Compare commits
100 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
347f6969bf | ||
|
|
6e497a2662 | ||
|
|
94accc238a | ||
|
|
2b803e8de8 | ||
|
|
f02fd2aae5 | ||
|
|
f6cb9ade9d | ||
|
|
fd368a8aac | ||
|
|
a2daa5c0b6 | ||
|
|
5da7180bfd | ||
|
|
ae44dade80 | ||
|
|
5788cd0b3e | ||
|
|
bfcb22f650 | ||
|
|
00e936532a | ||
|
|
1602ad2185 | ||
|
|
cebdb90d60 | ||
|
|
6320d78a37 | ||
|
|
47a0a92225 | ||
|
|
a6ea05a459 | ||
|
|
f5c51645d2 | ||
|
|
8e2ff33dbb | ||
|
|
2c94c40c77 | ||
|
|
2f943e8b12 | ||
|
|
0aa18e9945 | ||
|
|
13606638b7 | ||
|
|
57603725d2 | ||
|
|
f0f32abbfa | ||
|
|
83e7505565 | ||
|
|
f0ada788bf | ||
|
|
5d00af8ced | ||
|
|
1e34a9b39b | ||
|
|
6f4357fad7 | ||
|
|
fe2d6eb701 | ||
|
|
ae706e8e12 | ||
|
|
edf5fa6d32 | ||
|
|
5d3530242e | ||
|
|
c7d872c93b | ||
|
|
e46bea31c8 | ||
|
|
6539c34a82 | ||
|
|
d00301ccc3 | ||
|
|
4e4acc6b3d | ||
|
|
9d1956dc2a | ||
|
|
e08666995c | ||
|
|
765fa76cb7 | ||
|
|
1da9aa2578 | ||
|
|
20b33588e7 | ||
|
|
d66e8f3294 | ||
|
|
1fb6e08d42 | ||
|
|
ba78151e49 | ||
|
|
c78d0f651b | ||
|
|
fa03a68963 | ||
|
|
fe32e7a49c | ||
|
|
361da9e049 | ||
|
|
33d8fd2f08 | ||
|
|
a0a7d43a38 | ||
|
|
8e4f30a017 | ||
|
|
5a757b7fb1 | ||
|
|
e35fadc353 | ||
|
|
860c844d6c | ||
|
|
c3189639f0 | ||
|
|
c534d9316a | ||
|
|
7da3fd5b71 | ||
|
|
a19f0b5bdc | ||
|
|
28ac05ce0a | ||
|
|
e60e124324 | ||
|
|
cab575937d | ||
|
|
7a905643eb | ||
|
|
3859ad8e40 | ||
|
|
89e3982a29 | ||
|
|
28afa1ddcf | ||
|
|
8629b39ce1 | ||
|
|
00e38efd14 | ||
|
|
a532c6b42c | ||
|
|
1fdf97f77a | ||
|
|
16e78a2677 | ||
|
|
2d6725df73 | ||
|
|
d88baa4899 | ||
|
|
29f846c8f9 | ||
|
|
a2a43ed464 | ||
|
|
5592e16200 | ||
|
|
9a1006e711 | ||
|
|
29e7ce174b | ||
|
|
8165d5977b | ||
|
|
fca3cf250c | ||
|
|
7fdaee155a | ||
|
|
4e6bd44c38 | ||
|
|
a555676076 | ||
|
|
cb1a333a56 | ||
|
|
07039b3d16 | ||
|
|
48251e1e52 | ||
|
|
fa1d5e900d | ||
|
|
622971c41c | ||
|
|
d81d17b5f2 | ||
|
|
c870561f7d | ||
|
|
286f8751b5 | ||
|
|
fad1ae0f90 | ||
|
|
621f4ca23b | ||
|
|
f2dfc6c473 | ||
|
|
612b86c50b | ||
|
|
7775e37a65 | ||
|
|
b4c4857761 |
@@ -9,7 +9,7 @@ import org.bukkit.inventory.ItemStack as ItemStack
|
|||||||
import org.bukkit.Material as Material
|
import org.bukkit.Material as Material
|
||||||
import org.bukkit.event.block.Action as Action
|
import org.bukkit.event.block.Action as Action
|
||||||
import org.bukkit.block.BlockFace as BlockFace
|
import org.bukkit.block.BlockFace as BlockFace
|
||||||
import org.bukkit.scheduler.BukkitRunnable as Runnable
|
import org.bukkit.scheduler.BukkitRunnable as BukkitRunnable
|
||||||
|
|
||||||
"""
|
"""
|
||||||
# Permissions:
|
# Permissions:
|
||||||
@@ -38,11 +38,11 @@ settingInformation = dict( #[setting type, identifying description, detailed des
|
|||||||
"Sets your preferred default furnace contents to your currently held itemstack. Use an empty hand to empty a slot, or /toggle furnace clear to clear all slots.",
|
"Sets your preferred default furnace contents to your currently held itemstack. Use an empty hand to empty a slot, or /toggle furnace clear to clear all slots.",
|
||||||
["cooker", "fillf"], 2
|
["cooker", "fillf"], 2
|
||||||
],
|
],
|
||||||
#torch = [0,
|
torch = [0,
|
||||||
# "removal of torches you place on redstone blocks",
|
"removal of torches you place on redstone blocks",
|
||||||
# "Toggles whether redstone torches which you place on redstone blocks will be deleted after a short amount of delay.",
|
"Toggles whether redstone torches which you place on redstone blocks will be deleted after a short amount of delay.",
|
||||||
# ["redstonetorch", "tor"]
|
["redstonetorch", "tor"]
|
||||||
#],
|
],
|
||||||
piston = [2,
|
piston = [2,
|
||||||
"rotating pistons, droppers and hoppers to face the block you place them against",
|
"rotating pistons, droppers and hoppers to face the block you place them against",
|
||||||
"Toggles whether pistons or sticky pistons which you place will be rotated to face the block which you placed them against.",
|
"Toggles whether pistons or sticky pistons which you place will be rotated to face the block which you placed them against.",
|
||||||
@@ -66,7 +66,7 @@ defaults = {
|
|||||||
2: list
|
2: list
|
||||||
}
|
}
|
||||||
|
|
||||||
faces = {
|
piston_faces = {
|
||||||
BlockFace.DOWN : 0,
|
BlockFace.DOWN : 0,
|
||||||
BlockFace.UP : 1,
|
BlockFace.UP : 1,
|
||||||
BlockFace.NORTH : 2,
|
BlockFace.NORTH : 2,
|
||||||
@@ -75,6 +75,14 @@ faces = {
|
|||||||
BlockFace.EAST : 5
|
BlockFace.EAST : 5
|
||||||
}
|
}
|
||||||
|
|
||||||
|
torch_faces = {
|
||||||
|
1: BlockFace.WEST,
|
||||||
|
2: BlockFace.EAST,
|
||||||
|
3: BlockFace.NORTH,
|
||||||
|
4: BlockFace.SOUTH,
|
||||||
|
5: BlockFace.DOWN
|
||||||
|
}
|
||||||
|
|
||||||
playerSettings = open_json_file("blockplacemods", {})
|
playerSettings = open_json_file("blockplacemods", {})
|
||||||
|
|
||||||
for setting, details in settingInformation.iteritems():
|
for setting, details in settingInformation.iteritems():
|
||||||
@@ -128,14 +136,14 @@ def toggle_command(sender, command, label, args):
|
|||||||
elif arg2 in ("toggle", "switch"):
|
elif arg2 in ("toggle", "switch"):
|
||||||
new = not enabled
|
new = not enabled
|
||||||
elif arg2 in ("on", "enable"):
|
elif arg2 in ("on", "enable"):
|
||||||
new = not default
|
new = True
|
||||||
elif arg2 in ("off", "disable"):
|
elif arg2 in ("off", "disable"):
|
||||||
new = default
|
new = False
|
||||||
else:
|
else:
|
||||||
return " &cArgument '%s' was not recognized. \n Use &o/toggle %s info &cfor more information" % (arg2, setting)
|
return " &cArgument '%s' was not recognized. \n Use &o/toggle %s info &cfor more information" % (arg2, setting)
|
||||||
if enabled == new:
|
if enabled is new:
|
||||||
return " &cAlready %s: &a%s" % ("enabled" if enabled else "disabled", details[1])
|
return " &cAlready %s: &a%s" % ("enabled" if enabled else "disabled", details[1])
|
||||||
if new == default:
|
if new is default:
|
||||||
values.remove(uuid)
|
values.remove(uuid)
|
||||||
else:
|
else:
|
||||||
values.append(uuid)
|
values.append(uuid)
|
||||||
@@ -150,9 +158,11 @@ def toggle_command(sender, command, label, args):
|
|||||||
if arg2 == "clear":
|
if arg2 == "clear":
|
||||||
if enabled:
|
if enabled:
|
||||||
del values[uuid]
|
del values[uuid]
|
||||||
return " &aDisabled " + details[1]
|
saveSettings()
|
||||||
|
return " &aDisabled " + details[1]
|
||||||
|
return " &cAlready disabled: " + details[1]
|
||||||
|
|
||||||
if arg2 == "details":
|
if arg2 == "info":
|
||||||
return " &aSetting %s:\n &9%s \n&6Accepted arguments: [<slot>|clear|details]" % (setting, details[2])
|
return " &aSetting %s:\n &9%s \n&6Accepted arguments: [<slot>|clear|details]" % (setting, details[2])
|
||||||
|
|
||||||
slot = int(arg2) if arg2.isdigit() else 0
|
slot = int(arg2) if arg2.isdigit() else 0
|
||||||
@@ -165,16 +175,17 @@ def toggle_command(sender, command, label, args):
|
|||||||
items = values[uuid]
|
items = values[uuid]
|
||||||
if slot in items:
|
if slot in items:
|
||||||
del items[slot]
|
del items[slot]
|
||||||
saveSettings()
|
|
||||||
if len(items) == 0:
|
if len(items) == 0:
|
||||||
del items
|
del items
|
||||||
|
saveSettings()
|
||||||
return " &aDisabled " + details[1]
|
return " &aDisabled " + details[1]
|
||||||
|
saveSettings()
|
||||||
return " &aCleared slot %s of setting %s" % (slot, setting)
|
return " &aCleared slot %s of setting %s" % (slot, setting)
|
||||||
return " &cSlot %s of setting %s was already cleared!" % (slot, setting)
|
return " &cSlot %s of setting %s was already cleared!" % (slot, setting)
|
||||||
return " &cAlready disabled: " + details[1]
|
return " &cAlready disabled: " + details[1]
|
||||||
|
|
||||||
if arglen == 2 and not arg2.isdigit():
|
if arglen == 2 and not arg2.isdigit():
|
||||||
return " &cArgument '%s' was not recognized. \nUse &o/toggle %s details &cfor more detailsrmation." % (arg2, setting)
|
return " &cArgument '%s' was not recognized. \nUse &o/toggle %s info &cfor more information." % (arg2, setting)
|
||||||
|
|
||||||
if not enabled:
|
if not enabled:
|
||||||
values[uuid] = {}
|
values[uuid] = {}
|
||||||
@@ -197,59 +208,63 @@ def isEnabled(toggleSetting, uuid):
|
|||||||
|
|
||||||
@hook.event("block.BlockPlaceEvent", "monitor")
|
@hook.event("block.BlockPlaceEvent", "monitor")
|
||||||
def on_block_place(event):
|
def on_block_place(event):
|
||||||
if event.isCancelled():
|
try:
|
||||||
return
|
|
||||||
player = event.getPlayer()
|
|
||||||
if not is_creative(player):
|
|
||||||
return
|
|
||||||
|
|
||||||
uuid = uid(player)
|
if event.isCancelled():
|
||||||
block = event.getBlockPlaced()
|
return
|
||||||
material = block.getType()
|
player = event.getPlayer()
|
||||||
|
if not is_creative(player):
|
||||||
|
return
|
||||||
|
|
||||||
|
uuid = uid(player)
|
||||||
|
block = event.getBlockPlaced()
|
||||||
|
material = block.getType()
|
||||||
|
|
||||||
|
|
||||||
if (material in (Material.WOOD_STEP, Material.STEP)
|
if (material in (Material.WOOD_STEP, Material.STEP)
|
||||||
and isEnabled("slab", uuid)
|
and isEnabled("slab", uuid)
|
||||||
and player.hasPermission("utils.toggle.slab")
|
and player.hasPermission("utils.toggle.slab")
|
||||||
and block.getData() < 8
|
and block.getData() < 8
|
||||||
):
|
):
|
||||||
block.setData(block.getData() + 8) # Flip upside down
|
block.setData(block.getData() + 8) # Flip upside down
|
||||||
|
|
||||||
|
|
||||||
elif (material == Material.CAULDRON
|
elif (material == Material.CAULDRON
|
||||||
and isEnabled("cauldron", uuid)
|
and isEnabled("cauldron", uuid)
|
||||||
and player.hasPermission("utils.toggle.cauldron")
|
and player.hasPermission("utils.toggle.cauldron")
|
||||||
):
|
):
|
||||||
block.setData(3) #3 layers of water, 3 signal strength
|
block.setData(3) #3 layers of water, 3 signal strength
|
||||||
|
|
||||||
|
|
||||||
elif ((material == Material.FURNACE and player.hasPermission("utils.toggle.furnace"))
|
elif ((material == Material.FURNACE and player.hasPermission("utils.toggle.furnace"))
|
||||||
or (material == Material.DROPPER and player.hasPermission("utils.toggle.dropper"))
|
or (material == Material.DROPPER and player.hasPermission("utils.toggle.dropper"))
|
||||||
or (material == Material.HOPPER and player.hasPermission("utils.toggle.hopper"))
|
or (material == Material.HOPPER and player.hasPermission("utils.toggle.hopper"))
|
||||||
):
|
):
|
||||||
stacks = get(str(material).lower()).get(uuid)
|
stacks = get(str(material).lower()).get(uuid)
|
||||||
if stacks != None: # Enabled
|
if stacks != None: # Enabled
|
||||||
state = block.getState()
|
state = block.getState()
|
||||||
inv = state.getInventory()
|
inv = state.getInventory()
|
||||||
for slot, stack in stacks.iteritems():
|
for slot, stack in stacks.iteritems():
|
||||||
inv.setItem(int(slot), toStack(stack))
|
inv.setItem(int(slot), toStack(stack))
|
||||||
state.update()
|
state.update()
|
||||||
|
|
||||||
"""
|
|
||||||
elif (material == Material.REDSTONE_TORCH_ON
|
|
||||||
and event.getBlockAgainst().getType() == Material.REDSTONE_BLOCK
|
|
||||||
and isEnabled("torch", uuid)
|
|
||||||
and player.hasPermission("utils.toggle.torch")
|
|
||||||
):
|
|
||||||
torches_to_break.append(block)
|
|
||||||
"""
|
|
||||||
|
|
||||||
|
|
||||||
if (material in (Material.PISTON_BASE, Material.PISTON_STICKY_BASE)
|
elif (material == Material.REDSTONE_TORCH_ON
|
||||||
and isEnabled("piston", uuid)
|
and isEnabled("torch", uuid)
|
||||||
and player.hasPermission("utils.toggle.piston")
|
and player.hasPermission("utils.toggle.torch")
|
||||||
):
|
and block.getData() in torch_faces
|
||||||
block.setData(faces[block.getFace(event.getBlockAgainst())])
|
and block.getRelative(torch_faces[block.getData()]).getType() is Material.REDSTONE_BLOCK
|
||||||
|
):
|
||||||
|
torches_to_break.append(block)
|
||||||
|
|
||||||
|
|
||||||
|
elif (material in (Material.PISTON_BASE, Material.PISTON_STICKY_BASE)
|
||||||
|
and isEnabled("piston", uuid)
|
||||||
|
and player.hasPermission("utils.toggle.piston")
|
||||||
|
):
|
||||||
|
block.setData(piston_faces[block.getFace(event.getBlockAgainst())])
|
||||||
|
except:
|
||||||
|
error(trace())
|
||||||
|
|
||||||
|
|
||||||
@hook.event("player.PlayerInteractEvent", "monitor")
|
@hook.event("player.PlayerInteractEvent", "monitor")
|
||||||
@@ -268,29 +283,36 @@ def on_interact(event):
|
|||||||
if not event2.isCancelled():
|
if not event2.isCancelled():
|
||||||
block.setData(block.getData() - 1 if block.getData() > 0 else 3)
|
block.setData(block.getData() - 1 if block.getData() > 0 else 3)
|
||||||
|
|
||||||
"""
|
|
||||||
break_torches = True
|
break_torches = True
|
||||||
torches_to_break = deque()
|
torches_to_break = deque()
|
||||||
|
|
||||||
def stop_breaking_torches():
|
def stop_breaking_torches():
|
||||||
break_torches = False
|
break_torches = False
|
||||||
info("Interrupted torch breaking thread")
|
info("[BlockPlaceMods] Interrupted torch breaking thread")
|
||||||
|
|
||||||
|
|
||||||
class torch_breaker(Runnable):
|
class JBukkitRunnable(BukkitRunnable):
|
||||||
|
|
||||||
def run():
|
def __init__(self, func):
|
||||||
|
self.run = func
|
||||||
|
|
||||||
try:
|
|
||||||
if break_torches:
|
def torch_breaker():
|
||||||
for i in range(len(torches_to_break)):
|
|
||||||
block = torches_to_break.popleft()
|
try:
|
||||||
mat = block.getType()
|
if break_torches:
|
||||||
if mat == Material.REDSTONE_TORCH_OFF:
|
for i in range(len(torches_to_break)):
|
||||||
block.setTypeId(0)
|
block = torches_to_break.popleft()
|
||||||
elif mat == Material.REDSTONE_TORCH_ON:
|
mat = block.getType()
|
||||||
|
if mat == Material.REDSTONE_TORCH_OFF:
|
||||||
|
block.setTypeId(0)
|
||||||
|
elif mat == Material.REDSTONE_TORCH_ON:
|
||||||
|
if block.getData() in torch_faces and block.getRelative(torch_faces[block.getData()]).getType() is Material.REDSTONE_BLOCK:
|
||||||
torches_to_break.append(block)
|
torches_to_break.append(block)
|
||||||
except:
|
except:
|
||||||
error(trace())
|
error(trace())
|
||||||
"""
|
|
||||||
|
|
||||||
|
|
||||||
|
def schedule_torch_breaker():
|
||||||
|
JBukkitRunnable(torch_breaker).runTaskTimer(server.getPluginManager().getPlugin("RedstonerUtils"), 0, 1)
|
||||||
|
|||||||
453
chatalias.py
453
chatalias.py
@@ -1,32 +1,22 @@
|
|||||||
############################################
|
# TODO: Add cg/ac/msg support
|
||||||
# Alias v2.0 by Pepich #
|
|
||||||
# Changes to previous version from curs3d: #
|
|
||||||
# Dynamic alias limit from permissions #
|
|
||||||
# AC/CG/MSG support #
|
|
||||||
# Color support #
|
|
||||||
# Bugfixes #
|
|
||||||
# #
|
|
||||||
# TODO: #
|
|
||||||
# Add command support... #
|
|
||||||
############################################
|
|
||||||
|
|
||||||
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 *
|
||||||
from traceback import format_exc as trace
|
|
||||||
from secrets import *
|
|
||||||
|
|
||||||
# Version number and requirements
|
# Version number and requirements
|
||||||
|
|
||||||
alias_version = "2.0.0"
|
alias_version = "2.1.0"
|
||||||
helpers_versions = ["1.1.0", "2.0.0"]
|
helpers_versions = ["1.1.0", "2.0.0"]
|
||||||
enabled = False
|
enabled = False
|
||||||
error = colorify("&cUnspecified error")
|
error_msg = colorify("&cUnspecified error")
|
||||||
commands_per_page = 5
|
commands_per_page = 5
|
||||||
global_aliases = {"./":"/"}
|
global_aliases = {"./":"/"}
|
||||||
data = {}
|
data = {}
|
||||||
use_mysql = False
|
use_mysql = True
|
||||||
|
|
||||||
# Permissions:
|
# Permissions:
|
||||||
|
|
||||||
@@ -44,47 +34,109 @@ permission_LIST = "utils.alias.list"
|
|||||||
permission_LIST_OTHERS = "utils.alias.list.others"
|
permission_LIST_OTHERS = "utils.alias.list.others"
|
||||||
# Set alias amounts/length limits, e.g. utils.alias.amount.420
|
# Set alias amounts/length limits, e.g. utils.alias.amount.420
|
||||||
permission_AMOUNT = "utils.alias.amount."
|
permission_AMOUNT = "utils.alias.amount."
|
||||||
|
default_alias_limit = 15
|
||||||
permission_LENGTH = "utils.alias.length."
|
permission_LENGTH = "utils.alias.length."
|
||||||
|
default_length_limit = 120
|
||||||
# See when the plugin was disabled due to version errors
|
# See when the plugin was disabled due to version errors
|
||||||
permission_INFO = "utils.alias.info"
|
permission_INFO = "utils.alias.info"
|
||||||
permission_FINFO = "utils.alias.finfo"
|
permission_FINFO = "utils.alias.finfo"
|
||||||
|
|
||||||
########
|
|
||||||
# CODE #
|
|
||||||
########
|
|
||||||
|
|
||||||
enabled = helpers_version in helpers_versions
|
|
||||||
if not enabled:
|
|
||||||
error = colorify("&6Incompatible versions detected (&chelpers.py&6)")
|
|
||||||
|
|
||||||
|
|
||||||
def safe_open_json(uuid):
|
def safe_open_json(uuid):
|
||||||
if not os.path.exists("plugins/redstoner-utils.py.dir/files/aliases"):
|
if not os.path.exists("plugins/redstoner-utils.py.dir/files/aliases"):
|
||||||
os.makedirs("plugins/redstoner-utils.py.dir/files/aliases")
|
os.makedirs("plugins/redstoner-utils.py.dir/files/aliases")
|
||||||
value = open_json_file("aliases/" + uuid)
|
value = open_json_file("aliases/" + uuid)
|
||||||
if value is None:
|
if value is None:
|
||||||
value = global_aliases
|
value = dict(global_aliases)
|
||||||
save_json_file("aliases/" + uuid, value)
|
save_json_file("aliases/" + uuid, value)
|
||||||
return value
|
return value
|
||||||
|
|
||||||
|
|
||||||
|
def get_player_alias_limit(player):
|
||||||
|
value = get_permission_content(player, permission_AMOUNT)
|
||||||
|
if value is not None and value.isdigit():
|
||||||
|
return int(value)
|
||||||
|
return default_alias_limit
|
||||||
|
|
||||||
|
|
||||||
|
def get_player_length_limit(player):
|
||||||
|
value = get_permission_content(player, permission_LENGTH)
|
||||||
|
if value is not None and value.isdigit():
|
||||||
|
return int(value)
|
||||||
|
return default_length_limit
|
||||||
|
|
||||||
|
|
||||||
|
@hook.event("player.PlayerJoinEvent", "high")
|
||||||
|
def on_join(event):
|
||||||
|
if enabled:
|
||||||
|
t = threading.Thread(target=load_data, args=(uid(event.getPlayer()), ))
|
||||||
|
t.daemon = True
|
||||||
|
t.start()
|
||||||
|
else:
|
||||||
|
if event.getPlayer().hasPermission(permission_FINFO):
|
||||||
|
disabled_fallback(event.getPlayer())
|
||||||
|
|
||||||
|
|
||||||
|
@hook.event("player.AsyncPlayerChatEvent", "high")
|
||||||
|
def on_player_chat(event):
|
||||||
|
if enabled:
|
||||||
|
if event.isCancelled():
|
||||||
|
return
|
||||||
|
player = event.getPlayer()
|
||||||
|
if not hasPerm(player, permission_USE):
|
||||||
|
return
|
||||||
|
msg_limit = get_player_length_limit(player)
|
||||||
|
for alias, value in data[uid(player)].iteritems():
|
||||||
|
if player.hasPermission("essentials.chat.color"):
|
||||||
|
event.setMessage(event.getMessage().replace(colorify(alias), colorify(value)))
|
||||||
|
else:
|
||||||
|
event.setMessage(event.getMessage().replace(alias, value))
|
||||||
|
if not player.hasPermission(permission_ALL) and len(event.getMessage()) > msg_limit:
|
||||||
|
event.setCancelled(True)
|
||||||
|
plugin_header(player, "Chatalias")
|
||||||
|
msg(player, "The message you wanted to generate would exceed the length limit limit of %d. Please make it shorter!" % msg_limit)
|
||||||
|
return
|
||||||
|
|
||||||
|
|
||||||
|
def hasPerm(player, permission):
|
||||||
|
return (player.hasPermission(permission)) or (player.hasPermission(permission_ALL))
|
||||||
|
|
||||||
|
|
||||||
|
def disabled_fallback(receiver):
|
||||||
|
if not hasPerm(receiver, permission_INFO):
|
||||||
|
msg(receiver, colorify("&cUnknown command. Use &e/help&c, &e/plugins &cor ask a mod."))
|
||||||
|
else:
|
||||||
|
msg(receiver, colorify("&cPlugin alias v" + alias_version + " has experienced an &eEMERGENCY SHUTDOWN:"))
|
||||||
|
msg(receiver, error_msg)
|
||||||
|
msg(receiver, colorify("&cPlease contact a dev/admin (especially pep :P) about this to take a look at it."))
|
||||||
|
|
||||||
|
|
||||||
|
def can_remote(player):
|
||||||
|
return hasPerm(player, permission_LIST_OTHERS) or hasPerm(player, permission_MODIFY_OTHERS)
|
||||||
|
|
||||||
|
|
||||||
|
# Command
|
||||||
|
|
||||||
@hook.command("alias",
|
@hook.command("alias",
|
||||||
usage="/<command> <add, remove, list, help> [...]",
|
usage="/<command> <add, remove, list, help> [...]",
|
||||||
desc="Allows aliasing of words")
|
desc="Allows aliasing of words")
|
||||||
def on_alias_command(sender, cmd, label, args):
|
def on_alias_command(sender, cmd, label, args):
|
||||||
|
plugin_header(sender, "Chatalias")
|
||||||
try:
|
try:
|
||||||
args = array_to_list(args)
|
args = array_to_list(args)
|
||||||
if not enabled:
|
if not enabled:
|
||||||
disabled_fallback(sender)
|
disabled_fallback(sender)
|
||||||
return True
|
return
|
||||||
if not hasPerm(sender, permission_BASE):
|
if not hasPerm(sender, permission_BASE):
|
||||||
plugin_header(recipient=sender, name="Alias")
|
|
||||||
noperm(sender)
|
noperm(sender)
|
||||||
|
return
|
||||||
|
if args[0].lower() != "player" and not is_player(sender):
|
||||||
|
msg(sender, "&cThe console cannot have aliases")
|
||||||
return True
|
return True
|
||||||
return subcommands[args[0].lower()](sender, args[1:])
|
subcommands[args[0].lower()](sender, args[1:])
|
||||||
except:
|
except:
|
||||||
print(trace())
|
subcommands["help"](sender, "1")
|
||||||
return subcommands["help"](sender, "1")
|
return True
|
||||||
|
|
||||||
|
|
||||||
def help(sender, args):
|
def help(sender, args):
|
||||||
@@ -117,205 +169,234 @@ 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
|
|
||||||
|
|
||||||
|
|
||||||
@hook.event("player.PlayerJoinEvent", "high")
|
|
||||||
def on_join(event):
|
|
||||||
try:
|
|
||||||
if enabled:
|
|
||||||
t = threading.Thread(target=load_data, args=(uid(event.getPlayer()), ))
|
|
||||||
t.daemon = True
|
|
||||||
t.start()
|
|
||||||
else:
|
|
||||||
if event.getPlayer().hasPermission(permission_FINFO):
|
|
||||||
disabled_fallback(event.getPlayer())
|
|
||||||
except:
|
|
||||||
print(trace())
|
|
||||||
|
|
||||||
|
|
||||||
@hook.event("player.AsyncPlayerChatEvent", "high")
|
|
||||||
def on_player_chat(event):
|
|
||||||
try:
|
|
||||||
if enabled:
|
|
||||||
if event.isCancelled():
|
|
||||||
return
|
|
||||||
if not hasPerm(event.getPlayer(), permission_USE):
|
|
||||||
return
|
|
||||||
for alias, value in data[str(uid(event.getPlayer()))].items():
|
|
||||||
if not event.getPlayer().hasPermission(permission_ALL) and len(event.getMessage()) > int(get_permission_content(event.getPlayer(), permission_LENGTH)):
|
|
||||||
event.setCanceled(True)
|
|
||||||
plugin_header(event.getPlayer, "Alias")
|
|
||||||
msg(event.getPlayer(), "The message you wanted to generate would exceed your limit. Please make it shorter!")
|
|
||||||
return
|
|
||||||
if event.getPlayer().hasPermission("essentials.chat.color"):
|
|
||||||
event.setMessage(event.getMessage().replace(colorify(alias), colorify(value)))
|
|
||||||
else:
|
|
||||||
event.setMessage(event.getMessage().replace(alias, value))
|
|
||||||
except:
|
|
||||||
print(trace())
|
|
||||||
|
|
||||||
def hasPerm(player, permission):
|
|
||||||
return (player.hasPermission(permission)) or (player.hasPermission(permission_ALL))
|
|
||||||
|
|
||||||
|
|
||||||
def disabled_fallback(receiver):
|
|
||||||
if not hasPerm(receiver, permission_INFO):
|
|
||||||
msg(receiver, colorify("&cUnknown command. Use &e/help&c, &e/plugins &cor ask a mod."))
|
|
||||||
else:
|
|
||||||
msg(receiver, colorify("&cPlugin alias v" + alias_version + " has experienced an &eEMERGENCY SHUTDOWN:"))
|
|
||||||
msg(receiver, error)
|
|
||||||
msg(receiver, colorify("&cPlease contact a dev/admin (especially pep :P) about this to take a look at it."))
|
|
||||||
|
|
||||||
|
|
||||||
def can_remote(player):
|
|
||||||
return hasPerm(player, permission_LIST_OTHERS) or hasPerm(player, permission_MODIFY_OTHERS)
|
|
||||||
|
|
||||||
|
|
||||||
def add(sender, args):
|
def add(sender, args):
|
||||||
plugin_header(sender, "Alias")
|
uuid = uid(sender)
|
||||||
if not sender.hasPermission(permission_ALL) and len(data[uid(sender)]) >= int(get_permission_content(sender, permission_AMOUNT)):
|
|
||||||
msg(sender, "&cCould not create alias: Max_limit reached!")
|
|
||||||
return True
|
|
||||||
args = [args[0]] + [" ".join(args[1:])]
|
args = [args[0]] + [" ".join(args[1:])]
|
||||||
data[str(uid(sender))][str(args[0])] = args[1]
|
if (args[0] not in data[uuid]) and is_alias_limit_reached(sender, sender):
|
||||||
save_data(uid(sender))
|
return
|
||||||
msg(sender, colorify("&7Alias: ") + args[0] + colorify("&7 -> " + args[1] + colorify("&7 was succesfully created!")), usecolor=sender.hasPermission("essentials.chat.color"))
|
if not add_alias_data(uuid, args[0], args[1]):
|
||||||
return True
|
msg(sender, colorify("&c") + "Could not add this alias because it would cause some sequences to be replaced multiple times", usecolor = False)
|
||||||
|
return
|
||||||
|
msg(sender, colorify("&7Alias: ") + args[0] + colorify("&7 -> ") + args[1] + colorify("&7 was succesfully created!"), usecolor=sender.hasPermission("essentials.chat.color"))
|
||||||
|
|
||||||
|
|
||||||
def radd(sender, args):
|
def radd(sender, sender_name, target, args, silent):
|
||||||
args = [args[0:1]] + [" ".join([args[2:len(args)-2]])] + [args[len(args)-1]]
|
if len(args) < 2:
|
||||||
plugin_header(sender, "Alias")
|
msg(sender, "&cYou must pass a sequence and an alias for it")
|
||||||
if args[3].lower() == "false":
|
return
|
||||||
plugin_header(target, "Alias")
|
replaced = args[0]
|
||||||
msg(target, "&cPlayer " + sender_name + " &cis creating an alias for you!")
|
alias = " ".join(args[1:])
|
||||||
if not sender.hasPermission(permission_ALL) and len(data[uid(sender)]) >= int(get_permission_content(target, permission_AMOUNT)):
|
uuid = uid(target)
|
||||||
msg(sender, "&cCould not create alias: Max_limit reached!")
|
if not silent:
|
||||||
if args[3].lower() == "false":
|
if sender is not target:
|
||||||
msg(target, "&cCould not create alias: Max_limit reached!")
|
plugin_header(target, "Chatalias")
|
||||||
|
msg(target, "&cPlayer %s &cis creating an alias for you!" % sender_name)
|
||||||
|
if (replaced not in data[uuid]) and is_alias_limit_reached(target, sender, silent):
|
||||||
|
return
|
||||||
|
if not add_alias_data(uuid, replaced, alias):
|
||||||
|
message = colorify("&c") + "Could not add this alias because it would cause some sequences to be replaced multiple times"
|
||||||
|
msg(sender, message, usecolor = False)
|
||||||
|
if not silent:
|
||||||
|
msg(target, message, usecolor = False)
|
||||||
|
return
|
||||||
|
message = colorify("&7Alias: &7%s&7 -> &7%s&7 was successfully created!") % ((colorify(replaced), colorify(alias)) if target.hasPermission("essentials.chat.color") else (replaced, alias))
|
||||||
|
msg(sender, message, usecolor = False)
|
||||||
|
if not silent:
|
||||||
|
msg(target, message, usecolor = False)
|
||||||
|
|
||||||
|
|
||||||
|
def is_alias_limit_reached(player, recipient, silent = True):
|
||||||
|
if player.hasPermission(permission_ALL):
|
||||||
|
return False
|
||||||
|
alias_limit = get_player_alias_limit(player)
|
||||||
|
if len(data[uid(player)]) >= alias_limit:
|
||||||
|
message = ("&cYour limit of %d has been reached" if player is recipient else "&cThe limit of %d has been reached for that player") % alias_limit
|
||||||
|
msg(recipient, message)
|
||||||
|
if not silent:
|
||||||
|
msg(player, message)
|
||||||
return True
|
return True
|
||||||
|
return False
|
||||||
|
|
||||||
target = get_player(args[0])
|
|
||||||
if is_player(sender):
|
def add_alias_data(puuid, aliased, new_alias):
|
||||||
sender_name = colorify(sender.getDisplayName)
|
prior = dict(data[puuid])
|
||||||
else:
|
if aliased in prior:
|
||||||
sender_name = colorify("&6Console")
|
info("Checking prior, removing previous alias for " + aliased)
|
||||||
if len(args) == 3:
|
del prior[aliased]
|
||||||
args += ["true"]
|
|
||||||
data[str(uid(target))][str(args[1])] = str(args[2])
|
# prevent 2 -> 3 if there is 1 -> 2
|
||||||
save_data(uid(target))
|
for alias in prior.values():
|
||||||
msg(sender, colorify("&7Alias: ") + args[1] + colorify("&7 -> " + args[2] + colorify("&7 was succesfully created!")), usecolor=target.hasPermission("essentials.chat.color"))
|
if aliased in alias:
|
||||||
if args[3].lower() == "false":
|
info("aliased %s in alias %s" % (aliased, alias))
|
||||||
msg(target, colorify("&7Alias: ") + args[1] + colorify("&7 -> " + args[2] + colorify("&7 was succesfully created!")), usecolor=target.hasPermission("essentials.chat.color"))
|
return False
|
||||||
|
|
||||||
|
# prevent 1 -> 2 if there is 2 -> 3
|
||||||
|
for sequence in prior:
|
||||||
|
if sequence in new_alias:
|
||||||
|
info("sequence %s in new_alias %s" % (sequence, new_alias))
|
||||||
|
return False
|
||||||
|
|
||||||
|
data[puuid][aliased] = new_alias
|
||||||
|
save_data(puuid)
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
def remove(sender, args):
|
def remove(sender, args):
|
||||||
plugin_header(sender, "Alias")
|
|
||||||
try:
|
try:
|
||||||
msg(sender, colorify("&7Successfully removed alias ") + args[0] + colorify(" &7-> ") + data[uid(sender)].pop(args[0]) + colorify("&7!"), usecolor=sender.hasPermission("essentials.chat.color"))
|
msg(sender, colorify("&7Successfully removed alias ") + args[0] + colorify(" &7-> ") + data[uid(sender)].pop(args[0]) + colorify("&7!"), usecolor=sender.hasPermission("essentials.chat.color"))
|
||||||
save_data(uid(sender))
|
save_data(uid(sender))
|
||||||
except:
|
except:
|
||||||
msg(sender, colorify("&cCould not remove alias ") + args[0] + colorify(", it does not exist."), usecolor=sender.hasPermission("essentials.chat.color"))
|
msg(sender, colorify("&cCould not remove alias ") + args[0] + colorify(", it does not exist."), usecolor=sender.hasPermission("essentials.chat.color"))
|
||||||
return True
|
|
||||||
|
|
||||||
|
|
||||||
def rremove(sender, args):
|
def rremove(sender, sender_name, target, args, silent):
|
||||||
plugin_header(sender, "Alias")
|
if len(args) < 1:
|
||||||
target = get_player(args[0])
|
msg(sender, "&cYou must specify a sequence whose alias is to be removed")
|
||||||
if is_player(sender):
|
return
|
||||||
sender_name = colorify(sender.getDisplayName)
|
removed = args[0]
|
||||||
|
uuid = uid(target)
|
||||||
|
aliases = data[uuid]
|
||||||
|
if not silent:
|
||||||
|
msg(target, "&cPlayer %s &cis removing an alias for you!" % sender_name)
|
||||||
|
if removed in aliases:
|
||||||
|
alias = aliases.pop(removed)
|
||||||
|
message = colorify("&7Alias: &7%s&7 -> &7%s&7 successfully removed!") % ((colorify(removed), colorify(alias)) if target.hasPermission("essentials.chat.color") else (removed, alias))
|
||||||
|
msg(sender, message, usecolor = False)
|
||||||
|
if not silent:
|
||||||
|
msg(target, message, usecolor = False)
|
||||||
|
save_data(uuid)
|
||||||
else:
|
else:
|
||||||
sender_name = colorify("&6Console")
|
message = colorify("&cCould not remove alias &7%s&c, it does not exist") % colorify(removed) if target.hasPermission("essentials.chat.color") else removed
|
||||||
if args[2].lower() == "false":
|
msg(sender, message, usecolor = False)
|
||||||
print("WTF")
|
if not silent:
|
||||||
plugin_header(target, "Alias")
|
msg(target, message, usecolor = False)
|
||||||
msg(target, "&cPlayer " + sender_name + " &cis removing an alias for you!")
|
|
||||||
try:
|
|
||||||
alias = data[uid(target)].pop(args[1])
|
|
||||||
msg(sender, colorify("&7Successfully removed alias ") + args[1] + colorify(" &7-> ") + alias + colorify("&7!"), usecolor=sender.hasPermission("essentials.chat.color"))
|
|
||||||
if args[2].lower() == "false":
|
|
||||||
msg(target, colorify("&7Successfully removed alias ") + args[1] + colorify(" &7-> ") + alias + colorify("&7!"), usecolor=sender.hasPermission("essentials.chat.color"))
|
|
||||||
save_data(uid(target))
|
|
||||||
except:
|
|
||||||
msg(sender, colorify("&cCould not remove alias ") + args[1] + colorify(", it does not exist."), usecolor=sender.hasPermission("essentials.chat.color"))
|
|
||||||
if args[2].lower() == "false":
|
|
||||||
msg(target, colorify("&cCould not remove alias ") + args[1] + colorify(", it does not exist."), usecolor=sender.hasPermission("essentials.chat.color"))
|
|
||||||
return True
|
|
||||||
|
|
||||||
|
|
||||||
def list_alias(sender, args):
|
def list_alias(sender, args):
|
||||||
plugin_header(sender, "Alias")
|
|
||||||
msg(sender, "&7You have a total of " + str(len(data[uid(sender)])) + " aliases:")
|
msg(sender, "&7You have a total of " + str(len(data[uid(sender)])) + " aliases:")
|
||||||
for word, alias in data[str(uid(sender))].items():
|
for word, alias in data[str(uid(sender))].items():
|
||||||
msg(sender, colorify("&7") + word + colorify("&7 -> ") + alias, usecolor=sender.hasPermission("essentials.chat.color"))
|
msg(sender, colorify("&7") + word + colorify("&7 -> ") + alias, usecolor=sender.hasPermission("essentials.chat.color"))
|
||||||
return True
|
|
||||||
|
|
||||||
|
|
||||||
def rlist_alias(sender, args):
|
def rlist_alias(sender, sender_name, target, args, silent):
|
||||||
plugin_header(sender, "Alias")
|
aliases = data[uid(target)]
|
||||||
target = get_player(args[0])
|
msg(sender, "&7Player %s has a total of %d aliases:" % (target.getName(), len(aliases)))
|
||||||
if is_player(sender):
|
if not silent:
|
||||||
sender_name = colorify(sender.getDisplayName)
|
if sender is not target:
|
||||||
|
plugin_header(target, "Chatalias")
|
||||||
|
msg(target, "&cPlayer %s &cis listing your aliases" % sender_name)
|
||||||
|
if target.hasPermission("essentials.chat.color"):
|
||||||
|
for pair in aliases.iteritems():
|
||||||
|
msg(sender, colorify("&7%s&7 -> %s" % pair), usecolor = False)
|
||||||
else:
|
else:
|
||||||
sender_name = colorify("&6Console")
|
for pair in aliases.iteritems():
|
||||||
if len(args) == 1:
|
msg(sender, colorify("&7%s&7 -> %s") % pair, usecolor = False)
|
||||||
args += ["true"]
|
|
||||||
msg(sender, "Player " + args[0] + " has following aliases (" + str(len(data[uid(target)])) + " in total):")
|
|
||||||
if args[1].lower() == "false":
|
|
||||||
plugin_header(target, "Alias")
|
|
||||||
msg(target, "&cPlayer " + sender_name + " &cis listing your aliases (" + str(len(data[uid(target)])) + " in total):")
|
|
||||||
for word, alias in data[str(uid(target))].items():
|
|
||||||
msg(sender, colorify("&7") + word + colorify("&7 -> ") + alias, usecolor=target.hasPermission("essentials.chat.color"))
|
|
||||||
if args[1].lower() == "false":
|
|
||||||
msg(target, colorify("&7") + word + colorify("&7 -> ") + alias, usecolor=target.hasPermission("essentials.chat.color"))
|
|
||||||
return True
|
|
||||||
|
|
||||||
|
|
||||||
def remote(sender, args):
|
def remote(sender, args):
|
||||||
try:
|
if len(args) < 2:
|
||||||
return remotes[args[1].lower()](sender, [args[0]] + [args[2:]])
|
msg(sender, "&cAlias remotes take at least 3 arguments")
|
||||||
except:
|
return
|
||||||
print(trace())
|
target_remote = remotes.get(args[1].lower())
|
||||||
return subcommands["help"](sender, ["2"])
|
if target_remote is None:
|
||||||
|
msg(sender, "&cThat remote command does not exist")
|
||||||
|
return
|
||||||
|
target = server.getOfflinePlayer(args[0])
|
||||||
|
if target is None or not (target.hasPlayedBefore() or target.isOnline()):
|
||||||
|
msg(sender, "&cThat player could not be found")
|
||||||
|
return
|
||||||
|
silent = True
|
||||||
|
if len(args) > (2 if target_remote is rlist_alias else 3 if target_remote is rremove else 4):
|
||||||
|
if args[-1].lower() == "false":
|
||||||
|
silent = sender is target or not target.isOnline()
|
||||||
|
args = args[:-1]
|
||||||
|
elif args[-1].lower() == "true":
|
||||||
|
args = args[:-1]
|
||||||
|
target_remote(sender, sender.getDisplayName() if is_player(sender) else colorify("&6Console"), target, args[2:], silent)
|
||||||
|
|
||||||
|
|
||||||
def load_data(uuid):
|
|
||||||
if use_mysql:
|
|
||||||
conn = zxJDBC.connect(mysql_database, mysql_user, mysql_pass, "com.mysql.jdbc.Driver")
|
|
||||||
curs = conn.cursor()
|
|
||||||
curs.execute("SELECT alias FROM alias WHERE uuid = ?", (uuid, ))
|
|
||||||
results = curs.fetchall()
|
|
||||||
if len(results) == 0:
|
|
||||||
results = global_aliases
|
|
||||||
curs.execute("INSERT INTO alias VALUES (?,?)", (uuid, results, ))
|
|
||||||
data[uuid] = results
|
|
||||||
else:
|
|
||||||
data[uuid] = safe_open_json(uuid)
|
|
||||||
|
|
||||||
|
|
||||||
def save_data(uuid):
|
|
||||||
if use_mysql:
|
|
||||||
conn = zxJDBC.connect(mysql_database, mysql_user, mysql_pass, "com.mysql.jdbc.Driver")
|
|
||||||
curs = conn.cursor()
|
|
||||||
curs.execute("UPDATE alias SET alias = ? WHERE uuid = ?", (data[uuid], uuid, ))
|
|
||||||
else:
|
|
||||||
save_json_file("aliases/" + uuid, data[uuid])
|
|
||||||
|
|
||||||
# Subcommands:
|
|
||||||
|
|
||||||
subcommands = {
|
subcommands = {
|
||||||
"help": help,
|
"help": help,
|
||||||
|
"?": help,
|
||||||
"add": add,
|
"add": add,
|
||||||
"remove": remove,
|
"remove": remove,
|
||||||
|
"del": remove,
|
||||||
|
"delete": remove,
|
||||||
"player": remote,
|
"player": remote,
|
||||||
|
"remote": remote,
|
||||||
"list": list_alias
|
"list": list_alias
|
||||||
}
|
}
|
||||||
|
|
||||||
remotes = {
|
remotes = {
|
||||||
"add": radd,
|
"add": radd,
|
||||||
"remove": rremove,
|
"remove": rremove,
|
||||||
|
"del": rremove,
|
||||||
|
"delete": rremove,
|
||||||
"list": rlist_alias,
|
"list": rlist_alias,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
# Storage
|
||||||
|
# MySQL Table:
|
||||||
|
# CREATE TABLE `chatalias` (`uuid` VARCHAR(36) PRIMARY KEY, `alias` TEXT);
|
||||||
|
|
||||||
|
def load_data(uuid):
|
||||||
|
if use_mysql:
|
||||||
|
try:
|
||||||
|
t = threading.Thread(target=load_data_thread, args=(uuid,))
|
||||||
|
t.daemon = True
|
||||||
|
t.start()
|
||||||
|
except:
|
||||||
|
error(trace())
|
||||||
|
else:
|
||||||
|
data[uuid] = safe_open_json(uuid)
|
||||||
|
|
||||||
|
def load_data_thread(uuid):
|
||||||
|
conn = zxJDBC.connect(mysql_database, mysql_user, mysql_pass, "com.mysql.jdbc.Driver")
|
||||||
|
curs = conn.cursor()
|
||||||
|
curs.execute("SELECT `alias` FROM `chatalias` WHERE `uuid` = ?;", (uuid, ))
|
||||||
|
results = curs.fetchall()
|
||||||
|
curs.close()
|
||||||
|
conn.close()
|
||||||
|
if len(results) == 0:
|
||||||
|
value = dict(global_aliases)
|
||||||
|
else:
|
||||||
|
value = json_loads(results[0][0])
|
||||||
|
data[uuid] = value
|
||||||
|
|
||||||
|
|
||||||
|
def save_data(uuid):
|
||||||
|
if use_mysql:
|
||||||
|
try:
|
||||||
|
t = threading.Thread(target=save_data_thread, args=(uuid,))
|
||||||
|
t.daemon = True
|
||||||
|
t.start()
|
||||||
|
except:
|
||||||
|
error(trace())
|
||||||
|
else:
|
||||||
|
save_json_file("aliases/" + uuid, data[uuid])
|
||||||
|
|
||||||
|
def save_data_thread(uuid):
|
||||||
|
conn = zxJDBC.connect(mysql_database, mysql_user, mysql_pass, "com.mysql.jdbc.Driver")
|
||||||
|
curs = conn.cursor()
|
||||||
|
curs.execute("INSERT INTO `chatalias` (`uuid`, `alias`) VALUES (?, ?) ON DUPLICATE KEY UPDATE `alias` = VALUES(`alias`);",
|
||||||
|
(uuid, json_dumps(data[uuid])))
|
||||||
|
conn.commit()
|
||||||
|
curs.close()
|
||||||
|
conn.close()
|
||||||
|
|
||||||
|
|
||||||
|
# OnModuleLoad
|
||||||
|
|
||||||
|
enabled = helpers_version in helpers_versions
|
||||||
|
if not enabled:
|
||||||
|
error_msg = colorify("&6Incompatible versions detected (&chelpers.py&6)")
|
||||||
|
for player in server.getOnlinePlayers():
|
||||||
|
if enabled:
|
||||||
|
load_data(uid(player))
|
||||||
|
else:
|
||||||
|
if player.hasPermission(permission_FINFO):
|
||||||
|
disabled_fallback(player)
|
||||||
|
|||||||
@@ -89,7 +89,7 @@ def groupchat(sender, message, ann = False):
|
|||||||
def do_for_chatgroup(group, func, *args, **kwargs):
|
def do_for_chatgroup(group, func, *args, **kwargs):
|
||||||
for receiver in server.getOnlinePlayers():
|
for receiver in server.getOnlinePlayers():
|
||||||
if groups.get(uid(receiver)) == group:
|
if groups.get(uid(receiver)) == group:
|
||||||
func(receiver, args, kwargs)
|
func(receiver, *args, **kwargs)
|
||||||
|
|
||||||
def send_tpa_request(receiver, sender):
|
def send_tpa_request(receiver, sender):
|
||||||
if not receiver == sender:
|
if not receiver == sender:
|
||||||
@@ -102,8 +102,9 @@ def save_groups():
|
|||||||
@hook.event("player.AsyncPlayerChatEvent", "normal")
|
@hook.event("player.AsyncPlayerChatEvent", "normal")
|
||||||
def on_chat(event):
|
def on_chat(event):
|
||||||
sender = event.getPlayer()
|
sender = event.getPlayer()
|
||||||
|
user = get_py_player(sender)
|
||||||
msge = event.getMessage()
|
msge = event.getMessage()
|
||||||
if not event.isCancelled():
|
if (not user.logging_in) and (not event.isCancelled()):
|
||||||
sender_id = uid(sender)
|
sender_id = uid(sender)
|
||||||
key = get_key(sender_id)
|
key = get_key(sender_id)
|
||||||
keylen = len(key)
|
keylen = len(key)
|
||||||
|
|||||||
6
check.py
6
check.py
@@ -35,11 +35,11 @@ def get_website_data(player):
|
|||||||
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()
|
||||||
uuid = str(uid(player)).replace("-", "")
|
uuid = str(uid(player)).replace("-", "")
|
||||||
curs.execute("SELECT DISTINCT `id`, `email` FROM users WHERE `uuid` = ? LIMIT 1", (uuid,))
|
curs.execute("SELECT DISTINCT `id`, `email`, `confirmed` FROM users WHERE `uuid` = ? LIMIT 1", (uuid,))
|
||||||
results = curs.fetchall()
|
results = curs.fetchall()
|
||||||
curs.close()
|
curs.close()
|
||||||
conn.close()
|
conn.close()
|
||||||
return ("http://redstoner.com/users/%s" % results[0][0], results[0][1]) if results else (None, None)
|
return ("http://redstoner.com/users/%s" % results[0][0], results[0][1], False if results[0][2] == 0 else True) if results else (None, None, True)
|
||||||
|
|
||||||
|
|
||||||
# receive country based on the user's IP
|
# receive country based on the user's IP
|
||||||
@@ -68,6 +68,8 @@ def get_all_data(sender, player):
|
|||||||
website = get_website_data(player)
|
website = get_website_data(player)
|
||||||
msg(sender, "&6> Website account: &e%s" % website[0])
|
msg(sender, "&6> Website account: &e%s" % website[0])
|
||||||
msg(sender, "&6> email: &e%s" % website[1])
|
msg(sender, "&6> email: &e%s" % website[1])
|
||||||
|
if not website[2]:
|
||||||
|
msg(sender, "&6> &cEmail NOT Confirmed!")
|
||||||
msg(sender, "&7 -- Data provided by ipinfo.io")
|
msg(sender, "&7 -- Data provided by ipinfo.io")
|
||||||
msg(sender, "&6> Country: &e%s" % get_country(data))
|
msg(sender, "&6> Country: &e%s" % get_country(data))
|
||||||
msg(sender, "&7 -- Data provided by Mojang")
|
msg(sender, "&7 -- Data provided by Mojang")
|
||||||
|
|||||||
4
cycle.py
4
cycle.py
@@ -56,7 +56,7 @@ def on_slot_change(event):
|
|||||||
|
|
||||||
def do_cycle(player, down):
|
def do_cycle(player, down):
|
||||||
inv = player.getInventory()
|
inv = player.getInventory()
|
||||||
items = inv.getContents()
|
items = inv.getStorageContents()
|
||||||
shift = -9 if down else 9
|
shift = -9 if down else 9
|
||||||
shift = shift % len(items)
|
shift = shift % len(items)
|
||||||
for _ in range(4):
|
for _ in range(4):
|
||||||
@@ -64,7 +64,7 @@ def do_cycle(player, down):
|
|||||||
uniq_items = sorted(set(list(items)[:9])) # get unique inventory
|
uniq_items = sorted(set(list(items)[:9])) # get unique inventory
|
||||||
if uniq_items != [None]: # row not empty
|
if uniq_items != [None]: # row not empty
|
||||||
break
|
break
|
||||||
inv.setContents(items)
|
inv.setStorageContents(items)
|
||||||
|
|
||||||
def save_cyclers():
|
def save_cyclers():
|
||||||
save_json_file("cycle", no_cyclers)
|
save_json_file("cycle", no_cyclers)
|
||||||
162
damnspam.py
162
damnspam.py
@@ -1,12 +1,15 @@
|
|||||||
#pylint: disable = F0401
|
#pylint: disable = F0401
|
||||||
from helpers import *
|
from helpers import *
|
||||||
from time import time as now
|
from time import time as now
|
||||||
import org.bukkit.event.block.BlockBreakEvent as BlockBreakEvent
|
import org.bukkit.Material as Material
|
||||||
|
import org.bukkit.block.BlockFace as BlockFace
|
||||||
|
|
||||||
inputs = open_json_file("damnspam", {}) # format "x;y;z;World"
|
inputs = open_json_file("damnspam", {}) # format "x;y;z;World"
|
||||||
accepted_inputs = ["WOOD_BUTTON", "STONE_BUTTON", "LEVER"]
|
accepted_inputs = ["WOOD_BUTTON", "STONE_BUTTON", "LEVER"]
|
||||||
changing_input = False
|
changing_input = False
|
||||||
removing_input = False
|
removing_input = False
|
||||||
|
max_timeout = 240
|
||||||
|
timeout_error_str = "&cThe timeout must be -1 or within 0 and %d" % max_timeout
|
||||||
|
|
||||||
|
|
||||||
def save_inputs():
|
def save_inputs():
|
||||||
@@ -26,31 +29,35 @@ def add_input(creator, block, timeout_off, timeout_on):
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
def is_acceptable_timeout(timeout):
|
||||||
|
return (0 < timeout <= max_timeout) or timeout == -1
|
||||||
|
|
||||||
|
|
||||||
@hook.command("damnspam")
|
@hook.command("damnspam")
|
||||||
def on_dammnspam_command(sender, command, label, args):
|
def on_dammnspam_command(sender, command, label, args):
|
||||||
global changing_input
|
|
||||||
|
|
||||||
plugin_header(sender, "DamnSpam")
|
plugin_header(sender, "DamnSpam")
|
||||||
|
|
||||||
if not checkargs(sender, args, 1, 2):
|
if not checkargs(sender, args, 1, 2):
|
||||||
msg(sender, "&c/damnspam <seconds> &e(Buttons/Levers)")
|
msg(sender, "&c/damnspam <seconds> &e(Buttons/Levers)")
|
||||||
msg(sender, "&c/damnspam <seconds after off> <seconds after on> &e(Levers only)")
|
msg(sender, "&c/damnspam <seconds after off> <seconds after on> &e(Levers only)")
|
||||||
return True
|
return True
|
||||||
#Gittestlol
|
#Gittestlol
|
||||||
if not is_creative(sender):
|
if not is_creative(sender):
|
||||||
msg(sender, "&cYou can only do this in Creative mode.")
|
msg(sender, "&cYou can only do this in Creative mode")
|
||||||
return True
|
return True
|
||||||
|
|
||||||
# /damnspam <secs>
|
# /damnspam <secs>
|
||||||
|
destroying_input = False # if both timeouts are 0, the plugin will attempt to remove the protection
|
||||||
if len(args) == 1:
|
if len(args) == 1:
|
||||||
timeout_on = args[0]
|
timeout_on = args[0]
|
||||||
try:
|
try:
|
||||||
timeout_on = round(float(timeout_on), 2)
|
timeout_on = round(float(timeout_on), 2)
|
||||||
timeout_off = timeout_on
|
if timeout_on == 0:
|
||||||
if 60 >= timeout_on <= -2 or timeout_on == 0:
|
destroying_input = True
|
||||||
timeout_on = False
|
elif not is_acceptable_timeout(timeout_on):
|
||||||
if timeout_on == False:
|
msg(sender, "&cThe timeout must be -1 or within 0 and %d" % max_timeout)
|
||||||
msg(sender, "&cThe timeout must be within 0-60 or -1.")
|
|
||||||
return True
|
return True
|
||||||
|
timeout_off = timeout_on
|
||||||
except ValueError:
|
except ValueError:
|
||||||
msg(sender, "&cThe timeout must be a number")
|
msg(sender, "&cThe timeout must be a number")
|
||||||
return True
|
return True
|
||||||
@@ -62,12 +69,10 @@ def on_dammnspam_command(sender, command, label, args):
|
|||||||
try:
|
try:
|
||||||
timeout_on = round(float(timeout_on), 2)
|
timeout_on = round(float(timeout_on), 2)
|
||||||
timeout_off = round(float(timeout_off), 2)
|
timeout_off = round(float(timeout_off), 2)
|
||||||
if 60 >= timeout_on <= -2 or timeout_on == 0:
|
if timeout_on == 0 and timeout_off == 0:
|
||||||
timeout_on = False
|
destroying_input = True
|
||||||
if 60 >= timeout_off <= -2 or timeout_off == 0:
|
elif not (is_acceptable_timeout(timeout_on) and is_acceptable_timeout(timeout_off)):
|
||||||
timeout_off = False
|
msg(sender, "&cThe timeout must be -1 or within 0 and %d" % max_timeout)
|
||||||
if timeout_on == False or timeout_off == False:
|
|
||||||
msg(sender, "&cThe timeout must be within 0-60 or -1.")
|
|
||||||
return True
|
return True
|
||||||
except ValueError:
|
except ValueError:
|
||||||
msg(sender, "&cThe timeout must be a number")
|
msg(sender, "&cThe timeout must be a number")
|
||||||
@@ -80,72 +85,111 @@ def on_dammnspam_command(sender, command, label, args):
|
|||||||
msg(sender, "&cPlease look at a button or lever while executing this command!")
|
msg(sender, "&cPlease look at a button or lever while executing this command!")
|
||||||
return True
|
return True
|
||||||
|
|
||||||
if location_str(target) in inputs:
|
global changing_input
|
||||||
|
target_loc_str = location_str(target)
|
||||||
|
if target_loc_str in inputs:
|
||||||
changing_input = True # this input already has a timeout
|
changing_input = True # this input already has a timeout
|
||||||
|
|
||||||
|
type_str = ttype.lower().replace("_", " ")
|
||||||
|
|
||||||
# test if player is allowed to build here
|
# test if player is allowed to build here
|
||||||
test_event = BlockBreakEvent(target, sender)
|
build_check = can_build(sender, target)
|
||||||
server.getPluginManager().callEvent(test_event)
|
|
||||||
changing_input = False
|
changing_input = False
|
||||||
if test_event.isCancelled():
|
if not build_check:
|
||||||
msg(sender, "&cYou are not allowed to modify this %s" % str(target.getType()).lower())
|
msg(sender, "&cYou are not allowed to modify this %s" % type_str)
|
||||||
return True
|
return True
|
||||||
|
|
||||||
# add block to inputs
|
# add block to inputs
|
||||||
add_input(sender, target, timeout_off, timeout_on)
|
if destroying_input:
|
||||||
|
if target_loc_str not in inputs:
|
||||||
|
msg(sender, "&cThere is no timeout to remove on this %s (by setting the timeout to 0)" % type_str)
|
||||||
|
return True
|
||||||
|
del inputs[target_loc_str]
|
||||||
|
msg(sender, "&aSuccessfully removed the timeout for this %s" % type_str)
|
||||||
|
else:
|
||||||
|
add_input(sender, target, timeout_off, timeout_on)
|
||||||
|
msg(sender, "&aSuccessfully set a timeout for this %s" % type_str)
|
||||||
save_inputs()
|
save_inputs()
|
||||||
msg(sender, "&aSuccessfully set a timeout for this %s." % ttype.lower().replace("_", " "))
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
@hook.event("block.BlockBreakEvent", "normal")
|
def check_block_break(break_event, block):
|
||||||
def on_block_break(event):
|
if str(block.getType()) not in accepted_inputs:
|
||||||
global removing_input
|
|
||||||
|
|
||||||
if removing_input:
|
|
||||||
return
|
return
|
||||||
sender = event.getPlayer()
|
pos_str = location_str(block)
|
||||||
block = event.getBlock()
|
if pos_str not in inputs:
|
||||||
btype = str(block.getType()).lower()
|
return
|
||||||
if str(block.getType()) in accepted_inputs and not event.isCancelled():
|
sender = break_event.getPlayer()
|
||||||
pos_str = location_str(block)
|
input_str = ("this %s" if block is break_event.getBlock() else "the %s attached to that block") % str(block.getType()).lower().replace("_", " ")
|
||||||
if inputs.get(pos_str):
|
if not sender.isSneaking():
|
||||||
if sender.isSneaking():
|
msg(sender, "&cYou cannot destroy " + input_str)
|
||||||
# test if player is allowed to build here
|
msg(sender, "&c&nSneak&c and break or set the timeout to 0 if you want to remove it.")
|
||||||
removing_input = True
|
break_event.setCancelled(True)
|
||||||
test_event = BlockBreakEvent(block, sender)
|
return
|
||||||
server.getPluginManager().callEvent(test_event)
|
global removing_input
|
||||||
removing_input = False
|
removing_input = True
|
||||||
if test_event.isCancelled():
|
success = can_build(sender, block)
|
||||||
event.setCancelled(True)
|
removing_input = False
|
||||||
msg(sender, "&cYou are not allowed to remove this %s" % btype)
|
if success:
|
||||||
return True
|
del inputs[pos_str]
|
||||||
inputs.pop(pos_str) # remove
|
save_inputs()
|
||||||
save_inputs()
|
msg(sender, "&aSuccessfully removed %s!" % input_str)
|
||||||
msg(sender, "&eSuccessfully removed this %s!" % btype)
|
else:
|
||||||
return True
|
msg(sender, "&cYou are not allowed to remove " + input_str)
|
||||||
elif not changing_input:
|
break_event.setCancelled(True)
|
||||||
event.setCancelled(True)
|
|
||||||
msg(sender, "&cYou cannot destroy this %s!" % btype)
|
|
||||||
msg(sender, "&c&nSneak&c and break if you want to remove it.")
|
# a dict for levers and buttons, with a tuple of tuples as value. The tuples in the tuple represent
|
||||||
return True
|
# the data values which the block must have if the block were placed towards the linked blockface to be affected.
|
||||||
|
# The order is DOWN, UP, NORTH, SOUTH, WEST, EAST
|
||||||
|
attached_blocks = {
|
||||||
|
|
||||||
|
Material.LEVER: ((0, 7, 8, 15), (5, 6, 13, 14), (4, 12), (3, 11), (2, 10), (1, 9)),
|
||||||
|
Material.STONE_BUTTON: ((0, 8), (5, 6, 7, 13, 14, 15), (4, 12), (3, 11), (2, 10), (1, 9)),
|
||||||
|
Material.WOOD_BUTTON: ((0, 8), (5, 6, 7, 13, 14, 15), (4, 12), (3, 11), (2, 10), (1, 9)),
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
# returns a generator containing the levers or buttons that would be broken if this block were broken
|
||||||
|
def get_attached_blocks(block):
|
||||||
|
for i, face in ((0, BlockFace.DOWN), (1, BlockFace.UP), (2, BlockFace.NORTH), (3, BlockFace.SOUTH), (4, BlockFace.WEST), (5, BlockFace.EAST)):
|
||||||
|
side = block.getRelative(face)
|
||||||
|
dvalues = attached_blocks.get(side.getType())
|
||||||
|
if dvalues is not None and side.getData() in dvalues[i]:
|
||||||
|
yield side
|
||||||
|
|
||||||
|
|
||||||
|
@hook.event("block.BlockBreakEvent", "highest")
|
||||||
|
def on_block_break(event):
|
||||||
|
if removing_input or changing_input or event.isCancelled():
|
||||||
|
return
|
||||||
|
block = event.getBlock()
|
||||||
|
check_block_break(event, event.getBlock())
|
||||||
|
for affected_block in get_attached_blocks(block):
|
||||||
|
check_block_break(event, affected_block)
|
||||||
|
|
||||||
|
|
||||||
@hook.event("player.PlayerInteractEvent", "normal")
|
@hook.event("player.PlayerInteractEvent", "normal")
|
||||||
def on_interact(event):
|
def on_interact(event):
|
||||||
if (str(event.getAction()) == "RIGHT_CLICK_BLOCK") and not event.isCancelled():
|
if (str(event.getAction()) == "RIGHT_CLICK_BLOCK") and not event.isCancelled():
|
||||||
sender = event.getPlayer()
|
sender = event.getPlayer()
|
||||||
block = event.getClickedBlock()
|
block = event.getClickedBlock()
|
||||||
btype = str(block.getType()).lower()
|
|
||||||
powered = (block.getData() & 0x8) == 0x8 if btype == "lever" else False # data > 7, but this is how bukkit does it
|
|
||||||
pos_str = location_str(block)
|
pos_str = location_str(block)
|
||||||
data = inputs.get(pos_str)
|
data = inputs.get(pos_str)
|
||||||
if data:
|
if data:
|
||||||
checktime = data["timeout_on"] if powered else data["timeout_off"]
|
sender = event.getPlayer()
|
||||||
|
btype = str(block.getType()).lower().replace("_", " ")
|
||||||
|
if btype == "lever" and block.getData() < 8:
|
||||||
|
checktime = data["timeout_off"]
|
||||||
|
else:
|
||||||
|
checktime = data["timeout_on"]
|
||||||
|
time_left = data["last_time"] + checktime - now()
|
||||||
|
|
||||||
if checktime == -1:
|
if checktime == -1:
|
||||||
event.setCancelled(True)
|
event.setCancelled(True)
|
||||||
msg(sender, "&cThis %s is locked permanently by /damnspam." % (btype))
|
msg(sender, "&cThis %s is locked permanently by /damnspam." % (btype))
|
||||||
elif data["last_time"] + checktime > now():
|
elif time_left > 0:
|
||||||
event.setCancelled(True)
|
event.setCancelled(True)
|
||||||
msg(sender, "&cThis %s has a damnspam timeout of %ss." % (btype, checktime))
|
msg(sender, "&cThis %s has a damnspam timeout of %.2fs, with %.2fs left." % (btype, checktime, time_left))
|
||||||
else:
|
else:
|
||||||
inputs[pos_str]["last_time"] = round(now(), 2)
|
data["last_time"] = round(now(), 2)
|
||||||
|
|||||||
97
friends.py
97
friends.py
@@ -5,6 +5,10 @@ friends = open_json_file("friends", {}) # {Player_UUID:[List_of_friend
|
|||||||
friend_join_sound = "random.orb"
|
friend_join_sound = "random.orb"
|
||||||
|
|
||||||
|
|
||||||
|
def is_friend_of(player, other):
|
||||||
|
lst = friends.get(uid(player))
|
||||||
|
return lst is not None and uid(other) in lst
|
||||||
|
|
||||||
|
|
||||||
@hook.event("player.PlayerJoinEvent", "high") # creates sound and sends a bold message on friend join
|
@hook.event("player.PlayerJoinEvent", "high") # creates sound and sends a bold message on friend join
|
||||||
def fjm(event): # friend join message
|
def fjm(event): # friend join message
|
||||||
@@ -25,6 +29,13 @@ def friendmessage(player, message): # sends a message with a prefix
|
|||||||
msg(player, "&7[&aFriends&7] " + message)
|
msg(player, "&7[&aFriends&7] " + message)
|
||||||
|
|
||||||
|
|
||||||
|
def get_player(name):
|
||||||
|
result = server.getOfflinePlayer(name)
|
||||||
|
if result is not None and (result.hasPlayedBefore() or result.isOnline()):
|
||||||
|
return result
|
||||||
|
return None
|
||||||
|
|
||||||
|
|
||||||
def ls(sender):
|
def ls(sender):
|
||||||
try:
|
try:
|
||||||
sender_friends = friends.get(uid(sender), False)
|
sender_friends = friends.get(uid(sender), False)
|
||||||
@@ -55,21 +66,25 @@ def add(sender, names):
|
|||||||
added = []
|
added = []
|
||||||
notfound = []
|
notfound = []
|
||||||
friendalready = []
|
friendalready = []
|
||||||
|
added_self = False
|
||||||
|
|
||||||
if not sender_id in friends:
|
if not sender_id in friends:
|
||||||
friends[sender_id] = []
|
friends[sender_id] = []
|
||||||
|
|
||||||
for name in names:
|
for name in names:
|
||||||
player = server.getPlayer(name)
|
player = get_player(name)
|
||||||
if player:
|
if player:
|
||||||
player_id = uid(player)
|
player_id = uid(player)
|
||||||
not_yourself = player != sender
|
not_yourself = sender != player
|
||||||
|
|
||||||
if not player_id in friends[sender_id]:
|
if not player_id in friends[sender_id]:
|
||||||
if not_yourself:
|
if not_yourself:
|
||||||
friends[sender_id].append(player_id)
|
friends[sender_id].append(player_id)
|
||||||
added.append(player.getName())
|
added.append(player.getName())
|
||||||
friendmessage(player.getPlayer(), "&a&o%s &aadded you to their friends list" % stripcolors(sender.getDisplayName()))
|
if player.isOnline():
|
||||||
|
friendmessage(player.getPlayer(), "&a&o%s &aadded you to their friends list" % stripcolors(sender.getDisplayName()))
|
||||||
|
else:
|
||||||
|
added_self = True
|
||||||
else:
|
else:
|
||||||
friendalready.append(player.getName())
|
friendalready.append(player.getName())
|
||||||
|
|
||||||
@@ -80,10 +95,10 @@ def add(sender, names):
|
|||||||
if added:
|
if added:
|
||||||
friendmessage(sender, "&a&o%s&a added." % ", ".join(added))
|
friendmessage(sender, "&a&o%s&a added." % ", ".join(added))
|
||||||
if notfound:
|
if notfound:
|
||||||
friendmessage(sender, "&c&o%s&c not found. (must be online)" % ", ".join(notfound))
|
friendmessage(sender, "&c&o%s&c not found." % ", ".join(notfound))
|
||||||
if friendalready:
|
if friendalready:
|
||||||
friendmessage(sender, "&c&o%s&c is/are already your friend." % ", ".join(friendalready))
|
friendmessage(sender, "&c&o%s&c is/are already your friend." % ", ".join(friendalready))
|
||||||
if not not_yourself:
|
if added_self:
|
||||||
friendmessage(sender, "&cYou can't add yourself to your friends list.")
|
friendmessage(sender, "&cYou can't add yourself to your friends list.")
|
||||||
|
|
||||||
|
|
||||||
@@ -94,18 +109,21 @@ def rem(sender, names):
|
|||||||
notafriend = []
|
notafriend = []
|
||||||
|
|
||||||
for name in names:
|
for name in names:
|
||||||
player = server.Player(name)
|
player = get_player(name)
|
||||||
if player:
|
if player:
|
||||||
player_id = uid(player)
|
player_id = uid(player)
|
||||||
if player_id in friends.get(sender_id, []):
|
if player_id in friends.get(sender_id, []):
|
||||||
friends[sender_id].remove(player_id)
|
friends[sender_id].remove(player_id)
|
||||||
removed.append(player.getName())
|
removed.append(player.getName())
|
||||||
friendmessage(player.getPlayer(), "&c&o%s &cremoved you from their friends list" % stripcolors(sender.getDisplayName()))
|
if player.isOnline():
|
||||||
|
friendmessage(player.getPlayer(), "&c&o%s &cremoved you from their friends list" % stripcolors(sender.getDisplayName()))
|
||||||
else:
|
else:
|
||||||
notafriend.append(player.getName())
|
notafriend.append(player.getName())
|
||||||
else:
|
else:
|
||||||
notfound.append(name)
|
notfound.append(name)
|
||||||
|
|
||||||
|
if not friends.get(sender_id, False):
|
||||||
|
del friends[sender_id]
|
||||||
save_friends()
|
save_friends()
|
||||||
if removed:
|
if removed:
|
||||||
friendmessage(sender, "&a&o%s&a removed." % ", ".join(removed))
|
friendmessage(sender, "&a&o%s&a removed." % ", ".join(removed))
|
||||||
@@ -126,35 +144,38 @@ def fhelp(sender):
|
|||||||
|
|
||||||
@hook.command("friends")
|
@hook.command("friends")
|
||||||
def on_friend_command(sender, command, label, args):
|
def on_friend_command(sender, command, label, args):
|
||||||
if not is_player(sender):
|
try:
|
||||||
friendmessage(sender, "&c&lYou can't have friends!")
|
if not is_player(sender):
|
||||||
|
friendmessage(sender, "&c&lYou can't have friends!")
|
||||||
|
return True
|
||||||
|
|
||||||
|
cmd = args[0] if args else None
|
||||||
|
fargs = args[1:]
|
||||||
|
|
||||||
|
# /friends list
|
||||||
|
if cmd in ["list", "lst", "*"]:
|
||||||
|
thread.start_new_thread(ls, (sender,))
|
||||||
|
|
||||||
|
# /friends clear
|
||||||
|
elif cmd in ["clear", "/"]:
|
||||||
|
clear(sender)
|
||||||
|
|
||||||
|
# /friends add <names>
|
||||||
|
elif cmd in ["add", "+"]:
|
||||||
|
if fargs:
|
||||||
|
add(sender, fargs)
|
||||||
|
else:
|
||||||
|
fhelp(sender)
|
||||||
|
|
||||||
|
# /friends remove <names>
|
||||||
|
elif cmd in ["remove", "rem", "delete", "del", "-"]:
|
||||||
|
if fargs:
|
||||||
|
rem(sender, fargs)
|
||||||
|
else:
|
||||||
|
fhelp(sender)
|
||||||
|
|
||||||
|
else:
|
||||||
|
fhelp(sender)
|
||||||
return True
|
return True
|
||||||
|
except:
|
||||||
cmd = args[0] if args else None
|
error(trace())
|
||||||
fargs = args[1:]
|
|
||||||
|
|
||||||
# /friends list
|
|
||||||
if cmd in ["list", "lst", "*"]:
|
|
||||||
thread.start_new_thread(ls, (sender,))
|
|
||||||
|
|
||||||
# /friends clear
|
|
||||||
elif cmd in ["clear", "/"]:
|
|
||||||
clear(sender)
|
|
||||||
|
|
||||||
# /friends add <names>
|
|
||||||
elif cmd in ["add", "+"]:
|
|
||||||
if fargs:
|
|
||||||
add(sender, fargs)
|
|
||||||
else:
|
|
||||||
fhelp(sender)
|
|
||||||
|
|
||||||
# /friends remove <names>
|
|
||||||
elif cmd in ["remove", "rem", "delete", "del", "-"]:
|
|
||||||
if fargs:
|
|
||||||
rem(sender, fargs)
|
|
||||||
else:
|
|
||||||
fhelp(sender)
|
|
||||||
|
|
||||||
else:
|
|
||||||
fhelp(sender)
|
|
||||||
return True
|
|
||||||
|
|||||||
43
helpers.py
43
helpers.py
@@ -11,8 +11,6 @@ import org.bukkit.block as bblock
|
|||||||
import org.bukkit.event.entity as entity
|
import org.bukkit.event.entity as entity
|
||||||
import org.bukkit.command.ConsoleCommandSender
|
import org.bukkit.command.ConsoleCommandSender
|
||||||
from org.bukkit.entity import *
|
from org.bukkit.entity import *
|
||||||
from player import get_py_player
|
|
||||||
from player import py_players
|
|
||||||
|
|
||||||
#Imports for async query
|
#Imports for async query
|
||||||
from secrets import *
|
from secrets import *
|
||||||
@@ -260,13 +258,15 @@ def toggle(player, ls, name = "Toggle", add = None):
|
|||||||
If add is given, True explicitely adds it whereas False removes it
|
If add is given, True explicitely adds it whereas False removes it
|
||||||
"""
|
"""
|
||||||
pid = uid(player)
|
pid = uid(player)
|
||||||
if pid in ls or add == False:
|
if pid in ls or add is False:
|
||||||
ls.remove(pid)
|
ls.remove(pid)
|
||||||
msg(player, "&a%s turned off!" % name)
|
msg(player, "&a%s turned off!" % name)
|
||||||
elif add != False:
|
elif add is not False:
|
||||||
ls.append(pid)
|
ls.append(pid)
|
||||||
msg(player, "&a%s turned on!" % name)
|
msg(player, "&a%s turned on!" % name)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def send_JSON_message(playername, message):
|
def send_JSON_message(playername, message):
|
||||||
bukkit.Bukkit.getServer().dispatchCommand(bukkit.Bukkit.getServer().getConsoleSender(), "tellraw " + playername + " " + message)
|
bukkit.Bukkit.getServer().dispatchCommand(bukkit.Bukkit.getServer().getConsoleSender(), "tellraw " + playername + " " + message)
|
||||||
|
|
||||||
@@ -294,23 +294,30 @@ def is_ip(tocheck):
|
|||||||
|
|
||||||
# Allows the use of e.g. numeric permission nodes like "permission.amount.5" and similar.
|
# Allows the use of e.g. numeric permission nodes like "permission.amount.5" and similar.
|
||||||
# To get the data fetch the player and the start of the permission node, looking like "permission.amount."
|
# To get the data fetch the player and the start of the permission node, looking like "permission.amount."
|
||||||
def get_permission_content(player, permnode):
|
def get_permission_content(player, permnode, default_value = None):
|
||||||
perms = player.getEffectivePermissions()
|
try:
|
||||||
for perm in perms:
|
perms = player.getEffectivePermissions()
|
||||||
if str(perm.getPermission()).startswith(permnode):
|
for perm in perms:
|
||||||
return str(perm.getPermission()).replace(permnode, "")
|
if str(perm.getPermission()).startswith(permnode):
|
||||||
|
return str(perm.getPermission())[len(permnode):]
|
||||||
|
return default_value
|
||||||
# Gets an online player from their name
|
except:
|
||||||
def get_player(name):
|
error(trace())
|
||||||
for p in bukkit.Bukkit.getServer().getOnlinePlayers():
|
|
||||||
if p.getName().lower() == name.lower():
|
|
||||||
return p
|
|
||||||
return None
|
|
||||||
|
|
||||||
|
|
||||||
def array_to_list(array):
|
def array_to_list(array):
|
||||||
return_list = []
|
return_list = []
|
||||||
for a in array:
|
for a in array:
|
||||||
return_list += [a]
|
return_list.append(a)
|
||||||
return return_list
|
return return_list
|
||||||
|
|
||||||
|
|
||||||
|
#debug wrapper
|
||||||
|
def debug(func):
|
||||||
|
def wrap(*args, **kwargs):
|
||||||
|
try:
|
||||||
|
return func(*args, **kwargs)
|
||||||
|
except:
|
||||||
|
error(trace())
|
||||||
|
return None
|
||||||
|
return wrap
|
||||||
|
|||||||
380
imbusy.py
380
imbusy.py
@@ -1,114 +1,318 @@
|
|||||||
# I'M BUSY! Plugin by Curs3d #
|
"""
|
||||||
##############################
|
This plugin permits users to
|
||||||
# Concept by CookieManors :D #
|
send a command that renders
|
||||||
# http://bit.ly/1GnNPW8 #
|
them "busy", not letting them
|
||||||
##############################
|
to get tpa requests or direct
|
||||||
# This plugin permits users to
|
messages, except from console.
|
||||||
# send a command that renders
|
On restart, all busy data will
|
||||||
# them "busy", not letting them
|
be cleared.
|
||||||
# to get tpa requests or direct
|
"""
|
||||||
# messages, except from console.
|
|
||||||
# On restart, all busy data will
|
|
||||||
# be cleared.
|
|
||||||
|
|
||||||
from helpers import *
|
from helpers import *
|
||||||
from basecommands import simplecommand
|
from friends import is_friend_of
|
||||||
from traceback import format_exc as trace
|
import org.bukkit.command.Command as Command
|
||||||
busy_players = []
|
from time import time as now
|
||||||
|
|
||||||
|
imbusy_version = "v1.1.0"
|
||||||
|
|
||||||
|
base_permission = "utils.imbusy" # for /busy status
|
||||||
|
use_permission = "utils.imbusy.use" # for being busy
|
||||||
|
override_permission = "utils.imbusy.override" # for being able to bother busy people
|
||||||
|
|
||||||
|
busy_status_change_timeout = 15 # seconds
|
||||||
|
|
||||||
|
busy_players = {} # name : (status, timeout_expire)
|
||||||
|
# possible statuses: True if SUPER busy, False if normal busy, None if not busy
|
||||||
|
|
||||||
|
|
||||||
def unclear():
|
@hook.command("imbusy",
|
||||||
msg(sender, "Umm, what? Sorry, directions unlclear, got head stuck in washing machine")
|
aliases = ["busy"],
|
||||||
|
usage = "/<command> [on, off, status/check]",
|
||||||
|
description = "Offers control over your busy status"
|
||||||
@hook.command("busy",
|
|
||||||
aliases = ["focus"],
|
|
||||||
usage = "/<command> <on|off|status>",
|
|
||||||
description = "Sets busy mode on, you cannot recieve tpas and MSGs"
|
|
||||||
)
|
)
|
||||||
|
@debug
|
||||||
def on_busy_command(sender, cmd, label, args):
|
def on_busy_command(sender, cmd, label, args):
|
||||||
|
|
||||||
if not is_player(sender):
|
if not is_player(sender):
|
||||||
msg(sender, "Sorry, Console cannot be busy")
|
msg(sender, "&7Sorry, Console cannot be busy")
|
||||||
return True
|
return True
|
||||||
|
|
||||||
if not sender.hasPermission("utils.busy.allowed"):
|
plugin_header(recipient = sender, name = "I'M BUSY!")
|
||||||
plugin_header(recipient = sender, name = "I'M BUSY!")
|
|
||||||
|
if not sender.hasPermission(base_permission):
|
||||||
noperm(sender)
|
noperm(sender)
|
||||||
return True
|
return True
|
||||||
|
|
||||||
if len(args) == 0:
|
if len(args) == 0:
|
||||||
plugin_header(recipient = sender, name = "I'M BUSY!")
|
return toggle(sender)
|
||||||
msg(sender, "This plugin allows being busy, and when turned on you will not recieve any direct messages or tpa requests.")
|
|
||||||
msg(sender, "\nCommands:")
|
|
||||||
msg(sender, "/busy on: turns on busy mode")
|
|
||||||
msg(sender, "/busy off: turns off busy mode")
|
|
||||||
msg(sender, "/busy status [player]: shows your or [player]'s current busy status.")
|
|
||||||
return True
|
|
||||||
|
|
||||||
elif len(args) == 1:
|
arg0 = args[0].lower()
|
||||||
if args[0] == "on":
|
if arg0 == "on":
|
||||||
if sender.getName() in busy_players:
|
return on(sender)
|
||||||
plugin_header(recipient = sender, name = "I'M BUSY!")
|
if arg0 == "off":
|
||||||
msg(sender, "You cannot be even more focused than this without being a jedi!")
|
return off(sender)
|
||||||
return True
|
if arg0 in ("status", "check"):
|
||||||
busy_players.append(sender.getName())
|
return status(sender, args[1:])
|
||||||
plugin_header(recipient = sender, name = "I'M BUSY!")
|
if arg0 == "super":
|
||||||
broadcast(None, "%s is now SUPER busy! Don't even TRY bothering them, it will not work!" % sender.getName())
|
return super_cmd(sender)
|
||||||
return True
|
return help(sender)
|
||||||
|
|
||||||
elif args[0] == "off":
|
|
||||||
plugin_header(recipient = sender, name = "I'M BUSY!")
|
|
||||||
try:
|
|
||||||
busy_players.remove(sender.getName())
|
|
||||||
msg(sender, "Master has sent /busy command, %s is freeee!" % sender.getName())
|
|
||||||
return True
|
|
||||||
except ValueError:
|
|
||||||
msg(sender, "You are not busy! You cannot be even less busy! Are you perhaps bored?")
|
|
||||||
return True
|
|
||||||
|
|
||||||
elif args[0] == "status":
|
def change_status(target, status):
|
||||||
plugin_header(recipient = sender, name = "I'M BUSY!")
|
target_name = target.getName()
|
||||||
if sender.getName() in busy_players:
|
old_status = None
|
||||||
msg(sender, "You are super-duper busy and concentrated right now. Think, think, think!")
|
if target_name in busy_players:
|
||||||
return True
|
value = busy_players[target_name]
|
||||||
else:
|
time_left = value[1] - now()
|
||||||
msg(sender, "You are completely unable to focus right now.")
|
if time_left > 0:
|
||||||
return True
|
msg(target, "&cYou must wait %.2fs untill you can change your status" % time_left)
|
||||||
|
return
|
||||||
|
old_status = value[0]
|
||||||
|
|
||||||
|
if old_status is status:
|
||||||
|
if status is True:
|
||||||
|
msg(target, "&cYou are already SUPER busy")
|
||||||
|
elif status is False:
|
||||||
|
msg(target, "&cYou are already busy")
|
||||||
else:
|
else:
|
||||||
plugin_header(recipient = sender, name = "I'M BUSY!")
|
msg(target, "&cYou weren't busy yet")
|
||||||
unclear()
|
return
|
||||||
return False
|
|
||||||
|
|
||||||
elif len(args) == 2 and args[0] == "status":
|
|
||||||
plugin_header(recipient = sender, name = "I'M BUSY!")
|
|
||||||
if args[1] in busy_players:
|
|
||||||
msg(sender, "Yes, %s is busy. Shhh..." % args[1])
|
|
||||||
return True
|
|
||||||
else:
|
|
||||||
msg(sender, "No, you're good. Feel free to chat with %s!" % args[1])
|
|
||||||
return True
|
|
||||||
|
|
||||||
|
busy_players[target_name] = (status, now() + busy_status_change_timeout)
|
||||||
|
if status is True:
|
||||||
|
broadcast(None, target.getDisplayName() + " &7is now SUPER busy")
|
||||||
|
elif status is False:
|
||||||
|
broadcast(None, target.getDisplayName() + " &7is now busy")
|
||||||
else:
|
else:
|
||||||
plugin_header(recipient = sender, name = "I'M BUSY!")
|
broadcast(None, target.getDisplayName() + " &7is not busy anymore")
|
||||||
unclear()
|
|
||||||
return False
|
|
||||||
|
|
||||||
|
|
||||||
@hook.event("player.PlayerCommandPreprocessEvent", "monitor")
|
def get_status(target):
|
||||||
def on_cmd_preprocess_event(event):
|
return busy_players.get(target.getName(), (None,))[0]
|
||||||
message = event.getMessage().split(" ")
|
|
||||||
if message[0] == "/msg" or message[0] == "/w" or message[0] == "/m" or \
|
|
||||||
message[0] == "/tell" or message[0] == "/tpa" or message[0] == "/tpahere":
|
def toggle(sender):
|
||||||
if message[1] in busy_players:
|
if not sender.hasPermission(use_permission):
|
||||||
plugin_header(recipient = event.getPlayer(), name = "I'M BUSY!")
|
noperm(sender)
|
||||||
msg(event.getPlayer(), "We are sorry, but %s is currently busy. Please try again later." % message[1])
|
return True
|
||||||
event.setCancelled(True)
|
if get_status(sender) is None:
|
||||||
|
change_status(sender, False)
|
||||||
|
else:
|
||||||
|
change_status(sender, None)
|
||||||
|
return True
|
||||||
|
|
||||||
|
|
||||||
|
def help(sender):
|
||||||
|
msg(sender, "Let's you put yourself in busy status, preventing pms and tpa requests from other players")
|
||||||
|
msg(sender, "\n&eCommands:")
|
||||||
|
msg(sender, "&e/busy &7- Toggles busy status")
|
||||||
|
msg(sender, "&e/busy on &7- Turns on busy status")
|
||||||
|
msg(sender, "&e/busy off &7- Turns off busy status")
|
||||||
|
msg(sender, "&e/busy status [player] &7- shows your or [player]'s current busy status")
|
||||||
|
msg(sender, "&e/busy super &7- sets your status to SUPER busy such that even friends can not bother you")
|
||||||
|
return True
|
||||||
|
|
||||||
|
|
||||||
|
def on(sender):
|
||||||
|
if not sender.hasPermission(use_permission):
|
||||||
|
noperm(sender)
|
||||||
|
return True
|
||||||
|
change_status(sender, False)
|
||||||
|
return True
|
||||||
|
|
||||||
|
|
||||||
|
def off(sender):
|
||||||
|
if not sender.hasPermission(use_permission):
|
||||||
|
noperm(sender)
|
||||||
|
return True
|
||||||
|
change_status(sender, None)
|
||||||
|
return True
|
||||||
|
|
||||||
|
|
||||||
|
def status(sender, args):
|
||||||
|
if not sender.hasPermission(base_permission):
|
||||||
|
noperm(sender)
|
||||||
|
return True
|
||||||
|
if len(args) == 0:
|
||||||
|
target = sender
|
||||||
|
else:
|
||||||
|
target = server.getPlayer(args[0])
|
||||||
|
if target is None:
|
||||||
|
msg(sender, "&cThat player is not online")
|
||||||
|
return True
|
||||||
|
status = get_status(target)
|
||||||
|
if status is True:
|
||||||
|
status_str = "SUPER busy"
|
||||||
|
elif status is False:
|
||||||
|
status_str = "busy"
|
||||||
|
else:
|
||||||
|
status_str = "not busy"
|
||||||
|
msg(sender, "&7%s currently %s" % ("You are" if target is sender else "Player %s&7 is" % target.getDisplayName()), status_str)
|
||||||
|
return True
|
||||||
|
|
||||||
|
|
||||||
|
def super_cmd(sender):
|
||||||
|
if not sender.hasPermission(use_permission):
|
||||||
|
noperm(sender)
|
||||||
|
return True
|
||||||
|
change_status(sender, True)
|
||||||
|
return True
|
||||||
|
|
||||||
|
|
||||||
@hook.event("player.PlayerQuitEvent", "lowest")
|
@hook.event("player.PlayerQuitEvent", "lowest")
|
||||||
def on_player_leave(event):
|
def on_player_leave(event):
|
||||||
|
player_name = event.getPlayer().getName()
|
||||||
|
if player_name in busy_players:
|
||||||
|
del busy_players[player_name]
|
||||||
|
|
||||||
|
|
||||||
|
# Block any bothering if should be. If a busy player msgs someone else, they can be replied to and /msg'd as well.
|
||||||
|
# It's not entirely perfect in that regard as the ability to reply is lost when you are /msg'd by someone else.
|
||||||
|
|
||||||
|
reply_targets = {} # name : (reply_target_name, true if initiated by target)
|
||||||
|
|
||||||
|
|
||||||
|
def can_send(sender, target):
|
||||||
|
if target is sender or sender.hasPermission(override_permission):
|
||||||
|
return True
|
||||||
|
status = get_status(target)
|
||||||
|
if status is None:
|
||||||
|
return True
|
||||||
|
return status is False and is_friend_of(target, sender)
|
||||||
|
|
||||||
|
|
||||||
|
def whisper(sender, target_name):
|
||||||
|
target = server.getPlayer(target_name)
|
||||||
|
|
||||||
|
if target is not None:
|
||||||
|
sender_name = sender.getName()
|
||||||
|
if not can_send(sender, target):
|
||||||
|
value = reply_targets[sender_name]
|
||||||
|
if value[0] != target_name or value[1] is False:
|
||||||
|
msg(sender, "&c[&fBUSY&c] %s&r is busy!" % target.getDisplayName())
|
||||||
|
return False
|
||||||
|
|
||||||
|
reply_targets[sender_name] = (target_name, False)
|
||||||
|
reply_targets[target_name] = (sender_name, True)
|
||||||
|
return True
|
||||||
|
|
||||||
|
|
||||||
|
def reply(sender):
|
||||||
|
sender_name = sender.getName()
|
||||||
|
if sender_name in reply_targets:
|
||||||
|
value = reply_targets[sender_name]
|
||||||
|
target = server.getPlayer(value[0])
|
||||||
|
if target is not None:
|
||||||
|
if not value[1] and not can_send(sender, target):
|
||||||
|
msg(sender, "&c[&fBUSY&c] %s&r is busy!" % target.getDisplayName())
|
||||||
|
return False
|
||||||
|
|
||||||
|
reply_targets[target.getName()] = (sender_name, True)
|
||||||
|
return True
|
||||||
|
|
||||||
|
|
||||||
|
class CommandWrapper(Command):
|
||||||
|
|
||||||
|
def __init__(self, wrapped, checker):
|
||||||
|
Command.__init__(self, wrapped.getName())
|
||||||
|
self.setDescription(wrapped.getDescription())
|
||||||
|
self.setPermission(wrapped.getPermission())
|
||||||
|
self.setUsage(wrapped.getUsage())
|
||||||
|
self.setAliases(wrapped.getAliases())
|
||||||
|
self.wrapped = wrapped
|
||||||
|
self.checker = checker
|
||||||
|
|
||||||
|
def execute(self, sender, label, args):
|
||||||
|
try:
|
||||||
|
if not is_player(sender) or self.checker(sender, args):
|
||||||
|
return self.wrapped.execute(sender, label, args)
|
||||||
|
except:
|
||||||
|
error(trace())
|
||||||
|
return True
|
||||||
|
|
||||||
|
def tabComplete(self, sender, alias, args):
|
||||||
|
return self.wrapped.tabComplete(sender, alias, args)
|
||||||
|
|
||||||
|
|
||||||
|
def msg_command_checker(sender, args):
|
||||||
|
return len(args) <= 1 or whisper(sender, args[0])
|
||||||
|
|
||||||
|
def reply_command_checker(sender, args):
|
||||||
|
return len(args) == 0 or reply(sender)
|
||||||
|
|
||||||
|
def tpa_command_checker(sender, args):
|
||||||
|
if len(args) == 0:
|
||||||
|
return True
|
||||||
|
target = server.getPlayer(args[0])
|
||||||
|
if target is not None and not can_send(sender, target):
|
||||||
|
msg(sender, "&c[&fBUSY&c] %s&r is busy!" % target.getDisplayName())
|
||||||
|
return False
|
||||||
|
return True
|
||||||
|
|
||||||
|
def tpahere_command_checker(sender, args):
|
||||||
|
return tpa_command_checker(sender, args)
|
||||||
|
|
||||||
|
def mail_command_checker(sender, args):
|
||||||
|
if len(args) < 3 or args[0].lower() != "send":
|
||||||
|
return True
|
||||||
|
target = server.getPlayer(args[1])
|
||||||
|
if target is not None and not can_send(sender, target):
|
||||||
|
msg(sender, "&c[&fBUSY&c] %s&r is busy!" % target.getDisplayName())
|
||||||
|
return False
|
||||||
|
return True
|
||||||
|
|
||||||
|
|
||||||
|
@hook.event("player.PlayerCommandPreprocessEvent", "monitor")
|
||||||
|
def on_player_command_preprocess(event):
|
||||||
|
message = event.getMessage().split(" ")
|
||||||
|
if len(message) > 1 and message[0].lower() in ("/tell", "/minecraft:tell") and not whisper(event.getPlayer(), message[1]):
|
||||||
|
event.setCancelled(True)
|
||||||
|
|
||||||
|
|
||||||
|
def replace_ess_commands():
|
||||||
|
|
||||||
try:
|
try:
|
||||||
busy_players.remove(event.getPlayer().getName())
|
map_field = server.getPluginManager().getClass().getDeclaredField("commandMap")
|
||||||
|
map_field.setAccessible(True)
|
||||||
|
command_map = map_field.get(server.getPluginManager())
|
||||||
|
|
||||||
|
commands_field = command_map.getClass().getDeclaredField("knownCommands")
|
||||||
|
commands_field.setAccessible(True)
|
||||||
|
map = commands_field.get(command_map)
|
||||||
|
|
||||||
|
ess_msg_cmd = map.get("essentials:msg")
|
||||||
|
ess_reply_cmd = map.get("essentials:reply")
|
||||||
|
ess_tpa_cmd = map.get("essentials:tpa")
|
||||||
|
ess_tpahere_cmd = map.get("essentials:tpahere")
|
||||||
|
ess_mail_cmd = map.get("essentials:mail")
|
||||||
|
|
||||||
|
msg_cmd_wrapper = CommandWrapper(ess_msg_cmd, msg_command_checker)
|
||||||
|
reply_cmd_wrapper = CommandWrapper(ess_reply_cmd, reply_command_checker)
|
||||||
|
tpa_cmd_wrapper = CommandWrapper(ess_tpa_cmd, tpa_command_checker)
|
||||||
|
tpahere_cmd_wrapper = CommandWrapper(ess_tpahere_cmd, tpahere_command_checker)
|
||||||
|
mail_cmd_wrapper = CommandWrapper(ess_mail_cmd, mail_command_checker)
|
||||||
|
|
||||||
|
iterator = map.entrySet().iterator()
|
||||||
|
wrapped_commands = []
|
||||||
|
while iterator.hasNext():
|
||||||
|
entry = iterator.next()
|
||||||
|
value = entry.getValue()
|
||||||
|
changed = True
|
||||||
|
if value is ess_msg_cmd:
|
||||||
|
entry.setValue(msg_cmd_wrapper)
|
||||||
|
elif value is ess_reply_cmd:
|
||||||
|
entry.setValue(reply_cmd_wrapper)
|
||||||
|
elif value is ess_tpa_cmd:
|
||||||
|
entry.setValue(tpa_cmd_wrapper)
|
||||||
|
elif value is ess_tpahere_cmd:
|
||||||
|
entry.setValue(tpahere_cmd_wrapper)
|
||||||
|
elif value is ess_mail_cmd:
|
||||||
|
entry.setValue(mail_cmd_wrapper)
|
||||||
|
else:
|
||||||
|
changed = False
|
||||||
|
if changed:
|
||||||
|
wrapped_commands.append(entry.getKey())
|
||||||
|
info("[imbusy] wrapped commands: /" + ", /".join(wrapped_commands))
|
||||||
|
|
||||||
except:
|
except:
|
||||||
pass
|
error("[Imbusy] Failed to wrap essentials commands")
|
||||||
|
error(trace())
|
||||||
|
|||||||
@@ -7,11 +7,12 @@ from login_secrets import * #Don't forget to make login_secrets aswell
|
|||||||
import mysqlhack
|
import mysqlhack
|
||||||
from com.ziclix.python.sql import zxJDBC
|
from com.ziclix.python.sql import zxJDBC
|
||||||
from java.lang import Runnable
|
from java.lang import Runnable
|
||||||
|
from player import get_py_player, py_players
|
||||||
|
|
||||||
wait_time = 30 #seconds
|
wait_time = 30 #seconds
|
||||||
admin_perm = "utils.loginsecurity.admin"
|
admin_perm = "utils.loginsecurity.admin"
|
||||||
min_pass_length = 8
|
min_pass_length = 8
|
||||||
blocked_events = ["block.BlockBreakEvent", "block.BlockPlaceEvent", "player.PlayerMoveEvent","player.AsyncPlayerChatEvent"]
|
blocked_events = ["block.BlockBreakEvent", "block.BlockPlaceEvent", "player.AsyncPlayerChatEvent"]
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -273,3 +274,9 @@ def pre_command_proccess(event):
|
|||||||
if not args[0].lower() == "/login":
|
if not args[0].lower() == "/login":
|
||||||
msg(player.player, "&4You need to login before you do that!")
|
msg(player.player, "&4You need to login before you do that!")
|
||||||
event.setCancelled(True)
|
event.setCancelled(True)
|
||||||
|
|
||||||
|
@hook.event("player.PlayerMoveEvent","normal")
|
||||||
|
def player_move(event):
|
||||||
|
user = get_py_player(event.getPlayer())
|
||||||
|
if user.logging_in:
|
||||||
|
event.setTo(event.getFrom())
|
||||||
|
|||||||
13
main.py
13
main.py
@@ -19,12 +19,19 @@ except:
|
|||||||
|
|
||||||
@hook.enable
|
@hook.enable
|
||||||
def on_enable():
|
def on_enable():
|
||||||
|
if "blockplacemods" in shared["modules"]:
|
||||||
|
shared["modules"]["blockplacemods"].schedule_torch_breaker()
|
||||||
|
if "imbusy" in shared["modules"]:
|
||||||
|
shared["modules"]["imbusy"].replace_ess_commands()
|
||||||
|
if "serversigns" in shared["modules"]:
|
||||||
|
shared["modules"]["serversigns"].check_all_signs_and_force_commands()
|
||||||
info("RedstonerUtils enabled!")
|
info("RedstonerUtils enabled!")
|
||||||
|
|
||||||
|
|
||||||
@hook.disable
|
@hook.disable
|
||||||
def on_disable():
|
def on_disable():
|
||||||
shared["modules"]["reports"].stop_reporting()
|
if "reports" in shared["modules"]:
|
||||||
|
shared["modules"]["reports"].stop_reporting()
|
||||||
info("RedstonerUtils disabled!")
|
info("RedstonerUtils disabled!")
|
||||||
|
|
||||||
|
|
||||||
@@ -43,7 +50,9 @@ shared["load_modules"] = [
|
|||||||
# Adds /calc, toggles automatic solving of Math expressions in chat
|
# Adds /calc, toggles automatic solving of Math expressions in chat
|
||||||
"calc",
|
"calc",
|
||||||
# Adds aliasing of chat words
|
# Adds aliasing of chat words
|
||||||
#"chatalias",
|
"chatalias",
|
||||||
|
# For players to point friends
|
||||||
|
"friends",
|
||||||
# Plugin to locate laggy chunks. /lc <n> lists chunks with more than n entities
|
# Plugin to locate laggy chunks. /lc <n> lists chunks with more than n entities
|
||||||
"lagchunks",
|
"lagchunks",
|
||||||
# Adds /report and /rp, Stores reports with time and location
|
# Adds /report and /rp, Stores reports with time and location
|
||||||
|
|||||||
15
misc.py
15
misc.py
@@ -127,7 +127,7 @@ def on_interact(event):
|
|||||||
|
|
||||||
sudo_blacklist = ["pyeval", "script_backup_begin", "script_backup_end", "script_backup_error", "script_backup_database_begin", "script_backup_database_dumps", "script_backup_database_end",
|
sudo_blacklist = ["pyeval", "script_backup_begin", "script_backup_end", "script_backup_error", "script_backup_database_begin", "script_backup_database_dumps", "script_backup_database_end",
|
||||||
"script_backup_database_error", "script_backup_database_abort", "script_trim", "script_trim_result", "script_spigot_update", "script_disk_filled", "script_restart", "script_restart_abort",
|
"script_backup_database_error", "script_backup_database_abort", "script_trim", "script_trim_result", "script_spigot_update", "script_disk_filled", "script_restart", "script_restart_abort",
|
||||||
"script_stop", "script_stop_abort", "script_shutdown", "stop", "esudo", "essentials:sudo", "sudo"]
|
"script_stop", "script_stop_abort", "script_shutdown", "stop", "esudo", "essentials:sudo", "sudo", "essentials:esudo"]
|
||||||
|
|
||||||
@simplecommand("sudo",
|
@simplecommand("sudo",
|
||||||
usage = "<player> [cmd..]",
|
usage = "<player> [cmd..]",
|
||||||
@@ -212,12 +212,13 @@ def eval_thread(sender, code):
|
|||||||
msg(sender, ">>> %s: %s" % (eclass.__name__, e) + "\n ", False, "c")
|
msg(sender, ">>> %s: %s" % (eclass.__name__, e) + "\n ", False, "c")
|
||||||
thread.exit()
|
thread.exit()
|
||||||
|
|
||||||
pythoners = [
|
pythoners = (
|
||||||
"e452e012-2c82-456d-853b-3ac8e6b581f5", # Nemes
|
"e452e012-2c82-456d-853b-3ac8e6b581f5", # Nemes
|
||||||
"ae795aa8-6327-408e-92ab-25c8a59f3ba1", # jomo
|
"ae795aa8-6327-408e-92ab-25c8a59f3ba1", # jomo
|
||||||
"305ccbd7-0589-403e-a45b-d791dcfdee7d", # PanFritz
|
"d2693e91-93e1-4e3f-929f-f38e1ce8df03", # Pepich1851
|
||||||
"51f2ad3c-6cc8-40ea-aa2b-f25970316921" # Dico
|
"51f2ad3c-6cc8-40ea-aa2b-f25970316921", # Dico200
|
||||||
]
|
"15ad0e60-8691-4e29-9de9-2d6b538bf56d" # psrcek
|
||||||
|
)
|
||||||
|
|
||||||
@simplecommand("pyeval",
|
@simplecommand("pyeval",
|
||||||
usage = "[code..]",
|
usage = "[code..]",
|
||||||
|
|||||||
@@ -25,5 +25,6 @@ def on_join(event):
|
|||||||
|
|
||||||
@hook.event("player.PlayerQuitEvent","highest")
|
@hook.event("player.PlayerQuitEvent","highest")
|
||||||
def on_leave(event):
|
def on_leave(event):
|
||||||
py_players.remove(get_py_player(event.getPlayer()))
|
player = get_py_player(event.getPlayer())
|
||||||
|
if player in py_players:
|
||||||
|
py_players.remove(player)
|
||||||
|
|||||||
30
plotter.py
30
plotter.py
@@ -1,30 +0,0 @@
|
|||||||
#!/usr/bin/python
|
|
||||||
|
|
||||||
"""
|
|
||||||
*Very basic* start of a custom plot-plugin like PlotMe
|
|
||||||
on hold because the PlotMe developer continued to develop PlotMe
|
|
||||||
"""
|
|
||||||
|
|
||||||
import sys
|
|
||||||
|
|
||||||
x_plot_size = 3
|
|
||||||
z_plot_size = 3
|
|
||||||
padding = 1
|
|
||||||
|
|
||||||
def base_coords(x, z):
|
|
||||||
pid = plot_id(x, z)
|
|
||||||
return [pid[0] * (x_plot_size + padding), pid[1] * (z_plot_size + padding)]
|
|
||||||
|
|
||||||
def bounds(x, z):
|
|
||||||
base = base_coords(x, z)
|
|
||||||
return [base, [base[0] + x_plot_size, base[1] + z_plot_size]]
|
|
||||||
|
|
||||||
def plot_id(x, z):
|
|
||||||
return [x // (x_plot_size + padding), z // (z_plot_size + padding)]
|
|
||||||
|
|
||||||
|
|
||||||
x = int(sys.argv[1])
|
|
||||||
z = int(sys.argv[2])
|
|
||||||
print "id: %s" % plot_id(x, z)
|
|
||||||
print "base: %s" % base_coords(x, z)
|
|
||||||
print "bounds: %s" % bounds(x, z)
|
|
||||||
@@ -2,4 +2,3 @@ name: RedstonerUtils
|
|||||||
main: main.py
|
main: main.py
|
||||||
version: 3.1.0
|
version: 3.1.0
|
||||||
author: redstone_sheep
|
author: redstone_sheep
|
||||||
|
|
||||||
|
|||||||
@@ -55,6 +55,7 @@ class Slave(object):
|
|||||||
def update(self):
|
def update(self):
|
||||||
self.blocks -= 1
|
self.blocks -= 1
|
||||||
if self.blocks <= 0:
|
if self.blocks <= 0:
|
||||||
|
server.getPlayer(juuid(self.get_uuid())).teleport(server.getWorld(spawn_world).getSpawnLocation())
|
||||||
server.getPlayer(juuid(self.get_uuid())).teleport(server.getWorld(spawn_world).getSpawnLocation())
|
server.getPlayer(juuid(self.get_uuid())).teleport(server.getWorld(spawn_world).getSpawnLocation())
|
||||||
slaves.remove(self)
|
slaves.remove(self)
|
||||||
save_slaves()
|
save_slaves()
|
||||||
|
|||||||
33
saylol.py
33
saylol.py
@@ -1,11 +1,12 @@
|
|||||||
from time import time
|
from time import time
|
||||||
from helpers import *
|
from helpers import *
|
||||||
from random import randrange
|
from random import randrange
|
||||||
|
import math
|
||||||
|
|
||||||
lols = open_json_file("lol", [])
|
lols = open_json_file("lol", [])
|
||||||
timeout = 15
|
timeout = 15
|
||||||
last_msg = 0
|
last_msg = 0
|
||||||
|
list_limit = 20
|
||||||
|
|
||||||
|
|
||||||
def save_lols():
|
def save_lols():
|
||||||
@@ -69,8 +70,26 @@ def on_lol_command(sender, command, label, args):
|
|||||||
noperm(sender)
|
noperm(sender)
|
||||||
|
|
||||||
elif cmd == "list":
|
elif cmd == "list":
|
||||||
for i in range(len(lols)):
|
arg1 = args[1] if len(args) > 1 else None
|
||||||
|
if not arg1:
|
||||||
|
arg1 = "1"
|
||||||
|
if not arg1.isdigit():
|
||||||
|
msg(sender, "&cInvalid argument \"%s\"" % arg1)
|
||||||
|
return True
|
||||||
|
if int(arg1) == 0:
|
||||||
|
msg(sender, "&cPage 0 does not exist")
|
||||||
|
return True
|
||||||
|
arg1 = int(arg1) - 1
|
||||||
|
offset = list_limit * arg1
|
||||||
|
if offset > len(lols):
|
||||||
|
msg(sender, "&cNot a valid page (too high).")
|
||||||
|
return True
|
||||||
|
msg(sender, " &9&nLol list page %s/%s" % (arg1 + 1, int(math.ceil(len(lols) / float(list_limit))))) #"\t" symbol displays weirdly, hence the 4 spaces
|
||||||
|
for i in range(offset, min(offset + list_limit, len(lols))):
|
||||||
msg(sender, "&a%s: &e%s" % (str(i).rjust(3), lols[i]))
|
msg(sender, "&a%s: &e%s" % (str(i).rjust(3), lols[i]))
|
||||||
|
msg(sender, "")
|
||||||
|
msg(sender, "&eFor a specific page, type &a/lol list <page>&e.")
|
||||||
|
msg(sender, "") #emptyline
|
||||||
|
|
||||||
elif cmd == "search":
|
elif cmd == "search":
|
||||||
if sender.hasPermission("utils.lol.search"):
|
if sender.hasPermission("utils.lol.search"):
|
||||||
@@ -95,9 +114,9 @@ def on_lol_command(sender, command, label, args):
|
|||||||
msg(sender, "&cInvalid number '&e%s&c'" % args[1])
|
msg(sender, "&cInvalid number '&e%s&c'" % args[1])
|
||||||
|
|
||||||
else:
|
else:
|
||||||
msg(sender, "&a/lol &eSay random message")
|
msg(sender, "&a/lol &eSay random message")
|
||||||
msg(sender, "&a/lol list &eList all messages")
|
msg(sender, "&a/lol list [page] &eList messages")
|
||||||
msg(sender, "&a/lol id <id> &eSay specific message")
|
msg(sender, "&a/lol id <id> &eSay specific message")
|
||||||
msg(sender, "&a/lol add <text> &eAdd message")
|
msg(sender, "&a/lol add <text> &eAdd message")
|
||||||
msg(sender, "&a/lol del <id> &eDelete message")
|
msg(sender, "&a/lol del <id> &eDelete message")
|
||||||
return True
|
return True
|
||||||
|
|||||||
237
serversigns.py
237
serversigns.py
@@ -4,8 +4,26 @@ import org.bukkit.Material as Material
|
|||||||
import java.util.UUID as UUID
|
import java.util.UUID as UUID
|
||||||
import org.bukkit.Material as Material
|
import org.bukkit.Material as Material
|
||||||
import org.bukkit.block.BlockFace as BlockFace
|
import org.bukkit.block.BlockFace as BlockFace
|
||||||
|
from math import ceil
|
||||||
|
|
||||||
blocked_cmds = tuple(shared["modules"]["misc"].sudo_blacklist) + ("pex", "kick", "ban", "tempban", "reload", "op", "deop", "whitelist")
|
commands_whitelist = (
|
||||||
|
"mail", "email", "memo",
|
||||||
|
"echo", "ping",
|
||||||
|
"cg join",
|
||||||
|
"cg info",
|
||||||
|
"chatgroup join",
|
||||||
|
"chatgroup info",
|
||||||
|
"i",
|
||||||
|
"item",
|
||||||
|
"p h", "plot home", "plot h", "p home", "plotme home", "plotme h",
|
||||||
|
"up",
|
||||||
|
"tppos",
|
||||||
|
"seen",
|
||||||
|
)
|
||||||
|
|
||||||
|
max_line_length = 256
|
||||||
|
max_lines = 20
|
||||||
|
help_page_size = 12
|
||||||
|
|
||||||
def load_signs():
|
def load_signs():
|
||||||
signs_obj = open_json_file("serversigns", [])
|
signs_obj = open_json_file("serversigns", [])
|
||||||
@@ -20,9 +38,11 @@ def save_signs():
|
|||||||
signs_obj.append(key + tuple(value))
|
signs_obj.append(key + tuple(value))
|
||||||
save_json_file("serversigns", signs_obj)
|
save_json_file("serversigns", signs_obj)
|
||||||
|
|
||||||
signs = load_signs() # {("world", x, y, z): ["owner_id", "msg1", "msg2"]}
|
# {("world", x, y, z): ["owner_id", "msg1", "msg2"]}
|
||||||
|
signs = load_signs()
|
||||||
|
|
||||||
lines = {} # Accumulated messages so players can have longer messages: {"Dico200": "Message...........", ""}
|
# Accumulated messages so players can have longer messages: {"Dico200": "Message...........", ""}
|
||||||
|
lines = {}
|
||||||
|
|
||||||
def fromLoc(bLoc):
|
def fromLoc(bLoc):
|
||||||
"""
|
"""
|
||||||
@@ -85,6 +105,46 @@ def signsMsg(msg, colour = '4'):
|
|||||||
return "&c[Signs] &" + colour + msg
|
return "&c[Signs] &" + colour + msg
|
||||||
|
|
||||||
|
|
||||||
|
# /svs command
|
||||||
|
|
||||||
|
|
||||||
|
subcommand_info = (
|
||||||
|
|
||||||
|
(("claim",), (
|
||||||
|
"Claims the sign so that you can add messages to it",
|
||||||
|
), (("[owner]", "claims.other"),)),
|
||||||
|
(("info", "lines"), (
|
||||||
|
"Displays information about the (claimed) sign",
|
||||||
|
)),
|
||||||
|
(("add",), (
|
||||||
|
"Adds the message to the sign. Use ++ at the end",
|
||||||
|
"to add the message to your buffer. You can then use",
|
||||||
|
"the same command again to create a longer message",
|
||||||
|
), (("<message>[++]", None),)),
|
||||||
|
(("remove", "rem", "del", "delete"), (
|
||||||
|
"Removes the message with the given ID from the sign.",
|
||||||
|
"The ID is given before each message by &b/svs info&a.",
|
||||||
|
), (("<message ID>", None),)),
|
||||||
|
(("switch", "reverse"), (
|
||||||
|
"Reverses the order in which the given messages are shown.",
|
||||||
|
), (("<message ID 1> <message ID 2>", None),)),
|
||||||
|
(("clear",), (
|
||||||
|
"Removes all messages from the sign.",
|
||||||
|
)),
|
||||||
|
(("reset", "unclaim"), (
|
||||||
|
"Resets the sign, removing all messages and its owner.",
|
||||||
|
)),
|
||||||
|
(("whitelist", "commands", "wl"), (
|
||||||
|
"Displays a list of whitelisted commands",
|
||||||
|
)),
|
||||||
|
(("help",), (
|
||||||
|
"Displays this help page",
|
||||||
|
), (("[page]", None),)),
|
||||||
|
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@simplecommand(cmd = "serversigns", aliases = ["svs", "signmsg"],
|
@simplecommand(cmd = "serversigns", aliases = ["svs", "signmsg"],
|
||||||
description = "Makes something happen when you right click signs. \nUse /svs help for more details.",
|
description = "Makes something happen when you right click signs. \nUse /svs help for more details.",
|
||||||
usage = "<claim|reset|add <msg>[++]|remove <ID>|clear|info|help>",
|
usage = "<claim|reset|add <msg>[++]|remove <ID>|clear|info|help>",
|
||||||
@@ -92,35 +152,56 @@ def signsMsg(msg, colour = '4'):
|
|||||||
senderLimit = 0)
|
senderLimit = 0)
|
||||||
def svs_command(sender, command, label, args):
|
def svs_command(sender, command, label, args):
|
||||||
arg1 = args[0].lower()
|
arg1 = args[0].lower()
|
||||||
Validate.isTrue(arg1 in ("claim", "reset", "add", "remove", "info", "clear", "help", "switch", "reverse", "unclaim"),
|
|
||||||
signsMsg("That argument could not be recognized, use &o/svs help &4for expected arguments"))
|
cmd_info = None
|
||||||
Validate.isAuthorized(sender, "utils.serversigns." + arg1)
|
for cmd in subcommand_info:
|
||||||
|
if arg1 in cmd[0]:
|
||||||
|
cmd_info = cmd
|
||||||
|
break
|
||||||
|
|
||||||
|
Validate.notNone(cmd_info, signsMsg("That command could not be recognized, use &o/svs help &4for expected arguments"))
|
||||||
|
cmd = cmd_info[0][0]
|
||||||
|
Validate.isAuthorized(sender, "utils.serversigns." + cmd)
|
||||||
|
|
||||||
#-------------------- Sub commands that don't require any conditions -----------------------
|
#-------------------- Sub commands that don't require any conditions -----------------------
|
||||||
if arg1 == "help":
|
if cmd == "help":
|
||||||
admin = sender.hasPermission("utils.serversigns.admin")
|
all_lines = [
|
||||||
msg = signsMsg("Server signs lets you add messages to a sign.", 'a')
|
"&aServer signs let's you add messages to a sign.",
|
||||||
msg += "\nRight clicking the sign will display all the messages. Commands"
|
"Right clicking the sign will display all the messages. Commands",
|
||||||
msg += "\ncan also be added, by prefixing the message with a '/'."
|
"can also be added, by prefixing the message with a '/'.",
|
||||||
msg += "\nHow to use &b/serversigns&a:"
|
"How to use &b/serversigns&a:",
|
||||||
msg += "\n&b/svs claim" + ("" if not sender.hasPermission("utils.serversigns.admin") else " [owner]")
|
]
|
||||||
msg += "\n&a- Claims the sign so that you can add messages to it"
|
|
||||||
msg += "\n&b/svs info"
|
for cmd in subcommand_info:
|
||||||
msg += "\n&a- Displays information about the (claimed) sign"
|
if sender.hasPermission("utils.serversigns." + cmd[0][0]):
|
||||||
msg += "\n&b/svs add <message>[++]"
|
params = ""
|
||||||
msg += "\n&a- Adds the message to the sign. Use ++ at the end"
|
if len(cmd) == 3:
|
||||||
msg += "\n&a- to add the message to your buffer. You can then use"
|
for param, perm in cmd[2]:
|
||||||
msg += "\n&a- the same command again to create a longer message."
|
if perm is None or sender.hasPermission("utils.serversigns." + perm):
|
||||||
msg += "\n&b/svs remove <message ID>"
|
params += param + " "
|
||||||
msg += "\n&a- Removes the message with the given ID from the sign."
|
all_lines.append("&b/svs %s %s" % ("|".join(cmd[0]), params))
|
||||||
msg += "\n&a- The ID is given before each message by &b/svs info&a."
|
for info_line in cmd[1]:
|
||||||
msg += "\n&b/svs switch|reverse <message ID 1> <message ID 2>"
|
all_lines.append("&a- " + info_line)
|
||||||
msg += "\n&a- Reverses the order in which the given messages are shown."
|
|
||||||
msg += "\n&b/svs clear"
|
last_page = int(ceil(len(all_lines) / help_page_size))
|
||||||
msg += "\n&a- Removes all messages from the sign."
|
info("last page: %d" % last_page)
|
||||||
msg += "\n&b/svs reset|unclaim"
|
page = 1
|
||||||
msg += "\n&a- Resets the sign, removing all messages and its owner."
|
if len(args) > 1 and args[1].isdigit():
|
||||||
return msg
|
page = int(args[1])
|
||||||
|
if page <= 0:
|
||||||
|
page = 1
|
||||||
|
elif page > last_page:
|
||||||
|
page = last_page
|
||||||
|
|
||||||
|
first_line = signsMsg("Serversigns help page %d" % page, '6')
|
||||||
|
if page < last_page:
|
||||||
|
first_line += ", &e/svs help %d&6 for the next" % (page + 1)
|
||||||
|
page_lines = [first_line] + all_lines[(page - 1) * help_page_size : min(page * help_page_size, len(all_lines))]
|
||||||
|
return "\n".join(page_lines)
|
||||||
|
|
||||||
|
|
||||||
|
if cmd == "whitelist":
|
||||||
|
return signsMsg("Whitelisted commands: &3" + ", ".join(commands_whitelist), 'a')
|
||||||
#-------------------------------------------------------------------------------------------
|
#-------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
block = sender.getTargetBlock(None, 5)
|
block = sender.getTargetBlock(None, 5)
|
||||||
@@ -132,7 +213,7 @@ def svs_command(sender, command, label, args):
|
|||||||
arg2 = args[1].lower() if len(args) > 1 else None
|
arg2 = args[1].lower() if len(args) > 1 else None
|
||||||
|
|
||||||
#------------------------ Sub commands that require the block to be a sign -------------------------------
|
#------------------------ Sub commands that require the block to be a sign -------------------------------
|
||||||
if arg1 == "claim":
|
if cmd == "claim":
|
||||||
Validate.isTrue(not sign, signsMsg("The %s was already claimed" % signName))
|
Validate.isTrue(not sign, signsMsg("The %s was already claimed" % signName))
|
||||||
Validate.isTrue(can_build2(sender, block), signsMsg("You are not permitted to claim signs here"))
|
Validate.isTrue(can_build2(sender, block), signsMsg("You are not permitted to claim signs here"))
|
||||||
target = sender
|
target = sender
|
||||||
@@ -144,7 +225,7 @@ def svs_command(sender, command, label, args):
|
|||||||
uuid = uid(target)
|
uuid = uid(target)
|
||||||
if sign != None:
|
if sign != None:
|
||||||
if sign[0] == uuid:
|
if sign[0] == uuid:
|
||||||
return signsMsg("The" + signName + " was already owned by that player")
|
return signsMsg("The " + signName + " was already owned by that player")
|
||||||
else:
|
else:
|
||||||
sign[0] = uuid
|
sign[0] = uuid
|
||||||
else:
|
else:
|
||||||
@@ -156,7 +237,7 @@ def svs_command(sender, command, label, args):
|
|||||||
Validate.notNone(sign, signsMsg("The %s has not been claimed" % signName))
|
Validate.notNone(sign, signsMsg("The %s has not been claimed" % signName))
|
||||||
|
|
||||||
#----------------------Sub commands that require the sign to be claimed as well------------------------------------
|
#----------------------Sub commands that require the sign to be claimed as well------------------------------------
|
||||||
if arg1 == "info":
|
if cmd == "info":
|
||||||
sign_lines = ""
|
sign_lines = ""
|
||||||
for id, line in enumerate(sign[1:]):
|
for id, line in enumerate(sign[1:]):
|
||||||
sign_lines += ("\n &a%s: \"&f%s&a\"" % (id + 1, line))
|
sign_lines += ("\n &a%s: \"&f%s&a\"" % (id + 1, line))
|
||||||
@@ -166,26 +247,44 @@ def svs_command(sender, command, label, args):
|
|||||||
Validate.isTrue(canEdit(sign, sender), signsMsg("You do not own the %s!" % signName))
|
Validate.isTrue(canEdit(sign, sender), signsMsg("You do not own the %s!" % signName))
|
||||||
|
|
||||||
#---------------------- Sub commands that require you to own targeted sign as well -------------------------
|
#---------------------- Sub commands that require you to own targeted sign as well -------------------------
|
||||||
if arg1 == "add":
|
if cmd == "add":
|
||||||
|
Validate.isTrue(len(sign) - 1 <= max_lines, signsMsg("This sign already has the maximum amount of lines, you cannot add more"))
|
||||||
|
|
||||||
line = " ".join(args[1:])
|
line = " ".join(args[1:])
|
||||||
Validate.isTrue(line != "" and line != None, signsMsg("You have to enter a message to add or accumulate"))
|
Validate.isTrue(line != "" and line != None, signsMsg("You have to enter a message to add or accumulate"))
|
||||||
key = sender.getName()
|
key = sender.getName()
|
||||||
global lines
|
global lines
|
||||||
Validate.isTrue(key in lines or line[:1] != "/" or sender.hasPermission("utils.serversigns.command"), signsMsg("You cannot add commands to a sign!"))
|
Validate.isTrue(key in lines or line[:1] != "/" or sender.hasPermission("utils.serversigns.command"), signsMsg("You cannot add commands to a sign!"))
|
||||||
|
|
||||||
if line[-2:] == "++":
|
if line[-2:] == "++":
|
||||||
if key not in lines:
|
if key not in lines:
|
||||||
lines[key] = ""
|
lines[key] = ""
|
||||||
|
Validate.isTrue(len(lines[key]) + len(line[:-2]) + 1 <= max_line_length, signsMsg("This line would be too long, so the given message was not added to the accumulated message"))
|
||||||
lines[key] += " " + line[:-2]
|
lines[key] += " " + line[:-2]
|
||||||
return signsMsg("Added given message to the message you're accumulating. \nYour accumulated message is now as follows: \n&f%s" % lines[key], 'a')
|
return signsMsg("Added given message to the message you're accumulating. \nYour accumulated message is now as follows: \n&f%s" % lines[key], 'a')
|
||||||
|
|
||||||
if key in lines:
|
if key in lines:
|
||||||
line = (lines[key] + " " + line)[1:]
|
line = (lines[key] + " " + line)[1:]
|
||||||
Validate.isTrue(line[0] != "/" or line.split(" ")[0][1:] not in blocked_cmds, signsMsg("Usage of that command with server signs is prohibited"))
|
Validate.isTrue(len(line) <= max_line_length, signsMsg("This line would be too long, so it was not added to the sign. It is however still accumulated."))
|
||||||
|
|
||||||
|
if line[0] == "/":
|
||||||
|
cmd = line[1:].lower()
|
||||||
|
whitelisted = False
|
||||||
|
for wl_cmd in commands_whitelist:
|
||||||
|
if cmd[:len(wl_cmd)] == wl_cmd:
|
||||||
|
whitelisted = True
|
||||||
|
break
|
||||||
|
Validate.isTrue(whitelisted, signsMsg("That command is not whitelisted for use with serversigns"))
|
||||||
|
|
||||||
|
if key in lines:
|
||||||
|
del lines[key]
|
||||||
|
|
||||||
sign.append(colorify(line) if line[0] != "/" else line)
|
sign.append(colorify(line) if line[0] != "/" else line)
|
||||||
save_signs()
|
save_signs()
|
||||||
return signsMsg("Added line \"&f%s&a\" to the %s" % (line, signName), 'a')
|
return signsMsg("Added line \"&f%s&a\" to the %s" % (line, signName), 'a')
|
||||||
|
|
||||||
|
|
||||||
if arg1 == "remove":
|
if cmd == "remove":
|
||||||
Validate.notNone(arg2, signsMsg("You have to enter the ID of the message to remove!"))
|
Validate.notNone(arg2, signsMsg("You have to enter the ID of the message to remove!"))
|
||||||
try:
|
try:
|
||||||
id = int(arg2)
|
id = int(arg2)
|
||||||
@@ -196,7 +295,7 @@ def svs_command(sender, command, label, args):
|
|||||||
return signsMsg("Removed message with id %s from the %s" % (id, signName), 'a')
|
return signsMsg("Removed message with id %s from the %s" % (id, signName), 'a')
|
||||||
|
|
||||||
|
|
||||||
if arg1 in ("switch", "reverse"):
|
if cmd == "switch":
|
||||||
Validate.isTrue(len(args) == 3, signsMsg("You have to enter the 2 IDs of the messages to reverse"))
|
Validate.isTrue(len(args) == 3, signsMsg("You have to enter the 2 IDs of the messages to reverse"))
|
||||||
try:
|
try:
|
||||||
id1 = int(args[1])
|
id1 = int(args[1])
|
||||||
@@ -210,21 +309,20 @@ def svs_command(sender, command, label, args):
|
|||||||
return signsMsg("Reversed the messages with IDs %s and %s of the %s" % (id1, id2, signName), 'a')
|
return signsMsg("Reversed the messages with IDs %s and %s of the %s" % (id1, id2, signName), 'a')
|
||||||
|
|
||||||
|
|
||||||
if arg1 == "clear":
|
if cmd == "clear":
|
||||||
signs[loc] = [sign[0]]
|
signs[loc] = [sign[0]]
|
||||||
save_signs()
|
save_signs()
|
||||||
return signsMsg("Removed all messages from the %s" % signName, 'a')
|
return signsMsg("Removed all messages from the %s" % signName, 'a')
|
||||||
|
|
||||||
|
|
||||||
if arg1 in ("reset", "unclaim"):
|
if cmd == "reset":
|
||||||
del signs[loc]
|
del signs[loc]
|
||||||
save_signs()
|
save_signs()
|
||||||
return signsMsg("Removed all messages and the owner from the %s, it can now be claimed" % signName, 'a')
|
return signsMsg("Removed all messages and the owner from the %s, it can now be claimed" % signName, 'a')
|
||||||
|
|
||||||
#-------------------------------------------------------------------------------------------------------
|
#-------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@hook.event("player.PlayerInteractEvent")
|
@hook.event("player.PlayerInteractEvent")
|
||||||
def on_click(event):
|
def on_click(event):
|
||||||
if str(event.getAction()) != "RIGHT_CLICK_BLOCK":
|
if str(event.getAction()) != "RIGHT_CLICK_BLOCK":
|
||||||
@@ -254,39 +352,37 @@ faces = {
|
|||||||
|
|
||||||
@hook.event("block.BlockBreakEvent", "monitor")
|
@hook.event("block.BlockBreakEvent", "monitor")
|
||||||
def on_break(event):
|
def on_break(event):
|
||||||
try:
|
if checking_block or event.isCancelled():
|
||||||
global checking_block
|
return
|
||||||
if checking_block or event.isCancelled():
|
|
||||||
return
|
|
||||||
|
|
||||||
block = event.getBlock()
|
block = event.getBlock()
|
||||||
if block.getType() in (Material.SIGN_POST, Material.WALL_SIGN):
|
if block.getType() in (Material.SIGN_POST, Material.WALL_SIGN):
|
||||||
check_sign(event, block, attached = False)
|
check_sign(event, block, attached = False)
|
||||||
|
|
||||||
for block_face, data_values in faces.iteritems():
|
for block_face, data_values in faces.iteritems():
|
||||||
block2 = block.getRelative(block_face)
|
block2 = block.getRelative(block_face)
|
||||||
if block2.getType() == Material.WALL_SIGN and block2.getData() in data_values:
|
if block2.getType() == Material.WALL_SIGN and block2.getData() in data_values:
|
||||||
check_sign(event, block2)
|
check_sign(event, block2)
|
||||||
|
|
||||||
block3 = block.getRelative(BlockFace.UP)
|
block3 = block.getRelative(BlockFace.UP)
|
||||||
if block3.getType() == Material.SIGN_POST:
|
if block3.getType() == Material.SIGN_POST:
|
||||||
check_sign(event, block3)
|
check_sign(event, block3)
|
||||||
except:
|
|
||||||
error(trace())
|
|
||||||
|
|
||||||
|
|
||||||
def check_sign(event, block, attached = True):
|
def check_sign(event, block, attached = True):
|
||||||
player = event.getPlayer()
|
player = event.getPlayer()
|
||||||
sign = getSign(fromLoc(block.getLocation()))
|
loc = fromLoc(block.getLocation())
|
||||||
|
if block.getType() not in (Material.WALL_SIGN, Material.SIGN_POST) or getSign(loc) is None:
|
||||||
|
return
|
||||||
if not can_build2(player, block):
|
if not can_build2(player, block):
|
||||||
event.setCancelled(True)
|
event.setCancelled(True)
|
||||||
msg(event.getPlayer(), signsMsg("You cannot break %s" % ("the sign attached to that block" if attached else "that sign")))
|
msg(event.getPlayer(), signsMsg("You cannot break %s" % ("the sign attached to that block" if attached else "that sign")))
|
||||||
else:
|
else:
|
||||||
loc = fromLoc(block.getLocation())
|
|
||||||
del signs[loc]
|
del signs[loc]
|
||||||
save_signs()
|
save_signs()
|
||||||
msg(player, signsMsg("Reset the %s which you just broke" % identifySign(loc)))
|
msg(player, signsMsg("Reset the %s which you just broke" % identifySign(loc)))
|
||||||
|
|
||||||
|
|
||||||
def can_build2(player, block):
|
def can_build2(player, block):
|
||||||
global checking_block
|
global checking_block
|
||||||
event = BlockBreakEvent(block, player)
|
event = BlockBreakEvent(block, player)
|
||||||
@@ -295,3 +391,26 @@ def can_build2(player, block):
|
|||||||
checking_block = False
|
checking_block = False
|
||||||
return not event.isCancelled()
|
return not event.isCancelled()
|
||||||
|
|
||||||
|
|
||||||
|
def check_all_signs_and_force_commands():
|
||||||
|
for loc in signs:
|
||||||
|
if server.getWorld(loc[0]).getBlockAt(loc[1], loc[2], loc[3]).getType() not in (Material.WALL_SIGN, Material.SIGN_POST):
|
||||||
|
del signs[loc]
|
||||||
|
|
||||||
|
try:
|
||||||
|
map_field = server.getPluginManager().getClass().getDeclaredField("commandMap")
|
||||||
|
map_field.setAccessible(True)
|
||||||
|
command_map = map_field.get(server.getPluginManager())
|
||||||
|
|
||||||
|
commands_field = command_map.getClass().getDeclaredField("knownCommands")
|
||||||
|
commands_field.setAccessible(True)
|
||||||
|
map = commands_field.get(command_map)
|
||||||
|
|
||||||
|
rsutils_cmd = map.get("redstonerutils:serversigns")
|
||||||
|
map.put("svs", rsutils_cmd)
|
||||||
|
map.put("serversigns", rsutils_cmd)
|
||||||
|
map.put("signsmsg", rsutils_cmd)
|
||||||
|
|
||||||
|
except:
|
||||||
|
error("[Serversigns] failed to force commands")
|
||||||
|
error(trace())
|
||||||
|
|||||||
Reference in New Issue
Block a user