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:
parent
99bdc8af47
commit
5a9474822c
@ -1,6 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<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"/>
|
||||
<storedRefactorings deprecationInfo="true" structuralOnly="false"/>
|
||||
<selectedProjects/>
|
||||
|
@ -1,6 +1,6 @@
|
||||
name: PandacraftUtils
|
||||
main: net.mc_pandacraft.java.plugin.pandacraftutils.PandacraftUtils
|
||||
version: 3.6
|
||||
version: 3.7
|
||||
|
||||
|
||||
|
||||
|
@ -16,24 +16,39 @@ import org.bukkit.configuration.file.FileConfiguration;
|
||||
public class ConfigManager {
|
||||
private static ConfigManager instance = null;
|
||||
|
||||
public synchronized static ConfigManager getInstance() {
|
||||
|
||||
|
||||
public synchronized static ConfigManager getInstance() {
|
||||
if (instance == null)
|
||||
loadNewInstance();
|
||||
return instance;
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
return instance;
|
||||
}
|
||||
|
||||
public synchronized static void reloadConfig() {
|
||||
if (instance != null)
|
||||
PandacraftUtils.getInstance().reloadConfig();
|
||||
instance = null;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
private PandacraftUtils plugin = PandacraftUtils.getInstance();
|
||||
|
||||
@ -186,7 +201,7 @@ public class ConfigManager {
|
||||
|
||||
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("permissions", "group.default");
|
||||
message.put("permissions", "pandacraft.grade.default");
|
||||
Automessages_messages.add(message);
|
||||
|
||||
message = new HashMap<String, String>();
|
||||
@ -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<String, String>();
|
||||
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<String, String>();
|
||||
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<String, String>();
|
||||
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<String, String>();
|
||||
@ -358,7 +377,7 @@ public class ConfigManager {
|
||||
alias = new HashMap<String, String>();
|
||||
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<String, String> alias = new HashMap<String, String>();
|
||||
|
@ -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)
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -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());
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user