diff --git a/src/main/java/us/camin/regions/BukkitEventHandler.java b/src/main/java/us/camin/regions/BukkitEventHandler.java new file mode 100644 index 0000000..f8b21a4 --- /dev/null +++ b/src/main/java/us/camin/regions/BukkitEventHandler.java @@ -0,0 +1,53 @@ +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 . + * + */ + +import org.bukkit.event.Listener; +import org.bukkit.event.EventHandler; +import org.bukkit.event.player.PlayerTeleportEvent; +import org.bukkit.event.player.PlayerJoinEvent; +import org.bukkit.event.player.PlayerRespawnEvent; +import org.bukkit.event.player.PlayerChangedWorldEvent; + +public class BukkitEventHandler implements Listener { + Plugin m_plugin; + public BukkitEventHandler(Plugin p) { + m_plugin = p; + } + + @EventHandler + public void onTeleport(PlayerTeleportEvent event) { + m_plugin.recalculatePlayerRegions(); + } + + @EventHandler + public void onJoin(PlayerJoinEvent event) { + m_plugin.recalculatePlayerRegions(); + } + + @EventHandler + public void onRespawn(PlayerRespawnEvent event) { + m_plugin.recalculatePlayerRegions(); + } + + @EventHandler + public void onWorldChange(PlayerChangedWorldEvent event) { + m_plugin.recalculatePlayerRegions(); + } +} diff --git a/src/main/java/us/camin/regions/Plugin.java b/src/main/java/us/camin/regions/Plugin.java index 8f33577..f8680e6 100644 --- a/src/main/java/us/camin/regions/Plugin.java +++ b/src/main/java/us/camin/regions/Plugin.java @@ -60,6 +60,8 @@ public class Plugin extends JavaPlugin { getCommand("homeregion").setExecutor(new HomeRegionCommand(this)); getCommand("movein").setExecutor(new MoveinRegionCommand(this)); + getServer().getPluginManager().registerEvents(new BukkitEventHandler(this), this); + org.bukkit.plugin.Plugin mapPlugin = getServer().getPluginManager().getPlugin("dynmap"); if (mapPlugin instanceof DynmapCommonAPI) { DynmapCommonAPI mapAPI = (DynmapCommonAPI)mapPlugin;