Skip to content

Commit

Permalink
Ensure valid Economy present for economy sharable.
Browse files Browse the repository at this point in the history
  • Loading branch information
benwoo1110 committed Mar 10, 2021
1 parent 1d52822 commit f202a31
Showing 1 changed file with 17 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import org.bukkit.inventory.ItemStack;
import org.bukkit.potion.PotionEffect;
import org.jetbrains.annotations.NotNull;
import sun.rmi.runtime.Log;

import java.nio.ByteBuffer;
import java.util.Arrays;
Expand Down Expand Up @@ -537,13 +538,29 @@ public boolean updatePlayer(Player player, PlayerProfile profile) {
*/
public static final Sharable<Double> ECONOMY = new Sharable.Builder<Double>("economy", Double.class,
new SharableHandler<Double>() {
private boolean hasValidEconomyHandler() {
if (!inventories.getCore().getEconomist().isUsingEconomyPlugin()) {
return true;
}
Logging.warning("You do not have an an economy plugin with Vault. Economy sharable will not work!");
Logging.warning("Check that your economy and vault plugin are both working correctly.");
Logging.warning("If you enabled the sharable by mistake, run '/mvinv toggle economy' to resolve this.");
return false;
}

@Override
public void updateProfile(PlayerProfile profile, Player player) {
if (!hasValidEconomyHandler()) {
return;
}
profile.set(ECONOMY, inventories.getCore().getEconomist().getBalance(player));
}

@Override
public boolean updatePlayer(Player player, PlayerProfile profile) {
if (!hasValidEconomyHandler()) {
return false;
}
Double money = profile.get(ECONOMY);
if (money == null) {
inventories.getCore().getEconomist().setBalance(player, 0);
Expand Down

0 comments on commit f202a31

Please sign in to comment.