1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
|
from helpers import *
from basecommands import simplecommand
import org.bukkit.event.block.BlockBreakEvent as BlockBreakEvent
import org.bukkit.block.Furnace as Furnace
import org.bukkit.inventory.ItemStack as ItemStack
import org.bukkit.Material as Material
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."
]
}
defaultPlayerSettings = {
"cauldron": [],
"slab": [],
"furnace": {}
}
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,
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
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)
@hook.event("block.BlockPlaceEvent", "monitor")
def on_block_place(event):
try:
if event.isCancelled():
return
player = event.getPlayer()
if not is_creative(player):
return
uuid = uid(player)
block = event.getBlockPlaced()
material = str(block.getType())
if isEnabled("slab", uuid) and material in ("WOOD_STEP", "STEP") and block.getData() < 8:
block.setData(block.getData() + 8) # Flip upside down
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(toStack(stack))
state.update()
except:
error(trace())
@hook.event("player.PlayerInteractEvent", "monitor")
def on_interact(event):
try:
player = event.getPlayer()
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()
event2 = BlockBreakEvent(block, player)
server.getPluginManager().callEvent(event2)
if not event2.isCancelled():
block.setData(block.getData() - 1 if block.getData() > 0 else 3)
except:
error(trace())
|