Search in sources :

Example 16 with ChestMenu

use of me.mrCookieSlime.CSCoreLibPlugin.general.Inventory.ChestMenu in project Slimefun4 by Slimefun.

the class HologramProjector method openEditor.

private static void openEditor(@Nonnull Player p, @Nonnull Block projector) {
    ChestMenu menu = new ChestMenu(Slimefun.getLocalization().getMessage(p, "machines.HOLOGRAM_PROJECTOR.inventory-title"));
    menu.addItem(0, new CustomItemStack(Material.NAME_TAG, "&7Text &e(Click to edit)", "", "&r" + ChatColors.color(BlockStorage.getLocationInfo(projector.getLocation(), "text"))));
    menu.addMenuClickHandler(0, (pl, slot, item, action) -> {
        pl.closeInventory();
        Slimefun.getLocalization().sendMessage(pl, "machines.HOLOGRAM_PROJECTOR.enter-text", true);
        ChatUtils.awaitInput(pl, message -> {
            ArmorStand hologram = getArmorStand(projector, true);
            hologram.setCustomName(ChatColors.color(message));
            BlockStorage.addBlockInfo(projector, "text", hologram.getCustomName());
            openEditor(pl, projector);
        });
        return false;
    });
    menu.addItem(1, new CustomItemStack(Material.CLOCK, "&7Offset: &e" + NumberUtils.roundDecimalNumber(Double.valueOf(BlockStorage.getLocationInfo(projector.getLocation(), OFFSET_PARAMETER)) + 1.0D), "", "&rLeft Click: &7+0.1", "&rRight Click: &7-0.1"));
    menu.addMenuClickHandler(1, (pl, slot, item, action) -> {
        double offset = NumberUtils.reparseDouble(Double.valueOf(BlockStorage.getLocationInfo(projector.getLocation(), OFFSET_PARAMETER)) + (action.isRightClicked() ? -0.1F : 0.1F));
        ArmorStand hologram = getArmorStand(projector, true);
        Location l = new Location(projector.getWorld(), projector.getX() + 0.5, projector.getY() + offset, projector.getZ() + 0.5);
        hologram.teleport(l);
        BlockStorage.addBlockInfo(projector, OFFSET_PARAMETER, String.valueOf(offset));
        openEditor(pl, projector);
        return false;
    });
    menu.open(p);
}
Also used : ArmorStand(org.bukkit.entity.ArmorStand) CustomItemStack(io.github.bakedlibs.dough.items.CustomItemStack) ChestMenu(me.mrCookieSlime.CSCoreLibPlugin.general.Inventory.ChestMenu) Location(org.bukkit.Location)

Example 17 with ChestMenu

use of me.mrCookieSlime.CSCoreLibPlugin.general.Inventory.ChestMenu in project Slimefun4 by Slimefun.

the class ResourceManager method scan.

/**
 * This method will start a geo-scan at the given {@link Block} and display the result
 * of that scan to the given {@link Player}.
 *
 * Note that scans are always per {@link Chunk}, not per {@link Block}, the {@link Block}
 * parameter only determines the {@link Location} that was clicked but it will still scan
 * the entire {@link Chunk}.
 *
 * @param p
 *            The {@link Player} who requested these results
 * @param block
 *            The {@link Block} which the scan starts at
 * @param page
 *            The page to display
 */
