diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/PlotMain.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/PlotMain.java index 900ad0a76..0b052417a 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/PlotMain.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/PlotMain.java @@ -929,6 +929,7 @@ public class PlotMain extends JavaPlugin { options.put("teleport.on_login", Settings.TELEPORT_ON_LOGIN); options.put("perm-based-mob-cap.enabled", Settings.MOB_CAP_ENABLED); options.put("perm-based-mob-cap.max", Settings.MOB_CAP); + options.put("worldedit.require-selection-in-mask",Settings.REQUIRE_SELECTION); for (final Entry node : options.entrySet()) { if (!config.contains(node.getKey())) { @@ -951,6 +952,8 @@ public class PlotMain extends JavaPlugin { Settings.MOB_CAP = config.getInt("perm-based-mob-cap.max"); Settings.MAX_PLOTS = config.getInt("max_plots"); Settings.SCHEMATIC_SAVE_PATH = config.getString("schematics.save_path"); + + Settings.REQUIRE_SELECTION = config.getBoolean("worldedit.require-selection-in-mask"); } /** @@ -1540,7 +1543,9 @@ public class PlotMain extends JavaPlugin { final String version = worldEdit.getDescription().getVersion(); if ((version != null) && version.startsWith("5.")) { - PlotMain.sendConsoleSenderMessage("&cPlease update to WorldEdit 6 for improved stability and additional features:\nhttp://builds.enginehub.org/job/worldedit"); + PlotMain.sendConsoleSenderMessage("&cThis version of WorldEdit does not support PlotSquared."); + PlotMain.sendConsoleSenderMessage("&cPlease use WorldEdit 6+"); + PlotMain.sendConsoleSenderMessage("&c - http://builds.enginehub.org/job/worldedit"); } else { getServer().getPluginManager().registerEvents(new WorldEditListener(), this); } diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/config/C.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/config/C.java index afe65a1d0..e7542f67a 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/config/C.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/config/C.java @@ -32,6 +32,10 @@ import org.bukkit.ChatColor; * @author Citymonstret */ public enum C { + /* + * WorldEdit masks + */ + REQUIRE_SELECTION_IN_MASK("&c%s of your selection is not within your plot mask. You can only make edits within your plot."), /* * Records */ diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/config/Settings.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/config/Settings.java index b7ea1c113..a8be141cb 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/config/Settings.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/config/Settings.java @@ -29,6 +29,10 @@ package com.intellectualcrafters.plot.config; */ public class Settings { + /** + * Default worldedit-require-selection-in-mask: false + */ + public static boolean REQUIRE_SELECTION = true; /** * Default kill road mobs: true */ diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/listeners/WorldEditListener.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/listeners/WorldEditListener.java index d1fe13e9c..a02e2e94c 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/listeners/WorldEditListener.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/listeners/WorldEditListener.java @@ -22,6 +22,8 @@ package com.intellectualcrafters.plot.listeners; import com.intellectualcrafters.plot.PlotMain; +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; @@ -29,6 +31,13 @@ import com.intellectualcrafters.plot.object.PlotId; import com.intellectualcrafters.plot.util.PWE; import com.intellectualcrafters.plot.util.PlayerFunctions; import com.intellectualcrafters.plot.util.PlotHelper; +import com.sk89q.worldedit.BlockVector; +import com.sk89q.worldedit.LocalSession; +import com.sk89q.worldedit.bukkit.selections.Selection; +import com.sk89q.worldedit.function.mask.Mask; +import com.sk89q.worldedit.regions.CuboidRegion; +import com.sk89q.worldedit.world.World; + import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.Material; @@ -41,6 +50,7 @@ import org.bukkit.event.player.*; import java.util.Arrays; import java.util.HashSet; +import java.util.List; import java.util.Set; /** @@ -50,6 +60,8 @@ import java.util.Set; @SuppressWarnings("unused") public class WorldEditListener implements Listener { + final List monitored = Arrays.asList(new String[] { "set", "replace", "overlay", "walls", "outline", "deform", "hollow", "smooth", "move", "stack", "naturalize", "paste", "count", "regen", "copy", "cut", "" }); + public final Set blockedcmds = new HashSet<>(Arrays.asList("/gmask", "//gmask", "/worldedit:gmask")); public final Set restrictedcmds = new HashSet<>(Arrays.asList("/up", "//up", "/worldedit:up")); @@ -104,7 +116,7 @@ public class WorldEditListener implements Listener { @EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true) public void onPlayerCommand(final PlayerCommandPreprocessEvent e) { final Player p = e.getPlayer(); - if (PlotMain.hasPermission(p, "plots.worldedit.bypass") || !PlotMain.isPlotWorld(p.getWorld())) { + if (!PlotMain.isPlotWorld(p.getWorld()) || PlotMain.hasPermission(p, "plots.worldedit.bypass")) { return; } String cmd = e.getMessage().toLowerCase(); @@ -117,9 +129,40 @@ public class WorldEditListener implements Listener { if ((plot == null) || !(plot.helpers.contains(DBFunc.everyone) || plot.helpers.contains(p.getUniqueId()))) { e.setCancelled(true); } + return; } else if (this.blockedcmds.contains(cmd)) { e.setCancelled(true); + return; } + if (!Settings.REQUIRE_SELECTION) { + return; + } + for (final String c : monitored) { + if (cmd.equals("//" + c) || cmd.equals("/" + c) || cmd.equals("/worldedit:/" + c)) { + final Selection selection = PlotMain.worldEdit.getSelection(p); + if (selection == null) { + return; + } + final BlockVector pos1 = selection.getNativeMinimumPoint().toBlockVector(); + final BlockVector pos2 = selection.getNativeMaximumPoint().toBlockVector(); + + LocalSession session = PlotMain.worldEdit.getSession(p); + Mask mask = session.getMask(); + if (mask == null) { + PlayerFunctions.sendMessage(p, C.REQUIRE_SELECTION_IN_MASK, "Both points"); + return; + } + if (!mask.test(pos1)) { + e.setCancelled(true); + PlayerFunctions.sendMessage(p, C.REQUIRE_SELECTION_IN_MASK, "Position 1"); + } + if (!mask.test(pos2)) { + e.setCancelled(true); + PlayerFunctions.sendMessage(p, C.REQUIRE_SELECTION_IN_MASK, "Position 2"); + } + } + } + } @EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true) diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/PlayerFunctions.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/PlayerFunctions.java index a15250326..8f23f1143 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/PlayerFunctions.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/PlayerFunctions.java @@ -308,7 +308,6 @@ public class PlayerFunctions { String msg = c.s(); if ((args != null) && (args.length > 0)) { for (final String str : args) { - System.out.print(str); if (msg.contains("%s")) { msg = msg.replaceFirst("%s", str); }