Ajout d'une protection pour les animaux domptés + correction debug du rechargement de la configuration + correction de bug sur la gestion des permissions

This commit is contained in:
Marc Baloup 2015-02-11 00:56:36 -05:00
parent 99bdc8af47
commit 5a9474822c
7 changed files with 167 additions and 29 deletions

View File

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?> <?xml version="1.0" encoding="UTF-8" standalone="no"?>
<jardesc> <jardesc>
<jar path="PandacraftUtils/jar_export/PandacraftUtils-3.6.jar"/> <jar path="PandacraftUtils/jar_export/PandacraftUtils-3.7.jar"/>
<options buildIfNeeded="true" compress="true" descriptionLocation="/PandacraftUtils/make_jar.jardesc" exportErrors="true" exportWarnings="true" includeDirectoryEntries="false" overwrite="false" saveDescription="true" storeRefactorings="false" useSourceFolders="false"/> <options buildIfNeeded="true" compress="true" descriptionLocation="/PandacraftUtils/make_jar.jardesc" exportErrors="true" exportWarnings="true" includeDirectoryEntries="false" overwrite="false" saveDescription="true" storeRefactorings="false" useSourceFolders="false"/>
<storedRefactorings deprecationInfo="true" structuralOnly="false"/> <storedRefactorings deprecationInfo="true" structuralOnly="false"/>
<selectedProjects/> <selectedProjects/>

View File

@ -1,6 +1,6 @@
name: PandacraftUtils name: PandacraftUtils
main: net.mc_pandacraft.java.plugin.pandacraftutils.PandacraftUtils main: net.mc_pandacraft.java.plugin.pandacraftutils.PandacraftUtils
version: 3.6 version: 3.7

View File

