Experimental "WorldEdit set blocks" effect.
This commit is contained in:
parent
382e8be72e
commit
480bba958a
@ -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>(net.minecraft.server.v1_8_R3.NBTTagCompound.class, "compound").name("NBT Tag Compound").parser(new Parser<net.minecraft.server.v1_8_R3.NBTTagCompound>() {
|
||||
Classes.registerClass(new ClassInfo<net.minecraft.server.v1_8_R3.NBTTagCompound>(net.minecraft.server.v1_8_R3.NBTTagCompound.class, "[nbt] compound[s]").name("NBT Compound").parser(new Parser<net.minecraft.server.v1_8_R3.NBTTagCompound>() {
|
||||
|
||||
@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");
|
||||
|
59
src/me/TheBukor/effects/EffExecuteWorldEdit.java
Normal file
59
src/me/TheBukor/effects/EffExecuteWorldEdit.java
Normal file
@ -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> player;
|
||||
private Expression<ItemStack> block;
|
||||
private Expression<Integer> 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<Player>) expr[0];
|
||||
block = (Expression<ItemStack>) expr[1];
|
||||
blockLimit = (Expression<Integer>) 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
16
src/me/TheBukor/enums/WorldEditOperations.java
Normal file
16
src/me/TheBukor/enums/WorldEditOperations.java
Normal file
@ -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;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user