Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,36 @@ public Try<Void> setRegisterPapiHook(boolean registerPapiHook) {
return this.configHandle.set(configNodes.registerPapiHook, registerPapiHook);
}

@ApiStatus.AvailableSince("5.2")
public int getMaxInventoryItemsSize() {
return this.configHandle.get(configNodes.maxInventoryItemsSize);
}

@ApiStatus.AvailableSince("5.2")
public Try<Void> setMaxInventoryItemsSize(int maxInventoryItemsSize) {
return this.configHandle.set(configNodes.maxInventoryItemsSize, maxInventoryItemsSize);
}

@ApiStatus.AvailableSince("5.2")
public int getMaxEnderChestItemsSize() {
return this.configHandle.get(configNodes.maxEnderChestItemsSize);
}

@ApiStatus.AvailableSince("5.2")
public Try<Void> setMaxEnderChestItemsSize(int maxEnderChestItemsSize) {
return this.configHandle.set(configNodes.maxEnderChestItemsSize, maxEnderChestItemsSize);
}

@ApiStatus.AvailableSince("5.2")
public int getMaxArmorItemsSize() {
return this.configHandle.get(configNodes.maxArmorItemsSize);
}

@ApiStatus.AvailableSince("5.2")
public Try<Void> setMaxArmorItemsSize(int maxArmorItemsSize) {
return this.configHandle.set(configNodes.maxArmorItemsSize, maxArmorItemsSize);
}

