Search in sources :

Example 31 with Slimefun

use of io.github.thebusybiscuit.slimefun4.implementation.Slimefun in project FluffyMachines by NCBPFluffyBear.

the class FluffyMachines method onEnable.

@SneakyThrows
@Override
public void onEnable() {
    instance = this;
    // Read something from your config.yml
    Config cfg = new Config(this);
    if (cfg.getBoolean("options.auto-update") && getDescription().getVersion().startsWith("DEV - ")) {
        new GitHubBuildsUpdater(this, getFile(), "NCBPFluffyBear/FluffyMachines/master/").start();
    }
    try {
        if (!Enchantment.isAcceptingRegistrations()) {
            Field accepting = Enchantment.class.getDeclaredField("acceptingNew");
            accepting.setAccessible(true);
            accepting.set(null, true);
        }
    } catch (IllegalAccessException | NoSuchFieldException ignored) {
        getLogger().warning("Failed to register enchantment.");
    }
    registerGlow();
    // Register ACT Recipes
    Iterator<Recipe> recipeIterator = Bukkit.recipeIterator();
    while (recipeIterator.hasNext()) {
        Recipe r = recipeIterator.next();
        if (r instanceof ShapedRecipe) {
            ShapedRecipe sr = (ShapedRecipe) r;
            List<RecipeChoice> rc = new ArrayList<>();
            ItemStack key = new ItemStack(sr.getResult().getType(), 1);
            // Convert the recipe to a list
            for (Map.Entry<Character, RecipeChoice> choice : sr.getChoiceMap().entrySet()) {
                if (choice.getValue() != null) {
                    rc.add(choice.getValue());
                }
            }
            if (!shapedVanillaRecipes.containsKey(key)) {
                shapedVanillaRecipes.put(key, new ArrayList<>(Collections.singletonList(new Pair<>(sr.getResult(), rc))));
            } else {
                shapedVanillaRecipes.get(key).add(new Pair<>(sr.getResult(), rc));
            }
        } else if (r instanceof ShapelessRecipe) {
            ShapelessRecipe slr = (ShapelessRecipe) r;
            ItemStack key = new ItemStack(slr.getResult().getType(), 1);
            // Key has a list of recipe options
            if (!shapelessVanillaRecipes.containsKey(key)) {
                shapelessVanillaRecipes.put(key, new ArrayList<>(Collections.singletonList(new Pair<>(slr.getResult(), slr.getChoiceList()))));
            } else {
                shapelessVanillaRecipes.get(key).add(new Pair<>(slr.getResult(), slr.getChoiceList()));
            }
        }
    }
    // Register McMMO Events
    if (getServer().getPluginManager().isPluginEnabled("McMMO")) {
        Bukkit.getLogger().log(Level.INFO, "McMMO found!");
        getServer().getPluginManager().registerEvents(new McMMOEvents(), this);
    }
    // Registering Items
    FluffyItemSetup.setup(this);
    // Register Events Class
    getServer().getPluginManager().registerEvents(new Events(), this);
    final Metrics metrics = new Metrics(this, 8927);
    getLogger().log(Level.INFO, ChatColor.GREEN + "Hi there! Want to share your server with the " + "Slimefun community?");
    getLogger().log(Level.INFO, ChatColor.GREEN + "Join the official Slimefun Discord server at " + "https://discord.gg/slimefun");
}
Also used : ShapelessRecipe(org.bukkit.inventory.ShapelessRecipe) ShapedRecipe(org.bukkit.inventory.ShapedRecipe) Recipe(org.bukkit.inventory.Recipe) Config(io.github.thebusybiscuit.slimefun4.libraries.dough.config.Config) GitHubBuildsUpdater(io.github.thebusybiscuit.slimefun4.libraries.dough.updater.GitHubBuildsUpdater) ShapedRecipe(org.bukkit.inventory.ShapedRecipe) ArrayList(java.util.ArrayList) McMMOEvents(io.ncbpfluffybear.fluffymachines.utils.McMMOEvents) Field(java.lang.reflect.Field) Metrics(org.bstats.bukkit.Metrics) Events(io.ncbpfluffybear.fluffymachines.utils.Events) McMMOEvents(io.ncbpfluffybear.fluffymachines.utils.McMMOEvents) ShapelessRecipe(org.bukkit.inventory.ShapelessRecipe) RecipeChoice(org.bukkit.inventory.RecipeChoice) ItemStack(org.bukkit.inventory.ItemStack) HashMap(java.util.HashMap) Map(java.util.Map) Pair(io.github.thebusybiscuit.slimefun4.libraries.dough.collections.Pair) SneakyThrows(lombok.SneakyThrows)

