Search in sources :

Example 1 with SlimefunGuideMode

use of io.github.thebusybiscuit.slimefun4.core.guide.SlimefunGuideMode in project Slimefun4 by Slimefun.

the class GuideModeOption method onClick.

@Override
public void onClick(@Nonnull Player p, @Nonnull ItemStack guide) {
    Optional<SlimefunGuideMode> current = getSelectedOption(p, guide);
    if (current.isPresent()) {
        SlimefunGuideMode next = getNextMode(p, current.get());
        setSelectedOption(p, guide, next);
    }
    SlimefunGuideSettings.openSettings(p, guide);
}
Also used : SlimefunGuideMode(io.github.thebusybiscuit.slimefun4.core.guide.SlimefunGuideMode)

Example 2 with SlimefunGuideMode

use of io.github.thebusybiscuit.slimefun4.core.guide.SlimefunGuideMode in project Slimefun4 by Slimefun.

the class GuideModeOption method getDisplayItem.

@Nonnull
@Override
public Optional<ItemStack> getDisplayItem(Player p, ItemStack guide) {
    if (!p.hasPermission("slimefun.cheat.items")) {
        // Only Players with the appropriate permission can access the cheat sheet
        return Optional.empty();
    }
    Optional<SlimefunGuideMode> current = getSelectedOption(p, guide);
    if (current.isPresent()) {
        SlimefunGuideMode selectedMode = current.get();
        ItemStack item = new ItemStack(Material.AIR);
        if (selectedMode == SlimefunGuideMode.SURVIVAL_MODE) {
            item.setType(Material.CHEST);
        } else {
            item.setType(Material.COMMAND_BLOCK);
        }
        ItemMeta meta = item.getItemMeta();
        meta.setDisplayName(ChatColor.GRAY + "Slimefun Guide Type: " + ChatColor.YELLOW + ChatUtils.humanize(selectedMode.name()));
        List<String> lore = new ArrayList<>();
        lore.add("");
        lore.add((selectedMode == SlimefunGuideMode.SURVIVAL_MODE ? ChatColor.GREEN : ChatColor.GRAY) + "Survival Mode");
        lore.add((selectedMode == SlimefunGuideMode.CHEAT_MODE ? ChatColor.GREEN : ChatColor.GRAY) + "Cheat Sheet");
        lore.add("");
        lore.add(ChatColor.GRAY + "\u21E8 " + ChatColor.YELLOW + "Click to change the type");
        meta.setLore(lore);
        item.setItemMeta(meta);
        return Optional.of(item);
    }
    return Optional.empty();
}
Also used : ArrayList(java.util.ArrayList) SlimefunGuideMode(io.github.thebusybiscuit.slimefun4.core.guide.SlimefunGuideMode) ItemStack(org.bukkit.inventory.ItemStack) ItemMeta(org.bukkit.inventory.meta.ItemMeta) Nonnull(javax.annotation.Nonnull)

Example 3 with SlimefunGuideMode

use of io.github.thebusybiscuit.slimefun4.core.guide.SlimefunGuideMode in project Slimefun4 by Slimefun.

the class SlimefunRegistry method getSlimefunGuide.

/**
 * This returns the corresponding {@link SlimefunGuideImplementation} for a certain
 * {@link SlimefunGuideMode}.
 * <p>
 * This mainly only exists for internal purposes, if you want to open a certain section
 * using the {@link SlimefunGuide}, then please use the static methods provided in the
 * {@link SlimefunGuide} class.
 *
 * @param mode
 *            The {@link SlimefunGuideMode}
 *
 * @return The corresponding {@link SlimefunGuideImplementation}
 */
