Files
src
build.gradle
settings.gradle
Code
19 1,693
src/main/java/dev/xd/restrict/xDRestrict.java
package dev.xd.restrict;
import dev.xd.restrict.api.RestrictionAPI;
import dev.xd.restrict.commands.RestrictCommand;
import dev.xd.restrict.config.ConfigManager;
import dev.xd.restrict.cooldown.CooldownManager;
import dev.xd.restrict.listeners.CooldownListener;
import dev.xd.restrict.listeners.MaceRestrictionListener;
import dev.xd.restrict.listeners.PlayerCleanupListener;
import dev.xd.restrict.listeners.WindChargeRestrictionListener;
import dev.xd.restrict.managers.RestrictionManager;
import dev.xd.restrict.placeholder.XDPlaceholderExpansion;
import dev.xd.restrict.region.RegionManager;
import dev.xd.restrict.utils.NotificationManager;
import org.bukkit.Bukkit;
import org.bukkit.command.PluginCommand;
import org.bukkit.plugin.java.JavaPlugin;
/**
* Main xDRestrict plugin class.
*/
public final class xDRestrict extends JavaPlugin implements RestrictionAPI {
private ConfigManager configManager;
private RegionManager regionManager;
private CooldownManager cooldownManager;
private RestrictionManager restrictionManager;
private NotificationManager notificationManager;
/**
* Enables the plugin and registers all services and listeners.
*/
@Override
public void onEnable() {
configManager = new ConfigManager(this);
configManager.load();
regionManager = new RegionManager(this, configManager);
cooldownManager = new CooldownManager();
restrictionManager = new RestrictionManager(
configManager,
regionManager,
cooldownManager
);
notificationManager = new NotificationManager(configManager);
Bukkit.getPluginManager().registerEvents(
new MaceRestrictionListener(restrictionManager, notificationManager),
this
);
Bukkit.getPluginManager().registerEvents(
new WindChargeRestrictionListener(restrictionManager, notificationManager),
this
);
Bukkit.getPluginManager().registerEvents(
new CooldownListener(restrictionManager, notificationManager),
this
);
Bukkit.getPluginManager().registerEvents(
new PlayerCleanupListener(regionManager, cooldownManager),
this
);
PluginCommand command = getCommand("xdrestrict");
if (command != null) {
RestrictCommand restrictCommand = new RestrictCommand(this);
command.setExecutor(restrictCommand);
command.setTabCompleter(restrictCommand);
}
if (Bukkit.getPluginManager().getPlugin("PlaceholderAPI") != null) {
new XDPlaceholderExpansion(this).register();
getLogger().info("PlaceholderAPI expansion registered.");
}
getLogger().info("xDRestrict enabled for Paper/Folia.");
}
/**
* Disables the plugin and releases per-player state.
*/
@Override
public void onDisable() {
if (cooldownManager != null) {
cooldownManager.clear();
}
if (regionManager != null) {
regionManager.clearCache();
}
}
/**
* Gets the configuration manager.
*
* @return configuration manager
*/
public ConfigManager getConfigManager() {
return configManager;
}
/**
* Gets the region manager.
*
* @return region manager
*/
public RegionManager getRegionManager() {
return regionManager;
}
/**
* Gets the cooldown manager.
*
* @return cooldown manager
*/
public CooldownManager getCooldownManager() {
return cooldownManager;
}
/**
* Gets the restriction manager.
*
* @return restriction manager
*/
public RestrictionManager getRestrictionManager() {
return restrictionManager;
}
/**
* Gets the public API.
*
* @return this plugin API
*/
public RestrictionAPI getApi() {
return this;
}
/**
* Checks whether a player may use a Mace.
*
* @param player player to check
* @return true when allowed
*/
@Override
public boolean canUseMace(org.bukkit.entity.Player player) {
return restrictionManager.canUseMace(player);
}
/**
* Checks whether a player may use a Wind Charge.
*
* @param player player to check
* @return true when allowed
*/
@Override
public boolean canUseWindCharge(org.bukkit.entity.Player player) {
return restrictionManager.canUseWindCharge(player);
}
/**
* Checks whether an Ender Pearl cooldown is active.
*
* @param player player to check
* @return true when active
*/
@Override
public boolean isPearlOnCooldown(org.bukkit.entity.Player player) {
return restrictionManager.isPearlOnCooldown(player);
}
/**
* Gets the remaining Ender Pearl cooldown.
*
* @param player player to check
* @return remaining seconds
*/
@Override
public int getPearlCooldown(org.bukkit.entity.Player player) {
return restrictionManager.getPearlCooldown(player);
}
/**
* Checks whether an Enchanted Golden Apple cooldown is active.
*
* @param player player to check
* @return true when active
*/
@Override
public boolean isGappleOnCooldown(org.bukkit.entity.Player player) {
return restrictionManager.isGappleOnCooldown(player);
}
/**
* Gets the remaining Enchanted Golden Apple cooldown.
*
* @param player player to check
* @return remaining seconds
*/
public int getGappleCooldown(org.bukkit.entity.Player player) {
return restrictionManager.getGappleCooldown(player);
}