From f7512078651d89a39618401ce08287b8b1349dcc Mon Sep 17 00:00:00 2001 From: jomo Date: Fri, 8 Aug 2014 04:26:16 +0200 Subject: [PATCH 1/6] allowing to update timeouts | not sure if this works ;_; --- damnspam.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/damnspam.py b/damnspam.py index d252fd0..069708a 100644 --- a/damnspam.py +++ b/damnspam.py @@ -5,6 +5,7 @@ import org.bukkit.event.block.BlockBreakEvent as BlockBreakEvent inputs = open_json_file("damnspam", {}) # format "x;y;z;World" accepted_inputs = ["WOOD_BUTTON", "STONE_BUTTON", "LEVER"] +changing_input = False def save_inputs(): @@ -26,6 +27,8 @@ def add_input(creator, block, timeout_off, timeout_on): @hook.command("damnspam") def on_dammnspam_command(sender, args): + global changing_input + plugin_header(sender, "DamnSpam") if len(args) in [1,2]: @@ -67,10 +70,13 @@ def on_dammnspam_command(sender, args): msg(sender, "&cPlease look at a button or lever while executing this command!") return True + if location_str(target) in inputs: + changing_input = True # this input already has a timeout + # test if player is allowed to build here test_event = BlockBreakEvent(target, sender) server.getPluginManager().callEvent(test_event) if test_event.isCancelled(): - msg(sender, "&cYou are not allowed to modify this button") + msg(sender, "&cYou are not allowed to modify this input") return True # add block to inputs @@ -97,7 +103,7 @@ def on_block_break(event): save_inputs() msg(sender, "&eSuccessfully removed the input!") return True - else: + elif not changing_input: # FIXME: does this work?? event.setCancelled(True) msg(sender, "&cYou cannot destroy this input!") msg(sender, "&c&nSneak&c and break if you want to remove it.") From 8ecae8fe232da3eafff8a1c54224492dfab9e171 Mon Sep 17 00:00:00 2001 From: jomo Date: Fri, 8 Aug 2014 04:33:27 +0200 Subject: [PATCH 2/6] reset changing_input --- damnspam.py | 1 + 1 file changed, 1 insertion(+) diff --git a/damnspam.py b/damnspam.py index 069708a..cae8ec4 100644 --- a/damnspam.py +++ b/damnspam.py @@ -75,6 +75,7 @@ def on_dammnspam_command(sender, args): # test if player is allowed to build here test_event = BlockBreakEvent(target, sender) server.getPluginManager().callEvent(test_event) + changing_input = False if test_event.isCancelled(): msg(sender, "&cYou are not allowed to modify this input") return True From 10d8498ce4157d6e684173ddb6c44df0bd1534e1 Mon Sep 17 00:00:00 2001 From: jomo Date: Fri, 8 Aug 2014 05:14:22 +0200 Subject: [PATCH 3/6] check if player is allowed to remove input --- damnspam.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/damnspam.py b/damnspam.py index cae8ec4..ed0ffaa 100644 --- a/damnspam.py +++ b/damnspam.py @@ -100,11 +100,18 @@ def on_block_break(event): if inputs.get(pos_str): plugin_header(sender, "DamnSpam") if sender.isSneaking(): + # test if player is allowed to build here + test_event = BlockBreakEvent(block, sender) + server.getPluginManager().callEvent(test_event) + if test_event.isCancelled(): + event.setCancelled(True) + msg(sender, "&cYou are not allowed to remove this input") + return True inputs.pop(pos_str) # remove save_inputs() - msg(sender, "&eSuccessfully removed the input!") + msg(sender, "&eSuccessfully removed this input!") return True - elif not changing_input: # FIXME: does this work?? + elif not changing_input: event.setCancelled(True) msg(sender, "&cYou cannot destroy this input!") msg(sender, "&c&nSneak&c and break if you want to remove it.") From d0acf1bd3604450f67fc1cc4729f70de6906179f Mon Sep 17 00:00:00 2001 From: jomo Date: Fri, 8 Aug 2014 05:37:45 +0200 Subject: [PATCH 4/6] fixing endless loop --- damnspam.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/damnspam.py b/damnspam.py index ed0ffaa..54cbc24 100644 --- a/damnspam.py +++ b/damnspam.py @@ -6,6 +6,7 @@ import org.bukkit.event.block.BlockBreakEvent as BlockBreakEvent inputs = open_json_file("damnspam", {}) # format "x;y;z;World" accepted_inputs = ["WOOD_BUTTON", "STONE_BUTTON", "LEVER"] changing_input = False +removing_input = False def save_inputs(): @@ -93,6 +94,10 @@ def on_dammnspam_command(sender, args): @hook.event("block.BlockBreakEvent", "normal") def on_block_break(event): + global removing_input + + if removing_input: + return True sender = event.getPlayer() block = event.getBlock() if str(block.getType()) in accepted_inputs and not event.isCancelled(): @@ -101,12 +106,14 @@ def on_block_break(event): plugin_header(sender, "DamnSpam") if sender.isSneaking(): # test if player is allowed to build here - test_event = BlockBreakEvent(block, sender) + removing_input = True + test_event = BlockBreakEvent(block, sender) server.getPluginManager().callEvent(test_event) if test_event.isCancelled(): event.setCancelled(True) msg(sender, "&cYou are not allowed to remove this input") return True + removing_input = False inputs.pop(pos_str) # remove save_inputs() msg(sender, "&eSuccessfully removed this input!") From 5361e0d8db1579d318ffdcb370b64a4728bfb1f2 Mon Sep 17 00:00:00 2001 From: jomo Date: Fri, 8 Aug 2014 05:42:03 +0200 Subject: [PATCH 5/6] move line to correct position --- damnspam.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/damnspam.py b/damnspam.py index 54cbc24..7df9cb6 100644 --- a/damnspam.py +++ b/damnspam.py @@ -109,11 +109,11 @@ def on_block_break(event): removing_input = True test_event = BlockBreakEvent(block, sender) server.getPluginManager().callEvent(test_event) + removing_input = False if test_event.isCancelled(): event.setCancelled(True) msg(sender, "&cYou are not allowed to remove this input") return True - removing_input = False inputs.pop(pos_str) # remove save_inputs() msg(sender, "&eSuccessfully removed this input!") From 885589eb7b95aa99ffa52dcb0ab4e1583e51203e Mon Sep 17 00:00:00 2001 From: jomo Date: Fri, 8 Aug 2014 05:47:47 +0200 Subject: [PATCH 6/6] repalce input with lever/button --- damnspam.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/damnspam.py b/damnspam.py index 7df9cb6..e4d7a61 100644 --- a/damnspam.py +++ b/damnspam.py @@ -78,7 +78,7 @@ def on_dammnspam_command(sender, args): server.getPluginManager().callEvent(test_event) changing_input = False if test_event.isCancelled(): - msg(sender, "&cYou are not allowed to modify this input") + msg(sender, "&cYou are not allowed to modify this %s" % str(target.getType()).lower()) return True # add block to inputs @@ -99,7 +99,8 @@ def on_block_break(event): if removing_input: return True sender = event.getPlayer() - block = event.getBlock() + block = event.getBlock() + btype = str(block.getType()).lower() if str(block.getType()) in accepted_inputs and not event.isCancelled(): pos_str = location_str(block) if inputs.get(pos_str): @@ -112,15 +113,15 @@ def on_block_break(event): removing_input = False if test_event.isCancelled(): event.setCancelled(True) - msg(sender, "&cYou are not allowed to remove this input") + msg(sender, "&cYou are not allowed to remove this %s" % btype) return True inputs.pop(pos_str) # remove save_inputs() - msg(sender, "&eSuccessfully removed this input!") + msg(sender, "&eSuccessfully removed this %s!" % btype) return True elif not changing_input: event.setCancelled(True) - msg(sender, "&cYou cannot destroy this input!") + msg(sender, "&cYou cannot destroy this %s!" % btype) msg(sender, "&c&nSneak&c and break if you want to remove it.") return True