1
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:
TheBusyBiscuit 2019-09-02 10:24:53 +02:00
parent b075779f6b
commit 3368c56c62
16 changed files with 67 additions and 67 deletions

View File

@ -391,13 +391,17 @@ public class SlimefunItem {
}
@Deprecated
public void install() {}
public void install() {
// Deprecated
}
/**
* @deprecated Use {@link SlimefunItem#postRegister()} instead
*/
@Deprecated
public void create() {}
public void create() {
// Deprecated
}
/**
* @deprecated Use {@link SlimefunItem#addItemHandler(ItemHandler...)} instead
@ -524,7 +528,10 @@ public class SlimefunItem {
ChargableBlock.registerCapacitor(id, capacity);
}
public void postRegister() {}
public void postRegister() {
// Override this method to execute code after the Item has been registered
// Useful for calls to Slimefun.getItemValue(...)
}
protected void setItem(ItemStack stack) {
this.item = stack;

View File

@ -63,7 +63,9 @@ public abstract class AReactor extends SlimefunItem {
private static final int[] border_1 = {9, 10, 11, 18, 20, 27, 29, 36, 38, 45, 46, 47};
private static final int[] border_2 = {15, 16, 17, 24, 26, 33, 35, 42, 44, 51, 52, 53};
private static final int[] border_3 = {30, 31, 32, 39, 41, 48, 50};
private static final int[] border_4 = {25, 34, 43}; // No coolant border
// No coolant border
private static final int[] border_4 = {25, 34, 43};
private static final int infoSlot = 49;
public AReactor(Category category, ItemStack item, String id, RecipeType recipeType, ItemStack[] recipe) {

View File

@ -14,14 +14,13 @@ public final class MachineHelper {
private MachineHelper() {}
public static String getTimeLeft(int l) {
public static String getTimeLeft(int seconds) {
String timeleft = "";
final int minutes = (int) (l / 60L);
final int minutes = (int) (seconds / 60L);
if (minutes > 0) {
timeleft = String.valueOf(timeleft) + minutes + "m ";
}
l -= minutes * 60;
final int seconds = (int) l;
seconds -= minutes * 60;
timeleft = String.valueOf(timeleft) + seconds + "s";
return ChatColor.translateAlternateColorCodes('&', "&7" + timeleft + " left");
}

View File

@ -34,11 +34,12 @@ public class Composter extends SlimefunGadget {
@Override
public boolean onRightClick(ItemUseEvent e, final Player p, ItemStack item) {
if (e.getClickedBlock() != null) {
SlimefunItem machine = BlockStorage.check(e.getClickedBlock());
if (machine != null && machine.getID().equals(getID())) {
String id = BlockStorage.checkID(e.getClickedBlock());
if (id != null && id.equals(getID())) {
if (CSCoreLib.getLib().getProtectionManager().canAccessChest(p.getUniqueId(), e.getClickedBlock(), true)) {
final ItemStack input = p.getInventory().getItemInMainHand();
final Block b = e.getClickedBlock();
SlimefunItem machine = SlimefunItem.getByID(id);
for (ItemStack convert: RecipeType.getRecipeInputs(machine)) {
if (convert != null && SlimefunManager.isItemSimiliar(input, convert, true)) {

View File

@ -35,11 +35,13 @@ public class Crucible extends SlimefunGadget {
@Override
public boolean onRightClick(ItemUseEvent e, final Player p, ItemStack item) {
if (e.getClickedBlock() != null) {
SlimefunItem machine = BlockStorage.check(e.getClickedBlock());
if (machine != null && machine.getID().equals("CRUCIBLE")) {
String id = BlockStorage.checkID(e.getClickedBlock());
if (id != null && id.equals("CRUCIBLE")) {
if (CSCoreLib.getLib().getProtectionManager().canAccessChest(p.getUniqueId(), e.getClickedBlock(), true)) {
final ItemStack input = p.getInventory().getItemInMainHand();
final Block block = e.getClickedBlock().getRelative(BlockFace.UP);
SlimefunItem machine = SlimefunItem.getByID(id);
for (ItemStack convert: RecipeType.getRecipeInputs(machine)) {
if (input != null && SlimefunManager.isItemSimiliar(input, convert, true)) {
e.setCancelled(true);

View File

@ -184,11 +184,8 @@ public class ReactorAccessPort extends SlimefunItem {
public BlockMenu getReactorMenu(Location l) {
Location reactorL = new Location(l.getWorld(), l.getX(), l.getY() - 3, l.getZ());
String id = BlockStorage.checkID(reactorL);
if(id.equals("NUCLEAR_REACTOR") || id.equals("NETHERSTAR_REACTOR")) {
return BlockStorage.getInventory(reactorL);
}
SlimefunItem item = BlockStorage.check(reactorL.getBlock());
if (item instanceof AReactor) return BlockStorage.getInventory(l);
return null;
}

View File

@ -2,9 +2,7 @@ package me.mrCookieSlime.Slimefun.Objects.SlimefunItem.machines.electric;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.bukkit.Material;
import org.bukkit.block.Block;
@ -22,7 +20,6 @@ import me.mrCookieSlime.Slimefun.Objects.SlimefunBlockHandler;
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem;
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.UnregisterReason;
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.abstractItems.AContainer;
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.abstractItems.MachineRecipe;
import me.mrCookieSlime.Slimefun.Setup.SlimefunManager;
import me.mrCookieSlime.Slimefun.api.BlockStorage;
import me.mrCookieSlime.Slimefun.api.inventory.BlockMenu;
@ -32,11 +29,6 @@ import me.mrCookieSlime.Slimefun.api.item_transport.RecipeSorter;
public abstract class ElectricSmeltery extends AContainer {
public static Map<Block, MachineRecipe> processing = new HashMap<>();
public static Map<Block, Integer> progress = new HashMap<>();
protected List<MachineRecipe> recipes = new ArrayList<>();
private static final int[] border = {4, 5, 6, 7, 8, 13, 31, 40, 41, 42, 43, 44};
private static final int[] border_in = {0, 1, 2, 3, 9, 12, 18, 21, 27, 30, 36, 37, 38, 39};
private static final int[] border_out = {14, 15, 16, 17, 23, 26, 32, 33, 34, 35};

View File

@ -2718,8 +2718,8 @@ public final class SlimefunSetup {
@Override
public boolean onRightClick(ItemUseEvent e, Player p, ItemStack stack) {
if (e.getClickedBlock() == null) return false;
SlimefunItem item = BlockStorage.check(e.getClickedBlock());
if (item == null || !item.getID().equals("GPS_CONTROL_PANEL")) return false;
String item = BlockStorage.checkID(e.getClickedBlock());
if (item == null || !item.equals("GPS_CONTROL_PANEL")) return false;
e.setCancelled(true);
Slimefun.getGPSNetwork().openTransmitterControlPanel(p);
@ -3137,8 +3137,8 @@ public final class SlimefunSetup {
@Override
public boolean onRightClick(ItemUseEvent e, Player p, ItemStack stack) {
if (e.getClickedBlock() == null) return false;
SlimefunItem item = BlockStorage.check(e.getClickedBlock());
if (item == null || !item.getID().equals("GPS_GEO_SCANNER")) return false;
String item = BlockStorage.checkID(e.getClickedBlock());
if (item == null || !item.equals("GPS_GEO_SCANNER")) return false;
e.setCancelled(true);
Slimefun.getGPSNetwork().scanChunk(p, e.getClickedBlock().getChunk());
@ -3316,9 +3316,8 @@ public final class SlimefunSetup {
@Override
public boolean onRightClick(final ItemUseEvent e, Player p, ItemStack stack) {
if (e.getClickedBlock() == null) return false;
SlimefunItem item = BlockStorage.check(e.getClickedBlock());
if (item == null) return false;
if (!item.getID().equals("ELEVATOR_PLATE")) return false;
String item = BlockStorage.checkID(e.getClickedBlock());
if (item == null || !item.equals("ELEVATOR_PLATE")) return false;
if (BlockStorage.getLocationInfo(e.getClickedBlock().getLocation(), "owner").equals(p.getUniqueId().toString())) Elevator.openEditor(p, e.getClickedBlock());
return true;
@ -3732,8 +3731,8 @@ public final class SlimefunSetup {
@Override
public boolean onRightClick(ItemUseEvent e, Player p, ItemStack stack) {
if (e.getClickedBlock() == null) return false;
SlimefunItem item = BlockStorage.check(e.getClickedBlock());
if (item == null || !item.getID().equals("CARGO_MANAGER")) return false;
String item = BlockStorage.checkID(e.getClickedBlock());
if (item == null || !item.equals("CARGO_MANAGER")) return false;
e.setCancelled(true);
if (BlockStorage.getLocationInfo(e.getClickedBlock().getLocation(), "visualizer") == null) {

View File

@ -1026,14 +1026,13 @@ public final class SlimefunGuide {
getHistory().remove(uuid);
}
private static String getTimeLeft(int l) {
private static String getTimeLeft(int seconds) {
String timeleft = "";
final int minutes = (int) (l / 60L);
final int minutes = (int) (seconds / 60L);
if (minutes > 0) {
timeleft = String.valueOf(timeleft) + minutes + "m ";
}
l -= minutes * 60;
final int seconds = (int)l;
seconds -= minutes * 60;
timeleft = String.valueOf(timeleft) + seconds + "s";
return "&7" + timeleft;
}

View File

@ -30,7 +30,6 @@ import me.mrCookieSlime.CSCoreLibPlugin.general.Inventory.Item.CustomItem;
import me.mrCookieSlime.CSCoreLibPlugin.general.Player.PlayerInventory;
import me.mrCookieSlime.CSCoreLibPlugin.general.String.StringUtils;
import me.mrCookieSlime.Slimefun.SlimefunPlugin;
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem;
import me.mrCookieSlime.Slimefun.Setup.Messages;
import me.mrCookieSlime.Slimefun.api.BlockStorage;
import me.mrCookieSlime.Slimefun.utils.Utilities;
@ -52,9 +51,9 @@ public class AncientAltarListener implements Listener {
public void onInteract(PlayerInteractEvent e) {
if (e.getAction() != Action.RIGHT_CLICK_BLOCK) return;
Block b = e.getClickedBlock();
SlimefunItem item = BlockStorage.check(b);
String item = BlockStorage.checkID(b);
if (item != null) {
if (item.getID().equals("ANCIENT_PEDESTAL")) {
if (item.equals("ANCIENT_PEDESTAL")) {
if (utilities.altarinuse.contains(b.getLocation())) {
e.setCancelled(true);
return;
@ -81,7 +80,7 @@ public class AncientAltarListener implements Listener {
PlayerInventory.update(e.getPlayer());
}
}
else if (item.getID().equals("ANCIENT_ALTAR")) {
else if (item.equals("ANCIENT_ALTAR")) {
if (utilities.altarinuse.contains(b.getLocation())) {
e.setCancelled(true);
return;
@ -185,9 +184,9 @@ public class AncientAltarListener implements Listener {
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onBlockPlace(BlockPlaceEvent e) {
Block b = e.getBlockPlaced().getRelative(0, -1, 0);
SlimefunItem item = BlockStorage.check(b);
if(item == null) return;
if(item.getID().equalsIgnoreCase("ANCIENT_PEDESTAL")) {
String item = BlockStorage.checkID(b);
if (item != null && item.equalsIgnoreCase("ANCIENT_PEDESTAL")) {
Messages.local.sendTranslation(e.getPlayer(), "messages.cannot-place", true);
e.setCancelled(true);
}

View File

@ -498,7 +498,7 @@ public abstract class ProgrammableAndroid extends SlimefunItem {
private void mine(Block b, Block block) {
Collection<ItemStack> drops = block.getDrops();
if (!blockblacklist.contains(block.getType()) && !drops.isEmpty() && CSCoreLib.getLib().getProtectionManager().canBuild(UUID.fromString(BlockStorage.getLocationInfo(b.getLocation(), "owner")), block)) {
SlimefunItem item = BlockStorage.check(block);
String item = BlockStorage.checkID(block);
if (item == null) {
ItemStack[] items = drops.toArray(new ItemStack[drops.size()]);

View File

@ -8,7 +8,7 @@ import me.mrCookieSlime.CSCoreLibPlugin.PlayerRunnable;
import me.mrCookieSlime.CSCoreLibPlugin.general.Inventory.ChestMenu;
import me.mrCookieSlime.Slimefun.SlimefunGuide;
public abstract class GuideHandler {
public interface GuideHandler {
public abstract void addEntry(List<String> texts, List<String> tooltips);
public abstract PlayerRunnable getRunnable();
@ -17,11 +17,11 @@ public abstract class GuideHandler {
public abstract int next(Player p, int index, ChestMenu menu);
public PlayerRunnable getRunnable(boolean book) {
default PlayerRunnable getRunnable(boolean book) {
return this.getRunnable();
}
public void run(Player p, boolean survival, boolean book) {
default void run(Player p, boolean survival, boolean book) {
this.getRunnable(book).run(p);
if (survival && this.trackHistory()) {

View File

@ -15,7 +15,7 @@ import me.mrCookieSlime.Slimefun.api.item_transport.ItemTransportFlow;
public abstract class BlockMenuPreset extends ChestMenu {
private String title;
private String inventoryTitle;
private Set<Integer> occupied = new HashSet<>();
private String id;
private int size = -1;
@ -23,10 +23,10 @@ public abstract class BlockMenuPreset extends ChestMenu {
private ItemManipulationEvent event;
public BlockMenuPreset(String id, String title) {
super(title);
public BlockMenuPreset(String id, String inventoryTitle) {
super(inventoryTitle);
this.id = id;
this.title = title;
this.inventoryTitle = inventoryTitle;
this.init();
this.universal = false;
SlimefunPlugin.getUtilities().blockMenuPresets.put(id, this);
@ -36,10 +36,10 @@ public abstract class BlockMenuPreset extends ChestMenu {
this.event = event;
}
public BlockMenuPreset(String id, String title, boolean universal) {
super(title);
public BlockMenuPreset(String id, String inventoryTitle, boolean universal) {
super(inventoryTitle);
this.id = id;
this.title = title;
this.inventoryTitle = inventoryTitle;
this.init();
this.universal = universal;
SlimefunPlugin.getUtilities().blockMenuPresets.put(id, this);
@ -74,11 +74,11 @@ public abstract class BlockMenuPreset extends ChestMenu {
}
public int getSize() {
return this.size;
return size;
}
public String getTitle() {
return this.title;
return inventoryTitle;
}
public Set<Integer> getPresetSlots() {

View File

@ -75,14 +75,14 @@ public abstract class GitHubConnector {
public void parseData() {
try (BufferedReader reader = new BufferedReader(new FileReader(this.getFile()))) {
String full = "";
StringBuilder builder = new StringBuilder();
String line;
while ((line = reader.readLine()) != null) {
full = full + line;
builder.append(line);
}
JsonElement element = new JsonParser().parse(full);
JsonElement element = new JsonParser().parse(builder.toString());
this.onSuccess(element);
}
catch (IOException x) {

View File

@ -71,8 +71,9 @@ public class DamageListener implements Listener {
}
}
if (e.getEntity().getKiller() instanceof Player) {
Player p = (Player) e.getEntity().getKiller();
Player p = e.getEntity().getKiller();
ItemStack item = p.getInventory().getItemInMainHand();
if (SlimefunPlugin.getUtilities().drops.containsKey(e.getEntity().getType())) {

View File

@ -251,13 +251,15 @@ public class ToolListener implements Listener {
while (blocks.hasNext()) {
Block block = blocks.next();
SlimefunItem item = BlockStorage.check(block);
if (item != null) {
String id = BlockStorage.checkID(block);
if (id != null) {
blocks.remove();
if (!item.getID().equalsIgnoreCase("HARDENED_GLASS") && !item.getID().equalsIgnoreCase("WITHER_PROOF_OBSIDIAN") && !item.getID().equalsIgnoreCase("WITHER_PROOF_GLASS") && !item.getID().equalsIgnoreCase("FORCEFIELD_PROJECTOR") && !item.getID().equalsIgnoreCase("FORCEFIELD_RELAY")) {
if (!id.equalsIgnoreCase("HARDENED_GLASS") && !id.equalsIgnoreCase("WITHER_PROOF_OBSIDIAN") && !id.equalsIgnoreCase("WITHER_PROOF_GLASS") && !id.equalsIgnoreCase("FORCEFIELD_PROJECTOR") && !id.equalsIgnoreCase("FORCEFIELD_RELAY")) {
boolean success = true;
if (utilities.blockHandlers.containsKey(item.getID())) {
success = utilities.blockHandlers.get(item.getID()).onBreak(null, block, item, UnregisterReason.EXPLODE);
SlimefunItem item = SlimefunItem.getByID(id);
if (utilities.blockHandlers.containsKey(id)) {
success = utilities.blockHandlers.get(id).onBreak(null, block, item, UnregisterReason.EXPLODE);
}
if (success) {
BlockStorage.clearBlockInfo(block);