Added gate change listener interface used for dynmap.
This commit is contained in:
parent
c80b0f0f68
commit
f8f31640ef
31
src/de/craftinc/gates/GateChangeListener.java
Normal file
31
src/de/craftinc/gates/GateChangeListener.java
Normal file
@ -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 <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
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 Map<String, Object>changeSet);
|
||||||
|
}
|
@ -54,6 +54,20 @@ public class GatesManager
|
|||||||
|
|
||||||
protected boolean storageFileIsInvalid = false;
|
protected boolean storageFileIsInvalid = false;
|
||||||
|
|
||||||
|
protected Set<GateChangeListener> changeListeners = new HashSet<GateChangeListener>();
|
||||||
|
|
||||||
|
|
||||||
|
public void addGateChangeListener(GateChangeListener listener)
|
||||||
|
{
|
||||||
|
this.changeListeners.add(listener);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public void removeGateChangeListener(GateChangeListener listener)
|
||||||
|
{
|
||||||
|
this.changeListeners.remove(listener);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public Gate getGateWithId(final String id)
|
public Gate getGateWithId(final String id)
|
||||||
{
|
{
|
||||||
@ -489,6 +503,13 @@ public class GatesManager
|
|||||||
{
|
{
|
||||||
this.removeGateById(oldId);
|
this.removeGateById(oldId);
|
||||||
this.addGateWithId(g);
|
this.addGateWithId(g);
|
||||||
|
|
||||||
|
Map<String, Object> changeSet = new HashMap<String, Object>();
|
||||||
|
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.removeGateByFrameLocation(oldGateFrameBlocks);
|
||||||
this.addGateByFrameLocations(g);
|
this.addGateByFrameLocations(g);
|
||||||
|
|
||||||
|
Map<String, Object> changeSet = new HashMap<String, Object>();
|
||||||
|
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<String, Object> changeSet = new HashMap<String, Object>();
|
||||||
|
changeSet.put(GateChangeListener.changedExit, oldExit);
|
||||||
|
|
||||||
|
for (GateChangeListener l : this.changeListeners) {
|
||||||
|
l.gateChangedHandler(g, changeSet);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public void handleNewGate(final Gate g)
|
public void handleNewGate(final Gate g)
|
||||||
@ -516,6 +557,14 @@ public class GatesManager
|
|||||||
this.addGateByLocations(g);
|
this.addGateByLocations(g);
|
||||||
this.addGateWithId(g);
|
this.addGateWithId(g);
|
||||||
this.addGateByFrameLocations(g);
|
this.addGateByFrameLocations(g);
|
||||||
|
|
||||||
|
|
||||||
|
Map<String, Object> changeSet = new HashMap<String, Object>();
|
||||||
|
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.removeGateFromChunk(g, g.getLocation());
|
||||||
this.removeGateByLocation(g.getGateBlockLocations());
|
this.removeGateByLocation(g.getGateBlockLocations());
|
||||||
this.removeGateByFrameLocation(g.getGateFrameBlocks());
|
this.removeGateByFrameLocation(g.getGateFrameBlocks());
|
||||||
|
|
||||||
|
Map<String, Object> changeSet = new HashMap<String, Object>();
|
||||||
|
changeSet.put(GateChangeListener.removedGate, null);
|
||||||
|
|
||||||
|
for (GateChangeListener l : this.changeListeners) {
|
||||||
|
l.gateChangedHandler(g, changeSet);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user