Compare commits

...

26 Commits
master ... 2.1

Author SHA1 Message Date
Govindass
450c38e87e Merge branch 'master' of https://github.com/Govindass/SkStuff 2020-07-28 11:33:18 +03:00
Govindass
4a451c0ae2 remove old 1.9.2 2020-07-28 11:33:14 +03:00
Govindas
4eeb792318
Update README.md 2020-07-21 15:23:27 +03:00
Govindass
af60b96e4a Add 1.16 support & Add more syntaxes & Add 1.8-1.12 support back & Remove some syntaxes that are already in vanilla Skript 2020-07-21 15:16:57 +03:00
Govindas
f279742068
Update README.md 2020-01-13 14:49:34 +02:00
Govindas
10a25abe5b
Update README.md 2020-01-13 14:49:16 +02:00
Govindas
0ca413c58f
Update .gitignore 2020-01-13 13:11:45 +02:00
Govindas
8594b46b2b
Delete SkStuff.jar 2020-01-13 13:04:09 +02:00
Govindas
2e4900e509
Update README.md 2020-01-13 13:03:17 +02:00
Govindass
bb8710e9dc test 2020-01-13 13:00:44 +02:00
Govindass
6151a9ec09 1.15 2020-01-13 12:58:19 +02:00
Govindass
5de16a75e3 Update plugin.yml 2020-01-13 12:40:52 +02:00
Govindass
fc48cdc060 Create .gitignore 2020-01-13 12:40:18 +02:00
Govindass
d8209feb28 1.15 support 2020-01-13 12:37:12 +02:00
Govindas
3f42acfc54
Merge pull request #1 from ham1255/master
change softdepend to depend Plugin.yml
2019-11-19 08:19:37 +02:00
mohammed jassim alajel
e08eedd121
change softdepend to depend Plugin.yml 2019-11-18 21:24:02 +04:00
Govindass
627733ab2c
Update README.md 2019-11-18 15:04:09 +02:00
Govindass
0d33ad8a66
Update plugin.yml 2019-11-18 14:59:56 +02:00
Govindass
f8861cf6f1
Update README.md 2019-11-18 14:57:56 +02:00
Govindass
9bfbcd9639
Update README.md 2019-11-18 14:55:58 +02:00
Govindass
210bb8c315
Update README.md 2019-11-18 14:55:17 +02:00
Govindass
a3e52580c2 Update plugin.yml 2019-11-18 14:53:11 +02:00
Govindass
bf9514c322 1.13 & 1.14 Update, removal of old stuff
1.13 & 1.14 Update, removed worldedit, nbt, vanishnopacket stuff and old version stuff
2019-11-18 14:51:31 +02:00
Govindass
bf5e005a80
Delete ExprEditSessionLimit.java 2019-11-18 12:21:32 +02:00
Govindass
98ed997070
Add files via upload
1.13 & 1.14 update
2019-11-18 12:20:09 +02:00
Govindass
a943eb6882
Update README.md 2019-11-18 12:06:51 +02:00
111 changed files with 2168 additions and 9698 deletions

6
.gitignore vendored Normal file
View File

@ -0,0 +1,6 @@
/out
/bin
/target
/META-INF
/.settings
/.idea

View File

@ -0,0 +1,10 @@
<component name="ArtifactManager">
<artifact type="jar" build-on-make="true" name="SkStuff:jar">
<output-path>$PROJECT_DIR$/out/artifacts/SkStuff_jar</output-path>
<root id="archive" name="SkStuff.jar">
<element id="module-output" name="SkStuff" />
<element id="module-source" name="SkStuff" />
<element id="file-copy" path="$PROJECT_DIR$/plugin.yml" />
</root>
</artifact>
</component>

9
.idea/discord.xml Normal file
View File

@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="DiscordProjectSettings">
<option name="show" value="true" />
</component>
<component name="ProjectNotificationSettings">
<option name="askShowProject" value="false" />
</component>
</project>

6
.idea/misc.xml Normal file
View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" project-jdk-name="1.8" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/out" />
</component>
</project>

8
.idea/modules.xml Normal file
View File

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/SkStuff.iml" filepath="$PROJECT_DIR$/SkStuff.iml" />
</modules>
</component>
</project>

100
.idea/workspace.xml Normal file
View File

@ -0,0 +1,100 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ChangeListManager">
<list default="true" id="72e0643a-ea45-4e93-b5a5-734a94c41ff5" name="Default Changelist" comment="">
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/me/TheBukor/SkStuff/SkStuff.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/me/TheBukor/SkStuff/SkStuff.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/me/TheBukor/SkStuff/util/NMS_v1_9_R1.java" beforeDir="false" />
</list>
<option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" />
<option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
<option name="LAST_RESOLUTION" value="IGNORE" />
</component>
<component name="FileTemplateManagerImpl">
<option name="RECENT_TEMPLATES">
<list>
<option value="Class" />
</list>
</option>
</component>
<component name="Git.Settings">
<option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$" />
</component>
<component name="ProjectId" id="1dDc5mH6vdHCfDtdCWF3TtPitSZ" />
<component name="ProjectViewState">
<option name="showExcludedFiles" value="true" />
<option name="showLibraryContents" value="true" />
</component>
<component name="PropertiesComponent">
<property name="ASKED_ADD_EXTERNAL_FILES" value="true" />
<property name="RunOnceActivity.ShowReadmeOnStart" value="true" />
<property name="last_opened_file_path" value="$PROJECT_DIR$/plugin.yml" />
<property name="project.structure.last.edited" value="Artifacts" />
<property name="project.structure.proportion" value="0.15" />
<property name="project.structure.side.proportion" value="0.2" />
</component>
<component name="RecentsManager">
<key name="CopyClassDialog.RECENTS_KEY">
<recent name="me.TheBukor.SkStuff.pathfinders" />
<recent name="me.TheBukor.SkStuff.util" />
</key>
</component>
<component name="SQLPlugin.ProjectConfiguration">
<queries />
</component>
<component name="ServiceViewManager">
<option name="viewStates">
<list>
<serviceView>
<treeState>
<expand />
<select />
</treeState>
</serviceView>
</list>
</option>
</component>
<component name="SvnConfiguration">
<configuration />
</component>
<component name="TaskManager">
<task active="true" id="Default" summary="Default task">
<changelist id="72e0643a-ea45-4e93-b5a5-734a94c41ff5" name="Default Changelist" comment="" />
<created>1578912360094</created>
<option name="number" value="Default" />
<option name="presentableId" value="Default" />
<updated>1578912360094</updated>
</task>
<servers />
</component>
<component name="WindowStateProjectService">
<state x="79" y="101" key="FileChooserDialogImpl" timestamp="1595328182010">
<screen x="0" y="0" width="1366" height="728" />
</state>
<state x="79" y="101" key="FileChooserDialogImpl/0.0.1366.728@0.0.1366.728" timestamp="1595328182010" />
<state x="348" y="62" key="NewModule_or_Project.wizard" timestamp="1592831160031">
<screen x="0" y="0" width="1366" height="728" />
</state>
<state x="348" y="62" key="NewModule_or_Project.wizard/0.0.1366.728@0.0.1366.728" timestamp="1592831160031" />
<state x="163" y="0" key="SettingsEditor" timestamp="1595328184010">
<screen x="0" y="0" width="1366" height="728" />
</state>
<state x="163" y="0" key="SettingsEditor/0.0.1366.728@0.0.1366.728" timestamp="1595328184010" />
<state x="0" y="0" key="com.intellij.ide.util.TipDialog" timestamp="1595662947316">
<screen x="0" y="0" width="1366" height="728" />
</state>
<state x="0" y="0" key="com.intellij.ide.util.TipDialog/0.0.1366.728@0.0.1366.728" timestamp="1595662947316" />
</component>
<component name="XDebuggerManager">
<breakpoint-manager>
<breakpoints>
<line-breakpoint enabled="true" type="java-line">
<url>jar://$PROJECT_DIR$/../../import/craftbukkit-1.13.2.jar!/net/minecraft/server/v1_13_R2/NavigationAbstract.class</url>
<line>178</line>
<option name="timeStamp" value="1" />
</line-breakpoint>
</breakpoints>
</breakpoint-manager>
</component>
</project>

2
META-INF/MANIFEST.MF Normal file
View File

@ -0,0 +1,2 @@
Manifest-Version: 1.0

View File

@ -1,13 +1,62 @@
## 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.
**Download it [here](https://github.com/Tuke-Nuke/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.
---
This fork adds 1.8 - 1.16 support and removes a lot of stuff, focusing on entity related stuff as they're unique to SkStuff. No support given for versions like 1.9.2 while there's 1.9.4. only latest third digit versions.
[**Github**](https://github.com/TheBukor/SkStuff) - [**skUnity**](https://forums.skunity.com/resources/skstuff.131/)
**Download it [here](https://github.com/Govindass/SkStuff/releases)**
##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)
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.
```

159
SkStuff.iml Normal file
View File

@ -0,0 +1,159 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="EclipseModuleManager">
<libelement value="file://C:/Users/DELL/AppData/Roaming/.minecraft/workspace/eclipse/Build Path/1.7.10.jar" />
<libelement value="file://C:/Users/DELL/AppData/Roaming/.minecraft/workspace/eclipse/Build Path/1.8.3.jar" />
<libelement value="file://C:/Users/DELL/AppData/Roaming/.minecraft/workspace/eclipse/Build Path/1.8.8.jar" />
<libelement value="file://C:/Users/DELL/AppData/Roaming/.minecraft/workspace/eclipse/Build Path/1.8.jar" />
<libelement value="file://C:/Users/DELL/AppData/Roaming/.minecraft/workspace/eclipse/Build Path/Skript.jar" />
<libelement value="file://C:/Users/DELL/AppData/Roaming/.minecraft/workspace/eclipse/Build Path/VanishNoPacket.jar" />
<libelement value="file://C:/Users/DELL/AppData/Roaming/.minecraft/workspace/eclipse/Build Path/WorldEdit.jar" />
<libelement value="file://C:/Users/DELL/AppData/Roaming/.minecraft/workspace/eclipse/Build Path/ProtocolLib.jar" />
<libelement value="file://C:/Users/DELL/AppData/Roaming/.minecraft/workspace/eclipse/Build Path/1.9.4.jar" />
<libelement value="file://C:/Users/DELL/AppData/Roaming/.minecraft/workspace/eclipse/Build Path/1.9.jar" />
<libelement value="file://C:/Users/DELL/AppData/Roaming/.minecraft/workspace/eclipse/Build Path/1.10.jar" />
<libelement value="file://C:/Users/DELL/AppData/Roaming/.minecraft/workspace/eclipse/Build Path/1.11.jar" />
<libelement value="file://C:/Users/DELL/AppData/Roaming/.minecraft/workspace/eclipse/Build Path/WorldGuard1.11.jar" />
<src_description expected_position="0">
<src_folder value="file://$MODULE_DIR$/src" expected_position="0" />
</src_description>
</component>
<component name="NewModuleRootManager">
<output url="file://$MODULE_DIR$/bin" />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
</content>
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="jdk" jdkName="1.8" jdkType="JavaSDK" />
<orderEntry type="module-library">
<library>
<CLASSES>
<root url="jar://$MODULE_DIR$/../../import/craftbukkit-1.14.4-R0.1-SNAPSHOT.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES>
<root url="jar://$MODULE_DIR$/../../import/craftbukkit-1.14.4-R0.1-SNAPSHOT.jar!/" />
</SOURCES>
</library>
</orderEntry>
<orderEntry type="module-library">
<library>
<CLASSES>
<root url="jar://$MODULE_DIR$/../../import/craftbukkit-1.15.1-R0.1-SNAPSHOT.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES>
<root url="jar://$MODULE_DIR$/../../import/craftbukkit-1.15.1-R0.1-SNAPSHOT.jar!/" />
</SOURCES>
</library>
</orderEntry>
<orderEntry type="module-library">
<library>
<CLASSES>
<root url="jar://$MODULE_DIR$/../../import/craftbukkit-1.13.2.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES>
<root url="jar://$MODULE_DIR$/../../import/craftbukkit-1.13.2.jar!/" />
</SOURCES>
</library>
</orderEntry>
<orderEntry type="module-library">
<library>
<CLASSES>
<root url="jar://$MODULE_DIR$/../../import/Skript 2.3.7.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</orderEntry>
<orderEntry type="module-library">
<library>
<CLASSES>
<root url="jar://$MODULE_DIR$/../../import/craftbukkit-1.12.2.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES>
<root url="jar://$MODULE_DIR$/../../import/craftbukkit-1.12.2.jar!/" />
</SOURCES>
</library>
</orderEntry>
<orderEntry type="module-library">
<library>
<CLASSES>
<root url="jar://$MODULE_DIR$/../../import/craftbukkit-1.11.2.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES>
<root url="jar://$MODULE_DIR$/../../import/craftbukkit-1.11.2.jar!/" />
</SOURCES>
</library>
</orderEntry>
<orderEntry type="module-library">
<library>
<CLASSES>
<root url="jar://$MODULE_DIR$/../../import/craftbukkit-1.10.2-R0.1-SNAPSHOT-latest.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES>
<root url="jar://$MODULE_DIR$/../../import/craftbukkit-1.10.2-R0.1-SNAPSHOT-latest.jar!/" />
</SOURCES>
</library>
</orderEntry>
<orderEntry type="module-library">
<library>
<CLASSES>
<root url="jar://$MODULE_DIR$/../../import/craftbukkit-1.9.4-R0.1-SNAPSHOT-latest.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES>
<root url="jar://$MODULE_DIR$/../../import/craftbukkit-1.9.4-R0.1-SNAPSHOT-latest.jar!/" />
</SOURCES>
</library>
</orderEntry>
<orderEntry type="module-library">
<library>
<CLASSES>
<root url="jar://$MODULE_DIR$/../../import/craftbukkit-1.8.8-R0.1-SNAPSHOT-latest.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES>
<root url="jar://$MODULE_DIR$/../../import/craftbukkit-1.8.8-R0.1-SNAPSHOT-latest.jar!/" />
</SOURCES>
</library>
</orderEntry>
<orderEntry type="module-library">
<library>
<CLASSES>
<root url="jar://$MODULE_DIR$/../../import/craftbukkit-1.9.2-R0.1-SNAPSHOT-latest.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES>
<root url="jar://$MODULE_DIR$/../../import/craftbukkit-1.9.2-R0.1-SNAPSHOT-latest.jar!/" />
</SOURCES>
</library>
</orderEntry>
<orderEntry type="module-library">
<library>
<CLASSES>
<root url="jar://$MODULE_DIR$/../../import/craftbukkit-1.15.2.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES>
<root url="jar://$MODULE_DIR$/../../import/craftbukkit-1.15.2.jar!/" />
</SOURCES>
</library>
</orderEntry>
<orderEntry type="module-library">
<library>
<CLASSES>
<root url="jar://$MODULE_DIR$/../../import/craftbukkit-1.16.1.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES>
<root url="jar://$MODULE_DIR$/../../import/craftbukkit-1.16.1.jar!/" />
</SOURCES>
</library>
</orderEntry>
</component>
</module>

2
bin/.gitignore vendored
View File

@ -1,2 +0,0 @@
/me/
/org/

3
bin/META-INF/MANIFEST.MF Normal file
View File

@ -0,0 +1,3 @@
Manifest-Version: 1.0
Main-Class: me.TheBukor.SkStuff.SkStuff

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -1,6 +1,6 @@
name: SkStuff
author: TheBukor
description: A Skript addon which adds extra functionalities such as NBT and extended WorldEdit support.
version: 1.6.4.1-fork-1.12
name: SkPathfinderGoals
authors: [TheBukor, Govindas]
description: A Skript addon which adds extra functionalities such as pathfinder goals.
version: "2.0"
main: me.TheBukor.SkStuff.SkStuff
softdepend: [Skript, WorldEdit, VanishNoPacket]
softdepend: [Skript]

3
src/META-INF/MANIFEST.MF Normal file
View File

@ -0,0 +1,3 @@
Manifest-Version: 1.0
Main-Class: me.TheBukor.SkStuff.SkStuff

View File

@ -1,100 +1,22 @@
package me.TheBukor.SkStuff;
import java.io.IOException;
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;
import me.TheBukor.SkStuff.bstats.Metrics;
import me.TheBukor.SkStuff.effects.*;
import me.TheBukor.SkStuff.expressions.*;
import me.TheBukor.SkStuff.util.*;
import org.bukkit.Bukkit;
import org.bukkit.entity.Entity;
import org.bukkit.event.entity.EntityToggleGlideEvent;
import org.bukkit.inventory.Inventory;
import org.bukkit.plugin.java.JavaPlugin;
import javax.annotation.Nullable;
import java.io.IOException;
public class SkStuff extends JavaPlugin {
private int condAmount = 0;
@ -109,219 +31,24 @@ public class SkStuff extends JavaPlugin {
public void onEnable() {
if (Bukkit.getPluginManager().getPlugin("Skript") != null && Skript.isAcceptRegistrations()) {
Skript.registerAddon(this);
getLogger().info("SkStuff " + this.getDescription().getVersion() + " has been successfully enabled!");
getLogger().info("SkPathfinderGoals " + 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.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(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;
exprAmount += 6;
if (Skript.isRunningMinecraft(1, 9)) {
Skript.registerEffect(EffResourceSound.class, "play [raw] [([resource[ ]]pack)] sound %string% (for|to) %players% at %location% [[with] volume %-number%[[(,| and)] pitch %-number%]]", "play [raw] [([resource[ ]]pack)] sound %string% for %players% at %location% [[with] pitch %-number%[[(,| and)] volume %-number%]]");
Skript.registerEvent("Elytra glide toggle", SimpleEvent.class, EntityToggleGlideEvent.class, "[entity] elytra (fl(y|ight)|glid(e|ing)) toggl(e|ing)", "[entity] toggle elytra (fl(y|ight)|glid(e|ing))");
Skript.registerExpression(ExprGlideState.class, Boolean.class, ExpressionType.PROPERTY, "elytra (fl(y|ight)|glid(e|ing)) state of %livingentity%", "%livingentity%'s elytra (fl(y|ight)|glid(e|ing)) state");
//Skript.registerExpression(ExprPlayerChargeTime.class, Float.class, ExpressionType.PROPERTY, "blah of %player%", "%player%'s blah");
//Increase exprAmount when I uncomment this
EventValues.registerEventValue(EntityToggleGlideEvent.class, Entity.class, new Getter<Entity, EntityToggleGlideEvent>() {
@Override
@Nullable
public Entity get(EntityToggleGlideEvent e) {
return e.getEntity();
}
}, 0);
effAmount += 1;
evtAmount += 1;
exprAmount += 1;
if (Skript.isRunningMinecraft(1, 10)) {
Skript.registerExpression(ExprNoGravityState.class, Boolean.class, ExpressionType.PROPERTY, "no gravity (state|mode) of %entities%", "%entities%'s no gravity (state|mode)");
exprAmount += 1;
}
}
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|5¦squid rotate|6¦totem resurrect|7¦rabbit jump) (at|on) %entity%");
if (setupNMSVersion()) {
getLogger().info("Trying to register version specific stuff...");
Skript.registerExpression(ExprStepLength.class, Number.class, ExpressionType.PROPERTY, "[the] step length of %entity%", "%entity%'s step length");
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();
Metrics metrics = new Metrics(this, 1);
metrics.startSubmitting();
getLogger().info("Hooked into Metrics! Woohoo!!");
} catch (IOException ex) {
getLogger().warning("Sorry, I've failed to hook SkStuff into Metrics. I'm really sorry.");
getLogger().warning("Here's an error for you: " + ex.getMessage());
}
getLogger().info("Everything ready! Loaded a total of " + condAmount + " conditions, " + effAmount + " effects, " + evtAmount + " events, " + exprAmount + " expressions and " + typeAmount + " types!");
getLogger().info("Everything's ready!");
} else {
getLogger().info("Unable to find Skript or Skript isn't accepting registrations, disabling SkStuff...");
Bukkit.getPluginManager().disablePlugin(this);
@ -330,29 +57,43 @@ 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.")) {
switch (version) {
case "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.")) {
getLogger().info("It looks like you're running 1.8.8!");
break;
case "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.")) {
break;
case "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.")) {
getLogger().info("It looks like you're running 1.10.2!");
break;
case "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.")) {
getLogger().info("It looks like you're running 1.11.2!");
break;
case "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!");
} else {
getLogger().info("It looks like you're running 1.12.2!");
break;
case "v1_13_R2.":
nmsMethods = new NMS_v1_13_R2();
getLogger().info("It looks like you're running 1.13.2!");
break;
case "v1_14_R1.":
nmsMethods = new NMS_v1_14_R1();
getLogger().info("It looks like you're running 1.14.2!");
break;
case "v1_15_R1.":
nmsMethods = new NMS_v1_15_R1();
getLogger().info("It looks like you're running 1.15.1!");
break;
default:
getLogger().warning("It looks like you're running an unsupported server version, some features will not be available :(");
break;
}
return nmsMethods != null;
}
@ -362,6 +103,6 @@ public class SkStuff extends JavaPlugin {
}
public void onDisable() {
getLogger().info("SkStuff " + this.getDescription().getVersion() + " has been successfully disabled.");
getLogger().info("SkPathfinderGoals " + this.getDescription().getVersion() + " has been successfully disabled.");
}
}

View File

@ -0,0 +1,719 @@
package me.TheBukor.SkStuff.bstats;
import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import com.google.gson.JsonPrimitive;
import org.bukkit.Bukkit;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.Player;
import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.RegisteredServiceProvider;
import org.bukkit.plugin.ServicePriority;
import javax.net.ssl.HttpsURLConnection;
import java.io.*;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.util.*;
import java.util.concurrent.Callable;
import java.util.logging.Level;
import java.util.zip.GZIPOutputStream;
/**
* bStats collects some data for plugin authors.
* <p>
* Check out https://bStats.org/ to learn more about bStats!
*/
@SuppressWarnings({"WeakerAccess", "unused"})
public class Metrics {
static {
// You can use the property to disable the check in your test environment
if (System.getProperty("bstats.relocatecheck") == null || !System.getProperty("bstats.relocatecheck").equals("false")) {
// Maven's Relocate is clever and changes strings, too. So we have to use this little "trick" ... :D
final String defaultPackage = new String(
new byte[]{'o', 'r', 'g', '.', 'b', 's', 't', 'a', 't', 's', '.', 'b', 'u', 'k', 'k', 'i', 't'});
final String examplePackage = new String(new byte[]{'y', 'o', 'u', 'r', '.', 'p', 'a', 'c', 'k', 'a', 'g', 'e'});
// We want to make sure nobody just copy & pastes the example and use the wrong package names
if (Metrics.class.getPackage().getName().equals(defaultPackage) || Metrics.class.getPackage().getName().equals(examplePackage)) {
throw new IllegalStateException("bStats Metrics class has not been relocated correctly!");
}
}
}
// The version of this bStats class
public static final int B_STATS_VERSION = 1;
// The url to which the data is sent
private static final String URL = "https://bStats.org/submitData/bukkit";
// Is bStats enabled on this server?
private boolean enabled;
// Should failed requests be logged?
private static boolean logFailedRequests;
// Should the sent data be logged?
private static boolean logSentData;
// Should the response text be logged?
private static boolean logResponseStatusText;
// The uuid of the server
private static String serverUUID;
// The plugin
private final Plugin plugin;
// The plugin id
private final int pluginId;
// A list with all custom charts
private final List<CustomChart> charts = new ArrayList<>();
/**
* Class constructor.
*
* @param plugin The plugin which stats should be submitted.
* @param pluginId The id of the plugin.
* It can be found at <a href="https://bstats.org/what-is-my-plugin-id">What is my plugin id?</a>
*/
public Metrics(Plugin plugin, int pluginId) {
if (plugin == null) {
throw new IllegalArgumentException("Plugin cannot be null!");
}
this.plugin = plugin;
this.pluginId = pluginId;
// Get the config file
File bStatsFolder = new File(plugin.getDataFolder().getParentFile(), "bStats");
File configFile = new File(bStatsFolder, "config.yml");
YamlConfiguration config = YamlConfiguration.loadConfiguration(configFile);
// Check if the config file exists
if (!config.isSet("serverUuid")) {
// Add default values
config.addDefault("enabled", true);
// Every server gets it's unique random id.
config.addDefault("serverUuid", UUID.randomUUID().toString());
// Should failed request be logged?
config.addDefault("logFailedRequests", false);
// Should the sent data be logged?
config.addDefault("logSentData", false);
// Should the response text be logged?
config.addDefault("logResponseStatusText", false);
// Inform the server owners about bStats
config.options().header(
"bStats collects some data for plugin authors like how many servers are using their plugins.\n" +
"To honor their work, you should not disable it.\n" +
"This has nearly no effect on the server performance!\n" +
"Check out https://bStats.org/ to learn more :)"
).copyDefaults(true);
try {
config.save(configFile);
} catch (IOException ignored) { }
}
// Load the data
enabled = config.getBoolean("enabled", true);
serverUUID = config.getString("serverUuid");
logFailedRequests = config.getBoolean("logFailedRequests", false);
logSentData = config.getBoolean("logSentData", false);
logResponseStatusText = config.getBoolean("logResponseStatusText", false);
if (enabled) {
boolean found = false;
// Search for all other bStats Metrics classes to see if we are the first one
for (Class<?> service : Bukkit.getServicesManager().getKnownServices()) {
try {
service.getField("B_STATS_VERSION"); // Our identifier :)
found = true; // We aren't the first
break;
} catch (NoSuchFieldException ignored) { }
}
// Register our service
Bukkit.getServicesManager().register(Metrics.class, this, plugin, ServicePriority.Normal);
if (!found) {
// We are the first!
startSubmitting();
}
}
}
/**
* Checks if bStats is enabled.
*
* @return Whether bStats is enabled or not.
*/
public boolean isEnabled() {
return enabled;
}
/**
* Adds a custom chart.
*
* @param chart The chart to add.
*/
public void addCustomChart(CustomChart chart) {
if (chart == null) {
throw new IllegalArgumentException("Chart cannot be null!");
}
charts.add(chart);
}
/**
* Starts the Scheduler which submits our data every 30 minutes.
*/
public void startSubmitting() {
final Timer timer = new Timer(true); // We use a timer cause the Bukkit scheduler is affected by server lags
timer.scheduleAtFixedRate(new TimerTask() {
@Override
public void run() {
if (!plugin.isEnabled()) { // Plugin was disabled
timer.cancel();
return;
}
// Nevertheless we want our code to run in the Bukkit main thread, so we have to use the Bukkit scheduler
// Don't be afraid! The connection to the bStats server is still async, only the stats collection is sync ;)
Bukkit.getScheduler().runTask(plugin, () -> submitData());
}
}, 1000 * 60 * 5, 1000 * 60 * 30);
// Submit the data every 30 minutes, first time after 5 minutes to give other plugins enough time to start
// WARNING: Changing the frequency has no effect but your plugin WILL be blocked/deleted!
// WARNING: Just don't do it!
}
/**
* Gets the plugin specific data.
* This method is called using Reflection.
*
* @return The plugin specific data.
*/
public JsonObject getPluginData() {
JsonObject data = new JsonObject();
String pluginName = plugin.getDescription().getName();
String pluginVersion = plugin.getDescription().getVersion();
data.addProperty("pluginName", pluginName); // Append the name of the plugin
data.addProperty("id", pluginId); // Append the id of the plugin
data.addProperty("pluginVersion", pluginVersion); // Append the version of the plugin
JsonArray customCharts = new JsonArray();
for (CustomChart customChart : charts) {
// Add the data of the custom charts
JsonObject chart = customChart.getRequestJsonObject();
if (chart == null) { // If the chart is null, we skip it
continue;
}
customCharts.add(chart);
}
data.add("customCharts", customCharts);
return data;
}
/**
* Gets the server specific data.
*
* @return The server specific data.
*/
private JsonObject getServerData() {
// Minecraft specific data
int playerAmount;
try {
// Around MC 1.8 the return type was changed to a collection from an array,
// This fixes java.lang.NoSuchMethodError: org.bukkit.Bukkit.getOnlinePlayers()Ljava/util/Collection;
Method onlinePlayersMethod = Class.forName("org.bukkit.Server").getMethod("getOnlinePlayers");
playerAmount = onlinePlayersMethod.getReturnType().equals(Collection.class)
? ((Collection<?>) onlinePlayersMethod.invoke(Bukkit.getServer())).size()
: ((Player[]) onlinePlayersMethod.invoke(Bukkit.getServer())).length;
} catch (Exception e) {
playerAmount = Bukkit.getOnlinePlayers().size(); // Just use the new method if the Reflection failed
}
int onlineMode = Bukkit.getOnlineMode() ? 1 : 0;
String bukkitVersion = Bukkit.getVersion();
String bukkitName = Bukkit.getName();
// OS/Java specific data
String javaVersion = System.getProperty("java.version");
String osName = System.getProperty("os.name");
String osArch = System.getProperty("os.arch");
String osVersion = System.getProperty("os.version");
int coreCount = Runtime.getRuntime().availableProcessors();
JsonObject data = new JsonObject();
data.addProperty("serverUUID", serverUUID);
data.addProperty("playerAmount", playerAmount);
data.addProperty("onlineMode", onlineMode);
data.addProperty("bukkitVersion", bukkitVersion);
data.addProperty("bukkitName", bukkitName);
data.addProperty("javaVersion", javaVersion);
data.addProperty("osName", osName);
data.addProperty("osArch", osArch);
data.addProperty("osVersion", osVersion);
data.addProperty("coreCount", coreCount);
return data;
}
/**
* Collects the data and sends it afterwards.
*/
private void submitData() {
final JsonObject data = getServerData();
JsonArray pluginData = new JsonArray();
// Search for all other bStats Metrics classes to get their plugin data
for (Class<?> service : Bukkit.getServicesManager().getKnownServices()) {
try {
service.getField("B_STATS_VERSION"); // Our identifier :)
for (RegisteredServiceProvider<?> provider : Bukkit.getServicesManager().getRegistrations(service)) {
try {
Object plugin = provider.getService().getMethod("getPluginData").invoke(provider.getProvider());
if (plugin instanceof JsonObject) {
pluginData.add((JsonObject) plugin);
} else { // old bstats version compatibility
try {
Class<?> jsonObjectJsonSimple = Class.forName("org.json.simple.JSONObject");
if (plugin.getClass().isAssignableFrom(jsonObjectJsonSimple)) {
Method jsonStringGetter = jsonObjectJsonSimple.getDeclaredMethod("toJSONString");
jsonStringGetter.setAccessible(true);
String jsonString = (String) jsonStringGetter.invoke(plugin);
JsonObject object = new JsonParser().parse(jsonString).getAsJsonObject();
pluginData.add(object);
}
} catch (ClassNotFoundException e) {
// minecraft version 1.14+
if (logFailedRequests) {
this.plugin.getLogger().log(Level.SEVERE, "Encountered unexpected exception", e);
}
}
}
} catch (NullPointerException | NoSuchMethodException | IllegalAccessException | InvocationTargetException ignored) { }
}
} catch (NoSuchFieldException ignored) { }
}
data.add("plugins", pluginData);
// Create a new thread for the connection to the bStats server
new Thread(() -> {
try {
// Send the data
sendData(plugin, data);
} catch (Exception e) {
// Something went wrong! :(
if (logFailedRequests) {
plugin.getLogger().log(Level.WARNING, "Could not submit plugin stats of " + plugin.getName(), e);
}
}
}).start();
}
/**
* Sends the data to the bStats server.
*
* @param plugin Any plugin. It's just used to get a logger instance.
* @param data The data to send.
* @throws Exception If the request failed.
*/
private static void sendData(Plugin plugin, JsonObject data) throws Exception {
if (data == null) {
throw new IllegalArgumentException("Data cannot be null!");
}
if (Bukkit.isPrimaryThread()) {
throw new IllegalAccessException("This method must not be called from the main thread!");
}
if (logSentData) {
plugin.getLogger().info("Sending data to bStats: " + data);
}
HttpsURLConnection connection = (HttpsURLConnection) new URL(URL).openConnection();
// Compress the data to save bandwidth
byte[] compressedData = compress(data.toString());
// Add headers
connection.setRequestMethod("POST");
connection.addRequestProperty("Accept", "application/json");
connection.addRequestProperty("Connection", "close");
connection.addRequestProperty("Content-Encoding", "gzip"); // We gzip our request
connection.addRequestProperty("Content-Length", String.valueOf(compressedData.length));
connection.setRequestProperty("Content-Type", "application/json"); // We send our data in JSON format
connection.setRequestProperty("User-Agent", "MC-Server/" + B_STATS_VERSION);
// Send data
connection.setDoOutput(true);
try (DataOutputStream outputStream = new DataOutputStream(connection.getOutputStream())) {
outputStream.write(compressedData);
}
StringBuilder builder = new StringBuilder();
try (BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(connection.getInputStream()))) {
String line;
while ((line = bufferedReader.readLine()) != null) {
builder.append(line);
}
}
if (logResponseStatusText) {
plugin.getLogger().info("Sent data to bStats and received response: " + builder);
}
}
/**
* Gzips the given String.
*
* @param str The string to gzip.
* @return The gzipped String.
* @throws IOException If the compression failed.
*/
private static byte[] compress(final String str) throws IOException {
if (str == null) {
return null;
}
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
try (GZIPOutputStream gzip = new GZIPOutputStream(outputStream)) {
gzip.write(str.getBytes(StandardCharsets.UTF_8));
}
return outputStream.toByteArray();
}
/**
* Represents a custom chart.
*/
public static abstract class CustomChart {
// The id of the chart
final String chartId;
/**
* Class constructor.
*
* @param chartId The id of the chart.
*/
CustomChart(String chartId) {
if (chartId == null || chartId.isEmpty()) {
throw new IllegalArgumentException("ChartId cannot be null or empty!");
}
this.chartId = chartId;
}
private JsonObject getRequestJsonObject() {
JsonObject chart = new JsonObject();
chart.addProperty("chartId", chartId);
try {
JsonObject data = getChartData();
if (data == null) {
// If the data is null we don't send the chart.
return null;
}
chart.add("data", data);
} catch (Throwable t) {
if (logFailedRequests) {
Bukkit.getLogger().log(Level.WARNING, "Failed to get data for custom chart with id " + chartId, t);
}
return null;
}
return chart;
}
protected abstract JsonObject getChartData() throws Exception;
}
/**
* Represents a custom simple pie.
*/
public static class SimplePie extends CustomChart {
private final Callable<String> callable;
/**
* Class constructor.
*
* @param chartId The id of the chart.
* @param callable The callable which is used to request the chart data.
*/
public SimplePie(String chartId, Callable<String> callable) {
super(chartId);
this.callable = callable;
}
@Override
protected JsonObject getChartData() throws Exception {
JsonObject data = new JsonObject();
String value = callable.call();
if (value == null || value.isEmpty()) {
// Null = skip the chart
return null;
}
data.addProperty("value", value);
return data;
}
}
/**
* Represents a custom advanced pie.
*/
public static class AdvancedPie extends CustomChart {
private final Callable<Map<String, Integer>> callable;
/**
* Class constructor.
*
* @param chartId The id of the chart.
* @param callable The callable which is used to request the chart data.
*/
public AdvancedPie(String chartId, Callable<Map<String, Integer>> callable) {
super(chartId);
this.callable = callable;
}
@Override
protected JsonObject getChartData() throws Exception {
JsonObject data = new JsonObject();
JsonObject values = new JsonObject();
Map<String, Integer> map = callable.call();
if (map == null || map.isEmpty()) {
// Null = skip the chart
return null;
}
boolean allSkipped = true;
for (Map.Entry<String, Integer> entry : map.entrySet()) {
if (entry.getValue() == 0) {
continue; // Skip this invalid
}
allSkipped = false;
values.addProperty(entry.getKey(), entry.getValue());
}
if (allSkipped) {
// Null = skip the chart
return null;
}
data.add("values", values);
return data;
}
}
/**
* Represents a custom drilldown pie.
*/
public static class DrilldownPie extends CustomChart {
private final Callable<Map<String, Map<String, Integer>>> callable;
/**
* Class constructor.
*
* @param chartId The id of the chart.
* @param callable The callable which is used to request the chart data.
*/
public DrilldownPie(String chartId, Callable<Map<String, Map<String, Integer>>> callable) {
super(chartId);
this.callable = callable;
}
@Override
public JsonObject getChartData() throws Exception {
JsonObject data = new JsonObject();
JsonObject values = new JsonObject();
Map<String, Map<String, Integer>> map = callable.call();
if (map == null || map.isEmpty()) {
// Null = skip the chart
return null;
}
boolean reallyAllSkipped = true;
for (Map.Entry<String, Map<String, Integer>> entryValues : map.entrySet()) {
JsonObject value = new JsonObject();
boolean allSkipped = true;
for (Map.Entry<String, Integer> valueEntry : map.get(entryValues.getKey()).entrySet()) {
value.addProperty(valueEntry.getKey(), valueEntry.getValue());
allSkipped = false;
}
if (!allSkipped) {
reallyAllSkipped = false;
values.add(entryValues.getKey(), value);
}
}
if (reallyAllSkipped) {
// Null = skip the chart
return null;
}
data.add("values", values);
return data;
}
}
/**
* Represents a custom single line chart.
*/
public static class SingleLineChart extends CustomChart {
private final Callable<Integer> callable;
/**
* Class constructor.
*
* @param chartId The id of the chart.
* @param callable The callable which is used to request the chart data.
*/
public SingleLineChart(String chartId, Callable<Integer> callable) {
super(chartId);
this.callable = callable;
}
@Override
protected JsonObject getChartData() throws Exception {
JsonObject data = new JsonObject();
int value = callable.call();
if (value == 0) {
// Null = skip the chart
return null;
}
data.addProperty("value", value);
return data;
}
}
/**
* Represents a custom multi line chart.
*/
public static class MultiLineChart extends CustomChart {
private final Callable<Map<String, Integer>> callable;
/**
* Class constructor.
*
* @param chartId The id of the chart.
* @param callable The callable which is used to request the chart data.
*/
public MultiLineChart(String chartId, Callable<Map<String, Integer>> callable) {
super(chartId);
this.callable = callable;
}
@Override
protected JsonObject getChartData() throws Exception {
JsonObject data = new JsonObject();
JsonObject values = new JsonObject();
Map<String, Integer> map = callable.call();
if (map == null || map.isEmpty()) {
// Null = skip the chart
return null;
}
boolean allSkipped = true;
for (Map.Entry<String, Integer> entry : map.entrySet()) {
if (entry.getValue() == 0) {
continue; // Skip this invalid
}
allSkipped = false;
values.addProperty(entry.getKey(), entry.getValue());
}
if (allSkipped) {
// Null = skip the chart
return null;
}
data.add("values", values);
return data;
}
}
/**
* Represents a custom simple bar chart.
*/
public static class SimpleBarChart extends CustomChart {
private final Callable<Map<String, Integer>> callable;
/**
* Class constructor.
*
* @param chartId The id of the chart.
* @param callable The callable which is used to request the chart data.
*/
public SimpleBarChart(String chartId, Callable<Map<String, Integer>> callable) {
super(chartId);
this.callable = callable;
}
@Override
protected JsonObject getChartData() throws Exception {
JsonObject data = new JsonObject();
JsonObject values = new JsonObject();
Map<String, Integer> map = callable.call();
if (map == null || map.isEmpty()) {
// Null = skip the chart
return null;
}
for (Map.Entry<String, Integer> entry : map.entrySet()) {
JsonArray categoryValues = new JsonArray();
categoryValues.add(new JsonPrimitive(entry.getValue()));
values.add(entry.getKey(), categoryValues);
}
data.add("values", values);
return data;
}
}
/**
* Represents a custom advanced bar chart.
*/
public static class AdvancedBarChart extends CustomChart {
private final Callable<Map<String, int[]>> callable;
/**
* Class constructor.
*
* @param chartId The id of the chart.
* @param callable The callable which is used to request the chart data.
*/
public AdvancedBarChart(String chartId, Callable<Map<String, int[]>> callable) {
super(chartId);
this.callable = callable;
}
@Override
protected JsonObject getChartData() throws Exception {
JsonObject data = new JsonObject();
JsonObject values = new JsonObject();
Map<String, int[]> map = callable.call();
if (map == null || map.isEmpty()) {
// Null = skip the chart
return null;
}
boolean allSkipped = true;
for (Map.Entry<String, int[]> entry : map.entrySet()) {
if (entry.getValue().length == 0) {
continue; // Skip this invalid
}
allSkipped = false;
JsonArray categoryValues = new JsonArray();
for (int categoryValue : entry.getValue()) {
categoryValues.add(new JsonPrimitive(categoryValue));
}
values.add(entry.getKey(), categoryValues);
}
if (allSkipped) {
// Null = skip the chart
return null;
}
data.add("values", values);
return data;
}
}
}

View File

@ -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());
}
}

View File

@ -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();
}
}
}

View File

@ -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;
}
}
}

View File

@ -1,49 +0,0 @@
package me.TheBukor.SkStuff.effects;
import java.io.EOFException;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.zip.GZIPOutputStream;
import javax.annotation.Nullable;
import org.bukkit.event.Event;
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 EffGZipFile extends Effect {
private Expression<String> filePath;
@SuppressWarnings("unchecked")
@Override
public boolean init(Expression<?>[] expr, int matchedPattern, Kleenean arg2, ParseResult result) {
filePath = (Expression<String>) expr[0];
return true;
}
@Override
public String toString(@Nullable Event e, boolean debug) {
return "create GZipped file at path " + filePath.toString(e, debug);
}
@Override
protected void execute(Event e) {
File newFile = new File(filePath.getSingle(e));
if (!newFile.exists()) {
try {
new GZIPOutputStream(new FileOutputStream(newFile)).close();
} catch (FileNotFoundException ex) {
ex.printStackTrace();
} catch (IOException ex) {
if (!(ex instanceof EOFException)) {
ex.printStackTrace();
}
}
}
}
}

View File

@ -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();
}
}
}

View File

@ -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();
}
}
}

View File

@ -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();
}
}
}

View File

@ -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();
}
}
}

View File

@ -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();
}
}
}

View File

@ -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();
}
}
}

View File

@ -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);
}
}

View File

@ -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)) {

View File

@ -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();
}
}
}

View File

@ -1,57 +0,0 @@
package me.TheBukor.SkStuff.effects;
import javax.annotation.Nullable;
import org.bukkit.Location;
import org.bukkit.entity.Player;
import org.bukkit.event.Event;
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 EffResourceSound extends Effect {
private Expression<String> sound;
private Expression<Player> players;
private Expression<Location> location;
private Expression<Number> volume;
private Expression<Number> pitch;
private int pattern;
@SuppressWarnings("unchecked")
@Override
public boolean init(Expression<?>[] expr, int matchedPattern, Kleenean isDelayed, ParseResult result) {
sound = (Expression<String>) expr[0];
players = (Expression<Player>) expr[1];
location = (Expression<Location>) expr[2];
pattern = matchedPattern;
if (pattern == 0) {
volume = (Expression<Number>) expr[3];
pitch = (Expression<Number>) expr[4];
} else {
pitch = (Expression<Number>) expr[3];
volume = (Expression<Number>) expr[4];
}
return true;
}
@Override
public String toString(@Nullable Event e, boolean debug) {
return "play raw sound for " + players.toString(e, debug) + " at " + location.toString(e, debug) + " with " + (pattern == 0 ? "volume " + volume.toString(e, debug) : "pitch " + pitch.toString(e, debug)) + " and " + (pattern == 0 ? "pitch " + pitch.toString(e, debug) : "volume " + volume.toString(e, debug));
}
@SuppressWarnings("deprecation")
@Override
protected void execute(Event e) {
String s = sound.getSingle(e);
Player[] ps = players.getAll(e);
Location loc = location.getSingle(e);
float vol = (volume == null ? 1.0F : volume.getSingle(e).floatValue());
float pitch = (this.pitch == null ? 1.0F : this.pitch.getSingle(e).floatValue());
for (Player p : ps) {
p.playSound(loc, s, vol, pitch);
}
}
}

View File

@ -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();
}
}
}

View File

@ -40,12 +40,11 @@ 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 +97,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 +538,17 @@ 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));
switch (version) {
case "v1.12_R1.":
newGoals.add(new PathfinderGoalFollow_v1_12_R1((net.minecraft.server.v1_12_R1.EntityCreature) nmsEnt, nmsClass, radius, spd, usesName, customName));
break;
case "v1.13_R2.":
newGoals.add(new PathfinderGoalFollow_v1_13_R2((net.minecraft.server.v1_13_R2.EntityCreature) nmsEnt, nmsClass, radius, spd, usesName, customName));
break;
case "v1.14_R1.":
newGoals.add(new PathfinderGoalFollow_v1_14_R1((net.minecraft.server.v1_14_R1.EntityCreature) nmsEnt, nmsClass, radius, spd, usesName, customName));
break;
}
}
}
} else if (mark == 42) {

View File

@ -39,7 +39,17 @@ public class EffShowEntityEffect extends Effect {
} else if (mark == 4) {
effect = EntityEffect.WOLF_SHAKE;
toStringMark = "wolf shake";
} else if (mark == 5) {
effect = EntityEffect.SQUID_ROTATE;
toStringMark = "squid rotate";
} else if (mark == 6) {
effect = EntityEffect.TOTEM_RESURRECT;
toStringMark = "totem resurrect";
} else if (mark == 7) {
effect = EntityEffect.RABBIT_JUMP;
toStringMark = "rabbit jump";
}
return true;
}

View File

@ -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();
}
}
}

View File

@ -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);
}
}
}

View File

@ -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();
}
}

View File

@ -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;
}
}

View File

@ -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()));
}
}
}

View File

@ -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);
}
}

View File

@ -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() };
}
}

View File

@ -1,49 +0,0 @@
package me.TheBukor.SkStuff.expressions;
import javax.annotation.Nullable;
import org.bukkit.event.Event;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.inventory.Inventory;
import ch.njol.skript.ScriptLoader;
import ch.njol.skript.Skript;
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.util.Kleenean;
public class ExprClickedInventory extends SimpleExpression<Inventory> {
@Override
public Class<? extends Inventory> getReturnType() {
return Inventory.class;
}
@Override
public boolean isSingle() {
return true;
}
@Override
public boolean init(Expression<?>[] expr, int matchedPattern, Kleenean arg2, ParseResult result) {
if (!ScriptLoader.isCurrentEvent(InventoryClickEvent.class)) {
Skript.error("The expression clicked inventory can only be used in an on inventory click event", ErrorQuality.SEMANTIC_ERROR);
return false;
}
return true;
}
@Override
public String toString(@Nullable Event e, boolean debug) {
return "clicked inventory";
}
@Override
@Nullable
protected Inventory[] get(Event e) {
return new Inventory[] { ((InventoryClickEvent) e).getClickedInventory() };
}
}

View File

@ -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;
}
}

View File

@ -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;
}
}

View File

@ -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;
}
}

View File

@ -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;
}
}

View File

@ -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;
}
}

View File

@ -1,66 +0,0 @@
package me.TheBukor.SkStuff.expressions;
import javax.annotation.Nullable;
import org.bukkit.entity.LivingEntity;
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 ExprGlideState extends SimpleExpression<Boolean> {
private Expression<LivingEntity> entity;
@Override
public boolean isSingle() {
return true;
}
@Override
public Class<? extends Boolean> getReturnType() {
return Boolean.class;
}
@SuppressWarnings("unchecked")
@Override
public boolean init(Expression<?>[] expr, int matchedPattern, Kleenean isDelayed, ParseResult parseResult) {
entity = (Expression<LivingEntity>) expr[0];
return true;
}
@Override
public String toString(@Nullable Event e, boolean debug) {
return "elytra gliding state of " + entity.toString(e, debug);
}
@Override
@Nullable
protected Boolean[] get(Event e) {
LivingEntity ent = entity.getSingle(e);
return new Boolean[] { SkStuff.getNMSMethods().getElytraGlideState(ent) };
}
@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) {
LivingEntity ent = entity.getSingle(e);
if (mode == ChangeMode.SET) {
boolean newValue = (boolean) delta[0];
SkStuff.getNMSMethods().setElytraGlideState(ent, newValue);
}
}
}

View File

@ -1,63 +0,0 @@
package me.TheBukor.SkStuff.expressions;
import javax.annotation.Nullable;
import org.bukkit.block.Block;
import org.bukkit.block.BlockState;
import org.bukkit.block.DoubleChest;
import org.bukkit.entity.Entity;
import org.bukkit.event.Event;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.InventoryHolder;
import ch.njol.skript.Skript;
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 ExprInventoryOwner extends SimpleExpression<Object> {
private Expression<Inventory> inventory;
@Override
public boolean isSingle() {
return true;
}
@Override
public Class<? extends Object> getReturnType() {
return Object.class;
}
@SuppressWarnings("unchecked")
@Override
public boolean init(Expression<?>[] expr, int matchedPattern, Kleenean isDelayed, ParseResult parseResult) {
inventory = (Expression<Inventory>) expr[0];
return true;
}
@Override
public String toString(@Nullable Event e, boolean debug) {
return "owner of " + inventory.toString(e, debug);
}
@Override
@Nullable
protected Object[] get(Event e) {
if (inventory.getSingle(e) == null)
return null;
InventoryHolder holder = inventory.getSingle(e).getHolder();
if (holder instanceof Entity) {
return new Entity[] { (Entity) holder };
} else if (holder instanceof BlockState) {
return new Block[] { ((BlockState) holder).getBlock() };
} else if (holder instanceof DoubleChest) {
return new Block[] { ((DoubleChest) holder).getLocation().getBlock() };
} else {
Skript.error("Something went wrong when trying to get the owner of the specified inventory!");
Skript.error("Post the below info on the SkStuff thread in SkUnity:");
Skript.error("Class -> " + holder.getClass().getCanonicalName());
}
return null;
}
}

View File

@ -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 };
}
}

View File

@ -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) };
}
}

View File

@ -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) };
}
}

View File

@ -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) };
}
}

View File

@ -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;
}
}

View File

@ -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;
}
}

View File

@ -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;
}
}

View File

@ -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) };
}
}

View File

@ -1,82 +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 ExprNoGravityState extends SimpleExpression<Boolean> {
private Expression<Entity> entities;
@Override
public boolean isSingle() {
return entities.isSingle();
}
@Override
public Class<? extends Boolean> getReturnType() {
return Boolean.class;
}
@SuppressWarnings("unchecked")
@Override
public boolean init(Expression<?>[] expr, int matchedPattern, Kleenean isDelayed, ParseResult parseResult) {
entities = (Expression<Entity>) expr[0];
return true;
}
@Override
public String toString(@Nullable Event e, boolean debug) {
return "no gravity state of " + entities.toString(e, debug);
}
@Override
@Nullable
protected Boolean[] get(Event e) {
Entity[] ents = entities.getAll(e);
if (ents.length == 0)
return null;
Boolean[] gravityStates = new Boolean[ents.length];
int i = 0;
for (Entity ent : ents) {
if (ent == null)
continue;
gravityStates[i] = SkStuff.getNMSMethods().getNoGravity(ent);
i++;
}
return gravityStates;
}
@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) {
Entity[] ents = entities.getAll(e);
if (ents.length == 0)
return;
if (mode == ChangeMode.SET) {
boolean newValue = (boolean) delta[0];
for (Entity ent : ents) {
if (ent == null)
continue;
SkStuff.getNMSMethods().setNoGravity(ent, newValue);
}
}
}
}

View File

@ -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]);
}
}

View File

@ -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() };
}
}

View File

@ -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 };
}
}

View File

@ -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;
}
}

View File

@ -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;
}
}

View File

@ -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();
}
}
}
}
}

View File

@ -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;
}
}

View File

@ -1,77 +0,0 @@
package me.TheBukor.SkStuff.expressions;
import javax.annotation.Nullable;
import org.bukkit.event.Event;
import ch.njol.skript.Skript;
import ch.njol.skript.lang.Expression;
import ch.njol.skript.lang.SkriptParser.ParseResult;
import ch.njol.skript.lang.util.SimpleExpression;
import ch.njol.skript.util.Timespan;
import ch.njol.util.Kleenean;
public class ExprTimespanToNumber extends SimpleExpression<Number> {
private Expression<Timespan> time;
private String toStringMark;
private int mark;
@Override
public Class<? extends Number> getReturnType() {
return Number.class;
}
@Override
public boolean isSingle() {
return true;
}
@SuppressWarnings("unchecked")
@Override
public boolean init(Expression<?>[] expr, int matchedPattern, Kleenean arg2, ParseResult result) {
time = (Expression<Timespan>) expr[0];
mark = result.mark;
if (result.mark == 0) {
toStringMark = "ticks";
} else if (result.mark == 1) {
toStringMark = "seconds";
} else if (result.mark == 2) {
toStringMark = "minutes";
} else if (result.mark == 3) {
toStringMark = "hours";
} else if (result.mark == 4) {
toStringMark = "days";
}
return true;
}
@Override
public String toString(@Nullable Event e, boolean debug) {
return time.toString(e, debug) + "converted to " + toStringMark;
}
@SuppressWarnings("deprecation")
@Override
@Nullable
protected Number[] get(Event e) {
Timespan t = time.getSingle(e);
Number ticks = null;
if (Skript.methodExists(Timespan.class, "getTicks_i")) { //Compatibility with Mirreducki's Skript patch 24+ days timespans.
ticks = t.getTicks_i();
} else { //Standard Skript timespans, limited to roughly 24 days.
ticks = t.getTicks();
}
if (mark == 0) {
return new Number[] { ticks };
} else if (mark == 1) {
return new Number[] { ticks.longValue() / 20 };
} else if (mark == 2) {
return new Number[] { ticks.longValue() / 20 / 60 };
} else if (mark == 3) {
return new Number[] { ticks.longValue() / 20 / 60 / 60 };
} else if (mark == 4) {
return new Number[] { ticks.longValue() / 20 / 60 / 60 / 24 };
}
return null;
}
}

View File

@ -1,43 +0,0 @@
package me.TheBukor.SkStuff.expressions;
import javax.annotation.Nullable;
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;
public class ExprToLowerCase extends SimpleExpression<String> {
private Expression<String> text;
@Override
public Class<? extends String> getReturnType() {
return String.class;
}
@Override
public boolean isSingle() {
return true;
}
@SuppressWarnings("unchecked")
@Override
public boolean init(Expression<?>[] expr, int matchedPattern, Kleenean arg2, ParseResult arg3) {
text = (Expression<String>) expr[0];
return true;
}
@Override
public String toString(@Nullable Event e, boolean debug) {
return "convert all characters in " + text.toString(e, debug) + " to lowercase";
}
@Override
@Nullable
protected String[] get(Event e) {
String s = text.getSingle(e);
return new String[] { s.toLowerCase() };
}
}

View File

@ -1,43 +0,0 @@
package me.TheBukor.SkStuff.expressions;
import javax.annotation.Nullable;
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;
public class ExprToUpperCase extends SimpleExpression<String> {
private Expression<String> text;
@Override
public Class<? extends String> getReturnType() {
return String.class;
}
@Override
public boolean isSingle() {
return true;
}
@SuppressWarnings("unchecked")
@Override
public boolean init(Expression<?>[] expr, int matchedPattern, Kleenean arg2, ParseResult arg3) {
text = (Expression<String>) expr[0];
return true;
}
@Override
public String toString(@Nullable Event e, boolean debug) {
return "convert all characters in " + text.toString(e, debug) + " to uppercase";
}
@Override
@Nullable
protected String[] get(Event e) {
String s = text.getSingle(e);
return new String[] { s.toUpperCase() };
}
}

View File

@ -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) };
}
}

View File

@ -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());
}
}
}
}

View File

@ -1,56 +0,0 @@
package me.TheBukor.SkStuff.expressions;
import javax.annotation.Nullable;
import org.apache.commons.lang.WordUtils;
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;
public class ExprWordsToUpperCase extends SimpleExpression<String> {
private Expression<String> text;
private Boolean fullyCapitalize = false;
private String toStringEnd;
@Override
public Class<? extends String> getReturnType() {
return String.class;
}
@Override
public boolean isSingle() {
return true;
}
@SuppressWarnings("unchecked")
@Override
public boolean init(Expression<?>[] expr, int matchedPattern, Kleenean arg2, ParseResult result) {
text = (Expression<String>) expr[0];
if (result.mark == 0) {
toStringEnd = " to uppercase";
} else {
fullyCapitalize = true;
toStringEnd = " to uppercase ignoring other uppercase characters";
}
return true;
}
@Override
public String toString(@Nullable Event e, boolean debug) {
return "convert first character of each word in " + text.toString(e, debug) + toStringEnd;
}
@Override
@Nullable
protected String[] get(Event e) {
String s = text.getSingle(e);
if (fullyCapitalize) {
return new String[] { WordUtils.capitalizeFully(s) };
} else {
return new String[] { WordUtils.capitalize(s) };
}
}
}

View File

@ -1,13 +1,13 @@
package me.TheBukor.SkStuff.pathfinders;
import me.TheBukor.SkStuff.util.ReflectionUtils;
import net.minecraft.server.v1_13_R2.*;
import java.lang.reflect.Field;
import java.util.LinkedHashSet;
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,7 +64,8 @@ public class PathfinderGoalFollow_v1_9_R1 extends PathfinderGoal {
return false;
}
}
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()
@ -72,6 +73,4 @@ public class PathfinderGoalFollow_v1_9_R1 extends PathfinderGoal {
public void c() {
follower.getNavigation().a(followed, speed); // a() means moveTo()
}
}

View File

@ -0,0 +1,79 @@
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;
public class PathfinderGoalFollow_v1_14_R1 extends PathfinderGoal {
private EntityCreature follower;
private EntityLiving followed;
private Class<?> followedClass;
private float radius;
private double speed;
private boolean isByName;
private String customName;
public PathfinderGoalFollow_v1_14_R1(EntityCreature follower, Class<?> followedClass, float radius, double speed, boolean isByName, String customName) {
this.follower = follower;
this.followedClass = followedClass;
this.radius = radius;
this.speed = speed;
this.isByName = isByName;
this.customName = customName;
}
// a() is shouldExecute()
@SuppressWarnings("unchecked")
@Override
public boolean a() {
if (followed == null) {
List<?> list = follower.world.a((Class<? extends Entity>) followedClass, follower.getBoundingBox().grow(radius, 4.0D, radius));
if (list.isEmpty()) {
return false;
}
if (isByName) {
for (Object entity : list) {
if (((EntityLiving) entity).getCustomName().equals(customName)) {
followed = (EntityLiving) entity;
return true;
}
}
} else {
followed = (EntityLiving) list.get(0);
return true;
}
}
return true;
}
// b() is shouldContinueExecuting()
@Override
public boolean b() {
if (followed.dead) {
followed = null;
return false;
} else if (followed.h(follower) < 9.0D || followed.h(follower) > Math.pow(radius, 2)) { // h() = distanceSquaredFrom()
return false; // if 3 blocks away or not in radius, stop moving.
//Maybe I'll add a teleport feature later.
} else if (isByName) {
if (!followed.getCustomName().equals(customName)) {
followed = null;
return false;
}
}
//return follower.getNavigation().n(); // n() means hasNoPath()
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()
}
}

View File

@ -1,13 +1,13 @@
package me.TheBukor.SkStuff.pathfinders;
import net.minecraft.server.v1_15_R1.Entity;
import net.minecraft.server.v1_15_R1.EntityCreature;
import net.minecraft.server.v1_15_R1.EntityLiving;
import net.minecraft.server.v1_15_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_15_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_15_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() {
public void c () {
follower.getNavigation().a(followed, speed); // a() means moveTo()
}
}
}

View File

@ -0,0 +1,79 @@
package me.TheBukor.SkStuff.pathfinders;
import net.minecraft.server.v1_16_R1.Entity;
import net.minecraft.server.v1_16_R1.EntityCreature;
import net.minecraft.server.v1_16_R1.EntityLiving;
import net.minecraft.server.v1_16_R1.PathfinderGoal;
import java.util.List;
public class PathfinderGoalFollow_v1_16_R1 extends PathfinderGoal {
private EntityCreature follower;
private EntityLiving followed;
private Class<?> followedClass;
private float radius;
private double speed;
private boolean isByName;
private String customName;
public PathfinderGoalFollow_v1_16_R1(EntityCreature follower, Class<?> followedClass, float radius, double speed, boolean isByName, String customName) {
this.follower = follower;
this.followedClass = followedClass;
this.radius = radius;
this.speed = speed;
this.isByName = isByName;
this.customName = customName;
}
// a() is shouldExecute()
@SuppressWarnings("unchecked")
@Override
public boolean a() {
if (followed == null) {
List<?> list = follower.world.a((Class<? extends Entity>) followedClass, follower.getBoundingBox().grow(radius, 4.0D, radius));
if (list.isEmpty()) {
return false;
}
if (isByName) {
for (Object entity : list) {
if (((EntityLiving) entity).getCustomName().equals(customName)) {
followed = (EntityLiving) entity;
return true;
}
}
} else {
followed = (EntityLiving) list.get(0);
return true;
}
}
return true;
}
// b() is shouldContinueExecuting()
@Override
public boolean b() {
if (followed.dead) {
followed = null;
return false;
} else if (followed.h(follower) < 9.0D || followed.h(follower) > Math.pow(radius, 2)) { // h() = distanceSquaredFrom()
return false; // if 3 blocks away or not in radius, stop moving.
//Maybe I'll add a teleport feature later.
} else if (isByName) {
if (!followed.getCustomName().equals(customName)) {
followed = null;
return false;
}
}
//return follower.getNavigation().n(); // n() means hasNoPath()
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()
}
}

View File

@ -1,39 +1,12 @@
package me.TheBukor.SkStuff.util;
import java.io.File;
import org.bukkit.Location;
import org.bukkit.block.Block;
import org.bukkit.entity.Entity;
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 +14,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);
@ -76,24 +21,6 @@ public interface NMSInterface {
public boolean getFireProof(Entity entity);
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);
public void setElytraGlideState(Entity entity, boolean glide);
public boolean getNoGravity(Entity entity);
public void setNoGravity(Entity entity, boolean noGravity);
}

View File

@ -1,238 +1,15 @@
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 net.minecraft.server.v1_10_R1.EntityInsentient;
import net.minecraft.server.v1_10_R1.PathfinderGoal;
import net.minecraft.server.v1_10_R1.PathfinderGoalSelector;
import org.bukkit.craftbukkit.v1_10_R1.entity.CraftEntity;
import org.bukkit.entity.Entity;
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();
@ -276,361 +53,6 @@ public class NMS_v1_10_R1 implements NMSInterface {
}
}
@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) {
@ -655,48 +77,6 @@ public class NMS_v1_10_R1 implements NMSInterface {
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();
@ -708,25 +88,4 @@ public class NMS_v1_10_R1 implements NMSInterface {
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);
}
}

View File

@ -1,238 +1,15 @@
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 net.minecraft.server.v1_11_R1.EntityInsentient;
import net.minecraft.server.v1_11_R1.PathfinderGoal;
import net.minecraft.server.v1_11_R1.PathfinderGoalSelector;
import org.bukkit.craftbukkit.v1_11_R1.entity.CraftEntity;
import org.bukkit.entity.Entity;
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();
@ -276,361 +53,6 @@ public class NMS_v1_11_R1 implements NMSInterface {
}
}
@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) {
@ -655,48 +77,6 @@ public class NMS_v1_11_R1 implements NMSInterface {
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();
@ -708,25 +88,4 @@ public class NMS_v1_11_R1 implements NMSInterface {
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);
}
}

Some files were not shown because too many files have changed in this diff Show More