public void scan(@Nonnull Player p, @Nonnull Block block, int page) {
    if (Slimefun.getGPSNetwork().getNetworkComplexity(p.getUniqueId()) < 600) {
        Slimefun.getLocalization().sendMessages(p, "gps.insufficient-complexity", true, msg -> msg.replace("%complexity%", "600"));
        return;
    }
    int x = block.getX() >> 4;
    int z = block.getZ() >> 4;
    String title = "&4" + Slimefun.getLocalization().getResourceString(p, "tooltips.results");
    ChestMenu menu = new ChestMenu(title);
    for (int slot : backgroundSlots) {
        menu.addItem(slot, ChestMenuUtils.getBackground(), ChestMenuUtils.getEmptyClickHandler());
    }
    menu.addItem(4, new CustomItemStack(HeadTexture.MINECRAFT_CHUNK.getAsItemStack(), ChatColor.YELLOW + Slimefun.getLocalization().getResourceString(p, "tooltips.chunk"), "", "&8\u21E8 &7" + Slimefun.getLocalization().getResourceString(p, "tooltips.world") + ": " + block.getWorld().getName(), "&8\u21E8 &7X: " + x + " Z: " + z), ChestMenuUtils.getEmptyClickHandler());
    List<GEOResource> resources = new ArrayList<>(Slimefun.getRegistry().getGEOResources().values());
    resources.sort(Comparator.comparing(a -> a.getName(p).toLowerCase(Locale.ROOT)));
    int index = 10;
    int pages = (resources.size() - 1) / 36 + 1;
    for (int i = page * 28; i < resources.size() && i < (page + 1) * 28; i++) {
        GEOResource resource = resources.get(i);
        OptionalInt optional = getSupplies(resource, block.getWorld(), x, z);
        int supplies = optional.isPresent() ? optional.getAsInt() : generate(resource, block.getWorld(), x, block.getY(), z);
        String suffix = Slimefun.getLocalization().getResourceString(p, supplies == 1 ? "tooltips.unit" : "tooltips.units");
        ItemStack item = new CustomItemStack(resource.getItem(), "&f" + resource.getName(p), "&8\u21E8 &e" + supplies + ' ' + suffix);
        if (supplies > 1) {
            item.setAmount(supplies > item.getMaxStackSize() ? item.getMaxStackSize() : supplies);
        }
        menu.addItem(index, item, ChestMenuUtils.getEmptyClickHandler());
        index++;
        if (index % 9 == 8) {
            index += 2;
        }
    }
    menu.addItem(47, ChestMenuUtils.getPreviousButton(p, page + 1, pages));
    menu.addMenuClickHandler(47, (pl, slot, item, action) -> {
        if (page > 0) {
            scan(pl, block, page - 1);
        }
        return false;
    });
    menu.addItem(51, ChestMenuUtils.getNextButton(p, page + 1, pages));
    menu.addMenuClickHandler(51, (pl, slot, item, action) -> {
        if (page + 1 < pages) {
            scan(pl, block, page + 1);
        }
        return false;
    });
    menu.open(p);
}
Also used : BlockStorage(me.mrCookieSlime.Slimefun.api.BlockStorage) Player(org.bukkit.entity.Player) OptionalInt(java.util.OptionalInt) Biome(org.bukkit.block.Biome) ArrayList(java.util.ArrayList) GEOResourceGenerationEvent(io.github.thebusybiscuit.slimefun4.api.events.GEOResourceGenerationEvent) Block(org.bukkit.block.Block) GEOMiner(io.github.thebusybiscuit.slimefun4.implementation.items.geo.GEOMiner) Location(org.bukkit.Location) Locale(java.util.Locale) World(org.bukkit.World) ThreadLocalRandom(java.util.concurrent.ThreadLocalRandom) Chunk(org.bukkit.Chunk) BlockPosition(io.github.bakedlibs.dough.blocks.BlockPosition) Nonnull(javax.annotation.Nonnull) Bukkit(org.bukkit.Bukkit) ChestMenuUtils(io.github.thebusybiscuit.slimefun4.utils.ChestMenuUtils) Config(io.github.bakedlibs.dough.config.Config) GEOScanner(io.github.thebusybiscuit.slimefun4.implementation.items.geo.GEOScanner) ItemStack(org.bukkit.inventory.ItemStack) MinecraftVersion(io.github.thebusybiscuit.slimefun4.api.MinecraftVersion) List(java.util.List) Slimefun(io.github.thebusybiscuit.slimefun4.implementation.Slimefun) ChestMenu(me.mrCookieSlime.CSCoreLibPlugin.general.Inventory.ChestMenu) ChatColor(org.bukkit.ChatColor) Comparator(java.util.Comparator) HeadTexture(io.github.thebusybiscuit.slimefun4.utils.HeadTexture) Validate(org.apache.commons.lang.Validate) CustomItemStack(io.github.bakedlibs.dough.items.CustomItemStack) CustomItemStack(io.github.bakedlibs.dough.items.CustomItemStack) ArrayList(java.util.ArrayList) OptionalInt(java.util.OptionalInt) ItemStack(org.bukkit.inventory.ItemStack) CustomItemStack(io.github.bakedlibs.dough.items.CustomItemStack) ChestMenu(me.mrCookieSlime.CSCoreLibPlugin.general.Inventory.ChestMenu)

Example 18 with ChestMenu

use of me.mrCookieSlime.CSCoreLibPlugin.general.Inventory.ChestMenu in project Slimefun4 by Slimefun.

the class GPSNetwork method openTransmitterControlPanel.

/**
 * This method opens the {@link GPSTransmitter} control panel to the given
 * {@link Player}.
 *
 * @param p
 *            The {@link Player}
 */
