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

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

View File

@@ -0,0 +1,224 @@
package net.mc_pandacraft.java.plugin.pandacraftutils.modules;
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 org.bukkit.Location;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.AsyncPlayerChatEvent;
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
import org.bukkit.event.player.PlayerDropItemEvent;
import org.bukkit.event.player.PlayerEggThrowEvent;
import org.bukkit.event.player.PlayerInteractEntityEvent;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.event.player.PlayerMoveEvent;
import org.bukkit.event.player.PlayerTeleportEvent;
import org.bukkit.event.player.PlayerToggleFlightEvent;
import org.bukkit.event.player.PlayerToggleSneakEvent;
import org.bukkit.event.player.PlayerToggleSprintEvent;
import org.bukkit.scheduler.BukkitRunnable;
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 AfkManager()
{
plugin.getServer().getScheduler().runTaskTimer(plugin, this, 5*20L, 20L);
plugin.getServer().getPluginManager().registerEvents(this, plugin);
}
// ----------------------------------------
// ----------- Analyse Auto-AFK -----------
// ----------------------------------------
@Override
public void run() {
// methode exécutée toute les secondes
for (OnlinePlayer ap : OnlinePlayerManager.getInstance().getAll())
{ // parcours de tout les joueurs
if (ap == null)
continue;
if (ap.getPlayer().hasPermission("pandacraft.afk.exempt.autoafk"))
continue; // les joueurs exemptés de l'auto-afk sont ignorés
Player p = ap.getPlayer();
double timeElapsed = ap.getDurationSinceLastAction();
if (!ap.isAfk() && timeElapsed > timeoutAutoAfkMessage)
ap.setAfk(true); // on indique le changement d'état AFK de la personne
else if (ap.isAfk() && timeElapsed > timeoutAutoAfkKick && !p.hasPermission("pandacraft.afk.exempt.kick"))
p.kickPlayer("Vous avez été inactif pendant plus de "+Math.floor(timeoutAutoAfkKick/60)+" minutes");
// on kick le joueur restant trop longtemps, si il n'est pas exempt<70> du kick
}
}
// ----------------------------------------
// -------------- Evènements --------------
// ----------------------------------------
@EventHandler
public void onPlayerMove (PlayerMoveEvent event)
{
Location from = event.getFrom();
Location to = event.getTo();
if ( (from.getPitch() == to.getPitch() && from.getYaw() == to.getYaw())
|| (from.getX() == to.getX() && from.getY() == to.getY() && from.getZ() == to.getZ()))
return;
OnlinePlayerManager.getInstance().get(event.getPlayer()).isDoingAction();
}
@EventHandler
public void onPlayerCommandPreprocess (PlayerCommandPreprocessEvent event)
{
if (event.getPlayer().hasPermission("pandacraft.afk.exempt.commandcheck"))
return;
String[] split = event.getMessage().split(" ");
if (split.length > 0 &&
(
split[0].equalsIgnoreCase("/afk")
|| split[0].equalsIgnoreCase("/away")
|| split[0].equalsIgnoreCase("/mail")
|| split[0].equalsIgnoreCase("/email")
|| split[0].equalsIgnoreCase("/m")
|| split[0].equalsIgnoreCase("/msg")
|| split[0].equalsIgnoreCase("/t")
|| split[0].equalsIgnoreCase("/tell")
|| split[0].equalsIgnoreCase("/w")
|| split[0].equalsIgnoreCase("/whisper")
|| split[0].equalsIgnoreCase("/r")
|| split[0].equalsIgnoreCase("/reply")
)
)
return;
OnlinePlayerManager.getInstance().get(event.getPlayer()).isDoingAction();
}
@EventHandler
public void onPlayerInteract (PlayerInteractEvent event)
{
try
{
OnlinePlayerManager.getInstance().get(event.getPlayer()).isDoingAction();
}
catch (NullPointerException e) { }
}
@EventHandler
public void onPlayerInteractEntity (PlayerInteractEntityEvent event)
{
try
{
OnlinePlayerManager.getInstance().get(event.getPlayer()).isDoingAction();
}
catch (NullPointerException e) { }
}
@EventHandler
public void onPlayerTeleport (PlayerTeleportEvent event)
{
try
{
// on sors de l'AFK que si la téléportation ne se fait qu'à partir de 2 blocs d'espace
// pour éviter qu'on sorte de l'AFK en se faisait pousser par des pistons
// car un piston "téléporte" le joueur (techniquement parlant, dans le jeu) à 1 bloc de distance
if (event.getFrom().getWorld() != event.getTo().getWorld()
|| event.getFrom().distanceSquared(event.getTo()) > 2*2)
OnlinePlayerManager.getInstance().get(event.getPlayer()).isDoingAction();
}
catch (NullPointerException e) { }
}
@EventHandler
public void onPlayerToggleSprint (PlayerToggleSprintEvent event)
{
try
{
OnlinePlayerManager.getInstance().get(event.getPlayer()).isDoingAction();
}
catch (NullPointerException e) { }
}
@EventHandler
public void onPlayerToggleFlight (PlayerToggleFlightEvent event)
{
try
{
OnlinePlayerManager.getInstance().get(event.getPlayer()).isDoingAction();
}
catch (NullPointerException e) { }
}
@EventHandler
public void onPlayerToggleSneak (PlayerToggleSneakEvent event)
{
try
{
OnlinePlayerManager.getInstance().get(event.getPlayer()).isDoingAction();
}
catch (NullPointerException e) { }
}
@EventHandler
public void onAsyncPlayerChat (AsyncPlayerChatEvent event)
{
try
{
OnlinePlayerManager.getInstance().get(event.getPlayer()).isDoingAction();
}
catch (NullPointerException e) { }
}
@EventHandler
public void onPlayerDropItem (PlayerDropItemEvent event)
{
try
{
OnlinePlayerManager.getInstance().get(event.getPlayer()).isDoingAction();
}
catch (NullPointerException e) { }
}
@EventHandler
public void onPlayerEggThrow (PlayerEggThrowEvent event)
{
try
{
OnlinePlayerManager.getInstance().get(event.getPlayer()).isDoingAction();
}
catch (NullPointerException e) { }
}
}

