VanishNoPacket, manipulate compounds inside variables.

This commit is contained in:
Richard 2016-01-19 20:39:53 -02:00
parent 1bd64b530f
commit e598f81061
5 changed files with 159 additions and 3 deletions

View File

@ -11,5 +11,6 @@
<classpathentry kind="lib" path="C:/Users/Rubi/AppData/Roaming/.minecraft/workspace/Spigot 1.8, 1.8.3/1.7.5.jar"/>
<classpathentry kind="lib" path="C:/Users/Rubi/AppData/Roaming/.minecraft/workspace/Spigot 1.8, 1.8.3/1.7.2.jar"/>
<classpathentry kind="lib" path="C:/Users/Rubi/AppData/Roaming/.minecraft/workspace/Spigot 1.8, 1.8.3/1.8.7.jar"/>
<classpathentry kind="lib" path="C:/Users/Rubi/AppData/Roaming/.minecraft/workspace/Spigot 1.8, 1.8.3/VanishNoPacket.jar"/>
<classpathentry kind="output" path="bin"/>
</classpath>

View File

@ -1,6 +1,6 @@
name: SkStuff
author: TheBukor
description: A Skript addon which adds extra functionalities such as NBT and extended WorldEdit support.
version: 1.4.1
version: 1.4.1.1
main: me.TheBukor.SkStuff.SkStuff
softdepend: [Skript, WorldEdit]

View File

