Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/auto whitelist #16

Merged
merged 105 commits into from
Apr 17, 2023
Merged
Show file tree
Hide file tree
Changes from 104 commits
Commits
Show all changes
105 commits
Select commit Hold shift + click to select a range
7ff8ea0
Add YAML configuration for automatic whitelisting
voidpointer0x00 Mar 26, 2023
904ab40
Refactoring: make listener method names make more sense
voidpointer0x00 Apr 2, 2023
ab4e135
Explicitly declare `normal` event priority
voidpointer0x00 Apr 2, 2023
376fca5
Caution note when setting `max-repeats` < 1
voidpointer0x00 Apr 2, 2023
ec3e4df
0.9.4-unstable
voidpointer0x00 Apr 2, 2023
a467de5
Implement auto whitelist configuration with migration
voidpointer0x00 Apr 2, 2023
c1cfd1b
Change event priorities for disallow & auto whitelist
voidpointer0x00 Apr 3, 2023
344242f
Backwards-compatibility: use older method for parsing JsonReader
voidpointer0x00 Apr 3, 2023
9d3d3d9
Backwards-compatibility: api-version 1.18->1.13
voidpointer0x00 Apr 3, 2023
3628ee2
It works, TODO removed :)
voidpointer0x00 Apr 3, 2023
fb8152f
Merge branch 'dev-j8' into feature/auto-whitelist
voidpointer0x00 Apr 3, 2023
4762d7c
Implement strategy predicates
voidpointer0x00 Apr 3, 2023
7200e6a
Implement auto-whitelist listener logic
voidpointer0x00 Apr 3, 2023
df9f4b0
Add `timesAutoWhitelisted` field to `Whitelistable` implementations
voidpointer0x00 Apr 3, 2023
b04245d
0.9.x -> 1.0.0, incompatible changes to db schema were made
voidpointer0x00 Apr 3, 2023
d2916b7
Fix: update `timesAutoWhitelisted` field after auto-whitelist
voidpointer0x00 Apr 3, 2023
f9979c5
Implement V3 JSON update
voidpointer0x00 Apr 3, 2023
1d2cd26
Fix: invert `#hasPlayedBefore()`
voidpointer0x00 Apr 4, 2023
1ab081a
Rephrase logging message a bit
voidpointer0x00 Apr 4, 2023
1489310
Fix: timesAutoWhitelisted was left unchanged on `#add()`
voidpointer0x00 Apr 4, 2023
95515ac
Rollback new timesAutoWhitelisted field invention
voidpointer0x00 Apr 4, 2023
09d4b9c
Change description for `max-repeats` property
voidpointer0x00 Apr 4, 2023
2cf4e25
Rewrite docs for `#isDateExpirable(Date)`
voidpointer0x00 Apr 4, 2023
6e7724a
Remove TODO
voidpointer0x00 Apr 4, 2023
9ceb166
Introduce AutoWhitelistService
voidpointer0x00 Apr 8, 2023
c54fb8d
Fix: use public getter for whitelist field
voidpointer0x00 Apr 8, 2023
4392698
Use AutoWhitelistService type
voidpointer0x00 Apr 8, 2023
df86cb6
Fix WhitelistService DI
voidpointer0x00 Apr 8, 2023
0c8328c
Disallow only if max-repeats equals 0 (not `<=`)
voidpointer0x00 Apr 8, 2023
dc05cf4
Change method argument Whitelistable->UUID
voidpointer0x00 Apr 8, 2023
654b121
Add method `#add()` with AutoWhitelistNumber
voidpointer0x00 Apr 8, 2023
77d0a71
Add `#ZERO` implementation & default implementation for `#isExceeded()`
voidpointer0x00 Apr 8, 2023
a04e962
Implement AutoWhitelistNumber json storage
voidpointer0x00 Apr 8, 2023
e39e9e1
Add dummy implementation for new AutoWhitelistNumber stuff
voidpointer0x00 Apr 8, 2023
dd5b865
Fix logic to match new AutoWhitelistNumber stuff
voidpointer0x00 Apr 8, 2023
07f1630
Change & document format
voidpointer0x00 Apr 8, 2023
9da4e47
Refactoring: getTimesAutoWhitelisted->get()
voidpointer0x00 Apr 8, 2023
b5dcd21
Refactoring: swap arguments places
voidpointer0x00 Apr 8, 2023
7c6ea3a
Implement `#save()` & `#saveAutoWhitelist()`
voidpointer0x00 Apr 8, 2023
20ad47d
Fix timesAutoWhitelisted not being changed & refactoring
voidpointer0x00 Apr 8, 2023
687212c
Fix NPE
voidpointer0x00 Apr 8, 2023
8b68ccf
Fix: save json with wrapper
voidpointer0x00 Apr 8, 2023
5e62876
Refactoring: rename field dao->whitelistDao
voidpointer0x00 Apr 12, 2023
b480900
Remove unused generic type
voidpointer0x00 Apr 12, 2023
512349b
Implement db service methods for AutoWhitelistNumber
voidpointer0x00 Apr 12, 2023
c87df17
Get rid of plugin reference
voidpointer0x00 Apr 12, 2023
d897225
Refactoring: move Dbms to storage.db package, make credentials access…
voidpointer0x00 Apr 12, 2023
15355e5
Refactoring: ReconnectResult->ConnectionResult
voidpointer0x00 Apr 12, 2023
b8b9660
Change default strategy newcomers->all
voidpointer0x00 Apr 12, 2023
c0e1110
Refactoring: create OrmliteDatabase class to maintain SRP
voidpointer0x00 Apr 12, 2023
d0444d4
Avoid possible NPE
voidpointer0x00 Apr 12, 2023
1e7f3c1
Add `@NoArgsConstructor`
voidpointer0x00 Apr 12, 2023
6447416
Fix `Unable to run insert stmt` on update
voidpointer0x00 Apr 12, 2023
65ea38e
Edit log message & disallow if auto-whitelist failed
voidpointer0x00 Apr 12, 2023
25ea05c
Implement migrations subsystem
voidpointer0x00 Apr 12, 2023
84aea84
Remove async event change
voidpointer0x00 Apr 13, 2023
a296794
Refactoring: AutoWhitelistNumber -> TimesAutoWhitelistedNumber
voidpointer0x00 Apr 15, 2023
d6c9329
Refactoring: make class public, static methods package accessible
voidpointer0x00 Apr 15, 2023
248eb70
Make class final
voidpointer0x00 Apr 15, 2023
ce6b14a
Refactoring: add public #add() and #save() methods, rework internals
voidpointer0x00 Apr 15, 2023
7c1f20d
Add `#findAllAuto()` and `#getTotalCountOf..()` methods
voidpointer0x00 Apr 15, 2023
76896e6
Implement auto whitelist table export
voidpointer0x00 Apr 15, 2023
3279e32
Refactoring: store UUIDs instead of Whitelistables in import event
voidpointer0x00 Apr 15, 2023
1d05755
Refactoring: log exception on `#addAll()` failure
voidpointer0x00 Apr 15, 2023
c4d4f89
Get rid of WhitelistImportEvent
voidpointer0x00 Apr 15, 2023
ea47bb9
TimesAutoWhitelistedNumber: add `#getUniqueId()` and remove `ZERO`
voidpointer0x00 Apr 15, 2023
a72b349
Add `#addAll()` replacing & ifNotExists methods for auto whitelist
voidpointer0x00 Apr 15, 2023
5d7ea41
Implement import with timesAutoWhitelisted
voidpointer0x00 Apr 15, 2023
fe63650
Refactoring: move whitelist commands to whitelist package
voidpointer0x00 Apr 15, 2023
3450f99
Make permission setter public
voidpointer0x00 Apr 15, 2023
b9dd14f
Add public getter for `commands` field
voidpointer0x00 Apr 15, 2023
d7d0f93
Automatically generate permissions for subcommands
voidpointer0x00 Apr 15, 2023
884795e
Refactoring: use Duration instead of EssentialsDateParser and get rid…
voidpointer0x00 Apr 15, 2023
f673ed9
Add permissions
voidpointer0x00 Apr 15, 2023
38249a5
Add `#update()` method for times auto whitelisted
voidpointer0x00 Apr 15, 2023
61986d2
Fix: save whitelist on whitelistable update
voidpointer0x00 Apr 15, 2023
fa54ada
Add `#zero(UUID)` static factory
voidpointer0x00 Apr 15, 2023
e0ff26a
Implement first batch of auto-whitelist commands
voidpointer0x00 Apr 15, 2023
905cebd
Register auto-whitelist command
voidpointer0x00 Apr 15, 2023
c86ab3e
Change default strategy `newcomers` -> `all`
voidpointer0x00 Apr 15, 2023
7900f5d
Refactoring: rename `max-repeats` -> `limit`
voidpointer0x00 Apr 15, 2023
21dd836
Remove TODO comment
voidpointer0x00 Apr 16, 2023
38be624
Refactoring: migration `factory` -> `repository`
voidpointer0x00 Apr 16, 2023
7ba1fe9
Delete WhitelistImportEvent class
voidpointer0x00 Apr 16, 2023
a81494f
Fix: send args message instead of fail `onNotEnoughArgs`
voidpointer0x00 Apr 16, 2023
3a2b598
Add support for `player-details` placeholder
voidpointer0x00 Apr 16, 2023
6caabfc
Implement on/off commands
voidpointer0x00 Apr 16, 2023
246c1f9
Implement `set` and `info` commands
voidpointer0x00 Apr 16, 2023
4b2c032
Refactoring: create public StrategyPredicate enum instead of factory
voidpointer0x00 Apr 16, 2023
0024929
Remove 10 years cap
voidpointer0x00 Apr 17, 2023
6c6facf
Fix: dependency not found
voidpointer0x00 Apr 17, 2023
b21ff51
Add description & permissions for all the new auto-whitelist commands
voidpointer0x00 Apr 17, 2023
b538b01
Fix: send the messages (they just ignored)
voidpointer0x00 Apr 17, 2023
7995068
Add `{player}` to invalid args message
voidpointer0x00 Apr 17, 2023
8e0e62b
Handle FileNotFoundException differently
voidpointer0x00 Apr 17, 2023
0c88335
Fix: send the message (previously it was just ignored)
voidpointer0x00 Apr 17, 2023
28cb864
Set newTimesAutoWhitelisted value to `{new}` placeholder
voidpointer0x00 Apr 17, 2023
54d49a9
Fix: use `createOrUpdate()` instead of `update()`
voidpointer0x00 Apr 17, 2023
1ce52e1
Implement configuration related commands
voidpointer0x00 Apr 17, 2023
c30cf2c
Remove second consecutive space character
voidpointer0x00 Apr 17, 2023
b6a7d7a
Add translation for new messages
voidpointer0x00 Apr 17, 2023
51fe03d
Refactoring: remove "number" from TimesAutoWhitelisted
voidpointer0x00 Apr 17, 2023
7874457
Fix: remove ' char in logging message (breaks placeholders)
voidpointer0x00 Apr 17, 2023
96c78fc
Also run config migrations on reload command
voidpointer0x00 Apr 17, 2023
4251375
unstable->stable
voidpointer0x00 Apr 17, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@