View File

@@ -0,0 +1,125 @@
package net.mc_pandacraft.java.plugin.pandacraftutils.modules;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import net.mc_pandacraft.java.plugin.pandacraftutils.PandacraftUtils;
import net.mc_pandacraft.java.util.JArithmeticInterpreter;
import net.mc_pandacraft.java.util.StringUtil;
import org.bukkit.ChatColor;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.player.AsyncPlayerChatEvent;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerQuitEvent;
public class CalculatorManager implements Listener {
private PandacraftUtils plugin;
private Map<Player, List<HistoryElement>> history = new HashMap<Player, List<HistoryElement>>();
public CalculatorManager(PandacraftUtils pl) {
plugin = pl;
plugin.getServer().getPluginManager().registerEvents(this, plugin);
// analyse des joueurs déjà en ligne (/reload)
for (Player p : plugin.getServer().getOnlinePlayers())
onPlayerJoin(new PlayerJoinEvent(p, "")); // simule l'évènement d'arrivé d'un joueur, pour le rajouter
}
@EventHandler(priority=EventPriority.LOWEST)
public void onAsyncPlayerChat(AsyncPlayerChatEvent event)
{
String message = event.getMessage();
if (!message.startsWith("="))
return;
if (message.length() == 1)
{ // affichage de l'historique
event.getPlayer().sendMessage(ChatColor.GRAY+"Historique d'utilisation de la calculatrice");
int i = history.get(event.getPlayer()).size();
for(HistoryElement el : history.get(event.getPlayer()))
{
event.getPlayer().sendMessage(ChatColor.GRAY+"res"+i+ChatColor.RESET+" : "+ChatColor.GRAY+el.expression+ChatColor.RESET+"="+ChatColor.GRAY+el.value);
i--;
}
if (history.get(event.getPlayer()).size() == 0)
{
event.getPlayer().sendMessage(ChatColor.RED+"Utilisez le symbole "+ChatColor.GRAY+"="+ChatColor.RED+" dans le chat pour faire un calcul mathématique");
}
}
else
{
try {
message = message.substring(1);
// TODO prendre en compte les variables "resX"
StringBuffer expression = new StringBuffer();
HistoryElement calcul = new HistoryElement();
calcul.value = StringUtil.formatDouble(JArithmeticInterpreter.getResultFromExpression(message, expression));
calcul.expression = expression.toString();
history.get(event.getPlayer()).add(calcul);
if (history.get(event.getPlayer()).size() > 5)
history.get(event.getPlayer()).remove(0);
event.getPlayer().sendMessage(ChatColor.GRAY+calcul.expression+ChatColor.RESET+"="+ChatColor.GRAY+calcul.value);
}
catch (IllegalArgumentException e) {
event.getPlayer().sendMessage(ChatColor.RED+e.getMessage());
event.getPlayer().sendMessage(ChatColor.RED+"Utilisez le symbole "+ChatColor.GRAY+"="+ChatColor.RED+" dans le chat pour faire un calcul mathématique");
}
}
event.setCancelled(true);
}
@EventHandler
public void onPlayerJoin(PlayerJoinEvent event)
{
history.put(event.getPlayer(), new ArrayList<HistoryElement>());
}
@EventHandler
public void onPlayerQuit(PlayerQuitEvent event)
{
history.remove(event.getPlayer());
}
private class HistoryElement
{
public String expression;
public String value;
}
}

View File

