-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #63 from Foxikle/feat/moderation
Feat/moderation
- Loading branch information
Showing
26 changed files
with
1,255 additions
and
452 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package net.cytonic.cytosis; | ||
|
||
import lombok.Getter; | ||
import net.cytonic.cytosis.data.RedisDatabase; | ||
|
||
import java.util.HashSet; | ||
import java.util.Set; | ||
import java.util.UUID; | ||
|
||
/** | ||
* A class that holds data about the status of the Cytonic network | ||
*/ | ||
@Getter | ||
public class CytonicNetwork { | ||
private final Set<String> networkPlayers = new HashSet<>(); | ||
private final Set<UUID> networkPlayerUUIDs = new HashSet<>(); | ||
|
||
public void importDataFromRedis(RedisDatabase redisDatabase) { | ||
networkPlayers.clear(); | ||
networkPlayerUUIDs.clear(); | ||
networkPlayers.addAll(redisDatabase.getOnlinePlayers()); | ||
networkPlayerUUIDs.addAll(redisDatabase.getOnlineUUIDs()); | ||
} | ||
|
||
public void addPlayer(String name, UUID uuid) { | ||
networkPlayers.add(name); | ||
networkPlayerUUIDs.add(uuid); | ||
} | ||
|
||
public void removePlayer(String name, UUID uuid) { | ||
networkPlayers.remove(name); | ||
networkPlayerUUIDs.remove(uuid); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package net.cytonic.cytosis.auditlog; | ||
|
||
public enum Category { | ||
BAN, | ||
UNBAN, | ||
MUTE, | ||
UNMUTE, | ||
IPBAN, | ||
IPUNBAN | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package net.cytonic.cytosis.auditlog; | ||
|
||
import java.util.UUID; | ||
|
||
public record Entry(UUID uuid, UUID actor, Category category, String reason) { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
101 changes: 101 additions & 0 deletions
101
src/main/java/net/cytonic/cytosis/commands/moderation/BanCommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
package net.cytonic.cytosis.commands.moderation; | ||
|
||
import net.cytonic.cytosis.Cytosis; | ||
import net.cytonic.cytosis.auditlog.Category; | ||
import net.cytonic.cytosis.auditlog.Entry; | ||
import net.cytonic.cytosis.enums.BanReason; | ||
import net.cytonic.cytosis.logging.Logger; | ||
import net.cytonic.cytosis.messaging.KickReason; | ||
import net.cytonic.cytosis.utils.BanData; | ||
import net.cytonic.cytosis.utils.DurationParser; | ||
import net.cytonic.cytosis.utils.MessageUtils; | ||
import net.cytonic.cytosis.utils.OfflinePlayer; | ||
import net.minestom.server.command.builder.Command; | ||
import net.minestom.server.command.builder.arguments.ArgumentEnum; | ||
import net.minestom.server.command.builder.arguments.ArgumentType; | ||
import net.minestom.server.command.builder.suggestion.SuggestionEntry; | ||
import net.minestom.server.entity.Player; | ||
|
||
import java.time.Instant; | ||
|
||
import static net.cytonic.cytosis.utils.MiniMessageTemplate.MM; | ||
|
||
public class BanCommand extends Command { | ||
public BanCommand() { | ||
super("ban"); | ||
setCondition((sender, _) -> sender.hasPermission("cytosis.commands.moderation.ban")); | ||
|
||
var playerArg = ArgumentType.Word("target"); | ||
System.out.println(playerArg.getSuggestionCallback()); | ||
playerArg.setSuggestionCallback((sender, context, suggestion) -> { | ||
if (sender instanceof Player player) { | ||
player.sendActionBar(MM."<green>Fetching online players..."); | ||
} | ||
Cytosis.getDatabaseManager().getRedisDatabase().getOnlinePlayers().forEach(player -> | ||
suggestion.addEntry(new SuggestionEntry(player))); | ||
}); | ||
var durationArg = ArgumentType.Word("duration"); | ||
var reasonArg = ArgumentType.Enum("reason", BanReason.class).setFormat(ArgumentEnum.Format.LOWER_CASED); | ||
|
||
var group = ArgumentType.Group("ban-group", playerArg, durationArg, reasonArg); | ||
|
||
addSyntax((sender, context) -> { | ||
if (sender instanceof Player actor) { | ||
|
||
if (!actor.hasPermission("cytosis.commands.moderation.ban")) { | ||
actor.sendMessage(MM."<red>You don't have permission to use this command!"); | ||
} | ||
|
||
final String player = context/*.get(group)*/.get(playerArg); | ||
final String reason = context/*.get(group)*/.get(reasonArg).getReason(); | ||
final String rawDur = context/*.get(group)*/.get(durationArg); | ||
final Instant dur = DurationParser.parse(rawDur); | ||
|
||
if (!Cytosis.getDatabaseManager().getRedisDatabase().getOnlinePlayers().contains(player)) { | ||
sender.sendMessage(MM."<red>The player \{context.get(group).getRaw("player")} doesn't exist!"); | ||
return; | ||
} | ||
Cytosis.getDatabaseManager().getMysqlDatabase().findUUIDByName(player).whenComplete((uuid, throwable) -> { | ||
if (throwable != null) { | ||
sender.sendMessage(MM."<red>An error occured whilst finding \{player}!"); | ||
Logger.error("error; ", throwable); | ||
return; | ||
} | ||
Cytosis.getDatabaseManager().getMysqlDatabase().isBanned(uuid).whenComplete((banned, throwable1) -> { | ||
if (throwable1 != null) { | ||
sender.sendMessage(MM."<red>An error occured whilst finding if \{player} is banned!"); | ||
Logger.error("error; ", throwable1); | ||
return; | ||
} | ||
if (banned.isBanned()) { | ||
sender.sendMessage(MM."<red>\{player} is already banned!"); | ||
return; | ||
} | ||
Cytosis.getDatabaseManager().getMysqlDatabase().getPlayerRank(uuid).whenComplete((playerRank, throwable2) -> { | ||
if (throwable2 != null) { | ||
sender.sendMessage(MM."<red>An error occured whilst finding \{player}'s rank!"); | ||
Logger.error("error; ", throwable2); | ||
return; | ||
} | ||
OfflinePlayer op = new OfflinePlayer(player, uuid, playerRank); | ||
if (op.hasPermission("cytosis.moderation.ban_immune")) { | ||
sender.sendMessage(MM."<red>\{player} cannot be banned!"); | ||
return; | ||
} | ||
|
||
Cytosis.getDatabaseManager().getMysqlDatabase().banPlayer(uuid, reason, dur).whenComplete((_, throwable3) -> { | ||
if (throwable3 != null) { | ||
actor.sendMessage(MM."<red>An error occured whilst banning \{player}!"); | ||
return; | ||
} | ||
Cytosis.getMessagingManager().getRabbitMQ().kickPlayer(op, KickReason.BANNED, MessageUtils.formatBanMessage(new BanData(reason, dur, true))); | ||
actor.sendMessage(MM."<green>\{player} was successfully banned for \{DurationParser.unparseFull(dur)}."); | ||
Cytosis.getDatabaseManager().getMysqlDatabase().addAuditLogEntry(new Entry(uuid, actor.getUuid(), Category.BAN, reason)); | ||
}); | ||
}); | ||
}); | ||
}); | ||
} | ||
}, playerArg, durationArg, reasonArg); | ||
} | ||
} |
Oops, something went wrong.