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

Reduced technical debt

This commit is contained in:
TheBusyBiscuit 2019-08-30 01:40:18 +02:00
parent edade50abf
commit 5fa929e633
17 changed files with 41 additions and 31 deletions

View File

@ -110,6 +110,7 @@ public abstract class ADrill extends AContainer {
@Override @Override
public void registerDefaultRecipes() {} public void registerDefaultRecipes() {}
@Override
protected void tick(Block b) { protected void tick(Block b) {
if (isProcessing(b)) { if (isProcessing(b)) {
int timeleft = progress.get(b); int timeleft = progress.get(b);

View File

@ -12,14 +12,14 @@ public class MachineHelper {
timeleft = String.valueOf(timeleft) + minutes + "m "; timeleft = String.valueOf(timeleft) + minutes + "m ";
} }
l -= minutes * 60; l -= minutes * 60;
final int seconds = (int)l; final int seconds = (int) l;
timeleft = String.valueOf(timeleft) + seconds + "s"; timeleft = String.valueOf(timeleft) + seconds + "s";
return ChatColor.translateAlternateColorCodes('&', "&7" + timeleft + " left"); return ChatColor.translateAlternateColorCodes('&', "&7" + timeleft + " left");
} }
public static String getProgress(int time, int total) { public static String getProgress(int time, int total) {
StringBuilder progress = new StringBuilder(); StringBuilder progress = new StringBuilder();
float percentage = Math.round(((((total - time) * 100.0f) / total) * 100.0f) / 100.0f); float percentage = Math.round(((((total - time) * 100.0F) / total) * 100.0F) / 100.0F);
if (percentage < 16.0F) progress.append("&4"); if (percentage < 16.0F) progress.append("&4");
else if (percentage < 32.0F) progress.append("&c"); else if (percentage < 32.0F) progress.append("&c");
@ -47,7 +47,7 @@ public class MachineHelper {
public static String getCoolant(int time, int total) { public static String getCoolant(int time, int total) {
int passed = ((total - time) % 25); int passed = ((total - time) % 25);
StringBuilder progress = new StringBuilder(); StringBuilder progress = new StringBuilder();
float percentage = Math.round(((((25 - passed) * 100.0f) / 25) * 100.0f) / 100.0f); float percentage = Math.round(((((25 - passed) * 100.0F) / 25) * 100.0F) / 100.0F);
if (percentage < 33.0F) progress.append("&9"); if (percentage < 33.0F) progress.append("&9");
else if (percentage < 66.0F) progress.append("&1"); else if (percentage < 66.0F) progress.append("&1");
@ -71,7 +71,7 @@ public class MachineHelper {
public static float getPercentage(int time, int total) { public static float getPercentage(int time, int total) {
int passed = ((total - time) % 25); int passed = ((total - time) % 25);
return Math.round(((((25 - passed) * 100.0f) / 25) * 100.0f) / 100.0f); return Math.round(((((25 - passed) * 100.0F) / 25) * 100.0F) / 100.0F);
} }
public static short getDurability(ItemStack item, int timeleft, int max) { public static short getDurability(ItemStack item, int timeleft, int max) {

View File

@ -63,6 +63,7 @@ public class ChargingBench extends AContainer {
@Override @Override
public void registerDefaultRecipes() {} public void registerDefaultRecipes() {}
@Override
protected void tick(Block b) { protected void tick(Block b) {
if (ChargableBlock.getCharge(b) < getEnergyConsumption()) return; if (ChargableBlock.getCharge(b) < getEnergyConsumption()) return;

View File

@ -44,6 +44,7 @@ public abstract class ElectricDustWasher extends AContainer {
public abstract int getSpeed(); public abstract int getSpeed();
@Override
protected void tick(Block b) { protected void tick(Block b) {
if (isProcessing(b)) { if (isProcessing(b)) {
int timeleft = progress.get(b); int timeleft = progress.get(b);

View File

@ -43,6 +43,7 @@ public abstract class ElectricGoldPan extends AContainer {
public abstract int getSpeed(); public abstract int getSpeed();
@Override
protected void tick(Block b) { protected void tick(Block b) {
if (isProcessing(b)) { if (isProcessing(b)) {
int timeleft = progress.get(b); int timeleft = progress.get(b);

View File

@ -126,6 +126,7 @@ public abstract class ElectricSmeltery extends AContainer {
this.registerDefaultRecipes(); this.registerDefaultRecipes();
} }
@Override
protected void constructMenu(BlockMenuPreset preset) { protected void constructMenu(BlockMenuPreset preset) {
for (int i : border) { for (int i : border) {
preset.addItem(i, new CustomItem(new ItemStack(Material.GRAY_STAINED_GLASS_PANE), " "), preset.addItem(i, new CustomItem(new ItemStack(Material.GRAY_STAINED_GLASS_PANE), " "),

View File

@ -102,18 +102,22 @@ public abstract class HeatedPressureChamber extends AContainer {
registerRecipe(45, new ItemStack[] {SlimefunItems.ENRICHED_NETHER_ICE}, new ItemStack[]{new CustomItem(SlimefunItems.NETHER_ICE_COOLANT_CELL, 8)}); registerRecipe(45, new ItemStack[] {SlimefunItems.ENRICHED_NETHER_ICE}, new ItemStack[]{new CustomItem(SlimefunItems.NETHER_ICE_COOLANT_CELL, 8)});
} }
@Override
public String getInventoryTitle() { public String getInventoryTitle() {
return "&cHeated Pressure Chamber"; return "&cHeated Pressure Chamber";
} }
@Override
public ItemStack getProgressBar() { public ItemStack getProgressBar() {
return new ItemStack(Material.FLINT_AND_STEEL); return new ItemStack(Material.FLINT_AND_STEEL);
} }
@Override
public int[] getInputSlots() { public int[] getInputSlots() {
return new int[] {19, 20}; return new int[] {19, 20};
} }
@Override
public int[] getOutputSlots() { public int[] getOutputSlots() {
return new int[] {24, 25}; return new int[] {24, 25};
} }
@ -140,6 +144,7 @@ public abstract class HeatedPressureChamber extends AContainer {
super.register(slimefun); super.register(slimefun);
} }
@Override
protected void tick(Block b) { protected void tick(Block b) {
if (isProcessing(b)) { if (isProcessing(b)) {
int timeleft = progress.get(b); int timeleft = progress.get(b);

View File

@ -83,6 +83,7 @@ public abstract class OilPump extends AContainer {
@Override @Override
public void registerDefaultRecipes() {} public void registerDefaultRecipes() {}
@Override
protected void tick(Block b) { protected void tick(Block b) {
if (isProcessing(b)) { if (isProcessing(b)) {
int timeleft = progress.get(b); int timeleft = progress.get(b);

View File

@ -45,6 +45,7 @@ public abstract class Refinery extends AContainer {
return "REFINERY"; return "REFINERY";
} }
@Override
protected void tick(Block b) { protected void tick(Block b) {
if (isProcessing(b)) { if (isProcessing(b)) {
int timeleft = progress.get(b); int timeleft = progress.get(b);

View File

@ -32,7 +32,7 @@ public class JetBootsTask extends SlimefunTask {
p.getWorld().playSound(p.getLocation(), Sound.ENTITY_TNT_PRIMED, (float) 0.25, 1); p.getWorld().playSound(p.getLocation(), Sound.ENTITY_TNT_PRIMED, (float) 0.25, 1);
p.getWorld().playEffect(p.getLocation(), Effect.SMOKE, 1, 1); p.getWorld().playEffect(p.getLocation(), Effect.SMOKE, 1, 1);
p.setFallDistance(0.0f); p.setFallDistance(0F);
double gravity = 0.04; double gravity = 0.04;
double offset = new Random().nextInt(2) == 1 ? accuracy: -accuracy; double offset = new Random().nextInt(2) == 1 ? accuracy: -accuracy;
Vector vector = new Vector(p.getEyeLocation().getDirection().getX() * speed + offset, gravity, p.getEyeLocation().getDirection().getZ() * speed - offset); Vector vector = new Vector(p.getEyeLocation().getDirection().getX() * speed + offset, gravity, p.getEyeLocation().getDirection().getZ() * speed - offset);

View File

@ -32,7 +32,7 @@ public class JetpackTask extends SlimefunTask {
p.getWorld().playSound(p.getLocation(), Sound.ENTITY_GENERIC_EXPLODE, (float) 0.25, 1); p.getWorld().playSound(p.getLocation(), Sound.ENTITY_GENERIC_EXPLODE, (float) 0.25, 1);
p.getWorld().playEffect(p.getLocation(), Effect.SMOKE, 1, 1); p.getWorld().playEffect(p.getLocation(), Effect.SMOKE, 1, 1);
p.setFallDistance(0.0f); p.setFallDistance(0F);
Vector vector = new Vector(0, 1, 0); Vector vector = new Vector(0, 1, 0);
vector.multiply(thrust); vector.multiply(thrust);
vector.add(p.getEyeLocation().getDirection().multiply(0.2F)); vector.add(p.getEyeLocation().getDirection().multiply(0.2F));

View File

@ -16,7 +16,7 @@ public class ParachuteTask extends SlimefunTask {
Vector vector = new Vector(0, 1, 0); Vector vector = new Vector(0, 1, 0);
vector.multiply(-0.1); vector.multiply(-0.1);
p.setVelocity(vector); p.setVelocity(vector);
p.setFallDistance(0.0f); p.setFallDistance(0F);
if (!p.isSneaking()) Bukkit.getScheduler().cancelTask(id); if (!p.isSneaking()) Bukkit.getScheduler().cancelTask(id);
} }

View File

@ -966,7 +966,7 @@ public final class SlimefunSetup {
p.setVelocity(p.getEyeLocation().getDirection().multiply(4)); p.setVelocity(p.getEyeLocation().getDirection().multiply(4));
p.getWorld().playSound(p.getLocation(), Sound.ENTITY_TNT_PRIMED, 1, 1); p.getWorld().playSound(p.getLocation(), Sound.ENTITY_TNT_PRIMED, 1, 1);
p.getWorld().playEffect(p.getLocation(), Effect.SMOKE, 1); p.getWorld().playEffect(p.getLocation(), Effect.SMOKE, 1);
p.setFallDistance(0.0f); p.setFallDistance(0F);
} }
else { else {
Messages.local.sendTranslation(p, "messages.hungry", true); Messages.local.sendTranslation(p, "messages.hungry", true);

View File

@ -423,7 +423,7 @@ public final class SlimefunGuide {
); );
List<Category> categories = Slimefun.current_categories; List<Category> categories = Slimefun.current_categories;
List<GuideHandler> handlers = Slimefun.guide_handlers.values().stream().flatMap(list -> list.stream()).collect(Collectors.toList()); List<GuideHandler> handlers = Slimefun.guide_handlers.values().stream().flatMap(List::stream).collect(Collectors.toList());
int index = 9; int index = 9;
int pages = 1; int pages = 1;

View File

@ -104,7 +104,7 @@ public class BlockStorage {
} }
else if (file.getName().endsWith(".sfb")) { else if (file.getName().endsWith(".sfb")) {
if (timestamp + SlimefunStartup.instance.getSettings().BLOCK_LOADING_INFO_DELAY < System.currentTimeMillis()) { if (timestamp + SlimefunStartup.instance.getSettings().BLOCK_LOADING_INFO_DELAY < System.currentTimeMillis()) {
System.out.println("[Slimefun] Loading Blocks... " + Math.round((((done * 100.0f) / total) * 100.0f) / 100.0f) + "% done (\"" + w.getName() + "\")"); System.out.println("[Slimefun] Loading Blocks... " + Math.round((((done * 100.0F) / total) * 100.0F) / 100.0F) + "% done (\"" + w.getName() + "\")");
timestamp = System.currentTimeMillis(); timestamp = System.currentTimeMillis();
} }
@ -318,9 +318,9 @@ public class BlockStorage {
} }
public static Config getLocationInfo(Location l) { public static Config getLocationInfo(Location l) {
BlockStorage storage = getStorage(l.getWorld()); BlockStorage storage = getStorage(l.getWorld());
Config cfg = storage.storage.get(l); Config cfg = storage.storage.get(l);
return cfg == null ? new BlockInfoConfig() : cfg; return cfg == null ? new BlockInfoConfig() : cfg;
} }
private static Map<String, String> parseJSON(String json) { private static Map<String, String> parseJSON(String json) {
@ -374,7 +374,7 @@ public class BlockStorage {
} }
public static String getLocationInfo(Location l, String key) { public static String getLocationInfo(Location l, String key) {
return getBlockInfo(l).getString(key); return getLocationInfo(l).getString(key);
} }
public static void addBlockInfo(Location l, String key, String value) { public static void addBlockInfo(Location l, String key, String value) {
@ -616,9 +616,7 @@ public class BlockStorage {
if (menu != null) { if (menu != null) {
for (HumanEntity human : new ArrayList<>(menu.toInventory().getViewers())) { for (HumanEntity human : new ArrayList<>(menu.toInventory().getViewers())) {
// Prevents "java.lang.IllegalStateException: Asynchronous entity add!" when closing inventory while holding an item // Prevents "java.lang.IllegalStateException: Asynchronous entity add!" when closing inventory while holding an item
Bukkit.getScheduler().scheduleSyncDelayedTask(SlimefunStartup.instance, () -> { Bukkit.getScheduler().scheduleSyncDelayedTask(SlimefunStartup.instance, () -> human.closeInventory());
human.closeInventory();
});
} }
inventories.get(l).delete(l); inventories.get(l).delete(l);

View File

@ -42,7 +42,7 @@ public class PlaceholderAPIHook extends PlaceholderExpansion {
public String onRequest(OfflinePlayer p, String params) { public String onRequest(OfflinePlayer p, String params) {
if (params.equals("researches_total_xp_levels_spent")) { if (params.equals("researches_total_xp_levels_spent")) {
Stream<Research> stream = PlayerProfile.fromUUID(p.getUniqueId()).getResearches().stream(); Stream<Research> stream = PlayerProfile.fromUUID(p.getUniqueId()).getResearches().stream();
return String.valueOf(stream.mapToInt(r -> r.getCost()).sum()); return String.valueOf(stream.mapToInt(Research::getCost).sum());
} }
if (params.equals("researches_total_researches_unlocked")) { if (params.equals("researches_total_researches_unlocked")) {