Skip to content

Commit 731f1d1

Browse files
committed
start updating item meta
Things to note: - JukeboxPlayableComponent#isShowInTooltip/setShowInTooltip are deprecated since no longer available on the component. The alternative is either keep supporting item flag (by adding a new one) or migrate to use the new data component API - ItemFlag#HIDE_ADDITIONAL_TOOLTIP is deprecated, the new component tooltip_display allow to hide component individually, using the flag on an item now will do exactly like mojang data fixer providing backward compatibility by adding the components that would be hidden in a previous version in the tooltip_display component
1 parent dfb8d58 commit 731f1d1

File tree

62 files changed

+827
-1079
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

62 files changed

+827
-1079
lines changed

paper-api/src/main/java/com/destroystokyo/paper/entity/ai/GoalKey.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package com.destroystokyo.paper.entity.ai;
22

3-
import com.google.common.base.Objects;
3+
import java.util.Objects;
44
import java.util.StringJoiner;
55
import org.bukkit.NamespacedKey;
66
import org.bukkit.entity.Mob;
@@ -36,13 +36,13 @@ public boolean equals(@Nullable Object o) {
3636
if (this == o) return true;
3737
if (o == null || this.getClass() != o.getClass()) return false;
3838
GoalKey<?> goalKey = (GoalKey<?>) o;
39-
return Objects.equal(this.entityClass, goalKey.entityClass) &&
40-
Objects.equal(this.namespacedKey, goalKey.namespacedKey);
39+
return Objects.equals(this.entityClass, goalKey.entityClass) &&
40+
Objects.equals(this.namespacedKey, goalKey.namespacedKey);
4141
}
4242

4343
@Override
4444
public int hashCode() {
45-
return Objects.hashCode(this.entityClass, this.namespacedKey);
45+
return Objects.hash(this.entityClass, this.namespacedKey);
4646
}
4747

4848
@Override

paper-api/src/main/java/org/bukkit/command/defaults/VersionCommand.java

+3-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package org.bukkit.command.defaults;
22

3-
import com.google.common.base.Charsets;
43
import com.google.common.base.Preconditions;
54
import com.google.common.collect.ImmutableList;
65
import com.google.common.io.Resources;
@@ -11,6 +10,7 @@
1110
import java.io.IOException;
1211
import java.net.URL;
1312
import java.net.URLEncoder;
13+
import java.nio.charset.StandardCharsets;
1414
import java.util.ArrayList;
1515
import java.util.Arrays;
1616
import java.util.HashSet;
@@ -25,14 +25,12 @@
2525
import org.bukkit.plugin.PluginDescriptionFile;
2626
import org.bukkit.util.StringUtil;
2727
import org.jetbrains.annotations.NotNull;
28-
// Paper start - version command 2.0
2928
import com.destroystokyo.paper.util.VersionFetcher;
3029
import net.kyori.adventure.text.Component;
3130
import net.kyori.adventure.text.format.NamedTextColor;
3231
import net.kyori.adventure.text.event.ClickEvent;
3332
import net.kyori.adventure.text.format.TextDecoration;
3433
import net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer;
35-
// Paper end - version command 2.0
3634

