New WG Flag expressions (SkRambled expressions are somewhat broken)...
Register event-entity on Elytra Glide event Change Elytra glide state to accept entities Fixed "add x nbt of %slot%" Fix an NPE in the NBTOf expression
This commit is contained in:
		
							parent
							
								
									3b2a9ca988
								
							
						
					
					
						commit
						24c07ad0d8
					
				| @ -10,5 +10,6 @@ | |||||||
| 	<classpathentry kind="lib" path="C:/Users/DELL/AppData/Roaming/.minecraft/workspace/eclipse/Build Path/1.9.jar"/> | 	<classpathentry kind="lib" path="C:/Users/DELL/AppData/Roaming/.minecraft/workspace/eclipse/Build Path/1.9.jar"/> | ||||||
| 	<classpathentry kind="lib" path="C:/Users/DELL/AppData/Roaming/.minecraft/workspace/eclipse/Build Path/VanishNoPacket.jar"/> | 	<classpathentry kind="lib" path="C:/Users/DELL/AppData/Roaming/.minecraft/workspace/eclipse/Build Path/VanishNoPacket.jar"/> | ||||||
| 	<classpathentry kind="lib" path="C:/Users/DELL/AppData/Roaming/.minecraft/workspace/eclipse/Build Path/WorldEdit.jar"/> | 	<classpathentry kind="lib" path="C:/Users/DELL/AppData/Roaming/.minecraft/workspace/eclipse/Build Path/WorldEdit.jar"/> | ||||||
|  | 	<classpathentry kind="lib" path="C:/Users/DELL/AppData/Roaming/.minecraft/workspace/eclipse/Build Path/WorldGuard.jar"/> | ||||||
| 	<classpathentry kind="output" path="bin"/> | 	<classpathentry kind="output" path="bin"/> | ||||||
| </classpath> | </classpath> | ||||||
|  | |||||||
| @ -4,19 +4,28 @@ import javax.annotation.Nullable; | |||||||
| 
 | 
 | ||||||
| import org.bukkit.Bukkit; | import org.bukkit.Bukkit; | ||||||
| import org.bukkit.Location; | import org.bukkit.Location; | ||||||
|  | import org.bukkit.World; | ||||||
| import org.bukkit.block.Block; | import org.bukkit.block.Block; | ||||||
| import org.bukkit.entity.Entity; | import org.bukkit.entity.Entity; | ||||||
| import org.bukkit.entity.Player; | import org.bukkit.entity.Player; | ||||||
| import org.bukkit.event.entity.EntityToggleGlideEvent; | import org.bukkit.event.entity.EntityToggleGlideEvent; | ||||||
| import org.bukkit.inventory.Inventory; | import org.bukkit.inventory.Inventory; | ||||||
| import org.bukkit.inventory.ItemStack; | import org.bukkit.inventory.ItemStack; | ||||||
|  | import org.bukkit.plugin.Plugin; | ||||||
| import org.bukkit.plugin.java.JavaPlugin; | import org.bukkit.plugin.java.JavaPlugin; | ||||||
| 
 | 
 | ||||||
