From 4388d360e5b0964111285f97691438f3052ab16d Mon Sep 17 00:00:00 2001 From: DevDeborah Date: Fri, 20 Oct 2023 12:26:11 -0400 Subject: [PATCH 1/3] kick bank user out when exceeding bank data size should hopefully prevent undefined behavior and item dupe bugs. a theoretical example of how a duplication glitch could happen with previous behavior: fill bank up with diamonds and have it be under the max data size, overload the data size so it can't save, take out the diamonds, exit bank and enter again, bank did not save so diamonds should be there again. --- src/no/runsafe/runsafebank/BankHandler.java | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/no/runsafe/runsafebank/BankHandler.java b/src/no/runsafe/runsafebank/BankHandler.java index fc02594..cd7972e 100644 --- a/src/no/runsafe/runsafebank/BankHandler.java +++ b/src/no/runsafe/runsafebank/BankHandler.java @@ -56,6 +56,7 @@ private void loadBank(IPlayer owner) private void saveLoadedBanks() { List oldBanks = new ArrayList<>(); + List suspiciousBanks = new ArrayList<>(); for (Map.Entry bank : this.loadedBanks.entrySet()) { RunsafeInventory bankInventory = bank.getValue(); @@ -67,7 +68,11 @@ private void saveLoadedBanks() "Player attempted to exceed size limit of bank. Player: " + bankOwner.getName() + " Size: " + bankDataSize ); - this.debugger.debugFine("Bank inv size too big. Could not save bank for: " + bankOwner.getName()); + this.debugger.debugFine( + "Bank inv size too big. Could not save bank for: " + bankOwner.getName() + + " Size: " + bankDataSize + ); + suspiciousBanks.add(bankOwner); continue; } @@ -79,6 +84,13 @@ private void saveLoadedBanks() oldBanks.add(bankOwner); } + for (IPlayer suspect: suspiciousBanks) + { + suspect.sendColouredMessage("&cAttempted to exceed bank storage size. Contact a staff member for more information."); + suspect.closeInventory(); + loadedBanks.remove(suspect); + } + for (IPlayer owner: oldBanks) { this.loadedBanks.remove(owner); From 037d6ba92623283767ef4b0b4b28af47a04e310f Mon Sep 17 00:00:00 2001 From: DevDeborah Date: Fri, 20 Oct 2023 12:29:40 -0400 Subject: [PATCH 2/3] add ability to read config file --- src/no/runsafe/runsafebank/Plugin.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/no/runsafe/runsafebank/Plugin.java b/src/no/runsafe/runsafebank/Plugin.java index d61ad9d..ef47127 100644 --- a/src/no/runsafe/runsafebank/Plugin.java +++ b/src/no/runsafe/runsafebank/Plugin.java @@ -2,6 +2,7 @@ import no.runsafe.framework.RunsafePlugin; import no.runsafe.framework.features.Commands; +import no.runsafe.framework.features.Configuration; import no.runsafe.framework.features.Database; import no.runsafe.framework.features.Events; import no.runsafe.runsafebank.commands.ViewBank; @@ -17,6 +18,7 @@ protected void pluginSetup() addComponent(Commands.class); addComponent(Events.class); addComponent(Database.class); + addComponent(Configuration.class); // Plugin components addComponent(Interact.class); From 3cd0b25fe46b705a797e4d33af9d7d0c27b4beef Mon Sep 17 00:00:00 2001 From: DevDeborah Date: Fri, 20 Oct 2023 12:35:09 -0400 Subject: [PATCH 3/3] Move warning message to config --- src/defaults.yml | 1 + src/no/runsafe/runsafebank/BankHandler.java | 4 +++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/defaults.yml b/src/defaults.yml index e8af8ed..7f8a012 100644 --- a/src/defaults.yml +++ b/src/defaults.yml @@ -1,3 +1,4 @@ maxBankDataSize: 1000000 +overloadedWarningMessage: "&cAttempted to exceed bank storage size. Contact a staff member for more information." worlds: - survival3 \ No newline at end of file diff --git a/src/no/runsafe/runsafebank/BankHandler.java b/src/no/runsafe/runsafebank/BankHandler.java index cd7972e..67ce272 100644 --- a/src/no/runsafe/runsafebank/BankHandler.java +++ b/src/no/runsafe/runsafebank/BankHandler.java @@ -29,6 +29,7 @@ public BankHandler(BankRepository bankRepository, IDebug output, IScheduler sche public void OnConfigurationChanged(IConfiguration config) { this.maxBankDataSize = config.getConfigValueAsInt("maxBankDataSize"); + this.overloadedWarningMessage = config.getConfigValueAsString("overloadedWarningMessage"); } public void openBank(IPlayer viewer, IPlayer owner) @@ -86,7 +87,7 @@ private void saveLoadedBanks() for (IPlayer suspect: suspiciousBanks) { - suspect.sendColouredMessage("&cAttempted to exceed bank storage size. Contact a staff member for more information."); + suspect.sendColouredMessage(overloadedWarningMessage); suspect.closeInventory(); loadedBanks.remove(suspect); } @@ -118,6 +119,7 @@ public void OnPluginDisabled() this.saveLoadedBanks(); } + private String overloadedWarningMessage; private int maxBankDataSize; private final ConcurrentHashMap loadedBanks = new ConcurrentHashMap<>(); private final BankRepository bankRepository;