Search in sources :

Example 1 with ArmorTask

use of io.github.thebusybiscuit.slimefun4.implementation.tasks.ArmorTask in project Slimefun4 by Slimefun.

the class Slimefun method onPluginStart.

/**
 * This is our start method for a correct Slimefun installation.
 */
private void onPluginStart() {
    long timestamp = System.nanoTime();
    Logger logger = getLogger();
    // Check if Paper (<3) is installed
    if (PaperLib.isPaper()) {
        logger.log(Level.INFO, "Paper was detected! Performance optimizations have been applied.");
    } else {
        PaperLib.suggestPaper(this);
    }
    // Check if CS-CoreLib is installed (it is no longer needed)
    if (getServer().getPluginManager().getPlugin("CS-CoreLib") != null) {
        StartupWarnings.discourageCSCoreLib(logger);
    }
    // Encourage newer Java version
    if (NumberUtils.getJavaVersion() < RECOMMENDED_JAVA_VERSION) {
        StartupWarnings.oldJavaVersion(logger, RECOMMENDED_JAVA_VERSION);
    }
    // If the server has no "data-storage" folder, it's _probably_ a new install. So mark it for metrics.
    isNewlyInstalled = !new File("data-storage/Slimefun").exists();
    // Creating all necessary Folders
    logger.log(Level.INFO, "Creating directories...");
    createDirectories();
    // Load various config settings into our cache
    registry.load(this, config);
    // Set up localization
    logger.log(Level.INFO, "Loading language files...");
    String chatPrefix = config.getString("options.chat-prefix");
    String serverDefaultLanguage = config.getString("options.language");
    local = new LocalizationService(this, chatPrefix, serverDefaultLanguage);
    int networkSize = config.getInt("networks.max-size");
    // Make sure that the network size is a valid input
    if (networkSize < 1) {
        logger.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, config.getBoolean("networks.enable-visualizer"), config.getBoolean("networks.delete-excess-items"));
    // Setting up bStats
    new Thread(metricsService::start, "Slimefun Metrics").start();
    // Starting the Auto-Updater
    if (config.getBoolean("options.auto-update")) {
        logger.log(Level.INFO, "Starting Auto-Updater...");
        updaterService.start();
    } else {
        updaterService.disable();
    }
    // Registering all GEO Resources
    logger.log(Level.INFO, "Loading GEO-Resources...");
    GEOResourcesSetup.setup();
    logger.log(Level.INFO, "Loading Tags...");
    loadTags();
    logger.log(Level.INFO, "Loading items...");
    loadItems();
    logger.log(Level.INFO, "Loading researches...");
    loadResearches();
    registry.setResearchingEnabled(getResearchCfg().getBoolean("enable-researching"));
    PostSetup.setupWiki();
    logger.log(Level.INFO, "Registering listeners...");
    registerListeners();
    // Initiating various Stuff and all items with a slight delay (0ms after the Server finished loading)
    runSync(new SlimefunStartupTask(this, () -> {
        textureService.register(registry.getAllSlimefunItems(), true);
        permissionsService.register(registry.getAllSlimefunItems(), true);
        // This try/catch should prevent buggy Spigot builds from blocking item loading
        try {
            recipeService.refresh();
        } catch (Exception | LinkageError x) {
            logger.log(Level.SEVERE, x, () -> "An Exception occurred while iterating through the Recipe list on Minecraft Version " + minecraftVersion.getName() + " (Slimefun v" + getVersion() + ")");
        }
    }), 0);
    // Setting up our commands
    try {
        command.register();
    } catch (Exception | LinkageError x) {
        logger.log(Level.SEVERE, "An Exception occurred while registering the /slimefun command", x);
    }
    // Armor Update Task
    if (config.getBoolean("options.enable-armor-effects")) {
        boolean radioactiveFire = config.getBoolean("options.burn-players-when-radioactive");
        getServer().getScheduler().runTaskTimerAsynchronously(this, new ArmorTask(radioactiveFire), 0L, config.getInt("options.armor-update-interval") * 20L);
    }
    // Starting our tasks
    autoSavingService.start(this, config.getInt("options.auto-save-delay-in-minutes"));
    hologramsService.start();
    ticker.start(this);
    // Loading integrations
    logger.log(Level.INFO, "Loading Third-Party plugin integrations...");
    integrations.start();
    gitHubService.start(this);
    // Hooray!
    logger.log(Level.INFO, "Slimefun has finished loading in {0}", getStartupTime(timestamp));
}
Also used : ArmorTask(io.github.thebusybiscuit.slimefun4.implementation.tasks.ArmorTask) LocalizationService(io.github.thebusybiscuit.slimefun4.core.services.LocalizationService) SlimefunStartupTask(io.github.thebusybiscuit.slimefun4.implementation.tasks.SlimefunStartupTask) Logger(java.util.logging.Logger) TagMisconfigurationException(io.github.thebusybiscuit.slimefun4.api.exceptions.TagMisconfigurationException) NetworkManager(io.github.thebusybiscuit.slimefun4.core.networks.NetworkManager) File(java.io.File) PluginDescriptionFile(org.bukkit.plugin.PluginDescriptionFile)

Example 2 with ArmorTask

use of io.github.thebusybiscuit.slimefun4.implementation.tasks.ArmorTask in project Slimefun4 by Slimefun.

the class TestArmorTask method testSlimefunArmor.

@Test
@DisplayName("Test Slimefun Armor Effects")
void testSlimefunArmor() throws InterruptedException {
    Player player = server.addPlayer();
    TestUtilities.awaitProfile(player);
    // Setting the time to noon, to exclude the Solar Helmet check
    player.getWorld().setTime(16000);
    PotionEffect[] effects = { new PotionEffect(PotionEffectType.SPEED, 50, 3), new PotionEffect(PotionEffectType.SATURATION, 128, 12) };
    SlimefunItemStack helmet = new SlimefunItemStack("HELMET_FLEX", Material.IRON_HELMET, "&bSuper cool Helmet");
    SlimefunArmorPiece armor = new SlimefunArmorPiece(TestUtilities.getItemGroup(plugin, "armor_test"), helmet, RecipeType.NULL, new ItemStack[9], effects);
    armor.register(plugin);
    player.getInventory().setHelmet(helmet.clone());
    player.getInventory().setChestplate(new ItemStack(Material.DIAMOND_CHESTPLATE));
    new ArmorTask(false).run();
    // Check if all Potion Effects were applied
    Assertions.assertTrue(player.getActivePotionEffects().containsAll(Arrays.asList(effects)));
}
Also used : Player(org.bukkit.entity.Player) SlimefunArmorPiece(io.github.thebusybiscuit.slimefun4.implementation.items.armor.SlimefunArmorPiece) PotionEffect(org.bukkit.potion.PotionEffect) ItemStack(org.bukkit.inventory.ItemStack) SlimefunItemStack(io.github.thebusybiscuit.slimefun4.api.items.SlimefunItemStack) SlimefunItemStack(io.github.thebusybiscuit.slimefun4.api.items.SlimefunItemStack) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) DisplayName(org.junit.jupiter.api.DisplayName)

Example 3 with ArmorTask

use of io.github.thebusybiscuit.slimefun4.implementation.tasks.ArmorTask in project Slimefun4 by Slimefun.

the class TestArmorTask method testRadiactivity.