public void openTransmitterControlPanel(@Nonnull Player p) {
    ChestMenu menu = new ChestMenu(ChatColor.BLUE + Slimefun.getLocalization().getMessage(p, "machines.GPS_CONTROL_PANEL.title"));
    for (int slot : border) {
        menu.addItem(slot, ChestMenuUtils.getBackground(), ChestMenuUtils.getEmptyClickHandler());
    }
    menu.addItem(2, new CustomItemStack(SlimefunItems.GPS_TRANSMITTER, im -> {
        im.setDisplayName(ChatColor.GRAY + Slimefun.getLocalization().getMessage(p, "machines.GPS_CONTROL_PANEL.transmitters"));
        im.setLore(null);
    }));
    menu.addMenuClickHandler(2, ChestMenuUtils.getEmptyClickHandler());
    int complexity = getNetworkComplexity(p.getUniqueId());
    menu.addItem(4, new CustomItemStack(SlimefunItems.GPS_CONTROL_PANEL, "&7Network Info", "", "&8\u21E8 &7Status: " + (complexity > 0 ? "&2&lONLINE" : "&4&lOFFLINE"), "&8\u21E8 &7Complexity: &f" + complexity));
    menu.addMenuClickHandler(4, ChestMenuUtils.getEmptyClickHandler());
    menu.addItem(6, new CustomItemStack(HeadTexture.GLOBE_OVERWORLD.getAsItemStack(), "&7" + Slimefun.getLocalization().getMessage(p, "machines.GPS_CONTROL_PANEL.waypoints"), "", ChatColor.GRAY + "\u21E8 " + Slimefun.getLocalization().getMessage(p, "guide.tooltips.open-itemgroup")));
    menu.addMenuClickHandler(6, (pl, slot, item, action) -> {
        openWaypointControlPanel(pl);
        return false;
    });
    int index = 0;
    for (Location l : getTransmitters(p.getUniqueId())) {
        if (index >= inventory.length) {
            break;
        }
        SlimefunItem sfi = BlockStorage.check(l);
        if (sfi instanceof GPSTransmitter) {
            int slot = inventory[index];
            menu.addItem(slot, new CustomItemStack(SlimefunItems.GPS_TRANSMITTER, "&bGPS Transmitter", "&8\u21E8 &7World: &f" + l.getWorld().getName(), "&8\u21E8 &7X: &f" + l.getX(), "&8\u21E8 &7Y: &f" + l.getY(), "&8\u21E8 &7Z: &f" + l.getZ(), "", "&8\u21E8 &7Signal Strength: &f" + ((GPSTransmitter) sfi).getMultiplier(l.getBlockY()), "&8\u21E8 &7Ping: &f" + NumberUtils.roundDecimalNumber(1000D / l.getY()) + "ms"));
            menu.addMenuClickHandler(slot, ChestMenuUtils.getEmptyClickHandler());
            index++;
        }
    }
    menu.open(p);
}
Also used : ResourceManager(io.github.thebusybiscuit.slimefun4.api.geo.ResourceManager) WaypointCreateEvent(io.github.thebusybiscuit.slimefun4.api.events.WaypointCreateEvent) HashMap(java.util.HashMap) BlockStorage(me.mrCookieSlime.Slimefun.api.BlockStorage) Player(org.bukkit.entity.Player) HashSet(java.util.HashSet) ChatColors(io.github.bakedlibs.dough.common.ChatColors) Environment(org.bukkit.World.Environment) PlayerProfile(io.github.thebusybiscuit.slimefun4.api.player.PlayerProfile) SlimefunItems(io.github.thebusybiscuit.slimefun4.implementation.SlimefunItems) Location(org.bukkit.Location) Locale(java.util.Locale) Server(org.bukkit.Server) World(org.bukkit.World) Map(java.util.Map) GPSTransmitter(io.github.thebusybiscuit.slimefun4.implementation.items.gps.GPSTransmitter) Nonnull(javax.annotation.Nonnull) ChatInput(io.github.bakedlibs.dough.chat.ChatInput) Bukkit(org.bukkit.Bukkit) NumberUtils(io.github.thebusybiscuit.slimefun4.utils.NumberUtils) SlimefunItem(io.github.thebusybiscuit.slimefun4.api.items.SlimefunItem) ChestMenuUtils(io.github.thebusybiscuit.slimefun4.utils.ChestMenuUtils) Set(java.util.Set) UUID(java.util.UUID) Sound(org.bukkit.Sound) ItemStack(org.bukkit.inventory.ItemStack) GEOResource(io.github.thebusybiscuit.slimefun4.api.geo.GEOResource) Teleporter(io.github.thebusybiscuit.slimefun4.implementation.items.teleporter.Teleporter) Slimefun(io.github.thebusybiscuit.slimefun4.implementation.Slimefun) ChestMenu(me.mrCookieSlime.CSCoreLibPlugin.general.Inventory.ChestMenu) ChatColor(org.bukkit.ChatColor) HeadTexture(io.github.thebusybiscuit.slimefun4.utils.HeadTexture) Validate(org.apache.commons.lang.Validate) CustomItemStack(io.github.bakedlibs.dough.items.CustomItemStack) GPSTransmitter(io.github.thebusybiscuit.slimefun4.implementation.items.gps.GPSTransmitter) CustomItemStack(io.github.bakedlibs.dough.items.CustomItemStack) SlimefunItem(io.github.thebusybiscuit.slimefun4.api.items.SlimefunItem) ChestMenu(me.mrCookieSlime.CSCoreLibPlugin.general.Inventory.ChestMenu) Location(org.bukkit.Location)

