2016-04-14 16:24:03 +00:00
|
|
|
package me.mrCookieSlime.Slimefun;
|
|
|
|
|
2017-06-22 14:43:49 +00:00
|
|
|
import java.io.File;
|
2020-03-22 15:44:28 +00:00
|
|
|
import java.util.ArrayList;
|
2020-02-01 00:32:38 +00:00
|
|
|
import java.util.Arrays;
|
2020-03-22 15:44:28 +00:00
|
|
|
import java.util.Collection;
|
|
|
|
import java.util.List;
|
2020-02-01 00:32:38 +00:00
|
|
|
import java.util.Set;
|
2019-08-31 10:54:54 +00:00
|
|
|
import java.util.logging.Level;
|
2020-02-01 00:32:38 +00:00
|
|
|
import java.util.stream.Collectors;
|
2017-06-22 14:43:49 +00:00
|
|
|
|
|
|
|
import org.bukkit.Bukkit;
|
2020-04-10 18:30:24 +00:00
|
|
|
import org.bukkit.Server;
|
2017-06-22 14:43:49 +00:00
|
|
|
import org.bukkit.World;
|
2020-04-03 10:10:42 +00:00
|
|
|
import org.bukkit.command.Command;
|
2017-06-22 14:43:49 +00:00
|
|
|
import org.bukkit.entity.Player;
|
2020-02-01 00:32:38 +00:00
|
|
|
import org.bukkit.plugin.Plugin;
|
2020-05-04 14:25:47 +00:00
|
|
|
import org.bukkit.plugin.PluginDescriptionFile;
|
2017-06-22 14:43:49 +00:00
|
|
|
import org.bukkit.plugin.java.JavaPlugin;
|
2020-05-04 14:25:47 +00:00
|
|
|
import org.bukkit.plugin.java.JavaPluginLoader;
|
2017-06-22 14:43:49 +00:00
|
|
|
|
2019-12-27 01:16:01 +00:00
|
|
|
import io.github.thebusybiscuit.cscorelib2.config.Config;
|
2020-03-26 17:56:14 +00:00
|
|
|
import io.github.thebusybiscuit.cscorelib2.math.DoubleHandler;
|
2019-09-01 16:53:02 +00:00
|
|
|
import io.github.thebusybiscuit.cscorelib2.protection.ProtectionManager;
|
2019-10-01 11:14:50 +00:00
|
|
|
import io.github.thebusybiscuit.cscorelib2.reflection.ReflectionUtils;
|
2020-03-22 15:44:28 +00:00
|
|
|
import io.github.thebusybiscuit.slimefun4.api.MinecraftVersion;
|
2020-02-16 11:17:14 +00:00
|
|
|
import io.github.thebusybiscuit.slimefun4.api.SlimefunAddon;
|
2020-02-08 01:36:57 +00:00
|
|
|
import io.github.thebusybiscuit.slimefun4.api.gps.GPSNetwork;
|
2020-03-19 12:14:29 +00:00
|
|
|
import io.github.thebusybiscuit.slimefun4.api.player.PlayerProfile;
|
2020-02-01 00:32:38 +00:00
|
|
|
import io.github.thebusybiscuit.slimefun4.core.SlimefunRegistry;
|
2019-12-22 13:00:35 +00:00
|
|
|
import io.github.thebusybiscuit.slimefun4.core.commands.SlimefunCommand;
|
2020-05-07 16:00:44 +00:00
|
|
|
import io.github.thebusybiscuit.slimefun4.core.networks.NetworkManager;
|
2019-12-22 22:00:05 +00:00
|
|
|
import io.github.thebusybiscuit.slimefun4.core.services.AutoSavingService;
|
2020-02-08 19:50:21 +00:00
|
|
|
import io.github.thebusybiscuit.slimefun4.core.services.BackupService;
|
2019-12-08 11:58:05 +00:00
|
|
|
import io.github.thebusybiscuit.slimefun4.core.services.BlockDataService;
|
|
|
|
import io.github.thebusybiscuit.slimefun4.core.services.CustomItemDataService;
|
|
|
|
import io.github.thebusybiscuit.slimefun4.core.services.CustomTextureService;
|
2020-03-04 23:52:14 +00:00
|
|
|
import io.github.thebusybiscuit.slimefun4.core.services.LocalizationService;
|
2020-03-18 13:20:49 +00:00
|
|
|
import io.github.thebusybiscuit.slimefun4.core.services.MinecraftRecipeService;
|
2020-04-09 00:21:30 +00:00
|
|
|
import io.github.thebusybiscuit.slimefun4.core.services.PerWorldSettingsService;
|
2020-03-10 20:44:24 +00:00
|
|
|
import io.github.thebusybiscuit.slimefun4.core.services.PermissionsService;
|
2019-12-22 22:00:05 +00:00
|
|
|
import io.github.thebusybiscuit.slimefun4.core.services.UpdaterService;
|
2020-03-04 23:04:18 +00:00
|
|
|
import io.github.thebusybiscuit.slimefun4.core.services.github.GitHubService;
|
|
|
|
import io.github.thebusybiscuit.slimefun4.core.services.metrics.MetricsService;
|
2020-03-12 02:32:04 +00:00
|
|
|
import io.github.thebusybiscuit.slimefun4.core.services.plugins.ThirdPartyPluginService;
|
2020-06-15 23:16:14 +00:00
|
|
|
import io.github.thebusybiscuit.slimefun4.implementation.SlimefunItems;
|
2020-04-10 18:30:24 +00:00
|
|
|
import io.github.thebusybiscuit.slimefun4.implementation.items.altar.AncientAltar;
|
2020-06-02 11:58:03 +00:00
|
|
|
import io.github.thebusybiscuit.slimefun4.implementation.items.backpacks.Cooler;
|
2020-06-21 08:26:54 +00:00
|
|
|
import io.github.thebusybiscuit.slimefun4.implementation.items.electric.BasicCircuitBoard;
|
2020-06-20 17:21:44 +00:00
|
|
|
import io.github.thebusybiscuit.slimefun4.implementation.items.electric.reactors.Reactor;
|
2020-04-10 18:30:24 +00:00
|
|
|
import io.github.thebusybiscuit.slimefun4.implementation.items.tools.GrapplingHook;
|
|
|
|
import io.github.thebusybiscuit.slimefun4.implementation.items.weapons.SeismicAxe;
|
|
|
|
import io.github.thebusybiscuit.slimefun4.implementation.items.weapons.VampireBlade;
|
2020-01-12 10:05:35 +00:00
|
|
|
import io.github.thebusybiscuit.slimefun4.implementation.listeners.AncientAltarListener;
|
2019-12-29 13:14:51 +00:00
|
|
|
import io.github.thebusybiscuit.slimefun4.implementation.listeners.BackpackListener;
|
|
|
|
import io.github.thebusybiscuit.slimefun4.implementation.listeners.BlockListener;
|
2020-01-12 10:01:29 +00:00
|
|
|
import io.github.thebusybiscuit.slimefun4.implementation.listeners.BlockPhysicsListener;
|
2020-05-08 16:59:51 +00:00
|
|
|
import io.github.thebusybiscuit.slimefun4.implementation.listeners.CargoNodeListener;
|
2020-04-10 18:30:24 +00:00
|
|
|
import io.github.thebusybiscuit.slimefun4.implementation.listeners.CoolerListener;
|
2020-01-11 22:58:05 +00:00
|
|
|
import io.github.thebusybiscuit.slimefun4.implementation.listeners.DeathpointListener;
|
2020-01-12 01:05:33 +00:00
|
|
|
import io.github.thebusybiscuit.slimefun4.implementation.listeners.DebugFishListener;
|
2020-02-22 23:59:55 +00:00
|
|
|
import io.github.thebusybiscuit.slimefun4.implementation.listeners.DispenserListener;
|
2019-12-29 13:14:51 +00:00
|
|
|
import io.github.thebusybiscuit.slimefun4.implementation.listeners.EnhancedFurnaceListener;
|
2020-01-11 22:58:05 +00:00
|
|
|
import io.github.thebusybiscuit.slimefun4.implementation.listeners.ExplosionsListener;
|
2020-03-16 18:06:51 +00:00
|
|
|
import io.github.thebusybiscuit.slimefun4.implementation.listeners.FireworksListener;
|
|
|
|
import io.github.thebusybiscuit.slimefun4.implementation.listeners.GadgetsListener;
|
2019-12-29 17:30:48 +00:00
|
|
|
import io.github.thebusybiscuit.slimefun4.implementation.listeners.GrapplingHookListener;
|
2020-03-16 18:06:51 +00:00
|
|
|
import io.github.thebusybiscuit.slimefun4.implementation.listeners.IronGolemListener;
|
2019-12-29 13:14:51 +00:00
|
|
|
import io.github.thebusybiscuit.slimefun4.implementation.listeners.ItemPickupListener;
|
2020-05-04 14:25:47 +00:00
|
|
|
import io.github.thebusybiscuit.slimefun4.implementation.listeners.MobDropListener;
|
2019-12-29 13:14:51 +00:00
|
|
|
import io.github.thebusybiscuit.slimefun4.implementation.listeners.MultiBlockListener;
|
|
|
|
import io.github.thebusybiscuit.slimefun4.implementation.listeners.PlayerProfileListener;
|
2020-04-10 18:30:24 +00:00
|
|
|
import io.github.thebusybiscuit.slimefun4.implementation.listeners.SeismicAxeListener;
|
2020-01-05 13:30:50 +00:00
|
|
|
import io.github.thebusybiscuit.slimefun4.implementation.listeners.SlimefunBootsListener;
|
|
|
|
import io.github.thebusybiscuit.slimefun4.implementation.listeners.SlimefunBowListener;
|
2019-12-29 13:14:51 +00:00
|
|
|
import io.github.thebusybiscuit.slimefun4.implementation.listeners.SlimefunGuideListener;
|
2020-03-12 02:32:04 +00:00
|
|
|
import io.github.thebusybiscuit.slimefun4.implementation.listeners.SlimefunItemConsumeListener;
|
2020-01-25 13:20:58 +00:00
|
|
|
import io.github.thebusybiscuit.slimefun4.implementation.listeners.SlimefunItemListener;
|
2019-12-29 13:14:51 +00:00
|
|
|
import io.github.thebusybiscuit.slimefun4.implementation.listeners.SoulboundListener;
|
|
|
|
import io.github.thebusybiscuit.slimefun4.implementation.listeners.TalismanListener;
|
2020-04-10 18:30:24 +00:00
|
|
|
import io.github.thebusybiscuit.slimefun4.implementation.listeners.VampireBladeListener;
|
2020-01-12 10:01:29 +00:00
|
|
|
import io.github.thebusybiscuit.slimefun4.implementation.listeners.VanillaMachinesListener;
|
2020-03-16 18:06:51 +00:00
|
|
|
import io.github.thebusybiscuit.slimefun4.implementation.listeners.WitherListener;
|
2019-12-29 13:14:51 +00:00
|
|
|
import io.github.thebusybiscuit.slimefun4.implementation.listeners.WorldListener;
|
2020-03-05 20:28:50 +00:00
|
|
|
import io.github.thebusybiscuit.slimefun4.implementation.resources.GEOResourcesSetup;
|
2020-03-15 14:12:44 +00:00
|
|
|
import io.github.thebusybiscuit.slimefun4.implementation.setup.PostSetup;
|
2020-02-02 17:27:32 +00:00
|
|
|
import io.github.thebusybiscuit.slimefun4.implementation.setup.ResearchSetup;
|
2020-02-08 01:36:57 +00:00
|
|
|
import io.github.thebusybiscuit.slimefun4.implementation.setup.SlimefunItemSetup;
|
2020-02-04 18:05:49 +00:00
|
|
|
import io.github.thebusybiscuit.slimefun4.implementation.tasks.ArmorTask;
|
2020-03-26 17:56:14 +00:00
|
|
|
import io.github.thebusybiscuit.slimefun4.implementation.tasks.SlimefunStartupTask;
|
2020-02-04 18:05:49 +00:00
|
|
|
import io.github.thebusybiscuit.slimefun4.implementation.tasks.TickerTask;
|
2016-04-14 16:24:03 +00:00
|
|
|
import me.mrCookieSlime.CSCoreLibPlugin.CSCoreLib;
|
|
|
|
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.abstractItems.AContainer;
|
2019-10-05 21:49:25 +00:00
|
|
|
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.abstractItems.AGenerator;
|
2016-04-14 16:24:03 +00:00
|
|
|
import me.mrCookieSlime.Slimefun.api.BlockStorage;
|
|
|
|
import me.mrCookieSlime.Slimefun.api.Slimefun;
|
2019-08-22 19:37:09 +00:00
|
|
|
import me.mrCookieSlime.Slimefun.api.inventory.UniversalBlockMenu;
|
2016-04-14 16:24:03 +00:00
|
|
|
|
2020-03-04 23:04:18 +00:00
|
|
|
/**
|
|
|
|
* This is the main class of Slimefun.
|
|
|
|
* This is where all the magic starts, take a look around.
|
|
|
|
* Feel like home.
|
|
|
|
*
|
|
|
|
* @author TheBusyBiscuit
|
|
|
|
*
|
|
|
|
*/
|
2020-05-09 16:00:10 +00:00
|
|
|
public final class SlimefunPlugin extends JavaPlugin implements SlimefunAddon {
|
2016-11-19 23:23:37 +00:00
|
|
|
|
2020-03-04 23:04:18 +00:00
|
|
|
public static SlimefunPlugin instance;
|
2020-05-04 14:25:47 +00:00
|
|
|
|
2020-03-24 01:00:21 +00:00
|
|
|
private MinecraftVersion minecraftVersion = MinecraftVersion.UNKNOWN;
|
2020-03-04 23:04:18 +00:00
|
|
|
|
2020-03-15 16:43:51 +00:00
|
|
|
private final SlimefunRegistry registry = new SlimefunRegistry();
|
2020-03-24 01:00:21 +00:00
|
|
|
private final TickerTask ticker = new TickerTask();
|
|
|
|
private final SlimefunCommand command = new SlimefunCommand(this);
|
2020-03-14 00:12:52 +00:00
|
|
|
|
2020-03-10 20:44:24 +00:00
|
|
|
// Services - Systems that fulfill certain tasks, treat them as a black box
|
2020-03-04 23:04:18 +00:00
|
|
|
private final CustomItemDataService itemDataService = new CustomItemDataService(this, "slimefun_item");
|
|
|
|
private final BlockDataService blockDataService = new BlockDataService(this, "slimefun_block");
|
2020-05-11 16:56:01 +00:00
|
|
|
private final CustomTextureService textureService = new CustomTextureService(new Config(this, "item-models.yml"));
|
2020-03-04 23:04:18 +00:00
|
|
|
private final GitHubService gitHubService = new GitHubService("TheBusyBiscuit/Slimefun4");
|
2020-05-08 13:44:12 +00:00
|
|
|
private final UpdaterService updaterService = new UpdaterService(this, getDescription().getVersion(), getFile());
|
2020-03-18 13:20:49 +00:00
|
|
|
private final MetricsService metricsService = new MetricsService(this);
|
2020-03-04 23:04:18 +00:00
|
|
|
private final AutoSavingService autoSavingService = new AutoSavingService();
|
|
|
|
private final BackupService backupService = new BackupService();
|
2020-03-10 20:44:24 +00:00
|
|
|
private final PermissionsService permissionsService = new PermissionsService(this);
|
2020-04-09 00:21:30 +00:00
|
|
|
private final PerWorldSettingsService worldSettingsService = new PerWorldSettingsService(this);
|
2020-03-12 02:32:04 +00:00
|
|
|
private final ThirdPartyPluginService thirdPartySupportService = new ThirdPartyPluginService(this);
|
2020-03-18 13:20:49 +00:00
|
|
|
private final MinecraftRecipeService recipeService = new MinecraftRecipeService(this);
|
2020-03-04 23:04:18 +00:00
|
|
|
private LocalizationService local;
|
2020-03-12 02:32:04 +00:00
|
|
|
|
2020-03-15 16:43:51 +00:00
|
|
|
private GPSNetwork gpsNetwork;
|
2020-03-04 23:04:18 +00:00
|
|
|
private NetworkManager networkManager;
|
2020-03-12 02:32:04 +00:00
|
|
|
private ProtectionManager protections;
|
|
|
|
|
2020-03-24 01:00:21 +00:00
|
|
|
// Important config files for Slimefun
|
2020-04-09 00:21:30 +00:00
|
|
|
private final Config config = new Config(this);
|
|
|
|
private final Config items = new Config(this, "Items.yml");
|
|
|
|
private final Config researches = new Config(this, "Researches.yml");
|
2020-03-04 23:04:18 +00:00
|
|
|
|
|
|
|
// Listeners that need to be accessed elsewhere
|
2020-03-27 12:19:47 +00:00
|
|
|
private final AncientAltarListener ancientAltarListener = new AncientAltarListener();
|
|
|
|
private final GrapplingHookListener grapplingHookListener = new GrapplingHookListener();
|
2020-03-30 11:58:36 +00:00
|
|
|
private final BackpackListener backpackListener = new BackpackListener();
|
|
|
|
private final SlimefunBowListener bowListener = new SlimefunBowListener();
|
2020-03-04 23:04:18 +00:00
|
|
|
|
2020-05-04 14:25:47 +00:00
|
|
|
public SlimefunPlugin() {
|
|
|
|
super();
|
|
|
|
}
|
|
|
|
|
|
|
|
public SlimefunPlugin(JavaPluginLoader loader, PluginDescriptionFile description, File dataFolder, File file) {
|
|
|
|
super(loader, description, dataFolder, file);
|
2020-05-20 15:20:52 +00:00
|
|
|
minecraftVersion = MinecraftVersion.UNIT_TEST;
|
2020-05-04 14:25:47 +00:00
|
|
|
}
|
|
|
|
|
2020-03-04 23:04:18 +00:00
|
|
|
@Override
|
|
|
|
public void onEnable() {
|
2020-05-20 15:20:52 +00:00
|
|
|
if (minecraftVersion == MinecraftVersion.UNIT_TEST) {
|
2020-05-04 14:25:47 +00:00
|
|
|
instance = this;
|
|
|
|
local = new LocalizationService(this, "", null);
|
2020-05-24 17:12:45 +00:00
|
|
|
gpsNetwork = new GPSNetwork();
|
2020-06-10 15:11:28 +00:00
|
|
|
command.register();
|
2020-05-04 14:25:47 +00:00
|
|
|
}
|
|
|
|
else if (getServer().getPluginManager().isPluginEnabled("CS-CoreLib")) {
|
2020-03-26 17:56:14 +00:00
|
|
|
long timestamp = System.nanoTime();
|
2020-03-04 23:04:18 +00:00
|
|
|
|
2020-03-14 00:12:52 +00:00
|
|
|
// We wanna ensure that the Server uses a compatible version of Minecraft
|
2020-03-04 23:04:18 +00:00
|
|
|
if (isVersionUnsupported()) {
|
|
|
|
getServer().getPluginManager().disablePlugin(this);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
instance = this;
|
|
|
|
|
|
|
|
// Creating all necessary Folders
|
2020-04-09 00:21:30 +00:00
|
|
|
getLogger().log(Level.INFO, "Loading various systems...");
|
2020-03-04 23:04:18 +00:00
|
|
|
createDirectories();
|
2020-03-15 16:43:51 +00:00
|
|
|
registry.load(config);
|
2020-03-04 23:04:18 +00:00
|
|
|
|
2020-04-09 00:21:30 +00:00
|
|
|
// Set up localization
|
2020-04-10 18:30:24 +00:00
|
|
|
local = new LocalizationService(this, config.getString("options.chat-prefix"), config.getString("options.language"));
|
2020-03-04 23:04:18 +00:00
|
|
|
|
2020-03-24 01:00:21 +00:00
|
|
|
// Setting up Networks
|
2020-03-15 16:43:51 +00:00
|
|
|
gpsNetwork = new GPSNetwork();
|
2020-05-11 21:20:40 +00:00
|
|
|
|
|
|
|
int networkSize = config.getInt("networks.max-size");
|
|
|
|
|
|
|
|
if (networkSize < 1) {
|
|
|
|
getLogger().log(Level.WARNING, "Your 'networks.max-size' setting is misconfigured! It must be at least 1, it was set to: {0}", networkSize);
|
|
|
|
networkSize = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
networkManager = new NetworkManager(networkSize);
|
2020-03-04 23:04:18 +00:00
|
|
|
|
|
|
|
// Setting up bStats
|
|
|
|
metricsService.start();
|
|
|
|
|
|
|
|
// Starting the Auto-Updater
|
|
|
|
if (config.getBoolean("options.auto-update")) {
|
|
|
|
getLogger().log(Level.INFO, "Starting Auto-Updater...");
|
|
|
|
updaterService.start();
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
updaterService.disable();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Registering all GEO Resources
|
|
|
|
getLogger().log(Level.INFO, "Loading GEO-Resources...");
|
2020-03-04 23:52:14 +00:00
|
|
|
GEOResourcesSetup.setup();
|
2020-03-04 23:04:18 +00:00
|
|
|
|
2020-03-27 11:16:42 +00:00
|
|
|
getLogger().log(Level.INFO, "Loading items...");
|
|
|
|
loadItems();
|
2020-03-04 23:04:18 +00:00
|
|
|
|
2020-03-27 11:16:42 +00:00
|
|
|
getLogger().log(Level.INFO, "Loading researches...");
|
|
|
|
loadResearches();
|
2020-03-10 14:20:59 +00:00
|
|
|
|
2020-03-15 16:43:51 +00:00
|
|
|
registry.setResearchingEnabled(getResearchCfg().getBoolean("enable-researching"));
|
2020-03-15 14:12:44 +00:00
|
|
|
PostSetup.setupWiki();
|
2020-03-04 23:04:18 +00:00
|
|
|
|
|
|
|
// All Slimefun Listeners
|
|
|
|
new SlimefunBootsListener(this);
|
|
|
|
new SlimefunItemListener(this);
|
2020-03-12 02:32:04 +00:00
|
|
|
new SlimefunItemConsumeListener(this);
|
2020-03-04 23:04:18 +00:00
|
|
|
new BlockPhysicsListener(this);
|
2020-05-08 16:59:51 +00:00
|
|
|
new CargoNodeListener(this);
|
2020-03-04 23:04:18 +00:00
|
|
|
new MultiBlockListener(this);
|
2020-03-16 18:06:51 +00:00
|
|
|
new GadgetsListener(this);
|
2020-03-04 23:04:18 +00:00
|
|
|
new DispenserListener(this);
|
|
|
|
new BlockListener(this);
|
|
|
|
new EnhancedFurnaceListener(this);
|
|
|
|
new ItemPickupListener(this);
|
|
|
|
new DeathpointListener(this);
|
|
|
|
new ExplosionsListener(this);
|
|
|
|
new DebugFishListener(this);
|
|
|
|
new VanillaMachinesListener(this);
|
2020-03-16 18:06:51 +00:00
|
|
|
new FireworksListener(this);
|
|
|
|
new WitherListener(this);
|
|
|
|
new IronGolemListener(this);
|
2020-03-04 23:04:18 +00:00
|
|
|
|
2020-06-21 08:26:54 +00:00
|
|
|
new MobDropListener(this, (BasicCircuitBoard) SlimefunItems.BASIC_CIRCUIT_BOARD.getItem());
|
|
|
|
|
2020-04-10 18:30:24 +00:00
|
|
|
// Item-specific Listeners
|
|
|
|
new VampireBladeListener(this, (VampireBlade) SlimefunItems.BLADE_OF_VAMPIRES.getItem());
|
|
|
|
new CoolerListener(this, (Cooler) SlimefunItems.COOLER.getItem());
|
|
|
|
new SeismicAxeListener(this, (SeismicAxe) SlimefunItems.SEISMIC_AXE.getItem());
|
|
|
|
grapplingHookListener.register(this, (GrapplingHook) SlimefunItems.GRAPPLING_HOOK.getItem());
|
|
|
|
ancientAltarListener.register(this, (AncientAltar) SlimefunItems.ANCIENT_ALTAR.getItem());
|
|
|
|
|
2020-04-09 00:21:30 +00:00
|
|
|
bowListener.register(this);
|
2020-03-04 23:04:18 +00:00
|
|
|
|
2020-03-18 13:20:49 +00:00
|
|
|
// Toggleable Listeners for performance reasons
|
2020-03-12 02:32:04 +00:00
|
|
|
if (config.getBoolean("items.talismans")) {
|
|
|
|
new TalismanListener(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (config.getBoolean("items.soulbound")) {
|
|
|
|
new SoulboundListener(this);
|
|
|
|
}
|
2020-03-04 23:04:18 +00:00
|
|
|
|
|
|
|
if (config.getBoolean("items.backpacks")) {
|
2020-04-09 00:21:30 +00:00
|
|
|
backpackListener.register(this);
|
2020-03-04 23:04:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Handle Slimefun Guide being given on Join
|
2020-04-10 18:30:24 +00:00
|
|
|
new SlimefunGuideListener(this, config.getBoolean("guide.receive-on-first-join"));
|
2020-03-04 23:04:18 +00:00
|
|
|
|
|
|
|
// Load/Unload Worlds in Slimefun
|
|
|
|
new WorldListener(this);
|
|
|
|
|
|
|
|
// Clear the Slimefun Guide History upon Player Leaving
|
|
|
|
new PlayerProfileListener(this);
|
|
|
|
|
|
|
|
// Initiating various Stuff and all Items with a slightly delay (0ms after the Server finished loading)
|
2020-03-26 17:56:14 +00:00
|
|
|
Slimefun.runSync(new SlimefunStartupTask(this, () -> {
|
2020-03-04 23:04:18 +00:00
|
|
|
protections = new ProtectionManager(getServer());
|
2020-05-08 13:44:12 +00:00
|
|
|
textureService.register(registry.getAllSlimefunItems(), true);
|
2020-05-08 15:13:16 +00:00
|
|
|
permissionsService.register(registry.getAllSlimefunItems(), true);
|
2020-04-09 00:21:30 +00:00
|
|
|
recipeService.refresh();
|
2020-03-26 17:56:14 +00:00
|
|
|
}), 0);
|
2020-03-04 23:04:18 +00:00
|
|
|
|
2020-03-05 22:38:39 +00:00
|
|
|
// Setting up the command /sf and all subcommands
|
2020-03-24 01:00:21 +00:00
|
|
|
command.register();
|
2020-03-04 23:04:18 +00:00
|
|
|
|
|
|
|
// Armor Update Task
|
|
|
|
if (config.getBoolean("options.enable-armor-effects")) {
|
|
|
|
getServer().getScheduler().runTaskTimerAsynchronously(this, new ArmorTask(), 0L, config.getInt("options.armor-update-interval") * 20L);
|
|
|
|
}
|
|
|
|
|
|
|
|
autoSavingService.start(this, config.getInt("options.auto-save-delay-in-minutes"));
|
2020-03-26 17:56:14 +00:00
|
|
|
ticker.start(this);
|
2020-03-12 02:32:04 +00:00
|
|
|
thirdPartySupportService.start();
|
2020-03-26 17:56:14 +00:00
|
|
|
gitHubService.start(this);
|
2020-03-04 23:04:18 +00:00
|
|
|
|
2020-03-26 17:56:14 +00:00
|
|
|
// Hooray!
|
2020-03-27 11:16:42 +00:00
|
|
|
getLogger().log(Level.INFO, "Slimefun has finished loading in {0}", getStartupTime(timestamp));
|
2020-03-04 23:04:18 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
getLogger().log(Level.INFO, "#################### - INFO - ####################");
|
|
|
|
getLogger().log(Level.INFO, " ");
|
|
|
|
getLogger().log(Level.INFO, "Slimefun could not be loaded (yet).");
|
|
|
|
getLogger().log(Level.INFO, "It appears that you have not installed CS-CoreLib.");
|
|
|
|
getLogger().log(Level.INFO, "Please download and install CS-CoreLib manually:");
|
|
|
|
getLogger().log(Level.INFO, "https://thebusybiscuit.github.io/builds/TheBusyBiscuit/CS-CoreLib/master/");
|
|
|
|
|
|
|
|
getCommand("slimefun").setExecutor((sender, cmd, label, args) -> {
|
|
|
|
sender.sendMessage("You have forgotten to install CS-CoreLib! Slimefun is disabled.");
|
|
|
|
sender.sendMessage("https://thebusybiscuit.github.io/builds/TheBusyBiscuit/CS-CoreLib/master/");
|
|
|
|
return true;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-03-27 11:16:42 +00:00
|
|
|
private String getStartupTime(long timestamp) {
|
|
|
|
long ms = (System.nanoTime() - timestamp) / 1000000;
|
|
|
|
|
|
|
|
if (ms > 1000) {
|
2020-03-28 20:04:16 +00:00
|
|
|
return DoubleHandler.fixDouble(ms / 1000.0) + "s";
|
2020-03-27 11:16:42 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
return DoubleHandler.fixDouble(ms) + "ms";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-10 18:30:24 +00:00
|
|
|
/**
|
|
|
|
* This method checks for the {@link MinecraftVersion} of the {@link Server}.
|
|
|
|
* If the version is unsupported, a warning will be printed to the console.
|
|
|
|
*
|
|
|
|
* @return Whether the {@link MinecraftVersion} is unsupported
|
|
|
|
*/
|
2020-03-04 23:04:18 +00:00
|
|
|
private boolean isVersionUnsupported() {
|
|
|
|
String currentVersion = ReflectionUtils.getVersion();
|
|
|
|
|
|
|
|
if (currentVersion.startsWith("v")) {
|
2020-03-14 00:12:52 +00:00
|
|
|
for (MinecraftVersion version : MinecraftVersion.values()) {
|
|
|
|
if (version.matches(currentVersion)) {
|
|
|
|
minecraftVersion = version;
|
|
|
|
return false;
|
2020-03-04 23:04:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Looks like you are using an unsupported Minecraft Version
|
2020-03-29 16:54:46 +00:00
|
|
|
getLogger().log(Level.SEVERE, "#############################################");
|
2020-03-14 00:12:52 +00:00
|
|
|
getLogger().log(Level.SEVERE, "### Slimefun was not installed correctly!");
|
|
|
|
getLogger().log(Level.SEVERE, "### You are using the wrong version of Minecraft!");
|
|
|
|
getLogger().log(Level.SEVERE, "###");
|
2020-03-19 19:38:13 +00:00
|
|
|
getLogger().log(Level.SEVERE, "### You are using Minecraft {0}", ReflectionUtils.getVersion());
|
|
|
|
getLogger().log(Level.SEVERE, "### but Slimefun v{0} requires you to be using", getDescription().getVersion());
|
2020-03-22 15:44:28 +00:00
|
|
|
getLogger().log(Level.SEVERE, "### Minecraft {0}", String.join(" / ", getSupportedVersions()));
|
2020-03-29 16:54:46 +00:00
|
|
|
getLogger().log(Level.SEVERE, "#############################################");
|
2020-03-14 00:12:52 +00:00
|
|
|
return true;
|
2020-03-04 23:04:18 +00:00
|
|
|
}
|
|
|
|
|
2020-03-24 01:00:21 +00:00
|
|
|
getLogger().log(Level.WARNING, "We could not determine the version of Minecraft you were using ({0})", currentVersion);
|
2020-03-04 23:04:18 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2020-03-22 15:44:28 +00:00
|
|
|
private Collection<String> getSupportedVersions() {
|
|
|
|
List<String> list = new ArrayList<>();
|
|
|
|
|
|
|
|
for (MinecraftVersion version : MinecraftVersion.values()) {
|
|
|
|
if (version != MinecraftVersion.UNKNOWN) {
|
|
|
|
list.add(version.getName());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return list;
|
|
|
|
}
|
|
|
|
|
2020-03-04 23:04:18 +00:00
|
|
|
@Override
|
|
|
|
public void onDisable() {
|
2020-03-18 13:20:49 +00:00
|
|
|
// Slimefun never loaded successfully, so we don't even bother doing stuff here
|
2020-05-20 15:20:52 +00:00
|
|
|
if (instance == null || minecraftVersion == MinecraftVersion.UNIT_TEST) {
|
2020-03-18 13:20:49 +00:00
|
|
|
return;
|
|
|
|
}
|
2020-03-04 23:04:18 +00:00
|
|
|
|
2020-04-09 00:21:30 +00:00
|
|
|
// Cancel all tasks from this plugin immediately
|
2020-03-04 23:04:18 +00:00
|
|
|
Bukkit.getScheduler().cancelTasks(this);
|
|
|
|
|
|
|
|
if (ticker != null) {
|
|
|
|
// Finishes all started movements/removals of block data
|
|
|
|
ticker.halt();
|
|
|
|
ticker.run();
|
|
|
|
}
|
|
|
|
|
2020-04-10 18:30:24 +00:00
|
|
|
// Save all Player Profiles that are still in memory
|
2020-03-04 23:04:18 +00:00
|
|
|
PlayerProfile.iterator().forEachRemaining(profile -> {
|
|
|
|
if (profile.isDirty()) {
|
|
|
|
profile.save();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
for (World world : Bukkit.getWorlds()) {
|
|
|
|
try {
|
|
|
|
BlockStorage storage = BlockStorage.getStorage(world);
|
|
|
|
|
|
|
|
if (storage != null) {
|
|
|
|
storage.save(true);
|
|
|
|
}
|
|
|
|
else {
|
2020-03-19 19:38:13 +00:00
|
|
|
getLogger().log(Level.SEVERE, "Could not save Slimefun Blocks for World \"{0}\"", world.getName());
|
2020-03-04 23:04:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (Exception x) {
|
2020-03-19 19:38:13 +00:00
|
|
|
getLogger().log(Level.SEVERE, x, () -> "An Error occured while saving Slimefun-Blocks in World '" + world.getName() + "' for Slimefun " + getVersion());
|
2020-03-04 23:04:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for (UniversalBlockMenu menu : registry.getUniversalInventories().values()) {
|
|
|
|
menu.save();
|
|
|
|
}
|
|
|
|
|
2020-04-09 00:21:30 +00:00
|
|
|
// Create a new backup zip
|
2020-03-04 23:04:18 +00:00
|
|
|
backupService.run();
|
|
|
|
|
|
|
|
// Prevent Memory Leaks
|
2020-04-09 00:21:30 +00:00
|
|
|
// These static Maps should be removed at some point...
|
2020-03-04 23:04:18 +00:00
|
|
|
AContainer.processing = null;
|
|
|
|
AContainer.progress = null;
|
|
|
|
|
|
|
|
AGenerator.processing = null;
|
|
|
|
AGenerator.progress = null;
|
|
|
|
|
2020-06-20 17:21:44 +00:00
|
|
|
Reactor.processing = null;
|
|
|
|
Reactor.progress = null;
|
2020-03-04 23:04:18 +00:00
|
|
|
|
|
|
|
instance = null;
|
|
|
|
|
2020-04-09 00:21:30 +00:00
|
|
|
// Close all inventories on the server to prevent item dupes
|
|
|
|
// (Incase some idiot uses /reload)
|
2020-03-04 23:04:18 +00:00
|
|
|
for (Player p : Bukkit.getOnlinePlayers()) {
|
|
|
|
p.closeInventory();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void createDirectories() {
|
2020-03-27 12:19:47 +00:00
|
|
|
String[] storageFolders = { "Players", "blocks", "stored-blocks", "stored-inventories", "stored-chunks", "universal-inventories", "waypoints", "block-backups" };
|
2020-04-09 00:21:30 +00:00
|
|
|
String[] pluginFolders = { "scripts", "generators", "error-reports", "cache/github", "world-settings" };
|
2020-03-04 23:04:18 +00:00
|
|
|
|
2020-03-27 12:19:47 +00:00
|
|
|
for (String folder : storageFolders) {
|
2020-04-09 00:21:30 +00:00
|
|
|
File file = new File("data-storage/Slimefun", folder);
|
2020-06-21 08:26:54 +00:00
|
|
|
|
|
|
|
if (!file.exists()) {
|
|
|
|
file.mkdirs();
|
|
|
|
}
|
2020-03-04 23:04:18 +00:00
|
|
|
}
|
|
|
|
|
2020-03-27 12:19:47 +00:00
|
|
|
for (String folder : pluginFolders) {
|
2020-04-09 00:21:30 +00:00
|
|
|
File file = new File("plugins/Slimefun", folder);
|
2020-06-21 08:26:54 +00:00
|
|
|
|
|
|
|
if (!file.exists()) {
|
|
|
|
file.mkdirs();
|
|
|
|
}
|
2020-03-04 23:04:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-03-27 11:16:42 +00:00
|
|
|
private void loadItems() {
|
|
|
|
try {
|
|
|
|
SlimefunItemSetup.setup(this);
|
|
|
|
}
|
2020-06-19 11:22:52 +00:00
|
|
|
catch (Exception | LinkageError x) {
|
2020-03-27 11:16:42 +00:00
|
|
|
getLogger().log(Level.SEVERE, x, () -> "An Error occured while initializing SlimefunItems for Slimefun " + getVersion());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void loadResearches() {
|
|
|
|
try {
|
|
|
|
ResearchSetup.setupResearches();
|
|
|
|
}
|
2020-06-19 11:22:52 +00:00
|
|
|
catch (Exception | LinkageError x) {
|
2020-03-27 11:16:42 +00:00
|
|
|
getLogger().log(Level.SEVERE, x, () -> "An Error occured while initializing Slimefun Researches for Slimefun " + getVersion());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-03-04 23:04:18 +00:00
|
|
|
public static Config getCfg() {
|
|
|
|
return instance.config;
|
|
|
|
}
|
|
|
|
|
2020-03-16 18:06:51 +00:00
|
|
|
public static Config getResearchCfg() {
|
2020-03-04 23:04:18 +00:00
|
|
|
return instance.researches;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static Config getItemCfg() {
|
|
|
|
return instance.items;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static GPSNetwork getGPSNetwork() {
|
2020-03-15 16:43:51 +00:00
|
|
|
return instance.gpsNetwork;
|
2020-03-04 23:04:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public static TickerTask getTicker() {
|
|
|
|
return instance.ticker;
|
|
|
|
}
|
|
|
|
|
2020-03-07 10:35:29 +00:00
|
|
|
/**
|
|
|
|
* This returns the version of Slimefun that is currently installed.
|
|
|
|
*
|
|
|
|
* @return The currently installed version of Slimefun
|
|
|
|
*/
|
2020-03-04 23:04:18 +00:00
|
|
|
public static String getVersion() {
|
|
|
|
return instance.getDescription().getVersion();
|
|
|
|
}
|
|
|
|
|
|
|
|
public static ProtectionManager getProtectionManager() {
|
|
|
|
return instance.protections;
|
|
|
|
}
|
|
|
|
|
2020-04-03 10:10:42 +00:00
|
|
|
/**
|
|
|
|
* This returns the {@link LocalizationService} of Slimefun.
|
|
|
|
*
|
|
|
|
* @return The {@link LocalizationService} of Slimefun
|
|
|
|
*/
|
2020-03-04 23:04:18 +00:00
|
|
|
public static LocalizationService getLocal() {
|
|
|
|
return instance.local;
|
|
|
|
}
|
|
|
|
|
2020-03-18 13:20:49 +00:00
|
|
|
public static MinecraftRecipeService getMinecraftRecipes() {
|
|
|
|
return instance.recipeService;
|
2020-03-04 23:04:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public static CustomItemDataService getItemDataService() {
|
|
|
|
return instance.itemDataService;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static CustomTextureService getItemTextureService() {
|
|
|
|
return instance.textureService;
|
|
|
|
}
|
|
|
|
|
2020-03-10 20:44:24 +00:00
|
|
|
public static PermissionsService getPermissionsService() {
|
|
|
|
return instance.permissionsService;
|
|
|
|
}
|
|
|
|
|
2020-03-04 23:04:18 +00:00
|
|
|
public static BlockDataService getBlockDataService() {
|
|
|
|
return instance.blockDataService;
|
|
|
|
}
|
|
|
|
|
2020-03-12 02:32:04 +00:00
|
|
|
public static ThirdPartyPluginService getThirdPartySupportService() {
|
|
|
|
return instance.thirdPartySupportService;
|
|
|
|
}
|
|
|
|
|
2020-04-09 00:21:30 +00:00
|
|
|
public static PerWorldSettingsService getWorldSettingsService() {
|
|
|
|
return instance.worldSettingsService;
|
|
|
|
}
|
|
|
|
|
2020-03-07 10:35:29 +00:00
|
|
|
/**
|
|
|
|
* This method returns the {@link UpdaterService} of Slimefun.
|
|
|
|
* It is used to handle automatic updates.
|
|
|
|
*
|
|
|
|
* @return The {@link UpdaterService} for Slimefun
|
|
|
|
*/
|
2020-03-04 23:04:18 +00:00
|
|
|
public static UpdaterService getUpdater() {
|
|
|
|
return instance.updaterService;
|
|
|
|
}
|
|
|
|
|
2020-03-07 10:35:29 +00:00
|
|
|
/**
|
|
|
|
* This method returns the {@link GitHubService} of Slimefun.
|
|
|
|
* It is used to retrieve data from GitHub repositories.
|
|
|
|
*
|
|
|
|
* @return The {@link GitHubService} for Slimefun
|
|
|
|
*/
|
2020-03-04 23:04:18 +00:00
|
|
|
public static GitHubService getGitHubService() {
|
|
|
|
return instance.gitHubService;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static SlimefunRegistry getRegistry() {
|
|
|
|
return instance.registry;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static NetworkManager getNetworkManager() {
|
|
|
|
return instance.networkManager;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static AncientAltarListener getAncientAltarListener() {
|
|
|
|
return instance.ancientAltarListener;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static GrapplingHookListener getGrapplingHookListener() {
|
|
|
|
return instance.grapplingHookListener;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static BackpackListener getBackpackListener() {
|
|
|
|
return instance.backpackListener;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static SlimefunBowListener getBowListener() {
|
|
|
|
return instance.bowListener;
|
|
|
|
}
|
|
|
|
|
2020-03-07 10:35:29 +00:00
|
|
|
/**
|
|
|
|
* This method returns a {@link Set} of every {@link Plugin} that lists Slimefun
|
|
|
|
* as a required or optional dependency.
|
|
|
|
*
|
|
|
|
* We will just assume this to be a list of our addons.
|
|
|
|
*
|
|
|
|
* @return A {@link Set} of every {@link Plugin} that is dependent on Slimefun
|
|
|
|
*/
|
2020-03-04 23:04:18 +00:00
|
|
|
public static Set<Plugin> getInstalledAddons() {
|
|
|
|
return Arrays.stream(instance.getServer().getPluginManager().getPlugins()).filter(plugin -> plugin.getDescription().getDepend().contains(instance.getName()) || plugin.getDescription().getSoftDepend().contains(instance.getName())).collect(Collectors.toSet());
|
|
|
|
}
|
|
|
|
|
2020-04-03 10:10:42 +00:00
|
|
|
/**
|
|
|
|
* The {@link Command} that was added by Slimefun.
|
|
|
|
*
|
|
|
|
* @return Slimefun's command
|
|
|
|
*/
|
2020-03-06 15:39:07 +00:00
|
|
|
public static SlimefunCommand getCommand() {
|
|
|
|
return instance.command;
|
|
|
|
}
|
|
|
|
|
2020-04-03 10:10:42 +00:00
|
|
|
/**
|
|
|
|
* This returns the currently installed version of Minecraft.
|
|
|
|
*
|
|
|
|
* @return The current version of Minecraft
|
|
|
|
*/
|
2020-03-14 00:12:52 +00:00
|
|
|
public static MinecraftVersion getMinecraftVersion() {
|
|
|
|
return instance.minecraftVersion;
|
|
|
|
}
|
2020-04-09 00:21:30 +00:00
|
|
|
|
2020-04-07 17:01:30 +00:00
|
|
|
public static String getCSCoreLibVersion() {
|
|
|
|
return CSCoreLib.getLib().getDescription().getVersion();
|
|
|
|
}
|
2020-03-14 00:12:52 +00:00
|
|
|
|
2020-03-04 23:04:18 +00:00
|
|
|
@Override
|
|
|
|
public JavaPlugin getJavaPlugin() {
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public String getBugTrackerURL() {
|
|
|
|
return "https://github.com/TheBusyBiscuit/Slimefun4/issues";
|
|
|
|
}
|
2020-02-16 11:17:14 +00:00
|
|
|
|
2016-04-14 16:24:03 +00:00
|
|
|
}
|