From 101ab8f4530934baea47047254fdeaa4f6122cb7 Mon Sep 17 00:00:00 2001 From: Marc Baloup Date: Wed, 11 Feb 2015 22:24:47 -0500 Subject: [PATCH] =?UTF-8?q?Ajout=20de=20la=20fonctionnalit=C3=A9=20de=20Wo?= =?UTF-8?q?rldBorder?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- make_jar.jardesc | 2 +- resources/plugin.yml | 2 +- .../plugin/pandacraftutils/ConfigManager.java | 88 +++++++++ .../pandacraftutils/PandacraftUtils.java | 4 + .../modules/WESelectionDisplayManager.java | 2 +- .../modules/WorldBorderManager.java | 176 ++++++++++++++++++ .../pandacraftutils/players/OnlinePlayer.java | 5 + 7 files changed, 276 insertions(+), 3 deletions(-) create mode 100644 src/net/mc_pandacraft/java/plugin/pandacraftutils/modules/WorldBorderManager.java diff --git a/make_jar.jardesc b/make_jar.jardesc index 9f562b5..d2486a2 100644 --- a/make_jar.jardesc +++ b/make_jar.jardesc @@ -1,6 +1,6 @@ - + diff --git a/resources/plugin.yml b/resources/plugin.yml index 0d03030..59f2734 100644 --- a/resources/plugin.yml +++ b/resources/plugin.yml @@ -1,6 +1,6 @@ name: PandacraftUtils main: net.mc_pandacraft.java.plugin.pandacraftutils.PandacraftUtils -version: 3.7 +version: 3.8 diff --git a/src/net/mc_pandacraft/java/plugin/pandacraftutils/ConfigManager.java b/src/net/mc_pandacraft/java/plugin/pandacraftutils/ConfigManager.java index dd7f3a8..777f5ea 100644 --- a/src/net/mc_pandacraft/java/plugin/pandacraftutils/ConfigManager.java +++ b/src/net/mc_pandacraft/java/plugin/pandacraftutils/ConfigManager.java @@ -129,6 +129,7 @@ public class ConfigManager { initChatAnalysisBadWord(); initCommandAlias(); initAutomessages(); + initWorldBorder(); } @@ -395,6 +396,71 @@ public class ConfigManager { + + + /* + * World Border + */ + + public HashMap WorldBorder_config; + + + private void initWorldBorder() { + WorldBorder_config = new HashMap(); + + WorldBorder_config.put("Faction", new WorldBorderConfig(40, 296, 2000)); + WorldBorder_config.put("Survival_nether", new WorldBorderConfig(-11.4F, 18.5F, 1500)); + WorldBorder_config.put("Survival", new WorldBorderConfig(800, 1536, 5000)); + WorldBorder_config.put("NewFaction", new WorldBorderConfig(136, -136, 3000)); + WorldBorder_config.put("Faction_nether", new WorldBorderConfig(-81.6F, -76.9F, 500)); + WorldBorder_config.put("PlatCreative", new WorldBorderConfig(456.6f, -1367.5f, 735)); + WorldBorder_config.put("world", new WorldBorderConfig(0, 0, 2000)); + WorldBorder_config.put("spawn", new WorldBorderConfig(-224, 366, 1000)); + WorldBorder_config.put("creative", new WorldBorderConfig(0, 0, 1700)); + + + } + + + + + public static class WorldBorderConfig { + public final float X, Z, radius; + + public WorldBorderConfig(float x, float z, float r) { + X = x; + Z = z; + radius = Math.abs(r); + } + + public double getMinX() { return X - radius; } + public double getMaxX() { return X + radius; } + public double getMinZ() { return Z - radius; } + public double getMaxZ() { return Z + radius; } + + + + } + + + + + + + + + + + + + + + + + + + + public List CuboCommand_worlds = new ArrayList(); @@ -408,4 +474,26 @@ public class ConfigManager { + + + + + + + + + + + + + + + + + + + + + + } diff --git a/src/net/mc_pandacraft/java/plugin/pandacraftutils/PandacraftUtils.java b/src/net/mc_pandacraft/java/plugin/pandacraftutils/PandacraftUtils.java index f870088..a8e8949 100644 --- a/src/net/mc_pandacraft/java/plugin/pandacraftutils/PandacraftUtils.java +++ b/src/net/mc_pandacraft/java/plugin/pandacraftutils/PandacraftUtils.java @@ -13,6 +13,7 @@ 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.WorldBorderManager; import net.mc_pandacraft.java.plugin.pandacraftutils.modules.cheat_protect.CreativCheatManager; import net.mc_pandacraft.java.plugin.pandacraftutils.modules.cheat_protect.EntitySpamManager; import net.mc_pandacraft.java.plugin.pandacraftutils.modules.cheat_protect.NoPvpProtectManager; @@ -49,6 +50,7 @@ public class PandacraftUtils extends JavaPlugin { public AutoMessagesManager autoMessagesManager; public EntitySpamManager entitySpamManager; public TamedEntityProtectManager tamedEntityProtectManager; + public WorldBorderManager worldBorderManager; @@ -94,6 +96,7 @@ public class PandacraftUtils extends JavaPlugin { autoMessagesManager = new AutoMessagesManager(); entitySpamManager = new EntitySpamManager(); tamedEntityProtectManager = new TamedEntityProtectManager(); + worldBorderManager = new WorldBorderManager(); NetworkAPI.loadNewInstance(); @@ -124,6 +127,7 @@ public class PandacraftUtils extends JavaPlugin { autoMessagesManager = null; entitySpamManager = null; tamedEntityProtectManager = null; + worldBorderManager = null; instance = null; diff --git a/src/net/mc_pandacraft/java/plugin/pandacraftutils/modules/WESelectionDisplayManager.java b/src/net/mc_pandacraft/java/plugin/pandacraftutils/modules/WESelectionDisplayManager.java index a756120..699a6b5 100644 --- a/src/net/mc_pandacraft/java/plugin/pandacraftutils/modules/WESelectionDisplayManager.java +++ b/src/net/mc_pandacraft/java/plugin/pandacraftutils/modules/WESelectionDisplayManager.java @@ -102,7 +102,7 @@ public class WESelectionDisplayManager extends BukkitRunnable { if (self) ParticleEffect.HAPPY_VILLAGER.display(offset, offset, offset, 0F, 1, l, pls); else - ParticleEffect.FLAME.display(offset, offset, offset, 0F, 5, l, pls); + ParticleEffect.RED_DUST.display(offset, offset, offset, 0F, 3, l, pls); } } diff --git a/src/net/mc_pandacraft/java/plugin/pandacraftutils/modules/WorldBorderManager.java b/src/net/mc_pandacraft/java/plugin/pandacraftutils/modules/WorldBorderManager.java new file mode 100644 index 0000000..70f9e53 --- /dev/null +++ b/src/net/mc_pandacraft/java/plugin/pandacraftutils/modules/WorldBorderManager.java @@ -0,0 +1,176 @@ +package net.mc_pandacraft.java.plugin.pandacraftutils.modules; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; +import java.util.Map; + +import net.mc_pandacraft.java.plugin.pandacraftutils.PandacraftUtils; +import net.mc_pandacraft.java.plugin.pandacraftutils.ConfigManager; +import net.mc_pandacraft.java.plugin.pandacraftutils.ConfigManager.WorldBorderConfig; +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.protocol.ParticleEffect; + +import org.bukkit.ChatColor; +import org.bukkit.Location; +import org.bukkit.entity.Player; +import org.bukkit.event.Listener; +import org.bukkit.event.player.PlayerTeleportEvent; +import org.bukkit.scheduler.BukkitRunnable; + +public class WorldBorderManager extends BukkitRunnable implements Listener { + private PandacraftUtils plugin = PandacraftUtils.getInstance(); + + + + public WorldBorderManager() + { + plugin.getServer().getScheduler().runTaskTimer(plugin, this, 2L, 20L); + plugin.getServer().getPluginManager().registerEvents(this, plugin); + } + + + + + + @Override + public void run() { + + Collection players = OnlinePlayerManager.getAll(); + + Map configs = ConfigManager.getInstance().WorldBorder_config; + + + for (OnlinePlayer op : players) { + WorldBorderConfig config = configs.get(op.getPlayer().getWorld().getName()); + + if (config == null) return; + + // vérifier la position + Location newLoc = checkPosition(op.getPlayer().getLocation(), config); + + if (newLoc != null) { // le joueur dépasse la bordure + op.getPlayer().teleport(newLoc); + op.getPlayer().sendMessage(ChatColor.RED+"Vous avez été téléporté car vous avez passé la limite de la carte"); + } + + // afficher la limite + drawLimit(op.getPlayer(), config); + + } + + + } + + + public void onPlayerTeleport(PlayerTeleportEvent event) { + + Location l = event.getTo(); + + WorldBorderConfig config = ConfigManager.getInstance().WorldBorder_config.get(l.getWorld().getName()); + + if (config == null) return; + + Location newLoc = checkPosition(l, config); + + if (newLoc == null) return; + + event.setTo(newLoc); + + } + + + + + + + + + /** + * Vérifie la position donnée et donne une nouvelle position si nécessaire + * @param l la localisation vérifiée + * @param config la configuration sur lequel confronter la position + * @return une nouvelle position si le joueur doit bouger, ou null si ce n'est pas nécessaire + */ + public Location checkPosition(Location l, WorldBorderConfig config) { + + // si le joueur ne dépasse pas la bordure + if (isInSquare(l, config)) return null; + + double x = l.getX(); + double z = l.getZ(); + + if (x < config.getMinX()) + x = config.getMinX() + 1; + else if (x > config.getMaxX()) + x = config.getMaxX() - 1; + + if (z < config.getMinZ()) + z = config.getMinZ() + 1; + else if (z > config.getMaxZ()) + z = config.getMaxZ() - 1; + + return new Location(l.getWorld(), x, l.getY(), z, l.getYaw(),l.getPitch()); + } + + + + + + + + + public boolean isInSquare(Location pLoc, WorldBorderConfig config) { + if (Math.abs(config.X - pLoc.getX()) > config.radius) + return false; + if (Math.abs(config.Z - pLoc.getZ()) > config.radius) + return false; + return true; + } + + + + + + + + public void drawLimit(Player p, WorldBorderConfig config) { + + List pls = new ArrayList(1); + pls.add(p); + + long x1 = Math.round(config.getMinX()), + x2 = Math.round(config.getMaxX()), + z1 = Math.round(config.getMinZ()), + z2 = Math.round(config.getMaxZ()); + + Location pLoc = p.getLocation(); + + int distance = 17; + float offset = 0F; + + for (long i = Math.max(pLoc.getBlockX() - distance, x1); i <= Math.min(pLoc.getBlockX() + distance, x2); i++) + for (int j = pLoc.getBlockY() - distance; j <= pLoc.getBlockY() + distance; j++) + for (long k = Math.max(pLoc.getBlockZ() - distance, z1); k <= Math.min(pLoc.getBlockZ() + distance, z2); k++) { + + // exclus les points qui ne sont pas en contact avec l'extérieur de la sélection + if (!(i == x1 || i == x2 || k == z1 || k == z2)) + continue; + + Location l = new Location(pLoc.getWorld(), i, j, k); + + if(l.distanceSquared(pLoc) < distance*distance) + ParticleEffect.FLAME.display(offset, offset, offset, 0F, 4, l, pls); + } + + + } + + + + + + + +} 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 3a879a5..158baad 100644 --- a/src/net/mc_pandacraft/java/plugin/pandacraftutils/players/OnlinePlayer.java +++ b/src/net/mc_pandacraft/java/plugin/pandacraftutils/players/OnlinePlayer.java @@ -297,7 +297,12 @@ public class OnlinePlayer { * @return */ public String[] getGroups() { + try { return PermissionsEx.getUser(player).getGroupsNames(); + } catch (NoClassDefFoundError e) { + String[] g = {"default"}; + return g; + } } /** * Indique si le joueur est dans le groupe Spécifié