150 Commits

Author SHA1 Message Date
5a1436afae Release Plex v1.4 2024-06-14 20:29:08 -05:00
e066d9b3a1 Implemented the ability to toggle pvp (#97)
* Implemented the ability to toggle pvp

* Changed listener to  PrePlayerAttackEntityEvent

* ... Updated the formatting so I don't get screamed at !

* _
2024-06-04 10:30:34 -05:00
9e974ae737 Add a /tempmute command (#96)
* Update WhoHasCMD.java

Added functionality that clears all players with a specified item

* Added functionality that clears all players with a specified item

* Altered tab completion to include "clear" argument

* Update WhoHasCMD.java

* Implemented a mob limiter that can be configured via a command

* Fixed some imports

* Refined tab complete

* Implemented reviewed changes

* Added a /tempmute command

* Removed unnecessary imports & simplified the reason assignment

* Fixed the usage for the moblimit command

---------

Co-authored-by: Telesphoreo <me@telesphoreo.me>
2024-06-04 09:23:51 -05:00
23611e218b Implemented a moblimiter (#95)
* Update WhoHasCMD.java

Added functionality that clears all players with a specified item

* Added functionality that clears all players with a specified item

* Altered tab completion to include "clear" argument

* Update WhoHasCMD.java

* Implemented a mob limiter that can be configured via a command

* Fixed some imports

* Refined tab complete

* Implemented reviewed changes

---------

Co-authored-by: Telesphoreo <me@telesphoreo.me>
2024-05-31 15:41:14 -05:00
5f12a1532f Add vanish filtering to list 2024-05-31 15:38:56 -05:00
fff35ad34c fix -rb showing in ban message 2024-05-26 13:35:35 -05:00
83ec997125 Merge pull request #90 from Deauthorized/messagesincursion
Move most hard coded messages to messages.yml to allow customization.
2024-05-09 17:09:37 -06:00
2ed88da151 Merge branch 'master' into messagesincursion 2024-05-09 17:06:13 -06:00
c5b356e45a fix merge conflict for hopefully the last time 2024-05-06 15:51:04 -04:00
58fe304118 oops oops oops 2024-05-06 12:40:29 -07:00
50d969975c fix merge conflict 2024-05-06 15:37:56 -04:00
52cc738d4d fix merge conflict 2024-05-06 15:34:18 -04:00
fd19d8417c add banlist to plex instead of having it in tfm extras 2024-05-06 12:31:07 -07:00
efcb9b45df oh update usage too 2024-05-06 12:29:30 -07:00
a5d77036a9 closes #91
add rollback only if -rb is specified
2024-05-06 12:26:21 -07:00
5c609b3d8f Since this'll be a problem for some reason I'm restoring the original message 2024-05-04 05:19:41 -04:00
7383e0d9bb Update BanService.java 2024-05-04 02:46:07 -04:00
f1680174ae Update DebugCMD.java 2024-05-04 02:45:39 -04:00
c0966a0f5e Update messages.yml 2024-05-04 02:44:53 -04:00
fa1a8a91ba add jenkins webhook for tf 2024-05-03 14:54:04 -07:00
129ef7b6bf Remind me to read the documentation next time... coreprotect is supposed to be called asynchronously lol 2024-05-03 14:41:12 -07:00
d7ad94d270 overrwrote the wrong file :( 2024-05-02 17:43:06 -04:00
a0471e63f6 Update WorldListener.java 2024-05-02 17:42:33 -04:00
e2b3488aa7 Update ServerListener.java 2024-05-02 17:31:33 -04:00
5b3a37835a Update PlayerListener.java 2024-05-02 17:30:22 -04:00
344df2b225 Update AntiSpamListener.java 2024-05-02 17:29:38 -04:00
6e5f0d7beb Update AntiNukerListener.java 2024-05-02 17:29:24 -04:00
0c7b280aef Update TempbanCMD.java 2024-05-02 17:28:34 -04:00
647f17b5bd Update SmiteCMD.java 2024-05-02 17:27:47 -04:00
773f320cb6 Update NotesCMD.java 2024-05-02 17:27:17 -04:00
8f55be369f Update ListCMD.java 2024-05-02 17:26:20 -04:00
5a7a2c1835 Update KickCMD.java 2024-05-02 17:25:49 -04:00
bc163aa51a Update EntityWipeCMD.java 2024-05-02 17:25:26 -04:00
5040c76dc6 Update BcastLoginMessageCMD.java 2024-05-02 17:24:49 -04:00
7d94717de5 Update BanCMD.java 2024-05-02 17:23:37 -04:00
0add60322e Update messages.yml 2024-05-02 17:22:05 -04:00
068dd28fd4 Temporary fix for displaying login messages on join 2024-04-28 12:52:21 -05:00
357683a0f6 Add a toggle option for toggling chat (#89)
* Add moderated mode toggle option

* Add new messages to messages.yml for modmode toggle

* Add block_on_modmode list for commands to block, should be separate from block_on_mute so pms can still work

* Implement the restricted chat toggle

* Add the restricted chat toggle to the toggle gui

* Add the restricted chat toggle to the consoles version of the command as well

* Update toggles.yml / requested changes

* Update messages.yml / requested changes

* Update commands.yml / requested changes

* Update ToggleMenu.java / requested changes

* Update TogglesListener.java / requested changes

* Update ToggleCMD.java / requested changes

* Update messages.yml / requested changes

* Update ToggleMenu.java / requested changes

* Update ToggleCMD.java / requested changes
2024-04-28 12:04:18 -05:00
315e16488b adds support for vanish plugins 2024-04-27 22:24:03 -05:00
85605774cf fix mute & freeze not staying after relog
add configurable timers for mute and freeze
2024-03-23 08:14:36 -07:00
54015f668a Fixes NPE if Prism or CoreProtect are not installed (#87) 2024-03-02 15:38:49 -06:00
532e82472b Added functionality that clears all players with a specified item (#82)
* Update WhoHasCMD.java

Added functionality that clears all players with a specified item

* Added functionality that clears all players with a specified item

* Altered tab completion to include "clear" argument

* Update WhoHasCMD.java

---------

Co-authored-by: Telesphoreo <me@telesphoreo.me>
2024-02-04 13:35:11 -06:00
6ce4843829 Minor fix 2024-01-27 15:56:40 -06:00
7298c8669a Attempt to fix bans not working 2024-01-27 15:48:21 -06:00
6b7c076c41 Revert "Add BroadcastEvent"
This reverts commit aab5083f78.
2024-01-26 17:13:11 -06:00
7b56bd70e9 Revert "attempt to add discordsrv"
This reverts commit 912dff0ec9.
2024-01-26 17:13:08 -06:00
fbd36161d4 Better legacy component support, removes SignListener (#81)
* Better legacy component support, removes SignListener

* Removes unused imports
2024-01-26 17:12:17 -06:00
912dff0ec9 attempt to add discordsrv 2024-01-25 17:44:47 -06:00
aab5083f78 Add BroadcastEvent 2024-01-25 17:00:59 -06:00
adb0d070a4 Update Jetty 2024-01-25 15:56:45 -06:00
e22f079062 Tab completion improvements to ban command 2024-01-23 19:58:15 -06:00
8f713fd30c uncomment prism support 2024-01-23 19:52:03 -06:00
72467de5ce Tab completer improvements (#80)
* Attempt to improve the tab completion for Plex

* i give up for the night

* steven is a god

* Fix permission node
2024-01-20 11:32:24 -06:00
c9d954d1c0 reformat 2024-01-19 22:30:26 -06:00
b168029df1 Fixed /mp and it now has the ability to purge one or all mobs + tab completion. (#79)
* Added a tab completion to /mp because our genius Plex devs forgot to. Its shitty but works lmao

* Rewrote /mp to actually work with or without args so now specific or all mobs can be purged, instead of just all mobs being purged. Why the REAL plex developers didn't include this (yet they did for /rd) defies any sort of logic.

* Tweaked the command a bit. It works as it should now.

* Tweaked the command a bit. It works as it should now.
2024-01-19 22:29:00 -06:00
f34df4f296 Add IP Banning by getting every IP punishment through SQL and checking if it's the same IP, if it's a ban / tempban, and if it's active
Make the ban command add the most recent IP used by a PlexPlayer if the player being banned is not online, else use online player's IP
2024-01-16 22:23:31 -08:00
79206d9354 (broken) ip bans 2024-01-16 21:03:50 -06:00
7bca348587 Show the same treatment for tempbans 2024-01-15 15:45:00 -08:00
b35bf63ba4 Add coreprotect support, start on prism but commented out until they figure out a maven repository for their API 2024-01-15 15:39:57 -08:00
8c5c058292 Allow Prism to work with Plex 2024-01-15 13:18:24 -06:00
3d70100119 Yes, there is 2023-12-02 01:17:27 -06:00
6a8228947b Switch to indra git 2023-12-01 23:52:07 -06:00
187226ff45 Add build number back for local builds
I couldn't find a more efficient way to do this
2023-12-01 23:43:27 -06:00
6d80d5f4e3 Revamp the build system 2023-12-01 21:46:20 -06:00
d4710f1808 Make this more friendly 2023-11-29 15:32:03 -06:00
bee4268d51 Revert radius to distanceSquared 2023-11-27 20:38:39 +11:00
7254097ae4 Update naming convention 2023-11-26 00:31:13 -06:00
20765403f4 Update dependencies 2023-11-26 00:04:40 -06:00
9650685796 you saw NOTHING 2023-11-25 23:47:01 -06:00
1cf262ff91 Add radius to entitywipe command (#74)
* currently bugged

* Fixed radius not working

---------

Co-authored-by: Focusvity <nathan.curran10012@gmail.com>
2023-11-25 23:43:27 -06:00
4de796781d Fixed tab colors not working 2023-11-22 20:39:56 -06:00
b82747b0bf Change it for books too just in case 2023-11-20 16:59:32 -06:00
029cd40124 Fixes #73 2023-11-20 16:28:06 -06:00
360775bac3 Fixes /punishments [player] not actually working 2023-11-07 04:39:54 -07:00
37ac71b6ee Fixes spawn egg bypass
Literally a one-line fix. Bruh
2023-11-07 03:41:24 -07:00
88f10ef9cc Fix more SQL 2023-10-29 23:07:36 -05:00
3608e8e825 [Breaking] Remove rank stuff from database 2023-10-29 23:00:12 -05:00
3e9be76aa2 Move these to the top 2023-09-02 10:15:34 -07:00
2364ab33ff Overhaul menu system and simplify it heavily, separating Pageable Menus and regular Menus into two different implementations 2023-09-02 10:14:10 -07:00
28c57f3a52 this is quite literally the most awful thing i have ever done 2023-08-31 20:20:18 -05:00
5929fd9ddc Bugfixes with the punishments menu 2023-08-31 04:02:01 -06:00
14d859ef75 Merge remote-tracking branch 'origin/master' 2023-08-31 02:48:15 -07:00
bc8c89449e Remove WebUtils, MojangUtils, and ashcon and replace references of WebUtils with DataUtils#getPlayer(String username) 2023-08-31 02:48:02 -07:00
709ed50748 Merge pull request #67 from plexusorg/whohas-command
Adds /whohas command
2023-08-31 02:32:15 -07:00
cc9967f9c2 make bans and kicks not take too long 2023-08-31 02:18:11 -07:00
b0c19a14ab Removed unused import 2023-08-31 02:11:12 -06:00
475169b36a Adds /whohas command 2023-08-31 02:09:07 -06:00
bb019abd89 Merge pull request #65 from plexusorg/no-nh
Removes /namehistory
2023-08-30 18:13:13 -07:00
a7ed86549d fix prefix for developers 2023-08-30 18:12:15 -07:00
ba23129b15 Removes /nh 2023-08-30 13:11:35 -06:00
c51d8da5b7 fix prefixes 2023-08-29 20:41:15 -07:00
2a2152603b Attempt to add prefixes to adminchat 2023-08-29 16:06:16 -05:00
2c7440804c Change URL 2023-08-29 15:46:35 -05:00
b7db18284a Remove rank references 2023-08-29 15:46:21 -05:00
91e09d982d Merge pull request #64 from plexusorg/nomongo
mongo changes
2023-08-28 18:51:13 -05:00
15b12e6299 make our chat handler come first 2023-08-28 04:35:32 -07:00
4b37497a14 Merge branch 'nomongo' of https://github.com/plexusorg/plex 2023-08-26 06:59:46 -07:00
b0a8b463cb Add SQL Generators
Add cache for table strings generated
Add legacy support for Tags and login messages by converting legacy color codes to minimessage tags
2023-08-26 06:59:29 -07:00
1f48dc1e60 Merge remote-tracking branch 'origin/master' 2023-08-26 06:19:30 -07:00
95c4da338e Merge pull request #63 from plexusorg/fix/use-legacy-colour-codes-in-signs
Use legacy colour codes in signs
2023-08-26 06:19:24 -07:00
cea84884fc Merge remote-tracking branch 'origin/master' 2023-08-26 06:18:54 -07:00
Eva
2331cb9f80 Fix string sanitising (#62) 2023-08-25 17:21:55 -05:00
e4f18a24cc Properly cancel block explosions (#59) 2023-08-25 17:21:55 -05:00
Eva
668460f486 Fix string sanitising (#62) 2023-08-25 23:03:37 +01:00
7336cc8feb Use legacy colour codes in signs 2023-08-25 22:48:33 +01:00
bc5d0476ee Properly cancel block explosions (#59) 2023-08-25 10:23:24 -05:00
7ff6bdb171 Remove rank system entirely and move developer title to being hardcoded 2023-08-25 04:07:56 -07:00
175c7db23d Bump the version to 1.4-SNAPSHOT
Remove every trace of MongoDB
Fix issue where notes were not being notified on a permissions based system
2023-08-25 01:30:41 -07:00
f97411ce09 Cache whether the server is on a proxy or not
Fix kick where ban message was displayed instead of kick message
2023-08-24 22:36:14 -07:00
b0240ef46e Remove extra space from prefixes 2023-08-24 21:24:14 -07:00
4887960463 This is supposed to be if it is not empty 2023-08-24 19:08:30 -07:00
295e16b6c5 This is supposed to be empty by default not null 2023-08-24 15:36:49 -07:00
72d9e0817c Merge remote-tracking branch 'origin/master' 2023-08-24 15:36:07 -07:00
28ec8e1d2d Add support for reasons 2023-08-24 15:35:59 -07:00
9d0e7bf6d6 Fix compile error 2023-08-24 15:52:51 -05:00
96b0c81fed Back to snapshot 2023-08-24 15:50:12 -05:00
7dea0bcb72 Make sure the TNT is removed 2023-08-24 02:41:57 -07:00
8344e3596e Remove checkTab and replace with silentCheckRank
add isCancelled checks for MobListener
Modify the plugin's YAML file to load before essentials
Modify the world command to support the TFM Extras module
Add more checks in WorldListener to prevent spawning entities and interacting with anything except openable things (doors, trapdoors, gates)
2023-08-24 02:40:52 -07:00
37a649fa7a This should teleport players to the world spawn 2023-08-23 19:44:27 -07:00
d7df923e5c Allow someone to modify the event before the renderer is set. This allows someone to edit the message before processing 2023-08-23 19:34:01 -07:00
d54325304e Fixes vulnerability related to command blocking in rank-based systems (#58)
Video contributing to Plex finally???
2023-08-23 15:23:30 -05:00
bc6dbb1052 Add bypass for command blocking and definite bans 2023-08-22 14:37:45 -07:00
ecbd9c02da Release Plex v1.3 2023-07-22 20:00:25 -05:00
77dc95ae29 Add Folia support minus world generation 2023-07-21 20:01:59 -05:00
91a1b1cfff Remove publishing block 2023-07-10 22:58:51 -05:00
0c6091f06a Convert Plex to a paper plugin 2023-07-10 21:43:21 -05:00
ffbad7928a Update dependencies 2023-06-08 15:25:25 -05:00
7caa89539d Update Gradle and dependencies 2023-04-29 15:06:46 -05:00
ceb9a83eda Update Gradle and dependencies 2023-03-15 21:45:34 -05:00
a62bdef5b4 Add response HTTP status code check to update checker to improve efficiency 2023-03-09 17:16:14 +11:00
37649f1fdc Closes #55 2023-03-08 19:29:30 -06:00
ea512487ac Reformat 2023-03-08 14:26:10 -06:00
41b0076f8f Make the list command work with the permission system 2023-03-08 14:23:10 -06:00
00b6473e4d Let's actually remove these files 2023-03-08 22:48:51 +11:00
77be23faf0 Minor clean up 2023-03-08 22:45:47 +11:00
e39f882ea7 Fix out of bounds exception - closes #54 2023-03-08 21:46:27 +11:00
344d890877 Block translate tag 2023-03-08 00:45:41 -06:00
2c8c6353c1 Update build.gradle 2023-03-08 00:29:14 -06:00
8fa05e3838 Update dependencies and Gradle 2023-03-02 23:06:37 -06:00
158ce52320 Fix links 2022-12-26 23:39:47 -06:00
1cc431621b Update README.md 2022-12-26 23:34:26 -06:00
b9c873beb3 Update dependencies 2022-11-27 22:14:27 -06:00
6e1fa15a6c Remove redundant <red> 2022-11-27 16:40:55 -06:00
c216bdc5a4 Add permission check for the -o flag on the login message commands 2022-11-26 04:31:43 -06:00
ed638679b2 Use cache for toggling commandspy 2022-11-26 04:24:52 -06:00
76952e33b8 Use PlexCommand instead of PlexUtils 2022-11-26 04:24:38 -06:00
f3f7daaafb Add customizable login messages 2022-11-26 04:24:12 -06:00
dbbaf4ab70 Update Gradle 2022-11-26 02:25:05 -06:00
1a10fdd481 Update Gradle 2022-09-13 02:08:35 -05:00
7565bb6fcf Back to snapshot 2022-08-25 21:18:53 -05:00
206 changed files with 4309 additions and 4648 deletions

View File

@ -1,33 +1,8 @@
<component name="ProjectCodeStyleConfiguration"> <component name="ProjectCodeStyleConfiguration">
<code_scheme name="Plexus Code Style" version="1"> <code_scheme name="Plexus Code Style" version="173">
<JavaCodeStyleSettings>
<option name="CLASS_COUNT_TO_USE_IMPORT_ON_DEMAND" value="20" />
<option name="IMPORT_LAYOUT_TABLE">
<value>
<package name="" withSubpackages="true" static="false" />
<package name="" withSubpackages="true" static="true" />
</value>
</option>
</JavaCodeStyleSettings>
<JetCodeStyleSettings>
<option name="PACKAGES_TO_USE_STAR_IMPORTS">
<value>
<package name="java.util" alias="false" withSubpackages="false" />
<package name="kotlinx.android.synthetic" alias="false" withSubpackages="true" />
<package name="io.ktor" alias="false" withSubpackages="true" />
</value>
</option>
<option name="PACKAGES_IMPORT_LAYOUT">
<value>
<package name="" alias="false" withSubpackages="true" />
<package name="java" alias="false" withSubpackages="true" />
<package name="javax" alias="false" withSubpackages="true" />
<package name="kotlin" alias="false" withSubpackages="true" />
<package name="" alias="true" withSubpackages="true" />
</value>
</option>
</JetCodeStyleSettings>
<codeStyleSettings language="JAVA"> <codeStyleSettings language="JAVA">
<option name="KEEP_FIRST_COLUMN_COMMENT" value="false" />
<option name="KEEP_BLANK_LINES_BEFORE_RBRACE" value="1" />
<option name="BRACE_STYLE" value="2" /> <option name="BRACE_STYLE" value="2" />
<option name="CLASS_BRACE_STYLE" value="2" /> <option name="CLASS_BRACE_STYLE" value="2" />
<option name="METHOD_BRACE_STYLE" value="2" /> <option name="METHOD_BRACE_STYLE" value="2" />
@ -36,14 +11,10 @@
<option name="WHILE_ON_NEW_LINE" value="true" /> <option name="WHILE_ON_NEW_LINE" value="true" />
<option name="CATCH_ON_NEW_LINE" value="true" /> <option name="CATCH_ON_NEW_LINE" value="true" />
<option name="FINALLY_ON_NEW_LINE" value="true" /> <option name="FINALLY_ON_NEW_LINE" value="true" />
<option name="SPACE_AFTER_TYPE_CAST" value="true" />
<option name="IF_BRACE_FORCE" value="3" /> <option name="IF_BRACE_FORCE" value="3" />
<option name="DOWHILE_BRACE_FORCE" value="3" /> <option name="DOWHILE_BRACE_FORCE" value="3" />
<option name="WHILE_BRACE_FORCE" value="3" /> <option name="WHILE_BRACE_FORCE" value="3" />
<option name="FOR_BRACE_FORCE" value="3" /> <option name="FOR_BRACE_FORCE" value="3" />
<option name="BLANK_LINES_AFTER_CLASS_HEADER" value="0" />
<option name="KEEP_BLANK_LINES_BEFORE_RBRACE" value="1" />
<option name="KEEP_FIRST_COLUMN_COMMENT" value="false" />
</codeStyleSettings> </codeStyleSettings>
</code_scheme> </code_scheme>
</component> </component>

13
Jenkinsfile vendored
View File

@ -8,24 +8,13 @@ pipeline {
} }
} }
} }
stage("publish") {
when {
branch "master"
}
steps {
withCredentials([usernamePassword(credentialsId: '85b7099f-2e65-461e-b2ce-124edec41ed6', passwordVariable: 'plexPassword', usernameVariable: 'plexUser')]) {
withGradle {
sh "./gradlew publish --no-daemon"
}
}
}
}
} }
post { post {
always { always {
archiveArtifacts artifacts: "build/libs/*.jar", fingerprint: true archiveArtifacts artifacts: "build/libs/*.jar", fingerprint: true
javadoc javadocDir: "server/build/docs/javadoc", keepAll: false javadoc javadocDir: "server/build/docs/javadoc", keepAll: false
discordSend description: "**Build:** ${env.BUILD_NUMBER}\n**Status:** ${currentBuild.currentResult}", enableArtifactsList: true, footer: "Built with Jenkins", link: env.BUILD_URL, result: currentBuild.currentResult, scmWebUrl: "https://github.com/plexusorg/Plex", showChangeset: true, title: env.JOB_NAME, webhookURL: env.WEBHOOK_URL discordSend description: "**Build:** ${env.BUILD_NUMBER}\n**Status:** ${currentBuild.currentResult}", enableArtifactsList: true, footer: "Built with Jenkins", link: env.BUILD_URL, result: currentBuild.currentResult, scmWebUrl: "https://github.com/plexusorg/Plex", showChangeset: true, title: env.JOB_NAME, webhookURL: env.WEBHOOK_URL
discordSend description: "**Build:** ${env.BUILD_NUMBER}\n**Status:** ${currentBuild.currentResult}", enableArtifactsList: true, footer: "Built with Jenkins", link: env.BUILD_URL, result: currentBuild.currentResult, scmWebUrl: "https://github.com/plexusorg/Plex", showChangeset: true, title: env.JOB_NAME, webhookURL: env.TF_WEBHOOK_URL
cleanWs() cleanWs()
} }
} }

View File

@ -1,4 +1,4 @@
# Plex [![Build Status](https://ci.plex.us.org/job/Plex/job/master/badge/icon)](https://ci.plex.us.org/job/Plex/job/master/) ![CodeQL](https://github.com/plexusorg/Plex/workflows/CodeQL/badge.svg) # Plex [![Build Status](https://ci.plex.us.org/job/Plex/job/master/badge/icon)](https://ci.plex.us.org/job/Plex/job/master/) [![License](https://img.shields.io/github/license/plexusorg/Plex)](https://github.com/plexusorg/Plex/blob/master/LICENSE.md) [![Discord](https://img.shields.io/discord/927737516864446495)](https://discord.plex.us.org)
Plex is a new freedom plugin. It is an alternative to TotalFreedomMod. It has many of the features that make a freedom 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 doesnt have. For example, there is full support for using a server unique, but also many features that TotalFreedomMod doesnt have. For example, there is full support for using a

View File

@ -1,72 +0,0 @@
plugins {
id "java"
id "maven-publish"
id "com.github.johnrengelman.shadow" version "7.1.2"
}
group = "dev.plex"
version = "1.2"
description = "Plex"
subprojects {
apply plugin: "java"
apply plugin: "maven-publish"
apply plugin: "com.github.johnrengelman.shadow"
repositories {
maven {
url = uri("https://repo.papermc.io/repository/maven-public/")
}
maven {
url = uri("https://repository.apache.org/content/repositories/snapshots/")
}
maven {
url = uri("https://repo.maven.apache.org/maven2/")
}
maven {
url = uri("https://jitpack.io")
content {
includeGroup("com.github.MilkBowl")
}
}
mavenCentral()
}
java {
toolchain.languageVersion.set(JavaLanguageVersion.of(17))
}
tasks.withType(JavaCompile) {
options.encoding = "UTF-8"
}
publishing {
repositories {
maven {
def releasesRepoUrl = uri("https://nexus.telesphoreo.me/repository/plex-releases/")
def snapshotsRepoUrl = uri("https://nexus.telesphoreo.me/repository/plex-snapshots/")
url = rootProject.version.endsWith('SNAPSHOT') ? snapshotsRepoUrl : releasesRepoUrl
credentials {
username = System.getenv("plexUser")
password = System.getenv("plexPassword")
}
}
}
}
}
clean {
dependsOn(":server:clean")
dependsOn(":proxy:clean")
}
task copyJars(type: Copy, dependsOn: subprojects.jar) {
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
from(subprojects.jar)
from(subprojects.shadowJar)
into project.file('build/libs')
}

91
build.gradle.kts Normal file
View File

@ -0,0 +1,91 @@
plugins {
id("java")
id("maven-publish")
id("org.jetbrains.gradle.plugin.idea-ext") version "1.1.8"
id("net.kyori.blossom") version "2.1.0"
id("io.github.goooler.shadow") version "8.1.7"
}
group = "dev.plex"
version = "1.4"
description = "Plex"
subprojects {
apply(plugin = "java")
apply(plugin = "maven-publish")
apply(plugin = "org.jetbrains.gradle.plugin.idea-ext")
apply(plugin = "net.kyori.blossom")
apply(plugin = "io.github.goooler.shadow")
repositories {
maven {
url = uri("https://repo.papermc.io/repository/maven-public/")
}
maven {
url = uri("https://repository.apache.org/content/repositories/snapshots/")
}
maven {
url = uri("https://repo.maven.apache.org/maven2/")
}
maven {
url = uri("https://jitpack.io")
content {
includeGroup("com.github.MilkBowl")
includeGroup("com.github.LeonMangler")
}
}
mavenCentral()
}
java {
toolchain.languageVersion.set(JavaLanguageVersion.of(17))
}
tasks {
compileJava {
options.encoding = Charsets.UTF_8.name()
}
javadoc {
options.encoding = Charsets.UTF_8.name()
}
processResources {
filteringCharset = Charsets.UTF_8.name()
}
}
publishing {
repositories {
maven {
val releasesRepoUrl = uri("https://nexus.telesphoreo.me/repository/plex-releases/")
val snapshotsRepoUrl = uri("https://nexus.telesphoreo.me/repository/plex-snapshots/")
url = if (rootProject.version.toString().endsWith("SNAPSHOT")) snapshotsRepoUrl else releasesRepoUrl
credentials {
username = System.getenv("plexUser")
password = System.getenv("plexPassword")
}
}
}
}
}
tasks.clean {
dependsOn(subprojects.map {
it.project.tasks.clean
})
}
tasks.create<Copy>("copyJars") {
dependsOn(tasks.jar)
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
from(subprojects.map {
it.project.tasks.shadowJar
})
from(subprojects.map {
it.project.tasks.jar
})
into(file("build/libs"))
}

Binary file not shown.

View File

@ -1,5 +1,7 @@
distributionBase=GRADLE_USER_HOME distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions-snapshots/gradle-7.6-20220825090952+0000-bin.zip distributionUrl=https\://services.gradle.org/distributions/gradle-8.8-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists zipStorePath=wrapper/dists

41
gradlew vendored
View File

@ -55,7 +55,7 @@
# Darwin, MinGW, and NonStop. # Darwin, MinGW, and NonStop.
# #
# (3) This script is generated from the Groovy template # (3) This script is generated from the Groovy template
# https://github.com/gradle/gradle/blob/master/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt # https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
# within the Gradle project. # within the Gradle project.
# #
# You can find Gradle at https://github.com/gradle/gradle/. # You can find Gradle at https://github.com/gradle/gradle/.
@ -80,13 +80,11 @@ do
esac esac
done done
APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit # This is normally unused
# shellcheck disable=SC2034
APP_NAME="Gradle"
APP_BASE_NAME=${0##*/} APP_BASE_NAME=${0##*/}
# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036)
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. APP_HOME=$( cd "${APP_HOME:-./}" > /dev/null && pwd -P ) || exit
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
# Use the maximum available, or set MAX_FD != -1 to use that value. # Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD=maximum MAX_FD=maximum
@ -133,22 +131,29 @@ location of your Java installation."
fi fi
else else
JAVACMD=java JAVACMD=java
which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. if ! command -v java >/dev/null 2>&1
then
die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
Please set the JAVA_HOME variable in your environment to match the Please set the JAVA_HOME variable in your environment to match the
location of your Java installation." location of your Java installation."
fi fi
fi
# Increase the maximum file descriptors if we can. # Increase the maximum file descriptors if we can.
if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
case $MAX_FD in #( case $MAX_FD in #(
max*) max*)
# In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked.
# shellcheck disable=SC2039,SC3045
MAX_FD=$( ulimit -H -n ) || MAX_FD=$( ulimit -H -n ) ||
warn "Could not query maximum file descriptor limit" warn "Could not query maximum file descriptor limit"
esac esac
case $MAX_FD in #( case $MAX_FD in #(
'' | soft) :;; #( '' | soft) :;; #(
*) *)
# In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked.
# shellcheck disable=SC2039,SC3045
ulimit -n "$MAX_FD" || ulimit -n "$MAX_FD" ||
warn "Could not set maximum file descriptor limit to $MAX_FD" warn "Could not set maximum file descriptor limit to $MAX_FD"
esac esac
@ -193,11 +198,15 @@ if "$cygwin" || "$msys" ; then
done done
fi fi
# Collect all arguments for the java command;
# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
# shell script including quotes and variable substitutions, so put them in DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
# double quotes to make sure that they get re-expanded; and
# * put everything else in single quotes, so that it's not re-expanded. # Collect all arguments for the java command:
# * DEFAULT_JVM_OPTS, JAVA_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments,
# and any embedded shellness will be escaped.
# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be
# treated as '${Hostname}' itself on the command line.
set -- \ set -- \
"-Dorg.gradle.appname=$APP_BASE_NAME" \ "-Dorg.gradle.appname=$APP_BASE_NAME" \
@ -205,6 +214,12 @@ set -- \
org.gradle.wrapper.GradleWrapperMain \ org.gradle.wrapper.GradleWrapperMain \
"$@" "$@"
# Stop when "xargs" is not available.
if ! command -v xargs >/dev/null 2>&1
then
die "xargs is not available"
fi
# Use "xargs" to parse quoted args. # Use "xargs" to parse quoted args.
# #
# With -n1 it outputs one arg per line, with the quotes and backslashes removed. # With -n1 it outputs one arg per line, with the quotes and backslashes removed.

11
gradlew.bat vendored
View File

@ -26,6 +26,7 @@ if "%OS%"=="Windows_NT" setlocal
set DIRNAME=%~dp0 set DIRNAME=%~dp0
if "%DIRNAME%"=="" set DIRNAME=. if "%DIRNAME%"=="" set DIRNAME=.
@rem This is normally unused
set APP_BASE_NAME=%~n0 set APP_BASE_NAME=%~n0
set APP_HOME=%DIRNAME% set APP_HOME=%DIRNAME%
@ -40,7 +41,7 @@ if defined JAVA_HOME goto findJavaFromJavaHome
set JAVA_EXE=java.exe set JAVA_EXE=java.exe
%JAVA_EXE% -version >NUL 2>&1 %JAVA_EXE% -version >NUL 2>&1
if "%ERRORLEVEL%" == "0" goto execute if %ERRORLEVEL% equ 0 goto execute
echo. echo.
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
@ -75,13 +76,15 @@ set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
:end :end
@rem End local scope for the variables with windows NT shell @rem End local scope for the variables with windows NT shell
if "%ERRORLEVEL%"=="0" goto mainEnd if %ERRORLEVEL% equ 0 goto mainEnd
:fail :fail
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
rem the _cmd.exe /c_ return code! rem the _cmd.exe /c_ return code!
if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 set EXIT_CODE=%ERRORLEVEL%
exit /b 1 if %EXIT_CODE% equ 0 set EXIT_CODE=1
if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE%
exit /b %EXIT_CODE%
:mainEnd :mainEnd
if "%OS%"=="Windows_NT" endlocal if "%OS%"=="Windows_NT" endlocal

View File

@ -1,13 +1,9 @@
plugins {
id("net.kyori.blossom") version "1.3.0"
}
group = rootProject.group group = rootProject.group
version = rootProject.version version = rootProject.version
description = "Plex-Velocity" description = "Plex-Velocity"
repositories { repositories {
maven { url = uri("https://papermc.io/repo/repository/maven-public/") } maven { url = uri("https://repo.papermc.io/repository/maven-public/") }
} }
tasks.getByName<Jar>("jar") { tasks.getByName<Jar>("jar") {
@ -24,8 +20,14 @@ tasks {
} }
} }
sourceSets {
main {
blossom { blossom {
replaceToken("@version@", rootProject.version) javaSources {
property("version", project.version.toString())
}
}
}
} }
publishing { publishing {
@ -37,9 +39,9 @@ publishing {
} }
dependencies { dependencies {
compileOnly("org.projectlombok:lombok:1.18.24") compileOnly("org.projectlombok:lombok:1.18.32")
annotationProcessor("org.projectlombok:lombok:1.18.24") annotationProcessor("org.projectlombok:lombok:1.18.32")
compileOnly("org.json:json:20220320") compileOnly("org.json:json:20240303")
compileOnly("com.velocitypowered:velocity-api:3.1.2-SNAPSHOT") compileOnly("com.velocitypowered:velocity-api:3.2.0-SNAPSHOT")
annotationProcessor("com.velocitypowered:velocity-api:3.1.2-SNAPSHOT") annotationProcessor("com.velocitypowered:velocity-api:3.2.0-SNAPSHOT")
} }

View File

@ -0,0 +1,5 @@
package dev.plex;
class BuildParameters {
public static final String VERSION = "{{ version }}";
}

View File

@ -10,10 +10,11 @@ import dev.plex.config.TomlConfig;
import dev.plex.handlers.ListenerHandler; import dev.plex.handlers.ListenerHandler;
import dev.plex.settings.ServerSettings; import dev.plex.settings.ServerSettings;
import dev.plex.util.PlexLog; import dev.plex.util.PlexLog;
import lombok.Getter;
import java.io.File; import java.io.File;
import java.nio.file.Path; import java.nio.file.Path;
import java.util.logging.Logger; import java.util.logging.Logger;
import lombok.Getter;
/** /**
* Credits for TOML library go to https://github.com/mwanji/toml4j * Credits for TOML library go to https://github.com/mwanji/toml4j
@ -27,7 +28,7 @@ import lombok.Getter;
@Plugin( @Plugin(
name = "Plex", name = "Plex",
id = "plex", id = "plex",
version = "@version@", version = BuildParameters.VERSION,
url = "https://plex.us.org", url = "https://plex.us.org",
description = "Plex provides a new experience for freedom servers.", description = "Plex provides a new experience for freedom servers.",
authors = {"Telesphoreo", "Taah"} authors = {"Telesphoreo", "Taah"}

View File

@ -9,12 +9,13 @@ import dev.plex.Plex;
import dev.plex.command.annotation.CommandParameters; import dev.plex.command.annotation.CommandParameters;
import dev.plex.command.annotation.CommandPermissions; import dev.plex.command.annotation.CommandPermissions;
import dev.plex.command.source.RequiredCommandSource; import dev.plex.command.source.RequiredCommandSource;
import java.util.Arrays;
import net.kyori.adventure.audience.Audience; import net.kyori.adventure.audience.Audience;
import net.kyori.adventure.text.Component; import net.kyori.adventure.text.Component;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
import java.util.Arrays;
public abstract class PlexCommand implements SimpleCommand public abstract class PlexCommand implements SimpleCommand
{ {
/** /**

View File

@ -1,6 +1,7 @@
package dev.plex.command.annotation; package dev.plex.command.annotation;
import dev.plex.command.source.RequiredCommandSource; import dev.plex.command.source.RequiredCommandSource;
import java.lang.annotation.Retention; import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy; import java.lang.annotation.RetentionPolicy;

View File

@ -3,12 +3,13 @@ package dev.plex.config;
import dev.plex.Plex; import dev.plex.Plex;
import dev.plex.toml.Toml; import dev.plex.toml.Toml;
import dev.plex.toml.TomlWriter; import dev.plex.toml.TomlWriter;
import lombok.Getter;
import lombok.Setter;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.nio.file.Files; import java.nio.file.Files;
import java.util.function.Consumer; import java.util.function.Consumer;
import lombok.Getter;
import lombok.Setter;
@Getter @Getter
public class TomlConfig public class TomlConfig

View File

@ -4,6 +4,7 @@ import com.google.common.collect.Lists;
import dev.plex.listener.PlexListener; import dev.plex.listener.PlexListener;
import dev.plex.util.PlexLog; import dev.plex.util.PlexLog;
import dev.plex.util.ReflectionsUtil; import dev.plex.util.ReflectionsUtil;
import java.lang.reflect.InvocationTargetException; import java.lang.reflect.InvocationTargetException;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;

View File

@ -7,13 +7,14 @@ import com.velocitypowered.api.proxy.server.ServerPing;
import dev.plex.listener.PlexListener; import dev.plex.listener.PlexListener;
import dev.plex.settings.ServerSettings; import dev.plex.settings.ServerSettings;
import dev.plex.util.RandomUtil; import dev.plex.util.RandomUtil;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.minimessage.MiniMessage;
import java.util.UUID; import java.util.UUID;
import java.util.concurrent.ThreadLocalRandom; import java.util.concurrent.ThreadLocalRandom;
import java.util.concurrent.atomic.AtomicReference; import java.util.concurrent.atomic.AtomicReference;
import java.util.regex.Matcher; import java.util.regex.Matcher;
import java.util.regex.Pattern; import java.util.regex.Pattern;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.minimessage.MiniMessage;
public class ServerListener extends PlexListener public class ServerListener extends PlexListener
{ {

View File

@ -2,10 +2,11 @@ package dev.plex.settings;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
import com.google.gson.annotations.SerializedName; import com.google.gson.annotations.SerializedName;
import java.util.List;
import lombok.Data; import lombok.Data;
import lombok.Getter; import lombok.Getter;
import java.util.List;
@Getter @Getter
public class ServerSettings public class ServerSettings
{ {

View File

@ -4,6 +4,7 @@ package dev.plex.toml;
import java.lang.reflect.Array; import java.lang.reflect.Array;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import static dev.plex.toml.ValueWriters.WRITERS; import static dev.plex.toml.ValueWriters.WRITERS;
public abstract class ArrayValueWriter implements dev.plex.toml.ValueWriter public abstract class ArrayValueWriter implements dev.plex.toml.ValueWriter

View File

@ -1,14 +1,10 @@
package dev.plex.toml; package dev.plex.toml;
import com.google.gson.annotations.SerializedName; import com.google.gson.annotations.SerializedName;
import java.lang.reflect.Field; import java.lang.reflect.Field;
import java.lang.reflect.Modifier; import java.lang.reflect.Modifier;
import java.util.Arrays; import java.util.*;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.Map;
import java.util.Set;
class ObjectValueWriter implements ValueWriter class ObjectValueWriter implements ValueWriter
{ {

View File

@ -1,11 +1,6 @@
package dev.plex.toml; package dev.plex.toml;
import java.util.ArrayDeque; import java.util.*;
import java.util.Deque;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicInteger;
class Results class Results

View File

@ -1,6 +1,7 @@
package dev.plex.toml; package dev.plex.toml;
import java.util.Collection; import java.util.Collection;
import static dev.plex.toml.ValueWriters.WRITERS; import static dev.plex.toml.ValueWriters.WRITERS;
class TableArrayValueWriter extends ArrayValueWriter class TableArrayValueWriter extends ArrayValueWriter

View File

@ -2,23 +2,12 @@ package dev.plex.toml;
import com.google.gson.Gson; import com.google.gson.Gson;
import com.google.gson.JsonElement; import com.google.gson.JsonElement;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.Reader;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import lombok.Getter; import lombok.Getter;
import java.io.*;
import java.nio.charset.StandardCharsets;
import java.util.*;
/** /**
* <p>Provides access to the keys and tables in a TOML data source.</p> * <p>Provides access to the keys and tables in a TOML data source.</p>
* *

View File

@ -1,17 +1,13 @@
package dev.plex.toml; package dev.plex.toml;
import java.io.File; import org.jetbrains.annotations.Nullable;
import java.io.FileOutputStream;
import java.io.IOException; import java.io.*;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.StringWriter;
import java.io.Writer;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.TimeZone; import java.util.TimeZone;
import org.jetbrains.annotations.Nullable;
import static dev.plex.toml.ValueWriters.WRITERS; import static dev.plex.toml.ValueWriters.WRITERS;
/** /**

View File

@ -1,6 +1,7 @@
package dev.plex.toml; package dev.plex.toml;
import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicInteger;
import static dev.plex.toml.ArrayValueReader.ARRAY_VALUE_READER; import static dev.plex.toml.ArrayValueReader.ARRAY_VALUE_READER;
import static dev.plex.toml.BooleanValueReaderWriter.BOOLEAN_VALUE_READER_WRITER; import static dev.plex.toml.BooleanValueReaderWriter.BOOLEAN_VALUE_READER_WRITER;
import static dev.plex.toml.DateValueReaderWriter.DATE_VALUE_READER_WRITER; import static dev.plex.toml.DateValueReaderWriter.DATE_VALUE_READER_WRITER;

View File

@ -1,8 +1,9 @@
package dev.plex.util; package dev.plex.util;
import java.util.concurrent.ThreadLocalRandom;
import net.kyori.adventure.text.format.NamedTextColor; import net.kyori.adventure.text.format.NamedTextColor;
import java.util.concurrent.ThreadLocalRandom;
public class RandomUtil public class RandomUtil
{ {
public static NamedTextColor getRandomColor() public static NamedTextColor getRandomColor()

View File

@ -3,6 +3,7 @@ package dev.plex.util;
import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet;
import com.google.common.reflect.ClassPath; import com.google.common.reflect.ClassPath;
import dev.plex.Plex; import dev.plex.Plex;
import java.io.IOException; import java.io.IOException;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collections; import java.util.Collections;

View File

@ -1,139 +0,0 @@
plugins {
id "net.minecrell.plugin-yml.bukkit" version "0.5.2"
}
dependencies {
library "org.projectlombok:lombok:1.18.24"
annotationProcessor "org.projectlombok:lombok:1.18.24"
library "org.json:json:20220320"
library "commons-io:commons-io:2.11.0"
library "dev.morphia.morphia:morphia-core:2.2.7"
library "redis.clients:jedis:4.2.3"
library "org.mariadb.jdbc:mariadb-java-client:3.0.6"
library "com.zaxxer:HikariCP:5.0.1"
library "org.apache.httpcomponents.client5:httpclient5:5.2-beta1"
library "org.apache.commons:commons-lang3:3.12.0"
library "org.apache.maven.resolver:maven-resolver-api:1.8.2"
library "org.apache.maven.resolver:maven-resolver-impl:1.8.2"
library "org.apache.maven.resolver:maven-resolver-connector-basic:1.8.2"
library "org.apache.maven.resolver:maven-resolver-transport-http:1.8.2"
library "org.apache.maven:maven-resolver-provider:3.8.5"
library "org.eclipse.jetty:jetty-server:11.0.11"
library "org.eclipse.jetty:jetty-servlet:11.0.11"
library "org.eclipse.jetty:jetty-proxy:11.0.11"
library "com.google.code.gson:gson:2.9.0"
compileOnly "io.papermc.paper:paper-api:1.19.2-R0.1-SNAPSHOT"
compileOnly("com.github.MilkBowl:VaultAPI:1.7.1") {
exclude group: "org.bukkit", module: "bukkit"
}
implementation "org.bstats:bstats-base:3.0.0"
implementation "org.bstats:bstats-bukkit:3.0.0"
}
group = rootProject.group
version = rootProject.version
description = "Plex-Server"
shadowJar {
archiveBaseName.set("Plex")
archiveClassifier.set("")
relocate "org.bstats", "dev.plex"
}
bukkit {
name = "Plex"
version = project.version
description = "Plex provides a new experience for freedom servers."
main = "dev.plex.Plex"
website = "https://plex.us.org"
authors = ["Telesphoreo", "taahanis", "supernt"]
softDepend = ["Vault"]
apiVersion = "1.18"
}
String getGitHash() {
def stdout = new ByteArrayOutputStream()
try {
exec {
commandLine "git", "rev-parse", "--short", "HEAD"
standardOutput = stdout
ignoreExitValue = true
}
} catch (GradleException e) {
logger.error("Couldn't determine Git head because Git is not installed. " + e.getMessage())
}
return stdout.size() > 0 ? stdout.toString().trim() : "unknown"
}
String getBuildNumber() {
def stdout = new ByteArrayOutputStream()
try {
exec {
commandLine "git", "rev-list", "HEAD", "--count"
standardOutput = stdout
ignoreExitValue = true
}
} catch (GradleException e) {
logger.error("Couldn't determine build number because Git is not installed. " + e.getMessage())
}
return stdout.size() ? stdout.toString().trim() + " (local)" : "unknown"
}
static def getDate() {
return new Date().format("MM/dd/yyyy '<light_purple>at<gold>' hh:mm:ss a z")
}
task buildProperties {
ant.propertyfile(file: "$project.projectDir/src/main/resources/build.properties") {
entry(key: "buildAuthor", default: System.getenv("JENKINS_URL") != null ? "jenkins" : "unknown")
entry(key: "buildNumber", value: System.getenv("JENKINS_URL") != null ? System.getenv("BUILD_NUMBER") + " (Jenkins)" : getBuildNumber())
entry(key: "buildDate", value: getDate())
entry(key: "buildHead", value: getGitHash())
}
}
tasks {
build {
dependsOn(shadowJar)
finalizedBy(buildProperties)
}
jar {
enabled = false
}
shadowJar {
finalizedBy(rootProject.tasks.copyJars)
}
javadoc {
options.memberLevel = JavadocMemberLevel.PRIVATE
}
}
publishing {
publications {
maven(MavenPublication) {
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]
}
}
}

168
server/build.gradle.kts Normal file
View File

@ -0,0 +1,168 @@
import net.minecrell.pluginyml.paper.PaperPluginDescription
import java.io.ByteArrayOutputStream
import java.text.SimpleDateFormat
import java.util.*
plugins {
id("net.kyori.indra.git") version "3.1.3"
id("net.minecrell.plugin-yml.paper") version "0.6.0"
}
repositories {
maven(url = uri("https://maven.playpro.com"))
maven(url = uri("https://nexus.telesphoreo.me/repository/plex-modules/"))
}
dependencies {
library("org.projectlombok:lombok:1.18.32")
library("org.json:json:20240303")
library("commons-io:commons-io:2.16.1")
library("redis.clients:jedis:5.1.3")
library("org.mariadb.jdbc:mariadb-java-client:3.4.0")
library("com.zaxxer:HikariCP:5.1.0")
library("org.apache.maven.resolver:maven-resolver-transport-http:1.9.20")
library("org.jetbrains:annotations:24.1.0")
compileOnly("dev.folia:folia-api:1.20.4-R0.1-SNAPSHOT")
compileOnly("com.github.MilkBowl:VaultAPI:1.7.1") {
exclude("org.bukkit", "bukkit")
}
compileOnly("net.coreprotect:coreprotect:22.4")
compileOnly("network.darkhelmet.prism:Prism-Api:1.0.0")
implementation("org.bstats:bstats-base:3.0.2")
implementation("org.bstats:bstats-bukkit:3.0.2")
implementation("com.github.LeonMangler:SuperVanish:6.2.18-3")
annotationProcessor("org.projectlombok:lombok:1.18.32")
}
group = rootProject.group
version = rootProject.version
description = "Plex-Server"
paper {
name = "Plex"
version = rootProject.version.toString()
description = "Plex provides a new experience for freedom servers."
main = "dev.plex.Plex"
loader = "dev.plex.PlexLibraryManager"
website = "https://plex.us.org"
authors = listOf("Telesphoreo", "taahanis", "supernt")
apiVersion = "1.19"
foliaSupported = true
generateLibrariesJson = true
// Load BukkitTelnet and LibsDisguises before Plex so the modules register properly
serverDependencies {
register("BukkitTelnet") {
required = false
load = PaperPluginDescription.RelativeLoadOrder.BEFORE
}
register("Essentials") {
required = false
load = PaperPluginDescription.RelativeLoadOrder.BEFORE
}
register("LibsDisguises") {
required = false
load = PaperPluginDescription.RelativeLoadOrder.BEFORE
}
register("Prism") {
required = false
load = PaperPluginDescription.RelativeLoadOrder.BEFORE
}
register("CoreProtect") {
required = false
load = PaperPluginDescription.RelativeLoadOrder.BEFORE
}
register("PremiumVanish") {
required = false
load = PaperPluginDescription.RelativeLoadOrder.BEFORE
}
register("SlimeWorldManager") {
required = false
load = PaperPluginDescription.RelativeLoadOrder.AFTER
}
register("SuperVanish") {
required = false
load = PaperPluginDescription.RelativeLoadOrder.BEFORE
}
register("Vault") {
required = false
load = PaperPluginDescription.RelativeLoadOrder.BEFORE
}
}
}
fun getBuildNumber(): String {
val stdout = ByteArrayOutputStream()
try {
exec {
commandLine("git", "rev-list", "HEAD", "--count")
standardOutput = stdout
isIgnoreExitValue = true
}
} catch (e: GradleException) {
logger.error("Couldn't determine build number because Git is not installed. " + e.message)
}
return if (stdout.size() > 0) stdout.toString().trim() else "unknown"
}
tasks {
build {
dependsOn(shadowJar)
}
jar {
enabled = false
}
sourceSets {
main {
blossom {
resources {
property("author", if (System.getenv("JENKINS_URL") != null) "jenkins" else System.getProperty("user.name"))
property("buildNumber", if (System.getenv("BUILD_NUMBER") != null) System.getenv("BUILD_NUMBER") else getBuildNumber())
property("date", SimpleDateFormat("MM/dd/yyyy '<light_purple>at<gold>' hh:mm:ss a z").format(Date()))
property("gitCommit", indraGit.commit()?.name?.take(7))
}
}
}
}
shadowJar {
archiveBaseName.set("Plex")
archiveClassifier.set("")
relocate("org.bstats", "dev.plex")
finalizedBy(rootProject.tasks["copyJars"])
}
javadoc {
options.memberLevel = JavadocMemberLevel.PRIVATE
}
}
publishing {
publications {
create<MavenPublication>("maven") {
pom.withXml {
val dependenciesNode = asNode().appendNode("dependencies")
configurations.getByName("library").allDependencies.configureEach {
dependenciesNode.appendNode("dependency")
.appendNode("groupId", group).parent()
.appendNode("artifactId", name).parent()
.appendNode("version", version).parent()
.appendNode("scope", "provided").parent()
}
configurations.getByName("implementation").allDependencies.configureEach {
dependenciesNode.appendNode("dependency")
.appendNode("groupId", group).parent()
.appendNode("artifactId", name).parent()
.appendNode("version", version).parent()
.appendNode("scope", "provided").parent()
}
}
artifacts.artifact(tasks.shadowJar)
}
}
}

View File

@ -1,23 +1,19 @@
package dev.plex; package dev.plex;
import dev.plex.admin.Admin;
import dev.plex.admin.AdminList;
import dev.plex.cache.DataUtils; import dev.plex.cache.DataUtils;
import dev.plex.cache.PlayerCache; import dev.plex.cache.PlayerCache;
import dev.plex.config.Config; import dev.plex.config.Config;
import dev.plex.handlers.CommandHandler; import dev.plex.handlers.CommandHandler;
import dev.plex.handlers.ListenerHandler; import dev.plex.handlers.ListenerHandler;
import dev.plex.hook.CoreProtectHook;
import dev.plex.hook.PrismHook;
import dev.plex.module.ModuleManager; import dev.plex.module.ModuleManager;
import dev.plex.player.PlexPlayer; import dev.plex.player.PlexPlayer;
import dev.plex.punishment.PunishmentManager; import dev.plex.punishment.PunishmentManager;
import dev.plex.rank.RankManager;
import dev.plex.services.ServiceManager; import dev.plex.services.ServiceManager;
import dev.plex.storage.MongoConnection;
import dev.plex.storage.RedisConnection; import dev.plex.storage.RedisConnection;
import dev.plex.storage.SQLConnection; import dev.plex.storage.SQLConnection;
import dev.plex.storage.StorageType; 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.player.SQLPlayerData;
import dev.plex.storage.punishment.SQLNotes; import dev.plex.storage.punishment.SQLNotes;
import dev.plex.storage.punishment.SQLPunishment; import dev.plex.storage.punishment.SQLPunishment;
@ -52,30 +48,24 @@ public class Plex extends JavaPlugin
public File modulesFolder; public File modulesFolder;
private StorageType storageType = StorageType.SQLITE; private StorageType storageType = StorageType.SQLITE;
private SQLConnection sqlConnection; private SQLConnection sqlConnection;
private MongoConnection mongoConnection;
private RedisConnection redisConnection; private RedisConnection redisConnection;
private PlayerCache playerCache; private PlayerCache playerCache;
private MongoPlayerData mongoPlayerData;
private SQLPlayerData sqlPlayerData; private SQLPlayerData sqlPlayerData;
private SQLPunishment sqlPunishment; private SQLPunishment sqlPunishment;
private SQLNotes sqlNotes; private SQLNotes sqlNotes;
private SQLPermissions sqlPermissions;
private ModuleManager moduleManager; private ModuleManager moduleManager;
private RankManager rankManager;
private ServiceManager serviceManager; private ServiceManager serviceManager;
private PunishmentManager punishmentManager; private PunishmentManager punishmentManager;
private AdminList adminList;
private UpdateChecker updateChecker; private UpdateChecker updateChecker;
private String system;
private Permission permissions; private Permission permissions;
private Chat chat; private Chat chat;
private CoreProtectHook coreProtectHook;
private PrismHook prismHook;
public static Plex get() public static Plex get()
{ {
@ -119,13 +109,10 @@ public class Plex extends JavaPlugin
commands.load(false); commands.load(false);
sqlConnection = new SQLConnection(); sqlConnection = new SQLConnection();
mongoConnection = new MongoConnection();
redisConnection = new RedisConnection(); redisConnection = new RedisConnection();
playerCache = new PlayerCache(); playerCache = new PlayerCache();
system = config.getString("system");
PlexLog.log("Attempting to connect to DB: {0}", plugin.config.getString("data.central.db")); PlexLog.log("Attempting to connect to DB: {0}", plugin.config.getString("data.central.db"));
try try
{ {
@ -138,15 +125,38 @@ public class Plex extends JavaPlugin
e.printStackTrace(); e.printStackTrace();
} }
if (system.equals("permissions"))
{
if (!getServer().getPluginManager().isPluginEnabled("Vault")) if (!getServer().getPluginManager().isPluginEnabled("Vault"))
{ {
throw new RuntimeException("Vault is required to run on the server if you use permissions!"); throw new RuntimeException("Vault is required to run on the server alongside a permissions plugin, we recommend LuckPerms!");
} }
permissions = setupPermissions(); permissions = setupPermissions();
chat = setupChat(); chat = setupChat();
if (plugin.getServer().getPluginManager().isPluginEnabled("CoreProtect"))
{
PlexLog.log("Hooked into CoreProtect!");
coreProtectHook = new CoreProtectHook(this);
}
else
{
PlexLog.debug("Not hooking into CoreProtect");
}
if (plugin.getServer().getPluginManager().isPluginEnabled("Prism"))
{
PlexLog.log("Hooked into Prism!");
prismHook = new PrismHook(this);
}
else
{
PlexLog.debug("Not hooking into Prism");
}
if (PlexUtils.hasVanishPlugin())
{
PlexLog.log("Hooked into SuperVanish / PremiumVanish!");
} else {
PlexLog.debug("Not hooking into SuperVanish / PremiumVanish");
} }
updateChecker = new UpdateChecker(); updateChecker = new UpdateChecker();
@ -168,32 +178,22 @@ public class Plex extends JavaPlugin
PlexLog.log("Redis is disabled in the configuration file, not connecting."); PlexLog.log("Redis is disabled in the configuration file, not connecting.");
} }
if (storageType == StorageType.MONGODB)
{
mongoPlayerData = new MongoPlayerData();
}
else
{
sqlPlayerData = new SQLPlayerData(); sqlPlayerData = new SQLPlayerData();
sqlPunishment = new SQLPunishment(); sqlPunishment = new SQLPunishment();
sqlNotes = new SQLNotes(); sqlNotes = new SQLNotes();
sqlPermissions = new SQLPermissions();
}
new ListenerHandler(); new ListenerHandler();
new CommandHandler(); new CommandHandler();
rankManager = new RankManager();
rankManager.generateDefaultRanks();
rankManager.importDefaultRanks();
adminList = new AdminList();
PlexLog.log("Rank Manager initialized");
punishmentManager = new PunishmentManager(); punishmentManager = new PunishmentManager();
punishmentManager.mergeIndefiniteBans(); punishmentManager.mergeIndefiniteBans();
PlexLog.log("Punishment System initialized"); PlexLog.log("Punishment System initialized");
if (!PlexUtils.isFolia())
{
// World generation is not supported on Folia yet
generateWorlds(); generateWorlds();
}
serviceManager = new ServiceManager(); serviceManager = new ServiceManager();
PlexLog.log("Service Manager initialized"); PlexLog.log("Service Manager initialized");
@ -219,20 +219,7 @@ public class Plex extends JavaPlugin
Bukkit.getOnlinePlayers().forEach(player -> Bukkit.getOnlinePlayers().forEach(player ->
{ {
PlexPlayer plexPlayer = playerCache.getPlexPlayerMap().get(player.getUniqueId()); //get the player because it's literally impossible for them to not have an object PlexPlayer plexPlayer = playerCache.getPlexPlayerMap().get(player.getUniqueId()); //get the player because it's literally impossible for them to not have an object
if (plugin.getRankManager().isAdmin(plexPlayer))
{
plugin.getAdminList().removeFromCache(plexPlayer.getUuid());
}
if (mongoPlayerData != null) //back to mongo checking
{
mongoPlayerData.update(plexPlayer); //update the player's document
}
else if (sqlPlayerData != null) //sql checking
{
sqlPlayerData.update(plexPlayer); sqlPlayerData.update(plexPlayer);
}
}); });
if (redisConnection != null && redisConnection.isEnabled() && redisConnection.getJedis().isConnected()) if (redisConnection != null && redisConnection.isEnabled() && redisConnection.getJedis().isConnected())
{ {
@ -261,13 +248,6 @@ public class Plex extends JavaPlugin
{ {
PlexPlayer plexPlayer = DataUtils.getPlayer(player.getUniqueId()); PlexPlayer plexPlayer = DataUtils.getPlayer(player.getUniqueId());
playerCache.getPlexPlayerMap().put(player.getUniqueId(), plexPlayer); //put them into the cache playerCache.getPlexPlayerMap().put(player.getUniqueId(), plexPlayer); //put them into the cache
if (plugin.getRankManager().isAdmin(plexPlayer))
{
Admin admin = new Admin(plexPlayer.getUuid());
admin.setRank(plexPlayer.getRankFromString());
plugin.getAdminList().addToCache(admin);
}
}); });
} }

View File

@ -0,0 +1,65 @@
package dev.plex;
import com.google.gson.Gson;
import io.papermc.paper.plugin.loader.PluginClasspathBuilder;
import io.papermc.paper.plugin.loader.PluginLoader;
import io.papermc.paper.plugin.loader.library.impl.MavenLibraryResolver;
import org.eclipse.aether.artifact.DefaultArtifact;
import org.eclipse.aether.graph.Dependency;
import org.eclipse.aether.repository.RemoteRepository;
import org.jetbrains.annotations.NotNull;
import java.io.File;
import java.io.IOException;
import java.io.InputStreamReader;
import java.nio.charset.StandardCharsets;
import java.util.List;
import java.util.Map;
import java.util.stream.Stream;
public class PlexLibraryManager implements PluginLoader
{
@Override
public void classloader(@NotNull PluginClasspathBuilder classpathBuilder)
{
MavenLibraryResolver resolver = new MavenLibraryResolver();
PluginLibraries pluginLibraries = load();
pluginLibraries.asDependencies().forEach(resolver::addDependency);
pluginLibraries.asRepositories().forEach(resolver::addRepository);
// The plugin is null, a hacky way to check whether to load Jetty or not
if (new File("plugins/Plex/modules/Module-HTTPD.jar").isFile())
{
resolver.addDependency(new Dependency(new DefaultArtifact("org.eclipse.jetty:jetty-server:11.0.19"), null));
resolver.addDependency(new Dependency(new DefaultArtifact("org.eclipse.jetty:jetty-servlet:11.0.19"), null));
resolver.addDependency(new Dependency(new DefaultArtifact("org.eclipse.jetty:jetty-proxy:11.0.19"), null));
}
classpathBuilder.addLibrary(resolver);
}
public PluginLibraries load()
{
try (var in = getClass().getResourceAsStream("/paper-libraries.json"))
{
return new Gson().fromJson(new InputStreamReader(in, StandardCharsets.UTF_8), PluginLibraries.class);
}
catch (IOException e)
{
throw new RuntimeException(e);
}
}
private record PluginLibraries(Map<String, String> repositories, List<String> dependencies)
{
public Stream<Dependency> asDependencies()
{
return dependencies.stream()
.map(d -> new Dependency(new DefaultArtifact(d), null));
}
public Stream<RemoteRepository> asRepositories()
{
return repositories.entrySet().stream()
.map(e -> new RemoteRepository.Builder(e.getKey(), "default", e.getValue()).build());
}
}
}

View File

@ -1,55 +0,0 @@
package dev.plex.admin;
import dev.plex.rank.enums.Rank;
import java.util.UUID;
import lombok.AccessLevel;
import lombok.Getter;
import lombok.Setter;
/**
* Admin object to handle cached admins
*/
@Getter
@Setter
public class Admin
{
/**
* Gets the unique ID of an admin (immutable)
*/
@Setter(AccessLevel.NONE)
private UUID uuid;
/**
* Gets the rank of the admin
* <br>
* Contains a #setRank and #getRank by lombok
*/
private Rank rank;
/**
* Returns if the admin has command spy or not
* <br>
* Contains a #isCommandSpy and #setCommandSpy by Lombok
*/
private boolean commandSpy = false;
/**
* Returns if the admin has admin chat toggled or not
* <br>
* Contains a #isAdminChat and #setAdminChat by Lombok
*/
private boolean adminChat = false;
/**
* Creates an admin with the ADMIN rank as the default rank
*
* @param uuid
* @see UUID
* @see Rank
*/
public Admin(UUID uuid)
{
this.uuid = uuid;
this.rank = Rank.ADMIN;
}
}

View File

@ -1,150 +0,0 @@
package dev.plex.admin;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.google.common.reflect.TypeToken;
import com.google.gson.Gson;
import dev.morphia.Datastore;
import dev.morphia.query.Query;
import dev.plex.PlexBase;
import dev.plex.player.PlexPlayer;
import dev.plex.rank.enums.Rank;
import dev.plex.storage.StorageType;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import java.util.stream.Collectors;
/**
* Cached storage for Admin objects
*
* @see Admin
*/
public class AdminList implements PlexBase
{
/**
* Key / Value storage, where the key is the unique ID of the admin
*/
private final Map<UUID, Admin> admins = Maps.newHashMap();
/**
* Adds the admin to cache
*
* @param admin The admin object
*/
public void addToCache(Admin admin)
{
admins.put(admin.getUuid(), admin);
}
/**
* Removes an admin from the cache
*
* @param uuid The unique ID of the admin
* @see UUID
*/
public void removeFromCache(UUID uuid)
{
admins.remove(uuid);
}
/**
* Gathers every admins username (cached and in the database)
*
* @return An array list of the names of every admin
*/
public List<String> getAllAdmins()
{
List<String> admins = Lists.newArrayList();
if (plugin.getStorageType() == StorageType.MONGODB)
{
Datastore store = plugin.getMongoConnection().getDatastore();
Query<PlexPlayer> query = store.find(PlexPlayer.class);
admins.addAll(query.stream().filter(plexPlayer -> plexPlayer.getRankFromString().isAtLeast(Rank.ADMIN) && plexPlayer.isAdminActive()).map(PlexPlayer::getName).toList());
}
else
{
try (Connection con = plugin.getSqlConnection().getCon())
{
PreparedStatement statement = con.prepareStatement("SELECT * FROM `players` WHERE rank IN(?, ?, ?) AND adminActive=true");
statement.setString(1, Rank.ADMIN.name().toLowerCase());
statement.setString(2, Rank.SENIOR_ADMIN.name().toLowerCase());
statement.setString(3, Rank.EXECUTIVE.name().toLowerCase());
ResultSet set = statement.executeQuery();
while (set.next())
{
admins.add(set.getString("name"));
}
}
catch (SQLException throwables)
{
throwables.printStackTrace();
}
}
return admins;
}
/**
* Gathers every admin (cached and in the database)
*
* @return An array list of the names of every admin
*/
public List<PlexPlayer> getAllAdminPlayers()
{
List<PlexPlayer> plexPlayers = Lists.newArrayList();
if (plugin.getStorageType() == StorageType.MONGODB)
{
Datastore store = plugin.getMongoConnection().getDatastore();
Query<PlexPlayer> query = store.find(PlexPlayer.class);
return query.stream().toList().stream().filter(player -> plugin.getRankManager().isAdmin(player)).collect(Collectors.toList());
}
else
{
try (Connection con = plugin.getSqlConnection().getCon())
{
PreparedStatement statement = con.prepareStatement("SELECT * FROM `players` WHERE rank IN(?, ?, ?) AND adminActive=true");
statement.setString(1, Rank.ADMIN.name().toLowerCase());
statement.setString(2, Rank.SENIOR_ADMIN.name().toLowerCase());
statement.setString(3, Rank.EXECUTIVE.name().toLowerCase());
ResultSet set = statement.executeQuery();
while (set.next())
{
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();
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 plexPlayer = new PlexPlayer(UUID.fromString(uuid));
plexPlayer.setName(name);
plexPlayer.setLoginMessage(loginMSG);
plexPlayer.setPrefix(prefix);
plexPlayer.setRank(rankName);
plexPlayer.setIps(ips);
plexPlayer.setCoins(coins);
plexPlayer.setVanished(vanished);
plexPlayer.setCommandSpy(commandspy);
plexPlayers.add(plexPlayer);
}
}
catch (SQLException throwables)
{
throwables.printStackTrace();
}
}
return plexPlayers;
}
}

View File

@ -3,6 +3,7 @@ package dev.plex.cache;
import dev.plex.Plex; import dev.plex.Plex;
import dev.plex.player.PlexPlayer; import dev.plex.player.PlexPlayer;
import dev.plex.storage.StorageType; import dev.plex.storage.StorageType;
import java.util.Optional; import java.util.Optional;
import java.util.UUID; import java.util.UUID;
@ -18,28 +19,14 @@ public class DataUtils
* @return true if the player is registered in the database * @return true if the player is registered in the database
*/ */
public static boolean hasPlayedBefore(UUID uuid) public static boolean hasPlayedBefore(UUID uuid)
{
if (Plex.get().getStorageType() == StorageType.MONGODB)
{
return Plex.get().getMongoPlayerData().exists(uuid);
}
else
{ {
return Plex.get().getSqlPlayerData().exists(uuid); return Plex.get().getSqlPlayerData().exists(uuid);
} }
}
public static boolean hasPlayedBefore(String username) 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); return Plex.get().getSqlPlayerData().exists(username);
} }
}
/** /**
* Gets a player from cache or from the database * Gets a player from cache or from the database
@ -60,15 +47,8 @@ public class DataUtils
return Plex.get().getPlayerCache().getPlexPlayerMap().get(uuid); return Plex.get().getPlayerCache().getPlexPlayerMap().get(uuid);
} }
if (Plex.get().getStorageType() == StorageType.MONGODB)
{
return Plex.get().getMongoPlayerData().getByUUID(uuid);
}
else
{
return Plex.get().getSqlPlayerData().getByUUID(uuid, loadExtraData); return Plex.get().getSqlPlayerData().getByUUID(uuid, loadExtraData);
} }
}
public static PlexPlayer getPlayer(String username) public static PlexPlayer getPlayer(String username)
{ {
@ -83,15 +63,8 @@ public class DataUtils
return plexPlayer.get(); return plexPlayer.get();
} }
if (Plex.get().getStorageType() == StorageType.MONGODB)
{
return Plex.get().getMongoPlayerData().getByName(username);
}
else
{
return Plex.get().getSqlPlayerData().getByName(username, loadExtraData); return Plex.get().getSqlPlayerData().getByName(username, loadExtraData);
} }
}
/** /**
* Gets a player from cache or from the database * Gets a player from cache or from the database
@ -108,15 +81,8 @@ public class DataUtils
return player; return player;
} }
if (Plex.get().getStorageType() == StorageType.MONGODB)
{
return Plex.get().getMongoPlayerData().getByIP(ip);
}
else
{
return Plex.get().getSqlPlayerData().getByIP(ip); return Plex.get().getSqlPlayerData().getByIP(ip);
} }
}
/** /**
* Updates a player's information in the database * Updates a player's information in the database
@ -125,16 +91,9 @@ public class DataUtils
* @see PlexPlayer * @see PlexPlayer
*/ */
public static void update(PlexPlayer plexPlayer) public static void update(PlexPlayer plexPlayer)
{
if (Plex.get().getStorageType() == StorageType.MONGODB)
{
Plex.get().getMongoPlayerData().update(plexPlayer);
}
else
{ {
Plex.get().getSqlPlayerData().update(plexPlayer); Plex.get().getSqlPlayerData().update(plexPlayer);
} }
}
/** /**
* Inserts a player's information in the database * Inserts a player's information in the database
@ -143,17 +102,8 @@ public class DataUtils
* @see PlexPlayer * @see PlexPlayer
*/ */
public static void insert(PlexPlayer plexPlayer) public static void insert(PlexPlayer plexPlayer)
{
if (Plex.get().getStorageType() == StorageType.MONGODB)
{
Plex.get().getMongoPlayerData().save(plexPlayer);
}
else
{ {
Plex.get().getSqlPlayerData().insert(plexPlayer); Plex.get().getSqlPlayerData().insert(plexPlayer);
} }
}
/* REDIS METHODS AT ONE POINT FOR BANS, AND JSON METHODS FOR PUNISHMENTS */
} }