@@ -0,0 +1,277 @@
package net.mc_pandacraft.java.plugin.pandacraftutils.modules;
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 org.bukkit.ChatColor;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.player.AsyncPlayerChatEvent;
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
import org.bukkit.util.NumberConversions;
public class ChatAnalysisManager implements Listener {
private PandacraftUtils plugin = PandacraftUtils.getInstance();
public ChatAnalysisManager()
{
plugin.getServer().getPluginManager().registerEvents(this, plugin);
}
@EventHandler(priority=EventPriority.HIGHEST,ignoreCancelled=true)
public void onAsyncPlayerChat(AsyncPlayerChatEvent event)
{
try {
OnlinePlayer op = OnlinePlayerManager.getInstance().get(event.getPlayer());
if (event.getPlayer().hasPermission("pandacraft.antispam.exempt"))
return;
String message = event.getMessage();
long time = System.currentTimeMillis();
if (op.getLast_message() != null)
{
if (op.getLast_message().equals(message) && time - op.getLast_message_time() < ConfigManager.getInstance().ChatAnalysis_timeBeforeResendSameMessage)
{
event.getPlayer().sendMessage(ChatColor.RED+"Evitez de renvoyer le même message !");
if (op.getVL() >= ConfigManager.getInstance().ChatAnalysis_maxViolationLevel/2)
event.setCancelled(true);
else
event.setMessage(analyseString(message, op));
op.addVL(5);
return;
}
else
{
long time_since_last_message = time - op.getLast_message_time();
long timeout_needed = message.length() * ConfigManager.getInstance().ChatAnalysis_timePerCaracterForNewMessage;
if (time_since_last_message < timeout_needed)
{
event.getPlayer().sendMessage(ChatColor.RED+"Vous parlez un peu trop vite, ralentissez x)");
op.addVL(4);
event.setMessage(analyseString(message, op));
return;
}
}
}
message = analyseString(message, op);
event.setMessage(message);
op.removeVL(NumberConversions.floor(((time - op.getLast_message_time())/1000)/ConfigManager.getInstance().ChatAnalysis_nbSecondForOneVLDown));
op.setLast_message(message);
op.setLast_message_time(time);
} catch (NullPointerException e) { }
}
@EventHandler(priority=EventPriority.HIGHEST)
public void onPlayerCommandPreprocess (PlayerCommandPreprocessEvent event)
{
try {
OnlinePlayer op = OnlinePlayerManager.getInstance().get(event.getPlayer());
if (event.getPlayer().hasPermission("pandacraft.antispam.exempt"))
return;
String command_line = event.getMessage();
String[] command_line_split = event.getMessage().split(" ");
long time = System.currentTimeMillis();
String commande = command_line_split[0].substring(1).toLowerCase();
if (commande.equals("")) return;
// traitement du contenu des messages (si elle existe, comme MP ou /me)
// ici, le message, c'est dès le permier paramètre
if ((commande.equals("me")
|| commande.equals("action")
|| commande.equals("describe")
|| commande.equals("r")
|| commande.equals("reply"))
&& command_line_split.length > 1) {
try {
String message = command_line.substring(1+commande.length()+1); // "/"+commande+" "
message = analyseString(message, op);
command_line = "/"+commande+" "+message;
} catch (IndexOutOfBoundsException e) { }
}
// ici, le message, c'est dès le deuxième paramètre
else if((commande.equals("msg")
|| commande.equals("m")
|| commande.equals("tell")
|| commande.equals("t")
|| commande.equals("whisper")
|| commande.equals("w"))
&& command_line_split.length > 2) {
try {
String message = command_line.substring(1+commande.length()
+1+command_line_split[1].length()
+1); // "/"+commande+" "+pseudo+" "
message = analyseString(message, op);
command_line = "/"+commande+" "+command_line_split[1]+" "+message;
} catch (IndexOutOfBoundsException e) { }
}
// ici, le message, c'est dès le troisième paramètre
else if((commande.equals("mail")
|| commande.equals("email"))
&& command_line_split.length > 3) {
try {
String message = command_line.substring(1+commande.length()
+1+command_line_split[1].length()
+1+command_line_split[2].length()
+1); // "/"+commande+" "+sub_command+" "+pseudo+" "
message = analyseString(message, op);
command_line = "/"+commande+" "+command_line_split[1]+" "+command_line_split[2]+" "+message;
} catch (IndexOutOfBoundsException e) { }
}
if (commande.equals("afk")
|| commande.equals("away")
|| commande.equals("time")
|| commande.equals("day")
|| commande.equals("night")
|| commande.equals("me")
|| commande.equals("action")
|| commande.equals("describe")
|| commande.equals("tpa")
|| commande.equals("call")
|| commande.equals("tpask")
|| commande.equals("r")
|| commande.equals("reply")
|| commande.equals("msg")
|| commande.equals("m")
|| commande.equals("tell")
|| commande.equals("t")
|| commande.equals("whisper")
|| commande.equals("w")
|| commande.equals("mail")
|| commande.equals("email"))
{
if (op.getLast_command() != null)
{
if (op.getLast_command().equals(command_line) && time - op.getLast_command_time() < ConfigManager.getInstance().ChatAnalysis_timeBeforeResendSameCommand)
{
event.getPlayer().sendMessage(ChatColor.RED+"Patientez avant de renvoyer cette commande !");
if (op.getVL() >= ConfigManager.getInstance().ChatAnalysis_maxViolationLevel/2)
event.setCancelled(true);
op.addVL(5);
event.setMessage(command_line);
return;
}
}
op.removeVL(NumberConversions.floor(((time - op.getLast_command_time())/1000)/ConfigManager.getInstance().ChatAnalysis_nbSecondForOneVLDown));
op.setLast_command(command_line);
op.setLast_command_time(time);
event.setMessage(command_line);
}
} catch (NullPointerException e) { }
}
private String analyseString(String s, OnlinePlayer op)
{
// évite les suites d'au moins 4 caractàres à la suite
char[] cs = s.toCharArray();
String r = s.substring(0, (s.length()>=3)?3:s.length());
int nb_duplicated_char = 0;
for (int i=3; i<cs.length; i++)
{
if (cs[i] == cs[i-1] && cs[i-1] == cs[i-2] && cs[i-2] == cs[i-3])
{
nb_duplicated_char++;
continue;
}
r = r.concat(String.valueOf(cs[i]));
}
if (nb_duplicated_char > 0)
{
op.addVL(nb_duplicated_char/4+1);
op.getPlayer().sendMessage(ChatColor.RED+"Evitez les répétitions de caractères !");
}
s = r;
char[] sChar = s.toCharArray();
char[] minChar = s.toLowerCase().toCharArray();
// vérification des majuscules
if (sChar.length > 5)
{
int nb_caps = 0;
for (int i=0; i<sChar.length; i++)
if (sChar[i] != minChar[i])
nb_caps++;
if (nb_caps * 100 / sChar.length > 70 || nb_caps > 20)
{
// si plus de 70% des caractères sont majuscules
// ou plus de 20 majuscules
op.addVL(4);
s = s.toLowerCase();
op.getPlayer().sendMessage(ChatColor.RED+"Il y a trop de majuscules dans votre message, faites attention avant d'envoyer votre message ;)");
}
}
// traiter les insultes et masquage Pub ici
// adresse IPv4 basique
if (s.matches("(.*)([0-9]{1,3}\\.){3}[0-9]{1,3}(:[0-9]{1,5})?(.*)"))
{
s = s.replaceAll("[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}", "**.**.**.**");
op.addVL(3);
}
// pour chaque insultes présentes dans la configuration du plugin
for (String regex : ConfigManager.getInstance().ChatAnalysis_badWords)
{
if (s.matches("(?i:(.+[^a-zA-Z]|)"+regex+"(|[^a-zA-Z].+))"))
{
s = s.replaceAll("(?i:"+regex+")", "*****");
op.addVL(5);
}
}
return s;
}
}

