Update & Fix TownyFeature support. (#2279)

Dieser Commit ist enthalten in:
LlmDl 2023-06-11 16:55:11 -05:00 committet von GitHub
Ursprung 71c172cced
Commit ca4080eea7
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: 4AEE18F83AFDEB23

Datei anzeigen

@ -2,9 +2,7 @@ package com.fastasyncworldedit.bukkit.regions;
import com.fastasyncworldedit.core.regions.FaweMask; import com.fastasyncworldedit.core.regions.FaweMask;
import com.palmergames.bukkit.towny.Towny; import com.palmergames.bukkit.towny.Towny;
import com.palmergames.bukkit.towny.TownyUniverse; import com.palmergames.bukkit.towny.TownyAPI;
import com.palmergames.bukkit.towny.exceptions.NotRegisteredException;
import com.palmergames.bukkit.towny.object.PlayerCache;
import com.palmergames.bukkit.towny.object.Resident; import com.palmergames.bukkit.towny.object.Resident;
import com.palmergames.bukkit.towny.object.Town; import com.palmergames.bukkit.towny.object.Town;
import com.palmergames.bukkit.towny.object.TownBlock; import com.palmergames.bukkit.towny.object.TownBlock;
@ -36,31 +34,27 @@ public class TownyFeature extends BukkitMaskManager implements Listener {
if (block == null) { if (block == null) {
return false; return false;
} }
Resident resident; Resident resident = TownyAPI.getInstance().getResident(player);
try { if (resident == null) {
resident = TownyUniverse.getInstance().getResident(player.getName()); return false;
try { }
if (block.getResident().equals(resident)) { if (block.hasResident(resident) || block.hasTrustedResident(resident)) {
return true; return true;
} }
} catch (NotRegisteredException ignored) { Town town = block.getTownOrNull(); // Will not be null, because block is not null.
} if (town.isMayor(resident) || town.hasTrustedResident(resident)) {
Town town = block.getTown(); return true;
if (town.isMayor(resident)) { }
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; 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 ignored) {
} }
return false; return false;
} }
@ -69,32 +63,23 @@ public class TownyFeature extends BukkitMaskManager implements Listener {
public FaweMask getMask(final com.sk89q.worldedit.entity.Player wePlayer, MaskType type, boolean isWhitelist) { public FaweMask getMask(final com.sk89q.worldedit.entity.Player wePlayer, MaskType type, boolean isWhitelist) {
final Player player = BukkitAdapter.adapt(wePlayer); final Player player = BukkitAdapter.adapt(wePlayer);
final Location location = player.getLocation(); final Location location = player.getLocation();
try { final WorldCoord mycoord = WorldCoord.parseWorldCoord(location);
final PlayerCache cache = ((Towny) this.towny).getCache(player); if (mycoord.isWilderness()) {
final WorldCoord mycoord = cache.getLastTownBlock(); return null;
if (mycoord == null) { }
return null; final TownBlock myplot = mycoord.getTownBlockOrNull(); // Will not be null, because of the isWilderness() test above.
} boolean isMember = isAllowed(player, myplot);
final TownBlock myplot = mycoord.getTownBlock(); if (isMember) {
if (myplot == null) { final Location loc1 = mycoord.getLowerMostCornerLocation();
return null; final Location loc2 = mycoord.getUpperMostCornerLocation();
} final BlockVector3 pos1 = BlockVector3.at(loc1.getX(), loc1.getY(), loc1.getZ());
boolean isMember = isAllowed(player, myplot); final BlockVector3 pos2 = BlockVector3.at(loc2.getX(), loc2.getY(), loc2.getZ());
if (isMember) { return new FaweMask(new CuboidRegion(pos1, pos2)) {
final Chunk chunk = location.getChunk(); @Override
final BlockVector3 pos1 = BlockVector3 public boolean isValid(com.sk89q.worldedit.entity.Player player, MaskType type) {
.at(chunk.getX() * 16, 0, chunk.getZ() * 16); return isAllowed(BukkitAdapter.adapt(player), myplot);
final BlockVector3 pos2 = BlockVector3.at( }
chunk.getX() * 16 + 15, 156, chunk.getZ() * 16 };
+ 15);
return new FaweMask(new CuboidRegion(pos1, pos2)) {
@Override
public boolean isValid(com.sk89q.worldedit.entity.Player player, MaskType type) {
return isAllowed(BukkitAdapter.adapt(player), myplot);
}
};
}
} catch (Exception ignored) {
} }
return null; return null;
} }