Fixed all issues with F chest, and a massive increase in performance due to /f chest only serializing / deserializing on startup/shutdown instead of realtime.
This commit is contained in:
parent
9795d3c158
commit
4ad062dddb
@ -95,9 +95,9 @@ public interface Faction extends EconomyParticipator {
|
||||
|
||||
void setVault(Location vaultLocation);
|
||||
|
||||
Inventory getChest();
|
||||
Inventory getChestInventory();
|
||||
|
||||
void setChest(Inventory inventory);
|
||||
void setChestSize(int chestSize);
|
||||
|
||||
void setBannerPattern(ItemStack banner);
|
||||
|
||||
|
@ -31,6 +31,7 @@ import org.bukkit.entity.ArmorStand;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.player.AsyncPlayerChatEvent;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
@ -218,6 +219,7 @@ public class P extends MPlugin {
|
||||
|
||||
|
||||
|
||||
|
||||
setupPlaceholderAPI();
|
||||
postEnable();
|
||||
this.loadSuccessful = true;
|
||||
@ -391,6 +393,7 @@ public class P extends MPlugin {
|
||||
.registerTypeAdapter(accessTypeAdatper, new PermissionsMapTypeAdapter())
|
||||
.registerTypeAdapter(LazyLocation.class, new MyLocationTypeAdapter())
|
||||
.registerTypeAdapter(mapFLocToStringSetType, new MapFLocToStringSetTypeAdapter())
|
||||
.registerTypeAdapter(Inventory.class, new InventoryTypeAdapter())
|
||||
.registerTypeAdapterFactory(EnumTypeAdapter.ENUM_FACTORY);
|
||||
}
|
||||
|
||||
|
@ -27,6 +27,7 @@ public class CmdChest extends FCommand {
|
||||
@Override
|
||||
public void perform() {
|
||||
|
||||
|
||||
if (!P.p.getConfig().getBoolean("fchest.Enabled")) {
|
||||
fme.sendMessage("This command is disabled!");
|
||||
return;
|
||||
@ -40,7 +41,7 @@ public class CmdChest extends FCommand {
|
||||
}
|
||||
}
|
||||
|
||||
me.openInventory(fme.getFaction().getChest());
|
||||
me.openInventory(fme.getFaction().getChestInventory());
|
||||
|
||||
|
||||
}
|
||||
|
@ -611,27 +611,7 @@ public class FactionsPlayerListener implements Listener {
|
||||
return (result.length() == 3 ? result + "0" : result) + "/hrs ago";
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onCloseChest(InventoryCloseEvent e) {
|
||||
if (e.getInventory().getTitle() == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (e.getInventory().getTitle().equalsIgnoreCase(P.p.color(P.p.getConfig().getString("fchest.Inventory-Title")))) {
|
||||
FPlayers.getInstance().getByPlayer((Player) e.getPlayer()).getFaction().setChest(e.getInventory());
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onCloseChest(InventoryClickEvent e) {
|
||||
if (e.getInventory().getTitle() == null || e.getClickedInventory() == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (e.getInventory().getTitle().equalsIgnoreCase(P.p.color(P.p.getConfig().getString("fchest.Inventory-Title")))) {
|
||||
FPlayers.getInstance().getByPlayer((Player) e.getWhoClicked()).getFaction().setChest(e.getInventory());
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
||||
public void onPlayerMove(PlayerMoveEvent event) {
|
||||
|
@ -0,0 +1,29 @@
|
||||
package com.massivecraft.factions.util;
|
||||
|
||||
import com.google.gson.*;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
|
||||
public class InventoryTypeAdapter implements JsonSerializer<Inventory>, JsonDeserializer<Inventory> {
|
||||
|
||||
|
||||
@Override
|
||||
public JsonElement serialize(Inventory inventory, Type type, JsonSerializationContext jsonSerializationContext) {
|
||||
|
||||
JsonObject object = new JsonObject();
|
||||
object.add("contents", new JsonPrimitive(InventoryUtil.toBase64(inventory)));
|
||||
return object;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public Inventory deserialize(JsonElement jsonElement, Type type, JsonDeserializationContext jsonDeserializationContext) {
|
||||
JsonObject object = jsonElement.getAsJsonObject();
|
||||
return InventoryUtil.fromBase64(object.get("contents").getAsString());
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
@ -4,8 +4,6 @@ import com.massivecraft.factions.FPlayer;
|
||||
import com.massivecraft.factions.FPlayers;
|
||||
import com.massivecraft.factions.Faction;
|
||||
import com.massivecraft.factions.P;
|
||||
import com.massivecraft.factions.zcore.util.TL;
|
||||
import net.milkbowl.vault.economy.Economy;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.enchantments.Enchantment;
|
||||
@ -187,7 +185,7 @@ public class FUpgradesGUI implements Listener {
|
||||
}
|
||||
takeMoney(fme, cost);
|
||||
fme.getFaction().setUpgrades("Chest", 3);
|
||||
closeChests(fme.getFaction());
|
||||
updateChests(fme.getFaction());
|
||||
fme.getPlayer().closeInventory();
|
||||
}
|
||||
if (chestLevel == 1) {
|
||||
@ -197,7 +195,7 @@ public class FUpgradesGUI implements Listener {
|
||||
}
|
||||
takeMoney(fme, cost);
|
||||
fme.getFaction().setUpgrades("Chest", 2);
|
||||
closeChests(fme.getFaction());
|
||||
updateChests(fme.getFaction());
|
||||
fme.getPlayer().closeInventory();
|
||||
}
|
||||
if (chestLevel == 0) {
|
||||
@ -207,7 +205,7 @@ public class FUpgradesGUI implements Listener {
|
||||
}
|
||||
takeMoney(fme, cost);
|
||||
fme.getFaction().setUpgrades("Chest", 1);
|
||||
closeChests(fme.getFaction());
|
||||
updateChests(fme.getFaction());
|
||||
fme.getPlayer().closeInventory();
|
||||
}
|
||||
}
|
||||
@ -216,7 +214,7 @@ public class FUpgradesGUI implements Listener {
|
||||
|
||||
}
|
||||
|
||||
private void closeChests(Faction faction) {
|
||||
private void updateChests(Faction faction) {
|
||||
for (Player player : faction.getOnlinePlayers()) {
|
||||
if (player.getInventory().getTitle() == null) {
|
||||
return;
|
||||
@ -226,6 +224,19 @@ public class FUpgradesGUI implements Listener {
|
||||
player.closeInventory();
|
||||
}
|
||||
}
|
||||
|
||||
int level = faction.getUpgrade("Chest");
|
||||
int size = 9;
|
||||
if (level == 1) {
|
||||
size = P.p.getConfig().getInt("fupgrades.MainMenu.Chest.Chest-Size.level-1") * 9;
|
||||
} else if (level == 2) {
|
||||
size = P.p.getConfig().getInt("fupgrades.MainMenu.Chest.Chest-Size.level-2") * 9;
|
||||
} else if (level == 3) {
|
||||
size = P.p.getConfig().getInt("fupgrades.MainMenu.Chest.Chest-Size.level-3") * 9;
|
||||
}
|
||||
|
||||
faction.setChestSize(size);
|
||||
|
||||
}
|
||||
|
||||
private ItemStack[] buildItems(FPlayer fme) {
|
||||
|
@ -62,7 +62,7 @@ public abstract class MemoryFaction implements Faction, EconomyParticipator {
|
||||
protected Role defaultRole;
|
||||
protected Map<Permissable, Map<PermissableAction, Access>> permissions = new HashMap<>();
|
||||
protected Set<BanInfo> bans = new HashSet<>();
|
||||
String chestSerialized = null;
|
||||
Inventory chest;
|
||||
Map<String, Object> bannerSerialized;
|
||||
private long lastDeath;
|
||||
|
||||
@ -340,7 +340,10 @@ public abstract class MemoryFaction implements Faction, EconomyParticipator {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Inventory getChest() {
|
||||
public Inventory getChestInventory() {
|
||||
if (chest != null) {
|
||||
return chest;
|
||||
} else {
|
||||
int level = getUpgrade("Chest");
|
||||
int size = 9;
|
||||
if (level == 1) {
|
||||
@ -350,25 +353,22 @@ public abstract class MemoryFaction implements Faction, EconomyParticipator {
|
||||
} else if (level == 3) {
|
||||
size = P.p.getConfig().getInt("fupgrades.MainMenu.Chest.Chest-Size.level-3") * 9;
|
||||
}
|
||||
Inventory inventory = Bukkit.createInventory(null, size, P.p.color(P.p.getConfig().getString("fchest.Inventory-Title")));
|
||||
if (chestSerialized == null) {
|
||||
return inventory;
|
||||
} else {
|
||||
//long startTime = System.nanoTime();
|
||||
ItemStack[] contents = new ItemStack[0];
|
||||
|
||||
contents = InventoryUtil.fromBase64(chestSerialized).getContents();
|
||||
chest = Bukkit.createInventory(null, size);
|
||||
return chest;
|
||||
|
||||
inventory.setContents(contents);
|
||||
return inventory;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setChest(Inventory inventory) {
|
||||
chestSerialized = InventoryUtil.toBase64(inventory);
|
||||
public void setChestSize(int chestSize) {
|
||||
ItemStack[] contents = this.getChestInventory().getContents();
|
||||
chest = Bukkit.createInventory(null, chestSize);
|
||||
chest.setContents(contents);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void setBannerPattern(ItemStack banner) {
|
||||
bannerSerialized = banner.serialize();
|
||||
|
Loading…
Reference in New Issue
Block a user