From 418cfa6d03f6c4c08fdfbf978c87a19b0f11e1fc Mon Sep 17 00:00:00 2001 From: Jesse Boyd Date: Wed, 29 Aug 2018 01:04:25 +1000 Subject: [PATCH] Update towny hook / fix pattern traverser --- .../fawe/bukkit/regions/TownyFeature.java | 49 +++++++++---------- .../fawe/object/pattern/PatternTraverser.java | 8 +-- .../worldedit/world/block/BlockTypes.java | 1 + 3 files changed, 27 insertions(+), 31 deletions(-) diff --git a/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/regions/TownyFeature.java b/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/regions/TownyFeature.java index c3a5bdad2..587dda379 100644 --- a/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/regions/TownyFeature.java +++ b/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/regions/TownyFeature.java @@ -4,10 +4,7 @@ import com.boydti.fawe.bukkit.FaweBukkit; import com.boydti.fawe.object.FawePlayer; import com.palmergames.bukkit.towny.Towny; import com.palmergames.bukkit.towny.exceptions.NotRegisteredException; -import com.palmergames.bukkit.towny.object.PlayerCache; -import com.palmergames.bukkit.towny.object.TownBlock; -import com.palmergames.bukkit.towny.object.TownyUniverse; -import com.palmergames.bukkit.towny.object.WorldCoord; +import com.palmergames.bukkit.towny.object.*; import org.bukkit.Chunk; import org.bukkit.Location; import org.bukkit.entity.Player; @@ -28,18 +25,30 @@ public class TownyFeature extends BukkitMaskManager implements Listener { if (block == null) { return false; } + Resident resident; try { - if (block.getResident().getName().equals(player.getName())) { - return true; - } - } catch (final Exception ignore) {} - if (player.hasPermission("fawe.towny.*")) { - return true; - } else try { - if (block.getTown().isMayor(TownyUniverse.getDataSource().getResident(player.getName()))) { + resident = TownyUniverse.getDataSource().getResident(player.getName()); + try { + if (block.getResident().equals(resident)) { return true; } } catch (NotRegisteredException ignore) {} + Town town = block.getTown(); + if (town.isMayor(resident)) { + return true; + } + if (!town.hasResident(resident)) return false; + if (player.hasPermission("fawe.towny.*")) { + return true; + } + for (String rank : resident.getTownRanks()) { + if (player.hasPermission("fawe.towny." + rank)) { + return true; + } + } + } catch (NotRegisteredException e) { + return false; + } return false; } @@ -57,21 +66,7 @@ public class TownyFeature extends BukkitMaskManager implements Listener { if (myplot == null) { return null; } else { - boolean isMember = false; - try { - if (myplot.getResident().getName().equals(player.getName())) { - isMember = true; - } - } catch (final Exception e) { - - } - if (!isMember) { - if (player.hasPermission("fawe.towny.*")) { - isMember = true; - } else if (myplot.getTown().isMayor(TownyUniverse.getDataSource().getResident(player.getName()))) { - isMember = true; - } - } + boolean isMember = isAllowed(player, myplot); if (isMember) { final Chunk chunk = location.getChunk(); final Location pos1 = new Location(location.getWorld(), chunk.getX() * 16, 0, chunk.getZ() * 16); diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/pattern/PatternTraverser.java b/worldedit-core/src/main/java/com/boydti/fawe/object/pattern/PatternTraverser.java index dfbcba8ee..2e4b701b5 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/pattern/PatternTraverser.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/pattern/PatternTraverser.java @@ -34,7 +34,7 @@ public class PatternTraverser { Field field = current.getDeclaredField("extent"); field.setAccessible(true); field.set(pattern, newExtent); - } catch (NoSuchFieldException | IllegalAccessException ignore) { + } catch (NoSuchFieldException | IllegalAccessException | ClassCastException ignore) { } } try { @@ -42,7 +42,7 @@ public class PatternTraverser { field.setAccessible(true); Object next = field.get(pattern); reset(next, newExtent); - } catch (NoSuchFieldException | IllegalAccessException ignore) { + } catch (NoSuchFieldException | IllegalAccessException | ClassCastException ignore) { } try { Field field = current.getDeclaredField("mask"); @@ -56,7 +56,7 @@ public class PatternTraverser { field.setAccessible(true); Pattern next = (Pattern) field.get(pattern); reset(next, newExtent); - } catch (NoSuchFieldException | IllegalAccessException ignore) { + } catch (NoSuchFieldException | IllegalAccessException | ClassCastException ignore) { } try { Field field = current.getDeclaredField("patterns"); @@ -65,7 +65,7 @@ public class PatternTraverser { for (Pattern next : patterns) { reset(next, newExtent); } - } catch (NoSuchFieldException | IllegalAccessException ignore) { + } catch (NoSuchFieldException | IllegalAccessException | ClassCastException ignore) { } current = current.getSuperclass(); } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/world/block/BlockTypes.java b/worldedit-core/src/main/java/com/sk89q/worldedit/world/block/BlockTypes.java index 98af0cd99..2f084df28 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/world/block/BlockTypes.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/world/block/BlockTypes.java @@ -1014,6 +1014,7 @@ public enum BlockTypes implements BlockType { int size = blockMap.size(); for (BlockTypes type : oldValues) { if (!blockMap.containsKey(type.getId())) { + type.init(type.getId(), 0, new ArrayList<>()); Fawe.debug("Invalid block registered " + type.getId()); size++; }