diff --git a/.github/workflows/discord-webhook.yml b/.github/workflows/discord-webhook.yml
index f6c11887b..a4845bb6f 100644
--- a/.github/workflows/discord-webhook.yml
+++ b/.github/workflows/discord-webhook.yml
@@ -4,6 +4,7 @@ on:
push:
paths:
- 'src/**'
+ - '!src/main/resources/languages/**'
- 'pom.xml'
jobs:
@@ -15,11 +16,13 @@ jobs:
steps:
- name: Checkout repository
- uses: actions/checkout@v1
- - name: Set up JDK 1.8
- uses: actions/setup-java@master
+ uses: actions/checkout@v2.3.3
+ - name: Set up Java JDK 11
+ uses: actions/setup-java@v1.4.3
with:
- java-version: 1.8
+ java-version: '11'
+ java-package: jdk
+ architecture: x64
- name: Run Discord Webhook
uses: Slimefun/discord-webhook@master
with:
diff --git a/.github/workflows/url-checker.yml b/.github/workflows/url-checker.yml
index e0e150008..523248f00 100644
--- a/.github/workflows/url-checker.yml
+++ b/.github/workflows/url-checker.yml
@@ -4,9 +4,6 @@ on:
push:
branches:
- master
- pull_request:
- branches:
- - master
jobs:
build:
diff --git a/CHANGELOG.md b/CHANGELOG.md
index a5f708932..2346afa38 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -37,6 +37,8 @@
* Added Elytra Cap
* Added Planks to Sticks recipe to the Table Saw
* Added "slimefun.gps.bypass" permission to open GPS devices anywhere
+* (API) Added custom tags for developers
+* The range of the Seeker Pickaxe is now configurable
#### Changes
* Improved Auto-Updater (Multi-Threading and more)
@@ -68,6 +70,12 @@
* Fixed #2391
* Fixed #2403
* Fixed #2405
+* Fixed #2412
+* Fixed #2238
+* Fixed #2439
+* Fixed #2420
+* Fixed #2422
+* Fixed #2433
## Release Candidate 16 (07 Sep 2020)
https://thebusybiscuit.github.io/builds/TheBusyBiscuit/Slimefun4/stable/#16
diff --git a/pom.xml b/pom.xml
index eba85470d..217f7b2a1 100644
--- a/pom.xml
+++ b/pom.xml
@@ -262,6 +262,7 @@
*
+ tags/*
languages/*
@@ -344,7 +345,7 @@
com.konghq
unirest-java
- 3.11.00
+ 3.11.01
compile
diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/api/MinecraftVersion.java b/src/main/java/io/github/thebusybiscuit/slimefun4/api/MinecraftVersion.java
index c4c8c0dd5..9cb5793b9 100644
--- a/src/main/java/io/github/thebusybiscuit/slimefun4/api/MinecraftVersion.java
+++ b/src/main/java/io/github/thebusybiscuit/slimefun4/api/MinecraftVersion.java
@@ -50,7 +50,7 @@ public enum MinecraftVersion {
*/
UNIT_TEST("Unit Test Environment");
- public static final MinecraftVersion[] values = values();
+ public static final MinecraftVersion[] valuesCache = values();
private final String name;
private final String prefix;
diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/api/exceptions/TagMisconfigurationException.java b/src/main/java/io/github/thebusybiscuit/slimefun4/api/exceptions/TagMisconfigurationException.java
new file mode 100644
index 000000000..165f5c3be
--- /dev/null
+++ b/src/main/java/io/github/thebusybiscuit/slimefun4/api/exceptions/TagMisconfigurationException.java
@@ -0,0 +1,48 @@
+package io.github.thebusybiscuit.slimefun4.api.exceptions;
+
+import javax.annotation.ParametersAreNonnullByDefault;
+
+import org.bukkit.NamespacedKey;
+
+import io.github.thebusybiscuit.slimefun4.utils.tags.SlimefunTag;
+
+/**
+ * An {@link TagMisconfigurationException} is thrown whenever a {@link SlimefunTag}
+ * contains illegal, invalid or unknown values.
+ *
+ * @author TheBusyBiscuit
+ *
+ */
+public class TagMisconfigurationException extends Exception {
+
+ private static final long serialVersionUID = 5412127960821774280L;
+
+ /**
+ * This constructs a new {@link TagMisconfigurationException} for the given
+ * {@link SlimefunTag}'s {@link NamespacedKey} with the provided context.
+ *
+ * @param key
+ * The {@link NamespacedKey} of our {@link SlimefunTag}
+ * @param message
+ * The message to display
+ */
+ @ParametersAreNonnullByDefault
+ public TagMisconfigurationException(NamespacedKey key, String message) {
+ super("Tag '" + key + "' has been misconfigured: " + message);
+ }
+
+ /**
+ * This constructs a new {@link TagMisconfigurationException} for the given
+ * {@link SlimefunTag}'s {@link NamespacedKey} with the provided context.
+ *
+ * @param key
+ * The {@link NamespacedKey} of our {@link SlimefunTag}
+ * @param cause
+ * The {@link Throwable} which has caused this to happen
+ */
+ @ParametersAreNonnullByDefault
+ public TagMisconfigurationException(NamespacedKey key, Throwable cause) {
+ super("Tag '" + key + "' has been misconfigured (" + cause.getMessage() + ')', cause);
+ }
+
+}
diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/api/geo/ResourceManager.java b/src/main/java/io/github/thebusybiscuit/slimefun4/api/geo/ResourceManager.java
index b8fcbc218..81eb79474 100644
--- a/src/main/java/io/github/thebusybiscuit/slimefun4/api/geo/ResourceManager.java
+++ b/src/main/java/io/github/thebusybiscuit/slimefun4/api/geo/ResourceManager.java
@@ -201,15 +201,19 @@ public class ResourceManager {
menu.addItem(47, ChestMenuUtils.getPreviousButton(p, page + 1, pages));
menu.addMenuClickHandler(47, (pl, slot, item, action) -> {
- if (page > 0)
+ if (page > 0) {
scan(pl, block, page - 1);
+ }
+
return false;
});
menu.addItem(51, ChestMenuUtils.getNextButton(p, page + 1, pages));
menu.addMenuClickHandler(51, (pl, slot, item, action) -> {
- if (page + 1 < pages)
+ if (page + 1 < pages) {
scan(pl, block, page + 1);
+ }
+
return false;
});
diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/api/gps/GPSNetwork.java b/src/main/java/io/github/thebusybiscuit/slimefun4/api/gps/GPSNetwork.java
index 1e7d7e311..649a0ea48 100644
--- a/src/main/java/io/github/thebusybiscuit/slimefun4/api/gps/GPSNetwork.java
+++ b/src/main/java/io/github/thebusybiscuit/slimefun4/api/gps/GPSNetwork.java
@@ -148,10 +148,12 @@ public class GPSNetwork {
int index = 0;
for (Location l : getTransmitters(p.getUniqueId())) {
- if (index >= inventory.length)
+ if (index >= inventory.length) {
break;
+ }
SlimefunItem sfi = BlockStorage.check(l);
+
if (sfi instanceof GPSTransmitter) {
int slot = inventory[index];
@@ -216,8 +218,10 @@ public class GPSNetwork {
int index = 0;
for (Waypoint waypoint : profile.getWaypoints()) {
- if (index >= inventory.length)
+ if (index >= inventory.length) {
break;
+ }
+
int slot = inventory[index];
Location l = waypoint.getLocation();
diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/api/gps/TeleportationManager.java b/src/main/java/io/github/thebusybiscuit/slimefun4/api/gps/TeleportationManager.java
index e81bcf6a4..eb0ee827a 100644
--- a/src/main/java/io/github/thebusybiscuit/slimefun4/api/gps/TeleportationManager.java
+++ b/src/main/java/io/github/thebusybiscuit/slimefun4/api/gps/TeleportationManager.java
@@ -92,8 +92,9 @@ public final class TeleportationManager {
@ParametersAreNonnullByDefault
public int getTeleportationTime(int complexity, Location source, Location destination) {
- if (complexity < 100)
+ if (complexity < 100) {
return 100;
+ }
int speed = 50_000 + complexity * complexity;
return 1 + Math.min(4 * distanceSquared(source, destination) / speed, 40);
diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/api/items/ItemSetting.java b/src/main/java/io/github/thebusybiscuit/slimefun4/api/items/ItemSetting.java
index 7eedda655..68266f5d2 100644
--- a/src/main/java/io/github/thebusybiscuit/slimefun4/api/items/ItemSetting.java
+++ b/src/main/java/io/github/thebusybiscuit/slimefun4/api/items/ItemSetting.java
@@ -119,6 +119,17 @@ public class ItemSetting {
return c.isInstance(defaultValue);
}
+ /**
+ * This is an error message which should provide further context on what values
+ * are allowed.
+ *
+ * @return An error message which is displayed when this {@link ItemSetting} is misconfigured.
+ */
+ @Nonnull
+ protected String getErrorMessage() {
+ return "Only '" + defaultValue.getClass().getSimpleName() + "' values are allowed!";
+ }
+
/**
* This method is called by a {@link SlimefunItem} which wants to load its {@link ItemSetting}
* from the {@link Config} file.
@@ -132,7 +143,14 @@ public class ItemSetting {
Object configuredValue = SlimefunPlugin.getItemCfg().getValue(item.getID() + '.' + getKey());
if (defaultValue.getClass().isInstance(configuredValue)) {
- this.value = (T) configuredValue;
+ if (validateInput((T) configuredValue)) {
+ this.value = (T) configuredValue;
+ } else {
+ Slimefun.getLogger().log(Level.WARNING, "Slimefun has found an invalid config setting in your Items.yml!");
+ Slimefun.getLogger().log(Level.WARNING, " at \"{0}.{1}\"", new Object[] { item.getID(), getKey() });
+ Slimefun.getLogger().log(Level.WARNING, "{0} is not a valid input!", configuredValue);
+ Slimefun.getLogger().log(Level.WARNING, getErrorMessage());
+ }
} else {
this.value = defaultValue;
String found = configuredValue == null ? "null" : configuredValue.getClass().getSimpleName();
@@ -144,4 +162,10 @@ public class ItemSetting {
}
}
+ @Override
+ public String toString() {
+ T currentValue = this.value != null ? this.value : defaultValue;
+ return getClass().getSimpleName() + " {" + getKey() + " = " + currentValue + " (default: " + getDefaultValue() + ")";
+ }
+
}
diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/api/items/settings/DoubleRangeSetting.java b/src/main/java/io/github/thebusybiscuit/slimefun4/api/items/settings/DoubleRangeSetting.java
new file mode 100644
index 000000000..86b02ac05
--- /dev/null
+++ b/src/main/java/io/github/thebusybiscuit/slimefun4/api/items/settings/DoubleRangeSetting.java
@@ -0,0 +1,63 @@
+package io.github.thebusybiscuit.slimefun4.api.items.settings;
+
+import javax.annotation.Nonnull;
+import javax.annotation.ParametersAreNonnullByDefault;
+
+import org.apache.commons.lang.Validate;
+
+import io.github.thebusybiscuit.slimefun4.api.items.ItemSetting;
+
+/**
+ * This variation of {@link ItemSetting} allows you to define an {@link Double} range
+ * and enforces this range using the {@link #validateInput(Double)} method.
+ *
+ * @author TheBusyBiscuit
+ *
+ * @see ItemSetting
+ * @see IntRangeSetting
+ *
+ */
+public class DoubleRangeSetting extends ItemSetting {
+
+ private final double min;
+ private final double max;
+
+ @ParametersAreNonnullByDefault
+ public DoubleRangeSetting(String key, double min, double defaultValue, double max) {
+ super(key, defaultValue);
+ Validate.isTrue(defaultValue >= min && defaultValue <= max, "The default value is not in range.");
+
+ this.min = min;
+ this.max = max;
+ }
+
+ @Nonnull
+ @Override
+ protected String getErrorMessage() {
+ return "Only decimal numbers from " + min + '-' + max + "(inclusive) are allowed!";
+ }
+
+ @Override
+ public boolean validateInput(Double input) {
+ return super.validateInput(input) && input >= min && input <= max;
+ }
+
+ /**
+ * This returns the minimum value of this {@link DoubleRangeSetting}.
+ *
+ * @return The minimum value
+ */
+ public final double getMinimum() {
+ return min;
+ }
+
+ /**
+ * This returns the maximum value of this {@link DoubleRangeSetting}.
+ *
+ * @return The maximum value
+ */
+ public final double getMaximum() {
+ return max;
+ }
+
+}
diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/api/items/settings/EnumSetting.java b/src/main/java/io/github/thebusybiscuit/slimefun4/api/items/settings/EnumSetting.java
new file mode 100644
index 000000000..d952286af
--- /dev/null
+++ b/src/main/java/io/github/thebusybiscuit/slimefun4/api/items/settings/EnumSetting.java
@@ -0,0 +1,72 @@
+package io.github.thebusybiscuit.slimefun4.api.items.settings;
+
+import java.util.Arrays;
+import java.util.stream.Collectors;
+
+import javax.annotation.Nonnull;
+import javax.annotation.ParametersAreNonnullByDefault;
+
+import io.github.thebusybiscuit.slimefun4.api.items.ItemSetting;
+
+/**
+ * This variation of {@link ItemSetting} allows you to allow {@link Enum} constants to be
+ * used for {@link ItemSetting} validation.
+ *
+ * @author TheBusyBiscuit
+ *
+ * @see ItemSetting
+ *
+ */
+public class EnumSetting> extends ItemSetting {
+
+ private final Class enumClass;
+
+ @ParametersAreNonnullByDefault
+ public EnumSetting(String key, Class enumClass, T defaultValue) {
+ super(key, defaultValue.name());
+
+ this.enumClass = enumClass;
+ }
+
+ @Nonnull
+ @Override
+ protected String getErrorMessage() {
+ String values = Arrays.stream(getAllowedValues()).map(Enum::name).collect(Collectors.joining(", "));
+ return "The following values are valid: " + values;
+ }
+
+ /**
+ * This returns an array of valid {@link Enum} values.
+ * This method may be overridden to further limit the allowed values.
+ *
+ * @return An array of allowed {@link Enum} constants
+ */
+ public T[] getAllowedValues() {
+ return enumClass.getEnumConstants();
+ }
+
+ /**
+ * This will attempt to get the configured value as a constant of the desired {@link Enum}.
+ *
+ * @return The value as an {@link Enum} constant
+ */
+ public T getAsEnumConstant() {
+ return Enum.valueOf(enumClass, getValue());
+ }
+
+ @Override
+ public boolean validateInput(String input) {
+ if (!super.validateInput(input)) {
+ return false;
+ } else {
+ for (Enum value : getAllowedValues()) {
+ if (value.name().equals(input)) {
+ return true;
+ }
+ }
+
+ return false;
+ }
+ }
+
+}
diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/api/items/settings/IntRangeSetting.java b/src/main/java/io/github/thebusybiscuit/slimefun4/api/items/settings/IntRangeSetting.java
new file mode 100644
index 000000000..f4b41ed38
--- /dev/null
+++ b/src/main/java/io/github/thebusybiscuit/slimefun4/api/items/settings/IntRangeSetting.java
@@ -0,0 +1,63 @@
+package io.github.thebusybiscuit.slimefun4.api.items.settings;
+
+import javax.annotation.Nonnull;
+import javax.annotation.ParametersAreNonnullByDefault;
+
+import org.apache.commons.lang.Validate;
+
+import io.github.thebusybiscuit.slimefun4.api.items.ItemSetting;
+
+/**
+ * This variation of {@link ItemSetting} allows you to define an {@link Integer} range
+ * and enforces this range using the {@link #validateInput(Integer)} method.
+ *
+ * @author TheBusyBiscuit
+ *
+ * @see ItemSetting
+ * @see DoubleRangeSetting
+ *
+ */
+public class IntRangeSetting extends ItemSetting {
+
+ private final int min;
+ private final int max;
+
+ @ParametersAreNonnullByDefault
+ public IntRangeSetting(String key, int min, int defaultValue, int max) {
+ super(key, defaultValue);
+ Validate.isTrue(defaultValue >= min && defaultValue <= max, "The default value is not in range.");
+
+ this.min = min;
+ this.max = max;
+ }
+
+ @Nonnull
+ @Override
+ protected String getErrorMessage() {
+ return "Only whole numbers from " + min + '-' + max + "(inclusive) are allowed!";
+ }
+
+ @Override
+ public boolean validateInput(Integer input) {
+ return super.validateInput(input) && input >= min && input <= max;
+ }
+
+ /**
+ * This returns the minimum value of this {@link IntRangeSetting}.
+ *
+ * @return The minimum value
+ */
+ public final int getMinimum() {
+ return min;
+ }
+
+ /**
+ * This returns the maximum value of this {@link IntRangeSetting}.
+ *
+ * @return The maximum value
+ */
+ public final int getMaximum() {
+ return max;
+ }
+
+}
diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/api/items/settings/MaterialTagSetting.java b/src/main/java/io/github/thebusybiscuit/slimefun4/api/items/settings/MaterialTagSetting.java
new file mode 100644
index 000000000..b856d5614
--- /dev/null
+++ b/src/main/java/io/github/thebusybiscuit/slimefun4/api/items/settings/MaterialTagSetting.java
@@ -0,0 +1,83 @@
+package io.github.thebusybiscuit.slimefun4.api.items.settings;
+
+import java.util.List;
+import java.util.stream.Collectors;
+
+import javax.annotation.Nonnull;
+import javax.annotation.ParametersAreNonnullByDefault;
+
+import org.bukkit.Material;
+import org.bukkit.Tag;
+
+import io.github.thebusybiscuit.slimefun4.api.items.ItemSetting;
+
+/**
+ * This variation of {@link ItemSetting} allows you to define a default {@link Tag}.
+ * The {@link Tag} will be translated into a {@link String} {@link List} which the user
+ * can then configure as they wish.
+ *
+ * It also validates all inputs to be a valid {@link Material}.
+ *
+ * @author TheBusyBiscuit
+ *
+ * @see ItemSetting
+ *
+ */
+public class MaterialTagSetting extends ItemSetting> {
+
+ private final Tag defaultTag;
+
+ @ParametersAreNonnullByDefault
+ public MaterialTagSetting(String key, Tag defaultTag) {
+ super(key, getAsStringList(defaultTag));
+
+ this.defaultTag = defaultTag;
+ }
+
+ /**
+ * This {@link Tag} holds the default values for this {@link MaterialTagSetting}.
+ *
+ * @return The default {@link Tag}
+ */
+ @Nonnull
+ public Tag getDefaultTag() {
+ return defaultTag;
+ }
+
+ @Nonnull
+ @Override
+ protected String getErrorMessage() {
+ return "This List can only contain Materials in the format of e.g. REDSTONE_BLOCK";
+ }
+
+ @Override
+ public boolean validateInput(List input) {
+ if (super.validateInput(input)) {
+ for (String value : input) {
+ Material material = Material.matchMaterial(value);
+
+ // This value is not a valid material, the setting is not valid.
+ if (material == null) {
+ return false;
+ }
+ }
+
+ return true;
+ } else {
+ return false;
+ }
+ }
+
+ /**
+ * Internal method to turn a {@link Tag} into a {@link List} of {@link String Strings}.
+ *
+ * @param tag
+ * Our {@link Tag}
+ * @return The {@link String} {@link List}
+ */
+ @Nonnull
+ private static List getAsStringList(@Nonnull Tag tag) {
+ return tag.getValues().stream().map(Material::name).collect(Collectors.toList());
+ }
+
+}
diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/api/items/settings/package-info.java b/src/main/java/io/github/thebusybiscuit/slimefun4/api/items/settings/package-info.java
new file mode 100644
index 000000000..2f6bea34c
--- /dev/null
+++ b/src/main/java/io/github/thebusybiscuit/slimefun4/api/items/settings/package-info.java
@@ -0,0 +1,4 @@
+/**
+ * This package contains various sub classes of {@link io.github.thebusybiscuit.slimefun4.api.items.ItemSetting}.
+ */
+package io.github.thebusybiscuit.slimefun4.api.items.settings;
\ No newline at end of file
diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/api/player/PlayerBackpack.java b/src/main/java/io/github/thebusybiscuit/slimefun4/api/player/PlayerBackpack.java
index e0f2086f2..336a6bfbe 100644
--- a/src/main/java/io/github/thebusybiscuit/slimefun4/api/player/PlayerBackpack.java
+++ b/src/main/java/io/github/thebusybiscuit/slimefun4/api/player/PlayerBackpack.java
@@ -28,13 +28,14 @@ import io.github.thebusybiscuit.slimefun4.implementation.listeners.BackpackListe
*/
public class PlayerBackpack {
+ private static final String CONFIG_PREFIX = "backpacks.";
+
private final PlayerProfile profile;
private final int id;
private final Config cfg;
private Inventory inventory;
private int size;
- private static final String CONFIG_PREFIX = "backpacks.";
/**
* This constructor loads an existing Backpack
diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/api/player/StatusEffect.java b/src/main/java/io/github/thebusybiscuit/slimefun4/api/player/StatusEffect.java
index c108221ce..12a364457 100644
--- a/src/main/java/io/github/thebusybiscuit/slimefun4/api/player/StatusEffect.java
+++ b/src/main/java/io/github/thebusybiscuit/slimefun4/api/player/StatusEffect.java
@@ -4,6 +4,8 @@ import java.util.Optional;
import java.util.OptionalInt;
import java.util.concurrent.TimeUnit;
+import javax.annotation.Nonnull;
+
import io.github.thebusybiscuit.slimefun4.utils.PatternUtils;
import org.bukkit.Keyed;
import org.bukkit.NamespacedKey;
@@ -27,10 +29,11 @@ public class StatusEffect implements Keyed {
private final NamespacedKey key;
- public StatusEffect(NamespacedKey key) {
+ public StatusEffect(@Nonnull NamespacedKey key) {
this.key = key;
}
+ @Nonnull
@Override
public NamespacedKey getKey() {
return key;
@@ -48,7 +51,7 @@ public class StatusEffect implements Keyed {
* @param unit
* The {@link TimeUnit} for the given duration
*/
- public void add(Player p, int duration, TimeUnit unit) {
+ public void add(@Nonnull Player p, int duration, @Nonnull TimeUnit unit) {
add(p, 1, duration, unit);
}
@@ -64,7 +67,7 @@ public class StatusEffect implements Keyed {
* @param unit
* The {@link TimeUnit} for the given duration
*/
- public void add(Player p, int level, int duration, TimeUnit unit) {
+ public void add(@Nonnull Player p, int level, int duration, @Nonnull TimeUnit unit) {
PersistentDataAPI.setString(p, getKey(), level + ";" + System.currentTimeMillis() + unit.toMillis(duration));
}
@@ -77,7 +80,7 @@ public class StatusEffect implements Keyed {
* @param level
* The level of this effect
*/
- public void addPermanent(Player p, int level) {
+ public void addPermanent(@Nonnull Player p, int level) {
PersistentDataAPI.setString(p, getKey(), level + ";0");
}
@@ -91,7 +94,7 @@ public class StatusEffect implements Keyed {
* The {@link Player} to check for
* @return Whether this {@link StatusEffect} is currently applied
*/
- public boolean isPresent(Player p) {
+ public boolean isPresent(@Nonnull Player p) {
Optional optional = PersistentDataAPI.getOptionalString(p, getKey());
if (optional.isPresent()) {
@@ -104,8 +107,9 @@ public class StatusEffect implements Keyed {
clear(p);
return false;
}
- } else
+ } else {
return false;
+ }
}
/**
@@ -116,15 +120,16 @@ public class StatusEffect implements Keyed {
* The {@link Player} to check for
* @return An {@link OptionalInt} that describes the result
*/
- public OptionalInt getLevel(Player p) {
+ @Nonnull
+ public OptionalInt getLevel(@Nonnull Player p) {
Optional optional = PersistentDataAPI.getOptionalString(p, getKey());
if (optional.isPresent()) {
String[] data = PatternUtils.SEMICOLON.split(optional.get());
return OptionalInt.of(Integer.parseInt(data[0]));
-
- } else
+ } else {
return OptionalInt.empty();
+ }
}
/**
@@ -133,7 +138,7 @@ public class StatusEffect implements Keyed {
* @param p
* The {@link Player} to clear it from
*/
- public void clear(Player p) {
+ public void clear(@Nonnull Player p) {
PersistentDataAPI.remove(p, getKey());
}
diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/core/SlimefunRegistry.java b/src/main/java/io/github/thebusybiscuit/slimefun4/core/SlimefunRegistry.java
index 1b05dbcf1..ae85b19ab 100644
--- a/src/main/java/io/github/thebusybiscuit/slimefun4/core/SlimefunRegistry.java
+++ b/src/main/java/io/github/thebusybiscuit/slimefun4/core/SlimefunRegistry.java
@@ -11,6 +11,9 @@ import java.util.Set;
import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap;
+import javax.annotation.Nonnull;
+
+import org.apache.commons.lang.Validate;
import org.bukkit.Server;
import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType;
@@ -47,7 +50,7 @@ import me.mrCookieSlime.Slimefun.api.inventory.UniversalBlockMenu;
* @author TheBusyBiscuit
*
*/
-public class SlimefunRegistry {
+public final class SlimefunRegistry {
private final Map slimefunIds = new HashMap<>();
private final List slimefunItems = new ArrayList<>();
@@ -86,7 +89,9 @@ public class SlimefunRegistry {
private final Map automatedCraftingChamberRecipes = new HashMap<>();
- public void load(Config cfg) {
+ public void load(@Nonnull Config cfg) {
+ Validate.notNull(cfg, "The Config cannot be null!");
+
boolean showVanillaRecipes = cfg.getBoolean("guide.show-vanilla-recipes");
layouts.put(SlimefunGuideLayout.CHEST, new ChestSlimefunGuide(showVanillaRecipes));
diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/core/commands/subcommands/ResearchCommand.java b/src/main/java/io/github/thebusybiscuit/slimefun4/core/commands/subcommands/ResearchCommand.java
index dacdb30e2..8bc1d7e2d 100644
--- a/src/main/java/io/github/thebusybiscuit/slimefun4/core/commands/subcommands/ResearchCommand.java
+++ b/src/main/java/io/github/thebusybiscuit/slimefun4/core/commands/subcommands/ResearchCommand.java
@@ -49,8 +49,9 @@ class ResearchCommand extends SubCommand {
} else {
SlimefunPlugin.getLocalization().sendMessage(sender, "messages.not-online", true, msg -> msg.replace(PLACEHOLDER_PLAYER, args[1]));
}
- } else
+ } else {
SlimefunPlugin.getLocalization().sendMessage(sender, "messages.no-permission", true);
+ }
} else {
SlimefunPlugin.getLocalization().sendMessage(sender, "messages.usage", true, msg -> msg.replace("%usage%", "/sf research "));
}
diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/core/commands/subcommands/StatsCommand.java b/src/main/java/io/github/thebusybiscuit/slimefun4/core/commands/subcommands/StatsCommand.java
index 11abe9817..1bb18b3e6 100644
--- a/src/main/java/io/github/thebusybiscuit/slimefun4/core/commands/subcommands/StatsCommand.java
+++ b/src/main/java/io/github/thebusybiscuit/slimefun4/core/commands/subcommands/StatsCommand.java
@@ -29,8 +29,9 @@ class StatsCommand extends SubCommand {
} else {
SlimefunPlugin.getLocalization().sendMessage(sender, "messages.not-online", true, msg -> msg.replace("%player%", args[1]));
}
- } else
+ } else {
SlimefunPlugin.getLocalization().sendMessage(sender, "messages.no-permission", true);
+ }
} else if (sender instanceof Player) {
PlayerProfile.get((Player) sender, profile -> profile.sendStats(sender));
} else {
diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/core/guide/SlimefunGuide.java b/src/main/java/io/github/thebusybiscuit/slimefun4/core/guide/SlimefunGuide.java
index 0fd23d500..94970ac43 100644
--- a/src/main/java/io/github/thebusybiscuit/slimefun4/core/guide/SlimefunGuide.java
+++ b/src/main/java/io/github/thebusybiscuit/slimefun4/core/guide/SlimefunGuide.java
@@ -78,15 +78,20 @@ public final class SlimefunGuide {
}
public static void openCategory(PlayerProfile profile, Category category, SlimefunGuideLayout layout, int selectedPage) {
- if (category == null)
+ if (category == null) {
return;
+ }
+
SlimefunPlugin.getRegistry().getGuideLayout(layout).openCategory(profile, category, selectedPage);
}
public static void openSearch(PlayerProfile profile, String input, boolean survival, boolean addToHistory) {
SlimefunGuideImplementation layout = SlimefunPlugin.getRegistry().getGuideLayout(SlimefunGuideLayout.CHEST);
- if (!survival)
+
+ if (!survival) {
layout = SlimefunPlugin.getRegistry().getGuideLayout(SlimefunGuideLayout.CHEAT_SHEET);
+ }
+
layout.openSearch(profile, input, addToHistory);
}
diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/core/guide/SlimefunGuideLayout.java b/src/main/java/io/github/thebusybiscuit/slimefun4/core/guide/SlimefunGuideLayout.java
index 278352c9d..562fe5981 100644
--- a/src/main/java/io/github/thebusybiscuit/slimefun4/core/guide/SlimefunGuideLayout.java
+++ b/src/main/java/io/github/thebusybiscuit/slimefun4/core/guide/SlimefunGuideLayout.java
@@ -31,6 +31,6 @@ public enum SlimefunGuideLayout {
*/
CHEAT_SHEET;
- public static final SlimefunGuideLayout[] values = values();
+ public static final SlimefunGuideLayout[] valuesCache = values();
}
diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/core/guide/options/GuideLayoutOption.java b/src/main/java/io/github/thebusybiscuit/slimefun4/core/guide/options/GuideLayoutOption.java
index cf19b812d..38564d077 100644
--- a/src/main/java/io/github/thebusybiscuit/slimefun4/core/guide/options/GuideLayoutOption.java
+++ b/src/main/java/io/github/thebusybiscuit/slimefun4/core/guide/options/GuideLayoutOption.java
@@ -98,7 +98,7 @@ class GuideLayoutOption implements SlimefunGuideOption {
@Override
public Optional getSelectedOption(Player p, ItemStack guide) {
- for (SlimefunGuideLayout layout : SlimefunGuideLayout.values) {
+ for (SlimefunGuideLayout layout : SlimefunGuideLayout.valuesCache) {
if (SlimefunUtils.isItemSimilar(guide, SlimefunGuide.getItem(layout), true, false)) {
return Optional.of(layout);
}
diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/core/handlers/RainbowTickHandler.java b/src/main/java/io/github/thebusybiscuit/slimefun4/core/handlers/RainbowTickHandler.java
index 5cd2867ea..4ba7ed63a 100644
--- a/src/main/java/io/github/thebusybiscuit/slimefun4/core/handlers/RainbowTickHandler.java
+++ b/src/main/java/io/github/thebusybiscuit/slimefun4/core/handlers/RainbowTickHandler.java
@@ -1,6 +1,9 @@
package io.github.thebusybiscuit.slimefun4.core.handlers;
import java.util.Arrays;
+import java.util.List;
+
+import javax.annotation.Nonnull;
import org.apache.commons.lang.Validate;
import org.bukkit.Material;
@@ -10,7 +13,6 @@ import org.bukkit.block.data.BlockData;
import org.bukkit.block.data.type.GlassPane;
import io.github.thebusybiscuit.cscorelib2.collections.LoopIterator;
-import io.github.thebusybiscuit.cscorelib2.materials.MaterialCollection;
import io.github.thebusybiscuit.slimefun4.api.MinecraftVersion;
import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin;
import io.github.thebusybiscuit.slimefun4.implementation.items.blocks.RainbowBlock;
@@ -34,18 +36,22 @@ public class RainbowTickHandler extends BlockTicker {
private final boolean glassPanes;
private Material material;
- public RainbowTickHandler(Material... materials) {
+ public RainbowTickHandler(@Nonnull List materials) {
Validate.noNullElements(materials, "A RainbowTicker cannot have a Material that is null!");
- if (materials.length == 0) {
+ if (materials.isEmpty()) {
throw new IllegalArgumentException("A RainbowTicker must have at least one Material associated with it!");
}
glassPanes = containsGlassPanes(materials);
- iterator = new LoopIterator<>(Arrays.asList(materials));
+ iterator = new LoopIterator<>(materials);
material = iterator.next();
}
+ public RainbowTickHandler(Material... materials) {
+ this(Arrays.asList(materials));
+ }
+
/**
* This method checks whether a given {@link Material} array contains any {@link Material}
* that would result in a {@link GlassPane} {@link BlockData}.
@@ -57,7 +63,7 @@ public class RainbowTickHandler extends BlockTicker {
*
* @return Whether the array contained any {@link GlassPane} materials
*/
- private boolean containsGlassPanes(Material[] materials) {
+ private boolean containsGlassPanes(@Nonnull List materials) {
if (SlimefunPlugin.getMinecraftVersion() == MinecraftVersion.UNIT_TEST) {
// BlockData is not available to us during Unit Tests :/
return false;
@@ -75,10 +81,6 @@ public class RainbowTickHandler extends BlockTicker {
return false;
}
- public RainbowTickHandler(MaterialCollection collection) {
- this(collection.getAsArray());
- }
-
@Override
public void tick(Block b, SlimefunItem item, Config data) {
if (b.getType() == Material.AIR) {
diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/MetricsService.java b/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/MetricsService.java
index 2da170c23..5835e9f86 100644
--- a/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/MetricsService.java
+++ b/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/MetricsService.java
@@ -48,12 +48,7 @@ public class MetricsService {
private boolean hasDownloadedUpdate = false;
static {
- Unirest.config()
- .concurrency(2, 1)
- .setDefaultHeader("User-Agent", "MetricsModule Auto-Updater")
- .setDefaultHeader("Accept", "application/vnd.github.v3+json")
- .enableCookieManagement(false)
- .cookieSpec("ignoreCookies");
+ Unirest.config().concurrency(2, 1).setDefaultHeader("User-Agent", "MetricsModule Auto-Updater").setDefaultHeader("Accept", "application/vnd.github.v3+json").enableCookieManagement(false).cookieSpec("ignoreCookies");
}
public MetricsService(@Nonnull SlimefunPlugin plugin) {
@@ -221,7 +216,7 @@ public class MetricsService {
return true;
}
} catch (UnirestException e) {
- plugin.getLogger().log(Level.WARNING, "Failed to fetch the latest jar file from the builds page. Perhaps GitHub is down?");
+ plugin.getLogger().log(Level.WARNING, "Failed to fetch the latest jar file from the builds page. Perhaps GitHub is down? Response: {0}", e.getMessage());
} catch (IOException e) {
plugin.getLogger().log(Level.WARNING, "Failed to replace the old metric file with the new one. Please do this manually! Error: {0}", e.getMessage());
}
diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/localization/SlimefunLocalization.java b/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/localization/SlimefunLocalization.java
index 390f3a469..dc1bea4b1 100644
--- a/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/localization/SlimefunLocalization.java
+++ b/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/localization/SlimefunLocalization.java
@@ -85,7 +85,7 @@ public abstract class SlimefunLocalization extends Localization implements Keyed
protected abstract void addLanguage(@Nonnull String id, @Nonnull String texture);
protected void loadEmbeddedLanguages() {
- for (SupportedLanguage lang : SupportedLanguage.values) {
+ for (SupportedLanguage lang : SupportedLanguage.valuesCache) {
if (lang.isReadyForRelease() || SlimefunPlugin.getUpdater().getBranch() != SlimefunBranch.STABLE) {
addLanguage(lang.getLanguageId(), lang.getTexture());
}
diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/localization/SupportedLanguage.java b/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/localization/SupportedLanguage.java
index 76287f772..a6381a059 100644
--- a/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/localization/SupportedLanguage.java
+++ b/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/localization/SupportedLanguage.java
@@ -58,7 +58,7 @@ enum SupportedLanguage {
MACEDONIAN("mk", false, "a0e0b0b5d87a855466980a101a757bcdb5f77d9f7287889f3efa998ee0472fc0"),
TAGALOG("tl", true, "9306c0c1ce6a9c61bb42a572c49e6d0ed20e0e6b3d122cc64c339cbf78e9e937");
- public static final SupportedLanguage[] values = values();
+ public static final SupportedLanguage[] valuesCache = values();
private final String id;
private final boolean releaseReady;
diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/localization/Translators.java b/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/localization/Translators.java
index 80a235dbe..dd5f95a95 100644
--- a/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/localization/Translators.java
+++ b/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/localization/Translators.java
@@ -99,6 +99,9 @@ public class Translators {
addTranslator("Dr4gonD", "DragonD", SupportedLanguage.DUTCH, true);
addTranslator("svr333", SupportedLanguage.DUTCH, false);
addTranslator("PabloMarcendo", SupportedLanguage.DUTCH, true);
+ addTranslator("milvantiou", SupportedLanguage.DUTCH, true);
+ addTranslator("Sven313D", SupportedLanguage.DUTCH, true);
+ addTranslator("TypischTeun", SupportedLanguage.DUTCH, true);
// Translators - Danish
addTranslator("Mini-kun", SupportedLanguage.DANISH, true);
diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/profiler/PerformanceRating.java b/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/profiler/PerformanceRating.java
index b03191c6c..b1417b523 100644
--- a/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/profiler/PerformanceRating.java
+++ b/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/profiler/PerformanceRating.java
@@ -31,7 +31,7 @@ public enum PerformanceRating implements Predicate {
HURTFUL(ChatColor.DARK_RED, 500),
BAD(ChatColor.DARK_RED, Float.MAX_VALUE);
- public static final PerformanceRating[] values = values();
+ public static final PerformanceRating[] valuesCache = values();
private final ChatColor color;
private final float threshold;
diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/profiler/SlimefunProfiler.java b/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/profiler/SlimefunProfiler.java
index d123c37c4..7381abae3 100644
--- a/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/profiler/SlimefunProfiler.java
+++ b/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/profiler/SlimefunProfiler.java
@@ -296,7 +296,7 @@ public class SlimefunProfiler {
public PerformanceRating getPerformance() {
float percentage = getPercentageOfTick();
- for (PerformanceRating rating : PerformanceRating.values) {
+ for (PerformanceRating rating : PerformanceRating.valuesCache) {
if (rating.test(percentage)) {
return rating;
}
diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/SlimefunPlugin.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/SlimefunPlugin.java
index ffab307ba..b2656d623 100644
--- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/SlimefunPlugin.java
+++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/SlimefunPlugin.java
@@ -30,6 +30,7 @@ import io.github.thebusybiscuit.cscorelib2.protection.ProtectionManager;
import io.github.thebusybiscuit.cscorelib2.reflection.ReflectionUtils;
import io.github.thebusybiscuit.slimefun4.api.MinecraftVersion;
import io.github.thebusybiscuit.slimefun4.api.SlimefunAddon;
+import io.github.thebusybiscuit.slimefun4.api.exceptions.TagMisconfigurationException;
import io.github.thebusybiscuit.slimefun4.api.gps.GPSNetwork;
import io.github.thebusybiscuit.slimefun4.api.player.PlayerProfile;
import io.github.thebusybiscuit.slimefun4.core.SlimefunRegistry;
@@ -99,6 +100,7 @@ import io.github.thebusybiscuit.slimefun4.implementation.setup.SlimefunItemSetup
import io.github.thebusybiscuit.slimefun4.implementation.tasks.ArmorTask;
import io.github.thebusybiscuit.slimefun4.implementation.tasks.SlimefunStartupTask;
import io.github.thebusybiscuit.slimefun4.implementation.tasks.TickerTask;
+import io.github.thebusybiscuit.slimefun4.utils.tags.SlimefunTag;
import io.papermc.lib.PaperLib;
import me.mrCookieSlime.CSCoreLibPlugin.CSCoreLib;
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.abstractItems.AContainer;
@@ -175,7 +177,6 @@ public final class SlimefunPlugin extends JavaPlugin implements SlimefunAddon {
registry.load(config);
} else if (getServer().getPluginManager().isPluginEnabled("CS-CoreLib")) {
long timestamp = System.nanoTime();
-
PaperLib.suggestPaper(this);
// We wanna ensure that the Server uses a compatible version of Minecraft
@@ -228,6 +229,9 @@ public final class SlimefunPlugin extends JavaPlugin implements SlimefunAddon {
getLogger().log(Level.INFO, "Loading GEO-Resources...");
GEOResourcesSetup.setup();
+ getLogger().log(Level.INFO, "Loading Tags...");
+ loadTags();
+
getLogger().log(Level.INFO, "Loading items...");
loadItems();
@@ -310,7 +314,7 @@ public final class SlimefunPlugin extends JavaPlugin implements SlimefunAddon {
String currentVersion = ReflectionUtils.getVersion();
if (currentVersion.startsWith("v")) {
- for (MinecraftVersion version : MinecraftVersion.values) {
+ for (MinecraftVersion version : MinecraftVersion.valuesCache) {
if (version.matches(currentVersion)) {
minecraftVersion = version;
return false;
@@ -337,7 +341,7 @@ public final class SlimefunPlugin extends JavaPlugin implements SlimefunAddon {
private Collection getSupportedVersions() {
List list = new ArrayList<>();
- for (MinecraftVersion version : MinecraftVersion.values) {
+ for (MinecraftVersion version : MinecraftVersion.valuesCache) {
if (version != MinecraftVersion.UNKNOWN) {
list.add(version.getName());
}
@@ -489,6 +493,16 @@ public final class SlimefunPlugin extends JavaPlugin implements SlimefunAddon {
new PlayerProfileListener(this);
}
+ private void loadTags() {
+ for (SlimefunTag tag : SlimefunTag.valuesCache) {
+ try {
+ tag.reload();
+ } catch (TagMisconfigurationException e) {
+ getLogger().log(Level.SEVERE, e, () -> "Failed to load Tag: " + tag.name());
+ }
+ }
+ }
+
private void loadItems() {
try {
SlimefunItemSetup.setup(this);
diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/guide/ChestSlimefunGuide.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/guide/ChestSlimefunGuide.java
index 5ca33706b..4f346f291 100644
--- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/guide/ChestSlimefunGuide.java
+++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/guide/ChestSlimefunGuide.java
@@ -233,16 +233,22 @@ public class ChestSlimefunGuide implements SlimefunGuideImplementation {
menu.addItem(46, ChestMenuUtils.getPreviousButton(p, page, pages));
menu.addMenuClickHandler(46, (pl, slot, item, action) -> {
int next = page - 1;
- if (next != page && next > 0)
+
+ if (next != page && next > 0) {
openCategory(profile, category, next);
+ }
+
return false;
});
menu.addItem(52, ChestMenuUtils.getNextButton(p, page, pages));
menu.addMenuClickHandler(52, (pl, slot, item, action) -> {
int next = page + 1;
- if (next != page && next <= pages)
+
+ if (next != page && next <= pages) {
openCategory(profile, category, next);
+ }
+
return false;
});
diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/androids/FisherAndroid.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/androids/FisherAndroid.java
index 085895521..d2e9ce0c3 100644
--- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/androids/FisherAndroid.java
+++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/androids/FisherAndroid.java
@@ -4,12 +4,12 @@ import java.util.concurrent.ThreadLocalRandom;
import org.bukkit.Material;
import org.bukkit.Sound;
+import org.bukkit.Tag;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.inventory.ItemStack;
import io.github.thebusybiscuit.cscorelib2.collections.RandomizedSet;
-import io.github.thebusybiscuit.cscorelib2.materials.MaterialCollections;
import io.github.thebusybiscuit.slimefun4.api.MinecraftVersion;
import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin;
import me.mrCookieSlime.Slimefun.Lists.RecipeType;
@@ -25,7 +25,7 @@ public class FisherAndroid extends ProgrammableAndroid {
super(category, tier, item, recipeType, recipe);
// Fish
- for (Material fish : MaterialCollections.getAllFishItems()) {
+ for (Material fish : Tag.ITEMS_FISHES.getValues()) {
fishingLoot.add(new ItemStack(fish), 25);
}
diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/androids/Instruction.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/androids/Instruction.java
index e80029472..4a2083b05 100644
--- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/androids/Instruction.java
+++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/androids/Instruction.java
@@ -146,18 +146,18 @@ enum Instruction {
});
private static final Map nameLookup = new HashMap<>();
- public static final Instruction[] values = values();
+ public static final Instruction[] valuesCache = values();
+
+ static {
+ for (Instruction instruction : valuesCache) {
+ nameLookup.put(instruction.name(), instruction);
+ }
+ }
private final ItemStack item;
private final AndroidType type;
private final AndroidAction method;
- static {
- for (Instruction instruction : values) {
- nameLookup.put(instruction.name(), instruction);
- }
- }
-
@ParametersAreNonnullByDefault
Instruction(AndroidType type, HeadTexture head, @Nullable AndroidAction method) {
this.type = type;
@@ -198,7 +198,7 @@ enum Instruction {
* @return The {@link Instruction} or null if it does not exist.
*/
@Nullable
- public static Instruction getFromCache(@Nonnull String value) {
+ public static Instruction getInstruction(@Nonnull String value) {
Validate.notNull(value, "An Instruction cannot be null!");
return nameLookup.get(value);
}
diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/androids/MinerAndroid.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/androids/MinerAndroid.java
index f082b68f5..4328e6c0e 100644
--- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/androids/MinerAndroid.java
+++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/androids/MinerAndroid.java
@@ -11,10 +11,10 @@ import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.inventory.ItemStack;
-import io.github.thebusybiscuit.cscorelib2.materials.MaterialCollections;
import io.github.thebusybiscuit.cscorelib2.protection.ProtectableAction;
import io.github.thebusybiscuit.slimefun4.api.events.AndroidMineEvent;
import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin;
+import io.github.thebusybiscuit.slimefun4.utils.tags.SlimefunTag;
import me.mrCookieSlime.Slimefun.Lists.RecipeType;
import me.mrCookieSlime.Slimefun.Objects.Category;
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem;
@@ -40,7 +40,7 @@ public class MinerAndroid extends ProgrammableAndroid {
protected void dig(Block b, BlockMenu menu, Block block) {
Collection drops = block.getDrops(effectivePickaxe);
- if (!MaterialCollections.getAllUnbreakableBlocks().contains(block.getType()) && !drops.isEmpty()) {
+ if (!SlimefunTag.UNBREAKABLE_MATERIALS.isTagged(block.getType()) && !drops.isEmpty()) {
OfflinePlayer owner = Bukkit.getOfflinePlayer(UUID.fromString(BlockStorage.getLocationInfo(b.getLocation(), "owner")));
if (SlimefunPlugin.getProtectionManager().hasPermission(owner, block.getLocation(), ProtectableAction.BREAK_BLOCK)) {
@@ -71,7 +71,7 @@ public class MinerAndroid extends ProgrammableAndroid {
protected void moveAndDig(Block b, BlockMenu menu, BlockFace face, Block block) {
Collection drops = block.getDrops(effectivePickaxe);
- if (!MaterialCollections.getAllUnbreakableBlocks().contains(block.getType()) && !drops.isEmpty()) {
+ if (!SlimefunTag.UNBREAKABLE_MATERIALS.isTagged(block.getType()) && !drops.isEmpty()) {
OfflinePlayer owner = Bukkit.getOfflinePlayer(UUID.fromString(BlockStorage.getLocationInfo(b.getLocation(), "owner")));
if (SlimefunPlugin.getProtectionManager().hasPermission(owner, block.getLocation(), ProtectableAction.BREAK_BLOCK)) {
diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/androids/ProgrammableAndroid.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/androids/ProgrammableAndroid.java
index be15a49e3..fb4c80a3d 100644
--- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/androids/ProgrammableAndroid.java
+++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/androids/ProgrammableAndroid.java
@@ -257,7 +257,7 @@ public class ProgrammableAndroid extends SlimefunItem implements InventoryBlock,
return false;
});
} else {
- Instruction instruction = Instruction.getFromCache(script[i]);
+ Instruction instruction = Instruction.getInstruction(script[i]);
if (instruction == null) {
SlimefunPlugin.instance().getLogger().log(Level.WARNING, "Failed to parse Android instruction: {0}, maybe your server is out of date?", script[i]);
@@ -493,7 +493,7 @@ public class ProgrammableAndroid extends SlimefunItem implements InventoryBlock,
protected List getValidScriptInstructions() {
List list = new ArrayList<>();
- for (Instruction part : Instruction.values) {
+ for (Instruction part : Instruction.valuesCache) {
if (part == Instruction.START || part == Instruction.REPEAT) {
continue;
}
@@ -646,7 +646,7 @@ public class ProgrammableAndroid extends SlimefunItem implements InventoryBlock,
}
BlockStorage.addBlockInfo(b, "fuel", String.valueOf(fuel - 1));
- Instruction instruction = Instruction.getFromCache(script[index]);
+ Instruction instruction = Instruction.getInstruction(script[index]);
if (instruction == null) {
SlimefunPlugin.instance().getLogger().log(Level.WARNING, "Failed to parse Android instruction: {0}, maybe your server is out of date?", script[index]);
diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/androids/Script.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/androids/Script.java
index 2b623dbc5..5d97975f7 100644
--- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/androids/Script.java
+++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/androids/Script.java
@@ -9,6 +9,9 @@ import java.util.List;
import java.util.UUID;
import java.util.logging.Level;
+import javax.annotation.Nonnull;
+import javax.annotation.ParametersAreNonnullByDefault;
+
import org.apache.commons.lang.Validate;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
@@ -22,6 +25,12 @@ import io.github.thebusybiscuit.slimefun4.utils.ChatUtils;
import io.github.thebusybiscuit.slimefun4.utils.NumberUtils;
import me.mrCookieSlime.Slimefun.api.Slimefun;
+/**
+ * A {@link Script} represents runnable code for a {@link ProgrammableAndroid}.
+ *
+ * @author TheBusyBiscuit
+ *
+ */
public final class Script {
private final Config config;
@@ -29,7 +38,13 @@ public final class Script {
private final String author;
private final String code;
- private Script(Config config) {
+ /**
+ * This constructs a new {@link Script} from the given {@link Config}.
+ *
+ * @param config
+ * The {@link Config}
+ */
+ private Script(@Nonnull Config config) {
Validate.notNull(config);
this.config = config;
@@ -52,6 +67,7 @@ public final class Script {
*
* @return The name
*/
+ @Nonnull
public String getName() {
return name;
}
@@ -62,6 +78,7 @@ public final class Script {
*
* @return The author of this {@link Script}
*/
+ @Nonnull
public String getAuthor() {
return author;
}
@@ -73,6 +90,7 @@ public final class Script {
*
* @return The code for this {@link Script}
*/
+ @Nonnull
public String getSourceCode() {
return code;
}
@@ -86,7 +104,7 @@ public final class Script {
*
* @return Whether the given {@link OfflinePlayer} is the author of this {@link Script}.
*/
- public boolean isAuthor(OfflinePlayer p) {
+ public boolean isAuthor(@Nonnull OfflinePlayer p) {
return p.getUniqueId().equals(config.getUUID("author"));
}
@@ -99,7 +117,7 @@ public final class Script {
*
* @return Whether the given {@link Player} is able to rate this {@link Script}
*/
- public boolean canRate(Player p) {
+ public boolean canRate(@Nonnull Player p) {
if (isAuthor(p)) {
return false;
}
@@ -109,7 +127,8 @@ public final class Script {
return !upvoters.contains(p.getUniqueId().toString()) && !downvoters.contains(p.getUniqueId().toString());
}
- ItemStack getAsItemStack(ProgrammableAndroid android, Player p) {
+ @Nonnull
+ ItemStack getAsItemStack(@Nonnull ProgrammableAndroid android, @Nonnull Player p) {
List lore = new LinkedList<>();
lore.add("&7by &r" + getAuthor());
lore.add("");
@@ -128,6 +147,7 @@ public final class Script {
return new CustomItem(android.getItem(), "&b" + getName(), lore.toArray(new String[0]));
}
+ @Nonnull
private String getScriptRatingPercentage() {
float percentage = getRating();
return NumberUtils.getColorFromPercentage(percentage) + String.valueOf(percentage) + ChatColor.RESET + "% ";
@@ -181,7 +201,7 @@ public final class Script {
config.save();
}
- public void rate(Player p, boolean positive) {
+ public void rate(@Nonnull Player p, boolean positive) {
config.reload();
String path = "rating." + (positive ? "positive" : "negative");
@@ -192,7 +212,8 @@ public final class Script {
config.save();
}
- public static List