From 6568e6e41170ec2e2c3ab9eb34a81759a83c2452 Mon Sep 17 00:00:00 2001 From: Amaury Carrade Date: Sat, 21 May 2016 00:48:40 +0200 Subject: [PATCH] Made /maptool list clickable (closes #12) * NEW: a click on the maps names on /maptool list gives the maps. * NEW: added a tooltip on this list containing infos about the map. * NEW: light redesign of the list. --- .../commands/maptool/ListCommand.java | 39 ++++++++++++++++--- 1 file changed, 34 insertions(+), 5 deletions(-) diff --git a/src/main/java/fr/moribus/imageonmap/commands/maptool/ListCommand.java b/src/main/java/fr/moribus/imageonmap/commands/maptool/ListCommand.java index cead4e9..910cc90 100644 --- a/src/main/java/fr/moribus/imageonmap/commands/maptool/ListCommand.java +++ b/src/main/java/fr/moribus/imageonmap/commands/maptool/ListCommand.java @@ -21,8 +21,15 @@ package fr.moribus.imageonmap.commands.maptool; import fr.moribus.imageonmap.commands.IoMCommand; import fr.moribus.imageonmap.map.ImageMap; import fr.moribus.imageonmap.map.MapManager; +import fr.moribus.imageonmap.map.PosterMap; import fr.zcraft.zlib.components.commands.CommandException; import fr.zcraft.zlib.components.commands.CommandInfo; +import fr.zcraft.zlib.components.rawtext.RawText; +import fr.zcraft.zlib.components.rawtext.RawTextPart; +import fr.zcraft.zlib.tools.items.ItemStackBuilder; +import fr.zcraft.zlib.tools.text.RawMessage; +import org.bukkit.ChatColor; +import org.bukkit.Material; import org.bukkit.entity.Player; import java.util.List; @@ -42,13 +49,35 @@ public class ListCommand extends IoMCommand return; } - info(mapList.size() + " maps found."); - - String sMapList = mapList.get(0).getId(); + player.sendMessage(ChatColor.WHITE + "" + ChatColor.BOLD + mapList.size() + " maps found."); + + RawTextPart rawText = new RawText(""); + rawText = addMap(rawText, mapList.get(0)); + for(int i = 1, c = mapList.size(); i < c; i++) { - sMapList += "§7,§r" + mapList.get(i).getId(); + rawText = rawText.then(", ").color(ChatColor.GRAY); + rawText = addMap(rawText, mapList.get(i)); } - player.sendMessage(sMapList); + + RawMessage.send(player, rawText.build()); + } + + private RawTextPart addMap(RawTextPart rawText, ImageMap map) + { + final String size = map.getType() == ImageMap.Type.SINGLE ? "1×1" : ((PosterMap) map).getColumnCount() + "×" + ((PosterMap) map).getRowCount(); + + return rawText + .then(map.getId()) + .color(ChatColor.WHITE) + .command(GetCommand.class, map.getId()) + .hover(new ItemStackBuilder(Material.MAP) + .title(ChatColor.GREEN + "" + ChatColor.BOLD + map.getName()) + .lore(ChatColor.GRAY + map.getId() + ", " + size) + .lore("") + .lore(ChatColor.WHITE + "Click" + ChatColor.GRAY + " to get this map") + .hideAttributes() + .item() + ); } }