This repository has been archived on 2024-08-27. You can view files and clone it, but cannot push or open issues or pull requests.
redstoner-utils/lagchunks.py
Dico200 1750c82208 Changed all CommandExecutor arguments
Added arguments command and label to all command executor functions,
hopefully for massive performance increase.

This is due to the following mess in PythonLoader:
``` Java
@Override
public boolean onCommand(CommandSender sender, Command command, String
label, String[] args) {
boolean result;
if (argcount == -1) {
try {
result = call(4, sender, command, label, args);
argcount = 4;
} catch (PyException e) {
//this could goof up someone ... they'll probably yell at us and
eventually read this code ... fuck them
if (e.type == Py.TypeError && (e.value.toString().endsWith("takes
exactly 3 arguments (4 given)") || e.value.toString().endsWith("takes
exactly 4 arguments (5 given)"))) {
result = call(3, sender, command, label, args);
argcount = 3;
} else if (e.type == Py.TypeError && (e.value.toString().endsWith("takes
exactly 2 arguments (4 given)") || e.value.toString().endsWith("takes
exactly 3 arguments (5 given)"))) {
result = call(2, sender, command, label, args);
argcount = 2;
} else {
throw e;
}
}
} else {
result = call(argcount, sender, command, label, args);
}
return result;
}
```

Note: Still WIP on reports - I'm working on making it keep solved
reports to fix issue 10
2015-03-19 23:51:33 +01:00

60 lines
2.4 KiB
Python

#pylint: disable = F0401
import org.bukkit as bukkit
from helpers import *
lagchunks = []
def print_help(sender):
msg(sender, " &b/lagchunks <amount> &eList chunks where #entities >= <amount>")
msg(sender, " &b/lagchunks list &eShow list again")
msg(sender, " &b/lagchunks tp <num> &eTeleport to chunk <num> from list")
def scan_chunks(amount):
global lagchunks
chunks = []
for world in bukkit.Bukkit.getServer().getWorlds():
for chunk in world.getLoadedChunks():
if len(chunk.getEntities()) >= amount:
ents = chunk.getEntities()
# [0]world [1]X [2]Y [3]Z [4]amount
chunks.append([chunk.getWorld(), int(ents[-1].getLocation().getX()), int(ents[0].getLocation().getY()), int(ents[0].getLocation().getZ()), len(ents)])
chunks.sort(key = lambda entry: entry[4], reverse = True)
lagchunks = chunks
def list_chunks(sender):
for id, chunk in enumerate(lagchunks):
msg(sender, "&b%s&a: (&b%s&a) %s&7, &a%s &7(%s)" % (id, chunk[4], chunk[1], chunk[3], chunk[0].getName()))
msg(sender, "&2------------------")
def tp_chunk(sender, id):
chunk = lagchunks[id]
safetp(sender, chunk[0], chunk[1], chunk[2], chunk[3])
msg(sender, "&aTeleported to &b%s&a, &b%s&a in &7%s&a with &b%s&a entities nearby." % (chunk[1], chunk[3], chunk[0].getName(), chunk[4]))
@hook.command("lagchunks")
def on_lagchunks_command(sender, command, label, args):
if sender.hasPermission("utils.lagchunks"):
plugin_header(sender, "Lagchunks")
global lagchunks
if len(args) == 1 and args[0].isdigit() and int(args[0]) > 0:
amount = args[0]
msg(sender, "&aChunks with at least &b%s &aentities:" % amount, )
scan_chunks(int(amount))
list_chunks(sender)
elif len(args) == 1 and args[0].lower() == "list":
list_chunks(sender)
elif len(args) == 2 and args[0].lower() == "tp" and args[1].isdigit() and int(args[1]) <= len(lagchunks)-1:
if isinstance(sender, Player):
tp_chunk(sender, int(args[1]))
else:
msg(sender, "&cOnly players can do this!")
else:
print_help(sender)
else:
noperm(sender)
return True