Skip to content

Commit

Permalink
chore: 移除无用代码
Browse files Browse the repository at this point in the history
  • Loading branch information
mcchampions committed Sep 29, 2024
1 parent cc3127f commit 7ffe08c
Show file tree
Hide file tree
Showing 12 changed files with 4 additions and 209 deletions.
16 changes: 0 additions & 16 deletions src/main/java/city/norain/slimefun4/EnvironmentChecker.java
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,4 @@ void unlock(ScopeKey scopeKey) {
}
}

boolean hasLock(ScopeKey scopeKey) {
return locks.containsKey(scopeKey);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<PlayerProfile> cb) {
var controller = Slimefun.getDatabaseManager().getProfileDataController();
controller.getProfileAsync(p, new IAsyncReadCallback<>() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,17 @@

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;
import org.bukkit.block.Block;
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
Expand Down Expand Up @@ -83,23 +80,6 @@ public void markCargoNodeConfigurationDirty(Location node) {
connectorCache.remove(node);
}

private void filter(@Nullable ItemStack stack, List<ItemStackAndInteger> 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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,95 +105,6 @@ static int[] getOutputSlotRange(Inventory inv) {
}
}

@Nullable
static ItemStack withdraw(
AbstractItemNetwork network,
Map<Location, Inventory> 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<Location, Inventory> inventories, Block node, Block target) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,29 +25,5 @@ public enum SummaryOrderType {
/**
* Sort by average timings (highest to lowest)
*/
AVERAGE;

List<Map.Entry<String, Long>> sort(SlimefunProfiler profiler, Set<Map.Entry<String, Long>> 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<String, Long> map = new HashMap<>();
for (Map.Entry<String, Long> 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
}
Original file line number Diff line number Diff line change
Expand Up @@ -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()}.
* <p>
* 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}
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Biome> readBiomes(JsonArray array) throws BiomeMapException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down

0 comments on commit 7ffe08c

Please sign in to comment.