Example 32 with Slimefun

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

the class ArmorTask method checkForSolarHelmet.

private void checkForSolarHelmet(@Nonnull Player p) {
    ItemStack helmet = p.getInventory().getHelmet();
    if (Slimefun.getRegistry().isBackwardsCompatible() && !SlimefunUtils.isItemSimilar(helmet, SlimefunItems.SOLAR_HELMET, true, false)) {
        // Performance saver for slow backwards-compatible versions of Slimefun
        return;
    }
    SlimefunItem item = SlimefunItem.getByItem(helmet);
    if (item instanceof SolarHelmet && item.canUse(p, true)) {
        ((SolarHelmet) item).rechargeItems(p);
    }
}
Also used : SolarHelmet(io.github.thebusybiscuit.slimefun4.implementation.items.electric.gadgets.SolarHelmet) SlimefunItem(io.github.thebusybiscuit.slimefun4.api.items.SlimefunItem) ItemStack(org.bukkit.inventory.ItemStack) SlimefunItemStack(io.github.thebusybiscuit.slimefun4.api.items.SlimefunItemStack)

Example 33 with Slimefun

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

the class SlimefunStartupTask method run.

@Override
public void run() {
    runnable.run();
    // Load all items
    PostSetup.loadItems();
    // Load all worlds
    Slimefun.getWorldSettingsService().load(Bukkit.getWorlds());
    for (World world : Bukkit.getWorlds()) {
        try {
            new BlockStorage(world);
        } catch (Exception x) {
            Slimefun.logger().log(Level.SEVERE, x, () -> "An Error occurred while trying to load World \"" + world.getName() + "\" for Slimefun v" + Slimefun.getVersion());
        }
    }
    // Load/Unload Worlds, only after all plugins have started up. Fixes #2862
    new WorldListener(this.plugin);
    // Only load this Listener if the corresponding items are enabled
    if (isEnabled("ELEVATOR_PLATE", "GPS_ACTIVATION_DEVICE_SHARED", "GPS_ACTIVATION_DEVICE_PERSONAL")) {
        new TeleporterListener(plugin);
    }
}
Also used : TeleporterListener(io.github.thebusybiscuit.slimefun4.implementation.listeners.TeleporterListener) BlockStorage(me.mrCookieSlime.Slimefun.api.BlockStorage) WorldListener(io.github.thebusybiscuit.slimefun4.implementation.listeners.WorldListener) World(org.bukkit.World)

Example 34 with Slimefun

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

the class PostSetup method loadItems.

