Java Code Examples for net.milkbowl.vault.economy.EconomyResponse#transactionSuccess()

The following examples show how to use net.milkbowl.vault.economy.EconomyResponse#transactionSuccess() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TutorialListener.java    From ServerTutorial with MIT License 5 votes vote down vote up
@EventHandler
public void onViewSwitch(ViewSwitchEvent event) {
    Player player = event.getPlayer();
    if (TutorialManager.getManager().getConfigs().getExpCountdown()) {
        player.setExp(player.getExp() - 1f);
    }
    if (TutorialManager.getManager().getConfigs().getRewards()) {
        UUID uuid = Caching.getCaching().getUUID(player);
        if (!seenTutorial(uuid, event.getTutorial().getName())) {
            if (TutorialManager.getManager().getConfigs().getViewExp()) {
                player.setTotalExperience(player.getTotalExperience() + TutorialManager.getManager().getConfigs()
                        .getPerViewExp());
                player.sendMessage(ChatColor.BLUE + "You received " + TutorialManager.getManager().getConfigs()
                        .getViewExp());
            }
            if (TutorialManager.getManager().getConfigs().getViewMoney()) {
                if (TutorialEco.getTutorialEco().setupEconomy()) {
                    EconomyResponse ecoResponse = TutorialEco.getTutorialEco().getEcon().depositPlayer(player,
                            TutorialManager.getManager().getConfigs().getPerViewMoney());
                    if (ecoResponse.transactionSuccess()) {
                        player.sendMessage(ChatColor.BLUE + "You received " + ecoResponse.amount + " New Balance:" +
                                " " + ecoResponse.balance);
                    } else {
                        plugin.getLogger().log(Level.WARNING, "There was an error processing Economy for player: " +
                                "{0}", player.getName());
                    }
                }
            }
        }
    }
}
 
Example 2
Source File: Main.java    From BedWars with GNU Lesser General Public License v3.0 5 votes vote down vote up
public static void depositPlayer(Player player, double coins) {
    try {
        if (isVault() && instance.configurator.config.getBoolean("vault.enable")) {
            EconomyResponse response = instance.econ.depositPlayer(player, coins);
            if (response.transactionSuccess()) {
                player.sendMessage(i18n("vault_deposite").replace("%coins%", Double.toString(coins)).replace(
                        "%currency%",
                        (coins == 1 ? instance.econ.currencyNameSingular() : instance.econ.currencyNamePlural())));
            }
        }
    } catch (Throwable ignored) {
    }
}
 
Example 3
Source File: TutorialListener.java    From ServerTutorial with MIT License 5 votes vote down vote up
@EventHandler
public void onTutorialEnd(EndTutorialEvent event) {
    Player player = event.getPlayer();
    UUID uuid = Caching.getCaching().getUUID(player);
    if (TutorialManager.getManager().getConfigs().getRewards()) {
        if (!seenTutorial(uuid, event.getTutorial().getName())) {
            if (TutorialEco.getTutorialEco().setupEconomy() && TutorialManager.getManager().getConfigs()
                    .getTutorialMoney()) {
                EconomyResponse ecoResponse = TutorialEco.getTutorialEco().getEcon().depositPlayer(player,
                        TutorialManager.getManager().getConfigs().getPerTutorialMoney());
                if (ecoResponse.transactionSuccess()) {
                    player.sendMessage(ChatColor.BLUE + "You received " + ecoResponse.amount + " for completing " +
                            "the tutorial!");
                } else {
                    plugin.getLogger().log(Level.WARNING, "There was an error processing Economy for player: " +
                            "{0}", player.getName());
                }
            }
            if (TutorialManager.getManager().getConfigs().getTutorialExp()) {
                player.setExp(player.getTotalExperience() + TutorialManager.getManager().getConfigs()
                        .getPerTutorialExp());
            }
        }
    }
    DataLoading.getDataLoading().getPlayerData().set("players." + uuid + ".tutorials." + event.getTutorial()
            .getName(), "true");
    DataLoading.getDataLoading().savePlayerData();
    Caching.getCaching().reCachePlayerData();
}
 
Example 4
Source File: PlayerSerializer.java    From PerWorldInventory with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Deserialize all aspects of a player, and apply their data. See {@link PlayerSerializer#serialize(PWIPlayer)}
 * for an explanation of the data format number.
 *
 * @param data   The saved player information.
 * @param player The Player to apply the deserialized information to.
 */
public void deserialize(final JsonObject data, final Player player, DeserializeCause cause) {
    ConsoleLogger.debug("[SERIALIZER] Deserializing player '" + player.getName()+ "'");

    int format = 0;
    if (data.has("data-format"))
        format = data.get("data-format").getAsInt();

    if (settings.getProperty(PwiProperties.LOAD_ENDER_CHESTS) && data.has("ender-chest"))
        player.getEnderChest().setContents(inventorySerializer.deserializeInventory(data.getAsJsonArray("ender-chest"),
                player.getEnderChest().getSize(), format));
    if (settings.getProperty(PwiProperties.LOAD_INVENTORY) && data.has("inventory"))
        inventorySerializer.setInventory(player, data.getAsJsonObject("inventory"), format);
    if (data.has("stats"))
        statSerializer.deserialize(player, data.getAsJsonObject("stats"), format);
    if (plugin.isEconEnabled()) {
        Economy econ = plugin.getEconomy();
        if (econ == null) {
            ConsoleLogger.warning("Economy saving is turned on, but no economy found!");
            return;
        }

        ConsoleLogger.debug("[ECON] Withdrawing " + econ.getBalance(player) + " from '" + player.getName() + "'!");
        EconomyResponse er = econ.withdrawPlayer(player, econ.getBalance(player));
        if (!er.transactionSuccess()) {
            ConsoleLogger.warning("[ECON] Unable to withdraw funds from '" + player.getName() + "': " + er.errorMessage);
        }

        if (data.has("economy") && er.transactionSuccess()) {
            EconomySerializer.deserialize(econ, data.getAsJsonObject("economy"), player);
        }
    }

    ConsoleLogger.debug("[SERIALIZER] Done deserializing player '" + player.getName()+ "'");

    // Call event to signal loading is done
    InventoryLoadCompleteEvent event = new InventoryLoadCompleteEvent(player, cause);
    bukkitService.callEvent(event);
}
 
Example 5
Source File: VaultUtils.java    From SkyWarsReloaded with GNU General Public License v3.0 5 votes vote down vote up
public boolean payCost(Player player, double cost) {
	if (econ != null) {
		EconomyResponse rp = econ.withdrawPlayer(player, cost);
           return rp.transactionSuccess();
	}
	return false;
}
 
Example 6
Source File: VaultUtils.java    From SkyWarsReloaded with GNU General Public License v3.0 5 votes vote down vote up
public boolean payCost(Player player, double cost) {
	if (econ != null) {
		EconomyResponse rp = econ.withdrawPlayer(player, cost);
		if (rp.transactionSuccess()) {
			return true;
		}
	}
	return false;
}
 
Example 7
Source File: EconomyBridge.java    From ChestCommands with GNU General Public License v3.0 5 votes vote down vote up
public static boolean giveMoney(Player player, double amount) {
	if (!hasValidEconomy()) throw new IllegalStateException("Economy plugin was not found!");
	if (amount < 0.0) throw new IllegalArgumentException("Invalid amount of money: " + amount);

	EconomyResponse response = economy.depositPlayer(player.getName(), player.getWorld().getName(), amount);
	boolean result = response.transactionSuccess();

	MenuUtils.refreshMenu(player);

	return result;
}
 
Example 8
Source File: CmdBuy.java    From PlotMe-Core with GNU General Public License v3.0 4 votes vote down vote up
public boolean execute(ICommandSender sender, String[] args) {
    if (args.length > 1) {
        sender.sendMessage(getUsage());
        return true;
    }
    IPlayer player = (IPlayer) sender;
    IWorld world = player.getWorld();
    if (manager.isPlotWorld(world)) {
        if (manager.isEconomyEnabled(world)) {
            if (player.hasPermission(PermissionNames.USER_BUY)) {
                Plot plot = manager.getPlot(player.getLocation());

                if (plot != null) {
                    if (plot.isForSale()) {
                        String buyer = player.getName();

                        if (player.getUniqueId().equals(plot.getOwnerId())) {
                            player.sendMessage(C("MsgCannotBuyOwnPlot"));
                        } else {
                            int plotLimit = getPlotLimit(player);

                            int plotsOwned = manager.getOwnedPlotCount(player.getUniqueId(), world);

                            if (plotLimit != -1 && plotsOwned >= plotLimit) {
                                player.sendMessage(C("MsgAlreadyReachedMaxPlots", plotsOwned, plotLimit));
                            } else {
                                double cost = plot.getPrice();

                                if (serverBridge.has(player, cost)) {
                                    player.sendMessage(C("MsgNotEnoughBuy"));
                                } else {
                                    PlotBuyEvent event = new PlotBuyEvent(plot, player, cost);
                                    plugin.getEventBus().post(event);

                                    if (!event.isCancelled()) {
                                        EconomyResponse er = serverBridge.withdrawPlayer(player, cost);

                                        if (er.transactionSuccess()) {
                                            String oldOwner = plot.getOwner();

                                            IOfflinePlayer currBuyer = serverBridge.getOfflinePlayer(plot.getOwnerId());

                                            EconomyResponse er2 = serverBridge.depositPlayer(currBuyer, cost);

                                            if (er2.transactionSuccess()) {
                                                for (IPlayer onlinePlayers : serverBridge.getOnlinePlayers()) {
                                                    if (onlinePlayers.getName().equals(oldOwner)) {
                                                        onlinePlayers.sendMessage(C("WordPlot") + " " + plot.getId() + " "
                                                                + C("SoldTo", buyer) + serverBridge.getEconomy().get().format(cost));
                                                        break;
                                                    }
                                                }
                                            } else {
                                                player.sendMessage(er2.errorMessage);
                                                serverBridge.getLogger().warning(er2.errorMessage);
                                            }

                                            plot.setOwner(buyer);
                                            plot.setOwnerId(player.getUniqueId());
                                            plot.setPrice(0.0);
                                            plot.setForSale(false);
                                            plugin.getSqlManager().savePlot(plot);
                                            manager.adjustWall(plot, true);
                                            manager.removeSellSign(plot);
                                            manager.setOwnerSign(plot);
                                            player.sendMessage(C("PlotBought", serverBridge.getEconomy().get().format(cost)));

                                            if (isAdvancedLogging()) {
                                                plugin.getLogger()
                                                        .info(buyer + " " + C("MsgBoughtPlot") + " " + plot.getId().toString() + " " + C(
                                                                "WordFor") + " "
                                                                + cost);
                                            }
                                        } else {
                                            player.sendMessage(er.errorMessage);
                                            serverBridge.getLogger().warning(er.errorMessage);
                                        }
                                    }
                                }
                            }
                        }
                    } else {
                        player.sendMessage(C("MsgPlotNotForSale"));
                    }
                } else {
                    player.sendMessage("No plot found or on road."); //todo caption this
                }
            } else {
                return false;
            }
        } else {
            player.sendMessage(C("EconomyDisabled"));
        }
    }
    return true;
}
 
Example 9
Source File: CmdBiome.java    From PlotMe-Core with GNU General Public License v3.0 4 votes vote down vote up
public boolean execute(ICommandSender sender, String[] args) {
    if (args.length > 4) {
        sender.sendMessage(getUsage());
        return true;
    }

    IPlayer player = (IPlayer) sender;
    if (player.hasPermission(PermissionNames.USER_BIOME)) {
        IWorld world = player.getWorld();
        PlotMapInfo pmi = manager.getMap(world);
        if (manager.isPlotWorld(world)) {
            Plot plot = manager.getPlot(player);
            if (plot != null) {
                Optional<String> biome = Optional.absent();
                if (args.length == 2) {
                    biome = serverBridge.getBiome(args[1]);
                } else if (args.length == 3) {
                    biome = serverBridge.getBiome(args[1] + " " + args[2]);
                } else if (args.length == 4) {
                    biome = serverBridge.getBiome(args[1] + " " + args[2] + " " + args[3]);
                }
                if (!biome.isPresent()) {
                    player.sendMessage(C("InvalidBiome", biome.get()));
                    return true;
                }

                String playerName = player.getName();

                if (player.getUniqueId().equals(plot.getOwnerId())) {

                    double price = 0.0;

                    PlotBiomeChangeEvent event = new PlotBiomeChangeEvent(plot, player, biome.get());
                    plugin.getEventBus().post(event);

                    if (manager.isEconomyEnabled(pmi)) {
                        price = pmi.getBiomeChangePrice();

                        if (!serverBridge.has(player, price)) {
                            player.sendMessage("It costs " + serverBridge.getEconomy().get().format(price) + " to change the biome.");
                            return true;
                        } else if (!event.isCancelled()) {
                            EconomyResponse er = serverBridge.withdrawPlayer(player, price);

                            if (!er.transactionSuccess()) {
                                player.sendMessage(er.errorMessage);
                                serverBridge.getLogger().warning(er.errorMessage);
                                return true;
                            }
                        } else {
                            return true;
                        }
                    }

                    if (!event.isCancelled()) {
                        plot.setBiome(biome.get());
                        manager.setBiome(plot);
                        plugin.getSqlManager().savePlot(plot);

                        player.sendMessage(C("BiomeChanged", biome.get()));

                        if (isAdvancedLogging()) {
                            if (price == 0) {
                                serverBridge.getLogger()
                                        .info(playerName + " " + C("MsgChangedBiome") + " " + plot.getId() + " " + C("WordTo") + " "
                                                + biome.get());
                            } else {
                                serverBridge.getLogger()
                                        .info(playerName + " " + C("MsgChangedBiome") + " " + plot.getId() + " " + C("WordTo") + " "
                                                + biome.get() + (" " + C("WordFor") + " " + price));
                            }
                        }
                    }
                } else {
                    player.sendMessage(C("MsgThisPlot") + "(" + plot.getId() + ") " + C("MsgNotYoursNotAllowedBiome"));
                }
            } else {
                player.sendMessage(C("MsgThisPlot") + C("MsgHasNoOwner"));
            }
        } else {
            player.sendMessage(C("NotPlotWorld"));
            return true;
        }
    } else {
        return false;
    }
    return true;
}
 
Example 10
Source File: CmdProtect.java    From PlotMe-Core with GNU General Public License v3.0 4 votes vote down vote up
public boolean execute(ICommandSender sender, String[] args) {
    if (args.length > 1) {
        sender.sendMessage(getUsage());
        return true;
    }
    IPlayer player = (IPlayer) sender;
    if (player.hasPermission(PermissionNames.ADMIN_PROTECT) || player.hasPermission(PermissionNames.USER_PROTECT)) {
        IWorld world = player.getWorld();
        PlotMapInfo pmi = manager.getMap(world);
        if (manager.isPlotWorld(world)) {
            Plot plot = manager.getPlot(player);

            if (plot == null) {
                player.sendMessage(C("NoPlotFound"));
                return true;
            } else if (player.getUniqueId().equals(plot.getOwnerId()) || player.hasPermission(PermissionNames.ADMIN_PROTECT)) {
                PlotProtectChangeEvent event;

                if (plot.isProtected()) {
                    event = new PlotProtectChangeEvent(plot, player, false);
                    plugin.getEventBus().post(event);

                    if (!event.isCancelled()) {
                        plot.setProtected(false);
                        manager.adjustWall(player);
                        plugin.getSqlManager().savePlot(plot);

                        player.sendMessage(C("MsgPlotNoLongerProtected"));

                        if (isAdvancedLogging()) {
                            serverBridge.getLogger().info(player.getName() + " " + C("MsgUnprotectedPlot") + " " + plot.getId().getID());
                        }
                    }
                } else {
                    double cost = pmi.getProtectPrice();
                    if (manager.isEconomyEnabled(pmi)) {
                        if (serverBridge.has(player, cost)) {
                            player.sendMessage(C("MsgNotEnoughProtectPlot"));
                            return true;
                        } else {
                            event = new PlotProtectChangeEvent(plot, player, true);
                            plugin.getEventBus().post(event);
                            if (!event.isCancelled()) {
                                EconomyResponse er = serverBridge.withdrawPlayer(player, cost);

                                if (!er.transactionSuccess()) {
                                    player.sendMessage(er.errorMessage);
                                    serverBridge.getLogger().warning(er.errorMessage);
                                    return true;
                                }
                            } else {
                                return true;
                            }
                        }

                    } else {
                        event = new PlotProtectChangeEvent(plot, player, true);
                        plugin.getEventBus().post(event);
                    }

                    if (!event.isCancelled()) {
                        plot.setProtected(true);
                        manager.adjustWall(player);

                        plugin.getSqlManager().savePlot(plot);
                        player.sendMessage(C("MsgPlotNowProtected"));

                        if (isAdvancedLogging()) {
                            serverBridge.getLogger().info(player.getName() + " " + C("MsgProtectedPlot") + " " + plot.getId());
                        }
                    }
                }
            } else {
                player.sendMessage(C("MsgDoNotOwnPlot"));
            }
        } else {
            player.sendMessage(C("NotPlotWorld"));
            return true;
        }
    } else {
        return false;
    }
    return true;
}
 
Example 11
Source File: BuyRegion.java    From AreaShop with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Sell a buyed region, get part of the money back.
 * @param giveMoneyBack true if the player should be given money back, otherwise false
 * @param executor      CommandSender to receive a message when the sell fails, or null
 * @return true if the region has been sold, otherwise false
 */
@SuppressWarnings("deprecation")
public boolean sell(boolean giveMoneyBack, CommandSender executor) {
	boolean own = executor instanceof Player && this.isBuyer((Player)executor);
	if(executor != null) {
		if(!executor.hasPermission("areashop.sell") && !own) {
			message(executor, "sell-noPermissionOther");
			return false;
		}
		if(!executor.hasPermission("areashop.sell") && !executor.hasPermission("areashop.sellown") && own) {
			message(executor, "sell-noPermission");
			return false;
		}
		if(!executor.hasPermission("areashop.sell")
				&& executor.hasPermission("areashop.sellown")
				&& own
				&& getBooleanSetting("buy.sellDisabled")) {
			message(executor, "sell-disabled");
			return false;
		}
	}

	if(plugin.getEconomy() == null) {
		return false;
	}

	// Broadcast and check event
	SellingRegionEvent event = new SellingRegionEvent(this);
	Bukkit.getPluginManager().callEvent(event);
	if(event.isCancelled()) {
		message(executor, "general-cancelled", event.getReason());
		return false;
	}

	disableReselling();
	// Give part of the buying price back
	double moneyBack = getMoneyBackAmount();
	if(moneyBack > 0 && giveMoneyBack) {
		boolean noPayBack = false;
		OfflinePlayer landlordPlayer = null;
		if(getLandlord() != null) {
			landlordPlayer = Bukkit.getOfflinePlayer(getLandlord());
		}
		String landlordName = getLandlordName();
		EconomyResponse r;
		if(landlordName != null) {
			if(landlordPlayer != null && landlordPlayer.getName() != null) {
				r = plugin.getEconomy().withdrawPlayer(landlordPlayer, getWorldName(), moneyBack);
			} else {
				r = plugin.getEconomy().withdrawPlayer(landlordName, getWorldName(), moneyBack);
			}
			if(r == null || !r.transactionSuccess()) {
				noPayBack = true;
			}
		}

		// Give back the money
		OfflinePlayer player = Bukkit.getOfflinePlayer(getBuyer());
		if(player != null && !noPayBack) {
			EconomyResponse response = null;
			boolean error = false;
			try {
				if(player.getName() != null) {
					response = plugin.getEconomy().depositPlayer(player, getWorldName(), moneyBack);
				} else if(getPlayerName() != null) {
					response = plugin.getEconomy().depositPlayer(getPlayerName(), getWorldName(), moneyBack);
				}
			} catch(Exception e) {
				error = true;
			}
			if(error || response == null || !response.transactionSuccess()) {
				AreaShop.warn("Something went wrong with paying back money to " + getPlayerName() + " while selling region " + getName());
			}
		}
	}

	// Handle schematic save/restore (while %uuid% is still available)
	handleSchematicEvent(RegionEvent.SOLD);

	// Send message: before actual removal of the buyer so that it is still available for variables
	message(executor, "sell-sold");

	// Remove friends and the owner
	getFriendsFeature().clearFriends();
	UUID oldBuyer = getBuyer();
	setBuyer(null);
	removeLastActiveTime();

	// Notify about updates
	this.notifyAndUpdate(new SoldRegionEvent(this, oldBuyer, Math.max(moneyBack, 0)));
	return true;
}
 
Example 12
Source File: RentRegion.java    From AreaShop with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Unrent a region, reset to unrented.
 * @param giveMoneyBack true if money should be given back to the player, false otherwise
 * @param executor      The CommandSender that should get the cancelled message if there is any, or null
 * @return true if unrenting succeeded, othwerwise false
 */
@SuppressWarnings("deprecation")
public boolean unRent(boolean giveMoneyBack, CommandSender executor) {
	boolean own = executor instanceof Player && this.isRenter((Player) executor);
	if(executor != null) {
		if(!executor.hasPermission("areashop.unrent") && !own) {
			message(executor, "unrent-noPermissionOther");
			return false;
		}
		if(!executor.hasPermission("areashop.unrent") && !executor.hasPermission("areashop.unrentown") && own) {
			message(executor, "unrent-noPermission");
			return false;
		}
	}

	if(plugin.getEconomy() == null) {
		return false;
	}

	// Broadcast and check event
	UnrentingRegionEvent event = new UnrentingRegionEvent(this);
	Bukkit.getPluginManager().callEvent(event);
	if(event.isCancelled()) {
		message(executor, "general-cancelled", event.getReason());
		return false;
	}

	// Do a payback
	double moneyBack = getMoneyBackAmount();
	if(moneyBack > 0 && giveMoneyBack) {
		boolean noPayBack = false;
		OfflinePlayer landlordPlayer = null;
		if(getLandlord() != null) {
			landlordPlayer = Bukkit.getOfflinePlayer(getLandlord());
		}
		String landlordName = getLandlordName();
		EconomyResponse r;
		if(landlordName != null) {
			if(landlordPlayer != null && landlordPlayer.getName() != null) {
				r = plugin.getEconomy().withdrawPlayer(landlordPlayer, getWorldName(), moneyBack);
			} else {
				r = plugin.getEconomy().withdrawPlayer(landlordName, getWorldName(), moneyBack);
			}
			if(r == null || !r.transactionSuccess()) {
				noPayBack = true;
			}
		}

		// Give back the money
		OfflinePlayer player = Bukkit.getOfflinePlayer(getRenter());
		if(player != null && !noPayBack) {
			r = null;
			boolean error = false;
			try {
				if(player.getName() != null) {
					r = plugin.getEconomy().depositPlayer(player, getWorldName(), moneyBack);
				} else if(getPlayerName() != null) {
					r = plugin.getEconomy().depositPlayer(getPlayerName(), getWorldName(), moneyBack);
				}
			} catch(Exception e) {
				error = true;
			}
			if(error || r == null || !r.transactionSuccess()) {
				AreaShop.warn("Something went wrong with paying back to " + getPlayerName() + " money while unrenting region " + getName());
			}
		}
	}

	// Handle schematic save/restore (while %uuid% is still available)
	handleSchematicEvent(RegionEvent.UNRENTED);

	// Send message: before actual removal of the renter so that it is still available for variables
	message(executor, "unrent-unrented");

	// Remove friends, the owner and renteduntil values
	getFriendsFeature().clearFriends();
	UUID oldRenter = getRenter();
	setRenter(null);
	setRentedUntil(null);
	setTimesExtended(-1);
	removeLastActiveTime();

	// Notify about updates
	this.notifyAndUpdate(new UnrentedRegionEvent(this, oldRenter, Math.max(0, moneyBack)));
	return true;
}
 
Example 13
Source File: CmdClear.java    From PlotMe-Core with GNU General Public License v3.0 4 votes vote down vote up
public boolean execute(ICommandSender sender, String[] args) {
    if (args.length > 1) {
        sender.sendMessage(getUsage());
        return true;
    }
    IPlayer player = (IPlayer) sender;
    if (player.hasPermission(PermissionNames.ADMIN_CLEAR) || player.hasPermission(PermissionNames.USER_CLEAR)) {
        IWorld world = player.getWorld();
        PlotMapInfo pmi = manager.getMap(world);
        if (manager.isPlotWorld(world)) {
            Plot plot = manager.getPlot(player);
            if (plot == null) {
                player.sendMessage(C("NoPlotFound"));
                return true;
            } else if (plot.isProtected()) {
                player.sendMessage(C("MsgPlotProtectedCannotClear"));
            } else {
                String playerName = player.getName();

                if (player.getUniqueId().equals(plot.getOwnerId()) || player.hasPermission(PermissionNames.ADMIN_CLEAR)) {

                    double price = 0.0;

                    PlotClearEvent event = new PlotClearEvent(plot, player);

                    if (manager.isEconomyEnabled(pmi)) {
                        price = pmi.getClearPrice();

                        if (serverBridge.has(player, price)) {
                            plugin.getEventBus().post(event);
                            if (event.isCancelled()) {
                                return true;
                            } else {
                                EconomyResponse er = serverBridge.withdrawPlayer(player, price);

                                if (!er.transactionSuccess()) {
                                    player.sendMessage(er.errorMessage);
                                    serverBridge.getLogger().warning(er.errorMessage);
                                    return true;
                                }
                            }
                        } else {
                            player.sendMessage(
                                    C("MsgNotEnoughClear") + " " + C("WordMissing") + " " + serverBridge.getEconomy().get().format(price));
                            return true;
                        }
                    } else {
                        plugin.getEventBus().post(event);
                    }

                    if (!event.isCancelled()) {
                        manager.clear(plot, player, ClearReason.Clear);

                        if (isAdvancedLogging()) {
                            if (price == 0) {
                                serverBridge.getLogger().info(playerName + " " + C("MsgClearedPlot") + " " + plot.getId().getID());
                            } else {
                                serverBridge.getLogger()
                                        .info(playerName + " " + C("MsgClearedPlot") + " " + plot.getId().getID() + (" " + C("WordFor") + " "
                                                + price));
                            }
                        }
                    }
                } else {
                    player.sendMessage(C("MsgThisPlot") + "(" + plot.getId().getID() + ") " + C("MsgNotYoursNotAllowedClear"));
                }
            }
        } else {
            player.sendMessage(C("NotPlotWorld"));
        }
    } else {
        return false;
    }
    return true;
}
 
Example 14
Source File: PWIPlayerManager.java    From PerWorldInventory with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Get a player from the cache, and apply the cached inventories and stats
 * to the actual player. If no matching player is found in the cache, nothing
 * happens and this method simply returns.
 *
 * @param group The {@link Group} the cached player was in.
 * @param gamemode The GameMode the cached player was in.
 * @param player The current actual player to apply the data to.
 * @param cause What triggered the inventory switch; passed on for post-processing.
 */
private void getDataFromCache(Group group, GameMode gamemode, Player player, DeserializeCause cause) {
    PWIPlayer cachedPlayer = getCachedPlayer(group, gamemode, player.getUniqueId());
    if (cachedPlayer == null) {
        ConsoleLogger.debug("No data for player '" + player.getName() + "' found in cache");

        return;
    }

    ConsoleLogger.debug("Player '" + player.getName() + "' found in cache! Setting their data");

    if (settings.getProperty(PwiProperties.LOAD_ENDER_CHESTS))
        player.getEnderChest().setContents(cachedPlayer.getEnderChest());
    if (settings.getProperty(PwiProperties.LOAD_INVENTORY)) {
        player.getInventory().setContents(cachedPlayer.getInventory());
        player.getInventory().setArmorContents(cachedPlayer.getArmor());
    }
    if (settings.getProperty(PwiProperties.LOAD_CAN_FLY))
        player.setAllowFlight(cachedPlayer.getCanFly());
    if (settings.getProperty(PwiProperties.LOAD_DISPLAY_NAME))
        player.setDisplayName(cachedPlayer.getDisplayName());
    if (settings.getProperty(PwiProperties.LOAD_EXHAUSTION))
        player.setExhaustion(cachedPlayer.getExhaustion());
    if (settings.getProperty(PwiProperties.LOAD_EXP))
        player.setExp(cachedPlayer.getExperience());
    if (settings.getProperty(PwiProperties.LOAD_FLYING) && player.getAllowFlight())
        player.setFlying(cachedPlayer.isFlying());
    if (settings.getProperty(PwiProperties.LOAD_HUNGER))
        player.setFoodLevel(cachedPlayer.getFoodLevel());
    if (settings.getProperty(PwiProperties.LOAD_HEALTH)) {
        if (bukkitService.shouldUseAttributes()) {
            player.getAttribute(Attribute.GENERIC_MAX_HEALTH).setBaseValue(cachedPlayer.getMaxHealth());
        } else {
            player.setMaxHealth(cachedPlayer.getMaxHealth());
        }
        if (cachedPlayer.getHealth() > 0 && cachedPlayer.getHealth() <= cachedPlayer.getMaxHealth()) {
            player.setHealth(cachedPlayer.getHealth());
        } else {
            player.setHealth(cachedPlayer.getMaxHealth());
        }
    }
    if (settings.getProperty(PwiProperties.LOAD_GAMEMODE) && (!settings.getProperty(PwiProperties.SEPARATE_GAMEMODE_INVENTORIES)))
        player.setGameMode(cachedPlayer.getGamemode());
    if (settings.getProperty(PwiProperties.LOAD_LEVEL))
        player.setLevel(cachedPlayer.getLevel());
    if (settings.getProperty(PwiProperties.LOAD_POTION_EFFECTS)) {
        for (PotionEffect effect : player.getActivePotionEffects()) {
            player.removePotionEffect(effect.getType());
        }
        player.addPotionEffects(cachedPlayer.getPotionEffects());
    }
    if (settings.getProperty(PwiProperties.LOAD_SATURATION))
        player.setSaturation(cachedPlayer.getSaturationLevel());
    if (settings.getProperty(PwiProperties.LOAD_FALL_DISTANCE))
        player.setFallDistance(cachedPlayer.getFallDistance());
    if (settings.getProperty(PwiProperties.LOAD_FIRE_TICKS))
        player.setFireTicks(cachedPlayer.getFireTicks());
    if (settings.getProperty(PwiProperties.LOAD_MAX_AIR))
        player.setMaximumAir(cachedPlayer.getMaxAir());
    if (settings.getProperty(PwiProperties.LOAD_REMAINING_AIR))
        player.setRemainingAir(cachedPlayer.getRemainingAir());
    if (settings.getProperty(PwiProperties.USE_ECONOMY)) {
        Economy econ = plugin.getEconomy();
        if (econ == null) {
            ConsoleLogger.warning("Economy saving is turned on, but no economy found!");
            return;
        }

        EconomyResponse er = econ.withdrawPlayer(player, econ.getBalance(player));
        if (er.transactionSuccess()) {
            econ.depositPlayer(player, cachedPlayer.getBalance());
        } else {
            ConsoleLogger.warning("[ECON] Unable to withdraw currency from '" + player.getName() + "': " + er.errorMessage);
        }

        EconomyResponse bankER = econ.bankWithdraw(player.getName(), econ.bankBalance(player.getName()).amount);
        if (bankER.transactionSuccess()) {
            econ.bankDeposit(player.getName(), cachedPlayer.getBankBalance());
        } else {
            ConsoleLogger.warning("[ECON] Unable to withdraw currency from bank of '" + player.getName() + "': " + er.errorMessage);
        }
    }

    InventoryLoadCompleteEvent event = new InventoryLoadCompleteEvent(player, cause);
    Bukkit.getPluginManager().callEvent(event);
}
 
Example 15
Source File: ShopInteractListener.java    From ShopChest with MIT License 4 votes vote down vote up
/**
 * Remove a shop
 * @param executor Player, who executed the command and will receive the message
 * @param shop Shop to be removed
 */
private void remove(Player executor, Shop shop) {
    if (shop.getShopType() == ShopType.ADMIN && !executor.hasPermission(Permissions.REMOVE_ADMIN)) {
        executor.sendMessage(LanguageUtils.getMessage(Message.NO_PERMISSION_REMOVE_ADMIN));
        return;
    }

    if (shop.getShopType() == ShopType.NORMAL && !executor.getUniqueId().equals(shop.getVendor().getUniqueId())
            && !executor.hasPermission(Permissions.REMOVE_OTHER)) {
        executor.sendMessage(LanguageUtils.getMessage(Message.NO_PERMISSION_REMOVE_OTHERS));
        return;
    }

    plugin.debug(executor.getName() + " is removing " + shop.getVendor().getName() + "'s shop (#" + shop.getID() + ")");
    ShopRemoveEvent event = new ShopRemoveEvent(executor, shop);
    Bukkit.getPluginManager().callEvent(event);
    if (event.isCancelled()) {
        plugin.debug("Remove event cancelled (#" + shop.getID() + ")");
        return;
    }

    double creationPrice = shop.getShopType() == ShopType.ADMIN ? Config.shopCreationPriceAdmin : Config.shopCreationPriceNormal;
    if (creationPrice > 0 && Config.refundShopCreation && executor.getUniqueId().equals(shop.getVendor().getUniqueId())) {
        EconomyResponse r = plugin.getEconomy().depositPlayer(executor, shop.getLocation().getWorld().getName(), creationPrice);
        if (!r.transactionSuccess()) {
            plugin.debug("Economy transaction failed: " + r.errorMessage);
            executor.sendMessage(LanguageUtils.getMessage(Message.ERROR_OCCURRED,
                    new Replacement(Placeholder.ERROR, r.errorMessage)));
            executor.sendMessage(LanguageUtils.getMessage(Message.SHOP_REMOVED_REFUND,
                    new Replacement(Placeholder.CREATION_PRICE, 0)));
        } else {
            executor.sendMessage(LanguageUtils.getMessage(Message.SHOP_REMOVED_REFUND,
                new Replacement(Placeholder.CREATION_PRICE, creationPrice)));
        }
    } else {
        executor.sendMessage(LanguageUtils.getMessage(Message.SHOP_REMOVED));
    }

    shopUtils.removeShop(shop, true);
    plugin.debug("Removed shop (#" + shop.getID() + ")");
}
 
Example 16
Source File: CmdAdd.java    From PlotMe-Core with GNU General Public License v3.0 4 votes vote down vote up
public boolean execute(ICommandSender sender, String[] args) {
    if (args.length != 2) {
        sender.sendMessage(getUsage());
        return true;
    }
    if ("*".equals(args[1]) && plugin.getConfig().getBoolean("disableWildCard")) {
        sender.sendMessage(C("WildcardsDisabled"));
        return true;
    }

    //Start of the actual command
    IPlayer player = (IPlayer) sender;
    if (player.hasPermission(PermissionNames.ADMIN_ADD) || player.hasPermission(PermissionNames.USER_ADD)) {
        IWorld world = player.getWorld();
        if (manager.isPlotWorld(player)) {
            PlotMapInfo pmi = manager.getMap(world);
            Plot plot = manager.getPlot(player);
            if (plot != null) {
                String allowed;
                if ("*".equals(args[1])) {
                    allowed = "*";
                } else {
                    if (serverBridge.getPlayer(args[1]) != null) {
                        allowed = serverBridge.getPlayer(args[1]).getUniqueId().toString();
                    } else {
                        player.sendMessage(String.format("%s was not found. Are they online?", args[1]));
                        return true;
                    }
                }
                if (player.getUniqueId().equals(plot.getOwnerId()) || player.hasPermission(PermissionNames.ADMIN_ADD)) {
                    if (plot.isMember(allowed).isPresent()) {
                        player.sendMessage(C("MsgAlreadyAllowed", args[1]));
                    } else {
                        PlotAddTrustedEvent event = new PlotAddTrustedEvent(plot, player, allowed);
                        plugin.getEventBus().post(event);
                        double price = 0.0;
                        if (manager.isEconomyEnabled(pmi)) {
                            price = pmi.getAddPlayerPrice();

                            if (serverBridge.has(player, pmi.getAddPlayerPrice())) {
                                player.sendMessage("It costs " + serverBridge.getEconomy().get().format(price) + " to add a player to "
                                        + "the plot.");
                                return true;
                            } else if (!event.isCancelled()) {
                                EconomyResponse er = serverBridge.withdrawPlayer(player, price);

                                if (!er.transactionSuccess()) {
                                    player.sendMessage(er.errorMessage);
                                    serverBridge.getLogger().warning(er.errorMessage);
                                    return true;
                                }
                            }
                        }

                        if (!event.isCancelled()) {
                            plot.addMember(allowed, Plot.AccessLevel.ALLOWED);
                            plot.removeDenied(allowed);
                            plugin.getSqlManager().savePlot(plot);
                            player.sendMessage(C("MsgNowAllowed", args[1]));

                            if (isAdvancedLogging()) {
                                if (price == 0) {
                                    serverBridge.getLogger()
                                            .info(player.getName() + " " + C("MsgAddedPlayer") + " " + args[1] + " " + C("MsgToPlot")
                                                    + " "
                                                    + plot.getId());
                                } else {
                                    serverBridge.getLogger()
                                            .info(player.getName() + " " + C("MsgAddedPlayer") + " " + args[1] + " " + C("MsgToPlot")
                                                    + " "
                                                    + plot.getId() + (" " + C("WordFor") + " " + price));
                                }
                            }
                        }
                    }
                } else {
                    player.sendMessage(C("MsgThisPlot") + "(" + plot.getId() + ") " + C("MsgNotYoursNotAllowedAdd"));
                }
            } else {
                player.sendMessage(C("NoPlotFound"));
            }
        } else {
            player.sendMessage(C("NotPlotWorld"));
            return true;
        }
    } else {
        return false;
    }
    return true;
}
 
Example 17
Source File: PWIPlayerManager.java    From PerWorldInventory with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Get a player from the cache, and apply the cached inventories and stats
 * to the actual player. If no matching player is found in the cache, nothing
 * happens and this method simply returns.
 *
 * @param group The {@link Group} the cached player was in.
 * @param gamemode The GameMode the cached player was in.
 * @param player The current actual player to apply the data to.
 * @param cause What triggered the inventory switch; passed on for post-processing.
 */
private void getDataFromCache(Group group, GameMode gamemode, Player player, DeserializeCause cause) {
    PWIPlayer cachedPlayer = getCachedPlayer(group, gamemode, player.getUniqueId());
    if (cachedPlayer == null) {
        ConsoleLogger.debug("No data for player '" + player.getName() + "' found in cache");

        return;
    }

    ConsoleLogger.debug("Player '" + player.getName() + "' found in cache! Setting their data");

    if (settings.getProperty(PwiProperties.LOAD_ENDER_CHESTS))
        player.getEnderChest().setContents(cachedPlayer.getEnderChest());
    if (settings.getProperty(PwiProperties.LOAD_INVENTORY)) {
        player.getInventory().setContents(cachedPlayer.getInventory());
        player.getInventory().setArmorContents(cachedPlayer.getArmor());
    }
    if (settings.getProperty(PwiProperties.LOAD_CAN_FLY))
        player.setAllowFlight(cachedPlayer.getCanFly());
    if (settings.getProperty(PwiProperties.LOAD_DISPLAY_NAME))
        player.setDisplayName(cachedPlayer.getDisplayName());
    if (settings.getProperty(PwiProperties.LOAD_EXHAUSTION))
        player.setExhaustion(cachedPlayer.getExhaustion());
    if (settings.getProperty(PwiProperties.LOAD_EXP))
        player.setExp(cachedPlayer.getExperience());
    if (settings.getProperty(PwiProperties.LOAD_FLYING) && player.getAllowFlight())
        player.setFlying(cachedPlayer.isFlying());
    if (settings.getProperty(PwiProperties.LOAD_HUNGER))
        player.setFoodLevel(cachedPlayer.getFoodLevel());
    if (settings.getProperty(PwiProperties.LOAD_HEALTH)) {
        if (bukkitService.shouldUseAttributes()) {
            player.getAttribute(Attribute.GENERIC_MAX_HEALTH).setBaseValue(cachedPlayer.getMaxHealth());
        } else {
            player.setMaxHealth(cachedPlayer.getMaxHealth());
        }
        if (cachedPlayer.getHealth() > 0 && cachedPlayer.getHealth() <= cachedPlayer.getMaxHealth()) {
            player.setHealth(cachedPlayer.getHealth());
        } else {
            player.setHealth(cachedPlayer.getMaxHealth());
        }
    }
    if (settings.getProperty(PwiProperties.LOAD_GAMEMODE) && (!settings.getProperty(PwiProperties.SEPARATE_GAMEMODE_INVENTORIES)))
        player.setGameMode(cachedPlayer.getGamemode());
    if (settings.getProperty(PwiProperties.LOAD_LEVEL))
        player.setLevel(cachedPlayer.getLevel());
    if (settings.getProperty(PwiProperties.LOAD_POTION_EFFECTS)) {
        for (PotionEffect effect : player.getActivePotionEffects()) {
            player.removePotionEffect(effect.getType());
        }
        player.addPotionEffects(cachedPlayer.getPotionEffects());
    }
    if (settings.getProperty(PwiProperties.LOAD_SATURATION))
        player.setSaturation(cachedPlayer.getSaturationLevel());
    if (settings.getProperty(PwiProperties.LOAD_FALL_DISTANCE))
        player.setFallDistance(cachedPlayer.getFallDistance());
    if (settings.getProperty(PwiProperties.LOAD_FIRE_TICKS))
        player.setFireTicks(cachedPlayer.getFireTicks());
    if (settings.getProperty(PwiProperties.LOAD_MAX_AIR))
        player.setMaximumAir(cachedPlayer.getMaxAir());
    if (settings.getProperty(PwiProperties.LOAD_REMAINING_AIR))
        player.setRemainingAir(cachedPlayer.getRemainingAir());
    if (settings.getProperty(PwiProperties.USE_ECONOMY)) {
        Economy econ = plugin.getEconomy();
        if (econ == null) {
            ConsoleLogger.warning("Economy saving is turned on, but no economy found!");
            return;
        }

        EconomyResponse er = econ.withdrawPlayer(player, econ.getBalance(player));
        if (er.transactionSuccess()) {
            econ.depositPlayer(player, cachedPlayer.getBalance());
        } else {
            ConsoleLogger.warning("[ECON] Unable to withdraw currency from '" + player.getName() + "': " + er.errorMessage);
        }

        EconomyResponse bankER = econ.bankWithdraw(player.getName(), econ.bankBalance(player.getName()).amount);
        if (bankER.transactionSuccess()) {
            econ.bankDeposit(player.getName(), cachedPlayer.getBankBalance());
        } else {
            ConsoleLogger.warning("[ECON] Unable to withdraw currency from bank of '" + player.getName() + "': " + er.errorMessage);
        }
    }

    InventoryLoadCompleteEvent event = new InventoryLoadCompleteEvent(player, cause);
    Bukkit.getPluginManager().callEvent(event);
}
 
Example 18
Source File: OffsetBounty.java    From GlobalWarming with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 * Create a new bounty
 * - Players are limited to how many bounties they can create
 * - Requires an economy-plugin account with an adequate balance
 * - Requires a minimum of 1 block and a $1 reward
 */
public static void create(GPlayer gPlayer, int treeBlocks, int reward) {
    OffsetTable offsetTable = GlobalWarming.getInstance().getTableManager().getOffsetTable();
    if (offsetTable.getIncompleteBountyCount(gPlayer) >= MAX_BOUNTIES_CREATED_PER_PLAYER) {
        gPlayer.sendMsg(Lang.BOUNTY_MAXCREATED);
    } else if (treeBlocks < 1) {
        gPlayer.sendMsg(Lang.BOUNTY_BLOCKSREQUIRED);
    } else if (reward < 1) {
        gPlayer.sendMsg(Lang.BOUNTY_REWARDREQUIRED);
    } else {
        //Withdraw from account:
        boolean isWithdrawn = false;
        double balance = 0;
        Economy economy = GlobalWarming.getInstance().getEconomy();
        if (economy != null) {
            EconomyResponse response = economy.withdrawPlayer(gPlayer.getOfflinePlayer(), reward);
            isWithdrawn = response.transactionSuccess();
            balance = economy.getBalance(gPlayer.getOfflinePlayer());
        }

        if (isWithdrawn) {
            //New bounty:
            OffsetBounty bounty = new OffsetBounty(
                    GlobalWarming.getInstance().getRandom().nextInt(Integer.MAX_VALUE),
                    gPlayer.getUniqueId(),
                    null,
                    gPlayer.getAssociatedWorldId(),
                    treeBlocks,
                    reward,
                    0,
                    0
            );

            //Local records:
            offsetTable.addOffset(bounty);

            //Database:
            OffsetInsertQuery insertQuery = new OffsetInsertQuery(bounty);
            AsyncDBQueue.getInstance().queueInsertQuery(insertQuery);

            //Notify:
            gPlayer.sendMsg(String.format(Lang.BOUNTY_CREATED.get(), balance));
        } else {
            //Notify:
            // - Not enough funds or economy plugin issue
            gPlayer.sendMsg(String.format(Lang.BOUNTY_NOTCREATED.get(), balance));
        }
    }
}
 
Example 19
Source File: CmdDispose.java    From PlotMe-Core with GNU General Public License v3.0 4 votes vote down vote up
public boolean execute(ICommandSender sender, String[] args) {
    if (args.length > 1) {
        sender.sendMessage(getUsage());
        return true;
    }
    IPlayer player = (IPlayer) sender;
    if (player.hasPermission(PermissionNames.ADMIN_DISPOSE) || player.hasPermission(PermissionNames.USER_DISPOSE)) {
        IWorld world = player.getWorld();
        PlotMapInfo pmi = manager.getMap(world);
        if (manager.isPlotWorld(world)) {
            Plot plot = manager.getPlot(player);

            if (plot != null) {
                if (plot.isProtected()) {
                    player.sendMessage(C("MsgPlotProtectedNotDisposed"));
                } else if (player.getUniqueId().equals(plot.getOwnerId()) || player.hasPermission(PermissionNames.ADMIN_DISPOSE)) {

                    double cost = pmi.getDisposePrice();

                    PlotDisposeEvent event = new PlotDisposeEvent(plot, player);

                    if (manager.isEconomyEnabled(pmi)) {
                        if (serverBridge.has(player, cost)) {
                            player.sendMessage(C("MsgNotEnoughDispose"));
                            return true;
                        }

                        plugin.getEventBus().post(event);

                        if (event.isCancelled()) {
                            return true;
                        }
                        EconomyResponse economyResponse = serverBridge.withdrawPlayer(player, cost);

                        if (!economyResponse.transactionSuccess()) {
                            player.sendMessage(economyResponse.errorMessage);
                            plugin.getLogger().warning(economyResponse.errorMessage);
                            return true;
                        }
                    } else {
                        plugin.getEventBus().post(event);
                    }

                    if (!event.isCancelled()) {
                        manager.adjustWall(plot, false);
                        if (manager.deletePlot(plot)) {
                            player.sendMessage(C("PlotDisposed"));
                        } else {
                            player.sendMessage("Plot was not disposed? Something stopped this command.");
                        }

                        if (isAdvancedLogging()) {
                            plugin.getLogger().info(player.getName() + " " + C("MsgDisposedPlot") + " " + plot.getId());
                        }
                    }
                } else {
                    player.sendMessage(C("MsgThisPlot") + "(" + plot.getId() + ") " + C("MsgNotYoursCannotDispose"));
                }
            }
        } else {
            player.sendMessage(C("NotPlotWorld"));
        }
    } else {
        return false;
    }
    return true;
}
 
Example 20
Source File: TaxApplyTask.java    From GriefDefender with MIT License 4 votes vote down vote up
private void handleClaimTax(GDClaim claim, GDPlayerData playerData, boolean inTown) {
    final GDPermissionUser user = PermissionHolderCache.getInstance().getOrCreateUser(playerData.getUniqueId());
    final OfflinePlayer player = user.getOfflinePlayer();
    double taxRate = GDPermissionManager.getInstance().getInternalOptionValue(TypeToken.of(Double.class), user, Options.TAX_RATE, claim);
    double taxOwed = claim.getEconomyData().getTaxBalance() + (claim.getClaimBlocks() * taxRate);
    GDTaxClaimEvent event = new GDTaxClaimEvent(claim, taxRate, taxOwed);
    GriefDefender.getEventManager().post(event);
    if (event.cancelled()) {
        return;
    }
    final double taxBalance = claim.getEconomyData().getTaxBalance();
    taxRate = event.getTaxRate();
    taxOwed = taxBalance + (claim.getClaimBlocks() * taxRate);
    final EconomyResponse response = EconomyUtil.getInstance().withdrawFunds(player, taxOwed);
    if (!response.transactionSuccess()) {
        final Instant localNow = Instant.now();
        Instant taxPastDueDate = claim.getEconomyData().getTaxPastDueDate();
        if (taxPastDueDate == null) {
            claim.getEconomyData().setTaxPastDueDate(Instant.now());
        } else {
            final int taxExpirationDays = GDPermissionManager.getInstance().getInternalOptionValue(TypeToken.of(Integer.class), user, Options.TAX_EXPIRATION, claim).intValue();
            if (taxExpirationDays > 0) {
                claim.getInternalClaimData().setExpired(true);
                if (taxExpirationDays == 0) {
                    claim.getInternalClaimData().setExpired(true);
                    claim.getData().save();
                } else if (taxPastDueDate.plus(Duration.ofDays(taxExpirationDays)).isBefore(localNow)) {
                    claim.getInternalClaimData().setExpired(true);
                    claim.getData().save();
                }
            }
        }
        final double totalTaxOwed = taxBalance + taxOwed;
        claim.getEconomyData().setTaxBalance(totalTaxOwed);
        claim.getEconomyData().addPaymentTransaction(new GDPaymentTransaction(TransactionType.TAX, TransactionResultType.FAIL, Instant.now(), taxOwed));
    } else {
        claim.getEconomyData().addPaymentTransaction(new GDPaymentTransaction(TransactionType.TAX, TransactionResultType.SUCCESS, Instant.now(), taxOwed));
        claim.getEconomyData().setTaxPastDueDate(null);
        claim.getEconomyData().setTaxBalance(0);
        claim.getInternalClaimData().setExpired(false);

        if (inTown) {
            final GDClaim town = claim.getTownClaim();
            town.getData()
                .getEconomyData()
                .addPaymentTransaction(new GDPaymentTransaction(TransactionType.TAX, TransactionResultType.SUCCESS, Instant.now(), taxOwed));
            if (town.getEconomyAccountId().isPresent()) {
                this.economy.bankDeposit(town.getEconomyAccountId().get().toString(), taxOwed);
            }
        }
        claim.getData().save();
    }
}