Advertisement
riking

Untitled

Dec 2nd, 2013
475
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5.54 KB | None | 0 0
  1. package com.limegaming.gnarusly.GhostOnDeath;
  2.  
  3. import java.util.HashSet;
  4. import java.util.Set;
  5.  
  6. import org.bukkit.Bukkit;
  7. import org.bukkit.Material;
  8. import org.bukkit.entity.Entity;
  9. import org.bukkit.entity.LivingEntity;
  10. import org.bukkit.entity.Player;
  11. import org.bukkit.entity.Projectile;
  12. import org.bukkit.entity.ThrownPotion; //Not used yet
  13. import org.bukkit.event.EventHandler;
  14. import org.bukkit.event.Listener;
  15. import org.bukkit.event.entity.EntityDamageByEntityEvent;
  16. import org.bukkit.event.entity.PlayerDeathEvent;
  17. import org.bukkit.event.entity.PotionSplashEvent;
  18. import org.bukkit.event.player.PlayerBucketEmptyEvent;
  19. import org.bukkit.event.player.PlayerJoinEvent;
  20. import org.bukkit.potion.PotionEffectType;
  21. import org.bukkit.scheduler.BukkitRunnable;
  22. import org.bukkit.ChatColor;
  23.  
  24. public class GhostOnDeathListener implements Listener {
  25.    
  26.     public Set<String> list = new HashSet<String>();
  27.  
  28.     private class RemoveNameTask extends BukkitRunnable {
  29.         private final String victimName;
  30.         public RemoveNameTask(String name) { victimName = name; }
  31.  
  32.         @Override
  33.         public void run() {
  34.             GhostOnDeathListener.this.list.remove(victimName);
  35.             Bukkit.broadcastMessage("[");
  36.         }
  37.     }
  38.    
  39.     @EventHandler  
  40.     public void onDeath(PlayerDeathEvent event) {      
  41.         Player victim = (Player) event.getEntity();      
  42.         if (victim.getKiller() != null) {          
  43.             Player killer = victim.getKiller();      
  44.             final String victimName = ((Player) victim).getPlayer().getName();
  45.             //Not done yet, going to import DC and magic API
  46.            
  47.            
  48.             victim.sendMessage("You are the victim!");          
  49.             killer.sendMessage("You are the killer!");
  50.            
  51.             /* Adds user to list of victims */
  52.             list.add(victimName);
  53.            
  54.             /* Makes user into a ghost */
  55.             GhostOnDeathMain.ghostFactory.setGhost(victim, true);
  56.             GhostOnDeathMain.ghostFactory.addPlayer(killer);
  57.            
  58.             new RemoveNameTask(victimName).runTaskLater(GhostOnDeathMain.getPlugin(), 24000);
  59.         }
  60.     }
  61.    
  62.    
  63.     @EventHandler
  64.     public static void onPvP(EntityDamageByEntityEvent event) {
  65.         if ((event.getEntity() instanceof Player)) {
  66.             /* Checks to see if the damager is a player */
  67.             if (event.getDamager() instanceof Player) {
  68.                 Entity victim = event.getEntity();
  69.                 Player killer = (Player)event.getDamager();
  70.                 String killer2 = killer.getName();
  71.                 String victimName = ((Player) victim).getPlayer().getName();
  72.                 if (list.contains(victimName)) {
  73.                      /* Outputs message that you can't attack protected user */
  74.                     killer.sendMessage("That player is under PVP protection. Do not attempt to kill them.");
  75.                     /* Stops Killer from hurting them. */
  76.                     event.setCancelled(true);
  77.                 }
  78.                 else if (list.contains(killer2)) {
  79.                     killer.sendMessage("You're under PVP Protection. Do not PVP.");
  80.                     event.setCancelled(true);
  81.                 }
  82.             }
  83.            
  84.             else if (event.getDamager() instanceof Projectile) {
  85.              /* Checks to see if the damager is a projectile */
  86.              LivingEntity shooter = ((Projectile)event.getDamager()).getShooter();
  87.              /*Checks to see if the person shot is a player
  88.               *  and the shooter is a player. */
  89.              if (shooter instanceof Player && event.getEntity() instanceof Player) {
  90.                      Player killer = (Player)shooter;
  91.                      String killerName = ((Player) killer).getPlayer().getName();
  92.                      Entity victim = (Player) event.getEntity();
  93.                      String victimName = ((Player) victim).getPlayer().getName();
  94.                      /*Checks to see if victim died*/
  95.                      if (list.contains(victimName)) {
  96.                          /*Stops killer from hurting them*/
  97.                          event.setCancelled(true);
  98.                          killer.sendMessage("That player is under PVP protection. Do not attempt to kill them.");
  99.                      }
  100.                      else if (list.contains(killerName)) {
  101.                          killer.sendMessage("You're under PVP Protection. Do not PVP.");
  102.                          event.setCancelled(true);
  103.                          
  104.                      }
  105.                      
  106.              }
  107.             }
  108.         }
  109.     }
  110.     @EventHandler
  111.     public static void onPlayerJoin(PlayerJoinEvent event) {
  112.         Player player = event.getPlayer();
  113.         String playerName = event.getPlayer().getName();
  114.         if (list.contains(playerName)) {
  115.             GhostOnDeathMain.ghostFactory.setGhost(player, true);
  116.         }
  117.         else {
  118.             GhostOnDeathMain.ghostFactory.setGhost(player, false);
  119.             player.removePotionEffect(PotionEffectType.INVISIBILITY);
  120.         }
  121.        
  122.     }
  123.     @EventHandler
  124.     public void onPlayerBucketEmpty(PlayerBucketEmptyEvent event) {
  125.         Player player = event.getPlayer();
  126.         String playerName = event.getPlayer().getName();
  127.         if (list.contains(playerName)) {
  128.             Material bucket = event.getBucket();
  129.             if (bucket.toString().contains("LAVA")) {
  130.                 event.setCancelled(true);
  131.                 player.sendMessage("You can't use a lava bucket while under PVP protection!");
  132.             }
  133.              
  134.             if (bucket.toString().contains("WATER")) {
  135.                 //nothing
  136.         }
  137.         }
  138.     }
  139.    
  140.     @EventHandler
  141.     public void PotionHit(PotionSplashEvent event){
  142.         Entity damager = event.getPotion().getShooter();
  143.             if (damager instanceof Player){
  144.                 for(LivingEntity player : event.getAffectedEntities()){
  145.                     if(player instanceof Player){
  146.                         Player playerName = (Player) player;
  147.                        
  148.                         //not finished yet
  149.                        
  150.                     }
  151.                 }
  152.             }
  153.     }
  154. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement