Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package me.patrickfreed.iCotestConfig;
- import java.util.ArrayList;
- import org.bukkit.entity.Entity;
- import org.bukkit.entity.Player;
- import org.bukkit.event.entity.EntityDamageByProjectileEvent;
- import com.iConomy.*;
- import com.iConomy.system.Account;
- import com.iConomy.system.Holdings;
- import org.bukkit.event.entity.EntityDamageByEntityEvent;
- import org.bukkit.event.entity.EntityDamageEvent;
- import org.bukkit.event.entity.EntityDeathEvent;
- import org.bukkit.event.entity.EntityListener;
- public class iConomyPungaEntityListener extends EntityListener {
- public ArrayList<String> lastDamagePlayer = new ArrayList<String>();
- public ArrayList<String> lastDamageType = new ArrayList<String>();
- public Player pvper;
- public double amount=0;
- public double porcentaje;
- RandomPercentGenerator randp = new RandomPercentGenerator();
- RandomAmountGenerator randa = new RandomAmountGenerator();
- private final iConomyPunga instance;
- public iConomyPungaEntityListener(iConomyPunga instance) {
- this.instance = instance;
- }
- public void onEntityDamage(EntityDamageEvent event) {
- if(event.getEntity() instanceof Player) {
- Player player = (Player) event.getEntity();
- lastDamageDone(player, event);
- }
- }
- public void lastDamageDone(Player player, EntityDamageEvent event) {
- String lastdamage = event.getCause().name();
- Entity attacker;
- pvper=null;
- if (event instanceof EntityDamageByProjectileEvent) {
- EntityDamageByProjectileEvent mobevent = (EntityDamageByProjectileEvent) event;
- attacker = mobevent.getDamager();
- if (attacker instanceof Player) {
- pvper = (Player) attacker;
- }
- }
- else if (event instanceof EntityDamageByEntityEvent) {
- EntityDamageByEntityEvent mobevent = (EntityDamageByEntityEvent) event;
- attacker = mobevent.getDamager();
- if (attacker instanceof Player) {
- pvper = (Player) attacker;
- lastdamage = "PVP:"+pvper.getName();
- }
- }
- if (!lastDamagePlayer.contains(player.getName())) {
- lastDamagePlayer.add(player.getName());
- lastDamageType.add(event.getCause().name());
- }
- else {
- lastDamageType.set(lastDamagePlayer.indexOf(player.getName()), lastdamage);
- }
- }
- public void onEntityDeath(EntityDeathEvent event) {
- String damagetype=null;
- if (event.getEntity() instanceof Player) {
- Player player = (Player) event.getEntity();
- try {
- damagetype = lastDamageType.get(lastDamagePlayer.indexOf(player.getName()));
- } //try
- catch (ArrayIndexOutOfBoundsException ex){
- damagetype = null;
- } //catch
- String[] howtheydied=null;
- if (damagetype!=null){
- howtheydied = damagetype.split(":");
- if (howtheydied[0].matches("PVP")) {
- if (iConomy.hasAccount(player.getName())&&iConomy.hasAccount(pvper.getName())) {
- if (iConomyPunga.hasPermissions(player, "iConomyPunga.use")&&iConomyPunga.hasPermissions(pvper, "iConomyPunga.use")) {
- Account account1 = iConomy.getAccount(player.getName());
- Account account2 = iConomy.getAccount(pvper.getName());
- Holdings account1balance = account1.getHoldings();
- Holdings account2balance = account2.getHoldings();
- if (instance.mode.compareToIgnoreCase("random percentage") == 0){
- this.porcentaje = randp.getNumber();
- System.out.println(this.porcentaje);
- this.amount = (porcentaje*account1balance.balance())/100;
- }
- else if (instance.mode.compareToIgnoreCase("static percentage") == 0){
- this.porcentaje=Double.valueOf(iConomyPunga.pconfig.get("Percentage").trim()).doubleValue();
- this.amount = (porcentaje*account1balance.balance())/100;
- }
- else if (instance.mode.compareToIgnoreCase("Static Amount")== 0){
- this.amount = instance.staticAmount;
- }
- else if (instance.mode.compareToIgnoreCase("Random Amount")== 0){
- this.amount = randa.getNumber();
- }
- else{
- System.out.println("Invalid Mode, defaulting to static amount of 1.");
- this.amount = 1;
- }
- account1balance.subtract(amount);
- account2balance.add(amount);
- String Attacker = instance.kill_msg.replace("%d", player.getName());
- String Dead = instance.death_msg.replace("%d", player.getName());
- Attacker = Attacker.replace("%a", pvper.getName());
- Dead = Dead.replace("%a", pvper.getName());
- Attacker = Attacker.replace("%n", iConomy.format(amount));
- Dead = Dead.replace("%n", iConomy.format(amount));
- pvper.sendMessage(Attacker + "Noob");
- player.sendMessage(Dead + "Noob");
- try {damagetype = null;
- }
- catch (NullPointerException ex){
- damagetype = null; }
- }
- }
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement