From f555f194e16d19a22e70de07d2315bf1d0c6bd48 Mon Sep 17 00:00:00 2001 From: Sauilitired Date: Tue, 18 Nov 2014 23:17:55 +0100 Subject: [PATCH] Started working on a plot info inventory --- .../plot/commands/Info.java | 6 ++ .../plot/object/InfoInventory.java | 98 +++++++++++++++++++ 2 files changed, 104 insertions(+) create mode 100644 PlotSquared/src/main/java/com/intellectualcrafters/plot/object/InfoInventory.java diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Info.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Info.java index a35c5c460..083c4663b 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Info.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Info.java @@ -24,6 +24,7 @@ package com.intellectualcrafters.plot.commands; import com.intellectualcrafters.plot.PlotMain; import com.intellectualcrafters.plot.config.C; import com.intellectualcrafters.plot.database.DBFunc; +import com.intellectualcrafters.plot.object.InfoInventory; import com.intellectualcrafters.plot.object.Plot; import com.intellectualcrafters.plot.object.PlotId; import com.intellectualcrafters.plot.object.PlotWorld; @@ -91,6 +92,11 @@ public class Info extends SubCommand { } } + if (args.length == 1 && args[0].equalsIgnoreCase("inv")) { + new InfoInventory(plot, player).build().display(); + return true; + } + final boolean hasOwner = plot.hasOwner(); boolean containsEveryone; boolean trustedEveryone; diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/InfoInventory.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/InfoInventory.java new file mode 100644 index 000000000..2874493ca --- /dev/null +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/InfoInventory.java @@ -0,0 +1,98 @@ +package com.intellectualcrafters.plot.object; + +import com.intellectualcrafters.plot.util.UUIDHandler; +import org.bukkit.Bukkit; +import org.bukkit.ChatColor; +import org.bukkit.Material; +import org.bukkit.entity.Player; +import org.bukkit.inventory.Inventory; +import org.bukkit.inventory.InventoryHolder; +import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.meta.ItemMeta; + +import java.util.ArrayList; +import java.util.List; + +/** + * Created 2014-11-18 for PlotSquared + * + * @author Citymonstret + */ +public class InfoInventory implements InventoryHolder { + + private final Plot plot; + private final Inventory inventory; + private final Player player; + + /** + * Constructor + * + * @param plot from which we take information + */ + public InfoInventory(final Plot plot, final Player player) { + this.plot = plot; + this.player = player; + this.inventory = Bukkit.createInventory(this, 9, "Plot: " + plot.id.toString()); + } + + @Override + public Inventory getInventory() { + return inventory; + } + + public InfoInventory build() { + ItemStack generalInfo = + getItem(Material.EMERALD, "&cPlot Info", + "&cID: &6" + plot.getId().toString(), + "&cOwner: &6" + UUIDHandler.getName(plot.getOwner()), + "&cAlias: &6" + plot.settings.getAlias(), + "&cBiome: &6" + plot.settings.getBiome().toString().replaceAll("_", "").toLowerCase(), + "&cCan Build: &6" + plot.hasRights(player), + "&cIs Denied: &6" + plot.deny_entry(player) + ); + ItemStack helpers = + getItem(Material.EMERALD, "&cHelpers", + "&cAmount: &6" + plot.helpers.size(), + "&8Click to view a list of the plot helpers" + ); + ItemStack trusted = + getItem(Material.EMERALD, "&cTrusted", + "&cAmount: &6" + plot.trusted.size(), + "&8Click to view a list of trusted players" + ); + ItemStack denied = + getItem(Material.EMERALD, "&cDenied", + "&cAmount: &6" + plot.denied.size(), + "&8Click to view a list of denied players" + ); + ItemStack flags = + getItem(Material.EMERALD, "&cFlags", + "&cAmount: &6" + plot.settings.getFlags().size(), + "&8Click to view a list of plot flags" + ); + inventory.setItem(2, generalInfo); + inventory.setItem(3, helpers); + inventory.setItem(4, trusted); + inventory.setItem(5, denied); + inventory.setItem(6, flags); + return this; + } + + public InfoInventory display() { + player.closeInventory(); + player.openInventory(inventory); + return this; + } + + private ItemStack getItem(Material material, String name, String... lore) { + ItemStack stack = new ItemStack(material); + ItemMeta meta = stack.getItemMeta(); + meta.setDisplayName(ChatColor.translateAlternateColorCodes('&', name)); + List lList = new ArrayList<>(); + for (String l : lore) + lList.add(ChatColor.translateAlternateColorCodes('&', l)); + meta.setLore(lList); + stack.setItemMeta(meta); + return stack; + } +}