public static void loadItems() {
    Iterator<SlimefunItem> iterator = Slimefun.getRegistry().getEnabledSlimefunItems().iterator();
    while (iterator.hasNext()) {
        SlimefunItem item = iterator.next();
        if (item == null) {
            Slimefun.logger().log(Level.WARNING, "Removed bugged Item ('NULL?')");
            iterator.remove();
        } else {
            try {
                item.load();
            } catch (Exception | LinkageError x) {
                item.error("Failed to properly load this Item", x);
            }
        }
    }
    loadOreGrinderRecipes();
    loadSmelteryRecipes();
    CommandSender sender = Bukkit.getConsoleSender();
    int total = Slimefun.getRegistry().getEnabledSlimefunItems().size();
    int slimefunOnly = countNonAddonItems();
    sender.sendMessage("");
    sender.sendMessage(ChatColor.GREEN + "######################### - Slimefun v" + Slimefun.getVersion() + " - #########################");
    sender.sendMessage("");
    sender.sendMessage(ChatColor.GREEN + "Successfully loaded " + total + " Items and " + Slimefun.getRegistry().getResearches().size() + " Researches");
    sender.sendMessage(ChatColor.GREEN + "( " + slimefunOnly + " Items from Slimefun, " + (total - slimefunOnly) + " Items from " + Slimefun.getInstalledAddons().size() + " Addons )");
    sender.sendMessage("");
    sender.sendMessage(ChatColor.GREEN + "Slimefun is an Open-Source project that is kept alive by a large community.");
    sender.sendMessage(ChatColor.GREEN + "Consider helping us maintain this project by contributing on GitHub!");
    if (Slimefun.getUpdater().getBranch().isOfficial()) {
        sender.sendMessage("");
        sender.sendMessage(ChatColor.GREEN + " - Source Code:  https://github.com/Slimefun/Slimefun4");
        sender.sendMessage(ChatColor.GREEN + " - Wiki:         https://github.com/Slimefun/Slimefun4/wiki");
        sender.sendMessage(ChatColor.GREEN + " - Addons:       https://github.com/Slimefun/Slimefun4/wiki/Addons");
        sender.sendMessage(ChatColor.GREEN + " - Bug Reports:  https://github.com/Slimefun/Slimefun4/issues");
        sender.sendMessage(ChatColor.GREEN + " - Discord:      https://discord.gg/slimefun");
    } else {
        sender.sendMessage(ChatColor.GREEN + " - UNOFFICIALLY MODIFIED BUILD - NO OFFICIAL SUPPORT GIVEN");
    }
    sender.sendMessage("");
    Slimefun.getItemCfg().save();
    Slimefun.getResearchCfg().save();
    Slimefun.getRegistry().setAutoLoadingMode(true);
}
Also used : CommandSender(org.bukkit.command.CommandSender) SlimefunItem(io.github.thebusybiscuit.slimefun4.api.items.SlimefunItem) IOException(java.io.IOException)

Example 35 with Slimefun

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

the class SlimefunGuideSettings method addHeader.

