Compare commits
9 Commits
master
...
1.6.4.2-fo
Author | SHA1 | Date | |
---|---|---|---|
|
0d33ad8a66 | ||
|
f8861cf6f1 | ||
|
9bfbcd9639 | ||
|
210bb8c315 | ||
|
a3e52580c2 | ||
|
bf9514c322 | ||
|
bf5e005a80 | ||
|
98ed997070 | ||
|
a943eb6882 |
68
README.md
68
README.md
@ -1,13 +1,65 @@
|
||||
## Unofficial fork of [SkStuff](https://github.com/TheBukor/SkStuff)
|
||||
|
||||
As the owner is missing for a few weeks, this fork brings nbt support to 1.12. Only use it in case the official one still not supported.
|
||||
This fork adds 1.13.2 and 1.14.2 support, removes support for older than 1.13 versions, removes worldguard/worldedit, vanishnospacket and nbt stuff. This fork is focused on making pathfinder goals to work as they are unique to SkStuff. Note that I'm not very experienced Java developer yet, so it is possible that I have made some mistakes, but from my little testings things are working.
|
||||
|
||||
**Download it [here](https://github.com/Tuke-Nuke/SkStuff/releases)**
|
||||
**Download it [here](https://github.com/Govindass/SkStuff/releases)**
|
||||
|
||||
In case of **bugs**:
|
||||
* If it is a bug related to NBTs or Pathfind and it only happens in 1.12, you can report it here and I will try to help.
|
||||
* Any other bugs, should be reported at official pages. Since it is a temporary fork.
|
||||
**Little Pathfinder Goals Tutorial**
|
||||
Add pathfinder goals with:
|
||||
```
|
||||
add pathfind[er] goal [[with] priority %-integer%] <insert pathfinder goal here> to %livingentities%
|
||||
```
|
||||
|
||||
List of Pathfinder Goals
|
||||
```
|
||||
(avoid|run away from) %entitytype%[, radius %number%[, speed %number%[, speed (if|when) (close|near) %number%]]]
|
||||
break door[s]
|
||||
breed[, [move[ment]] speed %number%] #Note 1
|
||||
eat grass
|
||||
(flee from the sun|seek shad(e|ow))[, [move[ment]] speed %number%]
|
||||
(float (in[side]|on) water|swim)
|
||||
follow (owner|tamer)[, speed %number%[, min[imum] distance %number%[, max[imum] distance %number%]]] #Note 2
|
||||
follow (adult|parent)[s][, [move[ment]] speed %number%] #Note 3
|
||||
(fight back|react to|target) (damager|attacker) [[of] type] %entitytype%[, call ([for] help|reinforcement) %boolean%]
|
||||
o(c|z)elot jump on blocks[, [move[ment]] speed %number%]
|
||||
leap at target[, [leap] height %number%]
|
||||
look at %entitytype%[, (radius|max[imum] distance) %number%]
|
||||
melee attack %entitytype%[, [move[ment]] speed %number%[, (memorize|do('nt| not) forget) target [for [a] long[er] time] %boolean%]] #Note 4
|
||||
move to[wards] target[, [move[ment]] speed %number%[, (radius|max[imum] distance) %number%]]
|
||||
target nearest [entity [of] type] %entitytype%[, check sight %boolean%] #Note 5
|
||||
o(c|z)elot attack #Note 6
|
||||
open door[s]
|
||||
(panic|flee)[, [move[ment]] speed %number%]
|
||||
look around randomly
|
||||
(walk around randomly|wander)[, [move[ment]] speed %number%[, min[imum] [of] %timespan% between mov(e[ment][s]|ing)]]
|
||||
sit #Note 2
|
||||
[creeper] (explode|inflate|swell)
|
||||
squid (swim around|wander)
|
||||
shoot fireball[s] #Note 7
|
||||
[silverfish] hide (in[side]|on) block[s]
|
||||
(call|summon|wake) [other] [hidden] silverfish[es]
|
||||
[enderman] pick[[ ]up] block[s]
|
||||
[enderman] place block[s]
|
||||
[enderman] attack player (staring|looking) at [their] eye[s]]
|
||||
ghast move to[wards] target
|
||||
ghast (idle move[ment]|wander|random fl(ight|y[ing]))
|
||||
(tempt to|follow players (holding|with)) %itemstack%[, [move[ment]] speed %number%[, scared of player movement %boolean%]]
|
||||
target [random] %entitytype% (if|when) (not |un)tamed #Note 2
|
||||
guardian attack [entities] #Note 6
|
||||
[z[ombie[ ]]pig[man]] attack [player[s]] (if|when) angry
|
||||
[z[ombie[ ]]pig[man]] (react to|fight back|target) (attacker|damager) (if|when) angry
|
||||
[rabbit] eat carrot crops
|
||||
[killer] rabbit [melee] attack
|
||||
slime [random] jump
|
||||
slime change (direction|facing) randomly
|
||||
slime (idle move[ment]|wander)
|
||||
|
||||
---
|
||||
|
||||
[**Github**](https://github.com/TheBukor/SkStuff) - [**skUnity**](https://forums.skunity.com/resources/skstuff.131/)
|
||||
Notes:
|
||||
1 - Can only be applied to breedable animals.
|
||||
2 - Can only be applied to tameable animals (Wolves and Ocelots).
|
||||
3 - Only takes effect when the entity is a baby (age is less than 0).
|
||||
4 - The boolean argument specifies whether or not the entity should lose interest on its target if there's no suitable path. The speed parameter will ALWAYS be 1 for SPIDERS. The boolean will ALWAYS be TRUE for SPIDERS.
|
||||
5 - The boolean argument specifier whether or not the entity should have a direct line of sight of its target. Examples are spiders, by default they can see players through blocks. The boolean argument will ALWAYS be TRUE for SPIDERS.
|
||||
6 - If this goal is missing on the entity, it will not be able to attack.
|
||||
7 - Can only be applied on Ghasts or Blazes.
|
||||
```
|
||||
|
@ -1,6 +1,6 @@
|
||||
name: SkStuff
|
||||
author: TheBukor
|
||||
description: A Skript addon which adds extra functionalities such as NBT and extended WorldEdit support.
|
||||
version: 1.6.4.1-fork-1.12
|
||||
author: [TheBukor, Govindas]
|
||||
description: A Skript addon which adds extra functionalities such as pathfinder goals.
|
||||
version: 1.6.4.2-fork-1.13-1.14
|
||||
main: me.TheBukor.SkStuff.SkStuff
|
||||
softdepend: [Skript, WorldEdit, VanishNoPacket]
|
||||
softdepend: [Skript]
|
||||
|
3
src/META-INF/MANIFEST.MF
Normal file
3
src/META-INF/MANIFEST.MF
Normal file
@ -0,0 +1,3 @@
|
||||
Manifest-Version: 1.0
|
||||
Main-Class: me.TheBukor.SkStuff.SkStuff
|
||||
|
@ -7,93 +7,41 @@ import javax.annotation.Nullable;
|
||||
import me.TheBukor.SkStuff.util.*;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.entity.EntityToggleGlideEvent;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.kitteh.vanish.event.VanishStatusChangeEvent;
|
||||
import org.mcstats.Metrics;
|
||||
|
||||
import com.sk89q.worldedit.EditSession;
|
||||
import com.sk89q.worldguard.bukkit.WGBukkit;
|
||||
import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
|
||||
import com.sk89q.worldguard.protection.flags.DefaultFlag;
|
||||
import com.sk89q.worldguard.protection.flags.Flag;
|
||||
import com.sk89q.worldguard.protection.flags.registry.FlagRegistry;
|
||||
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
|
||||
|
||||
|
||||
import ch.njol.skript.Skript;
|
||||
import ch.njol.skript.classes.ClassInfo;
|
||||
import ch.njol.skript.classes.Parser;
|
||||
import ch.njol.skript.expressions.base.EventValueExpression;
|
||||
import ch.njol.skript.lang.ExpressionType;
|
||||
import ch.njol.skript.lang.ParseContext;
|
||||
import ch.njol.skript.lang.util.SimpleEvent;
|
||||
import ch.njol.skript.registrations.Classes;
|
||||
import ch.njol.skript.registrations.EventValues;
|
||||
import ch.njol.skript.util.Getter;
|
||||
import me.TheBukor.SkStuff.conditions.CondSelectionContains;
|
||||
import me.TheBukor.SkStuff.effects.EffClearPathGoals;
|
||||
import me.TheBukor.SkStuff.effects.EffDrainLiquid;
|
||||
import me.TheBukor.SkStuff.effects.EffDrawLineWE;
|
||||
import me.TheBukor.SkStuff.effects.EffGZipFile;
|
||||
import me.TheBukor.SkStuff.effects.EffMakeCylinder;
|
||||
import me.TheBukor.SkStuff.effects.EffMakeJump;
|
||||
import me.TheBukor.SkStuff.effects.EffMakePyramid;
|
||||
import me.TheBukor.SkStuff.effects.EffMakeSphere;
|
||||
import me.TheBukor.SkStuff.effects.EffMakeWalls;
|
||||
import me.TheBukor.SkStuff.effects.EffNaturalize;
|
||||
import me.TheBukor.SkStuff.effects.EffPasteSchematic;
|
||||
import me.TheBukor.SkStuff.effects.EffRememberChanges;
|
||||
import me.TheBukor.SkStuff.effects.EffRemovePathGoal;
|
||||
import me.TheBukor.SkStuff.effects.EffReplaceBlocksWE;
|
||||
import me.TheBukor.SkStuff.effects.EffResourceSound;
|
||||
import me.TheBukor.SkStuff.effects.EffSetBlocksWE;
|
||||
import me.TheBukor.SkStuff.effects.EffSetPathGoal;
|
||||
import me.TheBukor.SkStuff.effects.EffShowEntityEffect;
|
||||
import me.TheBukor.SkStuff.effects.EffSimulateSnow;
|
||||
import me.TheBukor.SkStuff.effects.EffToggleVanish;
|
||||
import me.TheBukor.SkStuff.effects.EffUndoRedoSession;
|
||||
import me.TheBukor.SkStuff.events.EvtWorldEditChange;
|
||||
import me.TheBukor.SkStuff.events.WorldEditChangeHandler;
|
||||
import me.TheBukor.SkStuff.expressions.ExprChangedBlocksSession;
|
||||
import me.TheBukor.SkStuff.expressions.ExprClickedInventory;
|
||||
import me.TheBukor.SkStuff.expressions.ExprEditSessionLimit;
|
||||
import me.TheBukor.SkStuff.expressions.ExprFileNBT;
|
||||
|
||||
import me.TheBukor.SkStuff.expressions.ExprFireProof;
|
||||
import me.TheBukor.SkStuff.expressions.ExprFlagOfWGRegion;
|
||||
import me.TheBukor.SkStuff.expressions.ExprFlagsOfWGRegion;
|
||||
import me.TheBukor.SkStuff.expressions.ExprGlideState;
|
||||
import me.TheBukor.SkStuff.expressions.ExprInventoryOwner;
|
||||
import me.TheBukor.SkStuff.expressions.ExprItemNBT;
|
||||
import me.TheBukor.SkStuff.expressions.ExprLastLocation;
|
||||
import me.TheBukor.SkStuff.expressions.ExprMCIdOf;
|
||||
import me.TheBukor.SkStuff.expressions.ExprMCIdToItem;
|
||||
import me.TheBukor.SkStuff.expressions.ExprNBTListContents;
|
||||
import me.TheBukor.SkStuff.expressions.ExprNBTListIndex;
|
||||
import me.TheBukor.SkStuff.expressions.ExprNBTOf;
|
||||
import me.TheBukor.SkStuff.expressions.ExprNewEditSession;
|
||||
|
||||
|
||||
|
||||
import me.TheBukor.SkStuff.expressions.ExprNoClip;
|
||||
import me.TheBukor.SkStuff.expressions.ExprNoGravityState;
|
||||
import me.TheBukor.SkStuff.expressions.ExprRegionsWithinLocation;
|
||||
import me.TheBukor.SkStuff.expressions.ExprSchematicArea;
|
||||
import me.TheBukor.SkStuff.expressions.ExprSelectionArea;
|
||||
import me.TheBukor.SkStuff.expressions.ExprSelectionOfPlayer;
|
||||
import me.TheBukor.SkStuff.expressions.ExprSelectionPos;
|
||||
import me.TheBukor.SkStuff.expressions.ExprStepLength;
|
||||
import me.TheBukor.SkStuff.expressions.ExprSuperPickaxe;
|
||||
import me.TheBukor.SkStuff.expressions.ExprTagOf;
|
||||
|
||||
import me.TheBukor.SkStuff.expressions.ExprTimespanToNumber;
|
||||
import me.TheBukor.SkStuff.expressions.ExprToLowerCase;
|
||||
import me.TheBukor.SkStuff.expressions.ExprToUpperCase;
|
||||
import me.TheBukor.SkStuff.expressions.ExprVanishState;
|
||||
import me.TheBukor.SkStuff.expressions.ExprWGMemberOwner;
|
||||
import me.TheBukor.SkStuff.expressions.ExprWordsToUpperCase;
|
||||
|
||||
public class SkStuff extends JavaPlugin {
|
||||
@ -111,11 +59,11 @@ public class SkStuff extends JavaPlugin {
|
||||
Skript.registerAddon(this);
|
||||
getLogger().info("SkStuff " + this.getDescription().getVersion() + " has been successfully enabled!");
|
||||
getLogger().info("Registering general non version specific stuff...");
|
||||
Skript.registerEffect(EffShowEntityEffect.class, "(display|play|show) entity effect (0¦firework[s] explo(de|sion)|1¦hurt|2¦[[iron] golem] (give|offer) (rose|poppy)|3¦[sheep] eat grass|4¦wolf shake) at %entity%");
|
||||
Skript.registerEffect(EffShowEntityEffect.class, "(display|play|show) entity effect (0¦firework[s] explo(de|sion)|1¦hurt|2¦[[iron] golem] (give|offer) (rose|poppy)|3¦[sheep] eat grass|4¦wolf shake) at %entity%");
|
||||
Skript.registerExpression(ExprToUpperCase.class, String.class, ExpressionType.SIMPLE, "%string% [converted] to [all] (cap[ital]s|upper[ ]case)", "convert %string% to [all] (cap[ital]s|upper[ ]case)", "capitalize [all] [char[acter]s (of|in)] %string%");
|
||||
Skript.registerExpression(ExprToLowerCase.class, String.class, ExpressionType.SIMPLE, "%string% [converted] to [all] lower[ ]case", "convert %string% to [all] lower[ ]case", "un[( |-)]capitalize [all] [char[acter]s (of|in)] %string%");
|
||||
Skript.registerExpression(ExprWordsToUpperCase.class, String.class, ExpressionType.SIMPLE, "(first|1st) (letter|char[acter]) (of|in) (each word|[all] words) (of|in) %string% [converted] to (cap[ital]s|upper[ ]case) (0¦|1¦ignoring [other] upper[ ]case [(char[acter]s|letters)])", "convert (first|1st) (letter|char[acter]) (of|in) (each word|[all] words) (of|in) %string% to (cap[ital]s|upper[ ]case) (0¦|1¦ignoring [other] upper[ ]case [(char[acter]s|letters)])", "capitalize (first|1st) (letter|char[acter]) (of|in) (each word|[all] words) (of|in) %string% (0¦|1¦ignoring [other] upper[ ]case [(char[acter]s|letters)])");
|
||||
Skript.registerExpression(ExprTimespanToNumber.class, Number.class, ExpressionType.SIMPLE, "%timespan% [converted] [in]to (0¦ticks|1¦sec[ond]s|2¦min[ute]s|3¦hours|4¦days)");
|
||||
Skript.registerExpression(ExprWordsToUpperCase.class, String.class, ExpressionType.SIMPLE, "(first|1st) (letter|char[acter]) (of|in) (each word|[all] words) (of|in) %string% [converted] to (cap[ital]s|upper[ ]case) (0¦|1¦ignoring [other] upper[ ]case [(char[acter]s|letters)])", "convert (first|1st) (letter|char[acter]) (of|in) (each word|[all] words) (of|in) %string% to (cap[ital]s|upper[ ]case) (0¦|1¦ignoring [other] upper[ ]case [(char[acter]s|letters)])", "capitalize (first|1st) (letter|char[acter]) (of|in) (each word|[all] words) (of|in) %string% (0¦|1¦ignoring [other] upper[ ]case [(char[acter]s|letters)])");
|
||||
Skript.registerExpression(ExprTimespanToNumber.class, Number.class, ExpressionType.SIMPLE, "%timespan% [converted] [in]to (0¦ticks|1¦sec[ond]s|2¦min[ute]s|3¦hours|4¦days)");
|
||||
Skript.registerExpression(ExprClickedInventory.class, Inventory.class, ExpressionType.SIMPLE, "[skstuff] clicked inventory");
|
||||
Skript.registerExpression(ExprInventoryOwner.class, Object.class, ExpressionType.PROPERTY, "[inventory] (owner|holder) of %inventory%", "%inventory%'s [inventory] (owner|holder)");
|
||||
effAmount += 1;
|
||||
@ -144,175 +92,22 @@ public class SkStuff extends JavaPlugin {
|
||||
if (setupNMSVersion()) {
|
||||
getLogger().info("Trying to register version specific stuff...");
|
||||
Skript.registerEffect(EffClearPathGoals.class, "(clear|delete) [all] pathfind[er] goals (of|from) %livingentities%");
|
||||
Skript.registerEffect(EffRemovePathGoal.class, "remove pathfind[er] goal (0¦(avoid|run away from) entit(y|ies)|1¦break door[s]|2¦breed|3¦eat grass|4¦(flee from the sun|seek shad(e|ow))|5¦float (in[side]|on) water|6¦follow (owner|tamer)|7¦follow (adult|parent)[s]|8¦(fight back|react to|target) (damager|attacker)|9¦o(c|z)elot jump on blocks|10¦leap at target|11¦look at entit(y|ies)|12¦melee attack entit(y|ies)|13¦move to[wards] target|14¦target nearest entity|15¦o(c|z)elot attack [chicken[s]]|16¦open door[s]|17¦(panic|flee)|18¦look around randomly|19¦(walk around randomly|wander)|20¦sit|21¦[creeper] (explode|inflate|swell)|22¦squid (swim|wander)|23¦shoot fireball[s]|24¦[silverfish] hide (in[side]|on) block[s]|25¦(wake other silverfish[es]|[silverfish] call (help|reinforcement|other [hidden] silverfish[es]))|26¦[enderm(a|e)n] pick[[ ]up] block[s]|27¦[enderm(a|e)n] place block[s]|28¦[enderman] attack player (staring|looking) [at eye[s]]|29¦ghast move to[wards] target|30¦ghast (idle move[ment]|wander|random fl(ight|y[ing]))|31¦(tempt to|follow players (holding|with)) [a[n]] item|32¦target [random] entity (if|when) (not tamed|untamed)|33¦guardian attack [entity]|34¦[z[ombie[ ]]pig[man]] attack [player[s]] (if|when) angry|35¦[z[ombie[ ]]pig[man]] (react to|fight back|target) (attacker|damager) (if|when) angry|36¦[rabbit] eat carrot crops|37¦[killer] rabbit [melee] attack|38¦slime [random] jump|39¦slime change (direction|facing) randomly|40¦slime (idle move[ment]|wander)|41¦follow [entity]|42¦bow shoot) from %livingentities%");
|
||||
Skript.registerEffect(EffRemovePathGoal.class, "remove pathfind[er] goal (0¦(avoid|run away from) entit(y|ies)|1¦break door[s]|2¦breed|3¦eat grass|4¦(flee from the sun|seek shad(e|ow))|5¦float (in[side]|on) water|6¦follow (owner|tamer)|7¦follow (adult|parent)[s]|8¦(fight back|react to|target) (damager|attacker)|9¦o(c|z)elot jump on blocks|10¦leap at target|11¦look at entit(y|ies)|12¦melee attack entit(y|ies)|13¦move to[wards] target|14¦target nearest entity|15¦o(c|z)elot attack [chicken[s]]|16¦open door[s]|17¦(panic|flee)|18¦look around randomly|19¦(walk around randomly|wander)|20¦sit|21¦[creeper] (explode|inflate|swell)|22¦squid (swim|wander)|23¦shoot fireball[s]|24¦[silverfish] hide (in[side]|on) block[s]|25¦(wake other silverfish[es]|[silverfish] call (help|reinforcement|other [hidden] silverfish[es]))|26¦[enderm(a|e)n] pick[[ ]up] block[s]|27¦[enderm(a|e)n] place block[s]|28¦[enderman] attack player (staring|looking) [at eye[s]]|29¦ghast move to[wards] target|30¦ghast (idle move[ment]|wander|random fl(ight|y[ing]))|31¦(tempt to|follow players (holding|with)) [a[n]] item|32¦target [random] entity (if|when) (not tamed|untamed)|33¦guardian attack [entity]|34¦[z[ombie[ ]]pig[man]] attack [player[s]] (if|when) angry|35¦[z[ombie[ ]]pig[man]] (react to|fight back|target) (attacker|damager) (if|when) angry|36¦[rabbit] eat carrot crops|37¦[killer] rabbit [melee] attack|38¦slime [random] jump|39¦slime change (direction|facing) randomly|40¦slime (idle move[ment]|wander)|41¦follow [entity]|42¦bow shoot) from %livingentities%");
|
||||
// Note to self: whenever adding a new pathfinder goal, increase the expression index for 'entities' in EffSetPathGoal
|
||||
Skript.registerEffect(EffSetPathGoal.class, "add pathfind[er] goal [[with] priority %-integer%] (0¦(avoid|run away from) %*entitydatas%[, radius %-number%[, speed %-number%[, speed (if|when) (close|near) %-number%]]]|1¦break door[s]|2¦breed[,[move[ment]] speed %-number%]|3¦eat grass|4¦(flee from the sun|seek shad(e|ow))[, [move[ment]] speed %-number%]|5¦(float (in[side]|on) water|swim)|6¦follow (owner|tamer)[, speed %-number%[, min[imum] distance %-number%[, max[imum] distance %-number%]]]|7¦follow (adult|parent)[s][, [move[ment]] speed %-number%]|8¦(fight back|react to|target) (damager|attacker) [[of] type] %*entitydatas%[, call ([for] help|reinforcement) %-boolean%]|9¦o(c|z)elot jump on blocks[, [move[ment]] speed %-number%]|10¦leap at target[, [leap] height %-number%]|11¦look at %*entitydatas%[, (radius|max[imum] distance) %-number%]|12¦melee attack %*entitydatas%[, [move[ment]] speed %-number%[, (memorize|do('nt| not) forget) target [for [a] long[er] time] %-boolean%]]|13¦move to[wards] target[, [move[ment]] speed %-number%[, (radius|max[imum] distance) %-number%]]|14¦target nearest [entity [of] type] %*entitydatas%[, check sight %-boolean%]|15¦o(c|z)elot attack|16¦open door[s]|17¦(panic|flee)[, [move[ment]] speed %-number%]|18¦look around randomly|19¦(walk around randomly|wander)[, [move[ment]] speed %-number%[, min[imum] [of] %-timespan% between mov(e[ment][s]|ing)]]|20¦sit|21¦[creeper] (explode|inflate|swell)|22¦squid (swim around|wander)|23¦shoot fireball[s]|24¦[silverfish] hide (in[side]|on) block[s]|25¦((call|summon|wake) [other] [hidden] silverfish[es])|26¦[enderman] pick[[ ]up] block[s]|27¦[enderman] place block[s]|28¦[enderman] attack player (staring|looking) at [their] eye[s]]|29¦ghast move to[wards] target|30¦ghast (idle move[ment]|wander|random fl(ight|y[ing]))|31¦(tempt to|follow players (holding|with)) %-itemstack%[, [move[ment]] speed %number%[, scared of player movement %-boolean%]]|32¦target [random] %*entitydatas% (if|when) (not |un)tamed|33¦guardian attack [entities]|34¦[z[ombie[ ]]pig[man]] attack [player[s]] (if|when) angry|35¦[z[ombie[ ]]pig[man]] (react to|fight back|target) (attacker|damager) (if|when) angry|36¦[rabbit] eat carrot crops|37¦[killer] rabbit [melee] attack|38¦slime [random] jump|39¦slime change (direction|facing) randomly|40¦slime (idle move[ment]|wander)|41¦follow %*entitydatas%[, radius %-number%[, speed %-number%[, [custom[ ]]name[d] %-string%]]]|42¦bow shoot[, [move[ment]] speed %-number%[, unk[nown] param[eter] %-number%[, follow range %-number%]]])) to %livingentities%");
|
||||
Skript.registerEffect(EffSetPathGoal.class, "add pathfind[er] goal [[with] priority %-integer%] (0¦(avoid|run away from) %*entitydatas%[, radius %-number%[, speed %-number%[, speed (if|when) (close|near) %-number%]]]|1¦break door[s]|2¦breed[,[move[ment]] speed %-number%]|3¦eat grass|4¦(flee from the sun|seek shad(e|ow))[, [move[ment]] speed %-number%]|5¦(float (in[side]|on) water|swim)|6¦follow (owner|tamer)[, speed %-number%[, min[imum] distance %-number%[, max[imum] distance %-number%]]]|7¦follow (adult|parent)[s][, [move[ment]] speed %-number%]|8¦(fight back|react to|target) (damager|attacker) [[of] type] %*entitydatas%[, call ([for] help|reinforcement) %-boolean%]|9¦o(c|z)elot jump on blocks[, [move[ment]] speed %-number%]|10¦leap at target[, [leap] height %-number%]|11¦look at %*entitydatas%[, (radius|max[imum] distance) %-number%]|12¦melee attack %*entitydatas%[, [move[ment]] speed %-number%[, (memorize|do('nt| not) forget) target [for [a] long[er] time] %-boolean%]]|13¦move to[wards] target[, [move[ment]] speed %-number%[, (radius|max[imum] distance) %-number%]]|14¦target nearest [entity [of] type] %*entitydatas%[, check sight %-boolean%]|15¦o(c|z)elot attack|16¦open door[s]|17¦(panic|flee)[, [move[ment]] speed %-number%]|18¦look around randomly|19¦(walk around randomly|wander)[, [move[ment]] speed %-number%[, min[imum] [of] %-timespan% between mov(e[ment][s]|ing)]]|20¦sit|21¦[creeper] (explode|inflate|swell)|22¦squid (swim around|wander)|23¦shoot fireball[s]|24¦[silverfish] hide (in[side]|on) block[s]|25¦((call|summon|wake) [other] [hidden] silverfish[es])|26¦[enderman] pick[[ ]up] block[s]|27¦[enderman] place block[s]|28¦[enderman] attack player (staring|looking) at [their] eye[s]]|29¦ghast move to[wards] target|30¦ghast (idle move[ment]|wander|random fl(ight|y[ing]))|31¦(tempt to|follow players (holding|with)) %-itemstack%[, [move[ment]] speed %number%[, scared of player movement %-boolean%]]|32¦target [random] %*entitydatas% (if|when) (not |un)tamed|33¦guardian attack [entities]|34¦[z[ombie[ ]]pig[man]] attack [player[s]] (if|when) angry|35¦[z[ombie[ ]]pig[man]] (react to|fight back|target) (attacker|damager) (if|when) angry|36¦[rabbit] eat carrot crops|37¦[killer] rabbit [melee] attack|38¦slime [random] jump|39¦slime change (direction|facing) randomly|40¦slime (idle move[ment]|wander)|41¦follow %*entitydatas%[, radius %-number%[, speed %-number%[, [custom[ ]]name[d] %-string%]]]|42¦bow shoot[, [move[ment]] speed %-number%[, unk[nown] param[eter] %-number%[, follow range %-number%]]])) to %livingentities%");
|
||||
Skript.registerEffect(EffMakeJump.class, "make %livingentities% jump", "force %livingentities% to jump");
|
||||
Skript.registerEffect(EffGZipFile.class, "create [a] gzip[ped] file [at] [path] %string%");
|
||||
Skript.registerExpression(ExprNBTOf.class, Object.class, ExpressionType.PROPERTY, "nbt[[ ]tag[s]] of %~object%", "%~object%'s nbt[[ ]tag[s]]");
|
||||
Skript.registerExpression(ExprItemNBT.class, ItemStack.class, ExpressionType.SIMPLE, "%itemstack% with [custom] nbt[[ ]tag[s]] %string%");
|
||||
Skript.registerExpression(ExprTagOf.class, Object.class, ExpressionType.PROPERTY, "[nbt[ ]]tag %string% of [[nbt] compound] %compound%");
|
||||
Skript.registerExpression(ExprFileNBT.class, Object.class, ExpressionType.PROPERTY, "nbt[[ ]tag[s]] from [file] %string%");
|
||||
Skript.registerExpression(ExprNBTListIndex.class, Object.class, ExpressionType.PROPERTY, "[nbt[ ]list] %nbtlist% index %number%");
|
||||
Skript.registerExpression(ExprNBTListContents.class, Object.class, ExpressionType.PROPERTY, "[all] contents (of|from) [nbt[ ]list] %nbtlist%", "[nbt[ ]list] %nbtlist% contents");
|
||||
Skript.registerExpression(ExprNoClip.class, Boolean.class, ExpressionType.PROPERTY, "no[( |-)]clip (state|mode) of %entities%", "%entities%'s no[( |-)]clip (state|mode)");
|
||||
Skript.registerExpression(ExprFireProof.class, Boolean.class, ExpressionType.PROPERTY, "fire[ ]proof (state|mode) of %entities%", "%entities%'s fire[ ]proof (state|mode)");
|
||||
//Skript.registerExpression(ExprEndermanBlocks.class, ItemStack.class, ExpressionType.PROPERTY, "blocks that %entity% can (carry|hold|grab|steal)");
|
||||
Skript.registerExpression(ExprMCIdOf.class, String.class, ExpressionType.PROPERTY, "(mc|minecraft) [(string|native)] id of %itemtype%", "%itemtype%'s minecraft [(string|native)] id");
|
||||
Skript.registerExpression(ExprMCIdToItem.class, ItemStack.class, ExpressionType.SIMPLE, "item[[ ](stack|type)] (of|from) (mc|minecraft) [(string|native)] id %string%");
|
||||
Skript.registerExpression(ExprLastLocation.class, Location.class, ExpressionType.SIMPLE, "[the] (last|past|former) location of %entity%", "%entity%'s (last|past|former) location", "[the] location of %entity% (1|one) tick before", "%entity%'s location (1|one) tick before");
|
||||
Skript.registerExpression(ExprStepLength.class, Number.class, ExpressionType.PROPERTY, "[the] step length of %entity%", "%entity%'s step length");
|
||||
nmsMethods.registerCompoundClassInfo();
|
||||
nmsMethods.registerNBTListClassInfo();
|
||||
|
||||
effAmount += 5;
|
||||
exprAmount += 12;
|
||||
// 13 with the ender blocks expression
|
||||
typeAmount += 2;
|
||||
}
|
||||
if (Bukkit.getPluginManager().getPlugin("WorldEdit") != null) {
|
||||
getLogger().info("WorldEdit found! Registering WorldEdit stuff...");
|
||||
Skript.registerCondition(CondSelectionContains.class, "[(world[ ]edit|we)] selection of %player% (contains|has) %location%", "%player%'s [(world[ ]edit|we)] selection (contains|has) %location%", "[(world[ ]edit|we)] selection of %player% does(n't| not) (contain|have) %location%", "%player%'s [(world[ ]edit|we)] selection does(n't| not) (contain|have) %location%");
|
||||
Skript.registerEffect(EffDrawLineWE.class, "(create|draw|make) [a[n]] (0¦(no(n|t)(-| )hollow|filled|)|1¦hollow) line from %location% to %location% (using|with) [edit[ ]session] %editsession% (using|with) [block[s]] %itemstacks% [with] thick[ness] %double%");
|
||||
Skript.registerEffect(EffUndoRedoSession.class, "(0¦undo|1¦redo) (change|edit)s (of|from) [edit[ ]session] %editsession%");
|
||||
Skript.registerEffect(EffRememberChanges.class, "make %player% (remember|be able to undo) changes (of|from) [edit[ ]session] %editsession%");
|
||||
Skript.registerEffect(EffMakeSphere.class, "(create|make) [a[n]] (0¦(no(n|t)(-| )hollow|filled|)|1¦hollow) (ellipsoid|sphere) [centered] at %location% [with] radius [of] %double%,[ ]%double%(,[ ]| and )%double% (using|with) [edit[ ]session] %editsession% (using|with) [block[s]] %itemstacks%");
|
||||
Skript.registerEffect(EffSimulateSnow.class, "(simulate snow at|place snow over) %location% (in|within) [a] radius [of] %double% (using|with) [edit[ ]session] %editsession%", "make %location% snowy (in|within) [a] radius [of] %double% (using|with) [edit[ ]session] %editsession%");
|
||||
Skript.registerEffect(EffMakePyramid.class, "(create|make) [a[n]] (0¦(no(n|t)(-| )hollow|filled|)|1¦hollow) pyramid at %location% [with] radius [of] %integer% (using|with) [edit[ ]session] %editsession% (using|with) [block[s]] %itemstacks%");
|
||||
Skript.registerEffect(EffDrainLiquid.class, "(drain|remove) [all] liquid[s] at %location% (in|within) [a] radius [of] %double% (using|with) [edit[ ]session] %editsession%");
|
||||
Skript.registerEffect(EffNaturalize.class, "naturalize ([cuboid] region|[all] blocks) (from|between) %location% (to|and) %location% (using|with) [edit[ ]session] %editsession%");
|
||||
Skript.registerEffect(EffMakeWalls.class, "(create|make) wall[s] from %location% to %location% (using|with) [edit[ ]session] %editsession% (using|with) [block[s]] %itemstacks%");
|
||||
Skript.registerEffect(EffSetBlocksWE.class, "set [all] blocks (from|between) %location% (to|and) %location% to %itemstacks% (using|with) [edit[ ]session] %editsession%");
|
||||
Skript.registerEffect(EffMakeCylinder.class, "(create|make) [a[n]] (0¦(no(n|t)(-| )hollow|filled|)|1¦hollow) cylinder at %location% [with] radius [of] %double%,[ ]%integer%(,[ ]| and )%double% (using|with) [edit[ ]session] %editsession% (using|with) [block[s]] %itemstacks%");
|
||||
Skript.registerEffect(EffReplaceBlocksWE.class, "replace [all] %itemstacks% (from|between) %location% (to|and) %location% with %itemstacks% (using|with) [edit[ ]session] %editsession%");
|
||||
Skript.registerEffect(EffPasteSchematic.class, "paste schem[atic] %string% at %location% using [edit[ ]session] %editsession% (0¦|1¦(ignor(e|ing)|without|[with] no) air)");
|
||||
Skript.registerExpression(ExprEditSessionLimit.class, Integer.class, ExpressionType.PROPERTY, "[block] limit [change] of [edit[ ]session] %editsession%");
|
||||
Skript.registerExpression(ExprChangedBlocksSession.class, Integer.class, ExpressionType.PROPERTY, "number of [all] changed blocks (in|of) [edit[ ]session] %editsession%");
|
||||
Skript.registerExpression(ExprNewEditSession.class, EditSession.class, ExpressionType.PROPERTY, "[new] edit[ ]session in [world] %world% [with] [max[imum]] [block] limit [change] [of] %integer%");
|
||||
Skript.registerExpression(ExprSelectionOfPlayer.class, Location.class, ExpressionType.PROPERTY, "[(world[ ]edit|we)] selection of %player%", "%player%'s [(world[ ]edit|we)] selection");
|
||||
Skript.registerExpression(ExprSelectionPos.class, Location.class, ExpressionType.PROPERTY, "[(world[ ]edit|we)] po(s|int)[ ](0¦1|1¦2) of %player%", "%player%'s [(world[ ]edit|we)] po(s|int)[ ](0¦1|1¦2)");
|
||||
Skript.registerExpression(ExprSelectionArea.class, Integer.class, ExpressionType.SIMPLE, "(0¦volume|1¦(x( |-)size|width)|2¦(y( |-)size|height)|3¦(z( |-)size|length)|4¦area) of [(world[ ]edit|we)] selection of %player%", "%player%'s [(world[ ]edit|we)] selection (0¦volume|1¦(x( |-)size|width)|2¦(y( |-)size|height)|3¦(z( |-)size|length)|4¦area)");
|
||||
Skript.registerExpression(ExprSchematicArea.class, Integer.class, ExpressionType.SIMPLE, "(0¦volume|1¦(x( |-)size|width)|2¦(y( |-)size|height)|3¦(z( |-)size|length)|4¦area) of schem[atic] [from] %string%");
|
||||
Skript.registerExpression(ExprSuperPickaxe.class, Boolean.class, ExpressionType.PROPERTY, "[(world[ ]edit|we)] super[ ]pick[axe] (state|mode) of %players%", "%players%'s [(world[ ]edit|we)] super[ ]pick[axe] (state|mode)");
|
||||
Classes.registerClass(new ClassInfo<EditSession>(EditSession.class, "editsession").name("Edit Session").user("edit ?sessions?"));
|
||||
try {
|
||||
Class.forName("com.sk89q.worldedit.extent.logging.AbstractLoggingExtent");
|
||||
new WorldEditChangeHandler();
|
||||
Skript.registerEvent("WorldEdit block change", SimpleEvent.class, EvtWorldEditChange.class, "world[ ]edit [block] (chang(e|ing)|edit[ing])");
|
||||
EventValues.registerEventValue(EvtWorldEditChange.class, Player.class, new Getter<Player, EvtWorldEditChange>() {
|
||||
@Override
|
||||
@Nullable
|
||||
public Player get(EvtWorldEditChange e) {
|
||||
return EvtWorldEditChange.getPlayer();
|
||||
}
|
||||
}, 0);
|
||||
EventValues.registerEventValue(EvtWorldEditChange.class, Block.class, new Getter<Block, EvtWorldEditChange>() {
|
||||
@Override
|
||||
@Nullable
|
||||
public Block get(EvtWorldEditChange e) {
|
||||
return EvtWorldEditChange.getBlock();
|
||||
}
|
||||
}, 0);
|
||||
evtAmount += 1;
|
||||
} catch (ClassNotFoundException ex) {
|
||||
Skript.error("Unable to register \"On WorldEdit block change\" event! You will need to upgrade to WorldEdit 6.x if you want to use it!");
|
||||
}
|
||||
condAmount += 1;
|
||||
effAmount += 13;
|
||||
exprAmount += 8;
|
||||
typeAmount += 1;
|
||||
final Plugin worldGuard = Bukkit.getPluginManager().getPlugin("WorldGuard");
|
||||
if (worldGuard != null) { //WorldGuard depends on WorldEdit
|
||||
getLogger().info("WorldGuard found! Registering WorldGuard stuff...");
|
||||
Plugin umbaska = Bukkit.getPluginManager().getPlugin("Umbaska");
|
||||
Plugin skRambled = Bukkit.getPluginManager().getPlugin("SkRambled");
|
||||
boolean registerNewTypes = (umbaska == null && skRambled == null);
|
||||
if (registerNewTypes) {
|
||||
Skript.registerExpression(ExprFlagOfWGRegion.class, String.class, ExpressionType.PROPERTY, "[(world[ ]guard|wg)] flag %wgflag% of %wgregion%");
|
||||
Skript.registerExpression(ExprFlagsOfWGRegion.class, Flag.class, ExpressionType.PROPERTY, "[(all|the)] [(world[ ]guard|wg)] flags of %wgregion%");
|
||||
Skript.registerExpression(ExprWGMemberOwner.class, OfflinePlayer.class, ExpressionType.PROPERTY, "[the] (0¦members|1¦owner[s]) of [[the] (world[ ]guard|wg) region] %wgregion%");
|
||||
Classes.registerClass(new ClassInfo<Flag>(Flag.class, "wgflag").name("WorldGuard Flag").user("((world ?guard|wg) )?flags?").defaultExpression(new EventValueExpression<Flag>(Flag.class)).parser(new Parser<Flag<?>>() {
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public Flag<?> parse(String flag, ParseContext context) {
|
||||
FlagRegistry flagRegistry = ((WorldGuardPlugin) worldGuard).getFlagRegistry();
|
||||
return DefaultFlag.fuzzyMatchFlag(flagRegistry, flag);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString(Flag<?> flag, int flags) {
|
||||
return flag.getName().toLowerCase();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toVariableNameString(Flag<?> flag) {
|
||||
return flag.getName().toLowerCase();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getVariableNamePattern() {
|
||||
return ".+";
|
||||
}
|
||||
}));
|
||||
Classes.registerClass(new ClassInfo<ProtectedRegion>(ProtectedRegion.class, "wgregion").name("WorldGuard Region").user("((world ?guard|wg) )?regions?").defaultExpression(new EventValueExpression<>(ProtectedRegion.class)).parser(new Parser<ProtectedRegion>() {
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public ProtectedRegion parse(String region, ParseContext context) {
|
||||
for (World w : Bukkit.getWorlds()) {
|
||||
if (WGBukkit.getRegionManager(w).hasRegion(region)) {
|
||||
return WGBukkit.getRegionManager(w).getRegion(region);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString(ProtectedRegion region, int flags) {
|
||||
return region.getId();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toVariableNameString(ProtectedRegion region) {
|
||||
return region.getId();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getVariableNamePattern() {
|
||||
return ".+";
|
||||
}
|
||||
|
||||
}));
|
||||
typeAmount += 2;
|
||||
} else {
|
||||
Skript.registerExpression(ExprFlagOfWGRegion.class, String.class, ExpressionType.PROPERTY, "[skstuff] [w[orld[ ]]g[uard]] flag %flag% of %protectedregion%");
|
||||
Skript.registerExpression(ExprFlagsOfWGRegion.class, Flag.class, ExpressionType.PROPERTY, "[skstuff] [all] [w[orld[ ]]g[uard]] flags of %protectedregion%");
|
||||
Skript.registerExpression(ExprWGMemberOwner.class, OfflinePlayer.class, ExpressionType.PROPERTY, "[the] [skstuff] (0¦members|1¦owner[s]) of [[the] (world[ ]guard|wg) region] %protectedregion%");
|
||||
}
|
||||
Skript.registerExpression(ExprRegionsWithinLocation.class, ProtectedRegion.class, ExpressionType.SIMPLE, "[all] [the] regions (containing|within|inside) %location%");
|
||||
exprAmount += 4;
|
||||
|
||||
if (!Skript.classExists("com.sk89q.protection.flags.registry.FlagRegistry")) {
|
||||
getLogger().warning("Detected old unsupported version of WorldGuard, please update to WorldGuard 6.2. Flags will not fully work with your current version!!");
|
||||
}
|
||||
}
|
||||
}
|
||||
if (Bukkit.getPluginManager().getPlugin("VanishNoPacket") != null) {
|
||||
getLogger().info("VanishNoPacket was found! Registering vanishing features...");
|
||||
Skript.registerEffect(EffToggleVanish.class, "toggle vanish (state|mode) of %player% (0¦|1¦(silently|quietly))", "toggle %player%'s vanish (state|mode) (0¦|1¦(silently|quietly))");
|
||||
Skript.registerEvent("Vanish toggle event", SimpleEvent.class, VanishStatusChangeEvent.class, "[player] vanish [(state|mode)] (chang|toggl)(e|ing)");
|
||||
Skript.registerExpression(ExprVanishState.class, Boolean.class, ExpressionType.PROPERTY, "vanish (state|mode) of %player%", "%player%'s vanish (state|mode)");
|
||||
EventValues.registerEventValue(VanishStatusChangeEvent.class, Player.class, new Getter<Player, VanishStatusChangeEvent>() {
|
||||
@Override
|
||||
@Nullable
|
||||
public Player get(VanishStatusChangeEvent e) {
|
||||
return e.getPlayer();
|
||||
}
|
||||
}, 0);
|
||||
effAmount += 1;
|
||||
evtAmount += 1;
|
||||
exprAmount += 1;
|
||||
}
|
||||
try {
|
||||
Metrics metrics = new Metrics(this);
|
||||
metrics.start();
|
||||
@ -330,27 +125,13 @@ public class SkStuff extends JavaPlugin {
|
||||
|
||||
private boolean setupNMSVersion() {
|
||||
String version = ReflectionUtils.getVersion();
|
||||
if (version.equals("v1_7_R4.")) {
|
||||
nmsMethods = new NMS_v1_7_R4();
|
||||
getLogger().info("It looks like you're running 1.7.10!");
|
||||
} else if (version.equals("v1_8_R3.")) {
|
||||
nmsMethods = new NMS_v1_8_R3();
|
||||
getLogger().info("It looks like you're either running 1.8.4, 1.8.7, 1.8.8 or 1.8.9!");
|
||||
} else if (version.equals("v1_9_R1.")) {
|
||||
nmsMethods = new NMS_v1_9_R1();
|
||||
getLogger().info("It looks like you're either running 1.9.0 or 1.9.2!");
|
||||
} else if (version.equals("v1_9_R2.")) {
|
||||
nmsMethods = new NMS_v1_9_R2();
|
||||
getLogger().info("It looks like you're running 1.9.4!");
|
||||
} else if (version.equals("v1_10_R1.")) {
|
||||
nmsMethods = new NMS_v1_10_R1();
|
||||
getLogger().info("It looks like you're running 1.10!");
|
||||
} else if (version.equals("v1_11_R1.")) {
|
||||
nmsMethods = new NMS_v1_11_R1();
|
||||
getLogger().info("It looks like you're running 1.11!");
|
||||
} else if (version.equals("v1_12_R1.")) {
|
||||
nmsMethods = new NMS_v1_12_R1();
|
||||
getServer().getConsoleSender().sendMessage("§c[SkStuff] You are running an unofficial fork of SkStuff, by Tuke_Nuke. Some nbt stuffs may not work properly!");
|
||||
|
||||
if (version.equals("v1_13_R2.")) {
|
||||
nmsMethods = new NMS_v1_13_R2();
|
||||
getLogger().info("It looks like you're running 1.13.2!");
|
||||
} else if (version.equals("v1_14_R1.")) {
|
||||
nmsMethods = new NMS_v1_14_R1();
|
||||
getLogger().info("It looks like you're running 1.14.2!");
|
||||
} else {
|
||||
getLogger().warning("It looks like you're running an unsupported server version, some features will not be available :(");
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
@ -20,9 +20,9 @@ import ch.njol.skript.lang.Expression;
|
||||
import ch.njol.skript.lang.SkriptParser.ParseResult;
|
||||
import ch.njol.util.Kleenean;
|
||||
import me.TheBukor.SkStuff.SkStuff;
|
||||
import me.TheBukor.SkStuff.pathfinders.PathfinderGoalFollow_v1_8_R3;
|
||||
import me.TheBukor.SkStuff.pathfinders.PathfinderGoalFollow_v1_9_R1;
|
||||
import me.TheBukor.SkStuff.util.ReflectionUtils;
|
||||
import me.TheBukor.SkStuff.pathfinders.PathfinderGoalFollow_v1_13_R2;
|
||||
import me.TheBukor.SkStuff.pathfinders.PathfinderGoalFollow_v1_14_R1;
|
||||
|
||||
public class EffRemovePathGoal extends Effect {
|
||||
private Expression<LivingEntity> entities;
|
||||
@ -178,10 +178,10 @@ public class EffRemovePathGoal extends Effect {
|
||||
toRemove = ReflectionUtils.getNMSClass("EntitySlime$PathfinderGoalSlimeIdle");
|
||||
} else if (mark == 41) {
|
||||
String version = ReflectionUtils.getVersion();
|
||||
if (version.equals("v1_8_R3.")) {
|
||||
toRemove = PathfinderGoalFollow_v1_8_R3.class;
|
||||
} else if (version.equals("v1_9_R1.")) {
|
||||
toRemove = PathfinderGoalFollow_v1_9_R1.class;
|
||||
if (version.equals("v1_13_R2.")) {
|
||||
toRemove = PathfinderGoalFollow_v1_13_R2.class;
|
||||
} else if (version.equals("v1_14_R1.")) {
|
||||
toRemove = PathfinderGoalFollow_v1_14_R1.class;
|
||||
}
|
||||
} else if (mark == 42) {
|
||||
if (Skript.isRunningMinecraft(1, 9)) {
|
||||
|
@ -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();
|
||||
}
|
||||
}
|
||||
}
|
@ -40,12 +40,12 @@ import ch.njol.skript.lang.SkriptParser.ParseResult;
|
||||
import ch.njol.skript.util.Timespan;
|
||||
import ch.njol.util.Kleenean;
|
||||
import me.TheBukor.SkStuff.SkStuff;
|
||||
import me.TheBukor.SkStuff.pathfinders.PathfinderGoalFollow_v1_8_R3;
|
||||
import me.TheBukor.SkStuff.pathfinders.PathfinderGoalFollow_v1_9_R1;
|
||||
import me.TheBukor.SkStuff.pathfinders.PathfinderGoalFollow_v1_13_R2;
|
||||
import me.TheBukor.SkStuff.pathfinders.PathfinderGoalFollow_v1_14_R1;
|
||||
import me.TheBukor.SkStuff.util.ReflectionUtils;
|
||||
import net.minecraft.server.v1_8_R3.EntityCreature;
|
||||
|
||||
public class EffSetPathGoal extends Effect {
|
||||
public final class EffSetPathGoal extends Effect {
|
||||
private Expression<Integer> goalPriority;
|
||||
private Expression<? extends EntityData<?>> typeToAvoid;
|
||||
private Expression<Number> avoidRadius;
|
||||
@ -98,7 +98,7 @@ public class EffSetPathGoal extends Effect {
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public boolean init(Expression<?>[] expr, int matchedPattern, Kleenean arg2, ParseResult result) {
|
||||
public final boolean init(Expression<?>[] expr, int matchedPattern, Kleenean arg2, ParseResult result) {
|
||||
goalPriority = (Expression<Integer>) expr[0];
|
||||
mark = result.mark;
|
||||
if (mark == 0) {
|
||||
@ -539,10 +539,10 @@ public class EffSetPathGoal extends Effect {
|
||||
className = "Living";
|
||||
}
|
||||
Class<?> nmsClass = ReflectionUtils.getNMSClass("Entity" + className);
|
||||
if (version.equals("v1_8_R3.")) {
|
||||
newGoals.add(new PathfinderGoalFollow_v1_8_R3((EntityCreature) nmsEnt, nmsClass, radius, spd, usesName, customName));
|
||||
} else if (version.equals("v1_9_R1.")) {
|
||||
newGoals.add(new PathfinderGoalFollow_v1_9_R1((net.minecraft.server.v1_9_R1.EntityCreature) nmsEnt, nmsClass, radius, spd, usesName, customName));
|
||||
if (version.equals("v1_13_R2.")) {
|
||||
newGoals.add(new PathfinderGoalFollow_v1_13_R2((net.minecraft.server.v1_13_R2.EntityCreature) nmsEnt, nmsClass, radius, spd, usesName, customName));
|
||||
} else if (version.equals("v1_14_R1.")) {
|
||||
newGoals.add(new PathfinderGoalFollow_v1_14_R1((net.minecraft.server.v1_14_R1.EntityCreature) nmsEnt, nmsClass, radius, spd, usesName, customName));
|
||||
}
|
||||
}
|
||||
} else if (mark == 42) {
|
||||
|
@ -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,76 +0,0 @@
|
||||
package me.TheBukor.SkStuff.expressions;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.event.Event;
|
||||
|
||||
import com.sk89q.worldedit.EditSession;
|
||||
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 ExprEditSessionLimit extends SimpleExpression<Integer> {
|
||||
private Expression<EditSession> editSession;
|
||||
private WorldEditPlugin we = (WorldEditPlugin) Bukkit.getServer().getPluginManager().getPlugin("WorldEdit");
|
||||
|
||||
|
||||
@Override
|
||||
public Class<? extends Integer> getReturnType() {
|
||||
return Integer.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSingle() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public boolean init(Expression<?>[] expr, int matchedPattern, Kleenean arg2, ParseResult arg3) {
|
||||
editSession = (Expression<EditSession>) expr[0];
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString(@Nullable Event e, boolean debug) {
|
||||
return "the block change limit of an edit session";
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
protected Integer[] get(Event e) {
|
||||
EditSession session = editSession.getSingle(e);
|
||||
if (session == null)
|
||||
return null;
|
||||
return new Integer[] { session.getBlockChangeLimit() };
|
||||
}
|
||||
|
||||
@Override
|
||||
public void change(Event e, @Nullable Object[] delta, ChangeMode mode) {
|
||||
EditSession session = editSession.getSingle(e);
|
||||
if (session == null)
|
||||
return;
|
||||
if (mode == ChangeMode.SET) {
|
||||
Integer newLimit = (Integer) delta[0];
|
||||
session.setBlockChangeLimit(Integer.valueOf(newLimit));
|
||||
} else if (mode == ChangeMode.RESET) {
|
||||
session.setBlockChangeLimit(Integer.valueOf(we.getLocalConfiguration().defaultChangeLimit));
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
@Nullable
|
||||
public Class<?>[] acceptChange(ChangeMode mode) {
|
||||
if (mode == ChangeMode.SET || mode == ChangeMode.RESET || mode == ChangeMode.DELETE) {
|
||||
return CollectionUtils.array(Integer.class);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
@ -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,13 +1,13 @@
|
||||
package me.TheBukor.SkStuff.pathfinders;
|
||||
|
||||
import net.minecraft.server.v1_13_R2.Entity;
|
||||
import net.minecraft.server.v1_13_R2.EntityCreature;
|
||||
import net.minecraft.server.v1_13_R2.EntityLiving;
|
||||
import net.minecraft.server.v1_13_R2.PathfinderGoal;
|
||||
|
||||
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 {
|
||||
public class PathfinderGoalFollow_v1_13_R2 extends PathfinderGoal {
|
||||
private EntityCreature follower;
|
||||
private EntityLiving followed;
|
||||
private Class<?> followedClass;
|
||||
@ -16,7 +16,7 @@ public class PathfinderGoalFollow_v1_9_R1 extends PathfinderGoal {
|
||||
private boolean isByName;
|
||||
private String customName;
|
||||
|
||||
public PathfinderGoalFollow_v1_9_R1(EntityCreature follower, Class<?> followedClass, float radius, double speed, boolean isByName, String customName) {
|
||||
public PathfinderGoalFollow_v1_13_R2(EntityCreature follower, Class<?> followedClass, float radius, double speed, boolean isByName, String customName) {
|
||||
this.follower = follower;
|
||||
this.followedClass = followedClass;
|
||||
this.radius = radius;
|
||||
@ -64,14 +64,16 @@ public class PathfinderGoalFollow_v1_9_R1 extends PathfinderGoal {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return follower.getNavigation().n(); // n() means hasNoPath()
|
||||
//return follower.getNavigation().n(); // n() means hasNoPath()
|
||||
return true;
|
||||
// n() is now protected void and I'm not sure how to access it, so I'm just returning a boolean, this probably will cause some issues with this pathfinder goal, if you know a better solution, let me know. - Govindas.
|
||||
}
|
||||
|
||||
// c() is execute()
|
||||
@Override
|
||||
public void c() {
|
||||
follower.getNavigation().a(followed, speed); // a() means moveTo()
|
||||
}
|
||||
// c() is execute()
|
||||
@Override
|
||||
public void c () {
|
||||
follower.getNavigation().a(followed, speed); // a() means moveTo()
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -1,13 +1,13 @@
|
||||
package me.TheBukor.SkStuff.pathfinders;
|
||||
|
||||
import net.minecraft.server.v1_14_R1.Entity;
|
||||
import net.minecraft.server.v1_14_R1.EntityCreature;
|
||||
import net.minecraft.server.v1_14_R1.EntityLiving;
|
||||
import net.minecraft.server.v1_14_R1.PathfinderGoal;
|
||||
|
||||
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 {
|
||||
public class PathfinderGoalFollow_v1_14_R1 extends PathfinderGoal {
|
||||
private EntityCreature follower;
|
||||
private EntityLiving followed;
|
||||
private Class<?> followedClass;
|
||||
@ -16,7 +16,7 @@ public class PathfinderGoalFollow_v1_8_R3 extends PathfinderGoal {
|
||||
private boolean isByName;
|
||||
private String customName;
|
||||
|
||||
public PathfinderGoalFollow_v1_8_R3(EntityCreature follower, Class<?> followedClass, float radius, double speed, boolean isByName, String customName) {
|
||||
public PathfinderGoalFollow_v1_14_R1(EntityCreature follower, Class<?> followedClass, float radius, double speed, boolean isByName, String customName) {
|
||||
this.follower = follower;
|
||||
this.followedClass = followedClass;
|
||||
this.radius = radius;
|
||||
@ -64,12 +64,16 @@ public class PathfinderGoalFollow_v1_8_R3 extends PathfinderGoal {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return follower.getNavigation().m(); // m() means hasNoPath()
|
||||
//return follower.getNavigation().n(); // n() means hasNoPath()
|
||||
return true;
|
||||
// n() is now protected void and I'm not sure how to access it, so I'm just returning a boolean, this probably will cause some issues with this pathfinder goal, if you know a better solution, let me know. - Govindas.
|
||||
}
|
||||
|
||||
// c() is execute()
|
||||
@Override
|
||||
public void c() {
|
||||
follower.getNavigation().a(followed, speed); // a() means moveTo()
|
||||
// c() is execute()
|
||||
@Override
|
||||
public void c () {
|
||||
follower.getNavigation().a(followed, speed); // a() means moveTo()
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
@ -2,6 +2,7 @@ package me.TheBukor.SkStuff.util;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import net.minecraft.server.v1_13_R2.EntityTypes;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.entity.Entity;
|
||||
@ -9,31 +10,10 @@ import org.bukkit.inventory.ItemStack;
|
||||
|
||||
public interface NMSInterface {
|
||||
|
||||
public Object getNBTTag(Object compound, String tag);
|
||||
|
||||
public void setNBTTag(Object compound, String tag, Object toSet);
|
||||
|
||||
public void removeNBTTag(Object compound, String tag);
|
||||
|
||||
public byte getTypeId(Object nbtBase);
|
||||
|
||||
public Object getNBTTagValue(Object compound, String tag, byte typeId);
|
||||
|
||||
public void addToCompound(Object compound, Object toAdd);
|
||||
|
||||
public void removeFromCompound(Object compound, String ... toRemove);
|
||||
|
||||
public Object parseRawNBT(String rawNBT);
|
||||
|
||||
public Object[] getContents(Object nbtList);
|
||||
|
||||
public void addToList(Object nbtList, Object toAdd);
|
||||
|
||||
public void removeFromList(Object nbtList, int index);
|
||||
|
||||
public void setIndex(Object nbtList, int index, Object toSet);
|
||||
|
||||
public Object getIndex(Object nbtList, int index);
|
||||
|
||||
public void clearPathfinderGoals(Entity entity);
|
||||
|
||||
@ -41,34 +21,6 @@ public interface NMSInterface {
|
||||
|
||||
public void addPathfinderGoal(Object entity, int priority, Object goal, boolean isTargetSelector);
|
||||
|
||||
public void registerCompoundClassInfo();
|
||||
|
||||
public void registerNBTListClassInfo();
|
||||
|
||||
public Object getEntityNBT(Entity entity);
|
||||
|
||||
public Object getTileNBT(Block block);
|
||||
|
||||
public Object getItemNBT(ItemStack itemStack);
|
||||
|
||||
public void setEntityNBT(Entity entity, Object newCompound);
|
||||
|
||||
public void setTileNBT(Block block, Object newCompound);
|
||||
|
||||
public ItemStack getItemWithNBT(ItemStack itemStack, Object compound);
|
||||
|
||||
public Object getFileNBT(File file);
|
||||
|
||||
public void setFileNBT(File file, Object newCompound);
|
||||
|
||||
public Object convertToNBT(Number number);
|
||||
|
||||
public Object convertToNBT(String string);
|
||||
|
||||
public String getMCId(ItemStack itemStack);
|
||||
|
||||
public ItemStack getItemFromMcId(String mcId);
|
||||
|
||||
public boolean getNoClip(Entity entity);
|
||||
|
||||
public void setNoClip(Entity entity, boolean noclip);
|
||||
@ -77,17 +29,8 @@ public interface NMSInterface {
|
||||
|
||||
public void setFireProof(Entity entity, boolean fireProof);
|
||||
|
||||
/*
|
||||
public ItemStack[] getEndermanBlocks(Entity enderman);
|
||||
|
||||
public void setEndermanBlocks(Entity enderman, ItemStack... blocks);
|
||||
*/
|
||||
|
||||
public Location getLastLocation(Entity entity);
|
||||
|
||||
public float getEntityStepLength(Entity entity);
|
||||
|
||||
public void setEntityStepLength(Entity entity, float length);
|
||||
|
||||
public boolean getElytraGlideState(Entity entity);
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
115
src/me/TheBukor/SkStuff/util/NMS_v1_13_R2.java
Normal file
115
src/me/TheBukor/SkStuff/util/NMS_v1_13_R2.java
Normal file
@ -0,0 +1,115 @@
|
||||
package me.TheBukor.SkStuff.util;
|
||||
|
||||
|
||||
|
||||
import net.minecraft.server.v1_13_R2.*;
|
||||
import org.bukkit.Location;
|
||||
|
||||
import org.bukkit.craftbukkit.v1_13_R2.entity.CraftEntity;
|
||||
import org.bukkit.craftbukkit.v1_13_R2.entity.CraftLivingEntity;
|
||||
|
||||
import org.bukkit.entity.Entity;
|
||||
|
||||
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedHashSet;
|
||||
|
||||
public class NMS_v1_13_R2 implements NMSInterface {
|
||||
|
||||
|
||||
|
||||
@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 boolean getNoClip(Entity entity) {
|
||||
net.minecraft.server.v1_13_R2.Entity nmsEntity = ((CraftEntity) entity).getHandle();
|
||||
return nmsEntity.noclip;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setNoClip(Entity entity, boolean noclip) {
|
||||
net.minecraft.server.v1_13_R2.Entity nmsEntity = ((CraftEntity) entity).getHandle();
|
||||
nmsEntity.noclip = noclip;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean getFireProof(Entity entity) {
|
||||
net.minecraft.server.v1_13_R2.Entity nmsEntity = ((CraftEntity) entity).getHandle();
|
||||
return nmsEntity.isFireProof();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setFireProof(Entity entity, boolean fireProof) {
|
||||
net.minecraft.server.v1_13_R2.Entity nmsEntity = ((CraftEntity) entity).getHandle();
|
||||
ReflectionUtils.setField("fireProof", nmsEntity.getClass(), nmsEntity, fireProof);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@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_13_R2.Entity nmsEntity = ((CraftEntity) entity).getHandle();
|
||||
return nmsEntity.isNoGravity();
|
||||
}
|
||||
|
||||
public void setNoGravity(Entity entity, boolean noGravity) {
|
||||
net.minecraft.server.v1_13_R2.Entity nmsEntity = ((CraftEntity) entity).getHandle();
|
||||
nmsEntity.setNoGravity(noGravity);
|
||||
}
|
||||
}
|
112
src/me/TheBukor/SkStuff/util/NMS_v1_14_R1.java
Normal file
112
src/me/TheBukor/SkStuff/util/NMS_v1_14_R1.java
Normal file
@ -0,0 +1,112 @@
|
||||
package me.TheBukor.SkStuff.util;
|
||||
|
||||
|
||||
import net.minecraft.server.v1_14_R1.EntityInsentient;
|
||||
import net.minecraft.server.v1_14_R1.EntityLiving;
|
||||
import net.minecraft.server.v1_14_R1.PathfinderGoal;
|
||||
import net.minecraft.server.v1_14_R1.PathfinderGoalSelector;
|
||||
import org.bukkit.craftbukkit.v1_14_R1.entity.CraftEntity;
|
||||
import org.bukkit.craftbukkit.v1_14_R1.entity.CraftLivingEntity;
|
||||
import org.bukkit.entity.Entity;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedHashSet;
|
||||
|
||||
public class NMS_v1_14_R1 implements NMSInterface {
|
||||
|
||||
|
||||
|
||||
@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 boolean getNoClip(Entity entity) {
|
||||
net.minecraft.server.v1_14_R1.Entity nmsEntity = ((CraftEntity) entity).getHandle();
|
||||
return nmsEntity.noclip;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setNoClip(Entity entity, boolean noclip) {
|
||||
net.minecraft.server.v1_14_R1.Entity nmsEntity = ((CraftEntity) entity).getHandle();
|
||||
nmsEntity.noclip = noclip;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean getFireProof(Entity entity) {
|
||||
net.minecraft.server.v1_14_R1.Entity nmsEntity = ((CraftEntity) entity).getHandle();
|
||||
return nmsEntity.isFireProof();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setFireProof(Entity entity, boolean fireProof) {
|
||||
net.minecraft.server.v1_14_R1.Entity nmsEntity = ((CraftEntity) entity).getHandle();
|
||||
ReflectionUtils.setField("fireProof", nmsEntity.getClass(), nmsEntity, fireProof);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@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_14_R1.Entity nmsEntity = ((CraftEntity) entity).getHandle();
|
||||
return nmsEntity.isNoGravity();
|
||||
}
|
||||
|
||||
public void setNoGravity(Entity entity, boolean noGravity) {
|
||||
net.minecraft.server.v1_14_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