From 86d80c893b919d447c74c5803f6c8cf5d77744ca Mon Sep 17 00:00:00 2001 From: Marc Baloup Date: Thu, 12 Feb 2015 14:38:11 -0500 Subject: [PATCH] =?UTF-8?q?Correction=20de=20bug=20de=20la=20protection=20?= =?UTF-8?q?des=20animaux=20apprivois=C3=A9s?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../TamedEntityProtectManager.java | 56 +++++++++++++++---- 1 file changed, 44 insertions(+), 12 deletions(-) diff --git a/src/net/mc_pandacraft/java/plugin/pandacraftutils/modules/cheat_protect/TamedEntityProtectManager.java b/src/net/mc_pandacraft/java/plugin/pandacraftutils/modules/cheat_protect/TamedEntityProtectManager.java index f12129a..55fc42f 100644 --- a/src/net/mc_pandacraft/java/plugin/pandacraftutils/modules/cheat_protect/TamedEntityProtectManager.java +++ b/src/net/mc_pandacraft/java/plugin/pandacraftutils/modules/cheat_protect/TamedEntityProtectManager.java @@ -4,15 +4,14 @@ import net.mc_pandacraft.java.plugin.pandacraftutils.PandacraftUtils; import org.bukkit.ChatColor; import org.bukkit.entity.AnimalTamer; -import org.bukkit.entity.Entity; import org.bukkit.entity.LivingEntity; import org.bukkit.entity.Player; import org.bukkit.entity.Tameable; -import org.bukkit.entity.Vehicle; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; import org.bukkit.event.entity.EntityDamageByEntityEvent; import org.bukkit.event.entity.EntityTameEvent; +import org.bukkit.event.player.PlayerInteractEntityEvent; import org.bukkit.event.vehicle.VehicleEnterEvent; public class TamedEntityProtectManager implements Listener { @@ -51,12 +50,19 @@ public class TamedEntityProtectManager implements Listener { public void onVehicleEnter(VehicleEnterEvent event) { if (event.getVehicle().getWorld().getPVP()) return; - Vehicle vehicle = event.getVehicle(); - if (!(vehicle instanceof Tameable)) return; - Tameable tameableEntity = (Tameable) vehicle; + if (!isConcerned(event.getEntered(), event.getVehicle())) return; + + Tameable tameableEntity = (Tameable) event.getVehicle(); if (!tameableEntity.getOwner().equals(event.getEntered())) + { event.setCancelled(true); + + Player p = (Player) event.getEntered(); + + p.sendMessage(ChatColor.RED+"Cet animal est à "+tameableEntity.getOwner().getName()+" vous ne pouvez pas y toucher"); + + } } @@ -65,19 +71,45 @@ public class TamedEntityProtectManager implements Listener { public void onEntityDamage(EntityDamageByEntityEvent event) { if (event.getEntity().getWorld().getPVP()) return; - Entity damager = event.getDamager(); - if (!(damager instanceof Player)) return; - Entity target = event.getEntity(); - if (!(target instanceof Tameable)) return; + if (!isConcerned(event.getDamager(), event.getEntity())) return; - Player p = (Player) damager; - Tameable animal = (Tameable) target; + Player p = (Player) event.getDamager(); + Tameable animal = (Tameable) event.getEntity(); - if (!animal.getOwner().equals(p)) + if (!animal.getOwner().equals(p)) { event.setCancelled(true); + p.sendMessage(ChatColor.RED+"Cet animal est à "+animal.getOwner().getName()+" vous ne pouvez pas y toucher"); + } } + + @EventHandler + public void onPlayerInteractEntity(PlayerInteractEntityEvent event) { + if (event.getPlayer().getWorld().getPVP()) return; + + if (!isConcerned(event.getPlayer(), event.getRightClicked())) return; + + Tameable animal = (Tameable) event.getRightClicked(); + + if (animal.getOwner().equals(event.getPlayer())) return; + + } + + + + + + + private boolean isConcerned(Object player, Object tameable) { + if (!(player instanceof Player)) return false; + if (!(tameable instanceof Tameable)) return false; + if (((Tameable)tameable).getOwner() == null) return false; + return true; + } + + + }