This commit is contained in:
PixelSergey
2015-10-31 19:36:05 +02:00
7 changed files with 34 additions and 19 deletions

View File

@@ -87,7 +87,7 @@ def colorify(text):
"""
replace &-codes with real color codes
"""
return sub("&(?=[?\\da-fk-or])", u"\u00A7", "%s" % text)
return sub("&" + u"\u00A7", "&", "%s" % sub("&(?=[?\\da-fk-or])", u"\u00A7", "%s" % text))
def stripcolors(text):

View File

@@ -5,24 +5,31 @@ from java.util import UUID as UUID
from helpers import *
from org.bukkit import *
from traceback import format_exc as trace
from iptracker_secrets import *
iptrack_permission = "utils.iptrack"
@hook.event("player.PlayerJoinEvent", "low")
def on_player_join(event):
t = threading.Thread(target=on_player_join_thread, args=(event))
t.daemon = True
t.start()
def on_player_join_thread(event):
player = event.getPlayer()
ip = player.getAddress().getHostString()
uuid = uid(player)
conn = zxJDBC.connect(mysql_database, mysql_user, mysql_pass, "com.mysql.jdbc.Driver")
curs = conn.cursor()
curs.execute("SELECT ips FROM iptrack_uuidtoips WHERE uuid = ?", (uuid, ))
curs.execute("SELECT ips FROM uuid2ips WHERE uuid = ?", (uuid, ))
results = curs.fetchall()
if len(results) == 0:
ips = []
else:
ips = json.loads(results[0][0])
curs.execute("SELECT uuids FROM iptrack_iptouuids WHERE ip = ?", (ip, ))
curs.execute("SELECT uuids FROM ip2uuids WHERE ip = ?", (ip, ))
results = curs.fetchall()
if len(results) == 0:
uuids = []
@@ -33,15 +40,15 @@ def on_player_join(event):
if ip not in ips:
ips.append(ip)
if new_ip_entry:
curs.execute("INSERT INTO iptrack_uuidtoips VALUES (?,?)", (uuid, json.dumps(ips), ))
curs.execute("INSERT INTO uuid2ips VALUES (?,?)", (uuid, json.dumps(ips), ))
else:
curs.execute("UPDATE iptrack_uuidtoips SET ips = ? WHERE uuid = ?", (uuid, json.dumps(ips), ))
curs.execute("UPDATE uuid2ips SET ips = ? WHERE uuid = ?", (uuid, json.dumps(ips), ))
if uuid not in uuids:
uuids.append(uuid)
if new_uuid_entry:
curs.execute("INSERT INTO iptrack_iptouuids VALUES (?,?)", (ip, json.dumps(uuids), ))
curs.execute("INSERT INTO ip2uuids VALUES (?,?)", (ip, json.dumps(uuids), ))
else:
curs.execute("UPDATE iptrack_iptouuids SET uuids = ? WHERE uuid = ?", (ip, json.dumps(uuids), ))
curs.execute("UPDATE ip2uuids SET uuids = ? WHERE uuid = ?", (ip, json.dumps(uuids), ))
conn.commit()
curs.close()
conn.close()
@@ -49,14 +56,19 @@ def on_player_join(event):
@hook.command("getinfo")
def on_getinfo_command(sender, args):
t = threading.Thread(target=on_player_join_thread, args=(sender, args))
t.daemon = True
t.start()
def on_getinfo_command_thread(sender, args):
if(sender.hasPermission(iptrack_permission)):
if not checkargs(sender, args, 1, 1):
return false
return False
else:
if isIP(args[0]):
conn = zxJDBC.connect(mysql_database, mysql_user, mysql_pass, "com.mysql.jdbc.Driver")
curs = conn.cursor()
curs.execute("SELECT uuids FROM iptrack_iptouuids WHERE ip = ?", (args[0], ))
curs.execute("SELECT uuids FROM ip2uuids WHERE ip = ?", (args[0], ))
results = curs.fetchall()
curs.close()
conn.close()
@@ -76,7 +88,7 @@ def on_getinfo_command(sender, args):
uuid = target.getUniqueId()
conn = zxJDBC.connect(mysql_database, mysql_user, mysql_pass, "com.mysql.jdbc.Driver")
curs = conn.cursor()
curs.execute("SELECT ips FROM iptrack_uuidtoips WHERE uuid = ?", (uuid.toString(), ))
curs.execute("SELECT ips FROM uuid2ips WHERE uuid = ?", (uuid.toString(), ))
results = curs.fetchall()
curs.close()
conn.close()