/**
* Tells whether this is the first time the plugin has run as set by a config flag.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import org.mvplugins.multiverse.core.config.node.serializer.NodeSerializer;
import org.mvplugins.multiverse.inventories.share.Sharables;
import org.mvplugins.multiverse.inventories.share.Shares;
import org.mvplugins.multiverse.inventories.util.PlayerStats;

import java.util.ArrayList;
import java.util.List;
Expand Down Expand Up @@ -156,7 +157,6 @@ public Object serialize(Shares sharables, Class<Shares> aClass) {
.build());

final ConfigNode<Boolean> applyPlayerdataOnJoin = node(ConfigNode.builder("performance.apply-playerdata-on-join", Boolean.class)
.comment("")
.comment("This will only work if save-playerdata-on-quit is set to true.")
.comment("Minecraft will already load the most up-to-date player data and this option will generally be redundant.")
.comment("The only possible edge case uses is if you have a need to always modify the mvinv playerdata while the player is offline.")
Expand Down Expand Up @@ -236,6 +236,33 @@ public Object serialize(Shares sharables, Class<Shares> aClass) {
.name("register-papi-hook")
.build());

private final ConfigHeaderNode maxItemsSizeHeader = node(ConfigHeaderNode.builder("misc.max-items-size")
.comment("")
.comment("These are the maximum sizes for each inventory type. You should not change these values unless")
.comment("you have a plugin or feature that changes the size of these inventories.")
.comment("-------")
.comment("Changing these values without a plugin or feature that increases the size of these inventories")
.comment("may result in errors and loss of items when switching worlds/groups. This config option is merely")
.comment("to resolve compatibility issues with other plugins/features that alter inventory sizes.")
.comment("-------")
.comment("One notable example is if you used purpur's config option to increase ender chest size.")
.build());

final ConfigNode<Integer> maxInventoryItemsSize = node(ConfigNode.builder("misc.max-items-size.inventory", Integer.class)
.defaultValue(PlayerStats.INVENTORY_SIZE)
.name("max-player-inventory-size")
.build());

final ConfigNode<Integer> maxEnderChestItemsSize = node(ConfigNode.builder("misc.max-items-size.ender-chest", Integer.class)
.defaultValue(PlayerStats.ENDER_CHEST_SIZE)
.name("max-ender-chest-size")
.build());

final ConfigNode<Integer> maxArmorItemsSize = node(ConfigNode.builder("misc.max-items-size.armor", Integer.class)
.defaultValue(PlayerStats.ARMOR_SIZE)
.name("max-inventory-title-length")
.build());

final ConfigNode<Boolean> firstRun = node(ConfigNode.builder("first-run", Boolean.class)
.comment("")
.comment("")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.mvplugins.multiverse.inventories.share;

import org.mvplugins.multiverse.inventories.MultiverseInventoriesApi;
import org.mvplugins.multiverse.inventories.util.ItemStackConverter;
import org.mvplugins.multiverse.inventories.util.MinecraftTools;
import org.bukkit.Material;
Expand All @@ -12,13 +13,7 @@
* A simple {@link SharableSerializer} usable with ItemStack[] which converts the ItemStack[] to the string format
* that is used by default in Multiverse-Inventories.
*/
final class InventorySerializer implements SharableSerializer<ItemStack[]> {

private final int inventorySize;

public InventorySerializer(final int inventorySize) {
this.inventorySize = inventorySize;
}
abstract class InventorySerializer implements SharableSerializer<ItemStack[]> {

@Override
public ItemStack[] deserialize(Object obj) {
Expand All @@ -42,7 +37,7 @@ private Map<String, Object> mapSlots(ItemStack[] itemStacks) {
}

private ItemStack[] unmapSlots(Object obj) {
ItemStack[] inventory = new ItemStack[inventorySize];
ItemStack[] inventory = new ItemStack[getInventorySize()];
if (!(obj instanceof Map invMap)) {
return MinecraftTools.fillWithAir(inventory);
}
Expand All @@ -61,4 +56,27 @@ private ItemStack[] unmapSlots(Object obj) {
}
return inventory;
}

protected abstract int getInventorySize();

static final class MainInventorySerializer extends InventorySerializer {
@Override
protected int getInventorySize() {
return MultiverseInventoriesApi.get().getInventoriesConfig().getMaxInventoryItemsSize();
}
}

static final class EnderChestSerializer extends InventorySerializer {
@Override
protected int getInventorySize() {
return MultiverseInventoriesApi.get().getInventoriesConfig().getMaxEnderChestItemsSize();
}
}

static final class ArmorSerializer extends InventorySerializer {
@Override
protected int getInventorySize() {
return MultiverseInventoriesApi.get().getInventoriesConfig().getMaxArmorItemsSize();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.advancement.AdvancementProgress;
import org.bukkit.inventory.Inventory;
import org.jetbrains.annotations.ApiStatus;
import org.mvplugins.multiverse.core.economy.MVEconomist;
import org.mvplugins.multiverse.core.teleportation.AsyncSafetyTeleporter;
Expand Down Expand Up @@ -111,16 +112,21 @@ public void updateProfile(ProfileData profile, Player player) {
@Override
public boolean updatePlayer(Player player, ProfileData profile) {
ItemStack[] value = profile.get(ENDER_CHEST);
Inventory enderChest = player.getEnderChest();
if (value == null) {
player.getEnderChest().setContents(MinecraftTools.fillWithAir(
new ItemStack[PlayerStats.ENDER_CHEST_SIZE]));
enderChest.setContents(MinecraftTools.fillWithAir(
new ItemStack[enderChest.getSize()]));
return false;
}
player.getEnderChest().setContents(value);
if (value.length != enderChest.getSize()) {
Logging.fine("Mismatch ender chest size found in profile for player " + player.getName()
+ ". Expected " + enderChest.getSize() + " but got " + value.length + ".");
}
enderChest.setContents(value);
return true;
}
}).serializer(new ProfileEntry(false, DataStrings.ENDER_CHEST_CONTENTS),
new InventorySerializer(PlayerStats.ENDER_CHEST_SIZE)).altName("ender").build();
new InventorySerializer.EnderChestSerializer()).altName("ender").build();

/**
* Sharing Inventory.
Expand All @@ -144,7 +150,7 @@ public boolean updatePlayer(Player player, ProfileData profile) {
return true;
}
}).serializer(new ProfileEntry(false, DataStrings.PLAYER_INVENTORY_CONTENTS),
new InventorySerializer(PlayerStats.INVENTORY_SIZE)).build();
new InventorySerializer.MainInventorySerializer()).build();

/**
* Sharing Armor.
Expand All @@ -168,7 +174,7 @@ public boolean updatePlayer(Player player, ProfileData profile) {
return true;
}
}).serializer(new ProfileEntry(false, DataStrings.PLAYER_ARMOR_CONTENTS),
new InventorySerializer(PlayerStats.ARMOR_SIZE)).altName("armor").build();
new InventorySerializer.ArmorSerializer()).altName("armor").build();

/**
* Sharing Offhand.
Expand Down
4 changes: 4 additions & 0 deletions src/test/resources/config/fresh_config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ performance:

misc:
register-papi-hook: true
max-items-size:
inventory: 36
ender-chest: 27
armor: 4

first-run: true
version: 5.0
4 changes: 4 additions & 0 deletions src/test/resources/config/migrated_config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ performance:

misc:
register-papi-hook: true
max-items-size:
inventory: 36
ender-chest: 27
armor: 4

first-run: true
version: 5.0