Fixed a Few Things

This commit is contained in:
Driftay 2019-09-20 16:59:31 -04:00
parent 81636c6448
commit d6ca2934de
5 changed files with 16 additions and 11 deletions

View File

@ -3,7 +3,6 @@ package com.massivecraft.factions.shop;
import com.github.stefvanschie.inventoryframework.Gui; import com.github.stefvanschie.inventoryframework.Gui;
import com.github.stefvanschie.inventoryframework.GuiItem; import com.github.stefvanschie.inventoryframework.GuiItem;
import com.github.stefvanschie.inventoryframework.pane.PaginatedPane; import com.github.stefvanschie.inventoryframework.pane.PaginatedPane;
import com.google.common.collect.ImmutableList;
import com.massivecraft.factions.FPlayer; import com.massivecraft.factions.FPlayer;
import com.massivecraft.factions.FPlayers; import com.massivecraft.factions.FPlayers;
import com.massivecraft.factions.Faction; import com.massivecraft.factions.Faction;
@ -21,7 +20,6 @@ import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta; import org.bukkit.inventory.meta.ItemMeta;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.stream.Collectors; import java.util.stream.Collectors;

View File

@ -1,6 +1,8 @@
package com.massivecraft.factions.util; package com.massivecraft.factions.util;
import com.google.gson.*; import com.google.gson.*;
import com.massivecraft.factions.Conf;
import com.massivecraft.factions.FactionsPlugin;
import org.bukkit.inventory.Inventory; import org.bukkit.inventory.Inventory;
import java.lang.reflect.Type; import java.lang.reflect.Type;
@ -20,8 +22,6 @@ public class InventoryTypeAdapter implements JsonSerializer<Inventory>, JsonDese
@Override @Override
public Inventory deserialize(JsonElement jsonElement, Type type, JsonDeserializationContext jsonDeserializationContext) { public Inventory deserialize(JsonElement jsonElement, Type type, JsonDeserializationContext jsonDeserializationContext) {
JsonObject object = jsonElement.getAsJsonObject(); JsonObject object = jsonElement.getAsJsonObject();
return InventoryUtil.fromBase64(object.get("contents").getAsString()); return InventoryUtil.fromBase64(object.get("contents").getAsString(), FactionsPlugin.getInstance().color(FactionsPlugin.getInstance().getConfig().getString("fchest.Inventory-Title")));
} }
} }

View File

@ -1,5 +1,6 @@
package com.massivecraft.factions.util; package com.massivecraft.factions.util;
import com.massivecraft.factions.FactionsPlugin;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.inventory.Inventory; import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
@ -71,11 +72,11 @@ public class InventoryUtil {
return toBase64(inventory); return toBase64(inventory);
} }
public static Inventory fromBase64(String data) { public static Inventory fromBase64(String data, String invName) {
try { try {
ByteArrayInputStream inputStream = new ByteArrayInputStream(Base64Coder.decodeLines(data)); ByteArrayInputStream inputStream = new ByteArrayInputStream(Base64Coder.decodeLines(data));
BukkitObjectInputStream dataInput = new BukkitObjectInputStream(inputStream); BukkitObjectInputStream dataInput = new BukkitObjectInputStream(inputStream);
Inventory inventory = Bukkit.getServer().createInventory(null, dataInput.readInt()); Inventory inventory = Bukkit.getServer().createInventory(null, dataInput.readInt(), FactionsPlugin.getInstance().color(invName));
// Read the serialized inventory // Read the serialized inventory
for (int i = 0; i < inventory.getSize(); i++) { for (int i = 0; i < inventory.getSize(); i++) {

View File

@ -8,6 +8,7 @@ import com.massivecraft.factions.util.XMaterial;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.enchantments.Enchantment; import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.HumanEntity;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
@ -272,7 +273,7 @@ public class FUpgradesGUI implements Listener {
private void updateChests(Faction faction) { private void updateChests(Faction faction) {
String invName = FactionsPlugin.getInstance().color(FactionsPlugin.getInstance().getConfig().getString("fchest.Inventory-Title")); String invName = FactionsPlugin.getInstance().color(FactionsPlugin.getInstance().getConfig().getString("fchest.Inventory-Title"));
for (Player player : faction.getOnlinePlayers()) { for (HumanEntity player : faction.getChestInventory().getViewers()) {
if (player.getInventory().getTitle() != null && player.getInventory().getTitle().equalsIgnoreCase(invName)) if (player.getInventory().getTitle() != null && player.getInventory().getTitle().equalsIgnoreCase(invName))
player.closeInventory(); player.closeInventory();
} }

View File

@ -423,8 +423,14 @@ public abstract class MemoryFaction implements Faction, EconomyParticipator {
@Override @Override
public Inventory getChestInventory() { public Inventory getChestInventory() {
if (chest != null) return chest; if (chest == null) {
this.chest = Bukkit.createInventory(null, getChestSize(), FactionsPlugin.getInstance().color(FactionsPlugin.getInstance().getConfig().getString("fchest.Inventory-Title")));
return chest;
}
return chest;
}
private int getChestSize() {
int size = 9; int size = 9;
switch (getUpgrade(UpgradeType.CHEST)) { switch (getUpgrade(UpgradeType.CHEST)) {
case 1: case 1:
@ -437,8 +443,7 @@ public abstract class MemoryFaction implements Faction, EconomyParticipator {
size = FactionsPlugin.getInstance().getConfig().getInt("fupgrades.MainMenu.Chest.Chest-Size.level-3") * 9; size = FactionsPlugin.getInstance().getConfig().getInt("fupgrades.MainMenu.Chest.Chest-Size.level-3") * 9;
break; break;
} }
chest = Bukkit.createInventory(null, size, FactionsPlugin.getInstance().color(FactionsPlugin.getInstance().getConfig().getString("fchest.Inventory-Title"))); return size;
return chest;
} }