Storage Changes

This commit is contained in:
jameslfc19 2020-07-02 14:08:00 +01:00
parent 054232f1ba
commit 6b09dec908
9 changed files with 350 additions and 139 deletions

View File

@ -1,45 +0,0 @@
package com.jamesdpeters.minecraft.chests.storage;
import com.jamesdpeters.minecraft.chests.storage.AbstractStorage;
import com.jamesdpeters.minecraft.chests.storage.AutoCraftingStorage;
import com.jamesdpeters.minecraft.chests.storage.StorageType;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.OfflinePlayer;
import java.util.UUID;
public class StorageInfo<T extends AbstractStorage> {
private String group;
private OfflinePlayer player;
private T storage;
public StorageInfo(String playerUUID, String group, StorageType<T> storageType){
this(UUID.fromString(playerUUID),group, storageType);
}
public StorageInfo(UUID playerUUID, String group, StorageType<T> storageType){
this.group = group;
this.storage = storageType.getStorage(playerUUID,group);
this.player = Bukkit.getOfflinePlayer(playerUUID);
}
public String getGroup() {
return group;
}
public OfflinePlayer getPlayer() {
return player;
}
/**
* Get the AutoCraftingStorage for this Sign and check if the given location is apart of the system if not
* add it.
* @return @{@link AutoCraftingStorage}
*/
public T getStorage(Location location) {
if(!storage.containsLocation(location)) storage.addLocation(location);
return storage;
}
}

View File

