mirror of
https://github.com/StarWishsama/Slimefun4.git
synced 2024-09-19 19:25:48 +00:00
[CI skip] Added unit test for new debugging tool
This commit is contained in:
parent
ee43db9388
commit
008090cc6f
@ -4,8 +4,8 @@ import org.bukkit.block.Block;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
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.networks.cargo.CargoNet;
|
||||
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.EasterEgg;
|
||||
|
@ -1,12 +1,13 @@
|
||||
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.SubCommand;
|
||||
import io.github.thebusybiscuit.slimefun4.core.debug.Debug;
|
||||
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.
|
||||
@ -35,9 +36,7 @@ public class DebugCommand extends SubCommand {
|
||||
if (args.length == 1) {
|
||||
String currentCase = Debug.getTestCase();
|
||||
if (currentCase != null) {
|
||||
Slimefun.getLocalization().sendMessage(sender, "commands.debug.current", true,
|
||||
msg -> msg.replace("%test_case%", currentCase)
|
||||
);
|
||||
Slimefun.getLocalization().sendMessage(sender, "commands.debug.current", true, msg -> msg.replace("%test_case%", currentCase));
|
||||
} else {
|
||||
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");
|
||||
} else {
|
||||
Debug.setTestCase(test);
|
||||
Slimefun.getLocalization().sendMessage(sender, "commands.debug.running",
|
||||
msg -> msg.replace("%test%", test));
|
||||
Slimefun.getLocalization().sendMessage(sender, "commands.debug.running", msg -> msg.replace("%test%", test));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -7,8 +7,8 @@ import org.bukkit.entity.Player;
|
||||
|
||||
import io.github.thebusybiscuit.slimefun4.core.commands.SlimefunCommand;
|
||||
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.SlimefunItems;
|
||||
|
||||
class DebugFishCommand extends SubCommand {
|
||||
|
||||
|
@ -1,10 +1,11 @@
|
||||
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.Nullable;
|
||||
import java.util.logging.Level;
|
||||
|
||||
import io.github.thebusybiscuit.slimefun4.implementation.Slimefun;
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*
|
||||
* @param testCase The {@link TestCase} to use
|
||||
* @param msg The message to log
|
||||
* @param testCase
|
||||
* The {@link TestCase} to use
|
||||
* @param msg
|
||||
* The message to log
|
||||
*/
|
||||
public static void log(@Nonnull TestCase testCase, @Nonnull String msg) {
|
||||
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.
|
||||
*
|
||||
* @param testCase The {@link TestCase} to use
|
||||
* @param msg The message to log
|
||||
* @param vars The variables to replace, use "{}" in the message and have it replaced with a specified thing
|
||||
* @param testCase
|
||||
* The {@link TestCase} to use
|
||||
* @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) {
|
||||
log(testCase.toString(), msg, vars);
|
||||
@ -44,8 +50,10 @@ public final class Debug {
|
||||
/**
|
||||
* Log a message if the test case is currently enabled.
|
||||
*
|
||||
* @param test The test case to use
|
||||
* @param msg The message to log
|
||||
* @param test
|
||||
* The test case to use
|
||||
* @param msg
|
||||
* The message to log
|
||||
*/
|
||||
public static void log(@Nonnull String test, @Nonnull String msg) {
|
||||
log(test, msg, new Object[0]);
|
||||
@ -54,18 +62,23 @@ public final class Debug {
|
||||
/**
|
||||
* Log a message if the test case is currently enabled.
|
||||
*
|
||||
* @param test The test case to use
|
||||
* @param msg The message to log
|
||||
* @param vars The variables to replace, use "{}" in the message and have it replaced with a specified thing
|
||||
* @param test
|
||||
* The test case to use
|
||||
* @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) {
|
||||
if (testCase == null || !testCase.equals(test)) return;
|
||||
if (testCase == null || !testCase.equals(test)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (vars.length > 0) {
|
||||
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 {
|
||||
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
|
||||
* </code>
|
||||
*
|
||||
* @param msg The message to send. For variables, you can pass "{}"
|
||||
* @param vars A varargs of the variables you wish to use
|
||||
* @param msg
|
||||
* The message to send. For variables, you can pass "{}"
|
||||
* @param vars
|
||||
* A varargs of the variables you wish to use
|
||||
*
|
||||
* @return The resulting String
|
||||
*/
|
||||
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 `}`
|
||||
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
|
||||
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;
|
||||
@ -99,7 +116,8 @@ public final class Debug {
|
||||
* 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.
|
||||
*
|
||||
* @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) {
|
||||
testCase = test;
|
||||
|
@ -1,8 +1,9 @@
|
||||
package io.github.thebusybiscuit.slimefun4.core.debug;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.util.Locale;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
/**
|
||||
* 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>}
|
||||
|
@ -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
|
||||
*
|
||||
* @param outputItem
|
||||
* A crafted {@link ItemStack} from {@link MultiBlockMachine}
|
||||
* A crafted {@link ItemStack} from {@link MultiBlockMachine}
|
||||
* @param block
|
||||
* Main {@link Block} of our {@link Container} from {@link MultiBlockMachine}
|
||||
* Main {@link Block} of our {@link Container} from {@link MultiBlockMachine}
|
||||
* @param blockInv
|
||||
* The {@link Inventory} of our {@link Container}
|
||||
* The {@link Inventory} of our {@link Container}
|
||||
*
|
||||
*/
|
||||
@ParametersAreNonnullByDefault
|
||||
|
@ -5,8 +5,6 @@ import java.util.Map;
|
||||
import javax.annotation.Nonnull;
|
||||
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.Material;
|
||||
import org.bukkit.Tag;
|
||||
@ -19,6 +17,8 @@ import org.bukkit.inventory.InventoryHolder;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
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.utils.SlimefunUtils;
|
||||
import io.github.thebusybiscuit.slimefun4.utils.itemstack.ItemStackWrapper;
|
||||
|
@ -7,13 +7,13 @@ import java.util.function.Predicate;
|
||||
|
||||
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.block.Block;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
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.utils.SlimefunUtils;
|
||||
import io.github.thebusybiscuit.slimefun4.utils.itemstack.ItemStackWrapper;
|
||||
|
@ -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.EnergyNetProvider;
|
||||
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.SlimefunItems;
|
||||
import io.github.thebusybiscuit.slimefun4.utils.NumberUtils;
|
||||
|
||||
import me.mrCookieSlime.CSCoreLibPlugin.Configuration.Config;
|
||||
|
@ -46,7 +46,7 @@ public class CheatSheetSlimefunGuide extends SurvivalSlimefunGuide {
|
||||
* The {@link Player} who opened his {@link SlimefunGuide}
|
||||
* @param profile
|
||||
* The {@link PlayerProfile} of the {@link Player}
|
||||
*
|
||||
*
|
||||
* @return a {@link List} of visible {@link ItemGroup} instances
|
||||
*/
|
||||
@Override
|
||||
|
@ -318,7 +318,7 @@ public class SurvivalSlimefunGuide implements SlimefunGuideImplementation {
|
||||
if (action.isShiftClicked()) {
|
||||
clonedItem.setAmount(clonedItem.getMaxStackSize());
|
||||
}
|
||||
|
||||
|
||||
pl.getInventory().addItem(clonedItem);
|
||||
}
|
||||
}
|
||||
|
@ -41,7 +41,7 @@ public class FarmerAndroid extends ProgrammableAndroid {
|
||||
if (!block.getWorld().getWorldBorder().isInside(block.getLocation())) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
if (data instanceof Ageable && ((Ageable) data).getAge() >= ((Ageable) data).getMaximumAge()) {
|
||||
drop = getDropFromCrop(blockType);
|
||||
}
|
||||
|
@ -125,13 +125,13 @@ public class MinerAndroid extends ProgrammableAndroid {
|
||||
|
||||
@ParametersAreNonnullByDefault
|
||||
private void breakBlock(BlockMenu menu, Collection<ItemStack> drops, Block block) {
|
||||
|
||||
|
||||
if (!block.getWorld().getWorldBorder().isInside(block.getLocation())) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
block.getWorld().playEffect(block.getLocation(), Effect.STEP_SOUND, block.getType());
|
||||
|
||||
|
||||
// Push our drops to the inventory
|
||||
for (ItemStack drop : drops) {
|
||||
menu.pushItem(drop, getOutputSlots());
|
||||
|
@ -890,11 +890,11 @@ public class ProgrammableAndroid extends SlimefunItem implements InventoryBlock,
|
||||
@ParametersAreNonnullByDefault
|
||||
protected void move(Block b, BlockFace face, Block block) {
|
||||
if (block.getY() > 0 && block.getY() < block.getWorld().getMaxHeight() && block.isEmpty()) {
|
||||
|
||||
|
||||
if (!block.getWorld().getWorldBorder().isInside(block.getLocation())) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
BlockData blockData = Material.PLAYER_HEAD.createBlockData(data -> {
|
||||
if (data instanceof Rotatable) {
|
||||
Rotatable rotatable = ((Rotatable) data);
|
||||
|
@ -49,7 +49,7 @@ public class WoodcutterAndroid extends ProgrammableAndroid {
|
||||
if (!target.getWorld().getWorldBorder().isInside(target.getLocation())) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
if (Tag.LOGS.isTagged(target.getType())) {
|
||||
List<Block> list = Vein.find(target, MAX_REACH, block -> Tag.LOGS.isTagged(block.getType()));
|
||||
|
||||
|
@ -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.SlimefunItemStack;
|
||||
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.SlimefunItems;
|
||||
|
||||
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.abstractItems.AGenerator;
|
||||
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.abstractItems.MachineFuel;
|
||||
|
@ -8,8 +8,8 @@ import org.bukkit.inventory.ItemStack;
|
||||
import io.github.thebusybiscuit.slimefun4.api.items.ItemGroup;
|
||||
import io.github.thebusybiscuit.slimefun4.api.items.SlimefunItemStack;
|
||||
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.SlimefunItems;
|
||||
import io.github.thebusybiscuit.slimefun4.implementation.items.multiblocks.OreWasher;
|
||||
import io.github.thebusybiscuit.slimefun4.utils.SlimefunUtils;
|
||||
|
||||
|
@ -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.core.attributes.NotHopperable;
|
||||
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.SlimefunItems;
|
||||
|
||||
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.abstractItems.AContainer;
|
||||
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.abstractItems.MachineRecipe;
|
||||
|
@ -40,7 +40,7 @@ import me.mrCookieSlime.Slimefun.api.inventory.BlockMenu;
|
||||
*/
|
||||
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
|
||||
public AutoEnchanter(ItemGroup itemGroup, SlimefunItemStack item, RecipeType recipeType, ItemStack[] recipe) {
|
||||
|
@ -14,8 +14,8 @@ import org.bukkit.potion.PotionEffectType;
|
||||
import io.github.thebusybiscuit.slimefun4.api.items.ItemGroup;
|
||||
import io.github.thebusybiscuit.slimefun4.api.items.SlimefunItemStack;
|
||||
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.SlimefunItems;
|
||||
|
||||
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.abstractItems.MachineFuel;
|
||||
|
||||
|
@ -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.recipes.RecipeType;
|
||||
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.backpacks.Cooler;
|
||||
import io.github.thebusybiscuit.slimefun4.implementation.listeners.CoolerListener;
|
||||
|
@ -22,8 +22,8 @@ import org.bukkit.inventory.ItemStack;
|
||||
import io.github.thebusybiscuit.slimefun4.api.items.ItemGroup;
|
||||
import io.github.thebusybiscuit.slimefun4.api.items.SlimefunItemStack;
|
||||
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.SlimefunItems;
|
||||
import io.github.thebusybiscuit.slimefun4.utils.SlimefunUtils;
|
||||
import io.papermc.lib.PaperLib;
|
||||
|
||||
|
@ -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.utils.SlimefunUtils;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* A {@link GoldPan} is a {@link SlimefunItem} which allows you to obtain various
|
||||
* resources from Gravel.
|
||||
|
@ -31,7 +31,7 @@ public class HerculesPickaxe extends SimpleSlimefunItem<ToolUseHandler> {
|
||||
|
||||
if (SlimefunTag.ORES.isTagged(mat)) {
|
||||
if (Slimefun.getMinecraftVersion().isAtLeast(MinecraftVersion.MINECRAFT_1_17)) {
|
||||
switch(mat) {
|
||||
switch (mat) {
|
||||
case DEEPSLATE_IRON_ORE:
|
||||
drops.add(new CustomItemStack(SlimefunItems.IRON_DUST, 2));
|
||||
break;
|
||||
@ -47,7 +47,7 @@ public class HerculesPickaxe extends SimpleSlimefunItem<ToolUseHandler> {
|
||||
}
|
||||
}
|
||||
|
||||
switch(mat) {
|
||||
switch (mat) {
|
||||
case IRON_ORE:
|
||||
drops.add(new CustomItemStack(SlimefunItems.IRON_DUST, 2));
|
||||
break;
|
||||
|
@ -56,9 +56,7 @@ public class ExplosiveBow extends SlimefunBow {
|
||||
for (Entity nearby : entites) {
|
||||
LivingEntity entity = (LivingEntity) nearby;
|
||||
|
||||
Vector distanceVector = entity.getLocation().toVector()
|
||||
.subtract(target.getLocation().toVector())
|
||||
.add(new Vector(0, 0.75, 0));
|
||||
Vector distanceVector = entity.getLocation().toVector().subtract(target.getLocation().toVector()).add(new Vector(0, 0.75, 0));
|
||||
|
||||
double distanceSquared = distanceVector.lengthSquared();
|
||||
double damage = e.getDamage() * (1 - (distanceSquared / (2 * range.getValue() * range.getValue())));
|
||||
|
@ -12,8 +12,8 @@ import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.entity.EntityDeathEvent;
|
||||
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.SlimefunItems;
|
||||
import io.github.thebusybiscuit.slimefun4.utils.SlimefunUtils;
|
||||
|
||||
/**
|
||||
|
@ -9,8 +9,8 @@ import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerToggleSneakEvent;
|
||||
|
||||
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.SlimefunItems;
|
||||
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.Jetpack;
|
||||
|
@ -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.core.handlers.BlockUseHandler;
|
||||
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.SlimefunItems;
|
||||
import io.github.thebusybiscuit.slimefun4.utils.SlimefunUtils;
|
||||
|
||||
import me.mrCookieSlime.Slimefun.api.BlockStorage;
|
||||
|
@ -14,8 +14,8 @@ import org.bukkit.event.block.Action;
|
||||
import org.bukkit.event.player.PlayerInteractEvent;
|
||||
|
||||
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.SlimefunItems;
|
||||
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.Teleporter;
|
||||
|
@ -10,8 +10,8 @@ import org.bukkit.event.entity.EntityChangeBlockEvent;
|
||||
|
||||
import io.github.thebusybiscuit.slimefun4.api.items.SlimefunItem;
|
||||
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.SlimefunItems;
|
||||
|
||||
import me.mrCookieSlime.Slimefun.api.BlockStorage;
|
||||
|
||||
|
@ -26,8 +26,8 @@ import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonParser;
|
||||
|
||||
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.SlimefunItems;
|
||||
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.OreCrusher;
|
||||
|
@ -8,8 +8,8 @@ import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import io.github.thebusybiscuit.slimefun4.api.items.SlimefunItem;
|
||||
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.SlimefunItems;
|
||||
|
||||
/**
|
||||
* This static setup class is used to register all default implementations of
|
||||
|
@ -22,8 +22,8 @@ import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
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.SlimefunItems;
|
||||
import io.github.thebusybiscuit.slimefun4.implementation.items.altar.AncientAltar;
|
||||
import io.github.thebusybiscuit.slimefun4.implementation.items.altar.AncientPedestal;
|
||||
import io.github.thebusybiscuit.slimefun4.implementation.listeners.AncientAltarListener;
|
||||
|
@ -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.core.attributes.ProtectionType;
|
||||
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.SlimefunItems;
|
||||
import io.github.thebusybiscuit.slimefun4.implementation.items.armor.SlimefunArmorPiece;
|
||||
import io.github.thebusybiscuit.slimefun4.implementation.items.electric.gadgets.SolarHelmet;
|
||||
import io.github.thebusybiscuit.slimefun4.utils.SlimefunUtils;
|
||||
|
@ -10,8 +10,6 @@ import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
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.bukkit.ChatColor;
|
||||
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.core.attributes.Radioactive;
|
||||
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.items.altar.AncientPedestal;
|
||||
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!");
|
||||
return true;
|
||||
} else {
|
||||
Debug.log(TestCase.CARGO_INPUT_TESTING, " Item IDs don't match, checking meta {} == {} (lore: {})",
|
||||
itemMeta, possibleSfItemMeta, checkLore
|
||||
);
|
||||
Debug.log(TestCase.CARGO_INPUT_TESTING, " Item IDs don't match, checking meta {} == {} (lore: {})", itemMeta, possibleSfItemMeta, checkLore);
|
||||
return equalsItemMeta(itemMeta, possibleSfItemMeta, checkLore);
|
||||
}
|
||||
} else if (sfitem.hasItemMeta()) {
|
||||
ItemMeta sfItemMeta = sfitem.getItemMeta();
|
||||
Debug.log(TestCase.CARGO_INPUT_TESTING, " Comparing meta (vanilla items?) - {} == {} (lore: {})",
|
||||
itemMeta, sfItemMeta, checkLore
|
||||
);
|
||||
Debug.log(TestCase.CARGO_INPUT_TESTING, " Comparing meta (vanilla items?) - {} == {} (lore: {})", itemMeta, sfItemMeta, checkLore);
|
||||
return equalsItemMeta(itemMeta, sfItemMeta, checkLore);
|
||||
} else {
|
||||
return false;
|
||||
|
@ -18,8 +18,8 @@ import org.junit.jupiter.api.Order;
|
||||
import org.junit.jupiter.api.Test;
|
||||
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.SlimefunItems;
|
||||
import io.github.thebusybiscuit.slimefun4.implementation.resources.GEOResourcesSetup;
|
||||
import io.github.thebusybiscuit.slimefun4.utils.SlimefunUtils;
|
||||
|
||||
|
@ -1,9 +1,9 @@
|
||||
package io.github.thebusybiscuit.slimefun4.api.items.settings;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.HashSet;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.Tag;
|
||||
|
@ -8,8 +8,8 @@ import org.junit.jupiter.api.DisplayName;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
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.SlimefunItems;
|
||||
import io.github.thebusybiscuit.slimefun4.utils.SlimefunUtils;
|
||||
|
||||
import be.seeseemelk.mockbukkit.MockBukkit;
|
||||
|
@ -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));
|
||||
}
|
||||
|
||||
}
|
@ -8,8 +8,8 @@ import org.junit.jupiter.api.DisplayName;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
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.SlimefunItems;
|
||||
import io.github.thebusybiscuit.slimefun4.test.TestUtilities;
|
||||
|
||||
import be.seeseemelk.mockbukkit.MockBukkit;
|
||||
|
@ -14,8 +14,8 @@ import org.bukkit.inventory.ItemStack;
|
||||
import org.junit.jupiter.api.AfterAll;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.DisplayName;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import io.github.bakedlibs.dough.items.CustomItemStack;
|
||||
import io.github.thebusybiscuit.slimefun4.api.items.SlimefunItem;
|
||||
|
Loading…
Reference in New Issue
Block a user