1
mirror of https://github.com/StarWishsama/Slimefun4.git synced 2024-09-19 19:25:48 +00:00

Removed backwards compatiblity mode (#3896)

This commit is contained in:
J3fftw 2023-07-09 18:10:46 +02:00 committed by GitHub
parent 59a98f1759
commit b04cfcc169
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 7 additions and 110 deletions

View File

@ -39,16 +39,12 @@ import io.github.thebusybiscuit.slimefun4.core.SlimefunRegistry;
import io.github.thebusybiscuit.slimefun4.core.attributes.NotConfigurable;
import io.github.thebusybiscuit.slimefun4.core.attributes.Placeable;
import io.github.thebusybiscuit.slimefun4.core.attributes.Radioactive;
import io.github.thebusybiscuit.slimefun4.core.attributes.Rechargeable;
import io.github.thebusybiscuit.slimefun4.core.guide.SlimefunGuide;
import io.github.thebusybiscuit.slimefun4.core.handlers.GlobalItemHandler;
import io.github.thebusybiscuit.slimefun4.implementation.Slimefun;
import io.github.thebusybiscuit.slimefun4.implementation.items.VanillaItem;
import io.github.thebusybiscuit.slimefun4.implementation.items.backpacks.SlimefunBackpack;
import io.github.thebusybiscuit.slimefun4.implementation.items.electric.machines.enchanting.AutoDisenchanter;
import io.github.thebusybiscuit.slimefun4.implementation.items.electric.machines.enchanting.AutoEnchanter;
import io.github.thebusybiscuit.slimefun4.utils.SlimefunUtils;
import io.github.thebusybiscuit.slimefun4.utils.itemstack.ItemStackWrapper;
import me.mrCookieSlime.Slimefun.Objects.handlers.BlockTicker;
@ -767,13 +763,7 @@ public class SlimefunItem implements Placeable {
}
}
// Backwards compatibility
if (Slimefun.getRegistry().isBackwardsCompatible()) {
boolean loreInsensitive = this instanceof Rechargeable || this instanceof SlimefunBackpack || id.equals("BROKEN_SPAWNER") || id.equals("REINFORCED_SPAWNER");
return SlimefunUtils.isItemSimilar(item, this.itemStackTemplate, !loreInsensitive);
} else {
return false;
}
return false;
}
/**
@ -1179,33 +1169,8 @@ public class SlimefunItem implements Placeable {
Optional<String> itemID = Slimefun.getItemDataService().getItemData(item);
if (itemID.isPresent()) {
return getById(itemID.get());
}
return itemID.map(SlimefunItem::getById).orElse(null);
// Backwards compatibility
if (Slimefun.getRegistry().isBackwardsCompatible()) {
// This wrapper improves the heavy ItemStack#getItemMeta() call by caching it.
ItemStackWrapper wrapper = ItemStackWrapper.wrap(item);
/*
* Quite expensive performance-wise.
* But necessary for supporting legacy items
*/
for (SlimefunItem sfi : Slimefun.getRegistry().getAllSlimefunItems()) {
if (sfi.isItem(wrapper)) {
/*
* If we have to loop all items for the given item, then at least
* set the id via PersistentDataAPI for future performance boosts
*/
Slimefun.getItemDataService().setItemData(item, sfi.getId());
return sfi;
}
}
}
return null;
}
}

View File