View File

@ -2,6 +2,7 @@ package dev.plex.cache;
import com.google.common.collect.Maps; import com.google.common.collect.Maps;
import dev.plex.player.PlexPlayer; import dev.plex.player.PlexPlayer;
import java.util.Map; import java.util.Map;
import java.util.UUID; import java.util.UUID;

View File

@ -1,37 +1,31 @@
package dev.plex.command; package dev.plex.command;
import com.google.common.collect.Lists;
import dev.plex.Plex; import dev.plex.Plex;
import dev.plex.cache.DataUtils; import dev.plex.cache.DataUtils;
import dev.plex.command.annotation.CommandParameters; import dev.plex.command.annotation.CommandParameters;
import dev.plex.command.annotation.CommandPermissions; import dev.plex.command.annotation.CommandPermissions;
import dev.plex.command.exception.CommandFailException; import dev.plex.command.exception.*;
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.command.source.RequiredCommandSource;
import dev.plex.player.PlexPlayer; import dev.plex.player.PlexPlayer;
import dev.plex.rank.enums.Rank;
import dev.plex.util.PlexLog; import dev.plex.util.PlexLog;
import dev.plex.util.PlexUtils; import dev.plex.util.PlexUtils;
import java.util.Arrays;
import java.util.UUID;
import net.kyori.adventure.audience.Audience; import net.kyori.adventure.audience.Audience;
import net.kyori.adventure.text.Component; import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.NamedTextColor; import net.kyori.adventure.text.format.NamedTextColor;
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer; import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.World; import org.bukkit.World;
import org.bukkit.command.Command; import org.bukkit.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.bukkit.entity.Player;
import org.bukkit.util.StringUtil;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
import java.util.Arrays;
import java.util.List;
import java.util.UUID;
/** /**
* Superclass for all commands * Superclass for all commands
*/ */
@ -52,11 +46,6 @@ public abstract class PlexCommand extends Command implements PluginIdentifiableC
*/ */
private final CommandPermissions perms; private final CommandPermissions perms;
/**
* Minimum required rank fetched from the permissions
*/
private final Rank level;
/** /**
* Required command source fetched from the permissions * Required command source fetched from the permissions
*/ */
@ -74,16 +63,27 @@ public abstract class PlexCommand extends Command implements PluginIdentifiableC
setName(this.params.name()); setName(this.params.name());
setLabel(this.params.name()); setLabel(this.params.name());
setDescription(params.description()); setDescription(params.description());
setPermission(this.perms.permission());
setUsage(params.usage().replace("<command>", this.params.name())); setUsage(params.usage().replace("<command>", this.params.name()));
if (params.aliases().split(",").length > 0) if (params.aliases().split(",").length > 0)
{ {
setAliases(Arrays.asList(params.aliases().split(","))); setAliases(Arrays.asList(params.aliases().split(",")));
} }
this.level = perms.level();
this.commandSource = perms.source(); this.commandSource = perms.source();
if (register) if (register)
{ {
if (getMap().getKnownCommands().containsKey(this.getName().toLowerCase()))
{
getMap().getKnownCommands().remove(this.getName().toLowerCase());
}
this.getAliases().forEach(s ->
{
if (getMap().getKnownCommands().containsKey(s.toLowerCase()))
{
getMap().getKnownCommands().remove(s.toLowerCase());
}
});
getMap().register("plex", this); getMap().register("plex", this);
} }
} }
@ -137,73 +137,23 @@ public abstract class PlexCommand extends Command implements PluginIdentifiableC
return false; return false;
} }
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 (!perms.permission().isEmpty() && !player.hasPermission(perms.permission())) if (!perms.permission().isEmpty() && !player.hasPermission(perms.permission()))
{ {
send(sender, messageComponent("noPermissionNode", perms.permission())); send(sender, messageComponent("noPermissionNode", perms.permission()));
return true; 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");
return true;
}
}
if (sender instanceof ConsoleCommandSender && !sender.getName().equalsIgnoreCase("console")) //telnet if (sender instanceof ConsoleCommandSender && !sender.getName().equalsIgnoreCase("console")) //telnet
{ {
PlexPlayer plexPlayer = DataUtils.getPlayer(sender.getName()); 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 (!perms.permission().isEmpty() && !plugin.getPermissions().playerHas(null, Bukkit.getPlayer(plexPlayer.getName()), perms.permission())) if (!perms.permission().isEmpty() && !plugin.getPermissions().playerHas(null, Bukkit.getPlayer(plexPlayer.getName()), perms.permission()))
{ {
send(sender, messageComponent("noPermissionNode", perms.permission())); send(sender, messageComponent("noPermissionNode", perms.permission()));
return true; 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");
return true;
}
}
try try
{ {
Component component = this.execute(sender, isConsole(sender) ? null : (Player) sender, args); Component component = this.execute(sender, isConsole(sender) ? null : (Player) sender, args);
@ -220,6 +170,17 @@ public abstract class PlexCommand extends Command implements PluginIdentifiableC
return true; return true;
} }
@NotNull
public abstract List<String> smartTabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) throws IllegalArgumentException;
@NotNull
@Override
public List<String> tabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) throws IllegalArgumentException
{
List<String> list = smartTabComplete(sender, alias, args);
return StringUtil.copyPartialMatches(args[args.length - 1], list, Lists.newArrayList());
}
/** /**
* Checks if the String given is a matching command * Checks if the String given is a matching command
* *
@ -283,111 +244,31 @@ public abstract class PlexCommand extends Command implements PluginIdentifiableC
* Checks whether a sender has enough permissions or is high enough a rank * Checks whether a sender has enough permissions or is high enough a rank
* *
* @param sender A CommandSender * @param sender A CommandSender
* @param rank The rank to check (if the server is using ranks) * @param permission The permission to check
* @param permission The permission to check (if the server is using permissions)
* @return true if the sender has enough permissions * @return true if the sender has enough permissions
* @see Rank
*/ */
protected boolean checkRank(CommandSender sender, Rank rank, String permission) protected boolean checkPermission(CommandSender sender, String permission)
{ {
if (!isConsole(sender)) if (!isConsole(sender))
{ {
return checkRank((Player)sender, rank, permission); return checkPermission((Player) sender, 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 (!perms.permission().isEmpty() && !plugin.getPermissions().playerHas(null, Bukkit.getOfflinePlayer(plexPlayer.getName()), perms.permission()))
{
throw new CommandFailException(PlexUtils.messageString("noPermissionNode", permission));
}
}
} }
return true; return true;
} }
/**
* Checks whether a player has enough permissions or is high enough a rank
*
* @param player The player object
* @param rank The rank to check (if the server is using ranks)
* @param permission The permission to check (if the server is using permissions)
* @return true if the sender has enough permissions
* @see Rank
*/
protected boolean checkRank(Player player, Rank rank, String permission)
{
if (player instanceof ConsoleCommandSender)
{
return true;
}
PlexPlayer plexPlayer = getPlexPlayer(player);
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 (!perms.permission().isEmpty() && !player.hasPermission(perms.permission()))
{
throw new CommandFailException(PlexUtils.messageString("noPermissionNode", permission));
}
}
return true;
}
protected boolean silentCheckRank(Player player, Rank rank, String permission)
{
if (player instanceof ConsoleCommandSender)
{
return true;
}
PlexPlayer plexPlayer = getPlexPlayer(player);
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"))
{
return !perms.permission().isEmpty() && player.hasPermission(permission);
}
return false;
}
/** /**
* Checks whether a sender has enough permissions or is high enough a rank * Checks whether a sender has enough permissions or is high enough a rank
* *
* @param sender The player object * @param sender A CommandSender
* @param rank The rank to check (if the server is using ranks) * @param permission The permission to check
* @param permission The permission to check (if the server is using permissions)
* @return true if the sender has enough permissions * @return true if the sender has enough permissions
* @see Rank
*/ */
protected boolean checkTab(CommandSender sender, Rank rank, String permission) protected boolean silentCheckPermission(CommandSender sender, String permission)
{ {
PlexLog.debug("Checking {0} with {1}", sender.getName(), permission);
if (!isConsole(sender)) if (!isConsole(sender))
{ {
return checkTab((Player)sender, rank, permission); return silentCheckPermission((Player) sender, permission);
} }
return true; return true;
} }
@ -396,79 +277,25 @@ public abstract class PlexCommand extends Command implements PluginIdentifiableC
* Checks whether a player has enough permissions or is high enough a rank * Checks whether a player has enough permissions or is high enough a rank
* *
* @param player The player object * @param player The player object
* @param rank The rank to check (if the server is using ranks) * @param permission The permission to check
* @param permission The permission to check (if the server is using permissions)
* @return true if the sender has enough permissions * @return true if the sender has enough permissions
* @see Rank
*/ */
protected boolean checkTab(Player player, Rank rank, String permission) protected boolean checkPermission(Player player, String permission)
{ {
PlexPlayer plexPlayer = getPlexPlayer(player); if (player instanceof ConsoleCommandSender)
if (plugin.getSystem().equalsIgnoreCase("ranks"))
{ {
return rank.isAtLeast(Rank.ADMIN) ? plexPlayer.isAdminActive() && plexPlayer.getRankFromString().isAtLeast(rank) : plexPlayer.getRankFromString().isAtLeast(rank); return true;
} }
else if (plugin.getSystem().equalsIgnoreCase("permissions")) if (!permission.isEmpty() && !player.hasPermission(permission))
{ {
return !perms.permission().isEmpty() && player.hasPermission(permission); throw new CommandFailException(PlexUtils.messageString("noPermissionNode", permission));
} }
return true; return true;
} }
/** protected boolean silentCheckPermission(Player player, String permission)
* Checks if a player is an admin
*
* @param plexPlayer The PlexPlayer object
* @return true if the player is an admin
* @see PlexPlayer
*/
protected boolean isAdmin(PlexPlayer plexPlayer)
{ {
return Plex.get().getRankManager().isAdmin(plexPlayer); return !permission.isEmpty() && player.hasPermission(permission);
}
/**
* Checks if a sender is an admin
*
* @param sender A command sender
* @return true if the sender is an admin or if console
*/
protected boolean isAdmin(CommandSender sender)
{
if (!(sender instanceof Player player))
{
return true;
}
PlexPlayer plexPlayer = getPlexPlayer(player);
return plugin.getRankManager().isAdmin(plexPlayer);
}
/**
* Checks if a username is an admin
*
* @param name The username
* @return true if the username is an admin
*/
protected boolean isAdmin(String name)
{
PlexPlayer plexPlayer = DataUtils.getPlayer(name);
return plugin.getRankManager().isAdmin(plexPlayer);
}
/**
* Checks if a sender is a senior admin
*
* @param sender A command sender
* @return true if the sender is a senior admin or if console
*/
protected boolean isSeniorAdmin(CommandSender sender)
{
if (!(sender instanceof Player player))
{
return true;
}
PlexPlayer plexPlayer = getPlexPlayer(player);
return plugin.getRankManager().isSeniorAdmin(plexPlayer);
} }
/** /**
@ -646,11 +473,6 @@ public abstract class PlexCommand extends Command implements PluginIdentifiableC
return PlexUtils.mmDeserialize(s); return PlexUtils.mmDeserialize(s);
} }
public Rank getLevel()
{
return level;
}
public CommandMap getMap() public CommandMap getMap()
{ {
return Plex.get().getServer().getCommandMap(); return Plex.get().getServer().getCommandMap();

View File

@ -1,7 +1,7 @@
package dev.plex.command.annotation; package dev.plex.command.annotation;
import dev.plex.command.source.RequiredCommandSource; import dev.plex.command.source.RequiredCommandSource;
import dev.plex.rank.enums.Rank;
import java.lang.annotation.Retention; import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy; import java.lang.annotation.RetentionPolicy;
@ -11,14 +11,6 @@ import java.lang.annotation.RetentionPolicy;
@Retention(RetentionPolicy.RUNTIME) @Retention(RetentionPolicy.RUNTIME)
public @interface CommandPermissions public @interface CommandPermissions
{ {
/**
* Minimum rank required
*
* @return Minimum rank required for the command
* @see Rank
*/
Rank level() default Rank.IMPOSTOR;
/** /**
* Required command source * Required command source
* *

View File

@ -1,12 +0,0 @@
package dev.plex.command.annotation;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
@Retention(RetentionPolicy.RUNTIME)
public @interface System
{
String value() default "";
boolean debug() default false;
}

View File

@ -1,10 +1,11 @@
package dev.plex.command.blocking; package dev.plex.command.blocking;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
import java.util.List;
import lombok.Data; import lombok.Data;
import net.kyori.adventure.text.Component; import net.kyori.adventure.text.Component;
import java.util.List;
@Data @Data
public class BlockedCommand public class BlockedCommand
{ {

View File

@ -1,186 +0,0 @@
package dev.plex.command.impl;
import com.google.common.collect.ImmutableList;
import dev.plex.cache.DataUtils;
import dev.plex.command.PlexCommand;
import dev.plex.command.annotation.CommandParameters;
import dev.plex.command.annotation.CommandPermissions;
import dev.plex.command.annotation.System;
import dev.plex.command.exception.ConsoleOnlyException;
import dev.plex.command.exception.PlayerNotFoundException;
import dev.plex.command.source.RequiredCommandSource;
import dev.plex.event.AdminAddEvent;
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.PlexUtils;
import java.util.Arrays;
import java.util.List;
import net.kyori.adventure.text.Component;
import org.apache.commons.lang3.StringUtils;
import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@CommandPermissions(level = Rank.OP, source = RequiredCommandSource.ANY)
@CommandParameters(name = "admin", usage = "/<command> <add <player> | remove <player> | setrank <player> <rank> | list>", aliases = "saconfig,slconfig,adminconfig,adminmanage", description = "Manage all admins")
@System(value = "ranks")
public class AdminCMD extends PlexCommand
{
//TODO: Better return messages
@Override
protected Component execute(@NotNull CommandSender sender, @Nullable Player playerSender, String[] args)
{
if (args.length == 0)
{
return usage();
}
if (args[0].equalsIgnoreCase("add"))
{
if (args.length != 2)
{
return usage("/admin add <player>");
}
if (!isConsole(sender))
{
throw new ConsoleOnlyException();
}
/*UUID targetUUID = PlexUtils.getFromName(args[1]);
if (targetUUID != null)
{
PlexLog.debug("Admin Adding UUID: " + targetUUID);
}*/
if (!DataUtils.hasPlayedBefore(args[1]))
{
throw new PlayerNotFoundException();
}
PlexPlayer plexPlayer = DataUtils.getPlayer(args[1]);
if (isAdmin(plexPlayer))
{
return messageComponent("playerIsAdmin");
}
Bukkit.getServer().getPluginManager().callEvent(new AdminAddEvent(sender, plexPlayer));
return null;
}
if (args[0].equalsIgnoreCase("remove"))
{
if (args.length != 2)
{
return usage("/admin remove <player>");
}
if (!isConsole(sender))
{
throw new ConsoleOnlyException();
}
// UUID targetUUID = PlexUtils.getFromName(args[1]);
if (!DataUtils.hasPlayedBefore(args[1]))
{
throw new PlayerNotFoundException();
}
PlexPlayer plexPlayer = DataUtils.getPlayer(args[1]);
if (!isAdmin(plexPlayer))
{
return messageComponent("playerNotAdmin");
}
Bukkit.getServer().getPluginManager().callEvent(new AdminRemoveEvent(sender, plexPlayer));
return null;
}
if (args[0].equalsIgnoreCase("setrank"))
{
if (args.length != 3)
{
return usage("/admin setrank <player> <rank>");
}
if (!isConsole(sender))
{
throw new ConsoleOnlyException();
}
// UUID targetUUID = PlexUtils.getFromName(args[1]);
if (!DataUtils.hasPlayedBefore(args[1]))
{
throw new PlayerNotFoundException();
}
if (!rankExists(args[2]))
{
return messageComponent("rankNotFound");
}
Rank rank = Rank.valueOf(args[2].toUpperCase());
if (!rank.isAtLeast(Rank.ADMIN))
{
return messageComponent("rankMustBeHigherThanAdmin");
}
PlexPlayer plexPlayer = DataUtils.getPlayer(args[1]);
if (!isAdmin(plexPlayer))
{
return messageComponent("playerNotAdmin");
}
Bukkit.getServer().getPluginManager().callEvent(new AdminSetRankEvent(sender, plexPlayer, rank));
return null;
}
if (args[0].equalsIgnoreCase("list"))
{
if (args.length != 1)
{
return usage("/admin list");
}
return componentFromString("Admins: " + StringUtils.join(plugin.getAdminList().getAllAdmins(), ", "));
}
return null;
}
@Override
public @NotNull List<String> tabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) throws IllegalArgumentException
{
if (args.length == 1)
{
return Arrays.asList("add", "remove", "setrank", "list");
}
else if (args.length == 2 && !args[0].equalsIgnoreCase("list"))
{
return PlexUtils.getPlayerNameList();
}
return ImmutableList.of();
}
private boolean rankExists(String rank)
{
for (Rank ranks : Rank.values())
{
if (ranks.name().equalsIgnoreCase(rank))
{
return true;
}
}
return false;
}
}

