package net.mc_pandacraft.java.plugin.pandacraftutils.modules; 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; import net.mc_pandacraft.java.util.bukkit.protocol.ParticleEffect; 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 { private PandacraftUtils plugin = PandacraftUtils.getInstance(); public WESelectionDisplayManager() { 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()) { Player p = op.getPlayer(); // 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); // 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); } } } catch (Exception e) { e.printStackTrace(); } } private void drawCuboid(CuboidSelection cubo, Player p, boolean self) { List pls = new ArrayList(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); } } } }