Example 19 with ChestMenu

use of me.mrCookieSlime.CSCoreLibPlugin.general.Inventory.ChestMenu in project Slimefun4 by Slimefun.

the class TeleportationManager method openTeleporterGUI.

@ParametersAreNonnullByDefault
public void openTeleporterGUI(Player p, UUID ownerUUID, Block b, int complexity) {
    if (teleporterUsers.add(p.getUniqueId())) {
        p.playSound(p.getLocation(), Sound.UI_BUTTON_CLICK, 1F, 1F);
        PlayerProfile.fromUUID(ownerUUID, profile -> {
            ChestMenu menu = new ChestMenu("&3Teleporter");
            menu.addMenuCloseHandler(pl -> teleporterUsers.remove(pl.getUniqueId()));
            for (int slot : teleporterBorder) {
                menu.addItem(slot, ChestMenuUtils.getBackground(), ChestMenuUtils.getEmptyClickHandler());
            }
            menu.addItem(4, new CustomItemStack(HeadTexture.GLOBE_OVERWORLD.getAsItemStack(), ChatColor.YELLOW + Slimefun.getLocalization().getMessage(p, "machines.TELEPORTER.gui.title")));
            menu.addMenuClickHandler(4, ChestMenuUtils.getEmptyClickHandler());
            Location source = new Location(b.getWorld(), b.getX() + 0.5D, b.getY() + 2D, b.getZ() + 0.5D);
            int index = 0;
            for (Waypoint waypoint : profile.getWaypoints()) {
                if (index >= teleporterInventory.length) {
                    break;
                }
                int slot = teleporterInventory[index];
                Location l = waypoint.getLocation();
                double time = NumberUtils.reparseDouble(0.5 * getTeleportationTime(complexity, source, l));
                // @formatter:off
                String[] lore = { "", "&8\u21E8 &7" + Slimefun.getLocalization().getResourceString(p, "tooltips.world") + ": &f" + l.getWorld().getName(), "&8\u21E8 &7X: &f" + l.getX(), "&8\u21E8 &7Y: &f" + l.getY(), "&8\u21E8 &7Z: &f" + l.getZ(), "&8\u21E8 &7" + Slimefun.getLocalization().getMessage(p, "machines.TELEPORTER.gui.time") + ": &f" + time + "s", "", "&8\u21E8 &c" + Slimefun.getLocalization().getMessage(p, "machines.TELEPORTER.gui.tooltip") };
                // @formatter:on
                menu.addItem(slot, new CustomItemStack(waypoint.getIcon(), waypoint.getName().replace("player:death ", ""), lore));
                menu.addMenuClickHandler(slot, (pl, s, item, action) -> {
                    pl.closeInventory();
                    teleport(pl.getUniqueId(), complexity, source, l, false);
                    return false;
                });
                index++;
            }
            Slimefun.runSync(() -> menu.open(p));
        });
    }
}
Also used : CustomItemStack(io.github.bakedlibs.dough.items.CustomItemStack) ChestMenu(me.mrCookieSlime.CSCoreLibPlugin.general.Inventory.ChestMenu) Location(org.bukkit.Location) ParametersAreNonnullByDefault(javax.annotation.ParametersAreNonnullByDefault)

Example 20 with ChestMenu

use of me.mrCookieSlime.CSCoreLibPlugin.general.Inventory.ChestMenu in project Slimefun4 by Slimefun.

