Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
- import com.sk89q.worldguard.protection.managers.RegionManager;
- import com.sk89q.worldguard.protection.regions.ProtectedRegion;
- import org.bukkit.Bukkit;
- import org.bukkit.World;
- import org.bukkit.entity.Player;
- import org.bukkit.plugin.Plugin;
- /**
- * Project created by ExpDev
- */
- public class WgTest {
- /**
- * Executes when the programs runs
- */
- public static void main(String[] strings) {
- // initializing class so I can use the getWorldGuard method
- WgTest wgTest = new WgTest();
- // creating a Player object from my name :)
- Player p = Bukkit.getPlayer("ExpDev");
- // checking if the player exists/is online
- if(p == null) {
- // they aren't. aborttttt
- System.out.println("Player is not online or does not exist");
- return;
- }
- // getting the world guard plugin
- WorldGuardPlugin wg = wgTest.getWorldGuard();
- // checking whether or not the dependency is installed
- if(wg == null) {
- // it ain't. you might wanna disable the plugin then
- System.out.println("World Guard plugin is not to be found. Disable plugin if it is dependant on it.");
- return;
- }
- // the world we will be looking in
- World w = Bukkit.getWorld("world");
- // getting the region manager
- RegionManager manager = manager = wg.getRegionManager(w);;
- // the region you want to look for the player in
- ProtectedRegion region = manager.getRegion("region");
- // checking if the given region exists or not
- if(region == null) {
- // doesn't exist. do nothing
- System.out.println("That region does not exist.");
- return;
- }
- // our true/false result of whether or not the player's position is contained in the region
- boolean inRegion = region.contains(wg.wrapPlayer(p).getPosition());
- // printing out whether it is or not
- System.out.println("Player " + p.getName() + " is in region " + region.getId() + ": " + inRegion);
- }
- /**
- * Get the world guard plugin instance
- * @return The world guard plugin instance (null if not found)
- */
- private WorldGuardPlugin getWorldGuard() {
- Plugin plugin = Bukkit.getServer().getPluginManager().getPlugin("WorldGuard");
- // WorldGuard may not be loaded
- if (plugin == null || !(plugin instanceof WorldGuardPlugin)) {
- return null; // Maybe you want throw an exception instead
- }
- return (WorldGuardPlugin) plugin;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement