Skip to content

Commit

Permalink
Merge pull request #8 from NightMirror21/develop
Browse files Browse the repository at this point in the history
6.0
  • Loading branch information
NightMirror21 authored Jun 28, 2023
2 parents 2d975c8 + fd00e4d commit 7c796f7
Show file tree
Hide file tree
Showing 72 changed files with 2,956 additions and 1,542 deletions.
5 changes: 3 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
.idea/
target/
.idea
.gradle
build/
220 changes: 34 additions & 186 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,193 +1,41 @@
# WhitelistByTime

## Features
- Working at 1.12.2 - 1.19.4
- Full customization
- HEX support
- API
- Placeholders (Can be turned off)
- Memorizing players by nickname case-sensitive or not (Customized)
- Storing data in any database type
- Executing the /whitelist command both in the console and in the game
- Convenience of specifying the time and checking how much is left

## Commands and Permissions
**/whitelist on/off** - *whitelistbytime.turn*\
**/whitelist add [nickname] (time)** - *whitelistbytime.add*\
**/whitelist remove [nickname]** - *whitelistbytime.remove*\
**/whitelist check [nickname]** - *whitelistbytime.check*\
**/whitelist checkme** - *whitelistbytime.checkme*\
**/whitelist time set/add/remove [nickname] [time]** - *whitelistbytime.time*\
**/whitelist reload** - *whitelistbytime.reload*\
**/whitelist getall** - *whitelistbytime.getall*
- (time) - time for which the player will be added to the whitelist\
Example: 2d 3h 10m\
Leave this value empty if you want to add player forever

## Placeholders:
All output can be configured in the config\
\
**%wlbytime_in_whitelist%** - *In whitelist or not*\
**%wlbytime_time_left%** - *How much is left in whitelist*
This plugin allows you to add players for a certain time or permanently.

