diff --git a/.classpath b/.classpath
index 97c5184..6c9e5e6 100644
--- a/.classpath
+++ b/.classpath
@@ -10,5 +10,6 @@
+
diff --git a/src/me/TheBukor/SkStuff/SkStuff.java b/src/me/TheBukor/SkStuff/SkStuff.java
index 1371938..584926d 100644
--- a/src/me/TheBukor/SkStuff/SkStuff.java
+++ b/src/me/TheBukor/SkStuff/SkStuff.java
@@ -4,19 +4,28 @@ import javax.annotation.Nullable;
import org.bukkit.Bukkit;
import org.bukkit.Location;
+import org.bukkit.World;
import org.bukkit.block.Block;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import org.bukkit.event.entity.EntityToggleGlideEvent;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
+import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.java.JavaPlugin;
import com.sk89q.worldedit.EditSession;
+import com.sk89q.worldguard.bukkit.WGBukkit;
+import com.sk89q.worldguard.protection.flags.DefaultFlag;
+import com.sk89q.worldguard.protection.flags.Flag;
+import com.sk89q.worldguard.protection.regions.ProtectedRegion;
import ch.njol.skript.Skript;
import ch.njol.skript.classes.ClassInfo;
+import ch.njol.skript.classes.Parser;
+import ch.njol.skript.expressions.base.EventValueExpression;
import ch.njol.skript.lang.ExpressionType;
+import ch.njol.skript.lang.ParseContext;
import ch.njol.skript.lang.util.SimpleEvent;
import ch.njol.skript.registrations.Classes;
import ch.njol.skript.registrations.EventValues;
@@ -51,6 +60,8 @@ import me.TheBukor.SkStuff.expressions.ExprEditSessionLimit;
import me.TheBukor.SkStuff.expressions.ExprEndermanBlocks;
import me.TheBukor.SkStuff.expressions.ExprFileNBT;
import me.TheBukor.SkStuff.expressions.ExprFireProof;
+import me.TheBukor.SkStuff.expressions.ExprFlagOfWGRegion;
+import me.TheBukor.SkStuff.expressions.ExprFlagsOfWGRegion;
import me.TheBukor.SkStuff.expressions.ExprGlideState;
import me.TheBukor.SkStuff.expressions.ExprItemNBT;
import me.TheBukor.SkStuff.expressions.ExprMCIdOf;
@@ -87,6 +98,7 @@ public class SkStuff extends JavaPlugin {
private static NMSInterface nmsMethods;
+ @SuppressWarnings("rawtypes")
public void onEnable() {
if (Bukkit.getPluginManager().getPlugin("Skript") != null && Skript.isAcceptRegistrations()) {
Skript.registerAddon(this);
@@ -106,7 +118,7 @@ public class SkStuff extends JavaPlugin {
if (Skript.isRunningMinecraft(1, 9)) {
getLogger().info("WOW! You're using Minecraft 1.9! Lemme register some cool stuff right away!");
Skript.registerEvent("Elytra glide toggle", SimpleEvent.class, EntityToggleGlideEvent.class, "[entity] elytra (fl(y|ight)|glid(e|ing)) toggl(e|ing)", "[entity] toggle elytra (fl(y|ight)|glid(e|ing))");
- Skript.registerExpression(ExprGlideState.class, Boolean.class, ExpressionType.PROPERTY, "elytra (fl(y|ight)|glid(e|ing)) state of %player%", "%player%'s elytra (fl(y|ight)|glid(e|ing)) state");
+ Skript.registerExpression(ExprGlideState.class, Boolean.class, ExpressionType.PROPERTY, "elytra (fl(y|ight)|glid(e|ing)) state of %livingentity%", "%livingentity%'s elytra (fl(y|ight)|glid(e|ing)) state");
EventValues.registerEventValue(EntityToggleGlideEvent.class, Entity.class, new Getter() {
@Override
@@ -186,12 +198,78 @@ public class SkStuff extends JavaPlugin {
evtAmount += 1;
} catch (ClassNotFoundException ex) {
Skript.error("Unable to register \"On WorldEdit block change\" event! You will need to upgrade to WorldEdit 6.0");
- return;
}
condAmount += 1;
effAmount += 13;
exprAmount += 7;
typeAmount += 1;
+ if (Bukkit.getPluginManager().getPlugin("WorldGuard") != null) { //WorldGuard depends on WorldEdit
+ Plugin umbaska = Bukkit.getPluginManager().getPlugin("Umbaska");
+ Plugin skRambled = Bukkit.getPluginManager().getPlugin("SkRambled");
+ boolean registerNewTypes = (umbaska == null && skRambled == null);
+ if (registerNewTypes) {
+ Skript.registerExpression(ExprFlagOfWGRegion.class, Flag.class, ExpressionType.PROPERTY, "[w[orld[ ]]g[uard]] flag %wgflag% of %wgregion%");
+ Skript.registerExpression(ExprFlagsOfWGRegion.class, Flag.class, ExpressionType.PROPERTY, "all [w[orld[ ]]g[uard]] flags of %wgregion%");
+ Classes.registerClass(new ClassInfo(Flag.class, "wgflag").name("WorldGuard Flag").user("(w(orld ?)?g(uard)? )?flags?").defaultExpression(new EventValueExpression(Flag.class)).parser(new Parser>() {
+
+ @Override
+ @Nullable
+ public Flag> parse(String flag, ParseContext context) {
+ return DefaultFlag.fuzzyMatchFlag(flag);
+ }
+
+ @Override
+ public String toString(Flag> flag, int flags) {
+ return flag.getName().toLowerCase();
+ }
+
+ @Override
+ public String toVariableNameString(Flag> flag) {
+ return flag.getName().toLowerCase();
+ }
+
+ @Override
+ public String getVariableNamePattern() {
+ return ".+";
+ }
+ }));
+ Classes.registerClass(new ClassInfo(ProtectedRegion.class, "wgregion").name("WorldGuard Region").user("(w(orld ?)?g(uard)? )?regions?").defaultExpression(new EventValueExpression<>(ProtectedRegion.class)).parser(new Parser() {
+
+ @Override
+ @Nullable
+ public ProtectedRegion parse(String region, ParseContext context) {
+ for (World w : Bukkit.getWorlds()) {
+ if (WGBukkit.getRegionManager(w).hasRegion(region)) {
+ return WGBukkit.getRegionManager(w).getRegion(region);
+ }
+ }
+ return null;
+ }
+
+ @Override
+ public String toString(ProtectedRegion region, int flags) {
+ return region.getId();
+ }
+
+ @Override
+ public String toVariableNameString(ProtectedRegion region) {
+ return region.getId();
+ }
+
+ @Override
+ public String getVariableNamePattern() {
+ return ".+";
+ }
+
+ }));
+ } else {
+ Skript.registerExpression(ExprFlagOfWGRegion.class, Flag.class, ExpressionType.PROPERTY, "[skstuff] [w[orld[ ]]g[uard]] flag %flag% of %protectedregion%");
+ Skript.registerExpression(ExprFlagsOfWGRegion.class, Flag.class, ExpressionType.PROPERTY, "[skstuff] [all] [w[orld[ ]]g[uard]] flags of %protectedregion%");
+ }
+ exprAmount += 2;
+ if (registerNewTypes)
+ typeAmount += 2;
+ }
}
if (Bukkit.getPluginManager().getPlugin("VanishNoPacket") != null) {
getLogger().info("VanishNoPacket was found! Registering vanishing features...");
diff --git a/src/me/TheBukor/SkStuff/effects/EffSetPathGoal.java b/src/me/TheBukor/SkStuff/effects/EffSetPathGoal.java
index 3b3649d..ff1518d 100644
--- a/src/me/TheBukor/SkStuff/effects/EffSetPathGoal.java
+++ b/src/me/TheBukor/SkStuff/effects/EffSetPathGoal.java
@@ -175,7 +175,7 @@ public class EffSetPathGoal extends Effect {
for (EntityData> entData : types) {
if (!LivingEntity.class.isAssignableFrom(entData.getType()))
return;
- String className = entData.getType().getClass().getSimpleName();
+ String className = entData.getType().getSimpleName();
if (className.equals("HumanEntity")) {
className = "Human";
} else if (className.equals("EntityLiving")) {
@@ -189,7 +189,7 @@ public class EffSetPathGoal extends Effect {
for (EntityData> entData : types) {
if (!LivingEntity.class.isAssignableFrom(entData.getType()))
return;
- String className = entData.getType().getClass().getSimpleName();
+ String className = entData.getType().getSimpleName();
if (className.equals("HumanEntity")) {
className = "Human";
} else if (className.equals("EntityLiving")) {
@@ -240,7 +240,7 @@ public class EffSetPathGoal extends Effect {
for (EntityData> entData : types) {
if (!LivingEntity.class.isAssignableFrom(entData.getType()))
return;
- String className = entData.getType().getClass().getSimpleName();
+ String className = entData.getType().getSimpleName();
if (className.equals("HumanEntity")) {
className = "Human";
} else if (className.equals("EntityLiving")) {
@@ -269,7 +269,7 @@ public class EffSetPathGoal extends Effect {
for (EntityData> entData : types) {
if (!LivingEntity.class.isAssignableFrom(entData.getType()))
return;
- String className = entData.getType().getClass().getSimpleName();
+ String className = entData.getType().getSimpleName();
if (className.equals("HumanEntity")) {
className = "Human";
} else if (className.equals("EntityLiving")) {
@@ -285,7 +285,7 @@ public class EffSetPathGoal extends Effect {
for (EntityData> entData : types) {
if (!LivingEntity.class.isAssignableFrom(entData.getType()))
return;
- String className = entData.getType().getClass().getSimpleName();
+ String className = entData.getType().getSimpleName();
if (className.equals("HumanEntity")) {
className = "Human";
} else if (className.equals("EntityLiving")) {
@@ -298,18 +298,7 @@ public class EffSetPathGoal extends Effect {
double spd = (meleeSpeed == null ? 1.0D : meleeSpeed.getSingle(e).doubleValue());
boolean memorize = (meleeMemorize == null ? false : meleeMemorize.getSingle(e));
Class> goalMeleeAttack = ReflectionUtils.getNMSClass("PathfinderGoalMeleeAttack");
- for (EntityData> entData : types) {
- if (!LivingEntity.class.isAssignableFrom(entData.getType()))
- return;
- String className = entData.getType().getClass().getSimpleName();
- if (className.equals("HumanEntity")) {
- className = "Human";
- } else if (className.equals("EntityLiving")) {
- className = "Living";
- }
- Class> nmsClass = ReflectionUtils.getNMSClass("Entity" + className);
- newGoals.add(goalMeleeAttack.getConstructor(entCreature, Class.class, double.class, boolean.class).newInstance(nmsEnt, nmsClass, spd, memorize));
- }
+ newGoals.add(goalMeleeAttack.getConstructor(entCreature, double.class, boolean.class).newInstance(nmsEnt, spd, memorize));
}
} else if (mark == 13) {
double spd = (moveTargetSpeed == null ? 1.0D : moveTargetSpeed.getSingle(e).doubleValue());
@@ -324,7 +313,7 @@ public class EffSetPathGoal extends Effect {
for (EntityData> entData : types) {
if (!LivingEntity.class.isAssignableFrom(entData.getType()))
return;
- String className = entData.getType().getClass().getSimpleName();
+ String className = entData.getType().getSimpleName();
if (className.equals("HumanEntity")) {
className = "Human";
} else if (className.equals("EntityLiving")) {
@@ -339,7 +328,7 @@ public class EffSetPathGoal extends Effect {
for (EntityData> entData : types) {
if (!LivingEntity.class.isAssignableFrom(entData.getType()))
return;
- String className = entData.getType().getClass().getSimpleName();
+ String className = entData.getType().getSimpleName();
if (className.equals("HumanEntity")) {
className = "Human";
} else if (className.equals("EntityLiving")) {
@@ -450,7 +439,7 @@ public class EffSetPathGoal extends Effect {
for (EntityData> entData : types) {
if (!LivingEntity.class.isAssignableFrom(entData.getType()))
return;
- String className = entData.getType().getClass().getSimpleName();
+ String className = entData.getType().getSimpleName();
if (className.equals("HumanEntity")) {
className = "Human";
} else if (className.equals("EntityLiving")) {
diff --git a/src/me/TheBukor/SkStuff/expressions/ExprFlagOfWGRegion.java b/src/me/TheBukor/SkStuff/expressions/ExprFlagOfWGRegion.java
new file mode 100644
index 0000000..8f1267f
--- /dev/null
+++ b/src/me/TheBukor/SkStuff/expressions/ExprFlagOfWGRegion.java
@@ -0,0 +1,121 @@
+package me.TheBukor.SkStuff.expressions;
+
+import java.util.HashSet;
+import java.util.Set;
+
+import org.bukkit.craftbukkit.libs.jline.internal.Nullable;
+import org.bukkit.entity.EntityType;
+import org.bukkit.event.Event;
+
+import com.sk89q.worldguard.protection.flags.BooleanFlag;
+import com.sk89q.worldguard.protection.flags.EntityTypeFlag;
+import com.sk89q.worldguard.protection.flags.Flag;
+import com.sk89q.worldguard.protection.flags.SetFlag;
+import com.sk89q.worldguard.protection.flags.StateFlag;
+import com.sk89q.worldguard.protection.flags.StateFlag.State;
+import com.sk89q.worldguard.protection.flags.StringFlag;
+import com.sk89q.worldguard.protection.regions.ProtectedRegion;
+
+import ch.njol.skript.Skript;
+import ch.njol.skript.classes.Changer.ChangeMode;
+import ch.njol.skript.entity.EntityData;
+import ch.njol.skript.lang.Expression;
+import ch.njol.skript.lang.SkriptParser.ParseResult;
+import ch.njol.skript.lang.util.SimpleExpression;
+import ch.njol.util.Kleenean;
+import ch.njol.util.coll.CollectionUtils;
+
+@SuppressWarnings("rawtypes")
+public class ExprFlagOfWGRegion extends SimpleExpression {
+ private Expression> flag;
+ private Expression region;
+
+ @SuppressWarnings("unchecked")
+ @Override
+ public boolean init(final Expression>[] expr, final int matchedPattern, final Kleenean isDelayed, final ParseResult parseResult) {
+ flag = (Expression>) expr[0];
+ region = (Expression) expr[1];
+ return true;
+ }
+
+ @Override
+ protected Flag>[] get(final Event e) {
+ ProtectedRegion region = this.region.getSingle(e);
+ Flag> flag = this.flag.getSingle(e);
+ return new Flag>[] { (Flag>) region.getFlag(flag) };
+ }
+
+ @Override
+ public boolean isSingle() {
+ return true;
+ }
+
+ @SuppressWarnings("unchecked")
+ @Override
+ public Class extends Flag>> getReturnType() {
+ return (Class extends Flag>>) Flag.class;
+ }
+
+ @Override
+ public String toString(final @Nullable Event e, final boolean debug) {
+ return "worldguard flag " + flag.toString(e, debug) + " of " + region.toString(e, debug);
+ }
+
+ @SuppressWarnings("unchecked")
+ @Override
+ public void change(Event e, Object[] delta, ChangeMode mode) {
+ ProtectedRegion region = this.region.getSingle(e);
+ Flag> flag = this.flag.getSingle(e);
+ if (region == null)
+ return;
+ if (mode == ChangeMode.SET) {
+ if (flag instanceof StateFlag && delta[0] instanceof Boolean) {
+ boolean allow = (boolean) delta[0];
+ State newState = State.DENY;
+ if (allow) {
+ newState = State.ALLOW;
+ }
+ region.setFlag((StateFlag) flag, newState);
+ } else if (flag instanceof StringFlag && delta[0] instanceof String) {
+ String newValue = (String) delta[0];
+ region.setFlag((StringFlag) flag, newValue);
+ } else if (flag instanceof BooleanFlag && delta[0] instanceof Boolean) {
+ boolean newValue = (boolean) delta[0];
+ region.setFlag((BooleanFlag) flag, newValue);
+ } else if (flag instanceof SetFlag) {
+ if (delta instanceof EntityData[]) {
+ if (((SetFlag) flag).getType() instanceof EntityTypeFlag) {
+ Set newSet = new HashSet();
+ for (Object entData : delta) {
+ EntityType toAdd = null;
+ for (EntityType entType : EntityType.values()) { //A weird workaround I've thought to get the entity type from a Skript entity data
+ if (((EntityData) entData).getType() == entType.getEntityClass()) {
+ toAdd = entType;
+ }
+ }
+ if (toAdd != null) {
+ newSet.add(toAdd);
+ }
+ }
+ region.setFlag((SetFlag) flag, newSet);
+ } else {
+ Skript.error("Sorry, this flag type isn't supported yet! Flag type: SetFlag of type " + ((SetFlag) flag).getType().getName());
+ }
+ }
+ } else {
+ Skript.error("Sorry, this flag type isn't supported yet! Flag type: " + flag.getClass().getSimpleName());
+ }
+ } else if (mode == ChangeMode.RESET || mode == ChangeMode.DELETE) {
+ region.setFlag(flag, null);
+ }
+ }
+
+ @SuppressWarnings("unchecked")
+ @Override
+ public Class>[] acceptChange(final ChangeMode mode) {
+ if (mode == ChangeMode.SET || mode == ChangeMode.RESET || mode == ChangeMode.DELETE) {
+ return CollectionUtils.array(String.class, Boolean.class, EntityData[].class);
+ }
+ return null;
+ }
+}
diff --git a/src/me/TheBukor/SkStuff/expressions/ExprFlagsOfWGRegion.java b/src/me/TheBukor/SkStuff/expressions/ExprFlagsOfWGRegion.java
new file mode 100644
index 0000000..10fb408
--- /dev/null
+++ b/src/me/TheBukor/SkStuff/expressions/ExprFlagsOfWGRegion.java
@@ -0,0 +1,67 @@
+package me.TheBukor.SkStuff.expressions;
+
+import org.bukkit.craftbukkit.libs.jline.internal.Nullable;
+import org.bukkit.event.Event;
+
+import com.sk89q.worldguard.protection.flags.Flag;
+import com.sk89q.worldguard.protection.regions.ProtectedRegion;
+
+import ch.njol.skript.classes.Changer.ChangeMode;
+import ch.njol.skript.lang.Expression;
+import ch.njol.skript.lang.SkriptParser.ParseResult;
+import ch.njol.skript.lang.util.SimpleExpression;
+import ch.njol.util.Kleenean;
+
+@SuppressWarnings("rawtypes")
+public class ExprFlagsOfWGRegion extends SimpleExpression {
+ private Expression region;
+
+ @SuppressWarnings("unchecked")
+ @Override
+ public boolean init(final Expression>[] expr, final int matchedPattern, final Kleenean isDelayed, final ParseResult parseResult) {
+ region = (Expression) expr[0];
+ return true;
+ }
+
+ @Override
+ protected Flag[] get(final Event e) {
+ ProtectedRegion region = this.region.getSingle(e);
+ if (region != null) {
+ return region.getFlags().keySet().toArray(new Flag[region.getFlags().size()]);
+ }
+ return null;
+ }
+
+ @Override
+ public boolean isSingle() {
+ return false;
+ }
+
+ @Override
+ public Class extends Flag> getReturnType() {
+ return Flag.class;
+ }
+
+ @Override
+ public String toString(final @Nullable Event e, final boolean debug) {
+ return "all worldguard flags of " + region.toString(e, debug);
+ }
+
+ @Override
+ public void change(Event e, Object[] delta, ChangeMode mode) {
+ ProtectedRegion region = this.region.getSingle(e);
+ if (region == null)
+ return;
+ if (mode == ChangeMode.RESET || mode == ChangeMode.DELETE) {
+ region.getFlags().clear();
+ }
+ }
+
+ @Override
+ public Class>[] acceptChange(final ChangeMode mode) {
+ if (mode == ChangeMode.RESET || mode == ChangeMode.DELETE) {
+ return new Class[0];
+ }
+ return null;
+ }
+}
\ No newline at end of file
diff --git a/src/me/TheBukor/SkStuff/expressions/ExprGlideState.java b/src/me/TheBukor/SkStuff/expressions/ExprGlideState.java
index 6c3e04b..6d5383f 100644
--- a/src/me/TheBukor/SkStuff/expressions/ExprGlideState.java
+++ b/src/me/TheBukor/SkStuff/expressions/ExprGlideState.java
@@ -2,8 +2,8 @@ package me.TheBukor.SkStuff.expressions;
import javax.annotation.Nullable;
-import org.bukkit.craftbukkit.v1_9_R1.entity.CraftPlayer;
-import org.bukkit.entity.Player;
+import org.bukkit.craftbukkit.v1_9_R1.entity.CraftLivingEntity;
+import org.bukkit.entity.LivingEntity;
import org.bukkit.event.Event;
import ch.njol.skript.classes.Changer.ChangeMode;
@@ -12,10 +12,10 @@ import ch.njol.skript.lang.SkriptParser.ParseResult;
import ch.njol.skript.lang.util.SimpleExpression;
import ch.njol.util.Kleenean;
import ch.njol.util.coll.CollectionUtils;
-import net.minecraft.server.v1_9_R1.EntityPlayer;
+import net.minecraft.server.v1_9_R1.EntityLiving;
public class ExprGlideState extends SimpleExpression {
- private Expression player;
+ private Expression entity;
@Override
public boolean isSingle() {
@@ -30,21 +30,21 @@ public class ExprGlideState extends SimpleExpression {
@SuppressWarnings("unchecked")
@Override
public boolean init(Expression>[] expr, int matchedPattern, Kleenean isDelayed, ParseResult parseResult) {
- player = (Expression) expr[0];
+ entity = (Expression) expr[0];
return true;
}
@Override
public String toString(@Nullable Event e, boolean debug) {
- return "elytra gliding state of " + player.toString(e, debug);
+ return "elytra gliding state of " + entity.toString(e, debug);
}
@Override
@Nullable
protected Boolean[] get(Event e) {
- Player p = player.getSingle(e);
- EntityPlayer nmsPlayer = ((CraftPlayer) p).getHandle();
- return new Boolean[] { nmsPlayer.cB() };
+ LivingEntity ent = entity.getSingle(e);
+ EntityLiving nmsEntity = ((CraftLivingEntity) ent).getHandle();
+ return new Boolean[] { nmsEntity.cB() };
}
@SuppressWarnings("unchecked")
@@ -59,11 +59,11 @@ public class ExprGlideState extends SimpleExpression {
@Override
public void change(Event e, @Nullable Object[] delta, ChangeMode mode) {
- Player p = player.getSingle(e);
- EntityPlayer nmsPlayer = ((CraftPlayer) p).getHandle();
+ LivingEntity ent = entity.getSingle(e);
+ EntityLiving nmsEntity = ((CraftLivingEntity) ent).getHandle();
if (mode == ChangeMode.SET) {
boolean newValue = (boolean) delta[0];
- nmsPlayer.setFlag(7, newValue);
+ nmsEntity.setFlag(7, newValue);
}
}
}
diff --git a/src/me/TheBukor/SkStuff/expressions/ExprNBTOf.java b/src/me/TheBukor/SkStuff/expressions/ExprNBTOf.java
index 0a8e353..d96ac42 100644
--- a/src/me/TheBukor/SkStuff/expressions/ExprNBTOf.java
+++ b/src/me/TheBukor/SkStuff/expressions/ExprNBTOf.java
@@ -128,18 +128,19 @@ public class ExprNBTOf extends SimpleExpression