package me.JRazek.PerRegionChat; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; import org.bukkit.event.Listener; import org.bukkit.event.player.AsyncPlayerChatEvent; import org.bukkit.plugin.Plugin; import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.Location; import org.bukkit.entity.Player; import com.sk89q.worldedit.bukkit.BukkitAdapter; import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.world.World; import com.sk89q.worldguard.WorldGuard; import com.sk89q.worldguard.bukkit.WorldGuardPlugin; import com.sk89q.worldguard.protection.ApplicableRegionSet; import com.sk89q.worldguard.protection.flags.Flag; import com.sk89q.worldguard.protection.flags.StateFlag; import com.sk89q.worldguard.protection.flags.registry.FlagConflictException; import com.sk89q.worldguard.protection.flags.registry.FlagRegistry; import com.sk89q.worldguard.protection.managers.RegionManager; import com.sk89q.worldguard.protection.regions.ProtectedRegion; import com.sk89q.worldguard.protection.regions.RegionContainer; public class Main extends JavaPlugin implements Listener { public static StateFlag MY_CUSTOM_FLAG; @Override public void onLoad() { // ... do your own plugin things, etc FlagRegistry registry = WorldGuard.getInstance().getFlagRegistry(); try { // create a flag with the name "my-custom-flag", defaulting to true StateFlag flag = new StateFlag("my-custom-flag", true); registry.register(flag); MY_CUSTOM_FLAG = flag; // only set our field if there was no error } catch (FlagConflictException e) { // some other plugin registered a flag by the same name already. // you can use the existing flag, but this may cause conflicts - be sure to check type Flag existing = registry.get("my-custom-flag"); if (existing instanceof StateFlag) { MY_CUSTOM_FLAG = (StateFlag) existing; } else { // types don't match - this is bad news! some other plugin conflicts with you // hopefully this never actually happens } } } public WorldGuardPlugin worldGuardPlugin; @Override public void onEnable() { worldGuardPlugin = getWorldGuard(); getServer().getPluginManager().registerEvents(this, this); } public WorldGuardPlugin getWorldGuard() { Plugin plugin = this.getServer().getPluginManager().getPlugin("WorldGuard"); if(plugin == null || !(plugin instanceof WorldGuardPlugin)) { return null; } return (WorldGuardPlugin) plugin; } @EventHandler(priority = EventPriority.NORMAL) public void Chat_activity(AsyncPlayerChatEvent event) { Player player = event.getPlayer(); Location location = player.getLocation(); String message = event.getMessage(); getRegionbyLocation(location); //player.sendMessage("im here"); } public ProtectedRegion getRegionbyLocation(Location location) { World world = BukkitAdapter.adapt(location.getWorld()); RegionContainer container = WorldGuard.getInstance().getPlatform().getRegionContainer(); RegionManager regions = container.get(world); BlockVector3 v = BlockVector3.at(location.getX(), location.getY(), location.getZ()); ApplicableRegionSet set = regions.getApplicableRegions(v); String rgID; for(ProtectedRegion setElement : set) { } return null; } public void onDisable() { } }