mirror of
https://github.com/DiscordSRV/Ascension.git
synced 2025-02-22 02:41:23 +01:00
Handling ban pardon
This commit is contained in:
parent
d98e12f241
commit
01287a37bd
@ -0,0 +1,41 @@
|
||||
/*
|
||||
* This file is part of DiscordSRV, licensed under the GPLv3 License
|
||||
* Copyright (c) 2016-2025 Austin "Scarsz" Shapiro, Henri "Vankka" Schubin and DiscordSRV 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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.discordsrv.fabric.mixin.ban;
|
||||
|
||||
import com.discordsrv.fabric.module.ban.FabricBanModule;
|
||||
import com.llamalad7.mixinextras.sugar.Local;
|
||||
import com.mojang.authlib.GameProfile;
|
||||
import net.minecraft.server.command.ServerCommandSource;
|
||||
import net.minecraft.server.dedicated.command.BanCommand;
|
||||
import net.minecraft.server.dedicated.command.PardonCommand;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
@Mixin(PardonCommand.class)
|
||||
public class PardonCommandMixin {
|
||||
|
||||
@Inject(method = "pardon", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/BannedPlayerList;remove(Ljava/lang/Object;)V"))
|
||||
private static void pardon(ServerCommandSource source, Collection<GameProfile> targets, CallbackInfoReturnable<Integer> cir, @Local GameProfile gameProfile) {
|
||||
FabricBanModule.onPardon(gameProfile);
|
||||
}
|
||||
}
|
@ -56,6 +56,7 @@ public class FabricBanModule extends AbstractFabricModule implements PunishmentM
|
||||
}
|
||||
|
||||
public static void onBan(GameProfile gameProfile) {
|
||||
if (instance == null) return;
|
||||
FabricDiscordSRV discordSRV = instance.discordSRV;
|
||||
BanSyncModule module = discordSRV.getModule(BanSyncModule.class);
|
||||
if (module != null) {
|
||||
@ -64,12 +65,19 @@ public class FabricBanModule extends AbstractFabricModule implements PunishmentM
|
||||
}
|
||||
}
|
||||
|
||||
public static void onPardon(GameProfile gameProfile) {
|
||||
if (instance == null) return;
|
||||
FabricDiscordSRV discordSRV = instance.discordSRV;
|
||||
BanSyncModule module = discordSRV.getModule(BanSyncModule.class);
|
||||
if (module != null) instance.removeBan(gameProfile.getId()).complete(null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompletableFuture<@Nullable Punishment> getBan(@NotNull UUID playerUUID) {
|
||||
BannedPlayerList banList = discordSRV.getServer().getPlayerManager().getUserBanList();
|
||||
|
||||
Optional<GameProfile> gameProfile = Objects.requireNonNull(discordSRV.getServer().getUserCache()).getByUuid(playerUUID);
|
||||
if (!gameProfile.isPresent()) {
|
||||
if (gameProfile.isEmpty()) {
|
||||
return CompletableFuture.completedFuture(null);
|
||||
}
|
||||
|
||||
@ -94,11 +102,6 @@ public class FabricBanModule extends AbstractFabricModule implements PunishmentM
|
||||
@NotNull MinecraftComponent punisher
|
||||
) {
|
||||
try {
|
||||
String reasonLegacy = reason != null ? ComponentUtil.fromAPI(reason).toString() : null;
|
||||
String punisherLegacy = ComponentUtil.fromAPI(punisher).toString();
|
||||
|
||||
BannedPlayerList banList = discordSRV.getServer().getPlayerManager().getUserBanList();
|
||||
|
||||
discordSRV.getServer().getPlayerManager().getUserBanList().add(new BannedPlayerEntry(
|
||||
discordSRV.getServer().getUserCache().getByUuid(playerUUID).get(),
|
||||
null,
|
||||
@ -123,7 +126,7 @@ public class FabricBanModule extends AbstractFabricModule implements PunishmentM
|
||||
BannedPlayerList banList = discordSRV.getServer().getPlayerManager().getUserBanList();
|
||||
|
||||
Optional<GameProfile> gameProfile = Objects.requireNonNull(discordSRV.getServer().getUserCache()).getByUuid(playerUUID);
|
||||
if (!gameProfile.isPresent()) {
|
||||
if (gameProfile.isEmpty()) {
|
||||
return CompletableFuture.completedFuture(null);
|
||||
}
|
||||
|
||||
|
@ -5,6 +5,7 @@
|
||||
"mixins": [
|
||||
"PlayerAdvancementTrackerMixin",
|
||||
"ban.BanCommandMixin",
|
||||
"ban.PardonCommandMixin",
|
||||
"requiredlinking.CommandManagerMixin",
|
||||
"requiredlinking.PlayerManagerMixin",
|
||||
"requiredlinking.ServerPlayNetworkHandlerMixin"
|
||||
|
Loading…
Reference in New Issue
Block a user