1
mirror of https://github.com/StarWishsama/Slimefun4.git synced 2024-09-20 03:35:51 +00:00

[CI skip] Added unit test for new debugging tool

This commit is contained in:
TheBusyBiscuit 2021-10-11 01:37:54 +02:00
parent ee43db9388
commit 008090cc6f
41 changed files with 227 additions and 83 deletions

View File

@ -4,8 +4,8 @@ import org.bukkit.block.Block;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import io.github.thebusybiscuit.slimefun4.api.events.SlimefunItemSpawnEvent; import io.github.thebusybiscuit.slimefun4.api.events.SlimefunItemSpawnEvent;
import io.github.thebusybiscuit.slimefun4.core.networks.cargo.CargoNet;
import io.github.thebusybiscuit.slimefun4.core.multiblocks.MultiBlockMachine; import io.github.thebusybiscuit.slimefun4.core.multiblocks.MultiBlockMachine;
import io.github.thebusybiscuit.slimefun4.core.networks.cargo.CargoNet;
import io.github.thebusybiscuit.slimefun4.implementation.items.altar.AncientPedestal; import io.github.thebusybiscuit.slimefun4.implementation.items.altar.AncientPedestal;
import io.github.thebusybiscuit.slimefun4.implementation.items.seasonal.ChristmasPresent; import io.github.thebusybiscuit.slimefun4.implementation.items.seasonal.ChristmasPresent;
import io.github.thebusybiscuit.slimefun4.implementation.items.seasonal.EasterEgg; import io.github.thebusybiscuit.slimefun4.implementation.items.seasonal.EasterEgg;

View File