| import com.sk89q.worldedit.EditSession; | 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.Skript; | ||||||
| import ch.njol.skript.classes.ClassInfo; | 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.ExpressionType; | ||||||
|  | import ch.njol.skript.lang.ParseContext; | ||||||
| import ch.njol.skript.lang.util.SimpleEvent; | import ch.njol.skript.lang.util.SimpleEvent; | ||||||
| import ch.njol.skript.registrations.Classes; | import ch.njol.skript.registrations.Classes; | ||||||
| import ch.njol.skript.registrations.EventValues; | 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.ExprEndermanBlocks; | ||||||
| import me.TheBukor.SkStuff.expressions.ExprFileNBT; | import me.TheBukor.SkStuff.expressions.ExprFileNBT; | ||||||
| import me.TheBukor.SkStuff.expressions.ExprFireProof; | 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.ExprGlideState; | ||||||
| import me.TheBukor.SkStuff.expressions.ExprItemNBT; | import me.TheBukor.SkStuff.expressions.ExprItemNBT; | ||||||
| import me.TheBukor.SkStuff.expressions.ExprMCIdOf; | import me.TheBukor.SkStuff.expressions.ExprMCIdOf; | ||||||
| @ -87,6 +98,7 @@ public class SkStuff extends JavaPlugin { | |||||||
| 
 | 
 | ||||||
| 	private static NMSInterface nmsMethods; | 	private static NMSInterface nmsMethods; | ||||||
| 
 | 
 | ||||||
|  | 	@SuppressWarnings("rawtypes") | ||||||
| 	public void onEnable() { | 	public void onEnable() { | ||||||
| 		if (Bukkit.getPluginManager().getPlugin("Skript") != null && Skript.isAcceptRegistrations()) { | 		if (Bukkit.getPluginManager().getPlugin("Skript") != null && Skript.isAcceptRegistrations()) { | ||||||
| 			Skript.registerAddon(this); | 			Skript.registerAddon(this); | ||||||
| @ -106,7 +118,7 @@ public class SkStuff extends JavaPlugin { | |||||||
| 			if (Skript.isRunningMinecraft(1, 9)) { | 			if (Skript.isRunningMinecraft(1, 9)) { | ||||||
| 				getLogger().info("WOW! You're using Minecraft 1.9! Lemme register some cool stuff right away!"); | 				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.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<Entity, EntityToggleGlideEvent>() { | 				EventValues.registerEventValue(EntityToggleGlideEvent.class, Entity.class, new Getter<Entity, EntityToggleGlideEvent>() { | ||||||
| 					@Override | 					@Override | ||||||
| @ -186,12 +198,78 @@ public class SkStuff extends JavaPlugin { | |||||||
| 					evtAmount += 1; | 					evtAmount += 1; | ||||||
| 				} catch (ClassNotFoundException ex) { | 				} catch (ClassNotFoundException ex) { | ||||||
| 					Skript.error("Unable to register \"On WorldEdit block change\" event! You will need to upgrade to WorldEdit 6.0"); | 					Skript.error("Unable to register \"On WorldEdit block change\" event! You will need to upgrade to WorldEdit 6.0"); | ||||||
| 					return; |  | ||||||
| 				} | 				} | ||||||
| 				condAmount += 1; | 				condAmount += 1; | ||||||
| 				effAmount += 13; | 				effAmount += 13; | ||||||
| 				exprAmount += 7; | 				exprAmount += 7; | ||||||
| 				typeAmount += 1; | 				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>(Flag.class, "wgflag").name("WorldGuard Flag").user("(w(orld ?)?g(uard)? )?flags?").defaultExpression(new EventValueExpression<Flag>(Flag.class)).parser(new Parser<Flag<?>>() { | ||||||
|  | 
 | ||||||
|  | 							@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>(ProtectedRegion.class, "wgregion").name("WorldGuard Region").user("(w(orld ?)?g(uard)? )?regions?").defaultExpression(new EventValueExpression<>(ProtectedRegion.class)).parser(new Parser<ProtectedRegion>() { | ||||||
|  | 	 | ||||||
|  | 							@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) { | 			if (Bukkit.getPluginManager().getPlugin("VanishNoPacket") != null) { | ||||||
| 				getLogger().info("VanishNoPacket was found! Registering vanishing features..."); | 				getLogger().info("VanishNoPacket was found! Registering vanishing features..."); | ||||||
|  | |||||||
| @ -175,7 +175,7 @@ public class EffSetPathGoal extends Effect { | |||||||
| 						for (EntityData<?> entData : types) { | 						for (EntityData<?> entData : types) { | ||||||
| 							if (!LivingEntity.class.isAssignableFrom(entData.getType())) | 							if (!LivingEntity.class.isAssignableFrom(entData.getType())) | ||||||
| 								return; | 								return; | ||||||
| 							String className = entData.getType().getClass().getSimpleName(); | 							String className = entData.getType().getSimpleName(); | ||||||
| 							if (className.equals("HumanEntity")) { | 							if (className.equals("HumanEntity")) { | ||||||
| 								className = "Human"; | 								className = "Human"; | ||||||
| 							} else if (className.equals("EntityLiving")) { | 							} else if (className.equals("EntityLiving")) { | ||||||
| @ -189,7 +189,7 @@ public class EffSetPathGoal extends Effect { | |||||||
| 						for (EntityData<?> entData : types) { | 						for (EntityData<?> entData : types) { | ||||||
| 							if (!LivingEntity.class.isAssignableFrom(entData.getType())) | 							if (!LivingEntity.class.isAssignableFrom(entData.getType())) | ||||||
| 								return; | 								return; | ||||||
| 							String className = entData.getType().getClass().getSimpleName(); | 							String className = entData.getType().getSimpleName(); | ||||||
| 							if (className.equals("HumanEntity")) { | 							if (className.equals("HumanEntity")) { | ||||||
| 								className = "Human"; | 								className = "Human"; | ||||||
| 							} else if (className.equals("EntityLiving")) { | 							} else if (className.equals("EntityLiving")) { | ||||||
| @ -240,7 +240,7 @@ public class EffSetPathGoal extends Effect { | |||||||
| 					for (EntityData<?> entData : types) { | 					for (EntityData<?> entData : types) { | ||||||
| 						if (!LivingEntity.class.isAssignableFrom(entData.getType())) | 						if (!LivingEntity.class.isAssignableFrom(entData.getType())) | ||||||
| 							return; | 							return; | ||||||
| 						String className = entData.getType().getClass().getSimpleName(); | 						String className = entData.getType().getSimpleName(); | ||||||
| 						if (className.equals("HumanEntity")) { | 						if (className.equals("HumanEntity")) { | ||||||
| 							className = "Human"; | 							className = "Human"; | ||||||
| 						} else if (className.equals("EntityLiving")) { | 						} else if (className.equals("EntityLiving")) { | ||||||
| @ -269,7 +269,7 @@ public class EffSetPathGoal extends Effect { | |||||||
| 					for (EntityData<?> entData : types) { | 					for (EntityData<?> entData : types) { | ||||||
| 						if (!LivingEntity.class.isAssignableFrom(entData.getType())) | 						if (!LivingEntity.class.isAssignableFrom(entData.getType())) | ||||||
| 							return; | 							return; | ||||||
| 						String className = entData.getType().getClass().getSimpleName(); | 						String className = entData.getType().getSimpleName(); | ||||||
| 						if (className.equals("HumanEntity")) { | 						if (className.equals("HumanEntity")) { | ||||||
| 							className = "Human"; | 							className = "Human"; | ||||||
| 						} else if (className.equals("EntityLiving")) { | 						} else if (className.equals("EntityLiving")) { | ||||||
| @ -285,7 +285,7 @@ public class EffSetPathGoal extends Effect { | |||||||
| 						for (EntityData<?> entData : types) { | 						for (EntityData<?> entData : types) { | ||||||
| 							if (!LivingEntity.class.isAssignableFrom(entData.getType())) | 							if (!LivingEntity.class.isAssignableFrom(entData.getType())) | ||||||
| 								return; | 								return; | ||||||
| 							String className = entData.getType().getClass().getSimpleName(); | 							String className = entData.getType().getSimpleName(); | ||||||
| 							if (className.equals("HumanEntity")) { | 							if (className.equals("HumanEntity")) { | ||||||
| 								className = "Human"; | 								className = "Human"; | ||||||
| 							} else if (className.equals("EntityLiving")) { | 							} else if (className.equals("EntityLiving")) { | ||||||
| @ -298,18 +298,7 @@ public class EffSetPathGoal extends Effect { | |||||||
| 						double spd = (meleeSpeed == null ? 1.0D : meleeSpeed.getSingle(e).doubleValue()); | 						double spd = (meleeSpeed == null ? 1.0D : meleeSpeed.getSingle(e).doubleValue()); | ||||||
| 						boolean memorize = (meleeMemorize == null ? false : meleeMemorize.getSingle(e)); | 						boolean memorize = (meleeMemorize == null ? false : meleeMemorize.getSingle(e)); | ||||||
| 						Class<?> goalMeleeAttack = ReflectionUtils.getNMSClass("PathfinderGoalMeleeAttack"); | 						Class<?> goalMeleeAttack = ReflectionUtils.getNMSClass("PathfinderGoalMeleeAttack"); | ||||||
| 						for (EntityData<?> entData : types) { | 						newGoals.add(goalMeleeAttack.getConstructor(entCreature, double.class, boolean.class).newInstance(nmsEnt, spd, memorize)); | ||||||
| 							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)); |  | ||||||
| 						} |  | ||||||
| 					} | 					} | ||||||
| 				} else if (mark == 13) { | 				} else if (mark == 13) { | ||||||
| 					double spd = (moveTargetSpeed == null ? 1.0D : moveTargetSpeed.getSingle(e).doubleValue()); | 					double spd = (moveTargetSpeed == null ? 1.0D : moveTargetSpeed.getSingle(e).doubleValue()); | ||||||
| @ -324,7 +313,7 @@ public class EffSetPathGoal extends Effect { | |||||||
| 						for (EntityData<?> entData : types) { | 						for (EntityData<?> entData : types) { | ||||||
| 							if (!LivingEntity.class.isAssignableFrom(entData.getType())) | 							if (!LivingEntity.class.isAssignableFrom(entData.getType())) | ||||||
| 								return; | 								return; | ||||||
| 							String className = entData.getType().getClass().getSimpleName(); | 							String className = entData.getType().getSimpleName(); | ||||||
| 							if (className.equals("HumanEntity")) { | 							if (className.equals("HumanEntity")) { | ||||||
| 								className = "Human"; | 								className = "Human"; | ||||||
| 							} else if (className.equals("EntityLiving")) { | 							} else if (className.equals("EntityLiving")) { | ||||||
| @ -339,7 +328,7 @@ public class EffSetPathGoal extends Effect { | |||||||
| 						for (EntityData<?> entData : types) { | 						for (EntityData<?> entData : types) { | ||||||
| 							if (!LivingEntity.class.isAssignableFrom(entData.getType())) | 							if (!LivingEntity.class.isAssignableFrom(entData.getType())) | ||||||
| 								return; | 								return; | ||||||
| 							String className = entData.getType().getClass().getSimpleName(); | 							String className = entData.getType().getSimpleName(); | ||||||
| 							if (className.equals("HumanEntity")) { | 							if (className.equals("HumanEntity")) { | ||||||
| 								className = "Human"; | 								className = "Human"; | ||||||
| 							} else if (className.equals("EntityLiving")) { | 							} else if (className.equals("EntityLiving")) { | ||||||
| @ -450,7 +439,7 @@ public class EffSetPathGoal extends Effect { | |||||||
| 					for (EntityData<?> entData : types) { | 					for (EntityData<?> entData : types) { | ||||||
| 						if (!LivingEntity.class.isAssignableFrom(entData.getType())) | 						if (!LivingEntity.class.isAssignableFrom(entData.getType())) | ||||||
| 							return; | 							return; | ||||||
| 						String className = entData.getType().getClass().getSimpleName(); | 						String className = entData.getType().getSimpleName(); | ||||||
| 						if (className.equals("HumanEntity")) { | 						if (className.equals("HumanEntity")) { | ||||||
| 							className = "Human"; | 							className = "Human"; | ||||||
| 						} else if (className.equals("EntityLiving")) { | 						} else if (className.equals("EntityLiving")) { | ||||||
|  | |||||||
							
								
								
									
										121
									
								
								src/me/TheBukor/SkStuff/expressions/ExprFlagOfWGRegion.java
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										121
									
								
								src/me/TheBukor/SkStuff/expressions/ExprFlagOfWGRegion.java
									
									
									
									
									
										Normal file
									
								
							| @ -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<Flag> { | ||||||
|  | 	private Expression<Flag<?>> flag; | ||||||
|  | 	private Expression<ProtectedRegion> region; | ||||||
|  | 
 | ||||||
|  | 	@SuppressWarnings("unchecked") | ||||||
|  | 	@Override | ||||||
|  | 	public boolean init(final Expression<?>[] expr, final int matchedPattern, final Kleenean isDelayed, final ParseResult parseResult) { | ||||||
|  | 		flag = (Expression<Flag<?>>) expr[0]; | ||||||
|  | 		region = (Expression<ProtectedRegion>) 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<EntityType> newSet = new HashSet<EntityType>(); | ||||||
|  | 						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<EntityType>) 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; | ||||||
|  | 	} | ||||||
|  | } | ||||||
							
								
								
									
										67
									
								
								src/me/TheBukor/SkStuff/expressions/ExprFlagsOfWGRegion.java
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										67
									
								
								src/me/TheBukor/SkStuff/expressions/ExprFlagsOfWGRegion.java
									
									
									
									
									
										Normal file
									
								
							| @ -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<Flag> { | ||||||
|  | 	private Expression<ProtectedRegion> region; | ||||||
|  | 
 | ||||||
|  | 	@SuppressWarnings("unchecked") | ||||||
|  | 	@Override | ||||||
|  | 	public boolean init(final Expression<?>[] expr, final int matchedPattern, final Kleenean isDelayed, final ParseResult parseResult) { | ||||||
|  | 		region = (Expression<ProtectedRegion>) 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; | ||||||
|  | 	} | ||||||
|  | } | ||||||
| @ -2,8 +2,8 @@ package me.TheBukor.SkStuff.expressions; | |||||||
| 
 | 
 | ||||||
| import javax.annotation.Nullable; | import javax.annotation.Nullable; | ||||||
| 
 | 
 | ||||||
| import org.bukkit.craftbukkit.v1_9_R1.entity.CraftPlayer; | import org.bukkit.craftbukkit.v1_9_R1.entity.CraftLivingEntity; | ||||||
| import org.bukkit.entity.Player; | import org.bukkit.entity.LivingEntity; | ||||||
| import org.bukkit.event.Event; | import org.bukkit.event.Event; | ||||||
| 
 | 
 | ||||||
| import ch.njol.skript.classes.Changer.ChangeMode; | 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.skript.lang.util.SimpleExpression; | ||||||
| import ch.njol.util.Kleenean; | import ch.njol.util.Kleenean; | ||||||
| import ch.njol.util.coll.CollectionUtils; | 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<Boolean> { | public class ExprGlideState extends SimpleExpression<Boolean> { | ||||||
| 	private Expression<Player> player; | 	private Expression<LivingEntity> entity; | ||||||
| 
 | 
 | ||||||
| 	@Override | 	@Override | ||||||
| 	public boolean isSingle() { | 	public boolean isSingle() { | ||||||
| @ -30,21 +30,21 @@ public class ExprGlideState extends SimpleExpression<Boolean> { | |||||||
| 	@SuppressWarnings("unchecked") | 	@SuppressWarnings("unchecked") | ||||||
| 	@Override | 	@Override | ||||||
| 	public boolean init(Expression<?>[] expr, int matchedPattern, Kleenean isDelayed, ParseResult parseResult) { | 	public boolean init(Expression<?>[] expr, int matchedPattern, Kleenean isDelayed, ParseResult parseResult) { | ||||||
| 		player = (Expression<Player>) expr[0]; | 		entity = (Expression<LivingEntity>) expr[0]; | ||||||
| 		return true; | 		return true; | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	@Override | 	@Override | ||||||
| 	public String toString(@Nullable Event e, boolean debug) { | 	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 | 	@Override | ||||||
| 	@Nullable | 	@Nullable | ||||||
| 	protected Boolean[] get(Event e) { | 	protected Boolean[] get(Event e) { | ||||||
| 		Player p = player.getSingle(e); | 		LivingEntity ent = entity.getSingle(e); | ||||||
| 		EntityPlayer nmsPlayer = ((CraftPlayer) p).getHandle(); | 		EntityLiving nmsEntity = ((CraftLivingEntity) ent).getHandle(); | ||||||
| 		return new Boolean[] { nmsPlayer.cB() }; | 		return new Boolean[] { nmsEntity.cB() }; | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	@SuppressWarnings("unchecked") | 	@SuppressWarnings("unchecked") | ||||||
| @ -59,11 +59,11 @@ public class ExprGlideState extends SimpleExpression<Boolean> { | |||||||
| 
 | 
 | ||||||
| 	@Override | 	@Override | ||||||
| 	public void change(Event e, @Nullable Object[] delta, ChangeMode mode) { | 	public void change(Event e, @Nullable Object[] delta, ChangeMode mode) { | ||||||
| 		Player p = player.getSingle(e); | 		LivingEntity ent = entity.getSingle(e); | ||||||
| 		EntityPlayer nmsPlayer = ((CraftPlayer) p).getHandle(); | 		EntityLiving nmsEntity = ((CraftLivingEntity) ent).getHandle(); | ||||||
| 		if (mode == ChangeMode.SET) { | 		if (mode == ChangeMode.SET) { | ||||||
| 			boolean newValue = (boolean) delta[0]; | 			boolean newValue = (boolean) delta[0]; | ||||||
| 			nmsPlayer.setFlag(7, newValue); | 			nmsEntity.setFlag(7, newValue); | ||||||
| 		} | 		} | ||||||
| 	} | 	} | ||||||
| } | } | ||||||
|  | |||||||
| @ -128,18 +128,19 @@ public class ExprNBTOf extends SimpleExpression<Object> { | |||||||
| 				} | 				} | ||||||
| 			} | 			} | ||||||
| 		} else if (tar instanceof Slot) { | 		} else if (tar instanceof Slot) { | ||||||
| 			Object itemNBT = SkStuff.getNMSMethods().getItemNBT(((Slot) tar).getItem()); | 			ItemStack slotItem = ((Slot) tar).getItem(); | ||||||
|  | 			Object itemNBT = SkStuff.getNMSMethods().getItemNBT(slotItem); | ||||||
| 			if (mode == ChangeMode.ADD) { | 			if (mode == ChangeMode.ADD) { | ||||||
| 				SkStuff.getNMSMethods().addToCompound(itemNBT, parsedNBT); | 				SkStuff.getNMSMethods().addToCompound(itemNBT, parsedNBT); | ||||||
| 				ItemStack newItem = SkStuff.getNMSMethods().getItemWithNBT((ItemStack) tar, itemNBT); | 				ItemStack newItem = SkStuff.getNMSMethods().getItemWithNBT(slotItem, itemNBT); | ||||||
| 				((Slot) tar).setItem(newItem); | 				((Slot) tar).setItem(newItem); | ||||||
| 			} else if (mode == ChangeMode.REMOVE) { | 			} else if (mode == ChangeMode.REMOVE) { | ||||||
| 				String[] toRemove = Arrays.copyOf(delta, delta.length, String[].class); | 				String[] toRemove = Arrays.copyOf(delta, delta.length, String[].class); | ||||||
| 				SkStuff.getNMSMethods().removeFromCompound(itemNBT, toRemove); | 				SkStuff.getNMSMethods().removeFromCompound(itemNBT, toRemove); | ||||||
| 				ItemStack newItem = SkStuff.getNMSMethods().getItemWithNBT((ItemStack) tar, itemNBT); | 				ItemStack newItem = SkStuff.getNMSMethods().getItemWithNBT(slotItem, itemNBT); | ||||||
| 				((Slot) tar).setItem(newItem); | 				((Slot) tar).setItem(newItem); | ||||||
| 			} else if (mode == ChangeMode.DELETE || mode == ChangeMode.RESET) { | 			} else if (mode == ChangeMode.DELETE || mode == ChangeMode.RESET) { | ||||||
| 				ItemStack newItem = SkStuff.getNMSMethods().getItemWithNBT((ItemStack) tar, null); | 				ItemStack newItem = SkStuff.getNMSMethods().getItemWithNBT(slotItem, null); | ||||||
| 				((Slot) tar).setItem(newItem); | 				((Slot) tar).setItem(newItem); | ||||||
| 			} | 			} | ||||||
| 		} | 		} | ||||||
|  | |||||||
| @ -423,7 +423,7 @@ public class NMS_v1_9_R1 implements NMSInterface { | |||||||
| 
 | 
 | ||||||
| 	@Override | 	@Override | ||||||
| 	public NBTTagCompound getItemNBT(ItemStack itemStack) { | 	public NBTTagCompound getItemNBT(ItemStack itemStack) { | ||||||
| 		if (itemStack.getType() == Material.AIR) | 		if (itemStack == null || itemStack.getType() == Material.AIR) | ||||||
| 			return null; | 			return null; | ||||||
| 		NBTTagCompound itemNBT = CraftItemStack.asNMSCopy(itemStack).getTag(); | 		NBTTagCompound itemNBT = CraftItemStack.asNMSCopy(itemStack).getTag(); | ||||||
| 		if (String.valueOf(itemNBT).equals("{}")) | 		if (String.valueOf(itemNBT).equals("{}")) | ||||||
|  | |||||||
		Loading…
	
		Reference in New Issue
	
	Block a user
	 TheBukor
						TheBukor