diff options
Diffstat (limited to 'spark-forge1122/src/main')
9 files changed, 0 insertions, 685 deletions
diff --git a/spark-forge1122/src/main/java/me/lucko/spark/forge/Forge1122CommandSender.java b/spark-forge1122/src/main/java/me/lucko/spark/forge/Forge1122CommandSender.java deleted file mode 100644 index 7e7d73c..0000000 --- a/spark-forge1122/src/main/java/me/lucko/spark/forge/Forge1122CommandSender.java +++ /dev/null @@ -1,75 +0,0 @@ -/* - * This file is part of spark. - * - * Copyright (c) lucko (Luck) <luck@lucko.me> - * 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 <http://www.gnu.org/licenses/>. - */ - -package me.lucko.spark.forge; - -import me.lucko.spark.common.command.sender.AbstractCommandSender; -import me.lucko.spark.forge.plugin.Forge1122SparkPlugin; - -import net.kyori.adventure.text.Component; -import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer; -import net.minecraft.command.ICommandSender; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.network.rcon.RConConsoleSource; -import net.minecraft.server.MinecraftServer; -import net.minecraft.util.text.ITextComponent; - -import java.util.UUID; - -public class Forge1122CommandSender extends AbstractCommandSender<ICommandSender> { - private final Forge1122SparkPlugin plugin; - - public Forge1122CommandSender(ICommandSender source, Forge1122SparkPlugin plugin) { - super(source); - this.plugin = plugin; - } - - @Override - public String getName() { - if (super.delegate instanceof EntityPlayer) { - return ((EntityPlayer) super.delegate).getGameProfile().getName(); - } else if (super.delegate instanceof MinecraftServer) { - return "Console"; - } else if (super.delegate instanceof RConConsoleSource) { - return "RCON Console"; - } else { - return "unknown:" + super.delegate.getClass().getSimpleName(); - } - } - - @Override - public UUID getUniqueId() { - if (super.delegate instanceof EntityPlayer) { - return ((EntityPlayer) super.delegate).getUniqueID(); - } - return null; - } - - @Override - public void sendMessage(Component message) { - ITextComponent component = ITextComponent.Serializer.jsonToComponent(GsonComponentSerializer.gson().serialize(message)); - super.delegate.sendMessage(component); - } - - @Override - public boolean hasPermission(String permission) { - return this.plugin.hasPermission(super.delegate, permission); - } -} diff --git a/spark-forge1122/src/main/java/me/lucko/spark/forge/Forge1122PlatformInfo.java b/spark-forge1122/src/main/java/me/lucko/spark/forge/Forge1122PlatformInfo.java deleted file mode 100644 index 379c0e3..0000000 --- a/spark-forge1122/src/main/java/me/lucko/spark/forge/Forge1122PlatformInfo.java +++ /dev/null @@ -1,53 +0,0 @@ -/* - * This file is part of spark. - * - * Copyright (c) lucko (Luck) <luck@lucko.me> - * 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 <http://www.gnu.org/licenses/>. - */ - -package me.lucko.spark.forge; - -import me.lucko.spark.common.platform.AbstractPlatformInfo; - -import net.minecraftforge.common.ForgeVersion; - -public class Forge1122PlatformInfo extends AbstractPlatformInfo { - private final Type type; - - public Forge1122PlatformInfo(Type type) { - this.type = type; - } - - @Override - public Type getType() { - return this.type; - } - - @Override - public String getName() { - return "Forge"; - } - - @Override - public String getVersion() { - return ForgeVersion.getVersion(); - } - - @Override - public String getMinecraftVersion() { - return ForgeVersion.mcVersion; - } -} diff --git a/spark-forge1122/src/main/java/me/lucko/spark/forge/Forge1122SparkMod.java b/spark-forge1122/src/main/java/me/lucko/spark/forge/Forge1122SparkMod.java deleted file mode 100644 index 535c69e..0000000 --- a/spark-forge1122/src/main/java/me/lucko/spark/forge/Forge1122SparkMod.java +++ /dev/null @@ -1,83 +0,0 @@ -/* - * This file is part of spark. - * - * Copyright (c) lucko (Luck) <luck@lucko.me> - * 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 <http://www.gnu.org/licenses/>. - */ - -package me.lucko.spark.forge; - -import me.lucko.spark.forge.plugin.Forge1122ClientSparkPlugin; -import me.lucko.spark.forge.plugin.Forge1122ServerSparkPlugin; - -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.common.event.FMLServerStoppingEvent; -import net.minecraftforge.fml.relauncher.Side; - -import java.nio.file.Path; - -@Mod( - modid = "spark", - name = "spark", - version = "@version@", - acceptableRemoteVersions = "*" -) -public class Forge1122SparkMod { - - private Path configDirectory; - private Forge1122ServerSparkPlugin activeServerPlugin; - - public String getVersion() { - return Forge1122SparkMod.class.getAnnotation(Mod.class).version(); - } - - @EventHandler - public void preInit(FMLPreInitializationEvent e) { - this.configDirectory = e.getModConfigurationDirectory().toPath(); - } - - @EventHandler - public void clientInit(FMLInitializationEvent e) { - if (FMLCommonHandler.instance().getSide() == Side.CLIENT) { - Forge1122ClientSparkPlugin.register(this); - } - } - - @EventHandler - public void serverInit(FMLServerStartingEvent e) { - this.activeServerPlugin = Forge1122ServerSparkPlugin.register(this, e); - } - - @EventHandler - public void serverStop(FMLServerStoppingEvent e) { - if (this.activeServerPlugin != null) { - this.activeServerPlugin.disable(); - this.activeServerPlugin = null; - } - } - - public Path getConfigDirectory() { - if (this.configDirectory == null) { - throw new IllegalStateException("Config directory not set"); - } - return this.configDirectory; - } -} diff --git a/spark-forge1122/src/main/java/me/lucko/spark/forge/Forge1122TickHook.java b/spark-forge1122/src/main/java/me/lucko/spark/forge/Forge1122TickHook.java deleted file mode 100644 index 7ff9893..0000000 --- a/spark-forge1122/src/main/java/me/lucko/spark/forge/Forge1122TickHook.java +++ /dev/null @@ -1,60 +0,0 @@ -/* - * This file is part of spark. - * - * Copyright (c) lucko (Luck) <luck@lucko.me> - * 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 <http://www.gnu.org/licenses/>. - */ - -package me.lucko.spark.forge; - -import me.lucko.spark.common.tick.AbstractTickHook; -import me.lucko.spark.common.tick.TickHook; - -import net.minecraftforge.common.MinecraftForge; -import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; -import net.minecraftforge.fml.common.gameevent.TickEvent; - -public class Forge1122TickHook extends AbstractTickHook implements TickHook { - private final TickEvent.Type type; - - public Forge1122TickHook(TickEvent.Type type) { - this.type = type; - } - - @SubscribeEvent - public void onTick(TickEvent e) { - if (e.phase != TickEvent.Phase.START) { - return; - } - - if (e.type != this.type) { - return; - } - - onTick(); - } - - @Override - public void start() { - MinecraftForge.EVENT_BUS.register(this); - } - - @Override - public void close() { - MinecraftForge.EVENT_BUS.unregister(this); - } - -} diff --git a/spark-forge1122/src/main/java/me/lucko/spark/forge/Forge1122TickReporter.java b/spark-forge1122/src/main/java/me/lucko/spark/forge/Forge1122TickReporter.java deleted file mode 100644 index cd2cfd8..0000000 --- a/spark-forge1122/src/main/java/me/lucko/spark/forge/Forge1122TickReporter.java +++ /dev/null @@ -1,66 +0,0 @@ -/* - * This file is part of spark. - * - * Copyright (c) lucko (Luck) <luck@lucko.me> - * 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 <http://www.gnu.org/licenses/>. - */ - -package me.lucko.spark.forge; - -import me.lucko.spark.common.tick.SimpleTickReporter; -import me.lucko.spark.common.tick.TickReporter; - -import net.minecraftforge.common.MinecraftForge; -import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; -import net.minecraftforge.fml.common.gameevent.TickEvent; - -public class Forge1122TickReporter extends SimpleTickReporter implements TickReporter { - private final TickEvent.Type type; - - public Forge1122TickReporter(TickEvent.Type type) { - this.type = type; - } - - @SubscribeEvent - public void onTick(TickEvent e) { - if (e.type != this.type) { - return; - } - - switch (e.phase) { - case START: - onStart(); - break; - case END: - onEnd(); - break; - default: - throw new AssertionError(e.phase); - } - } - - @Override - public void start() { - MinecraftForge.EVENT_BUS.register(this); - } - - @Override - public void close() { - MinecraftForge.EVENT_BUS.unregister(this); - super.close(); - } - -} diff --git a/spark-forge1122/src/main/java/me/lucko/spark/forge/plugin/Forge1122ClientSparkPlugin.java b/spark-forge1122/src/main/java/me/lucko/spark/forge/plugin/Forge1122ClientSparkPlugin.java deleted file mode 100644 index 7ab0356..0000000 --- a/spark-forge1122/src/main/java/me/lucko/spark/forge/plugin/Forge1122ClientSparkPlugin.java +++ /dev/null @@ -1,90 +0,0 @@ -/* - * This file is part of spark. - * - * Copyright (c) lucko (Luck) <luck@lucko.me> - * 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 <http://www.gnu.org/licenses/>. - */ - -package me.lucko.spark.forge.plugin; - -import me.lucko.spark.common.platform.PlatformInfo; -import me.lucko.spark.common.tick.TickHook; -import me.lucko.spark.common.tick.TickReporter; -import me.lucko.spark.forge.Forge1122CommandSender; -import me.lucko.spark.forge.Forge1122PlatformInfo; -import me.lucko.spark.forge.Forge1122SparkMod; -import me.lucko.spark.forge.Forge1122TickHook; -import me.lucko.spark.forge.Forge1122TickReporter; - -import net.minecraft.client.Minecraft; -import net.minecraft.command.ICommandSender; -import net.minecraftforge.client.ClientCommandHandler; -import net.minecraftforge.common.MinecraftForge; -import net.minecraftforge.fml.common.gameevent.TickEvent; - -import java.util.stream.Stream; - -public class Forge1122ClientSparkPlugin extends Forge1122SparkPlugin { - - public static void register(Forge1122SparkMod mod) { - Forge1122ClientSparkPlugin plugin = new Forge1122ClientSparkPlugin(mod, Minecraft.getMinecraft()); - plugin.enable(); - - // register listeners - MinecraftForge.EVENT_BUS.register(plugin); - - // register commands - ClientCommandHandler.instance.registerCommand(plugin); - } - - private final Minecraft minecraft; - - public Forge1122ClientSparkPlugin(Forge1122SparkMod mod, Minecraft minecraft) { - super(mod); - this.minecraft = minecraft; - } - - @Override - public boolean hasPermission(ICommandSender sender, String permission) { - return true; - } - - @Override - public Stream<Forge1122CommandSender> getCommandSenders() { - return Stream.of(new Forge1122CommandSender(this.minecraft.player, this)); - } - - @Override - public TickHook createTickHook() { - return new Forge1122TickHook(TickEvent.Type.CLIENT); - } - - @Override - public TickReporter createTickReporter() { - return new Forge1122TickReporter(TickEvent.Type.CLIENT); - } - - @Override - public PlatformInfo getPlatformInfo() { - return new Forge1122PlatformInfo(PlatformInfo.Type.CLIENT); - } - - @Override - public String getCommandName() { - return "sparkc"; - } - -} diff --git a/spark-forge1122/src/main/java/me/lucko/spark/forge/plugin/Forge1122ServerSparkPlugin.java b/spark-forge1122/src/main/java/me/lucko/spark/forge/plugin/Forge1122ServerSparkPlugin.java deleted file mode 100644 index 72b1429..0000000 --- a/spark-forge1122/src/main/java/me/lucko/spark/forge/plugin/Forge1122ServerSparkPlugin.java +++ /dev/null @@ -1,98 +0,0 @@ -/* - * This file is part of spark. - * - * Copyright (c) lucko (Luck) <luck@lucko.me> - * 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 <http://www.gnu.org/licenses/>. - */ - -package me.lucko.spark.forge.plugin; - -import me.lucko.spark.common.platform.PlatformInfo; -import me.lucko.spark.common.tick.TickHook; -import me.lucko.spark.common.tick.TickReporter; -import me.lucko.spark.forge.Forge1122CommandSender; -import me.lucko.spark.forge.Forge1122PlatformInfo; -import me.lucko.spark.forge.Forge1122SparkMod; -import me.lucko.spark.forge.Forge1122TickHook; -import me.lucko.spark.forge.Forge1122TickReporter; - -import net.minecraft.command.ICommandSender; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.server.MinecraftServer; -import net.minecraftforge.fml.common.event.FMLServerStartingEvent; -import net.minecraftforge.fml.common.gameevent.TickEvent; -import net.minecraftforge.server.permission.DefaultPermissionLevel; -import net.minecraftforge.server.permission.PermissionAPI; - -import java.util.stream.Stream; - -public class Forge1122ServerSparkPlugin extends Forge1122SparkPlugin { - - public static Forge1122ServerSparkPlugin register(Forge1122SparkMod mod, FMLServerStartingEvent event) { - Forge1122ServerSparkPlugin plugin = new Forge1122ServerSparkPlugin(mod, event.getServer()); - plugin.enable(); - - // register commands & permissions - event.registerServerCommand(plugin); - PermissionAPI.registerNode("spark", DefaultPermissionLevel.OP, "Access to the spark command"); - - return plugin; - } - - private final MinecraftServer server; - - public Forge1122ServerSparkPlugin(Forge1122SparkMod mod, MinecraftServer server) { - super(mod); - this.server = server; - } - - @Override - public boolean hasPermission(ICommandSender sender, String permission) { - if (sender instanceof EntityPlayer) { - return PermissionAPI.hasPermission((EntityPlayer) sender, permission); - } else { - return true; - } - } - - @Override - public Stream<Forge1122CommandSender> getCommandSenders() { - return Stream.concat( - this.server.getPlayerList().getPlayers().stream(), - Stream.of(this.server) - ).map(sender -> new Forge1122CommandSender(sender, this)); - } - - @Override - public TickHook createTickHook() { - return new Forge1122TickHook(TickEvent.Type.SERVER); - } - - @Override - public TickReporter createTickReporter() { - return new Forge1122TickReporter(TickEvent.Type.SERVER); - } - - @Override - public PlatformInfo getPlatformInfo() { - return new Forge1122PlatformInfo(PlatformInfo.Type.SERVER); - } - - @Override - public String getCommandName() { - return "spark"; - } -} diff --git a/spark-forge1122/src/main/java/me/lucko/spark/forge/plugin/Forge1122SparkPlugin.java b/spark-forge1122/src/main/java/me/lucko/spark/forge/plugin/Forge1122SparkPlugin.java deleted file mode 100644 index 727a2fd..0000000 --- a/spark-forge1122/src/main/java/me/lucko/spark/forge/plugin/Forge1122SparkPlugin.java +++ /dev/null @@ -1,153 +0,0 @@ -/* - * This file is part of spark. - * - * Copyright (c) lucko (Luck) <luck@lucko.me> - * 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 <http://www.gnu.org/licenses/>. - */ - -package me.lucko.spark.forge.plugin; - -import me.lucko.spark.common.SparkPlatform; -import me.lucko.spark.common.SparkPlugin; -import me.lucko.spark.common.sampler.ThreadDumper; -import me.lucko.spark.forge.Forge1122CommandSender; -import me.lucko.spark.forge.Forge1122SparkMod; - -import net.minecraft.command.ICommand; -import net.minecraft.command.ICommandSender; -import net.minecraft.server.MinecraftServer; -import net.minecraft.util.math.BlockPos; - -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; - -import java.nio.file.Path; -import java.util.Collections; -import java.util.List; -import java.util.concurrent.Executors; -import java.util.concurrent.ScheduledExecutorService; -import java.util.logging.Level; - -import javax.annotation.Nullable; - -public abstract class Forge1122SparkPlugin implements SparkPlugin, ICommand { - - private final Forge1122SparkMod mod; - private final Logger logger; - protected final ScheduledExecutorService scheduler; - protected final SparkPlatform platform; - protected final ThreadDumper.GameThread threadDumper = new ThreadDumper.GameThread(); - - protected Forge1122SparkPlugin(Forge1122SparkMod mod) { - this.mod = mod; - this.logger = LogManager.getLogger("spark"); - this.scheduler = Executors.newSingleThreadScheduledExecutor(r -> { - Thread thread = Executors.defaultThreadFactory().newThread(r); - thread.setName("spark-forge-async-worker"); - thread.setDaemon(true); - return thread; - }); - this.platform = new SparkPlatform(this); - } - - public void enable() { - this.platform.enable(); - } - - public void disable() { - this.platform.disable(); - this.scheduler.shutdown(); - } - - public abstract boolean hasPermission(ICommandSender sender, String permission); - - @Override - public String getVersion() { - return this.mod.getVersion(); - } - - @Override - public Path getPluginDirectory() { - return this.mod.getConfigDirectory(); - } - - @Override - public void executeAsync(Runnable task) { - this.scheduler.execute(task); - } - - @Override - public void log(Level level, String msg) { - if (level == Level.INFO) { - this.logger.info(msg); - } else if (level == Level.WARNING) { - this.logger.warn(msg); - } else if (level == Level.SEVERE) { - this.logger.error(msg); - } else { - throw new IllegalArgumentException(level.getName()); - } - } - - @Override - public ThreadDumper getDefaultThreadDumper() { - return this.threadDumper.get(); - } - - // implement ICommand - - @Override - public String getName() { - return getCommandName(); - } - - @Override - public String getUsage(ICommandSender iCommandSender) { - return "/" + getCommandName(); - } - - @Override - public List<String> getAliases() { - return Collections.singletonList(getCommandName()); - } - - @Override - public void execute(MinecraftServer server, ICommandSender sender, String[] args) { - this.threadDumper.ensureSetup(); - this.platform.executeCommand(new Forge1122CommandSender(sender, this), args); - } - - @Override - public List<String> getTabCompletions(MinecraftServer server, ICommandSender sender, String[] args, @Nullable BlockPos blockPos) { - return this.platform.tabCompleteCommand(new Forge1122CommandSender(sender, this), args); - } - - @Override - public boolean checkPermission(MinecraftServer minecraftServer, ICommandSender sender) { - return this.platform.hasPermissionForAnyCommand(new Forge1122CommandSender(sender, this)); - } - - @Override - public boolean isUsernameIndex(String[] strings, int i) { - return false; - } - - @Override - public int compareTo(ICommand o) { - return getCommandName().compareTo(o.getName()); - } - -} diff --git a/spark-forge1122/src/main/resources/mcmod.info b/spark-forge1122/src/main/resources/mcmod.info deleted file mode 100644 index 1c2c241..0000000 --- a/spark-forge1122/src/main/resources/mcmod.info +++ /dev/null @@ -1,7 +0,0 @@ -[{ - "modid": "spark", - "name": "spark", - "description": "${pluginDescription}", - "version": "${pluginVersion}", - "authors": ["Luck"] -}] |