Service Facade

This commit is contained in:
Brian Neumann-Fopiano
2026-06-12 02:45:18 -04:00
parent b584cb4193
commit b5d08b6203
22 changed files with 163 additions and 63 deletions
@@ -40,6 +40,15 @@ public final class IrisLogging {
emit(LogLevel.ERROR, safeFormat(format, args));
}
public static void msg(String message) {
if (IrisPlatforms.isBound()) {
IrisPlatforms.get().msg(message);
return;
}
System.out.println("[Iris] " + message);
}
public static void reportError(Throwable error) {
if (IrisPlatforms.isBound()) {
IrisPlatforms.get().reportError(error);
@@ -40,9 +40,21 @@ public interface IrisPlatform {
File dataFolder();
File dataFile(String... path);
File pluginJar();
int irisVersionNumber();
int minecraftVersionNumber();
void callEvent(Object event);
void dispatchConsoleCommand(String command);
void log(LogLevel level, String message);
void msg(String message);
void reportError(Throwable error);
}
@@ -0,0 +1,44 @@
/*
* Iris is a World Generator for Minecraft Bukkit Servers
* Copyright (c) 2026 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 art.arcane.iris.spi;
import java.util.concurrent.ConcurrentHashMap;
public final class IrisServices {
private static final ConcurrentHashMap<Class<?>, Object> SERVICES = new ConcurrentHashMap<>();
private IrisServices() {
}
public static void register(Class<?> type, Object implementation) {
SERVICES.put(type, type.cast(implementation));
}
public static <T> T get(Class<T> type) {
Object implementation = SERVICES.get(type);
if (implementation == null) {
throw new IllegalStateException("No Iris service registered for " + type.getName());
}
return type.cast(implementation);
}
public static void clear() {
SERVICES.clear();
}
}