View File

@@ -0,0 +1,67 @@
package net.mc_pandacraft.java.plugin.pandacraftutils.modules;
import java.util.List;
import java.util.Map;
import net.mc_pandacraft.java.plugin.pandacraftutils.ConfigManager;
import net.mc_pandacraft.java.plugin.pandacraftutils.PandacraftUtils;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
public class CommandAliasManager implements Listener {
private PandacraftUtils plugin;
public CommandAliasManager(PandacraftUtils pl) {
plugin = pl;
plugin.getServer().getPluginManager().registerEvents(this, plugin);
}
@EventHandler(priority=EventPriority.HIGHEST)
public void onPlayerCommandPreprocess (PlayerCommandPreprocessEvent event)
{
Player p = event.getPlayer();
List<Map<String, String>> aliases = ConfigManager.getInstance().CommandAlias_alias;
for (Map<String, String> alias : aliases) {
if (alias == null)
continue;
String perms = alias.get("permissions");
String initialCmd = alias.get("initialCommand");
String aliasCmd = alias.get("replaceWith");
if (perms == null || initialCmd == null || aliasCmd == null)
continue;
if (!perms.equals("*")) {
String[] aPerms = perms.split(";");
boolean found = false;
for (String perm : aPerms) {
if (perm == null || perm.equals("")) continue; // boucle qui parcours les permissions de l'alias
if (p.hasPermission(perm)) found = true;
}
if (!found) continue; // boucle qui parcours les alias de commandes
}
String mess = event.getMessage();
if(mess.toLowerCase().startsWith(initialCmd))
mess = mess.replaceFirst("(?i)"+initialCmd, aliasCmd);
else
continue;
event.setMessage(mess);
return;
}
}
}

View File

@@ -0,0 +1,78 @@
package net.mc_pandacraft.java.plugin.pandacraftutils.modules;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import net.mc_pandacraft.java.plugin.pandacraftutils.PandacraftUtils;
import net.mc_pandacraft.java.plugin.pandacraftutils.plugin_interface.EssentialsInterface;
import org.bukkit.ChatColor;
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 de.luricos.bukkit.xAuth.events.xAuthLoginEvent;
public class LoginLogoutMessageManager implements Listener {
private PandacraftUtils plugin;
private List<Player> loggedInPlayer = new ArrayList<Player>();
public LoginLogoutMessageManager(PandacraftUtils pl) {
plugin = pl;
plugin.getServer().getPluginManager().registerEvents(this, plugin);
}
@EventHandler
public void onPlayerJoin(PlayerJoinEvent event) {
event.setJoinMessage(null);
}
@EventHandler
public void onxAuthLogin(xAuthLoginEvent event) {
loggedInPlayer.add(event.getPlayer());
if (EssentialsInterface.isPlayerVanished(event.getPlayer())) return;
plugin.getServer().broadcastMessage(ChatColor.YELLOW+event.getPlayer().getDisplayName()+ChatColor.YELLOW+" vient de se connecter");
}
@EventHandler
public void onPlayerQuit(PlayerQuitEvent event) {
event.setQuitMessage(null);
if (!isPlayerLoggedIn(event.getPlayer()))
return;
loggedInPlayer.remove(event.getPlayer());
// on affiche le message que si le joueur n'est pas vanish
if (EssentialsInterface.isPlayerVanished(event.getPlayer())) return;
plugin.getServer().broadcastMessage(ChatColor.YELLOW+event.getPlayer().getDisplayName()+ChatColor.YELLOW+" a quitté le jeu");
}
public List<Player> getLoggedInPlayers() { return loggedInPlayer; }
public List<Player> getLoggedOutPlayers() {
List<Player> players = new ArrayList<Player>(Arrays.asList(plugin.getServer().getOnlinePlayers()));
players.removeAll(loggedInPlayer);
return players;
}
public boolean isPlayerLoggedIn(Player p) {
return loggedInPlayer.contains(p);
}
}

