2015-01-22 09:32:47 +01:00
|
|
|
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;
|
2015-01-22 07:19:50 +01:00
|
|
|
import net.mc_pandacraft.java.plugin.pandacraftutils.players.OnlinePlayer;
|
|
|
|
import net.mc_pandacraft.java.plugin.pandacraftutils.players.OnlinePlayerManager;
|
2015-01-07 04:13:50 +01:00
|
|
|
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;
|
|
|
|
|
2015-01-22 09:32:47 +01:00
|
|
|
public class WESelectionDisplayManager extends BukkitRunnable {
|
2014-11-22 17:18:10 +01:00
|
|
|
|
2015-01-22 09:32:47 +01:00
|
|
|
private PandacraftUtils plugin = PandacraftUtils.getInstance();
|
2014-11-22 17:18:10 +01:00
|
|
|
|
|
|
|
|
2015-01-22 09:32:47 +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
|
|
|
|
{
|
|
|
|
|
2015-01-22 07:19:50 +01:00
|
|
|
for (OnlinePlayer op : OnlinePlayerManager.getInstance().getAll())
|
2014-11-22 17:18:10 +01:00
|
|
|
{
|
2015-01-22 07:19:50 +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;
|
|
|
|
|
2015-01-22 07:19:50 +01:00
|
|
|
if (!op.canViewWESelection()) continue; // le joueur ne veut pas voir de cubo
|
|
|
|
|
2015-01-07 04:13:50 +01:00
|
|
|
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
|
2014-11-23 00:28:17 +01:00
|
|
|
if (cubo != null && cubo.getWorld() == p.getWorld())
|
|
|
|
drawCuboid(cubo, p, true);
|
|
|
|
|
2015-01-22 07:19:50 +01:00
|
|
|
for (Player po : op.getPlayersForViewingOthersWESelections()){
|
2014-11-23 00:28:17 +01:00
|
|
|
if (po == null || !po.isOnline()) continue;
|
|
|
|
|
2015-01-07 04:13:50 +01:00
|
|
|
cubo = WorldEditInterface.getPlayerCuboSelection(po);
|
2014-11-23 00:28:17 +01:00
|
|
|
|
|
|
|
if (cubo != null && cubo.getWorld() == p.getWorld())
|
|
|
|
drawCuboid(cubo, p, false);
|
|
|
|
}
|
|
|
|
|
2014-11-22 17:18:10 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (Exception e) { e.printStackTrace(); }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2014-11-23 00:28:17 +01:00
|
|
|
|
|
|
|
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);
|
2014-11-23 00:28:17 +01:00
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|