@ParameterizedTest
@DisplayName("Test Radiation and Hazmat Suits")
@MethodSource("cartesianBooleans")
void testRadiactivity(boolean hazmat, boolean radioactiveFire) throws InterruptedException {
    Player player = server.addPlayer();
    TestUtilities.awaitProfile(player);
    // Setting the time to noon, to exclude the Solar Helmet check
    player.getWorld().setTime(16000);
    ItemGroup itemGroup = TestUtilities.getItemGroup(plugin, "hazmat_suit_test");
    SlimefunItemStack item = new SlimefunItemStack("MOCK_URANIUM_" + String.valueOf(hazmat).toUpperCase(Locale.ROOT) + "_" + String.valueOf(radioactiveFire).toUpperCase(Locale.ROOT), Material.EMERALD, "&aHi, I am deadly");
    new RadioactiveItem(itemGroup, Radioactivity.VERY_DEADLY, item, RecipeType.NULL, new ItemStack[9]).register(plugin);
    player.getInventory().setItemInMainHand(item.clone());
    player.getInventory().setItemInOffHand(new ItemStack(Material.EMERALD_ORE));
    if (hazmat) {
        SlimefunItemStack chestplate = new SlimefunItemStack("MOCK_HAZMAT_SUIT_" + String.valueOf(radioactiveFire).toUpperCase(Locale.ROOT), Material.LEATHER_CHESTPLATE, "&4Hazmat Prototype");
        MockHazmatSuit armor = new MockHazmatSuit(itemGroup, chestplate);
        armor.register(plugin);
        player.getInventory().setChestplate(chestplate.clone());
    }
    ArmorTask task = new ArmorTask(radioactiveFire);
    task.run();
    // Check if the Player is suffering from radiation
    boolean radiation = player.getActivePotionEffects().containsAll(task.getRadiationEffects());
    Assertions.assertEquals(!hazmat, radiation);
    Assertions.assertEquals(!hazmat && radioactiveFire, player.getFireTicks() > 0);
}
Also used : RadioactiveItem(io.github.thebusybiscuit.slimefun4.implementation.items.RadioactiveItem) Player(org.bukkit.entity.Player) ItemGroup(io.github.thebusybiscuit.slimefun4.api.items.ItemGroup) ItemStack(org.bukkit.inventory.ItemStack) SlimefunItemStack(io.github.thebusybiscuit.slimefun4.api.items.SlimefunItemStack) MockHazmatSuit(io.github.thebusybiscuit.slimefun4.test.mocks.MockHazmatSuit) SlimefunItemStack(io.github.thebusybiscuit.slimefun4.api.items.SlimefunItemStack) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) DisplayName(org.junit.jupiter.api.DisplayName) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Aggregations

SlimefunItemStack (io.github.thebusybiscuit.slimefun4.api.items.SlimefunItemStack)2 Player (org.bukkit.entity.Player)2 ItemStack (org.bukkit.inventory.ItemStack)2 DisplayName (org.junit.jupiter.api.DisplayName)2 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)2 TagMisconfigurationException (io.github.thebusybiscuit.slimefun4.api.exceptions.TagMisconfigurationException)1 ItemGroup (io.github.thebusybiscuit.slimefun4.api.items.ItemGroup)1 NetworkManager (io.github.thebusybiscuit.slimefun4.core.networks.NetworkManager)1 LocalizationService (io.github.thebusybiscuit.slimefun4.core.services.LocalizationService)1 RadioactiveItem (io.github.thebusybiscuit.slimefun4.implementation.items.RadioactiveItem)1 SlimefunArmorPiece (io.github.thebusybiscuit.slimefun4.implementation.items.armor.SlimefunArmorPiece)1 ArmorTask (io.github.thebusybiscuit.slimefun4.implementation.tasks.ArmorTask)1 SlimefunStartupTask (io.github.thebusybiscuit.slimefun4.implementation.tasks.SlimefunStartupTask)1 MockHazmatSuit (io.github.thebusybiscuit.slimefun4.test.mocks.MockHazmatSuit)1 File (java.io.File)1 Logger (java.util.logging.Logger)1 PluginDescriptionFile (org.bukkit.plugin.PluginDescriptionFile)1 PotionEffect (org.bukkit.potion.PotionEffect)1 Test (org.junit.jupiter.api.Test)1 MethodSource (org.junit.jupiter.params.provider.MethodSource)1