diff options
author | Luck <git@lucko.me> | 2019-08-26 09:02:55 +0100 |
---|---|---|
committer | Luck <git@lucko.me> | 2019-08-26 09:02:55 +0100 |
commit | bf2262c392c7e234c8662aa7be5d2970dcacee65 (patch) | |
tree | eedcfee731264ea5ba9d687a5dfd70eaf36a835e /spark-forge/src/main/java | |
parent | 8a7ca8ef4a29bd1d684a29f925f3a9db1f69fe0b (diff) | |
download | spark-bf2262c392c7e234c8662aa7be5d2970dcacee65.tar.gz spark-bf2262c392c7e234c8662aa7be5d2970dcacee65.tar.bz2 spark-bf2262c392c7e234c8662aa7be5d2970dcacee65.zip |
Various misc changes to spark-forge and spark-fabric
Diffstat (limited to 'spark-forge/src/main/java')
-rw-r--r-- | spark-forge/src/main/java/me/lucko/spark/forge/ForgeCommandSender.java | 1 | ||||
-rw-r--r-- | spark-forge/src/main/java/me/lucko/spark/forge/ForgeSparkMod.java | 2 | ||||
-rw-r--r-- | spark-forge/src/main/java/me/lucko/spark/forge/plugin/ForgeClientSparkPlugin.java (renamed from spark-forge/src/main/java/me/lucko/spark/forge/ForgeClientSparkPlugin.java) | 7 | ||||
-rw-r--r-- | spark-forge/src/main/java/me/lucko/spark/forge/plugin/ForgeServerSparkPlugin.java (renamed from spark-forge/src/main/java/me/lucko/spark/forge/ForgeServerSparkPlugin.java) | 9 | ||||
-rw-r--r-- | spark-forge/src/main/java/me/lucko/spark/forge/plugin/ForgeSparkPlugin.java (renamed from spark-forge/src/main/java/me/lucko/spark/forge/ForgeSparkPlugin.java) | 26 |
5 files changed, 31 insertions, 14 deletions
diff --git a/spark-forge/src/main/java/me/lucko/spark/forge/ForgeCommandSender.java b/spark-forge/src/main/java/me/lucko/spark/forge/ForgeCommandSender.java index 418cf2d..ff988f0 100644 --- a/spark-forge/src/main/java/me/lucko/spark/forge/ForgeCommandSender.java +++ b/spark-forge/src/main/java/me/lucko/spark/forge/ForgeCommandSender.java @@ -21,6 +21,7 @@ package me.lucko.spark.forge; import me.lucko.spark.common.CommandSender; +import me.lucko.spark.forge.plugin.ForgeSparkPlugin; import net.kyori.text.Component; import net.kyori.text.serializer.gson.GsonComponentSerializer; import net.minecraft.command.ICommandSource; 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 index f3bf5c3..1f7199d 100644 --- a/spark-forge/src/main/java/me/lucko/spark/forge/ForgeSparkMod.java +++ b/spark-forge/src/main/java/me/lucko/spark/forge/ForgeSparkMod.java @@ -20,6 +20,8 @@ package me.lucko.spark.forge; +import me.lucko.spark.forge.plugin.ForgeClientSparkPlugin; +import me.lucko.spark.forge.plugin.ForgeServerSparkPlugin; import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.eventbus.api.SubscribeEvent; import net.minecraftforge.fml.ModContainer; diff --git a/spark-forge/src/main/java/me/lucko/spark/forge/ForgeClientSparkPlugin.java b/spark-forge/src/main/java/me/lucko/spark/forge/plugin/ForgeClientSparkPlugin.java index 0d38ea2..7de0038 100644 --- a/spark-forge/src/main/java/me/lucko/spark/forge/ForgeClientSparkPlugin.java +++ b/spark-forge/src/main/java/me/lucko/spark/forge/plugin/ForgeClientSparkPlugin.java @@ -18,10 +18,13 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. */ -package me.lucko.spark.forge; +package me.lucko.spark.forge.plugin; import com.mojang.brigadier.CommandDispatcher; import me.lucko.spark.common.sampler.TickCounter; +import me.lucko.spark.forge.ForgeCommandSender; +import me.lucko.spark.forge.ForgeSparkMod; +import me.lucko.spark.forge.ForgeTickCounter; import net.minecraft.client.Minecraft; import net.minecraft.client.entity.player.ClientPlayerEntity; import net.minecraft.client.network.play.ClientPlayNetHandler; @@ -102,7 +105,7 @@ public class ForgeClientSparkPlugin extends ForgeSparkPlugin { } @Override - boolean hasPermission(ICommandSource sender, String permission) { + public boolean hasPermission(ICommandSource sender, String permission) { return true; } diff --git a/spark-forge/src/main/java/me/lucko/spark/forge/ForgeServerSparkPlugin.java b/spark-forge/src/main/java/me/lucko/spark/forge/plugin/ForgeServerSparkPlugin.java index 13ccb59..5eb61f8 100644 --- a/spark-forge/src/main/java/me/lucko/spark/forge/ForgeServerSparkPlugin.java +++ b/spark-forge/src/main/java/me/lucko/spark/forge/plugin/ForgeServerSparkPlugin.java @@ -18,13 +18,16 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. */ -package me.lucko.spark.forge; +package me.lucko.spark.forge.plugin; import com.mojang.brigadier.Command; import com.mojang.brigadier.CommandDispatcher; import com.mojang.brigadier.context.CommandContext; import com.mojang.brigadier.exceptions.CommandSyntaxException; import me.lucko.spark.common.sampler.TickCounter; +import me.lucko.spark.forge.ForgeCommandSender; +import me.lucko.spark.forge.ForgeSparkMod; +import me.lucko.spark.forge.ForgeTickCounter; import net.minecraft.command.CommandSource; import net.minecraft.command.ICommandSource; import net.minecraft.entity.player.PlayerEntity; @@ -69,7 +72,7 @@ public class ForgeServerSparkPlugin extends ForgeSparkPlugin implements Command< } @Override - boolean hasPermission(ICommandSource sender, String permission) { + public boolean hasPermission(ICommandSource sender, String permission) { if (sender instanceof PlayerEntity) { return PermissionAPI.hasPermission((PlayerEntity) sender, permission); } else { @@ -80,7 +83,7 @@ public class ForgeServerSparkPlugin extends ForgeSparkPlugin implements Command< @Override public Stream<ForgeCommandSender> getSendersWithPermission(String permission) { return Stream.concat( - this.server.getPlayerList().getPlayers().stream().filter(player -> PermissionAPI.hasPermission(player, permission)), + this.server.getPlayerList().getPlayers().stream().filter(player -> hasPermission(player, permission)), Stream.of(this.server) ).map(sender -> new ForgeCommandSender(sender, this)); } diff --git a/spark-forge/src/main/java/me/lucko/spark/forge/ForgeSparkPlugin.java b/spark-forge/src/main/java/me/lucko/spark/forge/plugin/ForgeSparkPlugin.java index 7141e8d..915ca6d 100644 --- a/spark-forge/src/main/java/me/lucko/spark/forge/ForgeSparkPlugin.java +++ b/spark-forge/src/main/java/me/lucko/spark/forge/plugin/ForgeSparkPlugin.java @@ -18,7 +18,7 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. */ -package me.lucko.spark.forge; +package me.lucko.spark.forge.plugin; import com.google.common.util.concurrent.ThreadFactoryBuilder; import com.mojang.brigadier.Command; @@ -26,9 +26,11 @@ import com.mojang.brigadier.CommandDispatcher; import com.mojang.brigadier.arguments.StringArgumentType; import com.mojang.brigadier.builder.LiteralArgumentBuilder; import com.mojang.brigadier.builder.RequiredArgumentBuilder; +import com.mojang.brigadier.tree.LiteralCommandNode; import me.lucko.spark.common.SparkPlatform; import me.lucko.spark.common.SparkPlugin; import me.lucko.spark.common.sampler.ThreadDumper; +import me.lucko.spark.forge.ForgeSparkMod; import net.minecraft.command.ICommandSource; import java.nio.file.Path; @@ -38,14 +40,20 @@ import java.util.concurrent.ScheduledExecutorService; public abstract class ForgeSparkPlugin implements SparkPlugin { public static <T> void registerCommands(CommandDispatcher<T> dispatcher, Command<T> executor, String... aliases) { - for (String alias : aliases) { - LiteralArgumentBuilder<T> command = LiteralArgumentBuilder.<T>literal(alias) - .executes(executor) - .then(RequiredArgumentBuilder.<T, String>argument("args", StringArgumentType.greedyString()) - .executes(executor) - ); + if (aliases.length == 0) { + return; + } + + String mainName = aliases[0]; + LiteralArgumentBuilder<T> command = LiteralArgumentBuilder.<T>literal(mainName) + .executes(executor) + .then(RequiredArgumentBuilder.<T, String>argument("args", StringArgumentType.greedyString()) + .executes(executor) + ); - dispatcher.register(command); + LiteralCommandNode<T> node = dispatcher.register(command); + for (int i = 1; i < aliases.length; i++) { + dispatcher.register(LiteralArgumentBuilder.<T>literal(aliases[i]).redirect(node)); } } @@ -62,7 +70,7 @@ public abstract class ForgeSparkPlugin implements SparkPlugin { this.platform.enable(); } - abstract boolean hasPermission(ICommandSource sender, String permission); + public abstract boolean hasPermission(ICommandSource sender, String permission); @Override public String getVersion() { |