From c671e35661ec53859c69936865bb916c0f6f34bc Mon Sep 17 00:00:00 2001 From: tastybento Date: Thu, 22 Aug 2019 15:08:14 -0700 Subject: [PATCH] Adds the missing support for PLAYER_HEAD icons https://github.com/BentoBoxWorld/Warps/issues/38 --- .../java/world/bentobox/warps/WarpPanelManager.java | 12 ++++++++---- .../java/world/bentobox/warps/WarpSignsManager.java | 8 ++++++-- .../java/world/bentobox/warps/config/Settings.java | 7 ++++--- src/main/resources/config.yml | 9 ++++----- 4 files changed, 22 insertions(+), 14 deletions(-) diff --git a/src/main/java/world/bentobox/warps/WarpPanelManager.java b/src/main/java/world/bentobox/warps/WarpPanelManager.java index 819c80c..d25ceef 100644 --- a/src/main/java/world/bentobox/warps/WarpPanelManager.java +++ b/src/main/java/world/bentobox/warps/WarpPanelManager.java @@ -29,9 +29,7 @@ public class WarpPanelManager { } private PanelItem getPanelItem(World world, UUID warpOwner) { - // Return a sign panel item - return new PanelItemBuilder() - .icon(getSignIcon(world, warpOwner)) + PanelItemBuilder pib = new PanelItemBuilder() .name(addon.getPlugin().getPlayers().getName(warpOwner)) .description(getSign(world, warpOwner)) .clickHandler((panel, clicker, click, slot) -> { { @@ -39,7 +37,13 @@ public class WarpPanelManager { addon.getWarpSignsManager().warpPlayer(world, clicker, warpOwner); return true; } - }).build(); + }); + Material icon = getSignIcon(world, warpOwner); + if (icon.equals(Material.PLAYER_HEAD)) { + return pib.icon(addon.getPlayers().getName(warpOwner)).build(); + } else { + return pib.icon(icon).build(); + } } private Material getSignIcon(World world, UUID warpOwner) { diff --git a/src/main/java/world/bentobox/warps/WarpSignsManager.java b/src/main/java/world/bentobox/warps/WarpSignsManager.java index a2938a8..d500608 100644 --- a/src/main/java/world/bentobox/warps/WarpSignsManager.java +++ b/src/main/java/world/bentobox/warps/WarpSignsManager.java @@ -262,8 +262,12 @@ public class WarpSignsManager { // Remove any trailing blank lines result.removeIf(String::isEmpty); // Get the sign type - Material type = Material.valueOf(sign.getType().name().replace("WALL_", "")); - return new SignCache(result, type); + Material icon = Material.matchMaterial(addon.getSettings().getIcon()); + if (icon == null || icon.name().contains("SIGN")) { + return new SignCache(result, Material.valueOf(sign.getType().name().replace("WALL_", ""))); + } else { + return new SignCache(result, icon); + } } else { addon.getWarpSignsManager().removeWarp(world, uuid); } diff --git a/src/main/java/world/bentobox/warps/config/Settings.java b/src/main/java/world/bentobox/warps/config/Settings.java index a955b49..9f119bf 100644 --- a/src/main/java/world/bentobox/warps/config/Settings.java +++ b/src/main/java/world/bentobox/warps/config/Settings.java @@ -30,9 +30,10 @@ public class Settings implements ConfigObject private String welcomeLine; @ConfigComment("") - @ConfigComment("Icon that will be displayed in Warps list.") - @ConfigComment("It uses native Minecraft material strings, but using string 'PLAYER', it is possible to") - @ConfigComment("use player heads instead.") + @ConfigComment("Icon that will be displayed in Warps list. SIGN counts for any kind of sign and the type of") + @ConfigComment("wood used will be reflected in the panel if the server supports it.") + @ConfigComment("It uses native Minecraft material strings, but using string 'PLAYER_HEAD', it is possible to") + @ConfigComment("use player heads instead. Beware that Mojang API rate limiting may prevent heads from loading.") @ConfigEntry(path = "icon") private String icon = "SIGN"; diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index fa03767..93a29dc 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -12,9 +12,10 @@ warplevelrestriction: 10 # Not case sensitive! welcomeLine: '[Welcome]' # -# Icon that will be displayed in Warps list. -# It uses native Minecraft material strings, but using string 'PLAYER', it is possible to -# use player heads instead. +# Icon that will be displayed in Warps list. SIGN counts for any kind of sign and the type of +# wood used will be reflected in the panel if the server supports it. +# It uses native Minecraft material strings, but using string 'PLAYER_HEAD', it is possible to +# use player heads instead. Beware that Mojang API rate limiting may prevent heads from loading. icon: 'SIGN' # # This list stores GameModes in which Level addon should not work. @@ -22,5 +23,3 @@ icon: 'SIGN' # disabled-gamemodes: # - BSkyBlock disabled-gamemodes: [] -# -uniqueId: config