@ -1,4 +1,4 @@
package com.jamesdpeters.minecraft.chests.storage;
package com.jamesdpeters.minecraft.chests.storage.abstracts;
import com.jamesdpeters.minecraft.chests.ChestsPlusPlus;
import com.jamesdpeters.minecraft.chests.misc.Permissions;
@ -21,6 +21,7 @@ import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import org.bukkit.persistence.PersistentDataType;
import org.bukkit.util.EulerAngle;
import org.bukkit.util.Vector;
import java.util.ArrayList;
@ -34,22 +35,19 @@ import java.util.UUID;
public abstract class AbstractStorage implements ConfigurationSerializable {
//Serializables
private ArrayList<String> members;
private List<OfflinePlayer> bukkitMembers;
private OfflinePlayer player;
protected UUID playerUUID;
boolean isPublic;
private UUID playerUUID;
private boolean isPublic;
private List<LocationInfo> locationInfoList;
private Inventory inventory;
private String inventoryName;
private StorageType storageType;
public <T extends AbstractStorage> AbstractStorage(OfflinePlayer player, String identifier, Location location, StorageType<T> storageType){
public AbstractStorage(OfflinePlayer player, String identifier, Location location){
this.player = player;
this.playerUUID = player.getUniqueId();
this.isPublic = false;
this.storageType = storageType;
setIdentifier(identifier);
LocationInfo locationInfo = new LocationInfo(location);
locationInfoList = new ArrayList<>(Collections.singleton(locationInfo));
@ -57,8 +55,15 @@ public abstract class AbstractStorage implements ConfigurationSerializable {
init();
}
/**
* This constructor MUST be in the subclass in order for deserialization to work!
* @param map
*/
@SuppressWarnings("unchecked")
public AbstractStorage(Map<String, Object> map){
//Pass map through
deserialize(map);
//This reformats the previous method of location storage to the newer version.
List<Location> locations = (ArrayList<Location>) map.get("locations");
@ -93,21 +98,20 @@ public abstract class AbstractStorage implements ConfigurationSerializable {
inventory.setContents(itemStacks);
}
//Pass map through
deserialize(map);
init();
}
@Override
public Map<String, Object> serialize() {
HashMap<String, Object> map = new LinkedHashMap<>();
//Add custom parameters first
serialize(map);
//Now add default parameters
//Add default parameters
if(storeInventory()) map.put("inventory", inventory.getContents());
map.put("playerUUID", player.getUniqueId().toString());
map.put("locationInfo", locationInfoList);
map.put("playerUUID", player.getUniqueId().toString());
map.put("members", members);
map.put("isPublic", isPublic);
//Add custom parameters
serialize(map);
return map;
}
@ -115,25 +119,27 @@ public abstract class AbstractStorage implements ConfigurationSerializable {
Bukkit.getScheduler().scheduleSyncRepeatingTask(ChestsPlusPlus.PLUGIN, this::updateClients, 1, 5);
}
public abstract StorageType getStorageType();
/**
* @return true if this storage should store the inventory to disk.
*/
abstract boolean storeInventory();
public abstract boolean storeInventory();
/**
* Add custom parameters here to be serialized.
* @param map - the map to be added to.
*/
abstract void serialize(Map<String, Object> map);
protected abstract void serialize(Map<String, Object> map);
/**
* Use this to deserialize custom parameters.
* @param map - the map to deserialize from.
*/
abstract void deserialize(Map<String, Object> map);
abstract Inventory initInventory();
abstract void setIdentifier(String newIdentifier);
protected abstract void deserialize(Map<String, Object> map);
protected abstract Inventory initInventory();
protected abstract void setIdentifier(String newIdentifier);
public abstract String getIdentifier();
/**
@ -141,7 +147,7 @@ public abstract class AbstractStorage implements ConfigurationSerializable {
* @param block - the block that was added.
* @param player - the player who added the storage.
*/
abstract void onStorageAdded(Block block, Player player);
public abstract void onStorageAdded(Block block, Player player);
/**
* @return List of locations
@ -199,7 +205,7 @@ public abstract class AbstractStorage implements ConfigurationSerializable {
getLocations().forEach(location -> {
Block block = location.getLocation().getBlock();
BlockFace face = storageType.getStorageFacing(block);
BlockFace face = getStorageType().getStorageFacing(block);
if(face != null) {
Block signBlock = block.getRelative(face);
if(signBlock.getState() instanceof Sign) {
@ -288,17 +294,12 @@ public abstract class AbstractStorage implements ConfigurationSerializable {
return false;
}
// /**
// * @return the direction the storage at the given location is facing.
// */
// public abstract BlockFace getStorageFacing(Block block);
/* ARMOR STAND METHODS */
/**
* @return the @{@link ItemStack} an @{@link ArmorStand} should be holding.
*/
abstract ItemStack getArmorStandItem();
protected abstract ItemStack getArmorStandItem();
/**
* Updates nearby clients for all locations of this storage:
@ -313,10 +314,12 @@ public abstract class AbstractStorage implements ConfigurationSerializable {
if(world != null) {
Collection<Entity> players = world.getNearbyEntities(location.getLocation(), 20, 20, 20, entity -> entity instanceof Player);
players.forEach(entity -> {
if(entity instanceof Player){
Player player = (Player) entity;
BlockFace facing = storageType.getStorageFacing(block);
BlockFace facing = getStorageType().getStorageFacing(block);
if(facing != null) {
Block anchor = block.getRelative(facing);
@ -334,11 +337,11 @@ public abstract class AbstractStorage implements ConfigurationSerializable {
//Get currently stored armorStand if there isn't one spawn it.
ArmorStand stand = isBlock ? location.getBlockStand() : location.getItemStand();
if(stand == null || !stand.isValid()){
stand = createArmorStand(world,standLoc);
stand = createArmorStand(world,standLoc,isBlock);
addArmorStand(isBlock, location, stand);
}
stand.setHelmet(displayItem);
stand.setItemInHand(displayItem);
//Set on fire to correct lighting.
stand.setFireTicks(Integer.MAX_VALUE);
@ -364,15 +367,18 @@ public abstract class AbstractStorage implements ConfigurationSerializable {
* @param standLoc - location to spawn the @{@link ArmorStand} at.
* @return instance of @{@link ArmorStand} that was spawned.
*/
private ArmorStand createArmorStand(World world, Location standLoc){
private ArmorStand createArmorStand(World world, Location standLoc, boolean isBlock){
ArmorStand stand = world.spawn(standLoc, ArmorStand.class);
stand.setVisible(false);
stand.setVisible(true);
stand.setGravity(false);
stand.setSilent(true);
stand.setInvulnerable(true);
stand.setMarker(true);
stand.setBasePlate(false);
stand.setSmall(true);
stand.setCanPickupItems(false);
EulerAngle angle = isBlock ? new EulerAngle( Math.toRadians( -15 ), Math.toRadians( -45 ), 0 ) : new EulerAngle(0,0,0);
stand.setRightArmPose(angle);
//Store value of 1 in armour stand to indicate it belongs to this plugin.
stand.getPersistentDataContainer().set(Values.PluginKey, PersistentDataType.INTEGER, 1);
@ -398,7 +404,7 @@ public abstract class AbstractStorage implements ConfigurationSerializable {
private void setArmorStandHelmet(boolean isBlock, LocationInfo location, ItemStack helmet){
ArmorStand stand = isBlock ? location.getBlockStand() : location.getItemStand();
if(stand != null) stand.setHelmet(helmet);
if(stand != null) stand.setItemInHand(helmet);
}
private void addArmorStand(boolean isBlock, LocationInfo location, ArmorStand stand){
@ -441,6 +447,10 @@ public abstract class AbstractStorage implements ConfigurationSerializable {
return inventory;
}
public UUID getPlayerUUID() {
return playerUUID;
}
/* SETTERS */
public void setPublic(boolean aPublic) {

View File

@ -0,0 +1,68 @@
package com.jamesdpeters.minecraft.chests.storage.abstracts;
import com.jamesdpeters.minecraft.chests.serialize.LocationInfo;
import com.jamesdpeters.minecraft.chests.storage.autocraft.AutoCraftingStorage;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.OfflinePlayer;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.block.Sign;
import org.bukkit.block.data.Directional;
import org.bukkit.entity.Player;
import java.util.UUID;
public class StorageInfo<T extends AbstractStorage> {
private String group;
private OfflinePlayer player;
private T storage;
public StorageInfo(String playerUUID, String group, StorageType<T> storageType, Sign sign){
this(UUID.fromString(playerUUID),group, storageType, sign);
}
public StorageInfo(UUID playerUUID, String group, StorageType<T> storageType, Sign sign){
this.group = group;
this.player = Bukkit.getOfflinePlayer(playerUUID);
this.storage = storageType.getStorage(playerUUID,group);
if(storage == null){
if(sign.getBlockData() instanceof Directional) {
Directional directional = (Directional) sign.getBlockData();
BlockFace storageFace = directional.getFacing().getOppositeFace();
Block storageBlock = sign.getBlock().getRelative(storageFace);
Player player = Bukkit.getPlayer(playerUUID);
if(player != null) {
boolean added = storageType.add(player, group, storageBlock.getLocation(), this.player);
if(added) {
this.storage = storageType.getStorage(playerUUID, group);
storageType.getMessages().foundUnlinkedStorage(player,group);
}
}
}
}
}
public String getGroup() {
return group;
}
public OfflinePlayer getPlayer() {
return player;
}
/**
* Get the AutoCraftingStorage for this Sign and check if the given location is apart of the system if not
* add it.
* @return @{@link AutoCraftingStorage}
*/
public T getStorage(Location location) {
if(!storage.containsLocation(location)){
storage.addLocation(location);
Player player = storage.getOwner().getPlayer();
if(player != null) storage.getStorageType().getMessages().foundUnlinkedStorage(player,getGroup());
}
return storage;
}
}

View File

@ -0,0 +1,70 @@
package com.jamesdpeters.minecraft.chests.storage.abstracts;
import com.jamesdpeters.minecraft.chests.misc.Utils;
import com.jamesdpeters.minecraft.chests.serialize.Config;
import com.jamesdpeters.minecraft.chests.storage.chestlink.ChestLinkStorage;
import org.bukkit.ChatColor;
import org.bukkit.entity.Player;
public abstract class StorageMessages {
protected static String TAG = "[Chests++]";
public abstract String getStorageName();
public void storageAdded(Player target, String group, String player){
target.sendMessage(ChatColor.GREEN+TAG+" Succesfully added "+getStorageName()+" to group: "+ChatColor.WHITE+group+ChatColor.RED+" for "+ChatColor.WHITE+player);
}
public void storageRemoved(Player target, String group, String player){
target.sendMessage(ChatColor.RED+TAG+" Succesfully removed "+getStorageName()+" from group: "+ChatColor.WHITE+group+ChatColor.RED+" for "+ChatColor.WHITE+player);
}
public void removedGroup(Player target, String toRemove){
target.sendMessage(ChatColor.RED+""+ChatColor.BOLD+TAG+" Succesfully removed group "+toRemove+" from your "+getStorageName()+"'s!");
}
public void groupDoesntExist(Player target, String toRemove){
target.sendMessage(ChatColor.RED+""+ChatColor.BOLD+TAG+" "+toRemove+" isn't a valid "+getStorageName()+" group to remove!");
}
public void foundUnlinkedStorage(Player target, String group){
target.sendMessage(ChatColor.GOLD+TAG+" This "+getStorageName()+" wasn't linked to your system! It has been added under the "+group+" group!");
}
public void addedMember(Player target, AbstractStorage storage, String added){
target.sendMessage(ChatColor.GREEN+""+ChatColor.BOLD+TAG+" Succesfully added "+ChatColor.WHITE+added+ChatColor.GREEN+" to "+getStorageName()+" group "+ChatColor.WHITE+storage.getIdentifier());
target.sendMessage(ChatColor.GREEN+""+ChatColor.BOLD+TAG+" Current Members: "+ Utils.prettyPrintPlayers(ChatColor.GREEN,storage.getMembers()));
}
public void unableToAddMember(Player target, String toAdd){
target.sendMessage(ChatColor.RED+""+ChatColor.BOLD+TAG+" Unable to add player "+toAdd+" to "+getStorageName()+"!");
}
public void removedMember(Player target, AbstractStorage storage, String added){
target.sendMessage(ChatColor.GREEN+""+ChatColor.BOLD+TAG+" Succesfully removed "+ChatColor.WHITE+added+ChatColor.GREEN+" from "+getStorageName()+" group "+ChatColor.WHITE+storage.getIdentifier());
target.sendMessage(ChatColor.GREEN+""+ChatColor.BOLD+TAG+" Current Members: "+ Utils.prettyPrintPlayers(ChatColor.GREEN,storage.getMembers()));
}
public void unableToRemoveMember(Player target, String toAdd){
target.sendMessage(ChatColor.RED+""+ChatColor.BOLD+TAG+" Unable to remove player "+toAdd+" from "+getStorageName()+"! Were they already removed?");
}
public void listMembers(Player target, AbstractStorage storage){
if(storage.getMembers() != null){
target.sendMessage(ChatColor.GREEN+"Members of "+getStorageName()+" group "+ChatColor.WHITE+storage.getIdentifier()+": "+Utils.prettyPrintPlayers(ChatColor.GREEN,storage.getMembers()));
} else {
target.sendMessage(ChatColor.YELLOW+"There are no additional members in the group: "+ChatColor.WHITE+storage.getIdentifier());
}
}
public void setPublic(Player target, AbstractStorage storage){
target.sendMessage(ChatColor.GREEN+"Publicity for "+getStorageName()+" group "+storage.getIdentifier()+" is set to: "+ChatColor.WHITE+storage.isPublic());
}
public abstract void invalidID(Player target);
public abstract void listStorageGroups(Player target);
public abstract void mustLookAtBlock(Player player);
public abstract void invalidSignPlacement(Player player);
}

View File

@ -1,4 +1,4 @@
package com.jamesdpeters.minecraft.chests.storage;
package com.jamesdpeters.minecraft.chests.storage.abstracts;
import com.jamesdpeters.minecraft.chests.ChestsPlusPlus;
@ -6,7 +6,8 @@ import com.jamesdpeters.minecraft.chests.misc.Messages;
import com.jamesdpeters.minecraft.chests.misc.Settings;
import com.jamesdpeters.minecraft.chests.misc.Values;
import com.jamesdpeters.minecraft.chests.serialize.Config;
import com.jamesdpeters.minecraft.chests.serialize.LinkedChest;
import com.jamesdpeters.minecraft.chests.serialize.ConfigStorage;
import com.jamesdpeters.minecraft.chests.storage.StorageUtils;
import org.bukkit.Bukkit;
import org.bukkit.GameMode;
import org.bukkit.Location;
@ -35,10 +36,10 @@ import java.util.stream.Collectors;
public abstract class StorageType<T extends AbstractStorage> {
private LinkedChest store;
private ConfigStorage store;
private StorageUtils<StorageInfo<T>, T> storageUtils;
StorageType(LinkedChest store){
protected StorageType(ConfigStorage store){
this.store = store;
storageUtils = new StorageUtils<>(this);
}
@ -47,7 +48,7 @@ public abstract class StorageType<T extends AbstractStorage> {
return storageUtils;
}
public abstract HashMap<String, HashMap<String, T>> getStorageMap(LinkedChest store);
public abstract HashMap<String, HashMap<String, T>> getStorageMap(ConfigStorage store);
public abstract T createNewStorageInstance(OfflinePlayer player, String inventoryName, Location location);
@ -80,6 +81,8 @@ public abstract class StorageType<T extends AbstractStorage> {
*/
public abstract BlockFace getStorageFacing(Block block);
public abstract StorageMessages getMessages();
/*
STORAGE MAP SECTION
*/
@ -210,10 +213,9 @@ public abstract class StorageType<T extends AbstractStorage> {
});
storage.dropInventory(player.getLocation());
getStorageMap(player.getUniqueId()).remove(group);
//TODO Reformat Message.
Messages.REMOVED_GROUP(player, group);
getMessages().removedGroup(player,group);
} else {
Messages.GROUP_DOESNT_EXIST(player, group);
getMessages().groupDoesntExist(player, group);
}
Config.saveASync();
}
@ -231,7 +233,6 @@ public abstract class StorageType<T extends AbstractStorage> {
public boolean renameStorage(Player player, String oldIdentifier, String newIdentifier) {
HashMap<String, T> map = getStorageMap(player.getUniqueId());
if (!map.containsKey(oldIdentifier)) {
//TODO Reformat Message.
Messages.CANNOT_RENAME_GROUP_DOESNT_EXIST(player, oldIdentifier);
return false;
}
@ -249,7 +250,7 @@ public abstract class StorageType<T extends AbstractStorage> {
/* HELPER UTILS */
static void placeSign(Block placedAgainst, Block toReplace, BlockFace facing, Player player, String identifier, String linkTag){
protected void placeSign(Block placedAgainst, Block toReplace, BlockFace facing, Player player, String identifier, String linkTag){
Bukkit.broadcastMessage("Placing Sign!");
if(toReplace.getType() == Material.AIR){
BlockState replacedBlockState = toReplace.getState();
@ -276,7 +277,7 @@ public abstract class StorageType<T extends AbstractStorage> {
if(ownerPlayer != null){
uuid = ownerPlayer.getUniqueId().toString();
} else {
Messages.INVALID_CHESTID(player);
getMessages().invalidID(player);
return;
}
} else {
@ -310,7 +311,7 @@ public abstract class StorageType<T extends AbstractStorage> {
SignChangeEvent signChangeEvent = new SignChangeEvent(sign.getBlock(),player,lines);
ChestsPlusPlus.PLUGIN.getServer().getPluginManager().callEvent(signChangeEvent);
} else {
Messages.NO_SPACE_FOR_SIGN(player);
getMessages().invalidSignPlacement(player);
}
}

View File

@ -1,7 +1,11 @@
package com.jamesdpeters.minecraft.chests.storage;
package com.jamesdpeters.minecraft.chests.storage.autocraft;
import com.jamesdpeters.minecraft.chests.interfaces.VirtualCraftingHolder;
import com.jamesdpeters.minecraft.chests.serialize.Config;
import com.jamesdpeters.minecraft.chests.serialize.RecipeSerializable;
import com.jamesdpeters.minecraft.chests.storage.abstracts.AbstractStorage;
import com.jamesdpeters.minecraft.chests.storage.abstracts.StorageType;
import com.jamesdpeters.minecraft.chests.storage.chestlink.ChestLinkStorageType;
import org.bukkit.Location;
import org.bukkit.OfflinePlayer;
import org.bukkit.block.Block;
@ -15,7 +19,6 @@ import org.bukkit.inventory.ShapedRecipe;
import org.bukkit.inventory.ShapelessRecipe;
import java.util.Map;
import java.util.UUID;
@SerializableAs("AutoCraftingStorage")
public class AutoCraftingStorage extends AbstractStorage implements ConfigurationSerializable {
@ -24,28 +27,36 @@ public class AutoCraftingStorage extends AbstractStorage implements Configuratio
private String identifier;
private VirtualCraftingHolder virtualCraftingHolder;
@Override
void serialize(Map<String, Object> hashMap) {
hashMap.put("recipe",recipeSerializable);
hashMap.put("playerUUID",playerUUID.toString());
hashMap.put("identifier", identifier);
hashMap.put("isPublic", isPublic);
public AutoCraftingStorage(Map<String, Object> map){
super(map);
}
@Override
void deserialize(Map<String, Object> map) {
recipeSerializable = (RecipeSerializable) map.get("recipe");
playerUUID = UUID.fromString((String) map.get("playerUUID"));
identifier = (String) map.get("identifier");
if(map.containsKey("isPublic")) isPublic = (boolean) map.get("isPublic");
else isPublic = false;
public AutoCraftingStorageType getStorageType() {
return Config.getAutoCraft();
}
public AutoCraftingStorage(OfflinePlayer player, String identifier, Location location){
super(player, identifier, location);
this.identifier = identifier;
initInventory();
}
@Override
ItemStack getArmorStandItem() {
protected void serialize(Map<String, Object> hashMap) {
hashMap.put("recipe",recipeSerializable);
hashMap.put("identifier", identifier);
}
@Override
protected void deserialize(Map<String, Object> map) {
recipeSerializable = (RecipeSerializable) map.get("recipe");
identifier = (String) map.get("identifier");
initInventory();
}
@Override
protected ItemStack getArmorStandItem() {
if(recipeSerializable != null){
if(recipeSerializable.getRecipe() != null){
return recipeSerializable.getRecipe().getResult();
@ -56,18 +67,10 @@ public class AutoCraftingStorage extends AbstractStorage implements Configuratio
@Override
boolean storeInventory() {
public boolean storeInventory() {
return false;
}
public AutoCraftingStorage(OfflinePlayer player, String identifier, Location location, StorageType<AutoCraftingStorage> storageType){
super(player, identifier, location, storageType);
this.playerUUID = player.getUniqueId();
this.identifier = identifier;
this.isPublic = false;
initInventory();
}
public void setRecipe(Recipe recipe){
if(recipe == null){
recipeSerializable = null;
@ -108,12 +111,12 @@ public class AutoCraftingStorage extends AbstractStorage implements Configuratio
}
@Override
void setIdentifier(String newIdentifier) {
protected void setIdentifier(String newIdentifier) {
identifier = newIdentifier;
}
@Override
void onStorageAdded(Block block, Player player) {
public void onStorageAdded(Block block, Player player) {
//Don't need to do anything with the Crafting table.
}
}

View File

@ -1,11 +1,15 @@
package com.jamesdpeters.minecraft.chests.storage;
package com.jamesdpeters.minecraft.chests.storage.autocraft;
import com.jamesdpeters.minecraft.chests.misc.Messages;
import com.jamesdpeters.minecraft.chests.misc.Permissions;
import com.jamesdpeters.minecraft.chests.misc.Utils;
import com.jamesdpeters.minecraft.chests.misc.Values;
import com.jamesdpeters.minecraft.chests.serialize.Config;
import com.jamesdpeters.minecraft.chests.serialize.LinkedChest;
import com.jamesdpeters.minecraft.chests.serialize.ConfigStorage;
import com.jamesdpeters.minecraft.chests.storage.abstracts.StorageInfo;
import com.jamesdpeters.minecraft.chests.storage.abstracts.StorageMessages;
import com.jamesdpeters.minecraft.chests.storage.abstracts.StorageType;
import org.bukkit.ChatColor;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.OfflinePlayer;
@ -18,18 +22,18 @@ import java.util.HashMap;
public class AutoCraftingStorageType extends StorageType<AutoCraftingStorage> {
public AutoCraftingStorageType(LinkedChest store) {
public AutoCraftingStorageType(ConfigStorage store) {
super(store);
}
@Override
public HashMap<String, HashMap<String, AutoCraftingStorage>> getStorageMap(LinkedChest store) {
public HashMap<String, HashMap<String, AutoCraftingStorage>> getStorageMap(ConfigStorage store) {
return store.autocraftingtables;
}
@Override
public AutoCraftingStorage createNewStorageInstance(OfflinePlayer player, String inventoryName, Location location) {
return new AutoCraftingStorage(player, inventoryName, location, this);
return new AutoCraftingStorage(player, inventoryName, location);
}
@Override
@ -83,4 +87,45 @@ public class AutoCraftingStorageType extends StorageType<AutoCraftingStorage> {
}
return null;
}
@Override
public StorageMessages getMessages() {
return messages;
}
private static AutoCraftMessages messages = new AutoCraftMessages();
private static class AutoCraftMessages extends StorageMessages {
@Override
public String getStorageName() {
return "AutoCrafter";
}
@Override
public void invalidID(Player target) {
target.sendMessage(ChatColor.RED+"Invalid AutoCrafter ID! Must not contain a colon ':' unless you are referencing another players group that you are a member off");
target.sendMessage(ChatColor.RED+"/autocraft add <owner>:<group>");
}
@Override
public void listStorageGroups(Player target) {
target.sendMessage(ChatColor.GREEN+""+ChatColor.BOLD+"List of your AutoCraft Stations:");
for(AutoCraftingStorage storage : Config.getAutoCraft().getStorageMap(target.getUniqueId()).values()){
if(storage != null){
target.sendMessage(ChatColor.GREEN+storage.getIdentifier()+ChatColor.WHITE);
}
}
}
@Override
public void mustLookAtBlock(Player player) {
player.sendMessage(ChatColor.RED+TAG+" You must be looking at the Crafting Table you want to AutoCraft with!");
}
@Override
public void invalidSignPlacement(Player player) {
player.sendMessage(ChatColor.GOLD+""+ChatColor.BOLD+TAG+" Invalid AutoCrafter - You must place a sign on any side of a Crafting Table, and it must not already by apart of a group!");
}
}
}

View File

@ -1,4 +1,4 @@
package com.jamesdpeters.minecraft.chests.storage;
package com.jamesdpeters.minecraft.chests.storage.chestlink;
import com.jamesdpeters.minecraft.chests.ChestsPlusPlus;
import com.jamesdpeters.minecraft.chests.interfaces.VirtualInventoryHolder;
@ -6,8 +6,11 @@ import com.jamesdpeters.minecraft.chests.inventories.ChestLinkMenu;
import com.jamesdpeters.minecraft.chests.misc.Messages;
import com.jamesdpeters.minecraft.chests.misc.Utils;
import com.jamesdpeters.minecraft.chests.runnables.VirtualChestToHopper;
import com.jamesdpeters.minecraft.chests.serialize.Config;
import com.jamesdpeters.minecraft.chests.sort.InventorySorter;
import com.jamesdpeters.minecraft.chests.sort.SortMethod;
import com.jamesdpeters.minecraft.chests.storage.abstracts.AbstractStorage;
import com.jamesdpeters.minecraft.chests.storage.abstracts.StorageType;
import fr.minuskube.inv.ClickableItem;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
@ -17,6 +20,7 @@ import org.bukkit.OfflinePlayer;
import org.bukkit.block.Block;
import org.bukkit.block.Chest;
import org.bukkit.configuration.serialization.ConfigurationSerializable;
import org.bukkit.configuration.serialization.SerializableAs;
import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.InventoryHolder;
@ -27,14 +31,19 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
@SerializableAs("ChestLinkStorage")
public class ChestLinkStorage extends AbstractStorage implements ConfigurationSerializable {
private String inventoryName = "Chest";
private String inventoryName;
private VirtualChestToHopper chestToHopper;
private SortMethod sortMethod;
public ChestLinkStorage(OfflinePlayer player, String group, Location location, StorageType<ChestLinkStorage> storageType){
super(player, group, location, storageType);
public ChestLinkStorage(Map<String, Object> map){
super(map);
}
public ChestLinkStorage(OfflinePlayer player, String group, Location location){
super(player, group, location);
this.inventoryName = group;
this.sortMethod = SortMethod.OFF;
@ -44,18 +53,17 @@ public class ChestLinkStorage extends AbstractStorage implements ConfigurationSe
getInventory().setContents(chest.getInventory().getContents());
chest.getInventory().clear();
}
init();
}
@Override
void serialize(Map<String, Object> hashMap) {
protected void serialize(Map<String, Object> hashMap) {
hashMap.put("inventoryName",inventoryName);
hashMap.put("sortMethod", sortMethod.toString());
}
@Override
void deserialize(Map<String, Object> map) {
protected void deserialize(Map<String, Object> map) {
String tempName = (String) map.get("inventoryName");
if(tempName != null) inventoryName = tempName;
@ -66,7 +74,7 @@ public class ChestLinkStorage extends AbstractStorage implements ConfigurationSe
}
@Override
ItemStack getArmorStandItem() {
protected ItemStack getArmorStandItem() {
return InventorySorter.getMostCommonItem(getInventory());
}
@ -76,7 +84,12 @@ public class ChestLinkStorage extends AbstractStorage implements ConfigurationSe
}
@Override
boolean storeInventory() {
public ChestLinkStorageType getStorageType() {
return Config.getChestLink();
}
@Override
public boolean storeInventory() {
return true;
}
@ -91,7 +104,7 @@ public class ChestLinkStorage extends AbstractStorage implements ConfigurationSe
}
@Override
void onStorageAdded(Block block, Player player) {
public void onStorageAdded(Block block, Player player) {
//Migrates that chest into InventoryStorage and if full drops it at the chest location.
if(block.getState() instanceof Chest) {
Chest chest = (Chest) block.getState();
@ -120,12 +133,12 @@ public class ChestLinkStorage extends AbstractStorage implements ConfigurationSe
ItemMeta meta = toReturn.getItemMeta();
if(meta != null) {
String dispName = ChatColor.GREEN + "" + getIdentifier() + ": " +ChatColor.WHITE+ ""+getTotalItems()+" items";
if(player.getUniqueId().equals(playerUUID)) meta.setDisplayName(dispName);
if(player.getUniqueId().equals(getPlayerUUID())) meta.setDisplayName(dispName);
else meta.setDisplayName(getOwner().getName()+": "+dispName);
if(getMembers() != null) {
List<String> memberNames = new ArrayList<>();
if(isPublic) memberNames.add(ChatColor.WHITE+"Public Chest");
if(isPublic()) memberNames.add(ChatColor.WHITE+"Public Chest");
memberNames.add(ChatColor.BOLD+""+ChatColor.UNDERLINE+"Members:");
getMembers().forEach(player1 -> memberNames.add(ChatColor.stripColor(player1.getName())));
meta.setLore(memberNames);

View File

@ -1,9 +1,14 @@
package com.jamesdpeters.minecraft.chests.storage;
package com.jamesdpeters.minecraft.chests.storage.chestlink;
import com.jamesdpeters.minecraft.chests.misc.Permissions;
import com.jamesdpeters.minecraft.chests.misc.Values;
import com.jamesdpeters.minecraft.chests.runnables.ChestLinkVerifier;
import com.jamesdpeters.minecraft.chests.serialize.LinkedChest;
import com.jamesdpeters.minecraft.chests.serialize.Config;
import com.jamesdpeters.minecraft.chests.serialize.ConfigStorage;
import com.jamesdpeters.minecraft.chests.storage.abstracts.AbstractStorage;
import com.jamesdpeters.minecraft.chests.storage.abstracts.StorageMessages;
import com.jamesdpeters.minecraft.chests.storage.abstracts.StorageType;
import org.bukkit.ChatColor;
import org.bukkit.Location;
import org.bukkit.OfflinePlayer;
import org.bukkit.block.Block;
@ -16,18 +21,18 @@ import java.util.HashMap;
public class ChestLinkStorageType extends StorageType<ChestLinkStorage> {
public ChestLinkStorageType(LinkedChest store) {
public ChestLinkStorageType(ConfigStorage store) {
super(store);
}
@Override
public HashMap<String, HashMap<String, ChestLinkStorage>> getStorageMap(LinkedChest store) {
public HashMap<String, HashMap<String, ChestLinkStorage>> getStorageMap(ConfigStorage store) {
return store.chests;
}
@Override
public ChestLinkStorage createNewStorageInstance(OfflinePlayer player, String inventoryName, Location location) {
return new ChestLinkStorage(player, inventoryName, location, this);
return new ChestLinkStorage(player, inventoryName, location);
}
@Override
@ -74,4 +79,45 @@ public class ChestLinkStorageType extends StorageType<ChestLinkStorage> {
}
return null;
}
@Override
public StorageMessages getMessages() {
return messages;
}
private static ChestLinkMessages messages = new ChestLinkMessages();
private static class ChestLinkMessages extends StorageMessages {
@Override
public String getStorageName() {
return "ChestLink";
}
@Override
public void invalidID(Player target) {
target.sendMessage(ChatColor.RED+"Invalid ChestLink ID! Must not contain a colon ':' unless you are referencing another players group that you are a member off");
target.sendMessage(ChatColor.RED+"/chestlink add <owner>:<group>");
}
@Override
public void listStorageGroups(Player target) {
target.sendMessage(ChatColor.GREEN+""+ChatColor.BOLD+"List of your ChestLinks:");
for(ChestLinkStorage storage : Config.getChestLink().getStorageMap(target.getUniqueId()).values()){
if(storage != null){
target.sendMessage(ChatColor.GREEN+storage.getIdentifier()+ChatColor.WHITE+" - "+storage.getTotalItems()+" items");
}
}
}
@Override
public void mustLookAtBlock(Player player) {
player.sendMessage(ChatColor.RED+TAG+" You must be looking at the chest you want to ChestLink!");
}
@Override
public void invalidSignPlacement(Player player) {
player.sendMessage(ChatColor.GOLD+""+ChatColor.BOLD+TAG+" Invalid ChestLink - You must place a sign on the front of a chest / you should ensure there is space for a sign on front of the chest!");
}
}
}