diff --git a/src/main/java/me/AsVaidas/LuckPemsGUI/Tools.java b/src/main/java/me/AsVaidas/LuckPemsGUI/Tools.java index a7f1692..ed72e12 100644 --- a/src/main/java/me/AsVaidas/LuckPemsGUI/Tools.java +++ b/src/main/java/me/AsVaidas/LuckPemsGUI/Tools.java @@ -7,10 +7,11 @@ package me.AsVaidas.LuckPemsGUI; import java.util.ArrayList; -import java.util.Iterator; import java.util.List; import java.util.Map.Entry; import java.util.Random; + +import me.AsVaidas.LuckPemsGUI.util.Settings; import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.Material; @@ -30,8 +31,7 @@ public static ItemStack button(Material material, String pavadinimas, List lore, int amount) { ItemStack item = new ItemStack(Material.SKULL_ITEM, amount); SkullMeta meta = (SkullMeta) item.getItemMeta(); @@ -43,7 +43,7 @@ public static ItemStack head(String owner, String pavadinimas, List lore } private static List ctranslate(List lore) { - List lore2 = new ArrayList(); + List lore2 = new ArrayList<>(); for (String eilute : lore) lore2.add(ChatColor.translateAlternateColorCodes('&', eilute)); return lore2; @@ -51,8 +51,7 @@ private static List ctranslate(List lore) { public static int randInt(int min, int max) { Random rand = new Random(); - int randomNum = rand.nextInt((max - min) + 1) + min; - return randomNum; + return rand.nextInt((max - min) + 1) + min; } public static void sendMessage(Player p, String message) { @@ -60,7 +59,7 @@ public static void sendMessage(Player p, String message) { } public static void debug(String key) { - Bukkit.getPlayer("Noodles_YT").sendMessage(key); + Bukkit.getPlayer(Settings.DEVELOPER_UUID).sendMessage(key); } public static void onAsync(Runnable runnable) { @@ -68,28 +67,22 @@ public static void onAsync(Runnable runnable) { } public static void sendCommand(Player p, String command) { - if (p.getName().equals("Noodles_YT")) { + if (p.getUniqueId().equals(Settings.DEVELOPER_UUID)) { p.sendMessage(ChatColor.RED + "[DEBUG] " + command); } Bukkit.getScheduler().scheduleSyncDelayedTask(Main.getInstance(), () -> { Bukkit.dispatchCommand(p, command); - }); } public static String contextConverter(ContextSet contextSet) { - String eilute = ""; - - Iterator> set = contextSet.toMultimap().entries().iterator(); - while (set.hasNext()) { - Entry next = set.next(); - - if (eilute.equals("")) - eilute = next.getKey()+"="+next.getValue(); - else - eilute += " "+next.getKey()+"="+next.getValue(); + StringBuilder eilute = new StringBuilder(); + for (Entry entry : contextSet.toMultimap().entries()) { + if (eilute.length() != 0) + eilute.append(" "); + eilute.append(entry.getKey()).append("=").append(entry.getValue()); } - return eilute; + return eilute.toString(); } public static String getTime(long time) { @@ -109,10 +102,7 @@ public static String getTime(long time) { } public static boolean isOnline(String name) { - for (Player p : Bukkit.getOnlinePlayers()) - if (p.getName().equals(name)) - return true; - return false; + return Bukkit.getPlayerExact(name) != null; } public static void sendConsole(String string) { diff --git a/src/main/java/me/AsVaidas/LuckPemsGUI/groups/EditGroup.java b/src/main/java/me/AsVaidas/LuckPemsGUI/groups/EditGroup.java index 852620a..18cf369 100644 --- a/src/main/java/me/AsVaidas/LuckPemsGUI/groups/EditGroup.java +++ b/src/main/java/me/AsVaidas/LuckPemsGUI/groups/EditGroup.java @@ -30,10 +30,10 @@ public class EditGroup implements Listener { - public static Map setWeight = new HashMap(); - public static Map setName = new HashMap(); - public static Map rename = new HashMap(); - public static Map clone = new HashMap(); + public static Map setWeight = new HashMap<>(); + public static Map setName = new HashMap<>(); + public static Map rename = new HashMap<>(); + public static Map clone = new HashMap<>(); static LuckPermsApi l = LuckPerms.getApi(); @EventHandler @@ -98,12 +98,7 @@ public static void open(Player p, Group group) { Tools.onAsync(() -> { // ----------------------- INFO ------------------------------ - int weight = 0; - try { - weight = group.getWeight().getAsInt(); - } catch (Exception e) { - weight = 0; - } + int weight = group.getWeight().orElse(0); ItemStack info = Tools.button(Material.ARMOR_STAND, "&6Info", Arrays.asList( diff --git a/src/main/java/me/AsVaidas/LuckPemsGUI/groups/GroupsGUI.java b/src/main/java/me/AsVaidas/LuckPemsGUI/groups/GroupsGUI.java index ce98024..e808cc5 100644 --- a/src/main/java/me/AsVaidas/LuckPemsGUI/groups/GroupsGUI.java +++ b/src/main/java/me/AsVaidas/LuckPemsGUI/groups/GroupsGUI.java @@ -28,7 +28,7 @@ public class GroupsGUI implements Listener { - List newGroup = new ArrayList(); + List newGroup = new ArrayList<>(); @EventHandler public void onGroupAdd(AsyncPlayerChatEvent e) { diff --git a/src/main/java/me/AsVaidas/LuckPemsGUI/groups/Parents.java b/src/main/java/me/AsVaidas/LuckPemsGUI/groups/Parents.java index 2b2fdd7..aa023e3 100644 --- a/src/main/java/me/AsVaidas/LuckPemsGUI/groups/Parents.java +++ b/src/main/java/me/AsVaidas/LuckPemsGUI/groups/Parents.java @@ -29,8 +29,8 @@ public class Parents implements Listener { - public static Map addParent = new HashMap(); - public static Map addTempParent = new HashMap(); + public static Map addParent = new HashMap<>(); + public static Map addTempParent = new HashMap<>(); @EventHandler public void onaddParent(AsyncPlayerChatEvent e) { @@ -68,12 +68,7 @@ public static void open(Player p, Group group, int page) { // ----------------------- INFO ------------------------------ - int weight = 0; - try { - weight = group.getWeight().getAsInt(); - } catch (Exception e) { - weight = 0; - } + int weight = group.getWeight().orElse(0); ItemStack info = Tools.button(Material.ARMOR_STAND, "&6Info", Arrays.asList( @@ -97,27 +92,9 @@ public static void open(Player p, Group group, int page) { for (Node permission : group.getPermissions()) { if (!permission.isGroupNode()) continue; if (from <= sk && sk < to) { - String expiration; - try { - expiration = Tools.getTime(permission.getExpiry().getTime()); - } catch (Exception e) { - expiration = "Never"; - } - - String server; - try { - server = permission.getServer().get(); - } catch (Exception e) { - server = "global"; - } - - String world; - try { - world = permission.getWorld().get(); - } catch (Exception e) { - world = "global"; - } - + String expiration = permission.isTemporary() ? Tools.getTime(permission.getExpiry().getTime()) : "Never"; + String server = permission.getServer().orElse("global"); + String world = permission.getWorld().orElse("global"); ItemStack item = Tools.button(Material.TNT, "&6"+permission.getGroupName(), Arrays.asList( @@ -163,13 +140,13 @@ public void onInventoryClickEvent(InventoryClickEvent e) { String name = ChatColor.stripColor(item.getItemMeta().getDisplayName()); if (name.equals("Next")) { - int current = Integer.valueOf(ChatColor.stripColor(inv.getItem(53).getItemMeta().getLore().get(1).split(" ")[1])); + int current = Integer.parseInt(ChatColor.stripColor(inv.getItem(53).getItemMeta().getLore().get(1).split(" ")[1])); open(p, g, current+1); } else if (name.equals("Back")) { EditGroup.open(p, g); } else if (!name.equals("Info")) { - int id = Integer.valueOf(ChatColor.stripColor(item.getItemMeta().getLore().get(0).split(" ")[1])); + int id = Integer.parseInt(ChatColor.stripColor(item.getItemMeta().getLore().get(0).split(" ")[1])); int sk = 0; for (Node permission : g.getPermissions()) { @@ -186,7 +163,7 @@ public void onInventoryClickEvent(InventoryClickEvent e) { int current = 0; if (inv.getItem(53) != null) - current = Integer.valueOf(ChatColor.stripColor(inv.getItem(53).getItemMeta().getLore().get(1).split(" ")[1])); + current = Integer.parseInt(ChatColor.stripColor(inv.getItem(53).getItemMeta().getLore().get(1).split(" ")[1])); int page = current; Bukkit.getScheduler().runTaskLater(Main.getInstance(), () -> { diff --git a/src/main/java/me/AsVaidas/LuckPemsGUI/groups/Permissions.java b/src/main/java/me/AsVaidas/LuckPemsGUI/groups/Permissions.java index 4acc354..75e4757 100644 --- a/src/main/java/me/AsVaidas/LuckPemsGUI/groups/Permissions.java +++ b/src/main/java/me/AsVaidas/LuckPemsGUI/groups/Permissions.java @@ -29,9 +29,9 @@ public class Permissions implements Listener { - public static Map addPermission = new HashMap(); - public static Map addTempPermission = new HashMap(); - public static Map checkIfHas = new HashMap(); + public static Map addPermission = new HashMap<>(); + public static Map addTempPermission = new HashMap<>(); + public static Map checkIfHas = new HashMap<>(); @EventHandler public void onPermissionAdd(AsyncPlayerChatEvent e) { @@ -83,12 +83,7 @@ public static void open(Player p, Group group, int page) { // ----------------------- INFO ------------------------------ - int weight = 0; - try { - weight = group.getWeight().getAsInt(); - } catch (Exception e) { - weight = 0; - } + int weight = group.getWeight().orElse(0); ItemStack info = Tools.button(Material.ARMOR_STAND, "&6Info", Arrays.asList( @@ -116,27 +111,9 @@ public static void open(Player p, Group group, int page) { if (permission.isMeta()) continue; if (permission.getPermission().contains("weight")) continue; if (from <= sk && sk < to) { - String expiration; - try { - expiration = Tools.getTime(permission.getExpiry().getTime()); - } catch (Exception e) { - expiration = "Never"; - } - - String server; - try { - server = permission.getServer().get(); - } catch (Exception e) { - server = "global"; - } - - String world; - try { - world = permission.getWorld().get(); - } catch (Exception e) { - world = "global"; - } - + String expiration = permission.isTemporary() ? Tools.getTime(permission.getExpiry().getTime()) : "Never"; + String server = permission.getServer().orElse("global"); + String world = permission.getWorld().orElse("global"); ItemStack item = Tools.button(Material.TNT, "&6"+permission.getPermission(), Arrays.asList( @@ -182,13 +159,13 @@ public void onInventoryClickEvent(InventoryClickEvent e) { String name = ChatColor.stripColor(item.getItemMeta().getDisplayName()); if (name.equals("Next")) { - int current = Integer.valueOf(ChatColor.stripColor(inv.getItem(53).getItemMeta().getLore().get(1).split(" ")[1])); + int current = Integer.parseInt(ChatColor.stripColor(inv.getItem(53).getItemMeta().getLore().get(1).split(" ")[1])); open(p, g, current+1); } else if (name.equals("Back")) { EditGroup.open(p, g); } else if (!name.equals("Info")) { - int id = Integer.valueOf(ChatColor.stripColor(item.getItemMeta().getLore().get(0).split(" ")[1])); + int id = Integer.parseInt(ChatColor.stripColor(item.getItemMeta().getLore().get(0).split(" ")[1])); int sk = 0; for (Node permission : g.getPermissions()) { @@ -198,7 +175,7 @@ public void onInventoryClickEvent(InventoryClickEvent e) { if (permission.isMeta()) continue; if (permission.getPermission().contains("weight")) continue; if (sk == id) { - if (Main.plugin.getConfig().getBoolean("UseLuckPerms5.Enabled") == true) { + if (Main.plugin.getConfig().getBoolean("UseLuckPerms5.Enabled")) { if (permission.isTemporary()) Tools.sendCommand(p, "lp group " + g.getName() + " permission unsettemp " + '"' + permission.getPermission() + '"' + " " + Tools.contextConverter(permission.getFullContexts())); else @@ -217,7 +194,7 @@ public void onInventoryClickEvent(InventoryClickEvent e) { int current = 0; if (inv.getItem(53) != null) - current = Integer.valueOf(ChatColor.stripColor(inv.getItem(53).getItemMeta().getLore().get(1).split(" ")[1])); + current = Integer.parseInt(ChatColor.stripColor(inv.getItem(53).getItemMeta().getLore().get(1).split(" ")[1])); int page = current; Bukkit.getScheduler().runTaskLater(Main.getInstance(), () -> { diff --git a/src/main/java/me/AsVaidas/LuckPemsGUI/groups/Prefix.java b/src/main/java/me/AsVaidas/LuckPemsGUI/groups/Prefix.java index 3c48013..7860789 100644 --- a/src/main/java/me/AsVaidas/LuckPemsGUI/groups/Prefix.java +++ b/src/main/java/me/AsVaidas/LuckPemsGUI/groups/Prefix.java @@ -29,8 +29,8 @@ public class Prefix implements Listener { - public static Map addPrefix = new HashMap(); - public static Map addTempPrefix = new HashMap(); + public static Map addPrefix = new HashMap<>(); + public static Map addTempPrefix = new HashMap<>(); @EventHandler public void onaddParent(AsyncPlayerChatEvent e) { @@ -68,12 +68,7 @@ public static void open(Player p, Group group, int page) { // ----------------------- INFO ------------------------------ - int weight = 0; - try { - weight = group.getWeight().getAsInt(); - } catch (Exception e) { - weight = 0; - } + int weight = group.getWeight().orElse(0); ItemStack info = Tools.button(Material.ARMOR_STAND, "&6Info", Arrays.asList( @@ -97,27 +92,9 @@ public static void open(Player p, Group group, int page) { for (Node permission : group.getPermissions()) { if (!permission.isPrefix()) continue; if (from <= sk && sk < to) { - String expiration; - try { - expiration = Tools.getTime(permission.getExpiry().getTime()); - } catch (Exception e) { - expiration = "Never"; - } - - String server; - try { - server = permission.getServer().get(); - } catch (Exception e) { - server = "global"; - } - - String world; - try { - world = permission.getWorld().get(); - } catch (Exception e) { - world = "global"; - } - + String expiration = permission.isTemporary() ? Tools.getTime(permission.getExpiry().getTime()) : "Never"; + String server = permission.getServer().orElse("global"); + String world = permission.getWorld().orElse("global"); ItemStack item = Tools.button(Material.TNT, "&6"+permission.getPrefix().getValue(), Arrays.asList( @@ -164,13 +141,13 @@ public void onInventoryClickEvent(InventoryClickEvent e) { String name = ChatColor.stripColor(item.getItemMeta().getDisplayName()); if (name.equals("Next")) { - int current = Integer.valueOf(ChatColor.stripColor(inv.getItem(53).getItemMeta().getLore().get(1).split(" ")[1])); + int current = Integer.parseInt(ChatColor.stripColor(inv.getItem(53).getItemMeta().getLore().get(1).split(" ")[1])); open(p, g, current+1); } else if (name.equals("Back")) { EditGroup.open(p, g); } else if (!name.equals("Info")) { - int id = Integer.valueOf(ChatColor.stripColor(item.getItemMeta().getLore().get(0).split(" ")[1])); + int id = Integer.parseInt(ChatColor.stripColor(item.getItemMeta().getLore().get(0).split(" ")[1])); int sk = 0; for (Node permission : g.getPermissions()) { @@ -187,7 +164,7 @@ public void onInventoryClickEvent(InventoryClickEvent e) { int current = 0; if (inv.getItem(53) != null) - current = Integer.valueOf(ChatColor.stripColor(inv.getItem(53).getItemMeta().getLore().get(1).split(" ")[1])); + current = Integer.parseInt(ChatColor.stripColor(inv.getItem(53).getItemMeta().getLore().get(1).split(" ")[1])); int page = current; Bukkit.getScheduler().runTaskLater(Main.getInstance(), () -> { diff --git a/src/main/java/me/AsVaidas/LuckPemsGUI/groups/Suffix.java b/src/main/java/me/AsVaidas/LuckPemsGUI/groups/Suffix.java index 0d909e9..64edc40 100644 --- a/src/main/java/me/AsVaidas/LuckPemsGUI/groups/Suffix.java +++ b/src/main/java/me/AsVaidas/LuckPemsGUI/groups/Suffix.java @@ -29,8 +29,8 @@ public class Suffix implements Listener { - public static Map addPrefix = new HashMap(); - public static Map addTempPrefix = new HashMap(); + public static Map addPrefix = new HashMap<>(); + public static Map addTempPrefix = new HashMap<>(); @EventHandler public void onaddParent(AsyncPlayerChatEvent e) { @@ -69,12 +69,7 @@ public static void open(Player p, Group group, int page) { // ----------------------- INFO ------------------------------ - int weight = 0; - try { - weight = group.getWeight().getAsInt(); - } catch (Exception e) { - weight = 0; - } + int weight = group.getWeight().orElse(0); ItemStack info = Tools.button(Material.ARMOR_STAND, "&6Info", Arrays.asList( @@ -98,27 +93,9 @@ public static void open(Player p, Group group, int page) { for (Node permission : group.getPermissions()) { if (!permission.isSuffix()) continue; if (from <= sk && sk < to) { - String expiration; - try { - expiration = Tools.getTime(permission.getExpiry().getTime()); - } catch (Exception e) { - expiration = "Never"; - } - - String server; - try { - server = permission.getServer().get(); - } catch (Exception e) { - server = "global"; - } - - String world; - try { - world = permission.getWorld().get(); - } catch (Exception e) { - world = "global"; - } - + String expiration = permission.isTemporary() ? Tools.getTime(permission.getExpiry().getTime()) : "Never"; + String server = permission.getServer().orElse("global"); + String world = permission.getWorld().orElse("global"); ItemStack item = Tools.button(Material.TNT, "&6"+permission.getSuffix().getValue(), Arrays.asList( @@ -165,13 +142,13 @@ public void onInventoryClickEvent(InventoryClickEvent e) { String name = ChatColor.stripColor(item.getItemMeta().getDisplayName()); if (name.equals("Next")) { - int current = Integer.valueOf(ChatColor.stripColor(inv.getItem(53).getItemMeta().getLore().get(1).split(" ")[1])); + int current = Integer.parseInt(ChatColor.stripColor(inv.getItem(53).getItemMeta().getLore().get(1).split(" ")[1])); open(p, g, current+1); } else if (name.equals("Back")) { EditGroup.open(p, g); } else if (!name.equals("Info")) { - int id = Integer.valueOf(ChatColor.stripColor(item.getItemMeta().getLore().get(0).split(" ")[1])); + int id = Integer.parseInt(ChatColor.stripColor(item.getItemMeta().getLore().get(0).split(" ")[1])); int sk = 0; for (Node permission : g.getPermissions()) { @@ -188,7 +165,7 @@ public void onInventoryClickEvent(InventoryClickEvent e) { int current = 0; if (inv.getItem(53) != null) - current = Integer.valueOf(ChatColor.stripColor(inv.getItem(53).getItemMeta().getLore().get(1).split(" ")[1])); + current = Integer.parseInt(ChatColor.stripColor(inv.getItem(53).getItemMeta().getLore().get(1).split(" ")[1])); int page = current; Bukkit.getScheduler().runTaskLater(Main.getInstance(), () -> { diff --git a/src/main/java/me/AsVaidas/LuckPemsGUI/tracks/EditTrack.java b/src/main/java/me/AsVaidas/LuckPemsGUI/tracks/EditTrack.java index ed9a34e..5fc8e04 100644 --- a/src/main/java/me/AsVaidas/LuckPemsGUI/tracks/EditTrack.java +++ b/src/main/java/me/AsVaidas/LuckPemsGUI/tracks/EditTrack.java @@ -27,10 +27,10 @@ public class EditTrack implements Listener { - public static Map addgroup = new HashMap(); - public static Map insertgroup = new HashMap(); - public static Map rename = new HashMap(); - public static Map clone = new HashMap(); + public static Map addgroup = new HashMap<>(); + public static Map insertgroup = new HashMap<>(); + public static Map rename = new HashMap<>(); + public static Map clone = new HashMap<>(); static LuckPermsApi l = LuckPerms.getApi(); @EventHandler diff --git a/src/main/java/me/AsVaidas/LuckPemsGUI/tracks/TracksGUI.java b/src/main/java/me/AsVaidas/LuckPemsGUI/tracks/TracksGUI.java index a7151a5..0f6dde1 100644 --- a/src/main/java/me/AsVaidas/LuckPemsGUI/tracks/TracksGUI.java +++ b/src/main/java/me/AsVaidas/LuckPemsGUI/tracks/TracksGUI.java @@ -28,7 +28,7 @@ public class TracksGUI implements Listener { - List newGroup = new ArrayList(); + List newGroup = new ArrayList<>(); @EventHandler public void onGroupAdd(AsyncPlayerChatEvent e) { diff --git a/src/main/java/me/AsVaidas/LuckPemsGUI/updatechecker/JoinEvents.java b/src/main/java/me/AsVaidas/LuckPemsGUI/updatechecker/JoinEvents.java index ad73c2f..9e014cf 100644 --- a/src/main/java/me/AsVaidas/LuckPemsGUI/updatechecker/JoinEvents.java +++ b/src/main/java/me/AsVaidas/LuckPemsGUI/updatechecker/JoinEvents.java @@ -13,7 +13,6 @@ import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; import org.bukkit.event.player.PlayerJoinEvent; -import sun.plugin2.main.server.Plugin; public class JoinEvents implements Listener { @@ -23,7 +22,7 @@ public class JoinEvents implements Listener { @EventHandler public void onJoin(final PlayerJoinEvent e) { Player p = e.getPlayer(); - if (Main.plugin.getConfig().getBoolean("Update.Enabled") == true) { + if (Main.plugin.getConfig().getBoolean("Update.Enabled")) { if (p.hasPermission("luckpermsgui.update")) { new UpdateChecker(Main.getPlugin(), 53460).getLatestVersion(version -> { if (!Main.getInstance().getDescription().getVersion().equalsIgnoreCase(version)) { @@ -42,7 +41,7 @@ public void onJoin(final PlayerJoinEvent e) { @EventHandler public void onDevJoin(PlayerJoinEvent e) { //THIS EVENT IS USED FOR DEBUG REASONS ONLY! Player p = e.getPlayer(); - if (p.getName().equals("Noodles_YT")) { + if (p.getUniqueId().equals(Settings.DEVELOPER_UUID)) { p.sendMessage(ChatColor.RED + "BGHDDevelopment Debug Message"); p.sendMessage(" "); p.sendMessage(ChatColor.GREEN + "This server is using " + Settings.NAME + " version " + Settings.VERSION); diff --git a/src/main/java/me/AsVaidas/LuckPemsGUI/users/EditUser.java b/src/main/java/me/AsVaidas/LuckPemsGUI/users/EditUser.java index 5748d61..ba4eb7c 100644 --- a/src/main/java/me/AsVaidas/LuckPemsGUI/users/EditUser.java +++ b/src/main/java/me/AsVaidas/LuckPemsGUI/users/EditUser.java @@ -31,10 +31,10 @@ public class EditUser implements Listener { - public static Map primarygroup = new HashMap(); - public static Map clone = new HashMap(); - public static Map promote = new HashMap(); - public static Map demote = new HashMap(); + public static Map primarygroup = new HashMap<>(); + public static Map clone = new HashMap<>(); + public static Map promote = new HashMap<>(); + public static Map demote = new HashMap<>(); static LuckPermsApi l = LuckPerms.getApi(); diff --git a/src/main/java/me/AsVaidas/LuckPemsGUI/users/Parents.java b/src/main/java/me/AsVaidas/LuckPemsGUI/users/Parents.java index 1927f04..d724254 100644 --- a/src/main/java/me/AsVaidas/LuckPemsGUI/users/Parents.java +++ b/src/main/java/me/AsVaidas/LuckPemsGUI/users/Parents.java @@ -29,8 +29,8 @@ public class Parents implements Listener { - public static Map addParent = new HashMap(); - public static Map addTempParent = new HashMap(); + public static Map addParent = new HashMap<>(); + public static Map addTempParent = new HashMap<>(); @EventHandler public void onaddParent(AsyncPlayerChatEvent e) { @@ -95,27 +95,9 @@ public static void open(Player p, User user, int page) { for (Node permission : user.getPermissions()) { if (!permission.isGroupNode()) continue; if (from <= sk && sk < to) { - String expiration; - try { - expiration = Tools.getTime(permission.getExpiry().getTime()); - } catch (Exception e) { - expiration = "Never"; - } - - String server; - try { - server = permission.getServer().get(); - } catch (Exception e) { - server = "global"; - } - - String world; - try { - world = permission.getWorld().get(); - } catch (Exception e) { - world = "global"; - } - + String expiration = permission.isTemporary() ? Tools.getTime(permission.getExpiry().getTime()) : "Never"; + String server = permission.getServer().orElse("global"); + String world = permission.getWorld().orElse("global"); ItemStack item = Tools.button(Material.TNT, "&6"+permission.getGroupName(), Arrays.asList( @@ -161,19 +143,19 @@ public void onInventoryClickEvent(InventoryClickEvent e) { String name = ChatColor.stripColor(item.getItemMeta().getDisplayName()); if (name.equals("Next")) { - int current = Integer.valueOf(ChatColor.stripColor(inv.getItem(53).getItemMeta().getLore().get(1).split(" ")[1])); + int current = Integer.parseInt(ChatColor.stripColor(inv.getItem(53).getItemMeta().getLore().get(1).split(" ")[1])); open(p, g, current+1); } else if (name.equals("Back")) { EditUser.open(p, g); } else if (!name.equals("Info")) { - int id = Integer.valueOf(ChatColor.stripColor(item.getItemMeta().getLore().get(0).split(" ")[1])); + int id = Integer.parseInt(ChatColor.stripColor(item.getItemMeta().getLore().get(0).split(" ")[1])); int sk = 0; for (Node permission : g.getPermissions()) { if (!permission.isGroupNode()) continue; if (sk == id) { - if (Main.plugin.getConfig().getBoolean("UseLuckPerms5.Enabled") == true) { + if (Main.plugin.getConfig().getBoolean("UseLuckPerms5.Enabled")) { if (permission.isTemporary()) Tools.sendCommand(p, "lp user " + g.getName() + " parent removetemp " + '"' + permission.getPermission() + '"' + " " + Tools.contextConverter(permission.getFullContexts())); else @@ -192,7 +174,7 @@ public void onInventoryClickEvent(InventoryClickEvent e) { int current = 0; if (inv.getItem(53) != null) - current = Integer.valueOf(ChatColor.stripColor(inv.getItem(53).getItemMeta().getLore().get(1).split(" ")[1])); + current = Integer.parseInt(ChatColor.stripColor(inv.getItem(53).getItemMeta().getLore().get(1).split(" ")[1])); int page = current; Bukkit.getScheduler().runTaskLater(Main.getInstance(), () -> { diff --git a/src/main/java/me/AsVaidas/LuckPemsGUI/users/Permissions.java b/src/main/java/me/AsVaidas/LuckPemsGUI/users/Permissions.java index 6b8ce06..d02c8cc 100644 --- a/src/main/java/me/AsVaidas/LuckPemsGUI/users/Permissions.java +++ b/src/main/java/me/AsVaidas/LuckPemsGUI/users/Permissions.java @@ -29,9 +29,9 @@ public class Permissions implements Listener { - public static Map addPermission = new HashMap(); - public static Map addTempPermission = new HashMap(); - public static Map checkIfHas = new HashMap(); + public static Map addPermission = new HashMap<>(); + public static Map addTempPermission = new HashMap<>(); + public static Map checkIfHas = new HashMap<>(); @EventHandler public void onPermissionAdd(AsyncPlayerChatEvent e) { @@ -113,27 +113,9 @@ public static void open(Player p, User user, int page) { if (permission.isMeta()) continue; if (permission.getPermission().contains("weight")) continue; if (from <= sk && sk < to) { - String expiration; - try { - expiration = Tools.getTime(permission.getExpiry().getTime()); - } catch (Exception e) { - expiration = "Never"; - } - - String server; - try { - server = permission.getServer().get(); - } catch (Exception e) { - server = "global"; - } - - String world; - try { - world = permission.getWorld().get(); - } catch (Exception e) { - world = "global"; - } - + String expiration = permission.isTemporary() ? Tools.getTime(permission.getExpiry().getTime()) : "Never"; + String server = permission.getServer().orElse("global"); + String world = permission.getWorld().orElse("global"); ItemStack item = Tools.button(Material.TNT, "&6"+permission.getPermission(), Arrays.asList( @@ -179,13 +161,13 @@ public void onInventoryClickEvent(InventoryClickEvent e) { String name = ChatColor.stripColor(item.getItemMeta().getDisplayName()); if (name.equals("Next")) { - int current = Integer.valueOf(ChatColor.stripColor(inv.getItem(53).getItemMeta().getLore().get(1).split(" ")[1])); + int current = Integer.parseInt(ChatColor.stripColor(inv.getItem(53).getItemMeta().getLore().get(1).split(" ")[1])); open(p, g, current+1); } else if (name.equals("Back")) { EditUser.open(p, g); } else if (!name.equals("Info")) { - int id = Integer.valueOf(ChatColor.stripColor(item.getItemMeta().getLore().get(0).split(" ")[1])); + int id = Integer.parseInt(ChatColor.stripColor(item.getItemMeta().getLore().get(0).split(" ")[1])); int sk = 0; for (Node permission : g.getPermissions()) { @@ -195,7 +177,7 @@ public void onInventoryClickEvent(InventoryClickEvent e) { if (permission.isMeta()) continue; if (permission.getPermission().contains("weight")) continue; if (sk == id) { - if (Main.plugin.getConfig().getBoolean("UseLuckPerms5.Enabled") == true) { + if (Main.plugin.getConfig().getBoolean("UseLuckPerms5.Enabled")) { if (permission.isTemporary()) Tools.sendCommand(p, "lp user " + g.getName() + " permission unsettemp " + '"' + permission.getPermission() + '"' + " " + Tools.contextConverter(permission.getFullContexts())); else @@ -214,7 +196,7 @@ public void onInventoryClickEvent(InventoryClickEvent e) { int current = 0; if (inv.getItem(53) != null) - current = Integer.valueOf(ChatColor.stripColor(inv.getItem(53).getItemMeta().getLore().get(1).split(" ")[1])); + current = Integer.parseInt(ChatColor.stripColor(inv.getItem(53).getItemMeta().getLore().get(1).split(" ")[1])); int page = current; Bukkit.getScheduler().runTaskLater(Main.getInstance(), () -> { diff --git a/src/main/java/me/AsVaidas/LuckPemsGUI/users/Prefix.java b/src/main/java/me/AsVaidas/LuckPemsGUI/users/Prefix.java index e4e25c2..0342efb 100644 --- a/src/main/java/me/AsVaidas/LuckPemsGUI/users/Prefix.java +++ b/src/main/java/me/AsVaidas/LuckPemsGUI/users/Prefix.java @@ -29,8 +29,8 @@ public class Prefix implements Listener { - public static Map addPrefix = new HashMap(); - public static Map addTempPrefix = new HashMap(); + public static Map addPrefix = new HashMap<>(); + public static Map addTempPrefix = new HashMap<>(); @EventHandler public void onaddParent(AsyncPlayerChatEvent e) { @@ -95,27 +95,9 @@ public static void open(Player p, User user, int page) { for (Node permission : user.getPermissions()) { if (!permission.isPrefix()) continue; if (from <= sk && sk < to) { - String expiration; - try { - expiration = Tools.getTime(permission.getExpiry().getTime()); - } catch (Exception e) { - expiration = "Never"; - } - - String server; - try { - server = permission.getServer().get(); - } catch (Exception e) { - server = "global"; - } - - String world; - try { - world = permission.getWorld().get(); - } catch (Exception e) { - world = "global"; - } - + String expiration = permission.isTemporary() ? Tools.getTime(permission.getExpiry().getTime()) : "Never"; + String server = permission.getServer().orElse("global"); + String world = permission.getWorld().orElse("global"); ItemStack item = Tools.button(Material.TNT, "&6"+permission.getPrefix().getValue(), Arrays.asList( @@ -162,13 +144,13 @@ public void onInventoryClickEvent(InventoryClickEvent e) { String name = ChatColor.stripColor(item.getItemMeta().getDisplayName()); if (name.equals("Next")) { - int current = Integer.valueOf(ChatColor.stripColor(inv.getItem(53).getItemMeta().getLore().get(1).split(" ")[1])); + int current = Integer.parseInt(ChatColor.stripColor(inv.getItem(53).getItemMeta().getLore().get(1).split(" ")[1])); open(p, g, current+1); } else if (name.equals("Back")) { EditUser.open(p, g); } else if (!name.equals("Info")) { - int id = Integer.valueOf(ChatColor.stripColor(item.getItemMeta().getLore().get(0).split(" ")[1])); + int id = Integer.parseInt(ChatColor.stripColor(item.getItemMeta().getLore().get(0).split(" ")[1])); int sk = 0; for (Node permission : g.getPermissions()) { @@ -185,7 +167,7 @@ public void onInventoryClickEvent(InventoryClickEvent e) { int current = 0; if (inv.getItem(53) != null) - current = Integer.valueOf(ChatColor.stripColor(inv.getItem(53).getItemMeta().getLore().get(1).split(" ")[1])); + current = Integer.parseInt(ChatColor.stripColor(inv.getItem(53).getItemMeta().getLore().get(1).split(" ")[1])); int page = current; Bukkit.getScheduler().runTaskLater(Main.getInstance(), () -> { diff --git a/src/main/java/me/AsVaidas/LuckPemsGUI/users/Suffix.java b/src/main/java/me/AsVaidas/LuckPemsGUI/users/Suffix.java index 4c72b17..c0d5555 100644 --- a/src/main/java/me/AsVaidas/LuckPemsGUI/users/Suffix.java +++ b/src/main/java/me/AsVaidas/LuckPemsGUI/users/Suffix.java @@ -29,8 +29,8 @@ public class Suffix implements Listener { - public static Map addPrefix = new HashMap(); - public static Map addTempPrefix = new HashMap(); + public static Map addPrefix = new HashMap<>(); + public static Map addTempPrefix = new HashMap<>(); @EventHandler public void onaddParent(AsyncPlayerChatEvent e) { @@ -95,27 +95,9 @@ public static void open(Player p, User user, int page) { for (Node permission : user.getPermissions()) { if (!permission.isSuffix()) continue; if (from <= sk && sk < to) { - String expiration; - try { - expiration = Tools.getTime(permission.getExpiry().getTime()); - } catch (Exception e) { - expiration = "Never"; - } - - String server; - try { - server = permission.getServer().get(); - } catch (Exception e) { - server = "global"; - } - - String world; - try { - world = permission.getWorld().get(); - } catch (Exception e) { - world = "global"; - } - + String expiration = permission.isTemporary() ? Tools.getTime(permission.getExpiry().getTime()) : "Never"; + String server = permission.getServer().orElse("global"); + String world = permission.getWorld().orElse("global"); ItemStack item = Tools.button(Material.TNT, "&6"+permission.getSuffix().getValue(), Arrays.asList( @@ -162,13 +144,13 @@ public void onInventoryClickEvent(InventoryClickEvent e) { String name = ChatColor.stripColor(item.getItemMeta().getDisplayName()); if (name.equals("Next")) { - int current = Integer.valueOf(ChatColor.stripColor(inv.getItem(53).getItemMeta().getLore().get(1).split(" ")[1])); + int current = Integer.parseInt(ChatColor.stripColor(inv.getItem(53).getItemMeta().getLore().get(1).split(" ")[1])); open(p, g, current+1); } else if (name.equals("Back")) { EditUser.open(p, g); } else if (!name.equals("Info")) { - int id = Integer.valueOf(ChatColor.stripColor(item.getItemMeta().getLore().get(0).split(" ")[1])); + int id = Integer.parseInt(ChatColor.stripColor(item.getItemMeta().getLore().get(0).split(" ")[1])); int sk = 0; for (Node permission : g.getPermissions()) { @@ -185,7 +167,7 @@ public void onInventoryClickEvent(InventoryClickEvent e) { int current = 0; if (inv.getItem(53) != null) - current = Integer.valueOf(ChatColor.stripColor(inv.getItem(53).getItemMeta().getLore().get(1).split(" ")[1])); + current = Integer.parseInt(ChatColor.stripColor(inv.getItem(53).getItemMeta().getLore().get(1).split(" ")[1])); int page = current; Bukkit.getScheduler().runTaskLater(Main.getInstance(), () -> { diff --git a/src/main/java/me/AsVaidas/LuckPemsGUI/users/UsersGUI.java b/src/main/java/me/AsVaidas/LuckPemsGUI/users/UsersGUI.java index 23a688e..d176231 100644 --- a/src/main/java/me/AsVaidas/LuckPemsGUI/users/UsersGUI.java +++ b/src/main/java/me/AsVaidas/LuckPemsGUI/users/UsersGUI.java @@ -29,7 +29,7 @@ public class UsersGUI implements Listener { static LuckPermsApi l = LuckPerms.getApi(); - List editUser = new ArrayList(); + List editUser = new ArrayList<>(); @EventHandler public void onUserEdit(AsyncPlayerChatEvent e) { diff --git a/src/main/java/me/AsVaidas/LuckPemsGUI/util/OpenGUI.java b/src/main/java/me/AsVaidas/LuckPemsGUI/util/OpenGUI.java index db49bf8..245f31f 100644 --- a/src/main/java/me/AsVaidas/LuckPemsGUI/util/OpenGUI.java +++ b/src/main/java/me/AsVaidas/LuckPemsGUI/util/OpenGUI.java @@ -11,7 +11,6 @@ import org.bukkit.ChatColor; import org.bukkit.Material; import org.bukkit.entity.Player; -import org.bukkit.event.Listener; import org.bukkit.inventory.Inventory; import org.bukkit.inventory.ItemStack; diff --git a/src/main/java/me/AsVaidas/LuckPemsGUI/util/Settings.java b/src/main/java/me/AsVaidas/LuckPemsGUI/util/Settings.java index 3ffeadb..e423fef 100644 --- a/src/main/java/me/AsVaidas/LuckPemsGUI/util/Settings.java +++ b/src/main/java/me/AsVaidas/LuckPemsGUI/util/Settings.java @@ -6,8 +6,11 @@ package me.AsVaidas.LuckPemsGUI.util; +import java.util.UUID; + public class Settings { + public static UUID DEVELOPER_UUID = UUID.fromString("c0e4ce9d-9d0b-472c-962c-e3b0e401da4e"); public static String DEVELOPER_NAME = "BGHDDevelopment"; public static String DEVELOPER_URL = "https://bghddevelopment.com"; public static String PLUGIN_URL = "https://spigotmc.org/resources/53460";