@ParametersAreNonnullByDefault
private static void addHeader(Player p, ChestMenu menu, ItemStack guide) {
    LocalizationService locale = Slimefun.getLocalization();
    // @formatter:off
    menu.addItem(0, new CustomItemStack(SlimefunGuide.getItem(SlimefunGuideMode.SURVIVAL_MODE), "&e\u21E6 " + locale.getMessage(p, "guide.back.title"), "", "&7" + locale.getMessage(p, "guide.back.guide")));
    // @formatter:on
    menu.addMenuClickHandler(0, (pl, slot, item, action) -> {
        SlimefunGuide.openGuide(pl, guide);
        return false;
    });
    GitHubService github = Slimefun.getGitHubService();
    List<String> contributorsLore = new ArrayList<>();
    contributorsLore.add("");
    contributorsLore.addAll(locale.getMessages(p, "guide.credits.description", msg -> msg.replace("%contributors%", String.valueOf(github.getContributors().size()))));
    contributorsLore.add("");
    contributorsLore.add("&7\u21E8 &e" + locale.getMessage(p, "guide.credits.open"));
    // @formatter:off
    menu.addItem(2, new CustomItemStack(SlimefunUtils.getCustomHead("e952d2b3f351a6b0487cc59db31bf5f2641133e5ba0006b18576e996a0293e52"), "&c" + locale.getMessage(p, "guide.title.credits"), contributorsLore.toArray(new String[0])));
    // @formatter:on
    menu.addMenuClickHandler(2, (pl, slot, action, item) -> {
        ContributorsMenu.open(pl, 0);
        return false;
    });
    // @formatter:off
    menu.addItem(4, new CustomItemStack(Material.WRITABLE_BOOK, ChatColor.GREEN + locale.getMessage(p, "guide.title.versions"), "&7&o" + locale.getMessage(p, "guide.tooltips.versions-notice"), "", "&fMinecraft: &a" + Bukkit.getBukkitVersion(), "&fSlimefun: &a" + Slimefun.getVersion()), ChestMenuUtils.getEmptyClickHandler());
    // @formatter:on
    // @formatter:off
    menu.addItem(6, new CustomItemStack(Material.COMPARATOR, "&e" + locale.getMessage(p, "guide.title.source"), "", "&7Last Activity: &a" + NumberUtils.getElapsedTime(github.getLastUpdate()) + " ago", "&7Forks: &e" + github.getForks(), "&7Stars: &e" + github.getStars(), "", "&7&oSlimefun 4 is a community project,", "&7&othe source code is available on GitHub", "&7&oand if you want to keep this Plugin alive,", "&7&othen please consider contributing to it", "", "&7\u21E8 &eClick to go to GitHub"));
    // @formatter:on
    menu.addMenuClickHandler(6, (pl, slot, item, action) -> {
        pl.closeInventory();
        ChatUtils.sendURL(pl, "https://github.com/Slimefun/Slimefun4");
        return false;
    });
    // @formatter:off
    menu.addItem(8, new CustomItemStack(Material.KNOWLEDGE_BOOK, "&3" + locale.getMessage(p, "guide.title.wiki"), "", "&7Do you need help with an Item or machine?", "&7You cannot figure out what to do?", "&7Check out our community-maintained Wiki", "&7and become one of our Editors!", "", "&7\u21E8 &eClick to go to the official Slimefun Wiki"));
    // @formatter:on
    menu.addMenuClickHandler(8, (pl, slot, item, action) -> {
        pl.closeInventory();
        ChatUtils.sendURL(pl, "https://github.com/Slimefun/Slimefun4/wiki");
        return false;
    });
    // @formatter:off
    menu.addItem(47, new CustomItemStack(Material.BOOKSHELF, "&3" + locale.getMessage(p, "guide.title.addons"), "", "&7Slimefun is huge. But its addons are what makes", "&7this plugin truly shine. Go check them out, some", "&7of them may be exactly what you were missing out on!", "", "&7Installed on this Server: &b" + Slimefun.getInstalledAddons().size(), "", "&7\u21E8 &eClick to see all available addons for Slimefun4"));
    // @formatter:on
    menu.addMenuClickHandler(47, (pl, slot, item, action) -> {
        pl.closeInventory();
        ChatUtils.sendURL(pl, "https://github.com/Slimefun/Slimefun4/wiki/Addons");
        return false;
    });
    if (Slimefun.getUpdater().getBranch().isOfficial()) {
        // @formatter:off
        menu.addItem(49, new CustomItemStack(Material.REDSTONE_TORCH, "&4" + locale.getMessage(p, "guide.title.bugs"), "", "&7&oBug reports have to be made in English!", "", "&7Open Issues: &a" + github.getOpenIssues(), "&7Pending Pull Requests: &a" + github.getPendingPullRequests(), "", "&7\u21E8 &eClick to go to the Slimefun4 Bug Tracker"));
        // @formatter:on
        menu.addMenuClickHandler(49, (pl, slot, item, action) -> {
            pl.closeInventory();
            ChatUtils.sendURL(pl, "https://github.com/Slimefun/Slimefun4/issues");
            return false;
        });
    } else {
        menu.addItem(49, ChestMenuUtils.getBackground(), ChestMenuUtils.getEmptyClickHandler());
    }
    menu.addItem(51, new CustomItemStack(Material.TOTEM_OF_UNDYING, ChatColor.RED + locale.getMessage(p, "guide.work-in-progress")), (pl, slot, item, action) -> {
        // Add something here
        return false;
    });
}
Also used : GitHubService(io.github.thebusybiscuit.slimefun4.core.services.github.GitHubService) NumberUtils(io.github.thebusybiscuit.slimefun4.utils.NumberUtils) SlimefunUtils(io.github.thebusybiscuit.slimefun4.utils.SlimefunUtils) ChestMenuUtils(io.github.thebusybiscuit.slimefun4.utils.ChestMenuUtils) GitHubService(io.github.thebusybiscuit.slimefun4.core.services.github.GitHubService) Sound(org.bukkit.Sound) Player(org.bukkit.entity.Player) Research(io.github.thebusybiscuit.slimefun4.api.researches.Research) ParametersAreNonnullByDefault(javax.annotation.ParametersAreNonnullByDefault) ChatUtils(io.github.thebusybiscuit.slimefun4.utils.ChatUtils) ArrayList(java.util.ArrayList) ItemStack(org.bukkit.inventory.ItemStack) List(java.util.List) Language(io.github.thebusybiscuit.slimefun4.core.services.localization.Language) LocalizationService(io.github.thebusybiscuit.slimefun4.core.services.LocalizationService) Slimefun(io.github.thebusybiscuit.slimefun4.implementation.Slimefun) SlimefunGuideMode(io.github.thebusybiscuit.slimefun4.core.guide.SlimefunGuideMode) Optional(java.util.Optional) ChestMenu(me.mrCookieSlime.CSCoreLibPlugin.general.Inventory.ChestMenu) ChatColor(org.bukkit.ChatColor) SlimefunGuide(io.github.thebusybiscuit.slimefun4.core.guide.SlimefunGuide) Nonnull(javax.annotation.Nonnull) CustomItemStack(io.github.bakedlibs.dough.items.CustomItemStack) Material(org.bukkit.Material) Bukkit(org.bukkit.Bukkit) LocalizationService(io.github.thebusybiscuit.slimefun4.core.services.LocalizationService) CustomItemStack(io.github.bakedlibs.dough.items.CustomItemStack) ArrayList(java.util.ArrayList) ParametersAreNonnullByDefault(javax.annotation.ParametersAreNonnullByDefault)