3735
public class VersionCommand extends BukkitCommand {
3836
private VersionFetcher versionFetcher; // Paper - version command 2.0
@@ -283,8 +281,8 @@ private void setVersionMessage(final @NotNull Component msg) {
283281
private static int getDistance(@NotNull String repo, @NotNull String hash) {
284282
try {
285283
BufferedReader reader = Resources.asCharSource(
286-
new URL("https://hub.spigotmc.org/stash/rest/api/1.0/projects/SPIGOT/repos/" + repo + "/commits?since=" + URLEncoder.encode(hash, "UTF-8") + "&withCounts=true"),
287-
Charsets.UTF_8
284+
new URL("https://hub.spigotmc.org/stash/rest/api/1.0/projects/SPIGOT/repos/" + repo + "/commits?since=" + URLEncoder.encode(hash, StandardCharsets.UTF_8) + "&withCounts=true"),
285+
StandardCharsets.UTF_8
288286
).openBufferedStream();
289287
try {
290288
JsonObject obj = new Gson().fromJson(reader, JsonObject.class);

paper-api/src/main/java/org/bukkit/configuration/file/FileConfiguration.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package org.bukkit.configuration.file;
22

3-
import com.google.common.base.Charsets;
43
import com.google.common.base.Preconditions;
54
import com.google.common.io.Files;
65
import java.io.BufferedReader;
@@ -13,6 +12,7 @@
1312
import java.io.OutputStreamWriter;
1413
import java.io.Reader;
1514
import java.io.Writer;
15+
import java.nio.charset.StandardCharsets;
1616
import org.bukkit.configuration.Configuration;
1717
import org.bukkit.configuration.InvalidConfigurationException;
1818
import org.bukkit.configuration.MemoryConfiguration;
@@ -64,7 +64,7 @@ public void save(@NotNull File file) throws IOException {
6464

6565
String data = saveToString();
6666

67-
Writer writer = new OutputStreamWriter(new FileOutputStream(file), Charsets.UTF_8);
67+
Writer writer = new OutputStreamWriter(new FileOutputStream(file), StandardCharsets.UTF_8);
6868

6969
try {
7070
writer.write(data);
@@ -125,7 +125,7 @@ public void load(@NotNull File file) throws FileNotFoundException, IOException,
125125

126126
final FileInputStream stream = new FileInputStream(file);
127127

128-
load(new InputStreamReader(stream, Charsets.UTF_8));
128+
load(new InputStreamReader(stream, StandardCharsets.UTF_8));
129129
}
130130

131131
/**

paper-api/src/main/java/org/bukkit/inventory/ItemFlag.java

+5-2
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,11 @@ public enum ItemFlag {
3030
/**
3131
* Setting to show/hide potion effects, book and firework information, map
3232
* tooltips, patterns of banners.
33+
*
3334
* @see #HIDE_STORED_ENCHANTS HIDE_STORED_ENCHANTS for hiding stored enchants (like on enchanted books)
35+
* @deprecated each component can now be hidden individually in the {@code tooltip_display} component
3436
*/
37+
@Deprecated(since = "1.21.5", forRemoval = true)
3538
HIDE_ADDITIONAL_TOOLTIP,
3639
/**
3740
* Setting to show/hide dyes from colored leather armor.
@@ -65,9 +68,9 @@ public enum ItemFlag {
6568
* <li>Shulker box contents</li>
6669
* <li>Spawner descriptions</li>
6770
* </ul>
68-
* @deprecated use {@link #HIDE_ADDITIONAL_TOOLTIP}
71+
* @deprecated each component can now be hidden individually in the {@code tooltip_display} component
6972
*/
70-
@Deprecated(since = "1.20.5")
73+
@Deprecated(since = "1.20.5", forRemoval = true)
7174
public static final ItemFlag HIDE_ITEM_SPECIFICS = HIDE_ADDITIONAL_TOOLTIP;
7275
// Paper end
7376
}

paper-api/src/main/java/org/bukkit/inventory/ItemStack.java

+20-20
Original file line numberDiff line numberDiff line change
@@ -369,21 +369,21 @@ public int hashCode() {
369369
/**
370370
* Checks if this ItemStack contains the given {@link Enchantment}
371371
*
372-
* @param ench Enchantment to test
372+
* @param enchant Enchantment to test
373373
* @return True if this has the given enchantment
374374
*/
375-
public boolean containsEnchantment(@NotNull Enchantment ench) {
376-
return this.craftDelegate.containsEnchantment(ench); // Paper - delegate
375+
public boolean containsEnchantment(@NotNull Enchantment enchant) {
376+
return this.craftDelegate.containsEnchantment(enchant); // Paper - delegate
377377
}
378378

379379
/**
380380
* Gets the level of the specified enchantment on this item stack
381381
*
382-
* @param ench Enchantment to check
382+
* @param enchant Enchantment to check
383383
* @return Level of the enchantment, or 0
384384
*/
385-
public int getEnchantmentLevel(@NotNull Enchantment ench) {
386-
return this.craftDelegate.getEnchantmentLevel(ench); // Paper - delegate
385+
public int getEnchantmentLevel(@NotNull Enchantment enchant) {
386+
return this.craftDelegate.getEnchantmentLevel(enchant); // Paper - delegate
387387
}
388388

389389
/**
@@ -423,21 +423,21 @@ public void addEnchantments(@NotNull Map<Enchantment, Integer> enchantments) {
423423
* If this item stack already contained the given enchantment (at any
424424
* level), it will be replaced.
425425
*
426-
* @param ench Enchantment to add
426+
* @param enchant Enchantment to add
427427
* @param level Level of the enchantment
428428
* @throws IllegalArgumentException if enchantment null, or enchantment is
429429
* not applicable
430430
*/
431431
@Utility
432-
public void addEnchantment(@NotNull Enchantment ench, int level) {
433-
Preconditions.checkArgument(ench != null, "Enchantment cannot be null");
434-
if ((level < ench.getStartLevel()) || (level > ench.getMaxLevel())) {
435-
throw new IllegalArgumentException("Enchantment level is either too low or too high (given " + level + ", bounds are " + ench.getStartLevel() + " to " + ench.getMaxLevel() + ")");
436-
} else if (!ench.canEnchantItem(this)) {
432+
public void addEnchantment(@NotNull Enchantment enchant, int level) {
433+
Preconditions.checkArgument(enchant != null, "Enchantment cannot be null");
434+
if ((level < enchant.getStartLevel()) || (level > enchant.getMaxLevel())) {
435+
throw new IllegalArgumentException("Enchantment level is either too low or too high (given " + level + ", bounds are " + enchant.getStartLevel() + " to " + enchant.getMaxLevel() + ")");
436+
} else if (!enchant.canEnchantItem(this)) {
437437
throw new IllegalArgumentException("Specified enchantment cannot be applied to this itemstack");
438438
}
439439

440-
addUnsafeEnchantment(ench, level);
440+
addUnsafeEnchantment(enchant, level);
441441
}
442442

443443
/**
@@ -465,22 +465,22 @@ public void addUnsafeEnchantments(@NotNull Map<Enchantment, Integer> enchantment
465465
* This method is unsafe and will ignore level restrictions or item type.
466466
* Use at your own discretion.
467467
*
468-
* @param ench Enchantment to add
468+
* @param enchant Enchantment to add
469469
* @param level Level of the enchantment
470470
*/
471-
public void addUnsafeEnchantment(@NotNull Enchantment ench, int level) {
472-
this.craftDelegate.addUnsafeEnchantment(ench, level); // Paper - delegate
471+
public void addUnsafeEnchantment(@NotNull Enchantment enchant, int level) {
472+
this.craftDelegate.addUnsafeEnchantment(enchant, level); // Paper - delegate
473473
}
474474

475475
/**
476476
* Removes the specified {@link Enchantment} if it exists on this
477477
* ItemStack
478478
*
479-
* @param ench Enchantment to remove
479+
* @param enchant Enchantment to remove
480480
* @return Previous level, or 0
481481
*/
482-
public int removeEnchantment(@NotNull Enchantment ench) {
483-
return this.craftDelegate.removeEnchantment(ench); // Paper - delegate
482+
public int removeEnchantment(@NotNull Enchantment enchant) {
483+
return this.craftDelegate.removeEnchantment(enchant); // Paper - delegate
484484
}
485485

486486
/**
@@ -494,7 +494,7 @@ public void removeEnchantments() {
494494
@NotNull
495495
@Utility
496496
public Map<String, Object> serialize() {
497-
Map<String, Object> result = new LinkedHashMap<String, Object>();
497+
Map<String, Object> result = new LinkedHashMap<>();
498498

499499
result.put("v", Bukkit.getUnsafe().getDataVersion()); // Include version to indicate we are using modern material names (or LEGACY prefix)
500500
result.put("type", getType().name());

paper-api/src/main/java/org/bukkit/inventory/meta/EnchantmentStorageMeta.java

+10-10
Original file line numberDiff line numberDiff line change
@@ -22,19 +22,19 @@ public interface EnchantmentStorageMeta extends ItemMeta {
2222
/**
2323
* Checks for storage of the specified enchantment.
2424
*
25-
* @param ench enchantment to check
25+
* @param enchant enchantment to check
2626
* @return true if this enchantment is stored in this meta
2727
*/
28-
boolean hasStoredEnchant(@NotNull Enchantment ench);
28+
boolean hasStoredEnchant(@NotNull Enchantment enchant);
2929

3030
/**
3131
* Checks for the level of the stored enchantment.
3232
*
33-
* @param ench enchantment to check
33+
* @param enchant enchantment to check
3434
* @return The level that the specified stored enchantment has, or 0 if
3535
* none
3636
*/
37-
int getStoredEnchantLevel(@NotNull Enchantment ench);
37+
int getStoredEnchantLevel(@NotNull Enchantment enchant);
3838

3939
/**
4040
* Gets a copy the stored enchantments in this ItemMeta.
@@ -47,34 +47,34 @@ public interface EnchantmentStorageMeta extends ItemMeta {
4747
/**
4848
* Stores the specified enchantment in this item meta.
4949
*
50-
* @param ench Enchantment to store
50+
* @param enchant Enchantment to store
5151
* @param level Level for the enchantment
5252
* @param ignoreLevelRestriction this indicates the enchantment should be
5353
* applied, ignoring the level limit
5454
* @return true if the item meta changed as a result of this call, false
5555
* otherwise
5656
* @throws IllegalArgumentException if enchantment is null
5757
*/
58-
boolean addStoredEnchant(@NotNull Enchantment ench, int level, boolean ignoreLevelRestriction);
58+
boolean addStoredEnchant(@NotNull Enchantment enchant, int level, boolean ignoreLevelRestriction);
5959

6060
/**
6161
* Remove the specified stored enchantment from this item meta.
6262
*
63-
* @param ench Enchantment to remove
63+
* @param enchant Enchantment to remove
6464
* @return true if the item meta changed as a result of this call, false
6565
* otherwise
6666
* @throws IllegalArgumentException if enchantment is null
6767
*/
68-
boolean removeStoredEnchant(@NotNull Enchantment ench) throws IllegalArgumentException;
68+
boolean removeStoredEnchant(@NotNull Enchantment enchant) throws IllegalArgumentException;
6969

7070
/**
7171
* Checks if the specified enchantment conflicts with any enchantments in
7272
* this ItemMeta.
7373
*
74-
* @param ench enchantment to test
74+
* @param enchant enchantment to test
7575
* @return true if the enchantment conflicts, false otherwise
7676
*/
77-
boolean hasConflictingStoredEnchant(@NotNull Enchantment ench);
77+
boolean hasConflictingStoredEnchant(@NotNull Enchantment enchant);
7878

7979
@Override
8080
@NotNull

paper-api/src/main/java/org/bukkit/inventory/meta/ItemMeta.java

+10-10
Original file line numberDiff line numberDiff line change
@@ -400,18 +400,18 @@ default void displayName(final net.kyori.adventure.text.@Nullable Component disp
400400
/**
401401
* Checks for existence of the specified enchantment.
402402
*
403-
* @param ench enchantment to check
403+
* @param enchant enchantment to check
404404
* @return true if this enchantment exists for this meta
405405
*/
406-
boolean hasEnchant(@NotNull Enchantment ench);
406+
boolean hasEnchant(@NotNull Enchantment enchant);
407407

408408
/**
409409
* Checks for the level of the specified enchantment.
410410
*
411-
* @param ench enchantment to check
411+
* @param enchant enchantment to check
412412
* @return The level that the specified enchantment has, or 0 if none
413413
*/
414-
int getEnchantLevel(@NotNull Enchantment ench);
414+
int getEnchantLevel(@NotNull Enchantment enchant);
415415

416416
/**
417417
* Returns a copy the enchantments in this ItemMeta. <br>
@@ -425,23 +425,23 @@ default void displayName(final net.kyori.adventure.text.@Nullable Component disp
425425
/**
426426
* Adds the specified enchantment to this item meta.
427427
*
428-
* @param ench Enchantment to add
428+
* @param enchant Enchantment to add
429429
* @param level Level for the enchantment
430430
* @param ignoreLevelRestriction this indicates the enchantment should be
431431
* applied, ignoring the level limit
432432
* @return true if the item meta changed as a result of this call, false
433433
* otherwise
434434
*/
435-
boolean addEnchant(@NotNull Enchantment ench, int level, boolean ignoreLevelRestriction);
435+
boolean addEnchant(@NotNull Enchantment enchant, int level, boolean ignoreLevelRestriction);
436436

437437
/**
438438
* Removes the specified enchantment from this item meta.
439439
*
440-
* @param ench Enchantment to remove
440+
* @param enchant Enchantment to remove
441441
* @return true if the item meta changed as a result of this call, false
442442
* otherwise
443443
*/
444-
boolean removeEnchant(@NotNull Enchantment ench);
444+
boolean removeEnchant(@NotNull Enchantment enchant);
445445

446446
/**
447447
* Removes all enchantments from this item meta.
@@ -452,10 +452,10 @@ default void displayName(final net.kyori.adventure.text.@Nullable Component disp
452452
* Checks if the specified enchantment conflicts with any enchantments in
453453
* this ItemMeta.
454454
*
455-
* @param ench enchantment to test
455+
* @param enchant enchantment to test
456456
* @return true if the enchantment conflicts, false otherwise
457457
*/
458-
boolean hasConflictingEnchant(@NotNull Enchantment ench);
458+
boolean hasConflictingEnchant(@NotNull Enchantment enchant);
459459

460460
/**
461461
* Set itemflags which should be ignored when rendering a ItemStack in the Client. This Method does silently ignore double set itemFlags.

paper-api/src/main/java/org/bukkit/inventory/meta/components/JukeboxPlayableComponent.java

+11-2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import org.bukkit.NamespacedKey;
55
import org.bukkit.configuration.serialization.ConfigurationSerializable;
66
import org.jetbrains.annotations.ApiStatus;
7+
import org.jetbrains.annotations.Contract;
78
import org.jetbrains.annotations.NotNull;
89
import org.jetbrains.annotations.Nullable;
910

@@ -47,13 +48,21 @@ public interface JukeboxPlayableComponent extends ConfigurationSerializable {
4748
* Gets if the song will show in the item tooltip.
4849
*
4950
* @return if the song will show in the tooltip
51+
* @deprecated no longer available on the component directly
5052
*/
51-
boolean isShowInTooltip();
53+
@Deprecated(since = "1.21.5", forRemoval = true)
54+
@Contract("-> true") // todo add new item flag for compat? or just tell people to use the new data component api
55+
default boolean isShowInTooltip() {
56+
return true;
57+
}
5258

5359
/**
5460
* Sets if the song will show in the item tooltip.
5561
*
5662
* @param show true if the song will show in the tooltip
63+
* @deprecated no longer available on the component directly
5764
*/
58-
void setShowInTooltip(boolean show);
65+
@Deprecated(since = "1.21.5", forRemoval = true)
66+
default void setShowInTooltip(boolean show) {
67+
}
5968
}

0 commit comments

Comments
 (0)