Skip to content

Commit

Permalink
Bug fixes and feature additions
Browse files Browse the repository at this point in the history
- Removed permissions related to bank info, as all bank info should be public
- Various tweaks and code cleanup
- Bank volume limits are now carried in long values for safety
- Rehashed class structure of Guis (added new abstract superclasses SinglePageGui and MultiPageGui) for better polymorphism and inheritance
- Hopefully Gui icon lore will now always be gray by default
- Fixed error in Gui generics that prevented type safety
- Added enum value GuiType.ACCOUNT_SHULKER_CONTENTS
- Cleaned up and added some assertions to BankUtils
- Tweaked message
- Reworded some permission descriptions, added notes, changed defaults
  • Loading branch information
monst committed Aug 16, 2020
1 parent 546bde2 commit 9376afb
Show file tree
Hide file tree
Showing 21 changed files with 210 additions and 209 deletions.
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>com.monst</groupId>
<artifactId>BankingPlugin</artifactId>
<version>1.11.8-SNAPSHOT</version>
<version>1.12.0-SNAPSHOT</version>

<name>BankingPlugin</name>
<description>Create bank accounts in bank vault chests and earn interest on your investments!</description>
Expand Down Expand Up @@ -84,7 +84,7 @@
<dependency>
<groupId>com.sk89q.worldedit</groupId>
<artifactId>worldedit-bukkit</artifactId>
<version>7.1.0</version>
<version>7.2.0-SNAPSHOT</version>
<scope>provided</scope>
<exclusions>
<exclusion>
Expand Down
23 changes: 8 additions & 15 deletions src/main/java/com/monst/bankingplugin/Bank.java
Original file line number Diff line number Diff line change
Expand Up @@ -293,10 +293,7 @@ public TextComponent getInfoButton(CommandSender sender) {
@Override
public TextComponent getInformation(CommandSender sender) {
boolean isOwner = sender instanceof Player && isOwner((Player) sender);
boolean verbose = (sender instanceof Player && isTrusted((Player) sender))
|| (getType() == BankType.PLAYER && sender.hasPermission(Permissions.BANK_INFO_OTHER)
|| (getType() == BankType.ADMIN && sender.hasPermission(Permissions.BANK_INFO_ADMIN)));


TextComponent info = new TextComponent();
info.setColor(net.md_5.bungee.api.ChatColor.GRAY);

Expand All @@ -312,17 +309,13 @@ public TextComponent getInformation(CommandSender sender) {
info.addExtra("\n Offline payouts: " + ChatColor.AQUA + accountConfig.get(AccountConfig.Field.ALLOWED_OFFLINE_PAYOUTS));
info.addExtra(" (" + ChatColor.AQUA + accountConfig.get(AccountConfig.Field.ALLOWED_OFFLINE_PAYOUTS_BEFORE_RESET) + ChatColor.GRAY + " before multiplier reset)");
info.addExtra("\n Initial payout delay: " + ChatColor.AQUA + accountConfig.get(AccountConfig.Field.INITIAL_INTEREST_DELAY));
double minBal = accountConfig.get(AccountConfig.Field.MINIMUM_BALANCE);
info.addExtra("\n Minimum balance: " + ChatColor.GREEN + "$" + Utils.format(minBal));
if (minBal != 0)
info.addExtra(" (" + ChatColor.RED + "$" + accountConfig.getFormatted(AccountConfig.Field.LOW_BALANCE_FEE) + ChatColor.GRAY + " fee)");
if (verbose) {
info.addExtra("\n Accounts: " + ChatColor.AQUA + accounts.size());
info.addExtra("\n Total value: " + ChatColor.GREEN + "$" + Utils.format(getTotalValue()));
info.addExtra("\n Average account value: " + ChatColor.GREEN + "$" + Utils.format(getTotalValue().doubleValue() / accounts.size()));
info.addExtra("\n Equality score: ");
info.addExtra(BankUtils.getEqualityLore(this));
}
info.addExtra("\n Minimum balance: " + ChatColor.GREEN + "$" + Utils.format((double) accountConfig.get(AccountConfig.Field.MINIMUM_BALANCE)));
info.addExtra(" (" + ChatColor.RED + "$" + accountConfig.getFormatted(AccountConfig.Field.LOW_BALANCE_FEE) + ChatColor.GRAY + " fee)");
info.addExtra("\n Accounts: " + ChatColor.AQUA + accounts.size());
info.addExtra("\n Total value: " + ChatColor.GREEN + "$" + Utils.format(getTotalValue()));
info.addExtra("\n Average account value: " + ChatColor.GREEN + "$" + Utils.format(getTotalValue().doubleValue() / accounts.size()));
info.addExtra("\n Equality score: ");
info.addExtra(BankUtils.getEqualityLore(this));
info.addExtra("\n Location: " + ChatColor.AQUA + getSelection().getCoordinates());

return info;
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/com/monst/bankingplugin/BankingPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public void onLoad() {

worldGuard = Bukkit.getServer().getPluginManager().getPlugin("WorldGuard");
if (worldGuard != null) {
WorldGuardBankingFlag.register(this); // Throws class error with worldedit:World.class
WorldGuardBankingFlag.register(this);
}
}

Expand Down Expand Up @@ -176,7 +176,7 @@ public void onDisable() {

for (Bank bank : bankUtils.getBanksCopy()) {
bankUtils.removeBank(bank, false);
debug("Removed bank (\"" + bank.getName() + "\" (#" + bank.getID() + "))");
debug("Removed bank \"" + bank.getName() + "\" (#" + bank.getID() + ")");
}

if (database != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ private boolean promptBankCreate(final Player p, String[] args) {
return true;
}
long volume = selection.getVolume();
int volumeLimit = bankUtils.getVolumeLimit(p);
long volumeLimit = bankUtils.getVolumeLimit(p);
if (!isAdminBank && volumeLimit != -1 && volume > volumeLimit) {
plugin.debug("Bank is too large (" + volume + " blocks, limit: " + volumeLimit + ")");
p.sendMessage(String.format(Messages.SELECTION_TOO_LARGE, volumeLimit, volume - volumeLimit));
Expand Down Expand Up @@ -258,7 +258,7 @@ private void promptBankRemove(final CommandSender sender, String[] args) {
} else {
bank = bankUtils.lookupBank(args[1]);
if (bank == null) {
plugin.debug("No bank could be found under the identifier " + args[1]);
plugin.debug("No bank could be found with the name or ID \"" + args[1] + "\"");
sender.sendMessage(String.format(Messages.BANK_NOT_FOUND, args[1]));
return;
}
Expand Down Expand Up @@ -347,7 +347,7 @@ private void promptBankInfo(CommandSender sender, String[] args) {
} else {
bank = bankUtils.lookupBank(args[1]);
if (bank == null) {
plugin.debug("No bank could be found under the identifier \"" + args[1] + "\"");
plugin.debug("No bank could be found with the name or ID \"" + args[1] + "\"");
sender.sendMessage(String.format(Messages.BANK_NOT_FOUND, "\"" + args[1] + "\""));
return;
}
Expand Down Expand Up @@ -476,7 +476,7 @@ else if (args.length == 2) {

bank = bankUtils.lookupBank(args[1]);
if (bank == null) {
plugin.debug("No bank could be found under the identifier " + args[1]);
plugin.debug("No bank could be found with the name or ID \"" + args[1] + "\"");
p.sendMessage(String.format(Messages.BANK_NOT_FOUND, args[1]));
return true;
}
Expand All @@ -496,7 +496,7 @@ else if (args.length == 2) {
return true;
}
long volume = selection.getVolume();
int volumeLimit = bankUtils.getVolumeLimit(p);
long volumeLimit = bankUtils.getVolumeLimit(p);
if (bank.isPlayerBank() && volumeLimit != -1 && volume > volumeLimit) {
plugin.debug("Bank is too large (" + volume + " blocks, limit: " + volumeLimit + ")");
p.sendMessage(String.format(Messages.SELECTION_TOO_LARGE_RESIZE, volumeLimit, volume - volumeLimit));
Expand Down Expand Up @@ -631,7 +631,7 @@ private boolean promptBankSet(CommandSender sender, String[] args) {
String value = sb.toString();

if (bank == null) {
plugin.debug("No bank could be found under the identifier " + args[1]);
plugin.debug("No bank could be found with the name or ID \"" + args[1] + "\"");
sender.sendMessage(String.format(Messages.BANK_NOT_FOUND, args[1]));
return true;
}
Expand Down Expand Up @@ -706,7 +706,7 @@ private void promptBankSelect(Player p, String[] args) {
} else {
bank = bankUtils.lookupBank(args[1]);
if (bank == null) {
plugin.debug("No bank could be found under the identifier " + args[1]);
plugin.debug("No bank could be found with the name or ID \"" + args[1] + "\"");
p.sendMessage(String.format(Messages.BANK_NOT_FOUND, args[1]));
return;
}
Expand Down Expand Up @@ -756,7 +756,7 @@ private boolean promptBankTransfer(CommandSender sender, String[] args) {
} else {
bank = bankUtils.lookupBank(args[1]);
if (bank == null) {
plugin.debug("No bank could be found under the identifier " + args[1]);
plugin.debug("No bank could be found with the name or ID \"" + args[1] + "\"");
sender.sendMessage(String.format(Messages.BANK_NOT_FOUND, args[1]));
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ private void checkUpdates(CommandSender sender) {

// sender.sendMessage(Messages.UPDATE_CHECKING);

UpdateChecker uc = new UpdateChecker(BankingPlugin.getInstance());
UpdateChecker uc = new UpdateChecker(plugin);
UpdateChecker.UpdateCheckerResult result = uc.check();

if (result == UpdateChecker.UpdateCheckerResult.TRUE) {
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/com/monst/bankingplugin/config/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ public class Config {
* The default bank volume limit for players whose limit is not set via a
* permission.
*/
public static int maximumBankVolume;
public static long maximumBankVolume;

/**
* Whether a bank owner should be allowed to create an account at their own
Expand Down Expand Up @@ -481,7 +481,7 @@ public void reload() {
defaultBankLimit = config.getInt("default-limits.bank");
defaultAccountLimit = config.getInt("default-limits.account");
minimumBankVolume = Math.max(config.getInt("bank-size-limits.minimum"), 0);
maximumBankVolume = Math.max(config.getInt("bank-size-limits.maximum"), 0);
maximumBankVolume = Math.max(config.getLong("bank-size-limits.maximum"), 0);
allowSelfBanking = config.getBoolean("allow-self-banking");
confirmOnRemove = config.getBoolean("confirm-on-remove");
confirmOnRemoveAll = config.getBoolean("confirm-on-removeall");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import org.bukkit.event.Cancellable;

/**
* Called when a player reloads the shops
* Called when a player reloads the plugin
*/
public class ReloadEvent extends ControlEvent implements Cancellable {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,11 @@
public class WorldGuardBankingFlag {

public static void register(final BankingPlugin plugin) {
WorldGuardWrapper wrapper = WorldGuardWrapper.getInstance();

Optional<IWrappedFlag<WrappedState>> createBankFlag = wrapper.registerFlag("create-bank", WrappedState.class,
Config.wgAllowCreateBankDefault ? WrappedState.ALLOW : WrappedState.DENY);
Optional<IWrappedFlag<WrappedState>> createBankFlag = WorldGuardWrapper.getInstance()
.registerFlag("create-bank", WrappedState.class, Config.wgAllowCreateBankDefault
? WrappedState.ALLOW
: WrappedState.DENY);

plugin.debug("Flag create-bank: " + createBankFlag.isPresent());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import org.ipvp.canvas.slot.Slot;
import org.ipvp.canvas.type.ChestMenu;

public class AccountContentsGui extends Gui<Account> {
public class AccountContentsGui extends SinglePageGui<Account> {

boolean canEdit;

Expand All @@ -20,7 +20,7 @@ public AccountContentsGui(Account account) {
}

@Override
void createMenu() {
void initializeMenu() {
menu = ChestMenu.builder(guiSubject.getSize() * 3).title(guiSubject.getColorizedName()).redraw(true).build();
}

Expand Down Expand Up @@ -81,10 +81,10 @@ public ShulkerContentsGui(Account account, ShulkerBox shulkerBox) {
}

@Override
void createMenu() {
void initializeMenu() {
menu = ChestMenu.builder(3).title(
shulkerBox.getCustomName() != null
? shulkerBox.getCustomName()
? shulkerBox.getCustomName() // TODO: Figure out why always null
: WordUtils.capitalizeFully(shulkerBox.getColor().toString()) + " Shulker Box"
).redraw(true).build();
}
Expand All @@ -99,5 +99,9 @@ Slot.ClickHandler createClickHandler(int i) {
return null;
}

@Override
GuiType getType() {
return GuiType.ACCOUNT_SHULKER_CONTENTS;
}
}
}
14 changes: 7 additions & 7 deletions src/main/java/com/monst/bankingplugin/gui/AccountGui.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import java.util.List;
import java.util.stream.Collectors;

public class AccountGui extends Gui<Account> {
public class AccountGui extends SinglePageGui<Account> {

boolean isTrusted;
boolean canTP;
Expand All @@ -31,7 +31,7 @@ public AccountGui(Account account) {
}

@Override
void createMenu() {
void initializeMenu() {
menu = ChestMenu.builder(1).title(guiSubject.getColorizedName()).build();
}

Expand Down Expand Up @@ -60,7 +60,7 @@ ItemStack createSlotItem(int i) {
case 4:
if (isTrusted)
return createSlotItem(Material.NETHER_STAR, "Current Multiplier", Utils.getMultiplierLore(guiSubject));
return createSlotItem(Material.NETHER_STAR, "Multipliers", Utils.getMultiplierLore(guiSubject.getBank()));
return createSlotItem(Material.NETHER_STAR, "Bank Multipliers", Utils.getMultiplierLore(guiSubject.getBank()));
case 5:
if (isTrusted)
return createSlotItem(Material.IRON_BARS, "Account Restrictions", getAccountRestrictionsLore());
Expand Down Expand Up @@ -154,19 +154,19 @@ private List<String> getAccountRestrictionsLore() {
int untilReset = status.getRemainingOfflineUntilReset();
int offlineDecrement = guiSubject.getBank().getAccountConfig().get(AccountConfig.Field.OFFLINE_MULTIPLIER_DECREMENT);
return Utils.wordWrapAll(
ChatColor.GRAY + (delay == 0
(delay == 0
? "Account will generate interest in the next payout cycle."
: "Account will begin generating interest in " + ChatColor.AQUA + delay + ChatColor.GRAY + String.format(" payout cycle%s.", delay == 1 ? "" : "s")),

ChatColor.GRAY + "Account can generate interest for " + ChatColor.AQUA + remainingOffline + ChatColor.GRAY + String.format(" offline payout cycle%s.", remainingOffline == 1 ? "" : "s"),
"Account can generate interest for " + ChatColor.AQUA + remainingOffline + ChatColor.GRAY + String.format(" offline payout cycle%s.", remainingOffline == 1 ? "" : "s"),

ChatColor.GRAY + "Account multiplier will " + (untilReset < 0
"Account multiplier will " + (untilReset < 0
? "not reset while offline."
: (untilReset == 0 ? "reset immediately on an offline payout."
: "reset after " + ChatColor.AQUA + untilReset + ChatColor.GRAY
+ String.format(" offline payout cycle%s.", untilReset == 1 ? "" : "s"))),

ChatColor.GRAY + "Account multiplier will " + (offlineDecrement < 0
"Account multiplier will " + (offlineDecrement < 0
? "decrease by " + ChatColor.AQUA + offlineDecrement + ChatColor.GRAY + " stages for every offline payout."
: (offlineDecrement == 0 ? " freeze while offline." : " reset"))
);
Expand Down
55 changes: 3 additions & 52 deletions src/main/java/com/monst/bankingplugin/gui/AccountListGui.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import com.monst.bankingplugin.Account;
import com.monst.bankingplugin.Bank;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.ipvp.canvas.Menu;
import org.ipvp.canvas.mask.BinaryMask;
Expand All @@ -16,35 +15,15 @@
import org.ipvp.canvas.type.ChestMenu;

import java.util.Collections;
import java.util.List;

public class AccountListGui extends Gui<Bank> {

private static final int PREV_SLOT = 18;
private static final int NEXT_SLOT = 26;

private List<Menu> pages;
private int currentPage = 0;
public class AccountListGui extends MultiPageGui<Bank> {

public AccountListGui(Bank bank) {
super(bank);
super(bank, 18, 26);
}

@Override
void open(Player player, boolean update) {
if (update) {
createMenu();
setClickHandler();
setCloseHandler(OPEN_PREVIOUS);
shortenGuiChain();
}
if (pages.isEmpty())
return;
pages.get(currentPage).open(player);
}

@Override
void createMenu() {
void initializeMenu() {
@SuppressWarnings("rawtypes")
Menu.Builder pageTemplate = ChestMenu.builder(3).title("Account List").redraw(true);
Mask itemSlots = BinaryMask.builder(pageTemplate.getDimensions())
Expand All @@ -66,34 +45,6 @@ void createMenu() {
pages = builder.build();
}

private void setClickHandler() {
for (Menu page : pages) {
for (Slot slot : new Slot[]{page.getSlot(PREV_SLOT), page.getSlot(NEXT_SLOT)}) {
//noinspection SimplifyOptionalCallChains
Slot.ClickHandler prevHandler = slot.getClickHandler().orElse(null);
if (prevHandler != null)
slot.setClickHandler((player, info) -> {
prevHandler.click(player, info);
currentPage--;
});
}
}
}

@Override
void evaluateClearance(Player player) {
}

@Override
ItemStack createSlotItem(int i) {
return null;
}

@Override
Slot.ClickHandler createClickHandler(int i) {
return null;
}

@Override
void setCloseHandler(Menu.CloseHandler handler) {
pages.forEach(page -> page.setCloseHandler(handler));
Expand Down
Loading

0 comments on commit 9376afb

Please sign in to comment.