Ajout de la fonctionnalité de WorldBorder

This commit is contained in:
Marc Baloup 2015-02-11 22:24:47 -05:00
parent c13de458d4
commit 101ab8f453
7 changed files with 276 additions and 3 deletions

View File

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

View File

@ -129,6 +129,7 @@ public class ConfigManager {
initChatAnalysisBadWord();
initCommandAlias();
initAutomessages();
initWorldBorder();
}
@ -395,6 +396,71 @@ public class ConfigManager {
/*
* World Border
*/
public HashMap<String, WorldBorderConfig> WorldBorder_config;
private void initWorldBorder() {
WorldBorder_config = new HashMap<String, WorldBorderConfig>();
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<String> CuboCommand_worlds = new ArrayList<String>();
@ -408,4 +474,26 @@ public class ConfigManager {
}

View File

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

View File

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

View File

@ -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<OnlinePlayer> players = OnlinePlayerManager.getAll();
Map<String, WorldBorderConfig> 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<Player> pls = new ArrayList<Player>(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);
}
}
}

View File

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