Archived
0

Minor code cleanup

This commit is contained in:
David
2019-01-03 17:00:58 +01:00
parent 1465818ef8
commit 78c9bdfbda

View File

@@ -1,81 +1,68 @@
package com.redstoner.modules.lagchunks; 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;
import com.nemez.cmdmgr.Command.AsyncType; import com.nemez.cmdmgr.Command.AsyncType;
import com.redstoner.annotations.Commands; import com.redstoner.annotations.Commands;
import com.redstoner.annotations.Version; import com.redstoner.annotations.Version;
import com.redstoner.misc.CommandHolderType; import com.redstoner.misc.CommandHolderType;
import com.redstoner.modules.Module; import com.redstoner.modules.Module;
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;
@Commands(CommandHolderType.File) import java.util.ArrayList;
@Version(major = 5, minor = 0, revision = 0, compatible = 4) import java.util.List;
public class LagChunks implements Module
{ @Commands (CommandHolderType.File)
private List<LaggyChunk> laggyChunks = new ArrayList<LaggyChunk>(); @Version (major = 5, minor = 0, revision = 0, compatible = 4)
public class LagChunks implements Module {
private void scan(int amount) private List<LaggyChunk> laggyChunks = new ArrayList<>();
{
private void scan(int amount) {
laggyChunks.clear(); laggyChunks.clear();
for (World world : Bukkit.getServer().getWorlds())
{ for (World world : Bukkit.getServer().getWorlds()) {
for (Chunk chunk : world.getLoadedChunks()) for (Chunk chunk : world.getLoadedChunks()) {
{ if (chunk.getEntities().length > amount) {
if (chunk.getEntities().length > amount)
{
Location entLoc = chunk.getEntities()[0].getLocation(); Location entLoc = chunk.getEntities()[0].getLocation();
laggyChunks.add(new LaggyChunk(entLoc.getBlockX(), entLoc.getBlockY(), entLoc.getBlockZ(), world, laggyChunks.add(new LaggyChunk(entLoc.getBlockX(), entLoc.getBlockY(), entLoc.getBlockZ(), world,
chunk.getEntities().length)); chunk.getEntities().length
));
} }
} }
} }
} }
@Command(hook = "list_cmd") @Command (hook = "list_cmd")
public void list(CommandSender sender) public void list(CommandSender sender) {
{ if (laggyChunks.size() > 0) {
if (laggyChunks.size() > 0) ArrayList<String> message = new ArrayList<>();
{ for (LaggyChunk lc : laggyChunks) {
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 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"); + " §7(" + lc.world.getName() + ") §a- §b" + lc.amount + " entities");
} }
message.add("§2-------------------"); message.add("§2-------------------");
getLogger().message(sender, message.toArray(new String[] {})); getLogger().message(sender, message.toArray(new String[] {}));
} } else
else
getLogger().message(sender, true, "Couldn't find any chunks with that many entities."); getLogger().message(sender, true, "Couldn't find any chunks with that many entities.");
} }
@Command(hook = "scan_cmd", async = AsyncType.ALWAYS) @Command (hook = "scan_cmd", async = AsyncType.ALWAYS)
public void scan_cmd(CommandSender sender, int amount) public void scan_cmd(CommandSender sender, int amount) {
{
scan(amount); scan(amount);
list(sender); list(sender);
} }
@Command(hook = "tp") @Command (hook = "tp")
public void tp(CommandSender sender, int number) public void tp(CommandSender sender, int number) {
{
Player player = (Player) sender; Player player = (Player) sender;
if (number < laggyChunks.size()) if (number < laggyChunks.size()) {
{
player.teleport(laggyChunks.get(number).getLocation()); player.teleport(laggyChunks.get(number).getLocation());
getLogger().message(player, "§aTeleported to chunk " + number + "!"); getLogger().message(player, "§aTeleported to chunk " + number + "!");
} } else {
else
{
getLogger().message(sender, true, "§4Invalid chunk number! Use §e/lc list §4to show laggy chunks!"); getLogger().message(sender, true, "§4Invalid chunk number! Use §e/lc list §4to show laggy chunks!");
} }
} }