@ -14,6 +14,7 @@ import org.bukkit.plugin.java.JavaPlugin;
import com.sk89q.worldedit.EditSession;
import ch.njol.skript.Skript;
import ch.njol.skript.classes.Changer;
import ch.njol.skript.classes.ClassInfo;
import ch.njol.skript.classes.Parser;
import ch.njol.skript.lang.ExpressionType;
@ -22,6 +23,7 @@ import ch.njol.skript.lang.util.SimpleEvent;
import ch.njol.skript.registrations.Classes;
import ch.njol.skript.registrations.EventValues;
import ch.njol.skript.util.Getter;
import ch.njol.util.coll.CollectionUtils;
import me.TheBukor.SkStuff.conditions.CondSelectionContains;
import me.TheBukor.SkStuff.effects.EffDrainLiquid;
import me.TheBukor.SkStuff.effects.EffDrawLineWE;
@ -34,6 +36,7 @@ import me.TheBukor.SkStuff.effects.EffRememberChanges;
import me.TheBukor.SkStuff.effects.EffReplaceBlocksWE;
import me.TheBukor.SkStuff.effects.EffSetBlocksWE;
import me.TheBukor.SkStuff.effects.EffSimulateSnow;
import me.TheBukor.SkStuff.effects.EffToggleVanish;
import me.TheBukor.SkStuff.effects.EffUndoRedoSession;
import me.TheBukor.SkStuff.events.EvtWorldEditChange;
import me.TheBukor.SkStuff.events.WorldEditChangeHandler;
@ -50,6 +53,7 @@ import me.TheBukor.SkStuff.expressions.ExprSelectionArea;
import me.TheBukor.SkStuff.expressions.ExprSelectionOfPlayer;
import me.TheBukor.SkStuff.expressions.ExprSelectionPos;
import me.TheBukor.SkStuff.expressions.ExprTagOf;
import me.TheBukor.SkStuff.expressions.ExprVanishState;
import me.TheBukor.SkStuff.util.ReflectionUtils;
public class SkStuff extends JavaPlugin {
@ -63,7 +67,7 @@ public class SkStuff extends JavaPlugin {
private Class<?> nbtParserClass = ReflectionUtils.getNMSClass("MojangsonParser");
private Class<?> nbtParseExClass = ReflectionUtils.getNMSClass("MojangsonParseException");
@SuppressWarnings("unchecked")
@SuppressWarnings({ "unchecked" })
public void onEnable() {
if (Bukkit.getPluginManager().getPlugin("Skript") != null && Skript.isAcceptRegistrations()) {
Skript.registerAddon(this);
@ -78,7 +82,56 @@ public class SkStuff extends JavaPlugin {
Skript.registerExpression(ExprNoClip.class, Boolean.class, ExpressionType.PROPERTY, "no[( |-)]clip (state|mode) of %entity%", "%entity%'s no[( |-)]clip (state|mode)");
Skript.registerExpression(ExprFireProof.class, Boolean.class, ExpressionType.PROPERTY, "fire[ ]proof (state|mode) of %entity%", "%entity%'s fire[ ]proof (state|mode)");
Classes.registerClass(new ClassInfo<Object>((Class<Object>) nbtClass, "compound").user("((nbt)?( ?tag)?) ?compounds?").name("NBT Compound").parser(new Parser<Object>() {
Classes.registerClass(new ClassInfo<Object>((Class<Object>) nbtClass, "compound").user("((nbt)?( ?tag)?) ?compounds?").name("NBT Compound").changer(new Changer<Object>() {
private Class<?> nbtBaseClass = ReflectionUtils.getNMSClass("NBTBase");
@Override
@Nullable
public Class<?>[] acceptChange(ChangeMode mode) {
if (mode == ChangeMode.ADD || mode == ChangeMode.REMOVE) {
return CollectionUtils.array(String[].class);
}
return null;
}
@Override
public void change(Object[] NBT, @Nullable Object[] delta, ChangeMode mode) {
Boolean using1_7 = false;
String bukkitVersion = ReflectionUtils.getVersion();
if (bukkitVersion.startsWith("v1_7_R")) {
using1_7 = true;
}
String newTags = (String) delta[0];
if (mode == ChangeMode.ADD) {
Object NBT1 = null;
try {
NBT1 = nbtParserClass.getMethod("parse", String.class).invoke(NBT1, newTags);
if (!using1_7) {
NBT.getClass().getMethod("a", nbtClass).invoke(NBT, NBT1);
} else {
NBT.getClass().getMethod("set", String.class, nbtBaseClass).invoke(NBT, "", NBT1);
}
} catch (Exception ex) {
if (ex instanceof InvocationTargetException) {
if (ex.getCause().getClass().equals(nbtParseExClass) ) {
Skript.error("Error when parsing NBT - " + ex.getCause().getMessage());
}
ex.printStackTrace();
}
ex.printStackTrace();
}
} else if (mode == ChangeMode.REMOVE) {
for (Object s : delta) {
try {
NBT.getClass().getMethod("remove", String.class).invoke(NBT, (String) s);
} catch (Exception ex) {
ex.printStackTrace();
}
}
}
}
}).parser(new Parser<Object>() {
@Override
public String getVariableNamePattern() {
@ -176,6 +229,13 @@ public class SkStuff extends JavaPlugin {
Skript.error("Unable to register \"On WorldEdit block change\" event! You will need to upgrade to WorldEdit 6.0");
}
}
if (Bukkit.getPluginManager().getPlugin("VanishNoPacket") != null) {
getLogger().info("VanishNoPacket was found! Registering vanishing features...");
effAmount += 1;
exprAmount += 1;
Skript.registerEffect(EffToggleVanish.class, "toggle vanish (state|mode) of %player% (0¦|1¦(silently|quietly))", "toggle %player%'s vanish (state|mode) (0¦|1¦(silently|quietly))");
Skript.registerExpression(ExprVanishState.class, Boolean.class, ExpressionType.PROPERTY, "vanish (state|mode) of %player%", "%player%'s vanish (state|mode)");
}
getLogger().info("Everything ready! Loaded a total of " + condAmount + (condAmount == 1 ? " condition, " : " conditions, ") + effAmount + (effAmount == 1 ? " effect, " : " effects, ") + (evtWE ? "1 event, " : "") + exprAmount + (exprAmount == 1 ? " expression" : " expressions and ") + typeAmount + (typeAmount == 1 ? " type!" : " types!"));
} else {
getLogger().info("Unable to find Skript or Skript isn't accepting registrations, disabling SkStuff...");

View File

@ -0,0 +1,47 @@
package me.TheBukor.SkStuff.effects;
import javax.annotation.Nullable;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.event.Event;
import org.bukkit.plugin.Plugin;
import org.kitteh.vanish.VanishPlugin;
import ch.njol.skript.lang.Effect;
import ch.njol.skript.lang.Expression;
import ch.njol.skript.lang.SkriptParser.ParseResult;
import ch.njol.util.Kleenean;
public class EffToggleVanish extends Effect {
private Expression<Player> player;
private Plugin vanishPlugin = Bukkit.getPluginManager().getPlugin("VanishNoPacket");
private boolean silent = false;
private String toStringMark = "";
@SuppressWarnings("unchecked")
@Override
public boolean init(Expression<?>[] expr, int matchedPattern, Kleenean arg2, ParseResult result) {
player = (Expression<Player>) expr[0];
if (result.mark == 1) {
toStringMark = " silently";
silent = true;
}
return true;
}
@Override
public String toString(@Nullable Event e, boolean arg1) {
return "toggle vanished state of " + player.toString(e, false) + toStringMark;
}
@Override
protected void execute(Event e) {
Player p = player.getSingle(e);
if (silent) {
((VanishPlugin) vanishPlugin).getManager().toggleVanishQuiet(p, false);
} else {
((VanishPlugin) vanishPlugin).getManager().toggleVanish(p);
}
}
}

View File

@ -0,0 +1,48 @@
package me.TheBukor.SkStuff.expressions;
import javax.annotation.Nullable;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.event.Event;
import org.bukkit.plugin.Plugin;
import org.kitteh.vanish.VanishPlugin;
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 ExprVanishState extends SimpleExpression<Boolean> {
private Expression<Player> player;
private Plugin vanishPlugin = Bukkit.getPluginManager().getPlugin("VanishNoPacket");
@Override
public Class<? extends Boolean> getReturnType() {
return Boolean.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 "vanish state of " + player.toString(e, false);
}
@Override
@Nullable
protected Boolean[] get(Event e) {
Player p = player.getSingle(e);
return new Boolean[] { ((VanishPlugin) vanishPlugin).getManager().isVanished(p) };
}
}