aboutsummaryrefslogtreecommitdiff
path: root/spark-bukkit/src/main/java/me
diff options
context:
space:
mode:
Diffstat (limited to 'spark-bukkit/src/main/java/me')
-rw-r--r--spark-bukkit/src/main/java/me/lucko/spark/bukkit/BukkitCommandSender.java61
-rw-r--r--spark-bukkit/src/main/java/me/lucko/spark/bukkit/SparkBukkitPlugin.java39
2 files changed, 73 insertions, 27 deletions
diff --git a/spark-bukkit/src/main/java/me/lucko/spark/bukkit/BukkitCommandSender.java b/spark-bukkit/src/main/java/me/lucko/spark/bukkit/BukkitCommandSender.java
new file mode 100644
index 0000000..dacea76
--- /dev/null
+++ b/spark-bukkit/src/main/java/me/lucko/spark/bukkit/BukkitCommandSender.java
@@ -0,0 +1,61 @@
+/*
+ * 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.bukkit;
+
+import me.lucko.spark.common.CommandSender;
+import net.kyori.text.Component;
+import net.kyori.text.adapter.bukkit.TextAdapter;
+
+public class BukkitCommandSender implements CommandSender {
+ private final org.bukkit.command.CommandSender sender;
+
+ public BukkitCommandSender(org.bukkit.command.CommandSender sender) {
+ this.sender = sender;
+ }
+
+ @Override
+ public String getName() {
+ return this.sender.getName();
+ }
+
+ @Override
+ public void sendMessage(Component message) {
+ TextAdapter.sendComponent(this.sender, message);
+ }
+
+ @Override
+ public boolean hasPermission(String permission) {
+ return this.sender.hasPermission(permission);
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) return true;
+ if (o == null || getClass() != o.getClass()) return false;
+ BukkitCommandSender that = (BukkitCommandSender) o;
+ return this.sender.equals(that.sender);
+ }
+
+ @Override
+ public int hashCode() {
+ return this.sender.hashCode();
+ }
+}
diff --git a/spark-bukkit/src/main/java/me/lucko/spark/bukkit/SparkBukkitPlugin.java b/spark-bukkit/src/main/java/me/lucko/spark/bukkit/SparkBukkitPlugin.java
index 15c725d..ee85c70 100644
--- a/spark-bukkit/src/main/java/me/lucko/spark/bukkit/SparkBukkitPlugin.java
+++ b/spark-bukkit/src/main/java/me/lucko/spark/bukkit/SparkBukkitPlugin.java
@@ -20,29 +20,27 @@
package me.lucko.spark.bukkit;
+import me.lucko.spark.common.CommandSender;
import me.lucko.spark.common.SparkPlatform;
import me.lucko.spark.common.SparkPlugin;
import me.lucko.spark.common.command.CommandResponseHandler;
import me.lucko.spark.common.monitor.tick.TpsCalculator;
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.adapter.bukkit.TextAdapter;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
-import org.bukkit.command.CommandSender;
import org.bukkit.plugin.java.JavaPlugin;
import java.nio.file.Path;
-import java.util.Collections;
-import java.util.HashSet;
+import java.util.LinkedList;
import java.util.List;
import java.util.Set;
+import java.util.stream.Collectors;
-public class SparkBukkitPlugin extends JavaPlugin implements SparkPlugin<CommandSender> {
+public class SparkBukkitPlugin extends JavaPlugin implements SparkPlugin {
- private final SparkPlatform<CommandSender> platform = new SparkPlatform<>(this);
+ private final SparkPlatform platform = new SparkPlatform(this);
@Override
public void onEnable() {
@@ -56,7 +54,7 @@ public class SparkBukkitPlugin extends JavaPlugin implements SparkPlugin<Command
return true;
}
- CommandResponseHandler<CommandSender> resp = new CommandResponseHandler<>(this.platform, sender);
+ CommandResponseHandler resp = new CommandResponseHandler(this.platform, new BukkitCommandSender(sender));
TpsCalculator tpsCalculator = this.platform.getTpsCalculator();
resp.replyPrefixed(TextComponent.of("TPS from last 5s, 10s, 1m, 5m, 15m:"));
resp.replyPrefixed(TextComponent.builder(" ").append(tpsCalculator.toFormattedComponent()).build());
@@ -71,22 +69,14 @@ public class SparkBukkitPlugin extends JavaPlugin implements SparkPlugin<Command
}
@Override
- public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
- if (!sender.hasPermission("spark")) {
- sender.sendMessage(ChatColor.RED + "You do not have permission to use this command.");
- return true;
- }
-
- this.platform.executeCommand(sender, args);
+ public boolean onCommand(org.bukkit.command.CommandSender sender, Command command, String label, String[] args) {
+ this.platform.executeCommand(new BukkitCommandSender(sender), args);
return true;
}
@Override
- public List<String> onTabComplete(CommandSender sender, Command command, String alias, String[] args) {
- if (!sender.hasPermission("spark")) {
- return Collections.emptyList();
- }
- return this.platform.tabCompleteCommand(sender, args);
+ public List<String> onTabComplete(org.bukkit.command.CommandSender sender, Command command, String alias, String[] args) {
+ return this.platform.tabCompleteCommand(new BukkitCommandSender(sender), args);
}
@Override
@@ -106,15 +96,10 @@ public class SparkBukkitPlugin extends JavaPlugin implements SparkPlugin<Command
@Override
public Set<CommandSender> getSendersWithPermission(String permission) {
- Set<CommandSender> senders = new HashSet<>(getServer().getOnlinePlayers());
+ List<org.bukkit.command.CommandSender> senders = new LinkedList<>(getServer().getOnlinePlayers());
senders.removeIf(sender -> !sender.hasPermission(permission));
senders.add(getServer().getConsoleSender());
- return senders;
- }
-
- @Override
- public void sendMessage(CommandSender sender, Component message) {
- TextAdapter.sendComponent(sender, message);
+ return senders.stream().map(BukkitCommandSender::new).collect(Collectors.toSet());
}
@Override