Skip to content

Commit 573aae0

Browse files
authored
Fix /skull issues on 1.20.4+ (#6188)
Fixes #6124
1 parent c43ad26 commit 573aae0

File tree

1 file changed

+31
-7
lines changed

1 file changed

+31
-7
lines changed

Essentials/src/main/java/com/earth2me/essentials/commands/Commandskull.java

Lines changed: 31 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import com.google.gson.JsonParser;
1010
import net.ess3.api.TranslatableException;
1111
import org.bukkit.Material;
12+
import org.bukkit.OfflinePlayer;
1213
import org.bukkit.Server;
1314
import org.bukkit.inventory.ItemStack;
1415
import org.bukkit.inventory.meta.SkullMeta;
@@ -108,7 +109,7 @@ private void editSkull(final User user, final User receive, final ItemStack stac
108109
ess.runTaskAsynchronously(() -> {
109110
// Run this stuff async because it causes an HTTP request
110111

111-
final String shortOwnerName;
112+
String shortOwnerName;
112113
if (URL_VALUE_PATTERN.matcher(owner).matches()) {
113114
if (!playerProfileSupported) {
114115
user.sendTl("unsupportedFeature");
@@ -129,23 +130,46 @@ private void editSkull(final User user, final User receive, final ItemStack stac
129130

130131
shortOwnerName = owner.substring(0, 7);
131132
} else {
132-
//noinspection deprecation
133-
skullMeta.setOwner(owner);
134-
shortOwnerName = owner;
133+
if (playerProfileSupported) {
134+
try {
135+
PlayerProfile profile = ess.getServer().createPlayerProfile(null, owner);
136+
profile = profile.update().join();
137+
138+
if (profile != null) {
139+
skullMeta.setOwnerProfile(profile);
140+
}
141+
if (skullMeta.getOwnerProfile() == null) {
142+
final OfflinePlayer offline = ess.getServer().getOfflinePlayer(owner);
143+
skullMeta.setOwningPlayer(offline);
144+
}
145+
146+
shortOwnerName = owner;
147+
} catch (final Exception e) {
148+
//noinspection deprecation
149+
skullMeta.setOwner(owner);
150+
shortOwnerName = owner;
151+
}
152+
} else {
153+
//noinspection deprecation
154+
skullMeta.setOwner(owner);
155+
shortOwnerName = owner;
156+
}
135157
}
136158
skullMeta.setDisplayName("§fSkull of " + shortOwnerName);
137159

160+
final String shortNameFinal = shortOwnerName;
161+
138162
ess.scheduleSyncDelayedTask(() -> {
139163
stack.setItemMeta(skullMeta);
140164
if (spawn) {
141165
Inventories.addItem(receive.getBase(), stack);
142-
receive.sendTl("givenSkull", shortOwnerName);
166+
receive.sendTl("givenSkull", shortNameFinal);
143167
if (user != receive) {
144-
user.sendTl("givenSkullOther", receive.getDisplayName(), shortOwnerName);
168+
user.sendTl("givenSkullOther", receive.getDisplayName(), shortNameFinal);
145169
}
146170
return;
147171
}
148-
user.sendTl("skullChanged", shortOwnerName);
172+
user.sendTl("skullChanged", shortNameFinal);
149173
});
150174
});
151175
}

0 commit comments

Comments
 (0)