Matter apis

This commit is contained in:
Daniel Mills 2021-08-04 20:19:22 -04:00
parent f2b301cb17
commit ad324df937
11 changed files with 191 additions and 0 deletions

View File

@ -33,6 +33,8 @@ import com.volmit.iris.engine.object.biome.IrisBiome;
import com.volmit.iris.engine.object.biome.IrisBiomeCustom;
import com.volmit.iris.engine.object.compat.IrisCompat;
import com.volmit.iris.engine.object.dimensional.IrisDimension;
import com.volmit.iris.util.io.JarScanner;
import com.volmit.iris.util.matter.Sliced;
import com.volmit.iris.util.parallel.MultiBurst;
import com.volmit.iris.util.collection.KList;
import com.volmit.iris.util.collection.KSet;
@ -64,6 +66,8 @@ import org.bukkit.generator.ChunkGenerator;
import org.bukkit.plugin.Plugin;
import java.io.*;
import java.lang.annotation.Annotation;
import java.lang.reflect.InvocationTargetException;
import java.net.URL;
import java.util.Date;
@ -100,6 +104,25 @@ public class Iris extends VolmitPlugin implements Listener {
J.s(() -> Bukkit.getPluginManager().callEvent(e));
}
public static KList<Object> initialize(String s, Class<? extends Annotation> slicedClass) {
JarScanner js = new JarScanner(instance.getJarFile(), s);
KList<Object> v = new KList<>();
J.attempt(js::scan);
for(Class<?> i : js.getClasses())
{
if(slicedClass == null || i.isAnnotationPresent(slicedClass))
{
try {
v.add(i.getDeclaredConstructor().newInstance());
} catch (Throwable ignored) {
}
}
}
return v;
}
public void onEnable() {
instance = this;

View File

@ -0,0 +1,79 @@
/*
* 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 <https://www.gnu.org/licenses/>.
*/
package com.volmit.iris.util.matter;
import com.volmit.iris.Iris;
import com.volmit.iris.util.collection.KMap;
import com.volmit.iris.util.io.JarScanner;
import com.volmit.iris.util.matter.slices.BlockMatter;
import com.volmit.iris.util.matter.slices.BooleanMatter;
import lombok.Getter;
import org.bukkit.block.data.BlockData;
import java.util.Map;
public class IrisMatter implements Matter{
private static final KMap<Class<?>, MatterSlice<?>> slicers = buildSlicers();
@Getter
private final MatterHeader header;
@Getter
private final int width;
@Getter
private final int height;
@Getter
private final int depth;
@Getter
private KMap<Class<?>, MatterSlice<?>> sliceMap;
public IrisMatter(int width, int height, int depth)
{
this.width = width;
this.height = height;
this.depth = depth;
this.header = new MatterHeader();
}
@Override
public <T> MatterSlice<T> createSlice(Class<T> type, Matter m) {
MatterSlice<?> slice = slicers.get(type);
if(slice == null)
{
return null;
}
return (MatterSlice<T>) slice;
}
private static KMap<Class<?>, MatterSlice<?>> buildSlicers() {
KMap<Class<?>, MatterSlice<?>> c = new KMap<>();
for(Object i : Iris.initialize("com.volmit.iris.util.matter.slices", Sliced.class))
{
MatterSlice<?> s = (MatterSlice<?>) i;
c.put(s.getType(), s);
}
return c;
}
}

View File

@ -157,6 +157,23 @@ public interface Matter {
return (MatterSlice<T>) getSliceMap().put(c, slice);
}
default <T> MatterSlice<T> slice(Class<?> c)
{
if(!hasSlice(c))
{
MatterSlice<?> s = createSlice(c, this);
if(s == null)
{
return null;
}
putSlice(c, (MatterSlice<T>) s);
}
return (MatterSlice<T>) getSlice(c);
}
/**
* Check if a slice exists for a given type
* @param c the slice class type

View File

@ -0,0 +1,27 @@
/*
* 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 <https://www.gnu.org/licenses/>.
*/
package com.volmit.iris.util.matter;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
@Retention(RetentionPolicy.RUNTIME)
public @interface Sliced {
}

View File

@ -18,6 +18,7 @@
package com.volmit.iris.util.matter.slices;
import com.volmit.iris.util.matter.Sliced;
import com.volmit.iris.util.nbt.io.NBTUtil;
import com.volmit.iris.util.nbt.mca.NBTWorld;
import com.volmit.iris.util.nbt.tag.CompoundTag;
@ -27,8 +28,14 @@ import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
@Sliced
public class BlockMatter extends RawMatter<BlockData>
{
public BlockMatter()
{
this(1,1,1);
}
public BlockMatter(int width, int height, int depth) {
super(width, height, depth, BlockData.class);
}

View File

@ -18,12 +18,20 @@
package com.volmit.iris.util.matter.slices;
import com.volmit.iris.util.matter.Sliced;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
@Sliced
public class BooleanMatter extends RawMatter<Boolean>
{
public BooleanMatter()
{
this(1,1,1);
}
public BooleanMatter(int width, int height, int depth) {
super(width, height, depth, Boolean.class);
}

View File

@ -18,10 +18,17 @@
package com.volmit.iris.util.matter.slices;
import com.volmit.iris.util.matter.Sliced;
import com.volmit.iris.util.nbt.tag.CompoundTag;
@Sliced
public class CompoundMatter extends NBTMatter<CompoundTag>
{
public CompoundMatter()
{
this(1,1,1);
}
public CompoundMatter(int width, int height, int depth) {
super(width, height, depth, CompoundTag.class);
}

View File

@ -19,13 +19,19 @@
package com.volmit.iris.util.matter.slices;
import com.volmit.iris.util.data.Varint;
import com.volmit.iris.util.matter.Sliced;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
@Sliced
public class IntMatter extends RawMatter<Integer>
{
public IntMatter()
{
this(1,1,1);
}
public IntMatter(int width, int height, int depth) {
super(width, height, depth, Integer.class);
}

View File

@ -19,13 +19,19 @@
package com.volmit.iris.util.matter.slices;
import com.volmit.iris.util.data.Varint;
import com.volmit.iris.util.matter.Sliced;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
@Sliced
public class LongMatter extends RawMatter<Long>
{
public LongMatter()
{
this(1,1,1);
}
public LongMatter(int width, int height, int depth) {
super(width, height, depth, Long.class);
}

View File

@ -19,13 +19,19 @@
package com.volmit.iris.util.matter.slices;
import com.volmit.iris.util.matter.MatterSlice;
import com.volmit.iris.util.matter.Sliced;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
@Sliced
public class StringMatter extends RawMatter<String>
{
public StringMatter()
{
this(1,1,1);
}
public StringMatter(int width, int height, int depth) {
super(width, height, depth, String.class);
}

View File

@ -152,6 +152,11 @@ public abstract class VolmitPlugin extends JavaPlugin implements Listener {
}).start();
}
public File getJarFile()
{
return getFile();
}
public void l(Object l) {
Iris.info("[" + getName() + "]: " + l);
}