Aggregations

SlimefunItemStack (io.github.thebusybiscuit.slimefun4.api.items.SlimefunItemStack)17 SlimefunItem (io.github.thebusybiscuit.slimefun4.api.items.SlimefunItem)16 ItemStack (org.bukkit.inventory.ItemStack)14 DisplayName (org.junit.jupiter.api.DisplayName)14 Test (org.junit.jupiter.api.Test)14 Player (org.bukkit.entity.Player)12 CustomItemStack (io.github.bakedlibs.dough.items.CustomItemStack)10 Slimefun (io.github.thebusybiscuit.slimefun4.implementation.Slimefun)8 ParametersAreNonnullByDefault (javax.annotation.ParametersAreNonnullByDefault)7 NamespacedKey (org.bukkit.NamespacedKey)7 PlayerProfile (io.github.thebusybiscuit.slimefun4.api.player.PlayerProfile)6 ArrayList (java.util.ArrayList)6 Nonnull (javax.annotation.Nonnull)6 BeforeAll (org.junit.jupiter.api.BeforeAll)4 TagMisconfigurationException (io.github.thebusybiscuit.slimefun4.api.exceptions.TagMisconfigurationException)3 ItemGroup (io.github.thebusybiscuit.slimefun4.api.items.ItemGroup)3 Block (org.bukkit.block.Block)3 ItemMeta (org.bukkit.inventory.meta.ItemMeta)3 PotionEffect (org.bukkit.potion.PotionEffect)3 AndroidMineEvent (io.github.thebusybiscuit.slimefun4.api.events.AndroidMineEvent)2