summaryrefslogtreecommitdiff
path: root/damnspam.py
diff options
context:
space:
mode:
authorjomo <github@jomo.tv>2014-07-27 19:42:33 +0200
committerjomo <github@jomo.tv>2014-07-27 19:42:33 +0200
commitb1a3a92e49b353dfa42b52b448cdbc3b27bb33f8 (patch)
tree1b135af4f422d2ebcb96e814c08923d52b2f85c3 /damnspam.py
parente9b0ad656b71841fa23f332ddf8eff43e5cf1986 (diff)
apply file read/save helpers
Diffstat (limited to 'damnspam.py')
-rw-r--r--damnspam.py21
1 files changed, 2 insertions, 19 deletions
diff --git a/damnspam.py b/damnspam.py
index 1a93ae4..d252fd0 100644
--- a/damnspam.py
+++ b/damnspam.py
@@ -2,25 +2,13 @@
from helpers import *
from time import time as now
import org.bukkit.event.block.BlockBreakEvent as BlockBreakEvent
-import json
-spam_filename = "plugins/redstoner-utils.py.dir/files/damnspam.json"
-inputs = {} # format "x;y;z;World"
+inputs = open_json_file("damnspam", {}) # format "x;y;z;World"
accepted_inputs = ["WOOD_BUTTON", "STONE_BUTTON", "LEVER"]
-try:
- inputs = json.loads(open(spam_filename).read())
-except Exception, e:
- error("Failed to load buttons and levers: %s" % e)
-
def save_inputs():
- try:
- spam_file = open(spam_filename, "w")
- spam_file.write(json.dumps(inputs))
- spam_file.close()
- except Exception, e:
- error("Failed to save damnspam: " + str(e))
+ save_json_file("damnspam", inputs)
def location_str(block):
@@ -28,7 +16,6 @@ def location_str(block):
def add_input(creator, block, timeout_off, timeout_on):
- global inputs
inputs[location_str(block)] = {
"creator" : uid(creator),
"timeout_off" : timeout_off,
@@ -39,8 +26,6 @@ def add_input(creator, block, timeout_off, timeout_on):
@hook.command("damnspam")
def on_dammnspam_command(sender, args):
- global inputs
-
plugin_header(sender, "DamnSpam")
if len(args) in [1,2]:
@@ -101,8 +86,6 @@ def on_dammnspam_command(sender, args):
@hook.event("block.BlockBreakEvent", "normal")
def on_block_break(event):
- global inputs
-
sender = event.getPlayer()
block = event.getBlock()
if str(block.getType()) in accepted_inputs and not event.isCancelled():