Facebook
From Sludgy Hamster, 4 Years ago, written in Plain Text.
Embed
Download Paste or View Raw
Hits: 191
  1. package me.JRazek.PerRegionChat;
  2.  
  3. import org.bukkit.event.EventHandler;
  4. import org.bukkit.event.EventPriority;
  5. import org.bukkit.event.Listener;
  6. import org.bukkit.event.player.AsyncPlayerChatEvent;
  7. import org.bukkit.plugin.Plugin;
  8. import org.bukkit.plugin.java.JavaPlugin;
  9.  
  10. import org.bukkit.Location;
  11.  
  12.  
  13. import org.bukkit.entity.Player;
  14.  
  15. import com.sk89q.worldedit.bukkit.BukkitAdapter;
  16. import com.sk89q.worldedit.math.BlockVector3;
  17. import com.sk89q.worldedit.world.World;
  18. import com.sk89q.worldguard.WorldGuard;
  19. import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
  20. import com.sk89q.worldguard.protection.ApplicableRegionSet;
  21. import com.sk89q.worldguard.protection.flags.Flag;
  22. import com.sk89q.worldguard.protection.flags.StateFlag;
  23. import com.sk89q.worldguard.protection.flags.registry.FlagConflictException;
  24. import com.sk89q.worldguard.protection.flags.registry.FlagRegistry;
  25. import com.sk89q.worldguard.protection.managers.RegionManager;
  26. import com.sk89q.worldguard.protection.regions.ProtectedRegion;
  27. import com.sk89q.worldguard.protection.regions.RegionContainer;
  28.  
  29. public class Main extends JavaPlugin implements Listener {
  30.        
  31.         public static StateFlag MY_CUSTOM_FLAG;
  32.  
  33.         @Override
  34.         public void onLoad() {
  35.             // ... do your own plugin things, etc
  36.  
  37.             FlagRegistry registry = WorldGuard.getInstance().getFlagRegistry();
  38.             try {
  39.                 // create a flag with the name "my-custom-flag", defaulting to true
  40.                 StateFlag flag = new StateFlag("my-custom-flag", true);
  41.                 registry.register(flag);
  42.                 MY_CUSTOM_FLAG = flag; // only set our field if there was no error
  43.             } catch (FlagConflictException e) {
  44.                 // some other plugin registered a flag by the same name already.
  45.                 // you can use the existing flag, but this may cause conflicts - be sure to check type
  46.                 Flag<?> existing = registry.get("my-custom-flag");
  47.                 if (existing instanceof StateFlag) {
  48.                     MY_CUSTOM_FLAG = (StateFlag) existing;
  49.                 } else {
  50.                     // types don't match - this is bad news! some other plugin conflicts with you
  51.                     // hopefully this never actually happens
  52.                 }
  53.             }
  54.         }
  55.         public WorldGuardPlugin worldGuardPlugin;
  56.         @Override
  57.         public void onEnable() {
  58.                 worldGuardPlugin = getWorldGuard();
  59.                 getServer().getPluginManager().registerEvents(this, this);
  60.         }
  61.        
  62.         public WorldGuardPlugin getWorldGuard() {
  63.                 Plugin plugin = this.getServer().getPluginManager().getPlugin("WorldGuard");
  64.                 if(plugin == null || !(plugin instanceof WorldGuardPlugin)) {
  65.                         return null;
  66.                 }
  67.                 return (WorldGuardPlugin) plugin;
  68.         }
  69.         @EventHandler(priority = EventPriority.NORMAL)
  70.         public void Chat_activity(AsyncPlayerChatEvent event) {
  71.                 Player player = event.getPlayer();
  72.                 Location location = player.getLocation();      
  73.                 String message = event.getMessage();
  74.                 getRegionbyLocation(location);
  75.                 //player.sendMessage("im here");
  76.         }
  77.         public ProtectedRegion getRegionbyLocation(Location location) {
  78.                 World world = BukkitAdapter.adapt(location.getWorld());
  79.                 RegionContainer container = WorldGuard.getInstance().getPlatform().getRegionContainer();
  80.         RegionManager regions = container.get(world);
  81.         BlockVector3 v = BlockVector3.at(location.getX(), location.getY(), location.getZ());
  82.         ApplicableRegionSet set = regions.getApplicableRegions(v);
  83.         String rgID;
  84.         for(ProtectedRegion setElement : set) {
  85.                
  86.         }
  87.                 return null;
  88.         }
  89.        
  90.         public void onDisable() {
  91.                
  92.         }
  93. }
  94.