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

Refactored Code

This commit is contained in:
TheBusyBiscuit 2019-08-30 23:21:34 +02:00
parent 24ec50e072
commit 9aa7845293
10 changed files with 35 additions and 35 deletions

View File

@ -80,7 +80,7 @@ public class Research {
}
public boolean isEnabled() {
return SlimefunStartup.instance.getSettings().RESEARCHES_ENABLED && enabled;
return SlimefunStartup.instance.getSettings().researchesEnabled && enabled;
}
/**
@ -214,7 +214,7 @@ public class Research {
*/
public boolean canUnlock(Player p) {
if (!isEnabled()) return true;
return (p.getGameMode() == GameMode.CREATIVE && SlimefunStartup.instance.getSettings().RESEARCHES_FREE_IN_CREATIVE) || p.getLevel() >= this.cost;
return (p.getGameMode() == GameMode.CREATIVE && SlimefunStartup.instance.getSettings().researchesFreeInCreative) || p.getLevel() >= this.cost;
}
/**

View File

@ -123,7 +123,7 @@ public class AutoEnchanter extends AContainer {
special_amount += EmeraldEnchants.getInstance().getRegistry().getEnchantments(target).size();
}
if (amount > 0 && special_amount <= SlimefunStartup.instance.getSettings().EMERALD_ENCHANTS_LIMIT) {
if (amount > 0 && special_amount <= SlimefunStartup.instance.getSettings().emeraldEnchantsLimit) {
ItemStack newItem = target.clone();
for (Map.Entry<Enchantment, Integer> e: enchantments.entrySet()) {
newItem.addUnsafeEnchantment(e.getKey(), e.getValue());

View File

@ -81,7 +81,7 @@ public abstract class ElectricDustWasher extends AContainer {
else {
for (int slot: getInputSlots()) {
if (SlimefunManager.isItemSimiliar(BlockStorage.getInventory(b).getItemInSlot(slot), SlimefunItems.SIFTED_ORE, true)) {
if (!SlimefunStartup.instance.getSettings().DUST_WASHER_LEGACY) {
if (!SlimefunStartup.instance.getSettings().legacyDustWasher) {
boolean empty_slot = false;
for (int output_slot: getOutputSlots()) {
if (BlockStorage.getInventory(b).getItemInSlot(output_slot) == null) {
@ -94,7 +94,7 @@ public abstract class ElectricDustWasher extends AContainer {
ItemStack adding = OreWasher.items[new Random().nextInt(OreWasher.items.length)];
MachineRecipe r = new MachineRecipe(4 / getSpeed(), new ItemStack[0], new ItemStack[] {adding});
if (SlimefunStartup.instance.getSettings().DUST_WASHER_LEGACY && !fits(b, r.getOutput())) return;
if (SlimefunStartup.instance.getSettings().legacyDustWasher && !fits(b, r.getOutput())) return;
BlockStorage.getInventory(b).replaceExistingItem(slot, InvUtils.decreaseItem(BlockStorage.getInventory(b).getItemInSlot(slot), 1));
processing.put(b, r);
progress.put(b, r.getTicks());

View File

@ -56,7 +56,7 @@ public class OreWasher extends MultiBlockMachine {
ItemStack adding = items[new Random().nextInt(items.length)];
Inventory outputInv = null;
if (!SlimefunStartup.instance.getSettings().ORE_WASHER_LEGACY) {
if (!SlimefunStartup.instance.getSettings().legacyOreWasher) {
// This is a fancy way of checking if there is empty space in the inv; by checking if an unobtainable item could fit in it.
// However, due to the way the method findValidOutputInv() functions, the dummyAdding will never actually be added to the real inventory,
// so it really doesn't matter what item the ItemStack is made by. SlimefunItems.DEBUG_FISH however, signals that it's

View File

@ -160,7 +160,7 @@ public final class MiscSetup {
// Favour 8 Cobblestone -> 1 Sand Recipe over 1 Cobblestone -> 1 Gravel Recipe
Stream<ItemStack[]> stream = grinder_recipes.stream();
if (!settings.ORE_GRINDER_LEGACY) {
if (!settings.legacyOreGrinder) {
stream = stream.sorted((a, b) -> Integer.compare(b[0].getAmount(), a[0].getAmount()));
}

View File

@ -567,7 +567,7 @@ public final class SlimefunGuide {
openCategory(p, category, true, selected_page, book);
}
else {
if (!(p.getGameMode() == GameMode.CREATIVE && SlimefunStartup.instance.getSettings().RESEARCHES_FREE_IN_CREATIVE)) {
if (!(p.getGameMode() == GameMode.CREATIVE && SlimefunStartup.instance.getSettings().researchesFreeInCreative)) {
p.setLevel(p.getLevel() - research.getCost());
}
@ -706,12 +706,12 @@ public final class SlimefunGuide {
openCategory(p, category, true, selected_page, book);
}
else {
if (!(pl.getGameMode() == GameMode.CREATIVE && SlimefunStartup.instance.getSettings().RESEARCHES_FREE_IN_CREATIVE)) {
if (!(pl.getGameMode() == GameMode.CREATIVE && SlimefunStartup.instance.getSettings().researchesFreeInCreative)) {
pl.setLevel(pl.getLevel() - research.getCost());
}
if (pl.getGameMode() == GameMode.CREATIVE) {
research.unlock(pl, SlimefunStartup.instance.getSettings().RESEARCHES_FREE_IN_CREATIVE);
research.unlock(pl, SlimefunStartup.instance.getSettings().researchesFreeInCreative);
openCategory(pl, category, survival, selected_page, book);
}
else {
@ -780,7 +780,7 @@ public final class SlimefunGuide {
final SlimefunItem sfItem = SlimefunItem.getByItem(item);
if (sfItem == null && !SlimefunStartup.instance.getSettings().GUIDE_SHOW_VANILLA_RECIPES) return;
if (sfItem == null && !SlimefunStartup.instance.getSettings().guideShowVanillaRecipes) return;
ItemStack[] recipe = new ItemStack[9];
ItemStack recipeType = null;

View File

@ -191,7 +191,7 @@ public final class SlimefunStartup extends JavaPlugin {
MiscSetup.loadDescriptions();
settings = new Settings(config);
settings.RESEARCHES_ENABLED = getResearchCfg().getBoolean("enable-researching");
settings.researchesEnabled = getResearchCfg().getBoolean("enable-researching");
settings.SMELTERY_FIRE_BREAK_CHANCE = (Integer) Slimefun.getItemValue("SMELTERY", "chance.fireBreak");
System.out.println("[Slimefun] Loading Researches...");
@ -301,10 +301,10 @@ public final class SlimefunStartup extends JavaPlugin {
ticker = new TickerTask();
getServer().getScheduler().runTaskTimer(this, new PlayerAutoSaver(), 2000L, settings.BLOCK_AUTO_SAVE_DELAY * 60L * 20L);
getServer().getScheduler().runTaskTimer(this, new PlayerAutoSaver(), 2000L, settings.blocksAutoSaveDelay * 60L * 20L);
// Starting all ASYNC Tasks
getServer().getScheduler().runTaskTimerAsynchronously(this, new BlockAutoSaver(), 2000L, settings.BLOCK_AUTO_SAVE_DELAY * 60L * 20L);
getServer().getScheduler().runTaskTimerAsynchronously(this, new BlockAutoSaver(), 2000L, settings.blocksAutoSaveDelay * 60L * 20L);
getServer().getScheduler().runTaskTimerAsynchronously(this, ticker, 100L, config.getInt("URID.custom-ticker-delay"));
getServer().getScheduler().runTaskTimerAsynchronously(this, () -> utilities.connectors.forEach(GitHubConnector::pullFile), 80L, 60 * 60 * 20L);

View File

@ -103,7 +103,7 @@ public class BlockStorage {
System.err.println("[Slimefun] should probably look into it!");
}
else if (file.getName().endsWith(".sfb")) {
if (timestamp + SlimefunStartup.instance.getSettings().BLOCK_LOADING_INFO_DELAY < System.currentTimeMillis()) {
if (timestamp + SlimefunStartup.instance.getSettings().blocksInfoLoadingDelay < System.currentTimeMillis()) {
System.out.println("[Slimefun] Loading Blocks... " + Math.round((((done * 100.0F) / total) * 100.0F) / 100.0F) + "% done (\"" + w.getName() + "\")");
timestamp = System.currentTimeMillis();
}

View File

@ -161,7 +161,7 @@ public final class PlayerProfile {
}
public String getTitle() {
List<String> titles = SlimefunStartup.instance.getSettings().RESEARCHES_TITLES;
List<String> titles = SlimefunStartup.instance.getSettings().researchesTitles;
int index = Math.round(Float.valueOf(String.valueOf(Math.round(((researches.size() * 100.0F) / Research.list().size()) * 100.0F) / 100.0F)) / 100.0F) * titles.size();
if (index > 0) index--;

View File

@ -6,37 +6,37 @@ import me.mrCookieSlime.CSCoreLibPlugin.Configuration.Config;
public final class Settings {
public boolean RESEARCHES_ENABLED;
public boolean RESEARCHES_FREE_IN_CREATIVE;
public List<String> RESEARCHES_TITLES;
public boolean researchesEnabled;
public boolean researchesFreeInCreative;
public List<String> researchesTitles;
public int BLOCK_LOADING_INFO_DELAY;
public int BLOCK_AUTO_SAVE_DELAY;
public int blocksInfoLoadingDelay;
public int blocksAutoSaveDelay;
public boolean GUIDE_SHOW_VANILLA_RECIPES;
public boolean guideShowVanillaRecipes;
public int EMERALD_ENCHANTS_LIMIT;
public int emeraldEnchantsLimit;
public boolean DUST_WASHER_LEGACY;
public boolean ORE_GRINDER_LEGACY;
public boolean ORE_WASHER_LEGACY;
public boolean legacyDustWasher;
public boolean legacyOreGrinder;
public boolean legacyOreWasher;
public int SMELTERY_FIRE_BREAK_CHANCE;
public Settings(Config cfg) {
RESEARCHES_FREE_IN_CREATIVE = cfg.getBoolean("options.allow-free-creative-research");
RESEARCHES_TITLES = cfg.getStringList("research-ranks");
researchesFreeInCreative = cfg.getBoolean("options.allow-free-creative-research");
researchesTitles = cfg.getStringList("research-ranks");
BLOCK_LOADING_INFO_DELAY = cfg.getInt("URID.info-delay");
BLOCK_AUTO_SAVE_DELAY = cfg.getInt("options.auto-save-delay-in-minutes");
blocksInfoLoadingDelay = cfg.getInt("URID.info-delay");
blocksAutoSaveDelay = cfg.getInt("options.auto-save-delay-in-minutes");
GUIDE_SHOW_VANILLA_RECIPES = cfg.getBoolean("options.show-vanilla-recipes-in-guide");
guideShowVanillaRecipes = cfg.getBoolean("options.show-vanilla-recipes-in-guide");
EMERALD_ENCHANTS_LIMIT = cfg.getInt("options.emerald-enchantment-limit");
emeraldEnchantsLimit = cfg.getInt("options.emerald-enchantment-limit");
DUST_WASHER_LEGACY = cfg.getBoolean("options.legacy-dust-washer");
ORE_WASHER_LEGACY = cfg.getBoolean("options.legacy-ore-washer");
ORE_GRINDER_LEGACY = cfg.getBoolean("options.legacy-ore-grinder");
legacyDustWasher = cfg.getBoolean("options.legacy-dust-washer");
legacyOreWasher = cfg.getBoolean("options.legacy-ore-washer");
legacyOreGrinder = cfg.getBoolean("options.legacy-ore-grinder");
}
}