Skip to content

Commit fe887ee

Browse files
committed
Update to v1.1.0-beta1
1 parent 6df3bd0 commit fe887ee

File tree

20 files changed

+847
-641
lines changed

20 files changed

+847
-641
lines changed

README.md

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ on [SpigotMC.org](https://www.spigotmc.org/resources/betterwhitelist.101614/)
2121
as well. Prereleases are found only here on GitHub. If you find a bug, fill in
2222
bug report in GitHub [issues page](https://www.github.com/Polda18/BetterWhitelist/issues).
2323

24-
## How it works and issue with vanilla whitelist
24+
## How does it work and issue with vanilla whitelist
2525
Pretty much how you would expect the whitelist to work. It checks if the player
2626
is on the whitelist and if not, it kicks them out of the server with appropriate
2727
message. Managing the whitelist is you add a player to the whitelist and turn
@@ -66,14 +66,14 @@ use it. These are the subcommands:
6666
permission to run
6767
- `on` - Turns the whitelist on, requires `betterwhitelist.admin` permission to run
6868
- `off` - Turns the whitelist off, requires `betterwhitelist.admin` permission to run
69-
- `list` - Lists all whitelisted players, requires `betterwhitelist.list` permission to run
70-
- `add <playername>` - Adds specified player to the whitelist, requires `betterwhitelist.add`
71-
permission to run
72-
- `remove <playername>` - Removes specified player from the whitelist, requires `betterwhitelist.remove`
73-
permission to run
69+
- `list [p:<page number>]` - Lists all whitelisted players, requires `betterwhitelist.list` permission to run
70+
- `add <playername> [<another playername> ...]` - Adds specified player(s) to the whitelist,
71+
requires `betterwhitelist.add` permission to run
72+
- `remove <playername> [<another playername> ...]` - Removes specified player(s) from the whitelist,
73+
requires `betterwhitelist.remove` permission to run
7474
- `import` - Imports players from vanilla whitelist to be used with this plugin, requires
7575
`betterwhitelist.admin` permission to run
76-
- `lang <language code>` - Checks or changes language of the plugin messages, requires
76+
- `lang [<language code>]` - Checks or changes language of the plugin messages, requires
7777
`betterwhitelist.admin` permission to run
7878
- `reload` - Reloads the whitelist and configuration from the plugin files (used mainly if you do
7979
manual edits - not recommended), requires `betterwhitelist.admin` permission to run
@@ -83,6 +83,8 @@ use it. These are the subcommands:
8383
If you're using permissions plugin, this is a list of available permissions you'll need to use.
8484
All permissions default to server operators (op).
8585

86+
- `betterwhitelist` - This is a base permission and needs to be assigned to anyone who will be working with
87+
this whitelist plugin. Without this permission, the command won't be accessible.
8688
- `betterwhitelist.*` - This is a wildcard permission, which is equivalent for `betterwhitelist.admin`.
8789
It's recommended to use the named permission.
8890
- `betterwhitelist.admin` - This is a super permission that allows you to access all subcommands,
@@ -122,10 +124,15 @@ If you had your players in vanilla whitelist previously, you can import them
122124
using this command: `/wl import`. No additional parameters are required to run this
123125
command, no additional parameters are also taken into account. Running this
124126
command silently adds all players found in vanilla whitelist to whitelist of this
125-
plugin. You can verify content by executing `/wl list` command. To add a new player
126-
to the whitelist simply run `/wl add <playername>` where `<playername>` refers to
127-
the player IGN, and to remove a player from the whitelist run `/wl remove <playername>`
128-
where `<playername>` again refers to the player IGN.
127+
plugin. You can verify content by executing `/wl list` command. List is numbered,
128+
so to view next page, add `p:<page number>` argument to the command, where
129+
`<page_number>` is the page number you want to view. To add a new player
130+
to the whitelist simply run `/wl add <playername>` where `<playername>` refers
131+
to the player IGN, and to remove a player from the whitelist run
132+
`/wl remove <playername>` where `<playername>` again refers to the player IGN.
133+
It is possible to add or remove multiple players from whitelist by specifying more
134+
player names separated by spaces. If you use the command in game, it tries to autocomplete
135+
your command.
129136

130137
### Disclaimer
131138
This plugin isn't intended to support criminal behavior. It is intended to aid

pom.xml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
55
<modelVersion>4.0.0</modelVersion>
66

7-
<groupId>me.polda18</groupId>
7+
<groupId>cz.czghost.mcspigot</groupId>
88
<artifactId>BetterWhitelist</artifactId>
9-
<version>1.0.1</version>
9+
<version>1.1.0-beta1</version>
1010
<packaging>jar</packaging>
1111

1212
<name>BetterWhitelist</name>
@@ -16,7 +16,7 @@
1616
<java.version>1.17</java.version>
1717
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
1818
</properties>
19-
<url>https://polda18.github.io/BetterWhitelist</url>
19+
<url>https://www.github.com/Polda18/BetterWhitelist</url>
2020

2121
<build>
2222
<plugins>
@@ -25,8 +25,8 @@
2525
<artifactId>maven-compiler-plugin</artifactId>
2626
<version>3.8.1</version>
2727
<configuration>
28-
<source>11</source>
29-
<target>11</target>
28+
<source>16</source>
29+
<target>16</target>
3030
</configuration>
3131
</plugin>
3232
<plugin>

src/main/java/me/polda18/betterwhitelist/BetterWhitelist.java renamed to src/main/java/cz/czghost/mcspigot/betterwhitelist/BetterWhitelist.java

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
package me.polda18.betterwhitelist;
2-
3-
import me.polda18.betterwhitelist.commands.Autocomplete;
4-
import me.polda18.betterwhitelist.commands.WhitelistCommand;
5-
import me.polda18.betterwhitelist.config.Language;
6-
import me.polda18.betterwhitelist.config.Whitelist;
7-
import me.polda18.betterwhitelist.events.EventsListener;
8-
import me.polda18.betterwhitelist.utils.InvalidEntryException;
1+
package cz.czghost.mcspigot.betterwhitelist;
2+
3+
import cz.czghost.mcspigot.betterwhitelist.commands.Autocomplete;
4+
import cz.czghost.mcspigot.betterwhitelist.utils.InvalidEntryException;
5+
import cz.czghost.mcspigot.betterwhitelist.commands.WhitelistCommand;
6+
import cz.czghost.mcspigot.betterwhitelist.config.Language;
7+
import cz.czghost.mcspigot.betterwhitelist.config.Whitelist;
8+
import cz.czghost.mcspigot.betterwhitelist.events.EventsListener;
99
import org.bukkit.ChatColor;
1010
import org.bukkit.configuration.InvalidConfigurationException;
1111
import org.bukkit.configuration.file.FileConfiguration;
@@ -62,6 +62,7 @@ public Map<String, String> listAvailableLanguages() {
6262
public void setWhitelistEnabled(boolean enabled) {
6363
this.enabled = enabled;
6464
getConfig().set("enabled", enabled);
65+
saveConfig();
6566
}
6667

6768
/**
@@ -137,6 +138,7 @@ public void setLanguage(String lang_code) throws InvalidEntryException {
137138

138139
this.lang_code = lang_code;
139140
getConfig().set("language", lang_code);
141+
saveConfig();
140142
}
141143

142144
/**
Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
package cz.czghost.mcspigot.betterwhitelist.commands;
2+
3+
import cz.czghost.mcspigot.betterwhitelist.BetterWhitelist;
4+
import org.bukkit.command.Command;
5+
import org.bukkit.command.CommandSender;
6+
import org.bukkit.command.ConsoleCommandSender;
7+
import org.bukkit.command.TabCompleter;
8+
import org.jetbrains.annotations.NotNull;
9+
import org.jetbrains.annotations.Nullable;
10+
11+
import java.util.ArrayList;
12+
import java.util.List;
13+
import java.util.stream.Collectors;
14+
15+
/**
16+
* Autocomplete command in chat
17+
*/
18+
public class Autocomplete implements TabCompleter {
19+
private final BetterWhitelist plugin;
20+
21+
/**
22+
* Constructor: creates this autocompletion handler to be registered in the plugin
23+
* @param plugin Plugin instance to be used for access to configurations
24+
*/
25+
public Autocomplete(BetterWhitelist plugin) {
26+
this.plugin = plugin;
27+
}
28+
29+
/**
30+
* Fires when the autocompletion event happens
31+
* @param sender Command sender that is writing the command
32+
* @param command Command definition itself
33+
* @param alias Alias definition of the command itself
34+
* @param args List of arguments in the command being written
35+
* @return List of suggestions for next autocompletion
36+
*/
37+
@Override
38+
public @Nullable List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String alias, @NotNull String[] args) {
39+
ArrayList<String> list = new ArrayList<>();
40+
boolean isConsole = sender instanceof ConsoleCommandSender;
41+
42+
if(!command.getName().equalsIgnoreCase("whitelist")) {
43+
return null;
44+
// Make sure this autocomplete only returns when the command invoked belongs to this plugin
45+
// Since this plugin is a single-purpose, only one command belongs in here.
46+
}
47+
48+
if(args.length > 1) {
49+
switch (args[0].toLowerCase()) {
50+
case "add": // User wants to add a player to whitelist
51+
if (isConsole || sender.hasPermission("betterwhitelist.add")) {
52+
if (args[args.length - 1].isEmpty())
53+
list.add("ExamplePlayer"); // Give an example player :)
54+
else list.add(args[args.length - 1]);
55+
} else {
56+
return null;
57+
}
58+
break;
59+
case "remove": // User wants to remove player from whitelist
60+
if (isConsole || sender.hasPermission("betterwhitelist.remove")) {
61+
// Get all whitelisted players
62+
list.addAll(plugin.getWhitelist().getConfig().getKeys(false));
63+
64+
list = (ArrayList<String>) list.stream()
65+
.filter(s -> s.startsWith(args[args.length - 1])).collect(Collectors.toList());
66+
} else {
67+
return null;
68+
}
69+
break;
70+
case "lang": // User wants to view or change set language
71+
// Give a list of available languages
72+
if (isConsole || sender.hasPermission("betterwhitelist.admin")) {
73+
list.addAll(plugin.listAvailableLanguages().keySet());
74+
75+
list = (ArrayList<String>) list.stream()
76+
.filter(s -> s.startsWith(args[1])).collect(Collectors.toList());
77+
} else {
78+
return null;
79+
}
80+
break;
81+
case "list": // User wants to list players
82+
// Provide a page number specification
83+
if (isConsole || sender.hasPermission("betterwhitelist.list")) {
84+
list.add("p:");
85+
86+
list = (ArrayList<String>) list.stream()
87+
.filter(s -> s.startsWith(args[1])).collect(Collectors.toList());
88+
} else {
89+
return null;
90+
}
91+
break;
92+
default: // User entered invalid subcommand or subcommand has no arguments
93+
// Invalid subcommand provided or subcommand has no arguments, default to no list given
94+
return null;
95+
}
96+
} else {
97+
if (isConsole || sender.hasPermission("betterwhitelist.admin")) {
98+
// Add to list only if command sender has admin permissions
99+
list.add("on");
100+
list.add("off");
101+
list.add("reload");
102+
list.add("lang");
103+
list.add("import");
104+
list.add("status");
105+
list.add("version");
106+
}
107+
if (isConsole || sender.hasPermission("betterwhitelist.add"))
108+
list.add("add"); // Add to list only if command sender has add permission
109+
if (isConsole || sender.hasPermission("betterwhitelist.remove"))
110+
list.add("remove"); // Add to list only if command sender has remove permission
111+
if (isConsole || sender.hasPermission("betterwhitelist.list"))
112+
list.add("list"); // Add to list only if command sender has list permission
113+
if (list.isEmpty()) {
114+
return null; // If the list is empty (sender has no permission), no list is given
115+
}
116+
117+
// List is not empty, filter through start of the argument
118+
list = (ArrayList<String>) list.stream()
119+
.filter(s -> s.startsWith(args[0])).collect(Collectors.toList());
120+
}
121+
122+
return list;
123+
}
124+
}

0 commit comments

Comments
 (0)