@Nonnull
public SlimefunGuideImplementation getSlimefunGuide(@Nonnull SlimefunGuideMode mode) {
    Validate.notNull(mode, "The Guide mode cannot be null");
    SlimefunGuideImplementation guide = guides.get(mode);
    if (guide == null) {
        throw new IllegalStateException("Slimefun Guide '" + mode + "' has no registered implementation.");
    }
    return guide;
}
Also used : SlimefunGuideImplementation(io.github.thebusybiscuit.slimefun4.core.guide.SlimefunGuideImplementation) Nonnull(javax.annotation.Nonnull)

Example 4 with SlimefunGuideMode

use of io.github.thebusybiscuit.slimefun4.core.guide.SlimefunGuideMode in project Slimefun4 by Slimefun.

the class GuideCommand method onExecute.

@Override
public void onExecute(CommandSender sender, String[] args) {
    if (sender instanceof Player) {
        if (sender.hasPermission("slimefun.command.guide")) {
            SlimefunGuideMode design = SlimefunGuide.getDefaultMode();
            ((Player) sender).getInventory().addItem(SlimefunGuide.getItem(design).clone());
        } else {
            Slimefun.getLocalization().sendMessage(sender, "messages.no-permission", true);
        }
    } else {
        Slimefun.getLocalization().sendMessage(sender, "messages.only-players", true);
    }
}
Also used : Player(org.bukkit.entity.Player) SlimefunGuideMode(io.github.thebusybiscuit.slimefun4.core.guide.SlimefunGuideMode)

Example 5 with SlimefunGuideMode

use of io.github.thebusybiscuit.slimefun4.core.guide.SlimefunGuideMode in project Slimefun4 by Slimefun.

the class SlimefunGuideListener method openGuide.

@ParametersAreNonnullByDefault
private void openGuide(Player p, PlayerRightClickEvent e, SlimefunGuideMode layout) {
    SlimefunGuideOpenEvent event = new SlimefunGuideOpenEvent(p, e.getItem(), layout);
    Bukkit.getPluginManager().callEvent(event);
    if (!event.isCancelled()) {
        e.cancel();
        SlimefunGuide.openGuide(p, event.getGuideLayout());
    }
}
Also used : SlimefunGuideOpenEvent(io.github.thebusybiscuit.slimefun4.api.events.SlimefunGuideOpenEvent) ParametersAreNonnullByDefault(javax.annotation.ParametersAreNonnullByDefault)

Aggregations

SlimefunGuideMode (io.github.thebusybiscuit.slimefun4.core.guide.SlimefunGuideMode)5 Player (org.bukkit.entity.Player)3 CustomItemStack (io.github.bakedlibs.dough.items.CustomItemStack)2 PlayerProfile (io.github.thebusybiscuit.slimefun4.api.player.PlayerProfile)2 Nonnull (javax.annotation.Nonnull)2 ParametersAreNonnullByDefault (javax.annotation.ParametersAreNonnullByDefault)2 SlimefunGuideOpenEvent (io.github.thebusybiscuit.slimefun4.api.events.SlimefunGuideOpenEvent)1 FlexItemGroup (io.github.thebusybiscuit.slimefun4.api.items.groups.FlexItemGroup)1 GuideHistory (io.github.thebusybiscuit.slimefun4.core.guide.GuideHistory)1 SlimefunGuideImplementation (io.github.thebusybiscuit.slimefun4.core.guide.SlimefunGuideImplementation)1 SurvivalSlimefunGuide (io.github.thebusybiscuit.slimefun4.implementation.guide.SurvivalSlimefunGuide)1 ArrayList (java.util.ArrayList)1 ChestMenu (me.mrCookieSlime.CSCoreLibPlugin.general.Inventory.ChestMenu)1 NamespacedKey (org.bukkit.NamespacedKey)1 EventHandler (org.bukkit.event.EventHandler)1 ItemStack (org.bukkit.inventory.ItemStack)1 ItemMeta (org.bukkit.inventory.meta.ItemMeta)1 DisplayName (org.junit.jupiter.api.DisplayName)1 Test (org.junit.jupiter.api.Test)1