Debug to view advancements

This commit is contained in:
tastybento 2023-10-28 10:24:41 -07:00
parent ec48419961
commit 553a44cd07
4 changed files with 15 additions and 2 deletions

View File

@ -58,7 +58,7 @@
<!-- Non-minecraft related dependencies -->
<powermock.version>2.0.9</powermock.version>
<!-- More visible way how to change dependency versions -->
<spigot.version>1.20.1-R0.1-SNAPSHOT</spigot.version>
<spigot.version>1.20.2-R0.1-SNAPSHOT</spigot.version>
<bentobox.version>1.24.0</bentobox.version>
<!-- Revision variable removes warning about dynamic version -->
<revision>${build.version}-SNAPSHOT</revision>

View File

@ -16,6 +16,7 @@ import org.bukkit.entity.Player;
import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.jdt.annotation.Nullable;
import world.bentobox.bentobox.BentoBox;
import world.bentobox.bentobox.api.events.island.IslandEvent;
import world.bentobox.bentobox.database.Database;
import world.bentobox.bentobox.database.objects.Island;
@ -183,10 +184,12 @@ public class AdvancementsManager {
*/
public int addAdvancement(Player p, Advancement advancement) {
if (!addon.inWorld(p.getWorld())) {
BentoBox.getInstance().logDebug("Wrong world");
// Wrong world
return 0;
}
int score = getScore(advancement);
BentoBox.getInstance().logDebug("score is " + score);
if (score == 0) {
return 0;
}
@ -197,9 +200,11 @@ public class AdvancementsManager {
&& addAdvancement(island, advancement.getKey().toString())) {
int oldSize = island.getProtectionRange();
int newSize = Math.max(1, oldSize + score);
BentoBox.getInstance().logDebug("Changing size old = " + oldSize + " new = " + newSize);
setProtectionSize(island, newSize, p.getUniqueId());
return score;
}
BentoBox.getInstance().logDebug("No island");
return 0;
}
@ -240,6 +245,7 @@ public class AdvancementsManager {
* @return score of advancement, or 0 if it cannot be worked out
*/
public int getScore(Advancement a) {
BentoBox.getInstance().logDebug("get score");
String adv = "advancements." + a.getKey().getKey();
// Unknowns
if (adv.endsWith("/root")) {
@ -257,7 +263,9 @@ public class AdvancementsManager {
return 0;
}
} else {
BentoBox.getInstance().logDebug("Checking yaml for " + adv);
if (advConfig.contains(adv)) {
BentoBox.getInstance().logDebug("It's there");
return advConfig.getInt(adv, this.unknownAdvChange);
}

View File

@ -30,6 +30,7 @@ import org.bukkit.event.player.PlayerMoveEvent;
import org.bukkit.event.player.PlayerPortalEvent;
import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause;
import world.bentobox.bentobox.BentoBox;
import world.bentobox.bentobox.api.events.island.IslandNewIslandEvent;
import world.bentobox.bentobox.api.events.team.TeamJoinedEvent;
import world.bentobox.bentobox.api.events.team.TeamLeaveEvent;
@ -84,14 +85,17 @@ public class AdvancementListener implements Listener {
*/
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
public void onAdvancement(PlayerAdvancementDoneEvent e) {
BentoBox.getInstance().logDebug(e.getAdvancement().getKey());
// Ignore if player is not in survival or if advancements are being ignored
if (!e.getPlayer().getGameMode().equals(GameMode.SURVIVAL) || addon.getSettings().isIgnoreAdvancements()) {
return;
}
// Check if player is in the Boxed worlds
if (addon.inWorld(e.getPlayer().getWorld())) {
BentoBox.getInstance().logDebug("in world");
// Only allow members or higher to get advancements in a box
if (addon.getSettings().isDenyVisitorAdvancements() && !addon.getIslands().getIslandAt(e.getPlayer().getLocation()).map(i -> i.getMemberSet().contains(e.getPlayer().getUniqueId())).orElse(false)) {
BentoBox.getInstance().logDebug("not on island");
// Remove advancement from player
e.getAdvancement().getCriteria().forEach(c ->
e.getPlayer().getAdvancementProgress(e.getAdvancement()).revokeCriteria(c));
@ -103,6 +107,7 @@ public class AdvancementListener implements Listener {
}
// Add the advancement to the island
int score = addon.getAdvManager().addAdvancement(e.getPlayer(), e.getAdvancement());
BentoBox.getInstance().logDebug("Score for this advancement is " + score);
// Tell other team players one tick after it occurs if it is something that has a score
if (score != 0) {
User user = User.getInstance(e.getPlayer());

View File

@ -20,7 +20,7 @@ import org.bukkit.block.structure.Mirror;
import org.bukkit.block.structure.StructureRotation;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.craftbukkit.v1_20_R1.CraftWorld;
import org.bukkit.craftbukkit.v1_20_R2.CraftWorld;
import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player;