mirror of
https://github.com/darksaid98/Carbon.git
synced 2026-12-01 22:15:08 +00:00
Aliases and bug fixes
This commit is contained in:
1 parent
24ec001157
commit
a2ec2f50f1
5 files changed
+65
-10
No files matched your search
@@ -77,7 +77,7 @@ public class SimpleChatChannel extends ChatChannel {
|
||||
simpleChat.getDiscordManager().getDiscordAPI().addMessageCreateListener(this::processDiscordMessage);
|
||||
}
|
||||
|
||||
if (getWebhook() != null) {
|
||||
if (getWebhook() != null && !getWebhook().isEmpty()) {
|
||||
discordWebhook = new DiscordWebhook(getWebhook());
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,42 @@
|
||||
package net.draycia.simplechat.commands;
|
||||
|
||||
import co.aikar.commands.BaseCommand;
|
||||
import co.aikar.commands.annotation.*;
|
||||
import net.draycia.simplechat.SimpleChat;
|
||||
import net.draycia.simplechat.channels.ChatChannel;
|
||||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
@CommandAlias("%channelName")
|
||||
@CommandPermission("simplechat.switch")
|
||||
public class AliasedChannelCommand extends BaseCommand {
|
||||
|
||||
private SimpleChat simpleChat;
|
||||
private ChatChannel chatChannel;
|
||||
|
||||
public AliasedChannelCommand(SimpleChat simpleChat, ChatChannel chatChannel) {
|
||||
this.simpleChat = simpleChat;
|
||||
this.chatChannel = chatChannel;
|
||||
}
|
||||
|
||||
@Default
|
||||
//@CommandAlias("channel %channelName")
|
||||
public void baseCommand(Player player, @Optional String[] args) {
|
||||
if (args == null || args.length == 0) {
|
||||
simpleChat.setPlayerChannel(player, getChatChannel());
|
||||
|
||||
simpleChat.getAudiences().player(player).sendMessage(MiniMessage.instance().parse(
|
||||
getChatChannel().getSwitchMessage(), "color", "<" + getChatChannel().getColor().toString() + ">",
|
||||
"channel", getChatChannel().getName()));
|
||||
} else {
|
||||
Bukkit.getScheduler().scheduleAsyncDelayedTask(simpleChat, () -> {
|
||||
getChatChannel().sendMessage(player, String.join(" ", args));
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
public ChatChannel getChatChannel() {
|
||||
return chatChannel;
|
||||
}
|
||||
}
|
||||
@@ -1,8 +1,10 @@
|
||||
package net.draycia.simplechat.managers;
|
||||
|
||||
import co.aikar.commands.CommandManager;
|
||||
import net.draycia.simplechat.SimpleChat;
|
||||
import net.draycia.simplechat.channels.ChatChannel;
|
||||
import net.draycia.simplechat.channels.impls.*;
|
||||
import net.draycia.simplechat.commands.AliasedChannelCommand;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
|
||||
@@ -142,6 +144,11 @@ public class ChannelManager {
|
||||
|
||||
// TODO: register command for each channel
|
||||
simpleChat.getChannels().add(channel);
|
||||
|
||||
CommandManager commandManager = simpleChat.getCommandManager().getCommandManager();
|
||||
|
||||
commandManager.getCommandReplacements().addReplacement("commandAlias", channel.getName().toLowerCase());
|
||||
commandManager.registerCommand(new AliasedChannelCommand(simpleChat, channel));
|
||||
}
|
||||
|
||||
if (!hasTownChat) {
|
||||
|
||||
@@ -1,23 +1,25 @@
|
||||
package net.draycia.simplechat.managers;
|
||||
|
||||
import co.aikar.commands.BukkitCommandManager;
|
||||
import co.aikar.commands.ConditionFailedException;
|
||||
import co.aikar.commands.*;
|
||||
import net.draycia.simplechat.SimpleChat;
|
||||
import net.draycia.simplechat.channels.ChatChannel;
|
||||
import net.draycia.simplechat.commands.*;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class CommandManager {
|
||||
|
||||
private SimpleChat simpleChat;
|
||||
private BukkitCommandManager commandManager;
|
||||
|
||||
public CommandManager(SimpleChat simpleChat) {
|
||||
this.simpleChat = simpleChat;
|
||||
|
||||
BukkitCommandManager manager = new BukkitCommandManager(simpleChat);
|
||||
commandManager = new BukkitCommandManager(simpleChat);
|
||||
|
||||
manager.getCommandCompletions().registerCompletion("chatchannel", (context) -> {
|
||||
commandManager.getCommandCompletions().registerCompletion("chatchannel", (context) -> {
|
||||
ArrayList<String> completions = new ArrayList<>();
|
||||
|
||||
for (ChatChannel chatChannel : simpleChat.getChannels()) {
|
||||
@@ -29,7 +31,7 @@ public class CommandManager {
|
||||
return completions;
|
||||
});
|
||||
|
||||
manager.getCommandContexts().registerContext(ChatChannel.class, (context) -> {
|
||||
commandManager.getCommandContexts().registerContext(ChatChannel.class, (context) -> {
|
||||
String name = context.popFirstArg();
|
||||
|
||||
for (ChatChannel chatChannel : simpleChat.getChannels()) {
|
||||
@@ -41,13 +43,13 @@ public class CommandManager {
|
||||
return null;
|
||||
});
|
||||
|
||||
manager.getCommandConditions().addCondition(ChatChannel.class,"canuse", (context, execution, value) -> {
|
||||
commandManager.getCommandConditions().addCondition(ChatChannel.class,"canuse", (context, execution, value) -> {
|
||||
if (!value.canPlayerUse(context.getIssuer().getPlayer())) {
|
||||
throw new ConditionFailedException(simpleChat.getConfig().getString("language.cannot-use-channel"));
|
||||
}
|
||||
});
|
||||
|
||||
setupCommands(manager);
|
||||
setupCommands(commandManager);
|
||||
}
|
||||
|
||||
private void setupCommands(BukkitCommandManager manager) {
|
||||
@@ -62,4 +64,8 @@ public class CommandManager {
|
||||
manager.registerCommand(new ReplyCommand(simpleChat));
|
||||
}
|
||||
|
||||
public co.aikar.commands.CommandManager getCommandManager() {
|
||||
return commandManager;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -25,7 +25,7 @@ channels:
|
||||
global:
|
||||
name: 'Global'
|
||||
id: -1 # Set to -1, comment out, or remove to disable channel bridge
|
||||
webhook: 'URL_HERE' # Comment out / remove to disable webhook
|
||||
webhook: '' # Comment out / remove to disable webhook
|
||||
default: true # Removing this option defaults to 'false'
|
||||
announcements:
|
||||
name: 'Announcements'
|
||||
@@ -43,7 +43,7 @@ filter-text: '****'
|
||||
replacements:
|
||||
'%shrug%': '¯\_(ツ)_/¯'
|
||||
|
||||
bot-token: -1
|
||||
bot-token: ""
|
||||
|
||||
language:
|
||||
ignoring-user: '<green>You are now ignoring <gold><player><green>!'
|
||||
|
||||
Reference in new issue
Block a user