View File

@@ -0,0 +1,114 @@
package net.mc_pandacraft.java.plugin.pandacraftutils.modules;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import org.bukkit.entity.Player;
import com.comphenix.protocol.PacketType;
import com.comphenix.protocol.ProtocolLibrary;
import com.comphenix.protocol.events.ListenerOptions;
import com.comphenix.protocol.events.ListenerPriority;
import com.comphenix.protocol.events.PacketAdapter;
import com.comphenix.protocol.events.PacketEvent;
import com.comphenix.protocol.wrappers.WrappedGameProfile;
import net.mc_pandacraft.java.plugin.pandacraftutils.PandacraftUtils;
import net.mc_pandacraft.java.plugin.pandacraftutils.plugin_interface.EssentialsInterface;
public class PacketOutServerInfoListener {
private PandacraftUtils plugin;
public PacketOutServerInfoListener(PandacraftUtils pl) {
plugin = pl;
ProtocolLibrary
.getProtocolManager()
.addPacketListener(
new PacketAdapter(
plugin,
ListenerPriority.NORMAL,
Arrays.asList(new PacketType[] { PacketType.Status.Server.OUT_SERVER_INFO }),
new ListenerOptions[] { ListenerOptions.ASYNC })
{
@Override
public void onPacketSending(PacketEvent event)
{
Player[] pl_list = PacketOutServerInfoListener.this.plugin.getServer().getOnlinePlayers();
int count_player = 0;
List<Player> plAdmin = new ArrayList<Player>();
List<Player> plModo = new ArrayList<Player>();
List<Player> plPlayerUltimate = new ArrayList<Player>();
List<Player> plPlayerPremium = new ArrayList<Player>();
List<Player> plPlayer = new ArrayList<Player>();
for (Player p : pl_list)
{
if (p != null && p.isOnline())
{
// on passe si le joueur est vanish
if(EssentialsInterface.isPlayerVanished(p)) continue;
if (p.hasPermission("pandacraft.grade.admins"))
plAdmin.add(p);
else if (p.hasPermission("pandacraft.grade.modos"))
plModo.add(p);
else if (p.hasPermission("pandacraft.grade.ultimate"))
plPlayerUltimate.add(p);
else if (p.hasPermission("pandacraft.grade.premium"))
plPlayerPremium.add(p);
else
plPlayer.add(p);
count_player++;
}
}
List<WrappedGameProfile> list = new ArrayList<WrappedGameProfile>();
if (!plAdmin.isEmpty() || !plModo.isEmpty())
{
list.add(new WrappedGameProfile("", "§cStaff connecté :"));
for (Player p : plAdmin)
{
list.add(new WrappedGameProfile("", " - "+p.getDisplayName()));
}
for (Player p : plModo)
{
list.add(new WrappedGameProfile("", " - "+p.getDisplayName()));
}
}
if (!plPlayer.isEmpty() || !plPlayerPremium.isEmpty() || !plPlayerUltimate.isEmpty())
{
list.add(new WrappedGameProfile("", "§6Joueurs connectés :"));
for (Player p : plPlayerUltimate)
{
list.add(new WrappedGameProfile("", " - "+p.getDisplayName()));
}
for (Player p : plPlayerPremium)
{
list.add(new WrappedGameProfile("", " - "+p.getDisplayName()));
}
for (Player p : plPlayer)
{
list.add(new WrappedGameProfile("", " - "+p.getDisplayName()));
}
}
event.getPacket().getServerPings().read(0).setPlayers(list);
event.getPacket().getServerPings().read(0).setPlayersOnline(count_player);
}
}
);
}
}

View File

@@ -0,0 +1,52 @@
package net.mc_pandacraft.java.plugin.pandacraftutils.modules;
import java.util.Calendar;
import java.util.Date;
import net.mc_pandacraft.java.plugin.pandacraftutils.PandacraftUtils;
import org.bukkit.scheduler.BukkitRunnable;
public class SpawnTimeManager extends BukkitRunnable {
private PandacraftUtils plugin;
int timeTick = 0;
private String initial_map_name = "spawn";
public SpawnTimeManager(PandacraftUtils pl) {
plugin = pl;
run();
plugin.getServer().getScheduler().runTaskTimer(plugin, this, 1L, 2L);
}
@Override
public void run() {
Calendar calendar = Calendar.getInstance();
calendar.setTime(new Date());
int hours = calendar.get(Calendar.HOUR_OF_DAY);
int minutes = calendar.get(Calendar.MINUTE);
int seconds = calendar.get(Calendar.SECOND);
timeTick = ((hours * 3600 + minutes * 60 + seconds) * 10 / 36) - 6000;
if (timeTick < 0)
timeTick += 24000;
try
{
plugin.getServer().getWorld(initial_map_name).setFullTime(timeTick);
}
catch (NullPointerException e) {}
}
}

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

