From d4ee873f77502fffcfb8505baf961a8622a3fe56 Mon Sep 17 00:00:00 2001 From: Jascha Starke Date: Sat, 11 Feb 2012 13:05:49 +0100 Subject: [PATCH] New (basic) WorldGuard Integration (eventdriven) for less mem usage --- .../minecraft/limitedcreative/Commands.java | 5 +- .../limitedcreative/regions/Flags.java | 11 +++ .../regions/RegionListener.java | 64 +++------------- .../regions/WorldGuardIntegration.java | 29 ++++--- .../minecraft/worldguard/API.java | 40 ++++++++++ .../minecraft/worldguard/CListener.java | 75 +++++++++++++++++++ .../minecraft/worldguard/CPlayer.java | 48 ++++++++++++ .../minecraft/worldguard/CRegionManager.java | 35 +++++++++ .../minecraft/worldguard/FlagList.java | 4 + .../minecraft/worldguard/Integration.java | 26 +++++++ .../minecraft/worldguard/Interface.java | 58 ++++++++++++++ .../events/PlayerChangedAreaEvent.java | 68 +++++++++++++++++ 12 files changed, 395 insertions(+), 68 deletions(-) create mode 100644 src/de/jaschastarke/minecraft/worldguard/API.java create mode 100644 src/de/jaschastarke/minecraft/worldguard/CListener.java create mode 100644 src/de/jaschastarke/minecraft/worldguard/CPlayer.java create mode 100644 src/de/jaschastarke/minecraft/worldguard/Integration.java create mode 100644 src/de/jaschastarke/minecraft/worldguard/Interface.java create mode 100644 src/de/jaschastarke/minecraft/worldguard/events/PlayerChangedAreaEvent.java diff --git a/src/de/jaschastarke/minecraft/limitedcreative/Commands.java b/src/de/jaschastarke/minecraft/limitedcreative/Commands.java index 8738240..19df422 100644 --- a/src/de/jaschastarke/minecraft/limitedcreative/Commands.java +++ b/src/de/jaschastarke/minecraft/limitedcreative/Commands.java @@ -28,7 +28,6 @@ import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; import de.jaschastarke.minecraft.utils.Util; -import de.jaschastarke.minecraft.worldguard.CCommand; import static de.jaschastarke.minecraft.utils.Locale.L; public class Commands { @@ -185,9 +184,7 @@ public class Commands { public static void register(LimitedCreativeCore pplugin) { plugin = pplugin; plugin.getCommand("limitedcreative").setExecutor(new MainCommandExecutor()); - if (plugin.worldguard != null) { - plugin.getCommand("/region").setExecutor(new CCommand(plugin, plugin.worldguard.getRegionManager())); - } else { + if (plugin.worldguard == null) { plugin.getCommand("/region").setExecutor(new NotAvailableCommandExecutor()); } } diff --git a/src/de/jaschastarke/minecraft/limitedcreative/regions/Flags.java b/src/de/jaschastarke/minecraft/limitedcreative/regions/Flags.java index 16a5c4f..e921e01 100644 --- a/src/de/jaschastarke/minecraft/limitedcreative/regions/Flags.java +++ b/src/de/jaschastarke/minecraft/limitedcreative/regions/Flags.java @@ -1,5 +1,9 @@ package de.jaschastarke.minecraft.limitedcreative.regions; +import java.util.Arrays; +import java.util.List; + +import com.sk89q.worldguard.protection.flags.Flag; import com.sk89q.worldguard.protection.flags.RegionGroupFlag; import com.sk89q.worldguard.protection.flags.StateFlag; @@ -10,4 +14,11 @@ public final class Flags { static { CREATIVE.setGroupFlag(CREATIVE_GROUP); } + public static List> getList() { + return Arrays.asList(new Flag[]{ + SPAWNDROPS, + CREATIVE, + CREATIVE_GROUP + }); + } } diff --git a/src/de/jaschastarke/minecraft/limitedcreative/regions/RegionListener.java b/src/de/jaschastarke/minecraft/limitedcreative/regions/RegionListener.java index 01b3599..11f18da 100644 --- a/src/de/jaschastarke/minecraft/limitedcreative/regions/RegionListener.java +++ b/src/de/jaschastarke/minecraft/limitedcreative/regions/RegionListener.java @@ -5,7 +5,6 @@ import static de.jaschastarke.minecraft.utils.Locale.L; import org.bukkit.GameMode; import org.bukkit.Location; import org.bukkit.Material; -import org.bukkit.World; import org.bukkit.block.Block; import org.bukkit.entity.Item; import org.bukkit.event.EventHandler; @@ -15,51 +14,38 @@ import org.bukkit.event.block.BlockPistonExtendEvent; import org.bukkit.event.block.BlockPistonRetractEvent; import org.bukkit.event.block.BlockPlaceEvent; import org.bukkit.event.entity.ItemSpawnEvent; -import org.bukkit.event.player.PlayerMoveEvent; -import org.bukkit.event.player.PlayerTeleportEvent; - -import com.sk89q.worldedit.Vector; -import com.sk89q.worldguard.bukkit.WorldGuardPlugin; -import com.sk89q.worldguard.protection.ApplicableRegionSet; -import com.sk89q.worldguard.protection.managers.RegionManager; import de.jaschastarke.minecraft.limitedcreative.LCPlayer; import de.jaschastarke.minecraft.limitedcreative.LimitedCreativeCore; import de.jaschastarke.minecraft.utils.Util; import de.jaschastarke.minecraft.worldguard.ApplicableRegions; import de.jaschastarke.minecraft.worldguard.CRegionManager; +import de.jaschastarke.minecraft.worldguard.events.PlayerChangedAreaEvent; public class RegionListener implements Listener { private static LimitedCreativeCore plugin = WorldGuardIntegration.plugin; - private static WorldGuardPlugin wg = WorldGuardIntegration.wg; private CRegionManager rm; public RegionListener(WorldGuardIntegration wgi) { rm = wgi.getRegionManager(); } - private ApplicableRegions regionSet(World world, Location loc) { - RegionManager mgr = wg.getGlobalRegionManager().get(world); - return new ApplicableRegions(mgr.getApplicableRegions(loc), rm.world(world)); - } private ApplicableRegions regionSet(Location loc) { - return regionSet(loc.getWorld(), loc); + return rm.getRegionSet(loc); } private ApplicableRegions regionSet(Block block) { - return regionSet(block.getWorld(), block.getLocation()); + return rm.getRegionSet(block); } @EventHandler public void onBlockBreak(BlockBreakEvent event) { if (event.isCancelled()) return; LCPlayer player = LCPlayer.get(event.getPlayer()); - RegionManager mgr = wg.getGlobalRegionManager().get(event.getPlayer().getWorld()); - Vector pt = new Vector(event.getBlock().getLocation().getBlockX(), event.getBlock().getLocation().getBlockY(), event.getBlock().getLocation().getBlockZ()); - ApplicableRegions set = new ApplicableRegions(mgr.getApplicableRegions(pt), rm.world(event.getPlayer().getWorld())); + ApplicableRegions set = rm.getRegionSet(event.getBlock()); if (player.isRegionCreative() && !set.allows(Flags.CREATIVE, player)) { event.getPlayer().sendMessage(L("blocked.outside_creative_break")); event.setCancelled(true); - } else if (set.allows(Flags.CREATIVE) && player.getRaw().getGameMode() != GameMode.CREATIVE) { + } else if (player.getRaw().getGameMode() != GameMode.CREATIVE && set.allows(Flags.CREATIVE)) { plugin.spawnblock.block(event.getBlock(), player); } } @@ -69,11 +55,9 @@ public class RegionListener implements Listener { if (event.isCancelled()) return; LCPlayer player = LCPlayer.get(event.getPlayer()); - if (player.isRegionCreative()) { + if (player.isRegionCreative() && rm.isDiffrentRegion(event.getPlayer(), event.getBlock().getLocation())) { // do not build outside of creative regions, when in the region - RegionManager mgr = wg.getGlobalRegionManager().get(event.getPlayer().getWorld()); - Vector pt = new Vector(event.getBlock().getLocation().getBlockX(), event.getBlock().getLocation().getBlockY(), event.getBlock().getLocation().getBlockZ()); - ApplicableRegions set = new ApplicableRegions(mgr.getApplicableRegions(pt), rm.world(event.getPlayer().getWorld())); + ApplicableRegions set = rm.getRegionSet(event.getBlock()); if (!set.allows(Flags.CREATIVE, player)) { event.getPlayer().sendMessage(L("blocked.outside_creative")); event.setCancelled(true); @@ -82,38 +66,8 @@ public class RegionListener implements Listener { } @EventHandler - public void onPlayerMove(PlayerMoveEvent event) { - if (event.isCancelled()) - return; - if (event.getFrom().getBlockX() != event.getTo().getBlockX() - || event.getFrom().getBlockY() != event.getTo().getBlockY() - || event.getFrom().getBlockZ() != event.getTo().getBlockZ()) { - - LCPlayer player = LCPlayer.get(event.getPlayer()); - RegionManager mgr = wg.getGlobalRegionManager().get(event.getPlayer().getWorld()); - ApplicableRegionSet applicableRegions = mgr.getApplicableRegions(event.getTo()); - LimitedCreativeCore.debug(applicableRegions.toString()); - ApplicableRegions set = new ApplicableRegions(applicableRegions, rm.world(event.getPlayer().getWorld())); - - player.setRegionCreativeAllowed(set.allows(Flags.CREATIVE, player), event); - } - } - - @EventHandler - public void onPlayerTeleport(PlayerTeleportEvent event) { - if (event.isCancelled()) - return; - if (event.getFrom().getBlockX() != event.getTo().getBlockX() - || event.getFrom().getBlockY() != event.getTo().getBlockY() - || event.getFrom().getBlockZ() != event.getTo().getBlockZ()) { - - LCPlayer player = LCPlayer.get(event.getPlayer()); - RegionManager mgr = wg.getGlobalRegionManager().get(event.getPlayer().getWorld()); - Vector pt = new Vector(event.getTo().getBlockX(), event.getTo().getBlockY(), event.getTo().getBlockZ()); - ApplicableRegions set = new ApplicableRegions(mgr.getApplicableRegions(pt), rm.world(event.getPlayer().getWorld())); - - player.setRegionCreativeAllowed(set.allows(Flags.CREATIVE, player), event); - } + public void onPlayerChangedArea(PlayerChangedAreaEvent event) { + LCPlayer.get(event.getPlayer()).setRegionCreativeAllowed(event.getNewRegionSet().allows(Flags.CREATIVE), event.getMoveEvent()); } @EventHandler diff --git a/src/de/jaschastarke/minecraft/limitedcreative/regions/WorldGuardIntegration.java b/src/de/jaschastarke/minecraft/limitedcreative/regions/WorldGuardIntegration.java index 51545d7..e52b286 100644 --- a/src/de/jaschastarke/minecraft/limitedcreative/regions/WorldGuardIntegration.java +++ b/src/de/jaschastarke/minecraft/limitedcreative/regions/WorldGuardIntegration.java @@ -17,33 +17,44 @@ */ package de.jaschastarke.minecraft.limitedcreative.regions; -import java.io.File; +import java.util.List; import com.sk89q.worldguard.bukkit.WorldGuardPlugin; +import com.sk89q.worldguard.protection.flags.Flag; import de.jaschastarke.minecraft.limitedcreative.LimitedCreativeCore; import de.jaschastarke.minecraft.worldguard.CRegionManager; -import de.jaschastarke.minecraft.worldguard.FlagList; +import de.jaschastarke.minecraft.worldguard.Integration; +import de.jaschastarke.minecraft.worldguard.Interface; -public class WorldGuardIntegration { +public class WorldGuardIntegration implements Integration { public static LimitedCreativeCore plugin; public static WorldGuardPlugin wg; - private CRegionManager rm; public WorldGuardIntegration(LimitedCreativeCore plugin) { WorldGuardIntegration.plugin = plugin; wg = (WorldGuardPlugin) plugin.getServer().getPluginManager().getPlugin("WorldGuard"); - rm = new CRegionManager(new File(plugin.getDataFolder(), "regions.yml")); + /* + * This should be only done by the "API"-Plugin itself (when its done). You don't need to that again if you + * like to interact with LimitedCreative's WorldGuard-Integration + */ + new Interface(plugin); - FlagList.addFlag(Flags.CREATIVE); - FlagList.addFlag(Flags.CREATIVE_GROUP); - FlagList.addFlag(Flags.SPAWNDROPS); + /* + * You only need to do this one, to make your Flags available. + */ + Interface.getInstance().register(this); plugin.getServer().getPluginManager().registerEvents(new RegionListener(this), plugin); } public CRegionManager getRegionManager() { - return rm; + return Interface.getInstance().getRegionManager(); + } + + @Override + public List> getFlags() { + return Flags.getList(); } } diff --git a/src/de/jaschastarke/minecraft/worldguard/API.java b/src/de/jaschastarke/minecraft/worldguard/API.java new file mode 100644 index 0000000..d849589 --- /dev/null +++ b/src/de/jaschastarke/minecraft/worldguard/API.java @@ -0,0 +1,40 @@ +/* + * Limited Creative - (Bukkit Plugin) + * Copyright (C) 2012 jascha@ja-s.de + * + * This program 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. + * + * 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package de.jaschastarke.minecraft.worldguard; + +import org.bukkit.plugin.java.JavaPlugin; + +/** + * This Namespace may be used as a Standalone-Plugin just providing the WorldGuard-API + * TODO: Not done yet + */ +public class API extends JavaPlugin { + @Override + public void onDisable() { + // TODO Auto-generated method stub + + } + + @Override + public void onEnable() { + throw new IllegalArgumentException("Not yet supported"); + // TODO Auto-generated method stub + + } + +} diff --git a/src/de/jaschastarke/minecraft/worldguard/CListener.java b/src/de/jaschastarke/minecraft/worldguard/CListener.java new file mode 100644 index 0000000..c13829d --- /dev/null +++ b/src/de/jaschastarke/minecraft/worldguard/CListener.java @@ -0,0 +1,75 @@ +/* + * Limited Creative - (Bukkit Plugin) + * Copyright (C) 2012 jascha@ja-s.de + * + * This program 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. + * + * 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package de.jaschastarke.minecraft.worldguard; + +import org.bukkit.Bukkit; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.player.PlayerJoinEvent; +import org.bukkit.event.player.PlayerMoveEvent; +import org.bukkit.event.player.PlayerQuitEvent; +import org.bukkit.event.player.PlayerTeleportEvent; + +import de.jaschastarke.minecraft.worldguard.events.PlayerChangedAreaEvent; + +public class CListener implements Listener { + private Interface com; + public CListener(Interface com) { + this.com = com; + } + + @EventHandler + public void onPlayerMove(PlayerMoveEvent event) { + if (event.isCancelled()) + return; + if (event.getFrom().getBlockX() != event.getTo().getBlockX() + || event.getFrom().getBlockY() != event.getTo().getBlockY() + || event.getFrom().getBlockZ() != event.getTo().getBlockZ()) { // he really moved, and not just looked around + + if (com.getRegionManager().isDiffrentRegion(event.getPlayer(), event.getTo())) { + Bukkit.getServer().getPluginManager().callEvent(new PlayerChangedAreaEvent(event)); + CPlayer.get(event.getPlayer()).setHash(com.getRegionManager().getRegionsHash(event.getTo())); + } + } + } + + @EventHandler + public void onPlayerTeleport(PlayerTeleportEvent event) { + if (event.isCancelled()) + return; + if (event.getFrom().getBlockX() != event.getTo().getBlockX() + || event.getFrom().getBlockY() != event.getTo().getBlockY() + || event.getFrom().getBlockZ() != event.getTo().getBlockZ()) { // he really moved, and not just looked around + + if (com.getRegionManager().isDiffrentRegion(event.getPlayer(), event.getTo())) { + Bukkit.getServer().getPluginManager().callEvent(new PlayerChangedAreaEvent(event)); + CPlayer.get(event.getPlayer()).setHash(com.getRegionManager().getRegionsHash(event.getTo())); + } + } + } + + @EventHandler + public void onPlayerLogin(PlayerJoinEvent event) { + CPlayer.get(event.getPlayer()).setHash(com.getRegionManager().getRegionsHash(event.getPlayer().getLocation())); + } + + @EventHandler + public void onPlayerLogout(PlayerQuitEvent event) { + CPlayer.remove(event.getPlayer()); + } +} diff --git a/src/de/jaschastarke/minecraft/worldguard/CPlayer.java b/src/de/jaschastarke/minecraft/worldguard/CPlayer.java new file mode 100644 index 0000000..3913c58 --- /dev/null +++ b/src/de/jaschastarke/minecraft/worldguard/CPlayer.java @@ -0,0 +1,48 @@ +/* + * Limited Creative - (Bukkit Plugin) + * Copyright (C) 2012 jascha@ja-s.de + * + * This program 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. + * + * 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package de.jaschastarke.minecraft.worldguard; + +import java.util.HashMap; +import java.util.Map; + +import org.bukkit.entity.Player; + +public class CPlayer { + private static Map players = new HashMap(); + + public static CPlayer get(Player p) { + if (!players.containsKey(p.getName())) { + CPlayer pl = new CPlayer(); + players.put(p.getName(), pl); + return pl; + } else { + return players.get(p.getName()); + } + } + public static void remove(Player p) { + players.remove(p.getName()); + } + + private String hash = null; + public String getHash() { + return hash; + } + public void setHash(String hash) { + this.hash = hash; + } +} diff --git a/src/de/jaschastarke/minecraft/worldguard/CRegionManager.java b/src/de/jaschastarke/minecraft/worldguard/CRegionManager.java index 3ff6cf9..80b2c96 100644 --- a/src/de/jaschastarke/minecraft/worldguard/CRegionManager.java +++ b/src/de/jaschastarke/minecraft/worldguard/CRegionManager.java @@ -20,17 +20,26 @@ package de.jaschastarke.minecraft.worldguard; import java.io.File; import java.io.IOException; import java.util.ArrayList; +import java.util.Arrays; import java.util.HashMap; import java.util.List; import java.util.Map; +import org.bukkit.Location; import org.bukkit.World; +import org.bukkit.block.Block; import org.bukkit.configuration.ConfigurationSection; import org.bukkit.configuration.file.YamlConfiguration; +import org.bukkit.entity.Player; +import com.sk89q.worldguard.bukkit.BukkitUtil; +import com.sk89q.worldguard.protection.GlobalRegionManager; import com.sk89q.worldguard.protection.flags.Flag; +import com.sk89q.worldguard.protection.managers.RegionManager; import com.sk89q.worldguard.protection.regions.ProtectedRegion; +import de.jaschastarke.minecraft.utils.Util; + public class CRegionManager { protected YamlConfiguration c; protected File file; @@ -118,4 +127,30 @@ public class CRegionManager { return list; } } + + public GlobalRegionManager getWGGlobalManager() { + return Interface.getInstance().getWorldGuard().getGlobalRegionManager(); + } + public RegionManager getWGManager(World world) { + return Interface.getInstance().getWorldGuard().getRegionManager(world); + } + + public String getRegionsHash(Location loc) { + List idlist = getWGGlobalManager().get(loc.getWorld()).getApplicableRegionsIDs(BukkitUtil.toVector(loc)); + String[] ids = idlist.toArray(new String[idlist.size()]); + Arrays.sort(ids); + return Util.join(ids, "|"); + } + + public ApplicableRegions getRegionSet(Location loc) { + return new ApplicableRegions(getWGManager(loc.getWorld()).getApplicableRegions(loc), this.world(loc.getWorld())); + } + + public ApplicableRegions getRegionSet(Block block) { + return getRegionSet(block.getLocation()); + } + + public boolean isDiffrentRegion(Player player, Location loc) { + return !getRegionsHash(loc).equals(CPlayer.get(player).getHash()); + } } diff --git a/src/de/jaschastarke/minecraft/worldguard/FlagList.java b/src/de/jaschastarke/minecraft/worldguard/FlagList.java index 69e87d7..bd136ce 100644 --- a/src/de/jaschastarke/minecraft/worldguard/FlagList.java +++ b/src/de/jaschastarke/minecraft/worldguard/FlagList.java @@ -18,6 +18,7 @@ package de.jaschastarke.minecraft.worldguard; import java.util.ArrayList; +import java.util.Collection; import java.util.List; import org.bukkit.command.CommandSender; @@ -33,6 +34,9 @@ public class FlagList { public static void addFlag(Flag flag) { list.add(flag); } + public static void addFlags(Collection> flags) { + list.addAll(flags); + } public static Flag getFlag(String flag) { for (Flag f : list) { if (f.getName().replace("-", "").equalsIgnoreCase(flag.replace("-", ""))) { diff --git a/src/de/jaschastarke/minecraft/worldguard/Integration.java b/src/de/jaschastarke/minecraft/worldguard/Integration.java new file mode 100644 index 0000000..799beff --- /dev/null +++ b/src/de/jaschastarke/minecraft/worldguard/Integration.java @@ -0,0 +1,26 @@ +/* + * Limited Creative - (Bukkit Plugin) + * Copyright (C) 2012 jascha@ja-s.de + * + * This program 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. + * + * 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package de.jaschastarke.minecraft.worldguard; + +import java.util.List; + +import com.sk89q.worldguard.protection.flags.Flag; + +public interface Integration { + public List> getFlags(); +} diff --git a/src/de/jaschastarke/minecraft/worldguard/Interface.java b/src/de/jaschastarke/minecraft/worldguard/Interface.java new file mode 100644 index 0000000..a38438a --- /dev/null +++ b/src/de/jaschastarke/minecraft/worldguard/Interface.java @@ -0,0 +1,58 @@ +/* + * Limited Creative - (Bukkit Plugin) + * Copyright (C) 2012 jascha@ja-s.de + * + * This program 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. + * + * 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package de.jaschastarke.minecraft.worldguard; + +import java.io.File; + +import org.bukkit.plugin.java.JavaPlugin; + +import com.sk89q.worldguard.bukkit.WorldGuardPlugin; + +public class Interface { + //private JavaPlugin plugin; + private CRegionManager mgr; + private WorldGuardPlugin wg; + private static Interface _instance = null; + + public Interface(JavaPlugin plugin) { + if (_instance != null) + throw new RuntimeException("The Interface is Singleton!"); + //this.plugin = plugin; + _instance = this; + + wg = (WorldGuardPlugin) plugin.getServer().getPluginManager().getPlugin("WorldGuard"); + + + mgr = new CRegionManager(new File(plugin.getDataFolder(), "regions.yml")); + plugin.getCommand("/region").setExecutor(new CCommand(plugin, mgr, wg)); + plugin.getServer().getPluginManager().registerEvents(new CListener(this), plugin); + } + public static Interface getInstance() { + return _instance; + } + + public void register(Integration integration) { + FlagList.addFlags(integration.getFlags()); + } + public WorldGuardPlugin getWorldGuard() { + return wg; + } + public CRegionManager getRegionManager() { + return mgr; + } +} diff --git a/src/de/jaschastarke/minecraft/worldguard/events/PlayerChangedAreaEvent.java b/src/de/jaschastarke/minecraft/worldguard/events/PlayerChangedAreaEvent.java new file mode 100644 index 0000000..69e68f0 --- /dev/null +++ b/src/de/jaschastarke/minecraft/worldguard/events/PlayerChangedAreaEvent.java @@ -0,0 +1,68 @@ +/* + * Limited Creative - (Bukkit Plugin) + * Copyright (C) 2012 jascha@ja-s.de + * + * This program 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. + * + * 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package de.jaschastarke.minecraft.worldguard.events; + +import org.bukkit.entity.Player; +import org.bukkit.event.Event; +import org.bukkit.event.HandlerList; +import org.bukkit.event.player.PlayerMoveEvent; +import org.bukkit.event.player.PlayerTeleportEvent; + +import de.jaschastarke.minecraft.limitedcreative.LimitedCreativeCore; +import de.jaschastarke.minecraft.worldguard.ApplicableRegions; +import de.jaschastarke.minecraft.worldguard.Interface; + +@SuppressWarnings("serial") +public class PlayerChangedAreaEvent extends Event { + private PlayerMoveEvent event; + + public PlayerChangedAreaEvent(PlayerMoveEvent moveevent) { + event = moveevent; + } + + public Player getPlayer() { + return event.getPlayer(); + } + + public boolean isTeleport() { + return event instanceof PlayerTeleportEvent; + } + + public ApplicableRegions getPreviousRegionSet() { + return Interface.getInstance().getRegionManager().getRegionSet(event.getFrom()); + } + public ApplicableRegions getNewRegionSet() { + return Interface.getInstance().getRegionManager().getRegionSet(event.getTo()); + } + + private static final HandlerList handlers = new HandlerList(); + + public HandlerList getHandlers() { + LimitedCreativeCore.debug("getHandlers"); + return handlers; + } + + public static HandlerList getHandlerList() { + LimitedCreativeCore.debug("getHandlerList"); + return handlers; + } + + public PlayerMoveEvent getMoveEvent() { + return event; + } +}