mirror of
https://github.com/plexusorg/Plex.git
synced 2025-07-04 16:56:40 +00:00
Compare commits
97 Commits
Author | SHA1 | Date | |
---|---|---|---|
2cde4a430c | |||
c3a426d6db | |||
e662491198 | |||
ec7e370a01 | |||
ef957467ce | |||
1a94c3e39f | |||
b1fcf5e348 | |||
7c27c03d98 | |||
cbf4004169 | |||
57eab45b43 | |||
4eeaf051ad | |||
285514b04a | |||
a00c6926c4 | |||
bae1e49c5e | |||
730f7c5ea0 | |||
67a382695a | |||
9600f2d5d9 | |||
81200f73d1 | |||
ee18ae324d | |||
7d2a25668a | |||
98c487c639 | |||
953f1813d3 | |||
df02ad6771 | |||
299aeae38e | |||
f622e6c295 | |||
5f93b7e1e5 | |||
b41015bfd8 | |||
14cd376f7e | |||
ce3758730f | |||
eb788f02dd | |||
096bb1bb24 | |||
223eaf30b3 | |||
6763878d74 | |||
81c656c86e | |||
6c09905a8d | |||
f0c646688e | |||
336f17b1cf | |||
583f502cee | |||
c071195aaf | |||
f62b084bbc | |||
c92a4bbdb9 | |||
9b0b7537c2 | |||
f8d25491d5 | |||
1dc0e05715 | |||
ffe8993ee1 | |||
90ef0a2121 | |||
7457e9e454 | |||
dc65187381 | |||
b449d732b0 | |||
8dfaaf7a8c | |||
6b7bfacbfd | |||
16186bdfbb | |||
4bbb73d1ff | |||
aa9f306586 | |||
08a004d65f | |||
d798904394 | |||
f78edc55d4 | |||
8866f44aa2 | |||
0fc2aa68b0 | |||
391677596a | |||
5988eba06b | |||
81d3cc8dde | |||
7b13ca0248 | |||
06fcf531af | |||
9f7ac310d9 | |||
09bc47f3fb | |||
8544775be2 | |||
c8c8fc9c59 | |||
14095fdebb | |||
dcecebdc8d | |||
f73c63f1e7 | |||
067094130f | |||
d16aa6de4c | |||
6086f761eb | |||
b2f1f7e055 | |||
3c20213c0d | |||
3500cae2da | |||
c4be024619 | |||
9849003ecc | |||
f274e20f84 | |||
f180eec44a | |||
b1ef89dae9 | |||
de20747d45 | |||
c801feed6f | |||
5fdc5826b7 | |||
a87a9241af | |||
8fb64b8499 | |||
10dd546c09 | |||
5a352b2ca0 | |||
333f38fb64 | |||
d55eaf0d3d | |||
e35d70bc3c | |||
e421867f63 | |||
ec7d814467 | |||
9c5a557316 | |||
38e79fd917 | |||
10e63f5e86 |
77
.github/workflows/codeql-analysis.yml
vendored
Normal file
77
.github/workflows/codeql-analysis.yml
vendored
Normal file
@ -0,0 +1,77 @@
|
||||
# For most projects, this workflow file will not need changing; you simply need
|
||||
# to commit it to your repository.
|
||||
#
|
||||
# You may wish to alter this file to override the set of languages analyzed,
|
||||
# or to provide custom queries or build logic.
|
||||
#
|
||||
# ******** NOTE ********
|
||||
# We have attempted to detect the languages in your repository. Please check
|
||||
# the `language` matrix defined below to confirm you have the correct set of
|
||||
# supported CodeQL languages.
|
||||
#
|
||||
name: "CodeQL"
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [ master, server ]
|
||||
pull_request:
|
||||
# The branches below must be a subset of the branches above
|
||||
branches: [ master ]
|
||||
schedule:
|
||||
- cron: '29 4 * * *'
|
||||
|
||||
jobs:
|
||||
analyze:
|
||||
name: Analyze
|
||||
runs-on: ubuntu-latest
|
||||
permissions:
|
||||
actions: read
|
||||
contents: read
|
||||
security-events: write
|
||||
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
language: [ 'java' ]
|
||||
# CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python', 'ruby' ]
|
||||
# Learn more about CodeQL language support at https://git.io/codeql-language-support
|
||||
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v3
|
||||
|
||||
- name: Set up JDK 17
|
||||
uses: actions/setup-java@v2
|
||||
with:
|
||||
distribution: temurin
|
||||
java-version: 17
|
||||
cache: gradle
|
||||
|
||||
# Initializes the CodeQL tools for scanning.
|
||||
- name: Initialize CodeQL
|
||||
uses: github/codeql-action/init@v2
|
||||
with:
|
||||
languages: ${{ matrix.language }}
|
||||
# If you wish to specify custom queries, you can do so here or in a config file.
|
||||
# By default, queries listed here will override any specified in a config file.
|
||||
# Prefix the list here with "+" to use these queries and those in the config file.
|
||||
# queries: ./path/to/local/query, your-org/your-repo/queries@main
|
||||
|
||||
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
|
||||
# If this step fails, then you should remove it and run the build manually (see below)
|
||||
- name: Autobuild
|
||||
uses: github/codeql-action/autobuild@v2
|
||||
|
||||
# ℹ️ Command-line programs to run using the OS shell.
|
||||
# 📚 https://git.io/JvXDl
|
||||
|
||||
# ✏️ If the Autobuild fails above, remove it and uncomment the following three lines
|
||||
# and modify them (or add more) to build your code if your project
|
||||
# uses a compiled language
|
||||
|
||||
- run: |
|
||||
chmod +x gradlew
|
||||
./gradlew build --no-daemon
|
||||
|
||||
- name: Perform CodeQL Analysis
|
||||
uses: github/codeql-action/analyze@v2
|
3
.gitignore
vendored
3
.gitignore
vendored
@ -1,8 +1,7 @@
|
||||
/.idea/
|
||||
/.idea/codeStyles/codeStyleConfig.xml
|
||||
*.iml
|
||||
/target/
|
||||
/src/main/resources/build.properties
|
||||
src/main/resources/build.properties
|
||||
|
||||
# OS
|
||||
.DS_Store
|
||||
|
23
CONTRIBUTING.md
Normal file
23
CONTRIBUTING.md
Normal file
@ -0,0 +1,23 @@
|
||||
For those who are wanting to contribute, we fully encourage doing so. There are a few rules we require following when contributing however.
|
||||
|
||||
## Steps
|
||||
1. Make an isuse and get feedback. It's important to know if your idea will be accepted before writing any code.
|
||||
- If it is a feature request, describe the feature and be extremely specific.
|
||||
- If it is a bug report, ensure you include how to reproduce the bug and the expected outcome
|
||||
- If it is an enhancement, describe your proposed changes. Ensure you are extremely specific.
|
||||
2. Fork Plex
|
||||
3. Create a new branch that describes the new feature, enhancement, or bug fix. For example, this is good: `feature/add-xyz`. This is bad: `fix-this-lol`.
|
||||
4. Write the code that addresses your change.
|
||||
- Keep in mind that it **must** be formatted correctly. If you are using IntelliJ, there is a `codeStyle.xml` file that tells IntelliJ how to format your code. Check this link for information on how to use the file: https://www.jetbrains.com/help/idea/configuring-code-style.html#import-export-schemes
|
||||
5. Push your changes to your new branch and make a PR based off of that branch.
|
||||
|
||||
## Requirements for a PR
|
||||
- The issue must be marked as approved
|
||||
- It must only address each specific issue. Don't make one PR for multiple issues.
|
||||
- Your PR must compile and work. If it does not compile or work, your PR will most likely be rejected.
|
||||
|
||||
## Code requirements
|
||||
- Most importantly, your code must be efficient. Your pull request may be rejected if your code is deemed inefficient or sloppy.
|
||||
- Do not repeat yourself. Create functions as needed if you're using large blocks of code over and over again.
|
||||
- Do not use an excessive amount of commits when making your PR. It makes the master branch look messy.
|
||||
- Your code must be consistent with Plex's codebase. If a function already exists, use it.
|
@ -1,3 +1,8 @@
|
||||
# Plex
|
||||
# Plex [](https://ci.plex.us.org/job/Plex/job/master/)
|
||||
|
||||
A new freedom plugin.
|
||||
Plex is a new freedom plugin. It is an alternative to TotalFreedomMod. It has many of the features that make a freedom
|
||||
server unique, but also many features that TotalFreedomMod doesn’t have. For example, there is full support for using a
|
||||
permissions plugin instead of ranks. It is also much more performance oriented. You can use Redis to store indefinite
|
||||
bans and store player data in MongoDB, MariaDB, or SQLite. Plex is also fully customizable as you can change almost all
|
||||
of the messages within the plugin. Plex also has a module system which can be used to add additional functionality. Plex
|
||||
is not a rewrite, "debloat", or related to TotalFreedomMod. Plex is an entirely new experience.
|
||||
|
40
build.gradle
40
build.gradle
@ -1,7 +1,7 @@
|
||||
plugins {
|
||||
id "java"
|
||||
id "maven-publish"
|
||||
id "net.minecrell.plugin-yml.bukkit" version "0.5.1"
|
||||
id "net.minecrell.plugin-yml.bukkit" version "0.6.1-SNAPSHOT"
|
||||
id "com.github.johnrengelman.shadow" version "7.1.2"
|
||||
}
|
||||
|
||||
@ -19,6 +19,13 @@ repositories {
|
||||
url = uri("https://repo.maven.apache.org/maven2/")
|
||||
}
|
||||
|
||||
maven {
|
||||
url = uri("https://jitpack.io")
|
||||
content {
|
||||
includeGroup("com.github.MilkBowl")
|
||||
}
|
||||
}
|
||||
|
||||
mavenCentral()
|
||||
}
|
||||
|
||||
@ -43,12 +50,15 @@ dependencies {
|
||||
library "org.eclipse.jetty:jetty-proxy:11.0.9"
|
||||
library "com.google.code.gson:gson:2.9.0"
|
||||
compileOnly "io.papermc.paper:paper-api:1.18.2-R0.1-SNAPSHOT"
|
||||
compileOnly("com.github.MilkBowl:VaultAPI:1.7") {
|
||||
exclude group: "org.bukkit", module: "bukkit"
|
||||
}
|
||||
implementation "org.bstats:bstats-base:3.0.0"
|
||||
implementation "org.bstats:bstats-bukkit:3.0.0"
|
||||
}
|
||||
|
||||
group = "dev.plex"
|
||||
version = "1.0"
|
||||
version = "1.0.3"
|
||||
description = "Plex"
|
||||
|
||||
shadowJar {
|
||||
@ -62,7 +72,8 @@ bukkit {
|
||||
description = "Plex provides a new experience for freedom servers."
|
||||
main = "dev.plex.Plex"
|
||||
website = "https://plex.us.org"
|
||||
authors = ["Telesphoreo", "taahanis", "super"]
|
||||
authors = ["Telesphoreo", "taahanis", "supernt"]
|
||||
softDepend = ["Vault"]
|
||||
apiVersion = "1.18"
|
||||
}
|
||||
|
||||
@ -95,7 +106,7 @@ String getBuildNumber() {
|
||||
}
|
||||
|
||||
static def getDate() {
|
||||
return new Date().format("MM/dd/yyyy '<light_purple>at<gold>' hh:mm:ss a")
|
||||
return new Date().format("MM/dd/yyyy '<light_purple>at<gold>' hh:mm:ss a z")
|
||||
}
|
||||
|
||||
task buildProperties {
|
||||
@ -114,7 +125,26 @@ java {
|
||||
publishing {
|
||||
publications {
|
||||
maven(MavenPublication) {
|
||||
from(components.java)
|
||||
pom.withXml {
|
||||
def dependenciesNode = asNode().appendNode("dependencies")
|
||||
configurations.getByName("library").getAllDependencies().each { dependency ->
|
||||
dependenciesNode.appendNode("dependency").with {
|
||||
it.appendNode("groupId", dependency.group)
|
||||
it.appendNode("artifactId", dependency.name)
|
||||
it.appendNode("version", dependency.version)
|
||||
it.appendNode("scope", "provided")
|
||||
}
|
||||
}
|
||||
configurations.getByName("implementation").getAllDependencies().each { dependency ->
|
||||
dependenciesNode.appendNode("dependency").with {
|
||||
it.appendNode("groupId", dependency.group)
|
||||
it.appendNode("artifactId", dependency.name)
|
||||
it.appendNode("version", dependency.version)
|
||||
it.appendNode("scope", "runtime")
|
||||
}
|
||||
}
|
||||
}
|
||||
artifacts = [shadowJar]
|
||||
}
|
||||
}
|
||||
repositories {
|
||||
|
2
gradle/wrapper/gradle-wrapper.properties
vendored
2
gradle/wrapper/gradle-wrapper.properties
vendored
@ -1,5 +1,5 @@
|
||||
distributionBase=GRADLE_USER_HOME
|
||||
distributionPath=wrapper/dists
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-7.3.3-bin.zip
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-7.4.2-bin.zip
|
||||
zipStoreBase=GRADLE_USER_HOME
|
||||
zipStorePath=wrapper/dists
|
||||
|
@ -1 +1,7 @@
|
||||
rootProject.name = 'Plex'
|
||||
pluginManagement {
|
||||
repositories {
|
||||
maven { url = uri("https://nexus.telesphoreo.me/repository/gradle-plugins/") }
|
||||
gradlePluginPortal()
|
||||
}
|
||||
}
|
||||
rootProject.name = "Plex"
|
||||
|
@ -3,12 +3,7 @@ package dev.plex;
|
||||
import dev.plex.admin.Admin;
|
||||
import dev.plex.admin.AdminList;
|
||||
import dev.plex.cache.DataUtils;
|
||||
import dev.plex.cache.player.MongoPlayerData;
|
||||
import dev.plex.cache.player.PlayerCache;
|
||||
import dev.plex.cache.player.SQLPlayerData;
|
||||
import dev.plex.cache.sql.SQLNotes;
|
||||
import dev.plex.cache.sql.SQLPunishment;
|
||||
import dev.plex.command.blocker.CommandBlockerManager;
|
||||
import dev.plex.cache.PlayerCache;
|
||||
import dev.plex.config.Config;
|
||||
import dev.plex.handlers.CommandHandler;
|
||||
import dev.plex.handlers.ListenerHandler;
|
||||
@ -21,35 +16,41 @@ import dev.plex.storage.MongoConnection;
|
||||
import dev.plex.storage.RedisConnection;
|
||||
import dev.plex.storage.SQLConnection;
|
||||
import dev.plex.storage.StorageType;
|
||||
import dev.plex.storage.permission.SQLPermissions;
|
||||
import dev.plex.storage.player.MongoPlayerData;
|
||||
import dev.plex.storage.player.SQLPlayerData;
|
||||
import dev.plex.storage.punishment.SQLNotes;
|
||||
import dev.plex.storage.punishment.SQLPunishment;
|
||||
import dev.plex.util.BuildInfo;
|
||||
import dev.plex.util.PlexLog;
|
||||
import dev.plex.util.PlexUtils;
|
||||
import dev.plex.util.UpdateChecker;
|
||||
import dev.plex.world.CustomWorld;
|
||||
import java.io.File;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import net.milkbowl.vault.permission.Permission;
|
||||
import org.bstats.bukkit.Metrics;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.plugin.RegisteredServiceProvider;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.InputStream;
|
||||
import java.util.Properties;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
public class Plex extends JavaPlugin
|
||||
{
|
||||
public static final BuildProperties build = new BuildProperties();
|
||||
private static Plex plugin;
|
||||
|
||||
public Config config;
|
||||
public Config messages;
|
||||
public Config indefBans;
|
||||
public Config blockedCommands;
|
||||
public Config commands;
|
||||
|
||||
public File modulesFolder;
|
||||
private StorageType storageType = StorageType.SQLITE;
|
||||
|
||||
public static final BuildInfo build = new BuildInfo();
|
||||
|
||||
private SQLConnection sqlConnection;
|
||||
private MongoConnection mongoConnection;
|
||||
private RedisConnection redisConnection;
|
||||
@ -59,17 +60,19 @@ public class Plex extends JavaPlugin
|
||||
|
||||
private SQLPunishment sqlPunishment;
|
||||
private SQLNotes sqlNotes;
|
||||
private SQLPermissions sqlPermissions;
|
||||
|
||||
private ModuleManager moduleManager;
|
||||
private RankManager rankManager;
|
||||
private ServiceManager serviceManager;
|
||||
private PunishmentManager punishmentManager;
|
||||
private CommandBlockerManager commandBlockerManager;
|
||||
|
||||
private AdminList adminList;
|
||||
private UpdateChecker updateChecker;
|
||||
private String system;
|
||||
|
||||
private Permission permissions;
|
||||
|
||||
public static Plex get()
|
||||
{
|
||||
return plugin;
|
||||
@ -82,7 +85,7 @@ public class Plex extends JavaPlugin
|
||||
config = new Config(this, "config.yml");
|
||||
messages = new Config(this, "messages.yml");
|
||||
indefBans = new Config(this, "indefbans.yml");
|
||||
blockedCommands = new Config(this, "commands.yml");
|
||||
commands = new Config(this, "commands.yml");
|
||||
build.load(this);
|
||||
|
||||
modulesFolder = new File(this.getDataFolder() + File.separator + "modules");
|
||||
@ -103,7 +106,7 @@ public class Plex extends JavaPlugin
|
||||
messages.load();
|
||||
// Don't add default entries to indefinite ban file
|
||||
indefBans.load(false);
|
||||
blockedCommands.load();
|
||||
commands.load(false);
|
||||
|
||||
sqlConnection = new SQLConnection();
|
||||
mongoConnection = new MongoConnection();
|
||||
@ -118,12 +121,18 @@ public class Plex extends JavaPlugin
|
||||
{
|
||||
PlexUtils.testConnections();
|
||||
PlexLog.log("Connected to " + storageType.name().toUpperCase());
|
||||
} catch (Exception e)
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
PlexLog.error("Failed to connect to " + storageType.name().toUpperCase());
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
if (!setupPermissions() && system.equalsIgnoreCase("permissions") && !getServer().getPluginManager().isPluginEnabled("Vault"))
|
||||
{
|
||||
throw new RuntimeException("Vault is required to run on the server if you use permissions!");
|
||||
}
|
||||
|
||||
updateChecker = new UpdateChecker();
|
||||
PlexLog.log("Update checking enabled");
|
||||
|
||||
@ -135,7 +144,8 @@ public class Plex extends JavaPlugin
|
||||
{
|
||||
redisConnection.getJedis();
|
||||
PlexLog.log("Connected to Redis!");
|
||||
} else
|
||||
}
|
||||
else
|
||||
{
|
||||
PlexLog.log("Redis is disabled in the configuration file, not connecting.");
|
||||
}
|
||||
@ -143,11 +153,13 @@ public class Plex extends JavaPlugin
|
||||
if (storageType == StorageType.MONGODB)
|
||||
{
|
||||
mongoPlayerData = new MongoPlayerData();
|
||||
} else
|
||||
}
|
||||
else
|
||||
{
|
||||
sqlPlayerData = new SQLPlayerData();
|
||||
sqlPunishment = new SQLPunishment();
|
||||
sqlNotes = new SQLNotes();
|
||||
sqlPermissions = new SQLPermissions();
|
||||
}
|
||||
|
||||
new ListenerHandler();
|
||||
@ -163,9 +175,6 @@ public class Plex extends JavaPlugin
|
||||
punishmentManager.mergeIndefiniteBans();
|
||||
PlexLog.log("Punishment System initialized");
|
||||
|
||||
commandBlockerManager = new CommandBlockerManager();
|
||||
PlexLog.log("Command Blocker initialized");
|
||||
|
||||
generateWorlds();
|
||||
|
||||
serviceManager = new ServiceManager();
|
||||
@ -191,7 +200,8 @@ public class Plex extends JavaPlugin
|
||||
if (mongoPlayerData != null) //back to mongo checking
|
||||
{
|
||||
mongoPlayerData.update(plexPlayer); //update the player's document
|
||||
} else if (sqlPlayerData != null) //sql checking
|
||||
}
|
||||
else if (sqlPlayerData != null) //sql checking
|
||||
{
|
||||
sqlPlayerData.update(plexPlayer);
|
||||
}
|
||||
@ -231,33 +241,10 @@ public class Plex extends JavaPlugin
|
||||
});
|
||||
}
|
||||
|
||||
public static class BuildProperties
|
||||
public boolean setupPermissions()
|
||||
{
|
||||
public String number;
|
||||
public String author;
|
||||
public String date;
|
||||
public String head;
|
||||
|
||||
public void load(Plex plugin)
|
||||
{
|
||||
try
|
||||
{
|
||||
final Properties props;
|
||||
|
||||
try (InputStream in = plugin.getResource("build.properties"))
|
||||
{
|
||||
props = new Properties();
|
||||
props.load(in);
|
||||
}
|
||||
|
||||
number = props.getProperty("buildNumber", "unknown");
|
||||
author = props.getProperty("buildAuthor", "unknown");
|
||||
date = props.getProperty("buildDate", "unknown");
|
||||
head = props.getProperty("buildHead", "unknown");
|
||||
} catch (Exception ex)
|
||||
{
|
||||
PlexLog.error("Could not load build properties! Did you compile with NetBeans/Maven?");
|
||||
}
|
||||
}
|
||||
RegisteredServiceProvider<Permission> rsp = Bukkit.getServicesManager().getRegistration(Permission.class);
|
||||
permissions = rsp.getProvider();
|
||||
return permissions != null;
|
||||
}
|
||||
}
|
@ -1,6 +1,6 @@
|
||||
package dev.plex;
|
||||
|
||||
public class PlexBase
|
||||
public interface PlexBase
|
||||
{
|
||||
protected final static Plex plugin = Plex.get();
|
||||
Plex plugin = Plex.get();
|
||||
}
|
||||
|
@ -25,7 +25,7 @@ import java.util.stream.Collectors;
|
||||
* @see Admin
|
||||
*/
|
||||
|
||||
public class AdminList extends PlexBase
|
||||
public class AdminList implements PlexBase
|
||||
{
|
||||
/**
|
||||
* Key / Value storage, where the key is the unique ID of the admin
|
||||
@ -54,7 +54,7 @@ public class AdminList extends PlexBase
|
||||
}
|
||||
|
||||
/**
|
||||
* Gathers every admin's username (cached and in the database)
|
||||
* Gathers every admins username (cached and in the database)
|
||||
*
|
||||
* @return An array list of the names of every admin
|
||||
*/
|
||||
|
14
src/main/java/dev/plex/cache/DataUtils.java
vendored
14
src/main/java/dev/plex/cache/DataUtils.java
vendored
@ -1,11 +1,9 @@
|
||||
package dev.plex.cache;
|
||||
|
||||
import dev.plex.Plex;
|
||||
import dev.plex.cache.player.PlayerCache;
|
||||
import dev.plex.player.PlexPlayer;
|
||||
import dev.plex.storage.StorageType;
|
||||
import java.util.UUID;
|
||||
import org.bukkit.Bukkit;
|
||||
|
||||
/**
|
||||
* Parent cache class
|
||||
@ -30,6 +28,18 @@ public class DataUtils
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean hasPlayedBefore(String username)
|
||||
{
|
||||
if (Plex.get().getStorageType() == StorageType.MONGODB)
|
||||
{
|
||||
return Plex.get().getMongoPlayerData().exists(username);
|
||||
}
|
||||
else
|
||||
{
|
||||
return Plex.get().getSqlPlayerData().exists(username);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a player from cache or from the database
|
||||
*
|
||||
|
@ -1,4 +1,4 @@
|
||||
package dev.plex.cache.player;
|
||||
package dev.plex.cache;
|
||||
|
||||
import com.google.common.collect.Maps;
|
||||
import dev.plex.player.PlexPlayer;
|
@ -1,44 +0,0 @@
|
||||
package dev.plex.cache.notes;
|
||||
|
||||
import com.google.common.reflect.TypeToken;
|
||||
import com.google.gson.Gson;
|
||||
import dev.plex.Plex;
|
||||
import dev.plex.cache.player.PlayerCache;
|
||||
import dev.plex.player.PlexPlayer;
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
public class PlayerNotes
|
||||
{
|
||||
private final String SELECT = "SELECT * FROM `notes` WHERE uuid=?";
|
||||
//private final String UPDATE = "UPDATE `notes` SET name=?, written_by=?, note=? WHERE uuid=?";
|
||||
private final String INSERT = "INSERT INTO `notes` (`uuid`, `name`, `written_by`, `note`) VALUES (?, ?, ?, ?);";
|
||||
|
||||
public PlexPlayer getByUUID(UUID uuid)
|
||||
{
|
||||
try (Connection con = Plex.get().getSqlConnection().getCon())
|
||||
{
|
||||
PreparedStatement statement = con.prepareStatement(SELECT);
|
||||
statement.setString(1, uuid.toString());
|
||||
ResultSet set = statement.executeQuery();
|
||||
PlexPlayer plexPlayer = new PlexPlayer(uuid);
|
||||
while (set.next())
|
||||
{
|
||||
String name = set.getString("name");
|
||||
String writtenBy = set.getString("written_by");
|
||||
String note = set.getString("note");
|
||||
|
||||
}
|
||||
return plexPlayer;
|
||||
}
|
||||
catch (SQLException throwables)
|
||||
{
|
||||
throwables.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
@ -2,31 +2,37 @@ package dev.plex.command;
|
||||
|
||||
import dev.plex.Plex;
|
||||
import dev.plex.cache.DataUtils;
|
||||
import dev.plex.cache.player.PlayerCache;
|
||||
import dev.plex.cache.PlayerCache;
|
||||
import dev.plex.command.annotation.CommandParameters;
|
||||
import dev.plex.command.annotation.CommandPermissions;
|
||||
import dev.plex.command.exception.*;
|
||||
import dev.plex.command.exception.CommandFailException;
|
||||
import dev.plex.command.exception.ConsoleMustDefinePlayerException;
|
||||
import dev.plex.command.exception.ConsoleOnlyException;
|
||||
import dev.plex.command.exception.PlayerNotBannedException;
|
||||
import dev.plex.command.exception.PlayerNotFoundException;
|
||||
import dev.plex.command.source.RequiredCommandSource;
|
||||
import dev.plex.player.PlexPlayer;
|
||||
import dev.plex.rank.enums.Rank;
|
||||
import dev.plex.util.PlexLog;
|
||||
import dev.plex.util.PlexUtils;
|
||||
import java.util.Arrays;
|
||||
import java.util.UUID;
|
||||
import net.kyori.adventure.audience.Audience;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.command.*;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandMap;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.command.ConsoleCommandSender;
|
||||
import org.bukkit.command.PluginIdentifiableCommand;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* Superclass for all commands
|
||||
*/
|
||||
@ -125,7 +131,8 @@ public abstract class PlexCommand extends Command implements PluginIdentifiableC
|
||||
{
|
||||
send(sender, messageComponent("noPermissionRank", ChatColor.stripColor(getLevel().getLoginMessage())));
|
||||
return true;
|
||||
} else
|
||||
}
|
||||
else
|
||||
{
|
||||
if (getLevel().isAtLeast(Rank.ADMIN) && !plexPlayer.isAdminActive())
|
||||
{
|
||||
@ -133,14 +140,52 @@ public abstract class PlexCommand extends Command implements PluginIdentifiableC
|
||||
return true;
|
||||
}
|
||||
}
|
||||
} else if (plugin.getSystem().equalsIgnoreCase("permissions"))
|
||||
}
|
||||
else if (plugin.getSystem().equalsIgnoreCase("permissions"))
|
||||
{
|
||||
if (!player.hasPermission(perms.permission()))
|
||||
{
|
||||
send(sender, messageComponent("noPermissionNode", perms.permission()));
|
||||
return true;
|
||||
}
|
||||
} else
|
||||
}
|
||||
else
|
||||
{
|
||||
PlexLog.error("Neither permissions or ranks were selected to be used in the configuration file!");
|
||||
send(sender, "There is a server misconfiguration. Please alert a developer or the owner");
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
if (sender instanceof ConsoleCommandSender && !sender.getName().equalsIgnoreCase("console")) //telnet
|
||||
{
|
||||
PlexPlayer plexPlayer = DataUtils.getPlayer(sender.getName());
|
||||
|
||||
if (plugin.getSystem().equalsIgnoreCase("ranks"))
|
||||
{
|
||||
if (!plexPlayer.getRankFromString().isAtLeast(getLevel()))
|
||||
{
|
||||
send(sender, messageComponent("noPermissionRank", ChatColor.stripColor(getLevel().getLoginMessage())));
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (getLevel().isAtLeast(Rank.ADMIN) && !plexPlayer.isAdminActive())
|
||||
{
|
||||
send(sender, messageComponent("noPermissionRank", ChatColor.stripColor(getLevel().getLoginMessage())));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (plugin.getSystem().equalsIgnoreCase("permissions"))
|
||||
{
|
||||
if (!plugin.getPermissions().playerHas(null, Bukkit.getOfflinePlayer(plexPlayer.getUuid()), perms.permission()))
|
||||
{
|
||||
send(sender, messageComponent("noPermissionNode", perms.permission()));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
PlexLog.error("Neither permissions or ranks were selected to be used in the configuration file!");
|
||||
send(sender, "There is a server misconfiguration. Please alert a developer or the owner");
|
||||
@ -149,14 +194,16 @@ public abstract class PlexCommand extends Command implements PluginIdentifiableC
|
||||
}
|
||||
try
|
||||
{
|
||||
Component component = this.execute(sender, isConsole(sender) ? null : (Player) sender, args);
|
||||
Component component = this.execute(sender, isConsole(sender) ? null : (Player)sender, args);
|
||||
if (component != null)
|
||||
{
|
||||
send(sender, component);
|
||||
}
|
||||
} catch (PlayerNotFoundException | CommandFailException | ConsoleOnlyException | ConsoleMustDefinePlayerException | PlayerNotBannedException ex)
|
||||
}
|
||||
catch (PlayerNotFoundException | CommandFailException | ConsoleOnlyException |
|
||||
ConsoleMustDefinePlayerException | PlayerNotBannedException | NumberFormatException ex)
|
||||
{
|
||||
send(sender, MiniMessage.miniMessage().deserialize(ex.getMessage()));
|
||||
send(sender, PlexUtils.mmDeserialize(ex.getMessage()));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@ -178,7 +225,8 @@ public abstract class PlexCommand extends Command implements PluginIdentifiableC
|
||||
return true;
|
||||
}
|
||||
}
|
||||
} else if (params.aliases().split(",").length < 1)
|
||||
}
|
||||
else if (params.aliases().split(",").length < 1)
|
||||
{
|
||||
return getName().equalsIgnoreCase(label);
|
||||
}
|
||||
@ -232,7 +280,29 @@ public abstract class PlexCommand extends Command implements PluginIdentifiableC
|
||||
{
|
||||
if (!isConsole(sender))
|
||||
{
|
||||
return checkRank((Player) sender, rank, permission);
|
||||
return checkRank((Player)sender, rank, permission);
|
||||
}
|
||||
if (!sender.getName().equalsIgnoreCase("console"))
|
||||
{
|
||||
PlexPlayer plexPlayer = DataUtils.getPlayer(sender.getName());
|
||||
if (plugin.getSystem().equalsIgnoreCase("ranks"))
|
||||
{
|
||||
if (!plexPlayer.getRankFromString().isAtLeast(rank))
|
||||
{
|
||||
throw new CommandFailException(PlexUtils.messageString("noPermissionRank", ChatColor.stripColor(rank.getLoginMessage())));
|
||||
}
|
||||
if (rank.isAtLeast(Rank.ADMIN) && !plexPlayer.isAdminActive())
|
||||
{
|
||||
throw new CommandFailException(PlexUtils.messageString("noPermissionRank", ChatColor.stripColor(rank.getLoginMessage())));
|
||||
}
|
||||
}
|
||||
else if (plugin.getSystem().equalsIgnoreCase("permissions"))
|
||||
{
|
||||
if (!plugin.getPermissions().playerHas(null, Bukkit.getOfflinePlayer(plexPlayer.getUuid()), permission))
|
||||
{
|
||||
throw new CommandFailException(PlexUtils.messageString("noPermissionNode", permission));
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@ -263,7 +333,8 @@ public abstract class PlexCommand extends Command implements PluginIdentifiableC
|
||||
{
|
||||
throw new CommandFailException(PlexUtils.messageString("noPermissionRank", ChatColor.stripColor(rank.getLoginMessage())));
|
||||
}
|
||||
} else if (plugin.getSystem().equalsIgnoreCase("permissions"))
|
||||
}
|
||||
else if (plugin.getSystem().equalsIgnoreCase("permissions"))
|
||||
{
|
||||
if (!player.hasPermission(permission))
|
||||
{
|
||||
@ -283,7 +354,8 @@ public abstract class PlexCommand extends Command implements PluginIdentifiableC
|
||||
if (plugin.getSystem().equalsIgnoreCase("ranks"))
|
||||
{
|
||||
return rank.isAtLeast(Rank.ADMIN) ? plexPlayer.isAdminActive() && plexPlayer.getRankFromString().isAtLeast(rank) : plexPlayer.getRankFromString().isAtLeast(rank);
|
||||
} else if (plugin.getSystem().equalsIgnoreCase("permissions"))
|
||||
}
|
||||
else if (plugin.getSystem().equalsIgnoreCase("permissions"))
|
||||
{
|
||||
return player.hasPermission(permission);
|
||||
}
|
||||
@ -303,7 +375,7 @@ public abstract class PlexCommand extends Command implements PluginIdentifiableC
|
||||
{
|
||||
if (!isConsole(sender))
|
||||
{
|
||||
return checkTab((Player) sender, rank, permission);
|
||||
return checkTab((Player)sender, rank, permission);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@ -323,7 +395,8 @@ public abstract class PlexCommand extends Command implements PluginIdentifiableC
|
||||
if (plugin.getSystem().equalsIgnoreCase("ranks"))
|
||||
{
|
||||
return rank.isAtLeast(Rank.ADMIN) ? plexPlayer.isAdminActive() && plexPlayer.getRankFromString().isAtLeast(rank) : plexPlayer.getRankFromString().isAtLeast(rank);
|
||||
} else if (plugin.getSystem().equalsIgnoreCase("permissions"))
|
||||
}
|
||||
else if (plugin.getSystem().equalsIgnoreCase("permissions"))
|
||||
{
|
||||
return player.hasPermission(permission);
|
||||
}
|
||||
@ -536,7 +609,7 @@ public abstract class PlexCommand extends Command implements PluginIdentifiableC
|
||||
*/
|
||||
protected Component mmString(String s)
|
||||
{
|
||||
return MiniMessage.miniMessage().deserialize(s);
|
||||
return PlexUtils.mmDeserialize(s);
|
||||
}
|
||||
|
||||
public Rank getLevel()
|
||||
|
@ -1,22 +0,0 @@
|
||||
package dev.plex.command.blocker;
|
||||
|
||||
import dev.plex.rank.enums.Rank;
|
||||
import lombok.Getter;
|
||||
|
||||
@Getter
|
||||
public class BaseCommand
|
||||
{
|
||||
private final Rank rank;
|
||||
private final String message;
|
||||
|
||||
public BaseCommand(Rank r, String m)
|
||||
{
|
||||
rank = r;
|
||||
message = m;
|
||||
}
|
||||
|
||||
public String toString()
|
||||
{
|
||||
return "BaseCommand (Rank: " + (rank == null ? "ALL" : rank.name()) + ", Message: " + message + ")";
|
||||
}
|
||||
}
|
@ -1,108 +0,0 @@
|
||||
package dev.plex.command.blocker;
|
||||
|
||||
import dev.plex.Plex;
|
||||
import dev.plex.PlexBase;
|
||||
import dev.plex.rank.enums.Rank;
|
||||
import dev.plex.util.PlexLog;
|
||||
import dev.plex.util.PlexUtils;
|
||||
import lombok.Getter;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.PluginCommand;
|
||||
import org.bukkit.command.PluginCommandYamlParser;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
@Getter
|
||||
public class CommandBlockerManager extends PlexBase
|
||||
{
|
||||
private List<BaseCommand> blockedCommands = new ArrayList<>();
|
||||
|
||||
public boolean loadedYet;
|
||||
|
||||
public void syncCommands()
|
||||
{
|
||||
loadedYet = false;
|
||||
blockedCommands.clear();
|
||||
|
||||
List<String> raw = plugin.blockedCommands.getStringList("blockedCommands");
|
||||
|
||||
for (String cmd : raw)
|
||||
{
|
||||
int lastDelim = cmd.lastIndexOf(':');
|
||||
|
||||
String cmdWithoutMsg = cmd.substring(0, lastDelim);
|
||||
String[] rawPieces = cmdWithoutMsg.split(":", 3);
|
||||
|
||||
String rawType = rawPieces[0].toLowerCase();
|
||||
String rawRank = rawPieces[1].toLowerCase();
|
||||
String regexOrMatch = rawPieces[2];
|
||||
String message = cmd.substring(lastDelim + 1);
|
||||
|
||||
if (message.equals("_"))
|
||||
{
|
||||
message = PlexUtils.messageString("commandBlocked");
|
||||
}
|
||||
|
||||
Rank rank = switch (rawRank)
|
||||
{
|
||||
case "e" -> null;
|
||||
case "a" -> Rank.ADMIN;
|
||||
case "s" -> Rank.SENIOR_ADMIN;
|
||||
default -> null;
|
||||
};
|
||||
|
||||
if (rawType.equals("r"))
|
||||
{
|
||||
blockedCommands.add(new RegexCommand(Pattern.compile(regexOrMatch, Pattern.CASE_INSENSITIVE), rank, message));
|
||||
}
|
||||
else if (rawType.equals("m"))
|
||||
{
|
||||
int ind = regexOrMatch.indexOf(' ');
|
||||
if (ind == -1 && regexOrMatch.endsWith(":"))
|
||||
{
|
||||
String pluginName = regexOrMatch.substring(0, regexOrMatch.length() - 1);
|
||||
Plugin plugin = Arrays.stream(Bukkit.getServer().getPluginManager().getPlugins()).filter(pl -> pl.getName().equalsIgnoreCase(pluginName)).findAny().orElse(null);
|
||||
if (plugin != null)
|
||||
{
|
||||
List<Command> commandList = PluginCommandYamlParser.parse(plugin);
|
||||
for (Command command : commandList)
|
||||
{
|
||||
blockedCommands.add(new MatchCommand(command.getName(), rank, message));
|
||||
blockedCommands.add(new MatchCommand(pluginName + ":" + command.getName(), rank, message));
|
||||
for (String alias : command.getAliases())
|
||||
{
|
||||
blockedCommands.add(new MatchCommand(alias, rank, message));
|
||||
blockedCommands.add(new MatchCommand(pluginName + ":" + alias, rank, message));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
String blockedArgs = ind == -1 ? "" : regexOrMatch.substring(ind + 1);
|
||||
if (!blockedArgs.isEmpty())
|
||||
{
|
||||
blockedArgs = " " + blockedArgs; // necessary in case no args
|
||||
}
|
||||
PluginCommand pluginCommand = Plex.get().getServer().getPluginCommand(ind == -1 ? regexOrMatch : regexOrMatch.substring(0, ind));
|
||||
if (pluginCommand != null)
|
||||
{
|
||||
String pluginName = pluginCommand.getPlugin().getName();
|
||||
blockedCommands.add(new MatchCommand(pluginCommand.getName() + blockedArgs, rank, message));
|
||||
blockedCommands.add(new MatchCommand(pluginName + ":" + pluginCommand.getName() + blockedArgs, rank, message));
|
||||
List<String> aliases = pluginCommand.getAliases();
|
||||
for (String alias : aliases)
|
||||
{
|
||||
blockedCommands.add(new MatchCommand(alias + blockedArgs, rank, message));
|
||||
blockedCommands.add(new MatchCommand(pluginName + ":" + alias + blockedArgs, rank, message));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
loadedYet = true;
|
||||
}
|
||||
}
|
@ -1,21 +0,0 @@
|
||||
package dev.plex.command.blocker;
|
||||
|
||||
import dev.plex.rank.enums.Rank;
|
||||
import lombok.Getter;
|
||||
|
||||
@Getter
|
||||
public class MatchCommand extends BaseCommand
|
||||
{
|
||||
private final String match;
|
||||
|
||||
public MatchCommand(String r1, Rank r2, String m1)
|
||||
{
|
||||
super(r2, m1);
|
||||
match = r1;
|
||||
}
|
||||
|
||||
public String toString()
|
||||
{
|
||||
return "MatchCommand (Rank: " + (getRank() == null ? "ALL" : getRank().name()) + ", Match: " + match + ", Message: " + getMessage() + ")";
|
||||
}
|
||||
}
|
@ -1,23 +0,0 @@
|
||||
package dev.plex.command.blocker;
|
||||
|
||||
import dev.plex.rank.enums.Rank;
|
||||
import lombok.Getter;
|
||||
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
@Getter
|
||||
public class RegexCommand extends BaseCommand
|
||||
{
|
||||
private final Pattern regex;
|
||||
|
||||
public RegexCommand(Pattern r1, Rank r2, String m1)
|
||||
{
|
||||
super(r2, m1);
|
||||
regex = r1;
|
||||
}
|
||||
|
||||
public String toString()
|
||||
{
|
||||
return "RegexCommand (Rank: " + (getRank() == null ? "ALL" : getRank().name()) + ", Regex: " + regex.toString() + ", Message: " + getMessage() + ")";
|
||||
}
|
||||
}
|
16
src/main/java/dev/plex/command/blocking/BlockedCommand.java
Normal file
16
src/main/java/dev/plex/command/blocking/BlockedCommand.java
Normal file
@ -0,0 +1,16 @@
|
||||
package dev.plex.command.blocking;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import java.util.List;
|
||||
import lombok.Data;
|
||||
import net.kyori.adventure.text.Component;
|
||||
|
||||
@Data
|
||||
public class BlockedCommand
|
||||
{
|
||||
private Component message;
|
||||
private String requiredLevel;
|
||||
private String regex;
|
||||
private String command;
|
||||
private List<String> commandAliases = Lists.newArrayList();
|
||||
}
|
@ -14,11 +14,9 @@ import dev.plex.event.AdminRemoveEvent;
|
||||
import dev.plex.event.AdminSetRankEvent;
|
||||
import dev.plex.player.PlexPlayer;
|
||||
import dev.plex.rank.enums.Rank;
|
||||
import dev.plex.util.PlexLog;
|
||||
import dev.plex.util.PlexUtils;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.bukkit.Bukkit;
|
||||
@ -54,18 +52,18 @@ public class AdminCMD extends PlexCommand
|
||||
throw new ConsoleOnlyException();
|
||||
}
|
||||
|
||||
UUID targetUUID = PlexUtils.getFromName(args[1]);
|
||||
/*UUID targetUUID = PlexUtils.getFromName(args[1]);
|
||||
|
||||
if (targetUUID != null)
|
||||
{
|
||||
PlexLog.debug("Admin Adding UUID: " + targetUUID);
|
||||
}
|
||||
}*/
|
||||
|
||||
if (targetUUID == null || !DataUtils.hasPlayedBefore(targetUUID))
|
||||
if (!DataUtils.hasPlayedBefore(args[1]))
|
||||
{
|
||||
throw new PlayerNotFoundException();
|
||||
}
|
||||
PlexPlayer plexPlayer = DataUtils.getPlayer(targetUUID);
|
||||
PlexPlayer plexPlayer = DataUtils.getPlayer(args[1]);
|
||||
|
||||
if (isAdmin(plexPlayer))
|
||||
{
|
||||
@ -87,13 +85,13 @@ public class AdminCMD extends PlexCommand
|
||||
throw new ConsoleOnlyException();
|
||||
}
|
||||
|
||||
UUID targetUUID = PlexUtils.getFromName(args[1]);
|
||||
// UUID targetUUID = PlexUtils.getFromName(args[1]);
|
||||
|
||||
if (targetUUID == null || !DataUtils.hasPlayedBefore(targetUUID))
|
||||
if (!DataUtils.hasPlayedBefore(args[1]))
|
||||
{
|
||||
throw new PlayerNotFoundException();
|
||||
}
|
||||
PlexPlayer plexPlayer = DataUtils.getPlayer(targetUUID);
|
||||
PlexPlayer plexPlayer = DataUtils.getPlayer(args[1]);
|
||||
|
||||
if (!isAdmin(plexPlayer))
|
||||
{
|
||||
@ -116,9 +114,9 @@ public class AdminCMD extends PlexCommand
|
||||
throw new ConsoleOnlyException();
|
||||
}
|
||||
|
||||
UUID targetUUID = PlexUtils.getFromName(args[1]);
|
||||
// UUID targetUUID = PlexUtils.getFromName(args[1]);
|
||||
|
||||
if (targetUUID == null || !DataUtils.hasPlayedBefore(targetUUID))
|
||||
if (!DataUtils.hasPlayedBefore(args[1]))
|
||||
{
|
||||
throw new PlayerNotFoundException();
|
||||
}
|
||||
@ -135,7 +133,7 @@ public class AdminCMD extends PlexCommand
|
||||
return messageComponent("rankMustBeHigherThanAdmin");
|
||||
}
|
||||
|
||||
PlexPlayer plexPlayer = DataUtils.getPlayer(targetUUID);
|
||||
PlexPlayer plexPlayer = DataUtils.getPlayer(args[1]);
|
||||
|
||||
if (!isAdmin(plexPlayer))
|
||||
{
|
||||
|
@ -1,6 +1,6 @@
|
||||
package dev.plex.command.impl;
|
||||
|
||||
import dev.plex.cache.player.PlayerCache;
|
||||
import dev.plex.cache.PlayerCache;
|
||||
import dev.plex.command.PlexCommand;
|
||||
import dev.plex.command.annotation.CommandParameters;
|
||||
import dev.plex.command.annotation.CommandPermissions;
|
||||
|
@ -14,7 +14,11 @@ import dev.plex.punishment.PunishmentType;
|
||||
import dev.plex.rank.enums.Rank;
|
||||
import dev.plex.util.PlexLog;
|
||||
import dev.plex.util.PlexUtils;
|
||||
import dev.plex.util.TimeUtils;
|
||||
import dev.plex.util.WebUtils;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.ZoneId;
|
||||
import java.time.ZonedDateTime;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import net.kyori.adventure.text.Component;
|
||||
@ -38,7 +42,7 @@ public class BanCMD extends PlexCommand
|
||||
return usage();
|
||||
}
|
||||
|
||||
UUID targetUUID = PlexUtils.getFromName(args[0]);
|
||||
UUID targetUUID = WebUtils.getFromName(args[0]);
|
||||
|
||||
if (targetUUID == null || !DataUtils.hasPlayedBefore(targetUUID))
|
||||
{
|
||||
@ -47,15 +51,18 @@ public class BanCMD extends PlexCommand
|
||||
PlexPlayer plexPlayer = DataUtils.getPlayer(targetUUID);
|
||||
Player player = Bukkit.getPlayer(targetUUID);
|
||||
|
||||
if (isAdmin(plexPlayer))
|
||||
if (plugin.getSystem().equalsIgnoreCase("ranks"))
|
||||
{
|
||||
if (!isConsole(sender))
|
||||
if (isAdmin(plexPlayer))
|
||||
{
|
||||
assert playerSender != null;
|
||||
PlexPlayer plexPlayer1 = getPlexPlayer(playerSender);
|
||||
if (!plexPlayer1.getRankFromString().isAtLeast(plexPlayer.getRankFromString()))
|
||||
if (!isConsole(sender))
|
||||
{
|
||||
return messageComponent("higherRankThanYou");
|
||||
assert playerSender != null;
|
||||
PlexPlayer plexPlayer1 = getPlexPlayer(playerSender);
|
||||
if (!plexPlayer1.getRankFromString().isAtLeast(plexPlayer.getRankFromString()))
|
||||
{
|
||||
return messageComponent("higherRankThanYou");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -80,7 +87,7 @@ public class BanCMD extends PlexCommand
|
||||
punishment.setReason("No reason provided.");
|
||||
}
|
||||
punishment.setPunishedUsername(plexPlayer.getName());
|
||||
LocalDateTime date = LocalDateTime.now();
|
||||
ZonedDateTime date = ZonedDateTime.now(ZoneId.of(TimeUtils.TIMEZONE));
|
||||
punishment.setEndDate(date.plusDays(1));
|
||||
punishment.setCustomTime(false);
|
||||
punishment.setActive(!isAdmin(plexPlayer));
|
||||
|
@ -7,9 +7,7 @@ import dev.plex.command.annotation.CommandPermissions;
|
||||
import dev.plex.command.source.RequiredCommandSource;
|
||||
import dev.plex.player.PlexPlayer;
|
||||
import dev.plex.rank.enums.Rank;
|
||||
import dev.plex.util.PlexUtils;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
31
src/main/java/dev/plex/command/impl/ConsoleSayCMD.java
Normal file
31
src/main/java/dev/plex/command/impl/ConsoleSayCMD.java
Normal file
@ -0,0 +1,31 @@
|
||||
package dev.plex.command.impl;
|
||||
|
||||
import dev.plex.command.PlexCommand;
|
||||
import dev.plex.command.annotation.CommandParameters;
|
||||
import dev.plex.command.annotation.CommandPermissions;
|
||||
import dev.plex.command.source.RequiredCommandSource;
|
||||
import dev.plex.rank.enums.Rank;
|
||||
import dev.plex.util.PlexUtils;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@CommandPermissions(level = Rank.ADMIN, permission = "plex.consolesay", source = RequiredCommandSource.CONSOLE)
|
||||
@CommandParameters(name = "consolesay", usage = "/<command> <message>", description = "Displays a message to everyone", aliases = "csay")
|
||||
public class ConsoleSayCMD extends PlexCommand
|
||||
{
|
||||
@Override
|
||||
protected Component execute(@NotNull CommandSender sender, @Nullable Player playerSender, String[] args)
|
||||
{
|
||||
if (args.length == 0)
|
||||
{
|
||||
return usage();
|
||||
}
|
||||
|
||||
PlexUtils.broadcast(PlexUtils.messageComponent("consoleSayMessage", sender.getName(), PlexUtils.mmStripColor(StringUtils.join(args, " "))));
|
||||
return null;
|
||||
}
|
||||
}
|
@ -6,20 +6,23 @@ import dev.plex.command.annotation.CommandParameters;
|
||||
import dev.plex.command.annotation.CommandPermissions;
|
||||
import dev.plex.command.annotation.System;
|
||||
import dev.plex.rank.enums.Rank;
|
||||
import dev.plex.util.GameRuleUtil;
|
||||
import dev.plex.util.PlexLog;
|
||||
import dev.plex.util.PlexUtils;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@CommandParameters(name = "pdebug", description = "Plex's debug command", usage = "/<command> <redis-reset <player> | gamerules>")
|
||||
@CommandParameters(name = "pdebug", description = "Plex's debug command", usage = "/<command> <aliases <command> | redis-reset <player> | gamerules>")
|
||||
@CommandPermissions(level = Rank.EXECUTIVE, permission = "plex.debug")
|
||||
@System(debug = true)
|
||||
public class DebugCMD extends PlexCommand
|
||||
@ -45,7 +48,7 @@ public class DebugCMD extends PlexCommand
|
||||
{
|
||||
for (World world : Bukkit.getWorlds())
|
||||
{
|
||||
PlexUtils.commitGlobalGameRules(world);
|
||||
GameRuleUtil.commitGlobalGameRules(world);
|
||||
PlexLog.log("Set global gamerules for world: " + world.getName());
|
||||
}
|
||||
for (String world : plugin.config.getConfigurationSection("worlds").getKeys(false))
|
||||
@ -53,12 +56,22 @@ public class DebugCMD extends PlexCommand
|
||||
World bukkitWorld = Bukkit.getWorld(world);
|
||||
if (bukkitWorld != null)
|
||||
{
|
||||
PlexUtils.commitSpecificGameRules(bukkitWorld);
|
||||
GameRuleUtil.commitSpecificGameRules(bukkitWorld);
|
||||
PlexLog.log("Set specific gamerules for world: " + world.toLowerCase(Locale.ROOT));
|
||||
}
|
||||
}
|
||||
return mmString("<aqua>Re-applied game all the game rules!");
|
||||
}
|
||||
if (args[0].equalsIgnoreCase("aliases"))
|
||||
{
|
||||
String commandName = args[1];
|
||||
Command command = plugin.getServer().getCommandMap().getCommand(commandName);
|
||||
if (command == null)
|
||||
{
|
||||
return mmString("<red>That command could not be found!");
|
||||
}
|
||||
return mmString("<aqua>Aliases for " + commandName + " are: " + Arrays.toString(command.getAliases().toArray(new String[0])));
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
@ -1,6 +1,5 @@
|
||||
package dev.plex.command.impl;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import dev.plex.command.PlexCommand;
|
||||
import dev.plex.command.annotation.CommandParameters;
|
||||
import dev.plex.command.annotation.CommandPermissions;
|
||||
@ -8,10 +7,12 @@ import dev.plex.command.source.RequiredCommandSource;
|
||||
import dev.plex.rank.enums.Rank;
|
||||
import dev.plex.util.PlexUtils;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Entity;
|
||||
@ -20,11 +21,6 @@ import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
@CommandPermissions(level = Rank.ADMIN, permission = "plex.entitywipe", source = RequiredCommandSource.ANY)
|
||||
@CommandParameters(name = "entitywipe", description = "Remove various server entities that may cause lag, such as dropped items, minecarts, and boats.", usage = "/<command> [name]", aliases = "ew,rd")
|
||||
public class EntityWipeCMD extends PlexCommand
|
||||
@ -57,7 +53,7 @@ public class EntityWipeCMD extends PlexCommand
|
||||
{
|
||||
if (entity.getType() != EntityType.PLAYER)
|
||||
{
|
||||
String type = entity.getName();
|
||||
String type = entity.getType().name();
|
||||
|
||||
if (useBlacklist ? entityBlacklist.stream().noneMatch(entityName -> entityName.equalsIgnoreCase(type)) : entityWhitelist.stream().anyMatch(entityName -> entityName.equalsIgnoreCase(type)))
|
||||
{
|
||||
@ -86,10 +82,6 @@ public class EntityWipeCMD extends PlexCommand
|
||||
list = list.replaceAll("(, )(?!.*\1)", (list.indexOf(", ") == list.lastIndexOf(", ") ? "" : ",") + " and ");
|
||||
PlexUtils.broadcast(messageComponent("removedEntitiesOfTypes", sender.getName(), entityCount, list));
|
||||
}
|
||||
|
||||
/*entityCounts.forEach((entityName, numRemoved) -> {
|
||||
sender.sendMessage(messageComponent("removedEntitiesOfType", sender.getName(), numRemoved, entityName));
|
||||
});*/
|
||||
return null;
|
||||
}
|
||||
|
||||
@ -102,7 +94,7 @@ public class EntityWipeCMD extends PlexCommand
|
||||
{
|
||||
if (entity.getType() != EntityType.PLAYER)
|
||||
{
|
||||
entities.add(entity.getName());
|
||||
entities.add(entity.getType().name());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -17,7 +17,6 @@ import org.jetbrains.annotations.Nullable;
|
||||
@CommandParameters(name = "flatlands", description = "Teleport to the flatlands")
|
||||
public class FlatlandsCMD extends PlexCommand
|
||||
{
|
||||
|
||||
@Override
|
||||
protected Component execute(@NotNull CommandSender sender, @Nullable Player playerSender, String[] args)
|
||||
{
|
||||
|
@ -9,15 +9,18 @@ import dev.plex.punishment.Punishment;
|
||||
import dev.plex.punishment.PunishmentType;
|
||||
import dev.plex.rank.enums.Rank;
|
||||
import dev.plex.util.PlexUtils;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.ZoneId;
|
||||
import java.time.ZonedDateTime;
|
||||
import java.util.List;
|
||||
|
||||
import dev.plex.util.TimeUtils;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
|
||||
@CommandParameters(name = "freeze", description = "Freeze a player on the server", usage = "/<command> <player>", aliases = "fr")
|
||||
@CommandPermissions(level = Rank.ADMIN, permission = "plex.freeze")
|
||||
public class FreezeCMD extends PlexCommand
|
||||
@ -52,7 +55,7 @@ public class FreezeCMD extends PlexCommand
|
||||
|
||||
Punishment punishment = new Punishment(punishedPlayer.getUuid(), getUUID(sender));
|
||||
punishment.setCustomTime(false);
|
||||
LocalDateTime date = LocalDateTime.now();
|
||||
ZonedDateTime date = ZonedDateTime.now(ZoneId.of(TimeUtils.TIMEZONE));
|
||||
punishment.setEndDate(date.plusMinutes(5));
|
||||
punishment.setType(PunishmentType.FREEZE);
|
||||
punishment.setPunishedUsername(player.getName());
|
||||
|
@ -11,7 +11,11 @@ import dev.plex.punishment.Punishment;
|
||||
import dev.plex.punishment.PunishmentType;
|
||||
import dev.plex.rank.enums.Rank;
|
||||
import dev.plex.util.PlexUtils;
|
||||
import dev.plex.util.TimeUtils;
|
||||
import dev.plex.util.WebUtils;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.ZoneId;
|
||||
import java.time.ZonedDateTime;
|
||||
import java.util.UUID;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
@ -33,7 +37,7 @@ public class KickCMD extends PlexCommand
|
||||
return usage();
|
||||
}
|
||||
|
||||
UUID targetUUID = PlexUtils.getFromName(args[0]);
|
||||
UUID targetUUID = WebUtils.getFromName(args[0]);
|
||||
String reason = "No reason provided";
|
||||
|
||||
if (targetUUID == null || !DataUtils.hasPlayedBefore(targetUUID))
|
||||
@ -56,7 +60,7 @@ public class KickCMD extends PlexCommand
|
||||
}
|
||||
|
||||
punishment.setPunishedUsername(plexPlayer.getName());
|
||||
punishment.setEndDate(LocalDateTime.now());
|
||||
punishment.setEndDate(ZonedDateTime.now(ZoneId.of(TimeUtils.TIMEZONE)));
|
||||
punishment.setCustomTime(false);
|
||||
punishment.setActive(false);
|
||||
punishment.setIp(player.getAddress().getAddress().getHostAddress().trim());
|
||||
|
@ -37,6 +37,10 @@ public class ListCMD extends PlexCommand
|
||||
.append(Component.space())
|
||||
.append(Component.text(Bukkit.getMaxPlayers() == 1 ? "player." : "players.").color(NamedTextColor.GRAY));
|
||||
send(sender, header);
|
||||
if (players.size() == 0)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
for (int i = 0; i < players.size(); i++)
|
||||
{
|
||||
Player player = players.get(i);
|
||||
|
@ -17,7 +17,6 @@ import org.jetbrains.annotations.Nullable;
|
||||
@CommandParameters(name = "masterbuilderworld", aliases = "mbw", description = "Teleport to the Master Builder world")
|
||||
public class MasterbuilderworldCMD extends PlexCommand
|
||||
{
|
||||
|
||||
@Override
|
||||
protected Component execute(@NotNull CommandSender sender, @Nullable Player playerSender, String[] args)
|
||||
{
|
||||
|
@ -6,16 +6,17 @@ import dev.plex.command.annotation.CommandPermissions;
|
||||
import dev.plex.command.source.RequiredCommandSource;
|
||||
import dev.plex.rank.enums.Rank;
|
||||
import dev.plex.util.PlexUtils;
|
||||
import java.util.HashMap;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.*;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Mob;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
@CommandPermissions(level = Rank.ADMIN, permission = "plex.mobpurge", source = RequiredCommandSource.ANY)
|
||||
@CommandParameters(name = "mobpurge", description = "Purge all mobs.", usage = "/<command>", aliases = "mp")
|
||||
public class MobPurgeCMD extends PlexCommand
|
||||
|
@ -10,8 +10,11 @@ import dev.plex.punishment.PunishmentType;
|
||||
import dev.plex.rank.enums.Rank;
|
||||
import dev.plex.util.PlexUtils;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.ZoneId;
|
||||
import java.time.ZonedDateTime;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
import dev.plex.util.TimeUtils;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
@ -52,7 +55,7 @@ public class MuteCMD extends PlexCommand
|
||||
|
||||
Punishment punishment = new Punishment(punishedPlayer.getUuid(), getUUID(sender));
|
||||
punishment.setCustomTime(false);
|
||||
LocalDateTime date = LocalDateTime.now();
|
||||
ZonedDateTime date = ZonedDateTime.now(ZoneId.of(TimeUtils.TIMEZONE));
|
||||
punishment.setEndDate(date.plusMinutes(5));
|
||||
punishment.setType(PunishmentType.MUTE);
|
||||
punishment.setPunishedUsername(player.getName());
|
||||
|
@ -10,7 +10,7 @@ import dev.plex.util.AshconInfo;
|
||||
import dev.plex.util.MojangUtils;
|
||||
import dev.plex.util.PlexLog;
|
||||
import dev.plex.util.PlexUtils;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import dev.plex.util.TimeUtils;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import net.kyori.adventure.text.Component;
|
||||
@ -24,8 +24,6 @@ import org.jetbrains.annotations.Nullable;
|
||||
@CommandPermissions(level = Rank.OP, permission = "plex.namehistory")
|
||||
public class NameHistoryCMD extends PlexCommand
|
||||
{
|
||||
private static final DateTimeFormatter DATE_FORMAT = DateTimeFormatter.ofPattern("MM/dd/yyyy 'at' hh:mm:ss a");
|
||||
|
||||
@Override
|
||||
protected Component execute(@NotNull CommandSender sender, @Nullable Player playerSender, String[] args)
|
||||
{
|
||||
@ -45,12 +43,12 @@ public class NameHistoryCMD extends PlexCommand
|
||||
List<Component> historyList = Lists.newArrayList();
|
||||
Arrays.stream(info.getUsernameHistories()).forEach(history ->
|
||||
{
|
||||
if (history.getLocalDateTime() != null)
|
||||
if (history.getZonedDateTime() != null)
|
||||
{
|
||||
historyList.add(
|
||||
messageComponent("nameHistoryBody",
|
||||
history.getUsername(),
|
||||
DATE_FORMAT.format(history.getLocalDateTime())));
|
||||
TimeUtils.useTimezone(history.getZonedDateTime())));
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -9,9 +9,16 @@ import dev.plex.punishment.extra.Note;
|
||||
import dev.plex.rank.enums.Rank;
|
||||
import dev.plex.storage.StorageType;
|
||||
import dev.plex.util.PlexUtils;
|
||||
import dev.plex.util.TimeUtils;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.ZoneId;
|
||||
import java.time.ZonedDateTime;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
import net.kyori.adventure.text.format.TextDecoration;
|
||||
import org.apache.commons.lang3.ArrayUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.bukkit.command.CommandSender;
|
||||
@ -19,19 +26,10 @@ import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
|
||||
@CommandParameters(name = "notes", description = "Manage notes for a player", usage = "/<command> <player> <list | add <note> | remove <id> | clear>")
|
||||
@CommandPermissions(level = Rank.ADMIN, permission = "plex.notes")
|
||||
public class NotesCMD extends PlexCommand
|
||||
{
|
||||
private static final DateTimeFormatter DATE_FORMAT = DateTimeFormatter.ofPattern("MM/dd/yyyy 'at' hh:mm:ss a");
|
||||
|
||||
@Override
|
||||
protected Component execute(@NotNull CommandSender sender, @Nullable Player playerSender, String[] args)
|
||||
{
|
||||
@ -79,7 +77,7 @@ public class NotesCMD extends PlexCommand
|
||||
String content = StringUtils.join(ArrayUtils.subarray(args, 2, args.length), " ");
|
||||
if (playerSender != null)
|
||||
{
|
||||
Note note = new Note(plexPlayer.getUuid(), content, playerSender.getUniqueId(), LocalDateTime.now());
|
||||
Note note = new Note(plexPlayer.getUuid(), content, playerSender.getUniqueId(), ZonedDateTime.now(ZoneId.of(TimeUtils.TIMEZONE)));
|
||||
plexPlayer.getNotes().add(note);
|
||||
if (plugin.getStorageType() != StorageType.MONGODB)
|
||||
{
|
||||
@ -94,6 +92,10 @@ public class NotesCMD extends PlexCommand
|
||||
}
|
||||
case "remove":
|
||||
{
|
||||
if (args.length < 3)
|
||||
{
|
||||
return usage();
|
||||
}
|
||||
int id;
|
||||
try
|
||||
{
|
||||
@ -107,17 +109,19 @@ public class NotesCMD extends PlexCommand
|
||||
{
|
||||
plugin.getSqlNotes().getNotes(plexPlayer.getUuid()).whenComplete((notes, ex) ->
|
||||
{
|
||||
boolean deleted = false;
|
||||
for (Note note : notes)
|
||||
{
|
||||
if (note.getId() == id)
|
||||
{
|
||||
plugin.getSqlNotes().deleteNote(id, plexPlayer.getUuid()).whenComplete((notes1, ex1) ->
|
||||
send(sender, Component.text("Removed note with ID: " + id).color(NamedTextColor.GREEN)));
|
||||
deleted = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
send(sender, mmString("<red>A note with this ID could not be found"));
|
||||
}
|
||||
}
|
||||
if (!deleted)
|
||||
{
|
||||
send(sender, mmString("<red>A note with this ID could not be found"));
|
||||
}
|
||||
plexPlayer.getNotes().removeIf(note -> note.getId() == id);
|
||||
});
|
||||
@ -130,6 +134,7 @@ public class NotesCMD extends PlexCommand
|
||||
}
|
||||
return mmString("<red>A note with this ID could not be found");
|
||||
}
|
||||
return null;
|
||||
}
|
||||
case "clear":
|
||||
{
|
||||
@ -166,8 +171,8 @@ public class NotesCMD extends PlexCommand
|
||||
AtomicReference<Component> noteList = new AtomicReference<>(Component.text("Player notes for: " + plexPlayer.getName()).color(NamedTextColor.GREEN));
|
||||
for (Note note : notes)
|
||||
{
|
||||
Component noteLine = Component.text(note.getId() + " - Written by: " + DataUtils.getPlayer(note.getWrittenBy()).getName() + " on " + DATE_FORMAT.format(note.getTimestamp())).color(NamedTextColor.YELLOW).decoration(TextDecoration.ITALIC, false);
|
||||
noteLine = noteLine.append(Component.text(note.getNote())).color(NamedTextColor.GOLD).decoration(TextDecoration.ITALIC, true);
|
||||
Component noteLine = mmString("<gold><!italic>" + note.getId() + " - Written by: " + DataUtils.getPlayer(note.getWrittenBy()).getName() + " on " + TimeUtils.useTimezone(note.getTimestamp()));
|
||||
noteLine = noteLine.append(mmString("<newline><yellow># " + note.getNote()));
|
||||
noteList.set(noteList.get().append(Component.newline()));
|
||||
noteList.set(noteList.get().append(noteLine));
|
||||
}
|
||||
|
@ -9,16 +9,18 @@ import dev.plex.command.source.RequiredCommandSource;
|
||||
import dev.plex.module.PlexModule;
|
||||
import dev.plex.module.PlexModuleFile;
|
||||
import dev.plex.rank.enums.Rank;
|
||||
import dev.plex.util.BuildInfo;
|
||||
import dev.plex.util.PlexLog;
|
||||
import dev.plex.util.PlexUtils;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import dev.plex.util.PlexLog;
|
||||
import dev.plex.util.PlexUtils;
|
||||
import dev.plex.util.TimeUtils;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@ -35,9 +37,9 @@ public class PlexCMD extends PlexCommand
|
||||
if (args.length == 0)
|
||||
{
|
||||
send(sender, mmString("<light_purple>Plex - A new freedom plugin."));
|
||||
send(sender, mmString("<light_purple>Plugin version: <gold>" + plugin.getDescription().getVersion() + " #" + Plex.build.number + " <light_purple>Git: <gold>" + Plex.build.head));
|
||||
send(sender, mmString("<light_purple>Plugin version: <gold>" + plugin.getDescription().getVersion() + " #" + BuildInfo.getNumber() + " <light_purple>Git: <gold>" + BuildInfo.getHead()));
|
||||
send(sender, mmString("<light_purple>Authors: <gold>Telesphoreo, Taahh"));
|
||||
send(sender, mmString("<light_purple>Built by: <gold>" + Plex.build.author + " <light_purple>on <gold>" + Plex.build.date));
|
||||
send(sender, mmString("<light_purple>Built by: <gold>" + BuildInfo.getAuthor() + " <light_purple>on <gold>" + BuildInfo.getDate()));
|
||||
send(sender, mmString("<light_purple>Run <gold>/plex modules <light_purple>to see a list of modules."));
|
||||
plugin.getUpdateChecker().getUpdateStatusMessage(sender, true, 2);
|
||||
return null;
|
||||
@ -52,15 +54,20 @@ public class PlexCMD extends PlexCommand
|
||||
plugin.indefBans.load(false);
|
||||
plugin.getPunishmentManager().mergeIndefiniteBans();
|
||||
send(sender, "Reloaded indefinite bans");
|
||||
plugin.blockedCommands.load();
|
||||
plugin.getCommandBlockerManager().syncCommands();
|
||||
plugin.commands.load();
|
||||
send(sender, "Reloaded blocked commands file");
|
||||
plugin.getRankManager().importDefaultRanks();
|
||||
send(sender, "Imported ranks");
|
||||
plugin.setSystem(plugin.config.getString("system"));
|
||||
if (!plugin.setupPermissions() && plugin.getSystem().equalsIgnoreCase("permissions") && !plugin.getServer().getPluginManager().isPluginEnabled("Vault"))
|
||||
{
|
||||
throw new RuntimeException("Vault is required to run on the server if you use permissions!");
|
||||
}
|
||||
plugin.getServiceManager().endServices();
|
||||
plugin.getServiceManager().startServices();
|
||||
PlexLog.debug("Restarted services");
|
||||
TimeUtils.TIMEZONE = plugin.config.getString("server.timezone");
|
||||
send(sender, "Set timezone to: " + TimeUtils.TIMEZONE);
|
||||
send(sender, "Plex successfully reloaded.");
|
||||
return null;
|
||||
}
|
||||
|
@ -33,14 +33,14 @@ public class RankCMD extends PlexCommand
|
||||
if (!(playerSender == null))
|
||||
{
|
||||
Rank rank = getPlexPlayer(playerSender).getRankFromString();
|
||||
return messageComponent("yourRank", rank.getReadable());
|
||||
return messageComponent("yourRank", rank.isAtLeast(Rank.ADMIN) && !getPlexPlayer(playerSender).isAdminActive() ? (playerSender.isOp() ? Rank.OP.getReadable() : Rank.NONOP.getReadable()) : rank.getReadable());
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Player player = getNonNullPlayer(args[0]);
|
||||
Rank rank = getPlexPlayer(player).getRankFromString();
|
||||
return messageComponent("otherRank", player.getName(), rank.getReadable());
|
||||
return messageComponent("otherRank", player.getName(), rank.isAtLeast(Rank.ADMIN) && !getPlexPlayer(player).isAdminActive() ? (player.isOp() ? Rank.OP.getReadable() : Rank.NONOP.getReadable()) : rank.getReadable());
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
@ -14,7 +14,7 @@ import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@CommandPermissions(level = Rank.SENIOR_ADMIN, permission = "plex.rawsay", source = RequiredCommandSource.ANY)
|
||||
@CommandParameters(name = "rawsay", usage = "/<command> <message>", description = "Displays a message to everyone")
|
||||
@CommandParameters(name = "rawsay", usage = "/<command> <message>", description = "Displays a raw message to everyone")
|
||||
public class RawSayCMD extends PlexCommand
|
||||
{
|
||||
@Override
|
||||
|
31
src/main/java/dev/plex/command/impl/SayCMD.java
Normal file
31
src/main/java/dev/plex/command/impl/SayCMD.java
Normal file
@ -0,0 +1,31 @@
|
||||
package dev.plex.command.impl;
|
||||
|
||||
import dev.plex.command.PlexCommand;
|
||||
import dev.plex.command.annotation.CommandParameters;
|
||||
import dev.plex.command.annotation.CommandPermissions;
|
||||
import dev.plex.command.source.RequiredCommandSource;
|
||||
import dev.plex.rank.enums.Rank;
|
||||
import dev.plex.util.PlexUtils;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@CommandPermissions(level = Rank.ADMIN, permission = "plex.say", source = RequiredCommandSource.ANY)
|
||||
@CommandParameters(name = "say", usage = "/<command> <message>", description = "Displays a message to everyone")
|
||||
public class SayCMD extends PlexCommand
|
||||
{
|
||||
@Override
|
||||
protected Component execute(@NotNull CommandSender sender, @Nullable Player playerSender, String[] args)
|
||||
{
|
||||
if (args.length == 0)
|
||||
{
|
||||
return usage();
|
||||
}
|
||||
|
||||
PlexUtils.broadcast(PlexUtils.messageComponent("sayMessage", sender.getName(), PlexUtils.mmStripColor(StringUtils.join(args, " "))));
|
||||
return null;
|
||||
}
|
||||
}
|
@ -10,8 +10,12 @@ import dev.plex.punishment.PunishmentType;
|
||||
import dev.plex.rank.enums.Rank;
|
||||
import dev.plex.util.PlexUtils;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.ZoneId;
|
||||
import java.time.ZonedDateTime;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import dev.plex.util.TimeUtils;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
import net.kyori.adventure.title.Title;
|
||||
@ -125,7 +129,7 @@ public class SmiteCMD extends PlexCommand
|
||||
|
||||
Punishment punishment = new Punishment(plexPlayer.getUuid(), getUUID(sender));
|
||||
punishment.setCustomTime(false);
|
||||
punishment.setEndDate(LocalDateTime.now());
|
||||
punishment.setEndDate(ZonedDateTime.now(ZoneId.of(TimeUtils.TIMEZONE)));
|
||||
punishment.setType(PunishmentType.SMITE);
|
||||
punishment.setPunishedUsername(player.getName());
|
||||
punishment.setIp(player.getAddress().getAddress().getHostAddress().trim());
|
||||
|
@ -7,9 +7,10 @@ import dev.plex.command.annotation.CommandPermissions;
|
||||
import dev.plex.command.source.RequiredCommandSource;
|
||||
import dev.plex.player.PlexPlayer;
|
||||
import dev.plex.rank.enums.Rank;
|
||||
import dev.plex.util.PlexUtils;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
|
||||
import net.kyori.adventure.text.minimessage.tag.standard.StandardTags;
|
||||
import net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.bukkit.command.CommandSender;
|
||||
@ -47,15 +48,15 @@ public class TagCMD extends PlexCommand
|
||||
return usage("/tag set <prefix>");
|
||||
}
|
||||
String prefix = StringUtils.join(args, " ", 1, args.length);
|
||||
Component convertedComponent = removeEvents(noColorComponentFromString(prefix));
|
||||
convertedComponent = removeEvents(MiniMessage.miniMessage().deserialize(LegacyComponentSerializer.legacySection().serialize(convertedComponent)));
|
||||
|
||||
Component convertedComponent = removeEvents(PlexUtils.mmCustomDeserialize(prefix = prefix.replace("<newline>", "").replace("<br>", ""), StandardTags.color(), StandardTags.rainbow(), StandardTags.decorations(), StandardTags.gradient(), StandardTags.transition())); //noColorComponentFromString(prefix)
|
||||
|
||||
if (PlainTextComponentSerializer.plainText().serialize(convertedComponent).length() > plugin.config.getInt("chat.max-tag-length", 16))
|
||||
{
|
||||
return messageComponent("maximumPrefixLength", plugin.config.getInt("chat.max-tag-length", 16));
|
||||
}
|
||||
|
||||
player.setPrefix(MiniMessage.miniMessage().serialize(convertedComponent));
|
||||
player.setPrefix(prefix);
|
||||
DataUtils.update(player);
|
||||
return messageComponent("prefixSetTo", MiniMessage.miniMessage().serialize(convertedComponent));
|
||||
}
|
||||
@ -85,7 +86,7 @@ public class TagCMD extends PlexCommand
|
||||
PlexPlayer plexTarget = DataUtils.getPlayer(target.getUniqueId());
|
||||
plexTarget.setPrefix("");
|
||||
DataUtils.update(plexTarget);
|
||||
messageComponent("otherPrefixCleared");
|
||||
return messageComponent("otherPrefixCleared", target.getName());
|
||||
}
|
||||
return usage();
|
||||
}
|
||||
|
@ -12,6 +12,8 @@ import dev.plex.punishment.Punishment;
|
||||
import dev.plex.punishment.PunishmentType;
|
||||
import dev.plex.rank.enums.Rank;
|
||||
import dev.plex.util.PlexUtils;
|
||||
import dev.plex.util.TimeUtils;
|
||||
import dev.plex.util.WebUtils;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import net.kyori.adventure.text.Component;
|
||||
@ -35,7 +37,7 @@ public class TempbanCMD extends PlexCommand
|
||||
return usage();
|
||||
}
|
||||
|
||||
UUID targetUUID = PlexUtils.getFromName(args[0]);
|
||||
UUID targetUUID = WebUtils.getFromName(args[0]);
|
||||
String reason;
|
||||
|
||||
if (targetUUID == null || !DataUtils.hasPlayedBefore(targetUUID))
|
||||
@ -64,7 +66,7 @@ public class TempbanCMD extends PlexCommand
|
||||
return messageComponent("playerBanned");
|
||||
}
|
||||
Punishment punishment = new Punishment(targetUUID, getUUID(sender));
|
||||
punishment.setType(PunishmentType.BAN);
|
||||
punishment.setType(PunishmentType.TEMPBAN);
|
||||
if (args.length > 2)
|
||||
{
|
||||
reason = StringUtils.join(args, " ", 2, args.length);
|
||||
@ -75,7 +77,7 @@ public class TempbanCMD extends PlexCommand
|
||||
punishment.setReason("No reason provided.");
|
||||
}
|
||||
punishment.setPunishedUsername(plexPlayer.getName());
|
||||
punishment.setEndDate(PlexUtils.parseDateOffset(args[1]));
|
||||
punishment.setEndDate(TimeUtils.createDate(args[1]));
|
||||
punishment.setCustomTime(false);
|
||||
punishment.setActive(!isAdmin(plexPlayer));
|
||||
if (player != null)
|
||||
|
@ -5,24 +5,12 @@ import dev.plex.command.annotation.CommandParameters;
|
||||
import dev.plex.command.annotation.CommandPermissions;
|
||||
import dev.plex.command.source.RequiredCommandSource;
|
||||
import dev.plex.rank.enums.Rank;
|
||||
import dev.plex.services.ServiceManager;
|
||||
import dev.plex.services.impl.AutoWipeService;
|
||||
import dev.plex.util.PlexUtils;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
@CommandPermissions(level = Rank.ADMIN, permission = "plex.toggledrops", source = RequiredCommandSource.ANY)
|
||||
@CommandParameters(name = "toggledrops", description = "Toggle immediately removing drops.", usage = "/<command>", aliases = "td")
|
||||
public class ToggleDropsCMD extends PlexCommand
|
||||
|
@ -11,10 +11,10 @@ import dev.plex.command.source.RequiredCommandSource;
|
||||
import dev.plex.player.PlexPlayer;
|
||||
import dev.plex.rank.enums.Rank;
|
||||
import dev.plex.util.PlexUtils;
|
||||
import dev.plex.util.WebUtils;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@ -35,7 +35,7 @@ public class UnbanCMD extends PlexCommand
|
||||
|
||||
if (args.length == 1)
|
||||
{
|
||||
UUID targetUUID = PlexUtils.getFromName(args[0]);
|
||||
UUID targetUUID = WebUtils.getFromName(args[0]);
|
||||
|
||||
if (targetUUID == null || !DataUtils.hasPlayedBefore(targetUUID))
|
||||
{
|
||||
@ -47,7 +47,7 @@ public class UnbanCMD extends PlexCommand
|
||||
PlexPlayer plexPlayer = getOfflinePlexPlayer(targetUUID);
|
||||
if (!aBoolean)
|
||||
{
|
||||
send(sender, MiniMessage.miniMessage().deserialize(new PlayerNotBannedException().getMessage()));
|
||||
send(sender, PlexUtils.mmDeserialize(new PlayerNotBannedException().getMessage()));
|
||||
return;
|
||||
}
|
||||
plugin.getPunishmentManager().unban(targetUUID);
|
||||
|
@ -23,21 +23,27 @@ public class ModuleConfig extends YamlConfiguration
|
||||
private File file;
|
||||
|
||||
/**
|
||||
* The file name
|
||||
* Where the file is in the module JAR
|
||||
*/
|
||||
private String name;
|
||||
private String from;
|
||||
|
||||
/**
|
||||
* Where it should be copied to in the module folder
|
||||
*/
|
||||
private String to;
|
||||
|
||||
/**
|
||||
* Creates a config object
|
||||
*
|
||||
* @param module The module instance
|
||||
* @param name The file name
|
||||
* @param to The file name
|
||||
*/
|
||||
public ModuleConfig(PlexModule module, String name)
|
||||
public ModuleConfig(PlexModule module, String from, String to)
|
||||
{
|
||||
this.module = module;
|
||||
this.file = new File(module.getDataFolder(), name);
|
||||
this.name = name;
|
||||
this.file = new File(module.getDataFolder(), to);
|
||||
this.to = to;
|
||||
this.from = from;
|
||||
|
||||
if (!file.exists())
|
||||
{
|
||||
@ -79,45 +85,11 @@ public class ModuleConfig extends YamlConfiguration
|
||||
{
|
||||
try
|
||||
{
|
||||
Files.copy(module.getClass().getResourceAsStream("/" + name), this.file.toPath());
|
||||
Files.copy(module.getClass().getResourceAsStream("/" + from), this.file.toPath());
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
/*if (name == null || name.equals("")) {
|
||||
throw new IllegalArgumentException("ResourcePath cannot be null or empty");
|
||||
}
|
||||
|
||||
name = name.replace('\\', '/');
|
||||
InputStream in = module.getResource("/" + name);
|
||||
if (in == null) {
|
||||
throw new IllegalArgumentException("The embedded resource '" + name + "'");
|
||||
}
|
||||
|
||||
File outFile = new File(module.getDataFolder(), name);
|
||||
int lastIndex = name.lastIndexOf('/');
|
||||
File outDir = new File(module.getDataFolder(), name.substring(0, lastIndex >= 0 ? lastIndex : 0));
|
||||
|
||||
if (!outDir.exists()) {
|
||||
outDir.mkdirs();
|
||||
}
|
||||
|
||||
try {
|
||||
if (!outFile.exists()) {
|
||||
OutputStream out = new FileOutputStream(outFile);
|
||||
byte[] buf = new byte[1024];
|
||||
int len;
|
||||
while ((len = in.read(buf)) > 0) {
|
||||
out.write(buf, 0, len);
|
||||
}
|
||||
out.close();
|
||||
in.close();
|
||||
} else {
|
||||
module.getLogger().log(org.apache.logging.log4j.Level.INFO, "Could not save " + outFile.getName() + " to " + outFile + " because " + outFile.getName() + " already exists.");
|
||||
}
|
||||
} catch (IOException ex) {
|
||||
module.getLogger().log(Level.ERROR, "Could not save " + outFile.getName() + " to " + outFile, ex);
|
||||
}*/
|
||||
}
|
||||
}
|
@ -8,7 +8,7 @@ import org.bukkit.event.Event;
|
||||
import org.bukkit.event.HandlerList;
|
||||
|
||||
/**
|
||||
* Event that is ran when a player is added to the admin list
|
||||
* Event that is run when a player is added to the admin list
|
||||
*/
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
@Data
|
||||
|
@ -8,7 +8,7 @@ import org.bukkit.event.Event;
|
||||
import org.bukkit.event.HandlerList;
|
||||
|
||||
/**
|
||||
* Event that is ran when a player is removed from the admin list
|
||||
* Event that is run when a player is removed from the admin list
|
||||
*/
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
@Data
|
||||
|
@ -9,7 +9,7 @@ import org.bukkit.event.Event;
|
||||
import org.bukkit.event.HandlerList;
|
||||
|
||||
/**
|
||||
* Event that is ran when an admin's rank is set
|
||||
* Event that is run when an admins rank is set
|
||||
*/
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
@Data
|
||||
|
@ -1,7 +1,6 @@
|
||||
package dev.plex.event;
|
||||
|
||||
import dev.plex.player.PlexPlayer;
|
||||
import java.util.UUID;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import org.bukkit.Bukkit;
|
||||
|
@ -5,16 +5,16 @@ import dev.plex.PlexBase;
|
||||
import dev.plex.command.PlexCommand;
|
||||
import dev.plex.command.annotation.System;
|
||||
import dev.plex.util.PlexLog;
|
||||
import dev.plex.util.PlexUtils;
|
||||
import dev.plex.util.ReflectionsUtil;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
public class CommandHandler extends PlexBase
|
||||
public class CommandHandler implements PlexBase
|
||||
{
|
||||
public CommandHandler()
|
||||
{
|
||||
Set<Class<? extends PlexCommand>> commandSet = PlexUtils.getClassesBySubType("dev.plex.command.impl", PlexCommand.class);
|
||||
Set<Class<? extends PlexCommand>> commandSet = ReflectionsUtil.getClassesBySubType("dev.plex.command.impl", PlexCommand.class);
|
||||
List<PlexCommand> commands = Lists.newArrayList();
|
||||
|
||||
commandSet.forEach(clazz ->
|
||||
@ -39,7 +39,8 @@ public class CommandHandler extends PlexBase
|
||||
commands.add(clazz.getConstructor().newInstance());
|
||||
}
|
||||
}
|
||||
catch (InvocationTargetException | InstantiationException | IllegalAccessException | NoSuchMethodException ex)
|
||||
catch (InvocationTargetException | InstantiationException | IllegalAccessException |
|
||||
NoSuchMethodException ex)
|
||||
{
|
||||
PlexLog.error("Failed to register " + clazz.getSimpleName() + " as a command!");
|
||||
}
|
||||
|
@ -6,15 +6,16 @@ import dev.plex.listener.PlexListener;
|
||||
import dev.plex.listener.annotation.Toggleable;
|
||||
import dev.plex.util.PlexLog;
|
||||
import dev.plex.util.PlexUtils;
|
||||
import dev.plex.util.ReflectionsUtil;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
public class ListenerHandler extends PlexBase
|
||||
public class ListenerHandler implements PlexBase
|
||||
{
|
||||
public ListenerHandler()
|
||||
{
|
||||
Set<Class<? extends PlexListener>> listenerSet = PlexUtils.getClassesBySubType("dev.plex.listener.impl", PlexListener.class);
|
||||
Set<Class<? extends PlexListener>> listenerSet = ReflectionsUtil.getClassesBySubType("dev.plex.listener.impl", PlexListener.class);
|
||||
List<PlexListener> listeners = Lists.newArrayList();
|
||||
|
||||
listenerSet.forEach(clazz ->
|
||||
@ -34,7 +35,8 @@ public class ListenerHandler extends PlexBase
|
||||
listeners.add(clazz.getConstructor().newInstance());
|
||||
}
|
||||
}
|
||||
catch (InvocationTargetException | InstantiationException | IllegalAccessException | NoSuchMethodException ex)
|
||||
catch (InvocationTargetException | InstantiationException | IllegalAccessException |
|
||||
NoSuchMethodException ex)
|
||||
{
|
||||
PlexLog.error("Failed to register " + clazz.getSimpleName() + " as a listener!");
|
||||
}
|
||||
|
@ -3,7 +3,7 @@ package dev.plex.listener;
|
||||
import dev.plex.PlexBase;
|
||||
import org.bukkit.event.Listener;
|
||||
|
||||
public abstract class PlexListener extends PlexBase implements Listener
|
||||
public abstract class PlexListener implements Listener, PlexBase
|
||||
{
|
||||
public PlexListener()
|
||||
{
|
||||
|
@ -18,16 +18,17 @@ public class AdminListener extends PlexListener
|
||||
{
|
||||
String userSender = event.getSender().getName();
|
||||
PlexPlayer target = event.getPlexPlayer();
|
||||
if (!target.getRank().isEmpty())
|
||||
if (target.getRankFromString().isAtLeast(Rank.ADMIN))
|
||||
{
|
||||
PlexUtils.broadcast(messageComponent("adminReadded", userSender, target.getName(), target.getRankFromString().getReadable()));
|
||||
}
|
||||
else
|
||||
{
|
||||
PlexUtils.broadcast(messageComponent("adminReadded", userSender, target.getName(), target.getRankFromString().getReadable()));
|
||||
} else {
|
||||
target.setRank(Rank.ADMIN.name());
|
||||
PlexUtils.broadcast(messageComponent("newAdminAdded", userSender, target.getName()));
|
||||
}
|
||||
target.setAdminActive(true);
|
||||
DataUtils.update(target);
|
||||
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
@ -35,7 +36,6 @@ public class AdminListener extends PlexListener
|
||||
{
|
||||
String userSender = event.getSender().getName();
|
||||
PlexPlayer target = event.getPlexPlayer();
|
||||
// target.setRank("");
|
||||
target.setAdminActive(false);
|
||||
DataUtils.update(target);
|
||||
PlexUtils.broadcast(messageComponent("adminRemoved", userSender, target.getName()));
|
||||
|
42
src/main/java/dev/plex/listener/impl/AntiNukerListener.java
Normal file
42
src/main/java/dev/plex/listener/impl/AntiNukerListener.java
Normal file
@ -0,0 +1,42 @@
|
||||
package dev.plex.listener.impl;
|
||||
|
||||
import dev.plex.listener.PlexListener;
|
||||
import dev.plex.services.impl.TimingService;
|
||||
import java.util.UUID;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.block.BlockBreakEvent;
|
||||
import org.bukkit.event.block.BlockPlaceEvent;
|
||||
|
||||
public class AntiNukerListener extends PlexListener
|
||||
{
|
||||
@EventHandler(priority = EventPriority.HIGH)
|
||||
public void onBlockPlace(BlockPlaceEvent event)
|
||||
{
|
||||
TimingService.nukerCooldown.merge(event.getPlayer().getUniqueId(), 1L, Long::sum);
|
||||
if (getCount(event.getPlayer().getUniqueId()) > 200L)
|
||||
{
|
||||
TimingService.strikes.merge(event.getPlayer().getUniqueId(), 1L, Long::sum);
|
||||
event.getPlayer().kick(Component.text("Please turn off your nuker!"));
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGH)
|
||||
public void onBlockBreak(BlockBreakEvent event)
|
||||
{
|
||||
TimingService.nukerCooldown.merge(event.getPlayer().getUniqueId(), 1L, Long::sum);
|
||||
if (getCount(event.getPlayer().getUniqueId()) > 200L)
|
||||
{
|
||||
TimingService.strikes.merge(event.getPlayer().getUniqueId(), 1L, Long::sum);
|
||||
event.getPlayer().kick(Component.text("Please turn off your nuker!"));
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
public long getCount(UUID uuid)
|
||||
{
|
||||
return TimingService.nukerCooldown.getOrDefault(uuid, 1L);
|
||||
}
|
||||
}
|
41
src/main/java/dev/plex/listener/impl/AntiSpamListener.java
Normal file
41
src/main/java/dev/plex/listener/impl/AntiSpamListener.java
Normal file
@ -0,0 +1,41 @@
|
||||
package dev.plex.listener.impl;
|
||||
|
||||
import dev.plex.listener.PlexListener;
|
||||
import dev.plex.services.impl.TimingService;
|
||||
import io.papermc.paper.event.player.AsyncChatEvent;
|
||||
import java.util.UUID;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
|
||||
|
||||
public class AntiSpamListener extends PlexListener
|
||||
{
|
||||
@EventHandler
|
||||
public void onChat(AsyncChatEvent event)
|
||||
{
|
||||
TimingService.spamCooldown.merge(event.getPlayer().getUniqueId(), 1L, Long::sum);
|
||||
if (getCount(event.getPlayer().getUniqueId()) > 8L)
|
||||
{
|
||||
event.getPlayer().sendMessage(Component.text("Please refrain from spamming messages.").color(NamedTextColor.GRAY));
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST)
|
||||
public void onPlayerCommandPreprocess(PlayerCommandPreprocessEvent event)
|
||||
{
|
||||
TimingService.spamCooldown.merge(event.getPlayer().getUniqueId(), 1L, Long::sum);
|
||||
if (getCount(event.getPlayer().getUniqueId()) > 8L)
|
||||
{
|
||||
event.getPlayer().sendMessage(Component.text("Please refrain from spamming commands.").color(NamedTextColor.GRAY));
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
public long getCount(UUID uuid)
|
||||
{
|
||||
return TimingService.spamCooldown.getOrDefault(uuid, 1L);
|
||||
}
|
||||
}
|
@ -37,7 +37,7 @@ public class BanListener extends PlexListener
|
||||
if (plugin.getPunishmentManager().isBanned(event.getUniqueId()))
|
||||
{
|
||||
PlexPlayer player = DataUtils.getPlayer(event.getUniqueId());
|
||||
player.getPunishments().stream().filter(punishment -> punishment.getType() == PunishmentType.BAN && punishment.isActive()).findFirst().ifPresent(punishment ->
|
||||
player.getPunishments().stream().filter(punishment -> (punishment.getType() == PunishmentType.BAN || punishment.getType() == PunishmentType.TEMPBAN) && punishment.isActive()).findFirst().ifPresent(punishment ->
|
||||
event.disallow(AsyncPlayerPreLoginEvent.Result.KICK_BANNED,
|
||||
Punishment.generateBanMessage(punishment)));
|
||||
}
|
||||
|
@ -1,11 +1,10 @@
|
||||
package dev.plex.listener.impl;
|
||||
|
||||
import dev.plex.listener.PlexListener;
|
||||
import dev.plex.util.PlexUtils;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import dev.plex.util.PlexUtils;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
@ -28,7 +27,7 @@ public class BlockListener extends PlexListener
|
||||
@EventHandler(priority = EventPriority.LOW)
|
||||
public void onBlockPlace(BlockPlaceEvent event)
|
||||
{
|
||||
List<String> blockedBlocksConfig = plugin.config.getStringList("blockedBlocks");
|
||||
List<String> blockedBlocksConfig = plugin.config.getStringList("blocked_blocks");
|
||||
if (blockedBlocksConfig != cachedBlockedBlocksConfig)
|
||||
{
|
||||
blockedBlocks.clear();
|
||||
@ -57,17 +56,17 @@ public class BlockListener extends PlexListener
|
||||
if (blockedBlocks.contains(block.getType()))
|
||||
{
|
||||
block.setType(Material.CAKE);
|
||||
PlexUtils.disabledEffect(event.getPlayer(), block.getLocation().add(0.5,0.5,0.5));
|
||||
PlexUtils.disabledEffect(event.getPlayer(), block.getLocation().add(0.5, 0.5, 0.5));
|
||||
}
|
||||
|
||||
if(SIGNS.contains(block.getType()))
|
||||
if (SIGNS.contains(block.getType()))
|
||||
{
|
||||
Sign sign = (Sign) block.getState();
|
||||
Sign sign = (Sign)block.getState();
|
||||
boolean anythingChanged = false;
|
||||
for (int i = 0; i < sign.lines().size(); i++)
|
||||
{
|
||||
Component line = sign.line(i);
|
||||
if(line.clickEvent() != null)
|
||||
if (line.clickEvent() != null)
|
||||
{
|
||||
anythingChanged = true;
|
||||
sign.line(i, line.clickEvent(null));
|
||||
|
@ -1,6 +1,6 @@
|
||||
package dev.plex.listener.impl;
|
||||
|
||||
import dev.plex.cache.player.PlayerCache;
|
||||
import dev.plex.cache.PlayerCache;
|
||||
import dev.plex.listener.PlexListener;
|
||||
import dev.plex.listener.annotation.Toggleable;
|
||||
import dev.plex.player.PlexPlayer;
|
||||
@ -9,7 +9,7 @@ import io.papermc.paper.event.player.AsyncChatEvent;
|
||||
import net.kyori.adventure.audience.Audience;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
|
||||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@ -51,14 +51,14 @@ public class ChatListener extends PlexListener
|
||||
return Component.empty()
|
||||
.append(prefix)
|
||||
.append(Component.space())
|
||||
.append(LegacyComponentSerializer.legacyAmpersand().deserialize("&" + plugin.config.getString("chat.name-color") + LegacyComponentSerializer.legacyAmpersand().serialize(sourceDisplayName)))
|
||||
.append(MiniMessage.miniMessage().deserialize(plugin.config.getString("chat.name-color", "<white>"))).append(sourceDisplayName)
|
||||
.append(Component.space())
|
||||
.append(Component.text("»").color(NamedTextColor.GRAY))
|
||||
.append(Component.space())
|
||||
.append(message);
|
||||
}
|
||||
return Component.empty()
|
||||
.append(LegacyComponentSerializer.legacyAmpersand().deserialize("&" + plugin.config.getString("chat.name-color") + LegacyComponentSerializer.legacyAmpersand().serialize(sourceDisplayName)))
|
||||
.append(MiniMessage.miniMessage().deserialize(plugin.config.getString("chat.name-color", "<white>"))).append(sourceDisplayName)
|
||||
.append(Component.space())
|
||||
.append(Component.text("»").color(NamedTextColor.GRAY))
|
||||
.append(Component.space())
|
||||
|
@ -1,14 +1,18 @@
|
||||
package dev.plex.listener.impl;
|
||||
|
||||
import dev.plex.cache.DataUtils;
|
||||
import dev.plex.cache.player.PlayerCache;
|
||||
import dev.plex.command.blocker.BaseCommand;
|
||||
import dev.plex.command.blocker.MatchCommand;
|
||||
import dev.plex.command.blocker.RegexCommand;
|
||||
import dev.plex.cache.PlayerCache;
|
||||
import dev.plex.command.blocking.BlockedCommand;
|
||||
import dev.plex.listener.PlexListener;
|
||||
import dev.plex.player.PlexPlayer;
|
||||
import dev.plex.util.PlexUtils;
|
||||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||
import dev.plex.rank.enums.Rank;
|
||||
import dev.plex.services.impl.CommandBlockerService;
|
||||
import dev.plex.util.PlexLog;
|
||||
import java.util.Locale;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.entity.Player;
|
||||
@ -30,44 +34,100 @@ public class CommandListener extends PlexListener
|
||||
pl.sendMessage(ChatColor.GRAY + player.getName() + ": " + command);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
if (!plugin.getCommandBlockerManager().loadedYet)
|
||||
{
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
@EventHandler(priority = EventPriority.HIGHEST)
|
||||
public void onCommandBlocking(PlayerCommandPreprocessEvent event)
|
||||
{
|
||||
Player player = event.getPlayer();
|
||||
String message = event.getMessage().substring(1).stripLeading(); // stripLeading() is VITAL for workaround blocking (/ minecraft:summon)
|
||||
for (BaseCommand blockedCommand : plugin.getCommandBlockerManager().getBlockedCommands())
|
||||
PlexPlayer plexPlayer = DataUtils.getPlayer(player.getUniqueId());
|
||||
String commandName = StringUtils.normalizeSpace(event.getMessage()).split(" ")[0].replaceFirst("/", "");
|
||||
String arguments = StringUtils.normalizeSpace(StringUtils.normalizeSpace(event.getMessage()).replace(event.getMessage().split(" ")[0], ""));
|
||||
PlexLog.debug("Checking Command: {0} with args {1}", commandName, arguments);
|
||||
AtomicReference<BlockedCommand> cmdRef = new AtomicReference<>();
|
||||
PlexLog.debug("Blocked Commands List: " + CommandBlockerService.getBLOCKED_COMMANDS().size());
|
||||
CommandBlockerService.getBLOCKED_COMMANDS().stream().filter(blockedCommand -> blockedCommand.getCommand() != null).forEach(blockedCommand ->
|
||||
{
|
||||
PlexPlayer plexPlayer = DataUtils.getPlayer(player.getUniqueId());
|
||||
if (blockedCommand.getRank() != null && plexPlayer.getRankFromString().isAtLeast(blockedCommand.getRank()))
|
||||
boolean matches = true;
|
||||
String[] args = blockedCommand.getCommand().split(" ");
|
||||
String[] cmdArgs = event.getMessage().replaceFirst("/", "").split(" ");
|
||||
for (int i = 0; i < args.length; i++)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
boolean isBlocked = false;
|
||||
if (blockedCommand instanceof RegexCommand regexCommand)
|
||||
{
|
||||
if (regexCommand.getRegex().matcher(message).lookingAt())
|
||||
if (i + 1 > cmdArgs.length)
|
||||
{
|
||||
isBlocked = true;
|
||||
matches = false;
|
||||
break;
|
||||
}
|
||||
if (!args[i].equalsIgnoreCase(cmdArgs[i]))
|
||||
{
|
||||
matches = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
else if (blockedCommand instanceof MatchCommand matchCommand)
|
||||
if (matches)
|
||||
{
|
||||
if (message.toLowerCase().startsWith(matchCommand.getMatch().toLowerCase()))
|
||||
{
|
||||
isBlocked = true;
|
||||
}
|
||||
}
|
||||
if (isBlocked)
|
||||
{
|
||||
event.setCancelled(true);
|
||||
//PlexLog.debug("Command blocked.");
|
||||
player.sendMessage(MiniMessage.miniMessage().deserialize(PlexUtils.messageString("blockedCommandColor") + blockedCommand.getMessage()));
|
||||
PlexLog.debug("Used blocked command exactly matched");
|
||||
cmdRef.set(blockedCommand);
|
||||
return;
|
||||
}
|
||||
if (blockedCommand.getCommandAliases().stream().anyMatch(s -> s.equalsIgnoreCase(commandName)))
|
||||
{
|
||||
PlexLog.debug("Found a command name in a blocked command alias, checking arguments now.");
|
||||
String[] commandArgs = blockedCommand.getCommand().split(" ");
|
||||
if (arguments.toLowerCase(Locale.ROOT).startsWith(StringUtils.join(commandArgs, " ", 1, commandArgs.length).toLowerCase(Locale.ROOT)))
|
||||
{
|
||||
PlexLog.debug("Player attempted to use a blocked command with an alias.");
|
||||
cmdRef.set(blockedCommand);
|
||||
return;
|
||||
}
|
||||
}
|
||||
});
|
||||
if (cmdRef.get() == null)
|
||||
{
|
||||
CommandBlockerService.getBLOCKED_COMMANDS().forEach(blockedCommand ->
|
||||
{
|
||||
if (blockedCommand.getRegex() != null)
|
||||
{
|
||||
Pattern pattern = Pattern.compile(blockedCommand.getRegex(), Pattern.CASE_INSENSITIVE);
|
||||
Matcher matcher = pattern.matcher(event.getMessage().replaceFirst("/", ""));
|
||||
if (matcher.find())
|
||||
{
|
||||
PlexLog.debug("Player attempted to use a blocked regex");
|
||||
cmdRef.set(blockedCommand);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
if (cmdRef.get() != null)
|
||||
{
|
||||
BlockedCommand cmd = cmdRef.get();
|
||||
switch (cmd.getRequiredLevel().toLowerCase(Locale.ROOT))
|
||||
{
|
||||
case "e" ->
|
||||
{
|
||||
event.setCancelled(true);
|
||||
event.getPlayer().sendMessage(cmd.getMessage());
|
||||
}
|
||||
case "a" ->
|
||||
{
|
||||
if (plexPlayer.isAdminActive() && plexPlayer.getRankFromString().isAtLeast(Rank.ADMIN))
|
||||
{
|
||||
return;
|
||||
}
|
||||
event.setCancelled(true);
|
||||
event.getPlayer().sendMessage(cmd.getMessage());
|
||||
}
|
||||
case "s" ->
|
||||
{
|
||||
if (plexPlayer.isAdminActive() && plexPlayer.getRankFromString().isAtLeast(Rank.SENIOR_ADMIN))
|
||||
{
|
||||
return;
|
||||
}
|
||||
event.setCancelled(true);
|
||||
event.getPlayer().sendMessage(cmd.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -9,6 +9,9 @@ public class DropListener extends PlexListener
|
||||
@EventHandler
|
||||
public void onPlayerDropItem(PlayerDropItemEvent event)
|
||||
{
|
||||
if (!plugin.config.getBoolean("allowdrops")) event.setCancelled(true);
|
||||
if (!plugin.config.getBoolean("allowdrops"))
|
||||
{
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,13 +1,18 @@
|
||||
package dev.plex.listener.impl;
|
||||
|
||||
import dev.plex.cache.DataUtils;
|
||||
import dev.plex.cache.player.PlayerCache;
|
||||
import dev.plex.cache.PlayerCache;
|
||||
import dev.plex.listener.PlexListener;
|
||||
import dev.plex.player.PlexPlayer;
|
||||
import dev.plex.storage.StorageType;
|
||||
import dev.plex.util.PermissionsUtil;
|
||||
import dev.plex.util.PlexLog;
|
||||
import dev.plex.util.PlexUtils;
|
||||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.event.ClickEvent;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
@ -17,10 +22,7 @@ import org.bukkit.event.inventory.InventoryCloseEvent;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
import org.bukkit.event.player.PlayerQuitEvent;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
public class PlayerListener extends PlexListener
|
||||
public class PlayerListener<T> extends PlexListener
|
||||
{
|
||||
// setting up a player's data
|
||||
@EventHandler(priority = EventPriority.HIGHEST)
|
||||
@ -73,20 +75,28 @@ public class PlayerListener extends PlexListener
|
||||
player.openInventory(player.getInventory());
|
||||
}
|
||||
|
||||
assert plexPlayer != null;
|
||||
String loginMessage = plugin.getRankManager().getLoginMessage(plexPlayer);
|
||||
if (!loginMessage.isEmpty())
|
||||
{
|
||||
PlexUtils.broadcast(MiniMessage.miniMessage().deserialize("<aqua>" + player.getName() + " is " + loginMessage));
|
||||
PlexUtils.broadcast(PlexUtils.mmDeserialize("<aqua>" + player.getName() + " is " + loginMessage));
|
||||
}
|
||||
|
||||
PermissionsUtil.setupPermissions(player);
|
||||
|
||||
if (plugin.getStorageType() != StorageType.MONGODB)
|
||||
{
|
||||
plexPlayer.loadNotes().whenComplete((notes, throwable) ->
|
||||
{
|
||||
//TODO: Send note messages to admins
|
||||
});
|
||||
plexPlayer.loadNotes();
|
||||
}
|
||||
|
||||
plugin.getSqlNotes().getNotes(plexPlayer.getUuid()).whenComplete((notes, ex) ->
|
||||
{
|
||||
String plural = notes.size() == 1 ? "note." : "notes.";
|
||||
if (!notes.isEmpty())
|
||||
{
|
||||
PlexUtils.broadcastToAdmins(Component.text(plexPlayer.getName() + " has " + notes.size() + " " + plural).color(NamedTextColor.GOLD));
|
||||
PlexUtils.broadcastToAdmins(Component.text("Click to view their " + plural).clickEvent(ClickEvent.runCommand("/notes " + plexPlayer.getName() + " list")).color(NamedTextColor.GOLD));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// saving the player's data
|
||||
|
@ -3,9 +3,11 @@ package dev.plex.listener.impl;
|
||||
import com.destroystokyo.paper.event.server.PaperServerListPingEvent;
|
||||
import dev.plex.listener.PlexListener;
|
||||
import dev.plex.util.PlexUtils;
|
||||
import dev.plex.util.RandomUtil;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
import java.util.stream.Collectors;
|
||||
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.event.EventHandler;
|
||||
|
||||
@ -20,16 +22,17 @@ public class ServerListener extends PlexListener
|
||||
baseMotd = baseMotd.replace("%mcversion%", Bukkit.getBukkitVersion().split("-")[0]);
|
||||
if (plugin.config.getBoolean("server.colorize_motd"))
|
||||
{
|
||||
final StringBuilder motd = new StringBuilder();
|
||||
AtomicReference<Component> motd = new AtomicReference<>(Component.empty());
|
||||
for (final String word : baseMotd.split(" "))
|
||||
{
|
||||
motd.append(PlexUtils.randomChatColor()).append(word).append(" ");
|
||||
motd.set(motd.get().append(Component.text(word).color(RandomUtil.getRandomColor())));
|
||||
motd.set(motd.get().append(Component.space()));
|
||||
}
|
||||
event.motd(LegacyComponentSerializer.legacyAmpersand().deserialize(motd.toString().trim()));
|
||||
event.motd(motd.get());
|
||||
}
|
||||
else
|
||||
{
|
||||
event.motd(LegacyComponentSerializer.legacyAmpersand().deserialize(baseMotd.trim()));
|
||||
event.motd(PlexUtils.mmDeserialize(baseMotd.trim()));
|
||||
}
|
||||
if (plugin.config.contains("server.sample"))
|
||||
{
|
||||
|
@ -2,6 +2,9 @@ package dev.plex.listener.impl;
|
||||
|
||||
import dev.plex.listener.PlexListener;
|
||||
import dev.plex.util.PlexUtils;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
@ -20,10 +23,6 @@ import org.bukkit.event.player.PlayerInteractEntityEvent;
|
||||
import org.bukkit.event.player.PlayerInteractEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
public class SpawnListener extends PlexListener
|
||||
{
|
||||
private static final List<Material> SPAWN_EGGS = Arrays.stream(Material.values()).filter((mat) -> mat.name().endsWith("_SPAWN_EGG")).toList();
|
||||
@ -39,7 +38,7 @@ public class SpawnListener extends PlexListener
|
||||
return;
|
||||
}
|
||||
|
||||
if (plugin.config.getStringList("blockedEntities").stream().anyMatch(type -> type.equalsIgnoreCase(event.getEntityType().name())))
|
||||
if (plugin.config.getStringList("blocked_entities").stream().anyMatch(type -> type.equalsIgnoreCase(event.getEntityType().name())))
|
||||
{
|
||||
event.setCancelled(true);
|
||||
Location location = event.getLocation();
|
||||
@ -56,7 +55,7 @@ public class SpawnListener extends PlexListener
|
||||
if (SPAWN_EGGS.contains(itemType))
|
||||
{
|
||||
Block block = event.getBlock();
|
||||
Location blockLoc = block.getLocation().add(0.5,0.5,0.5).add(((Directional) block.getBlockData()).getFacing().getDirection().multiply(0.8));
|
||||
Location blockLoc = block.getLocation().add(0.5, 0.5, 0.5).add(((Directional)block.getBlockData()).getFacing().getDirection().multiply(0.8));
|
||||
EntityType eggType = spawnEggToEntityType(itemType);
|
||||
if (eggType != null)
|
||||
{
|
||||
@ -109,7 +108,8 @@ public class SpawnListener extends PlexListener
|
||||
}
|
||||
}
|
||||
|
||||
private static EntityType spawnEggToEntityType(Material mat){
|
||||
private static EntityType spawnEggToEntityType(Material mat)
|
||||
{
|
||||
EntityType eggType;
|
||||
try
|
||||
{
|
||||
|
@ -2,7 +2,7 @@ package dev.plex.listener.impl;
|
||||
|
||||
import dev.plex.Plex;
|
||||
import dev.plex.cache.DataUtils;
|
||||
import dev.plex.cache.player.PlayerCache;
|
||||
import dev.plex.cache.PlayerCache;
|
||||
import dev.plex.listener.PlexListener;
|
||||
import dev.plex.player.PlexPlayer;
|
||||
import dev.plex.rank.enums.Rank;
|
||||
@ -12,102 +12,44 @@ import dev.plex.util.PlexUtils;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.PluginIdentifiableCommand;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.block.BlockBreakEvent;
|
||||
import org.bukkit.event.block.BlockPlaceEvent;
|
||||
import org.bukkit.event.entity.EntitySpawnEvent;
|
||||
import org.bukkit.event.player.PlayerChangedWorldEvent;
|
||||
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
|
||||
import org.bukkit.event.player.PlayerTeleportEvent;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class WorldListener extends PlexListener
|
||||
{
|
||||
private final List<String> EDIT_COMMANDS = Arrays.asList("bigtree", "ebigtree", "largetree", "elargetree",
|
||||
"break", "ebreak", "antioch", "nuke", "editsign", "tree", "etree");
|
||||
|
||||
@EventHandler
|
||||
public void onBlockPlace(BlockPlaceEvent e)
|
||||
{
|
||||
Player player = e.getPlayer();
|
||||
PlexPlayer plexPlayer = PlayerCache.getPlexPlayerMap().get(player.getUniqueId());
|
||||
World world = player.getWorld();
|
||||
if (plugin.getSystem().equalsIgnoreCase("permissions"))
|
||||
if (!checkPermission(e.getPlayer(), true))
|
||||
{
|
||||
String permission = plugin.config.getString("worlds." + world.getName().toLowerCase() + ".permission");
|
||||
if (permission == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (player.hasPermission(permission))
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
else if (plugin.getSystem().equalsIgnoreCase("ranks"))
|
||||
{
|
||||
if (plugin.config.contains("worlds." + world.getName().toLowerCase() + ".requiredLevels"))
|
||||
{
|
||||
@NotNull List<String> requiredLevel = plugin.config.getStringList("worlds." + world.getName().toLowerCase() + ".requiredLevels");
|
||||
if (checkLevel(plexPlayer, requiredLevel.toArray(String[]::new)))
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
e.setCancelled(true);
|
||||
String noEdit = plugin.config.getString("worlds." + world.getName().toLowerCase() + ".noEdit");
|
||||
if (noEdit != null)
|
||||
{
|
||||
player.sendMessage(LegacyComponentSerializer.legacyAmpersand().deserialize(noEdit));
|
||||
e.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onBlockBreak(BlockBreakEvent e)
|
||||
{
|
||||
Player player = e.getPlayer();
|
||||
PlexPlayer plexPlayer = PlayerCache.getPlexPlayerMap().get(player.getUniqueId());
|
||||
World world = player.getWorld();
|
||||
if (plugin.getSystem().equalsIgnoreCase("permissions"))
|
||||
if (!checkPermission(e.getPlayer(), true))
|
||||
{
|
||||
String permission = plugin.config.getString("worlds." + world.getName().toLowerCase() + ".permission");
|
||||
if (permission == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (player.hasPermission(permission))
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
else if (plugin.getSystem().equalsIgnoreCase("ranks"))
|
||||
{
|
||||
if (plugin.config.contains("worlds." + world.getName().toLowerCase() + ".requiredLevels"))
|
||||
{
|
||||
@NotNull List<String> requiredLevel = plugin.config.getStringList("worlds." + world.getName().toLowerCase() + ".requiredLevels");
|
||||
if (checkLevel(plexPlayer, requiredLevel.toArray(String[]::new)))
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
e.setCancelled(true);
|
||||
String noEdit = plugin.config.getString("worlds." + world.getName().toLowerCase() + ".noEdit");
|
||||
if (noEdit != null)
|
||||
{
|
||||
player.sendMessage(LegacyComponentSerializer.legacyAmpersand().deserialize(noEdit));
|
||||
e.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
@ -121,6 +63,32 @@ public class WorldListener extends PlexListener
|
||||
e.setCancelled(true);
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST)
|
||||
public void onPlayerCommandPreprocess(PlayerCommandPreprocessEvent event)
|
||||
{
|
||||
// If the person has permission to modify the world, we don't need to block WorldEdit
|
||||
if (checkPermission(event.getPlayer(), false))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
String message = event.getMessage();
|
||||
// Don't check the arguments
|
||||
message = message.replaceAll("\\s.*", "").replaceFirst("/", "");
|
||||
Command command = Bukkit.getCommandMap().getCommand(message);
|
||||
if (command != null)
|
||||
{
|
||||
// This does check for aliases
|
||||
boolean isWeCommand = command instanceof PluginIdentifiableCommand && ((PluginIdentifiableCommand)command).getPlugin().equals(Bukkit.getPluginManager().getPlugin("WorldEdit"));
|
||||
boolean isFaweCommand = command instanceof PluginIdentifiableCommand && ((PluginIdentifiableCommand)command).getPlugin().equals(Bukkit.getPluginManager().getPlugin("FastAsyncWorldEdit"));
|
||||
if (isWeCommand || isFaweCommand || EDIT_COMMANDS.contains(message.toLowerCase()))
|
||||
{
|
||||
event.getPlayer().sendMessage(Component.text("You do not have permission to use that command in this world.").color(NamedTextColor.RED));
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: Add an entry setting in the config.yml and allow checking for all worlds
|
||||
@EventHandler
|
||||
public void onWorldTeleport(PlayerTeleportEvent e)
|
||||
@ -137,7 +105,7 @@ public class WorldListener extends PlexListener
|
||||
{
|
||||
e.setCancelled(true);
|
||||
}
|
||||
else if (plugin.getSystem().equals("permissions") && !e.getPlayer().hasPermission("plex.enter.adminworld"))
|
||||
else if (plugin.getSystem().equals("permissions") && !e.getPlayer().hasPermission("plex.adminworld.enter"))
|
||||
{
|
||||
e.setCancelled(true);
|
||||
}
|
||||
@ -157,16 +125,20 @@ public class WorldListener extends PlexListener
|
||||
Title title = Title.valueOf(titleString.toUpperCase(Locale.ROOT));
|
||||
switch (title)
|
||||
{
|
||||
case DEV -> {
|
||||
case DEV ->
|
||||
{
|
||||
hasAccess = PlexUtils.DEVELOPERS.contains(player.getUuid().toString());
|
||||
}
|
||||
case MASTER_BUILDER -> {
|
||||
case MASTER_BUILDER ->
|
||||
{
|
||||
hasAccess = Plex.get().config.contains("titles.masterbuilders") && Plex.get().config.getStringList("titles.masterbuilders").contains(player.getName());
|
||||
}
|
||||
case OWNER -> {
|
||||
case OWNER ->
|
||||
{
|
||||
hasAccess = Plex.get().config.contains("titles.owners") && Plex.get().config.getStringList("titles.owners").contains(player.getName());
|
||||
}
|
||||
default -> {
|
||||
default ->
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@ -180,4 +152,47 @@ public class WorldListener extends PlexListener
|
||||
}
|
||||
return hasAccess;
|
||||
}
|
||||
|
||||
private boolean checkPermission(Player player, boolean showMessage)
|
||||
{
|
||||
PlexPlayer plexPlayer = PlayerCache.getPlexPlayerMap().get(player.getUniqueId());
|
||||
World world = player.getWorld();
|
||||
if (plugin.getSystem().equalsIgnoreCase("permissions"))
|
||||
{
|
||||
String permission = plugin.config.getString("plex." + world.getName().toLowerCase() + ".permission");
|
||||
if (permission == null)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
if (player.hasPermission(permission))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
else if (plugin.getSystem().equalsIgnoreCase("ranks"))
|
||||
{
|
||||
if (plugin.config.contains("worlds." + world.getName().toLowerCase() + ".requiredLevels"))
|
||||
{
|
||||
@NotNull List<String> requiredLevel = plugin.config.getStringList("worlds." + world.getName().toLowerCase() + ".requiredLevels");
|
||||
if (checkLevel(plexPlayer, requiredLevel.toArray(String[]::new)))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
if (showMessage)
|
||||
{
|
||||
String noEdit = plugin.config.getString("worlds." + world.getName().toLowerCase() + ".noEdit");
|
||||
if (noEdit != null)
|
||||
{
|
||||
player.sendMessage(LegacyComponentSerializer.legacyAmpersand().deserialize(noEdit));
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
@ -2,9 +2,10 @@ package dev.plex.menu;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import dev.plex.cache.DataUtils;
|
||||
import dev.plex.cache.player.PlayerCache;
|
||||
import dev.plex.cache.PlayerCache;
|
||||
import dev.plex.player.PlexPlayer;
|
||||
import dev.plex.punishment.Punishment;
|
||||
import dev.plex.util.PlexUtils;
|
||||
import dev.plex.util.menu.AbstractMenu;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
@ -34,7 +35,7 @@ public class PunishedPlayerMenu extends AbstractMenu
|
||||
this.punishedPlayer = player;
|
||||
for (int i = 0; i <= punishedPlayer.getPunishments().size() / 53; i++)
|
||||
{
|
||||
Inventory inventory = Bukkit.createInventory(null, 54, "Punishments Page " + (i + 1));
|
||||
Inventory inventory = Bukkit.createInventory(null, 54, PlexUtils.mmDeserialize("Punishments Page " + (i + 1)));
|
||||
ItemStack nextPage = new ItemStack(Material.FEATHER);
|
||||
ItemMeta meta = nextPage.getItemMeta();
|
||||
meta.displayName(Component.text("Next Page").color(NamedTextColor.LIGHT_PURPLE));
|
||||
|
@ -3,6 +3,7 @@ package dev.plex.menu;
|
||||
import com.google.common.collect.Lists;
|
||||
import dev.plex.cache.DataUtils;
|
||||
import dev.plex.player.PlexPlayer;
|
||||
import dev.plex.util.PlexUtils;
|
||||
import dev.plex.util.menu.AbstractMenu;
|
||||
import java.util.List;
|
||||
import org.bukkit.Bukkit;
|
||||
@ -27,15 +28,15 @@ public class PunishmentMenu extends AbstractMenu
|
||||
super("§c§lPunishments");
|
||||
for (int i = 0; i <= Bukkit.getOnlinePlayers().size() / 53; i++)
|
||||
{
|
||||
Inventory inventory = Bukkit.createInventory(null, 54, "Punishments Page " + (i + 1));
|
||||
Inventory inventory = Bukkit.createInventory(null, 54, PlexUtils.mmDeserialize("Punishments Page " + (i + 1)));
|
||||
ItemStack nextPage = new ItemStack(Material.FEATHER);
|
||||
ItemMeta meta = nextPage.getItemMeta();
|
||||
meta.setDisplayName(ChatColor.LIGHT_PURPLE + "Next Page");
|
||||
meta.displayName(PlexUtils.mmDeserialize("<light_purple>Next Page"));
|
||||
nextPage.setItemMeta(meta);
|
||||
|
||||
ItemStack previousPage = new ItemStack(Material.FEATHER);
|
||||
ItemMeta meta2 = previousPage.getItemMeta();
|
||||
meta2.setDisplayName(ChatColor.LIGHT_PURPLE + "Previous Page");
|
||||
meta2.displayName(PlexUtils.mmDeserialize("<light_purple>Previous Page"));
|
||||
previousPage.setItemMeta(meta2);
|
||||
|
||||
inventory.setItem(50, nextPage);
|
||||
@ -72,7 +73,7 @@ public class PunishmentMenu extends AbstractMenu
|
||||
ItemStack item = new ItemStack(Material.PLAYER_HEAD);
|
||||
SkullMeta meta = (SkullMeta)item.getItemMeta();
|
||||
meta.setOwningPlayer(players);
|
||||
meta.setDisplayName(ChatColor.YELLOW + players.getName());
|
||||
meta.displayName(PlexUtils.mmDeserialize("<!italic><yellow>" + players.getName()));
|
||||
item.setItemMeta(meta);
|
||||
|
||||
inv.setItem(currentItemIndex, item);
|
||||
@ -98,11 +99,19 @@ public class PunishmentMenu extends AbstractMenu
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (!event.getCurrentItem().hasItemMeta())
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (!event.getCurrentItem().getItemMeta().hasDisplayName())
|
||||
{
|
||||
return;
|
||||
}
|
||||
ItemStack item = event.getCurrentItem();
|
||||
event.setCancelled(true);
|
||||
if (item.getType() == Material.FEATHER)
|
||||
{
|
||||
if (item.getItemMeta().getDisplayName().equalsIgnoreCase(ChatColor.LIGHT_PURPLE + "Next Page"))
|
||||
if (item.getItemMeta().displayName().equals(PlexUtils.mmDeserialize("<light_purple>Next Page")))
|
||||
{
|
||||
if (getCurrentInventoryIndex(inv) + 1 > inventories.size() - 1)
|
||||
{
|
||||
@ -114,7 +123,7 @@ public class PunishmentMenu extends AbstractMenu
|
||||
}
|
||||
openInv((Player)event.getWhoClicked(), getCurrentInventoryIndex(inv) + 1);
|
||||
}
|
||||
else if (item.getItemMeta().getDisplayName().equalsIgnoreCase(ChatColor.LIGHT_PURPLE + "Previous Page"))
|
||||
else if (item.getItemMeta().displayName().equals(PlexUtils.mmDeserialize("<light_purple>Previous Page")))
|
||||
{
|
||||
if (getCurrentInventoryIndex(inv) - 1 < 0)
|
||||
{
|
||||
|
@ -82,7 +82,8 @@ public class ModuleManager
|
||||
plexModule.setLogger(LogManager.getLogger(plexModuleFile.getName()));
|
||||
modules.add(plexModule);
|
||||
}
|
||||
catch (MalformedURLException | ClassNotFoundException | InvocationTargetException | InstantiationException | IllegalAccessException | NoSuchMethodException e)
|
||||
catch (MalformedURLException | ClassNotFoundException | InvocationTargetException |
|
||||
InstantiationException | IllegalAccessException | NoSuchMethodException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
@ -47,7 +47,6 @@ import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public class LibraryLoader
|
||||
{
|
||||
|
||||
private final Logger logger;
|
||||
private final RepositorySystem repository;
|
||||
private final DefaultRepositorySystemSession session;
|
||||
|
14
src/main/java/dev/plex/permission/Permission.java
Normal file
14
src/main/java/dev/plex/permission/Permission.java
Normal file
@ -0,0 +1,14 @@
|
||||
package dev.plex.permission;
|
||||
|
||||
import dev.morphia.annotations.Entity;
|
||||
import java.util.UUID;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
@Entity
|
||||
public class Permission
|
||||
{
|
||||
private final UUID uuid;
|
||||
private final String permission;
|
||||
private boolean allowed = true;
|
||||
}
|
@ -7,18 +7,18 @@ import dev.morphia.annotations.Id;
|
||||
import dev.morphia.annotations.IndexOptions;
|
||||
import dev.morphia.annotations.Indexed;
|
||||
import dev.plex.Plex;
|
||||
import dev.plex.permission.Permission;
|
||||
import dev.plex.punishment.Punishment;
|
||||
import dev.plex.punishment.extra.Note;
|
||||
import dev.plex.rank.enums.Rank;
|
||||
import dev.plex.storage.StorageType;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.ZonedDateTime;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import dev.plex.util.adapter.LocalDateTimeSerializer;
|
||||
import dev.plex.util.adapter.ZonedDateTimeSerializer;
|
||||
import lombok.AccessLevel;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
@ -26,6 +26,7 @@ import net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.permissions.PermissionAttachment;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@ -64,6 +65,9 @@ public class PlexPlayer
|
||||
private List<String> ips = Lists.newArrayList();
|
||||
private List<Punishment> punishments = Lists.newArrayList();
|
||||
private List<Note> notes = Lists.newArrayList();
|
||||
private List<Permission> permissions = Lists.newArrayList();
|
||||
|
||||
private transient PermissionAttachment permissionAttachment;
|
||||
|
||||
public PlexPlayer()
|
||||
{
|
||||
@ -88,6 +92,10 @@ public class PlexPlayer
|
||||
|
||||
this.rank = "";
|
||||
this.loadPunishments();
|
||||
if (Plex.get().getStorageType() != StorageType.MONGODB)
|
||||
{
|
||||
this.permissions.addAll(Plex.get().getSqlPermissions().getPermissions(this.uuid));
|
||||
}
|
||||
}
|
||||
|
||||
public String displayName()
|
||||
@ -119,7 +127,7 @@ public class PlexPlayer
|
||||
{
|
||||
if (Plex.get().getStorageType() != StorageType.MONGODB)
|
||||
{
|
||||
this.setPunishments(Plex.get().getSqlPunishment().getPunishments(this.getUuid()).stream().filter(punishment -> punishment.getPunished().equals(this.getUuid())).collect(Collectors.toList()));
|
||||
this.setPunishments(Plex.get().getSqlPunishment().getPunishments(this.getUuid()));
|
||||
}
|
||||
}
|
||||
|
||||
@ -134,6 +142,6 @@ public class PlexPlayer
|
||||
|
||||
public String toJSON()
|
||||
{
|
||||
return new GsonBuilder().registerTypeAdapter(LocalDateTime.class, new LocalDateTimeSerializer()).create().toJson(this);
|
||||
return new GsonBuilder().registerTypeAdapter(ZonedDateTime.class, new ZonedDateTimeSerializer()).create().toJson(this);
|
||||
}
|
||||
}
|
||||
|
@ -5,11 +5,12 @@ import dev.morphia.annotations.Entity;
|
||||
import dev.plex.Plex;
|
||||
import dev.plex.util.MojangUtils;
|
||||
import dev.plex.util.PlexUtils;
|
||||
import dev.plex.util.adapter.LocalDateTimeDeserializer;
|
||||
import dev.plex.util.adapter.LocalDateTimeSerializer;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import dev.plex.util.TimeUtils;
|
||||
import java.time.ZonedDateTime;
|
||||
import java.util.UUID;
|
||||
|
||||
import dev.plex.util.adapter.ZonedDateTimeDeserializer;
|
||||
import dev.plex.util.adapter.ZonedDateTimeSerializer;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import net.kyori.adventure.text.Component;
|
||||
@ -20,7 +21,6 @@ import net.kyori.adventure.text.Component;
|
||||
public class Punishment
|
||||
{
|
||||
private static final String banUrl = Plex.get().config.getString("banning.ban_url");
|
||||
private static final DateTimeFormatter DATE_FORMAT = DateTimeFormatter.ofPattern("MM/dd/yyyy 'at' hh:mm:ss a");
|
||||
private final UUID punished;
|
||||
private final UUID punisher;
|
||||
private String ip;
|
||||
@ -29,7 +29,7 @@ public class Punishment
|
||||
private String reason;
|
||||
private boolean customTime;
|
||||
private boolean active; // Field is only for bans
|
||||
private LocalDateTime endDate;
|
||||
private ZonedDateTime endDate;
|
||||
|
||||
public Punishment()
|
||||
{
|
||||
@ -45,8 +45,7 @@ public class Punishment
|
||||
|
||||
public static Component generateBanMessage(Punishment punishment)
|
||||
{
|
||||
return PlexUtils.messageComponent("banMessage", banUrl, punishment.getReason(),
|
||||
DATE_FORMAT.format(punishment.getEndDate()), punishment.getPunisher() == null ? "CONSOLE" : MojangUtils.getInfo(punishment.getPunisher().toString()).getUsername());
|
||||
return PlexUtils.messageComponent("banMessage", banUrl, punishment.getReason(), TimeUtils.useTimezone(punishment.getEndDate()), punishment.getPunisher() == null ? "CONSOLE" : MojangUtils.getInfo(punishment.getPunisher().toString()).getUsername());
|
||||
}
|
||||
|
||||
public static Component generateIndefBanMessage(String type)
|
||||
@ -56,11 +55,11 @@ public class Punishment
|
||||
|
||||
public static Punishment fromJson(String json)
|
||||
{
|
||||
return new GsonBuilder().registerTypeAdapter(LocalDateTime.class, new LocalDateTimeDeserializer()).create().fromJson(json, Punishment.class);
|
||||
return new GsonBuilder().registerTypeAdapter(ZonedDateTime.class, new ZonedDateTimeDeserializer()).create().fromJson(json, Punishment.class);
|
||||
}
|
||||
|
||||
public String toJSON()
|
||||
{
|
||||
return new GsonBuilder().registerTypeAdapter(LocalDateTime.class, new LocalDateTimeSerializer()).create().toJson(this);
|
||||
return new GsonBuilder().registerTypeAdapter(ZonedDateTime.class, new ZonedDateTimeSerializer()).create().toJson(this);
|
||||
}
|
||||
}
|
||||
|
@ -14,19 +14,23 @@ import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.ZoneId;
|
||||
import java.time.ZonedDateTime;
|
||||
import java.time.temporal.ChronoUnit;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import dev.plex.util.TimeUtils;
|
||||
import lombok.Data;
|
||||
import lombok.Getter;
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
|
||||
public class PunishmentManager extends PlexBase
|
||||
public class PunishmentManager implements PlexBase
|
||||
{
|
||||
@Getter
|
||||
private final List<IndefiniteBan> indefiniteBans = Lists.newArrayList();
|
||||
@ -129,17 +133,18 @@ public class PunishmentManager extends PlexBase
|
||||
{
|
||||
PlexPlayer player = DataUtils.getPlayer(uuid);
|
||||
player.loadPunishments();
|
||||
return player.getPunishments().stream().anyMatch(punishment -> punishment.getType() == PunishmentType.BAN && punishment.isActive());
|
||||
return player.getPunishments().stream().anyMatch(punishment -> (punishment.getType() == PunishmentType.BAN || punishment.getType() == PunishmentType.TEMPBAN) && punishment.isActive());
|
||||
});
|
||||
}
|
||||
|
||||
public boolean isBanned(UUID uuid)
|
||||
{
|
||||
// TODO: If a person is using MongoDB, this will error out because it is checking for bans on a player that doesn't exist yet
|
||||
/*if (!DataUtils.hasPlayedBefore(uuid))
|
||||
{
|
||||
return false;
|
||||
}*/
|
||||
return DataUtils.getPlayer(uuid).getPunishments().stream().anyMatch(punishment -> punishment.getType() == PunishmentType.BAN && punishment.isActive());
|
||||
return DataUtils.getPlayer(uuid).getPunishments().stream().anyMatch(punishment -> (punishment.getType() == PunishmentType.BAN || punishment.getType() == PunishmentType.TEMPBAN) && punishment.isActive());
|
||||
}
|
||||
|
||||
public boolean isBanned(PlexPlayer player)
|
||||
@ -154,15 +159,19 @@ public class PunishmentManager extends PlexBase
|
||||
return CompletableFuture.supplyAsync(() ->
|
||||
{
|
||||
List<PlexPlayer> players = Plex.get().getMongoPlayerData().getPlayers();
|
||||
return players.stream().map(PlexPlayer::getPunishments).flatMap(Collection::stream).filter(Punishment::isActive).filter(punishment -> punishment.getType() == PunishmentType.BAN).toList();
|
||||
return players.stream().map(PlexPlayer::getPunishments).flatMap(Collection::stream).filter(Punishment::isActive).filter(punishment -> punishment.getType() == PunishmentType.BAN || punishment.getType() == PunishmentType.TEMPBAN).toList();
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
//PlexLog.debug("Checking active bans mysql");
|
||||
CompletableFuture<List<Punishment>> future = new CompletableFuture<>();
|
||||
Plex.get().getSqlPunishment().getPunishments().whenComplete((punishments, throwable) ->
|
||||
{
|
||||
future.complete(punishments.stream().filter(Punishment::isActive).filter(punishment -> punishment.getType() == PunishmentType.BAN).toList());
|
||||
//PlexLog.debug("Received Punishments");
|
||||
List<Punishment> punishmentList = punishments.stream().filter(Punishment::isActive).filter(punishment -> punishment.getType() == PunishmentType.BAN || punishment.getType() == PunishmentType.TEMPBAN).toList();
|
||||
//PlexLog.debug("Completing with {0} punishments", punishmentList.size());
|
||||
future.complete(punishmentList);
|
||||
});
|
||||
return future;
|
||||
}
|
||||
@ -180,7 +189,7 @@ public class PunishmentManager extends PlexBase
|
||||
return CompletableFuture.runAsync(() ->
|
||||
{
|
||||
PlexPlayer plexPlayer = DataUtils.getPlayer(uuid);
|
||||
plexPlayer.setPunishments(plexPlayer.getPunishments().stream().filter(Punishment::isActive).filter(punishment -> punishment.getType() == PunishmentType.BAN)
|
||||
plexPlayer.setPunishments(plexPlayer.getPunishments().stream().filter(Punishment::isActive).filter(punishment -> punishment.getType() == PunishmentType.BAN || punishment.getType() == PunishmentType.TEMPBAN)
|
||||
.peek(punishment -> punishment.setActive(false)).collect(Collectors.toList()));
|
||||
DataUtils.update(plexPlayer);
|
||||
});
|
||||
@ -196,8 +205,8 @@ public class PunishmentManager extends PlexBase
|
||||
if (punishment.getType() == PunishmentType.FREEZE)
|
||||
{
|
||||
player.setFrozen(true);
|
||||
LocalDateTime now = LocalDateTime.now();
|
||||
LocalDateTime then = punishment.getEndDate();
|
||||
ZonedDateTime now = ZonedDateTime.now(ZoneId.of(TimeUtils.TIMEZONE));
|
||||
ZonedDateTime then = punishment.getEndDate();
|
||||
long seconds = ChronoUnit.SECONDS.between(now, then);
|
||||
new BukkitRunnable()
|
||||
{
|
||||
@ -217,8 +226,8 @@ public class PunishmentManager extends PlexBase
|
||||
else if (punishment.getType() == PunishmentType.MUTE)
|
||||
{
|
||||
player.setMuted(true);
|
||||
LocalDateTime now = LocalDateTime.now();
|
||||
LocalDateTime then = punishment.getEndDate();
|
||||
ZonedDateTime now = ZonedDateTime.now(ZoneId.of(TimeUtils.TIMEZONE));
|
||||
ZonedDateTime then = punishment.getEndDate();
|
||||
long seconds = ChronoUnit.SECONDS.between(now, then);
|
||||
new BukkitRunnable()
|
||||
{
|
||||
|
@ -2,5 +2,5 @@ package dev.plex.punishment;
|
||||
|
||||
public enum PunishmentType
|
||||
{
|
||||
MUTE, FREEZE, BAN, KICK, SMITE
|
||||
MUTE, FREEZE, BAN, KICK, SMITE, TEMPBAN
|
||||
}
|
||||
|
@ -2,12 +2,12 @@ package dev.plex.punishment.extra;
|
||||
|
||||
import com.google.gson.GsonBuilder;
|
||||
import dev.morphia.annotations.Entity;
|
||||
import dev.plex.util.adapter.LocalDateTimeSerializer;
|
||||
import lombok.Data;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.ZonedDateTime;
|
||||
import java.util.UUID;
|
||||
|
||||
import dev.plex.util.adapter.ZonedDateTimeSerializer;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
@Entity
|
||||
public class Note
|
||||
@ -15,12 +15,12 @@ public class Note
|
||||
private final UUID uuid;
|
||||
private final String note;
|
||||
private final UUID writtenBy;
|
||||
private final LocalDateTime timestamp;
|
||||
private final ZonedDateTime timestamp;
|
||||
|
||||
private int id; // This will be automatically set from addNote
|
||||
|
||||
public String toJSON()
|
||||
{
|
||||
return new GsonBuilder().registerTypeAdapter(LocalDateTime.class, new LocalDateTimeSerializer()).create().toJson(this);
|
||||
return new GsonBuilder().registerTypeAdapter(ZonedDateTime.class, new ZonedDateTimeSerializer()).create().toJson(this);
|
||||
}
|
||||
}
|
||||
|
@ -14,7 +14,7 @@ import java.util.stream.Collectors;
|
||||
import lombok.SneakyThrows;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||
import net.kyori.adventure.text.minimessage.tag.standard.StandardTags;
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONObject;
|
||||
import org.json.JSONTokener;
|
||||
@ -95,7 +95,7 @@ public class RankManager
|
||||
{
|
||||
if (!player.getPrefix().equals(""))
|
||||
{
|
||||
return MiniMessage.miniMessage().deserialize(player.getPrefix());
|
||||
return PlexUtils.mmCustomDeserialize(player.getPrefix(), StandardTags.color(), StandardTags.rainbow(), StandardTags.decorations(), StandardTags.gradient(), StandardTags.transition());
|
||||
}
|
||||
if (Plex.get().config.contains("titles.owners") && Plex.get().config.getStringList("titles.owners").contains(player.getName()))
|
||||
{
|
||||
|
@ -1,10 +1,10 @@
|
||||
package dev.plex.rank.enums;
|
||||
|
||||
import dev.plex.util.PlexUtils;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||
import org.json.JSONObject;
|
||||
|
||||
@Getter
|
||||
@ -47,7 +47,7 @@ public enum Rank
|
||||
|
||||
public Component getPrefix()
|
||||
{
|
||||
return MiniMessage.miniMessage().deserialize(this.prefix);
|
||||
return PlexUtils.mmDeserialize(this.prefix);
|
||||
}
|
||||
|
||||
public JSONObject toJSON()
|
||||
|
@ -1,10 +1,10 @@
|
||||
package dev.plex.rank.enums;
|
||||
|
||||
import dev.plex.util.PlexUtils;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||
import org.json.JSONObject;
|
||||
|
||||
@Getter
|
||||
@ -39,7 +39,7 @@ public enum Title
|
||||
|
||||
public Component getPrefix()
|
||||
{
|
||||
return MiniMessage.miniMessage().deserialize(this.prefix);
|
||||
return PlexUtils.mmDeserialize(this.prefix);
|
||||
}
|
||||
|
||||
public JSONObject toJSON()
|
||||
|
@ -5,7 +5,7 @@ import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
@Getter
|
||||
public abstract class AbstractService extends PlexBase implements IService
|
||||
public abstract class AbstractService implements IService, PlexBase
|
||||
{
|
||||
private boolean asynchronous;
|
||||
private boolean repeating;
|
||||
|
@ -2,23 +2,28 @@ package dev.plex.services;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import dev.plex.Plex;
|
||||
import dev.plex.services.impl.*;
|
||||
import dev.plex.services.impl.AutoWipeService;
|
||||
import dev.plex.services.impl.BanService;
|
||||
import dev.plex.services.impl.CommandBlockerService;
|
||||
import dev.plex.services.impl.GameRuleService;
|
||||
import dev.plex.services.impl.TimingService;
|
||||
import dev.plex.services.impl.UpdateCheckerService;
|
||||
import java.util.List;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.scheduler.BukkitTask;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class ServiceManager
|
||||
{
|
||||
private final List<AbstractService> services = Lists.newArrayList();
|
||||
|
||||
public ServiceManager()
|
||||
{
|
||||
registerService(new BanService());
|
||||
registerService(new GameRuleService());
|
||||
registerService(new UpdateCheckerService());
|
||||
registerService(new AutoWipeService());
|
||||
registerService(new BanService());
|
||||
registerService(new CommandBlockerService());
|
||||
registerService(new GameRuleService());
|
||||
registerService(new TimingService());
|
||||
registerService(new UpdateCheckerService());
|
||||
}
|
||||
|
||||
public void startServices()
|
||||
|
@ -2,12 +2,10 @@ package dev.plex.services.impl;
|
||||
|
||||
import dev.plex.Plex;
|
||||
import dev.plex.services.AbstractService;
|
||||
import java.util.List;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.EntityType;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class AutoWipeService extends AbstractService
|
||||
{
|
||||
|
@ -2,7 +2,9 @@ package dev.plex.services.impl;
|
||||
|
||||
import dev.plex.Plex;
|
||||
import dev.plex.services.AbstractService;
|
||||
import java.time.LocalDateTime;
|
||||
import dev.plex.util.TimeUtils;
|
||||
import java.time.ZoneId;
|
||||
import java.time.ZonedDateTime;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.bukkit.Bukkit;
|
||||
|
||||
@ -20,7 +22,7 @@ public class BanService extends AbstractService
|
||||
{
|
||||
punishments.forEach(punishment ->
|
||||
{
|
||||
if (LocalDateTime.now().isAfter(punishment.getEndDate()))
|
||||
if (ZonedDateTime.now(ZoneId.of(TimeUtils.TIMEZONE)).isAfter(punishment.getEndDate()))
|
||||
{
|
||||
Plex.get().getPunishmentManager().unban(punishment);
|
||||
Bukkit.broadcast(Component.text("Plex - Unbanned " + Bukkit.getOfflinePlayer(punishment.getPunished()).getName()));
|
||||
@ -32,7 +34,7 @@ public class BanService extends AbstractService
|
||||
@Override
|
||||
public int repeatInSeconds()
|
||||
{
|
||||
// Every 5 minutes
|
||||
return 300;
|
||||
// Every 30 seconds
|
||||
return 30;
|
||||
}
|
||||
}
|
||||
|
@ -1,20 +1,69 @@
|
||||
package dev.plex.services.impl;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import dev.plex.command.blocking.BlockedCommand;
|
||||
import dev.plex.services.AbstractService;
|
||||
import dev.plex.util.PlexLog;
|
||||
import dev.plex.util.PlexUtils;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import lombok.Getter;
|
||||
import org.bukkit.command.Command;
|
||||
|
||||
public class CommandBlockerService extends AbstractService
|
||||
{
|
||||
@Getter
|
||||
private static final List<BlockedCommand> BLOCKED_COMMANDS = Lists.newArrayList();
|
||||
|
||||
public CommandBlockerService()
|
||||
{
|
||||
super(false, true);
|
||||
super(false, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
plugin.getCommandBlockerManager().syncCommands();
|
||||
PlexLog.log("Command Blocker commands loaded");
|
||||
BLOCKED_COMMANDS.clear();
|
||||
plugin.commands.getStringList("commands").forEach(s ->
|
||||
{
|
||||
BlockedCommand command = new BlockedCommand();
|
||||
int lastDelim = s.lastIndexOf(':');
|
||||
|
||||
String cmdWithoutMsg = s.substring(0, lastDelim);
|
||||
String[] args = cmdWithoutMsg.split(":", 3); // Delimiter code by ayunami
|
||||
if (s.toLowerCase(Locale.ROOT).startsWith("r"))
|
||||
{
|
||||
command.setRequiredLevel(args[1]);
|
||||
command.setRegex(args[2]);
|
||||
command.setMessage(s.substring(lastDelim + 1).equalsIgnoreCase("_") ? PlexUtils.messageComponent("commandBlocked") : PlexUtils.mmDeserialize(s.substring(lastDelim + 1)));
|
||||
/*PlexLog.debug("=Found regex blocked=");
|
||||
PlexLog.debug(" Regex: " + command.getRegex());
|
||||
PlexLog.debug(" Message: " + command.getMessage());
|
||||
PlexLog.debug("====================");*/
|
||||
}
|
||||
else if (s.toLowerCase(Locale.ROOT).startsWith("m"))
|
||||
{
|
||||
command.setRequiredLevel(args[1]);
|
||||
command.setCommand(args[2]);
|
||||
command.setMessage(s.substring(lastDelim + 1).equalsIgnoreCase("_") ? PlexUtils.messageComponent("commandBlocked") : PlexUtils.mmDeserialize(s.substring(lastDelim + 1)));
|
||||
Command cmd = plugin.getServer().getCommandMap().getCommand(command.getCommand().split(" ")[0]);
|
||||
if (cmd == null)
|
||||
{
|
||||
PlexLog.error("Command '{0}' does not belong to any plugin!", command.getCommand().split(" ")[0]);
|
||||
return;
|
||||
}
|
||||
command.setCommandAliases(cmd.getAliases());
|
||||
command.getCommandAliases().add(command.getCommand().split(" ")[0]);
|
||||
/*PlexLog.debug("=Found command blocked=");
|
||||
PlexLog.debug(" Required Level: " + command.getRequiredLevel());
|
||||
PlexLog.debug(" Command: " + command.getCommand());
|
||||
PlexLog.debug(" Message: " + command.getMessage());
|
||||
PlexLog.debug(" Aliases: " + Arrays.toString(command.getCommandAliases().toArray(new String[0])));
|
||||
PlexLog.debug("====================");*/
|
||||
}
|
||||
BLOCKED_COMMANDS.add(command);
|
||||
});
|
||||
PlexLog.log("Command Blocker has loaded {0} entries!", BLOCKED_COMMANDS.size());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -1,6 +1,7 @@
|
||||
package dev.plex.services.impl;
|
||||
|
||||
import dev.plex.services.AbstractService;
|
||||
import dev.plex.util.GameRuleUtil;
|
||||
import dev.plex.util.PlexLog;
|
||||
import dev.plex.util.PlexUtils;
|
||||
import java.util.Locale;
|
||||
@ -19,7 +20,7 @@ public class GameRuleService extends AbstractService
|
||||
{
|
||||
for (World world : Bukkit.getWorlds())
|
||||
{
|
||||
PlexUtils.commitGlobalGameRules(world);
|
||||
GameRuleUtil.commitGlobalGameRules(world);
|
||||
PlexLog.log("Set global gamerules for world: " + world.getName());
|
||||
}
|
||||
for (String world : plugin.config.getConfigurationSection("worlds").getKeys(false))
|
||||
@ -27,7 +28,7 @@ public class GameRuleService extends AbstractService
|
||||
World bukkitWorld = Bukkit.getWorld(world);
|
||||
if (bukkitWorld != null)
|
||||
{
|
||||
PlexUtils.commitSpecificGameRules(bukkitWorld);
|
||||
GameRuleUtil.commitSpecificGameRules(bukkitWorld);
|
||||
PlexLog.log("Set specific gamerules for world: " + world.toLowerCase(Locale.ROOT));
|
||||
}
|
||||
}
|
||||
|
67
src/main/java/dev/plex/services/impl/TimingService.java
Normal file
67
src/main/java/dev/plex/services/impl/TimingService.java
Normal file
@ -0,0 +1,67 @@
|
||||
package dev.plex.services.impl;
|
||||
|
||||
import dev.plex.cache.DataUtils;
|
||||
import dev.plex.player.PlexPlayer;
|
||||
import dev.plex.punishment.Punishment;
|
||||
import dev.plex.punishment.PunishmentType;
|
||||
import dev.plex.services.AbstractService;
|
||||
import dev.plex.util.PlexLog;
|
||||
import dev.plex.util.TimeUtils;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class TimingService extends AbstractService
|
||||
{
|
||||
public static final Map<UUID, Long> spamCooldown = new HashMap<>();
|
||||
public static final Map<UUID, Long> nukerCooldown = new HashMap<>();
|
||||
public static final Map<UUID, Long> strikes = new HashMap<>();
|
||||
|
||||
public TimingService()
|
||||
{
|
||||
super(true, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
spamCooldown.clear();
|
||||
nukerCooldown.clear();
|
||||
for (Map.Entry<UUID, Long> map : strikes.entrySet())
|
||||
{
|
||||
PlexLog.debug(map.getKey() + ": " + map.getValue());
|
||||
// Tempban for 5 minutes and reset strikes. This will probably stop people from actually trying to use a Nuker to grief.
|
||||
if (map.getValue() >= 2L)
|
||||
{
|
||||
issueBan(map);
|
||||
strikes.remove(map.getKey());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void issueBan(Map.Entry<UUID, Long> map)
|
||||
{
|
||||
Punishment punishment = new Punishment(map.getKey(), null);
|
||||
Player player = Bukkit.getPlayer(map.getKey());
|
||||
PlexPlayer plexPlayer = DataUtils.getPlayer(map.getKey());
|
||||
punishment.setType(PunishmentType.TEMPBAN);
|
||||
punishment.setReason("You are temporarily banned for five minutes for using a Nuker.");
|
||||
if (player != null)
|
||||
{
|
||||
punishment.setPunishedUsername(player.getName());
|
||||
punishment.setIp(player.getAddress().getAddress().getHostAddress());
|
||||
}
|
||||
punishment.setEndDate(TimeUtils.createDate("5m"));
|
||||
punishment.setCustomTime(false);
|
||||
punishment.setActive(!plexPlayer.isAdminActive());
|
||||
plugin.getPunishmentManager().punish(plexPlayer, punishment);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int repeatInSeconds()
|
||||
{
|
||||
return 5;
|
||||
}
|
||||
}
|
@ -1,6 +1,5 @@
|
||||
package dev.plex.storage;
|
||||
|
||||
import com.mongodb.*;
|
||||
import com.mongodb.client.MongoClient;
|
||||
import com.mongodb.client.MongoClients;
|
||||
import dev.morphia.Datastore;
|
||||
@ -10,7 +9,7 @@ import dev.plex.PlexBase;
|
||||
import dev.plex.player.PlexPlayer;
|
||||
import dev.plex.util.PlexLog;
|
||||
|
||||
public class MongoConnection extends PlexBase
|
||||
public class MongoConnection implements PlexBase
|
||||
{
|
||||
// USE MORPHIA API FOR MONGO <3
|
||||
|
||||
@ -32,10 +31,14 @@ public class MongoConnection extends PlexBase
|
||||
if (database != null && !database.isEmpty())
|
||||
{
|
||||
connectionString = "mongodb://" + username + ":" + password + "@" + host + ":" + port + "/?authSource=" + database;
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
connectionString = "mongodb://" + username + ":" + password + "@" + host + ":" + port + "/";
|
||||
}
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
connectionString = "mongodb://" + host + ":" + port + "/";
|
||||
}
|
||||
connectionString += "?uuidRepresentation=STANDARD";
|
||||
|
@ -5,7 +5,7 @@ import dev.plex.util.PlexLog;
|
||||
import java.util.function.Consumer;
|
||||
import redis.clients.jedis.Jedis;
|
||||
|
||||
public class RedisConnection extends PlexBase
|
||||
public class RedisConnection implements PlexBase
|
||||
{
|
||||
private Jedis jedis;
|
||||
|
||||
|
@ -4,14 +4,13 @@ import com.zaxxer.hikari.HikariConfig;
|
||||
import com.zaxxer.hikari.HikariDataSource;
|
||||
import dev.plex.Plex;
|
||||
import dev.plex.PlexBase;
|
||||
import lombok.Getter;
|
||||
|
||||
import java.io.File;
|
||||
import java.sql.Connection;
|
||||
import java.sql.SQLException;
|
||||
import lombok.Getter;
|
||||
|
||||
@Getter
|
||||
public class SQLConnection extends PlexBase
|
||||
public class SQLConnection implements PlexBase
|
||||
{
|
||||
private HikariDataSource dataSource;
|
||||
|
||||
@ -19,7 +18,7 @@ public class SQLConnection extends PlexBase
|
||||
{
|
||||
if (!plugin.config.getString("data.central.storage").equalsIgnoreCase("sqlite") && !plugin.config.getString("data.central.storage").equalsIgnoreCase("mariadb"))
|
||||
{
|
||||
return;
|
||||
return;
|
||||
}
|
||||
|
||||
String host = plugin.config.getString("data.central.hostname");
|
||||
@ -45,7 +44,8 @@ public class SQLConnection extends PlexBase
|
||||
{
|
||||
dataSource.setJdbcUrl("jdbc:sqlite:" + new File(plugin.getDataFolder(), "database.db").getAbsolutePath());
|
||||
plugin.setStorageType(StorageType.SQLITE);
|
||||
} else if (plugin.config.getString("data.central.storage").equalsIgnoreCase("mariadb"))
|
||||
}
|
||||
else if (plugin.config.getString("data.central.storage").equalsIgnoreCase("mariadb"))
|
||||
{
|
||||
Class.forName("org.mariadb.jdbc.Driver");
|
||||
dataSource.setJdbcUrl("jdbc:mariadb://" + host + ":" + port + "/" + database);
|
||||
@ -53,7 +53,8 @@ public class SQLConnection extends PlexBase
|
||||
dataSource.setPassword(password);
|
||||
Plex.get().setStorageType(StorageType.MARIADB);
|
||||
}
|
||||
} catch (ClassNotFoundException throwables)
|
||||
}
|
||||
catch (ClassNotFoundException throwables)
|
||||
{
|
||||
throwables.printStackTrace();
|
||||
}
|
||||
@ -90,7 +91,13 @@ public class SQLConnection extends PlexBase
|
||||
"`note` VARCHAR(2000), " +
|
||||
"`timestamp` BIGINT" +
|
||||
");").execute();
|
||||
} catch (SQLException throwables)
|
||||
con.prepareStatement("CREATE TABLE IF NOT EXISTS `permissions` (" +
|
||||
"`uuid` VARCHAR(46) NOT NULL," +
|
||||
"`permission` VARCHAR(1000) NOT NULL," +
|
||||
"`allowed` BOOLEAN" +
|
||||
");").execute();
|
||||
}
|
||||
catch (SQLException throwables)
|
||||
{
|
||||
throwables.printStackTrace();
|
||||
}
|
||||
@ -105,7 +112,8 @@ public class SQLConnection extends PlexBase
|
||||
try
|
||||
{
|
||||
return dataSource.getConnection();
|
||||
} catch (SQLException e)
|
||||
}
|
||||
catch (SQLException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
@ -0,0 +1,95 @@
|
||||
package dev.plex.storage.permission;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import dev.plex.Plex;
|
||||
import dev.plex.permission.Permission;
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.UUID;
|
||||
|
||||
public class SQLPermissions
|
||||
{
|
||||
private static final String SELECT = "SELECT * FROM `permissions` WHERE uuid=?";
|
||||
private static final String INSERT = "INSERT INTO `permissions` (`uuid`, `permission`, `allowed`) VALUES(?, ?, ?)";
|
||||
private static final String REMOVE_PERMISSION = "DELETE FROM `permissions` WHERE uuid=? AND permission=?";
|
||||
private static final String UPDATE_PERMISSION = "UPDATE `permissions` SET allowed=? WHERE uuid=? AND permission=?";
|
||||
|
||||
public List<Permission> getPermissions(UUID uuid)
|
||||
{
|
||||
List<Permission> permissions = Lists.newArrayList();
|
||||
try (Connection con = Plex.get().getSqlConnection().getCon())
|
||||
{
|
||||
PreparedStatement statement = con.prepareStatement(SELECT);
|
||||
statement.setString(1, uuid.toString());
|
||||
ResultSet set = statement.executeQuery();
|
||||
while (set.next())
|
||||
{
|
||||
Permission permission = new Permission(UUID.fromString(set.getString("uuid")), set.getString("permission"));
|
||||
permission.setAllowed(set.getBoolean("allowed"));
|
||||
permissions.add(permission);
|
||||
}
|
||||
}
|
||||
catch (SQLException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
return permissions;
|
||||
}
|
||||
|
||||
public void addPermission(Permission permission)
|
||||
{
|
||||
try (Connection con = Plex.get().getSqlConnection().getCon())
|
||||
{
|
||||
PreparedStatement statement = con.prepareStatement(INSERT);
|
||||
statement.setString(1, permission.getUuid().toString());
|
||||
statement.setString(2, permission.getPermission().toLowerCase(Locale.ROOT));
|
||||
statement.setBoolean(3, permission.isAllowed());
|
||||
statement.execute();
|
||||
}
|
||||
catch (SQLException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public void updatePermission(Permission permission, boolean newValue)
|
||||
{
|
||||
try (Connection con = Plex.get().getSqlConnection().getCon())
|
||||
{
|
||||
PreparedStatement statement = con.prepareStatement(UPDATE_PERMISSION);
|
||||
statement.setBoolean(1, newValue);
|
||||
statement.setString(2, permission.getUuid().toString());
|
||||
statement.setString(3, permission.getPermission().toLowerCase(Locale.ROOT));
|
||||
statement.executeUpdate();
|
||||
}
|
||||
catch (SQLException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public void removePermission(Permission permission)
|
||||
{
|
||||
this.removePermission(permission.getUuid(), permission.getPermission());
|
||||
}
|
||||
|
||||
public void removePermission(UUID uuid, String permission)
|
||||
{
|
||||
try (Connection con = Plex.get().getSqlConnection().getCon())
|
||||
{
|
||||
PreparedStatement statement = con.prepareStatement(REMOVE_PERMISSION);
|
||||
statement.setString(1, uuid.toString());
|
||||
statement.setString(2, permission.toLowerCase(Locale.ROOT));
|
||||
statement.execute();
|
||||
}
|
||||
catch (SQLException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
package dev.plex.cache.player;
|
||||
package dev.plex.storage.player;
|
||||
|
||||
import dev.morphia.Datastore;
|
||||
import dev.morphia.query.Query;
|
||||
@ -6,6 +6,7 @@ import dev.morphia.query.Update;
|
||||
import dev.morphia.query.experimental.filters.Filters;
|
||||
import dev.morphia.query.experimental.updates.UpdateOperators;
|
||||
import dev.plex.Plex;
|
||||
import dev.plex.cache.PlayerCache;
|
||||
import dev.plex.player.PlexPlayer;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
@ -43,6 +44,14 @@ public class MongoPlayerData
|
||||
return query.first() != null;
|
||||
}
|
||||
|
||||
public boolean exists(String username)
|
||||
{
|
||||
Query<PlexPlayer> query = datastore.find(PlexPlayer.class)
|
||||
.filter(Filters.regex("name").caseInsensitive().pattern(username));
|
||||
|
||||
return query.first() != null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the player from cache or from mongo's database
|
||||
*
|
@ -1,9 +1,13 @@
|
||||
package dev.plex.cache.player;
|
||||
package dev.plex.storage.player;
|
||||
|
||||
import com.google.common.reflect.TypeToken;
|
||||
import com.google.gson.Gson;
|
||||
import dev.plex.Plex;
|
||||
import dev.plex.cache.PlayerCache;
|
||||
import dev.plex.player.PlexPlayer;
|
||||
import dev.plex.storage.StorageType;
|
||||
import dev.plex.util.PlexLog;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
@ -34,8 +38,22 @@ public class SQLPlayerData
|
||||
statement.setString(1, uuid.toString());
|
||||
ResultSet set = statement.executeQuery();
|
||||
return set.next();
|
||||
} catch (SQLException throwables)
|
||||
{
|
||||
throwables.printStackTrace();
|
||||
}
|
||||
catch (SQLException throwables)
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean exists(String username)
|
||||
{
|
||||
try (Connection con = Plex.get().getSqlConnection().getCon())
|
||||
{
|
||||
PreparedStatement statement = con.prepareStatement("SELECT * FROM `players` WHERE name=?");
|
||||
statement.setString(1, username);
|
||||
ResultSet set = statement.executeQuery();
|
||||
return set.next();
|
||||
} catch (SQLException throwables)
|
||||
{
|
||||
throwables.printStackTrace();
|
||||
}
|
||||
@ -86,8 +104,7 @@ public class SQLPlayerData
|
||||
plexPlayer.setCommandSpy(commandspy);
|
||||
}
|
||||
return plexPlayer;
|
||||
}
|
||||
catch (SQLException throwables)
|
||||
} catch (SQLException throwables)
|
||||
{
|
||||
throwables.printStackTrace();
|
||||
}
|
||||
@ -131,8 +148,7 @@ public class SQLPlayerData
|
||||
return plexPlayer;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
catch (SQLException throwables)
|
||||
} catch (SQLException throwables)
|
||||
{
|
||||
throwables.printStackTrace();
|
||||
}
|
||||
@ -154,44 +170,90 @@ public class SQLPlayerData
|
||||
return player;
|
||||
}
|
||||
|
||||
try (Connection con = Plex.get().getSqlConnection().getCon())
|
||||
if (Plex.get().getStorageType() == StorageType.MARIADB)
|
||||
{
|
||||
PreparedStatement statement = con.prepareStatement("select * from `players` where json_search(ips, ?, ?) IS NOT NULL LIMIT 1");
|
||||
statement.setString(1, "one");
|
||||
statement.setString(2, ip);
|
||||
ResultSet set = statement.executeQuery();
|
||||
|
||||
PlexPlayer plexPlayer = null;
|
||||
while (set.next())
|
||||
try (Connection con = Plex.get().getSqlConnection().getCon())
|
||||
{
|
||||
String uuid = set.getString("uuid");
|
||||
String name = set.getString("name");
|
||||
String loginMSG = set.getString("login_msg");
|
||||
String prefix = set.getString("prefix");
|
||||
String rankName = set.getString("rank").toUpperCase();
|
||||
boolean adminActive = set.getBoolean("adminActive");
|
||||
long coins = set.getLong("coins");
|
||||
boolean vanished = set.getBoolean("vanished");
|
||||
boolean commandspy = set.getBoolean("commandspy");
|
||||
List<String> ips = new Gson().fromJson(set.getString("ips"), new TypeToken<List<String>>()
|
||||
PreparedStatement statement = con.prepareStatement("select * from `players` where json_search(ips, ?, ?) IS NOT NULL LIMIT 1");
|
||||
statement.setString(1, "one");
|
||||
statement.setString(2, ip);
|
||||
ResultSet set = statement.executeQuery();
|
||||
|
||||
PlexPlayer plexPlayer = null;
|
||||
while (set.next())
|
||||
{
|
||||
}.getType());
|
||||
plexPlayer = new PlexPlayer(UUID.fromString(uuid));
|
||||
plexPlayer.setName(name);
|
||||
plexPlayer.setLoginMessage(loginMSG);
|
||||
plexPlayer.setPrefix(prefix);
|
||||
plexPlayer.setRank(rankName);
|
||||
plexPlayer.setAdminActive(adminActive);
|
||||
plexPlayer.setIps(ips);
|
||||
plexPlayer.setCoins(coins);
|
||||
plexPlayer.setVanished(vanished);
|
||||
plexPlayer.setCommandSpy(commandspy);
|
||||
String uuid = set.getString("uuid");
|
||||
String name = set.getString("name");
|
||||
String loginMSG = set.getString("login_msg");
|
||||
String prefix = set.getString("prefix");
|
||||
String rankName = set.getString("rank").toUpperCase();
|
||||
boolean adminActive = set.getBoolean("adminActive");
|
||||
long coins = set.getLong("coins");
|
||||
boolean vanished = set.getBoolean("vanished");
|
||||
boolean commandspy = set.getBoolean("commandspy");
|
||||
List<String> ips = new Gson().fromJson(set.getString("ips"), new TypeToken<List<String>>()
|
||||
{
|
||||
}.getType());
|
||||
plexPlayer = new PlexPlayer(UUID.fromString(uuid));
|
||||
plexPlayer.setName(name);
|
||||
plexPlayer.setLoginMessage(loginMSG);
|
||||
plexPlayer.setPrefix(prefix);
|
||||
plexPlayer.setRank(rankName);
|
||||
plexPlayer.setAdminActive(adminActive);
|
||||
plexPlayer.setIps(ips);
|
||||
plexPlayer.setCoins(coins);
|
||||
plexPlayer.setVanished(vanished);
|
||||
plexPlayer.setCommandSpy(commandspy);
|
||||
}
|
||||
return plexPlayer;
|
||||
} catch (SQLException throwables)
|
||||
{
|
||||
throwables.printStackTrace();
|
||||
}
|
||||
return plexPlayer;
|
||||
}
|
||||
catch (SQLException throwables)
|
||||
} else if (Plex.get().getStorageType() == StorageType.SQLITE)
|
||||
{
|
||||
throwables.printStackTrace();
|
||||
PlexLog.warn("Querying a user by IP running SQLite can cause performance issues! Please try to switch to a remote DB ASAP!");
|
||||
try (Connection con = Plex.get().getSqlConnection().getCon())
|
||||
{
|
||||
PreparedStatement statement = con.prepareStatement("select * from `players`");
|
||||
ResultSet set = statement.executeQuery();
|
||||
|
||||
PlexPlayer plexPlayer = null;
|
||||
while (set.next())
|
||||
{
|
||||
List<String> ips = new Gson().fromJson(set.getString("ips"), new TypeToken<List<String>>()
|
||||
{
|
||||
}.getType());
|
||||
if (!ips.contains(ip))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
String uuid = set.getString("uuid");
|
||||
String name = set.getString("name");
|
||||
String loginMSG = set.getString("login_msg");
|
||||
String prefix = set.getString("prefix");
|
||||
String rankName = set.getString("rank").toUpperCase();
|
||||
boolean adminActive = set.getBoolean("adminActive");
|
||||
long coins = set.getLong("coins");
|
||||
boolean vanished = set.getBoolean("vanished");
|
||||
boolean commandspy = set.getBoolean("commandspy");
|
||||
|
||||
plexPlayer = new PlexPlayer(UUID.fromString(uuid));
|
||||
plexPlayer.setName(name);
|
||||
plexPlayer.setLoginMessage(loginMSG);
|
||||
plexPlayer.setPrefix(prefix);
|
||||
plexPlayer.setRank(rankName);
|
||||
plexPlayer.setAdminActive(adminActive);
|
||||
plexPlayer.setIps(ips);
|
||||
plexPlayer.setCoins(coins);
|
||||
plexPlayer.setVanished(vanished);
|
||||
plexPlayer.setCommandSpy(commandspy);
|
||||
}
|
||||
return plexPlayer;
|
||||
} catch (SQLException throwables)
|
||||
{
|
||||
throwables.printStackTrace();
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
@ -218,8 +280,7 @@ public class SQLPlayerData
|
||||
statement.setBoolean(9, player.isCommandSpy());
|
||||
statement.setString(10, player.getUuid().toString());
|
||||
statement.executeUpdate();
|
||||
}
|
||||
catch (SQLException throwables)
|
||||
} catch (SQLException throwables)
|
||||
{
|
||||
throwables.printStackTrace();
|
||||
}
|
||||
@ -247,8 +308,7 @@ public class SQLPlayerData
|
||||
statement.setBoolean(9, player.isVanished());
|
||||
statement.setBoolean(10, player.isCommandSpy());
|
||||
statement.execute();
|
||||
}
|
||||
catch (SQLException throwables)
|
||||
} catch (SQLException throwables)
|
||||
{
|
||||
throwables.printStackTrace();
|
||||
}
|
@ -1,17 +1,15 @@
|
||||
package dev.plex.cache.sql;
|
||||
package dev.plex.storage.punishment;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import dev.plex.Plex;
|
||||
import dev.plex.punishment.extra.Note;
|
||||
import dev.plex.util.TimeUtils;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.time.Instant;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.ZoneId;
|
||||
import java.time.ZoneOffset;
|
||||
import java.time.*;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
@ -38,7 +36,7 @@ public class SQLNotes
|
||||
uuid,
|
||||
set.getString("note"),
|
||||
UUID.fromString(set.getString("written_by")),
|
||||
LocalDateTime.ofInstant(Instant.ofEpochMilli(set.getLong("timestamp")), ZoneId.systemDefault())
|
||||
ZonedDateTime.ofInstant(Instant.ofEpochMilli(set.getLong("timestamp")), ZoneId.of(TimeUtils.TIMEZONE))
|
||||
);
|
||||
note.setId(set.getInt("id"));
|
||||
notes.add(note);
|
||||
@ -47,6 +45,7 @@ public class SQLNotes
|
||||
catch (SQLException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
return notes;
|
||||
}
|
||||
return notes;
|
||||
});
|
||||
@ -83,7 +82,7 @@ public class SQLNotes
|
||||
statement.setString(2, note.getUuid().toString());
|
||||
statement.setString(3, note.getWrittenBy().toString());
|
||||
statement.setString(4, note.getNote());
|
||||
statement.setLong(5, note.getTimestamp().toInstant(ZoneOffset.UTC).toEpochMilli());
|
||||
statement.setLong(5, note.getTimestamp().toInstant().toEpochMilli());
|
||||
statement.execute();
|
||||
note.setId(notes.size());
|
||||
}
|
@ -1,18 +1,19 @@
|
||||
package dev.plex.cache.sql;
|
||||
package dev.plex.storage.punishment;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import dev.plex.Plex;
|
||||
import dev.plex.punishment.Punishment;
|
||||
import dev.plex.punishment.PunishmentType;
|
||||
import dev.plex.util.PlexLog;
|
||||
import dev.plex.util.TimeUtils;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.time.Instant;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.ZoneId;
|
||||
import java.time.ZoneOffset;
|
||||
import java.time.ZonedDateTime;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
@ -36,20 +37,20 @@ public class SQLPunishment
|
||||
ResultSet set = statement.executeQuery();
|
||||
while (set.next())
|
||||
{
|
||||
Punishment punishment = new Punishment(UUID.fromString(set.getString("punished")), UUID.fromString(set.getString("punisher")));
|
||||
Punishment punishment = new Punishment(UUID.fromString(set.getString("punished")), set.getString("punisher") != null && set.getString("punisher").isEmpty() ? UUID.fromString(set.getString("punisher")) : null);
|
||||
punishment.setActive(set.getBoolean("active"));
|
||||
punishment.setType(PunishmentType.valueOf(set.getString("type")));
|
||||
punishment.setCustomTime(set.getBoolean("customTime"));
|
||||
punishment.setPunishedUsername(set.getString("punishedUsername"));
|
||||
punishment.setEndDate(LocalDateTime.ofInstant(Instant.ofEpochMilli(set.getLong("endDate")), ZoneId.systemDefault()));
|
||||
punishment.setEndDate(ZonedDateTime.ofInstant(Instant.ofEpochMilli(set.getLong("endDate")), ZoneId.of(TimeUtils.TIMEZONE)));
|
||||
punishment.setReason(set.getString("reason"));
|
||||
punishment.setIp(set.getString("ip"));
|
||||
punishments.add(punishment);
|
||||
}
|
||||
}
|
||||
catch (SQLException e)
|
||||
} catch (SQLException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
return punishments;
|
||||
}
|
||||
return punishments;
|
||||
});
|
||||
@ -70,13 +71,12 @@ public class SQLPunishment
|
||||
punishment.setType(PunishmentType.valueOf(set.getString("type")));
|
||||
punishment.setCustomTime(set.getBoolean("customTime"));
|
||||
punishment.setPunishedUsername(set.getString("punishedUsername"));
|
||||
punishment.setEndDate(LocalDateTime.ofInstant(Instant.ofEpochMilli(set.getLong("endDate")), ZoneId.systemDefault()));
|
||||
punishment.setEndDate(ZonedDateTime.ofInstant(Instant.ofEpochMilli(set.getLong("endDate")), ZoneId.of(TimeUtils.TIMEZONE)));
|
||||
punishment.setReason(set.getString("reason"));
|
||||
punishment.setIp(set.getString("ip"));
|
||||
punishments.add(punishment);
|
||||
}
|
||||
}
|
||||
catch (SQLException e)
|
||||
} catch (SQLException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
@ -100,17 +100,38 @@ public class SQLPunishment
|
||||
statement.setString(6, punishment.getReason());
|
||||
statement.setBoolean(7, punishment.isCustomTime());
|
||||
statement.setBoolean(8, punishment.isActive());
|
||||
statement.setLong(9, punishment.getEndDate().toInstant(ZoneOffset.UTC).toEpochMilli());
|
||||
statement.setLong(9, punishment.getEndDate().toInstant().toEpochMilli());
|
||||
PlexLog.debug("Executing punishment");
|
||||
statement.execute();
|
||||
}
|
||||
catch (SQLException e)
|
||||
} catch (SQLException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void syncRemoveBan(UUID uuid)
|
||||
{
|
||||
try (Connection con = Plex.get().getSqlConnection().getCon())
|
||||
{
|
||||
PreparedStatement statement = con.prepareStatement(UPDATE_BAN);
|
||||
statement.setBoolean(1, false);
|
||||
statement.setBoolean(2, true);
|
||||
statement.setString(3, uuid.toString());
|
||||
statement.setString(4, PunishmentType.BAN.name());
|
||||
|
||||
PreparedStatement statement1 = con.prepareStatement(UPDATE_BAN);
|
||||
statement1.setBoolean(1, false);
|
||||
statement1.setBoolean(2, true);
|
||||
statement1.setString(3, uuid.toString());
|
||||
statement1.setString(4, PunishmentType.TEMPBAN.name());
|
||||
statement1.executeUpdate();
|
||||
} catch (SQLException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public CompletableFuture<Void> removeBan(UUID uuid)
|
||||
{
|
||||
return CompletableFuture.runAsync(() ->
|
||||
@ -123,8 +144,14 @@ public class SQLPunishment
|
||||
statement.setString(3, uuid.toString());
|
||||
statement.setString(4, PunishmentType.BAN.name());
|
||||
statement.executeUpdate();
|
||||
}
|
||||
catch (SQLException e)
|
||||
|
||||
PreparedStatement statement1 = con.prepareStatement(UPDATE_BAN);
|
||||
statement1.setBoolean(1, false);
|
||||
statement1.setBoolean(2, true);
|
||||
statement1.setString(3, uuid.toString());
|
||||
statement1.setString(4, PunishmentType.TEMPBAN.name());
|
||||
statement1.executeUpdate();
|
||||
} catch (SQLException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
@ -2,6 +2,8 @@ package dev.plex.util;
|
||||
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.ZonedDateTime;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.Setter;
|
||||
@ -25,7 +27,7 @@ public class AshconInfo
|
||||
{
|
||||
private String username;
|
||||
@SerializedName("changed_at")
|
||||
private LocalDateTime localDateTime;
|
||||
private ZonedDateTime zonedDateTime;
|
||||
}
|
||||
|
||||
@Getter
|
||||
|
39
src/main/java/dev/plex/util/BuildInfo.java
Normal file
39
src/main/java/dev/plex/util/BuildInfo.java
Normal file
@ -0,0 +1,39 @@
|
||||
package dev.plex.util;
|
||||
|
||||
import dev.plex.Plex;
|
||||
import java.io.InputStream;
|
||||
import java.util.Properties;
|
||||
import lombok.Getter;
|
||||
|
||||
public class BuildInfo
|
||||
{
|
||||
@Getter
|
||||
public static String number;
|
||||
@Getter
|
||||
public static String author;
|
||||
@Getter
|
||||
public static String date;
|
||||
@Getter
|
||||
public static String head;
|
||||
|
||||
public void load(Plex plugin)
|
||||
{
|
||||
try
|
||||
{
|
||||
Properties props;
|
||||
try (InputStream in = plugin.getResource("build.properties"))
|
||||
{
|
||||
props = new Properties();
|
||||
props.load(in);
|
||||
}
|
||||
|
||||
number = props.getProperty("buildNumber", "unknown");
|
||||
author = props.getProperty("buildAuthor", "unknown");
|
||||
date = props.getProperty("buildDate", "unknown");
|
||||
head = props.getProperty("buildHead", "unknown");
|
||||
}
|
||||
catch (Exception ignored)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
56
src/main/java/dev/plex/util/GameRuleUtil.java
Normal file
56
src/main/java/dev/plex/util/GameRuleUtil.java
Normal file
@ -0,0 +1,56 @@
|
||||
package dev.plex.util;
|
||||
|
||||
import dev.plex.Plex;
|
||||
import java.util.Locale;
|
||||
import org.apache.commons.lang.math.NumberUtils;
|
||||
import org.bukkit.GameRule;
|
||||
import org.bukkit.World;
|
||||
|
||||
public class GameRuleUtil
|
||||
{
|
||||
public static <T> void commitGlobalGameRules(World world)
|
||||
{
|
||||
for (String s : Plex.get().config.getStringList("global_gamerules"))
|
||||
{
|
||||
readGameRules(world, s);
|
||||
}
|
||||
}
|
||||
|
||||
public static <T> void commitSpecificGameRules(World world)
|
||||
{
|
||||
for (String s : Plex.get().config.getStringList("worlds." + world.getName().toLowerCase(Locale.ROOT) + ".gameRules"))
|
||||
{
|
||||
readGameRules(world, s);
|
||||
}
|
||||
}
|
||||
|
||||
private static <T> void readGameRules(World world, String s)
|
||||
{
|
||||
String gameRule = s.split(";")[0];
|
||||
T value = (T)s.split(";")[1];
|
||||
GameRule<T> rule = (GameRule<T>)GameRule.getByName(gameRule);
|
||||
if (rule != null && check(value).getClass().equals(rule.getType()))
|
||||
{
|
||||
world.setGameRule(rule, value);
|
||||
PlexLog.debug("Setting game rule " + gameRule + " for world " + world.getName() + " with value " + value);
|
||||
}
|
||||
else
|
||||
{
|
||||
PlexLog.error(String.format("Failed to set game rule %s for world %s with value %s!", gameRule, world.getName().toLowerCase(Locale.ROOT), value));
|
||||
}
|
||||
}
|
||||
|
||||
public static <T> Object check(T value)
|
||||
{
|
||||
if (value.toString().equalsIgnoreCase("true") || value.toString().equalsIgnoreCase("false"))
|
||||
{
|
||||
return Boolean.parseBoolean(value.toString());
|
||||
}
|
||||
|
||||
if (NumberUtils.isNumber(value.toString()))
|
||||
{
|
||||
return Integer.parseInt(value.toString());
|
||||
}
|
||||
return value;
|
||||
}
|
||||
}
|
@ -7,8 +7,11 @@ import java.nio.charset.StandardCharsets;
|
||||
import java.time.Instant;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.ZoneId;
|
||||
import java.time.ZonedDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.Arrays;
|
||||
|
||||
import dev.plex.Plex;
|
||||
import org.apache.http.HttpResponse;
|
||||
import org.apache.http.client.methods.HttpGet;
|
||||
import org.apache.http.impl.client.CloseableHttpClient;
|
||||
@ -37,16 +40,16 @@ public class MojangUtils
|
||||
return null;
|
||||
}
|
||||
client.close();
|
||||
AshconInfo ashconInfo = new GsonBuilder().registerTypeAdapter(LocalDateTime.class, (JsonDeserializer<LocalDateTime>)(json1, typeOfT, context) ->
|
||||
LocalDateTime.ofInstant(Instant.from(DateTimeFormatter.ISO_INSTANT.parse(json1.getAsJsonPrimitive().getAsString())), ZoneId.systemDefault())).create().fromJson(json, AshconInfo.class);
|
||||
AshconInfo ashconInfo = new GsonBuilder().registerTypeAdapter(ZonedDateTime.class, (JsonDeserializer<ZonedDateTime>)(json1, typeOfT, context) ->
|
||||
ZonedDateTime.ofInstant(Instant.from(DateTimeFormatter.ISO_INSTANT.parse(json1.getAsJsonPrimitive().getAsString())), ZoneId.of(Plex.get().config.getString("server.timezone")))).create().fromJson(json, AshconInfo.class);
|
||||
|
||||
Arrays.sort(ashconInfo.getUsernameHistories(), (o1, o2) ->
|
||||
{
|
||||
if (o1.getLocalDateTime() == null || o2.getLocalDateTime() == null)
|
||||
if (o1.getZonedDateTime() == null || o2.getZonedDateTime() == null)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
return o1.getLocalDateTime().compareTo(o2.getLocalDateTime());
|
||||
return o1.getZonedDateTime().compareTo(o2.getZonedDateTime());
|
||||
});
|
||||
|
||||
return ashconInfo;
|
||||
|
65
src/main/java/dev/plex/util/PermissionsUtil.java
Normal file
65
src/main/java/dev/plex/util/PermissionsUtil.java
Normal file
@ -0,0 +1,65 @@
|
||||
package dev.plex.util;
|
||||
|
||||
import dev.plex.Plex;
|
||||
import dev.plex.cache.DataUtils;
|
||||
import dev.plex.permission.Permission;
|
||||
import dev.plex.player.PlexPlayer;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.permissions.PermissionAttachment;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class PermissionsUtil
|
||||
{
|
||||
public static void setupPermissions(@NotNull Player player)
|
||||
{
|
||||
PlexPlayer plexPlayer = DataUtils.getPlayer(player.getUniqueId());
|
||||
PermissionAttachment attachment = player.addAttachment(Plex.get());
|
||||
plexPlayer.getPermissions().forEach(permission -> attachment.setPermission(permission.getPermission(), permission.isAllowed()));
|
||||
plexPlayer.setPermissionAttachment(attachment);
|
||||
}
|
||||
|
||||
public static void addPermission(PlexPlayer player, Permission permission)
|
||||
{
|
||||
Plex.get().getSqlPermissions().addPermission(PlexUtils.addToArrayList(player.getPermissions(), permission));
|
||||
Player p = Bukkit.getPlayer(player.getUuid());
|
||||
if (p == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
player.getPermissionAttachment().setPermission(permission.getPermission(), permission.isAllowed());
|
||||
}
|
||||
|
||||
public static void addPermission(PlexPlayer player, String permission)
|
||||
{
|
||||
addPermission(player, new Permission(player.getUuid(), permission));
|
||||
}
|
||||
|
||||
public static void removePermission(PlexPlayer player, String permission)
|
||||
{
|
||||
Plex.get().getSqlPermissions().removePermission(player.getUuid(), permission);
|
||||
player.getPermissions().removeIf(permission1 -> permission1.getPermission().equalsIgnoreCase(permission));
|
||||
Player p = Bukkit.getPlayer(player.getUuid());
|
||||
if (p == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
player.getPermissionAttachment().unsetPermission(permission);
|
||||
}
|
||||
|
||||
public static void updatePermission(PlexPlayer player, String permission, boolean newValue)
|
||||
{
|
||||
player.getPermissions().stream().filter(permission1 -> permission.equalsIgnoreCase(permission)).findFirst().ifPresent(permission1 ->
|
||||
{
|
||||
Plex.get().getSqlPermissions().updatePermission(permission1, newValue);
|
||||
});
|
||||
player.getPermissions().removeIf(permission1 -> permission1.getPermission().equalsIgnoreCase(permission));
|
||||
Player p = Bukkit.getPlayer(player.getUuid());
|
||||
if (p == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
player.getPermissionAttachment().unsetPermission(permission);
|
||||
|
||||
}
|
||||
}
|
@ -34,7 +34,21 @@ public class PlexLog
|
||||
message = message.replace("{" + i + "}", strings[i].toString());
|
||||
}
|
||||
}
|
||||
Bukkit.getConsoleSender().sendMessage(String.format(ChatColor.RED + "[Plex Error] " + ChatColor.GOLD + "%s", message));
|
||||
Bukkit.getConsoleSender().sendMessage(PlexUtils.mmDeserialize("<red>[Plex Error] <gold>" + message));
|
||||
// Bukkit.getConsoleSender().sendMessage(String.format(ChatColor.RED + "[Plex Error] " + ChatColor.GOLD + "%s", message));
|
||||
}
|
||||
|
||||
public static void warn(String message, Object... strings)
|
||||
{
|
||||
for (int i = 0; i < strings.length; i++)
|
||||
{
|
||||
if (message.contains("{" + i + "}"))
|
||||
{
|
||||
message = message.replace("{" + i + "}", strings[i].toString());
|
||||
}
|
||||
}
|
||||
// Bukkit.getConsoleSender().sendMessage(String.format(ChatColor.YELLOW + "[Plex Warning] " + ChatColor.GOLD + "%s", message));
|
||||
Bukkit.getConsoleSender().sendMessage(PlexUtils.mmDeserialize("<#eb7c0e>[Plex Warning] <gold>" + message));
|
||||
}
|
||||
|
||||
public static void debug(String message, Object... strings)
|
||||
@ -48,7 +62,8 @@ public class PlexLog
|
||||
}
|
||||
if (Plex.get().config.getBoolean("debug"))
|
||||
{
|
||||
Bukkit.getConsoleSender().sendMessage(String.format(ChatColor.DARK_PURPLE + "[Plex Debug] " + ChatColor.GOLD + "%s", message));
|
||||
Bukkit.getConsoleSender().sendMessage(PlexUtils.mmDeserialize("<dark_purple>[Plex Debug] <gold>" + message));
|
||||
// Bukkit.getConsoleSender().sendMessage(String.format(ChatColor.DARK_PURPLE + "[Plex Debug] " + ChatColor.GOLD + "%s", message));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,69 +1,51 @@
|
||||
package dev.plex.util;
|
||||
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.common.reflect.ClassPath;
|
||||
import dev.plex.Plex;
|
||||
import dev.plex.PlexBase;
|
||||
import dev.plex.config.Config;
|
||||
import dev.plex.cache.PlayerCache;
|
||||
import dev.plex.storage.StorageType;
|
||||
import java.sql.Connection;
|
||||
import java.sql.SQLException;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.Month;
|
||||
import java.time.ZoneId;
|
||||
import java.time.ZonedDateTime;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Random;
|
||||
import java.util.concurrent.ThreadLocalRandom;
|
||||
import java.util.stream.Collectors;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
|
||||
import org.apache.commons.lang.math.NumberUtils;
|
||||
import org.bukkit.*;
|
||||
import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver;
|
||||
import net.kyori.adventure.text.minimessage.tag.standard.StandardTags;
|
||||
import net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer;
|
||||
import org.apache.commons.lang.time.DateUtils;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Particle;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.PluginCommandYamlParser;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.json.simple.JSONObject;
|
||||
import org.json.simple.parser.JSONParser;
|
||||
import org.json.simple.parser.ParseException;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.URL;
|
||||
import java.sql.Connection;
|
||||
import java.sql.SQLException;
|
||||
import java.time.Instant;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.ZoneId;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.ThreadLocalRandom;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class PlexUtils extends PlexBase
|
||||
public class PlexUtils implements PlexBase
|
||||
{
|
||||
private static final Random RANDOM;
|
||||
private static final List<String> regxList = new ArrayList<>()
|
||||
{{
|
||||
add("y");
|
||||
add("mo");
|
||||
add("w");
|
||||
add("d");
|
||||
add("h");
|
||||
add("m");
|
||||
add("s");
|
||||
}};
|
||||
public static Map<String, ChatColor> CHAT_COLOR_NAMES;
|
||||
public static List<ChatColor> CHAT_COLOR_POOL;
|
||||
public static List<String> DEVELOPERS =
|
||||
Arrays.asList("78408086-1991-4c33-a571-d8fa325465b2", // Telesphoreo
|
||||
"f5cd54c4-3a24-4213-9a56-c06c49594dff", // Taahh
|
||||
"53b1512e-3481-4702-9f4f-63cb9c8be6a1", // supernt
|
||||
"ca83b658-c03b-4106-9edc-72f70a80656d", // ayunami2000
|
||||
"2e06e049-24c8-42e4-8bcf-d35372af31e6" //Fleek
|
||||
"2e06e049-24c8-42e4-8bcf-d35372af31e6" // Fleek
|
||||
);
|
||||
|
||||
static
|
||||
public static <T> T addToArrayList(List<T> list, T object)
|
||||
{
|
||||
RANDOM = new Random();
|
||||
CHAT_COLOR_NAMES = new HashMap<>();
|
||||
CHAT_COLOR_POOL = Arrays.asList(ChatColor.DARK_RED, ChatColor.RED, ChatColor.GOLD, ChatColor.YELLOW, ChatColor.GREEN, ChatColor.DARK_GREEN, ChatColor.AQUA, ChatColor.DARK_AQUA, ChatColor.BLUE, ChatColor.DARK_BLUE, ChatColor.DARK_PURPLE, ChatColor.LIGHT_PURPLE);
|
||||
for (final ChatColor chatColor : CHAT_COLOR_POOL)
|
||||
{
|
||||
CHAT_COLOR_NAMES.put(chatColor.name().toLowerCase().replace("_", ""), chatColor);
|
||||
}
|
||||
list.add(object);
|
||||
return object;
|
||||
}
|
||||
|
||||
public static void disabledEffect(Player player, Location location)
|
||||
@ -83,11 +65,6 @@ public class PlexUtils extends PlexBase
|
||||
players[0].getWorld().playSound(location, org.bukkit.Sound.BLOCK_FIRE_EXTINGUISH, 0.5f, 0.5f);
|
||||
}
|
||||
|
||||
public static ChatColor randomChatColor()
|
||||
{
|
||||
return CHAT_COLOR_POOL.get(RANDOM.nextInt(CHAT_COLOR_POOL.size()));
|
||||
}
|
||||
|
||||
public static void testConnections()
|
||||
{
|
||||
if (Plex.get().getSqlConnection().getDataSource() != null)
|
||||
@ -140,9 +117,38 @@ public class PlexUtils extends PlexBase
|
||||
return false;
|
||||
}
|
||||
|
||||
public static String colorize(final String string)
|
||||
private static final MiniMessage safeMessage = MiniMessage.builder().tags(TagResolver.builder().resolvers(
|
||||
StandardTags.color(),
|
||||
StandardTags.decorations(),
|
||||
StandardTags.gradient(),
|
||||
StandardTags.rainbow(),
|
||||
StandardTags.reset()
|
||||
).build()).build();
|
||||
|
||||
public static String mmStripColor(String input)
|
||||
{
|
||||
return ChatColor.translateAlternateColorCodes('&', string);
|
||||
return PlainTextComponentSerializer.plainText().serialize(mmDeserialize(input));
|
||||
}
|
||||
|
||||
public static Component mmDeserialize(String input)
|
||||
{
|
||||
boolean aprilFools = true; // true by default
|
||||
if (plugin.config.contains("april_fools"))
|
||||
{
|
||||
aprilFools = plugin.config.getBoolean("april_fools");
|
||||
}
|
||||
ZonedDateTime date = ZonedDateTime.now(ZoneId.of(TimeUtils.TIMEZONE));
|
||||
if (aprilFools && date.getMonth() == Month.APRIL && date.getDayOfMonth() == 1)
|
||||
{
|
||||
Component component = MiniMessage.miniMessage().deserialize(input); // removes existing tags
|
||||
return MiniMessage.miniMessage().deserialize("<rainbow>" + PlainTextComponentSerializer.plainText().serialize(component));
|
||||
}
|
||||
return MiniMessage.miniMessage().deserialize(input);
|
||||
}
|
||||
|
||||
public static Component mmCustomDeserialize(String input, TagResolver... resolvers)
|
||||
{
|
||||
return MiniMessage.builder().tags(TagResolver.builder().resolvers(resolvers).build()).build().deserialize(input);
|
||||
}
|
||||
|
||||
public static Component messageComponent(String entry, Object... objects)
|
||||
@ -164,138 +170,6 @@ public class PlexUtils extends PlexBase
|
||||
return f;
|
||||
}
|
||||
|
||||
private static long a(String parse)
|
||||
{
|
||||
StringBuilder sb = new StringBuilder();
|
||||
|
||||
regxList.forEach(obj ->
|
||||
{
|
||||
if (parse.endsWith(obj))
|
||||
{
|
||||
sb.append(parse.split(obj)[0]);
|
||||
}
|
||||
});
|
||||
|
||||
return Long.parseLong(sb.toString());
|
||||
}
|
||||
|
||||
private static TimeUnit verify(String arg)
|
||||
{
|
||||
TimeUnit unit = null;
|
||||
for (String c : regxList)
|
||||
{
|
||||
if (arg.endsWith(c))
|
||||
{
|
||||
switch (c)
|
||||
{
|
||||
case "y" -> unit = TimeUnit.YEAR;
|
||||
case "mo" -> unit = TimeUnit.MONTH;
|
||||
case "w" -> unit = TimeUnit.WEEK;
|
||||
case "d" -> unit = TimeUnit.DAY;
|
||||
case "h" -> unit = TimeUnit.HOUR;
|
||||
case "m" -> unit = TimeUnit.MINUTE;
|
||||
case "s" -> unit = TimeUnit.SECOND;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
return (unit != null) ? unit : TimeUnit.DAY;
|
||||
}
|
||||
|
||||
public static LocalDateTime parseDateOffset(String... time)
|
||||
{
|
||||
Instant instant = Instant.now();
|
||||
for (String arg : time)
|
||||
{
|
||||
instant = instant.plusSeconds(verify(arg).get() * a(arg));
|
||||
}
|
||||
return LocalDateTime.ofInstant(instant, ZoneId.systemDefault().getRules().getOffset(instant));
|
||||
}
|
||||
|
||||
public static ChatColor getChatColorFromConfig(Config config, ChatColor def, String path)
|
||||
{
|
||||
ChatColor color;
|
||||
if (config.getString(path) == null)
|
||||
{
|
||||
color = def;
|
||||
}
|
||||
else if (ChatColor.getByChar(config.getString(path)) == null)
|
||||
{
|
||||
color = def;
|
||||
}
|
||||
else
|
||||
{
|
||||
color = ChatColor.getByChar(config.getString(path));
|
||||
}
|
||||
return color;
|
||||
}
|
||||
|
||||
public static void setBlocks(Location c1, Location c2, Material material)
|
||||
{
|
||||
if (!c1.getWorld().getName().equals(c1.getWorld().getName()))
|
||||
{
|
||||
return;
|
||||
}
|
||||
int sy = Math.min(c1.getBlockY(), c2.getBlockY()), ey = Math.max(c1.getBlockY(), c2.getBlockY()), sx = Math.min(c1.getBlockX(), c2.getBlockX()), ex = Math.max(c1.getBlockX(), c2.getBlockX()), sz = Math.min(c1.getBlockZ(), c2.getBlockZ()), ez = Math.max(c1.getBlockZ(), c2.getBlockZ());
|
||||
World world = c1.getWorld();
|
||||
for (int y = sy; y <= ey; y++)
|
||||
{
|
||||
for (int x = sx; x <= ex; x++)
|
||||
{
|
||||
for (int z = sz; z <= ez; z++)
|
||||
{
|
||||
world.getBlockAt(x, y, z).setType(material);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static <T> void commitGlobalGameRules(World world)
|
||||
{
|
||||
for (String s : Plex.get().config.getStringList("global_gamerules"))
|
||||
{
|
||||
readGameRules(world, s);
|
||||
}
|
||||
}
|
||||
|
||||
public static <T> void commitSpecificGameRules(World world)
|
||||
{
|
||||
for (String s : Plex.get().config.getStringList("worlds." + world.getName().toLowerCase(Locale.ROOT) + ".gameRules"))
|
||||
{
|
||||
readGameRules(world, s);
|
||||
}
|
||||
}
|
||||
|
||||
private static <T> void readGameRules(World world, String s)
|
||||
{
|
||||
String gameRule = s.split(";")[0];
|
||||
T value = (T)s.split(";")[1];
|
||||
GameRule<T> rule = (GameRule<T>)GameRule.getByName(gameRule);
|
||||
if (rule != null && check(value).getClass().equals(rule.getType()))
|
||||
{
|
||||
world.setGameRule(rule, value);
|
||||
PlexLog.debug("Setting game rule " + gameRule + " for world " + world.getName() + " with value " + value);
|
||||
}
|
||||
else
|
||||
{
|
||||
PlexLog.error(String.format("Failed to set game rule %s for world %s with value %s!", gameRule, world.getName().toLowerCase(Locale.ROOT), value));
|
||||
}
|
||||
}
|
||||
|
||||
public static <T> Object check(T value)
|
||||
{
|
||||
if (value.toString().equalsIgnoreCase("true") || value.toString().equalsIgnoreCase("false"))
|
||||
{
|
||||
return Boolean.parseBoolean(value.toString());
|
||||
}
|
||||
|
||||
if (NumberUtils.isNumber(value.toString()))
|
||||
{
|
||||
return Integer.parseInt(value.toString());
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
public static List<String> getPlayerNameList()
|
||||
{
|
||||
return Bukkit.getOnlinePlayers().stream().map(Player::getName).collect(Collectors.toList());
|
||||
@ -303,7 +177,7 @@ public class PlexUtils extends PlexBase
|
||||
|
||||
public static void broadcast(String s)
|
||||
{
|
||||
Bukkit.broadcast(LegacyComponentSerializer.legacyAmpersand().deserialize(s));
|
||||
Bukkit.broadcast(MiniMessage.miniMessage().deserialize(s));
|
||||
}
|
||||
|
||||
public static void broadcast(Component component)
|
||||
@ -311,124 +185,11 @@ public class PlexUtils extends PlexBase
|
||||
Bukkit.broadcast(component);
|
||||
}
|
||||
|
||||
public static Object simpleGET(String url)
|
||||
public static void broadcastToAdmins(Component component)
|
||||
{
|
||||
try
|
||||
Bukkit.getOnlinePlayers().stream().filter(pl -> PlayerCache.getPlexPlayer(pl.getUniqueId()).isAdminActive()).forEach(pl ->
|
||||
{
|
||||
URL u = new URL(url);
|
||||
HttpURLConnection connection = (HttpURLConnection)u.openConnection();
|
||||
connection.setRequestMethod("GET");
|
||||
BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream()));
|
||||
String line;
|
||||
StringBuilder content = new StringBuilder();
|
||||
while ((line = in.readLine()) != null)
|
||||
{
|
||||
content.append(line);
|
||||
}
|
||||
in.close();
|
||||
connection.disconnect();
|
||||
return new JSONParser().parse(content.toString());
|
||||
}
|
||||
catch (IOException | ParseException ex)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static UUID getFromName(String name)
|
||||
{
|
||||
JSONObject profile;
|
||||
profile = (JSONObject)simpleGET("https://api.ashcon.app/mojang/v2/user/" + name);
|
||||
if (profile == null)
|
||||
{
|
||||
PlexLog.error("Profile from Ashcon API returned null!");
|
||||
return null;
|
||||
}
|
||||
String uuidString = (String)profile.get("uuid");
|
||||
return UUID.fromString(uuidString);
|
||||
}
|
||||
|
||||
@SuppressWarnings("UnstableApiUsage")
|
||||
public static Set<Class<?>> getClassesFrom(String packageName)
|
||||
{
|
||||
Set<Class<?>> classes = new HashSet<>();
|
||||
try
|
||||
{
|
||||
ClassPath path = ClassPath.from(Plex.class.getClassLoader());
|
||||
ImmutableSet<ClassPath.ClassInfo> infoSet = path.getTopLevelClasses(packageName);
|
||||
infoSet.forEach(info ->
|
||||
{
|
||||
try
|
||||
{
|
||||
Class<?> clazz = Class.forName(info.getName());
|
||||
classes.add(clazz);
|
||||
}
|
||||
catch (ClassNotFoundException ex)
|
||||
{
|
||||
PlexLog.error("Unable to find class " + info.getName() + " in " + packageName);
|
||||
}
|
||||
});
|
||||
}
|
||||
catch (IOException ex)
|
||||
{
|
||||
PlexLog.error("Something went wrong while fetching classes from " + packageName);
|
||||
throw new RuntimeException(ex);
|
||||
}
|
||||
return Collections.unmodifiableSet(classes);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public static <T> Set<Class<? extends T>> getClassesBySubType(String packageName, Class<T> subType)
|
||||
{
|
||||
Set<Class<?>> loadedClasses = getClassesFrom(packageName);
|
||||
Set<Class<? extends T>> classes = new HashSet<>();
|
||||
loadedClasses.forEach(clazz ->
|
||||
{
|
||||
if (clazz.getSuperclass() == subType || Arrays.asList(clazz.getInterfaces()).contains(subType))
|
||||
{
|
||||
classes.add((Class<? extends T>)clazz);
|
||||
}
|
||||
pl.sendMessage(component);
|
||||
});
|
||||
return Collections.unmodifiableSet(classes);
|
||||
}
|
||||
|
||||
public static boolean randomBoolean()
|
||||
{
|
||||
return ThreadLocalRandom.current().nextBoolean();
|
||||
}
|
||||
|
||||
public static int randomNum()
|
||||
{
|
||||
return ThreadLocalRandom.current().nextInt();
|
||||
}
|
||||
|
||||
public static int randomNum(int limit)
|
||||
{
|
||||
return ThreadLocalRandom.current().nextInt(limit);
|
||||
}
|
||||
|
||||
public static int randomNum(int start, int limit)
|
||||
{
|
||||
return ThreadLocalRandom.current().nextInt(start, limit);
|
||||
}
|
||||
|
||||
public static long getDateNow()
|
||||
{
|
||||
return new Date().getTime();
|
||||
}
|
||||
|
||||
public static Date getDateFromLong(long epoch)
|
||||
{
|
||||
return new Date(epoch);
|
||||
}
|
||||
|
||||
public static long hoursToSeconds(long hours)
|
||||
{
|
||||
return hours * 3600;
|
||||
}
|
||||
|
||||
public static long minutesToSeconds(long minutes)
|
||||
{
|
||||
return minutes * 60;
|
||||
}
|
||||
}
|
||||
|
34
src/main/java/dev/plex/util/RandomUtil.java
Normal file
34
src/main/java/dev/plex/util/RandomUtil.java
Normal file
@ -0,0 +1,34 @@
|
||||
package dev.plex.util;
|
||||
|
||||
import java.util.concurrent.ThreadLocalRandom;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
|
||||
public class RandomUtil
|
||||
{
|
||||
|
||||
public static NamedTextColor getRandomColor()
|
||||
{
|
||||
NamedTextColor[] colors = NamedTextColor.NAMES.values().stream().filter(namedTextColor -> namedTextColor != NamedTextColor.BLACK && namedTextColor != NamedTextColor.DARK_BLUE).toArray(NamedTextColor[]::new);
|
||||
return colors[randomNum(colors.length)];
|
||||
}
|
||||
|
||||
public static boolean randomBoolean()
|
||||
{
|
||||
return ThreadLocalRandom.current().nextBoolean();
|
||||
}
|
||||
|
||||
public static int randomNum()
|
||||
{
|
||||
return ThreadLocalRandom.current().nextInt();
|
||||
}
|
||||
|
||||
public static int randomNum(int limit)
|
||||
{
|
||||
return ThreadLocalRandom.current().nextInt(limit);
|
||||
}
|
||||
|
||||
public static int randomNum(int start, int limit)
|
||||
{
|
||||
return ThreadLocalRandom.current().nextInt(start, limit);
|
||||
}
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user