From 5a9474822cb590ecfdafe578625baa734402a3b2 Mon Sep 17 00:00:00 2001 From: Marc Baloup Date: Wed, 11 Feb 2015 00:56:36 -0500 Subject: [PATCH] =?UTF-8?q?Ajout=20d'une=20protection=20pour=20les=20anima?= =?UTF-8?q?ux=20dompt=C3=A9s=20+=20correction=20debug=20du=20rechargement?= =?UTF-8?q?=20de=20la=20configuration=20+=20correction=20de=20bug=20sur=20?= =?UTF-8?q?la=20gestion=20des=20permissions?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- make_jar.jardesc | 2 +- resources/plugin.yml | 2 +- .../plugin/pandacraftutils/ConfigManager.java | 53 ++++++++---- .../pandacraftutils/PandacraftUtils.java | 19 +++-- .../commands/CommandAdmin.java | 2 +- .../TamedEntityProtectManager.java | 83 +++++++++++++++++++ .../pandacraftutils/players/OnlinePlayer.java | 35 +++++++- 7 files changed, 167 insertions(+), 29 deletions(-) create mode 100644 src/net/mc_pandacraft/java/plugin/pandacraftutils/modules/cheat_protect/TamedEntityProtectManager.java diff --git a/make_jar.jardesc b/make_jar.jardesc index 8bc5d8e..9f562b5 100644 --- a/make_jar.jardesc +++ b/make_jar.jardesc @@ -1,6 +1,6 @@ - + diff --git a/resources/plugin.yml b/resources/plugin.yml index 4cc7b23..0d03030 100644 --- a/resources/plugin.yml +++ b/resources/plugin.yml @@ -1,6 +1,6 @@ name: PandacraftUtils main: net.mc_pandacraft.java.plugin.pandacraftutils.PandacraftUtils -version: 3.6 +version: 3.7 diff --git a/src/net/mc_pandacraft/java/plugin/pandacraftutils/ConfigManager.java b/src/net/mc_pandacraft/java/plugin/pandacraftutils/ConfigManager.java index b891a3f..dd7f3a8 100644 --- a/src/net/mc_pandacraft/java/plugin/pandacraftutils/ConfigManager.java +++ b/src/net/mc_pandacraft/java/plugin/pandacraftutils/ConfigManager.java @@ -16,25 +16,40 @@ import org.bukkit.configuration.file.FileConfiguration; public class ConfigManager { private static ConfigManager instance = null; + + public synchronized static ConfigManager getInstance() { - if (instance == null) - try { - instance = new ConfigManager(); - } catch (Exception e) { - PandacraftUtils.getInstance().getLogger().severe("Erreur de chargement de la configuration de PandacraftUtils"); - e.printStackTrace(); - } - + loadNewInstance(); return instance; } - public synchronized static void reloadConfig() { - if (instance != null) - PandacraftUtils.getInstance().reloadConfig(); - instance = null; + public synchronized static void loadNewInstance() { + PandacraftUtils.getInstance().reloadConfig(); + try { + instance = new ConfigManager(); + } catch (Exception e) { + PandacraftUtils.getInstance().getLogger().severe("Erreur de chargement de la configuration de PandacraftUtils"); + e.printStackTrace(); + } } + + + + + + + + + + + + + + + + private PandacraftUtils plugin = PandacraftUtils.getInstance(); private ConfigManager() throws Exception { @@ -186,7 +201,7 @@ public class ConfigManager { message = new HashMap(); message.put("message", ChatColor.BLUE+"Bienvenue sur Pandacraft ! :) Pour pouvoir jouer, n'oubliez pas de vous inscrire en cliquant sur le lien en dessous%n &ahttps://www.mc-pandacraft.net/?p=inscription"); - message.put("permissions", "group.default"); + message.put("permissions", "pandacraft.grade.default"); Automessages_messages.add(message); message = new HashMap(); @@ -289,6 +304,10 @@ public class ConfigManager { ChatAnalysis_badWords.add("minefield"); ChatAnalysis_badWords.add("mineplex"); ChatAnalysis_badWords.add("hypixel"); + ChatAnalysis_badWords.add("mtxserv"); + ChatAnalysis_badWords.add("spycraft"); + ChatAnalysis_badWords.add("verygames"); + ChatAnalysis_badWords.add("minecraft-mania"); //ChatAnalysis_badWords.add(""); //ChatAnalysis_badWords.add(""); //ChatAnalysis_badWords.add(""); @@ -316,19 +335,19 @@ public class ConfigManager { alias = new HashMap(); alias.put("initialCommand", "/day"); alias.put("replaceWith", "/ptime day"); - alias.put("permissions", "group.users"); // multiple permission separated with semicolumn + alias.put("permissions", "pandacraft.grade.users"); // multiple permission separated with semicolumn CommandAlias_alias.add(alias); alias = new HashMap(); alias.put("initialCommand", "/night"); alias.put("replaceWith", "/ptime night"); - alias.put("permissions", "group.users"); + alias.put("permissions", "pandacraft.grade.users"); CommandAlias_alias.add(alias); alias = new HashMap(); alias.put("initialCommand", "/time"); alias.put("replaceWith", "/ptime"); - alias.put("permissions", "group.users"); + alias.put("permissions", "pandacraft.grade.users"); CommandAlias_alias.add(alias); alias = new HashMap(); @@ -358,7 +377,7 @@ public class ConfigManager { alias = new HashMap(); alias.put("initialCommand", "/inscription"); alias.put("replaceWith", "/mail send marcbal Inscription"); - alias.put("permissions", "group.users"); + alias.put("permissions", "pandacraft.grade.users"); CommandAlias_alias.add(alias); /* Map alias = new HashMap(); diff --git a/src/net/mc_pandacraft/java/plugin/pandacraftutils/PandacraftUtils.java b/src/net/mc_pandacraft/java/plugin/pandacraftutils/PandacraftUtils.java index 045e393..f870088 100644 --- a/src/net/mc_pandacraft/java/plugin/pandacraftutils/PandacraftUtils.java +++ b/src/net/mc_pandacraft/java/plugin/pandacraftutils/PandacraftUtils.java @@ -16,10 +16,11 @@ import net.mc_pandacraft.java.plugin.pandacraftutils.modules.WESelectionDisplayM import net.mc_pandacraft.java.plugin.pandacraftutils.modules.cheat_protect.CreativCheatManager; import net.mc_pandacraft.java.plugin.pandacraftutils.modules.cheat_protect.EntitySpamManager; import net.mc_pandacraft.java.plugin.pandacraftutils.modules.cheat_protect.NoPvpProtectManager; +import net.mc_pandacraft.java.plugin.pandacraftutils.modules.cheat_protect.TamedEntityProtectManager; import net.mc_pandacraft.java.plugin.pandacraftutils.network_api.NetworkAPI; +import net.mc_pandacraft.java.plugin.pandacraftutils.players.OnlinePlayer; import net.mc_pandacraft.java.plugin.pandacraftutils.players.OnlinePlayerManager; -import org.bukkit.entity.Player; import org.bukkit.plugin.java.JavaPlugin; public class PandacraftUtils extends JavaPlugin { @@ -47,6 +48,7 @@ public class PandacraftUtils extends JavaPlugin { public TPSAnalysisManager tpsAnalysisManager; public AutoMessagesManager autoMessagesManager; public EntitySpamManager entitySpamManager; + public TamedEntityProtectManager tamedEntityProtectManager; @@ -69,6 +71,9 @@ public class PandacraftUtils extends JavaPlugin { getLogger().severe("Impossible de se connecter à la base de donnée !"); e.printStackTrace(); }*/ + + + ConfigManager.loadNewInstance(); OnlinePlayerManager.loadNewInstance(); CommandsManager.loadNewInstance(); @@ -88,6 +93,7 @@ public class PandacraftUtils extends JavaPlugin { tpsAnalysisManager = new TPSAnalysisManager(); autoMessagesManager = new AutoMessagesManager(); entitySpamManager = new EntitySpamManager(); + tamedEntityProtectManager = new TamedEntityProtectManager(); NetworkAPI.loadNewInstance(); @@ -117,9 +123,7 @@ public class PandacraftUtils extends JavaPlugin { tpsAnalysisManager = null; autoMessagesManager = null; entitySpamManager = null; - - - ConfigManager.reloadConfig(); + tamedEntityProtectManager = null; instance = null; @@ -162,11 +166,10 @@ public class PandacraftUtils extends JavaPlugin { message = ConfigManager.getInstance().ServerMessages_prefix + message; - for (Player p : getServer().getOnlinePlayers()) + for (OnlinePlayer op : OnlinePlayerManager.getAll()) { - if (p==null || !p.isOnline()) continue; - if (permission != null && !p.hasPermission(permission)) continue; - p.sendMessage(message); + if (permission != null && !op.hasPermission(permission)) continue; + op.getPlayer().sendMessage(message); } if (console) diff --git a/src/net/mc_pandacraft/java/plugin/pandacraftutils/commands/CommandAdmin.java b/src/net/mc_pandacraft/java/plugin/pandacraftutils/commands/CommandAdmin.java index 577e8a9..028f4dd 100644 --- a/src/net/mc_pandacraft/java/plugin/pandacraftutils/commands/CommandAdmin.java +++ b/src/net/mc_pandacraft/java/plugin/pandacraftutils/commands/CommandAdmin.java @@ -31,7 +31,7 @@ public class CommandAdmin extends AbstractCommandExecutor { if (args[0].equalsIgnoreCase("reload") && args.length >= 2) { if (args[1].equalsIgnoreCase("config")) { - ConfigManager.reloadConfig(); + ConfigManager.loadNewInstance(); sender.sendMessage(ChatColor.GREEN+"La configuration de PandacraftUtils viens d'être rechargée"); return true; } 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 new file mode 100644 index 0000000..f12129a --- /dev/null +++ b/src/net/mc_pandacraft/java/plugin/pandacraftutils/modules/cheat_protect/TamedEntityProtectManager.java @@ -0,0 +1,83 @@ +package net.mc_pandacraft.java.plugin.pandacraftutils.modules.cheat_protect; + +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.vehicle.VehicleEnterEvent; + +public class TamedEntityProtectManager implements Listener { + private PandacraftUtils plugin = PandacraftUtils.getInstance(); + + + public TamedEntityProtectManager() + { + + plugin.getServer().getPluginManager().registerEvents(this, plugin); + + } + + + + @EventHandler + 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 (playerOwner instanceof Player) { + Player p = (Player) playerOwner; + p.sendMessage(ChatColor.GREEN+"Vous venez de protéger cet animal"); + } + + } + } + + + @EventHandler + 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 (!tameableEntity.getOwner().equals(event.getEntered())) + event.setCancelled(true); + + } + + + @EventHandler + 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; + + Player p = (Player) damager; + Tameable animal = (Tameable) target; + + if (!animal.getOwner().equals(p)) + event.setCancelled(true); + + + } + + +} diff --git a/src/net/mc_pandacraft/java/plugin/pandacraftutils/players/OnlinePlayer.java b/src/net/mc_pandacraft/java/plugin/pandacraftutils/players/OnlinePlayer.java index 8b932da..3a879a5 100644 --- a/src/net/mc_pandacraft/java/plugin/pandacraftutils/players/OnlinePlayer.java +++ b/src/net/mc_pandacraft/java/plugin/pandacraftutils/players/OnlinePlayer.java @@ -266,6 +266,39 @@ public class OnlinePlayer { /* * Grades */ + /** + * Récupère le groupe parent direct ayant le poids le plus fort + * @return le groupe + */ + public String getGroup() { + String[] groups = getGroups(); + return (groups != null && groups.length > 0) ? groups[0] : PermissionsEx.getPermissionManager().getDefaultGroup().getName(); + } + + /** + * Défini si le joueur à la permission dont le noeux est passé sous forme de + * chaine de caractère. Cetteméthode ajoute une surcouche par rapport à la méthode + * Player.hasPermission(String) permettant de tester si un joueur est dans un groupe, de + * la même manière que OnlinePlayer.isInGroup(String) + * @param permission la permission testée + * @return si le joueur a la permission + */ + public boolean hasPermission(String permission) { + String permissionGroupPrefix = "pandacraft.grade."; + if (permission != null && permission.startsWith(permissionGroupPrefix)) { + String group = permission.substring(permissionGroupPrefix.length()); + return isInGroup(group); + } + return player.hasPermission(permission); + } + + /** + * Récupère la liste des groupes dans lequel le joueur se trouve + * @return + */ + public String[] getGroups() { + return PermissionsEx.getUser(player).getGroupsNames(); + } /** * Indique si le joueur est dans le groupe Spécifié * @param group Le groupe par rapport au plugin de permission @@ -273,7 +306,7 @@ public class OnlinePlayer { */ public boolean isInGroup(String group) { if (group == null) return false; - return PermissionsEx.getUser(player).inGroup(group, false); + return group.equalsIgnoreCase(getGroup()); } /**