From d67cce4184205e2f072820aebea98b43312317fa Mon Sep 17 00:00:00 2001 From: cyberpwn Date: Mon, 16 Aug 2021 17:55:54 -0400 Subject: [PATCH 01/13] v --- .../volmit/iris/util/plugin/VolmitPlugin.java | 94 ------------------- 1 file changed, 94 deletions(-) diff --git a/src/main/java/com/volmit/iris/util/plugin/VolmitPlugin.java b/src/main/java/com/volmit/iris/util/plugin/VolmitPlugin.java index 386a0a9d1..802210dc6 100644 --- a/src/main/java/com/volmit/iris/util/plugin/VolmitPlugin.java +++ b/src/main/java/com/volmit/iris/util/plugin/VolmitPlugin.java @@ -30,12 +30,9 @@ import org.bukkit.command.Command; import org.bukkit.command.*; import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.configuration.file.YamlConfiguration; -import org.bukkit.event.Event; import org.bukkit.event.HandlerList; import org.bukkit.event.Listener; import org.bukkit.permissions.PermissionDefault; -import org.bukkit.plugin.Plugin; -import org.bukkit.plugin.RegisteredListener; import org.bukkit.plugin.java.JavaPlugin; import java.io.File; @@ -43,11 +40,9 @@ import java.io.IOException; import java.lang.reflect.Field; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Modifier; -import java.net.URLClassLoader; import java.util.Iterator; import java.util.List; import java.util.Map; -import java.util.SortedSet; @SuppressWarnings("EmptyMethod") public abstract class VolmitPlugin extends JavaPlugin implements Listener { @@ -55,9 +50,6 @@ public abstract class VolmitPlugin extends JavaPlugin implements Listener { private KMap, VirtualCommand> commands; private KList commandCache; private KList permissionCache; - private KMap controllers; - private KList cachedControllers; - private KMap, IController> cachedClassControllers; public File getJarFile() { return getFile(); @@ -83,15 +75,12 @@ public abstract class VolmitPlugin extends JavaPlugin implements Listener { registerInstance(); registerPermissions(); registerCommands(); - registerControllers(); - Bukkit.getScheduler().scheduleSyncRepeatingTask(this, this::tickControllers, 0, 0); J.a(this::outputInfo); registerListener(this); start(); } public void unregisterAll() { - stopControllers(); unregisterListeners(); unregisterCommands(); unregisterPermissions(); @@ -260,16 +249,6 @@ public abstract class VolmitPlugin extends JavaPlugin implements Listener { unregisterAll(); } - private void tickControllers() { - if (bad) { - return; - } - - for (IController i : getControllers()) { - tickController(i); - } - } - private void tickController(IController i) { if (bad) { return; @@ -291,62 +270,6 @@ public abstract class VolmitPlugin extends JavaPlugin implements Listener { } } - public KList getControllers() { - if (bad) { - return new KList<>(); - } - - return cachedControllers; - } - - private void registerControllers() { - if (bad) { - return; - } - controllers = new KMap<>(); - cachedClassControllers = new KMap<>(); - - for (Field i : getClass().getDeclaredFields()) { - if (i.isAnnotationPresent(Control.class)) { - try { - i.setAccessible(true); - IController pc = (IController) i.getType().getConstructor().newInstance(); - registerController(pc); - i.set(this, pc); - v("Registered " + pc.getName() + " (" + i.getName() + ")"); - } catch (IllegalArgumentException | IllegalAccessException | InstantiationException | InvocationTargetException | NoSuchMethodException | SecurityException e) { - w("Failed to register controller (field " + i.getName() + ")"); - e.printStackTrace(); - Iris.reportError(e); - } - } - } - - cachedControllers = controllers.v(); - } - - public IController getController(Class c) { - return cachedClassControllers.get(c); - } - - private void registerController(IController pc) { - if (bad) { - return; - } - controllers.put(pc.getName(), pc); - cachedClassControllers.put(pc.getClass(), pc); - registerListener(pc); - - try { - pc.start(); - v("Started " + pc.getName()); - } catch (Throwable e) { - w("Failed to start controller " + pc.getName()); - e.printStackTrace(); - Iris.reportError(e); - } - } - private void registerInstance() { if (bad) { return; @@ -569,23 +492,6 @@ public abstract class VolmitPlugin extends JavaPlugin implements Listener { } } - private void stopControllers() { - if (bad) { - return; - } - for (IController i : controllers.v()) { - try { - unregisterListener(i); - i.stop(); - v("Stopped " + i.getName()); - } catch (Throwable e) { - Iris.reportError(e); - w("Failed to stop controller " + i.getName()); - e.printStackTrace(); - } - } - } - public File getDataFile(String... strings) { File f = new File(getDataFolder(), new KList<>(strings).toString(File.separator)); f.getParentFile().mkdirs(); From af602a414a76995bf58f5890b55749a6fb5e942e Mon Sep 17 00:00:00 2001 From: cyberpwn Date: Mon, 16 Aug 2021 18:51:53 -0400 Subject: [PATCH 02/13] Managers -> Services --- out/production/resources/plugin.yml | 23 ++++ src/main/java/com/volmit/iris/Iris.java | 128 ++++++++---------- .../com/volmit/iris/core/DolphinManager.java | 27 ---- .../core/command/CommandIrisDownload.java | 3 +- .../command/CommandIrisUpdateProject.java | 3 +- .../object/CommandIrisObjectAnalyze.java | 4 +- .../object/CommandIrisObjectContract.java | 8 +- .../command/object/CommandIrisObjectDust.java | 4 +- .../object/CommandIrisObjectExpand.java | 8 +- .../command/object/CommandIrisObjectP1.java | 10 +- .../command/object/CommandIrisObjectP2.java | 10 +- .../object/CommandIrisObjectPaste.java | 12 +- .../command/object/CommandIrisObjectSave.java | 7 +- .../object/CommandIrisObjectSaveMatter.java | 7 +- .../object/CommandIrisObjectShift.java | 8 +- .../command/object/CommandIrisObjectWand.java | 4 +- .../command/object/CommandIrisObjectXAY.java | 8 +- .../command/object/CommandIrisObjectXPY.java | 8 +- .../studio/CommandIrisStudioBeautify.java | 5 +- .../studio/CommandIrisStudioClose.java | 11 +- .../studio/CommandIrisStudioConvert.java | 3 +- .../studio/CommandIrisStudioCreate.java | 5 +- .../studio/CommandIrisStudioEditBiome.java | 5 +- .../CommandIrisStudioExplorerGenerator.java | 7 +- .../command/studio/CommandIrisStudioLoot.java | 7 +- .../command/studio/CommandIrisStudioMap.java | 3 +- .../command/studio/CommandIrisStudioOpen.java | 3 +- .../studio/CommandIrisStudioPackage.java | 3 +- .../studio/CommandIrisStudioProfile.java | 5 +- .../studio/CommandIrisStudioTPStudio.java | 5 +- .../studio/CommandIrisStudioUpdate.java | 5 +- .../command/world/CommandIrisUpdateWorld.java | 5 +- .../core/command/world/CommandLocate.java | 1 + .../com/volmit/iris/core/decrees/DecIris.java | 3 +- .../volmit/iris/core/decrees/DecStudio.java | 26 ++-- .../volmit/iris/core/edit/JigsawEditor.java | 3 +- .../BoardSVC.java} | 31 ++--- .../CommandSVC.java} | 19 ++- .../ConversionSVC.java} | 19 ++- .../volmit/iris/core/service/DolphinSVC.java | 54 ++++++++ .../EditSVC.java} | 25 ++-- .../StudioSVC.java} | 87 ++++++------ .../TreeSVC.java} | 17 ++- .../VillageSVC.java} | 34 ++++- .../WandSVC.java} | 16 ++- .../volmit/iris/core/tools/IrisCreator.java | 3 +- .../volmit/iris/core/tools/IrisToolbelt.java | 4 +- .../engine/object/common/HeadlessWorld.java | 3 +- .../util/hunk/view/ChunkBiomeHunkView.java | 6 +- .../iris/util/hunk/view/ChunkHunkView.java | 5 +- .../volmit/iris/util/plugin/VolmitPlugin.java | 8 +- 51 files changed, 411 insertions(+), 307 deletions(-) create mode 100644 out/production/resources/plugin.yml delete mode 100644 src/main/java/com/volmit/iris/core/DolphinManager.java rename src/main/java/com/volmit/iris/core/{CoreBoardManager.java => service/BoardSVC.java} (92%) rename src/main/java/com/volmit/iris/core/{CommandManager.java => service/CommandSVC.java} (87%) rename src/main/java/com/volmit/iris/core/{ConversionManager.java => service/ConversionSVC.java} (97%) create mode 100644 src/main/java/com/volmit/iris/core/service/DolphinSVC.java rename src/main/java/com/volmit/iris/core/{EditManager.java => service/EditSVC.java} (86%) rename src/main/java/com/volmit/iris/core/{ProjectManager.java => service/StudioSVC.java} (90%) rename src/main/java/com/volmit/iris/core/{TreeManager.java => service/TreeSVC.java} (98%) rename src/main/java/com/volmit/iris/core/{VillagerManager.java => service/VillageSVC.java} (63%) rename src/main/java/com/volmit/iris/core/{WandManager.java => service/WandSVC.java} (98%) diff --git a/out/production/resources/plugin.yml b/out/production/resources/plugin.yml new file mode 100644 index 000000000..641130bc2 --- /dev/null +++ b/out/production/resources/plugin.yml @@ -0,0 +1,23 @@ +name: ${name} +version: ${version} +main: ${main} +load: STARTUP +authors: [ cyberpwn, NextdoorPsycho ] +website: volmit.com +description: More than a Dimension! +libraries: + - org.zeroturnaround:zt-zip:1.14 + - com.googlecode.concurrentlinkedhashmap:concurrentlinkedhashmap-lru:1.4.2 + - org.ow2.asm:asm:9.2 + - com.google.code.gson:gson:2.8.7 + - it.unimi.dsi:fastutil:8.5.4 + - com.google.guava:guava:30.1.1-jre + - bsf:bsf:2.4.0 + - rhino:js:1.7R2 +commands: + iris: + aliases: [ ir, irs ] + irisd: + aliases: [ ird, irsd ] +api-version: ${apiversion} +hotload-dependencies: false \ No newline at end of file diff --git a/src/main/java/com/volmit/iris/Iris.java b/src/main/java/com/volmit/iris/Iris.java index 25547a991..4d86a0d8d 100644 --- a/src/main/java/com/volmit/iris/Iris.java +++ b/src/main/java/com/volmit/iris/Iris.java @@ -18,18 +18,17 @@ package com.volmit.iris; -import com.volmit.iris.core.*; +import com.volmit.iris.core.IrisSettings; import com.volmit.iris.core.command.CommandIris; import com.volmit.iris.core.command.PermissionIris; import com.volmit.iris.core.command.studio.CommandIrisStudio; -import com.volmit.iris.core.command.world.CommandLocate; import com.volmit.iris.core.link.IrisPapiExpansion; import com.volmit.iris.core.link.MultiverseCoreLink; import com.volmit.iris.core.link.MythicMobsLink; import com.volmit.iris.core.link.OraxenLink; import com.volmit.iris.core.nms.INMS; import com.volmit.iris.core.project.loader.IrisData; -import com.volmit.iris.core.tools.IrisToolbelt; +import com.volmit.iris.core.service.StudioSVC; import com.volmit.iris.engine.object.biome.IrisBiome; import com.volmit.iris.engine.object.biome.IrisBiomeCustom; import com.volmit.iris.engine.object.common.IrisWorld; @@ -37,6 +36,7 @@ import com.volmit.iris.engine.object.compat.IrisCompat; import com.volmit.iris.engine.object.dimensional.IrisDimension; import com.volmit.iris.engine.platform.BukkitChunkGenerator; import com.volmit.iris.util.collection.KList; +import com.volmit.iris.util.collection.KMap; import com.volmit.iris.util.collection.KSet; import com.volmit.iris.util.format.C; import com.volmit.iris.util.format.Form; @@ -48,10 +48,7 @@ import com.volmit.iris.util.io.JarScanner; import com.volmit.iris.util.math.M; import com.volmit.iris.util.math.RNG; import com.volmit.iris.util.parallel.MultiBurst; -import com.volmit.iris.util.plugin.Metrics; -import com.volmit.iris.util.plugin.Permission; -import com.volmit.iris.util.plugin.VolmitPlugin; -import com.volmit.iris.util.plugin.VolmitSender; +import com.volmit.iris.util.plugin.*; import com.volmit.iris.util.reflect.ShadeFix; import com.volmit.iris.util.scheduling.GroupedExecutor; import com.volmit.iris.util.scheduling.J; @@ -61,7 +58,6 @@ import io.papermc.lib.PaperLib; import net.kyori.adventure.platform.bukkit.BukkitAudiences; import net.kyori.adventure.text.serializer.ComponentSerializer; import org.bukkit.Bukkit; -import org.bukkit.World; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; @@ -78,19 +74,13 @@ import java.util.Date; @SuppressWarnings("CanBeFinal") public class Iris extends VolmitPlugin implements Listener { + private KMap, IrisService> services; public static KList executors = new KList<>(); public static Iris instance; public static BukkitAudiences audiences; - public static ProjectManager proj; - public static ConversionManager convert; - public static WandManager wand; - public static EditManager edit; - public static CoreBoardManager board; public static MultiverseCoreLink linkMultiverseCore; public static OraxenLink linkOraxen; public static MythicMobsLink linkMythicMobs; - public static CommandManager commandManager; - public static TreeManager saplingManager; private static final Queue syncJobs = new ShurikenQueue<>(); public static IrisCompat compat; public static FileWatcher configWatcher; @@ -105,68 +95,76 @@ public class Iris extends VolmitPlugin implements Listener { @com.volmit.iris.util.plugin.Command public CommandIrisStudio commandStudio; - public Iris() { + private void preEnable() { instance = this; INMS.get(); IO.delete(new File("iris")); installDataPacks(); + fixShading(); } - public void onEnable() { + @SuppressWarnings("unchecked") + private void enable() { + services = new KMap<>(); + initialize("com.volmit.iris.core.service").forEach((i) -> services.put((Class) i.getClass(), (IrisService) i)); + audiences = BukkitAudiences.create(this); - fixShading(); sender = new VolmitSender(Bukkit.getConsoleSender()); sender.setTag(getTag()); instance = this; compat = IrisCompat.configured(getDataFile("compat.json")); - proj = new ProjectManager(); - convert = new ConversionManager(); - wand = new WandManager(); - board = new CoreBoardManager(); + linkMultiverseCore = new MultiverseCoreLink(); linkOraxen = new OraxenLink(); linkMythicMobs = new MythicMobsLink(); - saplingManager = new TreeManager(); - edit = new EditManager(); configWatcher = new FileWatcher(getDataFile("settings.json")); - commandManager = new CommandManager(); - getServer().getPluginManager().registerEvents(new CommandLocate(), this); - getServer().getPluginManager().registerEvents(new WandManager(), this); - getServer().getPluginManager().registerEvents(new DolphinManager(), this); - getServer().getPluginManager().registerEvents(new VillagerManager(), this); - super.onEnable(); - Bukkit.getPluginManager().registerEvents(this, this); - J.s(this::lateBind); + + services.values().forEach(IrisService::onEnable); + services.values().forEach(this::registerListener); + } + + private void postEnable() { + J.a(() -> PaperLib.suggestPaper(this)); + J.a(() -> IO.delete(getTemp())); + J.a(this::bstats); + J.ar(this::checkConfigHotload, 60); + J.sr(this::tickQueue, 0); + J.s(this::setupPapi); + J.a(this::verifyDataPacksPost, 20); splash(); } + @SuppressWarnings("unchecked") + public static T service(Class c) { + return (T) instance.services.get(c); + } + + public Iris() { + preEnable(); + } + + @SuppressWarnings("unchecked") + public void onEnable() { + enable(); + super.onEnable(); + Bukkit.getPluginManager().registerEvents(this, this); + J.s(this::postEnable); + } + public void onDisable() { - if (IrisSettings.get().isStudio()) { - Iris.debug("Studio Mode Active: Closing Projects"); - proj.close(); - - for (World i : Bukkit.getWorlds()) { - if (IrisToolbelt.isIrisWorld(i)) { - Iris.debug("Closing Platform Generator " + i.getName()); - IrisToolbelt.access(i).close(); - } - } - - for (GroupedExecutor i : executors) { - Iris.debug("Closing Executor " + i.toString()); - i.closeNow(); - } + for (GroupedExecutor i : executors) { + Iris.debug("Closing Executor " + i.toString()); + i.closeNow(); } executors.clear(); - board.disable(); - Iris.debug("Cancelled all tasks"); + Bukkit.getScheduler().cancelTasks(this); - Iris.debug("Unregistered all events"); HandlerList.unregisterAll((Plugin) this); - Iris.debug("Multiburst Shutting down"); MultiBurst.burst.shutdown(); - Iris.debug("Iris Shutdown"); + + services.values().forEach(IrisService::onDisable); + services.clear(); super.onDisable(); } @@ -203,15 +201,6 @@ public class Iris extends VolmitPlugin implements Listener { ShadeFix.fix(ComponentSerializer.class); } - private void lateBind() { - J.a(() -> PaperLib.suggestPaper(this)); - J.a(() -> IO.delete(getTemp())); - J.a(this::bstats); - J.ar(this::checkConfigHotload, 60); - J.sr(this::tickQueue, 0); - J.s(this::setupPapi); - } - private void setupPapi() { if (Bukkit.getPluginManager().getPlugin("PlaceholderAPI") != null) { new IrisPapiExpansion().register(); @@ -330,13 +319,7 @@ public class Iris extends VolmitPlugin implements Listener { private void bstats() { if (IrisSettings.get().getGeneral().isPluginMetrics()) { - J.s(() -> { - Metrics m = new Metrics(Iris.instance, 8757); - - m.addCustomChart(new Metrics.SingleLineChart("custom_dimensions", ProjectManager::countUniqueDimensions)); - - m.addCustomChart(new Metrics.SimplePie("using_custom_dimensions", () -> ProjectManager.countUniqueDimensions() > 0 ? "Active Projects" : "No Projects")); - }); + J.s(() -> new Metrics(Iris.instance, 8757)); } } @@ -449,7 +432,7 @@ public class Iris extends VolmitPlugin implements Listener { public ChunkGenerator getDefaultWorldGenerator(String worldName, String id) { IrisDimension dim; - if (id == null || id.isEmpty()){ + if (id == null || id.isEmpty()) { dim = IrisData.loadAnyDimension(IrisSettings.get().getGenerator().getDefaultWorldType()); } else { dim = IrisData.loadAnyDimension(id); @@ -459,7 +442,7 @@ public class Iris extends VolmitPlugin implements Listener { if (dim == null) { Iris.warn("Unable to find dimension type " + id + " Looking for online packs..."); - Iris.proj.downloadSearch(new VolmitSender(Bukkit.getConsoleSender()), id, true); + service(StudioSVC.class).downloadSearch(new VolmitSender(Bukkit.getConsoleSender()), id, true); dim = IrisData.loadAnyDimension(id); if (dim == null) { @@ -611,12 +594,7 @@ public class Iris extends VolmitPlugin implements Listener { msg(C.WHITE + string); } - public void hit(long hits2) { - board.hits.put(hits2); - } - public void splash() { - J.a(this::verifyDataPacksPost, 20); if (!IrisSettings.get().getGeneral().isSplashLogoStartup()) { return; } diff --git a/src/main/java/com/volmit/iris/core/DolphinManager.java b/src/main/java/com/volmit/iris/core/DolphinManager.java deleted file mode 100644 index 65e6e04b6..000000000 --- a/src/main/java/com/volmit/iris/core/DolphinManager.java +++ /dev/null @@ -1,27 +0,0 @@ -package com.volmit.iris.core; - -import com.volmit.iris.core.tools.IrisToolbelt; -import org.bukkit.Material; -import org.bukkit.entity.EntityType; -import org.bukkit.event.EventHandler; -import org.bukkit.event.Listener; -import org.bukkit.event.player.PlayerInteractEntityEvent; - -public class DolphinManager implements Listener { - - /** - * Prevents dolphins from being fed, to locate a treasure map. - * Note: This results in odd dolphin behaviour, but it's the best we can do. - */ - @EventHandler - public void on(PlayerInteractEntityEvent event) { - if (!IrisToolbelt.isIrisWorld(event.getPlayer().getWorld())) { - return; - } - - Material hand = event.getPlayer().getInventory().getItem(event.getHand()).getType(); - if (event.getRightClicked().getType().equals(EntityType.DOLPHIN) && (hand.equals(Material.TROPICAL_FISH) || hand.equals(Material.PUFFERFISH) || hand.equals(Material.COD) || hand.equals(Material.SALMON))) { - event.setCancelled(true); - } - } -} diff --git a/src/main/java/com/volmit/iris/core/command/CommandIrisDownload.java b/src/main/java/com/volmit/iris/core/command/CommandIrisDownload.java index 824be4a52..90d4c5d8d 100644 --- a/src/main/java/com/volmit/iris/core/command/CommandIrisDownload.java +++ b/src/main/java/com/volmit/iris/core/command/CommandIrisDownload.java @@ -19,6 +19,7 @@ package com.volmit.iris.core.command; import com.volmit.iris.Iris; +import com.volmit.iris.core.service.StudioSVC; import com.volmit.iris.util.collection.KList; import com.volmit.iris.util.format.C; import com.volmit.iris.util.plugin.MortarCommand; @@ -75,7 +76,7 @@ public class CommandIrisDownload extends MortarCommand { final String finalPack = pack + "/" + branch; - J.a(() -> Iris.proj.downloadSearch(sender, finalPack, btrim)); + J.a(() -> Iris.service(StudioSVC.class).downloadSearch(sender, finalPack, btrim)); return true; } diff --git a/src/main/java/com/volmit/iris/core/command/CommandIrisUpdateProject.java b/src/main/java/com/volmit/iris/core/command/CommandIrisUpdateProject.java index 6b72f80b6..c5c3c541c 100644 --- a/src/main/java/com/volmit/iris/core/command/CommandIrisUpdateProject.java +++ b/src/main/java/com/volmit/iris/core/command/CommandIrisUpdateProject.java @@ -19,6 +19,7 @@ package com.volmit.iris.core.command; import com.volmit.iris.Iris; +import com.volmit.iris.core.service.StudioSVC; import com.volmit.iris.util.collection.KList; import com.volmit.iris.util.format.C; import com.volmit.iris.util.plugin.MortarCommand; @@ -45,7 +46,7 @@ public class CommandIrisUpdateProject extends MortarCommand { return true; } - J.a(() -> Iris.proj.downloadSearch(sender, args[0], false, true)); + J.a(() -> Iris.service(StudioSVC.class).downloadSearch(sender, args[0], false, true)); return true; } diff --git a/src/main/java/com/volmit/iris/core/command/object/CommandIrisObjectAnalyze.java b/src/main/java/com/volmit/iris/core/command/object/CommandIrisObjectAnalyze.java index f79225a60..6e8252f45 100644 --- a/src/main/java/com/volmit/iris/core/command/object/CommandIrisObjectAnalyze.java +++ b/src/main/java/com/volmit/iris/core/command/object/CommandIrisObjectAnalyze.java @@ -2,8 +2,8 @@ package com.volmit.iris.core.command.object; import com.volmit.iris.Iris; import com.volmit.iris.core.IrisSettings; -import com.volmit.iris.core.ProjectManager; import com.volmit.iris.core.project.loader.IrisData; +import com.volmit.iris.core.service.StudioSVC; import com.volmit.iris.core.tools.IrisToolbelt; import com.volmit.iris.engine.object.objects.IrisObject; import com.volmit.iris.util.collection.KList; @@ -71,7 +71,7 @@ public class CommandIrisObjectAnalyze extends MortarCommand { IrisObject obj = IrisData.loadAnyObject(args[0]); if (obj == null || obj.getLoadFile() == null) { - sender.sendMessage("Can't find " + args[0] + " in the " + ProjectManager.WORKSPACE_NAME + " folder"); + sender.sendMessage("Can't find " + args[0] + " in the " + StudioSVC.WORKSPACE_NAME + " folder"); return; } diff --git a/src/main/java/com/volmit/iris/core/command/object/CommandIrisObjectContract.java b/src/main/java/com/volmit/iris/core/command/object/CommandIrisObjectContract.java index c719db546..127c4381e 100644 --- a/src/main/java/com/volmit/iris/core/command/object/CommandIrisObjectContract.java +++ b/src/main/java/com/volmit/iris/core/command/object/CommandIrisObjectContract.java @@ -20,7 +20,7 @@ package com.volmit.iris.core.command.object; import com.volmit.iris.Iris; import com.volmit.iris.core.IrisSettings; -import com.volmit.iris.core.WandManager; +import com.volmit.iris.core.service.WandSVC; import com.volmit.iris.util.collection.KList; import com.volmit.iris.util.data.Cuboid; import com.volmit.iris.util.math.Direction; @@ -58,13 +58,13 @@ public class CommandIrisObjectContract extends MortarCommand { Player p = sender.player(); - if (!WandManager.isHoldingWand(p)) { + if (!WandSVC.isHoldingWand(p)) { sender.sendMessage("Ready your Wand."); return true; } int amt = args.length == 1 ? Integer.parseInt(args[0]) : 1; - Location[] b = WandManager.getCuboid(p.getInventory().getItemInMainHand()); + Location[] b = WandSVC.getCuboid(p.getInventory().getItemInMainHand()); Location a1 = b[0].clone(); Location a2 = b[1].clone(); Cuboid cursor = new Cuboid(a1, a2); @@ -72,7 +72,7 @@ public class CommandIrisObjectContract extends MortarCommand { cursor = cursor.expand(d, -amt); b[0] = cursor.getLowerNE(); b[1] = cursor.getUpperSW(); - p.getInventory().setItemInMainHand(WandManager.createWand(b[0], b[1])); + p.getInventory().setItemInMainHand(WandSVC.createWand(b[0], b[1])); p.updateInventory(); p.playSound(p.getLocation(), Sound.ENTITY_ITEM_FRAME_ROTATE_ITEM, 1f, 0.55f); diff --git a/src/main/java/com/volmit/iris/core/command/object/CommandIrisObjectDust.java b/src/main/java/com/volmit/iris/core/command/object/CommandIrisObjectDust.java index fccd5b92f..247fe232a 100644 --- a/src/main/java/com/volmit/iris/core/command/object/CommandIrisObjectDust.java +++ b/src/main/java/com/volmit/iris/core/command/object/CommandIrisObjectDust.java @@ -20,7 +20,7 @@ package com.volmit.iris.core.command.object; import com.volmit.iris.Iris; import com.volmit.iris.core.IrisSettings; -import com.volmit.iris.core.WandManager; +import com.volmit.iris.core.service.WandSVC; import com.volmit.iris.util.collection.KList; import com.volmit.iris.util.plugin.MortarCommand; import com.volmit.iris.util.plugin.VolmitSender; @@ -51,7 +51,7 @@ public class CommandIrisObjectDust extends MortarCommand { return true; } - sender.player().getInventory().addItem(WandManager.createDust()); + sender.player().getInventory().addItem(WandSVC.createDust()); sender.player().playSound(sender.player().getLocation(), Sound.AMBIENT_SOUL_SAND_VALLEY_ADDITIONS, 1f, 1.5f); return true; diff --git a/src/main/java/com/volmit/iris/core/command/object/CommandIrisObjectExpand.java b/src/main/java/com/volmit/iris/core/command/object/CommandIrisObjectExpand.java index 613899e19..106c372fe 100644 --- a/src/main/java/com/volmit/iris/core/command/object/CommandIrisObjectExpand.java +++ b/src/main/java/com/volmit/iris/core/command/object/CommandIrisObjectExpand.java @@ -20,7 +20,7 @@ package com.volmit.iris.core.command.object; import com.volmit.iris.Iris; import com.volmit.iris.core.IrisSettings; -import com.volmit.iris.core.WandManager; +import com.volmit.iris.core.service.WandSVC; import com.volmit.iris.util.collection.KList; import com.volmit.iris.util.data.Cuboid; import com.volmit.iris.util.math.Direction; @@ -58,13 +58,13 @@ public class CommandIrisObjectExpand extends MortarCommand { Player p = sender.player(); - if (!WandManager.isHoldingWand(p)) { + if (!WandSVC.isHoldingWand(p)) { sender.sendMessage("Ready your Wand."); return true; } int amt = args.length == 1 ? Integer.parseInt(args[0]) : 1; - Location[] b = WandManager.getCuboid(p.getInventory().getItemInMainHand()); + Location[] b = WandSVC.getCuboid(p.getInventory().getItemInMainHand()); Location a1 = b[0].clone(); Location a2 = b[1].clone(); Cuboid cursor = new Cuboid(a1, a2); @@ -72,7 +72,7 @@ public class CommandIrisObjectExpand extends MortarCommand { cursor = cursor.expand(d, amt); b[0] = cursor.getLowerNE(); b[1] = cursor.getUpperSW(); - p.getInventory().setItemInMainHand(WandManager.createWand(b[0], b[1])); + p.getInventory().setItemInMainHand(WandSVC.createWand(b[0], b[1])); p.updateInventory(); p.playSound(p.getLocation(), Sound.ENTITY_ITEM_FRAME_ROTATE_ITEM, 1f, 0.55f); diff --git a/src/main/java/com/volmit/iris/core/command/object/CommandIrisObjectP1.java b/src/main/java/com/volmit/iris/core/command/object/CommandIrisObjectP1.java index 6b07100a0..a5fea0acd 100644 --- a/src/main/java/com/volmit/iris/core/command/object/CommandIrisObjectP1.java +++ b/src/main/java/com/volmit/iris/core/command/object/CommandIrisObjectP1.java @@ -20,7 +20,7 @@ package com.volmit.iris.core.command.object; import com.volmit.iris.Iris; import com.volmit.iris.core.IrisSettings; -import com.volmit.iris.core.WandManager; +import com.volmit.iris.core.service.WandSVC; import com.volmit.iris.util.collection.KList; import com.volmit.iris.util.plugin.MortarCommand; import com.volmit.iris.util.plugin.VolmitSender; @@ -57,15 +57,15 @@ public class CommandIrisObjectP1 extends MortarCommand { Player p = sender.player(); - if (!WandManager.isHoldingWand(p)) { + if (!WandSVC.isHoldingWand(p)) { sender.sendMessage("Ready your Wand."); return true; } ItemStack wand = p.getInventory().getItemInMainHand(); - if (WandManager.isWand(wand)) { - Location[] g = WandManager.getCuboid(wand); + if (WandSVC.isWand(wand)) { + Location[] g = WandSVC.getCuboid(wand); g[0] = p.getLocation().getBlock().getLocation().clone().add(0, -1, 0); if (args.length == 1 && args[0].equals("-l")) { @@ -73,7 +73,7 @@ public class CommandIrisObjectP1 extends MortarCommand { g[0] = p.getTargetBlock(null, 256).getLocation().clone(); } - p.setItemInHand(WandManager.createWand(g[0], g[1])); + p.setItemInHand(WandSVC.createWand(g[0], g[1])); } return true; diff --git a/src/main/java/com/volmit/iris/core/command/object/CommandIrisObjectP2.java b/src/main/java/com/volmit/iris/core/command/object/CommandIrisObjectP2.java index 7e5605d94..18221c38a 100644 --- a/src/main/java/com/volmit/iris/core/command/object/CommandIrisObjectP2.java +++ b/src/main/java/com/volmit/iris/core/command/object/CommandIrisObjectP2.java @@ -20,7 +20,7 @@ package com.volmit.iris.core.command.object; import com.volmit.iris.Iris; import com.volmit.iris.core.IrisSettings; -import com.volmit.iris.core.WandManager; +import com.volmit.iris.core.service.WandSVC; import com.volmit.iris.util.collection.KList; import com.volmit.iris.util.plugin.MortarCommand; import com.volmit.iris.util.plugin.VolmitSender; @@ -57,15 +57,15 @@ public class CommandIrisObjectP2 extends MortarCommand { Player p = sender.player(); - if (!WandManager.isHoldingWand(p)) { + if (!WandSVC.isHoldingWand(p)) { sender.sendMessage("Ready your Wand."); return true; } ItemStack wand = p.getInventory().getItemInMainHand(); - if (WandManager.isWand(wand)) { - Location[] g = WandManager.getCuboid(wand); + if (WandSVC.isWand(wand)) { + Location[] g = WandSVC.getCuboid(wand); g[1] = p.getLocation().getBlock().getLocation().clone().add(0, -1, 0); if (args.length == 1 && args[0].equals("-l")) { @@ -73,7 +73,7 @@ public class CommandIrisObjectP2 extends MortarCommand { g[1] = p.getTargetBlock(null, 256).getLocation().clone(); } - p.setItemInHand(WandManager.createWand(g[0], g[1])); + p.setItemInHand(WandSVC.createWand(g[0], g[1])); } return true; diff --git a/src/main/java/com/volmit/iris/core/command/object/CommandIrisObjectPaste.java b/src/main/java/com/volmit/iris/core/command/object/CommandIrisObjectPaste.java index c81975491..958d2cff1 100644 --- a/src/main/java/com/volmit/iris/core/command/object/CommandIrisObjectPaste.java +++ b/src/main/java/com/volmit/iris/core/command/object/CommandIrisObjectPaste.java @@ -20,9 +20,9 @@ package com.volmit.iris.core.command.object; import com.volmit.iris.Iris; import com.volmit.iris.core.IrisSettings; -import com.volmit.iris.core.ProjectManager; -import com.volmit.iris.core.WandManager; import com.volmit.iris.core.project.loader.IrisData; +import com.volmit.iris.core.service.StudioSVC; +import com.volmit.iris.core.service.WandSVC; import com.volmit.iris.core.tools.IrisToolbelt; import com.volmit.iris.engine.object.common.IObjectPlacer; import com.volmit.iris.engine.object.objects.IrisObject; @@ -91,7 +91,7 @@ public class CommandIrisObjectPaste extends MortarCommand { if (obj == null || obj.getLoadFile() == null) { - sender.sendMessage("Can't find " + args[0] + " in the " + ProjectManager.WORKSPACE_NAME + " folder"); + sender.sendMessage("Can't find " + args[0] + " in the " + StudioSVC.WORKSPACE_NAME + " folder"); return true; } @@ -188,14 +188,14 @@ public class CommandIrisObjectPaste extends MortarCommand { CommandIrisObjectUndo.addChanges(sender.player(), futureChanges); if (intoWand) { - ItemStack newWand = WandManager.createWand(block.clone().subtract(obj.getCenter()).add(obj.getW() - 1, + ItemStack newWand = WandSVC.createWand(block.clone().subtract(obj.getCenter()).add(obj.getW() - 1, obj.getH() + obj.getCenter().clone().getY() - 1, obj.getD() - 1), block.clone().subtract(obj.getCenter().clone().setY(0))); - if (WandManager.isWand(wand)) { + if (WandSVC.isWand(wand)) { wand = newWand; p.getInventory().setItemInMainHand(wand); sender.sendMessage("Updated wand for " + "objects/" + args[0] + ".iob"); } else { - int slot = WandManager.findWand(sender.player().getInventory()); + int slot = WandSVC.findWand(sender.player().getInventory()); if (slot == -1) { p.getInventory().addItem(newWand); sender.sendMessage("Given new wand for " + "objects/" + args[0] + ".iob"); diff --git a/src/main/java/com/volmit/iris/core/command/object/CommandIrisObjectSave.java b/src/main/java/com/volmit/iris/core/command/object/CommandIrisObjectSave.java index 5b92fa0d9..a5dc75080 100644 --- a/src/main/java/com/volmit/iris/core/command/object/CommandIrisObjectSave.java +++ b/src/main/java/com/volmit/iris/core/command/object/CommandIrisObjectSave.java @@ -20,7 +20,8 @@ package com.volmit.iris.core.command.object; import com.volmit.iris.Iris; import com.volmit.iris.core.IrisSettings; -import com.volmit.iris.core.WandManager; +import com.volmit.iris.core.service.StudioSVC; +import com.volmit.iris.core.service.WandSVC; import com.volmit.iris.engine.object.objects.IrisObject; import com.volmit.iris.util.collection.KList; import com.volmit.iris.util.plugin.MortarCommand; @@ -75,8 +76,8 @@ public class CommandIrisObjectSave extends MortarCommand { Player p = sender.player(); ItemStack wand = p.getInventory().getItemInMainHand(); - IrisObject o = WandManager.createSchematic(wand); - File file = Iris.proj.getWorkspaceFile(args[0], "objects", args[1] + ".iob"); + IrisObject o = WandSVC.createSchematic(wand); + File file = Iris.service(StudioSVC.class).getWorkspaceFile(args[0], "objects", args[1] + ".iob"); if (file.exists()) { if (!overwrite) { diff --git a/src/main/java/com/volmit/iris/core/command/object/CommandIrisObjectSaveMatter.java b/src/main/java/com/volmit/iris/core/command/object/CommandIrisObjectSaveMatter.java index c22716eaa..45a599486 100644 --- a/src/main/java/com/volmit/iris/core/command/object/CommandIrisObjectSaveMatter.java +++ b/src/main/java/com/volmit/iris/core/command/object/CommandIrisObjectSaveMatter.java @@ -20,7 +20,8 @@ package com.volmit.iris.core.command.object; import com.volmit.iris.Iris; import com.volmit.iris.core.IrisSettings; -import com.volmit.iris.core.WandManager; +import com.volmit.iris.core.service.StudioSVC; +import com.volmit.iris.core.service.WandSVC; import com.volmit.iris.util.collection.KList; import com.volmit.iris.util.matter.Matter; import com.volmit.iris.util.plugin.MortarCommand; @@ -75,8 +76,8 @@ public class CommandIrisObjectSaveMatter extends MortarCommand { Player p = sender.player(); ItemStack wand = p.getInventory().getItemInMainHand(); - Matter o = WandManager.createMatterSchem(p, wand); - File file = Iris.proj.getWorkspaceFile(args[0], "objects", args[1] + ".iob"); + Matter o = WandSVC.createMatterSchem(p, wand); + File file = Iris.service(StudioSVC.class).getWorkspaceFile(args[0], "objects", args[1] + ".iob"); if (file.exists()) { if (!overwrite) { diff --git a/src/main/java/com/volmit/iris/core/command/object/CommandIrisObjectShift.java b/src/main/java/com/volmit/iris/core/command/object/CommandIrisObjectShift.java index 05bc6f508..e106704e6 100644 --- a/src/main/java/com/volmit/iris/core/command/object/CommandIrisObjectShift.java +++ b/src/main/java/com/volmit/iris/core/command/object/CommandIrisObjectShift.java @@ -20,7 +20,7 @@ package com.volmit.iris.core.command.object; import com.volmit.iris.Iris; import com.volmit.iris.core.IrisSettings; -import com.volmit.iris.core.WandManager; +import com.volmit.iris.core.service.WandSVC; import com.volmit.iris.util.collection.KList; import com.volmit.iris.util.data.Cuboid; import com.volmit.iris.util.math.Direction; @@ -58,13 +58,13 @@ public class CommandIrisObjectShift extends MortarCommand { Player p = sender.player(); - if (!WandManager.isHoldingWand(p)) { + if (!WandSVC.isHoldingWand(p)) { sender.sendMessage("Ready your Wand."); return true; } int amt = args.length == 1 ? Integer.parseInt(args[0]) : 1; - Location[] b = WandManager.getCuboid(p.getInventory().getItemInMainHand()); + Location[] b = WandSVC.getCuboid(p.getInventory().getItemInMainHand()); Location a1 = b[0].clone(); Location a2 = b[1].clone(); Direction d = Direction.closest(p.getLocation().getDirection()).reverse(); @@ -73,7 +73,7 @@ public class CommandIrisObjectShift extends MortarCommand { Cuboid cursor = new Cuboid(a1, a2); b[0] = cursor.getLowerNE(); b[1] = cursor.getUpperSW(); - p.getInventory().setItemInMainHand(WandManager.createWand(b[0], b[1])); + p.getInventory().setItemInMainHand(WandSVC.createWand(b[0], b[1])); p.updateInventory(); p.playSound(p.getLocation(), Sound.ENTITY_ITEM_FRAME_ROTATE_ITEM, 1f, 0.55f); diff --git a/src/main/java/com/volmit/iris/core/command/object/CommandIrisObjectWand.java b/src/main/java/com/volmit/iris/core/command/object/CommandIrisObjectWand.java index e71914784..d8c476c91 100644 --- a/src/main/java/com/volmit/iris/core/command/object/CommandIrisObjectWand.java +++ b/src/main/java/com/volmit/iris/core/command/object/CommandIrisObjectWand.java @@ -20,7 +20,7 @@ package com.volmit.iris.core.command.object; import com.volmit.iris.Iris; import com.volmit.iris.core.IrisSettings; -import com.volmit.iris.core.WandManager; +import com.volmit.iris.core.service.WandSVC; import com.volmit.iris.util.collection.KList; import com.volmit.iris.util.plugin.MortarCommand; import com.volmit.iris.util.plugin.VolmitSender; @@ -52,7 +52,7 @@ public class CommandIrisObjectWand extends MortarCommand { return true; } - sender.player().getInventory().addItem(WandManager.createWand()); + sender.player().getInventory().addItem(WandSVC.createWand()); sender.player().playSound(sender.player().getLocation(), Sound.ITEM_ARMOR_EQUIP_NETHERITE, 1f, 1.5f); return true; diff --git a/src/main/java/com/volmit/iris/core/command/object/CommandIrisObjectXAY.java b/src/main/java/com/volmit/iris/core/command/object/CommandIrisObjectXAY.java index 24acc4abc..3c3a65f98 100644 --- a/src/main/java/com/volmit/iris/core/command/object/CommandIrisObjectXAY.java +++ b/src/main/java/com/volmit/iris/core/command/object/CommandIrisObjectXAY.java @@ -20,7 +20,7 @@ package com.volmit.iris.core.command.object; import com.volmit.iris.Iris; import com.volmit.iris.core.IrisSettings; -import com.volmit.iris.core.WandManager; +import com.volmit.iris.core.service.WandSVC; import com.volmit.iris.util.collection.KList; import com.volmit.iris.util.data.Cuboid; import com.volmit.iris.util.data.Cuboid.CuboidDirection; @@ -60,12 +60,12 @@ public class CommandIrisObjectXAY extends MortarCommand { Player p = sender.player(); - if (!WandManager.isHoldingWand(p)) { + if (!WandSVC.isHoldingWand(p)) { sender.sendMessage("Ready your Wand."); return true; } - Location[] b = WandManager.getCuboid(p.getInventory().getItemInMainHand()); + Location[] b = WandSVC.getCuboid(p.getInventory().getItemInMainHand()); Location a1 = b[0].clone(); Location a2 = b[1].clone(); Location a1x = b[0].clone(); @@ -99,7 +99,7 @@ public class CommandIrisObjectXAY extends MortarCommand { cursor = cursor.contract(CuboidDirection.West); b[0] = cursor.getLowerNE(); b[1] = cursor.getUpperSW(); - p.getInventory().setItemInMainHand(WandManager.createWand(b[0], b[1])); + p.getInventory().setItemInMainHand(WandSVC.createWand(b[0], b[1])); p.updateInventory(); p.playSound(p.getLocation(), Sound.ENTITY_ITEM_FRAME_ROTATE_ITEM, 1f, 0.55f); diff --git a/src/main/java/com/volmit/iris/core/command/object/CommandIrisObjectXPY.java b/src/main/java/com/volmit/iris/core/command/object/CommandIrisObjectXPY.java index b142e9649..1ec4fc96d 100644 --- a/src/main/java/com/volmit/iris/core/command/object/CommandIrisObjectXPY.java +++ b/src/main/java/com/volmit/iris/core/command/object/CommandIrisObjectXPY.java @@ -20,7 +20,7 @@ package com.volmit.iris.core.command.object; import com.volmit.iris.Iris; import com.volmit.iris.core.IrisSettings; -import com.volmit.iris.core.WandManager; +import com.volmit.iris.core.service.WandSVC; import com.volmit.iris.util.collection.KList; import com.volmit.iris.util.data.Cuboid; import com.volmit.iris.util.data.Cuboid.CuboidDirection; @@ -59,11 +59,11 @@ public class CommandIrisObjectXPY extends MortarCommand { Player p = sender.player(); - if (!WandManager.isHoldingWand(p)) { + if (!WandSVC.isHoldingWand(p)) { sender.sendMessage("Ready your Wand."); return true; } - Location[] b = WandManager.getCuboid(p.getInventory().getItemInMainHand()); + Location[] b = WandSVC.getCuboid(p.getInventory().getItemInMainHand()); b[0].add(new Vector(0, 1, 0)); b[1].add(new Vector(0, 1, 0)); Location a1 = b[0].clone(); @@ -87,7 +87,7 @@ public class CommandIrisObjectXPY extends MortarCommand { cursor = cursor.contract(CuboidDirection.West); b[0] = cursor.getLowerNE(); b[1] = cursor.getUpperSW(); - p.getInventory().setItemInMainHand(WandManager.createWand(b[0], b[1])); + p.getInventory().setItemInMainHand(WandSVC.createWand(b[0], b[1])); p.updateInventory(); p.playSound(p.getLocation(), Sound.ENTITY_ITEM_FRAME_ROTATE_ITEM, 1f, 0.55f); diff --git a/src/main/java/com/volmit/iris/core/command/studio/CommandIrisStudioBeautify.java b/src/main/java/com/volmit/iris/core/command/studio/CommandIrisStudioBeautify.java index 6c4fcd4a8..c27bbc6f8 100644 --- a/src/main/java/com/volmit/iris/core/command/studio/CommandIrisStudioBeautify.java +++ b/src/main/java/com/volmit/iris/core/command/studio/CommandIrisStudioBeautify.java @@ -20,6 +20,7 @@ package com.volmit.iris.core.command.studio; import com.volmit.iris.Iris; import com.volmit.iris.core.IrisSettings; +import com.volmit.iris.core.service.StudioSVC; import com.volmit.iris.util.collection.KList; import com.volmit.iris.util.format.Form; import com.volmit.iris.util.io.IO; @@ -54,12 +55,12 @@ public class CommandIrisStudioBeautify extends MortarCommand { File clean = null; if (args.length == 0) { - if (!Iris.proj.isProjectOpen()) { + if (!Iris.service(StudioSVC.class).isProjectOpen()) { sender.sendMessage("No open project. Either use /iris std beautify or have a project open."); return true; } - clean = Iris.proj.getActiveProject().getPath(); + clean = Iris.service(StudioSVC.class).getActiveProject().getPath(); } else { clean = Iris.instance.getDataFolder("packs", args[0]); diff --git a/src/main/java/com/volmit/iris/core/command/studio/CommandIrisStudioClose.java b/src/main/java/com/volmit/iris/core/command/studio/CommandIrisStudioClose.java index 19080e304..4852ba0a8 100644 --- a/src/main/java/com/volmit/iris/core/command/studio/CommandIrisStudioClose.java +++ b/src/main/java/com/volmit/iris/core/command/studio/CommandIrisStudioClose.java @@ -20,6 +20,7 @@ package com.volmit.iris.core.command.studio; import com.volmit.iris.Iris; import com.volmit.iris.core.IrisSettings; +import com.volmit.iris.core.service.StudioSVC; import com.volmit.iris.util.collection.KList; import com.volmit.iris.util.plugin.MortarCommand; import com.volmit.iris.util.plugin.VolmitSender; @@ -47,7 +48,7 @@ public class CommandIrisStudioClose extends MortarCommand { return true; } - if (!Iris.proj.isProjectOpen()) { + if (!Iris.service(StudioSVC.class).isProjectOpen()) { sender.sendMessage("No open projects."); return true; } @@ -56,7 +57,7 @@ public class CommandIrisStudioClose extends MortarCommand { World f = null; for (World i : Bukkit.getWorlds()) { - if (i.getWorldFolder().getAbsolutePath().equals(Iris.proj.getActiveProject().getActiveProvider().getTarget().getWorld().worldFolder().getAbsolutePath())) { + if (i.getWorldFolder().getAbsolutePath().equals(Iris.service(StudioSVC.class).getActiveProject().getActiveProvider().getTarget().getWorld().worldFolder().getAbsolutePath())) { continue; } @@ -65,17 +66,17 @@ public class CommandIrisStudioClose extends MortarCommand { } if (f == null) { - for (Player i : Iris.proj.getActiveProject().getActiveProvider().getTarget().getWorld().getPlayers()) { + for (Player i : Iris.service(StudioSVC.class).getActiveProject().getActiveProvider().getTarget().getWorld().getPlayers()) { i.kickPlayer("Project Closing, No other world to put you in. Rejoin Please!"); } } else { - for (Player i : Iris.proj.getActiveProject().getActiveProvider().getTarget().getWorld().getPlayers()) { + for (Player i : Iris.service(StudioSVC.class).getActiveProject().getActiveProvider().getTarget().getWorld().getPlayers()) { i.teleport(f.getSpawnLocation()); } } } - Iris.proj.close(); + Iris.service(StudioSVC.class).close(); sender.sendMessage("Projects Closed & Caches Cleared!"); return true; } diff --git a/src/main/java/com/volmit/iris/core/command/studio/CommandIrisStudioConvert.java b/src/main/java/com/volmit/iris/core/command/studio/CommandIrisStudioConvert.java index a850a94df..2eaa93f9b 100644 --- a/src/main/java/com/volmit/iris/core/command/studio/CommandIrisStudioConvert.java +++ b/src/main/java/com/volmit/iris/core/command/studio/CommandIrisStudioConvert.java @@ -20,6 +20,7 @@ package com.volmit.iris.core.command.studio; import com.volmit.iris.Iris; import com.volmit.iris.core.IrisSettings; +import com.volmit.iris.core.service.ConversionSVC; import com.volmit.iris.util.collection.KList; import com.volmit.iris.util.plugin.MortarCommand; import com.volmit.iris.util.plugin.VolmitSender; @@ -44,7 +45,7 @@ public class CommandIrisStudioConvert extends MortarCommand { return true; } - Iris.convert.check(sender); + Iris.service(ConversionSVC.class).check(sender); return true; } diff --git a/src/main/java/com/volmit/iris/core/command/studio/CommandIrisStudioCreate.java b/src/main/java/com/volmit/iris/core/command/studio/CommandIrisStudioCreate.java index 2498d17a9..d36f44a61 100644 --- a/src/main/java/com/volmit/iris/core/command/studio/CommandIrisStudioCreate.java +++ b/src/main/java/com/volmit/iris/core/command/studio/CommandIrisStudioCreate.java @@ -20,6 +20,7 @@ package com.volmit.iris.core.command.studio; import com.volmit.iris.Iris; import com.volmit.iris.core.IrisSettings; +import com.volmit.iris.core.service.StudioSVC; import com.volmit.iris.util.collection.KList; import com.volmit.iris.util.format.C; import com.volmit.iris.util.plugin.MortarCommand; @@ -60,9 +61,9 @@ public class CommandIrisStudioCreate extends MortarCommand { } if (template != null) { - Iris.proj.create(sender, args[0], template); + Iris.service(StudioSVC.class).create(sender, args[0], template); } else { - Iris.proj.create(sender, args[0]); + Iris.service(StudioSVC.class).create(sender, args[0]); } return true; diff --git a/src/main/java/com/volmit/iris/core/command/studio/CommandIrisStudioEditBiome.java b/src/main/java/com/volmit/iris/core/command/studio/CommandIrisStudioEditBiome.java index 7098b6e13..4e99af1bc 100644 --- a/src/main/java/com/volmit/iris/core/command/studio/CommandIrisStudioEditBiome.java +++ b/src/main/java/com/volmit/iris/core/command/studio/CommandIrisStudioEditBiome.java @@ -20,6 +20,7 @@ package com.volmit.iris.core.command.studio; import com.volmit.iris.Iris; import com.volmit.iris.core.IrisSettings; +import com.volmit.iris.core.service.StudioSVC; import com.volmit.iris.util.collection.KList; import com.volmit.iris.util.plugin.MortarCommand; import com.volmit.iris.util.plugin.VolmitSender; @@ -48,7 +49,7 @@ public class CommandIrisStudioEditBiome extends MortarCommand { return true; } - if (!Iris.proj.isProjectOpen()) { + if (!Iris.service(StudioSVC.class).isProjectOpen()) { sender.sendMessage("There is not a studio currently loaded."); return true; } @@ -57,7 +58,7 @@ public class CommandIrisStudioEditBiome extends MortarCommand { Player p = sender.player(); try { - File f = Iris.proj.getActiveProject().getActiveProvider().getEngine().getBiome(p.getLocation().getBlockX(), p.getLocation().getBlockY(), p.getLocation().getBlockZ()).getLoadFile(); + File f = Iris.service(StudioSVC.class).getActiveProject().getActiveProvider().getEngine().getBiome(p.getLocation().getBlockX(), p.getLocation().getBlockY(), p.getLocation().getBlockZ()).getLoadFile(); Desktop.getDesktop().open(f); } catch (Throwable e) { Iris.reportError(e); diff --git a/src/main/java/com/volmit/iris/core/command/studio/CommandIrisStudioExplorerGenerator.java b/src/main/java/com/volmit/iris/core/command/studio/CommandIrisStudioExplorerGenerator.java index cd2345d4c..e20d8b53d 100644 --- a/src/main/java/com/volmit/iris/core/command/studio/CommandIrisStudioExplorerGenerator.java +++ b/src/main/java/com/volmit/iris/core/command/studio/CommandIrisStudioExplorerGenerator.java @@ -22,6 +22,7 @@ import com.volmit.iris.Iris; import com.volmit.iris.core.IrisSettings; import com.volmit.iris.core.gui.NoiseExplorerGUI; import com.volmit.iris.core.project.loader.IrisData; +import com.volmit.iris.core.service.StudioSVC; import com.volmit.iris.core.tools.IrisToolbelt; import com.volmit.iris.engine.object.noise.IrisGenerator; import com.volmit.iris.util.collection.KList; @@ -75,9 +76,9 @@ public class CommandIrisStudioExplorerGenerator extends MortarCommand { Supplier> l = () -> { long seed = 12345; IrisGenerator generator; - if (Iris.proj.isProjectOpen()) { - generator = Iris.proj.getActiveProject().getActiveProvider().getData().getGeneratorLoader().load(args[0]); - seed = Iris.proj.getActiveProject().getActiveProvider().getTarget().getWorld().seed(); + if (Iris.service(StudioSVC.class).isProjectOpen()) { + generator = Iris.service(StudioSVC.class).getActiveProject().getActiveProvider().getData().getGeneratorLoader().load(args[0]); + seed = Iris.service(StudioSVC.class).getActiveProject().getActiveProvider().getTarget().getWorld().seed(); } else { generator = IrisData.loadAnyGenerator(args[0]); } diff --git a/src/main/java/com/volmit/iris/core/command/studio/CommandIrisStudioLoot.java b/src/main/java/com/volmit/iris/core/command/studio/CommandIrisStudioLoot.java index 24060e7f5..d0ab286f4 100644 --- a/src/main/java/com/volmit/iris/core/command/studio/CommandIrisStudioLoot.java +++ b/src/main/java/com/volmit/iris/core/command/studio/CommandIrisStudioLoot.java @@ -20,6 +20,7 @@ package com.volmit.iris.core.command.studio; import com.volmit.iris.Iris; import com.volmit.iris.core.IrisSettings; +import com.volmit.iris.core.service.StudioSVC; import com.volmit.iris.core.tools.IrisToolbelt; import com.volmit.iris.engine.framework.Engine; import com.volmit.iris.engine.object.loot.IrisLootTable; @@ -58,7 +59,7 @@ public class CommandIrisStudioLoot extends MortarCommand { Player p = sender.player(); Engine prov = IrisToolbelt.access(sender.player().getWorld()).getEngine(); - if (!Iris.proj.isProjectOpen()) { + if (!Iris.service(StudioSVC.class).isProjectOpen()) { sender.sendMessage("You can only use /iris studio loot in a studio world of iris."); return true; } @@ -67,7 +68,7 @@ public class CommandIrisStudioLoot extends MortarCommand { Inventory inv = Bukkit.createInventory(null, 27 * 2); try { - Iris.proj.getActiveProject().getActiveProvider().getEngine().addItems(true, inv, RNG.r, tables, InventorySlotType.STORAGE, p.getLocation().getBlockX(), p.getLocation().getBlockY(), p.getLocation().getBlockZ(), 1); + Iris.service(StudioSVC.class).getActiveProject().getActiveProvider().getEngine().addItems(true, inv, RNG.r, tables, InventorySlotType.STORAGE, p.getLocation().getBlockX(), p.getLocation().getBlockY(), p.getLocation().getBlockZ(), 1); } catch (Throwable e) { Iris.reportError(e); sender.sendMessage("You can only use /iris loot in a studio world of iris."); @@ -109,7 +110,7 @@ public class CommandIrisStudioLoot extends MortarCommand { inv.clear(); } - Iris.proj.getActiveProject().getActiveProvider().getEngine().addItems(true, inv, new RNG(RNG.r.imax()), tables, InventorySlotType.STORAGE, p.getLocation().getBlockX(), p.getLocation().getBlockY(), p.getLocation().getBlockZ(), 1); + Iris.service(StudioSVC.class).getActiveProject().getActiveProvider().getEngine().addItems(true, inv, new RNG(RNG.r.imax()), tables, InventorySlotType.STORAGE, p.getLocation().getBlockX(), p.getLocation().getBlockY(), p.getLocation().getBlockZ(), 1); }, 0, fast ? 5 : 35)); return true; diff --git a/src/main/java/com/volmit/iris/core/command/studio/CommandIrisStudioMap.java b/src/main/java/com/volmit/iris/core/command/studio/CommandIrisStudioMap.java index 448850c22..90e5a7af4 100644 --- a/src/main/java/com/volmit/iris/core/command/studio/CommandIrisStudioMap.java +++ b/src/main/java/com/volmit/iris/core/command/studio/CommandIrisStudioMap.java @@ -21,6 +21,7 @@ package com.volmit.iris.core.command.studio; import com.volmit.iris.Iris; import com.volmit.iris.core.IrisSettings; import com.volmit.iris.core.gui.VisionGUI; +import com.volmit.iris.core.service.StudioSVC; import com.volmit.iris.core.tools.IrisToolbelt; import com.volmit.iris.engine.framework.Engine; import com.volmit.iris.util.collection.KList; @@ -55,7 +56,7 @@ public class CommandIrisStudioMap extends MortarCommand { Engine fe; try { - Engine g = Iris.proj.getActiveProject().getActiveProvider().getEngine(); + Engine g = Iris.service(StudioSVC.class).getActiveProject().getActiveProvider().getEngine(); VisionGUI.launch(g, 0); sender.sendMessage("Opening Map!"); } catch (Throwable e) { diff --git a/src/main/java/com/volmit/iris/core/command/studio/CommandIrisStudioOpen.java b/src/main/java/com/volmit/iris/core/command/studio/CommandIrisStudioOpen.java index a7067fbce..6eb019e51 100644 --- a/src/main/java/com/volmit/iris/core/command/studio/CommandIrisStudioOpen.java +++ b/src/main/java/com/volmit/iris/core/command/studio/CommandIrisStudioOpen.java @@ -20,6 +20,7 @@ package com.volmit.iris.core.command.studio; import com.volmit.iris.Iris; import com.volmit.iris.core.IrisSettings; +import com.volmit.iris.core.service.StudioSVC; import com.volmit.iris.util.collection.KList; import com.volmit.iris.util.plugin.MortarCommand; import com.volmit.iris.util.plugin.VolmitSender; @@ -50,7 +51,7 @@ public class CommandIrisStudioOpen extends MortarCommand { } sender.sendMessage("Opening studio world..."); - Iris.proj.open(sender, args[0]); + Iris.service(StudioSVC.class).open(sender, args[0]); return true; } diff --git a/src/main/java/com/volmit/iris/core/command/studio/CommandIrisStudioPackage.java b/src/main/java/com/volmit/iris/core/command/studio/CommandIrisStudioPackage.java index 5d222f2bd..f725a2b47 100644 --- a/src/main/java/com/volmit/iris/core/command/studio/CommandIrisStudioPackage.java +++ b/src/main/java/com/volmit/iris/core/command/studio/CommandIrisStudioPackage.java @@ -20,6 +20,7 @@ package com.volmit.iris.core.command.studio; import com.volmit.iris.Iris; import com.volmit.iris.core.IrisSettings; +import com.volmit.iris.core.service.StudioSVC; import com.volmit.iris.util.collection.KList; import com.volmit.iris.util.plugin.MortarCommand; import com.volmit.iris.util.plugin.VolmitSender; @@ -63,7 +64,7 @@ public class CommandIrisStudioPackage extends MortarCommand { } String dim = args[0]; - Iris.proj.compilePackage(sender, dim, o, m); + Iris.service(StudioSVC.class).compilePackage(sender, dim, o, m); }); return true; diff --git a/src/main/java/com/volmit/iris/core/command/studio/CommandIrisStudioProfile.java b/src/main/java/com/volmit/iris/core/command/studio/CommandIrisStudioProfile.java index 65e3cbe5c..609ecf599 100644 --- a/src/main/java/com/volmit/iris/core/command/studio/CommandIrisStudioProfile.java +++ b/src/main/java/com/volmit/iris/core/command/studio/CommandIrisStudioProfile.java @@ -22,6 +22,7 @@ import com.volmit.iris.Iris; import com.volmit.iris.core.IrisSettings; import com.volmit.iris.core.project.IrisProject; import com.volmit.iris.core.project.loader.IrisData; +import com.volmit.iris.core.service.StudioSVC; import com.volmit.iris.engine.object.biome.IrisBiome; import com.volmit.iris.engine.object.biome.IrisBiomePaletteLayer; import com.volmit.iris.engine.object.noise.IrisGenerator; @@ -70,12 +71,12 @@ public class CommandIrisStudioProfile extends MortarCommand { File report = Iris.instance.getDataFile("profile.txt"); KList v = new KList<>(); if (args.length == 0) { - if (!Iris.proj.isProjectOpen()) { + if (!Iris.service(StudioSVC.class).isProjectOpen()) { sender.sendMessage("No open project. Either use /iris std beautify or have a project open."); return; } - f = Iris.proj.getActiveProject().getPath(); + f = Iris.service(StudioSVC.class).getActiveProject().getPath(); } else { f = Iris.instance.getDataFolder("packs", args[0]); diff --git a/src/main/java/com/volmit/iris/core/command/studio/CommandIrisStudioTPStudio.java b/src/main/java/com/volmit/iris/core/command/studio/CommandIrisStudioTPStudio.java index f34d11cdc..b4a351cc4 100644 --- a/src/main/java/com/volmit/iris/core/command/studio/CommandIrisStudioTPStudio.java +++ b/src/main/java/com/volmit/iris/core/command/studio/CommandIrisStudioTPStudio.java @@ -20,6 +20,7 @@ package com.volmit.iris.core.command.studio; import com.volmit.iris.Iris; import com.volmit.iris.core.IrisSettings; +import com.volmit.iris.core.service.StudioSVC; import com.volmit.iris.util.collection.KList; import com.volmit.iris.util.plugin.MortarCommand; import com.volmit.iris.util.plugin.VolmitSender; @@ -50,14 +51,14 @@ public class CommandIrisStudioTPStudio extends MortarCommand { return true; } - if (!Iris.proj.isProjectOpen()) { + if (!Iris.service(StudioSVC.class).isProjectOpen()) { sender.sendMessage("There is not a studio currently loaded."); return true; } try { sender.sendMessage("Teleporting you to the active studio world."); - sender.player().teleport(Iris.proj.getActiveProject().getActiveProvider().getTarget().getWorld().spawnLocation()); + sender.player().teleport(Iris.service(StudioSVC.class).getActiveProject().getActiveProvider().getTarget().getWorld().spawnLocation()); sender.player().setGameMode(GameMode.SPECTATOR); } catch (Throwable e) { Iris.reportError(e); diff --git a/src/main/java/com/volmit/iris/core/command/studio/CommandIrisStudioUpdate.java b/src/main/java/com/volmit/iris/core/command/studio/CommandIrisStudioUpdate.java index 6890d8082..e8cfb22e9 100644 --- a/src/main/java/com/volmit/iris/core/command/studio/CommandIrisStudioUpdate.java +++ b/src/main/java/com/volmit/iris/core/command/studio/CommandIrisStudioUpdate.java @@ -22,6 +22,7 @@ import com.volmit.iris.Iris; import com.volmit.iris.core.IrisSettings; import com.volmit.iris.core.project.IrisProject; import com.volmit.iris.core.project.loader.IrisData; +import com.volmit.iris.core.service.StudioSVC; import com.volmit.iris.engine.object.objects.IrisObject; import com.volmit.iris.util.collection.KList; import com.volmit.iris.util.format.Form; @@ -62,7 +63,7 @@ public class CommandIrisStudioUpdate extends MortarCommand { for (String i : args) { if (i.equals("--rewrite-objects")) { - IrisData data = new IrisData(Iris.proj.getWorkspaceFolder(args[0])); + IrisData data = new IrisData(Iris.service(StudioSVC.class).getWorkspaceFolder(args[0])); int t = data.getObjectLoader().getPossibleKeys().length; ChronoLatch cl = new ChronoLatch(250, false); MultiBurst bx = new MultiBurst("Object Rewriter", Thread.MIN_PRIORITY, Runtime.getRuntime().availableProcessors()); @@ -107,7 +108,7 @@ public class CommandIrisStudioUpdate extends MortarCommand { } } - if (new IrisProject(Iris.proj.getWorkspaceFolder(args[0])).updateWorkspace()) { + if (new IrisProject(Iris.service(StudioSVC.class).getWorkspaceFolder(args[0])).updateWorkspace()) { sender.sendMessage("Updated Code Workspace for " + args[0]); } else { sender.sendMessage("Invalid project: " + args[0] + ". Try deleting the code-workspace file and try again."); diff --git a/src/main/java/com/volmit/iris/core/command/world/CommandIrisUpdateWorld.java b/src/main/java/com/volmit/iris/core/command/world/CommandIrisUpdateWorld.java index 24b2ee5fd..f63318aa3 100644 --- a/src/main/java/com/volmit/iris/core/command/world/CommandIrisUpdateWorld.java +++ b/src/main/java/com/volmit/iris/core/command/world/CommandIrisUpdateWorld.java @@ -19,6 +19,7 @@ package com.volmit.iris.core.command.world; import com.volmit.iris.Iris; +import com.volmit.iris.core.service.StudioSVC; import com.volmit.iris.util.collection.KList; import com.volmit.iris.util.format.C; import com.volmit.iris.util.plugin.MortarCommand; @@ -64,10 +65,10 @@ public class CommandIrisUpdateWorld extends MortarCommand { folder.mkdirs(); if (bfre) { - Iris.proj.downloadSearch(sender, args[1], false, true); + Iris.service(StudioSVC.class).downloadSearch(sender, args[1], false, true); } - Iris.proj.installIntoWorld(sender, args[1], folder); + Iris.service(StudioSVC.class).installIntoWorld(sender, args[1], folder); }); return true; diff --git a/src/main/java/com/volmit/iris/core/command/world/CommandLocate.java b/src/main/java/com/volmit/iris/core/command/world/CommandLocate.java index e88d436d4..ac8a59636 100644 --- a/src/main/java/com/volmit/iris/core/command/world/CommandLocate.java +++ b/src/main/java/com/volmit/iris/core/command/world/CommandLocate.java @@ -51,6 +51,7 @@ public class CommandLocate extends MortarCommand implements Listener { public CommandLocate() { super("locate"); requiresPermission(Iris.perm); + Iris.instance.registerListener(this); } @Override diff --git a/src/main/java/com/volmit/iris/core/decrees/DecIris.java b/src/main/java/com/volmit/iris/core/decrees/DecIris.java index e147490d9..a2a1c0538 100644 --- a/src/main/java/com/volmit/iris/core/decrees/DecIris.java +++ b/src/main/java/com/volmit/iris/core/decrees/DecIris.java @@ -20,6 +20,7 @@ package com.volmit.iris.core.decrees; import com.volmit.iris.Iris; import com.volmit.iris.core.IrisSettings; +import com.volmit.iris.core.service.StudioSVC; import com.volmit.iris.core.tools.IrisToolbelt; import com.volmit.iris.engine.object.dimensional.IrisDimension; import com.volmit.iris.util.decree.DecreeExecutor; @@ -141,7 +142,7 @@ public class DecIris implements DecreeExecutor boolean overwrite ) { sender().sendMessage(C.GREEN + "Downloading pack: " + pack + "/" + branch + (trim ? " trimmed" : "")); - Iris.proj.downloadSearch(sender(), "IrisDimensions/" + pack + "/" + branch, trim, overwrite); + Iris.service(StudioSVC.class).downloadSearch(sender(), "IrisDimensions/" + pack + "/" + branch, trim, overwrite); } @Decree(description = "Get metrics for your world", aliases = "measure", origin = DecreeOrigin.PLAYER) diff --git a/src/main/java/com/volmit/iris/core/decrees/DecStudio.java b/src/main/java/com/volmit/iris/core/decrees/DecStudio.java index 4682ae5e1..84fe3d224 100644 --- a/src/main/java/com/volmit/iris/core/decrees/DecStudio.java +++ b/src/main/java/com/volmit/iris/core/decrees/DecStudio.java @@ -24,6 +24,8 @@ import com.volmit.iris.core.gui.NoiseExplorerGUI; import com.volmit.iris.core.gui.VisionGUI; import com.volmit.iris.core.project.IrisProject; import com.volmit.iris.core.project.loader.IrisData; +import com.volmit.iris.core.service.ConversionSVC; +import com.volmit.iris.core.service.StudioSVC; import com.volmit.iris.core.tools.IrisToolbelt; import com.volmit.iris.engine.object.basic.IrisPosition; import com.volmit.iris.engine.object.biome.IrisBiome; @@ -89,17 +91,17 @@ public class DecStudio implements DecreeExecutor { @Param(defaultValue = "1337", description = "The seed to generate the studio with", aliases = "s") long seed) { sender().sendMessage(C.GREEN + "Opening studio for the \"" + dimension.getName() + "\" pack (seed: " + seed + ")"); - Iris.proj.open(sender(), seed, dimension.getLoadKey()); + Iris.service(StudioSVC.class).open(sender(), seed, dimension.getLoadKey()); } @Decree(description = "Close an open studio project", aliases = "x", sync = true) public void close() { - if (!Iris.proj.isProjectOpen()) { + if (!Iris.service(StudioSVC.class).isProjectOpen()) { sender().sendMessage(C.RED + "No open studio projects."); return; } - Iris.proj.close(); + Iris.service(StudioSVC.class).close(); sender().sendMessage(C.GREEN + "Project Closed."); } @@ -111,9 +113,9 @@ public class DecStudio implements DecreeExecutor { IrisDimension template) { if (template != null) { - Iris.proj.create(sender(), name, template.getLoadKey()); + Iris.service(StudioSVC.class).create(sender(), name, template.getLoadKey()); } else { - Iris.proj.create(sender(), name); + Iris.service(StudioSVC.class).create(sender(), name); } } @@ -137,7 +139,7 @@ public class DecStudio implements DecreeExecutor { MultiBurst burst = new MultiBurst("Cleaner", Thread.MIN_PRIORITY, Runtime.getRuntime().availableProcessors() * 2); jobs.add(new SingleJob("Updating Workspace", () -> { - if (!new IrisProject(Iris.proj.getWorkspaceFolder(project.getLoadKey())).updateWorkspace()) { + if (!new IrisProject(Iris.service(StudioSVC.class).getWorkspaceFolder(project.getLoadKey())).updateWorkspace()) { sender().sendMessage(C.GOLD + "Invalid project: " + project.getLoadKey() + ". Try deleting the code-workspace file and try again."); } J.sleep(250); @@ -210,7 +212,7 @@ public class DecStudio implements DecreeExecutor { } }; - IrisData data = new IrisData(Iris.proj.getWorkspaceFolder(project.getLoadKey())); + IrisData data = new IrisData(Iris.service(StudioSVC.class).getWorkspaceFolder(project.getLoadKey())); for (String f : data.getObjectLoader().getPossibleKeys()) { CompletableFuture gg = burst.complete(() ->{ File ff = data.getObjectLoader().findFile(f); @@ -256,7 +258,7 @@ public class DecStudio implements DecreeExecutor { @Decree(description = "Convert objects in the \"convert\" folder") public void convert() { - Iris.convert.check(sender()); + Iris.service(ConversionSVC.class).check(sender()); } @@ -431,7 +433,7 @@ public class DecStudio implements DecreeExecutor { @Param(name = "minify", description = "Whether or not to minify the pack", defaultValue = "true") boolean minify ){ - Iris.proj.compilePackage(sender(), dimension.getLoadKey(), obfuscate, minify); + Iris.service(StudioSVC.class).compilePackage(sender(), dimension.getLoadKey(), obfuscate, minify); } @Decree(description = "Profiles the performance of a dimension", origin = DecreeOrigin.PLAYER) @@ -641,7 +643,7 @@ public class DecStudio implements DecreeExecutor { @Decree(description = "Teleport to the active studio world", aliases = "stp", origin = DecreeOrigin.PLAYER, sync = true) public void tpstudio(){ - if (!Iris.proj.isProjectOpen()){ + if (!Iris.service(StudioSVC.class).isProjectOpen()){ sender().sendMessage(C.RED + "No studio world is open!"); return; } @@ -652,7 +654,7 @@ public class DecStudio implements DecreeExecutor { } sender().sendMessage(C.GREEN + "Sending you to the studio world!"); - player().teleport(Iris.proj.getActiveProject().getActiveProvider().getTarget().getWorld().spawnLocation()); + player().teleport(Iris.service(StudioSVC.class).getActiveProject().getActiveProvider().getTarget().getWorld().spawnLocation()); player().setGameMode(GameMode.SPECTATOR); } @@ -773,7 +775,7 @@ public class DecStudio implements DecreeExecutor { sender().sendMessage(C.RED + "Players only (this is a config error. Ask support to add DecreeOrigin.PLAYER to the command you tried to run)"); return true; } - if (!Iris.proj.isProjectOpen()){ + if (!Iris.service(StudioSVC.class).isProjectOpen()){ sender().sendMessage(C.RED + "No studio world is open!"); return true; } diff --git a/src/main/java/com/volmit/iris/core/edit/JigsawEditor.java b/src/main/java/com/volmit/iris/core/edit/JigsawEditor.java index bcd639bb4..5a38b74c6 100644 --- a/src/main/java/com/volmit/iris/core/edit/JigsawEditor.java +++ b/src/main/java/com/volmit/iris/core/edit/JigsawEditor.java @@ -20,6 +20,7 @@ package com.volmit.iris.core.edit; import com.google.gson.Gson; import com.volmit.iris.Iris; +import com.volmit.iris.core.service.WandSVC; import com.volmit.iris.engine.object.basic.IrisPosition; import com.volmit.iris.engine.object.jigsaw.IrisJigsawPiece; import com.volmit.iris.engine.object.jigsaw.IrisJigsawPieceConnector; @@ -168,7 +169,7 @@ public class JigsawEditor implements Listener { public void onTick() { if (cl.flip()) { - Iris.wand.draw(cuboid, player); + Iris.service(WandSVC.class).draw(cuboid, player); f: for (IrisPosition i : falling.k()) { diff --git a/src/main/java/com/volmit/iris/core/CoreBoardManager.java b/src/main/java/com/volmit/iris/core/service/BoardSVC.java similarity index 92% rename from src/main/java/com/volmit/iris/core/CoreBoardManager.java rename to src/main/java/com/volmit/iris/core/service/BoardSVC.java index 827e294ac..4206f6266 100644 --- a/src/main/java/com/volmit/iris/core/CoreBoardManager.java +++ b/src/main/java/com/volmit/iris/core/service/BoardSVC.java @@ -16,7 +16,7 @@ * along with this program. If not, see . */ -package com.volmit.iris.core; +package com.volmit.iris.core.service; import com.volmit.iris.Iris; import com.volmit.iris.core.tools.IrisToolbelt; @@ -29,6 +29,7 @@ import com.volmit.iris.util.collection.KList; import com.volmit.iris.util.format.C; import com.volmit.iris.util.format.Form; import com.volmit.iris.util.math.RollingSequence; +import com.volmit.iris.util.plugin.IrisService; import com.volmit.iris.util.scheduling.ChronoLatch; import com.volmit.iris.util.scheduling.J; import org.bukkit.Bukkit; @@ -38,30 +39,31 @@ import org.bukkit.boss.BarStyle; import org.bukkit.boss.BossBar; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; -import org.bukkit.event.Listener; import org.bukkit.event.player.PlayerChangedWorldEvent; import java.util.List; -public class CoreBoardManager implements BoardProvider, Listener { - - private final BossBar energyBar; - private final com.volmit.iris.util.board.BoardManager manager; +public class BoardSVC implements IrisService, BoardProvider { + private BossBar energyBar; + private com.volmit.iris.util.board.BoardManager manager; private String mem = "..."; - public final RollingSequence hits = new RollingSequence(20); public final RollingSequence tp = new RollingSequence(100); private final ChronoLatch cl = new ChronoLatch(1000); private final ChronoLatch ecl = new ChronoLatch(50); - public CoreBoardManager() { - Iris.instance.registerListener(this); - //@builder + @Override + public void onEnable() { manager = new com.volmit.iris.util.board.BoardManager(Iris.instance, BoardSettings.builder() .boardProvider(this) .scoreDirection(ScoreDirection.DOWN) .build()); energyBar = Bukkit.createBossBar("Spawner Energy " + 0, BarColor.BLUE, BarStyle.SOLID); - //@done + } + + @Override + public void onDisable() { + manager.onDisable(); + energyBar.removeAll(); } @EventHandler @@ -69,7 +71,6 @@ public class CoreBoardManager implements BoardProvider, Listener { J.s(() -> updatePlayer(e.getPlayer())); } - private boolean isIrisWorld(World w) { return IrisToolbelt.isIrisWorld(w) && IrisToolbelt.access(w).isStudio(); } @@ -154,10 +155,4 @@ public class CoreBoardManager implements BoardProvider, Listener { return v; } - - - public void disable() { - manager.onDisable(); - energyBar.removeAll(); - } } diff --git a/src/main/java/com/volmit/iris/core/CommandManager.java b/src/main/java/com/volmit/iris/core/service/CommandSVC.java similarity index 87% rename from src/main/java/com/volmit/iris/core/CommandManager.java rename to src/main/java/com/volmit/iris/core/service/CommandSVC.java index 4c59f5df1..13c636d03 100644 --- a/src/main/java/com/volmit/iris/core/CommandManager.java +++ b/src/main/java/com/volmit/iris/core/service/CommandSVC.java @@ -16,7 +16,7 @@ * along with this program. If not, see . */ -package com.volmit.iris.core; +package com.volmit.iris.core.service; import com.volmit.iris.Iris; import com.volmit.iris.core.decrees.DecIris; @@ -24,15 +24,22 @@ import com.volmit.iris.engine.data.cache.AtomicCache; import com.volmit.iris.util.collection.KList; import com.volmit.iris.util.decree.DecreeSystem; import com.volmit.iris.util.decree.virtual.VirtualDecreeCommand; +import com.volmit.iris.util.plugin.IrisService; -public class CommandManager implements DecreeSystem { - private final transient AtomicCache commandCache = new AtomicCache<>(); - private final transient AtomicCache> startsCache = new AtomicCache<>(); - - public CommandManager(){ +public class CommandSVC implements IrisService, DecreeSystem { + @Override + public void onEnable() { Iris.instance.getCommand("irisd").setExecutor(this); } + @Override + public void onDisable() { + + } + + private final transient AtomicCache commandCache = new AtomicCache<>(); + private final transient AtomicCache> startsCache = new AtomicCache<>(); + @Override public VirtualDecreeCommand getRoot() { return commandCache.aquire(() -> { diff --git a/src/main/java/com/volmit/iris/core/ConversionManager.java b/src/main/java/com/volmit/iris/core/service/ConversionSVC.java similarity index 97% rename from src/main/java/com/volmit/iris/core/ConversionManager.java rename to src/main/java/com/volmit/iris/core/service/ConversionSVC.java index c24f2adc2..95c99aa95 100644 --- a/src/main/java/com/volmit/iris/core/ConversionManager.java +++ b/src/main/java/com/volmit/iris/core/service/ConversionSVC.java @@ -16,7 +16,7 @@ * along with this program. If not, see . */ -package com.volmit.iris.core; +package com.volmit.iris.core.service; import com.google.gson.Gson; import com.volmit.iris.Iris; @@ -39,6 +39,7 @@ import com.volmit.iris.util.nbt.mca.NBTWorld; import com.volmit.iris.util.nbt.tag.CompoundTag; import com.volmit.iris.util.nbt.tag.IntTag; import com.volmit.iris.util.nbt.tag.ListTag; +import com.volmit.iris.util.plugin.IrisService; import com.volmit.iris.util.plugin.VolmitSender; import com.volmit.iris.util.scheduling.J; import org.bukkit.Material; @@ -49,11 +50,9 @@ import java.io.File; import java.io.IOException; import java.util.concurrent.atomic.AtomicInteger; -public class ConversionManager { - private final KList converters; - private final File folder; - - public ConversionManager() { +public class ConversionSVC implements IrisService { + @Override + public void onEnable() { folder = Iris.instance.getDataFolder("convert"); converters = new KList<>(); @@ -64,6 +63,14 @@ public class ConversionManager { }), 5); } + @Override + public void onDisable() { + + } + + private KList converters; + private File folder; + private String toPoolName(String poolReference) { return poolReference.split("\\Q:\\E")[1]; } diff --git a/src/main/java/com/volmit/iris/core/service/DolphinSVC.java b/src/main/java/com/volmit/iris/core/service/DolphinSVC.java new file mode 100644 index 000000000..0135673fa --- /dev/null +++ b/src/main/java/com/volmit/iris/core/service/DolphinSVC.java @@ -0,0 +1,54 @@ +/* + * Iris is a World Generator for Minecraft Bukkit Servers + * Copyright (c) 2021 Arcane Arts (Volmit Software) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package com.volmit.iris.core.service; + +import com.volmit.iris.core.tools.IrisToolbelt; +import com.volmit.iris.util.plugin.IrisService; +import org.bukkit.Material; +import org.bukkit.entity.EntityType; +import org.bukkit.event.EventHandler; +import org.bukkit.event.player.PlayerInteractEntityEvent; + +public class DolphinSVC implements IrisService { + @Override + public void onEnable() { + + } + + @Override + public void onDisable() { + + } + + /** + * Prevents dolphins from being fed, to locate a treasure map. + * Note: This results in odd dolphin behaviour, but it's the best we can do. + */ + @EventHandler + public void on(PlayerInteractEntityEvent event) { + if (!IrisToolbelt.isIrisWorld(event.getPlayer().getWorld())) { + return; + } + + Material hand = event.getPlayer().getInventory().getItem(event.getHand()).getType(); + if (event.getRightClicked().getType().equals(EntityType.DOLPHIN) && (hand.equals(Material.TROPICAL_FISH) || hand.equals(Material.PUFFERFISH) || hand.equals(Material.COD) || hand.equals(Material.SALMON))) { + event.setCancelled(true); + } + } +} diff --git a/src/main/java/com/volmit/iris/core/EditManager.java b/src/main/java/com/volmit/iris/core/service/EditSVC.java similarity index 86% rename from src/main/java/com/volmit/iris/core/EditManager.java rename to src/main/java/com/volmit/iris/core/service/EditSVC.java index 8abb24ce1..ce7ce1be5 100644 --- a/src/main/java/com/volmit/iris/core/EditManager.java +++ b/src/main/java/com/volmit/iris/core/service/EditSVC.java @@ -16,28 +16,34 @@ * along with this program. If not, see . */ -package com.volmit.iris.core; +package com.volmit.iris.core.service; import com.volmit.iris.Iris; import com.volmit.iris.core.edit.BlockEditor; import com.volmit.iris.core.edit.BukkitBlockEditor; import com.volmit.iris.util.collection.KMap; import com.volmit.iris.util.math.M; +import com.volmit.iris.util.plugin.IrisService; import org.bukkit.Bukkit; import org.bukkit.World; import org.bukkit.block.Biome; import org.bukkit.block.data.BlockData; import org.bukkit.event.EventHandler; -import org.bukkit.event.Listener; import org.bukkit.event.world.WorldUnloadEvent; -public class EditManager implements Listener { - private final KMap editors; +public class EditSVC implements IrisService { + private KMap editors; - public EditManager() { + @Override + public void onEnable() { this.editors = new KMap<>(); - Iris.instance.registerListener(this); - Bukkit.getScheduler().scheduleSyncRepeatingTask(Iris.instance, this::update, 0, 0); + Iris.info("EDIT SVC ENABLED!"); + Bukkit.getScheduler().scheduleSyncRepeatingTask(Iris.instance, this::update, 1000, 1000); + } + + @Override + public void onDisable() { + flushNow(); } public BlockData get(World world, int x, int y, int z) { @@ -90,11 +96,10 @@ public class EditManager implements Listener { return editors.get(world); } - BlockEditor e = null; - e = new BukkitBlockEditor(world); - + BlockEditor e = new BukkitBlockEditor(world); editors.put(world, e); return e; } + } diff --git a/src/main/java/com/volmit/iris/core/ProjectManager.java b/src/main/java/com/volmit/iris/core/service/StudioSVC.java similarity index 90% rename from src/main/java/com/volmit/iris/core/ProjectManager.java rename to src/main/java/com/volmit/iris/core/service/StudioSVC.java index 9e7a9130a..719c1a50d 100644 --- a/src/main/java/com/volmit/iris/core/ProjectManager.java +++ b/src/main/java/com/volmit/iris/core/service/StudioSVC.java @@ -16,13 +16,15 @@ * along with this program. If not, see . */ -package com.volmit.iris.core; +package com.volmit.iris.core.service; import com.google.gson.Gson; import com.google.gson.JsonSyntaxException; import com.volmit.iris.Iris; +import com.volmit.iris.core.IrisSettings; import com.volmit.iris.core.project.IrisProject; import com.volmit.iris.core.project.loader.IrisData; +import com.volmit.iris.core.tools.IrisToolbelt; import com.volmit.iris.engine.data.cache.AtomicCache; import com.volmit.iris.engine.object.dimensional.IrisDimension; import com.volmit.iris.util.collection.KMap; @@ -31,9 +33,12 @@ import com.volmit.iris.util.format.Form; import com.volmit.iris.util.io.IO; import com.volmit.iris.util.json.JSONException; import com.volmit.iris.util.json.JSONObject; +import com.volmit.iris.util.plugin.IrisService; import com.volmit.iris.util.plugin.VolmitSender; +import com.volmit.iris.util.scheduling.GroupedExecutor; import com.volmit.iris.util.scheduling.J; -import lombok.Data; +import org.bukkit.Bukkit; +import org.bukkit.World; import org.zeroturnaround.zip.ZipUtil; import org.zeroturnaround.zip.commons.FileUtils; @@ -41,57 +46,46 @@ import java.io.File; import java.io.IOException; import java.util.UUID; -@Data -public class ProjectManager { +public class StudioSVC implements IrisService { public static final String LISTING = "https://raw.githubusercontent.com/IrisDimensions/_listing/main/listing-v2.json"; public static final String WORKSPACE_NAME = "packs"; private KMap cacheListing = null; private IrisProject activeProject; private static final AtomicCache counter = new AtomicCache<>(); - public ProjectManager() { - if (IrisSettings.get().isStudio()) { - J.a(() -> - { - File ignore = getWorkspaceFile(".gitignore"); + @Override + public void onEnable() { + J.a(() -> + { + File ignore = getWorkspaceFile(".gitignore"); - if (!ignore.exists()) { - File m = Iris.getCached("Pack Ignore (.gitignore)", "https://raw.githubusercontent.com/VolmitSoftware/Iris/master/packignore.ignore"); - if (m != null) { - try { - IO.copyFile(m, ignore); - } catch (IOException e) { - Iris.reportError(e); - } - } - } - }); - } - } - - public static int countUniqueDimensions() { - - return counter.aquire(() -> { - int v = 0; - - try { - for (File i : Iris.instance.getDataFolder(WORKSPACE_NAME).listFiles()) { + if (!ignore.exists()) { + File m = Iris.getCached("Pack Ignore (.gitignore)", "https://raw.githubusercontent.com/VolmitSoftware/Iris/master/packignore.ignore"); + if (m != null) { try { - if (i.isDirectory() && i.list().length > 0 && !Iris.proj.getListing(true).containsKey(i.getName())) { - v++; - } - } catch (Throwable e) { + IO.copyFile(m, ignore); + } catch (IOException e) { Iris.reportError(e); } } - } catch (Throwable e) { - Iris.reportError(e); } - - return v; }); } + @Override + public void onDisable() { + if (IrisSettings.get().isStudio()) { + Iris.debug("Studio Mode Active: Closing Projects"); + + for (World i : Bukkit.getWorlds()) { + if (IrisToolbelt.isIrisWorld(i)) { + Iris.debug("Closing Platform Generator " + i.getName()); + IrisToolbelt.access(i).close(); + } + } + } + } + public IrisDimension installIntoWorld(VolmitSender sender, String type, File folder) { sender.sendMessage("Looking for Package: " + type); File iris = new File(folder, "iris"); @@ -99,15 +93,15 @@ public class ProjectManager { IrisDimension dim = IrisData.loadAnyDimension(type); if (dim == null) { - for (File i : Iris.proj.getWorkspaceFolder().listFiles()) { + for (File i : getWorkspaceFolder().listFiles()) { if (i.isFile() && i.getName().equals(type + ".iris")) { - sender.sendMessage("Found " + type + ".iris in " + ProjectManager.WORKSPACE_NAME + " folder"); + sender.sendMessage("Found " + type + ".iris in " + WORKSPACE_NAME + " folder"); ZipUtil.unpack(i, irispack); break; } } } else { - sender.sendMessage("Found " + type + " dimension in " + ProjectManager.WORKSPACE_NAME + " folder. Repackaging"); + sender.sendMessage("Found " + type + " dimension in " + WORKSPACE_NAME + " folder. Repackaging"); File f = new IrisProject(new File(getWorkspaceFolder(), type)).getPath(); try { @@ -120,8 +114,8 @@ public class ProjectManager { File dimf = new File(irispack, "dimensions/" + type + ".json"); if (!dimf.exists() || !dimf.isFile()) { - Iris.proj.downloadSearch(sender, type, false); - File downloaded = Iris.proj.getWorkspaceFolder(type); + downloadSearch(sender, type, false); + File downloaded = getWorkspaceFolder(type); for (File i : downloaded.listFiles()) { if (i.isFile()) { @@ -454,9 +448,14 @@ public class ProjectManager { create(sender, s, "example"); } + public IrisProject getActiveProject() + { + return activeProject; + } + public void updateWorkspace() { if (isProjectOpen()) { activeProject.updateWorkspace(); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/volmit/iris/core/TreeManager.java b/src/main/java/com/volmit/iris/core/service/TreeSVC.java similarity index 98% rename from src/main/java/com/volmit/iris/core/TreeManager.java rename to src/main/java/com/volmit/iris/core/service/TreeSVC.java index 2cf1b0a2d..3af45a961 100644 --- a/src/main/java/com/volmit/iris/core/TreeManager.java +++ b/src/main/java/com/volmit/iris/core/service/TreeSVC.java @@ -16,7 +16,7 @@ * along with this program. If not, see . */ -package com.volmit.iris.core; +package com.volmit.iris.core.service; import com.volmit.iris.Iris; import com.volmit.iris.core.project.loader.IrisData; @@ -35,6 +35,7 @@ import com.volmit.iris.util.collection.KMap; import com.volmit.iris.util.data.Cuboid; import com.volmit.iris.util.math.BlockPosition; import com.volmit.iris.util.math.RNG; +import com.volmit.iris.util.plugin.IrisService; import com.volmit.iris.util.scheduling.J; import org.bukkit.*; import org.bukkit.block.Block; @@ -44,19 +45,23 @@ import org.bukkit.block.data.BlockData; import org.bukkit.block.data.type.Sapling; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; -import org.bukkit.event.Listener; import org.bukkit.event.world.StructureGrowEvent; import java.util.List; import java.util.Objects; import java.util.function.Predicate; -public class TreeManager implements Listener { - +public class TreeSVC implements IrisService { private boolean block = false; - public TreeManager() { - Iris.instance.registerListener(this); + @Override + public void onEnable() { + + } + + @Override + public void onDisable() { + } /** diff --git a/src/main/java/com/volmit/iris/core/VillagerManager.java b/src/main/java/com/volmit/iris/core/service/VillageSVC.java similarity index 63% rename from src/main/java/com/volmit/iris/core/VillagerManager.java rename to src/main/java/com/volmit/iris/core/service/VillageSVC.java index 706d30629..a8652bcda 100644 --- a/src/main/java/com/volmit/iris/core/VillagerManager.java +++ b/src/main/java/com/volmit/iris/core/service/VillageSVC.java @@ -1,15 +1,43 @@ -package com.volmit.iris.core; +/* + * Iris is a World Generator for Minecraft Bukkit Servers + * Copyright (c) 2021 Arcane Arts (Volmit Software) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package com.volmit.iris.core.service; import com.volmit.iris.Iris; import com.volmit.iris.core.tools.IrisToolbelt; import com.volmit.iris.engine.object.villager.IrisVillagerOverride; import com.volmit.iris.engine.object.villager.IrisVillagerTrade; +import com.volmit.iris.util.plugin.IrisService; import org.bukkit.Material; import org.bukkit.event.EventHandler; -import org.bukkit.event.Listener; import org.bukkit.event.entity.VillagerAcquireTradeEvent; -public class VillagerManager implements Listener { +public class VillageSVC implements IrisService { + @Override + public void onEnable() { + + } + + @Override + public void onDisable() { + + } + /** * Replace or disable villager trade add event to prevent explorer map */ diff --git a/src/main/java/com/volmit/iris/core/WandManager.java b/src/main/java/com/volmit/iris/core/service/WandSVC.java similarity index 98% rename from src/main/java/com/volmit/iris/core/WandManager.java rename to src/main/java/com/volmit/iris/core/service/WandSVC.java index 7f365f752..0df9a1989 100644 --- a/src/main/java/com/volmit/iris/core/WandManager.java +++ b/src/main/java/com/volmit/iris/core/service/WandSVC.java @@ -16,7 +16,7 @@ * along with this program. If not, see . */ -package com.volmit.iris.core; +package com.volmit.iris.core.service; import com.volmit.iris.Iris; import com.volmit.iris.core.edit.DustRevealer; @@ -28,6 +28,7 @@ import com.volmit.iris.util.format.C; import com.volmit.iris.util.math.M; import com.volmit.iris.util.matter.Matter; import com.volmit.iris.util.matter.WorldMatter; +import com.volmit.iris.util.plugin.IrisService; import com.volmit.iris.util.plugin.VolmitSender; import com.volmit.iris.util.scheduling.J; import org.bukkit.*; @@ -35,7 +36,6 @@ import org.bukkit.block.Block; import org.bukkit.enchantments.Enchantment; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; -import org.bukkit.event.Listener; import org.bukkit.event.block.Action; import org.bukkit.event.player.PlayerInteractEvent; import org.bukkit.inventory.Inventory; @@ -45,16 +45,17 @@ import org.bukkit.inventory.meta.ItemMeta; import org.bukkit.util.BlockVector; import org.bukkit.util.Vector; +import java.awt.*; import java.awt.Color; import java.util.ArrayList; import java.util.Objects; -public class WandManager implements Listener { - +public class WandSVC implements IrisService { private static ItemStack wand; private static ItemStack dust; - public WandManager() { + @Override + public void onEnable() { wand = createWand(); dust = createDust(); @@ -65,6 +66,11 @@ public class WandManager implements Listener { }, 0); } + @Override + public void onDisable() { + + } + public void tick(Player p) { try { try { diff --git a/src/main/java/com/volmit/iris/core/tools/IrisCreator.java b/src/main/java/com/volmit/iris/core/tools/IrisCreator.java index 73c7bacaf..2a5dd22eb 100644 --- a/src/main/java/com/volmit/iris/core/tools/IrisCreator.java +++ b/src/main/java/com/volmit/iris/core/tools/IrisCreator.java @@ -22,6 +22,7 @@ import com.google.common.util.concurrent.AtomicDouble; import com.volmit.iris.Iris; import com.volmit.iris.core.IrisSettings; import com.volmit.iris.core.pregenerator.PregenTask; +import com.volmit.iris.core.service.StudioSVC; import com.volmit.iris.engine.data.cache.AtomicCache; import com.volmit.iris.engine.object.common.HeadlessWorld; import com.volmit.iris.engine.object.dimensional.IrisDimension; @@ -107,7 +108,7 @@ public class IrisCreator { if(!studio()) { - Iris.proj.installIntoWorld(sender, d.getLoadKey(), new File(name())); + Iris.service(StudioSVC.class).installIntoWorld(sender, d.getLoadKey(), new File(name())); } PlatformChunkGenerator access = null; diff --git a/src/main/java/com/volmit/iris/core/tools/IrisToolbelt.java b/src/main/java/com/volmit/iris/core/tools/IrisToolbelt.java index f339590bd..9980bc490 100644 --- a/src/main/java/com/volmit/iris/core/tools/IrisToolbelt.java +++ b/src/main/java/com/volmit/iris/core/tools/IrisToolbelt.java @@ -20,7 +20,6 @@ package com.volmit.iris.core.tools; import com.volmit.iris.Iris; import com.volmit.iris.core.IrisSettings; -import com.volmit.iris.core.ProjectManager; import com.volmit.iris.core.gui.PregeneratorJob; import com.volmit.iris.core.pregenerator.PregenTask; import com.volmit.iris.core.pregenerator.PregeneratorMethod; @@ -28,6 +27,7 @@ import com.volmit.iris.core.pregenerator.methods.HeadlessPregenMethod; import com.volmit.iris.core.pregenerator.methods.HybridPregenMethod; import com.volmit.iris.core.project.IrisProject; import com.volmit.iris.core.project.loader.IrisData; +import com.volmit.iris.core.service.StudioSVC; import com.volmit.iris.engine.object.dimensional.IrisDimension; import com.volmit.iris.engine.platform.HeadlessGenerator; import com.volmit.iris.engine.platform.PlatformChunkGenerator; @@ -71,7 +71,7 @@ public class IrisToolbelt { File pack = Iris.instance.getDataFolder("packs", dimension); if (!pack.exists()) { - Iris.proj.downloadSearch(new VolmitSender(Bukkit.getConsoleSender(), Iris.instance.getTag()), dimension, false, false); + Iris.service(StudioSVC.class).downloadSearch(new VolmitSender(Bukkit.getConsoleSender(), Iris.instance.getTag()), dimension, false, false); } if (!pack.exists()) { diff --git a/src/main/java/com/volmit/iris/engine/object/common/HeadlessWorld.java b/src/main/java/com/volmit/iris/engine/object/common/HeadlessWorld.java index 13c342bf5..d5629b3c0 100644 --- a/src/main/java/com/volmit/iris/engine/object/common/HeadlessWorld.java +++ b/src/main/java/com/volmit/iris/engine/object/common/HeadlessWorld.java @@ -20,6 +20,7 @@ package com.volmit.iris.engine.object.common; import com.volmit.iris.Iris; import com.volmit.iris.core.project.loader.IrisData; +import com.volmit.iris.core.service.StudioSVC; import com.volmit.iris.core.tools.IrisToolbelt; import com.volmit.iris.engine.object.dimensional.IrisDimension; import com.volmit.iris.engine.platform.BukkitChunkGenerator; @@ -60,7 +61,7 @@ public class HeadlessWorld { new File(world.worldFolder(), "region").mkdirs(); if (!studio && !new File(world.worldFolder(), "iris/pack").exists()) { - Iris.proj.installIntoWorld(new VolmitSender(Bukkit.getConsoleSender(), Iris.instance.getTag("Headless")), dimension.getLoadKey(), world.worldFolder()); + Iris.service(StudioSVC.class).installIntoWorld(new VolmitSender(Bukkit.getConsoleSender(), Iris.instance.getTag("Headless")), dimension.getLoadKey(), world.worldFolder()); } } diff --git a/src/main/java/com/volmit/iris/util/hunk/view/ChunkBiomeHunkView.java b/src/main/java/com/volmit/iris/util/hunk/view/ChunkBiomeHunkView.java index 8acbdd605..fac0d443a 100644 --- a/src/main/java/com/volmit/iris/util/hunk/view/ChunkBiomeHunkView.java +++ b/src/main/java/com/volmit/iris/util/hunk/view/ChunkBiomeHunkView.java @@ -19,6 +19,7 @@ package com.volmit.iris.util.hunk.view; import com.volmit.iris.Iris; +import com.volmit.iris.core.service.EditSVC; import com.volmit.iris.util.hunk.Hunk; import org.bukkit.Chunk; import org.bukkit.block.Biome; @@ -52,11 +53,12 @@ public class ChunkBiomeHunkView implements Hunk { return; } - Iris.edit.setBiome(chunk.getWorld(), x + (chunk.getX() * 16), y, z + (chunk.getZ() * 16), t); + Iris.service(EditSVC.class).setBiome(chunk.getWorld(), x + (chunk.getX() * 16), y, z + (chunk.getZ() * 16), t); } @Override public Biome getRaw(int x, int y, int z) { - return Iris.edit.getBiome(chunk.getWorld(), x + (chunk.getX() * 16), y, z + (chunk.getZ() * 16)); + return Iris.service(EditSVC.class) + .getBiome(chunk.getWorld(), x + (chunk.getX() * 16), y, z + (chunk.getZ() * 16)); } } diff --git a/src/main/java/com/volmit/iris/util/hunk/view/ChunkHunkView.java b/src/main/java/com/volmit/iris/util/hunk/view/ChunkHunkView.java index 64ad662aa..ec0f81996 100644 --- a/src/main/java/com/volmit/iris/util/hunk/view/ChunkHunkView.java +++ b/src/main/java/com/volmit/iris/util/hunk/view/ChunkHunkView.java @@ -19,6 +19,7 @@ package com.volmit.iris.util.hunk.view; import com.volmit.iris.Iris; +import com.volmit.iris.core.service.EditSVC; import com.volmit.iris.util.hunk.Hunk; import org.bukkit.Chunk; import org.bukkit.block.data.BlockData; @@ -52,11 +53,11 @@ public class ChunkHunkView implements Hunk { return; } - Iris.edit.set(chunk.getWorld(), x + (chunk.getX() * 16), y, z + (chunk.getZ() * 16), t); + Iris.service(EditSVC.class).set(chunk.getWorld(), x + (chunk.getX() * 16), y, z + (chunk.getZ() * 16), t); } @Override public BlockData getRaw(int x, int y, int z) { - return Iris.edit.get(chunk.getWorld(), x + (chunk.getX() * 16), y, z + (chunk.getZ() * 16)); + return Iris.service(EditSVC.class).get(chunk.getWorld(), x + (chunk.getX() * 16), y, z + (chunk.getZ() * 16)); } } diff --git a/src/main/java/com/volmit/iris/util/plugin/VolmitPlugin.java b/src/main/java/com/volmit/iris/util/plugin/VolmitPlugin.java index 802210dc6..7dd135477 100644 --- a/src/main/java/com/volmit/iris/util/plugin/VolmitPlugin.java +++ b/src/main/java/com/volmit/iris/util/plugin/VolmitPlugin.java @@ -448,16 +448,12 @@ public abstract class VolmitPlugin extends JavaPlugin implements Listener { } public void registerListener(Listener l) { - if (bad) { - return; - } + Iris.debug("Register Listener " + l.getClass().getSimpleName()); Bukkit.getPluginManager().registerEvents(l, this); } public void unregisterListener(Listener l) { - if (bad) { - return; - } + Iris.debug("Register Listener " + l.getClass().getSimpleName()); HandlerList.unregisterAll(l); } From a462ab98e95b01cc92fa9495edc7c38f97a35cb1 Mon Sep 17 00:00:00 2001 From: cyberpwn Date: Mon, 16 Aug 2021 18:53:01 -0400 Subject: [PATCH 03/13] Cleanup sources --- src/main/java/com/volmit/iris/Iris.java | 2 +- .../object/CommandIrisObjectAnalyze.java | 18 + .../pregen/CommandIrisPregenPause.java | 18 + .../pregen/CommandIrisPregenStart.java | 18 + .../command/pregen/CommandIrisPregenStop.java | 18 + .../studio/CommandIrisStudioBeautify.java | 2 +- .../command/what/CommandIrisWhatFeatures.java | 1 - .../core/command/world/CommandIrisCreate.java | 10 - .../com/volmit/iris/core/decrees/DecIris.java | 47 +- .../volmit/iris/core/decrees/DecPregen.java | 33 +- .../volmit/iris/core/decrees/DecSettings.java | 3 +- .../volmit/iris/core/decrees/DecStudio.java | 81 ++- .../volmit/iris/core/link/MythicMobsLink.java | 18 + .../volmit/iris/core/project/IrisPack.java | 8 +- .../volmit/iris/core/project/IrisProject.java | 9 +- .../volmit/iris/core/service/StudioSVC.java | 9 +- .../com/volmit/iris/core/service/WandSVC.java | 1 - .../volmit/iris/core/tools/IrisCreator.java | 25 +- .../volmit/iris/core/tools/IrisToolbelt.java | 11 +- .../engine/object/spawners/IrisSurface.java | 1 - .../object/villager/IrisVillagerOverride.java | 18 + .../object/villager/IrisVillagerTrade.java | 18 + .../iris/engine/platform/EngineProvider.java | 3 +- .../scripting/EngineExecutionEnvironment.java | 1 - .../java/com/volmit/iris/util/data/B.java | 5 +- .../iris/util/data/IrisProjectRepo.java | 46 +- .../util/decree/DecreeContextHandler.java | 30 +- .../iris/util/decree/DecreeExecutor.java | 28 +- .../volmit/iris/util/decree/DecreeNode.java | 13 +- .../volmit/iris/util/decree/DecreeOrigin.java | 5 +- .../iris/util/decree/DecreeParameter.java | 11 +- .../util/decree/DecreeParameterHandler.java | 69 +-- .../volmit/iris/util/decree/DecreeSystem.java | 86 +-- .../iris/util/decree/annotations/Decree.java | 1 + .../decree/context/BiomeContextHandler.java | 30 +- .../context/DimensionContextHandler.java | 30 +- .../context/GeneratorContextHandler.java | 23 +- .../decree/context/RegionContextHandler.java | 30 +- .../decree/context/WorldContextHandler.java | 25 +- .../exceptions/DecreeParsingException.java | 2 +- .../exceptions/DecreeWhichException.java | 4 +- .../util/decree/handlers/BiomeHandler.java | 31 +- .../decree/handlers/BlockVectorHandler.java | 64 +-- .../util/decree/handlers/BooleanHandler.java | 12 +- .../util/decree/handlers/ByteHandler.java | 11 +- .../decree/handlers/DimensionHandler.java | 31 +- .../util/decree/handlers/DoubleHandler.java | 11 +- .../util/decree/handlers/EntityHandler.java | 48 +- .../util/decree/handlers/FloatHandler.java | 13 +- .../decree/handlers/GeneratorHandler.java | 47 +- .../util/decree/handlers/IntegerHandler.java | 15 +- .../util/decree/handlers/LongHandler.java | 13 +- .../util/decree/handlers/PlayerHandler.java | 19 +- .../util/decree/handlers/RegionHandler.java | 29 +- .../util/decree/handlers/ScriptHandler.java | 47 +- .../util/decree/handlers/ShortHandler.java | 13 +- .../util/decree/handlers/StringHandler.java | 4 +- .../util/decree/handlers/VectorHandler.java | 67 +-- .../util/decree/handlers/WorldHandler.java | 21 +- .../decree/virtual/VirtualDecreeCommand.java | 351 ++++-------- .../com/volmit/iris/util/format/Form.java | 1 - .../com/volmit/iris/util/mantle/Mantle.java | 12 +- .../java/com/volmit/iris/util/network/DL.java | 535 ++++++++---------- .../iris/util/network/DownloadException.java | 29 +- .../iris/util/network/DownloadMonitor.java | 5 +- .../iris/util/network/MeteredInputStream.java | 161 +++--- .../util/network/MeteredOutputStream.java | 157 +++-- .../volmit/iris/util/plugin/VolmitSender.java | 118 ++-- .../util/scheduling/jobs/DownloadJob.java | 15 +- .../volmit/iris/util/scheduling/jobs/Job.java | 26 +- .../util/scheduling/jobs/JobCollection.java | 9 +- .../iris/util/scheduling/jobs/QueueJob.java | 12 +- .../iris/util/scheduling/jobs/SingleJob.java | 5 +- 73 files changed, 1235 insertions(+), 1508 deletions(-) diff --git a/src/main/java/com/volmit/iris/Iris.java b/src/main/java/com/volmit/iris/Iris.java index 4d86a0d8d..d3d943729 100644 --- a/src/main/java/com/volmit/iris/Iris.java +++ b/src/main/java/com/volmit/iris/Iris.java @@ -107,7 +107,7 @@ public class Iris extends VolmitPlugin implements Listener { private void enable() { services = new KMap<>(); initialize("com.volmit.iris.core.service").forEach((i) -> services.put((Class) i.getClass(), (IrisService) i)); - + audiences = BukkitAudiences.create(this); sender = new VolmitSender(Bukkit.getConsoleSender()); sender.setTag(getTag()); diff --git a/src/main/java/com/volmit/iris/core/command/object/CommandIrisObjectAnalyze.java b/src/main/java/com/volmit/iris/core/command/object/CommandIrisObjectAnalyze.java index 6e8252f45..88e541d0a 100644 --- a/src/main/java/com/volmit/iris/core/command/object/CommandIrisObjectAnalyze.java +++ b/src/main/java/com/volmit/iris/core/command/object/CommandIrisObjectAnalyze.java @@ -1,3 +1,21 @@ +/* + * Iris is a World Generator for Minecraft Bukkit Servers + * Copyright (c) 2021 Arcane Arts (Volmit Software) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + package com.volmit.iris.core.command.object; import com.volmit.iris.Iris; diff --git a/src/main/java/com/volmit/iris/core/command/pregen/CommandIrisPregenPause.java b/src/main/java/com/volmit/iris/core/command/pregen/CommandIrisPregenPause.java index 6dac3c1a5..b02d36559 100644 --- a/src/main/java/com/volmit/iris/core/command/pregen/CommandIrisPregenPause.java +++ b/src/main/java/com/volmit/iris/core/command/pregen/CommandIrisPregenPause.java @@ -1,3 +1,21 @@ +/* + * Iris is a World Generator for Minecraft Bukkit Servers + * Copyright (c) 2021 Arcane Arts (Volmit Software) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + package com.volmit.iris.core.command.pregen; import com.volmit.iris.Iris; diff --git a/src/main/java/com/volmit/iris/core/command/pregen/CommandIrisPregenStart.java b/src/main/java/com/volmit/iris/core/command/pregen/CommandIrisPregenStart.java index 4a5fdd9ec..d85badbb4 100644 --- a/src/main/java/com/volmit/iris/core/command/pregen/CommandIrisPregenStart.java +++ b/src/main/java/com/volmit/iris/core/command/pregen/CommandIrisPregenStart.java @@ -1,3 +1,21 @@ +/* + * Iris is a World Generator for Minecraft Bukkit Servers + * Copyright (c) 2021 Arcane Arts (Volmit Software) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + package com.volmit.iris.core.command.pregen; import com.volmit.iris.Iris; diff --git a/src/main/java/com/volmit/iris/core/command/pregen/CommandIrisPregenStop.java b/src/main/java/com/volmit/iris/core/command/pregen/CommandIrisPregenStop.java index 13312b0db..9b2041c56 100644 --- a/src/main/java/com/volmit/iris/core/command/pregen/CommandIrisPregenStop.java +++ b/src/main/java/com/volmit/iris/core/command/pregen/CommandIrisPregenStop.java @@ -1,3 +1,21 @@ +/* + * Iris is a World Generator for Minecraft Bukkit Servers + * Copyright (c) 2021 Arcane Arts (Volmit Software) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + package com.volmit.iris.core.command.pregen; import com.volmit.iris.Iris; diff --git a/src/main/java/com/volmit/iris/core/command/studio/CommandIrisStudioBeautify.java b/src/main/java/com/volmit/iris/core/command/studio/CommandIrisStudioBeautify.java index c27bbc6f8..229ef0740 100644 --- a/src/main/java/com/volmit/iris/core/command/studio/CommandIrisStudioBeautify.java +++ b/src/main/java/com/volmit/iris/core/command/studio/CommandIrisStudioBeautify.java @@ -74,6 +74,7 @@ public class CommandIrisStudioBeautify extends MortarCommand { return true; } + private int clean(VolmitSender s, File clean) { int c = 0; if (clean.isDirectory()) { @@ -131,7 +132,6 @@ public class CommandIrisStudioBeautify extends MortarCommand { } - @Override protected String getArgsUsage() { return "[project]"; diff --git a/src/main/java/com/volmit/iris/core/command/what/CommandIrisWhatFeatures.java b/src/main/java/com/volmit/iris/core/command/what/CommandIrisWhatFeatures.java index f72adaab8..bd93f2018 100644 --- a/src/main/java/com/volmit/iris/core/command/what/CommandIrisWhatFeatures.java +++ b/src/main/java/com/volmit/iris/core/command/what/CommandIrisWhatFeatures.java @@ -21,7 +21,6 @@ package com.volmit.iris.core.command.what; import com.google.gson.Gson; import com.volmit.iris.Iris; import com.volmit.iris.core.tools.IrisToolbelt; -import com.volmit.iris.engine.framework.Engine; import com.volmit.iris.engine.object.feature.IrisFeaturePositional; import com.volmit.iris.util.collection.KList; import com.volmit.iris.util.json.JSONObject; diff --git a/src/main/java/com/volmit/iris/core/command/world/CommandIrisCreate.java b/src/main/java/com/volmit/iris/core/command/world/CommandIrisCreate.java index 367cac287..d7474a385 100644 --- a/src/main/java/com/volmit/iris/core/command/world/CommandIrisCreate.java +++ b/src/main/java/com/volmit/iris/core/command/world/CommandIrisCreate.java @@ -20,25 +20,16 @@ package com.volmit.iris.core.command.world; import com.volmit.iris.Iris; import com.volmit.iris.core.IrisSettings; -import com.volmit.iris.core.nms.INMS; import com.volmit.iris.core.tools.IrisToolbelt; -import com.volmit.iris.core.tools.IrisWorldCreator; import com.volmit.iris.engine.object.dimensional.IrisDimension; -import com.volmit.iris.engine.platform.PlatformChunkGenerator; import com.volmit.iris.util.collection.KList; import com.volmit.iris.util.exceptions.IrisException; -import com.volmit.iris.util.format.Form; import com.volmit.iris.util.plugin.MortarCommand; import com.volmit.iris.util.plugin.VolmitSender; import com.volmit.iris.util.scheduling.J; -import com.volmit.iris.util.scheduling.O; -import org.bukkit.Bukkit; -import org.bukkit.World; -import org.bukkit.WorldCreator; import java.io.File; import java.util.Random; -import java.util.concurrent.atomic.AtomicReference; public class CommandIrisCreate extends MortarCommand { public CommandIrisCreate() { @@ -128,7 +119,6 @@ public class CommandIrisCreate extends MortarCommand { String finalDimensionName = dimensionName; - long finalSeed = seed; J.a(() -> { try { diff --git a/src/main/java/com/volmit/iris/core/decrees/DecIris.java b/src/main/java/com/volmit/iris/core/decrees/DecIris.java index a2a1c0538..ff15a8c5d 100644 --- a/src/main/java/com/volmit/iris/core/decrees/DecIris.java +++ b/src/main/java/com/volmit/iris/core/decrees/DecIris.java @@ -32,8 +32,7 @@ import com.volmit.iris.util.format.C; import java.io.File; @Decree(name = "irisd", aliases = {"ird"}, description = "Basic Command") -public class DecIris implements DecreeExecutor -{ +public class DecIris implements DecreeExecutor { private DecStudio studio; private DecPregen pregen; @@ -41,19 +40,19 @@ public class DecIris implements DecreeExecutor @Decree(description = "Create a new world", aliases = "+") public void create( @Param(aliases = "world-name", description = "The name of the world to create", defaultValue = "IrisWorld") - String name, + String name, @Param(aliases = "dimension", description = "The dimension type to create the world with", defaultValue = "overworld") - IrisDimension type, + IrisDimension type, @Param(description = "The seed to generate the world with", defaultValue = "1337") - long seed - ){ + long seed + ) { if (name.equals("iris")) { sender().sendMessage(C.RED + "You cannot use the world name \"iris\" for creating worlds as Iris uses this directory for studio worlds."); sender().sendMessage(C.RED + "May we suggest the name \"IrisWorld\" instead?"); return; } - if (new File(name).exists()){ + if (new File(name).exists()) { sender().sendMessage(C.RED + "That folder already exists!"); return; } @@ -66,7 +65,7 @@ public class DecIris implements DecreeExecutor .sender(sender()) .studio(false) .create(); - } catch (Throwable e){ + } catch (Throwable e) { sender().sendMessage(C.RED + "Exception raised during creation. See the console for more details."); Iris.error("Exception raised during world creation: " + e.getMessage()); Iris.reportError(e); @@ -77,18 +76,18 @@ public class DecIris implements DecreeExecutor } @Decree(description = "Print version information") - public void version(){ + public void version() { sender().sendMessage("Iris v" + Iris.instance.getDescription().getVersion() + " by Volmit Software"); } @Decree(description = "Set aura spins") public void aura( @Param(description = "The h color value", defaultValue = "-20") - int h, + int h, @Param(description = "The s color value", defaultValue = "7") - int s, + int s, @Param(description = "The b color value", defaultValue = "8") - int b + int b ) { IrisSettings.get().getGeneral().setSpinh(h); IrisSettings.get().getGeneral().setSpins(s); @@ -100,22 +99,22 @@ public class DecIris implements DecreeExecutor @Decree(description = "Bitwise calculations") public void bitwise( @Param(description = "The first value to run calculations on") - int value1, + int value1, @Param(description = "The operator: | & ^ >> << %") - String operator, + String operator, @Param(description = "The second value to run calculations on") - int value2 + int value2 ) { Integer v = null; - switch(operator) { + switch (operator) { case "|" -> v = value1 | value2; case "&" -> v = value1 & value2; case "^" -> v = value1 ^ value2; case "%" -> v = value1 % value2; case ">>" -> v = value1 >> value2; case "<<" -> v = value1 << value2; - }; - if (v == null){ + } + if (v == null) { sender().sendMessage(C.RED + "The operator you entered: (" + operator + ") is invalid!"); return; } @@ -125,7 +124,7 @@ public class DecIris implements DecreeExecutor @Decree(description = "Toggle debug") public void debug( @Param(name = "on", description = "Whether or not debug should be on", defaultValue = "true") - boolean on + boolean on ) { IrisSettings.get().getGeneral().setDebug(on); } @@ -133,13 +132,13 @@ public class DecIris implements DecreeExecutor @Decree(description = "Download a project.") public void download( @Param(name = "pack", description = "The pack to download", defaultValue = "overworld", aliases = "project") - String pack, + String pack, @Param(name = "branch", description = "The branch to download from", defaultValue = "master") - String branch, + String branch, @Param(name = "trim", description = "Whether or not to download a trimmed version (do not enable when editing)", defaultValue = "false") - boolean trim, + boolean trim, @Param(name = "overwrite", description = "Whether or not to overwrite the pack with the downloaded one", aliases = "force", defaultValue = "false") - boolean overwrite + boolean overwrite ) { sender().sendMessage(C.GREEN + "Downloading pack: " + pack + "/" + branch + (trim ? " trimmed" : "")); Iris.service(StudioSVC.class).downloadSearch(sender(), "IrisDimensions/" + pack + "/" + branch, trim, overwrite); @@ -147,7 +146,7 @@ public class DecIris implements DecreeExecutor @Decree(description = "Get metrics for your world", aliases = "measure", origin = DecreeOrigin.PLAYER) public void metrics() { - if (!IrisToolbelt.isIrisWorld(world())){ + if (!IrisToolbelt.isIrisWorld(world())) { sender().sendMessage(C.RED + "You must be in an Iris world"); return; } diff --git a/src/main/java/com/volmit/iris/core/decrees/DecPregen.java b/src/main/java/com/volmit/iris/core/decrees/DecPregen.java index 1a97ed063..8dc6f49a6 100644 --- a/src/main/java/com/volmit/iris/core/decrees/DecPregen.java +++ b/src/main/java/com/volmit/iris/core/decrees/DecPregen.java @@ -1,3 +1,21 @@ +/* + * Iris is a World Generator for Minecraft Bukkit Servers + * Copyright (c) 2021 Arcane Arts (Volmit Software) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + package com.volmit.iris.core.decrees; import com.volmit.iris.Iris; @@ -9,7 +27,6 @@ import com.volmit.iris.util.decree.annotations.Decree; import com.volmit.iris.util.decree.annotations.Param; import com.volmit.iris.util.format.C; import com.volmit.iris.util.math.Position2; -import org.bukkit.Location; import org.bukkit.World; import org.bukkit.util.Vector; @@ -17,12 +34,12 @@ import org.bukkit.util.Vector; public class DecPregen implements DecreeExecutor { @Decree(description = "Pregenerate a world") public void start( - @Param(description = "The world to pregen", contextual = true) - World world, - @Param(description = "The radius of the pregen in blocks", aliases = "size") - int radius, - @Param(aliases = "middle", description = "The center location of the pregen. Use \"me\" for your current location", defaultValue = "0,0") - Vector center + @Param(description = "The world to pregen", contextual = true) + World world, + @Param(description = "The radius of the pregen in blocks", aliases = "size") + int radius, + @Param(aliases = "middle", description = "The center location of the pregen. Use \"me\" for your current location", defaultValue = "0,0") + Vector center ) { try { IrisToolbelt.pregenerate(PregenTask @@ -40,7 +57,7 @@ public class DecPregen implements DecreeExecutor { } @Decree(description = "Stop the active pregeneration task", aliases = "x") - public void stop(){ + public void stop() { if (PregeneratorJob.shutdownInstance()) { sender().sendMessage(C.GREEN + "Stopped pregeneration task"); } else { diff --git a/src/main/java/com/volmit/iris/core/decrees/DecSettings.java b/src/main/java/com/volmit/iris/core/decrees/DecSettings.java index b7efbc37f..fe05846b7 100644 --- a/src/main/java/com/volmit/iris/core/decrees/DecSettings.java +++ b/src/main/java/com/volmit/iris/core/decrees/DecSettings.java @@ -20,7 +20,6 @@ package com.volmit.iris.core.decrees; import com.volmit.iris.util.decree.DecreeExecutor; -public class DecSettings implements DecreeExecutor -{ +public class DecSettings implements DecreeExecutor { } diff --git a/src/main/java/com/volmit/iris/core/decrees/DecStudio.java b/src/main/java/com/volmit/iris/core/decrees/DecStudio.java index 84fe3d224..8c899e58f 100644 --- a/src/main/java/com/volmit/iris/core/decrees/DecStudio.java +++ b/src/main/java/com/volmit/iris/core/decrees/DecStudio.java @@ -110,8 +110,7 @@ public class DecStudio implements DecreeExecutor { @Param(description = "The name of this new Iris Project.") String name, @Param(description = "Copy the contents of an existing project in your packs folder and use it as a template in this new project.", contextual = true) - IrisDimension template) - { + IrisDimension template) { if (template != null) { Iris.service(StudioSVC.class).create(sender(), name, template.getLoadKey()); } else { @@ -147,8 +146,7 @@ public class DecStudio implements DecreeExecutor { sender().sendMessage("Files: " + files.size()); - if(fixIds) - { + if (fixIds) { QueueJob r = new QueueJob<>() { @Override public void execute(File f) { @@ -173,8 +171,7 @@ public class DecStudio implements DecreeExecutor { jobs.add(r); } - if(beautify) - { + if (beautify) { QueueJob r = new QueueJob<>() { @Override public void execute(File f) { @@ -197,8 +194,7 @@ public class DecStudio implements DecreeExecutor { jobs.add(r); } - if(rewriteObjects) - { + if (rewriteObjects) { QueueJob q = new QueueJob<>() { @Override public void execute(Runnable runnable) { @@ -214,7 +210,7 @@ public class DecStudio implements DecreeExecutor { IrisData data = new IrisData(Iris.service(StudioSVC.class).getWorkspaceFolder(project.getLoadKey())); for (String f : data.getObjectLoader().getPossibleKeys()) { - CompletableFuture gg = burst.complete(() ->{ + CompletableFuture gg = burst.complete(() -> { File ff = data.getObjectLoader().findFile(f); IrisObject oo = new IrisObject(0, 0, 0); try { @@ -265,7 +261,7 @@ public class DecStudio implements DecreeExecutor { @Decree(description = "Edit the biome you are currently in", aliases = {"ebiome", "eb"}, origin = DecreeOrigin.PLAYER) public void editbiome( @Param(contextual = true, description = "The biome to edit") - IrisBiome biome + IrisBiome biome ) { if (noStudio()) return; @@ -303,7 +299,7 @@ public class DecStudio implements DecreeExecutor { IrisGenerator generator, @Param(description = "The seed to generate with", defaultValue = "12345") long seed - ){ + ) { if (noGUI()) return; sender().sendMessage(C.GREEN + "Opening Noise Explorer!"); @@ -324,13 +320,13 @@ public class DecStudio implements DecreeExecutor { IrisBiome biome, @Param(description = "The region to find", contextual = true) IrisRegion region - ){ - if (!IrisToolbelt.isIrisWorld(world())){ + ) { + if (!IrisToolbelt.isIrisWorld(world())) { sender().sendMessage(C.RED + "You must be in an Iris world to use this command!"); return; } - if (biome == null && region == null){ + if (biome == null && region == null) { sender().sendMessage(C.RED + "You must specify a biome or region!"); return; } @@ -373,9 +369,9 @@ public class DecStudio implements DecreeExecutor { @Decree(description = "Show loot if a chest were right here", origin = DecreeOrigin.PLAYER, sync = true) public void loot( @Param(description = "Fast insertion of items in virtual inventory (may cause performance drop)", defaultValue = "false") - boolean fast, + boolean fast, @Param(description = "Whether or not to append to the inventory currently open (if false, clears opened inventory)", defaultValue = "true") - boolean add + boolean add ) { if (noStudio()) return; @@ -384,7 +380,7 @@ public class DecStudio implements DecreeExecutor { try { engine().addItems(true, inv, RNG.r, tables, InventorySlotType.STORAGE, player().getLocation().getBlockX(), player().getLocation().getBlockY(), player().getLocation().getBlockZ(), 1); - } catch (Throwable e){ + } catch (Throwable e) { Iris.reportError(e); sender().sendMessage(C.RED + "Cannot add items to virtual inventory because of: " + e.getMessage()); return; @@ -414,8 +410,7 @@ public class DecStudio implements DecreeExecutor { } @Decree(description = "Render a world map (External GUI)", aliases = "render") - public void map() - { + public void map() { if (noStudio()) return; if (noGUI()) return; @@ -427,20 +422,20 @@ public class DecStudio implements DecreeExecutor { @Decree(description = "Package a dimension into a compressed format", aliases = "package") public void pkg( @Param(name = "dimension", description = "The dimension pack to compress", contextual = true, defaultValue = "overworld") - IrisDimension dimension, + IrisDimension dimension, @Param(name = "obfuscate", description = "Whether or not to obfuscate the pack", defaultValue = "false") - boolean obfuscate, + boolean obfuscate, @Param(name = "minify", description = "Whether or not to minify the pack", defaultValue = "true") - boolean minify - ){ + boolean minify + ) { Iris.service(StudioSVC.class).compilePackage(sender(), dimension.getLoadKey(), obfuscate, minify); } @Decree(description = "Profiles the performance of a dimension", origin = DecreeOrigin.PLAYER) public void profile( @Param(description = "The dimension to profile", contextual = true, defaultValue = "overworld") - IrisDimension dimension - ){ + IrisDimension dimension + ) { File pack = dimension.getLoadFile().getParentFile().getParentFile(); File report = Iris.instance.getDataFile("profile.txt"); IrisProject project = new IrisProject(pack); @@ -627,13 +622,13 @@ public class DecStudio implements DecreeExecutor { @Decree(description = "Summon an Iris Entity", origin = DecreeOrigin.PLAYER) public void summon( @Param(description = "The Iris Entity to spawn") - IrisEntity entity + IrisEntity entity ) { - if (!sender().isPlayer()){ + if (!sender().isPlayer()) { sender().sendMessage(C.RED + "Players only (this is a config error. Ask support to add DecreeOrigin.PLAYER to the command you tried to run)"); return; } - if (IrisToolbelt.isIrisWorld(world())){ + if (IrisToolbelt.isIrisWorld(world())) { sender().sendMessage(C.RED + "You can only spawn entities in Iris worlds!"); return; } @@ -642,13 +637,13 @@ public class DecStudio implements DecreeExecutor { } @Decree(description = "Teleport to the active studio world", aliases = "stp", origin = DecreeOrigin.PLAYER, sync = true) - public void tpstudio(){ - if (!Iris.service(StudioSVC.class).isProjectOpen()){ + public void tpstudio() { + if (!Iris.service(StudioSVC.class).isProjectOpen()) { sender().sendMessage(C.RED + "No studio world is open!"); return; } - if (IrisToolbelt.isIrisWorld(world()) && engine().isStudio()){ + if (IrisToolbelt.isIrisWorld(world()) && engine().isStudio()) { sender().sendMessage(C.RED + "You are already in a studio world!"); return; } @@ -660,9 +655,9 @@ public class DecStudio implements DecreeExecutor { @Decree(description = "Update your dimension project") public void update( - @Param(description = "The dimension to update the workspace of", contextual = true, defaultValue = "overworld") - IrisDimension dimension - ){ + @Param(description = "The dimension to update the workspace of", contextual = true, defaultValue = "overworld") + IrisDimension dimension + ) { if (new IrisProject(dimension.getLoadFile().getParentFile().getParentFile()).updateWorkspace()) { sender().sendMessage(C.GREEN + "Updated Code Workspace for " + dimension.getName()); } else { @@ -682,7 +677,7 @@ public class DecStudio implements DecreeExecutor { boolean look, @Param(description = "Whether or not to show information about the block you are holding", defaultValue = "true") boolean hand - ){ + ) { // Data BlockData handHeld = player().getInventory().getItemInMainHand().getType().createBlockData(); Block targetBlock = player().getTargetBlockExact(128, FluidCollisionMode.NEVER); @@ -708,7 +703,7 @@ public class DecStudio implements DecreeExecutor { } // Target - if (targetBlockData == null){ + if (targetBlockData == null) { sender().sendMessage(C.RED + "Not looking at any block"); } else if (look) { sender().sendMessage(C.GREEN + "" + C.BOLD + "Looked-at block information"); @@ -760,7 +755,7 @@ public class DecStudio implements DecreeExecutor { * @return true if server GUIs are not enabled */ private boolean noGUI() { - if (!IrisSettings.get().isUseServerLaunchedGuis()){ + if (!IrisSettings.get().isUseServerLaunchedGuis()) { sender().sendMessage(C.RED + "You must have server launched GUIs enabled in the settings!"); return true; } @@ -770,16 +765,16 @@ public class DecStudio implements DecreeExecutor { /** * @return true if no studio is open or the player is not in one */ - private boolean noStudio(){ - if (!sender().isPlayer()){ + private boolean noStudio() { + if (!sender().isPlayer()) { sender().sendMessage(C.RED + "Players only (this is a config error. Ask support to add DecreeOrigin.PLAYER to the command you tried to run)"); return true; } - if (!Iris.service(StudioSVC.class).isProjectOpen()){ + if (!Iris.service(StudioSVC.class).isProjectOpen()) { sender().sendMessage(C.RED + "No studio world is open!"); return true; } - if (!engine().isStudio()){ + if (!engine().isStudio()) { sender().sendMessage(C.RED + "You must be in a studio world!"); return true; } @@ -787,9 +782,7 @@ public class DecStudio implements DecreeExecutor { } - - public void files(File clean, KList files) - { + public void files(File clean, KList files) { if (clean.isDirectory()) { for (File i : clean.listFiles()) { files(i, files); diff --git a/src/main/java/com/volmit/iris/core/link/MythicMobsLink.java b/src/main/java/com/volmit/iris/core/link/MythicMobsLink.java index b89c76ccf..1a4287136 100644 --- a/src/main/java/com/volmit/iris/core/link/MythicMobsLink.java +++ b/src/main/java/com/volmit/iris/core/link/MythicMobsLink.java @@ -1,3 +1,21 @@ +/* + * Iris is a World Generator for Minecraft Bukkit Servers + * Copyright (c) 2021 Arcane Arts (Volmit Software) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + package com.volmit.iris.core.link; import org.bukkit.Bukkit; diff --git a/src/main/java/com/volmit/iris/core/project/IrisPack.java b/src/main/java/com/volmit/iris/core/project/IrisPack.java index b907103d6..f0b06b469 100644 --- a/src/main/java/com/volmit/iris/core/project/IrisPack.java +++ b/src/main/java/com/volmit/iris/core/project/IrisPack.java @@ -18,8 +18,6 @@ package com.volmit.iris.core.project; -import com.volmit.iris.core.project.loader.IrisData; -import com.volmit.iris.engine.object.dimensional.IrisDimension; import lombok.Data; import java.io.File; @@ -28,13 +26,11 @@ import java.io.File; public class IrisPack { private final File folder; - public IrisPack(File folder) - { + public IrisPack(File folder) { this.folder = folder; } - public String getName() - { + public String getName() { return getFolder().getName(); } } diff --git a/src/main/java/com/volmit/iris/core/project/IrisProject.java b/src/main/java/com/volmit/iris/core/project/IrisProject.java index 0601e80e3..3a8cd8535 100644 --- a/src/main/java/com/volmit/iris/core/project/IrisProject.java +++ b/src/main/java/com/volmit/iris/core/project/IrisProject.java @@ -21,11 +21,9 @@ package com.volmit.iris.core.project; import com.google.gson.Gson; import com.volmit.iris.Iris; import com.volmit.iris.core.IrisSettings; -import com.volmit.iris.core.nms.INMS; import com.volmit.iris.core.project.loader.IrisData; import com.volmit.iris.core.project.loader.ResourceLoader; import com.volmit.iris.core.tools.IrisToolbelt; -import com.volmit.iris.core.tools.IrisWorldCreator; import com.volmit.iris.engine.object.biome.IrisBiome; import com.volmit.iris.engine.object.block.IrisBlockData; import com.volmit.iris.engine.object.dimensional.IrisDimension; @@ -40,7 +38,6 @@ import com.volmit.iris.util.collection.KList; import com.volmit.iris.util.collection.KMap; import com.volmit.iris.util.collection.KSet; import com.volmit.iris.util.exceptions.IrisException; -import com.volmit.iris.util.format.C; import com.volmit.iris.util.format.Form; import com.volmit.iris.util.io.IO; import com.volmit.iris.util.json.JSONArray; @@ -52,9 +49,8 @@ import com.volmit.iris.util.scheduling.J; import com.volmit.iris.util.scheduling.O; import com.volmit.iris.util.scheduling.PrecisionStopwatch; import lombok.Data; -import net.md_5.bungee.api.ChatMessageType; -import net.md_5.bungee.api.chat.TextComponent; -import org.bukkit.*; +import org.bukkit.Bukkit; +import org.bukkit.GameMode; import org.zeroturnaround.zip.ZipUtil; import java.awt.*; @@ -448,7 +444,6 @@ public class IrisProject { } - public static int clean(VolmitSender s, File clean) { int c = 0; if (clean.isDirectory()) { diff --git a/src/main/java/com/volmit/iris/core/service/StudioSVC.java b/src/main/java/com/volmit/iris/core/service/StudioSVC.java index 719c1a50d..5d42fb9a9 100644 --- a/src/main/java/com/volmit/iris/core/service/StudioSVC.java +++ b/src/main/java/com/volmit/iris/core/service/StudioSVC.java @@ -35,7 +35,6 @@ import com.volmit.iris.util.json.JSONException; import com.volmit.iris.util.json.JSONObject; import com.volmit.iris.util.plugin.IrisService; import com.volmit.iris.util.plugin.VolmitSender; -import com.volmit.iris.util.scheduling.GroupedExecutor; import com.volmit.iris.util.scheduling.J; import org.bukkit.Bukkit; import org.bukkit.World; @@ -49,7 +48,7 @@ import java.util.UUID; public class StudioSVC implements IrisService { public static final String LISTING = "https://raw.githubusercontent.com/IrisDimensions/_listing/main/listing-v2.json"; public static final String WORKSPACE_NAME = "packs"; - private KMap cacheListing = null; + private final KMap cacheListing = null; private IrisProject activeProject; private static final AtomicCache counter = new AtomicCache<>(); @@ -323,7 +322,8 @@ public class StudioSVC implements IrisService { public void open(VolmitSender sender, long seed, String dimm) { try { - open(sender,seed, dimm, () -> {}); + open(sender, seed, dimm, () -> { + }); } catch (Exception e) { Iris.reportError(e); sender.sendMessage("Error when creating studio world:"); @@ -448,8 +448,7 @@ public class StudioSVC implements IrisService { create(sender, s, "example"); } - public IrisProject getActiveProject() - { + public IrisProject getActiveProject() { return activeProject; } diff --git a/src/main/java/com/volmit/iris/core/service/WandSVC.java b/src/main/java/com/volmit/iris/core/service/WandSVC.java index 0df9a1989..4a94710e2 100644 --- a/src/main/java/com/volmit/iris/core/service/WandSVC.java +++ b/src/main/java/com/volmit/iris/core/service/WandSVC.java @@ -45,7 +45,6 @@ import org.bukkit.inventory.meta.ItemMeta; import org.bukkit.util.BlockVector; import org.bukkit.util.Vector; -import java.awt.*; import java.awt.Color; import java.util.ArrayList; import java.util.Objects; diff --git a/src/main/java/com/volmit/iris/core/tools/IrisCreator.java b/src/main/java/com/volmit/iris/core/tools/IrisCreator.java index 2a5dd22eb..8b719972d 100644 --- a/src/main/java/com/volmit/iris/core/tools/IrisCreator.java +++ b/src/main/java/com/volmit/iris/core/tools/IrisCreator.java @@ -23,13 +23,9 @@ import com.volmit.iris.Iris; import com.volmit.iris.core.IrisSettings; import com.volmit.iris.core.pregenerator.PregenTask; import com.volmit.iris.core.service.StudioSVC; -import com.volmit.iris.engine.data.cache.AtomicCache; -import com.volmit.iris.engine.object.common.HeadlessWorld; import com.volmit.iris.engine.object.dimensional.IrisDimension; -import com.volmit.iris.engine.platform.HeadlessGenerator; import com.volmit.iris.engine.platform.PlatformChunkGenerator; import com.volmit.iris.util.exceptions.IrisException; -import com.volmit.iris.util.exceptions.MissingDimensionException; import com.volmit.iris.util.format.C; import com.volmit.iris.util.format.Form; import com.volmit.iris.util.math.RNG; @@ -38,15 +34,12 @@ import com.volmit.iris.util.scheduling.J; import com.volmit.iris.util.scheduling.O; import lombok.Data; import lombok.experimental.Accessors; -import net.md_5.bungee.api.ChatMessageType; -import net.md_5.bungee.api.chat.TextComponent; import org.bukkit.*; import java.io.File; import java.util.concurrent.CompletableFuture; import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicReference; -import java.util.function.Consumer; /** * Makes it a lot easier to setup an engine, world, studio or whatever @@ -94,20 +87,17 @@ public class IrisCreator { * @throws IrisException shit happens */ public World create() throws IrisException { - if(Bukkit.isPrimaryThread()) - { + if (Bukkit.isPrimaryThread()) { throw new IrisException("You cannot invoke create() on the main thread."); } IrisDimension d = IrisToolbelt.getDimension(dimension()); - if(d == null) - { + if (d == null) { throw new IrisException("Dimension cannot be found null for id " + dimension()); } - if(!studio()) - { + if (!studio()) { Iris.service(StudioSVC.class).installIntoWorld(sender, d.getLoadKey(), new File(name())); } @@ -158,15 +148,13 @@ public class IrisCreator { done.set(true); - if(sender.isPlayer()) - { + if (sender.isPlayer()) { J.s(() -> { sender.player().teleport(new Location(world.get(), 0, world.get().getHighestBlockYAt(0, 0), 0)); }); } - if(studio) - { + if (studio) { J.s(() -> { Iris.linkMultiverseCore.removeFromConfig(world.get()); @@ -189,8 +177,7 @@ public class IrisCreator { AtomicBoolean dx = new AtomicBoolean(false); J.a(() -> { - while(!dx.get()) - { + while (!dx.get()) { if (sender.isPlayer()) { sender.sendProgress(pp.get(), "Pregenerating"); J.sleep(16); diff --git a/src/main/java/com/volmit/iris/core/tools/IrisToolbelt.java b/src/main/java/com/volmit/iris/core/tools/IrisToolbelt.java index 9980bc490..3c5b58d75 100644 --- a/src/main/java/com/volmit/iris/core/tools/IrisToolbelt.java +++ b/src/main/java/com/volmit/iris/core/tools/IrisToolbelt.java @@ -25,7 +25,6 @@ import com.volmit.iris.core.pregenerator.PregenTask; import com.volmit.iris.core.pregenerator.PregeneratorMethod; import com.volmit.iris.core.pregenerator.methods.HeadlessPregenMethod; import com.volmit.iris.core.pregenerator.methods.HybridPregenMethod; -import com.volmit.iris.core.project.IrisProject; import com.volmit.iris.core.project.loader.IrisData; import com.volmit.iris.core.service.StudioSVC; import com.volmit.iris.engine.object.dimensional.IrisDimension; @@ -47,7 +46,6 @@ import org.zeroturnaround.zip.commons.FileUtils; import java.io.File; import java.io.IOException; -import java.net.MalformedURLException; import java.nio.charset.StandardCharsets; import java.util.UUID; @@ -184,15 +182,15 @@ public class IrisToolbelt { /** * Attempts to ensure that the pack is installed + * * @param sender the sender - * @param url the dimension + * @param url the dimension * @throws Throwable shit happens */ public static void install(VolmitSender sender, String url) throws Throwable { IrisProjectRepo r = IrisProjectRepo.from(url); - if(r != null) - { + if (r != null) { url = r.getRepo(); } @@ -218,8 +216,9 @@ public class IrisToolbelt { /** * Evacuate all players from the world + * * @param world the world to leave - * @param m the message + * @param m the message * @return true if it was evacuated. */ public static boolean evacuate(World world, String m) { diff --git a/src/main/java/com/volmit/iris/engine/object/spawners/IrisSurface.java b/src/main/java/com/volmit/iris/engine/object/spawners/IrisSurface.java index 6baf9ee2a..b599b20db 100644 --- a/src/main/java/com/volmit/iris/engine/object/spawners/IrisSurface.java +++ b/src/main/java/com/volmit/iris/engine/object/spawners/IrisSurface.java @@ -21,7 +21,6 @@ package com.volmit.iris.engine.object.spawners; import com.volmit.iris.engine.object.annotations.Desc; import org.bukkit.Material; import org.bukkit.block.Block; -import org.bukkit.block.BlockState; import org.bukkit.block.data.Waterlogged; @Desc("The type of surface entities should spawn on") diff --git a/src/main/java/com/volmit/iris/engine/object/villager/IrisVillagerOverride.java b/src/main/java/com/volmit/iris/engine/object/villager/IrisVillagerOverride.java index dca836015..aef3e0d4f 100644 --- a/src/main/java/com/volmit/iris/engine/object/villager/IrisVillagerOverride.java +++ b/src/main/java/com/volmit/iris/engine/object/villager/IrisVillagerOverride.java @@ -1,3 +1,21 @@ +/* + * Iris is a World Generator for Minecraft Bukkit Servers + * Copyright (c) 2021 Arcane Arts (Volmit Software) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + package com.volmit.iris.engine.object.villager; import com.volmit.iris.engine.object.annotations.ArrayType; diff --git a/src/main/java/com/volmit/iris/engine/object/villager/IrisVillagerTrade.java b/src/main/java/com/volmit/iris/engine/object/villager/IrisVillagerTrade.java index e0694c84b..5e674303e 100644 --- a/src/main/java/com/volmit/iris/engine/object/villager/IrisVillagerTrade.java +++ b/src/main/java/com/volmit/iris/engine/object/villager/IrisVillagerTrade.java @@ -1,3 +1,21 @@ +/* + * Iris is a World Generator for Minecraft Bukkit Servers + * Copyright (c) 2021 Arcane Arts (Volmit Software) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + package com.volmit.iris.engine.object.villager; diff --git a/src/main/java/com/volmit/iris/engine/platform/EngineProvider.java b/src/main/java/com/volmit/iris/engine/platform/EngineProvider.java index b1bb60772..401694e34 100644 --- a/src/main/java/com/volmit/iris/engine/platform/EngineProvider.java +++ b/src/main/java/com/volmit/iris/engine/platform/EngineProvider.java @@ -43,8 +43,7 @@ public class EngineProvider { IrisData data = new IrisData(dataLocation); IrisDimension realDimension = data.getDimensionLoader().load(dimension); - if(realDimension == null) - { + if (realDimension == null) { throw new RuntimeException("Cannot find dimension in " + data.getDataFolder().getAbsolutePath() + " with key " + dimension); } diff --git a/src/main/java/com/volmit/iris/engine/scripting/EngineExecutionEnvironment.java b/src/main/java/com/volmit/iris/engine/scripting/EngineExecutionEnvironment.java index b91e02ebb..100279ece 100644 --- a/src/main/java/com/volmit/iris/engine/scripting/EngineExecutionEnvironment.java +++ b/src/main/java/com/volmit/iris/engine/scripting/EngineExecutionEnvironment.java @@ -19,7 +19,6 @@ package com.volmit.iris.engine.scripting; import com.volmit.iris.engine.framework.Engine; -import com.volmit.iris.engine.object.common.IrisScript; import org.apache.bsf.BSFManager; public interface EngineExecutionEnvironment { diff --git a/src/main/java/com/volmit/iris/util/data/B.java b/src/main/java/com/volmit/iris/util/data/B.java index 15de96ad3..25fc1b483 100644 --- a/src/main/java/com/volmit/iris/util/data/B.java +++ b/src/main/java/com/volmit/iris/util/data/B.java @@ -159,10 +159,7 @@ public class B { if (bx instanceof Leaves && IrisSettings.get().getGenerator().preventLeafDecay) { ((Leaves) bx).setPersistent(true); - } - - else if(bx instanceof Leaves) - { + } else if (bx instanceof Leaves) { ((Leaves) bx).setPersistent(false); } diff --git a/src/main/java/com/volmit/iris/util/data/IrisProjectRepo.java b/src/main/java/com/volmit/iris/util/data/IrisProjectRepo.java index be71001d9..b3fa89818 100644 --- a/src/main/java/com/volmit/iris/util/data/IrisProjectRepo.java +++ b/src/main/java/com/volmit/iris/util/data/IrisProjectRepo.java @@ -36,64 +36,44 @@ public class IrisProjectRepo { @Builder.Default private String tag = ""; - public static IrisProjectRepo from(String g) - { + public static IrisProjectRepo from(String g) { // https://github.com/IrisDimensions/overworld - if(g.startsWith("https://github.com/")) - { + if (g.startsWith("https://github.com/")) { String sub = g.split("\\Qgithub.com/\\E")[1]; IrisProjectRepo r = IrisProjectRepo.builder() .user(sub.split("\\Q/\\E")[0]) .repo(sub.split("\\Q/\\E")[1]).build(); - if(g.contains("/tree/")) - { + if (g.contains("/tree/")) { r.setBranch(g.split("/tree/")[1]); } return r; - } - - else if(g.contains("/")) - { + } else if (g.contains("/")) { String[] f = g.split("\\Q/\\E"); - if(f.length == 1) - { + if (f.length == 1) { return from(g); - } - - else if(f.length == 2) - { + } else if (f.length == 2) { return IrisProjectRepo.builder() .user(f[0]) .repo(f[1]) .build(); - } - - else if(f.length >= 3) - { + } else if (f.length >= 3) { IrisProjectRepo r = IrisProjectRepo.builder() .user(f[0]) .repo(f[1]) .build(); - if(f[2].startsWith("#")) - { + if (f[2].startsWith("#")) { r.setTag(f[2].substring(1)); - } - - else - { + } else { r.setBranch(f[2]); } return r; } - } - - else - { + } else { return IrisProjectRepo.builder() .user("IrisDimensions") .repo(g) @@ -104,10 +84,8 @@ public class IrisProjectRepo { return null; } - public String toURL() - { - if(!tag.trim().isEmpty()) - { + public String toURL() { + if (!tag.trim().isEmpty()) { return "https://codeload.github.com/" + user + "/" + repo + "/zip/refs/tags/" + tag; } diff --git a/src/main/java/com/volmit/iris/util/decree/DecreeContextHandler.java b/src/main/java/com/volmit/iris/util/decree/DecreeContextHandler.java index db325eabc..27d567102 100644 --- a/src/main/java/com/volmit/iris/util/decree/DecreeContextHandler.java +++ b/src/main/java/com/volmit/iris/util/decree/DecreeContextHandler.java @@ -1,3 +1,21 @@ +/* + * Iris is a World Generator for Minecraft Bukkit Servers + * Copyright (c) 2021 Arcane Arts (Volmit Software) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + package com.volmit.iris.util.decree; import com.volmit.iris.Iris; @@ -5,19 +23,15 @@ import com.volmit.iris.util.collection.KMap; import com.volmit.iris.util.plugin.VolmitSender; public interface DecreeContextHandler { - static KMap, DecreeContextHandler> contextHandlers = buildContextHandlers(); + KMap, DecreeContextHandler> contextHandlers = buildContextHandlers(); static KMap, DecreeContextHandler> buildContextHandlers() { KMap, DecreeContextHandler> contextHandlers = new KMap<>(); - try - { + try { Iris.initialize("com.volmit.iris.util.decree.context").forEach((i) - -> contextHandlers.put(((DecreeContextHandler)i).getType(), (DecreeContextHandler)i)); - } - - catch(Throwable e) - { + -> contextHandlers.put(((DecreeContextHandler) i).getType(), (DecreeContextHandler) i)); + } catch (Throwable e) { Iris.reportError(e); e.printStackTrace(); } diff --git a/src/main/java/com/volmit/iris/util/decree/DecreeExecutor.java b/src/main/java/com/volmit/iris/util/decree/DecreeExecutor.java index 5c27073f4..6f2753883 100644 --- a/src/main/java/com/volmit/iris/util/decree/DecreeExecutor.java +++ b/src/main/java/com/volmit/iris/util/decree/DecreeExecutor.java @@ -21,28 +21,23 @@ package com.volmit.iris.util.decree; import com.volmit.iris.core.tools.IrisToolbelt; import com.volmit.iris.engine.framework.Engine; import com.volmit.iris.engine.platform.PlatformChunkGenerator; -import com.volmit.iris.util.format.C; import com.volmit.iris.util.plugin.VolmitSender; import org.bukkit.World; import org.bukkit.entity.Player; public interface DecreeExecutor { - default VolmitSender sender() - { + default VolmitSender sender() { return DecreeContext.get(); } - default Player player() - { + default Player player() { return sender().player(); } - default Engine engine() - { - if(sender().isPlayer() && IrisToolbelt.access(sender().player().getWorld()) != null) - { + default Engine engine() { + if (sender().isPlayer() && IrisToolbelt.access(sender().player().getWorld()) != null) { PlatformChunkGenerator gen = IrisToolbelt.access(sender().player().getWorld()); - if (gen != null){ + if (gen != null) { return gen.getEngine(); } } @@ -50,24 +45,21 @@ public interface DecreeExecutor { return null; } - default PlatformChunkGenerator access() - { - if(sender().isPlayer()) { + default PlatformChunkGenerator access() { + if (sender().isPlayer()) { return IrisToolbelt.access(world()); } return null; } - default World world() - { - if (sender().isPlayer()){ + default World world() { + if (sender().isPlayer()) { return sender().player().getWorld(); } return null; } - default T get(T v, T ifUndefined) - { + default T get(T v, T ifUndefined) { return v == null ? ifUndefined : v; } } diff --git a/src/main/java/com/volmit/iris/util/decree/DecreeNode.java b/src/main/java/com/volmit/iris/util/decree/DecreeNode.java index e1d02713e..884ec3aff 100644 --- a/src/main/java/com/volmit/iris/util/decree/DecreeNode.java +++ b/src/main/java/com/volmit/iris/util/decree/DecreeNode.java @@ -25,7 +25,6 @@ import lombok.Data; import java.lang.reflect.Method; import java.lang.reflect.Parameter; -import java.util.Arrays; @Data public class DecreeNode { @@ -37,20 +36,20 @@ public class DecreeNode { this.instance = instance; this.method = method; this.decree = method.getDeclaredAnnotation(Decree.class); - if (decree == null){ + if (decree == null) { throw new RuntimeException("Cannot instantiate DecreeNode on method " + method.getName() + " in " + method.getDeclaringClass().getCanonicalName() + " not annotated by @Decree"); } } /** * Get the parameters of this decree node + * * @return The list of parameters if ALL are annotated by @{@link Param}, else null */ public KList getParameters() { KList p = new KList<>(); - for(Parameter i : method.getParameters()) - { + for (Parameter i : method.getParameters()) { p.add(new DecreeParameter(i)); } @@ -72,10 +71,8 @@ public class DecreeNode { public KList getNames() { KList d = new KList<>(); - for(String i : decree.aliases()) - { - if(i.isEmpty()) - { + for (String i : decree.aliases()) { + if (i.isEmpty()) { continue; } diff --git a/src/main/java/com/volmit/iris/util/decree/DecreeOrigin.java b/src/main/java/com/volmit/iris/util/decree/DecreeOrigin.java index eae213916..c234ce59e 100644 --- a/src/main/java/com/volmit/iris/util/decree/DecreeOrigin.java +++ b/src/main/java/com/volmit/iris/util/decree/DecreeOrigin.java @@ -30,11 +30,12 @@ public enum DecreeOrigin { /** * Check if the origin is valid for a sender + * * @param sender The sender to check * @return True if valid for origin */ - public boolean validFor(VolmitSender sender){ - if (sender.isPlayer()){ + public boolean validFor(VolmitSender sender) { + if (sender.isPlayer()) { return this.equals(PLAYER) || this.equals(BOTH); } else { return this.equals(CONSOLE) || this.equals(BOTH); diff --git a/src/main/java/com/volmit/iris/util/decree/DecreeParameter.java b/src/main/java/com/volmit/iris/util/decree/DecreeParameter.java index d327effa6..d10dae774 100644 --- a/src/main/java/com/volmit/iris/util/decree/DecreeParameter.java +++ b/src/main/java/com/volmit/iris/util/decree/DecreeParameter.java @@ -34,7 +34,7 @@ public class DecreeParameter { public DecreeParameter(Parameter parameter) { this.parameter = parameter; this.param = parameter.getDeclaredAnnotation(Param.class); - if (param == null){ + if (param == null) { throw new RuntimeException("Cannot instantiate DecreeParameter on " + parameter.getName() + " in method " + parameter.getDeclaringExecutable().getName() + "(...) in class " + parameter.getDeclaringExecutable().getDeclaringClass().getCanonicalName() + " not annotated by @Param"); } } @@ -62,10 +62,8 @@ public class DecreeParameter { public KList getNames() { KList d = new KList<>(); - for(String i : param.aliases()) - { - if(i.isEmpty()) - { + for (String i : param.aliases()) { + if (i.isEmpty()) { continue; } @@ -90,8 +88,7 @@ public class DecreeParameter { KList ff = getHandler().getPossibilities(); ff = ff != null ? ff : new KList<>(); KList f = ff.convert((i) -> getHandler().toStringForce(i)); - if(f.isEmpty()) - { + if (f.isEmpty()) { f = new KList<>(); f.add(getHandler().getRandomDefault()); } diff --git a/src/main/java/com/volmit/iris/util/decree/DecreeParameterHandler.java b/src/main/java/com/volmit/iris/util/decree/DecreeParameterHandler.java index e52d54fd4..5aa81c3ca 100644 --- a/src/main/java/com/volmit/iris/util/decree/DecreeParameterHandler.java +++ b/src/main/java/com/volmit/iris/util/decree/DecreeParameterHandler.java @@ -21,19 +21,20 @@ package com.volmit.iris.util.decree; import com.volmit.iris.util.collection.KList; import com.volmit.iris.util.decree.exceptions.DecreeParsingException; import com.volmit.iris.util.decree.exceptions.DecreeWhichException; -import org.jetbrains.annotations.NotNull; import java.util.concurrent.atomic.AtomicReference; public interface DecreeParameterHandler { /** * Should return the possible values for this type + * * @return Possibilities for this type. */ KList getPossibilities(); /** * Converting the type back to a string (inverse of the {@link #parse(String) parse} method) + * * @param t The input of the designated type to convert to a String * @return The resulting string */ @@ -41,25 +42,27 @@ public interface DecreeParameterHandler { /** * Forces conversion to the designated type before converting to a string using {@link #toString(T t)} + * * @param t The object to convert to string (that should be of this type) * @return The resulting string. */ - default String toStringForce(Object t) - { - return toString((T)t); + default String toStringForce(Object t) { + return toString((T) t); } /** * Should parse a String into the designated type + * * @param in The string to parse * @return The value extracted from the string, of the designated type * @throws DecreeParsingException Thrown when the parsing fails (ex: "oop" translated to an integer throws this) - * @throws DecreeWhichException Thrown when multiple results are possible + * @throws DecreeWhichException Thrown when multiple results are possible */ T parse(String in) throws DecreeParsingException, DecreeWhichException; /** * Returns whether a certain type is supported by this handler
+ * * @param type The type to check * @return True if supported, false if not */ @@ -67,13 +70,12 @@ public interface DecreeParameterHandler { /** * The possible entries for the inputted string (support for autocomplete on partial entries) + * * @param input The inputted string to check against * @return A {@link KList} of possibilities */ - default KList getPossibilities(String input) - { - if(input.trim().isEmpty()) - { + default KList getPossibilities(String input) { + if (input.trim().isEmpty()) { KList f = getPossibilities(); return f == null ? new KList<>() : f; } @@ -82,26 +84,23 @@ public interface DecreeParameterHandler { KList possible = getPossibilities(); KList matches = new KList<>(); - if (possible == null || possible.isEmpty()){ + if (possible == null || possible.isEmpty()) { return matches; } - if (input.isEmpty()) - { + if (input.isEmpty()) { return getPossibilities(); } KList converted = possible.convert(v -> toString(v).trim()); - for(int i = 0; i < converted.size(); i++) - { + for (int i = 0; i < converted.size(); i++) { String g = converted.get(i); // if // G == I or // I in G or // G in I - if(g.equalsIgnoreCase(input) || g.toLowerCase().contains(input.toLowerCase()) || input.toLowerCase().contains(g.toLowerCase())) - { + if (g.equalsIgnoreCase(input) || g.toLowerCase().contains(input.toLowerCase()) || input.toLowerCase().contains(g.toLowerCase())) { matches.add(possible.get(i)); } } @@ -109,54 +108,36 @@ public interface DecreeParameterHandler { return matches; } - default String getRandomDefault() - { + default String getRandomDefault() { return "NOEXAMPLE"; } - default double getMultiplier(AtomicReference g) - { + default double getMultiplier(AtomicReference g) { double multiplier = 1; String in = g.get(); boolean valid = true; - while(valid) { + while (valid) { boolean trim = false; - if (in.toLowerCase().endsWith("k")) - { + if (in.toLowerCase().endsWith("k")) { multiplier *= 1000; trim = true; - } - - else if(in.toLowerCase().endsWith("m")) - { + } else if (in.toLowerCase().endsWith("m")) { multiplier *= 1000000; trim = true; - } - - else if(in.toLowerCase().endsWith("h")) - { + } else if (in.toLowerCase().endsWith("h")) { multiplier *= 100; trim = true; - } - - else if(in.toLowerCase().endsWith("c")) - { + } else if (in.toLowerCase().endsWith("c")) { multiplier *= 16; trim = true; - } - - else if(in.toLowerCase().endsWith("r")) - { + } else if (in.toLowerCase().endsWith("r")) { multiplier *= (16 * 32); trim = true; - } - - else { + } else { valid = false; } - if(trim) - { + if (trim) { in = in.substring(0, in.length() - 1); } } diff --git a/src/main/java/com/volmit/iris/util/decree/DecreeSystem.java b/src/main/java/com/volmit/iris/util/decree/DecreeSystem.java index 547b6cbd1..afa9d0543 100644 --- a/src/main/java/com/volmit/iris/util/decree/DecreeSystem.java +++ b/src/main/java/com/volmit/iris/util/decree/DecreeSystem.java @@ -38,12 +38,12 @@ public interface DecreeSystem extends CommandExecutor, TabCompleter { /** * The root class to start command searching from + * * @return */ VirtualDecreeCommand getRoot(); - default boolean call(VolmitSender sender, String[] args) - { + default boolean call(VolmitSender sender, String[] args) { DecreeContext.touch(sender); return getRoot().invoke(sender, enhanceArgs(args)); } @@ -61,108 +61,77 @@ public interface DecreeSystem extends CommandExecutor, TabCompleter { @Override default boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) { J.aBukkit(() -> { - if(!call(new VolmitSender(sender), args)) - { + if (!call(new VolmitSender(sender), args)) { sender.sendMessage(C.RED + "Unknown Iris Command"); } }); return true; } - static KList enhanceArgs(String[] args) - { + static KList enhanceArgs(String[] args) { return enhanceArgs(args, true); } - static KList enhanceArgs(String[] args, boolean trim) - { + static KList enhanceArgs(String[] args, boolean trim) { KList a = new KList<>(); - if(args.length == 0) - { + if (args.length == 0) { return a; } StringBuilder flat = new StringBuilder(); - for(String i : args) - { - if(trim) - { - if(i.trim().isEmpty()) - { + for (String i : args) { + if (trim) { + if (i.trim().isEmpty()) { continue; } flat.append(" ").append(i.trim()); - } - - else - { - if(i.endsWith(" ")) - { + } else { + if (i.endsWith(" ")) { flat.append(" ").append(i.trim()).append(" "); } } } - flat = new StringBuilder(flat.length() > 0 ? trim ? flat.toString().trim().length() > 0 ?flat.substring(1).trim() : flat.toString().trim() : flat.substring(1) : flat); + flat = new StringBuilder(flat.length() > 0 ? trim ? flat.toString().trim().length() > 0 ? flat.substring(1).trim() : flat.toString().trim() : flat.substring(1) : flat); StringBuilder arg = new StringBuilder(); boolean quoting = false; - for(int x = 0; x < flat.length(); x++) - { + for (int x = 0; x < flat.length(); x++) { char i = flat.charAt(x); char j = x < flat.length() - 1 ? flat.charAt(x + 1) : i; boolean hasNext = x < flat.length(); - if(i == ' ' && !quoting) - { - if(!arg.toString().trim().isEmpty() && trim) - { + if (i == ' ' && !quoting) { + if (!arg.toString().trim().isEmpty() && trim) { a.add(arg.toString().trim()); arg = new StringBuilder(); } - } - - else if(i == '"') - { - if(!quoting && (arg.length() == 0)) - { + } else if (i == '"') { + if (!quoting && (arg.length() == 0)) { quoting = true; - } - - else if(quoting) - { + } else if (quoting) { quoting = false; - if(hasNext && j == ' ') - { - if(!arg.toString().trim().isEmpty() && trim) - { + if (hasNext && j == ' ') { + if (!arg.toString().trim().isEmpty() && trim) { a.add(arg.toString().trim()); arg = new StringBuilder(); } - } - - else if(!hasNext) - { - if(!arg.toString().trim().isEmpty() && trim) - { + } else if (!hasNext) { + if (!arg.toString().trim().isEmpty() && trim) { a.add(arg.toString().trim()); arg = new StringBuilder(); } } } - } - - else - { + } else { arg.append(i); } } - if(!arg.toString().trim().isEmpty() && trim) - { + if (!arg.toString().trim().isEmpty() && trim) { a.add(arg.toString().trim()); } @@ -171,14 +140,13 @@ public interface DecreeSystem extends CommandExecutor, TabCompleter { /** * Get the handler for the specified type + * * @param type The type to handle * @return The corresponding {@link DecreeParameterHandler}, or null */ static DecreeParameterHandler getHandler(Class type) { - for(DecreeParameterHandler i : handlers) - { - if(i.supports(type)) - { + for (DecreeParameterHandler i : handlers) { + if (i.supports(type)) { return i; } } diff --git a/src/main/java/com/volmit/iris/util/decree/annotations/Decree.java b/src/main/java/com/volmit/iris/util/decree/annotations/Decree.java index 5406e2fb0..847027429 100644 --- a/src/main/java/com/volmit/iris/util/decree/annotations/Decree.java +++ b/src/main/java/com/volmit/iris/util/decree/annotations/Decree.java @@ -38,6 +38,7 @@ public @interface Decree { /** * Only allow if studio mode is enabled + * * @return defaults to false */ boolean studio() default false; diff --git a/src/main/java/com/volmit/iris/util/decree/context/BiomeContextHandler.java b/src/main/java/com/volmit/iris/util/decree/context/BiomeContextHandler.java index d8c2012ae..7a48953a1 100644 --- a/src/main/java/com/volmit/iris/util/decree/context/BiomeContextHandler.java +++ b/src/main/java/com/volmit/iris/util/decree/context/BiomeContextHandler.java @@ -1,3 +1,21 @@ +/* + * Iris is a World Generator for Minecraft Bukkit Servers + * Copyright (c) 2021 Arcane Arts (Volmit Software) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + package com.volmit.iris.util.decree.context; import com.volmit.iris.core.tools.IrisToolbelt; @@ -6,14 +24,14 @@ import com.volmit.iris.util.decree.DecreeContextHandler; import com.volmit.iris.util.plugin.VolmitSender; public class BiomeContextHandler implements DecreeContextHandler { - public Class getType(){return IrisBiome.class;} + public Class getType() { + return IrisBiome.class; + } - public IrisBiome handle(VolmitSender sender) - { - if(sender.isPlayer() + public IrisBiome handle(VolmitSender sender) { + if (sender.isPlayer() && IrisToolbelt.isIrisWorld(sender.player().getWorld()) - && IrisToolbelt.access(sender.player().getWorld()).getEngine() != null) - { + && IrisToolbelt.access(sender.player().getWorld()).getEngine() != null) { return IrisToolbelt.access(sender.player().getWorld()).getEngine().getBiome(sender.player().getLocation()); } diff --git a/src/main/java/com/volmit/iris/util/decree/context/DimensionContextHandler.java b/src/main/java/com/volmit/iris/util/decree/context/DimensionContextHandler.java index 90025baad..fe271f759 100644 --- a/src/main/java/com/volmit/iris/util/decree/context/DimensionContextHandler.java +++ b/src/main/java/com/volmit/iris/util/decree/context/DimensionContextHandler.java @@ -1,3 +1,21 @@ +/* + * Iris is a World Generator for Minecraft Bukkit Servers + * Copyright (c) 2021 Arcane Arts (Volmit Software) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + package com.volmit.iris.util.decree.context; import com.volmit.iris.core.tools.IrisToolbelt; @@ -6,14 +24,14 @@ import com.volmit.iris.util.decree.DecreeContextHandler; import com.volmit.iris.util.plugin.VolmitSender; public class DimensionContextHandler implements DecreeContextHandler { - public Class getType(){return IrisDimension.class;} + public Class getType() { + return IrisDimension.class; + } - public IrisDimension handle(VolmitSender sender) - { - if(sender.isPlayer() + public IrisDimension handle(VolmitSender sender) { + if (sender.isPlayer() && IrisToolbelt.isIrisWorld(sender.player().getWorld()) - && IrisToolbelt.access(sender.player().getWorld()).getEngine() != null) - { + && IrisToolbelt.access(sender.player().getWorld()).getEngine() != null) { return IrisToolbelt.access(sender.player().getWorld()).getEngine().getDimension(); } diff --git a/src/main/java/com/volmit/iris/util/decree/context/GeneratorContextHandler.java b/src/main/java/com/volmit/iris/util/decree/context/GeneratorContextHandler.java index 0e23c0f62..e5b520b24 100644 --- a/src/main/java/com/volmit/iris/util/decree/context/GeneratorContextHandler.java +++ b/src/main/java/com/volmit/iris/util/decree/context/GeneratorContextHandler.java @@ -1,3 +1,21 @@ +/* + * Iris is a World Generator for Minecraft Bukkit Servers + * Copyright (c) 2021 Arcane Arts (Volmit Software) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + package com.volmit.iris.util.decree.context; import com.volmit.iris.core.tools.IrisToolbelt; @@ -14,10 +32,9 @@ public class GeneratorContextHandler implements DecreeContextHandler. + */ + package com.volmit.iris.util.decree.context; import com.volmit.iris.core.tools.IrisToolbelt; @@ -6,14 +24,14 @@ import com.volmit.iris.util.decree.DecreeContextHandler; import com.volmit.iris.util.plugin.VolmitSender; public class RegionContextHandler implements DecreeContextHandler { - public Class getType(){return IrisRegion.class;} + public Class getType() { + return IrisRegion.class; + } - public IrisRegion handle(VolmitSender sender) - { - if(sender.isPlayer() + public IrisRegion handle(VolmitSender sender) { + if (sender.isPlayer() && IrisToolbelt.isIrisWorld(sender.player().getWorld()) - && IrisToolbelt.access(sender.player().getWorld()).getEngine() != null) - { + && IrisToolbelt.access(sender.player().getWorld()).getEngine() != null) { return IrisToolbelt.access(sender.player().getWorld()).getEngine().getRegion(sender.player().getLocation()); } diff --git a/src/main/java/com/volmit/iris/util/decree/context/WorldContextHandler.java b/src/main/java/com/volmit/iris/util/decree/context/WorldContextHandler.java index 44880df15..a19e5ae22 100644 --- a/src/main/java/com/volmit/iris/util/decree/context/WorldContextHandler.java +++ b/src/main/java/com/volmit/iris/util/decree/context/WorldContextHandler.java @@ -1,3 +1,21 @@ +/* + * Iris is a World Generator for Minecraft Bukkit Servers + * Copyright (c) 2021 Arcane Arts (Volmit Software) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + package com.volmit.iris.util.decree.context; import com.volmit.iris.util.decree.DecreeContextHandler; @@ -5,10 +23,11 @@ import com.volmit.iris.util.plugin.VolmitSender; import org.bukkit.World; public class WorldContextHandler implements DecreeContextHandler { - public Class getType(){return World.class;} + public Class getType() { + return World.class; + } - public World handle(VolmitSender sender) - { + public World handle(VolmitSender sender) { return sender.isPlayer() ? sender.player().getWorld() : null; } } diff --git a/src/main/java/com/volmit/iris/util/decree/exceptions/DecreeParsingException.java b/src/main/java/com/volmit/iris/util/decree/exceptions/DecreeParsingException.java index 42dcf7a67..9ae308d82 100644 --- a/src/main/java/com/volmit/iris/util/decree/exceptions/DecreeParsingException.java +++ b/src/main/java/com/volmit/iris/util/decree/exceptions/DecreeParsingException.java @@ -21,7 +21,7 @@ package com.volmit.iris.util.decree.exceptions; /** * Thrown when a decree parameter is parsed, but parsing fails */ -public class DecreeParsingException extends Exception{ +public class DecreeParsingException extends Exception { public DecreeParsingException(String message) { super(message); } diff --git a/src/main/java/com/volmit/iris/util/decree/exceptions/DecreeWhichException.java b/src/main/java/com/volmit/iris/util/decree/exceptions/DecreeWhichException.java index 1a34ec754..36486a937 100644 --- a/src/main/java/com/volmit/iris/util/decree/exceptions/DecreeWhichException.java +++ b/src/main/java/com/volmit/iris/util/decree/exceptions/DecreeWhichException.java @@ -18,13 +18,11 @@ package com.volmit.iris.util.decree.exceptions; -import com.volmit.iris.util.collection.KList; - /** * Thrown when more than one option is available for a singular mapping
* Like having a hashmap where one input maps to two outputs. */ -public class DecreeWhichException extends Exception{ +public class DecreeWhichException extends Exception { public DecreeWhichException() { super(); } diff --git a/src/main/java/com/volmit/iris/util/decree/handlers/BiomeHandler.java b/src/main/java/com/volmit/iris/util/decree/handlers/BiomeHandler.java index 1409cf14e..deb687b79 100644 --- a/src/main/java/com/volmit/iris/util/decree/handlers/BiomeHandler.java +++ b/src/main/java/com/volmit/iris/util/decree/handlers/BiomeHandler.java @@ -21,13 +21,11 @@ package com.volmit.iris.util.decree.handlers; import com.volmit.iris.Iris; import com.volmit.iris.core.project.loader.IrisData; import com.volmit.iris.engine.object.biome.IrisBiome; -import com.volmit.iris.engine.object.dimensional.IrisDimension; import com.volmit.iris.util.collection.KList; import com.volmit.iris.util.collection.KMap; import com.volmit.iris.util.decree.DecreeParameterHandler; import com.volmit.iris.util.decree.exceptions.DecreeParsingException; import com.volmit.iris.util.decree.exceptions.DecreeWhichException; -import com.volmit.iris.util.math.RNG; import java.io.File; @@ -37,12 +35,10 @@ public class BiomeHandler implements DecreeParameterHandler { KMap p = new KMap<>(); //noinspection ConstantConditions - for(File i : Iris.instance.getDataFolder("packs").listFiles()) - { - if(i.isDirectory()) { + for (File i : Iris.instance.getDataFolder("packs").listFiles()) { + if (i.isDirectory()) { IrisData data = new IrisData(i, true); - for (IrisBiome j : data.getBiomeLoader().loadAll(data.getBiomeLoader().getPossibleKeys())) - { + for (IrisBiome j : data.getBiomeLoader().loadAll(data.getBiomeLoader().getPossibleKeys())) { p.putIfAbsent(j.getLoadKey(), j); } @@ -60,27 +56,19 @@ public class BiomeHandler implements DecreeParameterHandler { @Override public IrisBiome parse(String in) throws DecreeParsingException, DecreeWhichException { - try - { + try { KList options = getPossibilities(in); - if(options.isEmpty()) - { + if (options.isEmpty()) { throw new DecreeParsingException("Unable to find Biome \"" + in + "\""); - } - - else if(options.size() > 1) - { + } else if (options.size() > 1) { throw new DecreeWhichException(); } return options.get(0); - } - catch(DecreeParsingException e){ + } catch (DecreeParsingException e) { throw e; - } - catch(Throwable e) - { + } catch (Throwable e) { throw new DecreeParsingException("Unable to find Biome \"" + in + "\" because of an uncaught exception: " + e); } } @@ -91,8 +79,7 @@ public class BiomeHandler implements DecreeParameterHandler { } @Override - public String getRandomDefault() - { + public String getRandomDefault() { return "biome"; } } diff --git a/src/main/java/com/volmit/iris/util/decree/handlers/BlockVectorHandler.java b/src/main/java/com/volmit/iris/util/decree/handlers/BlockVectorHandler.java index b499295f3..61adc04b0 100644 --- a/src/main/java/com/volmit/iris/util/decree/handlers/BlockVectorHandler.java +++ b/src/main/java/com/volmit/iris/util/decree/handlers/BlockVectorHandler.java @@ -30,7 +30,6 @@ import com.volmit.iris.util.plugin.VolmitSender; import org.bukkit.FluidCollisionMode; import org.bukkit.entity.Player; import org.bukkit.util.BlockVector; -import org.bukkit.util.Vector; public class BlockVectorHandler implements DecreeParameterHandler { @Override @@ -38,8 +37,7 @@ public class BlockVectorHandler implements DecreeParameterHandler { KList vx = new KList<>(); VolmitSender s = DecreeContext.get(); - if(s.isPlayer()) - { + if (s.isPlayer()) { vx.add(s.player().getLocation().toVector().toBlockVector()); } @@ -48,9 +46,8 @@ public class BlockVectorHandler implements DecreeParameterHandler { @Override public String toString(BlockVector v) { - if(v.getY() == 0) - { - return Form.f(v.getBlockX(), 2)+ "," + Form.f(v.getBlockZ(), 2); + if (v.getY() == 0) { + return Form.f(v.getBlockX(), 2) + "," + Form.f(v.getBlockZ(), 2); } return Form.f(v.getBlockX(), 2) + "," + Form.f(v.getBlockY(), 2) + "," + Form.f(v.getBlockZ(), 2); @@ -59,69 +56,43 @@ public class BlockVectorHandler implements DecreeParameterHandler { @Override public BlockVector parse(String in) throws DecreeParsingException, DecreeWhichException { try { - if (in.contains(",")) - { + if (in.contains(",")) { String[] comp = in.split("\\Q,\\E"); - if(comp.length == 2) - { + if (comp.length == 2) { return new BlockVector(Integer.parseInt(comp[0].trim()), 0, Integer.parseInt(comp[1].trim())); - } - - else if(comp.length == 3) - { + } else if (comp.length == 3) { return new BlockVector(Integer.parseInt(comp[0].trim()), Integer.parseInt(comp[1].trim()), Integer.parseInt(comp[2].trim())); - } - - else - { + } else { throw new DecreeParsingException("Could not parse components for vector. You have " + comp.length + " components. Expected 2 or 3."); } - } - - else if(in.equalsIgnoreCase("here") ||in.equalsIgnoreCase("me") ||in.equalsIgnoreCase("self")) - { - if(!DecreeContext.get().isPlayer()) - { + } else if (in.equalsIgnoreCase("here") || in.equalsIgnoreCase("me") || in.equalsIgnoreCase("self")) { + if (!DecreeContext.get().isPlayer()) { throw new DecreeParsingException("You cannot specify me,self,here as a console."); } return DecreeContext.get().player().getLocation().toVector().toBlockVector(); - } - - else if(in.equalsIgnoreCase("look") ||in.equalsIgnoreCase("cursor") ||in.equalsIgnoreCase("crosshair")) - { - if(!DecreeContext.get().isPlayer()) - { + } else if (in.equalsIgnoreCase("look") || in.equalsIgnoreCase("cursor") || in.equalsIgnoreCase("crosshair")) { + if (!DecreeContext.get().isPlayer()) { throw new DecreeParsingException("You cannot specify look,cursor,crosshair as a console."); } return DecreeContext.get().player().getTargetBlockExact(256, FluidCollisionMode.NEVER).getLocation().toVector().toBlockVector(); - } - - else if(in.trim().toLowerCase().startsWith("player:")) - { + } else if (in.trim().toLowerCase().startsWith("player:")) { String v = in.trim().split("\\Q:\\E")[1]; KList px = DecreeSystem.getHandler(Player.class).getPossibilities(v); - if(px != null && px.isNotEmpty()) - { - return ((Player)px.get(0)).getLocation().toVector().toBlockVector(); - } - - else if(px == null || px.isEmpty()) - { + if (px != null && px.isNotEmpty()) { + return ((Player) px.get(0)).getLocation().toVector().toBlockVector(); + } else if (px == null || px.isEmpty()) { throw new DecreeParsingException("Cannot find player: " + v); } } - } - - catch(Throwable e) - { + } catch (Throwable e) { throw new DecreeParsingException("Unable to get Vector for \"" + in + "\" because of an uncaught exception: " + e); } @@ -134,8 +105,7 @@ public class BlockVectorHandler implements DecreeParameterHandler { } @Override - public String getRandomDefault() - { + public String getRandomDefault() { return M.r(0.5) ? "0,0" : "0,0,0"; } } diff --git a/src/main/java/com/volmit/iris/util/decree/handlers/BooleanHandler.java b/src/main/java/com/volmit/iris/util/decree/handlers/BooleanHandler.java index 6a7f1ba98..e61de78ad 100644 --- a/src/main/java/com/volmit/iris/util/decree/handlers/BooleanHandler.java +++ b/src/main/java/com/volmit/iris/util/decree/handlers/BooleanHandler.java @@ -22,7 +22,6 @@ import com.volmit.iris.util.collection.KList; import com.volmit.iris.util.decree.DecreeParameterHandler; import com.volmit.iris.util.decree.exceptions.DecreeParsingException; import com.volmit.iris.util.math.M; -import com.volmit.iris.util.math.RNG; public class BooleanHandler implements DecreeParameterHandler { @Override @@ -37,13 +36,9 @@ public class BooleanHandler implements DecreeParameterHandler { @Override public Boolean parse(String in) throws DecreeParsingException { - try - { + try { return Boolean.parseBoolean(in); - } - - catch(Throwable e) - { + } catch (Throwable e) { throw new DecreeParsingException("Unable to parse boolean \"" + in + "\""); } } @@ -54,8 +49,7 @@ public class BooleanHandler implements DecreeParameterHandler { } @Override - public String getRandomDefault() - { + public String getRandomDefault() { return M.r(0.5) + ""; } } diff --git a/src/main/java/com/volmit/iris/util/decree/handlers/ByteHandler.java b/src/main/java/com/volmit/iris/util/decree/handlers/ByteHandler.java index 1fee2277b..4321013f7 100644 --- a/src/main/java/com/volmit/iris/util/decree/handlers/ByteHandler.java +++ b/src/main/java/com/volmit/iris/util/decree/handlers/ByteHandler.java @@ -36,13 +36,9 @@ public class ByteHandler implements DecreeParameterHandler { @Override public Byte parse(String in) throws DecreeParsingException { - try - { + try { return Byte.parseByte(in); - } - - catch(Throwable e) - { + } catch (Throwable e) { throw new DecreeParsingException("Unable to parse byte \"" + in + "\""); } } @@ -53,8 +49,7 @@ public class ByteHandler implements DecreeParameterHandler { } @Override - public String getRandomDefault() - { + public String getRandomDefault() { return RNG.r.i(0, Byte.MAX_VALUE) + ""; } } diff --git a/src/main/java/com/volmit/iris/util/decree/handlers/DimensionHandler.java b/src/main/java/com/volmit/iris/util/decree/handlers/DimensionHandler.java index bb5aa88fa..b22f6b073 100644 --- a/src/main/java/com/volmit/iris/util/decree/handlers/DimensionHandler.java +++ b/src/main/java/com/volmit/iris/util/decree/handlers/DimensionHandler.java @@ -26,8 +26,6 @@ import com.volmit.iris.util.collection.KMap; import com.volmit.iris.util.decree.DecreeParameterHandler; import com.volmit.iris.util.decree.exceptions.DecreeParsingException; import com.volmit.iris.util.decree.exceptions.DecreeWhichException; -import org.bukkit.Bukkit; -import org.bukkit.World; import java.io.File; @@ -37,12 +35,10 @@ public class DimensionHandler implements DecreeParameterHandler { KMap p = new KMap<>(); //noinspection ConstantConditions - for(File i : Iris.instance.getDataFolder("packs").listFiles()) - { - if(i.isDirectory()) { + for (File i : Iris.instance.getDataFolder("packs").listFiles()) { + if (i.isDirectory()) { IrisData data = new IrisData(i, true); - for (IrisDimension j : data.getDimensionLoader().loadAll(data.getDimensionLoader().getPossibleKeys())) - { + for (IrisDimension j : data.getDimensionLoader().loadAll(data.getDimensionLoader().getPossibleKeys())) { p.putIfAbsent(j.getLoadKey(), j); } @@ -60,27 +56,19 @@ public class DimensionHandler implements DecreeParameterHandler { @Override public IrisDimension parse(String in) throws DecreeParsingException, DecreeWhichException { - try - { + try { KList options = getPossibilities(in); - if(options.isEmpty()) - { + if (options.isEmpty()) { throw new DecreeParsingException("Unable to find Dimension \"" + in + "\""); - } - - else if(options.size() > 1) - { + } else if (options.size() > 1) { throw new DecreeWhichException(); } return options.get(0); - } - catch(DecreeParsingException e){ + } catch (DecreeParsingException e) { throw e; - } - catch(Throwable e) - { + } catch (Throwable e) { throw new DecreeParsingException("Unable to find Dimension \"" + in + "\" because of an uncaught exception: " + e); } } @@ -91,8 +79,7 @@ public class DimensionHandler implements DecreeParameterHandler { } @Override - public String getRandomDefault() - { + public String getRandomDefault() { return "dimension"; } } diff --git a/src/main/java/com/volmit/iris/util/decree/handlers/DoubleHandler.java b/src/main/java/com/volmit/iris/util/decree/handlers/DoubleHandler.java index 0fc5577ea..51a0f06fe 100644 --- a/src/main/java/com/volmit/iris/util/decree/handlers/DoubleHandler.java +++ b/src/main/java/com/volmit/iris/util/decree/handlers/DoubleHandler.java @@ -34,15 +34,11 @@ public class DoubleHandler implements DecreeParameterHandler { @Override public Double parse(String in) throws DecreeParsingException { - try - { + try { AtomicReference r = new AtomicReference<>(in); double m = getMultiplier(r); return Double.parseDouble(r.get()) * m; - } - - catch(Throwable e) - { + } catch (Throwable e) { throw new DecreeParsingException("Unable to parse double \"" + in + "\""); } } @@ -58,8 +54,7 @@ public class DoubleHandler implements DecreeParameterHandler { } @Override - public String getRandomDefault() - { + public String getRandomDefault() { return Form.f(RNG.r.d(0, 99.99), 1) + ""; } } diff --git a/src/main/java/com/volmit/iris/util/decree/handlers/EntityHandler.java b/src/main/java/com/volmit/iris/util/decree/handlers/EntityHandler.java index ac4d35d56..f3c5b43f2 100644 --- a/src/main/java/com/volmit/iris/util/decree/handlers/EntityHandler.java +++ b/src/main/java/com/volmit/iris/util/decree/handlers/EntityHandler.java @@ -1,8 +1,25 @@ +/* + * Iris is a World Generator for Minecraft Bukkit Servers + * Copyright (c) 2021 Arcane Arts (Volmit Software) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + package com.volmit.iris.util.decree.handlers; import com.volmit.iris.Iris; import com.volmit.iris.core.project.loader.IrisData; -import com.volmit.iris.engine.object.dimensional.IrisDimension; import com.volmit.iris.engine.object.entity.IrisEntity; import com.volmit.iris.util.collection.KList; import com.volmit.iris.util.collection.KMap; @@ -24,12 +41,10 @@ public class EntityHandler implements DecreeParameterHandler { KMap p = new KMap<>(); //noinspection ConstantConditions - for(File i : Iris.instance.getDataFolder("packs").listFiles()) - { - if(i.isDirectory()) { + for (File i : Iris.instance.getDataFolder("packs").listFiles()) { + if (i.isDirectory()) { IrisData data = new IrisData(i, true); - for (IrisEntity j : data.getEntityLoader().loadAll(data.getEntityLoader().getPossibleKeys())) - { + for (IrisEntity j : data.getEntityLoader().loadAll(data.getEntityLoader().getPossibleKeys())) { p.putIfAbsent(j.getLoadKey(), j); } @@ -61,27 +76,19 @@ public class EntityHandler implements DecreeParameterHandler { */ @Override public IrisEntity parse(String in) throws DecreeParsingException, DecreeWhichException { - try - { + try { KList options = getPossibilities(in); - if(options.isEmpty()) - { + if (options.isEmpty()) { throw new DecreeParsingException("Unable to find Entity \"" + in + "\""); - } - - else if(options.size() > 1) - { + } else if (options.size() > 1) { throw new DecreeWhichException(); } return options.get(0); - } - catch(DecreeParsingException e){ + } catch (DecreeParsingException e) { throw e; - } - catch(Throwable e) - { + } catch (Throwable e) { throw new DecreeParsingException("Unable to find Entity \"" + in + "\" because of an uncaught exception: " + e); } } @@ -98,8 +105,7 @@ public class EntityHandler implements DecreeParameterHandler { } @Override - public String getRandomDefault() - { + public String getRandomDefault() { return "entity"; } } diff --git a/src/main/java/com/volmit/iris/util/decree/handlers/FloatHandler.java b/src/main/java/com/volmit/iris/util/decree/handlers/FloatHandler.java index 8f7942ca4..e2a4d4901 100644 --- a/src/main/java/com/volmit/iris/util/decree/handlers/FloatHandler.java +++ b/src/main/java/com/volmit/iris/util/decree/handlers/FloatHandler.java @@ -34,15 +34,11 @@ public class FloatHandler implements DecreeParameterHandler { @Override public Float parse(String in) throws DecreeParsingException { - try - { + try { AtomicReference r = new AtomicReference<>(in); double m = getMultiplier(r); - return (float)(Float.parseFloat(r.get()) * m); - } - - catch(Throwable e) - { + return (float) (Float.parseFloat(r.get()) * m); + } catch (Throwable e) { throw new DecreeParsingException("Unable to parse float \"" + in + "\""); } } @@ -58,8 +54,7 @@ public class FloatHandler implements DecreeParameterHandler { } @Override - public String getRandomDefault() - { + public String getRandomDefault() { return Form.f(RNG.r.d(0, 99.99), 1) + ""; } } diff --git a/src/main/java/com/volmit/iris/util/decree/handlers/GeneratorHandler.java b/src/main/java/com/volmit/iris/util/decree/handlers/GeneratorHandler.java index 62d0c2545..108b39f89 100644 --- a/src/main/java/com/volmit/iris/util/decree/handlers/GeneratorHandler.java +++ b/src/main/java/com/volmit/iris/util/decree/handlers/GeneratorHandler.java @@ -1,3 +1,21 @@ +/* + * Iris is a World Generator for Minecraft Bukkit Servers + * Copyright (c) 2021 Arcane Arts (Volmit Software) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + package com.volmit.iris.util.decree.handlers; import com.volmit.iris.Iris; @@ -17,12 +35,10 @@ public class GeneratorHandler implements DecreeParameterHandler { KMap p = new KMap<>(); //noinspection ConstantConditions - for(File i : Iris.instance.getDataFolder("packs").listFiles()) - { - if(i.isDirectory()) { + for (File i : Iris.instance.getDataFolder("packs").listFiles()) { + if (i.isDirectory()) { IrisData data = new IrisData(i, true); - for (IrisGenerator j : data.getGeneratorLoader().loadAll(data.getGeneratorLoader().getPossibleKeys())) - { + for (IrisGenerator j : data.getGeneratorLoader().loadAll(data.getGeneratorLoader().getPossibleKeys())) { p.putIfAbsent(j.getLoadKey(), j); } @@ -40,27 +56,19 @@ public class GeneratorHandler implements DecreeParameterHandler { @Override public IrisGenerator parse(String in) throws DecreeParsingException, DecreeWhichException { - try - { + try { KList options = getPossibilities(in); - if(options.isEmpty()) - { + if (options.isEmpty()) { throw new DecreeParsingException("Unable to find Generator \"" + in + "\""); - } - - else if(options.size() > 1) - { + } else if (options.size() > 1) { throw new DecreeWhichException(); } return options.get(0); - } - catch(DecreeParsingException e){ + } catch (DecreeParsingException e) { throw e; - } - catch(Throwable e) - { + } catch (Throwable e) { throw new DecreeParsingException("Unable to find Generator \"" + in + "\" because of an uncaught exception: " + e); } } @@ -71,8 +79,7 @@ public class GeneratorHandler implements DecreeParameterHandler { } @Override - public String getRandomDefault() - { + public String getRandomDefault() { return "generator"; } } diff --git a/src/main/java/com/volmit/iris/util/decree/handlers/IntegerHandler.java b/src/main/java/com/volmit/iris/util/decree/handlers/IntegerHandler.java index 454866a2f..1c7588675 100644 --- a/src/main/java/com/volmit/iris/util/decree/handlers/IntegerHandler.java +++ b/src/main/java/com/volmit/iris/util/decree/handlers/IntegerHandler.java @@ -21,10 +21,8 @@ package com.volmit.iris.util.decree.handlers; import com.volmit.iris.util.collection.KList; import com.volmit.iris.util.decree.DecreeParameterHandler; import com.volmit.iris.util.decree.exceptions.DecreeParsingException; -import com.volmit.iris.util.format.Form; import com.volmit.iris.util.math.RNG; -import java.util.Locale; import java.util.concurrent.atomic.AtomicReference; public class IntegerHandler implements DecreeParameterHandler { @@ -35,15 +33,11 @@ public class IntegerHandler implements DecreeParameterHandler { @Override public Integer parse(String in) throws DecreeParsingException { - try - { + try { AtomicReference r = new AtomicReference<>(in); double m = getMultiplier(r); - return (int)(Integer.valueOf(r.get()).doubleValue() * m); - } - - catch(Throwable e) - { + return (int) (Integer.valueOf(r.get()).doubleValue() * m); + } catch (Throwable e) { throw new DecreeParsingException("Unable to parse integer \"" + in + "\""); } } @@ -59,8 +53,7 @@ public class IntegerHandler implements DecreeParameterHandler { } @Override - public String getRandomDefault() - { + public String getRandomDefault() { return RNG.r.i(0, 99) + ""; } } diff --git a/src/main/java/com/volmit/iris/util/decree/handlers/LongHandler.java b/src/main/java/com/volmit/iris/util/decree/handlers/LongHandler.java index cfe40ea33..51c88bbda 100644 --- a/src/main/java/com/volmit/iris/util/decree/handlers/LongHandler.java +++ b/src/main/java/com/volmit/iris/util/decree/handlers/LongHandler.java @@ -33,15 +33,11 @@ public class LongHandler implements DecreeParameterHandler { @Override public Long parse(String in) throws DecreeParsingException { - try - { + try { AtomicReference r = new AtomicReference<>(in); double m = getMultiplier(r); - return (long)(Long.valueOf(r.get()).doubleValue() * m); - } - - catch(Throwable e) - { + return (long) (Long.valueOf(r.get()).doubleValue() * m); + } catch (Throwable e) { throw new DecreeParsingException("Unable to parse long \"" + in + "\""); } } @@ -57,8 +53,7 @@ public class LongHandler implements DecreeParameterHandler { } @Override - public String getRandomDefault() - { + public String getRandomDefault() { return RNG.r.i(0, 99) + ""; } } diff --git a/src/main/java/com/volmit/iris/util/decree/handlers/PlayerHandler.java b/src/main/java/com/volmit/iris/util/decree/handlers/PlayerHandler.java index 5f0e395d6..fde4d88cb 100644 --- a/src/main/java/com/volmit/iris/util/decree/handlers/PlayerHandler.java +++ b/src/main/java/com/volmit/iris/util/decree/handlers/PlayerHandler.java @@ -40,25 +40,17 @@ public class PlayerHandler implements DecreeParameterHandler { @Override public Player parse(String in) throws DecreeParsingException, DecreeWhichException { - try - { + try { KList options = getPossibilities(in); - if(options.isEmpty()) - { + if (options.isEmpty()) { throw new DecreeParsingException("Unable to find Player \"" + in + "\""); - } - - else if(options.size() > 1) - { + } else if (options.size() > 1) { throw new DecreeWhichException(); } return options.get(0); - } - - catch(Throwable e) - { + } catch (Throwable e) { throw new DecreeParsingException("Unable to find Player \"" + in + "\" because of an uncaught exception: " + e); } } @@ -69,8 +61,7 @@ public class PlayerHandler implements DecreeParameterHandler { } @Override - public String getRandomDefault() - { + public String getRandomDefault() { return "playername"; } } diff --git a/src/main/java/com/volmit/iris/util/decree/handlers/RegionHandler.java b/src/main/java/com/volmit/iris/util/decree/handlers/RegionHandler.java index 58dd64757..d2ba36ddc 100644 --- a/src/main/java/com/volmit/iris/util/decree/handlers/RegionHandler.java +++ b/src/main/java/com/volmit/iris/util/decree/handlers/RegionHandler.java @@ -35,12 +35,10 @@ public class RegionHandler implements DecreeParameterHandler { KMap p = new KMap<>(); //noinspection ConstantConditions - for(File i : Iris.instance.getDataFolder("packs").listFiles()) - { - if(i.isDirectory()) { + for (File i : Iris.instance.getDataFolder("packs").listFiles()) { + if (i.isDirectory()) { IrisData data = new IrisData(i, true); - for (IrisRegion j : data.getRegionLoader().loadAll(data.getRegionLoader().getPossibleKeys())) - { + for (IrisRegion j : data.getRegionLoader().loadAll(data.getRegionLoader().getPossibleKeys())) { p.putIfAbsent(j.getLoadKey(), j); } @@ -58,27 +56,19 @@ public class RegionHandler implements DecreeParameterHandler { @Override public IrisRegion parse(String in) throws DecreeParsingException, DecreeWhichException { - try - { + try { KList options = getPossibilities(in); - if(options.isEmpty()) - { + if (options.isEmpty()) { throw new DecreeParsingException("Unable to find Region \"" + in + "\""); - } - - else if(options.size() > 1) - { + } else if (options.size() > 1) { throw new DecreeWhichException(); } return options.get(0); - } - catch(DecreeParsingException e){ + } catch (DecreeParsingException e) { throw e; - } - catch(Throwable e) - { + } catch (Throwable e) { throw new DecreeParsingException("Unable to find Region \"" + in + "\" because of an uncaught exception: " + e); } } @@ -89,8 +79,7 @@ public class RegionHandler implements DecreeParameterHandler { } @Override - public String getRandomDefault() - { + public String getRandomDefault() { return "region"; } } diff --git a/src/main/java/com/volmit/iris/util/decree/handlers/ScriptHandler.java b/src/main/java/com/volmit/iris/util/decree/handlers/ScriptHandler.java index 3e8315d0c..1f3bfc615 100644 --- a/src/main/java/com/volmit/iris/util/decree/handlers/ScriptHandler.java +++ b/src/main/java/com/volmit/iris/util/decree/handlers/ScriptHandler.java @@ -1,3 +1,21 @@ +/* + * Iris is a World Generator for Minecraft Bukkit Servers + * Copyright (c) 2021 Arcane Arts (Volmit Software) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + package com.volmit.iris.util.decree.handlers; import com.volmit.iris.Iris; @@ -17,12 +35,10 @@ public class ScriptHandler implements DecreeParameterHandler { KMap p = new KMap<>(); //noinspection ConstantConditions - for(File i : Iris.instance.getDataFolder("packs").listFiles()) - { - if(i.isDirectory()) { + for (File i : Iris.instance.getDataFolder("packs").listFiles()) { + if (i.isDirectory()) { IrisData data = new IrisData(i, true); - for (IrisScript j : data.getScriptLoader().loadAll(data.getScriptLoader().getPossibleKeys())) - { + for (IrisScript j : data.getScriptLoader().loadAll(data.getScriptLoader().getPossibleKeys())) { p.putIfAbsent(j.getLoadKey(), j); } @@ -40,27 +56,19 @@ public class ScriptHandler implements DecreeParameterHandler { @Override public IrisScript parse(String in) throws DecreeParsingException, DecreeWhichException { - try - { + try { KList options = getPossibilities(in); - if(options.isEmpty()) - { + if (options.isEmpty()) { throw new DecreeParsingException("Unable to find Script \"" + in + "\""); - } - - else if(options.size() > 1) - { + } else if (options.size() > 1) { throw new DecreeWhichException(); } return options.get(0); - } - catch(DecreeParsingException e){ + } catch (DecreeParsingException e) { throw e; - } - catch(Throwable e) - { + } catch (Throwable e) { throw new DecreeParsingException("Unable to find Script \"" + in + "\" because of an uncaught exception: " + e); } } @@ -71,8 +79,7 @@ public class ScriptHandler implements DecreeParameterHandler { } @Override - public String getRandomDefault() - { + public String getRandomDefault() { return "script"; } } diff --git a/src/main/java/com/volmit/iris/util/decree/handlers/ShortHandler.java b/src/main/java/com/volmit/iris/util/decree/handlers/ShortHandler.java index 174f20d47..42472aa73 100644 --- a/src/main/java/com/volmit/iris/util/decree/handlers/ShortHandler.java +++ b/src/main/java/com/volmit/iris/util/decree/handlers/ShortHandler.java @@ -33,15 +33,11 @@ public class ShortHandler implements DecreeParameterHandler { @Override public Short parse(String in) throws DecreeParsingException { - try - { + try { AtomicReference r = new AtomicReference<>(in); double m = getMultiplier(r); - return (short)(Short.valueOf(r.get()).doubleValue() * m); - } - - catch(Throwable e) - { + return (short) (Short.valueOf(r.get()).doubleValue() * m); + } catch (Throwable e) { throw new DecreeParsingException("Unable to parse short \"" + in + "\""); } } @@ -57,8 +53,7 @@ public class ShortHandler implements DecreeParameterHandler { } @Override - public String getRandomDefault() - { + public String getRandomDefault() { return RNG.r.i(0, 99) + ""; } } diff --git a/src/main/java/com/volmit/iris/util/decree/handlers/StringHandler.java b/src/main/java/com/volmit/iris/util/decree/handlers/StringHandler.java index 501b446cc..f960db407 100644 --- a/src/main/java/com/volmit/iris/util/decree/handlers/StringHandler.java +++ b/src/main/java/com/volmit/iris/util/decree/handlers/StringHandler.java @@ -21,7 +21,6 @@ package com.volmit.iris.util.decree.handlers; import com.volmit.iris.util.collection.KList; import com.volmit.iris.util.decree.DecreeParameterHandler; import com.volmit.iris.util.decree.exceptions.DecreeParsingException; -import com.volmit.iris.util.math.RNG; /** * Abstraction can sometimes breed stupidity @@ -48,8 +47,7 @@ public class StringHandler implements DecreeParameterHandler { } @Override - public String getRandomDefault() - { + public String getRandomDefault() { return new KList().qadd("text").qadd("string") .qadd("blah").qadd("derp").qadd("yolo").getRandom(); } diff --git a/src/main/java/com/volmit/iris/util/decree/handlers/VectorHandler.java b/src/main/java/com/volmit/iris/util/decree/handlers/VectorHandler.java index 3203f8389..f99f55d2a 100644 --- a/src/main/java/com/volmit/iris/util/decree/handlers/VectorHandler.java +++ b/src/main/java/com/volmit/iris/util/decree/handlers/VectorHandler.java @@ -27,23 +27,18 @@ import com.volmit.iris.util.decree.exceptions.DecreeWhichException; import com.volmit.iris.util.format.Form; import com.volmit.iris.util.math.M; import com.volmit.iris.util.plugin.VolmitSender; -import org.bukkit.Bukkit; import org.bukkit.FluidCollisionMode; -import org.bukkit.World; import org.bukkit.entity.Player; import org.bukkit.util.BlockVector; import org.bukkit.util.Vector; -import java.util.Locale; - public class VectorHandler implements DecreeParameterHandler { @Override public KList getPossibilities() { KList vx = new KList<>(); VolmitSender s = DecreeContext.get(); - if(s.isPlayer()) - { + if (s.isPlayer()) { vx.add(s.player().getLocation().toVector()); } @@ -52,9 +47,8 @@ public class VectorHandler implements DecreeParameterHandler { @Override public String toString(Vector v) { - if(v.getY() == 0) - { - return Form.f(v.getX(), 2)+ "," + Form.f(v.getZ(), 2); + if (v.getY() == 0) { + return Form.f(v.getX(), 2) + "," + Form.f(v.getZ(), 2); } return Form.f(v.getX(), 2) + "," + Form.f(v.getY(), 2) + "," + Form.f(v.getZ(), 2); @@ -63,69 +57,43 @@ public class VectorHandler implements DecreeParameterHandler { @Override public Vector parse(String in) throws DecreeParsingException, DecreeWhichException { try { - if (in.contains(",")) - { + if (in.contains(",")) { String[] comp = in.split("\\Q,\\E"); - if(comp.length == 2) - { + if (comp.length == 2) { return new BlockVector(Double.parseDouble(comp[0].trim()), 0, Double.parseDouble(comp[1].trim())); - } - - else if(comp.length == 3) - { + } else if (comp.length == 3) { return new BlockVector(Double.parseDouble(comp[0].trim()), Double.parseDouble(comp[1].trim()), Double.parseDouble(comp[2].trim())); - } - - else - { + } else { throw new DecreeParsingException("Could not parse components for vector. You have " + comp.length + " components. Expected 2 or 3."); } - } - - else if(in.equalsIgnoreCase("here") ||in.equalsIgnoreCase("me") ||in.equalsIgnoreCase("self")) - { - if(!DecreeContext.get().isPlayer()) - { + } else if (in.equalsIgnoreCase("here") || in.equalsIgnoreCase("me") || in.equalsIgnoreCase("self")) { + if (!DecreeContext.get().isPlayer()) { throw new DecreeParsingException("You cannot specify me,self,here as a console."); } return DecreeContext.get().player().getLocation().toVector(); - } - - else if(in.equalsIgnoreCase("look") ||in.equalsIgnoreCase("cursor") ||in.equalsIgnoreCase("crosshair")) - { - if(!DecreeContext.get().isPlayer()) - { + } else if (in.equalsIgnoreCase("look") || in.equalsIgnoreCase("cursor") || in.equalsIgnoreCase("crosshair")) { + if (!DecreeContext.get().isPlayer()) { throw new DecreeParsingException("You cannot specify look,cursor,crosshair as a console."); } return DecreeContext.get().player().getTargetBlockExact(256, FluidCollisionMode.NEVER).getLocation().toVector(); - } - - else if(in.trim().toLowerCase().startsWith("player:")) - { + } else if (in.trim().toLowerCase().startsWith("player:")) { String v = in.trim().split("\\Q:\\E")[1]; KList px = DecreeSystem.getHandler(Player.class).getPossibilities(v); - if(px != null && px.isNotEmpty()) - { - return ((Player)px.get(0)).getLocation().toVector(); - } - - else if(px == null || px.isEmpty()) - { + if (px != null && px.isNotEmpty()) { + return ((Player) px.get(0)).getLocation().toVector(); + } else if (px == null || px.isEmpty()) { throw new DecreeParsingException("Cannot find player: " + v); } } - } - - catch(Throwable e) - { + } catch (Throwable e) { throw new DecreeParsingException("Unable to get Vector for \"" + in + "\" because of an uncaught exception: " + e); } @@ -138,8 +106,7 @@ public class VectorHandler implements DecreeParameterHandler { } @Override - public String getRandomDefault() - { + public String getRandomDefault() { return M.r(0.5) ? "0,0" : "0,0,0"; } } diff --git a/src/main/java/com/volmit/iris/util/decree/handlers/WorldHandler.java b/src/main/java/com/volmit/iris/util/decree/handlers/WorldHandler.java index f82e9709c..de7438c5e 100644 --- a/src/main/java/com/volmit/iris/util/decree/handlers/WorldHandler.java +++ b/src/main/java/com/volmit/iris/util/decree/handlers/WorldHandler.java @@ -38,27 +38,19 @@ public class WorldHandler implements DecreeParameterHandler { @Override public World parse(String in) throws DecreeParsingException, DecreeWhichException { - try - { + try { KList options = getPossibilities(in); - if(options.isEmpty()) - { + if (options.isEmpty()) { throw new DecreeParsingException("Unable to find World \"" + in + "\""); - } - - else if(options.size() > 1) - { + } else if (options.size() > 1) { throw new DecreeWhichException(); } return options.get(0); - } - catch(DecreeParsingException e){ + } catch (DecreeParsingException e) { throw e; - } - catch(Throwable e) - { + } catch (Throwable e) { throw new DecreeParsingException("Unable to find World \"" + in + "\" because of an uncaught exception: " + e); } } @@ -69,8 +61,7 @@ public class WorldHandler implements DecreeParameterHandler { } @Override - public String getRandomDefault() - { + public String getRandomDefault() { return "world"; } } diff --git a/src/main/java/com/volmit/iris/util/decree/virtual/VirtualDecreeCommand.java b/src/main/java/com/volmit/iris/util/decree/virtual/VirtualDecreeCommand.java index 2095a5ef4..e06b4256e 100644 --- a/src/main/java/com/volmit/iris/util/decree/virtual/VirtualDecreeCommand.java +++ b/src/main/java/com/volmit/iris/util/decree/virtual/VirtualDecreeCommand.java @@ -22,7 +22,10 @@ import com.volmit.iris.Iris; import com.volmit.iris.core.IrisSettings; import com.volmit.iris.util.collection.KList; import com.volmit.iris.util.collection.KMap; -import com.volmit.iris.util.decree.*; +import com.volmit.iris.util.decree.DecreeContext; +import com.volmit.iris.util.decree.DecreeContextHandler; +import com.volmit.iris.util.decree.DecreeNode; +import com.volmit.iris.util.decree.DecreeParameter; import com.volmit.iris.util.decree.annotations.Decree; import com.volmit.iris.util.decree.exceptions.DecreeParsingException; import com.volmit.iris.util.decree.exceptions.DecreeWhichException; @@ -31,15 +34,10 @@ import com.volmit.iris.util.format.Form; import com.volmit.iris.util.plugin.VolmitSender; import com.volmit.iris.util.scheduling.J; import lombok.Data; -import lombok.Getter; -import org.apache.logging.log4j.core.impl.ThrowableFormatOptions; import java.lang.reflect.Field; -import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.lang.reflect.Modifier; -import java.util.Arrays; -import java.util.Locale; import java.util.Objects; @Data @@ -49,8 +47,7 @@ public class VirtualDecreeCommand { private final KList nodes; private final DecreeNode node; - private VirtualDecreeCommand(Class type, VirtualDecreeCommand parent, KList nodes, DecreeNode node) - { + private VirtualDecreeCommand(Class type, VirtualDecreeCommand parent, KList nodes, DecreeNode node) { this.parent = parent; this.type = type; this.nodes = nodes; @@ -64,23 +61,19 @@ public class VirtualDecreeCommand { public static VirtualDecreeCommand createRoot(VirtualDecreeCommand parent, Object v) throws Throwable { VirtualDecreeCommand c = new VirtualDecreeCommand(v.getClass(), parent, new KList<>(), null); - for(Field i : v.getClass().getDeclaredFields()) - { - if(Modifier.isStatic(i.getModifiers()) || Modifier.isFinal(i.getModifiers())|| Modifier.isTransient(i.getModifiers())|| Modifier.isVolatile(i.getModifiers())) - { + for (Field i : v.getClass().getDeclaredFields()) { + if (Modifier.isStatic(i.getModifiers()) || Modifier.isFinal(i.getModifiers()) || Modifier.isTransient(i.getModifiers()) || Modifier.isVolatile(i.getModifiers())) { continue; } - if(!i.getType().isAnnotationPresent(Decree.class)) - { + if (!i.getType().isAnnotationPresent(Decree.class)) { continue; } i.setAccessible(true); Object childRoot = i.get(v); - if(childRoot == null) - { + if (childRoot == null) { childRoot = i.getType().getConstructor().newInstance(); i.set(v, childRoot); } @@ -88,15 +81,12 @@ public class VirtualDecreeCommand { c.getNodes().add(createRoot(c, childRoot)); } - for(Method i : v.getClass().getDeclaredMethods()) - { - if(Modifier.isStatic(i.getModifiers()) || Modifier.isFinal(i.getModifiers()) || Modifier.isPrivate(i.getModifiers())) - { + for (Method i : v.getClass().getDeclaredMethods()) { + if (Modifier.isStatic(i.getModifiers()) || Modifier.isFinal(i.getModifiers()) || Modifier.isPrivate(i.getModifiers())) { continue; } - if(!i.isAnnotationPresent(Decree.class)) - { + if (!i.isAnnotationPresent(Decree.class)) { continue; } @@ -106,13 +96,11 @@ public class VirtualDecreeCommand { return c; } - public String getPath() - { + public String getPath() { KList n = new KList<>(); VirtualDecreeCommand cursor = this; - while(cursor.getParent() != null) - { + while (cursor.getParent() != null) { cursor = cursor.getParent(); n.add(cursor.getName()); } @@ -120,13 +108,11 @@ public class VirtualDecreeCommand { return "/" + n.reverse().qadd(getName()).toString(" "); } - public String getParentPath() - { - return getParent().getPath(); + public String getParentPath() { + return getParent().getPath(); } - public String getName() - { + public String getName() { return isNode() ? getNode().getName() : getType().getDeclaredAnnotation(Decree.class).name(); } @@ -134,24 +120,19 @@ public class VirtualDecreeCommand { return isNode() ? getNode().getDecree().studio() : getType().getDeclaredAnnotation(Decree.class).studio(); } - public String getDescription() - { + public String getDescription() { return isNode() ? getNode().getDescription() : getType().getDeclaredAnnotation(Decree.class).description(); } - public KList getNames() - { - if(isNode()) - { + public KList getNames() { + if (isNode()) { return getNode().getNames(); } KList d = new KList<>(); Decree dc = getType().getDeclaredAnnotation(Decree.class); - for(String i : dc.aliases()) - { - if(i.isEmpty()) - { + for (String i : dc.aliases()) { + if (i.isEmpty()) { continue; } @@ -164,56 +145,45 @@ public class VirtualDecreeCommand { return d; } - public boolean isNode() - { + public boolean isNode() { return node != null; } - public KList tabComplete(KList args, String raw) - { + public KList tabComplete(KList args, String raw) { KList skip = new KList<>(); KList tabs = new KList<>(); invokeTabComplete(args, skip, tabs, raw); return tabs; } - private boolean invokeTabComplete(KList args, KList skip, KList tabs, String raw) - { - if(isStudio() && !IrisSettings.get().isStudio()) - { + private boolean invokeTabComplete(KList args, KList skip, KList tabs, String raw) { + if (isStudio() && !IrisSettings.get().isStudio()) { return false; } - if(isNode()) - { + if (isNode()) { tab(args, tabs); skip.add(hashCode()); return false; } - if(args.isEmpty()) - { + if (args.isEmpty()) { tab(args, tabs); return true; } String head = args.get(0); - if (args.size() > 1 || head.endsWith(" ")) - { + if (args.size() > 1 || head.endsWith(" ")) { VirtualDecreeCommand match = matchNode(head, skip); - if(match != null) - { + if (match != null) { args.pop(); return match.invokeTabComplete(args, skip, tabs, raw); } skip.add(hashCode()); - } - - else - { + } else { tab(args, tabs); } @@ -226,22 +196,18 @@ public class VirtualDecreeCommand { Runnable la = () -> { }; - for(String a : args) - { + for (String a : args) { la.run(); last = a; la = () -> { - if(isNode()) - { + if (isNode()) { String sea = a.contains("=") ? a.split("\\Q=\\E")[0] : a; sea = sea.trim(); - searching: for(DecreeParameter i : getNode().getParameters()) - { - for(String m : i.getNames()) - { - if(m.equalsIgnoreCase(sea) || m.toLowerCase().contains(sea.toLowerCase()) || sea.toLowerCase().contains(m.toLowerCase())) - { + searching: + for (DecreeParameter i : getNode().getParameters()) { + for (String m : i.getNames()) { + if (m.equalsIgnoreCase(sea) || m.toLowerCase().contains(sea.toLowerCase()) || sea.toLowerCase().contains(m.toLowerCase())) { ignore.add(i); continue searching; } @@ -251,52 +217,37 @@ public class VirtualDecreeCommand { }; } - if(last != null) - { + if (last != null) { if (isNode()) { - for(DecreeParameter i : getNode().getParameters()) - { - if(ignore.contains(i)) - { + for (DecreeParameter i : getNode().getParameters()) { + if (ignore.contains(i)) { continue; } int g = 0; - if(last.contains("=")) - { + if (last.contains("=")) { String[] vv = last.trim().split("\\Q=\\E"); String vx = vv.length == 2 ? vv[1] : ""; - for(String f : i.getHandler().getPossibilities(vx).convert((v) -> i.getHandler().toStringForce(v))) - { + for (String f : i.getHandler().getPossibilities(vx).convert((v) -> i.getHandler().toStringForce(v))) { g++; - tabs.add(i.getName() +"="+ f); + tabs.add(i.getName() + "=" + f); + } + } else { + for (String f : i.getHandler().getPossibilities("").convert((v) -> i.getHandler().toStringForce(v))) { + g++; + tabs.add(i.getName() + "=" + f); } } - else - { - for(String f : i.getHandler().getPossibilities("").convert((v) -> i.getHandler().toStringForce(v))) - { - g++; - tabs.add(i.getName() +"="+ f); - } - } - - if(g == 0) - { + if (g == 0) { tabs.add(i.getName() + "="); } } - } - - else - { - for(VirtualDecreeCommand i : getNodes()) - { + } else { + for (VirtualDecreeCommand i : getNodes()) { String m = i.getName(); - if(m.equalsIgnoreCase(last) || m.toLowerCase().contains(last.toLowerCase()) || last.toLowerCase().contains(m.toLowerCase())) - { + if (m.equalsIgnoreCase(last) || m.toLowerCase().contains(last.toLowerCase()) || last.toLowerCase().contains(m.toLowerCase())) { tabs.addAll(i.getNames()); } } @@ -304,40 +255,30 @@ public class VirtualDecreeCommand { } } - private KMap map(VolmitSender sender, KList in) - { + private KMap map(VolmitSender sender, KList in) { KMap data = new KMap<>(); - for(int ix = 0; ix < in.size(); ix++) - { + for (int ix = 0; ix < in.size(); ix++) { String i = in.get(ix); - if(i.contains("=")) - { + if (i.contains("=")) { String[] v = i.split("\\Q=\\E"); String key = v[0]; String value = v[1]; DecreeParameter param = null; - for(DecreeParameter j : getNode().getParameters()) - { - for(String k : j.getNames()) - { - if(k.equalsIgnoreCase(key)) - { + for (DecreeParameter j : getNode().getParameters()) { + for (String k : j.getNames()) { + if (k.equalsIgnoreCase(key)) { param = j; break; } } } - if(param == null) - { - for(DecreeParameter j : getNode().getParameters()) - { - for(String k : j.getNames()) - { - if(k.toLowerCase().contains(key.toLowerCase()) || key.toLowerCase().contains(k.toLowerCase())) - { + if (param == null) { + for (DecreeParameter j : getNode().getParameters()) { + for (String k : j.getNames()) { + if (k.toLowerCase().contains(key.toLowerCase()) || key.toLowerCase().contains(k.toLowerCase())) { param = j; break; } @@ -345,8 +286,7 @@ public class VirtualDecreeCommand { } } - if(param == null) - { + if (param == null) { Iris.debug("Can't find parameter key for " + key + "=" + value + " in " + getPath()); sender.sendMessage(C.YELLOW + "Unknown Parameter: " + key); continue; @@ -367,12 +307,8 @@ public class VirtualDecreeCommand { Iris.debug("Client chose " + update + " for " + key + "=" + value + " (old) in " + getPath()); in.set(ix--, update); } - } - - else - { - try - { + } else { + try { DecreeParameter par = getNode().getParameters().get(ix); try { data.put(par.getName(), par.getHandler().parse(i)); @@ -387,11 +323,8 @@ public class VirtualDecreeCommand { Iris.debug("Client chose " + update + " for " + par.getName() + "=" + i + " (old) in " + getPath()); in.set(ix--, update); } - } - - catch(IndexOutOfBoundsException e) - { - sender.sendMessage(C.YELLOW + "Unknown Parameter: " + i + " (" + Form.getNumberSuffixThStRd(ix+1) + " argument)"); + } catch (IndexOutOfBoundsException e) { + sender.sendMessage(C.YELLOW + "Unknown Parameter: " + i + " (" + Form.getNumberSuffixThStRd(ix + 1) + " argument)"); } } } @@ -399,25 +332,20 @@ public class VirtualDecreeCommand { return data; } - public boolean invoke(VolmitSender sender, KList realArgs) - { + public boolean invoke(VolmitSender sender, KList realArgs) { return invoke(sender, realArgs, new KList<>()); } - public boolean invoke(VolmitSender sender, KList args, KList skip) - { - if(isStudio() && !IrisSettings.get().isStudio()) - { + public boolean invoke(VolmitSender sender, KList args, KList skip) { + if (isStudio() && !IrisSettings.get().isStudio()) { sender.sendMessage(C.RED + "To use Iris Studio Commands, please enable studio in Iris/settings.json (settings auto-reload)"); return false; } Iris.debug("@ " + getPath() + " with " + args.toString(", ")); - if(isNode()) - { - Iris.debug("Invoke " +getPath() + "(" + args.toString(",") + ") at "); - if(invokeNode(sender, map(sender, args))) - { + if (isNode()) { + Iris.debug("Invoke " + getPath() + "(" + args.toString(",") + ") at "); + if (invokeNode(sender, map(sender, args))) { return true; } @@ -425,8 +353,7 @@ public class VirtualDecreeCommand { return false; } - if(args.isEmpty()) - { + if (args.isEmpty()) { sender.sendDecreeHelp(this); return true; @@ -435,8 +362,7 @@ public class VirtualDecreeCommand { String head = args.get(0); VirtualDecreeCommand match = matchNode(head, skip); - if(match != null) - { + if (match != null) { args.pop(); return match.invoke(sender, args, skip); } @@ -447,25 +373,20 @@ public class VirtualDecreeCommand { } private boolean invokeNode(VolmitSender sender, KMap map) { - if(map == null) - { + if (map == null) { return false; } Object[] params = new Object[getNode().getMethod().getParameterCount()]; int vm = 0; - for(DecreeParameter i : getNode().getParameters()) - { + for (DecreeParameter i : getNode().getParameters()) { Object value = map.get(i.getName()); - try - { - if(value == null && i.hasDefault()) - { + try { + if (value == null && i.hasDefault()) { value = i.getDefaultValue(); } - } - catch (DecreeParsingException e) { + } catch (DecreeParsingException e) { Iris.debug("Can't parse parameter value for " + i.getName() + "=" + i + " in " + getPath() + " using handler " + i.getHandler().getClass().getSimpleName()); sender.sendMessage(C.RED + "Cannot convert \"" + i + "\" into a " + i.getType().getSimpleName()); return false; @@ -474,11 +395,9 @@ public class VirtualDecreeCommand { KList validOptions = i.getHandler().getPossibilities(i.getParam().defaultValue()); String update = null; // TODO: PICK ONE Iris.debug("Client chose " + update + " for " + i.getName() + "=" + i + " (old) in " + getPath()); - try - { + try { value = i.getDefaultValue(); - } - catch (DecreeParsingException x) { + } catch (DecreeParsingException x) { x.printStackTrace(); Iris.debug("Can't parse parameter value for " + i.getName() + "=" + i + " in " + getPath() + " using handler " + i.getHandler().getClass().getSimpleName()); sender.sendMessage(C.RED + "Cannot convert \"" + i + "\" into a " + i.getType().getSimpleName()); @@ -488,33 +407,23 @@ public class VirtualDecreeCommand { } } - if(i.isContextual() && value == null) - { + if (i.isContextual() && value == null) { DecreeContextHandler ch = DecreeContextHandler.contextHandlers.get(i.getType()); - if(ch != null) - { + if (ch != null) { value = ch.handle(sender); - if(value != null) - { + if (value != null) { Iris.debug("Null Parameter " + i.getName() + " derived a value of " + i.getHandler().toStringForce(value) + " from " + ch.getClass().getSimpleName()); - } - - else - { + } else { Iris.debug("Null Parameter " + i.getName() + " could not derive a value from " + ch.getClass().getSimpleName()); } - } - - else - { + } else { Iris.debug("Null Parameter " + i.getName() + " is contextual but has no context handler for " + i.getType().getCanonicalName()); } } - if(i.hasDefault() && value == null) - { + if (i.hasDefault() && value == null) { try { Iris.debug("Null Parameter " + i.getName() + " is using default value " + i.getParam().defaultValue()); value = i.getDefaultValue(); @@ -523,7 +432,7 @@ public class VirtualDecreeCommand { } } - if(i.isRequired() && value == null) { + if (i.isRequired() && value == null) { sender.sendMessage("Missing: " + i.getName() + " (" + i.getType().getSimpleName() + ") as the " + Form.getNumberSuffixThStRd(vm + 1) + " argument."); return false; } @@ -533,55 +442,41 @@ public class VirtualDecreeCommand { } Runnable rx = () -> { - try - { + try { DecreeContext.touch(sender); getNode().getMethod().setAccessible(true); getNode().getMethod().invoke(getNode().getInstance(), params); - } - - catch(Throwable e) - { + } catch (Throwable e) { e.printStackTrace(); throw new RuntimeException("Failed to execute "); // TODO: } }; - if(getNode().isSync()) - { + if (getNode().isSync()) { J.s(rx); - } - - else - { + } else { rx.run(); } return true; } - public KList matchAllNodes(String in) - { + public KList matchAllNodes(String in) { KList g = new KList<>(); - if(in.trim().isEmpty()) - { + if (in.trim().isEmpty()) { g.addAll(nodes); return g; } - for(VirtualDecreeCommand i : nodes) - { - if(i.matches(in)) - { + for (VirtualDecreeCommand i : nodes) { + if (i.matches(in)) { g.add(i); } } - for(VirtualDecreeCommand i : nodes) - { - if(i.deepMatches(in)) - { + for (VirtualDecreeCommand i : nodes) { + if (i.deepMatches(in)) { g.add(i); } } @@ -590,35 +485,27 @@ public class VirtualDecreeCommand { return g; } - public VirtualDecreeCommand matchNode(String in, KList skip) - { - if(in.trim().isEmpty()) - { + public VirtualDecreeCommand matchNode(String in, KList skip) { + if (in.trim().isEmpty()) { return null; } - for(VirtualDecreeCommand i : nodes) - { - if(skip.contains(i.hashCode())) - { + for (VirtualDecreeCommand i : nodes) { + if (skip.contains(i.hashCode())) { continue; } - if(i.matches(in)) - { + if (i.matches(in)) { return i; } } - for(VirtualDecreeCommand i : nodes) - { - if(skip.contains(i.hashCode())) - { + for (VirtualDecreeCommand i : nodes) { + if (skip.contains(i.hashCode())) { continue; } - if(i.deepMatches(in)) - { + if (i.deepMatches(in)) { return i; } } @@ -626,14 +513,11 @@ public class VirtualDecreeCommand { return null; } - public boolean deepMatches(String in) - { + public boolean deepMatches(String in) { KList a = getNames(); - for(String i : a) - { - if(i.toLowerCase().contains(in.toLowerCase()) || in.toLowerCase().contains(i.toLowerCase())) - { + for (String i : a) { + if (i.toLowerCase().contains(in.toLowerCase()) || in.toLowerCase().contains(i.toLowerCase())) { return true; } } @@ -642,26 +526,23 @@ public class VirtualDecreeCommand { } @Override - public int hashCode(){ + public int hashCode() { return Objects.hash(getName(), getDescription(), getType(), getPath()); } @Override - public boolean equals(Object obj){ - if (!(obj instanceof VirtualDecreeCommand)){ + public boolean equals(Object obj) { + if (!(obj instanceof VirtualDecreeCommand)) { return false; } return this.hashCode() == obj.hashCode(); } - public boolean matches(String in) - { + public boolean matches(String in) { KList a = getNames(); - for(String i : a) - { - if(i.equalsIgnoreCase(in)) - { + for (String i : a) { + if (i.equalsIgnoreCase(in)) { return true; } } diff --git a/src/main/java/com/volmit/iris/util/format/Form.java b/src/main/java/com/volmit/iris/util/format/Form.java index 217db0fea..beac89d4d 100644 --- a/src/main/java/com/volmit/iris/util/format/Form.java +++ b/src/main/java/com/volmit/iris/util/format/Form.java @@ -18,7 +18,6 @@ package com.volmit.iris.util.format; -import com.google.common.base.Preconditions; import com.volmit.iris.util.math.M; import com.volmit.iris.util.math.RollingSequence; diff --git a/src/main/java/com/volmit/iris/util/mantle/Mantle.java b/src/main/java/com/volmit/iris/util/mantle/Mantle.java index 387c82199..80da0a9b1 100644 --- a/src/main/java/com/volmit/iris/util/mantle/Mantle.java +++ b/src/main/java/com/volmit/iris/util/mantle/Mantle.java @@ -136,8 +136,7 @@ public class Mantle { throw new RuntimeException("The Mantle is closed"); } - if(y < 0) - { + if (y < 0) { return; } @@ -170,8 +169,7 @@ public class Mantle { throw new RuntimeException("The Mantle is closed"); } - if(y < 0) - { + if (y < 0) { return null; } @@ -259,8 +257,7 @@ public class Mantle { */ @RegionCoordinates private TectonicPlate get(int x, int z) { - if(io.get()) - { + if (io.get()) { try { return getSafe(x, z).get(); } catch (InterruptedException e) { @@ -272,8 +269,7 @@ public class Mantle { TectonicPlate p = loadedRegions.get(key(x, z)); - if(p != null) - { + if (p != null) { return p; } diff --git a/src/main/java/com/volmit/iris/util/network/DL.java b/src/main/java/com/volmit/iris/util/network/DL.java index 5815fd940..e81286edc 100644 --- a/src/main/java/com/volmit/iris/util/network/DL.java +++ b/src/main/java/com/volmit/iris/util/network/DL.java @@ -18,305 +18,258 @@ package com.volmit.iris.util.network; -import java.io.BufferedInputStream; -import java.io.BufferedOutputStream; -import java.io.File; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.InputStream; -import java.net.URL; -import java.net.URLConnection; - import com.volmit.iris.util.collection.KSet; import com.volmit.iris.util.io.IO; import com.volmit.iris.util.scheduling.ChronoLatch; -public abstract class DL -{ - protected File d; - protected URL u; - protected ChronoLatch latch; - protected KSet flags; - protected MeteredOutputStream o; - protected DownloadState state; - protected int timeout; - protected long size; - protected long start; - protected long downloaded; - protected long currentChunk; - protected long lastChunk; - protected long bps; - protected int bufferSize; - protected long lastPull; - protected DownloadMonitor m; - - public DL(URL u, File d, DownloadFlag...downloadFlags) - { - this.d = d; - this.u = u; - size = -1; - lastPull = -1; - downloaded = 0; - bufferSize = 8192 * 32; - currentChunk = 0; - lastChunk = -1; - bps = -1; - start = -1; - timeout = 10000; - state = DownloadState.NEW; - flags = new KSet<>(); - latch = new ChronoLatch(500); +import java.io.*; +import java.net.URL; +import java.net.URLConnection; - for(DownloadFlag i : downloadFlags) - { - flags.add(i); - } - } - - public void monitor(DownloadMonitor m) - { - this.m = m; - } - - public void update() - { - if(m != null) - { - m.onUpdate(state, getProgress(), getElapsed(), getTimeLeft(), bps, getDiskBytesPerSecond(), size, downloaded, bufferSize, getBufferUse()); - } - } - - public boolean hasFlag(DownloadFlag f) - { - return flags.contains(f); - } - - public boolean isState(DownloadState s) - { - return state.equals(s); - } - - protected void state(DownloadState s) - { - this.state = s; - update(); - } - - public int getBufferSize() - { - return bufferSize; - } - - public void start() throws IOException - { - if(!isState(DownloadState.NEW)) - { - throw new DownloadException("Cannot start download while " + state.toString()); - } - - state(DownloadState.STARTING); - - if(hasFlag(DownloadFlag.CALCULATE_SIZE)) - { - size = calculateSize(); - } - - start = System.currentTimeMillis(); - downloaded = 0; - bps = 0; - lastChunk = System.currentTimeMillis(); - o = new MeteredOutputStream(new FileOutputStream(d), 100); - openStream(); - state(DownloadState.DOWNLOADING); - } - - protected abstract long download() throws IOException; - - protected abstract void openStream() throws IOException; - - protected abstract void closeStream() throws IOException; - - public void downloadChunk() throws IOException - { - if(!isState(DownloadState.DOWNLOADING)) - { - throw new DownloadException("Cannot download while " + state.toString()); - } - - long d = download(); - lastPull = d; - - if(d < 0) - { - finishDownload(); - return; - } - - downloaded += d; - currentChunk += d; - - double chunkTime = (double)(System.currentTimeMillis() - lastChunk) / 1000D; - bps = (long) ((double)currentChunk / chunkTime); - - if(latch.flip()) - { - update(); - } - } - - public double getBufferUse() - { - return (double)lastPull / (double)bufferSize; - } - - private void finishDownload() throws IOException - { - if(!isState(DownloadState.NEW)) - { - throw new DownloadException("Cannot finish download while " + state.toString()); - } - - closeStream(); - o.close(); - state(DownloadState.COMPLETE); - } +public abstract class DL { + protected File d; + protected URL u; + protected ChronoLatch latch; + protected KSet flags; + protected MeteredOutputStream o; + protected DownloadState state; + protected int timeout; + protected long size; + protected long start; + protected long downloaded; + protected long currentChunk; + protected long lastChunk; + protected long bps; + protected int bufferSize; + protected long lastPull; + protected DownloadMonitor m; - public long getElapsed() - { - return System.currentTimeMillis() - start; - } - - public long getRemaining() - { - return size - downloaded; - } - - public long getTimeLeft() - { - return (long) (((double)getRemaining() / (double)bps) * 1000D); - } - - public long getDiskBytesPerSecond() - { - if(o == null) - { - return -1; - } - - return o.getBps(); - } - - public long getBytesPerSecond() - { - return bps; - } - - public double getProgress() - { - return hasProgress() ? ((double)downloaded / (double)size) : -1D; - } - - public boolean hasProgress() - { - return size > 0; - } + public DL(URL u, File d, DownloadFlag... downloadFlags) { + this.d = d; + this.u = u; + size = -1; + lastPull = -1; + downloaded = 0; + bufferSize = 8192 * 32; + currentChunk = 0; + lastChunk = -1; + bps = -1; + start = -1; + timeout = 10000; + state = DownloadState.NEW; + flags = new KSet<>(); + latch = new ChronoLatch(500); - private long calculateSize() throws IOException - { - URLConnection c = u.openConnection(); - c.setConnectTimeout((int) timeout); - c.setReadTimeout((int) timeout); - c.connect(); - return c.getContentLengthLong(); - } - - public enum DownloadFlag - { - CALCULATE_SIZE - } - - public enum DownloadState - { - NEW, - STARTING, - DOWNLOADING, - FINALIZING, - COMPLETE, - FAILED - } - - public static class ThrottledDownload extends Download - { - private long mbps; - - public ThrottledDownload(URL u, File d, long mbps, DownloadFlag... downloadFlags) { - super(u, d, downloadFlags); - this.mbps = mbps; - } - - @Override - protected long download() throws IOException - { - if(getBytesPerSecond() > mbps) - { - try - { - Thread.sleep(40); - } - - catch (InterruptedException e) - { - e.printStackTrace(); - } - - return IO.transfer(in, o, 8192, mbps/20); - } - - return IO.transfer(in, o, 8192, bufferSize); - } - } - - public static class DoubleBufferedDownload extends Download - { - protected BufferedOutputStream os; - - public DoubleBufferedDownload(URL u, File d, DownloadFlag... downloadFlags) - { - super(u, d, downloadFlags); - } - - @Override - protected void openStream() throws IOException - { - os = new BufferedOutputStream(o, 8192*16); - in = new BufferedInputStream(u.openStream(), 8192*16); - buf = new byte[8192 * 2]; - } - } - - public static class Download extends DL - { - protected InputStream in; - protected byte[] buf; - public Download(URL u, File d, DownloadFlag... downloadFlags) { - super(u, d, downloadFlags); - } + for (DownloadFlag i : downloadFlags) { + flags.add(i); + } + } - @Override - protected long download() throws IOException - { - return IO.transfer(in, o, buf, bufferSize); - } + public void monitor(DownloadMonitor m) { + this.m = m; + } - @Override - protected void openStream() throws IOException { - in = u.openStream(); - buf = new byte[8192]; - } + public void update() { + if (m != null) { + m.onUpdate(state, getProgress(), getElapsed(), getTimeLeft(), bps, getDiskBytesPerSecond(), size, downloaded, bufferSize, getBufferUse()); + } + } - @Override - protected void closeStream() throws IOException { - in.close(); - } - } + public boolean hasFlag(DownloadFlag f) { + return flags.contains(f); + } + + public boolean isState(DownloadState s) { + return state.equals(s); + } + + protected void state(DownloadState s) { + this.state = s; + update(); + } + + public int getBufferSize() { + return bufferSize; + } + + public void start() throws IOException { + if (!isState(DownloadState.NEW)) { + throw new DownloadException("Cannot start download while " + state.toString()); + } + + state(DownloadState.STARTING); + + if (hasFlag(DownloadFlag.CALCULATE_SIZE)) { + size = calculateSize(); + } + + start = System.currentTimeMillis(); + downloaded = 0; + bps = 0; + lastChunk = System.currentTimeMillis(); + o = new MeteredOutputStream(new FileOutputStream(d), 100); + openStream(); + state(DownloadState.DOWNLOADING); + } + + protected abstract long download() throws IOException; + + protected abstract void openStream() throws IOException; + + protected abstract void closeStream() throws IOException; + + public void downloadChunk() throws IOException { + if (!isState(DownloadState.DOWNLOADING)) { + throw new DownloadException("Cannot download while " + state.toString()); + } + + long d = download(); + lastPull = d; + + if (d < 0) { + finishDownload(); + return; + } + + downloaded += d; + currentChunk += d; + + double chunkTime = (double) (System.currentTimeMillis() - lastChunk) / 1000D; + bps = (long) ((double) currentChunk / chunkTime); + + if (latch.flip()) { + update(); + } + } + + public double getBufferUse() { + return (double) lastPull / (double) bufferSize; + } + + private void finishDownload() throws IOException { + if (!isState(DownloadState.NEW)) { + throw new DownloadException("Cannot finish download while " + state.toString()); + } + + closeStream(); + o.close(); + state(DownloadState.COMPLETE); + } + + public long getElapsed() { + return System.currentTimeMillis() - start; + } + + public long getRemaining() { + return size - downloaded; + } + + public long getTimeLeft() { + return (long) (((double) getRemaining() / (double) bps) * 1000D); + } + + public long getDiskBytesPerSecond() { + if (o == null) { + return -1; + } + + return o.getBps(); + } + + public long getBytesPerSecond() { + return bps; + } + + public double getProgress() { + return hasProgress() ? ((double) downloaded / (double) size) : -1D; + } + + public boolean hasProgress() { + return size > 0; + } + + private long calculateSize() throws IOException { + URLConnection c = u.openConnection(); + c.setConnectTimeout(timeout); + c.setReadTimeout(timeout); + c.connect(); + return c.getContentLengthLong(); + } + + public enum DownloadFlag { + CALCULATE_SIZE + } + + public enum DownloadState { + NEW, + STARTING, + DOWNLOADING, + FINALIZING, + COMPLETE, + FAILED + } + + public static class ThrottledDownload extends Download { + private final long mbps; + + public ThrottledDownload(URL u, File d, long mbps, DownloadFlag... downloadFlags) { + super(u, d, downloadFlags); + this.mbps = mbps; + } + + @Override + protected long download() throws IOException { + if (getBytesPerSecond() > mbps) { + try { + Thread.sleep(40); + } catch (InterruptedException e) { + e.printStackTrace(); + } + + return IO.transfer(in, o, 8192, mbps / 20); + } + + return IO.transfer(in, o, 8192, bufferSize); + } + } + + public static class DoubleBufferedDownload extends Download { + protected BufferedOutputStream os; + + public DoubleBufferedDownload(URL u, File d, DownloadFlag... downloadFlags) { + super(u, d, downloadFlags); + } + + @Override + protected void openStream() throws IOException { + os = new BufferedOutputStream(o, 8192 * 16); + in = new BufferedInputStream(u.openStream(), 8192 * 16); + buf = new byte[8192 * 2]; + } + } + + public static class Download extends DL { + protected InputStream in; + protected byte[] buf; + + public Download(URL u, File d, DownloadFlag... downloadFlags) { + super(u, d, downloadFlags); + } + + @Override + protected long download() throws IOException { + return IO.transfer(in, o, buf, bufferSize); + } + + @Override + protected void openStream() throws IOException { + in = u.openStream(); + buf = new byte[8192]; + } + + @Override + protected void closeStream() throws IOException { + in.close(); + } + } } \ No newline at end of file diff --git a/src/main/java/com/volmit/iris/util/network/DownloadException.java b/src/main/java/com/volmit/iris/util/network/DownloadException.java index 83154c087..37e9be366 100644 --- a/src/main/java/com/volmit/iris/util/network/DownloadException.java +++ b/src/main/java/com/volmit/iris/util/network/DownloadException.java @@ -20,23 +20,22 @@ package com.volmit.iris.util.network; import java.io.IOException; -public class DownloadException extends IOException -{ - private static final long serialVersionUID = 5137918663903349839L; +public class DownloadException extends IOException { + private static final long serialVersionUID = 5137918663903349839L; - public DownloadException() { - super(); - } + public DownloadException() { + super(); + } - public DownloadException(String message, Throwable cause) { - super(message, cause); - } + public DownloadException(String message, Throwable cause) { + super(message, cause); + } - public DownloadException(String message) { - super(message); - } + public DownloadException(String message) { + super(message); + } - public DownloadException(Throwable cause) { - super(cause); - } + public DownloadException(Throwable cause) { + super(cause); + } } \ No newline at end of file diff --git a/src/main/java/com/volmit/iris/util/network/DownloadMonitor.java b/src/main/java/com/volmit/iris/util/network/DownloadMonitor.java index 7ce01ac5c..d9316077f 100644 --- a/src/main/java/com/volmit/iris/util/network/DownloadMonitor.java +++ b/src/main/java/com/volmit/iris/util/network/DownloadMonitor.java @@ -19,7 +19,6 @@ package com.volmit.iris.util.network; @FunctionalInterface -public interface DownloadMonitor -{ - public void onUpdate(DL.DownloadState state, double progress, long elapsed, long estimated, long bps, long iobps, long size, long downloaded, long buffer, double bufferuse); +public interface DownloadMonitor { + void onUpdate(DL.DownloadState state, double progress, long elapsed, long estimated, long bps, long iobps, long size, long downloaded, long buffer, double bufferuse); } \ No newline at end of file diff --git a/src/main/java/com/volmit/iris/util/network/MeteredInputStream.java b/src/main/java/com/volmit/iris/util/network/MeteredInputStream.java index 9a32b9531..939f8746b 100644 --- a/src/main/java/com/volmit/iris/util/network/MeteredInputStream.java +++ b/src/main/java/com/volmit/iris/util/network/MeteredInputStream.java @@ -21,100 +21,85 @@ package com.volmit.iris.util.network; import java.io.IOException; import java.io.InputStream; -public class MeteredInputStream extends InputStream -{ - private InputStream os; - private long written; - private long totalWritten; - private long since; - private boolean auto; - private long interval; - private long bps; - - public MeteredInputStream(InputStream os, long interval) - { - this.os = os; - written = 0; - totalWritten = 0; - auto = true; - this.interval = interval; - bps = 0; - since = System.currentTimeMillis(); - } - - public MeteredInputStream(InputStream os) - { - this(os, 100); - auto = false; - } +public class MeteredInputStream extends InputStream { + private final InputStream os; + private long written; + private long totalWritten; + private long since; + private boolean auto; + private long interval; + private long bps; - @Override - public int read() throws IOException - { - written++; - totalWritten++; - - if(auto && System.currentTimeMillis() - getSince() > interval) - { - pollRead(); - } - - return os.read(); - } - - public long getSince() - { - return since; - } - - public long getRead() - { - return written; - } - - public long pollRead() - { - long w = written; - written = 0; - double secondsElapsedSince = (double) (System.currentTimeMillis() - since) / 1000.0; - bps = (long) ((double) w / secondsElapsedSince); - since = System.currentTimeMillis(); - - return w; - } + public MeteredInputStream(InputStream os, long interval) { + this.os = os; + written = 0; + totalWritten = 0; + auto = true; + this.interval = interval; + bps = 0; + since = System.currentTimeMillis(); + } - public void close() throws IOException - { - os.close(); - } + public MeteredInputStream(InputStream os) { + this(os, 100); + auto = false; + } - public boolean isAuto() - { - return auto; - } + @Override + public int read() throws IOException { + written++; + totalWritten++; - public void setAuto(boolean auto) - { - this.auto = auto; - } + if (auto && System.currentTimeMillis() - getSince() > interval) { + pollRead(); + } - public long getInterval() - { - return interval; - } + return os.read(); + } - public void setInterval(long interval) - { - this.interval = interval; - } + public long getSince() { + return since; + } - public long getTotalRead() - { - return totalWritten; - } + public long getRead() { + return written; + } - public long getBps() - { - return bps; - } + public long pollRead() { + long w = written; + written = 0; + double secondsElapsedSince = (double) (System.currentTimeMillis() - since) / 1000.0; + bps = (long) ((double) w / secondsElapsedSince); + since = System.currentTimeMillis(); + + return w; + } + + public void close() throws IOException { + os.close(); + } + + public boolean isAuto() { + return auto; + } + + public void setAuto(boolean auto) { + this.auto = auto; + } + + public long getInterval() { + return interval; + } + + public void setInterval(long interval) { + this.interval = interval; + } + + public long getTotalRead() { + return totalWritten; + } + + public long getBps() { + return bps; + } } \ No newline at end of file diff --git a/src/main/java/com/volmit/iris/util/network/MeteredOutputStream.java b/src/main/java/com/volmit/iris/util/network/MeteredOutputStream.java index 4c3ef62a2..8ba0d12ad 100644 --- a/src/main/java/com/volmit/iris/util/network/MeteredOutputStream.java +++ b/src/main/java/com/volmit/iris/util/network/MeteredOutputStream.java @@ -21,98 +21,83 @@ package com.volmit.iris.util.network; import java.io.IOException; import java.io.OutputStream; -public class MeteredOutputStream extends OutputStream -{ - private OutputStream os; - private long written; - private long totalWritten; - private long since; - private boolean auto; - private long interval; - private long bps; - - public MeteredOutputStream(OutputStream os, long interval) - { - this.os = os; - written = 0; - totalWritten = 0; - auto = true; - this.interval = interval; - bps = 0; - since = System.currentTimeMillis(); - } - - public MeteredOutputStream(OutputStream os) - { - this(os, 100); - auto = false; - } +public class MeteredOutputStream extends OutputStream { + private final OutputStream os; + private long written; + private long totalWritten; + private long since; + private boolean auto; + private long interval; + private long bps; - @Override - public void write(int b) throws IOException - { - os.write(b); - written++; - totalWritten++; - - if(auto && System.currentTimeMillis() - getSince() > interval) - { - pollWritten(); - } - } - - public long getSince() - { - return since; - } - - public long getWritten() - { - return written; - } - - public long pollWritten() - { - long w = written; - written = 0; - double secondsElapsedSince = (double) (System.currentTimeMillis() - since) / 1000.0; - bps = (long) ((double) w / secondsElapsedSince); - since = System.currentTimeMillis(); - return w; - } + public MeteredOutputStream(OutputStream os, long interval) { + this.os = os; + written = 0; + totalWritten = 0; + auto = true; + this.interval = interval; + bps = 0; + since = System.currentTimeMillis(); + } - public void close() throws IOException - { - os.close(); - } + public MeteredOutputStream(OutputStream os) { + this(os, 100); + auto = false; + } - public boolean isAuto() - { - return auto; - } + @Override + public void write(int b) throws IOException { + os.write(b); + written++; + totalWritten++; - public void setAuto(boolean auto) - { - this.auto = auto; - } + if (auto && System.currentTimeMillis() - getSince() > interval) { + pollWritten(); + } + } - public long getInterval() - { - return interval; - } + public long getSince() { + return since; + } - public void setInterval(long interval) - { - this.interval = interval; - } + public long getWritten() { + return written; + } - public long getTotalWritten() - { - return totalWritten; - } + public long pollWritten() { + long w = written; + written = 0; + double secondsElapsedSince = (double) (System.currentTimeMillis() - since) / 1000.0; + bps = (long) ((double) w / secondsElapsedSince); + since = System.currentTimeMillis(); + return w; + } - public long getBps() - { - return bps; - } + public void close() throws IOException { + os.close(); + } + + public boolean isAuto() { + return auto; + } + + public void setAuto(boolean auto) { + this.auto = auto; + } + + public long getInterval() { + return interval; + } + + public void setInterval(long interval) { + this.interval = interval; + } + + public long getTotalWritten() { + return totalWritten; + } + + public long getBps() { + return bps; + } } \ No newline at end of file diff --git a/src/main/java/com/volmit/iris/util/plugin/VolmitSender.java b/src/main/java/com/volmit/iris/util/plugin/VolmitSender.java index 5d98877db..0835bc6e4 100644 --- a/src/main/java/com/volmit/iris/util/plugin/VolmitSender.java +++ b/src/main/java/com/volmit/iris/util/plugin/VolmitSender.java @@ -360,11 +360,9 @@ public class VolmitSender implements CommandSender { return s.spigot(); } - private String pickRandoms(int max, VirtualDecreeCommand i) - { + private String pickRandoms(int max, VirtualDecreeCommand i) { KList m = new KList<>(); - for(int ix = 0; ix < max; ix++) - { + for (int ix = 0; ix < max; ix++) { m.add((i.isNode() ? (i.getNode().getParameters().isNotEmpty()) ? "<#aebef2>✦ <#5ef288>" @@ -385,8 +383,7 @@ public class VolmitSender implements CommandSender { } - public void sendHeader(String name, int overrideLength) - { + public void sendHeader(String name, int overrideLength) { int len = overrideLength; int h = name.length() + 2; String s = Form.repeat(" ", len - h - 4); @@ -395,95 +392,80 @@ public class VolmitSender implements CommandSender { String sf = "["; String se = "]"; - if(name.trim().isEmpty()) - { - sendMessageRaw("" + sf + s + "" + s + se); - } - - else - { + if (name.trim().isEmpty()) { + sendMessageRaw("" + sf + s + "" + s + se); + } else { sendMessageRaw("" + sf + s + si + " " + name + " " + so + s + se); } } - public void sendHeader(String name) - { - sendHeader(name,46); + public void sendHeader(String name) { + sendHeader(name, 46); } public void sendDecreeHelp(VirtualDecreeCommand v) { int m = v.getNodes().size(); - if(v.getNodes().isNotEmpty()) - { + if (v.getNodes().isNotEmpty()) { sendHeader(Form.capitalize(v.getName()) + " Help"); - if(isPlayer() && v.getParent() != null) - { - sendMessageRaw("Click to go back to <#3299bf>" + Form.capitalize(v.getParent().getName()) + " Help" +"'><#f58571>〈 Back"); + if (isPlayer() && v.getParent() != null) { + sendMessageRaw("Click to go back to <#3299bf>" + Form.capitalize(v.getParent().getName()) + " Help" + "'><#f58571>〈 Back"); } - for(VirtualDecreeCommand i : v.getNodes()) - { - if(isPlayer()) - { + for (VirtualDecreeCommand i : v.getNodes()) { + if (isPlayer()) { //@builder String s = ( - " "<#42ecf5>" + f).toString(", ") + "\n" - + "<#3fe05a>✎ <#6ad97d>" + i.getDescription() + "\n" - + "<#bbe03f>✒ <#a8e0a2>" + (i.isNode() - ? ((i.getNode().getParameters().isEmpty() - ? "There are no parameters." - : "Hover over all of the parameters to learn more.") + "\n") - : "This is a command category. Run <#98eda5>" + i.getPath()) - + (i.isNode() - ? (i.getNode().getParameters().isNotEmpty()) - ? "<#aebef2>✦ <#5ef288>" + " "<#42ecf5>" + f).toString(", ") + "\n" + + "<#3fe05a>✎ <#6ad97d>" + i.getDescription() + "\n" + + "<#bbe03f>✒ <#a8e0a2>" + (i.isNode() + ? ((i.getNode().getParameters().isEmpty() + ? "There are no parameters." + : "Hover over all of the parameters to learn more.") + "\n") + : "This is a command category. Run <#98eda5>" + i.getPath()) + + (i.isNode() + ? (i.getNode().getParameters().isNotEmpty()) + ? "<#aebef2>✦ <#5ef288>" + i.getParentPath() + " <#42ecf5>" + i.getName() + " " + i.getNode().getParameters().convert((f) - -> "<#d665f0>" + f.example()) - .toString(" ") + "\n" - : "" - : "") - + (i.isNode() ? "" + pickRandoms(Math.min(i.getNode().getParameters().size() + 1, 5), i) + "" : "") - + "'>" - + "<#46826a>⇀ " +i.getName() + "" - + (i.isNode() ? - " " + i.getNode().getParameters().convert((f) - -> " "<#d665f0>" + ff).toString(", ") + "\n" + -> "<#d665f0>" + f.example()) + .toString(" ") + "\n" + : "" + : "") + + (i.isNode() ? "" + pickRandoms(Math.min(i.getNode().getParameters().size() + 1, 5), i) + "" : "") + + "'>" + + "<#46826a>⇀ " + i.getName() + "" + + (i.isNode() ? + " " + i.getNode().getParameters().convert((f) + -> " "<#d665f0>" + ff).toString(", ") + "\n" + "<#3fe05a>✎ <#6ad97d>" + f.getDescription() + "\n" - + (f.isRequired() + + (f.isRequired() ? "<#db4321>⚠ <#faa796>This parameter is required." : (f.hasDefault() - ? "<#2181db>✔ <#78dcf0>Defaults to \""+f.getParam().defaultValue()+"\" if undefined." - : "<#a73abd>✔ <#78dcf0>This parameter is optional.")) + "\n" - + (f.isContextual() ? "<#ff9900>➱ <#ffcc00>The value may be derived from environment context \n" : "") - + "<#cc00ff>✢ <#ff33cc>This parameter is of type " + f.getType().getSimpleName() + "\n" - + "'>" - + (f.isRequired() ? "[" : "") - + "" + f.getName() - + (f.isRequired() ? "]" : "") - + "").toString(" ") - : " - Category of Commands" - ) - ); + ? "<#2181db>✔ <#78dcf0>Defaults to \"" + f.getParam().defaultValue() + "\" if undefined." + : "<#a73abd>✔ <#78dcf0>This parameter is optional.")) + "\n" + + (f.isContextual() ? "<#ff9900>➱ <#ffcc00>The value may be derived from environment context \n" : "") + + "<#cc00ff>✢ <#ff33cc>This parameter is of type " + f.getType().getSimpleName() + "\n" + + "'>" + + (f.isRequired() ? "[" : "") + + "" + f.getName() + + (f.isRequired() ? "]" : "") + + "").toString(" ") + : " - Category of Commands" + ) + ); //@done sendMessageRaw(s); System.out.println(s); - } - - else - { + } else { sendMessage(i.getPath() + "()"); } } - } - - else - { + } else { sendMessage(C.RED + "There are no subcommands in this group! Contact support, this is a command design issue!"); } } diff --git a/src/main/java/com/volmit/iris/util/scheduling/jobs/DownloadJob.java b/src/main/java/com/volmit/iris/util/scheduling/jobs/DownloadJob.java index 70f048036..ebab8ff29 100644 --- a/src/main/java/com/volmit/iris/util/scheduling/jobs/DownloadJob.java +++ b/src/main/java/com/volmit/iris/util/scheduling/jobs/DownloadJob.java @@ -26,8 +26,8 @@ import java.io.IOException; import java.net.MalformedURLException; import java.net.URL; -public class DownloadJob implements Job{ - private DL.Download download; +public class DownloadJob implements Job { + private final DL.Download download; private int tw; private int cw; @@ -38,13 +38,9 @@ public class DownloadJob implements Job{ download.monitor(new DownloadMonitor() { @Override public void onUpdate(DL.DownloadState state, double progress, long elapsed, long estimated, long bps, long iobps, long size, long downloaded, long buffer, double bufferuse) { - if(size == -1) - { + if (size == -1) { tw = 1; - } - - else - { + } else { tw = (int) (size / 100); cw = (int) (downloaded / 100); } @@ -61,8 +57,7 @@ public class DownloadJob implements Job{ public void execute() { try { download.start(); - while(download.isState(DL.DownloadState.DOWNLOADING)) - { + while (download.isState(DL.DownloadState.DOWNLOADING)) { download.downloadChunk(); } } catch (IOException e) { diff --git a/src/main/java/com/volmit/iris/util/scheduling/jobs/Job.java b/src/main/java/com/volmit/iris/util/scheduling/jobs/Job.java index 309841b88..33864d86b 100644 --- a/src/main/java/com/volmit/iris/util/scheduling/jobs/Job.java +++ b/src/main/java/com/volmit/iris/util/scheduling/jobs/Job.java @@ -18,7 +18,6 @@ package com.volmit.iris.util.scheduling.jobs; -import com.volmit.iris.util.collection.KList; import com.volmit.iris.util.format.Form; import com.volmit.iris.util.plugin.VolmitSender; import com.volmit.iris.util.scheduling.J; @@ -26,8 +25,7 @@ import com.volmit.iris.util.scheduling.PrecisionStopwatch; import java.util.concurrent.CompletableFuture; -public interface Job -{ +public interface Job { String getName(); void execute(); @@ -36,35 +34,27 @@ public interface Job int getTotalWork(); - default int getWorkRemaining() - { + default int getWorkRemaining() { return getTotalWork() - getWorkCompleted(); } int getWorkCompleted(); - default String getProgressString() - { + default String getProgressString() { return Form.pc(getProgress(), 0); } - default double getProgress() - { - return (double)getWorkCompleted() / (double)getTotalWork(); + default double getProgress() { + return (double) getWorkCompleted() / (double) getTotalWork(); } - default void execute(VolmitSender sender) - { + default void execute(VolmitSender sender) { PrecisionStopwatch p = PrecisionStopwatch.start(); CompletableFuture f = J.afut(this::execute); int c = J.ar(() -> { - if(sender.isPlayer()) - { + if (sender.isPlayer()) { sender.sendProgress(getProgress(), getName()); - } - - else - { + } else { sender.sendMessage(getName() + ": " + getProgressString()); } }, sender.isPlayer() ? 0 : 20); diff --git a/src/main/java/com/volmit/iris/util/scheduling/jobs/JobCollection.java b/src/main/java/com/volmit/iris/util/scheduling/jobs/JobCollection.java index 0accefafb..9c5a44f1f 100644 --- a/src/main/java/com/volmit/iris/util/scheduling/jobs/JobCollection.java +++ b/src/main/java/com/volmit/iris/util/scheduling/jobs/JobCollection.java @@ -25,13 +25,11 @@ public class JobCollection implements Job { private String status; private final KList jobs; - public JobCollection(String name, Job... jobs) - { + public JobCollection(String name, Job... jobs) { this(name, new KList<>(jobs)); } - public JobCollection(String name, KList jobs) - { + public JobCollection(String name, KList jobs) { this.name = name; status = null; this.jobs = new KList<>(jobs); @@ -44,8 +42,7 @@ public class JobCollection implements Job { @Override public void execute() { - for(Job i : jobs) - { + for (Job i : jobs) { status = i.getName(); i.execute(); } diff --git a/src/main/java/com/volmit/iris/util/scheduling/jobs/QueueJob.java b/src/main/java/com/volmit/iris/util/scheduling/jobs/QueueJob.java index 5fb92c5f3..4ee511545 100644 --- a/src/main/java/com/volmit/iris/util/scheduling/jobs/QueueJob.java +++ b/src/main/java/com/volmit/iris/util/scheduling/jobs/QueueJob.java @@ -25,21 +25,18 @@ public abstract class QueueJob implements Job { private int totalWork; private int completed; - public QueueJob() - { + public QueueJob() { totalWork = 0; completed = 0; queue = new KList<>(); } - public void queue(T t) - { + public void queue(T t) { queue.add(t); totalWork++; } - public void queue(KList f) - { + public void queue(KList f) { queue.addAll(f); totalWork += f.size(); } @@ -49,8 +46,7 @@ public abstract class QueueJob implements Job { @Override public void execute() { totalWork = queue.size(); - while(queue.isNotEmpty()) - { + while (queue.isNotEmpty()) { execute(queue.pop()); completeWork(); } diff --git a/src/main/java/com/volmit/iris/util/scheduling/jobs/SingleJob.java b/src/main/java/com/volmit/iris/util/scheduling/jobs/SingleJob.java index c422b0ecd..549a940df 100644 --- a/src/main/java/com/volmit/iris/util/scheduling/jobs/SingleJob.java +++ b/src/main/java/com/volmit/iris/util/scheduling/jobs/SingleJob.java @@ -18,13 +18,12 @@ package com.volmit.iris.util.scheduling.jobs; -public class SingleJob implements Job{ +public class SingleJob implements Job { private boolean done; private final String name; private final Runnable runnable; - public SingleJob(String name, Runnable runnable) - { + public SingleJob(String name, Runnable runnable) { this.name = name; done = false; this.runnable = runnable; From 8abaac56ffd576382fc7f8f613571559a348408a Mon Sep 17 00:00:00 2001 From: cyberpwn Date: Mon, 16 Aug 2021 19:13:06 -0400 Subject: [PATCH 04/13] Fix dim creation --- .../volmit/iris/core/project/IrisPack.java | 36 ------------------- .../volmit/iris/core/service/StudioSVC.java | 12 ++++--- .../volmit/iris/core/tools/IrisToolbelt.java | 34 ------------------ 3 files changed, 8 insertions(+), 74 deletions(-) delete mode 100644 src/main/java/com/volmit/iris/core/project/IrisPack.java diff --git a/src/main/java/com/volmit/iris/core/project/IrisPack.java b/src/main/java/com/volmit/iris/core/project/IrisPack.java deleted file mode 100644 index f0b06b469..000000000 --- a/src/main/java/com/volmit/iris/core/project/IrisPack.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Iris is a World Generator for Minecraft Bukkit Servers - * Copyright (c) 2021 Arcane Arts (Volmit Software) - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package com.volmit.iris.core.project; - -import lombok.Data; - -import java.io.File; - -@Data -public class IrisPack { - private final File folder; - - public IrisPack(File folder) { - this.folder = folder; - } - - public String getName() { - return getFolder().getName(); - } -} diff --git a/src/main/java/com/volmit/iris/core/service/StudioSVC.java b/src/main/java/com/volmit/iris/core/service/StudioSVC.java index 5d42fb9a9..25ba76726 100644 --- a/src/main/java/com/volmit/iris/core/service/StudioSVC.java +++ b/src/main/java/com/volmit/iris/core/service/StudioSVC.java @@ -163,6 +163,12 @@ public class StudioSVC implements IrisService { try { url = getListing(false).get(key); + + if(url == null) + { + Iris.warn("ITS ULL for " + key); + } + url = url == null ? key : url; Iris.info("Assuming URL " + url); String branch = "master"; @@ -289,10 +295,6 @@ public class StudioSVC implements IrisService { } public KMap getListing(boolean cached) { - if (cached && cacheListing != null) { - return cacheListing; - } - JSONObject a; if (cached) { @@ -308,6 +310,8 @@ public class StudioSVC implements IrisService { l.put(i, a.getString(i)); } + l.put("IrisDimensions/overworld/master", "IrisDimensions/overworld/stable"); + l.put("overworld", "IrisDimensions/overworld/stable"); return l; } diff --git a/src/main/java/com/volmit/iris/core/tools/IrisToolbelt.java b/src/main/java/com/volmit/iris/core/tools/IrisToolbelt.java index 3c5b58d75..4b0541080 100644 --- a/src/main/java/com/volmit/iris/core/tools/IrisToolbelt.java +++ b/src/main/java/com/volmit/iris/core/tools/IrisToolbelt.java @@ -180,40 +180,6 @@ public class IrisToolbelt { return false; } - /** - * Attempts to ensure that the pack is installed - * - * @param sender the sender - * @param url the dimension - * @throws Throwable shit happens - */ - public static void install(VolmitSender sender, String url) throws Throwable { - IrisProjectRepo r = IrisProjectRepo.from(url); - - if (r != null) { - url = r.getRepo(); - } - - File f = Iris.instance.getDataFolder("packs", url); - IO.delete(f); - KList j = new KList<>(); - File pack = new File(Iris.getTemp(), UUID.nameUUIDFromBytes(r.toURL().getBytes(StandardCharsets.UTF_8)) + ".zip"); - j.add(new DownloadJob(r.toURL(), pack)); - j.add(new SingleJob("Extracting", () -> { - File work = new File(Iris.getTemp(), "dltk-" + UUID.randomUUID()); - ZipUtil.unpack(pack, work); - File raw = work.listFiles()[0]; - try { - FileUtils.copyDirectory(raw, f); - } catch (IOException e) { - e.printStackTrace(); - } - })); - - JobCollection c = new JobCollection("Pack", j); - c.execute(sender); - } - /** * Evacuate all players from the world * From b7309ccdf12dec9750c4f43b00023c1e6fdf9e25 Mon Sep 17 00:00:00 2001 From: cyberpwn Date: Mon, 16 Aug 2021 19:15:31 -0400 Subject: [PATCH 05/13] Comments --- src/main/java/com/volmit/iris/core/service/StudioSVC.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/com/volmit/iris/core/service/StudioSVC.java b/src/main/java/com/volmit/iris/core/service/StudioSVC.java index 25ba76726..ba37b1deb 100644 --- a/src/main/java/com/volmit/iris/core/service/StudioSVC.java +++ b/src/main/java/com/volmit/iris/core/service/StudioSVC.java @@ -310,6 +310,7 @@ public class StudioSVC implements IrisService { l.put(i, a.getString(i)); } + // TEMP FIX l.put("IrisDimensions/overworld/master", "IrisDimensions/overworld/stable"); l.put("overworld", "IrisDimensions/overworld/stable"); return l; From 32f34f144483ca44800a962436dd8f4f0b5e2f6f Mon Sep 17 00:00:00 2001 From: cyberpwn Date: Mon, 16 Aug 2021 19:35:03 -0400 Subject: [PATCH 06/13] Dim installing --- .../volmit/iris/core/project/IrisPack.java | 57 +++++++++++++++++++ .../volmit/iris/core/tools/IrisToolbelt.java | 12 ---- ...ojectRepo.java => IrisPackRepository.java} | 48 ++++++++++++++-- 3 files changed, 99 insertions(+), 18 deletions(-) create mode 100644 src/main/java/com/volmit/iris/core/project/IrisPack.java rename src/main/java/com/volmit/iris/util/data/{IrisProjectRepo.java => IrisPackRepository.java} (59%) diff --git a/src/main/java/com/volmit/iris/core/project/IrisPack.java b/src/main/java/com/volmit/iris/core/project/IrisPack.java new file mode 100644 index 000000000..98822810d --- /dev/null +++ b/src/main/java/com/volmit/iris/core/project/IrisPack.java @@ -0,0 +1,57 @@ +/* + * Iris is a World Generator for Minecraft Bukkit Servers + * Copyright (c) 2021 Arcane Arts (Volmit Software) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package com.volmit.iris.core.project; + +import com.volmit.iris.Iris; +import com.volmit.iris.core.service.StudioSVC; +import com.volmit.iris.util.data.IrisPackRepository; +import com.volmit.iris.util.io.IO; +import com.volmit.iris.util.plugin.VolmitSender; +import lombok.Data; + +import java.io.File; +import java.net.MalformedURLException; + +@Data +public class IrisPack { + private final File folder; + + public IrisPack(File folder) + { + this.folder = folder; + } + + public void delete() + { + IO.delete(folder); + folder.delete(); + } + + public static IrisPack from(VolmitSender sender, String url) throws MalformedURLException { + return from(sender, IrisPackRepository.from(url)); + } + + public static IrisPack from(VolmitSender sender, IrisPackRepository repo) throws MalformedURLException { + String name = repo.getRepo(); + String url = repo.toURL(); + repo.install(sender); + + return new IrisPack(Iris.instance.getDataFolder(StudioSVC.WORKSPACE_NAME, repo.getRepo())); + } +} diff --git a/src/main/java/com/volmit/iris/core/tools/IrisToolbelt.java b/src/main/java/com/volmit/iris/core/tools/IrisToolbelt.java index 4b0541080..39ff711b5 100644 --- a/src/main/java/com/volmit/iris/core/tools/IrisToolbelt.java +++ b/src/main/java/com/volmit/iris/core/tools/IrisToolbelt.java @@ -30,24 +30,12 @@ import com.volmit.iris.core.service.StudioSVC; import com.volmit.iris.engine.object.dimensional.IrisDimension; import com.volmit.iris.engine.platform.HeadlessGenerator; import com.volmit.iris.engine.platform.PlatformChunkGenerator; -import com.volmit.iris.util.collection.KList; -import com.volmit.iris.util.data.IrisProjectRepo; -import com.volmit.iris.util.io.IO; import com.volmit.iris.util.plugin.VolmitSender; -import com.volmit.iris.util.scheduling.jobs.DownloadJob; -import com.volmit.iris.util.scheduling.jobs.Job; -import com.volmit.iris.util.scheduling.jobs.JobCollection; -import com.volmit.iris.util.scheduling.jobs.SingleJob; import org.bukkit.Bukkit; import org.bukkit.World; import org.bukkit.entity.Player; -import org.zeroturnaround.zip.ZipUtil; -import org.zeroturnaround.zip.commons.FileUtils; import java.io.File; -import java.io.IOException; -import java.nio.charset.StandardCharsets; -import java.util.UUID; /** * Something you really want to wear if working on Iris. Shit gets pretty hectic down there. diff --git a/src/main/java/com/volmit/iris/util/data/IrisProjectRepo.java b/src/main/java/com/volmit/iris/util/data/IrisPackRepository.java similarity index 59% rename from src/main/java/com/volmit/iris/util/data/IrisProjectRepo.java rename to src/main/java/com/volmit/iris/util/data/IrisPackRepository.java index b3fa89818..3b4620955 100644 --- a/src/main/java/com/volmit/iris/util/data/IrisProjectRepo.java +++ b/src/main/java/com/volmit/iris/util/data/IrisPackRepository.java @@ -18,12 +18,28 @@ package com.volmit.iris.util.data; +import com.volmit.iris.Iris; +import com.volmit.iris.core.service.StudioSVC; +import com.volmit.iris.util.collection.KList; +import com.volmit.iris.util.format.Form; +import com.volmit.iris.util.plugin.VolmitSender; +import com.volmit.iris.util.scheduling.jobs.DownloadJob; +import com.volmit.iris.util.scheduling.jobs.Job; +import com.volmit.iris.util.scheduling.jobs.JobCollection; +import com.volmit.iris.util.scheduling.jobs.SingleJob; import lombok.Builder; import lombok.Data; +import org.zeroturnaround.zip.ZipUtil; +import org.zeroturnaround.zip.commons.FileUtils; + +import java.io.File; +import java.io.IOException; +import java.net.MalformedURLException; +import java.util.UUID; @Data @Builder -public class IrisProjectRepo { +public class IrisPackRepository { @Builder.Default private String user = "IrisDimensions"; @@ -36,11 +52,11 @@ public class IrisProjectRepo { @Builder.Default private String tag = ""; - public static IrisProjectRepo from(String g) { + public static IrisPackRepository from(String g) { // https://github.com/IrisDimensions/overworld if (g.startsWith("https://github.com/")) { String sub = g.split("\\Qgithub.com/\\E")[1]; - IrisProjectRepo r = IrisProjectRepo.builder() + IrisPackRepository r = IrisPackRepository.builder() .user(sub.split("\\Q/\\E")[0]) .repo(sub.split("\\Q/\\E")[1]).build(); @@ -55,12 +71,12 @@ public class IrisProjectRepo { if (f.length == 1) { return from(g); } else if (f.length == 2) { - return IrisProjectRepo.builder() + return IrisPackRepository.builder() .user(f[0]) .repo(f[1]) .build(); } else if (f.length >= 3) { - IrisProjectRepo r = IrisProjectRepo.builder() + IrisPackRepository r = IrisPackRepository.builder() .user(f[0]) .repo(f[1]) .build(); @@ -74,7 +90,7 @@ public class IrisProjectRepo { return r; } } else { - return IrisProjectRepo.builder() + return IrisPackRepository.builder() .user("IrisDimensions") .repo(g) .branch(g.equals("overworld") ? "stable" : "master") @@ -91,4 +107,24 @@ public class IrisProjectRepo { return "https://codeload.github.com/" + user + "/" + repo + "/zip/refs/heads/" + branch; } + + public void install(VolmitSender sender) throws MalformedURLException { + File pack = Iris.instance.getDataFolder(StudioSVC.WORKSPACE_NAME, getRepo()); + + if(!pack.exists()) + { + File dl = new File(Iris.getTemp(), "dltk-" + UUID.randomUUID() + ".zip"); + File work = new File(Iris.getTemp(), "extk-" + UUID.randomUUID()); + new JobCollection(Form.capitalize(getRepo()), + new DownloadJob(toURL(), pack), + new SingleJob("Extracting", () -> ZipUtil.unpack(dl, work)), + new SingleJob("Installing", () -> { + try { + FileUtils.copyDirectory(work.listFiles()[0], pack); + } catch (IOException e) { + e.printStackTrace(); + } + })).execute(sender); + } + } } From 51802f71a5bd379397b45570a1054abeb9720f6f Mon Sep 17 00:00:00 2001 From: cyberpwn Date: Mon, 16 Aug 2021 23:23:39 -0400 Subject: [PATCH 07/13] Fix hotloading bricking the engine --- src/main/java/com/volmit/iris/Iris.java | 39 +++++++++++-- .../com/volmit/iris/core/decrees/DecIris.java | 5 ++ .../com/volmit/iris/engine/IrisEngine.java | 14 ++++- .../volmit/iris/engine/framework/Engine.java | 2 +- .../framework/WrongEngineBroException.java | 22 ++++++++ .../engine/platform/BukkitChunkGenerator.java | 56 +++++++++++++++---- .../com/volmit/iris/util/mantle/Mantle.java | 5 ++ 7 files changed, 124 insertions(+), 19 deletions(-) create mode 100644 src/main/java/com/volmit/iris/engine/framework/WrongEngineBroException.java diff --git a/src/main/java/com/volmit/iris/Iris.java b/src/main/java/com/volmit/iris/Iris.java index d3d943729..76c6fd91e 100644 --- a/src/main/java/com/volmit/iris/Iris.java +++ b/src/main/java/com/volmit/iris/Iris.java @@ -50,10 +50,7 @@ import com.volmit.iris.util.math.RNG; import com.volmit.iris.util.parallel.MultiBurst; import com.volmit.iris.util.plugin.*; import com.volmit.iris.util.reflect.ShadeFix; -import com.volmit.iris.util.scheduling.GroupedExecutor; -import com.volmit.iris.util.scheduling.J; -import com.volmit.iris.util.scheduling.Queue; -import com.volmit.iris.util.scheduling.ShurikenQueue; +import com.volmit.iris.util.scheduling.*; import io.papermc.lib.PaperLib; import net.kyori.adventure.platform.bukkit.BukkitAudiences; import net.kyori.adventure.text.serializer.ComponentSerializer; @@ -71,6 +68,7 @@ import java.io.*; import java.lang.annotation.Annotation; import java.net.URL; import java.util.Date; +import java.util.Map; @SuppressWarnings("CanBeFinal") public class Iris extends VolmitPlugin implements Listener { @@ -707,4 +705,37 @@ public class Iris extends VolmitPlugin implements Listener { } } + + public static void dump() + { + try + { + File fi = Iris.instance.getDataFile("dump", "td-" + new java.sql.Date(M.ms()) + ".txt"); + FileOutputStream fos = new FileOutputStream(fi ); + Map f = Thread.getAllStackTraces(); + PrintWriter pw = new PrintWriter(fos); + for(Thread i : f.keySet()) + { + pw.println("========================================"); + pw.println("Thread: '" + i.getName() + "' ID: " + i.getId() + " STATUS: " + i.getState().name()); + + for(StackTraceElement j : f.get(i)) + { + pw.println(" @ " + j.toString()); + } + + pw.println("========================================"); + pw.println(); + pw.println(); + } + + pw.close(); + System.out.println("DUMPED! See " + fi.getAbsolutePath()); + } + + catch(Throwable e) + { + e.printStackTrace(); + } + } } diff --git a/src/main/java/com/volmit/iris/core/decrees/DecIris.java b/src/main/java/com/volmit/iris/core/decrees/DecIris.java index ff15a8c5d..9898d2b8f 100644 --- a/src/main/java/com/volmit/iris/core/decrees/DecIris.java +++ b/src/main/java/com/volmit/iris/core/decrees/DecIris.java @@ -28,8 +28,13 @@ import com.volmit.iris.util.decree.DecreeOrigin; import com.volmit.iris.util.decree.annotations.Decree; import com.volmit.iris.util.decree.annotations.Param; import com.volmit.iris.util.format.C; +import com.volmit.iris.util.math.M; import java.io.File; +import java.io.FileOutputStream; +import java.io.PrintWriter; +import java.sql.Date; +import java.util.Map; @Decree(name = "irisd", aliases = {"ird"}, description = "Basic Command") public class DecIris implements DecreeExecutor { diff --git a/src/main/java/com/volmit/iris/engine/IrisEngine.java b/src/main/java/com/volmit/iris/engine/IrisEngine.java index 55ff8ed4b..129b81a29 100644 --- a/src/main/java/com/volmit/iris/engine/IrisEngine.java +++ b/src/main/java/com/volmit/iris/engine/IrisEngine.java @@ -65,6 +65,8 @@ import org.bukkit.generator.BlockPopulator; import java.io.File; import java.io.IOException; import java.util.Random; +import java.util.concurrent.Semaphore; +import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicLong; @@ -287,12 +289,11 @@ public class IrisEngine extends BlockPopulator implements Engine { @Override public void close() { - J.car(art); closed = true; + J.car(art); getWorldManager().close(); getTarget().close(); saveEngineData(); - getMantle().close(); getTerrainActuator().close(); getDecorantActuator().close(); getBiomeActuator().close(); @@ -300,6 +301,8 @@ public class IrisEngine extends BlockPopulator implements Engine { getRavineModifier().close(); getCaveModifier().close(); getPostModifier().close(); + getMantle().close(); + Iris.debug("Engine Fully Shutdown!"); } @Override @@ -355,7 +358,12 @@ public class IrisEngine extends BlockPopulator implements Engine { @BlockCoordinates @Override - public void generate(int x, int z, Hunk vblocks, Hunk vbiomes, boolean multicore) { + public void generate(int x, int z, Hunk vblocks, Hunk vbiomes, boolean multicore) throws WrongEngineBroException { + if(closed) + { + throw new WrongEngineBroException(); + } + context.touch(); getEngineData().getStatistics().generatedChunk(); try { diff --git a/src/main/java/com/volmit/iris/engine/framework/Engine.java b/src/main/java/com/volmit/iris/engine/framework/Engine.java index f46de7481..d16c4724a 100644 --- a/src/main/java/com/volmit/iris/engine/framework/Engine.java +++ b/src/main/java/com/volmit/iris/engine/framework/Engine.java @@ -139,7 +139,7 @@ public interface Engine extends DataProvider, Fallible, LootProvider, BlockUpdat double modifyZ(double z); @BlockCoordinates - void generate(int x, int z, Hunk blocks, Hunk biomes, boolean multicore); + void generate(int x, int z, Hunk blocks, Hunk biomes, boolean multicore) throws WrongEngineBroException; EngineMetrics getMetrics(); diff --git a/src/main/java/com/volmit/iris/engine/framework/WrongEngineBroException.java b/src/main/java/com/volmit/iris/engine/framework/WrongEngineBroException.java new file mode 100644 index 000000000..8268f804d --- /dev/null +++ b/src/main/java/com/volmit/iris/engine/framework/WrongEngineBroException.java @@ -0,0 +1,22 @@ +/* + * Iris is a World Generator for Minecraft Bukkit Servers + * Copyright (c) 2021 Arcane Arts (Volmit Software) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package com.volmit.iris.engine.framework; + +public class WrongEngineBroException extends Exception { +} diff --git a/src/main/java/com/volmit/iris/engine/platform/BukkitChunkGenerator.java b/src/main/java/com/volmit/iris/engine/platform/BukkitChunkGenerator.java index 9e16f961d..984109e9f 100644 --- a/src/main/java/com/volmit/iris/engine/platform/BukkitChunkGenerator.java +++ b/src/main/java/com/volmit/iris/engine/platform/BukkitChunkGenerator.java @@ -21,11 +21,13 @@ package com.volmit.iris.engine.platform; import com.volmit.iris.Iris; import com.volmit.iris.engine.data.chunk.TerrainChunk; import com.volmit.iris.engine.framework.Engine; +import com.volmit.iris.engine.framework.WrongEngineBroException; import com.volmit.iris.engine.object.common.IrisWorld; import com.volmit.iris.util.collection.KList; import com.volmit.iris.util.hunk.Hunk; import com.volmit.iris.util.io.ReactiveFolder; import com.volmit.iris.util.scheduling.ChronoLatch; +import com.volmit.iris.util.scheduling.J; import com.volmit.iris.util.scheduling.Looper; import com.volmit.iris.util.scheduling.PrecisionStopwatch; import org.bukkit.Bukkit; @@ -40,8 +42,10 @@ import org.jetbrains.annotations.NotNull; import java.io.File; import java.util.List; import java.util.Random; +import java.util.concurrent.Semaphore; public class BukkitChunkGenerator extends ChunkGenerator implements PlatformChunkGenerator { + private static final int HOTLOAD_LOCKS = 1000000; private final EngineProvider provider; private final IrisWorld world; private final File dataLocation; @@ -50,11 +54,13 @@ public class BukkitChunkGenerator extends ChunkGenerator implements PlatformChun private final KList populators; private final ChronoLatch hotloadChecker; private final Looper hotloader; + private final Semaphore hotloadLock; private final boolean studio; public BukkitChunkGenerator(IrisWorld world, boolean studio, File dataLocation, String dimensionKey) { populators = new KList<>(); this.world = world; + this.hotloadLock = new Semaphore(HOTLOAD_LOCKS); this.hotloadChecker = new ChronoLatch(1000, false); this.studio = studio; this.dataLocation = dataLocation; @@ -78,8 +84,11 @@ public class BukkitChunkGenerator extends ChunkGenerator implements PlatformChun hotloader.setName(getTarget().getWorld().name() + " Hotloader"); } - public Engine getEngine() { - return provider.getEngine(); + public synchronized Engine getEngine() { + synchronized (provider) + { + return provider.getEngine(); + } } @Override @@ -89,8 +98,11 @@ public class BukkitChunkGenerator extends ChunkGenerator implements PlatformChun @Override public void close() { - hotloader.interrupt(); - provider.close(); + synchronized (provider) + { + hotloader.interrupt(); + provider.close(); + } } @Override @@ -100,19 +112,36 @@ public class BukkitChunkGenerator extends ChunkGenerator implements PlatformChun @Override public void hotload() { - initialize(); + J.aBukkit(() -> { + try { + hotloadLock.acquire(HOTLOAD_LOCKS); + initialize(); + hotloadLock.release(HOTLOAD_LOCKS); + } catch (InterruptedException e) { + e.printStackTrace(); + } + }); } private void initialize() { - provider.provideEngine(world, dimensionKey, dataLocation, isStudio(), (e) -> { - populators.clear(); - populators.add((BlockPopulator) e); - folder.checkIgnore(); - }); + synchronized (provider) + { + provider.provideEngine(world, dimensionKey, dataLocation, isStudio(), (e) -> { + populators.clear(); + populators.add((BlockPopulator) e); + folder.checkIgnore(); + }); + } } @Override public @NotNull ChunkData generateChunkData(@NotNull World world, @NotNull Random ignored, int x, int z, @NotNull BiomeGrid biome) { + try { + hotloadLock.acquire(); + } catch (InterruptedException e) { + e.printStackTrace(); + } + try { Iris.debug("Generated " + x + " " + z); PrecisionStopwatch ps = PrecisionStopwatch.start(); @@ -121,8 +150,11 @@ public class BukkitChunkGenerator extends ChunkGenerator implements PlatformChun Hunk biomes = Hunk.view((BiomeGrid) tc); this.world.bind(world); getEngine().generate(x * 16, z * 16, blocks, biomes, true); + hotloadLock.release(); return tc.getRaw(); - } catch (Throwable e) { + } + + catch (Throwable e) { Iris.error("======================================"); e.printStackTrace(); Iris.reportErrorChunk(x, z, e, "CHUNK"); @@ -136,8 +168,10 @@ public class BukkitChunkGenerator extends ChunkGenerator implements PlatformChun } } + hotloadLock.release(); return d; } + } @NotNull diff --git a/src/main/java/com/volmit/iris/util/mantle/Mantle.java b/src/main/java/com/volmit/iris/util/mantle/Mantle.java index 80da0a9b1..625bc64b1 100644 --- a/src/main/java/com/volmit/iris/util/mantle/Mantle.java +++ b/src/main/java/com/volmit/iris/util/mantle/Mantle.java @@ -179,6 +179,11 @@ public class Mantle { .get(x & 15, y & 15, z & 15); } + public boolean isClosed() + { + return closed.get(); + } + /** * Closes the Mantle. By closing the mantle, you can no longer read or write * any data to the mantle or it's Tectonic Plates. Closing will also flush any From aff1a245c28ba702182bea9dc3f908c247346554 Mon Sep 17 00:00:00 2001 From: cyberpwn Date: Mon, 16 Aug 2021 23:30:33 -0400 Subject: [PATCH 08/13] Make hotloading idiot proof --- build.gradle | 2 +- .../engine/platform/BukkitChunkGenerator.java | 27 ++++++++++++------- 2 files changed, 19 insertions(+), 10 deletions(-) diff --git a/build.gradle b/build.gradle index a614f23db..9e62e4237 100644 --- a/build.gradle +++ b/build.gradle @@ -32,7 +32,7 @@ plugins { } group 'com.volmit.iris' -version '1.7.1' +version '1.7.2' def apiVersion = '1.17' def name = getRootProject().getName() // See settings.gradle def main = 'com.volmit.iris.Iris' diff --git a/src/main/java/com/volmit/iris/engine/platform/BukkitChunkGenerator.java b/src/main/java/com/volmit/iris/engine/platform/BukkitChunkGenerator.java index 984109e9f..0500e0e87 100644 --- a/src/main/java/com/volmit/iris/engine/platform/BukkitChunkGenerator.java +++ b/src/main/java/com/volmit/iris/engine/platform/BukkitChunkGenerator.java @@ -112,15 +112,17 @@ public class BukkitChunkGenerator extends ChunkGenerator implements PlatformChun @Override public void hotload() { - J.aBukkit(() -> { - try { - hotloadLock.acquire(HOTLOAD_LOCKS); - initialize(); - hotloadLock.release(HOTLOAD_LOCKS); - } catch (InterruptedException e) { - e.printStackTrace(); - } - }); + J.aBukkit(this::hotloadBLOCKING); + } + + public void hotloadBLOCKING() { + try { + hotloadLock.acquire(HOTLOAD_LOCKS); + initialize(); + hotloadLock.release(HOTLOAD_LOCKS); + } catch (InterruptedException e) { + e.printStackTrace(); + } } private void initialize() { @@ -154,6 +156,13 @@ public class BukkitChunkGenerator extends ChunkGenerator implements PlatformChun return tc.getRaw(); } + catch(WrongEngineBroException e) + { + hotloadLock.release(); + hotloadBLOCKING(); + return generateChunkData(world, ignored, x, z, biome); + } + catch (Throwable e) { Iris.error("======================================"); e.printStackTrace(); From 3348d46b5a8c808b81df098f7e71760941372d4b Mon Sep 17 00:00:00 2001 From: cyberpwn Date: Mon, 16 Aug 2021 23:41:07 -0400 Subject: [PATCH 09/13] Endersignal debug --- .../iris/engine/framework/EngineAssignedWorldManager.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/volmit/iris/engine/framework/EngineAssignedWorldManager.java b/src/main/java/com/volmit/iris/engine/framework/EngineAssignedWorldManager.java index 9041d6b31..47173cfb2 100644 --- a/src/main/java/com/volmit/iris/engine/framework/EngineAssignedWorldManager.java +++ b/src/main/java/com/volmit/iris/engine/framework/EngineAssignedWorldManager.java @@ -88,7 +88,9 @@ public abstract class EngineAssignedWorldManager extends EngineAssignedComponent if (pr != null) { e.getEntity().getWorld().playSound(e.getEntity().getLocation(), Sound.ITEM_TRIDENT_THROW, 1f, 1.6f); - ((EnderSignal) e.getEntity()).setTargetLocation(new Location(e.getEntity().getWorld(), pr.getX(), 40, pr.getZ())); + Location ll = new Location(e.getEntity().getWorld(), pr.getX(), 40, pr.getZ()); + Iris.debug("ESignal: " + ll.getBlockX() + " " + ll.getBlockZ()); + ((EnderSignal) e.getEntity()).setTargetLocation(ll); } } } From 0dbabe629aa04baf2b9153a2628490cf798e3f3d Mon Sep 17 00:00:00 2001 From: cyberpwn Date: Mon, 16 Aug 2021 23:47:33 -0400 Subject: [PATCH 10/13] More debug --- .../iris/engine/framework/EngineAssignedWorldManager.java | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/main/java/com/volmit/iris/engine/framework/EngineAssignedWorldManager.java b/src/main/java/com/volmit/iris/engine/framework/EngineAssignedWorldManager.java index 47173cfb2..593fc55f5 100644 --- a/src/main/java/com/volmit/iris/engine/framework/EngineAssignedWorldManager.java +++ b/src/main/java/com/volmit/iris/engine/framework/EngineAssignedWorldManager.java @@ -78,6 +78,13 @@ public abstract class EngineAssignedWorldManager extends EngineAssignedComponent Position2 pr = null; double d = Double.MAX_VALUE; + Iris.debug("Ps: " + p.size()); + + for(Position2 i : p) + { + Iris.debug("- " + i.getX() + " " + i.getZ()); + } + for (Position2 i : p) { double dx = i.distance(px); if (dx < d) { From ff05429f583a9aaff17ecb46ac60b10882d5c7fa Mon Sep 17 00:00:00 2001 From: cyberpwn Date: Mon, 16 Aug 2021 23:51:40 -0400 Subject: [PATCH 11/13] Attempt --- src/main/java/com/volmit/iris/util/math/Position2.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/volmit/iris/util/math/Position2.java b/src/main/java/com/volmit/iris/util/math/Position2.java index 560a254df..4d1b9fc28 100644 --- a/src/main/java/com/volmit/iris/util/math/Position2.java +++ b/src/main/java/com/volmit/iris/util/math/Position2.java @@ -92,6 +92,6 @@ public class Position2 { } public IrisPosition toIris() { - return new IrisPosition(x, 0, z); + return new IrisPosition(x, 23, z); } } From d79af8fcc25d9709fa53319a06257a0e47e037ae Mon Sep 17 00:00:00 2001 From: cyberpwn Date: Tue, 17 Aug 2021 00:19:12 -0400 Subject: [PATCH 12/13] Fix update --- src/main/java/com/volmit/iris/engine/IrisEngine.java | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/volmit/iris/engine/IrisEngine.java b/src/main/java/com/volmit/iris/engine/IrisEngine.java index 129b81a29..fd062e5e2 100644 --- a/src/main/java/com/volmit/iris/engine/IrisEngine.java +++ b/src/main/java/com/volmit/iris/engine/IrisEngine.java @@ -423,8 +423,16 @@ public class IrisEngine extends BlockPopulator implements Engine { @ChunkCoordinates @Override public void populate(World world, Random random, Chunk c) { - updateChunk(c); - placeTiles(c); + try + { + updateChunk(c); + placeTiles(c); + } + + catch(Throwable e) + { + e.printStackTrace(); + } } @Override From b55bf6e6c15723a635f7a035048d5b3603d23230 Mon Sep 17 00:00:00 2001 From: StrangeOne101 Date: Tue, 17 Aug 2021 23:20:09 +1200 Subject: [PATCH 13/13] 2 Bug Fixes - Fixed #552 by making sure the biome saved in datapacks is all lowercase - Fixed extra character showing when Iris downloads a pack --- .../java/com/volmit/iris/core/nms/v17_1/NMSBinding17_1.java | 2 +- src/main/java/com/volmit/iris/core/service/StudioSVC.java | 2 +- .../com/volmit/iris/engine/object/biome/IrisBiomeCustom.java | 4 ++++ .../volmit/iris/engine/object/dimensional/IrisDimension.java | 4 ++-- 4 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/volmit/iris/core/nms/v17_1/NMSBinding17_1.java b/src/main/java/com/volmit/iris/core/nms/v17_1/NMSBinding17_1.java index a0a3f92b0..542297741 100644 --- a/src/main/java/com/volmit/iris/core/nms/v17_1/NMSBinding17_1.java +++ b/src/main/java/com/volmit/iris/core/nms/v17_1/NMSBinding17_1.java @@ -228,7 +228,7 @@ public class NMSBinding17_1 implements INMSBinding { @Override public Object getCustomBiomeBaseFor(String mckey) { try { - return getCustomBiomeRegistry().d(ResourceKey.a(IRegistry.aO, new MinecraftKey(mckey))); + return getCustomBiomeRegistry().d(ResourceKey.a(IRegistry.aO, new MinecraftKey(mckey.toLowerCase()))); } catch (Throwable e) { Iris.reportError(e); } diff --git a/src/main/java/com/volmit/iris/core/service/StudioSVC.java b/src/main/java/com/volmit/iris/core/service/StudioSVC.java index ba37b1deb..d47de46b1 100644 --- a/src/main/java/com/volmit/iris/core/service/StudioSVC.java +++ b/src/main/java/com/volmit/iris/core/service/StudioSVC.java @@ -189,7 +189,7 @@ public class StudioSVC implements IrisService { public void download(VolmitSender sender, String repo, String branch, boolean trim, boolean forceOverwrite) throws JsonSyntaxException, IOException { String url = "https://codeload.github.com/" + repo + "/zip/refs/heads/" + branch; - sender.sendMessage("Downloading " + url); + sender.sendMessage("Downloading " + url + " "); //The extra space stops a bug in adventure API from repeating the last letter of the URL File zip = Iris.getNonCachedFile("pack-" + trim + "-" + repo, url); File temp = Iris.getTemp(); File work = new File(temp, "dl-" + UUID.randomUUID()); diff --git a/src/main/java/com/volmit/iris/engine/object/biome/IrisBiomeCustom.java b/src/main/java/com/volmit/iris/engine/object/biome/IrisBiomeCustom.java index 7a1476116..3d800d89e 100644 --- a/src/main/java/com/volmit/iris/engine/object/biome/IrisBiomeCustom.java +++ b/src/main/java/com/volmit/iris/engine/object/biome/IrisBiomeCustom.java @@ -167,4 +167,8 @@ public class IrisBiomeCustom { return 0; } + + public String getId() { + return id.toLowerCase(); + } } diff --git a/src/main/java/com/volmit/iris/engine/object/dimensional/IrisDimension.java b/src/main/java/com/volmit/iris/engine/object/dimensional/IrisDimension.java index 35ce5e094..ca571c184 100644 --- a/src/main/java/com/volmit/iris/engine/object/dimensional/IrisDimension.java +++ b/src/main/java/com/volmit/iris/engine/object/dimensional/IrisDimension.java @@ -472,14 +472,14 @@ public class IrisDimension extends IrisRegistrant { boolean write = false; boolean changed = false; - IO.delete(new File(datapacks, "iris/data/" + getLoadKey())); + IO.delete(new File(datapacks, "iris/data/" + getLoadKey().toLowerCase())); for (IrisBiome i : getAllBiomes(data)) { if (i.isCustom()) { write = true; for (IrisBiomeCustom j : i.getCustomDerivitives()) { - File output = new File(datapacks, "iris/data/" + getLoadKey() + "/worldgen/biome/" + j.getId() + ".json"); + File output = new File(datapacks, "iris/data/" + getLoadKey().toLowerCase() + "/worldgen/biome/" + j.getId() + ".json"); if (!output.exists()) { changed = true;