View File

@ -1,16 +1,15 @@
package dev.plex.command.impl; package dev.plex.command.impl;
import dev.plex.cache.DataUtils;
import dev.plex.command.PlexCommand; import dev.plex.command.PlexCommand;
import dev.plex.command.annotation.CommandParameters; import dev.plex.command.annotation.CommandParameters;
import dev.plex.command.annotation.CommandPermissions; import dev.plex.command.annotation.CommandPermissions;
import dev.plex.command.source.RequiredCommandSource; import dev.plex.command.source.RequiredCommandSource;
import dev.plex.hook.VaultHook;
import dev.plex.player.PlexPlayer; import dev.plex.player.PlexPlayer;
import dev.plex.rank.enums.Rank; import dev.plex.util.PlexLog;
import dev.plex.util.PlexUtils; import dev.plex.util.PlexUtils;
import dev.plex.util.minimessage.SafeMiniMessage; import dev.plex.util.minimessage.SafeMiniMessage;
import dev.plex.util.redis.MessageUtil; import dev.plex.util.redis.MessageUtil;
import java.util.UUID;
import net.kyori.adventure.text.Component; import net.kyori.adventure.text.Component;
import org.apache.commons.lang3.BooleanUtils; import org.apache.commons.lang3.BooleanUtils;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
@ -19,26 +18,49 @@ import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
@CommandPermissions(level = Rank.ADMIN, permission = "plex.adminchat", source = RequiredCommandSource.ANY) import java.util.Collections;
import java.util.List;
import java.util.UUID;
@CommandPermissions(permission = "plex.adminchat", source = RequiredCommandSource.ANY)
@CommandParameters(name = "adminchat", description = "Talk privately with other admins", usage = "/<command> <message>", aliases = "o,ac,sc,staffchat") @CommandParameters(name = "adminchat", description = "Talk privately with other admins", usage = "/<command> <message>", aliases = "o,ac,sc,staffchat")
public class AdminChatCMD extends PlexCommand public class AdminChatCMD extends PlexCommand
{ {
@Override @Override
protected Component execute(@NotNull CommandSender sender, @Nullable Player playerSender, String[] args) protected Component execute(@NotNull CommandSender sender, @Nullable Player playerSender, String[] args)
{ {
PlexPlayer player;
if (args.length == 0) if (args.length == 0)
{ {
if (playerSender != null) { if (playerSender != null)
PlexPlayer player = DataUtils.getPlayer(playerSender.getUniqueId()); {
player = plugin.getPlayerCache().getPlexPlayer(playerSender.getUniqueId());
player.setStaffChat(!player.isStaffChat()); player.setStaffChat(!player.isStaffChat());
return messageComponent("adminChatToggled", BooleanUtils.toStringOnOff(player.isStaffChat())); return messageComponent("adminChatToggled", BooleanUtils.toStringOnOff(player.isStaffChat()));
} }
return usage(); return usage();
} }
String prefix;
if (playerSender != null)
{
player = plugin.getPlayerCache().getPlexPlayer(playerSender.getUniqueId());
prefix = PlexUtils.mmSerialize(VaultHook.getPrefix(player));
}
else
{
prefix = "<dark_gray>[<dark_purple>Console<dark_gray>]";
}
PlexLog.debug("admin chat prefix: {0}", prefix);
String message = StringUtils.join(args, " "); String message = StringUtils.join(args, " ");
plugin.getServer().getConsoleSender().sendMessage(messageComponent("adminChatFormat", sender.getName(), message)); plugin.getServer().getConsoleSender().sendMessage(messageComponent("adminChatFormat", sender.getName(), prefix, message));
MessageUtil.sendStaffChat(sender, SafeMiniMessage.mmDeserialize(message), PlexUtils.adminChat(sender.getName(), message).toArray(UUID[]::new)); MessageUtil.sendStaffChat(sender, SafeMiniMessage.mmDeserialize(message), PlexUtils.adminChat(sender.getName(), prefix, message).toArray(UUID[]::new));
return null; return null;
} }
@Override
public @NotNull List<String> smartTabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) throws IllegalArgumentException
{
return Collections.emptyList();
}
} }

