|
| 1 | +package com.jcdesimp.landlord.landFlags; |
| 2 | + |
| 3 | +import com.jcdesimp.landlord.landManagement.Landflag; |
| 4 | +import com.jcdesimp.landlord.persistantData.OwnedLand; |
| 5 | +import org.bukkit.ChatColor; |
| 6 | +import org.bukkit.Material; |
| 7 | +import org.bukkit.entity.Player; |
| 8 | +import org.bukkit.entity.Projectile; |
| 9 | +import org.bukkit.event.EventHandler; |
| 10 | +import org.bukkit.event.EventPriority; |
| 11 | +import org.bukkit.event.entity.EntityDamageByEntityEvent; |
| 12 | +import org.bukkit.inventory.ItemStack; |
| 13 | + |
| 14 | +import java.util.Arrays; |
| 15 | + |
| 16 | +/** |
| 17 | + * File created by jcdesimp on 5/24/14. |
| 18 | + */ |
| 19 | + |
| 20 | +/* |
| 21 | + ******************************************************* |
| 22 | + * All flags need to extend the abstract Landflag class |
| 23 | + ******************************************************* |
| 24 | + */ |
| 25 | +public class PVP extends Landflag { |
| 26 | + |
| 27 | + public PVP() { |
| 28 | + super( |
| 29 | + "PVP", //Display name (will be displayed to players) |
| 30 | + "Gives permission to attack|" + |
| 31 | + "players on this land|" , |
| 32 | + new ItemStack(Material.IRON_SWORD), //Itemstack (represented in and manager) |
| 33 | + "Allowed PvP", //Text shown in manager for granted permission |
| 34 | + "can hurt other players.", //Description in manager for granted permission (ex: Friendly players <desc>) |
| 35 | + "Denied PvP", //Text shown in manager for denied permission |
| 36 | + "cannot hurt other players." //Desciption in manager for denied permission (ex: Regular players <desc>) |
| 37 | + ); |
| 38 | + } |
| 39 | + |
| 40 | + |
| 41 | + @EventHandler(priority = EventPriority.HIGH) |
| 42 | + public void playerDamage(EntityDamageByEntityEvent event){ |
| 43 | + //String[] safeAnimals = {"OCELOT","WOLF","HORSE","COW","PIG","MUSHROOM_COW","SHEEP","CHICKEN"}; |
| 44 | + org.bukkit.entity.Entity victim = event.getEntity(); |
| 45 | + if(!(victim instanceof Player)){ |
| 46 | + return; |
| 47 | + } |
| 48 | + |
| 49 | + |
| 50 | + org.bukkit.entity.Entity attacker = event.getDamager(); |
| 51 | + |
| 52 | + if(attacker.getType().toString().equals("PLAYER")){ |
| 53 | + Player p = (Player)attacker; |
| 54 | + OwnedLand land = OwnedLand.getApplicableLand(victim.getLocation()); |
| 55 | + if(land==null){ |
| 56 | + return; |
| 57 | + } |
| 58 | + if(!land.hasPermTo(p, this)){ |
| 59 | + |
| 60 | + p.sendMessage(ChatColor.RED+"You cannot harm other players on this land."); |
| 61 | + |
| 62 | + event.setCancelled(true); |
| 63 | + |
| 64 | + } |
| 65 | + |
| 66 | + } else if(attacker.getType().toString().equalsIgnoreCase("Arrow") || attacker.getType().toString().equalsIgnoreCase("SPLASH_POTION")){ |
| 67 | + Projectile a = (Projectile)attacker; |
| 68 | + Player p; |
| 69 | + if(a.getShooter() instanceof Player){ |
| 70 | + OwnedLand land = OwnedLand.getApplicableLand(victim.getLocation()); |
| 71 | + p = (Player)a.getShooter(); |
| 72 | + if(land==null){ |
| 73 | + return; |
| 74 | + } |
| 75 | + //System.out.println(a.getType()); |
| 76 | + if(!land.hasPermTo(p, this)){ |
| 77 | + if(a.getType().toString().equals("ARROW")) { |
| 78 | + p.sendMessage(ChatColor.RED + "You cannot harm other players on this land."); |
| 79 | + } |
| 80 | + a.remove(); |
| 81 | + event.setCancelled(true); |
| 82 | + } |
| 83 | + } |
| 84 | + |
| 85 | + |
| 86 | + } |
| 87 | + } |
| 88 | + |
| 89 | + |
| 90 | + |
| 91 | +} |
0 commit comments