optimized WorldEdit masking with multi plot mask regions.

This commit is contained in:
boy0001 2015-04-12 15:22:03 +10:00
parent a205156ba3
commit 9fa0b51b94
20 changed files with 419 additions and 431 deletions

View File

@ -37,15 +37,14 @@ import com.intellectualcrafters.plot.listeners.PlayerEvents;
import com.intellectualcrafters.plot.listeners.PlayerEvents_1_8;
import com.intellectualcrafters.plot.listeners.PlotPlusListener;
import com.intellectualcrafters.plot.listeners.TNTListener;
import com.intellectualcrafters.plot.listeners.WorldEditListener;
import com.intellectualcrafters.plot.listeners.WorldEvents;
import com.intellectualcrafters.plot.listeners.worldedit.WEListener;
import com.intellectualcrafters.plot.object.PlotPlayer;
import com.intellectualcrafters.plot.titles.AbstractTitle;
import com.intellectualcrafters.plot.titles.DefaultTitle;
import com.intellectualcrafters.plot.util.BlockManager;
import com.intellectualcrafters.plot.util.BlockUpdateUtil;
import com.intellectualcrafters.plot.util.ChunkManager;
import com.intellectualcrafters.plot.util.CmdConfirm;
import com.intellectualcrafters.plot.util.ConsoleColors;
import com.intellectualcrafters.plot.util.EventUtil;
import com.intellectualcrafters.plot.util.MainUtil;
@ -66,6 +65,7 @@ import com.intellectualcrafters.plot.util.bukkit.UUIDHandler;
import com.intellectualcrafters.plot.uuid.DefaultUUIDWrapper;
import com.intellectualcrafters.plot.uuid.OfflineUUIDWrapper;
import com.intellectualcrafters.plot.uuid.UUIDWrapper;
import com.sk89q.worldedit.WorldEdit;
import com.sk89q.worldedit.bukkit.WorldEditPlugin;
public class BukkitMain extends JavaPlugin implements Listener, IPlotMain {
@ -260,7 +260,9 @@ public class BukkitMain extends JavaPlugin implements Listener, IPlotMain {
log("&cPlease use WorldEdit 6+ for masking support");
log("&c - http://builds.enginehub.org/job/worldedit");
} else {
getServer().getPluginManager().registerEvents(new WorldEditListener(), this);
WEListener weClass = new WEListener();
WorldEdit.getInstance().getEventBus().register(weClass);
getServer().getPluginManager().registerEvents(weClass, this);
MainCommand.subCommands.add(new WE_Anywhere());
}
}

View File

@ -808,6 +808,7 @@ public class PlotSquared {
options.put("plotme-convert.cache-uuids", Settings.CACHE_PLOTME);
options.put("claim.max-auto-area", Settings.MAX_AUTO_SIZE);
options.put("UUID.offline", Settings.OFFLINE_MODE);
options.put("UUID.force-lowercase", Settings.UUID_LOWERCASE);
options.put("kill_road_mobs", Settings.KILL_ROAD_MOBS_DEFAULT);
options.put("mob_pathfinding", Settings.MOB_PATHFINDING_DEFAULT);
options.put("console.color", Settings.CONSOLE_COLOR);
@ -819,7 +820,6 @@ public class PlotSquared {
options.put("clear.on.ban", false);
options.put("max_plots", Settings.MAX_PLOTS);
options.put("schematics.save_path", Settings.SCHEMATIC_SAVE_PATH);
options.put("uuid.read-from-disk", Settings.UUID_FROM_DISK);
options.put("cache.permissions", Settings.PERMISSION_CACHING);
options.put("titles", Settings.TITLES);
options.put("teleport.on_login", Settings.TELEPORT_ON_LOGIN);
@ -871,6 +871,7 @@ public class PlotSquared {
}
Settings.SCHEMATIC_SAVE_PATH = config.getString("schematics.save_path");
Settings.OFFLINE_MODE = config.getBoolean("UUID.offline");
Settings.UUID_LOWERCASE = config.getBoolean("UUID.force-lowercase");
Settings.UUID_FROM_DISK = config.getBoolean("uuid.read-from-disk");
Settings.REQUIRE_SELECTION = config.getBoolean("worldedit.require-selection-in-mask");
}
@ -959,9 +960,6 @@ public class PlotSquared {
Settings.AUTO_CLEAR = config.getBoolean("clear.auto.enabled");
Settings.AUTO_CLEAR_DAYS = config.getInt("clear.auto.days");
Settings.DELETE_PLOTS_ON_BAN = config.getBoolean("clear.on.ban");
Settings.API_URL = config.getString("uuid.api.location");
Settings.CUSTOM_API = config.getBoolean("uuid.api.custom");
Settings.UUID_FECTHING = config.getBoolean("uuid.fetching");
}
public static void showDebug() {

View File

@ -21,12 +21,10 @@
package com.intellectualcrafters.plot.commands;
import java.util.Arrays;
import java.util.List;
import org.apache.commons.lang.StringUtils;
import com.intellectualcrafters.plot.config.C;
import com.intellectualcrafters.plot.database.DBFunc;
import com.intellectualcrafters.plot.object.Location;
import com.intellectualcrafters.plot.object.Plot;
import com.intellectualcrafters.plot.object.PlotId;
@ -35,7 +33,6 @@ import com.intellectualcrafters.plot.object.comment.CommentInbox;
import com.intellectualcrafters.plot.object.comment.CommentManager;
import com.intellectualcrafters.plot.object.comment.PlotComment;
import com.intellectualcrafters.plot.util.MainUtil;
import com.intellectualcrafters.plot.util.Permissions;
public class Comment extends SubCommand {
public Comment() {

View File

@ -21,7 +21,6 @@
package com.intellectualcrafters.plot.commands;
import com.intellectualcrafters.plot.PlotSquared;
import com.intellectualcrafters.plot.commands.SubCommand.CommandCategory;
import com.intellectualcrafters.plot.config.C;
import com.intellectualcrafters.plot.object.Location;
import com.intellectualcrafters.plot.object.Plot;

View File

@ -21,14 +21,15 @@
package com.intellectualcrafters.plot.commands;
import com.intellectualcrafters.plot.PlotSquared;
import com.intellectualcrafters.plot.config.C;
import com.intellectualcrafters.plot.listeners.worldedit.WEListener;
import com.intellectualcrafters.plot.object.PlotPlayer;
import com.intellectualcrafters.plot.util.MainUtil;
import com.intellectualcrafters.plot.util.Permissions;
import com.intellectualcrafters.plot.util.bukkit.PWE;
public class WE_Anywhere extends SubCommand {
public WE_Anywhere() {
super("weanywhere", "plots.weanywhere", "Force bypass of WorldEdit", "weanywhere", "wea", CommandCategory.DEBUG, true);
super("weanywhere", "plots.worldedit.bypass", "Force bypass of WorldEdit", "weanywhere", "wea", CommandCategory.DEBUG, true);
}
@Override
@ -37,12 +38,15 @@ public class WE_Anywhere extends SubCommand {
MainUtil.sendMessage(plr, "&cWorldEdit is not enabled on this server");
return false;
}
if (Permissions.hasPermission(plr, "plots.worldedit.bypass") && PWE.hasMask(plr)) {
PWE.removeMask(plr);
MainUtil.sendMessage(plr, "&6Cleared your WorldEdit mask");
} else {
PWE.setMask(plr, plr.getLocation(), true);
MainUtil.sendMessage(plr, "&6Updated your WorldEdit mask");
if (Permissions.hasPermission(plr, "plots.worldedit.bypass")) {
if (WEListener.bypass.contains(plr.getName())) {
WEListener.bypass.remove(plr.getName());
MainUtil.sendMessage(plr, C.WORLDEDIT_RESTRICTED);
}
else {
WEListener.bypass.add(plr.getName());
MainUtil.sendMessage(plr, C.WORLDEDIT_UNMASKED);
}
}
return true;
}

View File

@ -86,6 +86,8 @@ public enum C {
* WorldEdit masks
*/
REQUIRE_SELECTION_IN_MASK("$2%s of your selection is not within your plot mask. You can only make edits within your plot."),
WORLDEDIT_UNMASKED("$1Your WorldEdit is now unrestricted."),
WORLDEDIT_RESTRICTED("$1Your WorldEdit is now restricted."),
/*
* Records
*/

View File

@ -145,6 +145,7 @@ public class Settings {
* Use offline mode storage
*/
public static boolean OFFLINE_MODE = false;
public static boolean UUID_LOWERCASE = false;
/**
* Command confirmation
*/

View File

@ -1,7 +1,6 @@
package com.intellectualcrafters.plot.generator;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
@ -21,12 +20,10 @@ import com.intellectualcrafters.plot.object.Location;
import com.intellectualcrafters.plot.object.Plot;
import com.intellectualcrafters.plot.object.PlotBlock;
import com.intellectualcrafters.plot.object.PlotWorld;
import com.intellectualcrafters.plot.object.RegionWrapper;
import com.intellectualcrafters.plot.object.RunnableVal;
import com.intellectualcrafters.plot.util.ChunkManager;
import com.intellectualcrafters.plot.util.MainUtil;
import com.intellectualcrafters.plot.util.TaskManager;
import com.intellectualcrafters.plot.util.bukkit.BukkitSetBlockManager;
import com.intellectualcrafters.plot.util.bukkit.BukkitUtil;
public class BukkitHybridUtils extends HybridUtils {

View File

@ -2,7 +2,6 @@ package com.intellectualcrafters.plot.generator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map.Entry;
import org.bukkit.World;
import org.bukkit.block.Biome;

View File

@ -7,7 +7,6 @@ import org.bukkit.block.BlockState;
import org.bukkit.entity.Entity;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.block.BlockPhysicsEvent;
import org.bukkit.event.world.ChunkLoadEvent;
import org.bukkit.event.world.ChunkUnloadEvent;

View File

@ -83,6 +83,7 @@ import com.intellectualcrafters.plot.config.Settings;
import com.intellectualcrafters.plot.database.DBFunc;
import com.intellectualcrafters.plot.flag.Flag;
import com.intellectualcrafters.plot.flag.FlagManager;
import com.intellectualcrafters.plot.listeners.worldedit.WEListener;
import com.intellectualcrafters.plot.object.BukkitPlayer;
import com.intellectualcrafters.plot.object.Location;
import com.intellectualcrafters.plot.object.Plot;
@ -93,13 +94,10 @@ import com.intellectualcrafters.plot.object.PlotManager;
import com.intellectualcrafters.plot.object.PlotPlayer;
import com.intellectualcrafters.plot.object.PlotWorld;
import com.intellectualcrafters.plot.object.StringWrapper;
import com.intellectualcrafters.plot.object.comment.CommentManager;
import com.intellectualcrafters.plot.util.ChunkManager;
import com.intellectualcrafters.plot.util.CmdConfirm;
import com.intellectualcrafters.plot.util.EventUtil;
import com.intellectualcrafters.plot.util.MainUtil;
import com.intellectualcrafters.plot.util.Permissions;
import com.intellectualcrafters.plot.util.SetupUtils;
import com.intellectualcrafters.plot.util.TaskManager;
import com.intellectualcrafters.plot.util.bukkit.BukkitUtil;
import com.intellectualcrafters.plot.util.bukkit.UUIDHandler;
@ -461,6 +459,7 @@ public class PlayerEvents extends com.intellectualcrafters.plot.listeners.PlotLi
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public static void onWorldChanged(final PlayerChangedWorldEvent event) {
final PlotPlayer player = BukkitUtil.getPlayer(event.getPlayer());
WEListener.bypass.remove(player.getName());
((BukkitPlayer) player).hasPerm = new HashSet<>();
((BukkitPlayer) player).noPerm = new HashSet<>();
}
@ -1020,6 +1019,7 @@ public class PlayerEvents extends com.intellectualcrafters.plot.listeners.PlotLi
public static void onLeave(final PlayerQuitEvent event) {
PlotPlayer pp = BukkitUtil.getPlayer(event.getPlayer());
EventUtil.unregisterPlayer(pp);
WEListener.bypass.remove(pp.getName());
if (Settings.DELETE_PLOTS_ON_BAN && event.getPlayer().isBanned()) {
final Collection<Plot> plots = PlotSquared.getPlots(pp.getName()).values();
for (final Plot plot : plots) {

View File

@ -1,266 +0,0 @@
////////////////////////////////////////////////////////////////////////////////////////////////////
// PlotSquared - A plot manager and world generator for the Bukkit API /
// Copyright (c) 2014 IntellectualSites/IntellectualCrafters /
// /
// This program is free software; you can redistribute it and/or modify /
// it under the terms of the GNU General Public License as published by /
// the Free Software Foundation; either version 3 of the License, or /
// (at your option) any later version. /
// /
// This program is distributed in the hope that it will be useful, /
// but WITHOUT ANY WARRANTY; without even the implied warranty of /
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the /
// GNU General Public License for more details. /
// /
// You should have received a copy of the GNU General Public License /
// along with this program; if not, write to the Free Software Foundation, /
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA /
// /
// You can contact us via: support@intellectualsites.com /
////////////////////////////////////////////////////////////////////////////////////////////////////
package com.intellectualcrafters.plot.listeners;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.UUID;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerMoveEvent;
import org.bukkit.event.player.PlayerPortalEvent;
import org.bukkit.event.player.PlayerTeleportEvent;
import com.intellectualcrafters.plot.PlotSquared;
import com.intellectualcrafters.plot.config.C;
import com.intellectualcrafters.plot.config.Settings;
import com.intellectualcrafters.plot.database.DBFunc;
import com.intellectualcrafters.plot.events.PlotDeleteEvent;
import com.intellectualcrafters.plot.object.Plot;
import com.intellectualcrafters.plot.object.PlotHandler;
import com.intellectualcrafters.plot.object.PlotId;
import com.intellectualcrafters.plot.object.PlotPlayer;
import com.intellectualcrafters.plot.util.MainUtil;
import com.intellectualcrafters.plot.util.Permissions;
import com.intellectualcrafters.plot.util.bukkit.BukkitUtil;
import com.intellectualcrafters.plot.util.bukkit.PWE;
import com.intellectualcrafters.plot.util.bukkit.UUIDHandler;
import com.sk89q.worldedit.BlockVector;
import com.sk89q.worldedit.LocalSession;
import com.sk89q.worldedit.bukkit.selections.Selection;
import com.sk89q.worldedit.function.mask.Mask;
/**
* @author Citymonstret
* @author Empire92
*/
public class WorldEditListener implements Listener {
final List<String> monitored = Arrays.asList(new String[] { "set", "replace", "overlay", "walls", "outline", "deform", "hollow", "smooth", "move", "stack", "naturalize", "paste", "count", "regen", "copy", "cut", "" });
public final Set<String> blockedcmds = new HashSet<>(Arrays.asList("/gmask", "//gmask", "/worldedit:gmask"));
public final Set<String> restrictedcmds = new HashSet<>(Arrays.asList("/up", "//up", "/worldedit:up"));
private boolean isPlotWorld(final Location l) {
return (PlotSquared.isPlotWorld(l.getWorld().getName()));
}
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
public void onDelete(final PlotDeleteEvent e) {
final String world = e.getWorld();
final PlotId id = e.getPlotId();
final Plot plot = PlotSquared.getPlots(world).get(id);
if (plot == null) {
return;
}
HashSet<UUID> members = PlotHandler.getOwners(plot);
if (members == null) {
return;
}
members.addAll(plot.helpers);
for (UUID member : members) {
final PlotPlayer player = UUIDHandler.getPlayer(member);
if (player == null) {
continue;
}
if (!world.equals(player.getLocation().getWorld())) {
return;
}
if (Permissions.hasPermission(player, "plots.worldedit.bypass")) {
return;
}
PWE.setNoMask(player);
}
}
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
public void onInteract(final PlayerInteractEvent e) {
final Block b = e.getClickedBlock();
if (b == null) {
return;
}
final Player p = e.getPlayer();
final Location l = b.getLocation();
if (!isPlotWorld(l)) {
return;
}
p.getItemInHand();
if ((p.getItemInHand() == null) || (p.getItemInHand().getType() == Material.AIR)) {
return;
}
final PlotPlayer pp = BukkitUtil.getPlayer(p);
final com.intellectualcrafters.plot.object.Location loc = pp.getLocation();
final Plot plot = MainUtil.getPlot(loc);
if (plot != null) {
if (plot.hasOwner() && (plot.helpers != null) && (plot.helpers.contains(DBFunc.everyone) || plot.helpers.contains(pp.getUUID()))) {
PWE.setMask(BukkitUtil.getPlayer(p), loc, false);
}
}
}
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
public void onPlayerCommand(final PlayerCommandPreprocessEvent e) {
final Player p = e.getPlayer();
final PlotPlayer pp = BukkitUtil.getPlayer(p);
if (!PlotSquared.isPlotWorld(p.getWorld().getName()) || Permissions.hasPermission(pp, "plots.worldedit.bypass")) {
return;
}
String cmd = e.getMessage().toLowerCase();
if (cmd.contains(" ")) {
cmd = cmd.substring(0, cmd.indexOf(" "));
}
if (this.restrictedcmds.contains(cmd)) {
final Plot plot = MainUtil.getPlot(pp.getLocation());
if ((plot == null) || !(plot.helpers.contains(DBFunc.everyone) || plot.helpers.contains(pp.getUUID()))) {
e.setCancelled(true);
}
return;
} else if (this.blockedcmds.contains(cmd)) {
e.setCancelled(true);
return;
}
if (!Settings.REQUIRE_SELECTION) {
return;
}
for (final String c : this.monitored) {
if (cmd.equals("//" + c) || cmd.equals("/" + c) || cmd.equals("/worldedit:/" + c)) {
final Selection selection = PlotSquared.worldEdit.getSelection(p);
if (selection == null) {
return;
}
final BlockVector pos1 = selection.getNativeMinimumPoint().toBlockVector();
final BlockVector pos2 = selection.getNativeMaximumPoint().toBlockVector();
final LocalSession session = PlotSquared.worldEdit.getSession(p);
final Mask mask = session.getMask();
if (mask == null) {
MainUtil.sendMessage(pp, C.REQUIRE_SELECTION_IN_MASK, "Both points");
return;
}
if (!mask.test(pos1)) {
e.setCancelled(true);
MainUtil.sendMessage(pp, C.REQUIRE_SELECTION_IN_MASK, "Position 1");
}
if (!mask.test(pos2)) {
e.setCancelled(true);
MainUtil.sendMessage(pp, C.REQUIRE_SELECTION_IN_MASK, "Position 2");
}
}
}
}
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
public void onPlayerJoin(final PlayerJoinEvent e) {
final Player p = e.getPlayer();
final Location l = p.getLocation();
final PlotPlayer pp = BukkitUtil.getPlayer(p);
if (Permissions.hasPermission(pp, "plots.worldedit.bypass")) {
if (isPlotWorld(l)) {
PWE.removeMask(pp);
}
return;
}
if (isPlotWorld(l)) {
final com.intellectualcrafters.plot.object.Location loc = BukkitUtil.getLocation(l);
PWE.setMask(pp, loc, false);
} else {
PWE.removeMask(pp);
}
}
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onPlayerMove(final PlayerMoveEvent e) {
final Location t = e.getTo();
final Location f = e.getFrom();
final com.intellectualcrafters.plot.object.Location locf = BukkitUtil.getLocation(f);
final com.intellectualcrafters.plot.object.Location loct = BukkitUtil.getLocation(t);
if ((locf.getX() != loct.getX()) || (locf.getZ() != loct.getZ())) {
final Player p = e.getPlayer();
final PlotPlayer pp = BukkitUtil.getPlayer(p);
if (!isPlotWorld(t)) {
return;
}
final PlotId idF = MainUtil.getPlotId(locf);
final PlotId idT = MainUtil.getPlotId(loct);
if ((idT != null) && !(idF == idT)) {
if (Permissions.hasPermission(pp, "plots.worldedit.bypass")) {
if (!PWE.hasMask(pp)) {
return;
}
}
PWE.setMask(pp, loct, false);
}
}
}
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
public void onPortal(final PlayerPortalEvent e) {
final Player p = e.getPlayer();
final PlotPlayer pp = BukkitUtil.getPlayer(p);
if (Permissions.hasPermission(pp, "plots.worldedit.bypass")) {
return;
}
final Location t = e.getTo();
final Location f = e.getFrom();
if (t == null) {
PWE.removeMask(pp);
return;
}
if (isPlotWorld(t)) {
final com.intellectualcrafters.plot.object.Location loct = BukkitUtil.getLocation(t);
PWE.setMask(pp, loct, false);
return;
}
if ((f != null) && isPlotWorld(f)) {
PWE.removeMask(pp);
}
}
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
public void onTeleport(final PlayerTeleportEvent e) {
final Player p = e.getPlayer();
final PlotPlayer pp = BukkitUtil.getPlayer(p);
if (Permissions.hasPermission(pp, "plots.worldedit.bypass")) {
if (!PWE.hasMask(pp)) {
return;
}
}
final Location t = e.getTo();
final com.intellectualcrafters.plot.object.Location loct = BukkitUtil.getLocation(t);
final Location f = e.getFrom();
if (!PlotSquared.isPlotWorld(loct.getWorld())) {
if (isPlotWorld(f)) {
PWE.removeMask(pp);
}
return;
}
PWE.setMask(pp, loct, false);
}
}

View File

@ -0,0 +1,75 @@
package com.intellectualcrafters.plot.listeners.worldedit;
import java.util.ArrayList;
import java.util.List;
import com.sk89q.worldedit.Vector;
import com.sk89q.worldedit.Vector2D;
import com.sk89q.worldedit.WorldEditException;
import com.sk89q.worldedit.blocks.BaseBlock;
import com.sk89q.worldedit.entity.BaseEntity;
import com.sk89q.worldedit.entity.Entity;
import com.sk89q.worldedit.extent.Extent;
import com.sk89q.worldedit.function.operation.Operation;
import com.sk89q.worldedit.regions.Region;
import com.sk89q.worldedit.util.Location;
import com.sk89q.worldedit.world.biome.BaseBiome;
public class NullExtent implements Extent {
@Override
public BaseBiome getBiome(Vector2D arg0) {
return null;
}
@Override
public BaseBlock getBlock(Vector arg0) {
return null;
}
@Override
public BaseBlock getLazyBlock(Vector arg0) {
return null;
}
@Override
public Operation commit() {
return null;
}
@Override
public boolean setBiome(Vector2D arg0, BaseBiome arg1) {
return false;
}
@Override
public boolean setBlock(Vector arg0, BaseBlock arg1) throws WorldEditException {
return false;
}
@Override
public Entity createEntity(Location arg0, BaseEntity arg1) {
return null;
}
@Override
public List<? extends Entity> getEntities() {
return new ArrayList<>();
}
@Override
public List<? extends Entity> getEntities(Region arg0) {
return new ArrayList<>();
}
@Override
public Vector getMaximumPoint() {
return new Vector(0, 0, 0);
}
@Override
public Vector getMinimumPoint() {
return new Vector(0, 0, 0);
}
}

View File

@ -0,0 +1,48 @@
package com.intellectualcrafters.plot.listeners.worldedit;
import java.util.HashSet;
import com.intellectualcrafters.plot.object.RegionWrapper;
import com.sk89q.worldedit.Vector;
import com.sk89q.worldedit.Vector2D;
import com.sk89q.worldedit.WorldEditException;
import com.sk89q.worldedit.blocks.BaseBlock;
import com.sk89q.worldedit.entity.BaseEntity;
import com.sk89q.worldedit.entity.Entity;
import com.sk89q.worldedit.extent.AbstractDelegateExtent;
import com.sk89q.worldedit.extent.Extent;
import com.sk89q.worldedit.util.Location;
import com.sk89q.worldedit.world.biome.BaseBiome;
public class WEExtent extends AbstractDelegateExtent {
private final HashSet<RegionWrapper> mask;
public WEExtent(HashSet<RegionWrapper> mask, Extent extent) {
super(extent);
this.mask = mask;
}
@Override
public boolean setBlock(Vector location, BaseBlock block) throws WorldEditException {
if (WEListener.maskContains(mask, location.getBlockX(), location.getBlockZ())) {
return super.setBlock(location, block);
}
return false;
}
@Override
public Entity createEntity(Location location, BaseEntity entity) {
if (WEListener.maskContains(mask, location.getBlockX(), location.getBlockZ())) {
return super.createEntity(location, entity);
}
return null;
}
@Override
public boolean setBiome(Vector2D position, BaseBiome biome) {
if (WEListener.maskContains(mask, position.getBlockX(), position.getBlockZ())) {
return super.setBiome(position, biome);
}
return false;
}
}

View File

@ -0,0 +1,165 @@
package com.intellectualcrafters.plot.listeners.worldedit;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
import com.intellectualcrafters.plot.PlotSquared;
import com.intellectualcrafters.plot.config.C;
import com.intellectualcrafters.plot.config.Settings;
import com.intellectualcrafters.plot.database.DBFunc;
import com.intellectualcrafters.plot.object.Location;
import com.intellectualcrafters.plot.object.Plot;
import com.intellectualcrafters.plot.object.PlotPlayer;
import com.intellectualcrafters.plot.object.RegionWrapper;
import com.intellectualcrafters.plot.util.MainUtil;
import com.intellectualcrafters.plot.util.Permissions;
import com.intellectualcrafters.plot.util.bukkit.BukkitUtil;
import com.intellectualcrafters.plot.util.bukkit.UUIDHandler;
import com.sk89q.worldedit.BlockVector;
import com.sk89q.worldedit.IncompleteRegionException;
import com.sk89q.worldedit.Vector;
import com.sk89q.worldedit.WorldEdit;
import com.sk89q.worldedit.bukkit.selections.Selection;
import com.sk89q.worldedit.event.extent.EditSessionEvent;
import com.sk89q.worldedit.extension.platform.Actor;
import com.sk89q.worldedit.regions.Region;
import com.sk89q.worldedit.util.eventbus.EventHandler.Priority;
import com.sk89q.worldedit.util.eventbus.Subscribe;
public class WEListener implements Listener {
public static HashSet<String> bypass = new HashSet<>();
final List<String> monitored = Arrays.asList(new String[] { "set", "replace", "overlay", "walls", "outline", "deform", "hollow", "smooth", "move", "stack", "naturalize", "paste", "count", "regen", "copy", "cut", "" });
public final Set<String> blockedcmds = new HashSet<>(Arrays.asList("/gmask", "//gmask", "/worldedit:gmask"));
public final Set<String> restrictedcmds = new HashSet<>(Arrays.asList("/up", "//up", "/worldedit:up"));
@Subscribe(priority=Priority.VERY_EARLY)
public void onEditSession(EditSessionEvent event) {
String world = event.getWorld().getName();
if (!PlotSquared.isPlotWorld(world)) {
return;
}
Actor actor = event.getActor();
if (actor != null && actor.isPlayer()) {
String name = actor.getName();
if (bypass.contains(name)) {
return;
}
PlotPlayer player = UUIDHandler.getPlayer(actor.getName());
HashSet<RegionWrapper> mask = getMask(player);
if (mask.size() == 0) {
event.setExtent(new NullExtent());
return;
}
try {
Region selection = WorldEdit.getInstance().getSession(player.getName()).getSelection(event.getWorld());
Vector pos1 = selection.getMinimumPoint();
Vector pos2 = selection.getMaximumPoint();
RegionWrapper regionSelection = new RegionWrapper(Math.min(pos1.getBlockX(), pos2.getBlockX()), Math.max(pos1.getBlockX(), pos2.getBlockX()), Math.min(pos1.getBlockZ(), pos2.getBlockZ()), Math.max(pos1.getBlockZ(), pos2.getBlockZ()));
if (!regionContains(regionSelection, mask)) {
event.setExtent(new NullExtent());
return;
}
} catch (IncompleteRegionException e) {}
event.setExtent(new WEExtent(mask, event.getExtent()));
}
}
public static boolean maskContains(HashSet<RegionWrapper> mask, int x, int z) {
for (RegionWrapper region : mask) {
if ((x >= region.minX) && (x <= region.maxX) && (z >= region.minZ) && (z <= region.maxZ)) {
return true;
}
}
return false;
}
public static boolean intersects(RegionWrapper region1, RegionWrapper region2) {
if ((region1.minX <= region2.maxX) && (region1.maxX >= region2.minX) && (region1.minZ <= region2.maxZ) && (region1.maxZ >= region2.minZ)) {
return true;
}
return false;
}
public static boolean regionContains(RegionWrapper selection, HashSet<RegionWrapper> mask) {
for (RegionWrapper region : mask) {
if (intersects(region, selection)) {
return true;
}
}
return false;
}
public HashSet<RegionWrapper> getMask(PlotPlayer player) {
HashSet<RegionWrapper> regions = new HashSet<>();
for (Plot plot : PlotSquared.getPlots(player)) {
if (!plot.settings.getMerged(1) && !plot.settings.getMerged(2)) {
Location pos1 = MainUtil.getPlotBottomLoc(plot.world, plot.id).add(1, 0, 1);
Location pos2 = MainUtil.getPlotTopLoc(plot.world, plot.id);
regions.add(new RegionWrapper(pos1.getX(), pos2.getX(), pos1.getZ(), pos2.getZ()));
}
}
return regions;
}
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
public void onPlayerCommand(final PlayerCommandPreprocessEvent e) {
final Player p = e.getPlayer();
final PlotPlayer pp = BukkitUtil.getPlayer(p);
if (!PlotSquared.isPlotWorld(p.getWorld().getName()) || Permissions.hasPermission(pp, "plots.worldedit.bypass")) {
return;
}
String cmd = e.getMessage().toLowerCase();
if (cmd.contains(" ")) {
cmd = cmd.substring(0, cmd.indexOf(" "));
}
if (this.restrictedcmds.contains(cmd)) {
final Plot plot = MainUtil.getPlot(pp.getLocation());
if ((plot == null) || !(plot.helpers.contains(DBFunc.everyone) || plot.helpers.contains(pp.getUUID()))) {
e.setCancelled(true);
}
return;
} else if (this.blockedcmds.contains(cmd)) {
e.setCancelled(true);
return;
}
if (!Settings.REQUIRE_SELECTION) {
return;
}
for (final String c : this.monitored) {
if (cmd.equals("//" + c) || cmd.equals("/" + c) || cmd.equals("/worldedit:/" + c)) {
final Selection selection = PlotSquared.worldEdit.getSelection(p);
if (selection == null) {
return;
}
final BlockVector pos1 = selection.getNativeMinimumPoint().toBlockVector();
final BlockVector pos2 = selection.getNativeMaximumPoint().toBlockVector();
HashSet<RegionWrapper> mask = getMask(pp);
if (mask.size() == 0) {
MainUtil.sendMessage(pp, C.REQUIRE_SELECTION_IN_MASK, "Both points");
return;
}
if (!maskContains(mask, pos1.getBlockX(), pos1.getBlockZ())) {
e.setCancelled(true);
MainUtil.sendMessage(pp, C.REQUIRE_SELECTION_IN_MASK, "Position 1");
}
if (!maskContains(mask, pos2.getBlockX(), pos2.getBlockZ())) {
e.setCancelled(true);
MainUtil.sendMessage(pp, C.REQUIRE_SELECTION_IN_MASK, "Position 2");
}
}
}
}
}

View File

@ -1,6 +1,5 @@
package com.intellectualcrafters.plot.object;
import java.util.HashMap;
import java.util.HashSet;
import java.util.UUID;

View File

@ -2,9 +2,7 @@ package com.intellectualcrafters.plot.object.comment;
import java.util.HashMap;
import com.intellectualcrafters.plot.config.Settings;
import com.intellectualcrafters.plot.object.PlotPlayer;
import com.intellectualcrafters.plot.util.TaskManager;
public class CommentManager {

View File

@ -1,20 +1,17 @@
package com.intellectualcrafters.plot.util.bukkit;
import java.io.IOException;
import java.util.List;
import java.util.Map.Entry;
import org.bukkit.Bukkit;
import org.bukkit.World;
import org.bukkit.World.Environment;
import org.bukkit.WorldCreator;
import org.bukkit.generator.BlockPopulator;
import org.bukkit.generator.ChunkGenerator;
import org.bukkit.plugin.Plugin;
import com.intellectualcrafters.plot.PlotSquared;
import com.intellectualcrafters.plot.config.ConfigurationNode;
import com.intellectualcrafters.plot.generator.SquarePlotManager;
import com.intellectualcrafters.plot.object.PlotGenerator;
import com.intellectualcrafters.plot.object.PlotWorld;
import com.intellectualcrafters.plot.object.SetupObject;

View File

@ -1,132 +0,0 @@
////////////////////////////////////////////////////////////////////////////////////////////////////
// PlotSquared - A plot manager and world generator for the Bukkit API /
// Copyright (c) 2014 IntellectualSites/IntellectualCrafters /
// /
// This program is free software; you can redistribute it and/or modify /
// it under the terms of the GNU General Public License as published by /
// the Free Software Foundation; either version 3 of the License, or /
// (at your option) any later version. /
// /
// This program is distributed in the hope that it will be useful, /
// but WITHOUT ANY WARRANTY; without even the implied warranty of /
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the /
// GNU General Public License for more details. /
// /
// You should have received a copy of the GNU General Public License /
// along with this program; if not, write to the Free Software Foundation, /
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA /
// /
// You can contact us via: support@intellectualsites.com /
////////////////////////////////////////////////////////////////////////////////////////////////////
package com.intellectualcrafters.plot.util.bukkit;
import com.intellectualcrafters.plot.PlotSquared;
import com.intellectualcrafters.plot.database.DBFunc;
import com.intellectualcrafters.plot.flag.FlagManager;
import com.intellectualcrafters.plot.object.BukkitPlayer;
import com.intellectualcrafters.plot.object.Location;
import com.intellectualcrafters.plot.object.Plot;
import com.intellectualcrafters.plot.object.PlotHandler;
import com.intellectualcrafters.plot.object.PlotId;
import com.intellectualcrafters.plot.object.PlotPlayer;
import com.intellectualcrafters.plot.util.MainUtil;
import com.sk89q.worldedit.LocalSession;
import com.sk89q.worldedit.LocalWorld;
import com.sk89q.worldedit.Vector;
import com.sk89q.worldedit.WorldEdit;
import com.sk89q.worldedit.function.mask.Mask;
import com.sk89q.worldedit.function.mask.RegionMask;
import com.sk89q.worldedit.regions.CuboidRegion;
/**
* @author Citymonstret
* @author Empire92
*/
public class PWE {
public static LocalSession getSession(PlotPlayer p) {
if (PlotSquared.worldEdit == null) {
return WorldEdit.getInstance().getSession(p.getName());
} else {
return PlotSquared.worldEdit.getSession(((BukkitPlayer) p).player);
}
}
public static void setMask(final PlotPlayer p, final Location l, final boolean force) {
try {
LocalSession s = getSession(p);
if (!PlotSquared.isPlotWorld(l.getWorld())) {
removeMask(p);
}
final PlotId id = MainUtil.getPlotId(l);
if (id != null) {
final Plot plot = PlotSquared.getPlots(l.getWorld()).get(id);
if (plot != null) {
if (FlagManager.isPlotFlagTrue(plot, "no-worldedit")) {
return;
}
final boolean r = (PlotHandler.isOwner(plot, p.getUUID())) || plot.helpers.contains(DBFunc.everyone) || plot.helpers.contains(p.getUUID());
if (r) {
final String w = l.getWorld();
final Location bloc = MainUtil.getPlotBottomLoc(w, plot.id);
final Location tloc = MainUtil.getPlotTopLoc(w, plot.id);
final Vector bvec = new Vector(bloc.getX() + 1, bloc.getY(), bloc.getZ() + 1);
final Vector tvec = new Vector(tloc.getX(), tloc.getY(), tloc.getZ());
// FIXME unchecked casting
final LocalWorld lw = PlotSquared.worldEdit.wrapPlayer(((BukkitPlayer) p).player).getWorld();
final CuboidRegion region = new CuboidRegion(lw, bvec, tvec);
final RegionMask mask = new RegionMask(region);
s.setMask(mask);
return;
}
}
}
if (force ^ (noMask(s) && !p.hasPermission("plots.worldedit.bypass"))) {
// FIXME unchecked casting
final com.sk89q.worldedit.bukkit.BukkitPlayer plr = PlotSquared.worldEdit.wrapPlayer(((BukkitPlayer) p).player);
final Vector p1 = new Vector(69, 69, 69), p2 = new Vector(69, 69, 69);
s.setMask(new RegionMask(new CuboidRegion(plr.getWorld(), p1, p2)));
}
} catch (final Exception e) {
e.printStackTrace();
}
}
public static boolean hasMask(final PlotPlayer p) {
LocalSession s = getSession(p);
return !noMask(s);
}
public static boolean noMask(final LocalSession s) {
return s.getMask() == null;
}
@SuppressWarnings("deprecation")
public static void setNoMask(final PlotPlayer p) {
try {
LocalSession s = getSession(p);
final com.sk89q.worldedit.bukkit.BukkitPlayer plr = PlotSquared.worldEdit.wrapPlayer(((BukkitPlayer) p).player);
final Vector p1 = new Vector(69, 69, 69), p2 = new Vector(69, 69, 69);
s.setMask(new RegionMask(new CuboidRegion(plr.getWorld(), p1, p2)));
} catch (final Exception e) {
//
}
}
public static void removeMask(final PlotPlayer p, final LocalSession s) {
final Mask mask = null;
s.setMask(mask);
}
public static void removeMask(final PlotPlayer p) {
try {
LocalSession s = getSession(p);
removeMask(p, s);
} catch (final Exception e) {
// throw new
// PlotSquaredException(PlotSquaredException.PlotError.MISSING_DEPENDENCY,
// "WorldEdit == Null?");
}
}
}

View File

@ -0,0 +1,106 @@
package com.intellectualcrafters.plot.uuid;
import java.lang.reflect.Method;
import java.util.Collection;
import java.util.UUID;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import org.bukkit.Server;
import org.bukkit.entity.Player;
import com.google.common.base.Charsets;
import com.google.common.collect.BiMap;
import com.intellectualcrafters.plot.PlotSquared;
import com.intellectualcrafters.plot.object.BukkitOfflinePlayer;
import com.intellectualcrafters.plot.object.OfflinePlotPlayer;
import com.intellectualcrafters.plot.object.PlotPlayer;
import com.intellectualcrafters.plot.object.StringWrapper;
import com.intellectualcrafters.plot.util.bukkit.UUIDHandler;
public class LowerOfflineUUIDWrapper extends UUIDWrapper {
private Method getOnline = null;
private final Object[] arg = new Object[0];
public LowerOfflineUUIDWrapper() {
try {
this.getOnline = Server.class.getMethod("getOnlinePlayers", new Class[0]);
} catch (final NoSuchMethodException e) {
e.printStackTrace();
} catch (final SecurityException e) {
e.printStackTrace();
}
}
@Override
public UUID getUUID(final PlotPlayer player) {
return UUID.nameUUIDFromBytes(("OfflinePlayer:" + player.getName().toLowerCase()).getBytes(Charsets.UTF_8));
}
@Override
public UUID getUUID(final OfflinePlotPlayer player) {
return UUID.nameUUIDFromBytes(("OfflinePlayer:" + player.getName().toLowerCase()).getBytes(Charsets.UTF_8));
}
public UUID getUUID(final OfflinePlayer player) {
return UUID.nameUUIDFromBytes(("OfflinePlayer:" + player.getName().toLowerCase() ).getBytes(Charsets.UTF_8));
}
@Override
public OfflinePlotPlayer getOfflinePlayer(final UUID uuid) {
final BiMap<UUID, StringWrapper> map = UUIDHandler.getUuidMap().inverse();
String name;
try {
name = map.get(uuid).value;
} catch (final NullPointerException e) {
name = null;
}
if (name != null) {
final OfflinePlayer op = Bukkit.getOfflinePlayer(name);
if (op.hasPlayedBefore()) {
return new BukkitOfflinePlayer(op);
}
}
for (final OfflinePlayer player : Bukkit.getOfflinePlayers()) {
if (getUUID(player).equals(uuid)) {
return new BukkitOfflinePlayer(player);
}
}
return null;
}
public Player[] getOnlinePlayers() {
if (this.getOnline == null) {
return Bukkit.getOnlinePlayers().toArray(new Player[0]);
}
try {
final Object players = this.getOnline.invoke(Bukkit.getServer(), this.arg);
if (players instanceof Player[]) {
return (Player[]) players;
} else {
@SuppressWarnings("unchecked")
final Collection<? extends Player> p = (Collection<? extends Player>) players;
return p.toArray(new Player[0]);
}
} catch (final Exception e) {
PlotSquared.log("Failed to resolve online players");
this.getOnline = null;
return Bukkit.getOnlinePlayers().toArray(new Player[0]);
}
}
@Override
public UUID getUUID(final String name) {
return UUID.nameUUIDFromBytes(("OfflinePlayer:" + name.toLowerCase()).getBytes(Charsets.UTF_8));
}
@Override
public OfflinePlotPlayer[] getOfflinePlayers() {
OfflinePlayer[] ops = Bukkit.getOfflinePlayers();
BukkitOfflinePlayer[] toReturn = new BukkitOfflinePlayer[ops.length] ;
for (int i = 0; i < ops.length; i++) {
toReturn[i] = new BukkitOfflinePlayer(ops[i]);
}
return toReturn;
}
}