From 6921bfabdb2d24a5e49dee73645e9c66f3771b3b Mon Sep 17 00:00:00 2001 From: Dev7ex <46531389+Dev7ex@users.noreply.github.com> Date: Sun, 13 Aug 2023 16:32:01 +0200 Subject: [PATCH] Initial commit --- .gitattributes | 2 + .gitignore | 236 ++++++ LICENSE | 674 ++++++++++++++++++ README.md | 2 + multiperms-api/multiperms-api-bukkit/pom.xml | 119 ++++ .../api/bukkit/MultiPermsBukkitApi.java | 10 + .../api/bukkit/event/MultiPermsListener.java | 38 + .../group/PermissionGroupCreateEvent.java | 35 + .../group/PermissionGroupDeleteEvent.java | 35 + .../event/group/PermissionGroupEditEvent.java | 36 + .../event/group/PermissionGroupEvent.java | 22 + .../event/user/PermissionUserEvent.java | 22 + .../user/PermissionUserGroupSetEvent.java | 34 + .../event/user/PermissionUserLoginEvent.java | 28 + .../event/user/PermissionUserLogoutEvent.java | 28 + .../api/bukkit/hook/BukkitPermissionHook.java | 18 + multiperms-api/multiperms-api-core/pom.xml | 21 + .../dev7ex/multiperms/api/MultiPermsApi.java | 25 + .../api/MultiPermsApiConfiguration.java | 17 + .../api/MultiPermsApiConfigurationEntry.java | 26 + .../multiperms/api/MultiPermsApiProvider.java | 24 + .../multiperms/api/group/PermissionGroup.java | 52 ++ .../group/PermissionGroupConfiguration.java | 40 ++ .../api/group/PermissionGroupProperty.java | 41 ++ .../api/group/PermissionGroupProvider.java | 45 ++ .../multiperms/api/hook/PermissionHook.java | 13 + .../api/hook/PermissionHookProvider.java | 17 + .../multiperms/api/user/PermissionUser.java | 53 ++ .../api/user/PermissionUserConfiguration.java | 28 + .../api/user/PermissionUserProperty.java | 27 + .../api/user/PermissionUserProvider.java | 32 + multiperms-api/pom.xml | 49 ++ multiperms-bukkit/pom.xml | 138 ++++ .../multiperms/MultiPermsConfiguration.java | 35 + .../dev7ex/multiperms/MultiPermsPlugin.java | 90 +++ .../multiperms/command/PermissionCommand.java | 63 ++ .../command/permission/GroupCommand.java | 66 ++ .../command/permission/HelpCommand.java | 28 + .../command/permission/ReloadCommand.java | 33 + .../command/permission/UserCommand.java | 74 ++ .../command/permission/group/AddCommand.java | 73 ++ .../permission/group/CreateCommand.java | 76 ++ .../permission/group/DeleteCommand.java | 71 ++ .../command/permission/group/EditCommand.java | 129 ++++ .../command/permission/group/ListCommand.java | 50 ++ .../permission/group/RemoveCommand.java | 85 +++ .../command/permission/user/AddCommand.java | 112 +++ .../command/permission/user/ClearCommand.java | 81 +++ .../command/permission/user/InfoCommand.java | 75 ++ .../permission/user/RemoveCommand.java | 118 +++ .../command/permission/user/SetCommand.java | 81 +++ .../com/dev7ex/multiperms/group/Group.java | 42 ++ .../multiperms/group/GroupConfiguration.java | 217 ++++++ .../multiperms/group/GroupPermissible.java | 33 + .../dev7ex/multiperms/group/GroupService.java | 203 ++++++ .../hook/DefaultPermissionHookProvider.java | 57 ++ .../multiperms/hook/MultiPermsHook.java | 34 + .../listener/PlayerChatListener.java | 42 ++ .../listener/PlayerConnectionListener.java | 73 ++ .../listener/ScoreboardListener.java | 57 ++ .../scoreboard/ScoreboardService.java | 71 ++ .../java/com/dev7ex/multiperms/user/User.java | 83 +++ .../multiperms/user/UserConfiguration.java | 190 +++++ .../dev7ex/multiperms/user/UserService.java | 157 ++++ .../src/main/resources/config.yml | 124 ++++ .../src/main/resources/language/de_DE.yml | 101 +++ .../src/main/resources/language/en_US.yml | 101 +++ .../src/main/resources/plugin.yml | 19 + pom.xml | 37 + 69 files changed, 4968 insertions(+) create mode 100644 .gitattributes create mode 100644 .gitignore create mode 100644 LICENSE create mode 100644 README.md create mode 100644 multiperms-api/multiperms-api-bukkit/pom.xml create mode 100644 multiperms-api/multiperms-api-bukkit/src/main/java/com/dev7ex/multiperms/api/bukkit/MultiPermsBukkitApi.java create mode 100644 multiperms-api/multiperms-api-bukkit/src/main/java/com/dev7ex/multiperms/api/bukkit/event/MultiPermsListener.java create mode 100644 multiperms-api/multiperms-api-bukkit/src/main/java/com/dev7ex/multiperms/api/bukkit/event/group/PermissionGroupCreateEvent.java create mode 100644 multiperms-api/multiperms-api-bukkit/src/main/java/com/dev7ex/multiperms/api/bukkit/event/group/PermissionGroupDeleteEvent.java create mode 100644 multiperms-api/multiperms-api-bukkit/src/main/java/com/dev7ex/multiperms/api/bukkit/event/group/PermissionGroupEditEvent.java create mode 100644 multiperms-api/multiperms-api-bukkit/src/main/java/com/dev7ex/multiperms/api/bukkit/event/group/PermissionGroupEvent.java create mode 100644 multiperms-api/multiperms-api-bukkit/src/main/java/com/dev7ex/multiperms/api/bukkit/event/user/PermissionUserEvent.java create mode 100644 multiperms-api/multiperms-api-bukkit/src/main/java/com/dev7ex/multiperms/api/bukkit/event/user/PermissionUserGroupSetEvent.java create mode 100644 multiperms-api/multiperms-api-bukkit/src/main/java/com/dev7ex/multiperms/api/bukkit/event/user/PermissionUserLoginEvent.java create mode 100644 multiperms-api/multiperms-api-bukkit/src/main/java/com/dev7ex/multiperms/api/bukkit/event/user/PermissionUserLogoutEvent.java create mode 100644 multiperms-api/multiperms-api-bukkit/src/main/java/com/dev7ex/multiperms/api/bukkit/hook/BukkitPermissionHook.java create mode 100644 multiperms-api/multiperms-api-core/pom.xml create mode 100644 multiperms-api/multiperms-api-core/src/main/java/com/dev7ex/multiperms/api/MultiPermsApi.java create mode 100644 multiperms-api/multiperms-api-core/src/main/java/com/dev7ex/multiperms/api/MultiPermsApiConfiguration.java create mode 100644 multiperms-api/multiperms-api-core/src/main/java/com/dev7ex/multiperms/api/MultiPermsApiConfigurationEntry.java create mode 100644 multiperms-api/multiperms-api-core/src/main/java/com/dev7ex/multiperms/api/MultiPermsApiProvider.java create mode 100644 multiperms-api/multiperms-api-core/src/main/java/com/dev7ex/multiperms/api/group/PermissionGroup.java create mode 100644 multiperms-api/multiperms-api-core/src/main/java/com/dev7ex/multiperms/api/group/PermissionGroupConfiguration.java create mode 100644 multiperms-api/multiperms-api-core/src/main/java/com/dev7ex/multiperms/api/group/PermissionGroupProperty.java create mode 100644 multiperms-api/multiperms-api-core/src/main/java/com/dev7ex/multiperms/api/group/PermissionGroupProvider.java create mode 100644 multiperms-api/multiperms-api-core/src/main/java/com/dev7ex/multiperms/api/hook/PermissionHook.java create mode 100644 multiperms-api/multiperms-api-core/src/main/java/com/dev7ex/multiperms/api/hook/PermissionHookProvider.java create mode 100644 multiperms-api/multiperms-api-core/src/main/java/com/dev7ex/multiperms/api/user/PermissionUser.java create mode 100644 multiperms-api/multiperms-api-core/src/main/java/com/dev7ex/multiperms/api/user/PermissionUserConfiguration.java create mode 100644 multiperms-api/multiperms-api-core/src/main/java/com/dev7ex/multiperms/api/user/PermissionUserProperty.java create mode 100644 multiperms-api/multiperms-api-core/src/main/java/com/dev7ex/multiperms/api/user/PermissionUserProvider.java create mode 100644 multiperms-api/pom.xml create mode 100644 multiperms-bukkit/pom.xml create mode 100644 multiperms-bukkit/src/main/java/com/dev7ex/multiperms/MultiPermsConfiguration.java create mode 100644 multiperms-bukkit/src/main/java/com/dev7ex/multiperms/MultiPermsPlugin.java create mode 100644 multiperms-bukkit/src/main/java/com/dev7ex/multiperms/command/PermissionCommand.java create mode 100644 multiperms-bukkit/src/main/java/com/dev7ex/multiperms/command/permission/GroupCommand.java create mode 100644 multiperms-bukkit/src/main/java/com/dev7ex/multiperms/command/permission/HelpCommand.java create mode 100644 multiperms-bukkit/src/main/java/com/dev7ex/multiperms/command/permission/ReloadCommand.java create mode 100644 multiperms-bukkit/src/main/java/com/dev7ex/multiperms/command/permission/UserCommand.java create mode 100644 multiperms-bukkit/src/main/java/com/dev7ex/multiperms/command/permission/group/AddCommand.java create mode 100644 multiperms-bukkit/src/main/java/com/dev7ex/multiperms/command/permission/group/CreateCommand.java create mode 100644 multiperms-bukkit/src/main/java/com/dev7ex/multiperms/command/permission/group/DeleteCommand.java create mode 100644 multiperms-bukkit/src/main/java/com/dev7ex/multiperms/command/permission/group/EditCommand.java create mode 100644 multiperms-bukkit/src/main/java/com/dev7ex/multiperms/command/permission/group/ListCommand.java create mode 100644 multiperms-bukkit/src/main/java/com/dev7ex/multiperms/command/permission/group/RemoveCommand.java create mode 100644 multiperms-bukkit/src/main/java/com/dev7ex/multiperms/command/permission/user/AddCommand.java create mode 100644 multiperms-bukkit/src/main/java/com/dev7ex/multiperms/command/permission/user/ClearCommand.java create mode 100644 multiperms-bukkit/src/main/java/com/dev7ex/multiperms/command/permission/user/InfoCommand.java create mode 100644 multiperms-bukkit/src/main/java/com/dev7ex/multiperms/command/permission/user/RemoveCommand.java create mode 100644 multiperms-bukkit/src/main/java/com/dev7ex/multiperms/command/permission/user/SetCommand.java create mode 100644 multiperms-bukkit/src/main/java/com/dev7ex/multiperms/group/Group.java create mode 100644 multiperms-bukkit/src/main/java/com/dev7ex/multiperms/group/GroupConfiguration.java create mode 100644 multiperms-bukkit/src/main/java/com/dev7ex/multiperms/group/GroupPermissible.java create mode 100644 multiperms-bukkit/src/main/java/com/dev7ex/multiperms/group/GroupService.java create mode 100644 multiperms-bukkit/src/main/java/com/dev7ex/multiperms/hook/DefaultPermissionHookProvider.java create mode 100644 multiperms-bukkit/src/main/java/com/dev7ex/multiperms/hook/MultiPermsHook.java create mode 100644 multiperms-bukkit/src/main/java/com/dev7ex/multiperms/listener/PlayerChatListener.java create mode 100644 multiperms-bukkit/src/main/java/com/dev7ex/multiperms/listener/PlayerConnectionListener.java create mode 100644 multiperms-bukkit/src/main/java/com/dev7ex/multiperms/listener/ScoreboardListener.java create mode 100644 multiperms-bukkit/src/main/java/com/dev7ex/multiperms/scoreboard/ScoreboardService.java create mode 100644 multiperms-bukkit/src/main/java/com/dev7ex/multiperms/user/User.java create mode 100644 multiperms-bukkit/src/main/java/com/dev7ex/multiperms/user/UserConfiguration.java create mode 100644 multiperms-bukkit/src/main/java/com/dev7ex/multiperms/user/UserService.java create mode 100644 multiperms-bukkit/src/main/resources/config.yml create mode 100644 multiperms-bukkit/src/main/resources/language/de_DE.yml create mode 100644 multiperms-bukkit/src/main/resources/language/en_US.yml create mode 100644 multiperms-bukkit/src/main/resources/plugin.yml create mode 100644 pom.xml diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..dfe0770 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,2 @@ +# Auto detect text files and perform LF normalization +* text=auto diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..3d5c15a --- /dev/null +++ b/.gitignore @@ -0,0 +1,236 @@ + +# Created by https://www.toptal.com/developers/gitignore/api/intellij+all,git,maven,windows,linux,macos,vscode,netbeans,java,ssh +# Edit at https://www.toptal.com/developers/gitignore?templates=intellij+all,git,maven,windows,linux,macos,vscode,netbeans,java,ssh + +### Git ### +# Created by git for backups. To disable backups in Git: +# $ git config --global mergetool.keepBackup false +*.orig + +# Created by git when using merge tools for conflicts +*.BACKUP.* +*.BASE.* +*.LOCAL.* +*.REMOTE.* +*_BACKUP_*.txt +*_BASE_*.txt +*_LOCAL_*.txt +*_REMOTE_*.txt + +### Intellij+all ### +# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider +# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 + +# User-specific stuff +.idea/**/workspace.xml +.idea/**/tasks.xml +.idea/**/usage.statistics.xml +.idea/**/dictionaries +.idea/**/shelf + +# Generated files +.idea/**/contentModel.xml + +# Sensitive or high-churn files +.idea/**/dataSources/ +.idea/**/dataSources.ids +.idea/**/dataSources.local.xml +.idea/**/sqlDataSources.xml +.idea/**/dynamic.xml +.idea/**/uiDesigner.xml +.idea/**/dbnavigator.xml + +# Gradle +.idea/**/gradle.xml +.idea/**/libraries + +# Gradle and Maven with auto-import +# When using Gradle or Maven with auto-import, you should exclude module files, +# since they will be recreated, and may cause churn. Uncomment if using +# auto-import. +# .idea/artifacts +# .idea/compiler.xml +# .idea/jarRepositories.xml +# .idea/modules.xml +# .idea/*.iml +# .idea/modules +# *.iml +# *.ipr + +# CMake +cmake-build-*/ + +# Mongo Explorer plugin +.idea/**/mongoSettings.xml + +# File-based project format +*.iws + +# IntelliJ +out/ + +# mpeltonen/sbt-idea plugin +.idea_modules/ + +# JIRA plugin +atlassian-ide-plugin.xml + +# Cursive Clojure plugin +.idea/replstate.xml + +# Crashlytics plugin (for Android Studio and IntelliJ) +com_crashlytics_export_strings.xml +crashlytics.properties +crashlytics-build.properties +fabric.properties + +# Editor-based Rest Client +.idea/httpRequests + +# Android studio 3.1+ serialized cache file +.idea/caches/build_file_checksums.ser + +### Intellij+all Patch ### +# Ignores the whole .idea folder and all .iml files +# See https://github.com/joeblau/gitignore.io/issues/186 and https://github.com/joeblau/gitignore.io/issues/360 + +.idea/ + +# Reason: https://github.com/joeblau/gitignore.io/issues/186#issuecomment-249601023 + +*.iml +modules.xml +.idea/misc.xml +*.ipr + +# Sonarlint plugin +.idea/sonarlint + +### Java ### +# Compiled class file +*.class + +# Log file +*.log + +# BlueJ files +*.ctxt + +# Mobile Tools for Java (J2ME) +.mtj.tmp/ + +# Package Files # +*.jar +*.war +*.nar +*.ear +*.zip +*.tar.gz +*.rar + +# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml +hs_err_pid* + +### Linux ### +*~ + +# temporary files which can be created if a process still has a handle open of a deleted file +.fuse_hidden* + +# KDE directory preferences +.directory + +# Linux trash folder which might appear on any partition or disk +.Trash-* + +# .nfs files are created when an open file is removed but is still being accessed +.nfs* + +### macOS ### +# General +.DS_Store +.AppleDouble +.LSOverride + +# Icon must end with two \r +Icon + + +# Thumbnails +._* + +# Files that might appear in the root of a volume +.DocumentRevisions-V100 +.fseventsd +.Spotlight-V100 +.TemporaryItems +.Trashes +.VolumeIcon.icns +.com.apple.timemachine.donotpresent + +# Directories potentially created on remote AFP share +.AppleDB +.AppleDesktop +Network Trash Folder +Temporary Items +.apdisk + +### Maven ### +target/ +pom.xml.tag +pom.xml.releaseBackup +pom.xml.versionsBackup +pom.xml.next +release.properties +dependency-reduced-pom.xml +buildNumber.properties +.mvn/timing.properties +# https://github.com/takari/maven-wrapper#usage-without-binary-jar +.mvn/wrapper/maven-wrapper.jar +.flattened-pom.xml + +### NetBeans ### +**/nbproject/private/ +**/nbproject/Makefile-*.mk +**/nbproject/Package-*.bash +build/ +nbbuild/ +dist/ +nbdist/ +.nb-gradle/ + +### SSH ### +**/.ssh/id_* +**/.ssh/*_id_* +**/.ssh/known_hosts + +#!! ERROR: vscode is undefined. Use list command to see defined gitignore types !!# + +### Windows ### +# Windows thumbnail cache files +Thumbs.db +Thumbs.db:encryptable +ehthumbs.db +ehthumbs_vista.db + +# Dump file +*.stackdump + +# Folder config file +[Dd]esktop.ini + +# Recycle Bin used on file shares +$RECYCLE.BIN/ + +# Windows Installer files +*.cab +*.msi +*.msix +*.msm +*.msp + +# Windows shortcuts +*.lnk + +# End of https://www.toptal.com/developers/gitignore/api/intellij+all,git,maven,windows,linux,macos,vscode,netbeans,java,ssh +dependency-reduced-pom.xml diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..e62ec04 --- /dev/null +++ b/LICENSE @@ -0,0 +1,674 @@ +GNU GENERAL PUBLIC LICENSE + Version 3, 29 June 2007 + + Copyright (C) 2007 Free Software Foundation, Inc. + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The GNU General Public License is a free, copyleft license for +software and other kinds of works. + + The licenses for most software and other practical works are designed +to take away your freedom to share and change the works. By contrast, +the GNU General Public License is intended to guarantee your freedom to +share and change all versions of a program--to make sure it remains free +software for all its users. We, the Free Software Foundation, use the +GNU General Public License for most of our software; it applies also to +any other work released this way by its authors. You can apply it to +your programs, too. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +them if you wish), that you receive source code or can get it if you +want it, that you can change the software or use pieces of it in new +free programs, and that you know you can do these things. + + To protect your rights, we need to prevent others from denying you +these rights or asking you to surrender the rights. Therefore, you have +certain responsibilities if you distribute copies of the software, or if +you modify it: responsibilities to respect the freedom of others. + + For example, if you distribute copies of such a program, whether +gratis or for a fee, you must pass on to the recipients the same +freedoms that you received. You must make sure that they, too, receive +or can get the source code. And you must show them these terms so they +know their rights. + + Developers that use the GNU GPL protect your rights with two steps: +(1) assert copyright on the software, and (2) offer you this License +giving you legal permission to copy, distribute and/or modify it. + + For the developers' and authors' protection, the GPL clearly explains +that there is no warranty for this free software. For both users' and +authors' sake, the GPL requires that modified versions be marked as +changed, so that their problems will not be attributed erroneously to +authors of previous versions. + + Some devices are designed to deny users access to install or run +modified versions of the software inside them, although the manufacturer +can do so. This is fundamentally incompatible with the aim of +protecting users' freedom to change the software. The systematic +pattern of such abuse occurs in the area of products for individuals to +use, which is precisely where it is most unacceptable. Therefore, we +have designed this version of the GPL to prohibit the practice for those +products. If such problems arise substantially in other domains, we +stand ready to extend this provision to those domains in future versions +of the GPL, as needed to protect the freedom of users. + + Finally, every program is threatened constantly by software patents. +States should not allow patents to restrict development and use of +software on general-purpose computers, but in those that do, we wish to +avoid the special danger that patents applied to a free program could +make it effectively proprietary. To prevent this, the GPL assures that +patents cannot be used to render the program non-free. + + The precise terms and conditions for copying, distribution and +modification follow. + + TERMS AND CONDITIONS + + 0. Definitions. + + "This License" refers to version 3 of the GNU General Public License. + + "Copyright" also means copyright-like laws that apply to other kinds of +works, such as semiconductor masks. + + "The Program" refers to any copyrightable work licensed under this +License. Each licensee is addressed as "you". "Licensees" and +"recipients" may be individuals or organizations. + + To "modify" a work means to copy from or adapt all or part of the work +in a fashion requiring copyright permission, other than the making of an +exact copy. The resulting work is called a "modified version" of the +earlier work or a work "based on" the earlier work. + + A "covered work" means either the unmodified Program or a work based +on the Program. + + To "propagate" a work means to do anything with it that, without +permission, would make you directly or secondarily liable for +infringement under applicable copyright law, except executing it on a +computer or modifying a private copy. Propagation includes copying, +distribution (with or without modification), making available to the +public, and in some countries other activities as well. + + To "convey" a work means any kind of propagation that enables other +parties to make or receive copies. Mere interaction with a user through +a computer network, with no transfer of a copy, is not conveying. + + An interactive user interface displays "Appropriate Legal Notices" +to the extent that it includes a convenient and prominently visible +feature that (1) displays an appropriate copyright notice, and (2) +tells the user that there is no warranty for the work (except to the +extent that warranties are provided), that licensees may convey the +work under this License, and how to view a copy of this License. If +the interface presents a list of user commands or options, such as a +menu, a prominent item in the list meets this criterion. + + 1. Source Code. + + The "source code" for a work means the preferred form of the work +for making modifications to it. "Object code" means any non-source +form of a work. + + A "Standard Interface" means an interface that either is an official +standard defined by a recognized standards body, or, in the case of +interfaces specified for a particular programming language, one that +is widely used among developers working in that language. + + The "System Libraries" of an executable work include anything, other +than the work as a whole, that (a) is included in the normal form of +packaging a Major Component, but which is not part of that Major +Component, and (b) serves only to enable use of the work with that +Major Component, or to implement a Standard Interface for which an +implementation is available to the public in source code form. A +"Major Component", in this context, means a major essential component +(kernel, window system, and so on) of the specific operating system +(if any) on which the executable work runs, or a compiler used to +produce the work, or an object code interpreter used to run it. + + The "Corresponding Source" for a work in object code form means all +the source code needed to generate, install, and (for an executable +work) run the object code and to modify the work, including scripts to +control those activities. However, it does not include the work's +System Libraries, or general-purpose tools or generally available free +programs which are used unmodified in performing those activities but +which are not part of the work. For example, Corresponding Source +includes interface definition files associated with source files for +the work, and the source code for shared libraries and dynamically +linked subprograms that the work is specifically designed to require, +such as by intimate data communication or control flow between those +subprograms and other parts of the work. + + The Corresponding Source need not include anything that users +can regenerate automatically from other parts of the Corresponding +Source. + + The Corresponding Source for a work in source code form is that +same work. + + 2. Basic Permissions. + + All rights granted under this License are granted for the term of +copyright on the Program, and are irrevocable provided the stated +conditions are met. This License explicitly affirms your unlimited +permission to run the unmodified Program. The output from running a +covered work is covered by this License only if the output, given its +content, constitutes a covered work. This License acknowledges your +rights of fair use or other equivalent, as provided by copyright law. + + You may make, run and propagate covered works that you do not +convey, without conditions so long as your license otherwise remains +in force. You may convey covered works to others for the sole purpose +of having them make modifications exclusively for you, or provide you +with facilities for running those works, provided that you comply with +the terms of this License in conveying all material for which you do +not control copyright. Those thus making or running the covered works +for you must do so exclusively on your behalf, under your direction +and control, on terms that prohibit them from making any copies of +your copyrighted material outside their relationship with you. + + Conveying under any other circumstances is permitted solely under +the conditions stated below. Sublicensing is not allowed; section 10 +makes it unnecessary. + + 3. Protecting Users' Legal Rights From Anti-Circumvention Law. + + No covered work shall be deemed part of an effective technological +measure under any applicable law fulfilling obligations under article +11 of the WIPO copyright treaty adopted on 20 December 1996, or +similar laws prohibiting or restricting circumvention of such +measures. + + When you convey a covered work, you waive any legal power to forbid +circumvention of technological measures to the extent such circumvention +is effected by exercising rights under this License with respect to +the covered work, and you disclaim any intention to limit operation or +modification of the work as a means of enforcing, against the work's +users, your or third parties' legal rights to forbid circumvention of +technological measures. + + 4. Conveying Verbatim Copies. + + You may convey verbatim copies of the Program's source code as you +receive it, in any medium, provided that you conspicuously and +appropriately publish on each copy an appropriate copyright notice; +keep intact all notices stating that this License and any +non-permissive terms added in accord with section 7 apply to the code; +keep intact all notices of the absence of any warranty; and give all +recipients a copy of this License along with the Program. + + You may charge any price or no price for each copy that you convey, +and you may offer support or warranty protection for a fee. + + 5. Conveying Modified Source Versions. + + You may convey a work based on the Program, or the modifications to +produce it from the Program, in the form of source code under the +terms of section 4, provided that you also meet all of these conditions: + + a) The work must carry prominent notices stating that you modified + it, and giving a relevant date. + + b) The work must carry prominent notices stating that it is + released under this License and any conditions added under section + 7. This requirement modifies the requirement in section 4 to + "keep intact all notices". + + c) You must license the entire work, as a whole, under this + License to anyone who comes into possession of a copy. This + License will therefore apply, along with any applicable section 7 + additional terms, to the whole of the work, and all its parts, + regardless of how they are packaged. This License gives no + permission to license the work in any other way, but it does not + invalidate such permission if you have separately received it. + + d) If the work has interactive user interfaces, each must display + Appropriate Legal Notices; however, if the Program has interactive + interfaces that do not display Appropriate Legal Notices, your + work need not make them do so. + + A compilation of a covered work with other separate and independent +works, which are not by their nature extensions of the covered work, +and which are not combined with it such as to form a larger program, +in or on a volume of a storage or distribution medium, is called an +"aggregate" if the compilation and its resulting copyright are not +used to limit the access or legal rights of the compilation's users +beyond what the individual works permit. Inclusion of a covered work +in an aggregate does not cause this License to apply to the other +parts of the aggregate. + + 6. Conveying Non-Source Forms. + + You may convey a covered work in object code form under the terms +of sections 4 and 5, provided that you also convey the +machine-readable Corresponding Source under the terms of this License, +in one of these ways: + + a) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by the + Corresponding Source fixed on a durable physical medium + customarily used for software interchange. + + b) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by a + written offer, valid for at least three years and valid for as + long as you offer spare parts or customer support for that product + model, to give anyone who possesses the object code either (1) a + copy of the Corresponding Source for all the software in the + product that is covered by this License, on a durable physical + medium customarily used for software interchange, for a price no + more than your reasonable cost of physically performing this + conveying of source, or (2) access to copy the + Corresponding Source from a network server at no charge. + + c) Convey individual copies of the object code with a copy of the + written offer to provide the Corresponding Source. This + alternative is allowed only occasionally and noncommercially, and + only if you received the object code with such an offer, in accord + with subsection 6b. + + d) Convey the object code by offering access from a designated + place (gratis or for a charge), and offer equivalent access to the + Corresponding Source in the same way through the same place at no + further charge. You need not require recipients to copy the + Corresponding Source along with the object code. If the place to + copy the object code is a network server, the Corresponding Source + may be on a different server (operated by you or a third party) + that supports equivalent copying facilities, provided you maintain + clear directions next to the object code saying where to find the + Corresponding Source. Regardless of what server hosts the + Corresponding Source, you remain obligated to ensure that it is + available for as long as needed to satisfy these requirements. + + e) Convey the object code using peer-to-peer transmission, provided + you inform other peers where the object code and Corresponding + Source of the work are being offered to the general public at no + charge under subsection 6d. + + A separable portion of the object code, whose source code is excluded +from the Corresponding Source as a System Library, need not be +included in conveying the object code work. + + A "User Product" is either (1) a "consumer product", which means any +tangible personal property which is normally used for personal, family, +or household purposes, or (2) anything designed or sold for incorporation +into a dwelling. In determining whether a product is a consumer product, +doubtful cases shall be resolved in favor of coverage. For a particular +product received by a particular user, "normally used" refers to a +typical or common use of that class of product, regardless of the status +of the particular user or of the way in which the particular user +actually uses, or expects or is expected to use, the product. A product +is a consumer product regardless of whether the product has substantial +commercial, industrial or non-consumer uses, unless such uses represent +the only significant mode of use of the product. + + "Installation Information" for a User Product means any methods, +procedures, authorization keys, or other information required to install +and execute modified versions of a covered work in that User Product from +a modified version of its Corresponding Source. The information must +suffice to ensure that the continued functioning of the modified object +code is in no case prevented or interfered with solely because +modification has been made. + + If you convey an object code work under this section in, or with, or +specifically for use in, a User Product, and the conveying occurs as +part of a transaction in which the right of possession and use of the +User Product is transferred to the recipient in perpetuity or for a +fixed term (regardless of how the transaction is characterized), the +Corresponding Source conveyed under this section must be accompanied +by the Installation Information. But this requirement does not apply +if neither you nor any third party retains the ability to install +modified object code on the User Product (for example, the work has +been installed in ROM). + + The requirement to provide Installation Information does not include a +requirement to continue to provide support service, warranty, or updates +for a work that has been modified or installed by the recipient, or for +the User Product in which it has been modified or installed. Access to a +network may be denied when the modification itself materially and +adversely affects the operation of the network or violates the rules and +protocols for communication across the network. + + Corresponding Source conveyed, and Installation Information provided, +in accord with this section must be in a format that is publicly +documented (and with an implementation available to the public in +source code form), and must require no special password or key for +unpacking, reading or copying. + + 7. Additional Terms. + + "Additional permissions" are terms that supplement the terms of this +License by making exceptions from one or more of its conditions. +Additional permissions that are applicable to the entire Program shall +be treated as though they were included in this License, to the extent +that they are valid under applicable law. If additional permissions +apply only to part of the Program, that part may be used separately +under those permissions, but the entire Program remains governed by +this License without regard to the additional permissions. + + When you convey a copy of a covered work, you may at your option +remove any additional permissions from that copy, or from any part of +it. (Additional permissions may be written to require their own +removal in certain cases when you modify the work.) You may place +additional permissions on material, added by you to a covered work, +for which you have or can give appropriate copyright permission. + + Notwithstanding any other provision of this License, for material you +add to a covered work, you may (if authorized by the copyright holders of +that material) supplement the terms of this License with terms: + + a) Disclaiming warranty or limiting liability differently from the + terms of sections 15 and 16 of this License; or + + b) Requiring preservation of specified reasonable legal notices or + author attributions in that material or in the Appropriate Legal + Notices displayed by works containing it; or + + c) Prohibiting misrepresentation of the origin of that material, or + requiring that modified versions of such material be marked in + reasonable ways as different from the original version; or + + d) Limiting the use for publicity purposes of names of licensors or + authors of the material; or + + e) Declining to grant rights under trademark law for use of some + trade names, trademarks, or service marks; or + + f) Requiring indemnification of licensors and authors of that + material by anyone who conveys the material (or modified versions of + it) with contractual assumptions of liability to the recipient, for + any liability that these contractual assumptions directly impose on + those licensors and authors. + + All other non-permissive additional terms are considered "further +restrictions" within the meaning of section 10. If the Program as you +received it, or any part of it, contains a notice stating that it is +governed by this License along with a term that is a further +restriction, you may remove that term. If a license document contains +a further restriction but permits relicensing or conveying under this +License, you may add to a covered work material governed by the terms +of that license document, provided that the further restriction does +not survive such relicensing or conveying. + + If you add terms to a covered work in accord with this section, you +must place, in the relevant source files, a statement of the +additional terms that apply to those files, or a notice indicating +where to find the applicable terms. + + Additional terms, permissive or non-permissive, may be stated in the +form of a separately written license, or stated as exceptions; +the above requirements apply either way. + + 8. Termination. + + You may not propagate or modify a covered work except as expressly +provided under this License. Any attempt otherwise to propagate or +modify it is void, and will automatically terminate your rights under +this License (including any patent licenses granted under the third +paragraph of section 11). + + However, if you cease all violation of this License, then your +license from a particular copyright holder is reinstated (a) +provisionally, unless and until the copyright holder explicitly and +finally terminates your license, and (b) permanently, if the copyright +holder fails to notify you of the violation by some reasonable means +prior to 60 days after the cessation. + + Moreover, your license from a particular copyright holder is +reinstated permanently if the copyright holder notifies you of the +violation by some reasonable means, this is the first time you have +received notice of violation of this License (for any work) from that +copyright holder, and you cure the violation prior to 30 days after +your receipt of the notice. + + Termination of your rights under this section does not terminate the +licenses of parties who have received copies or rights from you under +this License. If your rights have been terminated and not permanently +reinstated, you do not qualify to receive new licenses for the same +material under section 10. + + 9. Acceptance Not Required for Having Copies. + + You are not required to accept this License in order to receive or +run a copy of the Program. Ancillary propagation of a covered work +occurring solely as a consequence of using peer-to-peer transmission +to receive a copy likewise does not require acceptance. However, +nothing other than this License grants you permission to propagate or +modify any covered work. These actions infringe copyright if you do +not accept this License. Therefore, by modifying or propagating a +covered work, you indicate your acceptance of this License to do so. + + 10. Automatic Licensing of Downstream Recipients. + + Each time you convey a covered work, the recipient automatically +receives a license from the original licensors, to run, modify and +propagate that work, subject to this License. You are not responsible +for enforcing compliance by third parties with this License. + + An "entity transaction" is a transaction transferring control of an +organization, or substantially all assets of one, or subdividing an +organization, or merging organizations. If propagation of a covered +work results from an entity transaction, each party to that +transaction who receives a copy of the work also receives whatever +licenses to the work the party's predecessor in interest had or could +give under the previous paragraph, plus a right to possession of the +Corresponding Source of the work from the predecessor in interest, if +the predecessor has it or can get it with reasonable efforts. + + You may not impose any further restrictions on the exercise of the +rights granted or affirmed under this License. For example, you may +not impose a license fee, royalty, or other charge for exercise of +rights granted under this License, and you may not initiate litigation +(including a cross-claim or counterclaim in a lawsuit) alleging that +any patent claim is infringed by making, using, selling, offering for +sale, or importing the Program or any portion of it. + + 11. Patents. + + A "contributor" is a copyright holder who authorizes use under this +License of the Program or a work on which the Program is based. The +work thus licensed is called the contributor's "contributor version". + + A contributor's "essential patent claims" are all patent claims +owned or controlled by the contributor, whether already acquired or +hereafter acquired, that would be infringed by some manner, permitted +by this License, of making, using, or selling its contributor version, +but do not include claims that would be infringed only as a +consequence of further modification of the contributor version. For +purposes of this definition, "control" includes the right to grant +patent sublicenses in a manner consistent with the requirements of +this License. + + Each contributor grants you a non-exclusive, worldwide, royalty-free +patent license under the contributor's essential patent claims, to +make, use, sell, offer for sale, import and otherwise run, modify and +propagate the contents of its contributor version. + + In the following three paragraphs, a "patent license" is any express +agreement or commitment, however denominated, not to enforce a patent +(such as an express permission to practice a patent or covenant not to +sue for patent infringement). To "grant" such a patent license to a +party means to make such an agreement or commitment not to enforce a +patent against the party. + + If you convey a covered work, knowingly relying on a patent license, +and the Corresponding Source of the work is not available for anyone +to copy, free of charge and under the terms of this License, through a +publicly available network server or other readily accessible means, +then you must either (1) cause the Corresponding Source to be so +available, or (2) arrange to deprive yourself of the benefit of the +patent license for this particular work, or (3) arrange, in a manner +consistent with the requirements of this License, to extend the patent +license to downstream recipients. "Knowingly relying" means you have +actual knowledge that, but for the patent license, your conveying the +covered work in a country, or your recipient's use of the covered work +in a country, would infringe one or more identifiable patents in that +country that you have reason to believe are valid. + + If, pursuant to or in connection with a single transaction or +arrangement, you convey, or propagate by procuring conveyance of, a +covered work, and grant a patent license to some of the parties +receiving the covered work authorizing them to use, propagate, modify +or convey a specific copy of the covered work, then the patent license +you grant is automatically extended to all recipients of the covered +work and works based on it. + + A patent license is "discriminatory" if it does not include within +the scope of its coverage, prohibits the exercise of, or is +conditioned on the non-exercise of one or more of the rights that are +specifically granted under this License. You may not convey a covered +work if you are a party to an arrangement with a third party that is +in the business of distributing software, under which you make payment +to the third party based on the extent of your activity of conveying +the work, and under which the third party grants, to any of the +parties who would receive the covered work from you, a discriminatory +patent license (a) in connection with copies of the covered work +conveyed by you (or copies made from those copies), or (b) primarily +for and in connection with specific products or compilations that +contain the covered work, unless you entered into that arrangement, +or that patent license was granted, prior to 28 March 2007. + + Nothing in this License shall be construed as excluding or limiting +any implied license or other defenses to infringement that may +otherwise be available to you under applicable patent law. + + 12. No Surrender of Others' Freedom. + + If conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot convey a +covered work so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you may +not convey it at all. For example, if you agree to terms that obligate you +to collect a royalty for further conveying from those to whom you convey +the Program, the only way you could satisfy both those terms and this +License would be to refrain entirely from conveying the Program. + + 13. Use with the GNU Affero General Public License. + + Notwithstanding any other provision of this License, you have +permission to link or combine any covered work with a work licensed +under version 3 of the GNU Affero General Public License into a single +combined work, and to convey the resulting work. The terms of this +License will continue to apply to the part which is the covered work, +but the special requirements of the GNU Affero General Public License, +section 13, concerning interaction through a network will apply to the +combination as such. + + 14. Revised Versions of this License. + + The Free Software Foundation may publish revised and/or new versions of +the GNU General Public License from time to time. Such new versions will +be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + + Each version is given a distinguishing version number. If the +Program specifies that a certain numbered version of the GNU General +Public License "or any later version" applies to it, you have the +option of following the terms and conditions either of that numbered +version or of any later version published by the Free Software +Foundation. If the Program does not specify a version number of the +GNU General Public License, you may choose any version ever published +by the Free Software Foundation. + + If the Program specifies that a proxy can decide which future +versions of the GNU General Public License can be used, that proxy's +public statement of acceptance of a version permanently authorizes you +to choose that version for the Program. + + Later license versions may give you additional or different +permissions. However, no additional obligations are imposed on any +author or copyright holder as a result of your choosing to follow a +later version. + + 15. Disclaimer of Warranty. + + THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY +APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT +HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY +OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, +THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM +IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF +ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + + 16. Limitation of Liability. + + IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS +THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY +GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE +USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF +DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD +PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), +EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF +SUCH DAMAGES. + + 17. Interpretation of Sections 15 and 16. + + If the disclaimer of warranty and limitation of liability provided +above cannot be given local legal effect according to their terms, +reviewing courts shall apply local law that most closely approximates +an absolute waiver of all civil liability in connection with the +Program, unless a warranty or assumption of liability accompanies a +copy of the Program in return for a fee. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Programs + + If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these terms. + + To do so, attach the following notices to the program. It is safest +to attach them to the start of each source file to most effectively +state the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + + Copyright (C) + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + +Also add information on how to contact you by electronic and paper mail. + + If the program does terminal interaction, make it output a short +notice like this when it starts in an interactive mode: + + Copyright (C) + This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. + This is free software, and you are welcome to redistribute it + under certain conditions; type `show c' for details. + +The hypothetical commands `show w' and `show c' should show the appropriate +parts of the General Public License. Of course, your program's commands +might be different; for a GUI interface, you would use an "about box". + + You should also get your employer (if you work as a programmer) or school, +if any, to sign a "copyright disclaimer" for the program, if necessary. +For more information on this, and how to apply and follow the GNU GPL, see +. + + The GNU General Public License does not permit incorporating your program +into proprietary programs. If your program is a subroutine library, you +may consider it more useful to permit linking proprietary applications with +the library. If this is what you want to do, use the GNU Lesser General +Public License instead of this License. But first, please read +. diff --git a/README.md b/README.md new file mode 100644 index 0000000..7970cd1 --- /dev/null +++ b/README.md @@ -0,0 +1,2 @@ +# MultiPerms + Permission Mangement for Minecraft diff --git a/multiperms-api/multiperms-api-bukkit/pom.xml b/multiperms-api/multiperms-api-bukkit/pom.xml new file mode 100644 index 0000000..83fa4a3 --- /dev/null +++ b/multiperms-api/multiperms-api-bukkit/pom.xml @@ -0,0 +1,119 @@ + + + + multiperms-api + com.dev7ex + 1.0.0-SNAPSHOT + + 4.0.0 + + MultiPerms-API-Bukkit + multiperms-api-bukkit + + + 16 + 16 + + + + + placeholderapi + https://repo.extendedclip.com/content/repositories/placeholderapi/ + + + + + + org.spigotmc + spigot-api + ${dependency-spigot-api-version} + provided + + + + com.dev7ex + facilis-common-bukkit + ${dependency.facilis-common-version} + provided + + + + me.clip + placeholderapi + ${dependency-placeholder-api-version} + provided + + + + org.projectlombok + lombok + ${dependency.lombok-version} + provided + + + + com.dev7ex + multiperms-api-core + ${project.version} + compile + + + + org.jetbrains + annotations + ${dependency.annotations-version} + provided + + + + + ${project.name}-${project.version} + clean package + + + + . + src/main/resources + true + + + **/.*.* + + + + + + + org.apache.maven.plugins + maven-shade-plugin + ${maven-shade-plugin.version} + + + package + + shade + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + ${maven-compiler-plugin.version} + + true + lines,vars,source + UTF-8 + true + true + ${project.source.version} + ${project.source.version} + + + + + + \ No newline at end of file diff --git a/multiperms-api/multiperms-api-bukkit/src/main/java/com/dev7ex/multiperms/api/bukkit/MultiPermsBukkitApi.java b/multiperms-api/multiperms-api-bukkit/src/main/java/com/dev7ex/multiperms/api/bukkit/MultiPermsBukkitApi.java new file mode 100644 index 0000000..d616e83 --- /dev/null +++ b/multiperms-api/multiperms-api-bukkit/src/main/java/com/dev7ex/multiperms/api/bukkit/MultiPermsBukkitApi.java @@ -0,0 +1,10 @@ +package com.dev7ex.multiperms.api.bukkit; + +import com.dev7ex.multiperms.api.MultiPermsApi; + +/** + * @author Dev7ex + * @since 03.07.2023 + */ +public interface MultiPermsBukkitApi extends MultiPermsApi { +} diff --git a/multiperms-api/multiperms-api-bukkit/src/main/java/com/dev7ex/multiperms/api/bukkit/event/MultiPermsListener.java b/multiperms-api/multiperms-api-bukkit/src/main/java/com/dev7ex/multiperms/api/bukkit/event/MultiPermsListener.java new file mode 100644 index 0000000..0a75619 --- /dev/null +++ b/multiperms-api/multiperms-api-bukkit/src/main/java/com/dev7ex/multiperms/api/bukkit/event/MultiPermsListener.java @@ -0,0 +1,38 @@ +package com.dev7ex.multiperms.api.bukkit.event; + +import com.dev7ex.multiperms.api.MultiPermsApiConfiguration; +import com.dev7ex.multiperms.api.bukkit.MultiPermsBukkitApi; +import com.dev7ex.multiperms.api.group.PermissionGroupProvider; +import com.dev7ex.multiperms.api.user.PermissionUserProvider; +import org.bukkit.event.Listener; +import org.jetbrains.annotations.NotNull; + +/** + * @author Dev7ex + * @since 03.07.2023 + */ +public abstract class MultiPermsListener implements Listener { + + private final MultiPermsBukkitApi multiPermsApi; + + public MultiPermsListener(@NotNull final MultiPermsBukkitApi multiPermsApi) { + this.multiPermsApi = multiPermsApi; + } + + public MultiPermsApiConfiguration getConfiguration() { + return this.multiPermsApi.getConfiguration(); + } + + public String getPrefix() { + return this.multiPermsApi.getConfiguration().getPrefix(); + } + + public PermissionGroupProvider getGroupProvider() { + return this.multiPermsApi.getGroupProvider(); + } + + public PermissionUserProvider getUserProvider() { + return this.multiPermsApi.getUserProvider(); + } + +} diff --git a/multiperms-api/multiperms-api-bukkit/src/main/java/com/dev7ex/multiperms/api/bukkit/event/group/PermissionGroupCreateEvent.java b/multiperms-api/multiperms-api-bukkit/src/main/java/com/dev7ex/multiperms/api/bukkit/event/group/PermissionGroupCreateEvent.java new file mode 100644 index 0000000..9bd8ee9 --- /dev/null +++ b/multiperms-api/multiperms-api-bukkit/src/main/java/com/dev7ex/multiperms/api/bukkit/event/group/PermissionGroupCreateEvent.java @@ -0,0 +1,35 @@ +package com.dev7ex.multiperms.api.bukkit.event.group; + +import com.dev7ex.multiperms.api.group.PermissionGroup; +import lombok.AccessLevel; +import lombok.Getter; +import lombok.Setter; +import org.bukkit.event.Cancellable; +import org.bukkit.event.HandlerList; +import org.jetbrains.annotations.NotNull; + +/** + * @author Dev7ex + * @since 03.07.2023 + */ +@Getter(AccessLevel.PUBLIC) +@Setter(AccessLevel.PUBLIC) +public class PermissionGroupCreateEvent extends PermissionGroupEvent implements Cancellable { + + private static final HandlerList HANDLERS = new HandlerList(); + private boolean cancelled = false; + + public PermissionGroupCreateEvent(@NotNull final PermissionGroup group) { + super(group); + } + + public static HandlerList getHandlerList() { + return PermissionGroupCreateEvent.HANDLERS; + } + + @Override + public @NotNull HandlerList getHandlers() { + return PermissionGroupCreateEvent.HANDLERS; + } + +} diff --git a/multiperms-api/multiperms-api-bukkit/src/main/java/com/dev7ex/multiperms/api/bukkit/event/group/PermissionGroupDeleteEvent.java b/multiperms-api/multiperms-api-bukkit/src/main/java/com/dev7ex/multiperms/api/bukkit/event/group/PermissionGroupDeleteEvent.java new file mode 100644 index 0000000..3c61bc8 --- /dev/null +++ b/multiperms-api/multiperms-api-bukkit/src/main/java/com/dev7ex/multiperms/api/bukkit/event/group/PermissionGroupDeleteEvent.java @@ -0,0 +1,35 @@ +package com.dev7ex.multiperms.api.bukkit.event.group; + +import com.dev7ex.multiperms.api.group.PermissionGroup; +import lombok.AccessLevel; +import lombok.Getter; +import lombok.Setter; +import org.bukkit.event.Cancellable; +import org.bukkit.event.HandlerList; +import org.jetbrains.annotations.NotNull; + +/** + * @author Dev7ex + * @since 03.07.2023 + */ +@Getter(AccessLevel.PUBLIC) +@Setter(AccessLevel.PUBLIC) +public class PermissionGroupDeleteEvent extends PermissionGroupEvent implements Cancellable { + + private static final HandlerList HANDLERS = new HandlerList(); + private boolean cancelled = false; + + public PermissionGroupDeleteEvent(@NotNull final PermissionGroup group) { + super(group); + } + + public static HandlerList getHandlerList() { + return PermissionGroupDeleteEvent.HANDLERS; + } + + @Override + public @NotNull HandlerList getHandlers() { + return PermissionGroupDeleteEvent.HANDLERS; + } + +} diff --git a/multiperms-api/multiperms-api-bukkit/src/main/java/com/dev7ex/multiperms/api/bukkit/event/group/PermissionGroupEditEvent.java b/multiperms-api/multiperms-api-bukkit/src/main/java/com/dev7ex/multiperms/api/bukkit/event/group/PermissionGroupEditEvent.java new file mode 100644 index 0000000..9219148 --- /dev/null +++ b/multiperms-api/multiperms-api-bukkit/src/main/java/com/dev7ex/multiperms/api/bukkit/event/group/PermissionGroupEditEvent.java @@ -0,0 +1,36 @@ +package com.dev7ex.multiperms.api.bukkit.event.group; + +import com.dev7ex.multiperms.api.group.PermissionGroup; +import com.dev7ex.multiperms.api.group.PermissionGroupProperty; +import lombok.AccessLevel; +import lombok.Getter; +import org.bukkit.event.HandlerList; +import org.jetbrains.annotations.NotNull; + +/** + * @author Dev7ex + * @since 03.08.2023 + */ +@Getter(AccessLevel.PUBLIC) +public class PermissionGroupEditEvent extends PermissionGroupEvent { + + private static final HandlerList HANDLERS = new HandlerList(); + private final PermissionGroupProperty groupProperty; + private final Object value; + + public PermissionGroupEditEvent(@NotNull final PermissionGroup group, @NotNull final PermissionGroupProperty groupProperty, @NotNull final Object value) { + super(group); + this.groupProperty = groupProperty; + this.value = value; + } + + public static HandlerList getHandlerList() { + return PermissionGroupEditEvent.HANDLERS; + } + + @Override + public @NotNull HandlerList getHandlers() { + return PermissionGroupEditEvent.HANDLERS; + } + +} diff --git a/multiperms-api/multiperms-api-bukkit/src/main/java/com/dev7ex/multiperms/api/bukkit/event/group/PermissionGroupEvent.java b/multiperms-api/multiperms-api-bukkit/src/main/java/com/dev7ex/multiperms/api/bukkit/event/group/PermissionGroupEvent.java new file mode 100644 index 0000000..9efbb51 --- /dev/null +++ b/multiperms-api/multiperms-api-bukkit/src/main/java/com/dev7ex/multiperms/api/bukkit/event/group/PermissionGroupEvent.java @@ -0,0 +1,22 @@ +package com.dev7ex.multiperms.api.bukkit.event.group; + +import com.dev7ex.multiperms.api.group.PermissionGroup; +import lombok.AccessLevel; +import lombok.Getter; +import org.bukkit.event.Event; +import org.jetbrains.annotations.NotNull; + +/** + * @author Dev7ex + * @since 03.07.2023 + */ +@Getter(AccessLevel.PUBLIC) +public abstract class PermissionGroupEvent extends Event { + + private final PermissionGroup group; + + public PermissionGroupEvent(@NotNull final PermissionGroup group) { + this.group = group; + } + +} diff --git a/multiperms-api/multiperms-api-bukkit/src/main/java/com/dev7ex/multiperms/api/bukkit/event/user/PermissionUserEvent.java b/multiperms-api/multiperms-api-bukkit/src/main/java/com/dev7ex/multiperms/api/bukkit/event/user/PermissionUserEvent.java new file mode 100644 index 0000000..749e6c2 --- /dev/null +++ b/multiperms-api/multiperms-api-bukkit/src/main/java/com/dev7ex/multiperms/api/bukkit/event/user/PermissionUserEvent.java @@ -0,0 +1,22 @@ +package com.dev7ex.multiperms.api.bukkit.event.user; + +import com.dev7ex.multiperms.api.user.PermissionUser; +import lombok.AccessLevel; +import lombok.Getter; +import org.bukkit.event.Event; +import org.jetbrains.annotations.NotNull; + +/** + * @author Dev7ex + * @since 03.07.2023 + */ +@Getter(AccessLevel.PUBLIC) +public abstract class PermissionUserEvent extends Event { + + private final PermissionUser user; + + public PermissionUserEvent(@NotNull final PermissionUser user) { + this.user = user; + } + +} \ No newline at end of file diff --git a/multiperms-api/multiperms-api-bukkit/src/main/java/com/dev7ex/multiperms/api/bukkit/event/user/PermissionUserGroupSetEvent.java b/multiperms-api/multiperms-api-bukkit/src/main/java/com/dev7ex/multiperms/api/bukkit/event/user/PermissionUserGroupSetEvent.java new file mode 100644 index 0000000..ca3b89b --- /dev/null +++ b/multiperms-api/multiperms-api-bukkit/src/main/java/com/dev7ex/multiperms/api/bukkit/event/user/PermissionUserGroupSetEvent.java @@ -0,0 +1,34 @@ +package com.dev7ex.multiperms.api.bukkit.event.user; + +import com.dev7ex.multiperms.api.group.PermissionGroup; +import com.dev7ex.multiperms.api.user.PermissionUser; +import lombok.AccessLevel; +import lombok.Getter; +import org.bukkit.event.HandlerList; +import org.jetbrains.annotations.NotNull; + +/** + * @author Dev7ex + * @since 03.08.2023 + */ +@Getter(AccessLevel.PUBLIC) +public class PermissionUserGroupSetEvent extends PermissionUserEvent { + + private static final HandlerList HANDLERS = new HandlerList(); + private final PermissionGroup newGroup; + + public PermissionUserGroupSetEvent(@NotNull final PermissionUser user, @NotNull final PermissionGroup newGroup) { + super(user); + this.newGroup = newGroup; + } + + public static HandlerList getHandlerList() { + return PermissionUserGroupSetEvent.HANDLERS; + } + + @Override + public @NotNull HandlerList getHandlers() { + return PermissionUserGroupSetEvent.HANDLERS; + } + +} diff --git a/multiperms-api/multiperms-api-bukkit/src/main/java/com/dev7ex/multiperms/api/bukkit/event/user/PermissionUserLoginEvent.java b/multiperms-api/multiperms-api-bukkit/src/main/java/com/dev7ex/multiperms/api/bukkit/event/user/PermissionUserLoginEvent.java new file mode 100644 index 0000000..3194297 --- /dev/null +++ b/multiperms-api/multiperms-api-bukkit/src/main/java/com/dev7ex/multiperms/api/bukkit/event/user/PermissionUserLoginEvent.java @@ -0,0 +1,28 @@ +package com.dev7ex.multiperms.api.bukkit.event.user; + +import com.dev7ex.multiperms.api.user.PermissionUser; +import org.bukkit.event.HandlerList; +import org.jetbrains.annotations.NotNull; + +/** + * @author Dev7ex + * @since 03.08.2023 + */ +public class PermissionUserLoginEvent extends PermissionUserEvent { + + private static final HandlerList HANDLERS = new HandlerList(); + + public PermissionUserLoginEvent(@NotNull final PermissionUser user) { + super(user); + } + + public static HandlerList getHandlerList() { + return PermissionUserLoginEvent.HANDLERS; + } + + @Override + public @NotNull HandlerList getHandlers() { + return PermissionUserLoginEvent.HANDLERS; + } + +} diff --git a/multiperms-api/multiperms-api-bukkit/src/main/java/com/dev7ex/multiperms/api/bukkit/event/user/PermissionUserLogoutEvent.java b/multiperms-api/multiperms-api-bukkit/src/main/java/com/dev7ex/multiperms/api/bukkit/event/user/PermissionUserLogoutEvent.java new file mode 100644 index 0000000..e5750d2 --- /dev/null +++ b/multiperms-api/multiperms-api-bukkit/src/main/java/com/dev7ex/multiperms/api/bukkit/event/user/PermissionUserLogoutEvent.java @@ -0,0 +1,28 @@ +package com.dev7ex.multiperms.api.bukkit.event.user; + +import com.dev7ex.multiperms.api.user.PermissionUser; +import org.bukkit.event.HandlerList; +import org.jetbrains.annotations.NotNull; + +/** + * @author Dev7ex + * @since 03.08.2023 + */ +public class PermissionUserLogoutEvent extends PermissionUserEvent { + + private static final HandlerList HANDLERS = new HandlerList(); + + public PermissionUserLogoutEvent(@NotNull final PermissionUser user) { + super(user); + } + + public static HandlerList getHandlerList() { + return PermissionUserLogoutEvent.HANDLERS; + } + + @Override + public @NotNull HandlerList getHandlers() { + return PermissionUserLogoutEvent.HANDLERS; + } + +} diff --git a/multiperms-api/multiperms-api-bukkit/src/main/java/com/dev7ex/multiperms/api/bukkit/hook/BukkitPermissionHook.java b/multiperms-api/multiperms-api-bukkit/src/main/java/com/dev7ex/multiperms/api/bukkit/hook/BukkitPermissionHook.java new file mode 100644 index 0000000..bb8cf2c --- /dev/null +++ b/multiperms-api/multiperms-api-bukkit/src/main/java/com/dev7ex/multiperms/api/bukkit/hook/BukkitPermissionHook.java @@ -0,0 +1,18 @@ +package com.dev7ex.multiperms.api.bukkit.hook; + +import com.dev7ex.multiperms.api.hook.PermissionHook; +import lombok.AccessLevel; +import lombok.Getter; + +import java.util.List; + +/** + * @author Dev7ex + * @since 03.08.2023 + */ +@Getter(AccessLevel.PUBLIC) +public class BukkitPermissionHook implements PermissionHook { + + private final List permissions = List.of("bukkit.command.version", "bukkit.command.plugins", "bukkit.command.help", "bukkit.command.reload", "bukkit.command.timings"); + +} diff --git a/multiperms-api/multiperms-api-core/pom.xml b/multiperms-api/multiperms-api-core/pom.xml new file mode 100644 index 0000000..16cda40 --- /dev/null +++ b/multiperms-api/multiperms-api-core/pom.xml @@ -0,0 +1,21 @@ + + + 4.0.0 + + + multiperms-api + com.dev7ex + 1.0.0-SNAPSHOT + + + MultiPerms-API-Core + multiperms-api-core + + + 16 + 16 + + + \ No newline at end of file diff --git a/multiperms-api/multiperms-api-core/src/main/java/com/dev7ex/multiperms/api/MultiPermsApi.java b/multiperms-api/multiperms-api-core/src/main/java/com/dev7ex/multiperms/api/MultiPermsApi.java new file mode 100644 index 0000000..f59317d --- /dev/null +++ b/multiperms-api/multiperms-api-core/src/main/java/com/dev7ex/multiperms/api/MultiPermsApi.java @@ -0,0 +1,25 @@ +package com.dev7ex.multiperms.api; + +import com.dev7ex.multiperms.api.group.PermissionGroupProvider; +import com.dev7ex.multiperms.api.hook.PermissionHookProvider; +import com.dev7ex.multiperms.api.user.PermissionUserProvider; + +import java.io.File; + +/** + * @author Dev7ex + * @since 03.07.2023 + */ +public interface MultiPermsApi { + + MultiPermsApiConfiguration getConfiguration(); + + File getUserFolder(); + + PermissionGroupProvider getGroupProvider(); + + PermissionUserProvider getUserProvider(); + + PermissionHookProvider getPermissionHookProvider(); + +} diff --git a/multiperms-api/multiperms-api-core/src/main/java/com/dev7ex/multiperms/api/MultiPermsApiConfiguration.java b/multiperms-api/multiperms-api-core/src/main/java/com/dev7ex/multiperms/api/MultiPermsApiConfiguration.java new file mode 100644 index 0000000..6358f81 --- /dev/null +++ b/multiperms-api/multiperms-api-core/src/main/java/com/dev7ex/multiperms/api/MultiPermsApiConfiguration.java @@ -0,0 +1,17 @@ +package com.dev7ex.multiperms.api; + +/** + * @author Dev7ex + * @since 03.07.2023 + */ +public interface MultiPermsApiConfiguration { + + String getPrefix(); + + String getChatFormat(); + + boolean isChatEnabled(); + + boolean isTablistEnabled(); + +} diff --git a/multiperms-api/multiperms-api-core/src/main/java/com/dev7ex/multiperms/api/MultiPermsApiConfigurationEntry.java b/multiperms-api/multiperms-api-core/src/main/java/com/dev7ex/multiperms/api/MultiPermsApiConfigurationEntry.java new file mode 100644 index 0000000..9c525dd --- /dev/null +++ b/multiperms-api/multiperms-api-core/src/main/java/com/dev7ex/multiperms/api/MultiPermsApiConfigurationEntry.java @@ -0,0 +1,26 @@ +package com.dev7ex.multiperms.api; + +import lombok.AccessLevel; +import lombok.Getter; +import org.jetbrains.annotations.NotNull; + +/** + * @author Dev7ex + * @since 03.08.2023 + */ +@Getter(AccessLevel.PUBLIC) +public enum MultiPermsApiConfigurationEntry { + + PREFIX("prefix"), + NO_PERMISSION("no-permission"), + NO_CONSOLE_COMMAND("no-console-command"), + NO_PLAYER_COMMAND("no-player-command"), + NO_PLAYER_FOUND("no-player-found"); + + private final String storagePath; + + MultiPermsApiConfigurationEntry(@NotNull final String storagePath) { + this.storagePath = storagePath; + } + +} diff --git a/multiperms-api/multiperms-api-core/src/main/java/com/dev7ex/multiperms/api/MultiPermsApiProvider.java b/multiperms-api/multiperms-api-core/src/main/java/com/dev7ex/multiperms/api/MultiPermsApiProvider.java new file mode 100644 index 0000000..6c3aafa --- /dev/null +++ b/multiperms-api/multiperms-api-core/src/main/java/com/dev7ex/multiperms/api/MultiPermsApiProvider.java @@ -0,0 +1,24 @@ +package com.dev7ex.multiperms.api; + +import lombok.AccessLevel; +import lombok.Getter; +import org.jetbrains.annotations.NotNull; + +/** + * @author Dev7ex + * @since 03.07.2023 + */ +public class MultiPermsApiProvider { + + @Getter(AccessLevel.PUBLIC) + private static MultiPermsApi multiPermsApi; + + public static void registerApi(@NotNull final MultiPermsApi multiPermsApi) { + MultiPermsApiProvider.multiPermsApi = multiPermsApi; + } + + public static void unregisterApi() { + MultiPermsApiProvider.multiPermsApi = null; + } + +} diff --git a/multiperms-api/multiperms-api-core/src/main/java/com/dev7ex/multiperms/api/group/PermissionGroup.java b/multiperms-api/multiperms-api-core/src/main/java/com/dev7ex/multiperms/api/group/PermissionGroup.java new file mode 100644 index 0000000..4a7aa93 --- /dev/null +++ b/multiperms-api/multiperms-api-core/src/main/java/com/dev7ex/multiperms/api/group/PermissionGroup.java @@ -0,0 +1,52 @@ +package com.dev7ex.multiperms.api.group; + +import org.jetbrains.annotations.NotNull; + +import java.util.List; + +/** + * @author Dev7ex + * @since 03.07.2023 + */ +public interface PermissionGroup extends Comparable { + + int getIdentification(); + + void setIdentification(final int identification); + + String getName(); + + void setName(@NotNull final String name); + + List getPermissions(); + + boolean hasPermission(@NotNull final String permission); + + String getDisplayName(); + + void setDisplayName(@NotNull final String displayName); + + int getPriority(); + + void setPriority(final int priority); + + char getColor(); + + void setColor(final char color); + + String getChatPrefix(); + + void setChatPrefix(@NotNull final String chatPrefix); + + String getTablistPrefix(); + + void setTablistPrefix(@NotNull final String tablistPrefix); + + String getColoredDisplayName(); + + @Override + default int compareTo(@NotNull final PermissionGroup group) { + return Integer.compare(this.getPriority(), group.getPriority()); + } + +} diff --git a/multiperms-api/multiperms-api-core/src/main/java/com/dev7ex/multiperms/api/group/PermissionGroupConfiguration.java b/multiperms-api/multiperms-api-core/src/main/java/com/dev7ex/multiperms/api/group/PermissionGroupConfiguration.java new file mode 100644 index 0000000..f5dad31 --- /dev/null +++ b/multiperms-api/multiperms-api-core/src/main/java/com/dev7ex/multiperms/api/group/PermissionGroupConfiguration.java @@ -0,0 +1,40 @@ +package com.dev7ex.multiperms.api.group; + +import com.dev7ex.common.map.ParsedMap; +import org.jetbrains.annotations.NotNull; + +import java.util.Map; + +/** + * @author Dev7ex + * @since 03.07.2023 + */ +public interface PermissionGroupConfiguration { + + void add(@NotNull final PermissionGroup group); + + void remove(final int identification); + + boolean contains(final int identification); + + void save(); + + void write(final int identification, @NotNull final ParsedMap groupData); + + void addPermission(final int identification, @NotNull final String permission); + + void removePermission(final int identification, @NotNull final String permission); + + void clearPermissions(final int identification); + + @NotNull + ParsedMap read(final int identification); + + @NotNull + ParsedMap read(final int identification, final PermissionGroupProperty... properties); + + PermissionGroup getGroup(final int identification); + + Map getGroups(); + +} diff --git a/multiperms-api/multiperms-api-core/src/main/java/com/dev7ex/multiperms/api/group/PermissionGroupProperty.java b/multiperms-api/multiperms-api-core/src/main/java/com/dev7ex/multiperms/api/group/PermissionGroupProperty.java new file mode 100644 index 0000000..ce273f7 --- /dev/null +++ b/multiperms-api/multiperms-api-core/src/main/java/com/dev7ex/multiperms/api/group/PermissionGroupProperty.java @@ -0,0 +1,41 @@ +package com.dev7ex.multiperms.api.group; + +import lombok.AccessLevel; +import lombok.Getter; +import org.jetbrains.annotations.NotNull; + +import java.util.Arrays; +import java.util.List; +import java.util.Optional; + +/** + * @author Dev7ex + * @since 03.07.2023 + */ +@Getter(AccessLevel.PUBLIC) +public enum PermissionGroupProperty { + + IDENTIFICATION("identification"), + NAME("name"), + PERMISSIONS("permissions"), + DISPLAY_NAME("display-name"), + PRIORITY("priority"), + COLOR("color"), + CHAT_PREFIX("chat-prefix"), + TABLIST_PREFIX("tablist-prefix"); + + private final String storagePath; + + PermissionGroupProperty(final String storagePath) { + this.storagePath = storagePath; + } + + public static List toStringList() { + return Arrays.stream(PermissionGroupProperty.values()).map(Enum::name).toList(); + } + + public static Optional fromString(@NotNull final String s) { + return Arrays.stream(PermissionGroupProperty.values()).filter(property -> property.name().equalsIgnoreCase(s)).findFirst(); + } + +} diff --git a/multiperms-api/multiperms-api-core/src/main/java/com/dev7ex/multiperms/api/group/PermissionGroupProvider.java b/multiperms-api/multiperms-api-core/src/main/java/com/dev7ex/multiperms/api/group/PermissionGroupProvider.java new file mode 100644 index 0000000..6371e37 --- /dev/null +++ b/multiperms-api/multiperms-api-core/src/main/java/com/dev7ex/multiperms/api/group/PermissionGroupProvider.java @@ -0,0 +1,45 @@ +package com.dev7ex.multiperms.api.group; + +import org.jetbrains.annotations.NotNull; + +import java.util.List; +import java.util.Map; +import java.util.Optional; + +/** + * @author Dev7ex + * @since 03.07.2023 + */ +public interface PermissionGroupProvider { + + void register(@NotNull final PermissionGroup group); + + void unregister(final int identification); + + boolean isRegistered(final int identification); + + Optional getGroup(final int identification); + + Optional getGroup(@NotNull final String name); + + PermissionGroup getGroupOrDefault(final int identification); + + PermissionGroup getDefaultGroup(); + + Map getGroups(@NotNull final List identifications); + + PermissionGroup getNextBestGroup(@NotNull final List groups); + + List getExistingGroups(@NotNull final List groupIdentifications); + + List getDeadGroups(@NotNull final List groupIdentifications); + + void saveGroup(@NotNull final PermissionGroup group, @NotNull final PermissionGroupProperty... properties); + + void saveGroup(@NotNull final PermissionGroup group); + + PermissionGroupConfiguration getConfiguration(); + + Map getGroups(); + +} diff --git a/multiperms-api/multiperms-api-core/src/main/java/com/dev7ex/multiperms/api/hook/PermissionHook.java b/multiperms-api/multiperms-api-core/src/main/java/com/dev7ex/multiperms/api/hook/PermissionHook.java new file mode 100644 index 0000000..a7f7315 --- /dev/null +++ b/multiperms-api/multiperms-api-core/src/main/java/com/dev7ex/multiperms/api/hook/PermissionHook.java @@ -0,0 +1,13 @@ +package com.dev7ex.multiperms.api.hook; + +import java.util.List; + +/** + * @author Dev7ex + * @since 03.08.2023 + */ +public interface PermissionHook { + + List getPermissions(); + +} diff --git a/multiperms-api/multiperms-api-core/src/main/java/com/dev7ex/multiperms/api/hook/PermissionHookProvider.java b/multiperms-api/multiperms-api-core/src/main/java/com/dev7ex/multiperms/api/hook/PermissionHookProvider.java new file mode 100644 index 0000000..3080d0d --- /dev/null +++ b/multiperms-api/multiperms-api-core/src/main/java/com/dev7ex/multiperms/api/hook/PermissionHookProvider.java @@ -0,0 +1,17 @@ +package com.dev7ex.multiperms.api.hook; + +import java.util.Map; + +/** + * @author Dev7ex + * @since 03.08.2023 + */ +public interface PermissionHookProvider { + + Map getPermissionHooks(); + + void register(final T hookHolder, final PermissionHook hook); + + void unregister(final T hookHolder); + +} diff --git a/multiperms-api/multiperms-api-core/src/main/java/com/dev7ex/multiperms/api/user/PermissionUser.java b/multiperms-api/multiperms-api-core/src/main/java/com/dev7ex/multiperms/api/user/PermissionUser.java new file mode 100644 index 0000000..7d3603d --- /dev/null +++ b/multiperms-api/multiperms-api-core/src/main/java/com/dev7ex/multiperms/api/user/PermissionUser.java @@ -0,0 +1,53 @@ +package com.dev7ex.multiperms.api.user; + +import com.dev7ex.multiperms.api.group.PermissionGroup; +import org.jetbrains.annotations.NotNull; + +import java.util.List; +import java.util.UUID; + +/** + * @author Dev7ex + * @since 03.07.2023 + */ +public interface PermissionUser { + + UUID getUniqueId(); + + String getName(); + + void setName(@NotNull final String name); + + PermissionUserConfiguration getConfiguration(); + + void setConfiguration(@NotNull final PermissionUserConfiguration configuration); + + long getLastLogin(); + + void setLastLogin(final long lastLogin); + + String getColoredName(); + + PermissionGroup getGroup(); + + void setGroup(@NotNull final PermissionGroup group); + + List getSubGroups(); + + void setSubGroups(@NotNull final List subGroups); + + List getPermissions(); + + List getAllPermissions(); + + void setPermissions(@NotNull final List permissions); + + void addPermission(@NotNull final String permission); + + void removePermission(@NotNull final String permission); + + boolean hasPermission(@NotNull final String permission); + + void sendMessage(@NotNull final String message); + +} diff --git a/multiperms-api/multiperms-api-core/src/main/java/com/dev7ex/multiperms/api/user/PermissionUserConfiguration.java b/multiperms-api/multiperms-api-core/src/main/java/com/dev7ex/multiperms/api/user/PermissionUserConfiguration.java new file mode 100644 index 0000000..0e01faa --- /dev/null +++ b/multiperms-api/multiperms-api-core/src/main/java/com/dev7ex/multiperms/api/user/PermissionUserConfiguration.java @@ -0,0 +1,28 @@ +package com.dev7ex.multiperms.api.user; + +import com.dev7ex.common.map.ParsedMap; +import org.jetbrains.annotations.NotNull; + +/** + * @author Dev7ex + * @since 03.07.2023 + */ +public interface PermissionUserConfiguration { + + ParsedMap read(); + + ParsedMap read(@NotNull final PermissionUserProperty... properties); + + void write(@NotNull final ParsedMap userData); + + void write(@NotNull final PermissionUserProperty property, @NotNull final Object value); + + void removePermission(final String permission); + + void addPermission(final String permission); + + void clearPermissions(); + + void save(); + +} diff --git a/multiperms-api/multiperms-api-core/src/main/java/com/dev7ex/multiperms/api/user/PermissionUserProperty.java b/multiperms-api/multiperms-api-core/src/main/java/com/dev7ex/multiperms/api/user/PermissionUserProperty.java new file mode 100644 index 0000000..fd02024 --- /dev/null +++ b/multiperms-api/multiperms-api-core/src/main/java/com/dev7ex/multiperms/api/user/PermissionUserProperty.java @@ -0,0 +1,27 @@ +package com.dev7ex.multiperms.api.user; + +import lombok.AccessLevel; +import lombok.Getter; +import org.jetbrains.annotations.NotNull; + +/** + * @author Dev7ex + * @since 03.07.2023 + */ +@Getter(AccessLevel.PUBLIC) +public enum PermissionUserProperty { + + UNIQUE_ID("unique-id"), + NAME("name"), + LAST_LOGIN("last-login"), + GROUP("group"), + SUB_GROUPS("sub-groups"), + PERMISSION("permission"); + + private final String storagePath; + + PermissionUserProperty(@NotNull final String storagePath) { + this.storagePath = storagePath; + } + +} diff --git a/multiperms-api/multiperms-api-core/src/main/java/com/dev7ex/multiperms/api/user/PermissionUserProvider.java b/multiperms-api/multiperms-api-core/src/main/java/com/dev7ex/multiperms/api/user/PermissionUserProvider.java new file mode 100644 index 0000000..1cc20ba --- /dev/null +++ b/multiperms-api/multiperms-api-core/src/main/java/com/dev7ex/multiperms/api/user/PermissionUserProvider.java @@ -0,0 +1,32 @@ +package com.dev7ex.multiperms.api.user; + +import com.dev7ex.multiperms.api.group.PermissionGroup; +import org.jetbrains.annotations.NotNull; + +import java.util.Map; +import java.util.Optional; +import java.util.UUID; + +/** + * @author Dev7ex + * @since 03.07.2023 + */ +public interface PermissionUserProvider { + + void registerUser(@NotNull final PermissionUser user); + + void unregisterUser(@NotNull final UUID uniqueId); + + Optional getUser(@NotNull final UUID uniqueId); + + Optional getUser(@NotNull final String name); + + Map getUsers(); + + Map getUsers(@NotNull final PermissionGroup group); + + void saveUser(@NotNull final PermissionUser user); + + void saveUser(@NotNull final PermissionUser user, @NotNull final PermissionUserProperty... properties); + +} diff --git a/multiperms-api/pom.xml b/multiperms-api/pom.xml new file mode 100644 index 0000000..cfc6d34 --- /dev/null +++ b/multiperms-api/pom.xml @@ -0,0 +1,49 @@ + + + 4.0.0 + pom + + multiperms-api-core + multiperms-api-bukkit + + + + multiperms + com.dev7ex + 1.0.0-SNAPSHOT + + + MultiPerms-API + multiperms-api + + + 16 + 16 + + + + + com.dev7ex + facilis-common-core + ${dependency.facilis-common-version} + provided + + + + org.projectlombok + lombok + ${dependency.lombok-version} + provided + + + + org.jetbrains + annotations + ${dependency.annotations-version} + provided + + + + \ No newline at end of file diff --git a/multiperms-bukkit/pom.xml b/multiperms-bukkit/pom.xml new file mode 100644 index 0000000..bb2a045 --- /dev/null +++ b/multiperms-bukkit/pom.xml @@ -0,0 +1,138 @@ + + + 4.0.0 + + + multiperms + com.dev7ex + 1.0.0-SNAPSHOT + + + MultiPerms-Bukkit + multiperms-bukkit + + + 16 + 16 + + + + + spigot-repo + https://hub.spigotmc.org/nexus/content/repositories/snapshots/ + + + + placeholderapi + https://repo.extendedclip.com/content/repositories/placeholderapi/ + + + + + + org.spigotmc + spigot-api + ${dependency-spigot-api-version} + provided + + + + com.dev7ex + facilis-common-bukkit + ${dependency.facilis-common-version} + provided + + + + com.dev7ex + multiperms-api-bukkit + ${project.version} + compile + + + + me.clip + placeholderapi + ${dependency-placeholder-api-version} + provided + + + + commons-io + commons-io + ${dependency-commons-io-version} + provided + + + + org.projectlombok + lombok + ${dependency.lombok-version} + provided + + + + org.jetbrains + annotations + ${dependency.annotations-version} + provided + + + + + ${project.name}-${project.version} + clean package + + + + . + src/main/resources + true + + + **/.*.* + + + + + + + org.apache.maven.plugins + maven-shade-plugin + ${maven-shade-plugin.version} + + + package + + shade + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + ${maven-compiler-plugin.version} + + true + lines,vars,source + UTF-8 + true + true + ${project.source.version} + ${project.source.version} + + + + + org.apache.maven.plugins + maven-javadoc-plugin + 3.5.0 + + + + + \ No newline at end of file diff --git a/multiperms-bukkit/src/main/java/com/dev7ex/multiperms/MultiPermsConfiguration.java b/multiperms-bukkit/src/main/java/com/dev7ex/multiperms/MultiPermsConfiguration.java new file mode 100644 index 0000000..6ba3d33 --- /dev/null +++ b/multiperms-bukkit/src/main/java/com/dev7ex/multiperms/MultiPermsConfiguration.java @@ -0,0 +1,35 @@ +package com.dev7ex.multiperms; + +import com.dev7ex.common.bukkit.configuration.ConfigurationProperties; +import com.dev7ex.common.bukkit.plugin.configuration.DefaultPluginConfiguration; +import com.dev7ex.multiperms.api.MultiPermsApiConfiguration; +import org.bukkit.plugin.Plugin; +import org.jetbrains.annotations.NotNull; + +/** + * @author Dev7ex + * @since 03.07.2023 + */ +@ConfigurationProperties(fileName = "config.yml") +public class MultiPermsConfiguration extends DefaultPluginConfiguration implements MultiPermsApiConfiguration { + + public MultiPermsConfiguration(@NotNull final Plugin plugin) { + super(plugin); + } + + @Override + public String getChatFormat() { + return super.getString("settings.chat-format"); + } + + @Override + public boolean isChatEnabled() { + return super.getBoolean("settings.chat-enabled"); + } + + @Override + public boolean isTablistEnabled() { + return super.getBoolean("settings.tablist-enabled"); + } + +} diff --git a/multiperms-bukkit/src/main/java/com/dev7ex/multiperms/MultiPermsPlugin.java b/multiperms-bukkit/src/main/java/com/dev7ex/multiperms/MultiPermsPlugin.java new file mode 100644 index 0000000..b9ef16f --- /dev/null +++ b/multiperms-bukkit/src/main/java/com/dev7ex/multiperms/MultiPermsPlugin.java @@ -0,0 +1,90 @@ +package com.dev7ex.multiperms; + +import com.dev7ex.common.bukkit.plugin.BukkitPlugin; +import com.dev7ex.common.bukkit.plugin.PluginProperties; +import com.dev7ex.multiperms.api.MultiPermsApiProvider; +import com.dev7ex.multiperms.api.bukkit.MultiPermsBukkitApi; +import com.dev7ex.multiperms.command.PermissionCommand; +import com.dev7ex.multiperms.group.GroupConfiguration; +import com.dev7ex.multiperms.group.GroupService; +import com.dev7ex.multiperms.hook.DefaultPermissionHookProvider; +import com.dev7ex.multiperms.listener.PlayerChatListener; +import com.dev7ex.multiperms.listener.PlayerConnectionListener; +import com.dev7ex.multiperms.listener.ScoreboardListener; +import com.dev7ex.multiperms.scoreboard.ScoreboardService; +import com.dev7ex.multiperms.user.UserService; +import lombok.AccessLevel; +import lombok.Getter; +import org.bukkit.plugin.java.JavaPlugin; + +import java.io.File; + +/** + * @author Dev7ex + * @since 03.07.2023 + */ +@Getter(AccessLevel.PUBLIC) +@PluginProperties(metrics = true, metricsId = 19393) +public class MultiPermsPlugin extends BukkitPlugin implements MultiPermsBukkitApi { + + private MultiPermsConfiguration configuration; + private GroupConfiguration groupConfiguration; + + private GroupService groupProvider; + private UserService userProvider; + private ScoreboardService scoreboardProvider; + private DefaultPermissionHookProvider permissionHookProvider; + + @Override + public void onLoad() { + super.createDataFolder(); + super.createSubFolder("user"); + + this.configuration = new MultiPermsConfiguration(this); + this.configuration.load(); + + this.groupConfiguration = new GroupConfiguration(this); + this.groupConfiguration.createFile(); + this.groupConfiguration.load(); + } + + @Override + public void onEnable() { + MultiPermsApiProvider.registerApi(this); + } + + @Override + public void onDisable() { + MultiPermsApiProvider.unregisterApi(); + } + + @Override + public void registerCommands() { + super.registerCommand(new PermissionCommand(this)); + } + + @Override + public void registerListeners() { + super.registerListenerIf(new PlayerChatListener(this), enableIf -> this.configuration.isChatEnabled()); + super.registerListener(new PlayerConnectionListener(this)); + super.registerListenerIf(new ScoreboardListener(this), enableIf -> this.configuration.isTablistEnabled()); + } + + @Override + public void registerServices() { + super.registerService(this.groupProvider = new GroupService(this.groupConfiguration)); + super.registerService(this.userProvider = new UserService(this.groupProvider)); + super.registerService(this.scoreboardProvider = new ScoreboardService(this.groupProvider)); + super.registerService(this.permissionHookProvider = new DefaultPermissionHookProvider()); + } + + @Override + public File getUserFolder() { + return super.getSubFolder("user"); + } + + public static MultiPermsPlugin getInstance() { + return JavaPlugin.getPlugin(MultiPermsPlugin.class); + } + +} diff --git a/multiperms-bukkit/src/main/java/com/dev7ex/multiperms/command/PermissionCommand.java b/multiperms-bukkit/src/main/java/com/dev7ex/multiperms/command/PermissionCommand.java new file mode 100644 index 0000000..3b4c6cf --- /dev/null +++ b/multiperms-bukkit/src/main/java/com/dev7ex/multiperms/command/PermissionCommand.java @@ -0,0 +1,63 @@ +package com.dev7ex.multiperms.command; + +import com.dev7ex.common.bukkit.command.BukkitCommand; +import com.dev7ex.common.bukkit.command.CommandProperties; +import com.dev7ex.common.bukkit.plugin.BukkitPlugin; +import com.dev7ex.multiperms.command.permission.GroupCommand; +import com.dev7ex.multiperms.command.permission.HelpCommand; +import com.dev7ex.multiperms.command.permission.ReloadCommand; +import com.dev7ex.multiperms.command.permission.UserCommand; +import com.google.common.collect.Lists; +import org.bukkit.command.Command; +import org.bukkit.command.CommandSender; +import org.bukkit.command.TabCompleter; +import org.jetbrains.annotations.NotNull; + +import java.util.List; +import java.util.Optional; + +/** + * @author Dev7ex + * @since 03.07.2023 + */ +@CommandProperties(name = "permission", permission = "multiperms.command.permission", aliases = {"mp", "perms"}) +public class PermissionCommand extends BukkitCommand implements TabCompleter { + + public PermissionCommand(@NotNull final BukkitPlugin plugin) { + super(plugin); + + super.registerSubCommand(new GroupCommand(plugin)); + super.registerSubCommand(new HelpCommand(plugin)); + super.registerSubCommand(new ReloadCommand(plugin)); + super.registerSubCommand(new UserCommand(plugin)); + } + + @Override + public boolean execute(@NotNull final CommandSender commandSender, @NotNull final String[] arguments) { + if ((arguments.length == 0) || (arguments.length > 6)) { + return super.getSubCommand("help").orElseThrow().execute(commandSender, arguments); + } + final Optional commandOptional = super.getSubCommand(arguments[0].toLowerCase()); + + if (commandOptional.isEmpty()) { + return super.getSubCommand("help").orElseThrow().execute(commandSender, arguments); + } + return commandOptional.get().execute(commandOptional.get(), commandSender, arguments); + } + + @Override + public List onTabComplete(@NotNull final CommandSender commandSender, @NotNull final Command command, + @NotNull final String commandLabel, @NotNull final String[] arguments) { + if (arguments.length == 1) { + return Lists.newArrayList(super.getSubCommands().keySet()); + } + final Optional commandOptional = super.getSubCommand(arguments[0].toLowerCase()); + + if ((commandOptional.isEmpty()) || (!(commandOptional.get() instanceof TabCompleter))) { + return null; + } + return ((TabCompleter) commandOptional.get()).onTabComplete(commandSender, command, commandLabel, arguments); + } + + +} diff --git a/multiperms-bukkit/src/main/java/com/dev7ex/multiperms/command/permission/GroupCommand.java b/multiperms-bukkit/src/main/java/com/dev7ex/multiperms/command/permission/GroupCommand.java new file mode 100644 index 0000000..023390e --- /dev/null +++ b/multiperms-bukkit/src/main/java/com/dev7ex/multiperms/command/permission/GroupCommand.java @@ -0,0 +1,66 @@ +package com.dev7ex.multiperms.command.permission; + +import com.dev7ex.common.bukkit.command.BukkitCommand; +import com.dev7ex.common.bukkit.command.CommandProperties; +import com.dev7ex.common.bukkit.plugin.BukkitPlugin; +import com.dev7ex.multiperms.command.permission.group.*; +import com.google.common.collect.Lists; +import org.bukkit.command.Command; +import org.bukkit.command.CommandSender; +import org.bukkit.command.TabCompleter; +import org.jetbrains.annotations.NotNull; + +import java.util.Collections; +import java.util.List; + +/** + * @author Dev7ex + * @since 03.07.2023 + */ +@CommandProperties(name = "group", permission = "multiperms.command.permission.group") +public class GroupCommand extends BukkitCommand implements TabCompleter { + + public GroupCommand(@NotNull final BukkitPlugin plugin) { + super(plugin); + + super.registerSubCommand(new AddCommand(plugin)); + super.registerSubCommand(new CreateCommand(plugin)); + super.registerSubCommand(new DeleteCommand(plugin)); + super.registerSubCommand(new EditCommand(plugin)); + super.registerSubCommand(new HelpCommand(plugin)); + super.registerSubCommand(new ListCommand(plugin)); + super.registerSubCommand(new RemoveCommand(plugin)); + } + + @Override + public boolean execute(@NotNull final CommandSender commandSender, @NotNull final String[] arguments) { + if ((arguments.length == 1) || (arguments.length > 6)) { + return super.getSubCommand("help").orElseThrow().execute(commandSender, arguments); + } + + if (super.getSubCommand(arguments[1].toLowerCase()).isEmpty()) { + super.getSubCommand("help").orElseThrow().execute(commandSender, arguments); + return true; + } + return super.getSubCommand(arguments[1].toLowerCase()).get().execute(commandSender, arguments); + } + + @Override + public final List onTabComplete(@NotNull final CommandSender commandSender, @NotNull final Command command, + @NotNull final String commandLabel, @NotNull final String[] arguments) { + if (arguments.length == 2) { + return Lists.newArrayList(super.getSubCommands().keySet()); + } + + if (super.getSubCommand(arguments[1].toLowerCase()).isEmpty()) { + return Collections.emptyList(); + } + final BukkitCommand subCommand = super.getSubCommand(arguments[1].toLowerCase()).get(); + + if (!(subCommand instanceof TabCompleter)) { + return Collections.emptyList(); + } + return ((TabCompleter) subCommand).onTabComplete(commandSender, command, commandLabel, arguments); + } + +} diff --git a/multiperms-bukkit/src/main/java/com/dev7ex/multiperms/command/permission/HelpCommand.java b/multiperms-bukkit/src/main/java/com/dev7ex/multiperms/command/permission/HelpCommand.java new file mode 100644 index 0000000..6ee499e --- /dev/null +++ b/multiperms-bukkit/src/main/java/com/dev7ex/multiperms/command/permission/HelpCommand.java @@ -0,0 +1,28 @@ +package com.dev7ex.multiperms.command.permission; + +import com.dev7ex.common.bukkit.command.BukkitCommand; +import com.dev7ex.common.bukkit.command.CommandProperties; +import com.dev7ex.common.bukkit.plugin.BukkitPlugin; +import org.bukkit.command.CommandSender; +import org.jetbrains.annotations.NotNull; + +/** + * @author Dev7ex + * @since 03.07.2023 + */ +@CommandProperties(name = "help", permission = "multiperms.command.permission") +public class HelpCommand extends BukkitCommand { + + public HelpCommand(@NotNull final BukkitPlugin plugin) { + super(plugin); + } + + @Override + public boolean execute(@NotNull final CommandSender commandSender, @NotNull final String[] arguments) { + super.getConfiguration().getStringList("messages.commands.permission.help.message").forEach(message -> { + commandSender.sendMessage(message.replaceAll("%prefix%", super.getPrefix())); + }); + return true; + } + +} diff --git a/multiperms-bukkit/src/main/java/com/dev7ex/multiperms/command/permission/ReloadCommand.java b/multiperms-bukkit/src/main/java/com/dev7ex/multiperms/command/permission/ReloadCommand.java new file mode 100644 index 0000000..eb03e57 --- /dev/null +++ b/multiperms-bukkit/src/main/java/com/dev7ex/multiperms/command/permission/ReloadCommand.java @@ -0,0 +1,33 @@ +package com.dev7ex.multiperms.command.permission; + +import com.dev7ex.common.bukkit.command.BukkitCommand; +import com.dev7ex.common.bukkit.command.CommandProperties; +import com.dev7ex.common.bukkit.plugin.BukkitPlugin; +import org.bukkit.command.CommandSender; +import org.jetbrains.annotations.NotNull; + +/** + * @author Dev7ex + * @since 08.08.2023 + */ +@CommandProperties(name = "reload", permission = "multiperms.command.permission.reload") +public class ReloadCommand extends BukkitCommand { + + public ReloadCommand(@NotNull final BukkitPlugin plugin) { + super(plugin); + } + + @Override + public boolean execute(@NotNull final CommandSender commandSender, @NotNull final String[] arguments) { + if (arguments.length != 1) { + commandSender.sendMessage(super.getConfiguration().getString("messages.commands.permission.reload.usage") + .replaceAll("%prefix%", super.getPrefix())); + return true; + } + super.getConfiguration().load(); + commandSender.sendMessage(super.getConfiguration().getString("messages.commands.permission.reload.message") + .replaceAll("%prefix%", super.getPrefix())); + return true; + } + +} diff --git a/multiperms-bukkit/src/main/java/com/dev7ex/multiperms/command/permission/UserCommand.java b/multiperms-bukkit/src/main/java/com/dev7ex/multiperms/command/permission/UserCommand.java new file mode 100644 index 0000000..126d94d --- /dev/null +++ b/multiperms-bukkit/src/main/java/com/dev7ex/multiperms/command/permission/UserCommand.java @@ -0,0 +1,74 @@ +package com.dev7ex.multiperms.command.permission; + +import com.dev7ex.common.bukkit.command.BukkitCommand; +import com.dev7ex.common.bukkit.command.CommandProperties; +import com.dev7ex.common.bukkit.plugin.BukkitPlugin; +import com.dev7ex.multiperms.command.permission.user.*; +import com.google.common.collect.Lists; +import org.bukkit.Bukkit; +import org.bukkit.command.Command; +import org.bukkit.command.CommandSender; +import org.bukkit.command.TabCompleter; +import org.bukkit.entity.Player; +import org.jetbrains.annotations.NotNull; + +import java.util.Collections; +import java.util.List; + +/** + * @author Dev7ex + * @since 03.07.2023 + */ +@CommandProperties(name = "user", permission = "blockperms.command.permission.user") +public class UserCommand extends BukkitCommand implements TabCompleter { + + public UserCommand(@NotNull final BukkitPlugin plugin) { + super(plugin); + + super.registerSubCommand(new AddCommand(plugin)); + super.registerSubCommand(new ClearCommand(plugin)); + super.registerSubCommand(new InfoCommand(plugin)); + super.registerSubCommand(new HelpCommand(plugin)); + super.registerSubCommand(new RemoveCommand(plugin)); + super.registerSubCommand(new SetCommand(plugin)); + } + + @Override + public boolean execute(@NotNull final CommandSender commandSender, @NotNull final String[] arguments) { + if ((arguments.length == 1) || (arguments.length > 7)) { + return super.getSubCommand("help").orElseThrow().execute(commandSender, arguments); + } + + if (Bukkit.getPlayer(arguments[1]) == null) { + commandSender.sendMessage("player not found"); + return true; + } + + if (super.getSubCommand(arguments[2].toLowerCase()).isEmpty()) { + super.getSubCommand("help").orElseThrow().execute(commandSender, arguments); + return true; + } + return super.getSubCommand(arguments[2].toLowerCase()).get().execute(commandSender, arguments); + } + + @Override + public final List onTabComplete(@NotNull final CommandSender commandSender, @NotNull final Command command, + @NotNull final String commandLabel, @NotNull final String[] arguments) { + if (arguments.length == 2) { + return Bukkit.getOnlinePlayers().stream().map(Player::getName).toList(); + } + if (arguments.length == 3) { + return Lists.newArrayList(super.getSubCommands().keySet()); + } + if (super.getSubCommand(arguments[2].toLowerCase()).isEmpty()) { + return Collections.emptyList(); + } + final BukkitCommand subCommand = super.getSubCommand(arguments[2].toLowerCase()).get(); + + if (!(subCommand instanceof TabCompleter)) { + return Collections.emptyList(); + } + return ((TabCompleter) subCommand).onTabComplete(commandSender, command, commandLabel, arguments); + } + +} diff --git a/multiperms-bukkit/src/main/java/com/dev7ex/multiperms/command/permission/group/AddCommand.java b/multiperms-bukkit/src/main/java/com/dev7ex/multiperms/command/permission/group/AddCommand.java new file mode 100644 index 0000000..7bc909e --- /dev/null +++ b/multiperms-bukkit/src/main/java/com/dev7ex/multiperms/command/permission/group/AddCommand.java @@ -0,0 +1,73 @@ +package com.dev7ex.multiperms.command.permission.group; + +import com.dev7ex.common.bukkit.command.BukkitCommand; +import com.dev7ex.common.bukkit.command.CommandProperties; +import com.dev7ex.common.bukkit.plugin.BukkitPlugin; +import com.dev7ex.multiperms.MultiPermsPlugin; +import com.dev7ex.multiperms.api.group.PermissionGroup; +import com.dev7ex.multiperms.api.group.PermissionGroupProvider; +import org.bukkit.command.Command; +import org.bukkit.command.CommandSender; +import org.bukkit.command.TabCompleter; +import org.jetbrains.annotations.NotNull; + +import java.util.Collections; +import java.util.List; +import java.util.stream.Collectors; + +/** + * @author Dev7ex + * @since 03.07.2023 + */ +@CommandProperties(name = "add", permission = "multiperms.command.permission.group.add") +public class AddCommand extends BukkitCommand implements TabCompleter { + + public AddCommand(@NotNull final BukkitPlugin plugin) { + super(plugin); + } + + @Override + public boolean execute(@NotNull final CommandSender commandSender, @NotNull final String[] arguments) { + if (arguments.length != 4) { + commandSender.sendMessage(super.getConfiguration().getString("messages.commands.permission.group.add.usage") + .replaceAll("%prefix%", super.getPrefix())); + return true; + } + final PermissionGroupProvider groupProvider = MultiPermsPlugin.getInstance().getGroupProvider(); + + if (groupProvider.getGroup(arguments[2].toLowerCase()).isEmpty()) { + commandSender.sendMessage(super.getConfiguration().getString("messages.general.group-not-exists") + .replaceAll("%prefix%", super.getPrefix())); + return true; + } + final PermissionGroup group = groupProvider.getGroup(arguments[2].toLowerCase()).get(); + + if (group.getPermissions().contains(arguments[3])) { + commandSender.sendMessage(super.getConfiguration().getString("messages.commands.permission.group.add.group-has-permission") + .replaceAll("%prefix%", super.getPrefix()) + .replaceAll("%colored_group_name%", group.getColoredDisplayName()) + .replaceAll("%permission%", arguments[3])); + return true; + } + group.getPermissions().add(arguments[3]); + commandSender.sendMessage(super.getConfiguration().getString("messages.commands.permission.group.add.successfully-added") + .replaceAll("%prefix%", super.getPrefix()) + .replaceAll("%colored_group_name%", group.getColoredDisplayName()) + .replaceAll("%permission%", arguments[3])); + groupProvider.getConfiguration().addPermission(group.getIdentification(), arguments[3]); + return true; + } + + @Override + public final List onTabComplete(@NotNull final CommandSender commandSender, @NotNull final Command command, + @NotNull final String commandLabel, @NotNull final String[] arguments) { + if ((arguments.length < 3) || (arguments.length > 4)) { + return Collections.emptyList(); + } + if (arguments.length == 3) { + return MultiPermsPlugin.getInstance().getGroupProvider().getGroups().values().stream().map(PermissionGroup::getName).collect(Collectors.toList()); + } + return MultiPermsPlugin.getInstance().getPermissionHookProvider().getAllPermissions(); + } + +} \ No newline at end of file diff --git a/multiperms-bukkit/src/main/java/com/dev7ex/multiperms/command/permission/group/CreateCommand.java b/multiperms-bukkit/src/main/java/com/dev7ex/multiperms/command/permission/group/CreateCommand.java new file mode 100644 index 0000000..63de34d --- /dev/null +++ b/multiperms-bukkit/src/main/java/com/dev7ex/multiperms/command/permission/group/CreateCommand.java @@ -0,0 +1,76 @@ +package com.dev7ex.multiperms.command.permission.group; + +import com.dev7ex.common.bukkit.command.BukkitCommand; +import com.dev7ex.common.bukkit.command.CommandProperties; +import com.dev7ex.common.bukkit.plugin.BukkitPlugin; +import com.dev7ex.common.util.Numbers; +import com.dev7ex.multiperms.MultiPermsPlugin; +import com.dev7ex.multiperms.api.group.PermissionGroup; +import com.dev7ex.multiperms.api.group.PermissionGroupConfiguration; +import com.dev7ex.multiperms.api.group.PermissionGroupProvider; +import com.dev7ex.multiperms.group.Group; +import org.bukkit.command.CommandSender; +import org.jetbrains.annotations.NotNull; + +import java.util.Collections; + +/** + * @author Dev7ex + * @since 03.07.2023 + */ +@CommandProperties(name = "create", permission = "multiperms.command.permission.group.create") +public class CreateCommand extends BukkitCommand { + + public CreateCommand(@NotNull final BukkitPlugin plugin) { + super(plugin); + } + + @Override + public boolean execute(@NotNull final CommandSender commandSender, @NotNull final String[] arguments) { + if (arguments.length != 4) { + commandSender.sendMessage(super.getConfiguration().getString("messages.commands.permission.group.create.usage") + .replaceAll("%prefix%", super.getPrefix())); + return true; + } + final PermissionGroupProvider groupProvider = MultiPermsPlugin.getInstance().getGroupProvider(); + final PermissionGroupConfiguration groupConfiguration = MultiPermsPlugin.getInstance().getGroupConfiguration(); + + if (groupProvider.getGroup(arguments[2].toLowerCase()).isPresent()) { + commandSender.sendMessage(super.getConfiguration().getString("messages.commands.permission.group.create.group-already-exists") + .replaceAll("%prefix%", super.getPrefix())); + return true; + } + + if (!Numbers.isInteger(arguments[3])) { + commandSender.sendMessage(super.getConfiguration().getString("messages.general.invalid-identification") + .replaceAll("%prefix%", super.getPrefix())); + return true; + } + final int groupIdentification = Integer.parseInt(arguments[3]); + + if (groupProvider.getGroup(groupIdentification).isPresent()) { + commandSender.sendMessage(super.getConfiguration().getString("messages.commands.permission.group.create.group-already-exists-id") + .replaceAll("%prefix%", super.getPrefix())); + return true; + } + + final PermissionGroup group = Group.builder() + .setIdentification(groupIdentification) + .setName(arguments[2].toLowerCase()) + .setPermissions(Collections.emptyList()) + .setDisplayName(arguments[2]) + .setPriority(0) + .setColor('7') + .setChatPrefix("§8[§7" + arguments[2] + "§8]§7") + .setTablistPrefix("§8[§7" + arguments[2] + "§8]") + .build(); + + groupProvider.register(group); + groupConfiguration.add(group); + commandSender.sendMessage(super.getConfiguration().getString("messages.commands.permission.group.create.successfully-created") + .replaceAll("%prefix%", super.getPrefix()) + .replaceAll("%colored_group_name%", group.getColoredDisplayName())); + return true; + } + +} diff --git a/multiperms-bukkit/src/main/java/com/dev7ex/multiperms/command/permission/group/DeleteCommand.java b/multiperms-bukkit/src/main/java/com/dev7ex/multiperms/command/permission/group/DeleteCommand.java new file mode 100644 index 0000000..ddca087 --- /dev/null +++ b/multiperms-bukkit/src/main/java/com/dev7ex/multiperms/command/permission/group/DeleteCommand.java @@ -0,0 +1,71 @@ +package com.dev7ex.multiperms.command.permission.group; + +import com.dev7ex.common.bukkit.command.BukkitCommand; +import com.dev7ex.common.bukkit.command.CommandProperties; +import com.dev7ex.common.bukkit.plugin.BukkitPlugin; +import com.dev7ex.multiperms.MultiPermsPlugin; +import com.dev7ex.multiperms.api.bukkit.event.group.PermissionGroupDeleteEvent; +import com.dev7ex.multiperms.api.group.PermissionGroup; +import com.dev7ex.multiperms.api.group.PermissionGroupConfiguration; +import com.dev7ex.multiperms.api.group.PermissionGroupProvider; +import org.bukkit.Bukkit; +import org.bukkit.command.Command; +import org.bukkit.command.CommandSender; +import org.bukkit.command.TabCompleter; +import org.jetbrains.annotations.NotNull; + +import java.util.Collections; +import java.util.List; + +/** + * @author Dev7ex + * @since 03.07.2023 + */ +@CommandProperties(name = "delete", permission = "multiperms.command.permission.group.delete") +public class DeleteCommand extends BukkitCommand implements TabCompleter { + + public DeleteCommand(@NotNull final BukkitPlugin plugin) { + super(plugin); + } + + @Override + public boolean execute(@NotNull final CommandSender commandSender, @NotNull final String[] arguments) { + if (arguments.length != 3) { + commandSender.sendMessage(super.getConfiguration().getString("messages.commands.permission.group.create.usage") + .replaceAll("%prefix%", super.getPrefix())); + return true; + } + final PermissionGroupProvider groupProvider = MultiPermsPlugin.getInstance().getGroupProvider(); + final PermissionGroupConfiguration groupConfiguration = MultiPermsPlugin.getInstance().getGroupConfiguration(); + + if (groupProvider.getGroup(arguments[2].toLowerCase()).isEmpty()) { + commandSender.sendMessage(super.getConfiguration().getString("messages.general.group-not-exists") + .replaceAll("%prefix%", super.getPrefix())); + return true; + } + final PermissionGroup group = groupProvider.getGroup(arguments[2].toLowerCase()).get(); + final PermissionGroupDeleteEvent event = new PermissionGroupDeleteEvent(group); + + Bukkit.getPluginManager().callEvent(event); + + if (event.isCancelled()) { + return true; + } + groupProvider.unregister(group.getIdentification()); + groupConfiguration.remove(group.getIdentification()); + commandSender.sendMessage(super.getConfiguration().getString("messages.commands.permission.group.delete.successfully-deleted") + .replaceAll("%prefix%", super.getPrefix()) + .replaceAll("%colored_group_name%", group.getColoredDisplayName())); + return true; + } + + @Override + public final List onTabComplete(@NotNull final CommandSender commandSender, @NotNull final Command command, + @NotNull final String commandLabel, @NotNull final String[] arguments) { + if (arguments.length != 3) { + return Collections.emptyList(); + } + return MultiPermsPlugin.getInstance().getGroupProvider().getGroups().values().stream().map(PermissionGroup::getName).toList(); + } + +} diff --git a/multiperms-bukkit/src/main/java/com/dev7ex/multiperms/command/permission/group/EditCommand.java b/multiperms-bukkit/src/main/java/com/dev7ex/multiperms/command/permission/group/EditCommand.java new file mode 100644 index 0000000..2476946 --- /dev/null +++ b/multiperms-bukkit/src/main/java/com/dev7ex/multiperms/command/permission/group/EditCommand.java @@ -0,0 +1,129 @@ +package com.dev7ex.multiperms.command.permission.group; + +import com.dev7ex.common.bukkit.command.BukkitCommand; +import com.dev7ex.common.bukkit.command.CommandProperties; +import com.dev7ex.common.bukkit.plugin.BukkitPlugin; +import com.dev7ex.common.map.ParsedMap; +import com.dev7ex.multiperms.MultiPermsPlugin; +import com.dev7ex.multiperms.api.bukkit.event.group.PermissionGroupEditEvent; +import com.dev7ex.multiperms.api.group.PermissionGroup; +import com.dev7ex.multiperms.api.group.PermissionGroupConfiguration; +import com.dev7ex.multiperms.api.group.PermissionGroupProperty; +import com.dev7ex.multiperms.api.group.PermissionGroupProvider; +import org.bukkit.Bukkit; +import org.bukkit.ChatColor; +import org.bukkit.command.Command; +import org.bukkit.command.CommandSender; +import org.bukkit.command.TabCompleter; +import org.jetbrains.annotations.NotNull; + +import java.util.Arrays; +import java.util.Collections; +import java.util.List; +import java.util.Optional; +import java.util.stream.Collectors; + +/** + * @author Dev7ex + * @since 03.07.2023 + */ +@CommandProperties(name = "edit", permission = "multiperms.command.permission.group.edit") +public class EditCommand extends BukkitCommand implements TabCompleter { + + public EditCommand(@NotNull final BukkitPlugin plugin) { + super(plugin); + } + + @Override + public boolean execute(@NotNull final CommandSender commandSender, @NotNull final String[] arguments) { + if (arguments.length != 5) { + commandSender.sendMessage(super.getConfiguration().getString("messages.commands.permission.group.edit.usage") + .replaceAll("%prefix%", super.getPrefix())); + return true; + } + final PermissionGroupProvider groupProvider = MultiPermsPlugin.getInstance().getGroupProvider(); + final PermissionGroupConfiguration groupConfiguration = MultiPermsPlugin.getInstance().getGroupConfiguration(); + + if (groupProvider.getGroup(arguments[2].toLowerCase()).isEmpty()) { + commandSender.sendMessage(super.getConfiguration().getString("messages.general.group-not-exists") + .replaceAll("%prefix%", super.getPrefix())); + return true; + } + final PermissionGroup permissionGroup = groupProvider.getGroup(arguments[2].toLowerCase()).get(); + final Optional propertyOptional = PermissionGroupProperty.fromString(arguments[3].toUpperCase()); + final ParsedMap groupData = new ParsedMap<>(); + + if (propertyOptional.isEmpty()) { + commandSender.sendMessage(super.getConfiguration().getString("messages.commands.permission.group.edit.property-not-exists") + .replaceAll("%prefix%", super.getPrefix())); + return true; + } + final PermissionGroupProperty property = propertyOptional.get(); + + final PermissionGroupEditEvent event = new PermissionGroupEditEvent(permissionGroup, property, arguments[4]); + Bukkit.getPluginManager().callEvent(event); + + if (property == PermissionGroupProperty.PERMISSIONS) { + commandSender.sendMessage(super.getConfiguration().getString("messages.general.function-not-available") + .replaceAll("%prefix%", super.getPrefix())); + return true; + } + + switch (property) { + case DISPLAY_NAME -> { + permissionGroup.setDisplayName(arguments[4]); + groupData.put(PermissionGroupProperty.DISPLAY_NAME, arguments[4]); + break; + } + case TABLIST_PREFIX -> { + permissionGroup.setTablistPrefix(arguments[4]); + groupData.put(PermissionGroupProperty.TABLIST_PREFIX, arguments[4]); + break; + } + case COLOR -> { + if (ChatColor.getByChar(arguments[4].replaceAll("§", "").charAt(0)) == null) { + commandSender.sendMessage(super.getConfiguration().getString("messages.commands.permission.group.edit.invalid-color") + .replaceAll("%prefix%", super.getPrefix())); + return true; + } + permissionGroup.setColor(arguments[4].charAt(0)); + groupData.put(PermissionGroupProperty.COLOR, arguments[4].charAt(0)); + break; + } + case PRIORITY -> { + permissionGroup.setPriority(Integer.parseInt(arguments[4])); + groupData.put(PermissionGroupProperty.PRIORITY, arguments[4]); + break; + } + case CHAT_PREFIX -> { + permissionGroup.setChatPrefix(arguments[4]); + groupData.put(PermissionGroupProperty.CHAT_PREFIX, arguments[4]); + break; + } + } + commandSender.sendMessage(super.getConfiguration().getString("messages.commands.permission.group.edit.successfully-edited") + .replaceAll("%prefix%", super.getPrefix()) + .replaceAll("%group_property%", property.toString()) + .replaceAll("%value%", arguments[4])); + groupProvider.saveGroup(permissionGroup); + return true; + } + + @Override + public final List onTabComplete(@NotNull final CommandSender commandSender, @NotNull final Command command, + @NotNull final String commandLabel, @NotNull final String[] arguments) { + if (arguments.length == 3) { + return MultiPermsPlugin.getInstance().getGroupProvider().getGroups().values().stream().map(PermissionGroup::getName).toList(); + } + + if (arguments.length == 4) { + return PermissionGroupProperty.toStringList(); + } + + if ((arguments.length == 5) && (arguments[3].equalsIgnoreCase(PermissionGroupProperty.COLOR.toString()))) { + return Arrays.stream(ChatColor.values()).map(ChatColor::getChar).map(Object::toString).collect(Collectors.toList()); + } + return Collections.emptyList(); + } + +} diff --git a/multiperms-bukkit/src/main/java/com/dev7ex/multiperms/command/permission/group/ListCommand.java b/multiperms-bukkit/src/main/java/com/dev7ex/multiperms/command/permission/group/ListCommand.java new file mode 100644 index 0000000..0021993 --- /dev/null +++ b/multiperms-bukkit/src/main/java/com/dev7ex/multiperms/command/permission/group/ListCommand.java @@ -0,0 +1,50 @@ +package com.dev7ex.multiperms.command.permission.group; + +import com.dev7ex.common.bukkit.command.BukkitCommand; +import com.dev7ex.common.bukkit.command.CommandProperties; +import com.dev7ex.common.bukkit.plugin.BukkitPlugin; +import com.dev7ex.multiperms.MultiPermsPlugin; +import com.dev7ex.multiperms.api.group.PermissionGroup; +import net.md_5.bungee.api.ChatColor; +import org.bukkit.command.CommandSender; +import org.jetbrains.annotations.NotNull; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +/** + * @author Dev7ex + * @since 03.07.2023 + */ +@CommandProperties(name = "list", permission = "multiperms.command.permission.group.list") +public class ListCommand extends BukkitCommand { + + public ListCommand(@NotNull final BukkitPlugin plugin) { + super(plugin); + } + + @Override + public boolean execute(@NotNull final CommandSender commandSender, @NotNull final String[] arguments) { + if (arguments.length != 2) { + commandSender.sendMessage(super.getPrefix() + "§cUsage: /permission group list"); + return true; + } + final StringBuilder stringBuilder = new StringBuilder(); + final List groups = new ArrayList<>(MultiPermsPlugin.getInstance().getGroupProvider().getGroups().values()); + Collections.sort(groups); + + for (final PermissionGroup group : groups) { + if (stringBuilder.length() > 0) { + stringBuilder.append(ChatColor.GRAY); + stringBuilder.append(", "); + } + stringBuilder.append(group.getColoredDisplayName()); + } + commandSender.sendMessage(super.getConfiguration().getString("messages.commands.permission.group.list.message") + .replaceAll("%prefix%", super.getPrefix()) + .replaceAll("%colored_group_names%", stringBuilder.toString())); + return true; + } + +} diff --git a/multiperms-bukkit/src/main/java/com/dev7ex/multiperms/command/permission/group/RemoveCommand.java b/multiperms-bukkit/src/main/java/com/dev7ex/multiperms/command/permission/group/RemoveCommand.java new file mode 100644 index 0000000..536028a --- /dev/null +++ b/multiperms-bukkit/src/main/java/com/dev7ex/multiperms/command/permission/group/RemoveCommand.java @@ -0,0 +1,85 @@ +package com.dev7ex.multiperms.command.permission.group; + +import com.dev7ex.common.bukkit.command.BukkitCommand; +import com.dev7ex.common.bukkit.command.CommandProperties; +import com.dev7ex.common.bukkit.plugin.BukkitPlugin; +import com.dev7ex.multiperms.MultiPermsPlugin; +import com.dev7ex.multiperms.api.group.PermissionGroup; +import com.dev7ex.multiperms.api.group.PermissionGroupConfiguration; +import com.dev7ex.multiperms.api.group.PermissionGroupProvider; +import org.bukkit.command.Command; +import org.bukkit.command.CommandSender; +import org.bukkit.command.TabCompleter; +import org.jetbrains.annotations.NotNull; + +import java.util.Collections; +import java.util.List; +import java.util.stream.Collectors; + +/** + * @author Dev7ex + * @since 03.07.2023 + */ +@CommandProperties(name = "remove", permission = "multiperms.command.permission.group.remove") +public class RemoveCommand extends BukkitCommand implements TabCompleter { + + public RemoveCommand(@NotNull final BukkitPlugin plugin) { + super(plugin); + } + + @Override + public boolean execute(@NotNull final CommandSender commandSender, @NotNull final String[] arguments) { + if (arguments.length != 4) { + commandSender.sendMessage(super.getConfiguration().getString("messages.commands.permission.group.remove.usage") + .replaceAll("%prefix%", super.getPrefix())); + return true; + } + final PermissionGroupProvider groupProvider = MultiPermsPlugin.getInstance().getGroupProvider(); + final PermissionGroupConfiguration groupConfiguration = MultiPermsPlugin.getInstance().getGroupConfiguration(); + + if (groupProvider.getGroup(arguments[2].toLowerCase()).isEmpty()) { + commandSender.sendMessage(super.getConfiguration().getString("messages.general.group-not-exists") + .replaceAll("%prefix%", super.getPrefix())); + return true; + } + final PermissionGroup group = groupProvider.getGroup(arguments[2].toLowerCase()).get(); + + if (!group.getPermissions().contains(arguments[3])) { + commandSender.sendMessage(super.getConfiguration().getString("messages.commands.permission.group.remove.group-has-permission-not") + .replaceAll("%prefix%", super.getPrefix()) + .replaceAll("%colored_group_name%", group.getColoredDisplayName()) + .replaceAll("%permission%", arguments[3])); + return true; + } + group.getPermissions().remove(arguments[3]); + groupConfiguration.removePermission(group.getIdentification(), arguments[3]); + commandSender.sendMessage(super.getConfiguration().getString("messages.commands.permission.group.remove.successfully-removed") + .replaceAll("%prefix%", super.getPrefix()) + .replaceAll("%colored_group_name%", group.getColoredDisplayName()) + .replaceAll("%permission%", arguments[3])); + return true; + } + + @Override + public final List onTabComplete(@NotNull final CommandSender commandSender, @NotNull final Command command, + @NotNull final String commandLabel, @NotNull final String[] arguments) { + if ((arguments.length < 3) || (arguments.length > 4)) { + return Collections.emptyList(); + } + + if (arguments.length == 3) { + return MultiPermsPlugin.getInstance().getGroupProvider() + .getGroups() + .values() + .stream() + .map(PermissionGroup::getName) + .collect(Collectors.toList()); + } + + if (MultiPermsPlugin.getInstance().getGroupProvider().getGroup(arguments[2].toLowerCase()).isEmpty()) { + return Collections.emptyList(); + } + return MultiPermsPlugin.getInstance().getGroupProvider().getGroup(arguments[2].toLowerCase()).get().getPermissions(); + } + +} \ No newline at end of file diff --git a/multiperms-bukkit/src/main/java/com/dev7ex/multiperms/command/permission/user/AddCommand.java b/multiperms-bukkit/src/main/java/com/dev7ex/multiperms/command/permission/user/AddCommand.java new file mode 100644 index 0000000..9d6531e --- /dev/null +++ b/multiperms-bukkit/src/main/java/com/dev7ex/multiperms/command/permission/user/AddCommand.java @@ -0,0 +1,112 @@ +package com.dev7ex.multiperms.command.permission.user; + +import com.dev7ex.common.bukkit.command.BukkitCommand; +import com.dev7ex.common.bukkit.command.CommandProperties; +import com.dev7ex.common.bukkit.plugin.BukkitPlugin; +import com.dev7ex.multiperms.MultiPermsPlugin; +import com.dev7ex.multiperms.api.group.PermissionGroup; +import com.dev7ex.multiperms.api.group.PermissionGroupProvider; +import com.dev7ex.multiperms.api.user.PermissionUser; +import org.bukkit.command.Command; +import org.bukkit.command.CommandSender; +import org.bukkit.command.TabCompleter; +import org.jetbrains.annotations.NotNull; + +import java.util.Collections; +import java.util.List; + +/** + * @author Dev7ex + * @since 03.07.2023 + */ +@CommandProperties(name = "add", permission = "multiperms.command.permission.user.add") +public class AddCommand extends BukkitCommand implements TabCompleter { + + public AddCommand(@NotNull final BukkitPlugin plugin) { + super(plugin); + } + + @Override + public boolean execute(@NotNull final CommandSender commandSender, @NotNull final String[] arguments) { + if (arguments.length != 5) { + commandSender.sendMessage(super.getConfiguration().getString("messages.commands.permission.user.add.usage") + .replaceAll("%prefix%", super.getPrefix())); + return true; + } + + final PermissionGroupProvider groupProvider = MultiPermsPlugin.getInstance().getGroupProvider(); + final PermissionUser user = MultiPermsPlugin.getInstance().getUserProvider().getUser(arguments[1]).orElseThrow(); + + switch (arguments[3]) { + case "group": + if (groupProvider.getGroup(arguments[4].toLowerCase()).isEmpty()) { + commandSender.sendMessage(super.getConfiguration().getString("messages.general.group-not-exists") + .replaceAll("%prefix%", super.getPrefix())); + return true; + } + final PermissionGroup group = groupProvider.getGroup(arguments[4].toLowerCase()).get(); + + if (user.getGroup().getIdentification() == group.getIdentification()) { + commandSender.sendMessage(super.getConfiguration().getString("messages.commands.permission.user.add.group.main-group") + .replaceAll("%prefix%", super.getPrefix()) + .replaceAll("%colored_user_name%", user.getColoredName())); + return true; + } + + if (user.getSubGroups().contains(group)) { + commandSender.sendMessage(super.getConfiguration().getString("messages.commands.permission.user.add.group.user-has-group") + .replaceAll("%prefix%", super.getPrefix()) + .replaceAll("%colored_user_name%", user.getColoredName())); + return true; + } + user.getSubGroups().add(group); + commandSender.sendMessage(super.getConfiguration().getString("messages.commands.permission.user.add.group.successfully-added") + .replaceAll("%prefix%", super.getPrefix()) + .replaceAll("%colored_user_name%", user.getColoredName()) + .replaceAll("%colored_group_name%", group.getColoredDisplayName())); + break; + + case "permission": + if (user.hasPermission(arguments[4])) { + commandSender.sendMessage(super.getConfiguration().getString("messages.commands.permission.user.add.permission.user-has-permission") + .replaceAll("%prefix%", super.getPrefix()) + .replaceAll("%colored_user_name%", user.getColoredName())); + return true; + } + user.getConfiguration().addPermission(arguments[4]); + user.addPermission(arguments[4]); + commandSender.sendMessage(super.getConfiguration().getString("messages.commands.permission.user.add.permission.successfully-added") + .replaceAll("%prefix%", super.getPrefix()) + .replaceAll("%colored_user_name%", user.getColoredName()) + .replaceAll("%permission%", arguments[4])); + break; + } + + return true; + } + + @Override + public final List onTabComplete(@NotNull final CommandSender commandSender, @NotNull final Command command, + @NotNull final String commandLabel, @NotNull final String[] arguments) { + + if (arguments.length < 4 || arguments.length > 5) { + return Collections.emptyList(); + } + + if (arguments.length == 4) { + return List.of("group", "permission"); + } + + switch (arguments[3]) { + case "group": + return MultiPermsPlugin.getInstance().getGroupProvider().getGroups().values().stream().map(PermissionGroup::getName).toList(); + + case "permission": + return MultiPermsPlugin.getInstance().getPermissionHookProvider().getAllPermissions(); + + default: + return Collections.emptyList(); + } + } + +} diff --git a/multiperms-bukkit/src/main/java/com/dev7ex/multiperms/command/permission/user/ClearCommand.java b/multiperms-bukkit/src/main/java/com/dev7ex/multiperms/command/permission/user/ClearCommand.java new file mode 100644 index 0000000..d51b437 --- /dev/null +++ b/multiperms-bukkit/src/main/java/com/dev7ex/multiperms/command/permission/user/ClearCommand.java @@ -0,0 +1,81 @@ +package com.dev7ex.multiperms.command.permission.user; + +import com.dev7ex.common.bukkit.command.BukkitCommand; +import com.dev7ex.common.bukkit.command.CommandProperties; +import com.dev7ex.common.bukkit.plugin.BukkitPlugin; +import com.dev7ex.multiperms.MultiPermsPlugin; +import com.dev7ex.multiperms.api.group.PermissionGroupProvider; +import com.dev7ex.multiperms.api.user.PermissionUser; +import com.dev7ex.multiperms.api.user.PermissionUserProperty; +import org.bukkit.command.Command; +import org.bukkit.command.CommandSender; +import org.bukkit.command.TabCompleter; +import org.jetbrains.annotations.NotNull; + +import java.util.Collections; +import java.util.List; + +/** + * @author Dev7ex + * @since 03.07.2023 + */ +@CommandProperties(name = "clear", permission = "multiperms.command.permission.user.clear") +public class ClearCommand extends BukkitCommand implements TabCompleter { + + public ClearCommand(@NotNull final BukkitPlugin plugin) { + super(plugin); + } + + @Override + public boolean execute(@NotNull final CommandSender commandSender, @NotNull final String[] arguments) { + if (arguments.length != 4) { + commandSender.sendMessage(super.getConfiguration().getString("messages.commands.permission.user.clear.usage") + .replaceAll("%prefix%", super.getPrefix())); + return true; + } + final PermissionGroupProvider groupProvider = MultiPermsPlugin.getInstance().getGroupProvider(); + final PermissionUser user = MultiPermsPlugin.getInstance().getUserProvider().getUser(arguments[1]).orElseThrow(); + + switch (arguments[3]) { + case "group": + if (user.getSubGroups().isEmpty()) { + commandSender.sendMessage(super.getConfiguration().getString("messages.commands.permission.user.clear.group.user-groups-empty") + .replaceAll("%prefix%", super.getPrefix()) + .replaceAll("%colored_user_name%", user.getColoredName())); + return true; + } + user.getSubGroups().clear(); + user.getConfiguration().write(PermissionUserProperty.SUB_GROUPS, Collections.emptyList()); + commandSender.sendMessage(super.getConfiguration().getString("messages.commands.permission.user.clear.group.successfully-cleared") + .replaceAll("%prefix%", super.getPrefix()) + .replaceAll("%colored_user_name%", user.getColoredName())); + return true; + + case "permission": + if (user.getPermissions().isEmpty()) { + commandSender.sendMessage(super.getConfiguration().getString("messages.commands.permission.user.clear.permission.user-permissions-empty") + .replaceAll("%prefix%", super.getPrefix()) + .replaceAll("%colored_user_name%", user.getColoredName())); + return true; + } + user.getPermissions().clear(); + user.getConfiguration().write(PermissionUserProperty.PERMISSION, Collections.emptyList()); + commandSender.sendMessage(super.getConfiguration().getString("messages.commands.permission.user.clear.permission.successfully-cleared") + .replaceAll("%prefix%", super.getPrefix()) + .replaceAll("%colored_user_name%", user.getColoredName())); + } + + return true; + } + + @Override + public final List onTabComplete(@NotNull final CommandSender commandSender, @NotNull final Command command, + @NotNull final String commandLabel, @NotNull final String[] arguments) { + + if (arguments.length == 4) { + return List.of("group", "permission"); + } + return null; + } + +} diff --git a/multiperms-bukkit/src/main/java/com/dev7ex/multiperms/command/permission/user/InfoCommand.java b/multiperms-bukkit/src/main/java/com/dev7ex/multiperms/command/permission/user/InfoCommand.java new file mode 100644 index 0000000..e15d9cd --- /dev/null +++ b/multiperms-bukkit/src/main/java/com/dev7ex/multiperms/command/permission/user/InfoCommand.java @@ -0,0 +1,75 @@ +package com.dev7ex.multiperms.command.permission.user; + +import com.dev7ex.common.bukkit.command.BukkitCommand; +import com.dev7ex.common.bukkit.command.CommandProperties; +import com.dev7ex.common.bukkit.plugin.BukkitPlugin; +import com.dev7ex.multiperms.MultiPermsPlugin; +import com.dev7ex.multiperms.api.group.PermissionGroup; +import com.dev7ex.multiperms.api.user.PermissionUser; +import net.md_5.bungee.api.ChatColor; +import org.bukkit.command.CommandSender; +import org.jetbrains.annotations.NotNull; + +/** + * @author Dev7ex + * @since 03.07.2023 + */ +@CommandProperties(name = "info", permission = "multiperms.command.permission.user.info") +public class InfoCommand extends BukkitCommand { + + public InfoCommand(@NotNull final BukkitPlugin plugin) { + super(plugin); + } + + @Override + public boolean execute(@NotNull final CommandSender commandSender, @NotNull final String[] arguments) { + final PermissionUser user = MultiPermsPlugin.getInstance().getUserProvider().getUser(arguments[1]).orElseThrow(); + + super.getConfiguration().getStringList("messages.commands.permission.user.info.message").forEach(message -> { + commandSender.sendMessage(message.replaceAll("%prefix%", super.getPrefix()) + .replaceAll("%unique_id%", user.getUniqueId().toString()) + .replaceAll("%colored_user_name%", user.getColoredName()) + .replaceAll("%colored_group_name%", user.getGroup().getColoredDisplayName()) + .replaceAll("%colored_group_names%", this.formatSubGroups(user)) + .replaceAll("%permissions%", this.formatPermissions(user))); + }); + return true; + } + + public final String formatSubGroups(final PermissionUser user) { + final StringBuilder stringBuilder = new StringBuilder(); + + if (user.getSubGroups().isEmpty()) { + return "{}"; + } + + for (final PermissionGroup group : user.getSubGroups()) { + if (stringBuilder.length() > 0) { + stringBuilder.append(ChatColor.GRAY); + stringBuilder.append(", "); + } + stringBuilder.append(group.getColoredDisplayName()); + } + return stringBuilder.toString(); + } + + public final String formatPermissions(final PermissionUser user) { + final StringBuilder stringBuilder = new StringBuilder(); + + if (user.getPermissions().isEmpty()) { + return "{}"; + } + + + for (final String permission : user.getPermissions()) { + if (stringBuilder.length() > 0) { + stringBuilder.append(ChatColor.GRAY); + stringBuilder.append(", "); + } + stringBuilder.append(ChatColor.GREEN + permission); + } + + return stringBuilder.toString(); + } + +} diff --git a/multiperms-bukkit/src/main/java/com/dev7ex/multiperms/command/permission/user/RemoveCommand.java b/multiperms-bukkit/src/main/java/com/dev7ex/multiperms/command/permission/user/RemoveCommand.java new file mode 100644 index 0000000..81eb266 --- /dev/null +++ b/multiperms-bukkit/src/main/java/com/dev7ex/multiperms/command/permission/user/RemoveCommand.java @@ -0,0 +1,118 @@ +package com.dev7ex.multiperms.command.permission.user; + +import com.dev7ex.common.bukkit.command.BukkitCommand; +import com.dev7ex.common.bukkit.command.CommandProperties; +import com.dev7ex.common.bukkit.plugin.BukkitPlugin; +import com.dev7ex.multiperms.MultiPermsPlugin; +import com.dev7ex.multiperms.api.group.PermissionGroup; +import com.dev7ex.multiperms.api.group.PermissionGroupProvider; +import com.dev7ex.multiperms.api.user.PermissionUser; +import org.bukkit.command.Command; +import org.bukkit.command.CommandSender; +import org.bukkit.command.TabCompleter; +import org.jetbrains.annotations.NotNull; + +import java.util.Collections; +import java.util.List; +import java.util.stream.Collectors; + +/** + * @author Dev7ex + * @since 03.07.2023 + */ +@CommandProperties(name = "remove", permission = "multiperms.command.user.remove") +public class RemoveCommand extends BukkitCommand implements TabCompleter { + + public RemoveCommand(@NotNull final BukkitPlugin plugin) { + super(plugin); + } + + @Override + public boolean execute(@NotNull final CommandSender commandSender, @NotNull final String[] arguments) { + if (arguments.length != 5) { + commandSender.sendMessage(super.getConfiguration().getString("messages.commands.permission.user.remove.usage") + .replaceAll("%prefix%", super.getPrefix())); + return true; + } + + final PermissionGroupProvider groupProvider = MultiPermsPlugin.getInstance().getGroupProvider(); + final PermissionUser user = MultiPermsPlugin.getInstance().getUserProvider().getUser(arguments[1]).orElseThrow(); + + switch (arguments[3]) { + case "group": + if (groupProvider.getGroup(arguments[4].toLowerCase()).isEmpty()) { + commandSender.sendMessage(super.getConfiguration().getString("messages.general.group-not-exists") + .replaceAll("%prefix%", super.getPrefix())); + return true; + } + final PermissionGroup group = groupProvider.getGroup(arguments[4].toLowerCase()).get(); + + if (user.getGroup().getIdentification() == group.getIdentification()) { + commandSender.sendMessage(super.getConfiguration().getString("messages.commands.permission.user.remove.group.main-group") + .replaceAll("%prefix%", super.getPrefix()) + .replaceAll("%colored_user_name%", user.getColoredName())); + return true; + } + + if (!user.getSubGroups().contains(group)) { + commandSender.sendMessage(super.getConfiguration().getString("messages.commands.permission.user.remove.group.user-has-group-not") + .replaceAll("%prefix%", super.getPrefix()) + .replaceAll("%colored_user_name%", user.getColoredName()) + .replaceAll("%colored_group_name%", group.getColoredDisplayName())); + return true; + } + user.getSubGroups().remove(group); + commandSender.sendMessage(super.getConfiguration().getString("messages.commands.permission.user.remove.group.successfully-removed") + .replaceAll("%prefix%", super.getPrefix()) + .replaceAll("%colored_user_name%", user.getColoredName()) + .replaceAll("%colored_group_name%", group.getColoredDisplayName())); + break; + + case "permission": + if (!user.hasPermission(arguments[4])) { + commandSender.sendMessage(super.getConfiguration().getString("messages.commands.permission.user.remove.permission.user-has-permission-not") + .replaceAll("%prefix%", super.getPrefix()) + .replaceAll("%colored_user_name%", user.getColoredName())); + return true; + } + user.getConfiguration().addPermission(arguments[4]); + user.addPermission(arguments[4]); + commandSender.sendMessage(super.getConfiguration().getString("messages.commands.permission.user.remove.permission.successfully-removed") + .replaceAll("%prefix%", super.getPrefix()) + .replaceAll("%colored_user_name%", user.getColoredName()) + .replaceAll("%permission%", arguments[4])); + break; + } + + return true; + } + + @Override + public final List onTabComplete(@NotNull final CommandSender commandSender, @NotNull final Command command, + @NotNull final String commandLabel, @NotNull final String[] arguments) { + if ((arguments.length < 4) || (arguments.length > 5)) { + return Collections.emptyList(); + } + + if (arguments.length == 4) { + return List.of("group", "permission"); + } + + if (MultiPermsPlugin.getInstance().getUserProvider().getUser(arguments[1]).isEmpty()) { + return Collections.emptyList(); + } + final PermissionUser user = MultiPermsPlugin.getInstance().getUserProvider().getUser(arguments[1]).orElseThrow(); + + switch (arguments[3]) { + case "group": + return user.getSubGroups().stream().map(PermissionGroup::getName).collect(Collectors.toList()); + + case "permission": + return user.getAllPermissions(); + + default: + return Collections.emptyList(); + } + } + +} diff --git a/multiperms-bukkit/src/main/java/com/dev7ex/multiperms/command/permission/user/SetCommand.java b/multiperms-bukkit/src/main/java/com/dev7ex/multiperms/command/permission/user/SetCommand.java new file mode 100644 index 0000000..5505945 --- /dev/null +++ b/multiperms-bukkit/src/main/java/com/dev7ex/multiperms/command/permission/user/SetCommand.java @@ -0,0 +1,81 @@ +package com.dev7ex.multiperms.command.permission.user; + +import com.dev7ex.common.bukkit.command.BukkitCommand; +import com.dev7ex.common.bukkit.command.CommandProperties; +import com.dev7ex.common.bukkit.plugin.BukkitPlugin; +import com.dev7ex.multiperms.MultiPermsPlugin; +import com.dev7ex.multiperms.api.bukkit.event.user.PermissionUserGroupSetEvent; +import com.dev7ex.multiperms.api.group.PermissionGroup; +import com.dev7ex.multiperms.api.group.PermissionGroupProvider; +import com.dev7ex.multiperms.api.user.PermissionUser; +import com.dev7ex.multiperms.api.user.PermissionUserProperty; +import org.bukkit.Bukkit; +import org.bukkit.command.Command; +import org.bukkit.command.CommandSender; +import org.bukkit.command.TabCompleter; +import org.jetbrains.annotations.NotNull; + +import java.util.Collections; +import java.util.List; + +/** + * @author Dev7ex + * @since 03.07.2023 + */ +@CommandProperties(name = "set", permission = "multiperms.command.permission.user.set") +public class SetCommand extends BukkitCommand implements TabCompleter { + + public SetCommand(@NotNull final BukkitPlugin plugin) { + super(plugin); + } + + @Override + public boolean execute(@NotNull final CommandSender commandSender, @NotNull final String[] arguments) { + // /permission user set + if (arguments.length != 4) { + commandSender.sendMessage(super.getConfiguration().getString("messages.commands.permission.user.set.usage") + .replaceAll("%prefix%", super.getPrefix())); + return true; + } + final PermissionUser user = MultiPermsPlugin.getInstance().getUserProvider().getUser(arguments[1]).orElseThrow(); + final PermissionGroupProvider groupProvider = MultiPermsPlugin.getInstance().getGroupProvider(); + + if (groupProvider.getGroup(arguments[3].toLowerCase()).isEmpty()) { + commandSender.sendMessage(super.getConfiguration().getString("messages.general.group-not-exists") + .replaceAll("%prefix%", super.getPrefix())); + return true; + } + final PermissionGroup group = groupProvider.getGroup(arguments[3].toLowerCase()).get(); + + if (user.getGroup().getName().equalsIgnoreCase(arguments[3])) { + commandSender.sendMessage(super.getConfiguration().getString("messages.commands.permission.user.set.user-has-group") + .replaceAll("%prefix%", super.getPrefix()) + .replaceAll("%colored_user_name%", user.getColoredName()) + .replaceAll("%colored_group_name%", group.getColoredDisplayName())); + return true; + } + + user.getSubGroups().removeIf(removeIf -> user.getSubGroups().contains(group)); + + Bukkit.getPluginManager().callEvent(new PermissionUserGroupSetEvent(user, group)); + user.setGroup(group); + MultiPermsPlugin.getInstance().getUserProvider().saveUser(user, PermissionUserProperty.GROUP); + MultiPermsPlugin.getInstance().getScoreboardProvider().updateNameTags(Bukkit.getPlayer(user.getUniqueId()), user); + commandSender.sendMessage(super.getConfiguration().getString("messages.commands.permission.user.set.successfully-set") + .replaceAll("%prefix%", super.getPrefix()) + .replaceAll("%colored_user_name%", user.getColoredName()) + .replaceAll("%colored_group_name%", group.getColoredDisplayName())); + return true; + } + + @Override + public final List onTabComplete(@NotNull final CommandSender commandSender, @NotNull final Command command, + @NotNull final String commandLabel, @NotNull final String[] arguments) { + + if (arguments.length != 4) { + return Collections.emptyList(); + } + return MultiPermsPlugin.getInstance().getGroupProvider().getGroups().values().stream().map(PermissionGroup::getName).toList(); + } + +} diff --git a/multiperms-bukkit/src/main/java/com/dev7ex/multiperms/group/Group.java b/multiperms-bukkit/src/main/java/com/dev7ex/multiperms/group/Group.java new file mode 100644 index 0000000..c1677bd --- /dev/null +++ b/multiperms-bukkit/src/main/java/com/dev7ex/multiperms/group/Group.java @@ -0,0 +1,42 @@ +package com.dev7ex.multiperms.group; + +import com.dev7ex.multiperms.api.group.PermissionGroup; +import lombok.AccessLevel; +import lombok.Builder; +import lombok.Getter; +import lombok.Setter; +import net.md_5.bungee.api.ChatColor; +import org.jetbrains.annotations.NotNull; + +import java.util.ArrayList; +import java.util.List; + +/** + * @author Dev7ex + * @since 03.07.2023 + */ +@Getter(AccessLevel.PUBLIC) +@Setter(AccessLevel.PUBLIC) +@Builder(setterPrefix = "set") +public class Group implements PermissionGroup { + + private int identification; + private String name; + private String displayName; + private char color; + private int priority; + private String tablistPrefix; + private String chatPrefix; + private List permissions = new ArrayList<>(); + + @Override + public String getColoredDisplayName() { + return (ChatColor.getByChar(this.color) + this.displayName); + } + + @Override + public boolean hasPermission(@NotNull final String permission) { + return (this.permissions.contains("*")) || (this.permissions.contains(permission)); + } + +} diff --git a/multiperms-bukkit/src/main/java/com/dev7ex/multiperms/group/GroupConfiguration.java b/multiperms-bukkit/src/main/java/com/dev7ex/multiperms/group/GroupConfiguration.java new file mode 100644 index 0000000..7869323 --- /dev/null +++ b/multiperms-bukkit/src/main/java/com/dev7ex/multiperms/group/GroupConfiguration.java @@ -0,0 +1,217 @@ +package com.dev7ex.multiperms.group; + +import com.dev7ex.common.bukkit.configuration.ConfigurationBase; +import com.dev7ex.common.bukkit.configuration.ConfigurationProperties; +import com.dev7ex.common.map.ParsedMap; +import com.dev7ex.multiperms.api.group.PermissionGroup; +import com.dev7ex.multiperms.api.group.PermissionGroupConfiguration; +import com.dev7ex.multiperms.api.group.PermissionGroupProperty; +import org.bukkit.plugin.Plugin; +import org.jetbrains.annotations.NotNull; + +import java.util.*; + +/** + * @author Dev7ex + * @since 03.07.2023 + */ +@ConfigurationProperties(fileName = "group.yml") +public class GroupConfiguration extends ConfigurationBase implements PermissionGroupConfiguration { + + public GroupConfiguration(@NotNull final Plugin plugin) { + super(plugin); + } + + public void load() { + super.loadFile(); + + if (!this.contains(0)) { + this.add(Group.builder() + .setIdentification(0) + .setName("default") + .setDisplayName("User") + .setColor('7') + .setPriority(0) + .setTablistPrefix("§8[§7User§8] §7") + .setChatPrefix("§8[§7User§8]§7") + .setPermissions(Collections.emptyList()) + .build()); + } + } + + @Override + public void add(@NotNull final PermissionGroup group) { + super.getFileConfiguration().set(group.getIdentification() + "." + PermissionGroupProperty.NAME.getStoragePath(), group.getName()); + super.getFileConfiguration().set(group.getIdentification() + "." + PermissionGroupProperty.DISPLAY_NAME.getStoragePath(), group.getDisplayName()); + super.getFileConfiguration().set(group.getIdentification() + "." + PermissionGroupProperty.COLOR.getStoragePath(), group.getColor()); + super.getFileConfiguration().set(group.getIdentification() + "." + PermissionGroupProperty.PRIORITY.getStoragePath(), group.getPriority()); + super.getFileConfiguration().set(group.getIdentification() + "." + PermissionGroupProperty.TABLIST_PREFIX.getStoragePath(), group.getTablistPrefix()); + super.getFileConfiguration().set(group.getIdentification() + "." + PermissionGroupProperty.CHAT_PREFIX.getStoragePath(), group.getChatPrefix()); + super.getFileConfiguration().set(group.getIdentification() + "." + PermissionGroupProperty.PERMISSIONS.getStoragePath(), group.getPermissions()); + this.saveFile(); + } + + @Override + public void remove(final int identification) { + super.getFileConfiguration().set(String.valueOf(identification), null); + super.saveFile(); + } + + @Override + public boolean contains(final int identification) { + return super.getFileConfiguration().contains(String.valueOf(identification)); + } + + @Override + public void save() { + super.saveFile(); + } + + @Override + public void write(final int identification, @NotNull final ParsedMap userData) { + for (final PermissionGroupProperty property : userData.keySet()) { + switch (property) { + case IDENTIFICATION: + case PRIORITY: + super.getFileConfiguration().set(identification + "." + property.getStoragePath(), userData.getInteger(property)); + break; + + case NAME: + case DISPLAY_NAME: + case CHAT_PREFIX: + case TABLIST_PREFIX: + super.getFileConfiguration().set(identification + "." + property.getStoragePath(), userData.getString(property)); + break; + + case PERMISSIONS: + final List permissions = super.getFileConfiguration().getStringList(identification + "." + PermissionGroupProperty.PERMISSIONS.getStoragePath()); + permissions.addAll(userData.getStringList(PermissionGroupProperty.PERMISSIONS)); + super.getFileConfiguration().set(identification + "." + property.getStoragePath(), permissions); + + case COLOR: + super.getFileConfiguration().set(identification + "." + property.getStoragePath(), userData.getCharacter(property)); + break; + } + } + this.save(); + } + + @Override + public void addPermission(final int identification, @NotNull final String permission) { + final List permissions = super.getFileConfiguration().getStringList(identification + "." + PermissionGroupProperty.PERMISSIONS.getStoragePath()); + permissions.add(permission); + super.getFileConfiguration().set(identification + "." + PermissionGroupProperty.PERMISSIONS.getStoragePath(), permissions); + this.save(); + } + + @Override + public void removePermission(final int identification, @NotNull final String permission) { + final List permissions = super.getFileConfiguration().getStringList(identification + "." + PermissionGroupProperty.PERMISSIONS.getStoragePath()); + permissions.remove(permission); + super.getFileConfiguration().set(identification + "." + PermissionGroupProperty.PERMISSIONS.getStoragePath(), permissions); + this.save(); + } + + @Override + public void clearPermissions(final int identification) { + super.getFileConfiguration().set(identification + "." + PermissionGroupProperty.PERMISSIONS.getStoragePath(), Collections.emptyList()); + this.save(); + } + + @Override + public @NotNull ParsedMap read(final int identification) { + final ParsedMap groupData = new ParsedMap<>(); + + Arrays.stream(PermissionGroupProperty.values()).forEach(property -> { + switch (property) { + case IDENTIFICATION: + groupData.put(property, super.getFileConfiguration().getInt(property.getStoragePath())); + break; + + case NAME: + case DISPLAY_NAME: + case CHAT_PREFIX: + case TABLIST_PREFIX: + groupData.put(property, super.getFileConfiguration().getString(property.getStoragePath())); + break; + + case PERMISSIONS: + groupData.put(property, super.getFileConfiguration().getStringList(property.getStoragePath())); + break; + + case COLOR: + groupData.put(property, Objects.requireNonNull(super.getFileConfiguration().getString(property.getStoragePath())).charAt(0)); + break; + } + }); + return groupData; + } + + @Override + public @NotNull ParsedMap read(final int identification, @NotNull final PermissionGroupProperty... properties) { + if (properties == null) { + return this.read(identification); + } + final ParsedMap groupData = new ParsedMap<>(); + + for (final PermissionGroupProperty property : properties) { + switch (property) { + case IDENTIFICATION: + groupData.put(property, super.getFileConfiguration().getInt(property.getStoragePath())); + break; + + case NAME: + case DISPLAY_NAME: + case CHAT_PREFIX: + case TABLIST_PREFIX: + groupData.put(property, super.getFileConfiguration().getString(property.getStoragePath())); + break; + + case PERMISSIONS: + groupData.put(property, super.getFileConfiguration().getStringList(property.getStoragePath())); + break; + + case COLOR: + groupData.put(property, Objects.requireNonNull(super.getFileConfiguration().getString(property.getStoragePath())).charAt(0)); + break; + } + } + return groupData; + } + + @Override + public PermissionGroup getGroup(final int identification) { + return Group.builder() + .setIdentification(identification) + .setName(super.getFileConfiguration().getString(identification + "." + PermissionGroupProperty.NAME.getStoragePath())) + .setDisplayName(super.getFileConfiguration().getString(identification + "." + PermissionGroupProperty.DISPLAY_NAME.getStoragePath())) + .setColor(super.getFileConfiguration().getString(identification + "." + PermissionGroupProperty.COLOR.getStoragePath()).charAt(0)) + .setPriority(super.getFileConfiguration().getInt(identification + "." + PermissionGroupProperty.PRIORITY.getStoragePath())) + .setTablistPrefix(super.getFileConfiguration().getString(identification + "." + PermissionGroupProperty.TABLIST_PREFIX.getStoragePath())) + .setChatPrefix(super.getFileConfiguration().getString(identification + "." + PermissionGroupProperty.CHAT_PREFIX.getStoragePath())) + .setPermissions(super.getFileConfiguration().getStringList(identification + "." + PermissionGroupProperty.PERMISSIONS.getStoragePath())) + .build(); + } + + @Override + public Map getGroups() { + final Map groups = new HashMap<>(); + + for (final String groupIdentification : super.getFileConfiguration().getKeys(false)) { + final Group group = Group.builder() + .setIdentification(Integer.parseInt(groupIdentification)) + .setName(super.getFileConfiguration().getString(groupIdentification + "." + PermissionGroupProperty.NAME.getStoragePath())) + .setPermissions(super.getFileConfiguration().getStringList(groupIdentification + "." + PermissionGroupProperty.PERMISSIONS.getStoragePath())) + .setDisplayName(super.getFileConfiguration().getString(groupIdentification + "." + PermissionGroupProperty.DISPLAY_NAME.getStoragePath())) + .setPriority(super.getFileConfiguration().getInt(groupIdentification + "." + PermissionGroupProperty.PRIORITY.getStoragePath())) + .setColor(super.getFileConfiguration().getString(groupIdentification + "." + PermissionGroupProperty.COLOR.getStoragePath()).toCharArray()[0]) + .setChatPrefix(super.getFileConfiguration().getString(groupIdentification + "." + PermissionGroupProperty.CHAT_PREFIX.getStoragePath())) + .setTablistPrefix(super.getFileConfiguration().getString(groupIdentification + "." + PermissionGroupProperty.TABLIST_PREFIX.getStoragePath())) + .build(); + groups.put(group.getIdentification(), group); + } + return groups; + } + + +} diff --git a/multiperms-bukkit/src/main/java/com/dev7ex/multiperms/group/GroupPermissible.java b/multiperms-bukkit/src/main/java/com/dev7ex/multiperms/group/GroupPermissible.java new file mode 100644 index 0000000..22d721e --- /dev/null +++ b/multiperms-bukkit/src/main/java/com/dev7ex/multiperms/group/GroupPermissible.java @@ -0,0 +1,33 @@ +package com.dev7ex.multiperms.group; + +import com.dev7ex.multiperms.api.user.PermissionUser; +import org.bukkit.entity.Player; +import org.bukkit.permissions.PermissibleBase; +import org.jetbrains.annotations.NotNull; + +/** + * @author Dev7ex + * @since 03.07.2023 + */ +public class GroupPermissible extends PermissibleBase { + + private final Player player; + private final PermissionUser user; + + public GroupPermissible(@NotNull final Player player, @NotNull final PermissionUser user) { + super(player); + this.player = player; + this.user = user; + } + + @Override + public boolean hasPermission(@NotNull final String permission) { + return (this.user.hasPermission(permission)) || (this.player.isOp()); + } + + @Override + public boolean isPermissionSet(@NotNull final String permission) { + return this.user.getAllPermissions().contains(permission); + } + +} diff --git a/multiperms-bukkit/src/main/java/com/dev7ex/multiperms/group/GroupService.java b/multiperms-bukkit/src/main/java/com/dev7ex/multiperms/group/GroupService.java new file mode 100644 index 0000000..60b975e --- /dev/null +++ b/multiperms-bukkit/src/main/java/com/dev7ex/multiperms/group/GroupService.java @@ -0,0 +1,203 @@ +package com.dev7ex.multiperms.group; + +import com.dev7ex.common.bukkit.BukkitCommon; +import com.dev7ex.common.bukkit.plugin.service.PluginService; +import com.dev7ex.common.map.ParsedMap; +import com.dev7ex.multiperms.MultiPermsPlugin; +import com.dev7ex.multiperms.api.group.PermissionGroup; +import com.dev7ex.multiperms.api.group.PermissionGroupConfiguration; +import com.dev7ex.multiperms.api.group.PermissionGroupProperty; +import com.dev7ex.multiperms.api.group.PermissionGroupProvider; +import com.dev7ex.multiperms.api.user.PermissionUser; +import lombok.AccessLevel; +import lombok.Getter; +import org.bukkit.entity.Player; +import org.jetbrains.annotations.NotNull; + +import java.lang.reflect.Field; +import java.util.*; + +/** + * @author Dev7ex + * @since 03.07.2023 + */ +@Getter(AccessLevel.PUBLIC) +public class GroupService implements PluginService, PermissionGroupProvider { + + private final Map groups = new HashMap<>(); + private final PermissionGroupConfiguration configuration; + + public GroupService(@NotNull final PermissionGroupConfiguration configuration) { + this.configuration = configuration; + } + + @Override + public void onEnable() { + this.groups.putAll(this.configuration.getGroups()); + + MultiPermsPlugin.getInstance().getLogger().info("Found [" + this.groups.values().size() + "] Groups"); + } + + @Override + public void onDisable() { + this.groups.clear(); + } + + @Override + public void register(final PermissionGroup group) { + this.groups.put(group.getIdentification(), group); + } + + @Override + public void unregister(final int identification) { + this.groups.remove(identification); + } + + @Override + public boolean isRegistered(final int identification) { + return this.groups.containsKey(identification); + } + + public void invokePermissions(final Player player, final PermissionUser user) { + final String serverVersion = BukkitCommon.getMinecraftServerVersion(); + + try { + final Class entityClazz = Class.forName("org.bukkit.craftbukkit." + serverVersion + ".entity.CraftHumanEntity"); + final Field field = entityClazz.getDeclaredField("perm"); + field.setAccessible(true); + field.set(player, new GroupPermissible(player, user)); + + } catch (final Exception exception) { + exception.printStackTrace(); + } + } + + @Override + public Optional getGroup(final int identification) { + return this.groups.values().stream().filter(permissionGroup -> permissionGroup.getIdentification() == identification).findFirst(); + } + + @Override + public Optional getGroup(@NotNull final String name) { + return this.groups.values().stream().filter(permissionGroup -> permissionGroup.getName().equalsIgnoreCase(name)).findFirst(); + } + + @Override + public PermissionGroup getGroupOrDefault(final int identification) { + return (this.getGroup(identification).isEmpty() ? this.getDefaultGroup() : this.getGroup(identification).get()); + } + + @Override + public Map getGroups(final List identifications) { + final Map groups = new HashMap<>(); + + for (final int identification : identifications) { + groups.put(identification, this.groups.get(identification)); + } + return groups; + } + + @Override + public PermissionGroup getNextBestGroup(final List groups) { + if (groups.isEmpty()) { + return this.getDefaultGroup(); + } + Collections.sort(groups); + return groups.get(0); + } + + public PermissionGroup getNextWorstGroup(final List groups) { + if (groups.isEmpty()) { + return this.getDefaultGroup(); + } + Collections.sort(groups); + Collections.reverse(groups); + return groups.get(0); + } + + @Override + public List getDeadGroups(final List groupIdentifications) { + final List deadGroups = new ArrayList<>(); + + for (final int identification : groupIdentifications) { + if (this.getGroup(identification).isPresent()) { + continue; + } + deadGroups.add(this.getGroup(identification).get()); + } + return deadGroups; + } + + @Override + public List getExistingGroups(final List groupIdentifications) { + final List existingGroups = new ArrayList<>(); + + for (final int identification : groupIdentifications) { + if (this.getGroup(identification).isEmpty()) { + continue; + } + existingGroups.add(this.getGroup(identification).get()); + } + return existingGroups; + } + + @Override + public PermissionGroup getDefaultGroup() { + return this.groups.get(0); + } + + @Override + public void saveGroup(@NotNull final PermissionGroup group) { + this.saveGroup(group, PermissionGroupProperty.IDENTIFICATION, + PermissionGroupProperty.NAME, + PermissionGroupProperty.DISPLAY_NAME, + PermissionGroupProperty.COLOR, + PermissionGroupProperty.PRIORITY, + PermissionGroupProperty.TABLIST_PREFIX, + PermissionGroupProperty.CHAT_PREFIX, + PermissionGroupProperty.PERMISSIONS); + } + + @Override + public void saveGroup(@NotNull final PermissionGroup group, @NotNull final PermissionGroupProperty... properties) { + final ParsedMap data = new ParsedMap<>(); + + for (final PermissionGroupProperty property : properties) { + switch (property) { + case IDENTIFICATION: + data.put(property, group.getIdentification()); + break; + + case NAME: + data.put(property, group.getName()); + break; + + case DISPLAY_NAME: + data.put(property, group.getDisplayName()); + break; + + case COLOR: + data.put(property, group.getColor()); + break; + + case PRIORITY: + data.put(property, group.getPriority()); + break; + + case TABLIST_PREFIX: + data.put(property, group.getTablistPrefix()); + break; + + case CHAT_PREFIX: + data.put(property, group.getChatPrefix()); + break; + + case PERMISSIONS: + data.put(property, group.getPermissions()); + break; + } + } + this.configuration.write(group.getIdentification(), data); + } + +} diff --git a/multiperms-bukkit/src/main/java/com/dev7ex/multiperms/hook/DefaultPermissionHookProvider.java b/multiperms-bukkit/src/main/java/com/dev7ex/multiperms/hook/DefaultPermissionHookProvider.java new file mode 100644 index 0000000..084b537 --- /dev/null +++ b/multiperms-bukkit/src/main/java/com/dev7ex/multiperms/hook/DefaultPermissionHookProvider.java @@ -0,0 +1,57 @@ +package com.dev7ex.multiperms.hook; + +import com.dev7ex.common.bukkit.BukkitCommonPlugin; +import com.dev7ex.common.bukkit.plugin.service.PluginService; +import com.dev7ex.multiperms.MultiPermsPlugin; +import com.dev7ex.multiperms.api.bukkit.hook.BukkitPermissionHook; +import com.dev7ex.multiperms.api.hook.PermissionHook; +import com.dev7ex.multiperms.api.hook.PermissionHookProvider; +import lombok.AccessLevel; +import lombok.Getter; +import org.bukkit.plugin.Plugin; +import org.bukkit.plugin.java.JavaPlugin; +import org.jetbrains.annotations.NotNull; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +/** + * @author Dev7ex + * @since 03.08.2023 + */ +@Getter(AccessLevel.PUBLIC) +public class DefaultPermissionHookProvider implements PluginService, PermissionHookProvider { + + private final Map permissionHooks = new HashMap<>(); + + @Override + public void onEnable() { + this.register(MultiPermsPlugin.getInstance(), new BukkitPermissionHook()); + this.register(JavaPlugin.getPlugin(BukkitCommonPlugin.class), new MultiPermsHook()); + } + + @Override + public void onDisable() { + this.permissionHooks.clear(); + } + + @Override + public void register(@NotNull final Plugin hookHolder, @NotNull final PermissionHook hook) { + MultiPermsPlugin.getInstance().getLogger().info("Register Hook " + hook.getClass().getSimpleName()); + this.permissionHooks.put(hookHolder, hook); + } + + @Override + public void unregister(@NotNull final Plugin hookHolder) { + this.permissionHooks.remove(hookHolder); + } + + public List getAllPermissions() { + final List permissions = new ArrayList<>(); + this.permissionHooks.values().forEach(permissionHook -> permissions.addAll(permissionHook.getPermissions())); + return permissions; + } + +} diff --git a/multiperms-bukkit/src/main/java/com/dev7ex/multiperms/hook/MultiPermsHook.java b/multiperms-bukkit/src/main/java/com/dev7ex/multiperms/hook/MultiPermsHook.java new file mode 100644 index 0000000..f867514 --- /dev/null +++ b/multiperms-bukkit/src/main/java/com/dev7ex/multiperms/hook/MultiPermsHook.java @@ -0,0 +1,34 @@ +package com.dev7ex.multiperms.hook; + +import com.dev7ex.multiperms.api.hook.PermissionHook; + +import java.util.List; + +/** + * @author Dev7ex + * @since 03.08.2023 + */ +public class MultiPermsHook implements PermissionHook { + + @Override + public List getPermissions() { + return List.of("multiperms.command.permission", + "multiperms.command.permission.group", + "multiperms.command.permission.group.add", + "multiperms.command.permission.group.create", + "multiperms.command.permission.group.delete", + "multiperms.command.permission.group.edit", + "multiperms.command.permission.group.list", + "multiperms.command.permission.group.remove", + "multiperms.command.permission.reload", + "multiperms.command.permission.user", + "multiperms.command.permission.user.add", + "multiperms.command.permission.user.clear", + "multiperms.command.permission.user.info", + "multiperms.command.permission.user.remove", + "multiperms.command.permission.user.set", + "multiperms.command.permission.user", + "multiperms.chat.colored"); + } + +} diff --git a/multiperms-bukkit/src/main/java/com/dev7ex/multiperms/listener/PlayerChatListener.java b/multiperms-bukkit/src/main/java/com/dev7ex/multiperms/listener/PlayerChatListener.java new file mode 100644 index 0000000..b61f674 --- /dev/null +++ b/multiperms-bukkit/src/main/java/com/dev7ex/multiperms/listener/PlayerChatListener.java @@ -0,0 +1,42 @@ +package com.dev7ex.multiperms.listener; + +import com.dev7ex.multiperms.api.bukkit.MultiPermsBukkitApi; +import com.dev7ex.multiperms.api.bukkit.event.MultiPermsListener; +import com.dev7ex.multiperms.api.user.PermissionUser; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.player.AsyncPlayerChatEvent; +import org.jetbrains.annotations.NotNull; + +import java.util.Optional; + +/** + * @author Dev7ex + * @since 03.07.2023 + */ +public class PlayerChatListener extends MultiPermsListener { + + public PlayerChatListener(@NotNull final MultiPermsBukkitApi multiPermsApi) { + super(multiPermsApi); + } + + @EventHandler(priority = EventPriority.NORMAL) + public void handlePlayerChat(final AsyncPlayerChatEvent event) { + final Player player = event.getPlayer(); + final Optional optionalUser = super.getUserProvider().getUser(player.getUniqueId()); + + if (optionalUser.isEmpty()) { + return; + } + event.setFormat(super.getConfiguration().getChatFormat() + .replaceAll("%prefix%", optionalUser.get().getGroup().getChatPrefix().replaceAll("&", "§")) + .replaceAll("%name%", player.getName()) + .replaceAll("%message%", event.getMessage())); + + if (player.hasPermission("multiperms.chat.colored")) { + event.setFormat(event.getFormat().replaceAll("&", "§")); + } + } + +} diff --git a/multiperms-bukkit/src/main/java/com/dev7ex/multiperms/listener/PlayerConnectionListener.java b/multiperms-bukkit/src/main/java/com/dev7ex/multiperms/listener/PlayerConnectionListener.java new file mode 100644 index 0000000..8a133a0 --- /dev/null +++ b/multiperms-bukkit/src/main/java/com/dev7ex/multiperms/listener/PlayerConnectionListener.java @@ -0,0 +1,73 @@ +package com.dev7ex.multiperms.listener; + +import com.dev7ex.common.map.ParsedMap; +import com.dev7ex.multiperms.MultiPermsPlugin; +import com.dev7ex.multiperms.api.bukkit.MultiPermsBukkitApi; +import com.dev7ex.multiperms.api.bukkit.event.MultiPermsListener; +import com.dev7ex.multiperms.api.bukkit.event.user.PermissionUserLoginEvent; +import com.dev7ex.multiperms.api.bukkit.event.user.PermissionUserLogoutEvent; +import com.dev7ex.multiperms.api.group.PermissionGroup; +import com.dev7ex.multiperms.api.user.PermissionUser; +import com.dev7ex.multiperms.api.user.PermissionUserConfiguration; +import com.dev7ex.multiperms.api.user.PermissionUserProperty; +import com.dev7ex.multiperms.user.User; +import com.dev7ex.multiperms.user.UserConfiguration; +import org.bukkit.Bukkit; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.player.PlayerJoinEvent; +import org.bukkit.event.player.PlayerQuitEvent; +import org.jetbrains.annotations.NotNull; + +import java.util.List; + +/** + * @author Dev7ex + * @since 03.07.2023 + */ +public class PlayerConnectionListener extends MultiPermsListener { + + public PlayerConnectionListener(@NotNull final MultiPermsBukkitApi multiPermsApi) { + super(multiPermsApi); + } + + @EventHandler(priority = EventPriority.NORMAL) + public void handlePlayerJoin(final PlayerJoinEvent event) { + final Player player = event.getPlayer(); + final PermissionUser user = new User(player.getUniqueId(), player.getName()); + final PermissionUserConfiguration userConfiguration = new UserConfiguration(user); + final ParsedMap userData = userConfiguration.read(); + + final List subGroups = super.getGroupProvider().getExistingGroups(userData.getIntList(PermissionUserProperty.SUB_GROUPS)); // Get SubGroups from config + final PermissionGroup userGroup = super.getGroupProvider().getGroupOrDefault(userData.getInteger(PermissionUserProperty.GROUP)); + + subGroups.removeIf(group -> group.getIdentification() == userGroup.getIdentification()); + + user.setConfiguration(userConfiguration); + user.setGroup(userGroup); + user.setPermissions(userData.getStringList(PermissionUserProperty.PERMISSION)); + user.setSubGroups(subGroups); + user.setLastLogin(System.currentTimeMillis()); + + MultiPermsPlugin.getInstance().getGroupProvider().invokePermissions(player, user); + + super.getUserProvider().registerUser(user); + super.getUserProvider().saveUser(user, PermissionUserProperty.LAST_LOGIN, + PermissionUserProperty.GROUP, PermissionUserProperty.SUB_GROUPS); + + Bukkit.getPluginManager().callEvent(new PermissionUserLoginEvent(user)); + } + + @EventHandler(priority = EventPriority.NORMAL) + public void handlePlayerQuit(final PlayerQuitEvent event) { + final Player player = event.getPlayer(); + final PermissionUser user = super.getUserProvider().getUser(player.getUniqueId()).orElseThrow(); + + Bukkit.getPluginManager().callEvent(new PermissionUserLogoutEvent(user)); + + super.getUserProvider().saveUser(user); + super.getUserProvider().unregisterUser(player.getUniqueId()); + } + +} diff --git a/multiperms-bukkit/src/main/java/com/dev7ex/multiperms/listener/ScoreboardListener.java b/multiperms-bukkit/src/main/java/com/dev7ex/multiperms/listener/ScoreboardListener.java new file mode 100644 index 0000000..1ac8c7f --- /dev/null +++ b/multiperms-bukkit/src/main/java/com/dev7ex/multiperms/listener/ScoreboardListener.java @@ -0,0 +1,57 @@ +package com.dev7ex.multiperms.listener; + +import com.dev7ex.multiperms.MultiPermsPlugin; +import com.dev7ex.multiperms.api.bukkit.MultiPermsBukkitApi; +import com.dev7ex.multiperms.api.bukkit.event.MultiPermsListener; +import com.dev7ex.multiperms.api.bukkit.event.group.PermissionGroupDeleteEvent; +import com.dev7ex.multiperms.api.bukkit.event.group.PermissionGroupEditEvent; +import com.dev7ex.multiperms.api.bukkit.event.user.PermissionUserLoginEvent; +import com.dev7ex.multiperms.api.user.PermissionUser; +import org.bukkit.Bukkit; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.jetbrains.annotations.NotNull; + +import java.util.Collection; +import java.util.Objects; + +/** + * @author Dev7ex + * @since 13.08.2023 + */ +public class ScoreboardListener extends MultiPermsListener { + + public ScoreboardListener(@NotNull final MultiPermsBukkitApi multiPermsApi) { + super(multiPermsApi); + } + + @EventHandler(priority = EventPriority.NORMAL) + public void handleUserLogin(final PermissionUserLoginEvent event) { + final PermissionUser user = event.getUser(); + final Player player = Objects.requireNonNull(Bukkit.getPlayer(user.getUniqueId())); + + MultiPermsPlugin.getInstance().getScoreboardProvider().updateNameTagsDelayed(player, user, 5L); + } + + @EventHandler(priority = EventPriority.NORMAL) + public void handleGroupDelete(final PermissionGroupDeleteEvent event) { + final Collection users = super.getUserProvider().getUsers(event.getGroup()).values(); + if (users.isEmpty()) { + return; + } + + for (final PermissionUser user : users) { + user.setGroup(super.getGroupProvider().getNextBestGroup(user.getSubGroups())); + MultiPermsPlugin.getInstance().getScoreboardProvider().updateNameTagsDelayed(Objects.requireNonNull(Bukkit.getPlayer(user.getUniqueId())), user, 5L); + } + } + + @EventHandler(priority = EventPriority.NORMAL) + public void handleGroupEdit(final PermissionGroupEditEvent event) { + for (final PermissionUser user : super.getUserProvider().getUsers().values()) { + MultiPermsPlugin.getInstance().getScoreboardProvider().updateNameTagsDelayed(Objects.requireNonNull(Bukkit.getPlayer(user.getUniqueId())), user, 5L); + } + } + +} diff --git a/multiperms-bukkit/src/main/java/com/dev7ex/multiperms/scoreboard/ScoreboardService.java b/multiperms-bukkit/src/main/java/com/dev7ex/multiperms/scoreboard/ScoreboardService.java new file mode 100644 index 0000000..4378a8a --- /dev/null +++ b/multiperms-bukkit/src/main/java/com/dev7ex/multiperms/scoreboard/ScoreboardService.java @@ -0,0 +1,71 @@ +package com.dev7ex.multiperms.scoreboard; + +import com.dev7ex.common.bukkit.plugin.service.PluginService; +import com.dev7ex.multiperms.MultiPermsPlugin; +import com.dev7ex.multiperms.api.group.PermissionGroup; +import com.dev7ex.multiperms.api.user.PermissionUser; +import com.dev7ex.multiperms.group.GroupService; +import org.bukkit.Bukkit; +import org.bukkit.ChatColor; +import org.bukkit.entity.Player; +import org.bukkit.scoreboard.Team; +import org.jetbrains.annotations.NotNull; + +import java.util.Objects; + +/** + * @author Dev7ex + * @since 03.07.2023 + */ +public record ScoreboardService(GroupService groupProvider) implements PluginService { + + @Override + public void onEnable() { + for (final Player players : Bukkit.getOnlinePlayers()) { + final PermissionUser user = MultiPermsPlugin.getInstance().getUserProvider().getUser(players.getUniqueId()).orElseThrow(); + this.updateNameTags(players, user); + } + } + + @Override + public void onDisable() { + } + + public void initializeScoreboard(@NotNull final Player player) { + if (!player.getScoreboard().equals(Objects.requireNonNull(Bukkit.getScoreboardManager()).getMainScoreboard())) { + return; + } + player.setScoreboard(Objects.requireNonNull(player.getServer().getScoreboardManager()).getNewScoreboard()); + } + + public void updateNameTags(@NotNull final Player player, @NotNull final PermissionUser user) { + this.initializeScoreboard(player); + + for (final Player players : Bukkit.getOnlinePlayers()) { + final PermissionUser targetUser = MultiPermsPlugin.getInstance().getUserProvider().getUser(players.getUniqueId()).orElseThrow(); + + this.initializeScoreboard(players); + this.addTeamEntry(player, players, user.getGroup()); + this.addTeamEntry(players, player, targetUser.getGroup()); + } + } + + public void updateNameTagsDelayed(@NotNull final Player player, @NotNull final PermissionUser user, final long delay) { + Bukkit.getScheduler().runTaskLater(MultiPermsPlugin.getInstance(), () -> this.updateNameTags(player, user), delay); + } + + public void addTeamEntry(@NotNull final Player entry, @NotNull final Player other, @NotNull final PermissionGroup entryGroup) { + final Team entryTeam = other.getScoreboard().getTeam(this.getTeamName(entryGroup)) == null ? + other.getScoreboard().registerNewTeam(this.getTeamName(entryGroup)) : + other.getScoreboard().getTeam(this.getTeamName(entryGroup)); + + entryTeam.setPrefix(entryGroup.getTablistPrefix().replaceAll("&", "§").replaceAll("_", " ")); + entryTeam.setColor(ChatColor.getByChar(entryGroup.getColor())); + entryTeam.addEntry(entry.getName()); + } + + public String getTeamName(@NotNull final PermissionGroup group) { + return String.format("%d%s", group.getPriority(), group.getName()); + } + +} diff --git a/multiperms-bukkit/src/main/java/com/dev7ex/multiperms/user/User.java b/multiperms-bukkit/src/main/java/com/dev7ex/multiperms/user/User.java new file mode 100644 index 0000000..d4da263 --- /dev/null +++ b/multiperms-bukkit/src/main/java/com/dev7ex/multiperms/user/User.java @@ -0,0 +1,83 @@ +package com.dev7ex.multiperms.user; + +import com.dev7ex.multiperms.MultiPermsPlugin; +import com.dev7ex.multiperms.api.group.PermissionGroup; +import com.dev7ex.multiperms.api.user.PermissionUser; +import com.dev7ex.multiperms.api.user.PermissionUserConfiguration; +import com.google.common.collect.Lists; +import lombok.AccessLevel; +import lombok.Getter; +import lombok.Setter; +import net.md_5.bungee.api.ChatColor; +import org.bukkit.Bukkit; +import org.bukkit.entity.Player; +import org.jetbrains.annotations.NotNull; + +import java.util.ArrayList; +import java.util.List; +import java.util.UUID; + +/** + * @author Dev7ex + * @since 03.07.2023 + */ +@Getter(AccessLevel.PUBLIC) +@Setter(AccessLevel.PUBLIC) +public class User implements PermissionUser { + + private UUID uniqueId; + private String name; + private PermissionUserConfiguration configuration; + private long lastLogin; + private PermissionGroup group; + private List subGroups = new ArrayList<>(); + private List permissions = new ArrayList<>(); + + public User(@NotNull final UUID uniqueId, @NotNull final String name) { + this.uniqueId = uniqueId; + this.name = name; + } + + @Override + public String getColoredName() { + return (ChatColor.getByChar(this.group.getColor()) + this.name); + } + + @Override + public List getAllPermissions() { + final List permissions = Lists.newArrayList(this.permissions); + permissions.addAll(this.group.getPermissions()); + if (!this.subGroups.isEmpty()) { + this.subGroups.forEach(permissionGroup -> permissions.addAll(permissionGroup.getPermissions())); + } + return permissions; + } + + @Override + public void addPermission(@NotNull final String permission) { + this.permissions.add(permission); + } + + @Override + public void removePermission(@NotNull final String permission) { + this.permissions.remove(permission); + } + + @Override + public boolean hasPermission(@NotNull final String permission) { + return ((this.permissions.contains("*")) || (this.permissions.contains(permission)) + || (this.group.hasPermission(permission)) + || (this.subGroups.stream().anyMatch(permissionGroup -> permissionGroup.hasPermission(permission)))); + } + + @Override + public void sendMessage(@NotNull final String message) { + this.getEntity().sendMessage(MultiPermsPlugin.getInstance().getConfiguration().getPrefix() + message); + } + + public Player getEntity() { + return Bukkit.getPlayer(this.uniqueId); + } + + +} diff --git a/multiperms-bukkit/src/main/java/com/dev7ex/multiperms/user/UserConfiguration.java b/multiperms-bukkit/src/main/java/com/dev7ex/multiperms/user/UserConfiguration.java new file mode 100644 index 0000000..db1d8c4 --- /dev/null +++ b/multiperms-bukkit/src/main/java/com/dev7ex/multiperms/user/UserConfiguration.java @@ -0,0 +1,190 @@ +package com.dev7ex.multiperms.user; + +import com.dev7ex.common.map.ParsedMap; +import com.dev7ex.multiperms.MultiPermsPlugin; +import com.dev7ex.multiperms.api.user.PermissionUser; +import com.dev7ex.multiperms.api.user.PermissionUserConfiguration; +import com.dev7ex.multiperms.api.user.PermissionUserProperty; +import com.google.common.collect.Lists; +import lombok.SneakyThrows; +import org.bukkit.configuration.file.YamlConfiguration; +import org.jetbrains.annotations.NotNull; + +import java.io.File; +import java.util.*; + +/** + * @author Dev7ex + * @since 03.07.2023 + */ +public class UserConfiguration implements PermissionUserConfiguration { + + private final PermissionUser user; + private final File configurationFile; + private final YamlConfiguration fileConfiguration; + + @SneakyThrows + public UserConfiguration(final PermissionUser user) { + this.user = user; + + this.configurationFile = new File(MultiPermsPlugin.getInstance().getSubFolder("user") + + File.separator + user.getUniqueId().toString() + ".yml"); + + if (!this.configurationFile.exists()) { + final boolean created = this.configurationFile.createNewFile(); + } + this.fileConfiguration = YamlConfiguration.loadConfiguration(this.configurationFile); + this.fileConfiguration.addDefault(PermissionUserProperty.UNIQUE_ID.getStoragePath(), user.getUniqueId().toString()); + this.fileConfiguration.addDefault(PermissionUserProperty.NAME.getStoragePath(), user.getName()); + this.fileConfiguration.addDefault(PermissionUserProperty.LAST_LOGIN.getStoragePath(), 0L); + this.fileConfiguration.addDefault(PermissionUserProperty.GROUP.getStoragePath(), 0); + this.fileConfiguration.addDefault(PermissionUserProperty.SUB_GROUPS.getStoragePath(), Lists.newArrayList()); + this.fileConfiguration.addDefault(PermissionUserProperty.PERMISSION.getStoragePath(), Lists.newArrayList()); + this.fileConfiguration.options().copyDefaults(true); + this.save(); + } + + @Override + public ParsedMap read() { + final ParsedMap userData = new ParsedMap<>(); + + Arrays.stream(PermissionUserProperty.values()).forEach(property -> { + switch (property) { + case UNIQUE_ID: + userData.put(property, UUID.fromString(Objects.requireNonNull(this.fileConfiguration.getString(property.getStoragePath())))); + break; + + case NAME: + userData.put(property, this.fileConfiguration.getString(property.getStoragePath())); + break; + + case LAST_LOGIN: + userData.put(property, this.fileConfiguration.getLong(property.getStoragePath())); + break; + + + case GROUP: + userData.put(property, this.fileConfiguration.getInt(property.getStoragePath())); + break; + + case SUB_GROUPS: + userData.put(property, this.fileConfiguration.getIntegerList(property.getStoragePath())); + break; + + case PERMISSION: + userData.put(property, this.fileConfiguration.getStringList(property.getStoragePath())); + break; + } + }); + return userData; + } + + @Override + public ParsedMap read(@NotNull final PermissionUserProperty... properties) { + final ParsedMap userData = new ParsedMap<>(); + + for (final PermissionUserProperty property : properties) { + switch (property) { + case UNIQUE_ID: + userData.put(PermissionUserProperty.UNIQUE_ID, UUID.fromString(Objects.requireNonNull(this.fileConfiguration.getString(property.getStoragePath())))); + break; + + case NAME: + userData.put(property, this.fileConfiguration.getString(property.getStoragePath())); + break; + + case LAST_LOGIN: + userData.put(property, this.fileConfiguration.getLong(property.getStoragePath())); + break; + + case GROUP: + userData.put(property, this.fileConfiguration.getInt(property.getStoragePath())); + break; + + case SUB_GROUPS: + userData.put(property, this.fileConfiguration.getIntegerList(property.getStoragePath())); + break; + + case PERMISSION: + userData.put(property, this.fileConfiguration.getStringList(property.getStoragePath())); + break; + + default: + return this.read(); + } + } + return userData; + } + + @Override + public void write(final ParsedMap userData) { + for (final PermissionUserProperty property : userData.keySet()) { + switch (property) { + case UNIQUE_ID: + case NAME: + this.fileConfiguration.set(property.getStoragePath(), userData.getString(property)); + break; + + case LAST_LOGIN: + this.fileConfiguration.set(property.getStoragePath(), userData.getLong(property)); + break; + + case GROUP: + this.fileConfiguration.set(property.getStoragePath(), userData.getInteger(PermissionUserProperty.GROUP)); + break; + + case SUB_GROUPS: + this.fileConfiguration.set(property.getStoragePath(), userData.getIntList(PermissionUserProperty.SUB_GROUPS)); + break; + + case PERMISSION: + this.fileConfiguration.set(property.getStoragePath(), userData.getStringList(PermissionUserProperty.PERMISSION)); + break; + } + } + this.save(); + } + + @Override + public void write(@NotNull final PermissionUserProperty property, @NotNull final Object value) { + switch (property) { + case UNIQUE_ID: + case NAME: + case LAST_LOGIN: + case GROUP: + case SUB_GROUPS: + case PERMISSION: + this.fileConfiguration.set(property.getStoragePath(), value); + break; + } + this.save(); + } + + @Override + public void removePermission(final String permission) { + final List permissions = this.fileConfiguration.getStringList(PermissionUserProperty.PERMISSION.getStoragePath()); + permissions.remove(permission); + this.fileConfiguration.set(PermissionUserProperty.PERMISSION.getStoragePath(), permissions); + this.save(); + } + + @Override + public void addPermission(final String permission) { + final List permissions = this.fileConfiguration.getStringList(PermissionUserProperty.PERMISSION.getStoragePath()); + permissions.add(permission); + this.fileConfiguration.set(PermissionUserProperty.PERMISSION.getStoragePath(), permissions); + this.save(); + } + + @Override + public void clearPermissions() { + this.fileConfiguration.set(PermissionUserProperty.PERMISSION.getStoragePath(), Collections.emptyList()); + } + + @Override + @SneakyThrows + public void save() { + this.fileConfiguration.save(this.configurationFile); + } + +} diff --git a/multiperms-bukkit/src/main/java/com/dev7ex/multiperms/user/UserService.java b/multiperms-bukkit/src/main/java/com/dev7ex/multiperms/user/UserService.java new file mode 100644 index 0000000..790c362 --- /dev/null +++ b/multiperms-bukkit/src/main/java/com/dev7ex/multiperms/user/UserService.java @@ -0,0 +1,157 @@ +package com.dev7ex.multiperms.user; + +import com.dev7ex.common.bukkit.plugin.service.PluginService; +import com.dev7ex.common.map.ParsedMap; +import com.dev7ex.multiperms.MultiPermsPlugin; +import com.dev7ex.multiperms.api.group.PermissionGroup; +import com.dev7ex.multiperms.api.group.PermissionGroupProvider; +import com.dev7ex.multiperms.api.user.PermissionUser; +import com.dev7ex.multiperms.api.user.PermissionUserConfiguration; +import com.dev7ex.multiperms.api.user.PermissionUserProperty; +import com.dev7ex.multiperms.api.user.PermissionUserProvider; +import lombok.AccessLevel; +import lombok.Getter; +import org.bukkit.Bukkit; +import org.bukkit.entity.Player; +import org.jetbrains.annotations.NotNull; + +import java.util.*; +import java.util.stream.Collectors; + +/** + * @author Dev7ex + * @since 03.07.2023 + */ +@Getter(AccessLevel.PUBLIC) +public class UserService implements PluginService, PermissionUserProvider { + + private final Map users = new HashMap<>(); + private final PermissionGroupProvider groupProvider; + + public UserService(final PermissionGroupProvider groupProvider) { + this.groupProvider = groupProvider; + } + + @Override + public void onEnable() { + for (final Player player : Bukkit.getOnlinePlayers()) { + final PermissionUser user = new User(player.getUniqueId(), player.getName()); + final PermissionUserConfiguration userConfiguration = new UserConfiguration(user); + + final ParsedMap userData = userConfiguration.read(); // Read Data from Config + final List subGroups = MultiPermsPlugin.getInstance().getGroupProvider().getExistingGroups(userData.getIntList(PermissionUserProperty.SUB_GROUPS)); // Get SubGroups from config + final PermissionGroup userGroup = MultiPermsPlugin.getInstance().getGroupProvider().getGroupOrDefault(userData.getInteger(PermissionUserProperty.GROUP)); + + subGroups.removeIf(group -> group.getIdentification() == userGroup.getIdentification()); + + user.setConfiguration(userConfiguration); + user.setGroup(userGroup); + user.setPermissions(userData.getStringList(PermissionUserProperty.PERMISSION)); + user.setSubGroups(subGroups); + + user.setConfiguration(userConfiguration); + + this.registerUser(user); + + MultiPermsPlugin.getInstance().getGroupProvider().invokePermissions(player, user); + + this.saveUser(user, PermissionUserProperty.GROUP, PermissionUserProperty.SUB_GROUPS); + } + + if (MultiPermsPlugin.getInstance().getConfiguration().isTablistEnabled()) { + for (final PermissionUser user : this.users.values()) { + MultiPermsPlugin.getInstance().getScoreboardProvider().updateNameTags(Objects.requireNonNull(Bukkit.getPlayer(user.getUniqueId())), user); + } + } + } + + @Override + public void onDisable() { + for (final PermissionUser user : this.users.values()) { + this.saveUser(user); + } + this.users.clear(); + } + + @Override + public void registerUser(@NotNull final PermissionUser user) { + this.users.put(user.getUniqueId(), user); + } + + @Override + public void unregisterUser(@NotNull final UUID uniqueId) { + this.users.remove(uniqueId); + } + + @Override + public Optional getUser(@NotNull final UUID uniqueId) { + return Optional.ofNullable(this.users.get(uniqueId)); + } + + @Override + public Optional getUser(@NotNull final String name) { + return this.users.values().stream().filter(permissionUser -> permissionUser.getName().equalsIgnoreCase(name)).findFirst(); + } + + @Override + public Map getUsers(@NotNull final PermissionGroup group) { + final Map users = new HashMap<>(); + + for (final PermissionUser onlineUser : this.users.values()) { + if (onlineUser.getGroup().getIdentification() != group.getIdentification()) { + continue; + } + users.put(onlineUser.getUniqueId(), onlineUser); + } + return users; + } + + @Override + public void saveUser(@NotNull final PermissionUser user) { + this.saveUser(user, PermissionUserProperty.UNIQUE_ID, + PermissionUserProperty.NAME, + PermissionUserProperty.LAST_LOGIN, + PermissionUserProperty.GROUP, + PermissionUserProperty.SUB_GROUPS, + PermissionUserProperty.PERMISSION); + } + + @Override + public void saveUser(@NotNull final PermissionUser user, @NotNull final PermissionUserProperty... properties) { + final ParsedMap data = new ParsedMap<>(); + + for (final PermissionUserProperty property : properties) { + switch (property) { + case UNIQUE_ID: + data.put(property, user.getUniqueId()); + break; + + case NAME: + data.put(property, user.getName()); + break; + + case LAST_LOGIN: + data.put(property, user.getLastLogin()); + break; + + case GROUP: + data.put(property, user.getGroup().getIdentification()); + break; + + case SUB_GROUPS: + data.put(property, user.getSubGroups().stream().map(PermissionGroup::getIdentification).collect(Collectors.toList())); + break; + + case PERMISSION: + data.put(property, user.getPermissions()); + break; + + default: + this.saveUser(user); + break; + } + user.getConfiguration().write(data); + } + } + +} diff --git a/multiperms-bukkit/src/main/resources/config.yml b/multiperms-bukkit/src/main/resources/config.yml new file mode 100644 index 0000000..9f53ecc --- /dev/null +++ b/multiperms-bukkit/src/main/resources/config.yml @@ -0,0 +1,124 @@ +# __ __ _ _ _ _____ +# | \/ | | | | (_) __ \ +# | \ / |_ _| | |_ _| |__) |__ _ __ _ __ ___ ___ +# | |\/| | | | | | __| | ___/ _ \ '__| '_ ` _ \/ __| +# | | | | |_| | | |_| | | | __/ | | | | | | \__ \ +# |_| |_|\__,_|_|\__|_|_| \___|_| |_| |_| |_|___/ +# +# Copyright (c) 2023 by Dev7ex +# Version: ${project.version} +config-version: ${project.version} +# General +prefix: '§8[§aMultiPerms§8]§r' +no-permission: '§cIm sorry, but you do not have permission to perform this command. Please contact the server administrators if you believe that is in error.' +no-console-command: '%prefix% §cThis player could not be found' +no-player-command: '%prefix% §cThis command can only performed by a player' +no-player-found: '%prefix% §cDieser Spieler konnte nicht gefunden werden' + +settings: + chat-enabled: true + chat-format: '%prefix% %name% §8» §7%message%' + tablist-enabled: true + +messages: + commands: + permission: + group: + add: + usage: '%prefix% §cUsage: /permission group add ' + group-has-permission: '%prefix% §7The group %colored_group_name% §7has the permission §a%permission% §7already' + successfully-added: '%prefix% §7You have added the permission §a%permission% §7to the group %colored_group_name%' + create: + usage: '%prefix% §cUsage /permission group create ' + group-already-exists: '%prefix% §cThere is already a group with this name!' + group-already-exists-id: '%prefix% §cThere is already a group with this Id!' + successfully-created: '%prefix% §7The group %colored_group_name% §7was §acreated' + delete: + usage: '%prefix% §cUsage /permission group delete ' + successfully-deleted: '%prefix% §7The group %colored_group_name% §7has been §cdeleted' + edit: + usage: '%prefix% §cUsage /permission group edit ' + property-not-exists: '%prefix% §cThis group property does not exist' + invalid-color: '%prefix% §cPlease specify a valid color' + successfully-edited: '%prefix% §7The property §a%group_property% §7was set to §a%value%' + list: + usage: '%prefix% §cUsage: /permission group list' + message: '%prefix% §7Groups: %colored_group_names%' + remove: + usage: '%prefix% §cUsage: /permission group remove ' + group-has-permission-not: '%prefix% §7The group %colored_group_name% §7has the permission §a%permission% §7not' + successfully-removed: '%prefix% §7You have removed the permission §a%permission% §7from the group %colored_group_name%!' + help: + message: + - '' + - '§f§m §r %prefix% §f§m ' + - '' + - '§7» §7/permission §agroup §7add ' + - '§7» §7/permission §agroup §7create ' + - '§7» §7/permission §agroup §7delete §7' + - '§7» §7/permission §agroup §7edit §7 ' + - '§7» §7/permission §agroup §7list' + - '§7» §7/permission §agroup §7remove ' + - '' + - '§7» §7/permission §areload' + - '' + - '§7» §7/permission §auser §7 §aadd §7 ' + - '§7» §7/permission §auser §7 §aclear §7>' + - '§7» §7/permission §auser §7 §ainfo' + - '§7» §7/permission §auser §7 §aremove §7 ' + - '§7» §7/permission §auser §7 §aset §7' + - '' + - '§f§m §r %prefix% §f§m ' + - '' + reload: + usage: '%prefix% §cUsage /permission reload' + message: '%prefix% §7The configuration has been reloaded successfully!' + user: + add: + usage: '%prefix% §cUsage /permission user add ' + group: + main-group: '%prefix% §cThis is the main group of %colored_user_name%' + user-has-group: '%prefix% %colored_user_name% §7has the group %colored_group_name% §7already' + successfully-added: '%prefix% §7You have added %colored_user_name% §7the group %colored_group_name%' + permission: + user-has-permission: '%prefix% %colored_user_name% §7has the permission §a%permission% §7already' + successfully-added: '%prefix% §7You have added %colored_user_name% §7the permission §a%permission%' + clear: + usage: '%prefix% §cUsage /permission user clear ' + group: + user-groups-empty: '%prefix% %colored_user_name% §7has no subgroups' + successfully-cleared: '%prefix% §7You have removed %colored_user_name% §7all subgroups' + permission: + user-permissions-empty: '%prefix% %colored_user_name% §7has no permissions' + successfully-cleared: '%prefix% §7You have removed %colored_user_name% §7all permissions' + info: + usage: '%prefix% §cUsage /permission user info' + message: + - '' + - '§f§m §r %colored_user_name% §f§m ' + - '' + - '§7» §7UUID: §a%unique_id%' + - '§7» §7Name: §a%colored_user_name%' + - '§7» §7Group: §a%colored_group_name%' + - '§7» §7Permissions: §a%permissions%' + - '§7» §7SubGroups: §a%colored_group_names%' + - '' + - '§f§m §r %colored_user_name% §f§m ' + - '' + remove: + usage: '%prefix% §cUsage /permission user remove ' + group: + main-group: '%prefix% §7This is the main group of %colored_user_name%' + user-has-group-not: '%prefix% %colored_user_name% §7has the group %colored_group_name% §7not' + successfully-removed: '%prefix% §7You have %colored_user_name% §7removed the %colored_group_name% §7group' + permission: + user-has-permission-not: '%prefix% %colored_user_name% §7has permission §a%permission% §7not' + successfully-removed: '%prefix% §7You have %colored_user_name% §7removed the permission §a%permission%' + set: + usage: '%prefix% §cUsage /permission user set ' + user-has-group: '%prefix% %colored_user_name% §7has the group %colored_group_name% §7already' + successfully-set: '%prefix% §7You have %colored_user_name% §7set the group %colored_group_name%' + general: + group-not-exists: '%prefix% §cThis group does not exist!' + invalid-identification: '%prefix% §cThis is not a valid Id!' + function-not-available: '%prefix% §cThis function is not available' \ No newline at end of file diff --git a/multiperms-bukkit/src/main/resources/language/de_DE.yml b/multiperms-bukkit/src/main/resources/language/de_DE.yml new file mode 100644 index 0000000..1c8d7dc --- /dev/null +++ b/multiperms-bukkit/src/main/resources/language/de_DE.yml @@ -0,0 +1,101 @@ +messages: + commands: + permission: + group: + add: + usage: '%prefix% §cUsage: /permission group add ' + group-has-permission: '%prefix% §7Die Gruppe %colored_group_name% §7hat die Permission §a%permission% §7bereits!' + successfully-added: '%prefix% §7Du hast der Gruppe %colored_group_name% §7die Permission §a%permission% §7hinzugefügt!' + create: + usage: '%prefix% §cUsage /permission group create ' + group-already-exists: '%prefix% §cEs existiert bereits eine Gruppe mit diesem Namen!' + group-already-exists-id: '%prefix% §cEs existiert bereits eine Gruppe mit dieser Id!' + successfully-created: '%prefix% §7Die Gruppe %colored_group_name% §7wurde §aerstellt!' + delete: + usage: '%prefix% §cUsage /permission group delete ' + successfully-deleted: '%prefix% §7Die Gruppe %colored_group_name% §7wurde §cgelöscht!' + edit: + usage: '%prefix% §cUsage /permission group edit ' + property-not-exists: '%prefix% §cDiese Gruppen Eigenschaft existiert nicht!' + invalid-color: '%prefix% §cBitte gib eine gültige Farbe an!' + successfully-edited: '%prefix% §7Die Eigenschaft §a%group_property% §7wurde auf §a%value% §7gesetzt!' + list: + usage: '%prefix% §cUsage: /permission group list' + message: '%prefix% §7Gruppen: %colored_group_names%' + remove: + usage: '%prefix% §cUsage: /permission group remove ' + group-has-permission-not: '%prefix% §7Die Gruppe %colored_group_name% §7hat die Permission §a%permission% §7nicht!' + successfully-removed: '%prefix% §7Du hast der Gruppe %colored_group_name% §7die Permission §a%permission% §7entfernt!' + help: + message: + - '' + - '§f§m §r %prefix% §f§m ' + - '' + - '§7» §7/permission §agroup §7add ' + - '§7» §7/permission §agroup §7create ' + - '§7» §7/permission §agroup §7delete §7' + - '§7» §7/permission §agroup §7edit §7 ' + - '§7» §7/permission §agroup §7list' + - '§7» §7/permission §agroup §7remove ' + - '' + - '§7» §7/permission §areload' + - '' + - '§7» §7/permission §auser §7 §aadd §7 ' + - '§7» §7/permission §auser §7 §aremove §7 ' + - '§7» §7/permission §auser §7 §ainfo' + - '§7» §7/permission §auser §7 §aset §7' + - '§7» §7/permission §auser §7 §aclear §7>' + - '' + - '§f§m §r %prefix% §f§m ' + - '' + reload: + usage: '%prefix% §cUsage /permission reload' + message: '%prefix% §7Die Konfiguration wurde erfolgreich neu geladen!' + user: + add: + usage: '%prefix% §cUsage /permission user add ' + group: + main-group: '%prefix% §cDas ist die Hauptgruppe von %colored_user_name%' + user-has-group: '%prefix% %colored_user_name% §7hat die Gruppe %colored_group_name% §7bereits!' + successfully-added: '%prefix% §7Du hast %colored_user_name% §7die Gruppe %colored_group_name% §7hinzugefügt!' + permission: + user-has-permission: '%prefix% %colored_user_name% §7hat die Permission §a%permission% §7bereits!' + successfully-added: '%prefix% §7Du hast %colored_user_name% §7die Permission §a%permission% §7hinzugefügt!' + clear: + usage: '%prefix% §cUsage /permission user clear ' + group: + user-groups-empty: '%prefix% %colored_user_name% §7hat keine Untergruppen!' + successfully-cleared: '%prefix% §7Du hast %colored_user_name% §7alle Untergruppen entfernt!' + permission: + user-permissions-empty: '%prefix% %colored_user_name% §7hat keine Permissions!' + successfully-cleared: '%prefix% §7Du hast %colored_user_name% §7alle Permissions entfernt!' + info: + usage: '%prefix% §cUsage /permission user info' + message: + - '' + - '§f§m §r %colored_user_name% §f§m ' + - '' + - '§7» §7UUID: §a%unique_id%' + - '§7» §7Name: §a%colored_user_name%' + - '§7» §7Gruppe: §a%colored_group_name%' + - '§7» §7Permissions: §a%permissions%' + - '§7» §7SubGroups: §a%colored_group_names%' + - '' + - '§f§m §r %colored_user_name% §f§m ' + - '' + remove: + usage: '%prefix% §cUsage /permission user remove ' + group: + main-group: '%prefix% §7Das ist die Hauptgruppe von %colored_user_name%' + user-has-group-not: '%prefix% %colored_user_name% §7hat die Gruppe %colored_group_name% §7nicht!' + successfully-removed: '%prefix% §7Du hast %colored_user_name% §7die Gruppe %colored_group_name% §7entfernt!' + permission: + user-has-permission-not: '%prefix% %colored_user_name% §7hat die Permission §a%permission% §7nicht!' + successfully-removed: '%prefix% §7Du hast %colored_user_name% §7die Permission §a%permission% §7entfernt!' + set: + usage: '%prefix% §cUsage /permission user set ' + user-has-group: '%prefix% %colored_user_name% §7hat die Gruppe %colored_group_name% §7bereits!' + successfully-set: '%prefix% §7Du hast %colored_user_name% §7die Gruppe %colored_group_name% §7gesetzt!' + general: + group-not-exists: '%prefix% §cDiese Gruppe existiert nicht!' + invalid-identification: '%prefix% §cDas ist keine gültige Id!' \ No newline at end of file diff --git a/multiperms-bukkit/src/main/resources/language/en_US.yml b/multiperms-bukkit/src/main/resources/language/en_US.yml new file mode 100644 index 0000000..27612df --- /dev/null +++ b/multiperms-bukkit/src/main/resources/language/en_US.yml @@ -0,0 +1,101 @@ +messages: + commands: + permission: + group: + add: + usage: '%prefix% §cUsage: /permission group add ' + group-has-permission: '%prefix% §7The group %colored_group_name% §7has the permission §a%permission% §7already' + successfully-added: '%prefix% §7You have added the permission §a%permission% to the group %colored_group_name%' + create: + usage: '%prefix% §cUsage /permission group create ' + group-already-exists: '%prefix% §cThere is already a group with this name!' + group-already-exists-id: '%prefix% §cThere is already a group with this Id!' + successfully-created: '%prefix% §7The group %colored_group_name% §7was §acreated' + delete: + usage: '%prefix% §cUsage /permission group delete ' + successfully-deleted: '%prefix% §7The group %colored_group_name% §7has been §cdeleted' + edit: + usage: '%prefix% §cUsage /permission group edit ' + property-not-exists: '%prefix% §cThis group property does not exist' + invalid-color: '%prefix% §cPlease specify a valid color' + successfully-edited: '%prefix% §7The property §a%group_property% §7was set to §a%value%' + list: + usage: '%prefix% §cUsage: /permission group list' + message: '%prefix% §7Groups: %colored_group_names%' + remove: + usage: '%prefix% §cUsage: /permission group remove ' + group-has-permission-not: '%prefix% §7The group %colored_group_name% §7has the permission §a%permission% §7not' + successfully-removed: '%prefix% §7You have removed the permission §a%permission% §7from the group %colored_group_name%!' + help: + message: + - '' + - '§f§m §r %prefix% §f§m ' + - '' + - '§7» §7/permission §agroup §7add ' + - '§7» §7/permission §agroup §7create ' + - '§7» §7/permission §agroup §7delete §7' + - '§7» §7/permission §agroup §7edit §7 ' + - '§7» §7/permission §agroup §7list' + - '§7» §7/permission §agroup §7remove ' + - '' + - '§7» §7/permission §areload' + - '' + - '§7» §7/permission §auser §7 §aadd §7 ' + - '§7» §7/permission §auser §7 §aremove §7 ' + - '§7» §7/permission §auser §7 §ainfo' + - '§7» §7/permission §auser §7 §aset §7' + - '§7» §7/permission §auser §7 §aclear §7>' + - '' + - '§f§m §r %prefix% §f§m ' + - '' + reload: + usage: '%prefix% §cUsage /permission reload' + message: '%prefix% §7The configuration has been reloaded successfully!' + user: + add: + usage: '%prefix% §cUsage /permission user add ' + group: + main-group: '%prefix% §cThis is the main group of %colored_user_name%' + user-has-group: '%prefix% %colored_user_name% §7has the group %colored_group_name% §7already' + successfully-added: '%prefix% §7You have added %colored_user_name% §7the group %colored_group_name%' + permission: + user-has-permission: '%prefix% %colored_user_name% §7has the permission §a%permission% §7already' + successfully-added: '%prefix% §7You have added %colored_user_name% §7the permission §a%permission%' + clear: + usage: '%prefix% §cUsage /permission user clear ' + group: + user-groups-empty: '%prefix% %colored_user_name% §7has no subgroups' + successfully-cleared: '%prefix% §7You have removed %colored_user_name% §7all subgroups' + permission: + user-permissions-empty: '%prefix% %colored_user_name% §7has no permissions' + successfully-cleared: '%prefix% §7You have removed %colored_user_name% §7all permissions' + info: + usage: '%prefix% §cUsage /permission user info' + message: + - '' + - '§f§m §r %colored_user_name% §f§m ' + - '' + - '§7» §7UUID: §a%unique_id%' + - '§7» §7Name: §a%colored_user_name%' + - '§7» §7Group: §a%colored_group_name%' + - '§7» §7Permissions: §a%permissions%' + - '§7» §7SubGroups: §a%colored_group_names%' + - '' + - '§f§m §r %colored_user_name% §f§m ' + - '' + remove: + usage: '%prefix% §cUsage /permission user remove ' + group: + main-group: '%prefix% §7This is the main group of %colored_user_name%' + user-has-group-not: '%prefix% %colored_user_name% §7has the group %colored_group_name% §7not' + successfully-removed: '%prefix% §7You have %colored_user_name% §7removed the %colored_group_name% §7group' + permission: + user-has-permission-not: '%prefix% %colored_user_name% §7has permission §a%permission% §7not' + successfully-removed: '%prefix% §7You have %colored_user_name% §7removed the permission §a%permission%' + set: + usage: '%prefix% §cUsage /permission user set ' + user-has-group: '%prefix% %colored_user_name% §7has the group %colored_group_name% §7already' + successfully-set: '%prefix% §7You have %colored_user_name% §7set the group %colored_group_name%' + general: + group-not-exists: '%prefix% §cThis group does not exist!' + invalid-identification: '%prefix% §cThis is not a valid Id!' \ No newline at end of file diff --git a/multiperms-bukkit/src/main/resources/plugin.yml b/multiperms-bukkit/src/main/resources/plugin.yml new file mode 100644 index 0000000..713a74f --- /dev/null +++ b/multiperms-bukkit/src/main/resources/plugin.yml @@ -0,0 +1,19 @@ +api-version: 1.16 +author: Dev7ex +database: false +depend: [ FacilisCommon ] +description: ${project.description} +load: POSTWORLD +loadbefore: [ ] +main: com.dev7ex.multiperms.MultiPermsPlugin +name: MultiPerms +prefix: MultiPerms +softdepend: [ PlaceholderAPI ] +version: ${project.version} +website: ${project.url} +commands: + permission: + aliases: [ multiperms, mp, perms ] + description: 'Main Command for all MultiPerms Commands' + permission: multiperms.command.permission + usage: /permission \ No newline at end of file diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..6ce6d22 --- /dev/null +++ b/pom.xml @@ -0,0 +1,37 @@ + + + 4.0.0 + + com.dev7ex + multiperms + pom + 1.0.0-SNAPSHOT + MultiPerms + + + multiperms-bukkit + multiperms-api + + + + ${project.source.version} + ${project.source.version} + + 3.8.1 + 3.2.4 + + 24.0.1 + 1.0.2-SNAPSHOT + 2.11.0 + 1.18.26 + 1.16.5-R0.1-SNAPSHOT + 3.9.0 + 2.11.3 + 1.19-R0.1-SNAPSHOT + + 16 + + + \ No newline at end of file