mirror of
https://github.com/BentoBoxWorld/Challenges.git
synced 2024-11-24 19:45:14 +01:00
Improve debugging in Creative GameMode.
Add ability to Creative GameMode complete inventory and exp challenge without necessary items and exp.
This commit is contained in:
parent
40d33f4afc
commit
68b0fa3b2e
2
pom.xml
2
pom.xml
@ -6,7 +6,7 @@
|
|||||||
|
|
||||||
<groupId>world.bentobox</groupId>
|
<groupId>world.bentobox</groupId>
|
||||||
<artifactId>challenges</artifactId>
|
<artifactId>challenges</artifactId>
|
||||||
<version>0.5.0</version>
|
<version>0.6.0-SNAPSHOT</version>
|
||||||
|
|
||||||
<name>Challenges</name>
|
<name>Challenges</name>
|
||||||
<description>Challenges is an add-on for BentoBox, an expandable Minecraft Bukkit plugin for island-type games like SkyBlock, AcidIsland or CaveBlock.</description>
|
<description>Challenges is an add-on for BentoBox, an expandable Minecraft Bukkit plugin for island-type games like SkyBlock, AcidIsland or CaveBlock.</description>
|
||||||
|
@ -4,6 +4,7 @@
|
|||||||
package world.bentobox.challenges.panel;
|
package world.bentobox.challenges.panel;
|
||||||
|
|
||||||
|
|
||||||
|
import org.bukkit.GameMode;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
import org.bukkit.block.Block;
|
import org.bukkit.block.Block;
|
||||||
@ -486,9 +487,14 @@ public class TryToComplete
|
|||||||
{
|
{
|
||||||
// Run through inventory
|
// Run through inventory
|
||||||
List<ItemStack> required = new ArrayList<>(this.challenge.getRequiredItems());
|
List<ItemStack> required = new ArrayList<>(this.challenge.getRequiredItems());
|
||||||
|
|
||||||
|
// Players in creative game mode has got all items. No point to search for them.
|
||||||
|
if (this.user.getPlayer().getGameMode() != GameMode.CREATIVE)
|
||||||
|
{
|
||||||
for (ItemStack req : required)
|
for (ItemStack req : required)
|
||||||
{
|
{
|
||||||
// Check for FIREWORK_ROCKET, ENCHANTED_BOOK, WRITTEN_BOOK, POTION and FILLED_MAP because these have unique meta when created
|
// Check for FIREWORK_ROCKET, ENCHANTED_BOOK, WRITTEN_BOOK, POTION and
|
||||||
|
// FILLED_MAP because these have unique meta when created
|
||||||
switch (req.getType())
|
switch (req.getType())
|
||||||
{
|
{
|
||||||
case FIREWORK_ROCKET:
|
case FIREWORK_ROCKET:
|
||||||
@ -497,7 +503,8 @@ public class TryToComplete
|
|||||||
case FILLED_MAP:
|
case FILLED_MAP:
|
||||||
// Get how many items are in the inventory. Item stacks amounts need to be summed
|
// Get how many items are in the inventory. Item stacks amounts need to be summed
|
||||||
int numInInventory =
|
int numInInventory =
|
||||||
Arrays.stream(this.user.getInventory().getContents()).filter(Objects::nonNull).
|
Arrays.stream(this.user.getInventory().getContents()).
|
||||||
|
filter(Objects::nonNull).
|
||||||
filter(i -> i.getType().equals(req.getType())).
|
filter(i -> i.getType().equals(req.getType())).
|
||||||
mapToInt(ItemStack::getAmount).
|
mapToInt(ItemStack::getAmount).
|
||||||
sum();
|
sum();
|
||||||
@ -519,6 +526,7 @@ public class TryToComplete
|
|||||||
Util.prettifyText(req.getType().toString()));
|
Util.prettifyText(req.getType().toString()));
|
||||||
return EMPTY_RESULT;
|
return EMPTY_RESULT;
|
||||||
}
|
}
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -528,7 +536,7 @@ public class TryToComplete
|
|||||||
{
|
{
|
||||||
this.removeItems(required);
|
this.removeItems(required);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Return the result
|
// Return the result
|
||||||
return new ChallengeResult().setMeetsRequirements().setRepeat(
|
return new ChallengeResult().setMeetsRequirements().setRepeat(
|
||||||
@ -790,8 +798,11 @@ public class TryToComplete
|
|||||||
{
|
{
|
||||||
this.user.sendMessage("challenges.errors.incorrect");
|
this.user.sendMessage("challenges.errors.incorrect");
|
||||||
}
|
}
|
||||||
else if (this.user.getPlayer().getTotalExperience() < this.challenge.getRequiredExperience())
|
else if (this.user.getPlayer().getTotalExperience() < this.challenge.getRequiredExperience() &&
|
||||||
|
this.user.getPlayer().getGameMode() != GameMode.CREATIVE)
|
||||||
{
|
{
|
||||||
|
// Players in creative gamemode has infinite amount of EXP.
|
||||||
|
|
||||||
this.user.sendMessage("challenges.errors.not-enough-experience",
|
this.user.sendMessage("challenges.errors.not-enough-experience",
|
||||||
"[value]",
|
"[value]",
|
||||||
Integer.toString(this.challenge.getRequiredExperience()));
|
Integer.toString(this.challenge.getRequiredExperience()));
|
||||||
@ -810,8 +821,10 @@ public class TryToComplete
|
|||||||
this.addon.getEconomyProvider().withdraw(this.user, this.challenge.getRequiredMoney());
|
this.addon.getEconomyProvider().withdraw(this.user, this.challenge.getRequiredMoney());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.challenge.isTakeExperience())
|
if (this.challenge.isTakeExperience() &&
|
||||||
|
this.user.getPlayer().getGameMode() != GameMode.CREATIVE)
|
||||||
{
|
{
|
||||||
|
// Cannot take anything from creative game mode.
|
||||||
this.user.getPlayer().setTotalExperience(
|
this.user.getPlayer().setTotalExperience(
|
||||||
this.user.getPlayer().getTotalExperience() - this.challenge.getRequiredExperience());
|
this.user.getPlayer().getTotalExperience() - this.challenge.getRequiredExperience());
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user