@ -65,7 +65,6 @@ public final class SlimefunRegistry {
private final Set<UUID> researchingPlayers = Collections.synchronizedSet(new HashSet<>());
// TODO: Move this all into a proper "config cache" class
private boolean backwardsCompatibility;
private boolean automaticallyLoadItems;
private boolean enableResearches;
private boolean freeCreativeResearches;
@ -109,7 +108,6 @@ public final 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");
disableLearningAnimation = cfg.getBoolean("researches.disable-learning-animation");
@ -129,29 +127,6 @@ public final 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;
}
/**
* This method sets the status of backwards compatibility.
* Backwards compatibility allows Slimefun to recognize items from older versions but comes
* at a huge performance cost.
*
* @param compatible
* Whether backwards compatibility should be enabled
*/
public void setBackwardsCompatible(boolean compatible) {
backwardsCompatibility = compatible;
}
/**
* This method will make any {@link SlimefunItem} which is registered automatically
* call {@link SlimefunItem#load()}.

View File

@ -83,18 +83,6 @@ class VersionsCommand extends SubCommand {
addJavaVersion(builder);
if (Slimefun.getRegistry().isBackwardsCompatible()) {
// @formatter:off
HoverEvent hoverEvent = new HoverEvent(HoverEvent.Action.SHOW_TEXT, new Text(
"Backwards compatibility has a negative impact on performance!\n" +
"We recommend you to disable this setting unless your server still " +
"has legacy Slimefun items (from before summer 2019) in circulation."
));
// @formatter:on
builder.append("\nBackwards compatibility enabled!\n").color(ChatColor.RED).event(hoverEvent);
}
builder.append("\n").event((HoverEvent) null);
addPluginVersions(builder);

View File

@ -129,12 +129,6 @@ public class ArmorTask implements Runnable {
private void checkForSolarHelmet(@Nonnull Player p) {
ItemStack helmet = p.getInventory().getHelmet();
if (Slimefun.getRegistry().isBackwardsCompatible() && !SlimefunUtils.isItemSimilar(helmet, SlimefunItems.SOLAR_HELMET, true, false)) {
// Performance saver for slow backwards-compatible versions of Slimefun
return;
}
SlimefunItem item = SlimefunItem.getByItem(helmet);
if (item instanceof SolarHelmet solarHelmet && item.canUse(p, true)) {

View File

@ -7,14 +7,10 @@ import org.bukkit.World;
import org.bukkit.World.Environment;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.potion.PotionEffect;
import io.github.thebusybiscuit.slimefun4.api.items.SlimefunItem;
import io.github.thebusybiscuit.slimefun4.api.player.PlayerProfile;
import io.github.thebusybiscuit.slimefun4.core.attributes.Radioactive;
import io.github.thebusybiscuit.slimefun4.implementation.Slimefun;
import io.github.thebusybiscuit.slimefun4.implementation.SlimefunItems;
import io.github.thebusybiscuit.slimefun4.implementation.items.armor.SlimefunArmorPiece;
import io.github.thebusybiscuit.slimefun4.implementation.items.electric.gadgets.SolarHelmet;
import io.github.thebusybiscuit.slimefun4.utils.SlimefunUtils;
@ -38,12 +34,6 @@ public class SolarHelmetTask extends AbstractArmorTask {
private void checkForSolarHelmet(@Nonnull Player p) {
ItemStack helmet = p.getInventory().getHelmet();
if (Slimefun.getRegistry().isBackwardsCompatible() && !SlimefunUtils.isItemSimilar(helmet, SlimefunItems.SOLAR_HELMET, true, false)) {
// Performance saver for slow backwards-compatible versions of Slimefun
return;
}
SlimefunItem item = SlimefunItem.getByItem(helmet);
if (item instanceof SolarHelmet solarHelmet && item.canUse(p, true)) {

View File

@ -5,7 +5,6 @@ options:
# You can download the latest stable build here: https://thebusybiscuit.github.io/builds/TheBusyBiscuit/Slimefun4/stable/
auto-update: true
backwards-compatibility: false
chat-prefix: '&a&lSlimefun 4&7> '
armor-update-interval: 10
enable-armor-effects: true

View File

@ -105,12 +105,11 @@ class TestSlimefunItem {
Assertions.assertThrows(IllegalArgumentException.class, () -> item.setRecipeType(null));
}
@ParameterizedTest
@Test
@DisplayName("Test SlimefunItem#isItem(...)")
@ValueSource(booleans = { true, false })
void testIsItem(boolean compatibility) {
void testIsItem() {
ItemStack item = new CustomItemStack(Material.BEACON, "&cItem Test");
String id = "IS_ITEM_TEST" + (compatibility ? "_COMPATIBLE" : "");
String id = "IS_ITEM_TEST";
SlimefunItem sfItem = TestUtilities.mockSlimefunItem(plugin, id, item);
sfItem.register(plugin);
@ -119,19 +118,8 @@ class TestSlimefunItem {
Assertions.assertFalse(sfItem.isItem(null));
Assertions.assertFalse(sfItem.isItem(new ItemStack(Material.BEACON)));
Assertions.assertFalse(sfItem.isItem(new CustomItemStack(Material.REDSTONE, "&cTest")));
if (compatibility) {
Slimefun.getRegistry().setBackwardsCompatible(true);
Assertions.assertEquals(sfItem, SlimefunItem.getByItem(item));
Assertions.assertTrue(sfItem.isItem(item));
Assertions.assertTrue(sfItem.isItem(new CustomItemStack(Material.BEACON, "&cItem Test")));
Slimefun.getRegistry().setBackwardsCompatible(false);
} else {
Assertions.assertFalse(sfItem.isItem(item));
Assertions.assertFalse(sfItem.isItem(new CustomItemStack(Material.BEACON, "&cItem Test")));
}
Assertions.assertFalse(sfItem.isItem(item));
Assertions.assertFalse(sfItem.isItem(new CustomItemStack(Material.BEACON, "&cItem Test")));
Assertions.assertEquals(sfItem, SlimefunItem.getByItem(new SlimefunItemStack(sfItem.getId(), item)));
}

View File

@ -100,7 +100,6 @@ class TestCargoNodeListener {
@Test
@DisplayName("Test non-Cargo node not being affected")
void testNonCargoNode() {
Slimefun.getRegistry().setBackwardsCompatible(true);
Player player = server.addPlayer();
Location l = new Location(player.getWorld(), 190, 50, 400);
Block b = l.getBlock();
@ -111,7 +110,6 @@ class TestCargoNodeListener {
BlockPlaceEvent event = new BlockPlaceEvent(b, b.getState(), against, item, player, true, EquipmentSlot.HAND);
listener.onCargoNodePlace(event);
Assertions.assertFalse(event.isCancelled());
Slimefun.getRegistry().setBackwardsCompatible(false);
}
}