mirror of
https://github.com/StarWishsama/Slimefun4.git
synced 2024-09-20 03:35:51 +00:00
Reduced technical debt
This commit is contained in:
parent
76004c3df9
commit
bb50dcaf73
@ -37,10 +37,7 @@ import me.mrCookieSlime.Slimefun.api.inventory.BlockMenu;
|
||||
public class SlimefunItem {
|
||||
|
||||
public static List<SlimefunItem> items = new ArrayList<>();
|
||||
|
||||
public static Map<String, SlimefunItem> mapID = new HashMap<>();
|
||||
public static Set<String> tickers = new HashSet<>();
|
||||
|
||||
public static List<SlimefunItem> all = new ArrayList<>();
|
||||
|
||||
private String id;
|
||||
@ -404,7 +401,7 @@ public class SlimefunItem {
|
||||
for (ItemHandler h: handler) {
|
||||
if (h instanceof BlockTicker) {
|
||||
this.ticking = true;
|
||||
tickers.add(getID());
|
||||
SlimefunPlugin.getUtilities().tickers.add(getID());
|
||||
this.blockTicker = (BlockTicker) h;
|
||||
}
|
||||
else if (h instanceof EnergyTicker) {
|
||||
@ -514,7 +511,7 @@ public class SlimefunItem {
|
||||
}
|
||||
|
||||
public static boolean isTicking(String item) {
|
||||
return tickers.contains(item);
|
||||
return SlimefunPlugin.getUtilities().tickers.contains(item);
|
||||
}
|
||||
|
||||
public static void registerBlockHandler(String id, SlimefunBlockHandler handler) {
|
||||
|
@ -208,6 +208,7 @@ public final class SlimefunSetup {
|
||||
new SlimefunItem(Categories.FOOD, SlimefunItems.DIET_COOKIE, "DIET_COOKIE", RecipeType.MAGIC_WORKBENCH,
|
||||
new ItemStack[] {new ItemStack(Material.COOKIE), SlimefunItems.ELYTRA_SCALE, null, null, null, null, null, null, null})
|
||||
.register(true, new ItemInteractionHandler() {
|
||||
|
||||
@Override
|
||||
public boolean onRightClick(ItemUseEvent e, Player p, ItemStack item) {
|
||||
if (SlimefunManager.isItemSimiliar(item, SlimefunItems.DIET_COOKIE, true)) {
|
||||
|
@ -43,10 +43,7 @@ import me.mrCookieSlime.Slimefun.api.PlayerProfile;
|
||||
import me.mrCookieSlime.Slimefun.api.Slimefun;
|
||||
import me.mrCookieSlime.Slimefun.api.SlimefunBackup;
|
||||
import me.mrCookieSlime.Slimefun.api.TickerTask;
|
||||
import me.mrCookieSlime.Slimefun.api.energy.ChargableBlock;
|
||||
import me.mrCookieSlime.Slimefun.api.energy.EnergyNet;
|
||||
import me.mrCookieSlime.Slimefun.api.energy.ItemEnergy;
|
||||
import me.mrCookieSlime.Slimefun.api.inventory.BlockMenuPreset;
|
||||
import me.mrCookieSlime.Slimefun.api.inventory.UniversalBlockMenu;
|
||||
import me.mrCookieSlime.Slimefun.api.item_transport.CargoNet;
|
||||
import me.mrCookieSlime.Slimefun.autosave.BlockAutoSaver;
|
||||
@ -366,14 +363,8 @@ public final class SlimefunPlugin extends JavaPlugin {
|
||||
SlimefunItem.all = null;
|
||||
SlimefunItem.items = null;
|
||||
SlimefunItem.mapID = null;
|
||||
BlockMenuPreset.presets = null;
|
||||
ChargableBlock.capacitors = null;
|
||||
ChargableBlock.maxCharges = null;
|
||||
AContainer.processing = null;
|
||||
AContainer.progress = null;
|
||||
EnergyNet.machinesInput = null;
|
||||
EnergyNet.machinesOutput = null;
|
||||
EnergyNet.machinesStorage = null;
|
||||
CargoNet.faces = null;
|
||||
OreWasher.items = null;
|
||||
|
||||
|
@ -1,11 +1,12 @@
|
||||
package me.mrCookieSlime.Slimefun.api.energy;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.logging.Level;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.Skull;
|
||||
|
||||
import me.mrCookieSlime.CSCoreLibPlugin.Configuration.Config;
|
||||
import me.mrCookieSlime.CSCoreLibPlugin.general.Math.DoubleHandler;
|
||||
import me.mrCookieSlime.CSCoreLibPlugin.general.World.CustomSkull;
|
||||
@ -13,28 +14,19 @@ import me.mrCookieSlime.Slimefun.SlimefunPlugin;
|
||||
import me.mrCookieSlime.Slimefun.api.BlockStorage;
|
||||
import me.mrCookieSlime.Slimefun.api.Slimefun;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.Skull;
|
||||
|
||||
public final class ChargableBlock {
|
||||
|
||||
private ChargableBlock() {}
|
||||
|
||||
public static Map<String, Integer> maxCharges = new HashMap<>();
|
||||
public static Set<String> rechargeable = new HashSet<>();
|
||||
public static Set<String> capacitors = new HashSet<>();
|
||||
|
||||
public static void registerChargableBlock(String id, int capacity, boolean recharge) {
|
||||
maxCharges.put(id, capacity);
|
||||
if (recharge) rechargeable.add(id);
|
||||
SlimefunPlugin.getUtilities().blocksEnergyCapacity.put(id, capacity);
|
||||
if (recharge) SlimefunPlugin.getUtilities().rechargeableItems.add(id);
|
||||
}
|
||||
|
||||
public static void registerCapacitor(String id, int capacity) {
|
||||
maxCharges.put(id, capacity);
|
||||
rechargeable.add(id);
|
||||
capacitors.add(id);
|
||||
SlimefunPlugin.getUtilities().blocksEnergyCapacity.put(id, capacity);
|
||||
SlimefunPlugin.getUtilities().rechargeableItems.add(id);
|
||||
SlimefunPlugin.getUtilities().capacitorIDs.add(id);
|
||||
}
|
||||
|
||||
public static boolean isChargable(Block b) {
|
||||
@ -43,13 +35,13 @@ public final class ChargableBlock {
|
||||
|
||||
public static boolean isChargable(Location l) {
|
||||
if (!BlockStorage.hasBlockInfo(l)) return false;
|
||||
return maxCharges.containsKey(BlockStorage.checkID(l));
|
||||
return SlimefunPlugin.getUtilities().blocksEnergyCapacity.containsKey(BlockStorage.checkID(l));
|
||||
}
|
||||
|
||||
public static boolean isRechargable(Block b) {
|
||||
if (!BlockStorage.hasBlockInfo(b)) return false;
|
||||
String id = BlockStorage.checkID(b);
|
||||
return maxCharges.containsKey(id) && rechargeable.contains(id);
|
||||
return SlimefunPlugin.getUtilities().blocksEnergyCapacity.containsKey(id) && SlimefunPlugin.getUtilities().rechargeableItems.contains(id);
|
||||
}
|
||||
|
||||
public static boolean isCapacitor(Block b) {
|
||||
@ -58,7 +50,7 @@ public final class ChargableBlock {
|
||||
|
||||
public static boolean isCapacitor(Location l) {
|
||||
if (!BlockStorage.hasBlockInfo(l)) return false;
|
||||
return capacitors.contains(BlockStorage.checkID(l));
|
||||
return SlimefunPlugin.getUtilities().capacitorIDs.contains(BlockStorage.checkID(l));
|
||||
}
|
||||
|
||||
public static int getDefaultCapacity(Block b) {
|
||||
@ -67,7 +59,7 @@ public final class ChargableBlock {
|
||||
|
||||
public static int getDefaultCapacity(Location l) {
|
||||
String id = BlockStorage.checkID(l);
|
||||
return id == null ? 0: maxCharges.get(id);
|
||||
return id == null ? 0: SlimefunPlugin.getUtilities().blocksEnergyCapacity.get(id);
|
||||
}
|
||||
|
||||
public static int getCharge(Block b) {
|
||||
@ -135,6 +127,7 @@ public final class ChargableBlock {
|
||||
int energy = getCharge(l);
|
||||
int space = getMaxCharge(l) - energy;
|
||||
int rest = charge;
|
||||
|
||||
if (space > 0 && charge > 0) {
|
||||
if (space > charge) {
|
||||
setCharge(l, energy + charge);
|
||||
@ -144,14 +137,15 @@ public final class ChargableBlock {
|
||||
rest = charge - space;
|
||||
setCharge(l, getMaxCharge(l));
|
||||
}
|
||||
if (capacitors.contains(BlockStorage.checkID(l))) {
|
||||
|
||||
if (SlimefunPlugin.getUtilities().capacitorIDs.contains(BlockStorage.checkID(l))) {
|
||||
updateTexture(l);
|
||||
}
|
||||
}
|
||||
else if (charge < 0 && energy >= -charge) {
|
||||
setCharge(l, energy + charge);
|
||||
|
||||
if (capacitors.contains(BlockStorage.checkID(l))) {
|
||||
if (SlimefunPlugin.getUtilities().capacitorIDs.contains(BlockStorage.checkID(l))) {
|
||||
updateTexture(l);
|
||||
}
|
||||
}
|
||||
@ -164,11 +158,15 @@ public final class ChargableBlock {
|
||||
|
||||
public static int getMaxCharge(Location l) {
|
||||
Config cfg = BlockStorage.getLocationInfo(l);
|
||||
|
||||
if (!cfg.contains("id")) {
|
||||
BlockStorage.clearBlockInfo(l);
|
||||
return 0;
|
||||
}
|
||||
if (cfg.contains("energy-capacity")) return Integer.parseInt(cfg.getString("energy-capacity"));
|
||||
|
||||
if (cfg.contains("energy-capacity")) {
|
||||
return Integer.parseInt(cfg.getString("energy-capacity"));
|
||||
}
|
||||
else {
|
||||
BlockStorage.addBlockInfo(l, "energy-capacity", String.valueOf(getDefaultCapacity(l)), false);
|
||||
return getDefaultCapacity(l);
|
||||
|
@ -19,41 +19,37 @@ import me.mrCookieSlime.Slimefun.holograms.EnergyHologram;
|
||||
public class EnergyNet extends Network {
|
||||
|
||||
private static final int RANGE = 6;
|
||||
|
||||
public static Set<String> machinesInput = new HashSet<>();
|
||||
public static Set<String> machinesStorage = new HashSet<>();
|
||||
public static Set<String> machinesOutput = new HashSet<>();
|
||||
|
||||
public static EnergyNetComponent getComponent(Block b) {
|
||||
return getComponent(b.getLocation());
|
||||
}
|
||||
|
||||
public static EnergyNetComponent getComponent(String id) {
|
||||
if (machinesInput.contains(id)) return EnergyNetComponent.SOURCE;
|
||||
if (machinesStorage.contains(id)) return EnergyNetComponent.DISTRIBUTOR;
|
||||
if (machinesOutput.contains(id)) return EnergyNetComponent.CONSUMER;
|
||||
if (SlimefunPlugin.getUtilities().energyNetInput.contains(id)) return EnergyNetComponent.SOURCE;
|
||||
if (SlimefunPlugin.getUtilities().energyNetStorage.contains(id)) return EnergyNetComponent.DISTRIBUTOR;
|
||||
if (SlimefunPlugin.getUtilities().energyNetOutput.contains(id)) return EnergyNetComponent.CONSUMER;
|
||||
return EnergyNetComponent.NONE;
|
||||
}
|
||||
|
||||
public static EnergyNetComponent getComponent(Location l) {
|
||||
if (!BlockStorage.hasBlockInfo(l)) return EnergyNetComponent.NONE;
|
||||
String id = BlockStorage.checkID(l);
|
||||
if (machinesInput.contains(id)) return EnergyNetComponent.SOURCE;
|
||||
if (machinesStorage.contains(id)) return EnergyNetComponent.DISTRIBUTOR;
|
||||
if (machinesOutput.contains(id)) return EnergyNetComponent.CONSUMER;
|
||||
if (SlimefunPlugin.getUtilities().energyNetInput.contains(id)) return EnergyNetComponent.SOURCE;
|
||||
if (SlimefunPlugin.getUtilities().energyNetStorage.contains(id)) return EnergyNetComponent.DISTRIBUTOR;
|
||||
if (SlimefunPlugin.getUtilities().energyNetOutput.contains(id)) return EnergyNetComponent.CONSUMER;
|
||||
return EnergyNetComponent.NONE;
|
||||
}
|
||||
|
||||
public static void registerComponent(String id, EnergyNetComponent component) {
|
||||
switch (component) {
|
||||
case CONSUMER:
|
||||
machinesOutput.add(id);
|
||||
SlimefunPlugin.getUtilities().energyNetOutput.add(id);
|
||||
break;
|
||||
case DISTRIBUTOR:
|
||||
machinesStorage.add(id);
|
||||
SlimefunPlugin.getUtilities().energyNetStorage.add(id);
|
||||
break;
|
||||
case SOURCE:
|
||||
machinesInput.add(id);
|
||||
SlimefunPlugin.getUtilities().energyNetInput.add(id);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
|
@ -1,8 +1,6 @@
|
||||
package me.mrCookieSlime.Slimefun.api.inventory;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
@ -17,8 +15,6 @@ import me.mrCookieSlime.Slimefun.api.item_transport.ItemTransportFlow;
|
||||
|
||||
public abstract class BlockMenuPreset extends ChestMenu {
|
||||
|
||||
public static Map<String, BlockMenuPreset> presets = new HashMap<>();
|
||||
|
||||
private String title;
|
||||
private Set<Integer> occupied = new HashSet<>();
|
||||
private String id;
|
||||
@ -33,7 +29,7 @@ public abstract class BlockMenuPreset extends ChestMenu {
|
||||
this.title = title;
|
||||
this.init();
|
||||
this.universal = false;
|
||||
presets.put(id, this);
|
||||
SlimefunPlugin.getUtilities().blockMenuPresets.put(id, this);
|
||||
}
|
||||
|
||||
public void registerEvent(ItemManipulationEvent event) {
|
||||
@ -46,7 +42,7 @@ public abstract class BlockMenuPreset extends ChestMenu {
|
||||
this.title = title;
|
||||
this.init();
|
||||
this.universal = universal;
|
||||
presets.put(id, this);
|
||||
SlimefunPlugin.getUtilities().blockMenuPresets.put(id, this);
|
||||
}
|
||||
|
||||
public abstract void init();
|
||||
@ -105,15 +101,16 @@ public abstract class BlockMenuPreset extends ChestMenu {
|
||||
}
|
||||
|
||||
public static BlockMenuPreset getPreset(String id) {
|
||||
return id == null ? null: presets.get(id);
|
||||
return id == null ? null: SlimefunPlugin.getUtilities().blockMenuPresets.get(id);
|
||||
}
|
||||
|
||||
public static boolean isInventory(String id) {
|
||||
return presets.containsKey(id);
|
||||
return SlimefunPlugin.getUtilities().blockMenuPresets.containsKey(id);
|
||||
}
|
||||
|
||||
public static boolean isUniversalInventory(String id) {
|
||||
return presets.containsKey(id) && presets.get(id).isUniversal();
|
||||
BlockMenuPreset preset = SlimefunPlugin.getUtilities().blockMenuPresets.get(id);
|
||||
return preset != null && preset.isUniversal();
|
||||
}
|
||||
|
||||
public boolean isUniversal() {
|
||||
|
@ -39,10 +39,8 @@ public class CargoNet extends Network {
|
||||
|
||||
private static final int RANGE = 5;
|
||||
public static List<BlockFace> faces = Arrays.asList(BlockFace.NORTH, BlockFace.EAST, BlockFace.SOUTH, BlockFace.WEST);
|
||||
public static Map<Location, Integer> roundRobin = new HashMap<>();
|
||||
public static Set<ItemRequest> requests = new HashSet<>();
|
||||
|
||||
private static int[] slots = new int[] {19, 20, 21, 28, 29, 30, 37, 38, 39};
|
||||
|
||||
private static final int[] slots = new int[] {19, 20, 21, 28, 29, 30, 37, 38, 39};
|
||||
|
||||
// Chest Terminal Stuff
|
||||
private static final ChestTerminalSorter sorter = new ChestTerminalSorter();
|
||||
@ -207,7 +205,7 @@ public class CargoNet extends Network {
|
||||
}
|
||||
|
||||
if (menu.getItemInSlot(17) != null) {
|
||||
requests.add(new ItemRequest(bus, 17, menu.getItemInSlot(17), ItemTransportFlow.INSERT));
|
||||
SlimefunPlugin.getUtilities().itemRequests.add(new ItemRequest(bus, 17, menu.getItemInSlot(17), ItemTransportFlow.INSERT));
|
||||
}
|
||||
}
|
||||
|
||||
@ -235,7 +233,7 @@ public class CargoNet extends Network {
|
||||
|
||||
BlockStorage.addBlockInfo(bus, "index", String.valueOf(index));
|
||||
|
||||
requests.add(new ItemRequest(bus, 17, items.get(index), ItemTransportFlow.WITHDRAW));
|
||||
SlimefunPlugin.getUtilities().itemRequests.add(new ItemRequest(bus, 17, items.get(index), ItemTransportFlow.WITHDRAW));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -245,11 +243,11 @@ public class CargoNet extends Network {
|
||||
|
||||
ItemStack sendingItem = menu.getItemInSlot(TERMINAL_OUT_SLOT);
|
||||
if (sendingItem != null) {
|
||||
requests.add(new ItemRequest(terminal, TERMINAL_OUT_SLOT, sendingItem, ItemTransportFlow.INSERT));
|
||||
SlimefunPlugin.getUtilities().itemRequests.add(new ItemRequest(terminal, TERMINAL_OUT_SLOT, sendingItem, ItemTransportFlow.INSERT));
|
||||
}
|
||||
}
|
||||
|
||||
Iterator<ItemRequest> iterator = requests.iterator();
|
||||
Iterator<ItemRequest> iterator = SlimefunPlugin.getUtilities().itemRequests.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
ItemRequest request = iterator.next();
|
||||
if (terminals.contains(request.getTerminal()) || imports.contains(request.getTerminal()) || exports.contains(request.getTerminal())) {
|
||||
@ -346,11 +344,11 @@ public class CargoNet extends Network {
|
||||
List<Location> outputlist = new ArrayList<>(output.get(frequency));
|
||||
|
||||
if (roundrobin) {
|
||||
if (!roundRobin.containsKey(input)) {
|
||||
roundRobin.put(input, 0);
|
||||
if (!SlimefunPlugin.getUtilities().roundRobin.containsKey(input)) {
|
||||
SlimefunPlugin.getUtilities().roundRobin.put(input, 0);
|
||||
}
|
||||
|
||||
int cIndex = roundRobin.get(input);
|
||||
int cIndex = SlimefunPlugin.getUtilities().roundRobin.get(input);
|
||||
|
||||
if (cIndex < outputlist.size()) {
|
||||
for (int i = 0; i < cIndex; i++) {
|
||||
@ -362,7 +360,7 @@ public class CargoNet extends Network {
|
||||
}
|
||||
else cIndex = 1;
|
||||
|
||||
roundRobin.put(input, cIndex);
|
||||
SlimefunPlugin.getUtilities().roundRobin.put(input, cIndex);
|
||||
}
|
||||
|
||||
for (Location out : outputlist) {
|
||||
@ -505,7 +503,7 @@ public class CargoNet extends Network {
|
||||
stack.setItemMeta(im);
|
||||
menu.replaceExistingItem(slot, stack);
|
||||
menu.addMenuClickHandler(slot, (p, sl, is, action) -> {
|
||||
requests.add(new ItemRequest(l, 44, new CustomItem(item.getItem(), action.isRightClicked() ? (item.getAmount() > item.getItem().getMaxStackSize() ? item.getItem().getMaxStackSize(): item.getAmount()): 1), ItemTransportFlow.WITHDRAW));
|
||||
SlimefunPlugin.getUtilities().itemRequests.add(new ItemRequest(l, 44, new CustomItem(item.getItem(), action.isRightClicked() ? (item.getAmount() > item.getItem().getMaxStackSize() ? item.getItem().getMaxStackSize(): item.getAmount()): 1), ItemTransportFlow.WITHDRAW));
|
||||
return false;
|
||||
});
|
||||
|
||||
|
@ -24,8 +24,10 @@ import me.mrCookieSlime.Slimefun.ancient_altar.AltarRecipe;
|
||||
import me.mrCookieSlime.Slimefun.api.BlockStorage;
|
||||
import me.mrCookieSlime.Slimefun.api.GuideHandler;
|
||||
import me.mrCookieSlime.Slimefun.api.PlayerProfile;
|
||||
import me.mrCookieSlime.Slimefun.api.inventory.BlockMenuPreset;
|
||||
import me.mrCookieSlime.Slimefun.api.inventory.UniversalBlockMenu;
|
||||
import me.mrCookieSlime.Slimefun.api.item_transport.CargoTransportEvent;
|
||||
import me.mrCookieSlime.Slimefun.api.item_transport.ItemRequest;
|
||||
import me.mrCookieSlime.Slimefun.hooks.github.Contributor;
|
||||
import me.mrCookieSlime.Slimefun.hooks.github.GitHubConnector;
|
||||
|
||||
@ -44,6 +46,20 @@ public final class Utilities {
|
||||
public Set<ItemStack> radioactiveItems = new HashSet<>();
|
||||
public Map<String, Set<ItemHandler>> itemHandlers = new HashMap<>();
|
||||
public Map<String, SlimefunBlockHandler> blockHandlers = new HashMap<>();
|
||||
public Set<String> tickers = new HashSet<>();
|
||||
|
||||
public Map<String, Integer> blocksEnergyCapacity = new HashMap<>();
|
||||
public Set<String> rechargeableItems = new HashSet<>();
|
||||
public Set<String> capacitorIDs = new HashSet<>();
|
||||
|
||||
public Set<String> energyNetInput = new HashSet<>();
|
||||
public Set<String> energyNetStorage = new HashSet<>();
|
||||
public Set<String> energyNetOutput = new HashSet<>();
|
||||
|
||||
public Map<Location, Integer> roundRobin = new HashMap<>();
|
||||
public Set<ItemRequest> itemRequests = new HashSet<>();
|
||||
|
||||
public Map<String, BlockMenuPreset> blockMenuPresets = new HashMap<>();
|
||||
|
||||
public List<Category> currentlyEnabledCategories = new ArrayList<>();
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user