RedProtect API - FabioZumbi12/RedProtect GitHub Wiki

RedProtect offer an API to easily manage the regions, check for flags and player permissions.
Use the Github maven api in your pom.xml:

Maven Repository

Repository:

<repositories>  
    <repository>  
        <id>redprotect-repo</id>  
        <url>https://raw.githubusercontent.com/FabioZumbi12/RedProtect/mvn-repo/</url>  
    </repository>  
</repositories>  

Dependency:

<dependencies>  
    <dependency>  
        //Core is needed
        <groupId>br.net.fabiozumbi12.RedProtect</groupId>  
        <artifactId>RedProtect-Core</artifactId>  
        <version>LATEST</version>  
        <scope>provided</scope>  
    </dependency>

    <dependency>  
        <groupId>br.net.fabiozumbi12.RedProtect</groupId>  
        <artifactId>RedProtect-[Check below for dependency names]</artifactId>  
        <version>LATEST</version>  
        <scope>provided</scope>  
    </dependency>
    <dependency>  
        <groupId>br.net.fabiozumbi12.RedProtect</groupId>  
        <artifactId>RedProtect-[Check below for dependency names]</artifactId>  
        <version>LATEST</version>
        <classifier>javadoc</classifier>
    </dependency>   
</dependencies>  

Check the dependency names and APIs: Click here

Check if a Region exists

You can check if the Redprotect is present and loaded using the code on your main class:

    public static boolean redProtect;

    public MyPluginClass extends JavaPlugin {

        public void onEnable() {
            redProtect = checkRP();
        }

        private boolean checkRP(){
        	Plugin pRP = Bukkit.getPluginManager().getPlugin("RedProtect");
        	if (pRP != null && pRP.isEnabled()){
        		return true;
        	}
        	return false;
        }
    }

With this we check if the RedProtect is installed and enabled. Now, you can use the method RedProtect.get().getAPI() to get the region, flags or add flags, and all other API methods from api.

Example 1 - Get region the player is

    public static Region getPlayerRegion(Player p){
        if (MyPluginClass.redProtect){
             return RedProtect.get().getAPI().getRegion(p.getLocation());
        }
        return null;
    }

If there's no region on player location, the method will return null.

Example 2 - Changing a flag

    Region r = getPlayerRegion(p);
    if (r != null){
        r.setFlag("chest",true); //allow others to access chests on region; 
    }

Example 3 - Allow or deny something, checking if a player can build

    Region r = getPlayerRegion(p);
    if (r != null && r.canBuild(p)){
        //do something to allowed players
    }

Example 4 - Get the leaders

    Region r = getPlayerRegion(p);
    //If in Online Mode, will return the UUIDs as string!
    List<PlayerRegion> leaders = r.getLeaders();
    if (!leaders.isEmpty()){
      String uuid= leaders.get(0).getUUID();
      String player = leaders.get(0).getPlayerName();
    }

You can see more info on API class with cometed methods: https://github.com/FabioZumbi12/RedProtect/blob/master/RedProtect-Spigot/src/main/java/br/net/fabiozumbi12/RedProtect/Bukkit/API/RedProtectAPI.java

⚠️ **GitHub.com Fallback** ⚠️