@ -16,24 +16,39 @@ import org.bukkit.configuration.file.FileConfiguration;
public class ConfigManager { public class ConfigManager {
private static ConfigManager instance = null; private static ConfigManager instance = null;
public synchronized static ConfigManager getInstance() {
public synchronized static ConfigManager getInstance() {
if (instance == null) if (instance == null)
loadNewInstance();
return instance;
}
public synchronized static void loadNewInstance() {
PandacraftUtils.getInstance().reloadConfig();
try { try {
instance = new ConfigManager(); instance = new ConfigManager();
} catch (Exception e) { } catch (Exception e) {
PandacraftUtils.getInstance().getLogger().severe("Erreur de chargement de la configuration de PandacraftUtils"); PandacraftUtils.getInstance().getLogger().severe("Erreur de chargement de la configuration de PandacraftUtils");
e.printStackTrace(); e.printStackTrace();
} }
return instance;
} }
public synchronized static void reloadConfig() {
if (instance != null)
PandacraftUtils.getInstance().reloadConfig();
instance = null;
}
private PandacraftUtils plugin = PandacraftUtils.getInstance(); private PandacraftUtils plugin = PandacraftUtils.getInstance();
@ -186,7 +201,7 @@ public class ConfigManager {
message = new HashMap<String, String>(); message = new HashMap<String, String>();
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("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); Automessages_messages.add(message);
message = new HashMap<String, String>(); message = new HashMap<String, String>();
@ -289,6 +304,10 @@ public class ConfigManager {
ChatAnalysis_badWords.add("minefield"); ChatAnalysis_badWords.add("minefield");
ChatAnalysis_badWords.add("mineplex"); ChatAnalysis_badWords.add("mineplex");
ChatAnalysis_badWords.add("hypixel"); 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(""); //ChatAnalysis_badWords.add("");
//ChatAnalysis_badWords.add(""); //ChatAnalysis_badWords.add("");
@ -316,19 +335,19 @@ public class ConfigManager {
alias = new HashMap<String, String>(); alias = new HashMap<String, String>();
alias.put("initialCommand", "/day"); alias.put("initialCommand", "/day");
alias.put("replaceWith", "/ptime 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); CommandAlias_alias.add(alias);
alias = new HashMap<String, String>(); alias = new HashMap<String, String>();
alias.put("initialCommand", "/night"); alias.put("initialCommand", "/night");
alias.put("replaceWith", "/ptime night"); alias.put("replaceWith", "/ptime night");
alias.put("permissions", "group.users"); alias.put("permissions", "pandacraft.grade.users");
CommandAlias_alias.add(alias); CommandAlias_alias.add(alias);
alias = new HashMap<String, String>(); alias = new HashMap<String, String>();
alias.put("initialCommand", "/time"); alias.put("initialCommand", "/time");
alias.put("replaceWith", "/ptime"); alias.put("replaceWith", "/ptime");
alias.put("permissions", "group.users"); alias.put("permissions", "pandacraft.grade.users");
CommandAlias_alias.add(alias); CommandAlias_alias.add(alias);
alias = new HashMap<String, String>(); alias = new HashMap<String, String>();
@ -358,7 +377,7 @@ public class ConfigManager {
alias = new HashMap<String, String>(); alias = new HashMap<String, String>();
alias.put("initialCommand", "/inscription"); alias.put("initialCommand", "/inscription");
alias.put("replaceWith", "/mail send marcbal Inscription"); alias.put("replaceWith", "/mail send marcbal Inscription");
alias.put("permissions", "group.users"); alias.put("permissions", "pandacraft.grade.users");
CommandAlias_alias.add(alias); CommandAlias_alias.add(alias);
/* /*
Map<String, String> alias = new HashMap<String, String>(); Map<String, String> alias = new HashMap<String, String>();

View File

@ -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.CreativCheatManager;
import net.mc_pandacraft.java.plugin.pandacraftutils.modules.cheat_protect.EntitySpamManager; 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.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.network_api.NetworkAPI;
import net.mc_pandacraft.java.plugin.pandacraftutils.players.OnlinePlayer;
import net.mc_pandacraft.java.plugin.pandacraftutils.players.OnlinePlayerManager; import net.mc_pandacraft.java.plugin.pandacraftutils.players.OnlinePlayerManager;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.plugin.java.JavaPlugin;
public class PandacraftUtils extends JavaPlugin { public class PandacraftUtils extends JavaPlugin {
@ -47,6 +48,7 @@ public class PandacraftUtils extends JavaPlugin {
public TPSAnalysisManager tpsAnalysisManager; public TPSAnalysisManager tpsAnalysisManager;
public AutoMessagesManager autoMessagesManager; public AutoMessagesManager autoMessagesManager;
public EntitySpamManager entitySpamManager; 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 !"); getLogger().severe("Impossible de se connecter à la base de donnée !");
e.printStackTrace(); e.printStackTrace();
}*/ }*/
ConfigManager.loadNewInstance();
OnlinePlayerManager.loadNewInstance(); OnlinePlayerManager.loadNewInstance();
CommandsManager.loadNewInstance(); CommandsManager.loadNewInstance();
@ -88,6 +93,7 @@ public class PandacraftUtils extends JavaPlugin {
tpsAnalysisManager = new TPSAnalysisManager(); tpsAnalysisManager = new TPSAnalysisManager();
autoMessagesManager = new AutoMessagesManager(); autoMessagesManager = new AutoMessagesManager();
entitySpamManager = new EntitySpamManager(); entitySpamManager = new EntitySpamManager();
tamedEntityProtectManager = new TamedEntityProtectManager();
NetworkAPI.loadNewInstance(); NetworkAPI.loadNewInstance();
@ -117,9 +123,7 @@ public class PandacraftUtils extends JavaPlugin {
tpsAnalysisManager = null; tpsAnalysisManager = null;
autoMessagesManager = null; autoMessagesManager = null;
entitySpamManager = null; entitySpamManager = null;
tamedEntityProtectManager = null;
ConfigManager.reloadConfig();
instance = null; instance = null;
@ -162,11 +166,10 @@ public class PandacraftUtils extends JavaPlugin {
message = ConfigManager.getInstance().ServerMessages_prefix + message; 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 && !op.hasPermission(permission)) continue;
if (permission != null && !p.hasPermission(permission)) continue; op.getPlayer().sendMessage(message);
p.sendMessage(message);
} }
if (console) if (console)

View File

@ -31,7 +31,7 @@ public class CommandAdmin extends AbstractCommandExecutor {
if (args[0].equalsIgnoreCase("reload") && args.length >= 2) { if (args[0].equalsIgnoreCase("reload") && args.length >= 2) {
if (args[1].equalsIgnoreCase("config")) { if (args[1].equalsIgnoreCase("config")) {
ConfigManager.reloadConfig(); ConfigManager.loadNewInstance();
sender.sendMessage(ChatColor.GREEN+"La configuration de PandacraftUtils viens d'être rechargée"); sender.sendMessage(ChatColor.GREEN+"La configuration de PandacraftUtils viens d'être rechargée");
return true; return true;
} }

View File

@ -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);
}
}

View File

@ -266,6 +266,39 @@ public class OnlinePlayer {
/* /*
* Grades * 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é * Indique si le joueur est dans le groupe Spécifié
* @param group Le groupe par rapport au plugin de permission * @param group Le groupe par rapport au plugin de permission
@ -273,7 +306,7 @@ public class OnlinePlayer {
*/ */
public boolean isInGroup(String group) { public boolean isInGroup(String group) {
if (group == null) return false; if (group == null) return false;
return PermissionsEx.getUser(player).inGroup(group, false); return group.equalsIgnoreCase(getGroup());
} }
/** /**