From ba0042311b2a3e2e05d24f03d3029bd3d92ccb1a Mon Sep 17 00:00:00 2001 From: NorbiPeti Date: Sat, 21 Sep 2019 22:16:44 +0200 Subject: [PATCH] Made Towny-Factions work for... not just 16x16 plots Math is hard TBMCPlugins/PluginConfigs#68 --- .../townyfactions/TownyFactionsComponent.java | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/main/java/buttondevteam/presents/components/townyfactions/TownyFactionsComponent.java b/src/main/java/buttondevteam/presents/components/townyfactions/TownyFactionsComponent.java index ad9ebb5..986467c 100644 --- a/src/main/java/buttondevteam/presents/components/townyfactions/TownyFactionsComponent.java +++ b/src/main/java/buttondevteam/presents/components/townyfactions/TownyFactionsComponent.java @@ -34,7 +34,7 @@ public class TownyFactionsComponent extends Component implements return getConfig().getData("distance", 5); } - @EventHandler + @EventHandler(ignoreCancelled = true) public void onFactionsClaim(EventFactionsChunksChange event) throws NotRegisteredException { if (event.getNewFaction().isNone()) return; //Allow unclaiming @@ -42,9 +42,10 @@ public class TownyFactionsComponent extends Component implements int x = chunk.getChunkX() * 16; int z = chunk.getChunkZ() * 16; int size = Coord.getCellSize(); - int amount = size / 16; + int amount = 16 / size; World world = chunk.asBukkitWorld(); int max = 0; + if (amount < 1) amount = 1; //For plot sizes > 16 for (int i = 0; i < amount; i++) { for (int j = 0; j < amount; j++) { Coord coord = Coord.parseCoord(new Location(world, x + i * size, 64, z + j * size)); @@ -53,15 +54,15 @@ public class TownyFactionsComponent extends Component implements if (dist > max) max = dist; } } - int distance = max * amount; + int distance = max / amount; if (distance().get() >= distance) { event.setCancelled(true); - event.getSender().sendMessage("§cYou are too close to a town! " + distance + " chunks away, " + distance().get() + " is allowed."); + event.getSender().sendMessage("§cYou are too close to a town! " + (distance - 1) + " chunks away, " + distance().get() + " is allowed."); } } } - @EventHandler + @EventHandler(ignoreCancelled = true) public void onTownyClaim(TownPreClaimEvent event) { PS coord = PS.valueOf(getLocation(event.getTownBlock().getWorldCoord())); int distance = distance().get();