PandacraftUtils/src/net/mc_pandacraft/java/plugin/pandacraftutils/modules/WESelectionDisplayManager.java

112 lines
3.0 KiB
Java
Raw Normal View History

package net.mc_pandacraft.java.plugin.pandacraftutils.modules;
2014-11-22 17:18:10 +01:00
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;
2014-11-29 13:42:25 +01:00
import net.mc_pandacraft.java.util.bukkit.protocol.ParticleEffect;
2014-11-22 17:18:10 +01:00
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 {
2014-11-22 17:18:10 +01:00
private PandacraftUtils plugin = PandacraftUtils.getInstance();
2014-11-22 17:18:10 +01:00
public WESelectionDisplayManager()
2014-11-22 17:18:10 +01:00
{
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())
2014-11-22 17:18:10 +01:00
{
Player p = op.getPlayer();
2014-11-22 17:18:10 +01:00
// 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);
2014-11-22 17:18:10 +01:00
// 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);
}
2014-11-22 17:18:10 +01:00
}
}
catch (Exception e) { e.printStackTrace(); }
}
private void drawCuboid(CuboidSelection cubo, Player p, boolean self)
2014-11-22 17:18:10 +01:00
{
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);
}
2014-11-22 17:18:10 +01:00
}
}
}