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