diff --git a/dependency-reduced-pom.xml b/dependency-reduced-pom.xml index 2d3d2bc..e188008 100644 --- a/dependency-reduced-pom.xml +++ b/dependency-reduced-pom.xml @@ -1,9 +1,9 @@ 4.0.0 - FPChat + com.fpghoti FPChat - 1.1.1 + 1.1.2 src/main/java @@ -35,12 +35,6 @@ 1.7 - - - org.apache.commons*:* - - - @@ -63,8 +57,30 @@ org.spigotmc spigot-api - 1.16.2-R0.1-SNAPSHOT - compile + 1.16.3-R0.1-SNAPSHOT + provided + + + commons-lang + commons-lang + + + guava + com.google.guava + + + gson + com.google.code.gson + + + bungeecord-chat + net.md-5 + + + snakeyaml + org.yaml + + com.github.MilkBowl diff --git a/pom.xml b/pom.xml index 73360b9..eb05e3d 100644 --- a/pom.xml +++ b/pom.xml @@ -2,9 +2,9 @@ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 - FPChat + com.fpghoti FPChat - 1.1.1 + 1.1.2 spigot-repo @@ -43,13 +43,6 @@ 3.0.0 1.7 - - - org.apache.commons*:* - - - - @@ -67,11 +60,13 @@ org.apache.commons commons-lang3 3.0 + compile org.spigotmc spigot-api - 1.16.2-R0.1-SNAPSHOT + 1.16.3-R0.1-SNAPSHOT + provided com.github.MilkBowl @@ -79,5 +74,11 @@ 1.7 provided + + com.zaxxer + HikariCP + 3.4.5 + compile + \ No newline at end of file diff --git a/src/main/java/com/fpghoti/fpchatx/FPChat.java b/src/main/java/com/fpghoti/fpchatx/FPChat.java index ed5f323..6a707aa 100644 --- a/src/main/java/com/fpghoti/fpchatx/FPChat.java +++ b/src/main/java/com/fpghoti/fpchatx/FPChat.java @@ -59,7 +59,6 @@ public class FPChat extends JavaPlugin { private MySQLConnection sql; private static FPChat plugin; private String pluginTag; - private int mysqlTimer = 1140; private BukkitTask refresh = null; private PlayerListener listener = null; private PlayerCache cache; @@ -235,14 +234,6 @@ public class FPChat extends JavaPlugin { } } } - if(config.mySQLEnabled()){ // mysql auto reconnect - if(mysqlTimer >= 1200){ - sql.reconnect(); - mysqlTimer = 0; - }else{ - mysqlTimer++; - } - } } }.runTaskTimerAsynchronously(this, 1*20, 1*20); } diff --git a/src/main/java/com/fpghoti/fpchatx/badge/Badge.java b/src/main/java/com/fpghoti/fpchatx/badge/Badge.java index 2c17fa9..29b469c 100644 --- a/src/main/java/com/fpghoti/fpchatx/badge/Badge.java +++ b/src/main/java/com/fpghoti/fpchatx/badge/Badge.java @@ -2,12 +2,12 @@ package com.fpghoti.fpchatx.badge; import com.fpghoti.fpchatx.FPChat; import com.fpghoti.fpchatx.config.BadgeConfig; -import com.fpghoti.fpchatx.player.FPlayer; public class Badge { private static BadgeList badges; private static BadgeConfig bconfig = null; + private static Badge zero = new Badge(0, "Empty", "", "", false); public static void loadBadges() { badges = new BadgeList(); @@ -21,6 +21,10 @@ public class Badge { } return bconfig; } + + public static Badge getZero() { + return zero; + } public static BadgeList getList() { return badges; diff --git a/src/main/java/com/fpghoti/fpchatx/badge/BadgeData.java b/src/main/java/com/fpghoti/fpchatx/badge/BadgeData.java new file mode 100644 index 0000000..973ce7b --- /dev/null +++ b/src/main/java/com/fpghoti/fpchatx/badge/BadgeData.java @@ -0,0 +1,270 @@ +package com.fpghoti.fpchatx.badge; + +import java.sql.Connection; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.HashMap; +import java.util.concurrent.CompletableFuture; +import java.util.logging.Level; + +import com.fpghoti.fpchatx.FPChat; +import com.fpghoti.fpchatx.player.FPlayer; +import com.fpghoti.fpchatx.util.Util; + +public class BadgeData { + + private FPlayer player; + private HashMap slots; + private BadgeList badges; + + public BadgeData(FPlayer player) { + this.player = player; + this.slots = new HashMap(); + badges = new BadgeList(); + CompletableFuture.runAsync(() -> { + createPlayerData(); + }).thenRunAsync(() -> { + getPlayerData(); + savePlayerData(); + }); + } + + public FPlayer getPlayer() { + return player; + } + + public Badge getBadge(int slot) { + if(slot <= 0 || !FPChat.getPlugin().getMainConfig().mySQLEnabled() || slot > FPChat.getPlugin().getMainConfig().getMaxBadgeSlots()) { + return null; + } + return slots.get(slot); + } + + public BadgeList getBadgeList() { + return this.badges; + } + + public void clearLoadout() { + this.slots = new HashMap(); + savePlayerData(); + } + + public void clearBadgeList() { + this.badges = new BadgeList(); + savePlayerData(); + } + + /**Will equip the badge regardless of the user's permissions.**/ + public BadgeEquipResult setBadge(int slot, Badge badge) { + if(!FPChat.getPlugin().getMainConfig().mySQLEnabled()) { + return BadgeEquipResult.NO_SQL; + } + if(slot <= 0 || slot > FPChat.getPlugin().getMainConfig().getMaxBadgeSlots()) { + return BadgeEquipResult.INVALID_SLOT; + } + slots.put(slot, badge); + savePlayerData(); + return BadgeEquipResult.SUCCESS; + } + + /**Will not equip badge if user does not have permission + * to use the badge or slot.**/ + public BadgeEquipResult equipBadge(int slot, Badge badge) { + if(!hasSlotPermission(slot)) { + return BadgeEquipResult.NO_PERMISSION_SLOT; + } + if(!player.hasPermission(badge.getPerm())) { + return BadgeEquipResult.NO_PERMISSION_BADGE; + } + return setBadge(slot, badge); + } + + public String getAppearanceString() { + String appearance = ""; + if(slots.isEmpty()) { + return ""; + } + for(int slot = 1; slot <= FPChat.getPlugin().getMainConfig().getMaxBadgeSlots(); slot++) { + if(hasSlotPermission(slot)) { + Badge badge = slots.get(slot); + if(badge != null && badge.isEnabled() && player.hasPermission(badge.getPerm())) { + appearance = badge.getContents() + appearance; + } + } + } + return appearance; + } + + public String toString() { + int max = FPChat.getPlugin().getMainConfig().getMaxBadgeSlots(); + String val = ""; + boolean first = true; + for(int slot = 1; slot <= max; slot++) { + Badge badge = getBadge(slot); + int id = 0; + if(badge != null) { + id = badge.getId(); + } + if(first) { + first = false; + val = Integer.toString(id); + }else { + val = val + "," + Integer.toString(id); + } + } + return val; + } + + private void setLoadoutFromString(String str) { + String[] array = str.split(","); + HashMap loadout = new HashMap(); + for(int i = 0; i < array.length; i++) { + int slot = i + 1; + String item = array[i]; + if(Util.isDigit(item)) { + int id = Integer.parseInt(item); + if(Badge.getList().containsId(id)) { + loadout.put(slot, Badge.getList().get(id)); + }else { + loadout.put(slot, Badge.getZero()); + } + }else { + loadout.put(slot, Badge.getZero()); + } + } + } + + private boolean hasSlotPermission(int slot) { + return player.hasPermission("fpchat.slot" + Integer.toString(slot)) || hasSlotBadge(slot); + } + + private boolean hasSlotBadge(int slot) { + for(Badge b : Badge.getList().getSlotUnlockBadges(slot)) { + if(badges.containsId(b.getId())) { + return true; + } + } + return false; + } + + private void createPlayerData() { + createSQLLoadoutEntry(); + createSQLBadgeListEntry(); + } + + private void getPlayerData() { + String loadoutString = getLoadoutSQLString(); + setLoadoutFromString(loadoutString); + String badgeListString = getBadgeListSQLString(); + badges = BadgeList.fromString(badgeListString); + } + + public void savePlayerData() { + saveNewBadgesToSQL(); + setBadgeListSQLString(badges.toString()); + setLoadoutSQLString(toString()); + } + + private void saveNewBadgesToSQL() { + for(Badge badge : Badge.getList()) { + if(player.hasPermission(badge.getPerm()) && !badges.containsId(badge.getId())) { + badges.add(badge); + } + } + } + + private void createSQLLoadoutEntry(){ + String uuid = player.getUniqueId().toString(); + Connection connection = null; + try { + connection = FPChat.getPlugin().getMySQLConnection().getConnection(); + if(!FPChat.getPlugin().getMySQLConnection().itemExists("player_uuid", uuid, FPChat.getPlugin().getMainConfig().getChatFeatureTable())){ + FPChat.getPlugin().getMySQLConnection().update("INSERT INTO " + FPChat.getPlugin().getMainConfig().getChatFeatureTable() + " (player_uuid, badge_loadout) VALUES ( '" + uuid + "', '' )"); + } + }catch(SQLException e) { + e.printStackTrace(); + }finally{ + try { + connection.close(); + } catch (SQLException e) { + e.printStackTrace(); + } + } + } + + private String getLoadoutSQLString() { + String uuid = player.getUniqueId().toString(); + String value = null; + Connection connection = null; + try{ + connection = FPChat.getPlugin().getMySQLConnection().getConnection(); + ResultSet rs = FPChat.getPlugin().getMySQLConnection().query("SELECT * FROM " + FPChat.getPlugin().getMainConfig().getChatFeatureTable() + " WHERE player_uuid = '" + uuid + "';", connection); + if (rs.next()) { + value = (String) rs.getObject("badge_loadout"); + } + }catch(SQLException e) { + FPChat.getPlugin().log(Level.SEVERE, "MySQL get error: " + e.getMessage()); + e.printStackTrace(); + }finally{ + try { + connection.close(); + } catch (SQLException e) { + e.printStackTrace(); + } + } + return value; + } + + private void setLoadoutSQLString(String value) { + String uuid = player.getUniqueId().toString(); + FPChat.getPlugin().getMySQLConnection().asyncUpdate("UPDATE " + FPChat.getPlugin().getMainConfig().getChatFeatureTable() + " SET badge_loadout = '" + value + "' WHERE player_uuid = '" + uuid + "';"); + } + + private void createSQLBadgeListEntry(){ + String uuid = player.getUniqueId().toString(); + Connection connection = null; + try { + connection = FPChat.getPlugin().getMySQLConnection().getConnection(); + if(!FPChat.getPlugin().getMySQLConnection().itemExists("player_uuid", uuid, FPChat.getPlugin().getMainConfig().getPermSyncTable())){ + FPChat.getPlugin().getMySQLConnection().update("INSERT INTO " + FPChat.getPlugin().getMainConfig().getPermSyncTable() + " (player_uuid, badges) VALUES ( '" + uuid + "', '' )"); + } + }catch(SQLException e) { + e.printStackTrace(); + }finally{ + try { + connection.close(); + } catch (SQLException e) { + e.printStackTrace(); + } + } + } + + private String getBadgeListSQLString() { + String uuid = player.getUniqueId().toString(); + String value = null; + Connection connection = null; + try{ + connection = FPChat.getPlugin().getMySQLConnection().getConnection(); + ResultSet rs = FPChat.getPlugin().getMySQLConnection().query("SELECT * FROM " + FPChat.getPlugin().getMainConfig().getPermSyncTable() + " WHERE player_uuid = '" + uuid + "';", connection); + if (rs.next()) { + value = (String) rs.getObject("badges"); + } + }catch(SQLException e) { + FPChat.getPlugin().log(Level.SEVERE, "MySQL get error: " + e.getMessage()); + e.printStackTrace(); + }finally{ + try { + connection.close(); + } catch (SQLException e) { + e.printStackTrace(); + } + } + return value; + } + + private void setBadgeListSQLString(String value) { + String uuid = player.getUniqueId().toString(); + FPChat.getPlugin().getMySQLConnection().asyncUpdate("UPDATE " + FPChat.getPlugin().getMainConfig().getPermSyncTable() + " SET badges = '" + value + "' WHERE player_uuid = '" + uuid + "';"); + } + +} diff --git a/src/main/java/com/fpghoti/fpchatx/badge/BadgeEquipResult.java b/src/main/java/com/fpghoti/fpchatx/badge/BadgeEquipResult.java new file mode 100644 index 0000000..19abbb0 --- /dev/null +++ b/src/main/java/com/fpghoti/fpchatx/badge/BadgeEquipResult.java @@ -0,0 +1,36 @@ +package com.fpghoti.fpchatx.badge; + +public enum BadgeEquipResult { + + SUCCESS{ + @Override + public String toString() { + return "Success"; + } + }, + INVALID_SLOT{ + @Override + public String toString() { + return "Invalid slot"; + } + }, + NO_SQL{ + @Override + public String toString() { + return "SQL is not enabled"; + } + }, + NO_PERMISSION_BADGE{ + @Override + public String toString() { + return "User does not have permission for badge"; + } + }, + NO_PERMISSION_SLOT{ + @Override + public String toString() { + return "User does not have permission for slot"; + } + }; + +} diff --git a/src/main/java/com/fpghoti/fpchatx/badge/BadgeList.java b/src/main/java/com/fpghoti/fpchatx/badge/BadgeList.java index 8f23d95..f65ddd9 100644 --- a/src/main/java/com/fpghoti/fpchatx/badge/BadgeList.java +++ b/src/main/java/com/fpghoti/fpchatx/badge/BadgeList.java @@ -3,11 +3,27 @@ package com.fpghoti.fpchatx.badge; import java.util.ArrayList; import java.util.Iterator; +import com.fpghoti.fpchatx.util.Util; + public class BadgeList implements Iterable{ + public static BadgeList fromString(String str) { + String[] array = str.split(","); + BadgeList badgeList = new BadgeList(); + for(String item : array) { + if(Util.isDigit(item)) { + int id = Integer.parseInt(item); + if(Badge.getList().containsId(id) && !badgeList.containsId(id)) { + Badge badge = Badge.getList().get(id); + badgeList.add(badge); + } + } + } + return badgeList; + } + private ArrayList list = new ArrayList(); - private Badge empty = new Badge(0, "Empty", "", "", false); @Override public Iterator iterator() { @@ -24,6 +40,13 @@ public class BadgeList implements Iterable{ list.add(badge); } + public void add(int id) { + Badge badge = Badge.getList().get(id); + if(badge != null) { + add(badge); + } + } + public void remove(int id) { ArrayList rl = new ArrayList(list); for(Badge b : rl) { @@ -46,20 +69,46 @@ public class BadgeList implements Iterable{ return false; } + public int getLargestId() { + int largest = 0; + for(Badge b : list) { + if(b.getId() > largest) { + largest = b.getId(); + } + } + return largest; + } + + public String toString() { + boolean first = true; + String val = ""; + for(int id = 1; id <= getLargestId(); id++) { + if(containsId(id)) { + if(first) { + first = false; + val = Integer.toString(id); + }else { + val = val + "," + Integer.toString(id); + } + } + } + return val; + } + public boolean overwrites(Badge badge) { return containsId(badge.getId()); } public Badge get(int id) { if(id <= 0 || !containsId(id)) { - return empty; + return Badge.getZero(); } for(Badge b : list) { if(b.getId() == id) { return b; } } - return empty; + return Badge.getZero(); } public Badge getIndex(int index) { diff --git a/src/main/java/com/fpghoti/fpchatx/badge/Sync.java b/src/main/java/com/fpghoti/fpchatx/badge/Sync.java deleted file mode 100644 index 3270de5..0000000 --- a/src/main/java/com/fpghoti/fpchatx/badge/Sync.java +++ /dev/null @@ -1,165 +0,0 @@ -package com.fpghoti.fpchatx.badge; - -import java.util.UUID; - -import com.fpghoti.fpchatx.FPChat; -import com.fpghoti.fpchatx.player.FPlayer; -import com.fpghoti.fpchatx.util.Util; - -public class Sync { - - public static void syncBadges(FPlayer p, boolean create){ - UUID id = p.getUniqueId(); - String uuid = id.toString(); - Util.connect(); - if(create && !FPChat.getPlugin().getMySQLConnection().itemExists("player_uuid", uuid, FPChat.getPlugin().getMainConfig().getPermSyncTable())){ - createPlayer(p); - } - String raw = (String) FPChat.getPlugin().getMySQLConnection().get("badges", "player_uuid", "=", uuid, FPChat.getPlugin().getMainConfig().getPermSyncTable()); - if(raw != null && raw.length() > 0 && raw.charAt(0) == ','){ - raw = raw.substring(1); - } - if(raw != null && !raw.equals("")) { - String list[] = Util.stripLast(raw).split(","); - for(String item : list) { - if(!item.equals("")) { - Integer badgeId = Integer.parseInt(item); - p.addSyncedBadge(badgeId); - } - } - } - } - - public static Boolean syncExists(FPlayer p){ - Boolean check = false; - if(p == null) { - return false; - } - String uuid = p.getUniqueId().toString(); - Util.connect(); - if(FPChat.getPlugin().getMySQLConnection().itemExists("player_uuid", uuid, FPChat.getPlugin().getMainConfig().getPermSyncTable())){ - check = true; - } - return check; - } - - public static void update(FPlayer p) { - update(p, true); - } - - public static void update(FPlayer p, boolean create){ - String uuid = p.getUniqueId().toString(); - Util.connect(); - if(create && !FPChat.getPlugin().getMySQLConnection().itemExists("player_uuid", uuid, FPChat.getPlugin().getMainConfig().getPermSyncTable())){ - createPlayer(p); - } - syncBadges(p, false); - String nl = ""; - String nl2 = ""; - String permstring = getBadgeString(p); - String[] permids = permstring.split(","); - for(String item : permids){ - if(Util.isDigit(item)) { - int id = Integer.parseInt(item); - if(!p.isSynced(id)){ - nl = nl + item + ","; - } - } - } - for(int id : p.syncedList()){ - String item = Integer.toString(id); - nl2 = nl2 + item + ","; - } - nl = nl + nl2; - FPChat.getPlugin().getMySQLConnection().set("badges", nl, "player_uuid", "=", uuid, FPChat.getPlugin().getMainConfig().getPermSyncTable()); - syncBadges(p,false); - } - - public static void revoke(FPlayer p) { - revoke(p,true); - } - - public static void revoke(FPlayer p, boolean create) { - String uuid = p.getUniqueId().toString(); - Util.connect(); - if(create && !FPChat.getPlugin().getMySQLConnection().itemExists("player_uuid", uuid, FPChat.getPlugin().getMainConfig().getPermSyncTable())){ - createPlayer(p); - } - syncBadges(p, false); - String nl = ""; - FPChat.getPlugin().getMySQLConnection().set("badges", nl, "player_uuid", "=", uuid, FPChat.getPlugin().getMainConfig().getPermSyncTable()); - syncBadges(p, false); - } - public static void revoke(FPlayer p, int badgeId){ - revoke(p, badgeId, true); - } - - public static void revoke(FPlayer p, int badgeId, boolean create){ - String uuid = p.getUniqueId().toString(); - - Util.connect(); - if(create && !FPChat.getPlugin().getMySQLConnection().itemExists("player_uuid", uuid, FPChat.getPlugin().getMainConfig().getPermSyncTable())){ - createPlayer(p); - } - syncBadges(p, false); - String nl = ""; - String nl2 = ""; - for(String item : revokeBadgeString(p, badgeId).split(",")){ - if(Util.isDigit(item)) { - int id = Integer.parseInt(item); - if(p.isSynced(id)){ - nl = nl + item + ","; - } - } - } - for(int id : p.syncedList()){ - String item = Integer.toString(id); - if(id != badgeId){ - nl2 = nl2 + item + ","; - } - } - nl = nl + nl2; - FPChat.getPlugin().getMySQLConnection().set("badges", nl, "player_uuid", "=", uuid, FPChat.getPlugin().getMainConfig().getPermSyncTable()); - syncBadges(p, false); - } - - public static String getBadgeString(FPlayer p){ - String list = ""; - for(Badge badge : Badge.getList()){ - int id = badge.getId(); - if(badge.isEnabled() && p.hasPermission("fpchat.badge." + badge.getPerm())){ - String add = Integer.toString(id) + ","; - list = list + add; - }else if(p.getBadgeQueue().contains(id)) { - String add = Integer.toString(id) + ","; - list = list + add; - p.unqueueBadge(id); - } - } - - return list; - } - - public static String revokeBadgeString(FPlayer p, int badgeId){ - String list = ""; - for(Badge badge : Badge.getList()){ - int id = badge.getId(); - if(p.hasPermission("fpchat.badge." + badge.getPerm())){ - if(id != badgeId){ - String add = Integer.toString(id) + ","; - list = list + add; - } - } - } - - return list; - } - - public static void createPlayer(FPlayer p){ - String uuid = p.getUniqueId().toString(); - Util.connect(); - if(!FPChat.getPlugin().getMySQLConnection().itemExists("player_uuid", uuid, FPChat.getPlugin().getMainConfig().getPermSyncTable())){ - FPChat.getPlugin().getMySQLConnection().insertInto("player_uuid, badges", " '" + uuid + "', '' ", FPChat.getPlugin().getMainConfig().getPermSyncTable()); - } - } -} diff --git a/src/main/java/com/fpghoti/fpchatx/chat/ChatChannel.java b/src/main/java/com/fpghoti/fpchatx/chat/ChatChannel.java index d95fa05..1fcc170 100644 --- a/src/main/java/com/fpghoti/fpchatx/chat/ChatChannel.java +++ b/src/main/java/com/fpghoti/fpchatx/chat/ChatChannel.java @@ -10,7 +10,6 @@ import org.bukkit.OfflinePlayer; import org.bukkit.entity.Player; import com.fpghoti.fpchatx.FPChat; -import com.fpghoti.fpchatx.badge.Badge; import com.fpghoti.fpchatx.config.ChannelFile; import com.fpghoti.fpchatx.customcodes.BubbleCode; import com.fpghoti.fpchatx.customcodes.Codify; @@ -297,35 +296,24 @@ public abstract class ChatChannel { } public String format(FPlayer p, String msg) { - String finalMessage = ""; - String slot3 = "", slot2 = "", slot1 = ""; - String stf = ""; - if (Permission.canUseColor(p)) { - msg = msg.replaceAll("&([0-9a-fk-or])", "§$1"); - } else { - msg = msg.replaceAll("§[0-9a-fk-or]", ""); - } + String finalMessage = "", badges = "", stf = "", filler = ""; String header = PrepareChat.swapPlaceholders(p, this, msg); if(Permission.isStaff(p)){ stf = FPChat.getPlugin().getMainConfig().getStaffBadge(); } if(plugin.getMainConfig().mySQLEnabled()){ - Integer[] badges = p.getBadges(); - slot1 = Badge.getList().get(badges[0]).getContents(); - slot2 = Badge.getList().get(badges[1]).getContents(); - slot3 = Badge.getList().get(badges[2]).getContents(); + badges = p.getBadgeData().getAppearanceString(); } - String filler = ""; if(plugin.getMainConfig().chatFilterEnabled()){ filler = "word "; } if(Permission.canUseColor(p)){ String last = ChatFilter.filter(filler + msg); last = BubbleCode.bubblecode(Permission.canBubbleCode(p), Codify.changeFormatSign(last)); - finalMessage = stf + slot3 + slot2 + slot1 + header + last; + finalMessage = ChatColor.translateAlternateColorCodes('&', stf + badges + header + last); }else{ String newmsg = ChatColor.stripColor(ChatColor.translateAlternateColorCodes('§', ChatFilter.filter(filler + msg))); - finalMessage = stf + slot3 + slot2 + slot1 + Codify.removeBubbles(header + newmsg); + finalMessage = stf + badges + Codify.removeBubbles(header + newmsg); } return finalMessage; } diff --git a/src/main/java/com/fpghoti/fpchatx/command/commands/BadgeClearCommand.java b/src/main/java/com/fpghoti/fpchatx/command/commands/BadgeClearCommand.java index ec2f196..79148de 100644 --- a/src/main/java/com/fpghoti/fpchatx/command/commands/BadgeClearCommand.java +++ b/src/main/java/com/fpghoti/fpchatx/command/commands/BadgeClearCommand.java @@ -38,12 +38,7 @@ public class BadgeClearCommand extends Commands { } FPlayer p = FPlayer.getPlayer((Player)sender); - p.setBadge(1, 0); - p.updateBadges(1, 0); - p.setBadge(2, 0); - p.updateBadges(2, 0); - p.setBadge(3, 0); - p.updateBadges(3, 0); + p.getBadgeData().clearLoadout(); p.sendMessage(FPChat.logo() + ChatColor.YELLOW + " Unequipped all badges!"); } diff --git a/src/main/java/com/fpghoti/fpchatx/command/commands/BadgeEquipCommand.java b/src/main/java/com/fpghoti/fpchatx/command/commands/BadgeEquipCommand.java index f0708c9..44ee7f1 100644 --- a/src/main/java/com/fpghoti/fpchatx/command/commands/BadgeEquipCommand.java +++ b/src/main/java/com/fpghoti/fpchatx/command/commands/BadgeEquipCommand.java @@ -6,6 +6,7 @@ import org.bukkit.entity.Player; import com.fpghoti.fpchatx.FPChat; import com.fpghoti.fpchatx.badge.Badge; +import com.fpghoti.fpchatx.badge.BadgeEquipResult; import com.fpghoti.fpchatx.command.Commands; import com.fpghoti.fpchatx.player.FPlayer; import com.fpghoti.fpchatx.util.Util; @@ -42,16 +43,24 @@ public class BadgeEquipCommand extends Commands { if(Util.isDigit(args[0]) && Util.isDigit(args[1])){ Integer slot = Integer.parseInt(args[0]), badgeId = Integer.parseInt(args[1]); - if(p.canUseSlot(slot)){ - if(badgeId == 0 || (Badge.getList().containsId(badgeId) && Badge.getList().get(badgeId).isEnabled() && p.hasBadge(badgeId))){ - p.setBadge(slot, badgeId); - p.updateBadges(slot, badgeId); - p.sendMessage( FPChat.logo() + ChatColor.YELLOW + " You have equipped a badge!"); - }else{ - p.sendMessage(FPChat.logo() + ChatColor.YELLOW + " You do not have permission to equip this badge!"); - } - }else{ - p.sendMessage(FPChat.logo() + ChatColor.YELLOW + " You do not have permission to equip a badge in this slot!"); + + if(!Badge.getList().containsId(badgeId)) { + p.sendMessage(FPChat.logo() + ChatColor.RED + " Invalid badge!"); + return; + } + + Badge badge = Badge.getList().get(badgeId); + BadgeEquipResult result = p.getBadgeData().equipBadge(slot, badge); + + switch(result) { + + case SUCCESS: + p.sendMessage(FPChat.logo() + ChatColor.YELLOW + " You successfully equiped a badge!"); + break; + + default: + p.sendMessage(FPChat.logo() + ChatColor.RED + " Could not equip badge: " + result.toString()); + } } } diff --git a/src/main/java/com/fpghoti/fpchatx/command/commands/BadgeListCommand.java b/src/main/java/com/fpghoti/fpchatx/command/commands/BadgeListCommand.java index 17235f5..988738e 100644 --- a/src/main/java/com/fpghoti/fpchatx/command/commands/BadgeListCommand.java +++ b/src/main/java/com/fpghoti/fpchatx/command/commands/BadgeListCommand.java @@ -49,7 +49,7 @@ public class BadgeListCommand extends Commands { } } - BadgeList list = p.getSyncedBadgeList(); + BadgeList list = p.getBadgeData().getBadgeList(); int pageCount = (int) Math.ceil((double) list.getListSize() / 8); if (pg > pageCount) { diff --git a/src/main/java/com/fpghoti/fpchatx/command/commands/GiveBadgeCommand.java b/src/main/java/com/fpghoti/fpchatx/command/commands/GiveBadgeCommand.java index 46c011b..e32b33a 100644 --- a/src/main/java/com/fpghoti/fpchatx/command/commands/GiveBadgeCommand.java +++ b/src/main/java/com/fpghoti/fpchatx/command/commands/GiveBadgeCommand.java @@ -6,7 +6,6 @@ import org.bukkit.entity.Player; import com.fpghoti.fpchatx.FPChat; import com.fpghoti.fpchatx.badge.Badge; -import com.fpghoti.fpchatx.badge.Sync; import com.fpghoti.fpchatx.command.Commands; import com.fpghoti.fpchatx.permission.Permission; import com.fpghoti.fpchatx.player.FPlayer; @@ -47,9 +46,10 @@ public class GiveBadgeCommand extends Commands { } if(Util.isDigit(args[1]) && Badge.getList().containsId(Integer.parseInt(args[1]))) { int id = Integer.parseInt(args[1]); - toGive.queueBadgeAdd(id); - Sync.update(toGive); - toGive.addSyncedBadge(id); + + toGive.getBadgeData().getBadgeList().add(id); + toGive.getBadgeData().savePlayerData(); + FPlayer.goodMsg(p, "Badge granted."); }else { FPlayer.errMsg(p,"Wrong command usage."); diff --git a/src/main/java/com/fpghoti/fpchatx/command/commands/RevokeBadgeCommand.java b/src/main/java/com/fpghoti/fpchatx/command/commands/RevokeBadgeCommand.java index 9549b50..af602e6 100644 --- a/src/main/java/com/fpghoti/fpchatx/command/commands/RevokeBadgeCommand.java +++ b/src/main/java/com/fpghoti/fpchatx/command/commands/RevokeBadgeCommand.java @@ -10,7 +10,6 @@ import org.bukkit.entity.Player; import com.fpghoti.fpchatx.FPChat; import com.fpghoti.fpchatx.badge.Badge; -import com.fpghoti.fpchatx.badge.Sync; import com.fpghoti.fpchatx.command.Commands; import com.fpghoti.fpchatx.permission.Permission; import com.fpghoti.fpchatx.player.FPlayer; @@ -49,18 +48,19 @@ public class RevokeBadgeCommand extends Commands { OfflinePlayer o = Bukkit.getOfflinePlayer(u); if(o != null) { FPlayer toRevoke = FPlayer.getPlayer(o,true); - if(Sync.syncExists(toRevoke) && (Util.isDigit(args[1]) || args[1].equals("*") )){ + if(Util.isDigit(args[1]) || args[1].equals("*")){ if(args[1].equals("*")) { - Sync.revoke(toRevoke); + toRevoke.getBadgeData().clearBadgeList(); FPlayer.goodMsg(p, "All badges revoked from the specified player."); }else { if(Badge.getList().containsId(Integer.parseInt(args[1]))) { int id = Integer.parseInt(args[1]); - Sync.revoke(toRevoke, id); - toRevoke.removeSyncedBadge(id); - toRevoke.clearUnownedBadges(); + + toRevoke.getBadgeData().getBadgeList().remove(id); + toRevoke.getBadgeData().savePlayerData(); + FPlayer.goodMsg(p, "Badge revoked from the specified player."); }else { FPlayer.errMsg(p, "Invalid badge."); diff --git a/src/main/java/com/fpghoti/fpchatx/config/MainConfig.java b/src/main/java/com/fpghoti/fpchatx/config/MainConfig.java index 830d9ed..c46547d 100644 --- a/src/main/java/com/fpghoti/fpchatx/config/MainConfig.java +++ b/src/main/java/com/fpghoti/fpchatx/config/MainConfig.java @@ -9,6 +9,7 @@ import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.configuration.file.YamlConfiguration; import com.fpghoti.fpchatx.FPChat; +import com.fpghoti.fpchatx.util.Util; public class MainConfig { @@ -121,6 +122,10 @@ public class MainConfig { config.createSection("PluginTag"); config.set("PluginTag", "&a&lFPChat&r"); } + if (config.get("MaxBadgeSlots")==null){ + config.createSection("MaxBadgeSlots"); + config.set("MaxBadgeSlots", "3"); + } try { config.save(configFile); } catch (IOException e) { @@ -262,5 +267,13 @@ public class MainConfig { public String getPluginTag() { return ChatColor.translateAlternateColorCodes('&',config.getString("PluginTag")); } + + public int getMaxBadgeSlots() { + String val = config.getString("MaxBadgeSlots"); + if(Util.isDigit(val)) { + return Integer.parseInt(val); + } + return 0; + } } diff --git a/src/main/java/com/fpghoti/fpchatx/mysql/MySQLConnection.java b/src/main/java/com/fpghoti/fpchatx/mysql/MySQLConnection.java index f6f30a4..58dce2b 100644 --- a/src/main/java/com/fpghoti/fpchatx/mysql/MySQLConnection.java +++ b/src/main/java/com/fpghoti/fpchatx/mysql/MySQLConnection.java @@ -1,16 +1,15 @@ package com.fpghoti.fpchatx.mysql; import java.sql.Connection; -import java.sql.DriverManager; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; +import java.util.concurrent.CompletableFuture; import java.util.logging.Level; -import org.bukkit.scheduler.BukkitRunnable; - import com.fpghoti.fpchatx.FPChat; import com.fpghoti.fpchatx.config.MainConfig; +import com.zaxxer.hikari.HikariDataSource; public class MySQLConnection{ @@ -18,6 +17,7 @@ public class MySQLConnection{ private FPChat plugin; private String host, user, password, database, port; private MainConfig config; + private HikariDataSource hikari; public MySQLConnection(FPChat plugin) { this.plugin = plugin; @@ -27,27 +27,38 @@ public class MySQLConnection{ password = config.getPassword(); database = config.getDatabase(); port = config.getPort(); - } - - private Connection connection; - - public Connection getConnection(){ - return connection; + hikari = new HikariDataSource(); + hikari.setMaximumPoolSize(10); + hikari.setDataSourceClassName("com.mysql.jdbc.jdbc2.optional.MysqlDataSource"); + hikari.addDataSourceProperty("serverName", host); + hikari.addDataSourceProperty("user", user); + hikari.addDataSourceProperty("password", password); + hikari.addDataSourceProperty("databaseName", database); + hikari.addDataSourceProperty("port", port); } public void generate() { if(config.mySQLEnabled()){ plugin.log(Level.INFO, "Connecting to MySQL..."); - connect(); - if(!tableExists(config.getChatFeatureTable())){ - plugin.log(Level.INFO, "FPChat table not found. Creating new table..."); - //createTable(config.getChatFeatureTable(), "player_uuid VARCHAR (36), badge_slot1 INT (11), badge_slot2 INT (11), badge_slot3 INT (11)"); - update("CREATE TABLE " + config.getChatFeatureTable() + " (player_uuid VARCHAR (36), badge_slot1 INT (11), badge_slot2 INT (11), badge_slot3 INT (11), PRIMARY KEY(player_uuid))"); - plugin.log(Level.INFO, "FPChat table created!"); - } - if(!tableExists(config.getPermSyncTable())){ - //createTable(config.getPermSyncTable(), "player_uuid VARCHAR (36), badges TEXT"); - update("CREATE TABLE " + config.getPermSyncTable() + " (player_uuid VARCHAR (36), badges TEXT, PRIMARY KEY(player_uuid))"); + Connection connection = null; + try { + connection = hikari.getConnection(); + if(!tableExists(config.getChatFeatureTable(), connection)){ + plugin.log(Level.INFO, "FPChat table not found. Creating new table..."); + update("CREATE TABLE " + config.getChatFeatureTable() + " (player_uuid VARCHAR (36), badge_loadout TEXT, PRIMARY KEY(player_uuid))"); + plugin.log(Level.INFO, "FPChat table created!"); + } + if(!tableExists(config.getPermSyncTable(), connection)){ + update("CREATE TABLE " + config.getPermSyncTable() + " (player_uuid VARCHAR (36), badges TEXT, PRIMARY KEY(player_uuid))"); + } + }catch(SQLException e) { + e.printStackTrace(); + }finally { + try { + connection.close(); + } catch (SQLException e) { + e.printStackTrace(); + } } plugin.log(Level.INFO, "FPChat successfully connected to MySQL!"); plugin.log(Level.INFO, "Badges have been enabled!"); @@ -56,66 +67,15 @@ public class MySQLConnection{ } } - public void connect(){ - - if (host.equalsIgnoreCase("") || host == null) { - plugin.log(Level.SEVERE, "You have not specified a host in the FPChatX config!"); - } else if (user.equalsIgnoreCase("") || user == null) { - plugin.log(Level.SEVERE, "You have not specified a user in the FPChatX config!"); - } else if (password.equalsIgnoreCase("") || password == null) { - plugin.log(Level.SEVERE, "You have not specified a password in the FPChatX config!"); - } else if (database.equalsIgnoreCase("") || database == null) { - plugin.log(Level.SEVERE, "You have not specified a database in the FPChatX config!"); - } else { - login(); - } - } - - public void disconnect(){ - try{ - if (getConnection() != null){ - connection.close(); - } - else{ - plugin.log(Level.SEVERE, "There was an issue with MySQL: FPChatX is not currently connected to a database."); - } - }catch(SQLException e){ - plugin.log(Level.SEVERE, "There was an issue with MySQL: " + e.getMessage()); - e.printStackTrace(); - } - connection = null; - } - - public void reconnect(){ - disconnect(); - connect(); - } - - public void login(){ - try{ - if (getConnection() != null){ - connection.close(); - } - } - catch (Exception e){} - connection = null; - try{ - connection = DriverManager.getConnection("jdbc:mysql://" + host + ":" + port + "/" + database, user, password); - }catch(SQLException e){ - plugin.log(Level.SEVERE, "There was an issue with MySQL: " + e.getMessage()); - e.printStackTrace(); - } - } - - public ResultSet query(String query){ + public ResultSet query(String query, Connection connection){ if (query == null) { return null; } - connect(); ResultSet results = null; try{ - Statement statement = getConnection().createStatement(); + Statement statement = connection.createStatement(); results = statement.executeQuery(query); + }catch(SQLException e){ plugin.log(Level.SEVERE, "There has been an error:" + e.getMessage()); plugin.log(Level.SEVERE,"Failed Query in MySQL using the following query input:"); @@ -129,34 +89,46 @@ public class MySQLConnection{ if (input == null){ return; } - connect(); - try{ - Statement statement = getConnection().createStatement(); - statement.executeUpdate(input); - statement.close(); - }catch(SQLException e){ - plugin.log(Level.SEVERE, "There has been an error:" + e.getMessage()); - plugin.log(Level.SEVERE,"Failed to update MySQL using the following update input:"); - plugin.log(Level.SEVERE, input); - e.printStackTrace(); - } + Statement statement; + Connection connection = null; + try { + connection = hikari.getConnection(); + statement = connection.createStatement(); + statement.executeUpdate(input); + statement.close(); + } catch (SQLException e) { + e.printStackTrace(); + }finally { + try { + connection.close(); + } catch (SQLException e) { + e.printStackTrace(); + } + } + } + + public void asyncUpdate(String input){ + CompletableFuture.runAsync(() -> { + update(input); + }); } - public boolean tableExists(String tablename){ + public boolean tableExists(String tablename, Connection connection){ if (tablename == null) { return false; } try{ - if (getConnection() == null) { + if (connection == null) { return false; } - if (getConnection().getMetaData() == null) { + if (connection.getMetaData() == null) { return false; } - ResultSet results = getConnection().getMetaData().getTables(null, null, tablename, null); + ResultSet results = connection.getMetaData().getTables(null, null, tablename, null); if (results.next()) { return true; } + }catch(SQLException e) { e.printStackTrace(); } @@ -167,67 +139,53 @@ public class MySQLConnection{ if (data != null) { data = "'" + data + "'"; } + Connection connection = null; try{ - ResultSet results = query("SELECT * FROM " + table + " WHERE " + column + "=" + data); + connection = hikari.getConnection(); + ResultSet results = query("SELECT * FROM " + table + " WHERE " + column + "=" + data, connection); while (results.next()) { if (results.getString(column) != null) { return true; } } + }catch(SQLException e) { plugin.log(Level.SEVERE, "MYSQL itemExists error: " + e.getMessage()); e.printStackTrace(); + }finally { + try { + connection.close(); + } catch (SQLException e) { + e.printStackTrace(); + } } return false; } public void createTable(String table, String columns){ - if (!tableExists(table)) { - update("CREATE TABLE " + table + " (" + columns + ")"); - } - } - - public void insertInto(final String columns, final String values, final String table){ - new BukkitRunnable() { - @Override - public void run() { - update("INSERT INTO " + table + " (" + columns + ") VALUES (" + values + ")"); - } - }.runTaskAsynchronously(plugin); - } - - - public void set(final String selected, final Object object, final String column, final String equality, final String data, final String table){ - new BukkitRunnable() { - @Override - public void run() { - Object gobject = object; - String gdata = data; - if (gobject != null) { - gobject = "'" + gobject + "'"; - } - if (gdata != null) { - gdata = "'" + gdata + "'"; - } - update("UPDATE " + table + " SET " + selected + "=" + gobject + " WHERE " + column + equality + gdata + ";"); - } - }.runTaskAsynchronously(plugin); - } - - - public Object get(String selected, String column, String equality, String data, String table){ - if (data != null) { - data = "'" + data + "'"; - } - try{ - ResultSet rs = query("SELECT * FROM " + table + " WHERE " + column + equality + data); - if (rs.next()) { - return rs.getObject(selected); + Connection connection = null; + try { + connection = hikari.getConnection(); + if (!tableExists(table, connection)) { + update("CREATE TABLE " + table + " (" + columns + ")"); } }catch(SQLException e) { - plugin.log(Level.SEVERE, "MySQL get error: " + e.getMessage()); e.printStackTrace(); + }finally { + try { + connection.close(); + } catch (SQLException e) { + e.printStackTrace(); + } } - return null; } + + public Connection getConnection() throws SQLException { + return hikari.getConnection(); + } + + public void disconnect() { + hikari.close(); + } + } diff --git a/src/main/java/com/fpghoti/fpchatx/player/FPlayer.java b/src/main/java/com/fpghoti/fpchatx/player/FPlayer.java index 66f853c..22c16e1 100644 --- a/src/main/java/com/fpghoti/fpchatx/player/FPlayer.java +++ b/src/main/java/com/fpghoti/fpchatx/player/FPlayer.java @@ -2,7 +2,6 @@ package com.fpghoti.fpchatx.player; import java.io.IOException; import java.util.ArrayList; -import java.util.Collections; import java.util.HashMap; import java.util.HashSet; import java.util.UUID; @@ -16,9 +15,7 @@ import org.bukkit.entity.Player; import org.bukkit.event.player.AsyncPlayerChatEvent; import com.fpghoti.fpchatx.FPChat; -import com.fpghoti.fpchatx.badge.Badge; -import com.fpghoti.fpchatx.badge.BadgeList; -import com.fpghoti.fpchatx.badge.Sync; +import com.fpghoti.fpchatx.badge.BadgeData; import com.fpghoti.fpchatx.chat.ChatChannel; import com.fpghoti.fpchatx.chat.ChatFilter; import com.fpghoti.fpchatx.chat.PrepareChat; @@ -118,22 +115,19 @@ public class FPlayer { private String primaryChannel; private String primaryTempChannel; private int shoutCooldown; - private Integer[] badges; private UUID lastMsg; private boolean spy; private boolean shoutVisible; private boolean hushed; - private ArrayList synced; private boolean toShout; private boolean toTalk; private ChatChannel talkChannel; - private ArrayList giveBadgeQueue; + private BadgeData badgeData; private FPlayer(OfflinePlayer p) { this.toShout = false; this.toTalk = false; this.talkChannel = null; - this.synced = new ArrayList(); this.offlinePlayer = p; this.name = p.getName(); this.uuid = p.getUniqueId(); @@ -144,7 +138,6 @@ public class FPlayer { this.spy = pfile.isSpy(); this.shoutVisible = pfile.shoutVisible(); this.hushed = pfile.isHushed(); - this.giveBadgeQueue = new ArrayList(); String rawignore = pfile.getIgnore(); if(!rawignore.equals("")) { for(String s : rawignore.split(",")) { @@ -173,12 +166,7 @@ public class FPlayer { } } if(FPChat.getPlugin().getMainConfig().mySQLEnabled()) { - Util.connect(); - Sync.update(this); - this.badges = getSQLBadges(); - }else { - Integer[] empt = {0,0,0}; - this.badges = empt; + this.badgeData = new BadgeData(this); } } @@ -189,128 +177,7 @@ public class FPlayer { public String getName() { return this.name; } - - public void updateBadges(int slot, int id) { - if(!Badge.getList().get(id).isEnabled()) { - badges[slot-1] = 0; - return; - } - badges[slot-1] = id; - } - - public void clearUnownedBadges() { - if(!hasBadge(badges[0]) || !Badge.getList().get(badges[0]).isEnabled()) { - setBadge(1, 0); - updateBadges(1,0); - } - if(!hasBadge(badges[1])|| !Badge.getList().get(badges[1]).isEnabled()) { - setBadge(2, 0); - updateBadges(2,0); - } - if(!hasBadge(badges[2])|| !Badge.getList().get(badges[2]).isEnabled()) { - setBadge(3, 0); - updateBadges(3,0); - } - } - - public Integer[] getSQLBadges(){ - UUID id = uuid; - String uuid = id.toString(); - Integer badge1 = 0, badge2 = 0, badge3 = 0; - Util.connect(); - if(!FPChat.getPlugin().getMySQLConnection().itemExists("player_uuid", uuid, FPChat.getPlugin().getMainConfig().getChatFeatureTable())){ - createPlayer(); - } - badge1 = (Integer) FPChat.getPlugin().getMySQLConnection().get("badge_slot1", "player_uuid", "=", uuid, FPChat.getPlugin().getMainConfig().getChatFeatureTable()); - badge2 = (Integer)FPChat.getPlugin().getMySQLConnection().get("badge_slot2", "player_uuid", "=", uuid, FPChat.getPlugin().getMainConfig().getChatFeatureTable()); - badge3 = (Integer)FPChat.getPlugin().getMySQLConnection().get("badge_slot3", "player_uuid", "=", uuid, FPChat.getPlugin().getMainConfig().getChatFeatureTable()); - Integer[] badges = {badge1, badge2, badge3}; - return badges; - } - - public Boolean hasBadge(int id){ - if(id == 0) { - return true; - } - - return hasPermission("fpchat.badge." + Badge.getList().get(id).getPerm()) || isSynced(id); - } - - public void setBadge(int slot, int badgeId){ - if(!Badge.getList().get(badgeId).isEnabled() && badgeId != 0) { - return; - } - if(slot > 3){ - slot = 3; - }else if(slot < 1){ - slot = 1; - } - Util.connect(); - if(!FPChat.getPlugin().getMySQLConnection().itemExists("player_uuid", uuid.toString(), FPChat.getPlugin().getMainConfig().getChatFeatureTable())){ - createPlayer(); - } - FPChat.getPlugin().getMySQLConnection().set("badge_slot" + String.valueOf(slot), badgeId, "player_uuid", "=", uuid.toString(), FPChat.getPlugin().getMainConfig().getChatFeatureTable()); - getSQLBadges(); - } - - public void createPlayer(){ - Util.connect(); - if(!FPChat.getPlugin().getMySQLConnection().itemExists("player_uuid", uuid.toString(), FPChat.getPlugin().getMainConfig().getChatFeatureTable())){ - FPChat.getPlugin().getMySQLConnection().insertInto("player_uuid, badge_slot1, badge_slot2, badge_slot3", " '" + uuid + "', '0', '0', '0' ", FPChat.getPlugin().getMainConfig().getChatFeatureTable()); - } - } - - public Boolean canUseSlot(int slotid){ - if(slotid == 1){ - return hasPermission("fpchat.slot1") || hasSlotBadge(1); - }else if(slotid == 2){ - return hasPermission("fpchat.slot2") || hasSlotBadge(2); - }else if(slotid == 3){ - return hasPermission("fpchat.slot3") || hasSlotBadge(3); - } - return false; - } - - private boolean hasSlotBadge(int slot) { - for(Badge b : Badge.getList().getSlotUnlockBadges(slot)) { - if(hasBadge(b.getId())) { - return true; - } - } - return false; - } - - public void addSyncedBadge(Integer id) { - if(!synced.contains(id)) { - this.synced.add(id); - } - } - - public void removeSyncedBadge(Integer id) { - this.synced.remove(id); - } - - public boolean isSynced(Integer id) { - return this.synced.contains(id); - } - - public ArrayList syncedList(){ - return this.synced; - } - - public BadgeList getSyncedBadgeList() { - BadgeList list = new BadgeList(); - ArrayList sc = new ArrayList(synced); - Collections.sort(sc); - for(Integer i : sc) { - Badge badge = Badge.getList().get(i); - if(badge.isEnabled()) { - list.add(badge); - } - } - return list; - } - + public int getShoutCooldown() { return this.shoutCooldown; } @@ -358,6 +225,10 @@ public class FPlayer { public void hideShout() { this.shoutVisible = false; } + + public BadgeData getBadgeData() { + return this.badgeData; + } public boolean setPrefix(String prefix) { if(isOnline() && getPlayer() != null) { @@ -388,13 +259,6 @@ public class FPlayer { this.hushed = false; } - public Integer[] getBadges() { - if(badges[0] == null || badges[1] == null || badges[2] == null) { - badges = getSQLBadges(); - } - return this.badges; - } - public FPlayer getLastMessage() { if(this.lastMsg == null) { return null; @@ -741,23 +605,6 @@ public class FPlayer { return false; } - public void queueBadgeAdd(int id) { - if(!Badge.getList().get(id).isEnabled()) { - return; - } - if(!hasBadge( id) && !giveBadgeQueue.contains(id)) { - giveBadgeQueue.add(id); - } - } - - public void unqueueBadge(Integer id) { - giveBadgeQueue.remove(id); - } - - public ArrayList getBadgeQueue(){ - return this.giveBadgeQueue; - } - public void cleanup() { String ignorelist = ""; for(UUID id : ignored) { diff --git a/src/main/java/com/fpghoti/fpchatx/util/Util.java b/src/main/java/com/fpghoti/fpchatx/util/Util.java index 2b8e354..d127f7e 100644 --- a/src/main/java/com/fpghoti/fpchatx/util/Util.java +++ b/src/main/java/com/fpghoti/fpchatx/util/Util.java @@ -5,16 +5,8 @@ import java.util.UUID; import org.bukkit.Bukkit; import org.bukkit.entity.Player; -import com.fpghoti.fpchatx.FPChat; - public class Util { - public static void connect(){ - if(FPChat.getPlugin().getMySQLConnection().getConnection() == null){ - FPChat.getPlugin().getMySQLConnection().reconnect(); - } - } - public Player playerGet(String uuid){ UUID id = UUID.fromString(uuid); Player p = Bukkit.getPlayer(id);