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
|
#### Additions
|
||||||
* Added a starting sound for the Ancient Altar
|
* Added a starting sound for the Ancient Altar
|
||||||
|
* Added config option to disable backwards compatibility and improve performance
|
||||||
|
|
||||||
#### Changes
|
#### Changes
|
||||||
* Coolant Cells now last twice as long
|
* Coolant Cells now last twice as long
|
||||||
|
@ -58,6 +58,7 @@ public class SlimefunRegistry {
|
|||||||
private final List<String> researchRanks = new ArrayList<>();
|
private final List<String> researchRanks = new ArrayList<>();
|
||||||
private final Set<UUID> researchingPlayers = new HashSet<>();
|
private final Set<UUID> researchingPlayers = new HashSet<>();
|
||||||
|
|
||||||
|
private boolean backwardsCompatibility;
|
||||||
private boolean automaticallyLoadItems;
|
private boolean automaticallyLoadItems;
|
||||||
private boolean enableResearches;
|
private boolean enableResearches;
|
||||||
private boolean freeCreativeResearches;
|
private boolean freeCreativeResearches;
|
||||||
@ -99,6 +100,7 @@ public class SlimefunRegistry {
|
|||||||
|
|
||||||
researchRanks.addAll(cfg.getStringList("research-ranks"));
|
researchRanks.addAll(cfg.getStringList("research-ranks"));
|
||||||
|
|
||||||
|
backwardsCompatibility = cfg.getBoolean("options.backwards-compatibility");
|
||||||
freeCreativeResearches = cfg.getBoolean("researches.free-in-creative-mode");
|
freeCreativeResearches = cfg.getBoolean("researches.free-in-creative-mode");
|
||||||
researchFireworks = cfg.getBoolean("researches.enable-fireworks");
|
researchFireworks = cfg.getBoolean("researches.enable-fireworks");
|
||||||
}
|
}
|
||||||
@ -115,6 +117,21 @@ public class SlimefunRegistry {
|
|||||||
return automaticallyLoadItems;
|
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) {
|
public void setAutoLoadingMode(boolean mode) {
|
||||||
automaticallyLoadItems = mode;
|
automaticallyLoadItems = mode;
|
||||||
}
|
}
|
||||||
@ -123,10 +140,20 @@ public class SlimefunRegistry {
|
|||||||
return categories;
|
return categories;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This {@link List} contains every {@link SlimefunItem}, even disabled items.
|
||||||
|
*
|
||||||
|
* @return A {@link List} containing every {@link SlimefunItem}
|
||||||
|
*/
|
||||||
public List<SlimefunItem> getAllSlimefunItems() {
|
public List<SlimefunItem> getAllSlimefunItems() {
|
||||||
return slimefunItems;
|
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() {
|
public List<SlimefunItem> getEnabledSlimefunItems() {
|
||||||
return enabledItems;
|
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 AddonsChart());
|
||||||
metrics.addCustomChart(new CommandChart());
|
metrics.addCustomChart(new CommandChart());
|
||||||
metrics.addCustomChart(new ServerSizeChart());
|
metrics.addCustomChart(new ServerSizeChart());
|
||||||
|
metrics.addCustomChart(new CompatibilityModeChart());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -31,15 +31,15 @@ public final class Script {
|
|||||||
this.config = config;
|
this.config = config;
|
||||||
this.name = config.getString("name");
|
this.name = config.getString("name");
|
||||||
this.code = config.getString("code");
|
this.code = config.getString("code");
|
||||||
String author = config.getString("author");
|
String uuid = config.getString("author");
|
||||||
|
|
||||||
Validate.notNull(name);
|
Validate.notNull(name);
|
||||||
Validate.notNull(code);
|
Validate.notNull(code);
|
||||||
Validate.notNull(author);
|
Validate.notNull(uuid);
|
||||||
Validate.notNull(config.getStringList("rating.positive"));
|
Validate.notNull(config.getStringList("rating.positive"));
|
||||||
Validate.notNull(config.getStringList("rating.negative"));
|
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");
|
this.author = player.getName() != null ? player.getName() : config.getString("author_name");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -807,15 +807,18 @@ public class SlimefunItem implements Placeable {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Quite expensive performance-wise
|
// Backwards compatibility
|
||||||
// But necessary for supporting legacy items
|
if (SlimefunPlugin.getMinecraftVersion().isBefore(MinecraftVersion.MINECRAFT_1_14) || SlimefunPlugin.getRegistry().isBackwardsCompatible()) {
|
||||||
for (SlimefunItem sfi : SlimefunPlugin.getRegistry().getAllSlimefunItems()) {
|
// Quite expensive performance-wise
|
||||||
if (sfi.isItem(wrapper)) {
|
// But necessary for supporting legacy items
|
||||||
// If we have to loop all items for the given item, then at least
|
for (SlimefunItem sfi : SlimefunPlugin.getRegistry().getAllSlimefunItems()) {
|
||||||
// set the id via PersistenDataAPI for future performance boosts
|
if (sfi.isItem(wrapper)) {
|
||||||
SlimefunPlugin.getItemDataService().setItemData(item, sfi.getID());
|
// If we have to loop all items for the given item, then at least
|
||||||
|
// set the id via PersistenDataAPI for future performance boosts
|
||||||
|
SlimefunPlugin.getItemDataService().setItemData(item, sfi.getID());
|
||||||
|
|
||||||
return sfi;
|
return sfi;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -5,6 +5,7 @@ options:
|
|||||||
# You can download the latest stable build here: https://thebusybiscuit.github.io/builds/TheBusyBiscuit/Slimefun4/stable/
|
# You can download the latest stable build here: https://thebusybiscuit.github.io/builds/TheBusyBiscuit/Slimefun4/stable/
|
||||||
|
|
||||||
auto-update: true
|
auto-update: true
|
||||||
|
backwards-compatibility: true
|
||||||
chat-prefix: '&a&lSlimefun 4 &7>'
|
chat-prefix: '&a&lSlimefun 4 &7>'
|
||||||
armor-update-interval: 10
|
armor-update-interval: 10
|
||||||
enable-armor-effects: true
|
enable-armor-effects: true
|
||||||
|
@ -5,11 +5,12 @@ import org.bukkit.inventory.ItemStack;
|
|||||||
import me.mrCookieSlime.Slimefun.Lists.RecipeType;
|
import me.mrCookieSlime.Slimefun.Lists.RecipeType;
|
||||||
import me.mrCookieSlime.Slimefun.Objects.Category;
|
import me.mrCookieSlime.Slimefun.Objects.Category;
|
||||||
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem;
|
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem;
|
||||||
|
import me.mrCookieSlime.Slimefun.api.SlimefunItemStack;
|
||||||
|
|
||||||
public class MockSlimefunItem extends SlimefunItem {
|
public class MockSlimefunItem extends SlimefunItem {
|
||||||
|
|
||||||
public MockSlimefunItem(Category category, ItemStack item, String id) {
|
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.Assertions;
|
||||||
import org.junit.jupiter.api.BeforeAll;
|
import org.junit.jupiter.api.BeforeAll;
|
||||||
import org.junit.jupiter.api.Test;
|
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.MockBukkit;
|
||||||
import io.github.thebusybiscuit.cscorelib2.item.CustomItem;
|
import io.github.thebusybiscuit.cscorelib2.item.CustomItem;
|
||||||
@ -147,10 +149,12 @@ public class TestSlimefunItemRegistration {
|
|||||||
Assertions.assertThrows(IllegalArgumentException.class, () -> item.setRecipeType(null));
|
Assertions.assertThrows(IllegalArgumentException.class, () -> item.setRecipeType(null));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@ParameterizedTest
|
||||||
public void testIsItem() {
|
@ValueSource(booleans = { true, false })
|
||||||
|
public void testIsItem(boolean compatibility) {
|
||||||
CustomItem item = new CustomItem(Material.BEACON, "&cItem Test");
|
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);
|
sfItem.register(plugin);
|
||||||
|
|
||||||
Assertions.assertTrue(sfItem.isItem(sfItem.getItem()));
|
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 ItemStack(Material.BEACON)));
|
||||||
Assertions.assertFalse(sfItem.isItem(new CustomItem(Material.REDSTONE, "&cTest")));
|
Assertions.assertFalse(sfItem.isItem(new CustomItem(Material.REDSTONE, "&cTest")));
|
||||||
|
|
||||||
Assertions.assertEquals(sfItem, SlimefunItem.getByItem(item));
|
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)));
|
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.Lists.RecipeType;
|
||||||
import me.mrCookieSlime.Slimefun.Objects.Category;
|
import me.mrCookieSlime.Slimefun.Objects.Category;
|
||||||
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem;
|
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem;
|
||||||
|
import me.mrCookieSlime.Slimefun.api.SlimefunItemStack;
|
||||||
|
|
||||||
public class TestSoulboundItem {
|
public class TestSoulboundItem {
|
||||||
|
|
||||||
@ -84,7 +85,7 @@ public class TestSoulboundItem {
|
|||||||
private class SoulboundMock extends SlimefunItem implements Soulbound {
|
private class SoulboundMock extends SlimefunItem implements Soulbound {
|
||||||
|
|
||||||
public SoulboundMock(Category category) {
|
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