Skip to content

Commit

Permalink
Add proper Why debug output for MCG generators.
Browse files Browse the repository at this point in the history
  • Loading branch information
BONNe committed Sep 23, 2020
1 parent fab6496 commit cf8e850
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import world.bentobox.bentobox.api.commands.ConfirmableCommand;
import world.bentobox.bentobox.api.localization.TextVariables;
import world.bentobox.bentobox.api.user.User;
import world.bentobox.bentobox.database.objects.Island;
import world.bentobox.bentobox.util.Util;
import world.bentobox.magiccobblestonegenerator.StoneGeneratorAddon;
import world.bentobox.magiccobblestonegenerator.utils.Constants;
Expand Down Expand Up @@ -220,7 +221,15 @@ public boolean execute(User user, String label, List<String> args)
}

// Set meta data on player
User target = User.getInstance(targetUUID);
Island island = this.getAddon().getIslands().getIsland(this.getWorld(), targetUUID);

if (island == null || island.getOwner() == null)
{
user.sendMessage("general.errors.player-is-not-owner");
return false;
}

User target = User.getInstance(island.getOwner());

if (!target.isOnline())
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import org.bukkit.event.block.BlockFormEvent;

import world.bentobox.magiccobblestonegenerator.StoneGeneratorAddon;
import world.bentobox.magiccobblestonegenerator.utils.Why;


/**
Expand Down Expand Up @@ -66,17 +67,15 @@ public void onBlockFormEvent(BlockFormEvent event)
map(island -> !island.isAllowed(StoneGeneratorAddon.MAGIC_COBBLESTONE_GENERATOR)).
orElse(!StoneGeneratorAddon.MAGIC_COBBLESTONE_GENERATOR.isSetForWorld(eventSourceBlock.getWorld())))
{
return;
}
Why.report(eventSourceBlock.getLocation(), "MCG is disabled by MAGIC_COBBLESTONE_GENERATOR flag!");

if (!this.addon.getAddonManager().isMembersOnline(eventSourceBlock.getLocation()))
{
// If island members are not online then do not continue
return;
}

if (!this.isInRangeToGenerate(eventSourceBlock))
{
Why.report(eventSourceBlock.getLocation(), "No players in range!");

// Check if any island member is at generator range.
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

import world.bentobox.magiccobblestonegenerator.StoneGeneratorAddon;
import world.bentobox.magiccobblestonegenerator.database.objects.GeneratorTierObject;
import world.bentobox.magiccobblestonegenerator.utils.Why;


/**
Expand Down Expand Up @@ -83,6 +84,7 @@ private boolean processBlockReplacement(Block block, @Nullable GeneratorTierObje
{
if (generatorTier == null)
{
Why.report(block.getLocation(), "Missing Generator Tier");
// Check if generator exists.
return false;
}
Expand All @@ -91,6 +93,8 @@ private boolean processBlockReplacement(Block block, @Nullable GeneratorTierObje

if (chanceMap.isEmpty())
{
Why.report(block.getLocation(), "Missing Block Chances in " + generatorTier.getUniqueId());

// Check if any block has a chance to spawn
return false;
}
Expand All @@ -99,10 +103,15 @@ private boolean processBlockReplacement(Block block, @Nullable GeneratorTierObje

if (newMaterial == null)
{
Why.report(block.getLocation(), "Cannot parse material from ChanceMap in " + generatorTier.getUniqueId());

// Check if a material was found
return false;
}

Why.report(block.getLocation(),
"Replace " + block.getType() + " with " + newMaterial + " by " + generatorTier.getUniqueId());

// ask config if physics should be used
block.setType(newMaterial, this.addon.getSettings().isUsePhysics());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,24 +13,36 @@
import org.bukkit.metadata.MetadataValue;
import java.util.UUID;

import world.bentobox.bentobox.BentoBox;
import world.bentobox.bentobox.api.addons.Addon;
import world.bentobox.bentobox.api.user.User;
import world.bentobox.bentobox.util.Util;
import world.bentobox.magiccobblestonegenerator.StoneGeneratorAddon;


/**
* Separate class that manages reports from Why Command.
*/
public class Why
{
public static void report(@NotNull Location location, String why)
{
BentoBox.getInstance().getIslands().getIslandAt(location).ifPresent(island -> {
User owner = User.getInstance(island.getOwner());

Why.report(StoneGeneratorAddon.getInstance(), owner, location, why);
});
}


/**
* This method prints debug messages about specific user.
* @param addon Addon which are called
* @param user User who calls the command.
* @param location Location where something is happening.
* @param why Reason and its value for why.
*/
public static void report(Addon addon, @Nullable User user, @NotNull Location location, Reason why)
public static void report(Addon addon, @Nullable User user, @NotNull Location location, String why)
{
// A quick way to debug flag listener unit tests is to add this line here: System.out.println(why.name()); NOSONAR
if (user != null &&
Expand All @@ -40,8 +52,8 @@ public static void report(Addon addon, @Nullable User user, @NotNull Location lo
findFirst().map(MetadataValue::asBoolean).
orElse(false))
{
String whyEvent = "Why: " + why.getKey() + " in world " + location.getWorld().getName() + " at " + Util.xyz(location.toVector());
String whyBypass = "Why: " + user.getName() + " - " + why.getValue();
String whyEvent = "Why: MagicCobblestoneGenerator in world " + location.getWorld().getName() + " at " + Util.xyz(location.toVector());
String whyBypass = "Why: " + user.getName() + " - " + why;

addon.log(whyEvent);
addon.log(whyBypass);
Expand Down

0 comments on commit cf8e850

Please sign in to comment.