From 98822e8e9e06996a3193c72c1c3bfeef62ddbc55 Mon Sep 17 00:00:00 2001 From: Heliosares Date: Sat, 14 Jan 2023 13:34:36 -0500 Subject: [PATCH] Reformatting --- .../adapters/SpigotConfigAdapter.java | 2 +- .../auxprotect/bungee/APBListener.java | 9 +- .../auxprotect/bungee/AuxProtectBungee.java | 1 - .../heliosares/auxprotect/core/APPlayer.java | 5 +- .../auxprotect/core/IAuxProtect.java | 30 +++---- .../heliosares/auxprotect/core/Language.java | 2 +- .../auxprotect/core/Parameters.java | 24 +++--- .../core/commands/ClaimInvCommand.java | 4 +- .../auxprotect/core/commands/InvCommand.java | 2 +- .../core/commands/InventoryCommand.java | 1 - .../auxprotect/core/commands/XrayCommand.java | 2 - .../auxprotect/database/ActivityResults.java | 1 - .../auxprotect/database/BlobManager.java | 3 +- .../auxprotect/database/DbEntry.java | 8 +- .../auxprotect/database/DbEntryBukkit.java | 2 +- .../auxprotect/database/EntryAction.java | 60 +++++++------- .../auxprotect/database/InvDiffManager.java | 1 - .../auxprotect/database/MigrationManager.java | 66 +++++++-------- .../auxprotect/database/Results.java | 2 - .../auxprotect/database/SQLManager.java | 78 ++++++++--------- .../exceptions/AuxProtectException.java | 1 + .../auxprotect/spigot/AuxProtectSpigot.java | 2 +- .../auxprotect/spigot/VeinManager.java | 6 +- .../listeners/AuctionHouseListener.java | 3 +- .../spigot/listeners/CommandListener.java | 10 +-- .../spigot/listeners/EntityListener.java | 23 ++--- .../spigot/listeners/InventoryListener.java | 2 +- .../spigot/listeners/JobsListener.java | 3 +- .../spigot/listeners/PaneListener.java | 2 +- .../spigot/listeners/PlayerListener.java | 7 +- .../spigot/listeners/ProjectileListener.java | 8 +- .../spigot/listeners/VeinListener.java | 2 +- .../spigot/listeners/WorldListener.java | 2 +- .../auxprotect/towny/TownyManager.java | 6 +- .../heliosares/auxprotect/utils/BidiMap.java | 5 +- .../auxprotect/utils/BidiMapCache.java | 7 +- .../auxprotect/utils/ChartRenderer.java | 9 +- .../auxprotect/utils/HasteBinAPI.java | 3 +- .../auxprotect/utils/InvSerialization.java | 1 + .../heliosares/auxprotect/utils/KeyUtil.java | 1 + .../auxprotect/utils/MoneySolver.java | 4 +- src/dev/heliosares/auxprotect/utils/Pane.java | 9 +- .../auxprotect/utils/PlayTimeSolver.java | 3 +- .../auxprotect/utils/PlaybackSolver.java | 83 +++++++++---------- .../auxprotect/utils/PosEncoder.java | 23 +++-- 45 files changed, 250 insertions(+), 278 deletions(-) diff --git a/src/dev/heliosares/auxprotect/adapters/SpigotConfigAdapter.java b/src/dev/heliosares/auxprotect/adapters/SpigotConfigAdapter.java index 3c1515a..34af0fb 100644 --- a/src/dev/heliosares/auxprotect/adapters/SpigotConfigAdapter.java +++ b/src/dev/heliosares/auxprotect/adapters/SpigotConfigAdapter.java @@ -110,7 +110,7 @@ public class SpigotConfigAdapter extends ConfigAdapter { public void load() throws IOException { super.load(); try { - config = (FileConfiguration) YamlConfiguration.loadConfiguration(file); + config = YamlConfiguration.loadConfiguration(file); } catch (Exception e) { AuxProtectAPI.getInstance().warning("Error while loading " + path + ":"); throw e; diff --git a/src/dev/heliosares/auxprotect/bungee/APBListener.java b/src/dev/heliosares/auxprotect/bungee/APBListener.java index 5ad2e8d..880483c 100644 --- a/src/dev/heliosares/auxprotect/bungee/APBListener.java +++ b/src/dev/heliosares/auxprotect/bungee/APBListener.java @@ -35,8 +35,7 @@ public class APBListener implements Listener { @EventHandler public void chatEvent(ChatEvent e) { try { - if (e.getSender() instanceof ProxiedPlayer) { - ProxiedPlayer player = (ProxiedPlayer) e.getSender(); + if (e.getSender() instanceof ProxiedPlayer player) { if (e.isCommand()) { DbEntry entry = new DbEntry(AuxProtectBungee.getLabel(player), EntryAction.COMMAND, false, e.getMessage(), ""); @@ -54,9 +53,9 @@ public class APBListener implements Listener { } } else if (Events.PMToggle.containsKey(player.getUniqueId())) { String message = e.getMessage(); - if (ProxyServer.getInstance().getPlayer((UUID) Events.PMToggle.get(player.getUniqueId())) != null) { + if (ProxyServer.getInstance().getPlayer(Events.PMToggle.get(player.getUniqueId())) != null) { ProxiedPlayer target = ProxyServer.getInstance() - .getPlayer((UUID) Events.PMToggle.get(player.getUniqueId())); + .getPlayer(Events.PMToggle.get(player.getUniqueId())); handlePM(player, target, message); } @@ -82,7 +81,7 @@ public class APBListener implements Listener { String message = MultiChatUtil.getMessageFromArgs(args); if (MultiChat.lastmsg.containsKey(player.getUniqueId())) { ProxiedPlayer target = ProxyServer.getInstance() - .getPlayer((UUID) MultiChat.lastmsg.get(player.getUniqueId())); + .getPlayer(MultiChat.lastmsg.get(player.getUniqueId())); if (target != null) { handlePM(player, target, message); diff --git a/src/dev/heliosares/auxprotect/bungee/AuxProtectBungee.java b/src/dev/heliosares/auxprotect/bungee/AuxProtectBungee.java index 52a0260..438b56e 100644 --- a/src/dev/heliosares/auxprotect/bungee/AuxProtectBungee.java +++ b/src/dev/heliosares/auxprotect/bungee/AuxProtectBungee.java @@ -132,7 +132,6 @@ public class AuxProtectBungee extends Plugin implements IAuxProtect { print(e); getLogger().severe("Failed to connect to SQL database. Disabling."); onDisable(); - return; } /* diff --git a/src/dev/heliosares/auxprotect/core/APPlayer.java b/src/dev/heliosares/auxprotect/core/APPlayer.java index 783df50..5e96772 100644 --- a/src/dev/heliosares/auxprotect/core/APPlayer.java +++ b/src/dev/heliosares/auxprotect/core/APPlayer.java @@ -15,6 +15,7 @@ import java.util.List; public class APPlayer { public final Player player; private final IAuxProtect plugin; + private final List inventoryBlob = new ArrayList<>(); public long lastLoggedMoney; public long lastLoggedInventory; public long lastLoggedInventoryDiff; @@ -30,6 +31,7 @@ public class APPlayer { public long lastNotifyInactive; // hotbar, main, armor, offhand, echest private List invDiffItems; + private Location lastLocationDiff; public APPlayer(IAuxProtect plugin, Player player) { this.player = player; @@ -141,9 +143,6 @@ public class APPlayer { } } - private final List inventoryBlob = new ArrayList<>(); - private Location lastLocationDiff; - public void tickDiffPos() { if (lastLocationDiff != null) { synchronized (inventoryBlob) { diff --git a/src/dev/heliosares/auxprotect/core/IAuxProtect.java b/src/dev/heliosares/auxprotect/core/IAuxProtect.java index 80f9e48..caf6342 100644 --- a/src/dev/heliosares/auxprotect/core/IAuxProtect.java +++ b/src/dev/heliosares/auxprotect/core/IAuxProtect.java @@ -32,33 +32,33 @@ public interface IAuxProtect { void add(DbEntry dbEntry); - public void runAsync(Runnable run); + void runAsync(Runnable run); - public void runSync(Runnable runnable); + void runSync(Runnable runnable); - public String getCommandPrefix(); + String getCommandPrefix(); - public String getCommandAlias(); + String getCommandAlias(); - public SenderAdapter getConsoleSender(); + SenderAdapter getConsoleSender(); - public boolean isShuttingDown(); + boolean isShuttingDown(); - public boolean isHooked(String name); + boolean isHooked(String name); - public File getRootDirectory(); + File getRootDirectory(); - public String getPlatformVersion(); + String getPlatformVersion(); - public String getPluginVersion(); + String getPluginVersion(); - public APPlayer getAPPlayer(SenderAdapter sender); + APPlayer getAPPlayer(SenderAdapter sender); - public int queueSize(); + int queueSize(); - public String getStackLog(); + String getStackLog(); - public List listPlayers(); + List listPlayers(); - public boolean isEnabled(); + boolean isEnabled(); } diff --git a/src/dev/heliosares/auxprotect/core/Language.java b/src/dev/heliosares/auxprotect/core/Language.java index ad3dc2f..f85b939 100644 --- a/src/dev/heliosares/auxprotect/core/Language.java +++ b/src/dev/heliosares/auxprotect/core/Language.java @@ -56,7 +56,7 @@ public class Language { return ColorTranslate.cc(s); } - public static enum L { + public enum L { UPDATE, // NO_PERMISSION, // NO_PERMISSION_NODE, // diff --git a/src/dev/heliosares/auxprotect/core/Parameters.java b/src/dev/heliosares/auxprotect/core/Parameters.java index c4f0284..b76f6b1 100644 --- a/src/dev/heliosares/auxprotect/core/Parameters.java +++ b/src/dev/heliosares/auxprotect/core/Parameters.java @@ -37,25 +37,25 @@ public class Parameters { // time private long after; private long before = Long.MAX_VALUE; - private List exactTime = new ArrayList<>(); - private List uids = new ArrayList<>(); - private List users = new ArrayList<>(); + private final List exactTime = new ArrayList<>(); + private final List uids = new ArrayList<>(); + private final List users = new ArrayList<>(); // action - private List actions = new ArrayList<>(); + private final List actions = new ArrayList<>(); private List targets = new ArrayList<>(); - private List datas = new ArrayList<>(); + private final List datas = new ArrayList<>(); // table private Table table; // radius - private HashMap radius = new HashMap<>(); + private final HashMap radius = new HashMap<>(); private Location location; - private List worlds = new ArrayList<>(); + private final List worlds = new ArrayList<>(); // flags - private List flags = new ArrayList<>(); + private final List flags = new ArrayList<>(); // ratings - private List ratings = new ArrayList<>(); + private final List ratings = new ArrayList<>(); // ---------------------------------------------------- // ------------------- CONSTRUCTORS ------------------- @@ -962,9 +962,7 @@ public class Parameters { } } if (!worlds.isEmpty()) { - if (worlds.contains(entry.world) == negateWorld) { - return false; - } + return worlds.contains(entry.world) != negateWorld; } return true; @@ -1015,7 +1013,7 @@ public class Parameters { return stmt + ")"; } - public static enum Flag { + public enum Flag { COUNT(null), COUNT_ONLY(null), PT(APPermission.LOOKUP_PLAYTIME), XRAY(APPermission.LOOKUP_XRAY), BW(null), MONEY(APPermission.LOOKUP_MONEY), ACTIVITY(APPermission.LOOKUP_ACTIVITY), PLAYBACK(APPermission.LOOKUP_PLAYBACK), INCREMENTAL_POS(APPermission.LOOKUP_PLAYBACK), RETENTION(APPermission.LOOKUP_RETENTION), HIDE_COORDS(null); diff --git a/src/dev/heliosares/auxprotect/core/commands/ClaimInvCommand.java b/src/dev/heliosares/auxprotect/core/commands/ClaimInvCommand.java index d26b0a9..b6f3330 100644 --- a/src/dev/heliosares/auxprotect/core/commands/ClaimInvCommand.java +++ b/src/dev/heliosares/auxprotect/core/commands/ClaimInvCommand.java @@ -24,7 +24,7 @@ import java.util.UUID; public class ClaimInvCommand implements CommandExecutor { - private AuxProtectSpigot plugin; + private final AuxProtectSpigot plugin; public ClaimInvCommand(AuxProtectSpigot plugin) { this.plugin = plugin; @@ -47,7 +47,7 @@ public class ClaimInvCommand implements CommandExecutor { target = Bukkit.getOfflinePlayer(UUID.fromString( plugin.getSqlManager().getUserManager().getUUIDFromUID(uid, false).substring(1))); } else if (sender instanceof Player player) { - uid = plugin.getSqlManager().getUserManager().getUIDFromUUID("$" + player.getUniqueId().toString(), + uid = plugin.getSqlManager().getUserManager().getUIDFromUUID("$" + player.getUniqueId(), false); target = player; } else { diff --git a/src/dev/heliosares/auxprotect/core/commands/InvCommand.java b/src/dev/heliosares/auxprotect/core/commands/InvCommand.java index 9ac4e9c..fba2c8e 100644 --- a/src/dev/heliosares/auxprotect/core/commands/InvCommand.java +++ b/src/dev/heliosares/auxprotect/core/commands/InvCommand.java @@ -117,7 +117,7 @@ public class InvCommand extends Command { } try { plugin.getSqlManager().getUserManager().setPendingInventory(plugin.getSqlManager() - .getUserManager().getUIDFromUUID("$" + target.getUniqueId().toString(), true), + .getUserManager().getUIDFromUUID("$" + target.getUniqueId(), true), recover); plugin.getSqlManager().executeWrite( "UPDATE " + Table.AUXPROTECT_INVENTORY diff --git a/src/dev/heliosares/auxprotect/core/commands/InventoryCommand.java b/src/dev/heliosares/auxprotect/core/commands/InventoryCommand.java index 8b3b6ee..3e53cae 100644 --- a/src/dev/heliosares/auxprotect/core/commands/InventoryCommand.java +++ b/src/dev/heliosares/auxprotect/core/commands/InventoryCommand.java @@ -96,7 +96,6 @@ public class InventoryCommand extends Command { String.format("§fBased on inventory from §9%s§f ago §7(%s)§f with §9%s§f differences", TimeUtil.millisToString(System.currentTimeMillis() - inv.basetime()), inv.basetime() + "e", inv.numdiff())); - ; plugin.runSync(() -> player.openInventory(output)); } else { diff --git a/src/dev/heliosares/auxprotect/core/commands/XrayCommand.java b/src/dev/heliosares/auxprotect/core/commands/XrayCommand.java index 2c56576..138a3e7 100644 --- a/src/dev/heliosares/auxprotect/core/commands/XrayCommand.java +++ b/src/dev/heliosares/auxprotect/core/commands/XrayCommand.java @@ -168,10 +168,8 @@ public class XrayCommand extends Command { XrayResults.sendEntry(spigot, sender, entry, auto); } catch (ConnectionPool.BusyException e) { sender.sendLang(Language.L.DATABASE_BUSY); - return; } catch (SQLException e) { sender.sendLang(Language.L.ERROR); - return; } } diff --git a/src/dev/heliosares/auxprotect/database/ActivityResults.java b/src/dev/heliosares/auxprotect/database/ActivityResults.java index 0e198e3..b5b02de 100644 --- a/src/dev/heliosares/auxprotect/database/ActivityResults.java +++ b/src/dev/heliosares/auxprotect/database/ActivityResults.java @@ -9,7 +9,6 @@ import dev.heliosares.auxprotect.utils.ActivitySolver; import java.time.Instant; import java.time.LocalDateTime; import java.time.ZoneId; -import java.util.ArrayList; import java.util.List; public class ActivityResults extends Results { diff --git a/src/dev/heliosares/auxprotect/database/BlobManager.java b/src/dev/heliosares/auxprotect/database/BlobManager.java index cf8b6a3..76e4576 100644 --- a/src/dev/heliosares/auxprotect/database/BlobManager.java +++ b/src/dev/heliosares/auxprotect/database/BlobManager.java @@ -18,11 +18,10 @@ public class BlobManager { private final SQLManager sql; private final IAuxProtect plugin; protected final HashMap cache = new HashMap<>(); + private final Table table; private long nextBlobID = 1; private long lastcleanup; - private final Table table; - public BlobManager(Table table, SQLManager sqlManager, IAuxProtect plugin) { this.table = table; this.sql = sqlManager; diff --git a/src/dev/heliosares/auxprotect/database/DbEntry.java b/src/dev/heliosares/auxprotect/database/DbEntry.java index 5fd81c3..29be804 100644 --- a/src/dev/heliosares/auxprotect/database/DbEntry.java +++ b/src/dev/heliosares/auxprotect/database/DbEntry.java @@ -220,14 +220,14 @@ public class DbEntry { return blob != null || blobid >= 0; } - protected void setBlobID(long blobid) { - this.blobid = blobid; - } - public long getBlobID() { return blobid; } + protected void setBlobID(long blobid) { + this.blobid = blobid; + } + @Override public String toString() { String out; diff --git a/src/dev/heliosares/auxprotect/database/DbEntryBukkit.java b/src/dev/heliosares/auxprotect/database/DbEntryBukkit.java index af5a0e5..0d9ee74 100644 --- a/src/dev/heliosares/auxprotect/database/DbEntryBukkit.java +++ b/src/dev/heliosares/auxprotect/database/DbEntryBukkit.java @@ -5,7 +5,7 @@ import org.bukkit.Location; import javax.annotation.Nullable; -public class DbEntryBukkit extends DbEntry{ +public class DbEntryBukkit extends DbEntry { public DbEntryBukkit(String userLabel, EntryAction action, boolean state, String targetLabel, String data) { super(userLabel, action, state, targetLabel, data); diff --git a/src/dev/heliosares/auxprotect/database/EntryAction.java b/src/dev/heliosares/auxprotect/database/EntryAction.java index 63c5caa..f6f17b3 100644 --- a/src/dev/heliosares/auxprotect/database/EntryAction.java +++ b/src/dev/heliosares/auxprotect/database/EntryAction.java @@ -1,11 +1,5 @@ package dev.heliosares.auxprotect.database; -import java.util.Collection; -import java.util.Collections; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Set; - import dev.heliosares.auxprotect.AuxProtectAPI; import dev.heliosares.auxprotect.adapters.SenderAdapter; import dev.heliosares.auxprotect.core.APPermission; @@ -13,6 +7,8 @@ import dev.heliosares.auxprotect.core.IAuxProtect; import dev.heliosares.auxprotect.core.Language; import dev.heliosares.auxprotect.core.PlatformType; +import java.util.*; + public class EntryAction { private static final HashMap values = new HashMap<>(); private static final Set usedids = new HashSet<>(); @@ -98,7 +94,7 @@ public class EntryAction { public static final EntryAction TOWNDELETE = new EntryAction("towndelete", 1312); public static final EntryAction TOWNJOIN = new EntryAction("townjoin", 1313, 1314); public static final EntryAction TOWNCLAIM = new EntryAction("townclaim", 1315, 1316); -// public static final EntryAction TOWNMERGE = new EntryAction("townmerge", 1317); + // public static final EntryAction TOWNMERGE = new EntryAction("townmerge", 1317); public static final EntryAction TOWNMAYOR = new EntryAction("townmayor", 1318); public static final EntryAction TOWNBANK = new EntryAction("townbank", 1319, 1320); @@ -144,12 +140,6 @@ public class EntryAction { values.put(name, this); } - private void validateID(String name, int id) throws IllegalArgumentException { - if (!usedids.add(id)) { - throw new IllegalArgumentException("Duplicate entry id: " + id + " from action: " + name); - } - } - protected EntryAction(String key, int nid, int pid, String ntext, String ptext) { this(key, nid, pid); this.overrideNText = ntext; @@ -161,6 +151,31 @@ public class EntryAction { this.overrideNText = text; } + public static Collection values() { + return Collections.unmodifiableCollection(values.values()); + } + + public static EntryAction getAction(String key) { + return values.get(key); + } + + public static EntryAction getAction(int id) { + if (id == 0) + return null; + for (EntryAction action : values.values()) { + if (action.id == id || action.idPos == id) { + return action; + } + } + return null; + } + + private void validateID(String name, int id) throws IllegalArgumentException { + if (!usedids.add(id)) { + throw new IllegalArgumentException("Duplicate entry id: " + id + " from action: " + name); + } + } + public String getText(boolean state) { if (hasDual) { if (state) { @@ -281,25 +296,6 @@ public class EntryAction { this.lowestpriority = lowestpriority; } - public static Collection values() { - return Collections.unmodifiableCollection(values.values()); - } - - public static EntryAction getAction(String key) { - return values.get(key); - } - - public static EntryAction getAction(int id) { - if (id == 0) - return null; - for (EntryAction action : values.values()) { - if (action.id == id || action.idPos == id) { - return action; - } - } - return null; - } - public String getNode() { return APPermission.LOOKUP_ACTION.dot(toString().toLowerCase()).node; } diff --git a/src/dev/heliosares/auxprotect/database/InvDiffManager.java b/src/dev/heliosares/auxprotect/database/InvDiffManager.java index 2e2143f..687798d 100644 --- a/src/dev/heliosares/auxprotect/database/InvDiffManager.java +++ b/src/dev/heliosares/auxprotect/database/InvDiffManager.java @@ -7,7 +7,6 @@ import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.Damageable; import java.io.IOException; -import java.io.InputStream; import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; diff --git a/src/dev/heliosares/auxprotect/database/MigrationManager.java b/src/dev/heliosares/auxprotect/database/MigrationManager.java index 7266fc7..d3d86dc 100644 --- a/src/dev/heliosares/auxprotect/database/MigrationManager.java +++ b/src/dev/heliosares/auxprotect/database/MigrationManager.java @@ -15,31 +15,14 @@ public class MigrationManager { private final SQLManager sql; private final Connection connection; private final IAuxProtect plugin; + private final Map migrationActions; private boolean isMigrating; private int version; private int originalVersion; private int complete; private int total; - private int migratingToVersion; - public int getComplete() { - return complete; - } - - public int getTotal() { - return total; - } - - public String getProgressString() { - if (!isMigrating()) return null; - if (migratingToVersion <= 0) return null; - int progressPercentage = (int) Math.floor((double) getComplete() / getTotal() * 100); - return String.format("Migration to v%d %d%% complete. (%d/%d). DO NOT INTERRUPT", migratingToVersion, progressPercentage, getComplete(), getTotal()); - } - - private final Map migrationActions; - MigrationManager(SQLManager sql, Connection connection, IAuxProtect plugin) { this.sql = sql; this.plugin = plugin; @@ -392,23 +375,35 @@ public class MigrationManager { } } + public int getComplete() { + return complete; + } + + public int getTotal() { + return total; + } + + public String getProgressString() { + if (!isMigrating()) return null; + if (migratingToVersion <= 0) return null; + int progressPercentage = (int) Math.floor((double) getComplete() / getTotal() * 100); + return String.format("Migration to v%d %d%% complete. (%d/%d). DO NOT INTERRUPT", migratingToVersion, progressPercentage, getComplete(), getTotal()); + } + public int getOriginalVersion() { return originalVersion; } - @FunctionalInterface - interface MigrateRunnable { - void run() throws SQLException; - } - - private record MigrationAction(boolean backup, boolean necessary, @Nullable MigrateRunnable preTableAction, - @Nullable MigrateRunnable postTableAction) { - } - public int getVersion() { return version; } + private void setVersion(int version) throws SQLException { + sql.execute(connection, "INSERT INTO " + Table.AUXPROTECT_VERSION + " (time,version) VALUES (" + + System.currentTimeMillis() + "," + (this.version = version) + ")"); + plugin.info("Done migrating to version " + version); + } + boolean isMigrating() { return isMigrating; } @@ -581,13 +576,6 @@ public class MigrationManager { } } - - private void setVersion(int version) throws SQLException { - sql.execute(connection, "INSERT INTO " + Table.AUXPROTECT_VERSION + " (time,version) VALUES (" - + System.currentTimeMillis() + "," + (this.version = version) + ")"); - plugin.info("Done migrating to version " + version); - } - private void tryExecute(String stmt) { try { sql.execute(connection, stmt); @@ -596,4 +584,14 @@ public class MigrationManager { plugin.print(e); } } + + + @FunctionalInterface + interface MigrateRunnable { + void run() throws SQLException; + } + + private record MigrationAction(boolean backup, boolean necessary, @Nullable MigrateRunnable preTableAction, + @Nullable MigrateRunnable postTableAction) { + } } diff --git a/src/dev/heliosares/auxprotect/database/Results.java b/src/dev/heliosares/auxprotect/database/Results.java index a5f70eb..edfe884 100644 --- a/src/dev/heliosares/auxprotect/database/Results.java +++ b/src/dev/heliosares/auxprotect/database/Results.java @@ -9,14 +9,12 @@ import dev.heliosares.auxprotect.core.Parameters.Flag; import dev.heliosares.auxprotect.spigot.AuxProtectSpigot; import dev.heliosares.auxprotect.spigot.VeinManager; import dev.heliosares.auxprotect.utils.InvSerialization; -import dev.heliosares.auxprotect.utils.PosEncoder; import dev.heliosares.auxprotect.utils.TimeUtil; import net.md_5.bungee.api.chat.ClickEvent; import net.md_5.bungee.api.chat.ComponentBuilder; import net.md_5.bungee.api.chat.HoverEvent; import net.md_5.bungee.api.chat.hover.content.Text; -import java.io.IOException; import java.sql.SQLException; import java.time.Instant; import java.time.ZoneId; diff --git a/src/dev/heliosares/auxprotect/database/SQLManager.java b/src/dev/heliosares/auxprotect/database/SQLManager.java index ae022ea..c990e9c 100644 --- a/src/dev/heliosares/auxprotect/database/SQLManager.java +++ b/src/dev/heliosares/auxprotect/database/SQLManager.java @@ -75,6 +75,32 @@ public class SQLManager { return tablePrefix; } + public static String sanitize(String str) { + StringBuilder out = new StringBuilder(); + for (char c : str.toCharArray()) { + if (c > 126) c = '?'; + out.append(c); + } + return out.toString(); + } + + public static String getBlobSize(double bytes) { + int oom = 0; + while (bytes > 1024) { + bytes /= 1024; + oom++; + } + String out = switch (oom) { + case 0 -> "B"; + case 1 -> "KB"; + case 2 -> "MB"; + case 3 -> "GB"; + case 4 -> "TB"; + default -> ""; + }; + return (Math.round(bytes * 100.0) / 100.0) + " " + out; + } + public SQLUserManager getUserManager() { return usermanager; } @@ -425,7 +451,7 @@ public class SQLManager { /** * @see PreparedStatement#execute() */ - public boolean executeWrite(String stmt, Object... args) throws SQLException, BusyException { + public boolean executeWrite(String stmt, Object... args) throws SQLException { plugin.debug(stmt, 5); Connection connection = conn.getWriteConnection(30000); try { @@ -449,7 +475,7 @@ public class SQLManager { /** * @see PreparedStatement#executeUpdate() */ - public int executeWriteReturnRows(String stmt, Object... args) throws SQLException, BusyException { + public int executeWriteReturnRows(String stmt, Object... args) throws SQLException { plugin.debug(stmt, 5); Connection connection = conn.getWriteConnection(30000); try (PreparedStatement pstmt = connection.prepareStatement(stmt)) { @@ -558,15 +584,6 @@ public class SQLManager { return conn.getPoolSize(); } - public static String sanitize(String str) { - StringBuilder out = new StringBuilder(); - for (char c : str.toCharArray()) { - if (c > 126) c = '?'; - out.append(c); - } - return out.toString(); - } - protected boolean put(Connection connection, Table table) throws SQLException, IOException { long start = System.nanoTime(); int count; @@ -676,23 +693,6 @@ public class SQLManager { return true; } - public static String getBlobSize(double bytes) { - int oom = 0; - while (bytes > 1024) { - bytes /= 1024; - oom++; - } - String out = switch (oom) { - case 0 -> "B"; - case 1 -> "KB"; - case 2 -> "MB"; - case 3 -> "GB"; - case 4 -> "TB"; - default -> ""; - }; - return (Math.round(bytes * 100.0) / 100.0) + " " + out; - } - public int purge(Table table, long time) throws SQLException { if (!isConnected) return 0; @@ -940,7 +940,7 @@ public class SQLManager { entryHash.put(entry.getTime(), entry); } if (table == null) return; - stmt = new StringBuilder(String.format(stmt.substring(0, stmt.length() - 1), table.toString()) + ")"); + stmt = new StringBuilder(String.format(stmt.substring(0, stmt.length() - 1), table) + ")"); Connection connection = getConnection(false); try (PreparedStatement pstmt = connection.prepareStatement(stmt.toString())) { try (ResultSet rs = pstmt.executeQuery()) { @@ -1011,16 +1011,6 @@ public class SQLManager { } } - public static enum LastKeys { - AUTO_PURGE(1), VACUUM(2), TELEMETRY(3); - - LastKeys(int id) { - this.id = (short) id; - } - - public final short id; - } - //TODO implement public void setLast(LastKeys key, long value) throws SQLException { executeWrite("UPDATE " + Table.AUXPROTECT_LASTS + " SET value=? WHERE `key`=?", value, key.id); @@ -1044,4 +1034,14 @@ public class SQLManager { if (migrationmanager == null) return null; return migrationmanager.getProgressString(); } + + public enum LastKeys { + AUTO_PURGE(1), VACUUM(2), TELEMETRY(3); + + public final short id; + + LastKeys(int id) { + this.id = (short) id; + } + } } diff --git a/src/dev/heliosares/auxprotect/exceptions/AuxProtectException.java b/src/dev/heliosares/auxprotect/exceptions/AuxProtectException.java index d2aa599..ab0e65d 100644 --- a/src/dev/heliosares/auxprotect/exceptions/AuxProtectException.java +++ b/src/dev/heliosares/auxprotect/exceptions/AuxProtectException.java @@ -10,6 +10,7 @@ public class AuxProtectException extends Exception { private static final long serialVersionUID = 8845413629243613163L; private final L l; private final List format; + public AuxProtectException(L l, Object... format) { super(l.translate(format)); this.l = l; diff --git a/src/dev/heliosares/auxprotect/spigot/AuxProtectSpigot.java b/src/dev/heliosares/auxprotect/spigot/AuxProtectSpigot.java index bc6c882..dc2e6b1 100644 --- a/src/dev/heliosares/auxprotect/spigot/AuxProtectSpigot.java +++ b/src/dev/heliosares/auxprotect/spigot/AuxProtectSpigot.java @@ -48,6 +48,7 @@ public class AuxProtectSpigot extends JavaPlugin implements IAuxProtect { private static SQLManager sqlManager; private final APConfig config = new APConfig(); private final Set hooks = new HashSet<>(); + private final HashMap apPlayers = new HashMap<>(); public String update; protected DatabaseRunnable dbRunnable; long lastCheckedForUpdate; @@ -57,7 +58,6 @@ public class AuxProtectSpigot extends JavaPlugin implements IAuxProtect { private ClaimInvCommand claiminvcommand; private APSCommand apcommand; private int SERVER_VERSION; - private final HashMap apPlayers = new HashMap<>(); private boolean isShuttingDown; private String stackLog = ""; diff --git a/src/dev/heliosares/auxprotect/spigot/VeinManager.java b/src/dev/heliosares/auxprotect/spigot/VeinManager.java index 0a17a53..e2fdbcb 100644 --- a/src/dev/heliosares/auxprotect/spigot/VeinManager.java +++ b/src/dev/heliosares/auxprotect/spigot/VeinManager.java @@ -9,9 +9,9 @@ import java.util.HashMap; import java.util.UUID; public class VeinManager { - private ArrayList entries = new ArrayList<>(); - private ArrayList ignoredentries = new ArrayList<>(); - private HashMap> skipped = new HashMap<>(); + private final ArrayList entries = new ArrayList<>(); + private final ArrayList ignoredentries = new ArrayList<>(); + private final HashMap> skipped = new HashMap<>(); public static String getSeverityDescription(int severity) { switch (severity) {// TODO lang diff --git a/src/dev/heliosares/auxprotect/spigot/listeners/AuctionHouseListener.java b/src/dev/heliosares/auxprotect/spigot/listeners/AuctionHouseListener.java index 0627659..4383405 100644 --- a/src/dev/heliosares/auxprotect/spigot/listeners/AuctionHouseListener.java +++ b/src/dev/heliosares/auxprotect/spigot/listeners/AuctionHouseListener.java @@ -6,7 +6,6 @@ import dev.heliosares.auxprotect.database.DbEntry; import dev.heliosares.auxprotect.database.EntryAction; import dev.heliosares.auxprotect.database.SingleItemEntry; import dev.heliosares.auxprotect.spigot.AuxProtectSpigot; -import dev.heliosares.auxprotect.utils.InvSerialization; import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.World; @@ -34,7 +33,7 @@ public class AuctionHouseListener implements Listener { } } DbEntry entry = new SingleItemEntry("$" + e.getSeller_UUID(), EntryAction.AUCTIONLIST, false, l, - e.getItem().getType().toString().toLowerCase(), plugin.formatMoney(e.getPrice()),e.getItem()); + e.getItem().getType().toString().toLowerCase(), plugin.formatMoney(e.getPrice()), e.getItem()); plugin.add(entry); } diff --git a/src/dev/heliosares/auxprotect/spigot/listeners/CommandListener.java b/src/dev/heliosares/auxprotect/spigot/listeners/CommandListener.java index 772c0b2..4554a03 100644 --- a/src/dev/heliosares/auxprotect/spigot/listeners/CommandListener.java +++ b/src/dev/heliosares/auxprotect/spigot/listeners/CommandListener.java @@ -8,7 +8,7 @@ import org.bukkit.event.player.PlayerCommandPreprocessEvent; public class CommandListener implements Listener { - private AuxProtectSpigot plugin; + private final AuxProtectSpigot plugin; public CommandListener(AuxProtectSpigot plugin) { this.plugin = plugin; @@ -19,15 +19,13 @@ public class CommandListener implements Listener { if (!plugin.getAPConfig().isOverrideCommands()) { return; } - String args1[] = e.getMessage().substring(1).split(" "); + String[] args1 = e.getMessage().substring(1).split(" "); String label = args1[0]; boolean auxprotect = label.equalsIgnoreCase("auxprotect") || label.equalsIgnoreCase("ap"); boolean claiminv = label.equalsIgnoreCase("claiminv"); if (auxprotect || claiminv) { - String args[] = new String[args1.length - 1]; - for (int i = 0; i < args.length; i++) { - args[i] = args1[i + 1]; - } + String[] args = new String[args1.length - 1]; + System.arraycopy(args1, 1, args, 0, args.length); if (auxprotect) { plugin.getApcommand().onCommand(e.getPlayer(), null, label, args); } else if (claiminv) { diff --git a/src/dev/heliosares/auxprotect/spigot/listeners/EntityListener.java b/src/dev/heliosares/auxprotect/spigot/listeners/EntityListener.java index ed685e8..201f91d 100644 --- a/src/dev/heliosares/auxprotect/spigot/listeners/EntityListener.java +++ b/src/dev/heliosares/auxprotect/spigot/listeners/EntityListener.java @@ -33,7 +33,7 @@ import java.util.ArrayList; public class EntityListener implements Listener { ArrayList blacklistedDamageCauses; - private AuxProtectSpigot plugin; + private final AuxProtectSpigot plugin; public EntityListener(AuxProtectSpigot plugin) { this.plugin = plugin; @@ -52,8 +52,7 @@ public class EntityListener implements Listener { public static boolean isChartMap(ItemStack item) { if (item.getType() == Material.FILLED_MAP && item.hasItemMeta()) { - if (item.getItemMeta() instanceof MapMeta) { - MapMeta meta = (MapMeta) item.getItemMeta(); + if (item.getItemMeta() instanceof MapMeta meta) { for (MapRenderer renderer : meta.getMapView().getRenderers()) { if (renderer instanceof ChartRenderer) { return true; @@ -112,14 +111,13 @@ public class EntityListener implements Listener { return; } if (e.getEntity() instanceof LivingEntity) { - if (((LivingEntity) e.getEntity()).isDead()) { + if (e.getEntity().isDead()) { return; } } String itemname = ""; Entity source = e.getDamager(); - if (e.getDamager() instanceof Projectile) { - Projectile projectile = (Projectile) e.getDamager(); + if (e.getDamager() instanceof Projectile projectile) { ProjectileSource projsource = projectile.getShooter(); if (projsource instanceof LivingEntity) { source = (LivingEntity) projsource; @@ -130,8 +128,7 @@ public class EntityListener implements Listener { String targetName = AuxProtectSpigot.getLabel(e.getEntity()); String sourceName = source == null ? targetName : AuxProtectSpigot.getLabel(source); - if (source instanceof Player) { - Player sourcePl = (Player) source; + if (source instanceof Player sourcePl) { plugin.getAPPlayer(sourcePl).addActivity(0.25); itemname += sourcePl.getInventory().getItemInMainHand().getType().toString().toLowerCase(); } @@ -142,10 +139,9 @@ public class EntityListener implements Listener { itemname += (Math.round(e.getFinalDamage() * 10) / 10.0) + "HP"; EntryAction action = EntryAction.HURT; - if (e.getEntity() instanceof LivingEntity + if (e.getEntity() instanceof LivingEntity livingEntity && ((LivingEntity) e.getEntity()).getHealth() - e.getFinalDamage() <= 0) { boolean totem = false; - LivingEntity livingEntity = (LivingEntity) e.getEntity(); EntityEquipment equip = livingEntity.getEquipment(); if (equip != null) { ItemStack hand = equip.getItem(EquipmentSlot.HAND); @@ -184,7 +180,7 @@ public class EntityListener implements Listener { @Override public void run() { if (e.getEntity().isDead() || !e.getEntity().isValid()) { - itemBreak(plugin, "#" + e.getCause().toString(), item.getItemStack(), item.getLocation()); + itemBreak(plugin, "#" + e.getCause(), item.getItemStack(), item.getLocation()); } } }.runTaskLater(plugin, 1); @@ -206,7 +202,7 @@ public class EntityListener implements Listener { reason = EntryAction.KILL; } DbEntry entry = new DbEntry("#env", reason, false, e.getEntity().getLocation(), targetName, - e.getCause().toString() + ", " + (Math.round(e.getFinalDamage() * 10) / 10.0) + "HP"); + e.getCause() + ", " + (Math.round(e.getFinalDamage() * 10) / 10.0) + "HP"); plugin.add(entry); } @@ -250,8 +246,7 @@ public class EntityListener implements Listener { @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) public void onPickupEvent(EntityPickupItemEvent e) { - if (e.getEntity() instanceof Player) { - Player player = (Player) e.getEntity(); + if (e.getEntity() instanceof Player player) { plugin.getAPPlayer(player).addActivity(1); diff --git a/src/dev/heliosares/auxprotect/spigot/listeners/InventoryListener.java b/src/dev/heliosares/auxprotect/spigot/listeners/InventoryListener.java index 8bb07bc..a21ec4a 100644 --- a/src/dev/heliosares/auxprotect/spigot/listeners/InventoryListener.java +++ b/src/dev/heliosares/auxprotect/spigot/listeners/InventoryListener.java @@ -16,7 +16,7 @@ import org.bukkit.inventory.ItemStack; public class InventoryListener implements Listener { - private AuxProtectSpigot plugin; + private final AuxProtectSpigot plugin; public InventoryListener(AuxProtectSpigot plugin) { this.plugin = plugin; diff --git a/src/dev/heliosares/auxprotect/spigot/listeners/JobsListener.java b/src/dev/heliosares/auxprotect/spigot/listeners/JobsListener.java index 5e29240..3fad577 100644 --- a/src/dev/heliosares/auxprotect/spigot/listeners/JobsListener.java +++ b/src/dev/heliosares/auxprotect/spigot/listeners/JobsListener.java @@ -37,8 +37,7 @@ public class JobsListener implements Listener { } Location location = null; // double boost = 1; - if (oplayer instanceof Player) { - Player player = (Player) oplayer; + if (oplayer instanceof Player player) { location = player.getLocation(); // try { // boost += Jobs.getPlayerManager().getBoost(Jobs.getPlayerManager().getJobsPlayer(player), job, type); diff --git a/src/dev/heliosares/auxprotect/spigot/listeners/PaneListener.java b/src/dev/heliosares/auxprotect/spigot/listeners/PaneListener.java index 8be57a4..cf0d74f 100644 --- a/src/dev/heliosares/auxprotect/spigot/listeners/PaneListener.java +++ b/src/dev/heliosares/auxprotect/spigot/listeners/PaneListener.java @@ -12,7 +12,7 @@ import org.bukkit.event.inventory.InventoryCloseEvent; public class PaneListener implements Listener { @SuppressWarnings("unused") - private AuxProtectSpigot plugin; + private final AuxProtectSpigot plugin; public PaneListener(AuxProtectSpigot plugin) { this.plugin = plugin; diff --git a/src/dev/heliosares/auxprotect/spigot/listeners/PlayerListener.java b/src/dev/heliosares/auxprotect/spigot/listeners/PlayerListener.java index f47b1e3..f6732be 100644 --- a/src/dev/heliosares/auxprotect/spigot/listeners/PlayerListener.java +++ b/src/dev/heliosares/auxprotect/spigot/listeners/PlayerListener.java @@ -146,8 +146,7 @@ public class PlayerListener implements Listener { @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) public void onConsume(PlayerItemConsumeEvent e) { String sup = ""; - if (e.getItem().getType() == Material.POTION && e.getItem().getItemMeta() instanceof PotionMeta) { - PotionMeta pm = (PotionMeta) e.getItem().getItemMeta(); + if (e.getItem().getType() == Material.POTION && e.getItem().getItemMeta() instanceof PotionMeta pm) { sup = pm.getBasePotionData().getType().toString().toLowerCase(); } DbEntry entry = new DbEntry(AuxProtectSpigot.getLabel(e.getPlayer()), EntryAction.CONSUME, false, @@ -287,10 +286,9 @@ public class PlayerListener implements Listener { @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) public void onPlayerUnleashEntityEvent(PlayerUnleashEntityEvent e) { - if (!(e.getEntity() instanceof LivingEntity)) { + if (!(e.getEntity() instanceof LivingEntity entity)) { return; } - LivingEntity entity = (LivingEntity) e.getEntity(); if (!entity.isLeashed()) { return; } @@ -320,7 +318,6 @@ public class PlayerListener implements Listener { public void onChat(AsyncPlayerChatEvent e) { plugin.getAPPlayer(e.getPlayer()).addActivity(5); if (e.isCancelled()) { - return; } } } diff --git a/src/dev/heliosares/auxprotect/spigot/listeners/ProjectileListener.java b/src/dev/heliosares/auxprotect/spigot/listeners/ProjectileListener.java index 4ff8b15..a5ca61b 100644 --- a/src/dev/heliosares/auxprotect/spigot/listeners/ProjectileListener.java +++ b/src/dev/heliosares/auxprotect/spigot/listeners/ProjectileListener.java @@ -4,8 +4,10 @@ import dev.heliosares.auxprotect.database.DbEntry; import dev.heliosares.auxprotect.database.EntryAction; import dev.heliosares.auxprotect.database.SingleItemEntry; import dev.heliosares.auxprotect.spigot.AuxProtectSpigot; -import org.bukkit.Location; -import org.bukkit.entity.*; +import org.bukkit.entity.EntityType; +import org.bukkit.entity.LivingEntity; +import org.bukkit.entity.Projectile; +import org.bukkit.entity.ThrowableProjectile; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; import org.bukkit.event.Listener; @@ -20,7 +22,7 @@ import java.util.ArrayList; public class ProjectileListener implements Listener { ArrayList whitelist; - private AuxProtectSpigot plugin; + private final AuxProtectSpigot plugin; public ProjectileListener(AuxProtectSpigot plugin) { this.plugin = plugin; diff --git a/src/dev/heliosares/auxprotect/spigot/listeners/VeinListener.java b/src/dev/heliosares/auxprotect/spigot/listeners/VeinListener.java index 6920e63..c4917ed 100644 --- a/src/dev/heliosares/auxprotect/spigot/listeners/VeinListener.java +++ b/src/dev/heliosares/auxprotect/spigot/listeners/VeinListener.java @@ -31,7 +31,7 @@ public class VeinListener implements Listener { private static final int ORE_RADIUS = 5; private static final int NON_ORE_THRESHOLD = 2; PerPlayerManager blockhistory = new PerPlayerManager<>(() -> new BlockHistory()); - private AuxProtectSpigot plugin; + private final AuxProtectSpigot plugin; public VeinListener(AuxProtectSpigot plugin) { this.plugin = plugin; diff --git a/src/dev/heliosares/auxprotect/spigot/listeners/WorldListener.java b/src/dev/heliosares/auxprotect/spigot/listeners/WorldListener.java index 36ae73d..a30039a 100644 --- a/src/dev/heliosares/auxprotect/spigot/listeners/WorldListener.java +++ b/src/dev/heliosares/auxprotect/spigot/listeners/WorldListener.java @@ -14,7 +14,7 @@ import org.bukkit.event.weather.LightningStrikeEvent; public class WorldListener implements Listener { - private AuxProtectSpigot plugin; + private final AuxProtectSpigot plugin; public WorldListener(AuxProtectSpigot plugin) { this.plugin = plugin; diff --git a/src/dev/heliosares/auxprotect/towny/TownyManager.java b/src/dev/heliosares/auxprotect/towny/TownyManager.java index 9951ff5..6a4eebc 100644 --- a/src/dev/heliosares/auxprotect/towny/TownyManager.java +++ b/src/dev/heliosares/auxprotect/towny/TownyManager.java @@ -17,7 +17,7 @@ import java.util.UUID; public class TownyManager { private final AuxProtectSpigot plugin; private final SQLManager sql; - private BidiMapCache names = new BidiMapCache<>(300000L, 300000L, true); + private final BidiMapCache names = new BidiMapCache<>(300000L, 300000L, true); public TownyManager(AuxProtectSpigot plugin, SQLManager sql) { this.plugin = plugin; @@ -54,7 +54,7 @@ public class TownyManager { * null) { usernames.put(uuid, player.getName()); return player.getName */ - String stmt = "SELECT * FROM " + Table.AUXPROTECT_LONGTERM.toString() + String stmt = "SELECT * FROM " + Table.AUXPROTECT_LONGTERM + " WHERE action_id=? AND uid=?\nORDER BY time DESC\nLIMIT 1;"; plugin.debug(stmt, 3); @@ -133,7 +133,7 @@ public class TownyManager { * null) { usernames.put(uuid, player.getName()); return player.getName */ - String stmt = "SELECT * FROM " + Table.AUXPROTECT_LONGTERM.toString() + String stmt = "SELECT * FROM " + Table.AUXPROTECT_LONGTERM + " WHERE action_id=? AND target=?\nORDER BY time DESC\nLIMIT 1;"; plugin.debug(stmt, 3); diff --git a/src/dev/heliosares/auxprotect/utils/BidiMap.java b/src/dev/heliosares/auxprotect/utils/BidiMap.java index b85d302..f320acc 100644 --- a/src/dev/heliosares/auxprotect/utils/BidiMap.java +++ b/src/dev/heliosares/auxprotect/utils/BidiMap.java @@ -6,8 +6,9 @@ import java.util.Set; public class BidiMap { - private HashMap set; - private HashMap reverse; + private final HashMap set; + private final HashMap reverse; + public BidiMap() { set = new HashMap<>(); reverse = new HashMap<>(); diff --git a/src/dev/heliosares/auxprotect/utils/BidiMapCache.java b/src/dev/heliosares/auxprotect/utils/BidiMapCache.java index d9ffe83..7421161 100644 --- a/src/dev/heliosares/auxprotect/utils/BidiMapCache.java +++ b/src/dev/heliosares/auxprotect/utils/BidiMapCache.java @@ -11,10 +11,11 @@ public class BidiMapCache { private final long timeToLive; private final long cleanupInterval; private final boolean updateWhenAccessed; - private HashMap set; - private HashMap reverse; - private HashMap timeAdded; + private final HashMap set; + private final HashMap reverse; + private final HashMap timeAdded; private long lastCleanup; + public BidiMapCache(long timeToLive, long cleanupInterval, boolean updateWhenAccessed) { set = new HashMap<>(); reverse = new HashMap<>(); diff --git a/src/dev/heliosares/auxprotect/utils/ChartRenderer.java b/src/dev/heliosares/auxprotect/utils/ChartRenderer.java index 267ffbc..d6394fa 100644 --- a/src/dev/heliosares/auxprotect/utils/ChartRenderer.java +++ b/src/dev/heliosares/auxprotect/utils/ChartRenderer.java @@ -16,14 +16,14 @@ public class ChartRenderer extends MapRenderer { public static final int yShift = 12; public static final int xSize = 100; public static final int ySize = 100; - private final double values[]; + private final double[] values; private final Color bgColor; private final String title; private final int xDivs; @SuppressWarnings("unused") private final String[] xLabels; -// public static final byte BLUE = 0x30; + // public static final byte BLUE = 0x30; // public static final byte BROWN = 0x28; // public static final byte DARK_BROWN = 0x34; // public static final byte DARK_GRAY = 0x2c; @@ -41,7 +41,7 @@ public class ChartRenderer extends MapRenderer { private final AuxProtectSpigot plugin; public double xScale = 1; public double yScale = 1; - private Color[][] map = new Color[128][128]; + private final Color[][] map = new Color[128][128]; public ChartRenderer(AuxProtectSpigot plugin, String title, Color bgColor, int values) { this.plugin = plugin; @@ -162,8 +162,7 @@ public class ChartRenderer extends MapRenderer { view.removeRenderer(renderer); view.addRenderer(this); ItemStack i = new ItemStack(Material.FILLED_MAP, 1); - if (i.getItemMeta() instanceof MapMeta) { - MapMeta meta = ((MapMeta) i.getItemMeta()); + if (i.getItemMeta() instanceof MapMeta meta) { meta.setMapView(view); i.setItemMeta(meta); } else { diff --git a/src/dev/heliosares/auxprotect/utils/HasteBinAPI.java b/src/dev/heliosares/auxprotect/utils/HasteBinAPI.java index 897b6ff..a6fe1a5 100644 --- a/src/dev/heliosares/auxprotect/utils/HasteBinAPI.java +++ b/src/dev/heliosares/auxprotect/utils/HasteBinAPI.java @@ -14,6 +14,7 @@ import java.util.stream.Collectors; public class HasteBinAPI { // Partial credit to mfnalex - https://www.spigotmc.org/threads/how-to-use-the-pastebin-api-in-java.500953/ + /** * hastebin is blocking pastes for some reason, using files only for now. */ @@ -30,7 +31,7 @@ public class HasteBinAPI { http.setDoOutput(true); http.setDoInput(true); - byte[] out = post.toString().getBytes(StandardCharsets.UTF_8); + byte[] out = post.getBytes(StandardCharsets.UTF_8); int length = out.length; http.setFixedLengthStreamingMode(length); http.setRequestProperty("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8"); diff --git a/src/dev/heliosares/auxprotect/utils/InvSerialization.java b/src/dev/heliosares/auxprotect/utils/InvSerialization.java index 1677083..4a6dfd1 100644 --- a/src/dev/heliosares/auxprotect/utils/InvSerialization.java +++ b/src/dev/heliosares/auxprotect/utils/InvSerialization.java @@ -46,6 +46,7 @@ public class InvSerialization { return byteArrayOutputStream.toByteArray(); } } + public static ItemStack[] toItemStackArray(byte[] bytes) throws ClassNotFoundException, IOException { if (bytes == null) { return null; diff --git a/src/dev/heliosares/auxprotect/utils/KeyUtil.java b/src/dev/heliosares/auxprotect/utils/KeyUtil.java index d136745..183c39c 100644 --- a/src/dev/heliosares/auxprotect/utils/KeyUtil.java +++ b/src/dev/heliosares/auxprotect/utils/KeyUtil.java @@ -31,6 +31,7 @@ public class KeyUtil { private final boolean isMalformed; private final boolean isPrivate; private final String keyholder; + public KeyUtil(String key) { boolean isValid = false; boolean isBlacklisted = false; diff --git a/src/dev/heliosares/auxprotect/utils/MoneySolver.java b/src/dev/heliosares/auxprotect/utils/MoneySolver.java index 3330bf0..6f9ec6c 100644 --- a/src/dev/heliosares/auxprotect/utils/MoneySolver.java +++ b/src/dev/heliosares/auxprotect/utils/MoneySolver.java @@ -21,8 +21,8 @@ import java.util.stream.Collectors; import java.util.stream.IntStream; public class MoneySolver extends ChartRenderer { - private double[] values = new double[100]; - private List xDivs; + private final double[] values = new double[100]; + private final List xDivs; private MoneySolver(AuxProtectSpigot plugin, Player player, List results, int time, String user) throws IllegalArgumentException { diff --git a/src/dev/heliosares/auxprotect/utils/Pane.java b/src/dev/heliosares/auxprotect/utils/Pane.java index a06a008..bacd98c 100644 --- a/src/dev/heliosares/auxprotect/utils/Pane.java +++ b/src/dev/heliosares/auxprotect/utils/Pane.java @@ -8,6 +8,7 @@ import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.ItemMeta; import java.util.ArrayList; +import java.util.Collections; import java.util.List; import java.util.function.Consumer; @@ -17,7 +18,7 @@ public class Pane implements InventoryHolder { private final Player player; private Inventory inventory; private ArrayList