Almost complete redo of blockplacemods, small fixes
I've redone most of blockplacemods its code. It is now MUCH easier to expand in the future and I think the code is more elegant and stuff. It all works the same as before, except the command is now /toggle <setting> I've merged the setting for /autotakewater and /autofillcauldron into one setting named cauldron.
This commit is contained in:
@@ -63,8 +63,3 @@ def simplecommand(cmd,
|
|||||||
return function(sender, command, label, args)
|
return function(sender, command, label, args)
|
||||||
return call
|
return call
|
||||||
return decorator
|
return decorator
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -5,122 +5,156 @@ import org.bukkit.block.Furnace as Furnace
|
|||||||
import org.bukkit.inventory.ItemStack as ItemStack
|
import org.bukkit.inventory.ItemStack as ItemStack
|
||||||
import org.bukkit.Material as Material
|
import org.bukkit.Material as Material
|
||||||
|
|
||||||
denyslabcorrection = open_json_file("denyslabcorrection", []) #Players that don't want slabs corrected
|
settingInformation = {
|
||||||
denyautofill = open_json_file("denyautocauldronfill", [])
|
"cauldron": [0,
|
||||||
denyautolevel = open_json_file("denyautocauldronlevel", [])
|
"easy cauldron water level control",
|
||||||
|
"Toggles whether cauldrons auto-fill upon placement and whether right clicking them with redstone dust or empty hand will cycle their water level"
|
||||||
|
],
|
||||||
|
"slab": [0,
|
||||||
|
"automatically flipping placed slabs upside-down",
|
||||||
|
"Toggles whether slabs/steps which you place should be automatically flipped upside-down"
|
||||||
|
],
|
||||||
|
"furnace": [1,
|
||||||
|
"automatically filling furnaces upon placement",
|
||||||
|
"Sets your preferred default furnace contents to your currently held itemstack. Use an empty hand to disable this feature."
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
def saveslabs():
|
defaultPlayerSettings = {
|
||||||
save_json_file("denyslabcorrection", denyslabcorrection)
|
"cauldron": [],
|
||||||
def savecauldrons():
|
"slab": [],
|
||||||
save_json_file("denyautocauldronfill", denyautofill)
|
"furnace": {}
|
||||||
def savelevels():
|
}
|
||||||
save_json_file("denyautocauldronlevel", denyautolevel)
|
|
||||||
|
|
||||||
@simplecommand("autofillcauldron",
|
playerSettings = open_json_file("blockplacemods", defaultPlayerSettings)
|
||||||
aliases = ["fillcauldronautomatically"],
|
|
||||||
usage = "on/off",
|
|
||||||
|
#for setting, default in enumerate(defaultPlayerSettings):
|
||||||
|
# if playerSettings.get(setting) == None:
|
||||||
|
# playerSettings[setting] = default
|
||||||
|
|
||||||
|
def get(setting):
|
||||||
|
return playerSettings[setting]
|
||||||
|
|
||||||
|
|
||||||
|
def saveSettings():
|
||||||
|
save_json_file("blockplacemods", playerSettings)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@simplecommand("toggle",
|
||||||
|
aliases = ["set"],
|
||||||
|
usage = "<setting> [value|info]",
|
||||||
|
description = "Toggles or sets your preferences for our redstone utilities.\nThe following settings are available:\n" + ", ".join([x for x in settingInformation]),
|
||||||
|
senderLimit = 0,
|
||||||
helpNoargs = True,
|
helpNoargs = True,
|
||||||
description = "Sets whether you want placed cauldrons to fill \nautomatically",
|
helpSubcmd = True,
|
||||||
amax = 1,
|
amax = 2)
|
||||||
senderLimit = 0)
|
def toggle_command(sender, command, label, args):
|
||||||
def autofillcauldron_command(sender, command, label, args):
|
setting = args[0].lower()
|
||||||
uuid = uid(server.getPlayer(sender.getName()))
|
info = settingInformation.get(setting)
|
||||||
if args[0].lower() == "off":
|
if info == None:
|
||||||
if uuid in denyautofill:
|
return "&cThat setting could not be found. For command help, use &o/toggle"
|
||||||
return "&cAuto fillment of cauldrons is already disabled"
|
|
||||||
denyautofill.append(uuid)
|
values = get(setting)
|
||||||
savecauldrons()
|
player = server.getPlayer(sender.getName())
|
||||||
return "&aFilling cauldrons will no longer happen automatically"
|
uuid = uid(player)
|
||||||
if args[0].lower() == "on":
|
arglen = len(args)
|
||||||
if uuid not in denyautofill:
|
|
||||||
return "&cAuto fillment of cauldrons is already enabled"
|
if info[0] == 0: # Toggle
|
||||||
denyautofill.remove(uuid)
|
enabled = uuid not in values
|
||||||
savecauldrons()
|
new = None
|
||||||
return "&aFilling cauldrons will happen automatically from now"
|
if arglen == 1:
|
||||||
return "HELP"
|
new = not enabled
|
||||||
|
else:
|
||||||
|
arg2 = args[1].lower()
|
||||||
|
if arg2 == "info":
|
||||||
|
return " &aSetting %s:\n &9%s\n &6Accepted arguments: None or one of the following:\n &oon, enable, off, disable, toggle, switch" % (setting, info[2])
|
||||||
|
elif arg2 in ("toggle", "switch"):
|
||||||
|
new = not enabled
|
||||||
|
elif arg2 in ("on", "enable"):
|
||||||
|
new = True
|
||||||
|
elif arg2 in ("off", "disable"):
|
||||||
|
new = False
|
||||||
|
else:
|
||||||
|
return "&cArgument '%s' was not recognized. \nTry one of the following: &oon, off, toggle" % arg2
|
||||||
|
if enabled == new:
|
||||||
|
return "&cAlready %s: &a%s" % ("enabled" if enabled else "disabled", info[1])
|
||||||
|
if new:
|
||||||
|
values.remove(uuid)
|
||||||
|
else:
|
||||||
|
values.append(uuid)
|
||||||
|
saveSettings()
|
||||||
|
return ("&aEnabled " if new else "&aDisabled ") + info[1]
|
||||||
|
|
||||||
|
elif info[0] == 1: # Save ItemStack in hand
|
||||||
|
if arglen == 1:
|
||||||
|
item = fromStack(player.getItemInHand())
|
||||||
|
if 0 in (item[0], item[1]):
|
||||||
|
del values[uuid]
|
||||||
|
return "&aDisabled " + info[1]
|
||||||
|
values[uuid] = item
|
||||||
|
saveSettings()
|
||||||
|
return "&aEnabled %s, with currently held itemstack" % info[1]
|
||||||
|
if args[1].lower() == "info":
|
||||||
|
return "&aSetting %s:\n&9%s" % (setting, info[2])
|
||||||
|
return "&cArgument '%s' was not recognized. \nUse /toggle %s info for more information." % setting
|
||||||
|
|
||||||
|
return None #This shouldn't happen
|
||||||
|
|
||||||
|
|
||||||
@simplecommand("autoflipslab",
|
def fromStack(itemStack):
|
||||||
aliases = ["autoflipstep", "flipslabautomatically", "flipstepautomatically"],
|
return [itemStack.getTypeId(), itemStack.getAmount(), itemStack.getData().getData()]
|
||||||
usage = "on/off",
|
def toStack(lst):
|
||||||
helpNoargs = True,
|
return ItemStack(lst[0], lst[1], lst[2])
|
||||||
description = "Sets whether you want placed slabs to be turned \nupside-down",
|
|
||||||
amax = 1,
|
|
||||||
senderLimit = 0)
|
|
||||||
def autoflipslab_command(sender, command, label, args):
|
|
||||||
uuid = uid(server.getPlayer(sender.getName()))
|
|
||||||
if args[0].lower() == "off":
|
|
||||||
if uuid in denyslabcorrection:
|
|
||||||
return "&cAuto flipping of slabs is already disabled"
|
|
||||||
denyslabcorrection.append(uuid)
|
|
||||||
saveslabs()
|
|
||||||
return "&aFlipping slabs will no longer happen automatically"
|
|
||||||
if args[0].lower() == "on":
|
|
||||||
if uuid not in denyslabcorrection:
|
|
||||||
return "&cAuto flipping of slabs is already enabled"
|
|
||||||
denyslabcorrection.remove(uuid)
|
|
||||||
saveslabs()
|
|
||||||
return "&aFlipping slabs will happen automatically from now"
|
|
||||||
return "HELP"
|
|
||||||
|
|
||||||
|
def isEnabled(toggleSetting, uuid):
|
||||||
|
return uuid not in get(toggleSetting)
|
||||||
|
|
||||||
@simplecommand("autotakewater",
|
|
||||||
aliases = ["autocauldronlevel"],
|
|
||||||
usage = "on/off",
|
|
||||||
helpNoargs = True,
|
|
||||||
description = "Sets whether you want right clicking cauldrons \nwith empty hand or redstone dust \nto lower water level",
|
|
||||||
amax = 1,
|
|
||||||
senderLimit = 0)
|
|
||||||
def autoflipslab_command(sender, command, label, args):
|
|
||||||
uuid = uid(server.getPlayer(sender.getName()))
|
|
||||||
if args[0].lower() == "off":
|
|
||||||
if uuid in denyautolevel:
|
|
||||||
return "&cTaking water with hand/redstone is already disabled"
|
|
||||||
denyautolevel.append(uuid)
|
|
||||||
savelevels()
|
|
||||||
return "&aYou can no longer take water with hand/redstone"
|
|
||||||
if args[0].lower() == "on":
|
|
||||||
if uuid not in denyautolevel:
|
|
||||||
return "&cTaking water with hand/redstone is already enabled"
|
|
||||||
denyautolevel.remove(uuid)
|
|
||||||
savelevels()
|
|
||||||
return "&aYou can take water with hand/redstone from now"
|
|
||||||
return "HELP"
|
|
||||||
|
|
||||||
|
|
||||||
@hook.event("block.BlockPlaceEvent", "monitor")
|
@hook.event("block.BlockPlaceEvent", "monitor")
|
||||||
def on_block_place(event):
|
def on_block_place(event):
|
||||||
|
try:
|
||||||
if event.isCancelled():
|
if event.isCancelled():
|
||||||
return
|
return
|
||||||
player = event.getPlayer()
|
player = event.getPlayer()
|
||||||
if player.getWorld().getName() not in ("Creative", "Trusted", "world"):
|
if not is_creative(player):
|
||||||
return
|
return
|
||||||
|
|
||||||
uuid = uid(player)
|
uuid = uid(player)
|
||||||
block = event.getBlockPlaced()
|
block = event.getBlockPlaced()
|
||||||
material = str(block.getType())
|
material = str(block.getType())
|
||||||
if uuid not in denyslabcorrection and material in ("WOOD_STEP", "STEP") and block.getData() < 8:
|
if isEnabled("slab", uuid) and material in ("WOOD_STEP", "STEP") and block.getData() < 8:
|
||||||
block.setData(block.getData() + 8) # Flip upside down
|
block.setData(block.getData() + 8) # Flip upside down
|
||||||
elif uuid not in denyautofill and material == "CAULDRON":
|
elif isEnabled("cauldron", uuid) and material == "CAULDRON":
|
||||||
block.setData(3) #3 layers of water, 3 signal strength
|
block.setData(3) #3 layers of water, 3 signal strength
|
||||||
elif material == "FURNACE":
|
elif material == "FURNACE":
|
||||||
|
stack = get("furnace").get(uuid)
|
||||||
|
if stack == None:
|
||||||
|
return
|
||||||
state = block.getState()
|
state = block.getState()
|
||||||
state.getInventory().setSmelting(ItemStack(Material.REDSTONE))
|
state.getInventory().setSmelting(toStack(stack))
|
||||||
state.update()
|
state.update()
|
||||||
|
except:
|
||||||
|
error(trace())
|
||||||
|
|
||||||
|
|
||||||
@hook.event("player.PlayerInteractEvent", "monitor")
|
@hook.event("player.PlayerInteractEvent", "monitor")
|
||||||
def on_interact(event):
|
def on_interact(event):
|
||||||
|
try:
|
||||||
player = event.getPlayer()
|
player = event.getPlayer()
|
||||||
if uid(player) in denyautolevel or player.getWorld().getName() not in ("Creative", "Trusted", "world"):
|
if (isEnabled("cauldron", uid(player))
|
||||||
return
|
and is_creative(player)
|
||||||
if str(event.getAction()) != "RIGHT_CLICK_BLOCK":
|
and str(event.getAction()) == "RIGHT_CLICK_BLOCK"
|
||||||
return
|
and (not event.hasItem() or str(event.getItem().getType()) == "REDSTONE")
|
||||||
if event.hasItem() and not str(event.getItem().getType()) == "REDSTONE":
|
and str(event.getClickedBlock().getType()) == "CAULDRON"
|
||||||
return
|
):
|
||||||
block = event.getClickedBlock()
|
block = event.getClickedBlock()
|
||||||
if str(block.getType()) != "CAULDRON":
|
|
||||||
return
|
|
||||||
event2 = BlockBreakEvent(block, player)
|
event2 = BlockBreakEvent(block, player)
|
||||||
server.getPluginManager().callEvent(event2)
|
server.getPluginManager().callEvent(event2)
|
||||||
if not event2.isCancelled():
|
if not event2.isCancelled():
|
||||||
data = block.getData()
|
block.setData(block.getData() - 1 if block.getData() > 0 else 3)
|
||||||
block.setData(data - 1 if data > 0 else 3)
|
except:
|
||||||
|
error(trace())
|
||||||
|
|
||||||
|
|||||||
17
misc.py
17
misc.py
@@ -73,7 +73,12 @@ def on_flow(event):
|
|||||||
if block.getWorld().getName() == "Creative" and rs_material_broken_by_flow(str(block.getType())):
|
if block.getWorld().getName() == "Creative" and rs_material_broken_by_flow(str(block.getType())):
|
||||||
event.setCancelled(True)
|
event.setCancelled(True)
|
||||||
|
|
||||||
|
def rs_material_broken_by_flow(material):
|
||||||
|
if material in ("REDSTONE", "LEVER", "TRIPWIRE"):
|
||||||
|
return True
|
||||||
|
parts = material.split("_")
|
||||||
|
length = len(parts)
|
||||||
|
return length > 1 and (parts[0] == "DIODE" or parts[1] in ("TORCH", "WIRE", "BUTTON", "HOOK") or (length == 3 and parts[1] == "COMPARATOR"))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -113,10 +118,10 @@ def on_me_command(sender, command, label, args):
|
|||||||
|
|
||||||
@hook.command("pluginversions")
|
@hook.command("pluginversions")
|
||||||
def on_pluginversions_command(sender, command, label, args):
|
def on_pluginversions_command(sender, command, label, args):
|
||||||
""
|
"""
|
||||||
/pluginversions
|
/pluginversions
|
||||||
print all plugins + versions; useful when updating plugins
|
print all plugins + versions; useful when updating plugins
|
||||||
""
|
"""
|
||||||
try:
|
try:
|
||||||
plugin_header(sender, "Plugin versions")
|
plugin_header(sender, "Plugin versions")
|
||||||
plugins = [pl.getDescription() for pl in list(ArrayList(java_array_to_list(server.getPluginManager().getPlugins())))]
|
plugins = [pl.getDescription() for pl in list(ArrayList(java_array_to_list(server.getPluginManager().getPlugins())))]
|
||||||
@@ -205,9 +210,3 @@ def on_modules_command(sender, command, label, args):
|
|||||||
plugin_header(sender, "Modules")
|
plugin_header(sender, "Modules")
|
||||||
msg(sender, ", ".join([(("&a" if mod in shared["modules"] else "&c") + mod) for mod in shared["load_modules"]]))
|
msg(sender, ", ".join([(("&a" if mod in shared["modules"] else "&c") + mod) for mod in shared["load_modules"]]))
|
||||||
|
|
||||||
def rs_material_broken_by_flow(material):
|
|
||||||
if material in ("REDSTONE", "LEVER", "TRIPWIRE"):
|
|
||||||
return True
|
|
||||||
parts = material.split("_")
|
|
||||||
length = len(parts)
|
|
||||||
return length > 1 and (parts[0] == "DIODE" or parts[1] in ("TORCH", "WIRE", "BUTTON", "HOOK") or (length == 3 and parts[1] == "COMPARATOR"))
|
|
||||||
|
|||||||
Reference in New Issue
Block a user