Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DRAFT] Move away from dough's CustomItemStack #4249

Open
wants to merge 1 commit into
base: walshy/mc-1.21
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

import javax.annotation.Nonnull;

import io.github.thebusybiscuit.slimefun4.utils.itemstack.ItemStackUtil;
import org.apache.commons.lang.Validate;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
Expand All @@ -22,7 +23,6 @@

import io.github.bakedlibs.dough.blocks.BlockPosition;
import io.github.bakedlibs.dough.config.Config;
import io.github.bakedlibs.dough.items.CustomItemStack;
import io.github.thebusybiscuit.slimefun4.api.MinecraftVersion;
import io.github.thebusybiscuit.slimefun4.api.events.GEOResourceGenerationEvent;
import io.github.thebusybiscuit.slimefun4.implementation.Slimefun;
Expand All @@ -38,9 +38,9 @@
/**
* The {@link ResourceManager} is responsible for registering and managing a {@link GEOResource}.
* You have to use the {@link ResourceManager} if you want to generate or consume a {@link GEOResource} too.
*
*
* @author TheBusyBiscuit
*
*
* @see GEOResource
* @see GEOMiner
* @see GEOScanner
Expand All @@ -53,7 +53,7 @@ public class ResourceManager {

/**
* This will create a new {@link ResourceManager}.
*
*
* @param plugin
* Our {@link Slimefun} instance
*/
Expand All @@ -64,7 +64,7 @@ public ResourceManager(@Nonnull Slimefun plugin) {
/**
* This method registers the given {@link GEOResource}.
* It may never be called directly, use {@link GEOResource#register()} instead.
*
*
* @param resource
* The {@link GEOResource} to register
*/
Expand Down Expand Up @@ -93,7 +93,7 @@ void register(@Nonnull GEOResource resource) {
* This method returns the amount of a certain {@link GEOResource} found in a given {@link Chunk}.
* The result is an {@link OptionalInt} which will be empty if this {@link GEOResource}
* has not been generated at that {@link Location} yet.
*
*
* @param resource
* The {@link GEOResource} to query
* @param world
Expand All @@ -102,7 +102,7 @@ void register(@Nonnull GEOResource resource) {
* The {@link Chunk} x coordinate
* @param z
* The {@link Chunk} z coordinate
*
*
* @return An {@link OptionalInt}, either empty or containing the amount of the given {@link GEOResource}
*/
public @Nonnull OptionalInt getSupplies(@Nonnull GEOResource resource, @Nonnull World world, int x, int z) {
Expand All @@ -121,7 +121,7 @@ void register(@Nonnull GEOResource resource) {

/**
* This method will set the supplies in a given {@link Chunk} to the specified value.
*
*
* @param resource
* The {@link GEOResource}
* @param world
Expand All @@ -147,7 +147,7 @@ public void setSupplies(@Nonnull GEOResource resource, @Nonnull World world, int
* <p>
* This method will invoke {@link #setSupplies(GEOResource, World, int, int, int)} and also calls a
* {@link GEOResourceGenerationEvent}.
*
*
* @param resource
* The {@link GEOResource} to generate
* @param world
Expand All @@ -156,7 +156,7 @@ public void setSupplies(@Nonnull GEOResource resource, @Nonnull World world, int
* The x coordinate of that {@link Chunk}
* @param z
* The z coordinate of that {@link Chunk}
*
*
* @return The new supply value
*/
private int generate(@Nonnull GEOResource resource, @Nonnull World world, int x, int y, int z) {
Expand Down Expand Up @@ -199,11 +199,11 @@ private int generate(@Nonnull GEOResource resource, @Nonnull World world, int x,
/**
* 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
Expand All @@ -227,7 +227,7 @@ public void scan(@Nonnull Player p, @Nonnull Block block, int page) {
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());
menu.addItem(4, ItemStackUtil.withNameLoreString(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)));

Expand All @@ -240,7 +240,7 @@ public void scan(@Nonnull Player p, @Nonnull Block block, int page) {
int supplies = optional.orElseGet(() -> generate(resource, block.getWorld(), x, block.getY(), z));
String suffix = Slimefun.getLocalization().getResourceString(p, ChatUtils.checkPlurality("tooltips.unit", supplies));

ItemStack item = new CustomItemStack(resource.getItem(), "&f" + resource.getName(p), "&8\u21E8 &e" + supplies + ' ' + suffix);
ItemStack item = ItemStackUtil.withNameLoreString(resource.getItem(), "&f" + resource.getName(p), "&8\u21E8 &e" + supplies + ' ' + suffix);

if (supplies > 1) {
item.setAmount(Math.min(supplies, item.getMaxStackSize()));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package io.github.thebusybiscuit.slimefun4.api.gps;

import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Locale;
Expand All @@ -10,6 +11,7 @@
import javax.annotation.Nonnull;
import javax.annotation.ParametersAreNonnullByDefault;

import io.github.thebusybiscuit.slimefun4.utils.itemstack.ItemStackUtil;
import org.apache.commons.lang.Validate;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
Expand All @@ -22,7 +24,6 @@

import io.github.bakedlibs.dough.chat.ChatInput;
import io.github.bakedlibs.dough.common.ChatColors;
import io.github.bakedlibs.dough.items.CustomItemStack;
import io.github.thebusybiscuit.slimefun4.api.events.WaypointCreateEvent;
import io.github.thebusybiscuit.slimefun4.api.geo.GEOResource;
import io.github.thebusybiscuit.slimefun4.api.geo.ResourceManager;
Expand All @@ -44,9 +45,9 @@
* The {@link GPSNetwork} is a manager class for all {@link GPSTransmitter Transmitters} and waypoints.
* There can only be one instance of this class per {@link Server}.
* It is also responsible for teleportation and resource management.
*
*
* @author TheBusyBiscuit
*
*
* @see TeleportationManager
* @see ResourceManager
*
Expand All @@ -64,7 +65,7 @@ public class GPSNetwork {
/**
* This constructs a new {@link GPSNetwork}.
* Note that this network is per {@link Server} and not per {@link Player}.
*
*
* @param plugin
* Our {@link Slimefun} instance
*/
Expand All @@ -74,7 +75,7 @@ public GPSNetwork(@Nonnull Slimefun plugin) {

/**
* This method updates the status of a {@link GPSTransmitter}.
*
*
* @param l
* The {@link Location} of the {@link GPSTransmitter}
* @param uuid
Expand All @@ -96,10 +97,10 @@ public void updateTransmitter(@Nonnull Location l, @Nonnull UUID uuid, boolean o
* This method calculates the GPS complexity for the given {@link UUID}.
* The complexity is determined by the Y level of each {@link GPSTransmitter}
* multiplied by the multiplier of that transmitter.
*
*
* @param uuid
* The {@link UUID} who to calculate it for
*
*
* @return The network complexity for that {@link UUID}
*/
public int getNetworkComplexity(@Nonnull UUID uuid) {
Expand All @@ -124,10 +125,10 @@ public int getNetworkComplexity(@Nonnull UUID uuid) {
/**
* This method returns the amount of {@link GPSTransmitter Transmitters} for the
* given {@link UUID}.
*
*
* @param uuid
* The {@link UUID} who these transmitters belong to
*
*
* @return The amount of transmitters
*/
public int countTransmitters(@Nonnull UUID uuid) {
Expand All @@ -138,7 +139,7 @@ public int countTransmitters(@Nonnull UUID uuid) {
/**
* This method opens the {@link GPSTransmitter} control panel to the given
* {@link Player}.
*
*
* @param p
* The {@link Player}
*/
Expand All @@ -149,18 +150,16 @@ public void openTransmitterControlPanel(@Nonnull Player p) {
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);
}));
String displayName = ChatColor.GRAY + Slimefun.getLocalization().getMessage(p, "machines.GPS_CONTROL_PANEL.transmitters");
menu.addItem(2, ItemStackUtil.withNameLoreString(SlimefunItems.GPS_TRANSMITTER, displayName, Collections.emptyList()));

menu.addMenuClickHandler(2, ChestMenuUtils.getEmptyClickHandler());

int complexity = getNetworkComplexity(p.getUniqueId());
menu.addItem(4, new CustomItemStack(SlimefunItems.GPS_CONTROL_PANEL, "&7Network Info", "", "&8\u21E8 &7Status: " + getStatusText(p, complexity), "&8\u21E8 &7Complexity: &f" + complexity));
menu.addItem(4, ItemStackUtil.withNameLoreString(SlimefunItems.GPS_CONTROL_PANEL, "&7Network Info", "", "&8\u21E8 &7Status: " + getStatusText(p, complexity), "&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.addItem(6, ItemStackUtil.withNameLoreString(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;
Expand All @@ -177,7 +176,7 @@ public void openTransmitterControlPanel(@Nonnull Player p) {
if (sfi instanceof GPSTransmitter transmitter) {
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" + transmitter.getMultiplier(l.getBlockY()), "&8\u21E8 &7Ping: &f" + NumberUtils.roundDecimalNumber(1000D / l.getY()) + "ms"));
menu.addItem(slot, ItemStackUtil.withNameLoreString(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" + transmitter.getMultiplier(l.getBlockY()), "&8\u21E8 &7Ping: &f" + NumberUtils.roundDecimalNumber(1000D / l.getY()) + "ms"));
menu.addMenuClickHandler(slot, ChestMenuUtils.getEmptyClickHandler());

index++;
Expand All @@ -192,14 +191,14 @@ public void openTransmitterControlPanel(@Nonnull Player p) {
* The icon is dependent on the {@link Environment} of the waypoint's {@link World}.
* However if the name of this waypoint indicates that this is actually a deathmarker
* then a different texture will be used.
*
*
* Otherwise it will return a globe, a nether or end sphere according to the {@link Environment}.
*
*
* @param name
* The name of a waypoint
* @param environment
* The {@link Environment} of the waypoint's {@link World}
*
*
* @return An icon for this waypoint
*/
@ParametersAreNonnullByDefault
Expand Down Expand Up @@ -232,17 +231,17 @@ public void openWaypointControlPanel(@Nonnull Player p) {
menu.addItem(slot, ChestMenuUtils.getBackground(), ChestMenuUtils.getEmptyClickHandler());
}

menu.addItem(2, new CustomItemStack(SlimefunItems.GPS_TRANSMITTER, "&7" + Slimefun.getLocalization().getMessage(p, "machines.GPS_CONTROL_PANEL.transmitters"), "", ChatColor.GRAY + "\u21E8 " + Slimefun.getLocalization().getMessage(p, "guide.tooltips.open-itemgroup")));
menu.addItem(2, ItemStackUtil.withNameLoreString(SlimefunItems.GPS_TRANSMITTER, "&7" + Slimefun.getLocalization().getMessage(p, "machines.GPS_CONTROL_PANEL.transmitters"), "", ChatColor.GRAY + "\u21E8 " + Slimefun.getLocalization().getMessage(p, "guide.tooltips.open-itemgroup")));
menu.addMenuClickHandler(2, (pl, slot, item, action) -> {
openTransmitterControlPanel(pl);
return false;
});

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.addItem(4, ItemStackUtil.withNameLoreString(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")));
menu.addItem(6, ItemStackUtil.withNameString(HeadTexture.GLOBE_OVERWORLD.getAsItemStack(), "&7" + Slimefun.getLocalization().getMessage(p, "machines.GPS_CONTROL_PANEL.waypoints")));
menu.addMenuClickHandler(6, ChestMenuUtils.getEmptyClickHandler());

int index = 0;
Expand All @@ -254,7 +253,7 @@ public void openWaypointControlPanel(@Nonnull Player p) {
int slot = inventory[index];

Location l = waypoint.getLocation();
menu.addItem(slot, new CustomItemStack(waypoint.getIcon(), waypoint.getName().replace("player:death ", ""), "&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 &cClick to delete"));
menu.addItem(slot, ItemStackUtil.withNameLoreString(waypoint.getIcon(), waypoint.getName().replace("player:death ", ""), "&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 &cClick to delete"));
menu.addMenuClickHandler(slot, (pl, s, item, action) -> {
profile.removeWaypoint(waypoint);
SoundEffect.GPS_NETWORK_OPEN_PANEL_SOUND.playFor(p);
Expand All @@ -273,7 +272,7 @@ public void openWaypointControlPanel(@Nonnull Player p) {
/**
* This method will prompt the given {@link Player} to enter a name for a waypoint.
* After entering the name, it will be added to his waypoint list.
*
*
* @param p
* The {@link Player} who should get a new waypoint
* @param l
Expand All @@ -298,7 +297,7 @@ public void createWaypoint(@Nonnull Player p, @Nonnull Location l) {

/**
* This method adds a new waypoint with the given name and {@link Location} for that {@link Player}.
*
*
* @param p
* The {@link Player} to get the new waypoint
* @param name
Expand Down Expand Up @@ -343,10 +342,10 @@ public void addWaypoint(@Nonnull Player p, @Nonnull String name, @Nonnull Locati
/**
* This method returns a {@link Set} of {@link Location Locations} for all {@link GPSTransmitter Transmitters}
* owned by the given {@link UUID}.
*
*
* @param uuid
* The {@link UUID} owning those transmitters
*
*
* @return A {@link Set} with all {@link Location Locations} of transmitters for this {@link UUID}
*/
@Nonnull
Expand All @@ -357,7 +356,7 @@ public Set<Location> getTransmitters(@Nonnull UUID uuid) {
/**
* This returns the {@link TeleportationManager} for this {@link GPSNetwork}.
* It is responsible for all actions that relate to the {@link Teleporter}.
*
*
* @return The {@link TeleportationManager} for this {@link GPSNetwork}
*/
@Nonnull
Expand All @@ -368,7 +367,7 @@ public TeleportationManager getTeleportationManager() {
/**
* This returns the {@link ResourceManager} for this {@link GPSNetwork}.
* Use this to access {@link GEOResource GEOResources}.
*
*
* @return The {@link ResourceManager} for this {@link GPSNetwork}
*/
@Nonnull
Expand Down
Loading
Loading