Fixed player subcommand, removed debug outputs #41
63
chatalias.py
63
chatalias.py
@ -11,6 +11,7 @@
|
|||||||
############################################
|
############################################
|
||||||
|
|
||||||
import os
|
import os
|
||||||
|
import mysqlhack
|
||||||
import org.bukkit as bukkit
|
import org.bukkit as bukkit
|
||||||
from org.bukkit import *
|
from org.bukkit import *
|
||||||
from helpers import *
|
from helpers import *
|
||||||
@ -26,6 +27,7 @@ error = colorify("&cUnspecified error")
|
|||||||
commands_per_page = 5
|
commands_per_page = 5
|
||||||
global_aliases = {"./":"/"}
|
global_aliases = {"./":"/"}
|
||||||
data = {}
|
data = {}
|
||||||
|
# DON'T SET THIS TO TRUE! MySQL requestst are NOT ASYNC yet! (And for some reason it doesn't want to store any data ._.)
|
||||||
use_mysql = False
|
use_mysql = False
|
||||||
|
|
||||||
# Permissions:
|
# Permissions:
|
||||||
@ -53,6 +55,7 @@ permission_FINFO = "utils.alias.finfo"
|
|||||||
# CODE #
|
# CODE #
|
||||||
########
|
########
|
||||||
|
|
||||||
|
# OnEnable
|
||||||
enabled = helpers_version in helpers_versions
|
enabled = helpers_version in helpers_versions
|
||||||
if not enabled:
|
if not enabled:
|
||||||
error = colorify("&6Incompatible versions detected (&chelpers.py&6)")
|
error = colorify("&6Incompatible versions detected (&chelpers.py&6)")
|
||||||
@ -83,7 +86,6 @@ def on_alias_command(sender, cmd, label, args):
|
|||||||
return True
|
return True
|
||||||
return subcommands[args[0].lower()](sender, args[1:])
|
return subcommands[args[0].lower()](sender, args[1:])
|
||||||
except:
|
except:
|
||||||
print(trace())
|
|
||||||
return subcommands["help"](sender, "1")
|
return subcommands["help"](sender, "1")
|
||||||
|
|
||||||
|
|
||||||
@ -117,22 +119,19 @@ def help(sender, args):
|
|||||||
for message in to_display:
|
for message in to_display:
|
||||||
msg(sender, message)
|
msg(sender, message)
|
||||||
if page+1 < pages:
|
if page+1 < pages:
|
||||||
msg(sender, colorify("&6To display the next page, type &c/help " + str(page+2)))
|
msg(sender, colorify("&6To display the next page, type &c/alias help " + str(page+2)))
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
@hook.event("player.PlayerJoinEvent", "high")
|
@hook.event("player.PlayerJoinEvent", "high")
|
||||||
def on_join(event):
|
def on_join(event):
|
||||||
try:
|
if enabled:
|
||||||
if enabled:
|
t = threading.Thread(target=load_data, args=(uid(event.getPlayer()), ))
|
||||||
t = threading.Thread(target=load_data, args=(uid(event.getPlayer()), ))
|
t.daemon = True
|
||||||
t.daemon = True
|
t.start()
|
||||||
t.start()
|
else:
|
||||||
else:
|
if event.getPlayer().hasPermission(permission_FINFO):
|
||||||
if event.getPlayer().hasPermission(permission_FINFO):
|
disabled_fallback(event.getPlayer())
|
||||||
disabled_fallback(event.getPlayer())
|
|
||||||
except:
|
|
||||||
print(trace())
|
|
||||||
|
|
||||||
|
|
||||||
@hook.event("player.AsyncPlayerChatEvent", "high")
|
@hook.event("player.AsyncPlayerChatEvent", "high")
|
||||||
@ -156,6 +155,7 @@ def on_player_chat(event):
|
|||||||
except:
|
except:
|
||||||
print(trace())
|
print(trace())
|
||||||
|
|
||||||
|
|
||||||
def hasPerm(player, permission):
|
def hasPerm(player, permission):
|
||||||
return (player.hasPermission(permission)) or (player.hasPermission(permission_ALL))
|
return (player.hasPermission(permission)) or (player.hasPermission(permission_ALL))
|
||||||
|
|
||||||
@ -186,8 +186,13 @@ def add(sender, args):
|
|||||||
|
|
||||||
|
|
||||||
def radd(sender, args):
|
def radd(sender, args):
|
||||||
args = [args[0:1]] + [" ".join([args[2:len(args)-2]])] + [args[len(args)-1]]
|
|
||||||
plugin_header(sender, "Alias")
|
plugin_header(sender, "Alias")
|
||||||
|
args = args[0:2] + [" ".join(args[2:len(args)-1])] + [args[len(args)-1]]
|
||||||
|
if is_player(sender):
|
||||||
|
sender_name = colorify(sender.getDisplayName())
|
||||||
|
else:
|
||||||
|
sender_name = colorify("&6Console")
|
||||||
|
target = get_player(args[0])
|
||||||
if args[3].lower() == "false":
|
if args[3].lower() == "false":
|
||||||
plugin_header(target, "Alias")
|
plugin_header(target, "Alias")
|
||||||
msg(target, "&cPlayer " + sender_name + " &cis creating an alias for you!")
|
msg(target, "&cPlayer " + sender_name + " &cis creating an alias for you!")
|
||||||
@ -196,12 +201,6 @@ def radd(sender, args):
|
|||||||
if args[3].lower() == "false":
|
if args[3].lower() == "false":
|
||||||
msg(target, "&cCould not create alias: Max_limit reached!")
|
msg(target, "&cCould not create alias: Max_limit reached!")
|
||||||
return True
|
return True
|
||||||
|
|
||||||
target = get_player(args[0])
|
|
||||||
if is_player(sender):
|
|
||||||
sender_name = colorify(sender.getDisplayName)
|
|
||||||
else:
|
|
||||||
sender_name = colorify("&6Console")
|
|
||||||
if len(args) == 3:
|
if len(args) == 3:
|
||||||
args += ["true"]
|
args += ["true"]
|
||||||
data[str(uid(target))][str(args[1])] = str(args[2])
|
data[str(uid(target))][str(args[1])] = str(args[2])
|
||||||
@ -226,11 +225,10 @@ def rremove(sender, args):
|
|||||||
plugin_header(sender, "Alias")
|
plugin_header(sender, "Alias")
|
||||||
target = get_player(args[0])
|
target = get_player(args[0])
|
||||||
if is_player(sender):
|
if is_player(sender):
|
||||||
sender_name = colorify(sender.getDisplayName)
|
sender_name = colorify(sender.getDisplayName())
|
||||||
else:
|
else:
|
||||||
sender_name = colorify("&6Console")
|
sender_name = colorify("&6Console")
|
||||||
if args[2].lower() == "false":
|
if args[2].lower() == "false":
|
||||||
print("WTF")
|
|
||||||
plugin_header(target, "Alias")
|
plugin_header(target, "Alias")
|
||||||
msg(target, "&cPlayer " + sender_name + " &cis removing an alias for you!")
|
msg(target, "&cPlayer " + sender_name + " &cis removing an alias for you!")
|
||||||
try:
|
try:
|
||||||
@ -276,13 +274,21 @@ def rlist_alias(sender, args):
|
|||||||
|
|
||||||
def remote(sender, args):
|
def remote(sender, args):
|
||||||
try:
|
try:
|
||||||
return remotes[args[1].lower()](sender, [args[0]] + [args[2:]])
|
return remotes[args[1].lower()](sender, [args[0]] + args[2:])
|
||||||
except:
|
except:
|
||||||
print(trace())
|
|
||||||
return subcommands["help"](sender, ["2"])
|
return subcommands["help"](sender, ["2"])
|
||||||
|
|
||||||
|
|
||||||
def load_data(uuid):
|
def load_data(uuid):
|
||||||
|
try:
|
||||||
|
load_data_thread(uuid)
|
||||||
|
# t = threading.Thread(target=load_data_thread, args=(uuid))
|
||||||
|
# t.daemon = True
|
||||||
|
# t.start()
|
||||||
|
except:
|
||||||
|
print(trace())
|
||||||
|
|
||||||
|
def load_data_thread(uuid):
|
||||||
if use_mysql:
|
if use_mysql:
|
||||||
conn = zxJDBC.connect(mysql_database, mysql_user, mysql_pass, "com.mysql.jdbc.Driver")
|
conn = zxJDBC.connect(mysql_database, mysql_user, mysql_pass, "com.mysql.jdbc.Driver")
|
||||||
curs = conn.cursor()
|
curs = conn.cursor()
|
||||||
@ -297,6 +303,15 @@ def load_data(uuid):
|
|||||||
|
|
||||||
|
|
||||||
def save_data(uuid):
|
def save_data(uuid):
|
||||||
|
try:
|
||||||
|
save_data_thread(uuid)
|
||||||
|
# t = threading.Thread(target=save_data_thread, args=(uuid))
|
||||||
|
# t.daemon = True
|
||||||
|
# t.start()
|
||||||
|
except:
|
||||||
|
print(trace())
|
||||||
|
|
||||||
|
def save_data_thread(uuid):
|
||||||
if use_mysql:
|
if use_mysql:
|
||||||
conn = zxJDBC.connect(mysql_database, mysql_user, mysql_pass, "com.mysql.jdbc.Driver")
|
conn = zxJDBC.connect(mysql_database, mysql_user, mysql_pass, "com.mysql.jdbc.Driver")
|
||||||
curs = conn.cursor()
|
curs = conn.cursor()
|
||||||
@ -304,8 +319,8 @@ def save_data(uuid):
|
|||||||
else:
|
else:
|
||||||
save_json_file("aliases/" + uuid, data[uuid])
|
save_json_file("aliases/" + uuid, data[uuid])
|
||||||
|
|
||||||
# Subcommands:
|
|
||||||
|
|
||||||
|
# Subcommands:
|
||||||
subcommands = {
|
subcommands = {
|
||||||
"help": help,
|
"help": help,
|
||||||
"add": add,
|
"add": add,
|
||||||
|
Reference in New Issue
Block a user