Skip to content

Commit 59cd8e8

Browse files
committed
fix permissions, messages, config & admin commands
1 parent 297b256 commit 59cd8e8

9 files changed

Lines changed: 192 additions & 278 deletions

File tree

src/main/java/onevnl/ru/elytrya/commands/BoostyCommand.java

Lines changed: 28 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,6 @@ public BoostyCommand(BoostyClient client) {
2828
registerSubCommand(new InfoSubCommand(client));
2929
registerSubCommand(new AdminSubCommand(client));
3030
registerSubCommand(new DiscordSubCommand(client));
31-
32-
Bukkit.getLogger().info(
33-
"[BoostyBridge] Command initialized. Discord enabled status: " +
34-
isDiscordEnabled()
35-
);
3631
}
3732

3833
private void registerSubCommand(SubCommand cmd) {
@@ -63,26 +58,25 @@ public boolean onCommand(
6358
boolean discordEnabled = isDiscordEnabled();
6459

6560
if (args.length == 0 || args[0].equalsIgnoreCase("help")) {
66-
List<String> helpLines = msg.getMessageList("help_menu");
67-
for (String line : helpLines) {
68-
if (
69-
!discordEnabled &&
70-
(line.contains("/boosty discord") || line.contains("discord"))
71-
) {
72-
continue;
61+
List<String> lines = msg.getMessageList("help_menu");
62+
if (lines != null) {
63+
for (String line : lines) {
64+
if (
65+
!discordEnabled &&
66+
(line.contains("/boosty discord") || line.contains("discord"))
67+
) {
68+
continue;
69+
}
70+
sender.sendMessage(line);
7371
}
74-
sender.sendMessage(line);
7572
}
7673

77-
if (
78-
sender.hasPermission("boosty.admin.unlink") ||
79-
sender.hasPermission("boosty.admin.info") ||
80-
sender.hasPermission("boosty.admin.forcelink") ||
81-
sender.hasPermission("boosty.admin.forcesync")
82-
) {
83-
List<String> adminHelp = msg.getMessageList("help_menu_admin");
84-
for (String line : adminHelp) {
85-
sender.sendMessage(line);
74+
if (sender.hasPermission("boosty.admin.*")) {
75+
List<String> adminLines = msg.getMessageList("help_menu_admin");
76+
if (adminLines != null) {
77+
for (String line : adminLines) {
78+
sender.sendMessage(line);
79+
}
8680
}
8781
}
8882
return true;
@@ -162,27 +156,28 @@ private void handleAdminTab(
162156
) {
163157
if (args.length == 2) {
164158
String input = args[1].toLowerCase();
165-
166-
List<String> adminActions = new ArrayList<>();
167-
adminActions.add("unlink");
168-
adminActions.add("info");
169-
adminActions.add("forcelink");
170-
adminActions.add("forcesync");
171-
if (discordEnabled) {
172-
adminActions.add("setdiscord");
173-
}
159+
String[] adminActions = {
160+
"unlink",
161+
"info",
162+
"forcelink",
163+
"forcesync",
164+
"setdiscord",
165+
};
174166

175167
for (String s : adminActions) {
168+
if (s.equals("setdiscord") && !discordEnabled) continue;
169+
176170
if (s.startsWith(input) && sender.hasPermission("boosty.admin." + s)) {
177171
list.add(s);
178172
}
179173
}
180174
} else if (args.length == 3) {
181-
handlePlayerTab(list, args, discordEnabled);
175+
handlePlayerTab(sender, list, args, discordEnabled);
182176
}
183177
}
184178

185179
private void handlePlayerTab(
180+
CommandSender sender,
186181
List<String> list,
187182
String[] args,
188183
boolean discordEnabled
@@ -194,6 +189,7 @@ private void handlePlayerTab(
194189
sub.equals("unlink") || sub.equals("info") || sub.equals("setdiscord")
195190
) {
196191
if (sub.equals("setdiscord") && !discordEnabled) return;
192+
if (!sender.hasPermission("boosty.admin." + sub)) return;
197193

198194
client
199195
.getDatabase()
@@ -202,15 +198,6 @@ private void handlePlayerTab(
202198
.map(BoostyUser::playerName)
203199
.filter(n -> n.toLowerCase().startsWith(input))
204200
.forEach(list::add);
205-
} else if (sub.equals("forcelink")) {
206-
client
207-
.getPlugin()
208-
.getServer()
209-
.getOnlinePlayers()
210-
.stream()
211-
.map(Player::getName)
212-
.filter(n -> n.toLowerCase().startsWith(input))
213-
.forEach(list::add);
214201
}
215202
}
216203
}

0 commit comments

Comments
 (0)