View File

@ -4,7 +4,6 @@ import dev.plex.command.PlexCommand;
import dev.plex.command.annotation.CommandParameters; import dev.plex.command.annotation.CommandParameters;
import dev.plex.command.annotation.CommandPermissions; import dev.plex.command.annotation.CommandPermissions;
import dev.plex.command.source.RequiredCommandSource; import dev.plex.command.source.RequiredCommandSource;
import dev.plex.rank.enums.Rank;
import net.kyori.adventure.text.Component; import net.kyori.adventure.text.Component;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.Location; import org.bukkit.Location;
@ -13,7 +12,10 @@ import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
@CommandPermissions(level = Rank.ADMIN, permission = "plex.adminworld", source = RequiredCommandSource.IN_GAME) import java.util.Collections;
import java.util.List;
@CommandPermissions(permission = "plex.adminworld", source = RequiredCommandSource.IN_GAME)
@CommandParameters(name = "adminworld", aliases = "aw", description = "Teleport to the adminworld") @CommandParameters(name = "adminworld", aliases = "aw", description = "Teleport to the adminworld")
public class AdminworldCMD extends PlexCommand public class AdminworldCMD extends PlexCommand
{ {
@ -30,4 +32,10 @@ public class AdminworldCMD extends PlexCommand
} }
return null; return null;
} }
@Override
public @NotNull List<String> smartTabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) throws IllegalArgumentException
{
return Collections.emptyList();
}
} }

View File

@ -7,9 +7,7 @@ import dev.plex.command.annotation.CommandPermissions;
import dev.plex.command.exception.CommandFailException; import dev.plex.command.exception.CommandFailException;
import dev.plex.command.source.RequiredCommandSource; import dev.plex.command.source.RequiredCommandSource;
import dev.plex.event.GameModeUpdateEvent; import dev.plex.event.GameModeUpdateEvent;
import dev.plex.rank.enums.Rank;
import dev.plex.util.PlexUtils; import dev.plex.util.PlexUtils;
import java.util.List;
import net.kyori.adventure.text.Component; import net.kyori.adventure.text.Component;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.GameMode; import org.bukkit.GameMode;
@ -18,7 +16,9 @@ import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
@CommandPermissions(level = Rank.OP, permission = "plex.gamemode.adventure", source = RequiredCommandSource.ANY) import java.util.List;
@CommandPermissions(permission = "plex.gamemode.adventure", source = RequiredCommandSource.ANY)
@CommandParameters(name = "adventure", aliases = "gma,egma,eadventure,adventuremode,eadventuremode", description = "Set your own or another player's gamemode to adventure mode") @CommandParameters(name = "adventure", aliases = "gma,egma,eadventure,adventuremode,eadventuremode", description = "Set your own or another player's gamemode to adventure mode")
public class AdventureCMD extends PlexCommand public class AdventureCMD extends PlexCommand
{ {
@ -29,14 +29,13 @@ public class AdventureCMD extends PlexCommand
{ {
if (isConsole(sender)) if (isConsole(sender))
{ {
throw new CommandFailException(PlexUtils.messageString("consoleMustDefinePlayer")); throw new CommandFailException(messageString("consoleMustDefinePlayer"));
} }
Bukkit.getServer().getPluginManager().callEvent(new GameModeUpdateEvent(sender, playerSender, GameMode.ADVENTURE)); Bukkit.getServer().getPluginManager().callEvent(new GameModeUpdateEvent(sender, playerSender, GameMode.ADVENTURE));
return null; return null;
} }
if (checkRank(sender, Rank.ADMIN, "plex.gamemode.adventure.others")) checkPermission(sender, "plex.gamemode.adventure.others");
{
if (args[0].equals("-a")) if (args[0].equals("-a"))
{ {
for (Player targetPlayer : Bukkit.getServer().getOnlinePlayers()) for (Player targetPlayer : Bukkit.getServer().getOnlinePlayers())
@ -50,14 +49,13 @@ public class AdventureCMD extends PlexCommand
Player nPlayer = getNonNullPlayer(args[0]); Player nPlayer = getNonNullPlayer(args[0]);
Bukkit.getServer().getPluginManager().callEvent(new GameModeUpdateEvent(sender, nPlayer, GameMode.ADVENTURE)); Bukkit.getServer().getPluginManager().callEvent(new GameModeUpdateEvent(sender, nPlayer, GameMode.ADVENTURE));
}
return null; return null;
} }
@Override @Override
public @NotNull List<String> tabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) throws IllegalArgumentException public @NotNull List<String> smartTabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) throws IllegalArgumentException
{ {
if (checkTab(sender, Rank.ADMIN, "plex.gamemode.adventure.others")) if (silentCheckPermission(sender, "plex.gamemode.adventure.others"))
{ {
return PlexUtils.getPlayerNameList(); return PlexUtils.getPlayerNameList();
} }

View File

@ -1,7 +1,5 @@
package dev.plex.command.impl; package dev.plex.command.impl;
import com.google.common.collect.ImmutableList;
import dev.plex.Plex;
import dev.plex.cache.DataUtils; import dev.plex.cache.DataUtils;
import dev.plex.command.PlexCommand; import dev.plex.command.PlexCommand;
import dev.plex.command.annotation.CommandParameters; import dev.plex.command.annotation.CommandParameters;
@ -11,16 +9,10 @@ import dev.plex.command.source.RequiredCommandSource;
import dev.plex.player.PlexPlayer; import dev.plex.player.PlexPlayer;
import dev.plex.punishment.Punishment; import dev.plex.punishment.Punishment;
import dev.plex.punishment.PunishmentType; import dev.plex.punishment.PunishmentType;
import dev.plex.rank.enums.Rank;
import dev.plex.util.BungeeUtil; import dev.plex.util.BungeeUtil;
import dev.plex.util.PlexLog; import dev.plex.util.PlexLog;
import dev.plex.util.PlexUtils; import dev.plex.util.PlexUtils;
import dev.plex.util.TimeUtils; import dev.plex.util.TimeUtils;
import dev.plex.util.WebUtils;
import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.util.List;
import java.util.UUID;
import net.kyori.adventure.text.Component; import net.kyori.adventure.text.Component;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
@ -29,8 +21,13 @@ import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
@CommandParameters(name = "ban", usage = "/<command> <player> [reason]", aliases = "offlineban,gtfo", description = "Bans a player, offline or online") import java.time.ZoneId;
@CommandPermissions(level = Rank.ADMIN, permission = "plex.ban", source = RequiredCommandSource.ANY) import java.time.ZonedDateTime;
import java.util.Collections;
import java.util.List;
@CommandParameters(name = "ban", usage = "/<command> <player> [reason] [-rb]", aliases = "offlineban,gtfo", description = "Bans a player, offline or online")
@CommandPermissions(permission = "plex.ban", source = RequiredCommandSource.ANY)
public class BanCMD extends PlexCommand public class BanCMD extends PlexCommand
{ {
@ -42,32 +39,16 @@ public class BanCMD extends PlexCommand
return usage(); return usage();
} }
UUID targetUUID = WebUtils.getFromName(args[0]); final PlexPlayer plexPlayer = DataUtils.getPlayer(args[0]);
if (targetUUID == null || !DataUtils.hasPlayedBefore(targetUUID)) if (plexPlayer == null)
{ {
throw new PlayerNotFoundException(); throw new PlayerNotFoundException();
} }
PlexPlayer plexPlayer = DataUtils.getPlayer(targetUUID);
Player player = Bukkit.getPlayer(targetUUID);
if (plugin.getSystem().equalsIgnoreCase("ranks")) Player player = Bukkit.getPlayer(plexPlayer.getUuid());
{
if (isAdmin(plexPlayer))
{
if (!isConsole(sender))
{
assert playerSender != null;
PlexPlayer plexPlayer1 = getPlexPlayer(playerSender);
if (!plexPlayer1.getRankFromString().isAtLeast(plexPlayer.getRankFromString()))
{
return messageComponent("higherRankThanYou");
}
}
}
}
plugin.getPunishmentManager().isAsyncBanned(targetUUID).whenComplete((aBoolean, throwable) -> plugin.getPunishmentManager().isAsyncBanned(plexPlayer.getUuid()).whenComplete((aBoolean, throwable) ->
{ {
if (aBoolean) if (aBoolean)
{ {
@ -75,29 +56,29 @@ public class BanCMD extends PlexCommand
return; return;
} }
String reason; String reason;
Punishment punishment = new Punishment(targetUUID, getUUID(sender)); Punishment punishment = new Punishment(plexPlayer.getUuid(), getUUID(sender));
punishment.setType(PunishmentType.BAN); punishment.setType(PunishmentType.BAN);
boolean rollBack = false;
if (args.length > 1) if (args.length > 1)
{ {
reason = StringUtils.join(args, " ", 1, args.length); reason = StringUtils.join(args, " ", 1, args.length);
punishment.setReason(reason); String newReason = StringUtils.normalizeSpace(reason.replace("-rb", ""));
punishment.setReason(newReason.trim().isEmpty() ? messageString("noReasonProvided") : newReason);
rollBack = reason.startsWith("-rb") || reason.endsWith("-rb");
} }
else else
{ {
punishment.setReason("No reason provided."); punishment.setReason(messageString("noReasonProvided"));
} }
punishment.setPunishedUsername(plexPlayer.getName()); punishment.setPunishedUsername(plexPlayer.getName());
ZonedDateTime date = ZonedDateTime.now(ZoneId.of(TimeUtils.TIMEZONE)); ZonedDateTime date = ZonedDateTime.now(ZoneId.of(TimeUtils.TIMEZONE));
punishment.setEndDate(date.plusDays(1)); punishment.setEndDate(date.plusDays(1));
punishment.setCustomTime(false); punishment.setCustomTime(false);
punishment.setActive(!isAdmin(plexPlayer)); punishment.setActive(true);
if (player != null) punishment.setIp(player != null ? player.getAddress().getAddress().getHostAddress().trim() : plexPlayer.getIps().get(plexPlayer.getIps().size() - 1));
{
punishment.setIp(player.getAddress().getAddress().getHostAddress().trim());
}
plugin.getPunishmentManager().punish(plexPlayer, punishment); plugin.getPunishmentManager().punish(plexPlayer, punishment);
PlexUtils.broadcast(messageComponent("banningPlayer", sender.getName(), plexPlayer.getName())); PlexUtils.broadcast(messageComponent("banningPlayer", sender.getName(), plexPlayer.getName()));
Bukkit.getScheduler().runTask(Plex.get(), () -> Bukkit.getGlobalRegionScheduler().execute(plugin, () ->
{ {
if (player != null) if (player != null)
{ {
@ -105,14 +86,59 @@ public class BanCMD extends PlexCommand
} }
}); });
PlexLog.debug("(From /ban command) PunishedPlayer UUID: " + plexPlayer.getUuid()); PlexLog.debug("(From /ban command) PunishedPlayer UUID: " + plexPlayer.getUuid());
if (rollBack)
{
/*if (plugin.getPrismHook() != null && plugin.getPrismHook().hasPrism())
{
PrismParameters parameters = plugin.getPrismHook().prismApi().createParameters();
parameters.addActionType("block-place");
parameters.addActionType("block-break");
parameters.addActionType("block-burn");
parameters.addActionType("entity-spawn");
parameters.addActionType("entity-kill");
parameters.addActionType("entity-explode");
parameters.addPlayerName(plexPlayer.getName());
parameters.setBeforeTime(Instant.now().toEpochMilli());
parameters.setProcessType(PrismProcessType.ROLLBACK);
final Future<Result> result = plugin.getPrismHook().prismApi().performLookup(parameters, sender);
Bukkit.getAsyncScheduler().runNow(plugin, scheduledTask ->
{
try
{
final Result done = result.get();
}
catch (InterruptedException | ExecutionException e)
{
throw new RuntimeException(e);
}
});
}
else */
if (plugin.getCoreProtectHook() != null && plugin.getCoreProtectHook().hasCoreProtect())
{
Bukkit.getAsyncScheduler().runNow(plugin, scheduledTask ->
{
plugin.getCoreProtectHook().coreProtectAPI().performRollback(86400, Collections.singletonList(plexPlayer.getName()), null, null, null, null, 0, null);
});
}
}
}); });
return null; return null;
} }
@Override @Override
public @NotNull List<String> tabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) throws IllegalArgumentException public @NotNull List<String> smartTabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) throws IllegalArgumentException
{ {
return args.length == 1 && checkTab(sender, Rank.ADMIN, "plex.ban") ? PlexUtils.getPlayerNameList() : ImmutableList.of(); if (args.length == 1 && silentCheckPermission(sender, this.getPermission()))
{
return PlexUtils.getPlayerNameList();
}
if (args.length > 1 && silentCheckPermission(sender, this.getPermission()))
{
return Collections.singletonList("-rb");
}
return Collections.emptyList();
} }
} }

View File

@ -0,0 +1,61 @@
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;
import dev.plex.punishment.Punishment;
import net.kyori.adventure.text.Component;
import org.apache.commons.lang3.StringUtils;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;
@CommandParameters(name = "banlist", description = "Manages the banlist", usage = "/<command> [purge]")
@CommandPermissions(permission = "plex.banlist")
public class BanListCommand extends PlexCommand
{
@Override
protected Component execute(@NotNull CommandSender sender, @Nullable Player player, @NotNull String[] args)
{
if (args.length == 0)
{
plugin.getPunishmentManager().getActiveBans().whenComplete((punishments, throwable) ->
{
send(sender, mmString("<gold>Active Bans (" + punishments.size() + "): <yellow>" + StringUtils.join(punishments.stream().map(Punishment::getPunishedUsername).collect(Collectors.toList()), ", ")));
});
return null;
}
if (args[0].equalsIgnoreCase("purge") || args[0].equalsIgnoreCase("clear"))
{
if (sender instanceof Player)
{
return messageComponent("noPermissionInGame");
}
if (!sender.getName().equalsIgnoreCase("console"))
{
if (!checkPermission(sender, "plex.banlist.clear"))
{
return null;
}
}
plugin.getPunishmentManager().getActiveBans().whenComplete((punishments, throwable) ->
{
punishments.forEach(plugin.getPunishmentManager()::unban);
send(sender, mmString("<gold>Unbanned " + punishments.size() + " players."));
});
}
return null;
}
@Override
public @NotNull List<String> smartTabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) throws IllegalArgumentException
{
return args.length == 1 && silentCheckPermission(sender, "plex.banlist.clear") ? List.of("purge", "clear") : ImmutableList.of();
}
}

View File

@ -0,0 +1,59 @@
package dev.plex.command.impl;
import com.google.common.collect.ImmutableList;
import dev.plex.cache.DataUtils;
import dev.plex.command.PlexCommand;
import dev.plex.command.annotation.CommandParameters;
import dev.plex.command.annotation.CommandPermissions;
import dev.plex.command.exception.PlayerNotFoundException;
import dev.plex.command.source.RequiredCommandSource;
import dev.plex.meta.PlayerMeta;
import dev.plex.player.PlexPlayer;
import dev.plex.util.PlexUtils;
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.util.List;
@CommandPermissions(permission = "plex.broadcastloginmessage", source = RequiredCommandSource.ANY)
@CommandParameters(name = "bcastloginmessage", usage = "/<command> <player>", description = "Broadcast your login message (for vanish support)", aliases = "bcastlm")
public class BcastLoginMessageCMD extends PlexCommand
{
@Override
protected Component execute(@NotNull CommandSender sender, @Nullable Player playerSender, String[] args)
{
if (args.length == 0)
{
return usage();
}
PlexPlayer plexPlayer = DataUtils.getPlayer(args[0]);
if (plexPlayer == null)
{
throw new PlayerNotFoundException();
}
String loginMessage = PlayerMeta.getLoginMessage(plexPlayer);
if (!loginMessage.isEmpty())
{
PlexUtils.broadcast(PlexUtils.stringToComponent(loginMessage));
PlexUtils.broadcast(messageComponent("loginMessage", plexPlayer.getName()));
}
else
{
return mmString("<red>This player does not have a login message.");
}
return null;
}
@Override
public @NotNull List<String> smartTabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) throws IllegalArgumentException
{
return args.length == 1 && silentCheckPermission(sender, this.getPermission()) ? PlexUtils.getPlayerNameList() : ImmutableList.of();
}
}

View File

@ -4,7 +4,6 @@ import dev.plex.command.PlexCommand;
import dev.plex.command.annotation.CommandParameters; import dev.plex.command.annotation.CommandParameters;
import dev.plex.command.annotation.CommandPermissions; import dev.plex.command.annotation.CommandPermissions;
import dev.plex.listener.impl.BlockListener; import dev.plex.listener.impl.BlockListener;
import dev.plex.rank.enums.Rank;
import dev.plex.util.PlexUtils; import dev.plex.util.PlexUtils;
import net.kyori.adventure.text.Component; import net.kyori.adventure.text.Component;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
@ -13,7 +12,12 @@ import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
@CommandPermissions(level = Rank.ADMIN, permission = "plex.blockedit") import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
@CommandPermissions(permission = "plex.blockedit")
@CommandParameters(name = "blockedit", usage = "/<command> [list | purge | all | <player>]", aliases = "bedit", description = "Prevent players from modifying blocks") @CommandParameters(name = "blockedit", usage = "/<command> [list | purge | all | <player>]", aliases = "bedit", description = "Prevent players from modifying blocks")
public class BlockEditCMD extends PlexCommand public class BlockEditCMD extends PlexCommand
{ {
@ -63,7 +67,7 @@ public class BlockEditCMD extends PlexCommand
int count = 0; int count = 0;
for (final Player player : Bukkit.getOnlinePlayers()) for (final Player player : Bukkit.getOnlinePlayers())
{ {
if (!silentCheckRank(player, Rank.ADMIN, "plex.blockedit")) if (!silentCheckPermission(player, "plex.blockedit"))
{ {
bl.blockedPlayers.add(player.getName()); bl.blockedPlayers.add(player.getName());
++count; ++count;
@ -76,7 +80,7 @@ public class BlockEditCMD extends PlexCommand
final Player player = getNonNullPlayer(args[0]); final Player player = getNonNullPlayer(args[0]);
if (!bl.blockedPlayers.contains(player.getName())) if (!bl.blockedPlayers.contains(player.getName()))
{ {
if (silentCheckRank(player, Rank.ADMIN, "plex.blockedit")) if (silentCheckPermission(player, "plex.blockedit"))
{ {
send(sender, messageComponent("higherRankThanYou")); send(sender, messageComponent("higherRankThanYou"));
return null; return null;
@ -95,4 +99,20 @@ public class BlockEditCMD extends PlexCommand
} }
return null; return null;
} }
@Override
public @NotNull List<String> smartTabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) throws IllegalArgumentException
{
if (silentCheckPermission(sender, this.getPermission()))
{
List<String> options = new ArrayList<>();
if (args.length == 1)
{
options.addAll(Arrays.asList("list", "purge", "all"));
options.addAll(PlexUtils.getPlayerNameList());
return options;
}
}
return Collections.emptyList();
}
} }

View File

@ -6,14 +6,16 @@ import dev.plex.command.annotation.CommandParameters;
import dev.plex.command.annotation.CommandPermissions; import dev.plex.command.annotation.CommandPermissions;
import dev.plex.command.source.RequiredCommandSource; import dev.plex.command.source.RequiredCommandSource;
import dev.plex.player.PlexPlayer; import dev.plex.player.PlexPlayer;
import dev.plex.rank.enums.Rank;
import net.kyori.adventure.text.Component; import net.kyori.adventure.text.Component;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
@CommandPermissions(level = Rank.ADMIN, permission = "plex.commandspy", source = RequiredCommandSource.IN_GAME) import java.util.Collections;
import java.util.List;
@CommandPermissions(permission = "plex.commandspy", source = RequiredCommandSource.IN_GAME)
@CommandParameters(name = "commandspy", aliases = "cmdspy", description = "Spy on other player's commands") @CommandParameters(name = "commandspy", aliases = "cmdspy", description = "Spy on other player's commands")
public class CommandSpyCMD extends PlexCommand public class CommandSpyCMD extends PlexCommand
{ {
@ -22,7 +24,7 @@ public class CommandSpyCMD extends PlexCommand
{ {
if (playerSender != null) if (playerSender != null)
{ {
PlexPlayer plexPlayer = DataUtils.getPlayer(playerSender.getUniqueId()); PlexPlayer plexPlayer = plugin.getPlayerCache().getPlexPlayer(playerSender.getUniqueId());
plexPlayer.setCommandSpy(!plexPlayer.isCommandSpy()); plexPlayer.setCommandSpy(!plexPlayer.isCommandSpy());
DataUtils.update(plexPlayer); DataUtils.update(plexPlayer);
send(sender, messageComponent("toggleCommandSpy") send(sender, messageComponent("toggleCommandSpy")
@ -31,4 +33,10 @@ public class CommandSpyCMD extends PlexCommand
} }
return null; return null;
} }
@Override
public @NotNull List<String> smartTabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) throws IllegalArgumentException
{
return Collections.emptyList();
}
} }

View File

@ -4,7 +4,6 @@ import dev.plex.command.PlexCommand;
import dev.plex.command.annotation.CommandParameters; import dev.plex.command.annotation.CommandParameters;
import dev.plex.command.annotation.CommandPermissions; import dev.plex.command.annotation.CommandPermissions;
import dev.plex.command.source.RequiredCommandSource; import dev.plex.command.source.RequiredCommandSource;
import dev.plex.rank.enums.Rank;
import dev.plex.util.PlexUtils; import dev.plex.util.PlexUtils;
import net.kyori.adventure.text.Component; import net.kyori.adventure.text.Component;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
@ -13,7 +12,10 @@ import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
@CommandPermissions(level = Rank.ADMIN, permission = "plex.consolesay", source = RequiredCommandSource.CONSOLE) import java.util.Collections;
import java.util.List;
@CommandPermissions(permission = "plex.consolesay", source = RequiredCommandSource.CONSOLE)
@CommandParameters(name = "consolesay", usage = "/<command> <message>", description = "Displays a message to everyone", aliases = "csay") @CommandParameters(name = "consolesay", usage = "/<command> <message>", description = "Displays a message to everyone", aliases = "csay")
public class ConsoleSayCMD extends PlexCommand public class ConsoleSayCMD extends PlexCommand
{ {
@ -28,4 +30,10 @@ public class ConsoleSayCMD extends PlexCommand
PlexUtils.broadcast(PlexUtils.messageComponent("consoleSayMessage", sender.getName(), PlexUtils.mmStripColor(StringUtils.join(args, " ")))); PlexUtils.broadcast(PlexUtils.messageComponent("consoleSayMessage", sender.getName(), PlexUtils.mmStripColor(StringUtils.join(args, " "))));
return null; return null;
} }
@Override
public @NotNull List<String> smartTabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) throws IllegalArgumentException
{
return Collections.emptyList();
}
} }

View File

@ -7,9 +7,7 @@ import dev.plex.command.annotation.CommandPermissions;
import dev.plex.command.exception.CommandFailException; import dev.plex.command.exception.CommandFailException;
import dev.plex.command.source.RequiredCommandSource; import dev.plex.command.source.RequiredCommandSource;
import dev.plex.event.GameModeUpdateEvent; import dev.plex.event.GameModeUpdateEvent;
import dev.plex.rank.enums.Rank;
import dev.plex.util.PlexUtils; import dev.plex.util.PlexUtils;
import java.util.List;
import net.kyori.adventure.text.Component; import net.kyori.adventure.text.Component;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.GameMode; import org.bukkit.GameMode;
@ -18,7 +16,9 @@ import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
@CommandPermissions(level = Rank.OP, permission = "plex.gamemode.creative", source = RequiredCommandSource.ANY) import java.util.List;
@CommandPermissions(permission = "plex.gamemode.creative", source = RequiredCommandSource.ANY)
@CommandParameters(name = "creative", aliases = "gmc,egmc,ecreative,eecreative,creativemode,ecreativemode", description = "Set your own or another player's gamemode to creative mode") @CommandParameters(name = "creative", aliases = "gmc,egmc,ecreative,eecreative,creativemode,ecreativemode", description = "Set your own or another player's gamemode to creative mode")
public class CreativeCMD extends PlexCommand public class CreativeCMD extends PlexCommand
{ {
@ -29,7 +29,7 @@ public class CreativeCMD extends PlexCommand
{ {
if (isConsole(sender)) if (isConsole(sender))
{ {
throw new CommandFailException(PlexUtils.messageString("consoleMustDefinePlayer")); throw new CommandFailException(messageString("consoleMustDefinePlayer"));
} }
if (!(playerSender == null)) if (!(playerSender == null))
{ {
@ -38,8 +38,7 @@ public class CreativeCMD extends PlexCommand
return null; return null;
} }
if (checkRank(sender, Rank.ADMIN, "plex.gamemode.creative.others")) checkPermission(sender, "plex.gamemode.creative.others");
{
if (args[0].equals("-a")) if (args[0].equals("-a"))
{ {
for (Player targetPlayer : Bukkit.getServer().getOnlinePlayers()) for (Player targetPlayer : Bukkit.getServer().getOnlinePlayers())
@ -55,13 +54,11 @@ public class CreativeCMD extends PlexCommand
Bukkit.getServer().getPluginManager().callEvent(new GameModeUpdateEvent(sender, nPlayer, GameMode.CREATIVE)); Bukkit.getServer().getPluginManager().callEvent(new GameModeUpdateEvent(sender, nPlayer, GameMode.CREATIVE));
return null; return null;
} }
return null;
}
@Override @Override
public @NotNull List<String> tabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) throws IllegalArgumentException public @NotNull List<String> smartTabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) throws IllegalArgumentException
{ {
if (checkTab(sender, Rank.ADMIN, "plex.gamemode.creative.others")) if (silentCheckPermission(sender, "plex.gamemode.creative.others"))
{ {
return PlexUtils.getPlayerNameList(); return PlexUtils.getPlayerNameList();
} }

View File

@ -4,14 +4,10 @@ import com.google.common.collect.ImmutableList;
import dev.plex.command.PlexCommand; import dev.plex.command.PlexCommand;
import dev.plex.command.annotation.CommandParameters; import dev.plex.command.annotation.CommandParameters;
import dev.plex.command.annotation.CommandPermissions; import dev.plex.command.annotation.CommandPermissions;
import dev.plex.command.annotation.System; import dev.plex.menu.impl.MaterialMenu;
import dev.plex.rank.enums.Rank;
import dev.plex.util.GameRuleUtil; import dev.plex.util.GameRuleUtil;
import dev.plex.util.PlexLog; import dev.plex.util.PlexLog;
import dev.plex.util.PlexUtils; 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.Component;
import net.kyori.adventure.text.format.NamedTextColor; import net.kyori.adventure.text.format.NamedTextColor;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
@ -22,9 +18,12 @@ import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
import java.util.Arrays;
import java.util.List;
import java.util.Locale;
@CommandParameters(name = "pdebug", description = "Plex's debug command", usage = "/<command> <aliases <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") @CommandPermissions(permission = "plex.debug")
@System(debug = true)
public class DebugCMD extends PlexCommand public class DebugCMD extends PlexCommand
{ {
@Override @Override
@ -35,14 +34,17 @@ public class DebugCMD extends PlexCommand
return usage(); return usage();
} }
if (args[0].equalsIgnoreCase("redis-reset")) if (args[0].equalsIgnoreCase("redis-reset"))
{
if (args.length == 2)
{ {
Player player = getNonNullPlayer(args[1]); Player player = getNonNullPlayer(args[1]);
if (plugin.getRedisConnection().getJedis().exists(player.getUniqueId().toString())) if (plugin.getRedisConnection().getJedis().exists(player.getUniqueId().toString()))
{ {
plugin.getRedisConnection().getJedis().del(player.getUniqueId().toString()); plugin.getRedisConnection().getJedis().del(player.getUniqueId().toString());
return componentFromString("Successfully reset " + player.getName() + "'s Redis punishments!").color(NamedTextColor.YELLOW); return messageComponent("redisResetSuccessful", player.getName());
}
return messageComponent("redisResetPlayerNotFound");
} }
return componentFromString("Couldn't find player in Redis punishments.");
} }
if (args[0].equalsIgnoreCase("gamerules")) if (args[0].equalsIgnoreCase("gamerules"))
{ {
@ -60,24 +62,36 @@ public class DebugCMD extends PlexCommand
PlexLog.log("Set specific gamerules for world: " + world.toLowerCase(Locale.ROOT)); PlexLog.log("Set specific gamerules for world: " + world.toLowerCase(Locale.ROOT));
} }
} }
return mmString("<aqua>Re-applied game all the game rules!"); return messageComponent("reappliedGamerules");
} }
if (args[0].equalsIgnoreCase("aliases")) if (args[0].equalsIgnoreCase("aliases"))
{
if (args.length == 2)
{ {
String commandName = args[1]; String commandName = args[1];
Command command = plugin.getServer().getCommandMap().getCommand(commandName); Command command = plugin.getServer().getCommandMap().getCommand(commandName);
if (command == null) if (command == null)
{ {
return mmString("<red>That command could not be found!"); return messageComponent("commandNotFound");
} }
return mmString("<aqua>Aliases for " + commandName + " are: " + Arrays.toString(command.getAliases().toArray(new String[0]))); return messageComponent("commandAliases", commandName, Arrays.toString(command.getAliases().toArray(new String[0])));
} }
}
if (args[0].equalsIgnoreCase("pagination"))
{
if (playerSender == null)
{
return messageComponent("noPermissionConsole");
}
new MaterialMenu().open(playerSender);
return null; return null;
} }
return usage();
}
@Override @Override
public @NotNull List<String> tabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) throws IllegalArgumentException public @NotNull List<String> smartTabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) throws IllegalArgumentException
{ {
return args.length == 1 ? PlexUtils.getPlayerNameList() : ImmutableList.of(); return args.length == 1 && silentCheckPermission(sender, this.getPermission()) ? PlexUtils.getPlayerNameList() : ImmutableList.of();
} }
} }

View File

@ -1,31 +0,0 @@
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.annotation.System;
import dev.plex.rank.enums.Rank;
import dev.plex.util.PlexUtils;
import net.kyori.adventure.text.Component;
import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@CommandParameters(name = "deopall", description = "Deop everyone on the server", aliases = "deopa")
@CommandPermissions(level = Rank.ADMIN)
@System(value = "ranks")
public class DeopAllCMD extends PlexCommand
{
@Override
protected Component execute(@NotNull CommandSender sender, @Nullable Player playerSender, String[] args)
{
for (Player player : Bukkit.getOnlinePlayers())
{
player.setOp(false);
}
PlexUtils.broadcast(messageComponent("deoppedAllPlayers", sender.getName()));
return null;
}
}

