Skip to content

Commit

Permalink
Updates usages of CustomItemStack (Slimefun#4253)
Browse files Browse the repository at this point in the history
Co-authored-by: Daniel Walsh <[email protected]>
  • Loading branch information
md5sha256 and WalshyDev authored Nov 9, 2024
1 parent 00da02c commit 6f02cae
Show file tree
Hide file tree
Showing 104 changed files with 598 additions and 625 deletions.
10 changes: 5 additions & 5 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -355,9 +355,9 @@

<!-- Shaded packages -->
<dependency>
<groupId>com.github.baked-libs.dough</groupId>
<groupId>com.github.Slimefun.dough</groupId>
<artifactId>dough-api</artifactId>
<version>f8ff25187d</version>
<version>cb22e71335</version>
<scope>compile</scope>
</dependency>
<dependency>
Expand Down Expand Up @@ -395,9 +395,9 @@
</dependency>
<!-- This needs to be before Spigot because MockBukkit will fail otherwise. -->
<dependency>
<groupId>com.github.MockBukkit</groupId>
<artifactId>MockBukkit</artifactId>
<version>v3.130.2</version>
<groupId>com.github.seeseemelk</groupId>
<artifactId>MockBukkit-v1.21</artifactId>
<version>3.133.2</version>
<scope>test</scope>

<exclusions>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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, CustomItemStack.create(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 = CustomItemStack.create(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
Expand Up @@ -44,9 +44,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 +64,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 +74,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 +96,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 +124,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 +138,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 +149,18 @@ public void openTransmitterControlPanel(@Nonnull Player p) {
menu.addItem(slot, ChestMenuUtils.getBackground(), ChestMenuUtils.getEmptyClickHandler());
}

menu.addItem(2, new CustomItemStack(SlimefunItems.GPS_TRANSMITTER, im -> {
menu.addItem(2, CustomItemStack.create(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: " + getStatusText(p, complexity), "&8\u21E8 &7Complexity: &f" + complexity));
menu.addItem(4, CustomItemStack.create(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, CustomItemStack.create(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 +177,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, CustomItemStack.create(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 +192,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 +232,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, CustomItemStack.create(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, CustomItemStack.create(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, CustomItemStack.create(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 +254,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, CustomItemStack.create(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 +273,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 +298,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 +343,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 +357,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 +368,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
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@
/**
* The {@link TeleportationManager} handles the process of teleportation for a {@link Player}
* who is using a {@link Teleporter}.
*
*
* @author TheBusyBiscuit
*
*
* @see GPSNetwork
* @see Teleporter
*
Expand Down Expand Up @@ -79,7 +79,7 @@ public void openTeleporterGUI(Player p, UUID ownerUUID, Block b, int complexity)
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.addItem(4, CustomItemStack.create(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);
Expand Down Expand Up @@ -107,7 +107,7 @@ public void openTeleporterGUI(Player p, UUID ownerUUID, Block b, int complexity)
};
// @formatter:on

menu.addItem(slot, new CustomItemStack(waypoint.getIcon(), waypoint.getName().replace("player:death ", ""), lore));
menu.addItem(slot, CustomItemStack.create(waypoint.getIcon(), waypoint.getName().replace("player:death ", ""), lore));
menu.addMenuClickHandler(slot, (pl, s, item, action) -> {
pl.closeInventory();
teleport(pl.getUniqueId(), complexity, source, l, false);
Expand Down Expand Up @@ -136,21 +136,21 @@ public void teleport(UUID uuid, int complexity, Location source, Location destin
* to the destination {@link Location}, given the specified complexity.
* <p>
* The returned time will be measured in 500ms intervals.
*
*
* <ul>
* <li>A returned time of {@literal 100} will mean 50,000ms (50s) of real-life time.</li>
* <li>A returned time of {@literal 10} will mean 5,000ms (5s) of real-life time.</li>
* <li>A returned time of {@literal 2} will mean 1,000ms (1s) of real-life time.</li>
* <li>and so on...</li>
* </ul>
*
*
* @param complexity
* The complexity of the {@link GPSNetwork}
* @param source
* The source {@link Location}
* @param destination
* The destination {@link Location}
*
*
* @return The amount of time the teleportation will take
*/
public int getTeleportationTime(int complexity, @Nonnull Location source, @Nonnull Location destination) {
Expand Down
Loading

0 comments on commit 6f02cae

Please sign in to comment.