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 call
|
||||
return decorator
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -5,122 +5,156 @@ import org.bukkit.block.Furnace as Furnace
|
||||
import org.bukkit.inventory.ItemStack as ItemStack
|
||||
import org.bukkit.Material as Material
|
||||
|
||||
denyslabcorrection = open_json_file("denyslabcorrection", []) #Players that don't want slabs corrected
|
||||
denyautofill = open_json_file("denyautocauldronfill", [])
|
||||
denyautolevel = open_json_file("denyautocauldronlevel", [])
|
||||
settingInformation = {
|
||||
"cauldron": [0,
|
||||
"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():
|
||||
save_json_file("denyslabcorrection", denyslabcorrection)
|
||||
def savecauldrons():
|
||||
save_json_file("denyautocauldronfill", denyautofill)
|
||||
def savelevels():
|
||||
save_json_file("denyautocauldronlevel", denyautolevel)
|
||||
defaultPlayerSettings = {
|
||||
"cauldron": [],
|
||||
"slab": [],
|
||||
"furnace": {}
|
||||
}
|
||||
|
||||
@simplecommand("autofillcauldron",
|
||||
aliases = ["fillcauldronautomatically"],
|
||||
usage = "on/off",
|
||||
playerSettings = open_json_file("blockplacemods", defaultPlayerSettings)
|
||||
|
||||
|
||||
#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,
|
||||
description = "Sets whether you want placed cauldrons to fill \nautomatically",
|
||||
amax = 1,
|
||||
senderLimit = 0)
|
||||
def autofillcauldron_command(sender, command, label, args):
|
||||
uuid = uid(server.getPlayer(sender.getName()))
|
||||
if args[0].lower() == "off":
|
||||
if uuid in denyautofill:
|
||||
return "&cAuto fillment of cauldrons is already disabled"
|
||||
denyautofill.append(uuid)
|
||||
savecauldrons()
|
||||
return "&aFilling cauldrons will no longer happen automatically"
|
||||
if args[0].lower() == "on":
|
||||
if uuid not in denyautofill:
|
||||
return "&cAuto fillment of cauldrons is already enabled"
|
||||
denyautofill.remove(uuid)
|
||||
savecauldrons()
|
||||
return "&aFilling cauldrons will happen automatically from now"
|
||||
return "HELP"
|
||||
helpSubcmd = True,
|
||||
amax = 2)
|
||||
def toggle_command(sender, command, label, args):
|
||||
setting = args[0].lower()
|
||||
info = settingInformation.get(setting)
|
||||
if info == None:
|
||||
return "&cThat setting could not be found. For command help, use &o/toggle"
|
||||
|
||||
values = get(setting)
|
||||
player = server.getPlayer(sender.getName())
|
||||
uuid = uid(player)
|
||||
arglen = len(args)
|
||||
|
||||
if info[0] == 0: # Toggle
|
||||
enabled = uuid not in values
|
||||
new = None
|
||||
if arglen == 1:
|
||||
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",
|
||||
aliases = ["autoflipstep", "flipslabautomatically", "flipstepautomatically"],
|
||||
usage = "on/off",
|
||||
helpNoargs = True,
|
||||
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 fromStack(itemStack):
|
||||
return [itemStack.getTypeId(), itemStack.getAmount(), itemStack.getData().getData()]
|
||||
def toStack(lst):
|
||||
return ItemStack(lst[0], lst[1], lst[2])
|
||||
|
||||
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")
|
||||
def on_block_place(event):
|
||||
try:
|
||||
if event.isCancelled():
|
||||
return
|
||||
player = event.getPlayer()
|
||||
if player.getWorld().getName() not in ("Creative", "Trusted", "world"):
|
||||
if not is_creative(player):
|
||||
return
|
||||
|
||||
uuid = uid(player)
|
||||
block = event.getBlockPlaced()
|
||||
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
|
||||
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
|
||||
elif material == "FURNACE":
|
||||
stack = get("furnace").get(uuid)
|
||||
if stack == None:
|
||||
return
|
||||
state = block.getState()
|
||||
state.getInventory().setSmelting(ItemStack(Material.REDSTONE))
|
||||
state.getInventory().setSmelting(toStack(stack))
|
||||
state.update()
|
||||
except:
|
||||
error(trace())
|
||||
|
||||
|
||||
@hook.event("player.PlayerInteractEvent", "monitor")
|
||||
def on_interact(event):
|
||||
try:
|
||||
player = event.getPlayer()
|
||||
if uid(player) in denyautolevel or player.getWorld().getName() not in ("Creative", "Trusted", "world"):
|
||||
return
|
||||
if str(event.getAction()) != "RIGHT_CLICK_BLOCK":
|
||||
return
|
||||
if event.hasItem() and not str(event.getItem().getType()) == "REDSTONE":
|
||||
return
|
||||
if (isEnabled("cauldron", uid(player))
|
||||
and is_creative(player)
|
||||
and str(event.getAction()) == "RIGHT_CLICK_BLOCK"
|
||||
and (not event.hasItem() or str(event.getItem().getType()) == "REDSTONE")
|
||||
and str(event.getClickedBlock().getType()) == "CAULDRON"
|
||||
):
|
||||
block = event.getClickedBlock()
|
||||
if str(block.getType()) != "CAULDRON":
|
||||
return
|
||||
event2 = BlockBreakEvent(block, player)
|
||||
server.getPluginManager().callEvent(event2)
|
||||
if not event2.isCancelled():
|
||||
data = block.getData()
|
||||
block.setData(data - 1 if data > 0 else 3)
|
||||
block.setData(block.getData() - 1 if block.getData() > 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())):
|
||||
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")
|
||||
def on_pluginversions_command(sender, command, label, args):
|
||||
""
|
||||
"""
|
||||
/pluginversions
|
||||
print all plugins + versions; useful when updating plugins
|
||||
""
|
||||
"""
|
||||
try:
|
||||
plugin_header(sender, "Plugin versions")
|
||||
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")
|
||||
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