diff --git a/Core.iml b/Core.iml
index 9e1f47a..01c10d7 100644
--- a/Core.iml
+++ b/Core.iml
@@ -12,23 +12,24 @@
-
-
+
-
+
+
-
-
+
+
+
\ No newline at end of file
diff --git a/pom.xml b/pom.xml
index 3baded1..f5bd412 100644
--- a/pom.xml
+++ b/pom.xml
@@ -59,14 +59,14 @@
- org.bukkit
- craftbukkit
+ org.spigotmc
+ spigot-api
1.10-R0.1-SNAPSHOT
provided
org.bukkit
- bukkit
+ craftbukkit
1.10-R0.1-SNAPSHOT
provided
@@ -85,17 +85,22 @@
netty-all
4.0.36.Final
-
- org.spigotmc
- spigot-api
- 1.10-R0.1-SNAPSHOT
- provided
-
com.google.code.gson
gson
2.3.1
+
+ com.zaxxer
+ HikariCP
+ 2.4.5
+ compile
+
+
+ com.google.guava
+ guava
+ 19.0
+
\ No newline at end of file
diff --git a/src/main/java/eu/univento/cloud/client/CloudManager.java b/src/main/java/eu/univento/cloud/client/CloudManager.java
new file mode 100644
index 0000000..60266fa
--- /dev/null
+++ b/src/main/java/eu/univento/cloud/client/CloudManager.java
@@ -0,0 +1,10 @@
+package eu.univento.cloud.client;
+
+/**
+ * @author joethei
+ * @version 0.1
+ * created on 08.07.2016
+ */
+public class CloudManager {
+
+}
\ No newline at end of file
diff --git a/src/main/java/eu/univento/cloud/client/CloudMessenger.java b/src/main/java/eu/univento/cloud/client/CloudMessenger.java
index 832c7e3..417e106 100644
--- a/src/main/java/eu/univento/cloud/client/CloudMessenger.java
+++ b/src/main/java/eu/univento/cloud/client/CloudMessenger.java
@@ -5,6 +5,8 @@ import eu.univento.core.api.player.CustomPlayer;
public class CloudMessenger {
+
+
public static void sendModModeMessage(ModModePrefix prefix, String message) {
//TODO: add stuff + server
}
diff --git a/src/main/java/eu/univento/core/Core.java b/src/main/java/eu/univento/core/Core.java
index 32edc74..cbe179b 100644
--- a/src/main/java/eu/univento/core/Core.java
+++ b/src/main/java/eu/univento/core/Core.java
@@ -3,6 +3,7 @@ package eu.univento.core;
import eu.univento.core.antihack.AntiHack;
import eu.univento.core.api.Blackscreen;
import eu.univento.core.api.Config;
+import eu.univento.core.api.database.DatabaseManager;
import eu.univento.core.api.database.MongoDB;
import eu.univento.core.api.database.MySQL;
import eu.univento.core.api.events.MoveEventFilter;
@@ -45,22 +46,37 @@ public class Core extends JavaPlugin{
/**
* mysql stuff
*/
- private static MySQL sql = new MySQL(getInstance(), Config.readString("MySQL.Host"), Config.readString("MySQL.Port"), Config.readString("MySQL.DB"), Config.readString("MySQL.User"), Config.readString("MySQL.Pass"));
+ private static MySQL sql = new MySQL(getInstance(), Config.readString("MySQL.Host"), Config.readString("MySQL.Port"), Config.readString("MySQL.DB"), Config.readString("MySQL.User"), Config.readString("MySQL.Pass"));
/**
* @return sql
*/
- public static MySQL returnSQL() {
+ public static MySQL getMySQL() {
return sql;
}
+ /*
+ private static AsyncMySQL asyncMySQL = new AsyncMySQL(getInstance(), Config.readString("MySQL.Host"), Config.readString("MySQL.Port"), Config.readString("MySQL.DB"), Config.readString("MySQL.User"), Config.readString("MySQL.Pass"));
+ public static AsyncMySQL getAsyncMySQL() {
+ return asyncMySQL;
+ }
+ */
private static MongoDB mongoDB;
public static MongoDB getMongoDB() {
return mongoDB;
}
- /**
- * logging and stuff
- */
+ /*
+ private static AsyncMongoDB asyncMongoDB;
+ public static AsyncMongoDB getAsyncMongoDB() {
+ return asyncMongoDB;
+ }
+ */
+
+ private static DatabaseManager databaseManager;
+ public static DatabaseManager getDatabaseManager() {
+ return databaseManager;
+ }
+
private static Logger log = Bukkit.getLogger();
public static ArrayList getOnlinePlayers() {
@@ -101,7 +117,6 @@ public class Core extends JavaPlugin{
if(ServerSettings.isGame()) {
new Fix(this, "fix", "fix");
- new Stats(this, "stats", "statistics");
new Nick(this, "nick", "nick");
}
AntiHack.registerListeners();
@@ -130,8 +145,9 @@ public class Core extends JavaPlugin{
Bukkit.getMessenger().registerOutgoingPluginChannel(this, "schematica");
Blackscreen.setupUtil(getInstance());
+ databaseManager = new DatabaseManager(getInstance());
mongoDB = new MongoDB(Config.readString("MongoDB.Host"), Config.readInt("MongoDB.Port"), Config.readString("MongoDB.User"), Config.readString("MongoDB.Password"), Config.readString("MongoDB.Database"));
-
+ //asyncMongoDB = new AsyncMongoDB(Config.readString("MongoDB.Host"), Config.readInt("MongoDB.Port"), Config.readString("MongoDB.User"), Config.readString("MongoDB.Password"), Config.readString("MongoDB.Database"));
log(Level.INFO, "\n" +
"\n" +
" \n" +
@@ -176,6 +192,7 @@ public class Core extends JavaPlugin{
@Override
public void onDisable() {
mongoDB.getClient().close();
+ databaseManager.closeConnections();
Bukkit.getMessenger().unregisterOutgoingPluginChannel(this, "BungeeCord");
Bukkit.getMessenger().unregisterIncomingPluginChannel(this, "BungeeCord");
Bukkit.getMessenger().unregisterOutgoingPluginChannel(this, "LABYMOD");
diff --git a/src/main/java/eu/univento/core/antihack/Hack.java b/src/main/java/eu/univento/core/antihack/Hack.java
index 9aac7b0..1a50edf 100644
--- a/src/main/java/eu/univento/core/antihack/Hack.java
+++ b/src/main/java/eu/univento/core/antihack/Hack.java
@@ -12,7 +12,8 @@ public enum Hack {
FASTPLACE(10),
KILLAURA(10),
FLY(10),
- WDL(10);
+ WDL(10),
+ NUKER(10);
private int id;
private Hack(int id) {
diff --git a/src/main/java/eu/univento/core/antihack/modules/Nuker.java b/src/main/java/eu/univento/core/antihack/modules/Nuker.java
new file mode 100644
index 0000000..9c57c07
--- /dev/null
+++ b/src/main/java/eu/univento/core/antihack/modules/Nuker.java
@@ -0,0 +1,37 @@
+package eu.univento.core.antihack.modules;
+
+import eu.univento.cloud.client.CloudMessenger;
+import eu.univento.core.antihack.Hack;
+import eu.univento.core.api.player.CustomPlayer;
+import org.bukkit.event.EventHandler;
+import org.bukkit.event.Listener;
+import org.bukkit.event.block.BlockBreakEvent;
+
+import java.util.LinkedHashMap;
+
+/**
+ * @author joethei
+ * @version 0.1
+ * created on 01.07.2016
+ */
+public class Nuker implements Listener {
+
+ private LinkedHashMap last = new LinkedHashMap<>();
+ private LinkedHashMap blocks = new LinkedHashMap<>();
+
+ @EventHandler
+ public void onBlockBreak(BlockBreakEvent e) {
+ CustomPlayer p = CustomPlayer.getPlayer(e.getPlayer());
+ if(last.get(p) != null && last.get(p) + 50000L >= System.currentTimeMillis()) {
+ last.put(p, System.currentTimeMillis());
+ blocks.put(p, blocks.get(p) + 1);
+ if(blocks.get(p) > 80) {
+ e.setCancelled(true);
+ CloudMessenger.sendHackMessage(Hack.NUKER, p);
+ p.warn(Hack.NUKER);
+ }
+ }else{
+ blocks.put(p, 0);
+ }
+ }
+}
\ No newline at end of file
diff --git a/src/main/java/eu/univento/core/api/database/AsyncMongoDB.java b/src/main/java/eu/univento/core/api/database/AsyncMongoDB.java
new file mode 100644
index 0000000..dfca444
--- /dev/null
+++ b/src/main/java/eu/univento/core/api/database/AsyncMongoDB.java
@@ -0,0 +1,47 @@
+package eu.univento.core.api.database;
+
+
+import com.mongodb.MongoCredential;
+import com.mongodb.ServerAddress;
+import com.mongodb.async.client.MongoClient;
+import com.mongodb.async.client.MongoClientSettings;
+import com.mongodb.async.client.MongoClients;
+import com.mongodb.async.client.MongoDatabase;
+import com.mongodb.connection.ClusterSettings;
+import eu.univento.core.api.Config;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public class AsyncMongoDB {
+
+ private MongoClient client;
+ private MongoDatabase database;
+
+ public AsyncMongoDB(String host, int port, String username, String password, String database) {
+ List addressList = new ArrayList<>();
+ addressList.add(new ServerAddress(host, port));
+ List credentials = new ArrayList<>();
+ credentials.add(MongoCredential.createCredential(username, database, password.toCharArray()));
+ ClusterSettings clusterSettings = ClusterSettings.builder().hosts(addressList).build();
+ MongoClientSettings settings = MongoClientSettings.builder().clusterSettings(clusterSettings).credentialList(credentials).build();
+ client = MongoClients.create(settings);
+ }
+
+ public MongoClient getClient() {
+ if(client == null)
+ new AsyncMongoDB(Config.readString("MongoDB.Host"), Config.readInt("MongoDB.Port"), Config.readString("MongoDB.User"), Config.readString("MongoDB.Password"), Config.readString("MongoDB.Database"));
+ return client;
+ }
+
+ public MongoDatabase getDatabase() {
+ if(database == null)
+ database = getClient().getDatabase(Config.readString("MongoDB.Database"));
+ return database;
+ }
+
+ public void closeConnection() {
+ if(client != null)
+ client.close();
+ }
+}
\ No newline at end of file
diff --git a/src/main/java/eu/univento/core/api/database/AsyncMySQL.java b/src/main/java/eu/univento/core/api/database/AsyncMySQL.java
index fbd800d..754a5c4 100644
--- a/src/main/java/eu/univento/core/api/database/AsyncMySQL.java
+++ b/src/main/java/eu/univento/core/api/database/AsyncMySQL.java
@@ -17,9 +17,9 @@ public class AsyncMySQL {
private Plugin plugin;
private MySQL sql;
- public AsyncMySQL(Plugin owner, String host, int port, String user, String password, String database) {
+ public AsyncMySQL(Plugin owner, String host, String port, String user, String password, String database) {
try {
- sql = new MySQL(host, port, user, password, database);
+ sql = new MySQL(owner, host, port, user, password, database);
executor = Executors.newCachedThreadPool();
plugin = owner;
} catch (Exception e) {
@@ -27,127 +27,30 @@ public class AsyncMySQL {
}
}
- public void update(PreparedStatement statement) {
- executor.execute(() -> sql.queryUpdate(statement));
- }
-
- public void update(String statement) {
- executor.execute(() -> sql.queryUpdate(statement));
- }
-
- public void query(PreparedStatement statement, Consumer consumer) {
+ public void update(String update) {
executor.execute(() -> {
- ResultSet result = sql.query(statement);
- Bukkit.getScheduler().runTask(plugin, () -> consumer.accept(result));
+ try {
+ sql.query(update);
+ } catch (SQLException | ClassNotFoundException e) {
+ e.printStackTrace();
+ }
});
}
- public void query(String statement, Consumer consumer) {
+ public void query(String query, Consumer consumer) {
executor.execute(() -> {
- ResultSet result = sql.query(statement);
- Bukkit.getScheduler().runTask(plugin, () -> consumer.accept(result));
+ ResultSet result = null;
+ try {
+ result = sql.query(query);
+ ResultSet finalResult = result;
+ Bukkit.getScheduler().runTask(plugin, () -> consumer.accept(finalResult));
+ } catch (SQLException | ClassNotFoundException e) {
+ e.printStackTrace();
+ }
});
}
- public PreparedStatement prepare(String query) {
- try {
- return sql.getConnection().prepareStatement(query);
- } catch (Exception e) {
- e.printStackTrace();
- }
- return null;
- }
-
public MySQL getMySQL() {
return sql;
}
-
- public static class MySQL {
-
- private String host, user, password, database;
- private int port;
-
- private Connection conn;
-
- public MySQL(String host, int port, String user, String password, String database) throws Exception {
- this.host = host;
- this.port = port;
- this.user = user;
- this.password = password;
- this.database = database;
-
- this.openConnection();
- }
-
- public void queryUpdate(String query) {
- checkConnection();
- try (PreparedStatement statement = conn.prepareStatement(query)) {
- queryUpdate(statement);
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
-
- public void queryUpdate(PreparedStatement statement) {
- checkConnection();
- try {
- statement.executeUpdate();
- } catch (Exception e) {
- e.printStackTrace();
- } finally {
- try {
- statement.close();
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- }
-
- public ResultSet query(String query) {
- checkConnection();
- try {
- return query(conn.prepareStatement(query));
- } catch (Exception e) {
- e.printStackTrace();
- }
- return null;
- }
-
- public ResultSet query(PreparedStatement statement) {
- checkConnection();
- try {
- return statement.executeQuery();
- } catch (Exception e) {
- e.printStackTrace();
- }
- return null;
- }
-
- public Connection getConnection() {
- return this.conn;
- }
-
- private void checkConnection() {
- try {
- if (this.conn == null || !this.conn.isValid(10) || this.conn.isClosed()) openConnection();
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
-
- public Connection openConnection() throws Exception {
- Class.forName("com.mysql.jdbc.Driver");
- return this.conn = DriverManager.getConnection("jdbc:mysql://" + this.host + ":" + this.port + "/" + this.database, this.user, this.password);
- }
-
- public void closeConnection() {
- try {
- this.conn.close();
- } catch (SQLException e) {
- e.printStackTrace();
- } finally {
- this.conn = null;
- }
- }
- }
}
\ No newline at end of file
diff --git a/src/main/java/eu/univento/core/api/database/Database.java b/src/main/java/eu/univento/core/api/database/Database.java
index 1cc711a..185fe33 100644
--- a/src/main/java/eu/univento/core/api/database/Database.java
+++ b/src/main/java/eu/univento/core/api/database/Database.java
@@ -2,10 +2,7 @@ package eu.univento.core.api.database;
import org.bukkit.plugin.Plugin;
-import java.sql.Connection;
-import java.sql.ResultSet;
-import java.sql.SQLException;
-import java.sql.Statement;
+import java.sql.*;
public abstract class Database {
protected Connection connection;
@@ -37,29 +34,25 @@ public abstract class Database {
return true;
}
- public ResultSet querySQL(String query)
+ public ResultSet query(String query)
throws SQLException, ClassNotFoundException {
if (!checkConnection()) {
openConnection();
}
- Statement statement = this.connection.createStatement();
+ PreparedStatement statement = this.connection.prepareStatement(query);
- ResultSet result = statement.executeQuery(query);
-
- return result;
+ return statement.executeQuery();
}
- public int updateSQL(String query)
+ public int update(String query)
throws SQLException, ClassNotFoundException {
if (!checkConnection()) {
openConnection();
}
- Statement statement = this.connection.createStatement();
+ PreparedStatement statement = this.connection.prepareStatement(query);
- int result = statement.executeUpdate(query);
-
- return result;
+ return statement.executeUpdate();
}
}
\ No newline at end of file
diff --git a/src/main/java/eu/univento/core/api/database/DatabaseManager.java b/src/main/java/eu/univento/core/api/database/DatabaseManager.java
new file mode 100644
index 0000000..cacf48f
--- /dev/null
+++ b/src/main/java/eu/univento/core/api/database/DatabaseManager.java
@@ -0,0 +1,53 @@
+package eu.univento.core.api.database;
+
+import eu.univento.core.api.Config;
+import org.bukkit.plugin.Plugin;
+
+import java.sql.SQLException;
+
+/**
+ * @author joethei
+ * @version 0.1
+ * created on 03.07.2016
+ */
+public class DatabaseManager {
+
+ private static AsyncMongoDB asyncMongoDB;
+ private static MongoDB mongoDB;
+ private static AsyncMySQL asyncMySQL;
+ private static MySQL mysql;
+
+ public DatabaseManager(Plugin plugin) {
+ asyncMongoDB = new AsyncMongoDB(Config.readString("MongoDB.Host"), Config.readInt("MongoDB.Port"), Config.readString("MongoDB.User"), Config.readString("MongoDB.Password"), Config.readString("MongoDB.Database"));
+ mongoDB = new MongoDB(Config.readString("MongoDB.Host"), Config.readInt("MongoDB.Port"), Config.readString("MongoDB.User"), Config.readString("MongoDB.Password"), Config.readString("MongoDB.Database"));
+ mysql = new MySQL(plugin, Config.readString("MySQL.Host"), Config.readString("MySQL.Port"), Config.readString("MySQL.DB"), Config.readString("MySQL.User"), Config.readString("MySQL.Pass"));
+ asyncMySQL = new AsyncMySQL(plugin, Config.readString("MySQL.Host"), Config.readString("MySQL.Port"), Config.readString("MySQL.DB"), Config.readString("MySQL.User"), Config.readString("MySQL.Pass"));
+ }
+
+ public void closeConnections() {
+ asyncMongoDB.closeConnection();
+ mongoDB.closeConnection();
+ try {
+ mysql.closeConnection();
+ asyncMySQL.getMySQL().closeConnection();
+ } catch (SQLException e) {
+ e.printStackTrace();
+ }
+ }
+
+ public AsyncMongoDB getAsyncMongoDB() {
+ return asyncMongoDB;
+ }
+
+ public MongoDB getMongoDB() {
+ return mongoDB;
+ }
+
+ public MySQL getMySQL() {
+ return mysql;
+ }
+
+ public AsyncMySQL getAsyncMySQL() {
+ return asyncMySQL;
+ }
+}
\ No newline at end of file
diff --git a/src/main/java/eu/univento/core/api/database/MySQL.java b/src/main/java/eu/univento/core/api/database/MySQL.java
index 7f8353d..8243d1f 100644
--- a/src/main/java/eu/univento/core/api/database/MySQL.java
+++ b/src/main/java/eu/univento/core/api/database/MySQL.java
@@ -6,31 +6,27 @@ import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
-public class MySQL extends Database
-{
- private final String user;
- private final String database;
- private final String password;
- private final String port;
- private final String hostname;
+public class MySQL extends Database {
+ private final String user;
+ private final String database;
+ private final String password;
+ private final String port;
+ private final String hostname;
- public MySQL(Plugin plugin, String hostname, String port, String database, String username, String password) {
- super(plugin);
- this.hostname = hostname;
- this.port = port;
- this.database = database;
- this.user = username;
- this.password = password;
- }
-
- public Connection openConnection() throws SQLException, ClassNotFoundException {
- if (checkConnection()) {
- return this.connection;
+ public MySQL(Plugin plugin, String hostname, String port, String database, String username, String password) {
+ super(plugin);
+ this.hostname = hostname;
+ this.port = port;
+ this.database = database;
+ this.user = username;
+ this.password = password;
+ }
+
+ public Connection openConnection() throws SQLException, ClassNotFoundException {
+ if (checkConnection())
+ return this.connection;
+ Class.forName("com.mysql.jdbc.Driver");
+ this.connection = DriverManager.getConnection("jdbc:mysql://" + this.hostname + ":" + this.port + "/" + this.database, this.user, this.password);
+ return this.connection;
}
- Class.forName("com.mysql.jdbc.Driver");
- this.connection = DriverManager.getConnection("jdbc:mysql://" +
- this.hostname + ":" + this.port + "/" + this.database,
- this.user, this.password);
- return this.connection;
- }
}
\ No newline at end of file
diff --git a/src/main/java/eu/univento/core/api/effects/Effects.java b/src/main/java/eu/univento/core/api/effects/Effects.java
index 1d7605c..5f072bc 100644
--- a/src/main/java/eu/univento/core/api/effects/Effects.java
+++ b/src/main/java/eu/univento/core/api/effects/Effects.java
@@ -1,7 +1,6 @@
package eu.univento.core.api.effects;
-import eu.univento.core.api.player.CustomPlayer;
-import eu.univento.core.api.player.PlayerSettings;
+import eu.univento.core.Core;
import net.minecraft.server.v1_10_R1.EnumParticle;
import net.minecraft.server.v1_10_R1.PacketPlayOutWorldParticles;
import org.bukkit.Location;
@@ -24,9 +23,7 @@ public class Effects {
*/
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(CustomPlayer p : PlayerSettings.getAllPlayersWithEffectsEnabled()) {
- p.getHandle().playerConnection.sendPacket(packet);
- }
+ Core.getOnlinePlayers().stream().filter(p -> p.hasEffects()).forEach(p -> p.getHandle().playerConnection.sendPacket(packet));
}
public static void playEffectToPlayer(Player p, Location loc, EnumParticle ep, float f, int count) {
diff --git a/src/main/java/eu/univento/core/api/items/ItemBuilder.java b/src/main/java/eu/univento/core/api/items/ItemBuilder.java
new file mode 100644
index 0000000..e68767e
--- /dev/null
+++ b/src/main/java/eu/univento/core/api/items/ItemBuilder.java
@@ -0,0 +1,377 @@
+package eu.univento.core.api.items;
+
+import org.bukkit.Color;
+import org.bukkit.Material;
+import org.bukkit.enchantments.Enchantment;
+import org.bukkit.inventory.ItemFlag;
+import org.bukkit.inventory.ItemStack;
+import org.bukkit.inventory.meta.ItemMeta;
+import org.bukkit.inventory.meta.LeatherArmorMeta;
+import org.bukkit.inventory.meta.SkullMeta;
+import org.bukkit.material.MaterialData;
+
+import java.util.*;
+
+/**
+ * NOTICE: This utility was developer as part of AeolusLib. While you can use it for your own projects, You are NOT allowed to delete or move this header comment.
+ *
+ * Utility:
+ * Chainable {@link ItemStack}s
+ *
+ * Example Usage(s):
+ * {@code ItemStack itemStack = new ItemBuilder(Material.SKULL_ITEM).amount(1).durability(3).skullOwner("MCAeolus").name(ChatColor.RED+"MCAeolus's Skull").make())}
+ * {@code ItemStack itemStack = new ItemBuilder().type(Material.BEDROCK).lores(new String[]{"Lore1",ChatColor.RED+"Lore2"}).enchantment(Enchantment.DAMAGE_ALL, 99).make()}
+ *
+ * @author MCAeolus, joethei
+ * @version 1.1
+ */
+
+public class ItemBuilder {
+
+ private final ItemStack item;
+ private final ItemMeta itemM;
+
+ /**
+ * Init item chainable via given Material parameter.
+ *
+ * @param itemType
+ * the {@link Material} to initiate the instance with.
+ *
+ * @since 1.0
+ */
+ public ItemBuilder(final Material itemType){
+ item = new ItemStack(itemType);
+ itemM = item.getItemMeta();
+ }
+
+ /**
+ * Init item chainable via given ItemStack parameter.
+ *
+ * @param itemStack
+ * the {@link ItemStack} to initialize the instance with.
+ *
+ * @since 1.0
+ */
+ public ItemBuilder(final ItemStack itemStack){
+ item = itemStack;
+ itemM = item.getItemMeta();
+ }
+
+ /**
+ * Init the item chainable with no defined Material/ItemStack
+ *
+ * @since 1.0
+ */
+ public ItemBuilder(){
+ item = new ItemStack(Material.AIR);
+ itemM = item.getItemMeta();
+ }
+
+ /**
+ * Changes the Material type of the {@link ItemStack}
+ *
+ * @param material
+ * the new {@link Material} to set for the ItemStack.
+ *
+ * @return the current instance for chainable application.
+ * @since 1.0
+ */
+ public ItemBuilder type(final Material material){
+ make().setType(material);
+ return this;
+ }
+
+ /**
+ * Changes the {@link ItemStack}s size.
+ *
+ * @param itemAmt
+ * the new Integer count of the ItemStack.
+ *
+ * @return the current instance for chainable application.
+ * @since 1.0
+ */
+ public ItemBuilder amount(final Integer itemAmt){
+ make().setAmount(itemAmt);
+ return this;
+ }
+
+ /**
+ * Changes the {@link ItemStack}s display name.
+ *
+ * @param name
+ * the new String for the ItemStack's display name to be set to.
+ *
+ * @return the current instance for chainable application.
+ * @since 1.0
+ */
+ public ItemBuilder name(final String name){
+ meta().setDisplayName(name);
+ make().setItemMeta(meta());
+ return this;
+ }
+
+ /**
+ * Adds a line of lore to the {@link ItemStack}
+ *
+ * @param lore
+ * String you want to add to the ItemStack's lore.
+ *
+ * @return the current instance for chainable application.
+ * @since 1.0
+ */
+ public ItemBuilder lore(final String lore){
+ List lores = meta().getLore();
+ if(lores == null){lores = new ArrayList<>();}
+ lores.add(lore);
+ meta().setLore(lores);
+ make().setItemMeta(meta());
+ return this;
+ }
+
+ /**
+ * Clears the {@link ItemStack}s lore and replaces it with the defined String array.
+ *
+ * @param lores
+ * String array you want to set the ItemStack's lore to.
+ *
+ * @return the current instance for chainable application.
+ * @since 1.0
+ */
+ public ItemBuilder lores(final String[] lores){
+ List loresList = meta().getLore();
+ if(loresList == null){loresList = new ArrayList<>();}
+ else{loresList.clear();}
+ Collections.addAll(loresList, lores);
+ meta().setLore(loresList);
+ return this;
+ }
+
+ /**
+ * Changes the durability of the current {@link ItemStack}
+ *
+ * @param durability
+ * the new int amount to set the ItemStack's durability to.
+ *
+ * @return the current instance for chainable application.
+ * @since 1.0
+ */
+ public ItemBuilder durability(final int durability){
+ make().setDurability((short) durability);
+ return this;
+ }
+
+ /**
+ * Changes the data value of the {@link ItemStack}
+ *
+ * @param data
+ * the new int data value (parsed as byte) to set the ItemStack's durability to.
+ *
+ * @return the current instance for chainable application.
+ * @since 1.0
+ */
+ @SuppressWarnings("deprecation")
+ public ItemBuilder data(final int data){
+ make().setData(new MaterialData(make().getType(), (byte)data));
+ return this;
+ }
+
+ /**
+ * Adds and UnsafeEnchantment to the {@link ItemStack} with a defined level int value.
+ *
+ * @param enchantment
+ * the {@link Enchantment} to add to the ItemStack.
+ *
+ * @param level
+ * the int amount that the Enchantment's level will be set to.
+ *
+ * @return the current instance for chainable application.
+ * @since 1.0
+ */
+ public ItemBuilder enchantment(final Enchantment enchantment, final int level){
+ make().addUnsafeEnchantment(enchantment, level);
+ return this;
+ }
+
+ /**
+ * Adds and UnsafeEnchantment to the {@Link} with a level int value of 1.
+ *
+ * @param enchantment
+ * the {@link Enchantment} to add to the ItemStack.
+ *
+ * @return the current instance for chainable application.
+ * @since 1.0
+ */
+ public ItemBuilder enchantment(final Enchantment enchantment){
+ make().addUnsafeEnchantment(enchantment, 1);
+ return this;
+ }
+
+ /**
+ * Clears all {@link Enchantment}s from the current {@link ItemStack} then adds the defined array of Enchantments to the ItemStack.
+ *
+ * @param enchantments
+ * the Enchantment array to replace any current enchantments applied on the ItemStack.
+ *
+ * @param level
+ * the int level value for all Enchantments to be set to.
+ *
+ * @return the current instance for chainable application.
+ * @since 1.0
+ */
+ public ItemBuilder enchantments(final Enchantment[] enchantments, final int level){
+ make().getEnchantments().clear();
+ for(Enchantment enchantment : enchantments){
+ make().addUnsafeEnchantment(enchantment, level);
+ }
+ return this;
+ }
+
+ /**
+ * Clears all {@link Enchantment}s from the current {@link ItemStack} then adds the defined array of Enchantments to the ItemStack with a level int value of 1.
+ *
+ * @param enchantments
+ * the Enchantment array to replace any current enchantments applied on the ItemStack.
+ *
+ * @return the current instance for chainable application.
+ * @since 1.0
+ */
+ public ItemBuilder enchantments(final Enchantment[] enchantments){
+ make().getEnchantments().clear();
+ for(Enchantment enchantment : enchantments){
+ make().addUnsafeEnchantment(enchantment, 1);
+ }
+ return this;
+ }
+
+ /**
+ * Clears the defined {@link Enchantment} from the {@link ItemStack}
+ *
+ * @param enchantment
+ * the Enchantment to remove from the ItemStack.
+ *
+ * @return the current instance for chainable application.
+ * @since 1.0
+ */
+ public ItemBuilder clearEnchantment(final Enchantment enchantment){
+ Map itemEnchantments = make().getEnchantments();
+ itemEnchantments.keySet().stream().filter(enchantmentC -> enchantment == enchantmentC).forEach(itemEnchantments::remove);
+ return this;
+ }
+
+ /**
+ * Clears all {@link Enchantment}s from the {@link ItemStack}
+ *
+ * @return the current instance for chainable application.
+ * @since 1.0
+ */
+ public ItemBuilder clearEnchantments(){
+ make().getEnchantments().clear();
+ return this;
+ }
+
+ /**
+ * Clears the defined {@link String} of lore from the {@link ItemStack}
+ *
+ * @param lore
+ * the String to be removed from the ItemStack.
+ *
+ * @return the current instance for chainable application.
+ * @since 1.0
+ */
+ public ItemBuilder clearLore(final String lore){
+ if(meta().getLore().contains(lore)){
+ meta().getLore().remove(lore);
+ }
+ make().setItemMeta(meta());
+ return this;
+ }
+
+ /**
+ * Clears all lore {@link String}s from the {@link ItemStack}
+ *
+ * @return the current instance for chainable application.
+ * @since 1.0
+ */
+ public ItemBuilder clearLores(){
+ meta().getLore().clear();
+ make().setItemMeta(meta());
+ return this;
+ }
+
+ /**
+ * Sets the {@link Color} of any LEATHER_ARMOR {@link Material} types of the {@link ItemStack}
+ *
+ * @param color
+ * the Color to set the LEATHER_ARMOR ItemStack to.
+ *
+ * @return the current instance for chainable application.
+ * @since 1.0
+ */
+ public ItemBuilder color(final Color color){
+ if(make().getType() == Material.LEATHER_HELMET
+ || make().getType() == Material.LEATHER_CHESTPLATE
+ || make().getType() == Material.LEATHER_LEGGINGS
+ || make().getType() == Material.LEATHER_BOOTS ){
+ LeatherArmorMeta meta = (LeatherArmorMeta) meta();
+ meta.setColor(color);
+ make().setItemMeta(meta);
+ }
+ return this;
+ }
+
+ /**
+ * Clears the {@link Color} of any LEATHER_ARMOR {@link Material} types of the {@link ItemStack}
+ *
+ * @return the current instance for chainable application.
+ * @since 1.0
+ */
+ public ItemBuilder clearColor(){
+ if(make().getType() == Material.LEATHER_HELMET
+ || make().getType() == Material.LEATHER_CHESTPLATE
+ || make().getType() == Material.LEATHER_LEGGINGS
+ || make().getType() == Material.LEATHER_BOOTS ){
+ LeatherArmorMeta meta = (LeatherArmorMeta) meta();
+ meta.setColor(null);
+ make().setItemMeta(meta);
+ }
+ return this;
+ }
+
+ /**
+ * Sets the skullOwner {@link SkullMeta} of the current SKULL_ITEM {@link Material} type {@link ItemStack}
+ *
+ * @param name
+ * the {@link String} value to set the SkullOwner meta to for the SKULL_ITEM Material type ItemStack.
+ *
+ * @return the current instance for chainable application
+ * @since 1.0
+ */
+ public ItemBuilder skullOwner(final String name){
+ if(make().getType() == Material.SKULL_ITEM && make().getDurability() == (byte) 3){
+ SkullMeta skullMeta = (SkullMeta) meta();
+ skullMeta.setOwner(name);
+ make().setItemMeta(meta());
+ }
+ return this;
+ }
+
+ /**
+ * Returns the {@link ItemMeta} of the {@link ItemStack}
+ *
+ * @return the ItemMeta of the ItemStack.
+ */
+ public ItemMeta meta(){
+ return itemM;
+ }
+
+ /**
+ * Returns the {@link ItemStack} of the {@link ItemBuilder} instance.
+ *
+ * @return the ItemStack of the ItemBuilder instance.
+ */
+ public ItemStack make(){
+ item.getItemMeta().addItemFlags(ItemFlag.HIDE_ATTRIBUTES, ItemFlag.HIDE_DESTROYS, ItemFlag.HIDE_UNBREAKABLE, ItemFlag.HIDE_ENCHANTS);
+ return item;
+ }
+
+}
diff --git a/src/main/java/eu/univento/core/api/languages/Language.java b/src/main/java/eu/univento/core/api/languages/Language.java
index ba75c0c..089ec03 100644
--- a/src/main/java/eu/univento/core/api/languages/Language.java
+++ b/src/main/java/eu/univento/core/api/languages/Language.java
@@ -8,11 +8,10 @@ import java.util.ResourceBundle;
public class Language {
- private Map languages;
private ResourceBundle translation;
public Language(String language) {
- languages = new HashMap<>();
+ Map languages = new HashMap<>();
languages.put("DE", Locale.GERMAN);
languages.put("EN", Locale.ENGLISH);
languages.put("IT", Locale.ITALY);
diff --git a/src/main/java/eu/univento/core/api/languages/Language_DE.java b/src/main/java/eu/univento/core/api/languages/Language_DE.java
index 0f332d9..5ce8a3b 100644
--- a/src/main/java/eu/univento/core/api/languages/Language_DE.java
+++ b/src/main/java/eu/univento/core/api/languages/Language_DE.java
@@ -1,7 +1,7 @@
package eu.univento.core.api.languages;
import eu.univento.core.api.player.CustomPlayer;
-import eu.univento.core.api.player.Ranks;
+import eu.univento.core.api.player.Rank;
/**
* @author joethei
@@ -141,7 +141,7 @@ class Language_DE implements Languages{
}
@Override
- public String Core_SETRANK_SET(CustomPlayer p, Ranks rank) {
+ public String Core_SETRANK_SET(CustomPlayer p, Rank rank) {
return "§7Du hast dem Spieler " + p.getDisplayName() + " auf §e" + rank.toString() + " §7gesetzt";
}
@Override
diff --git a/src/main/java/eu/univento/core/api/languages/Language_EN.java b/src/main/java/eu/univento/core/api/languages/Language_EN.java
index 27326e8..12e844f 100644
--- a/src/main/java/eu/univento/core/api/languages/Language_EN.java
+++ b/src/main/java/eu/univento/core/api/languages/Language_EN.java
@@ -1,7 +1,7 @@
package eu.univento.core.api.languages;
import eu.univento.core.api.player.CustomPlayer;
-import eu.univento.core.api.player.Ranks;
+import eu.univento.core.api.player.Rank;
/**
* @author joethei
@@ -140,7 +140,7 @@ public class Language_EN implements Languages{
}
@Override
- public String Core_SETRANK_SET(CustomPlayer p, Ranks rank) {
+ public String Core_SETRANK_SET(CustomPlayer p, Rank rank) {
return "§7You gave " + p.getDisplayName() + " the rank §e" + rank.toString();
}
diff --git a/src/main/java/eu/univento/core/api/languages/Language_IT.java b/src/main/java/eu/univento/core/api/languages/Language_IT.java
index e8b1806..b073dc1 100644
--- a/src/main/java/eu/univento/core/api/languages/Language_IT.java
+++ b/src/main/java/eu/univento/core/api/languages/Language_IT.java
@@ -1,7 +1,7 @@
package eu.univento.core.api.languages;
import eu.univento.core.api.player.CustomPlayer;
-import eu.univento.core.api.player.Ranks;
+import eu.univento.core.api.player.Rank;
/**
* @author joethei
@@ -140,7 +140,7 @@ public class Language_IT implements Languages{
}
@Override
- public String Core_SETRANK_SET(CustomPlayer p, Ranks rank) {
+ public String Core_SETRANK_SET(CustomPlayer p, Rank rank) {
return "§7Hai dato " + p.getDisplayName() + " il gruppo §e" + rank.toString();
}
@Override
diff --git a/src/main/java/eu/univento/core/api/languages/Languages.java b/src/main/java/eu/univento/core/api/languages/Languages.java
index 3146bc5..2507f5c 100644
--- a/src/main/java/eu/univento/core/api/languages/Languages.java
+++ b/src/main/java/eu/univento/core/api/languages/Languages.java
@@ -1,7 +1,7 @@
package eu.univento.core.api.languages;
import eu.univento.core.api.player.CustomPlayer;
-import eu.univento.core.api.player.Ranks;
+import eu.univento.core.api.player.Rank;
/**
* @author joethei
@@ -36,7 +36,7 @@ public interface Languages{
String Core_SETRANK_USAGE();
String Core_SETRANK_KICK();
String Core_SETRANK_NO_RANK();
- String Core_SETRANK_SET(CustomPlayer p, Ranks rank);
+ String Core_SETRANK_SET(CustomPlayer p, Rank rank);
String Core_TS_ALLREADY_VERIFIED();
String Core_TS_VERIFIED();
String Core_VANISH_ON();
diff --git a/src/main/java/eu/univento/core/api/languages/Messages.java b/src/main/java/eu/univento/core/api/languages/Messages.java
index 78232f3..24ebf99 100644
--- a/src/main/java/eu/univento/core/api/languages/Messages.java
+++ b/src/main/java/eu/univento/core/api/languages/Messages.java
@@ -1,7 +1,7 @@
package eu.univento.core.api.languages;
import eu.univento.core.api.player.CustomPlayer;
-import eu.univento.core.api.player.Ranks;
+import eu.univento.core.api.player.Rank;
/**
@@ -109,7 +109,7 @@ public class Messages {
public String Core_SETRANK_NO_RANK() {
return lang.Core_SETRANK_NO_RANK();
}
- public String Core_SETRANK_SET(CustomPlayer p, Ranks rank) {
+ public String Core_SETRANK_SET(CustomPlayer p, Rank rank) {
return lang.Core_SETRANK_SET(p, rank);
}
public String Core_TS_ALLREADY_VERIFIED() {
diff --git a/src/main/java/eu/univento/core/api/map/Cuboid.java b/src/main/java/eu/univento/core/api/map/Cuboid.java
index 5cb454f..908ab67 100644
--- a/src/main/java/eu/univento/core/api/map/Cuboid.java
+++ b/src/main/java/eu/univento/core/api/map/Cuboid.java
@@ -16,8 +16,8 @@ import java.util.stream.Collectors;
public class Cuboid implements Cloneable, ConfigurationSerializable, Iterable {
- protected String worldName;
- protected final Vector minimumPoint, maximumPoint;
+ private String worldName;
+ private final Vector minimumPoint, maximumPoint;
public Cuboid(Cuboid cuboid) {
this(cuboid.worldName, cuboid.minimumPoint.getX(), cuboid.minimumPoint.getY(), cuboid.minimumPoint.getZ(), cuboid.maximumPoint.getX(), cuboid.maximumPoint.getY(), cuboid.maximumPoint.getZ());
diff --git a/src/main/java/eu/univento/core/api/map/MapVoting.java b/src/main/java/eu/univento/core/api/map/MapVoting.java
index a9aa357..c31dbc0 100644
--- a/src/main/java/eu/univento/core/api/map/MapVoting.java
+++ b/src/main/java/eu/univento/core/api/map/MapVoting.java
@@ -1,7 +1,7 @@
package eu.univento.core.api.map;
import eu.univento.core.api.player.CustomPlayer;
-import eu.univento.core.api.player.Ranks;
+import eu.univento.core.api.player.Rank;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
@@ -109,7 +109,7 @@ public class MapVoting implements Listener{
}
public Inventory getInventory(CustomPlayer p) {
- if(p.isAllowed(Ranks.Admin)) {
+ if(p.isAllowed(Rank.Admin)) {
Inventory inv = Bukkit.createInventory(p, 45, invTitle);
for(Map map : allMaps) {
@@ -164,7 +164,7 @@ public class MapVoting implements Listener{
if(e.getWhoClicked() instanceof Player) {
CustomPlayer p = CustomPlayer.getPlayer(e.getWhoClicked().getName());
if(e.getInventory().getName().equals(invTitle)) {
- if(p.isAllowed(Ranks.Admin)) {
+ if(p.isAllowed(Rank.Admin)) {
allMaps.stream().filter(map -> e.getCurrentItem().getType() == map.getItem()).forEach(map -> {
forcedMap = map;
});
diff --git a/src/main/java/eu/univento/core/api/pet/NMSHandler.java b/src/main/java/eu/univento/core/api/pet/NMSHandler.java
new file mode 100644
index 0000000..0b2c025
--- /dev/null
+++ b/src/main/java/eu/univento/core/api/pet/NMSHandler.java
@@ -0,0 +1,43 @@
+package eu.univento.core.api.pet;
+
+import net.minecraft.server.v1_10_R1.Entity;
+import net.minecraft.server.v1_10_R1.World;
+import org.bukkit.Location;
+import org.bukkit.craftbukkit.v1_10_R1.CraftWorld;
+import org.bukkit.entity.EntityType;
+import org.bukkit.entity.LivingEntity;
+import org.bukkit.event.entity.CreatureSpawnEvent;
+
+import java.lang.reflect.InvocationTargetException;
+
+/**
+ * @author joethei
+ * @version 0.1
+ * created on 26.06.2016
+ */
+public class NMSHandler {
+
+ public static LivingEntity spawn(EntityType type, Location loc) {
+ World nmsWorld = ((CraftWorld) loc.getWorld()).getHandle();
+ PetType petType = PetType.valueOf(type);
+ if(petType == null) return null;
+ Entity entity;
+ try {
+ entity = (Entity) petType.getCustomClass().getConstructors()[0].newInstance(nmsWorld);
+ } catch (InstantiationException | IllegalAccessException | InvocationTargetException e) {
+ e.printStackTrace();
+ return null;
+ }
+ entity.setLocation(loc.getX(), loc.getY(), loc.getZ(), loc.getPitch(), loc.getYaw());
+ nmsWorld.addEntity(entity, CreatureSpawnEvent.SpawnReason.CUSTOM);
+ return (LivingEntity) entity.getBukkitEntity();
+ }
+
+ public static void registerEnties() {
+ PetType.registerEntities();
+ }
+
+ public static EntityType[] getRegisteredTypes() {
+ return PetType.getRegisteredTypes();
+ }
+}
\ No newline at end of file
diff --git a/src/main/java/eu/univento/core/api/pet/NMSHelper.java b/src/main/java/eu/univento/core/api/pet/NMSHelper.java
new file mode 100644
index 0000000..fc87ac4
--- /dev/null
+++ b/src/main/java/eu/univento/core/api/pet/NMSHelper.java
@@ -0,0 +1,41 @@
+package eu.univento.core.api.pet;
+
+import net.minecraft.server.v1_10_R1.EntityInsentient;
+import net.minecraft.server.v1_10_R1.EntityTypes;
+
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * @author joethei
+ * @version 0.1
+ * created on 26.06.2016
+ */
+class NMSHelper {
+
+ static void registerEntity(String name, int id, Class extends EntityInsentient> nmsClass, Class extends EntityInsentient> customClass) {
+ try {
+ final List