├── .github
├── .version
├── renovate.json
└── workflows
│ ├── codeql.yml
│ ├── json.yml
│ ├── maven.yml
│ └── release.yml
├── .gitignore
├── .run
├── compile-unix.run.xml
└── compile-win.run.xml
├── LICENSE
├── README.md
├── compile.bat
├── compile.sh
├── jitpack.yml
├── pom.xml
└── src
└── main
├── java
└── com
│ └── justixdev
│ └── eazynick
│ ├── EazyNick.java
│ ├── api
│ ├── NameFormatting.java
│ ├── NickManager.java
│ ├── NickedPlayerData.java
│ └── events
│ │ ├── PlayerNickEvent.java
│ │ └── PlayerUnnickEvent.java
│ ├── commands
│ ├── Command.java
│ ├── CommandManager.java
│ ├── CommandMetaData.java
│ ├── CommandResult.java
│ ├── CustomCommand.java
│ ├── impl
│ │ ├── disguise
│ │ │ ├── ChangeSkinCommand.java
│ │ │ ├── ChangeSkinOtherCommand.java
│ │ │ ├── FixSkinCommand.java
│ │ │ ├── NameCommand.java
│ │ │ ├── NickCommand.java
│ │ │ ├── NickOtherCommand.java
│ │ │ ├── NickedPlayersCommand.java
│ │ │ ├── ReNickCommand.java
│ │ │ ├── RealNameCommand.java
│ │ │ ├── ResetNameCommand.java
│ │ │ ├── ResetSkinCommand.java
│ │ │ ├── ResetSkinOtherCommand.java
│ │ │ ├── ToggleBungeeNickCommand.java
│ │ │ └── UnnickCommand.java
│ │ ├── gui
│ │ │ ├── BookGUICommand.java
│ │ │ ├── GuiNickCommand.java
│ │ │ ├── NickGUICommand.java
│ │ │ ├── NickListCommand.java
│ │ │ └── RankedNickGUICommand.java
│ │ └── plugin
│ │ │ ├── NickUpdateCheckCommand.java
│ │ │ └── PluginCommand.java
│ └── parameters
│ │ ├── CommandParameter.java
│ │ ├── ParameterCombination.java
│ │ └── ParameterType.java
│ ├── hooks
│ ├── LuckPermsHook.java
│ ├── PlaceHolderExpansion.java
│ └── TABHook.java
│ ├── listeners
│ ├── AsyncPlayerChatListener.java
│ ├── InventoryClickListener.java
│ ├── InventoryCloseListener.java
│ ├── PlayerChangedWorldListener.java
│ ├── PlayerCommandPreprocessListener.java
│ ├── PlayerDeathListener.java
│ ├── PlayerDropItemListener.java
│ ├── PlayerInteractListener.java
│ ├── PlayerJoinListener.java
│ ├── PlayerKickListener.java
│ ├── PlayerLoginListener.java
│ ├── PlayerNickListener.java
│ ├── PlayerQuitListener.java
│ ├── PlayerRespawnListener.java
│ ├── PlayerUnnickListener.java
│ ├── ServerCommandListener.java
│ └── ServerListPingListener.java
│ ├── nms
│ ├── NMSNickManager.java
│ ├── ReflectionHelper.java
│ ├── ScoreboardTeamHandler.java
│ ├── guis
│ │ ├── AnvilGUI.java
│ │ ├── SignGUI.java
│ │ └── book
│ │ │ ├── BookComponentBuilder.java
│ │ │ ├── BookPage.java
│ │ │ └── NMSBookUtils.java
│ └── netty
│ │ ├── InjectorType.java
│ │ ├── NMSPacketHelper.java
│ │ ├── PacketInjector.java
│ │ ├── PacketInjectorManager.java
│ │ ├── PlayerPacketInjector.java
│ │ ├── legacy
│ │ ├── LegacyAddressPacketInjector.java
│ │ ├── LegacyPacketInjector.java
│ │ ├── LegacyPlayerPacketInjector.java
│ │ └── impl
│ │ │ ├── IncomingLegacyPacketInjector.java
│ │ │ ├── OutgoingLegacyPacketInjector.java
│ │ │ └── ServerListLegacyPacketInjector.java
│ │ └── modern
│ │ ├── ModernAddressPacketInjector.java
│ │ ├── ModernPacketInjector.java
│ │ ├── ModernPlayerPacketInjector.java
│ │ └── impl
│ │ ├── IncomingModernPacketInjector.java
│ │ ├── OutgoingModernPacketInjector.java
│ │ └── ServerListModernPacketInjector.java
│ ├── sql
│ ├── MySQL.java
│ ├── MySQLNickManager.java
│ └── MySQLPlayerDataManager.java
│ ├── updater
│ ├── Updater.java
│ └── VersionComparisonResult.java
│ └── utilities
│ ├── ActionBarUtils.java
│ ├── AsyncTask.java
│ ├── BStatsMetrics.java
│ ├── ClassFinder.java
│ ├── GUIManager.java
│ ├── ItemBuilder.java
│ ├── MineSkinAPI.java
│ ├── StringUtils.java
│ ├── Utils.java
│ ├── configuration
│ ├── BaseFileFactory.java
│ ├── ConfigurationFile.java
│ ├── YamlFileFactory.java
│ └── yaml
│ │ ├── GUIYamlFile.java
│ │ ├── LanguageYamlFile.java
│ │ ├── NickNameYamlFile.java
│ │ ├── SavedNickDataYamlFile.java
│ │ ├── SetupYamlFile.java
│ │ └── YamlFile.java
│ └── mojang
│ ├── MojangAPI.java
│ ├── gameprofiles
│ ├── GameProfileBuilder.java
│ ├── GameProfileBuilder_1_7.java
│ └── GameProfileBuilder_1_8_R1.java
│ └── uuidfetching
│ ├── UUIDFetcher.java
│ ├── UUIDFetcher_1_7.java
│ └── UUIDFetcher_1_8_R1.java
└── resources
├── nickNames.txt
└── plugin.yml
/.github/.version:
--------------------------------------------------------------------------------
1 | 3.15.3
--------------------------------------------------------------------------------
/.github/renovate.json:
--------------------------------------------------------------------------------
1 | {
2 | "extends": [
3 | "config:base"
4 | ],
5 | "includeForks": true,
6 | "automerge": true,
7 | "baseBranches": ["master"]
8 | }
9 |
--------------------------------------------------------------------------------
/.github/workflows/codeql.yml:
--------------------------------------------------------------------------------
1 | # For most projects, this workflow file will not need changing; you simply need
2 | # to commit it to your repository.
3 | #
4 | # You may wish to alter this file to override the set of languages analyzed,
5 | # or to provide custom queries or build logic.
6 | #
7 | # ******** NOTE ********
8 | # We have attempted to detect the languages in your repository. Please check
9 | # the `language` matrix defined below to confirm you have the correct set of
10 | # supported CodeQL languages.
11 | #
12 | name: "CodeQL"
13 |
14 | on:
15 | push:
16 | pull_request:
17 | workflow_dispatch:
18 |
19 | jobs:
20 | analyze:
21 | name: Analyze
22 | runs-on: ubuntu-latest
23 | permissions:
24 | actions: read
25 | contents: read
26 | security-events: write
27 |
28 | strategy:
29 | fail-fast: false
30 | matrix:
31 | language: [ 'java' ]
32 | # CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python', 'ruby' ]
33 | # Learn more about CodeQL language support at https://git.io/codeql-language-support
34 |
35 | steps:
36 | - name: Checkout repository
37 | uses: actions/checkout@v3
38 |
39 | - name: Read .version file
40 | id: version
41 | run: echo "::set-output name=version::$(cat .github/.version)"
42 |
43 | - name: Set up JDK 8
44 | uses: actions/setup-java@v3
45 | with:
46 | java-version: '8'
47 | distribution: 'temurin'
48 | cache: maven
49 |
50 | - name: Prepare CodeQL
51 | run: |
52 | sed -i 's/0.0.0/${{ steps.version.outputs.version }}/g' pom.xml
53 | grep pom.xml -e ${{ steps.version.outputs.version }}
54 | sed -i 's/0.0.0/${{ steps.version.outputs.version }}/g' src/main/resources/plugin.yml
55 | grep src/main/resources/plugin.yml -e ${{ steps.version.outputs.version }}
56 | mkdir lib
57 | curl -L https://github.com/PEXPlugins/PermissionsEx/releases/download/STABLE-1.23.4/PermissionsEx-1.23.4.jar -o lib/PermissionsEx.jar
58 | curl -L https://github.com/NEZNAMY/TAB/releases/download/3.1.2/TAB.v3.1.2.jar -o lib/TAB.jar
59 | curl -L https://cdn.getbukkit.org/spigot/spigot-1.7.10-SNAPSHOT-b1657.jar -o lib/spigot-1.7.10.jar
60 | curl -L https://cdn.getbukkit.org/spigot/spigot-1.8-R0.1-SNAPSHOT-latest.jar -o lib/spigot-1.8.jar
61 |
62 | # Initializes the CodeQL tools for scanning.
63 | - name: Initialize CodeQL
64 | uses: github/codeql-action/init@v2
65 | with:
66 | languages: ${{ matrix.language }}
67 | # If you wish to specify custom queries, you can do so here or in a config file.
68 | # By default, queries listed here will override any specified in a config file.
69 | # Prefix the list here with "+" to use these queries and those in the config file.
70 | # queries: ./path/to/local/query, your-org/your-repo/queries@main
71 |
72 | # Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
73 | # If this step fails, then you should remove it and run the build manually (see below)
74 | - name: Autobuild
75 | uses: github/codeql-action/autobuild@v2
76 |
77 | # ℹ️ Command-line programs to run using the OS shell.
78 | # 📚 https://git.io/JvXDl
79 |
80 | # ✏️ If the Autobuild fails above, remove it and uncomment the following three lines
81 | # and modify them (or add more) to build your code if your project
82 | # uses a compiled language
83 |
84 | #- run: |
85 | # make bootstrap
86 | # make release
87 |
88 | - name: Perform CodeQL Analysis
89 | uses: github/codeql-action/analyze@v2
90 |
--------------------------------------------------------------------------------
/.github/workflows/json.yml:
--------------------------------------------------------------------------------
1 | name: JSON check
2 |
3 | on:
4 | push:
5 | pull_request:
6 | workflow_dispatch:
7 |
8 | jobs:
9 | test-json:
10 | runs-on: ubuntu-latest
11 | steps:
12 | - uses: actions/checkout@v3
13 | - name: json-syntax-check
14 | uses: limitusus/json-syntax-check@v2
15 | with:
16 | pattern: "\\.json$*"
--------------------------------------------------------------------------------
/.github/workflows/maven.yml:
--------------------------------------------------------------------------------
1 | name: Java CI with Maven
2 |
3 | on:
4 | push:
5 | pull_request:
6 | workflow_dispatch:
7 |
8 | jobs:
9 | build:
10 | runs-on: ubuntu-latest
11 | steps:
12 | - uses: actions/checkout@v3
13 |
14 | - name: Read .version file
15 | id: version
16 | run: echo "::set-output name=version::$(cat .github/.version)"
17 |
18 | - name: Set up JDK 8
19 | uses: actions/setup-java@v3
20 | with:
21 | java-version: '8'
22 | distribution: 'temurin'
23 | cache: maven
24 |
25 | - name: Build with Maven
26 | run: |
27 | sed -i 's/0.0.0/${{ steps.version.outputs.version }}/g' pom.xml
28 | grep pom.xml -e ${{ steps.version.outputs.version }}
29 | sed -i 's/0.0.0/${{ steps.version.outputs.version }}/g' src/main/resources/plugin.yml
30 | grep src/main/resources/plugin.yml -e ${{ steps.version.outputs.version }}
31 | mkdir lib
32 | curl -L https://github.com/PEXPlugins/PermissionsEx/releases/download/STABLE-1.23.4/PermissionsEx-1.23.4.jar -o lib/PermissionsEx.jar
33 | curl -L https://github.com/NEZNAMY/TAB/releases/download/3.1.2/TAB.v3.1.2.jar -o lib/TAB.jar
34 | curl -L https://cdn.getbukkit.org/spigot/spigot-1.7.10-SNAPSHOT-b1657.jar -o lib/spigot-1.7.10.jar
35 | curl -L https://cdn.getbukkit.org/spigot/spigot-1.8-R0.1-SNAPSHOT-latest.jar -o lib/spigot-1.8.jar
36 | mvn -B package --file pom.xml
37 | mv target/eazynick-* target/EazyNick.jar
38 |
39 | - uses: actions/upload-artifact@v3
40 | with:
41 | name: artifacts
42 | path: target/*.jar
43 |
--------------------------------------------------------------------------------
/.github/workflows/release.yml:
--------------------------------------------------------------------------------
1 | name: Release version
2 |
3 | on:
4 | workflow_dispatch:
5 | push:
6 | paths:
7 | - .github/workflows/release.yml
8 | - .github/.version
9 |
10 | jobs:
11 | build:
12 | runs-on: ubuntu-latest
13 | steps:
14 | - uses: actions/checkout@v3
15 |
16 | - name: Read .version file
17 | id: version
18 | run: echo "::set-output name=version::$(cat .github/.version)"
19 |
20 | - name: Set up JDK 8
21 | uses: actions/setup-java@v3
22 | with:
23 | java-version: '8'
24 | distribution: 'temurin'
25 | cache: maven
26 |
27 | - name: Build with Maven
28 | run: |
29 | sed -i 's/0.0.0/${{ steps.version.outputs.version }}/g' pom.xml
30 | grep pom.xml -e ${{ steps.version.outputs.version }}
31 | sed -i 's/0.0.0/${{ steps.version.outputs.version }}/g' src/main/resources/plugin.yml
32 | grep src/main/resources/plugin.yml -e ${{ steps.version.outputs.version }}
33 | mkdir lib
34 | curl -L https://github.com/PEXPlugins/PermissionsEx/releases/download/STABLE-1.23.4/PermissionsEx-1.23.4.jar -o lib/PermissionsEx.jar
35 | curl -L https://api.spiget.org/v2/resources/3836/download -o lib/NametagEdit.jar
36 | curl -L https://cdn.getbukkit.org/spigot/spigot-1.7.10-SNAPSHOT-b1657.jar -o lib/spigot-1.7.10.jar
37 | curl -L https://cdn.getbukkit.org/spigot/spigot-1.8-R0.1-SNAPSHOT-latest.jar -o lib/spigot-1.8.jar
38 | mvn -B package --file pom.xml
39 | mv target/eazynick-*.jar target/EazyNick.jar
40 |
41 | - uses: actions/upload-artifact@v3
42 | with:
43 | name: artifacts
44 | path: target/*.jar
45 |
46 | - uses: "marvinpinto/action-automatic-releases@latest"
47 | with:
48 | prerelease: false
49 | repo_token: ${{ github.token }}
50 | title: v${{ steps.version.outputs.version }}
51 | automatic_release_tag: v${{ steps.version.outputs.version }}
52 | files: |
53 | target/EazyNick.jar
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | .idea
2 | out
3 | target
4 | lib
5 | compile-dev.*
6 | *.iml
--------------------------------------------------------------------------------
/.run/compile-unix.run.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
--------------------------------------------------------------------------------
/.run/compile-win.run.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2022-2023 Justus G.
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | 
2 | # EazyNick
3 |
4 | ## Useful links
5 | > [Discord](https://discord.justix-dev.com)
6 |
7 | > [Support my work](https://www.paypal.me/JustixDevelopment)
8 |
9 | ## Compiling
10 | ### Requirements
11 | #### Mac OS
12 | > [brew](https://brew.sh): Execute the command on the homepage
13 |
14 | > sed: `brew install gnu-sed`
15 |
16 | #### Debian/Ubuntu
17 | > sed: `sudo apt-get install sed`
18 |
19 | #### Windows
20 | > [sed](http://gnuwin32.sourceforge.net/packages/sed.htm): Read the instructions on the download page
21 |
22 | ### Importing the run configuration in IntelliJ IDEA
23 | 1. Open `.run/compile-unix.run.xml` (Mac OS & Linux) or `.run/compile-win.run.xml` (Windows) in IntelliJ IDEA
24 | 2. Click on `Open Run/Debug Configurations...`
25 | 3. Click `OK`
26 |
27 | ### Compiling to jar using the run configuration
28 | Simply run the configuration, the jar will be saved at `target/EazyNick-vX.X.X-dev.jar`
29 |
30 | ### Compiling to jar manually
31 | 1. Compile the sources using ``mvn clean compile`` (in IntelliJ IDEA: Maven menu --> Lifecycle --> clean/compile)
32 | 2. Open `target/classes/plugin.yml` and replace `0.0.0` with the current version (located in `.github/.version`)
33 | 3. Run ``mvn -B package --file pom.xml`` (in IntelliJ IDEA: Maven menu --> Lifecycle --> package)
34 | 4. The jar will be saved as `target/eazynick-0.0.0.jar`
35 |
36 | ## License
37 | EazyNick is licensed under the permissive MIT license. Please see [`LICENSE`](https://github.com/JustixDevelopment/EazyNick/blob/master/LICENSE) for more info.
38 |
--------------------------------------------------------------------------------
/compile.bat:
--------------------------------------------------------------------------------
1 | @echo off
2 | cd /D "%~dp0target\classes"
3 | set /p version=<..\..\.github\.version
4 |
5 | sed -i "s/0.0.0/%version%/g" plugin.yml
6 | del sed*
7 | jar cvf "..\EazyNick-%version%-dev.jar" .
--------------------------------------------------------------------------------
/compile.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 | cd "$(dirname "$0")"/target/classes || exit
3 |
4 | version=$(cat ../../.github/.version)
5 |
6 | sed -i '' "s/0.0.0/$version/g" plugin.yml
7 | jar cvf "../EazyNick-$version-dev.jar" ./*
8 | exit
--------------------------------------------------------------------------------
/jitpack.yml:
--------------------------------------------------------------------------------
1 | jdk:
2 | - oraclejdk8
3 | before_install:
4 | - sed -i "s/0.0.0/$(cat .github/.version)/g" pom.xml
5 | - sed -i "s/0.0.0/$(cat .github/.version)/g" src/main/resources/plugin.yml
6 | - mkdir lib
7 | - curl -L https://github.com/PEXPlugins/PermissionsEx/releases/download/STABLE-1.23.4/PermissionsEx-1.23.4.jar -o lib/PermissionsEx.jar
8 | - curl -L https://api.spiget.org/v2/resources/3836/download -o lib/NametagEdit.jar
9 | - curl -L https://cdn.getbukkit.org/spigot/spigot-1.7.10-SNAPSHOT-b1657.jar -o lib/spigot-1.7.10.jar
10 | - curl -L https://cdn.getbukkit.org/spigot/spigot-1.8-R0.1-SNAPSHOT-latest.jar -o lib/spigot-1.8.jar
--------------------------------------------------------------------------------
/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 4.0.0
6 |
7 | com.justixdev
8 | eazynick
9 | 0.0.0
10 |
11 |
12 | 1.8
13 | 1.8
14 |
15 |
16 |
17 | jitpack.io
18 | https://jitpack.io
19 |
20 |
21 | spigot-repo
22 | https://hub.spigotmc.org/nexus/content/repositories/snapshots/
23 |
24 |
25 | placeholder-api
26 | https://repo.extendedclip.com/content/repositories/placeholderapi/
27 |
28 |
29 | releases
30 | https://repo.cloudnetservice.eu/repository/releases/
31 |
32 |
33 | codemc-releases
34 | https://repo.codemc.org/repository/maven-releases/
35 |
36 |
37 | krypton-repo-releases
38 | https://repo.kryptonmc.org/releases
39 |
40 |
41 |
42 |
43 |
44 | org.projectlombok
45 | lombok
46 | 1.18.26
47 | compile
48 |
49 |
50 |
51 |
52 | org.spigotmc
53 | spigot-api
54 | 1.20-R0.1-SNAPSHOT
55 | provided
56 |
57 |
58 | org.spigotmc
59 | spigot-1.8.0
60 | 1.8-R0.1-SNAPSHOT-latest
61 | system
62 | ${basedir}/lib/spigot-1.8.jar
63 |
64 |
65 | org.spigotmc
66 | spigot-1.7.10
67 | 1.7.10-SNAPSHOT-b1657
68 | system
69 | ${basedir}/lib/spigot-1.7.10.jar
70 |
71 |
72 |
73 |
74 | me.clip
75 | placeholderapi
76 | 2.11.3
77 | provided
78 |
79 |
80 | de.dytanic.cloudnet
81 | cloudnet-api-bridge
82 | 2.1.17
83 | provided
84 |
85 |
86 | com.github.MilkBowl
87 | VaultAPI
88 | 1.7.1
89 | provided
90 |
91 |
92 | net.skinsrestorer
93 | skinsrestorer-api
94 | 14.2.12
95 | provided
96 |
97 |
98 | net.luckperms
99 | api
100 | 5.4
101 | provided
102 |
103 |
104 | me.neznamy
105 | tab-api
106 | 4.0.0
107 | provided
108 |
109 |
110 | com.nametagedit
111 | nametagedit
112 | 4.5.11
113 | system
114 | ${basedir}/lib/NametagEdit.jar
115 |
116 |
117 | ru.tehkode
118 | permissions
119 | 1.23.4
120 | system
121 | ${basedir}/lib/PermissionsEx.jar
122 |
123 |
124 |
--------------------------------------------------------------------------------
/src/main/java/com/justixdev/eazynick/api/NameFormatting.java:
--------------------------------------------------------------------------------
1 | package com.justixdev.eazynick.api;
2 |
3 | import lombok.AllArgsConstructor;
4 | import lombok.Data;
5 |
6 | @Data
7 | @AllArgsConstructor
8 | public class NameFormatting {
9 |
10 | private String chatPrefix, chatSuffix, tabPrefix, tabSuffix, tagPrefix, tagSuffix;
11 |
12 | }
13 |
--------------------------------------------------------------------------------
/src/main/java/com/justixdev/eazynick/api/events/PlayerNickEvent.java:
--------------------------------------------------------------------------------
1 | package com.justixdev.eazynick.api.events;
2 |
3 | import lombok.Data;
4 | import lombok.EqualsAndHashCode;
5 | import lombok.Getter;
6 | import org.bukkit.entity.Player;
7 | import org.bukkit.event.Cancellable;
8 | import org.bukkit.event.Event;
9 | import org.bukkit.event.HandlerList;
10 | import org.jetbrains.annotations.NotNull;
11 |
12 | import java.util.UUID;
13 |
14 | @EqualsAndHashCode(callSuper = true)
15 | @Data
16 | public class PlayerNickEvent extends Event implements Cancellable {
17 |
18 | @Getter
19 | private static final HandlerList handlerList = new HandlerList();
20 |
21 | private boolean cancelled = false;
22 | private final Player player;
23 | private String nickName, skinName, chatPrefix, chatSuffix, tabPrefix, tabSuffix, tagPrefix, tagSuffix, groupName;
24 | private UUID spoofedUniqueId;
25 | private final boolean isBungeeOrJoinNick, isRenick;
26 | private int sortID;
27 |
28 | public PlayerNickEvent(Player player, String nickName, String skinName, UUID spoofedUniqueId, String chatPrefix, String chatSuffix, String tabPrefix, String tabSuffix, String tagPrefix, String tagSuffix, boolean isBungeeOrJoinNick, boolean isRenick, int sortID, String groupName) {
29 | this.player = player;
30 | this.nickName = nickName;
31 | this.skinName = skinName;
32 | this.spoofedUniqueId = spoofedUniqueId;
33 | this.chatPrefix = chatPrefix;
34 | this.chatSuffix = chatSuffix;
35 | this.tabPrefix = tabPrefix;
36 | this.tabSuffix = tabSuffix;
37 | this.tagPrefix = tagPrefix;
38 | this.tagSuffix = tagSuffix;
39 | this.isBungeeOrJoinNick = isBungeeOrJoinNick;
40 | this.isRenick = isRenick;
41 | this.sortID = sortID;
42 | this.groupName = groupName;
43 | }
44 |
45 | public UUID getSpoofedUniqueId() {
46 | return this.spoofedUniqueId != null
47 | ? this.spoofedUniqueId
48 | : this.player.getUniqueId();
49 | }
50 |
51 | @NotNull
52 | @Override
53 | public HandlerList getHandlers() {
54 | return handlerList;
55 | }
56 |
57 | }
--------------------------------------------------------------------------------
/src/main/java/com/justixdev/eazynick/api/events/PlayerUnnickEvent.java:
--------------------------------------------------------------------------------
1 | package com.justixdev.eazynick.api.events;
2 |
3 | import lombok.Data;
4 | import lombok.EqualsAndHashCode;
5 | import lombok.Getter;
6 | import lombok.RequiredArgsConstructor;
7 | import org.bukkit.entity.Player;
8 | import org.bukkit.event.Cancellable;
9 | import org.bukkit.event.Event;
10 | import org.bukkit.event.HandlerList;
11 | import org.jetbrains.annotations.NotNull;
12 |
13 | @EqualsAndHashCode(callSuper = true)
14 | @Data
15 | @RequiredArgsConstructor
16 | public class PlayerUnnickEvent extends Event implements Cancellable {
17 |
18 | @Getter
19 | private static final HandlerList handlerList = new HandlerList();
20 | private boolean cancelled = false;
21 | private final Player player;
22 |
23 | @Override
24 | public @NotNull HandlerList getHandlers() {
25 | return handlerList;
26 | }
27 |
28 | }
--------------------------------------------------------------------------------
/src/main/java/com/justixdev/eazynick/commands/Command.java:
--------------------------------------------------------------------------------
1 | package com.justixdev.eazynick.commands;
2 |
3 | import com.justixdev.eazynick.commands.parameters.ParameterCombination;
4 | import lombok.Data;
5 | import org.bukkit.command.CommandSender;
6 |
7 | import java.util.ArrayList;
8 | import java.util.Collections;
9 | import java.util.List;
10 |
11 | @Data
12 | public abstract class Command {
13 |
14 | protected List aliases;
15 |
16 | public Command() {
17 | this.initAliases();
18 | }
19 |
20 | protected void initAliases() {
21 | this.aliases = new ArrayList<>();
22 | }
23 |
24 | public List getCombinations() {
25 | return Collections.emptyList();
26 | }
27 |
28 | public abstract CommandResult execute(CommandSender sender, ParameterCombination args);
29 |
30 | }
--------------------------------------------------------------------------------
/src/main/java/com/justixdev/eazynick/commands/CommandMetaData.java:
--------------------------------------------------------------------------------
1 | package com.justixdev.eazynick.commands;
2 |
3 | import lombok.AllArgsConstructor;
4 | import lombok.Data;
5 |
6 | @Data
7 | @AllArgsConstructor
8 | public class CommandMetaData {
9 |
10 | private final String name;
11 | private final String description;
12 | private final boolean playersOnly;
13 |
14 | }
15 |
--------------------------------------------------------------------------------
/src/main/java/com/justixdev/eazynick/commands/CommandResult.java:
--------------------------------------------------------------------------------
1 | package com.justixdev.eazynick.commands;
2 |
3 | public enum CommandResult {
4 |
5 | FAILURE_NO_PERMISSION,
6 | FAILURE_OTHER,
7 | SUCCESS
8 |
9 | }
10 |
--------------------------------------------------------------------------------
/src/main/java/com/justixdev/eazynick/commands/CustomCommand.java:
--------------------------------------------------------------------------------
1 | package com.justixdev.eazynick.commands;
2 |
3 | import java.lang.annotation.ElementType;
4 | import java.lang.annotation.Retention;
5 | import java.lang.annotation.RetentionPolicy;
6 | import java.lang.annotation.Target;
7 |
8 | @Retention(RetentionPolicy.RUNTIME)
9 | @Target(ElementType.TYPE)
10 | public @interface CustomCommand {
11 |
12 | String name();
13 |
14 | String description();
15 |
16 | boolean playersOnly() default true;
17 |
18 | }
--------------------------------------------------------------------------------
/src/main/java/com/justixdev/eazynick/commands/impl/disguise/ChangeSkinCommand.java:
--------------------------------------------------------------------------------
1 | package com.justixdev.eazynick.commands.impl.disguise;
2 |
3 | import com.justixdev.eazynick.EazyNick;
4 | import com.justixdev.eazynick.api.NickManager;
5 | import com.justixdev.eazynick.commands.Command;
6 | import com.justixdev.eazynick.commands.CommandResult;
7 | import com.justixdev.eazynick.commands.CustomCommand;
8 | import com.justixdev.eazynick.commands.parameters.CommandParameter;
9 | import com.justixdev.eazynick.commands.parameters.ParameterCombination;
10 | import com.justixdev.eazynick.commands.parameters.ParameterType;
11 | import com.justixdev.eazynick.utilities.Utils;
12 | import com.justixdev.eazynick.utilities.configuration.yaml.LanguageYamlFile;
13 | import com.justixdev.eazynick.utilities.configuration.yaml.SetupYamlFile;
14 | import org.bukkit.command.CommandSender;
15 | import org.bukkit.entity.Player;
16 |
17 | import java.util.Arrays;
18 | import java.util.List;
19 |
20 | @CustomCommand(name = "changeskin", description = "Changes your skin")
21 | public class ChangeSkinCommand extends Command {
22 |
23 | @Override
24 | public List getCombinations() {
25 | return Arrays.asList(
26 | // random
27 | new ParameterCombination(),
28 | // custom
29 | new ParameterCombination(
30 | new CommandParameter("name", ParameterType.TEXT)));
31 | }
32 |
33 | @Override
34 | public CommandResult execute(CommandSender sender, ParameterCombination args) {
35 | EazyNick eazyNick = EazyNick.getInstance();
36 | Utils utils = eazyNick.getUtils();
37 | LanguageYamlFile languageYamlFile = eazyNick.getLanguageYamlFile();
38 | SetupYamlFile setupYamlFile = eazyNick.getSetupYamlFile();
39 |
40 | String prefix = utils.getPrefix();
41 | Player player = (Player) sender;
42 |
43 | if(!(utils.getCanUseNick().getOrDefault(player.getUniqueId(), System.currentTimeMillis()) <= System.currentTimeMillis())) {
44 | languageYamlFile.sendMessage(
45 | player,
46 | languageYamlFile.getConfigString(player, "Messages.NickDelay")
47 | .replace("%prefix%", prefix)
48 | );
49 | return CommandResult.SUCCESS;
50 | }
51 |
52 | NickManager api = new NickManager(player);
53 | String name = args.withName("name")
54 | .map(CommandParameter::asText)
55 | .orElse(null);
56 |
57 | if(name != null) {
58 | if(!player.hasPermission("eazynick.skin.custom"))
59 | return CommandResult.FAILURE_NO_PERMISSION;
60 | } else if(player.hasPermission("eazynick.skin.random")) {
61 | name = setupYamlFile.getConfiguration().getBoolean("UseMineSkinAPI")
62 | ? "MINESKIN:" + utils.getRandomStringFromList(utils.getMineSkinUUIDs())
63 | : api.getRandomName();
64 | } else
65 | return CommandResult.FAILURE_NO_PERMISSION;
66 |
67 | api.changeSkin(name);
68 |
69 | languageYamlFile.sendMessage(
70 | player,
71 | languageYamlFile.getConfigString(player, "Messages.SkinChanged")
72 | .replace("%skinName%", name)
73 | .replace("%skinname%", name)
74 | .replace("%prefix%", prefix)
75 | );
76 |
77 | return CommandResult.SUCCESS;
78 | }
79 |
80 | }
81 |
--------------------------------------------------------------------------------
/src/main/java/com/justixdev/eazynick/commands/impl/disguise/ChangeSkinOtherCommand.java:
--------------------------------------------------------------------------------
1 | package com.justixdev.eazynick.commands.impl.disguise;
2 |
3 | import com.justixdev.eazynick.EazyNick;
4 | import com.justixdev.eazynick.api.NickManager;
5 | import com.justixdev.eazynick.commands.Command;
6 | import com.justixdev.eazynick.commands.CommandResult;
7 | import com.justixdev.eazynick.commands.CustomCommand;
8 | import com.justixdev.eazynick.commands.parameters.CommandParameter;
9 | import com.justixdev.eazynick.commands.parameters.ParameterCombination;
10 | import com.justixdev.eazynick.commands.parameters.ParameterType;
11 | import com.justixdev.eazynick.utilities.Utils;
12 | import com.justixdev.eazynick.utilities.configuration.yaml.LanguageYamlFile;
13 | import com.justixdev.eazynick.utilities.configuration.yaml.SetupYamlFile;
14 | import org.bukkit.command.CommandSender;
15 | import org.bukkit.entity.Player;
16 |
17 | import java.util.Arrays;
18 | import java.util.List;
19 |
20 | @CustomCommand(name = "changeskinother", description = "Changes the skin of another player")
21 | public class ChangeSkinOtherCommand extends Command {
22 |
23 | @Override
24 | public List getCombinations() {
25 | return Arrays.asList(
26 | // random
27 | new ParameterCombination(
28 | new CommandParameter("player", ParameterType.PLAYER)),
29 | // custom
30 | new ParameterCombination(
31 | new CommandParameter("player", ParameterType.PLAYER),
32 | new CommandParameter("name", ParameterType.TEXT)));
33 | }
34 |
35 | @Override
36 | public CommandResult execute(CommandSender sender, ParameterCombination args) {
37 | EazyNick eazyNick = EazyNick.getInstance();
38 | Utils utils = eazyNick.getUtils();
39 | LanguageYamlFile languageYamlFile = eazyNick.getLanguageYamlFile();
40 | SetupYamlFile setupYamlFile = eazyNick.getSetupYamlFile();
41 |
42 | String prefix = utils.getPrefix();
43 | Player player = (Player) sender;
44 | Player targetPlayer = args.withName("player")
45 | .map(CommandParameter::asPlayer)
46 | .orElse(null);
47 | NickManager api = new NickManager(targetPlayer);
48 | String name = args.withName("name")
49 | .map(CommandParameter::asText)
50 | .orElse(null);
51 |
52 | assert targetPlayer != null;
53 |
54 | if(name != null) {
55 | if(!player.hasPermission("eazynick.other.skin.custom"))
56 | return CommandResult.FAILURE_NO_PERMISSION;
57 |
58 | languageYamlFile.sendMessage(
59 | player,
60 | languageYamlFile.getConfigString(player, "Messages.Other.SelectedSkin")
61 | .replace("%playerName%", targetPlayer.getName())
62 | .replace("%playername%", targetPlayer.getName())
63 | .replace("%skinName%", name)
64 | .replace("%skinname%", name)
65 | .replace("%prefix%", prefix)
66 | );
67 | } else if(player.hasPermission("eazynick.other.skin.random")) {
68 | name = setupYamlFile.getConfiguration().getBoolean("UseMineSkinAPI")
69 | ? "MINESKIN:" + utils.getRandomStringFromList(utils.getMineSkinUUIDs())
70 | : api.getRandomName();
71 |
72 | languageYamlFile.sendMessage(
73 | player,
74 | languageYamlFile.getConfigString(player, "Messages.Other.RandomSkin")
75 | .replace("%player%", targetPlayer.getName())
76 | .replace("%prefix%", prefix)
77 | );
78 | } else
79 | return CommandResult.FAILURE_NO_PERMISSION;
80 |
81 | api.changeSkin(name);
82 |
83 | return CommandResult.SUCCESS;
84 | }
85 |
86 | }
87 |
--------------------------------------------------------------------------------
/src/main/java/com/justixdev/eazynick/commands/impl/disguise/FixSkinCommand.java:
--------------------------------------------------------------------------------
1 | package com.justixdev.eazynick.commands.impl.disguise;
2 |
3 | import com.justixdev.eazynick.EazyNick;
4 | import com.justixdev.eazynick.commands.Command;
5 | import com.justixdev.eazynick.commands.CommandResult;
6 | import com.justixdev.eazynick.commands.CustomCommand;
7 | import com.justixdev.eazynick.commands.parameters.ParameterCombination;
8 | import com.justixdev.eazynick.nms.NMSNickManager;
9 | import com.justixdev.eazynick.utilities.Utils;
10 | import com.justixdev.eazynick.utilities.configuration.yaml.LanguageYamlFile;
11 | import org.bukkit.command.CommandSender;
12 | import org.bukkit.entity.Player;
13 |
14 | @CustomCommand(name = "fixskin", description = "Reloads your skin")
15 | public class FixSkinCommand extends Command {
16 |
17 | @Override
18 | public CommandResult execute(CommandSender sender, ParameterCombination args) {
19 | EazyNick eazyNick = EazyNick.getInstance();
20 | Utils utils = eazyNick.getUtils();
21 | LanguageYamlFile languageYamlFile = eazyNick.getLanguageYamlFile();
22 |
23 | Player player = (Player) sender;
24 |
25 | if(!player.hasPermission("eazynick.skin.fix"))
26 | return CommandResult.FAILURE_NO_PERMISSION;
27 |
28 | new NMSNickManager(player).updatePlayer();
29 |
30 | languageYamlFile.sendMessage(
31 | player,
32 | languageYamlFile.getConfigString(player, "Messages.FixSkin")
33 | .replace("%prefix%", utils.getPrefix())
34 | );
35 |
36 | return CommandResult.SUCCESS;
37 | }
38 |
39 | }
40 |
--------------------------------------------------------------------------------
/src/main/java/com/justixdev/eazynick/commands/impl/disguise/NameCommand.java:
--------------------------------------------------------------------------------
1 | package com.justixdev.eazynick.commands.impl.disguise;
2 |
3 | import com.justixdev.eazynick.EazyNick;
4 | import com.justixdev.eazynick.api.NickManager;
5 | import com.justixdev.eazynick.commands.Command;
6 | import com.justixdev.eazynick.commands.CommandResult;
7 | import com.justixdev.eazynick.commands.CustomCommand;
8 | import com.justixdev.eazynick.commands.parameters.ParameterCombination;
9 | import com.justixdev.eazynick.utilities.Utils;
10 | import com.justixdev.eazynick.utilities.configuration.yaml.LanguageYamlFile;
11 | import org.bukkit.command.CommandSender;
12 | import org.bukkit.entity.Player;
13 |
14 | @CustomCommand(name = "name", description = "Shows your active nickname")
15 | public class NameCommand extends Command {
16 |
17 | @Override
18 | public CommandResult execute(CommandSender sender, ParameterCombination args) {
19 | EazyNick eazyNick = EazyNick.getInstance();
20 | Utils utils = eazyNick.getUtils();
21 | LanguageYamlFile languageYamlFile = eazyNick.getLanguageYamlFile();
22 |
23 | String prefix = utils.getPrefix();
24 | Player player = (Player) sender;
25 | NickManager api = new NickManager(player);
26 |
27 | if(!api.isNicked()) {
28 | languageYamlFile.sendMessage(
29 | player,
30 | languageYamlFile.getConfigString(player, "Messages.NotNicked")
31 | .replace("%prefix%", prefix)
32 | );
33 | return CommandResult.SUCCESS;
34 | }
35 |
36 | languageYamlFile.sendMessage(
37 | player,
38 | languageYamlFile.getConfigString(player, "Messages.Name")
39 | .replace("%name%", api.getNickName())
40 | .replace("%prefix%", prefix)
41 | );
42 |
43 | return CommandResult.SUCCESS;
44 | }
45 |
46 | }
47 |
--------------------------------------------------------------------------------
/src/main/java/com/justixdev/eazynick/commands/impl/disguise/NickedPlayersCommand.java:
--------------------------------------------------------------------------------
1 | package com.justixdev.eazynick.commands.impl.disguise;
2 |
3 | import com.justixdev.eazynick.EazyNick;
4 | import com.justixdev.eazynick.api.NickManager;
5 | import com.justixdev.eazynick.commands.Command;
6 | import com.justixdev.eazynick.commands.CommandResult;
7 | import com.justixdev.eazynick.commands.CustomCommand;
8 | import com.justixdev.eazynick.commands.parameters.ParameterCombination;
9 | import com.justixdev.eazynick.utilities.Utils;
10 | import com.justixdev.eazynick.utilities.configuration.yaml.LanguageYamlFile;
11 | import org.bukkit.Bukkit;
12 | import org.bukkit.command.CommandSender;
13 | import org.bukkit.entity.Player;
14 |
15 | import java.util.List;
16 | import java.util.stream.Collectors;
17 |
18 | @CustomCommand(name = "nickedplayers", description = "Shows a list of all nicked players")
19 | public class NickedPlayersCommand extends Command {
20 |
21 | @Override
22 | protected void initAliases() {
23 | super.initAliases();
24 |
25 | this.aliases.add("disguisedplayers");
26 | }
27 |
28 | @Override
29 | public CommandResult execute(CommandSender sender, ParameterCombination args) {
30 | EazyNick eazyNick = EazyNick.getInstance();
31 | Utils utils = eazyNick.getUtils();
32 | LanguageYamlFile languageYamlFile = eazyNick.getLanguageYamlFile();
33 |
34 | String prefix = utils.getPrefix();
35 | Player player = (Player) sender;
36 |
37 | if(!player.hasPermission("eazynick.nickedplayers"))
38 | return CommandResult.FAILURE_NO_PERMISSION;
39 |
40 | List extends Player> nickedPlayers = Bukkit.getOnlinePlayers()
41 | .stream()
42 | .filter(currentPlayer -> utils.getNickedPlayers().containsKey(currentPlayer.getUniqueId()))
43 | .collect(Collectors.toList());
44 |
45 | if(!nickedPlayers.isEmpty()) {
46 | languageYamlFile.sendMessage(
47 | player,
48 | languageYamlFile.getConfigString(player, "Messages.NickedPlayers.CurrentNickedPlayers")
49 | .replace("%prefix%", prefix)
50 | );
51 |
52 | nickedPlayers.forEach(currentNickedPlayer -> {
53 | NickManager api = new NickManager(currentNickedPlayer);
54 |
55 | languageYamlFile.sendMessage(
56 | player,
57 | languageYamlFile.getConfigString(player, "Messages.NickedPlayers.PlayerInfo")
58 | .replace("%realName%", api.getRealName())
59 | .replace("%realname%", api.getRealName())
60 | .replace("%nickName%", api.getNickName())
61 | .replace("%nickname%", api.getNickName())
62 | .replace("%prefix%", prefix)
63 | );
64 | });
65 | } else
66 | languageYamlFile.sendMessage(
67 | player,
68 | languageYamlFile.getConfigString(player, "Messages.NickedPlayers.NoPlayerIsNicked")
69 | .replace("%prefix%", prefix)
70 | );
71 |
72 | return CommandResult.SUCCESS;
73 | }
74 |
75 | }
76 |
--------------------------------------------------------------------------------
/src/main/java/com/justixdev/eazynick/commands/impl/disguise/ReNickCommand.java:
--------------------------------------------------------------------------------
1 | package com.justixdev.eazynick.commands.impl.disguise;
2 |
3 | import com.justixdev.eazynick.EazyNick;
4 | import com.justixdev.eazynick.api.events.PlayerUnnickEvent;
5 | import com.justixdev.eazynick.commands.Command;
6 | import com.justixdev.eazynick.commands.CommandResult;
7 | import com.justixdev.eazynick.commands.CustomCommand;
8 | import com.justixdev.eazynick.commands.parameters.ParameterCombination;
9 | import com.justixdev.eazynick.sql.MySQLNickManager;
10 | import com.justixdev.eazynick.utilities.Utils;
11 | import com.justixdev.eazynick.utilities.configuration.yaml.LanguageYamlFile;
12 | import org.bukkit.Bukkit;
13 | import org.bukkit.command.CommandSender;
14 | import org.bukkit.entity.Player;
15 |
16 | @CustomCommand(name = "renick", description = "For internal purposes only")
17 | public class ReNickCommand extends Command {
18 |
19 | @Override
20 | public CommandResult execute(CommandSender sender, ParameterCombination args) {
21 | EazyNick eazyNick = EazyNick.getInstance();
22 | Utils utils = eazyNick.getUtils();
23 | LanguageYamlFile languageYamlFile = eazyNick.getLanguageYamlFile();
24 | MySQLNickManager mysqlNickManager = eazyNick.getMysqlNickManager();
25 |
26 | Player player = (Player) sender;
27 |
28 | if(utils.getNickOnWorldChangePlayers().contains(player.getUniqueId())
29 | || ((mysqlNickManager != null) && mysqlNickManager.isNicked(player.getUniqueId()))) {
30 | if(utils.getNickedPlayers().containsKey(player.getUniqueId())) {
31 | Bukkit.getPluginManager().callEvent(new PlayerUnnickEvent(player));
32 | return CommandResult.SUCCESS;
33 | }
34 |
35 | if(eazyNick.getSetupYamlFile().getConfiguration().getStringList("DisabledNickWorlds")
36 | .contains(player.getWorld().getName())) {
37 | languageYamlFile.sendMessage(
38 | player,
39 | languageYamlFile.getConfigString(player, "Messages.DisabledWorld")
40 | .replace("%prefix%", utils.getPrefix())
41 | );
42 | return CommandResult.SUCCESS;
43 | }
44 |
45 | utils.performReNick(player);
46 | }
47 |
48 | return CommandResult.SUCCESS;
49 | }
50 |
51 | }
52 |
--------------------------------------------------------------------------------
/src/main/java/com/justixdev/eazynick/commands/impl/disguise/RealNameCommand.java:
--------------------------------------------------------------------------------
1 | package com.justixdev.eazynick.commands.impl.disguise;
2 |
3 | import com.justixdev.eazynick.EazyNick;
4 | import com.justixdev.eazynick.api.NickManager;
5 | import com.justixdev.eazynick.commands.Command;
6 | import com.justixdev.eazynick.commands.CommandResult;
7 | import com.justixdev.eazynick.commands.CustomCommand;
8 | import com.justixdev.eazynick.commands.parameters.CommandParameter;
9 | import com.justixdev.eazynick.commands.parameters.ParameterCombination;
10 | import com.justixdev.eazynick.commands.parameters.ParameterType;
11 | import com.justixdev.eazynick.utilities.Utils;
12 | import com.justixdev.eazynick.utilities.configuration.yaml.LanguageYamlFile;
13 | import org.bukkit.command.CommandSender;
14 | import org.bukkit.entity.Player;
15 |
16 | import java.util.Collections;
17 | import java.util.List;
18 |
19 | @CustomCommand(name = "realname", description = "Shows the real username of a nicked player")
20 | public class RealNameCommand extends Command {
21 |
22 | @Override
23 | protected void initAliases() {
24 | super.initAliases();
25 |
26 | this.aliases.add("rd");
27 | this.aliases.add("realdisguise");
28 | }
29 |
30 | @Override
31 | public List getCombinations() {
32 | return Collections.singletonList(
33 | new ParameterCombination(
34 | new CommandParameter("player", ParameterType.PLAYER)));
35 | }
36 |
37 | @Override
38 | public CommandResult execute(CommandSender sender, ParameterCombination args) {
39 | EazyNick eazyNick = EazyNick.getInstance();
40 | Utils utils = eazyNick.getUtils();
41 | LanguageYamlFile languageYamlFile = eazyNick.getLanguageYamlFile();
42 |
43 | Player player = (Player) sender;
44 |
45 | if(!player.hasPermission("eazynick.real"))
46 | return CommandResult.FAILURE_NO_PERMISSION;
47 |
48 | String prefix = utils.getPrefix();
49 | NickManager api = new NickManager(args.withName("player")
50 | .map(CommandParameter::asPlayer)
51 | .orElse(null)
52 | );
53 |
54 | if(!api.isNicked()) {
55 | languageYamlFile.sendMessage(
56 | player,
57 | languageYamlFile.getConfigString(player, "Messages.PlayerNotNicked")
58 | .replace("%prefix%", prefix)
59 | );
60 | return CommandResult.SUCCESS;
61 | }
62 |
63 | String realName = api.getRealName();
64 |
65 | languageYamlFile.sendMessage(
66 | player,
67 | languageYamlFile.getConfigString(player, "Messages.RealName")
68 | .replace("%realName%", realName)
69 | .replace("%realname%", realName)
70 | .replace("%prefix%", prefix)
71 | );
72 |
73 | return CommandResult.SUCCESS;
74 | }
75 |
76 | }
77 |
--------------------------------------------------------------------------------
/src/main/java/com/justixdev/eazynick/commands/impl/disguise/ResetNameCommand.java:
--------------------------------------------------------------------------------
1 | package com.justixdev.eazynick.commands.impl.disguise;
2 |
3 | import com.justixdev.eazynick.EazyNick;
4 | import com.justixdev.eazynick.api.NickManager;
5 | import com.justixdev.eazynick.commands.Command;
6 | import com.justixdev.eazynick.commands.CommandResult;
7 | import com.justixdev.eazynick.commands.CustomCommand;
8 | import com.justixdev.eazynick.commands.parameters.ParameterCombination;
9 | import com.justixdev.eazynick.sql.MySQLNickManager;
10 | import com.justixdev.eazynick.utilities.Utils;
11 | import com.justixdev.eazynick.utilities.configuration.yaml.LanguageYamlFile;
12 | import org.bukkit.command.CommandSender;
13 | import org.bukkit.entity.Player;
14 |
15 | @CustomCommand(name = "resetname", description = "Resets your name")
16 | public class ResetNameCommand extends Command {
17 |
18 | @Override
19 | public CommandResult execute(CommandSender sender, ParameterCombination args) {
20 | EazyNick eazyNick = EazyNick.getInstance();
21 | Utils utils = eazyNick.getUtils();
22 | LanguageYamlFile languageYamlFile = eazyNick.getLanguageYamlFile();
23 | MySQLNickManager mysqlNickManager = eazyNick.getMysqlNickManager();
24 |
25 | Player player = (Player) sender;
26 |
27 | if(!player.hasPermission("eazynick.nick.reset"))
28 | return CommandResult.FAILURE_NO_PERMISSION;
29 |
30 | NickManager api = new NickManager(player);
31 | api.setName(api.getRealName());
32 |
33 | if(mysqlNickManager != null)
34 | mysqlNickManager.removePlayer(player.getUniqueId());
35 |
36 | languageYamlFile.sendMessage(
37 | player,
38 | languageYamlFile.getConfigString(player, "Messages.ResetName")
39 | .replace("%prefix%", utils.getPrefix())
40 | );
41 |
42 | return CommandResult.SUCCESS;
43 | }
44 |
45 | }
46 |
--------------------------------------------------------------------------------
/src/main/java/com/justixdev/eazynick/commands/impl/disguise/ResetSkinCommand.java:
--------------------------------------------------------------------------------
1 | package com.justixdev.eazynick.commands.impl.disguise;
2 |
3 | import com.justixdev.eazynick.EazyNick;
4 | import com.justixdev.eazynick.api.NickManager;
5 | import com.justixdev.eazynick.commands.Command;
6 | import com.justixdev.eazynick.commands.CommandResult;
7 | import com.justixdev.eazynick.commands.CustomCommand;
8 | import com.justixdev.eazynick.commands.parameters.ParameterCombination;
9 | import com.justixdev.eazynick.sql.MySQLNickManager;
10 | import com.justixdev.eazynick.utilities.Utils;
11 | import com.justixdev.eazynick.utilities.configuration.yaml.LanguageYamlFile;
12 | import org.bukkit.command.CommandSender;
13 | import org.bukkit.entity.Player;
14 |
15 | @CustomCommand(name = "resetskin", description = "Resets your skin")
16 | public class ResetSkinCommand extends Command {
17 |
18 | @Override
19 | public CommandResult execute(CommandSender sender, ParameterCombination args) {
20 | EazyNick eazyNick = EazyNick.getInstance();
21 | Utils utils = eazyNick.getUtils();
22 | LanguageYamlFile languageYamlFile = eazyNick.getLanguageYamlFile();
23 | MySQLNickManager mysqlNickManager = eazyNick.getMysqlNickManager();
24 |
25 | Player player = (Player) sender;
26 |
27 | if(!player.hasPermission("eazynick.skin.reset"))
28 | return CommandResult.FAILURE_NO_PERMISSION;
29 |
30 | NickManager api = new NickManager(player);
31 | api.changeSkin(api.getRealName());
32 |
33 | if(mysqlNickManager != null)
34 | mysqlNickManager.removePlayer(player.getUniqueId());
35 |
36 | languageYamlFile.sendMessage(
37 | player,
38 | languageYamlFile.getConfigString(player, "Messages.ResetSkin")
39 | .replace("%prefix%", utils.getPrefix())
40 | );
41 |
42 | return CommandResult.SUCCESS;
43 | }
44 |
45 | }
46 |
--------------------------------------------------------------------------------
/src/main/java/com/justixdev/eazynick/commands/impl/disguise/ResetSkinOtherCommand.java:
--------------------------------------------------------------------------------
1 | package com.justixdev.eazynick.commands.impl.disguise;
2 |
3 | import com.justixdev.eazynick.EazyNick;
4 | import com.justixdev.eazynick.api.NickManager;
5 | import com.justixdev.eazynick.commands.Command;
6 | import com.justixdev.eazynick.commands.CommandResult;
7 | import com.justixdev.eazynick.commands.CustomCommand;
8 | import com.justixdev.eazynick.commands.parameters.CommandParameter;
9 | import com.justixdev.eazynick.commands.parameters.ParameterCombination;
10 | import com.justixdev.eazynick.commands.parameters.ParameterType;
11 | import com.justixdev.eazynick.utilities.Utils;
12 | import com.justixdev.eazynick.utilities.configuration.yaml.LanguageYamlFile;
13 | import org.bukkit.command.CommandSender;
14 | import org.bukkit.entity.Player;
15 |
16 | import java.util.Collections;
17 | import java.util.List;
18 |
19 | @CustomCommand(name = "resetskinother", description = "Resets the skin of another player")
20 | public class ResetSkinOtherCommand extends Command {
21 |
22 | @Override
23 | public List getCombinations() {
24 | return Collections.singletonList(
25 | new ParameterCombination(
26 | new CommandParameter("player", ParameterType.PLAYER)));
27 | }
28 |
29 | @Override
30 | public CommandResult execute(CommandSender sender, ParameterCombination args) {
31 | EazyNick eazyNick = EazyNick.getInstance();
32 | Utils utils = eazyNick.getUtils();
33 | LanguageYamlFile languageYamlFile = eazyNick.getLanguageYamlFile();
34 |
35 | Player player = (Player) sender;
36 |
37 | if(!player.hasPermission("eazynick.other.skin.reset"))
38 | return CommandResult.FAILURE_NO_PERMISSION;
39 |
40 | Player targetPlayer = args.withName("player")
41 | .map(CommandParameter::asPlayer)
42 | .orElse(null);
43 |
44 | assert targetPlayer != null;
45 |
46 | NickManager api = new NickManager(targetPlayer);
47 |
48 | api.changeSkin(api.getRealName());
49 |
50 | languageYamlFile.sendMessage(
51 | player,
52 | languageYamlFile.getConfigString(player, "Messages.Other.ResetSkin")
53 | .replace("%playerName%", targetPlayer.getName())
54 | .replace("%playername%", targetPlayer.getName())
55 | .replace("%prefix%", utils.getPrefix())
56 | );
57 |
58 | return CommandResult.SUCCESS;
59 | }
60 |
61 | }
62 |
--------------------------------------------------------------------------------
/src/main/java/com/justixdev/eazynick/commands/impl/disguise/ToggleBungeeNickCommand.java:
--------------------------------------------------------------------------------
1 | package com.justixdev.eazynick.commands.impl.disguise;
2 |
3 | import com.justixdev.eazynick.EazyNick;
4 | import com.justixdev.eazynick.commands.Command;
5 | import com.justixdev.eazynick.commands.CommandResult;
6 | import com.justixdev.eazynick.commands.CustomCommand;
7 | import com.justixdev.eazynick.commands.parameters.ParameterCombination;
8 | import org.bukkit.command.CommandSender;
9 | import org.bukkit.entity.Player;
10 |
11 | @CustomCommand(name = "togglebungeenick", description = "Toggles the automatic nickname on server switch")
12 | public class ToggleBungeeNickCommand extends Command {
13 |
14 | @Override
15 | protected void initAliases() {
16 | super.initAliases();
17 |
18 | this.aliases.add("togglenick");
19 | this.aliases.add("togglebungeedisguise");
20 | this.aliases.add("toggledisguise");
21 | }
22 |
23 | @Override
24 | public CommandResult execute(CommandSender sender, ParameterCombination args) {
25 | EazyNick eazyNick = EazyNick.getInstance();
26 |
27 | Player player = (Player) sender;
28 |
29 | if(!(player.hasPermission("eazynick.nick.random") && player.hasPermission("eazynick.item")))
30 | return CommandResult.FAILURE_NO_PERMISSION;
31 |
32 | if (eazyNick.getSetupYamlFile().getConfiguration().getBoolean("BungeeCord"))
33 | eazyNick.getUtils().toggleBungeeNick(player);
34 |
35 | return CommandResult.SUCCESS;
36 | }
37 |
38 | }
39 |
--------------------------------------------------------------------------------
/src/main/java/com/justixdev/eazynick/commands/impl/disguise/UnnickCommand.java:
--------------------------------------------------------------------------------
1 | package com.justixdev.eazynick.commands.impl.disguise;
2 |
3 | import com.justixdev.eazynick.EazyNick;
4 | import com.justixdev.eazynick.api.NickManager;
5 | import com.justixdev.eazynick.api.events.PlayerUnnickEvent;
6 | import com.justixdev.eazynick.commands.Command;
7 | import com.justixdev.eazynick.commands.CommandResult;
8 | import com.justixdev.eazynick.commands.CustomCommand;
9 | import com.justixdev.eazynick.commands.parameters.ParameterCombination;
10 | import com.justixdev.eazynick.sql.MySQLNickManager;
11 | import com.justixdev.eazynick.sql.MySQLPlayerDataManager;
12 | import com.justixdev.eazynick.utilities.Utils;
13 | import com.justixdev.eazynick.utilities.configuration.yaml.LanguageYamlFile;
14 | import com.justixdev.eazynick.utilities.configuration.yaml.SetupYamlFile;
15 | import org.bukkit.Bukkit;
16 | import org.bukkit.command.CommandSender;
17 | import org.bukkit.entity.Player;
18 |
19 | @CustomCommand(name = "unnick", description = "Resets your identity")
20 | public class UnnickCommand extends Command {
21 |
22 | @Override
23 | protected void initAliases() {
24 | super.initAliases();
25 |
26 | this.aliases.add("ud");
27 | this.aliases.add("undisguise");
28 | }
29 |
30 | @Override
31 | public CommandResult execute(CommandSender sender, ParameterCombination args) {
32 | EazyNick eazyNick = EazyNick.getInstance();
33 | Utils utils = eazyNick.getUtils();
34 | LanguageYamlFile languageYamlFile = eazyNick.getLanguageYamlFile();
35 | SetupYamlFile setupYamlFile = eazyNick.getSetupYamlFile();
36 | MySQLNickManager mysqlNickManager = eazyNick.getMysqlNickManager();
37 | MySQLPlayerDataManager mysqlPlayerDataManager = eazyNick.getMysqlPlayerDataManager();
38 |
39 | String prefix = utils.getPrefix();
40 | Player player = (Player) sender;
41 |
42 | if(!player.hasPermission("eazynick.nick.reset"))
43 | return CommandResult.FAILURE_NO_PERMISSION;
44 |
45 | if(new NickManager(player).isNicked()) {
46 | if(player.hasPermission("eazynick.nick.reset"))
47 | Bukkit.getPluginManager().callEvent(new PlayerUnnickEvent(player));
48 | } else if((mysqlNickManager != null)
49 | && mysqlNickManager.isNicked(player.getUniqueId())
50 | && setupYamlFile.getConfiguration().getBoolean("LobbyMode")
51 | && setupYamlFile.getConfiguration().getBoolean("RemoveMySQLNickOnUnnickWhenLobbyModeEnabled")) {
52 | if(player.hasPermission("eazynick.nick.reset")) {
53 | mysqlNickManager.removePlayer(player.getUniqueId());
54 | mysqlPlayerDataManager.removeData(player.getUniqueId());
55 |
56 | languageYamlFile.sendMessage(
57 | player,
58 | languageYamlFile.getConfigString(player, "Messages.Unnick")
59 | .replace("%prefix%", prefix)
60 | );
61 | }
62 | } else
63 | languageYamlFile.sendMessage(
64 | player,
65 | languageYamlFile.getConfigString(player, "Messages.NotNicked")
66 | .replace("%prefix%", prefix)
67 | );
68 |
69 | return CommandResult.SUCCESS;
70 | }
71 |
72 | }
73 |
--------------------------------------------------------------------------------
/src/main/java/com/justixdev/eazynick/commands/impl/gui/GuiNickCommand.java:
--------------------------------------------------------------------------------
1 | package com.justixdev.eazynick.commands.impl.gui;
2 |
3 | import com.justixdev.eazynick.EazyNick;
4 | import com.justixdev.eazynick.commands.Command;
5 | import com.justixdev.eazynick.commands.CommandResult;
6 | import com.justixdev.eazynick.commands.CustomCommand;
7 | import com.justixdev.eazynick.commands.parameters.CommandParameter;
8 | import com.justixdev.eazynick.commands.parameters.ParameterCombination;
9 | import com.justixdev.eazynick.commands.parameters.ParameterType;
10 | import org.bukkit.command.CommandSender;
11 | import org.bukkit.entity.Player;
12 |
13 | import java.util.Collections;
14 | import java.util.List;
15 |
16 | @CustomCommand(name = "guinick", description = "For internal purposes only")
17 | public class GuiNickCommand extends Command {
18 |
19 | @Override
20 | public List getCombinations() {
21 | return Collections.singletonList(
22 | new ParameterCombination(
23 | new CommandParameter("rank", ParameterType.TEXT),
24 | new CommandParameter("skin", ParameterType.TEXT),
25 | new CommandParameter("nickname", ParameterType.TEXT)));
26 | }
27 |
28 | @Override
29 | public CommandResult execute(CommandSender sender, ParameterCombination args) {
30 | Player player = (Player) sender;
31 |
32 | if(!(player.hasPermission("eazynick.nick.random")
33 | || player.hasPermission("eazynick.nick.custom")))
34 | return CommandResult.FAILURE_NO_PERMISSION;
35 |
36 | EazyNick.getInstance().getUtils().performRankedNick(
37 | player,
38 | args.withName("rank")
39 | .map(CommandParameter::asText)
40 | .orElse(null),
41 | args.withName("skin")
42 | .map(CommandParameter::asText)
43 | .orElse(null),
44 | args.withName("nickname")
45 | .map(CommandParameter::asText)
46 | .orElse(null)
47 | );
48 |
49 | return CommandResult.SUCCESS;
50 | }
51 |
52 | }
--------------------------------------------------------------------------------
/src/main/java/com/justixdev/eazynick/commands/impl/gui/NickGUICommand.java:
--------------------------------------------------------------------------------
1 | package com.justixdev.eazynick.commands.impl.gui;
2 |
3 | import com.justixdev.eazynick.EazyNick;
4 | import com.justixdev.eazynick.commands.Command;
5 | import com.justixdev.eazynick.commands.CommandResult;
6 | import com.justixdev.eazynick.commands.CustomCommand;
7 | import com.justixdev.eazynick.commands.parameters.ParameterCombination;
8 | import com.justixdev.eazynick.utilities.ItemBuilder;
9 | import com.justixdev.eazynick.utilities.configuration.yaml.GUIYamlFile;
10 | import org.bukkit.Bukkit;
11 | import org.bukkit.Material;
12 | import org.bukkit.command.CommandSender;
13 | import org.bukkit.entity.Player;
14 | import org.bukkit.inventory.Inventory;
15 |
16 | import static com.justixdev.eazynick.nms.ReflectionHelper.VERSION_13_OR_LATER;
17 |
18 | @CustomCommand(name = "nickgui", description = "Opens a GUI to change/reset your identity")
19 | public class NickGUICommand extends Command {
20 |
21 | @Override
22 | protected void initAliases() {
23 | super.initAliases();
24 |
25 | this.aliases.add("dgui");
26 | this.aliases.add("disguisegui");
27 | }
28 |
29 | @Override
30 | public CommandResult execute(CommandSender sender, ParameterCombination args) {
31 | EazyNick eazyNick = EazyNick.getInstance();
32 | GUIYamlFile guiYamlFile = eazyNick.getGuiYamlFile();
33 |
34 | Player player = (Player) sender;
35 |
36 | if(!player.hasPermission("eazynick.gui.classic"))
37 | return CommandResult.FAILURE_NO_PERMISSION;
38 |
39 | Inventory inventory = Bukkit.createInventory(
40 | null,
41 | 27,
42 | guiYamlFile.getConfigString(player, "NickGUI.InventoryTitle")
43 | );
44 |
45 | for (int i = 0; i < inventory.getSize(); i++)
46 | inventory.setItem(
47 | i,
48 | new ItemBuilder(
49 | Material.getMaterial(VERSION_13_OR_LATER
50 | ? "BLACK_STAINED_GLASS_PANE"
51 | : "STAINED_GLASS_PANE"),
52 | 1,
53 | VERSION_13_OR_LATER ? 0 : 15
54 | )
55 | .setDisplayName("§r")
56 | .build()
57 | );
58 |
59 | inventory.setItem(
60 | 11,
61 | new ItemBuilder(Material.NAME_TAG)
62 | .setDisplayName(guiYamlFile.getConfigString(player, "NickGUI.Nick.DisplayName"))
63 | .build()
64 | );
65 | inventory.setItem(
66 | 15,
67 | new ItemBuilder(Material.GLASS, 1, 14)
68 | .setDisplayName(guiYamlFile.getConfigString(player, "NickGUI.Unnick.DisplayName"))
69 | .build()
70 | );
71 |
72 | player.openInventory(inventory);
73 |
74 | return CommandResult.SUCCESS;
75 | }
76 |
77 | }
78 |
--------------------------------------------------------------------------------
/src/main/java/com/justixdev/eazynick/commands/impl/gui/NickListCommand.java:
--------------------------------------------------------------------------------
1 | package com.justixdev.eazynick.commands.impl.gui;
2 |
3 | import com.justixdev.eazynick.EazyNick;
4 | import com.justixdev.eazynick.api.NickManager;
5 | import com.justixdev.eazynick.api.events.PlayerUnnickEvent;
6 | import com.justixdev.eazynick.commands.Command;
7 | import com.justixdev.eazynick.commands.CommandResult;
8 | import com.justixdev.eazynick.commands.CustomCommand;
9 | import com.justixdev.eazynick.commands.parameters.ParameterCombination;
10 | import com.justixdev.eazynick.sql.MySQLNickManager;
11 | import com.justixdev.eazynick.sql.MySQLPlayerDataManager;
12 | import com.justixdev.eazynick.utilities.Utils;
13 | import com.justixdev.eazynick.utilities.configuration.yaml.LanguageYamlFile;
14 | import com.justixdev.eazynick.utilities.configuration.yaml.SetupYamlFile;
15 | import org.bukkit.Bukkit;
16 | import org.bukkit.command.CommandSender;
17 | import org.bukkit.entity.Player;
18 |
19 | @CustomCommand(name = "nicklist", description = "Opens a GUI with all random nicknames")
20 | public class NickListCommand extends Command {
21 |
22 | @Override
23 | protected void initAliases() {
24 | super.initAliases();
25 |
26 | this.aliases.add("dlist");
27 | this.aliases.add("disgusielist");
28 | }
29 |
30 | @Override
31 | public CommandResult execute(CommandSender sender, ParameterCombination args) {
32 | EazyNick eazyNick = EazyNick.getInstance();
33 | Utils utils = eazyNick.getUtils();
34 | SetupYamlFile setupYamlFile = eazyNick.getSetupYamlFile();
35 | LanguageYamlFile languageYamlFile = eazyNick.getLanguageYamlFile();
36 | MySQLNickManager mysqlNickManager = eazyNick.getMysqlNickManager();
37 | MySQLPlayerDataManager mysqlPlayerDataManager = eazyNick.getMysqlPlayerDataManager();
38 |
39 | String prefix = utils.getPrefix();
40 | Player player = (Player) sender;
41 |
42 | if(new NickManager(player).isNicked()) {
43 | if(player.hasPermission("eazynick.nick.reset"))
44 | Bukkit.getPluginManager().callEvent(new PlayerUnnickEvent(player));
45 | } else if((mysqlNickManager != null)
46 | && mysqlNickManager.isNicked(player.getUniqueId())
47 | && setupYamlFile.getConfiguration().getBoolean("LobbyMode")
48 | && setupYamlFile.getConfiguration().getBoolean("RemoveMySQLNickOnUnnickWhenLobbyModeEnabled")) {
49 | mysqlNickManager.removePlayer(player.getUniqueId());
50 | mysqlPlayerDataManager.removeData(player.getUniqueId());
51 |
52 | languageYamlFile.sendMessage(
53 | player,
54 | languageYamlFile.getConfigString(player, "Messages.Unnick")
55 | .replace("%prefix%", prefix)
56 | );
57 | } else if(player.hasPermission("eazynick.gui.list")) {
58 | if(!setupYamlFile.getConfiguration().getStringList("DisabledNickWorlds")
59 | .contains(player.getWorld().getName()))
60 | eazyNick.getGuiManager().openNickList(player, 0);
61 | else
62 | languageYamlFile.sendMessage(
63 | player,
64 | languageYamlFile.getConfigString(player, "Messages.DisabledWorld")
65 | .replace("%prefix%", prefix)
66 | );
67 | } else
68 | return CommandResult.FAILURE_NO_PERMISSION;
69 |
70 | return CommandResult.SUCCESS;
71 | }
72 |
73 | }
74 |
--------------------------------------------------------------------------------
/src/main/java/com/justixdev/eazynick/commands/impl/gui/RankedNickGUICommand.java:
--------------------------------------------------------------------------------
1 | package com.justixdev.eazynick.commands.impl.gui;
2 |
3 | import com.justixdev.eazynick.EazyNick;
4 | import com.justixdev.eazynick.api.NickManager;
5 | import com.justixdev.eazynick.api.events.PlayerUnnickEvent;
6 | import com.justixdev.eazynick.commands.Command;
7 | import com.justixdev.eazynick.commands.CommandResult;
8 | import com.justixdev.eazynick.commands.CustomCommand;
9 | import com.justixdev.eazynick.commands.parameters.ParameterCombination;
10 | import com.justixdev.eazynick.sql.MySQLNickManager;
11 | import com.justixdev.eazynick.sql.MySQLPlayerDataManager;
12 | import com.justixdev.eazynick.utilities.Utils;
13 | import com.justixdev.eazynick.utilities.configuration.yaml.LanguageYamlFile;
14 | import com.justixdev.eazynick.utilities.configuration.yaml.SetupYamlFile;
15 | import org.bukkit.Bukkit;
16 | import org.bukkit.command.CommandSender;
17 | import org.bukkit.entity.Player;
18 |
19 | @CustomCommand(name = "rankednickgui", description = "Alternative GUI for legacy server versions")
20 | public class RankedNickGUICommand extends Command {
21 |
22 | @Override
23 | public CommandResult execute(CommandSender sender, ParameterCombination args) {
24 | EazyNick eazyNick = EazyNick.getInstance();
25 | Utils utils = eazyNick.getUtils();
26 | SetupYamlFile setupYamlFile = eazyNick.getSetupYamlFile();
27 | LanguageYamlFile languageYamlFile = eazyNick.getLanguageYamlFile();
28 | MySQLNickManager mysqlNickManager = eazyNick.getMysqlNickManager();
29 | MySQLPlayerDataManager mysqlPlayerDataManager = eazyNick.getMysqlPlayerDataManager();
30 |
31 | String prefix = utils.getPrefix();
32 | Player player = (Player) sender;
33 |
34 | if(new NickManager(player).isNicked()) {
35 | if(player.hasPermission("eazynick.nick.reset"))
36 | Bukkit.getPluginManager().callEvent(new PlayerUnnickEvent(player));
37 | } else if((mysqlNickManager != null)
38 | && mysqlNickManager.isNicked(player.getUniqueId())
39 | && setupYamlFile.getConfiguration().getBoolean("LobbyMode")
40 | && setupYamlFile.getConfiguration().getBoolean("RemoveMySQLNickOnUnnickWhenLobbyModeEnabled")) {
41 | mysqlNickManager.removePlayer(player.getUniqueId());
42 | mysqlPlayerDataManager.removeData(player.getUniqueId());
43 |
44 | languageYamlFile.sendMessage(
45 | player,
46 | languageYamlFile.getConfigString(player, "Messages.Unnick")
47 | .replace("%prefix%", prefix)
48 | );
49 | } else if(player.hasPermission("eazynick.gui.list")) {
50 | if(!setupYamlFile.getConfiguration().getStringList("DisabledNickWorlds")
51 | .contains(player.getWorld().getName()))
52 | eazyNick.getGuiManager().openRankedNickGUI(player, "");
53 | else
54 | languageYamlFile.sendMessage(
55 | player,
56 | languageYamlFile.getConfigString(player, "Messages.DisabledWorld")
57 | .replace("%prefix%", prefix)
58 | );
59 | } else
60 | return CommandResult.FAILURE_NO_PERMISSION;
61 |
62 | return CommandResult.SUCCESS;
63 | }
64 |
65 | }
66 |
--------------------------------------------------------------------------------
/src/main/java/com/justixdev/eazynick/commands/impl/plugin/NickUpdateCheckCommand.java:
--------------------------------------------------------------------------------
1 | package com.justixdev.eazynick.commands.impl.plugin;
2 |
3 | import com.justixdev.eazynick.EazyNick;
4 | import com.justixdev.eazynick.commands.Command;
5 | import com.justixdev.eazynick.commands.CommandResult;
6 | import com.justixdev.eazynick.commands.CustomCommand;
7 | import com.justixdev.eazynick.commands.parameters.ParameterCombination;
8 | import org.bukkit.command.CommandSender;
9 | import org.bukkit.entity.Player;
10 |
11 | @CustomCommand(name = "eazynickupdatecheck", description = "Checks for updates for the plugin")
12 | public class NickUpdateCheckCommand extends Command {
13 |
14 | @Override
15 | public CommandResult execute(CommandSender sender, ParameterCombination args) {
16 | Player player = (Player) sender;
17 |
18 | if(!player.hasPermission("eazynick.updatecheck"))
19 | return CommandResult.FAILURE_NO_PERMISSION;
20 |
21 | EazyNick.getInstance().getUpdater().checkForUpdates(player);
22 |
23 | return CommandResult.SUCCESS;
24 | }
25 |
26 | }
--------------------------------------------------------------------------------
/src/main/java/com/justixdev/eazynick/commands/parameters/CommandParameter.java:
--------------------------------------------------------------------------------
1 | package com.justixdev.eazynick.commands.parameters;
2 |
3 | import com.justixdev.eazynick.EazyNick;
4 | import com.justixdev.eazynick.utilities.configuration.yaml.LanguageYamlFile;
5 | import lombok.Data;
6 | import lombok.RequiredArgsConstructor;
7 | import org.bukkit.Bukkit;
8 | import org.bukkit.command.CommandSender;
9 | import org.bukkit.entity.Player;
10 |
11 | @Data
12 | @RequiredArgsConstructor
13 | public class CommandParameter {
14 |
15 | private final String name;
16 | private final ParameterType type;
17 | private Object value;
18 |
19 | public boolean isValid(CommandSender sender, String rawValue) {
20 | switch (this.type) {
21 | case NUMBER:
22 | try {
23 | this.value = Integer.parseInt(rawValue);
24 |
25 | return true;
26 | } catch (NumberFormatException ignore) {
27 | }
28 | break;
29 | case DECIMAL:
30 | try {
31 | this.value = Double.parseDouble(rawValue);
32 |
33 | return true;
34 | } catch (NumberFormatException ignore) {
35 | }
36 | break;
37 | case PLAYER:
38 | Player targetPlayer = Bukkit.getPlayer(rawValue);
39 |
40 | if(targetPlayer != null) {
41 | this.value = targetPlayer;
42 |
43 | return true;
44 | } else if(!rawValue.isEmpty()) {
45 | EazyNick eazyNick = EazyNick.getInstance();
46 | LanguageYamlFile languageYamlFile = eazyNick.getLanguageYamlFile();
47 |
48 | languageYamlFile.sendMessage(
49 | sender,
50 | languageYamlFile.getConfigString((sender instanceof Player) ? (Player) sender : null, "Messages.PlayerNotFound")
51 | .replace("%prefix%", eazyNick.getUtils().getPrefix())
52 | );
53 | }
54 | break;
55 | case TEXT:
56 | if(!rawValue.isEmpty()) {
57 | this.value = rawValue;
58 |
59 | return true;
60 | }
61 | break;
62 | case BOOL:
63 | boolean isTrue = rawValue.equalsIgnoreCase("true");
64 |
65 | if(isTrue || rawValue.equalsIgnoreCase("false")) {
66 | this.value = isTrue;
67 |
68 | return true;
69 | }
70 | break;
71 | }
72 |
73 | return false;
74 | }
75 |
76 | public int asNumber() {
77 | return (int) this.value;
78 | }
79 |
80 | public double asDecimal() {
81 | return (double) this.value;
82 | }
83 |
84 | public Player asPlayer() {
85 | return (Player) this.value;
86 | }
87 |
88 | public String asText() {
89 | return (String) this.value;
90 | }
91 |
92 | public boolean asBool() {
93 | return (boolean) this.value;
94 | }
95 |
96 | @Override
97 | public String toString() {
98 | return "CommandParameter{" +
99 | "name='" + name + '\'' +
100 | ", value=" + value +
101 | '}';
102 | }
103 |
104 | }
105 |
--------------------------------------------------------------------------------
/src/main/java/com/justixdev/eazynick/commands/parameters/ParameterCombination.java:
--------------------------------------------------------------------------------
1 | package com.justixdev.eazynick.commands.parameters;
2 |
3 | import lombok.Getter;
4 | import org.bukkit.command.CommandSender;
5 |
6 | import java.util.Arrays;
7 | import java.util.Optional;
8 |
9 | public class ParameterCombination {
10 |
11 | public static final ParameterCombination EMPTY = new ParameterCombination();
12 |
13 | @Getter
14 | private final CommandParameter[] parameters;
15 |
16 | public ParameterCombination(CommandParameter... parameters) {
17 | this.parameters = parameters;
18 | }
19 |
20 | public boolean matches(CommandSender sender, String[] args) {
21 | if(this.parameters.length != args.length)
22 | return false;
23 |
24 | for (int i = 0; i < args.length; i++) {
25 | if(!this.parameters[i].isValid(sender, args[i].trim()))
26 | return false;
27 | }
28 |
29 | return true;
30 | }
31 |
32 | public Optional withName(String name) {
33 | return Arrays.stream(this.parameters)
34 | .filter(parameter -> parameter.getName().equals(name))
35 | .findFirst();
36 | }
37 |
38 | }
39 |
--------------------------------------------------------------------------------
/src/main/java/com/justixdev/eazynick/commands/parameters/ParameterType.java:
--------------------------------------------------------------------------------
1 | package com.justixdev.eazynick.commands.parameters;
2 |
3 | public enum ParameterType {
4 |
5 | NUMBER,
6 | DECIMAL,
7 | PLAYER,
8 | TEXT,
9 | BOOL
10 |
11 | }
12 |
--------------------------------------------------------------------------------
/src/main/java/com/justixdev/eazynick/hooks/LuckPermsHook.java:
--------------------------------------------------------------------------------
1 | package com.justixdev.eazynick.hooks;
2 |
3 | import com.justixdev.eazynick.EazyNick;
4 | import com.justixdev.eazynick.utilities.Utils;
5 | import com.justixdev.eazynick.utilities.configuration.yaml.SetupYamlFile;
6 | import net.luckperms.api.LuckPerms;
7 | import net.luckperms.api.LuckPermsProvider;
8 | import net.luckperms.api.model.user.User;
9 | import net.luckperms.api.node.Node;
10 | import net.luckperms.api.node.NodeType;
11 | import net.luckperms.api.node.types.InheritanceNode;
12 | import net.luckperms.api.node.types.PrefixNode;
13 | import net.luckperms.api.node.types.SuffixNode;
14 | import org.bukkit.Bukkit;
15 | import org.bukkit.entity.Player;
16 |
17 | import java.util.Collection;
18 | import java.util.logging.Level;
19 |
20 | public class LuckPermsHook {
21 |
22 | private final Player player;
23 | private final LuckPerms api;
24 | private final User user;
25 |
26 | private final Utils utils;
27 | private final SetupYamlFile setupYamlFile;
28 |
29 | public LuckPermsHook(Player player) {
30 | this.player = player;
31 |
32 | this.api = LuckPermsProvider.get();
33 | this.user = this.api.getUserManager().getUser(this.player.getUniqueId());
34 |
35 | if(this.user == null)
36 | Bukkit.getLogger().log(Level.SEVERE, "Could not load LuckPerms user '" + player.getName() + "'");
37 |
38 | EazyNick eazyNick = EazyNick.getInstance();
39 | this.utils = eazyNick.getUtils();
40 | this.setupYamlFile = eazyNick.getSetupYamlFile();
41 | }
42 |
43 | public void updateNodes(String prefix, String suffix, String groupName) {
44 | if(this.user == null)
45 | return;
46 |
47 | if (this.setupYamlFile.getConfiguration().getBoolean("ChangeLuckPermsPrefixAndSuffix")) {
48 | // Create new prefix and suffix nodes
49 | PrefixNode prefixNode = PrefixNode.builder().prefix(prefix).priority(100).build();
50 | SuffixNode suffixNode = SuffixNode.builder().suffix(suffix).priority(100).build();
51 |
52 | this.user.transientData().add(prefixNode);
53 | this.user.transientData().add(suffixNode);
54 |
55 | this.utils.getLuckPermsPrefixes().put(this.player.getUniqueId(), prefixNode);
56 | this.utils.getLuckPermsSuffixes().put(this.player.getUniqueId(), suffixNode);
57 | }
58 |
59 | if (this.setupYamlFile.getConfiguration().getBoolean("SwitchLuckPermsGroupByNicking")
60 | && !groupName.equalsIgnoreCase("NONE") && !user.getPrimaryGroup().isEmpty()) {
61 | // Update group nodes
62 | this.utils.getOldLuckPermsGroups().put(this.player.getUniqueId(), user.getNodes(NodeType.INHERITANCE));
63 |
64 | this.removeAllGroups(this.user);
65 |
66 | this.user.data().add(InheritanceNode.builder(groupName).build());
67 | }
68 |
69 | this.api.getUserManager().saveUser(this.user);
70 | }
71 |
72 | public void resetNodes() {
73 | if(this.user == null)
74 | return;
75 |
76 | if (this.setupYamlFile.getConfiguration().getBoolean("ChangeLuckPermsPrefixAndSuffix")
77 | && this.utils.getLuckPermsPrefixes().containsKey(this.player.getUniqueId())
78 | && this.utils.getLuckPermsSuffixes().containsKey(this.player.getUniqueId())) {
79 | // Remove prefix and suffix nodes
80 | this.user.transientData().remove((Node) this.utils.getLuckPermsPrefixes().get(this.player.getUniqueId()));
81 | this.user.transientData().remove((Node) this.utils.getLuckPermsSuffixes().get(this.player.getUniqueId()));
82 |
83 | this.utils.getLuckPermsPrefixes().remove(this.player.getUniqueId());
84 | this.utils.getLuckPermsSuffixes().remove(this.player.getUniqueId());
85 | }
86 |
87 | if (this.setupYamlFile.getConfiguration().getBoolean("SwitchLuckPermsGroupByNicking")
88 | && this.utils.getOldLuckPermsGroups().containsKey(this.player.getUniqueId())) {
89 | // Reset group nodes
90 | this.removeAllGroups(user);
91 |
92 | //noinspection unchecked
93 | ((Collection) this.utils.getOldLuckPermsGroups().get(this.player.getUniqueId()))
94 | .forEach(node -> user.data().add(node));
95 |
96 | this.utils.getOldLuckPermsGroups().remove(this.player.getUniqueId());
97 | }
98 |
99 | this.api.getUserManager().saveUser(user);
100 | }
101 |
102 | private void removeAllGroups(User user) {
103 | user.data().toMap().values().forEach(node ->
104 | node.stream()
105 | .filter(node2 -> (node2 instanceof InheritanceNode))
106 | .forEach(node2 -> user.data().remove(node2)));
107 | }
108 |
109 | }
110 |
--------------------------------------------------------------------------------
/src/main/java/com/justixdev/eazynick/hooks/TABHook.java:
--------------------------------------------------------------------------------
1 | package com.justixdev.eazynick.hooks;
2 |
3 | import me.neznamy.tab.api.TabAPI;
4 | import me.neznamy.tab.api.TabPlayer;
5 | import me.neznamy.tab.api.nametag.NameTagManager;
6 | import me.neznamy.tab.api.tablist.TabListFormatManager;
7 | import org.bukkit.Bukkit;
8 | import org.bukkit.entity.Player;
9 |
10 | import java.util.logging.Level;
11 |
12 | public class TABHook {
13 |
14 | private static TabAPI api;
15 |
16 | private final TabPlayer tabPlayer;
17 | private final TabListFormatManager tablistFormatManager;
18 | private final NameTagManager nametagManager;
19 |
20 | public TABHook(Player player) {
21 | if(api == null)
22 | api = TabAPI.getInstance();
23 |
24 | this.tabPlayer = api.getPlayer(player.getUniqueId());
25 | this.nametagManager = api.getNameTagManager();
26 | this.tablistFormatManager = api.getTabListFormatManager();
27 |
28 | if((this.tabPlayer == null) || (this.tablistFormatManager == null) || (this.nametagManager == null))
29 | Bukkit.getLogger().log(Level.SEVERE, "Could not load TabPlayer for '" + player.getName() + "'");
30 | }
31 |
32 | public void update(String tabPrefix, String tabSuffix, String tagPrefix, String tagSuffix, String groupName) {
33 | if((this.tabPlayer == null) || (this.tablistFormatManager == null) || (this.nametagManager == null))
34 | return;
35 |
36 | // Set temporarily nametag values
37 | this.nametagManager.setPrefix(this.tabPlayer, tagPrefix);
38 | this.nametagManager.setSuffix(this.tabPlayer, tagSuffix);
39 |
40 | // Set temporarily list values
41 | this.tablistFormatManager.setPrefix(this.tabPlayer, tabPrefix);
42 | this.tablistFormatManager.setSuffix(this.tabPlayer, tabSuffix);
43 |
44 | // Change group name
45 | this.tabPlayer.setTemporaryGroup(groupName);
46 | }
47 |
48 | public void reset() {
49 | if((this.tabPlayer == null) || (this.tablistFormatManager == null) || (this.nametagManager == null))
50 | return;
51 |
52 | // Unset temporarily nametag values
53 | this.nametagManager.setPrefix(this.tabPlayer, this.nametagManager.getOriginalPrefix(this.tabPlayer));
54 | this.nametagManager.setSuffix(this.tabPlayer, this.nametagManager.getOriginalSuffix(this.tabPlayer));
55 |
56 | // Unset temporarily list values
57 | this.tablistFormatManager.setPrefix(this.tabPlayer, this.tablistFormatManager.getOriginalPrefix(this.tabPlayer));
58 | this.tablistFormatManager.setSuffix(this.tabPlayer, this.tablistFormatManager.getOriginalSuffix(this.tabPlayer));
59 |
60 | // Reset group name
61 | this.tabPlayer.setTemporaryGroup(null);
62 | }
63 |
64 | }
65 |
--------------------------------------------------------------------------------
/src/main/java/com/justixdev/eazynick/listeners/AsyncPlayerChatListener.java:
--------------------------------------------------------------------------------
1 | package com.justixdev.eazynick.listeners;
2 |
3 | import com.justixdev.eazynick.EazyNick;
4 | import com.justixdev.eazynick.api.NickManager;
5 | import com.justixdev.eazynick.utilities.Utils;
6 | import com.justixdev.eazynick.utilities.configuration.yaml.SetupYamlFile;
7 | import me.clip.placeholderapi.PlaceholderAPI;
8 | import org.bukkit.Bukkit;
9 | import org.bukkit.entity.Player;
10 | import org.bukkit.event.EventHandler;
11 | import org.bukkit.event.EventPriority;
12 | import org.bukkit.event.Listener;
13 | import org.bukkit.event.player.AsyncPlayerChatEvent;
14 |
15 | import static com.justixdev.eazynick.nms.ReflectionHelper.NMS_VERSION;
16 |
17 | public class AsyncPlayerChatListener implements Listener {
18 |
19 | @EventHandler(priority = EventPriority.HIGHEST)
20 | public void onFirstAsyncPlayerChat(AsyncPlayerChatEvent event) {
21 | EazyNick eazyNick = EazyNick.getInstance();
22 | Utils utils = eazyNick.getUtils();
23 |
24 | Player player = event.getPlayer();
25 |
26 | if(utils.getPlayersTypingNameInChat().containsKey(player.getUniqueId())) {
27 | String[] args = (utils.getPlayersTypingNameInChat().get(player.getUniqueId())
28 | + " "
29 | + event.getMessage().trim()).split("\\s+");
30 |
31 | utils.getPlayersTypingNameInChat().remove(player.getUniqueId());
32 | utils.performRankedNick(player, args[0], args[1], args[2]);
33 |
34 | event.setCancelled(true);
35 | }
36 | }
37 |
38 | @EventHandler(priority = EventPriority.LOWEST)
39 | public void onLastAsyncPlayerChat(AsyncPlayerChatEvent event) {
40 | EazyNick eazyNick = EazyNick.getInstance();
41 | Utils utils = eazyNick.getUtils();
42 | SetupYamlFile setupYamlFile = eazyNick.getSetupYamlFile();
43 |
44 | Player player = event.getPlayer();
45 | boolean replaceChat =
46 | setupYamlFile.getConfiguration().getBoolean("ReplaceNickedChatFormat")
47 | && utils.getWorldsWithDisabledPrefixAndSuffix()
48 | .stream()
49 | .anyMatch(world -> world.equalsIgnoreCase(player.getWorld().getName()));
50 |
51 | utils.setLastChatMessage(event.getMessage());
52 |
53 | NickManager api = new NickManager(player);
54 |
55 | if(event.getFormat().equals("<%1$s> %2$s") && !replaceChat && (NMS_VERSION.startsWith("v1_19") || NMS_VERSION.startsWith("v1_20"))) {
56 | event.setCancelled(true);
57 | Bukkit.getOnlinePlayers().forEach(currentPlayer -> currentPlayer.sendMessage("<" + api.getNickName() + "> " + event.getMessage()));
58 | return;
59 | }
60 |
61 | if (!replaceChat || event.isCancelled())
62 | return;
63 |
64 | if (api.isNicked()) {
65 | event.setCancelled(true);
66 |
67 | String format = setupYamlFile.getConfigString(player, "Settings.ChatFormat")
68 | .replace("%displayName%", player.getDisplayName())
69 | .replace("%nickName%", api.getNickName())
70 | .replace("%playerName%", api.getNickName())
71 | .replace("%displayname%", player.getDisplayName())
72 | .replace("%nickname%", api.getNickName())
73 | .replace("%playername%", api.getNickName())
74 | .replace("%prefix%", api.getChatPrefix())
75 | .replace("%suffix%", api.getChatSuffix());
76 |
77 | if(utils.isPluginInstalled("PlaceholderAPI"))
78 | format = PlaceholderAPI.setPlaceholders(player, format);
79 |
80 | String finalFormat = format
81 | .replace("%message%", event.getMessage())
82 | .replaceAll("%", "%%");
83 |
84 | event.setFormat(finalFormat);
85 |
86 | Bukkit.getConsoleSender().sendMessage(finalFormat);
87 |
88 | Bukkit.getOnlinePlayers().forEach(currentPlayer -> {
89 | if (currentPlayer.getName().equalsIgnoreCase(player.getName())) {
90 | if (setupYamlFile.getConfiguration().getBoolean("SeeNickSelf"))
91 | currentPlayer.sendMessage(finalFormat);
92 | else
93 | currentPlayer.sendMessage(finalFormat.replace(player.getDisplayName(), api.getOldDisplayName()));
94 | } else if (currentPlayer.hasPermission("eazynick.bypass")
95 | && setupYamlFile.getConfiguration().getBoolean("EnableBypassPermission"))
96 | currentPlayer.sendMessage(finalFormat.replace(player.getDisplayName(), api.getOldDisplayName()));
97 | else
98 | currentPlayer.sendMessage(finalFormat);
99 | });
100 | }
101 | }
102 |
103 | }
104 |
--------------------------------------------------------------------------------
/src/main/java/com/justixdev/eazynick/listeners/InventoryCloseListener.java:
--------------------------------------------------------------------------------
1 | package com.justixdev.eazynick.listeners;
2 |
3 | import com.justixdev.eazynick.EazyNick;
4 | import org.bukkit.event.EventHandler;
5 | import org.bukkit.event.EventPriority;
6 | import org.bukkit.event.Listener;
7 | import org.bukkit.event.inventory.InventoryCloseEvent;
8 |
9 | public class InventoryCloseListener implements Listener {
10 |
11 | @EventHandler(priority = EventPriority.LOWEST)
12 | public void onInventoryClose(InventoryCloseEvent event) {
13 | EazyNick
14 | .getInstance()
15 | .getUtils()
16 | .getNickNameListPages()
17 | .remove(event.getPlayer().getUniqueId());
18 | }
19 |
20 | }
21 |
--------------------------------------------------------------------------------
/src/main/java/com/justixdev/eazynick/listeners/PlayerChangedWorldListener.java:
--------------------------------------------------------------------------------
1 | package com.justixdev.eazynick.listeners;
2 |
3 | import com.justixdev.eazynick.EazyNick;
4 | import com.justixdev.eazynick.api.NickManager;
5 | import com.justixdev.eazynick.utilities.Utils;
6 | import com.justixdev.eazynick.utilities.configuration.yaml.SetupYamlFile;
7 | import org.bukkit.entity.Player;
8 | import org.bukkit.event.EventHandler;
9 | import org.bukkit.event.Listener;
10 | import org.bukkit.event.player.PlayerChangedWorldEvent;
11 |
12 | public class PlayerChangedWorldListener implements Listener {
13 |
14 | @EventHandler
15 | public void onPlayerChangedWorld(PlayerChangedWorldEvent event) {
16 | EazyNick eazyNick = EazyNick.getInstance();
17 | Utils utils = eazyNick.getUtils();
18 | SetupYamlFile setupYamlFile = eazyNick.getSetupYamlFile();
19 |
20 | Player player = event.getPlayer();
21 | NickManager api = new NickManager(player);
22 |
23 | if(utils.getWorldBlackList().stream().noneMatch(world -> world.equalsIgnoreCase(player.getWorld().getName()))) {
24 | if (setupYamlFile.getConfiguration().getBoolean("NickOnWorldChange")
25 | && utils.getNickOnWorldChangePlayers().contains(player.getUniqueId())
26 | && !api.isNicked())
27 | utils.performReNick(player);
28 | else if(!setupYamlFile.getConfiguration().getBoolean("KeepNickOnWorldChange"))
29 | api.unnickPlayerWithoutRemovingMySQL(false, true);
30 | } else if(api.isNicked())
31 | api.unnickPlayerWithoutRemovingMySQL(false, true);
32 | }
33 |
34 | }
35 |
--------------------------------------------------------------------------------
/src/main/java/com/justixdev/eazynick/listeners/PlayerCommandPreprocessListener.java:
--------------------------------------------------------------------------------
1 | package com.justixdev.eazynick.listeners;
2 |
3 | import com.justixdev.eazynick.EazyNick;
4 | import com.justixdev.eazynick.api.events.PlayerUnnickEvent;
5 | import com.justixdev.eazynick.utilities.Utils;
6 | import com.justixdev.eazynick.utilities.configuration.yaml.SetupYamlFile;
7 | import org.bukkit.Bukkit;
8 | import org.bukkit.command.PluginCommand;
9 | import org.bukkit.entity.Player;
10 | import org.bukkit.event.EventHandler;
11 | import org.bukkit.event.Listener;
12 | import org.bukkit.event.player.PlayerCommandPreprocessEvent;
13 |
14 | import java.util.Objects;
15 |
16 | import static com.justixdev.eazynick.nms.ReflectionHelper.NMS_VERSION;
17 |
18 | public class PlayerCommandPreprocessListener implements Listener {
19 |
20 | @EventHandler
21 | public void onPlayerCommandPreprocess(PlayerCommandPreprocessEvent event) {
22 | EazyNick eazyNick = EazyNick.getInstance();
23 | Utils utils = eazyNick.getUtils();
24 | SetupYamlFile setupYamlFile = eazyNick.getSetupYamlFile();
25 |
26 | Player player = event.getPlayer();
27 | String message = event.getMessage().trim();
28 |
29 | // Name replacements
30 | String[] args = message.split("\\s+");
31 | StringBuilder msg = new StringBuilder(message);
32 | boolean allowRealName = setupYamlFile.getConfiguration().getBoolean("AllowRealNamesInCommands");
33 |
34 | if(utils.getReplaceNameInCommandBlackList()
35 | .stream()
36 | .noneMatch(command -> args[0].equalsIgnoreCase("/" + command))
37 | && (EazyNick.getInstance().getCommand(args[0].substring(1)) == null)) {
38 | utils.getNickedPlayers().values().forEach(nickedPlayerData -> {
39 | for (int i = 0; i < args.length; i++) {
40 | if(args[i].equalsIgnoreCase(nickedPlayerData.getNickName()))
41 | args[i] = nickedPlayerData.getRealName();
42 | else if(args[i].equalsIgnoreCase(nickedPlayerData.getRealName()) && !(allowRealName))
43 | args[i] = nickedPlayerData.getRealName() + "§r";
44 | }
45 | });
46 |
47 | msg = new StringBuilder();
48 |
49 | for (String arg : args)
50 | msg.append(arg).append(" ");
51 |
52 | event.setMessage(msg.toString().trim());
53 | }
54 |
55 | if(message.toLowerCase().startsWith("/me ")
56 | && (message.length() > 4)
57 | && !event.isCancelled()
58 | && (NMS_VERSION.startsWith("v1_19") || NMS_VERSION.startsWith("v1_20"))
59 | ) {
60 | event.setCancelled(true);
61 | Bukkit.getOnlinePlayers().forEach(currentPlayer ->
62 | currentPlayer.sendMessage("* " + player.getName() + " " + message.substring(4))
63 | );
64 | return;
65 | }
66 |
67 | // Command system
68 | if(eazyNick.getCommandManager().execute(player, event.getMessage().substring(1))) {
69 | event.setCancelled(true);
70 | return;
71 | }
72 |
73 | String rawCommand = msg.toString().toLowerCase().replace("bukkit:", "");
74 |
75 | if(rawCommand.startsWith("/rl") || rawCommand.startsWith("/reload")) {
76 | event.setCancelled(true);
77 |
78 | utils.getNickedPlayers()
79 | .keySet()
80 | .stream()
81 | .map(Bukkit::getPlayer)
82 | .filter(Objects::nonNull)
83 | .forEach(currentPlayer -> Bukkit.getPluginManager().callEvent(new PlayerUnnickEvent(currentPlayer)));
84 |
85 | Bukkit.getScheduler().runTaskLater(eazyNick, Bukkit::reload, 20);
86 | return;
87 | }
88 |
89 | if (
90 | !(rawCommand.startsWith("/help nick")
91 | || rawCommand.startsWith("/help eazynick")
92 | || rawCommand.startsWith("/? nick")
93 | || rawCommand.startsWith("/? eazynick"))
94 | || !player.hasPermission("bukkit.command.help"))
95 | return;
96 |
97 | event.setCancelled(true);
98 |
99 | player.sendMessage("§e--------- §fHelp: " + eazyNick.getDescription().getName() + " §e----------------------");
100 | player.sendMessage("§7Below is a list of all " + eazyNick.getDescription().getName() + " commands:");
101 |
102 | PluginCommand command = eazyNick.getCommand("eazynick");
103 |
104 | if(command != null)
105 | player.sendMessage("§6/eazynick: §f" + command.getDescription());
106 | }
107 |
108 | }
109 |
--------------------------------------------------------------------------------
/src/main/java/com/justixdev/eazynick/listeners/PlayerDeathListener.java:
--------------------------------------------------------------------------------
1 | package com.justixdev.eazynick.listeners;
2 |
3 | import com.justixdev.eazynick.EazyNick;
4 | import com.justixdev.eazynick.api.NickManager;
5 | import com.justixdev.eazynick.utilities.configuration.yaml.SetupYamlFile;
6 | import org.bukkit.Bukkit;
7 | import org.bukkit.entity.Player;
8 | import org.bukkit.event.EventHandler;
9 | import org.bukkit.event.EventPriority;
10 | import org.bukkit.event.Listener;
11 | import org.bukkit.event.entity.PlayerDeathEvent;
12 |
13 | public class PlayerDeathListener implements Listener {
14 |
15 | @EventHandler(priority = EventPriority.LOWEST)
16 | public void onPlayerDeath(PlayerDeathEvent event) {
17 | EazyNick eazyNick = EazyNick.getInstance();
18 | SetupYamlFile setupYamlFile = eazyNick.getSetupYamlFile();
19 |
20 | Player player = event.getEntity();
21 | String deathMessage = (event.getDeathMessage() == null) || event.getDeathMessage().isEmpty()
22 | ? null
23 | : event.getDeathMessage();
24 | NickManager api = new NickManager(player);
25 |
26 | if(api.isNicked()
27 | && (deathMessage != null)
28 | && !setupYamlFile.getConfiguration().getBoolean("SeeNickSelf")) {
29 | event.setDeathMessage(null);
30 |
31 | Bukkit.getOnlinePlayers().forEach(currentPlayer -> currentPlayer.sendMessage(
32 | (currentPlayer != player)
33 | ? deathMessage
34 | : deathMessage.replace(api.getNickFormat(), api.getOldDisplayName())));
35 | }
36 | }
37 |
38 | }
39 |
--------------------------------------------------------------------------------
/src/main/java/com/justixdev/eazynick/listeners/PlayerDropItemListener.java:
--------------------------------------------------------------------------------
1 | package com.justixdev.eazynick.listeners;
2 |
3 | import com.justixdev.eazynick.EazyNick;
4 | import com.justixdev.eazynick.utilities.configuration.yaml.LanguageYamlFile;
5 | import org.bukkit.Material;
6 | import org.bukkit.entity.Player;
7 | import org.bukkit.event.EventHandler;
8 | import org.bukkit.event.Listener;
9 | import org.bukkit.event.player.PlayerDropItemEvent;
10 |
11 | public class PlayerDropItemListener implements Listener {
12 |
13 | @EventHandler
14 | public void onPlayerDropItem(PlayerDropItemEvent event) {
15 | EazyNick eazyNick = EazyNick.getInstance();
16 | LanguageYamlFile languageYamlFile = eazyNick.getLanguageYamlFile();
17 |
18 | Player player = event.getPlayer();
19 |
20 | if ((event.getItemDrop().getItemStack().getType() != Material.AIR)
21 | && (event.getItemDrop().getItemStack().getItemMeta() != null)) {
22 | String displayName = event.getItemDrop().getItemStack().getItemMeta().getDisplayName();
23 |
24 | if (displayName.equalsIgnoreCase(languageYamlFile.getConfigString(player, "NickItem.DisplayName.Enabled"))
25 | || displayName.equalsIgnoreCase(languageYamlFile.getConfigString(player, "NickItem.DisplayName.Disabled"))
26 | || displayName.equalsIgnoreCase(languageYamlFile.getConfigString(player, "NickItem.WorldChange.DisplayName.Enabled"))
27 | || displayName.equalsIgnoreCase(languageYamlFile.getConfigString(player, "NickItem.WorldChange.DisplayName.Disabled"))
28 | || displayName.equalsIgnoreCase(languageYamlFile.getConfigString(player, "NickItem.BungeeCord.DisplayName.Enabled"))
29 | || displayName.equalsIgnoreCase(languageYamlFile.getConfigString(player, "NickItem.BungeeCord.DisplayName.Disabled"))) {
30 | if (!eazyNick.getSetupYamlFile().getConfiguration().getBoolean("NickItem.InventorySettings.PlayersCanDropItem"))
31 | event.setCancelled(true);
32 | }
33 | }
34 | }
35 |
36 | }
37 |
--------------------------------------------------------------------------------
/src/main/java/com/justixdev/eazynick/listeners/PlayerLoginListener.java:
--------------------------------------------------------------------------------
1 | package com.justixdev.eazynick.listeners;
2 |
3 | import com.justixdev.eazynick.EazyNick;
4 | import com.justixdev.eazynick.utilities.Utils;
5 | import com.justixdev.eazynick.utilities.configuration.yaml.SetupYamlFile;
6 | import org.bukkit.entity.Player;
7 | import org.bukkit.event.EventHandler;
8 | import org.bukkit.event.EventPriority;
9 | import org.bukkit.event.Listener;
10 | import org.bukkit.event.player.PlayerLoginEvent;
11 |
12 | import java.util.UUID;
13 |
14 | public class PlayerLoginListener implements Listener {
15 |
16 | @EventHandler(priority = EventPriority.LOWEST)
17 | public void onLastPlayerLogin(PlayerLoginEvent event) {
18 | EazyNick eazyNick = EazyNick.getInstance();
19 | Utils utils = eazyNick.getUtils();
20 | SetupYamlFile setupYamlFile = eazyNick.getSetupYamlFile();
21 |
22 | Player player = event.getPlayer();
23 | UUID uniqueId = player.getUniqueId();
24 |
25 | if (
26 | (setupYamlFile.getConfiguration().getBoolean("BungeeCord")
27 | && (!setupYamlFile.getConfiguration().getBoolean("LobbyMode")
28 | || (player.hasPermission("eazynick.bypasslobbymode")
29 | && setupYamlFile.getConfiguration().getBoolean("EnableBypassLobbyModePermission")))
30 | && eazyNick.getMysqlNickManager().isNicked(uniqueId))
31 | || utils.getLastNickData().containsKey(uniqueId)
32 | || setupYamlFile.getConfiguration().getBoolean("JoinNick")
33 | || (setupYamlFile.getConfiguration().getBoolean("SaveLocalNickData")
34 | && eazyNick.getSavedNickDataYamlFile().getConfiguration()
35 | .contains(player.getUniqueId().toString().replace("-", ""))))
36 | utils.getSoonNickedPlayers().add(uniqueId);
37 | }
38 |
39 | }
40 |
--------------------------------------------------------------------------------
/src/main/java/com/justixdev/eazynick/listeners/PlayerRespawnListener.java:
--------------------------------------------------------------------------------
1 | package com.justixdev.eazynick.listeners;
2 |
3 | import com.justixdev.eazynick.EazyNick;
4 | import com.justixdev.eazynick.api.NickManager;
5 | import org.bukkit.entity.Player;
6 | import org.bukkit.event.EventHandler;
7 | import org.bukkit.event.EventPriority;
8 | import org.bukkit.event.Listener;
9 | import org.bukkit.event.player.PlayerRespawnEvent;
10 |
11 | public class PlayerRespawnListener implements Listener {
12 |
13 | @EventHandler(priority = EventPriority.LOWEST)
14 | public void onPlayerRespawn(PlayerRespawnEvent event) {
15 | Player player = event.getPlayer();
16 | NickManager api = new NickManager(player);
17 |
18 | if(api.isNicked()
19 | && !EazyNick.getInstance().getSetupYamlFile().getConfiguration().getBoolean("KeepNickOnDeath"))
20 | api.unnickPlayerWithoutRemovingMySQL(false, true);
21 | }
22 |
23 | }
24 |
--------------------------------------------------------------------------------
/src/main/java/com/justixdev/eazynick/listeners/ServerCommandListener.java:
--------------------------------------------------------------------------------
1 | package com.justixdev.eazynick.listeners;
2 |
3 | import com.justixdev.eazynick.EazyNick;
4 | import org.bukkit.event.EventHandler;
5 | import org.bukkit.event.Listener;
6 | import org.bukkit.event.server.ServerCommandEvent;
7 |
8 | public class ServerCommandListener implements Listener {
9 |
10 | @EventHandler
11 | public void onServerCommand(ServerCommandEvent event) {
12 | // Command system
13 | if(EazyNick.getInstance().getCommandManager().execute(event.getSender(), event.getCommand()))
14 | event.setCancelled(true);
15 | }
16 |
17 | }
18 |
--------------------------------------------------------------------------------
/src/main/java/com/justixdev/eazynick/listeners/ServerListPingListener.java:
--------------------------------------------------------------------------------
1 | package com.justixdev.eazynick.listeners;
2 |
3 | import com.justixdev.eazynick.EazyNick;
4 | import org.bukkit.event.EventHandler;
5 | import org.bukkit.event.Listener;
6 | import org.bukkit.event.server.ServerListPingEvent;
7 |
8 | public class ServerListPingListener implements Listener {
9 |
10 | @EventHandler
11 | public void onServerListPing(ServerListPingEvent event) {
12 | EazyNick.getInstance().getPacketInjectorManager().inject(event.getAddress());
13 | }
14 |
15 | }
16 |
--------------------------------------------------------------------------------
/src/main/java/com/justixdev/eazynick/nms/guis/book/BookComponentBuilder.java:
--------------------------------------------------------------------------------
1 | package com.justixdev.eazynick.nms.guis.book;
2 |
3 | import net.md_5.bungee.api.chat.BaseComponent;
4 | import net.md_5.bungee.api.chat.ClickEvent;
5 | import net.md_5.bungee.api.chat.HoverEvent;
6 | import net.md_5.bungee.api.chat.TextComponent;
7 |
8 | import java.lang.reflect.InvocationTargetException;
9 | import java.util.Collections;
10 |
11 | import static com.justixdev.eazynick.nms.ReflectionHelper.*;
12 |
13 | public class BookComponentBuilder {
14 |
15 | private final TextComponent component;
16 |
17 | public BookComponentBuilder(String text) {
18 | this.component = new TextComponent(text);
19 | }
20 |
21 | public BookComponentBuilder clickEvent(ClickEvent.Action action, String value) {
22 | this.component.setClickEvent(new ClickEvent(action, value));
23 | return this;
24 | }
25 |
26 | public BookComponentBuilder hoverEvent(HoverEvent.Action action, String text) {
27 | HoverEvent event = null;
28 |
29 | if(NMS_VERSION.startsWith("v1_17")
30 | || NMS_VERSION.startsWith("v1_18")
31 | || NMS_VERSION.startsWith("v1_19"))
32 | event = new HoverEvent(
33 | action,
34 | Collections.singletonList(new net.md_5.bungee.api.chat.hover.content.Text(text)));
35 | else {
36 | try {
37 | event = (HoverEvent) newInstance(
38 | HoverEvent.class,
39 | types(HoverEvent.Action.class, BaseComponent[].class),
40 | action,
41 | TextComponent.fromLegacyText(text));
42 | } catch (NoSuchMethodException | InvocationTargetException | IllegalAccessException |
43 | InstantiationException ignore) {
44 | }
45 | }
46 |
47 | if(event != null)
48 | this.component.setHoverEvent(event);
49 |
50 | return this;
51 | }
52 |
53 | public TextComponent build() {
54 | return this.component;
55 | }
56 |
57 | }
--------------------------------------------------------------------------------
/src/main/java/com/justixdev/eazynick/nms/guis/book/BookPage.java:
--------------------------------------------------------------------------------
1 | package com.justixdev.eazynick.nms.guis.book;
2 |
3 | import lombok.AllArgsConstructor;
4 | import net.md_5.bungee.api.chat.BaseComponent;
5 | import net.md_5.bungee.api.chat.TextComponent;
6 | import net.md_5.bungee.chat.ComponentSerializer;
7 |
8 | import java.util.Arrays;
9 | import java.util.List;
10 | import java.util.stream.Collectors;
11 |
12 | import static com.justixdev.eazynick.nms.ReflectionHelper.*;
13 |
14 | @AllArgsConstructor
15 | public class BookPage {
16 |
17 | private final List texts;
18 |
19 | public Object getAsIChatBaseComponent() {
20 | try {
21 | return invokeStatic(
22 | NMS_VERSION.startsWith("v1_7") || NMS_VERSION.equals("v1_8_R1")
23 | ? getNMSClass("ChatSerializer")
24 | : getNMSClass(
25 | NMS_VERSION.startsWith("v1_17")
26 | || NMS_VERSION.startsWith("v1_18")
27 | || NMS_VERSION.startsWith("v1_19")
28 | ? "network.chat.IChatBaseComponent"
29 | : "IChatBaseComponent")
30 | .getDeclaredClasses()[0],
31 | NMS_VERSION.startsWith("1_18") || NMS_VERSION.startsWith("1_19")
32 | ? "b"
33 | : "a",
34 | types(String.class),
35 | this.getAsString());
36 | } catch (Exception ex) {
37 | return null;
38 | }
39 | }
40 |
41 | public String getAsString() {
42 | return ComponentSerializer.toString(new TextComponent(
43 | this.texts
44 | .stream()
45 | .map(textComponent ->
46 | Arrays.stream(TextComponent.fromLegacyText(textComponent.getText()))
47 | .peek(baseComponent -> {
48 | if (textComponent.getClickEvent() != null)
49 | baseComponent.setClickEvent(textComponent.getClickEvent());
50 |
51 | if (textComponent.getHoverEvent() != null)
52 | baseComponent.setHoverEvent(textComponent.getHoverEvent());
53 |
54 | })
55 | .collect(Collectors.toList()))
56 | .flatMap(List::stream)
57 | .toArray(BaseComponent[]::new)));
58 | }
59 |
60 | public boolean isEmpty() {
61 | return this.texts.stream().allMatch(textComponent -> textComponent.getText().isEmpty());
62 | }
63 |
64 | }
65 |
--------------------------------------------------------------------------------
/src/main/java/com/justixdev/eazynick/nms/netty/InjectorType.java:
--------------------------------------------------------------------------------
1 | package com.justixdev.eazynick.nms.netty;
2 |
3 | public enum InjectorType {
4 |
5 | INCOMING("client_handler"),
6 | OUTGOING("server_handler");
7 |
8 | private final String handlerName;
9 |
10 | InjectorType(String handlerName) {
11 | this.handlerName = handlerName;
12 | }
13 |
14 | public String getHandlerName() {
15 | return handlerName;
16 | }
17 |
18 | }
19 |
--------------------------------------------------------------------------------
/src/main/java/com/justixdev/eazynick/nms/netty/NMSPacketHelper.java:
--------------------------------------------------------------------------------
1 | package com.justixdev.eazynick.nms.netty;
2 |
3 | import com.justixdev.eazynick.EazyNick;
4 | import com.justixdev.eazynick.api.NickManager;
5 | import com.justixdev.eazynick.utilities.Utils;
6 | import org.bukkit.Bukkit;
7 | import org.bukkit.entity.Player;
8 | import org.bukkit.util.StringUtil;
9 |
10 | import java.util.ArrayList;
11 | import java.util.Arrays;
12 | import java.util.Collections;
13 | import java.util.List;
14 |
15 | public class NMSPacketHelper {
16 |
17 | public static String[] replaceTabCompletions(Player player, String[] tabCompletions) {
18 | EazyNick eazyNick = EazyNick.getInstance();
19 | Utils utils = eazyNick.getUtils();
20 |
21 | List newCompletions = new ArrayList<>(Arrays.asList(tabCompletions));
22 | String textToComplete = utils.getTextsToComplete().get(player);
23 |
24 | if(textToComplete.startsWith("/")) {
25 | if(!textToComplete.contains(" ")) {
26 | // add commands
27 | eazyNick.getCommandManager().getCommands().forEach((key, value) -> {
28 | newCompletions.add("/" + key.getName());
29 | value.getAliases().forEach(alias -> newCompletions.add("/" + alias));
30 | });
31 |
32 | List matches = StringUtil.copyPartialMatches(textToComplete, newCompletions, new ArrayList<>());
33 | newCompletions.clear();
34 | newCompletions.addAll(matches);
35 | }
36 | }
37 |
38 | if(textToComplete.endsWith(" "))
39 | textToComplete = "";
40 | else
41 | textToComplete = textToComplete.substring(textToComplete.lastIndexOf(' ') + 1).trim();
42 |
43 | if(!(player.hasPermission("eazynick.bypass")
44 | && eazyNick.getSetupYamlFile().getConfiguration().getBoolean("EnableBypassPermission"))) {
45 | List playerNames = new ArrayList<>();
46 |
47 | // Collect player-/nicknames
48 |
49 | Bukkit.getOnlinePlayers()
50 | .stream()
51 | .filter(currentPlayer -> !new NickManager(currentPlayer).isNicked())
52 | .forEach(currentPlayer -> playerNames.add(currentPlayer.getName()));
53 |
54 | utils.getNickedPlayers()
55 | .values()
56 | .forEach(currentNickedPlayerData -> playerNames.add(currentNickedPlayerData.getNickName()));
57 |
58 | // Process completions
59 | newCompletions.removeIf(currentCompletion -> Bukkit.getOnlinePlayers()
60 | .stream()
61 | .anyMatch(currentPlayer -> currentPlayer.getName().equalsIgnoreCase(currentCompletion))
62 | );
63 | newCompletions.addAll(StringUtil.copyPartialMatches(
64 | textToComplete,
65 | playerNames,
66 | new ArrayList<>()
67 | ));
68 | }
69 |
70 | Collections.sort(newCompletions);
71 |
72 | return newCompletions.toArray(new String[0]);
73 | }
74 |
75 | }
76 |
--------------------------------------------------------------------------------
/src/main/java/com/justixdev/eazynick/nms/netty/PacketInjector.java:
--------------------------------------------------------------------------------
1 | package com.justixdev.eazynick.nms.netty;
2 |
3 | import com.justixdev.eazynick.EazyNick;
4 | import com.justixdev.eazynick.utilities.Utils;
5 | import com.justixdev.eazynick.utilities.configuration.yaml.SetupYamlFile;
6 | import lombok.Getter;
7 |
8 | import java.net.InetAddress;
9 |
10 | public abstract class PacketInjector {
11 |
12 | protected EazyNick eazyNick;
13 | protected Utils utils;
14 | protected SetupYamlFile setupYamlFile;
15 | @Getter
16 | protected InetAddress address;
17 | @Getter
18 | protected InjectorType type;
19 | protected String handlerName;
20 |
21 | public PacketInjector(InetAddress address, InjectorType type) {
22 | this.eazyNick = EazyNick.getInstance();
23 | this.utils = this.eazyNick.getUtils();
24 | this.setupYamlFile = this.eazyNick.getSetupYamlFile();
25 | this.address = address;
26 | this.type = type;
27 | this.handlerName = this.eazyNick.getName().toLowerCase() + "_" + type.getHandlerName();
28 | }
29 |
30 | public abstract void inject();
31 |
32 | public abstract void unregisterChannel();
33 |
34 | public boolean onPacketReceive(Object packet) {
35 | return true;
36 | }
37 |
38 | public Object onPacketSend(Object packet) {
39 | return packet;
40 | }
41 |
42 | public void remove() {
43 | Object lock = new Object();
44 | Thread killThread = new Thread(() -> {
45 | try {
46 | this.unregisterChannel();
47 | } catch (Exception ignore) {
48 | }
49 |
50 | synchronized (lock) {
51 | lock.notify();
52 | }
53 | });
54 | killThread.start();
55 |
56 | synchronized (lock) {
57 | try {
58 | lock.wait(50);
59 | } catch (InterruptedException ignore) {
60 | }
61 | }
62 |
63 | if(killThread.isAlive())
64 | killThread.interrupt();
65 | }
66 |
67 | }
68 |
--------------------------------------------------------------------------------
/src/main/java/com/justixdev/eazynick/nms/netty/PacketInjectorManager.java:
--------------------------------------------------------------------------------
1 | package com.justixdev.eazynick.nms.netty;
2 |
3 | import com.justixdev.eazynick.nms.netty.legacy.impl.IncomingLegacyPacketInjector;
4 | import com.justixdev.eazynick.nms.netty.legacy.impl.OutgoingLegacyPacketInjector;
5 | import com.justixdev.eazynick.nms.netty.legacy.impl.ServerListLegacyPacketInjector;
6 | import com.justixdev.eazynick.nms.netty.modern.impl.IncomingModernPacketInjector;
7 | import com.justixdev.eazynick.nms.netty.modern.impl.OutgoingModernPacketInjector;
8 | import com.justixdev.eazynick.nms.netty.modern.impl.ServerListModernPacketInjector;
9 | import org.bukkit.entity.Player;
10 |
11 | import java.net.InetAddress;
12 | import java.util.HashMap;
13 | import java.util.HashSet;
14 | import java.util.Map;
15 | import java.util.Set;
16 |
17 | import static com.justixdev.eazynick.nms.ReflectionHelper.NMS_VERSION;
18 |
19 | public class PacketInjectorManager {
20 |
21 | private final Map> packetInjectors;
22 |
23 | public PacketInjectorManager() {
24 | this.packetInjectors = new HashMap<>();
25 | }
26 |
27 | public void inject(Player player) {
28 | if(player.getAddress() == null)
29 | return;
30 |
31 | InetAddress address = player.getAddress().getAddress();
32 | Set playerInjectors = this.packetInjectors.getOrDefault(address, new HashSet<>());
33 |
34 | if(NMS_VERSION.equals("v1_7_R4")) {
35 | playerInjectors.add(new OutgoingLegacyPacketInjector(player));
36 | playerInjectors.add(new IncomingLegacyPacketInjector(player));
37 | } else {
38 | playerInjectors.add(new OutgoingModernPacketInjector(player));
39 | playerInjectors.add(new IncomingModernPacketInjector(player));
40 | }
41 |
42 | this.packetInjectors.putIfAbsent(address, playerInjectors);
43 | }
44 |
45 | public void inject(InetAddress address) {
46 | Set addressInjectors = this.packetInjectors.getOrDefault(address, new HashSet<>());
47 |
48 | if(NMS_VERSION.equals("v1_7_R4"))
49 | addressInjectors.add(new ServerListLegacyPacketInjector(address));
50 | else
51 | addressInjectors.add(new ServerListModernPacketInjector(address));
52 |
53 | this.packetInjectors.putIfAbsent(address, addressInjectors);
54 | }
55 |
56 | public void remove(Player player) {
57 | if(player.getAddress() == null)
58 | return;
59 |
60 | this.remove(player.getAddress().getAddress());
61 | }
62 |
63 | public void remove(InetAddress address) {
64 | if(this.packetInjectors.containsKey(address))
65 | this.packetInjectors.remove(address).forEach(PacketInjector::remove);
66 | }
67 |
68 | public void removeAll() {
69 | this.packetInjectors.values().forEach(injectors -> injectors.forEach(PacketInjector::remove));
70 | }
71 |
72 | }
73 |
--------------------------------------------------------------------------------
/src/main/java/com/justixdev/eazynick/nms/netty/PlayerPacketInjector.java:
--------------------------------------------------------------------------------
1 | package com.justixdev.eazynick.nms.netty;
2 |
3 | import org.bukkit.entity.Player;
4 |
5 | public interface PlayerPacketInjector {
6 |
7 | Player getPlayer();
8 |
9 | }
10 |
--------------------------------------------------------------------------------
/src/main/java/com/justixdev/eazynick/nms/netty/legacy/LegacyAddressPacketInjector.java:
--------------------------------------------------------------------------------
1 | package com.justixdev.eazynick.nms.netty.legacy;
2 |
3 | import com.justixdev.eazynick.nms.netty.InjectorType;
4 | import net.minecraft.util.io.netty.channel.Channel;
5 | import org.bukkit.Bukkit;
6 |
7 | import java.net.InetAddress;
8 | import java.net.InetSocketAddress;
9 | import java.util.Collections;
10 | import java.util.List;
11 |
12 | import static com.justixdev.eazynick.nms.ReflectionHelper.*;
13 |
14 | public class LegacyAddressPacketInjector extends LegacyPacketInjector {
15 |
16 | public LegacyAddressPacketInjector(InetAddress address, InjectorType type) {
17 | super(address, type);
18 |
19 | this.initChannel();
20 | }
21 |
22 | @Override
23 | public void initChannel() {
24 | getFirstFieldByType(
25 | getNMSClass("NetworkManager"),
26 | Channel.class
27 | ).ifPresent(field -> {
28 | field.setAccessible(true);
29 |
30 | try {
31 | // Get MinecraftServer from CraftServer
32 | Object minecraftServer = getFieldValue(Bukkit.getServer(), "console");
33 |
34 | for (Object manager : Collections.synchronizedList((List>) getLastFieldByTypeValue(
35 | invoke(minecraftServer, "getServerConnection"),
36 | List.class
37 | )).toArray()) {
38 | Channel channel = (Channel) field.get(manager);
39 |
40 | if ((channel == null) || (channel.pipeline() == null))
41 | continue;
42 |
43 | if(!(channel.remoteAddress() instanceof InetSocketAddress))
44 | continue;
45 |
46 | if(!((InetSocketAddress) channel.remoteAddress()).getAddress().equals(this.address))
47 | continue;
48 |
49 | if (channel.pipeline().get("packet_handler") != null) {
50 | this.channel = channel;
51 | this.inject();
52 | }
53 | }
54 | } catch (Exception ex) {
55 | ex.printStackTrace();
56 | }
57 | });
58 | }
59 |
60 | }
61 |
--------------------------------------------------------------------------------
/src/main/java/com/justixdev/eazynick/nms/netty/legacy/LegacyPacketInjector.java:
--------------------------------------------------------------------------------
1 | package com.justixdev.eazynick.nms.netty.legacy;
2 |
3 | import com.justixdev.eazynick.EazyNick;
4 | import com.justixdev.eazynick.nms.netty.InjectorType;
5 | import com.justixdev.eazynick.nms.netty.PacketInjector;
6 | import net.minecraft.util.io.netty.channel.Channel;
7 | import net.minecraft.util.io.netty.channel.ChannelDuplexHandler;
8 | import net.minecraft.util.io.netty.channel.ChannelHandlerContext;
9 | import net.minecraft.util.io.netty.channel.ChannelPromise;
10 |
11 | import java.net.InetAddress;
12 |
13 | public abstract class LegacyPacketInjector extends PacketInjector {
14 |
15 | protected Channel channel;
16 |
17 | public LegacyPacketInjector(InetAddress address, InjectorType type) {
18 | super(address, type);
19 | }
20 |
21 | public abstract void initChannel();
22 |
23 | @Override
24 | public void inject() {
25 | // Inject into to netty channel
26 | ChannelDuplexHandler handler = new ChannelDuplexHandler() {
27 |
28 | @Override
29 | public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
30 | if(!onPacketReceive(msg))
31 | return;
32 |
33 | super.channelRead(ctx, msg);
34 | }
35 |
36 | @Override
37 | public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) throws Exception {
38 | Object newPacket = onPacketSend(msg);
39 |
40 | if(newPacket == null)
41 | return;
42 |
43 | super.write(ctx, newPacket, promise);
44 | }
45 |
46 | @Override
47 | public void close(ChannelHandlerContext ctx, ChannelPromise future) throws Exception {
48 | EazyNick.getInstance().getPacketInjectorManager().remove(address);
49 |
50 | super.close(ctx, future);
51 | }
52 | };
53 |
54 | if (this.channel.pipeline().get(this.handlerName) != null)
55 | return;
56 |
57 | if(this.type.equals(InjectorType.INCOMING))
58 | this.channel.pipeline().addBefore(
59 | "packet_handler",
60 | this.handlerName,
61 | handler
62 | );
63 | else
64 | this.channel.pipeline().addAfter(
65 | "packet_handler",
66 | this.handlerName,
67 | handler
68 | );
69 | }
70 |
71 | @Override
72 | public void unregisterChannel() {
73 | this.channel.pipeline().remove(this.handlerName);
74 | }
75 |
76 | }
77 |
--------------------------------------------------------------------------------
/src/main/java/com/justixdev/eazynick/nms/netty/legacy/LegacyPlayerPacketInjector.java:
--------------------------------------------------------------------------------
1 | package com.justixdev.eazynick.nms.netty.legacy;
2 |
3 | import com.justixdev.eazynick.nms.netty.InjectorType;
4 | import lombok.Getter;
5 | import net.minecraft.util.io.netty.channel.Channel;
6 | import org.bukkit.entity.Player;
7 |
8 | import java.util.Objects;
9 |
10 | import static com.justixdev.eazynick.nms.ReflectionHelper.getFieldValue;
11 | import static com.justixdev.eazynick.nms.ReflectionHelper.invoke;
12 |
13 | public abstract class LegacyPlayerPacketInjector extends LegacyPacketInjector {
14 |
15 | @Getter
16 | protected Player player;
17 |
18 | public LegacyPlayerPacketInjector(Player player, InjectorType type) {
19 | super(Objects.requireNonNull(player.getAddress()).getAddress(), type);
20 |
21 | this.player = player;
22 |
23 | this.initChannel();
24 | }
25 |
26 | @Override
27 | public void initChannel() {
28 | try {
29 | Object entityPlayer = invoke(this.player, "getHandle");
30 | Object playerConnection = getFieldValue(entityPlayer, "playerConnection");
31 | Object networkManager = getFieldValue(playerConnection, "networkManager");
32 |
33 | this.channel = (Channel) getFieldValue(networkManager, "m");
34 | this.inject();
35 | } catch (Exception ex) {
36 | ex.printStackTrace();
37 | }
38 | }
39 |
40 | }
41 |
--------------------------------------------------------------------------------
/src/main/java/com/justixdev/eazynick/nms/netty/legacy/impl/IncomingLegacyPacketInjector.java:
--------------------------------------------------------------------------------
1 | package com.justixdev.eazynick.nms.netty.legacy.impl;
2 |
3 | import com.justixdev.eazynick.nms.guis.SignGUI;
4 | import com.justixdev.eazynick.nms.guis.SignGUI.EditCompleteEvent;
5 | import com.justixdev.eazynick.nms.netty.InjectorType;
6 | import com.justixdev.eazynick.nms.netty.legacy.LegacyPlayerPacketInjector;
7 | import org.bukkit.Bukkit;
8 | import org.bukkit.entity.Player;
9 |
10 | import java.util.Objects;
11 |
12 | import static com.justixdev.eazynick.nms.ReflectionHelper.*;
13 |
14 | public class IncomingLegacyPacketInjector extends LegacyPlayerPacketInjector {
15 |
16 | public IncomingLegacyPacketInjector(Player player) {
17 | super(player, InjectorType.INCOMING);
18 | }
19 |
20 | @Override
21 | public boolean onPacketReceive(Object packet) {
22 | SignGUI signGUI = this.eazyNick.getSignGUI();
23 |
24 | try {
25 | switch (packet.getClass().getSimpleName()) {
26 | case "PacketPlayInUpdateSign":
27 | if (signGUI.getEditCompleteListeners().containsKey(this.player)) {
28 | // Process SignGUI success
29 | Object[] rawLines = (Object[]) Objects.requireNonNull(getField(packet.getClass(), "b")).get(packet);
30 |
31 | Bukkit.getScheduler().runTask(this.eazyNick, () -> {
32 | try {
33 | String[] lines = new String[4];
34 |
35 | if (NMS_VERSION.startsWith("1_8")) {
36 | int i = 0;
37 |
38 | for (Object line : rawLines) {
39 | lines[i] = (String) invoke(line, "getText");
40 |
41 | i++;
42 | }
43 | } else
44 | lines = (String[]) rawLines;
45 |
46 | signGUI.getEditCompleteListeners().get(this.player).onEditComplete(new EditCompleteEvent(lines));
47 | signGUI.getBlocks().get(this.player).setType(signGUI.getOldTypes().get(this.player));
48 | } catch (Exception ex) {
49 | ex.printStackTrace();
50 | }
51 | });
52 | }
53 | break;
54 | case "PacketPlayInTabComplete":
55 | // Cache input text
56 | this.eazyNick.getUtils().getTextsToComplete().put(
57 | this.player,
58 | (String) getFieldValue(packet, "a")
59 | );
60 | break;
61 | default:
62 | break;
63 | }
64 | } catch (Exception ex) {
65 | ex.printStackTrace();
66 | }
67 |
68 | return true;
69 | }
70 |
71 | }
--------------------------------------------------------------------------------
/src/main/java/com/justixdev/eazynick/nms/netty/legacy/impl/ServerListLegacyPacketInjector.java:
--------------------------------------------------------------------------------
1 | package com.justixdev.eazynick.nms.netty.legacy.impl;
2 |
3 | import com.justixdev.eazynick.nms.netty.InjectorType;
4 | import com.justixdev.eazynick.nms.netty.legacy.LegacyAddressPacketInjector;
5 | import net.minecraft.util.com.mojang.authlib.GameProfile;
6 |
7 | import java.net.InetAddress;
8 | import java.util.UUID;
9 |
10 | import static com.justixdev.eazynick.nms.ReflectionHelper.getFieldValue;
11 | import static com.justixdev.eazynick.nms.ReflectionHelper.setField;
12 |
13 | @SuppressWarnings("SwitchStatementWithTooFewBranches")
14 | public class ServerListLegacyPacketInjector extends LegacyAddressPacketInjector {
15 |
16 | public ServerListLegacyPacketInjector(InetAddress address) {
17 | super(address, InjectorType.OUTGOING);
18 | }
19 |
20 | @Override
21 | public Object onPacketSend(Object packet) {
22 | try {
23 | switch (packet.getClass().getSimpleName()) {
24 | case "PacketStatusOutServerInfo":
25 | Object serverPing = getFieldValue(packet, "b");
26 | Object serverPingPlayerSample = getFieldValue(serverPing, "b");
27 | GameProfile[] gameProfileArray = (GameProfile[]) getFieldValue(serverPingPlayerSample, "c");
28 |
29 | for (int i = 0; i < gameProfileArray.length; i++) {
30 | UUID uuid = gameProfileArray[i].getId();
31 |
32 | if(this.utils.getNickedPlayers().containsKey(uuid))
33 | // Replace game profile with fake game profile (nicked player profile)
34 | gameProfileArray[i] = (GameProfile) this.utils.getNickedPlayers()
35 | .get(uuid)
36 | .getFakeGameProfile(false);
37 | }
38 |
39 | // Replace game profiles in ServerPingPlayerSample
40 | setField(serverPingPlayerSample, "c", gameProfileArray);
41 | break;
42 | default:
43 | break;
44 | }
45 | } catch (Exception ex) {
46 | ex.printStackTrace();
47 | }
48 |
49 | return packet;
50 | }
51 |
52 | }
53 |
--------------------------------------------------------------------------------
/src/main/java/com/justixdev/eazynick/nms/netty/modern/ModernAddressPacketInjector.java:
--------------------------------------------------------------------------------
1 | package com.justixdev.eazynick.nms.netty.modern;
2 |
3 | import com.justixdev.eazynick.nms.netty.InjectorType;
4 | import io.netty.channel.Channel;
5 | import org.bukkit.Bukkit;
6 |
7 | import java.net.InetAddress;
8 | import java.net.InetSocketAddress;
9 | import java.util.Collections;
10 | import java.util.List;
11 | import java.util.Queue;
12 |
13 | import static com.justixdev.eazynick.nms.ReflectionHelper.*;
14 |
15 | public class ModernAddressPacketInjector extends ModernPacketInjector {
16 |
17 | public ModernAddressPacketInjector(InetAddress address, InjectorType type) {
18 | super(address, type);
19 |
20 | this.initChannel();
21 | }
22 |
23 | @Override
24 | public void initChannel() {
25 | boolean is1_17 = NMS_VERSION.startsWith("v1_17"),
26 | is1_18 = NMS_VERSION.startsWith("v1_18"),
27 | is1_19 = NMS_VERSION.startsWith("v1_19"),
28 | is1_20 = NMS_VERSION.startsWith("v1_20");
29 |
30 | getFirstFieldByType(
31 | is1_17 || is1_18 || is1_19 || is1_20
32 | ? getNMSClass("network.NetworkManager")
33 | : getNMSClass("NetworkManager"),
34 | Channel.class
35 | ).ifPresent(field -> {
36 | field.setAccessible(true);
37 |
38 | try {
39 | // Get MinecraftServer from CraftServer
40 | Object minecraftServer = getFieldValue(Bukkit.getServer(), "console");
41 | Object[] managers;
42 |
43 | if(NMS_VERSION.startsWith("v1_13") || NMS_VERSION.startsWith("v1_14"))
44 | managers = Collections.synchronizedList((List>) getFieldValue(
45 | invoke(minecraftServer, "getServerConnection"),
46 | "g"
47 | )).toArray();
48 | else if(NMS_VERSION.startsWith("v1_15")
49 | || NMS_VERSION.startsWith("v1_16")
50 | || is1_17
51 | || is1_18
52 | || is1_19
53 | || is1_20)
54 | managers = ((Queue>) getFieldValue(
55 | invoke(
56 | minecraftServer,
57 | NMS_VERSION.equals("v1_19_R2")
58 | ? "ac"
59 | : is1_18 || is1_19 || is1_20
60 | ? "ad"
61 | : "getServerConnection"
62 | ),
63 | "pending"
64 | )).toArray();
65 | else
66 | managers = Collections.synchronizedList((List>) getLastFieldByTypeValue(
67 | invoke(minecraftServer, "getServerConnection"),
68 | List.class
69 | )).toArray();
70 |
71 | for (Object manager : managers) {
72 | Channel channel = (Channel) field.get(manager);
73 |
74 | if ((channel == null) || (channel.pipeline() == null))
75 | continue;
76 |
77 | if(!(channel.remoteAddress() instanceof InetSocketAddress))
78 | continue;
79 |
80 | if(!((InetSocketAddress) channel.remoteAddress()).getAddress().equals(this.address))
81 | continue;
82 |
83 | if (channel.pipeline().get("packet_handler") != null) {
84 | this.channel = channel;
85 | this.inject();
86 | }
87 | }
88 | } catch (Exception ex) {
89 | if(!ex.getMessage().startsWith("Duplicate handler name"))
90 | ex.printStackTrace();
91 | }
92 | });
93 | }
94 |
95 | }
96 |
--------------------------------------------------------------------------------
/src/main/java/com/justixdev/eazynick/nms/netty/modern/ModernPacketInjector.java:
--------------------------------------------------------------------------------
1 | package com.justixdev.eazynick.nms.netty.modern;
2 |
3 | import com.justixdev.eazynick.EazyNick;
4 | import com.justixdev.eazynick.nms.netty.InjectorType;
5 | import com.justixdev.eazynick.nms.netty.PacketInjector;
6 | import io.netty.channel.Channel;
7 | import io.netty.channel.ChannelDuplexHandler;
8 | import io.netty.channel.ChannelHandlerContext;
9 | import io.netty.channel.ChannelPromise;
10 |
11 | import java.net.InetAddress;
12 |
13 | public abstract class ModernPacketInjector extends PacketInjector {
14 |
15 | protected Channel channel;
16 |
17 | public ModernPacketInjector(InetAddress address, InjectorType type) {
18 | super(address, type);
19 | }
20 |
21 | public abstract void initChannel();
22 |
23 | @Override
24 | public void inject() {
25 | // Inject into to netty channel
26 | ChannelDuplexHandler handler = new ChannelDuplexHandler() {
27 | @Override
28 | public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
29 | if (!onPacketReceive(msg))
30 | return;
31 |
32 | super.channelRead(ctx, msg);
33 | }
34 |
35 | @Override
36 | public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) throws Exception {
37 | Object newPacket = onPacketSend(msg);
38 |
39 | if (newPacket == null)
40 | return;
41 |
42 | super.write(ctx, newPacket, promise);
43 | }
44 |
45 | @Override
46 | public void close(ChannelHandlerContext ctx, ChannelPromise promise) throws Exception {
47 | EazyNick.getInstance().getPacketInjectorManager().remove(address);
48 |
49 | super.close(ctx, promise);
50 | }
51 | };
52 |
53 | if (this.channel.pipeline().get(this.handlerName) != null)
54 | return;
55 |
56 | if (this.type.equals(InjectorType.INCOMING))
57 | this.channel.pipeline().addBefore(
58 | "packet_handler",
59 | this.handlerName,
60 | handler
61 | );
62 | else
63 | this.channel.pipeline().addAfter(
64 | "packet_handler",
65 | this.handlerName,
66 | handler
67 | );
68 | }
69 |
70 | @Override
71 | public void unregisterChannel() {
72 | this.channel.pipeline().remove(this.handlerName);
73 | }
74 |
75 | }
76 |
--------------------------------------------------------------------------------
/src/main/java/com/justixdev/eazynick/nms/netty/modern/ModernPlayerPacketInjector.java:
--------------------------------------------------------------------------------
1 | package com.justixdev.eazynick.nms.netty.modern;
2 |
3 | import com.justixdev.eazynick.nms.netty.InjectorType;
4 | import com.justixdev.eazynick.nms.netty.PlayerPacketInjector;
5 | import io.netty.channel.Channel;
6 | import lombok.Getter;
7 | import org.bukkit.entity.Player;
8 |
9 | import java.util.Objects;
10 |
11 | import static com.justixdev.eazynick.nms.ReflectionHelper.*;
12 |
13 | public class ModernPlayerPacketInjector extends ModernPacketInjector implements PlayerPacketInjector {
14 |
15 | @Getter
16 | protected Player player;
17 |
18 | public ModernPlayerPacketInjector(Player player, InjectorType type) {
19 | super(Objects.requireNonNull(player.getAddress()).getAddress(), type);
20 |
21 | this.player = player;
22 |
23 | this.initChannel();
24 | }
25 |
26 | @Override
27 | public void initChannel() {
28 | try {
29 | boolean is1_17 = NMS_VERSION.startsWith("v1_17"),
30 | is1_18 = NMS_VERSION.startsWith("v1_18"),
31 | is1_19 = NMS_VERSION.startsWith("v1_19"),
32 | is1_20 = NMS_VERSION.startsWith("v1_20");
33 | Object entityPlayer = invoke(this.player, "getHandle");
34 | Object playerConnection = getFieldValue(entityPlayer,
35 | is1_20
36 | ? "c"
37 | : is1_17 || is1_18 || is1_19
38 | ? "b"
39 | : "playerConnection"
40 | );
41 | Object networkManager = getFieldValue(playerConnection,
42 | NMS_VERSION.equals("v1_19_R3") || is1_20
43 | ? "h"
44 | : is1_19
45 | ? "b"
46 | : is1_17 || is1_18
47 | ? "a"
48 | : "networkManager"
49 | );
50 |
51 | this.channel = (Channel) getFieldValue(networkManager,
52 | is1_17 || is1_18 || is1_19 || is1_20
53 | ? NMS_VERSION.equals("v1_18_R2") || is1_19 || is1_20
54 | ? "m"
55 | : "k"
56 | : "channel"
57 | );
58 | this.inject();
59 | } catch (Exception ex) {
60 | if(!ex.getMessage().startsWith("Duplicate handler name"))
61 | ex.printStackTrace();
62 | }
63 | }
64 |
65 | }
66 |
--------------------------------------------------------------------------------
/src/main/java/com/justixdev/eazynick/nms/netty/modern/impl/IncomingModernPacketInjector.java:
--------------------------------------------------------------------------------
1 | package com.justixdev.eazynick.nms.netty.modern.impl;
2 |
3 | import com.justixdev.eazynick.nms.guis.SignGUI;
4 | import com.justixdev.eazynick.nms.guis.SignGUI.EditCompleteEvent;
5 | import com.justixdev.eazynick.nms.netty.InjectorType;
6 | import com.justixdev.eazynick.nms.netty.modern.ModernPlayerPacketInjector;
7 | import org.bukkit.Bukkit;
8 | import org.bukkit.entity.Player;
9 |
10 | import static com.justixdev.eazynick.nms.ReflectionHelper.*;
11 |
12 | public class IncomingModernPacketInjector extends ModernPlayerPacketInjector {
13 |
14 | public IncomingModernPacketInjector(Player player) {
15 | super(player, InjectorType.INCOMING);
16 | }
17 |
18 | @Override
19 | public boolean onPacketReceive(Object packet) {
20 | SignGUI signGUI = this.eazyNick.getSignGUI();
21 | boolean is1_17 = NMS_VERSION.startsWith("v1_17"),
22 | is1_18 = NMS_VERSION.startsWith("v1_18"),
23 | is1_19 = NMS_VERSION.startsWith("v1_19"),
24 | is1_20 = NMS_VERSION.startsWith("v1_20");
25 |
26 | try {
27 | switch (packet.getClass().getSimpleName()) {
28 | case "PacketPlayInUpdateSign":
29 | if (signGUI.getEditCompleteListeners().containsKey(this.player)) {
30 | // Process SignGUI success
31 | Object[] rawLines = (Object[]) getFieldValue(
32 | packet,
33 | is1_17 || is1_18 || is1_19 || is1_20
34 | ? "c"
35 | : "b"
36 | );
37 |
38 | Bukkit.getScheduler().runTask(eazyNick, () -> {
39 | String[] lines = new String[4];
40 |
41 | if (NMS_VERSION.startsWith("v1_8")) {
42 | int i = 0;
43 |
44 | for (Object line : rawLines) {
45 | try {
46 | lines[i] = (String) invoke(line, "getText");
47 | } catch (Exception ex) {
48 | lines[i] = "";
49 | }
50 |
51 | i++;
52 | }
53 | } else
54 | lines = (String[]) rawLines;
55 |
56 | signGUI.getEditCompleteListeners().get(this.player).onEditComplete(new EditCompleteEvent(lines));
57 | signGUI.getBlocks().get(this.player).setType(signGUI.getOldTypes().get(this.player));
58 | });
59 | }
60 | break;
61 | case "PacketPlayInTabComplete":
62 | // Cache input text
63 | this.eazyNick.getUtils().getTextsToComplete().put(
64 | this.player,
65 | (String) getFieldValue(packet, VERSION_13_OR_LATER ? "b" : "a")
66 | );
67 | break;
68 | default:
69 | break;
70 | }
71 | } catch (Exception ex) {
72 | ex.printStackTrace();
73 | }
74 |
75 | return true;
76 | }
77 |
78 | }
--------------------------------------------------------------------------------
/src/main/java/com/justixdev/eazynick/nms/netty/modern/impl/ServerListModernPacketInjector.java:
--------------------------------------------------------------------------------
1 | package com.justixdev.eazynick.nms.netty.modern.impl;
2 |
3 | import com.justixdev.eazynick.nms.netty.InjectorType;
4 | import com.justixdev.eazynick.nms.netty.modern.ModernAddressPacketInjector;
5 | import com.mojang.authlib.GameProfile;
6 |
7 | import java.net.InetAddress;
8 | import java.util.List;
9 | import java.util.UUID;
10 | import java.util.stream.Collectors;
11 |
12 | import static com.justixdev.eazynick.nms.ReflectionHelper.*;
13 |
14 | @SuppressWarnings({"unchecked", "SwitchStatementWithTooFewBranches"})
15 | public class ServerListModernPacketInjector extends ModernAddressPacketInjector {
16 |
17 | public ServerListModernPacketInjector(InetAddress address) {
18 | super(address, InjectorType.OUTGOING);
19 | }
20 |
21 | @Override
22 | public Object onPacketSend(Object packet) {
23 | boolean is1_17 = NMS_VERSION.startsWith("v1_17"),
24 | is1_18 = NMS_VERSION.startsWith("v1_18"),
25 | is1_19 = NMS_VERSION.startsWith("v1_19"),
26 | is1_20 = NMS_VERSION.startsWith("v1_20");
27 |
28 | try {
29 | switch (packet.getClass().getSimpleName()) {
30 | case "PacketStatusOutServerInfo":
31 | Object serverPing = getFieldValue(packet, (NMS_VERSION.equals("v1_19_R3") || is1_20) ? "a" : "b");
32 | Object serverPingPlayerSample = getFieldValue(
33 | serverPing,
34 | NMS_VERSION.equals("v1_19_R3") || is1_20
35 | ? "c"
36 | : is1_17 || is1_18 || is1_19
37 | ? "d"
38 | : "b"
39 | );
40 |
41 | if (NMS_VERSION.equals("v1_19_R3") || is1_20) {
42 | serverPingPlayerSample = invoke(serverPingPlayerSample, "orElse", types(Object.class), (Object) null);
43 |
44 | List gameProfileList = (List) getFieldValue(serverPingPlayerSample, "d");
45 | List newGameProfileList = gameProfileList
46 | .stream()
47 | .map(gameProfile -> this.utils.getNickedPlayers().containsKey(gameProfile.getId())
48 | ? (GameProfile) this.utils.getNickedPlayers()
49 | .get(gameProfile.getId())
50 | .getFakeGameProfile(this.setupYamlFile.getConfiguration().getBoolean("Settings.ChangeOptions.UUID"))
51 | : gameProfile
52 | )
53 | .collect(Collectors.toList());
54 |
55 | gameProfileList.clear();
56 | gameProfileList.addAll(newGameProfileList);
57 | } else {
58 | GameProfile[] gameProfileArray = (GameProfile[]) getFieldValue(serverPingPlayerSample, "c");
59 |
60 | for (int i = 0; i < gameProfileArray.length; i++) {
61 | UUID uuid = gameProfileArray[i].getId();
62 |
63 | if (this.utils.getNickedPlayers().containsKey(uuid))
64 | // Replace game profile with fake game profile (nicked player profile)
65 | gameProfileArray[i] = (GameProfile) this.utils.getNickedPlayers()
66 | .get(uuid)
67 | .getFakeGameProfile(this.setupYamlFile.getConfiguration().getBoolean("Settings.ChangeOptions.UUID"));
68 | }
69 |
70 | // Replace game profiles in ServerPingPlayerSample
71 | setField(serverPingPlayerSample, "c", gameProfileArray);
72 | }
73 | break;
74 | default:
75 | break;
76 | }
77 | } catch (Exception ex) {
78 | ex.printStackTrace();
79 | }
80 |
81 | return packet;
82 | }
83 |
84 | }
85 |
--------------------------------------------------------------------------------
/src/main/java/com/justixdev/eazynick/sql/MySQLNickManager.java:
--------------------------------------------------------------------------------
1 | package com.justixdev.eazynick.sql;
2 |
3 | import lombok.AllArgsConstructor;
4 | import lombok.Data;
5 | import lombok.RequiredArgsConstructor;
6 | import org.bukkit.Bukkit;
7 |
8 | import java.sql.ResultSet;
9 | import java.sql.SQLException;
10 | import java.util.HashMap;
11 | import java.util.UUID;
12 | import java.util.logging.Level;
13 |
14 | @RequiredArgsConstructor
15 | public class MySQLNickManager {
16 |
17 | private static final HashMap CACHE = new HashMap<>();
18 |
19 | private final MySQL mysql;
20 |
21 | public String getNickName(UUID uniqueId) {
22 | return this.isNicked(uniqueId) ? CACHE.get(uniqueId).getNickName() : "";
23 | }
24 |
25 | public String getSkinName(UUID uniqueId) {
26 | return this.isNicked(uniqueId) ? CACHE.get(uniqueId).getSkinName() : "";
27 | }
28 |
29 | public void addPlayer(UUID uniqueId, String nickName, String skinName) {
30 | this.removePlayer(uniqueId);
31 |
32 | CACHE.put(uniqueId, new CachedNickData(nickName, skinName));
33 |
34 | this.mysql.update("INSERT INTO `nicked_players` VALUES (?, ?, ?)", uniqueId, nickName, skinName);
35 | }
36 |
37 | public void removePlayer(UUID uniqueId) {
38 | CACHE.remove(uniqueId);
39 |
40 | this.mysql.update("DELETE FROM `nicked_players` WHERE unique_id = ?", uniqueId);
41 | }
42 |
43 | public boolean isNicked(UUID uniqueId) {
44 | if(CACHE.containsKey(uniqueId))
45 | return true;
46 |
47 | try(ResultSet resultSet = this.mysql.getResult("SELECT * FROM `nicked_players` WHERE unique_id = ?", uniqueId)) {
48 | if(resultSet.next()) {
49 | CACHE.put(uniqueId, CachedNickData.fromResultSet(resultSet));
50 |
51 | return true;
52 | }
53 | } catch (SQLException ex) {
54 | Bukkit.getLogger().log(Level.WARNING, "Could not execute sql query: " + ex.getMessage());
55 | }
56 |
57 | return false;
58 | }
59 |
60 | public void clearCachedData(UUID uniqueId) {
61 | CACHE.remove(uniqueId);
62 | }
63 |
64 | @Data
65 | @AllArgsConstructor
66 | public static class CachedNickData {
67 |
68 | private final String nickName, skinName;
69 |
70 | public static CachedNickData fromResultSet(ResultSet resultSet) throws SQLException {
71 | return new CachedNickData(
72 | resultSet.getString("nickname"),
73 | resultSet.getString("skin_name"));
74 | }
75 |
76 | }
77 |
78 | }
--------------------------------------------------------------------------------
/src/main/java/com/justixdev/eazynick/sql/MySQLPlayerDataManager.java:
--------------------------------------------------------------------------------
1 | package com.justixdev.eazynick.sql;
2 |
3 | import lombok.AllArgsConstructor;
4 | import lombok.Data;
5 | import lombok.RequiredArgsConstructor;
6 |
7 | import java.sql.ResultSet;
8 | import java.sql.SQLException;
9 | import java.util.HashMap;
10 | import java.util.UUID;
11 |
12 | @RequiredArgsConstructor
13 | public class MySQLPlayerDataManager {
14 |
15 | private static final HashMap CACHE = new HashMap<>();
16 |
17 | private final MySQL mysql;
18 |
19 | public String getGroupName(UUID uniqueId) {
20 | return this.isRegistered(uniqueId) ? CACHE.get(uniqueId).getGroupName() : "";
21 | }
22 |
23 | public String getChatPrefix(UUID uniqueId) {
24 | return this.isRegistered(uniqueId) ? CACHE.get(uniqueId).getChatPrefix() : "";
25 | }
26 |
27 | public String getChatSuffix(UUID uniqueId) {
28 | return this.isRegistered(uniqueId) ? CACHE.get(uniqueId).getChatSuffix() : "";
29 | }
30 |
31 | public String getTabPrefix(UUID uniqueId) {
32 | return this.isRegistered(uniqueId) ? CACHE.get(uniqueId).getTabPrefix() : "";
33 | }
34 |
35 | public String getTabSuffix(UUID uniqueId) {
36 | return this.isRegistered(uniqueId) ? CACHE.get(uniqueId).getTabSuffix() : "";
37 | }
38 |
39 | public String getTagPrefix(UUID uniqueId) {
40 | return this.isRegistered(uniqueId) ? CACHE.get(uniqueId).getTagPrefix() : "";
41 | }
42 |
43 | public String getTagSuffix(UUID uniqueId) {
44 | return this.isRegistered(uniqueId) ? CACHE.get(uniqueId).getTagSuffix() : "";
45 | }
46 |
47 | public void insertData(UUID uniqueId,
48 | String groupName,
49 | String chatPrefix,
50 | String chatSuffix,
51 | String tabPrefix,
52 | String tabSuffix,
53 | String tagPrefix,
54 | String tagSuffix) {
55 | this.removeData(uniqueId);
56 |
57 | CACHE.put(uniqueId, new CachedNickedPlayerData(
58 | groupName,
59 | chatPrefix,
60 | chatSuffix,
61 | tabPrefix,
62 | tabSuffix,
63 | tagPrefix,
64 | tagSuffix));
65 |
66 | this.mysql.update(
67 | "INSERT INTO `nicked_player_data` VALUES (?, ?, ?, ?, ?, ?, ?, ?)",
68 | uniqueId,
69 | groupName,
70 | chatPrefix,
71 | chatSuffix,
72 | tabPrefix,
73 | tabSuffix,
74 | tagPrefix,
75 | tagSuffix);
76 | }
77 |
78 | public void removeData(UUID uniqueId) {
79 | CACHE.remove(uniqueId);
80 |
81 | this.mysql.update("DELETE FROM `nicked_player_data` WHERE unique_id = ?", uniqueId);
82 | }
83 |
84 | public boolean isRegistered(UUID uniqueId) {
85 | if(CACHE.containsKey(uniqueId))
86 | return true;
87 |
88 | try(ResultSet resultSet = this.mysql.getResult("SELECT * FROM `nicked_player_data` WHERE unique_id = ?", uniqueId)) {
89 | if(resultSet.next()) {
90 | CACHE.put(uniqueId, CachedNickedPlayerData.fromResultSet(resultSet));
91 |
92 | return true;
93 | }
94 | } catch (SQLException ex) {
95 | ex.printStackTrace();
96 | }
97 |
98 | return false;
99 | }
100 |
101 | public void clearCachedData(UUID uniqueId) {
102 | CACHE.remove(uniqueId);
103 | }
104 |
105 | @Data
106 | @AllArgsConstructor
107 | public static class CachedNickedPlayerData {
108 |
109 | private final String groupName, chatPrefix, chatSuffix, tabPrefix, tabSuffix, tagPrefix, tagSuffix;
110 |
111 | public static CachedNickedPlayerData fromResultSet(ResultSet resultSet) throws SQLException {
112 | return new CachedNickedPlayerData(
113 | resultSet.getString("group"),
114 | resultSet.getString("chat_prefix"),
115 | resultSet.getString("chat_suffix"),
116 | resultSet.getString("tab_prefix"),
117 | resultSet.getString("tab_suffix"),
118 | resultSet.getString("tag_prefix"),
119 | resultSet.getString("tag_suffix"));
120 | }
121 |
122 | }
123 |
124 | }
--------------------------------------------------------------------------------
/src/main/java/com/justixdev/eazynick/updater/VersionComparisonResult.java:
--------------------------------------------------------------------------------
1 | package com.justixdev.eazynick.updater;
2 |
3 | public enum VersionComparisonResult {
4 |
5 | UP_TO_DATE,
6 | DEV,
7 | OUTDATED_PRE_RELEASE,
8 | OUTDATED_RELEASE
9 |
10 | }
11 |
--------------------------------------------------------------------------------
/src/main/java/com/justixdev/eazynick/utilities/ActionBarUtils.java:
--------------------------------------------------------------------------------
1 | package com.justixdev.eazynick.utilities;
2 |
3 | import net.md_5.bungee.api.ChatMessageType;
4 | import net.md_5.bungee.api.chat.TextComponent;
5 | import org.bukkit.entity.Player;
6 |
7 | import static com.justixdev.eazynick.nms.ReflectionHelper.*;
8 |
9 | public class ActionBarUtils {
10 |
11 | public void sendActionBar(Player player, String text) {
12 | try {
13 | // Send action bar message
14 | if (NMS_VERSION.startsWith("v1_7") || NMS_VERSION.startsWith("v1_8")) {
15 | sendPacketNMS(
16 | player,
17 | newInstance(
18 | getNMSClass("PacketPlayOutChat"),
19 | types(getNMSClass("IChatBaseComponent"), byte.class),
20 | invokeStatic(
21 | getNMSClass("IChatBaseComponent").getDeclaredClasses()[0],
22 | "a",
23 | types(String.class),
24 | "{\"text\":\"" + text + "\")"),
25 | (byte) 2));
26 | } else
27 | player.spigot().sendMessage(ChatMessageType.ACTION_BAR, TextComponent.fromLegacyText(text));
28 | } catch (Exception ignore) {
29 | }
30 | }
31 |
32 | }
33 |
--------------------------------------------------------------------------------
/src/main/java/com/justixdev/eazynick/utilities/AsyncTask.java:
--------------------------------------------------------------------------------
1 | package com.justixdev.eazynick.utilities;
2 |
3 | import java.util.concurrent.atomic.AtomicBoolean;
4 |
5 | public class AsyncTask {
6 |
7 | private final AsyncRunnable asyncRunnable;
8 | private final long delay, period;
9 | private final AtomicBoolean running;
10 | private Thread thread;
11 |
12 | public AsyncTask(AsyncRunnable asyncRunnable, long delay) {
13 | this(asyncRunnable, delay, -1);
14 | }
15 |
16 | public AsyncTask(AsyncRunnable asyncRunnable, long delay, long period) {
17 | this.asyncRunnable = asyncRunnable;
18 | this.delay = delay;
19 | this.period = period;
20 | this.running = new AtomicBoolean(period >= 0);
21 | }
22 |
23 | public AsyncTask run() {
24 | this.asyncRunnable.prepare(this);
25 |
26 | this.thread = new Thread(() -> {
27 | // Wait 'delay' milliseconds
28 | try {
29 | Thread.sleep(this.delay);
30 | } catch (InterruptedException ignore) {
31 | }
32 |
33 | do {
34 | this.asyncRunnable.run();
35 |
36 | // Check if task should be executed again
37 | if(this.period >= 0) {
38 | // Wait 'period' milliseconds
39 | try {
40 | Thread.sleep(this.period);
41 | } catch (InterruptedException ignore) {
42 | }
43 | }
44 | } while(this.running.get());
45 |
46 | this.thread.interrupt();
47 | });
48 |
49 | this.thread.start();
50 |
51 | return this;
52 | }
53 |
54 | public void cancel() {
55 | this.running.set(false);
56 | }
57 |
58 | public static abstract class AsyncRunnable {
59 |
60 | private AsyncTask asyncTask;
61 |
62 | public void prepare(AsyncTask asyncTask) {
63 | this.asyncTask = asyncTask;
64 | }
65 |
66 | public abstract void run();
67 |
68 | public void cancel() {
69 | if(this.asyncTask != null)
70 | this.asyncTask.cancel();
71 | else
72 | throw new UnsupportedOperationException("Not running");
73 | }
74 |
75 | }
76 |
77 | }
78 |
--------------------------------------------------------------------------------
/src/main/java/com/justixdev/eazynick/utilities/ClassFinder.java:
--------------------------------------------------------------------------------
1 | package com.justixdev.eazynick.utilities;
2 |
3 | import com.justixdev.eazynick.EazyNick;
4 |
5 | import java.lang.annotation.Annotation;
6 | import java.lang.reflect.InvocationTargetException;
7 | import java.util.Collections;
8 | import java.util.List;
9 | import java.util.Objects;
10 | import java.util.Set;
11 | import java.util.stream.Collectors;
12 |
13 | import static com.justixdev.eazynick.nms.ReflectionHelper.*;
14 |
15 | public class ClassFinder {
16 |
17 | public static List> withAnnotation(String packageName, Class extends Annotation> annotaionClass) {
18 | return allInPackage(packageName)
19 | .stream()
20 | .filter(clazz -> clazz.isAnnotationPresent(annotaionClass))
21 | .collect(Collectors.toList());
22 | }
23 |
24 | @SuppressWarnings("unchecked")
25 | public static List> allInPackage(String packageName) {
26 | try {
27 | ClassLoader classLoader = EazyNick.getInstance().getPluginClassLoader();
28 |
29 | return
30 | ((Set