mirror of
https://github.com/PikaMug/Quests.git
synced 2024-11-21 18:15:32 +01:00
Improved block tracking by @IllusionTheDev (#2270)
* Initial support for modern block tracking * Use BlockItemStack for other block events * Change internals to use BlockItemStack * Update types and compare * legacy block data support * Fix item name translation * Remove unused imports and cleanup * Blocks do not have display names * help I accidentally ran the auto formatter * Cast the correct value * Tiny format * Use correct goal object --------- Co-authored-by: Illusion <imdatillusion@gmail.com>
This commit is contained in:
parent
70119ad4ab
commit
c9d77d5708
@ -15,6 +15,7 @@ import me.pikamug.quests.quests.components.Stage;
|
||||
import me.pikamug.quests.quests.components.Objective;
|
||||
import me.pikamug.quests.enums.ObjectiveType;
|
||||
import me.pikamug.quests.module.CustomObjective;
|
||||
import me.pikamug.quests.util.stack.BlockItemStack;
|
||||
import org.bukkit.DyeColor;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
@ -145,16 +146,31 @@ public interface Quester extends Comparable<Quester> {
|
||||
|
||||
void showCurrentConditions(final Quest quest, final Quester quester);
|
||||
|
||||
@Deprecated
|
||||
void breakBlock(final Quest quest, final ItemStack itemStack);
|
||||
|
||||
void breakBlock(final Quest quest, final BlockItemStack blockItemStack);
|
||||
|
||||
@Deprecated
|
||||
void damageBlock(final Quest quest, final ItemStack itemStack);
|
||||
|
||||
void damageBlock(final Quest quest, final BlockItemStack blockItemStack);
|
||||
|
||||
@Deprecated
|
||||
void placeBlock(final Quest quest, final ItemStack itemStack);
|
||||
|
||||
void placeBlock(final Quest quest, final BlockItemStack blockItemStack);
|
||||
|
||||
@Deprecated
|
||||
void useBlock(final Quest quest, final ItemStack itemStack);
|
||||
|
||||
void useBlock(final Quest quest, final BlockItemStack blockItemStack);
|
||||
|
||||
@Deprecated
|
||||
void cutBlock(final Quest quest, final ItemStack itemStack);
|
||||
|
||||
void cutBlock(final Quest quest, final BlockItemStack blockItemStack);
|
||||
|
||||
void craftItem(final Quest quest, final ItemStack itemStack);
|
||||
|
||||
void smeltItem(final Quest quest, final ItemStack itemStack);
|
||||
|
@ -0,0 +1,39 @@
|
||||
package me.pikamug.quests.util.stack;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
public interface BlockItemStack {
|
||||
|
||||
static BlockItemStack of(final ItemStack original) {
|
||||
if (original == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return of(original.getType(), original.getAmount(), original.getDurability());
|
||||
}
|
||||
|
||||
static BlockItemStack of(final Block block) {
|
||||
return BlockItemStacks.getFactory().of(block);
|
||||
}
|
||||
|
||||
static BlockItemStack of(final Material type, final int amount, final short durability) {
|
||||
return BlockItemStacks.getFactory().of(type, amount, durability);
|
||||
}
|
||||
|
||||
static BlockItemStack clone(final BlockItemStack original, final int amount) {
|
||||
return BlockItemStacks.getFactory().clone(original, amount);
|
||||
}
|
||||
|
||||
static BlockItemStack clone(final BlockItemStack original, final int amount, final short durability) {
|
||||
return BlockItemStacks.getFactory().clone(original, amount, durability);
|
||||
}
|
||||
|
||||
Material getType();
|
||||
int getAmount();
|
||||
short getDurability();
|
||||
|
||||
boolean matches(BlockItemStack other);
|
||||
|
||||
}
|
@ -0,0 +1,12 @@
|
||||
package me.pikamug.quests.util.stack;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
|
||||
public interface BlockItemStackFactory {
|
||||
|
||||
BlockItemStack of(final Block block);
|
||||
BlockItemStack of(final Material type, final int amount, final short durability);
|
||||
BlockItemStack clone(final BlockItemStack original, final int amount);
|
||||
BlockItemStack clone(final BlockItemStack original, final int amount, final short durability);
|
||||
}
|
@ -0,0 +1,32 @@
|
||||
package me.pikamug.quests.util.stack;
|
||||
|
||||
import me.pikamug.quests.util.stack.impl.LegacyBlockItemStack;
|
||||
import me.pikamug.quests.util.stack.impl.ModernBlockItemStack;
|
||||
|
||||
public final class BlockItemStacks {
|
||||
|
||||
private BlockItemStacks() {
|
||||
}
|
||||
|
||||
private static BlockItemStackFactory factory;
|
||||
|
||||
public static BlockItemStackFactory getFactory() {
|
||||
return factory;
|
||||
}
|
||||
|
||||
private static void setFactory(final BlockItemStackFactory factory) {
|
||||
if (BlockItemStacks.factory != null) {
|
||||
throw new IllegalStateException("Factory is already set");
|
||||
}
|
||||
|
||||
BlockItemStacks.factory = factory;
|
||||
}
|
||||
|
||||
public static void init(final boolean modern) {
|
||||
if (modern) {
|
||||
setFactory(ModernBlockItemStack.FACTORY);
|
||||
} else {
|
||||
setFactory(LegacyBlockItemStack.FACTORY);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,90 @@
|
||||
package me.pikamug.quests.util.stack.impl;
|
||||
|
||||
import me.pikamug.quests.util.stack.BlockItemStack;
|
||||
import me.pikamug.quests.util.stack.BlockItemStackFactory;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.material.MaterialData;
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public class LegacyBlockItemStack implements BlockItemStack {
|
||||
|
||||
public static final BlockItemStackFactory FACTORY = new Factory();
|
||||
|
||||
private final MaterialData materialData;
|
||||
private int amount;
|
||||
|
||||
private LegacyBlockItemStack(final MaterialData materialData, final int amount) {
|
||||
this.materialData = materialData;
|
||||
this.amount = amount;
|
||||
}
|
||||
|
||||
public MaterialData getMaterialData() {
|
||||
return materialData;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getAmount() {
|
||||
return amount;
|
||||
}
|
||||
|
||||
@Override
|
||||
public short getDurability() {
|
||||
return materialData.getData();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Material getType() {
|
||||
return materialData.getItemType();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean matches(BlockItemStack other) {
|
||||
if (other == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
final MaterialData blockData = Factory.getBlockData(other);
|
||||
return this.materialData.equals(blockData) && (getDurability() == 0 || getDurability() == other.getDurability());
|
||||
}
|
||||
|
||||
public void setAmount(int amount) {
|
||||
this.amount = amount;
|
||||
}
|
||||
|
||||
public static class Factory implements BlockItemStackFactory {
|
||||
|
||||
@Override
|
||||
public BlockItemStack of(final Block block) {
|
||||
final MaterialData data = block.getState().getData();
|
||||
return new LegacyBlockItemStack(data, 1);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockItemStack of(final Material type, final int amount, final short durability) {
|
||||
final MaterialData data = type.getNewData((byte) durability);
|
||||
return new LegacyBlockItemStack(data, amount);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockItemStack clone(final BlockItemStack original, final int amount) {
|
||||
final MaterialData data = getBlockData(original);
|
||||
return new LegacyBlockItemStack(data, amount);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockItemStack clone(final BlockItemStack original, final int amount, final short durability) {
|
||||
final MaterialData data = getBlockData(original);
|
||||
data.setData((byte) durability);
|
||||
return new LegacyBlockItemStack(data, amount);
|
||||
}
|
||||
|
||||
private static MaterialData getBlockData(final BlockItemStack stack) {
|
||||
if (stack instanceof LegacyBlockItemStack) {
|
||||
return ((LegacyBlockItemStack)stack).materialData;
|
||||
}
|
||||
|
||||
return stack.getType().getNewData((byte) stack.getDurability());
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,103 @@
|
||||
package me.pikamug.quests.util.stack.impl;
|
||||
|
||||
import me.pikamug.quests.util.stack.BlockItemStack;
|
||||
import me.pikamug.quests.util.stack.BlockItemStackFactory;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.data.Ageable;
|
||||
import org.bukkit.block.data.BlockData;
|
||||
import org.bukkit.block.data.Powerable;
|
||||
|
||||
public class ModernBlockItemStack implements BlockItemStack {
|
||||
|
||||
public static final BlockItemStackFactory FACTORY = new Factory();
|
||||
|
||||
private final BlockData blockData;
|
||||
private int amount;
|
||||
private final short durability;
|
||||
|
||||
private ModernBlockItemStack(final BlockData blockData, final int amount, final short durability) {
|
||||
this.blockData = blockData;
|
||||
this.amount = amount;
|
||||
this.durability = durability;
|
||||
}
|
||||
|
||||
|
||||
private static short getDurability(BlockData data) {
|
||||
if (data instanceof Ageable) {
|
||||
return (short) ((Ageable)data).getAge();
|
||||
}
|
||||
|
||||
if (data instanceof Powerable) {
|
||||
return (short) (((Powerable)data).isPowered() ? 1 : 0);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
public BlockData getBlockData() {
|
||||
return blockData;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getAmount() {
|
||||
return amount;
|
||||
}
|
||||
|
||||
@Override
|
||||
public short getDurability() {
|
||||
return durability;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Material getType() {
|
||||
return blockData.getMaterial();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean matches(BlockItemStack other) {
|
||||
if (other == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
final BlockData blockData = Factory.getBlockData(other);
|
||||
return this.blockData.matches(blockData) && (durability == 0 || durability == other.getDurability());
|
||||
}
|
||||
|
||||
public void setAmount(int amount) {
|
||||
this.amount = amount;
|
||||
}
|
||||
|
||||
public static class Factory implements BlockItemStackFactory {
|
||||
|
||||
@Override
|
||||
public BlockItemStack of(final Block block) {
|
||||
return new ModernBlockItemStack(block.getBlockData(), 1, getDurability(block.getBlockData()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockItemStack of(final Material type, final int amount, final short durability) {
|
||||
return new ModernBlockItemStack(type.createBlockData(), amount, durability);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockItemStack clone(final BlockItemStack original, final int amount) {
|
||||
final BlockData data = getBlockData(original);
|
||||
return new ModernBlockItemStack(data, amount, original.getDurability());
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockItemStack clone(final BlockItemStack original, final int amount, final short durability) {
|
||||
final BlockData data = getBlockData(original);
|
||||
return new ModernBlockItemStack(data, amount, durability);
|
||||
}
|
||||
|
||||
private static BlockData getBlockData(final BlockItemStack stack) {
|
||||
if (stack instanceof ModernBlockItemStack) {
|
||||
return ((ModernBlockItemStack)stack).getBlockData();
|
||||
}
|
||||
|
||||
return stack.getType().createBlockData();
|
||||
}
|
||||
}
|
||||
}
|
@ -53,6 +53,7 @@ import me.pikamug.quests.tasks.BukkitNpcEffectThread;
|
||||
import me.pikamug.quests.tasks.BukkitPlayerMoveThread;
|
||||
import me.pikamug.quests.util.BukkitLang;
|
||||
import me.pikamug.quests.util.BukkitUpdateChecker;
|
||||
import me.pikamug.quests.util.stack.BlockItemStacks;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
@ -143,9 +144,11 @@ public class BukkitQuestsPlugin extends JavaPlugin implements Quests {
|
||||
try {
|
||||
Class.forName("me.pikamug.quests.libs.localelib.LocaleManager");
|
||||
localeManager = new LocaleManager();
|
||||
BlockItemStacks.init(!localeManager.isBelow113());
|
||||
} catch (final Exception ignored) {
|
||||
getLogger().warning("LocaleLib not present! Is this a debug environment?");
|
||||
}
|
||||
|
||||
convoListener = new BukkitConvoListener();
|
||||
blockListener = new BukkitBlockListener(this);
|
||||
itemListener = new BukkitItemListener(this);
|
||||
|
@ -22,7 +22,7 @@ import me.pikamug.quests.player.Quester;
|
||||
import me.pikamug.quests.quests.Quest;
|
||||
import me.pikamug.quests.quests.components.BukkitObjective;
|
||||
import me.pikamug.quests.quests.components.BukkitStage;
|
||||
import me.pikamug.quests.util.BukkitItemUtil;
|
||||
import me.pikamug.quests.util.stack.BlockItemStack;
|
||||
import me.pikamug.quests.util.BukkitLang;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Material;
|
||||
@ -61,10 +61,8 @@ public class BukkitBlockListener implements Listener {
|
||||
}
|
||||
final Player player = event.getPlayer();
|
||||
if (plugin.canUseQuests(player.getUniqueId())) {
|
||||
final ItemStack blockItemStack = getItemEquivalent(event.getBlock());
|
||||
if (blockItemStack == null) {
|
||||
return;
|
||||
}
|
||||
final BlockItemStack blockItem = BlockItemStack.of(event.getBlock());
|
||||
|
||||
final BukkitQuester quester = plugin.getQuester(player.getUniqueId());
|
||||
final ObjectiveType breakType = ObjectiveType.BREAK_BLOCK;
|
||||
final ObjectiveType placeType = ObjectiveType.PLACE_BLOCK;
|
||||
@ -89,12 +87,12 @@ public class BukkitBlockListener implements Listener {
|
||||
BukkitActionBarProvider.sendActionBar(player, ChatColor.RED + BukkitLang
|
||||
.get(player, "optionSilkTouchFail").replace("<quest>", quest.getName()));
|
||||
} else {
|
||||
quester.breakBlock(quest, blockItemStack);
|
||||
quester.breakBlock(quest, blockItem);
|
||||
|
||||
dispatchedBreakQuestIDs.addAll(quester.dispatchMultiplayerEverything(quest, breakType,
|
||||
(final Quester q, final Quest cq) -> {
|
||||
if (!dispatchedBreakQuestIDs.contains(cq.getId())) {
|
||||
q.breakBlock(cq, blockItemStack);
|
||||
q.breakBlock(cq, blockItem);
|
||||
}
|
||||
return null;
|
||||
}));
|
||||
@ -109,11 +107,11 @@ public class BukkitBlockListener implements Listener {
|
||||
if (progress < 0) {
|
||||
break;
|
||||
}
|
||||
final ItemStack is = currentStage.getBlocksToPlace().get(i);
|
||||
final BlockItemStack is = currentStage.getBlocksToPlace().get(i);
|
||||
if (event.getBlock().getType().equals(is.getType()) && is.getAmount() > 0) {
|
||||
ItemStack goal = new ItemStack(is.getType(), 64);
|
||||
for (final ItemStack stack : currentStage.getBlocksToPlace()) {
|
||||
if (BukkitItemUtil.compareItems(is, stack, true) == 0) {
|
||||
BlockItemStack goal = BlockItemStack.clone(is, 64);
|
||||
for (final BlockItemStack stack : currentStage.getBlocksToPlace()) {
|
||||
if (stack.matches(goal)) {
|
||||
goal = stack;
|
||||
}
|
||||
}
|
||||
@ -142,11 +140,11 @@ public class BukkitBlockListener implements Listener {
|
||||
if (progress < 0) {
|
||||
break;
|
||||
}
|
||||
final ItemStack is = currentStage.getBlocksToPlace().get(i);
|
||||
final BlockItemStack is = currentStage.getBlocksToPlace().get(i);
|
||||
if (event.getBlock().getType().equals(is.getType()) && is.getAmount() > 0) {
|
||||
ItemStack goal = new ItemStack(is.getType(), 64);
|
||||
for (final ItemStack stack : ((BukkitStage) quester.getCurrentStage(cq)).getBlocksToPlace()) {
|
||||
if (BukkitItemUtil.compareItems(is, stack, true) == 0) {
|
||||
BlockItemStack goal = BlockItemStack.clone(is, 64);
|
||||
for (final BlockItemStack stack : ((BukkitStage) quester.getCurrentStage(cq)).getBlocksToPlace()) {
|
||||
if (stack.matches(goal)) {
|
||||
goal = stack;
|
||||
}
|
||||
}
|
||||
@ -170,14 +168,14 @@ public class BukkitBlockListener implements Listener {
|
||||
}
|
||||
if (currentStage.containsObjective(cutType)) {
|
||||
if (player.getItemInHand().getType().equals(Material.SHEARS)) {
|
||||
quester.cutBlock(quest, blockItemStack);
|
||||
quester.cutBlock(quest, blockItem);
|
||||
}
|
||||
}
|
||||
dispatchedCutQuestIDs.addAll(quester.dispatchMultiplayerEverything(quest, cutType,
|
||||
(final Quester q, final Quest cq) -> {
|
||||
if (!dispatchedCutQuestIDs.contains(cq.getId())) {
|
||||
if (player.getItemInHand().getType().equals(Material.SHEARS)) {
|
||||
q.cutBlock(cq, blockItemStack);
|
||||
q.cutBlock(cq, blockItem);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
@ -195,10 +193,8 @@ public class BukkitBlockListener implements Listener {
|
||||
}
|
||||
final Player player = event.getPlayer();
|
||||
if (plugin.canUseQuests(player.getUniqueId())) {
|
||||
final ItemStack blockItemStack = getItemEquivalent(event.getBlock());
|
||||
if (blockItemStack == null) {
|
||||
return;
|
||||
}
|
||||
final BlockItemStack blockItemStack = BlockItemStack.of(event.getBlock());
|
||||
|
||||
final Quester quester = plugin.getQuester(player.getUniqueId());
|
||||
final ObjectiveType type = ObjectiveType.DAMAGE_BLOCK;
|
||||
final Set<String> dispatchedQuestIDs = new HashSet<>();
|
||||
@ -231,10 +227,8 @@ public class BukkitBlockListener implements Listener {
|
||||
}
|
||||
final Player player = event.getPlayer();
|
||||
if (plugin.canUseQuests(player.getUniqueId())) {
|
||||
final ItemStack blockItemStack = getItemEquivalent(event.getBlock());
|
||||
if (blockItemStack == null) {
|
||||
return;
|
||||
}
|
||||
final BlockItemStack blockItemStack = BlockItemStack.of(event.getBlock());
|
||||
|
||||
final BukkitQuester quester = plugin.getQuester(player.getUniqueId());
|
||||
final ObjectiveType placeType = ObjectiveType.PLACE_BLOCK;
|
||||
final ObjectiveType breakType = ObjectiveType.BREAK_BLOCK;
|
||||
@ -261,11 +255,11 @@ public class BukkitBlockListener implements Listener {
|
||||
if (progress < 0) {
|
||||
break;
|
||||
}
|
||||
final ItemStack is = currentStage.getBlocksToBreak().get(i);
|
||||
final BlockItemStack is = currentStage.getBlocksToBreak().get(i);
|
||||
if (event.getBlock().getType().equals(is.getType()) && is.getAmount() > 0) {
|
||||
ItemStack goal = new ItemStack(is.getType(), 64);
|
||||
for (final ItemStack stack : currentStage.getBlocksToBreak()) {
|
||||
if (BukkitItemUtil.compareItems(is, stack, true) == 0) {
|
||||
BlockItemStack goal = BlockItemStack.clone(is, 64);
|
||||
for (final BlockItemStack stack : currentStage.getBlocksToBreak()) {
|
||||
if (stack.matches(goal)) {
|
||||
goal = stack;
|
||||
}
|
||||
}
|
||||
@ -294,11 +288,11 @@ public class BukkitBlockListener implements Listener {
|
||||
if (progress < 0) {
|
||||
break;
|
||||
}
|
||||
final ItemStack is = currentStage.getBlocksToBreak().get(i);
|
||||
final BlockItemStack is = currentStage.getBlocksToBreak().get(i);
|
||||
if (event.getBlock().getType().equals(is.getType()) && is.getAmount() > 0) {
|
||||
ItemStack goal = new ItemStack(is.getType(), 64);
|
||||
for (final ItemStack stack : ((BukkitStage) quester.getCurrentStage(cq)).getBlocksToBreak()) {
|
||||
if (BukkitItemUtil.compareItems(is, stack, true) == 0) {
|
||||
BlockItemStack goal = BlockItemStack.clone(is, 64);
|
||||
for (final BlockItemStack stack : ((BukkitStage) quester.getCurrentStage(cq)).getBlocksToBreak()) {
|
||||
if (stack.matches(goal)) {
|
||||
goal = stack;
|
||||
}
|
||||
}
|
||||
@ -354,10 +348,8 @@ public class BukkitBlockListener implements Listener {
|
||||
}
|
||||
if (event.getAction().equals(Action.RIGHT_CLICK_BLOCK)) {
|
||||
if (!event.isCancelled() && event.getClickedBlock() != null) {
|
||||
final ItemStack blockItemStack = getItemEquivalent(event.getClickedBlock());
|
||||
if (blockItemStack == null) {
|
||||
return;
|
||||
}
|
||||
final BlockItemStack blockItemStack = BlockItemStack.of(event.getClickedBlock());
|
||||
|
||||
final ObjectiveType type = ObjectiveType.USE_BLOCK;
|
||||
final Set<String> dispatchedQuestIDs = new HashSet<>();
|
||||
for (final Quest quest : plugin.getLoadedQuests()) {
|
||||
|
@ -14,7 +14,6 @@ import com.alessiodp.parties.api.interfaces.Party;
|
||||
import com.alessiodp.parties.api.interfaces.PartyPlayer;
|
||||
import com.gmail.nossr50.datatypes.skills.SkillType;
|
||||
import com.gmail.nossr50.util.player.UserManager;
|
||||
import de.tr7zw.changeme.nbtapi.NBT;
|
||||
import io.github.znetworkw.znpcservers.npc.NPC;
|
||||
import lol.pyr.znpcsplus.api.npc.Npc;
|
||||
import me.clip.placeholderapi.PlaceholderAPI;
|
||||
@ -48,6 +47,7 @@ import me.pikamug.quests.quests.components.Objective;
|
||||
import me.pikamug.quests.quests.components.Planner;
|
||||
import me.pikamug.quests.quests.components.Stage;
|
||||
import me.pikamug.quests.tasks.BukkitStageTimer;
|
||||
import me.pikamug.quests.util.stack.BlockItemStack;
|
||||
import me.pikamug.quests.util.BukkitConfigUtil;
|
||||
import me.pikamug.quests.util.BukkitInventoryUtil;
|
||||
import me.pikamug.quests.util.BukkitItemUtil;
|
||||
@ -75,7 +75,6 @@ import org.bukkit.event.player.AsyncPlayerChatEvent;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.EnchantmentStorageMeta;
|
||||
import org.bukkit.material.Crops;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@ -1207,7 +1206,7 @@ public class BukkitQuester implements Quester {
|
||||
for (int i = 0; i < data.getBlocksBroken().size(); i++) {
|
||||
final int progress = data.getBlocksBroken().get(i);
|
||||
if (i >= stage.getBlocksToBreak().size()) { break; }
|
||||
final ItemStack goal = stage.getBlocksToBreak().get(i);
|
||||
final BlockItemStack goal = stage.getBlocksToBreak().get(i);
|
||||
final ChatColor color = progress < goal.getAmount() ? ChatColor.GREEN : ChatColor.GRAY;
|
||||
String message = formatCurrentObjectiveMessage(color, BukkitLang.get(getPlayer(), "break"),
|
||||
progress, goal.getAmount());
|
||||
@ -1219,7 +1218,7 @@ public class BukkitQuester implements Quester {
|
||||
for (int i = 0; i < data.getBlocksDamaged().size(); i++) {
|
||||
final int progress = data.getBlocksDamaged().get(i);
|
||||
if (i >= stage.getBlocksToDamage().size()) { break; }
|
||||
final ItemStack goal = stage.getBlocksToDamage().get(i);
|
||||
final BlockItemStack goal = stage.getBlocksToDamage().get(i);
|
||||
final ChatColor color = progress < goal.getAmount() ? ChatColor.GREEN : ChatColor.GRAY;
|
||||
String message = formatCurrentObjectiveMessage(color, BukkitLang.get(getPlayer(), "damage"),
|
||||
progress, goal.getAmount());
|
||||
@ -1231,7 +1230,7 @@ public class BukkitQuester implements Quester {
|
||||
for (int i = 0; i < data.getBlocksPlaced().size(); i++) {
|
||||
final int progress = data.getBlocksPlaced().get(i);
|
||||
if (i >= stage.getBlocksToPlace().size()) { break; }
|
||||
final ItemStack goal = stage.getBlocksToPlace().get(i);
|
||||
final BlockItemStack goal = stage.getBlocksToPlace().get(i);
|
||||
final ChatColor color = progress < goal.getAmount() ? ChatColor.GREEN : ChatColor.GRAY;
|
||||
String message = formatCurrentObjectiveMessage(color, BukkitLang.get(getPlayer(), "place"),
|
||||
progress, goal.getAmount());
|
||||
@ -1243,7 +1242,7 @@ public class BukkitQuester implements Quester {
|
||||
for (int i = 0; i < data.getBlocksUsed().size(); i++) {
|
||||
final int progress = data.getBlocksUsed().get(i);
|
||||
if (i >= stage.getBlocksToUse().size()) { break; }
|
||||
final ItemStack goal = stage.getBlocksToUse().get(i);
|
||||
final BlockItemStack goal = stage.getBlocksToUse().get(i);
|
||||
final ChatColor color = progress < goal.getAmount() ? ChatColor.GREEN : ChatColor.GRAY;
|
||||
String message = formatCurrentObjectiveMessage(color, BukkitLang.get(getPlayer(), "use"),
|
||||
progress, goal.getAmount());
|
||||
@ -1255,7 +1254,7 @@ public class BukkitQuester implements Quester {
|
||||
for (int i = 0; i < data.getBlocksCut().size(); i++) {
|
||||
final int progress = data.getBlocksCut().get(i);
|
||||
if (i >= stage.getBlocksToCut().size()) { break; }
|
||||
final ItemStack goal = stage.getBlocksToCut().get(i);
|
||||
final BlockItemStack goal = stage.getBlocksToCut().get(i);
|
||||
final ChatColor color = progress < goal.getAmount() ? ChatColor.GREEN : ChatColor.GRAY;
|
||||
String message = formatCurrentObjectiveMessage(color, BukkitLang.get(getPlayer(), "cut"),
|
||||
progress, goal.getAmount());
|
||||
@ -1601,7 +1600,16 @@ public class BukkitQuester implements Quester {
|
||||
final BukkitObjective objective = (BukkitObjective) obj;
|
||||
String message = "- " + BukkitLang.BukkitFormatToken.convertString(quester.getPlayer(),
|
||||
objective.getMessage());
|
||||
if (objective.getGoalAsItem() != null) {
|
||||
if (objective.getGoalAsBlockItem() != null) {
|
||||
final int progress = objective.getProgress();
|
||||
final BlockItemStack goal = objective.getGoalAsBlockItem();
|
||||
if (!settings.canShowCompletedObjs() && progress >= goal.getAmount()) {
|
||||
continue;
|
||||
}
|
||||
if (localeManager != null && settings.canTranslateNames()) {
|
||||
localeManager.sendMessage(quester.getPlayer(), message, goal.getType(), goal.getDurability(), null);
|
||||
}
|
||||
} else if (objective.getGoalAsItem() != null) {
|
||||
final int progress = objective.getProgress();
|
||||
final ItemStack goal = objective.getGoalAsItem();
|
||||
if (!settings.canShowCompletedObjs() && progress >= goal.getAmount()) {
|
||||
@ -1796,6 +1804,11 @@ public class BukkitQuester implements Quester {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void breakBlock(Quest quest, ItemStack itemStack) {
|
||||
breakBlock(quest, BlockItemStack.of(itemStack));
|
||||
}
|
||||
|
||||
/**
|
||||
* Marks block as broken if Quester has such an objective
|
||||
*
|
||||
@ -1803,12 +1816,19 @@ public class BukkitQuester implements Quester {
|
||||
* @param broken The block being broken
|
||||
*/
|
||||
@SuppressWarnings("deprecation")
|
||||
public void breakBlock(final Quest quest, final ItemStack broken) {
|
||||
ItemStack goal = null;
|
||||
for (final ItemStack toBreak : ((BukkitStage) getCurrentStage(quest)).getBlocksToBreak()) {
|
||||
public void breakBlock(final Quest quest, final BlockItemStack broken) {
|
||||
BlockItemStack goal = null;
|
||||
for (final BlockItemStack toBreak : ((BukkitStage) getCurrentStage(quest)).getBlocksToBreak()) {
|
||||
if (goal != null) {
|
||||
break;
|
||||
}
|
||||
|
||||
if (broken.matches(toBreak)) {
|
||||
goal = toBreak;
|
||||
} else {
|
||||
continue; // TODO
|
||||
}
|
||||
|
||||
if (broken.getType() == toBreak.getType()) {
|
||||
if (broken.getType().isSolid() && toBreak.getType().isSolid()) {
|
||||
// Blocks are solid so check for durability
|
||||
@ -1818,7 +1838,7 @@ public class BukkitQuester implements Quester {
|
||||
// Ignore durability for 1.13+
|
||||
goal = toBreak;
|
||||
}
|
||||
} else if (broken.getData() instanceof Crops && toBreak.getData() instanceof Crops) {
|
||||
} /*else if (broken.getBlockData() instanceof Ageable && toBreak.getBlockData() instanceof Ageable) {
|
||||
if (toBreak.getDurability() > 0) {
|
||||
// Age toBreak specified so check for durability
|
||||
if (broken.getDurability() == toBreak.getDurability()) {
|
||||
@ -1828,10 +1848,10 @@ public class BukkitQuester implements Quester {
|
||||
// Age toBreak unspecified so ignore durability
|
||||
goal = toBreak;
|
||||
}
|
||||
} else if (Material.getMaterial("CRAFTER") != null && broken.getType().isEdible()) {
|
||||
} */ else if (Material.getMaterial("CRAFTER") != null && broken.getType().isEdible()) {
|
||||
// Paper 1.21+ is special case
|
||||
final short toBreakAge = NBT.get(toBreak, nbt -> (short) nbt.getShort("quests_age"));
|
||||
final short brokenAge = NBT.get(broken, nbt -> (short) nbt.getShort("quests_age"));
|
||||
final short toBreakAge = /* NBT.get(toBreak, nbt -> (short) nbt.getShort("quests_age")); */ 0;
|
||||
final short brokenAge = broken.getDurability();
|
||||
if (toBreakAge > 0) {
|
||||
// Age toBreak specified so check for durability
|
||||
if (brokenAge == toBreakAge) {
|
||||
@ -1875,7 +1895,7 @@ public class BukkitQuester implements Quester {
|
||||
null, null, null, null);
|
||||
|
||||
// Multiplayer
|
||||
final ItemStack finalGoal = goal;
|
||||
final BlockItemStack finalGoal = goal;
|
||||
dispatchMultiplayerObjectives(quest, getCurrentStage(quest), (final Quester q) -> {
|
||||
((BukkitQuestProgress) q.getQuestProgressOrDefault(quest)).blocksBroken.set(breakIndex, progress);
|
||||
q.finishObjective(quest, new BukkitObjective(type, null, progress, finalGoal), null, null, null,
|
||||
@ -1889,6 +1909,11 @@ public class BukkitQuester implements Quester {
|
||||
plugin.getServer().getPluginManager().callEvent(postEvent);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void damageBlock(Quest quest, ItemStack itemStack) {
|
||||
damageBlock(quest, BlockItemStack.of(itemStack));
|
||||
}
|
||||
|
||||
/**
|
||||
* Marks block as damaged if Quester has such an objective
|
||||
*
|
||||
@ -1896,9 +1921,9 @@ public class BukkitQuester implements Quester {
|
||||
* @param damaged The block being damaged
|
||||
*/
|
||||
@SuppressWarnings("deprecation")
|
||||
public void damageBlock(final Quest quest, final ItemStack damaged) {
|
||||
ItemStack goal = null;
|
||||
for (final ItemStack toDamage : ((BukkitStage) getCurrentStage(quest)).getBlocksToDamage()) {
|
||||
public void damageBlock(final Quest quest, final BlockItemStack damaged) {
|
||||
BlockItemStack goal = null;
|
||||
for (final BlockItemStack toDamage : ((BukkitStage) getCurrentStage(quest)).getBlocksToDamage()) {
|
||||
if (goal != null) {
|
||||
break;
|
||||
}
|
||||
@ -1945,7 +1970,7 @@ public class BukkitQuester implements Quester {
|
||||
null, null, null, null);
|
||||
|
||||
// Multiplayer
|
||||
final ItemStack finalGoal = goal;
|
||||
final BlockItemStack finalGoal = goal;
|
||||
dispatchMultiplayerObjectives(quest, getCurrentStage(quest), (final Quester q) -> {
|
||||
((BukkitQuestProgress) q.getQuestProgressOrDefault(quest)).blocksDamaged.set(damageIndex, progress);
|
||||
q.finishObjective(quest, new BukkitObjective(type, null, progress, finalGoal), null, null, null,
|
||||
@ -1959,6 +1984,11 @@ public class BukkitQuester implements Quester {
|
||||
plugin.getServer().getPluginManager().callEvent(postEvent);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void placeBlock(Quest quest, ItemStack itemStack) {
|
||||
placeBlock(quest, BlockItemStack.of(itemStack));
|
||||
}
|
||||
|
||||
/**
|
||||
* Marks block as placed if Quester has such an objective
|
||||
*
|
||||
@ -1966,9 +1996,9 @@ public class BukkitQuester implements Quester {
|
||||
* @param placed The block being placed
|
||||
*/
|
||||
@SuppressWarnings("deprecation")
|
||||
public void placeBlock(final Quest quest, final ItemStack placed) {
|
||||
ItemStack goal = null;
|
||||
for (final ItemStack toPlace : ((BukkitStage) getCurrentStage(quest)).getBlocksToPlace()) {
|
||||
public void placeBlock(final Quest quest, final BlockItemStack placed) {
|
||||
BlockItemStack goal = null;
|
||||
for (final BlockItemStack toPlace : ((BukkitStage) getCurrentStage(quest)).getBlocksToPlace()) {
|
||||
if (goal != null) {
|
||||
break;
|
||||
}
|
||||
@ -2015,7 +2045,7 @@ public class BukkitQuester implements Quester {
|
||||
null, null, null, null);
|
||||
|
||||
// Multiplayer
|
||||
final ItemStack finalGoal = goal;
|
||||
final BlockItemStack finalGoal = goal;
|
||||
dispatchMultiplayerObjectives(quest, getCurrentStage(quest), (final Quester q) -> {
|
||||
((BukkitQuestProgress) q.getQuestProgressOrDefault(quest)).blocksPlaced.set(placeIndex, progress);
|
||||
q.finishObjective(quest, new BukkitObjective(type, null, progress, finalGoal), null, null, null,
|
||||
@ -2029,6 +2059,11 @@ public class BukkitQuester implements Quester {
|
||||
plugin.getServer().getPluginManager().callEvent(postEvent);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void useBlock(Quest quest, ItemStack itemStack) {
|
||||
useBlock(quest, BlockItemStack.of(itemStack));
|
||||
}
|
||||
|
||||
/**
|
||||
* Marks block as used if Quester has such an objective
|
||||
*
|
||||
@ -2036,9 +2071,9 @@ public class BukkitQuester implements Quester {
|
||||
* @param used The block being used
|
||||
*/
|
||||
@SuppressWarnings("deprecation")
|
||||
public void useBlock(final Quest quest, final ItemStack used) {
|
||||
ItemStack goal = null;
|
||||
for (final ItemStack toUse : ((BukkitStage) getCurrentStage(quest)).getBlocksToUse()) {
|
||||
public void useBlock(final Quest quest, final BlockItemStack used) {
|
||||
BlockItemStack goal = null;
|
||||
for (final BlockItemStack toUse : ((BukkitStage) getCurrentStage(quest)).getBlocksToUse()) {
|
||||
if (goal != null) {
|
||||
break;
|
||||
}
|
||||
@ -2085,7 +2120,7 @@ public class BukkitQuester implements Quester {
|
||||
null, null, null, null);
|
||||
|
||||
// Multiplayer
|
||||
final ItemStack finalGoal = goal;
|
||||
final BlockItemStack finalGoal = goal;
|
||||
dispatchMultiplayerObjectives(quest, getCurrentStage(quest), (final Quester q) -> {
|
||||
((BukkitQuestProgress) q.getQuestProgressOrDefault(quest)).blocksUsed.set(useIndex, progress);
|
||||
q.finishObjective(quest, new BukkitObjective(type, null, progress, finalGoal), null, null, null,
|
||||
@ -2099,6 +2134,11 @@ public class BukkitQuester implements Quester {
|
||||
plugin.getServer().getPluginManager().callEvent(postEvent);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void cutBlock(Quest quest, ItemStack itemStack) {
|
||||
cutBlock(quest, BlockItemStack.of(itemStack));
|
||||
}
|
||||
|
||||
/**
|
||||
* Marks block as cut if Quester has such an objective
|
||||
*
|
||||
@ -2106,9 +2146,9 @@ public class BukkitQuester implements Quester {
|
||||
* @param cut The block being cut
|
||||
*/
|
||||
@SuppressWarnings("deprecation")
|
||||
public void cutBlock(final Quest quest, final ItemStack cut) {
|
||||
ItemStack goal = null;
|
||||
for (final ItemStack toCut : ((BukkitStage) getCurrentStage(quest)).getBlocksToCut()) {
|
||||
public void cutBlock(final Quest quest, final BlockItemStack cut) {
|
||||
BlockItemStack goal = null;
|
||||
for (final BlockItemStack toCut : ((BukkitStage) getCurrentStage(quest)).getBlocksToCut()) {
|
||||
if (goal != null) {
|
||||
break;
|
||||
}
|
||||
@ -2155,7 +2195,7 @@ public class BukkitQuester implements Quester {
|
||||
null, null, null, null);
|
||||
|
||||
// Multiplayer
|
||||
final ItemStack finalGoal = goal;
|
||||
final BlockItemStack finalGoal = goal;
|
||||
dispatchMultiplayerObjectives(quest, getCurrentStage(quest), (final Quester q) -> {
|
||||
((BukkitQuestProgress) q.getQuestProgressOrDefault(quest)).blocksCut.set(cutIndex, progress);
|
||||
q.finishObjective(quest, new BukkitObjective(type, null, progress, finalGoal), null, null, null,
|
||||
@ -3146,6 +3186,10 @@ public class BukkitQuester implements Quester {
|
||||
final ObjectiveType type = objective.getType();
|
||||
final ItemStack goal = objective.getGoalObject() instanceof ItemStack ? (ItemStack) objective.getGoalObject()
|
||||
: new ItemStack(Material.AIR, objective.getGoal());
|
||||
final BlockItemStack goalBlock = objective.getGoalObject() instanceof BlockItemStack
|
||||
? (BlockItemStack) objective.getGoalObject()
|
||||
: BlockItemStack.of(Material.AIR, objective.getGoal(), (short) 0);
|
||||
|
||||
if (!getCurrentStage(quest).getObjectiveOverrides().isEmpty()) {
|
||||
for (final String s: getCurrentStage(quest).getObjectiveOverrides()) {
|
||||
String message = ChatColor.GREEN + "(" + BukkitLang.get(p, "completed") + ") "
|
||||
@ -3156,59 +3200,54 @@ public class BukkitQuester implements Quester {
|
||||
sendMessage(message);
|
||||
}
|
||||
} else if (type.equals(ObjectiveType.BREAK_BLOCK)) {
|
||||
final String message = formatCompletedObjectiveMessage("break", goal.getAmount());
|
||||
if (plugin.getConfigSettings().canTranslateNames() && !goal.hasItemMeta()
|
||||
&& !goal.getItemMeta().hasDisplayName()) {
|
||||
if (!plugin.getLocaleManager().sendMessage(p, message, goal.getType(), goal.getDurability(),
|
||||
null)) {
|
||||
sendMessage(message.replace("<item>", BukkitItemUtil.getName(goal)));
|
||||
final String message = formatCompletedObjectiveMessage("break", goalBlock.getAmount());
|
||||
if (plugin.getConfigSettings().canTranslateNames()) {
|
||||
if (!plugin.getLocaleManager().sendMessage(p, message,
|
||||
goalBlock.getType(), goalBlock.getDurability(), null)) {
|
||||
sendMessage(message.replace("<item>", BukkitItemUtil.getName(goalBlock)));
|
||||
}
|
||||
} else {
|
||||
sendMessage(message.replace("<item>", BukkitItemUtil.getName(goal)));
|
||||
sendMessage(message.replace("<item>", BukkitItemUtil.getName(goalBlock)));
|
||||
}
|
||||
} else if (type.equals(ObjectiveType.DAMAGE_BLOCK)) {
|
||||
final String message = formatCompletedObjectiveMessage("damage", goal.getAmount());
|
||||
if (plugin.getConfigSettings().canTranslateNames() && !goal.hasItemMeta()
|
||||
&& !goal.getItemMeta().hasDisplayName()) {
|
||||
if (!plugin.getLocaleManager().sendMessage(p, message, goal.getType(), goal.getDurability(),
|
||||
null)) {
|
||||
sendMessage(message.replace("<item>", BukkitItemUtil.getName(goal)));
|
||||
final String message = formatCompletedObjectiveMessage("damage", goalBlock.getAmount());
|
||||
if (plugin.getConfigSettings().canTranslateNames()) {
|
||||
if (!plugin.getLocaleManager().sendMessage(p, message,
|
||||
goalBlock.getType(), goalBlock.getDurability(), null)) {
|
||||
sendMessage(message.replace("<item>", BukkitItemUtil.getName(goalBlock)));
|
||||
}
|
||||
} else {
|
||||
sendMessage(message.replace("<item>", BukkitItemUtil.getName(goal)));
|
||||
sendMessage(message.replace("<item>", BukkitItemUtil.getName(goalBlock)));
|
||||
}
|
||||
} else if (type.equals(ObjectiveType.PLACE_BLOCK)) {
|
||||
final String message = formatCompletedObjectiveMessage("place", goal.getAmount());
|
||||
if (plugin.getConfigSettings().canTranslateNames() && !goal.hasItemMeta()
|
||||
&& !goal.getItemMeta().hasDisplayName()) {
|
||||
if (!plugin.getLocaleManager().sendMessage(p, message, goal.getType(), goal.getDurability(),
|
||||
null)) {
|
||||
sendMessage(message.replace("<item>", BukkitItemUtil.getName(goal)));
|
||||
final String message = formatCompletedObjectiveMessage("place", goalBlock.getAmount());
|
||||
if (plugin.getConfigSettings().canTranslateNames()) {
|
||||
if (!plugin.getLocaleManager().sendMessage(p, message,
|
||||
goalBlock.getType(), goalBlock.getDurability(), null)) {
|
||||
sendMessage(message.replace("<item>", BukkitItemUtil.getName(goalBlock)));
|
||||
}
|
||||
} else {
|
||||
sendMessage(message.replace("<item>", BukkitItemUtil.getName(goal)));
|
||||
sendMessage(message.replace("<item>", BukkitItemUtil.getName(goalBlock)));
|
||||
}
|
||||
} else if (type.equals(ObjectiveType.USE_BLOCK)) {
|
||||
final String message = formatCompletedObjectiveMessage("use", goal.getAmount());
|
||||
if (plugin.getConfigSettings().canTranslateNames() && !goal.hasItemMeta()
|
||||
&& !goal.getItemMeta().hasDisplayName()) {
|
||||
if (!plugin.getLocaleManager().sendMessage(p, message, goal.getType(), goal.getDurability(),
|
||||
null)) {
|
||||
sendMessage(message.replace("<item>", BukkitItemUtil.getName(goal)));
|
||||
if (plugin.getConfigSettings().canTranslateNames()) {
|
||||
if (!plugin.getLocaleManager().sendMessage(p, message,
|
||||
goalBlock.getType(), goalBlock.getDurability(), null)) {
|
||||
sendMessage(message.replace("<item>", BukkitItemUtil.getName(goalBlock)));
|
||||
}
|
||||
} else {
|
||||
sendMessage(message.replace("<item>", BukkitItemUtil.getName(goal)));
|
||||
sendMessage(message.replace("<item>", BukkitItemUtil.getName(goalBlock)));
|
||||
}
|
||||
} else if (type.equals(ObjectiveType.CUT_BLOCK)) {
|
||||
final String message = formatCompletedObjectiveMessage("cut", goal.getAmount());
|
||||
if (plugin.getConfigSettings().canTranslateNames() && !goal.hasItemMeta()
|
||||
&& !goal.getItemMeta().hasDisplayName()) {
|
||||
if (!plugin.getLocaleManager().sendMessage(p, message, goal.getType(), goal.getDurability(),
|
||||
null)) {
|
||||
sendMessage(message.replace("<item>", BukkitItemUtil.getName(goal)));
|
||||
if (plugin.getConfigSettings().canTranslateNames()) {
|
||||
if (!plugin.getLocaleManager().sendMessage(p, message,
|
||||
goalBlock.getType(), goalBlock.getDurability(), null)) {
|
||||
sendMessage(message.replace("<item>", BukkitItemUtil.getName(goalBlock)));
|
||||
}
|
||||
} else {
|
||||
sendMessage(message.replace("<item>", BukkitItemUtil.getName(goal)));
|
||||
sendMessage(message.replace("<item>", BukkitItemUtil.getName(goalBlock)));
|
||||
}
|
||||
} else if (type.equals(ObjectiveType.CRAFT_ITEM)) {
|
||||
final ItemStack is = ((BukkitStage) getCurrentStage(quest)).getItemsToCraft().get(getCurrentStage(quest)
|
||||
@ -3464,27 +3503,27 @@ public class BukkitQuester implements Quester {
|
||||
}
|
||||
final BukkitStage bukkitStage = (BukkitStage) quest.getStage(stage);
|
||||
if (!bukkitStage.getBlocksToBreak().isEmpty()) {
|
||||
for (final ItemStack ignored : bukkitStage.getBlocksToBreak()) {
|
||||
for (final BlockItemStack ignored : bukkitStage.getBlocksToBreak()) {
|
||||
data.blocksBroken.add(0);
|
||||
}
|
||||
}
|
||||
if (!bukkitStage.getBlocksToDamage().isEmpty()) {
|
||||
for (final ItemStack ignored : bukkitStage.getBlocksToDamage()) {
|
||||
for (final BlockItemStack ignored : bukkitStage.getBlocksToDamage()) {
|
||||
data.blocksDamaged.add(0);
|
||||
}
|
||||
}
|
||||
if (!bukkitStage.getBlocksToPlace().isEmpty()) {
|
||||
for (final ItemStack ignored : bukkitStage.getBlocksToPlace()) {
|
||||
for (final BlockItemStack ignored : bukkitStage.getBlocksToPlace()) {
|
||||
data.blocksPlaced.add(0);
|
||||
}
|
||||
}
|
||||
if (!bukkitStage.getBlocksToUse().isEmpty()) {
|
||||
for (final ItemStack ignored : bukkitStage.getBlocksToUse()) {
|
||||
for (final BlockItemStack ignored : bukkitStage.getBlocksToUse()) {
|
||||
data.blocksUsed.add(0);
|
||||
}
|
||||
}
|
||||
if (!bukkitStage.getBlocksToCut().isEmpty()) {
|
||||
for (final ItemStack ignored : bukkitStage.getBlocksToCut()) {
|
||||
for (final BlockItemStack ignored : bukkitStage.getBlocksToCut()) {
|
||||
data.blocksCut.add(0);
|
||||
}
|
||||
}
|
||||
|
@ -22,6 +22,7 @@ import me.pikamug.quests.quests.components.Planner;
|
||||
import me.pikamug.quests.quests.components.Requirements;
|
||||
import me.pikamug.quests.quests.components.Rewards;
|
||||
import me.pikamug.quests.quests.components.Stage;
|
||||
import me.pikamug.quests.util.stack.BlockItemStack;
|
||||
import me.pikamug.quests.util.BukkitConfigUtil;
|
||||
import me.pikamug.quests.util.BukkitFakeConversable;
|
||||
import me.pikamug.quests.util.BukkitLang;
|
||||
@ -303,7 +304,7 @@ public class BukkitQuestFactory implements QuestFactory, ConversationAbandonedLi
|
||||
final LinkedList<String> names = new LinkedList<>();
|
||||
final LinkedList<Integer> amounts = new LinkedList<>();
|
||||
final LinkedList<Short> durability = new LinkedList<>();
|
||||
for (final ItemStack e : bukkitStage.getBlocksToBreak()) {
|
||||
for (final BlockItemStack e : bukkitStage.getBlocksToBreak()) {
|
||||
names.add(e.getType().name());
|
||||
amounts.add(e.getAmount());
|
||||
durability.add(e.getDurability());
|
||||
@ -316,7 +317,7 @@ public class BukkitQuestFactory implements QuestFactory, ConversationAbandonedLi
|
||||
final LinkedList<String> names = new LinkedList<>();
|
||||
final LinkedList<Integer> amounts = new LinkedList<>();
|
||||
final LinkedList<Short> durability = new LinkedList<>();
|
||||
for (final ItemStack e : bukkitStage.getBlocksToDamage()) {
|
||||
for (final BlockItemStack e : bukkitStage.getBlocksToDamage()) {
|
||||
names.add(e.getType().name());
|
||||
amounts.add(e.getAmount());
|
||||
durability.add(e.getDurability());
|
||||
@ -329,7 +330,7 @@ public class BukkitQuestFactory implements QuestFactory, ConversationAbandonedLi
|
||||
final LinkedList<String> names = new LinkedList<>();
|
||||
final LinkedList<Integer> amounts = new LinkedList<>();
|
||||
final LinkedList<Short> durability = new LinkedList<>();
|
||||
for (final ItemStack e : bukkitStage.getBlocksToPlace()) {
|
||||
for (final BlockItemStack e : bukkitStage.getBlocksToPlace()) {
|
||||
names.add(e.getType().name());
|
||||
amounts.add(e.getAmount());
|
||||
durability.add(e.getDurability());
|
||||
@ -342,7 +343,7 @@ public class BukkitQuestFactory implements QuestFactory, ConversationAbandonedLi
|
||||
final LinkedList<String> names = new LinkedList<>();
|
||||
final LinkedList<Integer> amounts = new LinkedList<>();
|
||||
final LinkedList<Short> durability = new LinkedList<>();
|
||||
for (final ItemStack e : bukkitStage.getBlocksToUse()) {
|
||||
for (final BlockItemStack e : bukkitStage.getBlocksToUse()) {
|
||||
names.add(e.getType().name());
|
||||
amounts.add(e.getAmount());
|
||||
durability.add(e.getDurability());
|
||||
@ -355,7 +356,7 @@ public class BukkitQuestFactory implements QuestFactory, ConversationAbandonedLi
|
||||
final LinkedList<String> names = new LinkedList<>();
|
||||
final LinkedList<Integer> amounts = new LinkedList<>();
|
||||
final LinkedList<Short> durability = new LinkedList<>();
|
||||
for (final ItemStack e : bukkitStage.getBlocksToCut()) {
|
||||
for (final BlockItemStack e : bukkitStage.getBlocksToCut()) {
|
||||
names.add(e.getType().name());
|
||||
amounts.add(e.getAmount());
|
||||
durability.add(e.getDurability());
|
||||
|
@ -12,6 +12,7 @@ package me.pikamug.quests.quests.components;
|
||||
|
||||
import me.pikamug.quests.entity.BukkitCountableMob;
|
||||
import me.pikamug.quests.enums.ObjectiveType;
|
||||
import me.pikamug.quests.util.stack.BlockItemStack;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
@ -46,6 +47,8 @@ public class BukkitObjective implements Objective {
|
||||
this.progress = ((BukkitCountableMob) progressObj).getCount();
|
||||
} else if (progressObj instanceof Integer) {
|
||||
this.progress = (int) progress;
|
||||
} else if (progressObj instanceof BlockItemStack) {
|
||||
this.progress = ((BlockItemStack) progressObj).getAmount();
|
||||
} else {
|
||||
this.progress = 0;
|
||||
}
|
||||
@ -55,6 +58,8 @@ public class BukkitObjective implements Objective {
|
||||
this.goal = ((BukkitCountableMob) goalObj).getCount();
|
||||
} else if (goalObj instanceof Integer) {
|
||||
this.goal = (int) goalObj;
|
||||
} else if (progressObj instanceof BlockItemStack) {
|
||||
this.goal = ((BlockItemStack) progressObj).getAmount();
|
||||
} else {
|
||||
this.goal = 0;
|
||||
}
|
||||
@ -90,6 +95,10 @@ public class BukkitObjective implements Objective {
|
||||
return goalObj;
|
||||
}
|
||||
|
||||
public @Nullable BlockItemStack getGoalAsBlockItem() {
|
||||
return goalObj instanceof BlockItemStack ? (BlockItemStack) goalObj : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated Paper 1.21 builds do not allow ItemStack with 0 amount
|
||||
*/
|
||||
|
@ -14,7 +14,7 @@ import me.pikamug.quests.actions.Action;
|
||||
import me.pikamug.quests.conditions.Condition;
|
||||
import me.pikamug.quests.enums.ObjectiveType;
|
||||
import me.pikamug.quests.module.CustomObjective;
|
||||
import me.pikamug.quests.quests.components.Stage;
|
||||
import me.pikamug.quests.util.stack.BlockItemStack;
|
||||
import org.bukkit.DyeColor;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
@ -30,11 +30,11 @@ import java.util.UUID;
|
||||
|
||||
public class BukkitStage implements Stage {
|
||||
|
||||
private LinkedList<ItemStack> blocksToBreak = new LinkedList<>();
|
||||
private LinkedList<ItemStack> blocksToDamage = new LinkedList<>();
|
||||
private LinkedList<ItemStack> blocksToPlace = new LinkedList<>();
|
||||
private LinkedList<ItemStack> blocksToUse = new LinkedList<>();
|
||||
private LinkedList<ItemStack> blocksToCut = new LinkedList<>();
|
||||
private LinkedList<BlockItemStack> blocksToBreak = new LinkedList<>();
|
||||
private LinkedList<BlockItemStack> blocksToDamage = new LinkedList<>();
|
||||
private LinkedList<BlockItemStack> blocksToPlace = new LinkedList<>();
|
||||
private LinkedList<BlockItemStack> blocksToUse = new LinkedList<>();
|
||||
private LinkedList<BlockItemStack> blocksToCut = new LinkedList<>();
|
||||
private LinkedList<ItemStack> itemsToCraft = new LinkedList<>();
|
||||
private LinkedList<ItemStack> itemsToSmelt = new LinkedList<>();
|
||||
private LinkedList<ItemStack> itemsToEnchant = new LinkedList<>();
|
||||
@ -137,63 +137,63 @@ public class BukkitStage implements Stage {
|
||||
private final LinkedList<String> customObjectiveDisplays = new LinkedList<>();
|
||||
private final LinkedList<Entry<String, Object>> customObjectiveData = new LinkedList<>();
|
||||
|
||||
public LinkedList<ItemStack> getBlocksToBreak() {
|
||||
public LinkedList<BlockItemStack> getBlocksToBreak() {
|
||||
return blocksToBreak;
|
||||
}
|
||||
|
||||
public boolean addBlockToBreak(@NotNull ItemStack blockToBreak) {
|
||||
public boolean addBlockToBreak(@NotNull BlockItemStack blockToBreak) {
|
||||
return blocksToBreak.add(blockToBreak);
|
||||
}
|
||||
|
||||
public void setBlocksToBreak(final LinkedList<ItemStack> blocksToBreak) {
|
||||
public void setBlocksToBreak(final LinkedList<BlockItemStack> blocksToBreak) {
|
||||
this.blocksToBreak = blocksToBreak;
|
||||
}
|
||||
|
||||
public LinkedList<ItemStack> getBlocksToDamage() {
|
||||
public LinkedList<BlockItemStack> getBlocksToDamage() {
|
||||
return blocksToDamage;
|
||||
}
|
||||
|
||||
public boolean addBlockToDamage(@NotNull ItemStack blockToDamage) {
|
||||
public boolean addBlockToDamage(@NotNull BlockItemStack blockToDamage) {
|
||||
return blocksToDamage.add(blockToDamage);
|
||||
}
|
||||
|
||||
public void setBlocksToDamage(final LinkedList<ItemStack> blocksToDamage) {
|
||||
public void setBlocksToDamage(final LinkedList<BlockItemStack> blocksToDamage) {
|
||||
this.blocksToDamage = blocksToDamage;
|
||||
}
|
||||
|
||||
public LinkedList<ItemStack> getBlocksToPlace() {
|
||||
public LinkedList<BlockItemStack> getBlocksToPlace() {
|
||||
return blocksToPlace;
|
||||
}
|
||||
|
||||
public boolean addBlockToPlace(@NotNull ItemStack blockToPlace) {
|
||||
public boolean addBlockToPlace(@NotNull BlockItemStack blockToPlace) {
|
||||
return blocksToPlace.add(blockToPlace);
|
||||
}
|
||||
|
||||
public void setBlocksToPlace(final LinkedList<ItemStack> blocksToPlace) {
|
||||
public void setBlocksToPlace(final LinkedList<BlockItemStack> blocksToPlace) {
|
||||
this.blocksToPlace = blocksToPlace;
|
||||
}
|
||||
|
||||
public LinkedList<ItemStack> getBlocksToUse() {
|
||||
public LinkedList<BlockItemStack> getBlocksToUse() {
|
||||
return blocksToUse;
|
||||
}
|
||||
|
||||
public boolean addBlockToUse(@NotNull ItemStack blockToUse) {
|
||||
public boolean addBlockToUse(@NotNull BlockItemStack blockToUse) {
|
||||
return blocksToUse.add(blockToUse);
|
||||
}
|
||||
|
||||
public void setBlocksToUse(final LinkedList<ItemStack> blocksToUse) {
|
||||
public void setBlocksToUse(final LinkedList<BlockItemStack> blocksToUse) {
|
||||
this.blocksToUse = blocksToUse;
|
||||
}
|
||||
|
||||
public LinkedList<ItemStack> getBlocksToCut() {
|
||||
public LinkedList<BlockItemStack> getBlocksToCut() {
|
||||
return blocksToCut;
|
||||
}
|
||||
|
||||
public boolean addBlockToCut(@NotNull ItemStack blockToCut) {
|
||||
public boolean addBlockToCut(@NotNull BlockItemStack blockToCut) {
|
||||
return blocksToCut.add(blockToCut);
|
||||
}
|
||||
|
||||
public void setBlocksToCut(final LinkedList<ItemStack> blocksToCut) {
|
||||
public void setBlocksToCut(final LinkedList<BlockItemStack> blocksToCut) {
|
||||
this.blocksToCut = blocksToCut;
|
||||
}
|
||||
|
||||
|
@ -16,6 +16,7 @@ import me.pikamug.quests.quests.components.BukkitStage;
|
||||
import me.pikamug.quests.quests.components.Options;
|
||||
import me.pikamug.quests.quests.components.Planner;
|
||||
import me.pikamug.quests.storage.implementation.QuestStorageImpl;
|
||||
import me.pikamug.quests.util.stack.BlockItemStack;
|
||||
import me.pikamug.quests.util.BukkitConfigUtil;
|
||||
import me.pikamug.quests.util.BukkitItemUtil;
|
||||
import me.pikamug.quests.util.BukkitMiscUtil;
|
||||
@ -877,12 +878,12 @@ public class BukkitQuestYamlStorage implements QuestStorageImpl {
|
||||
}
|
||||
for (int i = 0; i < breakNames.size(); i++) {
|
||||
final String name = breakNames.get(i);
|
||||
final ItemStack is;
|
||||
final BlockItemStack is;
|
||||
if (i < breakDurability.size() && breakDurability.get(i) != -1) {
|
||||
is = BukkitItemUtil.processItemStack(name, breakAmounts.get(i), breakDurability.get(i));
|
||||
is = BukkitItemUtil.processBlockItemStack(name, breakAmounts.get(i), breakDurability.get(i));
|
||||
} else {
|
||||
// Legacy
|
||||
is = BukkitItemUtil.processItemStack(name, breakAmounts.get(i), (short) 0);
|
||||
is = BukkitItemUtil.processBlockItemStack(name, breakAmounts.get(i), (short) 0);
|
||||
}
|
||||
if (is != null && Material.matchMaterial(name) != null) {
|
||||
bukkitStage.addBlockToBreak(is);
|
||||
@ -919,12 +920,12 @@ public class BukkitQuestYamlStorage implements QuestStorageImpl {
|
||||
}
|
||||
for (int i = 0; i < damageNames.size(); i++) {
|
||||
final String name = damageNames.get(i);
|
||||
final ItemStack is;
|
||||
final BlockItemStack is;
|
||||
if (i < damageDurability.size() && damageDurability.get(i) != -1) {
|
||||
is = BukkitItemUtil.processItemStack(name, damageAmounts.get(i), damageDurability.get(i));
|
||||
is = BukkitItemUtil.processBlockItemStack(name, damageAmounts.get(i), damageDurability.get(i));
|
||||
} else {
|
||||
// Legacy
|
||||
is = BukkitItemUtil.processItemStack(name, damageAmounts.get(i), (short) 0);
|
||||
is = BukkitItemUtil.processBlockItemStack(name, damageAmounts.get(i), (short) 0);
|
||||
}
|
||||
if (is != null && Material.matchMaterial(name) != null) {
|
||||
bukkitStage.addBlockToDamage(is);
|
||||
@ -960,12 +961,12 @@ public class BukkitQuestYamlStorage implements QuestStorageImpl {
|
||||
}
|
||||
for (int i = 0; i < placeNames.size(); i++) {
|
||||
final String name = placeNames.get(i);
|
||||
final ItemStack is;
|
||||
final BlockItemStack is;
|
||||
if (i < placeDurability.size() && placeDurability.get(i) != -1) {
|
||||
is = BukkitItemUtil.processItemStack(name, placeAmounts.get(i), placeDurability.get(i));
|
||||
is = BukkitItemUtil.processBlockItemStack(name, placeAmounts.get(i), placeDurability.get(i));
|
||||
} else {
|
||||
// Legacy
|
||||
is = BukkitItemUtil.processItemStack(name, placeAmounts.get(i), (short) 0);
|
||||
is = BukkitItemUtil.processBlockItemStack(name, placeAmounts.get(i), (short) 0);
|
||||
}
|
||||
if (is != null && Material.matchMaterial(name) != null) {
|
||||
bukkitStage.addBlockToPlace(is);
|
||||
@ -1001,12 +1002,12 @@ public class BukkitQuestYamlStorage implements QuestStorageImpl {
|
||||
}
|
||||
for (int i = 0; i < useNames.size(); i++) {
|
||||
final String name = useNames.get(i);
|
||||
final ItemStack is;
|
||||
final BlockItemStack is;
|
||||
if (i < useDurability.size() && useDurability.get(i) != -1) {
|
||||
is = BukkitItemUtil.processItemStack(name, useAmounts.get(i), useDurability.get(i));
|
||||
is = BukkitItemUtil.processBlockItemStack(name, useAmounts.get(i), useDurability.get(i));
|
||||
} else {
|
||||
// Legacy
|
||||
is = BukkitItemUtil.processItemStack(name, useAmounts.get(i), (short) 0);
|
||||
is = BukkitItemUtil.processBlockItemStack(name, useAmounts.get(i), (short) 0);
|
||||
}
|
||||
if (is != null && Material.matchMaterial(name) != null) {
|
||||
bukkitStage.addBlockToUse(is);
|
||||
@ -1042,12 +1043,12 @@ public class BukkitQuestYamlStorage implements QuestStorageImpl {
|
||||
}
|
||||
for (int i = 0; i < cutNames.size(); i++) {
|
||||
final String name = cutNames.get(i);
|
||||
final ItemStack is;
|
||||
final BlockItemStack is;
|
||||
if (i < cutDurability.size() && cutDurability.get(i) != -1) {
|
||||
is = BukkitItemUtil.processItemStack(name, cutAmounts.get(i), cutDurability.get(i));
|
||||
is = BukkitItemUtil.processBlockItemStack(name, cutAmounts.get(i), cutDurability.get(i));
|
||||
} else {
|
||||
// Legacy
|
||||
is = BukkitItemUtil.processItemStack(name, cutAmounts.get(i), (short) 0);
|
||||
is = BukkitItemUtil.processBlockItemStack(name, cutAmounts.get(i), (short) 0);
|
||||
}
|
||||
if (is != null && Material.matchMaterial(name) != null) {
|
||||
bukkitStage.addBlockToCut(is);
|
||||
|
@ -11,6 +11,7 @@
|
||||
package me.pikamug.quests.util;
|
||||
|
||||
import de.tr7zw.changeme.nbtapi.NBT;
|
||||
import me.pikamug.quests.util.stack.BlockItemStack;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Color;
|
||||
@ -257,6 +258,34 @@ public class BukkitItemUtil {
|
||||
}
|
||||
}
|
||||
|
||||
public static BlockItemStack processBlockItemStack(final String material, final int amount, final short durability) {
|
||||
if (material == null) {
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
Material mat = Material.getMaterial(material.toUpperCase());
|
||||
if (mat == null) {
|
||||
return null;
|
||||
}
|
||||
return BlockItemStack.of(mat, amount, durability);
|
||||
} catch (final Exception e) {
|
||||
try {
|
||||
Bukkit.getLogger().warning(material + " x " + amount
|
||||
+ " is invalid! You may need to update your quests.yml or actions.yml "
|
||||
+ "in accordance with https://bit.ly/2BkBNNN");
|
||||
final Material mat = Material.matchMaterial(material, true);
|
||||
if (mat == null) {
|
||||
return null;
|
||||
}
|
||||
return BlockItemStack.of(mat, amount, durability);
|
||||
} catch (final Exception e2) {
|
||||
Bukkit.getLogger().severe("Unable to use LEGACY_" + material + " as item name");
|
||||
e2.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get ItemStack from formatted string. See #serializeItemStack for reverse function.
|
||||
*
|
||||
@ -623,6 +652,19 @@ public class BukkitItemUtil {
|
||||
return text;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a formatted display name. If none exists, returns item name.
|
||||
*
|
||||
* @param itemStack BlockItemStack to check
|
||||
* @return true display or item name, if stack is not null
|
||||
*/
|
||||
public static String getName(final BlockItemStack itemStack) {
|
||||
if (itemStack == null) {
|
||||
return null;
|
||||
}
|
||||
return ChatColor.AQUA + getPrettyItemName(itemStack.getType().name());
|
||||
}
|
||||
|
||||
/**
|
||||
* Ensures that an ItemStack is a valid, non-AIR material
|
||||
*
|
||||
|
Loading…
Reference in New Issue
Block a user