## Statistics
Statistics are obtained through bstats metrics.
![BStats](https://bstats.org/signatures/bukkit/WhitelistByTime.svg)

## API

For usage API download .jar and add it to your project.

**Events:**\
PlayerAddedToWhitelistEvent\
PlayerRemovedFromWhitelist

### Example API usage:
```java
public class Command implements CommandExecutor {

private final IAPI api = WhitelistByTime.getAPI();

@Override
public boolean onCommand(CommandSender commandSender, Command command, String s, String[] strings) {
for (String nickname : WhitelistByTimeAPI.getAllPlayers()) {
api.removePlayer(nickname);
}

commandSender.sendMessage("Success!");
return true;
}
}
```

### Example PlayerAddedToWhitelistEvent usage:

```java
public class EventListener implements Listener {

private final Logger log = Logger.getLogger("MySuperPlugin");

@EventHandler
public void onPlayerRemoved(PlayerRemovedFromWhitelistEvent event) {
if (event.getNickname().equals("Notch")) {
log.warning("Someone tried to remove Notch from whitelist!");

event.setCancelled(true);
}
}
}
```

## Config
```yaml
####### SETTINGS #######

# Is whitelist enabled by default on startup
enabled: true
# Checks the player in the whitelist
checker-thread: true
# The delay through which the thread will check players. In seconds
checker-delay: 1
# Check the case of the nickname
case-sensitive: true


####### DATABASE #######

type: 'sqlite'

# If not sqlite or h2
address: 'localhost:3030'
name: 'minecraft'
table: 'whitelist'

# If using user and password
use-user-and-password: false
user: 'user'
password: 'qwerty123'

####### PLACEHOLDERS HOOK #######

placeholders-enabled: true

# %wlbytime_in_whitelist% - In whitelist or not
in-whitelist-true: '&a✔'
in-whitelist-false: '&c✖'

# %wlbytime_time_left% - How much is left in whitelist
time-left: '&a%time%'

# Show less information (without hours, minutes, seconds) when time left more than one day
less-info-time-left: false
less-info-expires-today: 'Expires in'

####### MESSAGES #######

minecraft-commands:
plugin-reloaded: '&6Plugin reloaded!'
not-permission: '&cYou do not have permission!'

whitelist-enabled: '&aWhitelistByTime enabled'
whitelist-already-enabled: '&aWhitelistByTime already enabled'
whitelist-disabled: '&aWhitelistByTime disabled'
whitelist-already-disabled: '&aWhitelistByTime already disabled'

you-not-in-whitelist-kick:
- '#d2d301Sorry, but you are not in whitelist'
- 'Bye!'

player-removed-from-whitelist: '&e%player% &fsuccessfully removed from whitelist'
player-already-in-whitelist: '&e%player% &falready in whitelist'
player-not-in-whitelist: '&e%player% &fnot in whitelist'

# For command with time
successfully-added-for-time: '&a%player% &fadded to whitelist for &a%time%'
still-in-whitelist-for-time: '&a%player% &fwill be in whitelist still &a%time%'
checkme-still-in-whitelist-for-time: '&fYou will remain on the whitelist for &a%time%'

# For command without time
successfully-added: '&a%player% &fadded to whitelist forever'
still-in-whitelist: '&a%player% &fwill be in whitelist forever'
checkme-still-in-whitelist: '&fYou are permanently whitelisted'

list-title: '&a> Whitelist:'
list-player: '&a| &f%player% &7[%time%]'
list-empty: '&aWhitelist is empty'

set-time: 'Now &a%player% &fwill be in whitelist for &a%time%'
add-time: 'Added &a%time% &fto &a%player%'
remove-time: 'Removed &a%time% &ffrom &a%player%'

forever: 'forever'

help:
- '&a> WhitelistByTime - Help'
- '&a| &f/whitelist on/off'
- '&a| &f/whitelist add [nickname] (time)'
- '&a| &f/whitelist remove [nickname]'
- '&a| &f/whitelist check [nickname]'
- '&a| &f/whitelist checkme'
- '&a| &f/whitelist reload'
- '&a| &f/whitelist getall'
- '&a| &f/whitelist time set/add/remove [nickname] [time]'
- '&a| &f(time) - time for which the player will be added to the whitelist'
- '&a| &fExample: 2d 3h 10m'
- '&a| &fLeave this value empty if you want to add player forever'


## Commands and Permissions
| Command | Permission |
|--------------------------------------------------|-------------------------|
| /whitelist on/off | whitelistbytime.turn |
| /whitelist add [nickname] (time) | whitelistbytime.turn |
| /whitelist remove [nickname] | whitelistbytime.remove |
| /whitelist check [nickname] | whitelistbytime.check |
| /whitelist checkme | whitelistbytime.checkme |
| /whitelist time set/add/remove [nickname] [time] | whitelistbytime.time |
| /whitelist reload | whitelistbytime.reload |
| /whitelist getall | whitelistbytime.getall |

Note:
- [nickname] - this argument is required.
- (time) - The duration for which the player will be added to the whitelist.\
Example: 2d 3h 10m.\
Leave this value empty if you want to add the player permanently.

time-units:
year:
- 'y'
month:
- 'mo'
week:
- 'w'
day:
- 'd'
hour:
- 'h'
minute:
- 'm'
second:
- 's'
```
## Placeholders:
All output can be configured in the config.

*%wlbytime_in_whitelist%* - In whitelist or not.\
*%wlbytime_time_left%* - How much is left in whitelist.

## FAQ
1. *Why does the plugin weigh so much?*\
Because it contains libraries such as omrlite (database), caffein (cache), bstats (metrics).
2. *I have a problem/idea where should I write?*\
Create an issue in this repository and describe it in detail. I would be happy to get any feedback!
3. *Will there be bungee\velocity support?*\
Yes, it will, as soon as I learn how to use their api.
4. *What is the difference in the whitelistbytime between paper and spigot?*\
The difference lies in the formatting of the messages. In Spigot, strings are used, whereas in Paper, components are utilized. To create colored messages in Spigot, you can use the '&' sign or hex codes (e.g., #ffffffff). However, in Paper, only MiniMessage formatting is supported.
15 changes: 15 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
plugins {
id 'java'
}

def javaVersion = JavaVersion.VERSION_16;
sourceCompatibility = javaVersion;
targetCompatibility = javaVersion;

group = 'ru.nightmirror'
version = '1.0'
description = 'WhitelistByTime'

repositories {
mavenLocal()
}
28 changes: 28 additions & 0 deletions core/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
plugins {
id 'java'
id 'com.github.johnrengelman.shadow' version '7.1.2'
}

def javaVersion = JavaVersion.VERSION_16;
sourceCompatibility = javaVersion;
targetCompatibility = javaVersion;

group 'ru.nightmirror'
version '1.0'

repositories {
mavenCentral()

maven {
url = uri('https://repo.maven.apache.org/maven2/')
}
}

dependencies {
implementation 'com.github.ben-manes.caffeine:caffeine:3.1.6'
implementation 'com.j256.ormlite:ormlite-core:6.1'
implementation 'com.j256.ormlite:ormlite-jdbc:6.1'
compileOnly 'org.jetbrains:annotations:24.0.1'
compileOnly 'org.projectlombok:lombok:1.18.26'
annotationProcessor 'org.projectlombok:lombok:1.18.26'
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package ru.nightmirror.wlbytime.common.checker;

import lombok.AccessLevel;
import lombok.RequiredArgsConstructor;
import lombok.experimental.FieldDefaults;
import ru.nightmirror.wlbytime.common.database.misc.WLPlayer;
import ru.nightmirror.wlbytime.interfaces.checker.Checker;
import ru.nightmirror.wlbytime.interfaces.database.PlayerAccessor;
import ru.nightmirror.wlbytime.interfaces.misc.PlayersOnSeverAccessor;

import java.time.Duration;
import java.util.List;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;

@FieldDefaults(level = AccessLevel.PRIVATE, makeFinal = true)
@RequiredArgsConstructor
public class PlayersChecker implements Checker, Runnable {

PlayerAccessor playerAccessor;
PlayersOnSeverAccessor playersOnSeverAccessor;
Duration delay;
ScheduledExecutorService executor = Executors.newSingleThreadScheduledExecutor();

@Override
public void start() {
executor.scheduleAtFixedRate(this, delay.toMillis(), delay.toMillis(), TimeUnit.MILLISECONDS);
}

@Override
public void run() {
playerAccessor.getPlayers().thenAccept((players) -> {
long currentMilliseconds = System.currentTimeMillis();
List<WLPlayer> toRemove = players.stream().filter(player -> player.getUntil() != -1L && player.getUntil() <= currentMilliseconds).toList();
playerAccessor.delete(toRemove).join();
}).thenRun(() -> {
playersOnSeverAccessor.getPlayersOnServer().forEach(nickname -> {
playerAccessor.getPlayer(nickname).thenAccept(playerOptional -> {
if (playerOptional.isEmpty()) playersOnSeverAccessor.kickPlayer(nickname);
});
});
});
}

@Override
public void stop() {
executor.shutdown();
}
}
Loading

0 comments on commit 7c796f7

Please sign in to comment.