2014-10-19 23:04:27 +02:00
|
|
|
package com.massivecraft.factions.cmd;
|
|
|
|
|
2018-03-27 01:42:26 +02:00
|
|
|
|
2014-10-19 23:04:27 +02:00
|
|
|
import com.massivecraft.factions.FLocation;
|
2018-03-29 02:33:10 +02:00
|
|
|
import com.massivecraft.factions.P;
|
2014-10-19 23:04:27 +02:00
|
|
|
import com.massivecraft.factions.struct.Permission;
|
2018-04-01 16:13:23 +02:00
|
|
|
import com.massivecraft.factions.util.Particles.ParticleEffect;
|
2018-04-03 16:38:11 +02:00
|
|
|
import com.massivecraft.factions.util.VisualizeUtil;
|
2015-01-22 00:58:33 +01:00
|
|
|
import com.massivecraft.factions.zcore.util.TL;
|
2018-03-29 02:33:10 +02:00
|
|
|
import org.bukkit.Bukkit;
|
2014-10-19 23:04:27 +02:00
|
|
|
import org.bukkit.Location;
|
|
|
|
import org.bukkit.Material;
|
|
|
|
import org.bukkit.World;
|
|
|
|
import org.bukkit.entity.Player;
|
|
|
|
|
2018-03-29 02:33:10 +02:00
|
|
|
import java.util.Arrays;
|
|
|
|
import java.util.HashMap;
|
|
|
|
import java.util.Iterator;
|
|
|
|
import java.util.List;
|
2018-03-26 23:43:15 +02:00
|
|
|
|
2014-10-19 23:04:27 +02:00
|
|
|
public class CmdSeeChunk extends FCommand {
|
|
|
|
|
2018-03-29 02:33:10 +02:00
|
|
|
//Used a hashmap cuz imma make a particle selection gui later, will store it where the boolean is rn.
|
|
|
|
public static HashMap<String, Boolean> seeChunkMap = new HashMap<>();
|
|
|
|
Long interval = 10L;
|
2018-07-12 18:11:07 +02:00
|
|
|
private boolean useParticles;
|
|
|
|
private int length;
|
|
|
|
private ParticleEffect effect;
|
2018-03-29 02:33:10 +02:00
|
|
|
private int taskID = -1;
|
|
|
|
|
|
|
|
|
|
|
|
//I remade it cause of people getting mad that I had the same seechunk as drtshock
|
|
|
|
|
2018-03-26 23:43:15 +02:00
|
|
|
|
2014-10-19 23:04:27 +02:00
|
|
|
public CmdSeeChunk() {
|
|
|
|
super();
|
|
|
|
aliases.add("seechunk");
|
|
|
|
aliases.add("sc");
|
|
|
|
|
|
|
|
permission = Permission.SEECHUNK.node;
|
|
|
|
|
|
|
|
senderMustBePlayer = true;
|
|
|
|
senderMustBeMember = false;
|
|
|
|
senderMustBeModerator = false;
|
|
|
|
senderMustBeAdmin = false;
|
2018-03-26 23:43:15 +02:00
|
|
|
|
|
|
|
this.useParticles = p.getConfig().getBoolean("see-chunk.particles", true);
|
2018-03-29 02:33:10 +02:00
|
|
|
interval = P.p.getConfig().getLong("see-chunk.interval", 10L);
|
2018-07-12 18:11:07 +02:00
|
|
|
if (effect == null) {
|
2018-04-14 05:23:04 +02:00
|
|
|
effect = ParticleEffect.REDSTONE;
|
|
|
|
}
|
2018-03-31 04:22:06 +02:00
|
|
|
|
2014-10-19 23:04:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void perform() {
|
2018-03-29 02:33:10 +02:00
|
|
|
if (seeChunkMap.containsKey(me.getName())) {
|
|
|
|
seeChunkMap.remove(me.getName());
|
|
|
|
msg(TL.COMMAND_SEECHUNK_DISABLED);
|
|
|
|
} else {
|
|
|
|
seeChunkMap.put(me.getName(), true);
|
|
|
|
msg(TL.COMMAND_SEECHUNK_ENABLED);
|
|
|
|
manageTask();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void manageTask() {
|
|
|
|
if (taskID != -1) {
|
|
|
|
if (seeChunkMap.keySet().size() == 0) {
|
|
|
|
Bukkit.getScheduler().cancelTask(taskID);
|
|
|
|
taskID = -1;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
startTask();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void startTask() {
|
|
|
|
taskID = Bukkit.getScheduler().scheduleSyncRepeatingTask(P.p, new Runnable() {
|
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
Iterator itr = seeChunkMap.keySet().iterator();
|
|
|
|
while (itr.hasNext()) {
|
|
|
|
Object nameObject = itr.next();
|
|
|
|
String name = nameObject + "";
|
|
|
|
Player player = Bukkit.getPlayer(name);
|
|
|
|
showBorders(player);
|
|
|
|
}
|
|
|
|
manageTask();
|
|
|
|
}
|
|
|
|
}, 0, interval);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void showBorders(Player me) {
|
2014-10-19 23:04:27 +02:00
|
|
|
World world = me.getWorld();
|
|
|
|
FLocation flocation = new FLocation(me);
|
|
|
|
int chunkX = (int) flocation.getX();
|
|
|
|
int chunkZ = (int) flocation.getZ();
|
|
|
|
|
|
|
|
int blockX;
|
|
|
|
int blockZ;
|
|
|
|
|
2014-11-06 01:36:47 +01:00
|
|
|
blockX = chunkX * 16;
|
|
|
|
blockZ = chunkZ * 16;
|
2014-10-19 23:04:27 +02:00
|
|
|
showPillar(me, world, blockX, blockZ);
|
|
|
|
|
2018-03-31 04:22:06 +02:00
|
|
|
|
2014-11-06 01:36:47 +01:00
|
|
|
blockX = chunkX * 16 + 15;
|
|
|
|
blockZ = chunkZ * 16;
|
2014-10-19 23:04:27 +02:00
|
|
|
showPillar(me, world, blockX, blockZ);
|
|
|
|
|
2014-11-06 01:36:47 +01:00
|
|
|
blockX = chunkX * 16;
|
|
|
|
blockZ = chunkZ * 16 + 15;
|
2014-10-19 23:04:27 +02:00
|
|
|
showPillar(me, world, blockX, blockZ);
|
|
|
|
|
2014-11-06 01:36:47 +01:00
|
|
|
blockX = chunkX * 16 + 15;
|
|
|
|
blockZ = chunkZ * 16 + 15;
|
2014-10-19 23:04:27 +02:00
|
|
|
showPillar(me, world, blockX, blockZ);
|
|
|
|
}
|
|
|
|
|
2018-03-26 23:43:15 +02:00
|
|
|
private void showPillar(Player player, World world, int blockX, int blockZ) {
|
2018-03-29 02:33:10 +02:00
|
|
|
List<Player> onePlayer = Arrays.asList(player);
|
2014-10-20 19:06:47 +02:00
|
|
|
for (int blockY = 0; blockY < player.getLocation().getBlockY() + 30; blockY++) {
|
2018-03-29 02:33:10 +02:00
|
|
|
Location loc = new Location(world, blockX, blockY, blockZ).add(0.5, 0, 0.5);
|
2014-11-06 01:36:47 +01:00
|
|
|
if (loc.getBlock().getType() != Material.AIR) {
|
|
|
|
continue;
|
|
|
|
}
|
2018-03-26 23:43:15 +02:00
|
|
|
if (useParticles) {
|
2018-04-01 16:13:23 +02:00
|
|
|
this.effect.display(0, 0, 0, 0, 1, loc, player);
|
2018-03-26 23:43:15 +02:00
|
|
|
} else {
|
2018-07-28 07:31:58 +02:00
|
|
|
Material type = blockY % 5 == 0 ? Material.LEGACY_REDSTONE_LAMP_ON : Material.LEGACY_STAINED_GLASS;
|
|
|
|
VisualizeUtil.addLocation(player, loc, type);
|
2018-03-26 23:43:15 +02:00
|
|
|
}
|
2014-10-19 23:04:27 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-03-31 04:22:06 +02:00
|
|
|
|
2015-01-22 00:58:33 +01:00
|
|
|
@Override
|
|
|
|
public TL getUsageTranslation() {
|
|
|
|
return TL.GENERIC_PLACEHOLDER;
|
|
|
|
}
|
|
|
|
|
2018-03-26 23:43:15 +02:00
|
|
|
}
|