diff --git a/Core.iml b/Core.iml index 49ab2d7..0db5ae1 100644 --- a/Core.iml +++ b/Core.iml @@ -12,25 +12,24 @@ - - - - - - - - - - - - - - + + + + + + + + + + + + + \ No newline at end of file diff --git a/pom.xml b/pom.xml index 8291814..a32cdad 100644 --- a/pom.xml +++ b/pom.xml @@ -17,6 +17,7 @@ org.apache.maven.plugins maven-compiler-plugin + 3.5.1 1.8 1.8 @@ -82,19 +83,19 @@ org.bukkit craftbukkit - 1.9-R0.1-SNAPSHOT + 1.9.2-R0.1-SNAPSHOT + provided org.bukkit bukkit - 1.9-R0.1-SNAPSHOT + 1.9.2-R0.1-SNAPSHOT provided org.spigotmc spigot-api - 1.9-R0.1-SNAPSHOT - provided + 1.9.2-R0.1-SNAPSHOT diff --git a/src/main/java/eu/univento/core/Core.java b/src/main/java/eu/univento/core/Core.java index 582c97e..0dd6b4b 100644 --- a/src/main/java/eu/univento/core/Core.java +++ b/src/main/java/eu/univento/core/Core.java @@ -101,7 +101,8 @@ public class Core extends JavaPlugin{ new Fix(this, "fix", "fix"); new Stats(this, "stats", "statistics"); new Nick(this, "nick", "nick"); - }else{ + } + if(!ServerSettings.isBuild()) { new Build(this, "build", "build", "b"); pm.registerEvents(new Blocks(), this); } @@ -119,16 +120,17 @@ public class Core extends JavaPlugin{ log(Level.INFO, "registered all commands"); Bukkit.getMessenger().registerOutgoingPluginChannel(this, "BungeeCord"); + Bukkit.getMessenger().registerOutgoingPluginChannel(this, "LABYMOD"); 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")); - + mongoDB = new MongoDB(Config.readString("MongoDB.Host"), Config.readInt("MongoDB.Port"), Config.readString("MongoDB.User"), Config.readString("MongoDB.Password"), Config.readString("MongoDB.Database")); log(Level.INFO, "Plugin ver. " + getDescription().getVersion() + " started"); } @Override public void onDisable() { + mongoDB.getClient().close(); log(Level.INFO, "Plugin stoped"); } diff --git a/src/main/java/eu/univento/core/api/Config.java b/src/main/java/eu/univento/core/api/Config.java index ae6574b..7ded2c1 100644 --- a/src/main/java/eu/univento/core/api/Config.java +++ b/src/main/java/eu/univento/core/api/Config.java @@ -31,15 +31,16 @@ public class Config { //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.Host", "hostname"); 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.addDefault("MySQL.User", "root"); + cfg.addDefault("MySQL.Pass", ""); + cfg.addDefault("MongoDB.Host", "Hostname"); + cfg.addDefault("MongoDB.Port", 27017); + cfg.addDefault("MongoDB.User", "univento"); + cfg.addDefault("MongoDB.Password", "1234"); + cfg.addDefault("MongoDB.Database", "univento"); cfg.options().copyDefaults(true); cfg.save(file); diff --git a/src/main/java/eu/univento/core/api/Utils.java b/src/main/java/eu/univento/core/api/Utils.java index a6885fe..f3e1146 100644 --- a/src/main/java/eu/univento/core/api/Utils.java +++ b/src/main/java/eu/univento/core/api/Utils.java @@ -1,5 +1,6 @@ package eu.univento.core.api; + import eu.univento.core.Core; import org.bukkit.*; import org.bukkit.entity.Entity; @@ -154,14 +155,7 @@ public class Utils { * restarts server */ public static void restart() { - Bukkit.getScheduler().scheduleSyncDelayedTask(Core.getInstance(), new Runnable() { - - @Override - public void run() { - Bukkit.getServer().spigot().restart(); - } - - }, 10 * 20L); + Bukkit.getScheduler().scheduleSyncDelayedTask(Core.getInstance(), () -> Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "/restart"), 10 * 20L); } /** diff --git a/src/main/java/eu/univento/core/api/database/AsyncMySQL.java b/src/main/java/eu/univento/core/api/database/AsyncMySQL.java new file mode 100644 index 0000000..fbd800d --- /dev/null +++ b/src/main/java/eu/univento/core/api/database/AsyncMySQL.java @@ -0,0 +1,153 @@ +package eu.univento.core.api.database; + +import org.bukkit.Bukkit; +import org.bukkit.plugin.Plugin; + +import java.sql.*; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import java.util.function.Consumer; + +/** + * @author joethei + * @version 0.1 + */ +public class AsyncMySQL { + private ExecutorService executor; + private Plugin plugin; + private MySQL sql; + + public AsyncMySQL(Plugin owner, String host, int port, String user, String password, String database) { + try { + sql = new MySQL(host, port, user, password, database); + executor = Executors.newCachedThreadPool(); + plugin = owner; + } catch (Exception e) { + e.printStackTrace(); + } + } + + 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) { + executor.execute(() -> { + ResultSet result = sql.query(statement); + Bukkit.getScheduler().runTask(plugin, () -> consumer.accept(result)); + }); + } + + public void query(String statement, Consumer consumer) { + executor.execute(() -> { + ResultSet result = sql.query(statement); + Bukkit.getScheduler().runTask(plugin, () -> consumer.accept(result)); + }); + } + + 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 76fa156..1cc711a 100644 --- a/src/main/java/eu/univento/core/api/database/Database.java +++ b/src/main/java/eu/univento/core/api/database/Database.java @@ -7,66 +7,59 @@ import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; -public abstract class Database -{ - protected Connection connection; - protected Plugin plugin; +public abstract class Database { + protected Connection connection; + protected Plugin plugin; - protected Database(Plugin plugin) - { - this.plugin = plugin; - this.connection = null; - } - - public abstract Connection openConnection() - throws SQLException, ClassNotFoundException; - - public boolean checkConnection() - throws SQLException - { - return (this.connection != null) && (!this.connection.isClosed()); - } - - public Connection getConnection() - { - return this.connection; - } - - public boolean closeConnection() - throws SQLException - { - if (this.connection == null) { - return false; - } - this.connection.close(); - return true; - } - - public ResultSet querySQL(String query) - throws SQLException, ClassNotFoundException - { - if (!checkConnection()) { - openConnection(); + protected Database(Plugin plugin) { + this.plugin = plugin; + this.connection = null; } - Statement statement = this.connection.createStatement(); + public abstract Connection openConnection() + throws SQLException, ClassNotFoundException; - ResultSet result = statement.executeQuery(query); - - return result; - } - - public int updateSQL(String query) - throws SQLException, ClassNotFoundException - { - if (!checkConnection()) { - openConnection(); + public boolean checkConnection() + throws SQLException { + return (this.connection != null) && (!this.connection.isClosed()); } - Statement statement = this.connection.createStatement(); + public Connection getConnection() { + return this.connection; + } - int result = statement.executeUpdate(query); + public boolean closeConnection() + throws SQLException { + if (this.connection == null) { + return false; + } + this.connection.close(); + return true; + } - return result; - } + public ResultSet querySQL(String query) + throws SQLException, ClassNotFoundException { + if (!checkConnection()) { + openConnection(); + } + + Statement statement = this.connection.createStatement(); + + ResultSet result = statement.executeQuery(query); + + return result; + } + + public int updateSQL(String query) + throws SQLException, ClassNotFoundException { + if (!checkConnection()) { + openConnection(); + } + + Statement statement = this.connection.createStatement(); + + int result = statement.executeUpdate(query); + + return result; + } } \ No newline at end of file diff --git a/src/main/java/eu/univento/core/api/database/MongoDB.java b/src/main/java/eu/univento/core/api/database/MongoDB.java index 59d755a..3077702 100644 --- a/src/main/java/eu/univento/core/api/database/MongoDB.java +++ b/src/main/java/eu/univento/core/api/database/MongoDB.java @@ -6,7 +6,7 @@ import com.mongodb.ServerAddress; import com.mongodb.client.MongoDatabase; import eu.univento.core.api.Config; -import java.util.Arrays; +import java.util.Collections; public class MongoDB { @@ -15,19 +15,19 @@ public class MongoDB { 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")); + new MongoDB(Config.readString("MongoDB.Host"), Config.readInt("MongoDB.Port"), Config.readString("MongoDB.User"), 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)); + client = new MongoClient(new ServerAddress(host, port), Collections.singletonList(credential)); } public MongoDatabase getDatabase() { - if(database == null) { + if(database == null) database = getClient().getDatabase(Config.readString("MongoDB.Database")); - }return database; + return database; } public void setDatabase(String database) { @@ -35,9 +35,8 @@ public class MongoDB { } public void closeConnection() { - if(client != null) { + if(client != null) client.close(); - } } } \ No newline at end of file diff --git a/src/main/java/eu/univento/core/api/entity/EntityModifier.java b/src/main/java/eu/univento/core/api/entity/EntityModifier.java index 3804106..a2beed0 100644 --- a/src/main/java/eu/univento/core/api/entity/EntityModifier.java +++ b/src/main/java/eu/univento/core/api/entity/EntityModifier.java @@ -13,227 +13,197 @@ import org.bukkit.plugin.Plugin; import java.lang.reflect.Field; /** - * * @author GerVorbis * @version 1.0 */ -public class EntityModifier -{ - static org.bukkit.entity.Entity entity; - static CraftEntity craftentity; - static net.minecraft.server.v1_9_R1.Entity entityS; - static int scheduler; - static Plugin plugin; - static Player player = null; - static float Speed; +public class EntityModifier { + static org.bukkit.entity.Entity entity; + static CraftEntity craftentity; + static net.minecraft.server.v1_9_R1.Entity entityS; + static int scheduler; + static Plugin plugin; + static Player player = null; + static float Speed; - public EntityModifier(org.bukkit.entity.Entity entity, Plugin plugin) - { - EntityModifier.entity = entity; - craftentity = (CraftEntity)entity; - entityS = craftentity.getHandle(); - EntityModifier.plugin = plugin; - } - - public static Builder modify() - { - return new Builder(); - } - - public static final class Builder - { - public Builder setDisplayName(String display) - { - EntityModifier.entity.setCustomName(display); - EntityModifier.entity.setCustomNameVisible(true); - return this; + public EntityModifier(org.bukkit.entity.Entity entity, Plugin plugin) { + EntityModifier.entity = entity; + craftentity = (CraftEntity) entity; + entityS = craftentity.getHandle(); + EntityModifier.plugin = plugin; } - public Builder setDisplayNameVisible(Boolean visible) - { - EntityModifier.entity.setCustomNameVisible(visible.booleanValue()); - return this; + public static Builder modify() { + return new Builder(); } - public Builder playEffekt(EntityEffect entityeffect) - { - EntityModifier.entity.playEffect(entityeffect); - return this; - } - - public Builder remove() - { - EntityModifier.entity.remove(); - return this; - } - - public Builder setPassenger(org.bukkit.entity.Entity passenger) - { - EntityModifier.entity.setPassenger(passenger); - return this; - } - - public Builder setFireTicks(int ticks) - { - EntityModifier.entity.setFireTicks(ticks); - return this; - } - - public Builder setLocation(Location location) - { - teleport(location); - return this; - } - - public Builder setYawPitch(float yaw, float pitch) - { - Location loc = EntityModifier.entity.getLocation().clone(); - teleport( - new Location(loc.getWorld(), loc.getX(), loc.getY(), - loc.getZ(), yaw, pitch)); - return this; - } - - public Builder teleport(Location location) - { - EntityModifier.entity.teleport(location); - return this; - } - - public Builder die() - { - EntityModifier.entityS.die(); - return this; - } - - public Builder setInvisible(boolean invisible) - { - EntityModifier.entityS.setInvisible(invisible); - return this; - } - - public Builder noClip(boolean noClip) - { - EntityModifier.entityS.noclip = noClip; - return this; - } - - public Builder setInvulnerable(boolean invulnerable) - { - try - { - Field invulnerableField = net.minecraft.server.v1_9_R1.Entity.class - .getDeclaredField("invulnerable"); - invulnerableField.setAccessible(true); - invulnerableField.setBoolean(EntityModifier.entityS, invulnerable); - } catch (Exception ex) { - ex.printStackTrace(); - } - return this; - } - - public Builder setNoAI(boolean noAI) - { - NBTTagCompound tag = new NBTTagCompound(); - EntityModifier.entityS.c(tag); - tag.setBoolean("NoAI", noAI); - EntityLiving el = (EntityLiving)EntityModifier.entityS; - el.a(tag); - return this; - } - - public Builder setSilent(boolean silent) - { - NBTTagCompound tag = new NBTTagCompound(); - EntityModifier.entityS.c(tag); - tag.setBoolean("Silent", silent); - EntityLiving el = (EntityLiving)EntityModifier.entityS; - el.a(tag); - return this; - } - - public Builder setCanPickUpLoot(boolean canpickuploot) - { - NBTTagCompound tag = new NBTTagCompound(); - EntityModifier.entityS.c(tag); - tag.setBoolean("CanPickUpLoot", canpickuploot); - EntityLiving el = (EntityLiving)EntityModifier.entityS; - el.a(tag); - return this; - } - - public Builder setHealth(float health) - { - NBTTagCompound tag = new NBTTagCompound(); - EntityModifier.entityS.c(tag); - tag.setFloat("HealF", health); - EntityLiving el = (EntityLiving)EntityModifier.entityS; - el.a(tag); - return this; - } - - public Builder setCanDespawn(boolean candespawn) - { - candespawn = !candespawn; - NBTTagCompound tag = new NBTTagCompound(); - EntityModifier.entityS.c(tag); - tag.setBoolean("PersistenceRequired", candespawn); - EntityLiving el = (EntityLiving)EntityModifier.entityS; - el.a(tag); - return this; - } - - public Builder walkToLocation(Location location, float speed) - { - ((CraftCreature)EntityModifier.entity) - .getHandle() - .getNavigation() - .a(location.getX(), location.getY(), location.getZ(), speed); - return this; - } - - public Builder followPlayer(Player target, float speed) - { - EntityModifier.player = target; - EntityModifier.Speed = speed; - EntityModifier.scheduler = Bukkit.getScheduler().scheduleSyncRepeatingTask(EntityModifier.plugin, - new Runnable() - { - @SuppressWarnings("deprecation") - public void run() { - double distance = EntityModifier.entity.getLocation().distance( - EntityModifier.player.getLocation()); - if (distance < 11.0D) { - float speed = EntityModifier.Speed; - if (distance < 3.0D) { - speed = 0.0F; - } - ((CraftCreature)EntityModifier.entity) - .getHandle() - .getNavigation() - .a(EntityModifier.player.getLocation().getX(), - EntityModifier.player.getLocation().getY(), - EntityModifier.player.getLocation().getZ(), - speed); - } - else if (EntityModifier.player.isOnGround()) { - EntityModifier.entity.teleport(EntityModifier.player); - } + public static final class Builder { + public Builder setDisplayName(String display) { + EntityModifier.entity.setCustomName(display); + EntityModifier.entity.setCustomNameVisible(true); + return this; } - } - , 0L, 1L); - return this; - } - public Builder stopFollowingPlayer() - { - Bukkit.getScheduler().cancelTask(EntityModifier.scheduler); - return this; - } + public Builder setDisplayNameVisible(Boolean visible) { + EntityModifier.entity.setCustomNameVisible(visible.booleanValue()); + return this; + } - public org.bukkit.entity.Entity build() - { - return EntityModifier.entity; + public Builder playEffekt(EntityEffect entityeffect) { + EntityModifier.entity.playEffect(entityeffect); + return this; + } + + public Builder remove() { + EntityModifier.entity.remove(); + return this; + } + + public Builder setPassenger(org.bukkit.entity.Entity passenger) { + EntityModifier.entity.setPassenger(passenger); + return this; + } + + public Builder setFireTicks(int ticks) { + EntityModifier.entity.setFireTicks(ticks); + return this; + } + + public Builder setLocation(Location location) { + teleport(location); + return this; + } + + public Builder setYawPitch(float yaw, float pitch) { + Location loc = EntityModifier.entity.getLocation().clone(); + teleport( + new Location(loc.getWorld(), loc.getX(), loc.getY(), + loc.getZ(), yaw, pitch)); + return this; + } + + public Builder teleport(Location location) { + EntityModifier.entity.teleport(location); + return this; + } + + public Builder die() { + EntityModifier.entityS.die(); + return this; + } + + public Builder setInvisible(boolean invisible) { + EntityModifier.entityS.setInvisible(invisible); + return this; + } + + public Builder noClip(boolean noClip) { + EntityModifier.entityS.noclip = noClip; + return this; + } + + public Builder setInvulnerable(boolean invulnerable) { + try { + Field invulnerableField = net.minecraft.server.v1_9_R1.Entity.class + .getDeclaredField("invulnerable"); + invulnerableField.setAccessible(true); + invulnerableField.setBoolean(EntityModifier.entityS, invulnerable); + } catch (Exception ex) { + ex.printStackTrace(); + } + return this; + } + + public Builder setNoAI(boolean noAI) { + NBTTagCompound tag = new NBTTagCompound(); + EntityModifier.entityS.c(tag); + tag.setBoolean("NoAI", noAI); + EntityLiving el = (EntityLiving) EntityModifier.entityS; + el.a(tag); + return this; + } + + public Builder setSilent(boolean silent) { + NBTTagCompound tag = new NBTTagCompound(); + EntityModifier.entityS.c(tag); + tag.setBoolean("Silent", silent); + EntityLiving el = (EntityLiving) EntityModifier.entityS; + el.a(tag); + return this; + } + + public Builder setCanPickUpLoot(boolean canpickuploot) { + NBTTagCompound tag = new NBTTagCompound(); + EntityModifier.entityS.c(tag); + tag.setBoolean("CanPickUpLoot", canpickuploot); + EntityLiving el = (EntityLiving) EntityModifier.entityS; + el.a(tag); + return this; + } + + public Builder setHealth(float health) { + NBTTagCompound tag = new NBTTagCompound(); + EntityModifier.entityS.c(tag); + tag.setFloat("HealF", health); + EntityLiving el = (EntityLiving) EntityModifier.entityS; + el.a(tag); + return this; + } + + public Builder setCanDespawn(boolean candespawn) { + candespawn = !candespawn; + NBTTagCompound tag = new NBTTagCompound(); + EntityModifier.entityS.c(tag); + tag.setBoolean("PersistenceRequired", candespawn); + EntityLiving el = (EntityLiving) EntityModifier.entityS; + el.a(tag); + return this; + } + + public Builder walkToLocation(Location location, float speed) { + ((CraftCreature) EntityModifier.entity) + .getHandle() + .getNavigation() + .a(location.getX(), location.getY(), location.getZ(), speed); + return this; + } + + public Builder followPlayer(Player target, float speed) { + EntityModifier.player = target; + EntityModifier.Speed = speed; + EntityModifier.scheduler = Bukkit.getScheduler().scheduleSyncRepeatingTask(EntityModifier.plugin, + new Runnable() { + @SuppressWarnings("deprecation") + public void run() { + double distance = EntityModifier.entity.getLocation().distance( + EntityModifier.player.getLocation()); + if (distance < 11.0D) { + float speed = EntityModifier.Speed; + if (distance < 3.0D) { + speed = 0.0F; + } + ((CraftCreature) EntityModifier.entity) + .getHandle() + .getNavigation() + .a(EntityModifier.player.getLocation().getX(), + EntityModifier.player.getLocation().getY(), + EntityModifier.player.getLocation().getZ(), + speed); + } else if (EntityModifier.player.isOnGround()) { + EntityModifier.entity.teleport(EntityModifier.player); + } + } + } + , 0L, 1L); + return this; + } + + public Builder stopFollowingPlayer() { + Bukkit.getScheduler().cancelTask(EntityModifier.scheduler); + return this; + } + + public org.bukkit.entity.Entity build() { + return EntityModifier.entity; + } } - } } \ No newline at end of file diff --git a/src/main/java/eu/univento/core/api/events/MoveEventFilter.java b/src/main/java/eu/univento/core/api/events/MoveEventFilter.java index de71feb..fb64b9c 100644 --- a/src/main/java/eu/univento/core/api/events/MoveEventFilter.java +++ b/src/main/java/eu/univento/core/api/events/MoveEventFilter.java @@ -13,18 +13,14 @@ import java.util.WeakHashMap; /** * @author Crislibaer */ -public class MoveEventFilter implements Listener -{ - public static class PlayerBlockMoveEvent extends PlayerMoveEvent - { - public PlayerBlockMoveEvent(PlayerMoveEvent pEvent) - { +public class MoveEventFilter implements Listener { + public static class PlayerBlockMoveEvent extends PlayerMoveEvent { + public PlayerBlockMoveEvent(PlayerMoveEvent pEvent) { super(pEvent.getPlayer(), pEvent.getFrom(), pEvent.getTo()); } } - private static class BlockPosition - { + private static class BlockPosition { public int x; public int y; public int z; @@ -34,16 +30,13 @@ public class MoveEventFilter implements Listener private Server mServer; private WeakHashMap mLastPosition = new WeakHashMap<>(); - public MoveEventFilter(Server pServer) - { + public MoveEventFilter(Server pServer) { mServer = pServer; } @EventHandler - public void onPlayerMove(PlayerMoveEvent pEvent) - { - if(pEvent.isCancelled() || pEvent instanceof PlayerBlockMoveEvent) - { + public void onPlayerMove(PlayerMoveEvent pEvent) { + if (pEvent.isCancelled() || pEvent instanceof PlayerBlockMoveEvent) { return; } @@ -51,23 +44,17 @@ public class MoveEventFilter implements Listener Location currentPos = pEvent.getTo(); boolean fireEvent = false; - if(lastPos == null) - { + if (lastPos == null) { lastPos = new BlockPosition(); mLastPosition.put(pEvent.getPlayer(), lastPos); fireEvent = true; - } - else if(lastPos.x != currentPos.getBlockX() || lastPos.z != currentPos.getBlockZ() || lastPos.y != currentPos.getBlockY()) - { + } else if (lastPos.x != currentPos.getBlockX() || lastPos.z != currentPos.getBlockZ() || lastPos.y != currentPos.getBlockY()) { fireEvent = true; - } - else if(lastPos.world != currentPos.getWorld()) - { + } else if (lastPos.world != currentPos.getWorld()) { fireEvent = true; } - if(fireEvent) - { + if (fireEvent) { // make sure that our event is synchronous assert !pEvent.isAsynchronous(); @@ -76,8 +63,7 @@ public class MoveEventFilter implements Listener mServer.getPluginManager().callEvent(event); // check event state and only update new position if event does not gets canceled - if(!event.isCancelled()) - { + if (!event.isCancelled()) { // update new position lastPos.world = currentPos.getWorld(); lastPos.x = currentPos.getBlockX(); diff --git a/src/main/java/eu/univento/core/api/items/ItemSkulls.java b/src/main/java/eu/univento/core/api/items/ItemSkulls.java index 665a4ec..4c7e679 100644 --- a/src/main/java/eu/univento/core/api/items/ItemSkulls.java +++ b/src/main/java/eu/univento/core/api/items/ItemSkulls.java @@ -14,111 +14,92 @@ import java.lang.reflect.Method; import java.util.Base64; import java.util.UUID; -public class ItemSkulls -{ - private static Class skullMetaClass; - private static Class tileEntityClass; - private static Class blockPositionClass; - private static int mcVersion; +public class ItemSkulls { + private static Class skullMetaClass; + private static Class tileEntityClass; + private static Class blockPositionClass; + private static int mcVersion; - static - { - String version = org.bukkit.Bukkit.getServer().getClass().getPackage().getName() - .split("\\.")[3]; - mcVersion = Integer.parseInt(version.replaceAll("[^0-9]", "")); - try { - skullMetaClass = Class.forName("org.bukkit.craftbukkit." + version + - ".inventory.CraftMetaSkull"); - tileEntityClass = Class.forName("net.minecraft.server." + version + - ".TileEntitySkull"); - if (mcVersion > 174) - blockPositionClass = Class.forName("net.minecraft.server." + - version + ".BlockPosition"); - else - blockPositionClass = null; + static { + String version = org.bukkit.Bukkit.getServer().getClass().getPackage().getName().split("\\.")[3]; + mcVersion = Integer.parseInt(version.replaceAll("[^0-9]", "")); + try { + skullMetaClass = Class.forName("org.bukkit.craftbukkit." + version + ".inventory.CraftMetaSkull"); + tileEntityClass = Class.forName("net.minecraft.server." + version + ".TileEntitySkull"); + if (mcVersion > 174) + blockPositionClass = Class.forName("net.minecraft.server." + version + ".BlockPosition"); + else + blockPositionClass = null; + } catch (ClassNotFoundException e) { + e.printStackTrace(); + } } - catch (ClassNotFoundException e) { - e.printStackTrace(); + + public static ItemStack getSkull(String skinURL) { + return getSkull(skinURL, 1); } - } - public static ItemStack getSkull(String skinURL) - { - return getSkull(skinURL, 1); - } - - public static ItemStack getSkull(String skinURL, int amount) - { - ItemStack skull = new ItemStack(Material.SKULL_ITEM, amount, (short) 3); - SkullMeta meta = (SkullMeta)skull.getItemMeta(); - try { - Field profileField = skullMetaClass.getDeclaredField("profile"); - profileField.setAccessible(true); - profileField.set(meta, getProfile(skinURL)); - } catch (Exception ex) { - ex.printStackTrace(); + public static ItemStack getSkull(String skinURL, int amount) { + ItemStack skull = new ItemStack(Material.SKULL_ITEM, amount, (short) 3); + SkullMeta meta = (SkullMeta) skull.getItemMeta(); + try { + Field profileField = skullMetaClass.getDeclaredField("profile"); + profileField.setAccessible(true); + profileField.set(meta, getProfile(skinURL)); + } catch (Exception ex) { + ex.printStackTrace(); + } + skull.setItemMeta(meta); + return skull; } - skull.setItemMeta(meta); - return skull; - } - public static boolean setBlock(Location loc, String skinURL) - { - return setBlock(loc.getBlock(), skinURL); - } - - public static boolean setBlock(Block block, String skinURL) - { - boolean flag = block.getType() == Material.SKULL; - if (!flag) - block.setType(Material.SKULL); - try - { - Object nmsWorld = block.getWorld().getClass() - .getMethod("getHandle", new Class[0]).invoke(block.getWorld(), new Object[0]); - Object tileEntity = null; - - if (mcVersion <= 174) { - Method getTileEntity = nmsWorld.getClass().getMethod( - "getTileEntity", new Class[] { Integer.TYPE, Integer.TYPE, Integer.TYPE }); - tileEntity = tileEntityClass.cast(getTileEntity.invoke( - nmsWorld, new Object[] { Integer.valueOf(block.getX()), Integer.valueOf(block.getY()), Integer.valueOf(block.getZ()) })); - } else { - Method getTileEntity = nmsWorld.getClass().getMethod( - "getTileEntity", new Class[] { blockPositionClass }); - tileEntity = tileEntityClass.cast(getTileEntity.invoke( - nmsWorld, new Object[] { - getBlockPositionFor(block.getX(), block.getY(), - block.getZ()) })); - } - - tileEntityClass.getMethod("setGameProfile", new Class[] { GameProfile.class }) - .invoke(tileEntity, new Object[] { getProfile(skinURL) }); - } catch (Exception ex) { - ex.printStackTrace(); + public static boolean setBlock(Location loc, String skinURL) { + return setBlock(loc.getBlock(), skinURL); } - return !flag; - } - private static GameProfile getProfile(String skinURL) { - GameProfile profile = new GameProfile(UUID.randomUUID(), null); - String base64encoded = Base64.getEncoder().encodeToString( - new String("{textures:{SKIN:{url:\"" + skinURL + "\"}}}") - .getBytes()); - Property property = new Property("textures", base64encoded); - profile.getProperties().put("textures", property); - return profile; - } + public static boolean setBlock(Block block, String skinURL) { + boolean flag = block.getType() == Material.SKULL; + if (!flag) + block.setType(Material.SKULL); + try { + Object nmsWorld = block.getWorld().getClass().getMethod("getHandle", new Class[0]).invoke(block.getWorld()); + Object tileEntity = null; - private static Object getBlockPositionFor(int x, int y, int z) { - Object blockPosition = null; - try { - Constructor cons = blockPositionClass.getConstructor(new Class[] { Integer.TYPE, - Integer.TYPE, Integer.TYPE }); - blockPosition = cons.newInstance(new Object[] { Integer.valueOf(x), Integer.valueOf(y), Integer.valueOf(z) }); - } catch (Exception ex) { - ex.printStackTrace(); + if (mcVersion <= 174) { + Method getTileEntity = nmsWorld.getClass().getMethod("getTileEntity", Integer.TYPE, Integer.TYPE, Integer.TYPE); + tileEntity = tileEntityClass.cast(getTileEntity.invoke(nmsWorld, block.getX(), block.getY(), block.getZ())); + } else { + Method getTileEntity = nmsWorld.getClass().getMethod("getTileEntity", blockPositionClass); + tileEntity = tileEntityClass.cast(getTileEntity.invoke( + nmsWorld, getBlockPositionFor(block.getX(), block.getY(), + block.getZ()))); + } + + tileEntityClass.getMethod("setGameProfile", new Class[]{GameProfile.class}) + .invoke(tileEntity, getProfile(skinURL)); + } catch (Exception ex) { + ex.printStackTrace(); + } + return !flag; + } + + private static GameProfile getProfile(String skinURL) { + GameProfile profile = new GameProfile(UUID.randomUUID(), null); + String base64encoded = Base64.getEncoder().encodeToString( + ("{textures:{SKIN:{url:\"" + skinURL + "\"}}}").getBytes()); + Property property = new Property("textures", base64encoded); + profile.getProperties().put("textures", property); + return profile; + } + + private static Object getBlockPositionFor(int x, int y, int z) { + Object blockPosition = null; + try { + Constructor cons = blockPositionClass.getConstructor(Integer.TYPE, Integer.TYPE, Integer.TYPE); + blockPosition = cons.newInstance(x, y, z); + } catch (Exception ex) { + ex.printStackTrace(); + } + return blockPosition; } - return blockPosition; - } } \ No newline at end of file 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 46eb57d..e715542 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.Perms; +import eu.univento.core.api.player.Ranks; /** * @author joethei @@ -141,7 +141,7 @@ public class Language_DE implements Languages{ } @Override - public String Core_SETRANK_SET(CustomPlayer p, Perms.Ranks rank) { + public String Core_SETRANK_SET(CustomPlayer p, Ranks 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 d8a0af6..27326e8 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.Perms; +import eu.univento.core.api.player.Ranks; /** * @author joethei @@ -140,7 +140,7 @@ public class Language_EN implements Languages{ } @Override - public String Core_SETRANK_SET(CustomPlayer p, Perms.Ranks rank) { + public String Core_SETRANK_SET(CustomPlayer p, Ranks rank) { return "§7You gave " + p.getDisplayName() + " the rank §e" + rank.toString(); } @@ -356,7 +356,7 @@ public class Language_EN implements Languages{ @Override public String LobbyItems_BUILDSERVER() { - return "§aBuilding-Server"; + return "§aBuilding-server"; } @Override @@ -406,7 +406,7 @@ public class Language_EN implements Languages{ @Override public String LobbyItems_PETS_REMOVE() { - return "§6ride pet"; + return "§6remove pet"; } @Override 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 4be78ad..e8b1806 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.Perms; +import eu.univento.core.api.player.Ranks; /** * @author joethei @@ -140,7 +140,7 @@ public class Language_IT implements Languages{ } @Override - public String Core_SETRANK_SET(CustomPlayer p, Perms.Ranks rank) { + public String Core_SETRANK_SET(CustomPlayer p, Ranks 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 a74dd53..3146bc5 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.Perms; +import eu.univento.core.api.player.Ranks; /** * @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, Perms.Ranks rank); + String Core_SETRANK_SET(CustomPlayer p, Ranks 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 f7bea72..78232f3 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.Perms; +import eu.univento.core.api.player.Ranks; /** @@ -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, Perms.Ranks rank) { + public String Core_SETRANK_SET(CustomPlayer p, Ranks 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/Map.java b/src/main/java/eu/univento/core/api/map/Map.java index 901b65f..9d50a88 100644 --- a/src/main/java/eu/univento/core/api/map/Map.java +++ b/src/main/java/eu/univento/core/api/map/Map.java @@ -11,11 +11,13 @@ public class Map { private String name; private String builder; private Material item; + private String download; - public Map(String name, String builder, Material item) { + public Map(String name, String builder, Material item, String download) { this.name = name; this.builder = builder; this.item = item; + this.download = download; } public String getName() { @@ -29,4 +31,8 @@ public class Map { public Material getItem() { return item; } + + public String getDownloadLink() { + return download; + } } \ No newline at end of file diff --git a/src/main/java/eu/univento/core/api/map/MapDatabase.java b/src/main/java/eu/univento/core/api/map/MapDatabase.java index 4f30c95..a218a75 100644 --- a/src/main/java/eu/univento/core/api/map/MapDatabase.java +++ b/src/main/java/eu/univento/core/api/map/MapDatabase.java @@ -15,9 +15,9 @@ public class MapDatabase { public static ArrayList getAllMaps(Game game) { ArrayList maps = new ArrayList<>(); - maps.add(new Map("Map1", "TeamVento", Material.GRASS)); - maps.add(new Map("Map2", "TeamVento", Material.STONE)); - maps.add(new Map("Map3", "TeamVento", Material.APPLE)); + maps.add(new Map("Map1", "TeamVento", Material.GRASS, "http://creppy.univento.eu/maps/Strive/Map1")); + maps.add(new Map("Map2", "TeamVento", Material.STONE, "http://creppy.univento.eu/maps/Strive/Map2")); + maps.add(new Map("Map3", "TeamVento", Material.APPLE, "http://creppy.univento.eu/maps/Strive/Map3")); return maps; } diff --git a/src/main/java/eu/univento/core/api/map/MapDownloader.java b/src/main/java/eu/univento/core/api/map/MapDownloader.java new file mode 100644 index 0000000..a16ad79 --- /dev/null +++ b/src/main/java/eu/univento/core/api/map/MapDownloader.java @@ -0,0 +1,37 @@ +package eu.univento.core.api.map; + +import eu.univento.core.Core; + +import java.io.File; +import java.io.FileOutputStream; +import java.io.InputStream; +import java.io.OutputStream; +import java.net.URL; +import java.util.logging.Level; + +/** + * @author joethei + * @version 0.1 + */ +public class MapDownloader { + + public static void download(URL file, File dest) { + try { + InputStream is = file.openStream(); + File finaldest = new File(dest + "/" + file.getFile()); + if(!finaldest.getParentFile().mkdirs()) Core.log(Level.SEVERE, "Map Ordner konnte nicht erstellt werden"); + finaldest.createNewFile(); + OutputStream os = new FileOutputStream(finaldest); + byte data[] = new byte[1024]; + int count; + while ((count = is.read(data, 0, 1024)) != -1) { + os.write(data, 0, count); + } + os.flush(); + is.close(); + os.close(); + } catch (Exception ec) { + ec.printStackTrace(); + } + } +} \ No newline at end of file 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 0e10940..a9aa357 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.Perms; +import eu.univento.core.api.player.Ranks; 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(Perms.Ranks.Admin)) { + if(p.isAllowed(Ranks.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(Perms.Ranks.Admin)) { + if(p.isAllowed(Ranks.Admin)) { allMaps.stream().filter(map -> e.getCurrentItem().getType() == map.getItem()).forEach(map -> { forcedMap = map; }); diff --git a/src/main/java/eu/univento/core/api/player/BanSystem.java b/src/main/java/eu/univento/core/api/player/BanSystem.java index cc191db..bbde5e0 100644 --- a/src/main/java/eu/univento/core/api/player/BanSystem.java +++ b/src/main/java/eu/univento/core/api/player/BanSystem.java @@ -30,7 +30,7 @@ public class BanSystem{ * @throws ClassNotFoundException class couldn't be found */ static void setBanned(CustomPlayer p, String reason, CustomPlayer who, int time)throws SQLException, ClassNotFoundException { - int id = p.getID(); + int id = 0; MySQL sql = Core.returnSQL(); sql.openConnection(); @@ -38,7 +38,7 @@ static void setBanned(CustomPlayer p, String reason, CustomPlayer who, int time) date.setTime(date.getTime() + (time * 24)); Timestamp timestamp = new Timestamp(date.getTime()); - PreparedStatement st = sql.getConnection().prepareStatement("INSERT INTO bans (BID, Reason, until, BannerID) VALUES ('" + id + "', '" + reason + "', '" + who.getID() + "', '" + timestamp + "');"); + PreparedStatement st = sql.getConnection().prepareStatement("INSERT INTO bans (BID, Reason, until, BannerID) VALUES ('" + id + "', '" + reason + "', '" + 0 + "', '" + timestamp + "');"); st.execute(); p.kickPlayer("§cYou have been banned. §6Reason: " + reason + "\nUntil: " + timestamp); who.sendMessage("§cDu hast den Spieler " + p.getColor() + p.getName() + "§c für " + time + " Tage gebannt wegen " + reason); @@ -52,7 +52,7 @@ static void setBanned(CustomPlayer p, String reason, CustomPlayer who, int time) * @throws ClassNotFoundException class couldn't be found */ static void removeAllBans(CustomPlayer p) throws SQLException, ClassNotFoundException{ - int id = p.getID(); + int id = 0; MySQL sql = Core.returnSQL(); sql.openConnection(); PreparedStatement st = sql.getConnection().prepareStatement("DELETE FROM bans WHERE ID ='" + id + "';"); @@ -68,7 +68,7 @@ static void removeAllBans(CustomPlayer p) throws SQLException, ClassNotFoundExce * @throws ClassNotFoundException class couldn't be found */ static boolean isBanned(CustomPlayer p) throws SQLException, ClassNotFoundException { - int id = p.getID(); + int id = 0; MySQL sql = Core.returnSQL(); PreparedStatement st = sql.getConnection().prepareStatement("SELECT * FROM bans WHERE BID='" + id + "';"); ResultSet rs = st.executeQuery(); @@ -85,7 +85,7 @@ static boolean isBanned(CustomPlayer p) throws SQLException, ClassNotFoundExcept } static Timestamp getBanTime(CustomPlayer p) throws SQLException { - int id = p.getID(); + int id = 0; MySQL sql = Core.returnSQL(); PreparedStatement st = sql.getConnection().prepareStatement("SELECT * FROM bans WHERE ID='" + id + "';"); ResultSet rs = st.executeQuery(); @@ -106,7 +106,7 @@ static boolean isBanned(CustomPlayer p) throws SQLException, ClassNotFoundExcept * @throws ClassNotFoundException class couldn't be found */ static String getBanReason(CustomPlayer p)throws SQLException, ClassNotFoundException { - int id = p.getID(); + int id = 0; MySQL sql = Core.returnSQL(); sql.openConnection(); PreparedStatement st = sql.getConnection().prepareStatement("SELECT * FROM bans WHERE ID='" + id + "';"); @@ -129,7 +129,7 @@ static String getBanReason(CustomPlayer p)throws SQLException, ClassNotFoundExce * @throws ClassNotFoundException class couldn't be found */ static String getWhoBanned(CustomPlayer p)throws SQLException, ClassNotFoundException { - int id = p.getID(); + int id = 0; MySQL sql = Core.returnSQL(); sql.openConnection(); ResultSet rs = Core.returnSQL().getConnection().createStatement().executeQuery("SELECT * FROM bans WHERE ID='" + id + "';"); diff --git a/src/main/java/eu/univento/core/api/player/Coins.java b/src/main/java/eu/univento/core/api/player/Coins.java index 6d3c763..8368808 100644 --- a/src/main/java/eu/univento/core/api/player/Coins.java +++ b/src/main/java/eu/univento/core/api/player/Coins.java @@ -20,7 +20,7 @@ public class Coins{ * @return coins as integer */ static int getCoins(CustomPlayer p) { - int id = p.getID(); + int id = 0; MySQL sql = Core.returnSQL(); try { sql.openConnection(); @@ -44,7 +44,7 @@ public class Coins{ * @param coins coins to set */ static void setCoins(CustomPlayer p, int coins) { - int id = p.getID(); + int id = 0; MySQL sql = Core.returnSQL(); try { sql.openConnection(); diff --git a/src/main/java/eu/univento/core/api/player/CustomPlayer.java b/src/main/java/eu/univento/core/api/player/CustomPlayer.java index 9748199..537983c 100644 --- a/src/main/java/eu/univento/core/api/player/CustomPlayer.java +++ b/src/main/java/eu/univento/core/api/player/CustomPlayer.java @@ -1,99 +1,68 @@ package eu.univento.core.api.player; +import com.mongodb.BasicDBObject; +import com.mongodb.CursorType; +import com.mongodb.client.FindIterable; +import com.mongodb.client.MongoCollection; import eu.univento.core.Core; import eu.univento.core.api.Actionbar; import eu.univento.core.api.Utils; -import eu.univento.core.api.database.MySQL; +import eu.univento.core.api.database.MongoDB; import eu.univento.core.api.effects.Effects; import eu.univento.core.api.languages.Messages; import eu.univento.core.api.server.Game; -import eu.univento.core.api.server.ServerSettings; import eu.univento.core.api.server.Servers; -import eu.univento.core.api.utils.NameFetcher; +import io.netty.buffer.ByteBuf; +import io.netty.buffer.Unpooled; import net.minecraft.server.v1_9_R1.EnumParticle; +import net.minecraft.server.v1_9_R1.PacketDataSerializer; +import net.minecraft.server.v1_9_R1.PacketPlayOutCustomPayload; +import org.bson.Document; import org.bukkit.Bukkit; import org.bukkit.Color; import org.bukkit.Location; import org.bukkit.Sound; import org.bukkit.attribute.Attribute; +import org.bukkit.attribute.AttributeInstance; import org.bukkit.attribute.AttributeModifier; import org.bukkit.craftbukkit.v1_9_R1.CraftServer; import org.bukkit.craftbukkit.v1_9_R1.entity.CraftPlayer; import org.bukkit.entity.Player; +import org.bukkit.scoreboard.Scoreboard; import org.bukkit.scoreboard.Team; -import java.sql.PreparedStatement; -import java.sql.ResultSet; -import java.sql.SQLException; -import java.sql.Timestamp; -import java.util.Arrays; -import java.util.HashMap; -import java.util.Map; -import java.util.UUID; +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.ObjectOutputStream; +import java.util.*; -/** - * custom player implementation - * @author joethei - * @version 1.0 - */ public class CustomPlayer extends CraftPlayer { - /** - * all normal players - */ + private static final HashMap PLAYERS = new HashMap<>(); - - /** - * normal player - */ private final Player PLAYER; - - /** - * custom prefix for chat - */ private String customPrefix; - /** - * custom suffix for chat - */ private String customSuffix; - /** - * custom color for chat - */ private String customColor; - /** - * player id from database - */ - private int id = 0; - /** - * if player has open inventory - */ private boolean openInventory; - //private MongoDB mongoDB = Core.getMongoDB(); - //private MongoCollection userCollection = mongoDB.getDatabase().getCollection("users"); + private MongoDB mongoDB = Core.getMongoDB(); + private MongoCollection userCollection; + private MongoCollection friendCollection; - /** - * inits player - * - * @param player Player - */ private CustomPlayer(Player player) { super((CraftServer) Bukkit.getServer(), ((CraftPlayer) player).getHandle()); PLAYERS.put(player.getName().toLowerCase(), this); PLAYER = player; - id = getID(); + userCollection = mongoDB.getDatabase().getCollection("users"); + friendCollection = mongoDB.getDatabase().getCollection("friends"); } - /** - * called on player leaving - */ public void onLeave() { - /** Date date = new Date(); - Document doc = new Document("uuid", getUniqueId()); - userCollection.updateOne(doc, new Document("$set", new Document("lastOnline", date))); + setInDatabase("lastOnline", date); HashMap location = new HashMap<>(); location.put("X", getLocation().getX()); @@ -102,18 +71,11 @@ public class CustomPlayer extends CraftPlayer { location.put("Yaw", getLocation().getYaw()); location.put("Pitch", getLocation().getPitch()); - userCollection.updateOne(doc, new Document("$set", new Document("Pos", new Document("Loc", location)))); + if(Bukkit.getServerName().contains("Lobby")) setInDatabase("Pos", new BasicDBObject(location)); - */ if (PLAYERS.containsKey(getName().toLowerCase())) PLAYERS.remove(getName().toLowerCase()); } - /** - * init player - * - * @param player Player - * @return CustomPlayer - */ public static CustomPlayer getPlayer(String player) { if (PLAYERS.containsKey(player.toLowerCase())) { return PLAYERS.get(player.toLowerCase()); @@ -123,108 +85,31 @@ public class CustomPlayer extends CraftPlayer { } } - /** - * gets custom player from player - * - * @param player Player - * @return CustomPlayer - */ + public static CustomPlayer getPlayer(Player player) { return getPlayer(player.getName()); } - /** - * gets custom player from database id - * - * @param id database id of player - * @return CustomPlayer - */ - public static CustomPlayer getPlayer(int id) { - MySQL sql = Core.returnSQL(); - try { - sql.openConnection(); - PreparedStatement st = sql.getConnection().prepareStatement("SELECT ID, UUID FROM users WHERE ID='" + id + "');"); - ResultSet rs = st.executeQuery(); - String uuidString = rs.getString("UUID"); - sql.closeConnection(); - UUID uuid = UUID.fromString(uuidString); - NameFetcher names = new NameFetcher(Arrays.asList(uuid)); - Map map = null; - try { - map = names.call(); - } catch (Exception e) { - e.printStackTrace(); - } - String name = map.toString(); - String Name = name.substring(name.indexOf('=') + 1, name.indexOf('}')); - return CustomPlayer.getPlayer(Name); - - } catch (ClassNotFoundException | SQLException e) { - e.printStackTrace(); - return null; - } - } - - /** - * gets database id of player - * - * @return Integer - */ - public int getID() { - if (id == 0) { - MySQL sql = Core.returnSQL(); - try { - sql.openConnection(); - String uuid = this.getUniqueId().toString(); - PreparedStatement st = sql.getConnection().prepareStatement("SELECT * FROM users WHERE UUID ='" + uuid + "';"); - ResultSet rs = st.executeQuery(); - if (rs.next()) { - int id = rs.getInt("ID"); - this.id = id; - sql.closeConnection(); - return id; - } else { - sql.closeConnection(); - - return 0; - } - } catch (ClassNotFoundException | SQLException e) { - e.printStackTrace(); - return 0; - } - } else { - return id; - } - } - - /** - * get normal player - * - * @return Player - */ public Player getPLAYER() { return PLAYER; } - /** public void insertToDatabase() { - DBObject obj = new BasicDBObject("uuid", getUniqueId()); + Document doc = new Document("uuid", getUniqueId()); Date date = new Date(); - obj.put("rank", "Player"); - obj.put("firstLogin", date); - obj.put("lastLogin", date); - obj.put("lastOnline", date); - obj.put("lastIP", spigot().getRawAddress().getHostName()); - obj.put("tsid", 0); - obj.put("timesJoined", 1); - obj.put("timePlayed", 0); - obj.put("coins", 0); - obj.put("experience", 0); - obj.put("secrets", 0); - obj.put("foundSecrets", new ArrayList()); - obj.put("foundEggs", new ArrayList()); + doc.put("rank", "Player"); + doc.put("firstLogin", date); + doc.put("lastLogin", date); + doc.put("lastOnline", date); + doc.put("lastIP", getAddress().getHostName()); + doc.put("tsid", 0); + doc.put("timesJoined", 1); + doc.put("coins", 0); + doc.put("experience", 0); + doc.put("foundSecrets", new ArrayList()); + doc.put("foundEggs", new ArrayList()); HashMap settings = new HashMap<>(); settings.put("playerVisibility", "all"); @@ -238,7 +123,7 @@ public class CustomPlayer extends CraftPlayer { settings.put("storyMode", true); settings.put("language", "EN"); - obj.put("Settings", settings); + doc.put("Settings", new BasicDBObject(settings)); HashMap location = new HashMap<>(); location.put("X", getLocation().getX()); @@ -247,86 +132,75 @@ public class CustomPlayer extends CraftPlayer { location.put("Yaw", getLocation().getYaw()); location.put("Pitch", getLocation().getPitch()); - obj.put("Pos", location); - userCollection.insertOne(obj); + doc.put("Pos", new BasicDBObject(location)); + userCollection.insertOne(doc); + } + + @Override + public boolean hasPlayedBefore() { + FindIterable cursor = userCollection.find(new Document("uuid", getUniqueId())); + cursor.cursorType(CursorType.NonTailable); + + Object obj = cursor.first(); + if (obj == null) + return false; + return true; } public void updateDatabaseEntry() { - Date date = new Date(); - Document doc = new Document("uuid", getUniqueId()); - userCollection.updateOne(doc, new Document("$set", new Document("lastLogin", date))); - userCollection.updateOne(doc, new Document("$set", new Document("lastIP", spigot().getRawAddress().getHostName().toString()))); - userCollection.updateOne(doc, new Document("$set", new Document("timesPlayed", getTimesJoined() + 1))); + setInDatabase("lastLogin", new Date()); + setInDatabase("lastIP", getAddress().getHostName()); + setInDatabase("timesJoined", getTimesJoined() + 1); } - - public void setRank(Perms.Ranks rank) { - userCollection.updateOne(new Document("uuid", getUniqueId()), new Document("$set", new Document("rank", rank.toString()))); + public void setRank(Ranks rank) { + setInDatabase("rank", rank.toString()); } public void setTSID(int id) { - userCollection.updateOne(new Document("uuid", getUniqueId()), new Document("$set", new Document("tsid", id))); + setInDatabase("tsid", id); } public void setCoins(int coins) { - userCollection.updateOne(new Document("uuid", getUniqueId()), new Document("$set", new Document("coins", coins))); + setInDatabase("coins", coins); } public void setExperience(int experience) { - userCollection.updateOne(new Document("uuid", getUniqueId()), new Document("$set", new Document("experience", experience))); + setInDatabase("experience", experience); } - public void setSecrets(int secrets) { - userCollection.updateOne(new Document("uuid", getUniqueId()), new Document("$set", new Document("secrets", secrets))); + private void setFoundSecrets(ArrayList secrets) { + setInDatabase("foundSecrets", secrets); } - - private Object getObjectFromDatbase(String name) { - FindIterable cursor = userCollection.find(new Document("uuid", getUniqueId())); - cursor.cursorType(CursorType.NonTailable); - - Document doc = cursor.first(); - if (doc == null) { - return null; - } - return doc.get(name); + public void addSecret(String name) { + ArrayList list = getFoundSecrets(); + list.add(name); + setFoundSecrets(list); } - private int getIntegerFromDatabase(String name) { - FindIterable cursor = userCollection.find(new Document("uuid", getUniqueId())); - cursor.cursorType(CursorType.NonTailable); - - Document doc = cursor.first(); - if (doc == null) { - return 0; - } - return doc.getInteger(name); + private void setFoundEggs(ArrayList eggs) { + setInDatabase("foundEggs", eggs); } - private String getStringFromDatabase(String name) { - FindIterable cursor = userCollection.find(new Document("uuid", getUniqueId())); - cursor.cursorType(CursorType.NonTailable); - - Document doc = cursor.first(); - if (doc == null) { - return null; - } - return doc.getString(name); + public void addEgg(String name) { + ArrayList list = getFoundEggs(); + list.add(name); + setFoundEggs(list); } - private Date getDateFromDatabase(String name) { - FindIterable cursor = userCollection.find(new Document("uuid", getUniqueId())); - cursor.cursorType(CursorType.NonTailable); - - Document doc = cursor.first(); - if (doc == null) { - return null; - } - return doc.getDate(name); + private void setSettings(Map settings) { + setInDatabase("Settings", settings); } - public Perms.Ranks getRank() { - return Perms.Ranks.valueOf(getStringFromDatabase("rank")); + private void setSetting(String name, Object setting) { + Map list = getSettings(); + list.put(name, setting); + setSettings(list); + } + + public Ranks getRank() { + return Ranks.valueOf(getStringFromDatabase("rank")); } public Date getFirstLogin() { @@ -349,7 +223,7 @@ public class CustomPlayer extends CraftPlayer { return getIntegerFromDatabase("tsid"); } - public int getTimesJoined() { + private int getTimesJoined() { return getIntegerFromDatabase("timesJoined"); } @@ -361,38 +235,149 @@ public class CustomPlayer extends CraftPlayer { return getIntegerFromDatabase("experience"); } - public int getSecrets() { - return getIntegerFromDatabase("secrets"); - } + public int getSecrets() { return getFoundSecrets().size();} public ArrayList getFoundSecrets() { - return (ArrayList) getObjectFromDatbase("foundSecrets"); + return getArrayListFromDatabase("foundSecrets"); } - public ArrayList getFoundEggs() { - return (ArrayList) getObjectFromDatbase("foundEggs"); + public int getEggs() { return getFoundEggs().size();} + + private ArrayList getFoundEggs() { + return getArrayListFromDatabase("foundEggs"); } - public HashMap getSettings() { - return (HashMap) getObjectFromDatbase("settings"); + private Map getSettings() { + return getMapFromDatabase("Settings"); } - */ - /** - * connects player to server in bungeecord - * @param server ServerPinger to connect to - */ + + public Location getLastLocation() { + Map map = getMapFromDatabase("Pos"); + return new Location(Bukkit.getWorld("world"), (double)map.get("X"), (double)map.get("Y"), (double)map.get("Z"), (float)map.get("Yaw"), (float)map.get("Pitch")); + } + + public String getPlayerVisibility() { + return (String) getSettings().get("playerVisibility"); + } + + public boolean hasInventoryAnimation() { + return (boolean) getSettings().get("inventoryAnimation"); + } + + public boolean hasTeleportAnimation() { + return (boolean) getSettings().get("teleportAnimation"); + } + + public boolean hasPartyRequests() { + return (boolean) getSettings().get("partyRequests"); + } + + public boolean hasFriendRequests() { + return (boolean) getSettings().get("friendRequests"); + } + + public boolean hasFriendJump() { + return (boolean) getSettings().get("friendJump"); + } + + public boolean hasChatSounds() { + return (boolean) getSettings().get("chatSounds"); + } + + public boolean hasEffects() { + return (boolean) getSettings().get("effects"); + } + + public boolean hasStoryMode() { + return (boolean) getSettings().get("storyMode"); + } + + public String getLanguage() { + return (String) getSettings().get("language"); + } + + public void setPlayerVisibility(String visibility) { + setSetting("playerVisibility", visibility); + } + + public void setInventoryAnimation(boolean animation) { + setSetting("inventoryAnimation", animation); + } + + public void setTeleportAnimation(boolean animation) { + setSetting("teleportAnimation", animation); + } + + public void setPartyRequests(boolean requests) { + setSetting("partyRequests", requests); + } + + public void setFriendRequests(boolean requests) { + setSetting("friendRequests", requests); + } + + public void setFriendJump(boolean jump) { + setSetting("friendJump", jump); + } + + public void setChatSounds(boolean sounds) { + setSetting("chatSounds", sounds); + } + + public void setEffects(boolean effects) { + setSetting("effects", effects); + } + + public void setStoryMode(boolean storyMode) { + setSetting("storyMode", storyMode); + } + + public void setLanguage(String language) { + setSetting("language", language); + } + + public boolean isJoined() { + return true; + } + public void connectToServer(String server) { Servers.connectServer(PLAYER, server); } - + + public boolean isAllowed(Ranks rank) { + return getRank().value >= rank.value; + } + + public ArrayList getFriends() { + FindIterable cursor = friendCollection.find(new Document("uuid", getUniqueId())); + cursor.cursorType(CursorType.NonTailable); + + Document doc = cursor.first(); + if (doc == null) return null; + + return (ArrayList) doc.get("friends"); + } + + private void setFriends(ArrayList friends) { + friendCollection.updateOne(new Document("uuid", getUniqueId()), new Document("$set", new Document("friends", friends))); + } + + public boolean isFriend(UUID uuid) { + return getFriends().contains(uuid); + } + + public void addFriend(UUID uuid) { + ArrayList list = getFriends(); + list.add(uuid); + setFriends(list); + } + + + /** - * if player is allowed to do stuff - * @param rank Ranks - * @return true/false - */ - public boolean isAllowed(Perms.Ranks rank) { + public boolean isAllowed(Ranks.Ranks rank) { try { - return Perms.isAllowed(this, rank); + return Ranks.isAllowed(this, rank); } catch (ClassNotFoundException | SQLException e) { e.printStackTrace(); return false; @@ -400,377 +385,127 @@ public class CustomPlayer extends CraftPlayer { } /** - * rank of player - * @return Ranks - */ - public Perms.Ranks getRank() { + + public Ranks.Ranks getRank() { try { - return Perms.getRank(this); + return Ranks.getRank(this); } catch (ClassNotFoundException | SQLException e) { e.printStackTrace(); - return Perms.Ranks.Player; + return Ranks.Ranks.Player; } } - public Perms.Ranks getFreshRank() { + public Ranks.Ranks getFreshRank() { try{ - return Perms.getRankFresh(this); + return Ranks.getRankFresh(this); }catch (ClassNotFoundException | SQLException e) { e.printStackTrace(); - return Perms.Ranks.Player; + return Ranks.Ranks.Player; } } - /** - * sets rank of this custom player - * @param r Ranks - */ - public void setRank(Perms.Ranks r) { + public void setRank(Ranks.Ranks r) { try { - Perms.setRank(this, r); + Ranks.setRank(this, r); } catch (ClassNotFoundException e) { e.printStackTrace(); } catch (SQLException e) { e.printStackTrace(); } } - - /** - * prefix of player - * @return String - */ + + */ public String getPrefix() { if(customPrefix != null) return customPrefix; - if(isNicked()) return Perms.getPrefix(Perms.Ranks.Premium); - return Perms.getPrefix(getRank()); - } - - /** - * suffix of player - * @return String - */ - public String getSuffix() { - if(customSuffix != null) return customSuffix; - if(isNicked()) return Perms.getSuffix(Perms.Ranks.Premium); - return Perms.getSuffix(getRank()); - } - - /** - * color of player (Ranks) - * @return String - */ - public String getColor() { - if(customColor != null) return customColor; - if(isNicked()) return Perms.getColor(Perms.Ranks.Premium); - return Perms.getColor(getRank()); + if(isNicked()) return getPrefix(Ranks.Premium); + return getPrefix(getRank()); } - public Color getArmorColor() { - return Perms.getArmorColor(getRank()); + public String getSuffix() { + if(customSuffix != null) return customSuffix; + if(isNicked()) return getSuffix(Ranks.Premium); + return getSuffix(getRank()); + } + + public String getColor() { + if(customColor != null) return customColor; + if(isNicked()) return getColor(Ranks.Premium); + return getColor(getRank()); + } + + public Team getTeam() { + if(isNicked()) return getTeam(Ranks.Premium); + return getTeam(getRank()); } - - /** - * sets a custom prefix - * @param prefix String - */ + + //TODO: add function + public boolean isNicked() { + return false; + } + + public boolean isNickedReal() { + return false; + } + + public void setNicked(boolean nick) { + + } + + public Color getArmorColor() { + return getArmorColor(getRank()); + } + public void setCustomPrefix(String prefix) { customPrefix = prefix; } - - /** - * sets a custom suffix - * @param suffix String - */ + public void setCustomSuffix(String suffix) { customSuffix = suffix; } - - /** - * sets a custom color - * @param color String - */ + public void setCustomColor(String color) { customColor = color; } - - /** - * gets scoreboard team for player - * @return Team - */ - public Team getTeam() { - Perms.Teams teams = new Perms.Teams(this); - if(isNicked()) { - return teams.Premium; - }else { - return Perms.Teams.getTeam(this); - } - } - - /** - * bans player - * @param reason why ban him ? - * @param who who banned him ? - * @param time ban duration - */ - public void ban(String reason, CustomPlayer who, Integer time) { - try { - BanSystem.setBanned(this, reason, who, time); - } catch (SQLException | ClassNotFoundException e) { - e.printStackTrace(); - } - } - /** - * if player is banned - * @return true/false - */ - public boolean isBanned() { - try { - return BanSystem.isBanned(this); - } catch (SQLException | ClassNotFoundException e) { - e.printStackTrace(); - return false; - } - } - - /** - * get ban reason - * @return String - */ - public String getBanReason() { - try { - return BanSystem.getBanReason(this); - } catch (SQLException | ClassNotFoundException e) { - e.printStackTrace(); - return null; - } - - } - - /** - * get uuid of player who banned - * @return String - */ - public String getWhoBanned() { - try { - return BanSystem.getWhoBanned(this); - } catch (SQLException | ClassNotFoundException e) { - e.printStackTrace(); - return null; - } - } - public Timestamp getBanTime() { - try { - return BanSystem.getBanTime(this); - } catch (SQLException e) { - e.printStackTrace(); - return null; - } - } - - /** - * unbans the player - */ - public void removeAllBans() { - try { - BanSystem.removeAllBans(this); - } catch (SQLException | ClassNotFoundException e) { - e.printStackTrace(); - } - } - - /** - * get nickname of player - * @return String - */ - public String getNick() { - return NickName.getNick(this); - } - - /** - * if player is nicked - * @return true/false - */ - public boolean isNicked() { - if(ServerSettings.isGame()) { - try { - return NickName.isNicked(this); - } catch (SQLException | ClassNotFoundException e) { - e.printStackTrace(); - return false; - } - } - return false; - } - - /** - * checks if player is nicked - * @return true/false - */ - public boolean isNickedReal() { - try { - return NickName.isNicked(this); - } catch (SQLException | ClassNotFoundException e) { - e.printStackTrace(); - } - return false; - } - - /** - * sets nickname - * @param is boolean - */ - public void setNicked(boolean is) { - try { - NickName.setNick(this, is); - } catch (SQLException | ClassNotFoundException e) { - e.printStackTrace(); - } - } - - public void nick(String nick) { - NickName.setName(this, nick); - NickName.changeSkin(this, nick); - } - - public void unnick() { - NickName.changeSkin(this, getName()); - NickName.setName(this, getName()); - } - - /** - * checks if player has played on the network before - * @return true/false - */ - @Override - public boolean hasPlayedBefore() { - MySQL sql = Core.returnSQL(); - try { - sql.openConnection(); - String uuid = this.getUniqueId().toString(); - ResultSet rs = sql.getConnection().createStatement().executeQuery("SELECT * FROM users WHERE UUID= '" + uuid + "';"); - if (rs.next()) { - sql.closeConnection(); - return true; - }else { - sql.closeConnection(); - return false; - } - - } catch (ClassNotFoundException | SQLException e) { - e.printStackTrace(); - return false; - } - } - - /** - * checks if inventory is empty - * @return true/false - */ public boolean hasEmptyInventory() { return Utils.hasEmptyInventory(PLAYER); } - - /** - * clears all potion effects from player - */ + public void clearPotionEffects() { Utils.clearPotionEffects(PLAYER); } - - /** - * checks if players has a open inventory - * @return true/false - */ + public boolean hasOpenInventory() { return openInventory; } - /** - * sets opened inventory - * @param openInventory true/false - */ + public void setOpenInventory(boolean openInventory) { this.openInventory = openInventory; } - - /** - * gets coins from player - * @return coins as integer - */ - public int getCoins() { - return Coins.getCoins(this); - } - - /** - * sets coins if player - * @param coins coins as integer - */ - public void setCoins(int coins) { - Coins.setCoins(this, coins); - } - - /** - * adds coins to player coins - * @param coins coins as integer - */ + public void addCoins(int coins) { - int temp = Coins.getCoins(this); - Coins.setCoins(this, temp + coins); + setCoins(getCoins() + coins); } - - /** - * substracts coins from player coins - * @param coins coins as integer - */ + public void substractCoins(int coins) { - int temp = Coins.getCoins(this); - Coins.setCoins(this, temp - coins); + setCoins(getCoins() - coins); } - /** - * sends message with actionbar to player - * @param text String - */ + public void sendActionBar(String text) { Actionbar.send(PLAYER, text); } - /** - * gets experience from player - * @return experience experience as integer - */ - public int getExperience() { - return Experience.getExperience(this); - } - - /** - * sets experience of player - * @param experience experience to set - */ - public void setExperience(int experience) { - Experience.setExperience(this, experience); - } - - /** - * adds experience to player - * @param experience experience to add - */ public void addExperience(int experience) { - int temp = Experience.getExperience(this); - Experience.setExperience(this, temp + experience); + setExperience(getExperience() + experience); setExp(0F); giveExp(getExperience()); playSound(getLocation(), Sound.ENTITY_PLAYER_LEVELUP, 1.0F, 1.0F); } - - /** - * removes experience from player - * @param experience experience to remove - */ + public void substractExperience(int experience) { - int temp = Experience.getExperience(this); - Experience.setExperience(this, temp - experience); + setExperience(getExperience() - experience); setExp(0F); giveExp(getExperience()); } @@ -781,31 +516,8 @@ public class CustomPlayer extends CraftPlayer { giveExp(getExperience()); } - public int getFoundSecrets() { - return 0; - } - - public String getLanguage() { - return "DE"; - } - - public void setLanguage(String lang) { - PlayerSettings.set(lang, "lang", this); - } - - public boolean isSetting(String setting) { - return PlayerSettings.isSet(setting, this); - } - - public String getSetting(String setting) { return PlayerSettings.get(setting, this); } - - public void changeSetting(String setting) { - PlayerSettings.change(setting, this); - } - public void playParticle(Location loc, EnumParticle ep, float f, int count) { - if(isSetting("effects")) - Effects.playEffectToPlayer(PLAYER, loc, ep, f, count); + if(hasEffects()) Effects.playEffectToPlayer(PLAYER, loc, ep, f, count); } public void setAttackSpeed(double speed) { @@ -820,6 +532,8 @@ public class CustomPlayer extends CraftPlayer { public void resetAttackSpeed() { AttributeModifier modifier = new AttributeModifier("Core", getAttackSpeed(), AttributeModifier.Operation.ADD_NUMBER); getAttribute(Attribute.GENERIC_ATTACK_SPEED).removeModifier(modifier); + AttributeInstance instance = getAttribute(Attribute.GENERIC_ATTACK_SPEED); + instance.setBaseValue(16.0D); } public Messages getMessages() { @@ -829,4 +543,231 @@ public class CustomPlayer extends CraftPlayer { public Statistics getStatistics(Game game) { return new Statistics(this, game); } + + private void setInDatabase(String name, Object obj) { + userCollection.updateOne(new Document("uuid", getUniqueId()), new Document("$set", new Document(name, obj))); + } + + private Object getObjectFromDatbase(String name) { + FindIterable cursor = userCollection.find(new Document("uuid", getUniqueId())); + cursor.cursorType(CursorType.NonTailable); + + Document doc = cursor.first(); + if (doc == null) return null; + + return doc.get(name); + } + + private int getIntegerFromDatabase(String name) { + FindIterable cursor = userCollection.find(new Document("uuid", getUniqueId())); + cursor.cursorType(CursorType.NonTailable); + + Document doc = cursor.first(); + if (doc == null) return 0; + + return doc.getInteger(name); + } + + private String getStringFromDatabase(String name) { + FindIterable cursor = userCollection.find(new Document("uuid", getUniqueId())); + cursor.cursorType(CursorType.NonTailable); + + Document doc = cursor.first(); + if (doc == null) return null; + + return doc.getString(name); + } + + private Date getDateFromDatabase(String name) { + FindIterable cursor = userCollection.find(new Document("uuid", getUniqueId())); + cursor.cursorType(CursorType.NonTailable); + + Document doc = cursor.first(); + if (doc == null) return null; + + return doc.getDate(name); + } + + private ArrayList getArrayListFromDatabase(String name) { + return (ArrayList) getObjectFromDatbase(name); + } + + private Map getMapFromDatabase(String name) { + return (Map) getObjectFromDatbase(name); + } + + public String getPrefix(Ranks r) { + switch(r) { + case Admin: return "§8[§4Admin§8]§4 "; + case SrDeveloper: return "§8[§3Dev+§8]§3 "; + case Developer: return "§8[§3Dev§8]§3 "; + case SrModerator: return "§8[§cSrMod§8]§c "; + case HeadBuilder: return "§8[§aHead-Builder§8]§a "; + case Moderator: return "§8[§cMod§8]§c "; + case Builder: return "§8[§2Builder§8]§2 "; + case Supporter: return "§8[§9Supporter§8]§9 "; + case Youtuber: return "§5"; + case Premium: return "§6"; + case Player: return "§e"; + default: return "§cFehler "; + } + } + + public String getSuffix(Ranks r) { + switch(r) { + case Admin: return "§8 »§7 "; + case SrDeveloper: return "§8 »§7"; + case Developer: return "§8 »§7 "; + case SrModerator: return "§8 »§7 "; + case HeadBuilder: return "§8 »§7 "; + case Moderator: return "§8 »§7 "; + case Builder: return "§8 »§7 "; + case Supporter: return "§8 »§7 "; + case Youtuber: return "§8 »§7 "; + case Premium: return "§8 »§7 "; + case Player: return "§8 »§7 "; + default: return "§cFehler"; + } + } + + public String getColor(Ranks r) { + switch(r) { + case Admin: return "§4"; + case SrDeveloper: return "§3"; + case Developer: return "§3"; + case SrModerator: return "§c"; + case HeadBuilder: return "§a"; + case Moderator: return "§c"; + case Builder: return "§2"; + case Supporter: return "§9"; + case Youtuber: return "§5"; + case Premium: return "§6"; + case Player: return "§e"; + default: return "§cFehler"; + } + } + + private Color getArmorColor(Ranks r) { + switch (r) { + case Admin: return Color.MAROON; + case SrDeveloper: return Color.TEAL; + case Developer: return Color.TEAL; + case SrModerator: return Color.RED; + case HeadBuilder: return Color.LIME; + case Moderator: return Color.RED; + case Builder: return Color.GREEN; + case Supporter: return Color.PURPLE; + default: return null; + } + } + + public Team getTeam(Ranks r) { + switch (r) { + case Admin: return Admin; + case SrDeveloper: return SrDeveloper; + case Developer: return Developer; + case SrModerator: return SrModerator; + case HeadBuilder: return HeadBuilder; + case Moderator: return Moderator; + case Builder: return Builder; + case Supporter: return Supporter; + case Youtuber: return Youtuber; + case Premium: return Premium; + case Player: return Player; + default: return Player; + } + } + private Scoreboard board = getScoreboard(); + private Team Admin = board.getTeam("a"); + private Team SrDeveloper = board.getTeam("b"); + private Team Developer = board.getTeam("c"); + private Team SrModerator = board.getTeam("d"); + private Team HeadBuilder = board.getTeam("e"); + private Team Moderator = board.getTeam("f"); + private Team Builder = board.getTeam("g"); + private Team Supporter = board.getTeam("h"); + private Team Youtuber = board.getTeam("i"); + private Team Premium = board.getTeam("j"); + private Team Player = board.getTeam("k"); + + public void initScoreboard() { + Scoreboard board = getScoreboard(); + board.getTeams().forEach(Team::unregister); + + Team Admin = board.registerNewTeam("a"); + Team SrDeveloper = board.registerNewTeam("b"); + Team Developer = board.registerNewTeam("c"); + Team SrModerator = board.registerNewTeam("d"); + Team HeadBuilder = board.registerNewTeam("e"); + Team Moderator = board.registerNewTeam("f"); + Team Builder = board.registerNewTeam("g"); + Team Supporter = board.registerNewTeam("h"); + Team Youtuber = board.registerNewTeam("i"); + Team Premium = board.registerNewTeam("j"); + Team Player = board.registerNewTeam("k"); + + Admin.setPrefix(getColor(Ranks.Admin)); + SrDeveloper.setPrefix(getColor(Ranks.SrDeveloper)); + Developer.setPrefix(getColor(Ranks.Developer)); + SrModerator.setPrefix(getColor(Ranks.SrModerator)); + HeadBuilder.setPrefix(getColor(Ranks.HeadBuilder)); + Moderator.setPrefix(getColor(Ranks.Moderator)); + Builder.setPrefix(getColor(Ranks.Builder)); + Supporter.setPrefix(getColor(Ranks.Supporter)); + Youtuber.setPrefix(getColor(Ranks.Youtuber)); + Premium.setPrefix(getColor(Ranks.Premium)); + Player.setPrefix(getColor(Ranks.Player)); + + Admin.setOption(Team.Option.NAME_TAG_VISIBILITY, Team.OptionStatus.ALWAYS); + SrDeveloper.setOption(Team.Option.NAME_TAG_VISIBILITY, Team.OptionStatus.ALWAYS); + Developer.setOption(Team.Option.NAME_TAG_VISIBILITY, Team.OptionStatus.ALWAYS); + SrModerator.setOption(Team.Option.NAME_TAG_VISIBILITY, Team.OptionStatus.ALWAYS); + HeadBuilder.setOption(Team.Option.NAME_TAG_VISIBILITY, Team.OptionStatus.ALWAYS); + Moderator.setOption(Team.Option.NAME_TAG_VISIBILITY, Team.OptionStatus.ALWAYS); + Builder.setOption(Team.Option.NAME_TAG_VISIBILITY, Team.OptionStatus.ALWAYS); + Supporter.setOption(Team.Option.NAME_TAG_VISIBILITY, Team.OptionStatus.ALWAYS); + Youtuber.setOption(Team.Option.NAME_TAG_VISIBILITY, Team.OptionStatus.ALWAYS); + Premium.setOption(Team.Option.NAME_TAG_VISIBILITY, Team.OptionStatus.ALWAYS); + Player.setOption(Team.Option.NAME_TAG_VISIBILITY, Team.OptionStatus.ALWAYS); + + + } + + public void setLabyModFeatures(HashMap list) { + HashMap temp = new HashMap<>(); + for(LabyModFeature feature : list.keySet()) { + temp.put(feature.name(), list.get(feature)); + } + ByteArrayOutputStream byteOut = new ByteArrayOutputStream(); + try { + ObjectOutputStream out = new ObjectOutputStream(byteOut); + out.writeObject(temp); + ByteBuf byteBuf = Unpooled.copiedBuffer(byteOut.toByteArray()); + PacketDataSerializer packetDataSerializer = new PacketDataSerializer(byteBuf); + PacketPlayOutCustomPayload packet = new PacketPlayOutCustomPayload("LABYMOD", packetDataSerializer); + getHandle().playerConnection.sendPacket(packet); + + } catch (IOException e) { + e.printStackTrace(); + } + + } + + public enum LabyModFeature{ + FOOD("FOOD", 0), + GUI("GUI", 1), + NICK("NICK", 2), + BLOCKBUILD("BLOCKBUILD", 3), + CHAT("CHAT", 4), + EXTRAS("EXTRAS", 5), + ANIMATIONS("ANIMATIONS", 6), + POTIONS("POTIONS", 7), + ARMOR("ARMOR", 8), + DAMAGEINDICATOR("DAMAGEINDICATOR", 9), + MINIMAP_RADAR("MINIMAP_RADAR", 10); + + private LabyModFeature(String s, int n) { + + } + } } \ No newline at end of file diff --git a/src/main/java/eu/univento/core/api/player/Experience.java b/src/main/java/eu/univento/core/api/player/Experience.java index 012a28d..dc960c9 100644 --- a/src/main/java/eu/univento/core/api/player/Experience.java +++ b/src/main/java/eu/univento/core/api/player/Experience.java @@ -20,7 +20,7 @@ public class Experience{ * @return experience as integer */ static int getExperience(CustomPlayer p) { - int id = p.getID(); + int id = 0; MySQL sql = Core.returnSQL(); try { sql.openConnection(); @@ -44,7 +44,7 @@ public class Experience{ * @param experience experience to set */ static void setExperience(CustomPlayer p, int experience) { - int id = p.getID(); + int id = 0; MySQL sql = Core.returnSQL(); try { sql.openConnection(); diff --git a/src/main/java/eu/univento/core/api/player/Friends.java b/src/main/java/eu/univento/core/api/player/Friends.java index 3301acc..c5c23e4 100644 --- a/src/main/java/eu/univento/core/api/player/Friends.java +++ b/src/main/java/eu/univento/core/api/player/Friends.java @@ -37,7 +37,7 @@ public class Friends { try { sql.openConnection(); ArrayList list = new ArrayList(); - ResultSet rs = sql.getConnection().createStatement().executeQuery("SELECT * FROM Friends WHERE Player_ID = '" + player.getID()); + ResultSet rs = sql.getConnection().createStatement().executeQuery("SELECT * FROM Friends WHERE Player_ID = '" + 0 + "';"); while(rs.next()) { list.add(rs.getInt("Friend_ID")); } @@ -57,7 +57,7 @@ public class Friends { MySQL sql = Core.returnSQL(); try { sql.openConnection(); - PreparedStatement ps = sql.getConnection().prepareStatement("INSERT INTO Friends ('Player_ID', 'Friend_ID') VALUES ('" + player.getID() + "', '" + p.getID() + "');"); + PreparedStatement ps = sql.getConnection().prepareStatement("INSERT INTO Friends ('Player_ID', 'Friend_ID') VALUES ('" + 0 + "', '" + 0 + "');"); ps.execute(); sql.closeConnection(); } catch (ClassNotFoundException | SQLException e) { @@ -73,7 +73,7 @@ public class Friends { MySQL sql = Core.returnSQL(); try { sql.openConnection(); - PreparedStatement ps = sql.getConnection().prepareStatement("DELETE FROM Friends WHERE Player_ID='" + player.getID() + "' AND Friend_ID='" + p.getID() + "');"); + PreparedStatement ps = sql.getConnection().prepareStatement("DELETE FROM Friends WHERE Player_ID='" + 0 + "' AND Friend_ID='" + 0 + "');"); ps.execute(); sql.closeConnection(); } catch (ClassNotFoundException | SQLException e) { @@ -87,7 +87,7 @@ public class Friends { * @return true/false */ public boolean isFriend(CustomPlayer p) { - return getFriends().contains(p.getID()); + return getFriends().contains(0); } /** diff --git a/src/main/java/eu/univento/core/api/player/NickName.java b/src/main/java/eu/univento/core/api/player/NickName.java index af45b27..fd4f966 100644 --- a/src/main/java/eu/univento/core/api/player/NickName.java +++ b/src/main/java/eu/univento/core/api/player/NickName.java @@ -50,9 +50,9 @@ public class NickName { MySQL sql = Core.returnSQL(); sql.openConnection(); if (nick) - sql.getConnection().createStatement().executeUpdate("UPDATE PlayerSettings SET nick = '1' WHERE ID = '" + p.getID() + "';"); + sql.getConnection().createStatement().executeUpdate("UPDATE PlayerSettings SET nick = '1' WHERE ID = '" + 0 + "';"); else - sql.getConnection().createStatement().executeUpdate("UPDATE PlayerSettings SET nick = '0' WHERE ID = '" + p.getID() + "';"); + sql.getConnection().createStatement().executeUpdate("UPDATE PlayerSettings SET nick = '0' WHERE ID = '" + 0 + "';"); sql.closeConnection(); } @@ -66,7 +66,7 @@ public class NickName { static boolean isNicked(CustomPlayer p) throws SQLException, ClassNotFoundException { MySQL sql = Core.returnSQL(); sql.openConnection(); - ResultSet rs = sql.getConnection().createStatement().executeQuery("SELECT nick FROM PlayerSettings WHERE ID = '" + p.getID() + "';"); + ResultSet rs = sql.getConnection().createStatement().executeQuery("SELECT nick FROM PlayerSettings WHERE ID = '" + 0 + "';"); if (rs.next()) { boolean is = rs.getInt("nick") == 1; sql.closeConnection(); diff --git a/src/main/java/eu/univento/core/api/player/Perms.java b/src/main/java/eu/univento/core/api/player/Perms.java deleted file mode 100644 index 6a9819d..0000000 --- a/src/main/java/eu/univento/core/api/player/Perms.java +++ /dev/null @@ -1,307 +0,0 @@ -package eu.univento.core.api.player; - -import eu.univento.core.Core; -import eu.univento.core.api.database.MySQL; -import org.bukkit.Color; -import org.bukkit.scoreboard.Scoreboard; -import org.bukkit.scoreboard.Team; - -import java.sql.PreparedStatement; -import java.sql.ResultSet; -import java.sql.SQLException; -import java.util.HashMap; - -/** - * some permission management - * @author joethei - * @version 1.0 - */ -public class Perms{ - - private static HashMap ranks = new HashMap<>(); - public static HashMap getRanks() { - return ranks; - } - -/** - * gets the prefix of a player - * @param r Ranks - * @return String - */ -static String getPrefix(Ranks r) { - switch(r) { - case Admin: return "§8[§4Admin§8]§4 "; - case SrDeveloper: return "§8[§3Dev+§8]§3 "; - case Developer: return "§8[§3Dev§8]§3 "; - case SrModerator: return "§8[§cSrMod§8]§c "; - case HeadBuilder: return "§8[§aHead-Builder§8]§a "; - case Moderator: return "§8[§cMod§8]§c "; - case Builder: return "§8[§2Builder§8]§2 "; - case Supporter: return "§8[§9Supporter§8]§9 "; - case Youtuber: return "§5"; - case Premium: return "§6"; - case Player: return "§e"; - default: return "§cFehler "; - } - } - -/** - * gets the suffix of a player - * @param r Ranks - * @return String - */ -static String getSuffix(Ranks r) { - switch(r) { - case Admin: return "§8 »§7 "; - case SrDeveloper: return "§8 »§7"; - case Developer: return "§8 »§7 "; - case SrModerator: return "§8 »§7 "; - case HeadBuilder: return "§8 »§7 "; - case Moderator: return "§8 »§7 "; - case Builder: return "§8 »§7 "; - case Supporter: return "§8 »§7 "; - case Youtuber: return "§8 »§7 "; - case Premium: return "§8 »§7 "; - case Player: return "§8 »§7 "; - default: return "§cFehler"; - } - } - -/** - * gets color of a player - * @param r Ranks - * @return String - */ -static String getColor(Ranks r) { - switch(r) { - case Admin: return "§4"; - case SrDeveloper: return "§3"; - case Developer: return "§3"; - case SrModerator: return "§c"; - case HeadBuilder: return "§a"; - case Moderator: return "§c"; - case Builder: return "§2"; - case Supporter: return "§9"; - case Youtuber: return "§5"; - case Premium: return "§6"; - case Player: return "§e"; - default: return "§cFehler"; - } - } - -static Color getArmorColor(Ranks r) { - switch (r) { - case Admin: return Color.MAROON; - case SrDeveloper: return Color.TEAL; - case Developer: return Color.TEAL; - case SrModerator: return Color.RED; - case HeadBuilder: return Color.LIME; - case Moderator: return Color.RED; - case Builder: return Color.GREEN; - case Supporter: return Color.PURPLE; - default: return null; - } -} - -/** - * contains all scoreboard ranks - * @author joethei - * @version 1.0 - */ -static class Teams { - - CustomPlayer player; - Scoreboard board; - - Team Admin; - Team SrDeveloper; - Team Developer; - Team SrModerator; - Team Moderator; - Team HeadBuilder; - Team Builder; - Team Supporter; - Team Youtuber; - Team Premium; - Team Player; - - Teams(CustomPlayer player) { - this.player = player; - board = player.getScoreboard(); - Admin = board.getTeam("a"); - SrDeveloper = board.getTeam("b"); - Developer = board.getTeam("c"); - SrModerator = board.getTeam("d"); - HeadBuilder = board.getTeam("e"); - Moderator = board.getTeam("f"); - Builder = board.getTeam("g"); - Supporter = board.getTeam("h"); - Youtuber = board.getTeam("i"); - Premium = board.getTeam("j"); - Player = board.getTeam("k"); - } - - /** - * returns scoreboard team for rank - * @param p CustomPlayer - * @return Team - */ - static Team getTeam(CustomPlayer p) { - Teams teams = new Teams(p); - switch(p.getRank()) { - case Admin: return teams.Admin; - case SrDeveloper: return teams.SrDeveloper; - case Developer: return teams.Developer; - case SrModerator: return teams.SrModerator; - case HeadBuilder: return teams.HeadBuilder; - case Moderator: return teams.Moderator; - case Builder: return teams.Builder; - case Supporter: return teams.Supporter; - case Youtuber: return teams.Youtuber; - case Premium: return teams.Premium; - case Player: return teams.Player; - default: return null; - } - } -} - -/** - * setup scoreboards - */ -public static void initScoreboard(CustomPlayer p) { - Scoreboard board = p.getScoreboard(); - board.getTeams().forEach(Team::unregister); - - Team Admin = board.registerNewTeam("a"); - Team SrDeveloper = board.registerNewTeam("b"); - Team Developer = board.registerNewTeam("c"); - Team SrModerator = board.registerNewTeam("d"); - Team HeadBuilder = board.registerNewTeam("e"); - Team Moderator = board.registerNewTeam("f"); - Team Builder = board.registerNewTeam("g"); - Team Supporter = board.registerNewTeam("h"); - Team Youtuber = board.registerNewTeam("i"); - Team Premium = board.registerNewTeam("j"); - Team Player = board.registerNewTeam("k"); - - Admin.setPrefix(getColor(Ranks.Admin)); - SrDeveloper.setPrefix(getColor(Ranks.SrDeveloper)); - Developer.setPrefix(getColor(Ranks.Developer)); - SrModerator.setPrefix(getColor(Ranks.SrModerator)); - HeadBuilder.setPrefix(getColor(Ranks.HeadBuilder)); - Moderator.setPrefix(getColor(Ranks.Moderator)); - Builder.setPrefix(getColor(Ranks.Builder)); - Supporter.setPrefix(getColor(Ranks.Supporter)); - Youtuber.setPrefix(getColor(Ranks.Youtuber)); - Premium.setPrefix(getColor(Ranks.Premium)); - Player.setPrefix(getColor(Ranks.Player)); - - Admin.setOption(Team.Option.NAME_TAG_VISIBILITY, Team.OptionStatus.ALWAYS); - SrDeveloper.setOption(Team.Option.NAME_TAG_VISIBILITY, Team.OptionStatus.ALWAYS); - Developer.setOption(Team.Option.NAME_TAG_VISIBILITY, Team.OptionStatus.ALWAYS); - SrModerator.setOption(Team.Option.NAME_TAG_VISIBILITY, Team.OptionStatus.ALWAYS); - HeadBuilder.setOption(Team.Option.NAME_TAG_VISIBILITY, Team.OptionStatus.ALWAYS); - Moderator.setOption(Team.Option.NAME_TAG_VISIBILITY, Team.OptionStatus.ALWAYS); - Builder.setOption(Team.Option.NAME_TAG_VISIBILITY, Team.OptionStatus.ALWAYS); - Supporter.setOption(Team.Option.NAME_TAG_VISIBILITY, Team.OptionStatus.ALWAYS); - Youtuber.setOption(Team.Option.NAME_TAG_VISIBILITY, Team.OptionStatus.ALWAYS); - Premium.setOption(Team.Option.NAME_TAG_VISIBILITY, Team.OptionStatus.ALWAYS); - Player.setOption(Team.Option.NAME_TAG_VISIBILITY, Team.OptionStatus.ALWAYS); -} -/** - * gets Rank of player - * @param p Player - * @return Ranks - * @throws ClassNotFoundException Class couldn't be found - * @throws SQLException SQL server not available or throwing error - */ -static Ranks getRank(CustomPlayer p) throws ClassNotFoundException, SQLException { - if(getRanks().get(p) != null) { - return getRanks().get(p); - }else { - return getRankFresh(p); - } - - } - -/** - * gets Rank of player fresh from database - * @param p Player - * @return Ranks - * @throws ClassNotFoundException Class couldn't be found - * @throws SQLException SQL server not available or throwing error - */ -static Ranks getRankFresh(CustomPlayer p) throws SQLException, ClassNotFoundException { - MySQL sql = Core.returnSQL(); - sql.openConnection(); - String uuid = p.getUniqueId().toString(); - PreparedStatement st = sql.getConnection().prepareStatement("SELECT * FROM users WHERE UUID= '" + uuid + "';"); - ResultSet rs = st.executeQuery(); - if(rs.next()) { - String rank = rs.getString("Rank"); - sql.closeConnection(); - return Ranks.valueOf(rank); - }else { - sql.closeConnection(); - return null; - } - } - - /** - * sets rank for player - * @param p Player - * @param r Ranks - * @throws ClassNotFoundException Class couldn't be found - * @throws SQLException SQL server not available or throwing error - */ -static void setRank(CustomPlayer p, Ranks r) throws ClassNotFoundException, SQLException { - MySQL sql = Core.returnSQL(); - sql.openConnection(); - PreparedStatement st = sql.getConnection().prepareStatement("UPDATE users SET Rank='" + r.toString() + "' WHERE ID='" + p.getID() + "';"); - st.execute(); - sql.closeConnection(); - } - -/** - * if player is allowed to do - * @param p Player - * @param r Ranks - * @return true / false - * @throws ClassNotFoundException Class couldn't be found - * @throws SQLException SQL server not available or throwing error - */ -static boolean isAllowed(CustomPlayer p, Ranks r) throws ClassNotFoundException, SQLException{ - Ranks rank; - if(getRank(p) == null) { - rank = getRankFresh(p); - }else { - rank = getRank(p); - } - return rank.value >= r.value; - } - -/** - * contains all ranks - * @author joethei - * @version 1.0 - */ - public enum Ranks{ - Admin(11), - SrDeveloper(10), - Developer(9), - SrModerator(8), - HeadBuilder(7), - Moderator(6), - Builder(5), - Supporter(4), - Youtuber(3), - Premium(2), - Player(1); - - final int value; - - Ranks(int n) { - this.value = n; - } - } -} \ No newline at end of file diff --git a/src/main/java/eu/univento/core/api/player/PlayerSettings.java b/src/main/java/eu/univento/core/api/player/PlayerSettings.java index 07cf824..b9592d4 100644 --- a/src/main/java/eu/univento/core/api/player/PlayerSettings.java +++ b/src/main/java/eu/univento/core/api/player/PlayerSettings.java @@ -25,7 +25,7 @@ public class PlayerSettings { * @return boolean */ static boolean isSet(String what, CustomPlayer p) { - int id = p.getID(); + int id = 0; MySQL sql = Core.returnSQL(); try { sql.openConnection(); @@ -53,7 +53,7 @@ public class PlayerSettings { * @throws SQLException SQL ServerPinger not available or throwing error */ static void set(boolean bool, String what, CustomPlayer p) throws SQLException, ClassNotFoundException { - int id = p.getID(); + int id = 0; MySQL sql = Core.returnSQL(); sql.openConnection(); if (bool) { @@ -73,7 +73,7 @@ public class PlayerSettings { * @return String */ static String get(String what, CustomPlayer p) { - int id = p.getID(); + int id = 0; MySQL sql = Core.returnSQL(); try { sql.openConnection(); @@ -98,7 +98,7 @@ public class PlayerSettings { * @param p CustomPlayer */ static void set(String set, String what, CustomPlayer p) { - int id = p.getID(); + int id = 0; MySQL sql = Core.returnSQL(); try { sql.openConnection(); diff --git a/src/main/java/eu/univento/core/api/player/Ranks.java b/src/main/java/eu/univento/core/api/player/Ranks.java new file mode 100644 index 0000000..d8fe0fb --- /dev/null +++ b/src/main/java/eu/univento/core/api/player/Ranks.java @@ -0,0 +1,21 @@ +package eu.univento.core.api.player; + +public enum Ranks { + Admin(11), + SrDeveloper(10), + Developer(9), + SrModerator(8), + HeadBuilder(7), + Moderator(6), + Builder(5), + Supporter(4), + Youtuber(3), + Premium(2), + Player(1); + + final int value; + + Ranks(int n) { + this.value = n; + } +} \ No newline at end of file diff --git a/src/main/java/eu/univento/core/api/player/Statistics.java b/src/main/java/eu/univento/core/api/player/Statistics.java index 4541342..7de2d95 100644 --- a/src/main/java/eu/univento/core/api/player/Statistics.java +++ b/src/main/java/eu/univento/core/api/player/Statistics.java @@ -36,7 +36,7 @@ public class Statistics { MySQL sql = Core.returnSQL(); try { sql.openConnection(); - PreparedStatement st = sql.getConnection().prepareStatement("SELECT Deaths FROM " + game.toString() + "Stats WHERE ID='" + player.getID() + "');"); + PreparedStatement st = sql.getConnection().prepareStatement("SELECT Deaths FROM " + game.toString() + "Stats WHERE ID='" + 0 + "');"); ResultSet rs = st.executeQuery(); int deaths = rs.getInt("Deaths"); sql.closeConnection(); @@ -55,7 +55,7 @@ public class Statistics { MySQL sql = Core.returnSQL(); try { sql.openConnection(); - PreparedStatement st = sql.getConnection().prepareStatement("UPDATE " + game.toString() + "Stats WHERE ID='" + player.getID() + "' SET Deaths='" + deaths +"');"); + PreparedStatement st = sql.getConnection().prepareStatement("UPDATE " + game.toString() + "Stats WHERE ID='" + 0 + "' SET Deaths='" + deaths +"');"); st.execute(); } catch (ClassNotFoundException | SQLException e) { e.printStackTrace(); @@ -74,7 +74,7 @@ public class Statistics { MySQL sql = Core.returnSQL(); try { sql.openConnection(); - PreparedStatement st = sql.getConnection().prepareStatement("SELECT Kills FROM " + game.toString() + "Stats WHERE ID='" + player.getID() + "');"); + PreparedStatement st = sql.getConnection().prepareStatement("SELECT Kills FROM " + game.toString() + "Stats WHERE ID='" + 0 + "');"); ResultSet rs = st.executeQuery(); int kills = rs.getInt("Kills"); sql.closeConnection(); @@ -93,7 +93,7 @@ public class Statistics { MySQL sql = Core.returnSQL(); try { sql.openConnection(); - PreparedStatement st = sql.getConnection().prepareStatement("UPDATE " + game.toString() + "Stats WHERE ID='" + player.getID() + "' SET Kills='" + kills +"');"); + PreparedStatement st = sql.getConnection().prepareStatement("UPDATE " + game.toString() + "Stats WHERE ID='" + 0 + "' SET Kills='" + kills +"');"); st.execute(); } catch (ClassNotFoundException | SQLException e) { e.printStackTrace(); @@ -112,7 +112,7 @@ public class Statistics { MySQL sql = Core.returnSQL(); try { sql.openConnection(); - PreparedStatement st = sql.getConnection().prepareStatement("SELECT PlayedRounds FROM " + game.toString() + "Stats WHERE ID='" + player.getID() + "');"); + PreparedStatement st = sql.getConnection().prepareStatement("SELECT PlayedRounds FROM " + game.toString() + "Stats WHERE ID='" + 0 + "');"); ResultSet rs = st.executeQuery(); int rounds = rs.getInt("PlayedRounds"); sql.closeConnection(); @@ -131,7 +131,7 @@ public class Statistics { MySQL sql = Core.returnSQL(); try { sql.openConnection(); - PreparedStatement st = sql.getConnection().prepareStatement("UPDATE " + game.toString() + "Stats WHERE ID='" + player.getID() + "' SET PlayedRounds='" + rounds +"');"); + PreparedStatement st = sql.getConnection().prepareStatement("UPDATE " + game.toString() + "Stats WHERE ID='" + 0 + "' SET PlayedRounds='" + rounds +"');"); st.execute(); } catch (ClassNotFoundException | SQLException e) { e.printStackTrace(); @@ -150,7 +150,7 @@ public class Statistics { MySQL sql = Core.returnSQL(); try { sql.openConnection(); - PreparedStatement st = sql.getConnection().prepareStatement("SELECT Playtime FROM " + game.toString() + "Stats WHERE ID='" + player.getID() + "');"); + PreparedStatement st = sql.getConnection().prepareStatement("SELECT Playtime FROM " + game.toString() + "Stats WHERE ID='" + 0 + "');"); ResultSet rs = st.executeQuery(); int time = rs.getInt("Playtime"); sql.closeConnection(); @@ -169,7 +169,7 @@ public class Statistics { MySQL sql = Core.returnSQL(); try { sql.openConnection(); - PreparedStatement st = sql.getConnection().prepareStatement("UPDATE " + game.toString() + "Stats WHERE ID='" + player.getID() + "' SET Playtime='" + time +"');"); + PreparedStatement st = sql.getConnection().prepareStatement("UPDATE " + game.toString() + "Stats WHERE ID='" + 0 + "' SET Playtime='" + time +"');"); st.execute(); } catch (ClassNotFoundException | SQLException e) { e.printStackTrace(); @@ -184,7 +184,7 @@ public class Statistics { MySQL sql = Core.returnSQL(); try { sql.openConnection(); - PreparedStatement st = sql.getConnection().prepareStatement("SELECT Wins FROM " + game.toString() + "Stats WHERE ID='" + player.getID() + "');"); + PreparedStatement st = sql.getConnection().prepareStatement("SELECT Wins FROM " + game.toString() + "Stats WHERE ID='" + 0 + "');"); ResultSet rs = st.executeQuery(); int wins = rs.getInt("Wins"); sql.closeConnection(); @@ -203,7 +203,7 @@ public class Statistics { MySQL sql = Core.returnSQL(); try { sql.openConnection(); - PreparedStatement st = sql.getConnection().prepareStatement("UPDATE " + game.toString() + "Stats WHERE ID='" + player.getID() + "' SET Wins='" + wins +"');"); + PreparedStatement st = sql.getConnection().prepareStatement("UPDATE " + game.toString() + "Stats WHERE ID='" + 0 + "' SET Wins='" + wins +"');"); st.execute(); } catch (ClassNotFoundException | SQLException e) { e.printStackTrace(); diff --git a/src/main/java/eu/univento/core/commands/Ban.java b/src/main/java/eu/univento/core/commands/Ban.java index 28de10d..7164573 100644 --- a/src/main/java/eu/univento/core/commands/Ban.java +++ b/src/main/java/eu/univento/core/commands/Ban.java @@ -4,7 +4,7 @@ import eu.univento.core.Core; import eu.univento.core.api.AutoCommand; import eu.univento.core.api.languages.Messages; import eu.univento.core.api.player.CustomPlayer; -import eu.univento.core.api.player.Perms.Ranks; +import eu.univento.core.api.player.Ranks; import org.bukkit.Bukkit; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; @@ -41,7 +41,6 @@ public class Ban extends AutoCommand{ CustomPlayer t = CustomPlayer.getPlayer(args[0]); if(getReasons().containsValue(args[1])) { int id = getKey(args[1]); - t.ban(getReasons().get(id), p, getBanDurations().get(id)); }else { p.sendMessage(msgs.PREFIX() + msgs.Core_BAN_NO_REASON()); } diff --git a/src/main/java/eu/univento/core/commands/Build.java b/src/main/java/eu/univento/core/commands/Build.java index 3d87ba1..7243cd2 100644 --- a/src/main/java/eu/univento/core/commands/Build.java +++ b/src/main/java/eu/univento/core/commands/Build.java @@ -4,7 +4,7 @@ import eu.univento.core.Core; import eu.univento.core.api.AutoCommand; import eu.univento.core.api.languages.Messages; import eu.univento.core.api.player.CustomPlayer; -import eu.univento.core.api.player.Perms.Ranks; +import eu.univento.core.api.player.Ranks; import eu.univento.core.api.server.ServerSettings; import org.bukkit.GameMode; import org.bukkit.command.CommandSender; diff --git a/src/main/java/eu/univento/core/commands/ChatClear.java b/src/main/java/eu/univento/core/commands/ChatClear.java index 32741d2..577bcac 100644 --- a/src/main/java/eu/univento/core/commands/ChatClear.java +++ b/src/main/java/eu/univento/core/commands/ChatClear.java @@ -4,7 +4,7 @@ import eu.univento.core.Core; import eu.univento.core.api.AutoCommand; import eu.univento.core.api.languages.Messages; import eu.univento.core.api.player.CustomPlayer; -import eu.univento.core.api.player.Perms.Ranks; +import eu.univento.core.api.player.Ranks; import org.bukkit.Bukkit; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; diff --git a/src/main/java/eu/univento/core/commands/GameMode.java b/src/main/java/eu/univento/core/commands/GameMode.java index 05e41b3..8e19156 100644 --- a/src/main/java/eu/univento/core/commands/GameMode.java +++ b/src/main/java/eu/univento/core/commands/GameMode.java @@ -4,7 +4,7 @@ import eu.univento.core.Core; import eu.univento.core.api.AutoCommand; import eu.univento.core.api.languages.Messages; import eu.univento.core.api.player.CustomPlayer; -import eu.univento.core.api.player.Perms.Ranks; +import eu.univento.core.api.player.Ranks; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; diff --git a/src/main/java/eu/univento/core/commands/GlobalMute.java b/src/main/java/eu/univento/core/commands/GlobalMute.java index c489173..2a4372e 100644 --- a/src/main/java/eu/univento/core/commands/GlobalMute.java +++ b/src/main/java/eu/univento/core/commands/GlobalMute.java @@ -4,7 +4,7 @@ import eu.univento.core.Core; import eu.univento.core.api.AutoCommand; import eu.univento.core.api.languages.Messages; import eu.univento.core.api.player.CustomPlayer; -import eu.univento.core.api.player.Perms.Ranks; +import eu.univento.core.api.player.Ranks; import eu.univento.core.api.server.ServerSettings; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; diff --git a/src/main/java/eu/univento/core/commands/Nick.java b/src/main/java/eu/univento/core/commands/Nick.java index c3bfae6..f6926f2 100644 --- a/src/main/java/eu/univento/core/commands/Nick.java +++ b/src/main/java/eu/univento/core/commands/Nick.java @@ -4,7 +4,7 @@ import eu.univento.core.Core; import eu.univento.core.api.AutoCommand; import eu.univento.core.api.languages.Messages; import eu.univento.core.api.player.CustomPlayer; -import eu.univento.core.api.player.Perms.Ranks; +import eu.univento.core.api.player.Ranks; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; @@ -40,14 +40,14 @@ public class Nick extends AutoCommand{ p.setDisplayName(p.getName()); p.getTeam().addEntry(p.getDisplayName()); p.sendMessage(msgs.PREFIX() + msgs.Core_NICK_OFF()); - p.unnick(); + //p.unnick(); }else { p.getTeam().removeEntry(p.getDisplayName()); p.setNicked(true); - p.setDisplayName(p.getNick()); + //p.setDisplayName(p.getNick()); p.getTeam().addEntry(p.getDisplayName()); p.sendMessage(msgs.PREFIX() + msgs.Core_NICK_ON()); - p.nick(p.getNick()); + //p.nick(p.getNick()); } }else { p.sendMessage(msgs.NO_PERMS()); diff --git a/src/main/java/eu/univento/core/commands/RunAs.java b/src/main/java/eu/univento/core/commands/RunAs.java index ce97b75..cf48e61 100644 --- a/src/main/java/eu/univento/core/commands/RunAs.java +++ b/src/main/java/eu/univento/core/commands/RunAs.java @@ -4,7 +4,7 @@ import eu.univento.core.Core; import eu.univento.core.api.AutoCommand; import eu.univento.core.api.languages.Messages; import eu.univento.core.api.player.CustomPlayer; -import eu.univento.core.api.player.Perms.Ranks; +import eu.univento.core.api.player.Ranks; import org.bukkit.Bukkit; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; @@ -35,7 +35,7 @@ public class RunAs extends AutoCommand{ if(sender instanceof Player) { CustomPlayer p = CustomPlayer.getPlayer(sender.getName()); Messages msgs = new Messages(p); - if(p.isAllowed(Ranks.Admin)) { + if(p.isAllowed(Ranks.SrDeveloper)) { if(args.length >= 2) { CustomPlayer t = CustomPlayer.getPlayer(Bukkit.getPlayer(args[0]).getName()); if(t != null) { diff --git a/src/main/java/eu/univento/core/commands/SetRank.java b/src/main/java/eu/univento/core/commands/SetRank.java index 8d8e08f..6a47ed0 100644 --- a/src/main/java/eu/univento/core/commands/SetRank.java +++ b/src/main/java/eu/univento/core/commands/SetRank.java @@ -4,7 +4,7 @@ import eu.univento.core.Core; import eu.univento.core.api.AutoCommand; import eu.univento.core.api.languages.Messages; import eu.univento.core.api.player.CustomPlayer; -import eu.univento.core.api.player.Perms.Ranks; +import eu.univento.core.api.player.Ranks; import org.bukkit.Bukkit; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; @@ -38,28 +38,35 @@ public class SetRank extends AutoCommand{ Ranks rank = Ranks.valueOf(args[1]); if(rank != null) { if(Bukkit.getPlayer(args[0]) != null) { - CustomPlayer player = CustomPlayer.getPlayer(Bukkit.getPlayer(args[0])); - if(p.isAllowed(Ranks.HeadBuilder) && rank.equals(Ranks.Builder)) { - player.setRank(rank); - p.sendMessage(p.getMessages().PREFIX() + p.getMessages().Core_SETRANK_SET(player, player.getRank())); - player.kickPlayer(player.getMessages().Core_SETRANK_KICK()); - }if(p.isAllowed(Ranks.SrModerator) && rank.equals(Ranks.Moderator)) { - player.setRank(rank); - p.sendMessage(p.getMessages().PREFIX() + p.getMessages().Core_SETRANK_SET(player, player.getRank())); - player.kickPlayer(player.getMessages().Core_SETRANK_KICK()); - }if(p.isAllowed(Ranks.SrModerator) && rank.equals(Ranks.Supporter)) { - player.setRank(rank); - p.sendMessage(p.getMessages().PREFIX() + p.getMessages().Core_SETRANK_SET(player, player.getRank())); - player.kickPlayer(player.getMessages().Core_SETRANK_KICK()); - }if(p.isAllowed(Ranks.SrDeveloper) && rank.equals(Ranks.Developer)) { - player.setRank(rank); - p.sendMessage(p.getMessages().PREFIX() + p.getMessages().Core_SETRANK_SET(player, player.getRank())); - player.kickPlayer(player.getMessages().Core_SETRANK_KICK()); + CustomPlayer player = CustomPlayer.getPlayer(args[0]); + if(player.isAllowed(rank)) { + p.sendMessage(p.getMessages().PREFIX() + "§cDer Spieler hat den Rang schon oder ist besser."); + p.sendMessage(p.getMessages().PREFIX() + "§cÄnderungen müssen in der Datenbank stattfinden."); + return true; } if(p.isAllowed(Ranks.Admin)) { player.setRank(rank); p.sendMessage(p.getMessages().PREFIX() + p.getMessages().Core_SETRANK_SET(player, player.getRank())); player.kickPlayer(player.getMessages().Core_SETRANK_KICK()); + } + if(p.isAllowed(Ranks.SrDeveloper) && rank.equals(Ranks.Developer)) { + player.setRank(Ranks.Developer); + p.sendMessage(p.getMessages().PREFIX() + p.getMessages().Core_SETRANK_SET(player, Ranks.Developer)); + player.kickPlayer(player.getMessages().Core_SETRANK_KICK()); + } + if(p.isAllowed(Ranks.SrModerator) && rank.equals(Ranks.Moderator)) { + player.setRank(Ranks.Moderator); + p.sendMessage(p.getMessages().PREFIX() + p.getMessages().Core_SETRANK_SET(player, Ranks.Moderator)); + player.kickPlayer(player.getMessages().Core_SETRANK_KICK()); + }if(p.isAllowed(Ranks.SrModerator) && rank.equals(Ranks.Supporter)) { + player.setRank(Ranks.Supporter); + p.sendMessage(p.getMessages().PREFIX() + p.getMessages().Core_SETRANK_SET(player, Ranks.Supporter)); + player.kickPlayer(player.getMessages().Core_SETRANK_KICK()); + } + if(p.isAllowed(Ranks.HeadBuilder) && rank.equals(Ranks.Builder)) { + player.setRank(Ranks.Builder); + p.sendMessage(p.getMessages().PREFIX() + p.getMessages().Core_SETRANK_SET(player, Ranks.Builder)); + player.kickPlayer(player.getMessages().Core_SETRANK_KICK()); } }else { p.sendMessage(p.getMessages().NOT_ONLINE(args[0])); diff --git a/src/main/java/eu/univento/core/commands/SystemInfo.java b/src/main/java/eu/univento/core/commands/SystemInfo.java index 0e8d9d3..315ef7a 100644 --- a/src/main/java/eu/univento/core/commands/SystemInfo.java +++ b/src/main/java/eu/univento/core/commands/SystemInfo.java @@ -4,11 +4,13 @@ import eu.univento.core.Core; import eu.univento.core.api.AutoCommand; import eu.univento.core.api.languages.Messages; import eu.univento.core.api.player.CustomPlayer; -import eu.univento.core.api.player.Perms.Ranks; +import eu.univento.core.api.player.Ranks; import org.bukkit.Bukkit; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; +import java.net.InetAddress; +import java.net.UnknownHostException; import java.util.List; /** @@ -35,8 +37,13 @@ public class SystemInfo extends AutoCommand{ Messages msgs = new Messages(p); if(p.isAllowed(Ranks.SrModerator)) { Runtime run = Runtime.getRuntime(); - p.sendMessage("§6§l===SystemInfo ==="); - p.sendMessage("§6Spigot version: " + Bukkit.getVersion()); + p.sendMessage("§6§l===SystemInfo <" + Bukkit.getServerName() + ">==="); + try { + p.sendMessage("§6Server: " + InetAddress.getLocalHost().getHostName()); + } catch (UnknownHostException e) { + e.printStackTrace(); + } + p.sendMessage("§6Spigot version: " + Bukkit.getVersion()); p.sendMessage("§6used memory: " + (run.totalMemory() - run.freeMemory() / 1048576L) + " MB"); p.sendMessage("§6free memory: " + run.freeMemory() / 1048576L + " MB"); p.sendMessage("§6total memory: " + run.maxMemory() / 1048576L + " MB"); diff --git a/src/main/java/eu/univento/core/commands/Twitch.java b/src/main/java/eu/univento/core/commands/Twitch.java deleted file mode 100644 index d290f1b..0000000 --- a/src/main/java/eu/univento/core/commands/Twitch.java +++ /dev/null @@ -1,65 +0,0 @@ -package eu.univento.core.commands; - -import eu.univento.core.Core; -import eu.univento.core.api.AutoCommand; -import eu.univento.core.api.languages.Messages; -import eu.univento.core.api.player.CustomPlayer; -import eu.univento.core.api.twitch.Twitch_API; -import eu.univento.core.api.twitch.Twitch_Stream; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; - -import java.util.List; - -/** - * send info about twitch streams - * @author joethei - * @version 1.0 - */ -public class Twitch extends AutoCommand{ - - /** - * @param plugin main class - * @param command command to execute - * @param description describes the command - * @param aliases aliases of command - */ - public Twitch(Core plugin, String command, String description, String... aliases) { - super(plugin, command, description, aliases); - } - - @Override - public boolean execute(CommandSender sender, String label, String[] args) { - if(sender instanceof Player) { - CustomPlayer p = CustomPlayer.getPlayer(sender.getName()); - Messages msgs = new Messages(p); - if(args.length == 1) { - Twitch_Stream stream = Twitch_API.getStream(args[0]); - if(stream != null) { - p.sendMessage("§a" + stream.getBroadcaster()); - p.sendMessage("§aBenutzername: " + stream.getUsername()); - p.sendMessage("§aSpiel: " + stream.getMeta_game()); - p.sendMessage("§aKategorie: " + stream.getCategory()); - p.sendMessage("§aTitel: " + stream.getTitle()); - p.sendMessage("§aStatus: " + stream.getStatus()); - p.sendMessage("§aZuschauer:" + stream.getChannel_view_count()); - p.sendMessage("§aSprachen: " + stream.getGeo()); - p.sendMessage("§aOnline seit: " + stream.getUp_time()); - }else { - p.sendMessage(msgs.PREFIX() + "§aDen Benutzer gibt es nicht"); - } - }else { - p.sendMessage(msgs.PREFIX() + "§cNutze /twitch "); - } - }else { - sender.sendMessage(Messages.Console.NOT_A_PLAYER); - } - return true; - } - - @Override - public List tabComplete(CommandSender sender, String label, String[] args) { - return null; - } - -} \ No newline at end of file diff --git a/src/main/java/eu/univento/core/commands/Vanish.java b/src/main/java/eu/univento/core/commands/Vanish.java index 6c7bfe9..1ce004e 100644 --- a/src/main/java/eu/univento/core/commands/Vanish.java +++ b/src/main/java/eu/univento/core/commands/Vanish.java @@ -4,7 +4,7 @@ import eu.univento.core.Core; import eu.univento.core.api.AutoCommand; import eu.univento.core.api.languages.Messages; import eu.univento.core.api.player.CustomPlayer; -import eu.univento.core.api.player.Perms.Ranks; +import eu.univento.core.api.player.Ranks; import org.bukkit.Bukkit; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; diff --git a/src/main/java/eu/univento/core/listeners/Chat.java b/src/main/java/eu/univento/core/listeners/Chat.java index 6854ec9..fd4c042 100644 --- a/src/main/java/eu/univento/core/listeners/Chat.java +++ b/src/main/java/eu/univento/core/listeners/Chat.java @@ -2,7 +2,7 @@ package eu.univento.core.listeners; import eu.univento.core.api.languages.Messages; import eu.univento.core.api.player.CustomPlayer; -import eu.univento.core.api.player.Perms.Ranks; +import eu.univento.core.api.player.Ranks; import eu.univento.core.api.server.ServerSettings; import net.md_5.bungee.api.ChatColor; import org.bukkit.event.EventHandler; diff --git a/src/main/java/eu/univento/core/listeners/Commands.java b/src/main/java/eu/univento/core/listeners/Commands.java index ef1beed..14b3a44 100644 --- a/src/main/java/eu/univento/core/listeners/Commands.java +++ b/src/main/java/eu/univento/core/listeners/Commands.java @@ -3,7 +3,7 @@ package eu.univento.core.listeners; import eu.univento.core.Core; import eu.univento.core.api.languages.Messages; import eu.univento.core.api.player.CustomPlayer; -import eu.univento.core.api.player.Perms.Ranks; +import eu.univento.core.api.player.Ranks; import org.bukkit.Bukkit; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; @@ -41,17 +41,12 @@ public class Commands implements Listener{ if(p.isAllowed(Ranks.Admin)) { e.setCancelled(true); Bukkit.broadcastMessage(msgs.PREFIX() + "§cWarning ! Server will be restarted"); - Bukkit.getScheduler().scheduleSyncDelayedTask(Core.getInstance(), new Runnable() { - - @Override - public void run() { - for(Player players : Bukkit.getOnlinePlayers()) { - players.kickPlayer("§cServer has been restarted \n §6Please join again at: \n §bplay§5.§6univento§5.§aeu"); - } - Bukkit.getServer().spigot().restart(); - } - - }, 100L); + Bukkit.getScheduler().scheduleSyncDelayedTask(Core.getInstance(), () -> { + for(Player players : Bukkit.getOnlinePlayers()) { + players.kickPlayer("§cServer has been restarted \n §6Please join again at: \n §bplay§5.§6univento§5.§aeu"); + } + Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "/restart"); + }, 100L); }else { p.sendMessage(msgs.NO_PERMS()); } diff --git a/src/main/java/eu/univento/core/listeners/Events.java b/src/main/java/eu/univento/core/listeners/Events.java index 6b4b5cf..6afab8a 100644 --- a/src/main/java/eu/univento/core/listeners/Events.java +++ b/src/main/java/eu/univento/core/listeners/Events.java @@ -31,7 +31,7 @@ public class Events implements Listener{ @EventHandler(priority = EventPriority.HIGHEST) public void onInventoryClick(InventoryClickEvent e) { - Inventory inv = e.getClickedInventory(); + Inventory inv = e.getInventory(); if(e.getWhoClicked() instanceof Player) { CustomPlayer p = CustomPlayer.getPlayer(e.getWhoClicked().getName()); if(inv.getName().equals(JoinQuit.getLanguageChooser(p).getName())) { diff --git a/src/main/java/eu/univento/core/listeners/JoinQuit.java b/src/main/java/eu/univento/core/listeners/JoinQuit.java index 53c3763..9219641 100644 --- a/src/main/java/eu/univento/core/listeners/JoinQuit.java +++ b/src/main/java/eu/univento/core/listeners/JoinQuit.java @@ -3,11 +3,8 @@ package eu.univento.core.listeners; import eu.univento.core.Core; import eu.univento.core.api.Title; import eu.univento.core.api.Utils; -import eu.univento.core.api.database.MySQL; -import eu.univento.core.api.languages.Messages; import eu.univento.core.api.player.CustomPlayer; import eu.univento.core.api.player.NickName; -import eu.univento.core.api.player.Perms; import eu.univento.core.api.player.Spectator; import eu.univento.core.api.server.ServerSettings; import eu.univento.core.commands.Build; @@ -27,12 +24,6 @@ import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.ItemMeta; import org.bukkit.scoreboard.Team; -import java.sql.PreparedStatement; -import java.sql.ResultSet; -import java.sql.SQLException; -import java.sql.Timestamp; -import java.util.Date; - /** * @author joethei * @version 1.0 @@ -46,7 +37,6 @@ public class JoinQuit implements Listener{ @EventHandler public void onJoin(PlayerJoinEvent e) { CustomPlayer p = CustomPlayer.getPlayer(e.getPlayer()); - Messages msgs = new Messages(p); for(Player players : Bukkit.getOnlinePlayers()) { CustomPlayer player = CustomPlayer.getPlayer(players); @@ -59,24 +49,20 @@ public class JoinQuit implements Listener{ } if(!p.hasPlayedBefore()) { - //p.insertToDatabase(); - Perms.getRanks().put(p, p.getFreshRank()); + p.insertToDatabase(); for(int i = 0; i <= 15; i++) { Utils.randomFirework(p.getEyeLocation()); } Title.sendTitle(p, 0, 100, 0, "§6Welcome", "§aPlease choose a language"); Bukkit.getScheduler().scheduleSyncDelayedTask(Core.getInstance(), () -> p.openInventory(getLanguageChooser(p)), 100L); - return; } - //p.updateDatabaseEntry(); - Perms.getRanks().put(p, p.getFreshRank()); - Title.sendTabTitle(p, msgs.Core_TAB_TITLE() + Bukkit.getServerName() , msgs.TAB_PREFIX()); + p.updateDatabaseEntry(); + Title.sendTabTitle(p, p.getMessages().Core_TAB_TITLE() + Bukkit.getServerName() , p.getMessages().TAB_PREFIX()); p.setGameMode(ServerSettings.getGameMode()); p.setScoreboard(Bukkit.getScoreboardManager().getNewScoreboard()); - Perms.initScoreboard(p); - + p.initScoreboard(); if(p.isNicked()) { - p.nick(p.getNick()); + //TODO: add nicking back in } for(Player players : Bukkit.getOnlinePlayers()){ @@ -108,53 +94,15 @@ public class JoinQuit implements Listener{ if(Build.getPlayers().containsKey(p)) Build.getPlayers().remove(p); if(ServerSettings.isGame()) { - p.setNicked(false); p.setDisplayName(p.getName()); - p.unnick(); NickName.remove(p); } for(Team team : p.getScoreboard().getTeams()) { team.removeEntry(p.getDisplayName()); } - Perms.getRanks().remove(p); p.onLeave(); } - - /** - * creates player in database - * @param p CustomPlayer - */ - void createPlayer(CustomPlayer p) { - MySQL sql = Core.returnSQL(); - Date date = new Date(); - Timestamp time = new Timestamp(date.getTime()); - String uuid = p.getUniqueId().toString(); - try { - sql.openConnection(); - PreparedStatement st = sql.getConnection().prepareStatement("SELECT UUID FROM users WHERE UUID ='" + uuid + "'"); - ResultSet res = st.executeQuery(); - if (!res.next()){ - PreparedStatement st2 = sql.getConnection().prepareStatement("INSERT INTO users (UUID, FirstJoin, Rank, Coins) VALUES ('" + uuid + "','" + time + "', '" + Perms.Ranks.Player.toString() + "', 0);"); - st2.execute(); - - int id = p.getID(); - - PreparedStatement st3 = sql.getConnection().prepareStatement("INSERT INTO PlayerSettings (ID, teleport, FastMenu, requestsParty, requestsFriend, joined, nick) VALUES ('" + id +"', '1', '0', '1', '1', '0', '0',);"); - st3.execute(); - - PreparedStatement st4 = sql.getConnection().prepareStatement("INSERT INTO FoundItems(ID, music_3, sugar, feather, hearts) VALUES ('" + id + "',0, 0, 0, 0);"); - st4.execute(); - - sql.closeConnection(); - return; - } - sql.closeConnection(); - } - catch (SQLException | ClassNotFoundException e) { - e.printStackTrace(); - } - } - + /** * Handles KickMessage @@ -162,9 +110,7 @@ public class JoinQuit implements Listener{ */ @EventHandler(priority=EventPriority.HIGHEST) public void onKick(PlayerKickEvent e) { - CustomPlayer p = CustomPlayer.getPlayer(e.getPlayer()); e.setLeaveMessage(null); - p.setNicked(false); } static Inventory getLanguageChooser(CustomPlayer p) {