mirror of
https://github.com/StarWishsama/Slimefun4.git
synced 2024-09-20 03:35:51 +00:00
Merge branch 'master' into experimental
This commit is contained in:
commit
dba52edc47
32
pom.xml
32
pom.xml
@ -13,7 +13,7 @@
|
||||
<inceptionYear>2013</inceptionYear>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<description>Slimefun is a Spigot plugin that simulates a modpack-like atmosphere by adding over 500 new items and recipes to your Minecraft Server.</description>
|
||||
<description>Slimefun is a Spigot/Paper plugin that simulates a modpack-like atmosphere by adding over 500 new items and recipes to your Minecraft Server.</description>
|
||||
<url>https://github.com/TheBusyBiscuit/Slimefun4</url>
|
||||
|
||||
<properties>
|
||||
@ -47,16 +47,6 @@
|
||||
</licenses>
|
||||
|
||||
<repositories>
|
||||
<repository>
|
||||
<id>sonatype-snapshots</id>
|
||||
<url>http://oss.sonatype.org/content/repositories/snapshots</url>
|
||||
<releases>
|
||||
<enabled>false</enabled>
|
||||
</releases>
|
||||
<snapshots>
|
||||
<enabled>true</enabled>
|
||||
</snapshots>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>jitpack.io</id>
|
||||
<url>https://jitpack.io</url>
|
||||
@ -221,7 +211,7 @@
|
||||
<detectOfflineLinks>false</detectOfflineLinks>
|
||||
<additionalJOption>-html5</additionalJOption>
|
||||
|
||||
<!-- We can reference Bukkit's API in our Javadocs -->
|
||||
<!-- We can reference the Spigot API in our Javadocs -->
|
||||
<links>
|
||||
<link>${spigot.javadocs}</link>
|
||||
</links>
|
||||
@ -313,8 +303,8 @@
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.github.seeseemelk</groupId>
|
||||
<artifactId>MockBukkit-v1.15</artifactId>
|
||||
<version>0.3.1-SNAPSHOT</version>
|
||||
<artifactId>MockBukkit-v1.16</artifactId>
|
||||
<version>0.4.0</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
@ -337,10 +327,17 @@
|
||||
<version>1.7</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.papermc</groupId>
|
||||
<artifactId>paperlib</artifactId>
|
||||
<version>1.0.5</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.konghq</groupId>
|
||||
<artifactId>unirest-java</artifactId>
|
||||
<version>3.10.00</version>
|
||||
<scope>compile</scope>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>com.google.code.gson</groupId>
|
||||
@ -348,12 +345,6 @@
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.papermc</groupId>
|
||||
<artifactId>paperlib</artifactId>
|
||||
<version>1.0.5</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
|
||||
<!-- Third party plugin integrations -->
|
||||
<dependency>
|
||||
@ -370,7 +361,6 @@
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>me.clip</groupId>
|
||||
<artifactId>placeholderapi</artifactId>
|
||||
|
@ -0,0 +1,28 @@
|
||||
package io.github.thebusybiscuit.slimefun4.api.items;
|
||||
|
||||
import org.apache.commons.lang.Validate;
|
||||
|
||||
public class RangedItemSetting extends ItemSetting<Integer> {
|
||||
|
||||
private final int min;
|
||||
private final int max;
|
||||
|
||||
public RangedItemSetting(String key, int min, int defaultValue, int max) {
|
||||
super(key, defaultValue);
|
||||
|
||||
this.min = min;
|
||||
this.max = max;
|
||||
|
||||
Validate.isTrue(defaultValue >= min && defaultValue <= max, "The default value must be equal to or inbetween the minimum and maximum.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean validateInput(Integer input) {
|
||||
return super.validateInput(input) && input.intValue() >= min && input.intValue() <= max;
|
||||
}
|
||||
|
||||
public int getIntValue() {
|
||||
return getValue().intValue();
|
||||
}
|
||||
|
||||
}
|
@ -1,6 +1,5 @@
|
||||
package io.github.thebusybiscuit.slimefun4.core.services;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.Method;
|
||||
@ -11,6 +10,10 @@ import java.nio.file.StandardCopyOption;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.logging.Level;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin;
|
||||
import io.github.thebusybiscuit.slimefun4.utils.PatternUtils;
|
||||
import kong.unirest.GetRequest;
|
||||
@ -19,7 +22,6 @@ import kong.unirest.JsonNode;
|
||||
import kong.unirest.Unirest;
|
||||
import kong.unirest.UnirestException;
|
||||
import me.mrCookieSlime.Slimefun.api.Slimefun;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
/**
|
||||
* This Class represents a Metrics Service that sends data to https://bstats.org/
|
||||
@ -31,7 +33,6 @@ import org.bukkit.plugin.Plugin;
|
||||
* @author WalshyDev
|
||||
*/
|
||||
public class MetricsService {
|
||||
|
||||
|
||||
private static final String API_URL = "https://api.github.com/";
|
||||
private static final String REPO_NAME = "MetricsModule";
|
||||
|
@ -165,6 +165,7 @@ public final class SlimefunPlugin extends JavaPlugin implements SlimefunAddon {
|
||||
if (minecraftVersion == MinecraftVersion.UNIT_TEST) {
|
||||
local = new LocalizationService(this, "", null);
|
||||
gpsNetwork = new GPSNetwork();
|
||||
networkManager = new NetworkManager(200);
|
||||
command.register();
|
||||
registry.load(config);
|
||||
}
|
||||
|
@ -44,13 +44,15 @@ public abstract class AbstractEnergyProvider extends SlimefunItem implements Inv
|
||||
|
||||
/**
|
||||
* This method returns the title that is used for the {@link Inventory} of an
|
||||
* {@link AGenerator} that has been opened by a Player.
|
||||
* {@link AbstractEnergyProvider} that has been opened by a Player.
|
||||
*
|
||||
* Override this method to set the title.
|
||||
*
|
||||
* @return The title of the {@link Inventory} of this {@link AGenerator}
|
||||
* @return The title of the {@link Inventory} of this {@link AbstractEnergyProvider}
|
||||
*/
|
||||
public abstract String getInventoryTitle();
|
||||
public String getInventoryTitle() {
|
||||
return getItemName();
|
||||
}
|
||||
|
||||
/**
|
||||
* This method returns the {@link ItemStack} that this {@link AGenerator} will
|
||||
|
@ -96,9 +96,4 @@ public abstract class BioGenerator extends AGenerator {
|
||||
return new ItemStack(Material.GOLDEN_HOE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getInventoryTitle() {
|
||||
return "&2Bio Reactor";
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -42,9 +42,4 @@ public abstract class CoalGenerator extends AGenerator {
|
||||
return new ItemStack(Material.FLINT_AND_STEEL);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getInventoryTitle() {
|
||||
return "&cCoal Generator";
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -27,9 +27,4 @@ public abstract class CombustionGenerator extends AGenerator {
|
||||
return new ItemStack(Material.FLINT_AND_STEEL);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getInventoryTitle() {
|
||||
return "&cCombustion Reactor";
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -25,9 +25,4 @@ public abstract class LavaGenerator extends AGenerator {
|
||||
return new ItemStack(Material.FLINT_AND_STEEL);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getInventoryTitle() {
|
||||
return "&4Lava Generator";
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -26,9 +26,4 @@ public abstract class MagnesiumGenerator extends AGenerator {
|
||||
return new ItemStack(Material.FLINT_AND_STEEL);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getInventoryTitle() {
|
||||
return "&cMagnesium-powered Generator";
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -32,11 +32,6 @@ public abstract class NetherStarReactor extends Reactor {
|
||||
super(category, item, recipeType, recipe);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getInventoryTitle() {
|
||||
return "Nether Star Reactor";
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void registerDefaultFuelTypes() {
|
||||
registerFuel(new MachineFuel(1800, new ItemStack(Material.NETHER_STAR)));
|
||||
|
@ -26,11 +26,6 @@ public abstract class NuclearReactor extends Reactor {
|
||||
super(category, item, recipeType, recipe);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getInventoryTitle() {
|
||||
return "&2Nuclear Reactor";
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void registerDefaultFuelTypes() {
|
||||
registerFuel(new MachineFuel(1200, SlimefunItems.URANIUM, SlimefunItems.NEPTUNIUM));
|
||||
|
@ -180,17 +180,17 @@ public abstract class Reactor extends AbstractEnergyProvider {
|
||||
|
||||
preset.addItem(22, new CustomItem(new ItemStack(Material.BLACK_STAINED_GLASS_PANE), " "), ChestMenuUtils.getEmptyClickHandler());
|
||||
|
||||
preset.addItem(1, new CustomItem(getFuelIcon(), "&7Fuel Slot", "", "&rThis Slot accepts radioactive Fuel such as:", "&2Uranium &ror &aNeptunium"), ChestMenuUtils.getEmptyClickHandler());
|
||||
preset.addItem(1, new CustomItem(getFuelIcon(), "&7Fuel Slot", "", "&fThis Slot accepts radioactive Fuel such as:", "&2Uranium &for &aNeptunium"), ChestMenuUtils.getEmptyClickHandler());
|
||||
|
||||
for (int i : border_2) {
|
||||
preset.addItem(i, new CustomItem(new ItemStack(Material.CYAN_STAINED_GLASS_PANE), " "), ChestMenuUtils.getEmptyClickHandler());
|
||||
}
|
||||
|
||||
if (needsCooling()) {
|
||||
preset.addItem(7, new CustomItem(getCoolant(), "&bCoolant Slot", "", "&rThis Slot accepts Coolant Cells", "&4Without any Coolant Cells, your Reactor", "&4will explode"));
|
||||
preset.addItem(7, new CustomItem(getCoolant(), "&bCoolant Slot", "", "&fThis Slot accepts Coolant Cells", "&4Without any Coolant Cells, your Reactor", "&4will explode"));
|
||||
}
|
||||
else {
|
||||
preset.addItem(7, new CustomItem(new ItemStack(Material.BARRIER), "&bCoolant Slot", "", "&rThis Slot accepts Coolant Cells"));
|
||||
preset.addItem(7, new CustomItem(new ItemStack(Material.BARRIER), "&bCoolant Slot", "", "&fThis Slot accepts Coolant Cells"));
|
||||
|
||||
for (int i : border_4) {
|
||||
preset.addItem(i, new CustomItem(new ItemStack(Material.BARRIER), "&cNo Coolant Required"), ChestMenuUtils.getEmptyClickHandler());
|
||||
|
@ -1,7 +1,6 @@
|
||||
package io.github.thebusybiscuit.slimefun4.implementation.listeners;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.Firework;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
@ -18,7 +17,7 @@ public class FireworksListener implements Listener {
|
||||
|
||||
@EventHandler
|
||||
public void onResearchFireworkDamage(EntityDamageByEntityEvent e) {
|
||||
if (e.getDamager().getType() == EntityType.FIREWORK) {
|
||||
if (e.getDamager() instanceof Firework) {
|
||||
Firework firework = (Firework) e.getDamager();
|
||||
FireworkMeta meta = firework.getFireworkMeta();
|
||||
|
||||
|
@ -13,6 +13,12 @@ import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.Firework;
|
||||
import org.bukkit.inventory.meta.FireworkMeta;
|
||||
|
||||
/**
|
||||
* This is a simple utility classs for spawning random and colorful {@link Firework} rockets.
|
||||
*
|
||||
* @author TheBusyBiscuit
|
||||
*
|
||||
*/
|
||||
public final class FireworkUtils {
|
||||
|
||||
private static final Color[] COLORS = { Color.AQUA, Color.BLACK, Color.BLUE, Color.FUCHSIA, Color.GRAY, Color.GREEN, Color.LIME, Color.MAROON, Color.NAVY, Color.OLIVE, Color.ORANGE, Color.PURPLE, Color.RED, Color.SILVER, Color.TEAL, Color.WHITE, Color.YELLOW };
|
||||
@ -20,6 +26,10 @@ public final class FireworkUtils {
|
||||
private FireworkUtils() {}
|
||||
|
||||
public static void launchFirework(Location l, Color color) {
|
||||
createFirework(l, color);
|
||||
}
|
||||
|
||||
public static Firework createFirework(Location l, Color color) {
|
||||
Firework fw = (Firework) l.getWorld().spawnEntity(l, EntityType.FIREWORK);
|
||||
FireworkMeta meta = fw.getFireworkMeta();
|
||||
|
||||
@ -28,28 +38,17 @@ public final class FireworkUtils {
|
||||
meta.addEffect(effect);
|
||||
meta.setPower(ThreadLocalRandom.current().nextInt(2) + 1);
|
||||
fw.setFireworkMeta(meta);
|
||||
}
|
||||
|
||||
public static Firework createFirework(Location l, Color color) {
|
||||
Firework fw = (Firework) l.getWorld().spawnEntity(l, EntityType.FIREWORK);
|
||||
FireworkMeta meta = fw.getFireworkMeta();
|
||||
|
||||
meta.setDisplayName(ChatColor.GREEN + "Slimefun Research");
|
||||
FireworkEffect effect = FireworkEffect.builder().flicker(ThreadLocalRandom.current().nextBoolean()).withColor(color).with(ThreadLocalRandom.current().nextInt(3) + 1 == 1 ? Type.BALL : Type.BALL_LARGE).trail(ThreadLocalRandom.current().nextBoolean()).build();
|
||||
meta.addEffect(effect);
|
||||
meta.setPower(ThreadLocalRandom.current().nextInt(2) + 1);
|
||||
fw.setFireworkMeta(meta);
|
||||
|
||||
return fw;
|
||||
}
|
||||
|
||||
public static void launchRandom(Entity n, int amount) {
|
||||
Random random = ThreadLocalRandom.current();
|
||||
|
||||
for (int i = 0; i < amount; i++) {
|
||||
Location l = n.getLocation().clone();
|
||||
l.setX(l.getX() + ThreadLocalRandom.current().nextInt(amount));
|
||||
l.setX(l.getX() - ThreadLocalRandom.current().nextInt(amount));
|
||||
l.setZ(l.getZ() + ThreadLocalRandom.current().nextInt(amount));
|
||||
l.setZ(l.getZ() - ThreadLocalRandom.current().nextInt(amount));
|
||||
l.setX(l.getX() + random.nextInt(amount * 2) - amount);
|
||||
l.setZ(l.getZ() + random.nextInt(amount * 2) - amount);
|
||||
|
||||
launchFirework(l, getRandomColor());
|
||||
}
|
||||
|
@ -3,13 +3,14 @@ package io.github.thebusybiscuit.slimefun4.testing.tests;
|
||||
import org.junit.jupiter.api.AfterAll;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.DisplayName;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import be.seeseemelk.mockbukkit.MockBukkit;
|
||||
import io.github.thebusybiscuit.slimefun4.api.MinecraftVersion;
|
||||
import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin;
|
||||
|
||||
public class TestPluginClass {
|
||||
class TestPluginClass {
|
||||
|
||||
@BeforeAll
|
||||
public static void load() {
|
||||
@ -23,7 +24,8 @@ public class TestPluginClass {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void verifyTestEnvironment() {
|
||||
@DisplayName("Verify that we are in a UNIT_TEST environment")
|
||||
void verifyTestEnvironment() {
|
||||
MinecraftVersion version = SlimefunPlugin.getMinecraftVersion();
|
||||
|
||||
Assertions.assertEquals(MinecraftVersion.UNIT_TEST, version);
|
||||
@ -31,22 +33,28 @@ public class TestPluginClass {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConfigs() {
|
||||
@DisplayName("Verify that config files were loaded")
|
||||
void testConfigs() {
|
||||
Assertions.assertNotNull(SlimefunPlugin.getCfg());
|
||||
Assertions.assertNotNull(SlimefunPlugin.getResearchCfg());
|
||||
Assertions.assertNotNull(SlimefunPlugin.getItemCfg());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetters() {
|
||||
@DisplayName("Test some static Getters")
|
||||
void testGetters() {
|
||||
Assertions.assertNotNull(SlimefunPlugin.getTickerTask());
|
||||
Assertions.assertNotNull(SlimefunPlugin.getVersion());
|
||||
Assertions.assertNotNull(SlimefunPlugin.getRegistry());
|
||||
Assertions.assertNotNull(SlimefunPlugin.getCommand());
|
||||
Assertions.assertNotNull(SlimefunPlugin.getGPSNetwork());
|
||||
Assertions.assertNotNull(SlimefunPlugin.getNetworkManager());
|
||||
Assertions.assertNotNull(SlimefunPlugin.getProfiler());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testServicesNotNull() {
|
||||
@DisplayName("Test some Services being not-null")
|
||||
void testServicesNotNull() {
|
||||
Assertions.assertNotNull(SlimefunPlugin.getLocalization());
|
||||
Assertions.assertNotNull(SlimefunPlugin.getMinecraftRecipeService());
|
||||
Assertions.assertNotNull(SlimefunPlugin.getItemDataService());
|
||||
@ -57,10 +65,12 @@ public class TestPluginClass {
|
||||
Assertions.assertNotNull(SlimefunPlugin.getWorldSettingsService());
|
||||
Assertions.assertNotNull(SlimefunPlugin.getGitHubService());
|
||||
Assertions.assertNotNull(SlimefunPlugin.getUpdater());
|
||||
Assertions.assertNotNull(SlimefunPlugin.getMetricsService());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testListenersNotNull() {
|
||||
@DisplayName("Test some Listeners being not-null")
|
||||
void testListenersNotNull() {
|
||||
Assertions.assertNotNull(SlimefunPlugin.getAncientAltarListener());
|
||||
Assertions.assertNotNull(SlimefunPlugin.getGrapplingHookListener());
|
||||
Assertions.assertNotNull(SlimefunPlugin.getBackpackListener());
|
||||
|
@ -1,24 +1,21 @@
|
||||
package io.github.thebusybiscuit.slimefun4.testing.tests.listeners;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.Color;
|
||||
import org.bukkit.entity.Firework;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.entity.EntityDamageByEntityEvent;
|
||||
import org.bukkit.event.entity.EntityDamageEvent.DamageCause;
|
||||
import org.bukkit.inventory.meta.FireworkMeta;
|
||||
import org.junit.jupiter.api.AfterAll;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.DisplayName;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.mockito.Mockito;
|
||||
|
||||
import be.seeseemelk.mockbukkit.MockBukkit;
|
||||
import be.seeseemelk.mockbukkit.ServerMock;
|
||||
import be.seeseemelk.mockbukkit.inventory.meta.FireworkMetaMock;
|
||||
import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin;
|
||||
import io.github.thebusybiscuit.slimefun4.implementation.listeners.FireworksListener;
|
||||
import io.github.thebusybiscuit.slimefun4.utils.FireworkUtils;
|
||||
|
||||
class TestFireworksListener {
|
||||
|
||||
@ -40,12 +37,7 @@ class TestFireworksListener {
|
||||
@DisplayName("Test if Fireworks from Research cause no damage")
|
||||
void testFireworkDamage() {
|
||||
Player player = server.addPlayer();
|
||||
Firework firework = Mockito.mock(Firework.class);
|
||||
FireworkMeta meta = new FireworkMetaMock();
|
||||
meta.setDisplayName(ChatColor.GREEN + "Slimefun Research");
|
||||
|
||||
Mockito.when(firework.getType()).thenReturn(EntityType.FIREWORK);
|
||||
Mockito.when(firework.getFireworkMeta()).thenReturn(meta);
|
||||
Firework firework = FireworkUtils.createFirework(player.getLocation(), Color.BLUE);
|
||||
|
||||
EntityDamageByEntityEvent event = new EntityDamageByEntityEvent(firework, player, DamageCause.ENTITY_EXPLOSION, 6.0);
|
||||
server.getPluginManager().callEvent(event);
|
||||
|
@ -5,10 +5,15 @@ import java.util.Optional;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.permissions.Permission;
|
||||
import org.bukkit.permissions.PermissionDefault;
|
||||
import org.junit.jupiter.api.AfterAll;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.DisplayName;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.ValueSource;
|
||||
|
||||
import be.seeseemelk.mockbukkit.MockBukkit;
|
||||
import be.seeseemelk.mockbukkit.ServerMock;
|
||||
@ -18,7 +23,7 @@ import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin;
|
||||
import io.github.thebusybiscuit.slimefun4.testing.TestUtilities;
|
||||
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem;
|
||||
|
||||
public class TestPermissionsService {
|
||||
class TestPermissionsService {
|
||||
|
||||
private static ServerMock server;
|
||||
private static SlimefunPlugin plugin;
|
||||
@ -34,18 +39,24 @@ public class TestPermissionsService {
|
||||
MockBukkit.unmock();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRegistration() {
|
||||
@ParameterizedTest
|
||||
@DisplayName("Test if no permission is set by default")
|
||||
@ValueSource(booleans = { false, true })
|
||||
void testDefaultPermission(boolean registered) {
|
||||
PermissionsService service = new PermissionsService(plugin);
|
||||
SlimefunItem item = TestUtilities.mockSlimefunItem(plugin, "PERMISSIONS_TEST", new CustomItem(Material.EMERALD, "&bBad omen"));
|
||||
service.register(Arrays.asList(item), false);
|
||||
|
||||
if (registered) {
|
||||
service.register(Arrays.asList(item), false);
|
||||
}
|
||||
|
||||
Optional<String> permission = service.getPermission(item);
|
||||
Assertions.assertFalse(permission.isPresent());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetPermission() {
|
||||
@DisplayName("Test if a permission node can be set")
|
||||
void testSetPermission() {
|
||||
PermissionsService service = new PermissionsService(plugin);
|
||||
SlimefunItem item = TestUtilities.mockSlimefunItem(plugin, "PERMISSIONS_TEST", new CustomItem(Material.EMERALD, "&bBad omen"));
|
||||
|
||||
@ -65,7 +76,8 @@ public class TestPermissionsService {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHasPermissionTrue() {
|
||||
@DisplayName("Test if the Player will pass the permissions check if no permission was set")
|
||||
void testHasPermissionTrue() {
|
||||
PermissionsService service = new PermissionsService(plugin);
|
||||
Player player = server.addPlayer();
|
||||
SlimefunItem item = TestUtilities.mockSlimefunItem(plugin, "PERMISSIONS_TEST", new CustomItem(Material.EMERALD, "&bBad omen"));
|
||||
@ -78,7 +90,8 @@ public class TestPermissionsService {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHasPermissionFalse() {
|
||||
@DisplayName("Test Players without permissions being denied access")
|
||||
void testHasPermissionFalse() {
|
||||
PermissionsService service = new PermissionsService(plugin);
|
||||
Player player = server.addPlayer();
|
||||
SlimefunItem item = TestUtilities.mockSlimefunItem(plugin, "PERMISSIONS_TEST", new CustomItem(Material.EMERALD, "&bBad omen"));
|
||||
@ -86,4 +99,32 @@ public class TestPermissionsService {
|
||||
service.setPermission(item, "slimefun.tests");
|
||||
Assertions.assertFalse(service.hasPermission(player, item));
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("Test Server Operators passing permission checks")
|
||||
void testHasPermissionOp() {
|
||||
PermissionsService service = new PermissionsService(plugin);
|
||||
Player player = server.addPlayer();
|
||||
player.setOp(true);
|
||||
SlimefunItem item = TestUtilities.mockSlimefunItem(plugin, "PERMISSIONS_TEST", new CustomItem(Material.EMERALD, "&bBad omen"));
|
||||
|
||||
Permission permission = new Permission("slimefun.unit.tests.op", PermissionDefault.OP);
|
||||
|
||||
service.setPermission(item, permission.getName());
|
||||
Assertions.assertTrue(service.hasPermission(player, item));
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("Test Player with permission passing the permission check")
|
||||
void testHasPermissionSet() {
|
||||
PermissionsService service = new PermissionsService(plugin);
|
||||
Player player = server.addPlayer();
|
||||
SlimefunItem item = TestUtilities.mockSlimefunItem(plugin, "PERMISSIONS_TEST", new CustomItem(Material.EMERALD, "&bBad omen"));
|
||||
|
||||
String permission = "slimefun.unit.tests.permission";
|
||||
player.addAttachment(plugin, permission, true);
|
||||
service.setPermission(item, permission);
|
||||
|
||||
Assertions.assertTrue(service.hasPermission(player, item));
|
||||
}
|
||||
}
|
||||
|
@ -2,6 +2,7 @@ package io.github.thebusybiscuit.slimefun4.testing.tests.utils;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.DisplayName;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import io.github.thebusybiscuit.cscorelib2.chat.ChatColors;
|
||||
@ -10,6 +11,7 @@ import io.github.thebusybiscuit.slimefun4.utils.ChatUtils;
|
||||
class TestChatUtils {
|
||||
|
||||
@Test
|
||||
@DisplayName("Test ChatUtils.humanize(...)")
|
||||
void testHumanize() {
|
||||
String input = "TEST_STRING_COOL";
|
||||
String expected = "Test String Cool";
|
||||
@ -17,6 +19,7 @@ class TestChatUtils {
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("Test ChatUtils.christmas(...)")
|
||||
void testChristmas() {
|
||||
String input = "Tis the season";
|
||||
String expected = ChatColors.color("&aT&ci&as&c &at&ch&ae&c &as&ce&aa&cs&ao&cn");
|
||||
@ -24,6 +27,7 @@ class TestChatUtils {
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("Test ChatUtils.removeColorCodes(...)")
|
||||
void testColorCodeRemoval() {
|
||||
String expected = "Hello world";
|
||||
Assertions.assertEquals(expected, ChatUtils.removeColorCodes("&4&lHello &6world"));
|
||||
|
@ -0,0 +1,54 @@
|
||||
package io.github.thebusybiscuit.slimefun4.testing.tests.utils;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Color;
|
||||
import org.bukkit.FireworkEffect;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Firework;
|
||||
import org.junit.jupiter.api.AfterAll;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.DisplayName;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.Arguments;
|
||||
import org.junit.jupiter.params.provider.MethodSource;
|
||||
|
||||
import be.seeseemelk.mockbukkit.MockBukkit;
|
||||
import be.seeseemelk.mockbukkit.WorldMock;
|
||||
import io.github.thebusybiscuit.slimefun4.utils.FireworkUtils;
|
||||
|
||||
class TestFireworkUtils {
|
||||
|
||||
@BeforeAll
|
||||
public static void load() {
|
||||
MockBukkit.mock();
|
||||
}
|
||||
|
||||
@AfterAll
|
||||
public static void unload() {
|
||||
MockBukkit.unmock();
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@MethodSource("getColors")
|
||||
@DisplayName("Test colored Fireworks")
|
||||
void testColoredFirework(Color color) {
|
||||
Location l = new Location(new WorldMock(), 50, 50, 50);
|
||||
Firework firework = FireworkUtils.createFirework(l, color);
|
||||
|
||||
Assertions.assertEquals(l, firework.getLocation());
|
||||
Assertions.assertEquals(ChatColor.GREEN + "Slimefun Research", firework.getFireworkMeta().getDisplayName());
|
||||
|
||||
List<FireworkEffect> effects = firework.getFireworkMeta().getEffects();
|
||||
Assertions.assertEquals(1, effects.size());
|
||||
Assertions.assertEquals(color, effects.get(0).getColors().get(0));
|
||||
}
|
||||
|
||||
private static Stream<Arguments> getColors() {
|
||||
return Stream.of(Color.RED, Color.BLUE, Color.YELLOW, Color.fromRGB(100, 20, 100)).map(Arguments::of);
|
||||
}
|
||||
|
||||
}
|
@ -1,14 +1,16 @@
|
||||
package io.github.thebusybiscuit.slimefun4.testing.tests.utils;
|
||||
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.DisplayName;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import io.github.thebusybiscuit.slimefun4.api.MinecraftVersion;
|
||||
|
||||
public class TestMinecraftVersion {
|
||||
class TestMinecraftVersion {
|
||||
|
||||
@Test
|
||||
public void testMatches() {
|
||||
@DisplayName("Test if Minecraft versions match themselves")
|
||||
void testMatches() {
|
||||
Assertions.assertTrue(MinecraftVersion.MINECRAFT_1_13.matches("v1_13_R1"));
|
||||
Assertions.assertTrue(MinecraftVersion.MINECRAFT_1_14.matches("v1_14_R2"));
|
||||
|
||||
@ -18,7 +20,8 @@ public class TestMinecraftVersion {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAtLeast() {
|
||||
@DisplayName("Test if Minecraft versions are ordered correctly (#atLeast)")
|
||||
void testAtLeast() {
|
||||
Assertions.assertTrue(MinecraftVersion.MINECRAFT_1_15.isAtLeast(MinecraftVersion.MINECRAFT_1_13));
|
||||
Assertions.assertTrue(MinecraftVersion.MINECRAFT_1_15.isAtLeast(MinecraftVersion.MINECRAFT_1_14));
|
||||
Assertions.assertTrue(MinecraftVersion.MINECRAFT_1_15.isAtLeast(MinecraftVersion.MINECRAFT_1_15));
|
||||
@ -27,7 +30,8 @@ public class TestMinecraftVersion {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAtLeastUnknown() {
|
||||
@DisplayName("Test correct behaviour for MinecraftVersion.UNKNOWN.isAtleast(...)")
|
||||
void testAtLeastUnknown() {
|
||||
// Unknown should always fall back to false
|
||||
Assertions.assertFalse(MinecraftVersion.UNKNOWN.isAtLeast(MinecraftVersion.MINECRAFT_1_13));
|
||||
Assertions.assertFalse(MinecraftVersion.UNKNOWN.isAtLeast(MinecraftVersion.MINECRAFT_1_15));
|
||||
@ -36,7 +40,8 @@ public class TestMinecraftVersion {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIsBefore() {
|
||||
@DisplayName("Test if Minecraft versions are ordered correctly (#isBefore)")
|
||||
void testIsBefore() {
|
||||
Assertions.assertTrue(MinecraftVersion.MINECRAFT_1_13.isBefore(MinecraftVersion.MINECRAFT_1_14));
|
||||
Assertions.assertTrue(MinecraftVersion.MINECRAFT_1_13.isBefore(MinecraftVersion.MINECRAFT_1_15));
|
||||
Assertions.assertTrue(MinecraftVersion.MINECRAFT_1_14.isBefore(MinecraftVersion.MINECRAFT_1_15));
|
||||
@ -46,7 +51,8 @@ public class TestMinecraftVersion {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIsBeforeUnknown() {
|
||||
@DisplayName("Test correct behaviour for MinecraftVersion.UNKNOWN.isBefore(...)")
|
||||
void testIsBeforeUnknown() {
|
||||
// Unknown should always fall back to true
|
||||
Assertions.assertTrue(MinecraftVersion.UNKNOWN.isBefore(MinecraftVersion.MINECRAFT_1_13));
|
||||
Assertions.assertTrue(MinecraftVersion.UNKNOWN.isBefore(MinecraftVersion.MINECRAFT_1_15));
|
||||
|
@ -6,6 +6,7 @@ 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.DisplayName;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import be.seeseemelk.mockbukkit.MockBukkit;
|
||||
@ -18,7 +19,7 @@ import me.mrCookieSlime.Slimefun.Objects.Category;
|
||||
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem;
|
||||
import me.mrCookieSlime.Slimefun.api.SlimefunItemStack;
|
||||
|
||||
public class TestSoulboundItem {
|
||||
class TestSoulboundItem {
|
||||
|
||||
private static SlimefunPlugin plugin;
|
||||
|
||||
@ -34,7 +35,8 @@ public class TestSoulboundItem {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNullAndAir() {
|
||||
@DisplayName("Verify that null and air throw Illegal Argument Exceptions")
|
||||
void testNullAndAir() {
|
||||
Assertions.assertThrows(IllegalArgumentException.class, () -> SlimefunUtils.setSoulbound(null, true));
|
||||
|
||||
ItemStack item = new ItemStack(Material.AIR);
|
||||
@ -45,7 +47,8 @@ public class TestSoulboundItem {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetSoulbound() {
|
||||
@DisplayName("Test whether an Item can be marked as soulbound")
|
||||
void testSetSoulbound() {
|
||||
ItemStack item = new CustomItem(Material.DIAMOND, "&cI wanna be soulbound!");
|
||||
|
||||
Assertions.assertFalse(SlimefunUtils.isSoulbound(item));
|
||||
@ -60,7 +63,8 @@ public class TestSoulboundItem {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDoubleCalls() {
|
||||
@DisplayName("Make sure that marking an item as soulbound twice has no effect")
|
||||
void testDoubleCalls() {
|
||||
ItemStack item = new CustomItem(Material.DIAMOND, "&cI wanna be soulbound!");
|
||||
|
||||
SlimefunUtils.setSoulbound(item, true);
|
||||
@ -75,7 +79,8 @@ public class TestSoulboundItem {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSoulboundSlimefunItem() {
|
||||
@DisplayName("Test that soulbound Slimefun Items are soulbound")
|
||||
void testSoulboundSlimefunItem() {
|
||||
SlimefunItem item = new SoulboundMock(new Category(new NamespacedKey(plugin, "soulbound_category"), new CustomItem(Material.REDSTONE, "&4Walshrus forever")));
|
||||
item.register(plugin);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user