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 10, 2024
2 parents 5aa4e3d + 6c550d7 commit 9a32b4a
Show file tree
Hide file tree
Showing 20 changed files with 190 additions and 55 deletions.
8 changes: 4 additions & 4 deletions 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.4</version>
<version>0.100.3.5</version>

<licenses>
<license>
Expand Down Expand Up @@ -210,13 +210,13 @@
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<version>5.10.2</version>
<version>5.10.3</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>5.10.2</version>
<version>5.10.3</version>
<scope>test</scope>
</dependency>
<dependency>
Expand Down Expand Up @@ -423,7 +423,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.4.1</version>
<version>3.4.2</version>
<configuration>
<archive>
<manifestEntries>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -534,7 +534,7 @@ public enum ConfigNodes {
"global_town_settings.peaceful_cooldown_time",
"30",
"",
"# Number of seconds that must pass before peacfulness can be toggled by a town or nation."),
"# Number of seconds that must pass before peacefulness can be toggled by a town or nation."),
GTOWN_SETTINGS_TOWN_DELETE_COOLDOWN_TIMER(
"global_town_settings.town_delete_cooldown_time",
"0",
Expand Down Expand Up @@ -1690,6 +1690,13 @@ public enum ConfigNodes {
"",
"# Maximum length of Town and Nation names. Setting this to a number below your current max_name_length could result in",
"# safe mode if the new value is below of your existing town and nation name lengths."),
FILTERS_MAX_NAME_CAPITAL_LETTERS(
"filters_colour_chat.modify_chat.max_name_capital_letters",
"-1",
"",
"# Maximum number of capital letters that can be used in Town and Nation names. Set to -1 to disable this feature.",
"# This count does not include the first letter of a town, and does not count capitalized letters that come after a _ character.",
"# This means that a town named New_York would register 0 capitals. While McDonalds would register 1. COOLTOWN would register 7 capital letters."),
FILTERS_MAX_TAG_LENGTH(
"filters_colour_chat.modify_chat.max_tag_length",
"4",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1458,6 +1458,11 @@ public static int getMaxNameLength() {
return getInt(ConfigNodes.FILTERS_MAX_NAME_LGTH);
}

public static int getMaxNameCapitalLetters() {

return getInt(ConfigNodes.FILTERS_MAX_NAME_CAPITAL_LETTERS);
}

public static long getDeleteTime() {

return getSeconds(ConfigNodes.RES_SETTING_DELETE_OLD_RESIDENTS_TIME);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1179,7 +1179,7 @@ public void parseAdminTownCommand(CommandSender sender, String[] split) throws T

// Special case where we can create a new Town before we use split[0] to get a Town.
if (split[0].equalsIgnoreCase("new")) {
parseAdminNewTownCommand(sender, split);
parseAdminNewTownCommand(sender, StringMgmt.remFirstArg(split));
return;
}

Expand Down Expand Up @@ -1398,25 +1398,27 @@ public void parseAdminTownCommand(CommandSender sender, String[] split) throws T
}

private void parseAdminNewTownCommand(CommandSender sender, String[] split) throws TownyException {
if (split.length != 3)
if (split.length < 2)
throw new TownyException(Translatable.of("msg_err_not_enough_variables") + "/ta town new [townname] [mayor]");

checkPermOrThrow(sender, PermissionNodes.TOWNY_COMMAND_TOWNYADMIN_TOWN_NEW.getNode());

String mayorName = split[split.length - 1];
String townName = StringMgmt.join(StringMgmt.remLastArg(split), "_");
Player player = sender instanceof Player p ? p : null;
Resident resident;
if ("npc".equalsIgnoreCase(split[2]) && player != null) // Avoid creating a new npc resident if command is ran from console.
if ("npc".equalsIgnoreCase(mayorName) && player != null) // Avoid creating a new npc resident if command is ran from console.
resident = ResidentUtil.createAndGetNPCResident();
else
resident = getResidentOrThrow(split[2]);
resident = getResidentOrThrow(mayorName);

// If the command is being run from console, try to sub in the specfied player.
if (player == null) {
if (!resident.isOnline())
throw new TownyException(Translatable.of("msg_player_is_not_online", split[2]));
throw new TownyException(Translatable.of("msg_player_is_not_online", mayorName));
player = resident.getPlayer();
}
TownCommand.newTown(player, split[1], resident, true, true);
TownCommand.newTown(player, townName, resident, true, true);
}

private void parseAdminTownSet(CommandSender sender, Town town, String[] split) throws TownyException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1647,15 +1647,15 @@ public boolean loadTownBlocks() {
String line = "";
String path;


List<TownBlock> toSave = new ArrayList<>();
for (TownBlock townBlock : universe.getTownBlocks().values()) {
path = getTownBlockFilename(townBlock);

File fileTownBlock = new File(path);
if (fileTownBlock.exists() && fileTownBlock.isFile()) {

try {
HashMap<String, String> keys = FileMgmt.loadFileIntoHashMap(fileTownBlock);
HashMap<String, String> keys = FileMgmt.loadFileIntoHashMap(fileTownBlock);

line = keys.get("town");
if (line != null) {
Expand All @@ -1668,8 +1668,10 @@ public boolean loadTownBlocks() {
Town town = null;
if (universe.hasTown(line.trim()))
town = universe.getTown(line.trim());
else if (universe.getReplacementNameMap().containsKey(line.trim()))
town = universe.getTown(universe.getReplacementNameMap().get(line).trim());
else if (universe.getReplacementNameMap().containsKey(line.trim())) {
town = universe.getTown(universe.getReplacementNameMap().get(line.trim()));
toSave.add(townBlock);
}

if (town == null) {
TownyMessaging.sendErrorMsg(Translation.of("flatfile_err_townblock_file_contains_unregistered_town_delete", line, path));
Expand Down Expand Up @@ -1832,6 +1834,10 @@ else if (universe.getReplacementNameMap().containsKey(line.trim()))
}
}

// Some townblocks have had their town name change. Save the townblocks.
if (!toSave.isEmpty())
toSave.forEach(TownBlock::save);

return true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,15 @@
public class SuccessfulTownyTeleportEvent extends Event {

private static final HandlerList handlers = new HandlerList();
private Resident resident;
private Location teleportLocation;
private final Resident resident;
private final Location teleportLocation;
private final double teleportCost;

public SuccessfulTownyTeleportEvent(Resident resident, Location loc) {
public SuccessfulTownyTeleportEvent(Resident resident, Location loc, double cost) {
super(!Bukkit.isPrimaryThread());
this.resident = resident;
this.teleportLocation = loc;
this.teleportCost = cost;
}

@NotNull
Expand All @@ -44,4 +46,10 @@ public Location getTeleportLocation() {
return teleportLocation;
}

/**
* @return The price that the player paid to teleport.
*/
public double getTeleportCost() {
return this.teleportCost;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -208,14 +208,14 @@ public void onEntityDeath(EntityDeathEvent event) {
}

/**
* Prevent block explosions and lightning from hurting entities.
* Prevent entity and block explosions and lightning from hurting entities.
*
* Doesn't stop damage to vehicles or hanging entities.
*
* @param event - EntityDamageEvent
*/
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
public void onEntityTakesBlockExplosionDamage(EntityDamageEvent event) {
public void onEntityTakesExplosionDamage(EntityDamageEvent event) {
if (plugin.isError()) {
event.setCancelled(true);
return;
Expand All @@ -224,12 +224,19 @@ public void onEntityTakesBlockExplosionDamage(EntityDamageEvent event) {
if (!TownyAPI.getInstance().isTownyWorld(event.getEntity().getWorld()))
return;

if ((event.getCause() == DamageCause.BLOCK_EXPLOSION || event.getCause() == DamageCause.LIGHTNING) && entityProtectedFromExplosiveDamageHere(event.getEntity(), event.getCause())) {
if (causeIsExplosive(event.getCause()) && entityProtectedFromExplosiveDamageHere(event.getEntity(), event.getCause())) {
event.setDamage(0);
event.setCancelled(true);
}
}

private boolean causeIsExplosive(DamageCause cause) {
return switch(cause) {
case ENTITY_EXPLOSION, BLOCK_EXPLOSION, LIGHTNING -> true;
default -> false;
};
}

/**
* Removes dragon fireball AreaEffectClouds when they would spawn somewhere with PVP disabled.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -306,9 +306,10 @@ public void onPlayerBucketFill(PlayerBucketFillEvent event) {

if (!TownyAPI.getInstance().isTownyWorld(event.getPlayer().getWorld()))
return;

// Bail if we're filling air, usually a milked cow.
if (event.getBlockClicked().getType().equals(Material.AIR))

// Bail if we're milking a cow, goat, or if we're filling air.
if (event.getItemStack().getType().equals(Material.MILK_BUCKET)
|| event.getBlockClicked().getType().equals(Material.AIR))
return;

// Test whether we can fill the bucket by testing if they would be able to destroy the liquid it is picking up.
Expand Down Expand Up @@ -663,9 +664,10 @@ public void onPlayerInteractEntity(PlayerInteractEntityEvent event) {
actionType = ActionType.SWITCH;
} else if (EntityLists.DYEABLE.contains(entityType) && ItemLists.DYES.contains(item))
mat = item;
else if (item != null && item == Material.BUCKET && EntityLists.MILKABLE.contains(entityType))
else if (item != null && item == Material.BUCKET && EntityLists.MILKABLE.contains(entityType)) {
mat = EntityTypeUtil.parseEntityToMaterial(entityType);
else if (item != null && item == Material.COOKIE && EntityType.PARROT.equals(entityType))
actionType = ActionType.ITEM_USE;
} else if (item != null && item == Material.COOKIE && EntityType.PARROT.equals(entityType))
mat = EntityTypeUtil.parseEntityToMaterial(entityType);
else if (EntityLists.RIGHT_CLICK_PROTECTED.contains(entityType))
mat = EntityTypeUtil.parseEntityToMaterial(entityType);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public void run() {

PaperLib.teleportAsync(player, request.destinationLocation(), TeleportCause.COMMAND);

BukkitTools.fireEvent(new SuccessfulTownyTeleportEvent(resident, request.destinationLocation()));
BukkitTools.fireEvent(new SuccessfulTownyTeleportEvent(resident, request.destinationLocation(), request.teleportCost()));

if (request.cooldown() > 0)
CooldownTimerTask.addCooldownTimer(resident.getName(), "teleport", request.cooldown());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -672,7 +672,7 @@ private static void initiateSpawn(Player player, Location spawnLoc, int cooldown
if (player.getVehicle() != null)
player.getVehicle().eject();
PaperLib.teleportAsync(player, spawnLoc, TeleportCause.COMMAND);
BukkitTools.fireEvent(new SuccessfulTownyTeleportEvent(resident, spawnLoc));
BukkitTools.fireEvent(new SuccessfulTownyTeleportEvent(resident, spawnLoc, cost));
if (cooldown > 0 && !hasPerm(player, PermissionNodes.TOWNY_SPAWN_ADMIN_NOCOOLDOWN))
CooldownTimerTask.addCooldownTimer(player.getName(), "teleport", cooldown);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ public static String checkAndFilterTownNameOrThrow(String name) throws InvalidNa

testForImproperNameAndThrow(out);

testCapitalization(out);

testForSubcommand(out);

if (out.startsWith(TownySettings.getTownAccountPrefix()))
Expand All @@ -104,6 +106,8 @@ public static String checkAndFilterNationNameOrThrow(String name) throws Invalid

testForImproperNameAndThrow(out);

testCapitalization(out);

testForSubcommand(out);

if (out.startsWith(TownySettings.getNationAccountPrefix()))
Expand Down Expand Up @@ -283,6 +287,40 @@ private static void testAllUnderscores(String name) throws InvalidNameException
throw new InvalidNameException(Translatable.of("msg_err_name_validation_is_all_underscores", name));
}

/**
* Stops objects being named with too many capital letters.
*
* @param name String submitted for testing.
* @throws InvalidNameException when the name uses too many capital letters.
*/
private static void testCapitalization(String name) throws InvalidNameException {
int maxCapitals = TownySettings.getMaxNameCapitalLetters();
if (maxCapitals == -1)
return;

int capitals = 0;
boolean skip = true;
for (char letter : name.toCharArray()) {
if (skip) { // First character of the name or character after a _.
skip = false;
continue;
}

if (letter == '_') { // Next character will be allowed to be capitalized.
skip = true;
continue;
}

if (Character.isLowerCase(letter)) // Not a capital.
continue;

capitals++;
}

if (capitals > maxCapitals)
throw new InvalidNameException(Translatable.of("msg_err_name_validation_too_many_capitals", name, capitals, maxCapitals));
}

/**
* Stops escape characters being used, something that could harm mysql if things weren't sanitized.
*
Expand Down
20 changes: 19 additions & 1 deletion Towny/src/main/resources/ChangeLog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9845,4 +9845,22 @@ v0.92.0.11:
withdraw from the bank anyways, but it might keep towns from being deleted for not paying their upkeep.
- Fix potential NPEs in PlotGroup, courtesy of galacticwarrior9 with PR #7483.
0.100.3.4:
- Fix town plot permissions changing not causing the town to save.
- Fix town plot permissions changing not causing the town to save.
- Improve /ta town new TOWNNAME MAYORNAME, to support town names entered with spaces in them.
- Fix milking animals sometimes being able to get cancelled by the PlayerBucketFillEvent.
- Expose cost in successful teleport event, courtesy of Warrior with PR #7487.
- Closes #7486.
- Bump org.junit.jupiter:junit-jupiter from 5.10.2 to 5.10.3.
- Bump org.junit.jupiter:junit-jupiter-api from 5.10.2 to 5.10.3.
- Bump org.apache.maven.plugins:maven-jar-plugin from 3.4.1 to 3.4.2.
0.100.3.5:
- Fix TownBlocks which load replacement town names save the new town name in the database.
- Make more explosive entities throw TownyExplosionDamagesEntityEvent events when they explode and damage entities.
- Add the ability to limit the number of capital letters used in Town and Nation names.
- Closes 7497.
- New Config Option: filters_colour_chat.modify_chat.max_name_capital_letters
- Default: -1
- Maximum number of capital letters that can be used in Town and Nation names.
- This count does not include the first letter of a town, and does not count capitalized letters that come after a _ character.
- This means that a town named New_York would register 0 capitals. While McDonalds would register 1. COOLTOWN would register 7 capital letters.
- Fix config typo, courtesy of auriasmc with PR #7498. (First-Time Contributor!)
2 changes: 2 additions & 0 deletions Towny/src/main/resources/lang/en-US.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2461,6 +2461,8 @@ msg_err_name_validation_is_not_permitted: "%s is not permitted."

msg_err_name_validation_is_all_underscores: "%s is entirely underscores."

msg_err_name_validation_too_many_capitals: "%s contains %s capital letters which were not allowed, use less than %s."

msg_err_name_validation_contains_harmful_characters: "%s contains symbols that could be harmful."

msg_err_name_validation_contains_numbers: "%s contains numbers which aren't allowed in names."
Expand Down
5 changes: 3 additions & 2 deletions Towny/src/main/resources/lang/es-CL.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ name: Towny
language: es-cl
author: GNosii
website: 'https://townyadvanced.github.io/'
description: >
Language file for all game messages for this Locale.
description: Language file for all game messages for this Locale.
#A note on editing this file.
#----------------------------
#Do not alter this file if it is in the reference folder.
Expand Down Expand Up @@ -2125,3 +2124,5 @@ msg_town_being_deleted_because_no_residents: "%s está siendo eliminado porque p
outlawed_in: "Excluido en"
msg_warning_town_deposit_hint: "Para depositar dinero en tu banco de ciudad utiliza /town deposit [amount]."
msg_warning_nation_deposit_hint: "Para depositar dinero en tu banco de nación usa /nation deposit [amount]."
teleport_warmup_title_dont_move: "&6¡No te muevas!"
teleport_warmup_subtitle_seconds_remaining: "&c%s &7segundos restantes para teletransportarse."
4 changes: 4 additions & 0 deletions Towny/src/main/resources/lang/es-ES.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ help_6: 'Ayuda del comando nation.'
help_7: 'Ayuda del comando plot.'
help_8: 'Ayuda del comando towny.'
help_9: 'Ayuda del comando townyadmin.'
towny_help_0: "Ayuda general para Towny"
towny_help_1: "Muestra un mapa de los poblados cercanos"
towny_help_2: "Mostrar los precios utilizados con Economía"
towny_help_3: "Mostrar puntuaciones altas"
town_help_1: 'Estado de tu ciudad'
town_help_2: '[alcalde]'
town_help_3: 'Estado de la ciudad seleccionada'
Expand Down
Loading

0 comments on commit 9a32b4a

Please sign in to comment.