Added note deletion in tag
This commit is contained in:
29
tag.py
29
tag.py
@@ -1,6 +1,7 @@
|
||||
from helpers import *
|
||||
|
||||
add_perm = "utils.tag.add"
|
||||
del_perm = "utils.tag.del"
|
||||
check_perm = "utils.tag.check"
|
||||
|
||||
data = open_json_file("tag", {})
|
||||
@@ -24,12 +25,34 @@ def command(sender, command, label, args):
|
||||
msg(sender, "&a-&c Usage: /tag check <name>")
|
||||
else:
|
||||
noperm(sender)
|
||||
elif str(args[0]) == "del":
|
||||
if sender.hasPermission(del_perm):
|
||||
if len(args) == 3:
|
||||
delete(sender, args[1:])
|
||||
else:
|
||||
msg(sender, "&a-&c Usage: /tag del <id>")
|
||||
else:
|
||||
msg(sender, "&a-&c Unknown subcommand! (add, check)")
|
||||
msg(sender, "&a-&c Unknown subcommand! (add, check, del)")
|
||||
else:
|
||||
msg(sender, "&a&c Usage: /tag add/check")
|
||||
return True
|
||||
|
||||
def delete(sender, args):
|
||||
player = server.getPlayer(args[0])
|
||||
uuid = uid(player)
|
||||
try:
|
||||
if data[uuid] == None:
|
||||
pass
|
||||
except:
|
||||
msg(sender, "&a-&e There are no notes about this player")
|
||||
return
|
||||
if int(args[1]) - 1 >= len(data[uuid]):
|
||||
msg(sender, "&a-&c Id of note is out of range")
|
||||
return
|
||||
del (data[uuid])[int(args[1]) - 1]
|
||||
save_json_file("tag", data)
|
||||
msg(sender, "&a-&e Deleted note at %s" % args[1])
|
||||
|
||||
def add(sender, args):
|
||||
player = server.getPlayer(args[0])
|
||||
uuid = uid(player)
|
||||
@@ -46,8 +69,10 @@ def check(sender, args):
|
||||
player = server.getPlayer(args[0])
|
||||
uuid = uid(player)
|
||||
try:
|
||||
num = 0
|
||||
for tag in data[uuid]:
|
||||
msg(sender, "&a-&e %s" % str(tag))
|
||||
num += 1
|
||||
msg(sender, "&a-&e %s: %s" % (str(num), str(tag)))
|
||||
except:
|
||||
msg(sender, "&a-&e There are no notes about this player")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user