WorldEdit 6 + /plot setup (in progress)

This commit is contained in:
boy0001 2014-10-02 14:35:20 +10:00
parent 9409ebd7cb
commit 8b50bdd330
5 changed files with 293 additions and 149 deletions

View File

@ -8,7 +8,6 @@ import org.bukkit.World;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import com.sk89q.worldedit.bukkit.BukkitPlayer; import com.sk89q.worldedit.bukkit.BukkitPlayer;
import com.sk89q.worldedit.masks.RegionMask;
import com.sk89q.worldedit.regions.CuboidRegion; import com.sk89q.worldedit.regions.CuboidRegion;
/** /**
@ -27,42 +26,80 @@ public class PWE {
} else { } else {
s = PlotMain.worldEdit.getSession(p); s = PlotMain.worldEdit.getSession(p);
} }
Plot plot = PlayerFunctions.getCurrentPlot(p);
if (plot != null) { PlotId id = PlayerFunctions.getPlot(l);
boolean r; if (id != null) {
r = plot.getOwner() != null && plot.getOwner().equals(p.getUniqueId()); Plot plot = PlotMain.getPlots(l.getWorld()).get(id);
if (!r) { if (plot!=null) {
if (p.hasPermission("plots.we.member") && (plot.helpers.contains(DBFunc.everyone) || plot.helpers.contains(p.getUniqueId()))) { boolean r;
r = true; r = plot.getOwner() != null && plot.getOwner().equals(p.getUniqueId());
} else if (p.hasPermission("plots.we.bypass")) {
s.setMask(null); 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; 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); BukkitPlayer plr = PlotMain.worldEdit.wrapPlayer(p);
LocalWorld world = plr.getWorld(); Vector p1 = new Vector(69, 69, 69), p2 = new Vector(69, 69, 69);
Vector p1 = new Vector(0, 0, 0), p2 = new Vector(0, 0, 0);
s.setMask(new RegionMask(new CuboidRegion(world, p1, p2))); s.setMask(new com.sk89q.worldedit.masks.RegionMask(new CuboidRegion(plr.getWorld(), p1, p2)));
} }
} catch(Exception e) { } catch(Exception e) {
throw new PlotSquaredException(PlotSquaredException.PlotError.MISSING_DEPENDENCY, "WorldEdit == Null?"); 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) { public static void removeMask(Player p) {
try { try {
LocalSession s; LocalSession s;
@ -71,7 +108,7 @@ public class PWE {
} else { } else {
s = PlotMain.worldEdit.getSession(p); s = PlotMain.worldEdit.getSession(p);
} }
s.setMask(null); removeMask(p, s);
} catch(Exception e) { } catch(Exception e) {
throw new PlotSquaredException(PlotSquaredException.PlotError.MISSING_DEPENDENCY, "WorldEdit == Null?"); throw new PlotSquaredException(PlotSquaredException.PlotError.MISSING_DEPENDENCY, "WorldEdit == Null?");
} }

View File

@ -145,6 +145,41 @@ public class PlotMain extends JavaPlugin {
return 0; return 0;
} }
/**
* Check a player for a permission<br>
* - Op has all permissions <br>
* - 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<br> * Check a player for a permission<br>
* - Op has all permissions <br> * - Op has all permissions <br>

View File

@ -3,7 +3,13 @@ package com.intellectualcrafters.plot.commands;
import com.intellectualcrafters.plot.C; import com.intellectualcrafters.plot.C;
import com.intellectualcrafters.plot.PlotMain; import com.intellectualcrafters.plot.PlotMain;
import com.intellectualcrafters.plot.PlotWorld; import com.intellectualcrafters.plot.PlotWorld;
import com.intellectualcrafters.plot.WorldGenerator;
import org.bukkit.Bukkit; 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.entity.Player;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
@ -17,41 +23,36 @@ public class Setup extends SubCommand implements Listener {
public static Map<String, SetupObject> setupMap = new HashMap<>(); public static Map<String, SetupObject> 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 static class SetupStep {
private String constant; private String constant;
private Object default_value; private Object default_value;
private String description; private String description;
private Object value = 0; private Object value = 0;
private String type; private Class type;
public SetupStep(String constant, Object default_value, String description, String type) { public SetupStep(String constant, Object default_value, String description, Class type) {
this.constant = constant; this.constant = constant;
this.default_value = default_value; this.default_value = default_value;
this.description = description; this.description = description;
this.type = type; this.type = type;
} }
public String getType() { public Class getType() {
return this.type; 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) { public boolean setValue(Object o) {
@ -59,7 +60,29 @@ public class Setup extends SubCommand implements Listener {
} }
public boolean validValue(String string) { 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() { public Object getValue() {
@ -83,24 +106,30 @@ public class Setup extends SubCommand implements Listener {
String world; String world;
int current = 0; int current = 0;
PlotWorld p; PlotWorld p;
/*
SetupStep[] step = new SetupStep[] { ROAD_HEIGHT - Integer
new SetupStep("road_height", 64, "Height of road", "integer") { PLOT_HEIGHT - Integer
@Override WALL_HEIGHT - Integer
public boolean validValue(String string) { PLOT_WIDTH - Integer
try { ROAD_WIDTH - Integer
int t = Integer.parseInt(string); PLOT_BIOME - BIOME
} catch(Exception e) { MAIN_BLOCK - Block[] (as you can have several blocks, with IDS)
return false; TOP_BLOCK - Block[] (as you can have several blocks, with IDS)
} WALL_BLOCK - Block
return true; 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) { public SetupObject(String world) {
this.world = world; this.world = world;
this.p = new PlotWorld(); this.p = new PlotWorld();
} }
@ -121,6 +150,28 @@ public class Setup extends SubCommand implements Listener {
super("setup", "plots.admin", "Setup a PlotWorld", "/plot setup {world}", "setup", CommandCategory.ACTIONS); super("setup", "plots.admin", "Setup a PlotWorld", "/plot setup {world}", "setup", CommandCategory.ACTIONS);
} }
/*
* /plot setup {world} <default> - setup a world using default values
* (display current default settings)
* (use ordinary chat to get/set)
* <value> <option> - modify a value
* /plot setup create - create the world
*
* /plot setup {world} <world> - setup a world using the values for an existing world
* (display current world settings)
* (use ordinary chat to get/set)
* <value> <option> - modify a value
* /plot setup create - create the world
*
* /plot setup {world} - setup the world manually
* (display current world settings)
* (use ordinary chat to set)
* <option> - set the current value
* back - to go back a step
* /plot setup create - create the world
*
*/
@Override @Override
public boolean execute(Player plr, String... args) { public boolean execute(Player plr, String... args) {
if(setupMap.containsKey(plr.getName())) { if(setupMap.containsKey(plr.getName())) {
@ -128,11 +179,18 @@ public class Setup extends SubCommand implements Listener {
if(object.getCurrent() == object.getMax()) { if(object.getCurrent() == object.getMax()) {
sendMessage(plr, C.SETUP_FINISHED, object.world); sendMessage(plr, C.SETUP_FINISHED, object.world);
setupMap.remove(plr.getName()); setupMap.remove(plr.getName());
// Save stuff to config
// Generate a world
// String name = "{world}";
// World world = WorldCreator.name(name).generator(new WorldGenerator(name)).createWorld();
return true; return true;
} }
SetupStep step = object.step[object.current]; SetupStep step = object.step[object.current];
if(args.length < 1) { if(args.length < 1) {
sendMessage(plr, C.SETUP_STEP, object.current + 1 + "", step.getDescription(), step.getType(), step.getDefaultValue() + ""); sendMessage(plr, C.SETUP_STEP, object.current + 1 + "", step.getDescription(), step.getType().getName(), step.getDefaultValue() + "");
return true; return true;
} else { } else {
boolean valid = step.validValue(args[0]); boolean valid = step.validValue(args[0]);

View File

@ -200,7 +200,7 @@ public class PlayerEvents implements Listener {
} }
} }
catch (Exception e) { catch (Exception e) {
// Gotta catch them all. // Gotta catch 'em all.
} }
} }

View File

@ -1,7 +1,8 @@
package com.intellectualcrafters.plot.listeners; package com.intellectualcrafters.plot.listeners;
import com.intellectualcrafters.plot.*; import java.util.Arrays;
import com.intellectualcrafters.plot.database.DBFunc; import java.util.HashSet;
import java.util.Set;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.Material; import org.bukkit.Material;
@ -10,8 +11,20 @@ import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority; import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
import org.bukkit.event.block.Action; import org.bukkit.event.player.PlayerCommandPreprocessEvent;
import org.bukkit.event.player.*; 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.PWE;
import com.intellectualcrafters.plot.PlayerFunctions;
import com.intellectualcrafters.plot.Plot;
import com.intellectualcrafters.plot.PlotHelper;
import com.intellectualcrafters.plot.PlotId;
import com.intellectualcrafters.plot.PlotMain;
import com.intellectualcrafters.plot.database.DBFunc;
/** /**
* *
@ -20,69 +33,88 @@ import org.bukkit.event.player.*;
*/ */
public class WorldEditListener implements Listener { public class WorldEditListener implements Listener {
public final Set<String> blockedcmds = new HashSet<String>(Arrays.asList("/gmask", "//gmask", "/worldedit:gmask"));
public final Set<String> restrictedcmds = new HashSet<String>(Arrays.asList("/up", "//up", "/worldedit:up"));
private boolean isPlotWorld(Location l) { private boolean isPlotWorld(Location l) {
return (PlotMain.isPlotWorld(l.getWorld())); return (PlotMain.isPlotWorld(l.getWorld()));
} }
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true) @EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
public void onPlayerMove(final PlayerMoveEvent e) { public void onInteract(PlayerInteractEvent e) {
if (PlotMain.hasPermission(e.getPlayer(), "plots.worldedit.bypass")) { Block b = e.getClickedBlock();
if (b == null) {
return; return;
} }
Location f = e.getFrom();
Location t = e.getTo();
boolean cm = false;
Player p = e.getPlayer(); Player p = e.getPlayer();
if (t == null) { Location l = b.getLocation();
PWE.removeMask(p); if (!isPlotWorld(l)) {
} else { return;
if (f != null) { }
if (!f.getWorld().getName().equalsIgnoreCase(t.getWorld().getName())) { p.getItemInHand();
cm = true; if ((p.getItemInHand() == null) || (p.getItemInHand().getType() == Material.AIR)) {
} else if ((f.getBlockX() != t.getBlockX()) || (f.getBlockZ() != t.getBlockZ())) { return;
PlotId idF = PlayerFunctions.getPlot(f); }
PlotId idT = PlayerFunctions.getPlot(t); Plot plot = PlotHelper.getCurrentPlot(b.getLocation());
if (!(idF == idT)) { if (plot != null) {
cm = true; if ((plot != null) && (plot.helpers.contains(DBFunc.everyone) || plot.helpers.contains(p.getUniqueId()))) {
} PWE.setMask(p, l);
}
} }
if (cm) { }
if (isPlotWorld(t)) { }
PWE.setMask(p, p.getLocation());
} @EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
public void onPlayerCommand(PlayerCommandPreprocessEvent e) {
Player p = e.getPlayer();
if (PlotMain.hasPermission(p, "plots.worldedit.bypass") || !PlotMain.isPlotWorld(p.getWorld())) {
return;
}
String cmd = e.getMessage().toLowerCase();
if (cmd.contains(" ")) {
cmd = cmd.substring(0, cmd.indexOf(" "));
}
if (this.restrictedcmds.contains(cmd)) {
Plot plot = PlayerFunctions.getCurrentPlot(p);
if ((plot == null) || !(plot.helpers.contains(DBFunc.everyone) || plot.helpers.contains(p.getUniqueId()))) {
e.setCancelled(true);
} }
} else if (this.blockedcmds.contains(cmd)) {
e.setCancelled(true);
} }
} }
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true) @EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
public void onPlayerJoin(final PlayerJoinEvent e) { public void onPlayerJoin(final PlayerJoinEvent e) {
if (PlotMain.hasPermission(e.getPlayer(), "plots.worldedit.bypass")) { Player p = e.getPlayer();
if (PlotMain.hasPermission(p, "plots.worldedit.bypass")) {
return; return;
} }
Player p = e.getPlayer(); Location l = p.getLocation();
if (isPlotWorld(p.getLocation())) { if (isPlotWorld(l)) {
PWE.setMask(p, p.getLocation()); PWE.setMask(p, l);
} else { } else {
PWE.removeMask(p); PWE.removeMask(p);
} }
} }
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true) @EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
public void onTeleport(final PlayerTeleportEvent e) { public void onPlayerMove(final PlayerMoveEvent e) {
if (PlotMain.hasPermission(e.getPlayer(), "plots.worldedit.bypass")) { Location t = e.getTo();
if (!isPlotWorld(t)) {
return; return;
} }
Location f = e.getFrom();
Player p = e.getPlayer(); Player p = e.getPlayer();
Location f = e.getFrom(), t = e.getTo();
if (t == null) { if ((f.getBlockX() != t.getBlockX()) || (f.getBlockZ() != t.getBlockZ())) {
PWE.removeMask(p); PlotId idF = PlayerFunctions.getPlot(f);
} else { PlotId idT = PlayerFunctions.getPlot(t);
if ((f != null) && isPlotWorld(f) && !isPlotWorld(t)) { if (PlotMain.hasPermission(e.getPlayer(), "plots.worldedit.bypass")) {
PWE.removeMask(p); return;
} else if (isPlotWorld(t)) { }
PWE.setMask(p, p.getLocation()); if (idT!=null && !(idF == idT)) {
PWE.setMask(p, t);
} }
} }
} }
@ -93,53 +125,35 @@ public class WorldEditListener implements Listener {
return; return;
} }
Player p = e.getPlayer(); Player p = e.getPlayer();
Location f = e.getFrom(), t = e.getTo(); Location t = e.getTo();
if (t == null) { Location f = e.getFrom();
PWE.removeMask(p); if (!isPlotWorld(t)) {
} else { if (isPlotWorld(f)) {
if ((f != null) && isPlotWorld(f) && !isPlotWorld(t)) {
PWE.removeMask(p); PWE.removeMask(p);
} else if (isPlotWorld(t)) { }
PWE.setMask(p, p.getLocation()); else {
return;
} }
} }
PWE.setMask(p, t);
} }
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true) @EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
public void onPlayerCommand(PlayerCommandPreprocessEvent e) { public void onTeleport(final PlayerTeleportEvent e) {
if (PlotMain.hasPermission(e.getPlayer(), "plots.worldedit.bypass")) { if (PlotMain.hasPermission(e.getPlayer(), "plots.worldedit.bypass")) {
return; return;
} }
Player p = e.getPlayer(); Player p = e.getPlayer();
if (isPlotWorld(p.getLocation())) { Location t = e.getTo();
String msg = e.getMessage().toLowerCase(); Location f = e.getFrom();
if (msg.startsWith("//gmask") || msg.startsWith("/gmask") || msg.startsWith("/worldedit:gmask") || msg.startsWith("/worldedit:/gmask")) { if (!isPlotWorld(t)) {
e.setCancelled(true); if (isPlotWorld(f)) {
} else if (msg.startsWith("/up") || msg.startsWith("//up") || msg.startsWith("/worldedit:up") || msg.startsWith("/worldedit:/up")) { PWE.removeMask(p);
Plot plot = PlayerFunctions.getCurrentPlot(p); }
if ((p == null) || !(plot.helpers.contains(DBFunc.everyone) || plot.helpers.contains(p.getUniqueId()))) { else {
e.setCancelled(true); return;
}
}
}
}
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
public void onInteract(PlayerInteractEvent e) {
Player p = e.getPlayer();
if (PlotMain.hasPermission(p, "plots.worldedit.bypass")) {
return;
}
if (!p.hasPermission("plots.admin") && isPlotWorld(p.getLocation())) {
if (((e.getAction() == Action.LEFT_CLICK_BLOCK) || (e.getAction() == Action.RIGHT_CLICK_BLOCK)) && (p.getItemInHand() != null) && (p.getItemInHand().getType() != Material.AIR)) {
Block b = e.getClickedBlock();
Plot plot = PlotHelper.getCurrentPlot(b.getLocation());
if ((plot != null) && (plot.helpers.contains(DBFunc.everyone) || plot.helpers.contains(p.getUniqueId()))) {
PWE.setMask(p, b.getLocation());
} else {
e.setCancelled(true);
}
} }
} }
PWE.setMask(p, t);
} }
} }