Skip to content

Commit b378677

Browse files
committed
Updated: Use text components for whitelist commands
Fixed: Correctly display "not in whitelist" in red. Updated: Use whitelist contents for /whitelist remove tab completion Players who haven't played yet will have a plain UUID tooltip.
1 parent a1c6856 commit b378677

File tree

3 files changed

+81
-8
lines changed

3 files changed

+81
-8
lines changed

modules/RoyalCommands/src/main/java/org/royaldev/royalcommands/rcommands/whitelist/SCmdAdd.java

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,17 @@
99
import org.bukkit.command.CommandSender;
1010
import org.royaldev.royalcommands.Config;
1111
import org.royaldev.royalcommands.MessageColor;
12+
import org.royaldev.royalcommands.RUtils;
1213
import org.royaldev.royalcommands.RoyalCommands;
1314
import org.royaldev.royalcommands.rcommands.CmdWhitelist;
1415
import org.royaldev.royalcommands.rcommands.SubCommand;
1516
import org.royaldev.royalcommands.wrappers.player.RPlayer;
1617

18+
import net.md_5.bungee.api.chat.BaseComponent;
19+
import net.md_5.bungee.api.chat.HoverEvent;
20+
import net.md_5.bungee.api.chat.TextComponent;
21+
import net.md_5.bungee.api.chat.hover.content.Text;
22+
1723
public class SCmdAdd extends SubCommand<CmdWhitelist> {
1824

1925
public SCmdAdd(final RoyalCommands instance, final CmdWhitelist parent) {
@@ -38,7 +44,22 @@ public boolean runCommand(final CommandSender cs, final Command cmd, final Strin
3844
Config.whitelist.add(uuid);
3945
this.plugin.whl.set("whitelist", Config.whitelist);
4046
this.getParent().reloadWhitelist();
41-
cs.sendMessage(MessageColor.POSITIVE + "Added " + MessageColor.NEUTRAL + rp.getName() + MessageColor.POSITIVE + " (" + MessageColor.NEUTRAL + uuid + MessageColor.POSITIVE + ") to whitelist.");
47+
48+
49+
TextComponent tc = new TextComponent("Added ");
50+
tc.setColor(MessageColor.POSITIVE.bc());
51+
BaseComponent bc = new TextComponent(rp.getPlayer() != null ? rp.getPlayer().getDisplayName() : rp.getName());
52+
bc.setColor(MessageColor.NEUTRAL.bc());
53+
if (rp.getPlayer() != null) {
54+
bc.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, RUtils.getPlayerTooltip(rp.getPlayer())));
55+
} else {
56+
bc.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new Text(rp.getUUID().toString())));
57+
}
58+
tc.addExtra(bc);
59+
60+
tc.addExtra(TextComponent.fromLegacy(MessageColor.POSITIVE + " to the whitelist."));
61+
62+
cs.spigot().sendMessage(tc);
4263
return true;
4364
}
4465
}

modules/RoyalCommands/src/main/java/org/royaldev/royalcommands/rcommands/whitelist/SCmdCheck.java

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,17 @@
99
import org.bukkit.command.CommandSender;
1010
import org.royaldev.royalcommands.Config;
1111
import org.royaldev.royalcommands.MessageColor;
12+
import org.royaldev.royalcommands.RUtils;
1213
import org.royaldev.royalcommands.RoyalCommands;
1314
import org.royaldev.royalcommands.rcommands.CmdWhitelist;
1415
import org.royaldev.royalcommands.rcommands.SubCommand;
1516
import org.royaldev.royalcommands.wrappers.player.RPlayer;
1617

