-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0d43698
commit 48bfdcc
Showing
12 changed files
with
257 additions
and
4 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
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,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
15
bans-core-addons/command-checkuser/src/main/java/module-info.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,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; | ||
} |
35 changes: 35 additions & 0 deletions
35
...d-checkuser/src/main/java/space/arim/libertybans/core/addon/checkuser/CheckUserAddon.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,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"; | ||
} | ||
} |
111 changes: 111 additions & 0 deletions
111
...checkuser/src/main/java/space/arim/libertybans/core/addon/checkuser/CheckUserCommand.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,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); | ||
}); | ||
}); | ||
} | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
...-checkuser/src/main/java/space/arim/libertybans/core/addon/checkuser/CheckUserConfig.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,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(); | ||
} |
19 changes: 19 additions & 0 deletions
19
...-checkuser/src/main/java/space/arim/libertybans/core/addon/checkuser/CheckUserModule.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,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; | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
...heckuser/src/main/java/space/arim/libertybans/core/addon/checkuser/CheckUserProvider.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,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()}; | ||
} | ||
} |
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
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