Skip to content

Commit

Permalink
Merge pull request #6 from TownyAdvanced/master
Browse files Browse the repository at this point in the history
Update Towny
  • Loading branch information
CorruptedGreed authored Jan 26, 2024
2 parents 768fcf7 + 13352a5 commit ef6c98e
Show file tree
Hide file tree
Showing 20 changed files with 276 additions and 352 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.1.4</version>
<version>0.100.1.5</version>

<licenses>
<license>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2514,8 +2514,8 @@ public static int getMaxResidentsForTown(Town town) {
if (town.isCapital())
return getMaxResidentsPerTownCapitalOverride();
else
return !town.hasNation() && getMaxNumResidentsWithoutNation() > 0
? getMaxNumResidentsWithoutNation()
return !town.hasNation()
? town.getMaxAllowedNumberOfResidentsWithoutNation()
: getMaxResidentsPerTown();
}

Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -2618,7 +2618,7 @@ public static Town newTown(TownyWorld world, String name, Resident resident, Coo
}

if (TownySettings.isTownTagSetAutomatically())
town.setTag(name.substring(0, Math.min(name.length(), TownySettings.getMaxTagLength())).replace("_","").replace("-", ""));
town.setTag(NameUtil.getTagFromName(name));

resident.save();
townBlock.save();
Expand Down Expand Up @@ -3359,6 +3359,10 @@ else if (result.feedback() != null)
// Fast fail when we're claiming a single worldcoord and it is already claimed.
if (selection.size() == 1 && playerWorldCoord.hasTownBlock())
throw new TownyException(Translatable.of("msg_already_claimed", playerWorldCoord.getTownOrNull()));

// If selection is greater than 1 check for the multiclaim node.
if (selection.size() > 1)
checkPermOrThrow(player, PermissionNodes.TOWNY_COMMAND_TOWN_CLAIM_TOWN_MULTIPLE.getNode());
}

