Advertisement
Guest User

Untitled

a guest
Jul 17th, 2011
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 4.90 KB | None | 0 0
  1. package me.patrickfreed.iCotestConfig;
  2. import java.util.ArrayList;
  3. import org.bukkit.entity.Entity;
  4. import org.bukkit.entity.Player;
  5. import org.bukkit.event.entity.EntityDamageByProjectileEvent;
  6. import com.iConomy.*;
  7. import com.iConomy.system.Account;
  8. import com.iConomy.system.Holdings;
  9.  
  10. import org.bukkit.event.entity.EntityDamageByEntityEvent;
  11. import org.bukkit.event.entity.EntityDamageEvent;
  12. import org.bukkit.event.entity.EntityDeathEvent;
  13. import org.bukkit.event.entity.EntityListener;
  14. public class iConomyPungaEntityListener extends EntityListener {
  15.     public ArrayList<String> lastDamagePlayer = new ArrayList<String>();
  16.     public ArrayList<String> lastDamageType = new ArrayList<String>();
  17.     public Player pvper;
  18.     public double amount=0;
  19.     public double porcentaje;
  20.     RandomPercentGenerator randp = new RandomPercentGenerator();
  21.     RandomAmountGenerator randa = new RandomAmountGenerator();
  22.     private final iConomyPunga instance;
  23.     public iConomyPungaEntityListener(iConomyPunga instance) {
  24.     this.instance = instance;
  25.     }
  26.     public void onEntityDamage(EntityDamageEvent event) {
  27.         if(event.getEntity() instanceof Player) {
  28.         Player player = (Player) event.getEntity();
  29.         lastDamageDone(player, event);
  30.         }
  31.         }
  32.    
  33.     public void lastDamageDone(Player player, EntityDamageEvent event) {
  34.         String lastdamage = event.getCause().name();
  35.         Entity attacker;
  36.         pvper=null;
  37.         if (event instanceof EntityDamageByProjectileEvent) {
  38.         EntityDamageByProjectileEvent mobevent = (EntityDamageByProjectileEvent) event;
  39.         attacker = mobevent.getDamager();
  40.         if (attacker instanceof Player) {
  41.         pvper = (Player) attacker;
  42.         }
  43.         }
  44.         else if (event instanceof EntityDamageByEntityEvent) {
  45.         EntityDamageByEntityEvent mobevent = (EntityDamageByEntityEvent) event;
  46.         attacker = mobevent.getDamager();
  47.  
  48.         if (attacker instanceof Player) {
  49.         pvper = (Player) attacker;
  50.         lastdamage = "PVP:"+pvper.getName();
  51.         }
  52.  
  53.         }
  54.  
  55.         if (!lastDamagePlayer.contains(player.getName())) {
  56.         lastDamagePlayer.add(player.getName());
  57.         lastDamageType.add(event.getCause().name());
  58.         }
  59.         else {
  60.         lastDamageType.set(lastDamagePlayer.indexOf(player.getName()), lastdamage);
  61.         }
  62.             }  
  63.            
  64.    
  65.     public void onEntityDeath(EntityDeathEvent event) {
  66.         String damagetype=null;
  67.             if (event.getEntity() instanceof Player) {
  68.             Player player = (Player) event.getEntity();
  69.             try {
  70.                 damagetype = lastDamageType.get(lastDamagePlayer.indexOf(player.getName()));
  71.              } //try
  72.             catch (ArrayIndexOutOfBoundsException ex){
  73.                 damagetype = null;
  74.             } //catch
  75.             String[] howtheydied=null;
  76.             if (damagetype!=null){
  77.             howtheydied = damagetype.split(":");
  78.             if (howtheydied[0].matches("PVP")) {   
  79.                 if (iConomy.hasAccount(player.getName())&&iConomy.hasAccount(pvper.getName())) {
  80.                     if (iConomyPunga.hasPermissions(player, "iConomyPunga.use")&&iConomyPunga.hasPermissions(pvper, "iConomyPunga.use")) {
  81.  
  82.  
  83.                             Account account1 = iConomy.getAccount(player.getName());
  84.                             Account account2 = iConomy.getAccount(pvper.getName());
  85.          
  86.                             Holdings account1balance = account1.getHoldings();
  87.                             Holdings account2balance = account2.getHoldings();
  88.                            
  89.                             if (instance.mode.compareToIgnoreCase("random percentage") == 0){
  90.                                 this.porcentaje = randp.getNumber();
  91.                                 System.out.println(this.porcentaje);
  92.                                 this.amount = (porcentaje*account1balance.balance())/100;
  93.                             }
  94.                             else if (instance.mode.compareToIgnoreCase("static percentage") == 0){
  95.                                 this.porcentaje=Double.valueOf(iConomyPunga.pconfig.get("Percentage").trim()).doubleValue();
  96.                                 this.amount = (porcentaje*account1balance.balance())/100;
  97.                             }
  98.                             else if (instance.mode.compareToIgnoreCase("Static Amount")== 0){
  99.                                 this.amount = instance.staticAmount;
  100.                             }
  101.                             else if (instance.mode.compareToIgnoreCase("Random Amount")== 0){
  102.                                 this.amount = randa.getNumber();
  103.                             }
  104.                             else{
  105.                                 System.out.println("Invalid Mode, defaulting to static amount of 1.");
  106.                                 this.amount = 1;
  107.                             }
  108.                            
  109.                
  110.  
  111.                     account1balance.subtract(amount);
  112.                     account2balance.add(amount);                   
  113.                     String Attacker = instance.kill_msg.replace("%d", player.getName());
  114.                     String Dead = instance.death_msg.replace("%d", player.getName());  
  115.                    
  116.                     Attacker = Attacker.replace("%a", pvper.getName());
  117.                     Dead = Dead.replace("%a", pvper.getName());
  118.                    
  119.                     Attacker = Attacker.replace("%n", iConomy.format(amount));
  120.                     Dead = Dead.replace("%n", iConomy.format(amount));
  121.                    
  122.                     pvper.sendMessage(Attacker + "Noob");              
  123.                     player.sendMessage(Dead + "Noob");    
  124.                     try {damagetype = null;
  125.                         }
  126.                     catch (NullPointerException ex){
  127.                         damagetype = null; }
  128.                     }
  129.                     }
  130.                     }
  131.                     }      
  132.             }
  133.            
  134.             }
  135.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement