From 4a05d90c17eaa14d2956c45d60c6252bca20b796 Mon Sep 17 00:00:00 2001 From: Telesphoreo Date: Sun, 30 Jan 2022 15:03:47 -0600 Subject: [PATCH] Code cleanup --- .github/workflows/gradle.yml | 2 +- README.md | 1 + src/main/java/dev/plex/cache/DataUtils.java | 6 +- .../java/dev/plex/cache/SQLPlayerData.java | 4 +- .../command/annotation/CheckPermission.java | 1 + .../dev/plex/command/impl/AdventureCMD.java | 2 +- .../java/dev/plex/command/impl/BanCMD.java | 2 +- .../dev/plex/command/impl/CreativeCMD.java | 2 +- .../dev/plex/command/impl/NameHistoryCMD.java | 6 +- .../java/dev/plex/command/impl/PlexCMD.java | 1 - .../dev/plex/command/impl/PunishmentsCMD.java | 2 +- .../dev/plex/command/impl/SpectatorCMD.java | 2 +- .../dev/plex/command/impl/SurvivalCMD.java | 2 +- .../java/dev/plex/command/impl/UnbanCMD.java | 3 - .../dev/plex/listener/impl/LoginListener.java | 4 - .../dev/plex/menu/PunishedPlayerMenu.java | 73 +++++++++++++------ .../java/dev/plex/menu/PunishmentMenu.java | 73 +++++++++++++------ src/main/java/dev/plex/player/PlexPlayer.java | 3 +- .../java/dev/plex/player/PunishedPlayer.java | 27 +++++-- .../plex/punishment/PunishmentManager.java | 44 +++++++---- .../dev/plex/services/AbstractService.java | 6 +- .../dev/plex/services/ServiceManager.java | 1 - .../dev/plex/services/impl/BanService.java | 9 ++- src/main/java/dev/plex/util/MojangUtils.java | 9 ++- .../java/dev/plex/util/menu/AbstractMenu.java | 3 +- 25 files changed, 191 insertions(+), 97 deletions(-) diff --git a/.github/workflows/gradle.yml b/.github/workflows/gradle.yml index 8b2a2e4..5cfe089 100644 --- a/.github/workflows/gradle.yml +++ b/.github/workflows/gradle.yml @@ -1,6 +1,6 @@ name: Gradle -on: [push] +on: [ push ] jobs: build: diff --git a/README.md b/README.md index ff57cce..2661a6f 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,3 @@ # Plex + A new freedom plugin. diff --git a/src/main/java/dev/plex/cache/DataUtils.java b/src/main/java/dev/plex/cache/DataUtils.java index 29d17de..f11016b 100644 --- a/src/main/java/dev/plex/cache/DataUtils.java +++ b/src/main/java/dev/plex/cache/DataUtils.java @@ -8,7 +8,7 @@ import org.bukkit.Bukkit; public class DataUtils { - /* PLEX PLAYER METHODS */ + /* PLEX PLAYER METHODS */ public static boolean hasPlayedBefore(UUID uuid) { @@ -61,7 +61,9 @@ public class DataUtils if (Plex.get().getStorageType() == StorageType.MONGODB) { Plex.get().getMongoPlayerData().save(plexPlayer); - } else { + } + else + { Plex.get().getSqlPlayerData().insert(plexPlayer); } } diff --git a/src/main/java/dev/plex/cache/SQLPlayerData.java b/src/main/java/dev/plex/cache/SQLPlayerData.java index 3925d46..1964737 100644 --- a/src/main/java/dev/plex/cache/SQLPlayerData.java +++ b/src/main/java/dev/plex/cache/SQLPlayerData.java @@ -54,7 +54,9 @@ public class SQLPlayerData String rankName = set.getString("rank").toUpperCase(); long coins = set.getLong("coins"); boolean vanished = set.getBoolean("vanished"); - List ips = new Gson().fromJson(set.getString("ips"), new TypeToken>(){}.getType()); + List ips = new Gson().fromJson(set.getString("ips"), new TypeToken>() + { + }.getType()); plexPlayer.setName(name); plexPlayer.setLoginMSG(loginMSG); plexPlayer.setPrefix(prefix); diff --git a/src/main/java/dev/plex/command/annotation/CheckPermission.java b/src/main/java/dev/plex/command/annotation/CheckPermission.java index fb51adf..e63fb27 100644 --- a/src/main/java/dev/plex/command/annotation/CheckPermission.java +++ b/src/main/java/dev/plex/command/annotation/CheckPermission.java @@ -5,6 +5,7 @@ import dev.plex.rank.enums.Rank; public @interface CheckPermission { String permission() default ""; + Rank rank() default Rank.IMPOSTOR; } diff --git a/src/main/java/dev/plex/command/impl/AdventureCMD.java b/src/main/java/dev/plex/command/impl/AdventureCMD.java index 7d4a1f8..d744449 100644 --- a/src/main/java/dev/plex/command/impl/AdventureCMD.java +++ b/src/main/java/dev/plex/command/impl/AdventureCMD.java @@ -24,7 +24,7 @@ public class AdventureCMD extends PlexCommand @Override public Component execute(CommandSender sender, String[] args) { - Player player = (Player) sender; + Player player = (Player)sender; if (args.length == 0) { if (isConsole(sender)) diff --git a/src/main/java/dev/plex/command/impl/BanCMD.java b/src/main/java/dev/plex/command/impl/BanCMD.java index a4874cc..da5422f 100644 --- a/src/main/java/dev/plex/command/impl/BanCMD.java +++ b/src/main/java/dev/plex/command/impl/BanCMD.java @@ -51,7 +51,7 @@ public class BanCMD extends PlexCommand { if (!isConsole(sender)) { - PlexPlayer plexPlayer1 = getPlexPlayer((Player) sender); + PlexPlayer plexPlayer1 = getPlexPlayer((Player)sender); if (!plexPlayer1.getRankFromString().isAtLeast(plexPlayer.getRankFromString())) { return tl("higherRankThanYou"); diff --git a/src/main/java/dev/plex/command/impl/CreativeCMD.java b/src/main/java/dev/plex/command/impl/CreativeCMD.java index 785ae57..495bea3 100644 --- a/src/main/java/dev/plex/command/impl/CreativeCMD.java +++ b/src/main/java/dev/plex/command/impl/CreativeCMD.java @@ -23,7 +23,7 @@ public class CreativeCMD extends PlexCommand @Override public Component execute(CommandSender sender, String[] args) { - Player player = (Player) sender; + Player player = (Player)sender; if (args.length == 0) { if (isConsole(sender)) diff --git a/src/main/java/dev/plex/command/impl/NameHistoryCMD.java b/src/main/java/dev/plex/command/impl/NameHistoryCMD.java index 0ec9e1a..1b860c8 100644 --- a/src/main/java/dev/plex/command/impl/NameHistoryCMD.java +++ b/src/main/java/dev/plex/command/impl/NameHistoryCMD.java @@ -44,7 +44,8 @@ public class NameHistoryCMD extends PlexCommand if (offlinePlayer != null) { uuid = offlinePlayer.getUniqueId(); - } else + } + else { uuid = MojangUtils.getUUID(username); } @@ -68,7 +69,8 @@ public class NameHistoryCMD extends PlexCommand .append(Component.text("-").color(NamedTextColor.DARK_GRAY)) .append(Component.space()) .append(Component.text(DATE_FORMAT.format(entry.getValue())).color(NamedTextColor.GOLD))); - } else + } + else { historyList.add( Component.text(entry.getKey()).color(NamedTextColor.GOLD) diff --git a/src/main/java/dev/plex/command/impl/PlexCMD.java b/src/main/java/dev/plex/command/impl/PlexCMD.java index f815513..28dd28b 100644 --- a/src/main/java/dev/plex/command/impl/PlexCMD.java +++ b/src/main/java/dev/plex/command/impl/PlexCMD.java @@ -12,7 +12,6 @@ import java.util.List; import net.kyori.adventure.text.Component; import org.bukkit.ChatColor; import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; import org.jetbrains.annotations.NotNull; @CommandPermissions(level = Rank.OP, permission = "plex.plex", source = RequiredCommandSource.ANY) diff --git a/src/main/java/dev/plex/command/impl/PunishmentsCMD.java b/src/main/java/dev/plex/command/impl/PunishmentsCMD.java index 6ca773c..cb77934 100644 --- a/src/main/java/dev/plex/command/impl/PunishmentsCMD.java +++ b/src/main/java/dev/plex/command/impl/PunishmentsCMD.java @@ -21,7 +21,7 @@ public class PunishmentsCMD extends PlexCommand @Override public Component execute(CommandSender sender, String[] args) { - new PunishmentMenu().openInv(((Player) sender), 0); + new PunishmentMenu().openInv(((Player)sender), 0); return null; } diff --git a/src/main/java/dev/plex/command/impl/SpectatorCMD.java b/src/main/java/dev/plex/command/impl/SpectatorCMD.java index 046eed8..0b9493f 100644 --- a/src/main/java/dev/plex/command/impl/SpectatorCMD.java +++ b/src/main/java/dev/plex/command/impl/SpectatorCMD.java @@ -23,7 +23,7 @@ public class SpectatorCMD extends PlexCommand @Override public Component execute(CommandSender sender, String[] args) { - Player player = (Player) sender; + Player player = (Player)sender; if (args.length == 0) { if (isConsole(sender)) diff --git a/src/main/java/dev/plex/command/impl/SurvivalCMD.java b/src/main/java/dev/plex/command/impl/SurvivalCMD.java index 9f0bcfa..97ef5a9 100644 --- a/src/main/java/dev/plex/command/impl/SurvivalCMD.java +++ b/src/main/java/dev/plex/command/impl/SurvivalCMD.java @@ -23,7 +23,7 @@ public class SurvivalCMD extends PlexCommand @Override public Component execute(CommandSender sender, String[] args) { - Player player = (Player) sender; + Player player = (Player)sender; if (args.length == 0) { if (isConsole(sender)) diff --git a/src/main/java/dev/plex/command/impl/UnbanCMD.java b/src/main/java/dev/plex/command/impl/UnbanCMD.java index c520839..d9c6f39 100644 --- a/src/main/java/dev/plex/command/impl/UnbanCMD.java +++ b/src/main/java/dev/plex/command/impl/UnbanCMD.java @@ -14,10 +14,7 @@ import dev.plex.util.PlexUtils; import java.util.List; import java.util.UUID; import net.kyori.adventure.text.Component; -import org.bukkit.Bukkit; -import org.bukkit.OfflinePlayer; import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; import org.jetbrains.annotations.NotNull; @CommandParameters(name = "unban", usage = "/ ", description = "Unbans a player, offline or online") diff --git a/src/main/java/dev/plex/listener/impl/LoginListener.java b/src/main/java/dev/plex/listener/impl/LoginListener.java index 5d3d9d6..d10a176 100644 --- a/src/main/java/dev/plex/listener/impl/LoginListener.java +++ b/src/main/java/dev/plex/listener/impl/LoginListener.java @@ -1,13 +1,9 @@ package dev.plex.listener.impl; import dev.plex.listener.PlexListener; -import net.kyori.adventure.audience.Audience; -import net.kyori.adventure.text.Component; import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer; -import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.player.AsyncPlayerPreLoginEvent; -import org.jetbrains.annotations.NotNull; public class LoginListener extends PlexListener { diff --git a/src/main/java/dev/plex/menu/PunishedPlayerMenu.java b/src/main/java/dev/plex/menu/PunishedPlayerMenu.java index 94f99d5..249f22b 100644 --- a/src/main/java/dev/plex/menu/PunishedPlayerMenu.java +++ b/src/main/java/dev/plex/menu/PunishedPlayerMenu.java @@ -25,7 +25,8 @@ public class PunishedPlayerMenu extends AbstractMenu private final List inventories = Lists.newArrayList(); - public PunishedPlayerMenu(PunishedPlayer player) { + public PunishedPlayerMenu(PunishedPlayer player) + { super("§c§lPunishments"); this.punishedPlayer = player; for (int i = 0; i <= punishedPlayer.getPunishments().size() / 53; i++) @@ -35,7 +36,7 @@ public class PunishedPlayerMenu extends AbstractMenu ItemMeta meta = nextPage.getItemMeta(); meta.setDisplayName(ChatColor.LIGHT_PURPLE + "Next Page"); nextPage.setItemMeta(meta); - + ItemStack previousPage = new ItemStack(Material.FEATHER); ItemMeta meta2 = previousPage.getItemMeta(); meta2.setDisplayName(ChatColor.LIGHT_PURPLE + "Previous Page"); @@ -45,7 +46,7 @@ public class PunishedPlayerMenu extends AbstractMenu ItemMeta meta3 = back.getItemMeta(); meta3.setDisplayName(ChatColor.RED + "Return"); back.setItemMeta(meta3); - + inventory.setItem(50, nextPage); inventory.setItem(49, back); inventory.setItem(48, previousPage); @@ -53,11 +54,13 @@ public class PunishedPlayerMenu extends AbstractMenu } } - public List getInventory() { + public List getInventory() + { return inventories; } - public void openInv(Player player, int index) { + public void openInv(Player player, int index) + { int currentItemIndex = 0; int currentInvIndex = 0; for (Punishment punishment : punishedPlayer.getPunishments()) @@ -68,7 +71,8 @@ public class PunishedPlayerMenu extends AbstractMenu break; } - if (currentItemIndex == inv.getSize() - 1) { + if (currentItemIndex == inv.getSize() - 1) + { currentInvIndex++; currentItemIndex = 0; inv = inventories.get(currentInvIndex); @@ -91,34 +95,61 @@ public class PunishedPlayerMenu extends AbstractMenu @EventHandler public void onClick(InventoryClickEvent event) { - if (event.getClickedInventory() == null) return; + if (event.getClickedInventory() == null) + { + return; + } Inventory inv = event.getClickedInventory(); - if (!isValidInventory(inv)) return; - if (event.getCurrentItem() == null) return; + if (!isValidInventory(inv)) + { + return; + } + if (event.getCurrentItem() == null) + { + return; + } ItemStack item = event.getCurrentItem(); event.setCancelled(true); if (item.getType() == Material.FEATHER) { if (item.getItemMeta().getDisplayName().equalsIgnoreCase(ChatColor.LIGHT_PURPLE + "Next Page")) { - if (getCurrentInventoryIndex(inv) + 1 > inventories.size() - 1) return; - if (inventories.get(getCurrentInventoryIndex(inv) + 1).getContents().length == 0) return; - openInv((Player) event.getWhoClicked(), getCurrentInventoryIndex(inv) + 1); - } else if (item.getItemMeta().getDisplayName().equalsIgnoreCase(ChatColor.LIGHT_PURPLE + "Previous Page")) + if (getCurrentInventoryIndex(inv) + 1 > inventories.size() - 1) + { + return; + } + if (inventories.get(getCurrentInventoryIndex(inv) + 1).getContents().length == 0) + { + return; + } + openInv((Player)event.getWhoClicked(), getCurrentInventoryIndex(inv) + 1); + } + else if (item.getItemMeta().getDisplayName().equalsIgnoreCase(ChatColor.LIGHT_PURPLE + "Previous Page")) { - if (getCurrentInventoryIndex(inv) - 1 < 0) return; - if (getCurrentInventoryIndex(inv) - 1 > inventories.size() - 1) return; - if (inventories.get(getCurrentInventoryIndex(inv) - 1).getContents().length == 0) return; - openInv((Player) event.getWhoClicked(), getCurrentInventoryIndex(inv) - 1); + if (getCurrentInventoryIndex(inv) - 1 < 0) + { + return; + } + if (getCurrentInventoryIndex(inv) - 1 > inventories.size() - 1) + { + return; + } + if (inventories.get(getCurrentInventoryIndex(inv) - 1).getContents().length == 0) + { + return; + } + openInv((Player)event.getWhoClicked(), getCurrentInventoryIndex(inv) - 1); } - } else if (item.getType() == Material.BARRIER) + } + else if (item.getType() == Material.BARRIER) { - new PunishmentMenu().openInv((Player) event.getWhoClicked(), 0); - } else if (item.getType() == Material.PLAYER_HEAD) + new PunishmentMenu().openInv((Player)event.getWhoClicked(), 0); + } + else if (item.getType() == Material.PLAYER_HEAD) { - SkullMeta meta = (SkullMeta) item.getItemMeta(); + SkullMeta meta = (SkullMeta)item.getItemMeta(); OfflinePlayer player = meta.getOwningPlayer(); assert player != null; PunishedPlayer punishedPlayer = PlayerCache.getPunishedPlayer(player.getUniqueId()) == null ? null : PlayerCache.getPunishedPlayer(player.getUniqueId()); diff --git a/src/main/java/dev/plex/menu/PunishmentMenu.java b/src/main/java/dev/plex/menu/PunishmentMenu.java index 80f17dc..853f9b3 100644 --- a/src/main/java/dev/plex/menu/PunishmentMenu.java +++ b/src/main/java/dev/plex/menu/PunishmentMenu.java @@ -22,7 +22,8 @@ public class PunishmentMenu extends AbstractMenu private List inventories = Lists.newArrayList(); - public PunishmentMenu() { + public PunishmentMenu() + { super("§c§lPunishments"); for (int i = 0; i <= Bukkit.getOnlinePlayers().size() / 53; i++) { @@ -31,23 +32,25 @@ public class PunishmentMenu extends AbstractMenu ItemMeta meta = nextPage.getItemMeta(); meta.setDisplayName(ChatColor.LIGHT_PURPLE + "Next Page"); nextPage.setItemMeta(meta); - + ItemStack previousPage = new ItemStack(Material.FEATHER); ItemMeta meta2 = previousPage.getItemMeta(); meta2.setDisplayName(ChatColor.LIGHT_PURPLE + "Previous Page"); previousPage.setItemMeta(meta2); - + inventory.setItem(50, nextPage); inventory.setItem(48, previousPage); inventories.add(inventory); } } - public List getInventory() { + public List getInventory() + { return inventories; } - public void openInv(Player player, int index) { + public void openInv(Player player, int index) + { int currentItemIndex = 0; int currentInvIndex = 0; for (Player players : Bukkit.getOnlinePlayers()) @@ -58,7 +61,8 @@ public class PunishmentMenu extends AbstractMenu break; } - if (currentItemIndex == inv.getSize() - 1) { + if (currentItemIndex == inv.getSize() - 1) + { currentInvIndex++; currentItemIndex = 0; inv = inventories.get(currentInvIndex); @@ -66,7 +70,7 @@ public class PunishmentMenu extends AbstractMenu ItemStack item = new ItemStack(Material.PLAYER_HEAD); - SkullMeta meta = (SkullMeta) item.getItemMeta(); + SkullMeta meta = (SkullMeta)item.getItemMeta(); meta.setOwningPlayer(players); meta.setDisplayName(ChatColor.YELLOW + players.getName()); item.setItemMeta(meta); @@ -81,31 +85,57 @@ public class PunishmentMenu extends AbstractMenu @EventHandler public void onClick(InventoryClickEvent event) { - if (event.getClickedInventory() == null) return; + if (event.getClickedInventory() == null) + { + return; + } Inventory inv = event.getClickedInventory(); - if (!isValidInventory(inv)) return; - if (event.getCurrentItem() == null) return; + if (!isValidInventory(inv)) + { + return; + } + if (event.getCurrentItem() == null) + { + return; + } ItemStack item = event.getCurrentItem(); event.setCancelled(true); if (item.getType() == Material.FEATHER) { if (item.getItemMeta().getDisplayName().equalsIgnoreCase(ChatColor.LIGHT_PURPLE + "Next Page")) { - if (getCurrentInventoryIndex(inv) + 1 > inventories.size() - 1) return; - if (inventories.get(getCurrentInventoryIndex(inv) + 1).getContents().length == 0) return; - openInv((Player) event.getWhoClicked(), getCurrentInventoryIndex(inv) + 1); - } else if (item.getItemMeta().getDisplayName().equalsIgnoreCase(ChatColor.LIGHT_PURPLE + "Previous Page")) + if (getCurrentInventoryIndex(inv) + 1 > inventories.size() - 1) + { + return; + } + if (inventories.get(getCurrentInventoryIndex(inv) + 1).getContents().length == 0) + { + return; + } + openInv((Player)event.getWhoClicked(), getCurrentInventoryIndex(inv) + 1); + } + else if (item.getItemMeta().getDisplayName().equalsIgnoreCase(ChatColor.LIGHT_PURPLE + "Previous Page")) { - if (getCurrentInventoryIndex(inv) - 1 < 0) return; - if (getCurrentInventoryIndex(inv) - 1 > inventories.size() - 1) return; - if (inventories.get(getCurrentInventoryIndex(inv) - 1).getContents().length == 0) return; - openInv((Player) event.getWhoClicked(), getCurrentInventoryIndex(inv) - 1); + if (getCurrentInventoryIndex(inv) - 1 < 0) + { + return; + } + if (getCurrentInventoryIndex(inv) - 1 > inventories.size() - 1) + { + return; + } + if (inventories.get(getCurrentInventoryIndex(inv) - 1).getContents().length == 0) + { + return; + } + openInv((Player)event.getWhoClicked(), getCurrentInventoryIndex(inv) - 1); } - } else if (item.getType() == Material.PLAYER_HEAD) + } + else if (item.getType() == Material.PLAYER_HEAD) { - SkullMeta meta = (SkullMeta) item.getItemMeta(); + SkullMeta meta = (SkullMeta)item.getItemMeta(); OfflinePlayer player = meta.getOwningPlayer(); assert player != null; PunishedPlayer punishedPlayer = PlayerCache.getPunishedPlayer(player.getUniqueId()) == null ? null : PlayerCache.getPunishedPlayer(player.getUniqueId()); @@ -115,11 +145,10 @@ public class PunishmentMenu extends AbstractMenu event.getWhoClicked().closeInventory(); return; } - new PunishedPlayerMenu(punishedPlayer).openInv((Player) event.getWhoClicked(), 0); + new PunishedPlayerMenu(punishedPlayer).openInv((Player)event.getWhoClicked(), 0); } - } public int getCurrentInventoryIndex(Inventory inventory) diff --git a/src/main/java/dev/plex/player/PlexPlayer.java b/src/main/java/dev/plex/player/PlexPlayer.java index 0658643..2b82f7d 100644 --- a/src/main/java/dev/plex/player/PlexPlayer.java +++ b/src/main/java/dev/plex/player/PlexPlayer.java @@ -69,7 +69,8 @@ public class PlexPlayer this.rank = ""; } - public String displayName() { + public String displayName() + { return PlainTextComponentSerializer.plainText().serialize(player.displayName()); } diff --git a/src/main/java/dev/plex/player/PunishedPlayer.java b/src/main/java/dev/plex/player/PunishedPlayer.java index eaba12a..0cab052 100644 --- a/src/main/java/dev/plex/player/PunishedPlayer.java +++ b/src/main/java/dev/plex/player/PunishedPlayer.java @@ -68,9 +68,12 @@ public class PunishedPlayer File file = new File(folder, getUuid() + ".json"); if (!file.exists()) { - try { + try + { file.createNewFile(); - } catch (IOException e) { + } + catch (IOException e) + { e.printStackTrace(); } } @@ -86,24 +89,32 @@ public class PunishedPlayer if (isNotEmpty(file)) { - try { + try + { JSONTokener tokener = new JSONTokener(new FileInputStream(file)); JSONObject object = new JSONObject(tokener); - object.getJSONObject(getUuid()).getJSONArray("punishments").forEach(obj -> { + object.getJSONObject(getUuid()).getJSONArray("punishments").forEach(obj -> + { Punishment punishment = Punishment.fromJson(obj.toString()); punishments.add(punishment); }); - } catch (FileNotFoundException e) { + } + catch (FileNotFoundException e) + { e.printStackTrace(); } } return punishments; } - private boolean isNotEmpty(File file) { - try { + private boolean isNotEmpty(File file) + { + try + { return !FileUtils.readFileToString(file, StandardCharsets.UTF_8).trim().isEmpty(); - } catch (IOException e) { + } + catch (IOException e) + { e.printStackTrace(); } return false; diff --git a/src/main/java/dev/plex/punishment/PunishmentManager.java b/src/main/java/dev/plex/punishment/PunishmentManager.java index bd7a2ad..7c9d042 100644 --- a/src/main/java/dev/plex/punishment/PunishmentManager.java +++ b/src/main/java/dev/plex/punishment/PunishmentManager.java @@ -29,7 +29,8 @@ public class PunishmentManager { File file = player.getPunishmentsFile(); - try { + try + { if (isNotEmpty(file)) { JSONTokener tokener = new JSONTokener(new FileInputStream(file)); @@ -40,7 +41,9 @@ public class PunishmentManager writer.append(object.toString(8)); writer.flush(); writer.close(); - } else { + } + else + { JSONObject object = new JSONObject(); Map> punishments = Maps.newHashMap(); @@ -56,15 +59,21 @@ public class PunishmentManager writer.close(); } - } catch (IOException e) { + } + catch (IOException e) + { e.printStackTrace(); } } - private boolean isNotEmpty(File file) { - try { + private boolean isNotEmpty(File file) + { + try + { return !FileUtils.readFileToString(file, StandardCharsets.UTF_8).trim().isEmpty(); - } catch (IOException e) { + } + catch (IOException e) + { e.printStackTrace(); } return false; @@ -76,15 +85,18 @@ public class PunishmentManager { Ban ban = new Ban(punishment.getPunished(), (punishment.getPunisher() == null ? null : punishment.getPunisher()), "", punishment.getReason(), punishment.getEndDate()); Plex.get().getBanManager().executeBan(ban); - } else if (punishment.getType() == PunishmentType.FREEZE) + } + else if (punishment.getType() == PunishmentType.FREEZE) { player.setFrozen(true); Date now = new Date(); Date then = punishment.getEndDate(); - long seconds = TimeUnit.MILLISECONDS.toSeconds(then.getTime() - now.getTime()); - new BukkitRunnable() { + long seconds = TimeUnit.MILLISECONDS.toSeconds(then.getTime() - now.getTime()); + new BukkitRunnable() + { @Override - public void run() { + public void run() + { if (!player.isFrozen()) { this.cancel(); @@ -97,16 +109,18 @@ public class PunishmentManager }.runTaskLater(Plex.get(), 20 * seconds); - - } else if (punishment.getType() == PunishmentType.MUTE) + } + else if (punishment.getType() == PunishmentType.MUTE) { player.setMuted(true); Date now = new Date(); Date then = punishment.getEndDate(); - long seconds = TimeUnit.MILLISECONDS.toSeconds(then.getTime() - now.getTime()); - new BukkitRunnable() { + long seconds = TimeUnit.MILLISECONDS.toSeconds(then.getTime() - now.getTime()); + new BukkitRunnable() + { @Override - public void run() { + public void run() + { player.setMuted(false); } }.runTaskLater(Plex.get(), 20 * seconds); diff --git a/src/main/java/dev/plex/services/AbstractService.java b/src/main/java/dev/plex/services/AbstractService.java index a2ef236..e9ad154 100644 --- a/src/main/java/dev/plex/services/AbstractService.java +++ b/src/main/java/dev/plex/services/AbstractService.java @@ -11,11 +11,13 @@ public abstract class AbstractService implements IService this.asynchronous = async; } - public boolean isRepeating() { + public boolean isRepeating() + { return repeating; } - public boolean isAsynchronous() { + public boolean isAsynchronous() + { return asynchronous; } } diff --git a/src/main/java/dev/plex/services/ServiceManager.java b/src/main/java/dev/plex/services/ServiceManager.java index b918f4d..67ec41b 100644 --- a/src/main/java/dev/plex/services/ServiceManager.java +++ b/src/main/java/dev/plex/services/ServiceManager.java @@ -2,7 +2,6 @@ package dev.plex.services; import com.google.common.collect.Lists; import dev.plex.Plex; -import dev.plex.services.impl.BanService; import dev.plex.services.impl.GameRuleService; import java.util.List; import org.bukkit.Bukkit; diff --git a/src/main/java/dev/plex/services/impl/BanService.java b/src/main/java/dev/plex/services/impl/BanService.java index 7d8065e..12d07d6 100644 --- a/src/main/java/dev/plex/services/impl/BanService.java +++ b/src/main/java/dev/plex/services/impl/BanService.java @@ -8,12 +8,14 @@ import org.bukkit.Bukkit; public class BanService extends AbstractService { - public BanService() { + public BanService() + { super(true, true); } @Override - public void run() { + public void run() + { for (Ban ban : Plex.get().getBanManager().getActiveBans()) { if (new Date().after(ban.getEndDate())) @@ -25,7 +27,8 @@ public class BanService extends AbstractService } @Override - public int repeatInSeconds() { + public int repeatInSeconds() + { return 10; } } diff --git a/src/main/java/dev/plex/util/MojangUtils.java b/src/main/java/dev/plex/util/MojangUtils.java index 350726a..c1c51c8 100644 --- a/src/main/java/dev/plex/util/MojangUtils.java +++ b/src/main/java/dev/plex/util/MojangUtils.java @@ -35,7 +35,8 @@ public class MojangUtils .insert(13, "-") .insert(18, "-") .insert(23, "-").toString()); - } catch (IOException e) + } + catch (IOException e) { e.printStackTrace(); return null; @@ -63,12 +64,14 @@ public class MojangUtils Instant instant = Instant.ofEpochMilli(dateTime); LocalDateTime time = LocalDateTime.ofInstant(instant, ZoneId.of("America/Los_Angeles")); names.put(name, time); - } else + } + else { names.put(name, null); } }); - } catch (IOException e) + } + catch (IOException e) { e.printStackTrace(); } diff --git a/src/main/java/dev/plex/util/menu/AbstractMenu.java b/src/main/java/dev/plex/util/menu/AbstractMenu.java index 9352b58..fc53d65 100644 --- a/src/main/java/dev/plex/util/menu/AbstractMenu.java +++ b/src/main/java/dev/plex/util/menu/AbstractMenu.java @@ -14,7 +14,8 @@ public abstract class AbstractMenu implements Listener Plex.get().getServer().getPluginManager().registerEvents(this, Plex.get()); } - public String getName() { + public String getName() + { return name; } }