View File

@ -1,40 +0,0 @@
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;
import dev.plex.command.annotation.System;
import dev.plex.rank.enums.Rank;
import dev.plex.util.PlexUtils;
import java.util.List;
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;
@CommandParameters(name = "deop", description = "Deop a player on the server", usage = "/<command> <player>")
@CommandPermissions(level = Rank.ADMIN, permission = "plex.deop")
@System(value = "ranks")
public class DeopCMD extends PlexCommand
{
@Override
protected Component execute(@NotNull CommandSender sender, @Nullable Player playerSender, String[] args)
{
if (args.length != 1)
{
return usage();
}
Player player = getNonNullPlayer(args[0]);
player.setOp(false);
PlexUtils.broadcast(messageComponent("deoppedPlayer", sender.getName(), player.getName()));
return null;
}
@Override
public @NotNull List<String> tabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) throws IllegalArgumentException
{
return args.length == 1 ? PlexUtils.getPlayerNameList() : ImmutableList.of();
}
}

View File

@ -4,13 +4,8 @@ import dev.plex.command.PlexCommand;
import dev.plex.command.annotation.CommandParameters; import dev.plex.command.annotation.CommandParameters;
import dev.plex.command.annotation.CommandPermissions; import dev.plex.command.annotation.CommandPermissions;
import dev.plex.command.source.RequiredCommandSource; import dev.plex.command.source.RequiredCommandSource;
import dev.plex.rank.enums.Rank; import dev.plex.util.PlexLog;
import dev.plex.util.PlexUtils; import dev.plex.util.PlexUtils;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import net.kyori.adventure.text.Component; import net.kyori.adventure.text.Component;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.World; import org.bukkit.World;
@ -21,8 +16,10 @@ import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
@CommandPermissions(level = Rank.ADMIN, permission = "plex.entitywipe", source = RequiredCommandSource.ANY) import java.util.*;
@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")
@CommandPermissions(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> [entity] [radius]", aliases = "ew,rd")
public class EntityWipeCMD extends PlexCommand public class EntityWipeCMD extends PlexCommand
{ {
@Override @Override
@ -32,6 +29,22 @@ public class EntityWipeCMD extends PlexCommand
List<String> entityWhitelist = new LinkedList<>(Arrays.asList(args)); List<String> entityWhitelist = new LinkedList<>(Arrays.asList(args));
boolean radiusSpecified = !entityWhitelist.isEmpty() && isNumeric(entityWhitelist.get(entityWhitelist.size() - 1)); // try and detect if the last argument of the command is a number
boolean useBlacklist = args.length == 0 || (args.length == 1 && radiusSpecified); // if there are no arguments or the one argument is a number
int radius = 0;
PlexLog.debug("using blacklist: " + useBlacklist);
PlexLog.debug("radius specified: " + radiusSpecified);
if (radiusSpecified)
{
radius = parseInt(sender, args[entityWhitelist.size() - 1]); // get the args length as the size of the list
radius *= radius;
entityWhitelist.remove(entityWhitelist.size() - 1); // remove the radius from the list
}
PlexLog.debug("radius: " + radius);
EntityType[] entityTypes = EntityType.values(); EntityType[] entityTypes = EntityType.values();
entityWhitelist.removeIf(name -> entityWhitelist.removeIf(name ->
{ {
@ -43,8 +56,6 @@ public class EntityWipeCMD extends PlexCommand
return res; return res;
}); });
boolean useBlacklist = args.length == 0;
HashMap<String, Integer> entityCounts = new HashMap<>(); HashMap<String, Integer> entityCounts = new HashMap<>();
for (World world : Bukkit.getWorlds()) for (World world : Bukkit.getWorlds())
@ -57,6 +68,16 @@ public class EntityWipeCMD extends PlexCommand
if (useBlacklist ? entityBlacklist.stream().noneMatch(entityName -> entityName.equalsIgnoreCase(type)) : entityWhitelist.stream().anyMatch(entityName -> entityName.equalsIgnoreCase(type))) if (useBlacklist ? entityBlacklist.stream().noneMatch(entityName -> entityName.equalsIgnoreCase(type)) : entityWhitelist.stream().anyMatch(entityName -> entityName.equalsIgnoreCase(type)))
{ {
if (radius > 0)
{
PlexLog.debug("we got here, radius is > 0");
if (playerSender != null && entity.getWorld() == playerSender.getWorld() && playerSender.getLocation().distanceSquared(entity.getLocation()) > radius)
{
PlexLog.debug("continuing");
continue;
}
}
PlexLog.debug("removed entity: " + entity.getType().name());
entity.remove(); entity.remove();
entityCounts.put(type, entityCounts.getOrDefault(type, 0) + 1); entityCounts.put(type, entityCounts.getOrDefault(type, 0) + 1);
@ -85,7 +106,9 @@ public class EntityWipeCMD extends PlexCommand
return null; return null;
} }
public @NotNull List<String> tabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) throws IllegalArgumentException public @NotNull List<String> smartTabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) throws IllegalArgumentException
{
if (silentCheckPermission(sender, this.getPermission()))
{ {
List<String> entities = new ArrayList<>(); List<String> entities = new ArrayList<>();
for (World world : Bukkit.getWorlds()) for (World world : Bukkit.getWorlds())
@ -100,4 +123,36 @@ public class EntityWipeCMD extends PlexCommand
} }
return entities.stream().toList(); return entities.stream().toList();
} }
return Collections.emptyList();
}
private Integer parseInt(CommandSender sender, String string)
{
try
{
return Integer.parseInt(string);
}
catch (NumberFormatException ex)
{
sender.sendMessage(messageComponent("notANumber", string));
}
return null;
}
private boolean isNumeric(String string)
{
if (string == null)
{
return false;
}
try
{
int num = Integer.parseInt(string);
}
catch (NumberFormatException nfe)
{
return false;
}
return true;
}
} }

View File

@ -4,7 +4,6 @@ import dev.plex.command.PlexCommand;
import dev.plex.command.annotation.CommandParameters; import dev.plex.command.annotation.CommandParameters;
import dev.plex.command.annotation.CommandPermissions; import dev.plex.command.annotation.CommandPermissions;
import dev.plex.command.source.RequiredCommandSource; import dev.plex.command.source.RequiredCommandSource;
import dev.plex.rank.enums.Rank;
import net.kyori.adventure.text.Component; import net.kyori.adventure.text.Component;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.Location; import org.bukkit.Location;
@ -13,7 +12,10 @@ import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
@CommandPermissions(level = Rank.OP, permission = "plex.flatlands", source = RequiredCommandSource.IN_GAME) import java.util.Collections;
import java.util.List;
@CommandPermissions(permission = "plex.flatlands", source = RequiredCommandSource.IN_GAME)
@CommandParameters(name = "flatlands", description = "Teleport to the flatlands") @CommandParameters(name = "flatlands", description = "Teleport to the flatlands")
public class FlatlandsCMD extends PlexCommand public class FlatlandsCMD extends PlexCommand
{ {
@ -29,4 +31,10 @@ public class FlatlandsCMD extends PlexCommand
} }
return null; return null;
} }
@Override
public @NotNull List<String> smartTabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) throws IllegalArgumentException
{
return Collections.emptyList();
}
} }

View File

@ -7,20 +7,20 @@ import dev.plex.command.annotation.CommandPermissions;
import dev.plex.player.PlexPlayer; import dev.plex.player.PlexPlayer;
import dev.plex.punishment.Punishment; import dev.plex.punishment.Punishment;
import dev.plex.punishment.PunishmentType; import dev.plex.punishment.PunishmentType;
import dev.plex.rank.enums.Rank;
import dev.plex.util.PlexUtils; import dev.plex.util.PlexUtils;
import dev.plex.util.TimeUtils; import dev.plex.util.TimeUtils;
import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.util.List;
import net.kyori.adventure.text.Component; import net.kyori.adventure.text.Component;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.util.List;
@CommandParameters(name = "freeze", description = "Freeze a player on the server", usage = "/<command> <player>", aliases = "fr") @CommandParameters(name = "freeze", description = "Freeze a player on the server", usage = "/<command> <player>", aliases = "fr")
@CommandPermissions(level = Rank.ADMIN, permission = "plex.freeze") @CommandPermissions(permission = "plex.freeze")
public class FreezeCMD extends PlexCommand public class FreezeCMD extends PlexCommand
{ {
@Override @Override
@ -38,27 +38,15 @@ public class FreezeCMD extends PlexCommand
return messageComponent("playerFrozen"); return messageComponent("playerFrozen");
} }
if (isAdmin(getPlexPlayer(player)))
{
if (!isConsole(sender))
{
assert playerSender != null;
PlexPlayer plexPlayer1 = getPlexPlayer(playerSender);
if (!plexPlayer1.getRankFromString().isAtLeast(getPlexPlayer(player).getRankFromString()) && getPlexPlayer(player).isAdminActive())
{
return messageComponent("higherRankThanYou");
}
}
}
Punishment punishment = new Punishment(punishedPlayer.getUuid(), getUUID(sender)); Punishment punishment = new Punishment(punishedPlayer.getUuid(), getUUID(sender));
punishment.setCustomTime(false); punishment.setCustomTime(false);
ZonedDateTime date = ZonedDateTime.now(ZoneId.of(TimeUtils.TIMEZONE)); ZonedDateTime date = ZonedDateTime.now(ZoneId.of(TimeUtils.TIMEZONE));
punishment.setEndDate(date.plusMinutes(5)); punishment.setEndDate(date.plusSeconds(plugin.config.getInt("punishments.freeze-timer", 300)));
punishment.setType(PunishmentType.FREEZE); punishment.setType(PunishmentType.FREEZE);
punishment.setPunishedUsername(player.getName()); punishment.setPunishedUsername(player.getName());
punishment.setIp(player.getAddress().getAddress().getHostAddress().trim()); punishment.setIp(player.getAddress().getAddress().getHostAddress().trim());
punishment.setReason(""); punishment.setReason("");
punishment.setActive(true);
plugin.getPunishmentManager().punish(punishedPlayer, punishment); plugin.getPunishmentManager().punish(punishedPlayer, punishment);
PlexUtils.broadcast(messageComponent("frozePlayer", sender.getName(), player.getName())); PlexUtils.broadcast(messageComponent("frozePlayer", sender.getName(), player.getName()));
@ -66,8 +54,8 @@ public class FreezeCMD extends PlexCommand
} }
@Override @Override
public @NotNull List<String> tabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) throws IllegalArgumentException public @NotNull List<String> smartTabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) throws IllegalArgumentException
{ {
return args.length == 1 && checkTab(sender, Rank.ADMIN, "plex.freeze") ? PlexUtils.getPlayerNameList() : ImmutableList.of(); return args.length == 1 && silentCheckPermission(sender, this.getPermission()) ? PlexUtils.getPlayerNameList() : ImmutableList.of();
} }
} }

View File

@ -6,11 +6,7 @@ import dev.plex.command.annotation.CommandPermissions;
import dev.plex.command.exception.CommandFailException; import dev.plex.command.exception.CommandFailException;
import dev.plex.command.source.RequiredCommandSource; import dev.plex.command.source.RequiredCommandSource;
import dev.plex.event.GameModeUpdateEvent; import dev.plex.event.GameModeUpdateEvent;
import dev.plex.rank.enums.Rank;
import dev.plex.util.PlexUtils; import dev.plex.util.PlexUtils;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import net.kyori.adventure.text.Component; import net.kyori.adventure.text.Component;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.GameMode; import org.bukkit.GameMode;
@ -19,8 +15,12 @@ import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
@CommandParameters(name = "gamemode", usage = "/<command> <creative | survival | adventure | default | spectator> [player]", description = "Change your gamemode", aliases = "gm,egamemode,gmt,egmt") @CommandParameters(name = "gamemode", usage = "/<command> <creative | survival | adventure | default | spectator> [player]", description = "Change your gamemode", aliases = "gm,egamemode,gmt,egmt")
@CommandPermissions(level = Rank.OP, permission = "plex.gamemode", source = RequiredCommandSource.ANY) @CommandPermissions(permission = "plex.gamemode", source = RequiredCommandSource.ANY)
public class GamemodeCMD extends PlexCommand public class GamemodeCMD extends PlexCommand
{ {
private GameMode gamemode; private GameMode gamemode;
@ -61,14 +61,14 @@ public class GamemodeCMD extends PlexCommand
case "spectator", "sp", "3", "6" -> case "spectator", "sp", "3", "6" ->
{ {
gamemode = GameMode.SPECTATOR; gamemode = GameMode.SPECTATOR;
checkRank(sender, Rank.ADMIN, "plex.gamemode.spectator"); checkPermission(sender, "plex.gamemode.spectator");
update(sender, playerSender, GameMode.SPECTATOR); update(sender, playerSender, GameMode.SPECTATOR);
return null; return null;
} }
} }
if (args.length > 1) if (args.length > 1)
{ {
checkRank(sender, Rank.ADMIN, "plex.gamemode.others"); checkPermission(sender, "plex.gamemode.others");
Player player = getNonNullPlayer(args[1]); Player player = getNonNullPlayer(args[1]);
Bukkit.getServer().getPluginManager().callEvent(new GameModeUpdateEvent(sender, player, gamemode)); Bukkit.getServer().getPluginManager().callEvent(new GameModeUpdateEvent(sender, player, gamemode));
} }
@ -88,16 +88,19 @@ public class GamemodeCMD extends PlexCommand
} }
@Override @Override
public @NotNull List<String> tabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) throws IllegalArgumentException public @NotNull List<String> smartTabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) throws IllegalArgumentException
{ {
if (args.length == 1) if (args.length == 1)
{ {
return Arrays.asList("creative", "survival", "adventure", "spectator", "default"); return Arrays.asList("creative", "survival", "adventure", "spectator", "default");
} }
if (args.length == 2) if (args.length == 2)
{
if (silentCheckPermission(sender, "plex.gamemode.others"))
{ {
return PlexUtils.getPlayerNameList(); return PlexUtils.getPlayerNameList();
} }
}
return Collections.emptyList(); return Collections.emptyList();
} }
} }

View File

@ -1,5 +1,6 @@
package dev.plex.command.impl; package dev.plex.command.impl;
import com.google.common.collect.ImmutableList;
import dev.plex.cache.DataUtils; import dev.plex.cache.DataUtils;
import dev.plex.command.PlexCommand; import dev.plex.command.PlexCommand;
import dev.plex.command.annotation.CommandParameters; import dev.plex.command.annotation.CommandParameters;
@ -9,14 +10,9 @@ import dev.plex.command.source.RequiredCommandSource;
import dev.plex.player.PlexPlayer; import dev.plex.player.PlexPlayer;
import dev.plex.punishment.Punishment; import dev.plex.punishment.Punishment;
import dev.plex.punishment.PunishmentType; import dev.plex.punishment.PunishmentType;
import dev.plex.rank.enums.Rank;
import dev.plex.util.BungeeUtil; import dev.plex.util.BungeeUtil;
import dev.plex.util.PlexUtils; import dev.plex.util.PlexUtils;
import dev.plex.util.TimeUtils; import dev.plex.util.TimeUtils;
import dev.plex.util.WebUtils;
import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.util.UUID;
import net.kyori.adventure.text.Component; import net.kyori.adventure.text.Component;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
@ -25,8 +21,12 @@ import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.util.List;
@CommandParameters(name = "kick", description = "Kicks a player", usage = "/<command> <player>") @CommandParameters(name = "kick", description = "Kicks a player", usage = "/<command> <player>")
@CommandPermissions(level = Rank.ADMIN, permission = "plex.kick", source = RequiredCommandSource.ANY) @CommandPermissions(permission = "plex.kick", source = RequiredCommandSource.ANY)
public class KickCMD extends PlexCommand public class KickCMD extends PlexCommand
{ {
@Override @Override
@ -37,28 +37,27 @@ public class KickCMD extends PlexCommand
return usage(); return usage();
} }
UUID targetUUID = WebUtils.getFromName(args[0]); PlexPlayer plexPlayer = DataUtils.getPlayer(args[0]);
String reason = "No reason provided"; String reason = messageString("noReasonProvided");
if (targetUUID == null || !DataUtils.hasPlayedBefore(targetUUID)) if (plexPlayer == null)
{ {
throw new PlayerNotFoundException(); throw new PlayerNotFoundException();
} }
PlexPlayer plexPlayer = DataUtils.getPlayer(targetUUID); Player player = Bukkit.getPlayer(plexPlayer.getUuid());
Player player = Bukkit.getPlayer(targetUUID);
if (player == null) if (player == null)
{ {
throw new PlayerNotFoundException(); throw new PlayerNotFoundException();
} }
Punishment punishment = new Punishment(targetUUID, getUUID(sender)); Punishment punishment = new Punishment(plexPlayer.getUuid(), getUUID(sender));
punishment.setType(PunishmentType.KICK); punishment.setType(PunishmentType.KICK);
if (args.length > 1) if (args.length > 1)
{ {
reason = StringUtils.join(args, " ", 1, args.length); reason = StringUtils.join(args, " ", 1, args.length);
punishment.setReason(reason);
} }
punishment.setReason(reason);
punishment.setPunishedUsername(plexPlayer.getName()); punishment.setPunishedUsername(plexPlayer.getName());
punishment.setEndDate(ZonedDateTime.now(ZoneId.of(TimeUtils.TIMEZONE))); punishment.setEndDate(ZonedDateTime.now(ZoneId.of(TimeUtils.TIMEZONE)));
punishment.setCustomTime(false); punishment.setCustomTime(false);
@ -66,7 +65,13 @@ public class KickCMD extends PlexCommand
punishment.setIp(player.getAddress().getAddress().getHostAddress().trim()); punishment.setIp(player.getAddress().getAddress().getHostAddress().trim());
plugin.getPunishmentManager().punish(plexPlayer, punishment); plugin.getPunishmentManager().punish(plexPlayer, punishment);
PlexUtils.broadcast(messageComponent("kickedPlayer", sender.getName(), plexPlayer.getName())); PlexUtils.broadcast(messageComponent("kickedPlayer", sender.getName(), plexPlayer.getName()));
BungeeUtil.kickPlayer(player, Punishment.generateBanMessage(punishment)); BungeeUtil.kickPlayer(player, Punishment.generateKickMessage(punishment));
return null; return null;
} }
@Override
public @NotNull List<String> smartTabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) throws IllegalArgumentException
{
return args.length == 1 && silentCheckPermission(sender, this.getPermission()) ? PlexUtils.getPlayerNameList() : ImmutableList.of();
}
} }

View File

@ -2,11 +2,11 @@ package dev.plex.command.impl;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
import dev.plex.command.PlexCommand; import dev.plex.command.PlexCommand;
import dev.plex.util.PlexUtils;
import dev.plex.command.annotation.CommandParameters; import dev.plex.command.annotation.CommandParameters;
import dev.plex.command.annotation.CommandPermissions; import dev.plex.command.annotation.CommandPermissions;
import dev.plex.command.annotation.System; import dev.plex.hook.VaultHook;
import dev.plex.rank.enums.Rank; import dev.plex.meta.PlayerMeta;
import java.util.List;
import net.kyori.adventure.text.Component; import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.NamedTextColor; import net.kyori.adventure.text.format.NamedTextColor;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
@ -15,36 +15,49 @@ import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
@CommandParameters(name = "list", description = "Show a list of all online players", aliases = "lsit") import java.util.Collections;
@CommandPermissions(level = Rank.OP, permission = "plex.list") import java.util.List;
@System(value = "ranks")
@CommandParameters(name = "list", description = "Show a list of all online players", usage = "/<command> [-d | -v]", aliases = "lsit,who,playerlist,online")
@CommandPermissions(permission = "plex.list")
public class ListCMD extends PlexCommand public class ListCMD extends PlexCommand
{ {
@Override @Override
protected Component execute(@NotNull CommandSender sender, @Nullable Player playerSender, String[] args) protected Component execute(@NotNull CommandSender sender, @Nullable Player playerSender, String[] args)
{ {
List<Player> players = Lists.newArrayList(Bukkit.getOnlinePlayers()); List<Player> players = Lists.newArrayList(Bukkit.getOnlinePlayers());
if (args.length > 0 && args[0].equalsIgnoreCase("-v"))
{
checkPermission(sender, "plex.list.vanished");
players.removeIf(player -> !PlayerMeta.isVanished(player));
}
else
{
players.removeIf(PlayerMeta::isVanished);
}
Component list = Component.empty(); Component list = Component.empty();
Component header = Component.text("There " + (players.size() == 1 ? "is" : "are") + " currently").color(NamedTextColor.GRAY) Component header = PlexUtils.messageComponent(players.size() == 1 ? "listHeader" : "listHeaderPlural", players.size(), Bukkit.getMaxPlayers());
.append(Component.space())
.append(Component.text(players.size()).color(NamedTextColor.YELLOW))
.append(Component.space())
.append(Component.text(players.size() == 1 ? "player" : "players").color(NamedTextColor.GRAY))
.append(Component.space())
.append(Component.text("online out of").color(NamedTextColor.GRAY))
.append(Component.space())
.append(Component.text(Bukkit.getMaxPlayers()).color(NamedTextColor.YELLOW))
.append(Component.space())
.append(Component.text(Bukkit.getMaxPlayers() == 1 ? "player." : "players.").color(NamedTextColor.GRAY));
send(sender, header); send(sender, header);
if (players.size() == 0) if (players.isEmpty())
{ {
return null; return null;
} }
for (int i = 0; i < players.size(); i++) for (int i = 0; i < players.size(); i++)
{ {
Player player = players.get(i); Player player = players.get(i);
list = list.append(getPlexPlayer(player).getRankFromString().getPrefix()).append(Component.space()).append(Component.text(player.getName()).color(NamedTextColor.WHITE)); Component prefix = VaultHook.getPrefix(getPlexPlayer(player));
if (prefix != null && !prefix.equals(Component.empty()) && !prefix.equals(Component.space()))
{
list = list.append(prefix).append(Component.space());
}
list = list.append(Component.text(player.getName()).color(NamedTextColor.WHITE));
if (args.length > 0 && args[0].equalsIgnoreCase("-d"))
{
list = list.append(Component.space());
list = list.append(Component.text("(").color(NamedTextColor.WHITE));
list = list.append(player.displayName());
list = list.append(Component.text(")").color(NamedTextColor.WHITE));
}
if (i != players.size() - 1) if (i != players.size() - 1)
{ {
list = list.append(Component.text(",")).append(Component.space()); list = list.append(Component.text(",")).append(Component.space());
@ -52,4 +65,13 @@ public class ListCMD extends PlexCommand
} }
return list; return list;
} }
public @NotNull List<String> smartTabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) throws IllegalArgumentException
{
if (args.length == 1 && silentCheckPermission(sender, this.getPermission()))
{
return List.of("-d", "-v");
}
return Collections.emptyList();
}
} }

View File

@ -4,15 +4,18 @@ import dev.plex.command.PlexCommand;
import dev.plex.command.annotation.CommandParameters; import dev.plex.command.annotation.CommandParameters;
import dev.plex.command.annotation.CommandPermissions; import dev.plex.command.annotation.CommandPermissions;
import dev.plex.command.source.RequiredCommandSource; import dev.plex.command.source.RequiredCommandSource;
import dev.plex.rank.enums.Rank;
import net.kyori.adventure.text.Component; import net.kyori.adventure.text.Component;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
import java.util.Collections;
import java.util.List;
@CommandParameters(name = "localspawn", description = "Teleport to the spawnpoint of the world you are in") @CommandParameters(name = "localspawn", description = "Teleport to the spawnpoint of the world you are in")
@CommandPermissions(level = Rank.OP, permission = "plex.localspawn", source = RequiredCommandSource.IN_GAME) @CommandPermissions(permission = "plex.localspawn", source = RequiredCommandSource.IN_GAME)
public class LocalSpawnCMD extends PlexCommand public class LocalSpawnCMD extends PlexCommand
{ {
@Override @Override
@ -22,4 +25,10 @@ public class LocalSpawnCMD extends PlexCommand
playerSender.teleportAsync(playerSender.getWorld().getSpawnLocation()); playerSender.teleportAsync(playerSender.getWorld().getSpawnLocation());
return messageComponent("teleportedToWorldSpawn"); return messageComponent("teleportedToWorldSpawn");
} }
@Override
public @NotNull List<String> smartTabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) throws IllegalArgumentException
{
return Collections.emptyList();
}
} }

View File

@ -5,17 +5,17 @@ import dev.plex.command.PlexCommand;
import dev.plex.command.annotation.CommandParameters; import dev.plex.command.annotation.CommandParameters;
import dev.plex.command.annotation.CommandPermissions; import dev.plex.command.annotation.CommandPermissions;
import dev.plex.player.PlexPlayer; import dev.plex.player.PlexPlayer;
import dev.plex.rank.enums.Rank;
import dev.plex.util.PlexUtils; import dev.plex.util.PlexUtils;
import java.util.List;
import net.kyori.adventure.text.Component; import net.kyori.adventure.text.Component;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
import java.util.List;
@CommandParameters(name = "lockup", description = "Lockup a player on the server", usage = "/<command> <player>") @CommandParameters(name = "lockup", description = "Lockup a player on the server", usage = "/<command> <player>")
@CommandPermissions(level = Rank.ADMIN, permission = "plex.lockup") @CommandPermissions(permission = "plex.lockup")
public class LockupCMD extends PlexCommand public class LockupCMD extends PlexCommand
{ {
@Override @Override
@ -28,19 +28,6 @@ public class LockupCMD extends PlexCommand
Player player = getNonNullPlayer(args[0]); Player player = getNonNullPlayer(args[0]);
PlexPlayer punishedPlayer = getOfflinePlexPlayer(player.getUniqueId()); PlexPlayer punishedPlayer = getOfflinePlexPlayer(player.getUniqueId());
if (isAdmin(getPlexPlayer(player)))
{
if (!isConsole(sender))
{
assert playerSender != null;
PlexPlayer plexPlayer1 = getPlexPlayer(playerSender);
if (!plexPlayer1.getRankFromString().isAtLeast(getPlexPlayer(player).getRankFromString()))
{
return messageComponent("higherRankThanYou");
}
}
}
punishedPlayer.setLockedUp(!punishedPlayer.isLockedUp()); punishedPlayer.setLockedUp(!punishedPlayer.isLockedUp());
if (punishedPlayer.isLockedUp()) if (punishedPlayer.isLockedUp())
{ {
@ -51,8 +38,8 @@ public class LockupCMD extends PlexCommand
} }
@Override @Override
public @NotNull List<String> tabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) throws IllegalArgumentException public @NotNull List<String> smartTabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) throws IllegalArgumentException
{ {
return args.length == 1 && checkTab(sender, Rank.ADMIN, "plex.lockup") ? PlexUtils.getPlayerNameList() : ImmutableList.of(); return args.length == 1 && silentCheckPermission(sender, this.getPermission()) ? PlexUtils.getPlayerNameList() : ImmutableList.of();
} }
} }

View File

@ -4,7 +4,7 @@ import dev.plex.command.PlexCommand;
import dev.plex.command.annotation.CommandParameters; import dev.plex.command.annotation.CommandParameters;
import dev.plex.command.annotation.CommandPermissions; import dev.plex.command.annotation.CommandPermissions;
import dev.plex.command.source.RequiredCommandSource; import dev.plex.command.source.RequiredCommandSource;
import dev.plex.rank.enums.Rank;
import net.kyori.adventure.text.Component; import net.kyori.adventure.text.Component;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.Location; import org.bukkit.Location;
@ -13,7 +13,10 @@ import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
@CommandPermissions(level = Rank.OP, permission = "plex.masterbuilderworld", source = RequiredCommandSource.IN_GAME) import java.util.Collections;
import java.util.List;
@CommandPermissions(permission = "plex.masterbuilderworld", source = RequiredCommandSource.IN_GAME)
@CommandParameters(name = "masterbuilderworld", aliases = "mbw", description = "Teleport to the Master Builder world") @CommandParameters(name = "masterbuilderworld", aliases = "mbw", description = "Teleport to the Master Builder world")
public class MasterbuilderworldCMD extends PlexCommand public class MasterbuilderworldCMD extends PlexCommand
{ {
@ -30,4 +33,10 @@ public class MasterbuilderworldCMD extends PlexCommand
} }
return null; return null;
} }
@Override
public @NotNull List<String> smartTabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) throws IllegalArgumentException
{
return Collections.emptyList();
}
} }

View File

@ -0,0 +1,96 @@
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.util.PlexUtils;
import net.kyori.adventure.text.Component;
import org.bukkit.Bukkit;
import org.bukkit.Chunk;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
@CommandParameters(name = "moblimit", usage = "/<command> [on | off | setmax <limit>]", aliases = "entitylimit", description = "Manages the mob limit per chunk.")
@CommandPermissions(permission = "plex.moblimit", source = RequiredCommandSource.ANY)
public class MobLimitCMD extends PlexCommand
{
@Override
protected Component execute(@NotNull CommandSender sender, @Nullable Player playerSender, String[] args)
{
if (args.length == 0)
{
Chunk chunk = playerSender != null ? playerSender.getLocation().getChunk() : Bukkit.getWorlds().get(0).getChunkAt(0, 0);
int currentLimit = plugin.config.getInt("entity_limit.max_mobs_per_chunk");
int currentMobCount = (int) Arrays.stream(chunk.getEntities())
.filter(entity -> entity instanceof LivingEntity && !(entity instanceof Player))
.count();
String status = plugin.config.getBoolean("entity_limit.mob_limit_enabled") ? "<green>Enabled" : "<red>Disabled";
return PlexUtils.messageComponent("mobLimitStatus", status, currentMobCount, currentLimit, chunk.getX(), chunk.getZ());
}
switch (args[0].toLowerCase())
{
case "on":
plugin.config.set("entity_limit.mob_limit_enabled", true);
plugin.config.save();
return PlexUtils.messageComponent("mobLimitToggle", "enabled");
case "off":
plugin.config.set("entity_limit.mob_limit_enabled", false);
plugin.config.save();
return PlexUtils.messageComponent("mobLimitToggle", "disabled");
case "setmax":
try
{
if (args.length != 2) return usage();
int newLimit = Integer.parseInt(args[1]);
if (newLimit < 0) throw new NumberFormatException();
int limitCeiling = plugin.config.getInt("entity_limit.mob_limit_ceiling");
if (newLimit > limitCeiling)
{
newLimit = limitCeiling;
sender.sendMessage(PlexUtils.messageComponent("mobLimitCeiling"));
}
plugin.config.set("entity_limit.max_mobs_per_chunk", newLimit);
plugin.config.save();
return PlexUtils.messageComponent("mobLimitSet", newLimit);
}
catch (NumberFormatException e)
{
return PlexUtils.messageComponent("unableToParseNumber", args[1]);
}
default:
return usage();
}
}
@Override
public @NotNull List<String> smartTabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) throws IllegalArgumentException
{
if (silentCheckPermission(sender, this.getPermission()))
{
if (args.length == 1)
{
return Arrays.asList("on", "off", "setmax");
}
if (args.length == 2 && args[0].equals("setmax"))
{
return Collections.emptyList();
}
return Collections.emptyList();
}
return Collections.emptyList();
}
}

