Files
src
build.gradle
README.md
settings.gradle
Code
23 2,036
src/main/java/com/blocksy/events/BlocksyEventsPlugin.java
package com.blocksy.events;
import com.blocksy.events.commands.EventsCommand;
import com.blocksy.events.events.EventManager;
import com.blocksy.events.integrations.PlaceholderIntegration;
import com.blocksy.events.integrations.WorldGuardIntegration;
import com.blocksy.events.listeners.EventListener;
import com.blocksy.events.rewards.RewardService;
import com.blocksy.events.storage.BlockRestorationService;
import com.blocksy.events.storage.StatisticsService;
import com.blocksy.events.util.Messages;
import org.bukkit.Bukkit;
import org.bukkit.plugin.java.JavaPlugin;
import com.blocksy.events.integrations.EconomyIntegration;
public final class BlocksyEventsPlugin extends JavaPlugin {
private Messages messages;
private StatisticsService statistics;
private BlockRestorationService restorations;
private RewardService rewards;
private EventManager events;
private WorldGuardIntegration worldGuard;
private EconomyIntegration economy;
private Object placeholderExpansion;
@Override
public void onEnable() {
saveDefaultConfig();
saveResourceIfMissing("events.yml");
saveResourceIfMissing("messages.yml");
saveResourceIfMissing("rewards.yml");
messages = new Messages(this);
statistics = new StatisticsService(this);
restorations = new BlockRestorationService(this);
restorations.restoreLoadedChunks();
worldGuard = new WorldGuardIntegration(this);
rewards = new RewardService(this);
setupEconomy();
events = new EventManager(this);
EventListener listener = new EventListener(this);
Bukkit.getPluginManager().registerEvents(listener, this);
listener.cleanupOrphanEntities();
EventsCommand command = new EventsCommand(this);
getCommand("events").setExecutor(command);
getCommand("events").setTabCompleter(command);
if (Bukkit.getPluginManager().isPluginEnabled("PlaceholderAPI")) {
PlaceholderIntegration expansion = new PlaceholderIntegration(this);
expansion.register();
placeholderExpansion = expansion;
}
statistics.startSaving();
events.scheduleNextAutomaticEvent();
messages.logStartup();
}
@Override
public void onDisable() {
unregisterPlaceholderExpansion();
if (events != null) events.stopAll(false);
if (restorations != null) restorations.restoreAllLoaded();
if (statistics != null) statistics.save();
}
private void saveResourceIfMissing(String name) {
if (!getDataFolder().toPath().resolve(name).toFile().exists()) saveResource(name, false);
}
private void setupEconomy() {
economy = new EconomyIntegration(this);
economy.hook();
}
private void unregisterPlaceholderExpansion() {
if (placeholderExpansion == null) return;
try { placeholderExpansion.getClass().getMethod("unregister").invoke(placeholderExpansion); }
catch (ReflectiveOperationException exception) { getLogger().warning("Could not unregister PlaceholderAPI expansion: " + exception.getMessage()); }
}
public void reloadPluginFiles() {
reloadConfig();
messages.reload();
statistics.reload();
rewards.reload();
worldGuard.reload();
events.reloadConfiguration();
}
public Messages messages() { return messages; }
public StatisticsService statistics() { return statistics; }
public BlockRestorationService restorations() { return restorations; }
public RewardService rewards() { return rewards; }
public EventManager events() { return events; }
public WorldGuardIntegration worldGuard() { return worldGuard; }
public EconomyIntegration economy() { return economy; }
}