From 480bba958aa2db3d011b36ddcb1766b98bef945c Mon Sep 17 00:00:00 2001 From: Richard Date: Sat, 28 Nov 2015 21:43:47 -0200 Subject: [PATCH] Experimental "WorldEdit set blocks" effect. --- src/me/TheBukor/SkStuff.java | 5 +- .../TheBukor/effects/EffExecuteWorldEdit.java | 59 +++++++++++++++++++ .../TheBukor/enums/WorldEditOperations.java | 16 +++++ 3 files changed, 79 insertions(+), 1 deletion(-) create mode 100644 src/me/TheBukor/effects/EffExecuteWorldEdit.java create mode 100644 src/me/TheBukor/enums/WorldEditOperations.java diff --git a/src/me/TheBukor/SkStuff.java b/src/me/TheBukor/SkStuff.java index 9a1f9ef..637909c 100644 --- a/src/me/TheBukor/SkStuff.java +++ b/src/me/TheBukor/SkStuff.java @@ -14,6 +14,7 @@ import ch.njol.skript.lang.ExpressionType; import ch.njol.skript.lang.ParseContext; import ch.njol.skript.registrations.Classes; import me.TheBukor.conditions.CondSelectionContains; +import me.TheBukor.effects.EffExecuteWorldEdit; import me.TheBukor.expressions.ExprAreaOfSelection; import me.TheBukor.expressions.ExprHeightOfSchematic; import me.TheBukor.expressions.ExprHeightOfSelection; @@ -133,7 +134,7 @@ public class SkStuff extends JavaPlugin { Skript.registerExpression(ExprNBTv1_8_R3.class, net.minecraft.server.v1_8_R3.NBTTagCompound.class, ExpressionType.PROPERTY, "nbt[[ ]tag[s]] of %entity/block/itemstack%", "%entity/block/itemstack%'s nbt[[ ]tag[s]]"); Skript.registerExpression(ExprItemNBTv1_8_R3.class, ItemStack.class, ExpressionType.SIMPLE, "%itemstack% with [custom] nbt[[ ]tag[s]] %string%"); Skript.registerExpression(ExprTagOfv1_8_R3.class, Object.class, ExpressionType.SIMPLE, "[nbt[ ]]tag %string% of [nbt [compound]] %compound%"); - Classes.registerClass(new ClassInfo(net.minecraft.server.v1_8_R3.NBTTagCompound.class, "compound").name("NBT Tag Compound").parser(new Parser() { + Classes.registerClass(new ClassInfo(net.minecraft.server.v1_8_R3.NBTTagCompound.class, "[nbt] compound[s]").name("NBT Compound").parser(new Parser() { @Override public String getVariableNamePattern() { @@ -172,7 +173,9 @@ public class SkStuff extends JavaPlugin { condAmount += 1; evtAmount += 1; exprAmount += 12; + 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(EffExecuteWorldEdit.class, "make %player% execute (world[ ]edit|we) [operation] set (using|with) %itemstack% [[with] limit [of] %integer% [blocks]]", "execute %player% (world[ ]edit|we) [operation] set (using|with) %itemstack% [[with] limit [of] %integer% [blocks]"); Skript.registerExpression(ExprSelectionOfPlayer.class, Location.class, ExpressionType.PROPERTY, "[(world[ ]edit|we)] selection of %player%", "%player%'s [(world[ ]edit|we)] selection"); Skript.registerExpression(ExprSelectionPos1.class, Location.class, ExpressionType.PROPERTY, "[(world[ ]edit|we)] po(s|int)[ ]1 of %player%", "%player%'s [(world[ ]edit|we)] po(s|int)[ ]1"); Skript.registerExpression(ExprSelectionPos2.class, Location.class, ExpressionType.PROPERTY, "[(world[ ]edit|we)] po(s|int)[ ]2 of %player%", "%player%'s [(world[ ]edit|we)] po(s|int)[ ]2"); diff --git a/src/me/TheBukor/effects/EffExecuteWorldEdit.java b/src/me/TheBukor/effects/EffExecuteWorldEdit.java new file mode 100644 index 0000000..3446d55 --- /dev/null +++ b/src/me/TheBukor/effects/EffExecuteWorldEdit.java @@ -0,0 +1,59 @@ +package me.TheBukor.effects; + +import javax.annotation.Nullable; + +import org.bukkit.Bukkit; +import org.bukkit.entity.Player; +import org.bukkit.event.Event; +import org.bukkit.inventory.ItemStack; + +import com.sk89q.worldedit.EditSession; +import com.sk89q.worldedit.IncompleteRegionException; +import com.sk89q.worldedit.MaxChangedBlocksException; +import com.sk89q.worldedit.blocks.BaseBlock; +import com.sk89q.worldedit.bukkit.WorldEditPlugin; + +import ch.njol.skript.lang.Effect; +import ch.njol.skript.lang.Expression; +import ch.njol.skript.lang.SkriptParser.ParseResult; +import ch.njol.util.Kleenean; + +@SuppressWarnings("deprecation") +public class EffExecuteWorldEdit extends Effect { + private Expression player; + private Expression block; + private Expression blockLimit; + private WorldEditPlugin we = (WorldEditPlugin) Bukkit.getPluginManager().getPlugin("WorldEdit"); + + @SuppressWarnings("unchecked") + @Override + public boolean init(Expression[] expr, int matchedPattern, Kleenean arg2, ParseResult arg3) { + player = (Expression) expr[0]; + block = (Expression) expr[1]; + blockLimit = (Expression) expr[2]; + return true; + } + + @Override + public String toString(@Nullable Event e, boolean arg1) { + return "make " + player.toString(e, false) + " execute WorldEdit set using " + block.toString(e, false) + new String(blockLimit.getSingle(e) != null ? " with limit of " + blockLimit.toString(e, false) + " blocks" : ""); + } + + @Override + protected void execute(Event e) { + Player p = player.getSingle(e); + ItemStack b = block.getSingle(e); + Integer limit = blockLimit.getSingle(e); + if (we.getSelection(p) != null) { + if (b.getType().isBlock()) { + try { + EditSession session = we.createEditSession(p); + session.setBlockChangeLimit(limit != null ? limit : 4096); + session.setBlocks(we.getSession(p).getRegion(), new BaseBlock(b.getTypeId())); + } catch (MaxChangedBlocksException | IncompleteRegionException ex) { + return; + } + } + } + } +} diff --git a/src/me/TheBukor/enums/WorldEditOperations.java b/src/me/TheBukor/enums/WorldEditOperations.java new file mode 100644 index 0000000..efe2a04 --- /dev/null +++ b/src/me/TheBukor/enums/WorldEditOperations.java @@ -0,0 +1,16 @@ +package me.TheBukor.enums; + +public enum WorldEditOperations { + SET("set"), + WALLS("walls"); + + private final String id; + + WorldEditOperations(String id) { + this.id = id; + } + + public String getId() { + return id; + } +}