<groupId>voidpointer.spigot</groupId>
<artifactId>voidwhitelist</artifactId>
<version>0.9.5</version>
<version>1.0.0</version>
<packaging>jar</packaging>

<name>VoidWhitelist</name>

<description>UUID based temporal whitelist. Supports JSON, H2, MySQL and PostrgreSQL storage.</description>
<properties>
<version.stability>stable</version.stability>
<version.stability>unstable</version.stability>
<java.version>1.8</java.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package voidpointer.spigot.voidwhitelist;

import java.util.UUID;

public interface TimesAutoWhitelisted {
static TimesAutoWhitelisted zero(final UUID uniqueId) {
return of(uniqueId, 0);
}

static TimesAutoWhitelisted of(final UUID uniqueId, final int timesAutoWhitelisted) {
return new TimesAutoWhitelisted() {
@Override public UUID getUniqueId() {
return uniqueId;
}
@Override public int get() {
return timesAutoWhitelisted;
}
};
}

UUID getUniqueId();

int get();

default boolean isExceeded(final int limit) {
return (limit >= 0) && (get() >= limit);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@
import voidpointer.spigot.framework.localemodule.annotation.LocaleAnnotationResolver;
import voidpointer.spigot.framework.localemodule.annotation.PluginLocale;
import voidpointer.spigot.framework.localemodule.config.TranslatedLocaleFile;
import voidpointer.spigot.voidwhitelist.command.WhitelistCommand;
import voidpointer.spigot.voidwhitelist.command.autowhitelist.AutoWhitelistCommand;
import voidpointer.spigot.voidwhitelist.command.whitelist.WhitelistCommand;
import voidpointer.spigot.voidwhitelist.config.GuiConfig;
import voidpointer.spigot.voidwhitelist.config.WhitelistConfig;
import voidpointer.spigot.voidwhitelist.event.EventManager;
Expand All @@ -41,6 +42,7 @@
import voidpointer.spigot.voidwhitelist.message.WhitelistMessage;
import voidpointer.spigot.voidwhitelist.papi.PapiLocale;
import voidpointer.spigot.voidwhitelist.papi.TimeLeftExpansion;
import voidpointer.spigot.voidwhitelist.storage.AutoWhitelistService;
import voidpointer.spigot.voidwhitelist.storage.StorageFactory;
import voidpointer.spigot.voidwhitelist.storage.WhitelistService;
import voidpointer.spigot.voidwhitelist.task.KickTaskScheduler;
Expand All @@ -54,7 +56,8 @@ public final class VoidWhitelistPlugin extends JavaPlugin {
private static TranslatedLocaleFile locale;
@Dependency private static WhitelistConfig whitelistConfig;
@Dependency private static LocaleLog guiLocale;
@Dependency private static WhitelistService whitelistService;
@Dependency(id="whitelistService")
private static AutoWhitelistService whitelistService;
@Dependency private static EventManager eventManager;
@Dependency private static StorageFactory storageFactory;
@Dependency private static KickTaskScheduler kickTaskScheduler;
Expand All @@ -70,6 +73,7 @@ public final class VoidWhitelistPlugin extends JavaPlugin {
@Override public void onLoad() {
instance = this;
whitelistConfig = new WhitelistConfig(this);
whitelistConfig.runMigrations();
guiLocale = new GuiConfig(this, whitelistConfig).getLocaleLog();
papiLocale = new PapiLocale(this);
eventManager = new EventManager(this);
Expand All @@ -86,6 +90,7 @@ public final class VoidWhitelistPlugin extends JavaPlugin {
kickTaskScheduler = new KickTaskScheduler();
Injector.inject(this);
new WhitelistCommand().register(this);
new AutoWhitelistCommand().register(this);
registerListeners();
hookPapi();

Expand All @@ -95,11 +100,12 @@ public final class VoidWhitelistPlugin extends JavaPlugin {
}

@Override public void onDisable() {
whitelistService.shutdown();
if (whitelistService != null)
whitelistService.shutdown();
}

/** Changes the {@link WhitelistService}, but doesn't inject it. */
public void changeWhitelistService(final @NonNull WhitelistService whitelistService) {
public void changeWhitelistService(final @NonNull AutoWhitelistService whitelistService) {
VoidWhitelistPlugin.whitelistService = whitelistService;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,10 @@ public interface Whitelistable {
*/
boolean isAssociatedWith(final Player player);

/** @return {@code true} if the entity has an "expires at" date
* and {@code false} otherwise. */
/**
* @return {@code true} if the given {@link Date} can expire.
* @see #NEVER_EXPIRES
*/
static boolean isDateExpirable(final Date date) {
return NEVER_EXPIRES != date;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@

import static java.util.Collections.emptyList;
import static lombok.AccessLevel.PROTECTED;
import static lombok.AccessLevel.PUBLIC;

@Getter
@RequiredArgsConstructor
Expand All @@ -49,7 +50,7 @@ public abstract class Command implements CommandExecutor, TabCompleter {
private static final List<String> EMPTY_ALIASES = emptyList();
@AutowiredLocale private static LocaleLog localeLog;

@Setter(PROTECTED)
@Setter(PUBLIC)
private @NonNull String permission = EMPTY_PERMISSION;

private final String name;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
*/
package voidpointer.spigot.voidwhitelist.command;

import lombok.AccessLevel;
import lombok.Getter;
import voidpointer.spigot.framework.localemodule.LocaleLog;
import voidpointer.spigot.framework.localemodule.annotation.AutowiredLocale;
import voidpointer.spigot.voidwhitelist.command.arg.Args;
Expand All @@ -28,6 +30,8 @@

public final class CommandManager {
@AutowiredLocale private static LocaleLog log;

@Getter(AccessLevel.PUBLIC)
private final Map<String, Command> commands = new HashMap<>();

public void addCommand(final Command command) {
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package voidpointer.spigot.voidwhitelist.command.autowhitelist;

import org.bukkit.command.CommandSender;
import voidpointer.spigot.framework.localemodule.Locale;
import voidpointer.spigot.framework.localemodule.annotation.AutowiredLocale;
import voidpointer.spigot.voidwhitelist.command.Command;
import voidpointer.spigot.voidwhitelist.command.CommandManager;
import voidpointer.spigot.voidwhitelist.command.arg.Args;

import java.util.List;

import static voidpointer.spigot.voidwhitelist.message.WhitelistMessage.*;

public final class AutoWhitelistCommand extends Command {
public static final String NAME = "auto-whitelist";

@AutowiredLocale private static Locale locale;

private final CommandManager autoWhitelistCommands = new CommandManager();

public AutoWhitelistCommand() {
super(NAME);

super.setPermission("voidwhitelist.auto-whitelist");
super.setRequiredArgsNumber(1);

autoWhitelistCommands.addCommand(new HelpCommand());
/* general commands */
autoWhitelistCommands.addCommand(new EnableCommand());
autoWhitelistCommands.addCommand(new DisableCommand());
autoWhitelistCommands.addCommand(new IsOnCommand());
/* configuration related commands */
autoWhitelistCommands.addCommand(new GetDurationCommand());
autoWhitelistCommands.addCommand(new SetDurationCommand());
autoWhitelistCommands.addCommand(new GetLimitCommand());
autoWhitelistCommands.addCommand(new SetLimitCommand());
autoWhitelistCommands.addCommand(new GetStrategyCommand());
autoWhitelistCommands.addCommand(new SetStrategyCommand());
/* player related commands */
autoWhitelistCommands.addCommand(new InfoCommand());
autoWhitelistCommands.addCommand(new ResetCommand());
autoWhitelistCommands.addCommand(new SetCommand());
/* set appropriate permissions for sub commands */
autoWhitelistCommands.getCommands().values()
.forEach(cmd -> cmd.setPermission(getPermission() + '.' + cmd.getName()));
}

@Override public void execute(final Args args) {
final String subCommandName = args.removeFirst();
if (!autoWhitelistCommands.executeCommand(subCommandName, args))
locale.localize(AUTO_WHITELIST_UNKNOWN_COMMAND).send(args.getSender());
}

@Override public List<String> tabComplete(final Args args) {
return autoWhitelistCommands.tabComplete(args);
}

@Override protected void onNotEnoughArgs(final CommandSender sender, final Args args) {
locale.localize(AUTO_WHITELIST_NOT_ENOUGH_ARGS).send(sender);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package voidpointer.spigot.voidwhitelist.command.autowhitelist;

import voidpointer.spigot.framework.di.Autowired;
import voidpointer.spigot.framework.localemodule.Locale;
import voidpointer.spigot.framework.localemodule.annotation.AutowiredLocale;
import voidpointer.spigot.voidwhitelist.command.Command;
import voidpointer.spigot.voidwhitelist.command.arg.Args;
import voidpointer.spigot.voidwhitelist.config.WhitelistConfig;
import voidpointer.spigot.voidwhitelist.message.WhitelistMessage;

final class DisableCommand extends Command {
@AutowiredLocale private static Locale locale;
@Autowired private static WhitelistConfig whitelistConfig;

DisableCommand() {
super("off");
}

@Override public void execute(final Args args) {
whitelistConfig.disableAutoWhitelist();
locale.localize(WhitelistMessage.AUTO_WHITELIST_DISABLED).send(args.getSender());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package voidpointer.spigot.voidwhitelist.command.autowhitelist;

import voidpointer.spigot.framework.di.Autowired;
import voidpointer.spigot.framework.localemodule.Locale;
import voidpointer.spigot.framework.localemodule.annotation.AutowiredLocale;
import voidpointer.spigot.voidwhitelist.command.Command;
import voidpointer.spigot.voidwhitelist.command.arg.Args;
import voidpointer.spigot.voidwhitelist.config.WhitelistConfig;

import static voidpointer.spigot.voidwhitelist.message.WhitelistMessage.*;

final class EnableCommand extends Command {
@AutowiredLocale private static Locale locale;
@Autowired private static WhitelistConfig whitelistConfig;

EnableCommand() {
super("on");
}

@Override public void execute(final Args args) {
whitelistConfig.enableAutoWhitelist();
locale.localize(AUTO_WHITELIST_ENABLED).send(args.getSender());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package voidpointer.spigot.voidwhitelist.command.autowhitelist;

import voidpointer.spigot.framework.di.Autowired;
import voidpointer.spigot.framework.localemodule.Locale;
import voidpointer.spigot.framework.localemodule.annotation.AutowiredLocale;
import voidpointer.spigot.voidwhitelist.command.Command;
import voidpointer.spigot.voidwhitelist.command.arg.Args;
import voidpointer.spigot.voidwhitelist.config.WhitelistConfig;
import voidpointer.spigot.voidwhitelist.date.Duration;

import static voidpointer.spigot.voidwhitelist.message.WhitelistMessage.*;

final class GetDurationCommand extends Command {
@AutowiredLocale private static Locale locale;
@Autowired private static WhitelistConfig whitelistConfig;

GetDurationCommand() {
super("get-duration");
}

@Override public void execute(final Args args) {
final String rawDuration = whitelistConfig.getRawAutoDuration();
locale.localize(AUTO_WHITELIST_GET_DURATION)
.set("duration", rawDuration).set("exact", Duration.exactMillis(rawDuration).orElse(-1L))
.send(args.getSender());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package voidpointer.spigot.voidwhitelist.command.autowhitelist;

import voidpointer.spigot.framework.di.Autowired;
import voidpointer.spigot.framework.localemodule.Locale;
import voidpointer.spigot.framework.localemodule.annotation.AutowiredLocale;
import voidpointer.spigot.voidwhitelist.command.Command;
import voidpointer.spigot.voidwhitelist.command.arg.Args;
import voidpointer.spigot.voidwhitelist.config.WhitelistConfig;

import static voidpointer.spigot.voidwhitelist.message.WhitelistMessage.*;

final class GetLimitCommand extends Command {
@AutowiredLocale private static Locale locale;
@Autowired private static WhitelistConfig whitelistConfig;

GetLimitCommand() {
super("get-limit");
}

@Override public void execute(final Args args) {
locale.localize(AUTO_WHITELIST_GET_LIMIT).set("limit", whitelistConfig.getAutoLimit()).send(args.getSender());
}
}
Loading