mirror of
https://github.com/DRE2N/DungeonsXL.git
synced 2024-11-28 13:36:33 +01:00
#509: Add DungeonChest sign; rename Chest sign to RewardChest sign [WIP]
This commit is contained in:
parent
808f5a03aa
commit
6057044935
@ -17,15 +17,9 @@
|
|||||||
package de.erethon.dungeonsxl.sign;
|
package de.erethon.dungeonsxl.sign;
|
||||||
|
|
||||||
import de.erethon.caliburn.category.Category;
|
import de.erethon.caliburn.category.Category;
|
||||||
import de.erethon.caliburn.item.VanillaItem;
|
|
||||||
import de.erethon.caliburn.loottable.LootTable;
|
import de.erethon.caliburn.loottable.LootTable;
|
||||||
import de.erethon.commons.misc.NumberUtil;
|
|
||||||
import de.erethon.dungeonsxl.DungeonsXL;
|
import de.erethon.dungeonsxl.DungeonsXL;
|
||||||
import de.erethon.dungeonsxl.world.DGameWorld;
|
import de.erethon.dungeonsxl.world.DGameWorld;
|
||||||
import de.erethon.dungeonsxl.world.block.RewardChest;
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.LinkedList;
|
|
||||||
import java.util.List;
|
|
||||||
import org.bukkit.block.Block;
|
import org.bukkit.block.Block;
|
||||||
import org.bukkit.block.Chest;
|
import org.bukkit.block.Chest;
|
||||||
import org.bukkit.block.Sign;
|
import org.bukkit.block.Sign;
|
||||||
@ -34,50 +28,18 @@ import org.bukkit.inventory.ItemStack;
|
|||||||
/**
|
/**
|
||||||
* @author Frank Baumann, Daniel Saukel
|
* @author Frank Baumann, Daniel Saukel
|
||||||
*/
|
*/
|
||||||
public class ChestSign extends DSign {
|
public abstract class ChestSign extends DSign {
|
||||||
|
|
||||||
private DSignType type = DSignTypeDefault.CHEST;
|
protected Block chest;
|
||||||
|
|
||||||
private Block chest;
|
protected ItemStack[] chestContent;
|
||||||
|
protected LootTable lootTable;
|
||||||
|
|
||||||
private double moneyReward;
|
protected ChestSign(DungeonsXL plugin, Sign sign, String[] lines, DGameWorld gameWorld) {
|
||||||
private int levelReward;
|
|
||||||
private ItemStack[] chestContent;
|
|
||||||
private LootTable lootTable;
|
|
||||||
|
|
||||||
public ChestSign(DungeonsXL plugin, Sign sign, String[] lines, DGameWorld gameWorld) {
|
|
||||||
super(plugin, sign, lines, gameWorld);
|
super(plugin, sign, lines, gameWorld);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Getters and setters */
|
/* Getters and setters */
|
||||||
/**
|
|
||||||
* @return the money reward
|
|
||||||
*/
|
|
||||||
public double getMoneyReward() {
|
|
||||||
return moneyReward;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param amount the amount to set
|
|
||||||
*/
|
|
||||||
public void setMoneyReward(double amount) {
|
|
||||||
moneyReward = amount;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return the level reward
|
|
||||||
*/
|
|
||||||
public int getLevelReward() {
|
|
||||||
return levelReward;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param amount the amount to set
|
|
||||||
*/
|
|
||||||
public void setLevelReward(int amount) {
|
|
||||||
levelReward = amount;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return the chest contents
|
* @return the chest contents
|
||||||
*/
|
*/
|
||||||
@ -91,7 +53,7 @@ public class ChestSign extends DSign {
|
|||||||
/**
|
/**
|
||||||
* @param items the items to set as chest contents
|
* @param items the items to set as chest contents
|
||||||
*/
|
*/
|
||||||
public void setItemReward(ItemStack[] items) {
|
public void setChestContents(ItemStack[] items) {
|
||||||
chestContent = items;
|
chestContent = items;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -109,16 +71,11 @@ public class ChestSign extends DSign {
|
|||||||
this.lootTable = lootTable;
|
this.lootTable = lootTable;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public DSignType getType() {
|
|
||||||
return type;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Actions */
|
/* Actions */
|
||||||
/**
|
/**
|
||||||
* Checks for a chest next to the sign and sets the reward to its contents.
|
* Checks for a chest next to the sign and sets the reward to its contents.
|
||||||
*/
|
*/
|
||||||
public void checkChest() {
|
protected void checkChest() {
|
||||||
Block sign = getSign().getBlock();
|
Block sign = getSign().getBlock();
|
||||||
for (int i = -1; i <= 1; i++) {
|
for (int i = -1; i <= 1; i++) {
|
||||||
Block xRelative = sign.getRelative(i, 0, 0);
|
Block xRelative = sign.getRelative(i, 0, 0);
|
||||||
@ -146,45 +103,4 @@ public class ChestSign extends DSign {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean check() {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onInit() {
|
|
||||||
if (!lines[1].isEmpty()) {
|
|
||||||
String[] attributes = lines[1].split(",");
|
|
||||||
if (attributes.length >= 1) {
|
|
||||||
moneyReward = NumberUtil.parseDouble(attributes[0]);
|
|
||||||
}
|
|
||||||
if (attributes.length >= 2) {
|
|
||||||
levelReward = NumberUtil.parseInt(attributes[1]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!lines[2].isEmpty()) {
|
|
||||||
lootTable = plugin.getCaliburn().getLootTable(lines[2]);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (chest == null) {
|
|
||||||
checkChest();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (chest != null) {
|
|
||||||
ItemStack[] itemReward = chestContent;
|
|
||||||
if (lootTable != null) {
|
|
||||||
List<ItemStack> list = new LinkedList<>(Arrays.asList(chestContent));
|
|
||||||
list.addAll(lootTable.generateLootList());
|
|
||||||
itemReward = list.toArray(new ItemStack[list.size()]);
|
|
||||||
}
|
|
||||||
|
|
||||||
getGameWorld().addGameBlock(new RewardChest(plugin, chest, moneyReward, levelReward, itemReward));
|
|
||||||
getSign().getBlock().setType(VanillaItem.AIR.getMaterial());
|
|
||||||
|
|
||||||
} else {
|
|
||||||
markAsErroneous("No chest attached");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -39,11 +39,13 @@ public enum DSignTypeDefault implements DSignType {
|
|||||||
BLOCK("Block", "block", false, true, BlockSign.class),
|
BLOCK("Block", "block", false, true, BlockSign.class),
|
||||||
BOSS_SHOP("BossShop", "bossshop", false, true, BossShopSign.class),
|
BOSS_SHOP("BossShop", "bossshop", false, true, BossShopSign.class),
|
||||||
CHECKPOINT("Checkpoint", "checkpoint", false, false, CheckpointSign.class),
|
CHECKPOINT("Checkpoint", "checkpoint", false, false, CheckpointSign.class),
|
||||||
CHEST("Chest", "chest", false, false, ChestSign.class),
|
@Deprecated
|
||||||
|
CHEST("Chest", "chest", false, false, RewardChestSign.class),
|
||||||
CHUNK_UPDATER("ChunkUpdater", "chunkupdater", true, false, ChunkUpdaterSign.class),
|
CHUNK_UPDATER("ChunkUpdater", "chunkupdater", true, false, ChunkUpdaterSign.class),
|
||||||
CLASSES("Classes", "classes", true, true, ClassesSign.class),
|
CLASSES("Classes", "classes", true, true, ClassesSign.class),
|
||||||
COMMAND("CMD", "cmd", false, false, CommandSign.class),
|
COMMAND("CMD", "cmd", false, false, CommandSign.class),
|
||||||
DROP("Drop", "drop", false, false, DropSign.class),
|
DROP("Drop", "drop", false, false, DropSign.class),
|
||||||
|
DUNGEON_CHEST("DungeonChest", "dungeonchest", true, false, DungeonChestSign.class),
|
||||||
END("End", "end", false, true, EndSign.class),
|
END("End", "end", false, true, EndSign.class),
|
||||||
@Deprecated
|
@Deprecated
|
||||||
EXTERNAL_MOB("ExternalMob", "mob", false, false, MobSign.class),
|
EXTERNAL_MOB("ExternalMob", "mob", false, false, MobSign.class),
|
||||||
@ -63,6 +65,7 @@ public enum DSignTypeDefault implements DSignType {
|
|||||||
READY("Ready", "ready", true, true, ReadySign.class),
|
READY("Ready", "ready", true, true, ReadySign.class),
|
||||||
REDSTONE("Redstone", "redstone", false, false, RedstoneSign.class),
|
REDSTONE("Redstone", "redstone", false, false, RedstoneSign.class),
|
||||||
RESOURCE_PACK("ResourcePack", "resourcepack", true, true, ResourcePackSign.class),
|
RESOURCE_PACK("ResourcePack", "resourcepack", true, true, ResourcePackSign.class),
|
||||||
|
REWARD_CHEST("RewardChest", "rewardchest", false, false, RewardChestSign.class),
|
||||||
SCRIPT("Script", "script", false, false, ScriptSign.class),
|
SCRIPT("Script", "script", false, false, ScriptSign.class),
|
||||||
SOUND_MESSAGE("SoundMSG", "soundmsg", false, false, SoundMessageSign.class),
|
SOUND_MESSAGE("SoundMSG", "soundmsg", false, false, SoundMessageSign.class),
|
||||||
START("Start", "start", true, false, StartSign.class),
|
START("Start", "start", true, false, StartSign.class),
|
||||||
|
@ -0,0 +1,92 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2012-2018 Frank Baumann
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
package de.erethon.dungeonsxl.sign;
|
||||||
|
|
||||||
|
import de.erethon.caliburn.item.VanillaItem;
|
||||||
|
import de.erethon.dungeonsxl.DungeonsXL;
|
||||||
|
import de.erethon.dungeonsxl.world.DGameWorld;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
|
import org.bukkit.block.Chest;
|
||||||
|
import org.bukkit.block.Sign;
|
||||||
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Daniel Saukel
|
||||||
|
*/
|
||||||
|
public class DungeonChestSign extends ChestSign {
|
||||||
|
|
||||||
|
private DSignType type = DSignTypeDefault.DUNGEON_CHEST;
|
||||||
|
|
||||||
|
public DungeonChestSign(DungeonsXL plugin, Sign sign, String[] lines, DGameWorld gameWorld) {
|
||||||
|
super(plugin, sign, lines, gameWorld);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Getters and setters */
|
||||||
|
@Override
|
||||||
|
public DSignType getType() {
|
||||||
|
return type;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Actions */
|
||||||
|
@Override
|
||||||
|
public boolean check() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onInit() {
|
||||||
|
if (!lines[2].isEmpty()) {
|
||||||
|
lootTable = plugin.getCaliburn().getLootTable(lines[2]);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (chest == null) {
|
||||||
|
checkChest();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (chest != null) {
|
||||||
|
getSign().getBlock().setType(VanillaItem.AIR.getMaterial());
|
||||||
|
} else {
|
||||||
|
getSign().getBlock().setType(VanillaItem.CHEST.getMaterial());
|
||||||
|
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));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
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()));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
128
src/main/java/de/erethon/dungeonsxl/sign/RewardChestSign.java
Normal file
128
src/main/java/de/erethon/dungeonsxl/sign/RewardChestSign.java
Normal file
@ -0,0 +1,128 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2012-2018 Frank Baumann
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
package de.erethon.dungeonsxl.sign;
|
||||||
|
|
||||||
|
import de.erethon.caliburn.item.VanillaItem;
|
||||||
|
import de.erethon.commons.misc.NumberUtil;
|
||||||
|
import de.erethon.dungeonsxl.DungeonsXL;
|
||||||
|
import de.erethon.dungeonsxl.world.DGameWorld;
|
||||||
|
import de.erethon.dungeonsxl.world.block.RewardChest;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
|
import org.bukkit.block.Sign;
|
||||||
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Daniel Saukel
|
||||||
|
*/
|
||||||
|
public class RewardChestSign extends ChestSign {
|
||||||
|
|
||||||
|
private DSignType type = DSignTypeDefault.REWARD_CHEST;
|
||||||
|
|
||||||
|
private double moneyReward;
|
||||||
|
private int levelReward;
|
||||||
|
|
||||||
|
public RewardChestSign(DungeonsXL plugin, Sign sign, String[] lines, DGameWorld gameWorld) {
|
||||||
|
super(plugin, sign, lines, gameWorld);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Getters and setters */
|
||||||
|
/**
|
||||||
|
* @return the money reward
|
||||||
|
*/
|
||||||
|
public double getMoneyReward() {
|
||||||
|
return moneyReward;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param amount the amount to set
|
||||||
|
*/
|
||||||
|
public void setMoneyReward(double amount) {
|
||||||
|
moneyReward = amount;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return the level reward
|
||||||
|
*/
|
||||||
|
public int getLevelReward() {
|
||||||
|
return levelReward;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param amount the amount to set
|
||||||
|
*/
|
||||||
|
public void setLevelReward(int amount) {
|
||||||
|
levelReward = amount;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public DSignType getType() {
|
||||||
|
return type;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Actions */
|
||||||
|
@Override
|
||||||
|
public boolean check() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onInit() {
|
||||||
|
if (!lines[1].isEmpty()) {
|
||||||
|
String[] attributes = lines[1].split(",");
|
||||||
|
if (attributes.length >= 1) {
|
||||||
|
moneyReward = NumberUtil.parseDouble(attributes[0]);
|
||||||
|
}
|
||||||
|
if (attributes.length >= 2) {
|
||||||
|
levelReward = NumberUtil.parseInt(attributes[1]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!lines[2].isEmpty()) {
|
||||||
|
lootTable = plugin.getCaliburn().getLootTable(lines[2]);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (chest == null) {
|
||||||
|
checkChest();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (chest != null) {
|
||||||
|
getSign().getBlock().setType(VanillaItem.AIR.getMaterial());
|
||||||
|
} else {
|
||||||
|
getSign().getBlock().setType(VanillaItem.CHEST.getMaterial());
|
||||||
|
chest = getSign().getBlock();
|
||||||
|
}
|
||||||
|
|
||||||
|
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));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (list == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
getGameWorld().addGameBlock(new RewardChest(plugin, chest, moneyReward, levelReward, list.toArray(new ItemStack[list.size()])));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user