@@ -0,0 +1,86 @@
package net.mc_pandacraft.java.plugin.pandacraftutils.modules;
import java.util.LinkedList;
import net.mc_pandacraft.java.plugin.pandacraftutils.PandacraftUtils;
public class TPSAnalysisManager implements Runnable {
private static int nb_tick_history = 20 * 20; // 20 secondes;
private PandacraftUtils plugin = PandacraftUtils.getInstance();
private LinkedList<Long> tps_times = new LinkedList<Long>();
public TPSAnalysisManager()
{
plugin.getServer().getScheduler().runTaskTimer(plugin, this, 1L, 1L);
}
// mise à jour automatique pour le calcul des TPS
@Override
public void run() {
tps_times.add(new Long(System.currentTimeMillis()));
while (tps_times.size() > nb_tick_history + 1)
tps_times.poll();
}
public double getTPS()
{
return getTPS(nb_tick_history);
}
public double getTPS(int nb_tps)
{
if (tps_times.size() < 2)
return Double.NaN;
if (nb_tps >= tps_times.size()) nb_tps = tps_times.size()-1;
long time = tps_times.get(nb_tps).longValue() - tps_times.get(0).longValue();
if (time == 0)
return Double.NaN;
return nb_tps * 1000 / (double)time;
}
public double[] getTPSHistory(int nb_tick)
{
if (nb_tick >= tps_times.size()) nb_tick = tps_times.size()-1;
double[] history = new double[nb_tick];
for (int i=0; i<nb_tick; i++)
{
long elapsed = tps_times.get(i+1).longValue() - tps_times.get(i).longValue();
if (elapsed <= 0) elapsed = 1;
history[i] = 1000.0 / elapsed;
}
return history;
}
public String getStringTPSHistory(int nb_tick)
{
double[] history = getTPSHistory(nb_tick);
String s = "{MineAdmin_Graph}{";
boolean first = true;
for(double d : history)
{
if (first) first = false; else s = s.concat(",");
s = s.concat((Math.round(d*100)/100D)+"");
}
s = s.concat("}");
return s;
}
}

View File

@@ -0,0 +1,111 @@
package net.mc_pandacraft.java.plugin.pandacraftutils.modules;
import java.util.ArrayList;
import java.util.List;
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.WorldEditInterface;
import net.mc_pandacraft.java.util.bukkit.protocol.ParticleEffect;
import org.bukkit.Location;
import org.bukkit.entity.Player;
import org.bukkit.scheduler.BukkitRunnable;
import com.sk89q.worldedit.bukkit.selections.CuboidSelection;
public class WESelectionDisplayManager extends BukkitRunnable {
private PandacraftUtils plugin = PandacraftUtils.getInstance();
public WESelectionDisplayManager()
{
plugin.getServer().getScheduler().runTaskTimer(plugin, this, 20L, 20L);
}
// pour mettre à jour l'affichage du cubo
@Override
public void run() {
try
{
for (OnlinePlayer op : OnlinePlayerManager.getInstance().getAll())
{
Player p = op.getPlayer();
// on vérifie que le joueur soit en ligne
if (p == null || !p.isOnline())
continue;
if (!op.canViewWESelection()) continue; // le joueur ne veut pas voir de cubo
CuboidSelection cubo = WorldEditInterface.getPlayerCuboSelection(p);
// le joueur doit être dans le même monde que sa propre sélection
if (cubo != null && cubo.getWorld() == p.getWorld())
drawCuboid(cubo, p, true);
for (Player po : op.getPlayersForViewingOthersWESelections()){
if (po == null || !po.isOnline()) continue;
cubo = WorldEditInterface.getPlayerCuboSelection(po);
if (cubo != null && cubo.getWorld() == p.getWorld())
drawCuboid(cubo, p, false);
}
}
}
catch (Exception e) { e.printStackTrace(); }
}
private void drawCuboid(CuboidSelection cubo, Player p, boolean self)
{
List<Player> pls = new ArrayList<Player>(1);
pls.add(p);
Location p1 = cubo.getMinimumPoint(),
p2 = cubo.getMaximumPoint().add(1, 1, 1);
long x1 = Math.round(p1.getX()),
x2 = Math.round(p2.getX()),
y1 = Math.round(p1.getY()),
y2 = Math.round(p2.getY()),
z1 = Math.round(p1.getZ()),
z2 = Math.round(p2.getZ());
float offset = 0F;
float distance = 17;
for (long i=x1; i<=x2; i++)
for (long j=y1; j<=y2; j++)
for (long k=z1; k<=z2; k++)
{
// exclus les points qui ne sont pas en contact avec l'extérieur de la sélection
if (!(i == x1 || i == x2 || j == y1 || j == y2 || k == z1 || k == z2))
continue;
Location l = new Location(p1.getWorld(), i, j, k);
if (l.distanceSquared(p.getLocation()) < distance*distance){
if (self)
ParticleEffect.HAPPY_VILLAGER.display(offset, offset, offset, 0F, 1, l, pls);
else
ParticleEffect.FLAME.display(offset, offset, offset, 0F, 5, l, pls);
}
}
}
}

View File

