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> <artifactId>ChestsPlusPlus</artifactId>
<version>1.0-SNAPSHOT</version> <version>1.0-SNAPSHOT</version>
<properties> <properties>
<maven.compiler.source>8</maven.compiler.source> <maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target> <maven.compiler.target>8</maven.compiler.target>
</properties> </properties>
<repositories> <repositories>
<repository>
<id>mcstats</id>
<url>https://repo.mcstats.org/content/repositories/releases/</url>
</repository>
<repository> <repository>
<id>spigotmc-repo</id> <id>spigotmc-repo</id>
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url> <url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
@ -28,6 +35,9 @@
<id>dmulloy2-repo</id> <id>dmulloy2-repo</id>
<url>http://repo.dmulloy2.net/nexus/repository/public/</url> <url>http://repo.dmulloy2.net/nexus/repository/public/</url>
</repository> </repository>
</repositories> </repositories>
<dependencies> <dependencies>
@ -46,9 +56,9 @@
</dependency> </dependency>
<dependency> <dependency>
<groupId>com.comphenix.protocol</groupId> <groupId>fr.minuskube.inv</groupId>
<artifactId>ProtocolLib</artifactId> <artifactId>smart-invs</artifactId>
<version>4.4.0</version> <version>1.2.7</version>
</dependency> </dependency>
</dependencies> </dependencies>
@ -62,6 +72,21 @@
<groupId>org.apache.maven.plugins</groupId> <groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId> <artifactId>maven-shade-plugin</artifactId>
<version>3.1.0</version> <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> <executions>
<!--Tell the shade plugin when it should be run during a maven build--> <!--Tell the shade plugin when it should be run during a maven build-->
<execution> <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.listeners.InventoryListener;
import com.jamesdpeters.minecraft.chests.serialize.InventoryStorage; import com.jamesdpeters.minecraft.chests.serialize.InventoryStorage;
import com.jamesdpeters.minecraft.chests.serialize.LinkedChest; import com.jamesdpeters.minecraft.chests.serialize.LinkedChest;
import fr.minuskube.inv.InventoryManager;
import org.bukkit.configuration.serialization.ConfigurationSerialization; import org.bukkit.configuration.serialization.ConfigurationSerialization;
import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.plugin.java.JavaPlugin;
import java.io.IOException;
public class ChestsPlusPlus extends JavaPlugin { public class ChestsPlusPlus extends JavaPlugin {
public static JavaPlugin PLUGIN; public static JavaPlugin PLUGIN;
public static InventoryManager INVENTORY_MANAGER;
static { static {
ConfigurationSerialization.registerClass(LinkedChest.class, "LinkedChest"); ConfigurationSerialization.registerClass(LinkedChest.class, "LinkedChest");
@ -27,6 +31,10 @@ public class ChestsPlusPlus extends JavaPlugin {
getServer().getPluginManager().registerEvents(new HopperListener(),this); getServer().getPluginManager().registerEvents(new HopperListener(),this);
new Config(); new Config();
INVENTORY_MANAGER = new InventoryManager(this);
INVENTORY_MANAGER.init();
getLogger().info("Chests++ enabled!"); getLogger().info("Chests++ enabled!");
} }

View File

@ -24,4 +24,8 @@ public class Messages {
public static void MUST_HOLD_SIGN(Player target){ public static void MUST_HOLD_SIGN(Player target){
target.sendMessage(ChatColor.RED+"You must be hold a sign to do that!"); 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.EquipmentSlot;
import org.bukkit.inventory.Inventory; import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.persistence.PersistentDataType; import org.bukkit.persistence.PersistentDataType;
import java.util.*; import java.util.*;
@ -210,4 +211,13 @@ public class Utils {
} }
return filters; 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; package com.jamesdpeters.minecraft.chests.commands;
import com.jamesdpeters.minecraft.chests.ChestsPlusPlus; import com.jamesdpeters.minecraft.chests.*;
import com.jamesdpeters.minecraft.chests.Config; import com.jamesdpeters.minecraft.chests.inventories.ChestLinkMenu;
import com.jamesdpeters.minecraft.chests.Messages;
import com.jamesdpeters.minecraft.chests.Utils;
import com.jamesdpeters.minecraft.chests.serialize.InventoryStorage; import com.jamesdpeters.minecraft.chests.serialize.InventoryStorage;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
@ -32,7 +30,8 @@ public class RemoteChestCommand extends ServerCommand {
private enum OPTIONS { private enum OPTIONS {
ADD("/chestlink add <Group>", "Create/add a chest to a ChestLink group"), 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; String description, commandHelp;
static List<String> valuesList; static List<String> valuesList;
@ -77,10 +76,15 @@ public class RemoteChestCommand extends ServerCommand {
switch (OPTIONS.valueOf(args[0].toUpperCase())){ switch (OPTIONS.valueOf(args[0].toUpperCase())){
case ADD: case ADD:
if(args.length > 1){ if(args.length > 1){
Block targetBlock = player.getTargetBlockExact(5); if(sender.hasPermission(Permissions.ADD)) {
if(targetBlock != null) Utils.createChestLink(player,targetBlock,args[1]); Block targetBlock = player.getTargetBlockExact(5);
else Messages.MUST_LOOK_AT_CHEST(player); if (targetBlock != null) Utils.createChestLink(player, targetBlock, args[1]);
return true; else Messages.MUST_LOOK_AT_CHEST(player);
return true;
} else {
Messages.NO_PERMISSION(player);
return true;
}
} else { } else {
player.sendMessage(ChatColor.RED+OPTIONS.ADD.commandHelp); player.sendMessage(ChatColor.RED+OPTIONS.ADD.commandHelp);
player.sendMessage(ChatColor.RED+OPTIONS.ADD.description); player.sendMessage(ChatColor.RED+OPTIONS.ADD.description);
@ -88,14 +92,27 @@ public class RemoteChestCommand extends ServerCommand {
} }
case OPEN: case OPEN:
if(args.length > 1){ if(args.length > 1){
InventoryStorage invs = Config.getInventoryStorage(player,args[1]); if(sender.hasPermission(Permissions.OPEN)) {
Utils.openInventory(player,invs.getInventory()); InventoryStorage invs = Config.getInventoryStorage(player, args[1]);
return true; Utils.openInventory(player, invs.getInventory());
return true;
} else {
Messages.NO_PERMISSION(player);
return true;
}
} else { } else {
player.sendMessage(ChatColor.RED+OPTIONS.OPEN.commandHelp); player.sendMessage(ChatColor.RED+OPTIONS.OPEN.commandHelp);
player.sendMessage(ChatColor.RED+OPTIONS.OPEN.description); player.sendMessage(ChatColor.RED+OPTIONS.OPEN.description);
return true; 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 @EventHandler
public void playerInteract(BlockPlaceEvent event){ public void playerInteract(BlockPlaceEvent event){
if(event.getBlockPlaced().getState() instanceof Sign){ if(event.getPlayer().hasPermission(Permissions.ADD)){
if(event.getBlockAgainst().getState() instanceof Chest) { if(event.getBlockPlaced().getState() instanceof Sign){
new TempListener(){ if(event.getBlockAgainst().getState() instanceof Chest) {
@EventHandler new TempListener(){
public void onSignChange(SignChangeEvent signChangeEvent){ @EventHandler
if(event.getBlockPlaced().getLocation().equals(signChangeEvent.getBlock().getLocation())) { public void onSignChange(SignChangeEvent signChangeEvent){
Sign sign = (Sign) signChangeEvent.getBlock().getState(); if(event.getBlockPlaced().getLocation().equals(signChangeEvent.getBlock().getLocation())) {
ChestLinkInfo info = Utils.getChestLinkInfo(sign, signChangeEvent.getLines(), signChangeEvent.getPlayer()); Sign sign = (Sign) signChangeEvent.getBlock().getState();
if (info != null) { ChestLinkInfo info = Utils.getChestLinkInfo(sign, signChangeEvent.getLines(), signChangeEvent.getPlayer());
Config.addChest(info.getPlayer(), info.getGroup(), event.getBlockAgainst().getLocation()); if (info != null) {
Messages.CHEST_ADDED(event.getPlayer(), info.getGroup(), event.getPlayer().getDisplayName()); Config.addChest(info.getPlayer(), info.getGroup(), event.getBlockAgainst().getLocation());
setLine(sign,signChangeEvent,0, ChatColor.RED + signChangeEvent.getLine(0)); Messages.CHEST_ADDED(event.getPlayer(), info.getGroup(), event.getPlayer().getDisplayName());
setLine(sign,signChangeEvent,1, ChatColor.GREEN + signChangeEvent.getLine(1)); setLine(sign,signChangeEvent,0, ChatColor.RED + signChangeEvent.getLine(0));
setLine(sign,signChangeEvent,2, ChatColor.BOLD + event.getPlayer().getDisplayName()); setLine(sign,signChangeEvent,1, ChatColor.GREEN + signChangeEvent.getLine(1));
sign.getPersistentDataContainer().set(Values.playerUUID, PersistentDataType.STRING, event.getPlayer().getUniqueId().toString()); setLine(sign,signChangeEvent,2, ChatColor.BOLD + event.getPlayer().getDisplayName());
sign.update(); sign.getPersistentDataContainer().set(Values.playerUUID, PersistentDataType.STRING, event.getPlayer().getUniqueId().toString());
sign.update();
}
done();
} }
done();
} }
} };
};
}
} }
} else {
Messages.NO_PERMISSION(event.getPlayer());
} }
} }
@EventHandler @EventHandler

View File

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

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 @Override
public void run() { public void run() {
for(Location location : storage.getLocations()) { for(Location location : storage.getLocations()) {
Location below = location.clone().subtract(0, 1, 0); if(location != null) {
if (below.getBlock().getState() instanceof Hopper) { Location below = location.clone().subtract(0, 1, 0);
Hopper hopper = (Hopper) below.getBlock().getState(); if (below.getBlock().getState() instanceof Hopper) {
Utils.moveToOtherInventory(storage.getInventory(),1,hopper.getInventory(),Utils.getHopperFilters(below.getBlock())); 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.Messages;
import com.jamesdpeters.minecraft.chests.Utils;
import com.jamesdpeters.minecraft.chests.interfaces.VirtualInventoryHolder; import com.jamesdpeters.minecraft.chests.interfaces.VirtualInventoryHolder;
import com.jamesdpeters.minecraft.chests.runnables.VirtualChestToHopper; import com.jamesdpeters.minecraft.chests.runnables.VirtualChestToHopper;
import fr.minuskube.inv.ClickableItem;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.Block; import org.bukkit.block.Block;
import org.bukkit.block.Chest; import org.bukkit.block.Chest;
import org.bukkit.configuration.serialization.ConfigurationSerializable; import org.bukkit.configuration.serialization.ConfigurationSerializable;
@ -13,13 +17,15 @@ import org.bukkit.entity.Player;
import org.bukkit.event.inventory.InventoryType; import org.bukkit.event.inventory.InventoryType;
import org.bukkit.inventory.Inventory; import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import java.lang.reflect.Array; import java.lang.reflect.Array;
import java.util.*; import java.util.*;
public class InventoryStorage implements ConfigurationSerializable { public class InventoryStorage implements ConfigurationSerializable {
Inventory inventory; Inventory inventory; //Old Inventory
ArrayList<ItemStack> items;
ArrayList<Location> locationsList; ArrayList<Location> locationsList;
String inventoryName = "Chest"; String inventoryName = "Chest";
VirtualChestToHopper chestToHopper; VirtualChestToHopper chestToHopper;
@ -46,6 +52,7 @@ public class InventoryStorage implements ConfigurationSerializable {
inventory.setContents(itemStacks); inventory.setContents(itemStacks);
locationsList = (ArrayList<Location>) map.get("locations"); locationsList = (ArrayList<Location>) map.get("locations");
locationsList.removeAll(Collections.singletonList(null));
playerUUID = UUID.fromString((String) map.get("playerUUID")); playerUUID = UUID.fromString((String) map.get("playerUUID"));
player = Bukkit.getOfflinePlayer(playerUUID).getPlayer(); player = Bukkit.getOfflinePlayer(playerUUID).getPlayer();
@ -110,4 +117,28 @@ public class InventoryStorage implements ConfigurationSerializable {
public String toString() { public String toString() {
return inventoryName+": "+locationsList.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 main: com.jamesdpeters.minecraft.chests.ChestsPlusPlus
api-version: "1.14" api-version: "1.14"
depend: [ProtocolLib]
commands: commands:
chestlink: chestlink:
description: Chest++ Commands. 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