Skip to content

Commit

Permalink
Java 16 language updates.
Browse files Browse the repository at this point in the history
  • Loading branch information
tastybento committed Nov 26, 2021
1 parent fefbf6a commit 2b59587
Show file tree
Hide file tree
Showing 8 changed files with 18 additions and 33 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
<java.version>16</java.version>
<vault.version>1.7</vault.version>
<!-- Non-minecraft related dependencies -->
<powermock.version>2.0.2</powermock.version>
<powermock.version>2.0.9</powermock.version>
<!-- More visible way how to change dependency versions -->
<spigot.version>1.16.3-R0.1-SNAPSHOT</spigot.version>
<bentobox.version>1.18.0</bentobox.version>
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/world/bentobox/bank/Bank.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public void onEnable() {
// Register flag
this.registerFlag(BANK_ACCESS);
// Vault hook
if (!getPlugin().getVault().isPresent()) {
if (getPlugin().getVault().isEmpty()) {
// Vault is required
logError("Vault is required - disabling Bank - please install the Vault plugin");
this.setState(State.DISABLED);
Expand Down
7 changes: 3 additions & 4 deletions src/main/java/world/bentobox/bank/PhManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import java.util.TreeMap;

import org.bukkit.World;
import org.eclipse.jdt.annotation.Nullable;

import world.bentobox.bank.data.Money;
import world.bentobox.bentobox.BentoBox;
Expand Down Expand Up @@ -103,7 +102,7 @@ protected boolean registerPlaceholders(GameModeAddon gm) {
* @return string of balance
*/
String getVisitedIslandBalance(GameModeAddon gm, User user, boolean formatted, boolean plain) {
if (user == null || user.getLocation() == null) return "";
if (user == null || !user.isPlayer()) return "";
double balance = gm.inWorld(user.getWorld()) ? addon.getIslands().getIslandAt(user.getLocation()).map(i -> bankManager.getBalance(i).getValue()).orElse(0D) : 0D;
if (plain) {
return String.valueOf(balance);
Expand Down Expand Up @@ -184,10 +183,10 @@ protected void setNames(List<String> names) {

/**
* Get the string representation of money. May be converted to shorthand notation, e.g., 104556 = 10.5k
* @param lvl - value to represent
* @param value - value to represent
* @return string of the value.
*/
private String format(@Nullable double value) {
private String format(double value) {
String level = addon.getVault().format(value);
BigInteger levelValue = BigInteger.valueOf((long)value);
Map.Entry<BigInteger, String> stage = LEVELS.floorEntry(levelValue);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public abstract class AbstractBankCommand extends CompositeCommand {

protected AbstractBankCommand(CompositeCommand parent, String string) {
super(parent, string);
this.addon = ((Bank)getAddon());
this.addon = getAddon();
}

protected Bank addon;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,18 +37,11 @@ public boolean execute(User user, String label, List<String> args) {
.withdraw(user, island, value, TxType.TAKE)
.thenAccept(result -> {
switch (result) {
case FAILURE_LOW_BALANCE:
user.sendMessage("bank.errors.too-low");
break;
case SUCCESS:
user.sendMessage("bank.admin.give.success",
case FAILURE_LOW_BALANCE -> user.sendMessage("bank.errors.too-low");
case SUCCESS -> user.sendMessage("bank.admin.give.success",
TextVariables.NAME, this.target.getName(),
TextVariables.NUMBER, addon.getVault().format(addon.getBankManager().getBalance(island).getValue()));
break;
default:
user.sendMessage("bank.errors.bank-error");
break;

default -> user.sendMessage("bank.errors.bank-error");
}
});
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,20 +49,13 @@ public boolean execute(User user, String label, List<String> args) {
// Success
addon.getBankManager().withdraw(user, value, getWorld()).thenAccept(result -> {
switch (result) {
case FAILURE_LOAD_ERROR:
user.sendMessage("bank.errors.bank-error");
break;
case FAILURE_LOW_BALANCE:
user.sendMessage("bank.errors.low-balance");
break;
case FAILURE_NO_ISLAND:
user.sendMessage("general.errors.no-island");
break;
default:
addon.getVault().deposit(user, value.getValue(), getWorld());
user.sendMessage("bank.withdraw.success", TextVariables.NUMBER, addon.getVault().format(addon.getBankManager().getBalance(island).getValue()));
break;

case FAILURE_LOAD_ERROR -> user.sendMessage("bank.errors.bank-error");
case FAILURE_LOW_BALANCE -> user.sendMessage("bank.errors.low-balance");
case FAILURE_NO_ISLAND -> user.sendMessage("general.errors.no-island");
default -> {
addon.getVault().deposit(user, value.getValue(), getWorld());
user.sendMessage("bank.withdraw.success", TextVariables.NUMBER, addon.getVault().format(addon.getBankManager().getBalance(island).getValue()));
}
}
});
return true;
Expand Down
3 changes: 1 addition & 2 deletions src/main/java/world/bentobox/bank/data/Money.java
Original file line number Diff line number Diff line change
Expand Up @@ -138,10 +138,9 @@ public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (!(obj instanceof Money)) {
if (!(obj instanceof Money other)) {
return false;
}
Money other = (Money) obj;
return value.equals(other.value);
}

Expand Down
1 change: 1 addition & 0 deletions src/test/java/world/bentobox/bank/PhManagerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ public void setUp() {
return Optional.of(i);
});
when(plm.getName(any())).thenAnswer(arg -> arg.getArgument(0, UUID.class).toString());
when(user.isPlayer()).thenReturn(true);
pm = new PhManager(addon, bm);
}

Expand Down

0 comments on commit 2b59587

Please sign in to comment.