Unification des classes gérant l'exécution des commandes + retructuration complètes des packages et des classes

This commit is contained in:
Marc Baloup 2015-01-22 03:32:47 -05:00
parent 5e7b129c2e
commit 2f2ad0974b
31 changed files with 782 additions and 702 deletions

View File

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<jardesc>
<jar path="PandacraftUtils/jar_export/PandacraftUtils-2.11.jar"/>
<jar path="PandacraftUtils/jar_export/PandacraftUtils-3.0.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/>

View File

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

View File

@ -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

View File

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

View File

@ -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 <player>");
ap.adminToggleAfk();
return true;
}
return false;
}
}

View File

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

View File

@ -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<ProtectedCuboidRegion> cubos = getPlayerCubo(player_cubo, player.getWorld());
List<ProtectedCuboidRegion> 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<ProtectedCuboidRegion> 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<ProtectedCuboidRegion> getPlayerCubo(String p, World w) {
Map<String, ProtectedRegion> regions = wgPlugin.getRegionManager(w).getRegions();
List<ProtectedCuboidRegion> playerRegions = new ArrayList<ProtectedCuboidRegion>();
for (Map.Entry<String, ProtectedRegion> 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<ProtectedCuboidRegion> 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");
}
}

View File

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

View File

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

View File

@ -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

View File

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

View File

@ -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<WaitingPlayer> playerQueue = new LinkedList<WaitingPlayer>();
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; }
}
}

View File

@ -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))
{

View File

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

View File

@ -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<String, AbstractCommandExecutor> commandExecutors = new HashMap<String, AbstractCommandExecutor>();
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);
}
}

View File

@ -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 <player>");
ap.adminToggleAfk();
return true;
}
return false;
}
// ----------------------------------------

View File

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

View File

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

View File

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

View File

@ -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<Player> loggedInPlayer = new ArrayList<Player>();
public LoginLogoutManager(PandacraftUtils pl) {
public LoginLogoutMessageManager(PandacraftUtils pl) {
plugin = pl;
plugin.getServer().getPluginManager().registerEvents(this, plugin);

View File

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

View File

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

View File

@ -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<WaitingPlayer> playerQueue = new LinkedList<WaitingPlayer>();
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; }
}
}

View File

@ -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<ProtectedCuboidRegion> 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<ProtectedCuboidRegion> getPlayerCubo(String p, World w) {
Map<String, ProtectedRegion> regions = wgPlugin.getRegionManager(w).getRegions();
List<ProtectedCuboidRegion> playerRegions = new ArrayList<ProtectedCuboidRegion>();
for (Map.Entry<String, ProtectedRegion> 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<ProtectedCuboidRegion> 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");
}
}

View File

@ -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<Long> tps_times = new LinkedList<Long>();
public TPSAnalyser(PandacraftUtils pl)
public TPSAnalysisManager()
{
plugin = pl;
plugin.getServer().getScheduler().runTaskTimer(plugin, this, 1L, 1L);
}

View File

@ -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

View File

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

View File

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

View File

@ -26,7 +26,7 @@ public final class OnlinePlayerManager implements Listener {
return instance;
}
public static void loadNewInstance() {
public synchronized static void loadNewInstance() {
instance = new OnlinePlayerManager();
}

View File

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

View File

@ -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 <b>c_match</b> dans <b>s</b>
*/
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;
}
}