diff --git a/src/main/java/ninja/bytecode/iris/CommandIris.java b/src/main/java/ninja/bytecode/iris/CommandIris.java deleted file mode 100644 index 403c72203..000000000 --- a/src/main/java/ninja/bytecode/iris/CommandIris.java +++ /dev/null @@ -1,358 +0,0 @@ -package ninja.bytecode.iris; - -import java.util.function.Consumer; - -import org.bukkit.Bukkit; -import org.bukkit.ChatColor; -import org.bukkit.Chunk; -import org.bukkit.Location; -import org.bukkit.World; -import org.bukkit.command.Command; -import org.bukkit.command.CommandExecutor; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; - -import mortar.api.nms.NMP; -import mortar.api.sched.J; -import mortar.util.text.C; -import ninja.bytecode.iris.controller.PackController; -import ninja.bytecode.iris.generator.IrisGenerator; -import ninja.bytecode.iris.generator.WorldReactor; -import ninja.bytecode.iris.generator.genobject.PlacedObject; -import ninja.bytecode.iris.pack.CompiledDimension; -import ninja.bytecode.iris.pack.IrisBiome; -import ninja.bytecode.iris.util.BiomeLayer; -import ninja.bytecode.shuriken.collections.KList; -import ninja.bytecode.shuriken.collections.KMap; -import ninja.bytecode.shuriken.execution.ChronoLatch; -import ninja.bytecode.shuriken.format.Form; -import ninja.bytecode.shuriken.logging.L; - -public class CommandIris implements CommandExecutor -{ - public void msg(CommandSender s, String msg) - { - s.sendMessage(ChatColor.DARK_PURPLE + "[" + ChatColor.GRAY + "Iris" + ChatColor.DARK_PURPLE + "]" + ChatColor.GRAY + ": " + msg); - } - - @Override - public boolean onCommand(CommandSender sender, Command command, String label, String[] args) - { - if(args.length == 0) - { - msg(sender, "/iris timings - Iris Timings"); - msg(sender, "/iris rtp [biome] - RTP to a biome"); - msg(sender, "/iris otp [schematic] - RTP to a specific schematic"); - msg(sender, "/iris info - Chunk info"); - msg(sender, "/iris hotload - Recompile pack & inject into worlds"); - msg(sender, "/iris reload - Reload & Recompile"); - msg(sender, "/iris clean - Clean Pack Install in Iris Folder"); - msg(sender, "/ish - Iris Schematic Commands"); - } - - if(args.length > 0) - { - if(args[0].equalsIgnoreCase("timings")) - { - if(sender instanceof Player) - { - Player p = (Player) sender; - World w = p.getWorld(); - - if(w.getGenerator() instanceof IrisGenerator) - { - ((IrisGenerator) w.getGenerator()).getMetrics().send(p, (m) -> msg(p, m)); - } - - else - { - msg(p, "You must be in an iris world for this"); - } - } - } - - if(args[0].equalsIgnoreCase("info")) - { - if(sender instanceof Player) - { - Player p = (Player) sender; - World w = p.getWorld(); - - if(w.getGenerator() instanceof IrisGenerator) - { - IrisGenerator g = (IrisGenerator) w.getGenerator(); - IrisBiome biome = g.getBiome((int) g.getOffsetX(p.getLocation().getX(), p.getLocation().getZ()), (int) g.getOffsetZ(p.getLocation().getX(), p.getLocation().getZ())); - BiomeLayer l = new BiomeLayer(g, biome); - msg(p, "Biome: " + C.BOLD + C.WHITE + biome.getName() + C.RESET + C.GRAY + " (" + C.GOLD + l.getBiome().getRarityString() + C.GRAY + ")"); - - for(String i : biome.getSchematicGroups().k()) - { - String f = ""; - double percent = biome.getSchematicGroups().get(i); - - if(percent > 1D) - { - f = (int) percent + " + " + Form.pc(percent - (int) percent, percent - (int) percent >= 0.01 ? 0 : 3); - } - - else - { - f = Form.pc(percent, percent >= 0.01 ? 0 : 3); - } - - msg(p, "* " + C.DARK_GREEN + i + ": " + C.BOLD + C.WHITE + f + C.RESET + C.GRAY + " (" + Form.f(g.getDimension().getObjectGroup(i).size()) + " variants)"); - } - } - - else - { - msg(sender, "Not in an Iris World"); - } - } - } - - if(args[0].equalsIgnoreCase("otp")) - { - if(sender instanceof Player) - { - Player p = (Player) sender; - World w = p.getWorld(); - - if(w.getGenerator() instanceof IrisGenerator) - { - if(args.length >= 2) - { - PlacedObject o = ((IrisGenerator) w.getGenerator()).randomObject(args[1]); - - if(o != null) - { - Location l = new Location(w, o.getX(), o.getY(), o.getZ()); - p.teleport(l); - msg(p, "Found " + C.DARK_GREEN + o.getF().replace(":", "/" + C.WHITE)); - } - - else - { - msg(p, "Found Nothing"); - } - } - - else - { - msg(p, "/iris otp "); - } - } - } - } - - if(args[0].equalsIgnoreCase("rtp")) - { - if(sender instanceof Player) - { - Player p = (Player) sender; - World w = p.getWorld(); - - if(w.getGenerator() instanceof IrisGenerator) - { - if(args.length > 1) - { - IrisGenerator g = (IrisGenerator) w.getGenerator(); - IrisBiome b = null; - for(IrisBiome i : g.getDimension().getBiomes()) - { - if(args[1].toLowerCase().equals(i.getName().toLowerCase().replaceAll("\\Q \\E", "_"))) - { - b = i; - break; - } - } - - if(b == null) - { - msg(sender, "Unknown Biome: " + args[1]); - } - - else - { - msg(sender, "Looking for " + b.getName() + "..."); - boolean f = false; - int t = 0; - for(int i = 0; i < 10000; i++) - { - int x = (int) ((int) (29999983 / 1.2) * Math.random()); - int z = (int) ((int) (29999983 / 1.2) * Math.random()); - - if(g.getBiome((int) g.getOffsetX(x, z), (int) g.getOffsetZ(x, z)).equals(b)) - { - f = true; - - if(w.getHighestBlockYAt(x, z) > 66) - { - p.teleport(w.getHighestBlockAt(x, z).getLocation()); - break; - } - - else - { - t++; - - if(t > 30) - { - msg(sender, "Checked 30 " + b.getName() + " bearing chunks. All of them were underwater. Try Again!"); - break; - } - } - } - } - - if(!f) - { - msg(sender, "Looked for " + b.getName() + " in 10,000 different locations and could not find it. Try again!"); - } - } - } - - else - { - int x = (int) ((int) (29999983 / 1.2) * Math.random()); - int z = (int) ((int) (29999983 / 1.2) * Math.random()); - p.teleport(w.getHighestBlockAt(x, z).getLocation()); - } - } - - else - { - msg(sender, "Not in an Iris World"); - } - } - } - - if(args[0].equalsIgnoreCase("hotload")) - { - msg(sender, "=== Hotloading Pack ==="); - PackController c = Iris.getController(PackController.class); - KMap f = new KMap<>(); - - for(World i : Bukkit.getWorlds()) - { - if(i.getGenerator() instanceof IrisGenerator) - { - String n = ((IrisGenerator) i.getGenerator()).getDimension().getName(); - msg(sender, "Preparing " + n); - f.put(i.getName(), n); - } - } - - if(f.isEmpty()) - { - msg(sender, "No Worlds to inject!"); - return true; - } - - J.a(() -> - { - try - { - Consumer m = (msg) -> - { - J.s(() -> - { - String mm = msg; - - if(msg.contains("|")) - { - KList fx = new KList<>(); - fx.add(msg.split("\\Q|\\E")); - fx.remove(0); - fx.remove(0); - mm = fx.toString(""); - } - - msg(sender, mm.replaceAll("\\Q \\E", "")); - }); - }; - L.addLogConsumer(m); - c.compile(); - L.logConsumers.remove(m); - - J.s(() -> - { - if(sender instanceof Player) - { - ChronoLatch cl = new ChronoLatch(3000); - Player p = (Player) sender; - World ww = ((Player) sender).getWorld(); - - msg(p, "Regenerating View Distance"); - - WorldReactor r = new WorldReactor(ww); - r.generateRegionNormal(p, true, 200, (pct) -> - { - if(cl.flip()) - { - msg(p, "Regenerating " + Form.pc(pct)); - } - }, () -> - { - msg(p, "Done! Use F3 + A"); - }); - } - }, 5); - - for(String fi : f.k()) - { - J.s(() -> - { - World i = Bukkit.getWorld(fi); - CompiledDimension dim = c.getDimension(f.get(fi)); - - for(String k : c.getDimensions().k()) - { - if(c.getDimension(k).getName().equals(f.get(fi))) - { - dim = c.getDimension(k); - break; - } - } - - if(dim == null) - { - J.s(() -> msg(sender, "Cannot find dimnension: " + f.get(fi))); - return; - } - msg(sender, "Hotloaded " + i.getName()); - IrisGenerator g = ((IrisGenerator) i.getGenerator()); - g.inject(dim); - }); - } - } - - catch(Throwable e) - { - e.printStackTrace(); - } - }); - - } - - if(args[0].equalsIgnoreCase("reload")) - { - msg(sender, "Reloading Iris..."); - Iris.instance.reload(); - } - - if(args[0].equalsIgnoreCase("refresh")) - { - msg(sender, "Sec..."); - Player p = ((Player) sender); - - for(Chunk i : p.getWorld().getLoadedChunks()) - { - NMP.CHUNK.refresh(p, i); - } - } - } - - return false; - } -} diff --git a/src/main/java/ninja/bytecode/iris/CommandIsh.java b/src/main/java/ninja/bytecode/iris/CommandIsh.java deleted file mode 100644 index 48532edae..000000000 --- a/src/main/java/ninja/bytecode/iris/CommandIsh.java +++ /dev/null @@ -1,280 +0,0 @@ -package ninja.bytecode.iris; - -import java.io.File; -import java.io.FileInputStream; -import java.io.FileOutputStream; - -import org.bukkit.ChatColor; -import org.bukkit.Location; -import org.bukkit.Material; -import org.bukkit.Sound; -import org.bukkit.block.Block; -import org.bukkit.command.Command; -import org.bukkit.command.CommandExecutor; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; -import org.bukkit.util.Vector; - -import mortar.util.text.C; -import ninja.bytecode.iris.controller.WandController; -import ninja.bytecode.iris.generator.genobject.GenObject; -import ninja.bytecode.iris.util.Cuboid; -import ninja.bytecode.iris.util.Cuboid.CuboidDirection; -import ninja.bytecode.iris.util.Direction; -import ninja.bytecode.shuriken.format.Form; - -public class CommandIsh implements CommandExecutor -{ - public void msg(CommandSender s, String msg) - { - s.sendMessage(ChatColor.DARK_PURPLE + "[" + ChatColor.GRAY + "Iris" + ChatColor.DARK_PURPLE + "]" + ChatColor.GRAY + ": " + msg); - } - - @SuppressWarnings("deprecation") - @Override - public boolean onCommand(CommandSender sender, Command command, String label, String[] args) - { - if(args.length == 0) - { - msg(sender, "/ish wand - Get an Iris Wand"); - msg(sender, "/ish save - Save Schematic"); - msg(sender, "/ish load [cursor] - Paste Schematic"); - msg(sender, "/ish expand - Expand Cuboid in direction"); - msg(sender, "/ish shift - Shift Cuboid in direction"); - msg(sender, "/ish shrinkwrap - Shrink to blocks"); - msg(sender, "/ish xup - Shift up, Expand up, Contract in."); - msg(sender, "/ish xvert - Expand up, Expand down, Contract in."); - msg(sender, "/ish id - What id am i looking at"); - } - - if(args.length > 0) - { - if(sender instanceof Player) - { - Player p = (Player) sender; - if(args[0].equalsIgnoreCase("wand")) - { - p.getInventory().addItem(WandController.createWand()); - p.playSound(p.getLocation(), Sound.ITEM_ARMOR_EQUIP_DIAMOND, 1f, 1.55f); - } - - if(args[0].equalsIgnoreCase("id")) - { - - Block b = p.getTargetBlock(null, 64); - msg(p, b.getType().getId() + ":" + b.getData() + " (" + b.getType().toString() + ":" + b.getData() + ")"); - } - - if(args[0].equalsIgnoreCase("save")) - { - GenObject s = WandController.createSchematic(p.getInventory().getItemInMainHand(), p.getLocation()); - File f = new File(Iris.instance.getDataFolder(), "schematics/" + args[1] + ".ish"); - f.getParentFile().mkdirs(); - try - { - FileOutputStream fos = new FileOutputStream(f); - s.write(fos, true); - msg(p, "Saved " + args[1] + " (" + Form.f(s.getSchematic().size()) + " Entries)"); - p.playSound(p.getLocation(), Sound.BLOCK_ENCHANTMENT_TABLE_USE, 1f, 0.45f); - } - - catch(Throwable e1) - { - e1.printStackTrace(); - } - } - - if(args[0].equalsIgnoreCase("load")) - { - GenObject s = new GenObject(1, 1, 1); - File f = new File(Iris.instance.getDataFolder(), "schematics/" + args[1] + ".ish"); - if(!f.exists()) - { - msg(p, "Not Found"); - return true; - } - - try - { - FileInputStream fin = new FileInputStream(f); - s.read(fin, true); - - boolean cursor = false; - Direction df = null; - Direction dt = null; - - for(String i : args) - { - if(i.equalsIgnoreCase("cursor")) - { - cursor = true; - break; - } - - if(i.startsWith("from:")) - { - df = Direction.valueOf(i.split("\\Q:\\E")[1].toUpperCase().substring(0, 1)); - } - - if(i.startsWith("to:")) - { - dt = Direction.valueOf(i.split("\\Q:\\E")[1].toUpperCase().substring(0, 1)); - } - } - - if(dt != null && df != null) - { - msg(sender, "Rotating " + C.WHITE + df + C.GRAY + " to " + C.WHITE + dt); - s.rotate(df, dt); - } - - Location at = p.getLocation(); - - if(cursor) - { - at = p.getTargetBlock(null, 64).getLocation(); - } - - WandController.pasteSchematic(s, at); - p.playSound(p.getLocation(), Sound.BLOCK_ENCHANTMENT_TABLE_USE, 1f, 1.25f); - msg(p, "Pasted " + args[1] + " (" + Form.f(s.getSchematic().size()) + " Blocks Modified)"); - } - - catch(Throwable e1) - { - e1.printStackTrace(); - } - } - - if(args[0].equalsIgnoreCase("xup")) - { - Location[] b = WandController.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(); - Location a2 = b[1].clone(); - Cuboid cursor = new Cuboid(a1, a2); - - while(!cursor.containsOnly(Material.AIR)) - { - a1.add(new Vector(0, 1, 0)); - a2.add(new Vector(0, 1, 0)); - cursor = new Cuboid(a1, a2); - } - - a1.add(new Vector(0, -1, 0)); - a2.add(new Vector(0, -1, 0)); - b[0] = a1; - a2 = b[1]; - cursor = new Cuboid(a1, a2); - cursor = cursor.contract(CuboidDirection.North); - cursor = cursor.contract(CuboidDirection.South); - cursor = cursor.contract(CuboidDirection.East); - cursor = cursor.contract(CuboidDirection.West); - b[0] = cursor.getLowerNE(); - b[1] = cursor.getUpperSW(); - p.getInventory().setItemInMainHand(WandController.createWand(b[0], b[1])); - p.updateInventory(); - p.playSound(p.getLocation(), Sound.ENTITY_ITEMFRAME_ROTATE_ITEM, 1f, 0.55f); - } - - if(args[0].equalsIgnoreCase("shrinkwrap") || args[0].equalsIgnoreCase("shrink")) - { - Location[] b = WandController.getCuboid(p.getInventory().getItemInMainHand()); - Location a1 = b[0].clone(); - Location a2 = b[1].clone(); - Cuboid cursor = new Cuboid(a1, a2); - cursor = cursor.contract(CuboidDirection.North); - cursor = cursor.contract(CuboidDirection.South); - cursor = cursor.contract(CuboidDirection.East); - cursor = cursor.contract(CuboidDirection.West); - cursor = cursor.contract(CuboidDirection.Up); - cursor = cursor.contract(CuboidDirection.Down); - b[0] = cursor.getLowerNE(); - b[1] = cursor.getUpperSW(); - p.getInventory().setItemInMainHand(WandController.createWand(b[0], b[1])); - p.updateInventory(); - p.playSound(p.getLocation(), Sound.ENTITY_ITEMFRAME_ROTATE_ITEM, 1f, 0.55f); - } - - if(args[0].equalsIgnoreCase("expand")) - { - int amt = Integer.valueOf(args[1]); - Location[] b = WandController.getCuboid(p.getInventory().getItemInMainHand()); - Location a1 = b[0].clone(); - Location a2 = b[1].clone(); - Cuboid cursor = new Cuboid(a1, a2); - Direction d = Direction.closest(p.getLocation().getDirection()).reverse(); - cursor = cursor.expand(d, amt); - b[0] = cursor.getLowerNE(); - b[1] = cursor.getUpperSW(); - p.getInventory().setItemInMainHand(WandController.createWand(b[0], b[1])); - p.updateInventory(); - p.playSound(p.getLocation(), Sound.ENTITY_ITEMFRAME_ROTATE_ITEM, 1f, 0.55f); - } - - if(args[0].equalsIgnoreCase("shift")) - { - int amt = Integer.valueOf(args[1]); - Location[] b = WandController.getCuboid(p.getInventory().getItemInMainHand()); - Location a1 = b[0].clone(); - Location a2 = b[1].clone(); - Direction d = Direction.closest(p.getLocation().getDirection()).reverse(); - a1.add(d.toVector().multiply(amt)); - a2.add(d.toVector().multiply(amt)); - Cuboid cursor = new Cuboid(a1, a2); - b[0] = cursor.getLowerNE(); - b[1] = cursor.getUpperSW(); - p.getInventory().setItemInMainHand(WandController.createWand(b[0], b[1])); - p.updateInventory(); - p.playSound(p.getLocation(), Sound.ENTITY_ITEMFRAME_ROTATE_ITEM, 1f, 0.55f); - } - - if(args[0].equalsIgnoreCase("xvert")) - { - Location[] b = WandController.getCuboid(p.getInventory().getItemInMainHand()); - Location a1 = b[0].clone(); - Location a2 = b[1].clone(); - Location a1x = b[0].clone(); - Location a2x = b[1].clone(); - Cuboid cursor = new Cuboid(a1, a2); - Cuboid cursorx = new Cuboid(a1, a2); - - while(!cursor.containsOnly(Material.AIR)) - { - a1.add(new Vector(0, 1, 0)); - a2.add(new Vector(0, 1, 0)); - cursor = new Cuboid(a1, a2); - } - - a1.add(new Vector(0, -1, 0)); - a2.add(new Vector(0, -1, 0)); - - while(!cursorx.containsOnly(Material.AIR)) - { - a1x.add(new Vector(0, -1, 0)); - a2x.add(new Vector(0, -1, 0)); - cursorx = new Cuboid(a1x, a2x); - } - - a1x.add(new Vector(0, 1, 0)); - a2x.add(new Vector(0, 1, 0)); - b[0] = a1; - b[1] = a2x; - cursor = new Cuboid(b[0], b[1]); - cursor = cursor.contract(CuboidDirection.North); - cursor = cursor.contract(CuboidDirection.South); - cursor = cursor.contract(CuboidDirection.East); - cursor = cursor.contract(CuboidDirection.West); - b[0] = cursor.getLowerNE(); - b[1] = cursor.getUpperSW(); - p.getInventory().setItemInMainHand(WandController.createWand(b[0], b[1])); - p.updateInventory(); - p.playSound(p.getLocation(), Sound.ENTITY_ITEMFRAME_ROTATE_ITEM, 1f, 0.55f); - } - } - } - - return false; - } -} diff --git a/src/main/java/ninja/bytecode/iris/CommandIshOld.java b/src/main/java/ninja/bytecode/iris/CommandIshOld.java new file mode 100644 index 000000000..e153a9e76 --- /dev/null +++ b/src/main/java/ninja/bytecode/iris/CommandIshOld.java @@ -0,0 +1,65 @@ +package ninja.bytecode.iris; + +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; + +import org.bukkit.ChatColor; +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.Sound; +import org.bukkit.block.Block; +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; +import org.bukkit.util.Vector; + +import mortar.util.text.C; +import ninja.bytecode.iris.controller.WandController; +import ninja.bytecode.iris.generator.genobject.GenObject; +import ninja.bytecode.iris.util.Cuboid; +import ninja.bytecode.iris.util.Cuboid.CuboidDirection; +import ninja.bytecode.iris.util.Direction; +import ninja.bytecode.shuriken.format.Form; + +public class CommandIshOld implements CommandExecutor +{ + public void msg(CommandSender s, String msg) + { + s.sendMessage(ChatColor.DARK_PURPLE + "[" + ChatColor.GRAY + "Iris" + ChatColor.DARK_PURPLE + "]" + ChatColor.GRAY + ": " + msg); + } + + @SuppressWarnings("deprecation") + @Override + public boolean onCommand(CommandSender sender, Command command, String label, String[] args) + { + if(args.length == 0) + { + msg(sender, "/ish wand - Get an Iris Wand"); + msg(sender, "/ish save - Save Schematic"); + msg(sender, "/ish load [cursor] - Paste Schematic"); + msg(sender, "/ish expand - Expand Cuboid in direction"); + msg(sender, "/ish shift - Shift Cuboid in direction"); + msg(sender, "/ish shrinkwrap - Shrink to blocks"); + msg(sender, "/ish xup - Shift up, Expand up, Contract in."); + msg(sender, "/ish xvert - Expand up, Expand down, Contract in."); + msg(sender, "/ish id - What id am i looking at"); + } + + if(args.length > 0) + { + if(sender instanceof Player) + { + Player p = (Player) sender; + + if(args[0].equalsIgnoreCase("xvert")) + { + + } + } + } + + return false; + } +} diff --git a/src/main/java/ninja/bytecode/iris/Iris.java b/src/main/java/ninja/bytecode/iris/Iris.java index 98a8294c5..ff12361c9 100644 --- a/src/main/java/ninja/bytecode/iris/Iris.java +++ b/src/main/java/ninja/bytecode/iris/Iris.java @@ -1,82 +1,62 @@ package ninja.bytecode.iris; -import java.io.IOException; - import org.bukkit.Bukkit; -import org.bukkit.World; import org.bukkit.event.HandlerList; import org.bukkit.event.Listener; import org.bukkit.generator.ChunkGenerator; import org.bukkit.plugin.Plugin; -import org.bukkit.plugin.java.JavaPlugin; +import mortar.bukkit.command.Command; +import mortar.bukkit.plugin.Control; +import mortar.bukkit.plugin.Instance; +import mortar.bukkit.plugin.MortarPlugin; +import mortar.util.text.C; +import ninja.bytecode.iris.command.CommandIris; +import ninja.bytecode.iris.controller.ExecutionController; import ninja.bytecode.iris.controller.PackController; import ninja.bytecode.iris.controller.WandController; import ninja.bytecode.iris.generator.IrisGenerator; import ninja.bytecode.iris.util.Direction; -import ninja.bytecode.iris.util.IrisController; -import ninja.bytecode.iris.util.IrisControllerSet; import ninja.bytecode.shuriken.logging.L; -public class Iris extends JavaPlugin implements Listener +public class Iris extends MortarPlugin { - public IrisControllerSet controllerSet; public static Thread primaryThread; public static Settings settings; - public static Iris instance; public static IrisMetrics metrics; - public void onEnable() + @Instance + public static Iris instance; + + @Control + private ExecutionController executionController; + + @Control + private PackController packController; + + @Control + private WandController wandController; + + @Command + private CommandIris commandIris; + + @Override + public void start() { primaryThread = Thread.currentThread(); instance = this; - controllerSet = new IrisControllerSet(); L.consoleConsumer = (s) -> Bukkit.getConsoleSender().sendMessage(s); - - try - { - controllerSet.startControllers(getFile()); - } - - catch(IOException e) - { - L.ex(e); - } - - L.i("Controllers: " + controllerSet.size()); - Direction.calculatePermutations(); settings = new Settings(); getServer().getPluginManager().registerEvents((Listener) this, this); - getCommand("iris").setExecutor(new CommandIris()); - getCommand("ish").setExecutor(new CommandIsh()); - - if(!settings.performance.debugMode) - { - getController(PackController.class).compile(); - } + packController.compile(); } - public void onDisable() + @Override + public void stop() { - getController(PackController.class).dispose(); - getController(WandController.class).dispose(); - controllerSet.stopControllers(); HandlerList.unregisterAll((Plugin) this); Bukkit.getScheduler().cancelTasks(this); - - if(Iris.settings.performance.debugMode) - { - for(World i : Bukkit.getWorlds()) - { - if(i.getGenerator() instanceof IrisGenerator) - { - ((IrisGenerator) i.getGenerator()).dispose(); - } - } - - System.gc(); - } } public void reload() @@ -88,15 +68,35 @@ public class Iris extends JavaPlugin implements Listener }); } - @SuppressWarnings("unchecked") - public static T getController(Class c) - { - return (T) instance.controllerSet.get(c); - } - @Override public ChunkGenerator getDefaultWorldGenerator(String worldName, String id) { return new IrisGenerator(); } + + @Override + public String getTag(String arg0) + { + return makeTag(C.GREEN, C.DARK_GRAY, C.GRAY, C.BOLD + "Iris" + C.RESET); + } + + public static String makeTag(C brace, C tag, C text, String tagName) + { + return brace + "\u3008" + tag + tagName + brace + "\u3009" + " " + text; + } + + public static PackController pack() + { + return instance.packController; + } + + public static ExecutionController exec() + { + return instance.executionController; + } + + public static WandController wand() + { + return instance.wandController; + } } diff --git a/src/main/java/ninja/bytecode/iris/IrisMetrics.java b/src/main/java/ninja/bytecode/iris/IrisMetrics.java index c61d2b6cd..f423572f5 100644 --- a/src/main/java/ninja/bytecode/iris/IrisMetrics.java +++ b/src/main/java/ninja/bytecode/iris/IrisMetrics.java @@ -2,11 +2,10 @@ package ninja.bytecode.iris; import java.util.function.Consumer; -import org.bukkit.entity.Player; +import org.bukkit.command.CommandSender; import mortar.compute.math.M; import mortar.util.text.C; -import ninja.bytecode.iris.controller.ExecutionController; import ninja.bytecode.shuriken.bench.PrecisionStopwatch; import ninja.bytecode.shuriken.collections.KList; import ninja.bytecode.shuriken.collections.KMap; @@ -118,7 +117,7 @@ public class IrisMetrics this.sequences = sequences; } - public void send(Player p, Consumer c) + public void send(CommandSender p, Consumer c) { send(p, c, null, 0); } @@ -128,7 +127,7 @@ public class IrisMetrics scale = sf; } - public void send(Player p, Consumer c, String parent, int ind) + public void send(CommandSender p, Consumer c, String parent, int ind) { KMap out = new KMap<>(); @@ -219,7 +218,7 @@ public class IrisMetrics if(ind == 0) { c.accept(C.WHITE.toString() + C.BOLD + "Total Generators: " + C.RESET + C.DARK_AQUA + C.ITALIC + Form.f(generators)); - c.accept(C.WHITE.toString() + C.BOLD + "Parallelism: " + C.RESET + C.DARK_PURPLE + C.ITALIC + Form.pc(scale) + C.WHITE + C.BOLD + " Threads: " + C.RESET + C.BLUE + C.ITALIC + Iris.getController(ExecutionController.class).getTC()); + c.accept(C.WHITE.toString() + C.BOLD + "Parallelism: " + C.RESET + C.DARK_PURPLE + C.ITALIC + Form.pc(scale) + C.WHITE + C.BOLD + " Threads: " + C.RESET + C.BLUE + C.ITALIC + Iris.exec().getTC()); } for(String i : out.k()) diff --git a/src/main/java/ninja/bytecode/iris/command/CommandFind.java b/src/main/java/ninja/bytecode/iris/command/CommandFind.java new file mode 100644 index 000000000..7a47f0f61 --- /dev/null +++ b/src/main/java/ninja/bytecode/iris/command/CommandFind.java @@ -0,0 +1,33 @@ +package ninja.bytecode.iris.command; + +import mortar.bukkit.command.Command; +import mortar.bukkit.command.MortarCommand; +import mortar.bukkit.command.MortarSender; +import mortar.util.text.C; + +public class CommandFind extends MortarCommand +{ + @Command + private CommandFindBiome fBiome; + + @Command + private CommandFindObject fObject; + + public CommandFind() + { + super("find", "f"); + setDescription("Teleport to a specific biome / object"); + } + + @Override + public boolean handle(MortarSender sender, String[] args) + { + for(MortarCommand i : getChildren()) + { + sender.sendMessage("/iris find " + C.WHITE + i.getNode() + C.GRAY + (!i.getNodes().isEmpty() ? "," : "") + i.getNodes().toString(",") + " - " + C.DARK_GREEN + i.getDescription()); + } + + return true; + } + +} diff --git a/src/main/java/ninja/bytecode/iris/command/CommandFindBiome.java b/src/main/java/ninja/bytecode/iris/command/CommandFindBiome.java new file mode 100644 index 000000000..83ec2293f --- /dev/null +++ b/src/main/java/ninja/bytecode/iris/command/CommandFindBiome.java @@ -0,0 +1,87 @@ +package ninja.bytecode.iris.command; + +import org.bukkit.World; +import org.bukkit.entity.Player; + +import mortar.bukkit.command.MortarCommand; +import mortar.bukkit.command.MortarSender; +import ninja.bytecode.iris.generator.IrisGenerator; +import ninja.bytecode.iris.pack.IrisBiome; + +public class CommandFindBiome extends MortarCommand +{ + public CommandFindBiome() + { + super("biome", "b"); + setDescription("Teleport to a biome by name"); + } + + @Override + public boolean handle(MortarSender sender, String[] args) + { + World w = null; + + if(sender.isPlayer() && sender.player().getWorld().getGenerator() instanceof IrisGenerator) + { + w = sender.player().getWorld(); + } + + else + { + sender.sendMessage("Console / Non-Iris World."); + return true; + } + + Player p = sender.player(); + IrisGenerator g = (IrisGenerator) w.getGenerator(); + if(args.length > 0) + { + IrisBiome b = null; + for(IrisBiome i : g.getDimension().getBiomes()) + { + if(args[0].toLowerCase().equals(i.getName().toLowerCase().replaceAll("\\Q \\E", "_"))) + { + b = i; + break; + } + } + + if(b == null) + { + sender.sendMessage("Couldn't find any biomes containing '" + args[0] + "'."); + } + + else + { + sender.sendMessage("Looking for Biome " + b.getName() + "..."); + boolean f = false; + + for(int i = 0; i < 10000; i++) + { + int x = (int) ((int) (29999983 / 1.2) * Math.random()); + int z = (int) ((int) (29999983 / 1.2) * Math.random()); + + if(g.getBiome((int) g.getOffsetX(x, z), (int) g.getOffsetZ(x, z)).equals(b)) + { + f = true; + p.teleport(w.getHighestBlockAt(x, z).getLocation()); + break; + } + } + + if(!f) + { + sender.sendMessage("Couldn't for " + b.getName() + " in 10,000 different locations and could not find it. Try again!"); + } + } + } + + else + { + sender.sendMessage("/iris find biome "); + } + + return true; + } + +} diff --git a/src/main/java/ninja/bytecode/iris/command/CommandFindObject.java b/src/main/java/ninja/bytecode/iris/command/CommandFindObject.java new file mode 100644 index 000000000..da2d110a9 --- /dev/null +++ b/src/main/java/ninja/bytecode/iris/command/CommandFindObject.java @@ -0,0 +1,64 @@ +package ninja.bytecode.iris.command; + +import org.bukkit.Location; +import org.bukkit.World; +import org.bukkit.entity.Player; + +import mortar.bukkit.command.MortarCommand; +import mortar.bukkit.command.MortarSender; +import mortar.util.text.C; +import ninja.bytecode.iris.generator.IrisGenerator; +import ninja.bytecode.iris.generator.genobject.PlacedObject; + +public class CommandFindObject extends MortarCommand +{ + public CommandFindObject() + { + super("object", "o"); + setDescription("Teleport to an object by name"); + } + + @Override + public boolean handle(MortarSender sender, String[] args) + { + World w = null; + + if(sender.isPlayer() && sender.player().getWorld().getGenerator() instanceof IrisGenerator) + { + w = sender.player().getWorld(); + } + + else + { + sender.sendMessage("Console / Non-Iris World."); + return true; + } + + Player p = sender.player(); + + if(args.length > 0) + { + PlacedObject o = ((IrisGenerator) w.getGenerator()).randomObject(args[0]); + + if(o != null) + { + Location l = new Location(w, o.getX(), o.getY(), o.getZ()); + p.teleport(l); + sender.sendMessage("Found Object " + C.DARK_GREEN + o.getF().replace(":", "/" + C.WHITE)); + } + + else + { + sender.sendMessage("Couldn't find any objects containing '" + args[0] + "' Either"); + } + } + + else + { + sender.sendMessage("/iris find object "); + } + + return true; + } + +} diff --git a/src/main/java/ninja/bytecode/iris/command/CommandIris.java b/src/main/java/ninja/bytecode/iris/command/CommandIris.java index ed84e98a8..a7907abb8 100644 --- a/src/main/java/ninja/bytecode/iris/command/CommandIris.java +++ b/src/main/java/ninja/bytecode/iris/command/CommandIris.java @@ -1,132 +1,44 @@ package ninja.bytecode.iris.command; -import org.bukkit.Bukkit; -import org.bukkit.ChatColor; -import org.bukkit.GameMode; -import org.bukkit.Location; -import org.bukkit.World; -import org.bukkit.command.Command; -import org.bukkit.command.CommandExecutor; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; +import mortar.bukkit.command.Command; +import mortar.bukkit.command.MortarCommand; +import mortar.bukkit.command.MortarSender; +import mortar.util.text.C; -import ninja.bytecode.iris.Iris; -import ninja.bytecode.iris.controller.TimingsController; -import ninja.bytecode.iris.controller.WorldController; -import ninja.bytecode.iris.generator.IrisGenerator; -import ninja.bytecode.iris.pack.IrisBiome; -import ninja.bytecode.shuriken.format.Form; - -public class CommandIris implements CommandExecutor +public class CommandIris extends MortarCommand { - public void msg(CommandSender s, String msg) + @Command + private CommandTimings timings; + + @Command + private CommandWhat what; + + @Command + private CommandFind find; + + @Command + private CommandObject object; + + @Command + private CommandSelection selection; + + @Command + private CommandReload reload; + + public CommandIris() { - s.sendMessage(ChatColor.DARK_PURPLE + "[" + ChatColor.GRAY + "Iris" + ChatColor.DARK_PURPLE + "]" + ChatColor.GRAY + ": " + msg); + super("iris", "irs", "ir"); } @Override - public boolean onCommand(CommandSender sender, Command command, String label, String[] args) + public boolean handle(MortarSender sender, String[] args) { - if(args.length == 0) + for(MortarCommand i : getChildren()) { - msg(sender, "/iris timings - Iris Timings"); - msg(sender, "/iris rtp [biome] - RTP to a biome"); - msg(sender, "/iris gen - Gen a new Iris World"); - msg(sender, "/ish - Iris Schematic Commands"); + sender.sendMessage("/iris " + C.WHITE + i.getNode() + C.GRAY + (!i.getNodes().isEmpty() ? "," : "") + i.getNodes().toString(",") + " - " + C.DARK_GREEN + i.getDescription()); } - if(args.length > 0) - { - if(args[0].equalsIgnoreCase("timings")) - { - double t = Iris.getController(TimingsController.class).getResult("terrain"); - double d = Iris.getController(TimingsController.class).getResult("decor"); - msg(sender, "Generation: " + ChatColor.BOLD + ChatColor.WHITE + Form.duration(t + d, 2)); - msg(sender, " \\Terrain: " + ChatColor.BOLD + ChatColor.WHITE + Form.duration(t, 2)); - msg(sender, " \\Decor: " + ChatColor.BOLD + ChatColor.WHITE + Form.duration(d, 2)); - } - - if(args[0].equalsIgnoreCase("rtp")) - { - if(sender instanceof Player) - { - Player p = (Player) sender; - World w = p.getWorld(); - - if(w.getGenerator() instanceof IrisGenerator) - { - if(args.length > 1) - { - IrisGenerator g = (IrisGenerator) w.getGenerator(); - IrisBiome b = null; - for(IrisBiome i : g.getDimension().getBiomes()) - { - if(args[1].toLowerCase().equals(i.getName().toLowerCase().replaceAll("\\Q \\E", "_"))) - { - b = i; - break; - } - } - - if(b == null) - { - msg(sender, "Unknown Biome: " + args[1]); - } - - else - { - msg(sender, "Looking for " + b.getName() + "..."); - boolean f = false; - for(int i = 0; i < 10000; i++) - { - int x = (int) ((int) (29999983 / 1.2) * Math.random()); - int z = (int) ((int) (29999983 / 1.2) * Math.random()); - - if(g.getBiome(x, z).equals(b)) - { - f = true; - p.teleport(w.getHighestBlockAt(x, z).getLocation()); - break; - } - } - - if(!f) - { - msg(sender, "Looked for " + b.getName() + " in 10,000 different locations and could not find it. Try again!"); - } - } - } - - else - { - int x = (int) ((int) (29999983 / 1.2) * Math.random()); - int z = (int) ((int) (29999983 / 1.2) * Math.random()); - p.teleport(w.getHighestBlockAt(x, z).getLocation()); - } - } - } - } - - if(args[0].equalsIgnoreCase("gen")) - { - if(sender instanceof Player) - { - World wold = ((Player) sender).getWorld(); - World w = Iris.getController(WorldController.class).createIrisWorld(null, 0, true); - ((Player) sender).teleport(new Location(w, 0, 256, 0)); - ((Player) sender).setFlying(true); - ((Player) sender).setGameMode(GameMode.CREATIVE); - wold.setAutoSave(false); - Bukkit.unloadWorld(wold, false); - } - - else - { - Iris.getController(WorldController.class).createIrisWorld(null, 0, true); - } - } - } - - return false; + return true; } + } diff --git a/src/main/java/ninja/bytecode/iris/command/CommandIsh.java b/src/main/java/ninja/bytecode/iris/command/CommandIsh.java deleted file mode 100644 index 855b2b9c6..000000000 --- a/src/main/java/ninja/bytecode/iris/command/CommandIsh.java +++ /dev/null @@ -1,261 +0,0 @@ -package ninja.bytecode.iris.command; - -import java.io.File; -import java.io.FileInputStream; -import java.io.FileOutputStream; - -import org.bukkit.ChatColor; -import org.bukkit.Location; -import org.bukkit.Material; -import org.bukkit.Sound; -import org.bukkit.block.Block; -import org.bukkit.command.Command; -import org.bukkit.command.CommandExecutor; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; -import org.bukkit.util.Vector; - -import ninja.bytecode.iris.Iris; -import ninja.bytecode.iris.controller.WandController; -import ninja.bytecode.iris.generator.genobject.GenObject; -import ninja.bytecode.iris.util.Cuboid; -import ninja.bytecode.iris.util.Cuboid.CuboidDirection; -import ninja.bytecode.iris.util.Direction; -import ninja.bytecode.shuriken.format.Form; - -public class CommandIsh implements CommandExecutor -{ - public void msg(CommandSender s, String msg) - { - s.sendMessage(ChatColor.DARK_PURPLE + "[" + ChatColor.GRAY + "Iris" + ChatColor.DARK_PURPLE + "]" + ChatColor.GRAY + ": " + msg); - } - - @SuppressWarnings("deprecation") - @Override - public boolean onCommand(CommandSender sender, Command command, String label, String[] args) - { - if(args.length == 0) - { - msg(sender, "/ish wand - Get an Iris Wand"); - msg(sender, "/ish save - Save Schematic"); - msg(sender, "/ish load [cursor] - Paste Schematic"); - msg(sender, "/ish expand - Expand Cuboid in direction"); - msg(sender, "/ish shift - Shift Cuboid in direction"); - msg(sender, "/ish shrinkwrap - Shrink to blocks"); - msg(sender, "/ish xup - Shift up, Expand up, Contract in."); - msg(sender, "/ish xvert - Expand up, Expand down, Contract in."); - msg(sender, "/ish id - What id am i looking at"); - } - - if(args.length > 0) - { - if(sender instanceof Player) - { - Player p = (Player) sender; - if(args[0].equalsIgnoreCase("wand")) - { - p.getInventory().addItem(WandController.createWand()); - p.playSound(p.getLocation(), Sound.ITEM_ARMOR_EQUIP_DIAMOND, 1f, 1.55f); - } - - if(args[0].equalsIgnoreCase("id")) - { - - Block b = p.getTargetBlock(null, 64); - msg(p, b.getType().getId() + ":" + b.getData() + " (" + b.getType().toString() + ":" + b.getData() + ")"); - } - - if(args[0].equalsIgnoreCase("save")) - { - GenObject s = WandController.createSchematic(p.getInventory().getItemInMainHand(), p.getLocation()); - File f = new File(Iris.instance.getDataFolder(), "schematics/" + args[1] + ".ish"); - f.getParentFile().mkdirs(); - try - { - FileOutputStream fos = new FileOutputStream(f); - s.write(fos, true); - msg(p, "Saved " + args[1] + " (" + Form.f(s.getSchematic().size()) + " Entries)"); - p.playSound(p.getLocation(), Sound.BLOCK_ENCHANTMENT_TABLE_USE, 1f, 0.45f); - } - - catch(Throwable e1) - { - e1.printStackTrace(); - } - } - - if(args[0].equalsIgnoreCase("load")) - { - GenObject s = new GenObject(1, 1, 1); - File f = new File(Iris.instance.getDataFolder(), "schematics/" + args[1] + ".ish"); - if(!f.exists()) - { - msg(p, "Not Found"); - return true; - } - - try - { - FileInputStream fin = new FileInputStream(f); - s.read(fin, true); - - boolean cursor = false; - for(String i : args) - { - if(i.equalsIgnoreCase("cursor")) - { - cursor = true; - break; - } - } - - Location at = p.getLocation(); - - if(cursor) - { - at = p.getTargetBlock(null, 64).getLocation(); - } - - WandController.pasteSchematic(s, at); - p.playSound(p.getLocation(), Sound.BLOCK_ENCHANTMENT_TABLE_USE, 1f, 1.25f); - msg(p, "Pasted " + args[1] + " (" + Form.f(s.getSchematic().size()) + " Blocks Modified)"); - } - - catch(Throwable e1) - { - e1.printStackTrace(); - } - } - - if(args[0].equalsIgnoreCase("xup")) - { - Location[] b = WandController.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(); - Location a2 = b[1].clone(); - Cuboid cursor = new Cuboid(a1, a2); - - while(!cursor.containsOnly(Material.AIR)) - { - a1.add(new Vector(0, 1, 0)); - a2.add(new Vector(0, 1, 0)); - cursor = new Cuboid(a1, a2); - } - - a1.add(new Vector(0, -1, 0)); - a2.add(new Vector(0, -1, 0)); - b[0] = a1; - a2 = b[1]; - cursor = new Cuboid(a1, a2); - cursor = cursor.contract(CuboidDirection.North); - cursor = cursor.contract(CuboidDirection.South); - cursor = cursor.contract(CuboidDirection.East); - cursor = cursor.contract(CuboidDirection.West); - b[0] = cursor.getLowerNE(); - b[1] = cursor.getUpperSW(); - p.getInventory().setItemInMainHand(WandController.createWand(b[0], b[1])); - p.updateInventory(); - p.playSound(p.getLocation(), Sound.ENTITY_ITEMFRAME_ROTATE_ITEM, 1f, 0.55f); - } - - if(args[0].equalsIgnoreCase("shrinkwrap") || args[0].equalsIgnoreCase("shrink")) - { - Location[] b = WandController.getCuboid(p.getInventory().getItemInMainHand()); - Location a1 = b[0].clone(); - Location a2 = b[1].clone(); - Cuboid cursor = new Cuboid(a1, a2); - cursor = cursor.contract(CuboidDirection.North); - cursor = cursor.contract(CuboidDirection.South); - cursor = cursor.contract(CuboidDirection.East); - cursor = cursor.contract(CuboidDirection.West); - cursor = cursor.contract(CuboidDirection.Up); - cursor = cursor.contract(CuboidDirection.Down); - b[0] = cursor.getLowerNE(); - b[1] = cursor.getUpperSW(); - p.getInventory().setItemInMainHand(WandController.createWand(b[0], b[1])); - p.updateInventory(); - p.playSound(p.getLocation(), Sound.ENTITY_ITEMFRAME_ROTATE_ITEM, 1f, 0.55f); - } - - if(args[0].equalsIgnoreCase("expand")) - { - int amt = Integer.valueOf(args[1]); - Location[] b = WandController.getCuboid(p.getInventory().getItemInMainHand()); - Location a1 = b[0].clone(); - Location a2 = b[1].clone(); - Cuboid cursor = new Cuboid(a1, a2); - Direction d = Direction.closest(p.getLocation().getDirection()).reverse(); - cursor = cursor.expand(d, amt); - b[0] = cursor.getLowerNE(); - b[1] = cursor.getUpperSW(); - p.getInventory().setItemInMainHand(WandController.createWand(b[0], b[1])); - p.updateInventory(); - p.playSound(p.getLocation(), Sound.ENTITY_ITEMFRAME_ROTATE_ITEM, 1f, 0.55f); - } - - if(args[0].equalsIgnoreCase("shift")) - { - int amt = Integer.valueOf(args[1]); - Location[] b = WandController.getCuboid(p.getInventory().getItemInMainHand()); - Location a1 = b[0].clone(); - Location a2 = b[1].clone(); - Direction d = Direction.closest(p.getLocation().getDirection()).reverse(); - a1.add(d.toVector().multiply(amt)); - a2.add(d.toVector().multiply(amt)); - Cuboid cursor = new Cuboid(a1, a2); - b[0] = cursor.getLowerNE(); - b[1] = cursor.getUpperSW(); - p.getInventory().setItemInMainHand(WandController.createWand(b[0], b[1])); - p.updateInventory(); - p.playSound(p.getLocation(), Sound.ENTITY_ITEMFRAME_ROTATE_ITEM, 1f, 0.55f); - } - - if(args[0].equalsIgnoreCase("xvert")) - { - Location[] b = WandController.getCuboid(p.getInventory().getItemInMainHand()); - Location a1 = b[0].clone(); - Location a2 = b[1].clone(); - Location a1x = b[0].clone(); - Location a2x = b[1].clone(); - Cuboid cursor = new Cuboid(a1, a2); - Cuboid cursorx = new Cuboid(a1, a2); - - while(!cursor.containsOnly(Material.AIR)) - { - a1.add(new Vector(0, 1, 0)); - a2.add(new Vector(0, 1, 0)); - cursor = new Cuboid(a1, a2); - } - - a1.add(new Vector(0, -1, 0)); - a2.add(new Vector(0, -1, 0)); - - while(!cursorx.containsOnly(Material.AIR)) - { - a1x.add(new Vector(0, -1, 0)); - a2x.add(new Vector(0, -1, 0)); - cursorx = new Cuboid(a1x, a2x); - } - - a1x.add(new Vector(0, 1, 0)); - a2x.add(new Vector(0, 1, 0)); - b[0] = a1; - b[1] = a2x; - cursor = new Cuboid(b[0], b[1]); - cursor = cursor.contract(CuboidDirection.North); - cursor = cursor.contract(CuboidDirection.South); - cursor = cursor.contract(CuboidDirection.East); - cursor = cursor.contract(CuboidDirection.West); - b[0] = cursor.getLowerNE(); - b[1] = cursor.getUpperSW(); - p.getInventory().setItemInMainHand(WandController.createWand(b[0], b[1])); - p.updateInventory(); - p.playSound(p.getLocation(), Sound.ENTITY_ITEMFRAME_ROTATE_ITEM, 1f, 0.55f); - } - } - } - - return false; - } -} diff --git a/src/main/java/ninja/bytecode/iris/command/CommandObject.java b/src/main/java/ninja/bytecode/iris/command/CommandObject.java new file mode 100644 index 000000000..1c44cabfe --- /dev/null +++ b/src/main/java/ninja/bytecode/iris/command/CommandObject.java @@ -0,0 +1,36 @@ +package ninja.bytecode.iris.command; + +import mortar.bukkit.command.Command; +import mortar.bukkit.command.MortarCommand; +import mortar.bukkit.command.MortarSender; +import mortar.util.text.C; + +public class CommandObject extends MortarCommand +{ + @Command + private CommandObjectWand oWand; + + @Command + private CommandObjectLoad oLoad; + + @Command + private CommandObjectSave oSave; + + public CommandObject() + { + super("object", "o"); + setDescription("Object Subcommands"); + } + + @Override + public boolean handle(MortarSender sender, String[] args) + { + for(MortarCommand i : getChildren()) + { + sender.sendMessage("/iris object " + C.WHITE + i.getNode() + C.GRAY + (!i.getNodes().isEmpty() ? "," : "") + i.getNodes().toString(",") + " - " + C.DARK_GREEN + i.getDescription()); + } + + return true; + } + +} diff --git a/src/main/java/ninja/bytecode/iris/command/CommandObjectLoad.java b/src/main/java/ninja/bytecode/iris/command/CommandObjectLoad.java new file mode 100644 index 000000000..f26ad6d92 --- /dev/null +++ b/src/main/java/ninja/bytecode/iris/command/CommandObjectLoad.java @@ -0,0 +1,106 @@ +package ninja.bytecode.iris.command; + +import java.io.File; +import java.io.FileInputStream; + +import org.bukkit.Location; +import org.bukkit.Sound; +import org.bukkit.entity.Player; + +import mortar.bukkit.command.MortarCommand; +import mortar.bukkit.command.MortarSender; +import mortar.util.text.C; +import ninja.bytecode.iris.Iris; +import ninja.bytecode.iris.controller.WandController; +import ninja.bytecode.iris.generator.genobject.GenObject; +import ninja.bytecode.iris.util.Direction; +import ninja.bytecode.shuriken.format.Form; + +public class CommandObjectLoad extends MortarCommand +{ + public CommandObjectLoad() + { + super("load", "l"); + setDescription("Load & Paste an object"); + } + + @Override + public boolean handle(MortarSender sender, String[] args) + { + if(!sender.isPlayer()) + { + sender.sendMessage("Players Only"); + return true; + } + + if(args.length < 1) + { + sender.sendMessage("/iris object load "); + return true; + } + + Player p = sender.player(); + + GenObject s = new GenObject(1, 1, 1); + File f = new File(Iris.instance.getDataFolder(), "schematics/" + args[0] + ".ish"); + if(!f.exists()) + { + sender.sendMessage("Can't find " + args[0]); + return true; + } + + try + { + FileInputStream fin = new FileInputStream(f); + s.read(fin, true); + + boolean cursor = false; + Direction df = null; + Direction dt = null; + + for(String i : args) + { + if(i.equalsIgnoreCase("cursor")) + { + cursor = true; + break; + } + + if(i.startsWith("from:")) + { + df = Direction.valueOf(i.split("\\Q:\\E")[1].toUpperCase().substring(0, 1)); + } + + if(i.startsWith("to:")) + { + dt = Direction.valueOf(i.split("\\Q:\\E")[1].toUpperCase().substring(0, 1)); + } + } + + if(dt != null && df != null) + { + sender.sendMessage("Rotating " + C.WHITE + df + C.GRAY + " to " + C.WHITE + dt); + s.rotate(df, dt); + } + + Location at = p.getLocation(); + + if(cursor) + { + at = p.getTargetBlock(null, 64).getLocation(); + } + + WandController.pasteSchematic(s, at); + p.playSound(p.getLocation(), Sound.BLOCK_ENCHANTMENT_TABLE_USE, 1f, 1.25f); + sender.sendMessage("Pasted " + args[0] + " (" + Form.f(s.getSchematic().size()) + " Blocks Modified)"); + } + + catch(Throwable e1) + { + e1.printStackTrace(); + } + + return true; + } + +} diff --git a/src/main/java/ninja/bytecode/iris/command/CommandObjectSave.java b/src/main/java/ninja/bytecode/iris/command/CommandObjectSave.java new file mode 100644 index 000000000..83f73f879 --- /dev/null +++ b/src/main/java/ninja/bytecode/iris/command/CommandObjectSave.java @@ -0,0 +1,67 @@ +package ninja.bytecode.iris.command; + +import java.io.File; +import java.io.FileOutputStream; + +import org.bukkit.Sound; +import org.bukkit.entity.Player; + +import mortar.bukkit.command.MortarCommand; +import mortar.bukkit.command.MortarSender; +import ninja.bytecode.iris.Iris; +import ninja.bytecode.iris.controller.WandController; +import ninja.bytecode.iris.generator.genobject.GenObject; +import ninja.bytecode.shuriken.format.Form; + +public class CommandObjectSave extends MortarCommand +{ + public CommandObjectSave() + { + super("save", "s"); + setDescription("Save an object"); + } + + @Override + public boolean handle(MortarSender sender, String[] args) + { + if(!sender.isPlayer()) + { + sender.sendMessage("Players Only"); + return true; + } + + if(args.length < 1) + { + sender.sendMessage("/iris object save "); + return true; + } + + Player p = sender.player(); + GenObject s = WandController.createSchematic(p.getInventory().getItemInMainHand(), p.getLocation()); + + if(s == null) + { + sender.sendMessage("Hold your wand while using this command."); + return true; + } + + File f = new File(Iris.instance.getDataFolder(), "schematics/" + args[0] + ".ish"); + f.getParentFile().mkdirs(); + try + { + FileOutputStream fos = new FileOutputStream(f); + s.write(fos, true); + p.sendMessage("Saved " + args[1] + " (" + Form.f(s.getSchematic().size()) + " Entries)"); + p.playSound(p.getLocation(), Sound.BLOCK_ENCHANTMENT_TABLE_USE, 1f, 0.45f); + } + + catch(Throwable e1) + { + p.sendMessage("Failed. Check the console!"); + e1.printStackTrace(); + } + + return true; + } + +} diff --git a/src/main/java/ninja/bytecode/iris/command/CommandObjectWand.java b/src/main/java/ninja/bytecode/iris/command/CommandObjectWand.java new file mode 100644 index 000000000..b98f2166b --- /dev/null +++ b/src/main/java/ninja/bytecode/iris/command/CommandObjectWand.java @@ -0,0 +1,32 @@ +package ninja.bytecode.iris.command; + +import org.bukkit.Sound; + +import mortar.bukkit.command.MortarCommand; +import mortar.bukkit.command.MortarSender; +import ninja.bytecode.iris.controller.WandController; + +public class CommandObjectWand extends MortarCommand +{ + public CommandObjectWand() + { + super("wand", "w"); + setDescription("Obtain Iris Wand"); + } + + @Override + public boolean handle(MortarSender sender, String[] args) + { + if(!sender.isPlayer()) + { + sender.sendMessage("Players Only"); + return true; + } + + sender.player().getInventory().addItem(WandController.createWand()); + sender.player().playSound(sender.player().getLocation(), Sound.ITEM_ARMOR_EQUIP_DIAMOND, 1f, 1.55f); + + return true; + } + +} diff --git a/src/main/java/ninja/bytecode/iris/command/CommandReload.java b/src/main/java/ninja/bytecode/iris/command/CommandReload.java new file mode 100644 index 000000000..45d2a2afc --- /dev/null +++ b/src/main/java/ninja/bytecode/iris/command/CommandReload.java @@ -0,0 +1,36 @@ +package ninja.bytecode.iris.command; + +import mortar.bukkit.command.Command; +import mortar.bukkit.command.MortarCommand; +import mortar.bukkit.command.MortarSender; +import mortar.util.text.C; + +public class CommandReload extends MortarCommand +{ + @Command + private CommandReloadPack rThis; + + @Command + private CommandReloadChunks rChunks; + + @Command + private CommandReloadIris rIris; + + public CommandReload() + { + super("reload", "r"); + setDescription("Reload Chunks / Pack / Iris"); + } + + @Override + public boolean handle(MortarSender sender, String[] args) + { + for(MortarCommand i : getChildren()) + { + sender.sendMessage("/iris reload " + C.WHITE + i.getNode() + C.GRAY + (!i.getNodes().isEmpty() ? "," : "") + i.getNodes().toString(",") + " - " + C.DARK_GREEN + i.getDescription()); + } + + return true; + } + +} diff --git a/src/main/java/ninja/bytecode/iris/command/CommandReloadChunks.java b/src/main/java/ninja/bytecode/iris/command/CommandReloadChunks.java new file mode 100644 index 000000000..f9d0f4067 --- /dev/null +++ b/src/main/java/ninja/bytecode/iris/command/CommandReloadChunks.java @@ -0,0 +1,38 @@ +package ninja.bytecode.iris.command; + +import org.bukkit.Chunk; +import org.bukkit.entity.Player; + +import mortar.api.nms.NMP; +import mortar.bukkit.command.MortarCommand; +import mortar.bukkit.command.MortarSender; + +public class CommandReloadChunks extends MortarCommand +{ + public CommandReloadChunks() + { + super("chunks", "c"); + setDescription("Resends chunk packets."); + } + + @Override + public boolean handle(MortarSender sender, String[] args) + { + + if(!sender.isPlayer()) + { + sender.sendMessage("Again, You don't have a position. Stop it."); + } + + sender.sendMessage("Resending Chunks in your view distance."); + Player p = ((Player) sender); + + for(Chunk i : p.getWorld().getLoadedChunks()) + { + NMP.CHUNK.refresh(p, i); + } + + return true; + } + +} diff --git a/src/main/java/ninja/bytecode/iris/command/CommandReloadIris.java b/src/main/java/ninja/bytecode/iris/command/CommandReloadIris.java new file mode 100644 index 000000000..892c06388 --- /dev/null +++ b/src/main/java/ninja/bytecode/iris/command/CommandReloadIris.java @@ -0,0 +1,23 @@ +package ninja.bytecode.iris.command; + +import mortar.bukkit.command.MortarCommand; +import mortar.bukkit.command.MortarSender; +import ninja.bytecode.iris.Iris; + +public class CommandReloadIris extends MortarCommand +{ + public CommandReloadIris() + { + super("iris", "i"); + setDescription("Reloads Iris"); + } + + @Override + public boolean handle(MortarSender sender, String[] args) + { + Iris.instance.reload(); + + return true; + } + +} diff --git a/src/main/java/ninja/bytecode/iris/command/CommandReloadPack.java b/src/main/java/ninja/bytecode/iris/command/CommandReloadPack.java new file mode 100644 index 000000000..63bc8c350 --- /dev/null +++ b/src/main/java/ninja/bytecode/iris/command/CommandReloadPack.java @@ -0,0 +1,142 @@ +package ninja.bytecode.iris.command; + +import java.util.function.Consumer; + +import org.bukkit.Bukkit; +import org.bukkit.World; +import org.bukkit.entity.Player; + +import mortar.api.sched.J; +import mortar.bukkit.command.MortarCommand; +import mortar.bukkit.command.MortarSender; +import mortar.logic.queue.ChronoLatch; +import ninja.bytecode.iris.Iris; +import ninja.bytecode.iris.controller.PackController; +import ninja.bytecode.iris.generator.IrisGenerator; +import ninja.bytecode.iris.generator.WorldReactor; +import ninja.bytecode.iris.pack.CompiledDimension; +import ninja.bytecode.shuriken.collections.KList; +import ninja.bytecode.shuriken.collections.KMap; +import ninja.bytecode.shuriken.format.Form; +import ninja.bytecode.shuriken.logging.L; + +public class CommandReloadPack extends MortarCommand +{ + public CommandReloadPack() + { + super("pack", "p"); + setDescription("Reloads the pack + regen"); + } + + @Override + public boolean handle(MortarSender sender, String[] args) + { + sender.sendMessage("=== Hotloading Pack ==="); + PackController c = Iris.pack(); + KMap f = new KMap<>(); + + for(World i : Bukkit.getWorlds()) + { + if(i.getGenerator() instanceof IrisGenerator) + { + String n = ((IrisGenerator) i.getGenerator()).getDimension().getName(); + sender.sendMessage("Preparing " + n); + f.put(i.getName(), n); + } + } + + if(f.isEmpty()) + { + sender.sendMessage("No Worlds to inject!"); + return true; + } + + J.a(() -> + { + try + { + Consumer m = (msg) -> + { + J.s(() -> + { + String mm = msg; + + if(msg.contains("|")) + { + KList fx = new KList<>(); + fx.add(msg.split("\\Q|\\E")); + fx.remove(0); + fx.remove(0); + mm = fx.toString(""); + } + + sender.sendMessage(mm.replaceAll("\\Q \\E", "")); + }); + }; + + L.addLogConsumer(m); + c.compile(); + L.logConsumers.remove(m); + + J.s(() -> + { + if(sender.isPlayer()) + { + ChronoLatch cl = new ChronoLatch(3000); + Player p = sender.player(); + World ww = sender.player().getWorld(); + + sender.sendMessage("Regenerating View Distance"); + + WorldReactor r = new WorldReactor(ww); + r.generateRegionNormal(p, true, 200, (pct) -> + { + if(cl.flip()) + { + sender.sendMessage("Regenerating " + Form.pc(pct)); + } + }, () -> + { + sender.sendMessage("Done! Use F3 + A"); + }); + } + }, 5); + + for(String fi : f.k()) + { + J.s(() -> + { + World i = Bukkit.getWorld(fi); + CompiledDimension dim = c.getDimension(f.get(fi)); + + for(String k : c.getDimensions().k()) + { + if(c.getDimension(k).getName().equals(f.get(fi))) + { + dim = c.getDimension(k); + break; + } + } + + if(dim == null) + { + J.s(() -> sender.sendMessage("Cannot find dimnension: " + f.get(fi))); + return; + } + sender.sendMessage("Hotloaded " + i.getName()); + IrisGenerator g = ((IrisGenerator) i.getGenerator()); + g.inject(dim); + }); + } + } + + catch(Throwable e) + { + e.printStackTrace(); + } + }); + + return true; + } + +} diff --git a/src/main/java/ninja/bytecode/iris/command/CommandSelection.java b/src/main/java/ninja/bytecode/iris/command/CommandSelection.java new file mode 100644 index 000000000..041da0bd2 --- /dev/null +++ b/src/main/java/ninja/bytecode/iris/command/CommandSelection.java @@ -0,0 +1,42 @@ +package ninja.bytecode.iris.command; + +import mortar.bukkit.command.Command; +import mortar.bukkit.command.MortarCommand; +import mortar.bukkit.command.MortarSender; +import mortar.util.text.C; + +public class CommandSelection extends MortarCommand +{ + @Command + private CommandSelectionExpand expand; + + @Command + private CommandSelectionShift shift; + + @Command + private CommandSelectionShrink shr; + + @Command + private CommandSelectionXUp xip; + + @Command + private CommandSelectionXVert xvc; + + public CommandSelection() + { + super("selection", "sel", "s"); + setDescription("Wand Selection Subcommands"); + } + + @Override + public boolean handle(MortarSender sender, String[] args) + { + for(MortarCommand i : getChildren()) + { + sender.sendMessage("/iris sel " + C.WHITE + i.getNode() + C.GRAY + (!i.getNodes().isEmpty() ? "," : "") + i.getNodes().toString(",") + " - " + C.DARK_GREEN + i.getDescription()); + } + + return true; + } + +} diff --git a/src/main/java/ninja/bytecode/iris/command/CommandSelectionExpand.java b/src/main/java/ninja/bytecode/iris/command/CommandSelectionExpand.java new file mode 100644 index 000000000..d5345dc22 --- /dev/null +++ b/src/main/java/ninja/bytecode/iris/command/CommandSelectionExpand.java @@ -0,0 +1,60 @@ +package ninja.bytecode.iris.command; + +import org.bukkit.Location; +import org.bukkit.Sound; +import org.bukkit.entity.Player; + +import mortar.bukkit.command.MortarCommand; +import mortar.bukkit.command.MortarSender; +import ninja.bytecode.iris.controller.WandController; +import ninja.bytecode.iris.util.Cuboid; +import ninja.bytecode.iris.util.Direction; + +public class CommandSelectionExpand extends MortarCommand +{ + public CommandSelectionExpand() + { + super("expand", "+"); + setDescription("Expand in looking direction"); + } + + @Override + public boolean handle(MortarSender sender, String[] args) + { + if(!sender.isPlayer()) + { + sender.sendMessage("Players Only"); + return true; + } + + Player p = sender.player(); + + if(!WandController.isWand(p)) + { + sender.sendMessage("Ready your Wand."); + return true; + } + + if(args.length == 0) + { + sender.sendMessage("/iris selection expand "); + return true; + } + + int amt = Integer.valueOf(args[0]); + Location[] b = WandController.getCuboid(p.getInventory().getItemInMainHand()); + Location a1 = b[0].clone(); + Location a2 = b[1].clone(); + Cuboid cursor = new Cuboid(a1, a2); + Direction d = Direction.closest(p.getLocation().getDirection()).reverse(); + cursor = cursor.expand(d, amt); + b[0] = cursor.getLowerNE(); + b[1] = cursor.getUpperSW(); + p.getInventory().setItemInMainHand(WandController.createWand(b[0], b[1])); + p.updateInventory(); + p.playSound(p.getLocation(), Sound.ENTITY_ITEMFRAME_ROTATE_ITEM, 1f, 0.55f); + + return true; + } + +} diff --git a/src/main/java/ninja/bytecode/iris/command/CommandSelectionShift.java b/src/main/java/ninja/bytecode/iris/command/CommandSelectionShift.java new file mode 100644 index 000000000..d0e60ba4b --- /dev/null +++ b/src/main/java/ninja/bytecode/iris/command/CommandSelectionShift.java @@ -0,0 +1,61 @@ +package ninja.bytecode.iris.command; + +import org.bukkit.Location; +import org.bukkit.Sound; +import org.bukkit.entity.Player; + +import mortar.bukkit.command.MortarCommand; +import mortar.bukkit.command.MortarSender; +import ninja.bytecode.iris.controller.WandController; +import ninja.bytecode.iris.util.Cuboid; +import ninja.bytecode.iris.util.Direction; + +public class CommandSelectionShift extends MortarCommand +{ + public CommandSelectionShift() + { + super("shift", ">"); + setDescription("Shift looking direction"); + } + + @Override + public boolean handle(MortarSender sender, String[] args) + { + if(!sender.isPlayer()) + { + sender.sendMessage("Players Only"); + return true; + } + + Player p = sender.player(); + + if(!WandController.isWand(p)) + { + sender.sendMessage("Ready your Wand."); + return true; + } + + if(args.length == 0) + { + sender.sendMessage("/iris selection shift "); + return true; + } + + int amt = Integer.valueOf(args[0]); + Location[] b = WandController.getCuboid(p.getInventory().getItemInMainHand()); + Location a1 = b[0].clone(); + Location a2 = b[1].clone(); + Direction d = Direction.closest(p.getLocation().getDirection()).reverse(); + a1.add(d.toVector().multiply(amt)); + a2.add(d.toVector().multiply(amt)); + Cuboid cursor = new Cuboid(a1, a2); + b[0] = cursor.getLowerNE(); + b[1] = cursor.getUpperSW(); + p.getInventory().setItemInMainHand(WandController.createWand(b[0], b[1])); + p.updateInventory(); + p.playSound(p.getLocation(), Sound.ENTITY_ITEMFRAME_ROTATE_ITEM, 1f, 0.55f); + + return true; + } + +} diff --git a/src/main/java/ninja/bytecode/iris/command/CommandSelectionShrink.java b/src/main/java/ninja/bytecode/iris/command/CommandSelectionShrink.java new file mode 100644 index 000000000..762939d4c --- /dev/null +++ b/src/main/java/ninja/bytecode/iris/command/CommandSelectionShrink.java @@ -0,0 +1,57 @@ +package ninja.bytecode.iris.command; + +import org.bukkit.Location; +import org.bukkit.Sound; +import org.bukkit.entity.Player; + +import mortar.bukkit.command.MortarCommand; +import mortar.bukkit.command.MortarSender; +import ninja.bytecode.iris.controller.WandController; +import ninja.bytecode.iris.util.Cuboid; +import ninja.bytecode.iris.util.Cuboid.CuboidDirection; + +public class CommandSelectionShrink extends MortarCommand +{ + public CommandSelectionShrink() + { + super("shrinkwrap", "shrink"); + setDescription("Match blocks boundary"); + } + + @Override + public boolean handle(MortarSender sender, String[] args) + { + if(!sender.isPlayer()) + { + sender.sendMessage("Players Only"); + return true; + } + + Player p = sender.player(); + + if(!WandController.isWand(p)) + { + sender.sendMessage("Ready your Wand."); + return true; + } + + Location[] b = WandController.getCuboid(p.getInventory().getItemInMainHand()); + Location a1 = b[0].clone(); + Location a2 = b[1].clone(); + Cuboid cursor = new Cuboid(a1, a2); + cursor = cursor.contract(CuboidDirection.North); + cursor = cursor.contract(CuboidDirection.South); + cursor = cursor.contract(CuboidDirection.East); + cursor = cursor.contract(CuboidDirection.West); + cursor = cursor.contract(CuboidDirection.Up); + cursor = cursor.contract(CuboidDirection.Down); + b[0] = cursor.getLowerNE(); + b[1] = cursor.getUpperSW(); + p.getInventory().setItemInMainHand(WandController.createWand(b[0], b[1])); + p.updateInventory(); + p.playSound(p.getLocation(), Sound.ENTITY_ITEMFRAME_ROTATE_ITEM, 1f, 0.55f); + + return true; + } + +} diff --git a/src/main/java/ninja/bytecode/iris/command/CommandSelectionXUp.java b/src/main/java/ninja/bytecode/iris/command/CommandSelectionXUp.java new file mode 100644 index 000000000..62d500a69 --- /dev/null +++ b/src/main/java/ninja/bytecode/iris/command/CommandSelectionXUp.java @@ -0,0 +1,72 @@ +package ninja.bytecode.iris.command; + +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.Sound; +import org.bukkit.entity.Player; +import org.bukkit.util.Vector; + +import mortar.bukkit.command.MortarCommand; +import mortar.bukkit.command.MortarSender; +import ninja.bytecode.iris.controller.WandController; +import ninja.bytecode.iris.util.Cuboid; +import ninja.bytecode.iris.util.Cuboid.CuboidDirection; + +public class CommandSelectionXUp extends MortarCommand +{ + public CommandSelectionXUp() + { + super("expandup", "xup"); + setDescription("Expand Up & Trim In"); + } + + @Override + public boolean handle(MortarSender sender, String[] args) + { + if(!sender.isPlayer()) + { + sender.sendMessage("Players Only"); + return true; + } + + Player p = sender.player(); + + if(!WandController.isWand(p)) + { + sender.sendMessage("Ready your Wand."); + return true; + } + + Location[] b = WandController.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(); + Location a2 = b[1].clone(); + Cuboid cursor = new Cuboid(a1, a2); + + while(!cursor.containsOnly(Material.AIR)) + { + a1.add(new Vector(0, 1, 0)); + a2.add(new Vector(0, 1, 0)); + cursor = new Cuboid(a1, a2); + } + + a1.add(new Vector(0, -1, 0)); + a2.add(new Vector(0, -1, 0)); + b[0] = a1; + a2 = b[1]; + cursor = new Cuboid(a1, a2); + cursor = cursor.contract(CuboidDirection.North); + cursor = cursor.contract(CuboidDirection.South); + cursor = cursor.contract(CuboidDirection.East); + cursor = cursor.contract(CuboidDirection.West); + b[0] = cursor.getLowerNE(); + b[1] = cursor.getUpperSW(); + p.getInventory().setItemInMainHand(WandController.createWand(b[0], b[1])); + p.updateInventory(); + p.playSound(p.getLocation(), Sound.ENTITY_ITEMFRAME_ROTATE_ITEM, 1f, 0.55f); + + return true; + } + +} diff --git a/src/main/java/ninja/bytecode/iris/command/CommandSelectionXVert.java b/src/main/java/ninja/bytecode/iris/command/CommandSelectionXVert.java new file mode 100644 index 000000000..9d97047b9 --- /dev/null +++ b/src/main/java/ninja/bytecode/iris/command/CommandSelectionXVert.java @@ -0,0 +1,83 @@ +package ninja.bytecode.iris.command; + +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.Sound; +import org.bukkit.entity.Player; +import org.bukkit.util.Vector; + +import mortar.bukkit.command.MortarCommand; +import mortar.bukkit.command.MortarSender; +import ninja.bytecode.iris.controller.WandController; +import ninja.bytecode.iris.util.Cuboid; +import ninja.bytecode.iris.util.Cuboid.CuboidDirection; + +public class CommandSelectionXVert extends MortarCommand +{ + public CommandSelectionXVert() + { + super("expandvertical", "xvert"); + setDescription("Expand Up + Down & Trim In"); + } + + @Override + public boolean handle(MortarSender sender, String[] args) + { + if(!sender.isPlayer()) + { + sender.sendMessage("Players Only"); + return true; + } + + Player p = sender.player(); + + if(!WandController.isWand(p)) + { + sender.sendMessage("Ready your Wand."); + return true; + } + + Location[] b = WandController.getCuboid(p.getInventory().getItemInMainHand()); + Location a1 = b[0].clone(); + Location a2 = b[1].clone(); + Location a1x = b[0].clone(); + Location a2x = b[1].clone(); + Cuboid cursor = new Cuboid(a1, a2); + Cuboid cursorx = new Cuboid(a1, a2); + + while(!cursor.containsOnly(Material.AIR)) + { + a1.add(new Vector(0, 1, 0)); + a2.add(new Vector(0, 1, 0)); + cursor = new Cuboid(a1, a2); + } + + a1.add(new Vector(0, -1, 0)); + a2.add(new Vector(0, -1, 0)); + + while(!cursorx.containsOnly(Material.AIR)) + { + a1x.add(new Vector(0, -1, 0)); + a2x.add(new Vector(0, -1, 0)); + cursorx = new Cuboid(a1x, a2x); + } + + a1x.add(new Vector(0, 1, 0)); + a2x.add(new Vector(0, 1, 0)); + b[0] = a1; + b[1] = a2x; + cursor = new Cuboid(b[0], b[1]); + cursor = cursor.contract(CuboidDirection.North); + cursor = cursor.contract(CuboidDirection.South); + cursor = cursor.contract(CuboidDirection.East); + cursor = cursor.contract(CuboidDirection.West); + b[0] = cursor.getLowerNE(); + b[1] = cursor.getUpperSW(); + p.getInventory().setItemInMainHand(WandController.createWand(b[0], b[1])); + p.updateInventory(); + p.playSound(p.getLocation(), Sound.ENTITY_ITEMFRAME_ROTATE_ITEM, 1f, 0.55f); + + return true; + } + +} diff --git a/src/main/java/ninja/bytecode/iris/command/CommandTimings.java b/src/main/java/ninja/bytecode/iris/command/CommandTimings.java new file mode 100644 index 000000000..e5cae1523 --- /dev/null +++ b/src/main/java/ninja/bytecode/iris/command/CommandTimings.java @@ -0,0 +1,56 @@ +package ninja.bytecode.iris.command; + +import org.bukkit.Bukkit; +import org.bukkit.World; + +import mortar.bukkit.command.MortarCommand; +import mortar.bukkit.command.MortarSender; +import mortar.util.text.C; +import ninja.bytecode.iris.generator.IrisGenerator; + +public class CommandTimings extends MortarCommand +{ + public CommandTimings() + { + super("timings", "t"); + setDescription("Tick use on a per chunk basis"); + } + + @Override + public boolean handle(MortarSender sender, String[] args) + { + World world = null; + + if(sender.isPlayer() && sender.player().getWorld().getGenerator() instanceof IrisGenerator) + { + world = sender.player().getWorld(); + } + + else if(args.length >= 1) + { + World t = Bukkit.getWorld(args[0]); + + if(t == null) + { + sender.sendMessage("Unknown world " + args[0]); + return true; + } + + else if(t.getGenerator() instanceof IrisGenerator) + { + world = t; + } + } + + else + { + sender.sendMessage("Console / Non-Iris World. " + C.WHITE + "Use /iris timings "); + return true; + } + + ((IrisGenerator) world.getGenerator()).getMetrics().send(sender, (m) -> sender.sendMessage(m)); + + return true; + } + +} diff --git a/src/main/java/ninja/bytecode/iris/command/CommandWhat.java b/src/main/java/ninja/bytecode/iris/command/CommandWhat.java new file mode 100644 index 000000000..a6ff4f350 --- /dev/null +++ b/src/main/java/ninja/bytecode/iris/command/CommandWhat.java @@ -0,0 +1,36 @@ +package ninja.bytecode.iris.command; + +import mortar.bukkit.command.Command; +import mortar.bukkit.command.MortarCommand; +import mortar.bukkit.command.MortarSender; +import mortar.util.text.C; + +public class CommandWhat extends MortarCommand +{ + @Command + private CommandWhatBiome wBiome; + + @Command + private CommandWhatObject wObject; + + @Command + private CommandWhatBlock wBlock; + + public CommandWhat() + { + super("what", "w"); + setDescription("Identify what you are looking at."); + } + + @Override + public boolean handle(MortarSender sender, String[] args) + { + for(MortarCommand i : getChildren()) + { + sender.sendMessage("/iris what " + C.WHITE + i.getNode() + C.GRAY + (!i.getNodes().isEmpty() ? "," : "") + i.getNodes().toString(",") + " - " + C.DARK_GREEN + i.getDescription()); + } + + return true; + } + +} diff --git a/src/main/java/ninja/bytecode/iris/command/CommandWhatBiome.java b/src/main/java/ninja/bytecode/iris/command/CommandWhatBiome.java new file mode 100644 index 000000000..40270438d --- /dev/null +++ b/src/main/java/ninja/bytecode/iris/command/CommandWhatBiome.java @@ -0,0 +1,65 @@ +package ninja.bytecode.iris.command; + +import org.bukkit.World; +import org.bukkit.entity.Player; + +import mortar.bukkit.command.MortarCommand; +import mortar.bukkit.command.MortarSender; +import mortar.util.text.C; +import ninja.bytecode.iris.generator.IrisGenerator; +import ninja.bytecode.iris.pack.IrisBiome; +import ninja.bytecode.iris.util.BiomeLayer; +import ninja.bytecode.shuriken.format.Form; + +public class CommandWhatBiome extends MortarCommand +{ + public CommandWhatBiome() + { + super("biome", "b"); + setDescription("Identify Current Biome"); + } + + @Override + public boolean handle(MortarSender sender, String[] args) + { + World world = null; + + if(sender.isPlayer() && sender.player().getWorld().getGenerator() instanceof IrisGenerator) + { + world = sender.player().getWorld(); + } + + else + { + sender.sendMessage("Console / Non-Iris World."); + return true; + } + + Player p = sender.player(); + IrisGenerator g = (IrisGenerator) world.getGenerator(); + IrisBiome biome = g.getBiome((int) g.getOffsetX(p.getLocation().getX(), p.getLocation().getZ()), (int) g.getOffsetZ(p.getLocation().getX(), p.getLocation().getZ())); + BiomeLayer l = new BiomeLayer(g, biome); + sender.sendMessage("Biome: " + C.BOLD + C.WHITE + biome.getName() + C.RESET + C.GRAY + " (" + C.GOLD + l.getBiome().getRarityString() + C.GRAY + ")"); + + for(String i : biome.getSchematicGroups().k()) + { + String f = ""; + double percent = biome.getSchematicGroups().get(i); + + if(percent > 1D) + { + f = (int) percent + " + " + Form.pc(percent - (int) percent, percent - (int) percent >= 0.01 ? 0 : 3); + } + + else + { + f = Form.pc(percent, percent >= 0.01 ? 0 : 3); + } + + sender.sendMessage("* " + C.DARK_GREEN + i + ": " + C.BOLD + C.WHITE + f + C.RESET + C.GRAY + " (" + Form.f(g.getDimension().getObjectGroup(i).size()) + " variants)"); + } + + return true; + } + +} diff --git a/src/main/java/ninja/bytecode/iris/command/CommandWhatBlock.java b/src/main/java/ninja/bytecode/iris/command/CommandWhatBlock.java new file mode 100644 index 000000000..28bba5856 --- /dev/null +++ b/src/main/java/ninja/bytecode/iris/command/CommandWhatBlock.java @@ -0,0 +1,33 @@ +package ninja.bytecode.iris.command; + +import org.bukkit.block.Block; +import org.bukkit.entity.Player; + +import mortar.bukkit.command.MortarCommand; +import mortar.bukkit.command.MortarSender; + +public class CommandWhatBlock extends MortarCommand +{ + public CommandWhatBlock() + { + super("block", "id", "i"); + setDescription("Identify Current Block Looking at"); + } + + @SuppressWarnings("deprecation") + @Override + public boolean handle(MortarSender sender, String[] args) + { + if(!sender.isPlayer()) + { + sender.sendMessage("Not sure where you are looking."); + } + + Player p = sender.player(); + Block b = p.getTargetBlock(null, 64); + sender.sendMessage(b.getType().getId() + ":" + b.getData() + " (" + b.getType().toString() + ":" + b.getData() + ")"); + + return true; + } + +} diff --git a/src/main/java/ninja/bytecode/iris/command/CommandWhatObject.java b/src/main/java/ninja/bytecode/iris/command/CommandWhatObject.java new file mode 100644 index 000000000..fa833941b --- /dev/null +++ b/src/main/java/ninja/bytecode/iris/command/CommandWhatObject.java @@ -0,0 +1,165 @@ +package ninja.bytecode.iris.command; + +import org.bukkit.Location; +import org.bukkit.World; +import org.bukkit.entity.Player; + +import mortar.api.sched.SR; +import mortar.bukkit.command.MortarCommand; +import mortar.bukkit.command.MortarSender; +import mortar.lang.collection.FinalInteger; +import mortar.util.text.C; +import ninja.bytecode.iris.Iris; +import ninja.bytecode.iris.generator.IrisGenerator; +import ninja.bytecode.iris.generator.genobject.GenObject; +import ninja.bytecode.iris.generator.genobject.GenObjectGroup; +import ninja.bytecode.iris.generator.genobject.PlacedObject; +import ninja.bytecode.iris.pack.IrisBiome; +import ninja.bytecode.shuriken.collections.KMap; +import ninja.bytecode.shuriken.format.Form; + +public class CommandWhatObject extends MortarCommand +{ + private KMap goc; + private KMap gog; + + public CommandWhatObject() + { + super("object", "o"); + setDescription("WAYLA For Objects"); + goc = new KMap<>(); + gog = new KMap<>(); + } + + @Override + public boolean handle(MortarSender sender, String[] args) + { + World world = null; + + if(sender.isPlayer() && sender.player().getWorld().getGenerator() instanceof IrisGenerator) + { + world = sender.player().getWorld(); + } + + else + { + sender.sendMessage("Console / Non-Iris World."); + return true; + } + + Player p = sender.player(); + IrisGenerator generator = (IrisGenerator) world.getGenerator(); + Location l = p.getTargetBlock(null, 32).getLocation(); + PlacedObject po = generator.nearest(l, 12); + + if(po != null) + { + if(!goc.containsKey(po.getF())) + { + String root = po.getF().split("\\Q:\\E")[0]; + String n = po.getF().split("\\Q:\\E")[1]; + GenObjectGroup gg = generator.getDimension().getObjectGroup(root); + gog.put(root, gg); + + for(GenObject i : gg.getSchematics()) + { + if(i.getName().equals(n)) + { + goc.put(po.getF(), i); + break; + } + } + + if(!goc.containsKey(po.getF())) + { + goc.put(po.getF(), new GenObject(0, 0, 0)); + } + } + + GenObjectGroup ggg = gog.get(po.getF().split("\\Q:\\E")[0]); + GenObject g = goc.get(po.getF()); + + if(g != null) + { + Location point = new Location(l.getWorld(), po.getX(), po.getY(), po.getZ()); + IrisBiome biome = generator.getBiome((int) generator.getOffsetX(po.getX(), po.getZ()), (int) generator.getOffsetZ(po.getX(), po.getZ())); + String gg = po.getF().split("\\Q:\\E")[0]; + + p.sendMessage(C.DARK_GREEN + C.BOLD.toString() + gg + C.GRAY + "/" + C.RESET + C.ITALIC + C.GRAY + g.getName() + C.RESET + C.WHITE + " (1 of " + Form.f(generator.getDimension().getObjectGroup(gg).size()) + " variants)"); + + if(biome.getSchematicGroups().containsKey(gg)) + { + String f = ""; + double percent = biome.getSchematicGroups().get(gg); + + if(percent > 1D) + { + f = (int) percent + " + " + Form.pc(percent - (int) percent, percent - (int) percent >= 0.01 ? 0 : 3); + } + + else + { + f = Form.pc(percent, percent >= 0.01 ? 0 : 3); + } + + p.sendMessage(C.GOLD + "Spawn Chance in " + C.YELLOW + biome.getName() + C.RESET + ": " + C.BOLD + C.WHITE + f); + } + + try + { + int a = 0; + int b = 0; + double c = 0; + + for(GenObject i : ggg.getSchematics()) + { + a += i.getSuccesses(); + b += i.getPlaces(); + } + + c = ((double) a / (double) b); + p.sendMessage(C.GRAY + "Grp: " + C.DARK_AQUA + Form.f(a) + C.GRAY + " of " + C.AQUA + Form.f(b) + C.GRAY + " placements (" + C.DARK_AQUA + Form.pc(c, 0) + C.GRAY + ")"); + } + + catch(Throwable e) + { + e.printStackTrace(); + } + + p.sendMessage(C.GRAY + "Var: " + C.DARK_AQUA + Form.f(g.getSuccesses()) + C.GRAY + " of " + C.AQUA + Form.f(g.getPlaces()) + C.GRAY + " placements (" + C.DARK_AQUA + Form.pc(g.getSuccess(), 0) + C.GRAY + ")"); + + for(String i : ggg.getFlags()) + { + p.sendMessage(C.GRAY + "- " + C.DARK_PURPLE + i); + } + + FinalInteger fi = new FinalInteger(125); + + new SR() + { + @Override + public void run() + { + if(point.distanceSquared(p.getLocation()) > 64 * 64) + { + cancel(); + } + + fi.sub(1); + Iris.wand().draw(new Location[] {point.clone().add(g.getW() / 2, g.getH() / 2, g.getD() / 2), point.clone().subtract(g.getW() / 2, g.getH() / 2, g.getD() / 2) + }, p); + + if(fi.get() <= 0) + { + cancel(); + } + } + }; + + } + } + + return true; + } + +} diff --git a/src/main/java/ninja/bytecode/iris/controller/DebugController.java b/src/main/java/ninja/bytecode/iris/controller/DebugController.java deleted file mode 100644 index 340df256b..000000000 --- a/src/main/java/ninja/bytecode/iris/controller/DebugController.java +++ /dev/null @@ -1,103 +0,0 @@ -package ninja.bytecode.iris.controller; - -import org.bukkit.Bukkit; -import org.bukkit.ChatColor; -import org.bukkit.GameMode; -import org.bukkit.Location; -import org.bukkit.World; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; - -import mortar.util.text.C; -import ninja.bytecode.iris.Iris; -import ninja.bytecode.iris.generator.IrisGenerator; -import ninja.bytecode.iris.util.IrisController; -import ninja.bytecode.shuriken.collections.KList; -import ninja.bytecode.shuriken.collections.KSet; -import ninja.bytecode.shuriken.execution.J; - -public class DebugController implements IrisController -{ - @Override - public void onStart() - { - Bukkit.getScheduler().scheduleSyncDelayedTask(Iris.instance, () -> - { - if(Iris.settings.performance.debugMode) - { - J.a(() -> - { - J.a(() -> - { - J.sleep(1000); - while(!Iris.getController(PackController.class).isReady()) - { - J.sleep(250); - } - - Bukkit.getScheduler().scheduleSyncDelayedTask(Iris.instance, () -> - { - if(Iris.settings.performance.debugMode) - { - KSet ws = new KSet<>(); - KList destroy = new KList<>(); - - for(World i : Bukkit.getWorlds()) - { - if(i.getGenerator() instanceof IrisGenerator) - { - destroy.add(i); - } - } - - World w = Iris.getController(WorldController.class).createIrisWorld(null, 0, true); - for(Player i : Bukkit.getOnlinePlayers()) - { - Location m = i.getLocation(); - ws.add(i.getWorld().getName()); - i.teleport(new Location(w, m.getX(), m.getY(), m.getZ(), m.getYaw(), m.getPitch())); - i.setFlying(true); - i.setGameMode(GameMode.SPECTATOR); - - if(Iris.settings.performance.fastMode) - { - msg(i, C.GOLD + "Fast Mode is ON!"); - msg(i, "* Terrain is not interpolated"); - msg(i, "* Schematics larger than 3 chunks may be clipped"); - msg(i, "* Underground Generation is disabled"); - msg(i, "* Surface Lighting is skipped"); - } - } - - for(String i : ws) - { - Bukkit.unloadWorld(i, false); - } - - Bukkit.getScheduler().scheduleSyncDelayedTask(Iris.instance, () -> - { - for(World i : destroy.copy()) - { - Bukkit.unloadWorld(i, false); - } - }, 20); - } - }, 1); - }); - Iris.getController(PackController.class).compile(); - }); - } - }, 1); - } - - public void msg(CommandSender s, String msg) - { - s.sendMessage(ChatColor.DARK_PURPLE + "[" + ChatColor.GRAY + "Iris" + ChatColor.DARK_PURPLE + "]" + ChatColor.GRAY + ": " + msg); - } - - @Override - public void onStop() - { - - } -} diff --git a/src/main/java/ninja/bytecode/iris/controller/ExecutionController.java b/src/main/java/ninja/bytecode/iris/controller/ExecutionController.java index 7990a015d..caea96f64 100644 --- a/src/main/java/ninja/bytecode/iris/controller/ExecutionController.java +++ b/src/main/java/ninja/bytecode/iris/controller/ExecutionController.java @@ -2,34 +2,49 @@ package ninja.bytecode.iris.controller; import org.bukkit.World; +import mortar.bukkit.plugin.Controller; import ninja.bytecode.iris.Iris; -import ninja.bytecode.iris.util.IrisController; import ninja.bytecode.shuriken.collections.KMap; import ninja.bytecode.shuriken.execution.TaskExecutor; -public class ExecutionController implements IrisController +public class ExecutionController extends Controller { KMap executors; @Override - public void onStart() + public void start() { executors = new KMap<>(); } @Override - public void onStop() + public void stop() { for(TaskExecutor i : executors.v()) { i.close(); } + + executors.clear(); + } + + @Override + public void tick() + { + } public TaskExecutor getExecutor(World world, String f) { + String k = world.getWorldFolder().getAbsolutePath() + " (" + world + ") " + f; + + if(executors.containsKey(k)) + { + return executors.get(k); + } + TaskExecutor x = new TaskExecutor(getTC(), Iris.settings.performance.threadPriority, "Iris " + f); - executors.put(world.getWorldFolder().getAbsolutePath() + " (" + world + ") " + f, x); + executors.put(k, x); return x; } diff --git a/src/main/java/ninja/bytecode/iris/controller/PackController.java b/src/main/java/ninja/bytecode/iris/controller/PackController.java index 6cc7f4c05..aae73db22 100644 --- a/src/main/java/ninja/bytecode/iris/controller/PackController.java +++ b/src/main/java/ninja/bytecode/iris/controller/PackController.java @@ -5,6 +5,7 @@ import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; +import mortar.bukkit.plugin.Controller; import net.md_5.bungee.api.ChatColor; import ninja.bytecode.iris.Iris; import ninja.bytecode.iris.generator.genobject.GenObject; @@ -13,7 +14,6 @@ import ninja.bytecode.iris.pack.CompiledDimension; import ninja.bytecode.iris.pack.IrisBiome; import ninja.bytecode.iris.pack.IrisDimension; import ninja.bytecode.iris.pack.IrisPack; -import ninja.bytecode.iris.util.IrisController; import ninja.bytecode.shuriken.bench.PrecisionStopwatch; import ninja.bytecode.shuriken.collections.KList; import ninja.bytecode.shuriken.collections.KMap; @@ -24,7 +24,7 @@ import ninja.bytecode.shuriken.json.JSONException; import ninja.bytecode.shuriken.json.JSONObject; import ninja.bytecode.shuriken.logging.L; -public class PackController implements IrisController +public class PackController extends Controller { private KMap compiledDimensions; private KMap dimensions; @@ -33,7 +33,7 @@ public class PackController implements IrisController private boolean ready; @Override - public void onStart() + public void start() { compiledDimensions = new KMap<>(); dimensions = new KMap<>(); @@ -43,7 +43,13 @@ public class PackController implements IrisController } @Override - public void onStop() + public void stop() + { + + } + + @Override + public void tick() { } @@ -210,7 +216,7 @@ public class PackController implements IrisController if(g != null) { - Iris.getController(PackController.class).genObjectGroups.put(s, g); + genObjectGroups.put(s, g); return g; } @@ -298,7 +304,7 @@ public class PackController implements IrisController { try { - biomes.put(id, Iris.getController(PackController.class).loadBiome(id)); + biomes.put(id, ((PackController) Iris.instance.getController(PackController.class)).loadBiome(id)); } catch(JSONException | IOException e) diff --git a/src/main/java/ninja/bytecode/iris/controller/TimingsController.java b/src/main/java/ninja/bytecode/iris/controller/TimingsController.java deleted file mode 100644 index 9e2cdf356..000000000 --- a/src/main/java/ninja/bytecode/iris/controller/TimingsController.java +++ /dev/null @@ -1,36 +0,0 @@ -package ninja.bytecode.iris.controller; - -import ninja.bytecode.iris.util.IrisController; -import ninja.bytecode.shuriken.bench.Profiler; - -public class TimingsController implements IrisController -{ - public Profiler profiler; - - @Override - public void onStart() - { - profiler = new Profiler(768); - } - - @Override - public void onStop() - { - - } - - public void started(String obj) - { - profiler.start(obj); - } - - public void stopped(String obj) - { - profiler.stop(obj); - } - - public double getResult(String tag) - { - return profiler.getResult(tag).getAverage(); - } -} diff --git a/src/main/java/ninja/bytecode/iris/controller/WandController.java b/src/main/java/ninja/bytecode/iris/controller/WandController.java index 676123bf5..7bad52843 100644 --- a/src/main/java/ninja/bytecode/iris/controller/WandController.java +++ b/src/main/java/ninja/bytecode/iris/controller/WandController.java @@ -21,33 +21,21 @@ import org.bukkit.inventory.meta.ItemMeta; import org.bukkit.util.BlockVector; import org.bukkit.util.Vector; +import mortar.bukkit.plugin.Controller; import mortar.compute.math.M; -import mortar.util.text.C; import ninja.bytecode.iris.Iris; -import ninja.bytecode.iris.generator.IrisGenerator; import ninja.bytecode.iris.generator.genobject.GenObject; -import ninja.bytecode.iris.generator.genobject.GenObjectGroup; -import ninja.bytecode.iris.generator.genobject.PlacedObject; -import ninja.bytecode.iris.pack.IrisBiome; import ninja.bytecode.iris.util.Cuboid; -import ninja.bytecode.iris.util.IrisController; import ninja.bytecode.iris.util.MB; import ninja.bytecode.iris.util.ParticleEffect; import ninja.bytecode.iris.util.ParticleRedstone; import ninja.bytecode.shuriken.collections.KList; -import ninja.bytecode.shuriken.collections.KMap; -import ninja.bytecode.shuriken.format.Form; -public class WandController implements IrisController +public class WandController extends Controller { - private KMap goc; - private KMap gog; - @Override - public void onStart() + public void start() { - goc = new KMap<>(); - gog = new KMap<>(); // TODO: Optimize Bukkit.getScheduler().scheduleSyncRepeatingTask(Iris.instance, () -> { @@ -55,11 +43,17 @@ public class WandController implements IrisController { tick(i); } - }, 0, 5); + }, 0, 0); } @Override - public void onStop() + public void stop() + { + + } + + @Override + public void tick() { } @@ -71,11 +65,6 @@ public class WandController implements IrisController { if(isWand(p.getInventory().getItemInMainHand())) { - if(Iris.settings.performance.debugMode && p.getWorld().getGenerator() instanceof IrisGenerator) - { - tickHighlight(p, (IrisGenerator) p.getWorld().getGenerator()); - } - Location[] d = getCuboid(p.getInventory().getItemInMainHand()); draw(d, p); } @@ -87,7 +76,7 @@ public class WandController implements IrisController } } - private void draw(Location[] d, Player p) + public void draw(Location[] d, Player p) { ParticleEffect.CRIT_MAGIC.display(0.1f, 1, d[0].clone().add(0.5, 0.5, 0.5).clone().add(Vector.getRandom().subtract(Vector.getRandom()).normalize().clone().multiply(0.65)), p); ParticleEffect.CRIT.display(0.1f, 1, d[1].clone().add(0.5, 0.5, 0.5).clone().add(Vector.getRandom().subtract(Vector.getRandom()).normalize().clone().multiply(0.65)), p); @@ -168,103 +157,6 @@ public class WandController implements IrisController } } - private void tickHighlight(Player p, IrisGenerator generator) - { - Location l = p.getTargetBlock(null, 32).getLocation(); - PlacedObject po = generator.nearest(l, 12); - - if(po != null) - { - if(!goc.containsKey(po.getF())) - { - String root = po.getF().split("\\Q:\\E")[0]; - String n = po.getF().split("\\Q:\\E")[1]; - GenObjectGroup gg = generator.getDimension().getObjectGroup(root); - gog.put(root, gg); - - for(GenObject i : gg.getSchematics()) - { - if(i.getName().equals(n)) - { - goc.put(po.getF(), i); - break; - } - } - - if(!goc.containsKey(po.getF())) - { - goc.put(po.getF(), new GenObject(0, 0, 0)); - } - } - - GenObjectGroup ggg = gog.get(po.getF().split("\\Q:\\E")[0]); - GenObject g = goc.get(po.getF()); - - if(g != null) - { - Location point = new Location(l.getWorld(), po.getX(), po.getY(), po.getZ()); - IrisBiome biome = generator.getBiome((int) generator.getOffsetX(po.getX(), po.getZ()), (int) generator.getOffsetZ(po.getX(), po.getZ())); - String gg = po.getF().split("\\Q:\\E")[0]; - - for(int j = 0; j < 10; j++) - { - p.sendMessage(" "); - } - - p.sendMessage(C.DARK_GREEN + C.BOLD.toString() + gg + C.GRAY + "/" + C.RESET + C.ITALIC + C.GRAY + g.getName() + C.RESET + C.WHITE + " (1 of " + Form.f(generator.getDimension().getObjectGroup(gg).size()) + " variants)"); - - if(biome.getSchematicGroups().containsKey(gg)) - { - String f = ""; - double percent = biome.getSchematicGroups().get(gg); - - if(percent > 1D) - { - f = (int) percent + " + " + Form.pc(percent - (int) percent, percent - (int) percent >= 0.01 ? 0 : 3); - } - - else - { - f = Form.pc(percent, percent >= 0.01 ? 0 : 3); - } - - p.sendMessage(C.GOLD + "Spawn Chance in " + C.YELLOW + biome.getName() + C.RESET + ": " + C.BOLD + C.WHITE + f); - } - - try - { - int a = 0; - int b = 0; - double c = 0; - - for(GenObject i : ggg.getSchematics()) - { - a += i.getSuccesses(); - b += i.getPlaces(); - } - - c = ((double) a / (double) b); - p.sendMessage(C.GRAY + "Grp: " + C.DARK_AQUA + Form.f(a) + C.GRAY + " of " + C.AQUA + Form.f(b) + C.GRAY + " placements (" + C.DARK_AQUA + Form.pc(c, 0) + C.GRAY + ")"); - } - - catch(Throwable e) - { - e.printStackTrace(); - } - - p.sendMessage(C.GRAY + "Var: " + C.DARK_AQUA + Form.f(g.getSuccesses()) + C.GRAY + " of " + C.AQUA + Form.f(g.getPlaces()) + C.GRAY + " placements (" + C.DARK_AQUA + Form.pc(g.getSuccess(), 0) + C.GRAY + ")"); - - for(String i : ggg.getFlags()) - { - p.sendMessage(C.GRAY + "- " + C.DARK_PURPLE + i); - } - - draw(new Location[] {point.clone().add(g.getW() / 2, g.getH() / 2, g.getD() / 2), point.clone().subtract(g.getW() / 2, g.getH() / 2, g.getD() / 2) - }, p); - } - } - } - @EventHandler public void on(PlayerInteractEvent e) { @@ -383,12 +275,6 @@ public class WandController implements IrisController return createWand(left ? a : other, left ? other : a); } - public void dispose() - { - goc.clear(); - gog.clear(); - } - public static ItemStack createWand(Location a, Location b) { ItemStack is = new ItemStack(Material.BLAZE_ROD); @@ -403,6 +289,12 @@ public class WandController implements IrisController return is; } + public static boolean isWand(Player p) + { + ItemStack is = p.getInventory().getItemInMainHand(); + return !(is == null || !isWand(is)); + } + public static Location[] getCuboid(ItemStack is) { ItemMeta im = is.getItemMeta(); diff --git a/src/main/java/ninja/bytecode/iris/controller/WorldController.java b/src/main/java/ninja/bytecode/iris/controller/WorldController.java deleted file mode 100644 index bdfcdf7a8..000000000 --- a/src/main/java/ninja/bytecode/iris/controller/WorldController.java +++ /dev/null @@ -1,83 +0,0 @@ -package ninja.bytecode.iris.controller; - -import java.io.File; -import java.io.IOException; -import java.util.UUID; - -import org.apache.commons.io.FileUtils; -import org.bukkit.Bukkit; -import org.bukkit.World; -import org.bukkit.WorldCreator; - -import ninja.bytecode.iris.Iris; -import ninja.bytecode.iris.generator.IrisGenerator; -import ninja.bytecode.iris.pack.CompiledDimension; -import ninja.bytecode.iris.util.IrisController; -import ninja.bytecode.shuriken.execution.J; -import ninja.bytecode.shuriken.io.IO; - -public class WorldController implements IrisController -{ - @Override - public void onStart() - { - - } - - public boolean isChunkGenerated(World w, int x, int z) - { - return w.loadChunk(x, z, false); - } - - @Override - public void onStop() - { - - } - - public World createIrisWorld(CompiledDimension dimension, long seed, boolean temp) - { - if(dimension == null) - { - dimension = Iris.getController(PackController.class).getDimension("overworld"); - } - - //@builder - World ww = Bukkit.createWorld(new WorldCreator("iris-worlds/" + UUID.randomUUID().toString()) - .generator(new IrisGenerator(dimension)) - .environment(dimension.getEnvironment()) - .seed(seed)); - //@done - ww.setSpawnFlags(false, false); - ww.setAutoSave(false); - ww.setKeepSpawnInMemory(false); - ww.setSpawnLocation(0, 256, 0); - - if(temp) - { - File folder = ww.getWorldFolder(); - J.attempt(() -> new File(ww.getWorldFolder(), ".garbage").createNewFile()); - Runtime.getRuntime().addShutdownHook(new Thread() - { - @Override - public void run() - { - IO.delete(folder); - - try - { - FileUtils.forceDelete(folder); - System.out.println("Deleted Debug World: " + folder.getName()); - } - - catch(IOException e) - { - System.out.println("FAILED TO Delete Debug World: " + folder.getName()); - } - } - }); - } - - return ww; - } -} diff --git a/src/main/java/ninja/bytecode/iris/generator/IrisGenerator.java b/src/main/java/ninja/bytecode/iris/generator/IrisGenerator.java index 38c922e46..e0d55b978 100644 --- a/src/main/java/ninja/bytecode/iris/generator/IrisGenerator.java +++ b/src/main/java/ninja/bytecode/iris/generator/IrisGenerator.java @@ -13,7 +13,6 @@ import org.bukkit.util.NumberConversions; import mortar.util.text.C; import ninja.bytecode.iris.Iris; import ninja.bytecode.iris.IrisMetrics; -import ninja.bytecode.iris.controller.PackController; import ninja.bytecode.iris.generator.atomics.AtomicChunkData; import ninja.bytecode.iris.generator.genobject.GenObjectDecorator; import ninja.bytecode.iris.generator.genobject.PlacedObject; @@ -63,8 +62,6 @@ public class IrisGenerator extends ParallaxWorldGenerator private CNG scatter; private CNG beach; private CNG swirl; - private MB ICE = new MB(Material.ICE); - private MB PACKED_ICE = new MB(Material.PACKED_ICE); private MB BEDROCK = new MB(Material.BEDROCK); private GenObjectDecorator god; private GenLayerLayeredNoise glLNoise; @@ -78,7 +75,7 @@ public class IrisGenerator extends ParallaxWorldGenerator public IrisGenerator() { - this(Iris.getController(PackController.class).getDimension("overworld")); + this(Iris.pack().getDimension("overworld")); } public void hitObject() diff --git a/src/main/java/ninja/bytecode/iris/generator/genobject/GenObjectGroup.java b/src/main/java/ninja/bytecode/iris/generator/genobject/GenObjectGroup.java index 9f25d7113..7ac1d960c 100644 --- a/src/main/java/ninja/bytecode/iris/generator/genobject/GenObjectGroup.java +++ b/src/main/java/ninja/bytecode/iris/generator/genobject/GenObjectGroup.java @@ -8,7 +8,6 @@ import java.util.function.Consumer; import net.md_5.bungee.api.ChatColor; import ninja.bytecode.iris.Iris; -import ninja.bytecode.iris.controller.PackController; import ninja.bytecode.iris.util.Direction; import ninja.bytecode.shuriken.collections.KList; import ninja.bytecode.shuriken.format.Form; @@ -171,7 +170,7 @@ public class GenObjectGroup public static GenObjectGroup load(String string) { - File folder = Iris.getController(PackController.class).loadFolder(string); + File folder = Iris.pack().loadFolder(string); if(folder != null) { diff --git a/src/main/java/ninja/bytecode/iris/generator/parallax/ParallelChunkGenerator.java b/src/main/java/ninja/bytecode/iris/generator/parallax/ParallelChunkGenerator.java index 442dc6266..e112effe8 100644 --- a/src/main/java/ninja/bytecode/iris/generator/parallax/ParallelChunkGenerator.java +++ b/src/main/java/ninja/bytecode/iris/generator/parallax/ParallelChunkGenerator.java @@ -9,12 +9,9 @@ import org.bukkit.block.Biome; import org.bukkit.generator.ChunkGenerator; import ninja.bytecode.iris.Iris; -import ninja.bytecode.iris.controller.ExecutionController; -import ninja.bytecode.iris.controller.TimingsController; import ninja.bytecode.iris.generator.atomics.AtomicChunkData; import ninja.bytecode.iris.util.ChunkPlan; import ninja.bytecode.iris.util.ChunkSpliceListener; -import ninja.bytecode.shuriken.execution.TaskExecutor; import ninja.bytecode.shuriken.execution.TaskExecutor.TaskGroup; import ninja.bytecode.shuriken.execution.TaskExecutor.TaskResult; import ninja.bytecode.shuriken.math.RollingSequence; @@ -32,8 +29,6 @@ public abstract class ParallelChunkGenerator extends ChunkGenerator int cg = 0; private RollingSequence rs = new RollingSequence(512); private World world; - private TaskExecutor genPool; - private TaskExecutor genPar; private ChunkSpliceListener splicer; public void setSplicer(ChunkSpliceListener splicer) @@ -53,22 +48,12 @@ public abstract class ParallelChunkGenerator extends ChunkGenerator public TaskGroup startParallaxWork() { - if(genPar == null) - { - genPar = Iris.getController(ExecutionController.class).getExecutor(world, "Parallax"); - } - - return genPar.startWork(); + return Iris.exec().getExecutor(world, "Parallax").startWork(); } public TaskGroup startWork() { - if(genPool == null) - { - genPool = Iris.getController(ExecutionController.class).getExecutor(world, "Generator"); - } - - return genPool.startWork(); + return Iris.exec().getExecutor(world, "Generator").startWork(); } public ChunkData generateChunkData(World world, Random random, int x, int z, BiomeGrid biome) @@ -88,8 +73,6 @@ public abstract class ParallelChunkGenerator extends ChunkGenerator try { - Iris.getController(TimingsController.class).started("terrain"); - this.world = world; if(!ready) @@ -127,7 +110,6 @@ public abstract class ParallelChunkGenerator extends ChunkGenerator postChunk(world, x, z, random, data, plan.get()); rs.put(r.timeElapsed); cg++; - Iris.getController(TimingsController.class).stopped("terrain"); } catch(Throwable e) diff --git a/src/main/java/ninja/bytecode/iris/pack/IrisBiome.java b/src/main/java/ninja/bytecode/iris/pack/IrisBiome.java index c47dcfd3a..964217bb3 100644 --- a/src/main/java/ninja/bytecode/iris/pack/IrisBiome.java +++ b/src/main/java/ninja/bytecode/iris/pack/IrisBiome.java @@ -8,7 +8,6 @@ import org.bukkit.block.Biome; import mortar.util.text.C; import ninja.bytecode.iris.Iris; -import ninja.bytecode.iris.controller.PackController; import ninja.bytecode.iris.generator.layer.BiomeNoiseGenerator; import ninja.bytecode.iris.util.MB; import ninja.bytecode.iris.util.ObjectMode; @@ -286,7 +285,7 @@ public class IrisBiome { for(String i : schematicGroups.k()) { - Iris.getController(PackController.class).loadSchematicGroup(i); + Iris.pack().loadSchematicGroup(i); } } } diff --git a/src/main/java/ninja/bytecode/iris/pack/IrisDimension.java b/src/main/java/ninja/bytecode/iris/pack/IrisDimension.java index 3a1dd0a27..f01cfe739 100644 --- a/src/main/java/ninja/bytecode/iris/pack/IrisDimension.java +++ b/src/main/java/ninja/bytecode/iris/pack/IrisDimension.java @@ -5,7 +5,6 @@ import java.io.IOException; import org.bukkit.World.Environment; import ninja.bytecode.iris.Iris; -import ninja.bytecode.iris.controller.PackController; import ninja.bytecode.shuriken.collections.KList; import ninja.bytecode.shuriken.execution.J; import ninja.bytecode.shuriken.json.JSONArray; @@ -69,8 +68,8 @@ public class IrisDimension { int ii = i; - IrisBiome bb = Iris.getController(PackController.class).loadBiome(a.getString(ii)); - Iris.getController(PackController.class).registerBiome(a.getString(ii), bb); + IrisBiome bb = Iris.pack().loadBiome(a.getString(ii)); + Iris.pack().registerBiome(a.getString(ii), bb); b.add(bb); } return b; diff --git a/src/main/java/ninja/bytecode/iris/pack/IrisPack.java b/src/main/java/ninja/bytecode/iris/pack/IrisPack.java index 69fb14b2c..783e25a72 100644 --- a/src/main/java/ninja/bytecode/iris/pack/IrisPack.java +++ b/src/main/java/ninja/bytecode/iris/pack/IrisPack.java @@ -3,7 +3,6 @@ package ninja.bytecode.iris.pack; import java.io.IOException; import ninja.bytecode.iris.Iris; -import ninja.bytecode.iris.controller.PackController; import ninja.bytecode.shuriken.collections.KList; import ninja.bytecode.shuriken.execution.J; import ninja.bytecode.shuriken.json.JSONArray; @@ -15,58 +14,58 @@ public class IrisPack private KList dimensions; private KList biomes; private KList objects; - + public IrisPack() { this.dimensions = new KList<>(); this.biomes = new KList<>(); this.objects = new KList<>(); } - + public IrisPack(JSONObject o) { this(); fromJSON(o); } - + public void fromJSON(JSONObject o) { J.attempt(() -> dimensions = fromArray(o.getJSONArray("dimensions"))); J.attempt(() -> biomes = fromArray(o.getJSONArray("biomes"))); J.attempt(() -> objects = fromArray(o.getJSONArray("objects"))); } - + public JSONObject toJSON() { JSONObject o = new JSONObject(); o.put("dimensions", toArray(dimensions)); o.put("biomes", toArray(biomes)); o.put("objects", toArray(objects)); - + return o; } - + public KList fromArray(JSONArray ja) { KList g = new KList<>(); - + for(int i = 0; i < ja.length(); i++) { g.add(ja.getString(i)); } - + return g; } - + public JSONArray toArray(KList s) { JSONArray ja = new JSONArray(); - + for(String i : s) { ja.put(i); } - + return ja; } @@ -74,14 +73,14 @@ public class IrisPack { for(String i : dimensions) { - IrisDimension d = Iris.getController(PackController.class).loadDimension(i); - Iris.getController(PackController.class).registerDimension(i, d); + IrisDimension d = Iris.pack().loadDimension(i); + Iris.pack().registerDimension(i, d); } } - + public void loadBiome(String s) throws JSONException, IOException { - IrisBiome b = Iris.getController(PackController.class).loadBiome(s); - Iris.getController(PackController.class).registerBiome(s, b); + IrisBiome b = Iris.pack().loadBiome(s); + Iris.pack().registerBiome(s, b); } } diff --git a/src/main/java/ninja/bytecode/iris/pack/IrisRegion.java b/src/main/java/ninja/bytecode/iris/pack/IrisRegion.java index 6d1ae058a..98b977af2 100644 --- a/src/main/java/ninja/bytecode/iris/pack/IrisRegion.java +++ b/src/main/java/ninja/bytecode/iris/pack/IrisRegion.java @@ -3,7 +3,6 @@ package ninja.bytecode.iris.pack; import java.util.Objects; import ninja.bytecode.iris.Iris; -import ninja.bytecode.iris.controller.PackController; import ninja.bytecode.shuriken.collections.KList; import ninja.bytecode.shuriken.execution.J; import ninja.bytecode.shuriken.json.JSONObject; @@ -33,13 +32,13 @@ public class IrisRegion { J.attempt(() -> { - JSONObject o = Iris.getController(PackController.class).loadJSON("pack/regions/" + name + ".json"); + JSONObject o = Iris.pack().loadJSON("pack/regions/" + name + ".json"); J.attempt(() -> name = o.getString("name")); - J.attempt(() -> ocean = Iris.getController(PackController.class).getBiomeById(o.getString("ocean"))); - J.attempt(() -> beach = Iris.getController(PackController.class).getBiomeById(o.getString("beach"))); - J.attempt(() -> lake = Iris.getController(PackController.class).getBiomeById(o.getString("lake"))); - J.attempt(() -> lakeBeach = Iris.getController(PackController.class).getBiomeById(o.getString("shore"))); - J.attempt(() -> channel = Iris.getController(PackController.class).getBiomeById(o.getString("channel"))); + J.attempt(() -> ocean = Iris.pack().getBiomeById(o.getString("ocean"))); + J.attempt(() -> beach = Iris.pack().getBiomeById(o.getString("beach"))); + J.attempt(() -> lake = Iris.pack().getBiomeById(o.getString("lake"))); + J.attempt(() -> lakeBeach = Iris.pack().getBiomeById(o.getString("shore"))); + J.attempt(() -> channel = Iris.pack().getBiomeById(o.getString("channel"))); }); } diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 500e95030..c1443a77d 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -1,7 +1,5 @@ name: ${project.name} version: ${project.version} main: ninja.bytecode.iris.Iris -commands: - iris: - ish: +load: STARTUP depend: [Mortar] \ No newline at end of file