1
mirror of https://github.com/StarWishsama/Slimefun4.git synced 2024-09-19 19:25:48 +00:00

Slimefun Guide now shows ALL minecraft recipes, with pages

This commit is contained in:
TheBusyBiscuit 2019-12-27 02:16:01 +01:00
parent 582369c5b6
commit 2a06c2e215
15 changed files with 147 additions and 225 deletions

View File

@ -39,6 +39,7 @@ https://thebusybiscuit.github.io/builds/TheBusyBiscuit/Slimefun4/stable/#4
* Added config option for circuit board drops
* Added player option to toggle research fireworks in the guide settings
* Added Kelp Cookies
* Added support for multiple recipes on vanilla items
### Changes
* Revamped Guide Settings menu

View File

@ -5,8 +5,6 @@ import java.util.Arrays;
import java.util.LinkedList;
import java.util.List;
import java.util.Optional;
import java.util.Set;
import java.util.logging.Level;
import java.util.stream.Collectors;
import org.bukkit.ChatColor;
@ -342,7 +340,7 @@ public class ChestSlimefunGuide implements ISlimefunGuide {
if (item == null || item.getType() == Material.AIR) return;
final SlimefunItem sfItem = SlimefunItem.getByItem(item);
SlimefunItem sfItem = SlimefunItem.getByItem(item);
if (sfItem != null) {
displayItem(profile, sfItem, addToHistory);
@ -353,53 +351,81 @@ public class ChestSlimefunGuide implements ISlimefunGuide {
return;
}
Set<Recipe> recipes = SlimefunPlugin.getMinecraftRecipes().getRecipesFor(item);
Recipe[] recipes = SlimefunPlugin.getMinecraftRecipes().getRecipesFor(item).toArray(new Recipe[0]);
ItemStack[] recipe = new ItemStack[9];
RecipeType recipeType = null;
ItemStack result = null;
for (Recipe r : recipes) {
Optional<MinecraftRecipe<? super Recipe>> optional = MinecraftRecipe.of(r);
if (optional.isPresent()) {
MinecraftRecipe<?> mcRecipe = optional.get();
RecipeChoice[] choices = SlimefunPlugin.getMinecraftRecipes().getRecipeInput(r);
if (choices.length == 1) {
recipe[4] = choices[0].getItemStack();
}
else {
for (int i = 0; i < choices.length; i++) {
if (choices[i] != null) {
recipe[i] = choices[i].getItemStack();
}
}
}
if (mcRecipe == MinecraftRecipe.SHAPED_CRAFTING) {
recipeType = new RecipeType(new CustomItem(mcRecipe.getMachine(), null, "&7Shaped Recipe"));
}
else if (mcRecipe == MinecraftRecipe.SHAPELESS_CRAFTING) {
recipeType = new RecipeType(new CustomItem(mcRecipe.getMachine(), null, "&7Shapeless Recipe"));
}
else {
recipeType = new RecipeType(mcRecipe);
}
result = r.getResult();
break;
}
}
if (recipeType == null) {
if (recipes.length == 0) {
return;
}
showMinecraftRecipe(recipes, 0, item, profile, p, addToHistory);
}
private void showMinecraftRecipe(Recipe[] recipes, int index, ItemStack item, PlayerProfile profile, Player p, boolean addToHistory) {
Recipe recipe = recipes[index];
ItemStack[] recipeItems = new ItemStack[9];
RecipeType recipeType = RecipeType.NULL;
ItemStack result = null;
Optional<MinecraftRecipe<? super Recipe>> optional = MinecraftRecipe.of(recipe);
if (optional.isPresent()) {
MinecraftRecipe<?> mcRecipe = optional.get();
RecipeChoice[] choices = SlimefunPlugin.getMinecraftRecipes().getRecipeInput(recipe);
if (choices.length == 1) {
recipeItems[4] = choices[0].getItemStack();
}
else {
for (int i = 0; i < choices.length; i++) {
if (choices[i] != null) {
recipeItems[i] = choices[i].getItemStack();
}
}
}
if (mcRecipe == MinecraftRecipe.SHAPED_CRAFTING) {
recipeType = new RecipeType(new CustomItem(mcRecipe.getMachine(), null, "&7Shaped Recipe"));
}
else if (mcRecipe == MinecraftRecipe.SHAPELESS_CRAFTING) {
recipeType = new RecipeType(new CustomItem(mcRecipe.getMachine(), null, "&7Shapeless Recipe"));
}
else {
recipeType = new RecipeType(mcRecipe);
}
result = recipe.getResult();
}
else {
recipeItems = new ItemStack[] {null, null, null, null, new CustomItem(Material.BARRIER, "&4We are somehow unable to show you this Recipe :/"), null, null, null, null};
}
ChestMenu menu = create();
displayItem(menu, profile, p, item, result, recipeType, recipe, addToHistory);
displayItem(menu, profile, p, item, result, recipeType, recipeItems, addToHistory);
if (recipes.length > 1) {
for (int i = 27; i < 36; i++) {
menu.addItem(i, ChestMenuUtils.getBackground(), ChestMenuUtils.getEmptyClickHandler());
}
menu.addItem(28, ChestMenuUtils.getPreviousButton(index + 1, recipes.length),
(pl, slot, action, stack) -> {
if (index > 0) {
showMinecraftRecipe(recipes, index - 1, item, profile, p, false);
}
return false;
});
menu.addItem(34, ChestMenuUtils.getNextButton(index + 1, recipes.length),
(pl, slot, action, stack) -> {
if (index < recipes.length - 1) {
showMinecraftRecipe(recipes, index + 1, item, profile, p, false);
}
return false;
});
}
menu.open(p);
}
@ -415,29 +441,21 @@ public class ChestSlimefunGuide implements ISlimefunGuide {
ChestMenu menu = create();
if (item.hasWiki()) {
try {
menu.addItem(8, new CustomItem(Material.KNOWLEDGE_BOOK, "&rView this Item on our Wiki &7(Slimefun Wiki)", "", "&7\u21E8 Click to open"));
menu.addMenuClickHandler(8, (pl, slot, itemstack, action) -> {
pl.closeInventory();
ChatUtils.sendURL(pl, item.getWiki());
return false;
});
} catch (Exception x) {
Slimefun.getLogger().log(Level.SEVERE, "An Error occurred while adding a Wiki Page for Slimefun " + Slimefun.getVersion(), x);
}
menu.addItem(8, new CustomItem(Material.KNOWLEDGE_BOOK, "&rView this Item on our Wiki &7(Slimefun Wiki)", "", "&7\u21E8 Click to open"));
menu.addMenuClickHandler(8, (pl, slot, itemstack, action) -> {
pl.closeInventory();
ChatUtils.sendURL(pl, item.getWiki());
return false;
});
}
if (Slimefun.getItemConfig().contains(item.getID() + ".youtube")) {
try {
menu.addItem(7, new CustomItem(SkullItem.fromBase64("eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvYjQzNTNmZDBmODYzMTQzNTM4NzY1ODYwNzViOWJkZjBjNDg0YWFiMDMzMWI4NzJkZjExYmQ1NjRmY2IwMjllZCJ9fX0="), "&rDemonstration Video &7(Youtube)", "", "&7\u21E8 Click to watch"));
menu.addMenuClickHandler(7, (pl, slot, itemstack, action) -> {
pl.closeInventory();
ChatUtils.sendURL(pl, Slimefun.getItemConfig().getString(item.getID() + ".youtube"));
return false;
});
} catch (Exception x) {
Slimefun.getLogger().log(Level.SEVERE, "An Error occurred while adding a Youtube Video for Slimefun " + Slimefun.getVersion(), x);
}
menu.addItem(7, new CustomItem(SkullItem.fromBase64("eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvYjQzNTNmZDBmODYzMTQzNTM4NzY1ODYwNzViOWJkZjBjNDg0YWFiMDMzMWI4NzJkZjExYmQ1NjRmY2IwMjllZCJ9fX0="), "&rDemonstration Video &7(Youtube)", "", "&7\u21E8 Click to watch"));
menu.addMenuClickHandler(7, (pl, slot, itemstack, action) -> {
pl.closeInventory();
ChatUtils.sendURL(pl, Slimefun.getItemConfig().getString(item.getID() + ".youtube"));
return false;
});
}
displayItem(menu, profile, p, item, result, recipeType, recipe, addToHistory);
@ -477,8 +495,7 @@ public class ChestSlimefunGuide implements ISlimefunGuide {
return false;
});
menu.addItem(10, recipeType.toItem());
menu.addMenuClickHandler(10, ChestMenuUtils.getEmptyClickHandler());
menu.addItem(10, recipeType.toItem(), ChestMenuUtils.getEmptyClickHandler());
menu.addItem(12, getDisplayItem(p, isSlimefunRecipe, recipe[3]));
menu.addMenuClickHandler(12, (pl, slot, itemstack, action) -> {
@ -498,8 +515,7 @@ public class ChestSlimefunGuide implements ISlimefunGuide {
return false;
});
menu.addItem(16, output);
menu.addMenuClickHandler(16, ChestMenuUtils.getEmptyClickHandler());
menu.addItem(16, output, ChestMenuUtils.getEmptyClickHandler());
menu.addItem(21, getDisplayItem(p, isSlimefunRecipe, recipe[6]));
menu.addMenuClickHandler(21, (pl, slot, itemstack, action) -> {

View File

@ -1,13 +1,11 @@
package me.mrCookieSlime.Slimefun.GEO;
import java.util.logging.Level;
import org.bukkit.Chunk;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import io.github.thebusybiscuit.cscorelib2.skull.SkullItem;
import io.github.thebusybiscuit.slimefun4.core.utils.ChestMenuUtils;
import me.mrCookieSlime.CSCoreLibPlugin.general.Inventory.ChestMenu;
import me.mrCookieSlime.CSCoreLibPlugin.general.Inventory.Item.CustomItem;
import me.mrCookieSlime.Slimefun.SlimefunPlugin;
@ -15,7 +13,7 @@ import me.mrCookieSlime.Slimefun.api.Slimefun;
public final class GEOScanner {
private static final int[] geoscan_border = new int[] {0, 1, 2, 3, 5, 6, 7, 8, 9, 17, 18, 26, 27, 35, 36, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53};
private static final int[] BACKGROUND_SLOTS = {0, 1, 2, 3, 5, 6, 7, 8, 9, 17, 18, 26, 27, 35, 36, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53};
private GEOScanner() {}
@ -26,17 +24,16 @@ public final class GEOScanner {
}
ChestMenu menu = new ChestMenu("&4GEO-Scan Results");
for (int slot : geoscan_border) {
menu.addItem(slot, new CustomItem(new ItemStack(Material.GRAY_STAINED_GLASS_PANE), " "),
(pl, slotn, item, action) -> false
);
for (int slot : BACKGROUND_SLOTS) {
menu.addItem(slot, ChestMenuUtils.getBackground(), ChestMenuUtils.getEmptyClickHandler());
}
try {
menu.addItem(4, new CustomItem(SkullItem.fromBase64("eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvODQ0OWI5MzE4ZTMzMTU4ZTY0YTQ2YWIwZGUxMjFjM2Q0MDAwMGUzMzMyYzE1NzQ5MzJiM2M4NDlkOGZhMGRjMiJ9fX0="), "&eScanned Chunk", "", "&8\u21E8 &7World: " + chunk.getWorld().getName(), "&8\u21E8 &7X: " + chunk.getX() + " Z: " + chunk.getZ()), (pl, slot, stack, action) -> false);
} catch (Exception e) {
Slimefun.getLogger().log(Level.SEVERE, "Error while scanning a chunk for Slimefun " + Slimefun.getVersion(), e);
}
menu.addItem(4, new CustomItem(SkullItem.fromBase64("eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvODQ0OWI5MzE4ZTMzMTU4ZTY0YTQ2YWIwZGUxMjFjM2Q0MDAwMGUzMzMyYzE1NzQ5MzJiM2M4NDlkOGZhMGRjMiJ9fX0="),
"&eScanned Chunk",
"",
"&8\u21E8 &7World: " + chunk.getWorld().getName(),
"&8\u21E8 &7X: " + chunk.getX() + " Z: " + chunk.getZ()
), ChestMenuUtils.getEmptyClickHandler());
int index = 10;
for (OreGenResource resource : OreGenSystem.listResources()) {
@ -48,7 +45,7 @@ public final class GEOScanner {
item.setAmount(supply > item.getMaxStackSize() ? item.getMaxStackSize(): supply);
}
menu.addItem(index, item, (pl, slot, stack, action) -> false);
menu.addItem(index, item, ChestMenuUtils.getEmptyClickHandler());
index++;
if (index % 9 == 8) {

View File

@ -41,6 +41,7 @@ import me.mrCookieSlime.Slimefun.api.inventory.BlockMenu;
import me.mrCookieSlime.Slimefun.api.inventory.BlockMenuPreset;
import me.mrCookieSlime.Slimefun.api.item_transport.ItemTransportFlow;
import me.mrCookieSlime.Slimefun.holograms.ReactorHologram;
import me.mrCookieSlime.Slimefun.holograms.SimpleHologram;
import me.mrCookieSlime.Slimefun.utils.MachineHelper;
public abstract class AReactor extends SlimefunItem implements RecipeDisplayItem {
@ -164,7 +165,7 @@ public abstract class AReactor extends SlimefunItem implements RecipeDisplayItem
progress.remove(b.getLocation());
processing.remove(b.getLocation());
ReactorHologram.remove(b.getLocation());
SimpleHologram.remove(b);
return true;
});
@ -355,7 +356,7 @@ public abstract class AReactor extends SlimefunItem implements RecipeDisplayItem
if (explosion) {
BlockStorage.getInventory(l).close();
Slimefun.runSync(() -> ReactorHologram.remove(l), 0);
Slimefun.runSync(() -> SimpleHologram.remove(l.getBlock()));
explode.remove(l);
processing.remove(l);

View File

@ -13,7 +13,7 @@ import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.UnregisterReason;
import me.mrCookieSlime.Slimefun.Objects.handlers.BlockTicker;
import me.mrCookieSlime.Slimefun.api.SlimefunItemStack;
import me.mrCookieSlime.Slimefun.api.energy.EnergyNet;
import me.mrCookieSlime.Slimefun.holograms.EnergyHologram;
import me.mrCookieSlime.Slimefun.holograms.SimpleHologram;
public class EnergyRegulator extends SlimefunItem {
@ -25,12 +25,12 @@ public class EnergyRegulator extends SlimefunItem {
@Override
public void onPlace(Player p, Block b, SlimefunItem item) {
// Spawn the hologram
EnergyHologram.update(b, "&7Connecting...");
SimpleHologram.update(b, "&7Connecting...");
}
@Override
public boolean onBreak(Player p, Block b, SlimefunItem item, UnregisterReason reason) {
EnergyHologram.remove(b);
SimpleHologram.remove(b);
return true;
}
});

View File

@ -1,54 +0,0 @@
package me.mrCookieSlime.Slimefun.Setup;
import java.io.File;
import java.util.logging.Level;
import me.mrCookieSlime.Slimefun.api.Slimefun;
public final class Files {
public final File researches = new File("plugins/Slimefun/Researches.yml");
public final File config = new File("plugins/Slimefun/config.yml");
public final File items = new File("plugins/Slimefun/Items.yml");
public final File database = new File("data-storage/Slimefun/Players");
public final File whitelist = new File("plugins/Slimefun/whitelist.yml");
public void cleanup() {
if (!researches.exists()) {
Slimefun.getLogger().log(Level.WARNING, "###############################################");
Slimefun.getLogger().log(Level.WARNING, "############## = - INFO - = #################");
Slimefun.getLogger().log(Level.WARNING, "###############################################");
Slimefun.getLogger().log(Level.WARNING, " ");
Slimefun.getLogger().log(Level.WARNING, "Slimefun Warning:");
Slimefun.getLogger().log(Level.WARNING, " ");
Slimefun.getLogger().log(Level.WARNING, "Slimefun has detected that your Files are either");
Slimefun.getLogger().log(Level.WARNING, "outdated or do not exist. We generated new Files");
Slimefun.getLogger().log(Level.WARNING, "instead otherwise Slimefun would not work. If you");
Slimefun.getLogger().log(Level.WARNING, "have used Slimefun before, your Settings are now");
Slimefun.getLogger().log(Level.WARNING, "gone. But therefore Slimefun works!");
delete(new File("plugins/Slimefun"));
delete(new File("data-storage/Slimefun"));
}
if (!database.exists()) {
database.mkdirs();
}
}
public boolean delete(File folder) {
File[] files = folder.listFiles();
if (files != null) {
for (File current: files) {
if (current.isDirectory()) {
if (!delete(current)) return false;
}
else {
if (!current.delete()) return false;
}
}
}
return folder.delete();
}
}

View File

@ -27,7 +27,7 @@ import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunMachine;
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.machines.electric.AutomatedCraftingChamber;
import me.mrCookieSlime.Slimefun.api.Slimefun;
import me.mrCookieSlime.Slimefun.api.SlimefunRecipes;
import me.mrCookieSlime.Slimefun.utils.Settings;
import me.mrCookieSlime.Slimefun.utils.ConfigCache;
public final class MiscSetup {
@ -48,7 +48,7 @@ public final class MiscSetup {
SlimefunItem.setRadioactive(SlimefunItems.ENRICHED_NETHER_ICE);
}
public static void loadItems(Settings settings) {
public static void loadItems(ConfigCache settings) {
Iterator<SlimefunItem> iterator = SlimefunItem.list().iterator();
while (iterator.hasNext()) {
SlimefunItem item = iterator.next();

View File

@ -9,6 +9,7 @@ import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.plugin.java.JavaPlugin;
import io.github.thebusybiscuit.cscorelib2.config.Config;
import io.github.thebusybiscuit.cscorelib2.protection.ProtectionManager;
import io.github.thebusybiscuit.cscorelib2.recipes.RecipeSnapshot;
import io.github.thebusybiscuit.cscorelib2.reflection.ReflectionUtils;
@ -27,8 +28,6 @@ import io.github.thebusybiscuit.slimefun4.implementation.geo.resources.OilResour
import io.github.thebusybiscuit.slimefun4.implementation.geo.resources.SaltResource;
import io.github.thebusybiscuit.slimefun4.implementation.geo.resources.UraniumResource;
import me.mrCookieSlime.CSCoreLibPlugin.CSCoreLib;
import me.mrCookieSlime.CSCoreLibPlugin.PluginUtils;
import me.mrCookieSlime.CSCoreLibPlugin.Configuration.Config;
import me.mrCookieSlime.Slimefun.GEO.OreGenSystem;
import me.mrCookieSlime.Slimefun.GPS.GPSNetwork;
import me.mrCookieSlime.Slimefun.Lists.SlimefunItems;
@ -37,7 +36,6 @@ import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.abstractItems.AContainer;
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.abstractItems.AGenerator;
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.abstractItems.AReactor;
import me.mrCookieSlime.Slimefun.Objects.tasks.ArmorTask;
import me.mrCookieSlime.Slimefun.Setup.Files;
import me.mrCookieSlime.Slimefun.Setup.MiscSetup;
import me.mrCookieSlime.Slimefun.Setup.ResearchSetup;
import me.mrCookieSlime.Slimefun.Setup.SlimefunSetup;
@ -69,7 +67,7 @@ import me.mrCookieSlime.Slimefun.listeners.TalismanListener;
import me.mrCookieSlime.Slimefun.listeners.TeleporterListener;
import me.mrCookieSlime.Slimefun.listeners.ToolListener;
import me.mrCookieSlime.Slimefun.listeners.WorldListener;
import me.mrCookieSlime.Slimefun.utils.Settings;
import me.mrCookieSlime.Slimefun.utils.ConfigCache;
import me.mrCookieSlime.Slimefun.utils.Utilities;
public final class SlimefunPlugin extends JavaPlugin {
@ -95,7 +93,7 @@ public final class SlimefunPlugin extends JavaPlugin {
private GPSNetwork gps;
private ProtectionManager protections;
private Utilities utilities;
private Settings settings;
private ConfigCache settings;
private SlimefunHooks hooks;
// Supported Versions of Minecraft
@ -143,22 +141,24 @@ public final class SlimefunPlugin extends JavaPlugin {
}
instance = this;
// Creating all necessary Folders
getLogger().log(Level.INFO, "Loading Files...");
Files files = new Files();
files.cleanup();
String[] storage = {"Players", "blocks", "stored-blocks", "stored-inventories", "stored-chunks", "universal-inventories", "waypoints", "block-backups"};
String[] general = {"scripts", "generators", "error-reports", "cache/github"};
for (String file : storage) createDir("data-storage/Slimefun/" + file);
for (String file : general) createDir("plugins/Slimefun/" + file);
getLogger().log(Level.INFO, "Loading Config...");
// Setup config.yml
PluginUtils utils = new PluginUtils(this);
utils.setupConfig();
config = utils.getConfig();
settings = new Settings(config);
config = new Config(this);
settings = new ConfigCache(config);
// Loading all extra configs
researches = new Config(files.researches);
items = new Config(files.items);
whitelist = new Config(files.whitelist);
researches = new Config(this, "Researches.yml");
items = new Config(this, "Items.yml");
whitelist = new Config(this, "whitelist.yml");
// Setup messages.yml
local = new LocalizationService(this);
@ -175,12 +175,6 @@ public final class SlimefunPlugin extends JavaPlugin {
updaterService.start();
}
// Creating all necessary Folders
String[] storage = {"blocks", "stored-blocks", "stored-inventories", "stored-chunks", "universal-inventories", "waypoints", "block-backups"};
String[] general = {"scripts", "generators", "error-reports", "cache/github"};
for (String s : storage) createDir("data-storage/Slimefun/" + s);
for (String s : general) createDir("plugins/Slimefun/" + s);
getLogger().log(Level.INFO, "Loading Items...");
MiscSetup.setupItemSettings();
@ -369,7 +363,7 @@ public final class SlimefunPlugin extends JavaPlugin {
return instance.config;
}
public static Config getResearchCfg() {
public static io.github.thebusybiscuit.cscorelib2.config.Config getResearchCfg() {
return instance.researches;
}
@ -377,7 +371,7 @@ public final class SlimefunPlugin extends JavaPlugin {
return instance.items;
}
public static Config getWhitelist() {
public static io.github.thebusybiscuit.cscorelib2.config.Config getWhitelist() {
return instance.whitelist;
}
@ -393,7 +387,7 @@ public final class SlimefunPlugin extends JavaPlugin {
return instance.utilities;
}
public static Settings getSettings() {
public static ConfigCache getSettings() {
return instance.settings;
}

View File

@ -12,8 +12,8 @@ import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.plugin.Plugin;
import io.github.thebusybiscuit.cscorelib2.config.Config;
import io.github.thebusybiscuit.slimefun4.core.services.LocalizationService;
import me.mrCookieSlime.CSCoreLibPlugin.Configuration.Config;
import me.mrCookieSlime.Slimefun.SlimefunPlugin;
import me.mrCookieSlime.Slimefun.GPS.GPSNetwork;
import me.mrCookieSlime.Slimefun.Objects.Category;

View File

@ -15,6 +15,7 @@ import me.mrCookieSlime.Slimefun.api.BlockStorage;
import me.mrCookieSlime.Slimefun.api.network.Network;
import me.mrCookieSlime.Slimefun.api.network.NetworkComponent;
import me.mrCookieSlime.Slimefun.holograms.EnergyHologram;
import me.mrCookieSlime.Slimefun.holograms.SimpleHologram;
public class EnergyNet extends Network {
@ -117,7 +118,7 @@ public class EnergyNet extends Network {
public void tick(Block b) {
if (!regulator.equals(b.getLocation())) {
EnergyHologram.update(b, "&4Multiple Energy Regulators connected");
SimpleHologram.update(b, "&4Multiple Energy Regulators connected");
return;
}
super.tick();
@ -125,7 +126,7 @@ public class EnergyNet extends Network {
double demand = 0.0D;
if (connectorNodes.isEmpty() && terminusNodes.isEmpty()) {
EnergyHologram.update(b, "&4No Energy Network found");
SimpleHologram.update(b, "&4No Energy Network found");
}
else {
Set<Location> exploded = new HashSet<>();

View File

@ -1,46 +1,15 @@
package me.mrCookieSlime.Slimefun.holograms;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Location;
import org.bukkit.block.Block;
import org.bukkit.entity.ArmorStand;
import org.bukkit.entity.Entity;
import io.github.thebusybiscuit.cscorelib2.math.DoubleHandler;
import me.mrCookieSlime.Slimefun.SlimefunPlugin;
public final class EnergyHologram {
private EnergyHologram() {}
public static void update(Block b, double supply, double demand) {
update(b, demand > supply ? ("&4&l- &c" + DoubleHandler.getFancyDouble(Math.abs(supply - demand)) + " &7J &e\u26A1"): ("&2&l+ &a" + DoubleHandler.getFancyDouble(supply - demand) + " &7J &e\u26A1"));
}
public static void update(final Block b, final String name) {
Bukkit.getScheduler().scheduleSyncDelayedTask(SlimefunPlugin.instance, () -> {
ArmorStand hologram = getArmorStand(b, true);
hologram.setCustomName(ChatColor.translateAlternateColorCodes('&', name));
});
}
public static void remove(final Block b) {
Bukkit.getScheduler().scheduleSyncDelayedTask(SlimefunPlugin.instance, () -> {
ArmorStand hologram = getArmorStand(b, false);
if (hologram != null) hologram.remove();
});
}
private static ArmorStand getArmorStand(Block b, boolean createIfNoneExists) {
Location l = new Location(b.getWorld(), b.getX() + 0.5, b.getY() + 0.7F, b.getZ() + 0.5);
for (Entity n : l.getChunk().getEntities()) {
if (n instanceof ArmorStand && n.getCustomName() != null && l.distanceSquared(n.getLocation()) < 0.4D) return (ArmorStand) n;
}
if (!createIfNoneExists) return null;
else return SimpleHologram.create(l);
SimpleHologram.update(b, demand > supply ? ("&4&l- &c" + DoubleHandler.getFancyDouble(Math.abs(supply - demand)) + " &7J &e\u26A1"): ("&2&l+ &a" + DoubleHandler.getFancyDouble(supply - demand) + " &7J &e\u26A1"));
}
}

View File

@ -26,7 +26,9 @@ public final class HologramProjectorHologram {
Location l = new Location(projector.getWorld(), projector.getX() + 0.5, projector.getY() + offset, projector.getZ() + 0.5);
for (Entity n : l.getChunk().getEntities()) {
if (n instanceof ArmorStand && n.getCustomName() != null && n.getCustomName().equals(nametag) && l.distanceSquared(n.getLocation()) < 0.4D) return (ArmorStand) n;
if (n instanceof ArmorStand && n.getCustomName() != null && n.getCustomName().equals(nametag) && l.distanceSquared(n.getLocation()) < 0.4D) {
return (ArmorStand) n;
}
}
if (!createIfNoneExists) {

View File

@ -1,12 +1,11 @@
package me.mrCookieSlime.Slimefun.holograms;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Location;
import org.bukkit.entity.ArmorStand;
import org.bukkit.entity.Entity;
import me.mrCookieSlime.Slimefun.SlimefunPlugin;
import me.mrCookieSlime.Slimefun.api.Slimefun;
public final class ReactorHologram {
@ -16,7 +15,9 @@ public final class ReactorHologram {
Location l = new Location(reactor.getWorld(), reactor.getX() + 0.5, reactor.getY() + 0.7, reactor.getZ() + 0.5);
for (Entity n : l.getChunk().getEntities()) {
if (n instanceof ArmorStand && l.distanceSquared(n.getLocation()) < 0.4D) return (ArmorStand) n;
if (n instanceof ArmorStand && l.distanceSquared(n.getLocation()) < 0.4D) {
return (ArmorStand) n;
}
}
if (!createIfNoneExists) return null;
@ -27,18 +28,11 @@ public final class ReactorHologram {
return hologram;
}
public static void update(final Location l, final String name) {
Bukkit.getScheduler().scheduleSyncDelayedTask(SlimefunPlugin.instance, () -> {
public static void update(Location l, String name) {
Slimefun.runSync(() -> {
ArmorStand hologram = getArmorStand(l, true);
if (!hologram.isCustomNameVisible()) hologram.setCustomNameVisible(true);
hologram.setCustomName(ChatColor.translateAlternateColorCodes('&', name));
});
}
public static void remove(Location l) {
Bukkit.getScheduler().scheduleSyncDelayedTask(SlimefunPlugin.instance, () -> {
ArmorStand hologram = getArmorStand(l, false);
if (hologram != null) hologram.remove();
});
}
}

View File

@ -1,6 +1,5 @@
package me.mrCookieSlime.Slimefun.holograms;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Location;
import org.bukkit.block.Block;
@ -8,21 +7,21 @@ import org.bukkit.entity.ArmorStand;
import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType;
import me.mrCookieSlime.Slimefun.SlimefunPlugin;
import me.mrCookieSlime.Slimefun.api.Slimefun;
public final class SimpleHologram {
private SimpleHologram() {}
public static void update(final Block b, final String name) {
Bukkit.getScheduler().scheduleSyncDelayedTask(SlimefunPlugin.instance, () -> {
public static void update(Block b, String name) {
Slimefun.runSync(() -> {
ArmorStand hologram = getArmorStand(b, true);
hologram.setCustomName(ChatColor.translateAlternateColorCodes('&', name));
});
}
public static void remove(final Block b) {
Bukkit.getScheduler().scheduleSyncDelayedTask(SlimefunPlugin.instance, () -> {
public static void remove(Block b) {
Slimefun.runSync(() -> {
ArmorStand hologram = getArmorStand(b, false);
if (hologram != null) hologram.remove();
});
@ -32,7 +31,9 @@ public final class SimpleHologram {
Location l = new Location(b.getWorld(), b.getX() + 0.5, b.getY() + 0.7F, b.getZ() + 0.5);
for (Entity n : l.getChunk().getEntities()) {
if (n instanceof ArmorStand && n.getCustomName() != null && l.distanceSquared(n.getLocation()) < 0.4D) return (ArmorStand) n;
if (n instanceof ArmorStand && n.getCustomName() != null && l.distanceSquared(n.getLocation()) < 0.4D) {
return (ArmorStand) n;
}
}
if (!createIfNoneExists) return null;

View File

@ -2,9 +2,9 @@ package me.mrCookieSlime.Slimefun.utils;
import java.util.List;
import me.mrCookieSlime.CSCoreLibPlugin.Configuration.Config;
import io.github.thebusybiscuit.cscorelib2.config.Config;
public final class Settings {
public final class ConfigCache {
public final boolean printOutLoading;
@ -25,7 +25,7 @@ public final class Settings {
public int smelteryFireBreakChance;
public Settings(Config cfg) {
public ConfigCache(Config cfg) {
printOutLoading = cfg.getBoolean("options.print-out-loading");
researchesFreeInCreative = cfg.getBoolean("options.allow-free-creative-research");