From 5317c46b2fbaf6cf2caf381de8bed201ba9efb02 Mon Sep 17 00:00:00 2001 From: TheBusyBiscuit Date: Sat, 8 Feb 2020 02:36:57 +0100 Subject: [PATCH] [CI skip] "a shit ton" may be an understatement --- .../slimefun4/api/SlimefunAPI.java | 107 -------------- .../slimefun4/api/geo/GEOResource.java | 41 ++++-- .../slimefun4/api/geo/ResourceManager.java | 111 ++++++++++++++ .../slimefun4/api/gps}/GPSNetwork.java | 24 ++-- .../api/gps/TeleportationManager.java} | 6 +- .../slimefun4/core/SlimefunRegistry.java | 20 +-- .../core/guide/ChestSlimefunGuide.java | 2 +- .../slimefun4/core/guide/GuideSettings.java | 3 +- .../core/services/LocalizationService.java | 34 +++-- .../core/services/localization/Language.java | 18 +++ .../localization/SlimefunLocalization.java | 19 +++ .../localization/SupportedLanguage.java | 2 +- .../services/localization/Translators.java | 3 + .../geo/resources/NetherIceResource.java | 36 ----- .../geo/resources/SaltResource.java | 76 ---------- .../geo/resources/UraniumResource.java | 50 ------- .../resources/NetherIceResource.java | 46 ++++++ .../{geo => }/resources/OilResource.java | 65 +++++---- .../resources/SaltResource.java | 79 ++++++++++ .../resources/UraniumResource.java | 50 +++++++ ...mefunSetup.java => SlimefunItemSetup.java} | 6 +- .../Slimefun/GEO/GEOScanner.java | 58 -------- .../Slimefun/GEO/OreGenResource.java | 35 ----- .../Slimefun/GEO/OreGenSystem.java | 126 ---------------- .../Slimefun/GPS/NetworkStatus.java | 8 -- .../Slimefun/Lists/Categories.java | 48 ++++--- .../Slimefun/Objects/Category.java | 43 +++--- .../Slimefun/Objects/LockedCategory.java | 12 ++ .../Slimefun/Objects/SeasonalCategory.java | 5 +- .../items/PortableGEOScanner.java | 13 +- .../machines/electric/geo/GEOMiner.java | 23 +-- .../electric/geo/GEOScannerBlock.java | 4 +- .../machines/electric/geo/OilPump.java | 18 ++- .../machines/electric/gps/GPSTransmitter.java | 8 +- .../Slimefun/SlimefunPlugin.java | 23 ++- .../Slimefun/api/BlockStorage.java | 136 ++++-------------- .../mrCookieSlime/Slimefun/api/Slimefun.java | 2 +- .../resources/languages/categories_en.yml | 24 ++++ src/main/resources/languages/messages_ar.yml | 3 - src/main/resources/languages/messages_de.yml | 3 - src/main/resources/languages/messages_en.yml | 4 - src/main/resources/languages/messages_fr.yml | 3 - src/main/resources/languages/messages_hu.yml | 3 - src/main/resources/languages/messages_ru.yml | 3 - src/main/resources/languages/messages_sk.yml | 3 - src/main/resources/languages/messages_sv.yml | 3 - src/main/resources/languages/messages_vi.yml | 3 - .../resources/languages/messages_zh-CN.yml | 3 - .../resources/languages/messages_zh-TW.yml | 3 - src/main/resources/languages/resources_en.yml | 25 ++++ 50 files changed, 645 insertions(+), 798 deletions(-) delete mode 100644 src/main/java/io/github/thebusybiscuit/slimefun4/api/SlimefunAPI.java create mode 100644 src/main/java/io/github/thebusybiscuit/slimefun4/api/geo/ResourceManager.java rename src/main/java/{me/mrCookieSlime/Slimefun/GPS => io/github/thebusybiscuit/slimefun4/api/gps}/GPSNetwork.java (91%) rename src/main/java/{me/mrCookieSlime/Slimefun/GPS/GPSTeleportation.java => io/github/thebusybiscuit/slimefun4/api/gps/TeleportationManager.java} (97%) delete mode 100644 src/main/java/io/github/thebusybiscuit/slimefun4/implementation/geo/resources/NetherIceResource.java delete mode 100644 src/main/java/io/github/thebusybiscuit/slimefun4/implementation/geo/resources/SaltResource.java delete mode 100644 src/main/java/io/github/thebusybiscuit/slimefun4/implementation/geo/resources/UraniumResource.java create mode 100644 src/main/java/io/github/thebusybiscuit/slimefun4/implementation/resources/NetherIceResource.java rename src/main/java/io/github/thebusybiscuit/slimefun4/implementation/{geo => }/resources/OilResource.java (56%) create mode 100644 src/main/java/io/github/thebusybiscuit/slimefun4/implementation/resources/SaltResource.java create mode 100644 src/main/java/io/github/thebusybiscuit/slimefun4/implementation/resources/UraniumResource.java rename src/main/java/io/github/thebusybiscuit/slimefun4/implementation/setup/{SlimefunSetup.java => SlimefunItemSetup.java} (99%) delete mode 100644 src/main/java/me/mrCookieSlime/Slimefun/GEO/GEOScanner.java delete mode 100644 src/main/java/me/mrCookieSlime/Slimefun/GEO/OreGenResource.java delete mode 100644 src/main/java/me/mrCookieSlime/Slimefun/GEO/OreGenSystem.java delete mode 100644 src/main/java/me/mrCookieSlime/Slimefun/GPS/NetworkStatus.java create mode 100644 src/main/resources/languages/categories_en.yml create mode 100644 src/main/resources/languages/resources_en.yml diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/api/SlimefunAPI.java b/src/main/java/io/github/thebusybiscuit/slimefun4/api/SlimefunAPI.java deleted file mode 100644 index 3a106686d..000000000 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/api/SlimefunAPI.java +++ /dev/null @@ -1,107 +0,0 @@ -package io.github.thebusybiscuit.slimefun4.api; - -import java.util.Collection; -import java.util.Optional; -import java.util.Set; -import java.util.stream.Collectors; - -import org.bukkit.OfflinePlayer; -import org.bukkit.World; -import org.bukkit.block.Block; -import org.bukkit.entity.Player; -import org.bukkit.inventory.ItemStack; - -import io.github.thebusybiscuit.slimefun4.api.blocks.SlimefunBlock; -import io.github.thebusybiscuit.slimefun4.api.geo.GEOResource; -import io.github.thebusybiscuit.slimefun4.api.items.ItemRestriction; -import io.github.thebusybiscuit.slimefun4.core.SlimefunWorld; -import me.mrCookieSlime.Slimefun.GEO.OreGenResource; -import me.mrCookieSlime.Slimefun.Objects.Category; -import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem; -import me.mrCookieSlime.Slimefun.api.PlayerProfile; - -/** - * This class will hold the declarations of important API methods for Slimefun. - * Normally these methods will not be implemented in this interface, but some - * methods will have a default implementation for convenience. - * - * @author TheBusyBiscuit - * - */ -public interface SlimefunAPI { - - /** - * This method will register the given restriction. - * Calling this should directly influence the outcome of {@link SlimefunAPI#getItemRestrictions()}. - * - * @param restriction The restriction to register - */ - void addItemRestriction(ItemRestriction restriction); - - /** - * This method will return a {@link Set} of all instances of {@link ItemRestriction} that will directly - * affect the outcome of {@link SlimefunAPI#isAllowedToUse(Player, ItemStack, boolean)} - * - * @return The Set of all registered item restrictions - */ - Set getItemRestrictions(); - - /** - * This method will return whether a Player is allowed to use the given {@link ItemStack}. - * If warningMessages is set to true, the Player will be informed about the outcome of this method. - * - * Internally this method will loop through {@link SlimefunAPI#getItemRestrictions()} and perform - * checks using all available instances of {@link ItemRestriction}. - * - * Do NOT warn Players about a restriction if this method returns false. - * Warnings should be exclusively handled via {@link ItemRestriction#warnPlayer(PlayerProfile, Player, SlimefunItem, ItemStack)} - * - * @param p The Player to perform the check on - * @param item The Item to perform the check on - * @param sendWarnings Whether to warn the Player about not being able to use the given item - * @return Whether the Player is allowed to use the given item - */ - default boolean isAllowedToUse(Player p, ItemStack item, boolean sendWarnings) { - PlayerProfile profile = PlayerProfile.get(p); - SlimefunItem sfItem = SlimefunItem.getByItem(item); - - for (ItemRestriction restriction : getItemRestrictions()) { - if (!restriction.isAllowed(profile, p, sfItem, item)) { - if (sendWarnings) restriction.warnPlayer(profile, p, sfItem, item); - return false; - } - } - - return true; - } - - /** - * This method returns a {@link Set} of all registered instances of {@link Category}. - * - * @return A Set of all Categories - */ - Set getCategories(); - - /** - * This method returns A {@link Set} of all registered instances of {@link SlimefunItem}. - * Its default implementation generates a new Set based on all items found in the categories - * returned by {@link SlimefunAPI#getCategories()} - * - * @return A Set of all SlimefunItems - */ - default Set getItems() { - return getCategories().stream().flatMap(cat -> cat.getItems().stream()).collect(Collectors.toSet()); - } - - Optional getSlimefunItem(ItemStack item); - - Optional getBlock(Block b); - - SlimefunWorld getWorld(World world); - - PlayerProfile getPlayer(OfflinePlayer player); - - void registerGEOResource(GEOResource resource); - Collection getGEOResources(); - -} diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/api/geo/GEOResource.java b/src/main/java/io/github/thebusybiscuit/slimefun4/api/geo/GEOResource.java index 2bd9f2765..76f6e3b95 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/api/geo/GEOResource.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/api/geo/GEOResource.java @@ -1,20 +1,35 @@ package io.github.thebusybiscuit.slimefun4.api.geo; import org.bukkit.Chunk; +import org.bukkit.Keyed; +import org.bukkit.World.Environment; import org.bukkit.block.Biome; +import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; -public interface GEOResource { +import me.mrCookieSlime.Slimefun.SlimefunPlugin; + +public interface GEOResource extends Keyed { /** * Returns the default supply of this resource in that biome * + * @param environment The {@link Environment} this area is currently in (NORMAL / NETHER / THE_END) + * @param biome The {@link Biome} this area is currently in. + * * @return The default supply found in a {@link Chunk} with the given {@link Biome} */ - int getDefaultSupply(Biome biome); + int getDefaultSupply(Environment environment, Biome biome); /** - * Name/ID e.g. "Oil" + * Returns how much the value may deviate from the default supply (positive only). + * + * @return The deviation or spread of the supply + */ + int getMaxDeviation(); + + /** + * Returns the name of this resource (e.g. "Oil") * * @return The name of this Resource */ @@ -28,14 +43,6 @@ public interface GEOResource { */ ItemStack getItem(); - /** - * Measurement Unit e.g. "Bucket" / "Buckets". - * Use the amount parameter to determine whether to use singular or plural. - * - * @return The Measurement Unit for this resource, will be treated like a suffix. - */ - String getMeasurementUnit(int amount); - /** * Returns whether this Resource can be obtained using a GEO Miner. * This will automatically add it to the GEO - Miner. @@ -43,5 +50,17 @@ public interface GEOResource { * @return Whether you can get obtain this resource using a GEO Miner. */ boolean isObtainableFromGEOMiner(); + + /** + * Registers this GEO Resource + */ + default void register() { + SlimefunPlugin.getGPSNetwork().getResourceManager().register(this); + } + + default String getName(Player p) { + String name = SlimefunPlugin.getLocal().getResourceString(p, "resources." + getKey().getNamespace() + "." + getKey().getKey()); + return name == null ? getName(): name; + } } diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/api/geo/ResourceManager.java b/src/main/java/io/github/thebusybiscuit/slimefun4/api/geo/ResourceManager.java new file mode 100644 index 000000000..225233805 --- /dev/null +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/api/geo/ResourceManager.java @@ -0,0 +1,111 @@ +package io.github.thebusybiscuit.slimefun4.api.geo; + +import java.util.OptionalInt; +import java.util.concurrent.ThreadLocalRandom; + +import org.bukkit.World; +import org.bukkit.block.Block; +import org.bukkit.entity.Player; +import org.bukkit.inventory.ItemStack; + +import io.github.thebusybiscuit.cscorelib2.config.Config; +import io.github.thebusybiscuit.cscorelib2.item.CustomItem; +import io.github.thebusybiscuit.cscorelib2.skull.SkullItem; +import io.github.thebusybiscuit.slimefun4.utils.ChestMenuUtils; +import me.mrCookieSlime.CSCoreLibPlugin.general.Inventory.ChestMenu; +import me.mrCookieSlime.Slimefun.SlimefunPlugin; +import me.mrCookieSlime.Slimefun.api.BlockStorage; + +public class ResourceManager { + + private final int[] backgroundSlots = {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 final ItemStack chunkTexture = SkullItem.fromBase64("eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvODQ0OWI5MzE4ZTMzMTU4ZTY0YTQ2YWIwZGUxMjFjM2Q0MDAwMGUzMzMyYzE1NzQ5MzJiM2M4NDlkOGZhMGRjMiJ9fX0="); + private final Config config = new Config("plugins/Slimefun/resources.yml"); + + public void register(GEOResource resource) { + boolean enabled = config.getOrSetDefault(resource.getKey().toString().replace(':', '.') + ".enabled", true); + + if (enabled) { + SlimefunPlugin.getRegistry().getGEOResources().add(resource); + } + + config.save(); + } + + public OptionalInt getSupplies(GEOResource resource, World world, int x, int z) { + String key = resource.getKey().toString().replace(':', '-'); + + String value = BlockStorage.getChunkInfo(world, x, z, key); + + if (value != null) { + return OptionalInt.of(Integer.parseInt(value)); + } + else { + return OptionalInt.empty(); + } + } + + public void setSupplies(GEOResource resource, World world, int x, int z, int value) { + String key = resource.getKey().toString().replace(':', '-'); + BlockStorage.setChunkInfo(world, x, z, key, String.valueOf(value)); + } + + private int generate(GEOResource resource, World world, int x, int z) { + Block block = world.getBlockAt(x << 4, 72, z << 4); + int value = resource.getDefaultSupply(world.getEnvironment(), block.getBiome()); + + if (value > 0) { + value += ThreadLocalRandom.current().nextInt(resource.getMaxDeviation()); + } + + setSupplies(resource, world, x, z, value); + return value; + } + + public void scan(Player p, Block block) { + if (SlimefunPlugin.getGPSNetwork().getNetworkComplexity(p.getUniqueId()) < 600) { + SlimefunPlugin.getLocal().sendMessages(p, "gps.insufficient-complexity", true, msg -> msg.replace("%complexity%", "600")); + return; + } + + int x = block.getX() >> 4; + int z = block.getZ() >> 4; + + ChestMenu menu = new ChestMenu("&4" + SlimefunPlugin.getLocal().getResourceString(p, "tooltips.results")); + + for (int slot : backgroundSlots) { + menu.addItem(slot, ChestMenuUtils.getBackground(), ChestMenuUtils.getEmptyClickHandler()); + } + + menu.addItem(4, new CustomItem(chunkTexture, + "&e" + SlimefunPlugin.getLocal().getResourceString(p, "tooltips.chunk"), + "", + "&8\u21E8 &7" + SlimefunPlugin.getLocal().getResourceString(p, "tooltips.world") + ": " + block.getWorld().getName(), + "&8\u21E8 &7X: " + x + " Z: " + z + ), ChestMenuUtils.getEmptyClickHandler()); + + int index = 10; + + for (GEOResource resource : SlimefunPlugin.getRegistry().getGEOResources().values()) { + OptionalInt optional = getSupplies(resource, block.getWorld(), x, z); + int supplies = optional.isPresent() ? optional.getAsInt() : generate(resource, block.getWorld(), x, z); + String suffix = SlimefunPlugin.getLocal().getResourceString(p, supplies == 1 ? "tooltips.unit" : "tooltips.units"); + + ItemStack item = new CustomItem(resource.getItem(), "&r" + resource.getName(p), "&8\u21E8 &e" + supplies + ' ' + suffix); + + if (supplies > 1) { + item.setAmount(supplies > item.getMaxStackSize() ? item.getMaxStackSize(): supplies); + } + + menu.addItem(index, item, ChestMenuUtils.getEmptyClickHandler()); + index++; + + if (index % 9 == 8) { + index += 2; + } + } + + menu.open(p); + } + +} diff --git a/src/main/java/me/mrCookieSlime/Slimefun/GPS/GPSNetwork.java b/src/main/java/io/github/thebusybiscuit/slimefun4/api/gps/GPSNetwork.java similarity index 91% rename from src/main/java/me/mrCookieSlime/Slimefun/GPS/GPSNetwork.java rename to src/main/java/io/github/thebusybiscuit/slimefun4/api/gps/GPSNetwork.java index 643ea5b68..7d199c5b2 100644 --- a/src/main/java/me/mrCookieSlime/Slimefun/GPS/GPSNetwork.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/api/gps/GPSNetwork.java @@ -1,4 +1,4 @@ -package me.mrCookieSlime.Slimefun.GPS; +package io.github.thebusybiscuit.slimefun4.api.gps; import java.util.HashMap; import java.util.HashSet; @@ -19,6 +19,7 @@ import io.github.thebusybiscuit.cscorelib2.config.Config; import io.github.thebusybiscuit.cscorelib2.item.CustomItem; import io.github.thebusybiscuit.cscorelib2.math.DoubleHandler; import io.github.thebusybiscuit.cscorelib2.skull.SkullItem; +import io.github.thebusybiscuit.slimefun4.api.geo.ResourceManager; import io.github.thebusybiscuit.slimefun4.utils.ChestMenuUtils; import me.mrCookieSlime.CSCoreLibPlugin.general.Inventory.ChestMenu; import me.mrCookieSlime.Slimefun.SlimefunPlugin; @@ -29,23 +30,24 @@ import me.mrCookieSlime.Slimefun.api.BlockStorage; public class GPSNetwork { - private static final String DIRECTORY = "data-storage/Slimefun/waypoints/"; + private static final String WAYPOINTS_DIRECTORY = "data-storage/Slimefun/waypoints/"; private final int[] border = {0, 1, 3, 5, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 26, 27, 35, 36, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53}; private final int[] inventory = {19, 20, 21, 22, 23, 24, 25, 28, 29, 30, 31, 32, 33, 34, 37, 38, 39, 40, 41, 42, 43}; private final Map> transmitters = new HashMap<>(); - private final GPSTeleportation teleportation = new GPSTeleportation(this); + private final TeleportationManager teleportation = new TeleportationManager(this); + private final ResourceManager resourceManager = new ResourceManager(); private final ItemStack deathpointIcon = SkullItem.fromBase64("eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvMWFlMzg1NWY5NTJjZDRhMDNjMTQ4YTk0NmUzZjgxMmE1OTU1YWQzNWNiY2I1MjYyN2VhNGFjZDQ3ZDMwODEifX19"); private final ItemStack netherIcon = SkullItem.fromBase64("eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvZDgzNTcxZmY1ODlmMWE1OWJiMDJiODA4MDBmYzczNjExNmUyN2MzZGNmOWVmZWJlZGU4Y2YxZmRkZSJ9fX0="); private final ItemStack endIcon = SkullItem.fromBase64("eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvYzZjYWM1OWIyYWFlNDg5YWEwNjg3YjVkODAyYjI1NTVlYjE0YTQwYmQ2MmIyMWViMTE2ZmE1NjljZGI3NTYifX19"); private final ItemStack worldIcon = SkullItem.fromBase64("eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvYzljODg4MWU0MjkxNWE5ZDI5YmI2MWExNmZiMjZkMDU5OTEzMjA0ZDI2NWRmNWI0MzliM2Q3OTJhY2Q1NiJ9fX0="); - public void updateTransmitter(Location l, UUID uuid, NetworkStatus status) { + public void updateTransmitter(Location l, UUID uuid, boolean online) { Set set = transmitters.getOrDefault(uuid, new HashSet<>()); - if (status == NetworkStatus.ONLINE) { + if (online) { if (set.add(l)) { transmitters.put(uuid, set); } @@ -164,7 +166,7 @@ public class GPSNetwork { menu.addItem(slot, new CustomItem(globe, entry.getKey(), "&8\u21E8 &7World: &r" + l.getWorld().getName(), "&8\u21E8 &7X: &r" + l.getX(), "&8\u21E8 &7Y: &r" + l.getY(), "&8\u21E8 &7Z: &r" + l.getZ(), "", "&8\u21E8 &cClick to delete")); menu.addMenuClickHandler(slot, (pl, slotn, item, action) -> { String id = ChatColor.stripColor(ChatColor.translateAlternateColorCodes('&', entry.getKey())).toUpperCase().replace(' ', '_'); - Config cfg = new Config(DIRECTORY + pl.getUniqueId().toString() + ".yml"); + Config cfg = new Config(WAYPOINTS_DIRECTORY + pl.getUniqueId().toString() + ".yml"); cfg.setValue(id, null); cfg.save(); pl.playSound(pl.getLocation(), Sound.UI_BUTTON_CLICK, 1F, 1F); @@ -181,7 +183,7 @@ public class GPSNetwork { public Map getWaypoints(UUID uuid) { Map map = new HashMap<>(); - Config cfg = new Config(DIRECTORY + uuid.toString() + ".yml"); + Config cfg = new Config(WAYPOINTS_DIRECTORY + uuid.toString() + ".yml"); for (String key : cfg.getKeys()) { if (cfg.contains(key + ".world") && Bukkit.getWorld(cfg.getString(key + ".world")) != null) { @@ -212,7 +214,7 @@ public class GPSNetwork { return; } - Config cfg = new Config(DIRECTORY + p.getUniqueId().toString() + ".yml"); + Config cfg = new Config(WAYPOINTS_DIRECTORY + p.getUniqueId().toString() + ".yml"); String id = ChatColor.stripColor(ChatColor.translateAlternateColorCodes('&', name)).toUpperCase().replace(' ', '_'); cfg.setValue(id, l); @@ -227,8 +229,12 @@ public class GPSNetwork { return transmitters.getOrDefault(uuid, new HashSet<>()); } - public GPSTeleportation getTeleleportationService() { + public TeleportationManager getTeleleportationService() { return teleportation; } + public ResourceManager getResourceManager() { + return resourceManager; + } + } diff --git a/src/main/java/me/mrCookieSlime/Slimefun/GPS/GPSTeleportation.java b/src/main/java/io/github/thebusybiscuit/slimefun4/api/gps/TeleportationManager.java similarity index 97% rename from src/main/java/me/mrCookieSlime/Slimefun/GPS/GPSTeleportation.java rename to src/main/java/io/github/thebusybiscuit/slimefun4/api/gps/TeleportationManager.java index f7a4d61e3..383b42d91 100644 --- a/src/main/java/me/mrCookieSlime/Slimefun/GPS/GPSTeleportation.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/api/gps/TeleportationManager.java @@ -1,4 +1,4 @@ -package me.mrCookieSlime.Slimefun.GPS; +package io.github.thebusybiscuit.slimefun4.api.gps; import java.util.HashSet; import java.util.Map; @@ -23,7 +23,7 @@ import me.mrCookieSlime.CSCoreLibPlugin.general.Inventory.ChestMenu; import me.mrCookieSlime.Slimefun.SlimefunPlugin; import me.mrCookieSlime.Slimefun.api.Slimefun; -public final class GPSTeleportation { +public final class TeleportationManager { private final Set teleporterUsers = new HashSet<>(); private final int[] teleporterBorder = {0, 1, 2, 3, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 26, 27, 35, 36, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53}; @@ -31,7 +31,7 @@ public final class GPSTeleportation { private final GPSNetwork network; - public GPSTeleportation(GPSNetwork gpsNetwork) { + public TeleportationManager(GPSNetwork gpsNetwork) { network = gpsNetwork; } diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/core/SlimefunRegistry.java b/src/main/java/io/github/thebusybiscuit/slimefun4/core/SlimefunRegistry.java index 3b3ac3865..3d1b37297 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/core/SlimefunRegistry.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/core/SlimefunRegistry.java @@ -15,13 +15,12 @@ import org.bukkit.entity.EntityType; import org.bukkit.inventory.ItemStack; import io.github.thebusybiscuit.cscorelib2.collections.KeyMap; -import io.github.thebusybiscuit.cscorelib2.config.Config; +import io.github.thebusybiscuit.slimefun4.api.geo.GEOResource; import io.github.thebusybiscuit.slimefun4.core.guide.BookSlimefunGuide; import io.github.thebusybiscuit.slimefun4.core.guide.ChestSlimefunGuide; import io.github.thebusybiscuit.slimefun4.core.guide.ISlimefunGuide; import io.github.thebusybiscuit.slimefun4.core.guide.SlimefunGuideLayout; import me.mrCookieSlime.Slimefun.SlimefunPlugin; -import me.mrCookieSlime.Slimefun.GEO.OreGenResource; import me.mrCookieSlime.Slimefun.Objects.Category; import me.mrCookieSlime.Slimefun.Objects.MultiBlock; import me.mrCookieSlime.Slimefun.Objects.Research; @@ -51,8 +50,7 @@ public class SlimefunRegistry { private final Set activeChunks = new HashSet<>(); private final Set researchingPlayers = new HashSet<>(); - private final Map geoResources = new HashMap<>(); - private final Map geoResourcesConfigs = new HashMap<>(); + private final KeyMap geoResources = new KeyMap<>(); private final Set energyGenerators = new HashSet<>(); private final Set energyCapacitors = new HashSet<>(); @@ -188,12 +186,18 @@ public class SlimefunRegistry { return activeTickers; } - public Map getGEOResources() { + public KeyMap getGEOResources() { return geoResources; } - - public Map getGEOResourceConfigs() { - return geoResourcesConfigs; + + public GEOResource getGEOResource(String namespace, String key) { + for (GEOResource resource : geoResources.values()) { + if (resource.getKey().toString().equals(namespace + ":" + key)) { + return resource; + } + } + + return null; } @Deprecated diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/core/guide/ChestSlimefunGuide.java b/src/main/java/io/github/thebusybiscuit/slimefun4/core/guide/ChestSlimefunGuide.java index 97fb9a760..aeb9dbd32 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/core/guide/ChestSlimefunGuide.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/core/guide/ChestSlimefunGuide.java @@ -379,7 +379,7 @@ public class ChestSlimefunGuide implements ISlimefunGuide { RecipeChoice[] choices = SlimefunPlugin.getMinecraftRecipes().getRecipeInput(recipe); - if (choices[0] instanceof MaterialChoice) { + if (choices.length == 1 && choices[0] instanceof MaterialChoice) { recipeItems[4] = new ItemStack(((MaterialChoice) choices[0]).getChoices().get(0)); if (((MaterialChoice) choices[0]).getChoices().size() > 1) { diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/core/guide/GuideSettings.java b/src/main/java/io/github/thebusybiscuit/slimefun4/core/guide/GuideSettings.java index 2e605fabc..7542fe11f 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/core/guide/GuideSettings.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/core/guide/GuideSettings.java @@ -299,8 +299,7 @@ public final class GuideSettings { for (Language language : SlimefunPlugin.getLocal().getLanguages()) { menu.addItem(slot, new CustomItem(language.getItem(), ChatColor.GREEN + language.getName(p), - "&7" + SlimefunPlugin.getLocal().getMessage(p, "guide.languages.progress.messages") + ": &b" + SlimefunPlugin.getLocal().getProgress(language, Language::getMessages) + '%', - "&7" + SlimefunPlugin.getLocal().getMessage(p, "guide.languages.progress.researches") + ": &b" + SlimefunPlugin.getLocal().getProgress(language, Language::getResearches) + '%', + "&b" + SlimefunPlugin.getLocal().getProgress(language) + '%', "", "&7\u21E8 &e" + SlimefunPlugin.getLocal().getMessage(p, "guide.languages.select") ), (pl, i, item, action) -> { diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/LocalizationService.java b/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/LocalizationService.java index 0523d65c7..93a455e7e 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/LocalizationService.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/LocalizationService.java @@ -8,7 +8,6 @@ import java.util.Collection; import java.util.LinkedHashMap; import java.util.Map; import java.util.Optional; -import java.util.function.Function; import java.util.logging.Level; import org.bukkit.NamespacedKey; @@ -44,7 +43,7 @@ public class LocalizationService extends SlimefunLocalization { defaultLanguage.setMessages(getConfig().getConfiguration()); for (SupportedLanguage lang : SupportedLanguage.values()) { - addLanguage(lang.getId(), lang.getTexture()); + addLanguage(lang.getID(), lang.getTexture()); } String language = getConfig().getString(LANGUAGE_PATH); @@ -82,7 +81,7 @@ public class LocalizationService extends SlimefunLocalization { @Override public boolean hasLanguage(String language) { // Checks if our jar files contains any .yml file for this id - return containsResource("messages_" + language) || containsResource("researches_" + language); + return containsResource("messages_" + language) || containsResource("researches_" + language) || containsResource("resources_" + language); } private boolean containsResource(String file) { @@ -118,6 +117,11 @@ public class LocalizationService extends SlimefunLocalization { if (reset) { getConfig().clear(); } + + defaultLanguage.setResearches(streamConfigFile("researches_" + language + ".yml", null)); + defaultLanguage.setResources(streamConfigFile("resources_" + language + ".yml", null)); + defaultLanguage.setCategories(streamConfigFile("categories_" + language + ".yml", null)); + Slimefun.getLogger().log(Level.INFO, "Loaded language \"{0}\"", language); getConfig().setValue(LANGUAGE_PATH, language); @@ -139,23 +143,37 @@ public class LocalizationService extends SlimefunLocalization { if (hasLanguage(id)) { FileConfiguration messages = streamConfigFile("messages_" + id + ".yml", getConfig().getConfiguration()); FileConfiguration researches = streamConfigFile("researches_" + id + ".yml", null); + FileConfiguration resources = streamConfigFile("resources_" + id + ".yml", null); + FileConfiguration categories = streamConfigFile("categories_" + id + ".yml", null); Language language = new Language(id, hash); language.setMessages(messages); language.setResearches(researches); + language.setResources(resources); + language.setCategories(categories); languages.put(id, language); } } - public double getProgress(Language lang, Function method) { - double defaultKeys = getTotalKeys(method.apply(languages.get("en"))); + public double getProgress(Language lang) { + double defaultKeys = getTotalKeys(languages.get(SupportedLanguage.ENGLISH.getID())); if (defaultKeys == 0) return 0; - return DoubleHandler.fixDouble(100.0 * (getTotalKeys(method.apply(lang)) / defaultKeys)); + return DoubleHandler.fixDouble(100.0 * (getTotalKeys(lang) / defaultKeys)); } - private double getTotalKeys(FileConfiguration cfg) { - return cfg != null ? cfg.getKeys(true).size(): 0; + private double getTotalKeys(Language lang) { + return getKeys(lang.getMessages(), lang.getResearches(), lang.getResources(), lang.getCategories()); + } + + private double getKeys(FileConfiguration... files) { + int keys = 0; + + for (FileConfiguration cfg : files) { + keys += cfg != null ? cfg.getKeys(true).size() : 0; + } + + return keys; } private FileConfiguration streamConfigFile(String file, FileConfiguration defaults) { diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/localization/Language.java b/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/localization/Language.java index 3a146434e..046804607 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/localization/Language.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/localization/Language.java @@ -14,6 +14,8 @@ public final class Language { private FileConfiguration messages; private FileConfiguration researches; + private FileConfiguration resources; + private FileConfiguration categories; public Language(String id, String hash) { this.id = id; @@ -33,6 +35,14 @@ public final class Language { public FileConfiguration getResearches() { return researches; } + + public FileConfiguration getResources() { + return resources; + } + + public FileConfiguration getCategories() { + return categories; + } public void setMessages(FileConfiguration config) { this.messages = config; @@ -42,6 +52,14 @@ public final class Language { this.researches = config; } + public void setResources(FileConfiguration config) { + this.resources = config; + } + + public void setCategories(FileConfiguration config) { + this.categories = config; + } + public ItemStack getItem() { return item; } diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/localization/SlimefunLocalization.java b/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/localization/SlimefunLocalization.java index 8484d156f..13eab0ac8 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/localization/SlimefunLocalization.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/localization/SlimefunLocalization.java @@ -43,6 +43,25 @@ public abstract class SlimefunLocalization extends Localization implements Keyed return language.getResearches().getString(key.getNamespace() + "." + key.getKey()); } + public String getCategoryName(Player p, NamespacedKey key) { + Language language = getLanguage(p); + if (language.getCategories() == null) return null; + return language.getCategories().getString(key.getNamespace() + "." + key.getKey()); + } + + public String getResourceString(Player p, String key) { + Language language = getLanguage(p); + + String value = language.getResources() != null ? language.getResources().getString(key): null; + + if (value != null) { + return value; + } + else { + return getLanguage("en").getResources().getString(key); + } + } + @Override public void sendMessage(CommandSender sender, String key, boolean addPrefix) { String prefix = addPrefix ? getPrefix(): ""; diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/localization/SupportedLanguage.java b/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/localization/SupportedLanguage.java index a2ee64de9..97579feec 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/localization/SupportedLanguage.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/localization/SupportedLanguage.java @@ -39,7 +39,7 @@ public enum SupportedLanguage { this.textureHash = textureHash; } - public String getId() { + public String getID() { return id; } diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/localization/Translators.java b/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/localization/Translators.java index bc3d7378b..e69e9a795 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/localization/Translators.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/localization/Translators.java @@ -72,6 +72,9 @@ public class Translators { // Translators - Chinese (Taiwan) addTranslator("BrineYT", "zh-TW", true); addTranslator("mio9", "zh-TW", true); + + // Translators - Arabic + addTranslator("mohkamfer", "citBabY", "ar", false); } private void addTranslator(String name, String language, boolean lock) { diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/geo/resources/NetherIceResource.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/geo/resources/NetherIceResource.java deleted file mode 100644 index 5a8d44761..000000000 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/geo/resources/NetherIceResource.java +++ /dev/null @@ -1,36 +0,0 @@ -package io.github.thebusybiscuit.slimefun4.implementation.geo.resources; - -import org.bukkit.block.Biome; -import org.bukkit.inventory.ItemStack; - -import me.mrCookieSlime.Slimefun.GEO.OreGenResource; -import me.mrCookieSlime.Slimefun.Lists.SlimefunItems; - -public class NetherIceResource implements OreGenResource { - - @Override - public int getDefaultSupply(Biome biome) { - return biome == Biome.NETHER ? 32: 0; - } - - @Override - public String getName() { - return "Nether Ice"; - } - - @Override - public ItemStack getIcon() { - return SlimefunItems.NETHER_ICE.clone(); - } - - @Override - public String getMeasurementUnit() { - return "Block(s)"; - } - - @Override - public boolean isLiquid() { - return false; - } - -} diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/geo/resources/SaltResource.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/geo/resources/SaltResource.java deleted file mode 100644 index 87548a3f4..000000000 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/geo/resources/SaltResource.java +++ /dev/null @@ -1,76 +0,0 @@ -package io.github.thebusybiscuit.slimefun4.implementation.geo.resources; - -import java.util.Random; -import java.util.concurrent.ThreadLocalRandom; - -import org.bukkit.block.Biome; -import org.bukkit.inventory.ItemStack; - -import me.mrCookieSlime.Slimefun.GEO.OreGenResource; -import me.mrCookieSlime.Slimefun.Lists.SlimefunItems; - -public class SaltResource implements OreGenResource { - - @Override - public int getDefaultSupply(Biome biome) { - Random random = ThreadLocalRandom.current(); - - switch (biome) { - case SNOWY_BEACH: - case STONE_SHORE: - case BEACH: - case DESERT_LAKES: - case RIVER: - case ICE_SPIKES: - case FROZEN_RIVER: - return random.nextInt(40) + 3; - - case DEEP_OCEAN: - case OCEAN: - case COLD_OCEAN: - case DEEP_COLD_OCEAN: - case DEEP_FROZEN_OCEAN: - case DEEP_LUKEWARM_OCEAN: - case DEEP_WARM_OCEAN: - case FROZEN_OCEAN: - case LUKEWARM_OCEAN: - case WARM_OCEAN: - return random.nextInt(60) + 24; - - case SWAMP: - case SWAMP_HILLS: - return random.nextInt(20) + 4; - - case THE_END: - case END_BARRENS: - case END_MIDLANDS: - case SMALL_END_ISLANDS: - case NETHER: - return 0; - - default: - return random.nextInt(6) + 4; - } - } - - @Override - public String getName() { - return "Salt"; - } - - @Override - public ItemStack getIcon() { - return SlimefunItems.SALT.clone(); - } - - @Override - public String getMeasurementUnit() { - return "Crystal(s)"; - } - - @Override - public boolean isLiquid() { - return false; - } - -} diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/geo/resources/UraniumResource.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/geo/resources/UraniumResource.java deleted file mode 100644 index f80dcbe6c..000000000 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/geo/resources/UraniumResource.java +++ /dev/null @@ -1,50 +0,0 @@ -package io.github.thebusybiscuit.slimefun4.implementation.geo.resources; - -import java.util.Random; -import java.util.concurrent.ThreadLocalRandom; - -import org.bukkit.block.Biome; -import org.bukkit.inventory.ItemStack; - -import me.mrCookieSlime.Slimefun.GEO.OreGenResource; -import me.mrCookieSlime.Slimefun.Lists.SlimefunItems; - -public class UraniumResource implements OreGenResource { - - @Override - public int getDefaultSupply(Biome biome) { - Random random = ThreadLocalRandom.current(); - - switch (biome) { - case THE_END: - case END_BARRENS: - case END_MIDLANDS: - case SMALL_END_ISLANDS: - case NETHER: - return 0; - default: - return random.nextInt(5) + 1; - } - } - - @Override - public String getName() { - return "Small Chunks of Uranium"; - } - - @Override - public ItemStack getIcon() { - return SlimefunItems.SMALL_URANIUM.clone(); - } - - @Override - public String getMeasurementUnit() { - return "Piece(s)"; - } - - @Override - public boolean isLiquid() { - return false; - } - -} diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/resources/NetherIceResource.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/resources/NetherIceResource.java new file mode 100644 index 000000000..e46dd8289 --- /dev/null +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/resources/NetherIceResource.java @@ -0,0 +1,46 @@ +package io.github.thebusybiscuit.slimefun4.implementation.resources; + +import org.bukkit.NamespacedKey; +import org.bukkit.World.Environment; +import org.bukkit.block.Biome; +import org.bukkit.inventory.ItemStack; + +import io.github.thebusybiscuit.slimefun4.api.geo.GEOResource; +import me.mrCookieSlime.Slimefun.SlimefunPlugin; +import me.mrCookieSlime.Slimefun.Lists.SlimefunItems; + +public class NetherIceResource implements GEOResource { + + private final NamespacedKey key = new NamespacedKey(SlimefunPlugin.instance, "nether_ice"); + + @Override + public int getDefaultSupply(Environment environment, Biome biome) { + return environment == Environment.NETHER ? 32: 0; + } + + @Override + public NamespacedKey getKey() { + return key; + } + + @Override + public int getMaxDeviation() { + return 6; + } + + @Override + public String getName() { + return "Nether Ice"; + } + + @Override + public ItemStack getItem() { + return SlimefunItems.NETHER_ICE.clone(); + } + + @Override + public boolean isObtainableFromGEOMiner() { + return true; + } + +} diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/geo/resources/OilResource.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/resources/OilResource.java similarity index 56% rename from src/main/java/io/github/thebusybiscuit/slimefun4/implementation/geo/resources/OilResource.java rename to src/main/java/io/github/thebusybiscuit/slimefun4/implementation/resources/OilResource.java index 8a19505de..ed8a61519 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/geo/resources/OilResource.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/resources/OilResource.java @@ -1,50 +1,48 @@ -package io.github.thebusybiscuit.slimefun4.implementation.geo.resources; - -import java.util.Random; -import java.util.concurrent.ThreadLocalRandom; +package io.github.thebusybiscuit.slimefun4.implementation.resources; +import org.bukkit.NamespacedKey; +import org.bukkit.World.Environment; import org.bukkit.block.Biome; import org.bukkit.inventory.ItemStack; -import me.mrCookieSlime.Slimefun.GEO.OreGenResource; +import io.github.thebusybiscuit.slimefun4.api.geo.GEOResource; +import me.mrCookieSlime.Slimefun.SlimefunPlugin; import me.mrCookieSlime.Slimefun.Lists.SlimefunItems; -public class OilResource implements OreGenResource { +public class OilResource implements GEOResource { + + private final NamespacedKey key = new NamespacedKey(SlimefunPlugin.instance, "oil"); @Override - public int getDefaultSupply(Biome biome) { - Random random = ThreadLocalRandom.current(); + public int getDefaultSupply(Environment environment, Biome biome) { + + if (environment != Environment.NORMAL) { + return 0; + } switch (biome) { case SNOWY_BEACH: case STONE_SHORE: case BEACH: - return random.nextInt(6) + 2; + return 6; case DESERT: case DESERT_HILLS: case DESERT_LAKES: - return random.nextInt(40) + 19; + return 45; case MOUNTAINS: case GRAVELLY_MOUNTAINS: case MOUNTAIN_EDGE: case RIVER: - return random.nextInt(14) + 13; + return 17; case SNOWY_MOUNTAINS: case SNOWY_TUNDRA: case ICE_SPIKES: case FROZEN_OCEAN: case FROZEN_RIVER: - return random.nextInt(11) + 3; - - case THE_END: - case END_BARRENS: - case END_MIDLANDS: - case SMALL_END_ISLANDS: - case NETHER: - return 0; + return 14; case BADLANDS: case BADLANDS_PLATEAU: @@ -54,7 +52,7 @@ public class OilResource implements OreGenResource { case MODIFIED_WOODED_BADLANDS_PLATEAU: case MUSHROOM_FIELDS: case MUSHROOM_FIELD_SHORE: - return random.nextInt(24) + 14; + return 24; case DEEP_OCEAN: case OCEAN: @@ -65,16 +63,26 @@ public class OilResource implements OreGenResource { case DEEP_WARM_OCEAN: case LUKEWARM_OCEAN: case WARM_OCEAN: - return random.nextInt(62) + 24; + return 62; case SWAMP: case SWAMP_HILLS: - return random.nextInt(20) + 4; + return 20; default: - return random.nextInt(10) + 6; + return 10; } } + + @Override + public NamespacedKey getKey() { + return key; + } + + @Override + public int getMaxDeviation() { + return 8; + } @Override public String getName() { @@ -82,18 +90,13 @@ public class OilResource implements OreGenResource { } @Override - public ItemStack getIcon() { + public ItemStack getItem() { return SlimefunItems.BUCKET_OF_OIL.clone(); } @Override - public String getMeasurementUnit() { - return "Bucket(s)"; - } - - @Override - public boolean isLiquid() { - return true; + public boolean isObtainableFromGEOMiner() { + return false; } } diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/resources/SaltResource.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/resources/SaltResource.java new file mode 100644 index 000000000..58b4624d0 --- /dev/null +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/resources/SaltResource.java @@ -0,0 +1,79 @@ +package io.github.thebusybiscuit.slimefun4.implementation.resources; + +import org.bukkit.NamespacedKey; +import org.bukkit.World.Environment; +import org.bukkit.block.Biome; +import org.bukkit.inventory.ItemStack; + +import io.github.thebusybiscuit.slimefun4.api.geo.GEOResource; +import me.mrCookieSlime.Slimefun.SlimefunPlugin; +import me.mrCookieSlime.Slimefun.Lists.SlimefunItems; + +public class SaltResource implements GEOResource { + + private final NamespacedKey key = new NamespacedKey(SlimefunPlugin.instance, "salt"); + + @Override + public int getDefaultSupply(Environment environment, Biome biome) { + + if (environment != Environment.NORMAL) { + return 0; + } + + switch (biome) { + case SNOWY_BEACH: + case STONE_SHORE: + case BEACH: + case DESERT_LAKES: + case RIVER: + case ICE_SPIKES: + case FROZEN_RIVER: + return 40; + + case DEEP_OCEAN: + case OCEAN: + case COLD_OCEAN: + case DEEP_COLD_OCEAN: + case DEEP_FROZEN_OCEAN: + case DEEP_LUKEWARM_OCEAN: + case DEEP_WARM_OCEAN: + case FROZEN_OCEAN: + case LUKEWARM_OCEAN: + case WARM_OCEAN: + return 60; + + case SWAMP: + case SWAMP_HILLS: + return 20; + + default: + return 6; + } + } + + @Override + public int getMaxDeviation() { + return 18; + } + + @Override + public NamespacedKey getKey() { + return key; + } + + @Override + public String getName() { + return "Salt"; + } + + @Override + public ItemStack getItem() { + return SlimefunItems.SALT.clone(); + } + + @Override + public boolean isObtainableFromGEOMiner() { + return true; + } + +} diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/resources/UraniumResource.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/resources/UraniumResource.java new file mode 100644 index 000000000..c2b1a5ad6 --- /dev/null +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/resources/UraniumResource.java @@ -0,0 +1,50 @@ +package io.github.thebusybiscuit.slimefun4.implementation.resources; + +import org.bukkit.NamespacedKey; +import org.bukkit.World.Environment; +import org.bukkit.block.Biome; +import org.bukkit.inventory.ItemStack; + +import io.github.thebusybiscuit.slimefun4.api.geo.GEOResource; +import me.mrCookieSlime.Slimefun.SlimefunPlugin; +import me.mrCookieSlime.Slimefun.Lists.SlimefunItems; + +public class UraniumResource implements GEOResource { + + private final NamespacedKey key = new NamespacedKey(SlimefunPlugin.instance, "uranium"); + + @Override + public int getDefaultSupply(Environment envionment, Biome biome) { + if (envionment == Environment.NORMAL) { + return 5; + } + + return 0; + } + + @Override + public NamespacedKey getKey() { + return key; + } + + @Override + public int getMaxDeviation() { + return 2; + } + + @Override + public String getName() { + return "Small Chunks of Uranium"; + } + + @Override + public ItemStack getItem() { + return SlimefunItems.SMALL_URANIUM.clone(); + } + + @Override + public boolean isObtainableFromGEOMiner() { + return true; + } + +} diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/setup/SlimefunSetup.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/setup/SlimefunItemSetup.java similarity index 99% rename from src/main/java/io/github/thebusybiscuit/slimefun4/implementation/setup/SlimefunSetup.java rename to src/main/java/io/github/thebusybiscuit/slimefun4/implementation/setup/SlimefunItemSetup.java index 9d760cd40..71d4474c0 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/setup/SlimefunSetup.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/setup/SlimefunItemSetup.java @@ -177,11 +177,11 @@ import me.mrCookieSlime.Slimefun.api.BlockStorage; import me.mrCookieSlime.Slimefun.api.Slimefun; import me.mrCookieSlime.Slimefun.api.SlimefunItemStack; -public final class SlimefunSetup { +public final class SlimefunItemSetup { - private SlimefunSetup() {} + private SlimefunItemSetup() {} - public static void setupItems() { + public static void setup() { new SlimefunItem(Categories.WEAPONS, (SlimefunItemStack) SlimefunItems.GRANDMAS_WALKING_STICK, RecipeType.ENHANCED_CRAFTING_TABLE, new ItemStack[] {null, new ItemStack(Material.OAK_LOG), null, null, new ItemStack(Material.OAK_LOG), null, null, new ItemStack(Material.OAK_LOG), null}) .register(true); diff --git a/src/main/java/me/mrCookieSlime/Slimefun/GEO/GEOScanner.java b/src/main/java/me/mrCookieSlime/Slimefun/GEO/GEOScanner.java deleted file mode 100644 index 1cfa42b84..000000000 --- a/src/main/java/me/mrCookieSlime/Slimefun/GEO/GEOScanner.java +++ /dev/null @@ -1,58 +0,0 @@ -package me.mrCookieSlime.Slimefun.GEO; - -import org.bukkit.Chunk; -import org.bukkit.entity.Player; -import org.bukkit.inventory.ItemStack; - -import io.github.thebusybiscuit.cscorelib2.item.CustomItem; -import io.github.thebusybiscuit.cscorelib2.skull.SkullItem; -import io.github.thebusybiscuit.slimefun4.utils.ChestMenuUtils; -import me.mrCookieSlime.CSCoreLibPlugin.general.Inventory.ChestMenu; -import me.mrCookieSlime.Slimefun.SlimefunPlugin; - -public final class GEOScanner { - - 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() {} - - public static void scanChunk(Player p, Chunk chunk) { - if (SlimefunPlugin.getGPSNetwork().getNetworkComplexity(p.getUniqueId()) < 600) { - SlimefunPlugin.getLocal().sendMessages(p, "gps.insufficient-complexity", true, msg -> msg.replace("%complexity%", "600")); - return; - } - - ChestMenu menu = new ChestMenu("&4GEO-Scan Results"); - for (int slot : BACKGROUND_SLOTS) { - menu.addItem(slot, ChestMenuUtils.getBackground(), ChestMenuUtils.getEmptyClickHandler()); - } - - 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()) { - int supply = OreGenSystem.getSupplies(resource, chunk, true); - - ItemStack item = new CustomItem(resource.getItem(), "&r" + resource.getName(), "&8\u21E8 &e" + supply + ' ' + resource.getMeasurementUnit()); - - if (supply > 1) { - item.setAmount(supply > item.getMaxStackSize() ? item.getMaxStackSize(): supply); - } - - menu.addItem(index, item, ChestMenuUtils.getEmptyClickHandler()); - index++; - - if (index % 9 == 8) { - index += 2; - } - } - - menu.open(p); - } - -} diff --git a/src/main/java/me/mrCookieSlime/Slimefun/GEO/OreGenResource.java b/src/main/java/me/mrCookieSlime/Slimefun/GEO/OreGenResource.java deleted file mode 100644 index 2270e67ed..000000000 --- a/src/main/java/me/mrCookieSlime/Slimefun/GEO/OreGenResource.java +++ /dev/null @@ -1,35 +0,0 @@ -package me.mrCookieSlime.Slimefun.GEO; - -import org.bukkit.block.Biome; -import org.bukkit.inventory.ItemStack; - -public interface OreGenResource { - - /** - * Returns the default supply of this resource in that biome - */ - int getDefaultSupply(Biome biome); - - /** - * Name/ID e.g. "Oil" - */ - String getName(); - - @Deprecated - ItemStack getIcon(); - - default ItemStack getItem() { - return getIcon(); - } - - /** - * Measurement Unit e.g. "Buckets" - */ - String getMeasurementUnit(); - - /** - * Returns whether this Resource is considered a fluid - */ - boolean isLiquid(); - -} diff --git a/src/main/java/me/mrCookieSlime/Slimefun/GEO/OreGenSystem.java b/src/main/java/me/mrCookieSlime/Slimefun/GEO/OreGenSystem.java deleted file mode 100644 index 9199f512b..000000000 --- a/src/main/java/me/mrCookieSlime/Slimefun/GEO/OreGenSystem.java +++ /dev/null @@ -1,126 +0,0 @@ -package me.mrCookieSlime.Slimefun.GEO; - -import java.util.Collection; -import java.util.concurrent.ThreadLocalRandom; -import java.util.logging.Level; - -import org.bukkit.Chunk; -import org.bukkit.Location; -import org.bukkit.block.Biome; - -import io.github.thebusybiscuit.cscorelib2.config.Config; -import me.mrCookieSlime.Slimefun.SlimefunPlugin; -import me.mrCookieSlime.Slimefun.api.BlockStorage; -import me.mrCookieSlime.Slimefun.api.Slimefun; - -public final class OreGenSystem { - - private OreGenSystem() {} - - public static Collection listResources() { - return SlimefunPlugin.getRegistry().getGEOResources().values(); - } - - public static void registerResource(OreGenResource resource) { - Config cfg = new Config("plugins/Slimefun/generators/" + resource.getName() + ".yml"); - cfg.setDefaultValue("enabled", true); - - for (Biome biome : Biome.values()) { - cfg.setDefaultValue("spawn-rates." + biome.toString(), resource.getDefaultSupply(biome)); - } - - cfg.save(); - - if (cfg.getBoolean("enabled")) { - Slimefun.getLogger().log(Level.INFO, "Registering Ore Gen: " + resource.getName()); - - SlimefunPlugin.getRegistry().getGEOResources().put(resource.getName(), resource); - SlimefunPlugin.getRegistry().getGEOResourceConfigs().put(resource.getName(), cfg); - } - } - - public static OreGenResource getResource(String name) { - return SlimefunPlugin.getRegistry().getGEOResources().get(name); - } - - private static int getDefault(OreGenResource resource, Biome biome) { - if (resource == null) { - return 0; - } - else { - int supply = SlimefunPlugin.getRegistry().getGEOResourceConfigs().get(resource.getName()).getInt("spawn-rates." + biome.toString()); - return supply > 0 ? (supply + ThreadLocalRandom.current().nextInt(3)): 0; - } - } - - public static void setSupplies(OreGenResource resource, Chunk chunk, int amount) { - if (resource != null) { - BlockStorage.setChunkInfo(chunk, "resources_" + resource.getName().toUpperCase(), String.valueOf(amount)); - } - } - - public static void setSupplies(OreGenResource resource, Location l, int amount) { - if (resource != null) { - BlockStorage.setChunkInfo(l, "resources_" + resource.getName().toUpperCase(), String.valueOf(amount)); - } - } - - public static int generateSupplies(OreGenResource resource, Chunk chunk) { - if (resource == null) return 0; - - int supplies = getDefault(resource, chunk.getBlock(7, 60, 7).getBiome()); - BlockStorage.setChunkInfo(chunk, "resources_" + resource.getName().toUpperCase(), String.valueOf(supplies)); - return supplies; - } - - public static int generateSupplies(OreGenResource resource, Location l) { - if (resource == null) return 0; - - int supplies = getDefault(resource, l.getBlock().getBiome()); - BlockStorage.setChunkInfo(l, "resources_" + resource.getName().toUpperCase(), String.valueOf(supplies)); - return supplies; - } - - public static int getSupplies(OreGenResource resource, Chunk chunk, boolean generate) { - if (resource == null) return 0; - - String supply = BlockStorage.getChunkInfo(chunk, "resources_" + resource.getName().toUpperCase()); - - if (supply != null) { - return Integer.parseInt(supply); - } - else if (!generate) { - return 0; - } - else { - return generateSupplies(resource, chunk); - } - } - - public static int getSupplies(OreGenResource resource, Location l, boolean generate) { - if (resource == null) return 0; - - String supply = BlockStorage.getChunkInfo(l, "resources_" + resource.getName().toUpperCase()); - - if (supply != null) { - return Integer.parseInt(supply); - } - else if (!generate) { - return 0; - } - else { - return generateSupplies(resource, l); - } - } - - public static boolean wasResourceGenerated(OreGenResource resource, Chunk chunk) { - if (resource == null) return false; - return BlockStorage.hasChunkInfo(chunk, "resources_" + resource.getName().toUpperCase()); - } - - public static boolean wasResourceGenerated(OreGenResource resource, Location l) { - if (resource == null) return false; - return BlockStorage.hasChunkInfo(l, "resources_" + resource.getName().toUpperCase()); - } - -} diff --git a/src/main/java/me/mrCookieSlime/Slimefun/GPS/NetworkStatus.java b/src/main/java/me/mrCookieSlime/Slimefun/GPS/NetworkStatus.java deleted file mode 100644 index bdc9cba7c..000000000 --- a/src/main/java/me/mrCookieSlime/Slimefun/GPS/NetworkStatus.java +++ /dev/null @@ -1,8 +0,0 @@ -package me.mrCookieSlime.Slimefun.GPS; - -public enum NetworkStatus { - - ONLINE, - OFFLINE; - -} diff --git a/src/main/java/me/mrCookieSlime/Slimefun/Lists/Categories.java b/src/main/java/me/mrCookieSlime/Slimefun/Lists/Categories.java index 2144bd77a..c5ac350df 100644 --- a/src/main/java/me/mrCookieSlime/Slimefun/Lists/Categories.java +++ b/src/main/java/me/mrCookieSlime/Slimefun/Lists/Categories.java @@ -1,9 +1,11 @@ package me.mrCookieSlime.Slimefun.Lists; import org.bukkit.Material; +import org.bukkit.NamespacedKey; import io.github.thebusybiscuit.cscorelib2.item.CustomItem; import io.github.thebusybiscuit.slimefun4.utils.ChatUtils; +import me.mrCookieSlime.Slimefun.SlimefunPlugin; import me.mrCookieSlime.Slimefun.Objects.Category; import me.mrCookieSlime.Slimefun.Objects.LockedCategory; import me.mrCookieSlime.Slimefun.Objects.SeasonalCategory; @@ -19,30 +21,30 @@ public final class Categories { private Categories() {} - public static final Category WEAPONS = new Category(new CustomItem(SlimefunItems.BLADE_OF_VAMPIRES, "&7Weapons"), 1); - public static final Category TOOLS = new Category(new CustomItem(SlimefunItems.AUTO_SMELT_PICKAXE, "&7Tools"), 1); - public static final Category PORTABLE = new Category(new CustomItem(SlimefunItems.BACKPACK_MEDIUM, "&7Items"), 1); - public static final Category FOOD = new Category(new CustomItem(SlimefunItems.FORTUNE_COOKIE, "&7Food"), 2); - public static final Category MACHINES_1 = new Category(new CustomItem(Material.SMITHING_TABLE, "&7Basic Machines"), 1); - public static final LockedCategory ELECTRICITY = new LockedCategory(new CustomItem(SlimefunItems.NUCLEAR_REACTOR, "&bEnergy and Electricity"), 4, MACHINES_1); - public static final LockedCategory GPS = new LockedCategory(new CustomItem(SlimefunItems.GPS_TRANSMITTER, "&bGPS-based Machines"), 4, MACHINES_1); - public static final Category ARMOR = new Category(new CustomItem(SlimefunItems.DAMASCUS_STEEL_CHESTPLATE, "&7Armor"), 2); - public static final Category LUMPS_AND_MAGIC = new Category(new CustomItem(SlimefunItems.RUNE_ENDER, "&7Magical Items"), 2); - public static final Category MAGIC = new Category(new CustomItem(SlimefunItems.INFUSED_ELYTRA, "&7Magical Gadgets"), 3); - public static final Category MISC = new Category(new CustomItem(SlimefunItems.CAN, "&7Miscellaneous"), 2); - public static final Category TECH = new Category(new CustomItem(SlimefunItems.STEEL_JETPACK, "&7Technical Gadgets"), 3); - public static final Category RESOURCES = new Category(new CustomItem(SlimefunItems.SYNTHETIC_SAPPHIRE, "&7Resources"), 1); - public static final Category CARGO = new LockedCategory(new CustomItem(SlimefunItems.CARGO_MANAGER, "&cCargo Management"), 4, MACHINES_1); - public static final Category TECH_MISC = new Category(new CustomItem(SlimefunItems.HEATING_COIL, "&7Technical Components"), 2); - public static final Category MAGIC_ARMOR = new Category(new CustomItem(SlimefunItems.ENDER_HELMET, "&7Magical Armor"), 2); - public static final Category TALISMANS_1 = new Category(new CustomItem(SlimefunItems.TALISMAN, "&7Talismans - &aTier I"), 2); - public static final LockedCategory TALISMANS_2 = new LockedCategory(new CustomItem(SlimefunItems.ENDER_TALISMAN, "&7Talismans - &aTier II"), 3, TALISMANS_1); + public static final Category WEAPONS = new Category(new NamespacedKey(SlimefunPlugin.instance, "weapons"), new CustomItem(SlimefunItems.BLADE_OF_VAMPIRES, "&7Weapons"), 1); + public static final Category TOOLS = new Category(new NamespacedKey(SlimefunPlugin.instance, "tools"), new CustomItem(SlimefunItems.AUTO_SMELT_PICKAXE, "&7Tools"), 1); + public static final Category PORTABLE = new Category(new NamespacedKey(SlimefunPlugin.instance, "items"), new CustomItem(SlimefunItems.BACKPACK_MEDIUM, "&7Useful Items"), 1); + public static final Category FOOD = new Category(new NamespacedKey(SlimefunPlugin.instance, "food"), new CustomItem(SlimefunItems.FORTUNE_COOKIE, "&7Food"), 2); + public static final Category MACHINES_1 = new Category(new NamespacedKey(SlimefunPlugin.instance, "basic_machines"), new CustomItem(Material.SMITHING_TABLE, "&7Basic Machines"), 1); + public static final LockedCategory ELECTRICITY = new LockedCategory(new NamespacedKey(SlimefunPlugin.instance, "electricity"), new CustomItem(SlimefunItems.NUCLEAR_REACTOR, "&bEnergy and Electricity"), 4, MACHINES_1); + public static final LockedCategory GPS = new LockedCategory(new NamespacedKey(SlimefunPlugin.instance, "gps"), new CustomItem(SlimefunItems.GPS_TRANSMITTER, "&bGPS-based Machines"), 4, MACHINES_1); + public static final Category ARMOR = new Category(new NamespacedKey(SlimefunPlugin.instance, "armor"), new CustomItem(SlimefunItems.DAMASCUS_STEEL_CHESTPLATE, "&7Armor"), 2); + public static final Category LUMPS_AND_MAGIC = new Category(new NamespacedKey(SlimefunPlugin.instance, "magical_items"), new CustomItem(SlimefunItems.RUNE_ENDER, "&7Magical Items"), 2); + public static final Category MAGIC = new Category(new NamespacedKey(SlimefunPlugin.instance, "magical_gadgets"), new CustomItem(SlimefunItems.INFUSED_ELYTRA, "&7Magical Gadgets"), 3); + public static final Category MISC = new Category(new NamespacedKey(SlimefunPlugin.instance, "misc"), new CustomItem(SlimefunItems.CAN, "&7Miscellaneous"), 2); + public static final Category TECH = new Category(new NamespacedKey(SlimefunPlugin.instance, "technical_gadgets"), new CustomItem(SlimefunItems.STEEL_JETPACK, "&7Technical Gadgets"), 3); + public static final Category RESOURCES = new Category(new NamespacedKey(SlimefunPlugin.instance, "resources"), new CustomItem(SlimefunItems.SYNTHETIC_SAPPHIRE, "&7Resources"), 1); + public static final Category CARGO = new LockedCategory(new NamespacedKey(SlimefunPlugin.instance, "cargo"), new CustomItem(SlimefunItems.CARGO_MANAGER, "&cCargo Management"), 4, MACHINES_1); + public static final Category TECH_MISC = new Category(new NamespacedKey(SlimefunPlugin.instance, "tech_misc"), new CustomItem(SlimefunItems.HEATING_COIL, "&7Technical Components"), 2); + public static final Category MAGIC_ARMOR = new Category(new NamespacedKey(SlimefunPlugin.instance, "magical_armor"), new CustomItem(SlimefunItems.ENDER_HELMET, "&7Magical Armor"), 2); + public static final Category TALISMANS_1 = new Category(new NamespacedKey(SlimefunPlugin.instance, "talismans"), new CustomItem(SlimefunItems.TALISMAN, "&7Talismans - &aTier I"), 2); + public static final LockedCategory TALISMANS_2 = new LockedCategory(new NamespacedKey(SlimefunPlugin.instance, "ender_talismans"), new CustomItem(SlimefunItems.ENDER_TALISMAN, "&7Talismans - &aTier II"), 3, TALISMANS_1); // Seasonal Categories - public static final SeasonalCategory CHRISTMAS = new SeasonalCategory(12, 1, new CustomItem(Material.NETHER_STAR, ChatUtils.christmas("Christmas") + " &7(December)")); - public static final SeasonalCategory VALENTINES_DAY = new SeasonalCategory(2, 2, new CustomItem(Material.POPPY, "&dValentine's Day" + " &7(14th February)")); - public static final SeasonalCategory EASTER = new SeasonalCategory(4, 2, new CustomItem(Material.EGG, "&6Easter" + " &7(April)")); - public static final SeasonalCategory BIRTHDAY = new SeasonalCategory(10, 1, new CustomItem(Material.FIREWORK_ROCKET, "&a&lTheBusyBiscuit's Birthday &7(26th October)")); - public static final SeasonalCategory HALLOWEEN = new SeasonalCategory(10, 1, new CustomItem(Material.JACK_O_LANTERN, "&6&lHalloween &7(31st October)")); + public static final SeasonalCategory CHRISTMAS = new SeasonalCategory(new NamespacedKey(SlimefunPlugin.instance, "christmas"), 12, 1, new CustomItem(Material.NETHER_STAR, ChatUtils.christmas("Christmas") + " &7(December only)")); + public static final SeasonalCategory VALENTINES_DAY = new SeasonalCategory(new NamespacedKey(SlimefunPlugin.instance, "valentines_day"), 2, 2, new CustomItem(Material.POPPY, "&dValentine's Day" + " &7(14th February)")); + public static final SeasonalCategory EASTER = new SeasonalCategory(new NamespacedKey(SlimefunPlugin.instance, "easter"), 4, 2, new CustomItem(Material.EGG, "&6Easter" + " &7(April)")); + public static final SeasonalCategory BIRTHDAY = new SeasonalCategory(new NamespacedKey(SlimefunPlugin.instance, "birthday"), 10, 1, new CustomItem(Material.FIREWORK_ROCKET, "&a&lTheBusyBiscuit's Birthday &7(26th October)")); + public static final SeasonalCategory HALLOWEEN = new SeasonalCategory(new NamespacedKey(SlimefunPlugin.instance, "halloween"), 10, 1, new CustomItem(Material.JACK_O_LANTERN, "&6&lHalloween &7(31st October)")); } diff --git a/src/main/java/me/mrCookieSlime/Slimefun/Objects/Category.java b/src/main/java/me/mrCookieSlime/Slimefun/Objects/Category.java index e543e623c..3826eadea 100644 --- a/src/main/java/me/mrCookieSlime/Slimefun/Objects/Category.java +++ b/src/main/java/me/mrCookieSlime/Slimefun/Objects/Category.java @@ -7,13 +7,14 @@ import java.util.Comparator; import java.util.List; import org.bukkit.ChatColor; +import org.bukkit.Keyed; +import org.bukkit.NamespacedKey; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemFlag; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.ItemMeta; import io.github.thebusybiscuit.cscorelib2.item.CustomItem; -import io.github.thebusybiscuit.slimefun4.core.SlimefunRegistry; import me.mrCookieSlime.Slimefun.SlimefunPlugin; import me.mrCookieSlime.Slimefun.Lists.Categories; import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem; @@ -29,8 +30,9 @@ import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem; * @see LockedCategory * @see SeasonalCategory */ -public class Category { +public class Category implements Keyed { + private final NamespacedKey key; private final ItemStack item; private final List items; private final int tier; @@ -40,12 +42,18 @@ public class Category { * The tier is set to a default value of {@code 3}. * * @param item the display item for this category + * @deprecated Use the alternative with a {@link NamespacedKey} instead * * @since 4.0 */ + @Deprecated public Category(ItemStack item) { this(item, 3); } + + public Category(NamespacedKey key, ItemStack item) { + this(key, item, 3); + } /** * Constructs a Category with the given display item and the provided tier. @@ -54,11 +62,18 @@ public class Category { * * @param item the display item for this category * @param tier the tier for this category + * @deprecated Use the alternative with a {@link NamespacedKey} instead * * @since 4.0 */ + @Deprecated public Category(ItemStack item, int tier) { + this(new NamespacedKey(SlimefunPlugin.instance, "invalid_category"), item, tier); + } + + public Category(NamespacedKey key, ItemStack item, int tier) { this.item = item; + this.key = key; ItemMeta meta = item.getItemMeta(); meta.addItemFlags(ItemFlag.HIDE_ATTRIBUTES); @@ -69,19 +84,9 @@ public class Category { this.tier = tier; } - /** - * Gets the list of the registered categories. - * - * @deprecated Use {@link SlimefunRegistry#getEnabledCategories()} - * - * @return the list of the registered categories - * - * @since 4.0 - * @see Categories - */ - @Deprecated - public static List list() { - return SlimefunPlugin.getRegistry().getEnabledCategories(); + @Override + public NamespacedKey getKey() { + return key; } /** @@ -120,7 +125,13 @@ public class Category { } public ItemStack getItem(Player p) { - return new CustomItem(item, meta -> meta.setLore(Arrays.asList("", ChatColor.GRAY + "\u21E8 " + ChatColor.GREEN + SlimefunPlugin.getLocal().getMessage(p, "guide.tooltips.open-category")))); + return new CustomItem(item, meta -> { + String name = SlimefunPlugin.getLocal().getCategoryName(p, getKey()); + if (name == null) name = item.getItemMeta().getDisplayName(); + + meta.setDisplayName(ChatColor.GREEN + name); + meta.setLore(Arrays.asList("", ChatColor.GRAY + "\u21E8 " + ChatColor.GREEN + SlimefunPlugin.getLocal().getMessage(p, "guide.tooltips.open-category"))); + }); } /** diff --git a/src/main/java/me/mrCookieSlime/Slimefun/Objects/LockedCategory.java b/src/main/java/me/mrCookieSlime/Slimefun/Objects/LockedCategory.java index 2dc3f8dc9..9e64dec0a 100644 --- a/src/main/java/me/mrCookieSlime/Slimefun/Objects/LockedCategory.java +++ b/src/main/java/me/mrCookieSlime/Slimefun/Objects/LockedCategory.java @@ -3,6 +3,7 @@ package me.mrCookieSlime.Slimefun.Objects; import java.util.Arrays; import java.util.List; +import org.bukkit.NamespacedKey; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; @@ -40,9 +41,14 @@ public class LockedCategory extends Category { * @since 4.0 * @see #LockedCategory(ItemStack, int, Category...) */ + @Deprecated public LockedCategory(ItemStack item, Category... parents) { this(item, 3, parents); } + + public LockedCategory(NamespacedKey key, ItemStack item, Category... parents) { + this(key, item, 3, parents); + } /** * The constructor for a LockedCategory. @@ -57,11 +63,17 @@ public class LockedCategory extends Category { * @since 4.0 * @see #LockedCategory(ItemStack, Category...) */ + @Deprecated public LockedCategory(ItemStack item, int tier, Category... parents) { super(item, tier); this.parents = Arrays.asList(parents); } + public LockedCategory(NamespacedKey key, ItemStack item, int tier, Category... parents) { + super(key, item, tier); + this.parents = Arrays.asList(parents); + } + /** * Gets the list of parent categories for this category. * diff --git a/src/main/java/me/mrCookieSlime/Slimefun/Objects/SeasonalCategory.java b/src/main/java/me/mrCookieSlime/Slimefun/Objects/SeasonalCategory.java index b3b7b6e82..5479e1735 100644 --- a/src/main/java/me/mrCookieSlime/Slimefun/Objects/SeasonalCategory.java +++ b/src/main/java/me/mrCookieSlime/Slimefun/Objects/SeasonalCategory.java @@ -2,6 +2,7 @@ package me.mrCookieSlime.Slimefun.Objects; import java.util.Calendar; +import org.bukkit.NamespacedKey; import org.bukkit.inventory.ItemStack; /** @@ -32,8 +33,8 @@ public class SeasonalCategory extends Category { * * @since 4.0 */ - public SeasonalCategory(int month, int tier, ItemStack item) { - super(item, tier); + public SeasonalCategory(NamespacedKey key, int month, int tier, ItemStack item) { + super(key, item, tier); if (month < 1 || month > 12) { throw new IllegalArgumentException("There is no month no. " + month); diff --git a/src/main/java/me/mrCookieSlime/Slimefun/Objects/SlimefunItem/items/PortableGEOScanner.java b/src/main/java/me/mrCookieSlime/Slimefun/Objects/SlimefunItem/items/PortableGEOScanner.java index 85b8a17fc..154658235 100644 --- a/src/main/java/me/mrCookieSlime/Slimefun/Objects/SlimefunItem/items/PortableGEOScanner.java +++ b/src/main/java/me/mrCookieSlime/Slimefun/Objects/SlimefunItem/items/PortableGEOScanner.java @@ -1,9 +1,11 @@ package me.mrCookieSlime.Slimefun.Objects.SlimefunItem.items; -import org.bukkit.entity.Player; +import java.util.Optional; + +import org.bukkit.block.Block; import org.bukkit.inventory.ItemStack; -import me.mrCookieSlime.Slimefun.GEO.GEOScanner; +import me.mrCookieSlime.Slimefun.SlimefunPlugin; import me.mrCookieSlime.Slimefun.Lists.RecipeType; import me.mrCookieSlime.Slimefun.Objects.Category; import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SimpleSlimefunItem; @@ -19,9 +21,12 @@ public class PortableGEOScanner extends SimpleSlimefunItem { @Override public ItemUseHandler getItemHandler() { return e -> { + Optional block = e.getClickedBlock(); e.cancel(); - Player p = e.getPlayer(); - GEOScanner.scanChunk(p, p.getLocation().getChunk()); + + if (block.isPresent()) { + SlimefunPlugin.getGPSNetwork().getResourceManager().scan(e.getPlayer(), block.get()); + } }; } diff --git a/src/main/java/me/mrCookieSlime/Slimefun/Objects/SlimefunItem/machines/electric/geo/GEOMiner.java b/src/main/java/me/mrCookieSlime/Slimefun/Objects/SlimefunItem/machines/electric/geo/GEOMiner.java index 827ee99bd..ff3dc4377 100644 --- a/src/main/java/me/mrCookieSlime/Slimefun/Objects/SlimefunItem/machines/electric/geo/GEOMiner.java +++ b/src/main/java/me/mrCookieSlime/Slimefun/Objects/SlimefunItem/machines/electric/geo/GEOMiner.java @@ -2,6 +2,7 @@ package me.mrCookieSlime.Slimefun.Objects.SlimefunItem.machines.electric.geo; import java.util.LinkedList; import java.util.List; +import java.util.OptionalInt; import org.bukkit.Material; import org.bukkit.block.Block; @@ -10,12 +11,12 @@ import org.bukkit.event.inventory.InventoryClickEvent; import org.bukkit.inventory.ItemStack; import io.github.thebusybiscuit.cscorelib2.item.CustomItem; +import io.github.thebusybiscuit.slimefun4.api.geo.GEOResource; import io.github.thebusybiscuit.slimefun4.utils.ChestMenuUtils; import io.github.thebusybiscuit.slimefun4.utils.holograms.SimpleHologram; import me.mrCookieSlime.CSCoreLibPlugin.general.Inventory.ChestMenu.AdvancedMenuClickHandler; import me.mrCookieSlime.CSCoreLibPlugin.general.Inventory.ClickAction; -import me.mrCookieSlime.Slimefun.GEO.OreGenResource; -import me.mrCookieSlime.Slimefun.GEO.OreGenSystem; +import me.mrCookieSlime.Slimefun.SlimefunPlugin; import me.mrCookieSlime.Slimefun.Lists.RecipeType; import me.mrCookieSlime.Slimefun.Objects.Category; import me.mrCookieSlime.Slimefun.Objects.SlimefunBlockHandler; @@ -110,8 +111,8 @@ public abstract class GEOMiner extends AContainer implements InventoryBlock, Rec public List getDisplayRecipes() { List displayRecipes = new LinkedList<>(); - for (OreGenResource resource : OreGenSystem.listResources()) { - if (!resource.isLiquid()) { + for (GEOResource resource : SlimefunPlugin.getRegistry().getGEOResources().values()) { + if (resource.isObtainableFromGEOMiner()) { displayRecipes.add(new CustomItem(resource.getItem(), "&r" + resource.getName())); } } @@ -175,18 +176,20 @@ public abstract class GEOMiner extends AContainer implements InventoryBlock, Rec processing.remove(b); } } - else if (!BlockStorage.hasChunkInfo(b.getChunk())) { + else if (!BlockStorage.hasChunkInfo(b.getWorld(), b.getX() >> 4, b.getZ() >> 4)) { SimpleHologram.update(b, "&4GEO-Scan required!"); } else { - for (OreGenResource resource : OreGenSystem.listResources()) { - if (!resource.isLiquid()) { - if (!OreGenSystem.wasResourceGenerated(resource, b.getLocation())) { + 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 = OreGenSystem.getSupplies(resource, b.getLocation(), false); + int supplies = optional.getAsInt(); if (supplies > 0) { MachineRecipe r = new MachineRecipe(getProcessingTime() / getSpeed(), new ItemStack[0], new ItemStack[] {resource.getItem().clone()}); @@ -194,7 +197,7 @@ public abstract class GEOMiner extends AContainer implements InventoryBlock, Rec processing.put(b, r); progress.put(b, r.getTicks()); - OreGenSystem.setSupplies(resource, b.getLocation(), supplies - 1); + SlimefunPlugin.getGPSNetwork().getResourceManager().setSupplies(resource, b.getWorld(), b.getX() >> 4, b.getZ() >> 4, supplies - 1); SimpleHologram.update(b, "&7Mining: &r" + resource.getName()); return; } diff --git a/src/main/java/me/mrCookieSlime/Slimefun/Objects/SlimefunItem/machines/electric/geo/GEOScannerBlock.java b/src/main/java/me/mrCookieSlime/Slimefun/Objects/SlimefunItem/machines/electric/geo/GEOScannerBlock.java index 381f73c26..d9c7ca723 100644 --- a/src/main/java/me/mrCookieSlime/Slimefun/Objects/SlimefunItem/machines/electric/geo/GEOScannerBlock.java +++ b/src/main/java/me/mrCookieSlime/Slimefun/Objects/SlimefunItem/machines/electric/geo/GEOScannerBlock.java @@ -3,7 +3,7 @@ package me.mrCookieSlime.Slimefun.Objects.SlimefunItem.machines.electric.geo; import org.bukkit.block.Block; import org.bukkit.inventory.ItemStack; -import me.mrCookieSlime.Slimefun.GEO.GEOScanner; +import me.mrCookieSlime.Slimefun.SlimefunPlugin; import me.mrCookieSlime.Slimefun.Lists.RecipeType; import me.mrCookieSlime.Slimefun.Objects.Category; import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SimpleSlimefunItem; @@ -27,7 +27,7 @@ public class GEOScannerBlock extends SimpleSlimefunItem { Block b = e.getClickedBlock().get(); e.cancel(); - GEOScanner.scanChunk(e.getPlayer(), b.getChunk()); + SlimefunPlugin.getGPSNetwork().getResourceManager().scan(e.getPlayer(), b); }; } } diff --git a/src/main/java/me/mrCookieSlime/Slimefun/Objects/SlimefunItem/machines/electric/geo/OilPump.java b/src/main/java/me/mrCookieSlime/Slimefun/Objects/SlimefunItem/machines/electric/geo/OilPump.java index 5a4b7fe91..ab622ff04 100644 --- a/src/main/java/me/mrCookieSlime/Slimefun/Objects/SlimefunItem/machines/electric/geo/OilPump.java +++ b/src/main/java/me/mrCookieSlime/Slimefun/Objects/SlimefunItem/machines/electric/geo/OilPump.java @@ -2,6 +2,7 @@ package me.mrCookieSlime.Slimefun.Objects.SlimefunItem.machines.electric.geo; import java.util.Arrays; import java.util.List; +import java.util.OptionalInt; import org.bukkit.Material; import org.bukkit.block.Block; @@ -10,10 +11,9 @@ import org.bukkit.inventory.ItemStack; import io.github.thebusybiscuit.cscorelib2.item.CustomItem; import io.github.thebusybiscuit.cscorelib2.protection.ProtectableAction; +import io.github.thebusybiscuit.slimefun4.api.geo.GEOResource; import io.github.thebusybiscuit.slimefun4.utils.ChestMenuUtils; import me.mrCookieSlime.Slimefun.SlimefunPlugin; -import me.mrCookieSlime.Slimefun.GEO.OreGenResource; -import me.mrCookieSlime.Slimefun.GEO.OreGenSystem; import me.mrCookieSlime.Slimefun.Lists.RecipeType; import me.mrCookieSlime.Slimefun.Lists.SlimefunItems; import me.mrCookieSlime.Slimefun.Objects.Category; @@ -29,10 +29,14 @@ import me.mrCookieSlime.Slimefun.api.inventory.BlockMenuPreset; import me.mrCookieSlime.Slimefun.api.item_transport.ItemTransportFlow; public abstract class OilPump extends AContainer implements RecipeDisplayItem { + + private final GEOResource oil; public OilPump(Category category, SlimefunItemStack item, RecipeType recipeType, ItemStack[] recipe) { super(category, item, recipeType, recipe); + oil = SlimefunPlugin.getRegistry().getGEOResource("slimefun", "oil"); + new BlockMenuPreset(getID(), getInventoryTitle()) { @Override @@ -46,10 +50,11 @@ public abstract class OilPump extends AContainer implements RecipeDisplayItem { return false; } - if (!OreGenSystem.wasResourceGenerated(OreGenSystem.getResource("Oil"), b.getLocation())) { + if (!SlimefunPlugin.getGPSNetwork().getResourceManager().getSupplies(oil, b.getWorld(), b.getX() >> 4, b.getZ() >> 4).isPresent()) { SlimefunPlugin.getLocal().sendMessage(p, "gps.geo.scan-required", true); return false; } + return true; } @@ -107,16 +112,15 @@ public abstract class OilPump extends AContainer implements RecipeDisplayItem { else if (inv.fits(SlimefunItems.BUCKET_OF_OIL, getOutputSlots())) { for (int slot : getInputSlots()) { if (SlimefunManager.isItemSimilar(inv.getItemInSlot(slot), new ItemStack(Material.BUCKET), true)) { - OreGenResource oil = OreGenSystem.getResource("Oil"); - int supplies = OreGenSystem.getSupplies(oil, b.getLocation(), false); + OptionalInt supplies = SlimefunPlugin.getGPSNetwork().getResourceManager().getSupplies(oil, b.getWorld(), b.getX() >> 4, b.getZ() >> 4); - if (supplies > 0) { + if (supplies.isPresent() && supplies.getAsInt() > 0) { MachineRecipe r = new MachineRecipe(26, new ItemStack[0], new ItemStack[] {SlimefunItems.BUCKET_OF_OIL}); inv.consumeItem(slot); processing.put(b, r); progress.put(b, r.getTicks()); - OreGenSystem.setSupplies(oil, b.getLocation(), supplies - 1); + SlimefunPlugin.getGPSNetwork().getResourceManager().setSupplies(oil, b.getWorld(), b.getX() >> 4, b.getZ() >> 4, supplies.getAsInt() - 1); } else { ItemStack item = inv.getItemInSlot(slot).clone(); diff --git a/src/main/java/me/mrCookieSlime/Slimefun/Objects/SlimefunItem/machines/electric/gps/GPSTransmitter.java b/src/main/java/me/mrCookieSlime/Slimefun/Objects/SlimefunItem/machines/electric/gps/GPSTransmitter.java index dbd26c1c2..1ac2e7374 100644 --- a/src/main/java/me/mrCookieSlime/Slimefun/Objects/SlimefunItem/machines/electric/gps/GPSTransmitter.java +++ b/src/main/java/me/mrCookieSlime/Slimefun/Objects/SlimefunItem/machines/electric/gps/GPSTransmitter.java @@ -8,7 +8,6 @@ import org.bukkit.inventory.ItemStack; import me.mrCookieSlime.CSCoreLibPlugin.Configuration.Config; import me.mrCookieSlime.Slimefun.SlimefunPlugin; -import me.mrCookieSlime.Slimefun.GPS.NetworkStatus; import me.mrCookieSlime.Slimefun.Lists.RecipeType; import me.mrCookieSlime.Slimefun.Objects.Category; import me.mrCookieSlime.Slimefun.Objects.SlimefunBlockHandler; @@ -34,7 +33,7 @@ public abstract class GPSTransmitter extends SimpleSlimefunItem { @Override public boolean onBreak(Player p, Block b, SlimefunItem item, UnregisterReason reason) { - SlimefunPlugin.getGPSNetwork().updateTransmitter(b.getLocation(), UUID.fromString(BlockStorage.getLocationInfo(b.getLocation(), "owner")), NetworkStatus.OFFLINE); + SlimefunPlugin.getGPSNetwork().updateTransmitter(b.getLocation(), UUID.fromString(BlockStorage.getLocationInfo(b.getLocation(), "owner")), false); return true; } }); @@ -50,13 +49,14 @@ public abstract class GPSTransmitter extends SimpleSlimefunItem { @Override public void tick(Block b, SlimefunItem item, Config data) { int charge = ChargableBlock.getCharge(b); + UUID owner = UUID.fromString(BlockStorage.getLocationInfo(b.getLocation(), "owner")); if (charge >= getEnergyConsumption()) { - SlimefunPlugin.getGPSNetwork().updateTransmitter(b.getLocation(), UUID.fromString(BlockStorage.getLocationInfo(b.getLocation(), "owner")), NetworkStatus.ONLINE); + SlimefunPlugin.getGPSNetwork().updateTransmitter(b.getLocation(), owner, true); ChargableBlock.setCharge(b.getLocation(), charge - getEnergyConsumption()); } else { - SlimefunPlugin.getGPSNetwork().updateTransmitter(b.getLocation(), UUID.fromString(BlockStorage.getLocationInfo(b.getLocation(), "owner")), NetworkStatus.OFFLINE); + SlimefunPlugin.getGPSNetwork().updateTransmitter(b.getLocation(), owner, false); } } diff --git a/src/main/java/me/mrCookieSlime/Slimefun/SlimefunPlugin.java b/src/main/java/me/mrCookieSlime/Slimefun/SlimefunPlugin.java index 07bc1e0a2..42520ce23 100644 --- a/src/main/java/me/mrCookieSlime/Slimefun/SlimefunPlugin.java +++ b/src/main/java/me/mrCookieSlime/Slimefun/SlimefunPlugin.java @@ -17,6 +17,7 @@ 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; +import io.github.thebusybiscuit.slimefun4.api.gps.GPSNetwork; import io.github.thebusybiscuit.slimefun4.api.network.NetworkManager; import io.github.thebusybiscuit.slimefun4.core.SlimefunRegistry; import io.github.thebusybiscuit.slimefun4.core.commands.SlimefunCommand; @@ -30,10 +31,6 @@ import io.github.thebusybiscuit.slimefun4.core.services.GitHubService; import io.github.thebusybiscuit.slimefun4.core.services.LocalizationService; import io.github.thebusybiscuit.slimefun4.core.services.MetricsService; import io.github.thebusybiscuit.slimefun4.core.services.UpdaterService; -import io.github.thebusybiscuit.slimefun4.implementation.geo.resources.NetherIceResource; -import io.github.thebusybiscuit.slimefun4.implementation.geo.resources.OilResource; -import io.github.thebusybiscuit.slimefun4.implementation.geo.resources.SaltResource; -import io.github.thebusybiscuit.slimefun4.implementation.geo.resources.UraniumResource; import io.github.thebusybiscuit.slimefun4.implementation.listeners.AncientAltarListener; import io.github.thebusybiscuit.slimefun4.implementation.listeners.AndroidKillingListener; import io.github.thebusybiscuit.slimefun4.implementation.listeners.AutonomousToolsListener; @@ -62,15 +59,17 @@ import io.github.thebusybiscuit.slimefun4.implementation.listeners.TalismanListe import io.github.thebusybiscuit.slimefun4.implementation.listeners.TeleporterListener; import io.github.thebusybiscuit.slimefun4.implementation.listeners.VanillaMachinesListener; import io.github.thebusybiscuit.slimefun4.implementation.listeners.WorldListener; +import io.github.thebusybiscuit.slimefun4.implementation.resources.NetherIceResource; +import io.github.thebusybiscuit.slimefun4.implementation.resources.OilResource; +import io.github.thebusybiscuit.slimefun4.implementation.resources.SaltResource; +import io.github.thebusybiscuit.slimefun4.implementation.resources.UraniumResource; import io.github.thebusybiscuit.slimefun4.implementation.setup.MiscSetup; import io.github.thebusybiscuit.slimefun4.implementation.setup.ResearchSetup; -import io.github.thebusybiscuit.slimefun4.implementation.setup.SlimefunSetup; +import io.github.thebusybiscuit.slimefun4.implementation.setup.SlimefunItemSetup; import io.github.thebusybiscuit.slimefun4.implementation.setup.WikiSetup; import io.github.thebusybiscuit.slimefun4.implementation.tasks.ArmorTask; import io.github.thebusybiscuit.slimefun4.implementation.tasks.TickerTask; import me.mrCookieSlime.CSCoreLibPlugin.CSCoreLib; -import me.mrCookieSlime.Slimefun.GEO.OreGenSystem; -import me.mrCookieSlime.Slimefun.GPS.GPSNetwork; import me.mrCookieSlime.Slimefun.Lists.SlimefunItems; import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem; import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.abstractItems.AContainer; @@ -171,7 +170,7 @@ public final class SlimefunPlugin extends JavaPlugin { MiscSetup.setupItemSettings(); try { - SlimefunSetup.setupItems(); + SlimefunItemSetup.setup(); } catch (Exception x) { getLogger().log(Level.SEVERE, "An Error occured while initializing SlimefunItems for Slimefun " + getVersion(), x); } @@ -188,10 +187,10 @@ public final class SlimefunPlugin extends JavaPlugin { getLogger().log(Level.INFO, "Loading World Generators..."); // Generating Oil as an OreGenResource (it iss a cool API) - OreGenSystem.registerResource(new OilResource()); - OreGenSystem.registerResource(new NetherIceResource()); - OreGenSystem.registerResource(new UraniumResource()); - OreGenSystem.registerResource(new SaltResource()); + new OilResource().register(); + new NetherIceResource().register(); + new UraniumResource().register(); + new SaltResource().register(); // Setting up GitHub Connectors... gitHubService.connect(config.getBoolean("options.print-out-github-data-retrieving")); diff --git a/src/main/java/me/mrCookieSlime/Slimefun/api/BlockStorage.java b/src/main/java/me/mrCookieSlime/Slimefun/api/BlockStorage.java index 7b282f841..e2bd96939 100644 --- a/src/main/java/me/mrCookieSlime/Slimefun/api/BlockStorage.java +++ b/src/main/java/me/mrCookieSlime/Slimefun/api/BlockStorage.java @@ -59,15 +59,19 @@ public class BlockStorage { private static String serializeLocation(Location l) { return l.getWorld().getName() + ';' + l.getBlockX() + ';' + l.getBlockY() + ';' + l.getBlockZ(); } - - private static String serializeChunk(Chunk chunk) { - return chunk.getWorld().getName() + ";Chunk;" + chunk.getX() + ';' + chunk.getZ(); - } - +// +// private static String serializeChunk(Chunk chunk) { +// return chunk.getWorld().getName() + ";Chunk;" + chunk.getX() + ';' + chunk.getZ(); +// } +// private static String locationToChunkString(Location l) { return l.getWorld().getName() + ";Chunk;" + (l.getBlockX() >> 4) + ';' + (l.getBlockZ() >> 4); } + private static String serializeChunk(World world, int x, int z) { + return world.getName() + ";Chunk;" + x + ";" + z; + } + private static Location deserializeLocation(String l) { try { String[] components = l.split(";"); @@ -141,7 +145,7 @@ public class BlockStorage { } } } catch (Exception x) { - Slimefun.getLogger().log(Level.WARNING, "Failed to load " + file.getName() + '(' + key + ") for Slimefun " + Slimefun.getVersion(), x); + Slimefun.getLogger().log(Level.WARNING, "Failed to load " + file.getName() + '(' + key + ") for Slimefun " + SlimefunPlugin.getVersion(), x); } } done++; @@ -170,7 +174,7 @@ public class BlockStorage { SlimefunPlugin.getRegistry().getChunks().put(key, new BlockInfoConfig(parseJSON(cfg.getString(key)))); } } catch (Exception x) { - Slimefun.getLogger().log(Level.WARNING, "Failed to load " + chunks.getName() + " in World " + world.getName() + '(' + key + ") for Slimefun " + Slimefun.getVersion(), x); + Slimefun.getLogger().log(Level.WARNING, "Failed to load " + chunks.getName() + " in World " + world.getName() + '(' + key + ") for Slimefun " + SlimefunPlugin.getVersion(), x); } } } @@ -261,7 +265,7 @@ public class BlockStorage { try { Files.move(tmpFile.toPath(), cfg.getFile().toPath(), StandardCopyOption.ATOMIC_MOVE); } catch (IOException x) { - Slimefun.getLogger().log(Level.SEVERE, "An Error occured while copying a temporary File for Slimefun " + Slimefun.getVersion(), x); + Slimefun.getLogger().log(Level.SEVERE, "An Error occured while copying a temporary File for Slimefun " + SlimefunPlugin.getVersion(), x); } } } @@ -325,16 +329,6 @@ public class BlockStorage { } } - @Deprecated - public static Config getBlockInfo(Block block) { - return getLocationInfo(block.getLocation()); - } - - @Deprecated - public static Config getBlockInfo(Location l) { - return getLocationInfo(l); - } - public static Config getLocationInfo(Location l) { BlockStorage storage = getStorage(l.getWorld()); Config cfg = storage.storage.get(l); @@ -366,7 +360,7 @@ public class BlockStorage { logger.log(Level.WARNING, ""); logger.log(Level.WARNING, "IGNORE THIS ERROR UNLESS IT IS SPAMMING"); logger.log(Level.WARNING, ""); - logger.log(Level.SEVERE, "An Error occured while parsing Block Info for Slimefun " + Slimefun.getVersion(), x); + logger.log(Level.SEVERE, "An Error occured while parsing Block Info for Slimefun " + SlimefunPlugin.getVersion(), x); return null; } } @@ -380,21 +374,6 @@ public class BlockStorage { return json.toString(); } - - private static String getJSONData(Chunk chunk) { - if (chunk == null) return null; - return SlimefunPlugin.getRegistry().getChunks().get(serializeChunk(chunk)).toJSON(); - } - - @Deprecated - public static String getBlockInfo(Block block, String key) { - return getLocationInfo(block.getLocation(), key); - } - - @Deprecated - public static String getBlockInfo(Location l, String key) { - return getLocationInfo(l, key); - } public static String getLocationInfo(Location l, String key) { return getLocationInfo(l).getString(key); @@ -509,20 +488,10 @@ public class BlockStorage { } } - @Deprecated - public static void moveBlockInfo(Block block, Block newBlock) { - moveBlockInfo(block.getLocation(), newBlock.getLocation()); - } - public static void moveBlockInfo(Location from, Location to) { SlimefunPlugin.getTicker().queueMove(from, to); } - @Deprecated - public static void _integrated_moveBlockInfo(Block block, Block newBlock) { - _integrated_moveLocationInfo(block.getLocation(), newBlock.getLocation()); - } - public static void _integrated_moveLocationInfo(Location from, Location to) { if (!hasBlockInfo(from)) return; BlockStorage storage = getStorage(from.getWorld()); @@ -622,27 +591,11 @@ public class BlockStorage { public static Set getTickingChunks() { return new HashSet<>(SlimefunPlugin.getRegistry().getActiveChunks()); } - - @Deprecated - public static Set getTickingBlocks(Chunk chunk) { - return getTickingBlocks(chunk.toString()); - } public static Set getTickingLocations(Chunk chunk) { return getTickingLocations(chunk.toString()); } - @Deprecated - public static Set getTickingBlocks(String chunk) { - Set ret = new HashSet<>(); - - for (Location l : getTickingLocations(chunk)) { - ret.add(l.getBlock()); - } - - return ret; - } - public static Set getTickingLocations(String chunk) { return new HashSet<>(SlimefunPlugin.getRegistry().getActiveTickers().get(chunk)); } @@ -711,36 +664,23 @@ public class BlockStorage { else return storage.loadInventory(l, BlockMenuPreset.getPreset(checkID(l))); } - public static Config getChunkInfo(Chunk chunk) { + public static Config getChunkInfo(World world, int x, int z) { try { - BlockInfoConfig cfg = SlimefunPlugin.getRegistry().getChunks().get(serializeChunk(chunk)); + BlockInfoConfig cfg = SlimefunPlugin.getRegistry().getChunks().get(serializeChunk(world, x, z)); return cfg == null ? new BlockInfoConfig() : cfg; - } catch (Exception x) { - Slimefun.getLogger().log(Level.SEVERE, "Failed to parse ChunkInfo for Chunk: " + (chunk == null ? "?": chunk.getX()) + ", " + (chunk == null ? "?": chunk.getZ()) + " (" + getJSONData(chunk) + ") for Slimefun " + Slimefun.getVersion(), x); - return new BlockInfoConfig(); - } - } - - public static Config getChunkInfo(Location l) { - try { - BlockInfoConfig cfg = SlimefunPlugin.getRegistry().getChunks().get(locationToChunkString(l)); - return cfg == null ? new BlockInfoConfig() : cfg; - } catch (Exception x) { - Slimefun.getLogger().log(Level.SEVERE, "Failed to parse ChunkInfo for Location: " + (l == null ? "?": l.getBlockX()) + ", " + (l == null ? "?": l.getBlockZ()) + " for Slimefun " + Slimefun.getVersion(), x); + } catch (Exception e) { + Slimefun.getLogger().log(Level.SEVERE, "Failed to parse ChunkInfo for Slimefun " + SlimefunPlugin.getVersion(), x); return new BlockInfoConfig(); } } - public static boolean hasChunkInfo(Chunk chunk) { - return SlimefunPlugin.getRegistry().getChunks().containsKey(serializeChunk(chunk)); - } - - public static void setChunkInfo(Chunk chunk, String key, String value) { - BlockInfoConfig cfg = SlimefunPlugin.getRegistry().getChunks().get(serializeChunk(chunk)); + public static void setChunkInfo(World world, int x, int z, String key, String value) { + String serializedChunk = serializeChunk(world, x, z); + BlockInfoConfig cfg = SlimefunPlugin.getRegistry().getChunks().get(serializedChunk); if (cfg == null) { cfg = new BlockInfoConfig(); - SlimefunPlugin.getRegistry().getChunks().put(serializeChunk(chunk), cfg); + SlimefunPlugin.getRegistry().getChunks().put(serializedChunk, cfg); } cfg.setValue(key, value); @@ -748,37 +688,13 @@ public class BlockStorage { chunkChanges++; } - public static void setChunkInfo(Location l, String key, String value) { - BlockInfoConfig cfg = SlimefunPlugin.getRegistry().getChunks().get(locationToChunkString(l)); - - if (cfg == null) { - cfg = new BlockInfoConfig(); - SlimefunPlugin.getRegistry().getChunks().put(locationToChunkString(l), cfg); - } - - cfg.setValue(key, value); - - chunkChanges++; + public static boolean hasChunkInfo(World world, int x, int z) { + String serializedChunk = serializeChunk(world, x, z); + return SlimefunPlugin.getRegistry().getChunks().containsKey(serializedChunk); } - public static String getChunkInfo(Chunk chunk, String key) { - return getChunkInfo(chunk).getString(key); - } - - public static String getChunkInfo(Location l, String key) { - return getChunkInfo(l).getString(key); - } - - public static boolean hasChunkInfo(Chunk chunk, String key) { - return getChunkInfo(chunk, key) != null; - } - - public static boolean hasChunkInfo(Location l, String key) { - return getChunkInfo(l, key) != null; - } - - public static void clearChunkInfo(Chunk chunk) { - SlimefunPlugin.getRegistry().getChunks().remove(serializeChunk(chunk)); + public static String getChunkInfo(World world, int x, int z, String key) { + return getChunkInfo(world, x, z).getString(key); } public static String getBlockInfoAsJson(Block block) { diff --git a/src/main/java/me/mrCookieSlime/Slimefun/api/Slimefun.java b/src/main/java/me/mrCookieSlime/Slimefun/api/Slimefun.java index 270fc79df..881849469 100644 --- a/src/main/java/me/mrCookieSlime/Slimefun/api/Slimefun.java +++ b/src/main/java/me/mrCookieSlime/Slimefun/api/Slimefun.java @@ -11,10 +11,10 @@ import org.bukkit.inventory.ItemStack; import org.bukkit.scheduler.BukkitTask; import io.github.thebusybiscuit.cscorelib2.config.Config; +import io.github.thebusybiscuit.slimefun4.api.gps.GPSNetwork; import io.github.thebusybiscuit.slimefun4.core.SlimefunRegistry; import io.github.thebusybiscuit.slimefun4.core.services.LocalizationService; import me.mrCookieSlime.Slimefun.SlimefunPlugin; -import me.mrCookieSlime.Slimefun.GPS.GPSNetwork; import me.mrCookieSlime.Slimefun.Objects.Research; import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.ItemState; import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem; diff --git a/src/main/resources/languages/categories_en.yml b/src/main/resources/languages/categories_en.yml new file mode 100644 index 000000000..5aca9b42a --- /dev/null +++ b/src/main/resources/languages/categories_en.yml @@ -0,0 +1,24 @@ +slimefun: + weapons: 'Weapons' + tools: 'Tools' + items: 'Useful Items' + food: 'Food' + basic_machines: 'Basic Machines' + electricity: 'Energy and Electricity' + gps: 'GPS-based Machines' + armor: 'Armor' + magical_items: 'Magical Items' + magical_gadgets: 'Magical Gadgets' + misc: 'Miscellaneous Items' + technical_gadgets: 'Technical Gadgets' + resources: 'Resources' + cargo: 'Cargo Management' + tech_misc: 'Technical Components' + magical_armor: 'Magical Armor' + talismans: 'Talismans (Tier I)' + ender_talismans: 'Ender Talismans (Tier II)' + christmas: 'Christmas (December)' + valentines_day: 'Valentine''s Day (14th February)' + easter: 'Easter (April)' + birthday: 'TheBusyBiscuit''s birthday (26th October)' + halloween: 'Halloween (31st October)' \ No newline at end of file diff --git a/src/main/resources/languages/messages_ar.yml b/src/main/resources/languages/messages_ar.yml index 9924ed252..c2a045ef1 100644 --- a/src/main/resources/languages/messages_ar.yml +++ b/src/main/resources/languages/messages_ar.yml @@ -31,9 +31,6 @@ guide: select: اضغط لإختيار هذه اللغة select-default: اضغط لتحديد اللغة الإفتراضية selected-language: 'الإختيار الحالي:' - progress: - messages: رسائل الشات - researches: أسماء الأبحاث title: main: كتيب سلايم فان settings: الإعدادات والمعلومات diff --git a/src/main/resources/languages/messages_de.yml b/src/main/resources/languages/messages_de.yml index 2049ae2bc..ace436745 100644 --- a/src/main/resources/languages/messages_de.yml +++ b/src/main/resources/languages/messages_de.yml @@ -99,9 +99,6 @@ guide: lore: Klicke um eine Übersetzung hinzuzufügen name: "&aFehlt etwas?" updated: "&aFolgende Sprache wurde ausgewählt: &b%lang%" - progress: - messages: Chatnachrichten - researches: Namen von Erforschungen pages: next: Nächste Seite previous: Vorherige Seite diff --git a/src/main/resources/languages/messages_en.yml b/src/main/resources/languages/messages_en.yml index 19d667c04..e7f0b5601 100644 --- a/src/main/resources/languages/messages_en.yml +++ b/src/main/resources/languages/messages_en.yml @@ -48,10 +48,6 @@ guide: translations: name: '&aIs something missing?' lore: 'Click to add your own translation' - - progress: - messages: 'Chat messages' - researches: 'Research names' title: main: 'Slimefun Guide' diff --git a/src/main/resources/languages/messages_fr.yml b/src/main/resources/languages/messages_fr.yml index 283d95502..bc686c61e 100644 --- a/src/main/resources/languages/messages_fr.yml +++ b/src/main/resources/languages/messages_fr.yml @@ -96,9 +96,6 @@ guide: lore: Cliquez pour ajouter votre propre traduction name: "&aIl manque quelque chose ?" updated: "&aVotre langue a été correctement définie sur : &b%lang%" - progress: - messages: Messages du chat - researches: Noms des Recherches pages: next: Page suivante previous: Page précédente diff --git a/src/main/resources/languages/messages_hu.yml b/src/main/resources/languages/messages_hu.yml index 2f916a3e2..612268920 100644 --- a/src/main/resources/languages/messages_hu.yml +++ b/src/main/resources/languages/messages_hu.yml @@ -93,9 +93,6 @@ guide: lore: Kattints a saját fordítás hozzáadásához name: "&aHiányzik valami?" updated: "&aA nyelvet sikeresen átállítottad erre: &b%lang%" - progress: - messages: Chat üzenetek - researches: Kutatási nevek pages: next: Következő oldal previous: Előző oldal diff --git a/src/main/resources/languages/messages_ru.yml b/src/main/resources/languages/messages_ru.yml index f0e92c04c..a0d0242b3 100644 --- a/src/main/resources/languages/messages_ru.yml +++ b/src/main/resources/languages/messages_ru.yml @@ -95,9 +95,6 @@ guide: lore: Нажмите, чтобы добавить свой перевод name: "&aЧего-то не хватает?" updated: "&aВаш язык успешно установлен на: &b%lang%" - progress: - messages: Сообщения чата - researches: Названия исследований pages: next: Следующая страница previous: Предыдущая страница diff --git a/src/main/resources/languages/messages_sk.yml b/src/main/resources/languages/messages_sk.yml index afd704dca..2c79f1d41 100644 --- a/src/main/resources/languages/messages_sk.yml +++ b/src/main/resources/languages/messages_sk.yml @@ -93,9 +93,6 @@ guide: lore: Klikni pre pridanie svojho prekladu name: "&aNiečo chýba?" updated: "&aTvoj jazyk bol úspešne nastavený na: &b%lang%" - progress: - messages: Správy v chate - researches: Názvy prieskumov pages: next: Ďalšia stránka previous: Predošlá stránka diff --git a/src/main/resources/languages/messages_sv.yml b/src/main/resources/languages/messages_sv.yml index 7668c9ec0..1907eb560 100644 --- a/src/main/resources/languages/messages_sv.yml +++ b/src/main/resources/languages/messages_sv.yml @@ -92,9 +92,6 @@ guide: lore: Klicka här för att lägga till din egen översättning name: "&aIs något som saknas?" updated: "&aDitt språk är nu inställt på: &b%lang%" - progress: - messages: Chat meddelanden - researches: Forska namn pages: next: Nästa sida previous: Förra sidan diff --git a/src/main/resources/languages/messages_vi.yml b/src/main/resources/languages/messages_vi.yml index ffbd7120d..9699cf76d 100644 --- a/src/main/resources/languages/messages_vi.yml +++ b/src/main/resources/languages/messages_vi.yml @@ -94,9 +94,6 @@ guide: lore: Nhấn vào đây để thêm bản dịch của riêng bạn name: "&aThiếu một cái gì đó?" updated: "&aNgôn ngữ của bạn đã được đặt thành công: &b%lang%" - progress: - messages: Tin nhắn trò chuyện - researches: Tên nghiên cứu pages: next: Trang tiếp theo previous: Trang trước diff --git a/src/main/resources/languages/messages_zh-CN.yml b/src/main/resources/languages/messages_zh-CN.yml index d58d4d479..447a4c1c7 100644 --- a/src/main/resources/languages/messages_zh-CN.yml +++ b/src/main/resources/languages/messages_zh-CN.yml @@ -92,9 +92,6 @@ guide: lore: 单击添加你自己的翻译 name: "&a少了些什么?" updated: "&a你的语言已设为: &b%lang%" - progress: - messages: 聊天消息 - researches: 研究名字 pages: next: 下一页 previous: 上一页 diff --git a/src/main/resources/languages/messages_zh-TW.yml b/src/main/resources/languages/messages_zh-TW.yml index abfe22be0..96fe6b169 100644 --- a/src/main/resources/languages/messages_zh-TW.yml +++ b/src/main/resources/languages/messages_zh-TW.yml @@ -92,9 +92,6 @@ guide: lore: 點擊增加您自己的翻譯 name: "&a缺少什麼嗎?" updated: "&a你的語言已改成: &b%lang%" - progress: - messages: 聊天欄訊息 - researches: 研究名稱 pages: next: 下一頁 previous: 上一頁 diff --git a/src/main/resources/languages/resources_en.yml b/src/main/resources/languages/resources_en.yml new file mode 100644 index 000000000..c92c438e3 --- /dev/null +++ b/src/main/resources/languages/resources_en.yml @@ -0,0 +1,25 @@ +tooltips: + results: 'GEO-Scan Results' + chunk: 'Scanned Chunk' + world: 'World' + unit: 'Unit' + units: 'Units' + +resources: + slimefun: + oil: 'Oil' + nether_ice: 'Nether Ice' + salt: 'Salt' + uranium: 'Uranium' + + slimefunorechunks: + iron_ore_chunk: 'Iron Ore Chunk' + gold_ore_chunk: 'Gold Ore Chunk' + copper_ore_chunk: 'Copper Ore Chunk' + tin_ore_chunk: 'Tin Ore Chunk' + silver_ore_chunk: 'Silver Ore Chunk' + aluminum_ore_chunk: 'Aluminum Ore Chunk' + lead_ore_chunk: 'Lead Ore Chunk' + zinc_ore_chunk: 'Zinc Ore Chunk' + nickel_ore_chunk: 'Nickel Ore Chunk' + cobalt_ore_chunk: 'Cobalt Ore Chunk' \ No newline at end of file