@ -1,12 +1,13 @@
package io.github.thebusybiscuit.slimefun4.core.commands.subcommands; package io.github.thebusybiscuit.slimefun4.core.commands.subcommands;
import javax.annotation.Nonnull;
import org.bukkit.command.CommandSender;
import io.github.thebusybiscuit.slimefun4.core.commands.SlimefunCommand; import io.github.thebusybiscuit.slimefun4.core.commands.SlimefunCommand;
import io.github.thebusybiscuit.slimefun4.core.commands.SubCommand; import io.github.thebusybiscuit.slimefun4.core.commands.SubCommand;
import io.github.thebusybiscuit.slimefun4.core.debug.Debug; import io.github.thebusybiscuit.slimefun4.core.debug.Debug;
import io.github.thebusybiscuit.slimefun4.implementation.Slimefun; import io.github.thebusybiscuit.slimefun4.implementation.Slimefun;
import org.bukkit.command.CommandSender;
import javax.annotation.Nonnull;
/** /**
* The debug command will allow server owners to get information for us developers. * The debug command will allow server owners to get information for us developers.
@ -35,9 +36,7 @@ public class DebugCommand extends SubCommand {
if (args.length == 1) { if (args.length == 1) {
String currentCase = Debug.getTestCase(); String currentCase = Debug.getTestCase();
if (currentCase != null) { if (currentCase != null) {
Slimefun.getLocalization().sendMessage(sender, "commands.debug.current", true, Slimefun.getLocalization().sendMessage(sender, "commands.debug.current", true, msg -> msg.replace("%test_case%", currentCase));
msg -> msg.replace("%test_case%", currentCase)
);
} else { } else {
Slimefun.getLocalization().sendMessage(sender, "commands.debug.none-running", true); Slimefun.getLocalization().sendMessage(sender, "commands.debug.none-running", true);
} }
@ -51,8 +50,7 @@ public class DebugCommand extends SubCommand {
Slimefun.getLocalization().sendMessage(sender, "commands.debug.disabled"); Slimefun.getLocalization().sendMessage(sender, "commands.debug.disabled");
} else { } else {
Debug.setTestCase(test); Debug.setTestCase(test);
Slimefun.getLocalization().sendMessage(sender, "commands.debug.running", Slimefun.getLocalization().sendMessage(sender, "commands.debug.running", msg -> msg.replace("%test%", test));
msg -> msg.replace("%test%", test));
} }
} }
} }

View File

@ -7,8 +7,8 @@ import org.bukkit.entity.Player;
import io.github.thebusybiscuit.slimefun4.core.commands.SlimefunCommand; import io.github.thebusybiscuit.slimefun4.core.commands.SlimefunCommand;
import io.github.thebusybiscuit.slimefun4.core.commands.SubCommand; import io.github.thebusybiscuit.slimefun4.core.commands.SubCommand;
import io.github.thebusybiscuit.slimefun4.implementation.SlimefunItems;
import io.github.thebusybiscuit.slimefun4.implementation.Slimefun; import io.github.thebusybiscuit.slimefun4.implementation.Slimefun;
import io.github.thebusybiscuit.slimefun4.implementation.SlimefunItems;
class DebugFishCommand extends SubCommand { class DebugFishCommand extends SubCommand {

View File

@ -1,10 +1,11 @@
package io.github.thebusybiscuit.slimefun4.core.debug; package io.github.thebusybiscuit.slimefun4.core.debug;
import io.github.thebusybiscuit.slimefun4.implementation.Slimefun; import java.util.logging.Level;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import java.util.logging.Level;
import io.github.thebusybiscuit.slimefun4.implementation.Slimefun;
/** /**
* This class is responsible for debug logging. * This class is responsible for debug logging.
@ -23,8 +24,10 @@ public final class Debug {
/** /**
* Log a message if the {@link TestCase} is currently enabled. * Log a message if the {@link TestCase} is currently enabled.
* *
* @param testCase The {@link TestCase} to use * @param testCase
* @param msg The message to log * The {@link TestCase} to use
* @param msg
* The message to log
*/ */
public static void log(@Nonnull TestCase testCase, @Nonnull String msg) { public static void log(@Nonnull TestCase testCase, @Nonnull String msg) {
log(testCase.toString(), msg, new Object[0]); log(testCase.toString(), msg, new Object[0]);
@ -33,9 +36,12 @@ public final class Debug {
/** /**
* Log a variable message if the {@link TestCase} is currently enabled. * Log a variable message if the {@link TestCase} is currently enabled.
* *
* @param testCase The {@link TestCase} to use * @param testCase
* @param msg The message to log * The {@link TestCase} to use
* @param vars The variables to replace, use "{}" in the message and have it replaced with a specified thing * @param msg
* The message to log
* @param vars
* The variables to replace, use "{}" in the message and have it replaced with a specified thing
*/ */
public static void log(@Nonnull TestCase testCase, @Nonnull String msg, @Nonnull Object... vars) { public static void log(@Nonnull TestCase testCase, @Nonnull String msg, @Nonnull Object... vars) {
log(testCase.toString(), msg, vars); log(testCase.toString(), msg, vars);
@ -44,8 +50,10 @@ public final class Debug {
/** /**
* Log a message if the test case is currently enabled. * Log a message if the test case is currently enabled.
* *
* @param test The test case to use * @param test
* @param msg The message to log * The test case to use
* @param msg
* The message to log
*/ */
public static void log(@Nonnull String test, @Nonnull String msg) { public static void log(@Nonnull String test, @Nonnull String msg) {
log(test, msg, new Object[0]); log(test, msg, new Object[0]);
@ -54,18 +62,23 @@ public final class Debug {
/** /**
* Log a message if the test case is currently enabled. * Log a message if the test case is currently enabled.
* *
* @param test The test case to use * @param test
* @param msg The message to log * The test case to use
* @param vars The variables to replace, use "{}" in the message and have it replaced with a specified thing * @param msg
* The message to log
* @param vars
* The variables to replace, use "{}" in the message and have it replaced with a specified thing
*/ */
public static void log(@Nonnull String test, @Nonnull String msg, @Nonnull Object... vars) { public static void log(@Nonnull String test, @Nonnull String msg, @Nonnull Object... vars) {
if (testCase == null || !testCase.equals(test)) return; if (testCase == null || !testCase.equals(test)) {
return;
}
if (vars.length > 0) { if (vars.length > 0) {
String formatted = formatMessage(msg, vars); String formatted = formatMessage(msg, vars);
Slimefun.logger().log(Level.INFO, "[DEBUG {0}] {1}", new Object[]{ test, formatted }); Slimefun.logger().log(Level.INFO, "[DEBUG {0}] {1}", new Object[] { test, formatted });
} else { } else {
Slimefun.logger().log(Level.INFO, "[DEBUG {0}] {1}", new Object[]{ test, msg }); Slimefun.logger().log(Level.INFO, "[DEBUG {0}] {1}", new Object[] { test, msg });
} }
} }
@ -78,8 +91,11 @@ public final class Debug {
* MyBenchmark.whileFindChars thrpt 5 3319022.018 ± 45663.898 ops/s * MyBenchmark.whileFindChars thrpt 5 3319022.018 ± 45663.898 ops/s
* </code> * </code>
* *
* @param msg The message to send. For variables, you can pass "{}" * @param msg
* @param vars A varargs of the variables you wish to use * The message to send. For variables, you can pass "{}"
* @param vars
* A varargs of the variables you wish to use
*
* @return The resulting String * @return The resulting String
*/ */
private static @Nonnull String formatMessage(@Nonnull String msg, @Nonnull Object... vars) { private static @Nonnull String formatMessage(@Nonnull String msg, @Nonnull Object... vars) {
@ -89,7 +105,8 @@ public final class Debug {
// Find an opening curly brace `{` and validate the next char is a closing one `}` // Find an opening curly brace `{` and validate the next char is a closing one `}`
while ((i = msg.indexOf('{', i)) != -1 && msg.charAt(i + 1) == '}') { while ((i = msg.indexOf('{', i)) != -1 && msg.charAt(i + 1) == '}') {
// Substring up to the opening brace `{`, add the variable for this and add the rest of the message // Substring up to the opening brace `{`, add the variable for this and add the rest of the message
msg = msg.substring(0, i) + vars[idx++] + msg.substring(i + 2); msg = msg.substring(0, i) + vars[idx] + msg.substring(i + 2);
idx++;
} }
return msg; return msg;
@ -99,7 +116,8 @@ public final class Debug {
* Set the current test case for this server. * Set the current test case for this server.
* This will enable debug logging for this specific case which can be helpful by Slimefun or addon developers. * This will enable debug logging for this specific case which can be helpful by Slimefun or addon developers.
* *
* @param test The test case to enable or null to disable it * @param test
* The test case to enable or null to disable it
*/ */
public static void setTestCase(@Nullable String test) { public static void setTestCase(@Nullable String test) {
testCase = test; testCase = test;

View File

@ -1,8 +1,9 @@
package io.github.thebusybiscuit.slimefun4.core.debug; package io.github.thebusybiscuit.slimefun4.core.debug;
import javax.annotation.Nonnull;
import java.util.Locale; import java.util.Locale;
import javax.annotation.Nonnull;
/** /**
* Test cases in Slimefun. These are very useful for debugging why behavior is happening. * Test cases in Slimefun. These are very useful for debugging why behavior is happening.
* Server owners can enable these with {@code /sf debug <test-case>} * Server owners can enable these with {@code /sf debug <test-case>}

View File

@ -171,11 +171,11 @@ public abstract class MultiBlockMachine extends SlimefunItem implements NotPlace
* This method handles an output {@link ItemStack} from the {@link MultiBlockMachine} which has a crafting delay * This method handles an output {@link ItemStack} from the {@link MultiBlockMachine} which has a crafting delay
* *
* @param outputItem * @param outputItem
* A crafted {@link ItemStack} from {@link MultiBlockMachine} * A crafted {@link ItemStack} from {@link MultiBlockMachine}
* @param block * @param block
* Main {@link Block} of our {@link Container} from {@link MultiBlockMachine} * Main {@link Block} of our {@link Container} from {@link MultiBlockMachine}
* @param blockInv * @param blockInv
* The {@link Inventory} of our {@link Container} * The {@link Inventory} of our {@link Container}
* *
*/ */
@ParametersAreNonnullByDefault @ParametersAreNonnullByDefault

View File

@ -5,8 +5,6 @@ import java.util.Map;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import io.github.thebusybiscuit.slimefun4.core.debug.Debug;
import io.github.thebusybiscuit.slimefun4.core.debug.TestCase;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.Tag; import org.bukkit.Tag;
@ -19,6 +17,8 @@ import org.bukkit.inventory.InventoryHolder;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import io.github.bakedlibs.dough.inventory.InvUtils; import io.github.bakedlibs.dough.inventory.InvUtils;
import io.github.thebusybiscuit.slimefun4.core.debug.Debug;
import io.github.thebusybiscuit.slimefun4.core.debug.TestCase;
import io.github.thebusybiscuit.slimefun4.implementation.Slimefun; import io.github.thebusybiscuit.slimefun4.implementation.Slimefun;
import io.github.thebusybiscuit.slimefun4.utils.SlimefunUtils; import io.github.thebusybiscuit.slimefun4.utils.SlimefunUtils;
import io.github.thebusybiscuit.slimefun4.utils.itemstack.ItemStackWrapper; import io.github.thebusybiscuit.slimefun4.utils.itemstack.ItemStackWrapper;

View File

@ -7,13 +7,13 @@ import java.util.function.Predicate;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
import io.github.thebusybiscuit.slimefun4.core.debug.Debug;
import io.github.thebusybiscuit.slimefun4.core.debug.TestCase;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.block.Block; import org.bukkit.block.Block;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import io.github.thebusybiscuit.slimefun4.api.items.SlimefunItem; import io.github.thebusybiscuit.slimefun4.api.items.SlimefunItem;
import io.github.thebusybiscuit.slimefun4.core.debug.Debug;
import io.github.thebusybiscuit.slimefun4.core.debug.TestCase;
import io.github.thebusybiscuit.slimefun4.implementation.items.cargo.CargoNode; import io.github.thebusybiscuit.slimefun4.implementation.items.cargo.CargoNode;
import io.github.thebusybiscuit.slimefun4.utils.SlimefunUtils; import io.github.thebusybiscuit.slimefun4.utils.SlimefunUtils;
import io.github.thebusybiscuit.slimefun4.utils.itemstack.ItemStackWrapper; import io.github.thebusybiscuit.slimefun4.utils.itemstack.ItemStackWrapper;

View File

@ -22,8 +22,8 @@ import io.github.thebusybiscuit.slimefun4.api.network.NetworkComponent;
import io.github.thebusybiscuit.slimefun4.core.attributes.EnergyNetComponent; import io.github.thebusybiscuit.slimefun4.core.attributes.EnergyNetComponent;
import io.github.thebusybiscuit.slimefun4.core.attributes.EnergyNetProvider; import io.github.thebusybiscuit.slimefun4.core.attributes.EnergyNetProvider;
import io.github.thebusybiscuit.slimefun4.core.attributes.HologramOwner; import io.github.thebusybiscuit.slimefun4.core.attributes.HologramOwner;
import io.github.thebusybiscuit.slimefun4.implementation.SlimefunItems;
import io.github.thebusybiscuit.slimefun4.implementation.Slimefun; import io.github.thebusybiscuit.slimefun4.implementation.Slimefun;
import io.github.thebusybiscuit.slimefun4.implementation.SlimefunItems;
import io.github.thebusybiscuit.slimefun4.utils.NumberUtils; import io.github.thebusybiscuit.slimefun4.utils.NumberUtils;
import me.mrCookieSlime.CSCoreLibPlugin.Configuration.Config; import me.mrCookieSlime.CSCoreLibPlugin.Configuration.Config;

View File

@ -10,8 +10,8 @@ import io.github.thebusybiscuit.slimefun4.api.MinecraftVersion;
import io.github.thebusybiscuit.slimefun4.api.items.ItemGroup; import io.github.thebusybiscuit.slimefun4.api.items.ItemGroup;
import io.github.thebusybiscuit.slimefun4.api.items.SlimefunItemStack; import io.github.thebusybiscuit.slimefun4.api.items.SlimefunItemStack;
import io.github.thebusybiscuit.slimefun4.api.recipes.RecipeType; import io.github.thebusybiscuit.slimefun4.api.recipes.RecipeType;
import io.github.thebusybiscuit.slimefun4.implementation.SlimefunItems;
import io.github.thebusybiscuit.slimefun4.implementation.Slimefun; import io.github.thebusybiscuit.slimefun4.implementation.Slimefun;
import io.github.thebusybiscuit.slimefun4.implementation.SlimefunItems;
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.abstractItems.AGenerator; import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.abstractItems.AGenerator;
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.abstractItems.MachineFuel; import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.abstractItems.MachineFuel;

View File

@ -8,8 +8,8 @@ import org.bukkit.inventory.ItemStack;
import io.github.thebusybiscuit.slimefun4.api.items.ItemGroup; import io.github.thebusybiscuit.slimefun4.api.items.ItemGroup;
import io.github.thebusybiscuit.slimefun4.api.items.SlimefunItemStack; import io.github.thebusybiscuit.slimefun4.api.items.SlimefunItemStack;
import io.github.thebusybiscuit.slimefun4.api.recipes.RecipeType; import io.github.thebusybiscuit.slimefun4.api.recipes.RecipeType;
import io.github.thebusybiscuit.slimefun4.implementation.SlimefunItems;
import io.github.thebusybiscuit.slimefun4.implementation.Slimefun; import io.github.thebusybiscuit.slimefun4.implementation.Slimefun;
import io.github.thebusybiscuit.slimefun4.implementation.SlimefunItems;
import io.github.thebusybiscuit.slimefun4.implementation.items.multiblocks.OreWasher; import io.github.thebusybiscuit.slimefun4.implementation.items.multiblocks.OreWasher;
import io.github.thebusybiscuit.slimefun4.utils.SlimefunUtils; import io.github.thebusybiscuit.slimefun4.utils.SlimefunUtils;

View File

@ -12,8 +12,8 @@ import io.github.thebusybiscuit.slimefun4.api.items.SlimefunItemStack;
import io.github.thebusybiscuit.slimefun4.api.recipes.RecipeType; import io.github.thebusybiscuit.slimefun4.api.recipes.RecipeType;
import io.github.thebusybiscuit.slimefun4.core.attributes.NotHopperable; import io.github.thebusybiscuit.slimefun4.core.attributes.NotHopperable;
import io.github.thebusybiscuit.slimefun4.core.attributes.RecipeDisplayItem; import io.github.thebusybiscuit.slimefun4.core.attributes.RecipeDisplayItem;
import io.github.thebusybiscuit.slimefun4.implementation.SlimefunItems;
import io.github.thebusybiscuit.slimefun4.implementation.Slimefun; import io.github.thebusybiscuit.slimefun4.implementation.Slimefun;
import io.github.thebusybiscuit.slimefun4.implementation.SlimefunItems;
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.abstractItems.AContainer; import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.abstractItems.AContainer;
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.abstractItems.MachineRecipe; import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.abstractItems.MachineRecipe;

View File

@ -40,7 +40,7 @@ import me.mrCookieSlime.Slimefun.api.inventory.BlockMenu;
*/ */
public class AutoEnchanter extends AbstractEnchantmentMachine { public class AutoEnchanter extends AbstractEnchantmentMachine {
private final ItemSetting<Boolean> overrideExistingEnchantsLvl= new ItemSetting<>(this, "override-existing-enchants-lvl", false); private final ItemSetting<Boolean> overrideExistingEnchantsLvl = new ItemSetting<>(this, "override-existing-enchants-lvl", false);
@ParametersAreNonnullByDefault @ParametersAreNonnullByDefault
public AutoEnchanter(ItemGroup itemGroup, SlimefunItemStack item, RecipeType recipeType, ItemStack[] recipe) { public AutoEnchanter(ItemGroup itemGroup, SlimefunItemStack item, RecipeType recipeType, ItemStack[] recipe) {

View File

@ -14,8 +14,8 @@ import org.bukkit.potion.PotionEffectType;
import io.github.thebusybiscuit.slimefun4.api.items.ItemGroup; import io.github.thebusybiscuit.slimefun4.api.items.ItemGroup;
import io.github.thebusybiscuit.slimefun4.api.items.SlimefunItemStack; import io.github.thebusybiscuit.slimefun4.api.items.SlimefunItemStack;
import io.github.thebusybiscuit.slimefun4.api.recipes.RecipeType; import io.github.thebusybiscuit.slimefun4.api.recipes.RecipeType;
import io.github.thebusybiscuit.slimefun4.implementation.SlimefunItems;
import io.github.thebusybiscuit.slimefun4.implementation.Slimefun; import io.github.thebusybiscuit.slimefun4.implementation.Slimefun;
import io.github.thebusybiscuit.slimefun4.implementation.SlimefunItems;
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.abstractItems.MachineFuel; import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.abstractItems.MachineFuel;

View File

@ -19,7 +19,6 @@ import io.github.thebusybiscuit.slimefun4.api.items.SlimefunItem;
import io.github.thebusybiscuit.slimefun4.api.items.SlimefunItemStack; import io.github.thebusybiscuit.slimefun4.api.items.SlimefunItemStack;
import io.github.thebusybiscuit.slimefun4.api.recipes.RecipeType; import io.github.thebusybiscuit.slimefun4.api.recipes.RecipeType;
import io.github.thebusybiscuit.slimefun4.core.handlers.ItemConsumptionHandler; import io.github.thebusybiscuit.slimefun4.core.handlers.ItemConsumptionHandler;
import io.github.thebusybiscuit.slimefun4.implementation.Slimefun;
import io.github.thebusybiscuit.slimefun4.implementation.items.SimpleSlimefunItem; import io.github.thebusybiscuit.slimefun4.implementation.items.SimpleSlimefunItem;
import io.github.thebusybiscuit.slimefun4.implementation.items.backpacks.Cooler; import io.github.thebusybiscuit.slimefun4.implementation.items.backpacks.Cooler;
import io.github.thebusybiscuit.slimefun4.implementation.listeners.CoolerListener; import io.github.thebusybiscuit.slimefun4.implementation.listeners.CoolerListener;

View File

@ -22,8 +22,8 @@ import org.bukkit.inventory.ItemStack;
import io.github.thebusybiscuit.slimefun4.api.items.ItemGroup; import io.github.thebusybiscuit.slimefun4.api.items.ItemGroup;
import io.github.thebusybiscuit.slimefun4.api.items.SlimefunItemStack; import io.github.thebusybiscuit.slimefun4.api.items.SlimefunItemStack;
import io.github.thebusybiscuit.slimefun4.core.multiblocks.MultiBlockMachine; import io.github.thebusybiscuit.slimefun4.core.multiblocks.MultiBlockMachine;
import io.github.thebusybiscuit.slimefun4.implementation.SlimefunItems;
import io.github.thebusybiscuit.slimefun4.implementation.Slimefun; import io.github.thebusybiscuit.slimefun4.implementation.Slimefun;
import io.github.thebusybiscuit.slimefun4.implementation.SlimefunItems;
import io.github.thebusybiscuit.slimefun4.utils.SlimefunUtils; import io.github.thebusybiscuit.slimefun4.utils.SlimefunUtils;
import io.papermc.lib.PaperLib; import io.papermc.lib.PaperLib;

View File

@ -33,8 +33,6 @@ import io.github.thebusybiscuit.slimefun4.implementation.items.multiblocks.Autom
import io.github.thebusybiscuit.slimefun4.implementation.settings.GoldPanDrop; import io.github.thebusybiscuit.slimefun4.implementation.settings.GoldPanDrop;
import io.github.thebusybiscuit.slimefun4.utils.SlimefunUtils; import io.github.thebusybiscuit.slimefun4.utils.SlimefunUtils;
/** /**
* A {@link GoldPan} is a {@link SlimefunItem} which allows you to obtain various * A {@link GoldPan} is a {@link SlimefunItem} which allows you to obtain various
* resources from Gravel. * resources from Gravel.

View File

@ -31,7 +31,7 @@ public class HerculesPickaxe extends SimpleSlimefunItem<ToolUseHandler> {
if (SlimefunTag.ORES.isTagged(mat)) { if (SlimefunTag.ORES.isTagged(mat)) {
if (Slimefun.getMinecraftVersion().isAtLeast(MinecraftVersion.MINECRAFT_1_17)) { if (Slimefun.getMinecraftVersion().isAtLeast(MinecraftVersion.MINECRAFT_1_17)) {
switch(mat) { switch (mat) {
case DEEPSLATE_IRON_ORE: case DEEPSLATE_IRON_ORE:
drops.add(new CustomItemStack(SlimefunItems.IRON_DUST, 2)); drops.add(new CustomItemStack(SlimefunItems.IRON_DUST, 2));
break; break;
@ -47,7 +47,7 @@ public class HerculesPickaxe extends SimpleSlimefunItem<ToolUseHandler> {
} }
} }
switch(mat) { switch (mat) {
case IRON_ORE: case IRON_ORE:
drops.add(new CustomItemStack(SlimefunItems.IRON_DUST, 2)); drops.add(new CustomItemStack(SlimefunItems.IRON_DUST, 2));
break; break;

View File

@ -56,9 +56,7 @@ public class ExplosiveBow extends SlimefunBow {
for (Entity nearby : entites) { for (Entity nearby : entites) {
LivingEntity entity = (LivingEntity) nearby; LivingEntity entity = (LivingEntity) nearby;
Vector distanceVector = entity.getLocation().toVector() Vector distanceVector = entity.getLocation().toVector().subtract(target.getLocation().toVector()).add(new Vector(0, 0.75, 0));
.subtract(target.getLocation().toVector())
.add(new Vector(0, 0.75, 0));
double distanceSquared = distanceVector.lengthSquared(); double distanceSquared = distanceVector.lengthSquared();
double damage = e.getDamage() * (1 - (distanceSquared / (2 * range.getValue() * range.getValue()))); double damage = e.getDamage() * (1 - (distanceSquared / (2 * range.getValue() * range.getValue())));

View File

@ -12,8 +12,8 @@ import org.bukkit.event.Listener;
import org.bukkit.event.entity.EntityDeathEvent; import org.bukkit.event.entity.EntityDeathEvent;
import org.bukkit.event.entity.PlayerDeathEvent; import org.bukkit.event.entity.PlayerDeathEvent;
import io.github.thebusybiscuit.slimefun4.implementation.SlimefunItems;
import io.github.thebusybiscuit.slimefun4.implementation.Slimefun; import io.github.thebusybiscuit.slimefun4.implementation.Slimefun;
import io.github.thebusybiscuit.slimefun4.implementation.SlimefunItems;
import io.github.thebusybiscuit.slimefun4.utils.SlimefunUtils; import io.github.thebusybiscuit.slimefun4.utils.SlimefunUtils;
/** /**

View File

@ -9,8 +9,8 @@ import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerToggleSneakEvent; import org.bukkit.event.player.PlayerToggleSneakEvent;
import io.github.thebusybiscuit.slimefun4.api.items.SlimefunItem; import io.github.thebusybiscuit.slimefun4.api.items.SlimefunItem;
import io.github.thebusybiscuit.slimefun4.implementation.SlimefunItems;
import io.github.thebusybiscuit.slimefun4.implementation.Slimefun; import io.github.thebusybiscuit.slimefun4.implementation.Slimefun;
import io.github.thebusybiscuit.slimefun4.implementation.SlimefunItems;
import io.github.thebusybiscuit.slimefun4.implementation.items.armor.Parachute; import io.github.thebusybiscuit.slimefun4.implementation.items.armor.Parachute;
import io.github.thebusybiscuit.slimefun4.implementation.items.electric.gadgets.JetBoots; import io.github.thebusybiscuit.slimefun4.implementation.items.electric.gadgets.JetBoots;
import io.github.thebusybiscuit.slimefun4.implementation.items.electric.gadgets.Jetpack; import io.github.thebusybiscuit.slimefun4.implementation.items.electric.gadgets.Jetpack;

View File

@ -21,8 +21,8 @@ import io.github.thebusybiscuit.slimefun4.api.events.PlayerRightClickEvent;
import io.github.thebusybiscuit.slimefun4.api.items.SlimefunItem; import io.github.thebusybiscuit.slimefun4.api.items.SlimefunItem;
import io.github.thebusybiscuit.slimefun4.core.handlers.BlockUseHandler; import io.github.thebusybiscuit.slimefun4.core.handlers.BlockUseHandler;
import io.github.thebusybiscuit.slimefun4.core.handlers.ItemUseHandler; import io.github.thebusybiscuit.slimefun4.core.handlers.ItemUseHandler;
import io.github.thebusybiscuit.slimefun4.implementation.SlimefunItems;
import io.github.thebusybiscuit.slimefun4.implementation.Slimefun; import io.github.thebusybiscuit.slimefun4.implementation.Slimefun;
import io.github.thebusybiscuit.slimefun4.implementation.SlimefunItems;
import io.github.thebusybiscuit.slimefun4.utils.SlimefunUtils; import io.github.thebusybiscuit.slimefun4.utils.SlimefunUtils;
import me.mrCookieSlime.Slimefun.api.BlockStorage; import me.mrCookieSlime.Slimefun.api.BlockStorage;

View File

@ -14,8 +14,8 @@ import org.bukkit.event.block.Action;
import org.bukkit.event.player.PlayerInteractEvent; import org.bukkit.event.player.PlayerInteractEvent;
import io.github.thebusybiscuit.slimefun4.api.items.SlimefunItem; import io.github.thebusybiscuit.slimefun4.api.items.SlimefunItem;
import io.github.thebusybiscuit.slimefun4.implementation.SlimefunItems;
import io.github.thebusybiscuit.slimefun4.implementation.Slimefun; import io.github.thebusybiscuit.slimefun4.implementation.Slimefun;
import io.github.thebusybiscuit.slimefun4.implementation.SlimefunItems;
import io.github.thebusybiscuit.slimefun4.implementation.items.elevator.ElevatorPlate; import io.github.thebusybiscuit.slimefun4.implementation.items.elevator.ElevatorPlate;
import io.github.thebusybiscuit.slimefun4.implementation.items.teleporter.AbstractTeleporterPlate; import io.github.thebusybiscuit.slimefun4.implementation.items.teleporter.AbstractTeleporterPlate;
import io.github.thebusybiscuit.slimefun4.implementation.items.teleporter.Teleporter; import io.github.thebusybiscuit.slimefun4.implementation.items.teleporter.Teleporter;

View File

@ -10,8 +10,8 @@ import org.bukkit.event.entity.EntityChangeBlockEvent;
import io.github.thebusybiscuit.slimefun4.api.items.SlimefunItem; import io.github.thebusybiscuit.slimefun4.api.items.SlimefunItem;
import io.github.thebusybiscuit.slimefun4.core.attributes.WitherProof; import io.github.thebusybiscuit.slimefun4.core.attributes.WitherProof;
import io.github.thebusybiscuit.slimefun4.implementation.SlimefunItems;
import io.github.thebusybiscuit.slimefun4.implementation.Slimefun; import io.github.thebusybiscuit.slimefun4.implementation.Slimefun;
import io.github.thebusybiscuit.slimefun4.implementation.SlimefunItems;
import me.mrCookieSlime.Slimefun.api.BlockStorage; import me.mrCookieSlime.Slimefun.api.BlockStorage;

View File

@ -26,8 +26,8 @@ import com.google.gson.JsonObject;
import com.google.gson.JsonParser; import com.google.gson.JsonParser;
import io.github.thebusybiscuit.slimefun4.api.items.SlimefunItem; import io.github.thebusybiscuit.slimefun4.api.items.SlimefunItem;
import io.github.thebusybiscuit.slimefun4.implementation.SlimefunItems;
import io.github.thebusybiscuit.slimefun4.implementation.Slimefun; import io.github.thebusybiscuit.slimefun4.implementation.Slimefun;
import io.github.thebusybiscuit.slimefun4.implementation.SlimefunItems;
import io.github.thebusybiscuit.slimefun4.implementation.items.multiblocks.GrindStone; import io.github.thebusybiscuit.slimefun4.implementation.items.multiblocks.GrindStone;
import io.github.thebusybiscuit.slimefun4.implementation.items.multiblocks.MakeshiftSmeltery; import io.github.thebusybiscuit.slimefun4.implementation.items.multiblocks.MakeshiftSmeltery;
import io.github.thebusybiscuit.slimefun4.implementation.items.multiblocks.OreCrusher; import io.github.thebusybiscuit.slimefun4.implementation.items.multiblocks.OreCrusher;

View File

@ -8,8 +8,8 @@ import org.bukkit.inventory.ItemStack;
import io.github.thebusybiscuit.slimefun4.api.items.SlimefunItem; import io.github.thebusybiscuit.slimefun4.api.items.SlimefunItem;
import io.github.thebusybiscuit.slimefun4.api.researches.Research; import io.github.thebusybiscuit.slimefun4.api.researches.Research;
import io.github.thebusybiscuit.slimefun4.implementation.SlimefunItems;
import io.github.thebusybiscuit.slimefun4.implementation.Slimefun; import io.github.thebusybiscuit.slimefun4.implementation.Slimefun;
import io.github.thebusybiscuit.slimefun4.implementation.SlimefunItems;
/** /**
* This static setup class is used to register all default implementations of * This static setup class is used to register all default implementations of

View File

@ -22,8 +22,8 @@ import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import io.github.thebusybiscuit.slimefun4.api.events.AncientAltarCraftEvent; import io.github.thebusybiscuit.slimefun4.api.events.AncientAltarCraftEvent;
import io.github.thebusybiscuit.slimefun4.implementation.SlimefunItems;
import io.github.thebusybiscuit.slimefun4.implementation.Slimefun; import io.github.thebusybiscuit.slimefun4.implementation.Slimefun;
import io.github.thebusybiscuit.slimefun4.implementation.SlimefunItems;
import io.github.thebusybiscuit.slimefun4.implementation.items.altar.AncientAltar; import io.github.thebusybiscuit.slimefun4.implementation.items.altar.AncientAltar;
import io.github.thebusybiscuit.slimefun4.implementation.items.altar.AncientPedestal; import io.github.thebusybiscuit.slimefun4.implementation.items.altar.AncientPedestal;
import io.github.thebusybiscuit.slimefun4.implementation.listeners.AncientAltarListener; import io.github.thebusybiscuit.slimefun4.implementation.listeners.AncientAltarListener;

View File

@ -23,8 +23,8 @@ import io.github.thebusybiscuit.slimefun4.api.items.SlimefunItemStack;
import io.github.thebusybiscuit.slimefun4.api.player.PlayerProfile; import io.github.thebusybiscuit.slimefun4.api.player.PlayerProfile;
import io.github.thebusybiscuit.slimefun4.core.attributes.ProtectionType; import io.github.thebusybiscuit.slimefun4.core.attributes.ProtectionType;
import io.github.thebusybiscuit.slimefun4.core.attributes.Radioactive; import io.github.thebusybiscuit.slimefun4.core.attributes.Radioactive;
import io.github.thebusybiscuit.slimefun4.implementation.SlimefunItems;
import io.github.thebusybiscuit.slimefun4.implementation.Slimefun; import io.github.thebusybiscuit.slimefun4.implementation.Slimefun;
import io.github.thebusybiscuit.slimefun4.implementation.SlimefunItems;
import io.github.thebusybiscuit.slimefun4.implementation.items.armor.SlimefunArmorPiece; import io.github.thebusybiscuit.slimefun4.implementation.items.armor.SlimefunArmorPiece;
import io.github.thebusybiscuit.slimefun4.implementation.items.electric.gadgets.SolarHelmet; import io.github.thebusybiscuit.slimefun4.implementation.items.electric.gadgets.SolarHelmet;
import io.github.thebusybiscuit.slimefun4.utils.SlimefunUtils; import io.github.thebusybiscuit.slimefun4.utils.SlimefunUtils;

View File

@ -10,8 +10,6 @@ import javax.annotation.Nonnull;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import javax.annotation.ParametersAreNonnullByDefault; import javax.annotation.ParametersAreNonnullByDefault;
import io.github.thebusybiscuit.slimefun4.core.debug.Debug;
import io.github.thebusybiscuit.slimefun4.core.debug.TestCase;
import org.apache.commons.lang.Validate; import org.apache.commons.lang.Validate;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.Location; import org.bukkit.Location;
@ -40,6 +38,8 @@ import io.github.thebusybiscuit.slimefun4.api.items.SlimefunItem;
import io.github.thebusybiscuit.slimefun4.api.items.SlimefunItemStack; import io.github.thebusybiscuit.slimefun4.api.items.SlimefunItemStack;
import io.github.thebusybiscuit.slimefun4.core.attributes.Radioactive; import io.github.thebusybiscuit.slimefun4.core.attributes.Radioactive;
import io.github.thebusybiscuit.slimefun4.core.attributes.Soulbound; import io.github.thebusybiscuit.slimefun4.core.attributes.Soulbound;
import io.github.thebusybiscuit.slimefun4.core.debug.Debug;
import io.github.thebusybiscuit.slimefun4.core.debug.TestCase;
import io.github.thebusybiscuit.slimefun4.implementation.Slimefun; import io.github.thebusybiscuit.slimefun4.implementation.Slimefun;
import io.github.thebusybiscuit.slimefun4.implementation.items.altar.AncientPedestal; import io.github.thebusybiscuit.slimefun4.implementation.items.altar.AncientPedestal;
import io.github.thebusybiscuit.slimefun4.implementation.tasks.CapacitorTextureUpdateTask; import io.github.thebusybiscuit.slimefun4.implementation.tasks.CapacitorTextureUpdateTask;
@ -306,16 +306,12 @@ public final class SlimefunUtils {
Debug.log(TestCase.CARGO_INPUT_TESTING, " Item IDs matched!"); Debug.log(TestCase.CARGO_INPUT_TESTING, " Item IDs matched!");
return true; return true;
} else { } else {
Debug.log(TestCase.CARGO_INPUT_TESTING, " Item IDs don't match, checking meta {} == {} (lore: {})", Debug.log(TestCase.CARGO_INPUT_TESTING, " Item IDs don't match, checking meta {} == {} (lore: {})", itemMeta, possibleSfItemMeta, checkLore);
itemMeta, possibleSfItemMeta, checkLore
);
return equalsItemMeta(itemMeta, possibleSfItemMeta, checkLore); return equalsItemMeta(itemMeta, possibleSfItemMeta, checkLore);
} }
} else if (sfitem.hasItemMeta()) { } else if (sfitem.hasItemMeta()) {
ItemMeta sfItemMeta = sfitem.getItemMeta(); ItemMeta sfItemMeta = sfitem.getItemMeta();
Debug.log(TestCase.CARGO_INPUT_TESTING, " Comparing meta (vanilla items?) - {} == {} (lore: {})", Debug.log(TestCase.CARGO_INPUT_TESTING, " Comparing meta (vanilla items?) - {} == {} (lore: {})", itemMeta, sfItemMeta, checkLore);
itemMeta, sfItemMeta, checkLore
);
return equalsItemMeta(itemMeta, sfItemMeta, checkLore); return equalsItemMeta(itemMeta, sfItemMeta, checkLore);
} else { } else {
return false; return false;

View File

@ -18,8 +18,8 @@ import org.junit.jupiter.api.Order;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestMethodOrder; import org.junit.jupiter.api.TestMethodOrder;
import io.github.thebusybiscuit.slimefun4.implementation.SlimefunItems;
import io.github.thebusybiscuit.slimefun4.implementation.Slimefun; import io.github.thebusybiscuit.slimefun4.implementation.Slimefun;
import io.github.thebusybiscuit.slimefun4.implementation.SlimefunItems;
import io.github.thebusybiscuit.slimefun4.implementation.resources.GEOResourcesSetup; import io.github.thebusybiscuit.slimefun4.implementation.resources.GEOResourcesSetup;
import io.github.thebusybiscuit.slimefun4.utils.SlimefunUtils; import io.github.thebusybiscuit.slimefun4.utils.SlimefunUtils;

View File

@ -1,9 +1,9 @@
package io.github.thebusybiscuit.slimefun4.api.items.settings; package io.github.thebusybiscuit.slimefun4.api.items.settings;
import java.util.Arrays; import java.util.Arrays;
import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import java.util.HashSet;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.Tag; import org.bukkit.Tag;

View File

@ -8,8 +8,8 @@ import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ValueSource; import org.junit.jupiter.params.provider.ValueSource;
import io.github.thebusybiscuit.slimefun4.implementation.SlimefunItems;
import io.github.thebusybiscuit.slimefun4.implementation.Slimefun; import io.github.thebusybiscuit.slimefun4.implementation.Slimefun;
import io.github.thebusybiscuit.slimefun4.implementation.SlimefunItems;
import io.github.thebusybiscuit.slimefun4.utils.SlimefunUtils; import io.github.thebusybiscuit.slimefun4.utils.SlimefunUtils;
import be.seeseemelk.mockbukkit.MockBukkit; import be.seeseemelk.mockbukkit.MockBukkit;

View File

@ -0,0 +1,136 @@
package io.github.thebusybiscuit.slimefun4.core.debug;
import java.text.MessageFormat;
import java.util.logging.Handler;
import java.util.logging.LogRecord;
import javax.annotation.Nonnull;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import io.github.thebusybiscuit.slimefun4.implementation.Slimefun;
import be.seeseemelk.mockbukkit.MockBukkit;
class TestDebugLogging {
private final String testCase = "unit-test";
private String lastLogMessage = null;
@BeforeEach
void load() {
MockBukkit.mock();
MockBukkit.load(Slimefun.class);
// Attach a custom handler to catch logged messages
Slimefun.logger().addHandler(new Handler() {
@Override
public void publish(@Nonnull LogRecord record) {
// We need to apply formatting too
lastLogMessage = MessageFormat.format(record.getMessage(), record.getParameters());
}
@Override
public void flush() {}
@Override
public void close() throws SecurityException {}
});
}
@AfterEach
void unload() {
MockBukkit.unmock();
// Clean up afterwards
Debug.setTestCase(null);
}
@Test
@DisplayName("Test logging with no test case")
void testLoggingNoTestCase() {
Debug.setTestCase(null);
String msg = "Ramen is delicious";
Debug.log(testCase, msg);
Assertions.assertNull(lastLogMessage);
}
@Test
@DisplayName("Test logging with different test case")
void testLoggingWithDifferentTestCase() {
Debug.setTestCase("different-test-case");
String msg = "Ramen is delicious";
Debug.log(testCase, msg);
Assertions.assertNull(lastLogMessage);
}
@Test
@DisplayName("Test log message")
void testMessage() {
Debug.setTestCase(testCase);
Assertions.assertEquals(testCase, Debug.getTestCase());
String msg = "Ramen is delicious";
Debug.log(testCase, msg);
Assertions.assertNotNull(lastLogMessage);
Assertions.assertTrue(lastLogMessage.endsWith(msg));
}
@Test
@DisplayName("Test log message with single parameter")
void testMessageWithSingleParam() {
Debug.setTestCase(testCase);
Assertions.assertEquals(testCase, Debug.getTestCase());
String pattern = "{} is delicious";
String result = "Sushi is delicious";
Debug.log(testCase, pattern, "Sushi");
Assertions.assertNotNull(lastLogMessage);
Assertions.assertTrue(lastLogMessage.endsWith(result));
}
@Test
@DisplayName("Test log message with multiple parameters")
void testMessageWithParams() {
Debug.setTestCase(testCase);
Assertions.assertEquals(testCase, Debug.getTestCase());
String pattern = "{} is delicious and {} likes it!";
String result = "Sushi is delicious and TheBusyBiscuit likes it!";
Debug.log(testCase, pattern, "Sushi", "TheBusyBiscuit");
Assertions.assertNotNull(lastLogMessage);
Assertions.assertTrue(lastLogMessage.endsWith(result));
}
@Test
@DisplayName("Test log message with lookalike pattern")
void testMessageAwkwardPattern() {
Debug.setTestCase(testCase);
Assertions.assertEquals(testCase, Debug.getTestCase());
/*
* If our formatter trips up, the test will fail
* with an IndexOutOfBoundsException.
* Normally, this should pass though.
*/
String msg = "{Ramen} is} {delicious }{";
Debug.log(testCase, msg);
Assertions.assertNotNull(lastLogMessage);
Assertions.assertTrue(lastLogMessage.endsWith(msg));
}
}

View File

@ -8,8 +8,8 @@ import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import io.github.thebusybiscuit.slimefun4.api.events.WaypointCreateEvent; import io.github.thebusybiscuit.slimefun4.api.events.WaypointCreateEvent;
import io.github.thebusybiscuit.slimefun4.implementation.SlimefunItems;
import io.github.thebusybiscuit.slimefun4.implementation.Slimefun; import io.github.thebusybiscuit.slimefun4.implementation.Slimefun;
import io.github.thebusybiscuit.slimefun4.implementation.SlimefunItems;
import io.github.thebusybiscuit.slimefun4.test.TestUtilities; import io.github.thebusybiscuit.slimefun4.test.TestUtilities;
import be.seeseemelk.mockbukkit.MockBukkit; import be.seeseemelk.mockbukkit.MockBukkit;

View File

@ -14,8 +14,8 @@ import org.bukkit.inventory.ItemStack;
import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import io.github.bakedlibs.dough.items.CustomItemStack; import io.github.bakedlibs.dough.items.CustomItemStack;
import io.github.thebusybiscuit.slimefun4.api.items.SlimefunItem; import io.github.thebusybiscuit.slimefun4.api.items.SlimefunItem;