diff --git a/src/me/TheBukor/SkStuff.java b/src/me/TheBukor/SkStuff.java index b1bd199..7f3e778 100644 --- a/src/me/TheBukor/SkStuff.java +++ b/src/me/TheBukor/SkStuff.java @@ -18,10 +18,14 @@ import ch.njol.skript.registrations.Classes; import me.TheBukor.conditions.CondSelectionContains; import me.TheBukor.effects.EffDrainLiquid; import me.TheBukor.effects.EffDrawLineWE; +import me.TheBukor.effects.EffMakeCylinder; import me.TheBukor.effects.EffMakePyramid; import me.TheBukor.effects.EffMakeSphere; +import me.TheBukor.effects.EffMakeWalls; import me.TheBukor.effects.EffNaturalize; import me.TheBukor.effects.EffRememberChanges; +import me.TheBukor.effects.EffReplaceBlocksWE; +import me.TheBukor.effects.EffSetBlocksWE; import me.TheBukor.effects.EffSimulateSnow; import me.TheBukor.effects.EffUndoRedoSession; import me.TheBukor.expressions.ExprAreaOfSchematic; @@ -381,18 +385,22 @@ public class SkStuff extends JavaPlugin { if (Bukkit.getPluginManager().getPlugin("WorldEdit") != null) { getLogger().info("WorldEdit found! Registering WorldEdit stuff..."); condAmount += 1; - effAmount += 8; + effAmount += 12; exprAmount += 16; typeAmount += 1; Skript.registerCondition(CondSelectionContains.class, "[(world[ ]edit|we)] selection of %player% (contains|has) %location%", "%player%'s [(world[ ]edit|we)] selection (contains|has) %location%", "[(world[ ]edit|we)] selection of %player% does(n't| not) (contain|have) %location%", "%player%'s [(world[ ]edit|we)] selection does(n't| not) (contain|have) %location%"); Skript.registerEffect(EffDrawLineWE.class, "(create|draw|make) [a[n]] (0¦(no(n|t)(-| )hollow|filled|)|1¦hollow) line from %location% to %location% (using|with) [edit[ ]session] %editsession% (using|with) [block[s]] %itemstacks% [with] thick[ness] %double%"); Skript.registerEffect(EffUndoRedoSession.class, "(0¦undo|1¦redo) (change|edit)s (of|from) [edit[ ]session] %editsession%"); Skript.registerEffect(EffRememberChanges.class, "make %player% (remember|be able to undo) changes (of|from) [edit[ ]session] %editsession%"); - Skript.registerEffect(EffMakeSphere.class, "(create|make) [a[n]] (0¦(no(n|t)(-| )hollow|filled|)|1¦hollow) (ellipsoid|sphere) [centered] at %location% [with] radius [of] %double%, %double%(,| and) %double% (using|with) [edit[ ]session] %editsession% (using|with) [block[s]] %itemstacks%"); + Skript.registerEffect(EffMakeSphere.class, "(create|make) [a[n]] (0¦(no(n|t)(-| )hollow|filled|)|1¦hollow) (ellipsoid|sphere) [centered] at %location% [with] radius [of] %double%,[ ]%double%(,[ ]| and )%double% (using|with) [edit[ ]session] %editsession% (using|with) [block[s]] %itemstacks%"); Skript.registerEffect(EffSimulateSnow.class, "(simulate snow at|place snow over) %location% (in|within) [a] radius [of] %double% (using|with) [edit[ ]session] %editsession%", "make %location% snowy (in|within) [a] radius [of] %double% (using|with) [edit[ ]session] %editsession%"); Skript.registerEffect(EffMakePyramid.class, "(create|make) [a[n]] (0¦(no(n|t)(-| )hollow|filled|)|1¦hollow) pyramid at %location% [with] radius [of] %integer% (using|with) [edit[ ]session] %editsession% (using|with) [block[s]] %itemstacks%"); Skript.registerEffect(EffDrainLiquid.class, "(drain|remove) [all] liquid[s] at %location% (in|within) [a] radius [of] %double% (using|with) [edit[ ]session] %editsession%"); Skript.registerEffect(EffNaturalize.class, "naturalize ([cuboid] region|[all] blocks) (from|between) %location% (to|and) %location% (using|with) [edit[ ]session] %editsession%"); + Skript.registerEffect(EffMakeWalls.class, "(create|make) wall[s] from %location% to %location% (using|with) [edit[ ]session] %editsession% (using|with) [block[s]] %itemstacks%"); + Skript.registerEffect(EffSetBlocksWE.class, "set [all] blocks (from|between) %location% (to|and) %location% to %itemstacks% (using|with) [edit[ ]session] %editsession%"); + Skript.registerEffect(EffMakeCylinder.class, "(create|make) [a[n]] (0¦(no(n|t)(-| )hollow|filled|)|1¦hollow) cylinder at %location% [with] radius [of] %double%,[ ]%integer%(,[ ]| and )%double% (using|with) [edit[ ]session] %editsession% (using|with) [block[s]] %itemstacks%"); + Skript.registerEffect(EffReplaceBlocksWE.class, "replace [all] %itemstacks% (from|between) %location% (to|and) %location% with %itemstacks% (using|with) [edit[ ]session] %editsession%"); Skript.registerExpression(ExprEditSessionLimit.class, Integer.class, ExpressionType.PROPERTY, "[block] limit [change] of [edit[ ]session] %editsession%"); Skript.registerExpression(ExprChangedBlocksSession.class, Integer.class, ExpressionType.PROPERTY, "number of [all] changed blocks (in|of) [edit[ ]session] %editsession%"); Skript.registerExpression(ExprNewEditSession.class, EditSession.class, ExpressionType.PROPERTY, "new edit[ ]session in [world] %world% [with] [max[imum]] [block] limit [change] [of] %integer%"); diff --git a/src/me/TheBukor/effects/EffMakeCylinder.java b/src/me/TheBukor/effects/EffMakeCylinder.java new file mode 100644 index 0000000..abc4b49 --- /dev/null +++ b/src/me/TheBukor/effects/EffMakeCylinder.java @@ -0,0 +1,75 @@ +package me.TheBukor.effects; + +import javax.annotation.Nullable; + +import org.bukkit.Location; +import org.bukkit.event.Event; +import org.bukkit.inventory.ItemStack; + +import com.sk89q.worldedit.EditSession; +import com.sk89q.worldedit.MaxChangedBlocksException; +import com.sk89q.worldedit.WorldEditException; +import com.sk89q.worldedit.blocks.BaseBlock; +import com.sk89q.worldedit.bukkit.BukkitUtil; +import com.sk89q.worldedit.function.pattern.BlockPattern; +import com.sk89q.worldedit.function.pattern.Patterns; +import com.sk89q.worldedit.function.pattern.RandomPattern; + +import ch.njol.skript.lang.Effect; +import ch.njol.skript.lang.Expression; +import ch.njol.skript.lang.SkriptParser.ParseResult; +import ch.njol.util.Kleenean; + +public class EffMakeCylinder extends Effect { + private Expression location; + private Expression radius1; + private Expression radius2; + private Expression height; + private Expression editSession; + private Expression blockList; + private boolean filled = true; + + @SuppressWarnings("unchecked") + @Override + public boolean init(Expression[] expr, int matchedPattern, Kleenean arg2, ParseResult result) { + location = (Expression) expr[0]; + radius1 = (Expression) expr[1]; + height = (Expression) expr[2]; + radius2 = (Expression) expr[3]; + editSession = (Expression) expr[4]; + blockList = (Expression) expr[5]; + if (result.mark == 1) filled = false; + return true; + } + @Override + public String toString(@Nullable Event e, boolean arg1) { + return "create a cylinder at " + location.toString(e, false) + " with a radius of " + radius1.toString(e, false) + " " + height.toString(e, false) + " " + radius2.toString(e, false) + " using an edit session with " + blockList.toString(e, false); + } + + @SuppressWarnings("deprecation") + @Override + protected void execute(Event e) { + Location loc = location.getSingle(e); + Double rad1 = radius1.getSingle(e); + Integer h = height.getSingle(e); + Double rad2 = radius2.getSingle(e); + EditSession session = editSession.getSingle(e); + ItemStack[] blocks = blockList.getAll(e); + RandomPattern random = new RandomPattern(); + if (session == null) return; + for (ItemStack b : blocks) { + if (b.getType().isBlock()) { + random.add(new BlockPattern(new BaseBlock(b.getTypeId(), b.getDurability())), 50); + } + } + try { + session.makeCylinder(BukkitUtil.toVector(loc), Patterns.wrap(random), rad1, rad2, h, filled); + session.flushQueue(); + } catch (WorldEditException ex) { + if (ex instanceof MaxChangedBlocksException) + return; + else + ex.printStackTrace(); + } + } +} \ No newline at end of file diff --git a/src/me/TheBukor/effects/EffMakeWalls.java b/src/me/TheBukor/effects/EffMakeWalls.java new file mode 100644 index 0000000..16f13e5 --- /dev/null +++ b/src/me/TheBukor/effects/EffMakeWalls.java @@ -0,0 +1,69 @@ +package me.TheBukor.effects; + +import javax.annotation.Nullable; + +import org.bukkit.Location; +import org.bukkit.event.Event; +import org.bukkit.inventory.ItemStack; + +import com.sk89q.worldedit.EditSession; +import com.sk89q.worldedit.MaxChangedBlocksException; +import com.sk89q.worldedit.WorldEditException; +import com.sk89q.worldedit.blocks.BaseBlock; +import com.sk89q.worldedit.bukkit.BukkitUtil; +import com.sk89q.worldedit.function.pattern.BlockPattern; +import com.sk89q.worldedit.function.pattern.Patterns; +import com.sk89q.worldedit.function.pattern.RandomPattern; +import com.sk89q.worldedit.regions.CuboidRegion; +import com.sk89q.worldedit.world.World; + +import ch.njol.skript.lang.Effect; +import ch.njol.skript.lang.Expression; +import ch.njol.skript.lang.SkriptParser.ParseResult; +import ch.njol.util.Kleenean; + +public class EffMakeWalls extends Effect { + private Expression location1; + private Expression location2; + private Expression editSession; + private Expression blockList; + + @SuppressWarnings("unchecked") + @Override + public boolean init(Expression[] expr, int matchedPattern, Kleenean arg2, ParseResult result) { + location1 = (Expression) expr[0]; + location2 = (Expression) expr[1]; + editSession = (Expression) expr[2]; + blockList = (Expression) expr[3]; + return true; + } + @Override + public String toString(@Nullable Event e, boolean arg1) { + return "make walls from " + location1.toString(e, false) + " to " + location2.toString(e, false) + " using an edit session with " + blockList.toString(e, false); + } + + @SuppressWarnings("deprecation") + @Override + protected void execute(Event e) { + Location pos1 = location1.getSingle(e); + Location pos2 = location2.getSingle(e); + EditSession session = editSession.getSingle(e); + ItemStack[] blocks = blockList.getAll(e); + RandomPattern random = new RandomPattern(); + if (session == null) return; + for (ItemStack b : blocks) { + if (b.getType().isBlock()) { + random.add(new BlockPattern(new BaseBlock(b.getTypeId(), b.getDurability())), 50); + } + } + try { + session.makeWalls(new CuboidRegion((World) BukkitUtil.getLocalWorld(pos1.getWorld()), BukkitUtil.toVector(pos1), BukkitUtil.toVector(pos2)), Patterns.wrap(random)); + session.flushQueue(); + } catch (WorldEditException ex) { + if (ex instanceof MaxChangedBlocksException) + return; + else + ex.printStackTrace(); + } + } +} \ No newline at end of file diff --git a/src/me/TheBukor/effects/EffReplaceBlocksWE.java b/src/me/TheBukor/effects/EffReplaceBlocksWE.java new file mode 100644 index 0000000..15fc124 --- /dev/null +++ b/src/me/TheBukor/effects/EffReplaceBlocksWE.java @@ -0,0 +1,81 @@ +package me.TheBukor.effects; + +import java.util.HashSet; +import java.util.Set; + +import javax.annotation.Nullable; + +import org.bukkit.Location; +import org.bukkit.event.Event; +import org.bukkit.inventory.ItemStack; + +import com.sk89q.worldedit.EditSession; +import com.sk89q.worldedit.MaxChangedBlocksException; +import com.sk89q.worldedit.WorldEditException; +import com.sk89q.worldedit.blocks.BaseBlock; +import com.sk89q.worldedit.bukkit.BukkitUtil; +import com.sk89q.worldedit.function.pattern.BlockPattern; +import com.sk89q.worldedit.function.pattern.Patterns; +import com.sk89q.worldedit.function.pattern.RandomPattern; +import com.sk89q.worldedit.regions.CuboidRegion; +import com.sk89q.worldedit.world.World; + +import ch.njol.skript.lang.Effect; +import ch.njol.skript.lang.Expression; +import ch.njol.skript.lang.SkriptParser.ParseResult; +import ch.njol.util.Kleenean; + +public class EffReplaceBlocksWE extends Effect { + private Expression blockList1; + private Expression location1; + private Expression location2; + private Expression blockList2; + private Expression editSession; + + @SuppressWarnings("unchecked") + @Override + public boolean init(Expression[] expr, int matchedPattern, Kleenean arg2, ParseResult result) { + blockList1 = (Expression) expr[0]; + location1 = (Expression) expr[1]; + location2 = (Expression) expr[2]; + blockList2 = (Expression) expr[3]; + editSession = (Expression) expr[4]; + return true; + } + @Override + public String toString(@Nullable Event e, boolean arg1) { + return "replace all " + blockList1.toString(e, false) + " from " + location1.toString(e, false) + " to " + location2.toString(e, false) + " with " + blockList1.toString(e, false) + " using an edit session"; + } + + @SuppressWarnings({ "deprecation" }) + @Override + protected void execute(Event e) { + Location pos1 = location1.getSingle(e); + Location pos2 = location2.getSingle(e); + EditSession session = editSession.getSingle(e); + ItemStack[] blocks = blockList1.getAll(e); + ItemStack[] blocksToPlace = blockList2.getAll(e); + RandomPattern random = new RandomPattern(); + Set blocksToReplace = new HashSet(); + if (session == null) return; + for (ItemStack b : blocks) { + if (b.getType().isBlock()) { + blocksToReplace.add(new BaseBlock(b.getTypeId(), b.getDurability())); + } + } + for (ItemStack b : blocksToPlace) { + if (b.getType().isBlock()) { + random.add(new BlockPattern(new BaseBlock(b.getTypeId(), b.getDurability())), 50); + } + } + try { + session.replaceBlocks(new CuboidRegion((World) BukkitUtil.getLocalWorld(pos1.getWorld()), BukkitUtil.toVector(pos1), BukkitUtil.toVector(pos2)), blocksToReplace, Patterns.wrap(random)); + session.flushQueue(); + } catch (WorldEditException ex) { + if (ex instanceof MaxChangedBlocksException) + return; + else + ex.printStackTrace(); + } + } +} \ No newline at end of file diff --git a/src/me/TheBukor/effects/EffSetBlocksWE.java b/src/me/TheBukor/effects/EffSetBlocksWE.java new file mode 100644 index 0000000..d9b241f --- /dev/null +++ b/src/me/TheBukor/effects/EffSetBlocksWE.java @@ -0,0 +1,69 @@ +package me.TheBukor.effects; + +import javax.annotation.Nullable; + +import org.bukkit.Location; +import org.bukkit.event.Event; +import org.bukkit.inventory.ItemStack; + +import com.sk89q.worldedit.EditSession; +import com.sk89q.worldedit.MaxChangedBlocksException; +import com.sk89q.worldedit.WorldEditException; +import com.sk89q.worldedit.blocks.BaseBlock; +import com.sk89q.worldedit.bukkit.BukkitUtil; +import com.sk89q.worldedit.function.pattern.BlockPattern; +import com.sk89q.worldedit.function.pattern.Patterns; +import com.sk89q.worldedit.function.pattern.RandomPattern; +import com.sk89q.worldedit.regions.CuboidRegion; +import com.sk89q.worldedit.world.World; + +import ch.njol.skript.lang.Effect; +import ch.njol.skript.lang.Expression; +import ch.njol.skript.lang.SkriptParser.ParseResult; +import ch.njol.util.Kleenean; + +public class EffSetBlocksWE extends Effect { + private Expression location1; + private Expression location2; + private Expression blockList; + private Expression editSession; + + @SuppressWarnings("unchecked") + @Override + public boolean init(Expression[] expr, int matchedPattern, Kleenean arg2, ParseResult result) { + location1 = (Expression) expr[0]; + location2 = (Expression) expr[1]; + blockList = (Expression) expr[2]; + editSession = (Expression) expr[3]; + return true; + } + @Override + public String toString(@Nullable Event e, boolean arg1) { + return "set all blocks from " + location1.toString(e, false) + " to " + location2.toString(e, false) + " to " + blockList.toString(e, false) + " using an edit session"; + } + + @SuppressWarnings("deprecation") + @Override + protected void execute(Event e) { + Location pos1 = location1.getSingle(e); + Location pos2 = location2.getSingle(e); + EditSession session = editSession.getSingle(e); + ItemStack[] blocks = blockList.getAll(e); + RandomPattern random = new RandomPattern(); + if (session == null) return; + for (ItemStack b : blocks) { + if (b.getType().isBlock()) { + random.add(new BlockPattern(new BaseBlock(b.getTypeId(), b.getDurability())), 50); + } + } + try { + session.setBlocks(new CuboidRegion((World) BukkitUtil.getLocalWorld(pos1.getWorld()), BukkitUtil.toVector(pos1), BukkitUtil.toVector(pos2)), Patterns.wrap(random)); + session.flushQueue(); + } catch (WorldEditException ex) { + if (ex instanceof MaxChangedBlocksException) + return; + else + ex.printStackTrace(); + } + } +} \ No newline at end of file diff --git a/src/me/TheBukor/expressions/ExprSelectionOfPlayer.java b/src/me/TheBukor/expressions/ExprSelectionOfPlayer.java index 83b4549..b7dc4ce 100644 --- a/src/me/TheBukor/expressions/ExprSelectionOfPlayer.java +++ b/src/me/TheBukor/expressions/ExprSelectionOfPlayer.java @@ -15,10 +15,12 @@ import com.sk89q.worldedit.regions.CuboidRegion; import com.sk89q.worldedit.regions.Region; import com.sk89q.worldedit.world.World; +import ch.njol.skript.classes.Changer.ChangeMode; import ch.njol.skript.lang.Expression; import ch.njol.skript.lang.SkriptParser.ParseResult; import ch.njol.skript.lang.util.SimpleExpression; import ch.njol.util.Kleenean; +import ch.njol.util.coll.CollectionUtils; public class ExprSelectionOfPlayer extends SimpleExpression { private Expression player; @@ -66,21 +68,13 @@ public class ExprSelectionOfPlayer extends SimpleExpression { Location pos2 = new Location(we.getSelection(p).getWorld(), pos2Vec.getX(), pos2Vec.getY(), pos2Vec.getZ()); return new Location[] { pos1, pos2 }; } -/* @Override public void change(Event e, @Nullable Object[] delta, ChangeMode mode) { Player p = player.getSingle(e); - Object[] objs = getSource().getAll(e); - for (int i = 0; i < objs.length; i++) { - if (i > 0) { - Bukkit.broadcastMessage("WOT M8!! GREATER THAN 1!!"); - Bukkit.broadcastMessage(objs[i].toString()); - } - } - if (mode == ChangeMode.SET) { - we.setSelection(p, new CuboidSelection(((Location) objs[0]).getWorld(), (Location) objs[0], (Location) objs[1])); - } else if (mode == ChangeMode.DELETE || mode == ChangeMode.RESET) { - we.setSelection(p, null); + if (mode == ChangeMode.DELETE || mode == ChangeMode.RESET) { + if (we.getSelection(p) == null) + return; + we.getSession(p).getRegionSelector((World) BukkitUtil.getLocalWorld(we.getSelection(p).getWorld())).clear(); } } @@ -88,10 +82,9 @@ public class ExprSelectionOfPlayer extends SimpleExpression { @Override @Nullable public Class[] acceptChange(ChangeMode mode) { - if (mode == ChangeMode.SET || mode == ChangeMode.DELETE || mode == ChangeMode.RESET) { + if (mode == ChangeMode.DELETE || mode == ChangeMode.RESET) { return CollectionUtils.array(Location.class); } return null; } -*/ } \ No newline at end of file diff --git a/src/me/TheBukor/expressions/ExprSelectionPos1.java b/src/me/TheBukor/expressions/ExprSelectionPos1.java index 9f5a8de..2c94078 100644 --- a/src/me/TheBukor/expressions/ExprSelectionPos1.java +++ b/src/me/TheBukor/expressions/ExprSelectionPos1.java @@ -13,12 +13,15 @@ import com.sk89q.worldedit.bukkit.BukkitUtil; import com.sk89q.worldedit.bukkit.WorldEditPlugin; import com.sk89q.worldedit.regions.CuboidRegion; import com.sk89q.worldedit.regions.Region; +import com.sk89q.worldedit.regions.selector.CuboidRegionSelector; import com.sk89q.worldedit.world.World; +import ch.njol.skript.classes.Changer.ChangeMode; import ch.njol.skript.lang.Expression; import ch.njol.skript.lang.SkriptParser.ParseResult; import ch.njol.skript.lang.util.SimpleExpression; import ch.njol.util.Kleenean; +import ch.njol.util.coll.CollectionUtils; public class ExprSelectionPos1 extends SimpleExpression { private Expression player; @@ -56,11 +59,39 @@ public class ExprSelectionPos1 extends SimpleExpression { } catch (IncompleteRegionException ex) { return null; } - if (!(region instanceof CuboidRegion)) { + if (!(region instanceof CuboidRegion)) return null; //Who uses polygonal and other selection types anyways? - } CuboidRegion cuboid = (CuboidRegion) region; Vector pos = cuboid.getPos1(); - return new Location[] { new Location(we.getSelection(p).getWorld(), pos.getX(), pos.getY(), pos.getZ()) }; + return new Location[] { BukkitUtil.toLocation(we.getSelection(p).getWorld(), pos) }; + } + + @Override + public void change(Event e, @Nullable Object[] delta, ChangeMode mode) { + Player p = player.getSingle(e); + Location newLoc = (Location) delta[0]; + if (mode == ChangeMode.SET) { + Region region = null; + try { + region = we.getSession(p).getSelection((World) BukkitUtil.getLocalWorld(we.getSelection(p).getWorld())); + } catch (IncompleteRegionException | NullPointerException ex) { + CuboidRegionSelector cuboidregion = new CuboidRegionSelector(BukkitUtil.getLocalWorld((org.bukkit.World) newLoc.getWorld()), BukkitUtil.toVector(newLoc), BukkitUtil.toVector(newLoc)); + we.getSession(p).setRegionSelector((World) BukkitUtil.getLocalWorld(p.getWorld()), cuboidregion); + } + if (!(region instanceof CuboidRegion)) + return; //Who uses polygonal and other selection types anyways? + CuboidRegion cuboid = (CuboidRegion) region; + cuboid.setPos1(BukkitUtil.toVector(newLoc)); + } + } + + @SuppressWarnings("unchecked") + @Override + @Nullable + public Class[] acceptChange(ChangeMode mode) { + if (mode == ChangeMode.SET) { + return CollectionUtils.array(Location.class); + } + return null; } } \ No newline at end of file diff --git a/src/me/TheBukor/expressions/ExprSelectionPos2.java b/src/me/TheBukor/expressions/ExprSelectionPos2.java index 0291aac..2d0cf6a 100644 --- a/src/me/TheBukor/expressions/ExprSelectionPos2.java +++ b/src/me/TheBukor/expressions/ExprSelectionPos2.java @@ -13,12 +13,15 @@ import com.sk89q.worldedit.bukkit.BukkitUtil; import com.sk89q.worldedit.bukkit.WorldEditPlugin; import com.sk89q.worldedit.regions.CuboidRegion; import com.sk89q.worldedit.regions.Region; +import com.sk89q.worldedit.regions.selector.CuboidRegionSelector; import com.sk89q.worldedit.world.World; +import ch.njol.skript.classes.Changer.ChangeMode; import ch.njol.skript.lang.Expression; import ch.njol.skript.lang.SkriptParser.ParseResult; import ch.njol.skript.lang.util.SimpleExpression; import ch.njol.util.Kleenean; +import ch.njol.util.coll.CollectionUtils; public class ExprSelectionPos2 extends SimpleExpression { private Expression player; @@ -56,11 +59,39 @@ public class ExprSelectionPos2 extends SimpleExpression { } catch (IncompleteRegionException ex) { return null; } - if (!(region instanceof CuboidRegion)) { + if (!(region instanceof CuboidRegion)) return null; //Who uses polygonal and other selection types anyways? - } CuboidRegion cuboid = (CuboidRegion) region; Vector pos = cuboid.getPos2(); - return new Location[] { new Location(we.getSelection(p).getWorld(), pos.getX(), pos.getY(), pos.getZ()) }; + return new Location[] { BukkitUtil.toLocation(we.getSelection(p).getWorld(), pos) }; + } + + @Override + public void change(Event e, @Nullable Object[] delta, ChangeMode mode) { + Player p = player.getSingle(e); + Location newLoc = (Location) delta[0]; + if (mode == ChangeMode.SET) { + Region region = null; + try { + region = we.getSession(p).getSelection((World) BukkitUtil.getLocalWorld(we.getSelection(p).getWorld())); + } catch (IncompleteRegionException | NullPointerException ex) { + CuboidRegionSelector cuboidregion = new CuboidRegionSelector(BukkitUtil.getLocalWorld((org.bukkit.World) newLoc.getWorld()), BukkitUtil.toVector(newLoc), BukkitUtil.toVector(newLoc)); + we.getSession(p).setRegionSelector((World) BukkitUtil.getLocalWorld(p.getWorld()), cuboidregion); + } + if (!(region instanceof CuboidRegion)) + return; //Who uses polygonal and other selection types anyways? + CuboidRegion cuboid = (CuboidRegion) region; + cuboid.setPos2(BukkitUtil.toVector(newLoc)); + } + } + + @SuppressWarnings("unchecked") + @Override + @Nullable + public Class[] acceptChange(ChangeMode mode) { + if (mode == ChangeMode.SET) { + return CollectionUtils.array(Location.class); + } + return null; } } \ No newline at end of file