Correction de bug dans TamedEntityProtectManager
This commit is contained in:
parent
86d80c893b
commit
d6ee50816c
@ -4,7 +4,6 @@ import net.mc_pandacraft.java.plugin.pandacraftutils.PandacraftUtils;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.entity.AnimalTamer;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.entity.Tameable;
|
||||
import org.bukkit.event.EventHandler;
|
||||
@ -31,20 +30,17 @@ public class TamedEntityProtectManager implements Listener {
|
||||
public void onEntityTame(EntityTameEvent event) {
|
||||
if (event.getEntity().getWorld().getPVP()) return;
|
||||
|
||||
LivingEntity entity = event.getEntity();
|
||||
AnimalTamer playerOwner = event.getOwner();
|
||||
if (entity instanceof Tameable) {
|
||||
Tameable tameableEntity = (Tameable) entity;
|
||||
tameableEntity.setOwner(playerOwner);
|
||||
if (!(event.getEntity() instanceof Tameable)) return;
|
||||
if (!(event.getOwner() instanceof Player)) return;
|
||||
|
||||
if (playerOwner instanceof Player) {
|
||||
Player p = (Player) playerOwner;
|
||||
Tameable tameableEntity = (Tameable) event.getEntity();
|
||||
|
||||
tameableEntity.setOwner(event.getOwner());
|
||||
|
||||
Player p = (Player) event.getOwner();
|
||||
p.sendMessage(ChatColor.GREEN+"Vous venez de protéger cet animal");
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@EventHandler
|
||||
public void onVehicleEnter(VehicleEnterEvent event) {
|
||||
@ -54,15 +50,12 @@ public class TamedEntityProtectManager implements Listener {
|
||||
|
||||
Tameable tameableEntity = (Tameable) event.getVehicle();
|
||||
|
||||
if (!tameableEntity.getOwner().equals(event.getEntered()))
|
||||
{
|
||||
if (tameableEntity.getOwner().equals(event.getEntered())) return;
|
||||
|
||||
event.setCancelled(true);
|
||||
|
||||
Player p = (Player) event.getEntered();
|
||||
p.sendMessage(ChatColor.RED+"Cet animal est à "+getOwnerDisplayName(tameableEntity)+", vous ne pouvez pas y toucher");
|
||||
|
||||
p.sendMessage(ChatColor.RED+"Cet animal est à "+tameableEntity.getOwner().getName()+" vous ne pouvez pas y toucher");
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -76,11 +69,10 @@ public class TamedEntityProtectManager implements Listener {
|
||||
Player p = (Player) event.getDamager();
|
||||
Tameable animal = (Tameable) event.getEntity();
|
||||
|
||||
if (!animal.getOwner().equals(p)) {
|
||||
event.setCancelled(true);
|
||||
p.sendMessage(ChatColor.RED+"Cet animal est à "+animal.getOwner().getName()+" vous ne pouvez pas y toucher");
|
||||
}
|
||||
if (animal.getOwner().equals(p)) return;
|
||||
|
||||
event.setCancelled(true);
|
||||
p.sendMessage(ChatColor.RED+"Cet animal est à "+getOwnerDisplayName(animal)+", vous ne pouvez pas y toucher");
|
||||
|
||||
}
|
||||
|
||||
@ -96,6 +88,9 @@ public class TamedEntityProtectManager implements Listener {
|
||||
|
||||
if (animal.getOwner().equals(event.getPlayer())) return;
|
||||
|
||||
event.setCancelled(true);
|
||||
event.getPlayer().sendMessage(ChatColor.RED+"Cet animal est à "+getOwnerDisplayName(animal)+", vous ne pouvez pas y toucher");
|
||||
|
||||
}
|
||||
|
||||
|
||||
@ -112,4 +107,20 @@ public class TamedEntityProtectManager implements Listener {
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
public String getOwnerDisplayName(Tameable animal) {
|
||||
if (animal == null || animal.getOwner() == null)
|
||||
return null;
|
||||
|
||||
AnimalTamer owner = animal.getOwner();
|
||||
if (owner instanceof Player) // si le joueur est en ligne
|
||||
return ((Player) owner).getDisplayName();
|
||||
|
||||
return owner.getName();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user