Mineplex2018-withcommit/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/economy/GoldManager.java

129 lines
3.7 KiB
Java
Raw Normal View History

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.account.CoreClientManager;
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.clans.ClansManager;
import mineplex.game.clans.fields.repository.FieldRepository;
import mineplex.game.clans.items.generation.WeightSet;
import mineplex.game.clans.shop.bank.BankShop;
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;
private BankShop _bankShop;
public GoldManager(ClansManager plugin, CoreClientManager clientManager, DonationManager donationManager)
{
super("Clans Gold", plugin.getPlugin());
_instance = this;
_donationManager = donationManager;
_bankShop = new BankShop(plugin, clientManager, 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");
addGold(event.getPlayer(), 100000);
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));
}
public void purchaseToken(Player player, int tokenValue)
{
GoldToken token = new GoldToken(tokenValue);
deductGold(player, tokenValue);
player.getInventory().addItem(token.toItemStack());
notify(player, String.format("You have purchased a gold token worth %dg!", tokenValue));
}
private Donor getDonor(Player player)
{
return _donationManager.Get(player.getName());
}
private void notify(Player player, String message)
{
UtilPlayer.message(player, F.main("Gold", message));
}
}