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

Removed deprecated stuff

This commit is contained in:
TheBusyBiscuit 2021-01-06 16:26:40 +01:00
parent 74f8204b75
commit 75b72eb630
10 changed files with 27 additions and 141 deletions

View File

@ -33,6 +33,7 @@
* Performance optimizations for Cargo networks
* Removed an old version of bStats
* CraftBukkit is officially no longer supported, Slimefun will now be disabled on old builds of CraftBukkit
* Removed the deprecated ItemManipulationAPI for BlockMenus
#### Fixes
* Fixed a couple of compatibility issues with ItemsAdder

View File

@ -12,7 +12,6 @@ import java.util.Map;
import java.util.Optional;
import java.util.Queue;
import java.util.Set;
import java.util.logging.Level;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
@ -38,10 +37,8 @@ import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin;
import io.github.thebusybiscuit.slimefun4.utils.ChestMenuUtils;
import io.github.thebusybiscuit.slimefun4.utils.SlimefunUtils;
import io.papermc.lib.PaperLib;
import me.mrCookieSlime.CSCoreLibPlugin.Configuration.Config;
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem;
import me.mrCookieSlime.Slimefun.api.BlockStorage;
import me.mrCookieSlime.Slimefun.api.Slimefun;
import me.mrCookieSlime.Slimefun.api.inventory.BlockMenu;
import me.mrCookieSlime.Slimefun.api.inventory.DirtyChestMenu;
import me.mrCookieSlime.Slimefun.api.inventory.UniversalBlockMenu;
@ -426,12 +423,7 @@ abstract class AbstractItemNetwork extends Network {
}
} else if (BlockStorage.hasInventory(target)) {
BlockMenu blockMenu = BlockStorage.getInventory(target);
if (blockMenu.getPreset().getID().startsWith("BARREL_")) {
gatherItemsFromBarrel(l, blockMenu, items);
} else {
handleWithdraw(blockMenu, items, l);
}
handleWithdraw(blockMenu, items, l);
} else if (CargoUtils.hasInventory(target)) {
BlockState state = PaperLib.getBlockState(target, false).getState();
@ -445,41 +437,6 @@ abstract class AbstractItemNetwork extends Network {
}
}
@ParametersAreNonnullByDefault
private void gatherItemsFromBarrel(Location l, BlockMenu blockMenu, List<ItemStackAndInteger> items) {
try {
Config cfg = BlockStorage.getLocationInfo(blockMenu.getLocation());
String data = cfg.getString("storedItems");
if (data == null) {
return;
}
int stored = Integer.parseInt(data);
for (int slot : blockMenu.getPreset().getSlotsAccessedByItemTransport((DirtyChestMenu) blockMenu, ItemTransportFlow.WITHDRAW, null)) {
ItemStack stack = blockMenu.getItemInSlot(slot);
if (stack != null && CargoUtils.matchesFilter(this, l.getBlock(), stack)) {
boolean add = true;
for (ItemStackAndInteger item : items) {
if (SlimefunUtils.isItemSimilar(stack, item.getItemStackWrapper(), true, false)) {
add = false;
item.add(stack.getAmount() + stored);
}
}
if (add) {
items.add(new ItemStackAndInteger(stack, stack.getAmount() + stored));
}
}
}
} catch (Exception x) {
Slimefun.getLogger().log(Level.SEVERE, "An Exception occurred while trying to read data from a Barrel", x);
}
}
@ParametersAreNonnullByDefault
private void handleWithdraw(DirtyChestMenu menu, List<ItemStackAndInteger> items, Location l) {
for (int slot : menu.getPreset().getSlotsAccessedByItemTransport(menu, ItemTransportFlow.WITHDRAW, null)) {

View File

@ -27,7 +27,6 @@ import org.bukkit.plugin.java.JavaPluginLoader;
import org.bukkit.scheduler.BukkitTask;
import io.github.thebusybiscuit.cscorelib2.config.Config;
import io.github.thebusybiscuit.cscorelib2.math.DoubleHandler;
import io.github.thebusybiscuit.cscorelib2.protection.ProtectionManager;
import io.github.thebusybiscuit.cscorelib2.reflection.ReflectionUtils;
import io.github.thebusybiscuit.slimefun4.api.MinecraftVersion;
@ -113,6 +112,7 @@ import io.github.thebusybiscuit.slimefun4.implementation.tasks.ArmorTask;
import io.github.thebusybiscuit.slimefun4.implementation.tasks.SlimefunStartupTask;
import io.github.thebusybiscuit.slimefun4.implementation.tasks.TickerTask;
import io.github.thebusybiscuit.slimefun4.integrations.IntegrationsManager;
import io.github.thebusybiscuit.slimefun4.utils.NumberUtils;
import io.github.thebusybiscuit.slimefun4.utils.tags.SlimefunTag;
import io.papermc.lib.PaperLib;
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.abstractItems.AContainer;
@ -347,7 +347,6 @@ public final class SlimefunPlugin extends JavaPlugin implements SlimefunAddon {
getLogger().log(Level.INFO, "Loading Third-Party plugin integrations...");
integrations.start();
gitHubService.start(this);
// Hooray!
@ -434,9 +433,9 @@ public final class SlimefunPlugin extends JavaPlugin implements SlimefunAddon {
long ms = (System.nanoTime() - timestamp) / 1000000;
if (ms > 1000) {
return DoubleHandler.fixDouble(ms / 1000.0) + "s";
return NumberUtils.roundDecimalNumber(ms / 1000.0) + "s";
} else {
return DoubleHandler.fixDouble(ms) + "ms";
return NumberUtils.roundDecimalNumber(ms) + "ms";
}
}
@ -817,7 +816,15 @@ public final class SlimefunPlugin extends JavaPlugin implements SlimefunAddon {
*/
@Nonnull
public static Set<Plugin> getInstalledAddons() {
return Arrays.stream(instance.getServer().getPluginManager().getPlugins()).filter(plugin -> plugin.getDescription().getDepend().contains(instance.getName()) || plugin.getDescription().getSoftDepend().contains(instance.getName())).collect(Collectors.toSet());
String pluginName = instance.getName();
// @formatter:off
return Arrays.stream(instance.getServer().getPluginManager().getPlugins())
.filter(plugin -> {
PluginDescriptionFile description = plugin.getDescription();
return description.getDepend().contains(pluginName) || description.getSoftDepend().contains(pluginName);
}).collect(Collectors.toSet());
// @formatter:on
}
/**

View File

@ -223,6 +223,7 @@ public final class NumberUtils {
}
}
@Nonnull
public static String roundDecimalNumber(double number) {
return DECIMAL_FORMAT.format(number);
}

View File

@ -12,6 +12,7 @@ import org.bukkit.inventory.ItemStack;
import io.github.thebusybiscuit.cscorelib2.config.Config;
import me.mrCookieSlime.Slimefun.api.Slimefun;
// This class will be deprecated, relocated and rewritten in a future version.
public class BlockMenu extends DirtyChestMenu {
private Location location;

View File

@ -20,6 +20,7 @@ import me.mrCookieSlime.CSCoreLibPlugin.general.Inventory.ChestMenu;
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem;
import me.mrCookieSlime.Slimefun.api.item_transport.ItemTransportFlow;
// This class will be deprecated, relocated and rewritten in a future version.
public abstract class BlockMenuPreset extends ChestMenu {
private final Set<Integer> occupiedSlots = new HashSet<>();
@ -32,8 +33,6 @@ public abstract class BlockMenuPreset extends ChestMenu {
private final boolean universal;
private boolean locked;
private ItemManipulationEvent event;
public BlockMenuPreset(@Nonnull String id, @Nonnull String title) {
this(id, title, false);
}
@ -75,19 +74,6 @@ public abstract class BlockMenuPreset extends ChestMenu {
public abstract int[] getSlotsAccessedByItemTransport(ItemTransportFlow flow);
/**
* This method is deprecated.
*
* @deprecated Override {@link #onItemStackChange(DirtyChestMenu, int, ItemStack, ItemStack)} instead
*
* @param event
* The event
*/
@Deprecated
public void registerEvent(ItemManipulationEvent event) {
this.event = event;
}
/**
* This method is called whenever an {@link ItemStack} changes.
* You can override this as necessary if you need to listen to these events
@ -259,7 +245,6 @@ public abstract class BlockMenuPreset extends ChestMenu {
menu.addMenuOpeningHandler(getMenuOpeningHandler());
menu.addMenuCloseHandler(getMenuCloseHandler());
menu.registerEvent(event);
}
public void newInstance(@Nonnull BlockMenu menu, @Nonnull Location l) {

View File

@ -18,10 +18,10 @@ import io.github.thebusybiscuit.cscorelib2.item.CustomItem;
import io.github.thebusybiscuit.slimefun4.utils.itemstack.ItemStackWrapper;
import me.mrCookieSlime.CSCoreLibPlugin.general.Inventory.ChestMenu;
// This class will be deprecated, relocated and rewritten in a future version.
public class DirtyChestMenu extends ChestMenu {
protected final BlockMenuPreset preset;
protected ItemManipulationEvent event;
protected int changes = 1;
public DirtyChestMenu(@Nonnull BlockMenuPreset preset) {
@ -61,35 +61,20 @@ public class DirtyChestMenu extends ChestMenu {
return preset.canOpen(b, p);
}
@Override
public void open(Player... players) {
super.open(players);
// The Inventory will likely be modified soon
markDirty();
}
public void close() {
for (HumanEntity human : new ArrayList<>(toInventory().getViewers())) {
human.closeInventory();
}
}
/**
* This method has been deprecated.
*
* @deprecated The {@link ItemManipulationEvent} has been deprecated.
*
* @param event
* deprecated class
*/
@Deprecated
public void registerEvent(ItemManipulationEvent event) {
this.event = event;
}
@Override
public ChestMenu addMenuOpeningHandler(MenuOpeningHandler handler) {
if (handler instanceof MenuSavingHandler) {
MenuOpeningHandler openingHandler = ((MenuSavingHandler) handler).getOpeningHandler();
return super.addMenuOpeningHandler(new MenuSavingHandler(this, openingHandler));
} else {
return super.addMenuOpeningHandler(new MenuSavingHandler(this, handler));
}
}
public boolean fits(@Nonnull ItemStack item, int... slots) {
for (int slot : slots) {
// A small optimization for empty slots
@ -161,11 +146,6 @@ public class DirtyChestMenu extends ChestMenu {
public void replaceExistingItem(int slot, ItemStack item, boolean event) {
if (event) {
ItemStack previous = getItemInSlot(slot);
if (this.event != null) {
item = this.event.onEvent(slot, previous, item);
}
item = preset.onItemStackChange(this, slot, previous, item);
}

View File

@ -1,17 +0,0 @@
package me.mrCookieSlime.Slimefun.api.inventory;
import org.bukkit.inventory.ItemStack;
/**
* @deprecated Please use {@link BlockMenuPreset#onItemStackChange(DirtyChestMenu, int, ItemStack, ItemStack)} instead.
*
* @author TheBusyBiscuit
*
*/
@Deprecated
@FunctionalInterface
public interface ItemManipulationEvent {
ItemStack onEvent(int slot, ItemStack previous, ItemStack next);
}

View File

@ -1,30 +0,0 @@
package me.mrCookieSlime.Slimefun.api.inventory;
import javax.annotation.ParametersAreNonnullByDefault;
import org.bukkit.entity.Player;
import me.mrCookieSlime.CSCoreLibPlugin.general.Inventory.ChestMenu.MenuOpeningHandler;
public class MenuSavingHandler implements MenuOpeningHandler {
private final DirtyChestMenu menu;
private final MenuOpeningHandler handler;
@ParametersAreNonnullByDefault
public MenuSavingHandler(DirtyChestMenu menu, MenuOpeningHandler handler) {
this.menu = menu;
this.handler = handler;
}
@Override
public void onOpen(Player p) {
handler.onOpen(p);
menu.markDirty();
}
public MenuOpeningHandler getOpeningHandler() {
return handler;
}
}

View File

@ -4,6 +4,7 @@ import java.io.File;
import io.github.thebusybiscuit.cscorelib2.config.Config;
// This class will be deprecated, relocated and rewritten in a future version.
public class UniversalBlockMenu extends DirtyChestMenu {
public UniversalBlockMenu(BlockMenuPreset preset) {