mirror of
https://github.com/DiscordSRV/Ascension.git
synced 2025-02-14 01:21:25 +01:00
Cleanup code style
This commit is contained in:
parent
d5d96972d8
commit
8095977cc9
@ -22,6 +22,7 @@ import com.discordsrv.common.command.game.abstraction.GameCommandExecutionHelper
|
||||
import com.discordsrv.fabric.FabricDiscordSRV;
|
||||
import com.mojang.brigadier.CommandDispatcher;
|
||||
import com.mojang.brigadier.ParseResults;
|
||||
import com.mojang.brigadier.context.ParsedCommandNode;
|
||||
import com.mojang.brigadier.suggestion.Suggestions;
|
||||
import com.mojang.brigadier.tree.CommandNode;
|
||||
import com.mojang.brigadier.tree.RootCommandNode;
|
||||
@ -35,6 +36,7 @@ import java.util.concurrent.ExecutionException;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class FabricGameCommandExecutionHelper implements GameCommandExecutionHelper {
|
||||
|
||||
protected final FabricDiscordSRV discordSRV;
|
||||
private final CommandDispatcher<ServerCommandSource> dispatcher;
|
||||
|
||||
@ -60,8 +62,9 @@ public class FabricGameCommandExecutionHelper implements GameCommandExecutionHel
|
||||
return CompletableFuture.completedFuture(data);
|
||||
}
|
||||
|
||||
if (!parse.getContext().getNodes().isEmpty()) {
|
||||
CommandNode<ServerCommandSource> lastNode = parse.getContext().getNodes().getLast().getNode();
|
||||
List<ParsedCommandNode<ServerCommandSource>> nodes = parse.getContext().getNodes();
|
||||
if (!nodes.isEmpty()) {
|
||||
CommandNode<ServerCommandSource> lastNode = nodes.getLast().getNode();
|
||||
if (lastNode.getChildren().isEmpty() && lastNode.getRedirect() == null) {
|
||||
// We reached the end of the command tree. Suggest the full command as a valid command.
|
||||
return CompletableFuture.completedFuture(Collections.singletonList(fullCommand));
|
||||
@ -75,7 +78,7 @@ public class FabricGameCommandExecutionHelper implements GameCommandExecutionHel
|
||||
if (data.isEmpty()) {
|
||||
// Suggestions are empty, Likely the user is still typing an argument.
|
||||
// If the context is empty, We search all commands from the root.
|
||||
CommandNode<ServerCommandSource> lastNode = !parse.getContext().getNodes().isEmpty() ? parse.getContext().getNodes().getLast().getNode() : parse.getContext().getRootNode();
|
||||
CommandNode<ServerCommandSource> lastNode = !nodes.isEmpty() ? nodes.getLast().getNode() : parse.getContext().getRootNode();
|
||||
|
||||
for (CommandNode<ServerCommandSource> child : lastNode.getChildren()) {
|
||||
if (child.getName().toLowerCase().startsWith(parts.getLast().toLowerCase())) {
|
||||
@ -112,7 +115,12 @@ public class FabricGameCommandExecutionHelper implements GameCommandExecutionHel
|
||||
}
|
||||
|
||||
private CompletableFuture<List<String>> getRootCommands() {
|
||||
return CompletableFuture.completedFuture(dispatcher.getRoot().getChildren().stream().map(CommandNode::getName).collect(Collectors.toList()));
|
||||
return CompletableFuture.completedFuture(
|
||||
dispatcher.getRoot().getChildren()
|
||||
.stream()
|
||||
.map(CommandNode::getName)
|
||||
.collect(Collectors.toList())
|
||||
);
|
||||
}
|
||||
|
||||
// Split the error message if it's too long on a period or a comma. If the message reached 97 characters, split at that point and continue.
|
||||
@ -143,5 +151,4 @@ public class FabricGameCommandExecutionHelper implements GameCommandExecutionHel
|
||||
|
||||
return parts;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -41,7 +41,8 @@ public class FabricConsole extends FabricCommandSender implements Console {
|
||||
super(discordSRV, discordSRV.getServer().getCommandSource());
|
||||
this.loggingBackend = Log4JLoggerImpl.getRoot();
|
||||
|
||||
Function<Consumer<Component>, ServerCommandSource> commandSenderProvider = consumer -> new FabricCommandFeedbackExecutor(discordSRV.getServer(), consumer).getCommandSource();
|
||||
Function<Consumer<Component>, ServerCommandSource> commandSenderProvider =
|
||||
consumer -> new FabricCommandFeedbackExecutor(discordSRV.getServer(), consumer).getCommandSource();
|
||||
this.executorProvider = consumer -> new FabricCommandExecutor(discordSRV, commandSenderProvider.apply(consumer));
|
||||
}
|
||||
|
||||
|
@ -43,7 +43,15 @@ public class FabricCommandFeedbackExecutor implements CommandOutput, Consumer<Co
|
||||
public ServerCommandSource getCommandSource() {
|
||||
ServerWorld serverWorld = server.getOverworld();
|
||||
return new ServerCommandSource(
|
||||
this, serverWorld == null ? Vec3d.ZERO : Vec3d.of(serverWorld.getSpawnPos()), Vec2f.ZERO, serverWorld, 4, "DiscordSRV", Text.literal("DiscordSRV"), server, null
|
||||
this,
|
||||
serverWorld == null ? Vec3d.ZERO : Vec3d.of(serverWorld.getSpawnPos()),
|
||||
Vec2f.ZERO,
|
||||
serverWorld,
|
||||
4,
|
||||
"DiscordSRV",
|
||||
Text.literal("DiscordSRV"),
|
||||
server,
|
||||
null
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -30,6 +30,7 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
||||
|
||||
@Mixin(PlayerAdvancementTracker.class)
|
||||
public class PlayerAdvancementTrackerMixin {
|
||||
|
||||
@Shadow
|
||||
private ServerPlayerEntity owner;
|
||||
|
||||
|
@ -22,6 +22,7 @@ import com.discordsrv.common.core.module.type.AbstractModule;
|
||||
import com.discordsrv.fabric.FabricDiscordSRV;
|
||||
|
||||
public abstract class AbstractFabricModule extends AbstractModule<FabricDiscordSRV> {
|
||||
|
||||
protected boolean enabled = false;
|
||||
|
||||
public AbstractFabricModule(FabricDiscordSRV discordSRV) {
|
||||
|
@ -21,6 +21,7 @@ package com.discordsrv.fabric.module.ban;
|
||||
import com.discordsrv.api.component.MinecraftComponent;
|
||||
import com.discordsrv.api.module.type.PunishmentModule;
|
||||
import com.discordsrv.api.punishment.Punishment;
|
||||
import com.discordsrv.common.abstraction.player.IPlayer;
|
||||
import com.discordsrv.common.feature.bansync.BanSyncModule;
|
||||
import com.discordsrv.common.util.ComponentUtil;
|
||||
import com.discordsrv.fabric.FabricDiscordSRV;
|
||||
@ -43,6 +44,7 @@ import java.util.UUID;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
public class FabricBanModule extends AbstractFabricModule implements PunishmentModule.Bans {
|
||||
|
||||
private static FabricBanModule instance;
|
||||
|
||||
public FabricBanModule(FabricDiscordSRV discordSRV) {
|
||||
@ -55,13 +57,19 @@ public class FabricBanModule extends AbstractFabricModule implements PunishmentM
|
||||
if (instance == null) return;
|
||||
FabricDiscordSRV discordSRV = instance.discordSRV;
|
||||
BanSyncModule module = discordSRV.getModule(BanSyncModule.class);
|
||||
if (module != null) {
|
||||
instance.getBan(gameProfile.getId())
|
||||
.whenComplete((punishment, t) -> {
|
||||
if (punishment != null)
|
||||
module.notifyBanned(Objects.requireNonNull(discordSRV.playerProvider().player(gameProfile.getId())), punishment);
|
||||
});
|
||||
if (module == null) return;
|
||||
|
||||
UUID playerUUID = gameProfile.getId();
|
||||
IPlayer player = discordSRV.playerProvider().player(gameProfile.getId());
|
||||
if (player == null) {
|
||||
throw new RuntimeException("Player " + playerUUID + " not present in player provider");
|
||||
}
|
||||
|
||||
instance.getBan(playerUUID).whenComplete((punishment, t) -> {
|
||||
if (punishment != null) {
|
||||
module.notifyBanned(player, punishment);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public static void onPardon(GameProfile gameProfile) {
|
||||
@ -122,7 +130,11 @@ public class FabricBanModule extends AbstractFabricModule implements PunishmentM
|
||||
|
||||
ServerPlayerEntity serverPlayerEntity = server.getPlayerManager().getPlayer(playerUUID);
|
||||
if (serverPlayerEntity != null) {
|
||||
serverPlayerEntity.networkHandler.disconnect(reason != null ? discordSRV.getAdventure().asNative(reason.asAdventure()) : Text.translatable("multiplayer.disconnect.banned"));
|
||||
serverPlayerEntity.networkHandler.disconnect(
|
||||
reason != null
|
||||
? discordSRV.getAdventure().asNative(reason.asAdventure())
|
||||
: Text.translatable("multiplayer.disconnect.banned")
|
||||
);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
discordSRV.logger().error("Failed to ban player", e);
|
||||
|
@ -29,6 +29,7 @@ import net.minecraft.advancement.AdvancementEntry;
|
||||
import net.minecraft.server.network.ServerPlayerEntity;
|
||||
|
||||
public class FabricAdvancementModule extends AbstractFabricModule {
|
||||
|
||||
private static FabricAdvancementModule instance;
|
||||
private final FabricDiscordSRV discordSRV;
|
||||
|
||||
|
@ -29,6 +29,7 @@ import net.minecraft.network.message.SignedMessage;
|
||||
import net.minecraft.server.network.ServerPlayerEntity;
|
||||
|
||||
public class FabricChatModule extends AbstractFabricModule {
|
||||
|
||||
private final FabricDiscordSRV discordSRV;
|
||||
|
||||
public FabricChatModule(FabricDiscordSRV discordSRV) {
|
||||
|
@ -31,6 +31,7 @@ import net.minecraft.server.network.ServerPlayerEntity;
|
||||
import net.minecraft.text.Text;
|
||||
|
||||
public class FabricDeathModule extends AbstractFabricModule {
|
||||
|
||||
private final FabricDiscordSRV discordSRV;
|
||||
|
||||
public FabricDeathModule(FabricDiscordSRV discordSRV) {
|
||||
@ -60,5 +61,4 @@ public class FabricDeathModule extends AbstractFabricModule {
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -35,6 +35,7 @@ import net.minecraft.text.Text;
|
||||
import java.util.Objects;
|
||||
|
||||
public class FabricJoinModule extends AbstractFabricModule {
|
||||
|
||||
private final FabricDiscordSRV discordSRV;
|
||||
|
||||
public FabricJoinModule(FabricDiscordSRV discordSRV) {
|
||||
@ -51,7 +52,7 @@ public class FabricJoinModule extends AbstractFabricModule {
|
||||
|
||||
ServerPlayerEntity playerEntity = serverPlayNetworkHandler.player;
|
||||
MinecraftComponent component = getJoinMessage(playerEntity);
|
||||
boolean firstJoin = Objects.requireNonNull(minecraftServer.getUserCache()).findByName(serverPlayNetworkHandler.player.getGameProfile().getName()).isEmpty();
|
||||
boolean firstJoin = Objects.requireNonNull(minecraftServer.getUserCache()).findByName(playerEntity.getGameProfile().getName()).isEmpty();
|
||||
|
||||
DiscordSRVPlayer player = discordSRV.playerProvider().player(playerEntity);
|
||||
discordSRV.eventBus().publish(
|
||||
|
@ -32,6 +32,7 @@ import net.minecraft.text.Text;
|
||||
import net.minecraft.util.Formatting;
|
||||
|
||||
public class FabricQuitModule extends AbstractFabricModule {
|
||||
|
||||
private final FabricDiscordSRV discordSRV;
|
||||
|
||||
public FabricQuitModule(FabricDiscordSRV discordSRV) {
|
||||
|
@ -99,5 +99,4 @@ public class FabricPlayer extends FabricCommandSender implements IPlayer {
|
||||
public String toString() {
|
||||
return "FabricPlayer{" + username() + "}";
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -27,6 +27,7 @@ import net.minecraft.server.network.ServerPlayNetworkHandler;
|
||||
import net.minecraft.server.network.ServerPlayerEntity;
|
||||
|
||||
public class FabricPlayerProvider extends AbstractPlayerProvider<FabricPlayer, FabricDiscordSRV> {
|
||||
|
||||
private boolean enabled = false;
|
||||
|
||||
public FabricPlayerProvider(FabricDiscordSRV discordSRV) {
|
||||
@ -39,8 +40,9 @@ public class FabricPlayerProvider extends AbstractPlayerProvider<FabricPlayer, F
|
||||
@Override
|
||||
public void subscribe() {
|
||||
enabled = true;
|
||||
if (discordSRV.getServer() == null || discordSRV.getServer().getPlayerManager() == null)
|
||||
if (discordSRV.getServer() == null || discordSRV.getServer().getPlayerManager() == null) {
|
||||
return; // Server not started yet, So there's no players to add
|
||||
}
|
||||
|
||||
// Add players that are already connected
|
||||
for (ServerPlayerEntity player : discordSRV.getServer().getPlayerManager().getPlayerList()) {
|
||||
|
@ -43,7 +43,9 @@ public class FabricModManager implements PluginManager {
|
||||
id,
|
||||
modContainer.getMetadata().getName(),
|
||||
modContainer.getMetadata().getVersion().toString(),
|
||||
modContainer.getMetadata().getAuthors().stream().map(Person::getName).collect(Collectors.toList())
|
||||
modContainer.getMetadata().getAuthors().stream()
|
||||
.map(Person::getName)
|
||||
.collect(Collectors.toList())
|
||||
);
|
||||
})
|
||||
.collect(Collectors.toList());
|
||||
|
@ -55,6 +55,7 @@ import java.util.concurrent.CopyOnWriteArrayList;
|
||||
|
||||
|
||||
public class FabricRequiredLinkingModule extends ServerRequireLinkingModule<FabricDiscordSRV> {
|
||||
|
||||
private static FabricRequiredLinkingModule instance;
|
||||
private final Cache<UUID, Boolean> linkCheckRateLimit;
|
||||
private final Map<UUID, Component> frozen = new ConcurrentHashMap<>();
|
||||
@ -113,7 +114,11 @@ public class FabricRequiredLinkingModule extends ServerRequireLinkingModule<Fabr
|
||||
}
|
||||
|
||||
BlockPos from = player.getBlockPos();
|
||||
BlockPos to = new BlockPos(MathHelper.floor(packet.getX(player.getX())), MathHelper.floor(packet.getY(player.getY())), MathHelper.floor(packet.getZ(player.getZ())));
|
||||
BlockPos to = new BlockPos(
|
||||
MathHelper.floor(packet.getX(player.getX())),
|
||||
MathHelper.floor(packet.getY(player.getY())),
|
||||
MathHelper.floor(packet.getZ(player.getZ()))
|
||||
);
|
||||
if (from.getX() == to.getX() && from.getY() >= to.getY() && from.getZ() == to.getZ()) {
|
||||
return;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user