View File

@ -4,49 +4,119 @@ import dev.plex.command.PlexCommand;
import dev.plex.command.annotation.CommandParameters; import dev.plex.command.annotation.CommandParameters;
import dev.plex.command.annotation.CommandPermissions; import dev.plex.command.annotation.CommandPermissions;
import dev.plex.command.source.RequiredCommandSource; import dev.plex.command.source.RequiredCommandSource;
import dev.plex.rank.enums.Rank; import dev.plex.util.PlexLog;
import dev.plex.util.PlexUtils; import dev.plex.util.PlexUtils;
import java.util.HashMap;
import net.kyori.adventure.text.Component; import net.kyori.adventure.text.Component;
import org.apache.commons.lang3.text.WordUtils;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.World; import org.bukkit.World;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.Entity; import org.bukkit.entity.Entity;
import org.bukkit.entity.Mob; import org.bukkit.entity.EntityType;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
@CommandPermissions(level = Rank.ADMIN, permission = "plex.mobpurge", source = RequiredCommandSource.ANY) import java.util.ArrayList;
@CommandParameters(name = "mobpurge", description = "Purge all mobs.", usage = "/<command>", aliases = "mp") import java.util.Arrays;
import java.util.Collections;
import java.util.List;
@CommandPermissions(permission = "plex.mobpurge", source = RequiredCommandSource.ANY)
@CommandParameters(name = "mobpurge", description = "Purge all mobs.", usage = "/<command> [mob]", aliases = "mp")
public class MobPurgeCMD extends PlexCommand public class MobPurgeCMD extends PlexCommand
{ {
private final List<EntityType> MOB_TYPES = new ArrayList<>();
@Override @Override
protected Component execute(@NotNull CommandSender sender, @Nullable Player playerSender, @NotNull String[] args) protected Component execute(@NotNull CommandSender sender, @Nullable Player playerSender, @NotNull String[] args)
{ {
HashMap<String, Integer> entityCounts = new HashMap<>(); EntityType type = null;
String mobName = null;
for (World world : Bukkit.getWorlds()) if (args.length > 0)
{ {
for (Entity entity : world.getEntities()) try
{ {
if (entity instanceof Mob) type = EntityType.valueOf(args[0].toUpperCase());
}
catch (Exception e)
{ {
String type = entity.getType().name(); PlexLog.debug("A genius tried and failed removing the following invalid mob: " + args[0].toUpperCase());
entity.remove(); send(sender, messageComponent("notAValidMob"));
return null;
entityCounts.put(type, entityCounts.getOrDefault(type, 0) + 1);
} }
} if (!MOB_TYPES.contains(type))
} {
PlexLog.debug(Arrays.deepToString(MOB_TYPES.toArray()));
int entityCount = entityCounts.values().stream().mapToInt(a -> a).sum(); PlexLog.debug("A genius tried to remove a mob that doesn't exist: " + args[0].toUpperCase());
sender.sendMessage(messageComponent("notAValidMobButValidEntity"));
PlexUtils.broadcast(messageComponent("removedMobs", sender.getName(), entityCount));
/*entityCounts.forEach((entityName, numRemoved) -> {
sender.sendMessage(messageComponent("removedEntitiesOfType", sender.getName(), numRemoved, entityName));
});*/
return null; return null;
} }
} }
if (type != null)
{
mobName = WordUtils.capitalizeFully(type.name().replace("_", " "));
PlexLog.debug("The args aren't null so the mob is: " + mobName);
}
int count = purgeMobs(type);
if (type != null)
{
PlexUtils.broadcast(messageComponent("removedEntitiesOfTypes", sender.getName(), count, mobName));
PlexLog.debug("All " + count + " of " + mobName + " were removed");
}
else
{
PlexUtils.broadcast(messageComponent("removedMobs", sender.getName(), count));
PlexLog.debug("All " + count + " valid mobs were removed");
}
sender.sendMessage(messageComponent("amountOfMobsRemoved", count, (type != null ? mobName : "mob") + multipleS(count)));
return null;
}
private String multipleS(int count)
{
return (count == 1 ? "" : "s");
}
private int purgeMobs(EntityType type)
{
int removed = 0;
for (World world : Bukkit.getWorlds())
{
for (Entity entity : world.getLivingEntities())
{
if (entity instanceof LivingEntity && !(entity instanceof Player))
{
if (type != null && !entity.getType().equals(type))
{
continue;
}
entity.remove();
removed++;
}
}
}
return removed;
}
private List<String> getAllMobs()
{
List<String> mobs = new ArrayList<>();
Arrays.stream(EntityType.values()).filter(EntityType::isAlive).filter(EntityType::isSpawnable).forEach(MOB_TYPES::add);
for (EntityType entityType : MOB_TYPES)
{
mobs.add(entityType.name());
}
return mobs;
}
public @NotNull List<String> smartTabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) throws IllegalArgumentException
{
if (args.length == 1 && silentCheckPermission(sender, this.getPermission()))
{
return getAllMobs();
}
return Collections.emptyList();
}
}

View File

@ -7,20 +7,20 @@ import dev.plex.command.annotation.CommandPermissions;
import dev.plex.player.PlexPlayer; import dev.plex.player.PlexPlayer;
import dev.plex.punishment.Punishment; import dev.plex.punishment.Punishment;
import dev.plex.punishment.PunishmentType; import dev.plex.punishment.PunishmentType;
import dev.plex.rank.enums.Rank;
import dev.plex.util.PlexUtils; import dev.plex.util.PlexUtils;
import dev.plex.util.TimeUtils; import dev.plex.util.TimeUtils;
import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.util.List;
import net.kyori.adventure.text.Component; import net.kyori.adventure.text.Component;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.util.List;
@CommandParameters(name = "mute", description = "Mute a player on the server", usage = "/<command> <player>", aliases = "stfu") @CommandParameters(name = "mute", description = "Mute a player on the server", usage = "/<command> <player>", aliases = "stfu")
@CommandPermissions(level = Rank.ADMIN, permission = "plex.mute") @CommandPermissions(permission = "plex.mute")
public class MuteCMD extends PlexCommand public class MuteCMD extends PlexCommand
{ {
@Override @Override
@ -38,7 +38,7 @@ public class MuteCMD extends PlexCommand
return messageComponent("playerMuted"); return messageComponent("playerMuted");
} }
if (silentCheckRank(player, Rank.ADMIN, "plex.mute")) if (silentCheckPermission(player, "plex.mute"))
{ {
send(sender, messageComponent("higherRankThanYou")); send(sender, messageComponent("higherRankThanYou"));
return null; return null;
@ -47,11 +47,12 @@ public class MuteCMD extends PlexCommand
Punishment punishment = new Punishment(punishedPlayer.getUuid(), getUUID(sender)); Punishment punishment = new Punishment(punishedPlayer.getUuid(), getUUID(sender));
punishment.setCustomTime(false); punishment.setCustomTime(false);
ZonedDateTime date = ZonedDateTime.now(ZoneId.of(TimeUtils.TIMEZONE)); ZonedDateTime date = ZonedDateTime.now(ZoneId.of(TimeUtils.TIMEZONE));
punishment.setEndDate(date.plusMinutes(5)); punishment.setEndDate(date.plusSeconds(plugin.config.getInt("punishments.mute-timer", 300)));
punishment.setType(PunishmentType.MUTE); punishment.setType(PunishmentType.MUTE);
punishment.setPunishedUsername(player.getName()); punishment.setPunishedUsername(player.getName());
punishment.setIp(player.getAddress().getAddress().getHostAddress().trim()); punishment.setIp(player.getAddress().getAddress().getHostAddress().trim());
punishment.setReason(""); punishment.setReason("");
punishment.setActive(true);
plugin.getPunishmentManager().punish(punishedPlayer, punishment); plugin.getPunishmentManager().punish(punishedPlayer, punishment);
PlexUtils.broadcast(messageComponent("mutedPlayer", sender.getName(), player.getName())); PlexUtils.broadcast(messageComponent("mutedPlayer", sender.getName(), player.getName()));
@ -59,8 +60,8 @@ public class MuteCMD extends PlexCommand
} }
@Override @Override
public @NotNull List<String> tabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) throws IllegalArgumentException public @NotNull List<String> smartTabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) throws IllegalArgumentException
{ {
return args.length == 1 && checkTab(sender, Rank.ADMIN, "plex.mute") ? PlexUtils.getPlayerNameList() : ImmutableList.of(); return args.length == 1 && silentCheckPermission(sender, this.getPermission()) ? PlexUtils.getPlayerNameList() : ImmutableList.of();
} }
} }

View File

@ -1,71 +0,0 @@
package dev.plex.command.impl;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Lists;
import dev.plex.command.PlexCommand;
import dev.plex.command.annotation.CommandParameters;
import dev.plex.command.annotation.CommandPermissions;
import dev.plex.rank.enums.Rank;
import dev.plex.util.AshconInfo;
import dev.plex.util.MojangUtils;
import dev.plex.util.PlexLog;
import dev.plex.util.PlexUtils;
import dev.plex.util.TimeUtils;
import java.util.Arrays;
import java.util.List;
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;
import org.jetbrains.annotations.Nullable;
@CommandParameters(name = "namehistory", description = "Get the name history of a player", usage = "/<command> <player>", aliases = "nh")
@CommandPermissions(level = Rank.OP, permission = "plex.namehistory")
public class NameHistoryCMD extends PlexCommand
{
@Override
protected Component execute(@NotNull CommandSender sender, @Nullable Player playerSender, String[] args)
{
if (args.length != 1)
{
return usage();
}
String username = args[0];
AshconInfo info = MojangUtils.getInfo(username);
if (info == null)
{
return messageComponent("nameHistoryDoesntExist");
}
PlexLog.debug("NameHistory UUID: " + info.getUuid());
PlexLog.debug("NameHistory Size: " + info.getUsernameHistories().length);
List<Component> historyList = Lists.newArrayList();
Arrays.stream(info.getUsernameHistories()).forEach(history ->
{
if (history.getZonedDateTime() != null)
{
historyList.add(
messageComponent("nameHistoryBody",
history.getUsername(),
TimeUtils.useTimezone(history.getZonedDateTime())));
}
else
{
historyList.add(
Component.text(history.getUsername()).color(NamedTextColor.GOLD)
.append(Component.space()));
}
});
send(sender, messageComponent("nameHistoryTitle", username));
send(sender, messageComponent("nameHistorySeparator"));
historyList.forEach(component -> send(sender, component));
return null;
}
@Override
public @NotNull List<String> tabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) throws IllegalArgumentException
{
return args.length == 1 ? PlexUtils.getPlayerNameList() : ImmutableList.of();
}
}

View File

@ -6,16 +6,8 @@ import dev.plex.command.annotation.CommandParameters;
import dev.plex.command.annotation.CommandPermissions; import dev.plex.command.annotation.CommandPermissions;
import dev.plex.player.PlexPlayer; import dev.plex.player.PlexPlayer;
import dev.plex.punishment.extra.Note; 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.PlexUtils;
import dev.plex.util.TimeUtils; import dev.plex.util.TimeUtils;
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.Component;
import net.kyori.adventure.text.format.NamedTextColor; import net.kyori.adventure.text.format.NamedTextColor;
import org.apache.commons.lang3.ArrayUtils; import org.apache.commons.lang3.ArrayUtils;
@ -25,8 +17,15 @@ import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
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;
@CommandParameters(name = "notes", description = "Manage notes for a player", usage = "/<command> <player> <list | add <note> | remove <id> | clear>") @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") @CommandPermissions(permission = "plex.notes")
public class NotesCMD extends PlexCommand public class NotesCMD extends PlexCommand
{ {
@Override @Override
@ -47,8 +46,6 @@ public class NotesCMD extends PlexCommand
switch (args[1].toLowerCase()) switch (args[1].toLowerCase())
{ {
case "list": case "list":
{
if (plugin.getStorageType() != StorageType.MONGODB)
{ {
plugin.getSqlNotes().getNotes(plexPlayer.getUuid()).whenComplete((notes, ex) -> plugin.getSqlNotes().getNotes(plexPlayer.getUuid()).whenComplete((notes, ex) ->
{ {
@ -59,16 +56,6 @@ public class NotesCMD extends PlexCommand
} }
readNotes(sender, plexPlayer, notes); readNotes(sender, plexPlayer, notes);
}); });
}
else
{
List<Note> notes = plexPlayer.getNotes();
if (notes.size() == 0)
{
return messageComponent("noNotes");
}
readNotes(sender, plexPlayer, notes);
}
return null; return null;
} }
case "add": case "add":
@ -82,14 +69,7 @@ public class NotesCMD extends PlexCommand
{ {
Note note = new Note(plexPlayer.getUuid(), content, playerSender.getUniqueId(), ZonedDateTime.now(ZoneId.of(TimeUtils.TIMEZONE))); Note note = new Note(plexPlayer.getUuid(), content, playerSender.getUniqueId(), ZonedDateTime.now(ZoneId.of(TimeUtils.TIMEZONE)));
plexPlayer.getNotes().add(note); plexPlayer.getNotes().add(note);
if (plugin.getStorageType() != StorageType.MONGODB)
{
plugin.getSqlNotes().addNote(note); plugin.getSqlNotes().addNote(note);
}
else
{
DataUtils.update(plexPlayer);
}
return messageComponent("noteAdded"); return messageComponent("noteAdded");
} }
} }
@ -108,8 +88,6 @@ public class NotesCMD extends PlexCommand
{ {
return messageComponent("unableToParseNumber", args[2]); return messageComponent("unableToParseNumber", args[2]);
} }
if (plugin.getStorageType() != StorageType.MONGODB)
{
plugin.getSqlNotes().getNotes(plexPlayer.getUuid()).whenComplete((notes, ex) -> plugin.getSqlNotes().getNotes(plexPlayer.getUuid()).whenComplete((notes, ex) ->
{ {
boolean deleted = false; boolean deleted = false;
@ -128,40 +106,15 @@ public class NotesCMD extends PlexCommand
} }
plexPlayer.getNotes().removeIf(note -> note.getId() == id); plexPlayer.getNotes().removeIf(note -> note.getId() == id);
}); });
}
else
{
if (plexPlayer.getNotes().removeIf(note -> note.getId() == id))
{
return messageComponent("removedNote", id);
}
return messageComponent("noteNotFound");
}
return null; return null;
} }
case "clear": case "clear":
{
if (plugin.getStorageType() != StorageType.MONGODB)
{
plugin.getSqlNotes().getNotes(plexPlayer.getUuid()).whenComplete((notes, ex) ->
{
for (Note note : notes)
{
plugin.getSqlNotes().deleteNote(note.getId(), plexPlayer.getUuid());
}
plexPlayer.getNotes().clear();
send(sender, messageComponent("clearedNotes", notes.size()));
});
}
else
{ {
int count = plexPlayer.getNotes().size(); int count = plexPlayer.getNotes().size();
plexPlayer.getNotes().clear(); plexPlayer.getNotes().clear();
DataUtils.update(plexPlayer); DataUtils.update(plexPlayer);
return messageComponent("clearedNotes", count); return messageComponent("clearedNotes", count);
} }
return null;
}
default: default:
{ {
return usage(); return usage();
@ -171,11 +124,11 @@ public class NotesCMD extends PlexCommand
private void readNotes(@NotNull CommandSender sender, PlexPlayer plexPlayer, List<Note> notes) private void readNotes(@NotNull CommandSender sender, PlexPlayer plexPlayer, List<Note> notes)
{ {
AtomicReference<Component> noteList = new AtomicReference<>(Component.text("Player notes for: " + plexPlayer.getName()).color(NamedTextColor.GREEN)); AtomicReference<Component> noteList = new AtomicReference<>(messageComponent("notesHeader", plexPlayer.getName()));
for (Note note : notes) for (Note note : notes)
{ {
Component noteLine = mmString("<gold><!italic>" + note.getId() + " - Written by: " + DataUtils.getPlayer(note.getWrittenBy()).getName() + " on " + TimeUtils.useTimezone(note.getTimestamp())); Component noteLine = messageComponent("notePrefix", note.getId(), DataUtils.getPlayer(note.getWrittenBy()).getName(), TimeUtils.useTimezone(note.getTimestamp()));
noteLine = noteLine.append(mmString("<newline><yellow># " + note.getNote())); noteLine = noteLine.append(messageComponent("noteLine", note.getNote()));
noteList.set(noteList.get().append(Component.newline())); noteList.set(noteList.get().append(Component.newline()));
noteList.set(noteList.get().append(noteLine)); noteList.set(noteList.get().append(noteLine));
} }
@ -183,7 +136,9 @@ public class NotesCMD extends PlexCommand
} }
@Override @Override
public @NotNull List<String> tabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) throws IllegalArgumentException public @NotNull List<String> smartTabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) throws IllegalArgumentException
{
if (silentCheckPermission(sender, this.getPermission()))
{ {
if (args.length == 1) if (args.length == 1)
{ {
@ -195,4 +150,6 @@ public class NotesCMD extends PlexCommand
} }
return Collections.emptyList(); return Collections.emptyList();
} }
return Collections.emptyList();
}
} }

View File

@ -1,31 +0,0 @@
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.annotation.System;
import dev.plex.rank.enums.Rank;
import dev.plex.util.PlexUtils;
import net.kyori.adventure.text.Component;
import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@CommandParameters(name = "opall", description = "Op everyone on the server", aliases = "opa")
@CommandPermissions(level = Rank.ADMIN)
@System(value = "ranks")
public class OpAllCMD extends PlexCommand
{
@Override
protected Component execute(@NotNull CommandSender sender, @Nullable Player playerSender, String[] args)
{
for (Player player : Bukkit.getOnlinePlayers())
{
player.setOp(true);
}
PlexUtils.broadcast(messageComponent("oppedAllPlayers", sender.getName()));
return null;
}
}

View File

@ -1,40 +0,0 @@
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;
import dev.plex.command.annotation.System;
import dev.plex.rank.enums.Rank;
import dev.plex.util.PlexUtils;
import java.util.List;
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;
@CommandParameters(name = "op", description = "Op a player on the server", usage = "/<command> <player>")
@CommandPermissions(level = Rank.OP)
@System(value = "ranks")
public class OpCMD extends PlexCommand
{
@Override
protected Component execute(@NotNull CommandSender sender, @Nullable Player playerSender, String[] args)
{
if (args.length != 1)
{
return usage();
}
Player player = getNonNullPlayer(args[0]);
player.setOp(true);
PlexUtils.broadcast(messageComponent("oppedPlayer", sender.getName(), player.getName()));
return null;
}
@Override
public @NotNull List<String> tabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) throws IllegalArgumentException
{
return args.length == 1 ? PlexUtils.getPlayerNameList() : ImmutableList.of();
}
}

View File

@ -7,14 +7,9 @@ import dev.plex.command.exception.CommandFailException;
import dev.plex.command.source.RequiredCommandSource; import dev.plex.command.source.RequiredCommandSource;
import dev.plex.module.PlexModule; import dev.plex.module.PlexModule;
import dev.plex.module.PlexModuleFile; import dev.plex.module.PlexModuleFile;
import dev.plex.rank.enums.Rank;
import dev.plex.util.BuildInfo; import dev.plex.util.BuildInfo;
import dev.plex.util.PlexUtils; import dev.plex.util.PlexUtils;
import dev.plex.util.TimeUtils; import dev.plex.util.TimeUtils;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;
import net.kyori.adventure.text.Component; import net.kyori.adventure.text.Component;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
@ -24,7 +19,12 @@ import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
@CommandPermissions(level = Rank.IMPOSTOR, source = RequiredCommandSource.ANY) import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;
@CommandPermissions(source = RequiredCommandSource.ANY)
@CommandParameters(name = "plex", usage = "/<command> [reload | redis | modules [reload]]", description = "Show information about Plex or reload it") @CommandParameters(name = "plex", usage = "/<command> [reload | redis | modules [reload]]", description = "Show information about Plex or reload it")
public class PlexCMD extends PlexCommand public class PlexCMD extends PlexCommand
{ {
@ -35,7 +35,7 @@ public class PlexCMD extends PlexCommand
if (args.length == 0) if (args.length == 0)
{ {
send(sender, mmString("<light_purple>Plex - A new freedom plugin.")); send(sender, mmString("<light_purple>Plex - A new freedom plugin."));
send(sender, mmString("<light_purple>Plugin version: <gold>" + plugin.getDescription().getVersion() + " #" + BuildInfo.getNumber() + " <light_purple>Git: <gold>" + BuildInfo.getHead())); send(sender, mmString("<light_purple>Plugin version: <gold>" + plugin.getDescription().getVersion() + " #" + BuildInfo.getNumber() + " <light_purple>Git: <gold>" + BuildInfo.getCommit()));
send(sender, mmString("<light_purple>Authors: <gold>Telesphoreo, Taahh")); send(sender, mmString("<light_purple>Authors: <gold>Telesphoreo, Taahh"));
send(sender, mmString("<light_purple>Built by: <gold>" + BuildInfo.getAuthor() + " <light_purple>on <gold>" + BuildInfo.getDate())); 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.")); send(sender, mmString("<light_purple>Run <gold>/plex modules <light_purple>to see a list of modules."));
@ -44,7 +44,7 @@ public class PlexCMD extends PlexCommand
} }
if (args[0].equalsIgnoreCase("reload")) if (args[0].equalsIgnoreCase("reload"))
{ {
checkRank(sender, Rank.SENIOR_ADMIN, "plex.reload"); checkPermission(sender, "plex.reload");
plugin.config.load(); plugin.config.load();
send(sender, "Reloaded config file"); send(sender, "Reloaded config file");
plugin.messages.load(); plugin.messages.load();
@ -54,10 +54,7 @@ public class PlexCMD extends PlexCommand
send(sender, "Reloaded indefinite bans"); send(sender, "Reloaded indefinite bans");
plugin.commands.load(); plugin.commands.load();
send(sender, "Reloaded blocked commands file"); send(sender, "Reloaded blocked commands file");
plugin.getRankManager().importDefaultRanks(); if (!plugin.getServer().getPluginManager().isPluginEnabled("Vault"))
send(sender, "Imported ranks");
plugin.setSystem(plugin.config.getString("system"));
if (plugin.getSystem().equalsIgnoreCase("permissions") && !plugin.getServer().getPluginManager().isPluginEnabled("Vault"))
{ {
throw new RuntimeException("Vault is required to run on the server if you use permissions!"); throw new RuntimeException("Vault is required to run on the server if you use permissions!");
} }
@ -71,7 +68,7 @@ public class PlexCMD extends PlexCommand
} }
else if (args[0].equalsIgnoreCase("redis")) else if (args[0].equalsIgnoreCase("redis"))
{ {
checkRank(sender, Rank.SENIOR_ADMIN, "plex.redis"); checkPermission(sender, "plex.redis");
if (!plugin.getRedisConnection().isEnabled()) if (!plugin.getRedisConnection().isEnabled())
{ {
throw new CommandFailException("&cRedis is not enabled."); throw new CommandFailException("&cRedis is not enabled.");
@ -90,7 +87,7 @@ public class PlexCMD extends PlexCommand
} }
if (args[1].equalsIgnoreCase("reload")) if (args[1].equalsIgnoreCase("reload"))
{ {
checkRank(sender, Rank.EXECUTIVE, "plex.modules.reload"); checkPermission(sender, "plex.modules.reload");
plugin.getModuleManager().reloadModules(); plugin.getModuleManager().reloadModules();
return mmString("<green>All modules reloaded!"); return mmString("<green>All modules reloaded!");
} }
@ -98,7 +95,7 @@ public class PlexCMD extends PlexCommand
{ {
if (!hasUpdateAccess(playerSender, sender)) if (!hasUpdateAccess(playerSender, sender))
{ {
return messageComponent("noPermissionRank", "an Owner or Developer"); return messageComponent("noPermissionRank", "a Developer");
} }
for (PlexModule module : plugin.getModuleManager().getModules()) for (PlexModule module : plugin.getModuleManager().getModules())
{ {
@ -112,7 +109,7 @@ public class PlexCMD extends PlexCommand
{ {
if (!hasUpdateAccess(playerSender, sender)) if (!hasUpdateAccess(playerSender, sender))
{ {
return messageComponent("noPermissionRank", "an Owner or Developer"); return messageComponent("noPermissionRank", "a Developer");
} }
if (!plugin.getUpdateChecker().getUpdateStatusMessage(sender, false, 0)) if (!plugin.getUpdateChecker().getUpdateStatusMessage(sender, false, 0))
{ {
@ -129,7 +126,7 @@ public class PlexCMD extends PlexCommand
} }
@Override @Override
public @NotNull List<String> tabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) throws IllegalArgumentException public @NotNull List<String> smartTabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) throws IllegalArgumentException
{ {
if (args.length == 1) if (args.length == 1)
{ {
@ -155,13 +152,11 @@ public class PlexCMD extends PlexCommand
OfflinePlayer offlinePlayer = Bukkit.getOfflinePlayer(sender.getName()); OfflinePlayer offlinePlayer = Bukkit.getOfflinePlayer(sender.getName());
if (offlinePlayer.hasPlayedBefore()) if (offlinePlayer.hasPlayedBefore())
{ {
return PlexUtils.DEVELOPERS.contains(offlinePlayer.getUniqueId().toString()) return PlexUtils.DEVELOPERS.contains(offlinePlayer.getUniqueId().toString());
|| plugin.config.getStringList("titles.owners").contains(sender.getName());
} }
return false; return false;
} }
assert player != null; assert player != null;
return PlexUtils.DEVELOPERS.contains(player.getUniqueId().toString()) return PlexUtils.DEVELOPERS.contains(player.getUniqueId().toString());
|| plugin.config.getStringList("titles.owners").contains(player.getName());
} }
} }

View File

@ -1,34 +1,56 @@
package dev.plex.command.impl; package dev.plex.command.impl;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
import dev.plex.cache.DataUtils;
import dev.plex.command.PlexCommand; import dev.plex.command.PlexCommand;
import dev.plex.command.annotation.CommandParameters; import dev.plex.command.annotation.CommandParameters;
import dev.plex.command.annotation.CommandPermissions; import dev.plex.command.annotation.CommandPermissions;
import dev.plex.command.exception.PlayerNotFoundException;
import dev.plex.command.source.RequiredCommandSource; import dev.plex.command.source.RequiredCommandSource;
import dev.plex.menu.PunishmentMenu; import dev.plex.menu.impl.PunishedPlayerMenu;
import dev.plex.rank.enums.Rank; import dev.plex.menu.impl.PunishmentMenu;
import dev.plex.player.PlexPlayer;
import dev.plex.util.PlexUtils; import dev.plex.util.PlexUtils;
import java.util.List;
import net.kyori.adventure.text.Component; import net.kyori.adventure.text.Component;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
import java.util.List;
@CommandParameters(name = "punishments", usage = "/<command> [player]", description = "Opens the Punishments GUI", aliases = "punishlist,punishes") @CommandParameters(name = "punishments", usage = "/<command> [player]", description = "Opens the Punishments GUI", aliases = "punishlist,punishes")
@CommandPermissions(level = Rank.ADMIN, permission = "plex.punishments", source = RequiredCommandSource.IN_GAME) @CommandPermissions(permission = "plex.punishments", source = RequiredCommandSource.IN_GAME)
public class PunishmentsCMD extends PlexCommand public class PunishmentsCMD extends PlexCommand
{ {
@Override @Override
protected Component execute(@NotNull CommandSender sender, @Nullable Player playerSender, String[] args) protected Component execute(@NotNull CommandSender sender, @Nullable Player playerSender, String[] args)
{ {
new PunishmentMenu().openInv(playerSender, 0); if (args.length == 0)
{
new PunishmentMenu().open(playerSender);
}
else
{
if (!DataUtils.hasPlayedBefore(args[0]))
{
throw new PlayerNotFoundException();
}
final OfflinePlayer offlinePlayer = Bukkit.getOfflinePlayer(args[0]);
final PlexPlayer player = offlinePlayer.isOnline() ? getOnlinePlexPlayer(args[0]) : getOfflinePlexPlayer(offlinePlayer.getUniqueId());
new PunishedPlayerMenu(player).open(playerSender);
}
return null; return null;
} }
@Override @Override
public @NotNull List<String> tabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) throws IllegalArgumentException public @NotNull List<String> smartTabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) throws IllegalArgumentException
{ {
return args.length == 1 ? PlexUtils.getPlayerNameList() : ImmutableList.of(); return args.length == 1 && silentCheckPermission(sender, this.getPermission()) ? PlexUtils.getPlayerNameList() : ImmutableList.of();
} }
} }

View File

@ -1,57 +0,0 @@
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.annotation.System;
import dev.plex.command.exception.CommandFailException;
import dev.plex.command.source.RequiredCommandSource;
import dev.plex.rank.enums.Rank;
import dev.plex.util.PlexUtils;
import java.util.Collections;
import java.util.List;
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;
@CommandPermissions(level = Rank.OP, permission = "plex.rank", source = RequiredCommandSource.ANY)
@CommandParameters(name = "rank", description = "Displays your rank")
@System(value = "ranks")
public class RankCMD extends PlexCommand
{
@Override
protected Component execute(@NotNull CommandSender sender, @Nullable Player playerSender, String[] args)
{
if (args.length == 0)
{
if (isConsole(sender))
{
throw new CommandFailException("<red>When using the console, you must specify a player's rank.");
}
if (!(playerSender == null))
{
Rank rank = getPlexPlayer(playerSender).getRankFromString();
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.isAtLeast(Rank.ADMIN) && !getPlexPlayer(player).isAdminActive() ? (player.isOp() ? Rank.OP.getReadable() : Rank.NONOP.getReadable()) : rank.getReadable());
}
return null;
}
@Override
public @NotNull List<String> tabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) throws IllegalArgumentException
{
if (args.length == 1)
{
return PlexUtils.getPlayerNameList();
}
return Collections.emptyList();
}
}

View File

@ -4,7 +4,7 @@ import dev.plex.command.PlexCommand;
import dev.plex.command.annotation.CommandParameters; import dev.plex.command.annotation.CommandParameters;
import dev.plex.command.annotation.CommandPermissions; import dev.plex.command.annotation.CommandPermissions;
import dev.plex.command.source.RequiredCommandSource; import dev.plex.command.source.RequiredCommandSource;
import dev.plex.rank.enums.Rank;
import dev.plex.util.PlexUtils; import dev.plex.util.PlexUtils;
import net.kyori.adventure.text.Component; import net.kyori.adventure.text.Component;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
@ -13,7 +13,10 @@ import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
@CommandPermissions(level = Rank.SENIOR_ADMIN, permission = "plex.rawsay", source = RequiredCommandSource.ANY) import java.util.Collections;
import java.util.List;
@CommandPermissions(permission = "plex.rawsay", source = RequiredCommandSource.ANY)
@CommandParameters(name = "rawsay", usage = "/<command> <message>", description = "Displays a raw message to everyone") @CommandParameters(name = "rawsay", usage = "/<command> <message>", description = "Displays a raw message to everyone")
public class RawSayCMD extends PlexCommand public class RawSayCMD extends PlexCommand
{ {
@ -28,4 +31,10 @@ public class RawSayCMD extends PlexCommand
PlexUtils.broadcast(StringUtils.join(args, " ")); PlexUtils.broadcast(StringUtils.join(args, " "));
return null; return null;
} }
@Override
public @NotNull List<String> smartTabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) throws IllegalArgumentException
{
return Collections.emptyList();
}
} }

