Development/Hooking the plugin

Hooking

Hooking is simple:

ZureZones zure = ZureZones.getInstance();

But making it a little bit safer we can check if the plugin is already loaded:

ZureZones zure = null;
if (Bukkit.getPluginManager().isPluginEnabled("ZureZones"))
ZureZones zure = ZureZones.getInstance();

But we can use the bukkit way if you like it:

ZureZones zure = null;
if (Bukkit.getPluginManager().isPluginEnabled("ZureZones")) {
   Plugin plugin = Bukkit.getPluginManager().getPlugin("ZureZones");
   if (plugin != null && plugin instanceof ZureZones)
      zure = (ZureZones)plugin;
}

Using the hook

//getting the ZoneManager object:
ZoneManager zones = zure.getZoneManager();

//getting the dominant zone at a location:
Location loc = new Location(Bukkit.getWorld("world"),0,0,0);
Zone z = zones.getZoneAt(loc);

//gettings all the zones in a location:
ArrayList<Zone> zonesAt = zones.getZonesAt(loc);

//sorting them by priority:
ZoneList.sortByPriority(zonesAt);

//renaming a zone:
boolean renamed = z.rename("renamedZone");
if (renamed)
   System.out.println("The zone has been successfully renamed.");
else {
   System.out.println("The renaming has been failed.");
   System.out.println("May the name in the world is already taken.");
}

//adding a member to a zone:
Player p = Bukkit.getPlayer("Davesama");
z.getAttributes().setAccess(PlayerID.get(p), Access.OWNER);

//setting flag values on a zone:
ZoneFlags.<flag_name>
   .<setValue>(z.getAttributes(), <additional arguments>);

//settings flag values manually on zone:
z.getAttributes().setFlagNode("BUILD", false);
//but be warned, this means that you prohibited all the users
//from building on the zone, even the owner, so it is advised
//to use the methods of the flags

Listening to zure events

Example:

public class ZureListener implements Listener {

   public void register() {
      Bukkit.getPluginManager
         .registerEvents(this, <your plugin>);
   }

   @EventHandler
   public void onCreate(ZoneCreateEvent event) {
      if (event.getZoneName().contains("evil")) {
         event.setCancelled(true);
         event.getCreator().sendMessage(
            "§cYou cannot create evil zones!");
      }
   }

   @EventHandler
   public void onEnterZones(PlayerEnteredZonesEvent event) {
      PlayerID id = PlayerID.get(event.getPlayer());
      boolean entered = false;
      for (Zone z : event.getZones()) {
         if (z.getAttributes().getAccess(id)
          <= Access.GLOBALLY_ALLOWED) {
            entered = true;
            break;
         }
      }
      if (entered)
         event.getPlayer().sendMessage(
            "§eYou entered the territory of someone else!");
   }

}

Comments

Posts Quoted:
Reply
Clear All Quotes