@@ -0,0 +1,31 @@
package net.mc_pandacraft.java.plugin.pandacraftutils.modules.cheat_protect;
import net.mc_pandacraft.java.plugin.pandacraftutils.PandacraftUtils;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerMoveEvent;
public class CreativCheatManager implements Listener {
private PandacraftUtils plugin;
public CreativCheatManager(PandacraftUtils pl)
{
plugin = pl;
plugin.getServer().getPluginManager().registerEvents(this, plugin);
}
@EventHandler
public void onPlayerMove (PlayerMoveEvent e)
{
if (e.getTo().getY() > -60.0)
return;
e.getPlayer().setFallDistance(0);
e.getPlayer().setHealth(20);
e.getPlayer().teleport(e.getTo().getWorld().getSpawnLocation());
plugin.getLogger().info("§7"+e.getPlayer().getDisplayName()+"§r teleported to §7"+e.getTo().getWorld().getName()+"§r's spawn to avoid a bug exploit");
e.getPlayer().sendMessage("§dVous avez été téléporté au spawn de cette map car vous alliez tomber dans le vide.");
}
}

View File

@@ -0,0 +1,297 @@
package net.mc_pandacraft.java.plugin.pandacraftutils.modules.cheat_protect;
import java.util.List;
import net.mc_pandacraft.java.plugin.pandacraftutils.PandacraftUtils;
import org.bukkit.GameMode;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.event.block.BlockFromToEvent;
import org.bukkit.event.block.BlockIgniteEvent;
import org.bukkit.event.block.BlockPlaceEvent;
import org.bukkit.event.block.BlockIgniteEvent.IgniteCause;
import org.bukkit.event.player.PlayerBucketEmptyEvent;
public class NoPvpProtectManager implements Listener {
private PandacraftUtils plugin;
private double lava_distance = 5;
private double fire_distance = 5;
private String last_logger_message = "";
public NoPvpProtectManager(PandacraftUtils pl)
{
plugin = pl;
plugin.getServer().getPluginManager().registerEvents(this, plugin);
}
public void loggerInfo(String s)
{
if (s.equals(last_logger_message))
return;
plugin.getLogger().info(s);
last_logger_message = s;
}
@EventHandler
public void onBlockPlace(BlockPlaceEvent event)
{
if (event.getBlock().getWorld().getPVP())
return;
Material mat = event.getBlockPlaced().getType();
if (mat.equals(Material.LAVA) || mat.equals(Material.FIRE))
{ // on fait l'analyse pour le placement du bloc de lave
String mat_name_aff;
double distance;
if (mat.equals(Material.LAVA))
{
mat_name_aff = "de la lave";
distance = lava_distance;
}
else
{
mat_name_aff = "du feu";
distance = fire_distance;
}
Player p = event.getPlayer();
Location block_loc = event.getBlockPlaced().getLocation();
List<Player> pls = block_loc.getWorld().getPlayers();
boolean player_nearby = false;
String nearby_pl_aff = "";
// on fait le tour de toutes les entit§s de la map
for (Player pl : pls)
{
// on ne compte pas le poseur (sinon, on y arrivera pas x) )
if (pl == p || pl.getGameMode() == GameMode.CREATIVE)
continue;
Location ent_loc = pl.getLocation();
if (ent_loc.distance(block_loc) < distance)
{ // un joueur autre que celui qui a pos§ est trop proche
player_nearby = true;
nearby_pl_aff = nearby_pl_aff + " " + pl.getDisplayName();
}
}
if (player_nearby)
{
p.sendMessage("§dDemandez aux joueurs proche de vous de s'éloigner si vous voulez poser "+mat_name_aff+" :"+nearby_pl_aff);
loggerInfo("§7"+p.getName()+"§r attempted to place lava block or fire block in world §7"+block_loc.getWorld().getName()+"§r near to player(s) :§7" + nearby_pl_aff);
event.setCancelled(true);
}
}
}
@EventHandler
public void onPlayerBucketEmpty(PlayerBucketEmptyEvent event) {
if (event.getBlockClicked().getWorld().getPVP())
return;
if (event.getBucket() != null && event.getBucket() == Material.LAVA_BUCKET)
{ // on fait l'analyse pour le placement du bloc de lave
double distance = lava_distance;
Player p = event.getPlayer();
Location block_loc = event.getBlockClicked().getLocation();
List<Player> pls = block_loc.getWorld().getPlayers();
boolean player_nearby = false;
String nearby_pl_aff = "";
// on fait le tour de toutes les entit§s de la map
for (Player pl : pls)
{
// on ne compte pas le poseur (sinon, on y arrivera pas x) )
if (pl == p || pl.getGameMode() == GameMode.CREATIVE)
continue;
Location ent_loc = pl.getLocation();
if (ent_loc.distance(block_loc) < distance)
{ // un joueur autre que celui qui a pos§ est trop proche
player_nearby = true;
nearby_pl_aff = nearby_pl_aff + " " + pl.getDisplayName();
}
}
if (player_nearby)
{
p.sendMessage("§dDemandez aux joueurs proche de vous de s'éloigner si vous voulez poser de la lave :"+nearby_pl_aff);
loggerInfo("§7"+p.getName()+"§r attempted to place lava in world §7"+block_loc.getWorld().getName()+"§r near to player(s) :§7" + nearby_pl_aff);
event.setCancelled(true);
}
}
}
@EventHandler
public void onBlockIgnit(BlockIgniteEvent event) {
if (event.getPlayer() == null)
return;
if (event.getBlock().getWorld().getPVP())
return;
if (event.getCause() == IgniteCause.FIREBALL || event.getCause() == IgniteCause.FLINT_AND_STEEL)
{ // on fait l'analyse pour l'allumage avec un briquet
double distance = fire_distance;
Player p = event.getPlayer();
Location block_loc = event.getBlock().getLocation();
List<Player> pls = block_loc.getWorld().getPlayers();
boolean player_nearby = false;
String nearby_pl_aff = "";
// on fait le tour de tout les joueurs de la map
for (Player pl : pls)
{
// on ne compte pas le poseur (sinon, on y arrivera pas x) )
if (pl == p || pl.getGameMode() == GameMode.CREATIVE)
continue;
Location ent_loc = pl.getLocation();
if (ent_loc.distance(block_loc) < distance)
{ // un joueur autre que celui qui a pos§ est trop proche
player_nearby = true;
nearby_pl_aff = nearby_pl_aff + " " + pl.getDisplayName();
}
}
if (player_nearby)
{
p.sendMessage("§dDemandez aux joueurs proche de vous de s'éloigner si vous voulez poser du feu :"+nearby_pl_aff);
loggerInfo("§7"+p.getName()+"§r attempted to place fire in world §7"+block_loc.getWorld().getName()+"§r near to player(s) :§7" + nearby_pl_aff);
event.setCancelled(true);
}
}
}
@EventHandler
public void onBlockBreak(BlockBreakEvent event)
{
if (event.getBlock().getWorld().getPVP())
return;
Player p = event.getPlayer();
Block b = event.getBlock();
List<Player> pls = b.getWorld().getPlayers();
boolean player_standing = false;
String nearby_pl_aff = "";
// on fait le tour de tout les joueurs de la map
for (Player pl : pls)
{
// on ne compte pas le poseur (sinon, on y arrivera pas x) ) et on ignorent ceux qui fly
if (pl == p || pl.isFlying())
continue;
Location pl_loc = pl.getLocation().getBlock().getLocation();
Location pl_loc_under = new Location(pl_loc.getWorld(), pl_loc.getX(), pl_loc.getY()-1, pl_loc.getZ());
Location pl_loc_over = new Location(pl_loc.getWorld(), pl_loc.getX(), pl_loc.getY()+1, pl_loc.getZ());
if (pl_loc.equals(b.getLocation())
|| pl_loc_under.equals(b.getLocation())
|| pl_loc_over.equals(b.getLocation()))
{ // un joueur autre que celui qui a pos§ est trop proche
player_standing = true;
nearby_pl_aff = nearby_pl_aff + " " + pl.getDisplayName();
}
}
if (player_standing)
{
p.sendMessage("§dDemandez à ces joueurs de se déplacer si vous voulez casser ce bloc :"+nearby_pl_aff);
loggerInfo("§7"+p.getName()+"§r attempted to brake block in world §7"+b.getWorld().getName()+"§r under player(s) :§7" + nearby_pl_aff);
event.setCancelled(true);
}
}
@EventHandler
public void onBlockFromTo(BlockFromToEvent event)
{
if (event.getBlock().getWorld().getPVP())
return;
Block bf = event.getBlock();
Block bt = event.getToBlock();
Location loc_bt = bt.getLocation();
List<Player> pls = bf.getWorld().getPlayers();
boolean player_standing = false;
String nearby_pl_aff = "";
// on fait le tour de tout les joueurs de la map
for (Player pl : pls)
{
// on ignore ceux en cr§atif
if (pl.getGameMode() == GameMode.CREATIVE)
continue;
Location pl_loc = pl.getLocation().getBlock().getLocation();
// si la distance par rapport au joueur courant est > 5 bloc, on ignore
// c'est pour optimiser car les calculs qui suits semblent onéreuses en temps de calcul x)
if (pl_loc.distanceSquared(loc_bt) > 5*5)
continue;
Location pl_loc_floor = new Location(pl_loc.getWorld(), Math.floor(pl.getLocation().getX()), Math.floor(pl.getLocation().getY()), Math.floor(pl.getLocation().getZ()));
Location pl_loc_inner_block = pl.getLocation().subtract(pl_loc_floor);
int x_min = (int)Math.round(pl_loc.getX())-((pl_loc_inner_block.getX()<=0.3)?1:0);
int y_min = (int)Math.round(pl_loc.getY())-1;
int z_min = (int)Math.round(pl_loc.getZ())-((pl_loc_inner_block.getZ()<=0.3)?1:0);
int x_max = (int)Math.round(pl_loc.getX())+((pl_loc_inner_block.getX()>=0.7)?1:0);
int y_max = (int)Math.round(pl_loc.getY())+((pl_loc_inner_block.getY()>=0.2)?2:1);
int z_max = (int)Math.round(pl_loc.getZ())+((pl_loc_inner_block.getZ()>=0.7)?1:0);
for (int x = x_min; x <= x_max; x++)
for (int y = y_min; y <= y_max; y++)
for (int z = z_min; z <= z_max; z++)
if ((new Location(pl_loc.getWorld(), x, y, z)).equals(loc_bt))
{
player_standing = true;
nearby_pl_aff = nearby_pl_aff + " " + pl.getDisplayName();
}
}
if (player_standing)
{
event.setCancelled(true);
}
}
}