Finish dungeon chest rewrite. Resolves #509

This commit is contained in:
Daniel Saukel 2019-02-24 03:05:00 +01:00
parent 9139320888
commit 63092b6d71
3 changed files with 13 additions and 23 deletions

View File

@ -50,14 +50,15 @@ public class DungeonChestSign extends ChestSign {
@Override
public void onInit() {
// For consistency with reward chests but also for intuitiveness, both lines should be possible
if (!lines[1].isEmpty()) {
lootTable = plugin.getCaliburn().getLootTable(lines[1]);
}
if (!lines[2].isEmpty()) {
lootTable = plugin.getCaliburn().getLootTable(lines[2]);
}
if (chest == null) {
checkChest();
}
checkChest();
if (chest != null) {
getSign().getBlock().setType(VanillaItem.AIR.getMaterial());
} else {
@ -65,28 +66,23 @@ public class DungeonChestSign extends ChestSign {
chest = getSign().getBlock();
}
Chest state = (Chest) chest.getState();
List<ItemStack> list = null;
if (lootTable != null) {
list = lootTable.generateLootList();
}
if (chestContent != null) {
if (list != null) {
list = Arrays.asList(chestContent);
} else {
list.addAll(Arrays.asList(chestContent));
} else {
list = Arrays.asList(chestContent);
}
}
if (list == null) {
return;
}
ItemStack[] contents = list.toArray(new ItemStack[list.size()]);
if (contents.length > state.getBlockInventory().getSize()) {
contents = Arrays.copyOfRange(contents, 0, state.getBlockInventory().getSize());
}
state.getBlockInventory().setContents(contents);
state.update();
System.out.println(Arrays.toString(state.getBlockInventory().getContents()));
chestContent = Arrays.copyOfRange(list.toArray(new ItemStack[list.size()]), 0, 26);
((Chest) chest.getState()).getBlockInventory().setContents(chestContent);
}
}

View File

@ -96,10 +96,7 @@ public class RewardChestSign extends ChestSign {
lootTable = plugin.getCaliburn().getLootTable(lines[2]);
}
if (chest == null) {
checkChest();
}
checkChest();
if (chest != null) {
getSign().getBlock().setType(VanillaItem.AIR.getMaterial());
} else {
@ -113,9 +110,9 @@ public class RewardChestSign extends ChestSign {
}
if (chestContent != null) {
if (list != null) {
list = Arrays.asList(chestContent);
} else {
list.addAll(Arrays.asList(chestContent));
} else {
list = Arrays.asList(chestContent);
}
}
if (list == null) {

View File

@ -62,11 +62,8 @@ import org.bukkit.World;
import org.bukkit.block.Block;
import org.bukkit.block.Sign;
import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Hanging;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.entity.Spider;
import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.inventory.ItemStack;