diff --git a/pom.xml b/pom.xml index 5bfd718b..a2f161a9 100644 --- a/pom.xml +++ b/pom.xml @@ -39,7 +39,7 @@ maven-compiler-plugin - 3.8.0 + 3.8.1 1.8 1.8 @@ -122,6 +122,10 @@ jitpack.io https://jitpack.io + + glaremasters repo + https://repo.glaremasters.me/repository/towny/ + ender-repo @@ -139,7 +143,7 @@ MMOPlugins - https://mvn.lumine.io/repository/maven-releases/ + https://mvn.lumine.io/repository/maven-public/ @@ -152,7 +156,7 @@ org.spigotmc spigot-api - 1.17-R0.1-SNAPSHOT + 1.18.2-R0.1-SNAPSHOT provided @@ -284,8 +288,8 @@ io.lumine - MythicLib - 1.0.19 + MythicLib-dist + 1.3.1 provided @@ -297,9 +301,9 @@ - com.github.TownyAdvanced - Towny - 0.97.0.0 + com.palmergames.bukkit.towny + towny + 0.98.1.0 provided diff --git a/src/com/dre/brewery/utility/TownyUtil.java b/src/com/dre/brewery/utility/TownyUtil.java index c7836a81..59332e6e 100644 --- a/src/com/dre/brewery/utility/TownyUtil.java +++ b/src/com/dre/brewery/utility/TownyUtil.java @@ -5,7 +5,6 @@ import com.palmergames.bukkit.towny.object.Resident; import com.palmergames.bukkit.towny.object.Town; import com.palmergames.bukkit.towny.object.TownBlock; - import org.bukkit.Location; import org.bukkit.entity.Player; @@ -14,36 +13,33 @@ private TownyUtil() { } public static boolean isInsideTown(Location location) { - try { - final TownBlock townBlock = TownyAPI.getInstance().getTownBlock(location); - if (townBlock != null) { - final Town town = TownyAPI.getInstance().getTownBlock(location).getTown(); - if (town != null) { - // Execute your code here - return true; - } - } - } catch (NullPointerException | NotRegisteredException e) { - } - return false; + return TownyAPI.getInstance().getTown(location) != null; } public static boolean isInsideTown(Location location, Player player) { if (player == null) return isInsideTown(location); + + final Resident resident = TownyAPI.getInstance().getResident(player); + if (resident == null || resident.hasTown()) + return false; // if the resident doesnt exist or isnt in a town we can ignore them + final TownBlock townBlock = TownyAPI.getInstance().getTownBlock(location); + if (townBlock == null) return false; // no town here, we can leave try { - final Resident resident = TownyAPI.getInstance().getDataSource().getResident(player.getName()); - TownBlock townBlock = TownyAPI.getInstance().getTownBlock(location); - if (townBlock != null && townBlock.hasResident() - && resident.equals(townBlock.getResident())) + if (townBlock.hasResident() && resident.equals(townBlock.getResident())) // check if resident owns this plot return true; + } catch (NotRegisteredException ignored) { // should never be fired bc we check if the townblock has a resident + return false; // unnecessary bĂșt lets be safe + } - final Town town = TownyAPI.getInstance().getTownBlock(location).getTown(); + final Town town = TownyAPI.getInstance().getTown(location); + try { if (resident.getTown().equals(town)) { // Execute your code here return true; } - } catch (NullPointerException | NotRegisteredException e) { + } catch (NotRegisteredException ignored) { // checked earlier + return false; // unnecessary but lets be safe } return false; }