Added LagChunks module
This commit is contained in:
parent
145c3a1b42
commit
bc0144e33e
@ -7,13 +7,14 @@ import com.redstoner.coremods.debugger.Debugger;
|
||||
import com.redstoner.coremods.moduleLoader.ModuleLoader;
|
||||
import com.redstoner.modules.adminchat.Adminchat;
|
||||
import com.redstoner.modules.chatgroups.Chatgroups;
|
||||
import com.redstoner.modules.lagchunks.LagChunks;
|
||||
import com.redstoner.modules.skullclick.SkullClick;
|
||||
import com.redstoner.modules.warn.Warn;
|
||||
|
||||
/** Main class. Duh.
|
||||
*
|
||||
* @author Pepich */
|
||||
@Version(major = 1, minor = 1, revision = 2, compatible = -1)
|
||||
@Version(major = 1, minor = 1, revision = 3, compatible = -1)
|
||||
public class Main extends JavaPlugin
|
||||
{
|
||||
public static JavaPlugin plugin;
|
||||
@ -27,6 +28,7 @@ public class Main extends JavaPlugin
|
||||
// TODO: Add modules (this also loads them if necessary)
|
||||
ModuleLoader.addModule(Adminchat.class);
|
||||
ModuleLoader.addModule(Chatgroups.class);
|
||||
ModuleLoader.addModule(LagChunks.class);
|
||||
ModuleLoader.addModule(SkullClick.class);
|
||||
ModuleLoader.addModule(Warn.class);
|
||||
// And enable them
|
||||
|
125
src/com/redstoner/modules/lagchunks/LagChunks.java
Normal file
125
src/com/redstoner/modules/lagchunks/LagChunks.java
Normal file
@ -0,0 +1,125 @@
|
||||
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.Version;
|
||||
import com.redstoner.misc.Utils;
|
||||
import com.redstoner.modules.Module;
|
||||
|
||||
@Version(major = 1, minor = 0, revision = 0, compatible = 1)
|
||||
public class LagChunks implements Module
|
||||
{
|
||||
private boolean enabled = false;
|
||||
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)
|
||||
{
|
||||
Utils.sendModuleHeader(sender);
|
||||
for (LaggyChunk lc : laggyChunks)
|
||||
{
|
||||
Utils.sendMessage(sender, "", "§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");
|
||||
}
|
||||
Utils.sendMessage(sender, "", "§2-------------------");
|
||||
}
|
||||
else
|
||||
Utils.sendMessage(sender, null, "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());
|
||||
Utils.sendMessage(player, null, "§aTeleported to chunk " + number + "!");
|
||||
}
|
||||
else
|
||||
{
|
||||
Utils.sendErrorMessage(sender, null, "§4Invalid chunk number! Use §e/lc list §4to show laggy chunks!");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean enabled()
|
||||
{
|
||||
return enabled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEnable()
|
||||
{
|
||||
enabled = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDisable()
|
||||
{
|
||||
enabled = false;
|
||||
}
|
||||
|
||||
// @noformat
|
||||
@Override
|
||||
public String getCommandString()
|
||||
{
|
||||
return "command lc {\n" +
|
||||
" perm utils.lagchunks;\n" +
|
||||
" \n" +
|
||||
" list {\n" +
|
||||
" run list_cmd;\n" +
|
||||
" help re-lists already scanned chunks;\n" +
|
||||
" }\n" +
|
||||
" \n" +
|
||||
" [int:amount] {\n" +
|
||||
" run scan_cmd amount;\n" +
|
||||
" help scans for laggy chunks;\n" +
|
||||
" }\n" +
|
||||
" \n" +
|
||||
" tp [int:number] {\n" +
|
||||
" run tp number;\n" +
|
||||
" help teleports to the specified chunk;\n" +
|
||||
" type player;\n" +
|
||||
" }\n" +
|
||||
"}\n" +
|
||||
" ";
|
||||
}
|
||||
// @format
|
||||
}
|
21
src/com/redstoner/modules/lagchunks/LaggyChunk.java
Normal file
21
src/com/redstoner/modules/lagchunks/LaggyChunk.java
Normal file
@ -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);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user