-
-
Notifications
You must be signed in to change notification settings - Fork 73
Expand file tree
/
Copy pathToggleConnectionMsgsCmd.java
More file actions
76 lines (62 loc) · 2.93 KB
/
ToggleConnectionMsgsCmd.java
File metadata and controls
76 lines (62 loc) · 2.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
package me.xginko.aef.commands;
import me.xginko.aef.AnarchyExploitFixes;
import me.xginko.aef.utils.enums.AEFKey;
import me.xginko.aef.utils.permissions.AEFPermission;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.NamedTextColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandException;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.persistence.PersistentDataContainer;
import org.bukkit.persistence.PersistentDataType;
import org.jetbrains.annotations.NotNull;
import java.util.Collections;
import java.util.List;
public class ToggleConnectionMsgsCmd extends Command implements AEFCommand {
public ToggleConnectionMsgsCmd() {
super("toggleconnectionmsgs", "Toggle connection messages", "/toggleconnectionmsgs", Collections.singletonList("tcmsgs"));
}
@Override
public boolean shouldEnable() {
return AnarchyExploitFixes.config().cmd_toggleConMsgs_enabled;
}
@Override
@SuppressWarnings("UnstableApiUsage")
public void enable() {
AnarchyExploitFixes plugin = AnarchyExploitFixes.getInstance();
plugin.getServer().getCommandMap().register(plugin.getPluginMeta().getName().toLowerCase(), this);
}
@Override
public @NotNull List<String> tabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args)
throws CommandException, IllegalArgumentException
{
return Collections.emptyList();
}
@Override
@SuppressWarnings("DataFlowIssue")
public boolean execute(@NotNull CommandSender sender, @NotNull String commandLabel, @NotNull String[] args) {
if (!AnarchyExploitFixes.permissions().permissionValue(sender, AEFPermission.CMD_TOGGLE_CONNECT_MSGS.node()).toBoolean()) {
sender.sendMessage(AnarchyExploitFixes.getLang(sender).no_permission);
return true;
}
if (!(sender instanceof Player player)) {
sender.sendMessage(Component.text("Only players can execute this command.").color(NamedTextColor.RED));
return true;
}
boolean msgsWereVisible;
PersistentDataContainer dataContainer = player.getPersistentDataContainer();
if (!dataContainer.has(AEFKey.CONNECT_MSG_TOGGLE.getKey(), PersistentDataType.BOOLEAN)) {
msgsWereVisible = AnarchyExploitFixes.config().connectionMsgsAreOnByDefault;
} else {
msgsWereVisible = dataContainer.get(AEFKey.CONNECT_MSG_TOGGLE.getKey(), PersistentDataType.BOOLEAN);
}
dataContainer.set(AEFKey.CONNECT_MSG_TOGGLE.getKey(), PersistentDataType.BOOLEAN, !msgsWereVisible);
if (msgsWereVisible) {
player.sendMessage(AnarchyExploitFixes.getLang(player.locale()).misc_disabledConnectionMsgs);
} else {
player.sendMessage(AnarchyExploitFixes.getLang(player.locale()).misc_enabledConnectionMsgs);
}
return true;
}
}