From a8a37f055384b45fb2dfeaecd812d7cad6b3c923 Mon Sep 17 00:00:00 2001 From: Dico Date: Sat, 19 Jul 2014 01:39:08 +0200 Subject: [PATCH] Stuff added to helpers.py, forcefield updated to be a lot more efficient (simple change) --- forcefield.py | 3 +++ helpers.py | 18 ++++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/forcefield.py b/forcefield.py index f35bfe4..354e9a6 100644 --- a/forcefield.py +++ b/forcefield.py @@ -144,7 +144,10 @@ def forcefield_header(player, message): @hook.event("player.PlayerMoveEvent") def on_move(event): + if not ff_users: + return player = event.getPlayer() + log(player) if is_creative(player): player_id = uid(player) diff --git a/helpers.py b/helpers.py index f34e403..356d18a 100644 --- a/helpers.py +++ b/helpers.py @@ -6,6 +6,7 @@ import org.bukkit.Location as Location import org.bukkit.entity.Player as Player import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause as TeleportCause import org.bukkit.block as bblock +import json shared = {} # this dict can be used to share stuff across modules @@ -110,3 +111,20 @@ def uid(player): def retrieve_player(uid): return server.getOfflinePlayer(id_to_player(uid)) + + +def open_json_file(json_file): + try: + with open(json_file) as obj: + return json.loads(obj.read()) + except Exception, reading_error: + error("Failed to read from %s: %s" % (json_file, str(reading_error))) + + +def save_json_file(json_file, json_object): # json file is the path to the file, obj is the variable you want to write to the file. + global json_object + try: + with open(json_file) as obj: + obj.write(json.dumps(json_object)) + except Exception, writing_error: + error("Failed to write to %s: %s" % (json_file, str(writing_error))) \ No newline at end of file