From 2a03b547c7714a130b2bc1407b12a8abd58a9069 Mon Sep 17 00:00:00 2001 From: Luck Date: Sat, 3 Aug 2019 22:04:20 +0100 Subject: Some more reorganising --- .../lucko/spark/forge/ForgeClientSparkPlugin.java | 6 +- .../lucko/spark/forge/ForgeServerSparkPlugin.java | 4 +- .../java/me/lucko/spark/forge/ForgeSparkMod.java | 66 ++++++++++++++++++++++ .../me/lucko/spark/forge/ForgeSparkPlugin.java | 16 +++--- .../java/me/lucko/spark/forge/SparkForgeMod.java | 66 ---------------------- 5 files changed, 79 insertions(+), 79 deletions(-) create mode 100644 spark-forge/src/main/java/me/lucko/spark/forge/ForgeSparkMod.java delete mode 100644 spark-forge/src/main/java/me/lucko/spark/forge/SparkForgeMod.java (limited to 'spark-forge/src/main/java') diff --git a/spark-forge/src/main/java/me/lucko/spark/forge/ForgeClientSparkPlugin.java b/spark-forge/src/main/java/me/lucko/spark/forge/ForgeClientSparkPlugin.java index 5dd2ded..e4212ab 100644 --- a/spark-forge/src/main/java/me/lucko/spark/forge/ForgeClientSparkPlugin.java +++ b/spark-forge/src/main/java/me/lucko/spark/forge/ForgeClientSparkPlugin.java @@ -32,11 +32,11 @@ import java.util.stream.Stream; public class ForgeClientSparkPlugin extends ForgeSparkPlugin { - public static void register(SparkForgeMod mod) { + public static void register(ForgeSparkMod mod) { ClientCommandHandler.instance.registerCommand(new ForgeClientSparkPlugin(mod)); } - public ForgeClientSparkPlugin(SparkForgeMod mod) { + public ForgeClientSparkPlugin(ForgeSparkMod mod) { super(mod); } @@ -56,7 +56,7 @@ public class ForgeClientSparkPlugin extends ForgeSparkPlugin { } @Override - public String getLabel() { + public String getCommandName() { return "sparkc"; } diff --git a/spark-forge/src/main/java/me/lucko/spark/forge/ForgeServerSparkPlugin.java b/spark-forge/src/main/java/me/lucko/spark/forge/ForgeServerSparkPlugin.java index 3c686ae..22b6adc 100644 --- a/spark-forge/src/main/java/me/lucko/spark/forge/ForgeServerSparkPlugin.java +++ b/spark-forge/src/main/java/me/lucko/spark/forge/ForgeServerSparkPlugin.java @@ -31,7 +31,7 @@ import java.util.List; import java.util.stream.Stream; public class ForgeServerSparkPlugin extends ForgeSparkPlugin { - public ForgeServerSparkPlugin(SparkForgeMod mod) { + public ForgeServerSparkPlugin(ForgeSparkMod mod) { super(mod); } @@ -55,7 +55,7 @@ public class ForgeServerSparkPlugin extends ForgeSparkPlugin { } @Override - public String getLabel() { + public String getCommandName() { return "spark"; } diff --git a/spark-forge/src/main/java/me/lucko/spark/forge/ForgeSparkMod.java b/spark-forge/src/main/java/me/lucko/spark/forge/ForgeSparkMod.java new file mode 100644 index 0000000..1659d6d --- /dev/null +++ b/spark-forge/src/main/java/me/lucko/spark/forge/ForgeSparkMod.java @@ -0,0 +1,66 @@ +/* + * This file is part of spark. + * + * Copyright (c) lucko (Luck) + * Copyright (c) contributors + * + * 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 . + */ + +package me.lucko.spark.forge; + +import net.minecraftforge.fml.common.FMLCommonHandler; +import net.minecraftforge.fml.common.Mod; +import net.minecraftforge.fml.common.Mod.EventHandler; +import net.minecraftforge.fml.common.event.FMLInitializationEvent; +import net.minecraftforge.fml.common.event.FMLPreInitializationEvent; +import net.minecraftforge.fml.common.event.FMLServerStartingEvent; +import net.minecraftforge.fml.relauncher.Side; + +import java.nio.file.Path; + +@Mod( + modid = "spark", + name = "spark", + version = "@version@", + acceptableRemoteVersions = "*" +) +public class ForgeSparkMod { + + private Path configDirectory = null; + + @EventHandler + public void preInit(FMLPreInitializationEvent e) { + this.configDirectory = e.getModConfigurationDirectory().toPath(); + } + + @EventHandler + public void init(FMLInitializationEvent e) { + if (FMLCommonHandler.instance().getSide() == Side.CLIENT) { + ForgeClientSparkPlugin.register(this); + } + } + + @EventHandler + public void serverInit(FMLServerStartingEvent e) { + e.registerServerCommand(new ForgeServerSparkPlugin(this)); + } + + public Path getConfigDirectory() { + if (this.configDirectory == null) { + throw new IllegalStateException("Config directory not set"); + } + return this.configDirectory; + } +} diff --git a/spark-forge/src/main/java/me/lucko/spark/forge/ForgeSparkPlugin.java b/spark-forge/src/main/java/me/lucko/spark/forge/ForgeSparkPlugin.java index 039a7de..b2f2332 100644 --- a/spark-forge/src/main/java/me/lucko/spark/forge/ForgeSparkPlugin.java +++ b/spark-forge/src/main/java/me/lucko/spark/forge/ForgeSparkPlugin.java @@ -39,11 +39,11 @@ import java.util.concurrent.ScheduledExecutorService; @SuppressWarnings("NullableProblems") public abstract class ForgeSparkPlugin implements SparkPlugin, ICommand { - private final SparkForgeMod mod; + private final ForgeSparkMod mod; private final ScheduledExecutorService scheduler; private final SparkPlatform platform; - protected ForgeSparkPlugin(SparkForgeMod mod) { + protected ForgeSparkPlugin(ForgeSparkMod mod) { this.mod = mod; this.scheduler = Executors.newSingleThreadScheduledExecutor( new ThreadFactoryBuilder().setNameFormat("spark-forge-async-worker").build() @@ -56,17 +56,17 @@ public abstract class ForgeSparkPlugin implements SparkPlugin, ICommand { @Override public String getVersion() { - return SparkForgeMod.class.getAnnotation(Mod.class).version(); + return ForgeSparkMod.class.getAnnotation(Mod.class).version(); } @Override - public Path getPluginFolder() { + public Path getPluginDirectory() { return this.mod.getConfigDirectory(); } @Override - public void runAsync(Runnable r) { - this.scheduler.execute(r); + public void executeAsync(Runnable task) { + this.scheduler.execute(task); } @Override @@ -78,7 +78,7 @@ public abstract class ForgeSparkPlugin implements SparkPlugin, ICommand { @Override public String getUsage(ICommandSender iCommandSender) { - return "/" + getLabel(); + return "/" + getCommandName(); } @Override @@ -103,6 +103,6 @@ public abstract class ForgeSparkPlugin implements SparkPlugin, ICommand { @Override public int compareTo(ICommand o) { - return getLabel().compareTo(o.getName()); + return getCommandName().compareTo(o.getName()); } } diff --git a/spark-forge/src/main/java/me/lucko/spark/forge/SparkForgeMod.java b/spark-forge/src/main/java/me/lucko/spark/forge/SparkForgeMod.java deleted file mode 100644 index 32dfd77..0000000 --- a/spark-forge/src/main/java/me/lucko/spark/forge/SparkForgeMod.java +++ /dev/null @@ -1,66 +0,0 @@ -/* - * This file is part of spark. - * - * Copyright (c) lucko (Luck) - * Copyright (c) contributors - * - * 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 . - */ - -package me.lucko.spark.forge; - -import net.minecraftforge.fml.common.FMLCommonHandler; -import net.minecraftforge.fml.common.Mod; -import net.minecraftforge.fml.common.Mod.EventHandler; -import net.minecraftforge.fml.common.event.FMLInitializationEvent; -import net.minecraftforge.fml.common.event.FMLPreInitializationEvent; -import net.minecraftforge.fml.common.event.FMLServerStartingEvent; -import net.minecraftforge.fml.relauncher.Side; - -import java.nio.file.Path; - -@Mod( - modid = "spark", - name = "spark", - version = "@version@", - acceptableRemoteVersions = "*" -) -public class SparkForgeMod { - - private Path configDirectory = null; - - @EventHandler - public void preInit(FMLPreInitializationEvent e) { - this.configDirectory = e.getModConfigurationDirectory().toPath(); - } - - @EventHandler - public void init(FMLInitializationEvent e) { - if (FMLCommonHandler.instance().getSide() == Side.CLIENT) { - ForgeClientSparkPlugin.register(this); - } - } - - @EventHandler - public void serverInit(FMLServerStartingEvent e) { - e.registerServerCommand(new ForgeServerSparkPlugin(this)); - } - - public Path getConfigDirectory() { - if (this.configDirectory == null) { - throw new IllegalStateException("Config directory not set"); - } - return this.configDirectory; - } -} -- cgit