mirror of
https://github.com/PikaMug/Quests.git
synced 2024-11-22 02:25:42 +01:00
Track progress through int, part 1. See #2246
This commit is contained in:
parent
8f89eb9d8c
commit
e24b364297
@ -40,6 +40,7 @@ import org.bukkit.inventory.EquipmentSlot;
|
|||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
|
import java.util.LinkedList;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
public class BukkitBlockListener implements Listener {
|
public class BukkitBlockListener implements Listener {
|
||||||
@ -103,16 +104,16 @@ public class BukkitBlockListener implements Listener {
|
|||||||
if (currentStage.containsObjective(placeType)) {
|
if (currentStage.containsObjective(placeType)) {
|
||||||
for (final ItemStack is : questData.blocksPlaced) {
|
for (final ItemStack is : questData.blocksPlaced) {
|
||||||
if (event.getBlock().getType().equals(is.getType()) && is.getAmount() > 0) {
|
if (event.getBlock().getType().equals(is.getType()) && is.getAmount() > 0) {
|
||||||
ItemStack toPlace = new ItemStack(is.getType(), 64);
|
ItemStack goal = new ItemStack(is.getType(), 64);
|
||||||
for (final ItemStack stack : currentStage.getBlocksToPlace()) {
|
for (final ItemStack stack : currentStage.getBlocksToPlace()) {
|
||||||
if (BukkitItemUtil.compareItems(is, stack, true) == 0) {
|
if (BukkitItemUtil.compareItems(is, stack, true) == 0) {
|
||||||
toPlace = stack;
|
goal = stack;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
final BukkitQuesterPreUpdateObjectiveEvent preEvent
|
final BukkitQuesterPreUpdateObjectiveEvent preEvent
|
||||||
= new BukkitQuesterPreUpdateObjectiveEvent(quester, quest,
|
= new BukkitQuesterPreUpdateObjectiveEvent(quester, quest,
|
||||||
new BukkitObjective(placeType, null, is.getAmount(), toPlace.getAmount()));
|
new BukkitObjective(placeType, null, is.getAmount(), goal.getAmount()));
|
||||||
plugin.getServer().getPluginManager().callEvent(preEvent);
|
plugin.getServer().getPluginManager().callEvent(preEvent);
|
||||||
|
|
||||||
final int index = questData.blocksPlaced.indexOf(is);
|
final int index = questData.blocksPlaced.indexOf(is);
|
||||||
@ -122,7 +123,7 @@ public class BukkitBlockListener implements Listener {
|
|||||||
|
|
||||||
final BukkitQuesterPostUpdateObjectiveEvent postEvent
|
final BukkitQuesterPostUpdateObjectiveEvent postEvent
|
||||||
= new BukkitQuesterPostUpdateObjectiveEvent(quester, quest,
|
= new BukkitQuesterPostUpdateObjectiveEvent(quester, quest,
|
||||||
new BukkitObjective(placeType, null, newAmount, toPlace.getAmount()));
|
new BukkitObjective(placeType, null, newAmount, goal.getAmount()));
|
||||||
plugin.getServer().getPluginManager().callEvent(postEvent);
|
plugin.getServer().getPluginManager().callEvent(postEvent);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -134,16 +135,16 @@ public class BukkitBlockListener implements Listener {
|
|||||||
final BukkitQuestProgress qQuestData = (BukkitQuestProgress) q.getQuestDataOrDefault(cq);
|
final BukkitQuestProgress qQuestData = (BukkitQuestProgress) q.getQuestDataOrDefault(cq);
|
||||||
for (final ItemStack is : qQuestData.blocksPlaced) {
|
for (final ItemStack is : qQuestData.blocksPlaced) {
|
||||||
if (event.getBlock().getType().equals(is.getType()) && is.getAmount() > 0) {
|
if (event.getBlock().getType().equals(is.getType()) && is.getAmount() > 0) {
|
||||||
ItemStack toPlace = new ItemStack(is.getType(), 64);
|
ItemStack goal = new ItemStack(is.getType(), 64);
|
||||||
for (final ItemStack stack : ((BukkitStage) quester.getCurrentStage(cq)).getBlocksToPlace()) {
|
for (final ItemStack stack : ((BukkitStage) quester.getCurrentStage(cq)).getBlocksToPlace()) {
|
||||||
if (BukkitItemUtil.compareItems(is, stack, true) == 0) {
|
if (BukkitItemUtil.compareItems(is, stack, true) == 0) {
|
||||||
toPlace = stack;
|
goal = stack;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
final BukkitQuesterPreUpdateObjectiveEvent preEvent
|
final BukkitQuesterPreUpdateObjectiveEvent preEvent
|
||||||
= new BukkitQuesterPreUpdateObjectiveEvent((BukkitQuester) q, cq,
|
= new BukkitQuesterPreUpdateObjectiveEvent((BukkitQuester) q, cq,
|
||||||
new BukkitObjective(placeType, null, is.getAmount(), toPlace.getAmount()));
|
new BukkitObjective(placeType, null, is.getAmount(), goal.getAmount()));
|
||||||
plugin.getServer().getPluginManager().callEvent(preEvent);
|
plugin.getServer().getPluginManager().callEvent(preEvent);
|
||||||
|
|
||||||
final int index = qQuestData.blocksPlaced.indexOf(is);
|
final int index = qQuestData.blocksPlaced.indexOf(is);
|
||||||
@ -153,7 +154,7 @@ public class BukkitBlockListener implements Listener {
|
|||||||
|
|
||||||
final BukkitQuesterPostUpdateObjectiveEvent postEvent
|
final BukkitQuesterPostUpdateObjectiveEvent postEvent
|
||||||
= new BukkitQuesterPostUpdateObjectiveEvent((BukkitQuester) q, cq,
|
= new BukkitQuesterPostUpdateObjectiveEvent((BukkitQuester) q, cq,
|
||||||
new BukkitObjective(placeType, null, newAmount, toPlace.getAmount()));
|
new BukkitObjective(placeType, null, newAmount, goal.getAmount()));
|
||||||
plugin.getServer().getPluginManager().callEvent(postEvent);
|
plugin.getServer().getPluginManager().callEvent(postEvent);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -249,28 +250,30 @@ public class BukkitBlockListener implements Listener {
|
|||||||
if (quest.getOptions().canIgnoreBlockReplace()) {
|
if (quest.getOptions().canIgnoreBlockReplace()) {
|
||||||
// Ignore blocks replaced once broken (self)
|
// Ignore blocks replaced once broken (self)
|
||||||
if (currentStage.containsObjective(breakType)) {
|
if (currentStage.containsObjective(breakType)) {
|
||||||
for (final ItemStack is : questData.blocksBroken) {
|
for (int i = 0; i < questData.blocksBroken.size(); i++) {
|
||||||
|
final int progress = questData.blocksBroken.get(i) - 1;
|
||||||
|
if (progress < 0) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
final ItemStack is = currentStage.getBlocksToBreak().get(i);
|
||||||
if (event.getBlock().getType().equals(is.getType()) && is.getAmount() > 0) {
|
if (event.getBlock().getType().equals(is.getType()) && is.getAmount() > 0) {
|
||||||
ItemStack toBreak = new ItemStack(is.getType(), 64);
|
ItemStack goal = new ItemStack(is.getType(), 64);
|
||||||
for (final ItemStack stack : currentStage.getBlocksToBreak()) {
|
for (final ItemStack stack : currentStage.getBlocksToBreak()) {
|
||||||
if (BukkitItemUtil.compareItems(is, stack, true) == 0) {
|
if (BukkitItemUtil.compareItems(is, stack, true) == 0) {
|
||||||
toBreak = stack;
|
goal = stack;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
final BukkitQuesterPreUpdateObjectiveEvent preEvent
|
final BukkitQuesterPreUpdateObjectiveEvent preEvent
|
||||||
= new BukkitQuesterPreUpdateObjectiveEvent(quester, quest,
|
= new BukkitQuesterPreUpdateObjectiveEvent(quester, quest,
|
||||||
new BukkitObjective(placeType, null, is.getAmount(), toBreak.getAmount()));
|
new BukkitObjective(placeType, null, is.getAmount(), goal.getAmount()));
|
||||||
plugin.getServer().getPluginManager().callEvent(preEvent);
|
plugin.getServer().getPluginManager().callEvent(preEvent);
|
||||||
|
|
||||||
final int index = questData.blocksBroken.indexOf(is);
|
questData.blocksBroken.set(i, progress);
|
||||||
final int newAmount = is.getAmount() - 1;
|
|
||||||
is.setAmount(newAmount);
|
|
||||||
questData.blocksBroken.set(index, is);
|
|
||||||
|
|
||||||
final BukkitQuesterPostUpdateObjectiveEvent postEvent
|
final BukkitQuesterPostUpdateObjectiveEvent postEvent
|
||||||
= new BukkitQuesterPostUpdateObjectiveEvent(quester, quest,
|
= new BukkitQuesterPostUpdateObjectiveEvent(quester, quest,
|
||||||
new BukkitObjective(placeType, null, newAmount, toBreak.getAmount()));
|
new BukkitObjective(placeType, null, progress, goal.getAmount()));
|
||||||
plugin.getServer().getPluginManager().callEvent(postEvent);
|
plugin.getServer().getPluginManager().callEvent(postEvent);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -280,28 +283,30 @@ public class BukkitBlockListener implements Listener {
|
|||||||
(final Quester q, final Quest cq) -> {
|
(final Quester q, final Quest cq) -> {
|
||||||
if (!dispatchedBreakQuestIDs.contains(cq.getId())) {
|
if (!dispatchedBreakQuestIDs.contains(cq.getId())) {
|
||||||
final BukkitQuestProgress qQuestData = (BukkitQuestProgress) q.getQuestDataOrDefault(cq);
|
final BukkitQuestProgress qQuestData = (BukkitQuestProgress) q.getQuestDataOrDefault(cq);
|
||||||
for (final ItemStack is : qQuestData.blocksBroken) {
|
for (final int i : new LinkedList<>(qQuestData.blocksBroken)) {
|
||||||
|
final int progress = qQuestData.blocksBroken.get(i) - 1;
|
||||||
|
if (progress < 0) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
final ItemStack is = currentStage.getBlocksToBreak().get(i);
|
||||||
if (event.getBlock().getType().equals(is.getType()) && is.getAmount() > 0) {
|
if (event.getBlock().getType().equals(is.getType()) && is.getAmount() > 0) {
|
||||||
ItemStack toBreak = new ItemStack(is.getType(), 64);
|
ItemStack goal = new ItemStack(is.getType(), 64);
|
||||||
for (final ItemStack stack : ((BukkitStage) quester.getCurrentStage(cq)).getBlocksToBreak()) {
|
for (final ItemStack stack : ((BukkitStage) quester.getCurrentStage(cq)).getBlocksToBreak()) {
|
||||||
if (BukkitItemUtil.compareItems(is, stack, true) == 0) {
|
if (BukkitItemUtil.compareItems(is, stack, true) == 0) {
|
||||||
toBreak = stack;
|
goal = stack;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
final BukkitQuesterPreUpdateObjectiveEvent preEvent
|
final BukkitQuesterPreUpdateObjectiveEvent preEvent
|
||||||
= new BukkitQuesterPreUpdateObjectiveEvent((BukkitQuester) q, cq,
|
= new BukkitQuesterPreUpdateObjectiveEvent((BukkitQuester) q, cq,
|
||||||
new BukkitObjective(breakType, null, is.getAmount(), toBreak.getAmount()));
|
new BukkitObjective(breakType, null, is.getAmount(), goal.getAmount()));
|
||||||
plugin.getServer().getPluginManager().callEvent(preEvent);
|
plugin.getServer().getPluginManager().callEvent(preEvent);
|
||||||
|
|
||||||
final int index = qQuestData.blocksBroken.indexOf(is);
|
qQuestData.blocksBroken.set(i, progress);
|
||||||
final int newAmount = is.getAmount() - 1;
|
|
||||||
is.setAmount(newAmount);
|
|
||||||
qQuestData.blocksBroken.set(index, is);
|
|
||||||
|
|
||||||
final BukkitQuesterPostUpdateObjectiveEvent postEvent
|
final BukkitQuesterPostUpdateObjectiveEvent postEvent
|
||||||
= new BukkitQuesterPostUpdateObjectiveEvent((BukkitQuester) q, cq,
|
= new BukkitQuesterPostUpdateObjectiveEvent((BukkitQuester) q, cq,
|
||||||
new BukkitObjective(breakType, null, newAmount, toBreak.getAmount()));
|
new BukkitObjective(breakType, null, progress, goal.getAmount()));
|
||||||
plugin.getServer().getPluginManager().callEvent(postEvent);
|
plugin.getServer().getPluginManager().callEvent(postEvent);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -25,33 +25,40 @@ public class BukkitQuestProgress implements QuestProgress {
|
|||||||
public BukkitQuestProgress(final Quester quester) {
|
public BukkitQuestProgress(final Quester quester) {
|
||||||
this.quester = quester;
|
this.quester = quester;
|
||||||
}
|
}
|
||||||
|
// TODO increase serial id
|
||||||
public LinkedList<ItemStack> blocksBroken = new LinkedList<ItemStack>() {
|
public LinkedList<Integer> blocksBroken = new LinkedList<Integer>() {
|
||||||
|
|
||||||
private static final long serialVersionUID = -6071822509475270168L;
|
private static final long serialVersionUID = -6071822509475270169L;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ItemStack set(final int index, final ItemStack key) {
|
public boolean add(final Integer e) {
|
||||||
final ItemStack data = super.set(index, key);
|
final boolean b = super.add(e);
|
||||||
if (doJournalUpdate)
|
if (doJournalUpdate)
|
||||||
quester.updateJournal();
|
quester.updateJournal();
|
||||||
return data;
|
return b;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean add(final ItemStack key) {
|
public void add(final int index, final Integer element) {
|
||||||
final boolean data = super.add(key);
|
super.add(index, element);
|
||||||
if (doJournalUpdate)
|
if (doJournalUpdate)
|
||||||
quester.updateJournal();
|
quester.updateJournal();
|
||||||
return data;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean remove(final Object key) {
|
public boolean addAll(final Collection<? extends Integer> c) {
|
||||||
final boolean i = super.remove(key);
|
final boolean b = super.addAll(c);
|
||||||
if (doJournalUpdate)
|
if (doJournalUpdate)
|
||||||
quester.updateJournal();
|
quester.updateJournal();
|
||||||
return i;
|
return b;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean addAll(final int index, final Collection<? extends Integer> c) {
|
||||||
|
final boolean b = super.addAll(index, c);
|
||||||
|
if (doJournalUpdate)
|
||||||
|
quester.updateJournal();
|
||||||
|
return b;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -62,11 +69,27 @@ public class BukkitQuestProgress implements QuestProgress {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean addAll(final Collection<? extends ItemStack> m) {
|
public boolean remove(final Object o) {
|
||||||
final boolean i = super.addAll(m);
|
final boolean b = super.remove(o);
|
||||||
if (doJournalUpdate)
|
if (doJournalUpdate)
|
||||||
quester.updateJournal();
|
quester.updateJournal();
|
||||||
return i;
|
return b;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Integer remove(final int index) {
|
||||||
|
final Integer s = super.remove(index);
|
||||||
|
if (doJournalUpdate)
|
||||||
|
quester.updateJournal();
|
||||||
|
return s;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Integer set(final int index, final Integer element) {
|
||||||
|
final Integer s = super.set(index, element);
|
||||||
|
if (doJournalUpdate)
|
||||||
|
quester.updateJournal();
|
||||||
|
return s;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -1057,11 +1080,11 @@ public class BukkitQuestProgress implements QuestProgress {
|
|||||||
private boolean doJournalUpdate = true;
|
private boolean doJournalUpdate = true;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public LinkedList<ItemStack> getBlocksBroken() {
|
public LinkedList<Integer> getBlocksBroken() {
|
||||||
return blocksBroken;
|
return blocksBroken;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setBlocksBroken(final LinkedList<ItemStack> blocksBroken) {
|
public void setBlocksBroken(final LinkedList<Integer> blocksBroken) {
|
||||||
this.blocksBroken = blocksBroken;
|
this.blocksBroken = blocksBroken;
|
||||||
if (doJournalUpdate) {
|
if (doJournalUpdate) {
|
||||||
quester.updateJournal();
|
quester.updateJournal();
|
||||||
|
@ -1187,18 +1187,16 @@ public class BukkitQuester implements Quester {
|
|||||||
}
|
}
|
||||||
final BukkitQuestProgress data = (BukkitQuestProgress) getQuestDataOrDefault(quest);
|
final BukkitQuestProgress data = (BukkitQuestProgress) getQuestDataOrDefault(quest);
|
||||||
final LinkedList<Objective> objectives = new LinkedList<>();
|
final LinkedList<Objective> objectives = new LinkedList<>();
|
||||||
for (final ItemStack goal : stage.getBlocksToBreak()) {
|
for (int i = 0; i < data.getBlocksBroken().size(); i++) {
|
||||||
for (final ItemStack progress : data.blocksBroken) {
|
final int progress = data.getBlocksBroken().get(i);
|
||||||
if (progress.getType().equals(goal.getType()) && progress.getDurability() == goal.getDurability()) {
|
final ItemStack goal = stage.getBlocksToBreak().get(i);
|
||||||
final ChatColor color = progress.getAmount() < goal.getAmount() ? ChatColor.GREEN : ChatColor.GRAY;
|
final ChatColor color = progress < goal.getAmount() ? ChatColor.GREEN : ChatColor.GRAY;
|
||||||
String message = formatCurrentObjectiveMessage(color, BukkitLang.get(getPlayer(), "break"),
|
String message = formatCurrentObjectiveMessage(color, BukkitLang.get(getPlayer(), "break"),
|
||||||
progress.getAmount(), goal.getAmount());
|
progress, goal.getAmount());
|
||||||
if (formatNames) {
|
if (formatNames) {
|
||||||
message = message.replace("<item>", BukkitItemUtil.getName(progress));
|
message = message.replace("<item>", BukkitItemUtil.getName(goal));
|
||||||
}
|
|
||||||
objectives.add(new BukkitObjective(ObjectiveType.BREAK_BLOCK, message, progress, goal));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
objectives.add(new BukkitObjective(ObjectiveType.BREAK_BLOCK, message, progress, goal));
|
||||||
}
|
}
|
||||||
for (final ItemStack goal : stage.getBlocksToDamage()) {
|
for (final ItemStack goal : stage.getBlocksToDamage()) {
|
||||||
for (final ItemStack progress : data.blocksDamaged) {
|
for (final ItemStack progress : data.blocksDamaged) {
|
||||||
@ -1800,107 +1798,79 @@ public class BukkitQuester implements Quester {
|
|||||||
* Marks block as broken if Quester has such an objective
|
* Marks block as broken if Quester has such an objective
|
||||||
*
|
*
|
||||||
* @param quest The quest for which the block is being broken
|
* @param quest The quest for which the block is being broken
|
||||||
* @param itemStack The block being broken
|
* @param broken The block being broken
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("deprecation")
|
@SuppressWarnings("deprecation")
|
||||||
public void breakBlock(final Quest quest, final ItemStack itemStack) {
|
public void breakBlock(final Quest quest, final ItemStack broken) {
|
||||||
itemStack.setAmount(0);
|
ItemStack goal = null;
|
||||||
ItemStack broken = itemStack;
|
|
||||||
ItemStack toBreak = itemStack;
|
|
||||||
final BukkitQuestProgress bukkitQuestData = (BukkitQuestProgress) getQuestDataOrDefault(quest);
|
final BukkitQuestProgress bukkitQuestData = (BukkitQuestProgress) getQuestDataOrDefault(quest);
|
||||||
for (final ItemStack is : bukkitQuestData.blocksBroken) {
|
for (final ItemStack toBreak : ((BukkitStage) getCurrentStage(quest)).getBlocksToBreak()) {
|
||||||
if (itemStack.getType() == is.getType()) {
|
if (goal != null) {
|
||||||
if (itemStack.getType().isSolid() && is.getType().isSolid()) {
|
break;
|
||||||
|
}
|
||||||
|
if (broken.getType() == toBreak.getType()) {
|
||||||
|
if (broken.getType().isSolid() && toBreak.getType().isSolid()) {
|
||||||
// Blocks are solid so check for durability
|
// Blocks are solid so check for durability
|
||||||
if (itemStack.getDurability() == is.getDurability()) {
|
if (broken.getDurability() == toBreak.getDurability()) {
|
||||||
broken = is;
|
goal = toBreak;
|
||||||
} else if (!plugin.getLocaleManager().isBelow113()) {
|
} else if (!plugin.getLocaleManager().isBelow113()) {
|
||||||
// Ignore durability for 1.13+
|
// Ignore durability for 1.13+
|
||||||
broken = is;
|
goal = toBreak;
|
||||||
}
|
}
|
||||||
} else if (itemStack.getData() instanceof Crops && is.getData() instanceof Crops) {
|
} else if (broken.getData() instanceof Crops && toBreak.getData() instanceof Crops) {
|
||||||
if (is.getDurability() > 0) {
|
if (toBreak.getDurability() > 0) {
|
||||||
// Age is specified so check for durability
|
// Age toBreak specified so check for durability
|
||||||
if (itemStack.getDurability() == is.getDurability()) {
|
if (broken.getDurability() == toBreak.getDurability()) {
|
||||||
broken = is;
|
goal = toBreak;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Age is unspecified so ignore durability
|
// Age toBreak unspecified so ignore durability
|
||||||
broken = is;
|
goal = toBreak;
|
||||||
}
|
}
|
||||||
} else if (itemStack.getType().name().equals("RED_ROSE")) {
|
} else if (broken.getType().name().equals("RED_ROSE")) {
|
||||||
// Flowers are unique so check for durability
|
// Flowers are unique so check for durability
|
||||||
if (itemStack.getDurability() == is.getDurability()) {
|
if (broken.getDurability() == toBreak.getDurability()) {
|
||||||
broken = is;
|
goal = toBreak;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Blocks are not solid so ignore durability
|
// Blocks are not solid so ignore durability
|
||||||
broken = is;
|
goal = toBreak;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (final ItemStack is : ((BukkitStage) getCurrentStage(quest)).getBlocksToBreak()) {
|
|
||||||
if (itemStack.getType() == is.getType()) {
|
if (goal == null) {
|
||||||
if (itemStack.getType().isSolid() && is.getType().isSolid()) {
|
// No match found
|
||||||
// Blocks are solid so check for durability
|
return;
|
||||||
if (itemStack.getDurability() == is.getDurability()) {
|
|
||||||
toBreak = is;
|
|
||||||
} else if (!plugin.getLocaleManager().isBelow113()) {
|
|
||||||
// Ignore durability for 1.13+
|
|
||||||
toBreak = is;
|
|
||||||
}
|
|
||||||
} else if (itemStack.getData() instanceof Crops && is.getData() instanceof Crops) {
|
|
||||||
if (is.getDurability() > 0) {
|
|
||||||
// Age is specified so check for durability
|
|
||||||
if (itemStack.getDurability() == is.getDurability()) {
|
|
||||||
toBreak = is;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// Age is unspecified so ignore durability
|
|
||||||
toBreak = is;
|
|
||||||
}
|
|
||||||
} else if (itemStack.getType().name().equals("RED_ROSE")) {
|
|
||||||
// Flowers are unique so check for durability
|
|
||||||
if (itemStack.getDurability() == is.getDurability()) {
|
|
||||||
toBreak = is;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// Blocks are not solid so ignore durability
|
|
||||||
toBreak = is;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
final ObjectiveType type = ObjectiveType.BREAK_BLOCK;
|
final ObjectiveType type = ObjectiveType.BREAK_BLOCK;
|
||||||
final BukkitQuesterPreUpdateObjectiveEvent preEvent = new BukkitQuesterPreUpdateObjectiveEvent(this, quest,
|
final BukkitQuesterPreUpdateObjectiveEvent preEvent = new BukkitQuesterPreUpdateObjectiveEvent(this, quest,
|
||||||
new BukkitObjective(type, null, broken.getAmount(), toBreak.getAmount()));
|
new BukkitObjective(type, null, broken.getAmount(), goal.getAmount()));
|
||||||
plugin.getServer().getPluginManager().callEvent(preEvent);
|
plugin.getServer().getPluginManager().callEvent(preEvent);
|
||||||
|
|
||||||
final ItemStack newBroken = broken;
|
final int breakIndex = getCurrentStage(quest).getBlocksToBreak().indexOf(goal);
|
||||||
if (broken.getAmount() < toBreak.getAmount()) {
|
if (bukkitQuestData.blocksBroken.get(breakIndex) > goal.getAmount()) {
|
||||||
newBroken.setAmount(broken.getAmount() + 1);
|
return;
|
||||||
|
|
||||||
if (bukkitQuestData.blocksBroken.contains(broken)) {
|
|
||||||
bukkitQuestData.blocksBroken.set(bukkitQuestData.blocksBroken.indexOf(broken), newBroken);
|
|
||||||
if (broken.getAmount() == toBreak.getAmount()) {
|
|
||||||
finishObjective(quest, new BukkitObjective(type, null, itemStack, toBreak), null, null, null, null, null, null, null);
|
|
||||||
|
|
||||||
// Multiplayer
|
|
||||||
final ItemStack finalBroken = broken;
|
|
||||||
final ItemStack finalToBreak = toBreak;
|
|
||||||
dispatchMultiplayerObjectives(quest, getCurrentStage(quest), (final Quester q) -> {
|
|
||||||
((BukkitQuestProgress) q.getQuestDataOrDefault(quest)).blocksBroken.set(bukkitQuestData.blocksBroken
|
|
||||||
.indexOf(finalBroken), newBroken);
|
|
||||||
q.finishObjective(quest, new BukkitObjective(type, null, itemStack, finalToBreak), null, null, null, null, null,
|
|
||||||
null, null);
|
|
||||||
return null;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
final int progress = bukkitQuestData.blocksBroken.get(breakIndex) + 1;
|
||||||
|
bukkitQuestData.blocksBroken.set(breakIndex, progress);
|
||||||
|
if (progress >= goal.getAmount()) {
|
||||||
|
finishObjective(quest, new BukkitObjective(type, null, progress, goal), null, null, null,
|
||||||
|
null, null, null, null);
|
||||||
|
|
||||||
|
// Multiplayer
|
||||||
|
final ItemStack finalGoal = goal;
|
||||||
|
dispatchMultiplayerObjectives(quest, getCurrentStage(quest), (final Quester q) -> {
|
||||||
|
((BukkitQuestProgress) q.getQuestDataOrDefault(quest)).blocksBroken.set(breakIndex, progress);
|
||||||
|
q.finishObjective(quest, new BukkitObjective(type, null, progress, finalGoal), null, null, null,
|
||||||
|
null, null, null, null);
|
||||||
|
return null;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
final BukkitQuesterPostUpdateObjectiveEvent postEvent = new BukkitQuesterPostUpdateObjectiveEvent(this, quest,
|
final BukkitQuesterPostUpdateObjectiveEvent postEvent = new BukkitQuesterPostUpdateObjectiveEvent(this, quest,
|
||||||
new BukkitObjective(type, null, newBroken.getAmount(), toBreak.getAmount()));
|
new BukkitObjective(type, null, progress, goal.getAmount()));
|
||||||
plugin.getServer().getPluginManager().callEvent(postEvent);
|
plugin.getServer().getPluginManager().callEvent(postEvent);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -3649,13 +3619,8 @@ public class BukkitQuester implements Quester {
|
|||||||
}
|
}
|
||||||
final BukkitStage bukkitStage = (BukkitStage) quest.getStage(stage);
|
final BukkitStage bukkitStage = (BukkitStage) quest.getStage(stage);
|
||||||
if (!bukkitStage.getBlocksToBreak().isEmpty()) {
|
if (!bukkitStage.getBlocksToBreak().isEmpty()) {
|
||||||
for (final ItemStack toBreak : bukkitStage.getBlocksToBreak()) {
|
for (final ItemStack ignored : bukkitStage.getBlocksToBreak()) {
|
||||||
final ItemStack temp = getLowItemStack(toBreak.getType(), toBreak.getDurability());
|
data.blocksBroken.add(0);
|
||||||
if (data.blocksBroken.contains(toBreak)) {
|
|
||||||
data.blocksBroken.set(data.blocksBroken.indexOf(temp), temp);
|
|
||||||
} else {
|
|
||||||
data.blocksBroken.add(temp);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!bukkitStage.getBlocksToDamage().isEmpty()) {
|
if (!bukkitStage.getBlocksToDamage().isEmpty()) {
|
||||||
@ -3860,11 +3825,7 @@ public class BukkitQuester implements Quester {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (!questData.blocksBroken.isEmpty()) {
|
if (!questData.blocksBroken.isEmpty()) {
|
||||||
final LinkedList<Integer> blockAmounts = new LinkedList<>();
|
questSec.set("blocks-broken-amounts", questData.blocksBroken);
|
||||||
for (final ItemStack m : questData.blocksBroken) {
|
|
||||||
blockAmounts.add(m.getAmount());
|
|
||||||
}
|
|
||||||
questSec.set("blocks-broken-amounts", blockAmounts);
|
|
||||||
}
|
}
|
||||||
if (!questData.blocksDamaged.isEmpty()) {
|
if (!questData.blocksDamaged.isEmpty()) {
|
||||||
final LinkedList<Integer> blockAmounts = new LinkedList<>();
|
final LinkedList<Integer> blockAmounts = new LinkedList<>();
|
||||||
|
@ -44,13 +44,17 @@ public class BukkitObjective implements Objective {
|
|||||||
this.progress = ((ItemStack) progressObj).getAmount();
|
this.progress = ((ItemStack) progressObj).getAmount();
|
||||||
} else if (progressObj instanceof BukkitCountableMob) {
|
} else if (progressObj instanceof BukkitCountableMob) {
|
||||||
this.progress = ((BukkitCountableMob) progressObj).getCount();
|
this.progress = ((BukkitCountableMob) progressObj).getCount();
|
||||||
|
} else if (progressObj instanceof Integer) {
|
||||||
|
this.progress = (int) progress;
|
||||||
} else {
|
} else {
|
||||||
this.progress = 0;
|
this.progress = 0;
|
||||||
}
|
}
|
||||||
if (goalObj instanceof ItemStack) {
|
if (goalObj instanceof ItemStack) {
|
||||||
this.goal = ((ItemStack) goalObj).getAmount();
|
this.goal = ((ItemStack) goalObj).getAmount();
|
||||||
} else if (goalObj instanceof BukkitCountableMob) {
|
} else if (goalObj instanceof BukkitCountableMob) {
|
||||||
this.goal = ((BukkitCountableMob) goalObj).getCount();
|
this.goal = ((BukkitCountableMob) goalObj).getCount();
|
||||||
|
} else if (goalObj instanceof Integer) {
|
||||||
|
this.goal = (int) goalObj;
|
||||||
} else {
|
} else {
|
||||||
this.goal = 0;
|
this.goal = 0;
|
||||||
}
|
}
|
||||||
|
@ -176,15 +176,8 @@ public class BukkitQuesterYamlStorage implements QuesterStorageImpl {
|
|||||||
final BukkitQuestProgress bukkitQuestData = (BukkitQuestProgress) quester.getQuestDataOrDefault(quest);
|
final BukkitQuestProgress bukkitQuestData = (BukkitQuestProgress) quester.getQuestDataOrDefault(quest);
|
||||||
if (questSec.contains("blocks-broken-amounts")) {
|
if (questSec.contains("blocks-broken-amounts")) {
|
||||||
final List<Integer> brokenAmounts = questSec.getIntegerList("blocks-broken-amounts");
|
final List<Integer> brokenAmounts = questSec.getIntegerList("blocks-broken-amounts");
|
||||||
int index = 0;
|
for (int i = 0; i < brokenAmounts.size(); i++) {
|
||||||
for (final int amt : brokenAmounts) {
|
bukkitQuestData.blocksBroken.set(i, brokenAmounts.get(i));
|
||||||
final ItemStack is = stage.getBlocksToBreak().get(index);
|
|
||||||
final ItemStack temp = is.clone();
|
|
||||||
temp.setAmount(amt);
|
|
||||||
if (bukkitQuestData.getBlocksBroken().size() > 0) {
|
|
||||||
bukkitQuestData.blocksBroken.set(index, temp);
|
|
||||||
}
|
|
||||||
index++;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (questSec.contains("blocks-damaged-amounts")) {
|
if (questSec.contains("blocks-damaged-amounts")) {
|
||||||
|
@ -360,7 +360,7 @@ public class BukkitQuesterSqlStorage implements QuesterStorageImpl {
|
|||||||
try (final PreparedStatement ps = c.prepareStatement(statementProcessor.apply(PLAYER_QUEST_PROGRESS_INSERT))) {
|
try (final PreparedStatement ps = c.prepareStatement(statementProcessor.apply(PLAYER_QUEST_PROGRESS_INSERT))) {
|
||||||
ps.setString(1, uniqueId.toString());
|
ps.setString(1, uniqueId.toString());
|
||||||
ps.setString(2, entry.getKey().getId());
|
ps.setString(2, entry.getKey().getId());
|
||||||
ps.setString(3, serializeItemStackProgress(entry.getValue().getBlocksBroken()));
|
ps.setString(3, serializeProgress(entry.getValue().getBlocksBroken()));
|
||||||
ps.setString(4, serializeItemStackProgress(entry.getValue().getBlocksDamaged()));
|
ps.setString(4, serializeItemStackProgress(entry.getValue().getBlocksDamaged()));
|
||||||
ps.setString(5, serializeItemStackProgress(entry.getValue().getBlocksPlaced()));
|
ps.setString(5, serializeItemStackProgress(entry.getValue().getBlocksPlaced()));
|
||||||
ps.setString(6, serializeItemStackProgress(entry.getValue().getBlocksUsed()));
|
ps.setString(6, serializeItemStackProgress(entry.getValue().getBlocksUsed()));
|
||||||
@ -462,8 +462,7 @@ public class BukkitQuesterSqlStorage implements QuesterStorageImpl {
|
|||||||
final BukkitQuestProgress data = new BukkitQuestProgress(quester);
|
final BukkitQuestProgress data = new BukkitQuestProgress(quester);
|
||||||
if (quest != null && quester.getCurrentStage(quest) != null) {
|
if (quest != null && quester.getCurrentStage(quest) != null) {
|
||||||
final BukkitStage stage = (BukkitStage) quester.getCurrentStage(quest);
|
final BukkitStage stage = (BukkitStage) quester.getCurrentStage(quest);
|
||||||
data.blocksBroken.addAll(deserializeItemStackProgress(rs.getString("blocks_broken"),
|
data.blocksBroken.addAll(deserializeIntProgress(rs.getString("blocks_broken")));
|
||||||
stage.getBlocksToBreak()));
|
|
||||||
data.blocksDamaged.addAll(deserializeItemStackProgress(rs.getString("blocks_damaged"),
|
data.blocksDamaged.addAll(deserializeItemStackProgress(rs.getString("blocks_damaged"),
|
||||||
stage.getBlocksToDamage()));
|
stage.getBlocksToDamage()));
|
||||||
data.blocksPlaced.addAll(deserializeItemStackProgress(rs.getString("blocks_placed"),
|
data.blocksPlaced.addAll(deserializeItemStackProgress(rs.getString("blocks_placed"),
|
||||||
@ -623,6 +622,9 @@ public class BukkitQuesterSqlStorage implements QuesterStorageImpl {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @deprecated Legacy code, do not use. Will be removed in a later version.
|
||||||
|
*/
|
||||||
@SuppressWarnings("deprecation")
|
@SuppressWarnings("deprecation")
|
||||||
public LinkedList<ItemStack> deserializeItemStackProgress(String string, final LinkedList<ItemStack> objective) {
|
public LinkedList<ItemStack> deserializeItemStackProgress(String string, final LinkedList<ItemStack> objective) {
|
||||||
final LinkedList<ItemStack> list = new LinkedList<>();
|
final LinkedList<ItemStack> list = new LinkedList<>();
|
||||||
|
Loading…
Reference in New Issue
Block a user