Clean up code

This commit is contained in:
Alessandro Proto 2024-10-23 22:07:12 +02:00
parent abb5a00182
commit 61b5fffcd4
13 changed files with 21 additions and 33 deletions

View file

@ -16,7 +16,7 @@ public class AfkCommand {
.requires(Permissions.require("rcc.command.afk", true)) .requires(Permissions.require("rcc.command.afk", true))
.executes(context -> { .executes(context -> {
if(!context.getSource().isExecutedByPlayer()) { if (!context.getSource().isExecutedByPlayer()) {
context.getSource().sendFeedback(() -> Text.of("This command can only be executed by players!"), false); context.getSource().sendFeedback(() -> Text.of("This command can only be executed by players!"), false);
return 1; return 1;
} }

View file

@ -1,7 +1,6 @@
package cc.reconnected.server.commands; package cc.reconnected.server.commands;
import cc.reconnected.server.RccServer; import cc.reconnected.server.RccServer;
import cc.reconnected.server.struct.ServerPosition;
import com.mojang.brigadier.CommandDispatcher; import com.mojang.brigadier.CommandDispatcher;
import me.lucko.fabric.api.permissions.v0.Permissions; import me.lucko.fabric.api.permissions.v0.Permissions;
import net.minecraft.command.CommandRegistryAccess; import net.minecraft.command.CommandRegistryAccess;
@ -17,7 +16,7 @@ public class BackCommand {
var rootCommand = literal("back") var rootCommand = literal("back")
.requires(Permissions.require("rcc.command.back", true)) .requires(Permissions.require("rcc.command.back", true))
.executes(context -> { .executes(context -> {
if(!context.getSource().isExecutedByPlayer()) { if (!context.getSource().isExecutedByPlayer()) {
context.getSource().sendFeedback(() -> Text.of("This command can only be executed by players!"), false); context.getSource().sendFeedback(() -> Text.of("This command can only be executed by players!"), false);
return 1; return 1;
} }
@ -25,7 +24,7 @@ public class BackCommand {
var player = context.getSource().getPlayer(); var player = context.getSource().getPlayer();
var lastPosition = RccServer.lastPlayerPositions.get(player.getUuid()); var lastPosition = RccServer.lastPlayerPositions.get(player.getUuid());
if(lastPosition == null) { if (lastPosition == null) {
context.getSource().sendFeedback(() -> Text.literal("There is no position to return back to.").formatted(Formatting.RED), false); context.getSource().sendFeedback(() -> Text.literal("There is no position to return back to.").formatted(Formatting.RED), false);
return 1; return 1;
} }

View file

@ -40,7 +40,7 @@ public class FlyCommand {
.executes(context -> { .executes(context -> {
var playerName = StringArgumentType.getString(context, "player"); var playerName = StringArgumentType.getString(context, "player");
var player = context.getSource().getServer().getPlayerManager().getPlayer(playerName); var player = context.getSource().getServer().getPlayerManager().getPlayer(playerName);
if(player == null) { if (player == null) {
context.getSource().sendFeedback(() -> Text.literal("Player not found").setStyle(Style.EMPTY.withColor(Formatting.RED)), false); context.getSource().sendFeedback(() -> Text.literal("Player not found").setStyle(Style.EMPTY.withColor(Formatting.RED)), false);
return 1; return 1;
} }

View file

@ -39,7 +39,7 @@ public class GodCommand {
.executes(context -> { .executes(context -> {
var playerName = StringArgumentType.getString(context, "player"); var playerName = StringArgumentType.getString(context, "player");
var player = context.getSource().getServer().getPlayerManager().getPlayer(playerName); var player = context.getSource().getServer().getPlayerManager().getPlayer(playerName);
if(player == null) { if (player == null) {
context.getSource().sendFeedback(() -> Text.literal("Player not found").setStyle(Style.EMPTY.withColor(Formatting.RED)), false); context.getSource().sendFeedback(() -> Text.literal("Player not found").setStyle(Style.EMPTY.withColor(Formatting.RED)), false);
return 1; return 1;
} }

View file

@ -29,7 +29,7 @@ public class ReplyCommand {
var senderName = source.getName(); var senderName = source.getName();
var message = StringArgumentType.getString(context, "message"); var message = StringArgumentType.getString(context, "message");
if(!TellCommand.lastSender.containsKey(senderName)) { if (!TellCommand.lastSender.containsKey(senderName)) {
source.sendFeedback(() -> Text.literal("You have no one to reply to.").setStyle(Style.EMPTY.withColor(Formatting.RED)), false); source.sendFeedback(() -> Text.literal("You have no one to reply to.").setStyle(Style.EMPTY.withColor(Formatting.RED)), false);
return 1; return 1;
} }

View file

@ -2,22 +2,15 @@ package cc.reconnected.server.commands;
import cc.reconnected.server.RccServer; import cc.reconnected.server.RccServer;
import com.mojang.brigadier.CommandDispatcher; import com.mojang.brigadier.CommandDispatcher;
import com.mojang.brigadier.arguments.StringArgumentType;
import com.mojang.brigadier.context.CommandContext; import com.mojang.brigadier.context.CommandContext;
import net.fabricmc.fabric.api.event.lifecycle.v1.ServerTickEvents;
import net.minecraft.command.CommandRegistryAccess; import net.minecraft.command.CommandRegistryAccess;
import net.minecraft.command.CommandSource;
import net.minecraft.command.argument.UuidArgumentType; import net.minecraft.command.argument.UuidArgumentType;
import net.minecraft.server.command.CommandManager; import net.minecraft.server.command.CommandManager;
import net.minecraft.server.command.ServerCommandSource; import net.minecraft.server.command.ServerCommandSource;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.text.Style; import net.minecraft.text.Style;
import net.minecraft.text.Text; import net.minecraft.text.Text;
import net.minecraft.util.Formatting; import net.minecraft.util.Formatting;
import java.util.ArrayList;
import java.util.HashMap;
import static net.minecraft.server.command.CommandManager.*; import static net.minecraft.server.command.CommandManager.*;
public class TeleportAcceptCommand { public class TeleportAcceptCommand {
@ -85,7 +78,7 @@ public class TeleportAcceptCommand {
return; return;
} }
if(player.getUuid().equals(request.target)) { if (player.getUuid().equals(request.target)) {
// accepted a tpa from other to self // accepted a tpa from other to self
context.getSource().sendFeedback(() -> Text.literal("Teleport request accepted.").formatted(Formatting.GREEN), false); context.getSource().sendFeedback(() -> Text.literal("Teleport request accepted.").formatted(Formatting.GREEN), false);
sourcePlayer.sendMessage(Text.literal("Teleporting...").formatted(Formatting.GOLD), false); sourcePlayer.sendMessage(Text.literal("Teleporting...").formatted(Formatting.GOLD), false);

View file

@ -5,8 +5,6 @@ import cc.reconnected.server.struct.ServerPosition;
import com.mojang.brigadier.CommandDispatcher; import com.mojang.brigadier.CommandDispatcher;
import com.mojang.brigadier.arguments.StringArgumentType; import com.mojang.brigadier.arguments.StringArgumentType;
import com.mojang.brigadier.context.CommandContext; import com.mojang.brigadier.context.CommandContext;
import net.fabricmc.fabric.api.event.lifecycle.v1.ServerTickEvents;
import net.kyori.adventure.audience.Audience;
import net.kyori.adventure.text.Component; import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.ComponentLike; import net.kyori.adventure.text.ComponentLike;
import net.kyori.adventure.text.event.ClickCallback; import net.kyori.adventure.text.event.ClickCallback;
@ -63,7 +61,7 @@ public class TeleportAskCommand {
} }
var request = new TeleportRequest(player.getUuid(), target.getUuid()); var request = new TeleportRequest(player.getUuid(), target.getUuid());
var targetRequests = RccServer.teleportRequests.get(target.getUuid()); var targetRequests = RccServer.teleportRequests.get(target.getUuid());
targetRequests.addLast(request); targetRequests.addLast(request);
var requestMessage = Component.empty() var requestMessage = Component.empty()
@ -81,11 +79,6 @@ public class TeleportAskCommand {
} }
public static Component makeButton(ComponentLike text, ComponentLike hoverText, String command) { public static Component makeButton(ComponentLike text, ComponentLike hoverText, String command) {
var options = ClickCallback.Options.builder()
.uses(1)
.lifetime(Duration.ofSeconds(RccServer.CONFIG.teleportRequestTimeout()))
.build();
return Component.empty() return Component.empty()
.append(Component.text("[")) .append(Component.text("["))
.append(text) .append(text)

View file

@ -53,7 +53,7 @@ public class TeleportAskHereCommand {
} }
var request = new TeleportAskCommand.TeleportRequest(target.getUuid(), player.getUuid()); var request = new TeleportAskCommand.TeleportRequest(target.getUuid(), player.getUuid());
var targetRequests = RccServer.teleportRequests.get(target.getUuid()); var targetRequests = RccServer.teleportRequests.get(target.getUuid());
targetRequests.addLast(request); targetRequests.addLast(request);
var requestMessage = Component.empty() var requestMessage = Component.empty()

View file

@ -12,8 +12,6 @@ import net.minecraft.text.Style;
import net.minecraft.text.Text; import net.minecraft.text.Text;
import net.minecraft.util.Formatting; import net.minecraft.util.Formatting;
import java.util.ArrayList;
import static net.minecraft.server.command.CommandManager.argument; import static net.minecraft.server.command.CommandManager.argument;
import static net.minecraft.server.command.CommandManager.literal; import static net.minecraft.server.command.CommandManager.literal;
@ -81,7 +79,7 @@ public class TeleportDenyCommand {
otherPlayer = playerManager.getPlayer(request.target); otherPlayer = playerManager.getPlayer(request.target);
} }
if(otherPlayer != null) { if (otherPlayer != null) {
otherPlayer.sendMessage(Text.empty().append(player.getDisplayName()).append(Text.literal(" denied your teleport request.").formatted(Formatting.RED))); otherPlayer.sendMessage(Text.empty().append(player.getDisplayName()).append(Text.literal(" denied your teleport request.").formatted(Formatting.RED)));
} }
context.getSource().sendFeedback(() -> Text.literal("You denied the teleport request.").formatted(Formatting.GOLD), false); context.getSource().sendFeedback(() -> Text.literal("You denied the teleport request.").formatted(Formatting.GOLD), false);

View file

@ -78,9 +78,9 @@ public class TellCommand {
if (!source.getName().equals(targetName)) { if (!source.getName().equals(targetName)) {
source.sendMessage(text); source.sendMessage(text);
} }
if(targetPlayer != null) { if (targetPlayer != null) {
targetPlayer.sendMessage(text); targetPlayer.sendMessage(text);
if(source.isExecutedByPlayer()) { if (source.isExecutedByPlayer()) {
source.getServer().sendMessage(text); source.getServer().sendMessage(text);
} }
} else { } else {
@ -96,13 +96,14 @@ public class TellCommand {
Placeholder.component("message", parsedMessage.toText())); Placeholder.component("message", parsedMessage.toText()));
source.getServer().getPlayerManager().getPlayerList().forEach(player -> { source.getServer().getPlayerManager().getPlayerList().forEach(player -> {
var playerName = player.getGameProfile().getName(); var playerName = player.getGameProfile().getName();
if(playerName.equals(targetName) || playerName.equals(source.getName())) { if (playerName.equals(targetName) || playerName.equals(source.getName())) {
return; return;
} }
var playerPerms = playerAdapter.getPermissionData(player); var playerPerms = playerAdapter.getPermissionData(player);
if(playerPerms.checkPermission("rcc.tell.spy").asBoolean()) { if (playerPerms.checkPermission("rcc.tell.spy").asBoolean()) {
player.sendMessage(spyText); player.sendMessage(spyText);
}; }
;
}); });
} }
} }

View file

@ -103,6 +103,7 @@ public class PlayerData {
public @Nullable MetaNode getNode(String key) { public @Nullable MetaNode getNode(String key) {
return rawNodes.stream().filter(rawNode -> rawNode.getMetaKey().equals(key)).findFirst().orElse(null); return rawNodes.stream().filter(rawNode -> rawNode.getMetaKey().equals(key)).findFirst().orElse(null);
} }
@SuppressWarnings("UnusedReturnValue") @SuppressWarnings("UnusedReturnValue")
public CompletableFuture<Void> setBoolean(String key, boolean value) { public CompletableFuture<Void> setBoolean(String key, boolean value) {
return set(key, Boolean.toString(value)); return set(key, Boolean.toString(value));
@ -119,6 +120,7 @@ public class PlayerData {
return defaultValue; return defaultValue;
return Boolean.parseBoolean(nodes.get(nodePrefix + "." + key)); return Boolean.parseBoolean(nodes.get(nodePrefix + "." + key));
} }
@SuppressWarnings("UnusedReturnValue") @SuppressWarnings("UnusedReturnValue")
public CompletableFuture<Void> setDate(String key, Date date) { public CompletableFuture<Void> setDate(String key, Date date) {
var dateString = DateTimeFormatter.ISO_INSTANT.format(date.toInstant()); var dateString = DateTimeFormatter.ISO_INSTANT.format(date.toInstant());
@ -132,6 +134,7 @@ public class PlayerData {
var ta = DateTimeFormatter.ISO_INSTANT.parse(dateString); var ta = DateTimeFormatter.ISO_INSTANT.parse(dateString);
return Date.from(Instant.from(ta)); return Date.from(Instant.from(ta));
} }
@SuppressWarnings("UnusedReturnValue") @SuppressWarnings("UnusedReturnValue")
public CompletableFuture<Void> delete(String key) { public CompletableFuture<Void> delete(String key) {
return luckPerms().getUserManager().modifyUser(uuid, user -> { return luckPerms().getUserManager().modifyUser(uuid, user -> {

View file

@ -10,6 +10,7 @@ import java.net.InetSocketAddress;
public class ServiceServer { public class ServiceServer {
private final HttpServer server; private final HttpServer server;
public HttpServer httpServer() { public HttpServer httpServer() {
return this.server; return this.server;
} }

View file

@ -7,7 +7,7 @@ import static eu.pb4.placeholders.api.parsers.MarkdownLiteParserV1.MarkdownForma
public class MarkdownParser { public class MarkdownParser {
public static final MarkdownFormat[] ALL = new MarkdownFormat[] { public static final MarkdownFormat[] ALL = new MarkdownFormat[]{
MarkdownFormat.QUOTE, MarkdownFormat.QUOTE,
MarkdownFormat.BOLD, MarkdownFormat.BOLD,
MarkdownFormat.ITALIC, MarkdownFormat.ITALIC,