First Commit.
This commit is contained in:
commit
382e8be72e
11
.classpath
Normal file
11
.classpath
Normal file
@ -0,0 +1,11 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<classpath>
|
||||
<classpathentry kind="src" path="src"/>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
|
||||
<classpathentry kind="lib" path="C:/Users/Rubi/AppData/Roaming/.minecraft/Server - Survival - 1.8/spigot.jar"/>
|
||||
<classpathentry kind="lib" path="C:/Users/Rubi/AppData/Roaming/.minecraft/Server - Survival - 1.8/plugins/Skript.jar"/>
|
||||
<classpathentry kind="lib" path="C:/Users/Rubi/AppData/Roaming/.minecraft/workspace/Spigot 1.8, 1.8.3/1.8.3.jar"/>
|
||||
<classpathentry kind="lib" path="C:/Users/Rubi/AppData/Roaming/.minecraft/workspace/Spigot 1.8, 1.8.3/1.8.jar"/>
|
||||
<classpathentry kind="lib" path="C:/Users/Rubi/AppData/Roaming/.minecraft/Server - Survival - 1.8/plugins/WorldEdit.jar"/>
|
||||
<classpathentry kind="output" path="bin"/>
|
||||
</classpath>
|
17
.project
Normal file
17
.project
Normal file
@ -0,0 +1,17 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>SkStuff</name>
|
||||
<comment></comment>
|
||||
<projects>
|
||||
</projects>
|
||||
<buildSpec>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.jdt.core.javabuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
</buildSpec>
|
||||
<natures>
|
||||
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||
</natures>
|
||||
</projectDescription>
|
11
.settings/org.eclipse.jdt.core.prefs
Normal file
11
.settings/org.eclipse.jdt.core.prefs
Normal file
@ -0,0 +1,11 @@
|
||||
eclipse.preferences.version=1
|
||||
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
|
||||
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
|
||||
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
|
||||
org.eclipse.jdt.core.compiler.compliance=1.8
|
||||
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
|
||||
org.eclipse.jdt.core.compiler.debug.localVariable=generate
|
||||
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
|
||||
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
|
||||
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
|
||||
org.eclipse.jdt.core.compiler.source=1.8
|
1
bin/.gitignore
vendored
Normal file
1
bin/.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
||||
/me/
|
6
plugin.yml
Normal file
6
plugin.yml
Normal file
@ -0,0 +1,6 @@
|
||||
name: SkStuff
|
||||
author: TheBukor
|
||||
description: A Skript addon which adds extra functionalities such as NBT and extended WorldEdit support.
|
||||
version: 1.2.1
|
||||
main: me.TheBukor.SkStuff
|
||||
softdepend: [Skript]
|
211
src/me/TheBukor/SkStuff.java
Normal file
211
src/me/TheBukor/SkStuff.java
Normal file
@ -0,0 +1,211 @@
|
||||
package me.TheBukor;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import ch.njol.skript.Skript;
|
||||
import ch.njol.skript.classes.ClassInfo;
|
||||
import ch.njol.skript.classes.Parser;
|
||||
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.expressions.ExprAreaOfSelection;
|
||||
import me.TheBukor.expressions.ExprHeightOfSchematic;
|
||||
import me.TheBukor.expressions.ExprHeightOfSelection;
|
||||
import me.TheBukor.expressions.ExprItemNBTv1_8_R1;
|
||||
import me.TheBukor.expressions.ExprItemNBTv1_8_R2;
|
||||
import me.TheBukor.expressions.ExprItemNBTv1_8_R3;
|
||||
import me.TheBukor.expressions.ExprLengthOfSchematic;
|
||||
import me.TheBukor.expressions.ExprLengthOfSelection;
|
||||
import me.TheBukor.expressions.ExprNBTv1_8_R1;
|
||||
import me.TheBukor.expressions.ExprNBTv1_8_R2;
|
||||
import me.TheBukor.expressions.ExprNBTv1_8_R3;
|
||||
import me.TheBukor.expressions.ExprSelectionOfPlayer;
|
||||
import me.TheBukor.expressions.ExprSelectionPos1;
|
||||
import me.TheBukor.expressions.ExprSelectionPos2;
|
||||
import me.TheBukor.expressions.ExprTagOfv1_8_R1;
|
||||
import me.TheBukor.expressions.ExprTagOfv1_8_R2;
|
||||
import me.TheBukor.expressions.ExprTagOfv1_8_R3;
|
||||
import me.TheBukor.expressions.ExprVolumeOfSchematic;
|
||||
import me.TheBukor.expressions.ExprVolumeOfSelection;
|
||||
import me.TheBukor.expressions.ExprWidthOfSchematic;
|
||||
import me.TheBukor.expressions.ExprWidthOfSelection;
|
||||
import net.minecraft.server.v1_8_R1.MojangsonParser;
|
||||
import net.minecraft.server.v1_8_R1.NBTTagCompound;
|
||||
import net.minecraft.server.v1_8_R2.MojangsonParseException;
|
||||
|
||||
public class SkStuff extends JavaPlugin {
|
||||
private int condAmount = 0;
|
||||
private int exprAmount = 0;
|
||||
private int typeAmount = 0;
|
||||
private int evtAmount = 0;
|
||||
public void onEnable() {
|
||||
if (Bukkit.getPluginManager().getPlugin("Skript") != null) {
|
||||
Skript.registerAddon(this);
|
||||
getLogger().info("SkStuff " + this.getDescription().getVersion() + " has been successfully enabled!");
|
||||
if (Bukkit.getVersion().contains("(MC: 1.8)")){
|
||||
getLogger().info("Successfully found 1.8! Registering version specific expressions...");
|
||||
exprAmount += 3;
|
||||
typeAmount += 1;
|
||||
Skript.registerExpression(ExprNBTv1_8_R1.class, NBTTagCompound.class, ExpressionType.PROPERTY, "nbt[[ ]tag[s]] of %entity/block/itemstack%", "%entity/block/itemstack%'s nbt[[ ]tag[s]]");
|
||||
Skript.registerExpression(ExprItemNBTv1_8_R1.class, ItemStack.class, ExpressionType.SIMPLE, "%itemstack% with [custom] nbt[[ ]tag[s]] %string%");
|
||||
Skript.registerExpression(ExprTagOfv1_8_R1.class, Object.class, ExpressionType.SIMPLE, "[nbt[ ]]tag %string% of [nbt [compound]] %compound%");
|
||||
Classes.registerClass(new ClassInfo<NBTTagCompound>(NBTTagCompound.class, "compound").name("NBT Tag Compound").parser(new Parser<NBTTagCompound>() {
|
||||
|
||||
@Override
|
||||
public String getVariableNamePattern() {
|
||||
return ".+";
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public NBTTagCompound parse(String s, ParseContext arg1) {
|
||||
NBTTagCompound NBT = new NBTTagCompound();
|
||||
NBTTagCompound NBT1 = MojangsonParser.parse(s);
|
||||
NBT1.a(NBT);
|
||||
if (NBT.isEmpty() || NBT == null) {
|
||||
return null;
|
||||
}
|
||||
return NBT;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString(NBTTagCompound compound, int arg1) {
|
||||
return compound.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toVariableNameString(NBTTagCompound compound) {
|
||||
return compound.toString();
|
||||
}
|
||||
}));
|
||||
}
|
||||
if (Bukkit.getVersion().contains("(MC: 1.8.3)")){
|
||||
getLogger().info("Successfully found 1.8.3! Registering version specific expressions...");
|
||||
exprAmount += 3;
|
||||
typeAmount += 1;
|
||||
Skript.registerExpression(ExprNBTv1_8_R2.class, net.minecraft.server.v1_8_R2.NBTTagCompound.class, ExpressionType.PROPERTY, "nbt[[ ]tag[s]] of %entity/block/itemstack%", "%entity/block/itemstack%'s nbt[[ ]tag[s]]");
|
||||
Skript.registerExpression(ExprItemNBTv1_8_R2.class, ItemStack.class, ExpressionType.SIMPLE, "%itemstack% with [custom] nbt[[ ]tag[s]] %string%");
|
||||
Skript.registerExpression(ExprTagOfv1_8_R2.class, Object.class, ExpressionType.SIMPLE, "[nbt[ ]]tag %string% of [nbt [compound]] %compound%");
|
||||
Classes.registerClass(new ClassInfo<net.minecraft.server.v1_8_R2.NBTTagCompound>(net.minecraft.server.v1_8_R2.NBTTagCompound.class, "compound").name("NBT Tag Compound").parser(new Parser<net.minecraft.server.v1_8_R2.NBTTagCompound>() {
|
||||
|
||||
@Override
|
||||
public String getVariableNamePattern() {
|
||||
return ".+";
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public net.minecraft.server.v1_8_R2.NBTTagCompound parse(String s, ParseContext arg1) {
|
||||
net.minecraft.server.v1_8_R2.NBTTagCompound NBT = new net.minecraft.server.v1_8_R2.NBTTagCompound();
|
||||
try {
|
||||
net.minecraft.server.v1_8_R2.NBTTagCompound NBT1 = net.minecraft.server.v1_8_R2.MojangsonParser.parse(s);
|
||||
NBT.a(NBT1);
|
||||
} catch (MojangsonParseException ex) {
|
||||
Skript.warning("Error when parsing NBT - " + ex.getMessage());
|
||||
}
|
||||
if (NBT.isEmpty() || NBT == null) {
|
||||
return null;
|
||||
}
|
||||
return NBT;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString(net.minecraft.server.v1_8_R2.NBTTagCompound compound, int arg1) {
|
||||
return compound.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toVariableNameString(net.minecraft.server.v1_8_R2.NBTTagCompound compound) {
|
||||
return compound.toString();
|
||||
}
|
||||
}));
|
||||
}
|
||||
if (Bukkit.getVersion().contains("(MC: 1.8.4)") || Bukkit.getVersion().contains("(MC: 1.8.5)") || Bukkit.getVersion().contains("(MC: 1.8.6)") || Bukkit.getVersion().contains("(MC: 1.8.7)") || Bukkit.getVersion().contains("(MC: 1.8.8)")) {
|
||||
getLogger().info("Successfully found 1.8.4 - 1.8.8! Registering version specific expressions...");
|
||||
exprAmount += 3;
|
||||
typeAmount += 1;
|
||||
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>() {
|
||||
|
||||
@Override
|
||||
public String getVariableNamePattern() {
|
||||
return ".+";
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public net.minecraft.server.v1_8_R3.NBTTagCompound parse(String s, ParseContext arg1) {
|
||||
net.minecraft.server.v1_8_R3.NBTTagCompound NBT = new net.minecraft.server.v1_8_R3.NBTTagCompound();
|
||||
try {
|
||||
net.minecraft.server.v1_8_R3.NBTTagCompound NBT1 = net.minecraft.server.v1_8_R3.MojangsonParser.parse(s);
|
||||
NBT.a(NBT1);
|
||||
} catch (net.minecraft.server.v1_8_R3.MojangsonParseException ex) {
|
||||
return null;
|
||||
}
|
||||
if (NBT.isEmpty() || NBT == null) {
|
||||
return null;
|
||||
}
|
||||
return NBT;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString(net.minecraft.server.v1_8_R3.NBTTagCompound compound, int arg1) {
|
||||
return compound.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toVariableNameString(net.minecraft.server.v1_8_R3.NBTTagCompound compound) {
|
||||
return compound.toString();
|
||||
}
|
||||
}));
|
||||
}
|
||||
if (Bukkit.getPluginManager().getPlugin("WorldEdit") != null) {
|
||||
getLogger().info("WorldEdit found! Registering WorldEdit stuff...");
|
||||
condAmount += 1;
|
||||
evtAmount += 1;
|
||||
exprAmount += 12;
|
||||
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.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");
|
||||
Skript.registerExpression(ExprVolumeOfSelection.class, Integer.class, ExpressionType.SIMPLE, "volume of [(world[ ]edit|we)] selection of %player%", "%player%'s [(world[ ]edit|we)] selection volume");
|
||||
Skript.registerExpression(ExprWidthOfSelection.class, Integer.class, ExpressionType.SIMPLE, "(x( |-)size|width) of [(world[ ]edit|we)] selection of %player%", "%player%'s [(world[ ]edit|we)] selection (x( |-)size|width)");
|
||||
Skript.registerExpression(ExprLengthOfSelection.class, Integer.class, ExpressionType.SIMPLE, "(z( |-)size|length) of [(world[ ]edit|we)] selection of %player%", "%player%'s [(world[ ]edit|we) ]selection (z( |-)size|length)");
|
||||
Skript.registerExpression(ExprHeightOfSelection.class, Integer.class, ExpressionType.SIMPLE, "(y( |-)size|height) of [(world[ ]edit|we)] selection of %player%", "%player%'s [(world[ ]edit|we) ]selection (y( |-)size|height)");
|
||||
Skript.registerExpression(ExprAreaOfSelection.class, Integer.class, ExpressionType.SIMPLE, "area of [(world[ ]edit|we)] selection of %player%", "%player%'s [(world[ ]edit|we)] selection area");
|
||||
Skript.registerExpression(ExprVolumeOfSchematic.class, Integer.class, ExpressionType.SIMPLE, "volume of schem[atic] %string% [from [folder] %string%]");
|
||||
Skript.registerExpression(ExprWidthOfSchematic.class, Integer.class, ExpressionType.SIMPLE, "(x( |-)size|width) of schem[atic] %string% [from [folder] %string%]");
|
||||
Skript.registerExpression(ExprHeightOfSchematic.class, Integer.class, ExpressionType.SIMPLE, "(y( |-)size|height) of schem[atic] %string% [from [folder] %string%]");
|
||||
Skript.registerExpression(ExprLengthOfSchematic.class, Integer.class, ExpressionType.SIMPLE, "(z( |-)size|length) of schem[atic] %string% [from [folder] %string%]");
|
||||
}
|
||||
String pluralCond = "s";
|
||||
String pluralType = "s";
|
||||
String pluralEvt = "s";
|
||||
if (condAmount == 1) {
|
||||
pluralCond = "";
|
||||
}
|
||||
if (typeAmount == 1) {
|
||||
pluralType = "";
|
||||
}
|
||||
if (evtAmount == 1) {
|
||||
pluralEvt = "";
|
||||
}
|
||||
getLogger().info("Everything ready! Loaded a total of " + condAmount + " condition" + pluralCond + ", " + evtAmount + "event" + pluralEvt + ", " + exprAmount + " expressions and " + typeAmount + " type" + pluralType + "!");
|
||||
} else {
|
||||
getLogger().info("Unable to find Skript, disabling SkStuff...");
|
||||
this.onDisable();
|
||||
}
|
||||
}
|
||||
|
||||
public void onDisable() {
|
||||
getLogger().info("SkStuff " + this.getDescription().getVersion() + " has been successfully disabled");
|
||||
}
|
||||
}
|
49
src/me/TheBukor/conditions/CondSelectionContains.java
Normal file
49
src/me/TheBukor/conditions/CondSelectionContains.java
Normal file
@ -0,0 +1,49 @@
|
||||
package me.TheBukor.conditions;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.Event;
|
||||
|
||||
import com.sk89q.worldedit.bukkit.WorldEditPlugin;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import ch.njol.skript.lang.Condition;
|
||||
import ch.njol.skript.lang.Expression;
|
||||
import ch.njol.skript.lang.SkriptParser.ParseResult;
|
||||
import ch.njol.util.Checker;
|
||||
import ch.njol.util.Kleenean;
|
||||
|
||||
public class CondSelectionContains extends Condition {
|
||||
private Expression<Player> player;
|
||||
private Expression<Location> loc;
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public boolean init(Expression<?>[] expr, int matchedPattern, Kleenean arg2, ParseResult arg3) {
|
||||
player = (Expression<Player>) expr[0];
|
||||
loc = (Expression<Location>) expr[1];
|
||||
setNegated(matchedPattern == 2 || matchedPattern == 3);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString(@Nullable Event e, boolean arg1) {
|
||||
return "if WorldEdit selection of " + player.toString(e, false) + (isNegated() ? " doesn't contain " : " contains ") + loc.toString(e, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean check(Event e) {
|
||||
WorldEditPlugin we = (WorldEditPlugin) Bukkit.getServer().getPluginManager().getPlugin("WorldEdit");
|
||||
if (we.getSelection(player.getSingle(e)) == null) {
|
||||
return false;
|
||||
}
|
||||
return player.check(e, new Checker<Player>() {
|
||||
@Override
|
||||
public boolean check(Player p) {
|
||||
return we.getSelection(p).contains(loc.getSingle(e));
|
||||
}
|
||||
}, isNegated());
|
||||
}
|
||||
}
|
51
src/me/TheBukor/expressions/ExprAreaOfSelection.java
Normal file
51
src/me/TheBukor/expressions/ExprAreaOfSelection.java
Normal file
@ -0,0 +1,51 @@
|
||||
package me.TheBukor.expressions;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.Event;
|
||||
|
||||
import com.sk89q.worldedit.bukkit.WorldEditPlugin;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
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;
|
||||
|
||||
public class ExprAreaOfSelection extends SimpleExpression<Integer> {
|
||||
private Expression<Player> player;
|
||||
|
||||
@Override
|
||||
public Class<? extends Integer> getReturnType() {
|
||||
return Integer.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSingle() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public boolean init(Expression<?>[] expr, int matchedPattern, Kleenean arg2, ParseResult arg3) {
|
||||
player = (Expression<Player>) expr[0];
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString(@Nullable Event e, boolean arg1) {
|
||||
return "the area of the WorldEdit selection of " + player.toString(e, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
protected Integer[] get(Event e) {
|
||||
WorldEditPlugin worldEdit = (WorldEditPlugin) Bukkit.getServer().getPluginManager().getPlugin("WorldEdit");
|
||||
if (worldEdit.getSelection(player.getSingle(e)) == null) {
|
||||
return null;
|
||||
}
|
||||
return new Integer[] { (worldEdit.getSelection(player.getSingle(e)).getWidth() * worldEdit.getSelection(player.getSingle(e)).getLength()) };
|
||||
}
|
||||
|
||||
}
|
64
src/me/TheBukor/expressions/ExprHeightOfSchematic.java
Normal file
64
src/me/TheBukor/expressions/ExprHeightOfSchematic.java
Normal file
@ -0,0 +1,64 @@
|
||||
package me.TheBukor.expressions;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.event.Event;
|
||||
|
||||
import com.sk89q.worldedit.bukkit.WorldEditPlugin;
|
||||
import com.sk89q.worldedit.data.DataException;
|
||||
import com.sk89q.worldedit.schematic.MCEditSchematicFormat;
|
||||
|
||||
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;
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public class ExprHeightOfSchematic extends SimpleExpression<Integer> {
|
||||
private Expression<String> schematic;
|
||||
private Expression<String> folder;
|
||||
@SuppressWarnings("unused")
|
||||
private WorldEditPlugin we = (WorldEditPlugin) Bukkit.getServer().getPluginManager().getPlugin("WorldEdit");
|
||||
|
||||
@Override
|
||||
public Class<? extends Integer> getReturnType() {
|
||||
return Integer.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSingle() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public boolean init(Expression<?>[] expr, int matchedPattern, Kleenean arg2, ParseResult arg3) {
|
||||
schematic = (Expression<String>) expr[0];
|
||||
folder = (Expression<String>) expr[1];
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString(@Nullable Event e, boolean arg1) {
|
||||
return "the height of the schematic " + schematic.toString(e, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
protected Integer[] get(Event e) {
|
||||
String f = (folder.getSingle(e) != null) ? folder.getSingle(e) : "plugins/WorldEdit/";
|
||||
String schem = schematic.getSingle(e);
|
||||
File schemFile = new File((f.endsWith("/")) ? f : f + "/" + new String(schem.endsWith(".schematic") ? schem : schem + ".schematic"));
|
||||
Integer h = null;
|
||||
try {
|
||||
h = MCEditSchematicFormat.getFormat(schemFile).load(schemFile).getHeight();
|
||||
} catch (DataException | IOException e1) {
|
||||
return null;
|
||||
}
|
||||
return new Integer[] { h };
|
||||
}
|
||||
}
|
51
src/me/TheBukor/expressions/ExprHeightOfSelection.java
Normal file
51
src/me/TheBukor/expressions/ExprHeightOfSelection.java
Normal file
@ -0,0 +1,51 @@
|
||||
package me.TheBukor.expressions;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.Event;
|
||||
|
||||
import com.sk89q.worldedit.bukkit.WorldEditPlugin;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
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;
|
||||
|
||||
public class ExprHeightOfSelection extends SimpleExpression<Integer> {
|
||||
private Expression<Player> player;
|
||||
|
||||
@Override
|
||||
public Class<? extends Integer> getReturnType() {
|
||||
return Integer.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSingle() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public boolean init(Expression<?>[] expr, int matchedPattern, Kleenean arg2, ParseResult arg3) {
|
||||
player = (Expression<Player>) expr[0];
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString(@Nullable Event e, boolean arg1) {
|
||||
return "the height of the WorldEdit selection of " + player.toString(e, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
protected Integer[] get(Event e) {
|
||||
WorldEditPlugin worldEdit = (WorldEditPlugin) Bukkit.getServer().getPluginManager().getPlugin("WorldEdit");
|
||||
if (worldEdit.getSelection(player.getSingle(e)) == null) {
|
||||
return null;
|
||||
}
|
||||
return new Integer[] { worldEdit.getSelection(player.getSingle(e)).getHeight() };
|
||||
}
|
||||
|
||||
}
|
61
src/me/TheBukor/expressions/ExprItemNBTv1_8_R1.java
Normal file
61
src/me/TheBukor/expressions/ExprItemNBTv1_8_R1.java
Normal file
@ -0,0 +1,61 @@
|
||||
package me.TheBukor.expressions;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.craftbukkit.v1_8_R1.inventory.CraftItemStack;
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
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 net.minecraft.server.v1_8_R1.MojangsonParser;
|
||||
import net.minecraft.server.v1_8_R1.NBTTagCompound;
|
||||
|
||||
public class ExprItemNBTv1_8_R1 extends SimpleExpression<ItemStack> {
|
||||
private Expression<ItemStack> itemStack;
|
||||
private Expression<String> string;
|
||||
|
||||
@Override
|
||||
public Class<? extends ItemStack> getReturnType() {
|
||||
return ItemStack.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSingle() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public boolean init(Expression<?>[] expr, int matchedPattern, Kleenean arg2, ParseResult arg3) {
|
||||
itemStack = (Expression<ItemStack>) expr[0];
|
||||
string = (Expression<String>) expr[1];
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString(@Nullable Event e, boolean arg1) {
|
||||
return itemStack.toString(e, false) + " with custom NBT";
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public ItemStack[] get(Event e) {
|
||||
ItemStack item = itemStack.getSingle(e);
|
||||
String newTags = string.getSingle(e);
|
||||
if (item.getType() == Material.AIR || item == null) {
|
||||
return null;
|
||||
}
|
||||
net.minecraft.server.v1_8_R1.ItemStack nmsItem = CraftItemStack.asNMSCopy(item);
|
||||
NBTTagCompound NBT = MojangsonParser.parse(newTags);
|
||||
if (NBT == null || NBT.isEmpty()) {
|
||||
return new ItemStack[] { item };
|
||||
}
|
||||
nmsItem.setTag(NBT);
|
||||
ItemStack newItem = CraftItemStack.asCraftMirror(nmsItem);
|
||||
return new ItemStack[] { newItem };
|
||||
}
|
||||
}
|
68
src/me/TheBukor/expressions/ExprItemNBTv1_8_R2.java
Normal file
68
src/me/TheBukor/expressions/ExprItemNBTv1_8_R2.java
Normal file
@ -0,0 +1,68 @@
|
||||
package me.TheBukor.expressions;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.craftbukkit.v1_8_R2.inventory.CraftItemStack;
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import ch.njol.skript.Skript;
|
||||
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 net.minecraft.server.v1_8_R2.MojangsonParseException;
|
||||
import net.minecraft.server.v1_8_R2.MojangsonParser;
|
||||
import net.minecraft.server.v1_8_R2.NBTTagCompound;
|
||||
|
||||
public class ExprItemNBTv1_8_R2 extends SimpleExpression<ItemStack> {
|
||||
private Expression<ItemStack> itemStack;
|
||||
private Expression<String> string;
|
||||
|
||||
@Override
|
||||
public Class<? extends ItemStack> getReturnType() {
|
||||
return ItemStack.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSingle() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public boolean init(Expression<?>[] expr, int matchedPattern, Kleenean arg2, ParseResult arg3) {
|
||||
itemStack = (Expression<ItemStack>) expr[0];
|
||||
string = (Expression<String>) expr[1];
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString(@Nullable Event e, boolean arg1) {
|
||||
return itemStack.toString(e, false) + " with custom NBT";
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public ItemStack[] get(Event e) {
|
||||
ItemStack item = itemStack.getSingle(e);
|
||||
String newTags = string.getSingle(e);
|
||||
if (item.getType() == Material.AIR || item == null) {
|
||||
return null;
|
||||
}
|
||||
net.minecraft.server.v1_8_R2.ItemStack nmsItem = CraftItemStack.asNMSCopy(item);
|
||||
try {
|
||||
NBTTagCompound NBT = MojangsonParser.parse(newTags);
|
||||
if (NBT == null || NBT.isEmpty()) {
|
||||
return new ItemStack[] { item };
|
||||
}
|
||||
nmsItem.setTag(NBT);
|
||||
} catch (MojangsonParseException ex) {
|
||||
Skript.warning(ChatColor.RED + "Error when parsing NBT - " + ex.getMessage());
|
||||
}
|
||||
ItemStack newItem = CraftItemStack.asCraftMirror(nmsItem);
|
||||
return new ItemStack[] { newItem };
|
||||
}
|
||||
}
|
68
src/me/TheBukor/expressions/ExprItemNBTv1_8_R3.java
Normal file
68
src/me/TheBukor/expressions/ExprItemNBTv1_8_R3.java
Normal file
@ -0,0 +1,68 @@
|
||||
package me.TheBukor.expressions;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.craftbukkit.v1_8_R3.inventory.CraftItemStack;
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import ch.njol.skript.Skript;
|
||||
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 net.minecraft.server.v1_8_R3.MojangsonParseException;
|
||||
import net.minecraft.server.v1_8_R3.MojangsonParser;
|
||||
import net.minecraft.server.v1_8_R3.NBTTagCompound;
|
||||
|
||||
public class ExprItemNBTv1_8_R3 extends SimpleExpression<ItemStack> {
|
||||
private Expression<ItemStack> itemStack;
|
||||
private Expression<String> string;
|
||||
|
||||
@Override
|
||||
public Class<? extends ItemStack> getReturnType() {
|
||||
return ItemStack.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSingle() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public boolean init(Expression<?>[] expr, int matchedPattern, Kleenean arg2, ParseResult arg3) {
|
||||
itemStack = (Expression<ItemStack>) expr[0];
|
||||
string = (Expression<String>) expr[1];
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString(@Nullable Event e, boolean arg1) {
|
||||
return itemStack.toString(e, false) + " with custom NBT";
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public ItemStack[] get(Event e) {
|
||||
ItemStack item = itemStack.getSingle(e);
|
||||
String newTags = string.getSingle(e);
|
||||
if (item.getType() == Material.AIR || item == null) {
|
||||
return null;
|
||||
}
|
||||
net.minecraft.server.v1_8_R3.ItemStack nmsItem = CraftItemStack.asNMSCopy(item);
|
||||
try {
|
||||
NBTTagCompound NBT = MojangsonParser.parse(newTags);
|
||||
if (NBT == null || NBT.isEmpty()) {
|
||||
return new ItemStack[] { item };
|
||||
}
|
||||
nmsItem.setTag(NBT);
|
||||
} catch (MojangsonParseException ex) {
|
||||
Skript.warning(ChatColor.RED + "Error when parsing NBT - " + ex.getMessage());
|
||||
}
|
||||
ItemStack newItem = CraftItemStack.asCraftMirror(nmsItem);
|
||||
return new ItemStack[] { newItem };
|
||||
}
|
||||
}
|
64
src/me/TheBukor/expressions/ExprLengthOfSchematic.java
Normal file
64
src/me/TheBukor/expressions/ExprLengthOfSchematic.java
Normal file
@ -0,0 +1,64 @@
|
||||
package me.TheBukor.expressions;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.event.Event;
|
||||
|
||||
import com.sk89q.worldedit.bukkit.WorldEditPlugin;
|
||||
import com.sk89q.worldedit.data.DataException;
|
||||
import com.sk89q.worldedit.schematic.MCEditSchematicFormat;
|
||||
|
||||
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;
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public class ExprLengthOfSchematic extends SimpleExpression<Integer> {
|
||||
private Expression<String> schematic;
|
||||
private Expression<String> folder;
|
||||
@SuppressWarnings("unused")
|
||||
private WorldEditPlugin we = (WorldEditPlugin) Bukkit.getServer().getPluginManager().getPlugin("WorldEdit");
|
||||
|
||||
@Override
|
||||
public Class<? extends Integer> getReturnType() {
|
||||
return Integer.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSingle() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public boolean init(Expression<?>[] expr, int matchedPattern, Kleenean arg2, ParseResult arg3) {
|
||||
schematic = (Expression<String>) expr[0];
|
||||
folder = (Expression<String>) expr[1];
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString(@Nullable Event e, boolean arg1) {
|
||||
return "the length of the schematic " + schematic.toString(e, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
protected Integer[] get(Event e) {
|
||||
String f = (folder.getSingle(e) != null) ? folder.getSingle(e) : "plugins/WorldEdit/";
|
||||
String schem = schematic.getSingle(e);
|
||||
File schemFile = new File((f.endsWith("/")) ? f : f + "/" + new String(schem.endsWith(".schematic") ? schem : schem + ".schematic"));
|
||||
Integer l = null;
|
||||
try {
|
||||
l = MCEditSchematicFormat.getFormat(schemFile).load(schemFile).getLength();
|
||||
} catch (DataException | IOException e1) {
|
||||
return null;
|
||||
}
|
||||
return new Integer[] { l };
|
||||
}
|
||||
}
|
51
src/me/TheBukor/expressions/ExprLengthOfSelection.java
Normal file
51
src/me/TheBukor/expressions/ExprLengthOfSelection.java
Normal file
@ -0,0 +1,51 @@
|
||||
package me.TheBukor.expressions;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.Event;
|
||||
|
||||
import com.sk89q.worldedit.bukkit.WorldEditPlugin;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
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;
|
||||
|
||||
public class ExprLengthOfSelection extends SimpleExpression<Integer> {
|
||||
private Expression<Player> player;
|
||||
|
||||
@Override
|
||||
public Class<? extends Integer> getReturnType() {
|
||||
return Integer.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSingle() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public boolean init(Expression<?>[] expr, int matchedPattern, Kleenean arg2, ParseResult arg3) {
|
||||
player = (Expression<Player>) expr[0];
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString(@Nullable Event e, boolean arg1) {
|
||||
return "the length of the WorldEdit selection of " + player.toString(e, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
protected Integer[] get(Event e) {
|
||||
WorldEditPlugin worldEdit = (WorldEditPlugin) Bukkit.getServer().getPluginManager().getPlugin("WorldEdit");
|
||||
if (worldEdit.getSelection(player.getSingle(e)) == null) {
|
||||
return null;
|
||||
}
|
||||
return new Integer[] { worldEdit.getSelection(player.getSingle(e)).getLength() };
|
||||
}
|
||||
|
||||
}
|
197
src/me/TheBukor/expressions/ExprNBTv1_8_R1.java
Normal file
197
src/me/TheBukor/expressions/ExprNBTv1_8_R1.java
Normal file
@ -0,0 +1,197 @@
|
||||
package me.TheBukor.expressions;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.craftbukkit.v1_8_R1.CraftWorld;
|
||||
import org.bukkit.craftbukkit.v1_8_R1.entity.CraftEntity;
|
||||
import org.bukkit.craftbukkit.v1_8_R1.inventory.CraftItemStack;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
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.skript.util.Slot;
|
||||
import ch.njol.util.Kleenean;
|
||||
import ch.njol.util.coll.CollectionUtils;
|
||||
import net.minecraft.server.v1_8_R1.BlockPosition;
|
||||
import net.minecraft.server.v1_8_R1.MojangsonParser;
|
||||
import net.minecraft.server.v1_8_R1.NBTTagCompound;
|
||||
import net.minecraft.server.v1_8_R1.TileEntity;
|
||||
|
||||
public class ExprNBTv1_8_R1 extends SimpleExpression<NBTTagCompound> {
|
||||
private Expression<?> target;
|
||||
private NBTTagCompound[] returned;
|
||||
|
||||
@Override
|
||||
public Class<? extends NBTTagCompound> getReturnType() {
|
||||
return NBTTagCompound.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSingle() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean init(Expression<?>[] expr, int matchedPattern, Kleenean arg2, ParseResult arg3) {
|
||||
target = expr[0];
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString(@Nullable Event e, boolean arg1) {
|
||||
return "the NBT of " + target.toString(e, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public NBTTagCompound[] get(Event e) {
|
||||
Object tar = target.getSingle(e);
|
||||
if (tar instanceof Entity) {
|
||||
CraftEntity ent = (CraftEntity) tar;
|
||||
NBTTagCompound NBT = new NBTTagCompound();
|
||||
ent.getHandle().e(NBT);
|
||||
returned = new NBTTagCompound[] { NBT };
|
||||
|
||||
} else if (tar instanceof Block) {
|
||||
Block block = (Block) tar;
|
||||
NBTTagCompound NBT = new NBTTagCompound();
|
||||
TileEntity tileEntity = ((CraftWorld) block.getWorld()).getHandle()
|
||||
.getTileEntity(new BlockPosition(block.getX(), block.getY(), block.getZ()));
|
||||
if (tileEntity == null) {
|
||||
return null;
|
||||
}
|
||||
tileEntity.b(NBT);
|
||||
returned = new NBTTagCompound[] { NBT };
|
||||
|
||||
} else if (tar instanceof ItemStack) {
|
||||
ItemStack item = (ItemStack) tar;
|
||||
if (item.getType() == Material.AIR) {
|
||||
return null;
|
||||
}
|
||||
NBTTagCompound NBT = CraftItemStack.asNMSCopy(item).getTag();
|
||||
if (NBT == null || NBT.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
returned = new NBTTagCompound[] { NBT };
|
||||
}
|
||||
return returned;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void change(Event e, Object[] delta, ChangeMode mode) {
|
||||
Object tar = target.getSingle(e);
|
||||
if (tar instanceof Entity) {
|
||||
CraftEntity ent = (CraftEntity) tar;
|
||||
NBTTagCompound NBT = new NBTTagCompound();
|
||||
ent.getHandle().e(NBT);
|
||||
if (mode == ChangeMode.ADD) {
|
||||
String newTags = (String) (delta[0]);
|
||||
NBTTagCompound NBT1 = MojangsonParser.parse(newTags);
|
||||
NBT1.remove("UUIDMost");
|
||||
NBT1.remove("UUIDLeast");
|
||||
NBT1.remove("WorldUUIDLeast");
|
||||
NBT1.remove("WorldUUIDMost");
|
||||
NBT1.remove("Bukkit.updateLevel");
|
||||
NBT.a(NBT1);
|
||||
ent.getHandle().f(NBT);
|
||||
} else if (mode == ChangeMode.REMOVE) {
|
||||
ent.getHandle().e(NBT);
|
||||
for (Object s : delta) {
|
||||
if (s != "UUIDMost" || s != "UUIDLeast" || s != "WorldUUIDMost" || s != "WorldUUIDLeast"
|
||||
|| s != "Bukkit.updateLevel") {
|
||||
NBT.remove((String) s);
|
||||
ent.getHandle().f(NBT);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if (tar instanceof Block) {
|
||||
Block block = (Block) tar;
|
||||
NBTTagCompound NBT = new NBTTagCompound();
|
||||
TileEntity tileEntity = ((CraftWorld) block.getWorld()).getHandle()
|
||||
.getTileEntity(new BlockPosition(block.getX(), block.getY(), block.getZ()));
|
||||
if (tileEntity == null) {
|
||||
return;
|
||||
}
|
||||
if (mode == ChangeMode.ADD) {
|
||||
String newTags = (String) (delta[0]);
|
||||
tileEntity.b(NBT);
|
||||
NBTTagCompound NBT1 = MojangsonParser.parse(newTags);
|
||||
NBT.a(NBT1);
|
||||
NBT1.setInt("x", block.getX());
|
||||
NBT1.setInt("y", block.getY());
|
||||
NBT1.setInt("z", block.getZ());
|
||||
tileEntity.a(NBT);
|
||||
tileEntity.update();
|
||||
((CraftWorld) block.getWorld()).getHandle().notify(tileEntity.getPosition());
|
||||
} else if (mode == ChangeMode.REMOVE) {
|
||||
tileEntity.b(NBT);
|
||||
for (Object s : delta) {
|
||||
if (s != "x" || s != "y" || s != "z" || s != "id") {
|
||||
NBT.remove((String) s);
|
||||
tileEntity.a(NBT);
|
||||
tileEntity.update();
|
||||
((CraftWorld) block.getWorld()).getHandle().notify(tileEntity.getPosition());
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if (tar instanceof ItemStack) {
|
||||
ItemStack item = (ItemStack) tar;
|
||||
if (item.getType() == Material.AIR) {
|
||||
return;
|
||||
}
|
||||
net.minecraft.server.v1_8_R1.ItemStack nmsItem = CraftItemStack.asNMSCopy(item);
|
||||
NBTTagCompound NBT = nmsItem.getTag();
|
||||
if (NBT == null) {
|
||||
NBT = new NBTTagCompound();
|
||||
}
|
||||
if (mode == ChangeMode.ADD) {
|
||||
String newTags = (String) (delta[0]);
|
||||
NBTTagCompound NBT1 = MojangsonParser.parse(newTags);
|
||||
NBT.a(NBT1);
|
||||
nmsItem.setTag(NBT);
|
||||
ItemStack newItem = CraftItemStack.asCraftMirror(nmsItem);
|
||||
Object[] slot = target.getSource().getAll(e);
|
||||
if (!(slot[0] instanceof Slot)) {
|
||||
return;
|
||||
}
|
||||
((Slot) slot[0]).setItem(newItem);
|
||||
} else if (mode == ChangeMode.REMOVE) {
|
||||
NBT = nmsItem.getTag();
|
||||
if (NBT == null || NBT.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
for (Object s : delta) {
|
||||
NBT.remove((String) s);
|
||||
}
|
||||
nmsItem.setTag(NBT);
|
||||
ItemStack newItem = CraftItemStack.asCraftMirror(nmsItem);
|
||||
Object[] slot = target.getSource().getAll(e);
|
||||
((Slot) slot[0]).setItem(newItem);
|
||||
} else if (mode == ChangeMode.DELETE || mode == ChangeMode.RESET) {
|
||||
nmsItem.setTag(new NBTTagCompound());
|
||||
ItemStack newItem = CraftItemStack.asCraftMirror(nmsItem);
|
||||
Object[] slot = target.getSource().getAll(e);
|
||||
if (!(slot[0] instanceof Slot)) {
|
||||
return;
|
||||
}
|
||||
((Slot) slot[0]).setItem(newItem);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public Class<?>[] acceptChange(final ChangeMode mode) {
|
||||
if (mode == ChangeMode.ADD || mode == ChangeMode.REMOVE || mode == ChangeMode.DELETE
|
||||
|| mode == ChangeMode.RESET) {
|
||||
return CollectionUtils.array(String.class);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
211
src/me/TheBukor/expressions/ExprNBTv1_8_R2.java
Normal file
211
src/me/TheBukor/expressions/ExprNBTv1_8_R2.java
Normal file
@ -0,0 +1,211 @@
|
||||
package me.TheBukor.expressions;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.craftbukkit.v1_8_R2.CraftWorld;
|
||||
import org.bukkit.craftbukkit.v1_8_R2.entity.CraftEntity;
|
||||
import org.bukkit.craftbukkit.v1_8_R2.inventory.CraftItemStack;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import ch.njol.skript.Skript;
|
||||
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.skript.util.Slot;
|
||||
import ch.njol.util.Kleenean;
|
||||
import ch.njol.util.coll.CollectionUtils;
|
||||
import net.minecraft.server.v1_8_R2.BlockPosition;
|
||||
import net.minecraft.server.v1_8_R2.MojangsonParseException;
|
||||
import net.minecraft.server.v1_8_R2.MojangsonParser;
|
||||
import net.minecraft.server.v1_8_R2.NBTTagCompound;
|
||||
import net.minecraft.server.v1_8_R2.TileEntity;
|
||||
|
||||
public class ExprNBTv1_8_R2 extends SimpleExpression<NBTTagCompound> {
|
||||
private Expression<?> target;
|
||||
private NBTTagCompound[] returned;
|
||||
|
||||
@Override
|
||||
public Class<? extends NBTTagCompound> getReturnType() {
|
||||
return NBTTagCompound.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSingle() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean init(Expression<?>[] expr, int matchedPattern, Kleenean arg2, ParseResult arg3) {
|
||||
target = expr[0];
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString(@Nullable Event e, boolean arg1) {
|
||||
return "the NBT of " + target.toString(e, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public NBTTagCompound[] get(Event e) {
|
||||
Object tar = target.getSingle(e);
|
||||
if (tar instanceof Entity) {
|
||||
CraftEntity ent = (CraftEntity) tar;
|
||||
NBTTagCompound NBT = new NBTTagCompound();
|
||||
ent.getHandle().e(NBT);
|
||||
returned = new NBTTagCompound[] { NBT };
|
||||
|
||||
} else if (tar instanceof Block) {
|
||||
Block block = (Block) tar;
|
||||
NBTTagCompound NBT = new NBTTagCompound();
|
||||
TileEntity tileEntity = ((CraftWorld) block.getWorld()).getHandle()
|
||||
.getTileEntity(new BlockPosition(block.getX(), block.getY(), block.getZ()));
|
||||
if (tileEntity == null) {
|
||||
return null;
|
||||
}
|
||||
tileEntity.b(NBT);
|
||||
returned = new NBTTagCompound[] { NBT };
|
||||
|
||||
} else if (tar instanceof ItemStack) {
|
||||
ItemStack item = (ItemStack) tar;
|
||||
if (item.getType() == Material.AIR) {
|
||||
return null;
|
||||
}
|
||||
NBTTagCompound NBT = CraftItemStack.asNMSCopy(item).getTag();
|
||||
if (NBT == null || NBT.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
returned = new NBTTagCompound[] { NBT };
|
||||
}
|
||||
return returned;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void change(Event e, Object[] delta, ChangeMode mode) {
|
||||
Object tar = target.getSingle(e);
|
||||
if (tar instanceof Entity) {
|
||||
CraftEntity ent = (CraftEntity) tar;
|
||||
NBTTagCompound NBT = new NBTTagCompound();
|
||||
ent.getHandle().e(NBT);
|
||||
if (mode == ChangeMode.ADD) {
|
||||
String newTags = (String) (delta[0]);
|
||||
try {
|
||||
NBTTagCompound NBT1 = MojangsonParser.parse(newTags);
|
||||
NBT1.remove("UUIDMost");
|
||||
NBT1.remove("UUIDLeast");
|
||||
NBT1.remove("WorldUUIDLeast");
|
||||
NBT1.remove("WorldUUIDMost");
|
||||
NBT1.remove("Bukkit.updateLevel");
|
||||
NBT.a(NBT1);
|
||||
ent.getHandle().f(NBT);
|
||||
} catch (MojangsonParseException ex) {
|
||||
Skript.warning("Error when parsing NBT - " + ex.getMessage());
|
||||
}
|
||||
} else if (mode == ChangeMode.REMOVE) {
|
||||
ent.getHandle().e(NBT);
|
||||
for (Object s : delta) {
|
||||
if (s != "UUIDMost" || s != "UUIDLeast" || s != "WorldUUIDMost" || s != "WorldUUIDLeast"
|
||||
|| s != "Bukkit.updateLevel") {
|
||||
NBT.remove((String) s);
|
||||
ent.getHandle().f(NBT);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if (tar instanceof Block) {
|
||||
Block block = (Block) tar;
|
||||
NBTTagCompound NBT = new NBTTagCompound();
|
||||
TileEntity tileEntity = ((CraftWorld) block.getWorld()).getHandle()
|
||||
.getTileEntity(new BlockPosition(block.getX(), block.getY(), block.getZ()));
|
||||
if (tileEntity == null) {
|
||||
return;
|
||||
}
|
||||
if (mode == ChangeMode.ADD) {
|
||||
String newTags = (String) (delta[0]);
|
||||
tileEntity.b(NBT);
|
||||
try {
|
||||
NBTTagCompound NBT1 = MojangsonParser.parse(newTags);
|
||||
NBT.a(NBT1);
|
||||
NBT1.setInt("x", block.getX());
|
||||
NBT1.setInt("y", block.getY());
|
||||
NBT1.setInt("z", block.getZ());
|
||||
tileEntity.a(NBT);
|
||||
tileEntity.update();
|
||||
((CraftWorld) block.getWorld()).getHandle().notify(tileEntity.getPosition());
|
||||
} catch (MojangsonParseException ex) {
|
||||
Skript.warning("Error when parsing NBT - " + ex.getMessage());
|
||||
}
|
||||
} else if (mode == ChangeMode.REMOVE) {
|
||||
tileEntity.b(NBT);
|
||||
for (Object s : delta) {
|
||||
if (s != "x" || s != "y" || s != "z" || s != "id") {
|
||||
NBT.remove((String) s);
|
||||
tileEntity.a(NBT);
|
||||
tileEntity.update();
|
||||
((CraftWorld) block.getWorld()).getHandle().notify(tileEntity.getPosition());
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if (tar instanceof ItemStack) {
|
||||
ItemStack item = (ItemStack) tar;
|
||||
if (item.getType() == Material.AIR) {
|
||||
return;
|
||||
}
|
||||
net.minecraft.server.v1_8_R2.ItemStack nmsItem = CraftItemStack.asNMSCopy(item);
|
||||
NBTTagCompound NBT = nmsItem.getTag();
|
||||
if (NBT == null) {
|
||||
NBT = new NBTTagCompound();
|
||||
}
|
||||
if (mode == ChangeMode.ADD) {
|
||||
String newTags = (String) (delta[0]);
|
||||
try {
|
||||
NBTTagCompound NBT1 = MojangsonParser.parse(newTags);
|
||||
NBT.a(NBT1);
|
||||
nmsItem.setTag(NBT);
|
||||
ItemStack newItem = CraftItemStack.asCraftMirror(nmsItem);
|
||||
Object[] slot = target.getSource().getAll(e);
|
||||
if (!(slot[0] instanceof Slot)) {
|
||||
return;
|
||||
}
|
||||
((Slot) slot[0]).setItem(newItem);
|
||||
} catch (MojangsonParseException ex) {
|
||||
Skript.warning("Error when parsing NBT - " + ex.getMessage());
|
||||
}
|
||||
} else if (mode == ChangeMode.REMOVE) {
|
||||
NBT = nmsItem.getTag();
|
||||
if (NBT == null || NBT.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
for (Object s : delta) {
|
||||
NBT.remove((String) s);
|
||||
}
|
||||
nmsItem.setTag(NBT);
|
||||
ItemStack newItem = CraftItemStack.asCraftMirror(nmsItem);
|
||||
Object[] slot = target.getSource().getAll(e);
|
||||
((Slot) slot[0]).setItem(newItem);
|
||||
} else if (mode == ChangeMode.DELETE || mode == ChangeMode.RESET) {
|
||||
nmsItem.setTag(new NBTTagCompound());
|
||||
ItemStack newItem = CraftItemStack.asCraftMirror(nmsItem);
|
||||
Object[] slot = target.getSource().getAll(e);
|
||||
if (!(slot[0] instanceof Slot)) {
|
||||
return;
|
||||
}
|
||||
((Slot) slot[0]).setItem(newItem);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public Class<?>[] acceptChange(final ChangeMode mode) {
|
||||
if (mode == ChangeMode.ADD || mode == ChangeMode.REMOVE || mode == ChangeMode.DELETE
|
||||
|| mode == ChangeMode.RESET) {
|
||||
return CollectionUtils.array(String.class);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
211
src/me/TheBukor/expressions/ExprNBTv1_8_R3.java
Normal file
211
src/me/TheBukor/expressions/ExprNBTv1_8_R3.java
Normal file
@ -0,0 +1,211 @@
|
||||
package me.TheBukor.expressions;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.craftbukkit.v1_8_R3.CraftWorld;
|
||||
import org.bukkit.craftbukkit.v1_8_R3.entity.CraftEntity;
|
||||
import org.bukkit.craftbukkit.v1_8_R3.inventory.CraftItemStack;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import ch.njol.skript.Skript;
|
||||
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.skript.util.Slot;
|
||||
import ch.njol.util.Kleenean;
|
||||
import ch.njol.util.coll.CollectionUtils;
|
||||
import net.minecraft.server.v1_8_R3.BlockPosition;
|
||||
import net.minecraft.server.v1_8_R3.MojangsonParseException;
|
||||
import net.minecraft.server.v1_8_R3.MojangsonParser;
|
||||
import net.minecraft.server.v1_8_R3.NBTTagCompound;
|
||||
import net.minecraft.server.v1_8_R3.TileEntity;
|
||||
|
||||
public class ExprNBTv1_8_R3 extends SimpleExpression<NBTTagCompound> {
|
||||
private Expression<?> target;
|
||||
private NBTTagCompound[] returned;
|
||||
|
||||
@Override
|
||||
public Class<? extends NBTTagCompound> getReturnType() {
|
||||
return NBTTagCompound.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSingle() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean init(Expression<?>[] expr, int matchedPattern, Kleenean arg2, ParseResult arg3) {
|
||||
target = expr[0];
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString(@Nullable Event e, boolean arg1) {
|
||||
return "the NBT of " + target.toString(e, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public NBTTagCompound[] get(Event e) {
|
||||
Object tar = target.getSingle(e);
|
||||
if (tar instanceof Entity) {
|
||||
CraftEntity ent = (CraftEntity) tar;
|
||||
NBTTagCompound NBT = new NBTTagCompound();
|
||||
ent.getHandle().e(NBT);
|
||||
returned = new NBTTagCompound[] { NBT };
|
||||
|
||||
} else if (tar instanceof Block) {
|
||||
Block block = (Block) tar;
|
||||
NBTTagCompound NBT = new NBTTagCompound();
|
||||
TileEntity tileEntity = ((CraftWorld) block.getWorld()).getHandle()
|
||||
.getTileEntity(new BlockPosition(block.getX(), block.getY(), block.getZ()));
|
||||
if (tileEntity == null) {
|
||||
return null;
|
||||
}
|
||||
tileEntity.b(NBT);
|
||||
returned = new NBTTagCompound[] { NBT };
|
||||
|
||||
} else if (tar instanceof ItemStack) {
|
||||
ItemStack item = (ItemStack) tar;
|
||||
if (item.getType() == Material.AIR) {
|
||||
return null;
|
||||
}
|
||||
NBTTagCompound NBT = CraftItemStack.asNMSCopy(item).getTag();
|
||||
if (NBT == null || NBT.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
returned = new NBTTagCompound[] { NBT };
|
||||
}
|
||||
return returned;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void change(Event e, Object[] delta, ChangeMode mode) {
|
||||
Object tar = target.getSingle(e);
|
||||
if (tar instanceof Entity) {
|
||||
CraftEntity ent = (CraftEntity) tar;
|
||||
NBTTagCompound NBT = new NBTTagCompound();
|
||||
ent.getHandle().e(NBT);
|
||||
if (mode == ChangeMode.ADD) {
|
||||
String newTags = (String) (delta[0]);
|
||||
try {
|
||||
NBTTagCompound NBT1 = MojangsonParser.parse(newTags);
|
||||
NBT1.remove("UUIDMost");
|
||||
NBT1.remove("UUIDLeast");
|
||||
NBT1.remove("WorldUUIDLeast");
|
||||
NBT1.remove("WorldUUIDMost");
|
||||
NBT1.remove("Bukkit.updateLevel");
|
||||
NBT.a(NBT1);
|
||||
ent.getHandle().f(NBT);
|
||||
} catch (MojangsonParseException ex) {
|
||||
Skript.warning("Error when parsing NBT - " + ex.getMessage());
|
||||
}
|
||||
} else if (mode == ChangeMode.REMOVE) {
|
||||
ent.getHandle().e(NBT);
|
||||
for (Object s : delta) {
|
||||
if (s != "UUIDMost" || s != "UUIDLeast" || s != "WorldUUIDMost" || s != "WorldUUIDLeast"
|
||||
|| s != "Bukkit.updateLevel") {
|
||||
NBT.remove((String) s);
|
||||
ent.getHandle().f(NBT);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if (tar instanceof Block) {
|
||||
Block block = (Block) tar;
|
||||
NBTTagCompound NBT = new NBTTagCompound();
|
||||
TileEntity tileEntity = ((CraftWorld) block.getWorld()).getHandle()
|
||||
.getTileEntity(new BlockPosition(block.getX(), block.getY(), block.getZ()));
|
||||
if (tileEntity == null) {
|
||||
return;
|
||||
}
|
||||
if (mode == ChangeMode.ADD) {
|
||||
String newTags = (String) (delta[0]);
|
||||
tileEntity.b(NBT);
|
||||
try {
|
||||
NBTTagCompound NBT1 = MojangsonParser.parse(newTags);
|
||||
NBT.a(NBT1);
|
||||
NBT1.setInt("x", block.getX());
|
||||
NBT1.setInt("y", block.getY());
|
||||
NBT1.setInt("z", block.getZ());
|
||||
tileEntity.a(NBT);
|
||||
tileEntity.update();
|
||||
((CraftWorld) block.getWorld()).getHandle().notify(tileEntity.getPosition());
|
||||
} catch (MojangsonParseException ex) {
|
||||
Skript.warning("Error when parsing NBT - " + ex.getMessage());
|
||||
}
|
||||
} else if (mode == ChangeMode.REMOVE) {
|
||||
tileEntity.b(NBT);
|
||||
for (Object s : delta) {
|
||||
if (s != "x" || s != "y" || s != "z" || s != "id") {
|
||||
NBT.remove((String) s);
|
||||
tileEntity.a(NBT);
|
||||
tileEntity.update();
|
||||
((CraftWorld) block.getWorld()).getHandle().notify(tileEntity.getPosition());
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if (tar instanceof ItemStack) {
|
||||
ItemStack item = (ItemStack) tar;
|
||||
if (item.getType() == Material.AIR) {
|
||||
return;
|
||||
}
|
||||
net.minecraft.server.v1_8_R3.ItemStack nmsItem = CraftItemStack.asNMSCopy(item);
|
||||
NBTTagCompound NBT = nmsItem.getTag();
|
||||
if (NBT == null) {
|
||||
NBT = new NBTTagCompound();
|
||||
}
|
||||
if (mode == ChangeMode.ADD) {
|
||||
String newTags = (String) (delta[0]);
|
||||
try {
|
||||
NBTTagCompound NBT1 = MojangsonParser.parse(newTags);
|
||||
NBT.a(NBT1);
|
||||
nmsItem.setTag(NBT);
|
||||
ItemStack newItem = CraftItemStack.asCraftMirror(nmsItem);
|
||||
Object[] slot = target.getSource().getAll(e);
|
||||
if (!(slot[0] instanceof Slot)) {
|
||||
return;
|
||||
}
|
||||
((Slot) slot[0]).setItem(newItem);
|
||||
} catch (MojangsonParseException ex) {
|
||||
Skript.warning("Error when parsing NBT - " + ex.getMessage());
|
||||
}
|
||||
} else if (mode == ChangeMode.REMOVE) {
|
||||
NBT = nmsItem.getTag();
|
||||
if (NBT == null || NBT.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
for (Object s : delta) {
|
||||
NBT.remove((String) s);
|
||||
}
|
||||
nmsItem.setTag(NBT);
|
||||
ItemStack newItem = CraftItemStack.asCraftMirror(nmsItem);
|
||||
Object[] slot = target.getSource().getAll(e);
|
||||
((Slot) slot[0]).setItem(newItem);
|
||||
} else if (mode == ChangeMode.DELETE || mode == ChangeMode.RESET) {
|
||||
nmsItem.setTag(new NBTTagCompound());
|
||||
ItemStack newItem = CraftItemStack.asCraftMirror(nmsItem);
|
||||
Object[] slot = target.getSource().getAll(e);
|
||||
if (!(slot[0] instanceof Slot)) {
|
||||
return;
|
||||
}
|
||||
((Slot) slot[0]).setItem(newItem);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public Class<?>[] acceptChange(final ChangeMode mode) {
|
||||
if (mode == ChangeMode.ADD || mode == ChangeMode.REMOVE || mode == ChangeMode.DELETE
|
||||
|| mode == ChangeMode.RESET) {
|
||||
return CollectionUtils.array(String.class);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
96
src/me/TheBukor/expressions/ExprSelectionOfPlayer.java
Normal file
96
src/me/TheBukor/expressions/ExprSelectionOfPlayer.java
Normal file
@ -0,0 +1,96 @@
|
||||
package me.TheBukor.expressions;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.Event;
|
||||
|
||||
import com.sk89q.worldedit.IncompleteRegionException;
|
||||
import com.sk89q.worldedit.Vector;
|
||||
import com.sk89q.worldedit.bukkit.WorldEditPlugin;
|
||||
import com.sk89q.worldedit.regions.CuboidRegion;
|
||||
import com.sk89q.worldedit.regions.Region;
|
||||
|
||||
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;
|
||||
|
||||
public class ExprSelectionOfPlayer extends SimpleExpression<Location> {
|
||||
private Expression<Player> player;
|
||||
private WorldEditPlugin we = (WorldEditPlugin) Bukkit.getServer().getPluginManager().getPlugin("WorldEdit");;
|
||||
|
||||
@Override
|
||||
public Class<? extends Location> getReturnType() {
|
||||
return Location.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSingle() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public boolean init(Expression<?>[] expr, int matchedPattern, Kleenean arg2, ParseResult arg3) {
|
||||
player = (Expression<Player>) expr[0];
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString(@Nullable Event e, boolean arg1) {
|
||||
return "the WorldEdit selection of " + player.toString(e, false);
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@Override
|
||||
@Nullable
|
||||
protected Location[] get(Event e) {
|
||||
Player p = player.getSingle(e);
|
||||
Region region = null;
|
||||
try {
|
||||
region = we.getSession(p).getRegion();
|
||||
} catch (IncompleteRegionException ex) {
|
||||
return null;
|
||||
}
|
||||
if (!(region instanceof CuboidRegion)) {
|
||||
return null;
|
||||
}
|
||||
CuboidRegion cuboid = (CuboidRegion) region;
|
||||
Vector pos1Vec = cuboid.getPos1();
|
||||
Vector pos2Vec = cuboid.getPos2();
|
||||
Location pos1 = new Location(we.getSelection(p).getWorld(), pos1Vec.getX(), pos1Vec.getY(), pos1Vec.getZ());
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
@Nullable
|
||||
public Class<?>[] acceptChange(ChangeMode mode) {
|
||||
if (mode == ChangeMode.SET || mode == ChangeMode.DELETE || mode == ChangeMode.RESET) {
|
||||
return CollectionUtils.array(Location.class);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
*/
|
||||
}
|
65
src/me/TheBukor/expressions/ExprSelectionPos1.java
Normal file
65
src/me/TheBukor/expressions/ExprSelectionPos1.java
Normal file
@ -0,0 +1,65 @@
|
||||
package me.TheBukor.expressions;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.Event;
|
||||
|
||||
import com.sk89q.worldedit.IncompleteRegionException;
|
||||
import com.sk89q.worldedit.Vector;
|
||||
import com.sk89q.worldedit.bukkit.WorldEditPlugin;
|
||||
import com.sk89q.worldedit.regions.CuboidRegion;
|
||||
import com.sk89q.worldedit.regions.Region;
|
||||
|
||||
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;
|
||||
|
||||
public class ExprSelectionPos1 extends SimpleExpression<Location> {
|
||||
private Expression<Player> player;
|
||||
private WorldEditPlugin we = (WorldEditPlugin) Bukkit.getServer().getPluginManager().getPlugin("WorldEdit");
|
||||
|
||||
@Override
|
||||
public Class<? extends Location> getReturnType() {
|
||||
return Location.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSingle() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public boolean init(Expression<?>[] expr, int matchedPattern, Kleenean arg2, ParseResult arg3) {
|
||||
player = (Expression<Player>) expr[0];
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString(@Nullable Event e, boolean arg1) {
|
||||
return "the WorldEdit point 1 selection of " + player.toString(e, false);
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@Override
|
||||
@Nullable
|
||||
protected Location[] get(Event e) {
|
||||
Player p = player.getSingle(e);
|
||||
Region region = null;
|
||||
try {
|
||||
region = we.getSession(p).getRegion();
|
||||
} catch (IncompleteRegionException ex) {
|
||||
return null;
|
||||
}
|
||||
if (!(region instanceof CuboidRegion)) {
|
||||
return null;
|
||||
}
|
||||
CuboidRegion cuboid = (CuboidRegion) region;
|
||||
Vector pos = cuboid.getPos1();
|
||||
return new Location[] { new Location(we.getSelection(p).getWorld(), pos.getX(), pos.getY(), pos.getZ()) };
|
||||
}
|
||||
}
|
65
src/me/TheBukor/expressions/ExprSelectionPos2.java
Normal file
65
src/me/TheBukor/expressions/ExprSelectionPos2.java
Normal file
@ -0,0 +1,65 @@
|
||||
package me.TheBukor.expressions;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.Event;
|
||||
|
||||
import com.sk89q.worldedit.IncompleteRegionException;
|
||||
import com.sk89q.worldedit.Vector;
|
||||
import com.sk89q.worldedit.bukkit.WorldEditPlugin;
|
||||
import com.sk89q.worldedit.regions.CuboidRegion;
|
||||
import com.sk89q.worldedit.regions.Region;
|
||||
|
||||
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;
|
||||
|
||||
public class ExprSelectionPos2 extends SimpleExpression<Location> {
|
||||
private Expression<Player> player;
|
||||
private WorldEditPlugin we = (WorldEditPlugin) Bukkit.getServer().getPluginManager().getPlugin("WorldEdit");
|
||||
|
||||
@Override
|
||||
public Class<? extends Location> getReturnType() {
|
||||
return Location.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSingle() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public boolean init(Expression<?>[] expr, int matchedPattern, Kleenean arg2, ParseResult arg3) {
|
||||
player = (Expression<Player>) expr[0];
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString(@Nullable Event e, boolean arg1) {
|
||||
return "the WorldEdit point 2 selection of " + player.toString(e, false);
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@Override
|
||||
@Nullable
|
||||
protected Location[] get(Event e) {
|
||||
Player p = player.getSingle(e);
|
||||
Region region = null;
|
||||
try {
|
||||
region = we.getSession(p).getRegion();
|
||||
} catch (IncompleteRegionException ex) {
|
||||
return null;
|
||||
}
|
||||
if (!(region instanceof CuboidRegion)) {
|
||||
return null;
|
||||
}
|
||||
CuboidRegion cuboid = (CuboidRegion) region;
|
||||
Vector pos = cuboid.getPos2();
|
||||
return new Location[] { new Location(we.getSelection(p).getWorld(), pos.getX(), pos.getY(), pos.getZ()) };
|
||||
}
|
||||
}
|
82
src/me/TheBukor/expressions/ExprTagOfv1_8_R1.java
Normal file
82
src/me/TheBukor/expressions/ExprTagOfv1_8_R1.java
Normal file
@ -0,0 +1,82 @@
|
||||
package me.TheBukor.expressions;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import org.bukkit.event.Event;
|
||||
|
||||
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 net.minecraft.server.v1_8_R1.NBTTagCompound;
|
||||
|
||||
public class ExprTagOfv1_8_R1 extends SimpleExpression<Object> {
|
||||
private Expression<String> string;
|
||||
private Expression<NBTTagCompound> compound;
|
||||
private Object[] returned;
|
||||
@Override
|
||||
public Class<? extends Object> getReturnType() {
|
||||
return Object.class;
|
||||
}
|
||||
@Override
|
||||
public boolean isSingle() {
|
||||
return true;
|
||||
}
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public boolean init(Expression<?>[] expr, int arg1, Kleenean arg2, ParseResult arg3) {
|
||||
string = (Expression<String>) expr[0];
|
||||
compound = (Expression<NBTTagCompound>) expr[1];
|
||||
return true;
|
||||
}
|
||||
@Override
|
||||
public String toString(@Nullable Event e, boolean arg1) {
|
||||
return "the tag " + string.toString(e, false) + " of compound";
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
protected Object[] get(Event e) {
|
||||
NBTTagCompound NBT = compound.getSingle(e);
|
||||
String tag = string.getSingle(e);
|
||||
if (NBT.get(tag) == null) {
|
||||
return null;
|
||||
}
|
||||
Byte id = NBT.get(tag).getTypeId();
|
||||
switch (id) {
|
||||
case 1:
|
||||
returned = new Object[] { NBT.getByte(tag) };
|
||||
break;
|
||||
case 2:
|
||||
returned = new Object[] { NBT.getShort(tag) };
|
||||
break;
|
||||
case 3:
|
||||
returned = new Object[] { NBT.getInt(tag) };
|
||||
break;
|
||||
case 4:
|
||||
returned = new Object[] { NBT.getLong(tag) };
|
||||
break;
|
||||
case 5:
|
||||
returned = new Object[] { NBT.getFloat(tag) };
|
||||
break;
|
||||
case 6:
|
||||
returned = new Object[] { NBT.getDouble(tag) };
|
||||
break;
|
||||
case 8:
|
||||
returned = new Object[] { NBT.getString(tag) };
|
||||
break;
|
||||
case 9:
|
||||
returned = null;
|
||||
break;
|
||||
case 10:
|
||||
returned = new Object[] { NBT.getCompound(tag) };
|
||||
break;
|
||||
case 11:
|
||||
returned = null;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return returned;
|
||||
}
|
||||
}
|
82
src/me/TheBukor/expressions/ExprTagOfv1_8_R2.java
Normal file
82
src/me/TheBukor/expressions/ExprTagOfv1_8_R2.java
Normal file
@ -0,0 +1,82 @@
|
||||
package me.TheBukor.expressions;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import org.bukkit.event.Event;
|
||||
|
||||
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 net.minecraft.server.v1_8_R2.NBTTagCompound;
|
||||
|
||||
public class ExprTagOfv1_8_R2 extends SimpleExpression<Object> {
|
||||
private Expression<String> string;
|
||||
private Expression<NBTTagCompound> compound;
|
||||
private Object[] returned;
|
||||
@Override
|
||||
public Class<? extends Object> getReturnType() {
|
||||
return Object.class;
|
||||
}
|
||||
@Override
|
||||
public boolean isSingle() {
|
||||
return true;
|
||||
}
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public boolean init(Expression<?>[] expr, int arg1, Kleenean arg2, ParseResult arg3) {
|
||||
string = (Expression<String>) expr[0];
|
||||
compound = (Expression<NBTTagCompound>) expr[1];
|
||||
return true;
|
||||
}
|
||||
@Override
|
||||
public String toString(@Nullable Event e, boolean arg1) {
|
||||
return "the tag " + string.toString(e, false) + " of compound";
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
protected Object[] get(Event e) {
|
||||
NBTTagCompound NBT = compound.getSingle(e);
|
||||
String tag = string.getSingle(e);
|
||||
if (NBT.get(tag) == null) {
|
||||
return null;
|
||||
}
|
||||
Byte id = NBT.get(tag).getTypeId();
|
||||
switch (id) {
|
||||
case 1:
|
||||
returned = new Object[] { NBT.getByte(tag) };
|
||||
break;
|
||||
case 2:
|
||||
returned = new Object[] { NBT.getShort(tag) };
|
||||
break;
|
||||
case 3:
|
||||
returned = new Object[] { NBT.getInt(tag) };
|
||||
break;
|
||||
case 4:
|
||||
returned = new Object[] { NBT.getLong(tag) };
|
||||
break;
|
||||
case 5:
|
||||
returned = new Object[] { NBT.getFloat(tag) };
|
||||
break;
|
||||
case 6:
|
||||
returned = new Object[] { NBT.getDouble(tag) };
|
||||
break;
|
||||
case 8:
|
||||
returned = new Object[] { NBT.getString(tag) };
|
||||
break;
|
||||
case 9:
|
||||
returned = null;
|
||||
break;
|
||||
case 10:
|
||||
returned = new Object[] { NBT.getCompound(tag) };
|
||||
break;
|
||||
case 11:
|
||||
returned = null;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return returned;
|
||||
}
|
||||
}
|
82
src/me/TheBukor/expressions/ExprTagOfv1_8_R3.java
Normal file
82
src/me/TheBukor/expressions/ExprTagOfv1_8_R3.java
Normal file
@ -0,0 +1,82 @@
|
||||
package me.TheBukor.expressions;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import org.bukkit.event.Event;
|
||||
|
||||
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 net.minecraft.server.v1_8_R3.NBTTagCompound;
|
||||
|
||||
public class ExprTagOfv1_8_R3 extends SimpleExpression<Object> {
|
||||
private Expression<String> string;
|
||||
private Expression<NBTTagCompound> compound;
|
||||
private Object[] returned;
|
||||
@Override
|
||||
public Class<? extends Object> getReturnType() {
|
||||
return Object.class;
|
||||
}
|
||||
@Override
|
||||
public boolean isSingle() {
|
||||
return true;
|
||||
}
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public boolean init(Expression<?>[] expr, int arg1, Kleenean arg2, ParseResult arg3) {
|
||||
string = (Expression<String>) expr[0];
|
||||
compound = (Expression<NBTTagCompound>) expr[1];
|
||||
return true;
|
||||
}
|
||||
@Override
|
||||
public String toString(@Nullable Event e, boolean arg1) {
|
||||
return "the tag " + string.toString(e, false) + " of compound";
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
protected Object[] get(Event e) {
|
||||
NBTTagCompound NBT = compound.getSingle(e);
|
||||
String tag = string.getSingle(e);
|
||||
if (NBT.get(tag) == null) {
|
||||
return null;
|
||||
}
|
||||
Byte id = NBT.get(tag).getTypeId();
|
||||
switch (id) {
|
||||
case 1:
|
||||
returned = new Object[] { NBT.getByte(tag) };
|
||||
break;
|
||||
case 2:
|
||||
returned = new Object[] { NBT.getShort(tag) };
|
||||
break;
|
||||
case 3:
|
||||
returned = new Object[] { NBT.getInt(tag) };
|
||||
break;
|
||||
case 4:
|
||||
returned = new Object[] { NBT.getLong(tag) };
|
||||
break;
|
||||
case 5:
|
||||
returned = new Object[] { NBT.getFloat(tag) };
|
||||
break;
|
||||
case 6:
|
||||
returned = new Object[] { NBT.getDouble(tag) };
|
||||
break;
|
||||
case 8:
|
||||
returned = new Object[] { NBT.getString(tag) };
|
||||
break;
|
||||
case 9:
|
||||
returned = null;
|
||||
break;
|
||||
case 10:
|
||||
returned = new Object[] { NBT.getCompound(tag) };
|
||||
break;
|
||||
case 11:
|
||||
returned = null;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return returned;
|
||||
}
|
||||
}
|
76
src/me/TheBukor/expressions/ExprVolumeOfSchematic.java
Normal file
76
src/me/TheBukor/expressions/ExprVolumeOfSchematic.java
Normal file
@ -0,0 +1,76 @@
|
||||
package me.TheBukor.expressions;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.event.Event;
|
||||
|
||||
import com.sk89q.worldedit.bukkit.WorldEditPlugin;
|
||||
import com.sk89q.worldedit.data.DataException;
|
||||
import com.sk89q.worldedit.schematic.MCEditSchematicFormat;
|
||||
|
||||
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;
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public class ExprVolumeOfSchematic extends SimpleExpression<Integer> {
|
||||
private Expression<String> schematic;
|
||||
private Expression<String> folder;
|
||||
@SuppressWarnings("unused")
|
||||
private WorldEditPlugin we = (WorldEditPlugin) Bukkit.getServer().getPluginManager().getPlugin("WorldEdit");
|
||||
|
||||
@Override
|
||||
public Class<? extends Integer> getReturnType() {
|
||||
return Integer.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSingle() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public boolean init(Expression<?>[] expr, int matchedPattern, Kleenean arg2, ParseResult arg3) {
|
||||
schematic = (Expression<String>) expr[0];
|
||||
folder = (Expression<String>) expr[1];
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString(@Nullable Event e, boolean arg1) {
|
||||
return "the volume of the schematic " + schematic.toString(e, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
protected Integer[] get(Event e) {
|
||||
String f = (folder.getSingle(e) != null) ? folder.getSingle(e) : "plugins/WorldEdit/";
|
||||
String schem = schematic.getSingle(e);
|
||||
File schemFile = new File((f.endsWith("/")) ? f : f + "/" + new String(schem.endsWith(".schematic") ? schem : schem + ".schematic"));
|
||||
Integer w = 0;
|
||||
Integer h = 0;
|
||||
Integer l = 0;
|
||||
try {
|
||||
w = MCEditSchematicFormat.getFormat(schemFile).load(schemFile).getWidth();
|
||||
} catch (DataException | IOException e1) {
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
h = MCEditSchematicFormat.getFormat(schemFile).load(schemFile).getHeight();
|
||||
} catch (DataException | IOException e2) {
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
l = MCEditSchematicFormat.getFormat(schemFile).load(schemFile).getLength();
|
||||
} catch (DataException | IOException e1) {
|
||||
return null;
|
||||
}
|
||||
return new Integer[] { w * h * l };
|
||||
}
|
||||
}
|
51
src/me/TheBukor/expressions/ExprVolumeOfSelection.java
Normal file
51
src/me/TheBukor/expressions/ExprVolumeOfSelection.java
Normal file
@ -0,0 +1,51 @@
|
||||
package me.TheBukor.expressions;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.Event;
|
||||
|
||||
import com.sk89q.worldedit.bukkit.WorldEditPlugin;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
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;
|
||||
|
||||
public class ExprVolumeOfSelection extends SimpleExpression<Integer> {
|
||||
private Expression<Player> player;
|
||||
|
||||
@Override
|
||||
public Class<? extends Integer> getReturnType() {
|
||||
return Integer.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSingle() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public boolean init(Expression<?>[] expr, int matchedPattern, Kleenean arg2, ParseResult arg3) {
|
||||
player = (Expression<Player>) expr[0];
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString(@Nullable Event e, boolean arg1) {
|
||||
return "the volume of the WorldEdit selection of " + player.toString(e, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
protected Integer[] get(Event e) {
|
||||
WorldEditPlugin worldEdit = (WorldEditPlugin) Bukkit.getServer().getPluginManager().getPlugin("WorldEdit");
|
||||
if (worldEdit.getSelection(player.getSingle(e)) == null) {
|
||||
return null;
|
||||
}
|
||||
return new Integer[] { worldEdit.getSelection(player.getSingle(e)).getArea() };
|
||||
}
|
||||
|
||||
}
|
64
src/me/TheBukor/expressions/ExprWidthOfSchematic.java
Normal file
64
src/me/TheBukor/expressions/ExprWidthOfSchematic.java
Normal file
@ -0,0 +1,64 @@
|
||||
package me.TheBukor.expressions;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.event.Event;
|
||||
|
||||
import com.sk89q.worldedit.bukkit.WorldEditPlugin;
|
||||
import com.sk89q.worldedit.data.DataException;
|
||||
import com.sk89q.worldedit.schematic.MCEditSchematicFormat;
|
||||
|
||||
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;
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public class ExprWidthOfSchematic extends SimpleExpression<Integer> {
|
||||
private Expression<String> schematic;
|
||||
private Expression<String> folder;
|
||||
@SuppressWarnings("unused")
|
||||
private WorldEditPlugin we = (WorldEditPlugin) Bukkit.getServer().getPluginManager().getPlugin("WorldEdit");
|
||||
|
||||
@Override
|
||||
public Class<? extends Integer> getReturnType() {
|
||||
return Integer.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSingle() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public boolean init(Expression<?>[] expr, int matchedPattern, Kleenean arg2, ParseResult arg3) {
|
||||
schematic = (Expression<String>) expr[0];
|
||||
folder = (Expression<String>) expr[1];
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString(@Nullable Event e, boolean arg1) {
|
||||
return "the width of the schematic " + schematic.toString(e, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
protected Integer[] get(Event e) {
|
||||
String f = (folder.getSingle(e) != null) ? folder.getSingle(e) : "plugins/WorldEdit/";
|
||||
String schem = schematic.getSingle(e);
|
||||
File schemFile = new File((f.endsWith("/")) ? f : f + "/" + new String(schem.endsWith(".schematic") ? schem : schem + ".schematic"));
|
||||
Integer w = null;
|
||||
try {
|
||||
w = MCEditSchematicFormat.getFormat(schemFile).load(schemFile).getWidth();
|
||||
} catch (DataException | IOException e1) {
|
||||
return null;
|
||||
}
|
||||
return new Integer[] { w };
|
||||
}
|
||||
}
|
51
src/me/TheBukor/expressions/ExprWidthOfSelection.java
Normal file
51
src/me/TheBukor/expressions/ExprWidthOfSelection.java
Normal file
@ -0,0 +1,51 @@
|
||||
package me.TheBukor.expressions;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.Event;
|
||||
|
||||
import com.sk89q.worldedit.bukkit.WorldEditPlugin;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
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;
|
||||
|
||||
public class ExprWidthOfSelection extends SimpleExpression<Integer> {
|
||||
private Expression<Player> player;
|
||||
|
||||
@Override
|
||||
public Class<? extends Integer> getReturnType() {
|
||||
return Integer.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSingle() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public boolean init(Expression<?>[] expr, int matchedPattern, Kleenean arg2, ParseResult arg3) {
|
||||
player = (Expression<Player>) expr[0];
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString(@Nullable Event e, boolean arg1) {
|
||||
return "the width of the WorldEdit selection of " + player.toString(e, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
protected Integer[] get(Event e) {
|
||||
WorldEditPlugin worldEdit = (WorldEditPlugin) Bukkit.getServer().getPluginManager().getPlugin("WorldEdit");
|
||||
if (worldEdit.getSelection(player.getSingle(e)) == null) {
|
||||
return null;
|
||||
}
|
||||
return new Integer[] { worldEdit.getSelection(player.getSingle(e)).getWidth() };
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user