diff --git a/PlotSquared/src/com/intellectualcrafters/plot/PWE.java b/PlotSquared/src/com/intellectualcrafters/plot/PWE.java index e025b96ea..f4fef6e42 100644 --- a/PlotSquared/src/com/intellectualcrafters/plot/PWE.java +++ b/PlotSquared/src/com/intellectualcrafters/plot/PWE.java @@ -8,7 +8,6 @@ import org.bukkit.World; import org.bukkit.entity.Player; import com.sk89q.worldedit.bukkit.BukkitPlayer; -import com.sk89q.worldedit.masks.RegionMask; import com.sk89q.worldedit.regions.CuboidRegion; /** @@ -17,7 +16,7 @@ import com.sk89q.worldedit.regions.CuboidRegion; * */ public class PWE { - + @SuppressWarnings("unused") public static void setMask(Player p, Location l) { try { @@ -27,42 +26,80 @@ public class PWE { } else { s = PlotMain.worldEdit.getSession(p); } - Plot plot = PlayerFunctions.getCurrentPlot(p); - if (plot != null) { - boolean r; - r = plot.getOwner() != null && plot.getOwner().equals(p.getUniqueId()); - if (!r) { - if (p.hasPermission("plots.we.member") && (plot.helpers.contains(DBFunc.everyone) || plot.helpers.contains(p.getUniqueId()))) { - r = true; - } else if (p.hasPermission("plots.we.bypass")) { - s.setMask(null); + + PlotId id = PlayerFunctions.getPlot(l); + if (id != null) { + Plot plot = PlotMain.getPlots(l.getWorld()).get(id); + if (plot!=null) { + boolean r; + r = plot.getOwner() != null && plot.getOwner().equals(p.getUniqueId()); + + if (!r) { + if (p.hasPermission("plots.worldedit.member") && (plot.helpers.contains(DBFunc.everyone) || plot.helpers.contains(p.getUniqueId()))) { + r = true; + } else if (p.hasPermission("plots.worldedit.bypass")) { + removeMask(p, s); + return; + } + } + else { + + World w = p.getWorld(); + + Location bloc = PlotHelper.getPlotBottomLoc(w, plot.id); + Location tloc = PlotHelper.getPlotTopLoc(w, plot.id); + + Vector bvec = new Vector(bloc.getBlockX() + 1, bloc.getBlockY() + 1, bloc.getBlockZ() + 1); + Vector tvec = new Vector(tloc.getBlockX(), tloc.getBlockY(), tloc.getBlockZ()); + + LocalWorld lw = PlotMain.worldEdit.wrapPlayer(p).getWorld(); + + CuboidRegion region = new CuboidRegion(lw, bvec, tvec); + com.sk89q.worldedit.masks.RegionMask mask = new com.sk89q.worldedit.masks.RegionMask(region); + + s.setMask(mask); return; } } - if (r) { - World w = p.getWorld(); - Location b = PlotHelper.getPlotBottomLoc(w, plot.id); - Location t = PlotHelper.getPlotTopLoc(w, plot.id); - Vector p1 = new Vector(b.getBlockX(), b.getBlockY(), b.getBlockZ()); - Vector p2 = new Vector(t.getBlockX(), t.getBlockY(), t.getBlockZ()); - LocalWorld world = PlotMain.worldEdit.wrapPlayer(p).getWorld(); - CuboidRegion cr = new CuboidRegion(world, p1, p2); - RegionMask rm = new RegionMask(cr); - s.setMask(rm); - return; - } } - if (s.getMask() == null) { + if (noMask(s)) { + System.out.print("NONE"); BukkitPlayer plr = PlotMain.worldEdit.wrapPlayer(p); - LocalWorld world = plr.getWorld(); - Vector p1 = new Vector(0, 0, 0), p2 = new Vector(0, 0, 0); - s.setMask(new RegionMask(new CuboidRegion(world, p1, p2))); + Vector p1 = new Vector(69, 69, 69), p2 = new Vector(69, 69, 69); + + s.setMask(new com.sk89q.worldedit.masks.RegionMask(new CuboidRegion(plr.getWorld(), p1, p2))); } } catch(Exception e) { throw new PlotSquaredException(PlotSquaredException.PlotError.MISSING_DEPENDENCY, "WorldEdit == Null?"); } } - + + public static boolean noMask(LocalSession s) { + try { + com.sk89q.worldedit.masks.Mask mask = s.getMask(); + return mask==null; + } + catch (Throwable e) { + return true; + } + } + + public static void removeMask(Player p, LocalSession s) { + System.out.print(0); + try { + System.out.print(1); + s.setMask(null); + System.out.print(2); + } + catch (Throwable e) { + System.out.print(3); + com.sk89q.worldedit.masks.Mask mask = null; + s.setMask(mask); + System.out.print(4); + } + System.out.print(5); + } + public static void removeMask(Player p) { try { LocalSession s; @@ -71,7 +108,7 @@ public class PWE { } else { s = PlotMain.worldEdit.getSession(p); } - s.setMask(null); + removeMask(p, s); } catch(Exception e) { throw new PlotSquaredException(PlotSquaredException.PlotError.MISSING_DEPENDENCY, "WorldEdit == Null?"); } diff --git a/PlotSquared/src/com/intellectualcrafters/plot/PlotMain.java b/PlotSquared/src/com/intellectualcrafters/plot/PlotMain.java index 64a031db8..d59165a0c 100644 --- a/PlotSquared/src/com/intellectualcrafters/plot/PlotMain.java +++ b/PlotSquared/src/com/intellectualcrafters/plot/PlotMain.java @@ -144,6 +144,41 @@ public class PlotMain extends JavaPlugin { } return 0; } + + /** + * Check a player for a permission
+ * - Op has all permissions
+ * - checks for '*' nodes + * @param player + * @param perm + * @return + */ + public static boolean hasPermissions(Player player, String[] perms) { + if (player.isOp()) { + return true; + } + for (String perm:perms) { + boolean hasperm = false; + if (player.hasPermission(perm)) { + hasperm = true; + } + else { + String[] nodes = perm.split("\\."); + StringBuilder n = new StringBuilder(); + for(int i = 0; i < nodes.length-1; i++) { + n.append(nodes[i]+"."); + if (player.hasPermission(n+"*")) { + hasperm = true; + break; + } + } + } + if (!hasperm) + return false; + } + + return true; + } /** * Check a player for a permission
diff --git a/PlotSquared/src/com/intellectualcrafters/plot/commands/Setup.java b/PlotSquared/src/com/intellectualcrafters/plot/commands/Setup.java index 46e6519c9..e3f13ef2f 100644 --- a/PlotSquared/src/com/intellectualcrafters/plot/commands/Setup.java +++ b/PlotSquared/src/com/intellectualcrafters/plot/commands/Setup.java @@ -3,7 +3,13 @@ package com.intellectualcrafters.plot.commands; import com.intellectualcrafters.plot.C; import com.intellectualcrafters.plot.PlotMain; import com.intellectualcrafters.plot.PlotWorld; +import com.intellectualcrafters.plot.WorldGenerator; + import org.bukkit.Bukkit; +import org.bukkit.Location; +import org.bukkit.World; +import org.bukkit.WorldCreator; +import org.bukkit.block.Block; import org.bukkit.entity.Player; import org.bukkit.event.Listener; @@ -17,41 +23,36 @@ public class Setup extends SubCommand implements Listener { public static Map setupMap = new HashMap<>(); - /* - ROAD_HEIGHT - PLOT_HEIGHT - WALL_HEIGHT - PLOT_WIDTH - ROAD_WIDTH - PLOT_BIOME - MAIN_BLOCK - TOP_BLOCK - WALL_BLOCK - WALL_FILLING - ROAD_STRIPES - ROAD_STRIPES_ENABLED - ROAD_BLOCK - PLOT_CHAT - BLOCKS - SCHEMATIC_ON_CLAIM - SCHEMATIC_FILE - DEFAULT_FLAGS - */ private static class SetupStep { private String constant; private Object default_value; private String description; private Object value = 0; - private String type; - public SetupStep(String constant, Object default_value, String description, String type) { + private Class type; + public SetupStep(String constant, Object default_value, String description, Class type) { this.constant = constant; this.default_value = default_value; this.description = description; this.type = type; } - public String getType() { - return this.type; + public Class getType() { + if (this.type == Integer.class) { + return Integer.class; + } + if (this.type == Boolean.class) { + return Boolean.class; + } + if (this.type == Double.class) { + return Double.class; + } + if (this.type == Float.class) { + return Float.class; + } + if (this.type == String.class) { + return String.class; + } + return Object.class; } public boolean setValue(Object o) { @@ -59,7 +60,29 @@ public class Setup extends SubCommand implements Listener { } public boolean validValue(String string) { - return true; + try { + if (this.type == Integer.class) { + Integer.parseInt(string); + return true; + } + if (this.type == Boolean.class) { + Boolean.parseBoolean(string); + return true; + } + if (this.type == Double.class) { + Double.parseDouble(string); + return true; + } + if (this.type == Float.class) { + Float.parseFloat(string); + return true; + } + if (this.type == String.class) { + return true; + } + } + catch (Exception e) {} + return false; } public Object getValue() { @@ -83,24 +106,30 @@ public class Setup extends SubCommand implements Listener { String world; int current = 0; PlotWorld p; - - SetupStep[] step = new SetupStep[] { - new SetupStep("road_height", 64, "Height of road", "integer") { - @Override - public boolean validValue(String string) { - try { - int t = Integer.parseInt(string); - } catch(Exception e) { - return false; - } - return true; - } - } - }; + /* + ROAD_HEIGHT - Integer + PLOT_HEIGHT - Integer + WALL_HEIGHT - Integer + PLOT_WIDTH - Integer + ROAD_WIDTH - Integer + PLOT_BIOME - BIOME + MAIN_BLOCK - Block[] (as you can have several blocks, with IDS) + TOP_BLOCK - Block[] (as you can have several blocks, with IDS) + WALL_BLOCK - Block + WALL_FILLING - Block + ROAD_STRIPES - Block + ROAD_STRIPES_ENABLED - Boolean + ROAD_BLOCK - Block + PLOT_CHAT - Boolean + BLOCKS - wtf is this? + SCHEMATIC_ON_CLAIM - Boolean + SCHEMATIC_FILE - String + DEFAULT_FLAGS - String[] + */ + SetupStep[] step = new SetupStep[] { new SetupStep("road_height", 64, "Height of road", Integer.class) }; public SetupObject(String world) { this.world = world; - this.p = new PlotWorld(); } @@ -120,6 +149,28 @@ public class Setup extends SubCommand implements Listener { public Setup() { super("setup", "plots.admin", "Setup a PlotWorld", "/plot setup {world}", "setup", CommandCategory.ACTIONS); } + + /* + * /plot setup {world} - setup a world using default values + * (display current default settings) + * (use ordinary chat to get/set) + *