HUGE code cleanup

This commit is contained in:
jomo
2014-06-10 01:31:03 +02:00
parent 3dd467afec
commit cb716abd6b
12 changed files with 316 additions and 313 deletions

View File

@@ -1,10 +1,10 @@
#pylint: disable=F0401
from re import sub
import org.bukkit as bukkit
import org.bukkit.Location as Location
import org.bukkit.entity.Player as Player
import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause as TeleportCause
import org.bukkit.block as block
from java.util.logging import Level
import org.bukkit.block as bblock
server = bukkit.Bukkit.getServer()
@@ -14,7 +14,7 @@ def log(text):
def error(text):
server.getLogger().severe("[RedstonerUtils] %s" % text)
def msg(player, text, usecolor=True, basecolor=None):
def msg(player, text, usecolor = True, basecolor = None):
if player and (player == server.getConsoleSender() or player.getPlayer()): #getPlayer() returns None when offline
if basecolor:
player.sendMessage(colorify("&%s" % basecolor) + (colorify(text) if usecolor else text))
@@ -24,19 +24,16 @@ def msg(player, text, usecolor=True, basecolor=None):
# better than bukkit's broadcast.
# bukkit only works with permissibles that are subscribed to perm
def broadcast(perm, text):
try:
text = colorify(text)
for recipient in server.getOnlinePlayers().tolist() + [server.getConsoleSender()]:
(not perm or recipient.hasPermission(perm)) and msg(recipient, text)
except Exception, e:
error(e)
text = colorify(text)
for recipient in server.getOnlinePlayers().tolist() + [server.getConsoleSender()]:
(not perm or recipient.hasPermission(perm)) and msg(recipient, text)
def colorify(text):
return sub("&(?=[?\da-fk-or])", u"\u00A7", "%s" % text)
return sub("&(?=[?\\da-fk-or])", u"\u00A7", "%s" % text)
def safetp(player, world, x, y, z, yaw=0, pitch=0):
def safetp(player, world, x, y, z, yaw = 0, pitch = 0):
tpblock = Location(world, x, y, z).getBlock()
if (tpblock.isEmpty() and tpblock.getRelative(block.BlockFace.UP).isEmpty()) or y > 255:
if (tpblock.isEmpty() and tpblock.getRelative(bblock.BlockFace.UP).isEmpty()) or y > 255:
player.teleport(Location(world, x+0.5, y, z+0.5, yaw, pitch), TeleportCause.COMMAND)
else:
safetp(player, world, x, y+1, z, yaw, pitch)
@@ -53,16 +50,16 @@ def runas(player, cmd):
def isPlayer(sender):
return (isinstance(sender, Player))
def checkargs(sender, args, min, max):
if not (len(args) >= min and (max < 0 or len(args) <= max)):
if min == max:
msg(sender, "&cNeeds " + str(min) + " arguments!")
def checkargs(sender, args, amin, amax):
if not (len(args) >= amin and (amax < 0 or len(args) <= amax)):
if amin == amax:
msg(sender, "&cNeeds " + str(amin) + " arguments!")
return False
elif max < 0:
msg(sender, "&cNeeds at least " + str(min) + " arguments!")
elif amax < 0:
msg(sender, "&cNeeds at least " + str(amin) + " arguments!")
return False
else:
msg(sender, "&cNeeds " + str(min) + " to " + str(max) + " arguments!")
msg(sender, "&cNeeds " + str(amin) + " to " + str(amax) + " arguments!")
return False
return True