18+
import net.md_5.bungee.api.chat.BaseComponent;
19+
import net.md_5.bungee.api.chat.HoverEvent;
20+
import net.md_5.bungee.api.chat.TextComponent;
21+
import net.md_5.bungee.api.chat.hover.content.Text;
22+
1723
public class SCmdCheck extends SubCommand<CmdWhitelist> {
1824

1925
public SCmdCheck(final RoyalCommands instance, final CmdWhitelist parent) {
@@ -31,11 +37,23 @@ public boolean runCommand(final CommandSender cs, final Command cmd, final Strin
3137
}
3238
final RPlayer rp = this.getParent().getRPlayer(RoyalCommands.getFinalArg(eargs, 0));
3339
final String uuid = rp.getUUID().toString();
34-
cs.sendMessage(
35-
Config.whitelist.contains(uuid)
36-
? MessageColor.NEUTRAL + rp.getName() + MessageColor.POSITIVE + " (" + MessageColor.NEUTRAL + uuid + MessageColor.POSITIVE + ") is in the whitelist."
37-
: MessageColor.NEUTRAL + rp.getName() + MessageColor.NEGATIVE + " (" + MessageColor.NEUTRAL + uuid + MessageColor.POSITIVE + ") is not in the whitelist."
38-
);
40+
Boolean inWhitelist = Config.whitelist.contains(uuid);
41+
String inWhitelistStr = inWhitelist ? "" : "not ";
42+
MessageColor inWhitelistColor = inWhitelist ? MessageColor.POSITIVE : MessageColor.NEGATIVE;
43+
44+
TextComponent tc = new TextComponent("");
45+
BaseComponent bc = new TextComponent(rp.getPlayer() != null ? rp.getPlayer().getDisplayName() : rp.getName());
46+
bc.setColor(MessageColor.NEUTRAL.bc());
47+
if (rp.getPlayer() != null) {
48+
bc.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, RUtils.getPlayerTooltip(rp.getPlayer())));
49+
} else {
50+
bc.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new Text(rp.getUUID().toString())));
51+
}
52+
tc.addExtra(bc);
53+
54+
tc.addExtra(TextComponent.fromLegacy(" " + inWhitelistColor + "is " + inWhitelistStr + "in the whitelist."));
55+
56+
cs.spigot().sendMessage(tc);
3957
return true;
4058
}
4159
}

modules/RoyalCommands/src/main/java/org/royaldev/royalcommands/rcommands/whitelist/SCmdRemove.java

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,38 @@
55
*/
66
package org.royaldev.royalcommands.rcommands.whitelist;
77

8+
import java.util.ArrayList;
9+
import java.util.List;
10+
811
import org.bukkit.command.Command;
912
import org.bukkit.command.CommandSender;
1013
import org.royaldev.royalcommands.Config;
1114
import org.royaldev.royalcommands.MessageColor;
15+
import org.royaldev.royalcommands.RUtils;
1216
import org.royaldev.royalcommands.RoyalCommands;
1317
import org.royaldev.royalcommands.rcommands.CmdWhitelist;
1418
import org.royaldev.royalcommands.rcommands.SubCommand;
1519
import org.royaldev.royalcommands.wrappers.player.RPlayer;
1620

21+
import net.md_5.bungee.api.chat.BaseComponent;
22+
import net.md_5.bungee.api.chat.HoverEvent;
23+
import net.md_5.bungee.api.chat.TextComponent;
24+
import net.md_5.bungee.api.chat.hover.content.Text;
25+
1726
public class SCmdRemove extends SubCommand<CmdWhitelist> {
1827

1928
public SCmdRemove(final RoyalCommands instance, final CmdWhitelist parent) {
20-
super(instance, parent, "remove", true, "Removes a player from the whitelist.", "<command> (player)", new String[0], new Short[]{CompletionType.ONLINE_PLAYER.getShort()});
29+
super(instance, parent, "remove", true, "Removes a player from the whitelist.", "<command> (player)", new String[0], new Short[]{CompletionType.LIST.getShort()});
30+
}
31+
32+
@Override
33+
protected List<String> customList(final CommandSender cs, final Command cmd, final String label, final String[] args, final String arg) {
34+
List<String> players = new ArrayList<>();
35+
for (String p : Config.whitelist) {
36+
final RPlayer rp = this.getParent().getRPlayer(p);
37+
players.add(rp.getName());
38+
}
39+
return players;
2140
}
2241

2342
@Override
@@ -38,7 +57,22 @@ public boolean runCommand(final CommandSender cs, final Command cmd, final Strin
3857
Config.whitelist.remove(uuid);
3958
this.plugin.whl.set("whitelist", Config.whitelist);
4059
this.getParent().reloadWhitelist();
41-
cs.sendMessage(MessageColor.POSITIVE + "Removed " + MessageColor.NEUTRAL + rp.getName() + MessageColor.POSITIVE + " (" + MessageColor.NEUTRAL + uuid + MessageColor.POSITIVE + ") from whitelist.");
60+
61+
TextComponent tc = new TextComponent("Removed ");
62+
tc.setColor(MessageColor.POSITIVE.bc());
63+
BaseComponent bc = new TextComponent(rp.getPlayer() != null ? rp.getPlayer().getDisplayName() : rp.getName());
64+
bc.setColor(MessageColor.NEUTRAL.bc());
65+
if (rp.getPlayer() != null) {
66+
bc.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, RUtils.getPlayerTooltip(rp.getPlayer())));
67+
} else {
68+
bc.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new Text(rp.getUUID().toString())));
69+
}
70+
tc.addExtra(bc);
71+
72+
tc.addExtra(TextComponent.fromLegacy(MessageColor.POSITIVE + " from the whitelist."));
73+
74+
cs.spigot().sendMessage(tc);
75+
4276
return true;
4377
}
4478
}

0 commit comments

Comments
 (0)