Added Permissions & Inventory Menu!

This commit is contained in:
jameslfc19 2019-09-19 15:16:53 +01:00
parent f89ecdd13c
commit 6c5f596fee
15 changed files with 324 additions and 294 deletions

31
pom.xml
View File

@ -8,12 +8,19 @@
<artifactId>ChestsPlusPlus</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
</properties>
<repositories>
<repository>
<id>mcstats</id>
<url>https://repo.mcstats.org/content/repositories/releases/</url>
</repository>
<repository>
<id>spigotmc-repo</id>
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
@ -28,6 +35,9 @@
<id>dmulloy2-repo</id>
<url>http://repo.dmulloy2.net/nexus/repository/public/</url>
</repository>
</repositories>
<dependencies>
@ -46,9 +56,9 @@
</dependency>
<dependency>
<groupId>com.comphenix.protocol</groupId>
<artifactId>ProtocolLib</artifactId>
<version>4.4.0</version>
<groupId>fr.minuskube.inv</groupId>
<artifactId>smart-invs</artifactId>
<version>1.2.7</version>
</dependency>
</dependencies>
@ -62,6 +72,21 @@
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.1.0</version>
<configuration>
<artifactSet>
<includes>
<include>fr.minuskube.inv*:*</include>
</includes>
</artifactSet>
<relocations>
<relocation>
<pattern>fr.minuskube.inv</pattern>
<shadedPattern>com.jamesdpeters.minecraft.chests</shadedPattern>
</relocation>
</relocations>
</configuration>
<executions>
<!--Tell the shade plugin when it should be run during a maven build-->
<execution>

View File

@ -6,12 +6,16 @@ import com.jamesdpeters.minecraft.chests.listeners.HopperListener;
import com.jamesdpeters.minecraft.chests.listeners.InventoryListener;
import com.jamesdpeters.minecraft.chests.serialize.InventoryStorage;
import com.jamesdpeters.minecraft.chests.serialize.LinkedChest;
import fr.minuskube.inv.InventoryManager;
import org.bukkit.configuration.serialization.ConfigurationSerialization;
import org.bukkit.plugin.java.JavaPlugin;
import java.io.IOException;
public class ChestsPlusPlus extends JavaPlugin {
public static JavaPlugin PLUGIN;
public static InventoryManager INVENTORY_MANAGER;
static {
ConfigurationSerialization.registerClass(LinkedChest.class, "LinkedChest");
@ -27,6 +31,10 @@ public class ChestsPlusPlus extends JavaPlugin {
getServer().getPluginManager().registerEvents(new HopperListener(),this);
new Config();
INVENTORY_MANAGER = new InventoryManager(this);
INVENTORY_MANAGER.init();
getLogger().info("Chests++ enabled!");
}

View File

@ -24,4 +24,8 @@ public class Messages {
public static void MUST_HOLD_SIGN(Player target){
target.sendMessage(ChatColor.RED+"You must be hold a sign to do that!");
}
public static void NO_PERMISSION(Player target){
target.sendMessage(ChatColor.RED+""+ChatColor.BOLD+"You don't have permission to do that!");
}
}

View File

@ -0,0 +1,10 @@
package com.jamesdpeters.minecraft.chests;
import java.util.stream.Stream;
public class Permissions {
public static final String ADD = "chestlink.add";
public static final String OPEN = "chestlink.add";
public static final String MENU = "chestlink.add";
}

View File

@ -16,6 +16,7 @@ import org.bukkit.event.block.SignChangeEvent;
import org.bukkit.inventory.EquipmentSlot;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.persistence.PersistentDataType;
import java.util.*;
@ -210,4 +211,13 @@ public class Utils {
}
return filters;
}
public static ItemStack getNamedItem(ItemStack item, String name){
ItemMeta meta = item.getItemMeta();
if(meta != null) {
meta.setDisplayName(name);
item.setItemMeta(meta);
}
return item;
}
}

View File

