From 0f9232d016c118f37b14ecdd422521276c8a8c25 Mon Sep 17 00:00:00 2001 From: BONNe Date: Sat, 30 Mar 2019 23:32:31 +0200 Subject: [PATCH] Add ability to change icon in Warps panel. (#24) --- .../bentobox/warps/WarpPanelManager.java | 30 +++++++++++++++++-- .../world/bentobox/warps/config/Settings.java | 27 +++++++++++++++++ src/main/resources/config.yml | 7 ++++- 3 files changed, 61 insertions(+), 3 deletions(-) diff --git a/src/main/java/world/bentobox/warps/WarpPanelManager.java b/src/main/java/world/bentobox/warps/WarpPanelManager.java index dc8d783..660cdf3 100644 --- a/src/main/java/world/bentobox/warps/WarpPanelManager.java +++ b/src/main/java/world/bentobox/warps/WarpPanelManager.java @@ -14,6 +14,8 @@ import world.bentobox.bentobox.api.panels.PanelItem; import world.bentobox.bentobox.api.panels.builders.PanelBuilder; import world.bentobox.bentobox.api.panels.builders.PanelItemBuilder; import world.bentobox.bentobox.api.user.User; +import world.bentobox.bentobox.util.ItemParser; + public class WarpPanelManager { @@ -29,8 +31,32 @@ public class WarpPanelManager { private PanelItem getPanelItem(World world, UUID warpOwner) { // Return a sign panel item - return new PanelItemBuilder() - .icon(Material.SIGN) + + PanelItemBuilder builder = new PanelItemBuilder(); + + if (this.addon.getSettings().getIcon().equals("PLAYER")) + { + String playerName = this.addon.getPlayers().getName(warpOwner); + + if (!playerName.isEmpty()) + { + builder.icon(playerName); + } + else + { + // If player name is not found then use default icon. + + ItemStack itemStack = ItemParser.parse(this.addon.getSettings().getIcon() + ":1"); + builder.icon(itemStack == null ? Material.SIGN : itemStack.getType()); + } + } + else + { + ItemStack itemStack = ItemParser.parse(this.addon.getSettings().getIcon() + ":1"); + builder.icon(itemStack == null ? Material.SIGN : itemStack.getType()); + } + + return builder .name(addon.getPlugin().getPlayers().getName(warpOwner)) .description(getSign(world, warpOwner)) .clickHandler((panel, clicker, click, slot) -> { { diff --git a/src/main/java/world/bentobox/warps/config/Settings.java b/src/main/java/world/bentobox/warps/config/Settings.java index 89d2f67..b728e3f 100644 --- a/src/main/java/world/bentobox/warps/config/Settings.java +++ b/src/main/java/world/bentobox/warps/config/Settings.java @@ -29,6 +29,13 @@ public class Settings implements DataObject @ConfigEntry(path = "welcomeLine") 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.") + @ConfigEntry(path = "icon") + private String icon = "SIGN"; + @ConfigComment("") @ConfigComment("This list stores GameModes in which Level addon should not work.") @ConfigComment("To disable addon it is necessary to write its name in new line that starts with -. Example:") @@ -139,4 +146,24 @@ public class Settings implements DataObject { this.disabledGameModes = disabledGameModes; } + + + /** + * This method returns the icon object. + * @return the icon object. + */ + public String getIcon() + { + return icon; + } + + + /** + * This method sets the icon object value. + * @param icon the icon object new value. + */ + public void setIcon(String icon) + { + this.icon = icon; + } } diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index 95291ee..fa03767 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -11,7 +11,12 @@ warplevelrestriction: 10 # Text that player must put on sign to make it a warp sign # 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: 'SIGN' +# # This list stores GameModes in which Level addon should not work. # To disable addon it is necessary to write its name in new line that starts with -. Example: # disabled-gamemodes: