From 7ffe08c8b7d66374d807828c4acf63aa580ec4bf Mon Sep 17 00:00:00 2001 From: mcchampions <1309635304@qq.com> Date: Sun, 29 Sep 2024 21:39:28 +0800 Subject: [PATCH] =?UTF-8?q?chore:=20=E7=A7=BB=E9=99=A4=E6=97=A0=E7=94=A8?= =?UTF-8?q?=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../norain/slimefun4/EnvironmentChecker.java | 16 ---- .../storage/controller/ScopedLock.java | 3 - .../api/items/SlimefunItemStack.java | 5 -- .../slimefun4/api/player/PlayerProfile.java | 9 -- .../networks/cargo/AbstractItemNetwork.java | 22 +---- .../core/networks/cargo/CargoUtils.java | 89 ------------------- .../services/profiler/SummaryOrderType.java | 26 +----- .../slimefun4/implementation/Slimefun.java | 13 --- .../multiblocks/miner/OreDictionary.java | 6 -- .../listeners/BlockListener.java | 19 ---- .../utils/biomes/BiomeMapParser.java | 4 +- .../CSCoreLibPlugin/Configuration/Config.java | 1 - 12 files changed, 4 insertions(+), 209 deletions(-) diff --git a/src/main/java/city/norain/slimefun4/EnvironmentChecker.java b/src/main/java/city/norain/slimefun4/EnvironmentChecker.java index c8e0f52764..2e154eed62 100644 --- a/src/main/java/city/norain/slimefun4/EnvironmentChecker.java +++ b/src/main/java/city/norain/slimefun4/EnvironmentChecker.java @@ -23,20 +23,4 @@ static boolean checkIncompatiblePlugins(Logger logger) { return true; } - static boolean checkHybridServer() { - try { - Class.forName("cpw.mods.modlauncher.Launcher"); - Class.forName("net.minecraftforge.server.console.TerminalHandler"); - - return true; - } catch (ClassNotFoundException ignored) { - if (Bukkit.getPluginCommand("mohist") != null) { - return true; - } - - var serverVer = Bukkit.getVersion().toLowerCase(); - - return serverVer.contains("arclight") || serverVer.contains("mohist"); - } - } } diff --git a/src/main/java/com/xzavier0722/mc/plugin/slimefun4/storage/controller/ScopedLock.java b/src/main/java/com/xzavier0722/mc/plugin/slimefun4/storage/controller/ScopedLock.java index 213eef286a..6c85f75fdf 100644 --- a/src/main/java/com/xzavier0722/mc/plugin/slimefun4/storage/controller/ScopedLock.java +++ b/src/main/java/com/xzavier0722/mc/plugin/slimefun4/storage/controller/ScopedLock.java @@ -29,7 +29,4 @@ void unlock(ScopeKey scopeKey) { } } - boolean hasLock(ScopeKey scopeKey) { - return locks.containsKey(scopeKey); - } } diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/api/items/SlimefunItemStack.java b/src/main/java/io/github/thebusybiscuit/slimefun4/api/items/SlimefunItemStack.java index 4d91e41940..ee9e970656 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/api/items/SlimefunItemStack.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/api/items/SlimefunItemStack.java @@ -49,11 +49,6 @@ public SlimefunItemStack(String id, ItemStack item) { if (item.hasItemMeta()) { setItemMeta(item.getItemMeta()); } - if (Slimefun.instance() == null) { - throw new PrematureCodeException( - "A SlimefunItemStack must never be be created before your Plugin was enabled."); - } - this.id = id; ItemMeta meta = getItemMeta(); diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/api/player/PlayerProfile.java b/src/main/java/io/github/thebusybiscuit/slimefun4/api/player/PlayerProfile.java index d7f5e8e4d8..cd1704a882 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/api/player/PlayerProfile.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/api/player/PlayerProfile.java @@ -8,7 +8,6 @@ import io.github.thebusybiscuit.slimefun4.api.events.AsyncProfileLoadEvent; import io.github.thebusybiscuit.slimefun4.api.gps.Waypoint; import io.github.thebusybiscuit.slimefun4.api.items.HashedArmorpiece; -import io.github.thebusybiscuit.slimefun4.api.items.ItemState; import io.github.thebusybiscuit.slimefun4.api.researches.Research; import io.github.thebusybiscuit.slimefun4.core.attributes.ProtectionType; import io.github.thebusybiscuit.slimefun4.core.attributes.ProtectiveArmor; @@ -445,14 +444,6 @@ public boolean isInvalid() { return isInvalid; } - // returns the amount of researches with at least 1 enabled item - private int nonEmptyResearches() { - return (int) Slimefun.getRegistry().getResearches().stream() - .filter(research -> - research.getAffectedItems().stream().anyMatch(item -> item.getState() == ItemState.ENABLED)) - .count(); - } - private static void getOrCreate(OfflinePlayer p, Consumer cb) { var controller = Slimefun.getDatabaseManager().getProfileDataController(); controller.getProfileAsync(p, new IAsyncReadCallback<>() { diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/core/networks/cargo/AbstractItemNetwork.java b/src/main/java/io/github/thebusybiscuit/slimefun4/core/networks/cargo/AbstractItemNetwork.java index 1b267239e6..c4cce6591d 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/core/networks/cargo/AbstractItemNetwork.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/core/networks/cargo/AbstractItemNetwork.java @@ -2,12 +2,10 @@ import io.github.thebusybiscuit.slimefun4.api.network.Network; import io.github.thebusybiscuit.slimefun4.implementation.Slimefun; -import io.github.thebusybiscuit.slimefun4.utils.SlimefunUtils; + import java.util.HashMap; -import java.util.List; import java.util.Map; import java.util.Optional; -import javax.annotation.Nullable; import org.bukkit.Location; import org.bukkit.Material; @@ -15,7 +13,6 @@ import org.bukkit.block.BlockFace; import org.bukkit.block.data.BlockData; import org.bukkit.block.data.Directional; -import org.bukkit.inventory.ItemStack; /** * An abstract super class of {@link CargoNet} that handles @@ -83,23 +80,6 @@ public void markCargoNodeConfigurationDirty(Location node) { connectorCache.remove(node); } - private void filter(@Nullable ItemStack stack, List items, Location node) { - if (stack != null && CargoUtils.matchesFilter(this, node.getBlock(), stack)) { - boolean add = true; - - for (ItemStackAndInteger item : items) { - if (SlimefunUtils.isItemSimilar(stack, item.getItemStackWrapper(), true, false)) { - add = false; - item.add(stack.getAmount()); - } - } - - if (add) { - items.add(new ItemStackAndInteger(stack, stack.getAmount())); - } - } - } - protected ItemFilter getItemFilter(Block node) { Location loc = node.getLocation(); ItemFilter filter = filterCache.get(loc); diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/core/networks/cargo/CargoUtils.java b/src/main/java/io/github/thebusybiscuit/slimefun4/core/networks/cargo/CargoUtils.java index 9bdd656dec..664f7c0216 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/core/networks/cargo/CargoUtils.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/core/networks/cargo/CargoUtils.java @@ -105,95 +105,6 @@ static int[] getOutputSlotRange(Inventory inv) { } } - @Nullable - static ItemStack withdraw( - AbstractItemNetwork network, - Map inventories, - Block node, - Block target, - ItemStack template) { - DirtyChestMenu menu = getChestMenu(target); - - if (menu == null) { - if (hasInventory(target)) { - Inventory inventory = inventories.get(target.getLocation()); - - if (inventory != null) { - return withdrawFromVanillaInventory(network, node, template, inventory); - } - - BlockState state = target.getState(false); - - if (state instanceof InventoryHolder inventoryHolder) { - inventory = inventoryHolder.getInventory(); - inventories.put(target.getLocation(), inventory); - return withdrawFromVanillaInventory(network, node, template, inventory); - } - } - - return null; - } - - ItemStackWrapper wrapperTemplate = ItemStackWrapper.wrap(template); - - for (int slot : menu.getPreset().getSlotsAccessedByItemTransport(menu, ItemTransportFlow.WITHDRAW, null)) { - ItemStack is = menu.getItemInSlot(slot); - if (is == null || is.getType().isAir()) { - continue; - } - - ItemStackWrapper wrapperItemInSlot = ItemStackWrapper.wrap(is); - - if (SlimefunUtils.isItemSimilar(wrapperItemInSlot, wrapperTemplate, true) - && matchesFilter(network, node, wrapperItemInSlot)) { - if (is.getAmount() > template.getAmount()) { - is.setAmount(is.getAmount() - template.getAmount()); - menu.replaceExistingItem(slot, is); - return template; - } else { - menu.replaceExistingItem(slot, null); - return is; - } - } - } - - return null; - } - - @Nullable - static ItemStack withdrawFromVanillaInventory( - AbstractItemNetwork network, Block node, ItemStack template, Inventory inv) { - ItemStack[] contents = inv.getContents(); - int[] range = getOutputSlotRange(inv); - int minSlot = range[0]; - int maxSlot = range[1]; - - ItemStackWrapper wrapper = ItemStackWrapper.wrap(template); - - for (int slot = minSlot; slot < maxSlot; slot++) { - // Changes to these ItemStacks are synchronized with the Item in the Inventory - ItemStack itemInSlot = contents[slot]; - if (itemInSlot == null || itemInSlot.getType().isAir()) { - continue; - } - - ItemStackWrapper wrapperInSlot = ItemStackWrapper.wrap(itemInSlot); - if (SlimefunUtils.isItemSimilar(wrapperInSlot, wrapper, true, false) - && matchesFilter(network, node, wrapperInSlot)) { - if (itemInSlot.getAmount() > template.getAmount()) { - itemInSlot.setAmount(itemInSlot.getAmount() - template.getAmount()); - return template; - } else { - ItemStack clone = itemInSlot.clone(); - itemInSlot.setAmount(0); - return clone; - } - } - } - - return null; - } - @Nullable static ItemStackAndInteger withdraw( AbstractItemNetwork network, Map inventories, Block node, Block target) { diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/profiler/SummaryOrderType.java b/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/profiler/SummaryOrderType.java index a0e7532e65..c8943ee74d 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/profiler/SummaryOrderType.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/profiler/SummaryOrderType.java @@ -25,29 +25,5 @@ public enum SummaryOrderType { /** * Sort by average timings (highest to lowest) */ - AVERAGE; - - List> sort(SlimefunProfiler profiler, Set> entrySet) { - switch (this) { - case HIGHEST: - return entrySet.stream() - .sorted(Map.Entry.comparingByValue(Comparator.reverseOrder())) - .collect(Collectors.toList()); - case LOWEST: - return entrySet.stream() - .sorted(Comparator.comparingLong(Map.Entry::getValue)) - .collect(Collectors.toList()); - default: - final Map map = new HashMap<>(); - for (Map.Entry entry : entrySet) { - int count = profiler.getBlocksOfId(entry.getKey()); - long avg = count > 0 ? entry.getValue() / count : entry.getValue(); - - map.put(entry.getKey(), avg); - } - return map.entrySet().stream() - .sorted(Map.Entry.comparingByValue(Comparator.reverseOrder())) - .collect(Collectors.toList()); - } - } + AVERAGE } diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/Slimefun.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/Slimefun.java index 1e2fc5b668..22f49fafe7 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/Slimefun.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/Slimefun.java @@ -601,19 +601,6 @@ private void loadResearches() { return instance; } - /** - * This private static method allows us to throw a proper {@link Exception} - * whenever someone tries to access a static method while the instance is null. - * This happens when the method is invoked before {@link #onEnable()} or after {@link #onDisable()}. - *

- * Use it whenever a null check is needed to avoid a non-descriptive {@link NullPointerException}. - */ - private static void validateInstance() { - if (instance == null) { - throw new IllegalStateException("Cannot invoke static method, Slimefun instance is null."); - } - } - /** * This method returns out {@link MinecraftRecipeService} for Slimefun. * This service is responsible for finding/identifying {@link Recipe Recipes} diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/multiblocks/miner/OreDictionary.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/multiblocks/miner/OreDictionary.java index 889031d254..bc85a1127e 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/multiblocks/miner/OreDictionary.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/multiblocks/miner/OreDictionary.java @@ -1,6 +1,5 @@ package io.github.thebusybiscuit.slimefun4.implementation.items.multiblocks.miner; -import io.github.thebusybiscuit.slimefun4.api.MinecraftVersion; import java.util.Random; import org.bukkit.Material; @@ -15,11 +14,6 @@ interface OreDictionary { ItemStack getDrops(Material material, Random random); - static OreDictionary forVersion(MinecraftVersion version) { - // MC 1.17 - 1.18 - return new OreDictionary17(); - } - static OreDictionary getInstance() { return new OreDictionary17(); } diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/BlockListener.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/BlockListener.java index 513716a9c8..776c1d0b27 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/BlockListener.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/BlockListener.java @@ -3,7 +3,6 @@ import com.xzavier0722.mc.plugin.slimefun4.storage.callback.IAsyncReadCallback; import com.xzavier0722.mc.plugin.slimefun4.storage.controller.SlimefunBlockData; import com.xzavier0722.mc.plugin.slimefun4.storage.util.StorageCacheUtils; -import io.github.thebusybiscuit.slimefun4.api.MinecraftVersion; import io.github.thebusybiscuit.slimefun4.api.events.ExplosiveToolBreakBlocksEvent; import io.github.thebusybiscuit.slimefun4.api.events.SlimefunBlockBreakEvent; import io.github.thebusybiscuit.slimefun4.api.events.SlimefunBlockPlaceEvent; @@ -23,7 +22,6 @@ import org.bukkit.Material; import org.bukkit.block.Block; import org.bukkit.block.BlockFace; -import org.bukkit.block.data.BlockData; import org.bukkit.block.data.Rotatable; import org.bukkit.enchantments.Enchantment; import org.bukkit.entity.Player; @@ -373,23 +371,6 @@ private void checkForSensitiveBlocks(Block block, Integer count, boolean isDropI } */ - /** - * This method checks if the {@link BlockData} would be - * supported at the given {@link Block}. - * - * @param blockData The {@link BlockData} to check - * @param block The {@link Block} the {@link BlockData} would be at - * @return Whether the {@link BlockData} would be supported at the given {@link Block} - */ - private boolean isSupported(BlockData blockData, Block block) { - if (Slimefun.getMinecraftVersion().isAtLeast(MinecraftVersion.MINECRAFT_1_19)) { - return blockData.isSupported(block); - } else { - // TODO: Make 1.16-1.18 version. BlockData::isSupported is 1.19+. - return true; - } - } - private int getBonusDropsWithFortune(@Nullable ItemStack item, Block b) { int amount = 1; diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/utils/biomes/BiomeMapParser.java b/src/main/java/io/github/thebusybiscuit/slimefun4/utils/biomes/BiomeMapParser.java index d4d5dd4c0f..9a10665201 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/utils/biomes/BiomeMapParser.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/utils/biomes/BiomeMapParser.java @@ -125,12 +125,12 @@ private void readEntry(JsonObject entry) throws BiomeMapException { // Loop through all biome strings in this array for (Biome biome : biomes) { - T prev = map.put(biome, value); + map.put(biome, value); return; } } - } + } } private Set readBiomes(JsonArray array) throws BiomeMapException { diff --git a/src/main/java/me/mrCookieSlime/CSCoreLibPlugin/Configuration/Config.java b/src/main/java/me/mrCookieSlime/CSCoreLibPlugin/Configuration/Config.java index b8b12e5c5a..fe3f2d59ba 100644 --- a/src/main/java/me/mrCookieSlime/CSCoreLibPlugin/Configuration/Config.java +++ b/src/main/java/me/mrCookieSlime/CSCoreLibPlugin/Configuration/Config.java @@ -5,7 +5,6 @@ import java.util.Set; import lombok.Getter; -import me.mrCookieSlime.Slimefun.api.BlockStorage; import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.configuration.file.YamlConfiguration;