1
mirror of https://github.com/StarWishsama/Slimefun4.git synced 2024-09-20 03:35:51 +00:00

[CI skip] Reduced technical debt

This commit is contained in:
TheBusyBiscuit 2020-06-13 13:52:53 +02:00
parent 4dbc66fc4e
commit e3dc17a9df
5 changed files with 71 additions and 49 deletions

View File

@ -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<String>());
script.setValue("rating.negative", new ArrayList<String>());
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<String>());
config.setValue("rating.negative", new ArrayList<String>());
config.save();
}
}

View File

@ -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,6 +180,11 @@ public abstract class GEOMiner extends AContainer implements InventoryBlock, Rec
SimpleHologram.update(b, "&4GEO-Scan required!");
}
else {
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);
@ -185,12 +193,14 @@ public abstract class GEOMiner extends AContainer implements InventoryBlock, Rec
SimpleHologram.update(b, "&4GEO-Scan required!");
return;
}
else {
int supplies = optional.getAsInt();
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;
if (!inv.fits(r.getOutput()[0], getOutputSlots())) {
return;
}
processing.put(b, r);
progress.put(b, r.getTicks());
@ -199,12 +209,9 @@ public abstract class GEOMiner extends AContainer implements InventoryBlock, Rec
return;
}
}
}
}
SimpleHologram.update(b, "&7Finished");
}
}
}

View File

@ -88,13 +88,19 @@ public class AncientAltarListener implements Listener {
}
Optional<Block> 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<SlimefunItem> 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);

View File

@ -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));
});
}

View File

@ -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();
}
});
}