diff --git a/src/net/mc_pandacraft/java/plugin/pandacraftutils/PandacraftUtils.java b/src/net/mc_pandacraft/java/plugin/pandacraftutils/PandacraftUtils.java index a529f50..1c21c75 100644 --- a/src/net/mc_pandacraft/java/plugin/pandacraftutils/PandacraftUtils.java +++ b/src/net/mc_pandacraft/java/plugin/pandacraftutils/PandacraftUtils.java @@ -36,6 +36,27 @@ public class PandacraftUtils extends JavaPlugin { } + /** + * 'u' = stopped + * 'l' = loading + * 'r' = running + * 's' = stopping + */ + private static ServerState serverState = ServerState.STOPPED; + + public static ServerState getServerState() { return serverState; } + public static void setServerState(ServerState s) { serverState = s; } + + public enum ServerState{ + STOPPED, + LOADING, + RUNNING, + STOPPING + } + + + + //public DBConnection databaseConnection; public AfkManager afkManager; @@ -64,6 +85,8 @@ public class PandacraftUtils extends JavaPlugin { @Override public void onEnable(){ + setServerState(ServerState.LOADING); + instance = this; /* @@ -107,9 +130,17 @@ public class PandacraftUtils extends JavaPlugin { NetworkAPI.loadNewInstance(); getServer().getScheduler().runTaskLater(this, new Runnable() { - @Override public void run() { new PlayerDataCleaner(instance); } + @Override public void run() { + new PlayerDataCleaner(instance); + } }, 1); + getServer().getScheduler().runTaskLater(this, new Runnable() { + @Override public void run() { + setServerState(ServerState.RUNNING); + } + }, 30); + } @@ -117,6 +148,8 @@ public class PandacraftUtils extends JavaPlugin { @Override public void onDisable(){ + setServerState(ServerState.STOPPING); + ConfigManager.getInstance().saveAll(); afkManager = null; diff --git a/src/net/mc_pandacraft/java/plugin/pandacraftutils/modules/PacketOutServerInfoListener.java b/src/net/mc_pandacraft/java/plugin/pandacraftutils/modules/PacketOutServerInfoListener.java index bcc6813..ef83c48 100644 --- a/src/net/mc_pandacraft/java/plugin/pandacraftutils/modules/PacketOutServerInfoListener.java +++ b/src/net/mc_pandacraft/java/plugin/pandacraftutils/modules/PacketOutServerInfoListener.java @@ -16,6 +16,7 @@ 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.PandacraftUtils.ServerState; import net.mc_pandacraft.java.plugin.pandacraftutils.config.ConfigManager; import net.mc_pandacraft.java.plugin.pandacraftutils.players.OnlinePlayer; import net.mc_pandacraft.java.plugin.pandacraftutils.players.OnlinePlayerManager; @@ -105,8 +106,10 @@ public class PacketOutServerInfoListener { event.getPacket().getServerPings().read(0).setPlayersOnline(count_player); - - event.getPacket().getServerPings().read(0).setMotD(ConfigManager.getInstance().defaultConfig.pingMOTD); + if (PandacraftUtils.getServerState().equals(ServerState.RUNNING)) + event.getPacket().getServerPings().read(0).setMotD(ConfigManager.getInstance().defaultConfig.pingMOTD); + else + event.getPacket().getServerPings().read(0).setMotD("."); } } ); diff --git a/src/net/mc_pandacraft/java/plugin/pandacraftutils/modules/protection/WorldBorderManager.java b/src/net/mc_pandacraft/java/plugin/pandacraftutils/modules/protection/WorldBorderManager.java index a9902cc..cc930ec 100644 --- a/src/net/mc_pandacraft/java/plugin/pandacraftutils/modules/protection/WorldBorderManager.java +++ b/src/net/mc_pandacraft/java/plugin/pandacraftutils/modules/protection/WorldBorderManager.java @@ -9,6 +9,7 @@ import net.mc_pandacraft.java.plugin.pandacraftutils.config.ConfigManager; import net.mc_pandacraft.java.plugin.pandacraftutils.config.elements.WorldBorderConfigEntry; import net.mc_pandacraft.java.plugin.pandacraftutils.players.OnlinePlayer; import net.mc_pandacraft.java.plugin.pandacraftutils.players.OnlinePlayerManager; +import net.mc_pandacraft.java.util.bukkit.EntityStackUtil; import net.mc_pandacraft.java.util.bukkit.protocol.ParticleEffect; import org.bukkit.ChatColor; @@ -47,7 +48,7 @@ public class WorldBorderManager extends BukkitRunnable implements Listener { Location newLoc = checkPosition(op.getPlayer().getLocation(), config); if (newLoc != null) { // le joueur dépasse la bordure - op.teleportWithVehicle(newLoc); + EntityStackUtil.teleportStack(op.getPlayer(), newLoc); op.getPlayer().sendMessage(ChatColor.RED+"Vous avez été téléporté car vous avez passé la limite de la carte"); } diff --git a/src/net/mc_pandacraft/java/plugin/pandacraftutils/players/OnlinePlayer.java b/src/net/mc_pandacraft/java/plugin/pandacraftutils/players/OnlinePlayer.java index c61826f..70ed68b 100644 --- a/src/net/mc_pandacraft/java/plugin/pandacraftutils/players/OnlinePlayer.java +++ b/src/net/mc_pandacraft/java/plugin/pandacraftutils/players/OnlinePlayer.java @@ -14,8 +14,6 @@ import net.mc_pandacraft.java.plugin.pandacraftutils.plugin_interface.Essentials import org.bukkit.Bukkit; import org.bukkit.ChatColor; -import org.bukkit.Location; -import org.bukkit.entity.Entity; import org.bukkit.entity.Player; import org.bukkit.entity.Tameable; @@ -305,19 +303,6 @@ public class OnlinePlayer { } - public boolean teleportWithVehicle(Location l) { - Entity toTeleport = player; - while (toTeleport.getVehicle() != null) { - toTeleport = toTeleport.getVehicle(); - } - return toTeleport.teleport(l); - } - - - - - - diff --git a/src/net/mc_pandacraft/java/util/bukkit/EntityStackUtil.java b/src/net/mc_pandacraft/java/util/bukkit/EntityStackUtil.java new file mode 100644 index 0000000..28b93ec --- /dev/null +++ b/src/net/mc_pandacraft/java/util/bukkit/EntityStackUtil.java @@ -0,0 +1,70 @@ +package net.mc_pandacraft.java.util.bukkit; + +import java.util.ArrayList; +import java.util.List; + +import org.bukkit.Location; +import org.bukkit.entity.Entity; + +/** + * Permet de gérer les entités qui se transportent les uns les autres + * + * Ce groupement d'entité est appelé une "pile d'entité". + * + * Par exemple, un cheval et son monteur représente à eux deux une pile d'entité, dont + * l'élement tout en bas est le cheval + */ +public class EntityStackUtil { + + /** + * Déplace une pile d'entité vers l'endroit défini + * @param e Une entité faisant parti de la pile d'entité à téléporter + * @param l La position vers lequel envoyer toute la pile + */ + public static void teleportStack(Entity e, Location l) + { + List stack = new ArrayList(); + + // on se place sur l'entité tout en bas de la pile + Entity entTemp = e; + while (entTemp.getVehicle() != null) + entTemp = entTemp.getVehicle(); + + do { + stack.add(entTemp); + entTemp = entTemp.getPassenger(); + } while (entTemp != null); + + if (stack.size() == 1) { + stack.get(0).teleport(l); + return; + } + + stack.get(0).eject(); + stack.get(0).teleport(l); + stack.get(0).setPassenger(stack.get(1)); + + + } + + + + + + + + + + + + + + + + + + + + + +}