On peut maintenant voir la sélection WorldEdit d'un autre joueur (quadrillage de flamme) + ajout d'une fonctionnalité dans le projet permettant d'empaqueter le .jar en quelques clics, avec la config toute faite

This commit is contained in:
2014-11-23 00:28:17 +01:00
parent f7c9962e89
commit dd11a55497
6 changed files with 113 additions and 26 deletions

View File

@@ -14,7 +14,7 @@ public class ConfigManager {
public static ConfigManager getInstance() { return instance; }
@SuppressWarnings("unused")
private PandacraftUtils plugin;
public ConfigManager(File f, PandacraftUtils pl) {

View File

@@ -1,9 +1,10 @@
package net.mc_pandacraft.java.plugin.pandacraftutils.survival_cuboid;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import net.mc_pandacraft.java.plugin.pandacraftutils.PandacraftUtils;
import net.mc_pandacraft.java.plugin.pandacraftutils.protocol.ParticleEffect;
@@ -28,7 +29,7 @@ public class CommandWandSelection extends BukkitRunnable implements CommandExecu
private PandacraftUtils plugin;
private List<Player> players = new LinkedList<Player>();
private Map<Player, List<Player>> players = new HashMap<Player, List<Player>>();
@@ -40,7 +41,8 @@ public class CommandWandSelection extends BukkitRunnable implements CommandExecu
plugin.getServer().getScheduler().runTaskTimer(plugin, this, 20L, 20L);
plugin.getServer().getPluginManager().registerEvents(this, plugin);
players.addAll(Arrays.asList(plugin.getServer().getOnlinePlayers()));
for (Player p : plugin.getServer().getOnlinePlayers())
players.put(p, new ArrayList<Player>());
}
@@ -69,15 +71,47 @@ public class CommandWandSelection extends BukkitRunnable implements CommandExecu
}
Player p = (Player) sender;
if (players.contains(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 (players.containsKey(p) && otherP == null)
{ // le joueur ne veut plus voir de cubo
players.remove(p);
sender.sendMessage(ChatColor.GREEN+"Affichage de la sélection désactivé.");
}
else if (players.containsKey(p))
{
if (players.get(p).contains(otherP))
{
players.get(p).remove(otherP);
sender.sendMessage(ChatColor.GREEN+"Affichage de la sélection de "+ChatColor.GRAY+otherP.getName()+ChatColor.GREEN+" désactivé.");
}
else
{
players.get(p).add(otherP);
sender.sendMessage(ChatColor.GREEN+"Affichage de la sélection de "+ChatColor.GRAY+otherP.getName()+ChatColor.GREEN+" activé.");
}
}
else
{
players.add(p);
players.put(p, new ArrayList<Player>());
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) {
players.get(p).add(otherP);
sender.sendMessage(ChatColor.GREEN+"Affichage de la sélection de "+ChatColor.GRAY+otherP.getName()+ChatColor.GREEN+" activé.");
}
}
return true;
@@ -88,7 +122,7 @@ public class CommandWandSelection extends BukkitRunnable implements CommandExecu
@EventHandler
public void onPlayerQuit(PlayerQuitEvent event)
{
if (players.contains(event.getPlayer()))
if (players.containsKey(event.getPlayer()))
players.remove(event.getPlayer());
}
@@ -96,8 +130,8 @@ public class CommandWandSelection extends BukkitRunnable implements CommandExecu
@EventHandler
public void onPlayerJoin(PlayerJoinEvent event)
{
if (!players.contains(event.getPlayer()))
players.add(event.getPlayer());
if (!players.containsKey(event.getPlayer()))
players.put(event.getPlayer(), new ArrayList<Player>());
}
@@ -106,29 +140,35 @@ public class CommandWandSelection extends BukkitRunnable implements CommandExecu
@Override
public void run() {
WorldEditPlugin wePlugin = (WorldEditPlugin) plugin.getServer().getPluginManager().getPlugin("WorldEdit");
if (wePlugin == null) return;
try
{
for (Player p : players)
for (Entry<Player, List<Player>> pl : players.entrySet())
{
Player p = pl.getKey();
// on vérifie que le joueur soit en ligne
if (p == null || !p.isOnline())
continue;
Selection sel = wePlugin.getSelection(p);
// on garde que les cuboïdes (pas les autres formes)
if (!(sel instanceof CuboidSelection))
continue;
CuboidSelection cubo = (CuboidSelection) sel;
CuboidSelection cubo = getPlayerCuboSelection(p);
// le joueur doit être dans le même monde que sa propre sélection
if (cubo.getWorld() != p.getWorld())
if (cubo != null && cubo.getWorld() == p.getWorld())
drawCuboid(cubo, p, true);
if (pl.getValue() == null)
continue;
drawCuboid(cubo, p);
for (Player po : pl.getValue()){
if (po == null || !po.isOnline()) continue;
cubo = getPlayerCuboSelection(po);
if (cubo != null && cubo.getWorld() == p.getWorld())
drawCuboid(cubo, p, false);
}
}
}
catch (Exception e) { e.printStackTrace(); }
@@ -140,7 +180,21 @@ public class CommandWandSelection extends BukkitRunnable implements CommandExecu
private void drawCuboid(CuboidSelection cubo, Player p)
private CuboidSelection getPlayerCuboSelection(Player p) {
WorldEditPlugin wePlugin = (WorldEditPlugin) plugin.getServer().getPluginManager().getPlugin("WorldEdit");
if (wePlugin == null) return null;
Selection sel = wePlugin.getSelection(p);
if (sel == null) return null;
// on garde que les cuboïdes (pas les autres formes)
if (!(sel instanceof CuboidSelection))
return null;
return (CuboidSelection) sel;
}
private void drawCuboid(CuboidSelection cubo, Player p, boolean self)
{
List<Player> pls = new ArrayList<Player>(1);
pls.add(p);
@@ -166,9 +220,13 @@ public class CommandWandSelection extends BukkitRunnable implements CommandExecu
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)
ParticleEffect.HAPPY_VILLAGER
.display(offset, offset, offset, 0F, 1, l, pls);
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);
}
}
}