From e3dc17a9dfd04ee42035f626194129fe91a73fcd Mon Sep 17 00:00:00 2001 From: TheBusyBiscuit Date: Sat, 13 Jun 2020 13:52:53 +0200 Subject: [PATCH] [CI skip] Reduced technical debt --- .../implementation/items/androids/Script.java | 20 ++--- .../implementation/items/geo/GEOMiner.java | 73 ++++++++++--------- .../listeners/AncientAltarListener.java | 16 +++- .../utils/holograms/ReactorHologram.java | 6 +- .../utils/holograms/SimpleHologram.java | 5 +- 5 files changed, 71 insertions(+), 49 deletions(-) diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/androids/Script.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/androids/Script.java index 3cc69f97e..cb479ef9f 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/androids/Script.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/androids/Script.java @@ -181,17 +181,17 @@ public final class Script { } public static void upload(Player p, AndroidType androidType, int id, String name, String code) { - Config script = new Config("plugins/Slimefun/scripts/" + androidType.name() + '/' + p.getName() + ' ' + String.valueOf(id) + ".sfs"); + Config config = new Config("plugins/Slimefun/scripts/" + androidType.name() + '/' + p.getName() + ' ' + String.valueOf(id) + ".sfs"); - script.setValue("author", p.getUniqueId().toString()); - script.setValue("author_name", p.getName()); - script.setValue("name", ChatUtils.removeColorCodes(name)); - script.setValue("code", code); - script.setValue("downloads", 0); - script.setValue("android", androidType.name()); - script.setValue("rating.positive", new ArrayList()); - script.setValue("rating.negative", new ArrayList()); - script.save(); + config.setValue("author", p.getUniqueId().toString()); + config.setValue("author_name", p.getName()); + config.setValue("name", ChatUtils.removeColorCodes(name)); + config.setValue("code", code); + config.setValue("downloads", 0); + config.setValue("android", androidType.name()); + config.setValue("rating.positive", new ArrayList()); + config.setValue("rating.negative", new ArrayList()); + config.save(); } } diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/geo/GEOMiner.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/geo/GEOMiner.java index 23a559232..74309542b 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/geo/GEOMiner.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/geo/GEOMiner.java @@ -38,7 +38,7 @@ public abstract class GEOMiner extends AContainer implements InventoryBlock, Rec private static final int[] OUTPUT_BORDER = { 19, 20, 21, 22, 23, 24, 25, 28, 34, 37, 43, 46, 47, 48, 49, 50, 51, 52 }; private static final int[] OUTPUT_SLOTS = { 29, 30, 31, 32, 33, 38, 39, 40, 41, 42 }; private static final int PROCESSING_TIME = 14; - + public GEOMiner(Category category, SlimefunItemStack item, RecipeType recipeType, ItemStack[] recipe) { super(category, item, recipeType, recipe); @@ -152,22 +152,25 @@ public abstract class GEOMiner extends AContainer implements InventoryBlock, Rec @Override protected void tick(Block b) { - BlockMenu menu = BlockStorage.getInventory(b); + BlockMenu inv = BlockStorage.getInventory(b); if (isProcessing(b)) { int timeleft = progress.get(b); if (timeleft > 0) { - ChestMenuUtils.updateProgressbar(menu, 4, timeleft, processing.get(b).getTicks(), getProgressBar()); + ChestMenuUtils.updateProgressbar(inv, 4, timeleft, processing.get(b).getTicks(), getProgressBar()); + + if (ChargableBlock.getCharge(b) < getEnergyConsumption()) { + return; + } - if (ChargableBlock.getCharge(b) < getEnergyConsumption()) return; ChargableBlock.addCharge(b, -getEnergyConsumption()); progress.put(b, timeleft - 1); } else { - menu.replaceExistingItem(4, new CustomItem(new ItemStack(Material.BLACK_STAINED_GLASS_PANE), " ")); - menu.pushItem(processing.get(b).getOutput()[0], getOutputSlots()); + inv.replaceExistingItem(4, new CustomItem(new ItemStack(Material.BLACK_STAINED_GLASS_PANE), " ")); + inv.pushItem(processing.get(b).getOutput()[0], getOutputSlots()); progress.remove(b); processing.remove(b); @@ -177,34 +180,38 @@ public abstract class GEOMiner extends AContainer implements InventoryBlock, Rec SimpleHologram.update(b, "&4GEO-Scan required!"); } else { - for (GEOResource resource : SlimefunPlugin.getRegistry().getGEOResources().values()) { - if (resource.isObtainableFromGEOMiner()) { - OptionalInt optional = SlimefunPlugin.getGPSNetwork().getResourceManager().getSupplies(resource, b.getWorld(), b.getX() >> 4, b.getZ() >> 4); - - if (!optional.isPresent()) { - SimpleHologram.update(b, "&4GEO-Scan required!"); - return; - } - else { - int supplies = optional.getAsInt(); - - if (supplies > 0) { - MachineRecipe r = new MachineRecipe(PROCESSING_TIME / getSpeed(), new ItemStack[0], new ItemStack[] { resource.getItem().clone() }); - if (!menu.fits(r.getOutput()[0], getOutputSlots())) return; - - processing.put(b, r); - progress.put(b, r.getTicks()); - SlimefunPlugin.getGPSNetwork().getResourceManager().setSupplies(resource, b.getWorld(), b.getX() >> 4, b.getZ() >> 4, supplies - 1); - SimpleHologram.update(b, "&7Mining: &r" + resource.getName()); - return; - } - } - - } - } - - SimpleHologram.update(b, "&7Finished"); + start(b, inv); } } + private void start(Block b, BlockMenu inv) { + for (GEOResource resource : SlimefunPlugin.getRegistry().getGEOResources().values()) { + if (resource.isObtainableFromGEOMiner()) { + OptionalInt optional = SlimefunPlugin.getGPSNetwork().getResourceManager().getSupplies(resource, b.getWorld(), b.getX() >> 4, b.getZ() >> 4); + + if (!optional.isPresent()) { + SimpleHologram.update(b, "&4GEO-Scan required!"); + return; + } + + int supplies = optional.getAsInt(); + if (supplies > 0) { + MachineRecipe r = new MachineRecipe(PROCESSING_TIME / getSpeed(), new ItemStack[0], new ItemStack[] { resource.getItem().clone() }); + + if (!inv.fits(r.getOutput()[0], getOutputSlots())) { + return; + } + + processing.put(b, r); + progress.put(b, r.getTicks()); + SlimefunPlugin.getGPSNetwork().getResourceManager().setSupplies(resource, b.getWorld(), b.getX() >> 4, b.getZ() >> 4, supplies - 1); + SimpleHologram.update(b, "&7Mining: &r" + resource.getName()); + return; + } + } + } + + SimpleHologram.update(b, "&7Finished"); + } + } diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/AncientAltarListener.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/AncientAltarListener.java index 0ab53d64b..f93571d2f 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/AncientAltarListener.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/AncientAltarListener.java @@ -88,13 +88,19 @@ public class AncientAltarListener implements Listener { } Optional blockOptional = e.getClickedBlock(); - if (!blockOptional.isPresent()) return; + if (!blockOptional.isPresent()) { + return; + } Block b = blockOptional.get(); - if (b.getType() != Material.ENCHANTING_TABLE && b.getType() != Material.DISPENSER) return; + if (b.getType() != Material.ENCHANTING_TABLE && b.getType() != Material.DISPENSER) { + return; + } Optional slimefunBlock = e.getSlimefunBlock(); - if (!slimefunBlock.isPresent()) return; + if (!slimefunBlock.isPresent()) { + return; + } String id = slimefunBlock.get().getID(); @@ -124,7 +130,9 @@ public class AncientAltarListener implements Listener { Item stack = findItem(pedestal); if (stack == null) { - if (p.getInventory().getItemInMainHand().getType() == Material.AIR) return; + if (p.getInventory().getItemInMainHand().getType() != Material.AIR) { + return; + } if (pedestal.getRelative(0, 1, 0).getType() != Material.AIR) { SlimefunPlugin.getLocal().sendMessage(p, "machines.ANCIENT_PEDESTAL.obstructed", true); diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/utils/holograms/ReactorHologram.java b/src/main/java/io/github/thebusybiscuit/slimefun4/utils/holograms/ReactorHologram.java index 216210708..4f5a537fd 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/utils/holograms/ReactorHologram.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/utils/holograms/ReactorHologram.java @@ -33,7 +33,11 @@ public final class ReactorHologram { public static void update(Location l, String name) { Slimefun.runSync(() -> { ArmorStand hologram = getArmorStand(l, true); - if (!hologram.isCustomNameVisible()) hologram.setCustomNameVisible(true); + + if (!hologram.isCustomNameVisible()) { + hologram.setCustomNameVisible(true); + } + hologram.setCustomName(ChatColors.color(name)); }); } diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/utils/holograms/SimpleHologram.java b/src/main/java/io/github/thebusybiscuit/slimefun4/utils/holograms/SimpleHologram.java index afbfb5c89..20e5e9b29 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/utils/holograms/SimpleHologram.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/utils/holograms/SimpleHologram.java @@ -29,7 +29,10 @@ public final class SimpleHologram { public static void remove(Block b) { Slimefun.runSync(() -> { ArmorStand hologram = getArmorStand(b, false); - if (hologram != null) hologram.remove(); + + if (hologram != null) { + hologram.remove(); + } }); }