Fix survival use of /signalstrength, other interesting changes

This commit is contained in:
Dico200
2015-11-03 19:05:15 +01:00
parent 93ca9e0456
commit aa86881f5e
4 changed files with 84 additions and 14 deletions

View File

@@ -181,6 +181,16 @@ def is_creative(player):
return str(player.getGameMode()) == "CREATIVE" return str(player.getGameMode()) == "CREATIVE"
def is_rank(player, rank):
"""
rank: a string equal to the PEX group name found in /pex groups
returns True if one of the following conditions are met:
- the player is of the given rank,
- their rank inherits the given rank.
"""
return player.hasPermission("groups." + rank)
def uid(player): def uid(player):
""" """
returns the player's UUID returns the player's UUID

View File

@@ -7,6 +7,7 @@ import thread
import org.bukkit.inventory.ItemStack as ItemStack import org.bukkit.inventory.ItemStack as ItemStack
import org.bukkit.Bukkit as Bukkit import org.bukkit.Bukkit as Bukkit
from basecommands import simplecommand, Validate from basecommands import simplecommand, Validate
import java.util.Arrays as Arrays
@@ -161,7 +162,8 @@ def on_pluginversions_command(sender, command, label, args):
""" """
try: try:
plugin_header(sender, "Plugin versions") plugin_header(sender, "Plugin versions")
plugins = [pl.getDescription() for pl in list(ArrayList(java_array_to_list(server.getPluginManager().getPlugins())))] raw_plugins = server.getPluginManager().getPlugins() # Plugin[]
plugins = [raw_plugins[i].getDescription() for i in range(len(raw_plugins))]
info(type(plugins[0]).__name__) info(type(plugins[0]).__name__)
plugins.sort(key = lambda pl: pl.getDescription().getName()) plugins.sort(key = lambda pl: pl.getDescription().getName())
msg(sender, "&3Listing all " + str(len(plugins)) + " plugins and their version:") msg(sender, "&3Listing all " + str(len(plugins)) + " plugins and their version:")

View File

@@ -109,6 +109,11 @@ def get_entire_container(container):
helpSubcmd = True, helpSubcmd = True,
senderLimit = 0) senderLimit = 0)
def on_signalstrength_command(sender, command, label, args): def on_signalstrength_command(sender, command, label, args):
#Sender has to be in creative and if in Trusted world, they have to be Trusted+. Any ranks above trusted inherit groups.trusted.
if (not is_creative(sender)) or (sender.getWorld().getName() == "Trusted" and not is_rank(sender, "trusted")):
return "&cYou do not have permission to use that command in this world"
if len(args) > 0 and args[0].lower() in ("default", "defaults", "setdefaults"): if len(args) > 0 and args[0].lower() in ("default", "defaults", "setdefaults"):
strength, item_type, item_data = get_data(sender, args[1:]) strength, item_type, item_data = get_data(sender, args[1:])

View File

@@ -3,6 +3,14 @@ from secrets import *
import mysqlhack import mysqlhack
from com.ziclix.python.sql import zxJDBC from com.ziclix.python.sql import zxJDBC
"""
WORK IN PROGRESS
"""
#-----------------------Config--------------------------
config_file = "website-roles"
ranks = { ranks = {
"member" : 3, "member" : 3,
"builder" : 7, "builder" : 7,
@@ -13,31 +21,41 @@ ranks = {
"admin" : 5 "admin" : 5
} }
ranks = open_json_file(config_file, ranks)
def save_ranks():
save_json_file(config_file, ranks)
#-----------------------Event---------------------------
@hook.event("player.PlayerJoinEvent", "normal") @hook.event("player.PlayerJoinEvent", "normal")
def on_player_join(event): def on_player_join(event):
user = event.getPlayer() user = event.getPlayer()
uuid = uid(player).replace("-", "") uuid = uid(player).replace("-", "")
role = get_role(uuid)
if role in [1, 2, 6]: #Disabled/Banned/Superadmin sql_instruction
return
if role != None: def callback_thing(role, args):
for rank in ranks:
if user.hasPermission("group." + rank): if role in [1, 2, 6]: #Disabled/Banned/Superadmin
if role != ranks[rank]: return
set_role(uuid, ranks[rank]) if role != None:
elif user.hasPlayedBefore(): for rank in ranks:
msg(user, "&cYou haven't registed yet! Make sure to do so on redstoner.com") if user.hasPermission("group." + rank):
if role != ranks[rank]:
set_role(uuid, ranks[rank])
elif user.hasPlayedBefore():
msg(user, "&cYou haven't registed yet! Make sure to do so on redstoner.com")
def get_role(uuid): def get_role(uuid):
results = execute_query("SELECT `role_id` FROM users WHERE `uuid` = ? LIMIT 1", uuid) results = execute_query("SELECT `role_id` FROM users WHERE `uuid` = ? LIMIT 1;", uuid)
return results[0][0] return results[0][0]
# Returns a table with 1 row (LIMIT 1) and 1 column (SELECT `role_id`), so we're looking for the first row of the first column. # Returns a table with 1 row (LIMIT 1) and 1 column (SELECT `role_id`), so we're looking for the first row of the first column.
def set_role(uuid, role_id): def set_role(uuid, role_id):
execute_update(("UPDATE users SET `role_id` = %d WHERE `uuid` = ?" % role_id), uuid) execute_update("UPDATE users SET `role_id` = ? WHERE `uuid` = ?;", (role_id, uuid,))
# %d is like %s for integers (unlogically, you'd expect something like %i), though %s also works here. # %d is like %s for integers (unlogically, you'd expect something like %i), though %s also works here.
@@ -55,5 +73,40 @@ def execute_update(update, uuid):
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()
curs.execute(update, (uuid,)) curs.execute(update, (uuid,))
conn.commit()
curs.close() curs.close()
conn.close() conn.close()
def get_role(uuid):
sql_instruction()
#--------------------------------Queries / Updates----------------------------
def sql_instruction(instruction, args, fetch = True, callback_func = ignored_func, callback_args = tuple()):
thread = threading.Thread(target = curs_instruction, args = (instruction_executor, instruction, fetch, callback_func, callback_args))
thread.start()
def curs_instruction(func, instruction, fetch, callback_func, callback_args):
conn = zxJDBC.connect(mysql_database, mysql_user, mysql_pass, "com.mysql.jdbc.Driver")
curs = conn.getCursor()
if fetch:
returned = func(curs, instruction, fetch)
curs.close()
conn.close()
callback_func(returned, callback_args)
else:
func(curs, instruction, fetch)
conn.commit()
curs.close()
conn.close()
def instruction_executor(curs, instruction, fetch):
curs.execute(instruction)
return curs.fetchall() if fetch else None
def ignored_func(*args):
pass