From f8f31640ef314908d1e51a489e7398ec241919c7 Mon Sep 17 00:00:00 2001 From: Tobias Ottenweller Date: Sun, 26 Jan 2014 14:29:28 +0100 Subject: [PATCH] Added gate change listener interface used for dynmap. --- src/de/craftinc/gates/GateChangeListener.java | 31 ++++++++++ src/de/craftinc/gates/GatesManager.java | 56 +++++++++++++++++++ 2 files changed, 87 insertions(+) create mode 100644 src/de/craftinc/gates/GateChangeListener.java diff --git a/src/de/craftinc/gates/GateChangeListener.java b/src/de/craftinc/gates/GateChangeListener.java new file mode 100644 index 0000000..49917f6 --- /dev/null +++ b/src/de/craftinc/gates/GateChangeListener.java @@ -0,0 +1,31 @@ +/* Craft Inc. Gates + Copyright (C) 2011-2014 Craft Inc. Gates Team (see AUTHORS.txt) + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License as published + by the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public License + along with this program (LGPLv3). If not, see . +*/ +package de.craftinc.gates; + + +import java.util.Map; + +public interface GateChangeListener +{ + public static final String newGate = "GateChangeListener-newGate"; // value will be null + public static final String removedGate = "GateChangeListener-removedGate"; // value will be null + public static final String changedID = "GateChangeListener-changedID"; // value will be the old ID + public static final String changedLocation = "GateChangeListener-changedLocation"; // value will the old location + public static final String changedExit = "GateChangeListener-changedExit"; // value will be the old exit + + public void gateChangedHandler(final Gate g, final MapchangeSet); +} diff --git a/src/de/craftinc/gates/GatesManager.java b/src/de/craftinc/gates/GatesManager.java index 2df21c7..81fda3d 100644 --- a/src/de/craftinc/gates/GatesManager.java +++ b/src/de/craftinc/gates/GatesManager.java @@ -54,6 +54,20 @@ public class GatesManager protected boolean storageFileIsInvalid = false; + protected Set changeListeners = new HashSet(); + + + public void addGateChangeListener(GateChangeListener listener) + { + this.changeListeners.add(listener); + } + + + public void removeGateChangeListener(GateChangeListener listener) + { + this.changeListeners.remove(listener); + } + public Gate getGateWithId(final String id) { @@ -489,6 +503,13 @@ public class GatesManager { this.removeGateById(oldId); this.addGateWithId(g); + + Map changeSet = new HashMap(); + changeSet.put(GateChangeListener.changedID, oldId); + + for (GateChangeListener l : this.changeListeners) { + l.gateChangedHandler(g, changeSet); + } } @@ -505,7 +526,27 @@ public class GatesManager this.removeGateByFrameLocation(oldGateFrameBlocks); this.addGateByFrameLocations(g); + + Map changeSet = new HashMap(); + changeSet.put(GateChangeListener.changedLocation, oldLocation); + + for (GateChangeListener l : this.changeListeners) { + l.gateChangedHandler(g, changeSet); + } } + + // TODO: call this method! + public void handleGateExitChange(final Gate g, final Location oldExit) + { + // nothing to do + + Map changeSet = new HashMap(); + changeSet.put(GateChangeListener.changedExit, oldExit); + + for (GateChangeListener l : this.changeListeners) { + l.gateChangedHandler(g, changeSet); + } + } public void handleNewGate(final Gate g) @@ -516,6 +557,14 @@ public class GatesManager this.addGateByLocations(g); this.addGateWithId(g); this.addGateByFrameLocations(g); + + + Map changeSet = new HashMap(); + changeSet.put(GateChangeListener.newGate, null); + + for (GateChangeListener l : this.changeListeners) { + l.gateChangedHandler(g, changeSet); + } } @@ -527,6 +576,13 @@ public class GatesManager this.removeGateFromChunk(g, g.getLocation()); this.removeGateByLocation(g.getGateBlockLocations()); this.removeGateByFrameLocation(g.getGateFrameBlocks()); + + Map changeSet = new HashMap(); + changeSet.put(GateChangeListener.removedGate, null); + + for (GateChangeListener l : this.changeListeners) { + l.gateChangedHandler(g, changeSet); + } }