PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Inventory.java

74 lines
4.0 KiB
Java
Raw Normal View History

2014-11-08 20:27:09 +01:00
////////////////////////////////////////////////////////////////////////////////////////////////////
// PlotSquared - A plot manager and world generator for the Bukkit API /
// Copyright (c) 2014 IntellectualSites/IntellectualCrafters /
// /
// This program is free software; you can redistribute it and/or modify /
// it under the terms of the GNU General Public License as published by /
// the Free Software Foundation; either version 3 of the License, or /
// (at your option) any later version. /
// /
// This program is distributed in the hope that it will be useful, /
// but WITHOUT ANY WARRANTY; without even the implied warranty of /
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the /
// GNU General Public License for more details. /
// /
// You should have received a copy of the GNU General Public License /
// along with this program; if not, write to the Free Software Foundation, /
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA /
// /
// You can contact us via: support@intellectualsites.com /
////////////////////////////////////////////////////////////////////////////////////////////////////
2014-09-22 13:02:14 +02:00
package com.intellectualcrafters.plot.commands;
2015-01-13 17:38:15 +01:00
import java.util.ArrayList;
2014-09-22 13:02:14 +02:00
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
2015-06-05 16:08:16 +02:00
import com.intellectualcrafters.plot.config.C;
2015-02-22 08:14:49 +01:00
import com.intellectualcrafters.plot.object.BukkitPlayer;
2015-02-21 12:38:44 +01:00
import com.intellectualcrafters.plot.object.PlotPlayer;
2014-09-22 13:02:14 +02:00
public class Inventory extends SubCommand {
2014-11-05 04:42:08 +01:00
public Inventory() {
super("inventory", "plots.inventory", "Open a command inventory", "inventory", "inv", CommandCategory.INFO, true);
}
2015-02-23 02:32:27 +01:00
2014-11-05 04:42:08 +01:00
@Override
2015-02-21 08:30:55 +01:00
public boolean execute(final PlotPlayer plr, final String... args) {
2014-11-05 04:42:08 +01:00
final ArrayList<SubCommand> cmds = new ArrayList<>();
for (final SubCommand cmd : MainCommand.subCommands) {
if (cmd.permission.hasPermission(plr)) {
cmds.add(cmd);
}
}
final int size = 9 * (int) Math.ceil(cmds.size() / 9.0);
final org.bukkit.inventory.Inventory inventory = Bukkit.createInventory(null, size, "PlotSquared Commands");
for (final SubCommand cmd : cmds) {
inventory.addItem(getItem(cmd));
}
2015-02-22 08:14:49 +01:00
((BukkitPlayer) plr).player.openInventory(inventory);
2014-11-05 04:42:08 +01:00
return true;
}
2015-02-23 02:32:27 +01:00
2014-11-05 04:42:08 +01:00
private ItemStack getItem(final SubCommand cmd) {
final ItemStack stack = new ItemStack(Material.COMMAND);
final ItemMeta meta = stack.getItemMeta();
{
meta.setDisplayName(ChatColor.GREEN + cmd.cmd + ChatColor.DARK_GRAY + " [" + ChatColor.GREEN + cmd.alias + ChatColor.DARK_GRAY + "]");
meta.setLore(new ArrayList<String>() {
{
2015-05-24 03:00:16 +02:00
add(C.INVENTORY_CATEGORY.s().replace("{category}", cmd.category.toString()));
add(C.INVENTORY_DESC.s().replace("{desc}", cmd.description));
add(C.INVENTORY_USAGE.s().replace("{usage}", "/plot " + cmd.usage));
2014-11-05 04:42:08 +01:00
}
});
}
stack.setItemMeta(meta);
return stack;
}
2014-09-22 13:02:14 +02:00
}