mirror of
https://gitlab.com/SamB440/rpgregions-2.git
synced 2025-12-27 10:49:08 +00:00
Document API events
This commit is contained in:
@@ -1,28 +1,49 @@
|
||||
package net.islandearth.rpgregions.api.events;
|
||||
|
||||
import net.islandearth.rpgregions.managers.data.region.Discovery;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.HandlerList;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class RegionDiscoverEvent extends Event {
|
||||
|
||||
private static final HandlerList HANDLER_LIST = new HandlerList();
|
||||
private final Player player;
|
||||
private final String region;
|
||||
private final Discovery discovery;
|
||||
|
||||
public RegionDiscoverEvent(Player player, String region) {
|
||||
public RegionDiscoverEvent(Player player, String region, Discovery discovery) {
|
||||
this.player = player;
|
||||
this.region = region;
|
||||
this.discovery = discovery;
|
||||
}
|
||||
|
||||
/**
|
||||
* The player involved in this event.
|
||||
* @return the player involved
|
||||
*/
|
||||
public Player getPlayer() {
|
||||
return player;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the region that has been discovered.
|
||||
* @return {@link List} of regions
|
||||
*/
|
||||
public String getRegion() {
|
||||
return region;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the discovery involved. Contains useful information such as the date.
|
||||
* @return the region {@link Discovery}
|
||||
*/
|
||||
public Discovery getDiscovery() {
|
||||
return discovery;
|
||||
}
|
||||
|
||||
@Override
|
||||
public HandlerList getHandlers() {
|
||||
return HANDLER_LIST;
|
||||
|
||||
@@ -17,10 +17,18 @@ public class RegionsEffectEvent extends Event {
|
||||
this.regions = regions;
|
||||
}
|
||||
|
||||
/**
|
||||
* The player involved in this event.
|
||||
* @return the player involved
|
||||
*/
|
||||
public Player getPlayer() {
|
||||
return player;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a list of all regions that will give effects to the player.
|
||||
* @return {@link List} of regions
|
||||
*/
|
||||
public List<String> getRegions() {
|
||||
return regions;
|
||||
}
|
||||
|
||||
@@ -30,14 +30,27 @@ public class RegionsEnterEvent extends Event {
|
||||
return player;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a list of all regions that have been entered.
|
||||
* @return {@link List} of regions
|
||||
*/
|
||||
public List<String> getRegions() {
|
||||
return regions;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the prioritised region. This will be the first element in the regions array.
|
||||
* This is the region that will be prioritised for particles. Effects etc will stack.
|
||||
* @return the region at the start of the regions array
|
||||
*/
|
||||
public String getPriority() {
|
||||
return regions.get(0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether the player has truly moved into a new region.
|
||||
* @return whether player has truly moved into a new region
|
||||
*/
|
||||
public boolean hasChanged() {
|
||||
return hasChanged;
|
||||
}
|
||||
|
||||
@@ -44,8 +44,19 @@ public interface IntegrationManager {
|
||||
*/
|
||||
Optional<ConfiguredRegion> getPrioritisedRegion(Location location);
|
||||
|
||||
/**
|
||||
* Checks whether this region exists within the world specified
|
||||
* @param location {@link World} to check
|
||||
* @param region the region id
|
||||
* @return true if region exists in world, false otherwise
|
||||
*/
|
||||
boolean exists(World location, String region);
|
||||
|
||||
/**
|
||||
* Gets an immutable set of all region names in the specified world.
|
||||
* @param world {@link World} to check
|
||||
* @return set of all region names
|
||||
*/
|
||||
Set<String> getAllRegionNames(World world);
|
||||
|
||||
default boolean checkRequirements(PlayerMoveEvent event, String region) {
|
||||
|
||||
@@ -72,8 +72,9 @@ public class RegionListener implements Listener {
|
||||
plugin.debug("Discovering region.");
|
||||
LocalDateTime date = LocalDateTime.now();
|
||||
String formattedDate = date.format(format);
|
||||
account.addDiscovery(new WorldDiscovery(formattedDate, region));
|
||||
Bukkit.getPluginManager().callEvent(new RegionDiscoverEvent(player, region));
|
||||
Discovery discovery = new WorldDiscovery(formattedDate, region);
|
||||
account.addDiscovery(discovery);
|
||||
Bukkit.getPluginManager().callEvent(new RegionDiscoverEvent(player, region, discovery));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -26,8 +26,12 @@ public enum StorageType {
|
||||
plugin.getLogger().info("Loading StorageManager implementation...");
|
||||
IStorageManager generatedClazz = null;
|
||||
try {
|
||||
generatedClazz = clazz.getConstructor(RPGRegions.class).newInstance(JavaPlugin.getPlugin(RPGRegions.class));
|
||||
generatedClazz = clazz.getConstructor(RPGRegions.class).newInstance(plugin);
|
||||
plugin.getLogger().info("Loaded StorageManager implementation " + clazz.getName() + ".");
|
||||
if (generatedClazz instanceof YamlStorage) {
|
||||
plugin.getLogger().warning("You are using the YamlStorage implementation which is " +
|
||||
"not recommended for performance if dealing with lots of players.");
|
||||
}
|
||||
} catch (InstantiationException | InvocationTargetException | NoSuchMethodException | IllegalAccessException e) {
|
||||
plugin.getLogger().severe("Unable to load StorageManager (" + clazz.getName() + ")! Plugin will disable.");
|
||||
e.printStackTrace();
|
||||
|
||||
Reference in New Issue
Block a user