Files
src
BUILD_STATUS.md
build.gradle
manifest.kod
README.md
settings.gradle
Code
15 1,888
src/main/java/com/pmc/netherfall/PMCNetherfall.java
package com.pmc.netherfall;
import com.cryptomorin.xseries.XMaterial;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.block.Block;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.world.PortalCreateEvent;
import org.bukkit.event.player.PlayerPortalEvent;
import org.bukkit.plugin.java.JavaPlugin;
import java.sql.SQLException;
public final class PMCNetherfall extends JavaPlugin implements Listener {
private NetherfallStorage storage;
private NetherfallManager manager;
@Override
public void onEnable() {
saveDefaultConfig();
if (!getConfig().getBoolean("general.enabled", true)) {
getLogger().info("PMCNetherfall is disabled in config.yml.");
return;
}
try {
storage = new NetherfallStorage(this);
manager = new NetherfallManager(this, storage);
} catch (Exception exception) {
getLogger().severe("Could not initialize SQLite. Netherfall has been disabled safely: " + exception.getMessage());
getServer().getPluginManager().disablePlugin(this);
return;
}
getServer().getPluginManager().registerEvents(this, this);
getServer().getPluginManager().registerEvents(new NetherfallListener(manager), this);
getCommand("netherfall").setExecutor(new NetherfallCommand(this, manager));
getCommand("netherfall").setTabCompleter(new NetherfallCommand(this, manager));
manager.start();
getLogger().info("PMCNetherfall enabled at phase " + manager.getPhase() + ".");
}
@Override
public void onDisable() {
if (manager != null) manager.shutdown();
if (storage != null) {
try {
storage.close();
} catch (SQLException exception) {
getLogger().warning("Could not close the Netherfall database cleanly: " + exception.getMessage());
}
}
}
public NetherfallManager getManager() {
return manager;
}
@EventHandler
public void onPortalCreate(PortalCreateEvent event) {
if (manager == null || !getConfig().getBoolean("worlds.auto-discover-portals", true)) return;
Block portalBlock = event.getBlocks().stream()
.map(state -> state.getBlock())
.filter(block -> XMaterial.matchXMaterial(block.getType()).name().equals("NETHER_PORTAL"))
.findFirst().orElse(null);
if (portalBlock == null) return;
Location location = portalBlock.getLocation();
Bukkit.getScheduler().runTask(this, () -> manager.discoverPortal(location));
}
@EventHandler
public void onPlayerPortal(PlayerPortalEvent event) {
if (manager == null || !getConfig().getBoolean("worlds.auto-discover-portals", true)) return;
Location from = event.getFrom();
if (from.getWorld() != null && from.getWorld().getEnvironment() == org.bukkit.World.Environment.NORMAL) {
manager.discoverPortal(from);
}
}
}