2016-04-14 16:24:03 +00:00
|
|
|
package me.mrCookieSlime.Slimefun;
|
|
|
|
|
2017-06-22 14:43:49 +00:00
|
|
|
import java.io.File;
|
|
|
|
|
2017-11-25 21:07:00 +00:00
|
|
|
import me.mrCookieSlime.Slimefun.listeners.*;
|
2017-06-22 14:43:49 +00:00
|
|
|
import org.bukkit.Bukkit;
|
|
|
|
import org.bukkit.World;
|
|
|
|
import org.bukkit.entity.Player;
|
|
|
|
import org.bukkit.event.EventHandler;
|
|
|
|
import org.bukkit.event.Listener;
|
|
|
|
import org.bukkit.event.player.PlayerJoinEvent;
|
|
|
|
import org.bukkit.event.player.PlayerQuitEvent;
|
|
|
|
import org.bukkit.event.world.WorldLoadEvent;
|
|
|
|
import org.bukkit.event.world.WorldUnloadEvent;
|
|
|
|
import org.bukkit.inventory.ItemStack;
|
|
|
|
import org.bukkit.plugin.java.JavaPlugin;
|
|
|
|
import org.bukkit.potion.PotionEffect;
|
|
|
|
import org.bukkit.potion.PotionEffectType;
|
|
|
|
import org.bukkit.scheduler.BukkitRunnable;
|
|
|
|
|
2016-04-14 16:24:03 +00:00
|
|
|
import me.mrCookieSlime.CSCoreLibPlugin.CSCoreLib;
|
2017-06-13 17:28:54 +00:00
|
|
|
import me.mrCookieSlime.CSCoreLibPlugin.PluginUtils;
|
2017-06-22 14:43:49 +00:00
|
|
|
import me.mrCookieSlime.CSCoreLibPlugin.Configuration.Config;
|
2016-04-27 10:07:12 +00:00
|
|
|
import me.mrCookieSlime.CSCoreLibPlugin.general.Reflection.ReflectionUtils;
|
2016-04-14 16:24:03 +00:00
|
|
|
import me.mrCookieSlime.Slimefun.AncientAltar.Pedestals;
|
2017-03-24 13:04:38 +00:00
|
|
|
import me.mrCookieSlime.Slimefun.CSCoreLibSetup.CSCoreLibLoader;
|
2016-04-14 16:24:03 +00:00
|
|
|
import me.mrCookieSlime.Slimefun.Commands.SlimefunCommand;
|
|
|
|
import me.mrCookieSlime.Slimefun.Commands.SlimefunTabCompleter;
|
2016-05-18 17:04:27 +00:00
|
|
|
import me.mrCookieSlime.Slimefun.GEO.OreGenSystem;
|
2016-12-05 18:51:39 +00:00
|
|
|
import me.mrCookieSlime.Slimefun.GEO.Resources.NetherIceResource;
|
|
|
|
import me.mrCookieSlime.Slimefun.GEO.Resources.OilResource;
|
2016-04-14 16:24:03 +00:00
|
|
|
import me.mrCookieSlime.Slimefun.GPS.Elevator;
|
2017-01-15 18:17:02 +00:00
|
|
|
import me.mrCookieSlime.Slimefun.GitHub.GitHubConnector;
|
2017-01-18 11:44:12 +00:00
|
|
|
import me.mrCookieSlime.Slimefun.GitHub.GitHubSetup;
|
2017-06-22 14:43:49 +00:00
|
|
|
import me.mrCookieSlime.Slimefun.Hashing.ItemHash;
|
2016-05-18 20:26:35 +00:00
|
|
|
import me.mrCookieSlime.Slimefun.Lists.SlimefunItems;
|
2016-04-14 16:24:03 +00:00
|
|
|
import me.mrCookieSlime.Slimefun.Objects.MultiBlock;
|
|
|
|
import me.mrCookieSlime.Slimefun.Objects.Research;
|
|
|
|
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunArmorPiece;
|
|
|
|
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem;
|
|
|
|
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.abstractItems.AContainer;
|
2017-03-24 13:04:38 +00:00
|
|
|
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.machines.AutoEnchanter;
|
2017-06-22 14:43:49 +00:00
|
|
|
import me.mrCookieSlime.Slimefun.Setup.Files;
|
|
|
|
import me.mrCookieSlime.Slimefun.Setup.Messages;
|
|
|
|
import me.mrCookieSlime.Slimefun.Setup.MiscSetup;
|
|
|
|
import me.mrCookieSlime.Slimefun.Setup.ResearchSetup;
|
|
|
|
import me.mrCookieSlime.Slimefun.Setup.SlimefunManager;
|
|
|
|
import me.mrCookieSlime.Slimefun.Setup.SlimefunSetup;
|
2016-04-14 16:24:03 +00:00
|
|
|
import me.mrCookieSlime.Slimefun.URID.AutoSavingTask;
|
|
|
|
import me.mrCookieSlime.Slimefun.URID.URID;
|
|
|
|
import me.mrCookieSlime.Slimefun.WorldEdit.WESlimefunManager;
|
|
|
|
import me.mrCookieSlime.Slimefun.api.BlockStorage;
|
|
|
|
import me.mrCookieSlime.Slimefun.api.Slimefun;
|
2017-03-31 12:47:43 +00:00
|
|
|
import me.mrCookieSlime.Slimefun.api.SlimefunBackup;
|
2016-04-14 16:24:03 +00:00
|
|
|
import me.mrCookieSlime.Slimefun.api.TickerTask;
|
|
|
|
import me.mrCookieSlime.Slimefun.api.energy.ChargableBlock;
|
|
|
|
import me.mrCookieSlime.Slimefun.api.energy.EnergyNet;
|
|
|
|
import me.mrCookieSlime.Slimefun.api.energy.ItemEnergy;
|
|
|
|
import me.mrCookieSlime.Slimefun.api.inventory.BlockMenuPreset;
|
|
|
|
import me.mrCookieSlime.Slimefun.api.item_transport.CargoNet;
|
2017-01-23 11:52:14 +00:00
|
|
|
import me.mrCookieSlime.Slimefun.api.item_transport.ChestManipulator;
|
2017-03-24 13:04:38 +00:00
|
|
|
import net.coreprotect.CoreProtect;
|
|
|
|
import net.coreprotect.CoreProtectAPI;
|
2016-04-14 16:24:03 +00:00
|
|
|
|
|
|
|
public class SlimefunStartup extends JavaPlugin {
|
2016-11-19 23:23:37 +00:00
|
|
|
|
2016-04-14 16:24:03 +00:00
|
|
|
public static SlimefunStartup instance;
|
2016-11-19 23:23:37 +00:00
|
|
|
|
2016-04-14 16:24:03 +00:00
|
|
|
static PluginUtils utils;
|
|
|
|
static Config researches;
|
|
|
|
static Config items;
|
|
|
|
static Config whitelist;
|
|
|
|
static Config config;
|
2016-11-19 23:23:37 +00:00
|
|
|
|
2016-04-14 16:24:03 +00:00
|
|
|
public static TickerTask ticker;
|
2016-11-19 23:23:37 +00:00
|
|
|
|
2017-02-06 18:28:06 +00:00
|
|
|
private CoreProtectAPI coreProtectAPI;
|
|
|
|
|
2016-04-14 16:24:03 +00:00
|
|
|
private boolean clearlag = false;
|
2016-11-19 23:23:37 +00:00
|
|
|
private boolean exoticGarden = false;
|
2017-02-06 18:28:06 +00:00
|
|
|
private boolean coreProtect = false;
|
2016-08-05 23:11:32 +00:00
|
|
|
|
|
|
|
// Supported Versions of Minecraft
|
2017-06-14 10:35:25 +00:00
|
|
|
final String[] supported = {"v1_9_", "v1_10_", "v1_11_", "v1_12_"};
|
2017-01-19 17:29:04 +00:00
|
|
|
|
2016-04-14 16:24:03 +00:00
|
|
|
@SuppressWarnings("deprecation")
|
|
|
|
@Override
|
|
|
|
public void onEnable() {
|
|
|
|
CSCoreLibLoader loader = new CSCoreLibLoader(this);
|
|
|
|
if (loader.load()) {
|
2016-11-19 23:23:37 +00:00
|
|
|
|
2017-06-14 10:35:25 +00:00
|
|
|
String currentVersion = ReflectionUtils.getVersion();
|
|
|
|
|
|
|
|
if (currentVersion.startsWith("v")) {
|
|
|
|
boolean compatibleVersion = false;
|
|
|
|
StringBuilder versions = new StringBuilder();
|
|
|
|
|
|
|
|
int i = 0;
|
|
|
|
for (String version: supported) {
|
|
|
|
if (currentVersion.startsWith(version)) {
|
|
|
|
compatibleVersion = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (i == 0) versions.append(version.substring(1).replaceFirst("_", ".").replace("_", ".X"));
|
|
|
|
else if (i == supported.length - 1) versions.append(" or " + version.substring(1).replaceFirst("_", ".").replace("_", ".X"));
|
|
|
|
else versions.append(", " + version.substring(1).replaceFirst("_", ".").replace("_", ".X"));
|
|
|
|
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Looks like you are using an unsupported Minecraft Version
|
|
|
|
if (!compatibleVersion) {
|
|
|
|
System.err.println("### Slimefun failed to load!");
|
|
|
|
System.err.println("###");
|
|
|
|
System.err.println("### You are using the wrong Version of Minecraft!!!");
|
|
|
|
System.err.println("###");
|
|
|
|
System.err.println("### You are using Minecraft " + ReflectionUtils.getVersion());
|
|
|
|
System.err.println("### but Slimefun v" + getDescription().getVersion() + " requires you to be using");
|
|
|
|
System.err.println("### Minecraft " + versions.toString());
|
|
|
|
System.err.println("###");
|
|
|
|
System.err.println("### Please use an older Version of Slimefun and disable auto-updating");
|
|
|
|
System.err.println("### or consider updating your Server Software.");
|
|
|
|
getServer().getPluginManager().disablePlugin(this);
|
|
|
|
return;
|
2016-08-05 23:11:32 +00:00
|
|
|
}
|
2016-04-27 10:07:12 +00:00
|
|
|
}
|
2016-11-19 23:23:37 +00:00
|
|
|
|
2016-04-14 16:24:03 +00:00
|
|
|
instance = this;
|
|
|
|
System.out.println("[Slimefun] Loading Files...");
|
|
|
|
Files.cleanup();
|
2016-11-19 23:23:37 +00:00
|
|
|
|
2016-04-14 16:24:03 +00:00
|
|
|
System.out.println("[Slimefun] Loading Config...");
|
2016-11-19 23:23:37 +00:00
|
|
|
|
2016-04-14 16:24:03 +00:00
|
|
|
utils = new PluginUtils(this);
|
|
|
|
utils.setupConfig();
|
2016-11-19 23:23:37 +00:00
|
|
|
|
2016-08-05 23:23:40 +00:00
|
|
|
// Loading all extra configs
|
2016-04-14 16:24:03 +00:00
|
|
|
researches = new Config(Files.RESEARCHES);
|
|
|
|
items = new Config(Files.ITEMS);
|
|
|
|
whitelist = new Config(Files.WHITELIST);
|
2016-11-19 23:23:37 +00:00
|
|
|
|
2016-08-05 23:23:40 +00:00
|
|
|
// Init Config, Updater, Metrics and messages.yml
|
2016-04-14 16:24:03 +00:00
|
|
|
utils.setupUpdater(53485, getFile());
|
|
|
|
utils.setupMetrics();
|
|
|
|
utils.setupLocalization();
|
|
|
|
config = utils.getConfig();
|
|
|
|
Messages.local = utils.getLocalization();
|
|
|
|
Messages.setup();
|
|
|
|
|
2016-08-05 23:23:40 +00:00
|
|
|
// Creating all necessary Folders
|
|
|
|
// TODO: Make a shortcut method such as createDir(path)
|
2016-04-14 16:24:03 +00:00
|
|
|
if (!new File("data-storage/Slimefun/blocks").exists()) new File("data-storage/Slimefun/blocks").mkdirs();
|
|
|
|
if (!new File("data-storage/Slimefun/stored-blocks").exists()) new File("data-storage/Slimefun/stored-blocks").mkdirs();
|
|
|
|
if (!new File("data-storage/Slimefun/stored-inventories").exists()) new File("data-storage/Slimefun/stored-inventories").mkdirs();
|
2017-03-14 15:28:15 +00:00
|
|
|
if (!new File("data-storage/Slimefun/stored-chunks").exists()) new File("data-storage/Slimefun/stored-chunks").mkdirs();
|
2016-04-14 16:24:03 +00:00
|
|
|
if (!new File("data-storage/Slimefun/universal-inventories").exists()) new File("data-storage/Slimefun/universal-inventories").mkdirs();
|
|
|
|
if (!new File("data-storage/Slimefun/waypoints").exists()) new File("data-storage/Slimefun/waypoints").mkdirs();
|
|
|
|
if (!new File("data-storage/Slimefun/block-backups").exists()) new File("data-storage/Slimefun/block-backups").mkdirs();
|
|
|
|
if (!new File("plugins/Slimefun/scripts").exists()) new File("plugins/Slimefun/scripts").mkdirs();
|
|
|
|
if (!new File("plugins/Slimefun/generators").exists()) new File("plugins/Slimefun/generators").mkdirs();
|
2016-04-25 16:51:19 +00:00
|
|
|
if (!new File("plugins/Slimefun/error-reports").exists()) new File("plugins/Slimefun/error-reports").mkdirs();
|
2017-01-16 15:28:41 +00:00
|
|
|
if (!new File("plugins/Slimefun/cache/github").exists()) new File("plugins/Slimefun/cache/github").mkdirs();
|
2016-11-19 23:23:37 +00:00
|
|
|
|
2016-04-14 16:24:03 +00:00
|
|
|
SlimefunManager.plugin = this;
|
2016-11-19 23:23:37 +00:00
|
|
|
|
2016-04-14 16:24:03 +00:00
|
|
|
System.out.println("[Slimefun] Loading Items...");
|
|
|
|
MiscSetup.setupItemSettings();
|
|
|
|
try {
|
|
|
|
SlimefunSetup.setupItems();
|
|
|
|
} catch (Exception e1) {
|
|
|
|
e1.printStackTrace();
|
|
|
|
}
|
|
|
|
MiscSetup.loadDescriptions();
|
2016-11-19 23:23:37 +00:00
|
|
|
|
2016-04-14 16:24:03 +00:00
|
|
|
System.out.println("[Slimefun] Loading Researches...");
|
|
|
|
Research.enabled = getResearchCfg().getBoolean("enable-researching");
|
|
|
|
ResearchSetup.setupResearches();
|
2016-11-19 23:23:37 +00:00
|
|
|
|
2016-04-14 16:24:03 +00:00
|
|
|
MiscSetup.setupMisc();
|
2016-11-19 23:23:37 +00:00
|
|
|
|
2016-04-14 16:24:03 +00:00
|
|
|
BlockStorage.info_delay = config.getInt("URID.info-delay");
|
|
|
|
|
|
|
|
System.out.println("[Slimefun] Loading World Generators...");
|
2016-11-19 23:23:37 +00:00
|
|
|
|
2016-08-05 23:23:40 +00:00
|
|
|
// Generating Oil as an OreGenResource (its a cool API)
|
2016-12-05 18:51:39 +00:00
|
|
|
OreGenSystem.registerResource(new OilResource());
|
|
|
|
OreGenSystem.registerResource(new NetherIceResource());
|
2016-11-26 12:03:45 +00:00
|
|
|
|
2017-01-18 11:44:12 +00:00
|
|
|
// Setting up GitHub Connectors...
|
|
|
|
|
|
|
|
GitHubSetup.setup();
|
|
|
|
|
2016-08-05 23:23:40 +00:00
|
|
|
// All Slimefun Listeners
|
2016-04-14 16:24:03 +00:00
|
|
|
new ArmorListener(this);
|
|
|
|
new ItemListener(this);
|
|
|
|
new BlockListener(this);
|
|
|
|
new GearListener(this);
|
|
|
|
new AutonomousToolsListener(this);
|
|
|
|
new DamageListener(this);
|
|
|
|
new BowListener(this);
|
|
|
|
new ToolListener(this);
|
|
|
|
new FurnaceListener(this);
|
|
|
|
new TeleporterListener(this);
|
|
|
|
new AndroidKillingListener(this);
|
2017-11-25 21:07:00 +00:00
|
|
|
if (currentVersion.startsWith("v1_12_")) new ItemPickupListener_1_12(this);
|
|
|
|
else new ItemPickupListener(this);
|
2016-11-19 23:23:37 +00:00
|
|
|
|
2016-08-05 23:23:40 +00:00
|
|
|
// Toggleable Listeners for performance
|
2016-04-14 16:24:03 +00:00
|
|
|
if (config.getBoolean("items.talismans")) new TalismanListener(this);
|
|
|
|
if (config.getBoolean("items.backpacks")) new BackpackListener(this);
|
|
|
|
if (config.getBoolean("items.coolers")) new CoolerListener(this);
|
2016-08-05 23:23:40 +00:00
|
|
|
|
|
|
|
// Handle Slimefun Guide being given on Join
|
|
|
|
// TODO: Move it to its own class, was too lazy
|
2016-04-14 16:24:03 +00:00
|
|
|
if (config.getBoolean("options.give-guide-on-first-join")) {
|
|
|
|
getServer().getPluginManager().registerEvents(new Listener() {
|
2016-11-19 23:23:37 +00:00
|
|
|
|
2016-04-14 16:24:03 +00:00
|
|
|
@EventHandler
|
|
|
|
public void onJoin(PlayerJoinEvent e) {
|
|
|
|
if (!e.getPlayer().hasPlayedBefore()) {
|
|
|
|
Player p = e.getPlayer();
|
|
|
|
if (!getWhitelist().getBoolean(p.getWorld().getName() + ".enabled")) return;
|
|
|
|
if (!getWhitelist().getBoolean(p.getWorld().getName() + ".enabled-items.SLIMEFUN_GUIDE")) return;
|
2016-04-15 05:23:48 +00:00
|
|
|
p.getInventory().addItem(SlimefunGuide.getItem(config.getBoolean("guide.default-view-book")));
|
2016-04-14 16:24:03 +00:00
|
|
|
}
|
|
|
|
}
|
2016-11-19 23:23:37 +00:00
|
|
|
|
2016-04-14 16:24:03 +00:00
|
|
|
}, this);
|
|
|
|
}
|
2016-08-05 23:23:40 +00:00
|
|
|
|
|
|
|
// Load/Unload Worlds in Slimefun
|
|
|
|
// TODO: Move it to its own class, was too lazy
|
2016-04-14 16:24:03 +00:00
|
|
|
getServer().getPluginManager().registerEvents(new Listener() {
|
2016-11-19 23:23:37 +00:00
|
|
|
|
2016-04-14 16:24:03 +00:00
|
|
|
@EventHandler
|
|
|
|
public void onWorldLoad(WorldLoadEvent e) {
|
|
|
|
BlockStorage.getForcedStorage(e.getWorld());
|
2016-11-19 23:23:37 +00:00
|
|
|
|
2016-04-14 16:24:03 +00:00
|
|
|
SlimefunStartup.getWhitelist().setDefaultValue(e.getWorld().getName() + ".enabled", true);
|
|
|
|
SlimefunStartup.getWhitelist().setDefaultValue(e.getWorld().getName() + ".enabled-items.SLIMEFUN_GUIDE", true);
|
|
|
|
SlimefunStartup.getWhitelist().save();
|
|
|
|
}
|
2016-11-19 23:23:37 +00:00
|
|
|
|
2016-04-14 16:24:03 +00:00
|
|
|
@EventHandler
|
|
|
|
public void onWorldUnload(WorldUnloadEvent e) {
|
|
|
|
BlockStorage storage = BlockStorage.getStorage(e.getWorld());
|
|
|
|
if (storage != null) storage.save(true);
|
|
|
|
else System.err.println("[Slimefun] Could not save Slimefun Blocks for World \"" + e.getWorld().getName() + "\"");
|
|
|
|
}
|
2016-11-19 23:23:37 +00:00
|
|
|
|
2016-04-14 16:24:03 +00:00
|
|
|
}, this);
|
2016-11-19 23:23:37 +00:00
|
|
|
|
2016-08-05 23:23:40 +00:00
|
|
|
// Clear the Slimefun Guide History upon Player Leaving
|
|
|
|
// TODO: Move it to its own class, was too lazy
|
2016-04-14 16:24:03 +00:00
|
|
|
getServer().getPluginManager().registerEvents(new Listener() {
|
2016-11-19 23:23:37 +00:00
|
|
|
|
2016-04-14 16:24:03 +00:00
|
|
|
@EventHandler
|
|
|
|
public void onDisconnect(PlayerQuitEvent e) {
|
|
|
|
if (SlimefunGuide.history.containsKey(e.getPlayer().getUniqueId())) SlimefunGuide.history.remove(e.getPlayer().getUniqueId());
|
|
|
|
}
|
2016-11-19 23:23:37 +00:00
|
|
|
|
2016-04-14 16:24:03 +00:00
|
|
|
}, this);
|
2016-11-19 23:23:37 +00:00
|
|
|
|
2016-08-05 23:23:40 +00:00
|
|
|
// Initiating various Stuff and all Items with a slightly delay (0ms after the Server finished loading)
|
2016-04-14 16:24:03 +00:00
|
|
|
getServer().getScheduler().scheduleSyncDelayedTask(this, new Runnable() {
|
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
Slimefun.emeraldenchants = getServer().getPluginManager().isPluginEnabled("EmeraldEnchants");
|
|
|
|
SlimefunGuide.all_recipes = config.getBoolean("options.show-vanilla-recipes-in-guide");
|
|
|
|
MiscSetup.loadItems();
|
2016-11-19 23:23:37 +00:00
|
|
|
|
2016-04-14 16:24:03 +00:00
|
|
|
for (World world: Bukkit.getWorlds()) {
|
|
|
|
new BlockStorage(world);
|
|
|
|
}
|
2016-11-19 23:23:37 +00:00
|
|
|
|
2016-04-14 16:24:03 +00:00
|
|
|
if (SlimefunItem.getByName("ANCIENT_ALTAR") != null) new AncientAltarListener((SlimefunStartup) instance);
|
|
|
|
}
|
|
|
|
}, 0);
|
2016-11-19 23:23:37 +00:00
|
|
|
|
2016-08-05 23:23:40 +00:00
|
|
|
// WorldEdit Hook to clear Slimefun Data upon //set 0 //cut or any other equivalent
|
2016-04-14 16:24:03 +00:00
|
|
|
if (getServer().getPluginManager().isPluginEnabled("WorldEdit")) {
|
|
|
|
try {
|
2016-05-19 14:50:56 +00:00
|
|
|
Class.forName("com.sk89q.worldedit.extent.Extent");
|
2016-04-14 16:24:03 +00:00
|
|
|
new WESlimefunManager();
|
|
|
|
System.out.println("[Slimefun] Successfully hooked into WorldEdit!");
|
|
|
|
} catch(Exception x) {
|
|
|
|
System.err.println("[Slimefun] Failed to hook into WorldEdit!");
|
|
|
|
System.err.println("[Slimefun] Maybe consider updating WorldEdit or Slimefun?");
|
|
|
|
}
|
|
|
|
}
|
2016-11-19 23:23:37 +00:00
|
|
|
|
2016-04-14 16:24:03 +00:00
|
|
|
getCommand("slimefun").setExecutor(new SlimefunCommand(this));
|
|
|
|
getCommand("slimefun").setTabCompleter(new SlimefunTabCompleter());
|
2016-11-19 23:23:37 +00:00
|
|
|
|
2016-08-05 23:23:40 +00:00
|
|
|
// Armor Update Task
|
2016-04-14 16:24:03 +00:00
|
|
|
if (config.getBoolean("options.enable-armor-effects")) {
|
|
|
|
getServer().getScheduler().runTaskTimer(this, new Runnable() {
|
2016-11-19 23:23:37 +00:00
|
|
|
|
2016-04-14 16:24:03 +00:00
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
for (Player p: Bukkit.getOnlinePlayers()) {
|
|
|
|
for (ItemStack armor: p.getInventory().getArmorContents()) {
|
|
|
|
if (armor != null) {
|
|
|
|
if (Slimefun.hasUnlocked(p, armor, true)) {
|
|
|
|
if (SlimefunItem.getByItem(armor) instanceof SlimefunArmorPiece) {
|
|
|
|
for (PotionEffect effect: ((SlimefunArmorPiece) SlimefunItem.getByItem(armor)).getEffects()) {
|
|
|
|
p.removePotionEffect(effect.getType());
|
|
|
|
p.addPotionEffect(effect);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (SlimefunManager.isItemSimiliar(armor, SlimefunItem.getItem("SOLAR_HELMET"), false)) {
|
|
|
|
if (p.getWorld().getTime() < 12300 || p.getWorld().getTime() > 23850) {
|
|
|
|
if (p.getEyeLocation().getBlock().getLightFromSky() == 15) {
|
|
|
|
ItemEnergy.chargeInventory(p, Float.valueOf(String.valueOf(Slimefun.getItemValue("SOLAR_HELMET", "charge-amount"))));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-11-19 23:23:37 +00:00
|
|
|
|
2016-04-14 16:24:03 +00:00
|
|
|
for (ItemStack radioactive: SlimefunItem.radioactive) {
|
2016-12-13 15:00:35 +00:00
|
|
|
if (p.getInventory().containsAtLeast(radioactive, 1) || SlimefunManager.isItemSimiliar(p.getInventory().getItemInOffHand(), radioactive, true)) {
|
2017-08-12 12:28:34 +00:00
|
|
|
// Check if player is wearing the hazmat suit
|
|
|
|
// If so, break the loop
|
2016-12-13 15:00:35 +00:00
|
|
|
if (SlimefunManager.isItemSimiliar(SlimefunItems.SCUBA_HELMET, p.getInventory().getHelmet(), true) &&
|
|
|
|
SlimefunManager.isItemSimiliar(SlimefunItems.HAZMATSUIT_CHESTPLATE, p.getInventory().getChestplate(), true) &&
|
|
|
|
SlimefunManager.isItemSimiliar(SlimefunItems.HAZMATSUIT_LEGGINGS, p.getInventory().getLeggings(), true) &&
|
|
|
|
SlimefunManager.isItemSimiliar(SlimefunItems.RUBBER_BOOTS, p.getInventory().getBoots(), true)) {
|
2016-04-14 16:24:03 +00:00
|
|
|
break;
|
|
|
|
}
|
2016-12-13 15:00:35 +00:00
|
|
|
|
2017-08-12 12:28:34 +00:00
|
|
|
// If the item is enabled in the world, then make radioactivity do its job
|
2017-08-12 14:08:50 +00:00
|
|
|
if (Slimefun.isEnabled(p, radioactive, false)) {
|
2017-08-12 12:28:34 +00:00
|
|
|
p.addPotionEffect(new PotionEffect(PotionEffectType.WITHER, 400, 3));
|
|
|
|
p.addPotionEffect(new PotionEffect(PotionEffectType.BLINDNESS, 400, 3));
|
|
|
|
p.addPotionEffect(new PotionEffect(PotionEffectType.CONFUSION, 400, 3));
|
|
|
|
p.addPotionEffect(new PotionEffect(PotionEffectType.WEAKNESS, 400, 3));
|
|
|
|
p.addPotionEffect(new PotionEffect(PotionEffectType.SLOW, 400, 1));
|
|
|
|
p.addPotionEffect(new PotionEffect(PotionEffectType.SLOW_DIGGING, 400, 1));
|
|
|
|
p.setFireTicks(400);
|
|
|
|
break; // Break the loop to save some calculations
|
|
|
|
}
|
2016-04-14 16:24:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}, 0L, config.getInt("options.armor-update-interval") * 20L);
|
|
|
|
}
|
2016-11-19 23:23:37 +00:00
|
|
|
|
2016-04-14 16:24:03 +00:00
|
|
|
ticker = new TickerTask();
|
2016-11-19 23:23:37 +00:00
|
|
|
|
2016-08-05 23:23:40 +00:00
|
|
|
// Starting all ASYNC Tasks
|
2016-04-14 16:24:03 +00:00
|
|
|
getServer().getScheduler().scheduleAsyncRepeatingTask(this, new AutoSavingTask(), 1200L, config.getInt("options.auto-save-delay-in-minutes") * 60L * 20L);
|
|
|
|
getServer().getScheduler().scheduleAsyncRepeatingTask(this, ticker, 100L, config.getInt("URID.custom-ticker-delay"));
|
2017-01-18 11:14:01 +00:00
|
|
|
|
2017-01-18 11:44:12 +00:00
|
|
|
getServer().getScheduler().scheduleAsyncRepeatingTask(this, new Runnable() {
|
2017-01-18 11:14:01 +00:00
|
|
|
|
|
|
|
@Override
|
2017-01-18 11:44:12 +00:00
|
|
|
public void run() {
|
|
|
|
for (GitHubConnector connector: GitHubConnector.connectors) {
|
|
|
|
connector.pullFile();
|
|
|
|
}
|
2017-01-18 11:14:01 +00:00
|
|
|
}
|
2017-03-31 12:47:43 +00:00
|
|
|
}, 80L, 60 * 60 * 20L);
|
2017-01-18 11:14:01 +00:00
|
|
|
|
2016-08-05 23:23:40 +00:00
|
|
|
// Hooray!
|
2016-04-14 16:24:03 +00:00
|
|
|
System.out.println("[Slimefun] Finished!");
|
2016-11-19 23:23:37 +00:00
|
|
|
|
2016-04-14 16:24:03 +00:00
|
|
|
clearlag = getServer().getPluginManager().isPluginEnabled("ClearLag");
|
2016-11-19 23:23:37 +00:00
|
|
|
|
2017-02-06 18:28:06 +00:00
|
|
|
coreProtect = getServer().getPluginManager().isPluginEnabled("CoreProtect");
|
|
|
|
|
2016-11-19 23:23:37 +00:00
|
|
|
Bukkit.getScheduler().scheduleSyncDelayedTask(this, new BukkitRunnable() {
|
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
exoticGarden = getServer().getPluginManager().isPluginEnabled("ExoticGarden"); //Had to do it this way, otherwise it seems disabled.
|
|
|
|
}
|
|
|
|
}, 0);
|
|
|
|
|
2016-04-14 16:24:03 +00:00
|
|
|
if (clearlag) new ClearLaggIntegration(this);
|
2016-11-19 23:23:37 +00:00
|
|
|
|
2017-02-06 18:28:06 +00:00
|
|
|
if (coreProtect) coreProtectAPI = ((CoreProtect)getServer().getPluginManager().getPlugin("CoreProtect")).getAPI();
|
|
|
|
|
2017-06-23 11:06:08 +00:00
|
|
|
Research.creative_research = config.getBoolean("options.allow-free-creative-research");
|
2017-02-06 17:23:11 +00:00
|
|
|
|
|
|
|
AutoEnchanter.max_emerald_enchantments = config.getInt("options.emerald-enchantment-limit");
|
|
|
|
|
2016-08-05 23:23:40 +00:00
|
|
|
// Do not show /sf elevator command in our Log, it could get quite spammy
|
2016-04-14 22:37:23 +00:00
|
|
|
CSCoreLib.getLib().filterLog("([A-Za-z0-9_]{3,16}) issued server command: /sf elevator (.{0,})");
|
2016-04-14 16:24:03 +00:00
|
|
|
}
|
|
|
|
}
|
2016-11-19 23:23:37 +00:00
|
|
|
|
2016-04-14 16:24:03 +00:00
|
|
|
@Override
|
|
|
|
public void onDisable() {
|
|
|
|
Bukkit.getScheduler().cancelTasks(this);
|
2017-03-31 12:47:43 +00:00
|
|
|
|
|
|
|
// Finishes all started movements/removals of block data
|
|
|
|
ticker.HALTED = true;
|
|
|
|
ticker.run();
|
|
|
|
|
2016-06-10 16:39:40 +00:00
|
|
|
try {
|
|
|
|
for (World world: Bukkit.getWorlds()) {
|
|
|
|
BlockStorage storage = BlockStorage.getStorage(world);
|
2017-03-31 12:47:43 +00:00
|
|
|
if (storage != null) {
|
|
|
|
storage.save(true);
|
2016-06-10 16:39:40 +00:00
|
|
|
}
|
2017-03-31 12:47:43 +00:00
|
|
|
else {
|
|
|
|
System.err.println("[Slimefun] Could not save Slimefun Blocks for World \"" + world.getName() + "\"");
|
2016-04-14 16:24:03 +00:00
|
|
|
}
|
|
|
|
}
|
2017-03-31 12:47:43 +00:00
|
|
|
|
|
|
|
SlimefunBackup.start();
|
2016-06-10 16:39:40 +00:00
|
|
|
} catch(Exception x) {
|
2016-04-14 16:24:03 +00:00
|
|
|
}
|
2016-11-19 23:23:37 +00:00
|
|
|
|
2017-06-22 14:43:49 +00:00
|
|
|
// Prevent Memory Leaks
|
2016-04-14 16:24:03 +00:00
|
|
|
config = null;
|
|
|
|
researches = null;
|
|
|
|
items = null;
|
|
|
|
whitelist = null;
|
|
|
|
instance = null;
|
|
|
|
Messages.local = null;
|
|
|
|
Files.CONFIG = null;
|
|
|
|
Files.DATABASE = null;
|
|
|
|
Files.ITEMS = null;
|
|
|
|
Files.RESEARCHES = null;
|
|
|
|
Files.WHITELIST = null;
|
|
|
|
MultiBlock.list = null;
|
|
|
|
Research.list = null;
|
|
|
|
Research.researching = null;
|
|
|
|
SlimefunItem.all = null;
|
|
|
|
SlimefunItem.items = null;
|
2017-10-13 14:34:38 +00:00
|
|
|
SlimefunItem.map_id = null;
|
2016-04-14 16:24:03 +00:00
|
|
|
SlimefunItem.handlers = null;
|
|
|
|
SlimefunItem.radioactive = null;
|
|
|
|
Variables.damage = null;
|
|
|
|
Variables.jump = null;
|
|
|
|
Variables.mode = null;
|
|
|
|
SlimefunGuide.history = null;
|
|
|
|
Variables.enchanting = null;
|
|
|
|
Variables.backpack = null;
|
|
|
|
Variables.soulbound = null;
|
|
|
|
Variables.blocks = null;
|
|
|
|
Variables.cancelPlace = null;
|
|
|
|
Variables.arrows = null;
|
|
|
|
SlimefunCommand.arguments = null;
|
|
|
|
SlimefunCommand.descriptions = null;
|
|
|
|
SlimefunCommand.tabs = null;
|
|
|
|
URID.objects = null;
|
|
|
|
URID.ids = null;
|
|
|
|
SlimefunItem.blockhandler = null;
|
|
|
|
BlockMenuPreset.presets = null;
|
|
|
|
BlockStorage.loaded_tickers = null;
|
|
|
|
BlockStorage.ticking_chunks = null;
|
|
|
|
BlockStorage.worlds = null;
|
|
|
|
ChargableBlock.capacitors = null;
|
|
|
|
ChargableBlock.max_charges = null;
|
|
|
|
AContainer.processing = null;
|
|
|
|
AContainer.progress = null;
|
|
|
|
Slimefun.guide_handlers = null;
|
|
|
|
Pedestals.recipes = null;
|
|
|
|
Elevator.ignored = null;
|
|
|
|
EnergyNet.listeners = null;
|
|
|
|
EnergyNet.machines_input = null;
|
|
|
|
EnergyNet.machines_output = null;
|
|
|
|
EnergyNet.machines_storage = null;
|
|
|
|
CargoNet.faces = null;
|
|
|
|
BlockStorage.universal_inventories = null;
|
|
|
|
TickerTask.block_timings = null;
|
2016-05-18 17:04:27 +00:00
|
|
|
OreGenSystem.map = null;
|
2017-01-15 18:17:02 +00:00
|
|
|
SlimefunGuide.contributors = null;
|
2017-01-16 15:28:41 +00:00
|
|
|
GitHubConnector.connectors = null;
|
2017-01-23 11:52:14 +00:00
|
|
|
ChestManipulator.listeners = null;
|
2017-06-22 14:43:49 +00:00
|
|
|
ItemHash.digest = null;
|
|
|
|
ItemHash.map = null;
|
2016-11-19 23:23:37 +00:00
|
|
|
|
2016-04-14 16:24:03 +00:00
|
|
|
for (Player p: Bukkit.getOnlinePlayers()) {
|
|
|
|
p.closeInventory();
|
|
|
|
}
|
|
|
|
}
|
2016-11-19 23:23:37 +00:00
|
|
|
|
2016-04-14 16:24:03 +00:00
|
|
|
public static Config getCfg() {
|
|
|
|
return config;
|
|
|
|
}
|
2016-11-19 23:23:37 +00:00
|
|
|
|
2016-04-14 16:24:03 +00:00
|
|
|
public static Config getResearchCfg() {
|
|
|
|
return researches;
|
|
|
|
}
|
2016-11-19 23:23:37 +00:00
|
|
|
|
2016-04-14 16:24:03 +00:00
|
|
|
public static Config getItemCfg() {
|
|
|
|
return items;
|
|
|
|
}
|
2016-11-19 23:23:37 +00:00
|
|
|
|
2016-04-14 16:24:03 +00:00
|
|
|
public static Config getWhitelist() {
|
|
|
|
return whitelist;
|
|
|
|
}
|
2016-11-19 23:23:37 +00:00
|
|
|
|
2016-04-14 16:24:03 +00:00
|
|
|
public static int randomize(int max) {
|
2017-08-12 11:24:16 +00:00
|
|
|
if (max < 1) return 0;
|
2016-04-14 16:24:03 +00:00
|
|
|
return CSCoreLib.randomizer().nextInt(max);
|
|
|
|
}
|
2016-11-19 23:23:37 +00:00
|
|
|
|
2016-04-14 16:24:03 +00:00
|
|
|
public static boolean chance(int max, int percentage) {
|
2017-08-12 13:21:29 +00:00
|
|
|
if (max < 1) return false;
|
2016-04-14 16:24:03 +00:00
|
|
|
return CSCoreLib.randomizer().nextInt(max) <= percentage;
|
|
|
|
}
|
2016-11-19 23:23:37 +00:00
|
|
|
|
2016-04-14 16:24:03 +00:00
|
|
|
public boolean isClearLagInstalled() {
|
|
|
|
return clearlag;
|
|
|
|
}
|
|
|
|
|
2016-11-19 23:23:37 +00:00
|
|
|
public boolean isExoticGardenInstalled () {
|
|
|
|
return exoticGarden;
|
|
|
|
}
|
2017-02-06 18:28:06 +00:00
|
|
|
|
|
|
|
public boolean isCoreProtectInstalled() {
|
|
|
|
return coreProtect;
|
|
|
|
}
|
|
|
|
|
|
|
|
public CoreProtectAPI getCoreProtectAPI() {
|
|
|
|
return coreProtectAPI;
|
|
|
|
}
|
2016-04-14 16:24:03 +00:00
|
|
|
}
|