Command fixes, remove old preprocessor
Fixed command channels /tpahere message removed Made /me an actual command Fixed some help texts
This commit is contained in:
parent
f3ec9e7870
commit
5d8ae7fbd0
11 changed files with 36 additions and 104 deletions
7
pom.xml
7
pom.xml
|
@ -268,6 +268,13 @@
|
|||
<version>2.8.1</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<!-- TestPrepare also needs it (ChromaCore) so the versions should match -->
|
||||
<dependency>
|
||||
<groupId>org.mockito</groupId>
|
||||
<artifactId>mockito-core</artifactId>
|
||||
<version>3.0.0</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<artifactId>Chroma-Chat</artifactId>
|
||||
<organization>
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package buttondevteam.chat;
|
||||
|
||||
import buttondevteam.chat.commands.MWikiCommand;
|
||||
import buttondevteam.chat.commands.MeCommand;
|
||||
import buttondevteam.chat.commands.SnapCommand;
|
||||
import buttondevteam.chat.commands.ucmds.HelpCommand;
|
||||
import buttondevteam.chat.commands.ucmds.HistoryCommand;
|
||||
|
@ -76,6 +77,7 @@ public class PluginMain extends ButtonPlugin { // Translated to Java: 2015.07.15
|
|||
registerCommand(new MWikiCommand());
|
||||
registerCommand(new ReloadCommand());
|
||||
registerCommand(new SnapCommand());
|
||||
registerCommand(new MeCommand());
|
||||
}
|
||||
|
||||
public static Essentials essentials = null;
|
||||
|
|
15
src/main/java/buttondevteam/chat/commands/MeCommand.java
Normal file
15
src/main/java/buttondevteam/chat/commands/MeCommand.java
Normal file
|
@ -0,0 +1,15 @@
|
|||
package buttondevteam.chat.commands;
|
||||
|
||||
import buttondevteam.lib.TBMCSystemChatEvent;
|
||||
import buttondevteam.lib.chat.*;
|
||||
|
||||
@CommandClass(helpText = {
|
||||
"Me",
|
||||
"Displays a message starting with your name in your current channel."
|
||||
})
|
||||
public class MeCommand extends ICommand2MC {
|
||||
@Command2.Subcommand
|
||||
public void def(Command2MCSender sender, @Command2.TextArg String message) {
|
||||
TBMCChatAPI.SendSystemMessage(sender.getChannel(), sender.getChannel().getRTR(sender.getPermCheck()), "§5* " + sender.getName() + " " + message, TBMCSystemChatEvent.BroadcastTarget.ALL);
|
||||
}
|
||||
}
|
|
@ -15,7 +15,7 @@ import java.util.function.Function;
|
|||
import java.util.stream.Stream;
|
||||
|
||||
@CommandClass(helpText = {
|
||||
"§6--- Chat History ----", //
|
||||
"Chat History", //
|
||||
"Returns the last 10 messages the player can see." //
|
||||
})
|
||||
public class HistoryCommand extends UCommandBase {
|
||||
|
|
|
@ -13,7 +13,7 @@ public class DebugCommand extends AdminCommandBase {
|
|||
public static boolean DebugMode = false;
|
||||
|
||||
@Command2.Subcommand
|
||||
public boolean def(CommandSender sender, String alias, String[] args) {
|
||||
public boolean def(CommandSender sender) {
|
||||
sender.sendMessage("§eDebug mode " + ((DebugMode = !DebugMode) ? "§aenabled." : "§cdisabled."));
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -7,7 +7,6 @@ import buttondevteam.lib.architecture.IHaveConfig;
|
|||
import buttondevteam.lib.chat.*;
|
||||
import buttondevteam.lib.player.ChromaGamerBase;
|
||||
import lombok.val;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.HashMap;
|
||||
|
@ -101,9 +100,9 @@ public class AppendTextComponent extends Component<PluginMain> {
|
|||
}
|
||||
|
||||
@Command2.Subcommand
|
||||
public void def(CommandSender sender, @Command2.OptionalArg @Command2.TextArg String message) {
|
||||
TBMCChatAPI.SendChatMessage(ChatMessage.builder(sender, ChromaGamerBase.getFromSender(sender),
|
||||
(message == null ? "" : message + " ") + appendedText).fromCommand(true).build());
|
||||
public void def(Command2MCSender sender, @Command2.OptionalArg @Command2.TextArg String message) {
|
||||
TBMCChatAPI.SendChatMessage(ChatMessage.builder(sender.getSender(), ChromaGamerBase.getFromSender(sender.getSender()),
|
||||
(message == null ? "" : message + " ") + appendedText).fromCommand(true).permCheck(sender.getPermCheck()).build());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -8,7 +8,7 @@ import org.bukkit.GameMode;
|
|||
import org.bukkit.entity.Player;
|
||||
|
||||
@CommandClass(modOnly = false, helpText = {
|
||||
"§6---- Chat-only mode ----", //
|
||||
"Chat-only mode", //
|
||||
"This mode makes you invincible but unable to move, teleport or interact with the world in any way", //
|
||||
"It was designed for chat clients", //
|
||||
"Once enabled, the only way of disabling it is by relogging to the server" //
|
||||
|
|
|
@ -10,7 +10,7 @@ import org.bukkit.command.CommandSender;
|
|||
import org.bukkit.entity.Player;
|
||||
|
||||
@CommandClass(helpText = {
|
||||
"§6---- Set flair -----", "Set a flair for a player",
|
||||
"Set flair", "Set a flair for a player",
|
||||
"Usage: /u admin setflair <player> <flairtime (or non-presser, cant-press, none)> <cheater(true/false)> [username]",
|
||||
"Example 1: /u admin setflair NorbiPeti 19 false NorbiPeti --> orange (19s)",
|
||||
"Example 2: /u admin setflair iie 0 true asde --> purple (0s)"
|
||||
|
|
|
@ -18,7 +18,7 @@ import java.util.concurrent.atomic.AtomicInteger;
|
|||
import java.util.stream.Collectors;
|
||||
|
||||
@CommandClass(helpText = {
|
||||
"§6---- F Top ----", //
|
||||
"F Top", //
|
||||
"Shows the respect leaderboard" //
|
||||
})
|
||||
public class FTopCommand extends ICommand2MC {
|
||||
|
|
|
@ -20,7 +20,7 @@ import java.util.HashMap;
|
|||
import java.util.Map;
|
||||
|
||||
@CommandClass(modOnly = false, helpText = {
|
||||
"§6---- Unlol/unlaugh ----",
|
||||
"Unlol/unlaugh",
|
||||
"This command is based on a joke between NorbiPeti and Ghostise",
|
||||
"It will make the last person saying one of the recognized laugh strings blind for a few seconds",
|
||||
"Note that you can only unlaugh laughs that weren't unlaughed before"
|
||||
|
|
|
@ -8,38 +8,24 @@ import buttondevteam.chat.components.flair.FlairComponent;
|
|||
import buttondevteam.chat.components.formatter.FormatterComponent;
|
||||
import buttondevteam.chat.components.towncolors.TownColorComponent;
|
||||
import buttondevteam.core.ComponentManager;
|
||||
import buttondevteam.core.component.channel.Channel;
|
||||
import buttondevteam.core.component.channel.ChatRoom;
|
||||
import buttondevteam.lib.ChromaUtils;
|
||||
import buttondevteam.lib.TBMCChatEvent;
|
||||
import buttondevteam.lib.TBMCCoreAPI;
|
||||
import buttondevteam.lib.TBMCSystemChatEvent;
|
||||
import buttondevteam.lib.chat.ChatMessage;
|
||||
import buttondevteam.lib.chat.TBMCChatAPI;
|
||||
import buttondevteam.lib.player.ChromaGamerBase;
|
||||
import buttondevteam.lib.player.ChromaGamerBase.InfoTarget;
|
||||
import buttondevteam.lib.player.TBMCPlayerGetInfoEvent;
|
||||
import com.google.common.collect.BiMap;
|
||||
import com.google.common.collect.HashBiMap;
|
||||
import lombok.val;
|
||||
import net.ess3.api.events.NickChangeEvent;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.command.ConsoleCommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.AsyncPlayerChatEvent;
|
||||
import org.bukkit.event.player.PlayerChatTabCompleteEvent;
|
||||
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
|
||||
import org.bukkit.event.server.ServerCommandEvent;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.UUID;
|
||||
import java.util.function.BiPredicate;
|
||||
|
||||
public class PlayerListener implements Listener {
|
||||
/**
|
||||
|
@ -56,77 +42,6 @@ public class PlayerListener implements Listener {
|
|||
event.setCancelled(true); // The custom event should only be cancelled when muted or similar
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST)
|
||||
public void PlayerCommandPreprocess(PlayerCommandPreprocessEvent event) {
|
||||
if (!event.isCancelled())
|
||||
event.setCancelled(onCommandPreprocess(event.getPlayer(), event.getMessage()));
|
||||
}
|
||||
|
||||
private boolean onCommandPreprocess(CommandSender sender, String message) {
|
||||
if (message.length() < 2)
|
||||
return false;
|
||||
int index = message.indexOf(" ");
|
||||
val mp = ChromaGamerBase.getFromSender(sender);
|
||||
String cmd;
|
||||
final BiPredicate<Channel, String> checkchid = (chan, cmd1) -> cmd1.equalsIgnoreCase(chan.ID) || (Arrays.stream(chan.IDs().get()).anyMatch(cmd1::equalsIgnoreCase));
|
||||
if (index == -1) { // Only the command is run
|
||||
if (!(sender instanceof Player || sender instanceof ConsoleCommandSender))
|
||||
return false;
|
||||
// ^^ We can only store player or console channels - Directly sending to channels would still work if they had an event
|
||||
cmd = sender instanceof ConsoleCommandSender ? message : message.substring(1);
|
||||
for (Channel channel : ((Iterable<Channel>) Channel.getChannels()::iterator)) { //Using Stream.forEach would be too easy
|
||||
if (checkchid.test(channel, cmd)) {
|
||||
Channel oldch = mp.channel().get();
|
||||
if (oldch instanceof ChatRoom)
|
||||
((ChatRoom) oldch).leaveRoom(sender);
|
||||
if (oldch.equals(channel))
|
||||
mp.channel().set(Channel.GlobalChat);
|
||||
else {
|
||||
mp.channel().set(channel);
|
||||
if (channel instanceof ChatRoom)
|
||||
((ChatRoom) channel).joinRoom(sender);
|
||||
}
|
||||
sender.sendMessage("§6You are now talking in: §b" + mp.channel().get().DisplayName().get());
|
||||
return true;
|
||||
}
|
||||
}
|
||||
} else { // We have arguments
|
||||
cmd = sender instanceof ConsoleCommandSender ? message.substring(0, index) : message.substring(1, index);
|
||||
if (cmd.equalsIgnoreCase("tpahere")) {
|
||||
Player player = Bukkit.getPlayer(message.substring(index + 1));
|
||||
if (player != null && sender instanceof Player)
|
||||
player.sendMessage("§b" + ((Player) sender).getDisplayName() + " §bis in this world: " //TODO: Move to the Core
|
||||
+ ((Player) sender).getWorld().getName());
|
||||
} else if (cmd.equalsIgnoreCase("minecraft:me")) {
|
||||
if (!(sender instanceof Player) || !PluginMain.essentials.getUser((Player) sender).isMuted()) {
|
||||
String msg = message.substring(index + 1);
|
||||
TBMCChatAPI.SendSystemMessage(Channel.GlobalChat, Channel.RecipientTestResult.ALL, String.format("* %s %s", ChromaUtils.getDisplayName(sender), msg), TBMCSystemChatEvent.BroadcastTarget.ALL); //TODO: Don't send to all
|
||||
return true;
|
||||
} else {
|
||||
sender.sendMessage("§cCan't use /minecraft:me while muted.");
|
||||
return true;
|
||||
}
|
||||
} else if (cmd.equalsIgnoreCase("me")) { //Take over for Discord broadcast
|
||||
if (!(sender instanceof Player) || !PluginMain.essentials.getUser((Player) sender).isMuted()) {
|
||||
String msg = message.substring(index + 1);
|
||||
Bukkit.broadcastMessage(String.format("§5* %s %s", sender instanceof Player ? ((Player) sender).getDisplayName() : sender.getName(), msg));
|
||||
return true;
|
||||
} else {
|
||||
sender.sendMessage("§cCan't use /me while muted.");
|
||||
return true;
|
||||
}
|
||||
} else
|
||||
for (Channel channel : (Iterable<Channel>) Channel.getChannels()::iterator) {
|
||||
if (checkchid.test(channel, cmd)) { //Apparently method references don't require final variables
|
||||
TBMCChatAPI.SendChatMessage(ChatMessage.builder(sender, mp, message.substring(index + 1)).build(), channel);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
// TODO: Target selectors
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onTabComplete(PlayerChatTabCompleteEvent e) {
|
||||
String name = e.getLastToken();
|
||||
|
@ -136,12 +51,6 @@ public class PlayerListener implements Listener {
|
|||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST)
|
||||
public void onConsoleCommand(ServerCommandEvent event) {
|
||||
if (onCommandPreprocess(event.getSender(), event.getCommand()))
|
||||
event.setCommand("dontrunthiscmd");
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onGetInfo(TBMCPlayerGetInfoEvent e) {
|
||||
try (ChatPlayer cp = e.getPlayer().getAs(ChatPlayer.class)) {
|
||||
|
|
Loading…
Reference in a new issue