View File

@ -0,0 +1,71 @@
package dev.plex.command.impl;
import com.google.common.collect.ImmutableList;
import dev.plex.cache.DataUtils;
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.player.PlexPlayer;
import dev.plex.util.PlexUtils;
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.util.List;
@CommandPermissions(permission = "plex.removeloginmessage", source = RequiredCommandSource.ANY)
@CommandParameters(name = "removeloginmessage", usage = "/<command> [-o <player>]", description = "Remove your own (or someone else's) login message", aliases = "rlm,removeloginmsg")
public class RemoveLoginMessageCMD extends PlexCommand
{
@Override
protected Component execute(@NotNull CommandSender sender, @Nullable Player playerSender, String[] args)
{
if (args.length == 0 && !isConsole(sender))
{
if (playerSender != null)
{
PlexPlayer plexPlayer = plugin.getPlayerCache().getPlexPlayer(playerSender.getUniqueId());
plexPlayer.setLoginMessage("");
return messageComponent("removedOwnLoginMessage");
}
}
else if (args[0].equalsIgnoreCase("-o"))
{
checkPermission(sender, "plex.removeloginmessage.others");
if (args.length < 2)
{
return messageComponent("specifyPlayer");
}
PlexPlayer plexPlayer = DataUtils.getPlayer(args[1]);
if (plexPlayer == null)
{
return messageComponent("playerNotFound");
}
plexPlayer.setLoginMessage("");
return messageComponent("removedOtherLoginMessage", plexPlayer.getName());
}
else
{
return messageComponent("noPermissionConsole");
}
return null;
}
@Override
public @NotNull List<String> smartTabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) throws IllegalArgumentException
{
if (args.length == 1)
{
if (silentCheckPermission(sender, "plex.removeloginmessage.others"))
{
return List.of("-o");
}
}
return args.length == 2 && silentCheckPermission(sender, "plex.removeloginmessage.others") ? PlexUtils.getPlayerNameList() : ImmutableList.of();
}
}

View File

@ -4,7 +4,6 @@ import dev.plex.command.PlexCommand;
import dev.plex.command.annotation.CommandParameters; import dev.plex.command.annotation.CommandParameters;
import dev.plex.command.annotation.CommandPermissions; import dev.plex.command.annotation.CommandPermissions;
import dev.plex.command.source.RequiredCommandSource; import dev.plex.command.source.RequiredCommandSource;
import dev.plex.rank.enums.Rank;
import dev.plex.util.PlexUtils; import dev.plex.util.PlexUtils;
import net.kyori.adventure.text.Component; import net.kyori.adventure.text.Component;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
@ -13,7 +12,10 @@ import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
@CommandPermissions(level = Rank.ADMIN, permission = "plex.say", source = RequiredCommandSource.ANY) import java.util.Collections;
import java.util.List;
@CommandPermissions(permission = "plex.say", source = RequiredCommandSource.ANY)
@CommandParameters(name = "say", usage = "/<command> <message>", description = "Displays a message to everyone") @CommandParameters(name = "say", usage = "/<command> <message>", description = "Displays a message to everyone")
public class SayCMD extends PlexCommand public class SayCMD extends PlexCommand
{ {
@ -28,4 +30,10 @@ public class SayCMD extends PlexCommand
PlexUtils.broadcast(PlexUtils.messageComponent("sayMessage", sender.getName(), PlexUtils.mmStripColor(StringUtils.join(args, " ")))); PlexUtils.broadcast(PlexUtils.messageComponent("sayMessage", sender.getName(), PlexUtils.mmStripColor(StringUtils.join(args, " "))));
return null; return null;
} }
@Override
public @NotNull List<String> smartTabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) throws IllegalArgumentException
{
return Collections.emptyList();
}
} }

View File

@ -0,0 +1,97 @@
package dev.plex.command.impl;
import com.google.common.collect.ImmutableList;
import dev.plex.cache.DataUtils;
import dev.plex.command.PlexCommand;
import dev.plex.command.annotation.CommandParameters;
import dev.plex.command.annotation.CommandPermissions;
import dev.plex.command.exception.CommandFailException;
import dev.plex.command.source.RequiredCommandSource;
import dev.plex.player.PlexPlayer;
import dev.plex.util.PlexLog;
import dev.plex.util.PlexUtils;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.minimessage.MiniMessage;
import org.apache.commons.lang3.StringUtils;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.List;
@CommandPermissions(permission = "plex.setloginmessage", source = RequiredCommandSource.ANY)
@CommandParameters(name = "setloginmessage", usage = "/<command> [-o <player>] <message>", description = "Sets your (or someone else's) login message", aliases = "slm,setloginmsg")
public class SetLoginMessageCMD extends PlexCommand
{
private final boolean nameRequired = plugin.getConfig().getBoolean("loginmessages.name");
@Override
protected Component execute(@NotNull CommandSender sender, @Nullable Player playerSender, String[] args)
{
if (args.length == 0)
{
return usage();
}
if (playerSender != null)
{
if (args[0].equals("-o"))
{
checkPermission(sender, "plex.setloginmessage.others");
if (args.length < 2)
{
return messageComponent("specifyPlayer");
}
if (args.length < 3)
{
return messageComponent("specifyLoginMessage");
}
PlexPlayer plexPlayer = DataUtils.getPlayer(args[1]);
if (plexPlayer == null)
{
return messageComponent("playerNotFound");
}
String message = StringUtils.join(args, " ", 2, args.length);
message = message.replace(plexPlayer.getName(), "%player%");
validateMessage(message);
plexPlayer.setLoginMessage(message);
return messageComponent("setOtherPlayersLoginMessage", plexPlayer.getName(),
MiniMessage.miniMessage().serialize(PlexUtils.stringToComponent(message.replace("%player%", plexPlayer.getName()))));
}
if (isConsole(sender))
{
return messageComponent("noPermissionConsole");
}
PlexPlayer plexPlayer = plugin.getPlayerCache().getPlexPlayer(playerSender.getUniqueId());
String message = StringUtils.join(args, " ", 0, args.length)
.replace(plexPlayer.getName(), "%player%");
validateMessage(message);
plexPlayer.setLoginMessage(message);
return messageComponent("setOwnLoginMessage", PlexUtils.stringToComponent(message.replace("%player%", plexPlayer.getName())));
}
return null;
}
private void validateMessage(String message)
{
if (nameRequired && !message.contains("%player%"))
{
PlexLog.debug("Validating login message has a valid name in it");
throw new CommandFailException(messageString("nameRequired"));
}
}
@Override
public @NotNull List<String> smartTabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) throws IllegalArgumentException
{
if (args.length == 1)
{
if (silentCheckPermission(sender, "plex.setloginmessage"))
{
return List.of("-o");
}
}
return args.length == 2 && args[0].equalsIgnoreCase("-o") && silentCheckPermission(sender, "plex.setloginmessage") ? PlexUtils.getPlayerNameList() : ImmutableList.of();
}
}

View File

@ -7,13 +7,8 @@ import dev.plex.command.source.RequiredCommandSource;
import dev.plex.player.PlexPlayer; import dev.plex.player.PlexPlayer;
import dev.plex.punishment.Punishment; import dev.plex.punishment.Punishment;
import dev.plex.punishment.PunishmentType; import dev.plex.punishment.PunishmentType;
import dev.plex.rank.enums.Rank;
import dev.plex.util.PlexUtils; import dev.plex.util.PlexUtils;
import dev.plex.util.TimeUtils; import dev.plex.util.TimeUtils;
import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.util.Collections;
import java.util.List;
import net.kyori.adventure.text.Component; import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.NamedTextColor; import net.kyori.adventure.text.format.NamedTextColor;
import net.kyori.adventure.title.Title; import net.kyori.adventure.title.Title;
@ -27,7 +22,12 @@ import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
@CommandPermissions(level = Rank.ADMIN, permission = "plex.smite", source = RequiredCommandSource.ANY) import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.util.Collections;
import java.util.List;
@CommandPermissions(permission = "plex.smite", source = RequiredCommandSource.ANY)
@CommandParameters(name = "smite", usage = "/<command> <player> [reason] [-ci | -q]", description = "Someone being a little bitch? Smite them down...") @CommandParameters(name = "smite", usage = "/<command> <player> [reason] [-ci | -q]", description = "Someone being a little bitch? Smite them down...")
public class SmiteCMD extends PlexCommand public class SmiteCMD extends PlexCommand
{ {
@ -78,27 +78,16 @@ public class SmiteCMD extends PlexCommand
final Player player = getNonNullPlayer(args[0]); final Player player = getNonNullPlayer(args[0]);
final PlexPlayer plexPlayer = getPlexPlayer(player); final PlexPlayer plexPlayer = getPlexPlayer(player);
Title title = Title.title(Component.text("You've been smitten.").color(NamedTextColor.RED), Component.text("Be sure to follow the rules!").color(NamedTextColor.YELLOW)); Title title = Title.title(messageComponent("smiteTitleHeader"), messageComponent("smiteTitleMessage", reason, sender.getName()));
player.showTitle(title); player.showTitle(title);
if (!silent) if (!silent)
{ {
PlexUtils.broadcast(mmString("<red>" + player.getName() + " has been a naughty, naughty boy.")); PlexUtils.broadcast(messageComponent("smiteBroadcast", player.getName(), reason != null ? reason : messageString("noReasonProvided"), sender.getName()));
if (reason != null)
{
PlexUtils.broadcast(mmString(" <red>Reason: " + "<yellow>" + reason));
}
PlexUtils.broadcast(mmString(" <red>Smitten by: " + "<yellow>" + sender.getName()));
} }
else else
{ {
send(sender, "Smitten " + player.getName() + " quietly."); send(sender, messageComponent("smittenQuietly", player.getName()));
}
// Deop
if (plugin.getSystem().equalsIgnoreCase("ranks"))
{
player.setOp(false);
} }
// Set gamemode to survival // Set gamemode to survival
@ -135,15 +124,15 @@ public class SmiteCMD extends PlexCommand
if (reason != null) if (reason != null)
{ {
punishment.setReason(reason); punishment.setReason(reason);
send(player, mmString("<red>You've been smitten. Reason: <yellow>" + reason));
} }
send(player, messageComponent("smitten", reason != null ? reason : messageString("noReasonProvided")));
return null; return null;
} }
@Override @Override
public @NotNull List<String> tabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) throws IllegalArgumentException public @NotNull List<String> smartTabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) throws IllegalArgumentException
{ {
if (checkTab(sender, Rank.ADMIN, "plex.smite") && args.length == 1) if (silentCheckPermission(sender, this.getPermission()) && args.length == 1)
{ {
return PlexUtils.getPlayerNameList(); return PlexUtils.getPlayerNameList();
} }

View File

@ -7,9 +7,8 @@ import dev.plex.command.annotation.CommandPermissions;
import dev.plex.command.exception.CommandFailException; import dev.plex.command.exception.CommandFailException;
import dev.plex.command.source.RequiredCommandSource; import dev.plex.command.source.RequiredCommandSource;
import dev.plex.event.GameModeUpdateEvent; import dev.plex.event.GameModeUpdateEvent;
import dev.plex.rank.enums.Rank;
import dev.plex.util.PlexUtils; import dev.plex.util.PlexUtils;
import java.util.List;
import net.kyori.adventure.text.Component; import net.kyori.adventure.text.Component;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.GameMode; import org.bukkit.GameMode;
@ -18,7 +17,9 @@ import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
@CommandPermissions(level = Rank.ADMIN, permission = "plex.gamemode.spectator", source = RequiredCommandSource.ANY) import java.util.List;
@CommandPermissions(permission = "plex.gamemode.spectator", source = RequiredCommandSource.ANY)
@CommandParameters(name = "spectator", aliases = "gmsp,egmsp,spec", description = "Set your own or another player's gamemode to spectator mode") @CommandParameters(name = "spectator", aliases = "gmsp,egmsp,spec", description = "Set your own or another player's gamemode to spectator mode")
public class SpectatorCMD extends PlexCommand public class SpectatorCMD extends PlexCommand
{ {
@ -29,13 +30,13 @@ public class SpectatorCMD extends PlexCommand
{ {
if (isConsole(sender)) if (isConsole(sender))
{ {
throw new CommandFailException(PlexUtils.messageString("consoleMustDefinePlayer")); throw new CommandFailException(messageString("consoleMustDefinePlayer"));
} }
Bukkit.getServer().getPluginManager().callEvent(new GameModeUpdateEvent(sender, playerSender, GameMode.SPECTATOR)); Bukkit.getServer().getPluginManager().callEvent(new GameModeUpdateEvent(sender, playerSender, GameMode.SPECTATOR));
return null; return null;
} }
if (checkRank(sender, Rank.ADMIN, "plex.gamemode.spectator.others")) if (checkPermission(sender,"plex.gamemode.spectator.others"))
{ {
if (args[0].equals("-a")) if (args[0].equals("-a"))
{ {
@ -55,9 +56,9 @@ public class SpectatorCMD extends PlexCommand
} }
@Override @Override
public @NotNull List<String> tabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) throws IllegalArgumentException public @NotNull List<String> smartTabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) throws IllegalArgumentException
{ {
if (checkTab(sender, Rank.ADMIN, "plex.gamemode.spectator.others")) if (silentCheckPermission(sender,"plex.gamemode.spectator.others"))
{ {
return PlexUtils.getPlayerNameList(); return PlexUtils.getPlayerNameList();
} }

View File

@ -7,9 +7,8 @@ import dev.plex.command.annotation.CommandPermissions;
import dev.plex.command.exception.CommandFailException; import dev.plex.command.exception.CommandFailException;
import dev.plex.command.source.RequiredCommandSource; import dev.plex.command.source.RequiredCommandSource;
import dev.plex.event.GameModeUpdateEvent; import dev.plex.event.GameModeUpdateEvent;
import dev.plex.rank.enums.Rank;
import dev.plex.util.PlexUtils; import dev.plex.util.PlexUtils;
import java.util.List;
import net.kyori.adventure.text.Component; import net.kyori.adventure.text.Component;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.GameMode; import org.bukkit.GameMode;
@ -18,7 +17,9 @@ import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
@CommandPermissions(level = Rank.OP, permission = "plex.gamemode.survival", source = RequiredCommandSource.ANY) import java.util.List;
@CommandPermissions(permission = "plex.gamemode.survival", source = RequiredCommandSource.ANY)
@CommandParameters(name = "survival", aliases = "gms,egms,esurvival,survivalmode,esurvivalmode", description = "Set your own or another player's gamemode to survival mode") @CommandParameters(name = "survival", aliases = "gms,egms,esurvival,survivalmode,esurvivalmode", description = "Set your own or another player's gamemode to survival mode")
public class SurvivalCMD extends PlexCommand public class SurvivalCMD extends PlexCommand
{ {
@ -29,13 +30,13 @@ public class SurvivalCMD extends PlexCommand
{ {
if (isConsole(sender)) if (isConsole(sender))
{ {
throw new CommandFailException(PlexUtils.messageString("consoleMustDefinePlayer")); throw new CommandFailException(messageString("consoleMustDefinePlayer"));
} }
Bukkit.getServer().getPluginManager().callEvent(new GameModeUpdateEvent(sender, playerSender, GameMode.SURVIVAL)); Bukkit.getServer().getPluginManager().callEvent(new GameModeUpdateEvent(sender, playerSender, GameMode.SURVIVAL));
return null; return null;
} }
if (checkRank(sender, Rank.ADMIN, "plex.gamemode.survival.others")) if (checkPermission(sender,"plex.gamemode.survival.others"))
{ {
if (args[0].equals("-a")) if (args[0].equals("-a"))
{ {
@ -56,9 +57,9 @@ public class SurvivalCMD extends PlexCommand
} }
@Override @Override
public @NotNull List<String> tabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) throws IllegalArgumentException public @NotNull List<String> smartTabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) throws IllegalArgumentException
{ {
if (checkTab(sender, Rank.ADMIN, "plex.gamemode.survival.others")) if (silentCheckPermission(sender,"plex.gamemode.survival.others"))
{ {
return PlexUtils.getPlayerNameList(); return PlexUtils.getPlayerNameList();
} }

View File

@ -1,46 +0,0 @@
package dev.plex.command.impl;
import com.google.common.base.Splitter;
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 java.util.ArrayList;
import java.util.List;
import net.kyori.adventure.inventory.Book;
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;
@CommandParameters(name = "totalfreedommod", description = "You can't simpy do that.", aliases = "tfm")
@CommandPermissions(level = Rank.OP, source = RequiredCommandSource.ANY)
public class TFMCMD extends PlexCommand
{
@Override
protected Component execute(@NotNull CommandSender sender, @Nullable Player playerSender, @NotNull String[] args)
{
if (playerSender != null)
{
String simpy = "It's not about credit or discredit, it's about copyright of TFM. Looking at Plex's source code, it looks like a bunch of copy-pasted source code from TFM and Aero (utility plugin). You just put it under a different license and pretended it's yours. You can't simpy do that. You have to remove all parts which infringe on the TFM license (as per the TFM repository) and the Aero License (as per the Aero repository) or otherwise comply to the license requirements.";
List<String> pages = Splitter.fixedLength(256).splitToList(simpy);
List<Component> pageComponents = new ArrayList<>();
for (String page : pages)
{
pageComponents.add(PlexUtils.mmDeserialize("<rainbow>" + page + "</rainbow>"));
}
playerSender.openBook(Book.builder()
.title(Component.text("TFM License"))
.author(Component.text("Prozza"))
.pages(pageComponents));
}
return PlexUtils.mmDeserialize("<rainbow>It's not about credit or discredit, it's about copyright of TFM.<br>Looking at Plex's source code, it looks like a bunch of copy-pasted source code from TFM and Aero (utility plugin). You just put it under a different license and pretended it's yours.<br>You can't simpy do that. You have to remove all parts which infringe on the TFM license (as per the TFM repository) and the Aero License (as per the Aero repository) or otherwise comply to the license requirements.</rainbow>");
}
}

View File

@ -6,7 +6,6 @@ import dev.plex.command.annotation.CommandParameters;
import dev.plex.command.annotation.CommandPermissions; import dev.plex.command.annotation.CommandPermissions;
import dev.plex.command.source.RequiredCommandSource; import dev.plex.command.source.RequiredCommandSource;
import dev.plex.player.PlexPlayer; import dev.plex.player.PlexPlayer;
import dev.plex.rank.enums.Rank;
import dev.plex.util.PlexUtils; import dev.plex.util.PlexUtils;
import dev.plex.util.minimessage.SafeMiniMessage; import dev.plex.util.minimessage.SafeMiniMessage;
import net.kyori.adventure.text.Component; import net.kyori.adventure.text.Component;
@ -19,7 +18,11 @@ import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
@CommandPermissions(level = Rank.OP, permission = "plex.tag", source = RequiredCommandSource.ANY) import java.util.Arrays;
import java.util.Collections;
import java.util.List;
@CommandPermissions(permission = "plex.tag", source = RequiredCommandSource.ANY)
@CommandParameters(name = "tag", aliases = "prefix", description = "Set or clear your prefix", usage = "/<command> <set <prefix> | clear <player>>") @CommandParameters(name = "tag", aliases = "prefix", description = "Set or clear your prefix", usage = "/<command> <set <prefix> | clear <player>>")
public class TagCMD extends PlexCommand public class TagCMD extends PlexCommand
{ {
@ -47,16 +50,15 @@ public class TagCMD extends PlexCommand
{ {
return usage("/tag set <prefix>"); return usage("/tag set <prefix>");
} }
String prefix = PlexUtils.cleanString(StringUtils.join(args, " ", 1, args.length));
Component convertedComponent = SafeMiniMessage.mmDeserializeWithoutEvents(prefix); Component convertedComponent = PlexUtils.stringToComponent(StringUtils.join(args, " ", 1, args.length));
if (PlainTextComponentSerializer.plainText().serialize(convertedComponent).length() > plugin.config.getInt("chat.max-tag-length", 16)) 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)); return messageComponent("maximumPrefixLength", plugin.config.getInt("chat.max-tag-length", 16));
} }
player.setPrefix(prefix); player.setPrefix(MiniMessage.miniMessage().serialize(convertedComponent));
DataUtils.update(player); DataUtils.update(player);
return messageComponent("prefixSetTo", MiniMessage.miniMessage().serialize(convertedComponent)); return messageComponent("prefixSetTo", MiniMessage.miniMessage().serialize(convertedComponent));
} }
@ -76,20 +78,39 @@ public class TagCMD extends PlexCommand
} }
PlexPlayer player = DataUtils.getPlayer(playerSender.getUniqueId()); PlexPlayer player = DataUtils.getPlayer(playerSender.getUniqueId());
player.setPrefix(""); player.setPrefix(null);
DataUtils.update(player); DataUtils.update(player);
return messageComponent("prefixCleared"); return messageComponent("prefixCleared");
} }
checkPermission(sender, "plex.tag.clear.others");
checkRank(sender, Rank.ADMIN, "plex.tag.clear.others");
Player target = getNonNullPlayer(args[1]); Player target = getNonNullPlayer(args[1]);
PlexPlayer plexTarget = DataUtils.getPlayer(target.getUniqueId()); PlexPlayer plexTarget = DataUtils.getPlayer(target.getUniqueId());
plexTarget.setPrefix(""); plexTarget.setPrefix(null);
DataUtils.update(plexTarget); DataUtils.update(plexTarget);
return messageComponent("otherPrefixCleared", target.getName()); return messageComponent("otherPrefixCleared", target.getName());
} }
return usage(); return usage();
} }
@Override
public @NotNull List<String> smartTabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) throws IllegalArgumentException
{
if (args.length == 1)
{
return Arrays.asList("set", "clear");
}
if (args.length == 2)
{
if (args[0].equalsIgnoreCase("clear"))
{
if (silentCheckPermission(sender, "plex.tag.clear.others"))
{
return PlexUtils.getPlayerNameList();
}
}
}
return Collections.emptyList();
}
} }

View File

@ -10,13 +10,10 @@ import dev.plex.command.source.RequiredCommandSource;
import dev.plex.player.PlexPlayer; import dev.plex.player.PlexPlayer;
import dev.plex.punishment.Punishment; import dev.plex.punishment.Punishment;
import dev.plex.punishment.PunishmentType; import dev.plex.punishment.PunishmentType;
import dev.plex.rank.enums.Rank;
import dev.plex.util.BungeeUtil; import dev.plex.util.BungeeUtil;
import dev.plex.util.PlexLog;
import dev.plex.util.PlexUtils; import dev.plex.util.PlexUtils;
import dev.plex.util.TimeUtils; import dev.plex.util.TimeUtils;
import dev.plex.util.WebUtils;
import java.util.List;
import java.util.UUID;
import net.kyori.adventure.text.Component; import net.kyori.adventure.text.Component;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
@ -25,8 +22,11 @@ import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
@CommandParameters(name = "tempban", usage = "/<command> <player> <time> [reason]", description = "Temporarily ban a player") import java.util.Collections;
@CommandPermissions(level = Rank.ADMIN, permission = "plex.tempban", source = RequiredCommandSource.ANY) import java.util.List;
@CommandParameters(name = "tempban", usage = "/<command> <player> <time> [reason] [-rb]", description = "Temporarily ban a player")
@CommandPermissions(permission = "plex.tempban", source = RequiredCommandSource.ANY)
public class TempbanCMD extends PlexCommand public class TempbanCMD extends PlexCommand
{ {
@ -38,65 +38,87 @@ public class TempbanCMD extends PlexCommand
return usage(); return usage();
} }
UUID targetUUID = WebUtils.getFromName(args[0]); PlexPlayer target = DataUtils.getPlayer(args[0]);
String reason; String reason;
if (targetUUID == null || !DataUtils.hasPlayedBefore(targetUUID)) if (target == null)
{ {
throw new PlayerNotFoundException(); throw new PlayerNotFoundException();
} }
Player player = Bukkit.getPlayer(target.getUuid());
PlexPlayer plexPlayer = DataUtils.getPlayer(targetUUID); if (plugin.getPunishmentManager().isBanned(target.getUuid()))
Player player = Bukkit.getPlayer(targetUUID);
if (isAdmin(plexPlayer))
{
if (!isConsole(sender))
{
assert playerSender != null;
PlexPlayer plexPlayer1 = getPlexPlayer(playerSender);
if (!plexPlayer1.getRankFromString().isAtLeast(plexPlayer.getRankFromString()) && plexPlayer.isAdminActive())
{
return messageComponent("higherRankThanYou");
}
}
}
if (plugin.getPunishmentManager().isBanned(targetUUID))
{ {
return messageComponent("playerBanned"); return messageComponent("playerBanned");
} }
Punishment punishment = new Punishment(targetUUID, getUUID(sender)); Punishment punishment = new Punishment(target.getUuid(), getUUID(sender));
punishment.setType(PunishmentType.TEMPBAN); punishment.setType(PunishmentType.TEMPBAN);
boolean rollBack = false;
if (args.length > 2) if (args.length > 2)
{ {
reason = StringUtils.join(args, " ", 2, args.length); reason = StringUtils.join(args, " ", 2, args.length);
punishment.setReason(reason); String newReason = StringUtils.normalizeSpace(reason.replace("-nrb", ""));
punishment.setReason(newReason.trim().isEmpty() ? messageString("noReasonProvided") : newReason);
rollBack = reason.startsWith("-rb") || reason.endsWith("-rb");
} }
else else
{ {
punishment.setReason("No reason provided."); punishment.setReason(messageString("noReasonProvided"));
} }
punishment.setPunishedUsername(plexPlayer.getName()); punishment.setPunishedUsername(target.getName());
punishment.setEndDate(TimeUtils.createDate(args[1])); punishment.setEndDate(TimeUtils.createDate(args[1]));
punishment.setCustomTime(false); punishment.setCustomTime(false);
punishment.setActive(!isAdmin(plexPlayer)); punishment.setActive(true);
if (player != null) if (player != null)
{ {
punishment.setIp(player.getAddress().getAddress().getHostAddress().trim()); punishment.setIp(player.getAddress().getAddress().getHostAddress().trim());
} }
plugin.getPunishmentManager().punish(plexPlayer, punishment); plugin.getPunishmentManager().punish(target, punishment);
PlexUtils.broadcast(messageComponent("banningPlayer", sender.getName(), plexPlayer.getName())); PlexUtils.broadcast(messageComponent("banningPlayer", sender.getName(), target.getName()));
if (player != null) if (player != null)
{ {
BungeeUtil.kickPlayer(player, Punishment.generateBanMessage(punishment)); BungeeUtil.kickPlayer(player, Punishment.generateBanMessage(punishment));
} }
if (rollBack)
{
/*if (plugin.getPrismHook().hasPrism()) {
PrismParameters parameters = plugin.getPrismHook().prismApi().createParameters();
parameters.addActionType("block-place");
parameters.addActionType("block-break");
parameters.addActionType("block-burn");
parameters.addActionType("entity-spawn");
parameters.addActionType("entity-kill");
parameters.addActionType("entity-explode");
parameters.addPlayerName(plexPlayer.getName());
parameters.setBeforeTime(Instant.now().toEpochMilli());
parameters.setProcessType(PrismProcessType.ROLLBACK);
final Future<Result> result = plugin.getPrismHook().prismApi().performLookup(parameters, sender);
Bukkit.getAsyncScheduler().runNow(plugin, scheduledTask -> {
try
{
final Result done = result.get();
} catch (InterruptedException | ExecutionException e)
{
throw new RuntimeException(e);
}
});
}
else */
if (plugin.getCoreProtectHook() != null && plugin.getCoreProtectHook().hasCoreProtect())
{
PlexLog.debug("Testing coreprotect");
Bukkit.getAsyncScheduler().runNow(plugin, scheduledTask ->
{
plugin.getCoreProtectHook().coreProtectAPI().performRollback(86400, Collections.singletonList(target.getName()), null, null, null, null, 0, null);
});
}
}
return null; return null;
} }
@Override @Override
public @NotNull List<String> tabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) throws IllegalArgumentException public @NotNull List<String> smartTabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) throws IllegalArgumentException
{ {
return args.length == 1 && checkTab(sender, Rank.ADMIN, "plex.tempban") ? PlexUtils.getPlayerNameList() : ImmutableList.of(); return args.length == 1 && silentCheckPermission(sender, this.getPermission()) ? PlexUtils.getPlayerNameList() : ImmutableList.of();
} }
} }

View File

