mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2025-12-28 11:39:07 +00:00
Registries
This commit is contained in:
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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user