package mineplex.game.clans.economy; import java.util.Random; import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.World; import org.bukkit.entity.Entity; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.block.BlockBreakEvent; import org.bukkit.event.entity.EntityDamageByEntityEvent; import org.bukkit.event.entity.PlayerDeathEvent; import org.bukkit.event.player.PlayerCommandPreprocessEvent; import org.bukkit.event.player.PlayerRespawnEvent; import org.bukkit.plugin.java.JavaPlugin; import mineplex.game.clans.items.economy.GoldToken; import mineplex.core.MiniPlugin; import mineplex.core.common.CurrencyType; import mineplex.core.common.util.C; import mineplex.core.common.util.F; import mineplex.core.common.util.UtilPlayer; import mineplex.core.creature.Creature; import mineplex.core.donation.DonationManager; import mineplex.core.donation.Donor; import mineplex.core.energy.Energy; import mineplex.game.clans.Clans; import mineplex.game.clans.fields.repository.FieldRepository; import mineplex.game.clans.items.generation.WeightSet; import mineplex.minecraft.game.core.condition.ConditionFactory; import mineplex.minecraft.game.core.condition.ConditionManager; public class GoldManager extends MiniPlugin { public static final double DEATH_TAX = 0.04d; // Percentage of gold lost on death private static GoldManager _instance; public static GoldManager getInstance() { return _instance; } private DonationManager _donationManager; public GoldManager(JavaPlugin plugin, DonationManager donationManager) { super("Clans Gold", plugin); _instance = this; _donationManager = donationManager; } @EventHandler public void onPlayerDeath(PlayerDeathEvent event) { Player player = event.getEntity(); Player killer = player.getKiller(); int gold = getGold(player); int droppedGold = (int) (gold * DEATH_TAX); if (droppedGold > 0) { deductGold(player, droppedGold); notify(player, String.format("You dropped %d gold on your death!", droppedGold)); if (killer != null) { addGold(killer, droppedGold); notify(killer, String.format("You looted %d gold off of %s's corpse!", droppedGold, player.getName())); } } } @EventHandler public void playerCmd(PlayerCommandPreprocessEvent event) { if (event.getMessage().startsWith("/gold")) { notify(event.getPlayer(), "Your Balance is " + C.cYellow + getGold(event.getPlayer()) + "g"); event.setCancelled(true); } } public int getGold(Player player) { return getDonor(player).getGold(); } public void addGold(Player player, int amount) { getDonor(player).addGold(amount); } public void deductGold(Player player, int amount) { addGold(player, -amount); } public void cashIn(Player player, GoldToken token) { int value = token.getGoldValue(); addGold(player, value); notify(player, String.format("You have cashed in a gold token worth %dg!", value)); } private Donor getDonor(Player player) { return _donationManager.Get(player.getName()); } private void notify(Player player, String message) { UtilPlayer.message(player, F.main("Gold", message)); } }