View File

@@ -97,7 +97,9 @@ shared["load_modules"] = [
# obisidian mining punishment plugin
"punishments",
# a simple replacement for the buggy essentials /vanish
"vanish"
"vanish",
# ip-tracking utility
"iptracker"
]
shared["modules"] = {}
for module in shared["load_modules"]:

View File

@@ -4,7 +4,7 @@ from traceback import format_exc as print_traceback
mentions = open_json_file("mentio", {}) # contains a list of keywords for each player (uuid)
max_amount = -1
max_amount = 1000
arrow = colorify(u"&r&7\u2192&r")
colors_reg = reg_compile(u"\u00A7[\\da-fk-or]") # finds color codes

View File

@@ -98,7 +98,7 @@ def command(sender, cmd, label, args):
msg(sender, "&e-&a There are no people mining obsidian")
return True
for slave in slaves:
msg(sender, "&e-&a %s: %s blocks" % (slave.get_uuid(), slave.get_blocks()))
msg(sender, "&e-&a %s: %s blocks" % (server.getOfflinePlayer(juuid(slave.get_uuid())).getName(), slave.get_blocks()))
return True
elif args[0] == "add":
player = server.getOfflinePlayer(str(args[1]))
@@ -106,6 +106,7 @@ def command(sender, cmd, label, args):
player.teleport(server.getWorld(punish_world).getSpawnLocation())
Slave(False, player, int(args[2]))
save_slaves()
msg(player, "&e-&a You have been punished, mine %s blocks of obsidian to get out!" % args[2])
msg(sender, "&e-&a Player %s has been added into punishments for %s blocks of obsidian" % (player.getName(), args[2]))
else:
msg(sender, "&cYou can only punish online players")

View File

@@ -93,7 +93,7 @@ def get_entire_container(container):
world.getBlockAt(x - 1, y, z),
world.getBlockAt(x, y, z + 1),
world.getBlockAt(x, y, z - 1),
) if block.getType() == target_type
) if block.getType() == container_type
]
return container_blocks
@@ -101,7 +101,7 @@ def get_entire_container(container):
@simplecommand("signalstrength",
usage = "(<signal strength> [item] [data]) or (default <item> [data])",
usage = "(default) [signalstrength] [item] [data]",
aliases = ["ss", "level"],
description = "Fills the targeted container with the correct amount of items to achieve the desired signal strength.",
amin = 0,

8
tag.py
View File

@@ -34,11 +34,11 @@ def command(sender, command, label, args):
else:
msg(sender, "&a-&c Unknown subcommand! (add, check, del)")
else:
msg(sender, "&a&c Usage: /tag add/check")
msg(sender, "&a&c Usage: /tag add/check/del")
return True
def delete(sender, args):
player = server.getPlayer(args[0])
player = server.getOfflinePlayer(args[0])
uuid = uid(player)
try:
if data[uuid] == None:
@@ -54,7 +54,7 @@ def delete(sender, args):
msg(sender, "&a-&e Deleted note at %s" % args[1])
def add(sender, args):
player = server.getPlayer(args[0])
player = server.getOfflinePlayer(args[0])
uuid = uid(player)
try:
if data[uuid] == None:
@@ -66,7 +66,7 @@ def add(sender, args):
save_json_file("tag", data)
def check(sender, args):
player = server.getPlayer(args[0])
player = server.getOfflinePlayer(args[0])
uuid = uid(player)
try:
num = 0