diff --git a/build.gradle b/build.gradle index 134ce43f0..90c9fde80 100644 --- a/build.gradle +++ b/build.gradle @@ -99,4 +99,5 @@ dependencies { implementation 'com.sk89q.worldedit:worldedit-bukkit:7.2.0-SNAPSHOT' implementation 'io.lumine.xikage:MythicMobs:4.9.1' implementation 'com.google.code.gson:gson:2.8.5' + implementation 'me.clip:placeholderapi:2.10.10' } \ No newline at end of file diff --git a/src/main/java/com/volmit/iris/Iris.java b/src/main/java/com/volmit/iris/Iris.java index 25929fe7d..5ed17e5a2 100644 --- a/src/main/java/com/volmit/iris/Iris.java +++ b/src/main/java/com/volmit/iris/Iris.java @@ -22,6 +22,7 @@ import com.volmit.iris.core.*; import com.volmit.iris.core.command.CommandIris; import com.volmit.iris.core.command.PermissionIris; import com.volmit.iris.core.command.world.CommandLocate; +import com.volmit.iris.core.link.IrisPapiExpansion; import com.volmit.iris.core.link.MultiverseCoreLink; import com.volmit.iris.core.link.MythicMobsLink; import com.volmit.iris.core.nms.INMS; @@ -94,6 +95,46 @@ public class Iris extends VolmitPlugin implements Listener { installDataPacks(); } + + public void onEnable() { + instance = this; + try { + compat = IrisCompat.configured(getDataFile("compat.json")); + } catch (IOException e) { + Iris.reportError(e); + } + proj = new ProjectManager(); + convert = new ConversionManager(); + wand = new WandManager(); + board = new IrisBoardManager(); + linkMultiverseCore = new MultiverseCoreLink(); + linkMythicMobs = new MythicMobsLink(); + saplingManager = new TreeManager(); + edit = new EditManager(); + configWatcher = new FileWatcher(getDataFile("settings.json")); + getServer().getPluginManager().registerEvents(new CommandLocate(), this); + getServer().getPluginManager().registerEvents(new WandManager(), this); + super.onEnable(); + Bukkit.getPluginManager().registerEvents(this, this); + J.s(this::lateBind); + } + + private void lateBind() { + J.a(() -> PaperLib.suggestPaper(this)); + J.a(() -> IO.delete(getTemp())); + J.a(this::bstats); + J.a(this::splash, 20); + J.ar(this::checkConfigHotload, 60); + J.sr(this::tickQueue, 0); + J.a(this::setupPapi); + } + + private void setupPapi() { + if(Bukkit.getPluginManager().getPlugin("PlaceholderAPI") != null) { + new IrisPapiExpansion().register(); + } + } + public File getDatapacksFolder() { File props = new File("server.properties"); @@ -166,34 +207,6 @@ public class Iris extends VolmitPlugin implements Listener { return C.BOLD + "" + C.DARK_GRAY + "[" + C.BOLD + "" + C.GREEN + "Iris" + C.BOLD + C.DARK_GRAY + "]" + C.RESET + "" + C.GRAY + ": "; } - public void onEnable() { - instance = this; - try { - compat = IrisCompat.configured(getDataFile("compat.json")); - } catch (IOException e) { - Iris.reportError(e); - } - proj = new ProjectManager(); - convert = new ConversionManager(); - wand = new WandManager(); - board = new IrisBoardManager(); - linkMultiverseCore = new MultiverseCoreLink(); - linkMythicMobs = new MythicMobsLink(); - saplingManager = new TreeManager(); - edit = new EditManager(); - configWatcher = new FileWatcher(getDataFile("settings.json")); - J.a(() -> IO.delete(getTemp())); - J.a(this::bstats); - J.s(this::splash, 20); - J.sr(this::tickQueue, 0); - J.ar(this::checkConfigHotload, 40); - PaperLib.suggestPaper(this); - getServer().getPluginManager().registerEvents(new CommandLocate(), this); - getServer().getPluginManager().registerEvents(new WandManager(), this); - super.onEnable(); - Bukkit.getPluginManager().registerEvents(this, this); - } - private void checkConfigHotload() { if (configWatcher.checkModified()) { IrisSettings.invalidate(); diff --git a/src/main/java/com/volmit/iris/core/link/IrisPapiExpansion.java b/src/main/java/com/volmit/iris/core/link/IrisPapiExpansion.java new file mode 100644 index 000000000..fd052b230 --- /dev/null +++ b/src/main/java/com/volmit/iris/core/link/IrisPapiExpansion.java @@ -0,0 +1,156 @@ +/* + * Iris is a World Generator for Minecraft Bukkit Servers + * Copyright (c) 2021 Arcane Arts (Volmit Software) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package com.volmit.iris.core.link; + +import com.volmit.iris.Iris; +import com.volmit.iris.core.tools.IrisWorlds; +import com.volmit.iris.engine.framework.Engine; +import com.volmit.iris.engine.framework.IrisAccess; +import com.volmit.iris.engine.object.common.IrisWorld; +import me.clip.placeholderapi.expansion.PlaceholderExpansion; +import org.bukkit.Location; +import org.bukkit.OfflinePlayer; +import org.jetbrains.annotations.NotNull; + +// See/update https://app.gitbook.com/@volmitsoftware/s/iris/compatability/papi/ +public class IrisPapiExpansion extends PlaceholderExpansion { + @Override + public @NotNull String getIdentifier() { + return "iris"; + } + + @Override + public @NotNull String getAuthor() { + return "Volmit Software"; + } + + @Override + public @NotNull String getVersion() { + return Iris.instance.getDescription().getVersion(); + } + + @Override + public boolean persist() { + return false; + } + + @Override + public String onRequest(OfflinePlayer player, String p) { + Location l = null; + IrisAccess a = null; + + if(player.isOnline()) + { + l = player.getPlayer().getLocation(); + a = IrisWorlds.access(l.getWorld()); + } + + if (p.equalsIgnoreCase("biome_name")) + { + if(a != null) + { + return a.getBiome(l).getName(); + } + } + + else if (p.equalsIgnoreCase("biome_id")) + { + if(a != null) + { + return a.getBiome(l).getLoadKey(); + } + } + + else if (p.equalsIgnoreCase("biome_file")) + { + if(a != null) + { + return a.getBiome(l).getLoadFile().getPath(); + } + } + + else if (p.equalsIgnoreCase("region_name")) + { + if(a != null) + { + return a.getRegion(l).getName(); + } + } + + else if (p.equalsIgnoreCase("region_id")) + { + if(a != null) + { + return a.getRegion(l).getLoadKey(); + } + } + + else if (p.equalsIgnoreCase("region_file")) + { + if(a != null) + { + return a.getRegion(l).getLoadFile().getPath(); + } + } + + else if (p.equalsIgnoreCase("terrain_slope")) + { + if(a != null) + { + return ((Engine)a.getEngineAccess(l.getBlockY())) + .getFramework().getComplex().getSlopeStream() + .get(l.getX(), l.getZ()) + ""; + } + } + + else if (p.equalsIgnoreCase("terrain_height")) + { + if(a != null) + { + return (int)Math.round(a.getHeight(l)) + ""; + } + } + + else if (p.equalsIgnoreCase("world_mode")) + { + if(a != null) + { + return a.isStudio() ? "Studio" : "Production"; + } + } + + else if (p.equalsIgnoreCase("world_seed")) + { + if(a != null) + { + return a.getTarget().getWorld().seed() + ""; + } + } + + else if (p.equalsIgnoreCase("world_speed")) + { + if(a != null) + { + return a.getGeneratedPerSecond() + "/s"; + } + } + + return null; + } +} diff --git a/src/main/java/com/volmit/iris/engine/framework/IrisAccess.java b/src/main/java/com/volmit/iris/engine/framework/IrisAccess.java index e064ddc78..cf28aa5dc 100644 --- a/src/main/java/com/volmit/iris/engine/framework/IrisAccess.java +++ b/src/main/java/com/volmit/iris/engine/framework/IrisAccess.java @@ -36,6 +36,7 @@ import com.volmit.iris.util.scheduling.ChronoLatch; import com.volmit.iris.util.scheduling.J; import org.bukkit.Location; import org.bukkit.command.CommandSender; +import org.bukkit.util.Vector; import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicInteger; @@ -65,6 +66,31 @@ public interface IrisAccess extends Hotloadable, DataProvider { void printMetrics(CommandSender sender); + /** + * Ignores the world, just uses the position + * @param l the location + * @return the biome + */ + default IrisBiome getBiome(Location l) + { + return getBiome(l.toVector()); + } + + default IrisRegion getRegion(int x, int y, int z) + { + return getEngineAccess(y).getRegion(x, z); + } + + default IrisRegion getRegion(Location l) + { + return getRegion(l.getBlockX(), l.getBlockY(), l.getBlockZ()); + } + + default IrisBiome getBiome(Vector l) + { + return getBiome(l.getBlockX(), l.getBlockY(), l.getBlockZ()); + } + IrisBiome getBiome(int x, int y, int z); IrisBiome getCaveBiome(int x, int y, int z); @@ -266,4 +292,9 @@ public interface IrisAccess extends Hotloadable, DataProvider { return v; } + + default double getHeight(Location l) + { + return getHeight(l.getBlockX(), l.getBlockY(), l.getBlockZ()); + } }