mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2025-07-18 10:12:53 +00:00
Registries
This commit is contained in:
parent
fc6720e090
commit
5e6838bdc9
@ -7,9 +7,17 @@ version '1.0.0'
|
|||||||
|
|
||||||
repositories {
|
repositories {
|
||||||
mavenCentral()
|
mavenCentral()
|
||||||
|
maven {
|
||||||
|
url 'https://hub.spigotmc.org/nexus/content/repositories/snapshots/'
|
||||||
|
content {
|
||||||
|
includeGroup 'org.spigotmc'
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
|
implementation rootProject
|
||||||
|
implementation 'org.spigotmc:spigot-api:1.17.1-R0.1-SNAPSHOT'
|
||||||
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.7.0'
|
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.7.0'
|
||||||
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.7.0'
|
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.7.0'
|
||||||
}
|
}
|
||||||
|
@ -18,7 +18,98 @@
|
|||||||
|
|
||||||
package com.volmit.iris.api;
|
package com.volmit.iris.api;
|
||||||
|
|
||||||
public interface IrisAPI
|
import com.volmit.iris.Iris;
|
||||||
{
|
import com.volmit.iris.core.service.RegistrySVC;
|
||||||
|
import com.volmit.iris.core.tools.IrisToolbelt;
|
||||||
|
import com.volmit.iris.engine.data.cache.AtomicCache;
|
||||||
|
import com.volmit.iris.util.plugin.PluginRegistryGroup;
|
||||||
|
import org.bukkit.World;
|
||||||
|
import org.bukkit.block.data.BlockData;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.function.Supplier;
|
||||||
|
|
||||||
|
public class IrisAPI
|
||||||
|
{
|
||||||
|
private static final AtomicCache<RegistryHolder<BlockData>> customBlock = new AtomicCache<>();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks if the given world is an Iris World
|
||||||
|
*
|
||||||
|
* @param world the world
|
||||||
|
* @return true if it is an Iris world
|
||||||
|
*/
|
||||||
|
public static boolean isIrisWorld(World world) {
|
||||||
|
return IrisToolbelt.isIrisWorld(world);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks if the given world is an Iris World with studio mode
|
||||||
|
* @param world the world
|
||||||
|
* @return true if it is an Iris World & is in Studio Mode
|
||||||
|
*/
|
||||||
|
public static boolean isIrisStudioWorld(World world) {
|
||||||
|
return IrisToolbelt.isIrisStudioWorld(world);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Used for registering ids into custom blocks
|
||||||
|
* @return the registry
|
||||||
|
*/
|
||||||
|
public static RegistryHolder<BlockData> getCustomBlockRegistry()
|
||||||
|
{
|
||||||
|
return customBlock.aquire(RegistryHolder::new);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class RegistryHolder<T>
|
||||||
|
{
|
||||||
|
private Supplier<PluginRegistryGroup<T>> registry;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Unregister a node
|
||||||
|
* @param namespace the namespace (your plugin id or something)
|
||||||
|
* @param id the identifier for the node
|
||||||
|
*/
|
||||||
|
public void unregister(String namespace, String id)
|
||||||
|
{
|
||||||
|
Iris.service(RegistrySVC.class).getCustomBlockRegistry()
|
||||||
|
.getRegistry(namespace).unregister(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Unregister all nodes by namespace
|
||||||
|
* @param namespace the namespace (such as your plugin)
|
||||||
|
*/
|
||||||
|
public void unregisterAll(String namespace)
|
||||||
|
{
|
||||||
|
Iris.service(RegistrySVC.class).getCustomBlockRegistry()
|
||||||
|
.getRegistry(namespace).unregisterAll();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Register a node under a namespace & id
|
||||||
|
* such as myplugin:ruby_ore which should resolve to an object that
|
||||||
|
* could be used by the generator.
|
||||||
|
*
|
||||||
|
* @param namespace the namespace (of this plugin) (myplugin)
|
||||||
|
* @param id the identifier for this node (ruby_ore)
|
||||||
|
* @param block the provider for this node data (always return a new instance!)
|
||||||
|
*/
|
||||||
|
public void register(String namespace, String id, Supplier<BlockData> block)
|
||||||
|
{
|
||||||
|
Iris.service(RegistrySVC.class).getCustomBlockRegistry()
|
||||||
|
.getRegistry(namespace).register(id, block);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get all registered nodes under a namespace
|
||||||
|
* @param namespace the namespace such as your plugin
|
||||||
|
* @return the registry list (ids)
|
||||||
|
*/
|
||||||
|
public List<String> getRegsitries(String namespace)
|
||||||
|
{
|
||||||
|
return Iris.service(RegistrySVC.class).getCustomBlockRegistry()
|
||||||
|
.getRegistry(namespace).getRegistries();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -146,7 +146,6 @@ shadowJar {
|
|||||||
include(dependency('io.papermc:paperlib'))
|
include(dependency('io.papermc:paperlib'))
|
||||||
include(dependency('com.dfsek:Paralithic'))
|
include(dependency('com.dfsek:Paralithic'))
|
||||||
include(dependency('net.kyori:'))
|
include(dependency('net.kyori:'))
|
||||||
include(dependency('com.volmit.iris.api:'))
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -182,7 +181,6 @@ dependencies {
|
|||||||
implementation "net.kyori:adventure-text-minimessage:4.2.0-SNAPSHOT"
|
implementation "net.kyori:adventure-text-minimessage:4.2.0-SNAPSHOT"
|
||||||
implementation "net.kyori:adventure-platform-bukkit:4.0.0-SNAPSHOT"
|
implementation "net.kyori:adventure-platform-bukkit:4.0.0-SNAPSHOT"
|
||||||
implementation 'net.kyori:adventure-api:4.9.1'
|
implementation 'net.kyori:adventure-api:4.9.1'
|
||||||
implementation project(":api")
|
|
||||||
|
|
||||||
// Dynamically Loaded
|
// Dynamically Loaded
|
||||||
implementation 'io.timeandspace:smoothie-map:2.0.2'
|
implementation 'io.timeandspace:smoothie-map:2.0.2'
|
||||||
|
39
src/main/java/com/volmit/iris/core/service/RegistrySVC.java
Normal file
39
src/main/java/com/volmit/iris/core/service/RegistrySVC.java
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
/*
|
||||||
|
* 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.core.service;
|
||||||
|
|
||||||
|
import com.volmit.iris.util.plugin.IrisService;
|
||||||
|
import com.volmit.iris.util.plugin.PluginRegistryGroup;
|
||||||
|
import lombok.Data;
|
||||||
|
import org.bukkit.block.data.BlockData;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class RegistrySVC implements IrisService {
|
||||||
|
private PluginRegistryGroup<BlockData> customBlockRegistry;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onEnable() {
|
||||||
|
customBlockRegistry = new PluginRegistryGroup<>();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onDisable() {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,65 @@
|
|||||||
|
/*
|
||||||
|
* 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.plugin;
|
||||||
|
|
||||||
|
import com.volmit.iris.engine.object.annotations.Required;
|
||||||
|
import com.volmit.iris.util.collection.KList;
|
||||||
|
import com.volmit.iris.util.collection.KMap;
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import org.bukkit.plugin.Plugin;
|
||||||
|
|
||||||
|
import java.util.function.Supplier;
|
||||||
|
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
public class PluginRegistry<T> {
|
||||||
|
private final KMap<String, Supplier<T>> registry = new KMap<>();
|
||||||
|
@Getter
|
||||||
|
private final String namespace;
|
||||||
|
|
||||||
|
public void unregisterAll()
|
||||||
|
{
|
||||||
|
registry.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
public KList<String> getRegistries()
|
||||||
|
{
|
||||||
|
return registry.k();
|
||||||
|
}
|
||||||
|
|
||||||
|
public T get(String s)
|
||||||
|
{
|
||||||
|
if(!registry.containsKey(s))
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return registry.get(s).get();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void register(String s, Supplier<T> t)
|
||||||
|
{
|
||||||
|
registry.put(s, t);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void unregister(String s)
|
||||||
|
{
|
||||||
|
registry.remove(s);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,40 @@
|
|||||||
|
/*
|
||||||
|
* 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.plugin;
|
||||||
|
|
||||||
|
import com.volmit.iris.util.collection.KMap;
|
||||||
|
|
||||||
|
public class PluginRegistryGroup<T> {
|
||||||
|
private final KMap<String, PluginRegistry<T>> registries = new KMap<>();
|
||||||
|
|
||||||
|
public void clearRegistries()
|
||||||
|
{
|
||||||
|
registries.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void removeRegistry(String namespace)
|
||||||
|
{
|
||||||
|
registries.remove(namespace);
|
||||||
|
}
|
||||||
|
|
||||||
|
public PluginRegistry<T> getRegistry(String namespace)
|
||||||
|
{
|
||||||
|
return registries.computeIfAbsent(namespace, PluginRegistry::new);
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user