Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bug fixes #4

Merged
merged 3 commits into from
Oct 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/defaults.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
maxBankDataSize: 1000000
overloadedWarningMessage: "&cAttempted to exceed bank storage size. Contact a staff member for more information."
worlds:
- survival3
16 changes: 15 additions & 1 deletion src/no/runsafe/runsafebank/BankHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -56,6 +57,7 @@ private void loadBank(IPlayer owner)
private void saveLoadedBanks()
{
List<IPlayer> oldBanks = new ArrayList<>();
List<IPlayer> suspiciousBanks = new ArrayList<>();
for (Map.Entry<IPlayer, RunsafeInventory> bank : this.loadedBanks.entrySet())
{
RunsafeInventory bankInventory = bank.getValue();
Expand All @@ -67,7 +69,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;
}

Expand All @@ -79,6 +85,13 @@ private void saveLoadedBanks()
oldBanks.add(bankOwner);
}

for (IPlayer suspect: suspiciousBanks)
{
suspect.sendColouredMessage(overloadedWarningMessage);
suspect.closeInventory();
loadedBanks.remove(suspect);
}

for (IPlayer owner: oldBanks)
{
this.loadedBanks.remove(owner);
Expand Down Expand Up @@ -106,6 +119,7 @@ public void OnPluginDisabled()
this.saveLoadedBanks();
}

private String overloadedWarningMessage;
private int maxBankDataSize;
private final ConcurrentHashMap<IPlayer, RunsafeInventory> loadedBanks = new ConcurrentHashMap<>();
private final BankRepository bankRepository;
Expand Down
2 changes: 2 additions & 0 deletions src/no/runsafe/runsafebank/Plugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -17,6 +18,7 @@ protected void pluginSetup()
addComponent(Commands.class);
addComponent(Events.class);
addComponent(Database.class);
addComponent(Configuration.class);

// Plugin components
addComponent(Interact.class);
Expand Down