aboutsummaryrefslogtreecommitdiff
path: root/spark-velocity
diff options
context:
space:
mode:
authorLuck <git@lucko.me>2019-04-28 15:37:32 +0100
committerLuck <git@lucko.me>2019-05-04 23:22:32 +0100
commitc3ae37e88f967a21522af7d0cb79a571326cd7e9 (patch)
tree7ce46c61407dacdff3cabaeb1ffc8eb5e7cd614a /spark-velocity
parent51fa2b3e64f021c3c0535f9f931d3fae27ca7adc (diff)
downloadspark-c3ae37e88f967a21522af7d0cb79a571326cd7e9.tar.gz
spark-c3ae37e88f967a21522af7d0cb79a571326cd7e9.tar.bz2
spark-c3ae37e88f967a21522af7d0cb79a571326cd7e9.zip
Start implementing activity log feature
Diffstat (limited to 'spark-velocity')
-rw-r--r--spark-velocity/src/main/java/me/lucko/spark/velocity/SparkVelocityPlugin.java36
-rw-r--r--spark-velocity/src/main/java/me/lucko/spark/velocity/VelocityCommandSender.java69
2 files changed, 83 insertions, 22 deletions
diff --git a/spark-velocity/src/main/java/me/lucko/spark/velocity/SparkVelocityPlugin.java b/spark-velocity/src/main/java/me/lucko/spark/velocity/SparkVelocityPlugin.java
index c1c2f2d..4a5f500 100644
--- a/spark-velocity/src/main/java/me/lucko/spark/velocity/SparkVelocityPlugin.java
+++ b/spark-velocity/src/main/java/me/lucko/spark/velocity/SparkVelocityPlugin.java
@@ -30,21 +30,19 @@ import com.velocitypowered.api.event.proxy.ProxyShutdownEvent;
import com.velocitypowered.api.plugin.Plugin;
import com.velocitypowered.api.plugin.annotation.DataDirectory;
import com.velocitypowered.api.proxy.ProxyServer;
+import me.lucko.spark.common.CommandSender;
import me.lucko.spark.common.SparkPlatform;
import me.lucko.spark.common.SparkPlugin;
import me.lucko.spark.common.sampler.ThreadDumper;
import me.lucko.spark.common.sampler.TickCounter;
-import net.kyori.text.Component;
-import net.kyori.text.TextComponent;
-import net.kyori.text.event.ClickEvent;
-import net.kyori.text.format.TextColor;
-import net.kyori.text.serializer.ComponentSerializers;
import org.checkerframework.checker.nullness.qual.NonNull;
import org.checkerframework.checker.optional.qual.MaybePresent;
import java.nio.file.Path;
-import java.util.HashSet;
+import java.util.LinkedList;
+import java.util.List;
import java.util.Set;
+import java.util.stream.Collectors;
@Plugin(
id = "spark",
@@ -53,9 +51,9 @@ import java.util.Set;
description = "@desc@",
authors = {"Luck", "sk89q"}
)
-public class SparkVelocityPlugin implements SparkPlugin<CommandSource>, Command {
+public class SparkVelocityPlugin implements SparkPlugin, Command {
- private final SparkPlatform<CommandSource> platform = new SparkPlatform<>(this);
+ private final SparkPlatform platform = new SparkPlatform(this);
private final ProxyServer proxy;
private final Path configDirectory;
@@ -79,13 +77,12 @@ public class SparkVelocityPlugin implements SparkPlugin<CommandSource>, Command
@Override
public void execute(@MaybePresent CommandSource sender, @NonNull @MaybePresent String[] args) {
- if (!sender.hasPermission("spark")) {
- TextComponent msg = TextComponent.builder("You do not have permission to use this command.").color(TextColor.RED).build();
- sender.sendMessage(msg);
- return;
- }
+ this.platform.executeCommand(new VelocityCommandSender(sender), args);
+ }
- this.platform.executeCommand(sender, args);
+ @Override
+ public @MaybePresent List<String> suggest(@MaybePresent CommandSource sender, @NonNull @MaybePresent String[] currentArgs) {
+ return this.platform.tabCompleteCommand(new VelocityCommandSender(sender), currentArgs);
}
@Override
@@ -104,16 +101,11 @@ public class SparkVelocityPlugin implements SparkPlugin<CommandSource>, Command
}
@Override
- public Set<CommandSource> getSendersWithPermission(String permission) {
- Set<CommandSource> senders = new HashSet<>(this.proxy.getAllPlayers());
+ public Set<CommandSender> getSendersWithPermission(String permission) {
+ List<CommandSource> senders = new LinkedList<>(this.proxy.getAllPlayers());
senders.removeIf(sender -> !sender.hasPermission(permission));
senders.add(this.proxy.getConsoleCommandSource());
- return senders;
- }
-
- @Override
- public void sendMessage(CommandSource sender, Component message) {
- sender.sendMessage(message);
+ return senders.stream().map(VelocityCommandSender::new).collect(Collectors.toSet());
}
@Override
diff --git a/spark-velocity/src/main/java/me/lucko/spark/velocity/VelocityCommandSender.java b/spark-velocity/src/main/java/me/lucko/spark/velocity/VelocityCommandSender.java
new file mode 100644
index 0000000..1cad493
--- /dev/null
+++ b/spark-velocity/src/main/java/me/lucko/spark/velocity/VelocityCommandSender.java
@@ -0,0 +1,69 @@
+/*
+ * 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.velocity;
+
+import com.velocitypowered.api.command.CommandSource;
+import com.velocitypowered.api.proxy.ConsoleCommandSource;
+import com.velocitypowered.api.proxy.Player;
+import me.lucko.spark.common.CommandSender;
+import net.kyori.text.Component;
+
+public class VelocityCommandSender implements CommandSender {
+ private final CommandSource source;
+
+ public VelocityCommandSender(CommandSource source) {
+ this.source = source;
+ }
+
+ @Override
+ public String getName() {
+ if (this.source instanceof Player) {
+ return ((Player) this.source).getUsername();
+ } else if (this.source instanceof ConsoleCommandSource) {
+ return "Console";
+ } else {
+ return "unknown:" + this.source.getClass().getSimpleName();
+ }
+ }
+
+ @Override
+ public void sendMessage(Component message) {
+ this.source.sendMessage(message);
+ }
+
+ @Override
+ public boolean hasPermission(String permission) {
+ return this.source.hasPermission(permission);
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) return true;
+ if (o == null || getClass() != o.getClass()) return false;
+ VelocityCommandSender that = (VelocityCommandSender) o;
+ return this.source.equals(that.source);
+ }
+
+ @Override
+ public int hashCode() {
+ return this.source.hashCode();
+ }
+}