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));
}
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)));
}
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);
}
Aggregations