fixed storage bugs involving slots
This commit is contained in:
parent
54f6377c10
commit
cd5471c5b0
7 changed files with 72 additions and 13 deletions
|
@ -29,15 +29,12 @@ public class StorageCommand implements TabExecutor {
|
|||
Inventory inv;
|
||||
switch (args.length) {
|
||||
case 0:
|
||||
if(playerManager.getRaxenPlayer(player).getStorage() != null) {
|
||||
inv = playerManager.getRaxenPlayer(player).getStorage().getEc().getEc();
|
||||
}
|
||||
else {
|
||||
playerManager.getRaxenPlayer(player).createStorage();
|
||||
if(playerManager.getRaxenPlayer(player).getStorage() == null) {
|
||||
inv = playerManager.getRaxenPlayer(player).createStorage().getEc().getEc();
|
||||
} else {
|
||||
inv = playerManager.getRaxenPlayer(player).getStorage().getEc().getEc();
|
||||
}
|
||||
player.openInventory(inv);
|
||||
|
||||
break;
|
||||
case 1:
|
||||
Player p = Bukkit.getPlayer(args[0]);
|
||||
|
|
|
@ -95,11 +95,11 @@ public class RaxenPlayer {
|
|||
List<String> list = new ArrayList<String>();
|
||||
int reverse = 0;
|
||||
for(ItemStack it : ec) {
|
||||
reverse += 1;
|
||||
if(it != null) {
|
||||
String s = Items.itemStackSerilize(it, reverse);
|
||||
list.add(s);
|
||||
}
|
||||
reverse += 1;
|
||||
}
|
||||
String store = Items.listItemStackSerelize(list);
|
||||
this.storages = new Storage(new EnderChest(ec));
|
||||
|
|
|
@ -54,6 +54,7 @@ public class PlayerConfig {
|
|||
}
|
||||
|
||||
public void saveUsingMongoDB(Player player, Attributes attributes, String invstr, Integer reverse) {
|
||||
debug(main, "Saving " + player.getName() + "'s data!");
|
||||
Document doc = new Document("uuid", player.getUniqueId().toString())
|
||||
.append("name", player.getName())
|
||||
.append("maxHealth", attributes.getMaxHealth(player))
|
||||
|
@ -73,15 +74,16 @@ public class PlayerConfig {
|
|||
.append("inv", invstr);
|
||||
if (playerManager.getRaxenPlayer(player).getStorage() != null) {
|
||||
if(playerManager.getRaxenPlayer(player).getStorage().getEc() != null) {
|
||||
debug(main, "Saving " + player.getName() + "'s storage!");
|
||||
EnderChest ec = playerManager.getRaxenPlayer(player).getStorage().getEc();
|
||||
List<String> list = new ArrayList<String>();
|
||||
reverse = 0;
|
||||
for(ItemStack it : ec.getEc()) {
|
||||
reverse += 1;
|
||||
if(it != null) {
|
||||
if(it != null && it.getType() != Material.AIR) {
|
||||
String s = Items.itemStackSerilize(it, reverse);
|
||||
list.add(s);
|
||||
}
|
||||
reverse += 1;
|
||||
}
|
||||
String ecstr = Items.listItemStackSerelize(list);
|
||||
doc.append("ec", ecstr);
|
||||
|
@ -156,10 +158,9 @@ public class PlayerConfig {
|
|||
playerDoc.getInteger("luck"), playerDoc.getInteger("itemLuck"));
|
||||
Inventory ec = Bukkit.createInventory(null, 54, Component.text("Ender Chest"));
|
||||
if(playerDoc.getString("ec") != null) {
|
||||
debug(main, "Loading " + player.getName() + "'s storage.");
|
||||
ec = setItemsToInventory(listItemStackDeserilize(playerDoc.getString("ec")), ec);
|
||||
}
|
||||
EnderChest ecc = new EnderChest(ec);
|
||||
Storage storage = new Storage(ecc);
|
||||
playerManager.getRaxenPlayer(player).setStorage(ec);
|
||||
PlayerInventory inv = player.getInventory();
|
||||
inv = setItemsToInventory(listItemStackDeserilize(playerDoc.getString("inv")), inv);
|
||||
|
|
|
@ -0,0 +1,26 @@
|
|||
package gq.unurled.raxen.listener.player;
|
||||
|
||||
import gq.unurled.raxen.Raxen;
|
||||
import gq.unurled.raxen.manager.PlayerManager;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.inventory.InventoryCloseEvent;
|
||||
|
||||
import static gq.unurled.raxen.utils.Utils.log;
|
||||
|
||||
public class CloseInventoryEvent implements Listener {
|
||||
|
||||
private PlayerManager playerManager = Raxen.getPlayerManager();
|
||||
|
||||
@EventHandler
|
||||
public void InventoryCloseEvent(InventoryCloseEvent e) {
|
||||
Player player = (Player) e.getPlayer();
|
||||
Component title = e.getView().title();
|
||||
if (title.toString().contains("Ender Chest")) {
|
||||
playerManager.getRaxenPlayer(player).setStorage(e.getInventory());
|
||||
}
|
||||
log(player.getName() + " " + title.toString());
|
||||
}
|
||||
}
|
|
@ -33,6 +33,7 @@ public class ListenerManager {
|
|||
this.pm.registerEvents(new SpawnEvent(main), main);
|
||||
this.pm.registerEvents(new ClickBlockEvent(main), main);
|
||||
this.pm.registerEvents(serverPingEvent, main);
|
||||
this.pm.registerEvents(new CloseInventoryEvent(), main);
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,6 +3,7 @@ package gq.unurled.raxen.utils;
|
|||
import com.google.gson.Gson;
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
import de.tr7zw.nbtapi.NBTItem;
|
||||
import gq.unurled.raxen.Raxen;
|
||||
import gq.unurled.raxen.components.items.Attributes;
|
||||
import gq.unurled.raxen.components.items.NBT;
|
||||
import net.kyori.adventure.text.Component;
|
||||
|
@ -101,14 +102,14 @@ public class Items {
|
|||
Gson gson = new Gson();
|
||||
ItemStack it = new ItemStack(Material.AIR);
|
||||
Integer slot = 0;
|
||||
log("full item " + str);
|
||||
debug("full item " + str);
|
||||
for (String s : mapp) {
|
||||
if(s != null) {
|
||||
try {
|
||||
it = itemFrom64(s);
|
||||
} catch (Exception e) {
|
||||
if (!s.equals("")) {
|
||||
log("slot " + s);
|
||||
debug("slot " + s);
|
||||
slot = Integer.valueOf(s);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,6 +2,7 @@ package gq.unurled.raxen.utils;
|
|||
|
||||
import gq.unurled.raxen.Raxen;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
|
@ -9,6 +10,7 @@ import org.bukkit.entity.Player;
|
|||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
public class Utils {
|
||||
|
@ -23,6 +25,11 @@ public class Utils {
|
|||
return ChatColor.stripColor(color(string));
|
||||
}
|
||||
|
||||
/**
|
||||
* debug output to console if debug is set to true in config
|
||||
* @param main Raxen instance
|
||||
* @param strings ouptut to console
|
||||
*/
|
||||
public static void debug(Raxen main, String... strings) {
|
||||
FileConfiguration config = main.getConfig();
|
||||
if(config.getBoolean("debug")) {
|
||||
|
@ -32,6 +39,32 @@ public class Utils {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* debug output to console if debug is set to true in config
|
||||
* @param strings output to console
|
||||
*/
|
||||
public static void debug(String... strings) {
|
||||
Raxen main = (Raxen) Bukkit.getPluginManager().getPlugin("Raxen");
|
||||
FileConfiguration config = main.getConfig();
|
||||
if(config.getBoolean("debug")) {
|
||||
for(String string : strings) {
|
||||
logger.info(string);
|
||||
}
|
||||
}
|
||||
}
|
||||
/**
|
||||
* debug output to console if debug is set to true in config
|
||||
* @param config main file config
|
||||
* @param strings ouput to console
|
||||
*/
|
||||
public static void debug(FileConfiguration config, String... strings) {
|
||||
if(config.getBoolean("debug")) {
|
||||
for(String string : strings) {
|
||||
logger.info(string);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void log(String... strings) {
|
||||
for(String string : strings) {
|
||||
logger.info(string);
|
||||
|
|
Loading…
Reference in a new issue