mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2025-08-16 00:05:59 +00:00
Rereg
This commit is contained in:
parent
1f9f7101e2
commit
c209895389
22
README.md
22
README.md
@ -1,15 +1,18 @@
|
||||
# Iris
|
||||
# IrisBukkit
|
||||
|
||||
The master branch is for the latest version of minecraft.
|
||||
|
||||
# [Support](https://discord.gg/3xxPTpT) **|** [Documentation](https://docs.volmit.com/iris/) **|** [Git](https://github.com/IrisDimensions)
|
||||
# [Support](https://discord.gg/3xxPTpT) **|** [Documentation](https://docs.volmit.com/iris/) **
|
||||
|** [Git](https://github.com/IrisDimensions)
|
||||
|
||||
# Building
|
||||
|
||||
Building Iris is fairly simple, though you will need to setup a few things if your system has never been used for java
|
||||
Building IrisBukkit is fairly simple, though you will need to setup a few things if your system has never been used for
|
||||
java
|
||||
development.
|
||||
|
||||
Consider supporting our development by buying Iris on spigot! We work hard to make Iris the best it can be for everyone.
|
||||
Consider supporting our development by buying IrisBukkit on spigot! We work hard to make IrisBukkit the best it can be
|
||||
for everyone.
|
||||
|
||||
### Command Line Builds
|
||||
|
||||
@ -28,20 +31,23 @@ Consider supporting our development by buying Iris on spigot! We work hard to ma
|
||||
3. Add `export JAVA_HOME=$(/usr/libexec/java_home)` as a new line
|
||||
4. Use `CTRL + X`, then Press `Y`, Then `ENTER`
|
||||
5. Quit & Reopen Terminal and verify with `echo $JAVA_HOME`. It should print a directory
|
||||
3. If this is your first time building Iris for MC 1.18+ run `gradlew setup` inside the root Iris project folder.
|
||||
3. If this is your first time building IrisBukkit for MC 1.18+ run `gradlew setup` inside the root IrisBukkit project
|
||||
folder.
|
||||
Otherwise, skip this step. Grab a coffee, this may take up to 5 minutes depending on your cpu & internet connection.
|
||||
4. Once the project has setup, run `gradlew iris`
|
||||
5. The Iris jar will be placed in `Iris/build/Iris-XXX-XXX.jar` Enjoy! Consider supporting us by buying it on spigot!
|
||||
5. The IrisBukkit jar will be placed in `IrisBukkit/build/IrisBukkit-XXX-XXX.jar` Enjoy! Consider supporting us by
|
||||
buying it on spigot!
|
||||
|
||||
### IDE Builds (for development)
|
||||
|
||||
* Run `gradlew setup` any time you get dependency issues with craftbukkit
|
||||
* Configure ITJ Gradle to use JDK 17 (in settings, search for gradle)
|
||||
* Add a build line in the build.gradle for your own build task to directly compile Iris into your plugins folder if you
|
||||
* Add a build line in the build.gradle for your own build task to directly compile IrisBukkit into your plugins folder
|
||||
if you
|
||||
prefer.
|
||||
* Resync the project & run your newly created task (under the development folder in gradle tasks!)
|
||||
|
||||
# Iris Toolbelt
|
||||
# IrisBukkit Toolbelt
|
||||
|
||||
Everyone needs a tool-belt.
|
||||
|
||||
|
@ -8,7 +8,7 @@ version '1.0-SNAPSHOT'
|
||||
|
||||
jar {
|
||||
manifest {
|
||||
attributes('Contains-Sources':'java,class')
|
||||
attributes('Contains-Sources': 'java,class')
|
||||
}
|
||||
}
|
||||
|
||||
@ -44,7 +44,7 @@ allprojects {
|
||||
}
|
||||
|
||||
if (JavaVersion.current() != JavaVersion.VERSION_1_8 &&
|
||||
sourceSets.main.allJava.files.any {it.name == "module-info.java"}) {
|
||||
sourceSets.main.allJava.files.any { it.name == "module-info.java" }) {
|
||||
tasks.withType(JavaCompile) {
|
||||
options.compilerArgs += ['-Xplugin:Manifold', '--module-path', it.classpath.asPath]
|
||||
}
|
||||
|
@ -0,0 +1,13 @@
|
||||
package Iris.extensions.org.bukkit.Chunk;
|
||||
|
||||
import com.volmit.iris.platform.bukkit.wrapper.BukkitChunk;
|
||||
import manifold.ext.rt.api.Extension;
|
||||
import manifold.ext.rt.api.This;
|
||||
import org.bukkit.Chunk;
|
||||
|
||||
@Extension
|
||||
public class XChunk {
|
||||
public static BukkitChunk bukkitChunk(@This Chunk self) {
|
||||
return BukkitChunk.of(self);
|
||||
}
|
||||
}
|
@ -0,0 +1,13 @@
|
||||
package Iris.extensions.org.bukkit.NamespacedKey;
|
||||
|
||||
import com.volmit.iris.platform.bukkit.wrapper.BukkitKey;
|
||||
import manifold.ext.rt.api.Extension;
|
||||
import manifold.ext.rt.api.This;
|
||||
import org.bukkit.NamespacedKey;
|
||||
|
||||
@Extension
|
||||
public class XNamespacedKey {
|
||||
public static BukkitKey bukkitKey(@This NamespacedKey self) {
|
||||
return BukkitKey.of(self);
|
||||
}
|
||||
}
|
@ -0,0 +1,13 @@
|
||||
package Iris.extensions.org.bukkit.World;
|
||||
|
||||
import com.volmit.iris.platform.bukkit.wrapper.BukkitWorld;
|
||||
import manifold.ext.rt.api.Extension;
|
||||
import manifold.ext.rt.api.This;
|
||||
import org.bukkit.World;
|
||||
|
||||
@Extension
|
||||
public class XWorld {
|
||||
public static BukkitWorld bukkitWorld(@This World self) {
|
||||
return BukkitWorld.of(self);
|
||||
}
|
||||
}
|
@ -0,0 +1,18 @@
|
||||
package Iris.extensions.org.bukkit.block.Biome;
|
||||
|
||||
import com.volmit.iris.platform.bukkit.wrapper.BukkitBiome;
|
||||
import com.volmit.iris.platform.bukkit.wrapper.BukkitKey;
|
||||
import manifold.ext.rt.api.Extension;
|
||||
import manifold.ext.rt.api.This;
|
||||
import org.bukkit.block.Biome;
|
||||
|
||||
@Extension
|
||||
public class XBiome {
|
||||
public static BukkitKey bukkitKey(@This Biome self) {
|
||||
return self.getKey().bukkitKey();
|
||||
}
|
||||
|
||||
public static BukkitBiome bukkitBiome(@This Biome self) {
|
||||
return BukkitBiome.of(self);
|
||||
}
|
||||
}
|
@ -0,0 +1,18 @@
|
||||
package Iris.extensions.org.bukkit.block.data.BlockData;
|
||||
|
||||
import com.volmit.iris.platform.bukkit.wrapper.BukkitBlock;
|
||||
import com.volmit.iris.platform.bukkit.wrapper.BukkitKey;
|
||||
import manifold.ext.rt.api.Extension;
|
||||
import manifold.ext.rt.api.This;
|
||||
import org.bukkit.block.data.BlockData;
|
||||
|
||||
@Extension
|
||||
public class XBlockData {
|
||||
public static BukkitKey bukkitKey(@This BlockData self) {
|
||||
return self.getMaterial().getKey().bukkitKey();
|
||||
}
|
||||
|
||||
public static BukkitBlock bukkitBlock(@This BlockData self) {
|
||||
return BukkitBlock.of(self);
|
||||
}
|
||||
}
|
@ -0,0 +1,13 @@
|
||||
package Iris.extensions.org.bukkit.entity.Player;
|
||||
|
||||
import com.volmit.iris.platform.bukkit.wrapper.BukkitPlayer;
|
||||
import manifold.ext.rt.api.Extension;
|
||||
import manifold.ext.rt.api.This;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
@Extension
|
||||
public class XPlayer {
|
||||
public static BukkitPlayer bukkitPlayer(@This Player self) {
|
||||
return BukkitPlayer.of(self);
|
||||
}
|
||||
}
|
@ -1,44 +1,34 @@
|
||||
package com.volmit.iris.platform.bukkit;
|
||||
|
||||
import com.volmit.iris.engine.object.NSKey;
|
||||
import com.volmit.iris.engine.object.biome.NativeBiome;
|
||||
import com.volmit.iris.engine.object.block.IrisBlock;
|
||||
import com.volmit.iris.platform.IrisPlatform;
|
||||
import com.volmit.iris.platform.PlatformDataTransformer;
|
||||
import com.volmit.iris.platform.PlatformTransformer;
|
||||
import com.volmit.iris.platform.bukkit.transformers.BukkitBiomeTransformer;
|
||||
import com.volmit.iris.platform.bukkit.transformers.BukkitBlockDataTransformer;
|
||||
import com.volmit.iris.platform.bukkit.transformers.BukkitNamespaceTransformer;
|
||||
import com.volmit.iris.platform.PlatformBiome;
|
||||
import com.volmit.iris.platform.PlatformBlock;
|
||||
import com.volmit.iris.platform.PlatformWorld;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import org.bukkit.NamespacedKey;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.block.Biome;
|
||||
import org.bukkit.block.data.BlockData;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
public class IrisBukkit extends JavaPlugin implements IrisPlatform<NamespacedKey, BlockData, Biome> {
|
||||
public class IrisBukkit extends JavaPlugin implements IrisPlatform {
|
||||
private static IrisBukkit instance;
|
||||
private PlatformTransformer<NamespacedKey, NSKey> namespaceTransformer;
|
||||
private PlatformDataTransformer<BlockData, IrisBlock> blockDataTransformer;
|
||||
private PlatformDataTransformer<Biome, NativeBiome> biomeTransformer;
|
||||
|
||||
public void onEnable()
|
||||
{
|
||||
public void onEnable() {
|
||||
instance = this;
|
||||
namespaceTransformer = new BukkitNamespaceTransformer();
|
||||
blockDataTransformer = new BukkitBlockDataTransformer();
|
||||
biomeTransformer = new BukkitBiomeTransformer();
|
||||
}
|
||||
|
||||
public void onDisable()
|
||||
{
|
||||
public void onDisable() {
|
||||
|
||||
}
|
||||
|
||||
public static IrisBukkit getInstance()
|
||||
{
|
||||
public static IrisBukkit getInstance() {
|
||||
return instance;
|
||||
}
|
||||
|
||||
@ -46,4 +36,35 @@ public class IrisBukkit extends JavaPlugin implements IrisPlatform<NamespacedKey
|
||||
public String getPlatformName() {
|
||||
return "Bukkit";
|
||||
}
|
||||
|
||||
@Override
|
||||
public Stream<PlatformBlock> getBlocks() {
|
||||
//This is because it's a method extension
|
||||
//noinspection Convert2MethodRef
|
||||
return Arrays.stream(Material.values()).parallel().filter(Material::isBlock).map(Material::createBlockData).map(i -> i.bukkitBlock());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Stream<PlatformBiome> getBiomes() {
|
||||
//This is because it's a method extension
|
||||
//noinspection Convert2MethodRef
|
||||
return Arrays.stream(Biome.values()).parallel().filter((i) -> i != Biome.CUSTOM).map(i -> i.bukkitBiome());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isWorldLoaded(String name) {
|
||||
return Bukkit.getWorlds().keepWhere(i -> i.getName().equals(name)).isNotEmpty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public PlatformWorld getWorld(String name) {
|
||||
World w = Bukkit.getWorld(name);
|
||||
|
||||
if(w == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
return w.bukkitWorld();
|
||||
}
|
||||
}
|
||||
|
@ -1,42 +0,0 @@
|
||||
package com.volmit.iris.platform.bukkit.transformers;
|
||||
|
||||
import com.volmit.iris.engine.object.NSKey;
|
||||
import com.volmit.iris.engine.object.biome.NativeBiome;
|
||||
import com.volmit.iris.platform.PlatformDataTransformer;
|
||||
import com.volmit.iris.platform.PlatformTransformer;
|
||||
import com.volmit.iris.platform.bukkit.IrisBukkit;
|
||||
import org.bukkit.NamespacedKey;
|
||||
import org.bukkit.WorldType;
|
||||
import org.bukkit.block.Biome;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public class BukkitBiomeTransformer implements PlatformDataTransformer<Biome, NativeBiome> {
|
||||
@Override
|
||||
public Stream<Biome> getRegistry() {
|
||||
return Arrays.stream(Biome.values()).parallel().filter((i) -> i != Biome.CUSTOM);
|
||||
}
|
||||
|
||||
@Override
|
||||
public NSKey getKey(Biome nativeType) {
|
||||
return IrisBukkit.getInstance().getNamespaceTransformer().toIris(nativeType.getKey());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTypeName() {
|
||||
return "Block";
|
||||
}
|
||||
|
||||
@Override
|
||||
public NativeBiome toIris(Biome biome) {
|
||||
PlatformTransformer<NamespacedKey, NSKey> transformer = IrisBukkit.getInstance().getNamespaceTransformer();
|
||||
return new NativeBiome(transformer.toIris(biome.getKey()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Biome toNative(NativeBiome nativeBiome) {
|
||||
PlatformTransformer<NamespacedKey, NSKey> transformer = IrisBukkit.getInstance().getNamespaceTransformer();
|
||||
return Biome.values().stream().filter((i) -> transformer.toIris(i.getKey()).equals(nativeBiome.getKey())).findFirst().get();
|
||||
}
|
||||
}
|
@ -1,73 +0,0 @@
|
||||
package com.volmit.iris.platform.bukkit.transformers;
|
||||
|
||||
import art.arcane.amulet.util.Platform;
|
||||
import com.volmit.iris.engine.object.NSKey;
|
||||
import com.volmit.iris.engine.object.block.IrisBlock;
|
||||
import com.volmit.iris.platform.PlatformDataTransformer;
|
||||
import com.volmit.iris.platform.PlatformTransformer;
|
||||
import com.volmit.iris.platform.bukkit.IrisBukkit;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.NamespacedKey;
|
||||
import org.bukkit.block.Biome;
|
||||
import org.bukkit.block.data.BlockData;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public class BukkitBlockDataTransformer implements PlatformDataTransformer<BlockData, IrisBlock> {
|
||||
@Override
|
||||
public Stream<BlockData> getRegistry() {
|
||||
return Arrays.stream(Material.values()).parallel().filter(Material::isBlock).map(Material::createBlockData);
|
||||
}
|
||||
|
||||
@Override
|
||||
public NSKey getKey(BlockData nativeType) {
|
||||
return IrisBukkit.getInstance().getNamespaceTransformer().toIris(nativeType.getMaterial().getKey());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTypeName() {
|
||||
return "Biome";
|
||||
}
|
||||
|
||||
@Override
|
||||
public IrisBlock toIris(BlockData blockData) {
|
||||
PlatformTransformer<NamespacedKey, NSKey> transformer = IrisBukkit.getInstance().getNamespaceTransformer();
|
||||
|
||||
String s = blockData.getAsString(true);
|
||||
|
||||
if(s.contains("["))
|
||||
{
|
||||
Map<String, String> properties = new HashMap<>();
|
||||
String[] props = new String[]{s.split("\\Q[\\E")[1].split("\\Q]\\E")[0]};
|
||||
String[] p;
|
||||
if(props[0].contains(","))
|
||||
{
|
||||
for(String i : props[0].split("\\Q,\\E"))
|
||||
{
|
||||
p = i.split("\\Q=\\E");
|
||||
properties.put(p[0], p[1]);
|
||||
}
|
||||
}
|
||||
|
||||
else {
|
||||
p = props[0].split("\\Q=\\E");
|
||||
properties.put(p[0], p[1]);
|
||||
}
|
||||
|
||||
return new IrisBlock(transformer.toIris(blockData.getMaterial().getKey()), properties);
|
||||
}
|
||||
|
||||
else {
|
||||
return new IrisBlock(transformer.toIris(blockData.getMaterial().getKey()));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockData toNative(IrisBlock irisBlock) {
|
||||
return Bukkit.createBlockData(irisBlock.toString());
|
||||
}
|
||||
}
|
@ -1,17 +0,0 @@
|
||||
package com.volmit.iris.platform.bukkit.transformers;
|
||||
|
||||
import com.volmit.iris.engine.object.NSKey;
|
||||
import com.volmit.iris.platform.PlatformTransformer;
|
||||
import org.bukkit.NamespacedKey;
|
||||
|
||||
public class BukkitNamespaceTransformer implements PlatformTransformer<NamespacedKey, NSKey> {
|
||||
@Override
|
||||
public NSKey toIris(NamespacedKey namespacedKey) {
|
||||
return new NSKey(namespacedKey.toString());
|
||||
}
|
||||
|
||||
@Override
|
||||
public NamespacedKey toNative(NSKey nsKey) {
|
||||
return new NamespacedKey(nsKey.getNamespace(), nsKey.getKey());
|
||||
}
|
||||
}
|
@ -0,0 +1,24 @@
|
||||
package com.volmit.iris.platform.bukkit.wrapper;
|
||||
|
||||
import com.volmit.iris.platform.PlatformBiome;
|
||||
import com.volmit.iris.platform.PlatformNamespaceKey;
|
||||
import lombok.Data;
|
||||
import org.bukkit.block.Biome;
|
||||
|
||||
@Data
|
||||
public class BukkitBiome implements PlatformBiome {
|
||||
private final Biome delegate;
|
||||
|
||||
private BukkitBiome(Biome delegate) {
|
||||
this.delegate = delegate;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PlatformNamespaceKey getKey() {
|
||||
return delegate.getKey().bukkitKey();
|
||||
}
|
||||
|
||||
public static BukkitBiome of(Biome biome) {
|
||||
return new BukkitBiome(biome);
|
||||
}
|
||||
}
|
@ -0,0 +1,69 @@
|
||||
package com.volmit.iris.platform.bukkit.wrapper;
|
||||
|
||||
import com.volmit.iris.platform.PlatformBlock;
|
||||
import com.volmit.iris.platform.PlatformNamespaceKey;
|
||||
import lombok.Data;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.data.BlockData;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@Data
|
||||
public class BukkitBlock implements PlatformBlock {
|
||||
private final BlockData delegate;
|
||||
private final Map<String, String> properties;
|
||||
|
||||
private BukkitBlock(BlockData delegate, Map<String, String> properties) {
|
||||
this.delegate = delegate;
|
||||
this.properties = properties;
|
||||
}
|
||||
|
||||
private BukkitBlock(BlockData delegate) {
|
||||
this.delegate = delegate;
|
||||
String s = delegate.getAsString(true);
|
||||
|
||||
if(s.contains("[")) {
|
||||
Map<String, String> properties = new HashMap<>();
|
||||
String[] props = new String[] {s.split("\\Q[\\E")[1].split("\\Q]\\E")[0]};
|
||||
String[] p;
|
||||
if(props[0].contains(",")) {
|
||||
for(String i : props[0].split("\\Q,\\E")) {
|
||||
p = i.split("\\Q=\\E");
|
||||
properties.put(p[0], p[1]);
|
||||
}
|
||||
} else {
|
||||
p = props[0].split("\\Q=\\E");
|
||||
properties.put(p[0], p[1]);
|
||||
}
|
||||
|
||||
this.properties = Collections.unmodifiableMap(properties);
|
||||
} else {
|
||||
this.properties = Map.of();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, String> getProperties() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PlatformNamespaceKey getKey() {
|
||||
return delegate.getMaterial().getKey().bukkitKey();
|
||||
}
|
||||
|
||||
public static BukkitBlock of(BlockData blockData) {
|
||||
return new BukkitBlock(blockData);
|
||||
}
|
||||
|
||||
public static BukkitBlock of(Material material) {
|
||||
return of(material.createBlockData());
|
||||
}
|
||||
|
||||
public static BukkitBlock of(String raw) {
|
||||
return of(Bukkit.createBlockData(raw));
|
||||
}
|
||||
}
|
@ -0,0 +1,35 @@
|
||||
package com.volmit.iris.platform.bukkit.wrapper;
|
||||
|
||||
import com.volmit.iris.platform.PlatformChunk;
|
||||
import org.bukkit.Chunk;
|
||||
|
||||
public class BukkitChunk implements PlatformChunk {
|
||||
private final Chunk delegate;
|
||||
|
||||
private BukkitChunk(Chunk delegate) {
|
||||
this.delegate = delegate;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getX() {
|
||||
return delegate.getX();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getZ() {
|
||||
return delegate.getZ();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unload(boolean save, boolean force) {
|
||||
if(force) {
|
||||
delegate.getPluginChunkTickets().forEach(delegate::removePluginChunkTicket);
|
||||
}
|
||||
|
||||
delegate.unload(save);
|
||||
}
|
||||
|
||||
public static BukkitChunk of(Chunk chunk) {
|
||||
return new BukkitChunk(chunk);
|
||||
}
|
||||
}
|
@ -0,0 +1,45 @@
|
||||
package com.volmit.iris.platform.bukkit.wrapper;
|
||||
|
||||
import com.volmit.iris.platform.PlatformNamespaceKey;
|
||||
import lombok.Data;
|
||||
import org.bukkit.NamespacedKey;
|
||||
|
||||
@Data
|
||||
public class BukkitKey implements PlatformNamespaceKey {
|
||||
private final NamespacedKey delegate;
|
||||
|
||||
private BukkitKey(NamespacedKey delegate) {
|
||||
this.delegate = delegate;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getNamespace() {
|
||||
return delegate.getNamespace();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getKey() {
|
||||
return delegate.getKey();
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return delegate.toString();
|
||||
}
|
||||
|
||||
public static BukkitKey of(String nsk) {
|
||||
if(nsk.contains(":")) {
|
||||
String[] f = nsk.split("\\Q:\\E");
|
||||
return of(f[0], f[1]);
|
||||
}
|
||||
|
||||
return of("minecraft", nsk);
|
||||
}
|
||||
|
||||
public static BukkitKey of(String namespace, String key) {
|
||||
return of(new NamespacedKey(namespace, key));
|
||||
}
|
||||
|
||||
public static BukkitKey of(NamespacedKey key) {
|
||||
return new BukkitKey(key);
|
||||
}
|
||||
}
|
@ -0,0 +1,60 @@
|
||||
package com.volmit.iris.platform.bukkit.wrapper;
|
||||
|
||||
import art.arcane.amulet.geometry.Vec;
|
||||
import com.volmit.iris.platform.PlatformPlayer;
|
||||
import com.volmit.iris.platform.PlatformWorld;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
public class BukkitPlayer implements PlatformPlayer {
|
||||
private final Player delegate;
|
||||
|
||||
private BukkitPlayer(Player delegate) {
|
||||
this.delegate = delegate;
|
||||
}
|
||||
|
||||
@Override
|
||||
public UUID getUUID() {
|
||||
return delegate.getUniqueId();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return delegate.getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Vec getLocation() {
|
||||
return delegate.getLocation().vec();
|
||||
}
|
||||
|
||||
@Override
|
||||
public PlatformWorld getWorld() {
|
||||
return delegate.getWorld().bukkitWorld();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canUseIris() {
|
||||
return delegate.isOp();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendMessage(String message) {
|
||||
delegate.sendMessage(message);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendActionBar(String message) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendTitleMessage(String title, String subtitle, int in, int stay, int out) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
public static BukkitPlayer of(Player player) {
|
||||
return new BukkitPlayer(player);
|
||||
}
|
||||
}
|
@ -0,0 +1,90 @@
|
||||
package com.volmit.iris.platform.bukkit.wrapper;
|
||||
|
||||
import com.volmit.iris.platform.PlatformBiome;
|
||||
import com.volmit.iris.platform.PlatformBlock;
|
||||
import com.volmit.iris.platform.PlatformChunk;
|
||||
import com.volmit.iris.platform.PlatformPlayer;
|
||||
import com.volmit.iris.platform.PlatformWorld;
|
||||
import com.volmit.iris.util.WorldHeight;
|
||||
import lombok.Data;
|
||||
import org.bukkit.World;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Data
|
||||
public class BukkitWorld implements PlatformWorld {
|
||||
private final World delegate;
|
||||
private final WorldHeight worldHeight;
|
||||
|
||||
private BukkitWorld(World delegate) {
|
||||
this.delegate = delegate;
|
||||
this.worldHeight = new WorldHeight(delegate.getMinHeight(), delegate.getMaxHeight());
|
||||
}
|
||||
|
||||
@Override
|
||||
public WorldHeight getHeight() {
|
||||
return worldHeight;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return delegate.getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public File getFolder() {
|
||||
return delegate.getWorldFolder();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterable<PlatformPlayer> getPlayers() {
|
||||
//noinspection Convert2MethodRef
|
||||
return delegate.getPlayers().stream().map(i -> i.bukkitPlayer()).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterable<PlatformChunk> getLoadedChunks() {
|
||||
//noinspection Convert2MethodRef
|
||||
return delegate.getLoadedChunks().stream().map(i -> i.bukkitChunk()).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@Override
|
||||
public PlatformChunk getOrLoadChunk(int x, int z) {
|
||||
return delegate.getChunkAt(x, z).bukkitChunk();
|
||||
}
|
||||
|
||||
@Override
|
||||
public PlatformBlock getBlock(int x, int y, int z) {
|
||||
return delegate.getBlockAt(x, y, z).getBlockData().bukkitBlock();
|
||||
}
|
||||
|
||||
@Override
|
||||
public PlatformBiome getBiome(int x, int y, int z) {
|
||||
return delegate.getBiome(x, y, z).bukkitBiome();
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getSeed() {
|
||||
return delegate.getSeed();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isChunkLoaded(int x, int z) {
|
||||
return delegate.isChunkLoaded(x, z);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setBlock(int x, int y, int z, PlatformBlock block) {
|
||||
delegate.setBlockData(x, y, z, ((BukkitBlock) block).getDelegate());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setBiome(int x, int y, int z, PlatformBiome biome) {
|
||||
delegate.setBiome(x, y, z, ((BukkitBiome) biome).getDelegate());
|
||||
}
|
||||
|
||||
public static BukkitWorld of(World world) {
|
||||
return new BukkitWorld(world);
|
||||
}
|
||||
}
|
14
src/main/java/com/volmit/iris/engine/EngineRegistry.java
Normal file
14
src/main/java/com/volmit/iris/engine/EngineRegistry.java
Normal file
@ -0,0 +1,14 @@
|
||||
package com.volmit.iris.engine;
|
||||
|
||||
import com.volmit.iris.platform.PlatformBiome;
|
||||
import com.volmit.iris.platform.PlatformBlock;
|
||||
import com.volmit.iris.platform.PlatformRegistry;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
|
||||
@Builder
|
||||
@Data
|
||||
public class EngineRegistry {
|
||||
private final PlatformRegistry<PlatformBlock> blockRegistry;
|
||||
private final PlatformRegistry<PlatformBiome> biomeRegistry;
|
||||
}
|
@ -1,23 +1,21 @@
|
||||
package com.volmit.iris.engine;
|
||||
|
||||
import com.volmit.iris.engine.registry.EngineRegistry;
|
||||
import com.volmit.iris.engine.registry.PlatformRegistry;
|
||||
import com.volmit.iris.platform.IrisPlatform;
|
||||
import com.volmit.iris.platform.PlatformRegistry;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class IrisEngine<NS, BLOCK, BIOME> {
|
||||
private IrisPlatform<NS, BLOCK, BIOME> platform;
|
||||
private EngineRegistry<BLOCK, BIOME> registry;
|
||||
public class IrisEngine {
|
||||
private IrisPlatform platform;
|
||||
private EngineRegistry registry;
|
||||
private EngineConfiguration configuration;
|
||||
|
||||
public IrisEngine(IrisPlatform<NS, BLOCK, BIOME> platform, EngineConfiguration configuration)
|
||||
{
|
||||
public IrisEngine(IrisPlatform platform, EngineConfiguration configuration) {
|
||||
this.configuration = configuration;
|
||||
this.platform = platform;
|
||||
this.registry = EngineRegistry.<BLOCK, BIOME>builder()
|
||||
.blockRegistry(new PlatformRegistry<>(getPlatform().getBlockDataTransformer()))
|
||||
.biomeRegistry(new PlatformRegistry<>(getPlatform().getBiomeTransformer()))
|
||||
this.registry = EngineRegistry.builder()
|
||||
.blockRegistry(new PlatformRegistry<>(platform.getBlocks()))
|
||||
.biomeRegistry(new PlatformRegistry<>(platform.getBiomes()))
|
||||
.build();
|
||||
}
|
||||
}
|
||||
|
@ -1,53 +0,0 @@
|
||||
package com.volmit.iris.engine.object;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
|
||||
@Builder
|
||||
@Data
|
||||
public class NSKey
|
||||
{
|
||||
private final String key;
|
||||
|
||||
/**
|
||||
* accepts dirt as minecraft:dirt
|
||||
* accepts somemod:ground as somemod:ground
|
||||
* @param key the key
|
||||
*/
|
||||
public NSKey(String key)
|
||||
{
|
||||
this(key.contains(":") ? key.split("\\Q:\\E")[0] : "minecraft", key.contains(":") ? key.split("\\Q:\\E")[1] : key);
|
||||
}
|
||||
|
||||
public NSKey(String namespace, String key)
|
||||
{
|
||||
this.key = namespace + ":" + key;
|
||||
}
|
||||
|
||||
public String getNamespace()
|
||||
{
|
||||
return key.split("\\Q:\\E")[0];
|
||||
}
|
||||
|
||||
public String getKey()
|
||||
{
|
||||
return key.split("\\Q:\\E")[1];
|
||||
}
|
||||
|
||||
public NSKey withKey(String key)
|
||||
{
|
||||
return new NSKey(getNamespace(), key);
|
||||
}
|
||||
|
||||
public NSKey withNamespace(String namespace)
|
||||
{
|
||||
return new NSKey(namespace, getKey());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
return key;
|
||||
}
|
||||
}
|
@ -1,5 +0,0 @@
|
||||
package com.volmit.iris.engine.object;
|
||||
|
||||
public interface Namespaced {
|
||||
NSKey getKey();
|
||||
}
|
@ -1,20 +0,0 @@
|
||||
package com.volmit.iris.engine.object.biome;
|
||||
|
||||
import com.volmit.iris.engine.object.Namespaced;
|
||||
import com.volmit.iris.engine.object.NSKey;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class NativeBiome implements Namespaced {
|
||||
private final NSKey key;
|
||||
|
||||
public NativeBiome(NSKey key)
|
||||
{
|
||||
this.key = key;
|
||||
}
|
||||
|
||||
public String toString()
|
||||
{
|
||||
return key.toString();
|
||||
}
|
||||
}
|
@ -1,45 +0,0 @@
|
||||
package com.volmit.iris.engine.object.block;
|
||||
|
||||
import com.volmit.iris.engine.object.Namespaced;
|
||||
import com.volmit.iris.engine.object.NSKey;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@Data
|
||||
public class IrisBlock implements Namespaced {
|
||||
private static final Map<String, String> EMPTY_PROPERTIES = Map.of();
|
||||
private final NSKey key;
|
||||
private final Map<String, String> properties;
|
||||
|
||||
public IrisBlock(NSKey key, Map<String, String> properties)
|
||||
{
|
||||
this.key = key;
|
||||
this.properties = Collections.unmodifiableMap(properties);
|
||||
}
|
||||
|
||||
public IrisBlock(NSKey key)
|
||||
{
|
||||
this(key, EMPTY_PROPERTIES);
|
||||
}
|
||||
|
||||
public IrisBlock property(String key, String value) {
|
||||
Map<String, String> map = new HashMap<>(getProperties());
|
||||
map.put(key, value);
|
||||
return new IrisBlock(getKey(), map);
|
||||
}
|
||||
|
||||
public String toString()
|
||||
{
|
||||
StringBuilder sb = new StringBuilder();
|
||||
|
||||
for(String i : getProperties().keySet())
|
||||
{
|
||||
sb.append(",").append(i).append("=").append(getProperties().get(i));
|
||||
}
|
||||
|
||||
return sb.append(getKey()).append("[") + sb.append("]").substring(1);
|
||||
}
|
||||
}
|
@ -1,6 +0,0 @@
|
||||
package com.volmit.iris.engine.object.world;
|
||||
|
||||
public class IrisWorld
|
||||
{
|
||||
|
||||
}
|
@ -1,13 +0,0 @@
|
||||
package com.volmit.iris.engine.registry;
|
||||
|
||||
import com.volmit.iris.engine.object.biome.NativeBiome;
|
||||
import com.volmit.iris.engine.object.block.IrisBlock;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
|
||||
@Builder
|
||||
@Data
|
||||
public class EngineRegistry<BLOCK, BIOME> {
|
||||
private final PlatformRegistry<BLOCK, IrisBlock> blockRegistry;
|
||||
private final PlatformRegistry<BIOME, NativeBiome> biomeRegistry;
|
||||
}
|
@ -1,43 +0,0 @@
|
||||
package com.volmit.iris.engine.registry;
|
||||
|
||||
import art.arcane.amulet.collections.Biset;
|
||||
import art.arcane.amulet.collections.ObjectBiset;
|
||||
import com.volmit.iris.engine.object.Namespaced;
|
||||
import com.volmit.iris.engine.object.NSKey;
|
||||
import com.volmit.iris.platform.PlatformDataTransformer;
|
||||
import lombok.Data;
|
||||
import lombok.Getter;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
|
||||
public class PlatformRegistry<NATIVE, T extends Namespaced> {
|
||||
@Getter
|
||||
private final PlatformDataTransformer<NATIVE, T> transformer;
|
||||
private final Map<NSKey, RegistryValue<NATIVE, T>> registry;
|
||||
|
||||
public PlatformRegistry(PlatformDataTransformer<NATIVE, T> transformer)
|
||||
{
|
||||
this.transformer = transformer;
|
||||
registry = transformer.getRegistry().collect(Collectors.toMap(transformer::getKey, (t) -> new RegistryValue<>(t, transformer.toIris(t))));
|
||||
d("Registered " + transformer.countSuffixName(registry.size()));
|
||||
}
|
||||
|
||||
public NATIVE getNative(NSKey key) {
|
||||
return registry.get(key).getNativeValue();
|
||||
}
|
||||
|
||||
public T get(NSKey key) {
|
||||
return registry.get(key).getValue();
|
||||
}
|
||||
|
||||
public Set<NSKey> getKeys() {
|
||||
return Collections.unmodifiableSet(registry.keySet());
|
||||
}
|
||||
}
|
@ -1,9 +0,0 @@
|
||||
package com.volmit.iris.engine.registry;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class RegistryValue<NATIVE, T> {
|
||||
private final NATIVE nativeValue;
|
||||
private final T value;
|
||||
}
|
@ -1,15 +1,15 @@
|
||||
package com.volmit.iris.platform;
|
||||
|
||||
import com.volmit.iris.engine.object.NSKey;
|
||||
import com.volmit.iris.engine.object.biome.NativeBiome;
|
||||
import com.volmit.iris.engine.object.block.IrisBlock;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public interface IrisPlatform<NS, BLOCK, BIOME> {
|
||||
public interface IrisPlatform {
|
||||
String getPlatformName();
|
||||
|
||||
PlatformTransformer<NS, NSKey> getNamespaceTransformer();
|
||||
Stream<PlatformBlock> getBlocks();
|
||||
|
||||
PlatformDataTransformer<BLOCK, IrisBlock> getBlockDataTransformer();
|
||||
Stream<PlatformBiome> getBiomes();
|
||||
|
||||
PlatformDataTransformer<BIOME, NativeBiome> getBiomeTransformer();
|
||||
boolean isWorldLoaded(String name);
|
||||
|
||||
PlatformWorld getWorld(String name);
|
||||
}
|
||||
|
@ -0,0 +1,5 @@
|
||||
package com.volmit.iris.platform;
|
||||
|
||||
public interface PlatformBiome extends PlatformNamespaced {
|
||||
|
||||
}
|
@ -0,0 +1,7 @@
|
||||
package com.volmit.iris.platform;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public interface PlatformBlock extends PlatformNamespaced {
|
||||
Map<String, String> getProperties();
|
||||
}
|
@ -0,0 +1,9 @@
|
||||
package com.volmit.iris.platform;
|
||||
|
||||
public interface PlatformChunk {
|
||||
int getX();
|
||||
|
||||
int getZ();
|
||||
|
||||
void unload(boolean save, boolean force);
|
||||
}
|
@ -1,29 +0,0 @@
|
||||
package com.volmit.iris.platform;
|
||||
|
||||
import com.volmit.iris.engine.object.Namespaced;
|
||||
import com.volmit.iris.engine.object.NSKey;
|
||||
|
||||
import java.text.Normalizer;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public interface PlatformDataTransformer<NATIVE, T extends Namespaced> extends PlatformTransformer<NATIVE, T> {
|
||||
default Stream<NSKey> getRegistryKeys() {
|
||||
return getRegistry().map(this::getKey);
|
||||
}
|
||||
|
||||
Stream<NATIVE> getRegistry();
|
||||
|
||||
NSKey getKey(NATIVE nativeType);
|
||||
|
||||
String getTypeName();
|
||||
|
||||
default String getTypeNamePlural()
|
||||
{
|
||||
return getTypeName() + "s";
|
||||
}
|
||||
|
||||
default String countSuffixName(int count)
|
||||
{
|
||||
return count + " " + (count == 1 ? getTypeName() : getTypeNamePlural());
|
||||
}
|
||||
}
|
@ -0,0 +1,9 @@
|
||||
package com.volmit.iris.platform;
|
||||
|
||||
public interface PlatformNamespaceKey {
|
||||
String getNamespace();
|
||||
|
||||
String getKey();
|
||||
|
||||
String toString();
|
||||
}
|
@ -0,0 +1,5 @@
|
||||
package com.volmit.iris.platform;
|
||||
|
||||
public interface PlatformNamespaced {
|
||||
PlatformNamespaceKey getKey();
|
||||
}
|
23
src/main/java/com/volmit/iris/platform/PlatformPlayer.java
Normal file
23
src/main/java/com/volmit/iris/platform/PlatformPlayer.java
Normal file
@ -0,0 +1,23 @@
|
||||
package com.volmit.iris.platform;
|
||||
|
||||
import art.arcane.amulet.geometry.Vec;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
public interface PlatformPlayer {
|
||||
UUID getUUID();
|
||||
|
||||
String getName();
|
||||
|
||||
Vec getLocation();
|
||||
|
||||
PlatformWorld getWorld();
|
||||
|
||||
boolean canUseIris();
|
||||
|
||||
void sendMessage(String message);
|
||||
|
||||
void sendActionBar(String message);
|
||||
|
||||
void sendTitleMessage(String title, String subtitle, int in, int stay, int out);
|
||||
}
|
24
src/main/java/com/volmit/iris/platform/PlatformRegistry.java
Normal file
24
src/main/java/com/volmit/iris/platform/PlatformRegistry.java
Normal file
@ -0,0 +1,24 @@
|
||||
package com.volmit.iris.platform;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
|
||||
public class PlatformRegistry<T extends PlatformNamespaced> {
|
||||
private final Map<PlatformNamespaceKey, T> registry;
|
||||
|
||||
public PlatformRegistry(Stream<T> stream) {
|
||||
registry = Collections.unmodifiableMap(stream.collect(Collectors.toMap(PlatformNamespaced::getKey, (t) -> t)));
|
||||
}
|
||||
|
||||
public T get(PlatformNamespaceKey key) {
|
||||
return registry.get(key);
|
||||
}
|
||||
|
||||
public Set<PlatformNamespaceKey> getKeys() {
|
||||
return Collections.unmodifiableSet(registry.keySet());
|
||||
}
|
||||
}
|
@ -1,7 +0,0 @@
|
||||
package com.volmit.iris.platform;
|
||||
|
||||
public interface PlatformTransformer<NATIVE, T> {
|
||||
T toIris(NATIVE nativeType);
|
||||
|
||||
NATIVE toNative(T t);
|
||||
}
|
59
src/main/java/com/volmit/iris/platform/PlatformWorld.java
Normal file
59
src/main/java/com/volmit/iris/platform/PlatformWorld.java
Normal file
@ -0,0 +1,59 @@
|
||||
package com.volmit.iris.platform;
|
||||
|
||||
import com.volmit.iris.util.WorldHeight;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
public interface PlatformWorld {
|
||||
WorldHeight getHeight();
|
||||
|
||||
String getName();
|
||||
|
||||
File getFolder();
|
||||
|
||||
Iterable<PlatformPlayer> getPlayers();
|
||||
|
||||
Iterable<PlatformChunk> getLoadedChunks();
|
||||
|
||||
PlatformChunk getOrLoadChunk(int x, int z);
|
||||
|
||||
PlatformBlock getBlock(int x, int y, int z);
|
||||
|
||||
PlatformBiome getBiome(int x, int y, int z);
|
||||
|
||||
long getSeed();
|
||||
|
||||
boolean isChunkLoaded(int x, int z);
|
||||
|
||||
void setBlock(int x, int y, int z, PlatformBlock block);
|
||||
|
||||
void setBiome(int x, int y, int z, PlatformBiome biome);
|
||||
|
||||
default File getWorldFolder(String subfolder) {
|
||||
return new File(getFolder(), subfolder);
|
||||
}
|
||||
|
||||
default File getRegionFolder() {
|
||||
return getWorldFolder("region");
|
||||
}
|
||||
|
||||
default File getIrisFolder() {
|
||||
return getWorldFolder("iris");
|
||||
}
|
||||
|
||||
default boolean isRegionLoaded(int x, int z) {
|
||||
for(PlatformChunk i : getLoadedChunks()) {
|
||||
if(i.getX() >> 5 == x && i.getZ() >> 5 == z) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
default void unloadChunks(boolean save, boolean force) {
|
||||
for(PlatformChunk i : getLoadedChunks()) {
|
||||
i.unload(save, force);
|
||||
}
|
||||
}
|
||||
}
|
19
src/main/java/com/volmit/iris/util/WorldHeight.java
Normal file
19
src/main/java/com/volmit/iris/util/WorldHeight.java
Normal file
@ -0,0 +1,19 @@
|
||||
package com.volmit.iris.util;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
public class WorldHeight {
|
||||
private final int minHeight;
|
||||
private final int maxHeight;
|
||||
|
||||
public WorldHeight(int maxHeight) {
|
||||
this(0, maxHeight);
|
||||
}
|
||||
|
||||
public int getTotalHeight() {
|
||||
return maxHeight - minHeight;
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user