Skip to content

Commit

Permalink
CheckUser Addon (#168)
Browse files Browse the repository at this point in the history
  • Loading branch information
SnakeAmazing authored Sep 9, 2022
1 parent 0d43698 commit 48bfdcc
Show file tree
Hide file tree
Showing 12 changed files with 257 additions and 4 deletions.
5 changes: 5 additions & 0 deletions bans-core-addons/addon-integration/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,11 @@
<artifactId>addon-warn-actions</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>space.arim.libertybans</groupId>
<artifactId>addon-command-checkuser</artifactId>
<version>${project.version}</version>
</dependency>

<dependency>
<groupId>org.junit.jupiter</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import org.junit.jupiter.api.Test;
import space.arim.libertybans.core.addon.AddonLoader;
import space.arim.libertybans.core.addon.checkpunish.CheckPunishModule;
import space.arim.libertybans.core.addon.checkuser.CheckUserModule;
import space.arim.libertybans.core.addon.staffrollback.StaffRollbackModule;
import space.arim.libertybans.core.addon.warnactions.WarnActionsModule;

Expand All @@ -35,7 +36,10 @@ public class ServiceLoadingIT {
@Test
public void loadAddons() {
assertEquals(
Set.of(new CheckPunishModule(), new StaffRollbackModule(), new WarnActionsModule()),
Set.of(
new CheckPunishModule(), new CheckUserModule(),
new StaffRollbackModule(), new WarnActionsModule()
),
assertDoesNotThrow(AddonLoader::loadAddonBindModules)
);
}
Expand Down
14 changes: 14 additions & 0 deletions bans-core-addons/command-checkuser/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>space.arim.libertybans</groupId>
<artifactId>bans-core-addons</artifactId>
<version>1.1.0-SNAPSHOT</version>
</parent>

<name>command-checkuser</name>
<artifactId>addon-command-checkuser</artifactId>
</project>
15 changes: 15 additions & 0 deletions bans-core-addons/command-checkuser/src/main/java/module-info.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import space.arim.libertybans.core.addon.AddonProvider;
import space.arim.libertybans.core.addon.checkuser.CheckUserProvider;

module space.arim.libertybans.core.addon.checkuser {
requires jakarta.inject;
requires net.kyori.adventure;
requires net.kyori.examination.api;
requires static org.jetbrains.annotations;
requires space.arim.api.jsonchat;
requires space.arim.dazzleconf;
requires space.arim.injector;
requires space.arim.libertybans.core;
exports space.arim.libertybans.core.addon.checkuser;
provides AddonProvider with CheckUserProvider;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package space.arim.libertybans.core.addon.checkuser;

import jakarta.inject.Inject;
import jakarta.inject.Singleton;
import space.arim.libertybans.core.addon.AbstractAddon;
import space.arim.libertybans.core.addon.AddonCenter;

@Singleton
public final class CheckUserAddon extends AbstractAddon<CheckUserConfig> {

@Inject
public CheckUserAddon(AddonCenter addonCenter) {
super(addonCenter);
}

@Override
public void startup() {

}

@Override
public void shutdown() {

}

@Override
public Class<CheckUserConfig> configInterface() {
return CheckUserConfig.class;
}

@Override
public String identifier() {
return "command-checkuser";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
package space.arim.libertybans.core.addon.checkuser;

import jakarta.inject.Inject;
import org.jetbrains.annotations.Nullable;
import space.arim.libertybans.api.PunishmentType;
import space.arim.libertybans.api.punish.Punishment;
import space.arim.libertybans.api.select.PunishmentSelector;
import space.arim.libertybans.core.commands.AbstractCommandExecution;
import space.arim.libertybans.core.commands.AbstractSubCommandGroup;
import space.arim.libertybans.core.commands.CommandExecution;
import space.arim.libertybans.core.commands.CommandPackage;
import space.arim.libertybans.core.config.InternalFormatter;
import space.arim.libertybans.core.env.CmdSender;
import space.arim.libertybans.core.env.UUIDAndAddress;
import space.arim.libertybans.core.uuid.UUIDManager;
import space.arim.omnibus.util.concurrent.ReactionStage;

import java.util.stream.Stream;

public final class CheckUserCommand extends AbstractSubCommandGroup {

private final PunishmentSelector selector;
private final UUIDManager uuidManager;
private final InternalFormatter formatter;
private final CheckUserAddon checkUserAddon;

@Inject
public CheckUserCommand(Dependencies dependencies,
PunishmentSelector selector, UUIDManager uuidManager, InternalFormatter internalFormatter, CheckUserAddon checkUserAddon) {
super(dependencies, "checkuser");
this.selector = selector;
this.uuidManager = uuidManager;
this.formatter = internalFormatter;
this.checkUserAddon = checkUserAddon;
}

@Override
public CommandExecution execute(CmdSender sender, CommandPackage command, String arg) {
return new Execution(sender, command);
}

@Override
public Stream<String> suggest(CmdSender sender, String arg, int argIndex) {
return Stream.empty();
}

@Override
public boolean hasTabCompletePermission(CmdSender sender, String arg) {
return hasPermission(sender);
}

private boolean hasPermission(CmdSender sender) {
return sender.hasPermission("libertybans.addon.checkuser.use");
}

private final class Execution extends AbstractCommandExecution {

private final CheckUserConfig config;

private Execution(CmdSender sender, CommandPackage command) {
super(sender, command);
config = checkUserAddon.config();
}

@Override
public @Nullable ReactionStage<Void> execute() {
if (!hasPermission(sender())) {
sender().sendMessage(config.noPermission());
return null;
}

if (!command().hasNext()) {
sender().sendMessage(config.usage());
return null;
}

String name = command().next();

return uuidManager.lookupPlayer(name).thenCompose(optUuidAddress -> {
if (optUuidAddress.isEmpty()) {
sender().sendMessage(config.doesNotExist());
return completedFuture(null);
}

UUIDAndAddress uuidAddress = optUuidAddress.get();
return selector.getApplicablePunishment(
uuidAddress.uuid(), uuidAddress.address(), PunishmentType.BAN
).thenCompose(optPunishment -> {

if (optPunishment.isEmpty()) {
return selector.getApplicablePunishment(
uuidAddress.uuid(), uuidAddress.address(), PunishmentType.MUTE
).thenCompose(optMute -> {

if (optMute.isEmpty()) {
sender().sendMessage(config.noPunishment());
return completedFuture(null);
}
Punishment punishment = optMute.get();
return formatter.formatWithPunishment(config.layout(), punishment)
.thenAccept(sender()::sendMessage);
});
}
Punishment punishment = optPunishment.get();
return formatter.formatWithPunishment(config.layout(), punishment)
.thenAccept(sender()::sendMessage);
});
});
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package space.arim.libertybans.core.addon.checkuser;

import net.kyori.adventure.text.Component;
import space.arim.api.jsonchat.adventure.util.ComponentText;
import space.arim.dazzleconf.annote.ConfDefault;
import space.arim.dazzleconf.annote.ConfKey;
import space.arim.libertybans.core.addon.AddonConfig;

public interface CheckUserConfig extends AddonConfig {

@ConfKey("no-permission")
@ConfDefault.DefaultString("&cYou do not have permission to check user data")
Component noPermission();

@ConfDefault.DefaultString("&cUsage: /libertybans checkuser <player>")
Component usage();

@ConfKey("player-does-not-exist")
@ConfDefault.DefaultString("&cThat player does not exist")
Component doesNotExist();

@ConfKey("punishment-does-not-exist")
@ConfDefault.DefaultString("&cThat player doesn't have any active punishment.")
Component noPunishment();

@ConfDefault.DefaultStrings({
"&7Active punishment for player &e%VICTIM%",
"&7Type: &e%TYPE%",
"&7Reason: &e%REASON%",
"&7Operator: &e%OPERATOR%",
"Time remaining: &e%TIME_REMAINING%",
})
ComponentText layout();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package space.arim.libertybans.core.addon.checkuser;

import space.arim.injector.MultiBinding;
import space.arim.libertybans.core.addon.Addon;
import space.arim.libertybans.core.addon.AddonBindModule;
import space.arim.libertybans.core.commands.SubCommandGroup;

public final class CheckUserModule extends AddonBindModule {

@MultiBinding
public Addon<?> checkUserAddon(CheckUserAddon checkUserAddon) {
return checkUserAddon;
}

@MultiBinding
public SubCommandGroup checkUserCommand(CheckUserCommand checkUserCommand) {
return checkUserCommand;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package space.arim.libertybans.core.addon.checkuser;

import space.arim.libertybans.core.addon.AddonBindModule;
import space.arim.libertybans.core.addon.AddonProvider;

public final class CheckUserProvider implements AddonProvider {
@Override
public AddonBindModule[] bindModules() {
return new AddonBindModule[] {new CheckUserModule()};
}
}
1 change: 1 addition & 0 deletions bans-core-addons/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
<module>warn-actions</module>
<module>addon-integration</module>
<module>command-staffrollback</module>
<module>command-checkuser</module>
</modules>

<dependencies>
Expand Down
4 changes: 1 addition & 3 deletions bans-core/src/main/java/module-info.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,7 @@
exports space.arim.libertybans.core.selector;
exports space.arim.libertybans.core.selector.cache;
exports space.arim.libertybans.core.service;
exports space.arim.libertybans.core.uuid
to space.arim.dazzleconf, space.arim.injector;

exports space.arim.libertybans.core.uuid;
opens space.arim.libertybans.core.alts to space.arim.dazzleconf;
opens space.arim.libertybans.core.commands.extra to space.arim.dazzleconf;
opens space.arim.libertybans.core.config to space.arim.dazzleconf;
Expand Down
6 changes: 6 additions & 0 deletions docs/Addons.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@ This addon provides the `/libertybans checkpunish <ID>` command. This command di

Requires the permission `libertybans.addon.checkpunish.use`.

## CheckUser

Provides the `/libertybans checkuser <player>` command. This command displays if the given player is banned or muted.

Requires the permission `libertybans.addon.checkuser.use`.

## StaffRollback

Provides the `/libertybans staffrollback <operator> [time]` command. Performing a rollback fully purges all punishments by a certain staff member, which is useful if a staff member becomes rogue or has their account hacked.
Expand Down

0 comments on commit 48bfdcc

Please sign in to comment.