mirror of
https://github.com/boy0001/FastAsyncWorldedit.git
synced 2024-12-29 12:37:53 +01:00
Fixes #513
This commit is contained in:
parent
aa3e8e3815
commit
f9174ffb56
@ -20,6 +20,10 @@ public class GriefPreventionFeature extends BukkitMaskManager implements Listene
|
||||
this.plugin = p3;
|
||||
}
|
||||
|
||||
public boolean isAllowed(Player player, Claim claim, MaskType type) {
|
||||
return claim != null && (claim.getOwnerName().equalsIgnoreCase(player.getName()) || claim.getOwnerName().equals(player.getUniqueId()) || (type == MaskType.MEMBER && (claim.allowBuild(player, Material.AIR) == null)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public BukkitMask getMask(final FawePlayer<Player> fp, MaskType type) {
|
||||
final Player player = fp.parent;
|
||||
@ -27,7 +31,7 @@ public class GriefPreventionFeature extends BukkitMaskManager implements Listene
|
||||
final Claim claim = GriefPrevention.instance.dataStore.getClaimAt(location, true, null);
|
||||
if (claim != null) {
|
||||
final String uuid = player.getUniqueId().toString();
|
||||
if (claim.getOwnerName().equalsIgnoreCase(player.getName()) || claim.getOwnerName().equals(uuid) || (type == MaskType.MEMBER && (claim.allowBuild(player, Material.AIR) == null))) {
|
||||
if (isAllowed(player, claim, type)) {
|
||||
claim.getGreaterBoundaryCorner().getBlockX();
|
||||
final Location pos1 = new Location(location.getWorld(), claim.getLesserBoundaryCorner().getBlockX(), 0, claim.getLesserBoundaryCorner().getBlockZ());
|
||||
final Location pos2 = new Location(location.getWorld(), claim.getGreaterBoundaryCorner().getBlockX(), 256, claim.getGreaterBoundaryCorner().getBlockZ());
|
||||
@ -36,6 +40,11 @@ public class GriefPreventionFeature extends BukkitMaskManager implements Listene
|
||||
public String getName() {
|
||||
return "CLAIM:" + claim.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isValid(FawePlayer player, MaskType type) {
|
||||
return isAllowed((Player) player.parent, claim, type);
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
@ -22,6 +22,9 @@ public class PlotMeFeature extends BukkitMaskManager implements Listener {
|
||||
this.plugin = p3;
|
||||
|
||||
}
|
||||
public boolean isAllowed(Player player, Plot plot, MaskType type) {
|
||||
return plot != null && type == MaskType.MEMBER ? plot.isAllowed(player.getUniqueId()) : player.getUniqueId().equals(plot.getOwnerId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public BukkitMask getMask(final FawePlayer<Player> fp, MaskType type) {
|
||||
@ -31,8 +34,7 @@ public class PlotMeFeature extends BukkitMaskManager implements Listener {
|
||||
if (plot == null) {
|
||||
return null;
|
||||
}
|
||||
final boolean isallowed = type == MaskType.MEMBER ? plot.isAllowed(player.getUniqueId()) : player.getUniqueId().equals(plot.getOwnerId());
|
||||
if (isallowed) {
|
||||
if (isAllowed(player, plot, type)) {
|
||||
final Location pos1 = new Location(location.getWorld(), this.plotme.getGenManager(player.getWorld().getName()).bottomX(plot.getId(), new BukkitWorld(player.getWorld())), 0, this.plotme
|
||||
.getGenManager(player.getWorld().getName()).bottomZ(plot.getId(), new BukkitWorld(player.getWorld())));
|
||||
final Location pos2 = new Location(location.getWorld(), this.plotme.getGenManager(player.getWorld().getName()).topX(plot.getId(), new BukkitWorld(player.getWorld())), 256, this.plotme
|
||||
@ -42,6 +44,11 @@ public class PlotMeFeature extends BukkitMaskManager implements Listener {
|
||||
public String getName() {
|
||||
return plot.getId();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isValid(FawePlayer player, MaskType type) {
|
||||
return isAllowed((Player) player.parent, plot, type);
|
||||
}
|
||||
};
|
||||
}
|
||||
return null;
|
||||
|
@ -24,6 +24,10 @@ public class PreciousStonesFeature extends BukkitMaskManager implements Listener
|
||||
|
||||
}
|
||||
|
||||
public boolean isAllowed(Player player, Field field, MaskType type, boolean allowMember) {
|
||||
return field != null && (field.isOwner(player.getName()) || (type == MaskType.MEMBER && allowMember && field.getAllAllowed().contains(player.getName())));
|
||||
}
|
||||
|
||||
@Override
|
||||
public FaweMask getMask(final FawePlayer<Player> fp, MaskType type) {
|
||||
final Player player = fp.parent;
|
||||
@ -35,10 +39,15 @@ public class PreciousStonesFeature extends BukkitMaskManager implements Listener
|
||||
String name = player.getName();
|
||||
boolean member = fp.hasPermission("fawe.preciousstones.member");
|
||||
for (final Field myField : fields) {
|
||||
if (myField.isOwner(name) || (type == MaskType.MEMBER && member && myField.getAllAllowed().contains(player.getName()))) {
|
||||
if (isAllowed(player, myField, type, member)) {
|
||||
BlockVector pos1 = new BlockVector(myField.getMinx(), myField.getMiny(), myField.getMinz());
|
||||
BlockVector pos2 = new BlockVector(myField.getMaxx(), myField.getMaxy(), myField.getMaxz());
|
||||
return new FaweMask(pos1, pos2, "FIELD: " + myField);
|
||||
return new FaweMask(pos1, pos2, "FIELD: " + myField) {
|
||||
@Override
|
||||
public boolean isValid(FawePlayer player, MaskType type) {
|
||||
return isAllowed((Player) player.parent, myField, type, fp.hasPermission("fawe.preciousstones.member"));
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
return null;
|
||||
|
@ -21,13 +21,17 @@ public class ResidenceFeature extends BukkitMaskManager implements Listener {
|
||||
|
||||
}
|
||||
|
||||
public boolean isAllowed(Player player, ClaimedResidence residence, MaskType type) {
|
||||
return residence != null && (residence.getOwner().equals(player.getName()) || residence.getOwner().equals(player.getUniqueId().toString()) || type == MaskType.MEMBER && residence.getPlayersInResidence().contains(player));
|
||||
}
|
||||
|
||||
@Override
|
||||
public BukkitMask getMask(final FawePlayer<Player> fp, MaskType type) {
|
||||
public BukkitMask getMask(final FawePlayer<Player> fp, final MaskType type) {
|
||||
final Player player = fp.parent;
|
||||
final Location location = player.getLocation();
|
||||
final ClaimedResidence residence = Residence.getInstance().getResidenceManager().getByLoc(location);
|
||||
if (residence != null) {
|
||||
if (residence.getOwner().equals(player.getName()) || residence.getOwner().equals(player.getUniqueId().toString()) || type == MaskType.MEMBER && residence.getPlayersInResidence().contains(player)) {
|
||||
if (isAllowed(player, residence, type)) {
|
||||
final CuboidArea area = residence.getAreaArray()[0];
|
||||
final Location pos1 = area.getHighLoc();
|
||||
final Location pos2 = area.getLowLoc();
|
||||
@ -36,6 +40,11 @@ public class ResidenceFeature extends BukkitMaskManager implements Listener {
|
||||
public String getName() {
|
||||
return "RESIDENCE: " + residence.getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isValid(FawePlayer player, MaskType type) {
|
||||
return isAllowed((Player) player.parent, residence, type);
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
@ -3,6 +3,7 @@ package com.boydti.fawe.bukkit.regions;
|
||||
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;
|
||||
@ -23,6 +24,25 @@ public class TownyFeature extends BukkitMaskManager implements Listener {
|
||||
this.plugin = p3;
|
||||
}
|
||||
|
||||
public boolean isAllowed(Player player, TownBlock block) {
|
||||
if (block == null) {
|
||||
return false;
|
||||
}
|
||||
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()))) {
|
||||
return true;
|
||||
}
|
||||
} catch (NotRegisteredException ignore) {}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BukkitMask getMask(final FawePlayer<Player> fp) {
|
||||
final Player player = fp.parent;
|
||||
@ -61,6 +81,11 @@ public class TownyFeature extends BukkitMaskManager implements Listener {
|
||||
public String getName() {
|
||||
return "PLOT:" + location.getChunk().getX() + "," + location.getChunk().getZ();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isValid(FawePlayer player, MaskType type) {
|
||||
return isAllowed((Player) player.parent, myplot);
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
@ -35,11 +35,10 @@ public class Worldguard extends BukkitMaskManager implements Listener {
|
||||
|
||||
}
|
||||
|
||||
public ProtectedRegion getRegion(final Player player, final Location loc) {
|
||||
final com.sk89q.worldguard.LocalPlayer localplayer = this.worldguard.wrapPlayer(player);
|
||||
RegionManager manager = this.worldguard.getRegionManager(player.getWorld());
|
||||
public ProtectedRegion getRegion(final com.sk89q.worldguard.LocalPlayer player, final Location loc) {
|
||||
RegionManager manager = this.worldguard.getRegionManager(loc.getWorld());
|
||||
if (manager == null) {
|
||||
if (this.worldguard.getGlobalStateManager().get(player.getWorld()).useRegions) {
|
||||
if (this.worldguard.getGlobalStateManager().get(loc.getWorld()).useRegions) {
|
||||
System.out.println("Region capability is not enabled for WorldGuard.");
|
||||
} else {
|
||||
System.out.println("WorldGuard is not enabled for that world.");
|
||||
@ -47,12 +46,12 @@ public class Worldguard extends BukkitMaskManager implements Listener {
|
||||
return null;
|
||||
}
|
||||
final ProtectedRegion global = manager.getRegion("__global__");
|
||||
if (global != null && isAllowed(localplayer, global)) {
|
||||
if (global != null && isAllowed(player, global)) {
|
||||
return global;
|
||||
}
|
||||
final ApplicableRegionSet regions = manager.getApplicableRegions(player.getLocation());
|
||||
final ApplicableRegionSet regions = manager.getApplicableRegions(loc);
|
||||
for (final ProtectedRegion region : regions) {
|
||||
if (isAllowed(localplayer, region)) {
|
||||
if (isAllowed(player, region)) {
|
||||
return region;
|
||||
}
|
||||
}
|
||||
@ -82,8 +81,9 @@ public class Worldguard extends BukkitMaskManager implements Listener {
|
||||
@Override
|
||||
public BukkitMask getMask(final FawePlayer<Player> fp) {
|
||||
final Player player = fp.parent;
|
||||
final com.sk89q.worldguard.LocalPlayer localplayer = this.worldguard.wrapPlayer(player);
|
||||
final Location location = player.getLocation();
|
||||
final ProtectedRegion myregion = this.getRegion(player, location);
|
||||
final ProtectedRegion myregion = this.getRegion(localplayer, location);
|
||||
if (myregion != null) {
|
||||
final Location pos1;
|
||||
final Location pos2;
|
||||
@ -99,6 +99,11 @@ public class Worldguard extends BukkitMaskManager implements Listener {
|
||||
public String getName() {
|
||||
return myregion.getId();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isValid(FawePlayer player, MaskType type) {
|
||||
return isAllowed(worldguard.wrapPlayer((Player) player.parent), myregion);
|
||||
}
|
||||
};
|
||||
} else {
|
||||
return null;
|
||||
|
@ -45,7 +45,6 @@ public class LoggingChangeSet extends AbstractDelegateChangeSet {
|
||||
constructor.setAccessible(true);
|
||||
this.world = (IWorld) constructor.newInstance(asyncWorld);
|
||||
} catch (Throwable ignore) {
|
||||
ignore.printStackTrace();
|
||||
this.world = api.getWorld(world);
|
||||
}
|
||||
this.loc = new MutableVector();
|
||||
|
@ -392,7 +392,6 @@ public abstract class FaweQueue implements HasFaweQueue {
|
||||
try {
|
||||
return getCombinedId4Data(x, y, z);
|
||||
} catch (FaweException ignore) {
|
||||
ignore.printStackTrace();
|
||||
return def;
|
||||
}
|
||||
}
|
||||
|
@ -17,7 +17,7 @@ public class MultiRegionExtent extends FaweRegionExtent {
|
||||
*
|
||||
* @param extent the extent
|
||||
*/
|
||||
public MultiRegionExtent(Extent extent, FaweLimit limit, RegionWrapper[]regions) {
|
||||
public MultiRegionExtent(Extent extent, FaweLimit limit, RegionWrapper[] regions) {
|
||||
super(extent, limit);
|
||||
this.index = 0;
|
||||
this.region = regions[0];
|
||||
|
@ -1,5 +1,6 @@
|
||||
package com.boydti.fawe.regions;
|
||||
|
||||
import com.boydti.fawe.object.FawePlayer;
|
||||
import com.boydti.fawe.object.RegionWrapper;
|
||||
import com.sk89q.worldedit.BlockVector;
|
||||
import java.util.Arrays;
|
||||
@ -53,6 +54,10 @@ public class FaweMask {
|
||||
this.position2 = new BlockVector(Math.max(pos1.getBlockX(), pos2.getBlockX()), 256, Math.max(pos1.getBlockZ(), pos2.getBlockZ()));
|
||||
}
|
||||
|
||||
public boolean isValid(FawePlayer player, FaweMaskManager.MaskType type) {
|
||||
return false;
|
||||
};
|
||||
|
||||
public BlockVector[] getBounds() {
|
||||
final BlockVector[] BlockVectors = { this.position1, this.position2 };
|
||||
return BlockVectors;
|
||||
|
@ -31,4 +31,8 @@ public abstract class FaweMaskManager<T> {
|
||||
public FaweMask getMask(final FawePlayer<T> player, MaskType type) {
|
||||
return getMask(player);
|
||||
}
|
||||
|
||||
public boolean isValid(FaweMask mask) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -19,6 +19,7 @@ import com.intellectualcrafters.plot.util.block.QueueProvider;
|
||||
import com.plotsquared.listener.WEManager;
|
||||
import com.sk89q.worldedit.BlockVector;
|
||||
import java.util.HashSet;
|
||||
import java.util.UUID;
|
||||
|
||||
public class PlotSquaredFeature extends FaweMaskManager {
|
||||
public PlotSquaredFeature() {
|
||||
@ -75,16 +76,30 @@ public class PlotSquaredFeature extends FaweMaskManager {
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isAllowed(FawePlayer fp, Plot plot, MaskType type) {
|
||||
if (plot == null) {
|
||||
return false;
|
||||
}
|
||||
UUID uid = fp.getUUID();
|
||||
return (plot.isOwner(uid) || (type == MaskType.MEMBER && (plot.getTrusted().contains(uid) || (plot.getMembers().contains(uid) && fp.hasPermission("fawe.plotsquared.member")))));
|
||||
}
|
||||
|
||||
@Override
|
||||
public FaweMask getMask(FawePlayer fp, MaskType type) {
|
||||
final PlotPlayer pp = PlotPlayer.wrap(fp.parent);
|
||||
final HashSet<RegionWrapper> regions;
|
||||
Plot plot = pp.getCurrentPlot();
|
||||
PlotArea area = pp.getApplicablePlotArea();
|
||||
if (plot != null && (plot.isOwner(pp.getUUID()) || (type == MaskType.MEMBER && (plot.getTrusted().contains(pp.getUUID()) || (plot.getMembers().contains(pp.getUUID()) && pp.hasPermission("fawe.plotsquared.member")))))) {
|
||||
if (isAllowed(fp, plot, type)) {
|
||||
regions = plot.getRegions();
|
||||
} else {
|
||||
plot = null;
|
||||
regions = WEManager.getMask(pp);
|
||||
if (regions.size() == 1) {
|
||||
RegionWrapper region = regions.iterator().next();
|
||||
if (region.minX == Integer.MIN_VALUE && region.maxX == Integer.MAX_VALUE) {
|
||||
regions.clear();
|
||||
}
|
||||
}
|
||||
}
|
||||
if (regions == null || regions.size() == 0) {
|
||||
return null;
|
||||
@ -93,11 +108,13 @@ public class PlotSquaredFeature extends FaweMaskManager {
|
||||
for (final RegionWrapper current : regions) {
|
||||
faweRegions.add(new com.boydti.fawe.object.RegionWrapper(current.minX, current.maxX, current.minZ, current.maxZ));
|
||||
}
|
||||
PlotArea area = pp.getApplicablePlotArea();
|
||||
int min = area != null ? area.MIN_BUILD_HEIGHT : 0;
|
||||
int max = area != null ? area.MAX_BUILD_HEIGHT : 255;
|
||||
final RegionWrapper region = regions.iterator().next();
|
||||
final BlockVector pos1 = new BlockVector(region.minX, min, region.minZ);
|
||||
final BlockVector pos2 = new BlockVector(region.maxX, max, region.maxZ);
|
||||
final Plot finalPlot = plot;
|
||||
return new FaweMask(pos1, pos2) {
|
||||
@Override
|
||||
public String getName() {
|
||||
@ -109,6 +126,11 @@ public class PlotSquaredFeature extends FaweMaskManager {
|
||||
return WEManager.maskContains(regions, loc.getBlockX(), loc.getBlockY(), loc.getBlockZ());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isValid(FawePlayer player, MaskType type) {
|
||||
return isAllowed(player, finalPlot, type);
|
||||
}
|
||||
|
||||
@Override
|
||||
public HashSet<com.boydti.fawe.object.RegionWrapper> getRegions() {
|
||||
return faweRegions;
|
||||
|
@ -2,6 +2,7 @@ package com.boydti.fawe.util;
|
||||
|
||||
import com.boydti.fawe.config.BBC;
|
||||
import com.boydti.fawe.config.Settings;
|
||||
import com.boydti.fawe.object.FaweLocation;
|
||||
import com.boydti.fawe.object.FawePlayer;
|
||||
import com.boydti.fawe.object.RegionWrapper;
|
||||
import com.boydti.fawe.object.exception.FaweException;
|
||||
@ -13,7 +14,9 @@ import com.sk89q.worldedit.extent.AbstractDelegateExtent;
|
||||
import com.sk89q.worldedit.extent.Extent;
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.ArrayDeque;
|
||||
import java.util.Collection;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
public class WEManager {
|
||||
|
||||
@ -69,6 +72,15 @@ public class WEManager {
|
||||
return getMask(player, FaweMaskManager.MaskType.MEMBER);
|
||||
}
|
||||
|
||||
public boolean isIn(int x, int y, int z, Collection<RegionWrapper> regions) {
|
||||
for (RegionWrapper region : regions) {
|
||||
if (region.isIn(x, y, z)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a player's mask
|
||||
* @param player
|
||||
@ -78,29 +90,60 @@ public class WEManager {
|
||||
if (player.hasPermission("fawe.bypass") || !Settings.IMP.REGION_RESTRICTIONS) {
|
||||
return new RegionWrapper[] {RegionWrapper.GLOBAL()};
|
||||
}
|
||||
HashSet<RegionWrapper> mask = new HashSet<>();
|
||||
String world = player.getLocation().world;
|
||||
FaweLocation loc = player.getLocation();
|
||||
String world = loc.world;
|
||||
if (!world.equals(player.getMeta("lastMaskWorld"))) {
|
||||
player.deleteMeta("lastMaskWorld");
|
||||
player.deleteMeta("lastMask");
|
||||
}
|
||||
player.setMeta("lastMaskWorld", world);
|
||||
Set<FaweMask> masks = player.getMeta("lastMask");
|
||||
HashSet<RegionWrapper> regions = new HashSet<>();
|
||||
if (masks == null) {
|
||||
masks = new HashSet<>();
|
||||
} else {
|
||||
boolean removed = false;
|
||||
if (masks.isEmpty()) {
|
||||
removed = true;
|
||||
} else {
|
||||
for (FaweMask mask : masks) {
|
||||
HashSet<RegionWrapper> curRegions = mask.getRegions();
|
||||
for (RegionWrapper region : curRegions) {
|
||||
if (!isIn(loc.x, loc.y, loc.z, curRegions)) {
|
||||
removed = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!mask.isValid(player, type)) {
|
||||
removed = true;
|
||||
break;
|
||||
}
|
||||
regions.addAll(curRegions);
|
||||
}
|
||||
}
|
||||
if (removed) {
|
||||
masks.clear();
|
||||
regions.clear();
|
||||
} else {
|
||||
return regions.toArray(new RegionWrapper[regions.size()]);
|
||||
}
|
||||
}
|
||||
for (final FaweMaskManager manager : managers) {
|
||||
if (player.hasPermission("fawe." + manager.getKey())) {
|
||||
final FaweMask fm = manager.getMask(player);
|
||||
if (fm != null) {
|
||||
mask.addAll(fm.getRegions());
|
||||
HashSet<RegionWrapper> cur = fm.getRegions();
|
||||
regions.addAll(cur);
|
||||
masks.add(fm);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (mask.isEmpty()) {
|
||||
mask = player.getMeta("lastMask");
|
||||
if (mask == null) {
|
||||
mask = new HashSet<>();
|
||||
}
|
||||
if (!masks.isEmpty()) {
|
||||
player.setMeta("lastMask", masks);
|
||||
} else {
|
||||
player.deleteMeta("lastMask");
|
||||
}
|
||||
player.setMeta("lastMask", mask);
|
||||
return mask.toArray(new RegionWrapper[mask.size()]);
|
||||
return regions.toArray(new RegionWrapper[regions.size()]);
|
||||
}
|
||||
|
||||
|
||||
|
@ -44,9 +44,7 @@ public class Favs extends JavaPlugin {
|
||||
|
||||
}
|
||||
});
|
||||
} catch (Throwable ignore) {
|
||||
ignore.printStackTrace();
|
||||
}
|
||||
} catch (Throwable ignore) {}
|
||||
}
|
||||
|
||||
public void setupCommand(final String label, final FaweCommand cmd) {
|
||||
|
@ -109,6 +109,30 @@ public class Sniper {
|
||||
* @return true if command visibly processed, false otherwise.
|
||||
*/
|
||||
public boolean snipe(final Action action, final Material itemInHand, final Block clickedBlock, final BlockFace clickedFace) {
|
||||
switch (action) {
|
||||
case LEFT_CLICK_AIR:
|
||||
case LEFT_CLICK_BLOCK:
|
||||
case RIGHT_CLICK_AIR:
|
||||
case RIGHT_CLICK_BLOCK:
|
||||
break;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
if (tools.isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
String toolId = getToolId(itemInHand);
|
||||
SniperTool sniperTool = tools.get(toolId);
|
||||
if (sniperTool == null) {
|
||||
return false;
|
||||
}
|
||||
if (!sniperTool.hasToolAssigned(itemInHand)) {
|
||||
return false;
|
||||
}
|
||||
if (sniperTool.getCurrentBrush() == null) {
|
||||
getPlayer().sendMessage("No Brush selected.");
|
||||
return false;
|
||||
}
|
||||
try {
|
||||
Player player = getPlayer();
|
||||
final FawePlayer<Player> fp = FawePlayer.wrap(player);
|
||||
@ -118,18 +142,14 @@ public class Sniper {
|
||||
if (!fp.runAction(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
snipeOnCurrentThread(fp, action, itemInHand, clickedBlock, clickedFace);
|
||||
snipeOnCurrentThread(fp, action, itemInHand, clickedBlock, clickedFace, sniperTool, toolId);
|
||||
}
|
||||
}, true, false)) {
|
||||
BBC.WORLDEDIT_COMMAND_LIMIT.send(fp);
|
||||
}
|
||||
}
|
||||
}, Fawe.isMainThread());
|
||||
String toolId = getToolId(itemInHand);
|
||||
SniperTool sniperTool = tools.get(toolId);
|
||||
if (sniperTool.hasToolAssigned(itemInHand) && sniperTool.getCurrentBrush() != null) {
|
||||
return true;
|
||||
}
|
||||
return true;
|
||||
} catch (Throwable e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
@ -137,7 +157,7 @@ public class Sniper {
|
||||
}
|
||||
|
||||
// Old method (plus world arg)
|
||||
public synchronized boolean snipeOnCurrentThread(FawePlayer fp, final Action action, final Material itemInHand, Block clickedBlock, final BlockFace clickedFace) {
|
||||
public synchronized boolean snipeOnCurrentThread(FawePlayer fp, final Action action, final Material itemInHand, Block clickedBlock, final BlockFace clickedFace, SniperTool sniperTool, String toolId) {
|
||||
Player bukkitPlayer = getPlayer();
|
||||
World bukkitWorld = bukkitPlayer.getWorld();
|
||||
|
||||
@ -162,186 +182,165 @@ public class Sniper {
|
||||
if (clickedBlock != null) {
|
||||
clickedBlock = world.getBlockAt(clickedBlock.getX(), clickedBlock.getY(), clickedBlock.getZ());
|
||||
}
|
||||
|
||||
|
||||
String toolId = getToolId(itemInHand);
|
||||
SniperTool sniperTool = tools.get(toolId);
|
||||
|
||||
switch (action) {
|
||||
case LEFT_CLICK_AIR:
|
||||
case LEFT_CLICK_BLOCK:
|
||||
case RIGHT_CLICK_AIR:
|
||||
case RIGHT_CLICK_BLOCK:
|
||||
break;
|
||||
default:
|
||||
return false;
|
||||
if (!getPlayer().hasPermission(sniperTool.getCurrentBrush().getPermissionNode())) {
|
||||
getPlayer().sendMessage("You are not allowed to use this brush. You're missing the permission node '" + sniperTool.getCurrentBrush().getPermissionNode() + "'");
|
||||
return true;
|
||||
}
|
||||
|
||||
if (sniperTool.hasToolAssigned(itemInHand)) {
|
||||
if (sniperTool.getCurrentBrush() == null) {
|
||||
getPlayer().sendMessage("No Brush selected.");
|
||||
return true;
|
||||
final SnipeData snipeData = sniperTool.getSnipeData();
|
||||
if (getPlayer().isSneaking()) {
|
||||
Block targetBlock;
|
||||
SnipeAction snipeAction = sniperTool.getActionAssigned(itemInHand);
|
||||
|
||||
switch (action) {
|
||||
case LEFT_CLICK_BLOCK:
|
||||
case LEFT_CLICK_AIR:
|
||||
if (clickedBlock != null) {
|
||||
targetBlock = clickedBlock;
|
||||
} else {
|
||||
RangeBlockHelper rangeBlockHelper = snipeData.isRanged() ? new RangeBlockHelper(getPlayer(), world, snipeData.getRange()) : new RangeBlockHelper(getPlayer(), world);
|
||||
targetBlock = snipeData.isRanged() ? rangeBlockHelper.getRangeBlock() : rangeBlockHelper.getTargetBlock();
|
||||
}
|
||||
|
||||
switch (snipeAction) {
|
||||
case ARROW:
|
||||
if (targetBlock != null) {
|
||||
int originalVoxel = snipeData.getVoxelId();
|
||||
snipeData.setVoxelId(targetBlock.getTypeId());
|
||||
SniperMaterialChangedEvent event = new SniperMaterialChangedEvent(this, toolId, new MaterialData(originalVoxel, snipeData.getData()), new MaterialData(snipeData.getVoxelId(), snipeData.getData()));
|
||||
Bukkit.getPluginManager().callEvent(event);
|
||||
snipeData.getVoxelMessage().voxel();
|
||||
return true;
|
||||
} else {
|
||||
int originalVoxel = snipeData.getVoxelId();
|
||||
snipeData.setVoxelId(0);
|
||||
SniperMaterialChangedEvent event = new SniperMaterialChangedEvent(this, toolId, new MaterialData(originalVoxel, snipeData.getData()), new MaterialData(snipeData.getVoxelId(), snipeData.getData()));
|
||||
Bukkit.getPluginManager().callEvent(event);
|
||||
snipeData.getVoxelMessage().voxel();
|
||||
return true;
|
||||
}
|
||||
case GUNPOWDER:
|
||||
if (targetBlock != null) {
|
||||
byte originalData = snipeData.getData();
|
||||
snipeData.setData(targetBlock.getData());
|
||||
SniperMaterialChangedEvent event = new SniperMaterialChangedEvent(this, toolId, new MaterialData(snipeData.getVoxelId(), originalData), new MaterialData(snipeData.getVoxelId(), snipeData.getData()));
|
||||
Bukkit.getPluginManager().callEvent(event);
|
||||
snipeData.getVoxelMessage().data();
|
||||
return true;
|
||||
} else {
|
||||
byte originalData = snipeData.getData();
|
||||
snipeData.setData((byte) 0);
|
||||
SniperMaterialChangedEvent event = new SniperMaterialChangedEvent(this, toolId, new MaterialData(snipeData.getVoxelId(), originalData), new MaterialData(snipeData.getVoxelId(), snipeData.getData()));
|
||||
Bukkit.getPluginManager().callEvent(event);
|
||||
snipeData.getVoxelMessage().data();
|
||||
return true;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case RIGHT_CLICK_AIR:
|
||||
case RIGHT_CLICK_BLOCK:
|
||||
if (clickedBlock != null) {
|
||||
targetBlock = clickedBlock;
|
||||
} else {
|
||||
RangeBlockHelper rangeBlockHelper = snipeData.isRanged() ? new RangeBlockHelper(getPlayer(), world, snipeData.getRange()) : new RangeBlockHelper(getPlayer(), world);
|
||||
targetBlock = snipeData.isRanged() ? rangeBlockHelper.getRangeBlock() : rangeBlockHelper.getTargetBlock();
|
||||
}
|
||||
|
||||
switch (snipeAction) {
|
||||
case ARROW:
|
||||
if (targetBlock != null) {
|
||||
int originalId = snipeData.getReplaceId();
|
||||
snipeData.setReplaceId(targetBlock.getTypeId());
|
||||
SniperReplaceMaterialChangedEvent event = new SniperReplaceMaterialChangedEvent(this, toolId, new MaterialData(originalId, snipeData.getReplaceData()), new MaterialData(snipeData.getReplaceId(), snipeData.getReplaceData()));
|
||||
Bukkit.getPluginManager().callEvent(event);
|
||||
snipeData.getVoxelMessage().replace();
|
||||
return true;
|
||||
} else {
|
||||
int originalId = snipeData.getReplaceId();
|
||||
snipeData.setReplaceId(0);
|
||||
SniperReplaceMaterialChangedEvent event = new SniperReplaceMaterialChangedEvent(this, toolId, new MaterialData(originalId, snipeData.getReplaceData()), new MaterialData(snipeData.getReplaceId(), snipeData.getReplaceData()));
|
||||
Bukkit.getPluginManager().callEvent(event);
|
||||
snipeData.getVoxelMessage().replace();
|
||||
return true;
|
||||
}
|
||||
case GUNPOWDER:
|
||||
if (targetBlock != null) {
|
||||
byte originalData = snipeData.getReplaceData();
|
||||
snipeData.setReplaceData(targetBlock.getData());
|
||||
SniperReplaceMaterialChangedEvent event = new SniperReplaceMaterialChangedEvent(this, toolId, new MaterialData(snipeData.getReplaceId(), originalData), new MaterialData(snipeData.getReplaceId(), snipeData.getReplaceData()));
|
||||
Bukkit.getPluginManager().callEvent(event);
|
||||
snipeData.getVoxelMessage().replaceData();
|
||||
return true;
|
||||
} else {
|
||||
byte originalData = snipeData.getReplaceData();
|
||||
snipeData.setReplaceData((byte) 0);
|
||||
SniperReplaceMaterialChangedEvent event = new SniperReplaceMaterialChangedEvent(this, toolId, new MaterialData(snipeData.getReplaceId(), originalData), new MaterialData(snipeData.getReplaceId(), snipeData.getReplaceData()));
|
||||
Bukkit.getPluginManager().callEvent(event);
|
||||
snipeData.getVoxelMessage().replaceData();
|
||||
return true;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
if (!getPlayer().hasPermission(sniperTool.getCurrentBrush().getPermissionNode())) {
|
||||
getPlayer().sendMessage("You are not allowed to use this brush. You're missing the permission node '" + sniperTool.getCurrentBrush().getPermissionNode() + "'");
|
||||
return true;
|
||||
} else {
|
||||
final Block targetBlock;
|
||||
final Block lastBlock;
|
||||
final SnipeAction snipeAction = sniperTool.getActionAssigned(itemInHand);
|
||||
|
||||
switch (action) {
|
||||
case RIGHT_CLICK_AIR:
|
||||
case RIGHT_CLICK_BLOCK:
|
||||
break;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
|
||||
final SnipeData snipeData = sniperTool.getSnipeData();
|
||||
if (getPlayer().isSneaking()) {
|
||||
Block targetBlock;
|
||||
SnipeAction snipeAction = sniperTool.getActionAssigned(itemInHand);
|
||||
|
||||
switch (action) {
|
||||
case LEFT_CLICK_BLOCK:
|
||||
case LEFT_CLICK_AIR:
|
||||
if (clickedBlock != null) {
|
||||
targetBlock = clickedBlock;
|
||||
} else {
|
||||
RangeBlockHelper rangeBlockHelper = snipeData.isRanged() ? new RangeBlockHelper(getPlayer(), world, snipeData.getRange()) : new RangeBlockHelper(getPlayer(), world);
|
||||
targetBlock = snipeData.isRanged() ? rangeBlockHelper.getRangeBlock() : rangeBlockHelper.getTargetBlock();
|
||||
}
|
||||
|
||||
switch (snipeAction) {
|
||||
case ARROW:
|
||||
if (targetBlock != null) {
|
||||
int originalVoxel = snipeData.getVoxelId();
|
||||
snipeData.setVoxelId(targetBlock.getTypeId());
|
||||
SniperMaterialChangedEvent event = new SniperMaterialChangedEvent(this, toolId, new MaterialData(originalVoxel, snipeData.getData()), new MaterialData(snipeData.getVoxelId(), snipeData.getData()));
|
||||
Bukkit.getPluginManager().callEvent(event);
|
||||
snipeData.getVoxelMessage().voxel();
|
||||
return true;
|
||||
} else {
|
||||
int originalVoxel = snipeData.getVoxelId();
|
||||
snipeData.setVoxelId(0);
|
||||
SniperMaterialChangedEvent event = new SniperMaterialChangedEvent(this, toolId, new MaterialData(originalVoxel, snipeData.getData()), new MaterialData(snipeData.getVoxelId(), snipeData.getData()));
|
||||
Bukkit.getPluginManager().callEvent(event);
|
||||
snipeData.getVoxelMessage().voxel();
|
||||
return true;
|
||||
}
|
||||
case GUNPOWDER:
|
||||
if (targetBlock != null) {
|
||||
byte originalData = snipeData.getData();
|
||||
snipeData.setData(targetBlock.getData());
|
||||
SniperMaterialChangedEvent event = new SniperMaterialChangedEvent(this, toolId, new MaterialData(snipeData.getVoxelId(), originalData), new MaterialData(snipeData.getVoxelId(), snipeData.getData()));
|
||||
Bukkit.getPluginManager().callEvent(event);
|
||||
snipeData.getVoxelMessage().data();
|
||||
return true;
|
||||
} else {
|
||||
byte originalData = snipeData.getData();
|
||||
snipeData.setData((byte) 0);
|
||||
SniperMaterialChangedEvent event = new SniperMaterialChangedEvent(this, toolId, new MaterialData(snipeData.getVoxelId(), originalData), new MaterialData(snipeData.getVoxelId(), snipeData.getData()));
|
||||
Bukkit.getPluginManager().callEvent(event);
|
||||
snipeData.getVoxelMessage().data();
|
||||
return true;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case RIGHT_CLICK_AIR:
|
||||
case RIGHT_CLICK_BLOCK:
|
||||
if (clickedBlock != null) {
|
||||
targetBlock = clickedBlock;
|
||||
} else {
|
||||
RangeBlockHelper rangeBlockHelper = snipeData.isRanged() ? new RangeBlockHelper(getPlayer(), world, snipeData.getRange()) : new RangeBlockHelper(getPlayer(), world);
|
||||
targetBlock = snipeData.isRanged() ? rangeBlockHelper.getRangeBlock() : rangeBlockHelper.getTargetBlock();
|
||||
}
|
||||
|
||||
switch (snipeAction) {
|
||||
case ARROW:
|
||||
if (targetBlock != null) {
|
||||
int originalId = snipeData.getReplaceId();
|
||||
snipeData.setReplaceId(targetBlock.getTypeId());
|
||||
SniperReplaceMaterialChangedEvent event = new SniperReplaceMaterialChangedEvent(this, toolId, new MaterialData(originalId, snipeData.getReplaceData()), new MaterialData(snipeData.getReplaceId(), snipeData.getReplaceData()));
|
||||
Bukkit.getPluginManager().callEvent(event);
|
||||
snipeData.getVoxelMessage().replace();
|
||||
return true;
|
||||
} else {
|
||||
int originalId = snipeData.getReplaceId();
|
||||
snipeData.setReplaceId(0);
|
||||
SniperReplaceMaterialChangedEvent event = new SniperReplaceMaterialChangedEvent(this, toolId, new MaterialData(originalId, snipeData.getReplaceData()), new MaterialData(snipeData.getReplaceId(), snipeData.getReplaceData()));
|
||||
Bukkit.getPluginManager().callEvent(event);
|
||||
snipeData.getVoxelMessage().replace();
|
||||
return true;
|
||||
}
|
||||
case GUNPOWDER:
|
||||
if (targetBlock != null) {
|
||||
byte originalData = snipeData.getReplaceData();
|
||||
snipeData.setReplaceData(targetBlock.getData());
|
||||
SniperReplaceMaterialChangedEvent event = new SniperReplaceMaterialChangedEvent(this, toolId, new MaterialData(snipeData.getReplaceId(), originalData), new MaterialData(snipeData.getReplaceId(), snipeData.getReplaceData()));
|
||||
Bukkit.getPluginManager().callEvent(event);
|
||||
snipeData.getVoxelMessage().replaceData();
|
||||
return true;
|
||||
} else {
|
||||
byte originalData = snipeData.getReplaceData();
|
||||
snipeData.setReplaceData((byte) 0);
|
||||
SniperReplaceMaterialChangedEvent event = new SniperReplaceMaterialChangedEvent(this, toolId, new MaterialData(snipeData.getReplaceId(), originalData), new MaterialData(snipeData.getReplaceId(), snipeData.getReplaceData()));
|
||||
Bukkit.getPluginManager().callEvent(event);
|
||||
snipeData.getVoxelMessage().replaceData();
|
||||
return true;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
return false;
|
||||
if (clickedBlock != null) {
|
||||
targetBlock = clickedBlock;
|
||||
lastBlock = clickedBlock.getRelative(clickedFace);
|
||||
if (lastBlock == null || targetBlock == null) {
|
||||
getPlayer().sendMessage(ChatColor.RED + "Snipe target block must be visible.");
|
||||
return true;
|
||||
}
|
||||
} else {
|
||||
final Block targetBlock;
|
||||
final Block lastBlock;
|
||||
final SnipeAction snipeAction = sniperTool.getActionAssigned(itemInHand);
|
||||
RangeBlockHelper rangeBlockHelper = snipeData.isRanged() ? new RangeBlockHelper(getPlayer(), world, snipeData.getRange()) : new RangeBlockHelper(getPlayer(), world);
|
||||
targetBlock = snipeData.isRanged() ? rangeBlockHelper.getRangeBlock() : rangeBlockHelper.getTargetBlock();
|
||||
lastBlock = rangeBlockHelper.getLastBlock();
|
||||
|
||||
switch (action) {
|
||||
case RIGHT_CLICK_AIR:
|
||||
case RIGHT_CLICK_BLOCK:
|
||||
break;
|
||||
default:
|
||||
return false;
|
||||
if (targetBlock == null || lastBlock == null) {
|
||||
getPlayer().sendMessage(ChatColor.RED + "Snipe target block must be visible.");
|
||||
return true;
|
||||
}
|
||||
|
||||
if (clickedBlock != null) {
|
||||
targetBlock = clickedBlock;
|
||||
lastBlock = clickedBlock.getRelative(clickedFace);
|
||||
if (lastBlock == null || targetBlock == null) {
|
||||
getPlayer().sendMessage(ChatColor.RED + "Snipe target block must be visible.");
|
||||
return true;
|
||||
}
|
||||
} else {
|
||||
RangeBlockHelper rangeBlockHelper = snipeData.isRanged() ? new RangeBlockHelper(getPlayer(), world, snipeData.getRange()) : new RangeBlockHelper(getPlayer(), world);
|
||||
targetBlock = snipeData.isRanged() ? rangeBlockHelper.getRangeBlock() : rangeBlockHelper.getTargetBlock();
|
||||
lastBlock = rangeBlockHelper.getLastBlock();
|
||||
|
||||
if (targetBlock == null || lastBlock == null) {
|
||||
getPlayer().sendMessage(ChatColor.RED + "Snipe target block must be visible.");
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
final IBrush brush = sniperTool.getCurrentBrush();
|
||||
if (sniperTool.getCurrentBrush() instanceof PerformBrush) {
|
||||
PerformBrush performerBrush = (PerformBrush) sniperTool.getCurrentBrush();
|
||||
performerBrush.initP(snipeData);
|
||||
}
|
||||
|
||||
boolean result = brush.perform(snipeAction, snipeData, targetBlock, lastBlock);
|
||||
if (Fawe.isMainThread()) {
|
||||
SetQueue.IMP.flush(changeQueue);
|
||||
} else {
|
||||
changeQueue.flush();
|
||||
}
|
||||
if (changeSet != null) {
|
||||
if (Settings.IMP.HISTORY.COMBINE_STAGES) {
|
||||
changeSet.closeAsync();
|
||||
} else {
|
||||
changeSet.close();
|
||||
}
|
||||
LocalSession session = fp.getSession();
|
||||
session.remember(changeSet.toEditSession(fp));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
final IBrush brush = sniperTool.getCurrentBrush();
|
||||
if (sniperTool.getCurrentBrush() instanceof PerformBrush) {
|
||||
PerformBrush performerBrush = (PerformBrush) sniperTool.getCurrentBrush();
|
||||
performerBrush.initP(snipeData);
|
||||
}
|
||||
|
||||
boolean result = brush.perform(snipeAction, snipeData, targetBlock, lastBlock);
|
||||
if (Fawe.isMainThread()) {
|
||||
SetQueue.IMP.flush(changeQueue);
|
||||
} else {
|
||||
changeQueue.flush();
|
||||
}
|
||||
if (changeSet != null) {
|
||||
if (Settings.IMP.HISTORY.COMBINE_STAGES) {
|
||||
changeSet.closeAsync();
|
||||
} else {
|
||||
changeSet.close();
|
||||
}
|
||||
LocalSession session = fp.getSession();
|
||||
session.remember(changeSet.toEditSession(fp));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user