@ -1,9 +1,7 @@
package com.jamesdpeters.minecraft.chests.commands;
import com.jamesdpeters.minecraft.chests.ChestsPlusPlus;
import com.jamesdpeters.minecraft.chests.Config;
import com.jamesdpeters.minecraft.chests.Messages;
import com.jamesdpeters.minecraft.chests.Utils;
import com.jamesdpeters.minecraft.chests.*;
import com.jamesdpeters.minecraft.chests.inventories.ChestLinkMenu;
import com.jamesdpeters.minecraft.chests.serialize.InventoryStorage;
import org.apache.commons.lang.StringUtils;
import org.bukkit.Bukkit;
@ -32,7 +30,8 @@ public class RemoteChestCommand extends ServerCommand {
private enum OPTIONS {
ADD("/chestlink add <Group>", "Create/add a chest to a ChestLink group"),
OPEN("/chestlink open <Group>","Open the inventory of a ChestLink group");
OPEN("/chestlink open <Group>","Open the inventory of a ChestLink group"),
MENU("/chestlink menu","Open the ChestLink menu to display all groups!");
String description, commandHelp;
static List<String> valuesList;
@ -77,10 +76,15 @@ public class RemoteChestCommand extends ServerCommand {
switch (OPTIONS.valueOf(args[0].toUpperCase())){
case ADD:
if(args.length > 1){
Block targetBlock = player.getTargetBlockExact(5);
if(targetBlock != null) Utils.createChestLink(player,targetBlock,args[1]);
else Messages.MUST_LOOK_AT_CHEST(player);
return true;
if(sender.hasPermission(Permissions.ADD)) {
Block targetBlock = player.getTargetBlockExact(5);
if (targetBlock != null) Utils.createChestLink(player, targetBlock, args[1]);
else Messages.MUST_LOOK_AT_CHEST(player);
return true;
} else {
Messages.NO_PERMISSION(player);
return true;
}
} else {
player.sendMessage(ChatColor.RED+OPTIONS.ADD.commandHelp);
player.sendMessage(ChatColor.RED+OPTIONS.ADD.description);
@ -88,14 +92,27 @@ public class RemoteChestCommand extends ServerCommand {
}
case OPEN:
if(args.length > 1){
InventoryStorage invs = Config.getInventoryStorage(player,args[1]);
Utils.openInventory(player,invs.getInventory());
return true;
if(sender.hasPermission(Permissions.OPEN)) {
InventoryStorage invs = Config.getInventoryStorage(player, args[1]);
Utils.openInventory(player, invs.getInventory());
return true;
} else {
Messages.NO_PERMISSION(player);
return true;
}
} else {
player.sendMessage(ChatColor.RED+OPTIONS.OPEN.commandHelp);
player.sendMessage(ChatColor.RED+OPTIONS.OPEN.description);
return true;
}
case MENU:
if(sender.hasPermission(Permissions.MENU)) {
ChestLinkMenu.getMenu(player).open(player);
return true;
} else {
Messages.NO_PERMISSION(player);
return true;
}
}
}

View File

@ -0,0 +1,62 @@
package com.jamesdpeters.minecraft.chests.inventories;
import com.jamesdpeters.minecraft.chests.ChestsPlusPlus;
import com.jamesdpeters.minecraft.chests.Utils;
import com.jamesdpeters.minecraft.chests.serialize.InventoryStorage;
import fr.minuskube.inv.ClickableItem;
import fr.minuskube.inv.SmartInventory;
import fr.minuskube.inv.content.InventoryContents;
import fr.minuskube.inv.content.InventoryProvider;
import fr.minuskube.inv.content.Pagination;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import java.util.ArrayList;
import java.util.List;
public class ChestLinkInventory implements InventoryProvider {
ArrayList<ItemStack> items;
SmartInventory inventory;
InventoryStorage storage;
public ChestLinkInventory(InventoryStorage storage){
items = new ArrayList<>();
this.storage = storage;
inventory = SmartInventory.builder()
.id("chestLinkInventory")
.title(storage.getIdentifier())
.provider(this)
.manager(ChestsPlusPlus.INVENTORY_MANAGER)
.build();
//inventory.setInsertable(true);
}
@Override
public void init(Player player, InventoryContents contents) {
Pagination pagination = contents.pagination();
List<ClickableItem> itemList = new ArrayList<>();
pagination.setItems(itemList.toArray(new ClickableItem[0]));
pagination.setItemsPerPage(28);
contents.fillBorders(ClickableItem.empty(Utils.getNamedItem(new ItemStack(Material.GRAY_STAINED_GLASS_PANE)," ")));
for(ClickableItem item : pagination.getPageItems()){
contents.add(item);
}
contents.set(5, 2, ClickableItem.of(Utils.getNamedItem(new ItemStack(Material.ARROW),"Previous"),
e -> inventory.open(player, pagination.previous().getPage())));
contents.set(5, 6, ClickableItem.of(Utils.getNamedItem(new ItemStack(Material.ARROW),"Next"),
e -> inventory.open(player, pagination.next().getPage())));
}
@Override
public void update(Player player, InventoryContents contents) {
}
}

View File

@ -0,0 +1,85 @@
package com.jamesdpeters.minecraft.chests.inventories;
import com.jamesdpeters.minecraft.chests.ChestsPlusPlus;
import com.jamesdpeters.minecraft.chests.Config;
import com.jamesdpeters.minecraft.chests.Utils;
import com.jamesdpeters.minecraft.chests.serialize.InventoryStorage;
import fr.minuskube.inv.ClickableItem;
import fr.minuskube.inv.SmartInventory;
import fr.minuskube.inv.content.InventoryContents;
import fr.minuskube.inv.content.InventoryProvider;
import fr.minuskube.inv.content.Pagination;
import fr.minuskube.inv.content.SlotIterator;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
public class ChestLinkMenu implements InventoryProvider {
public static HashMap<Player, SmartInventory> menus;
private Collection<InventoryStorage> storages;
private SmartInventory menu;
private ChestLinkMenu(Player player){
this.storages = Config.getPlayer(player).values();
menu = SmartInventory.builder()
.id("chestLinkMenu")
.title("Inventory Storage")
.provider(this)
.manager(ChestsPlusPlus.INVENTORY_MANAGER)
.build();
//menu.setInsertable(true);
}
public static SmartInventory getMenu(Player player){
if(menus == null) menus = new HashMap<>();
if(menus.containsKey(player)){
return menus.get(player);
} else {
menus.put(player, new ChestLinkMenu(player).getMenu());
return menus.get(player);
}
}
@Override
public void init(Player player, InventoryContents contents) {
Pagination pagination = contents.pagination();
List<ClickableItem> itemList = new ArrayList<>();
for(InventoryStorage storage : storages){
ClickableItem item = storage.getClickableItem(player);
//item.setRemoveable(true);
itemList.add(item);
}
pagination.setItems(itemList.toArray(new ClickableItem[0]));
pagination.setItemsPerPage(28);
contents.fillBorders(ClickableItem.empty(Utils.getNamedItem(new ItemStack(Material.GRAY_STAINED_GLASS_PANE)," ")));
for(ClickableItem item : pagination.getPageItems()){
contents.add(item);
}
contents.set(5, 2, ClickableItem.of(Utils.getNamedItem(new ItemStack(Material.ARROW),"Previous"),
e -> menu.open(player, pagination.previous().getPage())));
contents.set(5, 6, ClickableItem.of(Utils.getNamedItem(new ItemStack(Material.ARROW),"Next"),
e -> menu.open(player, pagination.next().getPage())));
}
@Override
public void update(Player player, InventoryContents contents) {
}
public SmartInventory getMenu() {
return menu;
}
}

View File

@ -28,30 +28,35 @@ public class ChestLinkListener implements Listener {
@EventHandler
public void playerInteract(BlockPlaceEvent event){
if(event.getBlockPlaced().getState() instanceof Sign){
if(event.getBlockAgainst().getState() instanceof Chest) {
new TempListener(){
@EventHandler
public void onSignChange(SignChangeEvent signChangeEvent){
if(event.getBlockPlaced().getLocation().equals(signChangeEvent.getBlock().getLocation())) {
Sign sign = (Sign) signChangeEvent.getBlock().getState();
ChestLinkInfo info = Utils.getChestLinkInfo(sign, signChangeEvent.getLines(), signChangeEvent.getPlayer());
if (info != null) {
Config.addChest(info.getPlayer(), info.getGroup(), event.getBlockAgainst().getLocation());
Messages.CHEST_ADDED(event.getPlayer(), info.getGroup(), event.getPlayer().getDisplayName());
setLine(sign,signChangeEvent,0, ChatColor.RED + signChangeEvent.getLine(0));
setLine(sign,signChangeEvent,1, ChatColor.GREEN + signChangeEvent.getLine(1));
setLine(sign,signChangeEvent,2, ChatColor.BOLD + event.getPlayer().getDisplayName());
sign.getPersistentDataContainer().set(Values.playerUUID, PersistentDataType.STRING, event.getPlayer().getUniqueId().toString());
sign.update();
if(event.getPlayer().hasPermission(Permissions.ADD)){
if(event.getBlockPlaced().getState() instanceof Sign){
if(event.getBlockAgainst().getState() instanceof Chest) {
new TempListener(){
@EventHandler
public void onSignChange(SignChangeEvent signChangeEvent){
if(event.getBlockPlaced().getLocation().equals(signChangeEvent.getBlock().getLocation())) {
Sign sign = (Sign) signChangeEvent.getBlock().getState();
ChestLinkInfo info = Utils.getChestLinkInfo(sign, signChangeEvent.getLines(), signChangeEvent.getPlayer());
if (info != null) {
Config.addChest(info.getPlayer(), info.getGroup(), event.getBlockAgainst().getLocation());
Messages.CHEST_ADDED(event.getPlayer(), info.getGroup(), event.getPlayer().getDisplayName());
setLine(sign,signChangeEvent,0, ChatColor.RED + signChangeEvent.getLine(0));
setLine(sign,signChangeEvent,1, ChatColor.GREEN + signChangeEvent.getLine(1));
setLine(sign,signChangeEvent,2, ChatColor.BOLD + event.getPlayer().getDisplayName());
sign.getPersistentDataContainer().set(Values.playerUUID, PersistentDataType.STRING, event.getPlayer().getUniqueId().toString());
sign.update();
}
done();
}
done();
}
}
};
};
}
}
} else {
Messages.NO_PERMISSION(event.getPlayer());
}
}
@EventHandler

View File

@ -1,12 +1,11 @@
package com.jamesdpeters.minecraft.chests.listeners;
import com.comphenix.protocol.wrappers.BlockPosition;
import com.jamesdpeters.minecraft.chests.Config;
import com.jamesdpeters.minecraft.chests.Messages;
import com.jamesdpeters.minecraft.chests.Permissions;
import com.jamesdpeters.minecraft.chests.Utils;
import com.jamesdpeters.minecraft.chests.interfaces.VirtualInventoryHolder;
import com.jamesdpeters.minecraft.chests.protocollib.WrapperPlayServerBlockAction;
import com.jamesdpeters.minecraft.chests.serialize.InventoryStorage;
import org.bukkit.Location;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
@ -30,20 +29,11 @@ public class InventoryListener implements Listener {
InventoryStorage storage = Config.getInventoryStorage(event.getInventory().getLocation());
if(storage != null){
event.setCancelled(true);
Location chestLocation = event.getInventory().getLocation();
BlockPosition blockPosition = new BlockPosition((int) chestLocation.getX(),(int)chestLocation.getY(),(int)chestLocation.getZ());
WrapperPlayServerBlockAction packet = new WrapperPlayServerBlockAction();
packet.setLocation(blockPosition);
packet.setBlockType(event.getInventory().getLocation().getBlock().getType());
packet.setByte1(1);
packet.setByte2(1);
packet.broadcastPacket();
packet.sendPacket((Player) event.getPlayer());
Utils.openInventory((Player) event.getPlayer(),storage.getInventory());
if(event.getPlayer().hasPermission(Permissions.OPEN)) {
Utils.openInventory((Player) event.getPlayer(), storage.getInventory());
} else {
if(event.getPlayer() instanceof Player) Messages.NO_PERMISSION((Player) event.getPlayer());
}
}
}
}

View File

@ -1,115 +0,0 @@
package com.jamesdpeters.minecraft.chests.protocollib;
/**
* PacketWrapper - ProtocolLib wrappers for Minecraft packets
* Copyright (C) dmulloy2 <http://dmulloy2.net>
* Copyright (C) Kristian S. Strangeland
*
* 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, see <http://www.gnu.org/licenses/>.
*/
import java.lang.reflect.InvocationTargetException;
import org.bukkit.entity.Player;
import com.comphenix.protocol.PacketType;
import com.comphenix.protocol.ProtocolLibrary;
import com.comphenix.protocol.events.PacketContainer;
import com.google.common.base.Objects;
public abstract class AbstractPacket {
// The packet we will be modifying
protected PacketContainer handle;
/**
* Constructs a new strongly typed wrapper for the given packet.
*
* @param handle - handle to the raw packet data.
* @param type - the packet type.
*/
protected AbstractPacket(PacketContainer handle, PacketType type) {
// Make sure we're given a valid packet
if (handle == null)
throw new IllegalArgumentException("Packet handle cannot be NULL.");
if (!Objects.equal(handle.getType(), type))
throw new IllegalArgumentException(handle.getHandle()
+ " is not a packet of type " + type);
this.handle = handle;
}
/**
* Retrieve a handle to the raw packet data.
*
* @return Raw packet data.
*/
public PacketContainer getHandle() {
return handle;
}
/**
* Send the current packet to the given receiver.
*
* @param receiver - the receiver.
* @throws RuntimeException If the packet cannot be sent.
*/
public void sendPacket(Player receiver) {
try {
ProtocolLibrary.getProtocolManager().sendServerPacket(receiver,
getHandle());
} catch (InvocationTargetException e) {
throw new RuntimeException("Cannot send packet.", e);
}
}
/**
* Send the current packet to all online players.
*/
public void broadcastPacket() {
ProtocolLibrary.getProtocolManager().broadcastServerPacket(getHandle());
}
/**
* Simulate receiving the current packet from the given sender.
*
* @param sender - the sender.
* @throws RuntimeException If the packet cannot be received.
* @deprecated Misspelled. recieve to receive
* @see #receivePacket(Player)
*/
@Deprecated
public void recievePacket(Player sender) {
try {
ProtocolLibrary.getProtocolManager().recieveClientPacket(sender,
getHandle());
} catch (Exception e) {
throw new RuntimeException("Cannot recieve packet.", e);
}
}
/**
* Simulate receiving the current packet from the given sender.
*
* @param sender - the sender.
* @throws RuntimeException if the packet cannot be received.
*/
public void receivePacket(Player sender) {
try {
ProtocolLibrary.getProtocolManager().recieveClientPacket(sender,
getHandle());
} catch (Exception e) {
throw new RuntimeException("Cannot receive packet.", e);
}
}
}

View File

@ -1,120 +0,0 @@
package com.jamesdpeters.minecraft.chests.protocollib;
/**
* PacketWrapper - ProtocolLib wrappers for Minecraft packets
* Copyright (C) dmulloy2 <http://dmulloy2.net>
* Copyright (C) Kristian S. Strangeland
*
* 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, see <http://www.gnu.org/licenses/>.
*/
import org.bukkit.Material;
import com.comphenix.protocol.PacketType;
import com.comphenix.protocol.events.PacketContainer;
import com.comphenix.protocol.wrappers.BlockPosition;
public class WrapperPlayServerBlockAction extends AbstractPacket {
public static final PacketType TYPE = PacketType.Play.Server.BLOCK_ACTION;
public WrapperPlayServerBlockAction() {
super(new PacketContainer(TYPE), TYPE);
handle.getModifier().writeDefaults();
}
public WrapperPlayServerBlockAction(PacketContainer packet) {
super(packet, TYPE);
}
/**
* Retrieve Location.
* <p>
* Notes: block Coordinates
*
* @return The current Location
*/
public BlockPosition getLocation() {
return handle.getBlockPositionModifier().read(0);
}
/**
* Set Location.
*
* @param value - new value.
*/
public void setLocation(BlockPosition value) {
handle.getBlockPositionModifier().write(0, value);
}
/**
* Retrieve Byte 1.
* <p>
* Notes: varies depending on block - see Block_Actions
*
* @return The current Byte 1
*/
public int getByte1() {
return handle.getIntegers().read(0);
}
/**
* Set Byte 1.
*
* @param value - new value.
*/
public void setByte1(int value) {
handle.getIntegers().write(0, value);
}
/**
* Retrieve Byte 2.
* <p>
* Notes: varies depending on block - see Block_Actions
*
* @return The current Byte 2
*/
public int getByte2() {
return handle.getIntegers().read(1);
}
/**
* Set Byte 2.
*
* @param value - new value.
*/
public void setByte2(int value) {
handle.getIntegers().write(1, value);
}
/**
* Retrieve Block Type.
* <p>
* Notes: the block type for the block
*
* @return The current Block Type
*/
public Material getBlockType() {
return handle.getBlocks().read(0);
}
/**
* Set Block Type.
*
* @param value - new value.
*/
public void setBlockType(Material value) {
handle.getBlocks().write(0, value);
}
}

View File

@ -33,10 +33,12 @@ public class VirtualChestToHopper extends BukkitRunnable {
@Override
public void run() {
for(Location location : storage.getLocations()) {
Location below = location.clone().subtract(0, 1, 0);
if (below.getBlock().getState() instanceof Hopper) {
Hopper hopper = (Hopper) below.getBlock().getState();
Utils.moveToOtherInventory(storage.getInventory(),1,hopper.getInventory(),Utils.getHopperFilters(below.getBlock()));
if(location != null) {
Location below = location.clone().subtract(0, 1, 0);
if (below.getBlock().getState() instanceof Hopper) {
Hopper hopper = (Hopper) below.getBlock().getState();
Utils.moveToOtherInventory(storage.getInventory(), 1, hopper.getInventory(), Utils.getHopperFilters(below.getBlock()));
}
}
}
}

View File

@ -2,10 +2,14 @@ package com.jamesdpeters.minecraft.chests.serialize;
import com.jamesdpeters.minecraft.chests.Messages;
import com.jamesdpeters.minecraft.chests.Utils;
import com.jamesdpeters.minecraft.chests.interfaces.VirtualInventoryHolder;
import com.jamesdpeters.minecraft.chests.runnables.VirtualChestToHopper;
import fr.minuskube.inv.ClickableItem;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.block.Chest;
import org.bukkit.configuration.serialization.ConfigurationSerializable;
@ -13,13 +17,15 @@ import org.bukkit.entity.Player;
import org.bukkit.event.inventory.InventoryType;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import java.lang.reflect.Array;
import java.util.*;
public class InventoryStorage implements ConfigurationSerializable {
Inventory inventory;
Inventory inventory; //Old Inventory
ArrayList<ItemStack> items;
ArrayList<Location> locationsList;
String inventoryName = "Chest";
VirtualChestToHopper chestToHopper;
@ -46,6 +52,7 @@ public class InventoryStorage implements ConfigurationSerializable {
inventory.setContents(itemStacks);
locationsList = (ArrayList<Location>) map.get("locations");
locationsList.removeAll(Collections.singletonList(null));
playerUUID = UUID.fromString((String) map.get("playerUUID"));
player = Bukkit.getOfflinePlayer(playerUUID).getPlayer();
@ -110,4 +117,28 @@ public class InventoryStorage implements ConfigurationSerializable {
public String toString() {
return inventoryName+": "+locationsList.toString();
}
public ItemStack getIventoryIcon(){
ItemStack toReturn = null;
for(ItemStack item : inventory.getContents()){
if(item != null){
toReturn = item.clone();
}
}
if(toReturn == null) toReturn = new ItemStack(Material.CHEST);
ItemMeta meta = toReturn.getItemMeta();
if(meta != null) {
meta.setDisplayName(ChatColor.BOLD + "" + ChatColor.GREEN + "" + getIdentifier());
toReturn.setItemMeta(meta);
}
toReturn.setAmount(1);
return toReturn;
}
public ClickableItem getClickableItem(Player player) {
return ClickableItem.of(getIventoryIcon(), event -> {
Utils.openInventory(player,getInventory());
});
}
}

View File

@ -3,9 +3,25 @@ version: 1.14.4-v1
main: com.jamesdpeters.minecraft.chests.ChestsPlusPlus
api-version: "1.14"
depend: [ProtocolLib]
commands:
chestlink:
description: Chest++ Commands.
usage: Use /chestlink help for more info.
usage: Use /chestlink help for more info.
permissions:
chestlink.*:
description: Gives permission for all ChestLink commands.
default: op
children:
chestlink.add: true
chestlink.open: true
chestlink.menu: true
chestlink.add:
description: Gives permission to add ChestLinks!
default: false
chestlink.open:
description: Gives permission to open ChestLinks!
default: false
chestlink.menu:
description: Gives permission to open the ChestLink menu!
default: false