list = new ArrayList<>();
+ for(Player players : Bukkit.getOnlinePlayers()) {
+ CustomPlayer p = CustomPlayer.getPlayer(players);
+ list.add(p);
+ }
+ return list;
+ }
+
+ /**
+ * @param level Log level
+ * @param string String
+ */
+ public static void log(Level level, String string) {
+ if(ServerSettings.isDebug()) {
+ log.log(level, "[univento Core] " + string);
+ }
+ }
+
+ @Override
+ public void onEnable() {
+ ServerSettings.setDebug(true);
+ try {
+ Config.writeDefault();
+ } catch (ClassNotFoundException | SQLException | IOException e) {
+ e.printStackTrace();
+ }
+ instance = this;
+ log(Level.INFO, "activated debug mode");
+ PluginManager pm = Bukkit.getPluginManager();
+ pm.registerEvents(new Commands(), this);
+ pm.registerEvents(new JoinQuit(), this);
+ pm.registerEvents(new Chat(), this);
+ pm.registerEvents(new Events(), this);
+ pm.registerEvents(new MoveEventFilter(getServer()), this);
+
+ if(ServerSettings.isGame()) {
+ new Fix(this, "fix", "fix");
+ new Stats(this, "stats", "statistics");
+ new Nick(this, "nick", "nick");
+ }else{
+ new Build(this, "build", "build", "b");
+ pm.registerEvents(new Blocks(), this);
+ }
+
+ new RunAs(this, "RunAs", "runas");
+ new SystemInfo(this, "SystemInfo", "systeminfo");
+ new Vanish(this, "vanish", "vanish");
+ new GameMode(this, "gamemode" , "gamemode", "gm");
+ new SetRank(this, "setrank" , "setrank", "sr");
+ new GlobalMute(this, "globalmute", "globalmute");
+ new TS(this, "ts", "ts");
+ new Ban(this, "ban", "ban");
+ new ChatClear(this, "chatclear", "chatclear", "cc");
+
+ log(Level.INFO, "registered all commands");
+
+ Bukkit.getMessenger().registerOutgoingPluginChannel(this, "BungeeCord");
+
+ Blackscreen.setupUtil(getInstance());
+ //mongoDB = new MongoDB(Config.readString("MongoDB.Host"), Config.readInt("MongoDB.Port"), Config.readString("MongoDB.Username"), Config.readString("MongoDB.Password"), Config.readString("MongoDB.Database"));
+
+
+ log(Level.INFO, "Plugin ver. " + getDescription().getVersion() + " started");
+ }
+
+ @Override
+ public void onDisable() {
+ log(Level.INFO, "Plugin stoped");
+ }
+
+}
\ No newline at end of file
diff --git a/src/eu/univento/core/api/Actionbar.java b/src/main/java/eu/univento/core/api/Actionbar.java
similarity index 53%
rename from src/eu/univento/core/api/Actionbar.java
rename to src/main/java/eu/univento/core/api/Actionbar.java
index 924b36d..3f71ce6 100644
--- a/src/eu/univento/core/api/Actionbar.java
+++ b/src/main/java/eu/univento/core/api/Actionbar.java
@@ -1,18 +1,18 @@
-package eu.univento.core.api;
-
-import net.minecraft.server.v1_8_R3.IChatBaseComponent;
-import net.minecraft.server.v1_8_R3.IChatBaseComponent.ChatSerializer;
-import net.minecraft.server.v1_8_R3.PacketPlayOutChat;
-import org.bukkit.craftbukkit.v1_8_R3.entity.CraftPlayer;
-import org.bukkit.entity.Player;
-
-public class Actionbar {
-
- public static void send(Player player, String message){
- CraftPlayer p = (CraftPlayer) player;
- IChatBaseComponent cbc = ChatSerializer.a("{\"text\": \"" + message + "\"}");
- PacketPlayOutChat ppoc = new PacketPlayOutChat(cbc,(byte) 2);
- ((CraftPlayer) p).getHandle().playerConnection.sendPacket(ppoc);
- }
-
-}
+package eu.univento.core.api;
+
+import net.minecraft.server.v1_9_R1.IChatBaseComponent;
+import net.minecraft.server.v1_9_R1.IChatBaseComponent.ChatSerializer;
+import net.minecraft.server.v1_9_R1.PacketPlayOutChat;
+import org.bukkit.craftbukkit.v1_9_R1.entity.CraftPlayer;
+import org.bukkit.entity.Player;
+
+public class Actionbar {
+
+ public static void send(Player player, String message){
+ CraftPlayer p = (CraftPlayer) player;
+ IChatBaseComponent cbc = ChatSerializer.a("{\"text\": \"" + message + "\"}");
+ PacketPlayOutChat ppoc = new PacketPlayOutChat(cbc,(byte) 2);
+ p.getHandle().playerConnection.sendPacket(ppoc);
+ }
+
+}
diff --git a/src/eu/univento/core/api/AutoCommand.java b/src/main/java/eu/univento/core/api/AutoCommand.java
similarity index 88%
rename from src/eu/univento/core/api/AutoCommand.java
rename to src/main/java/eu/univento/core/api/AutoCommand.java
index 2644456..6ce34b9 100644
--- a/src/eu/univento/core/api/AutoCommand.java
+++ b/src/main/java/eu/univento/core/api/AutoCommand.java
@@ -1,78 +1,77 @@
-package eu.univento.core.api;
-
-import org.bukkit.Bukkit;
-import org.bukkit.command.Command;
-import org.bukkit.command.CommandMap;
-import org.bukkit.command.CommandSender;
-import org.bukkit.plugin.java.JavaPlugin;
-
-import java.lang.reflect.Field;
-import java.util.ArrayList;
-import java.util.List;
-
-/**
- * @author PostCrafter
- * @see href http://postcrafter.de/viewtopic.php?f=15&t=143
- * @param main class
- */
-public abstract class AutoCommand
extends Command {
-
- private static String VERSION;
-
- static {
- String path = Bukkit.getServer().getClass().getPackage().getName();
-
- AutoCommand.VERSION = path.substring(path.lastIndexOf(".") + 1, path.length());
-
- System.out.println("[PostLib] AutoCommand hook for Bukkit " + AutoCommand.VERSION);
- }
-
- protected final P plugin;
- protected final String command;
-
- public AutoCommand(P plugin, String command, String description, String... aliases) {
- super(command);
- this.plugin = plugin;
- this.command = command;
-
- super.setDescription(description);
- List aliasList = new ArrayList();
- for (String alias : aliases) {
- aliasList.add(alias);
- }
- super.setAliases(aliasList);
-
- this.register();
- }
-
- public void register() {
- try {
- Field f = Class.forName("org.bukkit.craftbukkit." + AutoCommand.VERSION + ".CraftServer").getDeclaredField("commandMap");
- f.setAccessible(true);
-
- CommandMap map = (CommandMap) f.get(Bukkit.getServer());
- map.register(this.plugin.getName(), this);
- } catch (Exception exc) {
- exc.printStackTrace();
- }
- }
-
- public abstract boolean execute(CommandSender sender, String label, String[] args);
-
- public abstract List tabComplete(CommandSender sender, String label, String[] args);
-
- public String buildString(String[] args, int start) {
- String str = "";
- if (args.length > start) {
- str += args[start];
- for (int i = start + 1; i < args.length; i++) {
- str += " " + args[i];
- }
- }
- return str;
- }
-
- public P getPlugin() {
- return this.plugin;
- }
-}
+package eu.univento.core.api;
+
+import eu.univento.core.Core;
+import org.bukkit.Bukkit;
+import org.bukkit.command.Command;
+import org.bukkit.command.CommandMap;
+import org.bukkit.command.CommandSender;
+import org.bukkit.plugin.java.JavaPlugin;
+
+import java.lang.reflect.Field;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.logging.Level;
+
+/**
+ * @author PostCrafter
+ * @see href http://postcrafter.de/viewtopic.php?f=15&t=143
+ * @param main class
+ */
+public abstract class AutoCommand
extends Command {
+
+ private static String VERSION;
+
+ static {
+ String path = Bukkit.getServer().getClass().getPackage().getName();
+ AutoCommand.VERSION = path.substring(path.lastIndexOf(".") + 1, path.length());
+ Core.log(Level.INFO, "AutoCommand hook for Bukkit " + AutoCommand.VERSION);
+ }
+
+ protected final P plugin;
+ protected final String command;
+
+ public AutoCommand(P plugin, String command, String description, String... aliases) {
+ super(command);
+ this.plugin = plugin;
+ this.command = command;
+
+ super.setDescription(description);
+ List aliasList = new ArrayList<>();
+ for (String alias : aliases) {
+ aliasList.add(alias);
+ }
+ super.setAliases(aliasList);
+ this.register();
+ }
+
+ private void register() {
+ try {
+ Field f = Class.forName("org.bukkit.craftbukkit." + AutoCommand.VERSION + ".CraftServer").getDeclaredField("commandMap");
+ f.setAccessible(true);
+
+ CommandMap map = (CommandMap) f.get(Bukkit.getServer());
+ map.register(this.plugin.getName(), this);
+ } catch (Exception exc) {
+ exc.printStackTrace();
+ }
+ }
+
+ public abstract boolean execute(CommandSender sender, String label, String[] args);
+
+ public abstract List tabComplete(CommandSender sender, String label, String[] args);
+
+ public String buildString(String[] args, int start) {
+ String str = "";
+ if (args.length > start) {
+ str += args[start];
+ for (int i = start + 1; i < args.length; i++) {
+ str += " " + args[i];
+ }
+ }
+ return str;
+ }
+
+ public P getPlugin() {
+ return this.plugin;
+ }
+}
diff --git a/src/eu/univento/core/api/Blackscreen.java b/src/main/java/eu/univento/core/api/Blackscreen.java
similarity index 72%
rename from src/eu/univento/core/api/Blackscreen.java
rename to src/main/java/eu/univento/core/api/Blackscreen.java
index acad260..7091575 100644
--- a/src/eu/univento/core/api/Blackscreen.java
+++ b/src/main/java/eu/univento/core/api/Blackscreen.java
@@ -1,85 +1,80 @@
-package eu.univento.core.api;
-
-import org.bukkit.Bukkit;
-import org.bukkit.entity.Player;
-import org.bukkit.plugin.Plugin;
-
-import java.lang.reflect.Field;
-import java.lang.reflect.Method;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.UUID;
-
-/**
- *
- * @author janhektor
- *
- */
-public class Blackscreen
-{
- private static Object packetObject;
- private static Class> packetClass;
- private static String VERSION;
- private static Map ticksLeft = new HashMap();
-
- static { String path = Bukkit.getServer().getClass().getPackage().getName();
- VERSION = path.substring(path.lastIndexOf(".") + 1, path.length());
- try {
- packetClass = Class.forName("net.minecraft.server." + VERSION + ".Packet");
- Class> packetGameStateClass = Class.forName("net.minecraft.server." + VERSION + ".PacketPlayOutGameStateChange");
- packetObject = packetGameStateClass.getConstructor(new Class[] { Integer.TYPE, Float.TYPE }).newInstance(new Object[] { Integer.valueOf(4), Integer.valueOf(0) });
- } catch (Exception ex) {
- ex.printStackTrace();
- }
- }
-
- public static void setupUtil(Plugin instance)
- {
- setupUtil(instance, 2);
- }
-
- public static void setupUtil(Plugin instance, int repeatingTicks)
- {
- Bukkit.getScheduler().runTaskTimer(instance, new Runnable()
- {
- public void run()
- {
- for (UUID uuid : Blackscreen.ticksLeft.keySet()) {
- Player p = Bukkit.getPlayer(uuid);
- if (p == null) {
- Blackscreen.ticksLeft.remove(uuid);
- }
- else if (((Integer)Blackscreen.ticksLeft.get(uuid)).intValue() > 0) {
- Blackscreen.ticksLeft.put(uuid, Integer.valueOf(((Integer)Blackscreen.ticksLeft.get(uuid)).intValue() - 2));
- Blackscreen.access(p);
- } else {
- Blackscreen.ticksLeft.remove(uuid);
- }
- }
- }
- }
- , 0L, repeatingTicks);
- }
-
- protected static void access(Player p) {
-
-}
-
-private static void sendPacket(Player p) {
- try {
- Object nmsPlayer = p.getClass().getMethod("getHandle", new Class[0]).invoke(p, new Object[0]);
- Field playerConnectionField = nmsPlayer.getClass().getField("playerConnection");
- Object pConnection = playerConnectionField.get(nmsPlayer);
- Method sendPacket = pConnection.getClass().getMethod("sendPacket", new Class[] { packetClass });
- sendPacket.invoke(pConnection, new Object[] { packetObject });
- } catch (Exception ex) {
- ex.printStackTrace();
- }
- }
-
- public static void setBlack(Player p, int seconds)
- {
- ticksLeft.put(p.getUniqueId(), Integer.valueOf(seconds * 20));
- sendPacket(p);
- }
+package eu.univento.core.api;
+
+import org.bukkit.Bukkit;
+import org.bukkit.entity.Player;
+import org.bukkit.plugin.Plugin;
+
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.UUID;
+
+/**
+ *
+ * @author janhektor
+ *
+ */
+public class Blackscreen {
+ private static Object packetObject;
+ private static Class> packetClass;
+ private static String VERSION;
+ private static Map ticksLeft = new HashMap();
+
+ static { String path = Bukkit.getServer().getClass().getPackage().getName();
+ VERSION = path.substring(path.lastIndexOf(".") + 1, path.length());
+ try {
+ packetClass = Class.forName("net.minecraft.server." + VERSION + ".Packet");
+ Class> packetGameStateClass = Class.forName("net.minecraft.server." + VERSION + ".PacketPlayOutGameStateChange");
+ packetObject = packetGameStateClass.getConstructor(new Class[] { Integer.TYPE, Float.TYPE }).newInstance(new Object[] { Integer.valueOf(4), Integer.valueOf(0) });
+ } catch (Exception ex) {
+ ex.printStackTrace();
+ }
+ }
+
+ public static void setupUtil(Plugin instance)
+ {
+ setupUtil(instance, 2);
+ }
+
+ public static void setupUtil(Plugin instance, int repeatingTicks)
+ {
+ Bukkit.getScheduler().runTaskTimer(instance, () -> {
+ for (UUID uuid : Blackscreen.ticksLeft.keySet()) {
+ Player p = Bukkit.getPlayer(uuid);
+ if (p == null) {
+ Blackscreen.ticksLeft.remove(uuid);
+ }
+ else if (((Integer)Blackscreen.ticksLeft.get(uuid)).intValue() > 0) {
+ Blackscreen.ticksLeft.put(uuid, Integer.valueOf((Blackscreen.ticksLeft.get(uuid)).intValue() - 2));
+ Blackscreen.access(p);
+ } else {
+ Blackscreen.ticksLeft.remove(uuid);
+ }
+ }
+ }
+ , 0L, repeatingTicks);
+ }
+
+ protected static void access(Player p) {
+
+}
+
+private static void sendPacket(Player p) {
+ try {
+ Object nmsPlayer = p.getClass().getMethod("getHandle", new Class[0]).invoke(p, new Object[0]);
+ Field playerConnectionField = nmsPlayer.getClass().getField("playerConnection");
+ Object pConnection = playerConnectionField.get(nmsPlayer);
+ Method sendPacket = pConnection.getClass().getMethod("sendPacket", new Class[] { packetClass });
+ sendPacket.invoke(pConnection, new Object[] { packetObject });
+ } catch (Exception ex) {
+ ex.printStackTrace();
+ }
+ }
+
+ public static void setBlack(Player p, int seconds)
+ {
+ ticksLeft.put(p.getUniqueId(), Integer.valueOf(seconds * 20));
+ sendPacket(p);
+ }
}
\ No newline at end of file
diff --git a/src/eu/univento/core/api/Config.java b/src/main/java/eu/univento/core/api/Config.java
similarity index 93%
rename from src/eu/univento/core/api/Config.java
rename to src/main/java/eu/univento/core/api/Config.java
index db310da..ae6574b 100644
--- a/src/eu/univento/core/api/Config.java
+++ b/src/main/java/eu/univento/core/api/Config.java
@@ -1,172 +1,171 @@
-package eu.univento.core.api;
-
-import org.bukkit.Bukkit;
-import org.bukkit.Location;
-import org.bukkit.configuration.file.FileConfiguration;
-import org.bukkit.configuration.file.YamlConfiguration;
-
-import java.io.File;
-import java.io.IOException;
-import java.sql.SQLException;
-
-/**
- * gets data from config file
- * @author joethei
- * @version 1.1
- */
-public class Config {
-
- /**config file*/
- private static File file = new File("plugins/Core", "config.yml");
- /**load configuration */
- private static FileConfiguration cfg = YamlConfiguration.loadConfiguration(file);
-
- /**
- * write default data to config
- * @throws ClassNotFoundException Class couldn't be found
- * @throws SQLException SQL server not available or throwing error
- * @throws IOException I/O failed
- */
- public static void writeDefault() throws ClassNotFoundException, SQLException, IOException {
- //editable messages will be set here, but do not edit this messages.
-
- //seting the default MySQL config.
- cfg.addDefault("MySQL.Host", "192.168.0.101");
- cfg.addDefault("MySQL.Port", "3306");
- cfg.addDefault("MySQL.DB", "core");
- cfg.addDefault("MySQL.User", "root");//best user name
- cfg.addDefault("MySQL.Pass", "");//best password
- cfg.addDefault("TS.IP", "ts.univento.eu");
- cfg.addDefault("TS.QueryPort", 0);
- cfg.addDefault("TS.QueryUser", "ServerQuery");
- cfg.addDefault("TS.QueryPass", "password");
-
- cfg.options().copyDefaults(true);
- cfg.save(file);
-
- }
-
- /**
- * write data as string to config
- * @param path path to data
- * @param obj data
- */
- public static void write(String path, String obj) {
- cfg.set(path, obj);
- try {
- cfg.save(file);
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
-
- /**
- * write data as integer to config
- * @param path path to data
- * @param obj data
- */
- public static void write(String path, int obj) {
- cfg.set(path, obj);
- try {
- cfg.save(file);
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
-
- /**
- * write data as double to config
- * @param path path to data
- * @param obj data
- */
- public static void write(String path, double obj) {
- cfg.set(path, obj);
- try {
- cfg.save(file);
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
-
-
- /**
- * write location to config
- * @param path path to data
- * @param loc location
- */
- public static void write(String path, Location loc) {
- String world = loc.getWorld().getName();
- double x = loc.getX();
- double y = loc.getY();
- double z = loc.getZ();
- double yaw = (double) loc.getYaw();
- double pitch = (double) loc.getPitch();
-
- cfg.set(path + ".World", world);
- cfg.set(path + ".X", x);
- cfg.set(path + ".Y", y);
- cfg.set(path + ".Z", z);
- cfg.set(path + ".Yaw", yaw);
- cfg.set(path + ".Pitch", pitch);
-
- try {
- cfg.save(file);
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
-
- /**
- * read integer from config
- * @param path path to data
- * @return Integer
- */
- public static int readInt(String path) {
- return cfg.getInt(path);
- }
-
- /**
- * read double from config
- * @param path path to data
- * @return Double
- */
- public static double readDouble(String path) {
- return cfg.getDouble(path);
- }
-
- /**
- * read string from config
- * @param path path to data
- * @return String
- */
- public static String readString(String path) {
- return cfg.getString(path);
- }
-
- /**
- * read location from config
- * @param path path to data
- * @return Location
- */
- public static Location readLocation(String path) {
- String world = cfg.getString(path + ".World");
- double x = cfg.getDouble(path + ".X");
- double y = cfg.getDouble(path + ".Y");
- double z = cfg.getDouble(path + ".Z");
- float yaw = (float) cfg.getDouble(path + ".Yaw");
- float pitch = (float) cfg.getDouble(path + ".Pitch");
-
- Location loc = new Location(Bukkit.getWorld(world), x, y, z, yaw, pitch);
- return loc;
- }
-
- /**
- * checks if data is existing
- * @param path path do data
- * @return true / false
- */
- public static boolean isExsisting(String path) {
- return cfg.contains(path);
- }
-
+package eu.univento.core.api;
+
+import org.bukkit.Bukkit;
+import org.bukkit.Location;
+import org.bukkit.configuration.file.FileConfiguration;
+import org.bukkit.configuration.file.YamlConfiguration;
+
+import java.io.File;
+import java.io.IOException;
+import java.sql.SQLException;
+
+/**
+ * gets data from config file
+ * @author joethei
+ * @version 1.1
+ */
+public class Config {
+
+ /**config file*/
+ private static File file = new File("plugins/Core", "config.yml");
+ /**load configuration */
+ private static FileConfiguration cfg = YamlConfiguration.loadConfiguration(file);
+
+ /**
+ * write default data to config
+ * @throws ClassNotFoundException Class couldn't be found
+ * @throws SQLException SQL server not available or throwing error
+ * @throws IOException I/O failed
+ */
+ public static void writeDefault() throws ClassNotFoundException, SQLException, IOException {
+ //editable messages will be set here, but do not edit this messages.
+
+ //seting the default MySQL config.
+ cfg.addDefault("MySQL.Host", "192.168.0.101");
+ cfg.addDefault("MySQL.Port", "3306");
+ cfg.addDefault("MySQL.DB", "core");
+ cfg.addDefault("MySQL.User", "root");//best user name
+ cfg.addDefault("MySQL.Pass", "");//best password
+ cfg.addDefault("TS.IP", "ts.univento.eu");
+ cfg.addDefault("TS.QueryPort", 0);
+ cfg.addDefault("TS.QueryUser", "ServerQuery");
+ cfg.addDefault("TS.QueryPass", "password");
+
+ cfg.options().copyDefaults(true);
+ cfg.save(file);
+
+ }
+
+ /**
+ * write data as string to config
+ * @param path path to data
+ * @param obj data
+ */
+ public static void write(String path, String obj) {
+ cfg.set(path, obj);
+ try {
+ cfg.save(file);
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+
+ /**
+ * write data as integer to config
+ * @param path path to data
+ * @param obj data
+ */
+ public static void write(String path, int obj) {
+ cfg.set(path, obj);
+ try {
+ cfg.save(file);
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+
+ /**
+ * write data as double to config
+ * @param path path to data
+ * @param obj data
+ */
+ public static void write(String path, double obj) {
+ cfg.set(path, obj);
+ try {
+ cfg.save(file);
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+
+
+ /**
+ * write location to config
+ * @param path path to data
+ * @param loc location
+ */
+ public static void write(String path, Location loc) {
+ String world = loc.getWorld().getName();
+ double x = loc.getX();
+ double y = loc.getY();
+ double z = loc.getZ();
+ double yaw = (double) loc.getYaw();
+ double pitch = (double) loc.getPitch();
+
+ cfg.set(path + ".World", world);
+ cfg.set(path + ".X", x);
+ cfg.set(path + ".Y", y);
+ cfg.set(path + ".Z", z);
+ cfg.set(path + ".Yaw", yaw);
+ cfg.set(path + ".Pitch", pitch);
+
+ try {
+ cfg.save(file);
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+
+ /**
+ * read integer from config
+ * @param path path to data
+ * @return Integer
+ */
+ public static int readInt(String path) {
+ return cfg.getInt(path);
+ }
+
+ /**
+ * read double from config
+ * @param path path to data
+ * @return Double
+ */
+ public static double readDouble(String path) {
+ return cfg.getDouble(path);
+ }
+
+ /**
+ * read string from config
+ * @param path path to data
+ * @return String
+ */
+ public static String readString(String path) {
+ return cfg.getString(path);
+ }
+
+ /**
+ * read location from config
+ * @param path path to data
+ * @return Location
+ */
+ public static Location readLocation(String path) {
+ String world = cfg.getString(path + ".World");
+ double x = cfg.getDouble(path + ".X");
+ double y = cfg.getDouble(path + ".Y");
+ double z = cfg.getDouble(path + ".Z");
+ float yaw = (float) cfg.getDouble(path + ".Yaw");
+ float pitch = (float) cfg.getDouble(path + ".Pitch");
+
+ return new Location(Bukkit.getWorld(world), x, y, z, yaw, pitch);
+ }
+
+ /**
+ * checks if data is existing
+ * @param path path do data
+ * @return true / false
+ */
+ public static boolean isExsisting(String path) {
+ return cfg.contains(path);
+ }
+
}
\ No newline at end of file
diff --git a/src/main/java/eu/univento/core/api/Hologram.java b/src/main/java/eu/univento/core/api/Hologram.java
new file mode 100644
index 0000000..5fcf3bc
--- /dev/null
+++ b/src/main/java/eu/univento/core/api/Hologram.java
@@ -0,0 +1,93 @@
+package eu.univento.core.api;
+
+import eu.univento.core.Core;
+import net.minecraft.server.v1_9_R1.EntityArmorStand;
+import net.minecraft.server.v1_9_R1.PacketPlayOutEntityDestroy;
+import net.minecraft.server.v1_9_R1.PacketPlayOutSpawnEntityLiving;
+import org.bukkit.Bukkit;
+import org.bukkit.Location;
+import org.bukkit.craftbukkit.v1_9_R1.CraftWorld;
+import org.bukkit.craftbukkit.v1_9_R1.entity.CraftPlayer;
+import org.bukkit.entity.Player;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public class Hologram {
+
+ private List entitylist = new ArrayList<>();
+ private String[] Text;
+ private Location location;
+ double DISTANCE = 0.25D;
+ int count;
+
+ public Hologram(String[] Text, Location location) {
+ this.Text = Text;
+ this.location = location;
+ create();
+ }
+
+
+ public void showPlayerTemp(final Player p,int Time){
+ showPlayer(p);
+ Bukkit.getScheduler().runTaskLater(Core.getInstance(), () -> hidePlayer(p), Time);
+ }
+
+
+ public void showAllTemp(final Player p,int Time){
+ showAll();
+ Bukkit.getScheduler().runTaskLater(Core.getInstance(), () -> hideAll(), Time);
+ }
+
+ public void showPlayer(Player p) {
+ for (EntityArmorStand armor : entitylist) {
+ PacketPlayOutSpawnEntityLiving packet = new PacketPlayOutSpawnEntityLiving(armor);
+ ((CraftPlayer) p).getHandle().playerConnection.sendPacket(packet);
+ }
+ }
+
+ public void hidePlayer(Player p) {
+ for (EntityArmorStand armor : entitylist) {
+ PacketPlayOutEntityDestroy packet = new PacketPlayOutEntityDestroy(armor.getId());
+ ((CraftPlayer) p).getHandle().playerConnection.sendPacket(packet);
+
+ }
+ }
+
+ public void showAll() {
+ for (Player player : Bukkit.getOnlinePlayers()) {
+ for (EntityArmorStand armor : entitylist) {
+ PacketPlayOutSpawnEntityLiving packet = new PacketPlayOutSpawnEntityLiving(armor);
+ ((CraftPlayer) player).getHandle().playerConnection.sendPacket(packet);
+ }
+ }
+ }
+
+ public void hideAll() {
+ for (Player player : Bukkit.getOnlinePlayers()) {
+ for (EntityArmorStand armor : entitylist) {
+ PacketPlayOutEntityDestroy packet = new PacketPlayOutEntityDestroy(armor.getId());
+ ((CraftPlayer) player).getHandle().playerConnection.sendPacket(packet);
+ }
+ }
+ }
+
+ private void create() {
+ for (String Text : this.Text) {
+ EntityArmorStand entity = new EntityArmorStand(((CraftWorld) this.location.getWorld()).getHandle(),this.location.getX(), this.location.getY(),this.location.getZ());
+ entity.setCustomName(Text);
+ entity.setCustomNameVisible(true);
+ entity.setInvisible(true);
+ entity.setGravity(false);
+ entitylist.add(entity);
+ this.location.subtract(0, this.DISTANCE, 0);
+ count++;
+ }
+
+ for (int i = 0; i < count; i++) {
+ this.location.add(0, this.DISTANCE, 0);
+ }
+ this.count = 0;
+ }
+
+}
\ No newline at end of file
diff --git a/src/eu/univento/core/api/Title.java b/src/main/java/eu/univento/core/api/Title.java
similarity index 79%
rename from src/eu/univento/core/api/Title.java
rename to src/main/java/eu/univento/core/api/Title.java
index 350bd56..81f9db1 100644
--- a/src/eu/univento/core/api/Title.java
+++ b/src/main/java/eu/univento/core/api/Title.java
@@ -1,99 +1,85 @@
-package eu.univento.core.api;
-
-import net.minecraft.server.v1_8_R3.IChatBaseComponent;
-import net.minecraft.server.v1_8_R3.PacketPlayOutPlayerListHeaderFooter;
-import net.minecraft.server.v1_8_R3.PacketPlayOutTitle;
-import net.minecraft.server.v1_8_R3.PlayerConnection;
-import org.bukkit.ChatColor;
-import org.bukkit.craftbukkit.v1_8_R3.entity.CraftPlayer;
-import org.bukkit.entity.Player;
-
-import java.lang.reflect.Field;
-
-//TODO: find real author, its not me
-/**
- * sends title to player
- * @author joethei
- * @version 1.0
- */
-public class Title {
-
- /**
- * send title to player
- * @param player Player
- * @param fadeIn Integer
- * @param stay Integer
- * @param fadeOut Integer
- * @param title String
- * @param subtitle String
- */
- public static void sendTitle(Player player, Integer fadeIn, Integer stay, Integer fadeOut, String title, String subtitle) {
- PlayerConnection connection = ((CraftPlayer) player).getHandle().playerConnection;
-
- PacketPlayOutTitle packetPlayOutTimes = new PacketPlayOutTitle(PacketPlayOutTitle.EnumTitleAction.TIMES, null, fadeIn.intValue(), stay.intValue(), fadeOut.intValue());
- connection.sendPacket(packetPlayOutTimes);
-
- if (subtitle != null) {
- subtitle = subtitle.replaceAll("%player%", player.getDisplayName());
- subtitle = ChatColor.translateAlternateColorCodes('&', subtitle);
- IChatBaseComponent titleSub = IChatBaseComponent.ChatSerializer.a("{\"text\": \"" + subtitle + "\"}");
- PacketPlayOutTitle packetPlayOutSubTitle = new PacketPlayOutTitle(PacketPlayOutTitle.EnumTitleAction.SUBTITLE, titleSub);
- connection.sendPacket(packetPlayOutSubTitle);
- }
-
- if (title != null) {
- title = title.replaceAll("%player%", player.getDisplayName());
- title = ChatColor.translateAlternateColorCodes('&', title);
- IChatBaseComponent titleMain = IChatBaseComponent.ChatSerializer.a("{\"text\": \"" + title + "\"}");
- PacketPlayOutTitle packetPlayOutTitle = new PacketPlayOutTitle(PacketPlayOutTitle.EnumTitleAction.TITLE, titleMain);
- connection.sendPacket(packetPlayOutTitle);
- }
- }
-
- /**
- * sends tab title to player
- * @param player Player
- * @param header String
- * @param footer String
- */
- public static void sendTabTitle(Player player, String header, String footer) {
- if (header == null)
- header = "";
- header = ChatColor.translateAlternateColorCodes('&', header);
-
- if (footer == null)
- footer = "";
- footer = ChatColor.translateAlternateColorCodes('&', footer);
-
- header = header.replaceAll("%player%", player.getDisplayName());
- footer = footer.replaceAll("%player%", player.getDisplayName());
-
- PlayerConnection connection = ((CraftPlayer) player).getHandle().playerConnection;
- IChatBaseComponent tabTitle = IChatBaseComponent.ChatSerializer.a("{\"text\": \"" + header + "\"}");
- IChatBaseComponent tabFoot = IChatBaseComponent.ChatSerializer.a("{\"text\": \"" + footer + "\"}");
- PacketPlayOutPlayerListHeaderFooter headerPacket = new PacketPlayOutPlayerListHeaderFooter(tabTitle);
- try {
- Field field = headerPacket.getClass().getDeclaredField("b");
- field.setAccessible(true);
- field.set(headerPacket, tabFoot);
- } catch (Exception e) {
- e.printStackTrace();
- } finally {
- connection.sendPacket(headerPacket);
- }
- }
-
- /**
- * checks if String is integer
- * @param s String
- * @return boolean
- */
- boolean isInteger(String s) {
- try {
- Integer.parseInt(s);
- } catch (NumberFormatException e) {
- return false;
- }
- return true;
- }
+package eu.univento.core.api;
+
+import net.minecraft.server.v1_9_R1.IChatBaseComponent;
+import net.minecraft.server.v1_9_R1.PacketPlayOutPlayerListHeaderFooter;
+import net.minecraft.server.v1_9_R1.PacketPlayOutTitle;
+import net.minecraft.server.v1_9_R1.PlayerConnection;
+import org.bukkit.ChatColor;
+import org.bukkit.craftbukkit.v1_9_R1.entity.CraftPlayer;
+import org.bukkit.entity.Player;
+
+import java.lang.reflect.Field;
+
+//TODO: find real author, its not me
+/**
+ * sends title to player
+ * @author joethei
+ * @version 1.0
+ */
+public class Title {
+
+ /**
+ * send title to player
+ * @param player Player
+ * @param fadeIn Integer
+ * @param stay Integer
+ * @param fadeOut Integer
+ * @param title String
+ * @param subtitle String
+ */
+ public static void sendTitle(Player player, Integer fadeIn, Integer stay, Integer fadeOut, String title, String subtitle) {
+ PlayerConnection connection = ((CraftPlayer) player).getHandle().playerConnection;
+
+ PacketPlayOutTitle packetPlayOutTimes = new PacketPlayOutTitle(PacketPlayOutTitle.EnumTitleAction.TIMES, null, fadeIn, stay, fadeOut);
+ connection.sendPacket(packetPlayOutTimes);
+
+ if (subtitle != null) {
+ subtitle = subtitle.replaceAll("%player%", player.getDisplayName());
+ subtitle = ChatColor.translateAlternateColorCodes('&', subtitle);
+ IChatBaseComponent titleSub = IChatBaseComponent.ChatSerializer.a("{\"text\": \"" + subtitle + "\"}");
+ PacketPlayOutTitle packetPlayOutSubTitle = new PacketPlayOutTitle(PacketPlayOutTitle.EnumTitleAction.SUBTITLE, titleSub);
+ connection.sendPacket(packetPlayOutSubTitle);
+ }
+
+ if (title != null) {
+ title = title.replaceAll("%player%", player.getDisplayName());
+ title = ChatColor.translateAlternateColorCodes('&', title);
+ IChatBaseComponent titleMain = IChatBaseComponent.ChatSerializer.a("{\"text\": \"" + title + "\"}");
+ PacketPlayOutTitle packetPlayOutTitle = new PacketPlayOutTitle(PacketPlayOutTitle.EnumTitleAction.TITLE, titleMain);
+ connection.sendPacket(packetPlayOutTitle);
+ }
+ }
+
+ /**
+ * sends tab title to player
+ * @param player Player
+ * @param header String
+ * @param footer String
+ */
+ public static void sendTabTitle(Player player, String header, String footer) {
+ if (header == null)
+ header = "";
+ header = ChatColor.translateAlternateColorCodes('&', header);
+
+ if (footer == null)
+ footer = "";
+ footer = ChatColor.translateAlternateColorCodes('&', footer);
+
+ header = header.replaceAll("%player%", player.getDisplayName());
+ footer = footer.replaceAll("%player%", player.getDisplayName());
+
+ PlayerConnection connection = ((CraftPlayer) player).getHandle().playerConnection;
+ IChatBaseComponent tabTitle = IChatBaseComponent.ChatSerializer.a("{\"text\": \"" + header + "\"}");
+ IChatBaseComponent tabFoot = IChatBaseComponent.ChatSerializer.a("{\"text\": \"" + footer + "\"}");
+ PacketPlayOutPlayerListHeaderFooter headerPacket = new PacketPlayOutPlayerListHeaderFooter(tabTitle);
+ try {
+ Field field = headerPacket.getClass().getDeclaredField("b");
+ field.setAccessible(true);
+ field.set(headerPacket, tabFoot);
+ } catch (Exception e) {
+ e.printStackTrace();
+ } finally {
+ connection.sendPacket(headerPacket);
+ }
+ }
}
\ No newline at end of file
diff --git a/src/eu/univento/core/api/Utils.java b/src/main/java/eu/univento/core/api/Utils.java
similarity index 88%
rename from src/eu/univento/core/api/Utils.java
rename to src/main/java/eu/univento/core/api/Utils.java
index b05e365..a6885fe 100644
--- a/src/eu/univento/core/api/Utils.java
+++ b/src/main/java/eu/univento/core/api/Utils.java
@@ -1,179 +1,176 @@
-package eu.univento.core.api;
-
-import eu.univento.core.Core;
-import org.bukkit.*;
-import org.bukkit.entity.Entity;
-import org.bukkit.entity.Player;
-import org.bukkit.inventory.ItemStack;
-import org.bukkit.potion.PotionEffect;
-import org.bukkit.util.Vector;
-
-import java.io.File;
-import java.util.List;
-
-/**
- * some utils you may need
- * @author joethei
- * @version 1.0
- */
-public class Utils {
-
- /**
- * plays sound for all players
- * @param s Sound
- */
- public static void playSoundToAll(Sound s) {
- for (Player all : Bukkit.getOnlinePlayers())
- all.playSound(all.getLocation(), s, 3.0F, 3.0F);
- }
-
- /**
- * plays effect for all players
- * @param e Effect
- */
- @SuppressWarnings("deprecation")
- public static void playEffectToAll(Effect e) {
- for (Player all : Bukkit.getOnlinePlayers())
- all.playEffect(all.getLocation(), e, 3);
- }
-
- /**
- * checks if server version is from spigot
- * @return true/false
- */
- public static boolean isSpigot() {
- return Bukkit.getVersion().contains("Spigot");
- }
-
- /**
- * deletes all folders and files in directory
- * @param file File
- */
- public static void deleteDir(File file) {
- if (file.isDirectory()) {
- if (file.list().length == 0) {
- file.delete();
- } else {
- String[] files = file.list();
- for (String tmp : files) {
- File fileDelete = new File(file, tmp);
- deleteDir(fileDelete);
- }
- if (file.list().length == 0)
- file.delete();
- }
- } else
- file.delete();
- }
-
- /**
- * creates a random number
- * @param low lowest possible value
- * @param high highest possible value
- * @return double
- */
- public static double random(int low, int high) {
- return Math.random() * (high - low) + low;
- }
-
- /**
- * checks if player has empty inventory
- * @param p Player
- * @return true/false
- */
- public static boolean hasEmptyInventory(Player p) {
- for (ItemStack item : p.getInventory().getContents()) {
- if ((item != null) && (item.getType() != Material.AIR))
- return false;
- }
- for (ItemStack item : p.getInventory().getArmorContents()) {
- if ((item != null) && (item.getType() != Material.AIR))
- return false;
- }
- return true;
- }
-
-
- /**
- * removes list of entity and counts them
- * @param e List
- * @return Integer
- */
- public static int removeEntitys(List e) {
- int i = 0;
- for (Entity en : e) {
- en.remove();
- i++;
- }
- return i;
- }
-
- /**
- * clears all potion effects from player
- * @param player Player
- */
- public static void clearPotionEffects(Player player) {
- for (PotionEffect effect : player.getActivePotionEffects())
- player.removePotionEffect(effect.getType());
- }
-
- /**
- * calculates vector from one location to another
- * @param from Location
- * @param to Location
- * @return Vector
- */
- public static Vector calculateVector(Location from, Location to) {
- Location a = from, b = to;
-
- // calculate the distance between the locations (a => from || b => to)
- double dX = a.getX() - b.getX();
- double dY = a.getY() - b.getY();
- double dZ = a.getZ() - b.getZ();
- // -------------------------
-
- // calculate the yaw
- double yaw = Math.atan2(dZ, dX);
- // -------------------------
-
- // calculate the pitch
- double pitch = Math.atan2(Math.sqrt(dZ * dZ + dX * dX), dY) + Math.PI;
- // -------------------------
-
- // calculate and create the new vector
- double x = Math.sin(pitch) * Math.cos(yaw);
- double y = Math.sin(pitch) * Math.sin(yaw);
- double z = Math.cos(pitch);
-
- Vector vector = new Vector(x, z, y);
- // -------------------------
-
- return vector;
- }
-
- /**
- * restarts server
- */
- public static void restart() {
- Bukkit.getScheduler().scheduleSyncDelayedTask(Core.getInstance(), new Runnable() {
-
- @Override
- public void run() {
- Bukkit.getServer().spigot().restart();
- }
-
- }, 10 * 20L);
- }
-
- /**
- * shots random firework at specified location
- * @param loc Location
- */
- public static void randomFirework(Location loc) {
- FireworkEffect.Builder builder = FireworkEffect.builder();
- FireworkEffect effect = builder.flicker(false).trail(false).with(FireworkEffect.Type.BALL_LARGE).withColor(Color.RED).withFade(Color.BLUE).build();
- //TODO: make a random fireworks effect
- //TODO: remove effect.toString(), its only to remove unused warnings
- effect.toString();
- }
+package eu.univento.core.api;
+
+import eu.univento.core.Core;
+import org.bukkit.*;
+import org.bukkit.entity.Entity;
+import org.bukkit.entity.Player;
+import org.bukkit.inventory.ItemStack;
+import org.bukkit.potion.PotionEffect;
+import org.bukkit.util.Vector;
+
+import java.io.File;
+import java.util.List;
+
+/**
+ * some utils you may need
+ * @author joethei
+ * @version 1.0
+ */
+public class Utils {
+
+ /**
+ * plays sound for all players
+ * @param s Sound
+ */
+ public static void playSoundToAll(Sound s) {
+ for (Player all : Bukkit.getOnlinePlayers())
+ all.playSound(all.getLocation(), s, 3.0F, 3.0F);
+ }
+
+ /**
+ * plays effect for all players
+ * @param e Effect
+ */
+ @SuppressWarnings("deprecation")
+ public static void playEffectToAll(Effect e) {
+ for (Player all : Bukkit.getOnlinePlayers())
+ all.playEffect(all.getLocation(), e, 3);
+ }
+
+ /**
+ * checks if server version is from spigot
+ * @return true/false
+ */
+ public static boolean isSpigot() {
+ return Bukkit.getVersion().contains("Spigot");
+ }
+
+ /**
+ * deletes all folders and files in directory
+ * @param file File
+ */
+ public static void deleteDir(File file) {
+ if (file.isDirectory()) {
+ if (file.list().length == 0) {
+ file.delete();
+ } else {
+ String[] files = file.list();
+ for (String tmp : files) {
+ File fileDelete = new File(file, tmp);
+ deleteDir(fileDelete);
+ }
+ if (file.list().length == 0)
+ file.delete();
+ }
+ } else
+ file.delete();
+ }
+
+ /**
+ * creates a random number
+ * @param low lowest possible value
+ * @param high highest possible value
+ * @return double
+ */
+ public static double random(int low, int high) {
+ return Math.random() * (high - low) + low;
+ }
+
+ /**
+ * checks if player has empty inventory
+ * @param p Player
+ * @return true/false
+ */
+ public static boolean hasEmptyInventory(Player p) {
+ for (ItemStack item : p.getInventory().getContents()) {
+ if ((item != null) && (item.getType() != Material.AIR))
+ return false;
+ }
+ for (ItemStack item : p.getInventory().getArmorContents()) {
+ if ((item != null) && (item.getType() != Material.AIR))
+ return false;
+ }
+ return true;
+ }
+
+
+ /**
+ * removes list of entity and counts them
+ * @param e List
+ * @return Integer
+ */
+ public static int removeEntitys(List e) {
+ int i = 0;
+ for (Entity en : e) {
+ en.remove();
+ i++;
+ }
+ return i;
+ }
+
+ /**
+ * clears all potion effects from player
+ * @param player Player
+ */
+ public static void clearPotionEffects(Player player) {
+ for (PotionEffect effect : player.getActivePotionEffects())
+ player.removePotionEffect(effect.getType());
+ }
+
+ /**
+ * calculates vector from one location to another
+ * @param from Location
+ * @param to Location
+ * @return Vector
+ */
+ public static Vector calculateVector(Location from, Location to) {
+ Location b = to;
+
+ // calculate the distance between the locations (a => from || b => to)
+ double dX = from.getX() - b.getX();
+ double dY = from.getY() - b.getY();
+ double dZ = from.getZ() - b.getZ();
+ // -------------------------
+
+ // calculate the yaw
+ double yaw = Math.atan2(dZ, dX);
+ // -------------------------
+
+ // calculate the pitch
+ double pitch = Math.atan2(Math.sqrt(dZ * dZ + dX * dX), dY) + Math.PI;
+ // -------------------------
+
+ // calculate and create the new vector
+ double x = Math.sin(pitch) * Math.cos(yaw);
+ double y = Math.sin(pitch) * Math.sin(yaw);
+ double z = Math.cos(pitch);
+
+ // -------------------------
+
+ return new Vector(x, z, y);
+ }
+
+ /**
+ * restarts server
+ */
+ public static void restart() {
+ Bukkit.getScheduler().scheduleSyncDelayedTask(Core.getInstance(), new Runnable() {
+
+ @Override
+ public void run() {
+ Bukkit.getServer().spigot().restart();
+ }
+
+ }, 10 * 20L);
+ }
+
+ /**
+ * shots random firework at specified location
+ * @param loc Location
+ */
+ public static void randomFirework(Location loc) {
+ FireworkEffect.Builder builder = FireworkEffect.builder();
+ FireworkEffect effect = builder.flicker(false).trail(false).with(FireworkEffect.Type.BALL_LARGE).withColor(Color.RED).withFade(Color.BLUE).build();
+ //TODO: make a random fireworks effect
+ }
}
\ No newline at end of file
diff --git a/src/eu/univento/core/api/database/Database.java b/src/main/java/eu/univento/core/api/database/Database.java
similarity index 100%
rename from src/eu/univento/core/api/database/Database.java
rename to src/main/java/eu/univento/core/api/database/Database.java
diff --git a/src/main/java/eu/univento/core/api/database/MongoDB.java b/src/main/java/eu/univento/core/api/database/MongoDB.java
new file mode 100644
index 0000000..59d755a
--- /dev/null
+++ b/src/main/java/eu/univento/core/api/database/MongoDB.java
@@ -0,0 +1,43 @@
+package eu.univento.core.api.database;
+
+import com.mongodb.MongoClient;
+import com.mongodb.MongoCredential;
+import com.mongodb.ServerAddress;
+import com.mongodb.client.MongoDatabase;
+import eu.univento.core.api.Config;
+
+import java.util.Arrays;
+
+public class MongoDB {
+
+ private MongoClient client;
+ private MongoDatabase database;
+
+ public MongoClient getClient() {
+ if(client == null)
+ new MongoDB(Config.readString("MongoDB.Host"), Config.readInt("MongoDB.Port"), Config.readString("MongoDB.Username"), Config.readString("MongoDB.Password"), Config.readString("MongoDB.Database"));
+ return client;
+ }
+
+ public MongoDB(String host, int port, String username, String password, String database) {
+ MongoCredential credential = MongoCredential.createCredential(username, database, password.toCharArray());
+ client = new MongoClient(new ServerAddress(host, port), Arrays.asList(credential));
+ }
+
+ public MongoDatabase getDatabase() {
+ if(database == null) {
+ database = getClient().getDatabase(Config.readString("MongoDB.Database"));
+ }return database;
+ }
+
+ public void setDatabase(String database) {
+ this.database = getClient().getDatabase(database);
+ }
+
+ public void closeConnection() {
+ if(client != null) {
+ client.close();
+ }
+ }
+
+}
\ No newline at end of file
diff --git a/src/eu/univento/core/api/database/MySQL.java b/src/main/java/eu/univento/core/api/database/MySQL.java
similarity index 100%
rename from src/eu/univento/core/api/database/MySQL.java
rename to src/main/java/eu/univento/core/api/database/MySQL.java
diff --git a/src/eu/univento/core/api/database/SQLite.java b/src/main/java/eu/univento/core/api/database/SQLite.java
similarity index 100%
rename from src/eu/univento/core/api/database/SQLite.java
rename to src/main/java/eu/univento/core/api/database/SQLite.java
diff --git a/src/main/java/eu/univento/core/api/effects/Effects.java b/src/main/java/eu/univento/core/api/effects/Effects.java
new file mode 100644
index 0000000..d5fb373
--- /dev/null
+++ b/src/main/java/eu/univento/core/api/effects/Effects.java
@@ -0,0 +1,36 @@
+package eu.univento.core.api.effects;
+
+import eu.univento.core.api.player.PlayerSettings;
+import net.minecraft.server.v1_9_R1.EnumParticle;
+import net.minecraft.server.v1_9_R1.PacketPlayOutWorldParticles;
+import org.bukkit.Location;
+import org.bukkit.craftbukkit.v1_9_R1.entity.CraftPlayer;
+import org.bukkit.entity.Player;
+
+/**
+ * some better effects
+ * @author joethei
+ * @version 1.0
+ */
+public class Effects {
+
+ /**
+ * plays effects from location
+ * @param loc Location
+ * @param ep EnumParticle
+ * @param f float of particles
+ * @param count count of particles
+ */
+ public static void playEffect(Location loc, EnumParticle ep, float f, int count) {
+ PacketPlayOutWorldParticles packet = new PacketPlayOutWorldParticles(ep, true, (float) loc.getX(), (float) loc.getY(), (float) loc.getZ(), f, f, f, 0.0F, count, 0, 0);
+ for(Player p : PlayerSettings.getAllPlayersWithEffectsEnabled()) {
+ ((CraftPlayer)p).getHandle().playerConnection.sendPacket(packet);
+ }
+ }
+
+ public static void playEffectToPlayer(Player p, Location loc, EnumParticle ep, float f, int count) {
+ PacketPlayOutWorldParticles packet = new PacketPlayOutWorldParticles(ep, true, (float) loc.getX(), (float) loc.getY(), (float) loc.getZ(), f, f, f, 0.0F, count, 0, 0);
+ ((CraftPlayer)p).getHandle().playerConnection.sendPacket(packet);
+ }
+
+}
\ No newline at end of file
diff --git a/src/main/java/eu/univento/core/api/effects/ParticleEffect.java b/src/main/java/eu/univento/core/api/effects/ParticleEffect.java
new file mode 100644
index 0000000..14c4e9e
--- /dev/null
+++ b/src/main/java/eu/univento/core/api/effects/ParticleEffect.java
@@ -0,0 +1,1606 @@
+package eu.univento.core.api.effects;
+
+import eu.univento.core.api.utils.reflection.ReflectionUtils;
+import eu.univento.core.api.utils.reflection.ReflectionUtils.PackageType;
+import org.bukkit.Bukkit;
+import org.bukkit.Color;
+import org.bukkit.Location;
+import org.bukkit.Material;
+import org.bukkit.entity.Player;
+import org.bukkit.util.Vector;
+
+import java.lang.reflect.Constructor;
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+
+/**
+ * ParticleEffect Library
+ *
+ * This library was created by @DarkBlade12 and allows you to display all Minecraft particle effects on a Bukkit server
+ *
+ * You are welcome to use it, modify it and redistribute it under the following conditions:
+ *
+ * - Don't claim this class as your own
+ *
- Don't remove this disclaimer
+ *
+ *
+ * Special thanks:
+ *
+ * - @microgeek (original idea, names and packet parameters)
+ *
- @ShadyPotato (1.8 names, ids and packet parameters)
+ *
- @RingOfStorms (particle behavior)
+ *
- @Cybermaxke (particle behavior)
+ *
- @JamieSinn (hosting a jenkins server and documentation for particleeffect)
+ *
+ *
+ * It would be nice if you provide credit to me if you use this class in a published project
+ *
+ * @author DarkBlade12
+ * @version 1.7
+ */
+public enum ParticleEffect {
+ /**
+ * A particle effect which is displayed by exploding tnt and creepers:
+ *
+ * - It looks like a white cloud
+ *
- The speed value influences the velocity at which the particle flies off
+ *
+ */
+ EXPLOSION_NORMAL("explode", 0, -1, ParticleProperty.DIRECTIONAL),
+ /**
+ * A particle effect which is displayed by exploding ghast fireballs and wither skulls:
+ *
+ * - It looks like a gray ball which is fading away
+ *
- The speed value slightly influences the size of this particle effect
+ *
+ */
+ EXPLOSION_LARGE("largeexplode", 1, -1),
+ /**
+ * A particle effect which is displayed by exploding tnt and creepers:
+ *
+ * - It looks like a crowd of gray balls which are fading away
+ *
- The speed value has no influence on this particle effect
+ *
+ */
+ EXPLOSION_HUGE("hugeexplosion", 2, -1),
+ /**
+ * A particle effect which is displayed by launching fireworks:
+ *
+ * - It looks like a white star which is sparkling
+ *
- The speed value influences the velocity at which the particle flies off
+ *
+ */
+ FIREWORKS_SPARK("fireworksSpark", 3, -1, ParticleProperty.DIRECTIONAL),
+ /**
+ * A particle effect which is displayed by swimming entities and arrows in water:
+ *
+ * - It looks like a bubble
+ *
- The speed value influences the velocity at which the particle flies off
+ *
+ */
+ WATER_BUBBLE("bubble", 4, -1, ParticleProperty.DIRECTIONAL, ParticleProperty.REQUIRES_WATER),
+ /**
+ * A particle effect which is displayed by swimming entities and shaking wolves:
+ *
+ * - It looks like a blue drop
+ *
- The speed value has no influence on this particle effect
+ *
+ */
+ WATER_SPLASH("splash", 5, -1, ParticleProperty.DIRECTIONAL),
+ /**
+ * A particle effect which is displayed on water when fishing:
+ *
+ * - It looks like a blue droplet
+ *
- The speed value influences the velocity at which the particle flies off
+ *
+ */
+ WATER_WAKE("wake", 6, 7, ParticleProperty.DIRECTIONAL),
+ /**
+ * A particle effect which is displayed by water:
+ *
+ * - It looks like a tiny blue square
+ *
- The speed value has no influence on this particle effect
+ *
+ */
+ SUSPENDED("suspended", 7, -1, ParticleProperty.REQUIRES_WATER),
+ /**
+ * A particle effect which is displayed by air when close to bedrock and the in the void:
+ *
+ * - It looks like a tiny gray square
+ *
- The speed value has no influence on this particle effect
+ *
+ */
+ SUSPENDED_DEPTH("depthSuspend", 8, -1, ParticleProperty.DIRECTIONAL),
+ /**
+ * A particle effect which is displayed when landing a critical hit and by arrows:
+ *
+ * - It looks like a light brown cross
+ *
- The speed value influences the velocity at which the particle flies off
+ *
+ */
+ CRIT("crit", 9, -1, ParticleProperty.DIRECTIONAL),
+ /**
+ * A particle effect which is displayed when landing a hit with an enchanted weapon:
+ *
+ * - It looks like a cyan star
+ *
- The speed value influences the velocity at which the particle flies off
+ *
+ */
+ CRIT_MAGIC("magicCrit", 10, -1, ParticleProperty.DIRECTIONAL),
+ /**
+ * A particle effect which is displayed by primed tnt, torches, droppers, dispensers, end portals, brewing stands and monster spawners:
+ *
+ * - It looks like a little gray cloud
+ *
- The speed value influences the velocity at which the particle flies off
+ *
+ */
+ SMOKE_NORMAL("smoke", 11, -1, ParticleProperty.DIRECTIONAL),
+ /**
+ * A particle effect which is displayed by fire, minecarts with furnace and blazes:
+ *
+ * - It looks like a large gray cloud
+ *
- The speed value influences the velocity at which the particle flies off
+ *
+ */
+ SMOKE_LARGE("largesmoke", 12, -1, ParticleProperty.DIRECTIONAL),
+ /**
+ * A particle effect which is displayed when splash potions or bottles o' enchanting hit something:
+ *
+ * - It looks like a white swirl
+ *
- The speed value causes the particle to only move upwards when set to 0
+ *
- Only the motion on the y-axis can be controlled, the motion on the x- and z-axis are multiplied by 0.1 when setting the values to 0
+ *
+ */
+ SPELL("spell", 13, -1),
+ /**
+ * A particle effect which is displayed when instant splash potions hit something:
+ *
+ * - It looks like a white cross
+ *
- The speed value causes the particle to only move upwards when set to 0
+ *
- Only the motion on the y-axis can be controlled, the motion on the x- and z-axis are multiplied by 0.1 when setting the values to 0
+ *
+ */
+ SPELL_INSTANT("instantSpell", 14, -1),
+ /**
+ * A particle effect which is displayed by entities with active potion effects:
+ *
+ * - It looks like a colored swirl
+ *
- The speed value causes the particle to be colored black when set to 0
+ *
- The particle color gets lighter when increasing the speed and darker when decreasing the speed
+ *
+ */
+ SPELL_MOB("mobSpell", 15, -1, ParticleProperty.COLORABLE),
+ /**
+ * A particle effect which is displayed by entities with active potion effects applied through a beacon:
+ *
+ * - It looks like a transparent colored swirl
+ *
- The speed value causes the particle to be always colored black when set to 0
+ *
- The particle color gets lighter when increasing the speed and darker when decreasing the speed
+ *
+ */
+ SPELL_MOB_AMBIENT("mobSpellAmbient", 16, -1, ParticleProperty.COLORABLE),
+ /**
+ * A particle effect which is displayed by witches:
+ *
+ * - It looks like a purple cross
+ *
- The speed value causes the particle to only move upwards when set to 0
+ *
- Only the motion on the y-axis can be controlled, the motion on the x- and z-axis are multiplied by 0.1 when setting the values to 0
+ *
+ */
+ SPELL_WITCH("witchMagic", 17, -1),
+ /**
+ * A particle effect which is displayed by blocks beneath a water source:
+ *
+ * - It looks like a blue drip
+ *
- The speed value has no influence on this particle effect
+ *
+ */
+ DRIP_WATER("dripWater", 18, -1),
+ /**
+ * A particle effect which is displayed by blocks beneath a lava source:
+ *
+ * - It looks like an orange drip
+ *
- The speed value has no influence on this particle effect
+ *
+ */
+ DRIP_LAVA("dripLava", 19, -1),
+ /**
+ * A particle effect which is displayed when attacking a villager in a village:
+ *
+ * - It looks like a cracked gray heart
+ *
- The speed value has no influence on this particle effect
+ *
+ */
+ VILLAGER_ANGRY("angryVillager", 20, -1),
+ /**
+ * A particle effect which is displayed when using bone meal and trading with a villager in a village:
+ *
+ * - It looks like a green star
+ *
- The speed value has no influence on this particle effect
+ *
+ */
+ VILLAGER_HAPPY("happyVillager", 21, -1, ParticleProperty.DIRECTIONAL),
+ /**
+ * A particle effect which is displayed by mycelium:
+ *
+ * - It looks like a tiny gray square
+ *
- The speed value has no influence on this particle effect
+ *
+ */
+ TOWN_AURA("townaura", 22, -1, ParticleProperty.DIRECTIONAL),
+ /**
+ * A particle effect which is displayed by note blocks:
+ *
+ * - It looks like a colored note
+ *
- The speed value causes the particle to be colored green when set to 0
+ *
+ */
+ NOTE("note", 23, -1, ParticleProperty.COLORABLE),
+ /**
+ * A particle effect which is displayed by nether portals, endermen, ender pearls, eyes of ender, ender chests and dragon eggs:
+ *
+ * - It looks like a purple cloud
+ *
- The speed value influences the spread of this particle effect
+ *
+ */
+ PORTAL("portal", 24, -1, ParticleProperty.DIRECTIONAL),
+ /**
+ * A particle effect which is displayed by enchantment tables which are nearby bookshelves:
+ *
+ * - It looks like a cryptic white letter
+ *
- The speed value influences the spread of this particle effect
+ *
+ */
+ ENCHANTMENT_TABLE("enchantmenttable", 25, -1, ParticleProperty.DIRECTIONAL),
+ /**
+ * A particle effect which is displayed by torches, active furnaces, magma cubes and monster spawners:
+ *
+ * - It looks like a tiny flame
+ *
- The speed value influences the velocity at which the particle flies off
+ *
+ */
+ FLAME("flame", 26, -1, ParticleProperty.DIRECTIONAL),
+ /**
+ * A particle effect which is displayed by lava:
+ *
+ * - It looks like a spark
+ *
- The speed value has no influence on this particle effect
+ *
+ */
+ LAVA("lava", 27, -1),
+ /**
+ * A particle effect which is currently unused:
+ *
+ * - It looks like a transparent gray square
+ *
- The speed value has no influence on this particle effect
+ *
+ */
+ FOOTSTEP("footstep", 28, -1),
+ /**
+ * A particle effect which is displayed when a mob dies:
+ *
+ * - It looks like a large white cloud
+ *
- The speed value influences the velocity at which the particle flies off
+ *
+ */
+ CLOUD("cloud", 29, -1, ParticleProperty.DIRECTIONAL),
+ /**
+ * A particle effect which is displayed by redstone ore, powered redstone, redstone torches and redstone repeaters:
+ *
+ * - It looks like a tiny colored cloud
+ *
- The speed value causes the particle to be colored red when set to 0
+ *
+ */
+ REDSTONE("reddust", 30, -1, ParticleProperty.COLORABLE),
+ /**
+ * A particle effect which is displayed when snowballs hit a block:
+ *
+ * - It looks like a little piece with the snowball texture
+ *
- The speed value has no influence on this particle effect
+ *
+ */
+ SNOWBALL("snowballpoof", 31, -1),
+ /**
+ * A particle effect which is currently unused:
+ *
+ * - It looks like a tiny white cloud
+ *
- The speed value influences the velocity at which the particle flies off
+ *
+ */
+ SNOW_SHOVEL("snowshovel", 32, -1, ParticleProperty.DIRECTIONAL),
+ /**
+ * A particle effect which is displayed by slimes:
+ *
+ * - It looks like a tiny part of the slimeball icon
+ *
- The speed value has no influence on this particle effect
+ *
+ */
+ SLIME("slime", 33, -1),
+ /**
+ * A particle effect which is displayed when breeding and taming animals:
+ *
+ * - It looks like a red heart
+ *
- The speed value has no influence on this particle effect
+ *
+ */
+ HEART("heart", 34, -1),
+ /**
+ * A particle effect which is displayed by barriers:
+ *
+ * - It looks like a red box with a slash through it
+ *
- The speed value has no influence on this particle effect
+ *
+ */
+ BARRIER("barrier", 35, 8),
+ /**
+ * A particle effect which is displayed when breaking a tool or eggs hit a block:
+ *
+ * - It looks like a little piece with an item texture
+ *
+ */
+ ITEM_CRACK("iconcrack", 36, -1, ParticleProperty.DIRECTIONAL, ParticleProperty.REQUIRES_DATA),
+ /**
+ * A particle effect which is displayed when breaking blocks or sprinting:
+ *
+ * - It looks like a little piece with a block texture
+ *
- The speed value has no influence on this particle effect
+ *
+ */
+ BLOCK_CRACK("blockcrack", 37, -1, ParticleProperty.REQUIRES_DATA),
+ /**
+ * A particle effect which is displayed when falling:
+ *
+ * - It looks like a little piece with a block texture
+ *
+ */
+ BLOCK_DUST("blockdust", 38, 7, ParticleProperty.DIRECTIONAL, ParticleProperty.REQUIRES_DATA),
+ /**
+ * A particle effect which is displayed when rain hits the ground:
+ *
+ * - It looks like a blue droplet
+ *
- The speed value has no influence on this particle effect
+ *
+ */
+ WATER_DROP("droplet", 39, 8),
+ /**
+ * A particle effect which is currently unused:
+ *
+ * - It has no visual effect
+ *
+ */
+ ITEM_TAKE("take", 40, 8),
+ /**
+ * A particle effect which is displayed by elder guardians:
+ *
+ * - It looks like the shape of the elder guardian
+ *
- The speed value has no influence on this particle effect
+ *
- The offset values have no influence on this particle effect
+ *
+ */
+ MOB_APPEARANCE("mobappearance", 41, 8);
+
+ private static final Map NAME_MAP = new HashMap();
+ private static final Map ID_MAP = new HashMap();
+ private final String name;
+ private final int id;
+ private final int requiredVersion;
+ private final List properties;
+
+ // Initialize map for quick name and id lookup
+ static {
+ for (ParticleEffect effect : values()) {
+ NAME_MAP.put(effect.name, effect);
+ ID_MAP.put(effect.id, effect);
+ }
+ }
+
+ /**
+ * Construct a new particle effect
+ *
+ * @param name Name of this particle effect
+ * @param id Id of this particle effect
+ * @param requiredVersion Version which is required (1.x)
+ * @param properties Properties of this particle effect
+ */
+ private ParticleEffect(String name, int id, int requiredVersion, ParticleProperty... properties) {
+ this.name = name;
+ this.id = id;
+ this.requiredVersion = requiredVersion;
+ this.properties = Arrays.asList(properties);
+ }
+
+ /**
+ * Returns the name of this particle effect
+ *
+ * @return The name
+ */
+ public String getName() {
+ return name;
+ }
+
+ /**
+ * Returns the id of this particle effect
+ *
+ * @return The id
+ */
+ public int getId() {
+ return id;
+ }
+
+ /**
+ * Returns the required version for this particle effect (1.x)
+ *
+ * @return The required version
+ */
+ public int getRequiredVersion() {
+ return requiredVersion;
+ }
+
+ /**
+ * Determine if this particle effect has a specific property
+ *
+ * @return Whether it has the property or not
+ */
+ public boolean hasProperty(ParticleProperty property) {
+ return properties.contains(property);
+ }
+
+ /**
+ * Determine if this particle effect is supported by your current server version
+ *
+ * @return Whether the particle effect is supported or not
+ */
+ public boolean isSupported() {
+ if (requiredVersion == -1) {
+ return true;
+ }
+ return ParticlePacket.getVersion() >= requiredVersion;
+ }
+
+ /**
+ * Returns the particle effect with the given name
+ *
+ * @param name Name of the particle effect
+ * @return The particle effect
+ */
+ public static ParticleEffect fromName(String name) {
+ for (Entry entry : NAME_MAP.entrySet()) {
+ if (!entry.getKey().equalsIgnoreCase(name)) {
+ continue;
+ }
+ return entry.getValue();
+ }
+ return null;
+ }
+
+ /**
+ * Returns the particle effect with the given id
+ *
+ * @param id Id of the particle effect
+ * @return The particle effect
+ */
+ public static ParticleEffect fromId(int id) {
+ for (Entry entry : ID_MAP.entrySet()) {
+ if (entry.getKey() != id) {
+ continue;
+ }
+ return entry.getValue();
+ }
+ return null;
+ }
+
+ /**
+ * Determine if water is at a certain location
+ *
+ * @param location Location to check
+ * @return Whether water is at this location or not
+ */
+ private static boolean isWater(Location location) {
+ Material material = location.getBlock().getType();
+ return material == Material.WATER || material == Material.STATIONARY_WATER;
+ }
+
+ /**
+ * Determine if the distance between @param location and one of the players exceeds 256
+ *
+ * @param location Location to check
+ * @return Whether the distance exceeds 256 or not
+ */
+ private static boolean isLongDistance(Location location, List players) {
+ String world = location.getWorld().getName();
+ for (Player player : players) {
+ Location playerLocation = player.getLocation();
+ if (!world.equals(playerLocation.getWorld().getName()) || playerLocation.distanceSquared(location) < 65536) {
+ continue;
+ }
+ return true;
+ }
+ return false;
+ }
+
+ /**
+ * Determine if the data type for a particle effect is correct
+ *
+ * @param effect Particle effect
+ * @param data Particle data
+ * @return Whether the data type is correct or not
+ */
+ private static boolean isDataCorrect(ParticleEffect effect, ParticleData data) {
+ return ((effect == BLOCK_CRACK || effect == BLOCK_DUST) && data instanceof BlockData) || (effect == ITEM_CRACK && data instanceof ItemData);
+ }
+
+ /**
+ * Determine if the color type for a particle effect is correct
+ *
+ * @param effect Particle effect
+ * @param color Particle color
+ * @return Whether the color type is correct or not
+ */
+ private static boolean isColorCorrect(ParticleEffect effect, ParticleColor color) {
+ return ((effect == SPELL_MOB || effect == SPELL_MOB_AMBIENT || effect == REDSTONE) && color instanceof OrdinaryColor) || (effect == NOTE && color instanceof NoteColor);
+ }
+
+ /**
+ * Displays a particle effect which is only visible for all players within a certain range in the world of @param center
+ *
+ * @param offsetX Maximum distance particles can fly away from the center on the x-axis
+ * @param offsetY Maximum distance particles can fly away from the center on the y-axis
+ * @param offsetZ Maximum distance particles can fly away from the center on the z-axis
+ * @param speed Display speed of the particles
+ * @param amount Amount of particles
+ * @param center Center location of the effect
+ * @param range Range of the visibility
+ * @throws ParticleVersionException If the particle effect is not supported by the server version
+ * @throws ParticleDataException If the particle effect requires additional data
+ * @throws IllegalArgumentException If the particle effect requires water and none is at the center location
+ * @see ParticlePacket
+ * @see ParticlePacket#sendTo(Location, double)
+ */
+ public void display(float offsetX, float offsetY, float offsetZ, float speed, int amount, Location center, double range) throws ParticleVersionException, ParticleDataException, IllegalArgumentException {
+ if (!isSupported()) {
+ throw new ParticleVersionException("This particle effect is not supported by your server version");
+ }
+ if (hasProperty(ParticleProperty.REQUIRES_DATA)) {
+ throw new ParticleDataException("This particle effect requires additional data");
+ }
+ if (hasProperty(ParticleProperty.REQUIRES_WATER) && !isWater(center)) {
+ throw new IllegalArgumentException("There is no water at the center location");
+ }
+ new ParticlePacket(this, offsetX, offsetY, offsetZ, speed, amount, range > 256, null).sendTo(center, range);
+ }
+
+ /**
+ * Displays a particle effect which is only visible for the specified players
+ *
+ * @param offsetX Maximum distance particles can fly away from the center on the x-axis
+ * @param offsetY Maximum distance particles can fly away from the center on the y-axis
+ * @param offsetZ Maximum distance particles can fly away from the center on the z-axis
+ * @param speed Display speed of the particles
+ * @param amount Amount of particles
+ * @param center Center location of the effect
+ * @param players Receivers of the effect
+ * @throws ParticleVersionException If the particle effect is not supported by the server version
+ * @throws ParticleDataException If the particle effect requires additional data
+ * @throws IllegalArgumentException If the particle effect requires water and none is at the center location
+ * @see ParticlePacket
+ * @see ParticlePacket#sendTo(Location, List)
+ */
+ public void display(float offsetX, float offsetY, float offsetZ, float speed, int amount, Location center, List players) throws ParticleVersionException, ParticleDataException, IllegalArgumentException {
+ if (!isSupported()) {
+ throw new ParticleVersionException("This particle effect is not supported by your server version");
+ }
+ if (hasProperty(ParticleProperty.REQUIRES_DATA)) {
+ throw new ParticleDataException("This particle effect requires additional data");
+ }
+ if (hasProperty(ParticleProperty.REQUIRES_WATER) && !isWater(center)) {
+ throw new IllegalArgumentException("There is no water at the center location");
+ }
+ new ParticlePacket(this, offsetX, offsetY, offsetZ, speed, amount, isLongDistance(center, players), null).sendTo(center, players);
+ }
+
+ /**
+ * Displays a particle effect which is only visible for the specified players
+ *
+ * @param offsetX Maximum distance particles can fly away from the center on the x-axis
+ * @param offsetY Maximum distance particles can fly away from the center on the y-axis
+ * @param offsetZ Maximum distance particles can fly away from the center on the z-axis
+ * @param speed Display speed of the particles
+ * @param amount Amount of particles
+ * @param center Center location of the effect
+ * @param players Receivers of the effect
+ * @throws ParticleVersionException If the particle effect is not supported by the server version
+ * @throws ParticleDataException If the particle effect requires additional data
+ * @throws IllegalArgumentException If the particle effect requires water and none is at the center location
+ * @see #display(float, float, float, float, int, Location, List)
+ */
+ public void display(float offsetX, float offsetY, float offsetZ, float speed, int amount, Location center, Player... players) throws ParticleVersionException, ParticleDataException, IllegalArgumentException {
+ display(offsetX, offsetY, offsetZ, speed, amount, center, Arrays.asList(players));
+ }
+
+ /**
+ * Displays a single particle which flies into a determined direction and is only visible for all players within a certain range in the world of @param center
+ *
+ * @param direction Direction of the particle
+ * @param speed Display speed of the particle
+ * @param center Center location of the effect
+ * @param range Range of the visibility
+ * @throws ParticleVersionException If the particle effect is not supported by the server version
+ * @throws ParticleDataException If the particle effect requires additional data
+ * @throws IllegalArgumentException If the particle effect is not directional or if it requires water and none is at the center location
+ * @see ParticlePacket#ParticlePacket(ParticleEffect, Vector, float, boolean, ParticleData)
+ * @see ParticlePacket#sendTo(Location, double)
+ */
+ public void display(Vector direction, float speed, Location center, double range) throws ParticleVersionException, ParticleDataException, IllegalArgumentException {
+ if (!isSupported()) {
+ throw new ParticleVersionException("This particle effect is not supported by your server version");
+ }
+ if (hasProperty(ParticleProperty.REQUIRES_DATA)) {
+ throw new ParticleDataException("This particle effect requires additional data");
+ }
+ if (!hasProperty(ParticleProperty.DIRECTIONAL)) {
+ throw new IllegalArgumentException("This particle effect is not directional");
+ }
+ if (hasProperty(ParticleProperty.REQUIRES_WATER) && !isWater(center)) {
+ throw new IllegalArgumentException("There is no water at the center location");
+ }
+ new ParticlePacket(this, direction, speed, range > 256, null).sendTo(center, range);
+ }
+
+ /**
+ * Displays a single particle which flies into a determined direction and is only visible for the specified players
+ *
+ * @param direction Direction of the particle
+ * @param speed Display speed of the particle
+ * @param center Center location of the effect
+ * @param players Receivers of the effect
+ * @throws ParticleVersionException If the particle effect is not supported by the server version
+ * @throws ParticleDataException If the particle effect requires additional data
+ * @throws IllegalArgumentException If the particle effect is not directional or if it requires water and none is at the center location
+ * @see ParticlePacket#ParticlePacket(ParticleEffect, Vector, float, boolean, ParticleData)
+ * @see ParticlePacket#sendTo(Location, List)
+ */
+ public void display(Vector direction, float speed, Location center, List players) throws ParticleVersionException, ParticleDataException, IllegalArgumentException {
+ if (!isSupported()) {
+ throw new ParticleVersionException("This particle effect is not supported by your server version");
+ }
+ if (hasProperty(ParticleProperty.REQUIRES_DATA)) {
+ throw new ParticleDataException("This particle effect requires additional data");
+ }
+ if (!hasProperty(ParticleProperty.DIRECTIONAL)) {
+ throw new IllegalArgumentException("This particle effect is not directional");
+ }
+ if (hasProperty(ParticleProperty.REQUIRES_WATER) && !isWater(center)) {
+ throw new IllegalArgumentException("There is no water at the center location");
+ }
+ new ParticlePacket(this, direction, speed, isLongDistance(center, players), null).sendTo(center, players);
+ }
+
+ /**
+ * Displays a single particle which flies into a determined direction and is only visible for the specified players
+ *
+ * @param direction Direction of the particle
+ * @param speed Display speed of the particle
+ * @param center Center location of the effect
+ * @param players Receivers of the effect
+ * @throws ParticleVersionException If the particle effect is not supported by the server version
+ * @throws ParticleDataException If the particle effect requires additional data
+ * @throws IllegalArgumentException If the particle effect is not directional or if it requires water and none is at the center location
+ * @see #display(Vector, float, Location, List)
+ */
+ public void display(Vector direction, float speed, Location center, Player... players) throws ParticleVersionException, ParticleDataException, IllegalArgumentException {
+ display(direction, speed, center, Arrays.asList(players));
+ }
+
+ /**
+ * Displays a single particle which is colored and only visible for all players within a certain range in the world of @param center
+ *
+ * @param color Color of the particle
+ * @param center Center location of the effect
+ * @param range Range of the visibility
+ * @throws ParticleVersionException If the particle effect is not supported by the server version
+ * @throws ParticleColorException If the particle effect is not colorable or the color type is incorrect
+ * @see ParticlePacket#ParticlePacket(ParticleEffect, ParticleColor, boolean)
+ * @see ParticlePacket#sendTo(Location, double)
+ */
+ public void display(ParticleColor color, Location center, double range) throws ParticleVersionException, ParticleColorException {
+ if (!isSupported()) {
+ throw new ParticleVersionException("This particle effect is not supported by your server version");
+ }
+ if (!hasProperty(ParticleProperty.COLORABLE)) {
+ throw new ParticleColorException("This particle effect is not colorable");
+ }
+ if (!isColorCorrect(this, color)) {
+ throw new ParticleColorException("The particle color type is incorrect");
+ }
+ new ParticlePacket(this, color, range > 256).sendTo(center, range);
+ }
+
+ /**
+ * Displays a single particle which is colored and only visible for the specified players
+ *
+ * @param color Color of the particle
+ * @param center Center location of the effect
+ * @param players Receivers of the effect
+ * @throws ParticleVersionException If the particle effect is not supported by the server version
+ * @throws ParticleColorException If the particle effect is not colorable or the color type is incorrect
+ * @see ParticlePacket#ParticlePacket(ParticleEffect, ParticleColor, boolean)
+ * @see ParticlePacket#sendTo(Location, List)
+ */
+ public void display(ParticleColor color, Location center, List players) throws ParticleVersionException, ParticleColorException {
+ if (!isSupported()) {
+ throw new ParticleVersionException("This particle effect is not supported by your server version");
+ }
+ if (!hasProperty(ParticleProperty.COLORABLE)) {
+ throw new ParticleColorException("This particle effect is not colorable");
+ }
+ if (!isColorCorrect(this, color)) {
+ throw new ParticleColorException("The particle color type is incorrect");
+ }
+ new ParticlePacket(this, color, isLongDistance(center, players)).sendTo(center, players);
+ }
+
+ /**
+ * Displays a single particle which is colored and only visible for the specified players
+ *
+ * @param color Color of the particle
+ * @param center Center location of the effect
+ * @param players Receivers of the effect
+ * @throws ParticleVersionException If the particle effect is not supported by the server version
+ * @throws ParticleColorException If the particle effect is not colorable or the color type is incorrect
+ * @see #display(ParticleColor, Location, List)
+ */
+ public void display(ParticleColor color, Location center, Player... players) throws ParticleVersionException, ParticleColorException {
+ display(color, center, Arrays.asList(players));
+ }
+
+ /**
+ * Displays a particle effect which requires additional data and is only visible for all players within a certain range in the world of @param center
+ *
+ * @param data Data of the effect
+ * @param offsetX Maximum distance particles can fly away from the center on the x-axis
+ * @param offsetY Maximum distance particles can fly away from the center on the y-axis
+ * @param offsetZ Maximum distance particles can fly away from the center on the z-axis
+ * @param speed Display speed of the particles
+ * @param amount Amount of particles
+ * @param center Center location of the effect
+ * @param range Range of the visibility
+ * @throws ParticleVersionException If the particle effect is not supported by the server version
+ * @throws ParticleDataException If the particle effect does not require additional data or if the data type is incorrect
+ * @see ParticlePacket
+ * @see ParticlePacket#sendTo(Location, double)
+ */
+ public void display(ParticleData data, float offsetX, float offsetY, float offsetZ, float speed, int amount, Location center, double range) throws ParticleVersionException, ParticleDataException {
+ if (!isSupported()) {
+ throw new ParticleVersionException("This particle effect is not supported by your server version");
+ }
+ if (!hasProperty(ParticleProperty.REQUIRES_DATA)) {
+ throw new ParticleDataException("This particle effect does not require additional data");
+ }
+ if (!isDataCorrect(this, data)) {
+ throw new ParticleDataException("The particle data type is incorrect");
+ }
+ new ParticlePacket(this, offsetX, offsetY, offsetZ, speed, amount, range > 256, data).sendTo(center, range);
+ }
+
+ /**
+ * Displays a particle effect which requires additional data and is only visible for the specified players
+ *
+ * @param data Data of the effect
+ * @param offsetX Maximum distance particles can fly away from the center on the x-axis
+ * @param offsetY Maximum distance particles can fly away from the center on the y-axis
+ * @param offsetZ Maximum distance particles can fly away from the center on the z-axis
+ * @param speed Display speed of the particles
+ * @param amount Amount of particles
+ * @param center Center location of the effect
+ * @param players Receivers of the effect
+ * @throws ParticleVersionException If the particle effect is not supported by the server version
+ * @throws ParticleDataException If the particle effect does not require additional data or if the data type is incorrect
+ * @see ParticlePacket
+ * @see ParticlePacket#sendTo(Location, List)
+ */
+ public void display(ParticleData data, float offsetX, float offsetY, float offsetZ, float speed, int amount, Location center, List players) throws ParticleVersionException, ParticleDataException {
+ if (!isSupported()) {
+ throw new ParticleVersionException("This particle effect is not supported by your server version");
+ }
+ if (!hasProperty(ParticleProperty.REQUIRES_DATA)) {
+ throw new ParticleDataException("This particle effect does not require additional data");
+ }
+ if (!isDataCorrect(this, data)) {
+ throw new ParticleDataException("The particle data type is incorrect");
+ }
+ new ParticlePacket(this, offsetX, offsetY, offsetZ, speed, amount, isLongDistance(center, players), data).sendTo(center, players);
+ }
+
+ /**
+ * Displays a particle effect which requires additional data and is only visible for the specified players
+ *
+ * @param data Data of the effect
+ * @param offsetX Maximum distance particles can fly away from the center on the x-axis
+ * @param offsetY Maximum distance particles can fly away from the center on the y-axis
+ * @param offsetZ Maximum distance particles can fly away from the center on the z-axis
+ * @param speed Display speed of the particles
+ * @param amount Amount of particles
+ * @param center Center location of the effect
+ * @param players Receivers of the effect
+ * @throws ParticleVersionException If the particle effect is not supported by the server version
+ * @throws ParticleDataException If the particle effect does not require additional data or if the data type is incorrect
+ * @see #display(ParticleData, float, float, float, float, int, Location, List)
+ */
+ public void display(ParticleData data, float offsetX, float offsetY, float offsetZ, float speed, int amount, Location center, Player... players) throws ParticleVersionException, ParticleDataException {
+ display(data, offsetX, offsetY, offsetZ, speed, amount, center, Arrays.asList(players));
+ }
+
+ /**
+ * Displays a single particle which requires additional data that flies into a determined direction and is only visible for all players within a certain range in the world of @param center
+ *
+ * @param data Data of the effect
+ * @param direction Direction of the particle
+ * @param speed Display speed of the particles
+ * @param center Center location of the effect
+ * @param range Range of the visibility
+ * @throws ParticleVersionException If the particle effect is not supported by the server version
+ * @throws ParticleDataException If the particle effect does not require additional data or if the data type is incorrect
+ * @see ParticlePacket
+ * @see ParticlePacket#sendTo(Location, double)
+ */
+ public void display(ParticleData data, Vector direction, float speed, Location center, double range) throws ParticleVersionException, ParticleDataException {
+ if (!isSupported()) {
+ throw new ParticleVersionException("This particle effect is not supported by your server version");
+ }
+ if (!hasProperty(ParticleProperty.REQUIRES_DATA)) {
+ throw new ParticleDataException("This particle effect does not require additional data");
+ }
+ if (!isDataCorrect(this, data)) {
+ throw new ParticleDataException("The particle data type is incorrect");
+ }
+ new ParticlePacket(this, direction, speed, range > 256, data).sendTo(center, range);
+ }
+
+ /**
+ * Displays a single particle which requires additional data that flies into a determined direction and is only visible for the specified players
+ *
+ * @param data Data of the effect
+ * @param direction Direction of the particle
+ * @param speed Display speed of the particles
+ * @param center Center location of the effect
+ * @param players Receivers of the effect
+ * @throws ParticleVersionException If the particle effect is not supported by the server version
+ * @throws ParticleDataException If the particle effect does not require additional data or if the data type is incorrect
+ * @see ParticlePacket
+ * @see ParticlePacket#sendTo(Location, List)
+ */
+ public void display(ParticleData data, Vector direction, float speed, Location center, List players) throws ParticleVersionException, ParticleDataException {
+ if (!isSupported()) {
+ throw new ParticleVersionException("This particle effect is not supported by your server version");
+ }
+ if (!hasProperty(ParticleProperty.REQUIRES_DATA)) {
+ throw new ParticleDataException("This particle effect does not require additional data");
+ }
+ if (!isDataCorrect(this, data)) {
+ throw new ParticleDataException("The particle data type is incorrect");
+ }
+ new ParticlePacket(this, direction, speed, isLongDistance(center, players), data).sendTo(center, players);
+ }
+
+ /**
+ * Displays a single particle which requires additional data that flies into a determined direction and is only visible for the specified players
+ *
+ * @param data Data of the effect
+ * @param direction Direction of the particle
+ * @param speed Display speed of the particles
+ * @param center Center location of the effect
+ * @param players Receivers of the effect
+ * @throws ParticleVersionException If the particle effect is not supported by the server version
+ * @throws ParticleDataException If the particle effect does not require additional data or if the data type is incorrect
+ * @see #display(ParticleData, Vector, float, Location, List)
+ */
+ public void display(ParticleData data, Vector direction, float speed, Location center, Player... players) throws ParticleVersionException, ParticleDataException {
+ display(data, direction, speed, center, Arrays.asList(players));
+ }
+
+ /**
+ * Represents the property of a particle effect
+ *
+ * This class is part of the ParticleEffect Library and follows the same usage conditions
+ *
+ * @author DarkBlade12
+ * @since 1.7
+ */
+ public static enum ParticleProperty {
+ /**
+ * The particle effect requires water to be displayed
+ */
+ REQUIRES_WATER,
+ /**
+ * The particle effect requires block or item data to be displayed
+ */
+ REQUIRES_DATA,
+ /**
+ * The particle effect uses the offsets as direction values
+ */
+ DIRECTIONAL,
+ /**
+ * The particle effect uses the offsets as color values
+ */
+ COLORABLE
+ }
+
+ /**
+ * Represents the particle data for effects like {@link ParticleEffect#ITEM_CRACK}, {@link ParticleEffect#BLOCK_CRACK} and {@link ParticleEffect#BLOCK_DUST}
+ *
+ * This class is part of the ParticleEffect Library and follows the same usage conditions
+ *
+ * @author DarkBlade12
+ * @since 1.6
+ */
+ public static abstract class ParticleData {
+ private final Material material;
+ private final byte data;
+ private final int[] packetData;
+
+ /**
+ * Construct a new particle data
+ *
+ * @param material Material of the item/block
+ * @param data Data value of the item/block
+ */
+ @SuppressWarnings("deprecation")
+ public ParticleData(Material material, byte data) {
+ this.material = material;
+ this.data = data;
+ this.packetData = new int[] { material.getId(), data };
+ }
+
+ /**
+ * Returns the material of this data
+ *
+ * @return The material
+ */
+ public Material getMaterial() {
+ return material;
+ }
+
+ /**
+ * Returns the data value of this data
+ *
+ * @return The data value
+ */
+ public byte getData() {
+ return data;
+ }
+
+ /**
+ * Returns the data as an int array for packet construction
+ *
+ * @return The data for the packet
+ */
+ public int[] getPacketData() {
+ return packetData;
+ }
+
+ /**
+ * Returns the data as a string for pre 1.8 versions
+ *
+ * @return The data string for the packet
+ */
+ public String getPacketDataString() {
+ return "_" + packetData[0] + "_" + packetData[1];
+ }
+ }
+
+ /**
+ * Represents the item data for the {@link ParticleEffect#ITEM_CRACK} effect
+ *
+ * This class is part of the ParticleEffect Library and follows the same usage conditions
+ *
+ * @author DarkBlade12
+ * @since 1.6
+ */
+ public static final class ItemData extends ParticleData {
+ /**
+ * Construct a new item data
+ *
+ * @param material Material of the item
+ * @param data Data value of the item
+ * @see ParticleData#ParticleData(Material, byte)
+ */
+ public ItemData(Material material, byte data) {
+ super(material, data);
+ }
+ }
+
+ /**
+ * Represents the block data for the {@link ParticleEffect#BLOCK_CRACK} and {@link ParticleEffect#BLOCK_DUST} effects
+ *
+ * This class is part of the ParticleEffect Library and follows the same usage conditions
+ *
+ * @author DarkBlade12
+ * @since 1.6
+ */
+ public static final class BlockData extends ParticleData {
+ /**
+ * Construct a new block data
+ *
+ * @param material Material of the block
+ * @param data Data value of the block
+ * @throws IllegalArgumentException If the material is not a block
+ * @see ParticleData#ParticleData(Material, byte)
+ */
+ public BlockData(Material material, byte data) throws IllegalArgumentException {
+ super(material, data);
+ if (!material.isBlock()) {
+ throw new IllegalArgumentException("The material is not a block");
+ }
+ }
+ }
+
+ /**
+ * Represents the color for effects like {@link ParticleEffect#SPELL_MOB}, {@link ParticleEffect#SPELL_MOB_AMBIENT}, {@link ParticleEffect#REDSTONE} and {@link ParticleEffect#NOTE}
+ *
+ * This class is part of the ParticleEffect Library and follows the same usage conditions
+ *
+ * @author DarkBlade12
+ * @since 1.7
+ */
+ public static abstract class ParticleColor {
+ /**
+ * Returns the value for the offsetX field
+ *
+ * @return The offsetX value
+ */
+ public abstract float getValueX();
+
+ /**
+ * Returns the value for the offsetY field
+ *
+ * @return The offsetY value
+ */
+ public abstract float getValueY();
+
+ /**
+ * Returns the value for the offsetZ field
+ *
+ * @return The offsetZ value
+ */
+ public abstract float getValueZ();
+ }
+
+ /**
+ * Represents the color for effects like {@link ParticleEffect#SPELL_MOB}, {@link ParticleEffect#SPELL_MOB_AMBIENT} and {@link ParticleEffect#NOTE}
+ *
+ * This class is part of the ParticleEffect Library and follows the same usage conditions
+ *
+ * @author DarkBlade12
+ * @since 1.7
+ */
+ public static final class OrdinaryColor extends ParticleColor {
+ private final int red;
+ private final int green;
+ private final int blue;
+
+ /**
+ * Construct a new ordinary color
+ *
+ * @param red Red value of the RGB format
+ * @param green Green value of the RGB format
+ * @param blue Blue value of the RGB format
+ * @throws IllegalArgumentException If one of the values is lower than 0 or higher than 255
+ */
+ public OrdinaryColor(int red, int green, int blue) throws IllegalArgumentException {
+ if (red < 0) {
+ throw new IllegalArgumentException("The red value is lower than 0");
+ }
+ if (red > 255) {
+ throw new IllegalArgumentException("The red value is higher than 255");
+ }
+ this.red = red;
+ if (green < 0) {
+ throw new IllegalArgumentException("The green value is lower than 0");
+ }
+ if (green > 255) {
+ throw new IllegalArgumentException("The green value is higher than 255");
+ }
+ this.green = green;
+ if (blue < 0) {
+ throw new IllegalArgumentException("The blue value is lower than 0");
+ }
+ if (blue > 255) {
+ throw new IllegalArgumentException("The blue value is higher than 255");
+ }
+ this.blue = blue;
+ }
+
+ /**
+ * Construct a new ordinary color
+ *
+ * @param color Bukkit color
+ */
+ public OrdinaryColor(Color color) {
+ this(color.getRed(), color.getGreen(), color.getBlue());
+ }
+
+ /**
+ * Returns the red value of the RGB format
+ *
+ * @return The red value
+ */
+ public int getRed() {
+ return red;
+ }
+
+ /**
+ * Returns the green value of the RGB format
+ *
+ * @return The green value
+ */
+ public int getGreen() {
+ return green;
+ }
+
+ /**
+ * Returns the blue value of the RGB format
+ *
+ * @return The blue value
+ */
+ public int getBlue() {
+ return blue;
+ }
+
+ /**
+ * Returns the red value divided by 255
+ *
+ * @return The offsetX value
+ */
+ @Override
+ public float getValueX() {
+ return (float) red / 255F;
+ }
+
+ /**
+ * Returns the green value divided by 255
+ *
+ * @return The offsetY value
+ */
+ @Override
+ public float getValueY() {
+ return (float) green / 255F;
+ }
+
+ /**
+ * Returns the blue value divided by 255
+ *
+ * @return The offsetZ value
+ */
+ @Override
+ public float getValueZ() {
+ return (float) blue / 255F;
+ }
+ }
+
+ /**
+ * Represents the color for the {@link ParticleEffect#NOTE} effect
+ *
+ * This class is part of the ParticleEffect Library and follows the same usage conditions
+ *
+ * @author DarkBlade12
+ * @since 1.7
+ */
+ public static final class NoteColor extends ParticleColor {
+ private final int note;
+
+ /**
+ * Construct a new note color
+ *
+ * @param note Note id which determines color
+ * @throws IllegalArgumentException If the note value is lower than 0 or higher than 24
+ */
+ public NoteColor(int note) throws IllegalArgumentException {
+ if (note < 0) {
+ throw new IllegalArgumentException("The note value is lower than 0");
+ }
+ if (note > 24) {
+ throw new IllegalArgumentException("The note value is higher than 24");
+ }
+ this.note = note;
+ }
+
+ /**
+ * Returns the note value divided by 24
+ *
+ * @return The offsetX value
+ */
+ @Override
+ public float getValueX() {
+ return (float) note / 24F;
+ }
+
+ /**
+ * Returns zero because the offsetY value is unused
+ *
+ * @return zero
+ */
+ @Override
+ public float getValueY() {
+ return 0;
+ }
+
+ /**
+ * Returns zero because the offsetZ value is unused
+ *
+ * @return zero
+ */
+ @Override
+ public float getValueZ() {
+ return 0;
+ }
+
+ }
+
+ /**
+ * Represents a runtime exception that is thrown either if the displayed particle effect requires data and has none or vice-versa or if the data type is incorrect
+ *
+ * This class is part of the ParticleEffect Library and follows the same usage conditions
+ *
+ * @author DarkBlade12
+ * @since 1.6
+ */
+ private static final class ParticleDataException extends RuntimeException {
+ private static final long serialVersionUID = 3203085387160737484L;
+
+ /**
+ * Construct a new particle data exception
+ *
+ * @param message Message that will be logged
+ */
+ public ParticleDataException(String message) {
+ super(message);
+ }
+ }
+
+ /**
+ * Represents a runtime exception that is thrown either if the displayed particle effect is not colorable or if the particle color type is incorrect
+ *
+ * This class is part of the ParticleEffect Library and follows the same usage conditions
+ *
+ * @author DarkBlade12
+ * @since 1.7
+ */
+ private static final class ParticleColorException extends RuntimeException {
+ private static final long serialVersionUID = 3203085387160737484L;
+
+ /**
+ * Construct a new particle color exception
+ *
+ * @param message Message that will be logged
+ */
+ public ParticleColorException(String message) {
+ super(message);
+ }
+ }
+
+ /**
+ * Represents a runtime exception that is thrown if the displayed particle effect requires a newer version
+ *
+ * This class is part of the ParticleEffect Library and follows the same usage conditions
+ *
+ * @author DarkBlade12
+ * @since 1.6
+ */
+ private static final class ParticleVersionException extends RuntimeException {
+ private static final long serialVersionUID = 3203085387160737484L;
+
+ /**
+ * Construct a new particle version exception
+ *
+ * @param message Message that will be logged
+ */
+ public ParticleVersionException(String message) {
+ super(message);
+ }
+ }
+
+ /**
+ * Represents a particle effect packet with all attributes which is used for sending packets to the players
+ *
+ * This class is part of the ParticleEffect Library and follows the same usage conditions
+ *
+ * @author DarkBlade12
+ * @since 1.5
+ */
+ public static final class ParticlePacket {
+ private static int version;
+ private static Class> enumParticle;
+ private static Constructor> packetConstructor;
+ private static Method getHandle;
+ private static Field playerConnection;
+ private static Method sendPacket;
+ private static boolean initialized;
+ private final ParticleEffect effect;
+ private float offsetX;
+ private final float offsetY;
+ private final float offsetZ;
+ private final float speed;
+ private final int amount;
+ private final boolean longDistance;
+ private final ParticleData data;
+ private Object packet;
+
+ /**
+ * Construct a new particle packet
+ *
+ * @param effect Particle effect
+ * @param offsetX Maximum distance particles can fly away from the center on the x-axis
+ * @param offsetY Maximum distance particles can fly away from the center on the y-axis
+ * @param offsetZ Maximum distance particles can fly away from the center on the z-axis
+ * @param speed Display speed of the particles
+ * @param amount Amount of particles
+ * @param longDistance Indicates whether the maximum distance is increased from 256 to 65536
+ * @param data Data of the effect
+ * @throws IllegalArgumentException If the speed or amount is lower than 0
+ * @see #initialize()
+ */
+ public ParticlePacket(ParticleEffect effect, float offsetX, float offsetY, float offsetZ, float speed, int amount, boolean longDistance, ParticleData data) throws IllegalArgumentException {
+ initialize();
+ if (speed < 0) {
+ throw new IllegalArgumentException("The speed is lower than 0");
+ }
+ if (amount < 0) {
+ throw new IllegalArgumentException("The amount is lower than 0");
+ }
+ this.effect = effect;
+ this.offsetX = offsetX;
+ this.offsetY = offsetY;
+ this.offsetZ = offsetZ;
+ this.speed = speed;
+ this.amount = amount;
+ this.longDistance = longDistance;
+ this.data = data;
+ }
+
+ /**
+ * Construct a new particle packet of a single particle flying into a determined direction
+ *
+ * @param effect Particle effect
+ * @param direction Direction of the particle
+ * @param speed Display speed of the particle
+ * @param longDistance Indicates whether the maximum distance is increased from 256 to 65536
+ * @param data Data of the effect
+ * @throws IllegalArgumentException If the speed is lower than 0
+ * @see #ParticleEffect(ParticleEffect, float, float, float, float, int, boolean, ParticleData)
+ */
+ public ParticlePacket(ParticleEffect effect, Vector direction, float speed, boolean longDistance, ParticleData data) throws IllegalArgumentException {
+ this(effect, (float) direction.getX(), (float) direction.getY(), (float) direction.getZ(), speed, 0, longDistance, data);
+ }
+
+ /**
+ * Construct a new particle packet of a single colored particle
+ *
+ * @param effect Particle effect
+ * @param color Color of the particle
+ * @param longDistance Indicates whether the maximum distance is increased from 256 to 65536
+ * @see #ParticleEffect(ParticleEffect, float, float, float, float, int, boolean, ParticleData)
+ */
+ public ParticlePacket(ParticleEffect effect, ParticleColor color, boolean longDistance) {
+ this(effect, color.getValueX(), color.getValueY(), color.getValueZ(), 1, 0, longDistance, null);
+ if (effect == ParticleEffect.REDSTONE && color instanceof OrdinaryColor && ((OrdinaryColor) color).getRed() == 0) {
+ offsetX = Float.MIN_NORMAL;
+ }
+ }
+
+ /**
+ * Initializes {@link #packetConstructor}, {@link #getHandle}, {@link #playerConnection} and {@link #sendPacket} and sets {@link #initialized} to true
if it succeeds
+ *
+ * Note: These fields only have to be initialized once, so it will return if {@link #initialized} is already set to true
+ *
+ * @throws VersionIncompatibleException if your bukkit version is not supported by this library
+ */
+ public static void initialize() throws VersionIncompatibleException {
+ if (initialized) {
+ return;
+ }
+ try {
+ version = Integer.parseInt(Character.toString(PackageType.getServerVersion().charAt(3)));
+ if (version > 7) {
+ enumParticle = PackageType.MINECRAFT_SERVER.getClass("EnumParticle");
+ }
+ Class> packetClass = PackageType.MINECRAFT_SERVER.getClass(version < 7 ? "Packet63WorldParticles" : "PacketPlayOutWorldParticles");
+ packetConstructor = ReflectionUtils.getConstructor(packetClass);
+ getHandle = ReflectionUtils.getMethod("CraftPlayer", PackageType.CRAFTBUKKIT_ENTITY, "getHandle");
+ playerConnection = ReflectionUtils.getField("EntityPlayer", PackageType.MINECRAFT_SERVER, false, "playerConnection");
+ sendPacket = ReflectionUtils.getMethod(playerConnection.getType(), "sendPacket", PackageType.MINECRAFT_SERVER.getClass("Packet"));
+ } catch (Exception exception) {
+ throw new VersionIncompatibleException("Your current bukkit version seems to be incompatible with this library", exception);
+ }
+ initialized = true;
+ }
+
+ /**
+ * Returns the version of your server (1.x)
+ *
+ * @return The version number
+ */
+ public static int getVersion() {
+ if (!initialized) {
+ initialize();
+ }
+ return version;
+ }
+
+ /**
+ * Determine if {@link #packetConstructor}, {@link #getHandle}, {@link #playerConnection} and {@link #sendPacket} are initialized
+ *
+ * @return Whether these fields are initialized or not
+ * @see #initialize()
+ */
+ public static boolean isInitialized() {
+ return initialized;
+ }
+
+ /**
+ * Initializes {@link #packet} with all set values
+ *
+ * @param center Center location of the effect
+ * @throws PacketInstantiationException If instantion fails due to an unknown error
+ */
+ private void initializePacket(Location center) throws PacketInstantiationException {
+ if (packet != null) {
+ return;
+ }
+ try {
+ packet = packetConstructor.newInstance();
+ if (version < 8) {
+ String name = effect.getName();
+ if (data != null) {
+ name += data.getPacketDataString();
+ }
+ ReflectionUtils.setValue(packet, true, "a", name);
+ } else {
+ ReflectionUtils.setValue(packet, true, "a", enumParticle.getEnumConstants()[effect.getId()]);
+ ReflectionUtils.setValue(packet, true, "j", longDistance);
+ if (data != null) {
+ int[] packetData = data.getPacketData();
+ ReflectionUtils.setValue(packet, true, "k", effect == ParticleEffect.ITEM_CRACK ? packetData : new int[] { packetData[0] | (packetData[1] << 12) });
+ }
+ }
+ ReflectionUtils.setValue(packet, true, "b", (float) center.getX());
+ ReflectionUtils.setValue(packet, true, "c", (float) center.getY());
+ ReflectionUtils.setValue(packet, true, "d", (float) center.getZ());
+ ReflectionUtils.setValue(packet, true, "e", offsetX);
+ ReflectionUtils.setValue(packet, true, "f", offsetY);
+ ReflectionUtils.setValue(packet, true, "g", offsetZ);
+ ReflectionUtils.setValue(packet, true, "h", speed);
+ ReflectionUtils.setValue(packet, true, "i", amount);
+ } catch (Exception exception) {
+ throw new PacketInstantiationException("Packet instantiation failed", exception);
+ }
+ }
+
+ /**
+ * Sends the packet to a single player and caches it
+ *
+ * @param center Center location of the effect
+ * @param player Receiver of the packet
+ * @throws PacketInstantiationException If instantion fails due to an unknown error
+ * @throws PacketSendingException If sending fails due to an unknown error
+ * @see #initializePacket(Location)
+ */
+ public void sendTo(Location center, Player player) throws PacketInstantiationException, PacketSendingException {
+ initializePacket(center);
+ try {
+ sendPacket.invoke(playerConnection.get(getHandle.invoke(player)), packet);
+ } catch (Exception exception) {
+ throw new PacketSendingException("Failed to send the packet to player '" + player.getName() + "'", exception);
+ }
+ }
+
+ /**
+ * Sends the packet to all players in the list
+ *
+ * @param center Center location of the effect
+ * @param players Receivers of the packet
+ * @throws IllegalArgumentException If the player list is empty
+ * @see #sendTo(Location center, Player player)
+ */
+ public void sendTo(Location center, List players) throws IllegalArgumentException {
+ if (players.isEmpty()) {
+ throw new IllegalArgumentException("The player list is empty");
+ }
+ for (Player player : players) {
+ sendTo(center, player);
+ }
+ }
+
+ /**
+ * Sends the packet to all players in a certain range
+ *
+ * @param center Center location of the effect
+ * @param range Range in which players will receive the packet (Maximum range for particles is usually 16, but it can differ for some types)
+ * @throws IllegalArgumentException If the range is lower than 1
+ * @see #sendTo(Location center, Player player)
+ */
+ public void sendTo(Location center, double range) throws IllegalArgumentException {
+ if (range < 1) {
+ throw new IllegalArgumentException("The range is lower than 1");
+ }
+ String worldName = center.getWorld().getName();
+ double squared = range * range;
+ for (Player player : Bukkit.getOnlinePlayers()) {
+ if (!player.getWorld().getName().equals(worldName) || player.getLocation().distanceSquared(center) > squared) {
+ continue;
+ }
+ sendTo(center, player);
+ }
+ }
+
+ /**
+ * Represents a runtime exception that is thrown if a bukkit version is not compatible with this library
+ *
+ * This class is part of the ParticleEffect Library and follows the same usage conditions
+ *
+ * @author DarkBlade12
+ * @since 1.5
+ */
+ private static final class VersionIncompatibleException extends RuntimeException {
+ private static final long serialVersionUID = 3203085387160737484L;
+
+ /**
+ * Construct a new version incompatible exception
+ *
+ * @param message Message that will be logged
+ * @param cause Cause of the exception
+ */
+ public VersionIncompatibleException(String message, Throwable cause) {
+ super(message, cause);
+ }
+ }
+
+ /**
+ * Represents a runtime exception that is thrown if packet instantiation fails
+ *
+ * This class is part of the ParticleEffect Library and follows the same usage conditions
+ *
+ * @author DarkBlade12
+ * @since 1.4
+ */
+ private static final class PacketInstantiationException extends RuntimeException {
+ private static final long serialVersionUID = 3203085387160737484L;
+
+ /**
+ * Construct a new packet instantiation exception
+ *
+ * @param message Message that will be logged
+ * @param cause Cause of the exception
+ */
+ public PacketInstantiationException(String message, Throwable cause) {
+ super(message, cause);
+ }
+ }
+
+ /**
+ * Represents a runtime exception that is thrown if packet sending fails
+ *
+ * This class is part of the ParticleEffect Library and follows the same usage conditions
+ *
+ * @author DarkBlade12
+ * @since 1.4
+ */
+ private static final class PacketSendingException extends RuntimeException {
+ private static final long serialVersionUID = 3203085387160737484L;
+
+ /**
+ * Construct a new packet sending exception
+ *
+ * @param message Message that will be logged
+ * @param cause Cause of the exception
+ */
+ public PacketSendingException(String message, Throwable cause) {
+ super(message, cause);
+ }
+ }
+ }
+}
\ No newline at end of file
diff --git a/src/eu/univento/core/api/effects/WorldBoarder.java b/src/main/java/eu/univento/core/api/effects/WorldBoarder.java
similarity index 100%
rename from src/eu/univento/core/api/effects/WorldBoarder.java
rename to src/main/java/eu/univento/core/api/effects/WorldBoarder.java
diff --git a/src/eu/univento/core/api/entity/EntityModifier.java b/src/main/java/eu/univento/core/api/entity/EntityModifier.java
similarity index 94%
rename from src/eu/univento/core/api/entity/EntityModifier.java
rename to src/main/java/eu/univento/core/api/entity/EntityModifier.java
index 6841e6a..3804106 100644
--- a/src/eu/univento/core/api/entity/EntityModifier.java
+++ b/src/main/java/eu/univento/core/api/entity/EntityModifier.java
@@ -1,12 +1,12 @@
package eu.univento.core.api.entity;
-import net.minecraft.server.v1_8_R3.EntityLiving;
-import net.minecraft.server.v1_8_R3.NBTTagCompound;
+import net.minecraft.server.v1_9_R1.EntityLiving;
+import net.minecraft.server.v1_9_R1.NBTTagCompound;
import org.bukkit.Bukkit;
import org.bukkit.EntityEffect;
import org.bukkit.Location;
-import org.bukkit.craftbukkit.v1_8_R3.entity.CraftCreature;
-import org.bukkit.craftbukkit.v1_8_R3.entity.CraftEntity;
+import org.bukkit.craftbukkit.v1_9_R1.entity.CraftCreature;
+import org.bukkit.craftbukkit.v1_9_R1.entity.CraftEntity;
import org.bukkit.entity.Player;
import org.bukkit.plugin.Plugin;
@@ -21,7 +21,7 @@ public class EntityModifier
{
static org.bukkit.entity.Entity entity;
static CraftEntity craftentity;
- static net.minecraft.server.v1_8_R3.Entity entityS;
+ static net.minecraft.server.v1_9_R1.Entity entityS;
static int scheduler;
static Plugin plugin;
static Player player = null;
@@ -122,7 +122,7 @@ public class EntityModifier
{
try
{
- Field invulnerableField = net.minecraft.server.v1_8_R3.Entity.class
+ Field invulnerableField = net.minecraft.server.v1_9_R1.Entity.class
.getDeclaredField("invulnerable");
invulnerableField.setAccessible(true);
invulnerableField.setBoolean(EntityModifier.entityS, invulnerable);
diff --git a/src/eu/univento/core/api/events/MoveEventFilter.java b/src/main/java/eu/univento/core/api/events/MoveEventFilter.java
similarity index 100%
rename from src/eu/univento/core/api/events/MoveEventFilter.java
rename to src/main/java/eu/univento/core/api/events/MoveEventFilter.java
diff --git a/src/eu/univento/core/api/fakeplayer/FakePlayer.java b/src/main/java/eu/univento/core/api/fakeplayer/FakePlayer.java
similarity index 95%
rename from src/eu/univento/core/api/fakeplayer/FakePlayer.java
rename to src/main/java/eu/univento/core/api/fakeplayer/FakePlayer.java
index 0bd98e5..8ed0956 100644
--- a/src/eu/univento/core/api/fakeplayer/FakePlayer.java
+++ b/src/main/java/eu/univento/core/api/fakeplayer/FakePlayer.java
@@ -2,9 +2,9 @@ package eu.univento.core.api.fakeplayer;
import com.mojang.authlib.GameProfile;
import eu.univento.core.Core;
-import net.minecraft.server.v1_8_R3.*;
+import net.minecraft.server.v1_9_R1.*;
import org.bukkit.Location;
-import org.bukkit.craftbukkit.v1_8_R3.entity.CraftPlayer;
+import org.bukkit.craftbukkit.v1_9_R1.entity.CraftPlayer;
import org.bukkit.entity.ArmorStand;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.LivingEntity;
@@ -21,6 +21,8 @@ import java.util.Arrays;
*/
public class FakePlayer {
+ //TODO: fix parts and add some stuff
+
private static final double MOVE_SPEED = 4.3D / 20;
private Player player;
@@ -47,9 +49,9 @@ public class FakePlayer {
this.dataWatcher = new DataWatcher(null);
byte status = 0;
- this.dataWatcher.a(0, status);
- this.dataWatcher.a(10, (byte) 127);
- this.dataWatcher.a(6, 20F);
+ //this.dataWatcher.a(0, status);
+ //this.dataWatcher.a(10, (byte) 127);
+ //this.dataWatcher.a(6, 20F);
}
private final BukkitRunnable tickTask = new BukkitRunnable() {
@@ -106,9 +108,9 @@ public class FakePlayer {
DataWatcher dataWatcher = this.dataWatcher;
byte status = 0;
status = changeMask(status, data, bool);
- dataWatcher.a(0, status);
- dataWatcher.a(10, (byte) 127);
- dataWatcher.a(6, 20F);
+ //dataWatcher.a(0, status);
+ //dataWatcher.a(10, (byte) 127);
+ //dataWatcher.a(6, 20F);
}
public void followEntity(LivingEntity entity) {
diff --git a/src/eu/univento/core/api/fakeplayer/PlayerKi.java b/src/main/java/eu/univento/core/api/fakeplayer/PlayerKi.java
similarity index 100%
rename from src/eu/univento/core/api/fakeplayer/PlayerKi.java
rename to src/main/java/eu/univento/core/api/fakeplayer/PlayerKi.java
diff --git a/src/main/java/eu/univento/core/api/game/Team.java b/src/main/java/eu/univento/core/api/game/Team.java
new file mode 100644
index 0000000..43e9fb6
--- /dev/null
+++ b/src/main/java/eu/univento/core/api/game/Team.java
@@ -0,0 +1,59 @@
+package eu.univento.core.api.game;
+
+import eu.univento.core.api.player.CustomPlayer;
+import org.bukkit.Bukkit;
+
+import java.util.ArrayList;
+
+/**
+ * @author joethei
+ * @version 0.1
+ */
+public class Team {
+
+ private ArrayList players = new ArrayList<>();
+ private String name;
+ private String prefix;
+ private org.bukkit.scoreboard.Team team;
+
+ public Team(String name, String prefix) {
+ this.name = name;
+ this.prefix = prefix;
+ if(Bukkit.getScoreboardManager().getMainScoreboard().getTeam(name) == null) {
+ team = Bukkit.getScoreboardManager().getMainScoreboard().registerNewTeam(name);
+ }else{
+ team = Bukkit.getScoreboardManager().getMainScoreboard().getTeam(name);
+ }
+ team.setPrefix(prefix);
+ }
+
+ public void addPlayer(CustomPlayer p) {
+ players.add(p);
+ team.addEntry(p.getName());
+ }
+
+ public void removePlayer(CustomPlayer p) {
+ players.remove(p);
+ team.removeEntry(p.getName());
+ }
+
+ public boolean isPlayer(CustomPlayer p) {
+ return players.contains(p);
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public String getPrefix() {
+ return prefix;
+ }
+
+ public ArrayList getPlayers() {
+ return players;
+ }
+
+ public org.bukkit.scoreboard.Team getScoreboardTeam() {
+ return team;
+ }
+}
\ No newline at end of file
diff --git a/src/main/java/eu/univento/core/api/game/TeamManager.java b/src/main/java/eu/univento/core/api/game/TeamManager.java
new file mode 100644
index 0000000..f9d5b15
--- /dev/null
+++ b/src/main/java/eu/univento/core/api/game/TeamManager.java
@@ -0,0 +1,41 @@
+package eu.univento.core.api.game;
+
+import eu.univento.core.api.player.CustomPlayer;
+
+import java.util.ArrayList;
+
+/**
+ * @author joethei
+ * @version 0.1
+ */
+public class TeamManager {
+
+ private static ArrayList teams = new ArrayList<>();
+
+ public static ArrayList getTeams() {
+ return teams;
+ }
+
+ public static Team getTeam(String name) {
+ for(Team team : teams) {
+ if(team.getName().equalsIgnoreCase(name)) return team;
+ }
+ return null;
+ }
+
+ public static Team getTeam(CustomPlayer p) {
+ for(Team team : teams) {
+ if(team.isPlayer(p)) return team;
+ }
+ return null;
+ }
+
+ public static void addTeam(Team team) {
+ teams.add(team);
+ }
+
+ public static void removeTeam(Team team) {
+ teams.remove(team);
+ }
+
+}
\ No newline at end of file
diff --git a/src/eu/univento/core/api/gui/AnvilGui.java b/src/main/java/eu/univento/core/api/gui/AnvilGUI.java
similarity index 98%
rename from src/eu/univento/core/api/gui/AnvilGui.java
rename to src/main/java/eu/univento/core/api/gui/AnvilGUI.java
index 834d1ec..ad824a0 100644
--- a/src/eu/univento/core/api/gui/AnvilGui.java
+++ b/src/main/java/eu/univento/core/api/gui/AnvilGUI.java
@@ -1,9 +1,9 @@
package eu.univento.core.api.gui;
import eu.univento.core.Core;
-import net.minecraft.server.v1_8_R3.*;
+import net.minecraft.server.v1_9_R1.*;
import org.bukkit.Bukkit;
-import org.bukkit.craftbukkit.v1_8_R3.entity.CraftPlayer;
+import org.bukkit.craftbukkit.v1_9_R1.entity.CraftPlayer;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.HandlerList;
diff --git a/src/main/java/eu/univento/core/api/gui/PlayerSignInputEvent.java b/src/main/java/eu/univento/core/api/gui/PlayerSignInputEvent.java
new file mode 100644
index 0000000..fb78412
--- /dev/null
+++ b/src/main/java/eu/univento/core/api/gui/PlayerSignInputEvent.java
@@ -0,0 +1,30 @@
+package eu.univento.core.api.gui;
+
+import org.bukkit.entity.Player;
+import org.bukkit.event.HandlerList;
+import org.bukkit.event.player.PlayerEvent;
+
+/**
+ * @author joethei
+ * @version 0.1
+ */
+public class PlayerSignInputEvent extends PlayerEvent{
+
+ public static HandlerList handlerList = new HandlerList();
+ public String[] lines;
+
+ public PlayerSignInputEvent(Player p, String[] lines) {
+ super(p);
+ this.lines = lines;
+ SignInputHandler.ejectNetty(p);
+ }
+
+ @Override
+ public HandlerList getHandlers() {
+ return handlerList;
+ }
+
+ public String[] getLines() {
+ return lines;
+ }
+}
\ No newline at end of file
diff --git a/src/main/java/eu/univento/core/api/gui/SignInput.java b/src/main/java/eu/univento/core/api/gui/SignInput.java
new file mode 100644
index 0000000..9bf1d4b
--- /dev/null
+++ b/src/main/java/eu/univento/core/api/gui/SignInput.java
@@ -0,0 +1,21 @@
+package eu.univento.core.api.gui;
+
+import eu.univento.core.api.player.CustomPlayer;
+import net.minecraft.server.v1_9_R1.BlockPosition;
+import net.minecraft.server.v1_9_R1.EntityPlayer;
+import net.minecraft.server.v1_9_R1.PacketPlayOutOpenSignEditor;
+
+/**
+ * @author joethei
+ * @version 0.1
+ */
+public class SignInput {
+
+ public static void openSignInput(CustomPlayer p) {
+ EntityPlayer player = p.getHandle();
+ BlockPosition bp = new BlockPosition(p.getHandle());
+ PacketPlayOutOpenSignEditor packet = new PacketPlayOutOpenSignEditor(bp);
+ player.playerConnection.sendPacket(packet);
+ SignInputHandler.injectNetty(p);
+ }
+}
\ No newline at end of file
diff --git a/src/main/java/eu/univento/core/api/gui/SignInputHandler.java b/src/main/java/eu/univento/core/api/gui/SignInputHandler.java
new file mode 100644
index 0000000..dd2b700
--- /dev/null
+++ b/src/main/java/eu/univento/core/api/gui/SignInputHandler.java
@@ -0,0 +1,67 @@
+package eu.univento.core.api.gui;
+
+import io.netty.channel.Channel;
+import io.netty.channel.ChannelHandlerContext;
+import io.netty.handler.codec.MessageToMessageDecoder;
+import net.minecraft.server.v1_9_R1.NetworkManager;
+import net.minecraft.server.v1_9_R1.Packet;
+import net.minecraft.server.v1_9_R1.PacketPlayInUpdateSign;
+import org.bukkit.Bukkit;
+import org.bukkit.craftbukkit.v1_9_R1.entity.CraftPlayer;
+import org.bukkit.entity.Player;
+
+import java.lang.reflect.Field;
+import java.util.List;
+
+/**
+ * @author joethei
+ * @version 0.1
+ */
+public class SignInputHandler {
+
+ private static Field channelField;
+
+ static{
+ for(Field filed : NetworkManager.class.getDeclaredFields()) {
+ if(channelField.getType().isAssignableFrom(Channel.class)) {
+ channelField = filed;
+ break;
+ }
+ }
+ }
+
+ public static void injectNetty(final Player player) {
+ try {
+ Channel channel = (Channel) channelField.get(((CraftPlayer) player).getHandle().playerConnection.networkManager);
+ if (channel != null) {
+ channel.pipeline().addAfter("decoder", "update_sign", new MessageToMessageDecoder() {
+
+ @Override
+ protected void decode(ChannelHandlerContext chc, Packet packet, List