From d07c8c88519b114ff37919b9ee6987b8ef18915c Mon Sep 17 00:00:00 2001 From: CocoTheOwner Date: Sat, 28 Aug 2021 16:18:53 +0200 Subject: [PATCH] What & debug fix --- .../command/what/CommandIrisWhatBlock.java | 39 --- .../command/what/CommandIrisWhatObjects.java | 9 +- .../core/command/world/CommandIrisVerify.java | 4 +- .../com/volmit/iris/core/decrees/DecIris.java | 14 +- .../com/volmit/iris/core/decrees/DecWhat.java | 315 ++++++++++++++++++ .../volmit/iris/core/service/CommandSVC.java | 3 +- .../util/decree/handlers/BooleanHandler.java | 3 + src/main/resources/plugin.yml | 2 + 8 files changed, 334 insertions(+), 55 deletions(-) create mode 100644 src/main/java/com/volmit/iris/core/decrees/DecWhat.java diff --git a/src/main/java/com/volmit/iris/core/command/what/CommandIrisWhatBlock.java b/src/main/java/com/volmit/iris/core/command/what/CommandIrisWhatBlock.java index 818d1ecb3..6018562f8 100644 --- a/src/main/java/com/volmit/iris/core/command/what/CommandIrisWhatBlock.java +++ b/src/main/java/com/volmit/iris/core/command/what/CommandIrisWhatBlock.java @@ -46,46 +46,7 @@ public class CommandIrisWhatBlock extends MortarCommand { if (sender.isPlayer()) { BlockData bd; Player p = sender.player(); - try { - bd = p.getTargetBlockExact(128, FluidCollisionMode.NEVER).getBlockData(); - } catch (NullPointerException e) { - Iris.reportError(e); - sender.sendMessage("Please look at any block, not at the sky"); - bd = null; - } - if (bd != null) { - sender.sendMessage("Material: " + C.GREEN + bd.getMaterial().name()); - sender.sendMessage("Full: " + C.WHITE + bd.getAsString(true)); - - if (B.isStorage(bd)) { - sender.sendMessage(C.YELLOW + "* Storage Block (Loot Capable)"); - } - - if (B.isLit(bd)) { - sender.sendMessage(C.YELLOW + "* Lit Block (Light Capable)"); - } - - if (B.isFoliage(bd)) { - sender.sendMessage(C.YELLOW + "* Foliage Block"); - } - - if (B.isDecorant(bd)) { - sender.sendMessage(C.YELLOW + "* Decorant Block"); - } - - if (B.isFluid(bd)) { - sender.sendMessage(C.YELLOW + "* Fluid Block"); - } - - if (B.isFoliagePlantable(bd)) { - sender.sendMessage(C.YELLOW + "* Plantable Foliage Block"); - } - - if (B.isSolid(bd)) { - sender.sendMessage(C.YELLOW + "* Solid Block"); - } - } } else { sender.sendMessage("Players only."); } diff --git a/src/main/java/com/volmit/iris/core/command/what/CommandIrisWhatObjects.java b/src/main/java/com/volmit/iris/core/command/what/CommandIrisWhatObjects.java index 83659a91b..fa9d5ca6b 100644 --- a/src/main/java/com/volmit/iris/core/command/what/CommandIrisWhatObjects.java +++ b/src/main/java/com/volmit/iris/core/command/what/CommandIrisWhatObjects.java @@ -61,7 +61,6 @@ public class CommandIrisWhatObjects extends MortarCommand { } - @SuppressWarnings("MismatchedQueryAndUpdateOfCollection") @Override public boolean handle(VolmitSender sender, String[] args) { if (sender.isPlayer()) { @@ -81,11 +80,9 @@ public class CommandIrisWhatObjects extends MortarCommand { try { Location l = p.getTargetBlockExact(48, FluidCollisionMode.NEVER).getLocation(); - if (l != null) { - int cx = l.getChunk().getX(); - int cz = l.getChunk().getZ(); - new Spiraler(3, 3, (x, z) -> chunks.addIfMissing(world.getChunkAt(x + cx, z + cz))).drain(); - } + int cx = l.getChunk().getX(); + int cz = l.getChunk().getZ(); + new Spiraler(3, 3, (x, z) -> chunks.addIfMissing(world.getChunkAt(x + cx, z + cz))).drain(); } catch (Throwable e) { Iris.reportError(e); } diff --git a/src/main/java/com/volmit/iris/core/command/world/CommandIrisVerify.java b/src/main/java/com/volmit/iris/core/command/world/CommandIrisVerify.java index 42bb4aef4..890f79fdd 100644 --- a/src/main/java/com/volmit/iris/core/command/world/CommandIrisVerify.java +++ b/src/main/java/com/volmit/iris/core/command/world/CommandIrisVerify.java @@ -60,8 +60,8 @@ public class CommandIrisVerify extends MortarCommand { MCAFile file = null; try { file = MCAUtil.read(i); - int rx = Integer.valueOf(i.getName().split("\\Q.\\E")[1]); - int rz = Integer.valueOf(i.getName().split("\\Q.\\E")[2]); + int rx = Integer.parseInt(i.getName().split("\\Q.\\E")[1]); + int rz = Integer.parseInt(i.getName().split("\\Q.\\E")[2]); for (int j = 0; j < 32; j++) { for (int k = 0; k < 32; k++) { f.incrementAndGet(); diff --git a/src/main/java/com/volmit/iris/core/decrees/DecIris.java b/src/main/java/com/volmit/iris/core/decrees/DecIris.java index c14854b6c..5976f97fe 100644 --- a/src/main/java/com/volmit/iris/core/decrees/DecIris.java +++ b/src/main/java/com/volmit/iris/core/decrees/DecIris.java @@ -33,6 +33,7 @@ import com.volmit.iris.util.decree.exceptions.DecreeWhichException; import com.volmit.iris.util.format.C; import java.io.File; +import java.util.Objects; @Decree(name = "irisd", aliases = {"ird"}, description = "Basic Command") public class DecIris implements DecreeExecutor { @@ -44,7 +45,9 @@ public class DecIris implements DecreeExecutor { private DecObject object; - @Decree(description = "Create a new world", aliases = {"+", "c"}) + private DecWhat what; + + @Decree(description = "Create a new world", aliases = "+") public void create( @Param(aliases = "world-name", description = "The name of the world to create") String name, @@ -130,14 +133,11 @@ public class DecIris implements DecreeExecutor { @Decree(description = "Toggle debug") public void debug( - @Param(description = "Whether or not debug should be on", defaultValue = "toggle") + @Param(name = "on", description = "Whether or not debug should be on", defaultValue = "other") Boolean on ) { - if (on == null){ - on = !IrisSettings.get().getGeneral().isDebug(); - } - sender().sendMessage(C.GREEN + "Set debug to " + on); - IrisSettings.get().getGeneral().setDebug(on); + IrisSettings.get().getGeneral().setDebug(Objects.requireNonNullElseGet(on, () -> !IrisSettings.get().getGeneral().isDebug())); + sender().sendMessage(); } @Decree(description = "Download a project.", aliases = "dl") diff --git a/src/main/java/com/volmit/iris/core/decrees/DecWhat.java b/src/main/java/com/volmit/iris/core/decrees/DecWhat.java new file mode 100644 index 000000000..7401f85f4 --- /dev/null +++ b/src/main/java/com/volmit/iris/core/decrees/DecWhat.java @@ -0,0 +1,315 @@ +package com.volmit.iris.core.decrees; + +import com.google.gson.Gson; +import com.volmit.iris.Iris; +import com.volmit.iris.core.nms.INMS; +import com.volmit.iris.core.tools.IrisToolbelt; +import com.volmit.iris.engine.framework.Engine; +import com.volmit.iris.engine.object.biome.IrisBiome; +import com.volmit.iris.engine.object.feature.IrisFeaturePositional; +import com.volmit.iris.engine.object.objects.IrisObject; +import com.volmit.iris.engine.object.objects.IrisObjectPlacement; +import com.volmit.iris.util.collection.KList; +import com.volmit.iris.util.collection.KMap; +import com.volmit.iris.util.collection.KSet; +import com.volmit.iris.util.data.B; +import com.volmit.iris.util.decree.DecreeExecutor; +import com.volmit.iris.util.decree.DecreeOrigin; +import com.volmit.iris.util.decree.annotations.Decree; +import com.volmit.iris.util.format.C; +import com.volmit.iris.util.format.Form; +import com.volmit.iris.util.json.JSONObject; +import com.volmit.iris.util.math.M; +import com.volmit.iris.util.math.Spiraler; +import com.volmit.iris.util.plugin.VolmitSender; +import io.papermc.lib.PaperLib; +import org.bukkit.*; +import org.bukkit.block.Biome; +import org.bukkit.block.Block; +import org.bukkit.block.data.BlockData; +import org.bukkit.entity.Player; +import org.bukkit.util.BlockVector; + +import java.io.File; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.io.PrintWriter; +import java.nio.file.Files; +import java.nio.file.attribute.FileTime; +import java.time.Duration; +import java.time.temporal.ChronoUnit; +import java.util.Date; +import java.util.Objects; + +@Decree(name = "what", aliases = "?", description = "Find information on the world around you", origin = DecreeOrigin.PLAYER) +public class DecWhat implements DecreeExecutor { + + @Decree(description = "Get information about the biome your are currently in") + public void biome() { + if (IrisToolbelt.isIrisWorld(player().getWorld())) { + IrisBiome b = engine().getBiome(player().getLocation()); + sender().sendMessage(C.GREEN + "IrisBiome: " + b.getLoadKey() + " (" + b.getDerivative().name() + ")"); + } else { + sender().sendMessage(C.YELLOW + "Non-Iris Biome: " + player().getLocation().getBlock().getBiome().name()); + if (player().getLocation().getBlock().getBiome().equals(Biome.CUSTOM)) { + try { + sender().sendMessage(C.YELLOW + "Data Pack Biome: " + INMS.get().getTrueBiomeBaseKey(player().getLocation()) + " (ID: " + INMS.get().getTrueBiomeBaseId(INMS.get().getTrueBiomeBase(player().getLocation())) + ")"); + } catch (Throwable ee) { + Iris.reportError(ee); + } + } + } + } + + @Decree(description = "Get information about the block you are looking at") + public void block() { + Block target = player().getTargetBlockExact(128, FluidCollisionMode.NEVER); + if (target == null) { + sender().sendMessage(C.YELLOW + "Please look at a block, not at the sky"); + return; + } + + BlockData bd = target.getBlockData(); + + + sender().sendMessage("Material: " + C.GREEN + bd.getMaterial().name()); + sender().sendMessage("Full: " + C.WHITE + bd.getAsString(true)); + + if (B.isStorage(bd)) { + sender().sendMessage(C.YELLOW + "* Storage Block (Loot Capable)"); + } + + if (B.isLit(bd)) { + sender().sendMessage(C.YELLOW + "* Lit Block (Light Capable)"); + } + + if (B.isFoliage(bd)) { + sender().sendMessage(C.YELLOW + "* Foliage Block"); + } + + if (B.isDecorant(bd)) { + sender().sendMessage(C.YELLOW + "* Decorant Block"); + } + + if (B.isFluid(bd)) { + sender().sendMessage(C.YELLOW + "* Fluid Block"); + } + + if (B.isFoliagePlantable(bd)) { + sender().sendMessage(C.YELLOW + "* Plantable Foliage Block"); + } + + if (B.isSolid(bd)) { + sender().sendMessage(C.YELLOW + "* Solid Block"); + } + } + + @Decree(aliases = "nf", description = "Get the noise feature data in your chunk") + public void features() { + + if (!IrisToolbelt.isIrisWorld(player().getWorld())){ + sender().sendMessage(C.RED + "Iris worlds only"); + return; + } + + int n = 0; + + for (IrisFeaturePositional irisFeaturePositional : engine().getMantle().getFeaturesInChunk(player().getLocation().getChunk())) { + sender().sendMessage("#" + n++ + " " + new JSONObject(new Gson().toJson(irisFeaturePositional)).toString(4)); + } + } + + @Decree(description = "Get information about the item you are holding", sync = true) + public void hand() { + BlockData bd = player().getInventory().getItemInMainHand().getType().createBlockData(); + + if (bd.getMaterial().equals(Material.AIR)){ + sender().sendMessage(C.YELLOW + "Please hold a block/item"); + return; + } + + sender().sendMessage("Material: " + C.GREEN + bd.getMaterial().name()); + sender().sendMessage("Full: " + C.WHITE + bd.getAsString(true)); + + } + + @Decree(aliases = "capture", description = "Get information about nearby structures") + public void objects() { + if (!IrisToolbelt.isIrisWorld(player().getWorld())){ + sender().sendMessage(C.RED + "You must be in an Iris world"); + return; + } + + World world = player().getWorld(); + + if (!IrisToolbelt.isIrisWorld(world)) { + sender().sendMessage("You must be in an iris world."); + return; + } + KList chunks = new KList<>(); + int bx = player().getLocation().getChunk().getX(); + int bz = player().getLocation().getChunk().getZ(); + + try { + Location l = player().getTargetBlockExact(48, FluidCollisionMode.NEVER).getLocation(); + + int cx = l.getChunk().getX(); + int cz = l.getChunk().getZ(); + new Spiraler(3, 3, (x, z) -> chunks.addIfMissing(world.getChunkAt(x + cx, z + cz))).drain(); + } catch (Throwable e) { + Iris.reportError(e); + } + + new Spiraler(3, 3, (x, z) -> chunks.addIfMissing(world.getChunkAt(x + bx, z + bz))).drain(); + sender().sendMessage("Capturing IGenData from " + chunks.size() + " nearby chunks."); + try { + File ff = Iris.instance.getDataFile("reports/" + M.ms() + ".txt"); + PrintWriter pw = new PrintWriter(ff); + pw.println("=== Iris Chunk Report ==="); + pw.println("== General Info =="); + pw.println("Iris Version: " + Iris.instance.getDescription().getVersion()); + pw.println("Bukkit Version: " + Bukkit.getBukkitVersion()); + pw.println("MC Version: " + Bukkit.getVersion()); + pw.println("PaperSpigot: " + (PaperLib.isPaper() ? "Yup!" : "Nope!")); + pw.println("Report Captured At: " + new Date()); + pw.println("Chunks: (" + chunks.size() + "): "); + + for (Chunk i : chunks) { + pw.println("- [" + i.getX() + ", " + i.getZ() + "]"); + } + + int regions = 0; + long size = 0; + String age = "No idea..."; + + try { + for (File i : Objects.requireNonNull(new File(world.getWorldFolder(), "region").listFiles())) { + if (i.isFile()) { + size += i.length(); + } + } + } catch (Throwable e) { + Iris.reportError(e); + } + + try { + FileTime creationTime = (FileTime) Files.getAttribute(world.getWorldFolder().toPath(), "creationTime"); + age = hrf(Duration.of(M.ms() - creationTime.toMillis(), ChronoUnit.MILLIS)); + } catch (IOException e) { + Iris.reportError(e); + } + + KList biomes = new KList<>(); + KList caveBiomes = new KList<>(); + KMap>> objects = new KMap<>(); + + for (Chunk i : chunks) { + for (int j = 0; j < 16; j += 3) { + + for (int k = 0; k < 16; k += 3) { + + assert engine() != null; + IrisBiome bb = engine().getSurfaceBiome((i.getX() * 16) + j, (i.getZ() * 16) + k); + IrisBiome bxf = engine().getCaveBiome((i.getX() * 16) + j, (i.getZ() * 16) + k); + biomes.addIfMissing(bb.getName() + " [" + Form.capitalize(bb.getInferredType().name().toLowerCase()) + "] " + " (" + bb.getLoadFile().getName() + ")"); + caveBiomes.addIfMissing(bxf.getName() + " (" + bxf.getLoadFile().getName() + ")"); + exportObjects(bb, pw, engine(), objects); + exportObjects(bxf, pw, engine(), objects); + } + } + } + + regions = Objects.requireNonNull(new File(world.getWorldFolder().getPath() + "/region").list()).length; + + pw.println(); + pw.println("== World Info =="); + pw.println("World Name: " + world.getName()); + pw.println("Age: " + age); + pw.println("Folder: " + world.getWorldFolder().getPath()); + pw.println("Regions: " + Form.f(regions)); + pw.println("Chunks: max. " + Form.f(regions * 32 * 32)); + pw.println("World Size: min. " + Form.fileSize(size)); + pw.println(); + pw.println("== Biome Info =="); + pw.println("Found " + biomes.size() + " Biome(s): "); + + for (String i : biomes) { + pw.println("- " + i); + } + pw.println(); + + pw.println("== Object Info =="); + + for (String i : objects.k()) { + pw.println("- " + i); + + for (String j : objects.get(i).k()) { + pw.println(" @ " + j); + + for (String k : objects.get(i).get(j)) { + pw.println(" * " + k); + } + } + } + + pw.println(); + pw.close(); + + sender().sendMessage("Reported to: " + ff.getPath()); + } catch (FileNotFoundException e) { + e.printStackTrace(); + Iris.reportError(e); + } + } + + private void exportObjects(IrisBiome bb, PrintWriter pw, Engine g, KMap>> objects) { + String n1 = bb.getName() + " [" + Form.capitalize(bb.getInferredType().name().toLowerCase()) + "] " + " (" + bb.getLoadFile().getName() + ")"; + int m = 0; + KSet stop = new KSet<>(); + for (IrisObjectPlacement f : bb.getObjects()) { + m++; + String n2 = "Placement #" + m + " (" + f.getPlace().size() + " possible objects)"; + + for (String i : f.getPlace()) { + String nn3 = i + ": [ERROR] Failed to find object!"; + + try { + if (stop.contains(i)) { + continue; + } + + File ff = g.getData().getObjectLoader().findFile(i); + BlockVector sz = IrisObject.sampleSize(ff); + nn3 = i + ": size=[" + sz.getBlockX() + "," + sz.getBlockY() + "," + sz.getBlockZ() + "] location=[" + ff.getPath() + "]"; + stop.add(i); + } catch (Throwable e) { + Iris.reportError(e); + } + + String n3 = nn3; + + objects.compute(n1, (k1, v1) -> + { + //noinspection ReplaceNullCheck + if (v1 == null) { + return new KMap<>(); + } + + return v1; + }).compute(n2, (k, v) -> + { + if (v == null) { + return new KList().qaddIfMissing(n3); + } + + v.addIfMissing(n3); + return v; + }); + } + } + } + + public static String hrf(Duration duration) { + return duration.toString().substring(2).replaceAll("(\\d[HMS])(?!$)", "$1 ").toLowerCase(); + } +} diff --git a/src/main/java/com/volmit/iris/core/service/CommandSVC.java b/src/main/java/com/volmit/iris/core/service/CommandSVC.java index 793100629..2bc017fb1 100644 --- a/src/main/java/com/volmit/iris/core/service/CommandSVC.java +++ b/src/main/java/com/volmit/iris/core/service/CommandSVC.java @@ -18,6 +18,7 @@ package com.volmit.iris.core.service; +import com.volmit.iris.Iris; import com.volmit.iris.core.decrees.DecIris; import com.volmit.iris.engine.data.cache.AtomicCache; import com.volmit.iris.util.collection.KList; @@ -28,7 +29,7 @@ import com.volmit.iris.util.plugin.IrisService; public class CommandSVC implements IrisService, DecreeSystem { @Override public void onEnable() { - // TODO Iris.instance.getCommand("irisd").setExecutor(this); + Iris.instance.getCommand("irisd").setExecutor(this); } @Override diff --git a/src/main/java/com/volmit/iris/util/decree/handlers/BooleanHandler.java b/src/main/java/com/volmit/iris/util/decree/handlers/BooleanHandler.java index e61de78ad..d53bb1555 100644 --- a/src/main/java/com/volmit/iris/util/decree/handlers/BooleanHandler.java +++ b/src/main/java/com/volmit/iris/util/decree/handlers/BooleanHandler.java @@ -37,6 +37,9 @@ public class BooleanHandler implements DecreeParameterHandler { @Override public Boolean parse(String in) throws DecreeParsingException { try { + if (in.equals("null") || in.equals("other") || in.equals("flip")) { + return null; + } return Boolean.parseBoolean(in); } catch (Throwable e) { throw new DecreeParsingException("Unable to parse boolean \"" + in + "\""); diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 14d43c307..0d540b7b7 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -20,5 +20,7 @@ libraries: commands: iris: aliases: [ ir, irs ] + irisd: + aliases: [ ird, id ] api-version: ${apiversion} hotload-dependencies: false \ No newline at end of file