Skip to content

Commit

Permalink
Merge branch 'TownyAdvanced:master' into fork
Browse files Browse the repository at this point in the history
  • Loading branch information
CorruptedGreed authored Jul 24, 2024
2 parents 9a32b4a + bf1140f commit b61f354
Show file tree
Hide file tree
Showing 78 changed files with 1,960 additions and 160 deletions.
2 changes: 1 addition & 1 deletion Towny/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

<artifactId>towny</artifactId>
<packaging>jar</packaging>
<version>0.100.3.5</version>
<version>0.100.3.10</version>

<licenses>
<license>
Expand Down
24 changes: 24 additions & 0 deletions Towny/src/main/java/com/palmergames/bukkit/config/ConfigNodes.java
Original file line number Diff line number Diff line change
Expand Up @@ -921,6 +921,18 @@ public enum ConfigNodes {
"0",
"",
"# Amount of buffer added to nation zone width surrounding capitals only. Creates a larger buffer around nation capitals."),
GNATION_SETTINGS_NATIONZONE_SKIPS_CONQUERED_TOWNS(
"global_nation_settings.nationzone.not_for_conquered_towns",
"false",
"",
"# When set to true, players which are part of a conquered town, will not have access to their nation's nationzone.",
"# They will still be able to use the nation_zone outside of their own town."),
GNATION_SETTINGS_NATIONZONE_PROTECTS_CONQUERED_TOWNS(
"global_nation_settings.nationzone.protect_conquered_towns",
"false",
"",
"# When set to true, the nation zone of a conquered town will only be usable by the conquered town's players.",
"# The players belonging to the conquering nation will not be able to use the nation zone."),
GNATION_SETTINGS_NATIONZONE_WAR_DISABLES(
"global_nation_settings.nationzone.war_disables",
"true",
Expand Down Expand Up @@ -1425,6 +1437,11 @@ public enum ConfigNodes {
"# Valid values are: true, false, war, peace",
"# When war or peace is set, it is only possible to teleport to the nations,",
"# when there is a war or peace."),
SPAWNING_DENY_CONQUERED_TOWNS_USE_OF_NATION_SPAWN(
"spawning.nation_spawn.deny_conquered_towns_use_of_nation_spawn",
"false",
"",
"# When set to true, towns conquered by their nation will not be allowed to use /n spawn."),

SPAWNING_NATION_SPAWN_COOLDOWN_ROOT(
"spawning.nation_spawn.spawning_cooldowns", "", ""),
Expand Down Expand Up @@ -2027,6 +2044,7 @@ public enum ConfigNodes {
NOTIFICATION_PLOT_NOTFORSALE("notification.plot.notforsale", "&e[Not For Sale]"),
NOTIFICATION_PLOT_TYPE("notification.plot.type", "&6[%s]"),
NOTIFICATION_GROUP("notification.group", "&f[%s]"),
NOTIFICATION_DISTRICT("notification.district", "&2[%s]"),
NOTIFICATION_TOWN_NAMES_ARE_VERBOSE(
"notification.town_names_are_verbose",
"true",
Expand Down Expand Up @@ -2372,6 +2390,12 @@ public enum ConfigNodes {
"/res set about [msg]",
"",
"# The default resident about text, shown in the resident's status screen."),
RES_SETTING_MIN_TIME_TO_JOIN_TOWN(
"resident_settings.min_time_to_join_town",
"0m",
"",
"# How long does a resident have to wait to join a town, after joining the server.",
"# Set to 0m to disable. 1m = 1 minute, 1h = 1 hour, 1d = 1 day."),
ECO(
"economy",
"",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import com.palmergames.bukkit.towny.object.TownBlockType;
import com.palmergames.bukkit.towny.object.TownyWorld;
import com.palmergames.bukkit.towny.object.WorldCoord;
import com.palmergames.bukkit.towny.object.District;
import com.palmergames.bukkit.towny.object.PlayerCache.TownBlockStatus;
import com.palmergames.bukkit.towny.utils.CombatUtil;
import com.palmergames.bukkit.towny.utils.PlayerCacheUtil;
Expand Down Expand Up @@ -41,6 +42,7 @@ public class ChunkNotification {
public static String notForSaleNotificationFormat = Colors.Yellow + "[Not For Sale]";
public static String plotTypeNotificationFormat = Colors.Gold + "[%s]";
public static String groupNotificationFormat = Colors.White + "[%s]";
public static String districtNotificationFormat = Colors.DARK_GREEN + "[%s]";

/**
* Called on Config load.
Expand All @@ -64,16 +66,18 @@ public static void loadFormatStrings() {
notForSaleNotificationFormat = Colors.translateColorCodes(TownySettings.getString(ConfigNodes.NOTIFICATION_PLOT_NOTFORSALE));
plotTypeNotificationFormat = Colors.translateColorCodes(TownySettings.getString(ConfigNodes.NOTIFICATION_PLOT_TYPE));
groupNotificationFormat = Colors.translateColorCodes(TownySettings.getString(ConfigNodes.NOTIFICATION_GROUP));
districtNotificationFormat = Colors.translateColorCodes(TownySettings.getString(ConfigNodes.NOTIFICATION_DISTRICT));
}

WorldCoord from, to;
boolean fromWild = false, toWild = false, toForSale = false, fromForSale = false,
toHomeBlock = false, toOutpostBlock = false, toPlotGroupBlock = false;
toHomeBlock = false, toOutpostBlock = false, toPlotGroupBlock = false, toDistrictBlock = false;
TownBlock fromTownBlock, toTownBlock = null;
Town fromTown = null, toTown = null;
Resident fromResident = null, toResident = null;
TownBlockType fromPlotType = null, toPlotType = null;
PlotGroup fromPlotGroup = null, toPlotGroup = null;
District fromDistrict = null, toDistrict = null;

public ChunkNotification(WorldCoord from, WorldCoord to) {

Expand All @@ -88,6 +92,9 @@ public ChunkNotification(WorldCoord from, WorldCoord to) {
fromPlotGroup = fromTownBlock.getPlotObjectGroup();
fromForSale = fromPlotGroup.getPrice() != -1;
}
if (fromTownBlock.hasDistrict()) {
fromDistrict = fromTownBlock.getDistrict();
}
fromTown = fromTownBlock.getTownOrNull();
fromResident = fromTownBlock.getResidentOrNull();

Expand All @@ -109,7 +116,10 @@ public ChunkNotification(WorldCoord from, WorldCoord to) {
toPlotGroup = toTownBlock.getPlotObjectGroup();
toForSale = toPlotGroup.getPrice() != -1;
}

toDistrictBlock = toTownBlock.hasDistrict();
if (toDistrictBlock) {
toDistrict = toTownBlock.getDistrict();
}
} else {
toWild = true;
}
Expand Down Expand Up @@ -277,6 +287,10 @@ public List<String> getPlotNotificationContent() {
if (output != null && output.length() > 0)
out.add(output);

output = getDistrictNotification();
if (output != null && output.length() > 0)
out.add(output);

return out;
}

Expand Down Expand Up @@ -323,6 +337,12 @@ public String getGroupNotification() {
return null;
}

public String getDistrictNotification() {
if (toDistrictBlock && (fromDistrict != toDistrict))
return String.format(districtNotificationFormat, StringMgmt.remUnderscore(toDistrict.getName()));
return null;
}

public String getPlotTypeNotification() {

if (toPlotType != null && !toPlotType.equals(fromPlotType) && !TownBlockType.RESIDENTIAL.equals(toPlotType))
Expand Down
12 changes: 12 additions & 0 deletions Towny/src/main/java/com/palmergames/bukkit/towny/Towny.java
Original file line number Diff line number Diff line change
Expand Up @@ -704,6 +704,18 @@ public void removePlayerMode(Player player) {
resident.clearModes();
}

/**
* Remove ALL current modes.
*
* @param player - player, whose modes are to be reset (all removed).
*/
public void removePlayerModes(Player player) {

Resident resident = TownyUniverse.getInstance().getResident(player.getName());
if (resident != null)
resident.resetModes(new String[0], true);
}

/**
* Fetch a list of all the players current modes.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ else if (townblock.isOutpost())
Component forSaleComponent = Component.empty();
Component claimedAtComponent = Component.empty();
Component groupComponent = Component.empty();
Component districtComponent = Component.empty();

if (TownyEconomyHandler.isActive()) {
double cost = townblock.hasPlotObjectGroup()
Expand All @@ -192,6 +193,13 @@ else if (townblock.isOutpost())
.append(translator.component("map_hover_plots", townblock.getPlotObjectGroup().getTownBlocks().size()).color(NamedTextColor.GREEN)
.append(Component.newline()))));

if (townblock.hasDistrict())
districtComponent = translator.component("map_hover_district").color(NamedTextColor.DARK_GREEN)
.append(Component.text(townblock.getDistrict().getFormattedName(), NamedTextColor.GREEN)
.append(translator.component("map_hover_plot_group_size").color(NamedTextColor.DARK_GREEN)
.append(translator.component("map_hover_plots", townblock.getDistrict().getTownBlocks().size()).color(NamedTextColor.GREEN)
.append(Component.newline()))));

if (townblock.hasResident())
residentComponent = Component.text(" (" + townblock.getResidentOrNull().getName() + ")", NamedTextColor.GREEN);

Expand All @@ -209,6 +217,7 @@ else if (townblock.isOutpost())

Component hoverComponent = townComponent
.append(plotTypeComponent)
.append(districtComponent)
.append(groupComponent)
.append(forSaleComponent)
.append(claimedAtComponent)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@

import com.palmergames.bukkit.config.ConfigNodes;
import com.palmergames.bukkit.towny.event.economy.TownyPreTransactionEvent;
import com.palmergames.bukkit.towny.event.economy.TownyTransactionEvent;
import com.palmergames.bukkit.towny.object.economy.adapter.ReserveEconomyAdapter;
import com.palmergames.bukkit.towny.object.Nation;
import com.palmergames.bukkit.towny.object.Resident;
import com.palmergames.bukkit.towny.object.Town;
import com.palmergames.bukkit.towny.object.Transaction;
import com.palmergames.bukkit.towny.object.TransactionType;
import com.palmergames.bukkit.towny.object.economy.transaction.Transaction;
import com.palmergames.bukkit.towny.object.economy.Account;
import com.palmergames.bukkit.towny.object.economy.TownyServerAccount;
import com.palmergames.bukkit.towny.object.economy.TownyServerAccountEconomyHandler;
import com.palmergames.bukkit.towny.object.economy.adapter.EconomyAdapter;
import com.palmergames.bukkit.towny.object.economy.adapter.VaultEconomyAdapter;
import com.palmergames.bukkit.util.BukkitTools;
Expand All @@ -18,9 +18,7 @@
import net.milkbowl.vault.economy.Economy;
import net.tnemc.core.Reserve;

import org.bukkit.Bukkit;
import org.bukkit.World;
import org.bukkit.entity.Player;
import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.RegisteredServiceProvider;
import org.jetbrains.annotations.Nullable;
Expand Down Expand Up @@ -98,6 +96,12 @@ public static void initialize(Towny plugin) {
TownyEconomyHandler.plugin = plugin;
}

public static TownyServerAccount initializeTownyServerAccount() {
TownyServerAccountEconomyHandler economyHandler = new TownyServerAccount();
TownyServerAccount account = new TownyServerAccount(economyHandler);
return account;
}

/**
* @return the economy type we have detected.
*/
Expand Down Expand Up @@ -211,36 +215,30 @@ public static boolean hasEnough(String accountName, double amount, World world)

private static boolean runPreChecks(Transaction transaction, String accountName) {
TownyPreTransactionEvent preEvent = new TownyPreTransactionEvent(transaction);
if (BukkitTools.isEventCancelled(preEvent)) {
TownyMessaging.sendErrorMsg(transaction.getPlayer(), preEvent.getCancelMessage());
if (BukkitTools.isEventCancelled(preEvent) && transaction.getSendingPlayer() != null) {
TownyMessaging.sendErrorMsg(transaction.getSendingPlayer(), preEvent.getCancelMessage());
return false;
}

checkNewAccount(accountName);
return true;
}


/**
* Attempts to remove an amount from an account
*
* @param accountName name of the account to modify
* @param account the Account losing money.
* @param amount amount of currency to remove from the account
* @param world name of the world in which to check in (TNE Reserve)
* @return true if successful
*/
public static boolean subtract(String accountName, double amount, World world) {
public static boolean subtract(Account account, double amount, World world) {

Player player = Bukkit.getServer().getPlayerExact(accountName);
Transaction transaction = new Transaction(TransactionType.SUBTRACT, player, amount);
TownyTransactionEvent event = new TownyTransactionEvent(transaction);

if (!runPreChecks(transaction, accountName)) {
if (!runPreChecks(Transaction.subtract(amount).paidBy(account).build(), account.getName())) {
return false;
}

if (economy.subtract(accountName, amount, world)) {
BukkitTools.fireEvent(event);
if (economy.subtract(account.getName(), amount, world)) {
return true;
}

Expand All @@ -250,23 +248,18 @@ public static boolean subtract(String accountName, double amount, World world) {
/**
* Add funds to an account.
*
* @param accountName account to add funds to
* @param account the Account receiving money.
* @param amount amount of currency to add
* @param world name of world (for TNE Reserve)
* @return true if successful
*/
public static boolean add(String accountName, double amount, World world) {
public static boolean add(Account account, double amount, World world) {

Player player = Bukkit.getServer().getPlayerExact(accountName);
Transaction transaction = new Transaction(TransactionType.ADD, player, amount);
TownyTransactionEvent event = new TownyTransactionEvent(transaction);

if (!runPreChecks(transaction, accountName)) {
if (!runPreChecks(Transaction.add(amount).paidTo(account).build(), account.getName())) {
return false;
}

if (economy.add(accountName, amount, world)) {
BukkitTools.fireEvent(event);
if (economy.add(account.getName(), amount, world)) {
return true;
}

Expand Down Expand Up @@ -297,27 +290,6 @@ public static String getFormattedBalance(double balance) {

}

/**
* Adds money to the server account (used for towny closed economy.)
*
* @param amount The amount to deposit.
* @param world The world of the deposit.
* @return A boolean indicating success.
*/
public static boolean addToServer(double amount, World world) {
return add(getServerAccount(), amount, world);
}

/**
* Removes money to the server account (used for towny closed economy.)
*
* @param amount The amount to withdraw.
* @param world The world of the withdraw.
* @return A boolean indicating success.
*/
public static boolean subtractFromServer(double amount, World world) {
return subtract(getServerAccount(), amount, world);
}

private static void checkNewAccount(String accountName) {
// Check if the account exists, if not create one.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,9 @@ public static StatusScreen getStatus(TownBlock townBlock, Player player) {
screen.addComponentOf("firespread", colourKeyValue(translator.of("firespread"), ((world.isForceFire() || townBlock.getPermissions().fire) ? translator.of("status_on"):translator.of("status_off"))));
screen.addComponentOf("mobspawns", colourKeyValue(translator.of("mobspawns"), ((world.isForceTownMobs() || townBlock.getPermissions().mobs || town.isAdminEnabledMobs()) ? translator.of("status_on"): translator.of("status_off"))));

if (townBlock.hasDistrict())
screen.addComponentOf("district", colourKey(translator.of("status_district_name_and_size", townBlock.getDistrict().getName(), townBlock.getDistrict().getTownBlocks().size())));

if (townBlock.hasPlotObjectGroup())
screen.addComponentOf("plotgroup", colourKey(translator.of("status_plot_group_name_and_size", townBlock.getPlotObjectGroup().getName(), townBlock.getPlotObjectGroup().getTownBlocks().size())));

Expand Down
Loading

0 comments on commit b61f354

Please sign in to comment.