mirror of
https://github.com/IntellectualSites/PlotSquared.git
synced 2024-11-26 15:16:45 +01:00
Additional mask checking for WE
This commit is contained in:
parent
0fca78c61a
commit
17f2a89c66
@ -929,6 +929,7 @@ public class PlotMain extends JavaPlugin {
|
|||||||
options.put("teleport.on_login", Settings.TELEPORT_ON_LOGIN);
|
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.enabled", Settings.MOB_CAP_ENABLED);
|
||||||
options.put("perm-based-mob-cap.max", Settings.MOB_CAP);
|
options.put("perm-based-mob-cap.max", Settings.MOB_CAP);
|
||||||
|
options.put("worldedit.require-selection-in-mask",Settings.REQUIRE_SELECTION);
|
||||||
|
|
||||||
for (final Entry<String, Object> node : options.entrySet()) {
|
for (final Entry<String, Object> node : options.entrySet()) {
|
||||||
if (!config.contains(node.getKey())) {
|
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.MOB_CAP = config.getInt("perm-based-mob-cap.max");
|
||||||
Settings.MAX_PLOTS = config.getInt("max_plots");
|
Settings.MAX_PLOTS = config.getInt("max_plots");
|
||||||
Settings.SCHEMATIC_SAVE_PATH = config.getString("schematics.save_path");
|
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();
|
final String version = worldEdit.getDescription().getVersion();
|
||||||
if ((version != null) && version.startsWith("5.")) {
|
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 {
|
} else {
|
||||||
getServer().getPluginManager().registerEvents(new WorldEditListener(), this);
|
getServer().getPluginManager().registerEvents(new WorldEditListener(), this);
|
||||||
}
|
}
|
||||||
|
@ -32,6 +32,10 @@ import org.bukkit.ChatColor;
|
|||||||
* @author Citymonstret
|
* @author Citymonstret
|
||||||
*/
|
*/
|
||||||
public enum C {
|
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
|
* Records
|
||||||
*/
|
*/
|
||||||
|
@ -29,6 +29,10 @@ package com.intellectualcrafters.plot.config;
|
|||||||
*/
|
*/
|
||||||
public class Settings {
|
public class Settings {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Default worldedit-require-selection-in-mask: false
|
||||||
|
*/
|
||||||
|
public static boolean REQUIRE_SELECTION = true;
|
||||||
/**
|
/**
|
||||||
* Default kill road mobs: true
|
* Default kill road mobs: true
|
||||||
*/
|
*/
|
||||||
|
@ -22,6 +22,8 @@
|
|||||||
package com.intellectualcrafters.plot.listeners;
|
package com.intellectualcrafters.plot.listeners;
|
||||||
|
|
||||||
import com.intellectualcrafters.plot.PlotMain;
|
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.database.DBFunc;
|
||||||
import com.intellectualcrafters.plot.events.PlotDeleteEvent;
|
import com.intellectualcrafters.plot.events.PlotDeleteEvent;
|
||||||
import com.intellectualcrafters.plot.object.Plot;
|
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.PWE;
|
||||||
import com.intellectualcrafters.plot.util.PlayerFunctions;
|
import com.intellectualcrafters.plot.util.PlayerFunctions;
|
||||||
import com.intellectualcrafters.plot.util.PlotHelper;
|
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.Bukkit;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
@ -41,6 +50,7 @@ import org.bukkit.event.player.*;
|
|||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -50,6 +60,8 @@ import java.util.Set;
|
|||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
public class WorldEditListener implements Listener {
|
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> blockedcmds = new HashSet<>(Arrays.asList("/gmask", "//gmask", "/worldedit:gmask"));
|
||||||
public final Set<String> restrictedcmds = new HashSet<>(Arrays.asList("/up", "//up", "/worldedit:up"));
|
public final Set<String> restrictedcmds = new HashSet<>(Arrays.asList("/up", "//up", "/worldedit:up"));
|
||||||
|
|
||||||
@ -104,7 +116,7 @@ public class WorldEditListener implements Listener {
|
|||||||
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
|
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
|
||||||
public void onPlayerCommand(final PlayerCommandPreprocessEvent e) {
|
public void onPlayerCommand(final PlayerCommandPreprocessEvent e) {
|
||||||
final Player p = e.getPlayer();
|
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;
|
return;
|
||||||
}
|
}
|
||||||
String cmd = e.getMessage().toLowerCase();
|
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()))) {
|
if ((plot == null) || !(plot.helpers.contains(DBFunc.everyone) || plot.helpers.contains(p.getUniqueId()))) {
|
||||||
e.setCancelled(true);
|
e.setCancelled(true);
|
||||||
}
|
}
|
||||||
|
return;
|
||||||
} else if (this.blockedcmds.contains(cmd)) {
|
} else if (this.blockedcmds.contains(cmd)) {
|
||||||
e.setCancelled(true);
|
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)
|
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
|
||||||
|
@ -308,7 +308,6 @@ public class PlayerFunctions {
|
|||||||
String msg = c.s();
|
String msg = c.s();
|
||||||
if ((args != null) && (args.length > 0)) {
|
if ((args != null) && (args.length > 0)) {
|
||||||
for (final String str : args) {
|
for (final String str : args) {
|
||||||
System.out.print(str);
|
|
||||||
if (msg.contains("%s")) {
|
if (msg.contains("%s")) {
|
||||||
msg = msg.replaceFirst("%s", str);
|
msg = msg.replaceFirst("%s", str);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user