diff options
21 files changed, 133 insertions, 174 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 index d353845..8bfc015 100644 --- a/spark-bukkit/src/main/java/me/lucko/spark/bukkit/BukkitCommandSender.java +++ b/spark-bukkit/src/main/java/me/lucko/spark/bukkit/BukkitCommandSender.java @@ -20,53 +20,40 @@ package me.lucko.spark.bukkit; -import me.lucko.spark.common.CommandSender; + +import me.lucko.spark.common.command.sender.AbstractCommandSender; import net.kyori.text.Component; import net.kyori.text.adapter.bukkit.TextAdapter; +import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; import java.util.UUID; -public class BukkitCommandSender implements CommandSender { - private final org.bukkit.command.CommandSender sender; - - public BukkitCommandSender(org.bukkit.command.CommandSender sender) { - this.sender = sender; +public class BukkitCommandSender extends AbstractCommandSender<CommandSender> { + public BukkitCommandSender(CommandSender sender) { + super(sender); } @Override public String getName() { - return this.sender.getName(); + return this.delegate.getName(); } @Override public UUID getUniqueId() { - if (this.sender instanceof Player) { - return ((Player) this.sender).getUniqueId(); + if (super.delegate instanceof Player) { + return ((Player) super.delegate).getUniqueId(); } return null; } @Override public void sendMessage(Component message) { - TextAdapter.sendComponent(this.sender, message); + TextAdapter.sendComponent(super.delegate, 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(); + return super.delegate.hasPermission(permission); } } diff --git a/spark-bukkit/src/main/java/me/lucko/spark/bukkit/placeholder/SparkPlaceholderApi.java b/spark-bukkit/src/main/java/me/lucko/spark/bukkit/placeholder/SparkPlaceholderApi.java index e5ada99..1eb2732 100644 --- a/spark-bukkit/src/main/java/me/lucko/spark/bukkit/placeholder/SparkPlaceholderApi.java +++ b/spark-bukkit/src/main/java/me/lucko/spark/bukkit/placeholder/SparkPlaceholderApi.java @@ -26,8 +26,6 @@ import me.lucko.spark.common.SparkPlatform; import org.bukkit.OfflinePlayer; import org.bukkit.entity.Player; -import java.util.stream.Collectors; - public class SparkPlaceholderApi extends PlaceholderExpansion { private final BukkitSparkPlugin plugin; private final SparkPlatform platform; @@ -55,12 +53,12 @@ public class SparkPlaceholderApi extends PlaceholderExpansion { @Override public String getAuthor() { - return plugin.getDescription().getAuthors().stream().collect(Collectors.joining(", ")); + return String.join(", ", this.plugin.getDescription().getAuthors()); } @Override public String getVersion() { - return plugin.getVersion(); + return this.plugin.getVersion(); } @Override diff --git a/spark-bungeecord/src/main/java/me/lucko/spark/bungeecord/BungeeCordCommandSender.java b/spark-bungeecord/src/main/java/me/lucko/spark/bungeecord/BungeeCordCommandSender.java index 193b38a..dcafcaa 100644 --- a/spark-bungeecord/src/main/java/me/lucko/spark/bungeecord/BungeeCordCommandSender.java +++ b/spark-bungeecord/src/main/java/me/lucko/spark/bungeecord/BungeeCordCommandSender.java @@ -20,53 +20,40 @@ package me.lucko.spark.bungeecord; -import me.lucko.spark.common.CommandSender; + +import me.lucko.spark.common.command.sender.AbstractCommandSender; import net.kyori.text.Component; import net.kyori.text.adapter.bungeecord.TextAdapter; +import net.md_5.bungee.api.CommandSender; import net.md_5.bungee.api.connection.ProxiedPlayer; import java.util.UUID; -public class BungeeCordCommandSender implements CommandSender { - private final net.md_5.bungee.api.CommandSender sender; - - public BungeeCordCommandSender(net.md_5.bungee.api.CommandSender sender) { - this.sender = sender; +public class BungeeCordCommandSender extends AbstractCommandSender<CommandSender> { + public BungeeCordCommandSender(CommandSender sender) { + super(sender); } @Override public String getName() { - return this.sender.getName(); + return super.delegate.getName(); } @Override public UUID getUniqueId() { - if (this.sender instanceof ProxiedPlayer) { - return ((ProxiedPlayer) this.sender).getUniqueId(); + if (super.delegate instanceof ProxiedPlayer) { + return ((ProxiedPlayer) super.delegate).getUniqueId(); } return null; } @Override public void sendMessage(Component message) { - TextAdapter.sendComponent(this.sender, message); + TextAdapter.sendComponent(super.delegate, 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; - BungeeCordCommandSender that = (BungeeCordCommandSender) o; - return this.sender.equals(that.sender); - } - - @Override - public int hashCode() { - return this.sender.hashCode(); + return super.delegate.hasPermission(permission); } } diff --git a/spark-common/src/main/java/me/lucko/spark/common/SparkPlatform.java b/spark-common/src/main/java/me/lucko/spark/common/SparkPlatform.java index db5cb84..dc88306 100644 --- a/spark-common/src/main/java/me/lucko/spark/common/SparkPlatform.java +++ b/spark-common/src/main/java/me/lucko/spark/common/SparkPlatform.java @@ -21,6 +21,7 @@ package me.lucko.spark.common; import com.google.common.collect.ImmutableList; +import me.lucko.spark.common.activitylog.ActivityLog; import me.lucko.spark.common.command.Arguments; import me.lucko.spark.common.command.Command; import me.lucko.spark.common.command.CommandModule; @@ -30,6 +31,7 @@ import me.lucko.spark.common.command.modules.HealthModule; import me.lucko.spark.common.command.modules.MemoryModule; import me.lucko.spark.common.command.modules.SamplerModule; import me.lucko.spark.common.command.modules.TickMonitoringModule; +import me.lucko.spark.common.command.sender.CommandSender; import me.lucko.spark.common.command.tabcomplete.CompletionSupplier; import me.lucko.spark.common.command.tabcomplete.TabCompleter; import me.lucko.spark.common.monitor.cpu.CpuMonitor; diff --git a/spark-common/src/main/java/me/lucko/spark/common/SparkPlugin.java b/spark-common/src/main/java/me/lucko/spark/common/SparkPlugin.java index 7ccffab..1171b33 100644 --- a/spark-common/src/main/java/me/lucko/spark/common/SparkPlugin.java +++ b/spark-common/src/main/java/me/lucko/spark/common/SparkPlugin.java @@ -20,6 +20,7 @@ package me.lucko.spark.common; +import me.lucko.spark.common.command.sender.CommandSender; import me.lucko.spark.common.sampler.ThreadDumper; import me.lucko.spark.common.sampler.TickCounter; diff --git a/spark-common/src/main/java/me/lucko/spark/common/ActivityLog.java b/spark-common/src/main/java/me/lucko/spark/common/activitylog/ActivityLog.java index 7327e2b..894593c 100644 --- a/spark-common/src/main/java/me/lucko/spark/common/ActivityLog.java +++ b/spark-common/src/main/java/me/lucko/spark/common/activitylog/ActivityLog.java @@ -18,7 +18,7 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. */ -package me.lucko.spark.common; +package me.lucko.spark.common.activitylog; import com.google.gson.Gson; import com.google.gson.GsonBuilder; @@ -27,6 +27,7 @@ import com.google.gson.JsonElement; import com.google.gson.JsonObject; import com.google.gson.JsonParser; import com.google.gson.JsonPrimitive; +import me.lucko.spark.common.command.sender.CommandSender; import java.io.BufferedReader; import java.io.BufferedWriter; @@ -175,7 +176,7 @@ public class ActivityLog { } public boolean shouldExpire() { - if (dataType.equals("url")) { + if (this.dataType.equals("url")) { return (System.currentTimeMillis() - this.time) > TimeUnit.DAYS.toMillis(7); } else { return false; diff --git a/spark-common/src/main/java/me/lucko/spark/common/command/Command.java b/spark-common/src/main/java/me/lucko/spark/common/command/Command.java index ab95cb6..db23454 100644 --- a/spark-common/src/main/java/me/lucko/spark/common/command/Command.java +++ b/spark-common/src/main/java/me/lucko/spark/common/command/Command.java @@ -21,8 +21,8 @@ package me.lucko.spark.common.command; import com.google.common.collect.ImmutableList; -import me.lucko.spark.common.CommandSender; import me.lucko.spark.common.SparkPlatform; +import me.lucko.spark.common.command.sender.CommandSender; import java.util.Collections; import java.util.List; diff --git a/spark-common/src/main/java/me/lucko/spark/common/command/CommandResponseHandler.java b/spark-common/src/main/java/me/lucko/spark/common/command/CommandResponseHandler.java index 6f02180..635e785 100644 --- a/spark-common/src/main/java/me/lucko/spark/common/command/CommandResponseHandler.java +++ b/spark-common/src/main/java/me/lucko/spark/common/command/CommandResponseHandler.java @@ -20,8 +20,8 @@ package me.lucko.spark.common.command; -import me.lucko.spark.common.CommandSender; import me.lucko.spark.common.SparkPlatform; +import me.lucko.spark.common.command.sender.CommandSender; import net.kyori.text.Component; import net.kyori.text.TextComponent; import net.kyori.text.format.TextColor; diff --git a/spark-common/src/main/java/me/lucko/spark/common/command/modules/ActivityLogModule.java b/spark-common/src/main/java/me/lucko/spark/common/command/modules/ActivityLogModule.java index e09dc9d..c78e567 100644 --- a/spark-common/src/main/java/me/lucko/spark/common/command/modules/ActivityLogModule.java +++ b/spark-common/src/main/java/me/lucko/spark/common/command/modules/ActivityLogModule.java @@ -20,7 +20,7 @@ package me.lucko.spark.common.command.modules; -import me.lucko.spark.common.ActivityLog.Activity; +import me.lucko.spark.common.activitylog.ActivityLog.Activity; import me.lucko.spark.common.command.Command; import me.lucko.spark.common.command.CommandModule; import me.lucko.spark.common.command.tabcomplete.TabCompleter; diff --git a/spark-common/src/main/java/me/lucko/spark/common/command/modules/MemoryModule.java b/spark-common/src/main/java/me/lucko/spark/common/command/modules/MemoryModule.java index dcfb0c4..0516f5b 100644 --- a/spark-common/src/main/java/me/lucko/spark/common/command/modules/MemoryModule.java +++ b/spark-common/src/main/java/me/lucko/spark/common/command/modules/MemoryModule.java @@ -20,8 +20,8 @@ package me.lucko.spark.common.command.modules; -import me.lucko.spark.common.ActivityLog.Activity; import me.lucko.spark.common.SparkPlatform; +import me.lucko.spark.common.activitylog.ActivityLog.Activity; import me.lucko.spark.common.command.Command; import me.lucko.spark.common.command.CommandModule; import me.lucko.spark.common.command.tabcomplete.CompletionSupplier; diff --git a/spark-common/src/main/java/me/lucko/spark/common/command/modules/SamplerModule.java b/spark-common/src/main/java/me/lucko/spark/common/command/modules/SamplerModule.java index 9f14e6e..f63d7ba 100644 --- a/spark-common/src/main/java/me/lucko/spark/common/command/modules/SamplerModule.java +++ b/spark-common/src/main/java/me/lucko/spark/common/command/modules/SamplerModule.java @@ -20,8 +20,8 @@ package me.lucko.spark.common.command.modules; -import me.lucko.spark.common.ActivityLog.Activity; import me.lucko.spark.common.SparkPlatform; +import me.lucko.spark.common.activitylog.ActivityLog.Activity; import me.lucko.spark.common.command.Command; import me.lucko.spark.common.command.CommandModule; import me.lucko.spark.common.command.CommandResponseHandler; diff --git a/spark-common/src/main/java/me/lucko/spark/common/command/modules/TickMonitoringModule.java b/spark-common/src/main/java/me/lucko/spark/common/command/modules/TickMonitoringModule.java index da26dea..0ebb252 100644 --- a/spark-common/src/main/java/me/lucko/spark/common/command/modules/TickMonitoringModule.java +++ b/spark-common/src/main/java/me/lucko/spark/common/command/modules/TickMonitoringModule.java @@ -81,7 +81,7 @@ public class TickMonitoringModule implements CommandModule { ); } - private class ReportingTickMonitor extends TickMonitor { + private static class ReportingTickMonitor extends TickMonitor { private final CommandResponseHandler resp; ReportingTickMonitor(SparkPlatform platform, CommandResponseHandler resp, TickCounter tickCounter, int percentageChangeThreshold, boolean monitorGc) { diff --git a/spark-common/src/main/java/me/lucko/spark/common/command/sender/AbstractCommandSender.java b/spark-common/src/main/java/me/lucko/spark/common/command/sender/AbstractCommandSender.java new file mode 100644 index 0000000..ce48889 --- /dev/null +++ b/spark-common/src/main/java/me/lucko/spark/common/command/sender/AbstractCommandSender.java @@ -0,0 +1,42 @@ +/* + * 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.common.command.sender; + +public abstract class AbstractCommandSender<S> implements CommandSender { + protected final S delegate; + + public AbstractCommandSender(S delegate) { + this.delegate = delegate; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + AbstractCommandSender<?> that = (AbstractCommandSender<?>) o; + return this.delegate.equals(that.delegate); + } + + @Override + public int hashCode() { + return this.delegate.hashCode(); + } +} diff --git a/spark-common/src/main/java/me/lucko/spark/common/CommandSender.java b/spark-common/src/main/java/me/lucko/spark/common/command/sender/CommandSender.java index 198bd79..ef56185 100644 --- a/spark-common/src/main/java/me/lucko/spark/common/CommandSender.java +++ b/spark-common/src/main/java/me/lucko/spark/common/command/sender/CommandSender.java @@ -18,7 +18,7 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. */ -package me.lucko.spark.common; +package me.lucko.spark.common.command.sender; import com.google.gson.JsonElement; import com.google.gson.JsonObject; diff --git a/spark-common/src/main/java/me/lucko/spark/common/heapdump/HeapDumpSummary.java b/spark-common/src/main/java/me/lucko/spark/common/heapdump/HeapDumpSummary.java index 53de4e8..137a4fe 100644 --- a/spark-common/src/main/java/me/lucko/spark/common/heapdump/HeapDumpSummary.java +++ b/spark-common/src/main/java/me/lucko/spark/common/heapdump/HeapDumpSummary.java @@ -20,15 +20,12 @@ package me.lucko.spark.common.heapdump; -import me.lucko.spark.common.CommandSender; +import me.lucko.spark.common.command.sender.CommandSender; import me.lucko.spark.common.util.TypeDescriptors; import me.lucko.spark.proto.SparkProtos; import me.lucko.spark.proto.SparkProtos.HeapData; import me.lucko.spark.proto.SparkProtos.HeapEntry; -import javax.management.JMX; -import javax.management.MBeanServer; -import javax.management.ObjectName; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.OutputStream; @@ -41,6 +38,10 @@ import java.util.regex.Pattern; import java.util.stream.Collectors; import java.util.zip.GZIPOutputStream; +import javax.management.JMX; +import javax.management.MBeanServer; +import javax.management.ObjectName; + /** * Represents a "heap dump summary" from the VM. * diff --git a/spark-common/src/main/java/me/lucko/spark/common/monitor/cpu/CpuMonitor.java b/spark-common/src/main/java/me/lucko/spark/common/monitor/cpu/CpuMonitor.java index aa653b7..47e3fac 100644 --- a/spark-common/src/main/java/me/lucko/spark/common/monitor/cpu/CpuMonitor.java +++ b/spark-common/src/main/java/me/lucko/spark/common/monitor/cpu/CpuMonitor.java @@ -22,15 +22,16 @@ package me.lucko.spark.common.monitor.cpu; import me.lucko.spark.common.util.RollingAverage; -import javax.management.JMX; -import javax.management.MBeanServer; -import javax.management.ObjectName; import java.lang.management.ManagementFactory; import java.math.BigDecimal; import java.util.concurrent.Executors; import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.TimeUnit; +import javax.management.JMX; +import javax.management.MBeanServer; +import javax.management.ObjectName; + /** * Exposes and monitors the system/process CPU usage. */ @@ -73,6 +74,7 @@ public enum CpuMonitor { /** * Ensures that the static initializer has been called. */ + @SuppressWarnings("EmptyMethod") public static void ensureMonitoring() { // intentionally empty } diff --git a/spark-common/src/main/java/me/lucko/spark/common/sampler/Sampler.java b/spark-common/src/main/java/me/lucko/spark/common/sampler/Sampler.java index 7418776..033a2d2 100644 --- a/spark-common/src/main/java/me/lucko/spark/common/sampler/Sampler.java +++ b/spark-common/src/main/java/me/lucko/spark/common/sampler/Sampler.java @@ -22,7 +22,7 @@ package me.lucko.spark.common.sampler; import com.google.common.util.concurrent.ThreadFactoryBuilder; -import me.lucko.spark.common.CommandSender; +import me.lucko.spark.common.command.sender.CommandSender; import me.lucko.spark.common.sampler.aggregator.DataAggregator; import me.lucko.spark.common.sampler.aggregator.SimpleDataAggregator; import me.lucko.spark.common.sampler.aggregator.TickedDataAggregator; diff --git a/spark-fabric/src/main/java/me/lucko/spark/fabric/FabricCommandSender.java b/spark-fabric/src/main/java/me/lucko/spark/fabric/FabricCommandSender.java index fea877c..d0bac92 100644 --- a/spark-fabric/src/main/java/me/lucko/spark/fabric/FabricCommandSender.java +++ b/spark-fabric/src/main/java/me/lucko/spark/fabric/FabricCommandSender.java @@ -20,7 +20,7 @@ package me.lucko.spark.fabric; -import me.lucko.spark.common.CommandSender; +import me.lucko.spark.common.command.sender.AbstractCommandSender; import me.lucko.spark.fabric.plugin.FabricSparkPlugin; import net.kyori.text.Component; import net.kyori.text.serializer.gson.GsonComponentSerializer; @@ -31,30 +31,29 @@ import net.minecraft.text.Text; import java.util.UUID; -public class FabricCommandSender implements CommandSender { - private final CommandOutput sender; +public class FabricCommandSender extends AbstractCommandSender<CommandOutput> { private final FabricSparkPlugin plugin; - public FabricCommandSender(CommandOutput sender, FabricSparkPlugin plugin) { - this.sender = sender; + public FabricCommandSender(CommandOutput commandOutput, FabricSparkPlugin plugin) { + super(commandOutput); this.plugin = plugin; } @Override public String getName() { - if (this.sender instanceof PlayerEntity) { - return ((PlayerEntity) this.sender).getGameProfile().getName(); - } else if (this.sender instanceof DedicatedServer) { + if (super.delegate instanceof PlayerEntity) { + return ((PlayerEntity) super.delegate).getGameProfile().getName(); + } else if (super.delegate instanceof DedicatedServer) { return "Console"; } else { - return "unknown:" + this.sender.getClass().getSimpleName(); + return "unknown:" + super.delegate.getClass().getSimpleName(); } } @Override public UUID getUniqueId() { - if (this.sender instanceof PlayerEntity) { - return ((PlayerEntity) this.sender).getUuid(); + if (super.delegate instanceof PlayerEntity) { + return ((PlayerEntity) super.delegate).getUuid(); } return null; } @@ -62,28 +61,11 @@ public class FabricCommandSender implements CommandSender { @Override public void sendMessage(Component message) { Text component = Text.Serializer.fromJson(GsonComponentSerializer.INSTANCE.serialize(message)); - this.sender.sendMessage(component); + super.delegate.sendMessage(component); } @Override public boolean hasPermission(String permission) { - return this.plugin.hasPermission(this.sender, permission); - } - - @Override - public boolean equals(Object o) { - if (this == o) { - return true; - } - if (o == null || getClass() != o.getClass()) { - return false; - } - FabricCommandSender that = (FabricCommandSender) o; - return this.sender.equals(that.sender); - } - - @Override - public int hashCode() { - return this.sender.hashCode(); + return this.plugin.hasPermission(super.delegate, permission); } } 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 ff988f0..4ef5087 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 @@ -20,7 +20,7 @@ package me.lucko.spark.forge; -import me.lucko.spark.common.CommandSender; +import me.lucko.spark.common.command.sender.AbstractCommandSender; import me.lucko.spark.forge.plugin.ForgeSparkPlugin; import net.kyori.text.Component; import net.kyori.text.serializer.gson.GsonComponentSerializer; @@ -31,30 +31,29 @@ import net.minecraft.util.text.ITextComponent; import java.util.UUID; -public class ForgeCommandSender implements CommandSender { - private final ICommandSource sender; +public class ForgeCommandSender extends AbstractCommandSender<ICommandSource> { private final ForgeSparkPlugin plugin; - public ForgeCommandSender(ICommandSource sender, ForgeSparkPlugin plugin) { - this.sender = sender; + public ForgeCommandSender(ICommandSource source, ForgeSparkPlugin plugin) { + super(source); this.plugin = plugin; } @Override public String getName() { - if (this.sender instanceof PlayerEntity) { - return ((PlayerEntity) this.sender).getGameProfile().getName(); - } else if (this.sender instanceof IServer) { + if (super.delegate instanceof PlayerEntity) { + return ((PlayerEntity) super.delegate).getGameProfile().getName(); + } else if (super.delegate instanceof IServer) { return "Console"; } else { - return "unknown:" + this.sender.getClass().getSimpleName(); + return "unknown:" + super.delegate.getClass().getSimpleName(); } } @Override public UUID getUniqueId() { - if (this.sender instanceof PlayerEntity) { - return ((PlayerEntity) this.sender).getUniqueID(); + if (super.delegate instanceof PlayerEntity) { + return ((PlayerEntity) super.delegate).getUniqueID(); } return null; } @@ -62,24 +61,11 @@ public class ForgeCommandSender implements CommandSender { @Override public void sendMessage(Component message) { ITextComponent component = ITextComponent.Serializer.fromJson(GsonComponentSerializer.INSTANCE.serialize(message)); - this.sender.sendMessage(component); + super.delegate.sendMessage(component); } @Override public boolean hasPermission(String permission) { - return this.plugin.hasPermission(this.sender, permission); - } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - ForgeCommandSender that = (ForgeCommandSender) o; - return this.sender.equals(that.sender); - } - - @Override - public int hashCode() { - return this.sender.hashCode(); + return this.plugin.hasPermission(super.delegate, permission); } } diff --git a/spark-sponge/src/main/java/me/lucko/spark/sponge/SpongeCommandSender.java b/spark-sponge/src/main/java/me/lucko/spark/sponge/SpongeCommandSender.java index 6f2c3a2..ca0d5d2 100644 --- a/spark-sponge/src/main/java/me/lucko/spark/sponge/SpongeCommandSender.java +++ b/spark-sponge/src/main/java/me/lucko/spark/sponge/SpongeCommandSender.java @@ -20,7 +20,7 @@ package me.lucko.spark.sponge; -import me.lucko.spark.common.CommandSender; +import me.lucko.spark.common.command.sender.AbstractCommandSender; import net.kyori.text.Component; import net.kyori.text.adapter.spongeapi.TextAdapter; import org.spongepowered.api.command.CommandSource; @@ -28,46 +28,31 @@ import org.spongepowered.api.entity.living.player.Player; import java.util.UUID; -public class SpongeCommandSender implements CommandSender { - private final CommandSource source; - +public class SpongeCommandSender extends AbstractCommandSender<CommandSource> { public SpongeCommandSender(CommandSource source) { - this.source = source; + super(source); } @Override public String getName() { - return this.source.getName(); + return super.delegate.getName(); } @Override public UUID getUniqueId() { - if (this.source instanceof Player) { - return ((Player) this.source).getUniqueId(); + if (super.delegate instanceof Player) { + return ((Player) super.delegate).getUniqueId(); } return null; } @Override public void sendMessage(Component message) { - TextAdapter.sendComponent(this.source, message); + TextAdapter.sendComponent(super.delegate, 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; - SpongeCommandSender that = (SpongeCommandSender) o; - return this.source.equals(that.source); - } - - @Override - public int hashCode() { - return this.source.hashCode(); + return super.delegate.hasPermission(permission); } } 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 index e9b4474..e49e802 100644 --- a/spark-velocity/src/main/java/me/lucko/spark/velocity/VelocityCommandSender.java +++ b/spark-velocity/src/main/java/me/lucko/spark/velocity/VelocityCommandSender.java @@ -23,57 +23,42 @@ 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 me.lucko.spark.common.command.sender.AbstractCommandSender; import net.kyori.text.Component; import java.util.UUID; -public class VelocityCommandSender implements CommandSender { - private final CommandSource source; - +public class VelocityCommandSender extends AbstractCommandSender<CommandSource> { public VelocityCommandSender(CommandSource source) { - this.source = source; + super(source); } @Override public String getName() { - if (this.source instanceof Player) { - return ((Player) this.source).getUsername(); - } else if (this.source instanceof ConsoleCommandSource) { + if (super.delegate instanceof Player) { + return ((Player) super.delegate).getUsername(); + } else if (super.delegate instanceof ConsoleCommandSource) { return "Console"; } else { - return "unknown:" + this.source.getClass().getSimpleName(); + return "unknown:" + super.delegate.getClass().getSimpleName(); } } @Override public UUID getUniqueId() { - if (this.source instanceof Player) { - return ((Player) this.source).getUniqueId(); + if (super.delegate instanceof Player) { + return ((Player) super.delegate).getUniqueId(); } return null; } @Override public void sendMessage(Component message) { - this.source.sendMessage(message); + super.delegate.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(); + return super.delegate.hasPermission(permission); } } |