mirror of
https://github.com/StarWishsama/Slimefun4.git
synced 2024-09-19 19:25:48 +00:00
Added a toggle for backwards compatibility
This commit is contained in:
parent
7059ad216c
commit
1456245ee0
@ -23,6 +23,7 @@
|
||||
|
||||
#### Additions
|
||||
* Added a starting sound for the Ancient Altar
|
||||
* Added config option to disable backwards compatibility and improve performance
|
||||
|
||||
#### Changes
|
||||
* Coolant Cells now last twice as long
|
||||
|
@ -58,6 +58,7 @@ public class SlimefunRegistry {
|
||||
private final List<String> researchRanks = new ArrayList<>();
|
||||
private final Set<UUID> researchingPlayers = new HashSet<>();
|
||||
|
||||
private boolean backwardsCompatibility;
|
||||
private boolean automaticallyLoadItems;
|
||||
private boolean enableResearches;
|
||||
private boolean freeCreativeResearches;
|
||||
@ -99,6 +100,7 @@ public class SlimefunRegistry {
|
||||
|
||||
researchRanks.addAll(cfg.getStringList("research-ranks"));
|
||||
|
||||
backwardsCompatibility = cfg.getBoolean("options.backwards-compatibility");
|
||||
freeCreativeResearches = cfg.getBoolean("researches.free-in-creative-mode");
|
||||
researchFireworks = cfg.getBoolean("researches.enable-fireworks");
|
||||
}
|
||||
@ -115,6 +117,21 @@ public class SlimefunRegistry {
|
||||
return automaticallyLoadItems;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method returns whether backwards-compatibility is enabled.
|
||||
* Backwards compatibility allows Slimefun to recognize items from older versions but comes
|
||||
* at a huge performance cost.
|
||||
*
|
||||
* @return Whether backwards compatibility is enabled
|
||||
*/
|
||||
public boolean isBackwardsCompatible() {
|
||||
return backwardsCompatibility;
|
||||
}
|
||||
|
||||
public void setBackwardsCompatible(boolean compatible) {
|
||||
backwardsCompatibility = compatible;
|
||||
}
|
||||
|
||||
public void setAutoLoadingMode(boolean mode) {
|
||||
automaticallyLoadItems = mode;
|
||||
}
|
||||
@ -123,10 +140,20 @@ public class SlimefunRegistry {
|
||||
return categories;
|
||||
}
|
||||
|
||||
/**
|
||||
* This {@link List} contains every {@link SlimefunItem}, even disabled items.
|
||||
*
|
||||
* @return A {@link List} containing every {@link SlimefunItem}
|
||||
*/
|
||||
public List<SlimefunItem> getAllSlimefunItems() {
|
||||
return slimefunItems;
|
||||
}
|
||||
|
||||
/**
|
||||
* This {@link List} contains every <strong>enabled</strong> {@link SlimefunItem}.
|
||||
*
|
||||
* @return A {@link List} containing every enabled {@link SlimefunItem}
|
||||
*/
|
||||
public List<SlimefunItem> getEnabledSlimefunItems() {
|
||||
return enabledItems;
|
||||
}
|
||||
|
@ -0,0 +1,16 @@
|
||||
package io.github.thebusybiscuit.slimefun4.core.services.metrics;
|
||||
|
||||
import org.bstats.bukkit.Metrics.SimplePie;
|
||||
|
||||
import me.mrCookieSlime.Slimefun.SlimefunPlugin;
|
||||
|
||||
class CompatibilityModeChart extends SimplePie {
|
||||
|
||||
CompatibilityModeChart() {
|
||||
super("compatibility_mode", () -> {
|
||||
boolean enabled = SlimefunPlugin.getRegistry().isBackwardsCompatible();
|
||||
return enabled ? "enabled" : "disabled";
|
||||
});
|
||||
}
|
||||
|
||||
}
|
@ -49,6 +49,7 @@ public class MetricsService {
|
||||
metrics.addCustomChart(new AddonsChart());
|
||||
metrics.addCustomChart(new CommandChart());
|
||||
metrics.addCustomChart(new ServerSizeChart());
|
||||
metrics.addCustomChart(new CompatibilityModeChart());
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -31,15 +31,15 @@ public final class Script {
|
||||
this.config = config;
|
||||
this.name = config.getString("name");
|
||||
this.code = config.getString("code");
|
||||
String author = config.getString("author");
|
||||
String uuid = config.getString("author");
|
||||
|
||||
Validate.notNull(name);
|
||||
Validate.notNull(code);
|
||||
Validate.notNull(author);
|
||||
Validate.notNull(uuid);
|
||||
Validate.notNull(config.getStringList("rating.positive"));
|
||||
Validate.notNull(config.getStringList("rating.negative"));
|
||||
|
||||
OfflinePlayer player = Bukkit.getOfflinePlayer(UUID.fromString(author));
|
||||
OfflinePlayer player = Bukkit.getOfflinePlayer(UUID.fromString(uuid));
|
||||
this.author = player.getName() != null ? player.getName() : config.getString("author_name");
|
||||
}
|
||||
|
||||
|
@ -807,6 +807,8 @@ public class SlimefunItem implements Placeable {
|
||||
}
|
||||
}
|
||||
|
||||
// Backwards compatibility
|
||||
if (SlimefunPlugin.getMinecraftVersion().isBefore(MinecraftVersion.MINECRAFT_1_14) || SlimefunPlugin.getRegistry().isBackwardsCompatible()) {
|
||||
// Quite expensive performance-wise
|
||||
// But necessary for supporting legacy items
|
||||
for (SlimefunItem sfi : SlimefunPlugin.getRegistry().getAllSlimefunItems()) {
|
||||
@ -818,6 +820,7 @@ public class SlimefunItem implements Placeable {
|
||||
return sfi;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
@ -5,6 +5,7 @@ options:
|
||||
# You can download the latest stable build here: https://thebusybiscuit.github.io/builds/TheBusyBiscuit/Slimefun4/stable/
|
||||
|
||||
auto-update: true
|
||||
backwards-compatibility: true
|
||||
chat-prefix: '&a&lSlimefun 4 &7>'
|
||||
armor-update-interval: 10
|
||||
enable-armor-effects: true
|
||||
|
@ -5,11 +5,12 @@ import org.bukkit.inventory.ItemStack;
|
||||
import me.mrCookieSlime.Slimefun.Lists.RecipeType;
|
||||
import me.mrCookieSlime.Slimefun.Objects.Category;
|
||||
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem;
|
||||
import me.mrCookieSlime.Slimefun.api.SlimefunItemStack;
|
||||
|
||||
public class MockSlimefunItem extends SlimefunItem {
|
||||
|
||||
public MockSlimefunItem(Category category, ItemStack item, String id) {
|
||||
super(category, item, id, RecipeType.NULL, new ItemStack[9]);
|
||||
super(category, new SlimefunItemStack(id, item), RecipeType.NULL, new ItemStack[9]);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -9,6 +9,8 @@ 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.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.ValueSource;
|
||||
|
||||
import be.seeseemelk.mockbukkit.MockBukkit;
|
||||
import io.github.thebusybiscuit.cscorelib2.item.CustomItem;
|
||||
@ -147,10 +149,12 @@ public class TestSlimefunItemRegistration {
|
||||
Assertions.assertThrows(IllegalArgumentException.class, () -> item.setRecipeType(null));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIsItem() {
|
||||
@ParameterizedTest
|
||||
@ValueSource(booleans = { true, false })
|
||||
public void testIsItem(boolean compatibility) {
|
||||
CustomItem item = new CustomItem(Material.BEACON, "&cItem Test");
|
||||
SlimefunItem sfItem = TestUtilities.mockSlimefunItem(plugin, "IS_ITEM_TEST", item);
|
||||
String id = "IS_ITEM_TEST" + (compatibility ? "_COMPATIBLE" : "");
|
||||
SlimefunItem sfItem = TestUtilities.mockSlimefunItem(plugin, id, item);
|
||||
sfItem.register(plugin);
|
||||
|
||||
Assertions.assertTrue(sfItem.isItem(sfItem.getItem()));
|
||||
@ -161,7 +165,12 @@ public class TestSlimefunItemRegistration {
|
||||
Assertions.assertFalse(sfItem.isItem(new ItemStack(Material.BEACON)));
|
||||
Assertions.assertFalse(sfItem.isItem(new CustomItem(Material.REDSTONE, "&cTest")));
|
||||
|
||||
if (compatibility) {
|
||||
SlimefunPlugin.getRegistry().setBackwardsCompatible(true);
|
||||
Assertions.assertEquals(sfItem, SlimefunItem.getByItem(item));
|
||||
SlimefunPlugin.getRegistry().setBackwardsCompatible(false);
|
||||
}
|
||||
|
||||
Assertions.assertEquals(sfItem, SlimefunItem.getByItem(new SlimefunItemStack(sfItem.getID(), item)));
|
||||
}
|
||||
|
||||
|
@ -16,6 +16,7 @@ import me.mrCookieSlime.Slimefun.SlimefunPlugin;
|
||||
import me.mrCookieSlime.Slimefun.Lists.RecipeType;
|
||||
import me.mrCookieSlime.Slimefun.Objects.Category;
|
||||
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem;
|
||||
import me.mrCookieSlime.Slimefun.api.SlimefunItemStack;
|
||||
|
||||
public class TestSoulboundItem {
|
||||
|
||||
@ -84,7 +85,7 @@ public class TestSoulboundItem {
|
||||
private class SoulboundMock extends SlimefunItem implements Soulbound {
|
||||
|
||||
public SoulboundMock(Category category) {
|
||||
super(category, new CustomItem(Material.REDSTONE, "&4Almighty Redstone"), "MOCK_SOULBOUND", RecipeType.NULL, new ItemStack[9]);
|
||||
super(category, new SlimefunItemStack("MOCK_SOULBOUND", Material.REDSTONE, "&4Almighty Redstone"), RecipeType.NULL, new ItemStack[9]);
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user