1.13 & 1.14 Update, removal of old stuff
1.13 & 1.14 Update, removed worldedit, nbt, vanishnopacket stuff and old version stuff
This commit is contained in:
		
							parent
							
								
									bf5e005a80
								
							
						
					
					
						commit
						bf9514c322
					
				| @ -1,49 +0,0 @@ | ||||
| package me.TheBukor.SkStuff.conditions; | ||||
| 
 | ||||
| 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.bukkit.WorldEditPlugin; | ||||
| 
 | ||||
| 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 debug) { | ||||
| 		return "if WorldEdit selection of " + player.toString(e, debug) + (isNegated() ? " doesn't contain " : " contains ") + loc.toString(e, debug); | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public boolean check(final Event e) { | ||||
| 		final 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()); | ||||
| 	} | ||||
| } | ||||
| @ -1,52 +0,0 @@ | ||||
| package me.TheBukor.SkStuff.effects; | ||||
| 
 | ||||
| import javax.annotation.Nullable; | ||||
| 
 | ||||
| import org.bukkit.Location; | ||||
| import org.bukkit.event.Event; | ||||
| 
 | ||||
| import com.sk89q.worldedit.EditSession; | ||||
| import com.sk89q.worldedit.MaxChangedBlocksException; | ||||
| import com.sk89q.worldedit.WorldEditException; | ||||
| import com.sk89q.worldedit.bukkit.BukkitUtil; | ||||
| 
 | ||||
| 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 EffDrainLiquid extends Effect { | ||||
| 	private Expression<Location> location; | ||||
| 	private Expression<Double> radius; | ||||
| 	private Expression<EditSession> editSession; | ||||
| 
 | ||||
| 	@SuppressWarnings("unchecked") | ||||
| 	@Override | ||||
| 	public boolean init(Expression<?>[] expr, int matchedPattern, Kleenean arg2, ParseResult result) { | ||||
| 		location = (Expression<Location>) expr[0]; | ||||
| 		radius = (Expression<Double>) expr[1]; | ||||
| 		editSession = (Expression<EditSession>) expr[2]; | ||||
| 		return true; | ||||
| 	} | ||||
| 	@Override | ||||
| 	public String toString(@Nullable Event e, boolean debug) { | ||||
| 		return "drain liquids at " + location.toString(e, debug) + " in a radius of " + radius.toString(e, debug); | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	protected void execute(Event e) { | ||||
| 		Location loc = location.getSingle(e); | ||||
| 		Double rad = radius.getSingle(e); | ||||
| 		EditSession session = editSession.getSingle(e); | ||||
| 		if (session == null) return; | ||||
| 		try { | ||||
| 			session.drainArea(BukkitUtil.toVector(loc), rad); | ||||
| 			session.flushQueue(); | ||||
| 		} catch (WorldEditException ex) { | ||||
| 			if (ex instanceof MaxChangedBlocksException) | ||||
| 				return; | ||||
| 			else | ||||
| 				ex.printStackTrace(); | ||||
| 		} | ||||
| 	} | ||||
| } | ||||
| @ -1,70 +0,0 @@ | ||||
| package me.TheBukor.SkStuff.effects; | ||||
| 
 | ||||
| import javax.annotation.Nullable; | ||||
| 
 | ||||
| import org.bukkit.Location; | ||||
| import org.bukkit.event.Event; | ||||
| import org.bukkit.inventory.ItemStack; | ||||
| 
 | ||||
| import com.sk89q.worldedit.EditSession; | ||||
| import com.sk89q.worldedit.MaxChangedBlocksException; | ||||
| import com.sk89q.worldedit.blocks.BaseBlock; | ||||
| import com.sk89q.worldedit.bukkit.BukkitUtil; | ||||
| import com.sk89q.worldedit.function.pattern.BlockPattern; | ||||
| import com.sk89q.worldedit.function.pattern.Patterns; | ||||
| import com.sk89q.worldedit.function.pattern.RandomPattern; | ||||
| 
 | ||||
| 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 EffDrawLineWE extends Effect { | ||||
| 	private Expression<Location> location1; | ||||
| 	private Expression<Location> location2; | ||||
| 	private Expression<EditSession> editSession; | ||||
| 	private Expression<ItemStack> blockList; | ||||
| 	private Expression<Double> thickness; | ||||
| 	private boolean filled = true; | ||||
| 
 | ||||
| 	@SuppressWarnings("unchecked") | ||||
| 	@Override | ||||
| 	public boolean init(Expression<?>[] expr, int matchedPattern, Kleenean arg2, ParseResult result) { | ||||
| 		location1 = (Expression<Location>) expr[0]; | ||||
| 		location2 = (Expression<Location>) expr[1]; | ||||
| 		editSession = (Expression<EditSession>) expr[2]; | ||||
| 		blockList = (Expression<ItemStack>) expr[3]; | ||||
| 		thickness = (Expression<Double>) expr[4]; | ||||
| 		if (result.mark == 1) | ||||
| 			filled = false; | ||||
| 		return true; | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public String toString(@Nullable Event e, boolean debug) { | ||||
| 		return "draw a line from " + location1.toString(e, debug) + " to " + location2.toString(e, debug) + " using an edit session with " + blockList.toString(e, debug) + " and thickness " + thickness.toString(e, debug); | ||||
| 	} | ||||
| 
 | ||||
| 	@SuppressWarnings("deprecation") | ||||
| 	@Override | ||||
| 	protected void execute(Event e) { | ||||
| 		Location pos1 = location1.getSingle(e); | ||||
| 		Location pos2 = location2.getSingle(e); | ||||
| 		EditSession session = editSession.getSingle(e); | ||||
| 		ItemStack[] blocks = blockList.getAll(e); | ||||
| 		Double thick = thickness.getSingle(e); | ||||
| 		RandomPattern random = new RandomPattern(); | ||||
| 		if (session == null) return; | ||||
| 		for (ItemStack b : blocks) { | ||||
| 			if (b.getType().isBlock()) { | ||||
| 				random.add(new BlockPattern(new BaseBlock(b.getTypeId(), b.getDurability())), 50); | ||||
| 			} | ||||
| 		} | ||||
| 		try { | ||||
| 			session.drawLine(Patterns.wrap(random), BukkitUtil.toVector(pos1), BukkitUtil.toVector(pos2), thick, filled); | ||||
| 			session.flushQueue(); | ||||
| 		} catch (MaxChangedBlocksException ex) { | ||||
| 			return; | ||||
| 		} | ||||
| 	} | ||||
| } | ||||
| @ -1,76 +0,0 @@ | ||||
| package me.TheBukor.SkStuff.effects; | ||||
| 
 | ||||
| import javax.annotation.Nullable; | ||||
| 
 | ||||
| import org.bukkit.Location; | ||||
| import org.bukkit.event.Event; | ||||
| import org.bukkit.inventory.ItemStack; | ||||
| 
 | ||||
| import com.sk89q.worldedit.EditSession; | ||||
| import com.sk89q.worldedit.MaxChangedBlocksException; | ||||
| import com.sk89q.worldedit.WorldEditException; | ||||
| import com.sk89q.worldedit.blocks.BaseBlock; | ||||
| import com.sk89q.worldedit.bukkit.BukkitUtil; | ||||
| import com.sk89q.worldedit.function.pattern.BlockPattern; | ||||
| import com.sk89q.worldedit.function.pattern.Patterns; | ||||
| import com.sk89q.worldedit.function.pattern.RandomPattern; | ||||
| 
 | ||||
| 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 EffMakeCylinder extends Effect { | ||||
| 	private Expression<Location> location; | ||||
| 	private Expression<Double> radius1; | ||||
| 	private Expression<Double> radius2; | ||||
| 	private Expression<Integer> height; | ||||
| 	private Expression<EditSession> editSession; | ||||
| 	private Expression<ItemStack> blockList; | ||||
| 	private boolean filled = true; | ||||
| 
 | ||||
| 	@SuppressWarnings("unchecked") | ||||
| 	@Override | ||||
| 	public boolean init(Expression<?>[] expr, int matchedPattern, Kleenean arg2, ParseResult result) { | ||||
| 		location = (Expression<Location>) expr[0]; | ||||
| 		radius1 = (Expression<Double>) expr[1]; | ||||
| 		height = (Expression<Integer>) expr[2]; | ||||
| 		radius2 = (Expression<Double>) expr[3]; | ||||
| 		editSession = (Expression<EditSession>) expr[4]; | ||||
| 		blockList = (Expression<ItemStack>) expr[5]; | ||||
| 		if (result.mark == 1) | ||||
| 			filled = false; | ||||
| 		return true; | ||||
| 	} | ||||
| 	@Override | ||||
| 	public String toString(@Nullable Event e, boolean debug) { | ||||
| 		return "create a cylinder at " + location.toString(e, debug) + " with a radius of " + radius1.toString(e, debug) + " " + height.toString(e, debug) + " " + radius2.toString(e, debug) + " using an edit session with " + blockList.toString(e, debug); | ||||
| 	} | ||||
| 
 | ||||
| 	@SuppressWarnings("deprecation") | ||||
| 	@Override | ||||
| 	protected void execute(Event e) { | ||||
| 		Location loc = location.getSingle(e); | ||||
| 		Double rad1 = radius1.getSingle(e); | ||||
| 		Integer h = height.getSingle(e); | ||||
| 		Double rad2 = radius2.getSingle(e); | ||||
| 		EditSession session = editSession.getSingle(e); | ||||
| 		ItemStack[] blocks = blockList.getAll(e); | ||||
| 		RandomPattern random = new RandomPattern(); | ||||
| 		if (session == null) return; | ||||
| 		for (ItemStack b : blocks) { | ||||
| 			if (b.getType().isBlock()) { | ||||
| 				random.add(new BlockPattern(new BaseBlock(b.getTypeId(), b.getDurability())), 50); | ||||
| 			} | ||||
| 		} | ||||
| 		try { | ||||
| 			session.makeCylinder(BukkitUtil.toVector(loc), Patterns.wrap(random), rad1, rad2, h, filled); | ||||
| 			session.flushQueue(); | ||||
| 		} catch (WorldEditException ex) { | ||||
| 			if (ex instanceof MaxChangedBlocksException) | ||||
| 				return; | ||||
| 			else | ||||
| 				ex.printStackTrace(); | ||||
| 		} | ||||
| 	} | ||||
| } | ||||
| @ -1,70 +0,0 @@ | ||||
| package me.TheBukor.SkStuff.effects; | ||||
| 
 | ||||
| import javax.annotation.Nullable; | ||||
| 
 | ||||
| import org.bukkit.Location; | ||||
| import org.bukkit.event.Event; | ||||
| import org.bukkit.inventory.ItemStack; | ||||
| 
 | ||||
| import com.sk89q.worldedit.EditSession; | ||||
| import com.sk89q.worldedit.MaxChangedBlocksException; | ||||
| import com.sk89q.worldedit.WorldEditException; | ||||
| import com.sk89q.worldedit.blocks.BaseBlock; | ||||
| import com.sk89q.worldedit.bukkit.BukkitUtil; | ||||
| import com.sk89q.worldedit.function.pattern.BlockPattern; | ||||
| import com.sk89q.worldedit.function.pattern.Patterns; | ||||
| import com.sk89q.worldedit.function.pattern.RandomPattern; | ||||
| 
 | ||||
| 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 EffMakePyramid extends Effect { | ||||
| 	private Expression<Location> location; | ||||
| 	private Expression<Integer> radius; | ||||
| 	private Expression<EditSession> editSession; | ||||
| 	private Expression<ItemStack> blockList; | ||||
| 	private boolean filled = true; | ||||
| 
 | ||||
| 	@SuppressWarnings("unchecked") | ||||
| 	@Override | ||||
| 	public boolean init(Expression<?>[] expr, int matchedPattern, Kleenean arg2, ParseResult result) { | ||||
| 		location = (Expression<Location>) expr[0]; | ||||
| 		radius = (Expression<Integer>) expr[1]; | ||||
| 		editSession = (Expression<EditSession>) expr[2]; | ||||
| 		blockList = (Expression<ItemStack>) expr[3]; | ||||
| 		if (result.mark == 1) | ||||
| 			filled = false; | ||||
| 		return true; | ||||
| 	} | ||||
| 	@Override | ||||
| 	public String toString(@Nullable Event e, boolean debug) { | ||||
| 		return "create a pyramid at " + location.toString(e, debug) + " with a radius of " + radius.toString(e, debug) + " using an edit session with " + blockList.toString(e, debug); | ||||
| 	} | ||||
| 
 | ||||
| 	@SuppressWarnings("deprecation") | ||||
| 	@Override | ||||
| 	protected void execute(Event e) { | ||||
| 		Location loc = location.getSingle(e); | ||||
| 		Integer rad = radius.getSingle(e); | ||||
| 		EditSession session = editSession.getSingle(e); | ||||
| 		ItemStack[] blocks = blockList.getAll(e); | ||||
| 		RandomPattern random = new RandomPattern(); | ||||
| 		if (session == null) return; | ||||
| 		for (ItemStack b : blocks) { | ||||
| 			if (b.getType().isBlock()) { | ||||
| 				random.add(new BlockPattern(new BaseBlock(b.getTypeId(), b.getDurability())), 50); | ||||
| 			} | ||||
| 		} | ||||
| 		try { | ||||
| 			session.makePyramid(BukkitUtil.toVector(loc), Patterns.wrap(random), rad, filled); | ||||
| 			session.flushQueue(); | ||||
| 		} catch (WorldEditException ex) { | ||||
| 			if (ex instanceof MaxChangedBlocksException) | ||||
| 				return; | ||||
| 			else | ||||
| 				ex.printStackTrace(); | ||||
| 		} | ||||
| 	} | ||||
| } | ||||
| @ -1,76 +0,0 @@ | ||||
| package me.TheBukor.SkStuff.effects; | ||||
| 
 | ||||
| import javax.annotation.Nullable; | ||||
| 
 | ||||
| import org.bukkit.Location; | ||||
| import org.bukkit.event.Event; | ||||
| import org.bukkit.inventory.ItemStack; | ||||
| 
 | ||||
| import com.sk89q.worldedit.EditSession; | ||||
| import com.sk89q.worldedit.MaxChangedBlocksException; | ||||
| import com.sk89q.worldedit.WorldEditException; | ||||
| import com.sk89q.worldedit.blocks.BaseBlock; | ||||
| import com.sk89q.worldedit.bukkit.BukkitUtil; | ||||
| import com.sk89q.worldedit.function.pattern.BlockPattern; | ||||
| import com.sk89q.worldedit.function.pattern.Patterns; | ||||
| import com.sk89q.worldedit.function.pattern.RandomPattern; | ||||
| 
 | ||||
| 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 EffMakeSphere extends Effect { | ||||
| 	private Expression<Location> location; | ||||
| 	private Expression<Double> radius1; | ||||
| 	private Expression<Double> radius2; | ||||
| 	private Expression<Double> radius3; | ||||
| 	private Expression<EditSession> editSession; | ||||
| 	private Expression<ItemStack> blockList; | ||||
| 	private boolean filled = true; | ||||
| 
 | ||||
| 	@SuppressWarnings("unchecked") | ||||
| 	@Override | ||||
| 	public boolean init(Expression<?>[] expr, int matchedPattern, Kleenean arg2, ParseResult result) { | ||||
| 		location = (Expression<Location>) expr[0]; | ||||
| 		radius1 = (Expression<Double>) expr[1]; | ||||
| 		radius2 = (Expression<Double>) expr[2]; | ||||
| 		radius3 = (Expression<Double>) expr[3]; | ||||
| 		editSession = (Expression<EditSession>) expr[4]; | ||||
| 		blockList = (Expression<ItemStack>) expr[5]; | ||||
| 		if (result.mark == 1) | ||||
| 			filled = false; | ||||
| 		return true; | ||||
| 	} | ||||
| 	@Override | ||||
| 	public String toString(@Nullable Event e, boolean debug) { | ||||
| 		return "create a sphere centered at " + location.toString(e, debug) + " with a radius of " + radius1.toString(e, debug) + " " + radius2.toString(e, debug) + " " + radius3.toString(e, debug) + " using an edit session with " + blockList.toString(e, debug); | ||||
| 	} | ||||
| 
 | ||||
| 	@SuppressWarnings("deprecation") | ||||
| 	@Override | ||||
| 	protected void execute(Event e) { | ||||
| 		Location loc = location.getSingle(e); | ||||
| 		Double rad1 = radius1.getSingle(e); | ||||
| 		Double rad2 = radius2.getSingle(e); | ||||
| 		Double rad3 = radius3.getSingle(e); | ||||
| 		EditSession session = editSession.getSingle(e); | ||||
| 		ItemStack[] blocks = blockList.getAll(e); | ||||
| 		RandomPattern random = new RandomPattern(); | ||||
| 		if (session == null) return; | ||||
| 		for (ItemStack b : blocks) { | ||||
| 			if (b.getType().isBlock()) { | ||||
| 				random.add(new BlockPattern(new BaseBlock(b.getTypeId(), b.getDurability())), 50); | ||||
| 			} | ||||
| 		} | ||||
| 		try { | ||||
| 			session.makeSphere(BukkitUtil.toVector(loc), Patterns.wrap(random), rad1, rad2, rad3, filled); | ||||
| 			session.flushQueue(); | ||||
| 		} catch (WorldEditException ex) { | ||||
| 			if (ex instanceof MaxChangedBlocksException) | ||||
| 				return; | ||||
| 			else | ||||
| 				ex.printStackTrace(); | ||||
| 		} | ||||
| 	} | ||||
| } | ||||
| @ -1,69 +0,0 @@ | ||||
| package me.TheBukor.SkStuff.effects; | ||||
| 
 | ||||
| import javax.annotation.Nullable; | ||||
| 
 | ||||
| import org.bukkit.Location; | ||||
| import org.bukkit.event.Event; | ||||
| import org.bukkit.inventory.ItemStack; | ||||
| 
 | ||||
| import com.sk89q.worldedit.EditSession; | ||||
| import com.sk89q.worldedit.MaxChangedBlocksException; | ||||
| import com.sk89q.worldedit.WorldEditException; | ||||
| import com.sk89q.worldedit.blocks.BaseBlock; | ||||
| import com.sk89q.worldedit.bukkit.BukkitUtil; | ||||
| import com.sk89q.worldedit.function.pattern.BlockPattern; | ||||
| import com.sk89q.worldedit.function.pattern.Patterns; | ||||
| import com.sk89q.worldedit.function.pattern.RandomPattern; | ||||
| import com.sk89q.worldedit.regions.CuboidRegion; | ||||
| import com.sk89q.worldedit.world.World; | ||||
| 
 | ||||
| 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 EffMakeWalls extends Effect { | ||||
| 	private Expression<Location> location1; | ||||
| 	private Expression<Location> location2; | ||||
| 	private Expression<EditSession> editSession; | ||||
| 	private Expression<ItemStack> blockList; | ||||
| 
 | ||||
| 	@SuppressWarnings("unchecked") | ||||
| 	@Override | ||||
| 	public boolean init(Expression<?>[] expr, int matchedPattern, Kleenean arg2, ParseResult result) { | ||||
| 		location1 = (Expression<Location>) expr[0]; | ||||
| 		location2 = (Expression<Location>) expr[1]; | ||||
| 		editSession = (Expression<EditSession>) expr[2]; | ||||
| 		blockList = (Expression<ItemStack>) expr[3]; | ||||
| 		return true; | ||||
| 	} | ||||
| 	@Override | ||||
| 	public String toString(@Nullable Event e, boolean debug) { | ||||
| 		return "make walls from " + location1.toString(e, debug) + " to " + location2.toString(e, debug) + " using an edit session with " + blockList.toString(e, debug); | ||||
| 	} | ||||
| 
 | ||||
| 	@SuppressWarnings("deprecation") | ||||
| 	@Override | ||||
| 	protected void execute(Event e) { | ||||
| 		Location pos1 = location1.getSingle(e); | ||||
| 		Location pos2 = location2.getSingle(e); | ||||
| 		EditSession session = editSession.getSingle(e); | ||||
| 		ItemStack[] blocks = blockList.getAll(e); | ||||
| 		RandomPattern random = new RandomPattern(); | ||||
| 		if (session == null) return; | ||||
| 		for (ItemStack b : blocks) { | ||||
| 			if (b.getType().isBlock()) { | ||||
| 				random.add(new BlockPattern(new BaseBlock(b.getTypeId(), b.getDurability())), 50); | ||||
| 			} | ||||
| 		} | ||||
| 		try { | ||||
| 			session.makeWalls(new CuboidRegion((World) BukkitUtil.getLocalWorld(pos1.getWorld()), BukkitUtil.toVector(pos1), BukkitUtil.toVector(pos2)), Patterns.wrap(random)); | ||||
| 			session.flushQueue(); | ||||
| 		} catch (WorldEditException ex) { | ||||
| 			if (ex instanceof MaxChangedBlocksException) | ||||
| 				return; | ||||
| 			else | ||||
| 				ex.printStackTrace(); | ||||
| 		} | ||||
| 	} | ||||
| } | ||||
| @ -1,54 +0,0 @@ | ||||
| package me.TheBukor.SkStuff.effects; | ||||
| 
 | ||||
| import javax.annotation.Nullable; | ||||
| 
 | ||||
| import org.bukkit.Location; | ||||
| import org.bukkit.event.Event; | ||||
| 
 | ||||
| import com.sk89q.worldedit.EditSession; | ||||
| import com.sk89q.worldedit.MaxChangedBlocksException; | ||||
| import com.sk89q.worldedit.WorldEditException; | ||||
| import com.sk89q.worldedit.bukkit.BukkitUtil; | ||||
| import com.sk89q.worldedit.regions.CuboidRegion; | ||||
| 
 | ||||
| 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 EffNaturalize extends Effect { | ||||
| 	private Expression<Location> location1; | ||||
| 	private Expression<Location> location2; | ||||
| 	private Expression<EditSession> editSession; | ||||
| 
 | ||||
| 	@SuppressWarnings("unchecked") | ||||
| 	@Override | ||||
| 	public boolean init(Expression<?>[] expr, int matchedPattern, Kleenean arg2, ParseResult result) { | ||||
| 		location1 = (Expression<Location>) expr[0]; | ||||
| 		location2 = (Expression<Location>) expr[1]; | ||||
| 		editSession = (Expression<EditSession>) expr[2]; | ||||
| 		return true; | ||||
| 	} | ||||
| 	@Override | ||||
| 	public String toString(@Nullable Event e, boolean debug) { | ||||
| 		return "naturalize all blocks from " + location1.toString(e, debug) + " to " + location2.toString(e, debug); | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	protected void execute(Event e) { | ||||
| 		Location pos1 = location1.getSingle(e); | ||||
| 		Location pos2 = location2.getSingle(e); | ||||
| 		EditSession session = editSession.getSingle(e); | ||||
| 		if (session == null) return; | ||||
| 		CuboidRegion region = new CuboidRegion(BukkitUtil.toVector(pos1), BukkitUtil.toVector(pos2)); | ||||
| 		try { | ||||
| 			session.naturalizeCuboidBlocks(region); | ||||
| 			session.flushQueue(); | ||||
| 		} catch (WorldEditException ex) { | ||||
| 			if (ex instanceof MaxChangedBlocksException) | ||||
| 				return; | ||||
| 			else | ||||
| 				ex.printStackTrace(); | ||||
| 		} | ||||
| 	} | ||||
| } | ||||
| @ -1,65 +0,0 @@ | ||||
| package me.TheBukor.SkStuff.effects; | ||||
| 
 | ||||
| import java.io.File; | ||||
| import java.io.IOException; | ||||
| 
 | ||||
| import javax.annotation.Nullable; | ||||
| 
 | ||||
| import org.bukkit.Location; | ||||
| import org.bukkit.event.Event; | ||||
| 
 | ||||
| import com.sk89q.worldedit.EditSession; | ||||
| import com.sk89q.worldedit.MaxChangedBlocksException; | ||||
| import com.sk89q.worldedit.Vector; | ||||
| import com.sk89q.worldedit.bukkit.BukkitUtil; | ||||
| import com.sk89q.worldedit.data.DataException; | ||||
| import com.sk89q.worldedit.schematic.SchematicFormat; | ||||
| 
 | ||||
| import ch.njol.skript.lang.Effect; | ||||
| import ch.njol.skript.lang.Expression; | ||||
| import ch.njol.skript.lang.SkriptParser.ParseResult; | ||||
| import ch.njol.util.Kleenean; | ||||
| 
 | ||||
| @SuppressWarnings("deprecation") | ||||
| public class EffPasteSchematic extends Effect { | ||||
| 	private Expression<String> schematic; | ||||
| 	private Expression<Location> location; | ||||
| 	private Expression<EditSession> editSession; | ||||
| 
 | ||||
| 	private int mark; | ||||
| 
 | ||||
| 	@SuppressWarnings("unchecked") | ||||
| 	@Override | ||||
| 	public boolean init(Expression<?>[] expr, int matchedPattern, Kleenean arg2, ParseResult result) { | ||||
| 		mark = result.mark; | ||||
| 		schematic = (Expression<String>) expr[0]; | ||||
| 		location = (Expression<Location>) expr[1]; | ||||
| 		editSession = (Expression<EditSession>) expr[2]; | ||||
| 		return true; | ||||
| 	} | ||||
| 	@Override | ||||
| 	public String toString(@Nullable Event e, boolean debug) { | ||||
| 		return "paste schematic " + schematic.toString(e, debug) + " at " + location.toString(e, debug) + " using edit session" + (mark == 1 ? " ignoring air" : ""); | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	protected void execute(Event e) { | ||||
| 		String schem = schematic.getSingle(e); | ||||
| 		Location loc = location.getSingle(e); | ||||
| 		EditSession session = editSession.getSingle(e); | ||||
| 		Vector origin = BukkitUtil.toVector(loc); | ||||
| 		boolean noAir = false; | ||||
| 		if (mark == 1) | ||||
| 			noAir = true; | ||||
| 		File schemFile = new File((schem.endsWith(".schematic") ? schem : (schem + ".schematic"))); | ||||
| 		if (!schemFile.exists() || session == null) | ||||
| 			return; | ||||
| 		try { | ||||
| 			SchematicFormat.getFormat(schemFile).load(schemFile).paste(session, origin, noAir); | ||||
| 		} catch (MaxChangedBlocksException | DataException | IOException ex) { | ||||
| 			if (ex instanceof MaxChangedBlocksException) | ||||
| 				return; | ||||
| 			ex.printStackTrace(); | ||||
| 		} | ||||
| 	} | ||||
| } | ||||
| @ -1,42 +0,0 @@ | ||||
| package me.TheBukor.SkStuff.effects; | ||||
| 
 | ||||
| import javax.annotation.Nullable; | ||||
| 
 | ||||
| import org.bukkit.Bukkit; | ||||
| import org.bukkit.entity.Player; | ||||
| import org.bukkit.event.Event; | ||||
| 
 | ||||
| import com.sk89q.worldedit.EditSession; | ||||
| import com.sk89q.worldedit.bukkit.WorldEditPlugin; | ||||
| 
 | ||||
| import ch.njol.skript.lang.Effect; | ||||
| import ch.njol.skript.lang.Expression; | ||||
| import ch.njol.skript.lang.SkriptParser.ParseResult; | ||||
| import ch.njol.util.Kleenean; | ||||
| 
 | ||||
| public class EffRememberChanges extends Effect { | ||||
| 	private Expression<Player> player; | ||||
| 	private Expression<EditSession> editSession; | ||||
| 
 | ||||
| 	@SuppressWarnings("unchecked") | ||||
| 	@Override | ||||
| 	public boolean init(Expression<?>[] expr, int matchedPattern, Kleenean arg2, ParseResult arg3) { | ||||
| 		player = (Expression<Player>) expr[0]; | ||||
| 		editSession = (Expression<EditSession>) expr[1]; | ||||
| 		return true; | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public String toString(@Nullable Event e, boolean debug) { | ||||
| 		return "make " + player.toString(e, debug) + " remember changes from edit session"; | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	protected void execute(Event e) { | ||||
| 		WorldEditPlugin we = (WorldEditPlugin) Bukkit.getPluginManager().getPlugin("WorldEdit"); | ||||
| 		Player p = player.getSingle(e); | ||||
| 		EditSession session = editSession.getSingle(e); | ||||
| 		if (we.getSession(p) == null) return; | ||||
| 		we.getSession(p).remember(session); | ||||
| 	} | ||||
| } | ||||
| @ -1,81 +0,0 @@ | ||||
| package me.TheBukor.SkStuff.effects; | ||||
| 
 | ||||
| import java.util.HashSet; | ||||
| import java.util.Set; | ||||
| 
 | ||||
| import javax.annotation.Nullable; | ||||
| 
 | ||||
| import org.bukkit.Location; | ||||
| import org.bukkit.event.Event; | ||||
| import org.bukkit.inventory.ItemStack; | ||||
| 
 | ||||
| import com.sk89q.worldedit.EditSession; | ||||
| import com.sk89q.worldedit.MaxChangedBlocksException; | ||||
| import com.sk89q.worldedit.WorldEditException; | ||||
| import com.sk89q.worldedit.blocks.BaseBlock; | ||||
| import com.sk89q.worldedit.bukkit.BukkitUtil; | ||||
| import com.sk89q.worldedit.function.pattern.BlockPattern; | ||||
| import com.sk89q.worldedit.function.pattern.Patterns; | ||||
| import com.sk89q.worldedit.function.pattern.RandomPattern; | ||||
| import com.sk89q.worldedit.regions.CuboidRegion; | ||||
| import com.sk89q.worldedit.world.World; | ||||
| 
 | ||||
| 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 EffReplaceBlocksWE extends Effect { | ||||
| 	private Expression<ItemStack> blockList1; | ||||
| 	private Expression<Location> location1; | ||||
| 	private Expression<Location> location2; | ||||
| 	private Expression<ItemStack> blockList2; | ||||
| 	private Expression<EditSession> editSession; | ||||
| 
 | ||||
| 	@SuppressWarnings("unchecked") | ||||
| 	@Override | ||||
| 	public boolean init(Expression<?>[] expr, int matchedPattern, Kleenean arg2, ParseResult result) { | ||||
| 		blockList1 = (Expression<ItemStack>) expr[0]; | ||||
| 		location1 = (Expression<Location>) expr[1]; | ||||
| 		location2 = (Expression<Location>) expr[2]; | ||||
| 		blockList2 = (Expression<ItemStack>) expr[3]; | ||||
| 		editSession = (Expression<EditSession>) expr[4]; | ||||
| 		return true; | ||||
| 	} | ||||
| 	@Override | ||||
| 	public String toString(@Nullable Event e, boolean debug) { | ||||
| 		return "replace all " + blockList1.toString(e, debug) + " from " + location1.toString(e, debug) + " to " + location2.toString(e, debug) + " with " + blockList1.toString(e, debug) + " using an edit session"; | ||||
| 	} | ||||
| 
 | ||||
| 	@SuppressWarnings({ "deprecation" }) | ||||
| 	@Override | ||||
| 	protected void execute(Event e) { | ||||
| 		Location pos1 = location1.getSingle(e); | ||||
| 		Location pos2 = location2.getSingle(e); | ||||
| 		EditSession session = editSession.getSingle(e); | ||||
| 		ItemStack[] blocks = blockList1.getAll(e); | ||||
| 		ItemStack[] blocksToPlace = blockList2.getAll(e); | ||||
| 		RandomPattern random = new RandomPattern(); | ||||
| 		Set<BaseBlock> blocksToReplace = new HashSet<BaseBlock>(); | ||||
| 		if (session == null) return; | ||||
| 		for (ItemStack b : blocks) { | ||||
| 			if (b.getType().isBlock()) { | ||||
| 				blocksToReplace.add(new BaseBlock(b.getTypeId(), b.getDurability())); | ||||
| 			} | ||||
| 		} | ||||
| 		for (ItemStack b : blocksToPlace) { | ||||
| 			if (b.getType().isBlock()) { | ||||
| 				random.add(new BlockPattern(new BaseBlock(b.getTypeId(), b.getDurability())), 50); | ||||
| 			} | ||||
| 		} | ||||
| 		try { | ||||
| 			session.replaceBlocks(new CuboidRegion((World) BukkitUtil.getLocalWorld(pos1.getWorld()), BukkitUtil.toVector(pos1), BukkitUtil.toVector(pos2)), blocksToReplace, Patterns.wrap(random)); | ||||
| 			session.flushQueue(); | ||||
| 		} catch (WorldEditException ex) { | ||||
| 			if (ex instanceof MaxChangedBlocksException) | ||||
| 				return; | ||||
| 			else | ||||
| 				ex.printStackTrace(); | ||||
| 		} | ||||
| 	} | ||||
| } | ||||
| @ -1,69 +0,0 @@ | ||||
| package me.TheBukor.SkStuff.effects; | ||||
| 
 | ||||
| import javax.annotation.Nullable; | ||||
| 
 | ||||
| import org.bukkit.Location; | ||||
| import org.bukkit.event.Event; | ||||
| import org.bukkit.inventory.ItemStack; | ||||
| 
 | ||||
| import com.sk89q.worldedit.EditSession; | ||||
| import com.sk89q.worldedit.MaxChangedBlocksException; | ||||
| import com.sk89q.worldedit.WorldEditException; | ||||
| import com.sk89q.worldedit.blocks.BaseBlock; | ||||
| import com.sk89q.worldedit.bukkit.BukkitUtil; | ||||
| import com.sk89q.worldedit.function.pattern.BlockPattern; | ||||
| import com.sk89q.worldedit.function.pattern.Patterns; | ||||
| import com.sk89q.worldedit.function.pattern.RandomPattern; | ||||
| import com.sk89q.worldedit.regions.CuboidRegion; | ||||
| import com.sk89q.worldedit.world.World; | ||||
| 
 | ||||
| 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 EffSetBlocksWE extends Effect { | ||||
| 	private Expression<Location> location1; | ||||
| 	private Expression<Location> location2; | ||||
| 	private Expression<ItemStack> blockList; | ||||
| 	private Expression<EditSession> editSession; | ||||
| 
 | ||||
| 	@SuppressWarnings("unchecked") | ||||
| 	@Override | ||||
| 	public boolean init(Expression<?>[] expr, int matchedPattern, Kleenean arg2, ParseResult result) { | ||||
| 		location1 = (Expression<Location>) expr[0]; | ||||
| 		location2 = (Expression<Location>) expr[1]; | ||||
| 		blockList = (Expression<ItemStack>) expr[2]; | ||||
| 		editSession = (Expression<EditSession>) expr[3]; | ||||
| 		return true; | ||||
| 	} | ||||
| 	@Override | ||||
| 	public String toString(@Nullable Event e, boolean debug) { | ||||
| 		return "set all blocks from " + location1.toString(e, debug) + " to " + location2.toString(e, debug) + " to " + blockList.toString(e, debug) + " using an edit session"; | ||||
| 	} | ||||
| 
 | ||||
| 	@SuppressWarnings("deprecation") | ||||
| 	@Override | ||||
| 	protected void execute(Event e) { | ||||
| 		Location pos1 = location1.getSingle(e); | ||||
| 		Location pos2 = location2.getSingle(e); | ||||
| 		EditSession session = editSession.getSingle(e); | ||||
| 		ItemStack[] blocks = blockList.getAll(e); | ||||
| 		RandomPattern random = new RandomPattern(); | ||||
| 		if (session == null) return; | ||||
| 		for (ItemStack b : blocks) { | ||||
| 			if (b.getType().isBlock()) { | ||||
| 				random.add(new BlockPattern(new BaseBlock(b.getTypeId(), b.getDurability())), 50); | ||||
| 			} | ||||
| 		} | ||||
| 		try { | ||||
| 			session.setBlocks(new CuboidRegion((World) BukkitUtil.getLocalWorld(pos1.getWorld()), BukkitUtil.toVector(pos1), BukkitUtil.toVector(pos2)), Patterns.wrap(random)); | ||||
| 			session.flushQueue(); | ||||
| 		} catch (WorldEditException ex) { | ||||
| 			if (ex instanceof MaxChangedBlocksException) | ||||
| 				return; | ||||
| 			else | ||||
| 				ex.printStackTrace(); | ||||
| 		} | ||||
| 	} | ||||
| } | ||||
| @ -1,52 +0,0 @@ | ||||
| package me.TheBukor.SkStuff.effects; | ||||
| 
 | ||||
| import javax.annotation.Nullable; | ||||
| 
 | ||||
| import org.bukkit.Location; | ||||
| import org.bukkit.event.Event; | ||||
| 
 | ||||
| import com.sk89q.worldedit.EditSession; | ||||
| import com.sk89q.worldedit.MaxChangedBlocksException; | ||||
| import com.sk89q.worldedit.WorldEditException; | ||||
| import com.sk89q.worldedit.bukkit.BukkitUtil; | ||||
| 
 | ||||
| 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 EffSimulateSnow extends Effect { | ||||
| 	private Expression<Location> location; | ||||
| 	private Expression<Double> radius; | ||||
| 	private Expression<EditSession> editSession; | ||||
| 
 | ||||
| 	@SuppressWarnings("unchecked") | ||||
| 	@Override | ||||
| 	public boolean init(Expression<?>[] expr, int matchedPattern, Kleenean arg2, ParseResult result) { | ||||
| 		location = (Expression<Location>) expr[0]; | ||||
| 		radius = (Expression<Double>) expr[1]; | ||||
| 		editSession = (Expression<EditSession>) expr[2]; | ||||
| 		return true; | ||||
| 	} | ||||
| 	@Override | ||||
| 	public String toString(@Nullable Event e, boolean debug) { | ||||
| 		return "make " + location.toString(e, debug) + " snowy in a radius of " + radius.toString(e, debug); | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	protected void execute(Event e) { | ||||
| 		Location loc = location.getSingle(e); | ||||
| 		Double rad = radius.getSingle(e); | ||||
| 		EditSession session = editSession.getSingle(e); | ||||
| 		if (session == null) return; | ||||
| 		try { | ||||
| 			session.simulateSnow(BukkitUtil.toVector(loc), rad); | ||||
| 			session.flushQueue(); | ||||
| 		} catch (WorldEditException ex) { | ||||
| 			if (ex instanceof MaxChangedBlocksException) | ||||
| 				return; | ||||
| 			else | ||||
| 				ex.printStackTrace(); | ||||
| 		} | ||||
| 	} | ||||
| } | ||||
| @ -1,47 +0,0 @@ | ||||
| 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 debug) { | ||||
| 		return "toggle vanished state of " + player.toString(e, debug) + 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); | ||||
| 		} | ||||
| 	} | ||||
| } | ||||
| @ -1,43 +0,0 @@ | ||||
| package me.TheBukor.SkStuff.effects; | ||||
| 
 | ||||
| import javax.annotation.Nullable; | ||||
| 
 | ||||
| import org.bukkit.event.Event; | ||||
| 
 | ||||
| import com.sk89q.worldedit.EditSession; | ||||
| 
 | ||||
| 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 EffUndoRedoSession extends Effect { | ||||
| 	private Expression<EditSession> editSession; | ||||
| 	private boolean redo = false; | ||||
| 
 | ||||
| 	@SuppressWarnings("unchecked") | ||||
| 	@Override | ||||
| 	public boolean init(Expression<?>[] expr, int matchedPattern, Kleenean arg2, ParseResult result) { | ||||
| 		editSession = (Expression<EditSession>) expr[0]; | ||||
| 		if (result.mark == 1) | ||||
| 			redo = true; | ||||
| 		return true; | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public String toString(@Nullable Event e, boolean debug) { | ||||
| 		return (redo == true ? "redo " : "undo ") + "changes from edit session"; | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	protected void execute(Event e) { | ||||
| 		EditSession session = editSession.getSingle(e); | ||||
| 		if (session == null) return; | ||||
| 		if (redo == false) {  | ||||
| 			session.undo(session); | ||||
| 		} else { | ||||
| 			session.redo(session); | ||||
| 		} | ||||
| 		session.flushQueue(); | ||||
| 	} | ||||
| } | ||||
| @ -1,46 +0,0 @@ | ||||
| package me.TheBukor.SkStuff.events; | ||||
| 
 | ||||
| import org.bukkit.block.Block; | ||||
| import org.bukkit.entity.Player; | ||||
| import org.bukkit.event.Cancellable; | ||||
| import org.bukkit.event.Event; | ||||
| import org.bukkit.event.HandlerList; | ||||
| 
 | ||||
| public class EvtWorldEditChange extends Event implements Cancellable { | ||||
| 	private static Player player; | ||||
| 	private static Block block; | ||||
| 	private boolean cancelled; | ||||
| 	private static final HandlerList handlers = new HandlerList(); | ||||
| 
 | ||||
| 	EvtWorldEditChange(Player player, Block block) { | ||||
| 		EvtWorldEditChange.player = player; | ||||
| 		EvtWorldEditChange.block = block; | ||||
| 		this.cancelled = false; | ||||
| 	} | ||||
| 
 | ||||
| 	public static Player getPlayer() { | ||||
| 		return player; | ||||
| 	} | ||||
| 
 | ||||
| 	public static Block getBlock() { | ||||
| 		return block; | ||||
| 	} | ||||
| 
 | ||||
| 	public HandlerList getHandlers() { | ||||
| 		return handlers; | ||||
| 	} | ||||
| 
 | ||||
| 	public static HandlerList getHandlerList() { | ||||
| 		return handlers; | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public boolean isCancelled() { | ||||
| 		return this.cancelled; | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public void setCancelled(boolean bool) { | ||||
| 		this.cancelled = bool; | ||||
| 	} | ||||
| } | ||||
| @ -1,24 +0,0 @@ | ||||
| package me.TheBukor.SkStuff.events; | ||||
| 
 | ||||
| import com.sk89q.worldedit.WorldEdit; | ||||
| import com.sk89q.worldedit.bukkit.BukkitWorld; | ||||
| import com.sk89q.worldedit.event.extent.EditSessionEvent; | ||||
| import com.sk89q.worldedit.extension.platform.Actor; | ||||
| import com.sk89q.worldedit.util.eventbus.Subscribe; | ||||
| import com.sk89q.worldedit.world.World; | ||||
| 
 | ||||
| public class WorldEditChangeHandler { | ||||
| 	 | ||||
| 	public WorldEditChangeHandler() { | ||||
| 		WorldEdit.getInstance().getEventBus().register(this); | ||||
| 	} | ||||
| 	 | ||||
|     @Subscribe | ||||
|     public void wrapForLogging(EditSessionEvent event) { | ||||
|         Actor actor = event.getActor(); | ||||
|         World world = event.getWorld(); | ||||
|         if (actor != null && world instanceof BukkitWorld) { | ||||
|             event.setExtent(new WorldEditExtent(actor, world, event.getExtent())); | ||||
|         } | ||||
|     } | ||||
| } | ||||
| @ -1,34 +0,0 @@ | ||||
| package me.TheBukor.SkStuff.events; | ||||
| 
 | ||||
| import org.bukkit.Bukkit; | ||||
| import org.bukkit.World; | ||||
| import org.bukkit.block.Block; | ||||
| import org.bukkit.entity.Player; | ||||
| 
 | ||||
| import com.sk89q.worldedit.Vector; | ||||
| import com.sk89q.worldedit.blocks.BaseBlock; | ||||
| import com.sk89q.worldedit.bukkit.BukkitUtil; | ||||
| import com.sk89q.worldedit.bukkit.BukkitWorld; | ||||
| import com.sk89q.worldedit.extension.platform.Actor; | ||||
| import com.sk89q.worldedit.extent.Extent; | ||||
| import com.sk89q.worldedit.extent.logging.AbstractLoggingExtent; | ||||
| 
 | ||||
| public class WorldEditExtent extends AbstractLoggingExtent { | ||||
| 
 | ||||
|     private final Actor actor; | ||||
|     private final World world; | ||||
| 
 | ||||
|     public WorldEditExtent(Actor actor, com.sk89q.worldedit.world.World weWorld, Extent extent) { | ||||
|         super(extent); | ||||
|         this.actor = actor; | ||||
|         this.world = ((BukkitWorld) weWorld).getWorld(); | ||||
|     } | ||||
|   | ||||
|     @Override | ||||
|     protected void onBlockChange(final Vector vec, BaseBlock baseBlock) { | ||||
|         final Block b = BukkitUtil.toLocation(world, vec).getBlock(); | ||||
|        	final Player p = Bukkit.getPlayerExact(actor.getName()); | ||||
|        	EvtWorldEditChange event = new EvtWorldEditChange(p, b); | ||||
| 		Bukkit.getPluginManager().callEvent(event); | ||||
|     } | ||||
| } | ||||
| @ -1,46 +0,0 @@ | ||||
| package me.TheBukor.SkStuff.expressions; | ||||
| 
 | ||||
| import javax.annotation.Nullable; | ||||
| 
 | ||||
| import org.bukkit.event.Event; | ||||
| 
 | ||||
| import com.sk89q.worldedit.EditSession; | ||||
| 
 | ||||
| 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 ExprChangedBlocksSession extends SimpleExpression<Integer> { | ||||
| 	private Expression<EditSession> editSession; | ||||
| 	@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) { | ||||
| 		editSession = (Expression<EditSession>) expr[0]; | ||||
| 		return true; | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public String toString(@Nullable Event e, boolean debug) { | ||||
| 		return "the number of changed blocks in an edit session"; | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	@Nullable | ||||
| 	protected Integer[] get(Event e) { | ||||
| 		EditSession session = editSession.getSingle(e); | ||||
| 		if (session == null) | ||||
| 			return null; | ||||
| 		return new Integer[] { session.getBlockChangeCount() }; | ||||
| 	} | ||||
| } | ||||
| @ -1,162 +0,0 @@ | ||||
| package me.TheBukor.SkStuff.expressions; | ||||
| 
 | ||||
| import java.util.ArrayList; | ||||
| import java.util.Arrays; | ||||
| import java.util.List; | ||||
| import java.util.Set; | ||||
| 
 | ||||
| import javax.annotation.Nullable; | ||||
| 
 | ||||
| import org.bukkit.Material; | ||||
| import org.bukkit.craftbukkit.v1_8_R3.inventory.CraftItemStack; | ||||
| import org.bukkit.entity.Enderman; | ||||
| 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.util.Kleenean; | ||||
| import ch.njol.util.coll.CollectionUtils; | ||||
| import me.TheBukor.SkStuff.util.ReflectionUtils; | ||||
| 
 | ||||
| public class ExprEndermanBlocks extends SimpleExpression<ItemStack> { | ||||
| 	private Expression<Entity> entity; | ||||
| 
 | ||||
| 	private Class<?> nmsBlockClass = ReflectionUtils.getNMSClass("Block"); | ||||
| 	private Class<?> endermanClass = ReflectionUtils.getNMSClass("EntityEnderman"); | ||||
| 	private Class<?> nmsIBlockData = ReflectionUtils.getNMSClass("IBlockData"); | ||||
| 	private Class<?> nmsItemClass = ReflectionUtils.getNMSClass("ItemStack"); | ||||
| 	private Class<?> craftEntClass = ReflectionUtils.getOBCClass("entity.CraftEntity"); | ||||
| 	private Class<?> craftItemClass = ReflectionUtils.getOBCClass("inventory.CraftItemStack"); | ||||
| 
 | ||||
| 	@Override | ||||
| 	public Class<? extends ItemStack> getReturnType() { | ||||
| 		return ItemStack.class; | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public boolean isSingle() { | ||||
| 		return false; | ||||
| 	} | ||||
| 
 | ||||
| 	@SuppressWarnings("unchecked") | ||||
| 	@Override | ||||
| 	public boolean init(Expression<?>[] expr, int matchedPattern, Kleenean arg2, ParseResult result) { | ||||
| 		entity = (Expression<Entity>) expr[0]; | ||||
| 		return true; | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public String toString(@Nullable Event e, boolean debug) { | ||||
| 		return "blocks that " + entity.toString(e, debug) + " can carry"; | ||||
| 	} | ||||
| 
 | ||||
| 	@SuppressWarnings("unchecked") | ||||
| 	@Override | ||||
| 	@Nullable | ||||
| 	protected ItemStack[] get(Event e) { | ||||
| 		Entity ent = entity.getSingle(e); | ||||
| 		if (ent == null || !(ent instanceof Enderman)) | ||||
| 			return null; | ||||
| 		Object nmsEnt = null; | ||||
| 		try { | ||||
| 			nmsEnt = craftEntClass.cast(ent).getClass().getMethod("getHandle").invoke(ent); | ||||
| 		} catch (Exception ex) { | ||||
| 			ex.printStackTrace(); | ||||
| 		} | ||||
| 		Set<Object> nmsBlocks = (Set<Object>) ReflectionUtils.getField("c", endermanClass, nmsEnt); | ||||
| 		List<ItemStack> items = new ArrayList<ItemStack>(); | ||||
| 		for (Object nmsBlock : nmsBlocks) { | ||||
| 			Object nmsBlockData; | ||||
| 			try { | ||||
| 				nmsBlockData = nmsBlockClass.getMethod("getBlockData").invoke(nmsBlock); | ||||
| 				int dataValue = (int) nmsBlockClass.getMethod("toLegacyData", nmsIBlockData).invoke(nmsBlock, | ||||
| 						nmsBlockData); | ||||
| 				Object nmsItem = nmsItemClass.getConstructor(nmsBlockClass, int.class, int.class).newInstance(nmsBlock, | ||||
| 						1, dataValue); | ||||
| 				ItemStack bukkitItem = (ItemStack) craftItemClass.getMethod("asCraftMirror", nmsItemClass).invoke(null, | ||||
| 						nmsItem); | ||||
| 				items.add(bukkitItem); | ||||
| 			} catch (Exception ex) { | ||||
| 				ex.printStackTrace(); | ||||
| 			} | ||||
| 		} | ||||
| 		return Arrays.copyOf(items.toArray(), items.size(), ItemStack[].class); | ||||
| 	} | ||||
| 
 | ||||
| 	@SuppressWarnings({ "unused", "unchecked" }) | ||||
| 	@Override | ||||
| 	public void change(Event e, @Nullable Object[] delta, ChangeMode mode) { | ||||
| 		Entity ent = entity.getSingle(e); | ||||
| 		if (ent == null || !(ent instanceof Enderman)) | ||||
| 			return; | ||||
| 		Object nmsEnt = null; | ||||
| 		try { | ||||
| 			nmsEnt = craftEntClass.cast(ent).getClass().getMethod("getHandle").invoke(ent); | ||||
| 		} catch (Exception ex) { | ||||
| 			ex.printStackTrace(); | ||||
| 		} | ||||
| 		Set<Object> enderBlocks = (Set<Object>) ReflectionUtils.getField("c", endermanClass, nmsEnt); | ||||
| 		if (mode == ChangeMode.ADD || mode == ChangeMode.REMOVE || mode == ChangeMode.SET) { | ||||
| 			ItemStack[] deltaItems = Arrays.copyOf(delta, delta.length, ItemStack[].class); | ||||
| 			if (mode == ChangeMode.SET) { | ||||
| 				enderBlocks.clear(); | ||||
| 			} | ||||
| 			for (ItemStack itemStack : deltaItems) { | ||||
| 				if (itemStack.getType() == Material.AIR || itemStack == null) | ||||
| 					continue; | ||||
| 				Object nmsItemStack = CraftItemStack.asNMSCopy(itemStack); | ||||
| 				Object nmsItem = null; | ||||
| 				try { | ||||
| 					nmsItem = nmsItemStack.getClass().getMethod("getItem").invoke(nmsItemStack); | ||||
| 				} catch (Exception ex) { | ||||
| 					ex.printStackTrace(); | ||||
| 				} | ||||
| 				if (mode == ChangeMode.ADD || mode == ChangeMode.SET) | ||||
| 					enderBlocks.add(nmsItem); | ||||
| 				else //ChangeMode.REMOVE | ||||
| 					enderBlocks.remove(nmsItem); | ||||
| 			} | ||||
| 		} else if (mode == ChangeMode.RESET) { | ||||
| 			ItemStack grass = new ItemStack(Material.GRASS); | ||||
| 			ItemStack dirt = new ItemStack(Material.DIRT); | ||||
| 			ItemStack sand = new ItemStack(Material.SAND); | ||||
| 			ItemStack gravel = new ItemStack(Material.GRAVEL); | ||||
| 			ItemStack dandelion = new ItemStack(Material.YELLOW_FLOWER); | ||||
| 			ItemStack poppy = new ItemStack(Material.RED_ROSE); | ||||
| 			ItemStack brownShroom = new ItemStack(Material.BROWN_MUSHROOM); | ||||
| 			ItemStack redShroom = new ItemStack(Material.RED_MUSHROOM); | ||||
| 			ItemStack tnt = new ItemStack(Material.TNT); | ||||
| 			ItemStack cactus = new ItemStack(Material.CACTUS); | ||||
| 			ItemStack clay = new ItemStack(Material.CLAY); | ||||
| 			ItemStack pumpkin = new ItemStack(Material.PUMPKIN); | ||||
| 			ItemStack melon = new ItemStack(Material.MELON_BLOCK); | ||||
| 			ItemStack mycellium = new ItemStack(Material.MYCEL); | ||||
| 			ItemStack[] defaultItems = new ItemStack[] { grass, dirt, gravel, dandelion, poppy, brownShroom, redShroom, tnt, cactus, clay, pumpkin, melon, mycellium }; | ||||
| 			enderBlocks.clear(); | ||||
| 			for (ItemStack itemStack : defaultItems) { | ||||
| 				Object nmsItemStack = CraftItemStack.asNMSCopy(itemStack); | ||||
| 				Object nmsItem = null; | ||||
| 				try { | ||||
| 					nmsItem = nmsItemStack.getClass().getMethod("getItem").invoke(nmsItemStack); | ||||
| 				} catch (Exception ex) { | ||||
| 					ex.printStackTrace(); | ||||
| 				} | ||||
| 				enderBlocks.add(nmsItem); | ||||
| 			} | ||||
| 		} | ||||
| 	} | ||||
| 
 | ||||
| 	@SuppressWarnings("unchecked") | ||||
| 	@Override | ||||
| 	@Nullable | ||||
| 	public Class<?>[] acceptChange(ChangeMode mode) { | ||||
| 		if (mode == ChangeMode.ADD || mode == ChangeMode.REMOVE || mode == ChangeMode.RESET|| mode == ChangeMode.SET) { | ||||
| 			return CollectionUtils.array(ItemStack[].class); | ||||
| 		} | ||||
| 		return null; | ||||
| 	} | ||||
| } | ||||
| @ -1,93 +0,0 @@ | ||||
| package me.TheBukor.SkStuff.expressions; | ||||
| 
 | ||||
| import java.io.File; | ||||
| 
 | ||||
| import javax.annotation.Nullable; | ||||
| 
 | ||||
| import org.bukkit.event.Event; | ||||
| 
 | ||||
| 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; | ||||
| import ch.njol.util.coll.CollectionUtils; | ||||
| import me.TheBukor.SkStuff.SkStuff; | ||||
| import me.TheBukor.SkStuff.util.ReflectionUtils; | ||||
| 
 | ||||
| public class ExprFileNBT extends SimpleExpression<Object> { | ||||
| 	private Expression<String> input; | ||||
| 
 | ||||
| 	private Class<?> nbtClass = ReflectionUtils.getNMSClass("NBTTagCompound"); | ||||
| 
 | ||||
| 	@Override | ||||
| 	public Class<? extends Object> getReturnType() { | ||||
| 		return nbtClass; | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public boolean isSingle() { | ||||
| 		return true; | ||||
| 	} | ||||
| 
 | ||||
| 	@SuppressWarnings("unchecked") | ||||
| 	@Override | ||||
| 	public boolean init(Expression<?>[] expr, int matchedPattern, Kleenean arg2, ParseResult arg3) { | ||||
| 		input = (Expression<String>) expr[0]; | ||||
| 		return true; | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public String toString(@Nullable Event e, boolean debug) { | ||||
| 		return "the NBT from file " + input.toString(e, debug); | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	@Nullable | ||||
| 	public Object[] get(Event e) { | ||||
| 		String fileName = input.getSingle(e); | ||||
| 		fileName = !fileName.endsWith(".dat") ? fileName + ".dat" : fileName; | ||||
| 		File file = new File(fileName); | ||||
| 		if (!file.exists()) | ||||
| 			return null; | ||||
| 		return new Object[] { SkStuff.getNMSMethods().getFileNBT(file) }; | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public void change(Event e, @Nullable Object[] delta, ChangeMode mode) { | ||||
| 		String fileName = input.getSingle(e); | ||||
| 		fileName = !fileName.endsWith(".dat") ? fileName + ".dat" : fileName; | ||||
| 		File file = new File(fileName); | ||||
| 		if (!file.exists()) | ||||
| 			return; | ||||
| 		Object fileNBT = SkStuff.getNMSMethods().getFileNBT(file); | ||||
| 		if (fileNBT == null) { | ||||
| 			try { | ||||
| 				fileNBT = nbtClass.newInstance(); | ||||
| 			} catch (InstantiationException | IllegalAccessException ex) { | ||||
| 				ex.printStackTrace(); | ||||
| 			} | ||||
| 		} | ||||
| 		if (mode == ChangeMode.ADD) { | ||||
| 			Object parsedNBT = null; | ||||
| 			parsedNBT = SkStuff.getNMSMethods().parseRawNBT((String) delta[0]); | ||||
| 			SkStuff.getNMSMethods().addToCompound(fileNBT, parsedNBT); | ||||
| 			SkStuff.getNMSMethods().setFileNBT(file, fileNBT); | ||||
| 		} else if (mode == ChangeMode.REMOVE) { | ||||
| 			for (Object s : delta) { | ||||
| 				SkStuff.getNMSMethods().removeFromCompound(fileNBT, (String) s); | ||||
| 			} | ||||
| 			SkStuff.getNMSMethods().setFileNBT(file, fileNBT); | ||||
| 		} | ||||
| 	} | ||||
| 
 | ||||
| 	@SuppressWarnings("unchecked") | ||||
| 	@Override | ||||
| 	@Nullable | ||||
| 	public Class<?>[] acceptChange(ChangeMode mode) { | ||||
| 		if (mode == ChangeMode.ADD || mode == ChangeMode.REMOVE) { | ||||
| 			return CollectionUtils.array(String.class); | ||||
| 		} | ||||
| 		return null; | ||||
| 	} | ||||
| } | ||||
| @ -1,110 +0,0 @@ | ||||
| package me.TheBukor.SkStuff.expressions; | ||||
| 
 | ||||
| import org.bukkit.craftbukkit.libs.jline.internal.Nullable; | ||||
| import org.bukkit.event.Event; | ||||
| 
 | ||||
| import com.sk89q.worldguard.protection.flags.BooleanFlag; | ||||
| import com.sk89q.worldguard.protection.flags.Flag; | ||||
| 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; | ||||
| 
 | ||||
| public class ExprFlagOfWGRegion extends SimpleExpression<String> { | ||||
| 	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 String[] get(final Event e) { | ||||
| 		ProtectedRegion region = this.region.getSingle(e); | ||||
| 		Flag<?> flag = this.flag.getSingle(e); | ||||
| 		return new String[] { region.getFlag(flag).toString() }; | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public boolean isSingle() { | ||||
| 		return true; | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public Class<? extends String> getReturnType() { | ||||
| 		return String.class; | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public String toString(final @Nullable Event e, final boolean debug) { | ||||
| 		return "worldguard flag " + flag.toString(e, debug) + " of " + region.toString(e, debug); | ||||
| 	} | ||||
| 
 | ||||
| 	@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: " + 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; | ||||
| 	} | ||||
| } | ||||
| @ -1,67 +0,0 @@ | ||||
| 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; | ||||
| 	} | ||||
| } | ||||
| @ -1,56 +0,0 @@ | ||||
| package me.TheBukor.SkStuff.expressions; | ||||
| 
 | ||||
| import javax.annotation.Nullable; | ||||
| 
 | ||||
| import org.bukkit.Material; | ||||
| 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 me.TheBukor.SkStuff.SkStuff; | ||||
| 
 | ||||
| public class ExprItemNBT 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 debug) { | ||||
| 		return itemStack.toString(e, debug) + " with custom NBT " + string.toString(e, debug); | ||||
| 	} | ||||
| 
 | ||||
| 	@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; | ||||
| 		} | ||||
| 		Object parsedNBT = null; | ||||
| 		parsedNBT = SkStuff.getNMSMethods().parseRawNBT(newTags); | ||||
| 		ItemStack newItem = SkStuff.getNMSMethods().getItemWithNBT(item, parsedNBT); | ||||
| 		return new ItemStack[] { newItem }; | ||||
| 	} | ||||
| } | ||||
| @ -1,49 +0,0 @@ | ||||
| package me.TheBukor.SkStuff.expressions; | ||||
| 
 | ||||
| import javax.annotation.Nullable; | ||||
| 
 | ||||
| import org.bukkit.Location; | ||||
| import org.bukkit.entity.Entity; | ||||
| 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 me.TheBukor.SkStuff.SkStuff; | ||||
| 
 | ||||
| public class ExprLastLocation extends SimpleExpression<Location> { | ||||
| 	private Expression<Entity> entity; | ||||
| 
 | ||||
| 	@Override | ||||
| 	public boolean isSingle() { | ||||
| 		return true; | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public Class<? extends Location> getReturnType() { | ||||
| 		return Location.class; | ||||
| 	} | ||||
| 
 | ||||
| 	@SuppressWarnings("unchecked") | ||||
| 	@Override | ||||
| 	public boolean init(Expression<?>[] expr, int matchedPattern, Kleenean isDelayed, ParseResult parseResult) { | ||||
| 		entity = (Expression<Entity>) expr[0]; | ||||
| 		return true; | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public String toString(@Nullable Event e, boolean debug) { | ||||
| 		return "last location of " + entity.toString(e, debug); | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	@Nullable | ||||
| 	protected Location[] get(Event e) { | ||||
| 		Entity ent = entity.getSingle(e); | ||||
| 		if (ent == null) { | ||||
| 			return null; | ||||
| 		} | ||||
| 			return new Location[] { SkStuff.getNMSMethods().getLastLocation(ent) }; | ||||
| 	} | ||||
| } | ||||
| @ -1,52 +0,0 @@ | ||||
| package me.TheBukor.SkStuff.expressions; | ||||
| 
 | ||||
| import javax.annotation.Nullable; | ||||
| 
 | ||||
| import org.bukkit.event.Event; | ||||
| import org.bukkit.inventory.ItemStack; | ||||
| 
 | ||||
| import ch.njol.skript.aliases.ItemType; | ||||
| 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 me.TheBukor.SkStuff.SkStuff; | ||||
| 
 | ||||
| public class ExprMCIdOf extends SimpleExpression<String> { | ||||
| 	private Expression<ItemType> itemType; | ||||
| 
 | ||||
| 	@Override | ||||
| 	public boolean isSingle() { | ||||
| 		return true; | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public Class<? extends String> getReturnType() { | ||||
| 		return String.class; | ||||
| 	} | ||||
| 
 | ||||
| 	@SuppressWarnings("unchecked") | ||||
| 	@Override | ||||
| 	public boolean init(Expression<?>[] expr, int matchedPattern, Kleenean isDelayed, ParseResult parseResult) { | ||||
| 		itemType = (Expression<ItemType>) expr[0]; | ||||
| 		return true; | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public String toString(@Nullable Event e, boolean debug) { | ||||
| 		return "minecraft id of " + itemType.toString(e, debug); | ||||
| 	} | ||||
| 
 | ||||
| 	@SuppressWarnings("deprecation") | ||||
| 	@Override | ||||
| 	@Nullable | ||||
| 	protected String[] get(Event e) { | ||||
| 		ItemType type = itemType.getSingle(e); | ||||
| 		if (type == null) { | ||||
| 			return null; | ||||
| 		} | ||||
| 		ItemStack item = new ItemStack(type.getTypes().get(0).getId()); | ||||
| 		return new String[] { SkStuff.getNMSMethods().getMCId(item) }; | ||||
| 	} | ||||
| 
 | ||||
| } | ||||
| @ -1,49 +0,0 @@ | ||||
| package me.TheBukor.SkStuff.expressions; | ||||
| 
 | ||||
| import javax.annotation.Nullable; | ||||
| 
 | ||||
| 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 me.TheBukor.SkStuff.SkStuff; | ||||
| 
 | ||||
| public class ExprMCIdToItem extends SimpleExpression<ItemStack> { | ||||
| 	private Expression<String> mcId; | ||||
| 
 | ||||
| 	@Override | ||||
| 	public boolean isSingle() { | ||||
| 		return true; | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public Class<? extends ItemStack> getReturnType() { | ||||
| 		return ItemStack.class; | ||||
| 	} | ||||
| 
 | ||||
| 	@SuppressWarnings("unchecked") | ||||
| 	@Override | ||||
| 	public boolean init(Expression<?>[] expr, int matchedPattern, Kleenean isDelayed, ParseResult parseResult) { | ||||
| 		mcId = (Expression<String>) expr[0]; | ||||
| 		return true; | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public String toString(@Nullable Event e, boolean debug) { | ||||
| 		return "item from minecraft id " + mcId.toString(e, debug); | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	@Nullable | ||||
| 	protected ItemStack[] get(Event e) { | ||||
| 		String id = mcId.getSingle(e); | ||||
| 		if (id == null) { | ||||
| 			return null; | ||||
| 		} | ||||
| 		return new ItemStack[] { SkStuff.getNMSMethods().getItemFromMcId(id) }; | ||||
| 	} | ||||
| 
 | ||||
| } | ||||
| @ -1,74 +0,0 @@ | ||||
| package me.TheBukor.SkStuff.expressions; | ||||
| 
 | ||||
| import javax.annotation.Nullable; | ||||
| 
 | ||||
| import org.bukkit.event.Event; | ||||
| 
 | ||||
| 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; | ||||
| import ch.njol.util.coll.CollectionUtils; | ||||
| import me.TheBukor.SkStuff.SkStuff; | ||||
| import me.TheBukor.SkStuff.util.ReflectionUtils; | ||||
| 
 | ||||
| public class ExprNBTListContents extends SimpleExpression<Object> { | ||||
| 	private Expression<Object> nbtList; | ||||
| 
 | ||||
| 	private Class<?> nbtBaseClass = ReflectionUtils.getNMSClass("NBTBase"); | ||||
| 
 | ||||
| 	@Override | ||||
| 	public Class<? extends Object> getReturnType() { | ||||
| 		return Object.class; | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public boolean isSingle() { | ||||
| 		return false; | ||||
| 	} | ||||
| 
 | ||||
| 	@SuppressWarnings("unchecked") | ||||
| 	@Override | ||||
| 	public boolean init(Expression<?>[] expr, int matchedPattern, Kleenean arg2, ParseResult result) { | ||||
| 		nbtList = (Expression<Object>) expr[0]; | ||||
| 		return true; | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public String toString(@Nullable Event e, boolean debug) { | ||||
| 		return "contents from NBT list " + nbtList.toString(e, debug); | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	@Nullable | ||||
| 	protected Object[] get(Event e) { | ||||
| 		Object list = nbtList.getSingle(e); | ||||
| 		return SkStuff.getNMSMethods().getContents(list); | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public void change(Event e, @Nullable Object[] delta, ChangeMode mode) { | ||||
| 		Object list = nbtList.getSingle(e); | ||||
| 		if (mode == ChangeMode.ADD) { | ||||
| 			if (nbtBaseClass.isAssignableFrom(delta[0].getClass())) | ||||
| 				SkStuff.getNMSMethods().addToList(list, delta[0]); | ||||
| 			else if (delta[0] instanceof Number) | ||||
| 				SkStuff.getNMSMethods().addToList(list, SkStuff.getNMSMethods().convertToNBT((Number) delta[0])); | ||||
| 			else if (delta[0] instanceof String) | ||||
| 				SkStuff.getNMSMethods().addToList(list, SkStuff.getNMSMethods().convertToNBT((String) delta[0])); | ||||
| 		} else if (mode == ChangeMode.REMOVE || mode == ChangeMode.REMOVE_ALL) { | ||||
| 			// TODO Code to remove a single or all objects of some value in an NBT array. | ||||
| 		} | ||||
| 	} | ||||
| 
 | ||||
| 	@SuppressWarnings("unchecked") | ||||
| 	@Override | ||||
| 	@Nullable | ||||
| 	public Class<?>[] acceptChange(ChangeMode mode) { | ||||
| 		if (mode == ChangeMode.ADD || mode == ChangeMode.REMOVE || mode == ChangeMode.REMOVE_ALL) { | ||||
| 			return CollectionUtils.array(Object.class); | ||||
| 		} | ||||
| 		return null; | ||||
| 	} | ||||
| } | ||||
| @ -1,83 +0,0 @@ | ||||
| package me.TheBukor.SkStuff.expressions; | ||||
| 
 | ||||
| import javax.annotation.Nullable; | ||||
| 
 | ||||
| import org.bukkit.event.Event; | ||||
| 
 | ||||
| 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; | ||||
| import ch.njol.util.coll.CollectionUtils; | ||||
| import me.TheBukor.SkStuff.SkStuff; | ||||
| import me.TheBukor.SkStuff.util.ReflectionUtils; | ||||
| 
 | ||||
| public class ExprNBTListIndex extends SimpleExpression<Object> { | ||||
| 	private Expression<Object> nbtList; | ||||
| 	private Expression<Number> index; | ||||
| 
 | ||||
| 	private Class<?> nbtBaseClass = ReflectionUtils.getNMSClass("NBTBase"); | ||||
| 
 | ||||
| 	@Override | ||||
| 	public Class<? extends Object> getReturnType() { | ||||
| 		return Object.class; | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public boolean isSingle() { | ||||
| 		return true; | ||||
| 	} | ||||
| 
 | ||||
| 	@SuppressWarnings("unchecked") | ||||
| 	@Override | ||||
| 	public boolean init(Expression<?>[] expr, int matchedPattern, Kleenean arg2, ParseResult result) { | ||||
| 		if (matchedPattern == 0) { | ||||
| 			nbtList = (Expression<Object>) expr[0]; | ||||
| 			index = (Expression<Number>) expr[1]; | ||||
| 		} else { | ||||
| 			index = (Expression<Number>) expr[0]; | ||||
| 			nbtList = (Expression<Object>) expr[1]; | ||||
| 		} | ||||
| 		return true; | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public String toString(@Nullable Event e, boolean debug) { | ||||
| 		return "index " + index.toString(e, debug) + " from nbt list " + nbtList.toString(e, debug); | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	@Nullable | ||||
| 	protected Object[] get(Event e) { | ||||
| 		int i = index.getSingle(e).intValue(); | ||||
| 		i--; | ||||
| 		Object list = nbtList.getSingle(e); | ||||
| 		return new Object[] { SkStuff.getNMSMethods().getIndex(list, i) }; | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public void change(Event e, @Nullable Object[] delta, ChangeMode mode) { | ||||
| 		int i = index.getSingle(e).intValue(); | ||||
| 		i--; | ||||
| 		Object list = nbtList.getSingle(e); | ||||
| 		if (mode == ChangeMode.SET) { | ||||
| 			if (!(delta[0] instanceof Number || delta[0] instanceof String || nbtBaseClass.isAssignableFrom(delta[0].getClass()))) | ||||
| 				//All NBTTags extends NBTBase, so it will check if delta[0] is instance of NBTTagList or NBTTagCompound, because these are the only NBTTagX classes registered in this addon. | ||||
| 				return; //NBT can only store numbers, strings, lists or compounds. | ||||
| 			SkStuff.getNMSMethods().setIndex(list, i, delta[0]); | ||||
| 		} else if (mode == ChangeMode.DELETE) { | ||||
| 			SkStuff.getNMSMethods().removeFromList(list, i); | ||||
| 		} | ||||
| 	} | ||||
| 
 | ||||
| 	@SuppressWarnings("unchecked") | ||||
| 	@Override | ||||
| 	@Nullable | ||||
| 	public Class<?>[] acceptChange(ChangeMode mode) { | ||||
| 		if (mode == ChangeMode.SET || mode == ChangeMode.DELETE) { | ||||
| 			return CollectionUtils.array(Object.class); | ||||
| 		} | ||||
| 		return null; | ||||
| 	} | ||||
| } | ||||
| @ -1,137 +0,0 @@ | ||||
| package me.TheBukor.SkStuff.expressions; | ||||
| 
 | ||||
| import java.util.Arrays; | ||||
| 
 | ||||
| import javax.annotation.Nullable; | ||||
| 
 | ||||
| import org.bukkit.block.Block; | ||||
| 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.log.ErrorQuality; | ||||
| import ch.njol.skript.util.Slot; | ||||
| import ch.njol.util.Kleenean; | ||||
| import ch.njol.util.coll.CollectionUtils; | ||||
| import me.TheBukor.SkStuff.SkStuff; | ||||
| import me.TheBukor.SkStuff.util.ReflectionUtils; | ||||
| 
 | ||||
| public class ExprNBTOf extends SimpleExpression<Object> { | ||||
| 	private Expression<Object> target; | ||||
| 
 | ||||
| 	private Class<?> nbtClass = ReflectionUtils.getNMSClass("NBTTagCompound"); | ||||
| 
 | ||||
| 	@Override | ||||
| 	public Class<? extends Object> getReturnType() { | ||||
| 		return nbtClass; | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public boolean isSingle() { | ||||
| 		return true; | ||||
| 	} | ||||
| 
 | ||||
| 	@SuppressWarnings("unchecked") | ||||
| 	@Override | ||||
| 	public boolean init(Expression<?>[] expr, int matchedPattern, Kleenean arg2, ParseResult result) { | ||||
| 		target = (Expression<Object>) expr[0]; | ||||
| 		Class<?> type = target.getReturnType(); | ||||
| 		if (type != Entity.class || type != Block.class || type != ItemStack.class || type != Slot.class) { | ||||
| 			Skript.error(target.toString() + " is neither an entity, a block nor an itemstack.", ErrorQuality.SEMANTIC_ERROR); | ||||
| 		} | ||||
| 		return true; | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public String toString(@Nullable Event e, boolean debug) { | ||||
| 		return "the NBT of " + target.toString(e, debug); | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	@Nullable | ||||
| 	public Object[] get(Event e) { | ||||
| 		Object tar = target.getSingle(e); | ||||
| 		if (tar instanceof Entity) { | ||||
| 			return new Object[] { SkStuff.getNMSMethods().getEntityNBT((Entity) tar) }; | ||||
| 		} else if (tar instanceof Block) { | ||||
| 			return new Object[] { SkStuff.getNMSMethods().getTileNBT((Block) tar) }; | ||||
| 		} else if (tar instanceof ItemStack) { | ||||
| 			return new Object[] { SkStuff.getNMSMethods().getItemNBT((ItemStack) tar) }; | ||||
| 		} else if (tar instanceof Slot) { | ||||
| 			return new Object[] { SkStuff.getNMSMethods().getItemNBT(((Slot) tar).getItem()) }; | ||||
| 		} | ||||
| 		return null; | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public void change(Event e, Object[] delta, ChangeMode mode) { | ||||
| 		Object tar = target.getSingle(e); | ||||
| 		Object parsedNBT = null; | ||||
| 		if (delta != null) { | ||||
| 			parsedNBT = SkStuff.getNMSMethods().parseRawNBT((String) delta[0]); | ||||
| 		} | ||||
| 		if (tar instanceof Entity) { | ||||
| 			Object entNBT = SkStuff.getNMSMethods().getEntityNBT((Entity) tar); | ||||
| 			if (mode == ChangeMode.ADD) { | ||||
| 				SkStuff.getNMSMethods().removeFromCompound(parsedNBT, "UUIDMost", "UUIDLeast", "WorldUUDMost", "WorldUUIDLeast", "Bukkit.updateLevel"); | ||||
| 				SkStuff.getNMSMethods().addToCompound(entNBT, parsedNBT); | ||||
| 				SkStuff.getNMSMethods().setEntityNBT((Entity) tar, entNBT); | ||||
| 			} else if (mode == ChangeMode.REMOVE) { | ||||
| 				for (Object s : delta) { | ||||
| 					if (s != "UUIDMost" || s != "UUIDLeast" || s != "WorldUUIDMost" || s != "WorldUUIDLeast" || s != "Bukkit.updateLevel") { // Prevent crucial data from being modified | ||||
| 						SkStuff.getNMSMethods().removeFromCompound(entNBT, (String) s); | ||||
| 					} | ||||
| 				} | ||||
| 				SkStuff.getNMSMethods().setEntityNBT((Entity) tar, entNBT); | ||||
| 			} | ||||
| 		} else if (tar instanceof Block) { | ||||
| 			Object blockNBT = SkStuff.getNMSMethods().getTileNBT((Block) tar); | ||||
| 			if (mode == ChangeMode.ADD) { | ||||
| 				SkStuff.getNMSMethods().removeFromCompound(parsedNBT, "x", "y", "z", "id"); | ||||
| 				SkStuff.getNMSMethods().addToCompound(blockNBT, parsedNBT); | ||||
| 				SkStuff.getNMSMethods().setTileNBT((Block) tar, blockNBT); | ||||
| 			} else if (mode == ChangeMode.REMOVE) { | ||||
| 				for (Object s : delta) { | ||||
| 					if (s != "x" || s != "y" || s != "z" || s != "id") { | ||||
| 						SkStuff.getNMSMethods().removeFromCompound(blockNBT, (String) s); | ||||
| 					} | ||||
| 				} | ||||
| 				SkStuff.getNMSMethods().setTileNBT((Block) tar, blockNBT); | ||||
| 			} | ||||
| 		} else if (tar instanceof ItemStack) { | ||||
| 			if (mode == ChangeMode.ADD || mode == ChangeMode.REMOVE || mode == ChangeMode.DELETE || mode == ChangeMode.RESET) { | ||||
| 				Skript.warning("Failed to change the NBT of an item: Itemstack didn't have any slot attached to it."); | ||||
| 			} | ||||
| 		} else if (tar instanceof Slot) { | ||||
| 			ItemStack slotItem = ((Slot) tar).getItem(); | ||||
| 			Object itemNBT = SkStuff.getNMSMethods().getItemNBT(slotItem); | ||||
| 			if (mode == ChangeMode.ADD) { | ||||
| 				SkStuff.getNMSMethods().addToCompound(itemNBT, parsedNBT); | ||||
| 				ItemStack newItem = SkStuff.getNMSMethods().getItemWithNBT(slotItem, itemNBT); | ||||
| 				((Slot) tar).setItem(newItem); | ||||
| 			} else if (mode == ChangeMode.REMOVE) { | ||||
| 				String[] toRemove = Arrays.copyOf(delta, delta.length, String[].class); | ||||
| 				SkStuff.getNMSMethods().removeFromCompound(itemNBT, toRemove); | ||||
| 				ItemStack newItem = SkStuff.getNMSMethods().getItemWithNBT(slotItem, itemNBT); | ||||
| 				((Slot) tar).setItem(newItem); | ||||
| 			} else if (mode == ChangeMode.DELETE || mode == ChangeMode.RESET) { | ||||
| 				ItemStack newItem = SkStuff.getNMSMethods().getItemWithNBT(slotItem, null); | ||||
| 				((Slot) tar).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; | ||||
| 	} | ||||
| } | ||||
| @ -1,54 +0,0 @@ | ||||
| package me.TheBukor.SkStuff.expressions; | ||||
| 
 | ||||
| import javax.annotation.Nullable; | ||||
| 
 | ||||
| import org.bukkit.Bukkit; | ||||
| import org.bukkit.World; | ||||
| import org.bukkit.event.Event; | ||||
| 
 | ||||
| import com.sk89q.worldedit.EditSession; | ||||
| import com.sk89q.worldedit.bukkit.BukkitUtil; | ||||
| import com.sk89q.worldedit.bukkit.WorldEditPlugin; | ||||
| 
 | ||||
| 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 ExprNewEditSession extends SimpleExpression<EditSession> { | ||||
| 	private Expression<World> world; | ||||
| 	private Expression<Integer> blockLimit; | ||||
| 
 | ||||
| 	@Override | ||||
| 	public Class<? extends EditSession> getReturnType() { | ||||
| 		return EditSession.class; | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public boolean isSingle() { | ||||
| 		return true; | ||||
| 	} | ||||
| 
 | ||||
| 	@SuppressWarnings("unchecked") | ||||
| 	@Override | ||||
| 	public boolean init(Expression<?>[] expr, int matchedPattern, Kleenean arg2, ParseResult arg3) { | ||||
| 		world = (Expression<World>) expr[0]; | ||||
| 		blockLimit = (Expression<Integer>) expr[1]; | ||||
| 		return true; | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public String toString(@Nullable Event e, boolean debug) { | ||||
| 		return "new edit session in world " + world.toString(e, debug) + " with maximum block change limit of " + blockLimit.toString(e, debug); | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	@Nullable | ||||
| 	protected EditSession[] get(Event e) { | ||||
| 		WorldEditPlugin we = (WorldEditPlugin) Bukkit.getServer().getPluginManager().getPlugin("WorldEdit"); | ||||
| 		World w = world.getSingle(e); | ||||
| 		Integer limit = blockLimit.getSingle(e); | ||||
| 		com.sk89q.worldedit.world.World weWorld = BukkitUtil.getLocalWorld(w); | ||||
| 		return new EditSession[] { we.getWorldEdit().getEditSessionFactory().getEditSession(weWorld, limit) }; | ||||
| 	} | ||||
| } | ||||
| @ -1,62 +0,0 @@ | ||||
| package me.TheBukor.SkStuff.expressions; | ||||
| 
 | ||||
| import java.util.ArrayList; | ||||
| import java.util.List; | ||||
| import java.util.Map; | ||||
| 
 | ||||
| import javax.annotation.Nullable; | ||||
| 
 | ||||
| import org.bukkit.Bukkit; | ||||
| import org.bukkit.Location; | ||||
| import org.bukkit.event.Event; | ||||
| 
 | ||||
| import com.sk89q.worldedit.Vector; | ||||
| import com.sk89q.worldguard.bukkit.WorldGuardPlugin; | ||||
| import com.sk89q.worldguard.protection.regions.ProtectedRegion; | ||||
| 
 | ||||
| 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 ExprRegionsWithinLocation extends SimpleExpression<ProtectedRegion> { | ||||
| 	private Expression<Location> location; | ||||
| 
 | ||||
| 	@Override | ||||
| 	public boolean isSingle() { | ||||
| 		return false; | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public Class<? extends ProtectedRegion> getReturnType() { | ||||
| 		return ProtectedRegion.class; | ||||
| 	} | ||||
| 
 | ||||
| 	@SuppressWarnings("unchecked") | ||||
| 	@Override | ||||
| 	public boolean init(Expression<?>[] expr, int matchedPattern, Kleenean isDelayed, ParseResult parseResult) { | ||||
| 		location = (Expression<Location>) expr[0]; | ||||
| 		return true; | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public String toString(@Nullable Event e, boolean debug) { | ||||
| 		return "all the regions containing " + location.toString(e, debug); | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	@Nullable | ||||
| 	protected ProtectedRegion[] get(Event e) { | ||||
| 		WorldGuardPlugin wg = (WorldGuardPlugin) Bukkit.getPluginManager().getPlugin("WorldGuard"); | ||||
| 		Location loc = location.getSingle(e); | ||||
| 		Vector vec = new Vector(loc.getX(), loc.getY(), loc.getZ()); | ||||
| 		Map<String, ProtectedRegion> regions = wg.getRegionManager(loc.getWorld()).getRegions(); | ||||
| 		List<ProtectedRegion> regionsInside = new ArrayList<ProtectedRegion>(); | ||||
| 		for (ProtectedRegion region : regions.values()) { | ||||
| 			if (region.contains(vec)) { | ||||
| 				regionsInside.add(region); | ||||
| 			} | ||||
| 		} | ||||
| 		return regionsInside.toArray(new ProtectedRegion[0]); | ||||
| 	} | ||||
| } | ||||
| @ -1,85 +0,0 @@ | ||||
| package me.TheBukor.SkStuff.expressions; | ||||
| 
 | ||||
| import java.io.File; | ||||
| import java.io.IOException; | ||||
| 
 | ||||
| import javax.annotation.Nullable; | ||||
| 
 | ||||
| import org.bukkit.event.Event; | ||||
| 
 | ||||
| import com.sk89q.worldedit.Vector; | ||||
| import com.sk89q.worldedit.schematic.MCEditSchematicFormat; | ||||
| import com.sk89q.worldedit.world.DataException; | ||||
| 
 | ||||
| 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 ExprSchematicArea extends SimpleExpression<Integer> { | ||||
| 	private Expression<String> schematic; | ||||
| 	 | ||||
| 	private int parseMark; | ||||
| 	private String toStringMark; | ||||
| 
 | ||||
| 	@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 result) { | ||||
| 		schematic = (Expression<String>) expr[0]; | ||||
| 		parseMark = result.mark; | ||||
| 		if (parseMark == 0) { | ||||
| 			toStringMark = "volume"; | ||||
| 		} else if (parseMark == 1) { | ||||
| 			toStringMark = "width (x-size)"; | ||||
| 		} else if (parseMark == 2) { | ||||
| 			toStringMark = "height (y-size)"; | ||||
| 		} else if (parseMark == 3) { | ||||
| 			toStringMark = "length (z-size)"; | ||||
| 		} else if (parseMark == 4) { | ||||
| 			toStringMark = "area"; | ||||
| 		} | ||||
| 		return true; | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public String toString(@Nullable Event e, boolean debug) { | ||||
| 		return "the " + toStringMark + " of the schematic from " + schematic.toString(e, debug); | ||||
| 	} | ||||
| 
 | ||||
| 	@SuppressWarnings("deprecation") | ||||
| 	@Override | ||||
| 	@Nullable | ||||
| 	protected Integer[] get(Event e) { | ||||
| 		String schem = schematic.getSingle(e); | ||||
| 		File schemFile = new File((schem.endsWith(".schematic") ? schem : (schem + ".schematic"))); | ||||
| 		Vector size = null; | ||||
| 		try { | ||||
| 			size = MCEditSchematicFormat.getFormat(schemFile).load(schemFile).getSize(); | ||||
| 		} catch (DataException | IOException ex) { | ||||
| 			return null; | ||||
| 		} | ||||
| 		Number result = null; | ||||
| 		if (parseMark == 0) { | ||||
| 			result = (size.getX() * size.getY() * size.getZ()); | ||||
| 		} else if (parseMark == 1) { | ||||
| 			result = size.getX(); | ||||
| 		} else if (parseMark == 2) { | ||||
| 			result = size.getY(); | ||||
| 		} else if (parseMark == 3) { | ||||
| 			result = size.getZ(); | ||||
| 		} else if (parseMark == 4) { | ||||
| 			result = (size.getX() * size.getZ()); | ||||
| 		} | ||||
| 		return new Integer[] { result.intValue() }; | ||||
| 	} | ||||
| } | ||||
| @ -1,77 +0,0 @@ | ||||
| package me.TheBukor.SkStuff.expressions; | ||||
| 
 | ||||
| import javax.annotation.Nullable; | ||||
| 
 | ||||
| import org.bukkit.Bukkit; | ||||
| import org.bukkit.entity.Player; | ||||
| import org.bukkit.event.Event; | ||||
| 
 | ||||
| import com.sk89q.worldedit.bukkit.WorldEditPlugin; | ||||
| import com.sk89q.worldedit.bukkit.selections.Selection; | ||||
| 
 | ||||
| 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 ExprSelectionArea extends SimpleExpression<Integer> { | ||||
| 	private Expression<Player> player; | ||||
| 	private Integer parseMark; | ||||
| 	private String toStringMark; | ||||
| 
 | ||||
| 	@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 result) { | ||||
| 		player = (Expression<Player>) expr[0]; | ||||
| 		parseMark = result.mark; | ||||
| 		if (parseMark == 0) { | ||||
| 			toStringMark = "volume"; | ||||
| 		} else if (parseMark == 1) { | ||||
| 			toStringMark = "width (x-size)"; | ||||
| 		} else if (parseMark == 2) { | ||||
| 			toStringMark = "height (y-size)"; | ||||
| 		} else if (parseMark == 3) { | ||||
| 			toStringMark = "length (z-size)"; | ||||
| 		} else if (parseMark == 4) { | ||||
| 			toStringMark = "area"; | ||||
| 		} | ||||
| 		return true; | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public String toString(@Nullable Event e, boolean debug) { | ||||
| 		return "the " + toStringMark + " of the WorldEdit selection of " + player.toString(e, debug); | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	@Nullable | ||||
| 	protected Integer[] get(Event e) { | ||||
| 		WorldEditPlugin we = (WorldEditPlugin) Bukkit.getServer().getPluginManager().getPlugin("WorldEdit"); | ||||
| 		Selection sel = we.getSelection(player.getSingle(e)); | ||||
| 		if (sel == null) | ||||
| 			return null; | ||||
| 		Integer result = null; | ||||
| 		if (parseMark == 0) { | ||||
| 			result = sel.getArea(); | ||||
| 		} else if (parseMark == 1) { | ||||
| 			result = sel.getWidth(); | ||||
| 		} else if (parseMark == 2) { | ||||
| 			result = sel.getHeight(); | ||||
| 		} else if (parseMark == 3) { | ||||
| 			result = sel.getLength(); | ||||
| 		} else if (parseMark == 4) { | ||||
| 			result = (sel.getWidth() * sel.getLength()); | ||||
| 		} | ||||
| 		return new Integer[] { result }; | ||||
| 	} | ||||
| } | ||||
| @ -1,90 +0,0 @@ | ||||
| package me.TheBukor.SkStuff.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.BukkitUtil; | ||||
| import com.sk89q.worldedit.bukkit.WorldEditPlugin; | ||||
| import com.sk89q.worldedit.regions.CuboidRegion; | ||||
| import com.sk89q.worldedit.regions.Region; | ||||
| import com.sk89q.worldedit.world.World; | ||||
| 
 | ||||
| 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; | ||||
| import ch.njol.util.coll.CollectionUtils; | ||||
| 
 | ||||
| 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 debug) { | ||||
| 		return "the WorldEdit selection of " + player.toString(e, debug); | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	@Nullable | ||||
| 	protected Location[] get(Event e) { | ||||
| 		Player p = player.getSingle(e); | ||||
| 		Region region = null; | ||||
| 		try { | ||||
| 			region = we.getSession(p).getSelection((World) BukkitUtil.getLocalWorld(we.getSelection(p).getWorld())); | ||||
| 		} 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); | ||||
| 		if (mode == ChangeMode.DELETE || mode == ChangeMode.RESET) { | ||||
| 			if (we.getSelection(p) == null) | ||||
| 				return; | ||||
| 			we.getSession(p).getRegionSelector((World) BukkitUtil.getLocalWorld(we.getSelection(p).getWorld())).clear(); | ||||
| 		} | ||||
| 	} | ||||
| 
 | ||||
| 	@SuppressWarnings("unchecked") | ||||
| 	@Override | ||||
| 	@Nullable | ||||
| 	public Class<?>[] acceptChange(ChangeMode mode) { | ||||
| 		if (mode == ChangeMode.DELETE || mode == ChangeMode.RESET) { | ||||
| 			return CollectionUtils.array(Location.class); | ||||
| 		} | ||||
| 		return null; | ||||
| 	} | ||||
| } | ||||
| @ -1,110 +0,0 @@ | ||||
| package me.TheBukor.SkStuff.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.BukkitUtil; | ||||
| import com.sk89q.worldedit.bukkit.WorldEditPlugin; | ||||
| import com.sk89q.worldedit.regions.CuboidRegion; | ||||
| import com.sk89q.worldedit.regions.Region; | ||||
| import com.sk89q.worldedit.regions.selector.CuboidRegionSelector; | ||||
| import com.sk89q.worldedit.world.World; | ||||
| 
 | ||||
| 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; | ||||
| import ch.njol.util.coll.CollectionUtils; | ||||
| 
 | ||||
| public class ExprSelectionPos extends SimpleExpression<Location> { | ||||
| 	private Expression<Player> player; | ||||
| 	private boolean usePos2 = false; | ||||
| 	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 result) { | ||||
| 		player = (Expression<Player>) expr[0]; | ||||
| 		if (result.mark == 1) { | ||||
| 			usePos2 = true; | ||||
| 		} | ||||
| 		return true; | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public String toString(@Nullable Event e, boolean debug) { | ||||
| 		return "the WorldEdit point " + (usePos2 ? "2" : "1") + " selection of " + player.toString(e, debug); | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	@Nullable | ||||
| 	protected Location[] get(Event e) { | ||||
| 		Player p = player.getSingle(e); | ||||
| 		Region region = null; | ||||
| 		try { | ||||
| 			region = we.getSession(p).getSelection((World) BukkitUtil.getLocalWorld(we.getSelection(p).getWorld())); | ||||
| 		} catch (IncompleteRegionException ex) { | ||||
| 			return null; | ||||
| 		} | ||||
| 		if (!(region instanceof CuboidRegion)) | ||||
| 			return null; //Who uses polygonal and other selection types anyways? | ||||
| 		CuboidRegion cuboid = (CuboidRegion) region; | ||||
| 		Vector pos = null; | ||||
| 		if (usePos2 == true) { | ||||
| 			pos = cuboid.getPos2(); | ||||
| 		} else { | ||||
| 			pos = cuboid.getPos1(); | ||||
| 		} | ||||
| 		return new Location[] { BukkitUtil.toLocation(we.getSelection(p).getWorld(), pos) }; | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public void change(Event e, @Nullable Object[] delta, ChangeMode mode) { | ||||
| 		Player p = player.getSingle(e); | ||||
| 		Location newLoc = (Location) delta[0]; | ||||
| 		if (mode == ChangeMode.SET) { | ||||
| 			Region region = null; | ||||
| 			try { | ||||
| 				region = we.getSession(p).getSelection((World) BukkitUtil.getLocalWorld(we.getSelection(p).getWorld())); | ||||
| 			} catch (IncompleteRegionException | NullPointerException ex) { | ||||
| 				CuboidRegionSelector cuboidregion = new CuboidRegionSelector(BukkitUtil.getLocalWorld((org.bukkit.World) newLoc.getWorld()), BukkitUtil.toVector(newLoc), BukkitUtil.toVector(newLoc)); | ||||
| 				we.getSession(p).setRegionSelector((World) BukkitUtil.getLocalWorld(p.getWorld()), cuboidregion); | ||||
| 			} | ||||
| 			if (!(region instanceof CuboidRegion)) | ||||
| 				return; //Who uses polygonal and other selection types anyways? | ||||
| 			CuboidRegion cuboid = (CuboidRegion) region; | ||||
| 			if (usePos2 == true) { | ||||
| 				cuboid.setPos2(BukkitUtil.toVector(newLoc)); | ||||
| 			} else { | ||||
| 				cuboid.setPos1(BukkitUtil.toVector(newLoc)); | ||||
| 			} | ||||
| 		} | ||||
| 	} | ||||
| 
 | ||||
| 	@SuppressWarnings("unchecked") | ||||
| 	@Override | ||||
| 	@Nullable | ||||
| 	public Class<?>[] acceptChange(ChangeMode mode) { | ||||
| 		if (mode == ChangeMode.SET) { | ||||
| 			return CollectionUtils.array(Location.class); | ||||
| 		} | ||||
| 		return null; | ||||
| 	} | ||||
| } | ||||
| @ -1,80 +0,0 @@ | ||||
| package me.TheBukor.SkStuff.expressions; | ||||
| 
 | ||||
| import javax.annotation.Nullable; | ||||
| 
 | ||||
| import org.bukkit.entity.Entity; | ||||
| import org.bukkit.event.Event; | ||||
| 
 | ||||
| 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; | ||||
| import ch.njol.util.coll.CollectionUtils; | ||||
| import me.TheBukor.SkStuff.SkStuff; | ||||
| 
 | ||||
| public class ExprStepLength extends SimpleExpression<Number> { | ||||
| 	private Expression<Entity> entity; | ||||
| 
 | ||||
| 	@Override | ||||
| 	public boolean isSingle() { | ||||
| 		return true; | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public Class<? extends Number> getReturnType() { | ||||
| 		return Number.class; | ||||
| 	} | ||||
| 
 | ||||
| 	@SuppressWarnings("unchecked") | ||||
| 	@Override | ||||
| 	public boolean init(Expression<?>[] expr, int matchedPattern, Kleenean isDelayed, ParseResult parseResult) { | ||||
| 		entity = (Expression<Entity>) expr[0]; | ||||
| 		return true; | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public String toString(@Nullable Event e, boolean debug) { | ||||
| 		return "step length of " + entity.toString(e, debug); | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	@Nullable | ||||
| 	protected Number[] get(Event e) { | ||||
| 		Entity ent = entity.getSingle(e); | ||||
| 		if (ent == null) { | ||||
| 			return null; | ||||
| 		} | ||||
| 		return new Number[] { SkStuff.getNMSMethods().getEntityStepLength(ent) }; | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public void change(Event e, @Nullable Object[] delta, ChangeMode mode) { | ||||
| 		Entity ent = entity.getSingle(e); | ||||
| 		if (ent == null) { | ||||
| 			return; | ||||
| 		} | ||||
| 		if (mode == ChangeMode.ADD) { | ||||
| 			float toAdd = ((Number) delta[0]).floatValue(); | ||||
| 			float currentLength = SkStuff.getNMSMethods().getEntityStepLength(ent); | ||||
| 			SkStuff.getNMSMethods().setEntityStepLength(ent, (currentLength + toAdd)); | ||||
| 		} else if (mode == ChangeMode.REMOVE) { | ||||
| 			float toRemove = ((Number) delta[0]).floatValue(); | ||||
| 			float currentLength = SkStuff.getNMSMethods().getEntityStepLength(ent); | ||||
| 			SkStuff.getNMSMethods().setEntityStepLength(ent, (currentLength - toRemove)); | ||||
| 		} else if (mode == ChangeMode.SET) { | ||||
| 			float toSet = ((Number) delta[0]).floatValue(); | ||||
| 			SkStuff.getNMSMethods().setEntityStepLength(ent, toSet); | ||||
| 		} | ||||
| 	} | ||||
| 
 | ||||
| 	@SuppressWarnings("unchecked") | ||||
| 	@Override | ||||
| 	@Nullable | ||||
| 	public Class<?>[] acceptChange(ChangeMode mode) { | ||||
| 		if (mode == ChangeMode.ADD || mode == ChangeMode.REMOVE || mode == ChangeMode.SET) { | ||||
| 			return CollectionUtils.array(Number.class); | ||||
| 		} | ||||
| 		return null; | ||||
| 	} | ||||
| } | ||||
| @ -1,82 +0,0 @@ | ||||
| package me.TheBukor.SkStuff.expressions; | ||||
| 
 | ||||
| import javax.annotation.Nullable; | ||||
| 
 | ||||
| import org.bukkit.Bukkit; | ||||
| import org.bukkit.entity.Player; | ||||
| import org.bukkit.event.Event; | ||||
| 
 | ||||
| import com.sk89q.worldedit.bukkit.WorldEditPlugin; | ||||
| 
 | ||||
| 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; | ||||
| import ch.njol.util.coll.CollectionUtils; | ||||
| 
 | ||||
| public class ExprSuperPickaxe extends SimpleExpression<Boolean> { | ||||
| 	private Expression<Player> players; | ||||
| 
 | ||||
| 	@Override | ||||
| 	public boolean isSingle() { | ||||
| 		return players.isSingle(); | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public Class<? extends Boolean> getReturnType() { | ||||
| 		return Boolean.class; | ||||
| 	} | ||||
| 
 | ||||
| 	@SuppressWarnings("unchecked") | ||||
| 	@Override | ||||
| 	public boolean init(Expression<?>[] expr, int matchedPattern, Kleenean isDelayed, ParseResult parseResult) { | ||||
| 		players = (Expression<Player>) expr[0]; | ||||
| 		return true; | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public String toString(@Nullable Event e, boolean debug) { | ||||
| 		return "world edit super pickaxe state of " + players.toString(e, debug); | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	@Nullable | ||||
| 	protected Boolean[] get(Event e) { | ||||
| 		WorldEditPlugin we = (WorldEditPlugin) Bukkit.getPluginManager().getPlugin("WorldEdit"); | ||||
| 		Player[] ps = players.getAll(e); | ||||
| 		Boolean[] states = new Boolean[ps.length]; | ||||
| 		int i = 0; | ||||
| 		for (Player p : ps) { | ||||
| 			states[i] = we.getSession(p).hasSuperPickAxe(); | ||||
| 			i++; | ||||
| 		} | ||||
| 		return states; | ||||
| 	} | ||||
| 
 | ||||
| 	@SuppressWarnings("unchecked") | ||||
| 	@Override | ||||
| 	@Nullable | ||||
| 	public Class<?>[] acceptChange(ChangeMode mode) { | ||||
| 		if (mode == ChangeMode.SET) { | ||||
| 			return CollectionUtils.array(Boolean.class); | ||||
| 		} | ||||
| 		return null; | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public void change(Event e, @Nullable Object[] delta, ChangeMode mode) { | ||||
| 		if (mode == ChangeMode.SET) { | ||||
| 			WorldEditPlugin we = (WorldEditPlugin) Bukkit.getPluginManager().getPlugin("WorldEdit"); | ||||
| 			Player[] ps = players.getAll(e); | ||||
| 			boolean enablePick = (boolean) delta[0]; | ||||
| 			for (Player p : ps) { | ||||
| 				if (enablePick) { | ||||
| 					we.getSession(p).enableSuperPickAxe(); | ||||
| 				} else { | ||||
| 					we.getSession(p).disableSuperPickAxe(); | ||||
| 				} | ||||
| 			} | ||||
| 		} | ||||
| 	} | ||||
| } | ||||
| @ -1,82 +0,0 @@ | ||||
| package me.TheBukor.SkStuff.expressions; | ||||
| 
 | ||||
| import javax.annotation.Nullable; | ||||
| 
 | ||||
| import org.bukkit.event.Event; | ||||
| 
 | ||||
| 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; | ||||
| import ch.njol.util.coll.CollectionUtils; | ||||
| import me.TheBukor.SkStuff.SkStuff; | ||||
| import me.TheBukor.SkStuff.util.ReflectionUtils; | ||||
| 
 | ||||
| public class ExprTagOf extends SimpleExpression<Object> { | ||||
| 	private Expression<String> string; | ||||
| 	private Expression<Object> compound; | ||||
| 
 | ||||
| 	private Class<?> nbtBaseClass = ReflectionUtils.getNMSClass("NBTBase"); | ||||
| 
 | ||||
| 	@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<Object>) expr[1]; | ||||
| 		return true; | ||||
| 	} | ||||
| 	@Override | ||||
| 	public String toString(@Nullable Event e, boolean debug) { | ||||
| 		return "the tag " + string.toString(e, debug) + " of " + compound.toString(e, debug); | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	@Nullable | ||||
| 	protected Object[] get(Event e) { | ||||
| 		Object NBT = compound.getSingle(e); | ||||
| 		if (NBT == null || NBT.toString().equals("{}")) { // "{}" is an empty compound. | ||||
| 			return null; //The NBT can be empty/inexistant for items | ||||
| 		} | ||||
| 		String stringTag = string.getSingle(e); | ||||
| 		Object tag = SkStuff.getNMSMethods().getNBTTag(NBT, stringTag); | ||||
| 		if (tag == null) { | ||||
| 			return null; //The tag doesn't exist? Return <none>. | ||||
| 		} | ||||
| 		byte id = SkStuff.getNMSMethods().getTypeId(tag); | ||||
| 		return new Object[] { SkStuff.getNMSMethods().getNBTTagValue(NBT, stringTag, id) }; | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public void change(Event e, @Nullable Object[] delta, ChangeMode mode) { | ||||
| 		Object NBT = compound.getSingle(e); | ||||
| 		if (NBT == null) { | ||||
| 			return; | ||||
| 		} | ||||
| 		String stringTag = string.getSingle(e); | ||||
| 		if (mode == ChangeMode.SET) { | ||||
| 			Object newValue = delta[0]; | ||||
| 			SkStuff.getNMSMethods().setNBTTag(NBT, stringTag, newValue); | ||||
| 		} else if (mode == ChangeMode.RESET || mode == ChangeMode.DELETE) { | ||||
| 			SkStuff.getNMSMethods().removeNBTTag(NBT, stringTag); | ||||
| 		} | ||||
| 	} | ||||
| 
 | ||||
| 	@SuppressWarnings("unchecked") | ||||
| 	@Override | ||||
| 	@Nullable | ||||
| 	public Class<?>[] acceptChange(ChangeMode mode) { | ||||
| 		if (mode == ChangeMode.SET || mode == ChangeMode.DELETE || mode == ChangeMode.RESET) { | ||||
| 			return CollectionUtils.array(Number.class, String.class, nbtBaseClass); | ||||
| 		} | ||||
| 		return null; | ||||
| 	} | ||||
| } | ||||
| @ -1,48 +0,0 @@ | ||||
| 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 debug) { | ||||
| 		return "vanish state of " + player.toString(e, debug); | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	@Nullable | ||||
| 	protected Boolean[] get(Event e) { | ||||
| 		Player p = player.getSingle(e); | ||||
| 		return new Boolean[] { ((VanishPlugin) vanishPlugin).getManager().isVanished(p) }; | ||||
| 	} | ||||
| } | ||||
| @ -1,111 +0,0 @@ | ||||
| package me.TheBukor.SkStuff.expressions; | ||||
| 
 | ||||
| import java.util.Arrays; | ||||
| import java.util.Set; | ||||
| import java.util.UUID; | ||||
| 
 | ||||
| import javax.annotation.Nullable; | ||||
| 
 | ||||
| import org.bukkit.Bukkit; | ||||
| import org.bukkit.OfflinePlayer; | ||||
| import org.bukkit.event.Event; | ||||
| 
 | ||||
| import com.sk89q.worldguard.domains.DefaultDomain; | ||||
| 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; | ||||
| import ch.njol.util.coll.CollectionUtils; | ||||
| 
 | ||||
| public class ExprWGMemberOwner extends SimpleExpression<OfflinePlayer> { | ||||
| 	private Expression<ProtectedRegion> region; | ||||
| 
 | ||||
| 	private int mark; | ||||
| 
 | ||||
| 	@Override | ||||
| 	public boolean isSingle() { | ||||
| 		return false; | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public Class<? extends OfflinePlayer> getReturnType() { | ||||
| 		return OfflinePlayer.class; | ||||
| 	} | ||||
| 
 | ||||
| 	@SuppressWarnings("unchecked") | ||||
| 	@Override | ||||
| 	public boolean init(Expression<?>[] expr, int matchedPattern, Kleenean isDelayed, ParseResult result) { | ||||
| 		region = (Expression<ProtectedRegion>) expr[0]; | ||||
| 		mark = result.mark; | ||||
| 		return true; | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public String toString(@Nullable Event e, boolean debug) { | ||||
| 		String markString = mark == 0 ? "members" : "owners"; | ||||
| 		return "the " + markString + " of the worldguard region " + region.toString(e, debug); | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	@Nullable | ||||
| 	protected OfflinePlayer[] get(Event e) { | ||||
| 		ProtectedRegion reg = region.getSingle(e); | ||||
| 		Set<UUID> uuids; | ||||
| 		if (mark == 0) { | ||||
| 			uuids = reg.getMembers().getUniqueIds(); | ||||
| 		} else { | ||||
| 			uuids = reg.getOwners().getUniqueIds(); | ||||
| 		} | ||||
| 		if (uuids.isEmpty()) { | ||||
| 			return null; | ||||
| 		} | ||||
| 		OfflinePlayer[] offPlayers = new OfflinePlayer[uuids.size()]; | ||||
| 		int i = 0; | ||||
| 		for (UUID uuid : uuids) { | ||||
| 			offPlayers[i] = Bukkit.getOfflinePlayer(uuid); | ||||
| 			i++; | ||||
| 		} | ||||
| 		return offPlayers; | ||||
| 	} | ||||
| 
 | ||||
| 	@SuppressWarnings("unchecked") | ||||
| 	@Override | ||||
| 	@Nullable | ||||
| 	public Class<?>[] acceptChange(ChangeMode mode) { | ||||
| 		if (mode == ChangeMode.ADD || mode == ChangeMode.REMOVE) { | ||||
| 			return CollectionUtils.array(OfflinePlayer[].class); | ||||
| 		} | ||||
| 		return null; | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public void change(Event e, @Nullable Object[] delta, ChangeMode mode) { | ||||
| 		ProtectedRegion reg = region.getSingle(e); | ||||
| 		if (mode == ChangeMode.ADD) { | ||||
| 			OfflinePlayer[] toAdd = Arrays.copyOf(delta, delta.length, OfflinePlayer[].class); | ||||
| 			for (OfflinePlayer offPlayer : toAdd) { | ||||
| 				DefaultDomain domain; | ||||
| 				if (mark == 0) { | ||||
| 					domain = reg.getMembers(); | ||||
| 				} else { | ||||
| 					domain = reg.getOwners(); | ||||
| 				} | ||||
| 				domain.addPlayer(offPlayer.getUniqueId()); | ||||
| 			} | ||||
| 		} else if (mode == ChangeMode.REMOVE) { | ||||
| 			OfflinePlayer[] toRemove = Arrays.copyOf(delta, delta.length, OfflinePlayer[].class); | ||||
| 			for (OfflinePlayer offPlayer : toRemove) { | ||||
| 				DefaultDomain domain; | ||||
| 				if (mark == 0) { | ||||
| 					domain = reg.getMembers(); | ||||
| 				} else { | ||||
| 					domain = reg.getOwners(); | ||||
| 				} | ||||
| 				domain.removePlayer(offPlayer.getUniqueId()); | ||||
| 			} | ||||
| 		} | ||||
| 	} | ||||
| } | ||||
| @ -1,75 +0,0 @@ | ||||
| package me.TheBukor.SkStuff.pathfinders; | ||||
| 
 | ||||
| import java.util.List; | ||||
| 
 | ||||
| import net.minecraft.server.v1_8_R3.Entity; | ||||
| import net.minecraft.server.v1_8_R3.EntityCreature; | ||||
| import net.minecraft.server.v1_8_R3.EntityLiving; | ||||
| import net.minecraft.server.v1_8_R3.PathfinderGoal; | ||||
| 
 | ||||
| public class PathfinderGoalFollow_v1_8_R3 extends PathfinderGoal { | ||||
| 	private EntityCreature follower; | ||||
| 	private EntityLiving followed; | ||||
| 	private Class<?> followedClass; | ||||
| 	private float radius; | ||||
| 	private double speed; | ||||
| 	private boolean isByName; | ||||
| 	private String customName; | ||||
| 
 | ||||
| 	public PathfinderGoalFollow_v1_8_R3(EntityCreature follower, Class<?> followedClass, float radius, double speed, boolean isByName, String customName) { | ||||
| 		this.follower = follower; | ||||
| 		this.followedClass = followedClass; | ||||
| 		this.radius = radius; | ||||
| 		this.speed = speed; | ||||
| 		this.isByName = isByName; | ||||
| 		this.customName = customName; | ||||
| 	} | ||||
| 
 | ||||
| 	// a() is shouldExecute() | ||||
| 	@SuppressWarnings("unchecked") | ||||
| 	@Override | ||||
| 	public boolean a() { | ||||
| 		if (followed == null) { | ||||
| 			List<?> list = follower.world.a((Class<? extends Entity>) followedClass, follower.getBoundingBox().grow(radius, 4.0D, radius)); | ||||
| 			if (list.isEmpty()) { | ||||
| 				return false; | ||||
| 			} | ||||
| 			if (isByName) { | ||||
| 				for (Object entity : list) { | ||||
| 					if (((EntityLiving) entity).getCustomName().equals(customName)) { | ||||
| 						followed = (EntityLiving) entity; | ||||
| 						return true; | ||||
| 					} | ||||
| 				} | ||||
| 			} else { | ||||
| 				followed = (EntityLiving) list.get(0); | ||||
| 				return true; | ||||
| 			} | ||||
| 		} | ||||
| 		return true; | ||||
| 	} | ||||
| 
 | ||||
| 	// b() is shouldContinueExecuting() | ||||
| 	@Override | ||||
| 	public boolean b() { | ||||
| 		if (followed.dead) { | ||||
| 			followed = null; | ||||
| 			return false; | ||||
| 		} else if (followed.h(follower) < 9.0D || followed.h(follower) > Math.pow(radius, 2)) {  // h() = distanceSquaredFrom() | ||||
| 			return false; // if 3 blocks away or not in radius, stop moving. | ||||
| 			//Maybe I'll add a teleport feature later. | ||||
| 		} else if (isByName) { | ||||
| 			if (!followed.getCustomName().equals(customName)) { | ||||
| 				followed = null; | ||||
| 				return false; | ||||
| 			} | ||||
| 		} | ||||
| 		return follower.getNavigation().m(); // m() means hasNoPath() | ||||
| 	} | ||||
| 
 | ||||
| 	// c() is execute() | ||||
| 	@Override | ||||
| 	public void c() { | ||||
| 		follower.getNavigation().a(followed, speed); // a() means moveTo() | ||||
| 	} | ||||
| } | ||||
| @ -1,77 +0,0 @@ | ||||
| package me.TheBukor.SkStuff.pathfinders; | ||||
| 
 | ||||
| import java.util.List; | ||||
| 
 | ||||
| import net.minecraft.server.v1_9_R1.Entity; | ||||
| import net.minecraft.server.v1_9_R1.EntityCreature; | ||||
| import net.minecraft.server.v1_9_R1.EntityLiving; | ||||
| import net.minecraft.server.v1_9_R1.PathfinderGoal; | ||||
| 
 | ||||
| public class PathfinderGoalFollow_v1_9_R1 extends PathfinderGoal { | ||||
| 	private EntityCreature follower; | ||||
| 	private EntityLiving followed; | ||||
| 	private Class<?> followedClass; | ||||
| 	private float radius; | ||||
| 	private double speed; | ||||
| 	private boolean isByName; | ||||
| 	private String customName; | ||||
| 
 | ||||
| 	public PathfinderGoalFollow_v1_9_R1(EntityCreature follower, Class<?> followedClass, float radius, double speed, boolean isByName, String customName) { | ||||
| 		this.follower = follower; | ||||
| 		this.followedClass = followedClass; | ||||
| 		this.radius = radius; | ||||
| 		this.speed = speed; | ||||
| 		this.isByName = isByName; | ||||
| 		this.customName = customName; | ||||
| 	} | ||||
| 
 | ||||
| 	// a() is shouldExecute() | ||||
| 	@SuppressWarnings("unchecked") | ||||
| 	@Override | ||||
| 	public boolean a() { | ||||
| 		if (followed == null) { | ||||
| 			List<?> list = follower.world.a((Class<? extends Entity>) followedClass, follower.getBoundingBox().grow(radius, 4.0D, radius)); | ||||
| 			if (list.isEmpty()) { | ||||
| 				return false; | ||||
| 			} | ||||
| 			if (isByName) { | ||||
| 				for (Object entity : list) { | ||||
| 					if (((EntityLiving) entity).getCustomName().equals(customName)) { | ||||
| 						followed = (EntityLiving) entity; | ||||
| 						return true; | ||||
| 					} | ||||
| 				} | ||||
| 			} else { | ||||
| 				followed = (EntityLiving) list.get(0); | ||||
| 				return true; | ||||
| 			} | ||||
| 		} | ||||
| 		return true; | ||||
| 	} | ||||
| 
 | ||||
| 	// b() is shouldContinueExecuting() | ||||
| 	@Override | ||||
| 	public boolean b() { | ||||
| 		if (followed.dead) { | ||||
| 			followed = null; | ||||
| 			return false; | ||||
| 		} else if (followed.h(follower) < 9.0D || followed.h(follower) > Math.pow(radius, 2)) {  // h() = distanceSquaredFrom() | ||||
| 			return false; // if 3 blocks away or not in radius, stop moving. | ||||
| 			//Maybe I'll add a teleport feature later. | ||||
| 		} else if (isByName) { | ||||
| 			if (!followed.getCustomName().equals(customName)) { | ||||
| 				followed = null; | ||||
| 				return false; | ||||
| 			} | ||||
| 		} | ||||
| 		return follower.getNavigation().n(); // n() means hasNoPath() | ||||
| 	} | ||||
| 
 | ||||
| 	// c() is execute() | ||||
| 	@Override | ||||
| 	public void c() { | ||||
| 		follower.getNavigation().a(followed, speed); // a() means moveTo() | ||||
| 	} | ||||
| 
 | ||||
| 	 | ||||
| } | ||||
| @ -1,732 +0,0 @@ | ||||
| package me.TheBukor.SkStuff.util; | ||||
| 
 | ||||
| import java.io.EOFException; | ||||
| import java.io.File; | ||||
| import java.io.FileInputStream; | ||||
| import java.io.FileNotFoundException; | ||||
| import java.io.FileOutputStream; | ||||
| import java.io.IOException; | ||||
| import java.io.NotSerializableException; | ||||
| import java.io.OutputStream; | ||||
| import java.io.StreamCorruptedException; | ||||
| import java.util.Iterator; | ||||
| import java.util.LinkedHashSet; | ||||
| 
 | ||||
| import javax.annotation.Nullable; | ||||
| 
 | ||||
| import org.bukkit.Location; | ||||
| import org.bukkit.Material; | ||||
| import org.bukkit.block.Block; | ||||
| import org.bukkit.craftbukkit.v1_10_R1.CraftWorld; | ||||
| import org.bukkit.craftbukkit.v1_10_R1.entity.CraftEntity; | ||||
| import org.bukkit.craftbukkit.v1_10_R1.inventory.CraftItemStack; | ||||
| import org.bukkit.craftbukkit.v1_10_R1.entity.CraftLivingEntity; | ||||
| import org.bukkit.entity.Entity; | ||||
| import org.bukkit.inventory.ItemStack; | ||||
| 
 | ||||
| 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.classes.Serializer; | ||||
| import ch.njol.skript.lang.ParseContext; | ||||
| import ch.njol.skript.registrations.Classes; | ||||
| import ch.njol.util.coll.CollectionUtils; | ||||
| import ch.njol.yggdrasil.Fields; | ||||
| import net.minecraft.server.v1_10_R1.BlockPosition; | ||||
| import net.minecraft.server.v1_10_R1.EntityInsentient; | ||||
| import net.minecraft.server.v1_10_R1.IBlockData; | ||||
| import net.minecraft.server.v1_10_R1.Item; | ||||
| import net.minecraft.server.v1_10_R1.MinecraftKey; | ||||
| import net.minecraft.server.v1_10_R1.MojangsonParseException; | ||||
| import net.minecraft.server.v1_10_R1.MojangsonParser; | ||||
| import net.minecraft.server.v1_10_R1.NBTBase; | ||||
| import net.minecraft.server.v1_10_R1.NBTCompressedStreamTools; | ||||
| import net.minecraft.server.v1_10_R1.NBTTagByte; | ||||
| import net.minecraft.server.v1_10_R1.NBTTagCompound; | ||||
| import net.minecraft.server.v1_10_R1.NBTTagDouble; | ||||
| import net.minecraft.server.v1_10_R1.NBTTagFloat; | ||||
| import net.minecraft.server.v1_10_R1.NBTTagInt; | ||||
| import net.minecraft.server.v1_10_R1.NBTTagList; | ||||
| import net.minecraft.server.v1_10_R1.NBTTagLong; | ||||
| import net.minecraft.server.v1_10_R1.NBTTagShort; | ||||
| import net.minecraft.server.v1_10_R1.NBTTagString; | ||||
| import net.minecraft.server.v1_10_R1.PathfinderGoal; | ||||
| import net.minecraft.server.v1_10_R1.PathfinderGoalSelector; | ||||
| import net.minecraft.server.v1_10_R1.TileEntity; | ||||
| import net.minecraft.server.v1_10_R1.World; | ||||
| import net.minecraft.server.v1_10_R1.EntityLiving; | ||||
| 
 | ||||
| public class NMS_v1_10_R1 implements NMSInterface { | ||||
| 
 | ||||
| 	@Override | ||||
| 	public Object getNBTTag(Object compound, String tag) { | ||||
| 		if (compound instanceof NBTTagCompound) { | ||||
| 			return ((NBTTagCompound) compound).get(tag); | ||||
| 		} | ||||
| 		return null; | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public void setNBTTag(Object compound, String tag, Object toSet) { | ||||
| 		if (compound instanceof NBTTagCompound && (toSet instanceof NBTBase || toSet instanceof Number || toSet instanceof String)) { | ||||
| 			NBTBase converted = null; | ||||
| 			if (toSet instanceof Number) { | ||||
| 				converted = convertToNBT((Number) toSet); | ||||
| 			} else if (toSet instanceof String) { | ||||
| 				converted = convertToNBT((String) toSet); | ||||
| 			} else { //Already an NBTBase | ||||
| 				converted = (NBTBase) toSet; //No need to convert anything | ||||
| 			} | ||||
| 			((NBTTagCompound) compound).set(tag, converted); | ||||
| 		} | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public void removeNBTTag(Object compound, String tag) { | ||||
| 		if (compound instanceof NBTTagCompound) { | ||||
| 			((NBTTagCompound) compound).remove(tag); | ||||
| 		} | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public byte getTypeId(Object nbtBase) { | ||||
| 		if (nbtBase instanceof NBTBase) { | ||||
| 			return ((NBTBase) nbtBase).getTypeId(); | ||||
| 		} | ||||
| 		return 0; | ||||
| 	} | ||||
| 
 | ||||
| 	 @Override | ||||
| 	public Object getNBTTagValue(Object compound, String tag, byte typeId) { | ||||
| 		if (compound instanceof NBTTagCompound) { | ||||
| 			switch (typeId) { | ||||
| 			case 1: | ||||
| 				return ((NBTTagCompound) compound).getByte(tag); | ||||
| 			case 2: | ||||
| 				return ((NBTTagCompound) compound).getShort(tag); | ||||
| 			case 3: | ||||
| 				return ((NBTTagCompound) compound).getInt(tag); | ||||
| 			case 4: | ||||
| 				return ((NBTTagCompound) compound).getLong(tag); | ||||
| 			case 5: | ||||
| 				return ((NBTTagCompound) compound).getFloat(tag); | ||||
| 			case 6: | ||||
| 				return ((NBTTagCompound) compound).getDouble(tag); | ||||
| 			case 7: //Byte array, only used in chunk files. Also doesn't have support for the MojangsonParser. | ||||
| 				break; | ||||
| 			case 8: | ||||
| 				return ((NBTTagCompound) compound).getString(tag); | ||||
| 			case 9: | ||||
| 				int i; | ||||
| 				NBTTagList list = null; | ||||
| 				for (i = 1; i <= 11; i++) { //To get a list I need to know the type of the tags it contains inside, | ||||
| 					//since I can't predict what type the list will have, I just loop all of the IDs until I find a non-empty list. | ||||
| 					list = ((NBTTagCompound) compound).getList(tag, i); //Try to get the list with the ID "loop-number". | ||||
| 					if (!list.isEmpty()) { //If list is not empty. | ||||
| 						break; //Stop loop. | ||||
| 					} | ||||
| 				} | ||||
| 				return list; //May be null | ||||
| 			case 10: | ||||
| 				return ((NBTTagCompound) compound).getCompound(tag); | ||||
| 			case 11: //Integer array, this one is only used on the chunk files (and maybe schematic files?). | ||||
| 				return ((NBTTagCompound) compound).getIntArray(tag); | ||||
| 			default: //This should never happen, but it's better to have this just in case it spills errors everywhere. | ||||
| 				break; | ||||
| 			} | ||||
| 		} | ||||
| 		return null; | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public void addToCompound(Object compound, Object toAdd) { | ||||
| 		if (compound instanceof NBTTagCompound && toAdd instanceof NBTTagCompound) { | ||||
| 			((NBTTagCompound) compound).a((NBTTagCompound) toAdd); | ||||
| 		} | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public void removeFromCompound(Object compound, String ... toRemove) { | ||||
| 		if (compound instanceof NBTTagCompound) { | ||||
| 			for (String s : toRemove) { | ||||
| 				((NBTTagCompound) compound).remove(s); | ||||
| 			} | ||||
| 		} | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public NBTTagCompound parseRawNBT(String rawNBT) { | ||||
| 		NBTTagCompound parsedNBT = null; | ||||
| 		try { | ||||
| 			parsedNBT = MojangsonParser.parse(rawNBT); | ||||
| 		} catch (MojangsonParseException ex) { | ||||
| 			Skript.warning("Error when parsing NBT - " + ex.getMessage()); | ||||
| 			return null; | ||||
| 		} | ||||
| 		return parsedNBT; | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public Object[] getContents(Object nbtList) { | ||||
| 		if (nbtList instanceof NBTTagList) { | ||||
| 			Object[] contents = new Object[((NBTTagList) nbtList).size()]; | ||||
| 			for (int i = 0; i < ((NBTTagList) nbtList).size(); i++) { | ||||
| 				if (getIndex(nbtList, i) != null) { | ||||
| 					contents[i] = getIndex(nbtList, i); | ||||
| 				} | ||||
| 			} | ||||
| 			return contents; | ||||
| 		} | ||||
| 		return null; | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public void addToList(Object nbtList, Object toAdd) { | ||||
| 		if (nbtList instanceof NBTTagList && toAdd instanceof NBTBase) { | ||||
| 			((NBTTagList) nbtList).add((NBTBase) toAdd); | ||||
| 		} | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public void removeFromList(Object nbtList, int index) { | ||||
| 		if (nbtList instanceof NBTTagList && index >= 0 && index < ((NBTTagList) nbtList).size()) { | ||||
| 			((NBTTagList) nbtList).remove(index); | ||||
| 		} | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public void setIndex(Object nbtList, int index, Object toSet) { | ||||
| 		if (nbtList instanceof NBTTagList && index >= 0 && index < ((NBTTagList) nbtList).size()) { | ||||
| 			if (toSet instanceof NBTBase) { | ||||
| 				((NBTTagList) nbtList).a(index, (NBTBase) toSet); | ||||
| 			} else if (toSet instanceof Number) { | ||||
| 				((NBTTagList) nbtList).a(index, convertToNBT((Number) toSet)); | ||||
| 			} else if (toSet instanceof String) { | ||||
| 				((NBTTagList) nbtList).a(index, convertToNBT((String) toSet)); | ||||
| 			} | ||||
| 		} | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public Object getIndex(Object nbtList, int index) { | ||||
| 		if (nbtList instanceof NBTTagList && index >= 0 && index < ((NBTTagList) nbtList).size()) { | ||||
| 			NBTBase value = ((NBTTagList) nbtList).h(index); | ||||
| 			if (value instanceof NBTTagByte) { | ||||
| 				return ((NBTTagByte) value).g(); //Byte stored inside a NBTNumber | ||||
| 			} else if (value instanceof NBTTagShort) { | ||||
| 				return ((NBTTagShort) value).f(); //Short inside a NBTNumber | ||||
| 			} else if (value instanceof NBTTagInt) { | ||||
| 				return ((NBTTagInt) value).e(); //Integer inside a NBTNumber | ||||
| 			} else if (value instanceof NBTTagLong) { | ||||
| 				return ((NBTTagLong) value).d(); //Long inside a NBTNumber | ||||
| 			} else if (value instanceof NBTTagFloat) { | ||||
| 				return ((NBTTagFloat) value).i(); //Float inside a NBTNumber | ||||
| 			} else if (value instanceof NBTTagDouble) { | ||||
| 				return ((NBTTagDouble) value).h(); //Double inside a NBTNumber | ||||
| 			} else if (value instanceof NBTTagString) { | ||||
| 				return ((NBTTagString) value).c_(); //String inside the NBTTagString | ||||
| 			} else if (value instanceof NBTBase) { | ||||
| 				return value; //No need to convert this | ||||
| 			} | ||||
| 		} | ||||
| 		return null; | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public void clearPathfinderGoals(Entity entity) { | ||||
| 		EntityInsentient nmsEnt = (EntityInsentient) ((CraftEntity) entity).getHandle(); | ||||
| 		((LinkedHashSet<?>) ReflectionUtils.getField("b", PathfinderGoalSelector.class, nmsEnt.goalSelector)).clear(); | ||||
| 		((LinkedHashSet<?>) ReflectionUtils.getField("c", PathfinderGoalSelector.class, nmsEnt.goalSelector)).clear(); | ||||
| 		((LinkedHashSet<?>) ReflectionUtils.getField("b", PathfinderGoalSelector.class, nmsEnt.targetSelector)).clear(); | ||||
| 		((LinkedHashSet<?>) ReflectionUtils.getField("c", PathfinderGoalSelector.class, nmsEnt.targetSelector)).clear(); | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public void removePathfinderGoal(Object entity, Class<?> goalClass, boolean isTargetSelector) { | ||||
| 		if (entity instanceof EntityInsentient) { | ||||
| 			((EntityInsentient) entity).setGoalTarget(null); | ||||
| 			if (isTargetSelector) { | ||||
| 				Iterator<?> goals = ((LinkedHashSet<?>) ReflectionUtils.getField("b", PathfinderGoalSelector.class, ((EntityInsentient) entity).targetSelector)).iterator(); | ||||
| 				while (goals.hasNext()) { | ||||
| 					Object goal = goals.next(); | ||||
| 					if (ReflectionUtils.getField("a", goal.getClass(), goal).getClass() == goalClass) { | ||||
| 						goals.remove(); | ||||
| 					} | ||||
| 				} | ||||
| 			} else { | ||||
| 				Iterator<?> goals = ((LinkedHashSet<?>) ReflectionUtils.getField("b", PathfinderGoalSelector.class, ((EntityInsentient) entity).goalSelector)).iterator(); | ||||
| 				while (goals.hasNext()) { | ||||
| 					Object goal = goals.next(); | ||||
| 					if (ReflectionUtils.getField("a", goal.getClass(), goal).getClass() == goalClass) { | ||||
| 						goals.remove(); | ||||
| 					} | ||||
| 				} | ||||
| 			} | ||||
| 		} | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public void addPathfinderGoal(Object entity, int priority, Object goal, boolean isTargetSelector) { | ||||
| 		if (entity instanceof EntityInsentient && goal instanceof PathfinderGoal) { | ||||
| 			if (isTargetSelector) | ||||
| 				((EntityInsentient) entity).targetSelector.a(priority, (PathfinderGoal) goal); | ||||
| 			else | ||||
| 				((EntityInsentient) entity).goalSelector.a(priority, (PathfinderGoal) goal); | ||||
| 		} | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public void registerCompoundClassInfo() { | ||||
| 		Classes.registerClass(new ClassInfo<NBTTagCompound>(NBTTagCompound.class, "compound").user("((nbt)?( ?tag)?) ?compounds?").name("NBT Compound").changer(new Changer<NBTTagCompound>() { | ||||
| 
 | ||||
| 			@SuppressWarnings("unchecked") | ||||
| 			@Override | ||||
| 			@Nullable | ||||
| 			public Class<?>[] acceptChange(ChangeMode mode) { | ||||
| 				if (mode == ChangeMode.ADD || mode == ChangeMode.REMOVE) { | ||||
| 					return CollectionUtils.array(String.class, NBTTagCompound.class); | ||||
| 				} | ||||
| 				return null; | ||||
| 			} | ||||
| 
 | ||||
| 			@Override | ||||
| 			public void change(NBTTagCompound[] NBT, @Nullable Object[] delta, ChangeMode mode) { | ||||
| 				if (mode == ChangeMode.ADD) { | ||||
| 					if (delta[0] instanceof String) { | ||||
| 						NBTTagCompound parsedNBT = parseRawNBT((String) delta[0]); | ||||
| 						addToCompound(NBT[0], parsedNBT); | ||||
| 					} else { | ||||
| 						addToCompound(NBT[0], delta[0]); | ||||
| 					} | ||||
| 				} else if (mode == ChangeMode.REMOVE) { | ||||
| 					if (delta[0] instanceof NBTTagCompound) | ||||
| 						return; | ||||
| 					for (Object s : delta) { | ||||
| 						NBT[0].remove((String) s); | ||||
| 					} | ||||
| 				} | ||||
| 			} | ||||
| 		}).parser(new Parser<NBTTagCompound>() { | ||||
| 
 | ||||
| 			@Override | ||||
| 			public String getVariableNamePattern() { | ||||
| 				return ".+"; | ||||
| 			} | ||||
| 
 | ||||
| 			@Override | ||||
| 			@Nullable | ||||
| 			public NBTTagCompound parse(String rawNBT, ParseContext context) { | ||||
| 				if (rawNBT.startsWith("nbt:{") && rawNBT.endsWith("}")) { | ||||
| 					NBTTagCompound NBT = parseRawNBT(rawNBT.substring(4)); | ||||
| 					return NBT; | ||||
| 				} | ||||
| 				return null; | ||||
| 			} | ||||
| 
 | ||||
| 			@Override | ||||
| 			public String toString(NBTTagCompound compound, int arg1) { | ||||
| 				return compound.toString(); | ||||
| 			} | ||||
| 
 | ||||
| 			@Override | ||||
| 			public String toVariableNameString(NBTTagCompound compound) { | ||||
| 				return compound.toString(); | ||||
| 			} | ||||
| 		}).serializer(new Serializer<NBTTagCompound>() { | ||||
| 
 | ||||
| 			@Override | ||||
| 			public Fields serialize(NBTTagCompound compound) throws NotSerializableException { | ||||
| 				Fields f = new Fields(); | ||||
| 				f.putObject("asString", compound.toString()); | ||||
| 				return f; | ||||
| 			} | ||||
| 
 | ||||
| 			@Override | ||||
| 			public void deserialize(NBTTagCompound compound, Fields f) throws StreamCorruptedException, NotSerializableException { | ||||
| 				assert false; | ||||
| 			} | ||||
| 
 | ||||
| 			@Override | ||||
| 			protected boolean canBeInstantiated() { | ||||
| 				return false; | ||||
| 			} | ||||
| 
 | ||||
| 			@Override | ||||
| 			protected NBTTagCompound deserialize(Fields fields) throws StreamCorruptedException, NotSerializableException { | ||||
| 				String raw = fields.getObject("asString", String.class); | ||||
| 				NBTTagCompound compound =  parseRawNBT(raw); | ||||
| 				if (compound == null) { | ||||
| 					throw new StreamCorruptedException("Unable to parse NBT from a variable: " + raw); | ||||
| 				} | ||||
| 				return compound; | ||||
| 			} | ||||
| 
 | ||||
| 			@Override | ||||
| 			@Nullable | ||||
| 			public NBTTagCompound deserialize(String s) { | ||||
| 				NBTTagCompound compound =  parseRawNBT(s); | ||||
| 				return compound; | ||||
| 			} | ||||
| 
 | ||||
| 			@Override | ||||
| 			public boolean mustSyncDeserialization() { | ||||
| 				return true; | ||||
| 			} | ||||
| 		})); | ||||
| 
 | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public void registerNBTListClassInfo() { | ||||
| 		Classes.registerClass(new ClassInfo<NBTTagList>(NBTTagList.class, "nbtlist").user("nbt ?list ?(tag)?").name("NBT List").changer(new Changer<NBTTagList>() { | ||||
| 
 | ||||
| 			@SuppressWarnings("unchecked") | ||||
| 			@Override | ||||
| 			@Nullable | ||||
| 			public Class<?>[] acceptChange(ChangeMode mode) { | ||||
| 				if (mode == ChangeMode.ADD) { | ||||
| 					return CollectionUtils.array(Byte.class, Short.class, Integer.class, Long.class, Float.class, Double.class, String.class, NBTTagCompound.class, NBTTagList.class); | ||||
| 				} | ||||
| 				return null; | ||||
| 			} | ||||
| 
 | ||||
| 			@Override | ||||
| 			public void change(NBTTagList[] nbtList, @Nullable Object[] delta, ChangeMode mode) { | ||||
| 				if (delta.length == 0) | ||||
| 					return; | ||||
| 				if (delta[0] instanceof Number) { | ||||
| 					addToList(nbtList[0], convertToNBT((Number) delta[0])); | ||||
| 				} else if (delta[0] instanceof String) { | ||||
| 					addToList(nbtList[0], convertToNBT((String) delta[0])); | ||||
| 				} else if (delta[0] instanceof NBTBase) { | ||||
| 					addToList(nbtList[0], delta[0]); | ||||
| 				} | ||||
| 			} | ||||
| 		}).parser(new Parser<NBTTagList>() { | ||||
| 
 | ||||
| 			@Override | ||||
| 			public String getVariableNamePattern() { | ||||
| 				return ".+"; | ||||
| 			} | ||||
| 
 | ||||
| 			@Override | ||||
| 			@Nullable | ||||
| 			public NBTTagList parse(String listString, ParseContext context) { | ||||
| 				if ((listString.startsWith("nbt:[") || listString.startsWith("nbtlist:[")) && listString.endsWith("]")) { | ||||
| 					int substring; | ||||
| 					if (listString.startsWith("nbt:[")) { | ||||
| 						substring = 4; | ||||
| 					} else { // "nbtlist:[WHATEVER]" | ||||
| 						substring = 8; | ||||
| 					} | ||||
| 					NBTTagCompound tempNBT =  parseRawNBT("{temp:" + listString.substring(substring) + "}"); | ||||
| 					NBTTagList parsedList = (NBTTagList) tempNBT.get("temp"); | ||||
| 					return parsedList; | ||||
| 				} | ||||
| 				return null; | ||||
| 			} | ||||
| 
 | ||||
| 			@Override | ||||
| 			public String toString(NBTTagList nbtList, int arg1) { | ||||
| 				return nbtList.toString(); | ||||
| 			} | ||||
| 
 | ||||
| 			@Override | ||||
| 			public String toVariableNameString(NBTTagList nbtList) { | ||||
| 				return nbtList.toString(); | ||||
| 			} | ||||
| 		}).serializer(new Serializer<NBTTagList>() { | ||||
| 
 | ||||
| 			@Override | ||||
| 			public Fields serialize(NBTTagList nbtList) throws NotSerializableException { | ||||
| 				Fields f = new Fields(); | ||||
| 				f.putObject("asString", nbtList.toString()); | ||||
| 				return f; | ||||
| 			} | ||||
| 
 | ||||
| 			@Override | ||||
| 			public void deserialize(NBTTagList nbtList, Fields f) throws StreamCorruptedException, NotSerializableException { | ||||
| 				assert false; | ||||
| 			} | ||||
| 
 | ||||
| 			@Override | ||||
| 			protected boolean canBeInstantiated() { | ||||
| 				return false; | ||||
| 			} | ||||
| 
 | ||||
| 			@Override | ||||
| 			protected NBTTagList deserialize(Fields fields) throws StreamCorruptedException, NotSerializableException { | ||||
| 				String s = fields.getObject("asString", String.class); | ||||
| 				NBTTagCompound tempNBT =  parseRawNBT("{temp:" + s + "}"); | ||||
| 				if (tempNBT == null || !tempNBT.hasKey("temp")) { | ||||
| 					throw new StreamCorruptedException("Unable to parse NBT list from a variable: " + s); | ||||
| 				} | ||||
| 				NBTTagList nbtList = (NBTTagList) tempNBT.get("temp"); | ||||
| 				return nbtList; | ||||
| 			} | ||||
| 
 | ||||
| 			@Override | ||||
| 			@Nullable | ||||
| 			public NBTTagList deserialize(String s) { | ||||
| 				NBTTagCompound tempNBT =  parseRawNBT("{temp:" + s + "}"); | ||||
| 				NBTTagList nbtList = (NBTTagList) tempNBT.get("temp"); | ||||
| 				return nbtList; | ||||
| 			} | ||||
| 
 | ||||
| 			@Override | ||||
| 			public boolean mustSyncDeserialization() { | ||||
| 				return true; | ||||
| 			} | ||||
| 		})); | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public NBTTagCompound getEntityNBT(Entity entity) { | ||||
| 		net.minecraft.server.v1_10_R1.Entity nmsEntity = ((CraftEntity) entity).getHandle(); | ||||
| 		NBTTagCompound NBT = new NBTTagCompound(); | ||||
| 		nmsEntity.e(NBT); | ||||
| 		return NBT; | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public NBTTagCompound getTileNBT(Block block) { | ||||
| 		NBTTagCompound NBT = new NBTTagCompound(); | ||||
| 		World nmsWorld = ((CraftWorld) block.getWorld()).getHandle(); | ||||
| 		TileEntity tileEntity = nmsWorld.getTileEntity(new BlockPosition(block.getX(), block.getY(), block.getZ())); | ||||
| 		if (tileEntity == null) | ||||
| 			return null; | ||||
| 		tileEntity.save(NBT); | ||||
| 		return NBT; | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public NBTTagCompound getItemNBT(ItemStack itemStack) { | ||||
| 		if (itemStack == null || itemStack.getType() == Material.AIR) | ||||
| 			return null; | ||||
| 		NBTTagCompound itemNBT = CraftItemStack.asNMSCopy(itemStack).getTag(); | ||||
| 		if (itemNBT == null) | ||||
| 			itemNBT = new NBTTagCompound(); | ||||
| 		return itemNBT; | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public void setEntityNBT(Entity entity, Object newCompound) { | ||||
| 		if (newCompound instanceof NBTTagCompound) { | ||||
| 			net.minecraft.server.v1_10_R1.Entity nmsEntity = ((CraftEntity) entity).getHandle(); | ||||
| 			nmsEntity.f((NBTTagCompound) newCompound); | ||||
| 		} | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public void setTileNBT(Block block, Object newCompound) { | ||||
| 		if (newCompound instanceof NBTTagCompound) { | ||||
| 			World nmsWorld = ((CraftWorld) block.getWorld()).getHandle(); | ||||
| 			TileEntity tileEntity = nmsWorld.getTileEntity(new BlockPosition(block.getX(), block.getY(), block.getZ())); | ||||
| 			if (tileEntity == null) | ||||
| 				return; | ||||
| 			tileEntity.a((NBTTagCompound) newCompound); | ||||
| 			tileEntity.update(); | ||||
| 			IBlockData tileEntType = nmsWorld.getType(new BlockPosition(block.getX(), block.getY(), block.getZ())); | ||||
| 			nmsWorld.notify(tileEntity.getPosition(), tileEntType, tileEntType, 3); | ||||
| 		} | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public ItemStack getItemWithNBT(ItemStack itemStack, Object compound) { | ||||
| 		net.minecraft.server.v1_10_R1.ItemStack nmsItem = CraftItemStack.asNMSCopy(itemStack); | ||||
| 		if (compound instanceof NBTTagCompound && itemStack != null) { | ||||
| 			if (itemStack.getType() == Material.AIR) | ||||
| 				return null; | ||||
| 			if (((NBTTagCompound) compound).isEmpty()) | ||||
| 				return itemStack; | ||||
| 			nmsItem.setTag((NBTTagCompound) compound); | ||||
| 			ItemStack newItem = CraftItemStack.asBukkitCopy(nmsItem); | ||||
| 			return newItem; | ||||
| 		} else if (compound == null) { | ||||
| 			nmsItem.setTag(null); | ||||
| 			ItemStack newItem = CraftItemStack.asBukkitCopy(nmsItem); | ||||
| 			return newItem; | ||||
| 		} | ||||
| 		return itemStack; | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public NBTTagCompound getFileNBT(File file) { | ||||
| 		FileInputStream fis = null; | ||||
| 		try { | ||||
| 			fis = new FileInputStream(file); | ||||
| 		} catch (FileNotFoundException ex) { | ||||
| 			return null; //File doesn't exist. | ||||
| 		} | ||||
| 		NBTTagCompound fileNBT = null; | ||||
| 		try { | ||||
| 			fileNBT = NBTCompressedStreamTools.a(fis); | ||||
| 			fis.close(); | ||||
| 		} catch (IOException ex) { | ||||
| 			if (ex instanceof EOFException) { | ||||
| 				; //Nothing. | ||||
| 			} else { | ||||
| 				ex.printStackTrace(); | ||||
| 			} | ||||
| 		} | ||||
| 		return fileNBT; | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public void setFileNBT(File file, Object newCompound) { | ||||
| 		if (newCompound instanceof NBTTagCompound) { | ||||
| 			OutputStream os = null; | ||||
| 			try { | ||||
| 				os = new FileOutputStream(file); | ||||
| 			} catch (FileNotFoundException ex) { | ||||
| 				ex.printStackTrace(); | ||||
| 			} | ||||
| 			try { | ||||
| 				NBTCompressedStreamTools.a((NBTTagCompound) newCompound, os); | ||||
| 				os.close(); | ||||
| 			} catch (IOException ex) { | ||||
| 				if (ex instanceof EOFException) { | ||||
| 					; //Ignore, just end of the file | ||||
| 				} else { | ||||
| 					ex.printStackTrace(); | ||||
| 				} | ||||
| 			} | ||||
| 		} | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public NBTBase convertToNBT(Number number) { | ||||
| 		if (number instanceof Byte) { | ||||
| 			return new NBTTagByte((byte) number); | ||||
| 		} else if (number instanceof Short) { | ||||
| 			return new NBTTagShort((short) number); | ||||
| 		} else if (number instanceof Integer) { | ||||
| 			return new NBTTagInt((int) number); | ||||
| 		} else if (number instanceof Long) { | ||||
| 			return new NBTTagLong((long) number); | ||||
| 		} else if (number instanceof Float) { | ||||
| 			return new NBTTagFloat((float) number); | ||||
| 		} else if (number instanceof Double) { | ||||
| 			return new NBTTagDouble((double) number); | ||||
| 		} | ||||
| 		return null; | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public NBTTagString convertToNBT(String string) { | ||||
| 		return new NBTTagString(string); | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public String getMCId(ItemStack itemStack) { | ||||
| 		net.minecraft.server.v1_10_R1.ItemStack nmsItem = CraftItemStack.asNMSCopy(itemStack); | ||||
| 		MinecraftKey mcKey = Item.REGISTRY.b(nmsItem.getItem()); | ||||
| 		return mcKey.toString(); | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public ItemStack getItemFromMcId(String mcId) { | ||||
| 		MinecraftKey mcKey = new MinecraftKey(mcId); | ||||
| 		Item nmsItem = (Item) Item.REGISTRY.get(mcKey); | ||||
| 		return CraftItemStack.asNewCraftStack(nmsItem); | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public boolean getNoClip(Entity entity) { | ||||
| 		net.minecraft.server.v1_10_R1.Entity nmsEntity = ((CraftEntity) entity).getHandle(); | ||||
| 		return nmsEntity.noclip; | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public void setNoClip(Entity entity, boolean noclip) { | ||||
| 		net.minecraft.server.v1_10_R1.Entity nmsEntity = ((CraftEntity) entity).getHandle(); | ||||
| 		nmsEntity.noclip = noclip; | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public boolean getFireProof(Entity entity) { | ||||
| 		net.minecraft.server.v1_10_R1.Entity nmsEntity = ((CraftEntity) entity).getHandle(); | ||||
| 		return nmsEntity.isFireProof(); | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public void setFireProof(Entity entity, boolean fireProof) { | ||||
| 		net.minecraft.server.v1_10_R1.Entity nmsEntity = ((CraftEntity) entity).getHandle(); | ||||
| 		ReflectionUtils.setField("fireProof", nmsEntity.getClass(), nmsEntity, fireProof); | ||||
| 	} | ||||
| 
 | ||||
| 	/* | ||||
| 	@SuppressWarnings("unchecked") | ||||
| 	@Override | ||||
| 	public ItemStack[] getEndermanBlocks(Entity enderman) { | ||||
| 		EntityEnderman nmsEnder = ((CraftEnderman) enderman).getHandle(); | ||||
| 		Set<net.minecraft.server.v1_10_R1.Block> nmsBlocks = (Set<net.minecraft.server.v1_10_R1.Block>) ReflectionUtils.getField("c", EntityEnderman.class, nmsEnder); | ||||
| 		ItemStack[] items = new ItemStack[nmsBlocks.size()]; | ||||
| 		int i = 0; | ||||
| 		for (net.minecraft.server.v1_10_R1.Block nmsBlock : nmsBlocks) { | ||||
| 			IBlockData nmsBlockData = nmsBlock.getBlockData(); | ||||
| 			int dataValue = nmsBlock.toLegacyData(nmsBlockData); | ||||
| 			net.minecraft.server.v1_10_R1.ItemStack nmsItem = new net.minecraft.server.v1_10_R1.ItemStack(nmsBlock, 1, dataValue); | ||||
| 			ItemStack bukkitItem = CraftItemStack.asCraftMirror(nmsItem); | ||||
| 			items[i] = bukkitItem; | ||||
| 			i++; | ||||
| 		} | ||||
| 		return items; | ||||
| 	} | ||||
| 
 | ||||
| 	@SuppressWarnings("unchecked") | ||||
| 	@Override | ||||
| 	public void setEndermanBlocks(Entity enderman, ItemStack... blocks) { | ||||
| 		EntityEnderman nmsEnder = ((CraftEnderman) enderman).getHandle(); | ||||
| 		Set<net.minecraft.server.v1_10_R1.Block> nmsBlocks = (Set<net.minecraft.server.v1_10_R1.Block>) ReflectionUtils.getField("c", EntityEnderman.class, nmsEnder); | ||||
| 		for (ItemStack block : blocks) { | ||||
| 			if (!block.getType().isBlock()) | ||||
| 				return; | ||||
| 			// TODO Figure out how to get a Blocks from a Bukkit ItemStack | ||||
| 			// Blocks.class has a PRIVATE method to get from a MC id. | ||||
| 		} | ||||
| 	} | ||||
| 	*/ | ||||
| 
 | ||||
| 	@Override | ||||
| 	public Location getLastLocation(Entity entity) { | ||||
| 		net.minecraft.server.v1_10_R1.Entity nmsEntity = ((CraftEntity) entity).getHandle(); | ||||
| 		org.bukkit.World world = nmsEntity.world.getWorld(); | ||||
| 		Location lastEntLoc = new Location(world, nmsEntity.M, nmsEntity.N, nmsEntity.O); | ||||
| 		return lastEntLoc; | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public float getEntityStepLength(Entity entity) { | ||||
| 		net.minecraft.server.v1_10_R1.Entity nmsEntity = ((CraftEntity) entity).getHandle(); | ||||
| 		return nmsEntity.P; | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public void setEntityStepLength(Entity entity, float length) { | ||||
| 		net.minecraft.server.v1_10_R1.Entity nmsEntity = ((CraftEntity) entity).getHandle(); | ||||
| 		nmsEntity.P = length; | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public boolean getElytraGlideState(Entity entity) { | ||||
| 		EntityLiving nmsEntity = ((CraftLivingEntity) entity).getHandle(); | ||||
| 		return nmsEntity.getFlag(7); | ||||
| 	} | ||||
| 	 | ||||
| 	public void setElytraGlideState(Entity entity, boolean glide) { | ||||
| 		EntityLiving nmsEntity = ((CraftLivingEntity) entity).getHandle(); | ||||
| 		nmsEntity.setFlag(7, glide); | ||||
| 	} | ||||
| 	 | ||||
| 	public boolean getNoGravity(Entity entity) { | ||||
| 		net.minecraft.server.v1_10_R1.Entity nmsEntity = ((CraftEntity) entity).getHandle(); | ||||
| 		return nmsEntity.isNoGravity(); | ||||
| 	} | ||||
| 	 | ||||
| 	public void setNoGravity(Entity entity, boolean noGravity) { | ||||
| 		net.minecraft.server.v1_10_R1.Entity nmsEntity = ((CraftEntity) entity).getHandle(); | ||||
| 		nmsEntity.setNoGravity(noGravity); | ||||
| 	} | ||||
| } | ||||
| @ -1,732 +0,0 @@ | ||||
| package me.TheBukor.SkStuff.util; | ||||
| 
 | ||||
| import java.io.EOFException; | ||||
| import java.io.File; | ||||
| import java.io.FileInputStream; | ||||
| import java.io.FileNotFoundException; | ||||
| import java.io.FileOutputStream; | ||||
| import java.io.IOException; | ||||
| import java.io.NotSerializableException; | ||||
| import java.io.OutputStream; | ||||
| import java.io.StreamCorruptedException; | ||||
| import java.util.Iterator; | ||||
| import java.util.LinkedHashSet; | ||||
| 
 | ||||
| import javax.annotation.Nullable; | ||||
| 
 | ||||
| import org.bukkit.Location; | ||||
| import org.bukkit.Material; | ||||
| import org.bukkit.block.Block; | ||||
| import org.bukkit.craftbukkit.v1_11_R1.CraftWorld; | ||||
| import org.bukkit.craftbukkit.v1_11_R1.entity.CraftEntity; | ||||
| import org.bukkit.craftbukkit.v1_11_R1.inventory.CraftItemStack; | ||||
| import org.bukkit.craftbukkit.v1_11_R1.entity.CraftLivingEntity; | ||||
| import org.bukkit.entity.Entity; | ||||
| import org.bukkit.inventory.ItemStack; | ||||
| 
 | ||||
| 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.classes.Serializer; | ||||
| import ch.njol.skript.lang.ParseContext; | ||||
| import ch.njol.skript.registrations.Classes; | ||||
| import ch.njol.util.coll.CollectionUtils; | ||||
| import ch.njol.yggdrasil.Fields; | ||||
| import net.minecraft.server.v1_11_R1.BlockPosition; | ||||
| import net.minecraft.server.v1_11_R1.EntityInsentient; | ||||
| import net.minecraft.server.v1_11_R1.IBlockData; | ||||
| import net.minecraft.server.v1_11_R1.Item; | ||||
| import net.minecraft.server.v1_11_R1.MinecraftKey; | ||||
| import net.minecraft.server.v1_11_R1.MojangsonParseException; | ||||
| import net.minecraft.server.v1_11_R1.MojangsonParser; | ||||
| import net.minecraft.server.v1_11_R1.NBTBase; | ||||
| import net.minecraft.server.v1_11_R1.NBTCompressedStreamTools; | ||||
| import net.minecraft.server.v1_11_R1.NBTTagByte; | ||||
| import net.minecraft.server.v1_11_R1.NBTTagCompound; | ||||
| import net.minecraft.server.v1_11_R1.NBTTagDouble; | ||||
| import net.minecraft.server.v1_11_R1.NBTTagFloat; | ||||
| import net.minecraft.server.v1_11_R1.NBTTagInt; | ||||
| import net.minecraft.server.v1_11_R1.NBTTagList; | ||||
| import net.minecraft.server.v1_11_R1.NBTTagLong; | ||||
| import net.minecraft.server.v1_11_R1.NBTTagShort; | ||||
| import net.minecraft.server.v1_11_R1.NBTTagString; | ||||
| import net.minecraft.server.v1_11_R1.PathfinderGoal; | ||||
| import net.minecraft.server.v1_11_R1.PathfinderGoalSelector; | ||||
| import net.minecraft.server.v1_11_R1.TileEntity; | ||||
| import net.minecraft.server.v1_11_R1.World; | ||||
| import net.minecraft.server.v1_11_R1.EntityLiving; | ||||
| 
 | ||||
| public class NMS_v1_11_R1 implements NMSInterface { | ||||
| 
 | ||||
| 	@Override | ||||
| 	public Object getNBTTag(Object compound, String tag) { | ||||
| 		if (compound instanceof NBTTagCompound) { | ||||
| 			return ((NBTTagCompound) compound).get(tag); | ||||
| 		} | ||||
| 		return null; | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public void setNBTTag(Object compound, String tag, Object toSet) { | ||||
| 		if (compound instanceof NBTTagCompound && (toSet instanceof NBTBase || toSet instanceof Number || toSet instanceof String)) { | ||||
| 			NBTBase converted = null; | ||||
| 			if (toSet instanceof Number) { | ||||
| 				converted = convertToNBT((Number) toSet); | ||||
| 			} else if (toSet instanceof String) { | ||||
| 				converted = convertToNBT((String) toSet); | ||||
| 			} else { //Already an NBTBase | ||||
| 				converted = (NBTBase) toSet; //No need to convert anything | ||||
| 			} | ||||
| 			((NBTTagCompound) compound).set(tag, converted); | ||||
| 		} | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public void removeNBTTag(Object compound, String tag) { | ||||
| 		if (compound instanceof NBTTagCompound) { | ||||
| 			((NBTTagCompound) compound).remove(tag); | ||||
| 		} | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public byte getTypeId(Object nbtBase) { | ||||
| 		if (nbtBase instanceof NBTBase) { | ||||
| 			return ((NBTBase) nbtBase).getTypeId(); | ||||
| 		} | ||||
| 		return 0; | ||||
| 	} | ||||
| 
 | ||||
| 	 @Override | ||||
| 	public Object getNBTTagValue(Object compound, String tag, byte typeId) { | ||||
| 		if (compound instanceof NBTTagCompound) { | ||||
| 			switch (typeId) { | ||||
| 			case 1: | ||||
| 				return ((NBTTagCompound) compound).getByte(tag); | ||||
| 			case 2: | ||||
| 				return ((NBTTagCompound) compound).getShort(tag); | ||||
| 			case 3: | ||||
| 				return ((NBTTagCompound) compound).getInt(tag); | ||||
| 			case 4: | ||||
| 				return ((NBTTagCompound) compound).getLong(tag); | ||||
| 			case 5: | ||||
| 				return ((NBTTagCompound) compound).getFloat(tag); | ||||
| 			case 6: | ||||
| 				return ((NBTTagCompound) compound).getDouble(tag); | ||||
| 			case 7: //Byte array, only used in chunk files. Also doesn't have support for the MojangsonParser. | ||||
| 				break; | ||||
| 			case 8: | ||||
| 				return ((NBTTagCompound) compound).getString(tag); | ||||
| 			case 9: | ||||
| 				int i; | ||||
| 				NBTTagList list = null; | ||||
| 				for (i = 1; i <= 11; i++) { //To get a list I need to know the type of the tags it contains inside, | ||||
| 					//since I can't predict what type the list will have, I just loop all of the IDs until I find a non-empty list. | ||||
| 					list = ((NBTTagCompound) compound).getList(tag, i); //Try to get the list with the ID "loop-number". | ||||
| 					if (!list.isEmpty()) { //If list is not empty. | ||||
| 						break; //Stop loop. | ||||
| 					} | ||||
| 				} | ||||
| 				return list; //May be null | ||||
| 			case 10: | ||||
| 				return ((NBTTagCompound) compound).getCompound(tag); | ||||
| 			case 11: //Integer array, this one is only used on the chunk files (and maybe schematic files?). | ||||
| 				return ((NBTTagCompound) compound).getIntArray(tag); | ||||
| 			default: //This should never happen, but it's better to have this just in case it spills errors everywhere. | ||||
| 				break; | ||||
| 			} | ||||
| 		} | ||||
| 		return null; | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public void addToCompound(Object compound, Object toAdd) { | ||||
| 		if (compound instanceof NBTTagCompound && toAdd instanceof NBTTagCompound) { | ||||
| 			((NBTTagCompound) compound).a((NBTTagCompound) toAdd); | ||||
| 		} | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public void removeFromCompound(Object compound, String ... toRemove) { | ||||
| 		if (compound instanceof NBTTagCompound) { | ||||
| 			for (String s : toRemove) { | ||||
| 				((NBTTagCompound) compound).remove(s); | ||||
| 			} | ||||
| 		} | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public NBTTagCompound parseRawNBT(String rawNBT) { | ||||
| 		NBTTagCompound parsedNBT = null; | ||||
| 		try { | ||||
| 			parsedNBT = MojangsonParser.parse(rawNBT); | ||||
| 		} catch (MojangsonParseException ex) { | ||||
| 			Skript.warning("Error when parsing NBT - " + ex.getMessage()); | ||||
| 			return null; | ||||
| 		} | ||||
| 		return parsedNBT; | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public Object[] getContents(Object nbtList) { | ||||
| 		if (nbtList instanceof NBTTagList) { | ||||
| 			Object[] contents = new Object[((NBTTagList) nbtList).size()]; | ||||
| 			for (int i = 0; i < ((NBTTagList) nbtList).size(); i++) { | ||||
| 				if (getIndex(nbtList, i) != null) { | ||||
| 					contents[i] = getIndex(nbtList, i); | ||||
| 				} | ||||
| 			} | ||||
| 			return contents; | ||||
| 		} | ||||
| 		return null; | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public void addToList(Object nbtList, Object toAdd) { | ||||
| 		if (nbtList instanceof NBTTagList && toAdd instanceof NBTBase) { | ||||
| 			((NBTTagList) nbtList).add((NBTBase) toAdd); | ||||
| 		} | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public void removeFromList(Object nbtList, int index) { | ||||
| 		if (nbtList instanceof NBTTagList && index >= 0 && index < ((NBTTagList) nbtList).size()) { | ||||
| 			((NBTTagList) nbtList).remove(index); | ||||
| 		} | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public void setIndex(Object nbtList, int index, Object toSet) { | ||||
| 		if (nbtList instanceof NBTTagList && index >= 0 && index < ((NBTTagList) nbtList).size()) { | ||||
| 			if (toSet instanceof NBTBase) { | ||||
| 				((NBTTagList) nbtList).a(index, (NBTBase) toSet); | ||||
| 			} else if (toSet instanceof Number) { | ||||
| 				((NBTTagList) nbtList).a(index, convertToNBT((Number) toSet)); | ||||
| 			} else if (toSet instanceof String) { | ||||
| 				((NBTTagList) nbtList).a(index, convertToNBT((String) toSet)); | ||||
| 			} | ||||
| 		} | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public Object getIndex(Object nbtList, int index) { | ||||
| 		if (nbtList instanceof NBTTagList && index >= 0 && index < ((NBTTagList) nbtList).size()) { | ||||
| 			NBTBase value = ((NBTTagList) nbtList).h(index); | ||||
| 			if (value instanceof NBTTagByte) { | ||||
| 				return ((NBTTagByte) value).g(); //Byte stored inside a NBTNumber | ||||
| 			} else if (value instanceof NBTTagShort) { | ||||
| 				return ((NBTTagShort) value).f(); //Short inside a NBTNumber | ||||
| 			} else if (value instanceof NBTTagInt) { | ||||
| 				return ((NBTTagInt) value).e(); //Integer inside a NBTNumber | ||||
| 			} else if (value instanceof NBTTagLong) { | ||||
| 				return ((NBTTagLong) value).d(); //Long inside a NBTNumber | ||||
| 			} else if (value instanceof NBTTagFloat) { | ||||
| 				return ((NBTTagFloat) value).i(); //Float inside a NBTNumber | ||||
| 			} else if (value instanceof NBTTagDouble) { | ||||
| 				return ((NBTTagDouble) value).asDouble(); //Double inside a NBTNumber | ||||
| 			} else if (value instanceof NBTTagString) { | ||||
| 				return ((NBTTagString) value).c_(); //String inside the NBTTagString | ||||
| 			} else if (value instanceof NBTBase) { | ||||
| 				return value; //No need to convert this | ||||
| 			} | ||||
| 		} | ||||
| 		return null; | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public void clearPathfinderGoals(Entity entity) { | ||||
| 		EntityInsentient nmsEnt = (EntityInsentient) ((CraftEntity) entity).getHandle(); | ||||
| 		((LinkedHashSet<?>) ReflectionUtils.getField("b", PathfinderGoalSelector.class, nmsEnt.goalSelector)).clear(); | ||||
| 		((LinkedHashSet<?>) ReflectionUtils.getField("c", PathfinderGoalSelector.class, nmsEnt.goalSelector)).clear(); | ||||
| 		((LinkedHashSet<?>) ReflectionUtils.getField("b", PathfinderGoalSelector.class, nmsEnt.targetSelector)).clear(); | ||||
| 		((LinkedHashSet<?>) ReflectionUtils.getField("c", PathfinderGoalSelector.class, nmsEnt.targetSelector)).clear(); | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public void removePathfinderGoal(Object entity, Class<?> goalClass, boolean isTargetSelector) { | ||||
| 		if (entity instanceof EntityInsentient) { | ||||
| 			((EntityInsentient) entity).setGoalTarget(null); | ||||
| 			if (isTargetSelector) { | ||||
| 				Iterator<?> goals = ((LinkedHashSet<?>) ReflectionUtils.getField("b", PathfinderGoalSelector.class, ((EntityInsentient) entity).targetSelector)).iterator(); | ||||
| 				while (goals.hasNext()) { | ||||
| 					Object goal = goals.next(); | ||||
| 					if (ReflectionUtils.getField("a", goal.getClass(), goal).getClass() == goalClass) { | ||||
| 						goals.remove(); | ||||
| 					} | ||||
| 				} | ||||
| 			} else { | ||||
| 				Iterator<?> goals = ((LinkedHashSet<?>) ReflectionUtils.getField("b", PathfinderGoalSelector.class, ((EntityInsentient) entity).goalSelector)).iterator(); | ||||
| 				while (goals.hasNext()) { | ||||
| 					Object goal = goals.next(); | ||||
| 					if (ReflectionUtils.getField("a", goal.getClass(), goal).getClass() == goalClass) { | ||||
| 						goals.remove(); | ||||
| 					} | ||||
| 				} | ||||
| 			} | ||||
| 		} | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public void addPathfinderGoal(Object entity, int priority, Object goal, boolean isTargetSelector) { | ||||
| 		if (entity instanceof EntityInsentient && goal instanceof PathfinderGoal) { | ||||
| 			if (isTargetSelector) | ||||
| 				((EntityInsentient) entity).targetSelector.a(priority, (PathfinderGoal) goal); | ||||
| 			else | ||||
| 				((EntityInsentient) entity).goalSelector.a(priority, (PathfinderGoal) goal); | ||||
| 		} | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public void registerCompoundClassInfo() { | ||||
| 		Classes.registerClass(new ClassInfo<NBTTagCompound>(NBTTagCompound.class, "compound").user("((nbt)?( ?tag)?) ?compounds?").name("NBT Compound").changer(new Changer<NBTTagCompound>() { | ||||
| 
 | ||||
| 			@SuppressWarnings("unchecked") | ||||
| 			@Override | ||||
| 			@Nullable | ||||
| 			public Class<?>[] acceptChange(ChangeMode mode) { | ||||
| 				if (mode == ChangeMode.ADD || mode == ChangeMode.REMOVE) { | ||||
| 					return CollectionUtils.array(String.class, NBTTagCompound.class); | ||||
| 				} | ||||
| 				return null; | ||||
| 			} | ||||
| 
 | ||||
| 			@Override | ||||
| 			public void change(NBTTagCompound[] NBT, @Nullable Object[] delta, ChangeMode mode) { | ||||
| 				if (mode == ChangeMode.ADD) { | ||||
| 					if (delta[0] instanceof String) { | ||||
| 						NBTTagCompound parsedNBT = parseRawNBT((String) delta[0]); | ||||
| 						addToCompound(NBT[0], parsedNBT); | ||||
| 					} else { | ||||
| 						addToCompound(NBT[0], delta[0]); | ||||
| 					} | ||||
| 				} else if (mode == ChangeMode.REMOVE) { | ||||
| 					if (delta[0] instanceof NBTTagCompound) | ||||
| 						return; | ||||
| 					for (Object s : delta) { | ||||
| 						NBT[0].remove((String) s); | ||||
| 					} | ||||
| 				} | ||||
| 			} | ||||
| 		}).parser(new Parser<NBTTagCompound>() { | ||||
| 
 | ||||
| 			@Override | ||||
| 			public String getVariableNamePattern() { | ||||
| 				return ".+"; | ||||
| 			} | ||||
| 
 | ||||
| 			@Override | ||||
| 			@Nullable | ||||
| 			public NBTTagCompound parse(String rawNBT, ParseContext context) { | ||||
| 				if (rawNBT.startsWith("nbt:{") && rawNBT.endsWith("}")) { | ||||
| 					NBTTagCompound NBT = parseRawNBT(rawNBT.substring(4)); | ||||
| 					return NBT; | ||||
| 				} | ||||
| 				return null; | ||||
| 			} | ||||
| 
 | ||||
| 			@Override | ||||
| 			public String toString(NBTTagCompound compound, int arg1) { | ||||
| 				return compound.toString(); | ||||
| 			} | ||||
| 
 | ||||
| 			@Override | ||||
| 			public String toVariableNameString(NBTTagCompound compound) { | ||||
| 				return compound.toString(); | ||||
| 			} | ||||
| 		}).serializer(new Serializer<NBTTagCompound>() { | ||||
| 
 | ||||
| 			@Override | ||||
| 			public Fields serialize(NBTTagCompound compound) throws NotSerializableException { | ||||
| 				Fields f = new Fields(); | ||||
| 				f.putObject("asString", compound.toString()); | ||||
| 				return f; | ||||
| 			} | ||||
| 
 | ||||
| 			@Override | ||||
| 			public void deserialize(NBTTagCompound compound, Fields f) throws StreamCorruptedException, NotSerializableException { | ||||
| 				assert false; | ||||
| 			} | ||||
| 
 | ||||
| 			@Override | ||||
| 			protected boolean canBeInstantiated() { | ||||
| 				return false; | ||||
| 			} | ||||
| 
 | ||||
| 			@Override | ||||
| 			protected NBTTagCompound deserialize(Fields fields) throws StreamCorruptedException, NotSerializableException { | ||||
| 				String raw = fields.getObject("asString", String.class); | ||||
| 				NBTTagCompound compound =  parseRawNBT(raw); | ||||
| 				if (compound == null) { | ||||
| 					throw new StreamCorruptedException("Unable to parse NBT from a variable: " + raw); | ||||
| 				} | ||||
| 				return compound; | ||||
| 			} | ||||
| 
 | ||||
| 			@Override | ||||
| 			@Nullable | ||||
| 			public NBTTagCompound deserialize(String s) { | ||||
| 				NBTTagCompound compound =  parseRawNBT(s); | ||||
| 				return compound; | ||||
| 			} | ||||
| 
 | ||||
| 			@Override | ||||
| 			public boolean mustSyncDeserialization() { | ||||
| 				return true; | ||||
| 			} | ||||
| 		})); | ||||
| 
 | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public void registerNBTListClassInfo() { | ||||
| 		Classes.registerClass(new ClassInfo<NBTTagList>(NBTTagList.class, "nbtlist").user("nbt ?list ?(tag)?").name("NBT List").changer(new Changer<NBTTagList>() { | ||||
| 
 | ||||
| 			@SuppressWarnings("unchecked") | ||||
| 			@Override | ||||
| 			@Nullable | ||||
| 			public Class<?>[] acceptChange(ChangeMode mode) { | ||||
| 				if (mode == ChangeMode.ADD) { | ||||
| 					return CollectionUtils.array(Byte.class, Short.class, Integer.class, Long.class, Float.class, Double.class, String.class, NBTTagCompound.class, NBTTagList.class); | ||||
| 				} | ||||
| 				return null; | ||||
| 			} | ||||
| 
 | ||||
| 			@Override | ||||
| 			public void change(NBTTagList[] nbtList, @Nullable Object[] delta, ChangeMode mode) { | ||||
| 				if (delta.length == 0) | ||||
| 					return; | ||||
| 				if (delta[0] instanceof Number) { | ||||
| 					addToList(nbtList[0], convertToNBT((Number) delta[0])); | ||||
| 				} else if (delta[0] instanceof String) { | ||||
| 					addToList(nbtList[0], convertToNBT((String) delta[0])); | ||||
| 				} else if (delta[0] instanceof NBTBase) { | ||||
| 					addToList(nbtList[0], delta[0]); | ||||
| 				} | ||||
| 			} | ||||
| 		}).parser(new Parser<NBTTagList>() { | ||||
| 
 | ||||
| 			@Override | ||||
| 			public String getVariableNamePattern() { | ||||
| 				return ".+"; | ||||
| 			} | ||||
| 
 | ||||
| 			@Override | ||||
| 			@Nullable | ||||
| 			public NBTTagList parse(String listString, ParseContext context) { | ||||
| 				if ((listString.startsWith("nbt:[") || listString.startsWith("nbtlist:[")) && listString.endsWith("]")) { | ||||
| 					int substring; | ||||
| 					if (listString.startsWith("nbt:[")) { | ||||
| 						substring = 4; | ||||
| 					} else { // "nbtlist:[WHATEVER]" | ||||
| 						substring = 8; | ||||
| 					} | ||||
| 					NBTTagCompound tempNBT =  parseRawNBT("{temp:" + listString.substring(substring) + "}"); | ||||
| 					NBTTagList parsedList = (NBTTagList) tempNBT.get("temp"); | ||||
| 					return parsedList; | ||||
| 				} | ||||
| 				return null; | ||||
| 			} | ||||
| 
 | ||||
| 			@Override | ||||
| 			public String toString(NBTTagList nbtList, int arg1) { | ||||
| 				return nbtList.toString(); | ||||
| 			} | ||||
| 
 | ||||
| 			@Override | ||||
| 			public String toVariableNameString(NBTTagList nbtList) { | ||||
| 				return nbtList.toString(); | ||||
| 			} | ||||
| 		}).serializer(new Serializer<NBTTagList>() { | ||||
| 
 | ||||
| 			@Override | ||||
| 			public Fields serialize(NBTTagList nbtList) throws NotSerializableException { | ||||
| 				Fields f = new Fields(); | ||||
| 				f.putObject("asString", nbtList.toString()); | ||||
| 				return f; | ||||
| 			} | ||||
| 
 | ||||
| 			@Override | ||||
| 			public void deserialize(NBTTagList nbtList, Fields f) throws StreamCorruptedException, NotSerializableException { | ||||
| 				assert false; | ||||
| 			} | ||||
| 
 | ||||
| 			@Override | ||||
| 			protected boolean canBeInstantiated() { | ||||
| 				return false; | ||||
| 			} | ||||
| 
 | ||||
| 			@Override | ||||
| 			protected NBTTagList deserialize(Fields fields) throws StreamCorruptedException, NotSerializableException { | ||||
| 				String s = fields.getObject("asString", String.class); | ||||
| 				NBTTagCompound tempNBT =  parseRawNBT("{temp:" + s + "}"); | ||||
| 				if (tempNBT == null || !tempNBT.hasKey("temp")) { | ||||
| 					throw new StreamCorruptedException("Unable to parse NBT list from a variable: " + s); | ||||
| 				} | ||||
| 				NBTTagList nbtList = (NBTTagList) tempNBT.get("temp"); | ||||
| 				return nbtList; | ||||
| 			} | ||||
| 
 | ||||
| 			@Override | ||||
| 			@Nullable | ||||
| 			public NBTTagList deserialize(String s) { | ||||
| 				NBTTagCompound tempNBT =  parseRawNBT("{temp:" + s + "}"); | ||||
| 				NBTTagList nbtList = (NBTTagList) tempNBT.get("temp"); | ||||
| 				return nbtList; | ||||
| 			} | ||||
| 
 | ||||
| 			@Override | ||||
| 			public boolean mustSyncDeserialization() { | ||||
| 				return true; | ||||
| 			} | ||||
| 		})); | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public NBTTagCompound getEntityNBT(Entity entity) { | ||||
| 		net.minecraft.server.v1_11_R1.Entity nmsEntity = ((CraftEntity) entity).getHandle(); | ||||
| 		NBTTagCompound NBT = new NBTTagCompound(); | ||||
| 		nmsEntity.e(NBT); | ||||
| 		return NBT; | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public NBTTagCompound getTileNBT(Block block) { | ||||
| 		NBTTagCompound NBT = new NBTTagCompound(); | ||||
| 		World nmsWorld = ((CraftWorld) block.getWorld()).getHandle(); | ||||
| 		TileEntity tileEntity = nmsWorld.getTileEntity(new BlockPosition(block.getX(), block.getY(), block.getZ())); | ||||
| 		if (tileEntity == null) | ||||
| 			return null; | ||||
| 		tileEntity.save(NBT); | ||||
| 		return NBT; | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public NBTTagCompound getItemNBT(ItemStack itemStack) { | ||||
| 		if (itemStack == null || itemStack.getType() == Material.AIR) | ||||
| 			return null; | ||||
| 		NBTTagCompound itemNBT = CraftItemStack.asNMSCopy(itemStack).getTag(); | ||||
| 		if (itemNBT == null) | ||||
| 			itemNBT = new NBTTagCompound(); | ||||
| 		return itemNBT; | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public void setEntityNBT(Entity entity, Object newCompound) { | ||||
| 		if (newCompound instanceof NBTTagCompound) { | ||||
| 			net.minecraft.server.v1_11_R1.Entity nmsEntity = ((CraftEntity) entity).getHandle(); | ||||
| 			nmsEntity.f((NBTTagCompound) newCompound); | ||||
| 		} | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public void setTileNBT(Block block, Object newCompound) { | ||||
| 		if (newCompound instanceof NBTTagCompound) { | ||||
| 			World nmsWorld = ((CraftWorld) block.getWorld()).getHandle(); | ||||
| 			TileEntity tileEntity = nmsWorld.getTileEntity(new BlockPosition(block.getX(), block.getY(), block.getZ())); | ||||
| 			if (tileEntity == null) | ||||
| 				return; | ||||
| 			tileEntity.a((NBTTagCompound) newCompound); | ||||
| 			tileEntity.update(); | ||||
| 			IBlockData tileEntType = nmsWorld.getType(new BlockPosition(block.getX(), block.getY(), block.getZ())); | ||||
| 			nmsWorld.notify(tileEntity.getPosition(), tileEntType, tileEntType, 3); | ||||
| 		} | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public ItemStack getItemWithNBT(ItemStack itemStack, Object compound) { | ||||
| 		net.minecraft.server.v1_11_R1.ItemStack nmsItem = CraftItemStack.asNMSCopy(itemStack); | ||||
| 		if (compound instanceof NBTTagCompound && itemStack != null) { | ||||
| 			if (itemStack.getType() == Material.AIR) | ||||
| 				return null; | ||||
| 			if (((NBTTagCompound) compound).isEmpty()) | ||||
| 				return itemStack; | ||||
| 			nmsItem.setTag((NBTTagCompound) compound); | ||||
| 			ItemStack newItem = CraftItemStack.asBukkitCopy(nmsItem); | ||||
| 			return newItem; | ||||
| 		} else if (compound == null) { | ||||
| 			nmsItem.setTag(null); | ||||
| 			ItemStack newItem = CraftItemStack.asBukkitCopy(nmsItem); | ||||
| 			return newItem; | ||||
| 		} | ||||
| 		return itemStack; | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public NBTTagCompound getFileNBT(File file) { | ||||
| 		FileInputStream fis = null; | ||||
| 		try { | ||||
| 			fis = new FileInputStream(file); | ||||
| 		} catch (FileNotFoundException ex) { | ||||
| 			return null; //File doesn't exist. | ||||
| 		} | ||||
| 		NBTTagCompound fileNBT = null; | ||||
| 		try { | ||||
| 			fileNBT = NBTCompressedStreamTools.a(fis); | ||||
| 			fis.close(); | ||||
| 		} catch (IOException ex) { | ||||
| 			if (ex instanceof EOFException) { | ||||
| 				; //Nothing. | ||||
| 			} else { | ||||
| 				ex.printStackTrace(); | ||||
| 			} | ||||
| 		} | ||||
| 		return fileNBT; | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public void setFileNBT(File file, Object newCompound) { | ||||
| 		if (newCompound instanceof NBTTagCompound) { | ||||
| 			OutputStream os = null; | ||||
| 			try { | ||||
| 				os = new FileOutputStream(file); | ||||
| 			} catch (FileNotFoundException ex) { | ||||
| 				ex.printStackTrace(); | ||||
| 			} | ||||
| 			try { | ||||
| 				NBTCompressedStreamTools.a((NBTTagCompound) newCompound, os); | ||||
| 				os.close(); | ||||
| 			} catch (IOException ex) { | ||||
| 				if (ex instanceof EOFException) { | ||||
| 					; //Ignore, just end of the file | ||||
| 				} else { | ||||
| 					ex.printStackTrace(); | ||||
| 				} | ||||
| 			} | ||||
| 		} | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public NBTBase convertToNBT(Number number) { | ||||
| 		if (number instanceof Byte) { | ||||
| 			return new NBTTagByte((byte) number); | ||||
| 		} else if (number instanceof Short) { | ||||
| 			return new NBTTagShort((short) number); | ||||
| 		} else if (number instanceof Integer) { | ||||
| 			return new NBTTagInt((int) number); | ||||
| 		} else if (number instanceof Long) { | ||||
| 			return new NBTTagLong((long) number); | ||||
| 		} else if (number instanceof Float) { | ||||
| 			return new NBTTagFloat((float) number); | ||||
| 		} else if (number instanceof Double) { | ||||
| 			return new NBTTagDouble((double) number); | ||||
| 		} | ||||
| 		return null; | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public NBTTagString convertToNBT(String string) { | ||||
| 		return new NBTTagString(string); | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public String getMCId(ItemStack itemStack) { | ||||
| 		net.minecraft.server.v1_11_R1.ItemStack nmsItem = CraftItemStack.asNMSCopy(itemStack); | ||||
| 		MinecraftKey mcKey = Item.REGISTRY.b(nmsItem.getItem()); | ||||
| 		return mcKey.toString(); | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public ItemStack getItemFromMcId(String mcId) { | ||||
| 		MinecraftKey mcKey = new MinecraftKey(mcId); | ||||
| 		Item nmsItem = (Item) Item.REGISTRY.get(mcKey); | ||||
| 		return CraftItemStack.asNewCraftStack(nmsItem); | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public boolean getNoClip(Entity entity) { | ||||
| 		net.minecraft.server.v1_11_R1.Entity nmsEntity = ((CraftEntity) entity).getHandle(); | ||||
| 		return nmsEntity.noclip; | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public void setNoClip(Entity entity, boolean noclip) { | ||||
| 		net.minecraft.server.v1_11_R1.Entity nmsEntity = ((CraftEntity) entity).getHandle(); | ||||
| 		nmsEntity.noclip = noclip; | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public boolean getFireProof(Entity entity) { | ||||
| 		net.minecraft.server.v1_11_R1.Entity nmsEntity = ((CraftEntity) entity).getHandle(); | ||||
| 		return nmsEntity.isFireProof(); | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public void setFireProof(Entity entity, boolean fireProof) { | ||||
| 		net.minecraft.server.v1_11_R1.Entity nmsEntity = ((CraftEntity) entity).getHandle(); | ||||
| 		ReflectionUtils.setField("fireProof", nmsEntity.getClass(), nmsEntity, fireProof); | ||||
| 	} | ||||
| 
 | ||||
| 	/* | ||||
| 	@SuppressWarnings("unchecked") | ||||
| 	@Override | ||||
| 	public ItemStack[] getEndermanBlocks(Entity enderman) { | ||||
| 		EntityEnderman nmsEnder = ((CraftEnderman) enderman).getHandle(); | ||||
| 		Set<net.minecraft.server.v1_11_R1.Block> nmsBlocks = (Set<net.minecraft.server.v1_11_R1.Block>) ReflectionUtils.getField("c", EntityEnderman.class, nmsEnder); | ||||
| 		ItemStack[] items = new ItemStack[nmsBlocks.size()]; | ||||
| 		int i = 0; | ||||
| 		for (net.minecraft.server.v1_11_R1.Block nmsBlock : nmsBlocks) { | ||||
| 			IBlockData nmsBlockData = nmsBlock.getBlockData(); | ||||
| 			int dataValue = nmsBlock.toLegacyData(nmsBlockData); | ||||
| 			net.minecraft.server.v1_11_R1.ItemStack nmsItem = new net.minecraft.server.v1_11_R1.ItemStack(nmsBlock, 1, dataValue); | ||||
| 			ItemStack bukkitItem = CraftItemStack.asCraftMirror(nmsItem); | ||||
| 			items[i] = bukkitItem; | ||||
| 			i++; | ||||
| 		} | ||||
| 		return items; | ||||
| 	} | ||||
| 
 | ||||
| 	@SuppressWarnings("unchecked") | ||||
| 	@Override | ||||
| 	public void setEndermanBlocks(Entity enderman, ItemStack... blocks) { | ||||
| 		EntityEnderman nmsEnder = ((CraftEnderman) enderman).getHandle(); | ||||
| 		Set<net.minecraft.server.v1_11_R1.Block> nmsBlocks = (Set<net.minecraft.server.v1_11_R1.Block>) ReflectionUtils.getField("c", EntityEnderman.class, nmsEnder); | ||||
| 		for (ItemStack block : blocks) { | ||||
| 			if (!block.getType().isBlock()) | ||||
| 				return; | ||||
| 			// TODO Figure out how to get a Blocks from a Bukkit ItemStack | ||||
| 			// Blocks.class has a PRIVATE method to get from a MC id. | ||||
| 		} | ||||
| 	} | ||||
| 	*/ | ||||
| 
 | ||||
| 	@Override | ||||
| 	public Location getLastLocation(Entity entity) { | ||||
| 		net.minecraft.server.v1_11_R1.Entity nmsEntity = ((CraftEntity) entity).getHandle(); | ||||
| 		org.bukkit.World world = nmsEntity.world.getWorld(); | ||||
| 		Location lastEntLoc = new Location(world, nmsEntity.M, nmsEntity.N, nmsEntity.O); | ||||
| 		return lastEntLoc; | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public float getEntityStepLength(Entity entity) { | ||||
| 		net.minecraft.server.v1_11_R1.Entity nmsEntity = ((CraftEntity) entity).getHandle(); | ||||
| 		return nmsEntity.P; | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public void setEntityStepLength(Entity entity, float length) { | ||||
| 		net.minecraft.server.v1_11_R1.Entity nmsEntity = ((CraftEntity) entity).getHandle(); | ||||
| 		nmsEntity.P = length; | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public boolean getElytraGlideState(Entity entity) { | ||||
| 		EntityLiving nmsEntity = ((CraftLivingEntity) entity).getHandle(); | ||||
| 		return nmsEntity.getFlag(7); | ||||
| 	} | ||||
| 	 | ||||
| 	public void setElytraGlideState(Entity entity, boolean glide) { | ||||
| 		EntityLiving nmsEntity = ((CraftLivingEntity) entity).getHandle(); | ||||
| 		nmsEntity.setFlag(7, glide); | ||||
| 	} | ||||
| 	 | ||||
| 	public boolean getNoGravity(Entity entity) { | ||||
| 		net.minecraft.server.v1_11_R1.Entity nmsEntity = ((CraftEntity) entity).getHandle(); | ||||
| 		return nmsEntity.isNoGravity(); | ||||
| 	} | ||||
| 	 | ||||
| 	public void setNoGravity(Entity entity, boolean noGravity) { | ||||
| 		net.minecraft.server.v1_11_R1.Entity nmsEntity = ((CraftEntity) entity).getHandle(); | ||||
| 		nmsEntity.setNoGravity(noGravity); | ||||
| 	} | ||||
| } | ||||
| @ -1,732 +0,0 @@ | ||||
| package me.TheBukor.SkStuff.util; | ||||
| 
 | ||||
| import java.io.EOFException; | ||||
| import java.io.File; | ||||
| import java.io.FileInputStream; | ||||
| import java.io.FileNotFoundException; | ||||
| import java.io.FileOutputStream; | ||||
| import java.io.IOException; | ||||
| import java.io.NotSerializableException; | ||||
| import java.io.OutputStream; | ||||
| import java.io.StreamCorruptedException; | ||||
| import java.util.Iterator; | ||||
| import java.util.LinkedHashSet; | ||||
| 
 | ||||
| import javax.annotation.Nullable; | ||||
| 
 | ||||
| import org.bukkit.Location; | ||||
| import org.bukkit.Material; | ||||
| import org.bukkit.block.Block; | ||||
| import org.bukkit.craftbukkit.v1_12_R1.CraftWorld; | ||||
| import org.bukkit.craftbukkit.v1_12_R1.entity.CraftEntity; | ||||
| import org.bukkit.craftbukkit.v1_12_R1.inventory.CraftItemStack; | ||||
| import org.bukkit.craftbukkit.v1_12_R1.entity.CraftLivingEntity; | ||||
| import org.bukkit.entity.Entity; | ||||
| import org.bukkit.inventory.ItemStack; | ||||
| 
 | ||||
| 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.classes.Serializer; | ||||
| import ch.njol.skript.lang.ParseContext; | ||||
| import ch.njol.skript.registrations.Classes; | ||||
| import ch.njol.util.coll.CollectionUtils; | ||||
| import ch.njol.yggdrasil.Fields; | ||||
| import net.minecraft.server.v1_12_R1.BlockPosition; | ||||
| import net.minecraft.server.v1_12_R1.EntityInsentient; | ||||
| import net.minecraft.server.v1_12_R1.IBlockData; | ||||
| import net.minecraft.server.v1_12_R1.Item; | ||||
| import net.minecraft.server.v1_12_R1.MinecraftKey; | ||||
| import net.minecraft.server.v1_12_R1.MojangsonParseException; | ||||
| import net.minecraft.server.v1_12_R1.MojangsonParser; | ||||
| import net.minecraft.server.v1_12_R1.NBTBase; | ||||
| import net.minecraft.server.v1_12_R1.NBTCompressedStreamTools; | ||||
| import net.minecraft.server.v1_12_R1.NBTTagByte; | ||||
| import net.minecraft.server.v1_12_R1.NBTTagCompound; | ||||
| import net.minecraft.server.v1_12_R1.NBTTagDouble; | ||||
| import net.minecraft.server.v1_12_R1.NBTTagFloat; | ||||
| import net.minecraft.server.v1_12_R1.NBTTagInt; | ||||
| import net.minecraft.server.v1_12_R1.NBTTagList; | ||||
| import net.minecraft.server.v1_12_R1.NBTTagLong; | ||||
| import net.minecraft.server.v1_12_R1.NBTTagShort; | ||||
| import net.minecraft.server.v1_12_R1.NBTTagString; | ||||
| import net.minecraft.server.v1_12_R1.PathfinderGoal; | ||||
| import net.minecraft.server.v1_12_R1.PathfinderGoalSelector; | ||||
| import net.minecraft.server.v1_12_R1.TileEntity; | ||||
| import net.minecraft.server.v1_12_R1.World; | ||||
| import net.minecraft.server.v1_12_R1.EntityLiving; | ||||
| 
 | ||||
| public class NMS_v1_12_R1 implements NMSInterface { | ||||
| 
 | ||||
| 	@Override | ||||
| 	public Object getNBTTag(Object compound, String tag) { | ||||
| 		if (compound instanceof NBTTagCompound) { | ||||
| 			return ((NBTTagCompound) compound).get(tag); | ||||
| 		} | ||||
| 		return null; | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public void setNBTTag(Object compound, String tag, Object toSet) { | ||||
| 		if (compound instanceof NBTTagCompound && (toSet instanceof NBTBase || toSet instanceof Number || toSet instanceof String)) { | ||||
| 			NBTBase converted = null; | ||||
| 			if (toSet instanceof Number) { | ||||
| 				converted = convertToNBT((Number) toSet); | ||||
| 			} else if (toSet instanceof String) { | ||||
| 				converted = convertToNBT((String) toSet); | ||||
| 			} else { //Already an NBTBase | ||||
| 				converted = (NBTBase) toSet; //No need to convert anything | ||||
| 			} | ||||
| 			((NBTTagCompound) compound).set(tag, converted); | ||||
| 		} | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public void removeNBTTag(Object compound, String tag) { | ||||
| 		if (compound instanceof NBTTagCompound) { | ||||
| 			((NBTTagCompound) compound).remove(tag); | ||||
| 		} | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public byte getTypeId(Object nbtBase) { | ||||
| 		if (nbtBase instanceof NBTBase) { | ||||
| 			return ((NBTBase) nbtBase).getTypeId(); | ||||
| 		} | ||||
| 		return 0; | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public Object getNBTTagValue(Object compound, String tag, byte typeId) { | ||||
| 		if (compound instanceof NBTTagCompound) { | ||||
| 			switch (typeId) { | ||||
| 				case 1: | ||||
| 					return ((NBTTagCompound) compound).getByte(tag); | ||||
| 				case 2: | ||||
| 					return ((NBTTagCompound) compound).getShort(tag); | ||||
| 				case 3: | ||||
| 					return ((NBTTagCompound) compound).getInt(tag); | ||||
| 				case 4: | ||||
| 					return ((NBTTagCompound) compound).getLong(tag); | ||||
| 				case 5: | ||||
| 					return ((NBTTagCompound) compound).getFloat(tag); | ||||
| 				case 6: | ||||
| 					return ((NBTTagCompound) compound).getDouble(tag); | ||||
| 				case 7: //Byte array, only used in chunk files. Also doesn't have support for the MojangsonParser. | ||||
| 					break; | ||||
| 				case 8: | ||||
| 					return ((NBTTagCompound) compound).getString(tag); | ||||
| 				case 9: | ||||
| 					int i; | ||||
| 					NBTTagList list = null; | ||||
| 					for (i = 1; i <= 11; i++) { //To get a list I need to know the type of the tags it contains inside, | ||||
| 						//since I can't predict what type the list will have, I just loop all of the IDs until I find a non-empty list. | ||||
| 						list = ((NBTTagCompound) compound).getList(tag, i); //Try to get the list with the ID "loop-number". | ||||
| 						if (!list.isEmpty()) { //If list is not empty. | ||||
| 							break; //Stop loop. | ||||
| 						} | ||||
| 					} | ||||
| 					return list; //May be null | ||||
| 				case 10: | ||||
| 					return ((NBTTagCompound) compound).getCompound(tag); | ||||
| 				case 11: //Integer array, this one is only used on the chunk files (and maybe schematic files?). | ||||
| 					return ((NBTTagCompound) compound).getIntArray(tag); | ||||
| 				default: //This should never happen, but it's better to have this just in case it spills errors everywhere. | ||||
| 					break; | ||||
| 			} | ||||
| 		} | ||||
| 		return null; | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public void addToCompound(Object compound, Object toAdd) { | ||||
| 		if (compound instanceof NBTTagCompound && toAdd instanceof NBTTagCompound) { | ||||
| 			((NBTTagCompound) compound).a((NBTTagCompound) toAdd); | ||||
| 		} | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public void removeFromCompound(Object compound, String ... toRemove) { | ||||
| 		if (compound instanceof NBTTagCompound) { | ||||
| 			for (String s : toRemove) { | ||||
| 				((NBTTagCompound) compound).remove(s); | ||||
| 			} | ||||
| 		} | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public NBTTagCompound parseRawNBT(String rawNBT) { | ||||
| 		NBTTagCompound parsedNBT = null; | ||||
| 		try { | ||||
| 			parsedNBT = MojangsonParser.parse(rawNBT); | ||||
| 		} catch (MojangsonParseException ex) { | ||||
| 			Skript.warning("Error when parsing NBT - " + ex.getMessage()); | ||||
| 			return null; | ||||
| 		} | ||||
| 		return parsedNBT; | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public Object[] getContents(Object nbtList) { | ||||
| 		if (nbtList instanceof NBTTagList) { | ||||
| 			Object[] contents = new Object[((NBTTagList) nbtList).size()]; | ||||
| 			for (int i = 0; i < ((NBTTagList) nbtList).size(); i++) { | ||||
| 				if (getIndex(nbtList, i) != null) { | ||||
| 					contents[i] = getIndex(nbtList, i); | ||||
| 				} | ||||
| 			} | ||||
| 			return contents; | ||||
| 		} | ||||
| 		return null; | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public void addToList(Object nbtList, Object toAdd) { | ||||
| 		if (nbtList instanceof NBTTagList && toAdd instanceof NBTBase) { | ||||
| 			((NBTTagList) nbtList).add((NBTBase) toAdd); | ||||
| 		} | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public void removeFromList(Object nbtList, int index) { | ||||
| 		if (nbtList instanceof NBTTagList && index >= 0 && index < ((NBTTagList) nbtList).size()) { | ||||
| 			((NBTTagList) nbtList).remove(index); | ||||
| 		} | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public void setIndex(Object nbtList, int index, Object toSet) { | ||||
| 		if (nbtList instanceof NBTTagList && index >= 0 && index < ((NBTTagList) nbtList).size()) { | ||||
| 			if (toSet instanceof NBTBase) { | ||||
| 				((NBTTagList) nbtList).a(index, (NBTBase) toSet); | ||||
| 			} else if (toSet instanceof Number) { | ||||
| 				((NBTTagList) nbtList).a(index, convertToNBT((Number) toSet)); | ||||
| 			} else if (toSet instanceof String) { | ||||
| 				((NBTTagList) nbtList).a(index, convertToNBT((String) toSet)); | ||||
| 			} | ||||
| 		} | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public Object getIndex(Object nbtList, int index) { | ||||
| 		if (nbtList instanceof NBTTagList && index >= 0 && index < ((NBTTagList) nbtList).size()) { | ||||
| 			NBTBase value = ((NBTTagList) nbtList).i(index); | ||||
| 			if (value instanceof NBTTagByte) { | ||||
| 				return ((NBTTagByte) value).g(); //Byte stored inside a NBTNumber | ||||
| 			} else if (value instanceof NBTTagShort) { | ||||
| 				return ((NBTTagShort) value).f(); //Short inside a NBTNumber | ||||
| 			} else if (value instanceof NBTTagInt) { | ||||
| 				return ((NBTTagInt) value).e(); //Integer inside a NBTNumber | ||||
| 			} else if (value instanceof NBTTagLong) { | ||||
| 				return ((NBTTagLong) value).d(); //Long inside a NBTNumber | ||||
| 			} else if (value instanceof NBTTagFloat) { | ||||
| 				return ((NBTTagFloat) value).i(); //Float inside a NBTNumber | ||||
| 			} else if (value instanceof NBTTagDouble) { | ||||
| 				return ((NBTTagDouble) value).asDouble(); //Double inside a NBTNumber | ||||
| 			} else if (value instanceof NBTTagString) { | ||||
| 				return ((NBTTagString) value).c_(); //String inside the NBTTagString | ||||
| 			} else if (value instanceof NBTBase) { | ||||
| 				return value; //No need to convert this | ||||
| 			} | ||||
| 		} | ||||
| 		return null; | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public void clearPathfinderGoals(Entity entity) { | ||||
| 		EntityInsentient nmsEnt = (EntityInsentient) ((CraftEntity) entity).getHandle(); | ||||
| 		((LinkedHashSet<?>) ReflectionUtils.getField("b", PathfinderGoalSelector.class, nmsEnt.goalSelector)).clear(); | ||||
| 		((LinkedHashSet<?>) ReflectionUtils.getField("c", PathfinderGoalSelector.class, nmsEnt.goalSelector)).clear(); | ||||
| 		((LinkedHashSet<?>) ReflectionUtils.getField("b", PathfinderGoalSelector.class, nmsEnt.targetSelector)).clear(); | ||||
| 		((LinkedHashSet<?>) ReflectionUtils.getField("c", PathfinderGoalSelector.class, nmsEnt.targetSelector)).clear(); | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public void removePathfinderGoal(Object entity, Class<?> goalClass, boolean isTargetSelector) { | ||||
| 		if (entity instanceof EntityInsentient) { | ||||
| 			((EntityInsentient) entity).setGoalTarget(null); | ||||
| 			if (isTargetSelector) { | ||||
| 				Iterator<?> goals = ((LinkedHashSet<?>) ReflectionUtils.getField("b", PathfinderGoalSelector.class, ((EntityInsentient) entity).targetSelector)).iterator(); | ||||
| 				while (goals.hasNext()) { | ||||
| 					Object goal = goals.next(); | ||||
| 					if (ReflectionUtils.getField("a", goal.getClass(), goal).getClass() == goalClass) { | ||||
| 						goals.remove(); | ||||
| 					} | ||||
| 				} | ||||
| 			} else { | ||||
| 				Iterator<?> goals = ((LinkedHashSet<?>) ReflectionUtils.getField("b", PathfinderGoalSelector.class, ((EntityInsentient) entity).goalSelector)).iterator(); | ||||
| 				while (goals.hasNext()) { | ||||
| 					Object goal = goals.next(); | ||||
| 					if (ReflectionUtils.getField("a", goal.getClass(), goal).getClass() == goalClass) { | ||||
| 						goals.remove(); | ||||
| 					} | ||||
| 				} | ||||
| 			} | ||||
| 		} | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public void addPathfinderGoal(Object entity, int priority, Object goal, boolean isTargetSelector) { | ||||
| 		if (entity instanceof EntityInsentient && goal instanceof PathfinderGoal) { | ||||
| 			if (isTargetSelector) | ||||
| 				((EntityInsentient) entity).targetSelector.a(priority, (PathfinderGoal) goal); | ||||
| 			else | ||||
| 				((EntityInsentient) entity).goalSelector.a(priority, (PathfinderGoal) goal); | ||||
| 		} | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public void registerCompoundClassInfo() { | ||||
| 		Classes.registerClass(new ClassInfo<NBTTagCompound>(NBTTagCompound.class, "compound").user("((nbt)?( ?tag)?) ?compounds?").name("NBT Compound").changer(new Changer<NBTTagCompound>() { | ||||
| 
 | ||||
| 			@SuppressWarnings("unchecked") | ||||
| 			@Override | ||||
| 			@Nullable | ||||
| 			public Class<?>[] acceptChange(ChangeMode mode) { | ||||
| 				if (mode == ChangeMode.ADD || mode == ChangeMode.REMOVE) { | ||||
| 					return CollectionUtils.array(String.class, NBTTagCompound.class); | ||||
| 				} | ||||
| 				return null; | ||||
| 			} | ||||
| 
 | ||||
| 			@Override | ||||
| 			public void change(NBTTagCompound[] NBT, @Nullable Object[] delta, ChangeMode mode) { | ||||
| 				if (mode == ChangeMode.ADD) { | ||||
| 					if (delta[0] instanceof String) { | ||||
| 						NBTTagCompound parsedNBT = parseRawNBT((String) delta[0]); | ||||
| 						addToCompound(NBT[0], parsedNBT); | ||||
| 					} else { | ||||
| 						addToCompound(NBT[0], delta[0]); | ||||
| 					} | ||||
| 				} else if (mode == ChangeMode.REMOVE) { | ||||
| 					if (delta[0] instanceof NBTTagCompound) | ||||
| 						return; | ||||
| 					for (Object s : delta) { | ||||
| 						NBT[0].remove((String) s); | ||||
| 					} | ||||
| 				} | ||||
| 			} | ||||
| 		}).parser(new Parser<NBTTagCompound>() { | ||||
| 
 | ||||
| 			@Override | ||||
| 			public String getVariableNamePattern() { | ||||
| 				return ".+"; | ||||
| 			} | ||||
| 
 | ||||
| 			@Override | ||||
| 			@Nullable | ||||
| 			public NBTTagCompound parse(String rawNBT, ParseContext context) { | ||||
| 				if (rawNBT.startsWith("nbt:{") && rawNBT.endsWith("}")) { | ||||
| 					NBTTagCompound NBT = parseRawNBT(rawNBT.substring(4)); | ||||
| 					return NBT; | ||||
| 				} | ||||
| 				return null; | ||||
| 			} | ||||
| 
 | ||||
| 			@Override | ||||
| 			public String toString(NBTTagCompound compound, int arg1) { | ||||
| 				return compound.toString(); | ||||
| 			} | ||||
| 
 | ||||
| 			@Override | ||||
| 			public String toVariableNameString(NBTTagCompound compound) { | ||||
| 				return compound.toString(); | ||||
| 			} | ||||
| 		}).serializer(new Serializer<NBTTagCompound>() { | ||||
| 
 | ||||
| 			@Override | ||||
| 			public Fields serialize(NBTTagCompound compound) throws NotSerializableException { | ||||
| 				Fields f = new Fields(); | ||||
| 				f.putObject("asString", compound.toString()); | ||||
| 				return f; | ||||
| 			} | ||||
| 
 | ||||
| 			@Override | ||||
| 			public void deserialize(NBTTagCompound compound, Fields f) throws StreamCorruptedException, NotSerializableException { | ||||
| 				assert false; | ||||
| 			} | ||||
| 
 | ||||
| 			@Override | ||||
| 			protected boolean canBeInstantiated() { | ||||
| 				return false; | ||||
| 			} | ||||
| 
 | ||||
| 			@Override | ||||
| 			protected NBTTagCompound deserialize(Fields fields) throws StreamCorruptedException, NotSerializableException { | ||||
| 				String raw = fields.getObject("asString", String.class); | ||||
| 				NBTTagCompound compound =  parseRawNBT(raw); | ||||
| 				if (compound == null) { | ||||
| 					throw new StreamCorruptedException("Unable to parse NBT from a variable: " + raw); | ||||
| 				} | ||||
| 				return compound; | ||||
| 			} | ||||
| 
 | ||||
| 			@Override | ||||
| 			@Nullable | ||||
| 			public NBTTagCompound deserialize(String s) { | ||||
| 				NBTTagCompound compound =  parseRawNBT(s); | ||||
| 				return compound; | ||||
| 			} | ||||
| 
 | ||||
| 			@Override | ||||
| 			public boolean mustSyncDeserialization() { | ||||
| 				return true; | ||||
| 			} | ||||
| 		})); | ||||
| 
 | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public void registerNBTListClassInfo() { | ||||
| 		Classes.registerClass(new ClassInfo<NBTTagList>(NBTTagList.class, "nbtlist").user("nbt ?list ?(tag)?").name("NBT List").changer(new Changer<NBTTagList>() { | ||||
| 
 | ||||
| 			@SuppressWarnings("unchecked") | ||||
| 			@Override | ||||
| 			@Nullable | ||||
| 			public Class<?>[] acceptChange(ChangeMode mode) { | ||||
| 				if (mode == ChangeMode.ADD) { | ||||
| 					return CollectionUtils.array(Byte.class, Short.class, Integer.class, Long.class, Float.class, Double.class, String.class, NBTTagCompound.class, NBTTagList.class); | ||||
| 				} | ||||
| 				return null; | ||||
| 			} | ||||
| 
 | ||||
| 			@Override | ||||
| 			public void change(NBTTagList[] nbtList, @Nullable Object[] delta, ChangeMode mode) { | ||||
| 				if (delta.length == 0) | ||||
| 					return; | ||||
| 				if (delta[0] instanceof Number) { | ||||
| 					addToList(nbtList[0], convertToNBT((Number) delta[0])); | ||||
| 				} else if (delta[0] instanceof String) { | ||||
| 					addToList(nbtList[0], convertToNBT((String) delta[0])); | ||||
| 				} else if (delta[0] instanceof NBTBase) { | ||||
| 					addToList(nbtList[0], delta[0]); | ||||
| 				} | ||||
| 			} | ||||
| 		}).parser(new Parser<NBTTagList>() { | ||||
| 
 | ||||
| 			@Override | ||||
| 			public String getVariableNamePattern() { | ||||
| 				return ".+"; | ||||
| 			} | ||||
| 
 | ||||
| 			@Override | ||||
| 			@Nullable | ||||
| 			public NBTTagList parse(String listString, ParseContext context) { | ||||
| 				if ((listString.startsWith("nbt:[") || listString.startsWith("nbtlist:[")) && listString.endsWith("]")) { | ||||
| 					int substring; | ||||
| 					if (listString.startsWith("nbt:[")) { | ||||
| 						substring = 4; | ||||
| 					} else { // "nbtlist:[WHATEVER]" | ||||
| 						substring = 8; | ||||
| 					} | ||||
| 					NBTTagCompound tempNBT =  parseRawNBT("{temp:" + listString.substring(substring) + "}"); | ||||
| 					NBTTagList parsedList = (NBTTagList) tempNBT.get("temp"); | ||||
| 					return parsedList; | ||||
| 				} | ||||
| 				return null; | ||||
| 			} | ||||
| 
 | ||||
| 			@Override | ||||
| 			public String toString(NBTTagList nbtList, int arg1) { | ||||
| 				return nbtList.toString(); | ||||
| 			} | ||||
| 
 | ||||
| 			@Override | ||||
| 			public String toVariableNameString(NBTTagList nbtList) { | ||||
| 				return nbtList.toString(); | ||||
| 			} | ||||
| 		}).serializer(new Serializer<NBTTagList>() { | ||||
| 
 | ||||
| 			@Override | ||||
| 			public Fields serialize(NBTTagList nbtList) throws NotSerializableException { | ||||
| 				Fields f = new Fields(); | ||||
| 				f.putObject("asString", nbtList.toString()); | ||||
| 				return f; | ||||
| 			} | ||||
| 
 | ||||
| 			@Override | ||||
| 			public void deserialize(NBTTagList nbtList, Fields f) throws StreamCorruptedException, NotSerializableException { | ||||
| 				assert false; | ||||
| 			} | ||||
| 
 | ||||
| 			@Override | ||||
| 			protected boolean canBeInstantiated() { | ||||
| 				return false; | ||||
| 			} | ||||
| 
 | ||||
| 			@Override | ||||
| 			protected NBTTagList deserialize(Fields fields) throws StreamCorruptedException, NotSerializableException { | ||||
| 				String s = fields.getObject("asString", String.class); | ||||
| 				NBTTagCompound tempNBT =  parseRawNBT("{temp:" + s + "}"); | ||||
| 				if (tempNBT == null || !tempNBT.hasKey("temp")) { | ||||
| 					throw new StreamCorruptedException("Unable to parse NBT list from a variable: " + s); | ||||
| 				} | ||||
| 				NBTTagList nbtList = (NBTTagList) tempNBT.get("temp"); | ||||
| 				return nbtList; | ||||
| 			} | ||||
| 
 | ||||
| 			@Override | ||||
| 			@Nullable | ||||
| 			public NBTTagList deserialize(String s) { | ||||
| 				NBTTagCompound tempNBT =  parseRawNBT("{temp:" + s + "}"); | ||||
| 				NBTTagList nbtList = (NBTTagList) tempNBT.get("temp"); | ||||
| 				return nbtList; | ||||
| 			} | ||||
| 
 | ||||
| 			@Override | ||||
| 			public boolean mustSyncDeserialization() { | ||||
| 				return true; | ||||
| 			} | ||||
| 		})); | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public NBTTagCompound getEntityNBT(Entity entity) { | ||||
| 		net.minecraft.server.v1_12_R1.Entity nmsEntity = ((CraftEntity) entity).getHandle(); | ||||
| 		NBTTagCompound NBT = new NBTTagCompound(); | ||||
| 		nmsEntity.save(NBT); | ||||
| 		return NBT; | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public NBTTagCompound getTileNBT(Block block) { | ||||
| 		NBTTagCompound NBT = new NBTTagCompound(); | ||||
| 		World nmsWorld = ((CraftWorld) block.getWorld()).getHandle(); | ||||
| 		TileEntity tileEntity = nmsWorld.getTileEntity(new BlockPosition(block.getX(), block.getY(), block.getZ())); | ||||
| 		if (tileEntity == null) | ||||
| 			return null; | ||||
| 		tileEntity.save(NBT); | ||||
| 		return NBT; | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public NBTTagCompound getItemNBT(ItemStack itemStack) { | ||||
| 		if (itemStack == null || itemStack.getType() == Material.AIR) | ||||
| 			return null; | ||||
| 		NBTTagCompound itemNBT = CraftItemStack.asNMSCopy(itemStack).getTag(); | ||||
| 		if (itemNBT == null) | ||||
| 			itemNBT = new NBTTagCompound(); | ||||
| 		return itemNBT; | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public void setEntityNBT(Entity entity, Object newCompound) { | ||||
| 		if (newCompound instanceof NBTTagCompound) { | ||||
| 			net.minecraft.server.v1_12_R1.Entity nmsEntity = ((CraftEntity) entity).getHandle(); | ||||
| 			nmsEntity.f((NBTTagCompound) newCompound); | ||||
| 		} | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public void setTileNBT(Block block, Object newCompound) { | ||||
| 		if (newCompound instanceof NBTTagCompound) { | ||||
| 			World nmsWorld = ((CraftWorld) block.getWorld()).getHandle(); | ||||
| 			TileEntity tileEntity = nmsWorld.getTileEntity(new BlockPosition(block.getX(), block.getY(), block.getZ())); | ||||
| 			if (tileEntity == null) | ||||
| 				return; | ||||
| 			tileEntity.a((NBTTagCompound) newCompound); | ||||
| 			tileEntity.update(); | ||||
| 			IBlockData tileEntType = nmsWorld.getType(new BlockPosition(block.getX(), block.getY(), block.getZ())); | ||||
| 			nmsWorld.notify(tileEntity.getPosition(), tileEntType, tileEntType, 3); | ||||
| 		} | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public ItemStack getItemWithNBT(ItemStack itemStack, Object compound) { | ||||
| 		net.minecraft.server.v1_12_R1.ItemStack nmsItem = CraftItemStack.asNMSCopy(itemStack); | ||||
| 		if (compound instanceof NBTTagCompound && itemStack != null) { | ||||
| 			if (itemStack.getType() == Material.AIR) | ||||
| 				return null; | ||||
| 			if (((NBTTagCompound) compound).isEmpty()) | ||||
| 				return itemStack; | ||||
| 			nmsItem.setTag((NBTTagCompound) compound); | ||||
| 			ItemStack newItem = CraftItemStack.asBukkitCopy(nmsItem); | ||||
| 			return newItem; | ||||
| 		} else if (compound == null) { | ||||
| 			nmsItem.setTag(null); | ||||
| 			ItemStack newItem = CraftItemStack.asBukkitCopy(nmsItem); | ||||
| 			return newItem; | ||||
| 		} | ||||
| 		return itemStack; | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public NBTTagCompound getFileNBT(File file) { | ||||
| 		FileInputStream fis = null; | ||||
| 		try { | ||||
| 			fis = new FileInputStream(file); | ||||
| 		} catch (FileNotFoundException ex) { | ||||
| 			return null; //File doesn't exist. | ||||
| 		} | ||||
| 		NBTTagCompound fileNBT = null; | ||||
| 		try { | ||||
| 			fileNBT = NBTCompressedStreamTools.a(fis); | ||||
| 			fis.close(); | ||||
| 		} catch (IOException ex) { | ||||
| 			if (ex instanceof EOFException) { | ||||
| 				; //Nothing. | ||||
| 			} else { | ||||
| 				ex.printStackTrace(); | ||||
| 			} | ||||
| 		} | ||||
| 		return fileNBT; | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public void setFileNBT(File file, Object newCompound) { | ||||
| 		if (newCompound instanceof NBTTagCompound) { | ||||
| 			OutputStream os = null; | ||||
| 			try { | ||||
| 				os = new FileOutputStream(file); | ||||
| 			} catch (FileNotFoundException ex) { | ||||
| 				ex.printStackTrace(); | ||||
| 			} | ||||
| 			try { | ||||
| 				NBTCompressedStreamTools.a((NBTTagCompound) newCompound, os); | ||||
| 				os.close(); | ||||
| 			} catch (IOException ex) { | ||||
| 				if (ex instanceof EOFException) { | ||||
| 					; //Ignore, just end of the file | ||||
| 				} else { | ||||
| 					ex.printStackTrace(); | ||||
| 				} | ||||
| 			} | ||||
| 		} | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public NBTBase convertToNBT(Number number) { | ||||
| 		if (number instanceof Byte) { | ||||
| 			return new NBTTagByte((byte) number); | ||||
| 		} else if (number instanceof Short) { | ||||
| 			return new NBTTagShort((short) number); | ||||
| 		} else if (number instanceof Integer) { | ||||
| 			return new NBTTagInt((int) number); | ||||
| 		} else if (number instanceof Long) { | ||||
| 			return new NBTTagLong((long) number); | ||||
| 		} else if (number instanceof Float) { | ||||
| 			return new NBTTagFloat((float) number); | ||||
| 		} else if (number instanceof Double) { | ||||
| 			return new NBTTagDouble((double) number); | ||||
| 		} | ||||
| 		return null; | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public NBTTagString convertToNBT(String string) { | ||||
| 		return new NBTTagString(string); | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public String getMCId(ItemStack itemStack) { | ||||
| 		net.minecraft.server.v1_12_R1.ItemStack nmsItem = CraftItemStack.asNMSCopy(itemStack); | ||||
| 		MinecraftKey mcKey = Item.REGISTRY.b(nmsItem.getItem()); | ||||
| 		return mcKey.toString(); | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public ItemStack getItemFromMcId(String mcId) { | ||||
| 		MinecraftKey mcKey = new MinecraftKey(mcId); | ||||
| 		Item nmsItem = (Item) Item.REGISTRY.get(mcKey); | ||||
| 		return CraftItemStack.asNewCraftStack(nmsItem); | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public boolean getNoClip(Entity entity) { | ||||
| 		net.minecraft.server.v1_12_R1.Entity nmsEntity = ((CraftEntity) entity).getHandle(); | ||||
| 		return nmsEntity.noclip; | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public void setNoClip(Entity entity, boolean noclip) { | ||||
| 		net.minecraft.server.v1_12_R1.Entity nmsEntity = ((CraftEntity) entity).getHandle(); | ||||
| 		nmsEntity.noclip = noclip; | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public boolean getFireProof(Entity entity) { | ||||
| 		net.minecraft.server.v1_12_R1.Entity nmsEntity = ((CraftEntity) entity).getHandle(); | ||||
| 		return nmsEntity.isFireProof(); | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public void setFireProof(Entity entity, boolean fireProof) { | ||||
| 		net.minecraft.server.v1_12_R1.Entity nmsEntity = ((CraftEntity) entity).getHandle(); | ||||
| 		ReflectionUtils.setField("fireProof", nmsEntity.getClass(), nmsEntity, fireProof); | ||||
| 	} | ||||
| 
 | ||||
| 	/* | ||||
| 	@SuppressWarnings("unchecked") | ||||
| 	@Override | ||||
| 	public ItemStack[] getEndermanBlocks(Entity enderman) { | ||||
| 		EntityEnderman nmsEnder = ((CraftEnderman) enderman).getHandle(); | ||||
| 		Set<net.minecraft.server.v1_12_R1.Block> nmsBlocks = (Set<net.minecraft.server.v1_12_R1.Block>) ReflectionUtils.getField("c", EntityEnderman.class, nmsEnder); | ||||
| 		ItemStack[] items = new ItemStack[nmsBlocks.size()]; | ||||
| 		int i = 0; | ||||
| 		for (net.minecraft.server.v1_12_R1.Block nmsBlock : nmsBlocks) { | ||||
| 			IBlockData nmsBlockData = nmsBlock.getBlockData(); | ||||
| 			int dataValue = nmsBlock.toLegacyData(nmsBlockData); | ||||
| 			net.minecraft.server.v1_12_R1.ItemStack nmsItem = new net.minecraft.server.v1_12_R1.ItemStack(nmsBlock, 1, dataValue); | ||||
| 			ItemStack bukkitItem = CraftItemStack.asCraftMirror(nmsItem); | ||||
| 			items[i] = bukkitItem; | ||||
| 			i++; | ||||
| 		} | ||||
| 		return items; | ||||
| 	} | ||||
| 
 | ||||
| 	@SuppressWarnings("unchecked") | ||||
| 	@Override | ||||
| 	public void setEndermanBlocks(Entity enderman, ItemStack... blocks) { | ||||
| 		EntityEnderman nmsEnder = ((CraftEnderman) enderman).getHandle(); | ||||
| 		Set<net.minecraft.server.v1_12_R1.Block> nmsBlocks = (Set<net.minecraft.server.v1_12_R1.Block>) ReflectionUtils.getField("c", EntityEnderman.class, nmsEnder); | ||||
| 		for (ItemStack block : blocks) { | ||||
| 			if (!block.getType().isBlock()) | ||||
| 				return; | ||||
| 			// TODO Figure out how to get a Blocks from a Bukkit ItemStack | ||||
| 			// Blocks.class has a PRIVATE method to get from a MC id. | ||||
| 		} | ||||
| 	} | ||||
| 	*/ | ||||
| 
 | ||||
| 	@Override | ||||
| 	public Location getLastLocation(Entity entity) { | ||||
| 		net.minecraft.server.v1_12_R1.Entity nmsEntity = ((CraftEntity) entity).getHandle(); | ||||
| 		org.bukkit.World world = nmsEntity.world.getWorld(); | ||||
| 		Location lastEntLoc = new Location(world, nmsEntity.M, nmsEntity.N, nmsEntity.O); | ||||
| 		return lastEntLoc; | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public float getEntityStepLength(Entity entity) { | ||||
| 		net.minecraft.server.v1_12_R1.Entity nmsEntity = ((CraftEntity) entity).getHandle(); | ||||
| 		return nmsEntity.P; | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public void setEntityStepLength(Entity entity, float length) { | ||||
| 		net.minecraft.server.v1_12_R1.Entity nmsEntity = ((CraftEntity) entity).getHandle(); | ||||
| 		nmsEntity.P = length; | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public boolean getElytraGlideState(Entity entity) { | ||||
| 		EntityLiving nmsEntity = ((CraftLivingEntity) entity).getHandle(); | ||||
| 		return nmsEntity.getFlag(7); | ||||
| 	} | ||||
| 
 | ||||
| 	public void setElytraGlideState(Entity entity, boolean glide) { | ||||
| 		EntityLiving nmsEntity = ((CraftLivingEntity) entity).getHandle(); | ||||
| 		nmsEntity.setFlag(7, glide); | ||||
| 	} | ||||
| 
 | ||||
| 	public boolean getNoGravity(Entity entity) { | ||||
| 		net.minecraft.server.v1_12_R1.Entity nmsEntity = ((CraftEntity) entity).getHandle(); | ||||
| 		return nmsEntity.isNoGravity(); | ||||
| 	} | ||||
| 
 | ||||
| 	public void setNoGravity(Entity entity, boolean noGravity) { | ||||
| 		net.minecraft.server.v1_12_R1.Entity nmsEntity = ((CraftEntity) entity).getHandle(); | ||||
| 		nmsEntity.setNoGravity(noGravity); | ||||
| 	} | ||||
| } | ||||
| @ -1,684 +0,0 @@ | ||||
| package me.TheBukor.SkStuff.util; | ||||
| 
 | ||||
| import java.io.EOFException; | ||||
| import java.io.File; | ||||
| import java.io.FileInputStream; | ||||
| import java.io.FileNotFoundException; | ||||
| import java.io.FileOutputStream; | ||||
| import java.io.IOException; | ||||
| import java.io.NotSerializableException; | ||||
| import java.io.OutputStream; | ||||
| import java.io.StreamCorruptedException; | ||||
| import java.util.HashMap; | ||||
| import java.util.Iterator; | ||||
| import java.util.List; | ||||
| import java.util.Set; | ||||
| 
 | ||||
| import javax.annotation.Nullable; | ||||
| 
 | ||||
| import org.bukkit.Bukkit; | ||||
| import org.bukkit.Location; | ||||
| import org.bukkit.Material; | ||||
| import org.bukkit.block.Block; | ||||
| import org.bukkit.craftbukkit.v1_7_R4.CraftWorld; | ||||
| import org.bukkit.craftbukkit.v1_7_R4.entity.CraftEntity; | ||||
| import org.bukkit.craftbukkit.v1_7_R4.inventory.CraftItemStack; | ||||
| import org.bukkit.entity.Entity; | ||||
| import org.bukkit.inventory.ItemStack; | ||||
| 
 | ||||
| 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.classes.Serializer; | ||||
| import ch.njol.skript.lang.ParseContext; | ||||
| import ch.njol.skript.registrations.Classes; | ||||
| import ch.njol.util.coll.CollectionUtils; | ||||
| import ch.njol.yggdrasil.Fields; | ||||
| import net.minecraft.server.v1_7_R4.Item; | ||||
| import net.minecraft.server.v1_7_R4.MojangsonParser; | ||||
| import net.minecraft.server.v1_7_R4.NBTBase; | ||||
| import net.minecraft.server.v1_7_R4.NBTCompressedStreamTools; | ||||
| import net.minecraft.server.v1_7_R4.NBTTagByte; | ||||
| import net.minecraft.server.v1_7_R4.NBTTagCompound; | ||||
| import net.minecraft.server.v1_7_R4.NBTTagDouble; | ||||
| import net.minecraft.server.v1_7_R4.NBTTagFloat; | ||||
| import net.minecraft.server.v1_7_R4.NBTTagInt; | ||||
| import net.minecraft.server.v1_7_R4.NBTTagList; | ||||
| import net.minecraft.server.v1_7_R4.NBTTagLong; | ||||
| import net.minecraft.server.v1_7_R4.NBTTagShort; | ||||
| import net.minecraft.server.v1_7_R4.NBTTagString; | ||||
| import net.minecraft.server.v1_7_R4.TileEntity; | ||||
| import net.minecraft.server.v1_7_R4.World; | ||||
| 
 | ||||
| public class NMS_v1_7_R4 implements NMSInterface { | ||||
| 
 | ||||
| 	@Override | ||||
| 	public Object getNBTTag(Object compound, String tag) { | ||||
| 		if (compound instanceof NBTTagCompound) { | ||||
| 			return ((NBTTagCompound) compound).get(tag); | ||||
| 		} | ||||
| 		return null; | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public void setNBTTag(Object compound, String tag, Object toSet) { | ||||
| 		if (compound instanceof NBTTagCompound && (toSet instanceof NBTBase || toSet instanceof Number || toSet instanceof String)) { | ||||
| 			NBTBase converted = null; | ||||
| 			if (toSet instanceof Number) { | ||||
| 				converted = convertToNBT((Number) toSet); | ||||
| 			} else if (toSet instanceof String) { | ||||
| 				converted = convertToNBT((String) toSet); | ||||
| 			} else { //Already an NBTBase | ||||
| 				converted = (NBTBase) toSet; //No need to convert anything | ||||
| 			} | ||||
| 			((NBTTagCompound) compound).set(tag, converted); | ||||
| 		} | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public void removeNBTTag(Object compound, String tag) { | ||||
| 		if (compound instanceof NBTTagCompound) { | ||||
| 			((NBTTagCompound) compound).remove(tag); | ||||
| 		} | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public byte getTypeId(Object nbtBase) { | ||||
| 		if (nbtBase instanceof NBTBase) { | ||||
| 			return ((NBTBase) nbtBase).getTypeId(); | ||||
| 		} | ||||
| 		return 0; | ||||
| 	} | ||||
| 
 | ||||
| 	 @Override | ||||
| 	public Object getNBTTagValue(Object compound, String tag, byte typeId) { | ||||
| 		if (compound instanceof NBTTagCompound) { | ||||
| 			switch (typeId) { | ||||
| 			case 1: | ||||
| 				return ((NBTTagCompound) compound).getByte(tag); | ||||
| 			case 2: | ||||
| 				return ((NBTTagCompound) compound).getShort(tag); | ||||
| 			case 3: | ||||
| 				return ((NBTTagCompound) compound).getInt(tag); | ||||
| 			case 4: | ||||
| 				return ((NBTTagCompound) compound).getLong(tag); | ||||
| 			case 5: | ||||
| 				return ((NBTTagCompound) compound).getFloat(tag); | ||||
| 			case 6: | ||||
| 				return ((NBTTagCompound) compound).getDouble(tag); | ||||
| 			case 7: //Byte array, only used in chunk files. Also doesn't have support for the MojangsonParser. | ||||
| 				break; | ||||
| 			case 8: | ||||
| 				return ((NBTTagCompound) compound).getString(tag); | ||||
| 			case 9: | ||||
| 				int i; | ||||
| 				NBTTagList list = null; | ||||
| 				for (i = 1; i <= 11; i++) { //To get a list I need to know the type of the tags it contains inside, | ||||
| 					//since I can't predict what type the list will have, I just loop all of the IDs until I find a non-empty list. | ||||
| 					list = ((NBTTagCompound) compound).getList(tag, i); //Try to get the list with the ID "loop-number". | ||||
| 					if (!list.toString().equals("[]")) { //If list is not empty. | ||||
| 						break; //Stop loop. | ||||
| 					} | ||||
| 				} | ||||
| 				return list; //May be null | ||||
| 			case 10: | ||||
| 				return ((NBTTagCompound) compound).getCompound(tag); | ||||
| 			case 11: //Integer array, this one is only used on the chunk files (and maybe schematic files?). | ||||
| 				return ((NBTTagCompound) compound).getIntArray(tag); | ||||
| 			default: //This should never happen, but it's better to have this just in case it spills errors everywhere. | ||||
| 				break; | ||||
| 			} | ||||
| 		} | ||||
| 		return null; | ||||
| 	} | ||||
| 
 | ||||
| 	@SuppressWarnings("unchecked") | ||||
| 	@Override | ||||
| 	public void addToCompound(Object compound, Object toAdd) { | ||||
| 		if (compound instanceof NBTTagCompound && toAdd instanceof NBTTagCompound) { | ||||
| 			HashMap<String, Object> map = (HashMap<String, Object>) ReflectionUtils.getField("map", NBTTagCompound.class, toAdd); | ||||
| 			Set<String> keySet = ((NBTTagCompound) toAdd).c(); | ||||
| 			Iterator<String> iterator = keySet.iterator(); | ||||
| 
 | ||||
| 			while(iterator.hasNext()) { | ||||
| 				String string = (String) iterator.next(); | ||||
| 				NBTBase base = (NBTBase) map.get(string); | ||||
| 				if(base.getTypeId() == 10) { | ||||
| 					if(((NBTTagCompound) compound).hasKeyOfType(string, 10)) { | ||||
| 						NBTTagCompound localNBT = ((NBTTagCompound) compound).getCompound(string); | ||||
| 						addToCompound(localNBT, (NBTTagCompound) base); | ||||
| 					} else { | ||||
| 						((NBTTagCompound) compound).set(string, base.clone()); | ||||
| 					} | ||||
| 				} else { | ||||
| 					((NBTTagCompound) compound).set(string, base.clone()); | ||||
| 				} | ||||
| 			} | ||||
| 		} | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public void removeFromCompound(Object compound, String ... toRemove) { | ||||
| 		if (compound instanceof NBTTagCompound) { | ||||
| 			for (String s : toRemove) { | ||||
| 				((NBTTagCompound) compound).remove(s); | ||||
| 			} | ||||
| 		} | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public NBTTagCompound parseRawNBT(String rawNBT) { | ||||
| 		NBTTagCompound parsedNBT = null; | ||||
| 		parsedNBT = (NBTTagCompound) MojangsonParser.parse(rawNBT); | ||||
| 		return parsedNBT; | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public Object[] getContents(Object nbtList) { | ||||
| 		if (nbtList instanceof NBTTagList) { | ||||
| 			Object[] contents = new Object[((NBTTagList) nbtList).size()]; | ||||
| 			for (int i = 0; i < ((NBTTagList) nbtList).size(); i++) { | ||||
| 				if (getIndex(nbtList, i) != null) { | ||||
| 					contents[i] = getIndex(nbtList, i); | ||||
| 				} | ||||
| 			} | ||||
| 			return contents; | ||||
| 		} | ||||
| 		return null; | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public void addToList(Object nbtList, Object toAdd) { | ||||
| 		if (nbtList instanceof NBTTagList && toAdd instanceof NBTBase) { | ||||
| 			((NBTTagList) nbtList).add((NBTBase) toAdd); | ||||
| 		} | ||||
| 	} | ||||
| 
 | ||||
| 	@SuppressWarnings("unchecked") | ||||
| 	@Override | ||||
| 	public void removeFromList(Object nbtList, int index) { | ||||
| 		if (nbtList instanceof NBTTagList && index >= 0 && index < ((NBTTagList) nbtList).size()) { | ||||
| 			List<Object> actualList = null; | ||||
| 			actualList = (List<Object>) ReflectionUtils.getField("list", NBTTagList.class, nbtList); | ||||
| 			actualList.remove(index); | ||||
| 		} | ||||
| 	} | ||||
| 
 | ||||
| 	@SuppressWarnings("unchecked") | ||||
| 	@Override | ||||
| 	public void setIndex(Object nbtList, int index, Object toSet) { | ||||
| 		if (nbtList instanceof NBTTagList && index >= 0 && index < ((NBTTagList) nbtList).size()) { | ||||
| 			int typeId = ((NBTTagList) nbtList).d(); //Contents ID | ||||
| 			NBTBase toSetNBT = null; | ||||
| 			if (toSet instanceof NBTBase) | ||||
| 				toSetNBT = (NBTBase) toSet; | ||||
| 			else if (toSet instanceof Number) | ||||
| 				toSetNBT = (NBTBase) convertToNBT((Number) toSet); | ||||
| 			else if (toSet instanceof String) | ||||
| 				toSetNBT = convertToNBT((String) toSet); | ||||
| 			else | ||||
| 				return; | ||||
| 			int toSetId = (toSetNBT).getTypeId(); | ||||
| 			if (typeId == 0) { | ||||
| 				ReflectionUtils.setField("type", NBTTagList.class, nbtList, toSetId); | ||||
| 			} else if (typeId != toSetId) { | ||||
| 				Skript.warning("Adding mismatching tag types to NBT list"); | ||||
| 				return; | ||||
| 			} | ||||
| 			List<Object> actualList = (List<Object>) ReflectionUtils.getField("list", NBTTagList.class, nbtList); | ||||
| 			actualList.set(index, toSetNBT); | ||||
| 		} | ||||
| 	} | ||||
| 
 | ||||
| 	@SuppressWarnings("unchecked") | ||||
| 	@Override | ||||
| 	public Object getIndex(Object nbtList, int index) { | ||||
| 		if (nbtList instanceof NBTTagList && index >= 0 && index < ((NBTTagList) nbtList).size()) { | ||||
| 			List<NBTBase> actualList = null; | ||||
| 			actualList = (List<NBTBase>) ReflectionUtils.getField("list", NBTTagList.class, nbtList); | ||||
| 			NBTBase value = (NBTBase) actualList.get(index); | ||||
| 			return value; | ||||
| 		} | ||||
| 		return null; | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public void clearPathfinderGoals(Entity entity) { | ||||
| 		Bukkit.getLogger().warning("Sorry, Pathfinder Goal are only supported in 1.8 and above"); | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public void removePathfinderGoal(Object entity, Class<?> goalClass, boolean isTargetSelector) { | ||||
| 		Bukkit.getLogger().warning("Sorry, Pathfinder Goals are only supported in 1.8 and above"); | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public void addPathfinderGoal(Object entity, int priority, Object goal, boolean isTargetSelector) { | ||||
| 		Bukkit.getLogger().warning("Sorry, Pathfinder Goals are only supported in 1.8 and above"); | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public void registerCompoundClassInfo() { | ||||
| 		Classes.registerClass(new ClassInfo<NBTTagCompound>(NBTTagCompound.class, "compound").user("((nbt)?( ?tag)?) ?compounds?").name("NBT Compound").changer(new Changer<NBTTagCompound>() { | ||||
| 
 | ||||
| 			@SuppressWarnings("unchecked") | ||||
| 			@Override | ||||
| 			@Nullable | ||||
| 			public Class<?>[] acceptChange(ChangeMode mode) { | ||||
| 				if (mode == ChangeMode.ADD || mode == ChangeMode.REMOVE) { | ||||
| 					return CollectionUtils.array(String.class, NBTTagCompound.class); | ||||
| 				} | ||||
| 				return null; | ||||
| 			} | ||||
| 
 | ||||
| 			@Override | ||||
| 			public void change(NBTTagCompound[] NBT, @Nullable Object[] delta, ChangeMode mode) { | ||||
| 				if (mode == ChangeMode.ADD) { | ||||
| 					if (delta[0] instanceof String) { | ||||
| 						NBTTagCompound parsedNBT = parseRawNBT((String) delta[0]); | ||||
| 						addToCompound(NBT[0], parsedNBT); | ||||
| 					} else { | ||||
| 						addToCompound(NBT[0], delta[0]); | ||||
| 					} | ||||
| 				} else if (mode == ChangeMode.REMOVE) { | ||||
| 					if (delta[0] instanceof NBTTagCompound) | ||||
| 						return; | ||||
| 					for (Object s : delta) { | ||||
| 						NBT[0].remove((String) s); | ||||
| 					} | ||||
| 				} | ||||
| 			} | ||||
| 		}).parser(new Parser<NBTTagCompound>() { | ||||
| 
 | ||||
| 			@Override | ||||
| 			public String getVariableNamePattern() { | ||||
| 				return ".+"; | ||||
| 			} | ||||
| 
 | ||||
| 			@Override | ||||
| 			@Nullable | ||||
| 			public NBTTagCompound parse(String rawNBT, ParseContext context) { | ||||
| 				if (rawNBT.startsWith("nbt:{") && rawNBT.endsWith("}")) { | ||||
| 					NBTTagCompound NBT = parseRawNBT(rawNBT.substring(4)); | ||||
| 					return NBT; | ||||
| 				} | ||||
| 				return null; | ||||
| 			} | ||||
| 
 | ||||
| 			@Override | ||||
| 			public String toString(NBTTagCompound compound, int arg1) { | ||||
| 				return compound.toString(); | ||||
| 			} | ||||
| 
 | ||||
| 			@Override | ||||
| 			public String toVariableNameString(NBTTagCompound compound) { | ||||
| 				return compound.toString(); | ||||
| 			} | ||||
| 		}).serializer(new Serializer<NBTTagCompound>() { | ||||
| 
 | ||||
| 				@Override | ||||
| 				public Fields serialize(NBTTagCompound compound) throws NotSerializableException { | ||||
| 					Fields f = new Fields(); | ||||
| 					f.putObject("asString", compound.toString()); | ||||
| 					return f; | ||||
| 				} | ||||
| 
 | ||||
| 				@Override | ||||
| 				public void deserialize(NBTTagCompound compound, Fields f) throws StreamCorruptedException, NotSerializableException { | ||||
| 					assert false; | ||||
| 				} | ||||
| 
 | ||||
| 				@Override | ||||
| 				protected boolean canBeInstantiated() { | ||||
| 					return false; | ||||
| 				} | ||||
| 
 | ||||
| 				@Override | ||||
| 				protected NBTTagCompound deserialize(Fields fields) throws StreamCorruptedException, NotSerializableException { | ||||
| 					String raw = fields.getObject("asString", String.class); | ||||
| 					NBTTagCompound compound =  parseRawNBT(raw); | ||||
| 					if (compound == null) { | ||||
| 						throw new StreamCorruptedException("Unable to parse NBT compound from a variable: " + raw); | ||||
| 					} | ||||
| 					return compound; | ||||
| 				} | ||||
| 
 | ||||
| 				@Override | ||||
| 				@Nullable | ||||
| 				public NBTTagCompound deserialize(String s) { | ||||
| 					NBTTagCompound compound =  parseRawNBT(s); | ||||
| 					return compound; | ||||
| 				} | ||||
| 
 | ||||
| 				@Override | ||||
| 				public boolean mustSyncDeserialization() { | ||||
| 					return true; | ||||
| 				} | ||||
| 			})); | ||||
| 
 | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public void registerNBTListClassInfo() { | ||||
| 		Classes.registerClass(new ClassInfo<NBTTagList>(NBTTagList.class, "nbtlist").user("nbt ?list ?(tag)?").name("NBT List").changer(new Changer<NBTTagList>() { | ||||
| 
 | ||||
| 			@SuppressWarnings("unchecked") | ||||
| 			@Override | ||||
| 			@Nullable | ||||
| 			public Class<?>[] acceptChange(ChangeMode mode) { | ||||
| 				if (mode == ChangeMode.ADD) { | ||||
| 					return CollectionUtils.array(Byte.class, Short.class, Integer.class, Long.class, Float.class, Double.class, String.class, NBTBase.class); | ||||
| 				} | ||||
| 				return null; | ||||
| 			} | ||||
| 
 | ||||
| 			@Override | ||||
| 			public void change(NBTTagList[] nbtList, @Nullable Object[] delta, ChangeMode mode) { | ||||
| 				if (delta.length == 0) | ||||
| 					return; | ||||
| 				if (delta[0] instanceof Number) { | ||||
| 					addToList(nbtList, convertToNBT((Number) delta[0])); | ||||
| 				} else if (delta[0] instanceof String) { | ||||
| 					addToList(nbtList, convertToNBT((String) delta[0])); | ||||
| 				} else if (delta[0] instanceof NBTBase) { | ||||
| 					addToList(nbtList, delta[0]); | ||||
| 				} | ||||
| 			} | ||||
| 		}).parser(new Parser<NBTTagList>() { | ||||
| 
 | ||||
| 			@Override | ||||
| 			public String getVariableNamePattern() { | ||||
| 				return ".+"; | ||||
| 			} | ||||
| 
 | ||||
| 			@Override | ||||
| 			@Nullable | ||||
| 			public NBTTagList parse(String listString, ParseContext context) { | ||||
| 				if ((listString.startsWith("nbt:[") || listString.startsWith("nbtlist:[")) && listString.endsWith("]")) { | ||||
| 					int substring; | ||||
| 					if (listString.startsWith("nbt:[")) { | ||||
| 						substring = 4; | ||||
| 					} else { // "nbtlist:[WHATEVER]" | ||||
| 						substring = 8; | ||||
| 					} | ||||
| 					NBTTagCompound tempNBT =  parseRawNBT("{temp:" + listString.substring(substring) + "}"); | ||||
| 					NBTTagList parsedList = (NBTTagList) tempNBT.get("temp"); | ||||
| 					return parsedList; | ||||
| 				} | ||||
| 				return null; | ||||
| 			} | ||||
| 
 | ||||
| 			@Override | ||||
| 			public String toString(NBTTagList nbtList, int arg1) { | ||||
| 				return nbtList.toString(); | ||||
| 			} | ||||
| 
 | ||||
| 			@Override | ||||
| 			public String toVariableNameString(NBTTagList nbtList) { | ||||
| 				return nbtList.toString(); | ||||
| 			} | ||||
| 		}).serializer(new Serializer<NBTTagList>() { | ||||
| 
 | ||||
| 			@Override | ||||
| 			public Fields serialize(NBTTagList nbtList) throws NotSerializableException { | ||||
| 				Fields f = new Fields(); | ||||
| 				f.putObject("asString", nbtList.toString()); | ||||
| 				return f; | ||||
| 			} | ||||
| 
 | ||||
| 			@Override | ||||
| 			public void deserialize(NBTTagList nbtList, Fields f) throws StreamCorruptedException, NotSerializableException { | ||||
| 				assert false; | ||||
| 			} | ||||
| 
 | ||||
| 			@Override | ||||
| 			protected boolean canBeInstantiated() { | ||||
| 				return false; | ||||
| 			} | ||||
| 
 | ||||
| 			@Override | ||||
| 			protected NBTTagList deserialize(Fields fields) throws StreamCorruptedException, NotSerializableException { | ||||
| 				String s = fields.getObject("asString", String.class); | ||||
| 				NBTTagCompound tempNBT =  parseRawNBT("{temp:" + s + "}"); | ||||
| 				if (tempNBT == null || !tempNBT.hasKey("temp")) { | ||||
| 					throw new StreamCorruptedException("Unable to parse NBT list from a variable: " + s); | ||||
| 				} | ||||
| 				NBTTagList nbtList = (NBTTagList) tempNBT.get("temp"); | ||||
| 				return nbtList; | ||||
| 			} | ||||
| 
 | ||||
| 			@Override | ||||
| 			@Nullable | ||||
| 			public NBTTagList deserialize(String s) { | ||||
| 				NBTTagCompound tempNBT =  parseRawNBT("{temp:" + s + "}"); | ||||
| 				NBTTagList nbtList = (NBTTagList) tempNBT.get("temp"); | ||||
| 				return nbtList; | ||||
| 			} | ||||
| 
 | ||||
| 			@Override | ||||
| 			public boolean mustSyncDeserialization() { | ||||
| 				return true; | ||||
| 			} | ||||
| 		})); | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public NBTTagCompound getEntityNBT(Entity entity) { | ||||
| 		net.minecraft.server.v1_7_R4.Entity nmsEntity = ((CraftEntity) entity).getHandle(); | ||||
| 		NBTTagCompound NBT = new NBTTagCompound(); | ||||
| 		nmsEntity.e(NBT); | ||||
| 		return NBT; | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public NBTTagCompound getTileNBT(Block block) { | ||||
| 		NBTTagCompound NBT = new NBTTagCompound(); | ||||
| 		World nmsWorld = ((CraftWorld) block.getWorld()).getHandle(); | ||||
| 		TileEntity tileEntity = nmsWorld.getTileEntity(block.getX(), block.getY(), block.getZ()); | ||||
| 		if (tileEntity == null) | ||||
| 			return null; | ||||
| 		tileEntity.b(NBT); | ||||
| 		return NBT; | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public NBTTagCompound getItemNBT(ItemStack itemStack) { | ||||
| 		if (itemStack == null || itemStack.getType() == Material.AIR) | ||||
| 			return null; | ||||
| 		NBTTagCompound itemNBT = CraftItemStack.asNMSCopy(itemStack).getTag(); | ||||
| 		if (itemNBT == null) | ||||
| 			itemNBT = new NBTTagCompound(); | ||||
| 		return itemNBT; | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public void setEntityNBT(Entity entity, Object newCompound) { | ||||
| 		if (newCompound instanceof NBTTagCompound) { | ||||
| 			net.minecraft.server.v1_7_R4.Entity nmsEntity = ((CraftEntity) entity).getHandle(); | ||||
| 			nmsEntity.f((NBTTagCompound) newCompound); | ||||
| 		} | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public void setTileNBT(Block block, Object newCompound) { | ||||
| 		if (newCompound instanceof NBTTagCompound) { | ||||
| 			World nmsWorld = ((CraftWorld) block.getWorld()).getHandle(); | ||||
| 			TileEntity tileEntity = nmsWorld.getTileEntity(block.getX(), block.getY(), block.getZ()); | ||||
| 			if (tileEntity == null) | ||||
| 				return; | ||||
| 			tileEntity.a((NBTTagCompound) newCompound); | ||||
| 			tileEntity.update(); | ||||
| 			nmsWorld.notify(tileEntity.x, tileEntity.y, tileEntity.z); | ||||
| 		} | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public ItemStack getItemWithNBT(ItemStack itemStack, Object compound) { | ||||
| 		net.minecraft.server.v1_7_R4.ItemStack nmsItem = CraftItemStack.asNMSCopy(itemStack); | ||||
| 		if (compound instanceof NBTTagCompound && itemStack != null) { | ||||
| 			if (itemStack.getType() == Material.AIR) | ||||
| 				return null; | ||||
| 			if (((NBTTagCompound) compound).isEmpty()) | ||||
| 				return itemStack; | ||||
| 			nmsItem.setTag((NBTTagCompound) compound); | ||||
| 			ItemStack newItem = CraftItemStack.asBukkitCopy(nmsItem); | ||||
| 			return newItem; | ||||
| 		} else if (compound == null) { | ||||
| 			nmsItem.setTag(null); | ||||
| 			ItemStack newItem = CraftItemStack.asBukkitCopy(nmsItem); | ||||
| 			return newItem; | ||||
| 		} | ||||
| 		return itemStack; | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public NBTTagCompound getFileNBT(File file) { | ||||
| 		FileInputStream fis = null; | ||||
| 		try { | ||||
| 			fis = new FileInputStream(file); | ||||
| 		} catch (FileNotFoundException ex) { | ||||
| 			return null; //File doesn't exist. | ||||
| 		} | ||||
| 		NBTTagCompound fileNBT = null; | ||||
| 		try { | ||||
| 			fileNBT = NBTCompressedStreamTools.a(fis); | ||||
| 			fis.close(); | ||||
| 		} catch (IOException ex) { | ||||
| 			ex.printStackTrace(); | ||||
| 		} finally { | ||||
| 			try { | ||||
| 				fis.close(); | ||||
| 			} catch (IOException ex) { | ||||
| 				ex.printStackTrace(); | ||||
| 			} | ||||
| 		} | ||||
| 		return fileNBT; | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public void setFileNBT(File file, Object newCompound) { | ||||
| 		OutputStream os = null; | ||||
| 		try { | ||||
| 			os = new FileOutputStream(file); | ||||
| 		} catch (FileNotFoundException ex) { | ||||
| 			ex.printStackTrace(); | ||||
| 		} | ||||
| 		try { | ||||
| 			NBTCompressedStreamTools.a((NBTTagCompound) newCompound, os); | ||||
| 			os.close(); | ||||
| 		} catch (Exception ex) { | ||||
| 			if (ex instanceof EOFException) { | ||||
| 				; //Ignore, just end of the file | ||||
| 			} else { | ||||
| 				ex.printStackTrace(); | ||||
| 			} | ||||
| 		} finally { | ||||
| 			try { | ||||
| 				os.close(); | ||||
| 			} catch (Exception ex) { | ||||
| 				if (ex instanceof EOFException) { | ||||
| 					; //Ignore. | ||||
| 				} else { | ||||
| 					ex.printStackTrace(); | ||||
| 				} | ||||
| 			} | ||||
| 		} | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public NBTBase convertToNBT(Number number) { | ||||
| 		if (number instanceof Byte) { | ||||
| 			return new NBTTagByte((byte) number); | ||||
| 		} else if (number instanceof Short) { | ||||
| 			return new NBTTagShort((short) number); | ||||
| 		} else if (number instanceof Integer) { | ||||
| 			return new NBTTagInt((int) number); | ||||
| 		} else if (number instanceof Long) { | ||||
| 			return new NBTTagLong((long) number); | ||||
| 		} else if (number instanceof Float) { | ||||
| 			return new NBTTagFloat((float) number); | ||||
| 		} else if (number instanceof Double) { | ||||
| 			return new NBTTagDouble((double) number); | ||||
| 		} | ||||
| 		return null; | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public NBTTagString convertToNBT(String string) { | ||||
| 		return new NBTTagString(string); | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public String getMCId(ItemStack itemStack) { | ||||
| 		net.minecraft.server.v1_7_R4.ItemStack nmsItem = CraftItemStack.asNMSCopy(itemStack); | ||||
| 		String test = Item.REGISTRY.c(nmsItem.getItem()); | ||||
| 		return test; | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public ItemStack getItemFromMcId(String mcId) { | ||||
| 		return null; //Not supported in 1.7 | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public boolean getNoClip(Entity entity) { | ||||
| 		return false; //Not supported in 1.7 | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public void setNoClip(Entity entity, boolean noclip) { | ||||
| 		return; //Not supported in 1.7 | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public boolean getFireProof(Entity entity) { | ||||
| 		net.minecraft.server.v1_7_R4.Entity nmsEntity = ((CraftEntity) entity).getHandle(); | ||||
| 		return (boolean) ReflectionUtils.getField("fireProof", nmsEntity.getClass(), nmsEntity); | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public void setFireProof(Entity entity, boolean fireProof) { | ||||
| 		net.minecraft.server.v1_7_R4.Entity nmsEntity = ((CraftEntity) entity).getHandle(); | ||||
| 		ReflectionUtils.setField("fireProof", nmsEntity.getClass(), nmsEntity, fireProof); | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public Location getLastLocation(Entity entity) { | ||||
| 		net.minecraft.server.v1_7_R4.Entity nmsEntity = ((CraftEntity) entity).getHandle(); | ||||
| 		org.bukkit.World world = nmsEntity.world.getWorld(); | ||||
| 		Location lastEntLoc = new Location(world, nmsEntity.S, nmsEntity.T, nmsEntity.U); | ||||
| 		return lastEntLoc; | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public float getEntityStepLength(Entity entity) { | ||||
| 		net.minecraft.server.v1_7_R4.Entity nmsEntity = ((CraftEntity) entity).getHandle(); | ||||
| 		return nmsEntity.V; | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public void setEntityStepLength(Entity entity, float length) { | ||||
| 		net.minecraft.server.v1_7_R4.Entity nmsEntity = ((CraftEntity) entity).getHandle(); | ||||
| 		nmsEntity.V = length; | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public boolean getElytraGlideState(Entity entity) { | ||||
| 		Bukkit.getLogger().warning("Executed \"Get elytra glide state\" code on 1.7! How the hell did this even happen!!"); | ||||
| 		return false; | ||||
| 	} | ||||
| 	 | ||||
| 	public void setElytraGlideState(Entity entity, boolean glide) { | ||||
| 		Bukkit.getLogger().warning("Executed \"Set elytra glide state\" code on 1.7! How the hell did this even happen!!"); | ||||
| 	} | ||||
| 	 | ||||
| 	public boolean getNoGravity(Entity entity) { | ||||
| 		Bukkit.getLogger().warning("Executed \"Get no gravity state of entity\" code on 1.7! How the hell did this even happen!!"); | ||||
| 		return false; | ||||
| 	} | ||||
| 	 | ||||
| 	public void setNoGravity(Entity entity, boolean noGravity) { | ||||
| 		Bukkit.getLogger().warning("Executed \"Set no gravity state of entity\" code on 1.7! How the hell did this even happen!!"); | ||||
| 	} | ||||
| } | ||||
| @ -1,693 +0,0 @@ | ||||
| package me.TheBukor.SkStuff.util; | ||||
| 
 | ||||
| import java.io.EOFException; | ||||
| import java.io.File; | ||||
| import java.io.FileInputStream; | ||||
| import java.io.FileNotFoundException; | ||||
| import java.io.FileOutputStream; | ||||
| import java.io.IOException; | ||||
| import java.io.NotSerializableException; | ||||
| import java.io.OutputStream; | ||||
| import java.io.StreamCorruptedException; | ||||
| import java.util.Iterator; | ||||
| import java.util.List; | ||||
| 
 | ||||
| import javax.annotation.Nullable; | ||||
| 
 | ||||
| import org.bukkit.Bukkit; | ||||
| import org.bukkit.Location; | ||||
| 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.inventory.ItemStack; | ||||
| 
 | ||||
| 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.classes.Serializer; | ||||
| import ch.njol.skript.lang.ParseContext; | ||||
| import ch.njol.skript.registrations.Classes; | ||||
| import ch.njol.util.coll.CollectionUtils; | ||||
| import ch.njol.yggdrasil.Fields; | ||||
| import net.minecraft.server.v1_8_R3.BlockPosition; | ||||
| import net.minecraft.server.v1_8_R3.EntityInsentient; | ||||
| import net.minecraft.server.v1_8_R3.Item; | ||||
| import net.minecraft.server.v1_8_R3.MinecraftKey; | ||||
| import net.minecraft.server.v1_8_R3.MojangsonParseException; | ||||
| import net.minecraft.server.v1_8_R3.MojangsonParser; | ||||
| import net.minecraft.server.v1_8_R3.NBTBase; | ||||
| import net.minecraft.server.v1_8_R3.NBTCompressedStreamTools; | ||||
| import net.minecraft.server.v1_8_R3.NBTTagByte; | ||||
| import net.minecraft.server.v1_8_R3.NBTTagCompound; | ||||
| import net.minecraft.server.v1_8_R3.NBTTagDouble; | ||||
| import net.minecraft.server.v1_8_R3.NBTTagFloat; | ||||
| import net.minecraft.server.v1_8_R3.NBTTagInt; | ||||
| import net.minecraft.server.v1_8_R3.NBTTagList; | ||||
| import net.minecraft.server.v1_8_R3.NBTTagLong; | ||||
| import net.minecraft.server.v1_8_R3.NBTTagShort; | ||||
| import net.minecraft.server.v1_8_R3.NBTTagString; | ||||
| import net.minecraft.server.v1_8_R3.PathfinderGoal; | ||||
| import net.minecraft.server.v1_8_R3.PathfinderGoalSelector; | ||||
| import net.minecraft.server.v1_8_R3.TileEntity; | ||||
| import net.minecraft.server.v1_8_R3.World; | ||||
| 
 | ||||
| public class NMS_v1_8_R3 implements NMSInterface { | ||||
| 
 | ||||
| 	@Override | ||||
| 	public Object getNBTTag(Object compound, String tag) { | ||||
| 		if (compound instanceof NBTTagCompound) { | ||||
| 			return ((NBTTagCompound) compound).get(tag); | ||||
| 		} | ||||
| 		return null; | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public void setNBTTag(Object compound, String tag, Object toSet) { | ||||
| 		if (compound instanceof NBTTagCompound && (toSet instanceof NBTBase || toSet instanceof Number || toSet instanceof String)) { | ||||
| 			NBTBase converted = null; | ||||
| 			if (toSet instanceof Number) { | ||||
| 				converted = convertToNBT((Number) toSet); | ||||
| 			} else if (toSet instanceof String) { | ||||
| 				converted = convertToNBT((String) toSet); | ||||
| 			} else { //Already an NBTBase | ||||
| 				converted = (NBTBase) toSet; //No need to convert anything | ||||
| 			} | ||||
| 			((NBTTagCompound) compound).set(tag, converted); | ||||
| 		} | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public void removeNBTTag(Object compound, String tag) { | ||||
| 		if (compound instanceof NBTTagCompound) { | ||||
| 			((NBTTagCompound) compound).remove(tag); | ||||
| 		} | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public byte getTypeId(Object nbtBase) { | ||||
| 		if (nbtBase instanceof NBTBase) { | ||||
| 			return ((NBTBase) nbtBase).getTypeId(); | ||||
| 		} | ||||
| 		return 0; | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public Object getNBTTagValue(Object compound, String tag, byte typeId) { | ||||
| 		if (compound instanceof NBTTagCompound) { | ||||
| 			switch (typeId) { | ||||
| 			case 1: | ||||
| 				return ((NBTTagCompound) compound).getByte(tag); | ||||
| 			case 2: | ||||
| 				return ((NBTTagCompound) compound).getShort(tag); | ||||
| 			case 3: | ||||
| 				return ((NBTTagCompound) compound).getInt(tag); | ||||
| 			case 4: | ||||
| 				return ((NBTTagCompound) compound).getLong(tag); | ||||
| 			case 5: | ||||
| 				return ((NBTTagCompound) compound).getFloat(tag); | ||||
| 			case 6: | ||||
| 				return ((NBTTagCompound) compound).getDouble(tag); | ||||
| 			case 7: //Byte array, only used in chunk files. Also doesn't have support for the MojangsonParser. | ||||
| 				break; | ||||
| 			case 8: | ||||
| 				return ((NBTTagCompound) compound).getString(tag); | ||||
| 			case 9: | ||||
| 				int i; | ||||
| 				NBTTagList list = null; | ||||
| 				for (i = 1; i <= 11; i++) { //To get a list I need to know the type of the tags it contains inside, | ||||
| 					//since I can't predict what type the list will have, I just loop all of the IDs until I find a non-empty list. | ||||
| 					list = ((NBTTagCompound) compound).getList(tag, i); //Try to get the list with the ID "loop-number". | ||||
| 					if (!list.isEmpty()) { //If list is not empty. | ||||
| 						break; //Stop loop. | ||||
| 					} | ||||
| 				} | ||||
| 				return list; //May be null | ||||
| 			case 10: | ||||
| 				return ((NBTTagCompound) compound).getCompound(tag); | ||||
| 			case 11: //Integer array, this one is only used on the chunk files (and maybe schematic files?). | ||||
| 				return ((NBTTagCompound) compound).getIntArray(tag); | ||||
| 			default: //This should never happen, but it's better to have this just in case it spills errors everywhere. | ||||
| 				break; | ||||
| 			} | ||||
| 		} | ||||
| 		return null; | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public void addToCompound(Object compound, Object toAdd) { | ||||
| 		if (compound instanceof NBTTagCompound && toAdd instanceof NBTTagCompound) { | ||||
| 			((NBTTagCompound) compound).a((NBTTagCompound) toAdd); | ||||
| 		} | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public void removeFromCompound(Object compound, String ... toRemove) { | ||||
| 		if (compound instanceof NBTTagCompound) { | ||||
| 			for (String s : toRemove) { | ||||
| 				((NBTTagCompound) compound).remove(s); | ||||
| 			} | ||||
| 		} | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public NBTTagCompound parseRawNBT(String rawNBT) { | ||||
| 		NBTTagCompound parsedNBT = null; | ||||
| 		try { | ||||
| 			parsedNBT = MojangsonParser.parse(rawNBT); | ||||
| 		} catch (MojangsonParseException ex) { | ||||
| 			Skript.warning("Error when parsing NBT - " + ex.getMessage()); | ||||
| 			return null; | ||||
| 		} | ||||
| 		return parsedNBT; | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public Object[] getContents(Object nbtList) { | ||||
| 		if (nbtList instanceof NBTTagList) { | ||||
| 			Object[] contents = new Object[((NBTTagList) nbtList).size()]; | ||||
| 			for (int i = 0; i < ((NBTTagList) nbtList).size(); i++) { | ||||
| 				if (getIndex(nbtList, i) != null) { | ||||
| 					contents[i] = getIndex(nbtList, i); | ||||
| 				} | ||||
| 			} | ||||
| 			return contents; | ||||
| 		} | ||||
| 		return null; | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public void addToList(Object nbtList, Object toAdd) { | ||||
| 		if (nbtList instanceof NBTTagList && toAdd instanceof NBTBase) { | ||||
| 			((NBTTagList) nbtList).add((NBTBase) toAdd); | ||||
| 		} | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public void removeFromList(Object nbtList, int index) { | ||||
| 		if (nbtList instanceof NBTTagList && index >= 0 && index < ((NBTTagList) nbtList).size()) { | ||||
| 			((NBTTagList) nbtList).a(index); | ||||
| 		} | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public void setIndex(Object nbtList, int index, Object toSet) { | ||||
| 		if (nbtList instanceof NBTTagList && index >= 0 && index < ((NBTTagList) nbtList).size()) { | ||||
| 			if (toSet instanceof NBTBase) { | ||||
| 				((NBTTagList) nbtList).a(index, (NBTBase) toSet); | ||||
| 			} else if (toSet instanceof Number) { | ||||
| 				((NBTTagList) nbtList).a(index, convertToNBT((Number) toSet)); | ||||
| 			} else if (toSet instanceof String) { | ||||
| 				((NBTTagList) nbtList).a(index, convertToNBT((String) toSet)); | ||||
| 			} | ||||
| 		} | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public Object getIndex(Object nbtList, int index) { | ||||
| 		if (nbtList instanceof NBTTagList && index >= 0 && index < ((NBTTagList) nbtList).size()) { | ||||
| 			NBTBase value = ((NBTTagList) nbtList).g(index); | ||||
| 			if (value instanceof NBTTagByte) { | ||||
| 				return ((NBTTagByte) value).f(); //Byte stored inside a NBTNumber | ||||
| 			} else if (value instanceof NBTTagShort) { | ||||
| 				return ((NBTTagShort) value).e(); //Short inside a NBTNumber | ||||
| 			} else if (value instanceof NBTTagInt) { | ||||
| 				return ((NBTTagInt) value).d(); //Integer inside a NBTNumber | ||||
| 			} else if (value instanceof NBTTagLong) { | ||||
| 				return ((NBTTagLong) value).c(); //Long inside a NBTNumber | ||||
| 			} else if (value instanceof NBTTagFloat) { | ||||
| 				return ((NBTTagFloat) value).h(); //Float inside a NBTNumber | ||||
| 			} else if (value instanceof NBTTagDouble) { | ||||
| 				return ((NBTTagDouble) value).g(); //Double inside a NBTNumber | ||||
| 			} else if (value instanceof NBTTagString) { | ||||
| 				return ((NBTTagString) value).a_(); //String inside the NBTTagString | ||||
| 			} else if (value instanceof NBTBase) { | ||||
| 				return value; //No need to convert this. | ||||
| 			} | ||||
| 		} | ||||
| 		return null; | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public void clearPathfinderGoals(Entity entity) { | ||||
| 		EntityInsentient nmsEnt = (EntityInsentient) ((CraftEntity) entity).getHandle(); | ||||
| 		((List<?>) ReflectionUtils.getField("b", PathfinderGoalSelector.class, nmsEnt.goalSelector)).clear(); | ||||
| 		((List<?>) ReflectionUtils.getField("c", PathfinderGoalSelector.class, nmsEnt.goalSelector)).clear(); | ||||
| 		((List<?>) ReflectionUtils.getField("b", PathfinderGoalSelector.class, nmsEnt.targetSelector)).clear(); | ||||
| 		((List<?>) ReflectionUtils.getField("c", PathfinderGoalSelector.class, nmsEnt.targetSelector)).clear(); | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public void removePathfinderGoal(Object entity, Class<?> goalClass, boolean isTargetSelector) { | ||||
| 		if (entity instanceof EntityInsentient) { | ||||
| 			((EntityInsentient) entity).setGoalTarget(null); | ||||
| 			if (isTargetSelector) { | ||||
| 				Iterator<?> goals = ((List<?>) ReflectionUtils.getField("b", PathfinderGoalSelector.class, ((EntityInsentient) entity).targetSelector)).iterator(); | ||||
| 				while (goals.hasNext()) { | ||||
| 					Object goal = goals.next(); | ||||
| 					if (ReflectionUtils.getField("a", goal.getClass(), goal).getClass() == goalClass) { | ||||
| 						goals.remove(); | ||||
| 					} | ||||
| 				} | ||||
| 			} else { | ||||
| 				Iterator<?> goals = ((List<?>) ReflectionUtils.getField("b", PathfinderGoalSelector.class, ((EntityInsentient) entity).goalSelector)).iterator(); | ||||
| 				while (goals.hasNext()) { | ||||
| 					Object goal = goals.next(); | ||||
| 					if (ReflectionUtils.getField("a", goal.getClass(), goal).getClass() == goalClass) { | ||||
| 						goals.remove(); | ||||
| 					} | ||||
| 				} | ||||
| 			} | ||||
| 		} | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public void addPathfinderGoal(Object entity, int priority, Object goal, boolean isTargetSelector) { | ||||
| 		if (entity instanceof EntityInsentient && goal instanceof PathfinderGoal) { | ||||
| 			if (isTargetSelector) | ||||
| 				((EntityInsentient) entity).targetSelector.a(priority, (PathfinderGoal) goal); | ||||
| 			else | ||||
| 				((EntityInsentient) entity).goalSelector.a(priority, (PathfinderGoal) goal); | ||||
| 		} | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public void registerCompoundClassInfo() { | ||||
| 		Classes.registerClass(new ClassInfo<NBTTagCompound>(NBTTagCompound.class, "compound").user("((nbt)?( ?tag)?) ?compounds?").name("NBT Compound").changer(new Changer<NBTTagCompound>() { | ||||
| 
 | ||||
| 			@SuppressWarnings("unchecked") | ||||
| 			@Override | ||||
| 			@Nullable | ||||
| 			public Class<?>[] acceptChange(ChangeMode mode) { | ||||
| 				if (mode == ChangeMode.ADD || mode == ChangeMode.REMOVE) { | ||||
| 					return CollectionUtils.array(String.class, NBTTagCompound.class); | ||||
| 				} | ||||
| 				return null; | ||||
| 			} | ||||
| 
 | ||||
| 			@Override | ||||
| 			public void change(NBTTagCompound[] NBT, @Nullable Object[] delta, ChangeMode mode) { | ||||
| 				if (mode == ChangeMode.ADD) { | ||||
| 					if (delta[0] instanceof String) { | ||||
| 						NBTTagCompound parsedNBT = parseRawNBT((String) delta[0]); | ||||
| 						addToCompound(NBT[0], parsedNBT); | ||||
| 					} else { | ||||
| 						addToCompound(NBT[0], delta[0]); | ||||
| 					} | ||||
| 				} else if (mode == ChangeMode.REMOVE) { | ||||
| 					if (delta[0] instanceof NBTTagCompound) | ||||
| 						return; | ||||
| 					for (Object s : delta) { | ||||
| 						NBT[0].remove((String) s); | ||||
| 					} | ||||
| 				} | ||||
| 			} | ||||
| 		}).parser(new Parser<NBTTagCompound>() { | ||||
| 
 | ||||
| 			@Override | ||||
| 			public String getVariableNamePattern() { | ||||
| 				return ".+"; | ||||
| 			} | ||||
| 
 | ||||
| 			@Override | ||||
| 			@Nullable | ||||
| 			public NBTTagCompound parse(String rawNBT, ParseContext context) { | ||||
| 				if (rawNBT.startsWith("nbt:{") && rawNBT.endsWith("}")) { | ||||
| 					NBTTagCompound NBT = parseRawNBT(rawNBT.substring(4)); | ||||
| 					return NBT; | ||||
| 				} | ||||
| 				return null; | ||||
| 			} | ||||
| 
 | ||||
| 			@Override | ||||
| 			public String toString(NBTTagCompound compound, int arg1) { | ||||
| 				return compound.toString(); | ||||
| 			} | ||||
| 
 | ||||
| 			@Override | ||||
| 			public String toVariableNameString(NBTTagCompound compound) { | ||||
| 				return compound.toString(); | ||||
| 			} | ||||
| 		}).serializer(new Serializer<NBTTagCompound>() { | ||||
| 
 | ||||
| 			@Override | ||||
| 			public Fields serialize(NBTTagCompound compound) throws NotSerializableException { | ||||
| 				Fields f = new Fields(); | ||||
| 				f.putObject("asString", compound.toString()); | ||||
| 				return f; | ||||
| 			} | ||||
| 
 | ||||
| 			@Override | ||||
| 			public void deserialize(NBTTagCompound compound, Fields f) throws StreamCorruptedException, NotSerializableException { | ||||
| 				assert false; | ||||
| 			} | ||||
| 
 | ||||
| 			@Override | ||||
| 			protected boolean canBeInstantiated() { | ||||
| 				return false; | ||||
| 			} | ||||
| 
 | ||||
| 			@Override | ||||
| 			protected NBTTagCompound deserialize(Fields fields) throws StreamCorruptedException, NotSerializableException { | ||||
| 				String raw = fields.getObject("asString", String.class); | ||||
| 				NBTTagCompound compound =  parseRawNBT(raw); | ||||
| 				if (compound == null) { | ||||
| 					throw new StreamCorruptedException("Unable to parse NBT from a variable: " + raw); | ||||
| 				} | ||||
| 				return compound; | ||||
| 			} | ||||
| 
 | ||||
| 			@Override | ||||
| 			@Nullable | ||||
| 			public NBTTagCompound deserialize(String s) { | ||||
| 				NBTTagCompound compound =  parseRawNBT(s); | ||||
| 				return compound; | ||||
| 			} | ||||
| 
 | ||||
| 			@Override | ||||
| 			public boolean mustSyncDeserialization() { | ||||
| 				return true; | ||||
| 			} | ||||
| 		})); | ||||
| 
 | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public void registerNBTListClassInfo() { | ||||
| 		Classes.registerClass(new ClassInfo<NBTTagList>(NBTTagList.class, "nbtlist").user("nbt ?list ?(tag)?").name("NBT List").changer(new Changer<NBTTagList>() { | ||||
| 
 | ||||
| 			@SuppressWarnings("unchecked") | ||||
| 			@Override | ||||
| 			@Nullable | ||||
| 			public Class<?>[] acceptChange(ChangeMode mode) { | ||||
| 				if (mode == ChangeMode.ADD) { | ||||
| 					return CollectionUtils.array(Byte.class, Short.class, Integer.class, Long.class, Float.class, Double.class, String.class, NBTTagCompound.class, NBTTagList.class); | ||||
| 				} | ||||
| 				return null; | ||||
| 			} | ||||
| 
 | ||||
| 			@Override | ||||
| 			public void change(NBTTagList[] nbtList, @Nullable Object[] delta, ChangeMode mode) { | ||||
| 				if (delta.length == 0) | ||||
| 					return; | ||||
| 				if (delta[0] instanceof Number) { | ||||
| 					addToList(nbtList, convertToNBT((Number) delta[0])); | ||||
| 				} else if (delta[0] instanceof String) { | ||||
| 					addToList(nbtList, convertToNBT((String) delta[0])); | ||||
| 				} else if (delta[0] instanceof NBTBase) { | ||||
| 					addToList(nbtList, delta[0]); | ||||
| 				} | ||||
| 			} | ||||
| 		}).parser(new Parser<NBTTagList>() { | ||||
| 
 | ||||
| 			@Override | ||||
| 			public String getVariableNamePattern() { | ||||
| 				return ".+"; | ||||
| 			} | ||||
| 
 | ||||
| 			@Override | ||||
| 			@Nullable | ||||
| 			public NBTTagList parse(String listString, ParseContext context) { | ||||
| 				if ((listString.startsWith("nbt:[") || listString.startsWith("nbtlist:[")) && listString.endsWith("]")) { | ||||
| 					int substring; | ||||
| 					if (listString.startsWith("nbt:[")) { | ||||
| 						substring = 4; | ||||
| 					} else { // "nbtlist:[WHATEVER]" | ||||
| 						substring = 8; | ||||
| 					} | ||||
| 					NBTTagCompound tempNBT =  parseRawNBT("{temp:" + listString.substring(substring) + "}"); | ||||
| 					NBTTagList parsedList = (NBTTagList) tempNBT.get("temp"); | ||||
| 					return parsedList; | ||||
| 				} | ||||
| 				return null; | ||||
| 			} | ||||
| 
 | ||||
| 			@Override | ||||
| 			public String toString(NBTTagList nbtList, int arg1) { | ||||
| 				return nbtList.toString(); | ||||
| 			} | ||||
| 
 | ||||
| 			@Override | ||||
| 			public String toVariableNameString(NBTTagList nbtList) { | ||||
| 				return nbtList.toString(); | ||||
| 			} | ||||
| 		}).serializer(new Serializer<NBTTagList>() { | ||||
| 
 | ||||
| 			@Override | ||||
| 			public Fields serialize(NBTTagList nbtList) throws NotSerializableException { | ||||
| 				Fields f = new Fields(); | ||||
| 				f.putObject("asString", nbtList.toString()); | ||||
| 				return f; | ||||
| 			} | ||||
| 
 | ||||
| 			@Override | ||||
| 			public void deserialize(NBTTagList nbtList, Fields f) throws StreamCorruptedException, NotSerializableException { | ||||
| 				assert false; | ||||
| 			} | ||||
| 
 | ||||
| 			@Override | ||||
| 			protected boolean canBeInstantiated() { | ||||
| 				return false; | ||||
| 			} | ||||
| 
 | ||||
| 			@Override | ||||
| 			protected NBTTagList deserialize(Fields fields) throws StreamCorruptedException, NotSerializableException { | ||||
| 				String s = fields.getObject("asString", String.class); | ||||
| 				NBTTagCompound tempNBT =  parseRawNBT("{temp:" + s + "}"); | ||||
| 				if (tempNBT == null || !tempNBT.hasKey("temp")) { | ||||
| 					throw new StreamCorruptedException("Unable to parse NBT list from a variable: " + s); | ||||
| 				} | ||||
| 				NBTTagList nbtList = (NBTTagList) tempNBT.get("temp"); | ||||
| 				return nbtList; | ||||
| 			} | ||||
| 
 | ||||
| 			@Override | ||||
| 			@Nullable | ||||
| 			public NBTTagList deserialize(String s) { | ||||
| 				NBTTagCompound tempNBT =  parseRawNBT("{temp:" + s + "}"); | ||||
| 				NBTTagList nbtList = (NBTTagList) tempNBT.get("temp"); | ||||
| 				return nbtList; | ||||
| 			} | ||||
| 
 | ||||
| 			@Override | ||||
| 			public boolean mustSyncDeserialization() { | ||||
| 				return true; | ||||
| 			} | ||||
| 		})); | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public NBTTagCompound getEntityNBT(Entity entity) { | ||||
| 		net.minecraft.server.v1_8_R3.Entity nmsEntity = ((CraftEntity) entity).getHandle(); | ||||
| 		NBTTagCompound NBT = new NBTTagCompound(); | ||||
| 		nmsEntity.e(NBT); | ||||
| 		return NBT; | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public NBTTagCompound getTileNBT(Block block) { | ||||
| 		NBTTagCompound NBT = new NBTTagCompound(); | ||||
| 		World nmsWorld = ((CraftWorld) block.getWorld()).getHandle(); | ||||
| 		TileEntity tileEntity = nmsWorld.getTileEntity(new BlockPosition(block.getX(), block.getY(), block.getZ())); | ||||
| 		if (tileEntity == null) | ||||
| 			return null; | ||||
| 		tileEntity.b(NBT); | ||||
| 		return NBT; | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public NBTTagCompound getItemNBT(ItemStack itemStack) { | ||||
| 		if (itemStack == null || itemStack.getType() == Material.AIR) | ||||
| 			return null; | ||||
| 		NBTTagCompound itemNBT = CraftItemStack.asNMSCopy(itemStack).getTag(); | ||||
| 		if (itemNBT == null) | ||||
| 			itemNBT = new NBTTagCompound(); | ||||
| 		return itemNBT; | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public void setEntityNBT(Entity entity, Object newCompound) { | ||||
| 		if (newCompound instanceof NBTTagCompound) { | ||||
| 			net.minecraft.server.v1_8_R3.Entity nmsEntity = ((CraftEntity) entity).getHandle(); | ||||
| 			nmsEntity.f((NBTTagCompound) newCompound); | ||||
| 		} | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public void setTileNBT(Block block, Object newCompound) { | ||||
| 		if (newCompound instanceof NBTTagCompound) { | ||||
| 			World nmsWorld = ((CraftWorld) block.getWorld()).getHandle(); | ||||
| 			TileEntity tileEntity = nmsWorld.getTileEntity(new BlockPosition(block.getX(), block.getY(), block.getZ())); | ||||
| 			if (tileEntity == null) | ||||
| 				return; | ||||
| 			tileEntity.a((NBTTagCompound) newCompound); | ||||
| 			tileEntity.update(); | ||||
| 			nmsWorld.notify(tileEntity.getPosition()); | ||||
| 		} | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public ItemStack getItemWithNBT(ItemStack itemStack, Object compound) { | ||||
| 		net.minecraft.server.v1_8_R3.ItemStack nmsItem = CraftItemStack.asNMSCopy(itemStack); | ||||
| 		if (compound instanceof NBTTagCompound && itemStack != null) { | ||||
| 			if (itemStack.getType() == Material.AIR) | ||||
| 				return null; | ||||
| 			if (((NBTTagCompound) compound).isEmpty()) | ||||
| 				return itemStack; | ||||
| 			nmsItem.setTag((NBTTagCompound) compound); | ||||
| 			ItemStack newItem = CraftItemStack.asBukkitCopy(nmsItem); | ||||
| 			return newItem; | ||||
| 		} else if (compound == null) { | ||||
| 			nmsItem.setTag(null); | ||||
| 			ItemStack newItem = CraftItemStack.asBukkitCopy(nmsItem); | ||||
| 			return newItem; | ||||
| 		} | ||||
| 		return itemStack; | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public NBTTagCompound getFileNBT(File file) { | ||||
| 		FileInputStream fis = null; | ||||
| 		try { | ||||
| 			fis = new FileInputStream(file); | ||||
| 		} catch (FileNotFoundException ex) { | ||||
| 			return null; //File doesn't exist. | ||||
| 		} | ||||
| 		NBTTagCompound fileNBT = null; | ||||
| 		try { | ||||
| 			fileNBT = NBTCompressedStreamTools.a(fis); | ||||
| 			fis.close(); | ||||
| 		} catch (IOException ex) { | ||||
| 			if (ex instanceof EOFException) { | ||||
| 				; //Nothing. | ||||
| 			} else { | ||||
| 				ex.printStackTrace(); | ||||
| 			} | ||||
| 		} | ||||
| 		return fileNBT; | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public void setFileNBT(File file, Object newCompound) { | ||||
| 		if (newCompound instanceof NBTTagCompound) { | ||||
| 			OutputStream os = null; | ||||
| 			try { | ||||
| 				os = new FileOutputStream(file); | ||||
| 			} catch (FileNotFoundException ex) { | ||||
| 				ex.printStackTrace(); | ||||
| 			} | ||||
| 			try { | ||||
| 				NBTCompressedStreamTools.a((NBTTagCompound) newCompound, os); | ||||
| 				os.close(); | ||||
| 			} catch (IOException ex) { | ||||
| 				if (ex instanceof EOFException) { | ||||
| 					; //Ignore, just end of the file | ||||
| 				} else { | ||||
| 					ex.printStackTrace(); | ||||
| 				} | ||||
| 			} | ||||
| 		} | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public NBTBase convertToNBT(Number number) { | ||||
| 		if (number instanceof Byte) { | ||||
| 			return new NBTTagByte((byte) number); | ||||
| 		} else if (number instanceof Short) { | ||||
| 			return new NBTTagShort((short) number); | ||||
| 		} else if (number instanceof Integer) { | ||||
| 			return new NBTTagInt((int) number); | ||||
| 		} else if (number instanceof Long) { | ||||
| 			return new NBTTagLong((long) number); | ||||
| 		} else if (number instanceof Float) { | ||||
| 			return new NBTTagFloat((float) number); | ||||
| 		} else if (number instanceof Double) { | ||||
| 			return new NBTTagDouble((double) number); | ||||
| 		} | ||||
| 		return null; | ||||
| 	} | ||||
| 
 | ||||
| 	public NBTTagString convertToNBT(String string) { | ||||
| 		return new NBTTagString(string); | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public String getMCId(ItemStack itemStack) { | ||||
| 		net.minecraft.server.v1_8_R3.ItemStack nmsItem = CraftItemStack.asNMSCopy(itemStack); | ||||
| 		MinecraftKey mcKey = Item.REGISTRY.c(nmsItem.getItem()); | ||||
| 		return mcKey.toString(); | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public ItemStack getItemFromMcId(String mcId) { | ||||
| 		MinecraftKey mcKey = new MinecraftKey(mcId); | ||||
| 		Item nmsItem = (Item) Item.REGISTRY.get(mcKey); | ||||
| 		return CraftItemStack.asNewCraftStack(nmsItem); | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public boolean getNoClip(Entity entity) { | ||||
| 		net.minecraft.server.v1_8_R3.Entity nmsEntity = ((CraftEntity) entity).getHandle(); | ||||
| 		return nmsEntity.noclip; | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public void setNoClip(Entity entity, boolean noclip) { | ||||
| 		net.minecraft.server.v1_8_R3.Entity nmsEntity = ((CraftEntity) entity).getHandle(); | ||||
| 		nmsEntity.noclip = noclip; | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public boolean getFireProof(Entity entity) { | ||||
| 		net.minecraft.server.v1_8_R3.Entity nmsEntity = ((CraftEntity) entity).getHandle(); | ||||
| 		return nmsEntity.isFireProof(); | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public void setFireProof(Entity entity, boolean fireProof) { | ||||
| 		net.minecraft.server.v1_8_R3.Entity nmsEntity = ((CraftEntity) entity).getHandle(); | ||||
| 		ReflectionUtils.setField("fireProof", nmsEntity.getClass(), nmsEntity, fireProof); | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public Location getLastLocation(Entity entity) { | ||||
| 		net.minecraft.server.v1_8_R3.Entity nmsEntity = ((CraftEntity) entity).getHandle(); | ||||
| 		org.bukkit.World world = nmsEntity.world.getWorld(); | ||||
| 		Location lastEntLoc = new Location(world, nmsEntity.P, nmsEntity.Q, nmsEntity.R); | ||||
| 		return lastEntLoc; | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public float getEntityStepLength(Entity entity) { | ||||
| 		net.minecraft.server.v1_8_R3.Entity nmsEntity = ((CraftEntity) entity).getHandle(); | ||||
| 		return nmsEntity.S; | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public void setEntityStepLength(Entity entity, float length) { | ||||
| 		net.minecraft.server.v1_8_R3.Entity nmsEntity = ((CraftEntity) entity).getHandle(); | ||||
| 		nmsEntity.S = length; | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public boolean getElytraGlideState(Entity entity) { | ||||
| 		Bukkit.getLogger().warning("Executed \"Elytra Glide State\" code on 1.8! How the hell did this even happen!!"); | ||||
| 		return false; | ||||
| 	} | ||||
| 	 | ||||
| 	public void setElytraGlideState(Entity entity, boolean glide) { | ||||
| 		Bukkit.getLogger().warning("Executed \"Elytra Glide State\" code on 1.8! How the hell did this even happen!!"); | ||||
| 	} | ||||
| 	 | ||||
| 	public boolean getNoGravity(Entity entity) { | ||||
| 		Bukkit.getLogger().warning("Executed \"Get no gravity state of entity\" code on 1.8! How the hell did this even happen!!"); | ||||
| 		return false; | ||||
| 	} | ||||
| 	 | ||||
| 	public void setNoGravity(Entity entity, boolean noGravity) { | ||||
| 		Bukkit.getLogger().warning("Executed \"Set no gravity state of entity\" code on 1.8! How the hell did this even happen!!"); | ||||
| 	} | ||||
| } | ||||
| @ -1,732 +0,0 @@ | ||||
| package me.TheBukor.SkStuff.util; | ||||
| 
 | ||||
| import java.io.EOFException; | ||||
| import java.io.File; | ||||
| import java.io.FileInputStream; | ||||
| import java.io.FileNotFoundException; | ||||
| import java.io.FileOutputStream; | ||||
| import java.io.IOException; | ||||
| import java.io.NotSerializableException; | ||||
| import java.io.OutputStream; | ||||
| import java.io.StreamCorruptedException; | ||||
| import java.util.Iterator; | ||||
| import java.util.LinkedHashSet; | ||||
| 
 | ||||
| import javax.annotation.Nullable; | ||||
| 
 | ||||
| import org.bukkit.Bukkit; | ||||
| import org.bukkit.Location; | ||||
| import org.bukkit.Material; | ||||
| import org.bukkit.block.Block; | ||||
| import org.bukkit.craftbukkit.v1_9_R1.CraftWorld; | ||||
| import org.bukkit.craftbukkit.v1_9_R1.entity.CraftEntity; | ||||
| import org.bukkit.craftbukkit.v1_9_R1.entity.CraftLivingEntity; | ||||
| import org.bukkit.craftbukkit.v1_9_R1.inventory.CraftItemStack; | ||||
| import org.bukkit.entity.Entity; | ||||
| import org.bukkit.inventory.ItemStack; | ||||
| 
 | ||||
| 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.classes.Serializer; | ||||
| import ch.njol.skript.lang.ParseContext; | ||||
| import ch.njol.skript.registrations.Classes; | ||||
| import ch.njol.util.coll.CollectionUtils; | ||||
| import ch.njol.yggdrasil.Fields; | ||||
| import net.minecraft.server.v1_9_R1.BlockPosition; | ||||
| import net.minecraft.server.v1_9_R1.EntityInsentient; | ||||
| import net.minecraft.server.v1_9_R1.EntityLiving; | ||||
| import net.minecraft.server.v1_9_R1.IBlockData; | ||||
| import net.minecraft.server.v1_9_R1.Item; | ||||
| import net.minecraft.server.v1_9_R1.MinecraftKey; | ||||
| import net.minecraft.server.v1_9_R1.MojangsonParseException; | ||||
| import net.minecraft.server.v1_9_R1.MojangsonParser; | ||||
| import net.minecraft.server.v1_9_R1.NBTBase; | ||||
| import net.minecraft.server.v1_9_R1.NBTCompressedStreamTools; | ||||
| import net.minecraft.server.v1_9_R1.NBTTagByte; | ||||
| import net.minecraft.server.v1_9_R1.NBTTagCompound; | ||||
| import net.minecraft.server.v1_9_R1.NBTTagDouble; | ||||
| import net.minecraft.server.v1_9_R1.NBTTagFloat; | ||||
| import net.minecraft.server.v1_9_R1.NBTTagInt; | ||||
| import net.minecraft.server.v1_9_R1.NBTTagList; | ||||
| import net.minecraft.server.v1_9_R1.NBTTagLong; | ||||
| import net.minecraft.server.v1_9_R1.NBTTagShort; | ||||
| import net.minecraft.server.v1_9_R1.NBTTagString; | ||||
| import net.minecraft.server.v1_9_R1.PathfinderGoal; | ||||
| import net.minecraft.server.v1_9_R1.PathfinderGoalSelector; | ||||
| import net.minecraft.server.v1_9_R1.TileEntity; | ||||
| import net.minecraft.server.v1_9_R1.World; | ||||
| 
 | ||||
| public class NMS_v1_9_R1 implements NMSInterface { | ||||
| 
 | ||||
| 	@Override | ||||
| 	public Object getNBTTag(Object compound, String tag) { | ||||
| 		if (compound instanceof NBTTagCompound) { | ||||
| 			return ((NBTTagCompound) compound).get(tag); | ||||
| 		} | ||||
| 		return null; | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public void setNBTTag(Object compound, String tag, Object toSet) { | ||||
| 		if (compound instanceof NBTTagCompound && (toSet instanceof NBTBase || toSet instanceof Number || toSet instanceof String)) { | ||||
| 			NBTBase converted = null; | ||||
| 			if (toSet instanceof Number) { | ||||
| 				converted = convertToNBT((Number) toSet); | ||||
| 			} else if (toSet instanceof String) { | ||||
| 				converted = convertToNBT((String) toSet); | ||||
| 			} else { //Already an NBTBase | ||||
| 				converted = (NBTBase) toSet; //No need to convert anything | ||||
| 			} | ||||
| 			((NBTTagCompound) compound).set(tag, converted); | ||||
| 		} | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public void removeNBTTag(Object compound, String tag) { | ||||
| 		if (compound instanceof NBTTagCompound) { | ||||
| 			((NBTTagCompound) compound).remove(tag); | ||||
| 		} | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public byte getTypeId(Object nbtBase) { | ||||
| 		if (nbtBase instanceof NBTBase) { | ||||
| 			return ((NBTBase) nbtBase).getTypeId(); | ||||
| 		} | ||||
| 		return 0; | ||||
| 	} | ||||
| 
 | ||||
| 	 @Override | ||||
| 	public Object getNBTTagValue(Object compound, String tag, byte typeId) { | ||||
| 		if (compound instanceof NBTTagCompound) { | ||||
| 			switch (typeId) { | ||||
| 			case 1: | ||||
| 				return ((NBTTagCompound) compound).getByte(tag); | ||||
| 			case 2: | ||||
| 				return ((NBTTagCompound) compound).getShort(tag); | ||||
| 			case 3: | ||||
| 				return ((NBTTagCompound) compound).getInt(tag); | ||||
| 			case 4: | ||||
| 				return ((NBTTagCompound) compound).getLong(tag); | ||||
| 			case 5: | ||||
| 				return ((NBTTagCompound) compound).getFloat(tag); | ||||
| 			case 6: | ||||
| 				return ((NBTTagCompound) compound).getDouble(tag); | ||||
| 			case 7: //Byte array, only used in chunk files. Also doesn't have support for the MojangsonParser. | ||||
| 				break; | ||||
| 			case 8: | ||||
| 				return ((NBTTagCompound) compound).getString(tag); | ||||
| 			case 9: | ||||
| 				int i; | ||||
| 				NBTTagList list = null; | ||||
| 				for (i = 1; i <= 11; i++) { //To get a list I need to know the type of the tags it contains inside, | ||||
| 					//since I can't predict what type the list will have, I just loop all of the IDs until I find a non-empty list. | ||||
| 					list = ((NBTTagCompound) compound).getList(tag, i); //Try to get the list with the ID "loop-number". | ||||
| 					if (!list.isEmpty()) { //If list is not empty. | ||||
| 						break; //Stop loop. | ||||
| 					} | ||||
| 				} | ||||
| 				return list; //May be null | ||||
| 			case 10: | ||||
| 				return ((NBTTagCompound) compound).getCompound(tag); | ||||
| 			case 11: //Integer array, this one is only used on the chunk files (and maybe schematic files?). | ||||
| 				return ((NBTTagCompound) compound).getIntArray(tag); | ||||
| 			default: //This should never happen, but it's better to have this just in case it spills errors everywhere. | ||||
| 				break; | ||||
| 			} | ||||
| 		} | ||||
| 		return null; | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public void addToCompound(Object compound, Object toAdd) { | ||||
| 		if (compound instanceof NBTTagCompound && toAdd instanceof NBTTagCompound) { | ||||
| 			((NBTTagCompound) compound).a((NBTTagCompound) toAdd); | ||||
| 		} | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public void removeFromCompound(Object compound, String ... toRemove) { | ||||
| 		if (compound instanceof NBTTagCompound) { | ||||
| 			for (String s : toRemove) { | ||||
| 				((NBTTagCompound) compound).remove(s); | ||||
| 			} | ||||
| 		} | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public NBTTagCompound parseRawNBT(String rawNBT) { | ||||
| 		NBTTagCompound parsedNBT = null; | ||||
| 		try { | ||||
| 			parsedNBT = MojangsonParser.parse(rawNBT); | ||||
| 		} catch (MojangsonParseException ex) { | ||||
| 			Skript.warning("Error when parsing NBT - " + ex.getMessage()); | ||||
| 			return null; | ||||
| 		} | ||||
| 		return parsedNBT; | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public Object[] getContents(Object nbtList) { | ||||
| 		if (nbtList instanceof NBTTagList) { | ||||
| 			Object[] contents = new Object[((NBTTagList) nbtList).size()]; | ||||
| 			for (int i = 0; i < ((NBTTagList) nbtList).size(); i++) { | ||||
| 				if (getIndex(nbtList, i) != null) { | ||||
| 					contents[i] = getIndex(nbtList, i); | ||||
| 				} | ||||
| 			} | ||||
| 			return contents; | ||||
| 		} | ||||
| 		return null; | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public void addToList(Object nbtList, Object toAdd) { | ||||
| 		if (nbtList instanceof NBTTagList && toAdd instanceof NBTBase) { | ||||
| 			((NBTTagList) nbtList).add((NBTBase) toAdd); | ||||
| 		} | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public void removeFromList(Object nbtList, int index) { | ||||
| 		if (nbtList instanceof NBTTagList && index >= 0 && index < ((NBTTagList) nbtList).size()) { | ||||
| 			((NBTTagList) nbtList).remove(index); | ||||
| 		} | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public void setIndex(Object nbtList, int index, Object toSet) { | ||||
| 		if (nbtList instanceof NBTTagList && index >= 0 && index < ((NBTTagList) nbtList).size()) { | ||||
| 			if (toSet instanceof NBTBase) { | ||||
| 				((NBTTagList) nbtList).a(index, (NBTBase) toSet); | ||||
| 			} else if (toSet instanceof Number) { | ||||
| 				((NBTTagList) nbtList).a(index, convertToNBT((Number) toSet)); | ||||
| 			} else if (toSet instanceof String) { | ||||
| 				((NBTTagList) nbtList).a(index, convertToNBT((String) toSet)); | ||||
| 			} | ||||
| 		} | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public Object getIndex(Object nbtList, int index) { | ||||
| 		if (nbtList instanceof NBTTagList && index >= 0 && index < ((NBTTagList) nbtList).size()) { | ||||
| 			NBTBase value = ((NBTTagList) nbtList).h(index); | ||||
| 			if (value instanceof NBTTagByte) { | ||||
| 				return ((NBTTagByte) value).f(); //Byte stored inside a NBTNumber | ||||
| 			} else if (value instanceof NBTTagShort) { | ||||
| 				return ((NBTTagShort) value).e(); //Short inside a NBTNumber | ||||
| 			} else if (value instanceof NBTTagInt) { | ||||
| 				return ((NBTTagInt) value).d(); //Integer inside a NBTNumber | ||||
| 			} else if (value instanceof NBTTagLong) { | ||||
| 				return ((NBTTagLong) value).c(); //Long inside a NBTNumber | ||||
| 			} else if (value instanceof NBTTagFloat) { | ||||
| 				return ((NBTTagFloat) value).h(); //Float inside a NBTNumber | ||||
| 			} else if (value instanceof NBTTagDouble) { | ||||
| 				return ((NBTTagDouble) value).g(); //Double inside a NBTNumber | ||||
| 			} else if (value instanceof NBTTagString) { | ||||
| 				return ((NBTTagString) value).a_(); //String inside the NBTTagString | ||||
| 			} else if (value instanceof NBTBase) { | ||||
| 				return value; //No need to convert this | ||||
| 			} | ||||
| 		} | ||||
| 		return null; | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public void clearPathfinderGoals(Entity entity) { | ||||
| 		EntityInsentient nmsEnt = (EntityInsentient) ((CraftEntity) entity).getHandle(); | ||||
| 		((LinkedHashSet<?>) ReflectionUtils.getField("b", PathfinderGoalSelector.class, nmsEnt.goalSelector)).clear(); | ||||
| 		((LinkedHashSet<?>) ReflectionUtils.getField("c", PathfinderGoalSelector.class, nmsEnt.goalSelector)).clear(); | ||||
| 		((LinkedHashSet<?>) ReflectionUtils.getField("b", PathfinderGoalSelector.class, nmsEnt.targetSelector)).clear(); | ||||
| 		((LinkedHashSet<?>) ReflectionUtils.getField("c", PathfinderGoalSelector.class, nmsEnt.targetSelector)).clear(); | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public void removePathfinderGoal(Object entity, Class<?> goalClass, boolean isTargetSelector) { | ||||
| 		if (entity instanceof EntityInsentient) { | ||||
| 			((EntityInsentient) entity).setGoalTarget(null); | ||||
| 			if (isTargetSelector) { | ||||
| 				Iterator<?> goals = ((LinkedHashSet<?>) ReflectionUtils.getField("b", PathfinderGoalSelector.class, ((EntityInsentient) entity).targetSelector)).iterator(); | ||||
| 				while (goals.hasNext()) { | ||||
| 					Object goal = goals.next(); | ||||
| 					if (ReflectionUtils.getField("a", goal.getClass(), goal).getClass() == goalClass) { | ||||
| 						goals.remove(); | ||||
| 					} | ||||
| 				} | ||||
| 			} else { | ||||
| 				Iterator<?> goals = ((LinkedHashSet<?>) ReflectionUtils.getField("b", PathfinderGoalSelector.class, ((EntityInsentient) entity).goalSelector)).iterator(); | ||||
| 				while (goals.hasNext()) { | ||||
| 					Object goal = goals.next(); | ||||
| 					if (ReflectionUtils.getField("a", goal.getClass(), goal).getClass() == goalClass) { | ||||
| 						goals.remove(); | ||||
| 					} | ||||
| 				} | ||||
| 			} | ||||
| 		} | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public void addPathfinderGoal(Object entity, int priority, Object goal, boolean isTargetSelector) { | ||||
| 		if (entity instanceof EntityInsentient && goal instanceof PathfinderGoal) { | ||||
| 			if (isTargetSelector) | ||||
| 				((EntityInsentient) entity).targetSelector.a(priority, (PathfinderGoal) goal); | ||||
| 			else | ||||
| 				((EntityInsentient) entity).goalSelector.a(priority, (PathfinderGoal) goal); | ||||
| 		} | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public void registerCompoundClassInfo() { | ||||
| 		Classes.registerClass(new ClassInfo<NBTTagCompound>(NBTTagCompound.class, "compound").user("((nbt)?( ?tag)?) ?compounds?").name("NBT Compound").changer(new Changer<NBTTagCompound>() { | ||||
| 
 | ||||
| 			@SuppressWarnings("unchecked") | ||||
| 			@Override | ||||
| 			@Nullable | ||||
| 			public Class<?>[] acceptChange(ChangeMode mode) { | ||||
| 				if (mode == ChangeMode.ADD || mode == ChangeMode.REMOVE) { | ||||
| 					return CollectionUtils.array(String.class, NBTTagCompound.class); | ||||
| 				} | ||||
| 				return null; | ||||
| 			} | ||||
| 
 | ||||
| 			@Override | ||||
| 			public void change(NBTTagCompound[] NBT, @Nullable Object[] delta, ChangeMode mode) { | ||||
| 				if (mode == ChangeMode.ADD) { | ||||
| 					if (delta[0] instanceof String) { | ||||
| 						NBTTagCompound parsedNBT = parseRawNBT((String) delta[0]); | ||||
| 						addToCompound(NBT[0], parsedNBT); | ||||
| 					} else { | ||||
| 						addToCompound(NBT[0], delta[0]); | ||||
| 					} | ||||
| 				} else if (mode == ChangeMode.REMOVE) { | ||||
| 					if (delta[0] instanceof NBTTagCompound) | ||||
| 						return; | ||||
| 					for (Object s : delta) { | ||||
| 						NBT[0].remove((String) s); | ||||
| 					} | ||||
| 				} | ||||
| 			} | ||||
| 		}).parser(new Parser<NBTTagCompound>() { | ||||
| 
 | ||||
| 			@Override | ||||
| 			public String getVariableNamePattern() { | ||||
| 				return ".+"; | ||||
| 			} | ||||
| 
 | ||||
| 			@Override | ||||
| 			@Nullable | ||||
| 			public NBTTagCompound parse(String rawNBT, ParseContext context) { | ||||
| 				if (rawNBT.startsWith("nbt:{") && rawNBT.endsWith("}")) { | ||||
| 					NBTTagCompound NBT = parseRawNBT(rawNBT.substring(4)); | ||||
| 					return NBT; | ||||
| 				} | ||||
| 				return null; | ||||
| 			} | ||||
| 
 | ||||
| 			@Override | ||||
| 			public String toString(NBTTagCompound compound, int arg1) { | ||||
| 				return compound.toString(); | ||||
| 			} | ||||
| 
 | ||||
| 			@Override | ||||
| 			public String toVariableNameString(NBTTagCompound compound) { | ||||
| 				return compound.toString(); | ||||
| 			} | ||||
| 		}).serializer(new Serializer<NBTTagCompound>() { | ||||
| 
 | ||||
| 			@Override | ||||
| 			public Fields serialize(NBTTagCompound compound) throws NotSerializableException { | ||||
| 				Fields f = new Fields(); | ||||
| 				f.putObject("asString", compound.toString()); | ||||
| 				return f; | ||||
| 			} | ||||
| 
 | ||||
| 			@Override | ||||
| 			public void deserialize(NBTTagCompound compound, Fields f) throws StreamCorruptedException, NotSerializableException { | ||||
| 				assert false; | ||||
| 			} | ||||
| 
 | ||||
| 			@Override | ||||
| 			protected boolean canBeInstantiated() { | ||||
| 				return false; | ||||
| 			} | ||||
| 
 | ||||
| 			@Override | ||||
| 			protected NBTTagCompound deserialize(Fields fields) throws StreamCorruptedException, NotSerializableException { | ||||
| 				String raw = fields.getObject("asString", String.class); | ||||
| 				NBTTagCompound compound =  parseRawNBT(raw); | ||||
| 				if (compound == null) { | ||||
| 					throw new StreamCorruptedException("Unable to parse NBT from a variable: " + raw); | ||||
| 				} | ||||
| 				return compound; | ||||
| 			} | ||||
| 
 | ||||
| 			@Override | ||||
| 			@Nullable | ||||
| 			public NBTTagCompound deserialize(String s) { | ||||
| 				NBTTagCompound compound =  parseRawNBT(s); | ||||
| 				return compound; | ||||
| 			} | ||||
| 
 | ||||
| 			@Override | ||||
| 			public boolean mustSyncDeserialization() { | ||||
| 				return true; | ||||
| 			} | ||||
| 		})); | ||||
| 
 | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public void registerNBTListClassInfo() { | ||||
| 		Classes.registerClass(new ClassInfo<NBTTagList>(NBTTagList.class, "nbtlist").user("nbt ?list ?(tag)?").name("NBT List").changer(new Changer<NBTTagList>() { | ||||
| 
 | ||||
| 			@SuppressWarnings("unchecked") | ||||
| 			@Override | ||||
| 			@Nullable | ||||
| 			public Class<?>[] acceptChange(ChangeMode mode) { | ||||
| 				if (mode == ChangeMode.ADD) { | ||||
| 					return CollectionUtils.array(Byte.class, Short.class, Integer.class, Long.class, Float.class, Double.class, String.class, NBTTagCompound.class, NBTTagList.class); | ||||
| 				} | ||||
| 				return null; | ||||
| 			} | ||||
| 
 | ||||
| 			@Override | ||||
| 			public void change(NBTTagList[] nbtList, @Nullable Object[] delta, ChangeMode mode) { | ||||
| 				if (delta.length == 0) | ||||
| 					return; | ||||
| 				if (delta[0] instanceof Number) { | ||||
| 					addToList(nbtList[0], convertToNBT((Number) delta[0])); | ||||
| 				} else if (delta[0] instanceof String) { | ||||
| 					addToList(nbtList[0], convertToNBT((String) delta[0])); | ||||
| 				} else if (delta[0] instanceof NBTBase) { | ||||
| 					addToList(nbtList[0], delta[0]); | ||||
| 				} | ||||
| 			} | ||||
| 		}).parser(new Parser<NBTTagList>() { | ||||
| 
 | ||||
| 			@Override | ||||
| 			public String getVariableNamePattern() { | ||||
| 				return ".+"; | ||||
| 			} | ||||
| 
 | ||||
| 			@Override | ||||
| 			@Nullable | ||||
| 			public NBTTagList parse(String listString, ParseContext context) { | ||||
| 				if ((listString.startsWith("nbt:[") || listString.startsWith("nbtlist:[")) && listString.endsWith("]")) { | ||||
| 					int substring; | ||||
| 					if (listString.startsWith("nbt:[")) { | ||||
| 						substring = 4; | ||||
| 					} else { // "nbtlist:[WHATEVER]" | ||||
| 						substring = 8; | ||||
| 					} | ||||
| 					NBTTagCompound tempNBT =  parseRawNBT("{temp:" + listString.substring(substring) + "}"); | ||||
| 					NBTTagList parsedList = (NBTTagList) tempNBT.get("temp"); | ||||
| 					return parsedList; | ||||
| 				} | ||||
| 				return null; | ||||
| 			} | ||||
| 
 | ||||
| 			@Override | ||||
| 			public String toString(NBTTagList nbtList, int arg1) { | ||||
| 				return nbtList.toString(); | ||||
| 			} | ||||
| 
 | ||||
| 			@Override | ||||
| 			public String toVariableNameString(NBTTagList nbtList) { | ||||
| 				return nbtList.toString(); | ||||
| 			} | ||||
| 		}).serializer(new Serializer<NBTTagList>() { | ||||
| 
 | ||||
| 			@Override | ||||
| 			public Fields serialize(NBTTagList nbtList) throws NotSerializableException { | ||||
| 				Fields f = new Fields(); | ||||
| 				f.putObject("asString", nbtList.toString()); | ||||
| 				return f; | ||||
| 			} | ||||
| 
 | ||||
| 			@Override | ||||
| 			public void deserialize(NBTTagList nbtList, Fields f) throws StreamCorruptedException, NotSerializableException { | ||||
| 				assert false; | ||||
| 			} | ||||
| 
 | ||||
| 			@Override | ||||
| 			protected boolean canBeInstantiated() { | ||||
| 				return false; | ||||
| 			} | ||||
| 
 | ||||
| 			@Override | ||||
| 			protected NBTTagList deserialize(Fields fields) throws StreamCorruptedException, NotSerializableException { | ||||
| 				String s = fields.getObject("asString", String.class); | ||||
| 				NBTTagCompound tempNBT =  parseRawNBT("{temp:" + s + "}"); | ||||
| 				if (tempNBT == null || !tempNBT.hasKey("temp")) { | ||||
| 					throw new StreamCorruptedException("Unable to parse NBT list from a variable: " + s); | ||||
| 				} | ||||
| 				NBTTagList nbtList = (NBTTagList) tempNBT.get("temp"); | ||||
| 				return nbtList; | ||||
| 			} | ||||
| 
 | ||||
| 			@Override | ||||
| 			@Nullable | ||||
| 			public NBTTagList deserialize(String s) { | ||||
| 				NBTTagCompound tempNBT =  parseRawNBT("{temp:" + s + "}"); | ||||
| 				NBTTagList nbtList = (NBTTagList) tempNBT.get("temp"); | ||||
| 				return nbtList; | ||||
| 			} | ||||
| 
 | ||||
| 			@Override | ||||
| 			public boolean mustSyncDeserialization() { | ||||
| 				return true; | ||||
| 			} | ||||
| 		})); | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public NBTTagCompound getEntityNBT(Entity entity) { | ||||
| 		net.minecraft.server.v1_9_R1.Entity nmsEntity = ((CraftEntity) entity).getHandle(); | ||||
| 		NBTTagCompound NBT = new NBTTagCompound(); | ||||
| 		nmsEntity.e(NBT); | ||||
| 		return NBT; | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public NBTTagCompound getTileNBT(Block block) { | ||||
| 		NBTTagCompound NBT = new NBTTagCompound(); | ||||
| 		World nmsWorld = ((CraftWorld) block.getWorld()).getHandle(); | ||||
| 		TileEntity tileEntity = nmsWorld.getTileEntity(new BlockPosition(block.getX(), block.getY(), block.getZ())); | ||||
| 		if (tileEntity == null) | ||||
| 			return null; | ||||
| 		tileEntity.save(NBT); | ||||
| 		return NBT; | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public NBTTagCompound getItemNBT(ItemStack itemStack) { | ||||
| 		if (itemStack == null || itemStack.getType() == Material.AIR) | ||||
| 			return null; | ||||
| 		NBTTagCompound itemNBT = CraftItemStack.asNMSCopy(itemStack).getTag(); | ||||
| 		if (itemNBT == null) | ||||
| 			itemNBT = new NBTTagCompound(); | ||||
| 		return itemNBT; | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public void setEntityNBT(Entity entity, Object newCompound) { | ||||
| 		if (newCompound instanceof NBTTagCompound) { | ||||
| 			net.minecraft.server.v1_9_R1.Entity nmsEntity = ((CraftEntity) entity).getHandle(); | ||||
| 			nmsEntity.f((NBTTagCompound) newCompound); | ||||
| 		} | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public void setTileNBT(Block block, Object newCompound) { | ||||
| 		if (newCompound instanceof NBTTagCompound) { | ||||
| 			World nmsWorld = ((CraftWorld) block.getWorld()).getHandle(); | ||||
| 			TileEntity tileEntity = nmsWorld.getTileEntity(new BlockPosition(block.getX(), block.getY(), block.getZ())); | ||||
| 			if (tileEntity == null) | ||||
| 				return; | ||||
| 			tileEntity.a((NBTTagCompound) newCompound); | ||||
| 			tileEntity.update(); | ||||
| 			IBlockData tileEntType = nmsWorld.getType(new BlockPosition(block.getX(), block.getY(), block.getZ())); | ||||
| 			nmsWorld.notify(tileEntity.getPosition(), tileEntType, tileEntType, 3); | ||||
| 		} | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public ItemStack getItemWithNBT(ItemStack itemStack, Object compound) { | ||||
| 		net.minecraft.server.v1_9_R1.ItemStack nmsItem = CraftItemStack.asNMSCopy(itemStack); | ||||
| 		if (compound instanceof NBTTagCompound && itemStack != null) { | ||||
| 			if (itemStack.getType() == Material.AIR) | ||||
| 				return null; | ||||
| 			if (((NBTTagCompound) compound).isEmpty()) | ||||
| 				return itemStack; | ||||
| 			nmsItem.setTag((NBTTagCompound) compound); | ||||
| 			ItemStack newItem = CraftItemStack.asBukkitCopy(nmsItem); | ||||
| 			return newItem; | ||||
| 		} else if (compound == null) { | ||||
| 			nmsItem.setTag(null); | ||||
| 			ItemStack newItem = CraftItemStack.asBukkitCopy(nmsItem); | ||||
| 			return newItem; | ||||
| 		} | ||||
| 		return itemStack; | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public NBTTagCompound getFileNBT(File file) { | ||||
| 		FileInputStream fis = null; | ||||
| 		try { | ||||
| 			fis = new FileInputStream(file); | ||||
| 		} catch (FileNotFoundException ex) { | ||||
| 			return null; //File doesn't exist. | ||||
| 		} | ||||
| 		NBTTagCompound fileNBT = null; | ||||
| 		try { | ||||
| 			fileNBT = NBTCompressedStreamTools.a(fis); | ||||
| 			fis.close(); | ||||
| 		} catch (IOException ex) { | ||||
| 			if (ex instanceof EOFException) { | ||||
| 				; //Nothing. | ||||
| 			} else { | ||||
| 				ex.printStackTrace(); | ||||
| 			} | ||||
| 		} | ||||
| 		return fileNBT; | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public void setFileNBT(File file, Object newCompound) { | ||||
| 		if (newCompound instanceof NBTTagCompound) { | ||||
| 			OutputStream os = null; | ||||
| 			try { | ||||
| 				os = new FileOutputStream(file); | ||||
| 			} catch (FileNotFoundException ex) { | ||||
| 				ex.printStackTrace(); | ||||
| 			} | ||||
| 			try { | ||||
| 				NBTCompressedStreamTools.a((NBTTagCompound) newCompound, os); | ||||
| 				os.close(); | ||||
| 			} catch (IOException ex) { | ||||
| 				if (ex instanceof EOFException) { | ||||
| 					; //Ignore, just end of the file | ||||
| 				} else { | ||||
| 					ex.printStackTrace(); | ||||
| 				} | ||||
| 			} | ||||
| 		} | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public NBTBase convertToNBT(Number number) { | ||||
| 		if (number instanceof Byte) { | ||||
| 			return new NBTTagByte((byte) number); | ||||
| 		} else if (number instanceof Short) { | ||||
| 			return new NBTTagShort((short) number); | ||||
| 		} else if (number instanceof Integer) { | ||||
| 			return new NBTTagInt((int) number); | ||||
| 		} else if (number instanceof Long) { | ||||
| 			return new NBTTagLong((long) number); | ||||
| 		} else if (number instanceof Float) { | ||||
| 			return new NBTTagFloat((float) number); | ||||
| 		} else if (number instanceof Double) { | ||||
| 			return new NBTTagDouble((double) number); | ||||
| 		} | ||||
| 		return null; | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public NBTTagString convertToNBT(String string) { | ||||
| 		return new NBTTagString(string); | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public String getMCId(ItemStack itemStack) { | ||||
| 		net.minecraft.server.v1_9_R1.ItemStack nmsItem = CraftItemStack.asNMSCopy(itemStack); | ||||
| 		MinecraftKey mcKey = Item.REGISTRY.b(nmsItem.getItem()); | ||||
| 		return mcKey.toString(); | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public ItemStack getItemFromMcId(String mcId) { | ||||
| 		MinecraftKey mcKey = new MinecraftKey(mcId); | ||||
| 		Item nmsItem = (Item) Item.REGISTRY.get(mcKey); | ||||
| 		return CraftItemStack.asNewCraftStack(nmsItem); | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public boolean getNoClip(Entity entity) { | ||||
| 		net.minecraft.server.v1_9_R1.Entity nmsEntity = ((CraftEntity) entity).getHandle(); | ||||
| 		return nmsEntity.noclip; | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public void setNoClip(Entity entity, boolean noclip) { | ||||
| 		net.minecraft.server.v1_9_R1.Entity nmsEntity = ((CraftEntity) entity).getHandle(); | ||||
| 		nmsEntity.noclip = noclip; | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public boolean getFireProof(Entity entity) { | ||||
| 		net.minecraft.server.v1_9_R1.Entity nmsEntity = ((CraftEntity) entity).getHandle(); | ||||
| 		return nmsEntity.isFireProof(); | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public void setFireProof(Entity entity, boolean fireProof) { | ||||
| 		net.minecraft.server.v1_9_R1.Entity nmsEntity = ((CraftEntity) entity).getHandle(); | ||||
| 		ReflectionUtils.setField("fireProof", nmsEntity.getClass(), nmsEntity, fireProof); | ||||
| 	} | ||||
| 
 | ||||
| 	/* | ||||
| 	@SuppressWarnings("unchecked") | ||||
| 	@Override | ||||
| 	public ItemStack[] getEndermanBlocks(Entity enderman) { | ||||
| 		EntityEnderman nmsEnder = ((CraftEnderman) enderman).getHandle(); | ||||
| 		Set<net.minecraft.server.v1_9_R1.Block> nmsBlocks = (Set<net.minecraft.server.v1_9_R1.Block>) ReflectionUtils.getField("c", EntityEnderman.class, nmsEnder); | ||||
| 		ItemStack[] items = new ItemStack[nmsBlocks.size()]; | ||||
| 		int i = 0; | ||||
| 		for (net.minecraft.server.v1_9_R1.Block nmsBlock : nmsBlocks) { | ||||
| 			IBlockData nmsBlockData = nmsBlock.getBlockData(); | ||||
| 			int dataValue = nmsBlock.toLegacyData(nmsBlockData); | ||||
| 			net.minecraft.server.v1_9_R1.ItemStack nmsItem = new net.minecraft.server.v1_9_R1.ItemStack(nmsBlock, 1, dataValue); | ||||
| 			ItemStack bukkitItem = CraftItemStack.asCraftMirror(nmsItem); | ||||
| 			items[i] = bukkitItem; | ||||
| 			i++; | ||||
| 		} | ||||
| 		return items; | ||||
| 	} | ||||
| 
 | ||||
| 	@SuppressWarnings("unchecked") | ||||
| 	@Override | ||||
| 	public void setEndermanBlocks(Entity enderman, ItemStack... blocks) { | ||||
| 		EntityEnderman nmsEnder = ((CraftEnderman) enderman).getHandle(); | ||||
| 		Set<net.minecraft.server.v1_9_R1.Block> nmsBlocks = (Set<net.minecraft.server.v1_9_R1.Block>) ReflectionUtils.getField("c", EntityEnderman.class, nmsEnder); | ||||
| 		for (ItemStack block : blocks) { | ||||
| 			if (!block.getType().isBlock()) | ||||
| 				return; | ||||
| 			// TODO Figure out how to get a Blocks from a Bukkit ItemStack | ||||
| 			// Blocks.class has a PRIVATE method to get from a MC id. | ||||
| 		} | ||||
| 	} | ||||
| 	*/ | ||||
| 
 | ||||
| 	@Override | ||||
| 	public Location getLastLocation(Entity entity) { | ||||
| 		net.minecraft.server.v1_9_R1.Entity nmsEntity = ((CraftEntity) entity).getHandle(); | ||||
| 		org.bukkit.World world = nmsEntity.world.getWorld(); | ||||
| 		Location lastEntLoc = new Location(world, nmsEntity.M, nmsEntity.N, nmsEntity.O); | ||||
| 		return lastEntLoc; | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public float getEntityStepLength(Entity entity) { | ||||
| 		net.minecraft.server.v1_9_R1.Entity nmsEntity = ((CraftEntity) entity).getHandle(); | ||||
| 		return nmsEntity.P; | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public void setEntityStepLength(Entity entity, float length) { | ||||
| 		net.minecraft.server.v1_9_R1.Entity nmsEntity = ((CraftEntity) entity).getHandle(); | ||||
| 		nmsEntity.P = length; | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public boolean getElytraGlideState(Entity entity) { | ||||
| 		EntityLiving nmsEntity = ((CraftLivingEntity) entity).getHandle(); | ||||
| 		return nmsEntity.getFlag(7); | ||||
| 	} | ||||
| 	 | ||||
| 	public void setElytraGlideState(Entity entity, boolean glide) { | ||||
| 		EntityLiving nmsEntity = ((CraftLivingEntity) entity).getHandle(); | ||||
| 		nmsEntity.setFlag(7, glide); | ||||
| 	} | ||||
| 	 | ||||
| 	public boolean getNoGravity(Entity entity) { | ||||
| 		Bukkit.getLogger().warning("Executed \"Get no gravity state of entity\" code on 1.9! How the hell did this even happen!!"); | ||||
| 		return false; | ||||
| 	} | ||||
| 	 | ||||
| 	public void setNoGravity(Entity entity, boolean noGravity) { | ||||
| 		Bukkit.getLogger().warning("Executed \"Set no gravity state of entity\" code on 1.9! How the hell did this even happen!!"); | ||||
| 	} | ||||
| } | ||||
| @ -1,732 +0,0 @@ | ||||
| package me.TheBukor.SkStuff.util; | ||||
| 
 | ||||
| import java.io.EOFException; | ||||
| import java.io.File; | ||||
| import java.io.FileInputStream; | ||||
| import java.io.FileNotFoundException; | ||||
| import java.io.FileOutputStream; | ||||
| import java.io.IOException; | ||||
| import java.io.NotSerializableException; | ||||
| import java.io.OutputStream; | ||||
| import java.io.StreamCorruptedException; | ||||
| import java.util.Iterator; | ||||
| import java.util.LinkedHashSet; | ||||
| 
 | ||||
| import javax.annotation.Nullable; | ||||
| 
 | ||||
| import org.bukkit.Bukkit; | ||||
| import org.bukkit.Location; | ||||
| import org.bukkit.Material; | ||||
| import org.bukkit.block.Block; | ||||
| import org.bukkit.craftbukkit.v1_9_R2.entity.CraftLivingEntity; | ||||
| import org.bukkit.craftbukkit.v1_9_R2.CraftWorld; | ||||
| import org.bukkit.craftbukkit.v1_9_R2.entity.CraftEntity; | ||||
| import org.bukkit.craftbukkit.v1_9_R2.inventory.CraftItemStack; | ||||
| import org.bukkit.entity.Entity; | ||||
| import org.bukkit.inventory.ItemStack; | ||||
| 
 | ||||
| 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.classes.Serializer; | ||||
| import ch.njol.skript.lang.ParseContext; | ||||
| import ch.njol.skript.registrations.Classes; | ||||
| import ch.njol.util.coll.CollectionUtils; | ||||
| import ch.njol.yggdrasil.Fields; | ||||
| import net.minecraft.server.v1_9_R2.EntityLiving; | ||||
| import net.minecraft.server.v1_9_R2.BlockPosition; | ||||
| import net.minecraft.server.v1_9_R2.EntityInsentient; | ||||
| import net.minecraft.server.v1_9_R2.IBlockData; | ||||
| import net.minecraft.server.v1_9_R2.Item; | ||||
| import net.minecraft.server.v1_9_R2.MinecraftKey; | ||||
| import net.minecraft.server.v1_9_R2.MojangsonParseException; | ||||
| import net.minecraft.server.v1_9_R2.MojangsonParser; | ||||
| import net.minecraft.server.v1_9_R2.NBTBase; | ||||
| import net.minecraft.server.v1_9_R2.NBTCompressedStreamTools; | ||||
| import net.minecraft.server.v1_9_R2.NBTTagByte; | ||||
| import net.minecraft.server.v1_9_R2.NBTTagCompound; | ||||
| import net.minecraft.server.v1_9_R2.NBTTagDouble; | ||||
| import net.minecraft.server.v1_9_R2.NBTTagFloat; | ||||
| import net.minecraft.server.v1_9_R2.NBTTagInt; | ||||
| import net.minecraft.server.v1_9_R2.NBTTagList; | ||||
| import net.minecraft.server.v1_9_R2.NBTTagLong; | ||||
| import net.minecraft.server.v1_9_R2.NBTTagShort; | ||||
| import net.minecraft.server.v1_9_R2.NBTTagString; | ||||
| import net.minecraft.server.v1_9_R2.PathfinderGoal; | ||||
| import net.minecraft.server.v1_9_R2.PathfinderGoalSelector; | ||||
| import net.minecraft.server.v1_9_R2.TileEntity; | ||||
| import net.minecraft.server.v1_9_R2.World; | ||||
| 
 | ||||
| public class NMS_v1_9_R2 implements NMSInterface { | ||||
| 
 | ||||
| 	@Override | ||||
| 	public Object getNBTTag(Object compound, String tag) { | ||||
| 		if (compound instanceof NBTTagCompound) { | ||||
| 			return ((NBTTagCompound) compound).get(tag); | ||||
| 		} | ||||
| 		return null; | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public void setNBTTag(Object compound, String tag, Object toSet) { | ||||
| 		if (compound instanceof NBTTagCompound && (toSet instanceof NBTBase || toSet instanceof Number || toSet instanceof String)) { | ||||
| 			NBTBase converted = null; | ||||
| 			if (toSet instanceof Number) { | ||||
| 				converted = convertToNBT((Number) toSet); | ||||
| 			} else if (toSet instanceof String) { | ||||
| 				converted = convertToNBT((String) toSet); | ||||
| 			} else { //Already an NBTBase | ||||
| 				converted = (NBTBase) toSet; //No need to convert anything | ||||
| 			} | ||||
| 			((NBTTagCompound) compound).set(tag, converted); | ||||
| 		} | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public void removeNBTTag(Object compound, String tag) { | ||||
| 		if (compound instanceof NBTTagCompound) { | ||||
| 			((NBTTagCompound) compound).remove(tag); | ||||
| 		} | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public byte getTypeId(Object nbtBase) { | ||||
| 		if (nbtBase instanceof NBTBase) { | ||||
| 			return ((NBTBase) nbtBase).getTypeId(); | ||||
| 		} | ||||
| 		return 0; | ||||
| 	} | ||||
| 
 | ||||
| 	 @Override | ||||
| 	public Object getNBTTagValue(Object compound, String tag, byte typeId) { | ||||
| 		if (compound instanceof NBTTagCompound) { | ||||
| 			switch (typeId) { | ||||
| 			case 1: | ||||
| 				return ((NBTTagCompound) compound).getByte(tag); | ||||
| 			case 2: | ||||
| 				return ((NBTTagCompound) compound).getShort(tag); | ||||
| 			case 3: | ||||
| 				return ((NBTTagCompound) compound).getInt(tag); | ||||
| 			case 4: | ||||
| 				return ((NBTTagCompound) compound).getLong(tag); | ||||
| 			case 5: | ||||
| 				return ((NBTTagCompound) compound).getFloat(tag); | ||||
| 			case 6: | ||||
| 				return ((NBTTagCompound) compound).getDouble(tag); | ||||
| 			case 7: //Byte array, only used in chunk files. Also doesn't have support for the MojangsonParser. | ||||
| 				break; | ||||
| 			case 8: | ||||
| 				return ((NBTTagCompound) compound).getString(tag); | ||||
| 			case 9: | ||||
| 				int i; | ||||
| 				NBTTagList list = null; | ||||
| 				for (i = 1; i <= 11; i++) { //To get a list I need to know the type of the tags it contains inside, | ||||
| 					//since I can't predict what type the list will have, I just loop all of the IDs until I find a non-empty list. | ||||
| 					list = ((NBTTagCompound) compound).getList(tag, i); //Try to get the list with the ID "loop-number". | ||||
| 					if (!list.isEmpty()) { //If list is not empty. | ||||
| 						break; //Stop loop. | ||||
| 					} | ||||
| 				} | ||||
| 				return list; //May be null | ||||
| 			case 10: | ||||
| 				return ((NBTTagCompound) compound).getCompound(tag); | ||||
| 			case 11: //Integer array, this one is only used on the chunk files (and maybe schematic files?). | ||||
| 				return ((NBTTagCompound) compound).getIntArray(tag); | ||||
| 			default: //This should never happen, but it's better to have this just in case it spills errors everywhere. | ||||
| 				break; | ||||
| 			} | ||||
| 		} | ||||
| 		return null; | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public void addToCompound(Object compound, Object toAdd) { | ||||
| 		if (compound instanceof NBTTagCompound && toAdd instanceof NBTTagCompound) { | ||||
| 			((NBTTagCompound) compound).a((NBTTagCompound) toAdd); | ||||
| 		} | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public void removeFromCompound(Object compound, String ... toRemove) { | ||||
| 		if (compound instanceof NBTTagCompound) { | ||||
| 			for (String s : toRemove) { | ||||
| 				((NBTTagCompound) compound).remove(s); | ||||
| 			} | ||||
| 		} | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public NBTTagCompound parseRawNBT(String rawNBT) { | ||||
| 		NBTTagCompound parsedNBT = null; | ||||
| 		try { | ||||
| 			parsedNBT = MojangsonParser.parse(rawNBT); | ||||
| 		} catch (MojangsonParseException ex) { | ||||
| 			Skript.warning("Error when parsing NBT - " + ex.getMessage()); | ||||
| 			return null; | ||||
| 		} | ||||
| 		return parsedNBT; | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public Object[] getContents(Object nbtList) { | ||||
| 		if (nbtList instanceof NBTTagList) { | ||||
| 			Object[] contents = new Object[((NBTTagList) nbtList).size()]; | ||||
| 			for (int i = 0; i < ((NBTTagList) nbtList).size(); i++) { | ||||
| 				if (getIndex(nbtList, i) != null) { | ||||
| 					contents[i] = getIndex(nbtList, i); | ||||
| 				} | ||||
| 			} | ||||
| 			return contents; | ||||
| 		} | ||||
| 		return null; | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public void addToList(Object nbtList, Object toAdd) { | ||||
| 		if (nbtList instanceof NBTTagList && toAdd instanceof NBTBase) { | ||||
| 			((NBTTagList) nbtList).add((NBTBase) toAdd); | ||||
| 		} | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public void removeFromList(Object nbtList, int index) { | ||||
| 		if (nbtList instanceof NBTTagList && index >= 0 && index < ((NBTTagList) nbtList).size()) { | ||||
| 			((NBTTagList) nbtList).remove(index); | ||||
| 		} | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public void setIndex(Object nbtList, int index, Object toSet) { | ||||
| 		if (nbtList instanceof NBTTagList && index >= 0 && index < ((NBTTagList) nbtList).size()) { | ||||
| 			if (toSet instanceof NBTBase) { | ||||
| 				((NBTTagList) nbtList).a(index, (NBTBase) toSet); | ||||
| 			} else if (toSet instanceof Number) { | ||||
| 				((NBTTagList) nbtList).a(index, convertToNBT((Number) toSet)); | ||||
| 			} else if (toSet instanceof String) { | ||||
| 				((NBTTagList) nbtList).a(index, convertToNBT((String) toSet)); | ||||
| 			} | ||||
| 		} | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public Object getIndex(Object nbtList, int index) { | ||||
| 		if (nbtList instanceof NBTTagList && index >= 0 && index < ((NBTTagList) nbtList).size()) { | ||||
| 			NBTBase value = ((NBTTagList) nbtList).h(index); | ||||
| 			if (value instanceof NBTTagByte) { | ||||
| 				return ((NBTTagByte) value).f(); //Byte stored inside a NBTNumber | ||||
| 			} else if (value instanceof NBTTagShort) { | ||||
| 				return ((NBTTagShort) value).e(); //Short inside a NBTNumber | ||||
| 			} else if (value instanceof NBTTagInt) { | ||||
| 				return ((NBTTagInt) value).d(); //Integer inside a NBTNumber | ||||
| 			} else if (value instanceof NBTTagLong) { | ||||
| 				return ((NBTTagLong) value).c(); //Long inside a NBTNumber | ||||
| 			} else if (value instanceof NBTTagFloat) { | ||||
| 				return ((NBTTagFloat) value).h(); //Float inside a NBTNumber | ||||
| 			} else if (value instanceof NBTTagDouble) { | ||||
| 				return ((NBTTagDouble) value).g(); //Double inside a NBTNumber | ||||
| 			} else if (value instanceof NBTTagString) { | ||||
| 				return ((NBTTagString) value).a_(); //String inside the NBTTagString | ||||
| 			} else if (value instanceof NBTBase) { | ||||
| 				return value; //No need to convert this | ||||
| 			} | ||||
| 		} | ||||
| 		return null; | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public void clearPathfinderGoals(Entity entity) { | ||||
| 		EntityInsentient nmsEnt = (EntityInsentient) ((CraftEntity) entity).getHandle(); | ||||
| 		((LinkedHashSet<?>) ReflectionUtils.getField("b", PathfinderGoalSelector.class, nmsEnt.goalSelector)).clear(); | ||||
| 		((LinkedHashSet<?>) ReflectionUtils.getField("c", PathfinderGoalSelector.class, nmsEnt.goalSelector)).clear(); | ||||
| 		((LinkedHashSet<?>) ReflectionUtils.getField("b", PathfinderGoalSelector.class, nmsEnt.targetSelector)).clear(); | ||||
| 		((LinkedHashSet<?>) ReflectionUtils.getField("c", PathfinderGoalSelector.class, nmsEnt.targetSelector)).clear(); | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public void removePathfinderGoal(Object entity, Class<?> goalClass, boolean isTargetSelector) { | ||||
| 		if (entity instanceof EntityInsentient) { | ||||
| 			((EntityInsentient) entity).setGoalTarget(null); | ||||
| 			if (isTargetSelector) { | ||||
| 				Iterator<?> goals = ((LinkedHashSet<?>) ReflectionUtils.getField("b", PathfinderGoalSelector.class, ((EntityInsentient) entity).targetSelector)).iterator(); | ||||
| 				while (goals.hasNext()) { | ||||
| 					Object goal = goals.next(); | ||||
| 					if (ReflectionUtils.getField("a", goal.getClass(), goal).getClass() == goalClass) { | ||||
| 						goals.remove(); | ||||
| 					} | ||||
| 				} | ||||
| 			} else { | ||||
| 				Iterator<?> goals = ((LinkedHashSet<?>) ReflectionUtils.getField("b", PathfinderGoalSelector.class, ((EntityInsentient) entity).goalSelector)).iterator(); | ||||
| 				while (goals.hasNext()) { | ||||
| 					Object goal = goals.next(); | ||||
| 					if (ReflectionUtils.getField("a", goal.getClass(), goal).getClass() == goalClass) { | ||||
| 						goals.remove(); | ||||
| 					} | ||||
| 				} | ||||
| 			} | ||||
| 		} | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public void addPathfinderGoal(Object entity, int priority, Object goal, boolean isTargetSelector) { | ||||
| 		if (entity instanceof EntityInsentient && goal instanceof PathfinderGoal) { | ||||
| 			if (isTargetSelector) | ||||
| 				((EntityInsentient) entity).targetSelector.a(priority, (PathfinderGoal) goal); | ||||
| 			else | ||||
| 				((EntityInsentient) entity).goalSelector.a(priority, (PathfinderGoal) goal); | ||||
| 		} | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public void registerCompoundClassInfo() { | ||||
| 		Classes.registerClass(new ClassInfo<NBTTagCompound>(NBTTagCompound.class, "compound").user("((nbt)?( ?tag)?) ?compounds?").name("NBT Compound").changer(new Changer<NBTTagCompound>() { | ||||
| 
 | ||||
| 			@SuppressWarnings("unchecked") | ||||
| 			@Override | ||||
| 			@Nullable | ||||
| 			public Class<?>[] acceptChange(ChangeMode mode) { | ||||
| 				if (mode == ChangeMode.ADD || mode == ChangeMode.REMOVE) { | ||||
| 					return CollectionUtils.array(String.class, NBTTagCompound.class); | ||||
| 				} | ||||
| 				return null; | ||||
| 			} | ||||
| 
 | ||||
| 			@Override | ||||
| 			public void change(NBTTagCompound[] NBT, @Nullable Object[] delta, ChangeMode mode) { | ||||
| 				if (mode == ChangeMode.ADD) { | ||||
| 					if (delta[0] instanceof String) { | ||||
| 						NBTTagCompound parsedNBT = parseRawNBT((String) delta[0]); | ||||
| 						addToCompound(NBT[0], parsedNBT); | ||||
| 					} else { | ||||
| 						addToCompound(NBT[0], delta[0]); | ||||
| 					} | ||||
| 				} else if (mode == ChangeMode.REMOVE) { | ||||
| 					if (delta[0] instanceof NBTTagCompound) | ||||
| 						return; | ||||
| 					for (Object s : delta) { | ||||
| 						NBT[0].remove((String) s); | ||||
| 					} | ||||
| 				} | ||||
| 			} | ||||
| 		}).parser(new Parser<NBTTagCompound>() { | ||||
| 
 | ||||
| 			@Override | ||||
| 			public String getVariableNamePattern() { | ||||
| 				return ".+"; | ||||
| 			} | ||||
| 
 | ||||
| 			@Override | ||||
| 			@Nullable | ||||
| 			public NBTTagCompound parse(String rawNBT, ParseContext context) { | ||||
| 				if (rawNBT.startsWith("nbt:{") && rawNBT.endsWith("}")) { | ||||
| 					NBTTagCompound NBT = parseRawNBT(rawNBT.substring(4)); | ||||
| 					return NBT; | ||||
| 				} | ||||
| 				return null; | ||||
| 			} | ||||
| 
 | ||||
| 			@Override | ||||
| 			public String toString(NBTTagCompound compound, int arg1) { | ||||
| 				return compound.toString(); | ||||
| 			} | ||||
| 
 | ||||
| 			@Override | ||||
| 			public String toVariableNameString(NBTTagCompound compound) { | ||||
| 				return compound.toString(); | ||||
| 			} | ||||
| 		}).serializer(new Serializer<NBTTagCompound>() { | ||||
| 
 | ||||
| 			@Override | ||||
| 			public Fields serialize(NBTTagCompound compound) throws NotSerializableException { | ||||
| 				Fields f = new Fields(); | ||||
| 				f.putObject("asString", compound.toString()); | ||||
| 				return f; | ||||
| 			} | ||||
| 
 | ||||
| 			@Override | ||||
| 			public void deserialize(NBTTagCompound compound, Fields f) throws StreamCorruptedException, NotSerializableException { | ||||
| 				assert false; | ||||
| 			} | ||||
| 
 | ||||
| 			@Override | ||||
| 			protected boolean canBeInstantiated() { | ||||
| 				return false; | ||||
| 			} | ||||
| 
 | ||||
| 			@Override | ||||
| 			protected NBTTagCompound deserialize(Fields fields) throws StreamCorruptedException, NotSerializableException { | ||||
| 				String raw = fields.getObject("asString", String.class); | ||||
| 				NBTTagCompound compound =  parseRawNBT(raw); | ||||
| 				if (compound == null) { | ||||
| 					throw new StreamCorruptedException("Unable to parse NBT from a variable: " + raw); | ||||
| 				} | ||||
| 				return compound; | ||||
| 			} | ||||
| 
 | ||||
| 			@Override | ||||
| 			@Nullable | ||||
| 			public NBTTagCompound deserialize(String s) { | ||||
| 				NBTTagCompound compound =  parseRawNBT(s); | ||||
| 				return compound; | ||||
| 			} | ||||
| 
 | ||||
| 			@Override | ||||
| 			public boolean mustSyncDeserialization() { | ||||
| 				return true; | ||||
| 			} | ||||
| 		})); | ||||
| 
 | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public void registerNBTListClassInfo() { | ||||
| 		Classes.registerClass(new ClassInfo<NBTTagList>(NBTTagList.class, "nbtlist").user("nbt ?list ?(tag)?").name("NBT List").changer(new Changer<NBTTagList>() { | ||||
| 
 | ||||
| 			@SuppressWarnings("unchecked") | ||||
| 			@Override | ||||
| 			@Nullable | ||||
| 			public Class<?>[] acceptChange(ChangeMode mode) { | ||||
| 				if (mode == ChangeMode.ADD) { | ||||
| 					return CollectionUtils.array(Byte.class, Short.class, Integer.class, Long.class, Float.class, Double.class, String.class, NBTTagCompound.class, NBTTagList.class); | ||||
| 				} | ||||
| 				return null; | ||||
| 			} | ||||
| 
 | ||||
| 			@Override | ||||
| 			public void change(NBTTagList[] nbtList, @Nullable Object[] delta, ChangeMode mode) { | ||||
| 				if (delta.length == 0) | ||||
| 					return; | ||||
| 				if (delta[0] instanceof Number) { | ||||
| 					addToList(nbtList[0], convertToNBT((Number) delta[0])); | ||||
| 				} else if (delta[0] instanceof String) { | ||||
| 					addToList(nbtList[0], convertToNBT((String) delta[0])); | ||||
| 				} else if (delta[0] instanceof NBTBase) { | ||||
| 					addToList(nbtList[0], delta[0]); | ||||
| 				} | ||||
| 			} | ||||
| 		}).parser(new Parser<NBTTagList>() { | ||||
| 
 | ||||
| 			@Override | ||||
| 			public String getVariableNamePattern() { | ||||
| 				return ".+"; | ||||
| 			} | ||||
| 
 | ||||
| 			@Override | ||||
| 			@Nullable | ||||
| 			public NBTTagList parse(String listString, ParseContext context) { | ||||
| 				if ((listString.startsWith("nbt:[") || listString.startsWith("nbtlist:[")) && listString.endsWith("]")) { | ||||
| 					int substring; | ||||
| 					if (listString.startsWith("nbt:[")) { | ||||
| 						substring = 4; | ||||
| 					} else { // "nbtlist:[WHATEVER]" | ||||
| 						substring = 8; | ||||
| 					} | ||||
| 					NBTTagCompound tempNBT =  parseRawNBT("{temp:" + listString.substring(substring) + "}"); | ||||
| 					NBTTagList parsedList = (NBTTagList) tempNBT.get("temp"); | ||||
| 					return parsedList; | ||||
| 				} | ||||
| 				return null; | ||||
| 			} | ||||
| 
 | ||||
| 			@Override | ||||
| 			public String toString(NBTTagList nbtList, int arg1) { | ||||
| 				return nbtList.toString(); | ||||
| 			} | ||||
| 
 | ||||
| 			@Override | ||||
| 			public String toVariableNameString(NBTTagList nbtList) { | ||||
| 				return nbtList.toString(); | ||||
| 			} | ||||
| 		}).serializer(new Serializer<NBTTagList>() { | ||||
| 
 | ||||
| 			@Override | ||||
| 			public Fields serialize(NBTTagList nbtList) throws NotSerializableException { | ||||
| 				Fields f = new Fields(); | ||||
| 				f.putObject("asString", nbtList.toString()); | ||||
| 				return f; | ||||
| 			} | ||||
| 
 | ||||
| 			@Override | ||||
| 			public void deserialize(NBTTagList nbtList, Fields f) throws StreamCorruptedException, NotSerializableException { | ||||
| 				assert false; | ||||
| 			} | ||||
| 
 | ||||
| 			@Override | ||||
| 			protected boolean canBeInstantiated() { | ||||
| 				return false; | ||||
| 			} | ||||
| 
 | ||||
| 			@Override | ||||
| 			protected NBTTagList deserialize(Fields fields) throws StreamCorruptedException, NotSerializableException { | ||||
| 				String s = fields.getObject("asString", String.class); | ||||
| 				NBTTagCompound tempNBT =  parseRawNBT("{temp:" + s + "}"); | ||||
| 				if (tempNBT == null || !tempNBT.hasKey("temp")) { | ||||
| 					throw new StreamCorruptedException("Unable to parse NBT list from a variable: " + s); | ||||
| 				} | ||||
| 				NBTTagList nbtList = (NBTTagList) tempNBT.get("temp"); | ||||
| 				return nbtList; | ||||
| 			} | ||||
| 
 | ||||
| 			@Override | ||||
| 			@Nullable | ||||
| 			public NBTTagList deserialize(String s) { | ||||
| 				NBTTagCompound tempNBT =  parseRawNBT("{temp:" + s + "}"); | ||||
| 				NBTTagList nbtList = (NBTTagList) tempNBT.get("temp"); | ||||
| 				return nbtList; | ||||
| 			} | ||||
| 
 | ||||
| 			@Override | ||||
| 			public boolean mustSyncDeserialization() { | ||||
| 				return true; | ||||
| 			} | ||||
| 		})); | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public NBTTagCompound getEntityNBT(Entity entity) { | ||||
| 		net.minecraft.server.v1_9_R2.Entity nmsEntity = ((CraftEntity) entity).getHandle(); | ||||
| 		NBTTagCompound NBT = new NBTTagCompound(); | ||||
| 		nmsEntity.e(NBT); | ||||
| 		return NBT; | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public NBTTagCompound getTileNBT(Block block) { | ||||
| 		NBTTagCompound NBT = new NBTTagCompound(); | ||||
| 		World nmsWorld = ((CraftWorld) block.getWorld()).getHandle(); | ||||
| 		TileEntity tileEntity = nmsWorld.getTileEntity(new BlockPosition(block.getX(), block.getY(), block.getZ())); | ||||
| 		if (tileEntity == null) | ||||
| 			return null; | ||||
| 		tileEntity.save(NBT); | ||||
| 		return NBT; | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public NBTTagCompound getItemNBT(ItemStack itemStack) { | ||||
| 		if (itemStack == null || itemStack.getType() == Material.AIR) | ||||
| 			return null; | ||||
| 		NBTTagCompound itemNBT = CraftItemStack.asNMSCopy(itemStack).getTag(); | ||||
| 		if (itemNBT == null) | ||||
| 			itemNBT = new NBTTagCompound(); | ||||
| 		return itemNBT; | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public void setEntityNBT(Entity entity, Object newCompound) { | ||||
| 		if (newCompound instanceof NBTTagCompound) { | ||||
| 			net.minecraft.server.v1_9_R2.Entity nmsEntity = ((CraftEntity) entity).getHandle(); | ||||
| 			nmsEntity.f((NBTTagCompound) newCompound); | ||||
| 		} | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public void setTileNBT(Block block, Object newCompound) { | ||||
| 		if (newCompound instanceof NBTTagCompound) { | ||||
| 			World nmsWorld = ((CraftWorld) block.getWorld()).getHandle(); | ||||
| 			TileEntity tileEntity = nmsWorld.getTileEntity(new BlockPosition(block.getX(), block.getY(), block.getZ())); | ||||
| 			if (tileEntity == null) | ||||
| 				return; | ||||
| 			tileEntity.a((NBTTagCompound) newCompound); | ||||
| 			tileEntity.update(); | ||||
| 			IBlockData tileEntType = nmsWorld.getType(new BlockPosition(block.getX(), block.getY(), block.getZ())); | ||||
| 			nmsWorld.notify(tileEntity.getPosition(), tileEntType, tileEntType, 3); | ||||
| 		} | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public ItemStack getItemWithNBT(ItemStack itemStack, Object compound) { | ||||
| 		net.minecraft.server.v1_9_R2.ItemStack nmsItem = CraftItemStack.asNMSCopy(itemStack); | ||||
| 		if (compound instanceof NBTTagCompound && itemStack != null) { | ||||
| 			if (itemStack.getType() == Material.AIR) | ||||
| 				return null; | ||||
| 			if (((NBTTagCompound) compound).isEmpty()) | ||||
| 				return itemStack; | ||||
| 			nmsItem.setTag((NBTTagCompound) compound); | ||||
| 			ItemStack newItem = CraftItemStack.asBukkitCopy(nmsItem); | ||||
| 			return newItem; | ||||
| 		} else if (compound == null) { | ||||
| 			nmsItem.setTag(null); | ||||
| 			ItemStack newItem = CraftItemStack.asBukkitCopy(nmsItem); | ||||
| 			return newItem; | ||||
| 		} | ||||
| 		return itemStack; | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public NBTTagCompound getFileNBT(File file) { | ||||
| 		FileInputStream fis = null; | ||||
| 		try { | ||||
| 			fis = new FileInputStream(file); | ||||
| 		} catch (FileNotFoundException ex) { | ||||
| 			return null; //File doesn't exist. | ||||
| 		} | ||||
| 		NBTTagCompound fileNBT = null; | ||||
| 		try { | ||||
| 			fileNBT = NBTCompressedStreamTools.a(fis); | ||||
| 			fis.close(); | ||||
| 		} catch (IOException ex) { | ||||
| 			if (ex instanceof EOFException) { | ||||
| 				; //Nothing. | ||||
| 			} else { | ||||
| 				ex.printStackTrace(); | ||||
| 			} | ||||
| 		} | ||||
| 		return fileNBT; | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public void setFileNBT(File file, Object newCompound) { | ||||
| 		if (newCompound instanceof NBTTagCompound) { | ||||
| 			OutputStream os = null; | ||||
| 			try { | ||||
| 				os = new FileOutputStream(file); | ||||
| 			} catch (FileNotFoundException ex) { | ||||
| 				ex.printStackTrace(); | ||||
| 			} | ||||
| 			try { | ||||
| 				NBTCompressedStreamTools.a((NBTTagCompound) newCompound, os); | ||||
| 				os.close(); | ||||
| 			} catch (IOException ex) { | ||||
| 				if (ex instanceof EOFException) { | ||||
| 					; //Ignore, just end of the file | ||||
| 				} else { | ||||
| 					ex.printStackTrace(); | ||||
| 				} | ||||
| 			} | ||||
| 		} | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public NBTBase convertToNBT(Number number) { | ||||
| 		if (number instanceof Byte) { | ||||
| 			return new NBTTagByte((byte) number); | ||||
| 		} else if (number instanceof Short) { | ||||
| 			return new NBTTagShort((short) number); | ||||
| 		} else if (number instanceof Integer) { | ||||
| 			return new NBTTagInt((int) number); | ||||
| 		} else if (number instanceof Long) { | ||||
| 			return new NBTTagLong((long) number); | ||||
| 		} else if (number instanceof Float) { | ||||
| 			return new NBTTagFloat((float) number); | ||||
| 		} else if (number instanceof Double) { | ||||
| 			return new NBTTagDouble((double) number); | ||||
| 		} | ||||
| 		return null; | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public NBTTagString convertToNBT(String string) { | ||||
| 		return new NBTTagString(string); | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public String getMCId(ItemStack itemStack) { | ||||
| 		net.minecraft.server.v1_9_R2.ItemStack nmsItem = CraftItemStack.asNMSCopy(itemStack); | ||||
| 		MinecraftKey mcKey = Item.REGISTRY.b(nmsItem.getItem()); | ||||
| 		return mcKey.toString(); | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public ItemStack getItemFromMcId(String mcId) { | ||||
| 		MinecraftKey mcKey = new MinecraftKey(mcId); | ||||
| 		Item nmsItem = (Item) Item.REGISTRY.get(mcKey); | ||||
| 		return CraftItemStack.asNewCraftStack(nmsItem); | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public boolean getNoClip(Entity entity) { | ||||
| 		net.minecraft.server.v1_9_R2.Entity nmsEntity = ((CraftEntity) entity).getHandle(); | ||||
| 		return nmsEntity.noclip; | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public void setNoClip(Entity entity, boolean noclip) { | ||||
| 		net.minecraft.server.v1_9_R2.Entity nmsEntity = ((CraftEntity) entity).getHandle(); | ||||
| 		nmsEntity.noclip = noclip; | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public boolean getFireProof(Entity entity) { | ||||
| 		net.minecraft.server.v1_9_R2.Entity nmsEntity = ((CraftEntity) entity).getHandle(); | ||||
| 		return nmsEntity.isFireProof(); | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public void setFireProof(Entity entity, boolean fireProof) { | ||||
| 		net.minecraft.server.v1_9_R2.Entity nmsEntity = ((CraftEntity) entity).getHandle(); | ||||
| 		ReflectionUtils.setField("fireProof", nmsEntity.getClass(), nmsEntity, fireProof); | ||||
| 	} | ||||
| 
 | ||||
| 	/* | ||||
| 	@SuppressWarnings("unchecked") | ||||
| 	@Override | ||||
| 	public ItemStack[] getEndermanBlocks(Entity enderman) { | ||||
| 		EntityEnderman nmsEnder = ((CraftEnderman) enderman).getHandle(); | ||||
| 		Set<net.minecraft.server.v1_9_R2.Block> nmsBlocks = (Set<net.minecraft.server.v1_9_R1.Block>) ReflectionUtils.getField("c", EntityEnderman.class, nmsEnder); | ||||
| 		ItemStack[] items = new ItemStack[nmsBlocks.size()]; | ||||
| 		int i = 0; | ||||
| 		for (net.minecraft.server.v1_9_R2.Block nmsBlock : nmsBlocks) { | ||||
| 			IBlockData nmsBlockData = nmsBlock.getBlockData(); | ||||
| 			int dataValue = nmsBlock.toLegacyData(nmsBlockData); | ||||
| 			net.minecraft.server.v1_9_R2.ItemStack nmsItem = new net.minecraft.server.v1_9_R1.ItemStack(nmsBlock, 1, dataValue); | ||||
| 			ItemStack bukkitItem = CraftItemStack.asCraftMirror(nmsItem); | ||||
| 			items[i] = bukkitItem; | ||||
| 			i++; | ||||
| 		} | ||||
| 		return items; | ||||
| 	} | ||||
| 
 | ||||
| 	@SuppressWarnings("unchecked") | ||||
| 	@Override | ||||
| 	public void setEndermanBlocks(Entity enderman, ItemStack... blocks) { | ||||
| 		EntityEnderman nmsEnder = ((CraftEnderman) enderman).getHandle(); | ||||
| 		Set<net.minecraft.server.v1_9_R2.Block> nmsBlocks = (Set<net.minecraft.server.v1_9_R1.Block>) ReflectionUtils.getField("c", EntityEnderman.class, nmsEnder); | ||||
| 		for (ItemStack block : blocks) { | ||||
| 			if (!block.getType().isBlock()) | ||||
| 				return; | ||||
| 			// TODO Figure out how to get a Blocks from a Bukkit ItemStack | ||||
| 			// Blocks.class has a PRIVATE method to get from a MC id. | ||||
| 		} | ||||
| 	} | ||||
| 	*/ | ||||
| 
 | ||||
| 	@Override | ||||
| 	public Location getLastLocation(Entity entity) { | ||||
| 		net.minecraft.server.v1_9_R2.Entity nmsEntity = ((CraftEntity) entity).getHandle(); | ||||
| 		org.bukkit.World world = nmsEntity.world.getWorld(); | ||||
| 		Location lastEntLoc = new Location(world, nmsEntity.M, nmsEntity.N, nmsEntity.O); | ||||
| 		return lastEntLoc; | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public float getEntityStepLength(Entity entity) { | ||||
| 		net.minecraft.server.v1_9_R2.Entity nmsEntity = ((CraftEntity) entity).getHandle(); | ||||
| 		return nmsEntity.P; | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public void setEntityStepLength(Entity entity, float length) { | ||||
| 		net.minecraft.server.v1_9_R2.Entity nmsEntity = ((CraftEntity) entity).getHandle(); | ||||
| 		nmsEntity.P = length; | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public boolean getElytraGlideState(Entity entity) { | ||||
| 		EntityLiving nmsEntity = ((CraftLivingEntity) entity).getHandle(); | ||||
| 		return nmsEntity.getFlag(7); | ||||
| 	} | ||||
| 	 | ||||
| 	public void setElytraGlideState(Entity entity, boolean glide) { | ||||
| 		EntityLiving nmsEntity = ((CraftLivingEntity) entity).getHandle(); | ||||
| 		nmsEntity.setFlag(7, glide); | ||||
| 	} | ||||
| 	 | ||||
| 	public boolean getNoGravity(Entity entity) { | ||||
| 		Bukkit.getLogger().warning("Executed \"Get no gravity state of entity\" code on 1.9! How the hell did this even happen!!"); | ||||
| 		return false; | ||||
| 	} | ||||
| 	 | ||||
| 	public void setNoGravity(Entity entity, boolean noGravity) { | ||||
| 		Bukkit.getLogger().warning("Executed \"Set no gravity state of entity\" code on 1.9! How the hell did this even happen!!"); | ||||
| 	} | ||||
| } | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user
	 Govindass
						Govindass