diff options
author | David <david@panic.tk> | 2018-11-07 23:50:06 +0100 |
---|---|---|
committer | David <david@panic.tk> | 2018-11-07 23:50:06 +0100 |
commit | 604cf01967ede98bf5024e4926bb0777fc4e8eee (patch) | |
tree | e2fa63d7e683769ee3bf3eddc75280648e92eb04 /src/main/java/com/redstoner/modules/lagchunks | |
parent | e86c52ef7c0e1e33c6af0e8674b038976bec11cc (diff) |
Converted Modules to gradle
Diffstat (limited to 'src/main/java/com/redstoner/modules/lagchunks')
3 files changed, 122 insertions, 0 deletions
diff --git a/src/main/java/com/redstoner/modules/lagchunks/LagChunks.cmd b/src/main/java/com/redstoner/modules/lagchunks/LagChunks.cmd new file mode 100644 index 0000000..142a437 --- /dev/null +++ b/src/main/java/com/redstoner/modules/lagchunks/LagChunks.cmd @@ -0,0 +1,19 @@ +command lc { + perm utils.lagchunks; + + list { + run list_cmd; + help re-lists already scanned chunks; + } + + [int:amount] { + run scan_cmd amount; + help scans for laggy chunks; + } + + tp [int:number] { + run tp number; + help teleports to the specified chunk; + type player; + } +} diff --git a/src/main/java/com/redstoner/modules/lagchunks/LagChunks.java b/src/main/java/com/redstoner/modules/lagchunks/LagChunks.java new file mode 100644 index 0000000..1debf12 --- /dev/null +++ b/src/main/java/com/redstoner/modules/lagchunks/LagChunks.java @@ -0,0 +1,82 @@ +package com.redstoner.modules.lagchunks; + +import java.util.ArrayList; +import java.util.List; + +import org.bukkit.Bukkit; +import org.bukkit.Chunk; +import org.bukkit.Location; +import org.bukkit.World; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +import com.nemez.cmdmgr.Command; +import com.nemez.cmdmgr.Command.AsyncType; +import com.redstoner.annotations.Commands; +import com.redstoner.annotations.Version; +import com.redstoner.misc.CommandHolderType; +import com.redstoner.modules.Module; + +@Commands(CommandHolderType.File) +@Version(major = 4, minor = 1, revision = 0, compatible = 4) +public class LagChunks implements Module +{ + private List<LaggyChunk> laggyChunks = new ArrayList<LaggyChunk>(); + + private void scan(int amount) + { + laggyChunks.clear(); + for (World world : Bukkit.getServer().getWorlds()) + { + for (Chunk chunk : world.getLoadedChunks()) + { + if (chunk.getEntities().length > amount) + { + Location entLoc = chunk.getEntities()[0].getLocation(); + laggyChunks.add(new LaggyChunk(entLoc.getBlockX(), entLoc.getBlockY(), entLoc.getBlockZ(), world, + chunk.getEntities().length)); + } + } + } + } + + @Command(hook = "list_cmd") + public void list(CommandSender sender) + { + if (laggyChunks.size() > 0) + { + ArrayList<String> message = new ArrayList<String>(); + for (LaggyChunk lc : laggyChunks) + { + message.add("§b[§a" + laggyChunks.indexOf(lc) + "§b]: §a" + lc.x + "§7, §a" + lc.y + "§7, §a" + lc.z + + " §7(" + lc.world.getName() + ") §a- §b" + lc.amount + " entities"); + } + message.add("§2-------------------"); + getLogger().message(sender, message.toArray(new String[] {})); + } + else + getLogger().message(sender, true, "Couldn't find any chunks with that many entities."); + } + + @Command(hook = "scan_cmd", async = AsyncType.ALWAYS) + public void scan_cmd(CommandSender sender, int amount) + { + scan(amount); + list(sender); + } + + @Command(hook = "tp") + public void tp(CommandSender sender, int number) + { + Player player = (Player) sender; + if (number < laggyChunks.size()) + { + player.teleport(laggyChunks.get(number).getLocation()); + getLogger().message(player, "§aTeleported to chunk " + number + "!"); + } + else + { + getLogger().message(sender, true, "§4Invalid chunk number! Use §e/lc list §4to show laggy chunks!"); + } + } +} diff --git a/src/main/java/com/redstoner/modules/lagchunks/LaggyChunk.java b/src/main/java/com/redstoner/modules/lagchunks/LaggyChunk.java new file mode 100644 index 0000000..3ff4d6f --- /dev/null +++ b/src/main/java/com/redstoner/modules/lagchunks/LaggyChunk.java @@ -0,0 +1,21 @@ +package com.redstoner.modules.lagchunks; + +import org.bukkit.Location; +import org.bukkit.World; + +public class LaggyChunk { + public final int x, y, z, amount; + public final World world; + + public LaggyChunk(int x, int y, int z, World world, int amount) { + this.x = x; + this.y = y; + this.z = z; + this.world = world; + this.amount = amount; + } + + public Location getLocation() { + return new Location(world, x, y, z); + } +} |