if (selection.isEmpty())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,9 @@ private void toggleWildernessUse(CommandSender sender, TownyWorld world, String[
TownyMessaging.sendMsg(sender, Translatable.of("msg_wilderness_use_set_to", toggle, world.getName()));
}

public void worldSet(CommandSender sender, TownyWorld world, String[] split) {
public void worldSet(CommandSender sender, TownyWorld world, String[] split) throws NoPermissionException {

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

if (split.length == 0) {
HelpMenu.TOWNYWORLD_SET.send(sender);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -690,7 +690,6 @@ public void renameTown(Town town, String newName) throws AlreadyRegisteredExcept
BukkitTools.fireEvent(new RenameTownEvent(oldName, town));
}

@SuppressWarnings("unlikely-arg-type")
@Override
public void renameNation(Nation nation, String newName) throws AlreadyRegisteredException, NotRegisteredException {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -294,29 +294,7 @@ public void onPotionSplashEvent(PotionSplashEvent event) {
if (!TownyAPI.getInstance().isTownyWorld(event.getEntity().getWorld()))
return;

boolean detrimental = false;

/*
* List of potion effects blocked from PvP.
*/
List<String> detrimentalPotions = TownySettings.getPotionTypes();

for (PotionEffect effect : event.getPotion().getEffects()) {

/*
* Check to see if any of the potion effects are protected.
* TODO: Make up a wrapper of some kind in order to support older versions while
* using the new methods when possible.
*/
@SuppressWarnings("deprecation")
String name = effect.getType().getName();
if (detrimentalPotions.contains(name)) {
detrimental = true;
break;
}
}

if (!detrimental)
if (!hasDetrimentalEffects(event.getPotion().getEffects()))
return;

for (LivingEntity defender : event.getAffectedEntities()) {
Expand Down Expand Up @@ -935,31 +913,26 @@ private boolean entityProtectedFromExplosiveDamageHere(Entity entity, DamageCaus
private boolean hasDetrimentalEffects(Collection<PotionEffect> effects) {
if (effects.isEmpty())
return false;

/*
* List of potion effects blocked from PvP.
*/
final List<String> detrimentalPotions = TownySettings.getPotionTypes().stream().map(type -> type.toLowerCase(Locale.ROOT)).collect(Collectors.toList());

for (final PotionEffect effect : effects) {
// TODO: Make up a wrapper of some kind in order to support older versions while
// using the new methods when possible.
@SuppressWarnings("deprecation")
final String name = effect.getType().getName().toLowerCase(Locale.ROOT);
return effects.stream()
.map(effect -> BukkitTools.potionEffectName(effect.getType()))
.anyMatch(name -> {
// Check to see if any of the potion effects are protected against.
if (detrimentalPotions.contains(name))
return true;

/*
* Check to see if any of the potion effects are protected.
*/
if (detrimentalPotions.contains(name))
return true;

// Account for PotionEffect#getType possibly returning the new name post enum removal.
final String legacyName = POTION_LEGACY_NAMES.inverse().get(name);
if (legacyName != null && detrimentalPotions.contains(legacyName))
return true;
}

return false;
// Account for PotionEffect#getType possibly returning the new name post enum removal.
final String legacyName = POTION_LEGACY_NAMES.inverse().get(name);
if (legacyName != null && detrimentalPotions.contains(legacyName))
return true;

return false;
});
}

@ApiStatus.Internal
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@
*/
public class TownyEntityMonitorListener implements Listener {

@SuppressWarnings("unused")
private final Towny plugin;

public TownyEntityMonitorListener(Towny instance) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,6 @@
* @author Shade/ElgarL
*
*/
@SuppressWarnings("deprecation")
public class TownyPlayerListener implements Listener {

private final Towny plugin;
Expand Down Expand Up @@ -246,7 +245,6 @@ public void onPlayerRespawn(PlayerRespawnEvent event) {
}
}

@SuppressWarnings({"unchecked"})
private boolean isEndPortalRespawn(PlayerRespawnEvent event) {
try {
final Collection<Enum<?>> respawnFlags = (Collection<Enum<?>>) GET_RESPAWN_FLAGS.invoke(event);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ public Collection<T> tagged() {
return this.tagged;
}

@SuppressWarnings("unused")
public static class Builder<T extends Keyed, F extends AbstractRegistryList<T>> {
private final Registry<T> registry;
private final Class<T> clazz;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1943,4 +1943,8 @@ public boolean hasEnoughResidentsToBeANationCapital() {
public boolean isAllowedThisAmountOfResidents(int residentCount, boolean isCapital) {
return TownUtil.townCanHaveThisAmountOfResidents(this, residentCount, isCapital);
}

public int getMaxAllowedNumberOfResidentsWithoutNation() {
return TownUtil.getMaxAllowedNumberOfResidentsWithoutNation(this);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ public enum PermissionNodes {

TOWNY_COMMAND_TOWN_CLAIM("towny.command.town.claim.*"),
TOWNY_COMMAND_TOWN_CLAIM_TOWN("towny.command.town.claim.town"),
TOWNY_COMMAND_TOWN_CLAIM_TOWN_MULTIPLE("towny.command.town.claim.town.multiple"),
TOWNY_COMMAND_TOWN_CLAIM_OUTPOST("towny.command.town.claim.outpost"),
TOWNY_COMMAND_TOWN_CLAIM_FILL("towny.command.town.claim.fill"),

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,6 @@ private static void checkForVitalGroups() {
* @param resident - Resident to check if player is valid
* @param player - Player to register permission
*/
@SuppressWarnings("unchecked")
public static void assignPermissions(Resident resident, Player player) {

if (resident == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,6 @@ public int getTaskId() {
* @deprecated Deprecated as of 0.99.0.6, use {@link #setTask(ScheduledTask)} instead.
*/
@Deprecated
@SuppressWarnings("unused")
public void setTaskId(int taskId) {

}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.palmergames.bukkit.towny.utils;

import com.palmergames.bukkit.towny.TownySettings;
import com.palmergames.bukkit.towny.object.Nameable;
import java.util.ArrayList;
import java.util.Collection;
Expand Down Expand Up @@ -49,4 +50,8 @@ public static List<String> filterByStart(List<String> list, String startingWith)
}
return list.stream().filter(name -> name.toLowerCase(Locale.ROOT).startsWith(startingWith.toLowerCase(Locale.ROOT))).collect(Collectors.toList());
}

public static String getTagFromName(String name) {
return name.substring(0, Math.min(name.length(), TownySettings.getMaxTagLength())).replace("_","").replace("-", "");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,14 @@ public static boolean townHasEnoughResidentsToJoinANation(Town town) {

public static boolean townCanHaveThisAmountOfResidents(Town town, int residentCount, boolean isCapital) {
int maxResidents = !isCapital
? !town.hasNation() && TownySettings.getMaxNumResidentsWithoutNation() > 0 ? TownySettings.getMaxNumResidentsWithoutNation() : TownySettings.getMaxResidentsPerTown()
? !town.hasNation() ? getMaxAllowedNumberOfResidentsWithoutNation(town) : TownySettings.getMaxResidentsPerTown()
: TownySettings.getMaxResidentsPerTownCapitalOverride();

return maxResidents == 0 || residentCount <= maxResidents;
}

public static int getMaxAllowedNumberOfResidentsWithoutNation(Town town) {
int maxResidents = TownySettings.getMaxNumResidentsWithoutNation() > 0 ? TownySettings.getMaxNumResidentsWithoutNation() : TownySettings.getMaxResidentsPerTown();
return maxResidents == 0 ? Integer.MAX_VALUE : maxResidents;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import org.bukkit.event.Event;
import org.bukkit.metadata.MetadataValue;
import org.bukkit.plugin.PluginManager;
import org.bukkit.potion.PotionEffectType;
import org.bukkit.scheduler.BukkitScheduler;
import org.bukkit.scoreboard.Criteria;
import org.bukkit.scoreboard.Objective;
Expand Down Expand Up @@ -328,6 +329,14 @@ public static List<String> getWorldNames(boolean lowercased) {
return lowercased ? getWorlds().stream().map(world -> world.getName().toLowerCase(Locale.ROOT)).collect(Collectors.toList()) : getWorldNames();
}

@SuppressWarnings("deprecation")
public static String potionEffectName(PotionEffectType type) {
if (MinecraftVersion.CURRENT_VERSION.isOlderThanOrEquals(MinecraftVersion.MINECRAFT_1_20_3))
return type.getName().toLowerCase(Locale.ROOT);
else
return type.getKey().getKey().toLowerCase(Locale.ROOT);
}

@SuppressWarnings("deprecation")
public static Objective objective(Scoreboard board, @NotNull String name, @NotNull String displayName) {
Objective objective;
Expand Down
10 changes: 9 additions & 1 deletion Towny/src/main/resources/ChangeLog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9469,4 +9469,12 @@ v0.92.0.11:
- Refactor max residents per town code into TownUtil accessed via a new Town method.
- Bump Spigot 1.20.2 to 1.20.4.
- Bump com.github.seeseemelk:MockBukkit-v1.20 from 3.60.0 to 3.65.0.
- Bump org.apache.maven.plugins:maven-surefire-plugin from 3.2.3 to 3.2.5.
- Bump org.apache.maven.plugins:maven-surefire-plugin from 3.2.3 to 3.2.5.
- Re-add the towny.command.town.claim.town.multiple permission node.
- A child node of towny.command.town.claim.*.
- Negate this node to stop towns claiming multiple plots at once, ie: with /t claim auto.
- Refactor parts of the NationCommand class, cleaning up edge case scenarios when towns might join/create nations when they shouldn't.
0.100.1.5:
- Remove unneeded annotations.
- Fix permission regression from 0.100.1.1.
- Add a wrapper for getting potion names post-1.20.4.
8 changes: 4 additions & 4 deletions Towny/src/main/resources/lang/uk-UA.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ towny_help_4: "Показати час до початку нового дня"
towny_help_5: "Показати статистику"
towny_help_6: "Показати версію Towny"
towny_top_help_0: "List top residents based on subcommand."
towny_top_help_1: "List top land-owners based on subcommand."
towny_top_help_2: "List wealthiest based on subcommand."
towny_top_help_1: "Топ землевласників на основі субкоманди."
towny_top_help_2: "Список найбагатших на основі субкоманди."
town_help_1: 'Статус вашого міста'
town_help_2: '[Мер]'
town_help_3: 'Вибраний статус міста'
Expand Down Expand Up @@ -95,8 +95,8 @@ town_help_33: "Використайте /t buy ? для допомоги."
town_help_34: "Використайте /t toggle ? для допомоги."
town_help_35: "Використовуйте /t rank ? для допомоги."
town_list_help_0: "Переглянути вказану сторінку."
town_list_help_1: "List towns by resident-count, with the specified page."
town_list_help_2: "List towns which are open, with the specified page."
town_list_help_1: "Список міст за кількістю жителів із зазначеною сторінкою."
town_list_help_2: "Список міст, які відкриті, із зазначеною сторінкою."
town_list_help_3: "List towns using bank balance, with the specified page."
town_list_help_4: "List towns in alphabetical order, with the specified page."
town_list_help_5: "List towns by claimed land, with the specified page."
Expand Down
1 change: 1 addition & 0 deletions Towny/src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -423,6 +423,7 @@ permissions:
children:
towny.command.town.claim.town: true
towny.command.town.claim.outpost: true
towny.command.town.claim.town.multiple: true
towny.command.town.claim.fill: true

towny.command.town.invite.*:
Expand Down

0 comments on commit ef6c98e

Please sign in to comment.