the class ContributorsMenu method open.

public static void open(Player p, int page) {
    ChestMenu menu = new ChestMenu(Slimefun.getLocalization().getMessage(p, "guide.title.credits"));
    menu.setEmptySlotsClickable(false);
    menu.addMenuOpeningHandler(pl -> pl.playSound(pl.getLocation(), Sound.BLOCK_NOTE_BLOCK_HARP, 0.7F, 0.7F));
    ChestMenuUtils.drawBackground(menu, 0, 2, 3, 4, 5, 6, 7, 8, 45, 47, 48, 49, 50, 51, 53);
    menu.addItem(1, new CustomItemStack(ChestMenuUtils.getBackButton(p, "", "&7" + Slimefun.getLocalization().getMessage(p, "guide.back.settings"))));
    menu.addMenuClickHandler(1, (pl, slot, item, action) -> {
        SlimefunGuideSettings.openSettings(pl, p.getInventory().getItemInMainHand());
        return false;
    });
    List<Contributor> contributors = new ArrayList<>(Slimefun.getGitHubService().getContributors().values());
    contributors.sort(Comparator.comparingInt(Contributor::getPosition));
    for (int i = page * 36; i < contributors.size() && i < (page + 1) * 36; i++) {
        Contributor contributor = contributors.get(i);
        ItemStack skull = getContributorHead(p, contributor);
        menu.addItem(i - page * 36 + 9, skull);
        menu.addMenuClickHandler(i - page * 36 + 9, (pl, slot, item, action) -> {
            if (contributor.getProfile() != null) {
                pl.closeInventory();
                ChatUtils.sendURL(pl, contributor.getProfile());
            }
            return false;
        });
    }
    int pages = (contributors.size() - 1) / 36 + 1;
    menu.addItem(46, ChestMenuUtils.getPreviousButton(p, page + 1, pages));
    menu.addMenuClickHandler(46, (pl, slot, item, action) -> {
        if (page > 0) {
            open(pl, page - 1);
        }
        return false;
    });
    menu.addItem(52, ChestMenuUtils.getNextButton(p, page + 1, pages));
    menu.addMenuClickHandler(52, (pl, slot, item, action) -> {
        if (page + 1 < pages) {
            open(pl, page + 1);
        }
        return false;
    });
    menu.open(p);
}
Also used : CustomItemStack(io.github.bakedlibs.dough.items.CustomItemStack) ArrayList(java.util.ArrayList) Contributor(io.github.thebusybiscuit.slimefun4.core.services.github.Contributor) ItemStack(org.bukkit.inventory.ItemStack) CustomItemStack(io.github.bakedlibs.dough.items.CustomItemStack) ChestMenu(me.mrCookieSlime.CSCoreLibPlugin.general.Inventory.ChestMenu)

Aggregations

ChestMenu (me.mrCookieSlime.CSCoreLibPlugin.general.Inventory.ChestMenu)33 CustomItemStack (io.github.bakedlibs.dough.items.CustomItemStack)23 ParametersAreNonnullByDefault (javax.annotation.ParametersAreNonnullByDefault)18 ItemStack (org.bukkit.inventory.ItemStack)17 Player (org.bukkit.entity.Player)11 SlimefunItem (io.github.thebusybiscuit.slimefun4.api.items.SlimefunItem)9 SlimefunItemStack (io.github.thebusybiscuit.slimefun4.api.items.SlimefunItemStack)7 Slimefun (io.github.thebusybiscuit.slimefun4.implementation.Slimefun)7 AsyncRecipeChoiceTask (io.github.thebusybiscuit.slimefun4.implementation.tasks.AsyncRecipeChoiceTask)7 ChestMenuUtils (io.github.thebusybiscuit.slimefun4.utils.ChestMenuUtils)7 Nonnull (javax.annotation.Nonnull)7 ChatColor (org.bukkit.ChatColor)7 CustomItemStack (io.github.thebusybiscuit.slimefun4.libraries.dough.items.CustomItemStack)6 ArrayList (java.util.ArrayList)6 List (java.util.List)6 ItemGroup (io.github.thebusybiscuit.slimefun4.api.items.ItemGroup)5 FlexItemGroup (io.github.thebusybiscuit.slimefun4.api.items.groups.FlexItemGroup)5 ChatUtils (io.github.thebusybiscuit.slimefun4.utils.ChatUtils)5 Location (org.bukkit.Location)5 Sound (org.bukkit.Sound)5