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

Fix/head guis #193

Open
wants to merge 4 commits into
base: master
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
1 change: 1 addition & 0 deletions .envrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
use nix
4 changes: 2 additions & 2 deletions .github/workflows/publish_to_nexus.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ jobs:

steps:
- uses: actions/checkout@v3.0.2
- name: Set up JDK 17
- name: Set up JDK 21
uses: actions/setup-java@v3.3.0
with:
distribution: temurin
java-version: 17
java-version: 21
- name: Build with Gradle
run: ./gradlew --build-cache build
- name: Test with Gradle
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/verify.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ jobs:

steps:
- uses: actions/checkout@v3.0.2
- name: Set up JDK 17
- name: Set up JDK 21
uses: actions/setup-java@v3.3.0
with:
distribution: temurin
java-version: 17
java-version: 21
- name: Build with Gradle
run: ./gradlew --build-cache build
- name: Test with Gradle
Expand Down
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,5 @@ gradle-app.setting
*.iws

# IntelliJ
out/
out/
.direnv
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ public interface IMaterialsManager {
Material getLongGrass();

ItemStack getPlayerHead(UUID owner);
ItemStack getPlayerHead(OfflinePlayer owner);
ItemStack getPlayerHead(UUID owner, String texture);
ItemStack getPlayerHead(OfflinePlayer owner, String texture);
ItemStack getPlayerHead(String texture);
Comment on lines +23 to +25
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need all those methods? I'd probably just add the method that takes a UUID and a texture - but we should avoid Stringly typed arguments as they can be confusing (you are passing a URL string to it?). The existing methods shouldn't be touched imo.

Copy link
Member Author

@rainbowdashlabs rainbowdashlabs Oct 9, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is mainly about keeping compatibility with legacy, without reinventing the wheel. I mainly went for a "make it work approach" instead of producing fine code.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually this is a huge mess right now. legacy might not even work anymore right now...
This is a big abstraction issue, since legacy requires the texture as base64 encoded whatever and latest requires the url encoded in the base46 string

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The latest way might not even work on older paper versions between 1.13 and 1.18 I think. once again I hate multiversion support xD

Copy link
Member Author

@rainbowdashlabs rainbowdashlabs Oct 9, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Esp since the same method is used to 1. create a player head for the requested owner and 2. to create a player head with some texture. This really messed it up a lot.
Another issue is that the skulls class is part of the core and has to work with two completely different approaches of creating skulls.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, for proper multi-version support the old strategy must exist as fallback on versions that don't have the bukkit PlayerProfile API. I think it's fine to extract the url only as needed. Or alternatively pass an object that holds both the base64 string and the url instead of just a string - that would also help with proper typing.


ItemStack getWitherSkull();

Expand Down
43 changes: 17 additions & 26 deletions LandLord-core/src/main/java/biz/princeps/landlord/util/Skulls.java
Original file line number Diff line number Diff line change
@@ -1,21 +1,19 @@
package biz.princeps.landlord.util;

import biz.princeps.landlord.api.ILandLord;
import com.mojang.authlib.GameProfile;
import com.mojang.authlib.properties.Property;
import com.google.gson.Gson;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.SkullMeta;

import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.Base64;
import java.util.List;
import java.util.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QubmV0L3RleHR1cmUvZWRmNWMyZjg5M2JkM2Y4OWNhNDA3MDNkZWQzZTQyZGQwZmJkYmE2ZjY3NjhjODc4OWFmZGZmMWZhNzhiZjYifX19"),
BACK5("eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvYzQ5ZDI3MWM1ZGY4NGY4YTNjOGFhNWQxNTQyN2Y2MjgzOTM0MWRhYjUyYzYxOWE1OTg3ZDM4ZmJlMThlNDY0In19fQ=="),
BACK10("eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvZjg0ZjU5NzEzMWJiZTI1ZGMwNThhZjg4OGNiMjk4MzFmNzk1OTliYzY3Yzk1YzgwMjkyNWNlNGFmYmEzMzJmYyJ9fX0="),
Expand All @@ -37,9 +35,11 @@ public enum Skulls {
;

final String texture;
final Profile profile;

Skulls(String texture) {
this.texture = texture;
profile = new Gson().fromJson(new String(Base64.getDecoder().decode(texture)), Profile.class);
}

public static List<Skulls> numToSkull(int num) {
Expand Down Expand Up @@ -86,26 +86,8 @@ public static List<Skulls> numToSkull(int num) {
}

public ItemStack getSkull(ILandLord plugin) {
UUID uuid = UUID.randomUUID();
ItemStack head = plugin.getMaterialsManager().getPlayerHead(uuid);
if (texture.isEmpty())
return head;

SkullMeta headMeta = (SkullMeta) head.getItemMeta();
GameProfile profile = new GameProfile(uuid, uuid.toString().substring(0, 16));

profile.getProperties().put("textures", new Property("textures", texture));

try {
Field profileField = headMeta.getClass().getDeclaredField("profile");
profileField.setAccessible(true);
profileField.set(headMeta, profile);

} catch (IllegalArgumentException | NoSuchFieldException | SecurityException | IllegalAccessException error) {
error.printStackTrace();
}
head.setItemMeta(headMeta);
return head;
UUID uuid = plugin.getServer().getOnlinePlayers().stream().findAny().get().getUniqueId();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the intention here? I think generating a random UUID here was fine before.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh yes it actually is fine again. It wasnt in a previous iteration

return plugin.getMaterialsManager().getPlayerHead(uuid, profile.textures.SKIN.url);
}

@Override
Expand All @@ -114,4 +96,13 @@ public String toString() {
this.name() +
'}';
}

public record Profile(Textures textures) {
}

public record Textures(Skin SKIN) {
}

public record Skin(String url) {
}
rainbowdashlabs marked this conversation as resolved.
Show resolved Hide resolved
}
8 changes: 5 additions & 3 deletions LandLord-latest/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
plugins {
id("com.github.johnrengelman.shadow") version "8.1.1"
id("com.gradleup.shadow") version "8.3.1"
id("biz.princeps.library-conventions")
}

dependencies {
implementation(project(":LandLord-core"))
compileOnly("org.spigotmc:spigot-api:1.21-R0.1-SNAPSHOT")
compileOnly("io.papermc.paper:paper-api:1.21.1-R0.1-SNAPSHOT")
compileOnly("com.sk89q.worldedit:worldedit-bukkit:7.2.20")
compileOnly("com.sk89q.worldguard:worldguard-bukkit:7.0.5")
compileOnly("com.sk89q.worldguard:worldguard-bukkit:7.0.5") {
exclude("org.spigotmc")
}
compileOnly("io.papermc:paperlib:1.0.8")
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,19 @@

import biz.princeps.landlord.api.ILandLord;
import biz.princeps.landlord.api.IMaterialsManager;
import biz.princeps.landlord.util.Skulls;
import com.destroystokyo.paper.profile.PlayerProfile;
import com.google.gson.Gson;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.OfflinePlayer;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.SkullMeta;
import org.bukkit.profile.PlayerTextures;

import java.net.MalformedURLException;
import java.net.URL;
import java.util.Base64;
import java.util.UUID;

public class MaterialsManager implements IMaterialsManager {
Expand Down Expand Up @@ -38,18 +46,40 @@ public Material getLongGrass() {

@Override
public ItemStack getPlayerHead(UUID owner) {
return getPlayerHead(plugin.getServer().getOfflinePlayer(owner));
}

@Override
public ItemStack getPlayerHead(OfflinePlayer owner) {
ItemStack skull = new ItemStack(Material.PLAYER_HEAD);
SkullMeta itemMeta = (SkullMeta) skull.getItemMeta();
itemMeta.setOwnerProfile(owner.getPlayerProfile());
itemMeta.setOwningPlayer(Bukkit.getOfflinePlayer(owner));
skull.setItemMeta(itemMeta);
return skull;
}

@Override
public ItemStack getPlayerHead(UUID owner, String url) {
return getPlayerHead(url);
}

@Override
public ItemStack getPlayerHead(OfflinePlayer owner, String url) {
return getPlayerHead(url);
}

@Override
public ItemStack getPlayerHead(String url) {
PlayerProfile profile = Bukkit.createProfile(UUID.randomUUID());
PlayerTextures textures = profile.getTextures();
try {
textures.setSkin(new URL(url));
rainbowdashlabs marked this conversation as resolved.
Show resolved Hide resolved
} catch (MalformedURLException e) {
throw new RuntimeException(e);
}
profile.setTextures(textures);
ItemStack stack = ItemStack.of(Material.PLAYER_HEAD);
SkullMeta meta = (SkullMeta) stack.getItemMeta();
meta.setPlayerProfile(profile);
stack.setItemMeta(meta);
return stack;
}

@Override
public ItemStack getWitherSkull() {
return new ItemStack(Material.WITHER_SKELETON_SKULL);
Expand Down
2 changes: 1 addition & 1 deletion LandLord-legacy/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
plugins {
id("com.github.johnrengelman.shadow") version "8.1.1"
id("com.gradleup.shadow") version "8.3.1"
id("biz.princeps.library-conventions")
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import biz.princeps.landlord.api.ILandLord;
import biz.princeps.landlord.api.IMaterialsManager;
import org.apache.commons.lang.NotImplementedException;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.OfflinePlayer;
import org.bukkit.entity.Player;
Expand Down Expand Up @@ -34,19 +36,29 @@ public Material getLongGrass() {
}

@Override
public ItemStack getPlayerHead(UUID owner) {
return getPlayerHead(plugin.getServer().getOfflinePlayer(owner));
public ItemStack getPlayerHead(UUID owner, String texture) {
return getPlayerHead(plugin.getServer().getOfflinePlayer(owner), texture);
}

@Override
public ItemStack getPlayerHead(OfflinePlayer owner) {
public ItemStack getPlayerHead(UUID owner) {
ItemStack skull = new ItemStack(Material.SKULL_ITEM);
SkullMeta itemMeta = (SkullMeta) skull.getItemMeta();
itemMeta.setOwningPlayer(owner);
itemMeta.setOwningPlayer(Bukkit.getOfflinePlayer(owner));
skull.setItemMeta(itemMeta);
return skull;
}

@Override
public ItemStack getPlayerHead(OfflinePlayer owner, String texture) {
return getPlayerHead(texture);
}

@Override
public ItemStack getPlayerHead(String texture) {
throw new NotImplementedException();
}

@Override
public ItemStack getWitherSkull() {
return new ItemStack(Material.SKULL_ITEM, 1, (short) 1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ allprojects {
java {
withSourcesJar()
withJavadocJar()
sourceCompatibility = JavaVersion.VERSION_1_8
toolchain{
languageVersion = JavaLanguageVersion.of(21)
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.9-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.10-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
Expand Down
11 changes: 11 additions & 0 deletions shell.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{ pkgs ? import <nixpkgs> {}, ... }:

let
jdk = pkgs.jdk21;
gradle= pkgs.gradle.override { java = jdk; };
in
pkgs.mkShell
{
packages = with pkgs; [jdk gradle];
}

Loading