9
0
mirror of https://github.com/VolmitSoftware/Iris.git synced 2025-12-27 19:19:07 +00:00

Registries

This commit is contained in:
cyberpwn
2021-09-09 07:47:42 -04:00
parent fc6720e090
commit 5e6838bdc9
6 changed files with 245 additions and 4 deletions

View File

@@ -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);
}
}

View File

@@ -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);
}
}