@ -0,0 +1,92 @@
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;
import dev.plex.player.PlexPlayer;
import dev.plex.punishment.Punishment;
import dev.plex.punishment.PunishmentType;
import dev.plex.util.PlexUtils;
import dev.plex.util.TimeUtils; // Import your 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.ZonedDateTime;
import java.util.Arrays;
import java.util.List;
@CommandParameters(name = "tempmute", description = "Temporarily mute a player on the server",
usage = "/<command> <player> <time> [reason]", aliases = "tmute")
@CommandPermissions(permission = "plex.tempmute")
public class TempmuteCMD extends PlexCommand
{
@Override
protected Component execute(@NotNull CommandSender sender, @Nullable Player playerSender, String[] args)
{
if (args.length < 2)
{
return usage();
}
Player player = getNonNullPlayer(args[0]);
PlexPlayer punishedPlayer = getOfflinePlexPlayer(player.getUniqueId());
if (punishedPlayer.isMuted())
{
return messageComponent("playerMuted");
}
if (silentCheckPermission(player, "plex.tempmute"))
{
send(sender, messageComponent("higherRankThanYou"));
return null;
}
ZonedDateTime endDate;
try
{
endDate = TimeUtils.createDate(args[1]);
}
catch (NumberFormatException e)
{
return messageComponent("invalidTimeFormat");
}
if (endDate.isBefore(ZonedDateTime.now()))
{
return messageComponent("timeMustBeFuture");
}
ZonedDateTime oneWeekFromNow = ZonedDateTime.now().plusWeeks(1);
if (endDate.isAfter(oneWeekFromNow))
{
return messageComponent("maxTimeExceeded");
}
final String reason = args.length >= 3 ? String.join(" ", Arrays.copyOfRange(args, 2, args.length))
: messageString("noReasonProvided");
Punishment punishment = new Punishment(punishedPlayer.getUuid(), getUUID(sender));
punishment.setCustomTime(true);
punishment.setEndDate(endDate);
punishment.setType(PunishmentType.MUTE);
punishment.setPunishedUsername(player.getName());
punishment.setIp(player.getAddress().getAddress().getHostAddress().trim());
punishment.setReason(reason);
punishment.setActive(true);
plugin.getPunishmentManager().punish(punishedPlayer, punishment);
PlexUtils.broadcast(messageComponent("tempMutedPlayer", sender.getName(), player.getName(), TimeUtils.formatRelativeTime(endDate)));
return null;
}
@Override
public @NotNull List<String> smartTabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) throws IllegalArgumentException
{
return args.length == 1 && silentCheckPermission(sender, this.getPermission()) ? PlexUtils.getPlayerNameList() : ImmutableList.of();
}
}

View File

@ -5,10 +5,8 @@ import dev.plex.command.PlexCommand;
import dev.plex.command.annotation.CommandParameters; import dev.plex.command.annotation.CommandParameters;
import dev.plex.command.annotation.CommandPermissions; import dev.plex.command.annotation.CommandPermissions;
import dev.plex.command.source.RequiredCommandSource; import dev.plex.command.source.RequiredCommandSource;
import dev.plex.menu.ToggleMenu; import dev.plex.menu.impl.ToggleMenu;
import dev.plex.rank.enums.Rank;
import dev.plex.util.PlexUtils; import dev.plex.util.PlexUtils;
import java.util.List;
import net.kyori.adventure.text.Component; import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.NamedTextColor; import net.kyori.adventure.text.format.NamedTextColor;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
@ -16,8 +14,10 @@ import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
import java.util.List;
@CommandParameters(name = "toggle", description = "Allows toggling various server aspects through a GUI", aliases = "toggles") @CommandParameters(name = "toggle", description = "Allows toggling various server aspects through a GUI", aliases = "toggles")
@CommandPermissions(level = Rank.ADMIN, permission = "plex.toggle", source = RequiredCommandSource.ANY) @CommandPermissions(permission = "plex.toggle", source = RequiredCommandSource.ANY)
public class ToggleCMD extends PlexCommand public class ToggleCMD extends PlexCommand
{ {
@Override @Override
@ -32,6 +32,8 @@ public class ToggleCMD extends PlexCommand
sender.sendMessage(PlexUtils.mmDeserialize("<gray> - Fluidspread" + status("fluidspread"))); sender.sendMessage(PlexUtils.mmDeserialize("<gray> - Fluidspread" + status("fluidspread")));
sender.sendMessage(PlexUtils.mmDeserialize("<gray> - Drops" + status("drops"))); sender.sendMessage(PlexUtils.mmDeserialize("<gray> - Drops" + status("drops")));
sender.sendMessage(PlexUtils.mmDeserialize("<gray> - Redstone" + status("redstone"))); sender.sendMessage(PlexUtils.mmDeserialize("<gray> - Redstone" + status("redstone")));
sender.sendMessage(PlexUtils.mmDeserialize("<gray> - PVP" + status("pvp")));
sender.sendMessage(PlexUtils.mmDeserialize("<gray> - Chat" + status("chat")));
return null; return null;
} }
switch (args[0].toLowerCase()) switch (args[0].toLowerCase())
@ -52,20 +54,29 @@ public class ToggleCMD extends PlexCommand
{ {
return toggle("redstone"); return toggle("redstone");
} }
case "pvp" ->
{
return toggle("pvp");
}
case "chat" ->
{
PlexUtils.broadcast(PlexUtils.messageComponent("chatToggled", sender.getName(), plugin.toggles.getBoolean("chat") ? "off" : "on"));
return toggle("chat");
}
default -> default ->
{ {
return messageComponent("invalidToggle"); return messageComponent("invalidToggle");
} }
} }
} }
new ToggleMenu().openInv(playerSender, 0); new ToggleMenu().open(playerSender);
return null; return null;
} }
@Override @Override
public @NotNull List<String> tabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) throws IllegalArgumentException public @NotNull List<String> smartTabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) throws IllegalArgumentException
{ {
return args.length == 1 ? PlexUtils.getPlayerNameList() : ImmutableList.of(); return args.length == 1 && silentCheckPermission(sender, this.getPermission()) ? PlexUtils.getPlayerNameList() : ImmutableList.of();
} }
private String status(String toggle) private String status(String toggle)

View File

@ -9,19 +9,17 @@ import dev.plex.command.exception.PlayerNotBannedException;
import dev.plex.command.exception.PlayerNotFoundException; import dev.plex.command.exception.PlayerNotFoundException;
import dev.plex.command.source.RequiredCommandSource; import dev.plex.command.source.RequiredCommandSource;
import dev.plex.player.PlexPlayer; import dev.plex.player.PlexPlayer;
import dev.plex.rank.enums.Rank;
import dev.plex.util.PlexUtils; 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.Component;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
import java.util.List;
@CommandParameters(name = "unban", usage = "/<command> <player>", description = "Unbans a player, offline or online") @CommandParameters(name = "unban", usage = "/<command> <player>", description = "Unbans a player, offline or online")
@CommandPermissions(level = Rank.ADMIN, permission = "plex.ban", source = RequiredCommandSource.ANY) @CommandPermissions(permission = "plex.ban", source = RequiredCommandSource.ANY)
public class UnbanCMD extends PlexCommand public class UnbanCMD extends PlexCommand
{ {
@ -35,31 +33,30 @@ public class UnbanCMD extends PlexCommand
if (args.length == 1) if (args.length == 1)
{ {
UUID targetUUID = WebUtils.getFromName(args[0]); PlexPlayer target = DataUtils.getPlayer(args[0]);
if (targetUUID == null || !DataUtils.hasPlayedBefore(targetUUID)) if (target == null)
{ {
throw new PlayerNotFoundException(); throw new PlayerNotFoundException();
} }
plugin.getPunishmentManager().isAsyncBanned(targetUUID).whenComplete((aBoolean, throwable) -> plugin.getPunishmentManager().isAsyncBanned(target.getUuid()).whenComplete((aBoolean, throwable) ->
{ {
PlexPlayer plexPlayer = getOfflinePlexPlayer(targetUUID);
if (!aBoolean) if (!aBoolean)
{ {
send(sender, PlexUtils.mmDeserialize(new PlayerNotBannedException().getMessage())); send(sender, PlexUtils.mmDeserialize(new PlayerNotBannedException().getMessage()));
return; return;
} }
plugin.getPunishmentManager().unban(targetUUID); plugin.getPunishmentManager().unban(target.getUuid());
PlexUtils.broadcast(messageComponent("unbanningPlayer", sender.getName(), plexPlayer.getName())); PlexUtils.broadcast(messageComponent("unbanningPlayer", sender.getName(), target.getName()));
}); });
} }
return null; return null;
} }
@Override @Override
public @NotNull List<String> tabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) throws IllegalArgumentException public @NotNull List<String> smartTabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) throws IllegalArgumentException
{ {
return args.length == 1 && checkTab(sender, Rank.ADMIN, "plex.unban") ? PlexUtils.getPlayerNameList() : ImmutableList.of(); return args.length == 1 && silentCheckPermission(sender, this.getPermission()) ? PlexUtils.getPlayerNameList() : ImmutableList.of();
} }
} }

View File

@ -1,21 +1,24 @@
package dev.plex.command.impl; package dev.plex.command.impl;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
import dev.plex.cache.DataUtils;
import dev.plex.command.PlexCommand; import dev.plex.command.PlexCommand;
import dev.plex.command.annotation.CommandParameters; import dev.plex.command.annotation.CommandParameters;
import dev.plex.command.annotation.CommandPermissions; import dev.plex.command.annotation.CommandPermissions;
import dev.plex.command.exception.CommandFailException; import dev.plex.command.exception.CommandFailException;
import dev.plex.command.exception.PlayerNotFoundException;
import dev.plex.player.PlexPlayer; import dev.plex.player.PlexPlayer;
import dev.plex.rank.enums.Rank; import dev.plex.punishment.PunishmentType;
import dev.plex.util.PlexUtils; import dev.plex.util.PlexUtils;
import java.util.List;
import net.kyori.adventure.text.Component; import net.kyori.adventure.text.Component;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
@CommandPermissions(level = Rank.ADMIN, permission = "plex.unfreeze") import java.util.List;
@CommandPermissions(permission = "plex.unfreeze")
@CommandParameters(name = "unfreeze", description = "Unfreeze a player", usage = "/<command> <player>") @CommandParameters(name = "unfreeze", description = "Unfreeze a player", usage = "/<command> <player>")
public class UnfreezeCMD extends PlexCommand public class UnfreezeCMD extends PlexCommand
{ {
@ -26,20 +29,28 @@ public class UnfreezeCMD extends PlexCommand
{ {
return usage(); return usage();
} }
Player player = getNonNullPlayer(args[0]); PlexPlayer punishedPlayer = DataUtils.getPlayer(args[0]);
PlexPlayer punishedPlayer = getOfflinePlexPlayer(player.getUniqueId()); if (punishedPlayer == null)
{
throw new PlayerNotFoundException();
}
if (!punishedPlayer.isFrozen()) if (!punishedPlayer.isFrozen())
{ {
throw new CommandFailException(PlexUtils.messageString("playerNotFrozen")); throw new CommandFailException(PlexUtils.messageString("playerNotFrozen"));
} }
punishedPlayer.setFrozen(false); punishedPlayer.setFrozen(false);
PlexUtils.broadcast(messageComponent("unfrozePlayer", sender.getName(), player.getName())); punishedPlayer.getPunishments().stream().filter(punishment -> punishment.getType() == PunishmentType.FREEZE && punishment.isActive()).forEach(punishment -> {
punishment.setActive(false);
plugin.getSqlPunishment().updatePunishment(punishment.getType(), false, punishment.getPunished());
});
PlexUtils.broadcast(messageComponent("unfrozePlayer", sender.getName(), punishedPlayer.getName()));
return null; return null;
} }
@Override @Override
public @NotNull List<String> tabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) throws IllegalArgumentException public @NotNull List<String> smartTabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) throws IllegalArgumentException
{ {
return args.length == 1 && checkTab(sender, Rank.ADMIN, "plex.unfreeze") ? PlexUtils.getPlayerNameList() : ImmutableList.of(); return args.length == 1 && silentCheckPermission(sender, this.getPermission()) ? PlexUtils.getPlayerNameList() : ImmutableList.of();
} }
} }

View File

@ -1,21 +1,24 @@
package dev.plex.command.impl; package dev.plex.command.impl;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
import dev.plex.cache.DataUtils;
import dev.plex.command.PlexCommand; import dev.plex.command.PlexCommand;
import dev.plex.command.annotation.CommandParameters; import dev.plex.command.annotation.CommandParameters;
import dev.plex.command.annotation.CommandPermissions; import dev.plex.command.annotation.CommandPermissions;
import dev.plex.command.exception.CommandFailException; import dev.plex.command.exception.CommandFailException;
import dev.plex.command.exception.PlayerNotFoundException;
import dev.plex.player.PlexPlayer; import dev.plex.player.PlexPlayer;
import dev.plex.rank.enums.Rank; import dev.plex.punishment.PunishmentType;
import dev.plex.util.PlexUtils; import dev.plex.util.PlexUtils;
import java.util.List;
import net.kyori.adventure.text.Component; import net.kyori.adventure.text.Component;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
@CommandPermissions(level = Rank.ADMIN, permission = "plex.unmute") import java.util.List;
@CommandPermissions(permission = "plex.unmute")
@CommandParameters(name = "unmute", description = "Unmute a player", usage = "/<command> <player>") @CommandParameters(name = "unmute", description = "Unmute a player", usage = "/<command> <player>")
public class UnmuteCMD extends PlexCommand public class UnmuteCMD extends PlexCommand
{ {
@ -26,20 +29,28 @@ public class UnmuteCMD extends PlexCommand
{ {
return usage(); return usage();
} }
Player player = getNonNullPlayer(args[0]); PlexPlayer punishedPlayer = DataUtils.getPlayer(args[0]);
PlexPlayer punishedPlayer = getOfflinePlexPlayer(player.getUniqueId()); if (punishedPlayer == null)
{
throw new PlayerNotFoundException();
}
if (!punishedPlayer.isMuted()) if (!punishedPlayer.isMuted())
{ {
throw new CommandFailException(PlexUtils.messageString("playerNotMuted")); throw new CommandFailException(PlexUtils.messageString("playerNotMuted"));
} }
punishedPlayer.setMuted(false); punishedPlayer.setMuted(false);
PlexUtils.broadcast(messageComponent("unmutedPlayer", sender.getName(), player.getName())); punishedPlayer.getPunishments().stream().filter(punishment -> punishment.getType() == PunishmentType.MUTE && punishment.isActive()).forEach(punishment -> {
punishment.setActive(false);
plugin.getSqlPunishment().updatePunishment(punishment.getType(), false, punishment.getPunished());
});
PlexUtils.broadcast(messageComponent("unmutedPlayer", sender.getName(), punishedPlayer.getName()));
return null; return null;
} }
@Override @Override
public @NotNull List<String> tabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) throws IllegalArgumentException public @NotNull List<String> smartTabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) throws IllegalArgumentException
{ {
return args.length == 1 && checkTab(sender, Rank.ADMIN, "plex.unfreeze") ? PlexUtils.getPlayerNameList() : ImmutableList.of(); return args.length == 1 && silentCheckPermission(sender, this.getPermission()) ? PlexUtils.getPlayerNameList() : ImmutableList.of();
} }
} }

View File

@ -0,0 +1,79 @@
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;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.JoinConfiguration;
import net.kyori.adventure.text.TextComponent;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.Arrays;
import java.util.List;
import java.util.Collections;
@CommandPermissions(permission = "plex.whohas")
@CommandParameters(name = "whohas", description = "Returns a list of players with a specific item in their inventory.", usage = "/<command> <material>", aliases = "wh")
public class WhoHasCMD extends PlexCommand
{
@Override
protected Component execute(@NotNull CommandSender sender, @Nullable Player playerSender, @NotNull String[] args)
{
if (args.length == 0)
{
return usage();
}
final Material material = Material.getMaterial(args[0].toUpperCase());
if (material == null)
{
return messageComponent("materialNotFound", args[0]);
}
boolean clearInventory = args.length > 1 && args[1].equalsIgnoreCase("clear");
if (clearInventory && !sender.hasPermission("plex.whohas.clear"))
{
return messageComponent("noPermissionNode", "plex.whohas.clear");
}
List<TextComponent> players = Bukkit.getOnlinePlayers().stream().filter(player ->
player.getInventory().contains(material)).map(player -> {
if (clearInventory)
{
player.getInventory().remove(material);
player.updateInventory();
}
return Component.text(player.getName());
}).toList();
return players.isEmpty() ?
messageComponent("nobodyHasThatMaterial") :
(clearInventory ?
messageComponent("playersMaterialCleared", Component.text(material.name()),
Component.join(JoinConfiguration.commas(true), players)) :
messageComponent("playersWithMaterial", Component.text(material.name()),
Component.join(JoinConfiguration.commas(true), players)));
}
@Override
public @NotNull List<String> smartTabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) throws IllegalArgumentException
{
if (args.length == 1 && silentCheckPermission(sender, this.getPermission()))
{
return Arrays.stream(Material.values()).map(Enum::name).toList();
}
else if (args.length == 2 && silentCheckPermission(sender, "plex.whohas.clear"))
{
return Collections.singletonList("clear");
}
return ImmutableList.of();
}
}

View File

@ -1,26 +1,29 @@
package dev.plex.command.impl; package dev.plex.command.impl;
import com.google.common.collect.ImmutableList; import com.google.common.collect.Lists;
import dev.plex.Plex;
import dev.plex.command.PlexCommand; import dev.plex.command.PlexCommand;
import dev.plex.command.annotation.CommandParameters; import dev.plex.command.annotation.CommandParameters;
import dev.plex.command.annotation.CommandPermissions; import dev.plex.command.annotation.CommandPermissions;
import dev.plex.command.source.RequiredCommandSource; import dev.plex.command.source.RequiredCommandSource;
import dev.plex.rank.enums.Rank;
import java.util.List;
import java.util.stream.Collectors;
import net.kyori.adventure.text.Component; import net.kyori.adventure.text.Component;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.World; import org.bukkit.World;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
@CommandPermissions(level = Rank.OP, permission = "plex.world", source = RequiredCommandSource.IN_GAME) import java.util.List;
import java.util.UUID;
import java.util.regex.Pattern;
@CommandPermissions(permission = "plex.world", source = RequiredCommandSource.IN_GAME)
@CommandParameters(name = "world", description = "Teleport to a world.", usage = "/<command> <world>") @CommandParameters(name = "world", description = "Teleport to a world.", usage = "/<command> <world>")
public class WorldCMD extends PlexCommand public class WorldCMD extends PlexCommand
{ {
private static final Pattern UUID_PATTERN = Pattern.compile("[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}");
@Override @Override
protected Component execute(@NotNull CommandSender sender, @Nullable Player playerSender, String[] args) protected Component execute(@NotNull CommandSender sender, @Nullable Player playerSender, String[] args)
{ {
@ -29,18 +32,44 @@ public class WorldCMD extends PlexCommand
{ {
return usage(); return usage();
} }
World world = getNonNullWorld(args[0]); World world = getNonNullWorld(args[0]);
playerSender.teleportAsync(new Location(world, 0, world.getHighestBlockYAt(0, 0) + 1, 0, 0, 0)); boolean playerWorld = args[0].matches("[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}");
if (playerWorld && Plex.get().getModuleManager().getModules().stream().anyMatch(plexModule -> plexModule.getPlexModuleFile().getName().equalsIgnoreCase("Module-TFMExtras")))
{
checkPermission(playerSender, "plex.world.playerworlds");
}
playerSender.teleportAsync(world.getSpawnLocation());
return messageComponent("playerWorldTeleport", world.getName()); return messageComponent("playerWorldTeleport", world.getName());
} }
@Override @Override
public @NotNull List<String> tabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) throws IllegalArgumentException public @NotNull List<String> smartTabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) throws IllegalArgumentException
{ {
if (args.length == 1) final List<String> completions = Lists.newArrayList();
final Player player = (Player) sender;
if (args.length == 1 && silentCheckPermission(sender, this.getPermission()))
{ {
return Bukkit.getWorlds().stream().map(World::getName).collect(Collectors.toList()); @NotNull List<World> worlds = Bukkit.getWorlds();
} for (World world : worlds)
return ImmutableList.of(); {
String worldName = world.getName();
try
{
final UUID uuid = UUID.fromString(worldName);
if (uuid.equals(player.getUniqueId()) || silentCheckPermission(player, "plex.world.playerworlds"))
{
completions.add(worldName);
}
}
catch (Exception e)
{
completions.add(worldName);
}
}
}
return completions;
} }
} }

View File

@ -2,10 +2,11 @@ package dev.plex.config;
import dev.plex.Plex; import dev.plex.Plex;
import dev.plex.util.PlexLog; import dev.plex.util.PlexLog;
import org.bukkit.configuration.file.YamlConfiguration;
import java.io.File; import java.io.File;
import java.io.InputStreamReader; import java.io.InputStreamReader;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import org.bukkit.configuration.file.YamlConfiguration;
/** /**
* Creates a custom Config object * Creates a custom Config object

View File

@ -1,11 +1,12 @@
package dev.plex.config; package dev.plex.config;
import dev.plex.module.PlexModule; import dev.plex.module.PlexModule;
import org.bukkit.configuration.InvalidConfigurationException;
import org.bukkit.configuration.file.YamlConfiguration;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.nio.file.Files; import java.nio.file.Files;
import org.bukkit.configuration.InvalidConfigurationException;
import org.bukkit.configuration.file.YamlConfiguration;
/** /**
* Creates a custom Config object * Creates a custom Config object

View File

@ -1,39 +0,0 @@
package dev.plex.event;
import dev.plex.player.PlexPlayer;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.bukkit.command.CommandSender;
import org.bukkit.event.Event;
import org.bukkit.event.HandlerList;
/**
* Event that is run when a player is added to the admin list
*/
@EqualsAndHashCode(callSuper = false)
@Data
public class AdminAddEvent extends Event
{
private static final HandlerList handlers = new HandlerList();
/**
* The sender who added the player
*/
private final CommandSender sender;
/**
* The PlexPlayer that was added
*/
private final PlexPlayer plexPlayer;
public static HandlerList getHandlerList()
{
return handlers;
}
@Override
public HandlerList getHandlers()
{
return handlers;
}
}

View File

@ -1,39 +0,0 @@
package dev.plex.event;
import dev.plex.player.PlexPlayer;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.bukkit.command.CommandSender;
import org.bukkit.event.Event;
import org.bukkit.event.HandlerList;
/**
* Event that is run when a player is removed from the admin list
*/
@EqualsAndHashCode(callSuper = false)
@Data
public class AdminRemoveEvent extends Event
{
private static final HandlerList handlers = new HandlerList();
/**
* The sender who added the player
*/
private final CommandSender sender;
/**
* The PlexPlayer that was removed
*/
private final PlexPlayer plexPlayer;
public static HandlerList getHandlerList()
{
return handlers;
}
@Override
public HandlerList getHandlers()
{
return handlers;
}
}

View File

@ -1,45 +0,0 @@
package dev.plex.event;
import dev.plex.player.PlexPlayer;
import dev.plex.rank.enums.Rank;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.bukkit.command.CommandSender;
import org.bukkit.event.Event;
import org.bukkit.event.HandlerList;
/**
* Event that is run when an admins rank is set
*/
@EqualsAndHashCode(callSuper = false)
@Data
public class AdminSetRankEvent extends Event
{
private static final HandlerList handlers = new HandlerList();
/**
* The sender who added the player
*/
private final CommandSender sender;
/**
* The PlexPlayer that was removed
*/
private final PlexPlayer plexPlayer;
/**
* The rank the player was set to
*/
private final Rank rank;
public static HandlerList getHandlerList()
{
return handlers;
}
@Override
public HandlerList getHandlers()
{
return handlers;
}
}

View File

@ -3,9 +3,10 @@ package dev.plex.handlers;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
import dev.plex.PlexBase; import dev.plex.PlexBase;
import dev.plex.command.PlexCommand; import dev.plex.command.PlexCommand;
import dev.plex.command.annotation.System; import dev.plex.command.impl.DebugCMD;
import dev.plex.util.PlexLog; import dev.plex.util.PlexLog;
import dev.plex.util.ReflectionsUtil; import dev.plex.util.ReflectionsUtil;
import java.lang.reflect.InvocationTargetException; import java.lang.reflect.InvocationTargetException;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;
@ -21,19 +22,10 @@ public class CommandHandler implements PlexBase
{ {
try try
{ {
if (clazz.isAnnotationPresent(System.class)) if (plugin.config.getBoolean("debug") && DebugCMD.class.isAssignableFrom(clazz))
{
System annotation = clazz.getDeclaredAnnotation(System.class);
if (annotation.value().equalsIgnoreCase(plugin.getSystem().toLowerCase()))
{ {
commands.add(clazz.getConstructor().newInstance()); commands.add(clazz.getConstructor().newInstance());
} }
if (plugin.config.getBoolean("debug") && annotation.debug())
{
commands.add(clazz.getConstructor().newInstance());
}
}
else else
{ {
commands.add(clazz.getConstructor().newInstance()); commands.add(clazz.getConstructor().newInstance());

View File

@ -6,6 +6,7 @@ import dev.plex.listener.PlexListener;
import dev.plex.listener.annotation.Toggleable; import dev.plex.listener.annotation.Toggleable;
import dev.plex.util.PlexLog; import dev.plex.util.PlexLog;
import dev.plex.util.ReflectionsUtil; import dev.plex.util.ReflectionsUtil;
import java.lang.reflect.InvocationTargetException; import java.lang.reflect.InvocationTargetException;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;

View File

@ -0,0 +1,63 @@
package dev.plex.hook;
import dev.plex.Plex;
import dev.plex.player.PlexPlayer;
import dev.plex.util.PlexLog;
import dev.plex.util.PlexUtils;
import dev.plex.util.minimessage.SafeMiniMessage;
import net.coreprotect.CoreProtect;
import net.coreprotect.CoreProtectAPI;
import net.kyori.adventure.text.Component;
import net.milkbowl.vault.chat.Chat;
import net.milkbowl.vault.permission.Permission;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.RegisteredServiceProvider;
import java.util.UUID;
public class CoreProtectHook
{
private CoreProtectAPI coreProtectAPI;
private boolean hasApi;
public CoreProtectHook(Plex plex)
{
Plugin plugin = plex.getServer().getPluginManager().getPlugin("CoreProtect");
// Check that CoreProtect is loaded
if (!(plugin instanceof CoreProtect))
{
PlexLog.debug("Plugin was not CoreProtect.");
return;
}
// Check that the API is enabled
CoreProtectAPI coreProtectAPI = ((CoreProtect) plugin).getAPI();
this.hasApi = coreProtectAPI.isEnabled();
if (!hasApi)
{
PlexLog.debug("CoreProtect API was disabled.");
return;
}
// Check that a compatible version of the API is loaded
if (coreProtectAPI.APIVersion() < 9)
{
PlexLog.debug("CoreProtect API version is: {0}", coreProtectAPI.APIVersion());
return;
}
this.coreProtectAPI = coreProtectAPI;
this.coreProtectAPI.testAPI();
}
public boolean hasCoreProtect() {
return hasApi;
}
public CoreProtectAPI coreProtectAPI()
{
return coreProtectAPI;
}
}

View File

@ -0,0 +1,34 @@
package dev.plex.hook;
import dev.plex.Plex;
import network.darkhelmet.prism.api.PrismApi;
import org.bukkit.plugin.Plugin;
public class PrismHook
{
private PrismApi prismApi;
public PrismHook(Plex plex)
{
Plugin plugin = plex.getServer().getPluginManager().getPlugin("Prism");
// Check that Prism is loaded
if (!plugin.isEnabled())
{
return;
}
// Check that the API is enabled
this.prismApi = (PrismApi) plugin;
}
public boolean hasPrism() {
return prismApi != null;
}
public PrismApi prismApi()
{
return prismApi;
}
}

View File

@ -1,10 +1,18 @@
package dev.plex.hook; package dev.plex.hook;
import dev.plex.player.PlexPlayer;
import dev.plex.util.PlexLog;
import dev.plex.util.PlexUtils;
import dev.plex.util.minimessage.SafeMiniMessage;
import net.kyori.adventure.text.Component;
import net.milkbowl.vault.chat.Chat; import net.milkbowl.vault.chat.Chat;
import net.milkbowl.vault.permission.Permission; import net.milkbowl.vault.permission.Permission;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import org.bukkit.plugin.RegisteredServiceProvider; import org.bukkit.plugin.RegisteredServiceProvider;
import java.util.UUID;
public class VaultHook public class VaultHook
{ {
private static Chat CHAT; private static Chat CHAT;
@ -46,6 +54,38 @@ public class VaultHook
return PERMISSIONS; return PERMISSIONS;
} }
public static Component getPrefix(UUID uuid)
{
return getPrefix(Bukkit.getOfflinePlayer(uuid));
}
public static Component getPrefix(PlexPlayer plexPlayer)
{
return getPrefix(Bukkit.getOfflinePlayer(plexPlayer.getUuid()));
}
public static Component getPrefix(OfflinePlayer player)
{
if (VaultHook.getChat() == null || VaultHook.getPermission() == null)
{
return Component.empty();
}
if (PlexUtils.DEVELOPERS.contains(player.getUniqueId().toString()))
{
return PlexUtils.mmDeserialize("<dark_gray>[<dark_purple>Developer<dark_gray>]");
}
String group = VaultHook.getPermission().getPrimaryGroup(null, player);
if (group == null || group.isEmpty()) {
return Component.empty();
}
String vaultPrefix = VaultHook.getChat().getGroupPrefix((String) null, group);
if (vaultPrefix == null || vaultPrefix.isEmpty()) {
return Component.empty();
}
PlexLog.debug("prefix: {0}", SafeMiniMessage.mmSerializeWithoutEvents(PlexUtils.stringToComponent(vaultPrefix)).replace("<", "\\<"));
return PlexUtils.stringToComponent(vaultPrefix);
}
public static Permission getPermission() public static Permission getPermission()
{ {
return PERMISSIONS; return PERMISSIONS;

View File

@ -1,54 +0,0 @@
package dev.plex.listener.impl;
import dev.plex.cache.DataUtils;
import dev.plex.event.AdminAddEvent;
import dev.plex.event.AdminRemoveEvent;
import dev.plex.event.AdminSetRankEvent;
import dev.plex.listener.PlexListener;
import dev.plex.player.PlexPlayer;
import dev.plex.rank.enums.Rank;
import dev.plex.util.PlexUtils;
import org.bukkit.event.EventHandler;
import static dev.plex.util.PlexUtils.messageComponent;
public class AdminListener extends PlexListener
{
@EventHandler
public void onAdminAdd(AdminAddEvent event)
{
String userSender = event.getSender().getName();
PlexPlayer target = (PlexPlayer)event.getPlexPlayer();
if (target.getRankFromString().isAtLeast(Rank.ADMIN))
{
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
public void onAdminRemove(AdminRemoveEvent event)
{
String userSender = event.getSender().getName();
PlexPlayer target = (PlexPlayer)event.getPlexPlayer();
target.setAdminActive(false);
DataUtils.update(target);
PlexUtils.broadcast(messageComponent("adminRemoved", userSender, target.getName()));
}
@EventHandler
public void onAdminSetRank(AdminSetRankEvent event)
{
String userSender = event.getSender().getName();
PlexPlayer target = (PlexPlayer)event.getPlexPlayer();
Rank newRank = (Rank)event.getRank();
target.setRank(newRank.name().toLowerCase());
DataUtils.update(target);
PlexUtils.broadcast(messageComponent("adminSetRank", userSender, target.getName(), newRank.getReadable()));
}
}

Some files were not shown because too many files have changed in this diff Show More