From 2f2ad0974b5f7470ed2c7afaca2e5b45c6a5ea17 Mon Sep 17 00:00:00 2001 From: Marc Baloup Date: Thu, 22 Jan 2015 03:32:47 -0500 Subject: [PATCH] =?UTF-8?q?Unification=20des=20classes=20g=C3=A9rant=20l'e?= =?UTF-8?q?x=C3=A9cution=20des=20commandes=20+=20retructuration=20compl?= =?UTF-8?q?=C3=A8tes=20des=20packages=20et=20des=20classes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- make_jar.jardesc | 2 +- resources/plugin.yml | 2 +- .../pandacraftutils/PandacraftUtils.java | 111 +++++---- .../commands/AbstractCommandExecutor.java | 31 +++ .../pandacraftutils/commands/CommandAfk.java | 94 +++++++ .../CommandBroadcast.java | 17 +- .../CommandCubo.java | 189 +++----------- .../list => commands}/CommandList.java | 41 +--- .../me => commands}/CommandMe.java | 14 +- .../ping => commands}/CommandPing.java | 16 +- .../CommandSetblock.java | 14 +- .../CommandStaff.java | 231 ++---------------- .../CommandSystem.java | 22 +- .../commands/Command_Selection.java | 87 +++++++ .../commands/CommandsManager.java | 69 ++++++ .../AfkManager.java} | 100 +------- .../CalculatorManager.java | 2 +- .../ChatAnalysisManager.java | 2 +- .../CommandAliasManager.java | 2 +- .../LoginLogoutMessageManager.java} | 6 +- .../PacketOutServerInfoListener.java | 2 +- .../SpawnTimeManager.java | 2 +- .../modules/StaffQueueManager.java | 191 +++++++++++++++ .../modules/SurvivalCuboManager.java | 107 ++++++++ .../TPSAnalysisManager.java} | 9 +- .../WESelectionDisplayManager.java} | 86 +------ .../cheat_protect}/CreativCheatManager.java | 2 +- .../cheat_protect}/NoPvpProtectManager.java | 2 +- .../players/OnlinePlayerManager.java | 2 +- .../plugin_interface/WorldGuardInterface.java | 14 ++ .../mc_pandacraft/java/util/StringUtil.java | 15 ++ 31 files changed, 782 insertions(+), 702 deletions(-) create mode 100644 src/net/mc_pandacraft/java/plugin/pandacraftutils/commands/AbstractCommandExecutor.java create mode 100644 src/net/mc_pandacraft/java/plugin/pandacraftutils/commands/CommandAfk.java rename src/net/mc_pandacraft/java/plugin/pandacraftutils/{simple_commands/broadcast => commands}/CommandBroadcast.java (65%) rename src/net/mc_pandacraft/java/plugin/pandacraftutils/{survival_cuboid => commands}/CommandCubo.java (84%) rename src/net/mc_pandacraft/java/plugin/pandacraftutils/{simple_commands/list => commands}/CommandList.java (89%) rename src/net/mc_pandacraft/java/plugin/pandacraftutils/{simple_commands/me => commands}/CommandMe.java (78%) rename src/net/mc_pandacraft/java/plugin/pandacraftutils/{simple_commands/ping => commands}/CommandPing.java (69%) rename src/net/mc_pandacraft/java/plugin/pandacraftutils/{simple_commands/setblock => commands}/CommandSetblock.java (89%) rename src/net/mc_pandacraft/java/plugin/pandacraftutils/{simple_commands/staff_player_help => commands}/CommandStaff.java (61%) rename src/net/mc_pandacraft/java/plugin/pandacraftutils/{system_analyzer => commands}/CommandSystem.java (91%) create mode 100644 src/net/mc_pandacraft/java/plugin/pandacraftutils/commands/Command_Selection.java create mode 100644 src/net/mc_pandacraft/java/plugin/pandacraftutils/commands/CommandsManager.java rename src/net/mc_pandacraft/java/plugin/pandacraftutils/{afk/CommandAfk.java => modules/AfkManager.java} (73%) rename src/net/mc_pandacraft/java/plugin/pandacraftutils/{calculator => modules}/CalculatorManager.java (98%) rename src/net/mc_pandacraft/java/plugin/pandacraftutils/{chat_analyzer => modules}/ChatAnalysisManager.java (99%) rename src/net/mc_pandacraft/java/plugin/pandacraftutils/{simple_commands/_command_alias => modules}/CommandAliasManager.java (95%) rename src/net/mc_pandacraft/java/plugin/pandacraftutils/{login_message/LoginLogoutManager.java => modules/LoginLogoutMessageManager.java} (91%) rename src/net/mc_pandacraft/java/plugin/pandacraftutils/{player_count_list => modules}/PacketOutServerInfoListener.java (97%) rename src/net/mc_pandacraft/java/plugin/pandacraftutils/{spawntime => modules}/SpawnTimeManager.java (93%) create mode 100644 src/net/mc_pandacraft/java/plugin/pandacraftutils/modules/StaffQueueManager.java create mode 100644 src/net/mc_pandacraft/java/plugin/pandacraftutils/modules/SurvivalCuboManager.java rename src/net/mc_pandacraft/java/plugin/pandacraftutils/{system_analyzer/TPSAnalyser.java => modules/TPSAnalysisManager.java} (88%) rename src/net/mc_pandacraft/java/plugin/pandacraftutils/{survival_cuboid/CommandWandSelection.java => modules/WESelectionDisplayManager.java} (52%) rename src/net/mc_pandacraft/java/plugin/pandacraftutils/{cheat_protect/creative => modules/cheat_protect}/CreativCheatManager.java (92%) rename src/net/mc_pandacraft/java/plugin/pandacraftutils/{cheat_protect/no_pvp => modules/cheat_protect}/NoPvpProtectManager.java (99%) create mode 100644 src/net/mc_pandacraft/java/plugin/pandacraftutils/plugin_interface/WorldGuardInterface.java diff --git a/make_jar.jardesc b/make_jar.jardesc index 037dd73..cad0ee5 100644 --- a/make_jar.jardesc +++ b/make_jar.jardesc @@ -1,6 +1,6 @@ - + diff --git a/resources/plugin.yml b/resources/plugin.yml index 8ff9094..b6ebc4f 100644 --- a/resources/plugin.yml +++ b/resources/plugin.yml @@ -1,6 +1,6 @@ name: PandacraftUtils main: net.mc_pandacraft.java.plugin.pandacraftutils.PandacraftUtils -version: 2.11 +version: 3.0 diff --git a/src/net/mc_pandacraft/java/plugin/pandacraftutils/PandacraftUtils.java b/src/net/mc_pandacraft/java/plugin/pandacraftutils/PandacraftUtils.java index 241a546..6b34797 100644 --- a/src/net/mc_pandacraft/java/plugin/pandacraftutils/PandacraftUtils.java +++ b/src/net/mc_pandacraft/java/plugin/pandacraftutils/PandacraftUtils.java @@ -1,26 +1,20 @@ package net.mc_pandacraft.java.plugin.pandacraftutils; - - -import net.mc_pandacraft.java.plugin.pandacraftutils.afk.CommandAfk; -import net.mc_pandacraft.java.plugin.pandacraftutils.calculator.CalculatorManager; -import net.mc_pandacraft.java.plugin.pandacraftutils.chat_analyzer.ChatAnalysisManager; -import net.mc_pandacraft.java.plugin.pandacraftutils.cheat_protect.creative.CreativCheatManager; -import net.mc_pandacraft.java.plugin.pandacraftutils.cheat_protect.no_pvp.NoPvpProtectManager; -import net.mc_pandacraft.java.plugin.pandacraftutils.login_message.LoginLogoutManager; -import net.mc_pandacraft.java.plugin.pandacraftutils.player_count_list.PacketOutServerInfoListener; +import net.mc_pandacraft.java.plugin.pandacraftutils.commands.CommandsManager; +import net.mc_pandacraft.java.plugin.pandacraftutils.modules.AfkManager; +import net.mc_pandacraft.java.plugin.pandacraftutils.modules.CalculatorManager; +import net.mc_pandacraft.java.plugin.pandacraftutils.modules.ChatAnalysisManager; +import net.mc_pandacraft.java.plugin.pandacraftutils.modules.CommandAliasManager; +import net.mc_pandacraft.java.plugin.pandacraftutils.modules.LoginLogoutMessageManager; +import net.mc_pandacraft.java.plugin.pandacraftutils.modules.PacketOutServerInfoListener; +import net.mc_pandacraft.java.plugin.pandacraftutils.modules.SpawnTimeManager; +import net.mc_pandacraft.java.plugin.pandacraftutils.modules.StaffQueueManager; +import net.mc_pandacraft.java.plugin.pandacraftutils.modules.SurvivalCuboManager; +import net.mc_pandacraft.java.plugin.pandacraftutils.modules.TPSAnalysisManager; +import net.mc_pandacraft.java.plugin.pandacraftutils.modules.WESelectionDisplayManager; +import net.mc_pandacraft.java.plugin.pandacraftutils.modules.cheat_protect.CreativCheatManager; +import net.mc_pandacraft.java.plugin.pandacraftutils.modules.cheat_protect.NoPvpProtectManager; import net.mc_pandacraft.java.plugin.pandacraftutils.players.OnlinePlayerManager; -import net.mc_pandacraft.java.plugin.pandacraftutils.simple_commands._command_alias.CommandAliasManager; -import net.mc_pandacraft.java.plugin.pandacraftutils.simple_commands.broadcast.CommandBroadcast; -import net.mc_pandacraft.java.plugin.pandacraftutils.simple_commands.list.CommandList; -import net.mc_pandacraft.java.plugin.pandacraftutils.simple_commands.me.CommandMe; -import net.mc_pandacraft.java.plugin.pandacraftutils.simple_commands.ping.CommandPing; -import net.mc_pandacraft.java.plugin.pandacraftutils.simple_commands.setblock.CommandSetblock; -import net.mc_pandacraft.java.plugin.pandacraftutils.simple_commands.staff_player_help.CommandStaff; -import net.mc_pandacraft.java.plugin.pandacraftutils.spawntime.SpawnTimeManager; -import net.mc_pandacraft.java.plugin.pandacraftutils.survival_cuboid.CommandCubo; -import net.mc_pandacraft.java.plugin.pandacraftutils.survival_cuboid.CommandWandSelection; -import net.mc_pandacraft.java.plugin.pandacraftutils.system_analyzer.CommandSystem; import org.bukkit.ChatColor; import org.bukkit.entity.Player; @@ -37,24 +31,20 @@ public class PandacraftUtils extends JavaPlugin { //public DBConnection databaseConnection; - public CommandAfk commandAfk; - public CommandList commandPlayers; - public CommandSetblock commandSetblock; - public CommandSystem commandSystem; - public CommandPing commandPing; - public CommandMe commandMe; - public CommandWandSelection commandWandSelection; - public CommandStaff commandStaff; - public CommandCubo commandCubo; - public CommandBroadcast commandBroadcast; - + public AfkManager afkManager; + public WESelectionDisplayManager wESelectionDisplayManager; public CommandAliasManager commandAliasManager; public SpawnTimeManager spawnTimeManager; public ChatAnalysisManager chatAnalysisManager; public CreativCheatManager creativCheatManager; public NoPvpProtectManager noPvpProtectManager; - public LoginLogoutManager loginLogoutManager; + public LoginLogoutMessageManager loginLogoutMessageManager; public CalculatorManager calculatorManager; + public SurvivalCuboManager survivalCuboManager; + public StaffQueueManager staffQueueManager; + public TPSAnalysisManager tpsAnalysisManager; + + public PacketOutServerInfoListener serverPingListener; @@ -76,27 +66,26 @@ public class PandacraftUtils extends JavaPlugin { e.printStackTrace(); }*/ OnlinePlayerManager.loadNewInstance(); + CommandsManager.loadNewInstance(); - commandPlayers = new CommandList(this); - commandSetblock = new CommandSetblock(this); - commandAfk = new CommandAfk(); - commandSystem = new CommandSystem(this); - commandPing = new CommandPing(this); - commandMe = new CommandMe(this); - commandWandSelection = new CommandWandSelection(this); - commandStaff = new CommandStaff(this); - commandCubo = new CommandCubo(this); - commandBroadcast = new CommandBroadcast(this); - + + afkManager = new AfkManager(); + wESelectionDisplayManager = new WESelectionDisplayManager(); commandAliasManager = new CommandAliasManager(this); spawnTimeManager = new SpawnTimeManager(this); chatAnalysisManager = new ChatAnalysisManager(); creativCheatManager = new CreativCheatManager(this); noPvpProtectManager = new NoPvpProtectManager(this); - loginLogoutManager = new LoginLogoutManager(this); + loginLogoutMessageManager = new LoginLogoutMessageManager(this); calculatorManager = new CalculatorManager(this); - + survivalCuboManager = new SurvivalCuboManager(); serverPingListener = new PacketOutServerInfoListener(this); + staffQueueManager = new StaffQueueManager(); + tpsAnalysisManager = new TPSAnalysisManager(); + + + + getServer().getScheduler().runTaskLater(this, new Runnable() { @@ -109,25 +98,20 @@ public class PandacraftUtils extends JavaPlugin { @Override public void onDisable(){ - commandPlayers = null; - commandSetblock = null; - commandAfk = null; - commandSystem = null; - commandPing = null; - commandMe = null; - commandWandSelection = null; - commandStaff = null; - commandCubo = null; - commandBroadcast = null; + afkManager = null; + wESelectionDisplayManager = null; commandAliasManager = null; spawnTimeManager = null; chatAnalysisManager = null; creativCheatManager = null; noPvpProtectManager = null; calculatorManager = null; - + survivalCuboManager = null; serverPingListener = null; + staffQueueManager = null; + tpsAnalysisManager = null; + ConfigManager.reloadConfig(); @@ -141,6 +125,21 @@ public class PandacraftUtils extends JavaPlugin { + + + + + + + + + + + + + + + /** * Envoi d'un message groupé à plusieurs ou à tout les joueurs et peut-être à la console * @param message message à envoyer diff --git a/src/net/mc_pandacraft/java/plugin/pandacraftutils/commands/AbstractCommandExecutor.java b/src/net/mc_pandacraft/java/plugin/pandacraftutils/commands/AbstractCommandExecutor.java new file mode 100644 index 0000000..2b10aa3 --- /dev/null +++ b/src/net/mc_pandacraft/java/plugin/pandacraftutils/commands/AbstractCommandExecutor.java @@ -0,0 +1,31 @@ +package net.mc_pandacraft.java.plugin.pandacraftutils.commands; + +import org.bukkit.command.CommandExecutor; + +import net.mc_pandacraft.java.plugin.pandacraftutils.PandacraftUtils; + +/** + * Classe parente de toutes les classes devant prendre en charge l'exécution d'une commande Minecraft + */ + +/* package */ abstract class AbstractCommandExecutor implements CommandExecutor { + + protected PandacraftUtils plugin = PandacraftUtils.getInstance(); + + protected final String commandName; + + /** + * + * @param cName (ne peut être null) nom de la commande tel que défini dans le fichier plugin.yml + */ + public AbstractCommandExecutor(String cName) { + if (cName == null) throw new IllegalArgumentException("La commande doit avoir un nom"); + commandName = cName; + + plugin.getCommand(commandName).setExecutor(this); + } + + public String getCommandName() { return commandName; } + + +} diff --git a/src/net/mc_pandacraft/java/plugin/pandacraftutils/commands/CommandAfk.java b/src/net/mc_pandacraft/java/plugin/pandacraftutils/commands/CommandAfk.java new file mode 100644 index 0000000..c18e503 --- /dev/null +++ b/src/net/mc_pandacraft/java/plugin/pandacraftutils/commands/CommandAfk.java @@ -0,0 +1,94 @@ +package net.mc_pandacraft.java.plugin.pandacraftutils.commands; + +import net.mc_pandacraft.java.plugin.pandacraftutils.players.OnlinePlayer; +import net.mc_pandacraft.java.plugin.pandacraftutils.players.OnlinePlayerManager; + +import org.bukkit.command.Command; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +public class CommandAfk extends AbstractCommandExecutor { + + public CommandAfk() { + super("afk"); + } + + + + + + @Override + public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) + { + boolean execute_self = false; + boolean execute_other = false; + Player other_player = null; + + if(sender instanceof Player) + { + if (args.length > 0) + { + if (((Player)sender).hasPermission("pandacraft.afk.other")) + { + if (plugin.getServer().getPlayer(args[0]) != null) + { + other_player = plugin.getServer().getPlayer(args[0]); + execute_other = true; + } + else + sender.sendMessage("§cLe joueur n'existe pas."); + } + else + { + sender.sendMessage("§cVous n'avez pas la permission d'effectuer cette action sur un autre joueur."); + } + } + else + execute_self = true; + } + else + { + if (args.length > 0) + { + if (plugin.getServer().getPlayer(args[0]) != null) + { + other_player = plugin.getServer().getPlayer(args[0]); + execute_other = true; + } + else + sender.sendMessage("§cLe joueur n'existe pas."); + } + else + sender.sendMessage("§cVeuillez indiquer un joueur."); + + } + + + if (execute_self) + { + Player p = (Player)sender; + OnlinePlayer ap = OnlinePlayerManager.getInstance().get(p); + if (ap == null) + plugin.getLogger().severe("Cant find AfkPlayer with name "+p.getName()+" when performing command /afk"); + else + ap.performAfkCommand(); + return true; + } + else if (execute_other && other_player != null) + { + OnlinePlayer ap = OnlinePlayerManager.getInstance().get(other_player); + if (ap == null) + plugin.getLogger().severe("Cant find AfkPlayer with name "+other_player.getName()+" when performing command /afk "); + ap.adminToggleAfk(); + return true; + } + + + + + + return false; + } + + +} diff --git a/src/net/mc_pandacraft/java/plugin/pandacraftutils/simple_commands/broadcast/CommandBroadcast.java b/src/net/mc_pandacraft/java/plugin/pandacraftutils/commands/CommandBroadcast.java similarity index 65% rename from src/net/mc_pandacraft/java/plugin/pandacraftutils/simple_commands/broadcast/CommandBroadcast.java rename to src/net/mc_pandacraft/java/plugin/pandacraftutils/commands/CommandBroadcast.java index 9764bf8..6b349f0 100644 --- a/src/net/mc_pandacraft/java/plugin/pandacraftutils/simple_commands/broadcast/CommandBroadcast.java +++ b/src/net/mc_pandacraft/java/plugin/pandacraftutils/commands/CommandBroadcast.java @@ -1,20 +1,15 @@ -package net.mc_pandacraft.java.plugin.pandacraftutils.simple_commands.broadcast; - -import net.mc_pandacraft.java.plugin.pandacraftutils.PandacraftUtils; +package net.mc_pandacraft.java.plugin.pandacraftutils.commands; import org.apache.commons.lang.StringUtils; import org.bukkit.ChatColor; import org.bukkit.command.Command; -import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandSender; -public class CommandBroadcast implements CommandExecutor { - - private PandacraftUtils plugin; - - public CommandBroadcast(PandacraftUtils pl) { - plugin = pl; - plugin.getCommand("broadcast").setExecutor(this); +public class CommandBroadcast extends AbstractCommandExecutor { + public CommandBroadcast() { + super("broadcast"); + + // classe qui gère deux commandes (presque identiques) plugin.getCommand("broadcastperm").setExecutor(this); } diff --git a/src/net/mc_pandacraft/java/plugin/pandacraftutils/survival_cuboid/CommandCubo.java b/src/net/mc_pandacraft/java/plugin/pandacraftutils/commands/CommandCubo.java similarity index 84% rename from src/net/mc_pandacraft/java/plugin/pandacraftutils/survival_cuboid/CommandCubo.java rename to src/net/mc_pandacraft/java/plugin/pandacraftutils/commands/CommandCubo.java index c8ff361..efbbb34 100644 --- a/src/net/mc_pandacraft/java/plugin/pandacraftutils/survival_cuboid/CommandCubo.java +++ b/src/net/mc_pandacraft/java/plugin/pandacraftutils/commands/CommandCubo.java @@ -1,25 +1,21 @@ -package net.mc_pandacraft.java.plugin.pandacraftutils.survival_cuboid; +package net.mc_pandacraft.java.plugin.pandacraftutils.commands; import java.math.BigDecimal; import java.util.ArrayList; import java.util.List; -import java.util.Map; import java.util.Random; import java.util.Set; import net.mc_pandacraft.java.plugin.pandacraftutils.ConfigManager; -import net.mc_pandacraft.java.plugin.pandacraftutils.PandacraftUtils; import net.mc_pandacraft.java.plugin.pandacraftutils.plugin_interface.EssentialsInterface; import net.mc_pandacraft.java.plugin.pandacraftutils.plugin_interface.WorldEditInterface; +import net.mc_pandacraft.java.plugin.pandacraftutils.plugin_interface.WorldGuardInterface; import net.mc_pandacraft.java.util.StringUtil; import org.bukkit.ChatColor; -import org.bukkit.World; import org.bukkit.command.Command; -import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; -import org.bukkit.plugin.Plugin; import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.bukkit.WorldEditPlugin; @@ -32,41 +28,21 @@ import com.sk89q.worldguard.protection.databases.ProtectionDatabaseException; import com.sk89q.worldguard.protection.regions.ProtectedCuboidRegion; import com.sk89q.worldguard.protection.regions.ProtectedRegion; -public class CommandCubo implements CommandExecutor { +public class CommandCubo extends AbstractCommandExecutor { - private PandacraftUtils plugin; - - private WorldGuardPlugin wgPlugin; - - private String regex_cubo_id = "cubo[0-9]+-[0-9A-Za-z_]+-[0-9A-Za-z_]+"; - - public CommandCubo(PandacraftUtils pl) { - plugin = pl; - - - plugin.getCommand("cubo").setExecutor(this); - - - Plugin wg = plugin.getServer().getPluginManager().getPlugin("WorldGuard"); - - // WorldGuard may not be loaded - if (wg == null || !(wg instanceof WorldGuardPlugin)) { - try { throw new Exception("Impossible de récupérer l'instance du plugin WorldGuard"); - } catch (Exception e) { e.printStackTrace(); } - } - - wgPlugin = (WorldGuardPlugin) wg; - + public CommandCubo() { + super("cubo"); } + - - - + @Override public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { + WorldGuardPlugin wgPlugin = WorldGuardInterface.getPlugin(); + if (args.length == 0 || !(sender instanceof Player)) { showHelp(sender); @@ -93,7 +69,7 @@ public class CommandCubo implements CommandExecutor { return true; } - if (hasStaffPermission(player) && args.length >= 2 && plugin.getServer().getPlayer(args[1]) == null) + if (plugin.survivalCuboManager.hasStaffPermission(player) && args.length >= 2 && plugin.getServer().getPlayer(args[1]) == null) { // un joueur est indiqué mais il n'est pas connecté player.sendMessage(ChatColor.RED+"Le joueur concerné n'est pas en ligne"); return true; @@ -102,7 +78,7 @@ public class CommandCubo implements CommandExecutor { // on cherche si on traite un autre joueur Player player_cubo; - if (!hasStaffPermission(player) || args.length < 2 || (player_cubo = plugin.getServer().getPlayer(args[1])) == null) + if (!plugin.survivalCuboManager.hasStaffPermission(player) || args.length < 2 || (player_cubo = plugin.getServer().getPlayer(args[1])) == null) player_cubo = player; player.sendMessage(ChatColor.GOLD+"----- Devis pour la création d'un cubo -----"); @@ -150,10 +126,10 @@ public class CommandCubo implements CommandExecutor { // on vérifie si le joueur peut payer double actual_money = EssentialsInterface.getPlayerMoney(player_cubo); - int volume_actuel_cubo = getPlayerActualBlockCount(player_cubo, selection.getWorld()); + int volume_actuel_cubo = plugin.survivalCuboManager.getPlayerActualBlockCount(player_cubo, selection.getWorld()); int volume_apres_cubo = volume_actuel_cubo + cubo.volume(); - double prix_actuel_cubo = getVolumePrice(volume_actuel_cubo); - double prix_apres_cubo = getVolumePrice(volume_apres_cubo); + double prix_actuel_cubo = plugin.survivalCuboManager.getVolumePrice(volume_actuel_cubo); + double prix_apres_cubo = plugin.survivalCuboManager.getVolumePrice(volume_apres_cubo); double prix_a_payer = prix_apres_cubo - prix_actuel_cubo; player.sendMessage(ChatColor.GOLD+"Solde actuel : "+StringUtil.formatDouble(actual_money)); @@ -201,7 +177,7 @@ public class CommandCubo implements CommandExecutor { player.sendMessage(ChatColor.RED+"Vous devez faire une sélection WorldEdit : faites "+ChatColor.GRAY+"//wand"); return true; } - if (hasStaffPermission(player) && args.length >= 3 && plugin.getServer().getPlayer(args[2]) == null) + if (plugin.survivalCuboManager.hasStaffPermission(player) && args.length >= 3 && plugin.getServer().getPlayer(args[2]) == null) { // un joueur est indiqué mais il n'est pas connecté player.sendMessage(ChatColor.RED+"Le joueur concerné n'est pas en ligne"); return true; @@ -209,7 +185,7 @@ public class CommandCubo implements CommandExecutor { // on cherche si on traite un autre joueur Player player_cubo; - if (!hasStaffPermission(player) || args.length < 3 || (player_cubo = plugin.getServer().getPlayer(args[2])) == null) + if (!plugin.survivalCuboManager.hasStaffPermission(player) || args.length < 3 || (player_cubo = plugin.getServer().getPlayer(args[2])) == null) player_cubo = player; player.sendMessage(ChatColor.GOLD+"----- Création d'un cubo -----"); @@ -262,10 +238,10 @@ public class CommandCubo implements CommandExecutor { // on vérifie si le joueur peut payer double actual_money = EssentialsInterface.getPlayerMoney(player_cubo); - int volume_actuel_cubo = getPlayerActualBlockCount(player_cubo, selection.getWorld()); + int volume_actuel_cubo = plugin.survivalCuboManager.getPlayerActualBlockCount(player_cubo, selection.getWorld()); int volume_apres_cubo = volume_actuel_cubo + cubo.volume(); - double prix_actuel_cubo = getVolumePrice(volume_actuel_cubo); - double prix_apres_cubo = getVolumePrice(volume_apres_cubo); + double prix_actuel_cubo = plugin.survivalCuboManager.getVolumePrice(volume_actuel_cubo); + double prix_apres_cubo = plugin.survivalCuboManager.getVolumePrice(volume_apres_cubo); double prix_a_payer = prix_apres_cubo - prix_actuel_cubo; @@ -330,11 +306,11 @@ public class CommandCubo implements CommandExecutor { // on cherche si on traite un autre joueur String player_cubo = player.getName(); - if (hasStaffPermission(player) && args.length >= 3) + if (plugin.survivalCuboManager.hasStaffPermission(player) && args.length >= 3) player_cubo = args[2]; - List cubos = getPlayerCubo(player_cubo, player.getWorld()); + List cubos = plugin.survivalCuboManager.getPlayerCubo(player_cubo, player.getWorld()); int nb_page = (int)Math.ceil(cubos.size()/5D); if (num_page > nb_page) num_page = nb_page; @@ -372,7 +348,7 @@ public class CommandCubo implements CommandExecutor { for(ProtectedRegion cubo : wgPlugin.getRegionManager(player.getWorld()).getApplicableRegions(player.getLocation())) { if (!(cubo instanceof ProtectedCuboidRegion)) continue; - if (!cubo.getId().matches(regex_cubo_id)) continue; + if (!cubo.getId().matches(plugin.survivalCuboManager.regex_cubo_id)) continue; inside_cubo = (ProtectedCuboidRegion) cubo; break; } @@ -418,7 +394,7 @@ public class CommandCubo implements CommandExecutor { player.sendMessage(ChatColor.RED+"Vous ne vous trouvez dans aucun cubo"); return true; } - if (!inside_cubo.isOwner(player.getName()) && !hasStaffPermission(player)) + if (!inside_cubo.isOwner(player.getName()) && !plugin.survivalCuboManager.hasStaffPermission(player)) { player.sendMessage(ChatColor.RED+"Vous n'avez pas la permission de faire cette action pour ce cubo"); return true; @@ -439,7 +415,7 @@ public class CommandCubo implements CommandExecutor { player.sendMessage(ChatColor.RED+"Vous ne vous trouvez dans aucun cubo"); return true; } - if (!inside_cubo.isOwner(player.getName()) && !hasStaffPermission(player)) + if (!inside_cubo.isOwner(player.getName()) && !plugin.survivalCuboManager.hasStaffPermission(player)) { player.sendMessage(ChatColor.RED+"Vous n'avez pas la permission de faire cette action pour ce cubo"); return true; @@ -455,9 +431,10 @@ public class CommandCubo implements CommandExecutor { double actu_money = EssentialsInterface.getPlugin().getUser(proprio_cubo).getMoney().doubleValue(); - int actu_volume_cubo = getPlayerActualBlockCount(proprio_cubo, player.getWorld()); + int actu_volume_cubo = plugin.survivalCuboManager.getPlayerActualBlockCount(proprio_cubo, player.getWorld()); int new_volume_cubo = actu_volume_cubo - inside_cubo.volume(); - double money_win = getVolumePrice(actu_volume_cubo) - getVolumePrice(new_volume_cubo); + double money_win = plugin.survivalCuboManager.getVolumePrice(actu_volume_cubo) + - plugin.survivalCuboManager.getVolumePrice(new_volume_cubo); wgPlugin.getRegionManager(player.getWorld()).removeRegion(inside_cubo.getId()); @@ -495,7 +472,7 @@ public class CommandCubo implements CommandExecutor { player.sendMessage(ChatColor.RED+"Vous ne vous trouvez dans aucun cubo"); return true; } - if (!inside_cubo.isOwner(player.getName()) && !hasStaffPermission(player)) + if (!inside_cubo.isOwner(player.getName()) && !plugin.survivalCuboManager.hasStaffPermission(player)) { player.sendMessage(ChatColor.RED+"Vous n'avez pas la permission de faire cette action pour ce cubo"); return true; @@ -534,7 +511,7 @@ public class CommandCubo implements CommandExecutor { player.sendMessage(ChatColor.RED+"Vous ne vous trouvez dans aucun cubo"); return true; } - if (!inside_cubo.isOwner(player.getName()) && !hasStaffPermission(player)) + if (!inside_cubo.isOwner(player.getName()) && !plugin.survivalCuboManager.hasStaffPermission(player)) { player.sendMessage(ChatColor.RED+"Vous n'avez pas la permission de faire cette action pour ce cubo"); return true; @@ -573,7 +550,7 @@ public class CommandCubo implements CommandExecutor { player.sendMessage(ChatColor.RED+"Vous ne vous trouvez dans aucun cubo"); return true; } - if (!inside_cubo.isOwner(player.getName()) && !hasStaffPermission(player)) + if (!inside_cubo.isOwner(player.getName()) && !plugin.survivalCuboManager.hasStaffPermission(player)) { player.sendMessage(ChatColor.RED+"Vous n'avez pas la permission de faire cette action pour ce cubo"); return true; @@ -614,7 +591,7 @@ public class CommandCubo implements CommandExecutor { if (args[0].equalsIgnoreCase("convert")) { - if (!hasStaffPermission(player)) + if (!plugin.survivalCuboManager.hasStaffPermission(player)) { player.sendMessage(ChatColor.RED+"Vous n'avez pas la permission de faire cette action"); return true; @@ -646,7 +623,7 @@ public class CommandCubo implements CommandExecutor { // on ignore les cubos dans le bon format - if (region_to_convert.getId().matches(regex_cubo_id)) + if (region_to_convert.getId().matches(plugin.survivalCuboManager.regex_cubo_id)) { nb_converted++; continue; @@ -790,10 +767,10 @@ public class CommandCubo implements CommandExecutor { - public void showHelp(CommandSender sender) { + private void showHelp(CommandSender sender) { String[] messages = null; - if ((sender instanceof Player) && hasStaffPermission((Player)sender)) + if ((sender instanceof Player) && plugin.survivalCuboManager.hasStaffPermission((Player)sender)) { // pour le staff connecté String[] m = { ChatColor.GOLD+"----- Assistant de protection en Survie -----", @@ -848,103 +825,5 @@ public class CommandCubo implements CommandExecutor { - - - - - - - - - - - - - - - - - - - /** - * @param p le joueur - * @param w le monde - * @return tout les cubos d'un joueur donné sur un monde donné - */ - public List getPlayerCubo(Player p, World w) { - return getPlayerCubo(p.getName(), w); - } - - - /** - * @param p le pseudo du joueur - * @param w le monde - * @return tout les cubos d'un joueur donné sur un monde donné - */ - public List getPlayerCubo(String p, World w) { - - Map regions = wgPlugin.getRegionManager(w).getRegions(); - List playerRegions = new ArrayList(); - - for (Map.Entry region : regions.entrySet()) { - // on ne prend en charge que les cuboides - if (!(region.getValue() instanceof ProtectedCuboidRegion)) - continue; - // on garde les régions gérés par la commande - if (!region.getValue().getId().matches(regex_cubo_id)) - continue; - if (!region.getValue().isOwner(p)) - continue; - playerRegions.add((ProtectedCuboidRegion)region.getValue()); - } - return playerRegions; - } - - /** - * - * @param p le joueur - * @param w le monde - * @return le volume total des cubos d'un joueur donné sur un monde donné - */ - public int getPlayerActualBlockCount(Player p, World w) { - return getPlayerActualBlockCount(p.getName(), w); - } - - /** - * - * @param p le joueur - * @param w le monde - * @return le volume total des cubos d'un joueur donné sur un monde donné - */ - public int getPlayerActualBlockCount(String p, World w) { - List regions = getPlayerCubo(p, w); - int nb = 0; - for (ProtectedCuboidRegion region : regions){ - nb += region.volume(); - } - return nb; - } - - /** - * - * @param nb le volume - * @return le prix pour le volume donné - */ - public double getVolumePrice(int nb) { - if (nb <= 2000) - return 0; - - if (nb<= 100000) - return nb-2000D; - - return Math.pow(((nb-2000D)/98000D),1.5)*98000; - } - - - - public boolean hasStaffPermission(Player p) { - return p.hasPermission("pandacraft.cubo.staff"); - } - } diff --git a/src/net/mc_pandacraft/java/plugin/pandacraftutils/simple_commands/list/CommandList.java b/src/net/mc_pandacraft/java/plugin/pandacraftutils/commands/CommandList.java similarity index 89% rename from src/net/mc_pandacraft/java/plugin/pandacraftutils/simple_commands/list/CommandList.java rename to src/net/mc_pandacraft/java/plugin/pandacraftutils/commands/CommandList.java index 0ab0dc3..e4765a6 100644 --- a/src/net/mc_pandacraft/java/plugin/pandacraftutils/simple_commands/list/CommandList.java +++ b/src/net/mc_pandacraft/java/plugin/pandacraftutils/commands/CommandList.java @@ -1,30 +1,26 @@ -package net.mc_pandacraft.java.plugin.pandacraftutils.simple_commands.list; +package net.mc_pandacraft.java.plugin.pandacraftutils.commands; import java.util.ArrayList; import net.mc_pandacraft.java.plugin.pandacraftutils.ConfigManager; -import net.mc_pandacraft.java.plugin.pandacraftutils.PandacraftUtils; 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.plugin_interface.EssentialsInterface; +import net.mc_pandacraft.java.util.StringUtil; import net.mc_pandacraft.java.util.TimeUtil; import org.bukkit.GameMode; import org.bukkit.Server; import org.bukkit.World; import org.bukkit.command.Command; -import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandSender; import org.bukkit.craftbukkit.v1_7_R1.entity.CraftPlayer; import org.bukkit.entity.Player; -public class CommandList implements CommandExecutor { - private PandacraftUtils plugin; - - public CommandList(PandacraftUtils pl) +public class CommandList extends AbstractCommandExecutor { + public CommandList() { - plugin = pl; - plugin.getCommand("list").setExecutor(this); + super("list"); } public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) @@ -233,17 +229,17 @@ public class CommandList implements CommandExecutor { } - int max_length = (header.length()-2*char_count(header, '§')) + 2; + int max_length = (header.length()-2*StringUtil.char_count(header, '§')) + 2; max_length += 2; // évite le décalage de l'entête si il n'y a aucun trait à gauche for (String line : aff_list) - max_length = (line != null && (line.length()-2*char_count(line, '§')) > max_length) ? (line.length()-2*char_count(line, '§')) : max_length; + max_length = (line != null && (line.length()-2*StringUtil.char_count(line, '§')) > max_length) ? (line.length()-2*StringUtil.char_count(line, '§')) : max_length; if (max_length > 70) max_length = 70; - long header_left_aff = Math.round(Math.floor((max_length - (header.length()-2*char_count(header, '§')) - 2)/2D)); + long header_left_aff = Math.round(Math.floor((max_length - (header.length()-2*StringUtil.char_count(header, '§')) - 2)/2D)); if (header_left_aff < 0) header_left_aff = 0; - long header_right_aff = Math.round(Math.ceil((max_length - (header.length()-2*char_count(header, '§')) - 2)/2D)); + long header_right_aff = Math.round(Math.ceil((max_length - (header.length()-2*StringUtil.char_count(header, '§')) - 2)/2D)); if (header_right_aff < 0) header_right_aff = 0; String final_header = decoration_color; @@ -276,24 +272,5 @@ public class CommandList implements CommandExecutor { - - private int char_count(String s, char c_match) - { - char[] chars = s.toCharArray(); - int count = 0; - for (char c : chars) - if (c == c_match) - count++; - return count; - } - - - - - - - - - } diff --git a/src/net/mc_pandacraft/java/plugin/pandacraftutils/simple_commands/me/CommandMe.java b/src/net/mc_pandacraft/java/plugin/pandacraftutils/commands/CommandMe.java similarity index 78% rename from src/net/mc_pandacraft/java/plugin/pandacraftutils/simple_commands/me/CommandMe.java rename to src/net/mc_pandacraft/java/plugin/pandacraftutils/commands/CommandMe.java index 6cc9629..a108a8d 100644 --- a/src/net/mc_pandacraft/java/plugin/pandacraftutils/simple_commands/me/CommandMe.java +++ b/src/net/mc_pandacraft/java/plugin/pandacraftutils/commands/CommandMe.java @@ -1,26 +1,22 @@ -package net.mc_pandacraft.java.plugin.pandacraftutils.simple_commands.me; +package net.mc_pandacraft.java.plugin.pandacraftutils.commands; -import net.mc_pandacraft.java.plugin.pandacraftutils.PandacraftUtils; import net.mc_pandacraft.java.plugin.pandacraftutils.plugin_interface.EssentialsInterface; import org.apache.commons.lang.StringUtils; import org.bukkit.ChatColor; import org.bukkit.command.Command; -import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandSender; import org.bukkit.command.ConsoleCommandSender; import org.bukkit.command.RemoteConsoleCommandSender; import org.bukkit.entity.Player; -public class CommandMe implements CommandExecutor { +public class CommandMe extends AbstractCommandExecutor { - private PandacraftUtils plugin; - - public CommandMe(PandacraftUtils pl) { - plugin = pl; - plugin.getCommand("me").setExecutor(this); + public CommandMe() { + super("me"); } + @Override public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { if (args.length == 0) return false; diff --git a/src/net/mc_pandacraft/java/plugin/pandacraftutils/simple_commands/ping/CommandPing.java b/src/net/mc_pandacraft/java/plugin/pandacraftutils/commands/CommandPing.java similarity index 69% rename from src/net/mc_pandacraft/java/plugin/pandacraftutils/simple_commands/ping/CommandPing.java rename to src/net/mc_pandacraft/java/plugin/pandacraftutils/commands/CommandPing.java index e509bd6..13f5149 100644 --- a/src/net/mc_pandacraft/java/plugin/pandacraftutils/simple_commands/ping/CommandPing.java +++ b/src/net/mc_pandacraft/java/plugin/pandacraftutils/commands/CommandPing.java @@ -1,25 +1,17 @@ -package net.mc_pandacraft.java.plugin.pandacraftutils.simple_commands.ping; - - -import net.mc_pandacraft.java.plugin.pandacraftutils.PandacraftUtils; +package net.mc_pandacraft.java.plugin.pandacraftutils.commands; import org.bukkit.ChatColor; import org.bukkit.command.Command; -import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandSender; import org.bukkit.command.ConsoleCommandSender; import org.bukkit.craftbukkit.v1_7_R1.entity.CraftPlayer; import org.bukkit.entity.Player; -public class CommandPing implements CommandExecutor { +public class CommandPing extends AbstractCommandExecutor { - private PandacraftUtils plugin; - - public CommandPing(PandacraftUtils pl) + public CommandPing() { - plugin = pl; - - plugin.getCommand("ping").setExecutor(this); + super("ping"); } @Override diff --git a/src/net/mc_pandacraft/java/plugin/pandacraftutils/simple_commands/setblock/CommandSetblock.java b/src/net/mc_pandacraft/java/plugin/pandacraftutils/commands/CommandSetblock.java similarity index 89% rename from src/net/mc_pandacraft/java/plugin/pandacraftutils/simple_commands/setblock/CommandSetblock.java rename to src/net/mc_pandacraft/java/plugin/pandacraftutils/commands/CommandSetblock.java index a52e8a8..2c4b50a 100644 --- a/src/net/mc_pandacraft/java/plugin/pandacraftutils/simple_commands/setblock/CommandSetblock.java +++ b/src/net/mc_pandacraft/java/plugin/pandacraftutils/commands/CommandSetblock.java @@ -1,24 +1,18 @@ -package net.mc_pandacraft.java.plugin.pandacraftutils.simple_commands.setblock; - -import net.mc_pandacraft.java.plugin.pandacraftutils.PandacraftUtils; +package net.mc_pandacraft.java.plugin.pandacraftutils.commands; import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.World; import org.bukkit.command.BlockCommandSender; import org.bukkit.command.Command; -import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandSender; import org.bukkit.command.ConsoleCommandSender; import org.bukkit.entity.Player; -public class CommandSetblock implements CommandExecutor { - private PandacraftUtils plugin; - - public CommandSetblock(PandacraftUtils pl) +public class CommandSetblock extends AbstractCommandExecutor { + public CommandSetblock() { - plugin = pl; - plugin.getCommand("setblock").setExecutor(this); + super("setblock"); } diff --git a/src/net/mc_pandacraft/java/plugin/pandacraftutils/simple_commands/staff_player_help/CommandStaff.java b/src/net/mc_pandacraft/java/plugin/pandacraftutils/commands/CommandStaff.java similarity index 61% rename from src/net/mc_pandacraft/java/plugin/pandacraftutils/simple_commands/staff_player_help/CommandStaff.java rename to src/net/mc_pandacraft/java/plugin/pandacraftutils/commands/CommandStaff.java index a0e0a46..bc11943 100644 --- a/src/net/mc_pandacraft/java/plugin/pandacraftutils/simple_commands/staff_player_help/CommandStaff.java +++ b/src/net/mc_pandacraft/java/plugin/pandacraftutils/commands/CommandStaff.java @@ -1,72 +1,43 @@ -package net.mc_pandacraft.java.plugin.pandacraftutils.simple_commands.staff_player_help; +package net.mc_pandacraft.java.plugin.pandacraftutils.commands; import java.util.Date; -import java.util.LinkedList; -import java.util.Queue; -import net.mc_pandacraft.java.plugin.pandacraftutils.PandacraftUtils; +import net.mc_pandacraft.java.plugin.pandacraftutils.modules.StaffQueueManager; +import net.mc_pandacraft.java.plugin.pandacraftutils.modules.StaffQueueManager.WaitingPlayer; import net.mc_pandacraft.java.util.TimeUtil; import org.apache.commons.lang.StringUtils; -import org.bukkit.Bukkit; import org.bukkit.ChatColor; -import org.bukkit.Location; -import org.bukkit.OfflinePlayer; import org.bukkit.command.Command; -import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; -import org.bukkit.event.EventHandler; -import org.bukkit.event.Listener; -import org.bukkit.event.player.PlayerJoinEvent; -import org.bukkit.event.player.PlayerQuitEvent; -import org.bukkit.scoreboard.DisplaySlot; -import org.bukkit.scoreboard.Objective; -import org.bukkit.scoreboard.Score; -import org.bukkit.scoreboard.Scoreboard; -public class CommandStaff implements CommandExecutor, Listener { - - private PandacraftUtils plugin; - - - private Queue playerQueue = new LinkedList(); - - private Scoreboard scoreboardPlayerQueue; - - - public CommandStaff(PandacraftUtils pl) { - plugin = pl; - plugin.getCommand("staff").setExecutor(this); +public class CommandStaff extends AbstractCommandExecutor { - plugin.getServer().getPluginManager().registerEvents(this, plugin); - - - scoreboardPlayerQueue = Bukkit.getScoreboardManager().getNewScoreboard(); + public CommandStaff() { + super("staff"); } - - @Override public boolean onCommand(CommandSender sender, Command cmd, String alias, String[] args) { + StaffQueueManager staffManager = plugin.staffQueueManager; if (sender instanceof Player && !((Player)sender).hasPermission("pandacraft.grade.staff")) { // un joueur qui n'est pas du staff // le joueur est-il déjà en file d'attente ? - if (getWaitingPlayer((Player)sender) != null) { + if (staffManager.getWaitingPlayer((Player)sender) != null) { if (args.length > 0 && args[0].equalsIgnoreCase("annuler")) { - removePlayer((Player)sender); - updateScoreBoardWaitingList(); + staffManager.removePlayer((Player)sender); sender.sendMessage(ChatColor.GREEN+"Vous avez été retiré de la file d'attente"); return true; } else if (args.length > 0 && args[0].equalsIgnoreCase("position")) { - sender.sendMessage(ChatColor.GREEN+"Vous êtes à la position "+getPlayerPosition((Player)sender)+" de la file d'attente"); + sender.sendMessage(ChatColor.GREEN+"Vous êtes à la position "+staffManager.getPlayerPosition((Player)sender)+" de la file d'attente"); return true; } sender.sendMessage(ChatColor.GREEN+"Vous êtes déjà dans la file d'attente"); @@ -84,10 +55,10 @@ public class CommandStaff implements CommandExecutor, Listener { return true; } - playerQueue.add(new WaitingPlayer(((Player)sender).getName(), StringUtils.join(args, " "), ((Player)sender).getLocation())); - updateScoreBoardWaitingList(); + staffManager.playerQueue.add(staffManager.new WaitingPlayer(((Player)sender).getName(), StringUtils.join(args, " "), ((Player)sender).getLocation())); + staffManager.updateScoreBoardWaitingList(); sender.sendMessage(ChatColor.GREEN+"Veuillez maintenant patienter quelques instant, le temps que le staff traite le début de la file d'attente ;)"); - sender.sendMessage(ChatColor.GREEN+"Vous êtes à la position "+getPlayerPosition((Player)sender)+" de la file d'attente"); + sender.sendMessage(ChatColor.GREEN+"Vous êtes à la position "+staffManager.getPlayerPosition((Player)sender)+" de la file d'attente"); return true; } else if (sender instanceof Player) @@ -127,6 +98,9 @@ public class CommandStaff implements CommandExecutor, Listener { private boolean onCommand_admin_commands(CommandSender sender, String[] args) { + + StaffQueueManager staffManager = plugin.staffQueueManager; + if (args[0].equalsIgnoreCase("?")) { // affichage de l'aide sender.sendMessage(ChatColor.GOLD+"--- Commandes administratives pour gérer la file d'attente ---"); @@ -138,15 +112,14 @@ public class CommandStaff implements CommandExecutor, Listener { } else if (args[0].equalsIgnoreCase("select") && args.length > 1 && sender instanceof Player) { - WaitingPlayer wp = getWaitingPlayer(args[1]); + WaitingPlayer wp = staffManager.getWaitingPlayer(args[1]); if (wp == null) { sender.sendMessage(ChatColor.RED+"Le joueur n'est pas dans la liste"); return true; } - removePlayer(args[1]); - updateScoreBoardWaitingList(); + staffManager.removePlayer(args[1]); Player p = plugin.getServer().getPlayerExact(wp.getPlayerName()); @@ -181,14 +154,13 @@ public class CommandStaff implements CommandExecutor, Listener { } else if (args[0].equalsIgnoreCase("remove") && args.length > 1) { - WaitingPlayer wp = getWaitingPlayer(args[1]); + WaitingPlayer wp = staffManager.getWaitingPlayer(args[1]); if (wp == null) { sender.sendMessage(ChatColor.RED+"Le joueur n'est pas dans la liste"); return true; } - removePlayer(args[1]); - updateScoreBoardWaitingList(); + staffManager.removePlayer(args[1]); Player p = plugin.getServer().getPlayerExact(wp.getPlayerName()); if (p != null && p.isOnline()) { p.sendMessage(ChatColor.RED+"Vous avez été retiré de la liste des joueurs en attente"); @@ -209,7 +181,7 @@ public class CommandStaff implements CommandExecutor, Listener { return true; } - WaitingPlayer wp = getWaitingPlayer(p.getName()); + WaitingPlayer wp = staffManager.getWaitingPlayer(p.getName()); if (wp != null) { sender.sendMessage(ChatColor.RED+"Le joueur est déjà dans la liste"); return true; @@ -224,9 +196,8 @@ public class CommandStaff implements CommandExecutor, Listener { String message = StringUtils.join(args, " "); - playerQueue.add(new WaitingPlayer(p.getName(),message, p.getLocation())); - - updateScoreBoardWaitingList(); + staffManager.playerQueue.add(staffManager.new WaitingPlayer(p.getName(),message, p.getLocation())); + staffManager.updateScoreBoardWaitingList(); sender.sendMessage(ChatColor.GREEN+"Vous venez d'ajouter "+p.getDisplayName()+ChatColor.RESET+ChatColor.GREEN+" dans la file d'attente"); @@ -243,66 +214,13 @@ public class CommandStaff implements CommandExecutor, Listener { - - - - - - - - - private WaitingPlayer getWaitingPlayer(String p) { - for (WaitingPlayer wp : playerQueue) - { - if (wp != null && wp.getPlayerName().equalsIgnoreCase(p)) - return wp; - } - return null; - } - - - private WaitingPlayer getWaitingPlayer(OfflinePlayer p) { - return getWaitingPlayer(p.getName()); - } - - - - - private int getPlayerPosition(OfflinePlayer p) { - int i = 0; - for (WaitingPlayer wp : playerQueue) - { - i++; - if (wp != null && wp.getPlayerName().equalsIgnoreCase(p.getName())) - return i; - } - return -1; - } - - - - private void removePlayer(String p) { - WaitingPlayer wp = getWaitingPlayer(p); - if (wp != null) - playerQueue.remove(wp); - } - private void removePlayer(OfflinePlayer p) { - removePlayer(p.getName()); - } - - - - - - - private void showWaintingList(CommandSender sender) { sender.sendMessage(ChatColor.BOLD+"-- File d'attente des joueurs pour le staff --"); - + int i=0; - for (WaitingPlayer wp : playerQueue) { + for (WaitingPlayer wp : plugin.staffQueueManager.playerQueue) { i++; Player p = plugin.getServer().getPlayerExact(wp.getPlayerName()); String name; @@ -325,104 +243,9 @@ public class CommandStaff implements CommandExecutor, Listener { - private void updateScoreBoardWaitingList() { - Objective obj = scoreboardPlayerQueue.getObjective("file_attente"); - if (obj != null) - obj.unregister(); - - - obj = scoreboardPlayerQueue.registerNewObjective("file_attente", "dummy"); - obj.setDisplayName(ChatColor.GOLD+"File d'attente staff"); - obj.setDisplaySlot(DisplaySlot.SIDEBAR); - - int i=0; - for (WaitingPlayer wp : playerQueue) { - i++; - - Player p = plugin.getServer().getPlayerExact(wp.getPlayerName()); - String name; - if (p == null || !p.isOnline()) - name = wp.getPlayerName(); - else - name = p.getPlayerListName(); - - String line = i+"."+name; - int boardPos = playerQueue.size()-i+1; - - - Score score = obj.getScore(plugin.getServer().getOfflinePlayer(line.substring(0, (line.length()>16)?16:line.length()))); - - score.setScore(boardPos); - } - } - - - - - - - - - - - @EventHandler - public void onPlayerJoin(PlayerJoinEvent event) { - Player p = event.getPlayer(); - if (p.hasPermission("pandacraft.grade.staff")) - p.setScoreboard(scoreboardPlayerQueue); - plugin.getServer().getScheduler().runTaskLater(plugin, new Runnable() { - @Override public void run() { updateScoreBoardWaitingList(); } - }, 2L); - - } - - @EventHandler - public void onPlayerQuit(PlayerQuitEvent event) { - plugin.getServer().getScheduler().runTaskLater(plugin, new Runnable() { - @Override public void run() { updateScoreBoardWaitingList(); } - }, 2L); - } - - - - - - - - - - - - - - - - private class WaitingPlayer { - - private String player; - private String message; - private Date creationDate; - private Location location; - - - public WaitingPlayer(String p, String m, Location l) { - - player = p; - message = m; - creationDate = new Date(); - location = l; - } - - - public String getPlayerName() { return player; } - - public String getMessage() { return message; } - - public Date getDate() { return creationDate; } - - public Location getLocation() { return location; } - } + + } diff --git a/src/net/mc_pandacraft/java/plugin/pandacraftutils/system_analyzer/CommandSystem.java b/src/net/mc_pandacraft/java/plugin/pandacraftutils/commands/CommandSystem.java similarity index 91% rename from src/net/mc_pandacraft/java/plugin/pandacraftutils/system_analyzer/CommandSystem.java rename to src/net/mc_pandacraft/java/plugin/pandacraftutils/commands/CommandSystem.java index e293c13..94c4f64 100644 --- a/src/net/mc_pandacraft/java/plugin/pandacraftutils/system_analyzer/CommandSystem.java +++ b/src/net/mc_pandacraft/java/plugin/pandacraftutils/commands/CommandSystem.java @@ -1,4 +1,4 @@ -package net.mc_pandacraft.java.plugin.pandacraftutils.system_analyzer; +package net.mc_pandacraft.java.plugin.pandacraftutils.commands; import java.lang.management.ManagementFactory; import java.lang.management.ThreadInfo; @@ -10,7 +10,6 @@ import java.util.Map.Entry; import java.util.TreeMap; import java.util.concurrent.atomic.AtomicInteger; -import net.mc_pandacraft.java.plugin.pandacraftutils.PandacraftUtils; import net.mc_pandacraft.java.util.MemoryUtil; import net.mc_pandacraft.java.util.TimeUtil; import net.mc_pandacraft.java.util.bukkit.TextProgressBar; @@ -18,25 +17,16 @@ import net.mc_pandacraft.java.util.bukkit.TextProgressBar; import org.bukkit.ChatColor; import org.bukkit.World; import org.bukkit.command.Command; -import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandSender; import org.bukkit.command.ConsoleCommandSender; import org.bukkit.entity.Entity; import org.bukkit.entity.EntityType; import org.bukkit.entity.Player; -public class CommandSystem implements CommandExecutor { - private PandacraftUtils plugin; - private TPSAnalyser tpsAnalyser; - - public CommandSystem(PandacraftUtils pl) +public class CommandSystem extends AbstractCommandExecutor { + public CommandSystem() { - plugin = pl; - - plugin.getCommand("system").setExecutor(this); - - tpsAnalyser = new TPSAnalyser(plugin); - + super("system"); } @@ -150,7 +140,7 @@ public class CommandSystem implements CommandExecutor { ConsoleCommandSender console = plugin.getServer().getConsoleSender(); - console.sendMessage(tpsAnalyser.getStringTPSHistory(20*20)); + console.sendMessage(plugin.tpsAnalysisManager.getStringTPSHistory(20*20)); } else @@ -173,7 +163,7 @@ public class CommandSystem implements CommandExecutor { sender.sendMessage(TextProgressBar.progressBar(values_bar, colors_bar, maxMem, ((sender instanceof Player)?155:43))); // tps - double tps = tpsAnalyser.getTPS(); + double tps = plugin.tpsAnalysisManager.getTPS(); String val_tps; if (Double.isNaN(tps)) { diff --git a/src/net/mc_pandacraft/java/plugin/pandacraftutils/commands/Command_Selection.java b/src/net/mc_pandacraft/java/plugin/pandacraftutils/commands/Command_Selection.java new file mode 100644 index 0000000..9660191 --- /dev/null +++ b/src/net/mc_pandacraft/java/plugin/pandacraftutils/commands/Command_Selection.java @@ -0,0 +1,87 @@ +package net.mc_pandacraft.java.plugin.pandacraftutils.commands; + +import net.mc_pandacraft.java.plugin.pandacraftutils.players.OnlinePlayer; +import net.mc_pandacraft.java.plugin.pandacraftutils.players.OnlinePlayerManager; + +import org.bukkit.ChatColor; +import org.bukkit.command.Command; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +public class Command_Selection extends AbstractCommandExecutor { + + public Command_Selection() { + super("/selection"); + } + + + + + + + // permet d'activer / désactiver l'affichage du cubo + @Override + public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { + + if (! (sender instanceof Player)) + { + sender.sendMessage(ChatColor.RED+"Seul un joueur en ligne peut effectuer cette commande"); + return false; + } + + if (plugin.getServer().getPluginManager().getPlugin("WorldEdit") == null) + { + sender.sendMessage(ChatColor.RED+"Plugin WorldEdit non installé"); + return false; + } + + Player p = (Player) sender; + OnlinePlayer op = OnlinePlayerManager.getInstance().get(p); + + + Player otherP = null; + if (args.length > 0) + { + otherP = plugin.getServer().getPlayer(args[0]); + if (otherP == null) + { + sender.sendMessage(ChatColor.RED+"Le joueur indiqué n'existe pas"); + return true; + } + } + + + if (op.canViewWESelection() && otherP == null) + { // le joueur ne veut plus voir de cubo + op.disableViewingWESelection(); + sender.sendMessage(ChatColor.GREEN+"Affichage de la sélection désactivé."); + } + else if (op.canViewWESelection()) + { + if (op.hasPlayerForWiewingHisWESelection(otherP)) + { + op.removePlayerForWiewingHisWESelection(otherP); + sender.sendMessage(ChatColor.GREEN+"Affichage de la sélection de "+ChatColor.GRAY+otherP.getName()+ChatColor.GREEN+" désactivé."); + } + else + { + op.addPlayerForWiewingHisWESelection(otherP); + sender.sendMessage(ChatColor.GREEN+"Affichage de la sélection de "+ChatColor.GRAY+otherP.getName()+ChatColor.GREEN+" activé."); + } + + } + else + { + op.enableViewingWESelection(); + sender.sendMessage(ChatColor.GREEN+"Affichage de la sélection activé. Si vous ne voyez pas les particules, activez les dans vos options Minecraft."); + if (otherP != null) { + op.addPlayerForWiewingHisWESelection(otherP); + sender.sendMessage(ChatColor.GREEN+"Affichage de la sélection de "+ChatColor.GRAY+otherP.getName()+ChatColor.GREEN+" activé."); + } + } + + return true; + } + + +} diff --git a/src/net/mc_pandacraft/java/plugin/pandacraftutils/commands/CommandsManager.java b/src/net/mc_pandacraft/java/plugin/pandacraftutils/commands/CommandsManager.java new file mode 100644 index 0000000..3364174 --- /dev/null +++ b/src/net/mc_pandacraft/java/plugin/pandacraftutils/commands/CommandsManager.java @@ -0,0 +1,69 @@ +package net.mc_pandacraft.java.plugin.pandacraftutils.commands; + +import java.util.HashMap; + +/** + * Initialise et stoque toutes les instances des classes exécutant les commandes Minecraft, géré par le plugin + */ +public class CommandsManager { + + private static CommandsManager instance; + + /** + * Retourne l'unique instance de la classe. Si elle n'existe pas, on tente de créer + * @return L'unique instance de la classe + */ + public synchronized static CommandsManager getInstance() { + if (instance == null) + loadNewInstance(); + return instance; + } + + public synchronized static void loadNewInstance() { + instance = new CommandsManager(); + } + + + + + + + + + + + + private HashMap commandExecutors = new HashMap(); + + private CommandsManager() { + + /* + * Initialisation des commandes + */ + add(new Command_Selection()); + add(new CommandAfk()); + add(new CommandBroadcast()); + add(new CommandCubo()); + add(new CommandList()); + add(new CommandMe()); + add(new CommandPing()); + add(new CommandSetblock()); + add(new CommandStaff()); + add(new CommandSystem()); + + } + + + + + + + private void add(AbstractCommandExecutor ace) { + commandExecutors.put(ace.getCommandName(), ace); + } + + public AbstractCommandExecutor get(String cmdName) { + return commandExecutors.get(cmdName); + } + +} diff --git a/src/net/mc_pandacraft/java/plugin/pandacraftutils/afk/CommandAfk.java b/src/net/mc_pandacraft/java/plugin/pandacraftutils/modules/AfkManager.java similarity index 73% rename from src/net/mc_pandacraft/java/plugin/pandacraftutils/afk/CommandAfk.java rename to src/net/mc_pandacraft/java/plugin/pandacraftutils/modules/AfkManager.java index 740167d..acfe9f8 100644 --- a/src/net/mc_pandacraft/java/plugin/pandacraftutils/afk/CommandAfk.java +++ b/src/net/mc_pandacraft/java/plugin/pandacraftutils/modules/AfkManager.java @@ -1,4 +1,4 @@ -package net.mc_pandacraft.java.plugin.pandacraftutils.afk; +package net.mc_pandacraft.java.plugin.pandacraftutils.modules; import net.mc_pandacraft.java.plugin.pandacraftutils.ConfigManager; @@ -7,9 +7,6 @@ import net.mc_pandacraft.java.plugin.pandacraftutils.players.OnlinePlayer; import net.mc_pandacraft.java.plugin.pandacraftutils.players.OnlinePlayerManager; import org.bukkit.Location; -import org.bukkit.command.Command; -import org.bukkit.command.CommandExecutor; -import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; @@ -26,18 +23,16 @@ import org.bukkit.event.player.PlayerToggleSneakEvent; import org.bukkit.event.player.PlayerToggleSprintEvent; import org.bukkit.scheduler.BukkitRunnable; -public class CommandAfk extends BukkitRunnable implements CommandExecutor, Listener { +public class AfkManager extends BukkitRunnable implements Listener { private PandacraftUtils plugin = PandacraftUtils.getInstance(); private int timeoutAutoAfkMessage = ConfigManager.getInstance().AFK_timeoutAutoAfkMessage; private int timeoutAutoAfkKick = ConfigManager.getInstance().AFK_timeoutAutoAfkKick; - public CommandAfk() + public AfkManager() { - - plugin.getCommand("afk").setExecutor(this); plugin.getServer().getScheduler().runTaskTimer(plugin, this, 5*20L, 20L); plugin.getServer().getPluginManager().registerEvents(this, plugin); @@ -47,95 +42,6 @@ public class CommandAfk extends BukkitRunnable implements CommandExecutor, Liste - - - - // ---------------------------------------- - // ------------ Commande /AFK ------------- - // ---------------------------------------- - @Override - public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) - { - boolean execute_self = false; - boolean execute_other = false; - Player other_player = null; - - if(sender instanceof Player) - { - if (args.length > 0) - { - if (((Player)sender).hasPermission("pandacraft.afk.other")) - { - if (plugin.getServer().getPlayer(args[0]) != null) - { - other_player = plugin.getServer().getPlayer(args[0]); - execute_other = true; - } - else - sender.sendMessage("§cLe joueur n'existe pas."); - } - else - { - sender.sendMessage("§cVous n'avez pas la permission d'effectuer cette action sur un autre joueur."); - } - } - else - execute_self = true; - } - else - { - if (args.length > 0) - { - if (plugin.getServer().getPlayer(args[0]) != null) - { - other_player = plugin.getServer().getPlayer(args[0]); - execute_other = true; - } - else - sender.sendMessage("§cLe joueur n'existe pas."); - } - else - sender.sendMessage("§cVeuillez indiquer un joueur."); - - } - - - if (execute_self) - { - Player p = (Player)sender; - OnlinePlayer ap = OnlinePlayerManager.getInstance().get(p); - if (ap == null) - plugin.getLogger().severe("Cant find AfkPlayer with name "+p.getName()+" when performing command /afk"); - else - ap.performAfkCommand(); - return true; - } - else if (execute_other && other_player != null) - { - OnlinePlayer ap = OnlinePlayerManager.getInstance().get(other_player); - if (ap == null) - plugin.getLogger().severe("Cant find AfkPlayer with name "+other_player.getName()+" when performing command /afk "); - ap.adminToggleAfk(); - return true; - } - - - - - - return false; - } - - - - - - - - - - - // ---------------------------------------- diff --git a/src/net/mc_pandacraft/java/plugin/pandacraftutils/calculator/CalculatorManager.java b/src/net/mc_pandacraft/java/plugin/pandacraftutils/modules/CalculatorManager.java similarity index 98% rename from src/net/mc_pandacraft/java/plugin/pandacraftutils/calculator/CalculatorManager.java rename to src/net/mc_pandacraft/java/plugin/pandacraftutils/modules/CalculatorManager.java index b39cb26..11162bc 100644 --- a/src/net/mc_pandacraft/java/plugin/pandacraftutils/calculator/CalculatorManager.java +++ b/src/net/mc_pandacraft/java/plugin/pandacraftutils/modules/CalculatorManager.java @@ -1,4 +1,4 @@ -package net.mc_pandacraft.java.plugin.pandacraftutils.calculator; +package net.mc_pandacraft.java.plugin.pandacraftutils.modules; import java.util.ArrayList; import java.util.HashMap; diff --git a/src/net/mc_pandacraft/java/plugin/pandacraftutils/chat_analyzer/ChatAnalysisManager.java b/src/net/mc_pandacraft/java/plugin/pandacraftutils/modules/ChatAnalysisManager.java similarity index 99% rename from src/net/mc_pandacraft/java/plugin/pandacraftutils/chat_analyzer/ChatAnalysisManager.java rename to src/net/mc_pandacraft/java/plugin/pandacraftutils/modules/ChatAnalysisManager.java index 1932bd0..d691c2b 100644 --- a/src/net/mc_pandacraft/java/plugin/pandacraftutils/chat_analyzer/ChatAnalysisManager.java +++ b/src/net/mc_pandacraft/java/plugin/pandacraftutils/modules/ChatAnalysisManager.java @@ -1,4 +1,4 @@ -package net.mc_pandacraft.java.plugin.pandacraftutils.chat_analyzer; +package net.mc_pandacraft.java.plugin.pandacraftutils.modules; import net.mc_pandacraft.java.plugin.pandacraftutils.ConfigManager; import net.mc_pandacraft.java.plugin.pandacraftutils.PandacraftUtils; diff --git a/src/net/mc_pandacraft/java/plugin/pandacraftutils/simple_commands/_command_alias/CommandAliasManager.java b/src/net/mc_pandacraft/java/plugin/pandacraftutils/modules/CommandAliasManager.java similarity index 95% rename from src/net/mc_pandacraft/java/plugin/pandacraftutils/simple_commands/_command_alias/CommandAliasManager.java rename to src/net/mc_pandacraft/java/plugin/pandacraftutils/modules/CommandAliasManager.java index b8322c6..47bff70 100644 --- a/src/net/mc_pandacraft/java/plugin/pandacraftutils/simple_commands/_command_alias/CommandAliasManager.java +++ b/src/net/mc_pandacraft/java/plugin/pandacraftutils/modules/CommandAliasManager.java @@ -1,4 +1,4 @@ -package net.mc_pandacraft.java.plugin.pandacraftutils.simple_commands._command_alias; +package net.mc_pandacraft.java.plugin.pandacraftutils.modules; import java.util.List; import java.util.Map; diff --git a/src/net/mc_pandacraft/java/plugin/pandacraftutils/login_message/LoginLogoutManager.java b/src/net/mc_pandacraft/java/plugin/pandacraftutils/modules/LoginLogoutMessageManager.java similarity index 91% rename from src/net/mc_pandacraft/java/plugin/pandacraftutils/login_message/LoginLogoutManager.java rename to src/net/mc_pandacraft/java/plugin/pandacraftutils/modules/LoginLogoutMessageManager.java index b837dc7..e1c941b 100644 --- a/src/net/mc_pandacraft/java/plugin/pandacraftutils/login_message/LoginLogoutManager.java +++ b/src/net/mc_pandacraft/java/plugin/pandacraftutils/modules/LoginLogoutMessageManager.java @@ -1,4 +1,4 @@ -package net.mc_pandacraft.java.plugin.pandacraftutils.login_message; +package net.mc_pandacraft.java.plugin.pandacraftutils.modules; import java.util.ArrayList; import java.util.Arrays; @@ -16,14 +16,14 @@ import org.bukkit.event.player.PlayerQuitEvent; import de.luricos.bukkit.xAuth.events.xAuthLoginEvent; -public class LoginLogoutManager implements Listener { +public class LoginLogoutMessageManager implements Listener { private PandacraftUtils plugin; private List loggedInPlayer = new ArrayList(); - public LoginLogoutManager(PandacraftUtils pl) { + public LoginLogoutMessageManager(PandacraftUtils pl) { plugin = pl; plugin.getServer().getPluginManager().registerEvents(this, plugin); diff --git a/src/net/mc_pandacraft/java/plugin/pandacraftutils/player_count_list/PacketOutServerInfoListener.java b/src/net/mc_pandacraft/java/plugin/pandacraftutils/modules/PacketOutServerInfoListener.java similarity index 97% rename from src/net/mc_pandacraft/java/plugin/pandacraftutils/player_count_list/PacketOutServerInfoListener.java rename to src/net/mc_pandacraft/java/plugin/pandacraftutils/modules/PacketOutServerInfoListener.java index f772640..ec06bc6 100644 --- a/src/net/mc_pandacraft/java/plugin/pandacraftutils/player_count_list/PacketOutServerInfoListener.java +++ b/src/net/mc_pandacraft/java/plugin/pandacraftutils/modules/PacketOutServerInfoListener.java @@ -1,4 +1,4 @@ -package net.mc_pandacraft.java.plugin.pandacraftutils.player_count_list; +package net.mc_pandacraft.java.plugin.pandacraftutils.modules; import java.util.ArrayList; import java.util.Arrays; diff --git a/src/net/mc_pandacraft/java/plugin/pandacraftutils/spawntime/SpawnTimeManager.java b/src/net/mc_pandacraft/java/plugin/pandacraftutils/modules/SpawnTimeManager.java similarity index 93% rename from src/net/mc_pandacraft/java/plugin/pandacraftutils/spawntime/SpawnTimeManager.java rename to src/net/mc_pandacraft/java/plugin/pandacraftutils/modules/SpawnTimeManager.java index 160b404..64fcc92 100644 --- a/src/net/mc_pandacraft/java/plugin/pandacraftutils/spawntime/SpawnTimeManager.java +++ b/src/net/mc_pandacraft/java/plugin/pandacraftutils/modules/SpawnTimeManager.java @@ -1,4 +1,4 @@ -package net.mc_pandacraft.java.plugin.pandacraftutils.spawntime; +package net.mc_pandacraft.java.plugin.pandacraftutils.modules; import java.util.Calendar; import java.util.Date; diff --git a/src/net/mc_pandacraft/java/plugin/pandacraftutils/modules/StaffQueueManager.java b/src/net/mc_pandacraft/java/plugin/pandacraftutils/modules/StaffQueueManager.java new file mode 100644 index 0000000..5145138 --- /dev/null +++ b/src/net/mc_pandacraft/java/plugin/pandacraftutils/modules/StaffQueueManager.java @@ -0,0 +1,191 @@ +package net.mc_pandacraft.java.plugin.pandacraftutils.modules; + +import java.util.Date; +import java.util.LinkedList; +import java.util.Queue; + +import net.mc_pandacraft.java.plugin.pandacraftutils.PandacraftUtils; + +import org.bukkit.Bukkit; +import org.bukkit.ChatColor; +import org.bukkit.Location; +import org.bukkit.OfflinePlayer; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.player.PlayerJoinEvent; +import org.bukkit.event.player.PlayerQuitEvent; +import org.bukkit.scoreboard.DisplaySlot; +import org.bukkit.scoreboard.Objective; +import org.bukkit.scoreboard.Score; +import org.bukkit.scoreboard.Scoreboard; + +public class StaffQueueManager implements Listener { + + private PandacraftUtils plugin = PandacraftUtils.getInstance(); + + + public Queue playerQueue = new LinkedList(); + + private Scoreboard scoreboardPlayerQueue = Bukkit.getScoreboardManager().getNewScoreboard(); + + + public StaffQueueManager() { + plugin.getServer().getPluginManager().registerEvents(this, plugin); + } + + + public WaitingPlayer getWaitingPlayer(String p) { + for (WaitingPlayer wp : playerQueue) + { + if (wp != null && wp.getPlayerName().equalsIgnoreCase(p)) + return wp; + } + return null; + } + + + public WaitingPlayer getWaitingPlayer(OfflinePlayer p) { + return getWaitingPlayer(p.getName()); + } + + + + + public int getPlayerPosition(OfflinePlayer p) { + int i = 0; + for (WaitingPlayer wp : playerQueue) + { + i++; + if (wp != null && wp.getPlayerName().equalsIgnoreCase(p.getName())) + return i; + } + return -1; + } + + + + public void removePlayer(String p) { + WaitingPlayer wp = getWaitingPlayer(p); + if (wp != null) + { + playerQueue.remove(wp); + updateScoreBoardWaitingList(); + } + } + public void removePlayer(OfflinePlayer p) { + removePlayer(p.getName()); + updateScoreBoardWaitingList(); + } + + + + + + + + + + + + public void updateScoreBoardWaitingList() { + Objective obj = scoreboardPlayerQueue.getObjective("file_attente"); + if (obj != null) + obj.unregister(); + + + obj = scoreboardPlayerQueue.registerNewObjective("file_attente", "dummy"); + obj.setDisplayName(ChatColor.GOLD+"File d'attente staff"); + obj.setDisplaySlot(DisplaySlot.SIDEBAR); + + int i=0; + for (WaitingPlayer wp : playerQueue) { + i++; + + Player p = plugin.getServer().getPlayerExact(wp.getPlayerName()); + String name; + if (p == null || !p.isOnline()) + name = wp.getPlayerName(); + else + name = p.getPlayerListName(); + + String line = i+"."+name; + int boardPos = playerQueue.size()-i+1; + + + Score score = obj.getScore(plugin.getServer().getOfflinePlayer(line.substring(0, (line.length()>16)?16:line.length()))); + + score.setScore(boardPos); + } + } + + + + + + + + + + + + + + @EventHandler + public void onPlayerJoin(PlayerJoinEvent event) { + Player p = event.getPlayer(); + if (p.hasPermission("pandacraft.grade.staff")) + p.setScoreboard(scoreboardPlayerQueue); + plugin.getServer().getScheduler().runTaskLater(plugin, new Runnable() { + @Override public void run() { updateScoreBoardWaitingList(); } + }, 2L); + + } + + @EventHandler + public void onPlayerQuit(PlayerQuitEvent event) { + plugin.getServer().getScheduler().runTaskLater(plugin, new Runnable() { + @Override public void run() { updateScoreBoardWaitingList(); } + }, 2L); + } + + + + + + + + + + + + + + + + public class WaitingPlayer { + + private String player; + private String message; + private Date creationDate; + private Location location; + + + public WaitingPlayer(String p, String m, Location l) { + + player = p; + message = m; + creationDate = new Date(); + location = l; + } + + + public String getPlayerName() { return player; } + + public String getMessage() { return message; } + + public Date getDate() { return creationDate; } + + public Location getLocation() { return location; } + } +} diff --git a/src/net/mc_pandacraft/java/plugin/pandacraftutils/modules/SurvivalCuboManager.java b/src/net/mc_pandacraft/java/plugin/pandacraftutils/modules/SurvivalCuboManager.java new file mode 100644 index 0000000..b7f4d6b --- /dev/null +++ b/src/net/mc_pandacraft/java/plugin/pandacraftutils/modules/SurvivalCuboManager.java @@ -0,0 +1,107 @@ +package net.mc_pandacraft.java.plugin.pandacraftutils.modules; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +import net.mc_pandacraft.java.plugin.pandacraftutils.plugin_interface.WorldGuardInterface; + +import org.bukkit.World; +import org.bukkit.entity.Player; + +import com.sk89q.worldguard.bukkit.WorldGuardPlugin; +import com.sk89q.worldguard.protection.regions.ProtectedCuboidRegion; +import com.sk89q.worldguard.protection.regions.ProtectedRegion; + +public class SurvivalCuboManager { + public WorldGuardPlugin wgPlugin = WorldGuardInterface.getPlugin(); + + public final String regex_cubo_id = "cubo[0-9]+-[0-9A-Za-z_]+-[0-9A-Za-z_]+"; + + + + + + + /** + * @param p le joueur + * @param w le monde + * @return tout les cubos d'un joueur donné sur un monde donné + */ + public List getPlayerCubo(Player p, World w) { + return getPlayerCubo(p.getName(), w); + } + + + /** + * @param p le pseudo du joueur + * @param w le monde + * @return tout les cubos d'un joueur donné sur un monde donné + */ + public List getPlayerCubo(String p, World w) { + + Map regions = wgPlugin.getRegionManager(w).getRegions(); + List playerRegions = new ArrayList(); + + for (Map.Entry region : regions.entrySet()) { + // on ne prend en charge que les cuboides + if (!(region.getValue() instanceof ProtectedCuboidRegion)) + continue; + // on garde les régions gérés par la commande + if (!region.getValue().getId().matches(regex_cubo_id)) + continue; + if (!region.getValue().isOwner(p)) + continue; + playerRegions.add((ProtectedCuboidRegion)region.getValue()); + } + return playerRegions; + } + + /** + * + * @param p le joueur + * @param w le monde + * @return le volume total des cubos d'un joueur donné sur un monde donné + */ + public int getPlayerActualBlockCount(Player p, World w) { + return getPlayerActualBlockCount(p.getName(), w); + } + + /** + * + * @param p le joueur + * @param w le monde + * @return le volume total des cubos d'un joueur donné sur un monde donné + */ + public int getPlayerActualBlockCount(String p, World w) { + List regions = getPlayerCubo(p, w); + int nb = 0; + for (ProtectedCuboidRegion region : regions){ + nb += region.volume(); + } + return nb; + } + + /** + * + * @param nb le volume + * @return le prix pour le volume donné + */ + public double getVolumePrice(int nb) { + if (nb <= 2000) + return 0; + + if (nb<= 100000) + return nb-2000D; + + return Math.pow(((nb-2000D)/98000D),1.5)*98000; + } + + + + public boolean hasStaffPermission(Player p) { + return p.hasPermission("pandacraft.cubo.staff"); + } + + +} diff --git a/src/net/mc_pandacraft/java/plugin/pandacraftutils/system_analyzer/TPSAnalyser.java b/src/net/mc_pandacraft/java/plugin/pandacraftutils/modules/TPSAnalysisManager.java similarity index 88% rename from src/net/mc_pandacraft/java/plugin/pandacraftutils/system_analyzer/TPSAnalyser.java rename to src/net/mc_pandacraft/java/plugin/pandacraftutils/modules/TPSAnalysisManager.java index d5810ef..c31633d 100644 --- a/src/net/mc_pandacraft/java/plugin/pandacraftutils/system_analyzer/TPSAnalyser.java +++ b/src/net/mc_pandacraft/java/plugin/pandacraftutils/modules/TPSAnalysisManager.java @@ -1,20 +1,19 @@ -package net.mc_pandacraft.java.plugin.pandacraftutils.system_analyzer; +package net.mc_pandacraft.java.plugin.pandacraftutils.modules; import java.util.LinkedList; import net.mc_pandacraft.java.plugin.pandacraftutils.PandacraftUtils; -public class TPSAnalyser implements Runnable { +public class TPSAnalysisManager implements Runnable { private static int nb_tick_history = 20 * 20; // 20 secondes; - private PandacraftUtils plugin; + private PandacraftUtils plugin = PandacraftUtils.getInstance(); private LinkedList tps_times = new LinkedList(); - public TPSAnalyser(PandacraftUtils pl) + public TPSAnalysisManager() { - plugin = pl; plugin.getServer().getScheduler().runTaskTimer(plugin, this, 1L, 1L); } diff --git a/src/net/mc_pandacraft/java/plugin/pandacraftutils/survival_cuboid/CommandWandSelection.java b/src/net/mc_pandacraft/java/plugin/pandacraftutils/modules/WESelectionDisplayManager.java similarity index 52% rename from src/net/mc_pandacraft/java/plugin/pandacraftutils/survival_cuboid/CommandWandSelection.java rename to src/net/mc_pandacraft/java/plugin/pandacraftutils/modules/WESelectionDisplayManager.java index d638de6..254f3db 100644 --- a/src/net/mc_pandacraft/java/plugin/pandacraftutils/survival_cuboid/CommandWandSelection.java +++ b/src/net/mc_pandacraft/java/plugin/pandacraftutils/modules/WESelectionDisplayManager.java @@ -1,4 +1,4 @@ -package net.mc_pandacraft.java.plugin.pandacraftutils.survival_cuboid; +package net.mc_pandacraft.java.plugin.pandacraftutils.modules; import java.util.ArrayList; import java.util.List; @@ -9,101 +9,23 @@ import net.mc_pandacraft.java.plugin.pandacraftutils.players.OnlinePlayerManager import net.mc_pandacraft.java.plugin.pandacraftutils.plugin_interface.WorldEditInterface; import net.mc_pandacraft.java.util.bukkit.protocol.ParticleEffect; -import org.bukkit.ChatColor; import org.bukkit.Location; -import org.bukkit.command.Command; -import org.bukkit.command.CommandExecutor; -import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; import org.bukkit.scheduler.BukkitRunnable; import com.sk89q.worldedit.bukkit.selections.CuboidSelection; -public class CommandWandSelection extends BukkitRunnable implements CommandExecutor { +public class WESelectionDisplayManager extends BukkitRunnable { - private PandacraftUtils plugin; + private PandacraftUtils plugin = PandacraftUtils.getInstance(); - public CommandWandSelection(PandacraftUtils pl) + public WESelectionDisplayManager() { - plugin = pl; - - plugin.getCommand("/selection").setExecutor(this); plugin.getServer().getScheduler().runTaskTimer(plugin, this, 20L, 20L); } - /* - * Commande //selection - */ - - - - - - // permet d'activer / désactiver l'affichage du cubo - @Override - public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { - - if (! (sender instanceof Player)) - { - sender.sendMessage(ChatColor.RED+"Seul un joueur en ligne peut effectuer cette commande"); - return false; - } - - if (plugin.getServer().getPluginManager().getPlugin("WorldEdit") == null) - { - sender.sendMessage(ChatColor.RED+"Plugin WorldEdit non installé"); - return false; - } - - Player p = (Player) sender; - OnlinePlayer op = OnlinePlayerManager.getInstance().get(p); - - - Player otherP = null; - if (args.length > 0) - { - otherP = plugin.getServer().getPlayer(args[0]); - if (otherP == null) - { - sender.sendMessage(ChatColor.RED+"Le joueur indiqué n'existe pas"); - return true; - } - } - - - if (op.canViewWESelection() && otherP == null) - { // le joueur ne veut plus voir de cubo - op.disableViewingWESelection(); - sender.sendMessage(ChatColor.GREEN+"Affichage de la sélection désactivé."); - } - else if (op.canViewWESelection()) - { - if (op.hasPlayerForWiewingHisWESelection(otherP)) - { - op.removePlayerForWiewingHisWESelection(otherP); - sender.sendMessage(ChatColor.GREEN+"Affichage de la sélection de "+ChatColor.GRAY+otherP.getName()+ChatColor.GREEN+" désactivé."); - } - else - { - op.addPlayerForWiewingHisWESelection(otherP); - sender.sendMessage(ChatColor.GREEN+"Affichage de la sélection de "+ChatColor.GRAY+otherP.getName()+ChatColor.GREEN+" activé."); - } - - } - else - { - op.enableViewingWESelection(); - sender.sendMessage(ChatColor.GREEN+"Affichage de la sélection activé. Si vous ne voyez pas les particules, activez les dans vos options Minecraft."); - if (otherP != null) { - op.addPlayerForWiewingHisWESelection(otherP); - sender.sendMessage(ChatColor.GREEN+"Affichage de la sélection de "+ChatColor.GRAY+otherP.getName()+ChatColor.GREEN+" activé."); - } - } - - return true; - } // pour mettre à jour l'affichage du cubo diff --git a/src/net/mc_pandacraft/java/plugin/pandacraftutils/cheat_protect/creative/CreativCheatManager.java b/src/net/mc_pandacraft/java/plugin/pandacraftutils/modules/cheat_protect/CreativCheatManager.java similarity index 92% rename from src/net/mc_pandacraft/java/plugin/pandacraftutils/cheat_protect/creative/CreativCheatManager.java rename to src/net/mc_pandacraft/java/plugin/pandacraftutils/modules/cheat_protect/CreativCheatManager.java index 7bc2cb3..141388a 100644 --- a/src/net/mc_pandacraft/java/plugin/pandacraftutils/cheat_protect/creative/CreativCheatManager.java +++ b/src/net/mc_pandacraft/java/plugin/pandacraftutils/modules/cheat_protect/CreativCheatManager.java @@ -1,4 +1,4 @@ -package net.mc_pandacraft.java.plugin.pandacraftutils.cheat_protect.creative; +package net.mc_pandacraft.java.plugin.pandacraftutils.modules.cheat_protect; import net.mc_pandacraft.java.plugin.pandacraftutils.PandacraftUtils; diff --git a/src/net/mc_pandacraft/java/plugin/pandacraftutils/cheat_protect/no_pvp/NoPvpProtectManager.java b/src/net/mc_pandacraft/java/plugin/pandacraftutils/modules/cheat_protect/NoPvpProtectManager.java similarity index 99% rename from src/net/mc_pandacraft/java/plugin/pandacraftutils/cheat_protect/no_pvp/NoPvpProtectManager.java rename to src/net/mc_pandacraft/java/plugin/pandacraftutils/modules/cheat_protect/NoPvpProtectManager.java index ef8eb89..aeeb1df 100644 --- a/src/net/mc_pandacraft/java/plugin/pandacraftutils/cheat_protect/no_pvp/NoPvpProtectManager.java +++ b/src/net/mc_pandacraft/java/plugin/pandacraftutils/modules/cheat_protect/NoPvpProtectManager.java @@ -1,4 +1,4 @@ -package net.mc_pandacraft.java.plugin.pandacraftutils.cheat_protect.no_pvp; +package net.mc_pandacraft.java.plugin.pandacraftutils.modules.cheat_protect; import java.util.List; diff --git a/src/net/mc_pandacraft/java/plugin/pandacraftutils/players/OnlinePlayerManager.java b/src/net/mc_pandacraft/java/plugin/pandacraftutils/players/OnlinePlayerManager.java index 42b6659..d01706c 100644 --- a/src/net/mc_pandacraft/java/plugin/pandacraftutils/players/OnlinePlayerManager.java +++ b/src/net/mc_pandacraft/java/plugin/pandacraftutils/players/OnlinePlayerManager.java @@ -26,7 +26,7 @@ public final class OnlinePlayerManager implements Listener { return instance; } - public static void loadNewInstance() { + public synchronized static void loadNewInstance() { instance = new OnlinePlayerManager(); } diff --git a/src/net/mc_pandacraft/java/plugin/pandacraftutils/plugin_interface/WorldGuardInterface.java b/src/net/mc_pandacraft/java/plugin/pandacraftutils/plugin_interface/WorldGuardInterface.java new file mode 100644 index 0000000..f07105a --- /dev/null +++ b/src/net/mc_pandacraft/java/plugin/pandacraftutils/plugin_interface/WorldGuardInterface.java @@ -0,0 +1,14 @@ +package net.mc_pandacraft.java.plugin.pandacraftutils.plugin_interface; + +import net.mc_pandacraft.java.plugin.pandacraftutils.PandacraftUtils; + +import com.sk89q.worldguard.bukkit.WorldGuardPlugin; + +public class WorldGuardInterface { + + public static WorldGuardPlugin getPlugin() { + try { + return (WorldGuardPlugin) PandacraftUtils.getInstance().getServer().getPluginManager().getPlugin("WorldGuard"); + } catch (Exception e) { return null; } + } +} diff --git a/src/net/mc_pandacraft/java/util/StringUtil.java b/src/net/mc_pandacraft/java/util/StringUtil.java index 515b635..2411fc4 100644 --- a/src/net/mc_pandacraft/java/util/StringUtil.java +++ b/src/net/mc_pandacraft/java/util/StringUtil.java @@ -8,4 +8,19 @@ public class StringUtil { else return String.valueOf((float)d); } + + /** + * @param s Chaine de caractère à parcourir + * @param c_match le caractère dont on doit retourner le nombre d'occurence + * @return nombre d'occurence de c_match dans s + */ + public static int char_count(CharSequence s, char c_match) + { + char[] chars = s.toString().toCharArray(); + int count = 0; + for (char c : chars) + if (c == c_match) + count++; + return count; + } }