mirror of
https://github.com/darksaid98/Carbon.git
synced 2026-12-01 22:15:08 +00:00
clearchat progress
This commit is contained in:
1 parent
17693466b9
commit
e37bad3d92
5 files changed
+105
-5
No files matched your search
@@ -18,6 +18,7 @@ import net.draycia.carbon.bukkit.listeners.BukkitChatListener;
|
||||
import net.draycia.carbon.bukkit.listeners.BukkitPlayerJoinListener;
|
||||
import net.draycia.carbon.bukkit.util.BukkitMessageRenderer;
|
||||
import net.draycia.carbon.common.channels.CarbonChannelRegistry;
|
||||
import net.draycia.carbon.common.command.commands.ClearChatCommand;
|
||||
import net.draycia.carbon.common.command.commands.ContinueCommand;
|
||||
import net.draycia.carbon.common.command.commands.DebugCommand;
|
||||
import net.draycia.carbon.common.command.commands.HelpCommand;
|
||||
@@ -103,6 +104,7 @@ public final class CarbonChatBukkit extends JavaPlugin implements CarbonChat {
|
||||
this.injector.getInstance(MuteHandler.class);
|
||||
|
||||
// Commands
|
||||
this.injector.getInstance(ClearChatCommand.class);
|
||||
this.injector.getInstance(ContinueCommand.class);
|
||||
this.injector.getInstance(DebugCommand.class);
|
||||
this.injector.getInstance(MuteCommand.class);
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
package net.draycia.carbon.common.command.commands;
|
||||
|
||||
import cloud.commandframework.CommandManager;
|
||||
import com.google.inject.Inject;
|
||||
import net.draycia.carbon.api.CarbonChat;
|
||||
import net.draycia.carbon.common.command.Commander;
|
||||
import net.draycia.carbon.common.command.PlayerCommander;
|
||||
import net.draycia.carbon.common.config.PrimaryConfig;
|
||||
|
||||
public class ClearChatCommand {
|
||||
|
||||
@Inject
|
||||
public ClearChatCommand(
|
||||
final CarbonChat carbonChat,
|
||||
final CommandManager<Commander> commandManager,
|
||||
final PrimaryConfig config
|
||||
) {
|
||||
var command = commandManager.commandBuilder("clearchat", "chatclear", "cc")
|
||||
.permission("carbon.clearchat")
|
||||
.senderType(PlayerCommander.class)
|
||||
.handler(handler -> {
|
||||
// Not fond of having to send 50 messages to each player
|
||||
// Are we not able to just paste in 50 newlines and call it a day?
|
||||
for (int i = 0; i < config.clearChatSettings().iterations(); i++) {
|
||||
for (final var player : carbonChat.server().players()) {
|
||||
if (!player.hasPermission("carbon.clearchat.exempt")) {
|
||||
player.sendMessage(config.clearChatSettings().message());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
carbonChat.server().sendMessage(config.clearChatSettings().broadcast());
|
||||
})
|
||||
.build();
|
||||
|
||||
commandManager.command(command);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -20,7 +20,7 @@ public class DebugCommand {
|
||||
) {
|
||||
var command = commandManager.commandBuilder("carbondebug", "cdebug")
|
||||
.argument(carbonPlayerArgument.newInstance(false, "player"))
|
||||
.permission("carbon.debug") // TODO: carbon.whisper.spy
|
||||
.permission("carbon.debug")
|
||||
.senderType(PlayerCommander.class)
|
||||
.handler(handler -> {
|
||||
final CarbonPlayer sender = ((PlayerCommander)handler.getSender()).carbonPlayer();
|
||||
|
||||
@@ -0,0 +1,49 @@
|
||||
package net.draycia.carbon.common.config;
|
||||
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||
import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import org.checkerframework.framework.qual.DefaultQualifier;
|
||||
import org.spongepowered.configurate.objectmapping.ConfigSerializable;
|
||||
import org.spongepowered.configurate.objectmapping.meta.Comment;
|
||||
|
||||
@ConfigSerializable
|
||||
@DefaultQualifier(NonNull.class)
|
||||
// TODO: Config versioning. This isn't automatically added to existing configs otherwise.
|
||||
public class ClearChatSettings {
|
||||
|
||||
@Comment("The message that will be sent to each player.")
|
||||
private String message = "";
|
||||
|
||||
@Comment("The number of times the message will be sent to each player.")
|
||||
private int iterations = 50;
|
||||
|
||||
@Comment("The message to be sent after chat is cleared.")
|
||||
private String broadcast = "<gold>Chat has been cleared by </gold><green><display_name><green><gold>.";
|
||||
|
||||
private @MonotonicNonNull Component messageComponent = null;
|
||||
|
||||
public Component message() {
|
||||
if (messageComponent == null) {
|
||||
this.messageComponent = MiniMessage.miniMessage().deserialize(message);
|
||||
}
|
||||
|
||||
return this.messageComponent;
|
||||
}
|
||||
|
||||
public int iterations() {
|
||||
return this.iterations;
|
||||
}
|
||||
|
||||
private @MonotonicNonNull Component broadcastComponent = null;
|
||||
|
||||
public Component broadcast() {
|
||||
if (broadcastComponent == null) {
|
||||
this.broadcastComponent = MiniMessage.miniMessage().deserialize(broadcast);
|
||||
}
|
||||
|
||||
return this.broadcastComponent;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -12,13 +12,19 @@ import org.spongepowered.configurate.objectmapping.meta.Comment;
|
||||
public class PrimaryConfig {
|
||||
|
||||
@Comment("The default locale for plugin messages.")
|
||||
private final Locale defaultLocale = Locale.US;
|
||||
private Locale defaultLocale = Locale.US;
|
||||
|
||||
@Comment("The default channel that new players will be in when they join.")
|
||||
private final Key defaultChannel = Key.key("carbon", "basic");
|
||||
private Key defaultChannel = Key.key("carbon", "basic");
|
||||
|
||||
@Comment("The service that will be used to store and load player information.")
|
||||
private final StorageType storageType = StorageType.JSON;
|
||||
private StorageType storageType = StorageType.JSON;
|
||||
|
||||
@Comment("Should we hide join/quit and death messages of muted players?")
|
||||
private final boolean hideMutedJoinLeaveQuit = false;
|
||||
private boolean hideMutedJoinLeaveQuit = false;
|
||||
|
||||
@Comment("Various ClearChat command settings.")
|
||||
private ClearChatSettings clearChatSettings = new ClearChatSettings();
|
||||
|
||||
public Locale defaultLocale() {
|
||||
return this.defaultLocale;
|
||||
@@ -36,6 +42,10 @@ public class PrimaryConfig {
|
||||
return this.hideMutedJoinLeaveQuit;
|
||||
}
|
||||
|
||||
public ClearChatSettings clearChatSettings() {
|
||||
return this.clearChatSettings;
|
||||
}
|
||||
|
||||
public enum StorageType {
|
||||
JSON,
|
||||
MYSQL,
|
||||
|
||||
Reference in new issue
Block a user