Amélioration de la commande /animal + correction de bug associé à cette commande
This commit is contained in:
@@ -5,8 +5,11 @@ import net.mc_pandacraft.java.plugin.pandacraftutils.players.OnlinePlayerManager
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.entity.AnimalTamer;
|
||||
import org.bukkit.entity.Horse;
|
||||
import org.bukkit.entity.Ocelot;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.entity.Tameable;
|
||||
import org.bukkit.entity.Wolf;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.entity.EntityDamageByEntityEvent;
|
||||
@@ -39,7 +42,7 @@ public class TamedEntityProtectManager implements Listener {
|
||||
tameableEntity.setOwner(event.getOwner());
|
||||
|
||||
Player p = (Player) event.getOwner();
|
||||
p.sendMessage(ChatColor.GREEN+"Vous venez de protéger cet animal");
|
||||
p.sendMessage(ChatColor.GREEN+"Vous venez de protéger "+get_thisAnimal_Name(tameableEntity));
|
||||
}
|
||||
|
||||
|
||||
@@ -55,7 +58,7 @@ public class TamedEntityProtectManager implements Listener {
|
||||
|
||||
event.setCancelled(true);
|
||||
Player p = (Player) event.getEntered();
|
||||
p.sendMessage(ChatColor.RED+"Cet animal est à "+getOwnerDisplayName(tameableEntity)+ChatColor.RED+", vous ne pouvez pas y toucher");
|
||||
p.sendMessage(ChatColor.RED+get_thisAnimal_Name(tameableEntity)+ChatColor.RED+" est à "+getOwnerDisplayName(tameableEntity)+ChatColor.RED+", vous ne pouvez pas y toucher");
|
||||
|
||||
|
||||
}
|
||||
@@ -73,7 +76,7 @@ public class TamedEntityProtectManager implements Listener {
|
||||
if (animal.getOwner().equals(p)) return;
|
||||
|
||||
event.setCancelled(true);
|
||||
p.sendMessage(ChatColor.RED+"Cet animal est à "+getOwnerDisplayName(animal)+ChatColor.RED+", vous ne pouvez pas y toucher");
|
||||
p.sendMessage(ChatColor.RED+get_thisAnimal_Name(animal)+ChatColor.RED+" est à "+getOwnerDisplayName(animal)+ChatColor.RED+", vous ne pouvez pas y toucher");
|
||||
|
||||
}
|
||||
|
||||
@@ -89,13 +92,13 @@ public class TamedEntityProtectManager implements Listener {
|
||||
|
||||
boolean selected = OnlinePlayerManager.get(event.getPlayer()).setSelectedAnimal(animal);
|
||||
if (selected) {
|
||||
event.getPlayer().sendMessage(ChatColor.GREEN+"Vous venez de sélectionner cet animal");
|
||||
event.getPlayer().sendMessage(ChatColor.GREEN+"Vous venez de sélectionner "+get_thisAnimal_Name(animal));
|
||||
}
|
||||
|
||||
if (animal.getOwner().equals(event.getPlayer())) return;
|
||||
|
||||
event.setCancelled(true);
|
||||
event.getPlayer().sendMessage(ChatColor.RED+"Cet animal est à "+getOwnerDisplayName(animal)+ChatColor.RED+", vous ne pouvez pas y toucher");
|
||||
event.getPlayer().sendMessage(ChatColor.RED+get_thisAnimal_Name(animal)+ChatColor.RED+" est à "+getOwnerDisplayName(animal)+ChatColor.RED+", vous ne pouvez pas y toucher");
|
||||
|
||||
}
|
||||
|
||||
@@ -129,4 +132,32 @@ public class TamedEntityProtectManager implements Listener {
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Donne le nom personnalisé de l'animal passé en paramètre, ou son espèce, le cas échéant, de la forme
|
||||
* "ce cheval", "ce loup" ou "ce chat".
|
||||
* @param animal l'animal apprivoisable pour lequel il faut récupérer son nom
|
||||
* @return
|
||||
*/
|
||||
public String get_thisAnimal_Name(Tameable animal) {
|
||||
if (animal instanceof Horse) {
|
||||
String customName = ((Horse) animal).getCustomName();
|
||||
return (customName == null) ? "ce cheval" : ChatColor.RESET+customName;
|
||||
}
|
||||
if (animal instanceof Wolf) {
|
||||
String customName = ((Wolf) animal).getCustomName();
|
||||
return (customName == null) ? "ce loup" : ChatColor.RESET+customName;
|
||||
}
|
||||
if (animal instanceof Ocelot) {
|
||||
String customName = ((Ocelot) animal).getCustomName();
|
||||
return (customName == null) ? "ce chat" : ChatColor.RESET+customName;
|
||||
}
|
||||
|
||||
return "cet animal";
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user