Refactor the RegionEvent into two subclasses for future operations
This commit is contained in:
parent
104fc169a7
commit
3bf886ba72
38
src/main/java/us/camin/regions/RegionCreateEvent.java
Normal file
38
src/main/java/us/camin/regions/RegionCreateEvent.java
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
package us.camin.regions;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This file is part of Regions
|
||||||
|
*
|
||||||
|
* Regions is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* Regions 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 General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with Regions. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
import org.bukkit.event.Event;
|
||||||
|
import org.bukkit.event.HandlerList;
|
||||||
|
|
||||||
|
public class RegionCreateEvent extends RegionEvent {
|
||||||
|
public static final HandlerList s_handlers = new HandlerList();
|
||||||
|
|
||||||
|
public RegionCreateEvent(Region region) {
|
||||||
|
super(region);
|
||||||
|
}
|
||||||
|
|
||||||
|
public HandlerList getHandlers() {
|
||||||
|
return s_handlers;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static HandlerList getHandlerList() {
|
||||||
|
return s_handlers;
|
||||||
|
}
|
||||||
|
}
|
@ -21,19 +21,12 @@ package us.camin.regions;
|
|||||||
import org.bukkit.event.Event;
|
import org.bukkit.event.Event;
|
||||||
import org.bukkit.event.HandlerList;
|
import org.bukkit.event.HandlerList;
|
||||||
|
|
||||||
public class RegionEvent extends Event {
|
public abstract class RegionEvent extends Event {
|
||||||
private static final HandlerList s_handlers = new HandlerList();
|
private static final HandlerList s_handlers = new HandlerList();
|
||||||
public final EventType type;
|
|
||||||
public final Region region;
|
public final Region region;
|
||||||
|
|
||||||
public enum EventType {
|
public RegionEvent(Region region) {
|
||||||
Added,
|
|
||||||
Removed
|
|
||||||
}
|
|
||||||
|
|
||||||
public RegionEvent(Region region, EventType type) {
|
|
||||||
this.region = region;
|
this.region = region;
|
||||||
this.type = type;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -36,14 +36,15 @@ public class RegionEventHandler implements Listener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onRegionEvent(RegionEvent event) {
|
public void onRegionEvent(RegionRemoveEvent event) {
|
||||||
if (event.type == RegionEvent.EventType.Added) {
|
|
||||||
Location loc = event.region.location();
|
|
||||||
MarkerIcon icon = m_api.getMarkerIcon("default");
|
|
||||||
m_set.createMarker(null, event.region.name(), loc.getWorld().getName(), loc.getX(), loc.getY(), loc.getZ(), icon, false);
|
|
||||||
} else if (event.type == RegionEvent.EventType.Removed) {
|
|
||||||
Marker marker = m_set.findMarkerByLabel(event.region.name());
|
Marker marker = m_set.findMarkerByLabel(event.region.name());
|
||||||
marker.deleteMarker();
|
marker.deleteMarker();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onRegionEvent(RegionCreateEvent event) {
|
||||||
|
Location loc = event.region.location();
|
||||||
|
MarkerIcon icon = m_api.getMarkerIcon("default");
|
||||||
|
m_set.createMarker(null, event.region.name(), loc.getWorld().getName(), loc.getX(), loc.getY(), loc.getZ(), icon, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -73,7 +73,7 @@ public class RegionManager {
|
|||||||
if (!m_regions.containsKey(worldName))
|
if (!m_regions.containsKey(worldName))
|
||||||
m_regions.put(worldName, new ArrayList<Region>());
|
m_regions.put(worldName, new ArrayList<Region>());
|
||||||
if (m_regions.get(worldName).add(r)) {
|
if (m_regions.get(worldName).add(r)) {
|
||||||
m_pm.callEvent(new RegionEvent(r, RegionEvent.EventType.Added));
|
m_pm.callEvent(new RegionCreateEvent(r));
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -83,7 +83,7 @@ public class RegionManager {
|
|||||||
log.fine("Removing region "+r.name()+" from "+r.location());
|
log.fine("Removing region "+r.name()+" from "+r.location());
|
||||||
if (m_regions.containsKey(worldName)) {
|
if (m_regions.containsKey(worldName)) {
|
||||||
if (m_regions.get(worldName).remove(r)) {
|
if (m_regions.get(worldName).remove(r)) {
|
||||||
m_pm.callEvent(new RegionEvent(r, RegionEvent.EventType.Removed));
|
m_pm.callEvent(new RegionRemoveEvent(r));
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
39
src/main/java/us/camin/regions/RegionRemoveEvent.java
Normal file
39
src/main/java/us/camin/regions/RegionRemoveEvent.java
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
package us.camin.regions;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This file is part of Regions
|
||||||
|
*
|
||||||
|
* Regions is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* Regions 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 General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with Regions. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
import org.bukkit.event.Event;
|
||||||
|
import org.bukkit.event.HandlerList;
|
||||||
|
|
||||||
|
public class RegionRemoveEvent extends RegionEvent {
|
||||||
|
public static final HandlerList s_handlers = new HandlerList();
|
||||||
|
|
||||||
|
public RegionRemoveEvent(Region region) {
|
||||||
|
super(region);
|
||||||
|
}
|
||||||
|
|
||||||
|
public HandlerList getHandlers() {
|
||||||
|
return s_handlers;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static HandlerList getHandlerList() {
|
||||||
|
return s_handlers;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user