Files
src
ASTROS_SKYBLOCK_RAID_GUIDE.txt
build.gradle
manifest.kod
settings.gradle
Code
33 1,626
src/main/java/com/kodari/skysiege/SkySiegePlugin.java
package com.kodari.skysiege;
import com.kodari.skysiege.command.SkySiegeCommand;
import com.kodari.skysiege.config.ConfigManager;
import com.kodari.skysiege.data.IslandRecord;
import com.kodari.skysiege.gui.GUIListener;
import com.kodari.skysiege.gui.GUIManager;
import com.kodari.skysiege.integration.IridiumSkyblockHook;
import com.kodari.skysiege.listener.CoreListener;
import com.kodari.skysiege.listener.WeaponListener;
import com.kodari.skysiege.raid.RaidManager;
import com.kodari.skysiege.storage.StorageService;
import com.kodari.skysiege.util.MessageUtil;
import com.kodari.skysiege.util.PlaceholderHook;
import org.bukkit.Bukkit;
import org.bukkit.command.PluginCommand;
import org.bukkit.scheduler.BukkitRunnable;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.Location;
import com.cryptomorin.xseries.XMaterial;
import java.util.UUID;
public final class SkySiegePlugin extends JavaPlugin {
private ConfigManager configManager;
private StorageService storageService;
private RaidManager raidManager;
private GUIManager guiManager;
private IridiumSkyblockHook iridiumSkyblockHook;
@Override
public void onEnable() {
saveDefaultConfig();
configManager = new ConfigManager(this);
iridiumSkyblockHook = new IridiumSkyblockHook();
if (iridiumSkyblockHook.isAvailable()) {
getLogger().info("IridiumSkyblock integration enabled.");
if (iridiumSkyblockHook.registerIslandCreationListener(this, this::queueAutomaticCore)) {
getLogger().info("Automatic island core registration enabled.");
} else {
getLogger().warning("Could not register the IridiumSkyblock island creation listener.");
}
}
storageService = new StorageService(this, configManager);
storageService.initialize();
raidManager = new RaidManager(this, configManager, storageService, iridiumSkyblockHook);
guiManager = new GUIManager();
Bukkit.getPluginManager().registerEvents(new GUIListener(guiManager), this);
Bukkit.getPluginManager().registerEvents(new CoreListener(this), this);
Bukkit.getPluginManager().registerEvents(new WeaponListener(this), this);
SkySiegeCommand command = new SkySiegeCommand(this);
PluginCommand pluginCommand = getCommand("astrosskyblockraid");
if (pluginCommand == null) {
getLogger().severe("The astrosskyblockraid command is missing from plugin.yml.");
getServer().getPluginManager().disablePlugin(this);
return;
}
pluginCommand.setExecutor(command);
pluginCommand.setTabCompleter(command);
if (Bukkit.getPluginManager().isPluginEnabled("PlaceholderAPI")) {
new PlaceholderHook(this).register();
}
}
@Override
public void onDisable() {
if (raidManager != null) raidManager.shutdown();
if (storageService != null) storageService.close();
}
public ConfigManager configManager() { return configManager; }
public StorageService storage() { return storageService; }
public RaidManager raids() { return raidManager; }
public GUIManager guis() { return guiManager; }
public IridiumSkyblockHook iridiumSkyblock() { return iridiumSkyblockHook; }
public String message(String key) { return MessageUtil.format(configManager.message(key), configManager.prefix()); }
private void queueAutomaticCore(UUID ownerId) {
new BukkitRunnable() {
private int attempts;
@Override
public void run() {
if (++attempts > 60) {
cancel();
getLogger().warning("Could not place an automatic core for IridiumSkyblock island owner " + ownerId + ".");
return;
}
IslandRecord record = storageService.getOrCreate(ownerId);
if (record.hasCore()) {
cancel();
return;
}
Location location = iridiumSkyblockHook.homeOf(ownerId);
if (location == null || location.getWorld() == null) return;
location = location.getBlock().getLocation();
record.setCoreWorld(location.getWorld().getName());
record.setCoreX(location.getBlockX());
record.setCoreY(location.getBlockY());
record.setCoreZ(location.getBlockZ());
Long islandValue = iridiumSkyblockHook.islandValueAt(location);
if (islandValue != null) record.setIslandValue(islandValue);
storageService.save(record);
XMaterial.matchXMaterial(configManager.coreMaterial()).map(XMaterial::parseMaterial)
.ifPresent(location.getBlock()::setType);
getLogger().info("Placed an automatic island core for " + ownerId + ".");
cancel();
}
}.runTaskTimer(this, 40L, 20L);
}
}