├── .github
├── ISSUE_TEMPLATE
│ ├── bug_report.yml
│ ├── bug_report_cn.yml
│ └── feature_request.md
└── workflows
│ ├── codeql-analysis.yml
│ └── gradle-builder.yml
├── .gitignore
├── LICENSE
├── README.md
├── Version Infos.json
├── Version_Info.json
├── build.gradle.kts
├── bukkit
├── build.gradle.kts
├── nms
│ ├── build.gradle.kts
│ ├── common
│ │ ├── build.gradle.kts
│ │ ├── generic_v1_19_3
│ │ │ ├── build.gradle.kts
│ │ │ └── src
│ │ │ │ └── main
│ │ │ │ └── kotlin
│ │ │ │ └── io
│ │ │ │ └── github
│ │ │ │ └── rothes
│ │ │ │ └── protocolstringreplacer
│ │ │ │ └── nms
│ │ │ │ └── generic
│ │ │ │ └── packetreader
│ │ │ │ ├── BlockEntityTypeGetter.kt
│ │ │ │ ├── MenuTypeGetter.kt
│ │ │ │ └── PacketReader.kt
│ │ ├── generic_v1_21
│ │ │ ├── build.gradle.kts
│ │ │ └── src
│ │ │ │ └── main
│ │ │ │ └── kotlin
│ │ │ │ └── io
│ │ │ │ └── github
│ │ │ │ └── rothes
│ │ │ │ └── protocolstringreplacer
│ │ │ │ └── nms
│ │ │ │ └── generic
│ │ │ │ └── packetreader
│ │ │ │ ├── BlockEntityTypeGetter.kt
│ │ │ │ ├── DisguisedPacketHandler.kt
│ │ │ │ ├── MenuTypeGetter.kt
│ │ │ │ └── PacketReader.kt
│ │ ├── generic_v1_21_3
│ │ │ ├── build.gradle.kts
│ │ │ └── src
│ │ │ │ └── main
│ │ │ │ └── kotlin
│ │ │ │ └── io
│ │ │ │ └── github
│ │ │ │ └── rothes
│ │ │ │ └── protocolstringreplacer
│ │ │ │ └── nms
│ │ │ │ └── generic
│ │ │ │ └── packetreader
│ │ │ │ ├── BlockEntityTypeGetter.kt
│ │ │ │ ├── DisguisedPacketHandler.kt
│ │ │ │ ├── MenuTypeGetter.kt
│ │ │ │ └── PacketReader.kt
│ │ └── src
│ │ │ └── main
│ │ │ ├── java
│ │ │ └── io
│ │ │ │ └── github
│ │ │ │ └── rothes
│ │ │ │ └── protocolstringreplacer
│ │ │ │ └── nms
│ │ │ │ └── packetreader
│ │ │ │ ├── ChatType.java
│ │ │ │ ├── IBlockEntityTypeGetter.java
│ │ │ │ ├── IMenuTypeGetter.java
│ │ │ │ └── IPacketReader.java
│ │ │ └── kotlin
│ │ │ └── io
│ │ │ └── github
│ │ │ └── rothes
│ │ │ └── protocolstringreplacer
│ │ │ └── nms
│ │ │ └── packetreader
│ │ │ └── IDisguisedPacketHandler.kt
│ ├── src
│ │ └── main
│ │ │ └── kotlin
│ │ │ └── io
│ │ │ └── github
│ │ │ └── rothes
│ │ │ └── protocolstringreplacer
│ │ │ └── nms
│ │ │ └── NmsManager.kt
│ ├── v1_19_1
│ │ ├── build.gradle.kts
│ │ └── src
│ │ │ └── main
│ │ │ └── kotlin
│ │ │ └── io
│ │ │ └── github
│ │ │ └── rothes
│ │ │ └── protocolstringreplacer
│ │ │ └── nms
│ │ │ └── v1_19_1
│ │ │ └── packetreader
│ │ │ └── PacketReader.kt
│ ├── v1_19_2
│ │ ├── build.gradle.kts
│ │ └── src
│ │ │ └── main
│ │ │ └── kotlin
│ │ │ └── io
│ │ │ └── github
│ │ │ └── rothes
│ │ │ └── protocolstringreplacer
│ │ │ └── nms
│ │ │ └── v1_19_2
│ │ │ └── packetreader
│ │ │ └── PacketReader.kt
│ ├── v1_19_3
│ │ └── build.gradle.kts
│ ├── v1_19_4
│ │ └── build.gradle.kts
│ ├── v1_20_1
│ │ └── build.gradle.kts
│ ├── v1_20_2
│ │ └── build.gradle.kts
│ ├── v1_20_4
│ │ └── build.gradle.kts
│ ├── v1_20_6
│ │ ├── build.gradle.kts
│ │ └── src
│ │ │ └── main
│ │ │ └── kotlin
│ │ │ └── io
│ │ │ └── github
│ │ │ └── rothes
│ │ │ └── protocolstringreplacer
│ │ │ └── nms
│ │ │ └── v1_20_6
│ │ │ └── packetreader
│ │ │ ├── BlockEntityTypeGetter.kt
│ │ │ ├── DisguisedPacketHandler.kt
│ │ │ ├── MenuTypeGetter.kt
│ │ │ └── PacketReader.kt
│ ├── v1_21_1
│ │ └── build.gradle.kts
│ ├── v1_21_3
│ │ └── build.gradle.kts
│ ├── v1_21_4
│ │ └── build.gradle.kts
│ └── v1_21_5
│ │ └── build.gradle.kts
└── src
│ └── main
│ ├── java
│ ├── com
│ │ └── sk89q
│ │ │ └── protocolstringreplacer
│ │ │ └── PsrDisguisePlugin.java
│ └── io
│ │ └── github
│ │ └── rothes
│ │ └── protocolstringreplacer
│ │ ├── ConfigManager.java
│ │ ├── ProtocolStringReplacer.java
│ │ ├── PsrLocalization.java
│ │ ├── Updater.java
│ │ ├── api
│ │ ├── capture
│ │ │ ├── CaptureInfo.java
│ │ │ └── CaptureInfoImpl.java
│ │ ├── configuration
│ │ │ ├── CommentYamlConfiguration.java
│ │ │ └── DotYamlConfiguration.java
│ │ ├── exceptions
│ │ │ ├── IncompatibleServerException.java
│ │ │ ├── JsonSyntaxException.java
│ │ │ └── MissingInitialResourceException.java
│ │ ├── replacer
│ │ │ └── ReplacerConfig.java
│ │ └── user
│ │ │ ├── PsrUser.java
│ │ │ └── PsrUserManager.java
│ │ ├── command
│ │ ├── CommandHandler.java
│ │ ├── SubCommand.java
│ │ └── subcommands
│ │ │ ├── Capture.java
│ │ │ ├── Edit.java
│ │ │ ├── Parse.java
│ │ │ ├── Reload.java
│ │ │ └── editchildren
│ │ │ ├── Block.java
│ │ │ ├── File.java
│ │ │ └── Replace.java
│ │ ├── console
│ │ ├── ConsoleReplaceManager.java
│ │ ├── PsrFilter.java
│ │ ├── PsrJndiLookup.java
│ │ ├── PsrLogEventPatternConverter.java
│ │ ├── PsrMessage.java
│ │ ├── PsrMessageFactory.java
│ │ └── PsrWrappedLineReader.java
│ │ ├── events
│ │ └── PsrReloadEvent.java
│ │ ├── listeners
│ │ ├── PlayerJoinListener.java
│ │ ├── PlayerQuitListener.java
│ │ └── PsrInternalListeners.java
│ │ ├── packetlistener
│ │ ├── BasePacketListener.java
│ │ ├── PacketListenerManager.java
│ │ ├── client
│ │ │ ├── BaseClientPacketListener.java
│ │ │ ├── CloseWindow.java
│ │ │ ├── SettingsLocale.java
│ │ │ ├── SettingsLocaleUpper20.java
│ │ │ └── itemstack
│ │ │ │ ├── BaseClientItemPacketListener.java
│ │ │ │ ├── SetCreativeSlot.java
│ │ │ │ └── WindowClick.java
│ │ └── server
│ │ │ ├── BaseServerComponentsPacketListener.java
│ │ │ ├── BaseServerPacketListener.java
│ │ │ ├── EntityMetadata.java
│ │ │ ├── KickDisconnect.java
│ │ │ ├── OpenWindow.java
│ │ │ ├── actionbar
│ │ │ ├── ChatActionBar.java
│ │ │ ├── SetActionBar.java
│ │ │ ├── SystemChatActionBar.java
│ │ │ └── TitleActionBar.java
│ │ │ ├── bossbar
│ │ │ ├── BossBar.java
│ │ │ └── BossBarPost17.java
│ │ │ ├── chat
│ │ │ ├── Chat.java
│ │ │ ├── ChatPreview.java
│ │ │ ├── DisguisedChat.java
│ │ │ ├── PlayerChatHelper.java
│ │ │ ├── SystemChat.java
│ │ │ └── TabComplete.java
│ │ │ ├── combat
│ │ │ ├── CombatEvent.java
│ │ │ └── PlayerCombatKill.java
│ │ │ ├── itemstack
│ │ │ ├── BaseServerItemPacketListener.java
│ │ │ └── SetSlot.java
│ │ │ ├── scoreboard
│ │ │ ├── BaseScoreBoardListener.java
│ │ │ ├── BaseUpdateTeamListener.java
│ │ │ ├── ScoreBoardObjective.java
│ │ │ ├── UpdateScore.java
│ │ │ ├── UpdateTeam.java
│ │ │ ├── UpdateTeamPost13.java
│ │ │ └── UpdateTeamPost17.java
│ │ │ ├── sign
│ │ │ ├── BaseServerSignPacketListener.java
│ │ │ ├── MapChunk.java
│ │ │ ├── TileEntityData.java
│ │ │ ├── TileEntityDataPost18.java
│ │ │ └── UpdateSign.java
│ │ │ └── title
│ │ │ ├── BaseTitleListener.java
│ │ │ ├── SetSubtitleText.java
│ │ │ ├── SetTitleText.java
│ │ │ └── Title.java
│ │ ├── replacer
│ │ ├── FileReplacerConfig.java
│ │ ├── ListenType.java
│ │ ├── MatchMode.java
│ │ ├── PAPIReplacer.java
│ │ ├── ReplaceMode.java
│ │ ├── ReplacerManager.java
│ │ ├── containers
│ │ │ ├── AbstractContainer.java
│ │ │ ├── ChatJsonContainer.java
│ │ │ ├── ComponentContainer.java
│ │ │ ├── ComponentsContainer.java
│ │ │ ├── Container.java
│ │ │ ├── EntityContentContainer.java
│ │ │ ├── HoverContentContainer.java
│ │ │ ├── HoverEventContainer.java
│ │ │ ├── ItemContentContainer.java
│ │ │ ├── Replaceable.java
│ │ │ ├── SignNbtContainer.java
│ │ │ ├── SimpleTextContainer.java
│ │ │ └── TextContentContainer.java
│ │ └── helpers
│ │ │ └── ItemHelper.java
│ │ ├── upgrade
│ │ ├── AbstractUpgradeHandler.java
│ │ ├── DotConfigUpgradeHandler.java
│ │ ├── UpgradeEnum.java
│ │ ├── UpgradeHandler1To2.java
│ │ ├── UpgradeHandler2To3.java
│ │ ├── UpgradeHandler3To4.java
│ │ ├── UpgradeHandler4To5.java
│ │ └── UpgradeHandler5To6.java
│ │ └── util
│ │ ├── ArgUtils.java
│ │ ├── ColorUtils.java
│ │ ├── FileUtils.java
│ │ ├── MessageUtils.java
│ │ ├── PaperUtils.java
│ │ ├── SpigotUtils.java
│ │ └── scheduler
│ │ ├── PsrScheduler.java
│ │ └── PsrTask.java
│ ├── kotlin
│ └── io
│ │ └── github
│ │ └── rothes
│ │ └── protocolstringreplacer
│ │ ├── InternalExtensions.kt
│ │ ├── InternalFunctions.kt
│ │ ├── command
│ │ └── subcommands
│ │ │ └── About.kt
│ │ ├── packetlistener
│ │ └── server
│ │ │ ├── chat
│ │ │ ├── DisguisedChatPost21.kt
│ │ │ └── TabCompletePost20_5.kt
│ │ │ ├── itemstack
│ │ │ ├── MerchantTradeList.kt
│ │ │ ├── WindowItems.kt
│ │ │ └── WindowItemsPost11.kt
│ │ │ └── sign
│ │ │ ├── MapChunkPost18.kt
│ │ │ └── TileTypeHelper.kt
│ │ └── replacer
│ │ └── containers
│ │ └── ItemStackContainer.kt
│ └── resources
│ ├── Languages
│ ├── Global
│ │ └── ExampleReplacers
│ │ │ └── Slimefun
│ │ │ └── Translation_CN
│ │ │ ├── Chat
│ │ │ └── Text_Contain.yml
│ │ │ ├── Console
│ │ │ ├── Regex.yml
│ │ │ └── Text_Contain.yml
│ │ │ ├── Entity
│ │ │ └── Cargo 货运.yml
│ │ │ ├── Interfaces
│ │ │ ├── Machine Interfaces
│ │ │ │ ├── Android 可编程式机器人.yml
│ │ │ │ ├── Auto-Crafter 自动合成器.yml
│ │ │ │ └── Cargo 货运.yml
│ │ │ └── Window-Title.yml
│ │ │ └── ItemStack
│ │ │ ├── Regex.yml
│ │ │ └── Text_Contain.yml
│ ├── en-US
│ │ ├── Configs
│ │ │ └── Config.yml
│ │ ├── ExampleReplacers
│ │ │ ├── ReadMe.md
│ │ │ └── Slimefun
│ │ │ │ └── Translation_CN
│ │ │ │ └── ReadMe.md
│ │ ├── Example_Replacers.txt
│ │ ├── Locales
│ │ │ └── Locale.yml
│ │ └── Replacers
│ │ │ ├── ConsoleColor.yml
│ │ │ └── Example.yml
│ └── zh-CN
│ │ ├── Configs
│ │ └── Config.yml
│ │ ├── ExampleReplacers
│ │ ├── ReadMe.md
│ │ └── Slimefun
│ │ │ └── Translation_CN
│ │ │ └── ReadMe.md
│ │ ├── Example_Replacers.txt
│ │ ├── Locales
│ │ └── Locale.yml
│ │ └── Replacers
│ │ ├── ConsoleColor.yml
│ │ └── Example.yml
│ ├── metadata.yml
│ └── plugin.yml
├── gradle.properties
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
├── jitpack.yml
└── settings.gradle.kts
/.github/ISSUE_TEMPLATE/bug_report_cn.yml:
--------------------------------------------------------------------------------
1 | name: Bug Report | 错误报告
2 | description: 报告错误或议题 [中文|Chinese]
3 | title: "[Bug] "
4 | labels: [🐞 Unconfirmed bug]
5 | assignees:
6 | - Rothes
7 |
8 | body:
9 | - type: markdown
10 | attributes:
11 | value: |
12 | ## 欢迎来到 ProtocolStringReplacer 问题追踪器
13 | 如果您需要帮助, 可以加入我们的 [Discord 服务器](https://discord.gg/zwzzkmYCBb) 或 [QQ群](https://qm.qq.com/cgi-bin/qm/qr?k=mDtcrvBGzqbA05mPLzBnPAYXm5lskYxg&jump_from=webapi).
14 | 感谢您愿意花费一些时间来帮助我们填写这个错误报告.
15 |
16 | - id: checklist
17 | type: checkboxes
18 | attributes:
19 | label: '检查清单'
20 | description: 在创建问题之前,请先检查此清单.
21 | options:
22 | - label: 我已经尝试过了最新开发版本的 ProtocolLib.
23 | - label: 我正在使用最新的官方 PSR.
24 | required: true
25 | - label: 我搜寻了类似的未关闭议题, 但没有找到任何有关的错误报告。
26 | required: true
27 |
28 | - id: description
29 | type: textarea
30 | validations:
31 | required: true
32 | attributes:
33 | label: '描述'
34 | description: |
35 | 清楚、详细地描述您遇到的错误是什么.
36 | 您提供的信息越多, 我们就越容易处理这个问题.
37 | placeholder: |
38 | 当我在做 [...] 时, 我遇到了 [...].
39 |
40 | - id: reproduction-steps
41 | type: textarea
42 | validations:
43 | required: true
44 | attributes:
45 | label: '重现步骤'
46 | description: |
47 | 重现此问题的完整步骤.
48 | 您描述地越清晰, 我们就越容易复现这个问题.
49 | placeholder: |
50 | 1. 先做 [...]
51 | 2. 再做 [...]
52 | 3. 错误 [...] 发生了
53 |
54 | - id: expected-behaviour
55 | type: textarea
56 | validations:
57 | required: true
58 | attributes:
59 | label: '预期行为'
60 | description: |
61 | 您认为怎么样才是正确、预期的行为?
62 | placeholder: |
63 | 我希望它能够 [...].
64 |
65 | - id: stacktrace
66 | type: input
67 | attributes:
68 | label: '堆栈轨迹'
69 | description: |
70 | 检查您的服务端日志, 搜索任何来自 ProtocolStringReplacer 的警告及错误信息.
71 | 如果您不确定, 请发送您的完整日志.
72 | placeholder: https://pastebin.com/...
73 |
74 | - id: server-software
75 | type: input
76 | validations:
77 | required: true
78 | attributes:
79 | label: '服务端版本'
80 | description: |
81 | 请输入您使用的服务端, 包括版本号.
82 | 执行 /about 指令并粘贴其输出.
83 | placeholder: 'git-Purpur-1894 (MC: 1.19.3)*'
84 |
85 | - id: psr-version
86 | type: input
87 | validations:
88 | required: true
89 | attributes:
90 | label: 'ProtocolStringReplacer 版本'
91 | description: |
92 | **"最新" 不是版本号, 我们需要的是一个确切的版本号.**
93 | 请输入 ProtocolStringReplacer 的版本号.
94 | placeholder: '2.17.3'
95 |
96 | - id: protocollib-version
97 | type: input
98 | validations:
99 | required: true
100 | attributes:
101 | label: 'ProtocolLib 版本'
102 | description: |
103 | 执行 /protocol version 指令并粘贴其输出.
104 | placeholder: 'v5.0.0-SNAPSHOT-b612'
105 |
106 | - id: other-versions
107 | type: textarea
108 | attributes:
109 | label: '其它插件'
110 | description: |
111 | 如果您的议题与其它插件有关系, 请在此处填写.
112 | placeholder: MyPluginA v1.0, MyPluginB v1.1 ...
113 |
114 | - id: additional-context
115 | type: textarea
116 | attributes:
117 | label: '额外内容'
118 | description: |
119 | 您可以在此处添加有关本议题的补充.
120 | placeholder: |
121 | 截图, 视频, 系统版本, 以及其它的更多信息...
122 |
123 | - type: markdown
124 | attributes:
125 | value: |
126 | ## 非常感谢您能够提交此错误报告!
127 | 如果您之后发现了任何有助于解决此议题的其他信息, 请立即在此议题下回复!
128 | 任何更多信息都有助于我们解决此议题!
129 |
--------------------------------------------------------------------------------
/.github/ISSUE_TEMPLATE/feature_request.md:
--------------------------------------------------------------------------------
1 | ---
2 | name: Feature request
3 | about: Suggest an idea for this project
4 | title: ''
5 | labels: ''
6 | assignees: Rothes
7 |
8 | ---
9 |
10 | **Is your feature request related to a problem? Please describe.**
11 | A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
12 |
13 | **Describe the solution you'd like**
14 | A clear and concise description of what you want to happen.
15 |
16 | **Describe alternatives you've considered**
17 | A clear and concise description of any alternative solutions or features you've considered.
18 |
19 | **Additional context**
20 | Add any other context or screenshots about the feature request here.
21 |
--------------------------------------------------------------------------------
/.github/workflows/codeql-analysis.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 | branches: [ master, '3.0.0-dev' ]
17 | pull_request:
18 | # The branches below must be a subset of the branches above
19 | branches: [ master, '3.0.0-dev' ]
20 | schedule:
21 | - cron: '26 10 * * 4'
22 |
23 | jobs:
24 | analyze:
25 | name: Analyze
26 | runs-on: ubuntu-latest
27 | permissions:
28 | actions: read
29 | contents: read
30 | security-events: write
31 |
32 | strategy:
33 | fail-fast: false
34 | matrix:
35 | language: [ 'java' ]
36 | # CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python', 'ruby' ]
37 | # Learn more about CodeQL language support at https://git.io/codeql-language-support
38 |
39 | steps:
40 | - name: Checkout repository
41 | uses: actions/checkout@v2
42 | - name: Setup Java JDK
43 | uses: actions/setup-java@v2.4.0
44 | with:
45 | distribution: zulu
46 | java-version: 17
47 | - name: Initialize CodeQL
48 | uses: github/codeql-action/init@v1
49 | with:
50 | languages: ${{ matrix.language }}
51 | # If you wish to specify custom queries, you can do so here or in a config file.
52 | # By default, queries listed here will override any specified in a config file.
53 | # Prefix the list here with "+" to use these queries and those in the config file.
54 | # queries: ./path/to/local/query, your-org/your-repo/queries@main
55 |
56 | # Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
57 | # If this step fails, then you should remove it and run the build manually (see below)
58 | - name: Autobuild
59 | uses: github/codeql-action/autobuild@v1
60 |
61 | # ℹ️ Command-line programs to run using the OS shell.
62 | # 📚 https://git.io/JvXDl
63 |
64 | # ✏️ If the Autobuild fails above, remove it and uncomment the following three lines
65 | # and modify them (or add more) to build your code if your project
66 | # uses a compiled language
67 |
68 | #- run: |
69 | # make bootstrap
70 | # make release
71 |
72 | - name: Perform CodeQL Analysis
73 | uses: github/codeql-action/analyze@v1
74 |
--------------------------------------------------------------------------------
/.github/workflows/gradle-builder.yml:
--------------------------------------------------------------------------------
1 | name: ProtocolStringReplacer Snapshot Builder
2 |
3 | on: [push]
4 |
5 | jobs:
6 | build:
7 | runs-on: ubuntu-latest
8 |
9 | steps:
10 | - uses: actions/checkout@v3
11 |
12 | - name: Set up JDK 21
13 | uses: actions/setup-java@v3
14 | with:
15 | java-version: '21'
16 | distribution: 'temurin'
17 |
18 | - name: Make gradlew executable
19 | run: chmod +x ./gradlew
20 |
21 | - name: Setup Gradle
22 | uses: gradle/gradle-build-action@v3
23 | with:
24 | gradle-version: 8.6
25 |
26 | - name: Execute Gradle build
27 | run: ./gradlew createJars
28 |
29 | - run: mkdir ProtocolStringReplacer && cp build/allJars/*.jar ProtocolStringReplacer
30 |
31 | - uses: actions/upload-artifact@v4
32 | with:
33 | name: ProtocolStringReplacer-Snapshot
34 | path: ProtocolStringReplacer
35 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | .gradle
2 |
3 | # Numerous always-ignore extensions
4 | *.diff
5 | *.err
6 | *.orig
7 | *.log
8 | *.rej
9 | *.swo
10 | *.swp
11 | *.vi
12 | *~
13 | # OS or Editor folders
14 | .DS_Store
15 | .cache
16 | .project
17 | .settings
18 | .tmproj
19 | nbproject
20 | Thumbs.db
21 |
22 | # Dreamweaver added files
23 | _notes
24 | dwsync.xml
25 |
26 | # Komodo
27 | *.komodoproject
28 | .komodotools
29 |
30 | # Folders to ignore
31 | .hg
32 | .svn
33 | .CVS
34 | intermediate
35 | publish
36 | .idea
37 |
38 |
39 | # Eclipse stuff
40 | .classpath
41 | build.xml
42 | target
43 |
44 | # various other potential build files
45 | build
46 | bin
47 | dist
48 | manifest.mf
49 |
50 | # Mac filesystem dust
51 |
52 |
53 | *.iml
54 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # ProtocolStringReplacer
2 |
3 | [](https://app.codacy.com/gh/Rothes/ProtocolStringReplacer?utm_source=github.com&utm_medium=referral&utm_content=Rothes/ProtocolStringReplacer&utm_campaign=Badge_Grade_Settings)
4 |
5 | A Spigot plugin for Minecraft 1.8 - 1.21.1 that gives you the ability to edit the strings/components in packet sends to players.
6 |
7 | Please visit [SpigotMC](#links) or [MCBBS](#links) for a detailed description.
8 |
9 | ## Download
10 | For stable releases, go SpigotMC or MCBBS. Also, we create a tag for each published version on GitHub. You can compile it yourself.
11 | For development builds, you can download on GitHub Actions.
12 |
13 | ## Support
14 | We provide support on our [Discord Server](https://discord.gg/zwzzkmYCBb), and [Tencent QQ group](https://qm.qq.com/cgi-bin/qm/qr?k=mDtcrvBGzqbA05mPLzBnPAYXm5lskYxg&jump_from=webapi).
15 | If you are going to open a ticket, you may ask for help first.
16 |
17 | ## Contribute
18 | We accept pull requests, feel free to contribute.
19 | But please discuss the changes with us first unless it's a minor fix,
20 | so we can let you know if we are willing to merge it and give you some suggestions.
21 |
22 | ## Related Links
23 |
24 | * **Wiki**:
25 | [https://rothes.gitbook.io/protocolstringreplacer](https://rothes.gitbook.io/protocolstringreplacer)
26 |
27 | * **MCBBS** (Down) :
28 | [https://www.mcbbs.net/thread-1209429-1-1.html](https://www.mcbbs.net/thread-1209429-1-1.html)
29 |
30 | * **SpigotMC**:
31 | [https://www.spigotmc.org/resources/protocolstringreplacer.96573](https://www.spigotmc.org/resources/protocolstringreplacer.96573/)
32 |
33 | * **bStats**:
34 | [https://bstats.org/plugin/bukkit/ProtocolStringReplacer/11740](https://bstats.org/plugin/bukkit/ProtocolStringReplacer/11740)
35 | 
36 |
37 | ## License
38 | ProtocolStringReplacer is licensed under GNU General Public License v3.0. Please see LICENSE for the full license.
39 |
--------------------------------------------------------------------------------
/Version Infos.json:
--------------------------------------------------------------------------------
1 | {
2 | "Version_Channels": {
3 | "Stable": {
4 | "Latest_Version_Number": 999,
5 | "Log_Level": "Info",
6 | "Actions": [],
7 | "Message": {
8 | "en-US": "§bA new version of PSR is available! You are really out of dated!\n§bDownload here: https://www.spigotmc.org/resources/protocolstringreplacer.96573/"
9 | }
10 | }
11 | },
12 | "Version_Actions": {
13 | "0-999": {
14 | "Log_Level": "Info",
15 | "Actions": [],
16 | "Message_Times": 1,
17 | "Notify_In_Game": false,
18 | "Message": {
19 | "en-US": "§bEnjoy PSR? Join our Discord: https://discord.gg/zwzzkmYCBb",
20 | "zh-CN": "§b喜欢PSR吗? 欢迎加入我们的 QQ群: 422532220 !"
21 | }
22 | },
23 | "0-45": {
24 | "Log_Level": "Error",
25 | "Actions": ["Prohibit"],
26 | "Message_Times": 1,
27 | "Message": {
28 | "en-US": "§cThe version of PSR you are running has been prohibited by the server. This is usually due to a serious problem. Please update the plugin.",
29 | "zh-CN": "§c您使用的版本已被远程服务器禁止. 这通常是因为该版本存在重大问题. 请更新插件."
30 | }
31 | }
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/Version_Info.json:
--------------------------------------------------------------------------------
1 | {
2 | "Version_Channels": {
3 | "Stable": {
4 | "Latest_Version_Number": 126,
5 | "Log_Level": "Info",
6 | "Actions": [],
7 | "Message": {
8 | "en-US": "§bA new version of PSR (\"3.1.2\") is available!\n§bDownload here: https://www.spigotmc.org/resources/96573/"
9 | }
10 | }
11 | },
12 | "Version_Actions": {
13 | "0-999": {
14 | "Log_Level": "Info",
15 | "Actions": [],
16 | "Message_Times": 1,
17 | "Notify_In_Game": false,
18 | "Message": {
19 | "en-US": "§bEnjoy PSR? Join our Discord: https://discord.gg/zwzzkmYCBb",
20 | "zh-CN": "§b喜欢PSR吗? 欢迎加入我们的 QQ群: 422532220 !"
21 | }
22 | },
23 | "0-45": {
24 | "Log_Level": "Error",
25 | "Actions": ["Prohibit"],
26 | "Message_Times": 1,
27 | "Message": {
28 | "en-US": "§cThe version of PSR you are running has been prohibited by the server. This is usually due to a serious problem. Please update the plugin.",
29 | "zh-CN": "§c您使用的版本已被远程服务器禁止. 这通常是因为该版本存在重大问题. 请更新插件."
30 | }
31 | }
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/build.gradle.kts:
--------------------------------------------------------------------------------
1 | plugins {
2 | kotlin("jvm") version "1.9.22"
3 | id("java")
4 | id("io.github.goooler.shadow") version "8.1.8"
5 | id("io.papermc.paperweight.userdev") version "2.0.0-beta.11" apply false
6 | }
7 |
8 | repositories {
9 | mavenCentral()
10 | }
11 |
12 | group = "io.github.rothes"
13 | version = rootProject.property("versionName").toString()
14 |
15 | tasks.register("createJars") {
16 | from(project(":bukkit").tasks.named("reobfJar"))
17 | into("$buildDir/allJars")
18 | }
19 |
20 |
21 | allprojects {
22 | apply(plugin = "java")
23 | apply(plugin = "kotlin")
24 | apply(plugin = "io.github.goooler.shadow")
25 |
26 | group = "io.github.rothes.protocolstringreplacer"
27 | version = rootProject.property("versionName").toString()
28 |
29 | val javaVer = JavaVersion.VERSION_1_8
30 |
31 | java {
32 | disableAutoTargetJvm()
33 | sourceCompatibility = javaVer
34 | targetCompatibility = javaVer
35 | withSourcesJar()
36 | withJavadocJar()
37 | }
38 |
39 | tasks.compileJava {
40 | options.encoding = "UTF-8"
41 | sourceCompatibility = javaVer.toString()
42 | targetCompatibility = javaVer.toString()
43 | }
44 |
45 | tasks.compileKotlin {
46 | kotlinOptions {
47 | jvmTarget = javaVer.toString()
48 | }
49 | }
50 |
51 | tasks.javadoc {
52 | options.encoding = "UTF-8"
53 | }
54 | }
--------------------------------------------------------------------------------
/bukkit/build.gradle.kts:
--------------------------------------------------------------------------------
1 | import org.apache.tools.ant.filters.ReplaceTokens
2 |
3 | plugins {
4 | kotlin("jvm") version "1.9.22"
5 | id("java")
6 | id("io.github.goooler.shadow") version "8.1.8"
7 | id("io.papermc.paperweight.userdev") version "2.0.0-beta.11"
8 | }
9 |
10 | val serverVer = rootProject.property("targetMinecraftVersion").toString()
11 |
12 | dependencies {
13 | implementation(project(":bukkit:nms"))
14 | paperweight.paperDevBundle("$serverVer-R0.1-SNAPSHOT")
15 | implementation("commons-collections:commons-collections:3.2.2")
16 | implementation("org.neosearch.stringsearcher:multiple-string-searcher:0.1.1")
17 | implementation("de.tr7zw:item-nbt-api:2.15.0")
18 | implementation("org.bstats:bstats-bukkit:3.0.2")
19 | compileOnly("com.comphenix.protocol:ProtocolLib:5.3.0")
20 | compileOnly("me.clip:placeholderapi:2.11.6")
21 | compileOnly("org.apache.logging.log4j:log4j-api:2.23.1")
22 | compileOnly("org.apache.logging.log4j:log4j-core:2.23.1")
23 | compileOnly("org.jline:jline-reader:3.26.2")
24 | compileOnly("net.minecrell:terminalconsoleappender:1.3.0")
25 | compileOnly("com.mojang:brigadier:1.0.18")
26 | compileOnly("commons-lang:commons-lang:2.6")
27 | }
28 |
29 | val fileName = "${rootProject.name}-${project.name}"
30 | base.archivesName = fileName
31 |
32 | tasks {
33 | shadowJar {
34 | archiveFileName = "${fileName}-${project.version}-mojmap.jar"
35 |
36 | relocate("org.bstats", "io.github.rothes.protocolstringreplacer.lib.org.bstats")
37 | relocate("org.apache.commons.collections", "io.github.rothes.protocolstringreplacer.lib.org.apache.commons.collections")
38 | relocate("org.neosearch.stringsearcher", "io.github.rothes.protocolstringreplacer.lib.org.neosearch.stringsearcher")
39 | relocate("de.tr7zw.changeme.nbtapi", "io.github.rothes.protocolstringreplacer.lib.de.tr7zw.changeme.nbtapi")
40 | relocate("kotlin", "io.github.rothes.protocolstringreplacer.lib.kotlin")
41 | }
42 |
43 | processResources {
44 | filter(
45 | "tokens" to mapOf(
46 | "versionName" to project.property("versionName"),
47 | "versionChannel" to project.property("versionChannel"),
48 | "versionId" to project.property("versionId"),
49 | ))
50 | outputs.doNotCacheIf("MakeReplacementsWork") { true }
51 | }
52 | }
53 |
54 | tasks {
55 | build {
56 | dependsOn(reobfJar)
57 | }
58 |
59 | reobfJar {
60 | mustRunAfter(shadowJar)
61 | }
62 | }
63 |
64 | paperweight.reobfArtifactConfiguration = io.papermc.paperweight.userdev.ReobfArtifactConfiguration.REOBF_PRODUCTION
65 |
66 | allprojects {
67 | repositories {
68 | mavenLocal()
69 | mavenCentral()
70 |
71 | maven("https://hub.spigotmc.org/nexus/content/repositories/snapshots/")
72 | maven("https://repo.papermc.io/repository/maven-public/")
73 | maven("https://repo.papermc.io/repository/maven-snapshots/")
74 | maven("https://repo.dmulloy2.net/repository/public/")
75 | maven("https://repo.extendedclip.com/content/repositories/placeholderapi/")
76 | maven("https://repo.codemc.org/repository/maven-public/")
77 | maven("https://jitpack.io/")
78 | maven("https://libraries.minecraft.net/")
79 | }
80 |
81 | tasks.shadowJar {
82 | dependencies {
83 | exclude(dependency("org.jetbrains:annotations"))
84 | }
85 | }
86 | }
--------------------------------------------------------------------------------
/bukkit/nms/build.gradle.kts:
--------------------------------------------------------------------------------
1 | plugins {
2 | kotlin("jvm") version "1.9.22"
3 | id("java")
4 | id("io.github.goooler.shadow") version "8.1.8"
5 | id("io.papermc.paperweight.userdev") version "2.0.0-beta.11"
6 | }
7 |
8 | val serverVer = rootProject.property("targetMinecraftVersion").toString()
9 |
10 | dependencies {
11 | paperweight.paperDevBundle("$serverVer-R0.1-SNAPSHOT")
12 | subprojects.filter {
13 | it.parent == project
14 | }.forEach {
15 | api(project(it.path, configuration = "reobf"))
16 | }
17 | }
18 |
19 | subprojects {
20 | apply(plugin = "io.papermc.paperweight.userdev")
21 | if (this.name != "common") {
22 | dependencies {
23 | compileOnly(project(":bukkit:nms:common"))
24 | }
25 | }
26 |
27 | tasks.shadowJar {
28 | relocate(
29 | "io.github.rothes.protocolstringreplacer.nms.generic",
30 | "io.github.rothes.protocolstringreplacer.nms.${project.name}"
31 | )
32 | }
33 | }
34 |
35 | allprojects {
36 | tasks {
37 | build {
38 | dependsOn(reobfJar)
39 | }
40 |
41 | reobfJar {
42 | mustRunAfter(shadowJar)
43 | }
44 | }
45 |
46 | paperweight.reobfArtifactConfiguration = io.papermc.paperweight.userdev.ReobfArtifactConfiguration.REOBF_PRODUCTION
47 | }
--------------------------------------------------------------------------------
/bukkit/nms/common/build.gradle.kts:
--------------------------------------------------------------------------------
1 | val serverVer = rootProject.property("targetMinecraftVersion").toString()
2 |
3 | dependencies {
4 | paperweight.paperDevBundle("$serverVer-R0.1-SNAPSHOT")
5 | }
--------------------------------------------------------------------------------
/bukkit/nms/common/generic_v1_19_3/build.gradle.kts:
--------------------------------------------------------------------------------
1 | val serverVer = "1.19.3"
2 |
3 | dependencies {
4 | paperweight.paperDevBundle("$serverVer-R0.1-SNAPSHOT")
5 | }
--------------------------------------------------------------------------------
/bukkit/nms/common/generic_v1_19_3/src/main/kotlin/io/github/rothes/protocolstringreplacer/nms/generic/packetreader/BlockEntityTypeGetter.kt:
--------------------------------------------------------------------------------
1 | package io.github.rothes.protocolstringreplacer.nms.generic.packetreader
2 |
3 | import io.github.rothes.protocolstringreplacer.nms.packetreader.IBlockEntityTypeGetter
4 | import net.minecraft.world.level.block.entity.BlockEntityType
5 |
6 | class BlockEntityTypeGetter: IBlockEntityTypeGetter {
7 |
8 | override fun getSignType(): Any = BlockEntityType.SIGN
9 |
10 | override fun getHangingSignType(): Any = BlockEntityType.HANGING_SIGN
11 | }
--------------------------------------------------------------------------------
/bukkit/nms/common/generic_v1_19_3/src/main/kotlin/io/github/rothes/protocolstringreplacer/nms/generic/packetreader/MenuTypeGetter.kt:
--------------------------------------------------------------------------------
1 | package io.github.rothes.protocolstringreplacer.nms.generic.packetreader
2 |
3 | import io.github.rothes.protocolstringreplacer.nms.packetreader.IMenuTypeGetter
4 | import net.minecraft.world.inventory.MenuType
5 |
6 | class MenuTypeGetter: IMenuTypeGetter {
7 |
8 | override fun getAnvilMenuType(): Any {
9 | return MenuType.ANVIL
10 | }
11 |
12 | }
--------------------------------------------------------------------------------
/bukkit/nms/common/generic_v1_19_3/src/main/kotlin/io/github/rothes/protocolstringreplacer/nms/generic/packetreader/PacketReader.kt:
--------------------------------------------------------------------------------
1 | package io.github.rothes.protocolstringreplacer.nms.generic.packetreader
2 |
3 | import io.github.rothes.protocolstringreplacer.nms.packetreader.ChatType
4 | import io.github.rothes.protocolstringreplacer.nms.packetreader.IPacketReader
5 | import net.minecraft.core.MappedRegistry
6 | import net.minecraft.core.registries.Registries
7 | import net.minecraft.network.protocol.game.ClientboundDisguisedChatPacket
8 | import net.minecraft.network.protocol.game.ClientboundPlayerChatPacket
9 | import net.minecraft.server.MinecraftServer
10 |
11 | class PacketReader: IPacketReader {
12 |
13 | private val chatTypes = with(
14 | MinecraftServer.getServer().registryAccess().registryOrThrow(Registries.CHAT_TYPE) as MappedRegistry)
15 | {
16 | registryKeySet()
17 | .sortedBy {
18 | getId(this.get(it))
19 | }
20 | .map { it.location().path }
21 | .map { ChatType.entries.find { type -> type.keys.contains(it) }!! }
22 | .toTypedArray()
23 | }
24 |
25 | override fun readChatType(packet: ClientboundPlayerChatPacket): ChatType {
26 | return chatTypes[packet.chatType.chatType]
27 | }
28 |
29 | }
--------------------------------------------------------------------------------
/bukkit/nms/common/generic_v1_21/build.gradle.kts:
--------------------------------------------------------------------------------
1 | val serverVer = "1.21"
2 |
3 | dependencies {
4 | paperweight.paperDevBundle("$serverVer-R0.1-SNAPSHOT")
5 | }
--------------------------------------------------------------------------------
/bukkit/nms/common/generic_v1_21/src/main/kotlin/io/github/rothes/protocolstringreplacer/nms/generic/packetreader/BlockEntityTypeGetter.kt:
--------------------------------------------------------------------------------
1 | package io.github.rothes.protocolstringreplacer.nms.generic.packetreader
2 |
3 | import io.github.rothes.protocolstringreplacer.nms.packetreader.IBlockEntityTypeGetter
4 | import net.minecraft.world.level.block.entity.BlockEntityType
5 |
6 | class BlockEntityTypeGetter: IBlockEntityTypeGetter {
7 |
8 | override fun getSignType(): Any = BlockEntityType.SIGN
9 |
10 | override fun getHangingSignType(): Any = BlockEntityType.HANGING_SIGN
11 | }
--------------------------------------------------------------------------------
/bukkit/nms/common/generic_v1_21/src/main/kotlin/io/github/rothes/protocolstringreplacer/nms/generic/packetreader/DisguisedPacketHandler.kt:
--------------------------------------------------------------------------------
1 | package io.github.rothes.protocolstringreplacer.nms.generic.packetreader
2 |
3 | import net.minecraft.network.chat.ChatType
4 | import net.minecraft.network.chat.Component
5 | import net.minecraft.network.protocol.game.ClientboundDisguisedChatPacket
6 | import io.github.rothes.protocolstringreplacer.nms.packetreader.IDisguisedPacketHandler
7 | import java.lang.reflect.Field
8 | import java.util.Optional
9 |
10 | class DisguisedPacketHandler: IDisguisedPacketHandler {
11 |
12 | override val displayNameField: Field = ChatType.Bound::class.java.declaredFields.first { it.type == Component::class.java }
13 | override val targetField: Field = ChatType.Bound::class.java.declaredFields.first { it.type == Optional::class.java }
14 |
15 | override fun boundRecord(packet: ClientboundDisguisedChatPacket): Any {
16 | return packet.chatType
17 | }
18 | }
--------------------------------------------------------------------------------
/bukkit/nms/common/generic_v1_21/src/main/kotlin/io/github/rothes/protocolstringreplacer/nms/generic/packetreader/MenuTypeGetter.kt:
--------------------------------------------------------------------------------
1 | package io.github.rothes.protocolstringreplacer.nms.generic.packetreader
2 |
3 | import io.github.rothes.protocolstringreplacer.nms.packetreader.IMenuTypeGetter
4 | import net.minecraft.world.inventory.MenuType
5 |
6 | class MenuTypeGetter: IMenuTypeGetter {
7 |
8 | override fun getAnvilMenuType(): Any {
9 | return MenuType.ANVIL
10 | }
11 |
12 | }
--------------------------------------------------------------------------------
/bukkit/nms/common/generic_v1_21/src/main/kotlin/io/github/rothes/protocolstringreplacer/nms/generic/packetreader/PacketReader.kt:
--------------------------------------------------------------------------------
1 | package io.github.rothes.protocolstringreplacer.nms.generic.packetreader
2 |
3 | import io.github.rothes.protocolstringreplacer.nms.packetreader.ChatType
4 | import io.github.rothes.protocolstringreplacer.nms.packetreader.IPacketReader
5 | import net.minecraft.core.MappedRegistry
6 | import net.minecraft.core.registries.Registries
7 | import net.minecraft.network.protocol.game.ClientboundPlayerChatPacket
8 | import net.minecraft.server.MinecraftServer
9 |
10 | class PacketReader: IPacketReader {
11 |
12 | private val registry = MinecraftServer.getServer().registryAccess().registryOrThrow(Registries.CHAT_TYPE)
13 | private val chatTypes = with(registry as MappedRegistry) {
14 | registryKeySet()
15 | .sortedBy {
16 | getId(this.get(it))
17 | }
18 | .map { it.location().path }
19 | .map { ChatType.entries.find { type -> type.keys.contains(it) }!! }
20 | .toTypedArray()
21 | }
22 |
23 | override fun readChatType(packet: ClientboundPlayerChatPacket): ChatType {
24 | return chatTypes[registry.getId(packet.chatType.chatType.value())]
25 | }
26 |
27 | }
--------------------------------------------------------------------------------
/bukkit/nms/common/generic_v1_21_3/build.gradle.kts:
--------------------------------------------------------------------------------
1 | val serverVer = "1.21.3"
2 |
3 | dependencies {
4 | paperweight.paperDevBundle("$serverVer-R0.1-SNAPSHOT")
5 | }
--------------------------------------------------------------------------------
/bukkit/nms/common/generic_v1_21_3/src/main/kotlin/io/github/rothes/protocolstringreplacer/nms/generic/packetreader/BlockEntityTypeGetter.kt:
--------------------------------------------------------------------------------
1 | package io.github.rothes.protocolstringreplacer.nms.generic.packetreader
2 |
3 | import io.github.rothes.protocolstringreplacer.nms.packetreader.IBlockEntityTypeGetter
4 | import net.minecraft.world.level.block.entity.BlockEntityType
5 |
6 | class BlockEntityTypeGetter: IBlockEntityTypeGetter {
7 |
8 | override fun getSignType(): Any = BlockEntityType.SIGN
9 |
10 | override fun getHangingSignType(): Any = BlockEntityType.HANGING_SIGN
11 | }
--------------------------------------------------------------------------------
/bukkit/nms/common/generic_v1_21_3/src/main/kotlin/io/github/rothes/protocolstringreplacer/nms/generic/packetreader/DisguisedPacketHandler.kt:
--------------------------------------------------------------------------------
1 | package io.github.rothes.protocolstringreplacer.nms.generic.packetreader
2 |
3 | import net.minecraft.network.chat.ChatType
4 | import net.minecraft.network.chat.Component
5 | import net.minecraft.network.protocol.game.ClientboundDisguisedChatPacket
6 | import io.github.rothes.protocolstringreplacer.nms.packetreader.IDisguisedPacketHandler
7 | import java.lang.reflect.Field
8 | import java.util.Optional
9 |
10 | class DisguisedPacketHandler: IDisguisedPacketHandler {
11 |
12 | override val displayNameField: Field = ChatType.Bound::class.java.declaredFields.first { it.type == Component::class.java }
13 | override val targetField: Field = ChatType.Bound::class.java.declaredFields.first { it.type == Optional::class.java }
14 |
15 | override fun boundRecord(packet: ClientboundDisguisedChatPacket): Any {
16 | return packet.chatType
17 | }
18 | }
--------------------------------------------------------------------------------
/bukkit/nms/common/generic_v1_21_3/src/main/kotlin/io/github/rothes/protocolstringreplacer/nms/generic/packetreader/MenuTypeGetter.kt:
--------------------------------------------------------------------------------
1 | package io.github.rothes.protocolstringreplacer.nms.generic.packetreader
2 |
3 | import io.github.rothes.protocolstringreplacer.nms.packetreader.IMenuTypeGetter
4 | import net.minecraft.world.inventory.MenuType
5 |
6 | class MenuTypeGetter: IMenuTypeGetter {
7 |
8 | override fun getAnvilMenuType(): Any {
9 | return MenuType.ANVIL
10 | }
11 |
12 | }
--------------------------------------------------------------------------------
/bukkit/nms/common/generic_v1_21_3/src/main/kotlin/io/github/rothes/protocolstringreplacer/nms/generic/packetreader/PacketReader.kt:
--------------------------------------------------------------------------------
1 | package io.github.rothes.protocolstringreplacer.nms.generic.packetreader
2 |
3 | import io.github.rothes.protocolstringreplacer.nms.packetreader.ChatType
4 | import io.github.rothes.protocolstringreplacer.nms.packetreader.IPacketReader
5 | import net.minecraft.core.MappedRegistry
6 | import net.minecraft.core.registries.Registries
7 | import net.minecraft.network.protocol.game.ClientboundPlayerChatPacket
8 | import net.minecraft.server.MinecraftServer
9 |
10 | class PacketReader: IPacketReader {
11 |
12 | private val registry = MinecraftServer.getServer().registryAccess().lookupOrThrow(Registries.CHAT_TYPE)
13 | private val chatTypes = with(registry as MappedRegistry) {
14 | registryKeySet()
15 | .sortedBy { getId(this.getValue(it)) }
16 | .map { it.location().path }
17 | .map { ChatType.entries.find { type -> type.keys.contains(it) }!! }
18 | .toTypedArray()
19 | }
20 |
21 | override fun readChatType(packet: ClientboundPlayerChatPacket): ChatType {
22 | return chatTypes[registry.getId(packet.chatType.chatType.value())]
23 | }
24 |
25 | }
--------------------------------------------------------------------------------
/bukkit/nms/common/src/main/java/io/github/rothes/protocolstringreplacer/nms/packetreader/ChatType.java:
--------------------------------------------------------------------------------
1 | package io.github.rothes.protocolstringreplacer.nms.packetreader;
2 |
3 | public enum ChatType {
4 |
5 | PLAYER_CHAT("chat"),
6 | SYSTEM_CHAT("system"),
7 | GAME_INFO("game_info"),
8 | SAY("say_command"),
9 | MSG_INCOMING(
10 | "msg_command_incoming",
11 | "msg_command" // 1.19
12 | ),
13 | MSG_OUTGOING("msg_command_outgoing"),
14 | TEAM_MSG_INCOMING(
15 | "team_msg_command_incoming",
16 | "team_msg_command" // 1.19
17 | ),
18 | TEAM_MSG_OUTGOING("team_msg_command_outgoing"),
19 | EMOTE("emote_command"),
20 | TELLRAW(
21 | "raw",
22 | "tellraw_command" // 1.19
23 | );
24 |
25 | private final String[] keys;
26 |
27 | ChatType(String... keys) {
28 | this.keys = keys;
29 | }
30 |
31 | public String[] getKeys() {
32 | return keys;
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/bukkit/nms/common/src/main/java/io/github/rothes/protocolstringreplacer/nms/packetreader/IBlockEntityTypeGetter.java:
--------------------------------------------------------------------------------
1 | package io.github.rothes.protocolstringreplacer.nms.packetreader;
2 |
3 | public interface IBlockEntityTypeGetter {
4 |
5 | Object getSignType();
6 | Object getHangingSignType();
7 |
8 | }
9 |
--------------------------------------------------------------------------------
/bukkit/nms/common/src/main/java/io/github/rothes/protocolstringreplacer/nms/packetreader/IMenuTypeGetter.java:
--------------------------------------------------------------------------------
1 | package io.github.rothes.protocolstringreplacer.nms.packetreader;
2 |
3 | public interface IMenuTypeGetter {
4 |
5 | Object getAnvilMenuType();
6 |
7 | }
8 |
--------------------------------------------------------------------------------
/bukkit/nms/common/src/main/java/io/github/rothes/protocolstringreplacer/nms/packetreader/IPacketReader.java:
--------------------------------------------------------------------------------
1 | package io.github.rothes.protocolstringreplacer.nms.packetreader;
2 |
3 | import net.minecraft.network.protocol.game.ClientboundPlayerChatPacket;
4 |
5 | public interface IPacketReader {
6 |
7 | ChatType readChatType(ClientboundPlayerChatPacket packet);
8 |
9 | }
10 |
--------------------------------------------------------------------------------
/bukkit/nms/common/src/main/kotlin/io/github/rothes/protocolstringreplacer/nms/packetreader/IDisguisedPacketHandler.kt:
--------------------------------------------------------------------------------
1 | package io.github.rothes.protocolstringreplacer.nms.packetreader
2 |
3 | import net.minecraft.network.protocol.game.ClientboundDisguisedChatPacket
4 | import java.lang.reflect.Field
5 |
6 | interface IDisguisedPacketHandler {
7 |
8 | val displayNameField: Field
9 | val targetField: Field
10 | fun boundRecord(packet: ClientboundDisguisedChatPacket): Any
11 | }
12 |
--------------------------------------------------------------------------------
/bukkit/nms/src/main/kotlin/io/github/rothes/protocolstringreplacer/nms/NmsManager.kt:
--------------------------------------------------------------------------------
1 | package io.github.rothes.protocolstringreplacer.nms
2 |
3 | import io.github.rothes.protocolstringreplacer.nms.packetreader.IBlockEntityTypeGetter
4 | import io.github.rothes.protocolstringreplacer.nms.packetreader.IDisguisedPacketHandler
5 | import io.github.rothes.protocolstringreplacer.nms.packetreader.IMenuTypeGetter
6 | import io.github.rothes.protocolstringreplacer.nms.packetreader.IPacketReader
7 | import java.util.function.Consumer
8 |
9 | object NmsManager {
10 |
11 | private const val PACKAGE_PREFIX = "io.github.rothes.protocolstringreplacer.nms"
12 |
13 | private lateinit var minecraftVersion: String
14 | lateinit var warningFunction: Consumer
15 |
16 | fun setVersion(major: Int, minor: Int) {
17 | var m = minor
18 | while (m < 10) {
19 | setVersionProp(major, m)
20 | try {
21 | create()
22 | return
23 | } catch (ignored: ClassNotFoundException) {
24 | m++
25 | }
26 | }
27 | // On older versions we are not using NMS.
28 | if (major >= 19) {
29 | warningFunction.accept("Minecraft version 1.$major.$minor is not supported by the plugin version you are running on.")
30 | m = minor
31 | while (--m >= 0) {
32 | setVersionProp(major, m)
33 | try {
34 | create()
35 | warningFunction.accept("Fallback to 1.$major.$m support and luckily it could be compatible.")
36 | return
37 | } catch (ignored: ClassNotFoundException) {
38 | }
39 | }
40 | }
41 | setVersionProp(major, minor)
42 | }
43 |
44 | private fun setVersionProp(major: Int, minor: Int) {
45 | minecraftVersion = if (minor == 0) "v1_$major" else "v1_${major}_$minor"
46 | }
47 |
48 | val packetReader by lazy { create() }
49 | val disguisedPacketHandler by lazy { create() }
50 | val menuTypeGetter by lazy { create() }
51 | val blockEntityTypeGetter by lazy { create() }
52 |
53 | private inline fun create(): T {
54 | return T::class.java.instance
55 | }
56 |
57 | @Suppress("UNCHECKED_CAST")
58 | private val Class.versioned: Class
59 | get() = Class.forName(buildString {
60 | append(PACKAGE_PREFIX)
61 | append(".")
62 | append(minecraftVersion)
63 | append(this@versioned.`package`.name.substring(PACKAGE_PREFIX.length))
64 | append('.')
65 | append(this@versioned.simpleName.substring(1))
66 | }) as Class
67 |
68 | private val Class.instance: T
69 | get() = this.versioned.getConstructor().newInstance() as T
70 |
71 | }
--------------------------------------------------------------------------------
/bukkit/nms/v1_19_1/build.gradle.kts:
--------------------------------------------------------------------------------
1 | val serverVer = "1.19" // 1.19.1 bundle is broken, so we're using 1.19
2 |
3 | dependencies {
4 | paperweight.paperDevBundle("$serverVer-R0.1-SNAPSHOT")
5 | pluginRemapper("net.fabricmc:tiny-remapper:0.10.3:fat")
6 | }
7 |
8 | java {
9 | toolchain {
10 | languageVersion = JavaLanguageVersion.of(17)
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/bukkit/nms/v1_19_1/src/main/kotlin/io/github/rothes/protocolstringreplacer/nms/v1_19_1/packetreader/PacketReader.kt:
--------------------------------------------------------------------------------
1 | package io.github.rothes.protocolstringreplacer.nms.v1_19_1.packetreader
2 |
3 | import io.github.rothes.protocolstringreplacer.nms.packetreader.ChatType
4 | import io.github.rothes.protocolstringreplacer.nms.packetreader.IPacketReader
5 | import net.minecraft.core.MappedRegistry
6 | import net.minecraft.core.Registry
7 | import net.minecraft.network.protocol.game.ClientboundPlayerChatPacket
8 | import net.minecraft.server.MinecraftServer
9 |
10 | class PacketReader: IPacketReader {
11 |
12 | private val chatTypes = with(
13 | MinecraftServer.getServer().registryAccess().registryOrThrow(Registry.CHAT_TYPE_REGISTRY) as MappedRegistry
14 | ) {
15 | registryKeySet()
16 | .sortedBy {
17 | getId(this.get(it))
18 | }
19 | .map { it.location().path }
20 | .map { ChatType.entries.find { type -> type.keys.contains(it) }!! }
21 | .toTypedArray()
22 | }
23 |
24 | override fun readChatType(packet: ClientboundPlayerChatPacket): ChatType {
25 | return chatTypes[packet.typeId]
26 | }
27 |
28 | }
--------------------------------------------------------------------------------
/bukkit/nms/v1_19_2/build.gradle.kts:
--------------------------------------------------------------------------------
1 | val serverVer = "1.19.2"
2 |
3 | dependencies {
4 | paperweight.paperDevBundle("$serverVer-R0.1-SNAPSHOT")
5 | pluginRemapper("net.fabricmc:tiny-remapper:0.10.3:fat")
6 | }
7 |
8 | java {
9 | toolchain {
10 | languageVersion = JavaLanguageVersion.of(17)
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/bukkit/nms/v1_19_2/src/main/kotlin/io/github/rothes/protocolstringreplacer/nms/v1_19_2/packetreader/PacketReader.kt:
--------------------------------------------------------------------------------
1 | package io.github.rothes.protocolstringreplacer.nms.v1_19_2.packetreader
2 |
3 | import io.github.rothes.protocolstringreplacer.nms.packetreader.ChatType
4 | import io.github.rothes.protocolstringreplacer.nms.packetreader.IPacketReader
5 | import net.minecraft.core.MappedRegistry
6 | import net.minecraft.core.Registry
7 | import net.minecraft.network.protocol.game.ClientboundPlayerChatPacket
8 | import net.minecraft.server.MinecraftServer
9 |
10 | class PacketReader: IPacketReader {
11 |
12 | private val chatTypes = with(
13 | MinecraftServer.getServer().registryAccess().registryOrThrow(Registry.CHAT_TYPE_REGISTRY) as MappedRegistry
14 | ) {
15 | registryKeySet()
16 | .sortedBy {
17 | getId(this.get(it))
18 | }
19 | .map { it.location().path }
20 | .map { ChatType.entries.find { type -> type.keys.contains(it) }!! }
21 | .toTypedArray()
22 | }
23 |
24 | override fun readChatType(packet: ClientboundPlayerChatPacket): ChatType {
25 | return chatTypes[packet.chatType.chatType]
26 | }
27 |
28 | }
--------------------------------------------------------------------------------
/bukkit/nms/v1_19_3/build.gradle.kts:
--------------------------------------------------------------------------------
1 | val serverVer = "1.19.3"
2 |
3 | dependencies {
4 | paperweight.paperDevBundle("$serverVer-R0.1-SNAPSHOT")
5 | implementation(project(":bukkit:nms:common:generic_v1_19_3"))
6 | }
7 |
--------------------------------------------------------------------------------
/bukkit/nms/v1_19_4/build.gradle.kts:
--------------------------------------------------------------------------------
1 | val serverVer = "1.19.4"
2 |
3 | dependencies {
4 | paperweight.paperDevBundle("$serverVer-R0.1-SNAPSHOT")
5 | implementation(project(":bukkit:nms:common:generic_v1_19_3"))
6 | }
7 |
--------------------------------------------------------------------------------
/bukkit/nms/v1_20_1/build.gradle.kts:
--------------------------------------------------------------------------------
1 | val serverVer = "1.20.1"
2 |
3 | dependencies {
4 | paperweight.paperDevBundle("$serverVer-R0.1-SNAPSHOT")
5 | implementation(project(":bukkit:nms:common:generic_v1_19_3"))
6 | }
7 |
--------------------------------------------------------------------------------
/bukkit/nms/v1_20_2/build.gradle.kts:
--------------------------------------------------------------------------------
1 | val serverVer = "1.20.2"
2 |
3 | dependencies {
4 | paperweight.paperDevBundle("$serverVer-R0.1-SNAPSHOT")
5 | implementation(project(":bukkit:nms:common:generic_v1_19_3"))
6 | }
--------------------------------------------------------------------------------
/bukkit/nms/v1_20_4/build.gradle.kts:
--------------------------------------------------------------------------------
1 | val serverVer = "1.20.4"
2 |
3 | dependencies {
4 | paperweight.paperDevBundle("$serverVer-R0.1-SNAPSHOT")
5 | implementation(project(":bukkit:nms:common:generic_v1_19_3"))
6 | }
7 |
--------------------------------------------------------------------------------
/bukkit/nms/v1_20_6/build.gradle.kts:
--------------------------------------------------------------------------------
1 | val serverVer = "1.20.6"
2 |
3 | dependencies {
4 | paperweight.paperDevBundle("$serverVer-R0.1-SNAPSHOT")
5 | }
6 |
--------------------------------------------------------------------------------
/bukkit/nms/v1_20_6/src/main/kotlin/io/github/rothes/protocolstringreplacer/nms/v1_20_6/packetreader/BlockEntityTypeGetter.kt:
--------------------------------------------------------------------------------
1 | package io.github.rothes.protocolstringreplacer.nms.v1_20_6.packetreader
2 |
3 | import io.github.rothes.protocolstringreplacer.nms.packetreader.IBlockEntityTypeGetter
4 | import net.minecraft.world.level.block.entity.BlockEntityType
5 |
6 | class BlockEntityTypeGetter: IBlockEntityTypeGetter {
7 |
8 | override fun getSignType(): Any = BlockEntityType.SIGN
9 |
10 | override fun getHangingSignType(): Any = BlockEntityType.HANGING_SIGN
11 | }
--------------------------------------------------------------------------------
/bukkit/nms/v1_20_6/src/main/kotlin/io/github/rothes/protocolstringreplacer/nms/v1_20_6/packetreader/DisguisedPacketHandler.kt:
--------------------------------------------------------------------------------
1 | package io.github.rothes.protocolstringreplacer.nms.v1_20_6.packetreader
2 |
3 | import net.minecraft.network.chat.ChatType
4 | import net.minecraft.network.chat.Component
5 | import net.minecraft.network.protocol.game.ClientboundDisguisedChatPacket
6 | import io.github.rothes.protocolstringreplacer.nms.packetreader.IDisguisedPacketHandler
7 | import java.lang.reflect.Field
8 | import java.util.Optional
9 |
10 | class DisguisedPacketHandler: IDisguisedPacketHandler {
11 |
12 | override val displayNameField: Field = ChatType.Bound::class.java.declaredFields.first { it.type == Component::class.java }
13 | override val targetField: Field = ChatType.Bound::class.java.declaredFields.first { it.type == Optional::class.java }
14 |
15 | override fun boundRecord(packet: ClientboundDisguisedChatPacket): Any {
16 | return packet.chatType
17 | }
18 | }
--------------------------------------------------------------------------------
/bukkit/nms/v1_20_6/src/main/kotlin/io/github/rothes/protocolstringreplacer/nms/v1_20_6/packetreader/MenuTypeGetter.kt:
--------------------------------------------------------------------------------
1 | package io.github.rothes.protocolstringreplacer.nms.v1_20_6.packetreader
2 |
3 | import io.github.rothes.protocolstringreplacer.nms.packetreader.IMenuTypeGetter
4 | import net.minecraft.world.inventory.MenuType
5 |
6 | class MenuTypeGetter: IMenuTypeGetter {
7 |
8 | override fun getAnvilMenuType(): Any {
9 | return MenuType.ANVIL
10 | }
11 |
12 | }
--------------------------------------------------------------------------------
/bukkit/nms/v1_20_6/src/main/kotlin/io/github/rothes/protocolstringreplacer/nms/v1_20_6/packetreader/PacketReader.kt:
--------------------------------------------------------------------------------
1 | package io.github.rothes.protocolstringreplacer.nms.v1_20_6.packetreader
2 |
3 | import io.github.rothes.protocolstringreplacer.nms.packetreader.ChatType
4 | import io.github.rothes.protocolstringreplacer.nms.packetreader.IPacketReader
5 | import net.minecraft.core.MappedRegistry
6 | import net.minecraft.core.registries.Registries
7 | import net.minecraft.network.protocol.game.ClientboundPlayerChatPacket
8 | import net.minecraft.server.MinecraftServer
9 |
10 | class PacketReader: IPacketReader {
11 |
12 | private val registry = MinecraftServer.getServer().registryAccess().registryOrThrow(Registries.CHAT_TYPE)
13 | private val chatTypes = with(registry as MappedRegistry) {
14 | registryKeySet()
15 | .sortedBy {
16 | getId(this.get(it))
17 | }
18 | .map { it.location().path }
19 | .map { ChatType.entries.find { type -> type.keys.contains(it) }!! }
20 | .toTypedArray()
21 | }
22 |
23 | override fun readChatType(packet: ClientboundPlayerChatPacket): ChatType {
24 | return chatTypes[registry.getId(packet.chatType.chatType.value())]
25 | }
26 |
27 | }
--------------------------------------------------------------------------------
/bukkit/nms/v1_21_1/build.gradle.kts:
--------------------------------------------------------------------------------
1 | val serverVer = "1.21.1"
2 |
3 | dependencies {
4 | paperweight.paperDevBundle("$serverVer-R0.1-SNAPSHOT")
5 | implementation(project(":bukkit:nms:common:generic_v1_21"))
6 | }
--------------------------------------------------------------------------------
/bukkit/nms/v1_21_3/build.gradle.kts:
--------------------------------------------------------------------------------
1 | val serverVer = "1.21.3"
2 |
3 | dependencies {
4 | paperweight.paperDevBundle("$serverVer-R0.1-SNAPSHOT")
5 | implementation(project(":bukkit:nms:common:generic_v1_21_3"))
6 | }
--------------------------------------------------------------------------------
/bukkit/nms/v1_21_4/build.gradle.kts:
--------------------------------------------------------------------------------
1 | val serverVer = "1.21.4"
2 |
3 | dependencies {
4 | paperweight.paperDevBundle("$serverVer-R0.1-SNAPSHOT")
5 | implementation(project(":bukkit:nms:common:generic_v1_21_3"))
6 | }
--------------------------------------------------------------------------------
/bukkit/nms/v1_21_5/build.gradle.kts:
--------------------------------------------------------------------------------
1 | val serverVer = "1.21.5"
2 |
3 | dependencies {
4 | paperweight.paperDevBundle("$serverVer-no-moonrise-SNAPSHOT")
5 | implementation(project(":bukkit:nms:common:generic_v1_21_3"))
6 | }
--------------------------------------------------------------------------------
/bukkit/src/main/java/io/github/rothes/protocolstringreplacer/api/configuration/DotYamlConfiguration.java:
--------------------------------------------------------------------------------
1 | package io.github.rothes.protocolstringreplacer.api.configuration;
2 |
3 | import org.apache.commons.lang.Validate;
4 | import org.bukkit.Bukkit;
5 | import org.bukkit.configuration.InvalidConfigurationException;
6 |
7 | import javax.annotation.Nonnull;
8 | import java.io.File;
9 | import java.io.FileNotFoundException;
10 | import java.io.IOException;
11 | import java.util.logging.Level;
12 |
13 | /**
14 | * Only used to upgrade old configs currently.
15 | */
16 | @SuppressWarnings("DeprecatedIsStillUsed")
17 | @Deprecated
18 | public class DotYamlConfiguration extends CommentYamlConfiguration {
19 |
20 | public DotYamlConfiguration() {
21 | super();
22 | options().pathSeparator('鰠');
23 | }
24 |
25 | @Nonnull
26 | public static DotYamlConfiguration loadConfiguration(@Nonnull File file) {
27 | Validate.notNull(file, "File cannot be null");
28 | DotYamlConfiguration config = new DotYamlConfiguration();
29 |
30 | try {
31 | config.load(file);
32 | } catch (FileNotFoundException ignored) {
33 | } catch (IOException | InvalidConfigurationException var4) {
34 | Bukkit.getLogger().log(Level.SEVERE, "Cannot load " + file, var4);
35 | }
36 |
37 | return config;
38 | }
39 |
40 | }
41 |
--------------------------------------------------------------------------------
/bukkit/src/main/java/io/github/rothes/protocolstringreplacer/api/exceptions/IncompatibleServerException.java:
--------------------------------------------------------------------------------
1 | package io.github.rothes.protocolstringreplacer.api.exceptions;
2 |
3 | public class IncompatibleServerException extends RuntimeException {
4 |
5 | public IncompatibleServerException(Throwable throwable) {
6 | super(throwable);
7 | }
8 |
9 | }
10 |
--------------------------------------------------------------------------------
/bukkit/src/main/java/io/github/rothes/protocolstringreplacer/api/exceptions/JsonSyntaxException.java:
--------------------------------------------------------------------------------
1 | package io.github.rothes.protocolstringreplacer.api.exceptions;
2 |
3 | public class JsonSyntaxException extends RuntimeException {
4 |
5 | public JsonSyntaxException(String msg, Throwable throwable) {
6 | super(msg, throwable);
7 | }
8 |
9 | }
10 |
--------------------------------------------------------------------------------
/bukkit/src/main/java/io/github/rothes/protocolstringreplacer/api/exceptions/MissingInitialResourceException.java:
--------------------------------------------------------------------------------
1 | package io.github.rothes.protocolstringreplacer.api.exceptions;
2 |
3 | public class MissingInitialResourceException extends RuntimeException {
4 |
5 | public MissingInitialResourceException(String message) {
6 | super(message);
7 | }
8 |
9 | }
10 |
--------------------------------------------------------------------------------
/bukkit/src/main/java/io/github/rothes/protocolstringreplacer/api/user/PsrUserManager.java:
--------------------------------------------------------------------------------
1 | package io.github.rothes.protocolstringreplacer.api.user;
2 |
3 | import org.bukkit.Bukkit;
4 | import org.bukkit.command.CommandSender;
5 | import org.bukkit.entity.Player;
6 | import org.jetbrains.annotations.NotNull;
7 |
8 | import javax.annotation.Nonnull;
9 | import java.util.HashMap;
10 | import java.util.UUID;
11 |
12 | public class PsrUserManager {
13 |
14 | private final HashMap users = new HashMap<>();
15 | private final PsrUser console = new PsrUser(Bukkit.getConsoleSender());
16 |
17 | public PsrUser getUser(@NotNull UUID uuid) {
18 | return users.getOrDefault(uuid, loadUser(uuid));
19 | }
20 |
21 | @Nonnull
22 | public PsrUser getUser(@NotNull Player player) {
23 | return users.getOrDefault(player.getUniqueId(), loadUser(player));
24 | }
25 |
26 | @Nonnull
27 | public PsrUser getUser(@NotNull CommandSender sender) {
28 | return sender instanceof Player? getUser((Player) sender) : console;
29 | }
30 |
31 | public PsrUser getConsoleUser() {
32 | return console;
33 | }
34 |
35 | public PsrUser loadUser(@NotNull UUID uuid) {
36 | return users.putIfAbsent(uuid, new PsrUser(uuid));
37 | }
38 |
39 | public PsrUser loadUser(@NotNull Player player) {
40 | return users.putIfAbsent(player.getUniqueId(), new PsrUser(player));
41 | }
42 |
43 | public void unloadUser(@NotNull UUID uuid) {
44 | users.remove(uuid);
45 | }
46 |
47 | public void unloadUser(@NotNull Player player) {
48 | unloadUser(player.getUniqueId());
49 | }
50 |
51 | }
52 |
--------------------------------------------------------------------------------
/bukkit/src/main/java/io/github/rothes/protocolstringreplacer/command/SubCommand.java:
--------------------------------------------------------------------------------
1 | package io.github.rothes.protocolstringreplacer.command;
2 |
3 | import io.github.rothes.protocolstringreplacer.api.user.PsrUser;
4 |
5 | import javax.annotation.Nonnull;
6 | import java.util.List;
7 |
8 | public abstract class SubCommand {
9 |
10 | private final String name;
11 | private final String permission;
12 | private final String description;
13 |
14 | public SubCommand(@Nonnull String name, @Nonnull String permission, @Nonnull String description) {
15 | this.name = name;
16 | this.permission = permission;
17 | this.description = description;
18 | }
19 |
20 | public abstract void onExecute(@Nonnull PsrUser user, @Nonnull String[] args);
21 |
22 | public abstract List onTab(@Nonnull PsrUser user, @Nonnull String[] args);
23 |
24 | @Nonnull
25 | public final String getName() {
26 | return name;
27 | }
28 |
29 | @Nonnull
30 | public String getPermission() {
31 | return permission;
32 | }
33 |
34 | @Nonnull
35 | public String getDescription() {
36 | return description;
37 | }
38 |
39 | public abstract void sendHelp(@Nonnull PsrUser user);
40 | }
41 |
--------------------------------------------------------------------------------
/bukkit/src/main/java/io/github/rothes/protocolstringreplacer/command/subcommands/Edit.java:
--------------------------------------------------------------------------------
1 | package io.github.rothes.protocolstringreplacer.command.subcommands;
2 |
3 | import io.github.rothes.protocolstringreplacer.PsrLocalization;
4 | import io.github.rothes.protocolstringreplacer.command.subcommands.editchildren.Block;
5 | import io.github.rothes.protocolstringreplacer.command.subcommands.editchildren.File;
6 | import io.github.rothes.protocolstringreplacer.command.subcommands.editchildren.Replace;
7 | import io.github.rothes.protocolstringreplacer.api.user.PsrUser;
8 | import io.github.rothes.protocolstringreplacer.command.SubCommand;
9 | import org.jetbrains.annotations.NotNull;
10 |
11 | import javax.annotation.Nonnull;
12 | import java.util.ArrayList;
13 | import java.util.LinkedList;
14 | import java.util.List;
15 |
16 | public class Edit extends SubCommand {
17 |
18 | private final LinkedList childCommands = new LinkedList<>();
19 |
20 | public Edit() {
21 | super("edit", "protocolstringreplacer.command.edit",
22 | PsrLocalization.getLocaledMessage("Sender.Commands.Edit.Description"));
23 |
24 | childCommands.add(new File());
25 | childCommands.add(new Replace());
26 | childCommands.add(new Block());
27 | // TODO: childCommands.add(new Option());
28 | }
29 |
30 | @Override
31 | public void onExecute(@Nonnull PsrUser user, @Nonnull String[] args) {
32 | if (args.length > 1) {
33 | for (SubCommand childCommand : childCommands) {
34 | if (childCommand.getName().equalsIgnoreCase(args[1])) {
35 | if (user.hasPermissionOrOp(childCommand.getPermission())) {
36 | childCommand.onExecute(user, args);
37 | } else {
38 | user.sendFilteredText(PsrLocalization.getPrefixedLocaledMessage("Sender.Commands.No-Permission"));
39 | }
40 | return;
41 | }
42 | }
43 | }
44 | sendHelp(user);
45 | }
46 |
47 | @Override
48 | public List onTab(@NotNull PsrUser user, @NotNull String[] args) {
49 | List list = new ArrayList<>();
50 | if (args.length == 2) {
51 | list.add("help");
52 | for (SubCommand childCommand : childCommands) {
53 | if (user.hasPermissionOrOp(childCommand.getPermission())) {
54 | list.add(childCommand.getName());
55 | }
56 | }
57 | } else {
58 | for (SubCommand childCommand : childCommands) {
59 | if (childCommand.getName().equalsIgnoreCase(args[1])) {
60 | list = childCommand.onTab(user, args);
61 | }
62 | }
63 | }
64 | return list;
65 | }
66 |
67 | @Override
68 | public void sendHelp(@Nonnull PsrUser user) {
69 | user.sendFilteredText(PsrLocalization.getLocaledMessage("Sender.Commands.Edit.Help.Header"));
70 | for (SubCommand childCommand : childCommands) {
71 | user.sendFilteredText(PsrLocalization.getLocaledMessage("Sender.Commands.Subcommand-Help-Format",
72 | "/psr edit " + childCommand.getName(), childCommand.getDescription()));
73 | }
74 | user.sendFilteredText(PsrLocalization.getLocaledMessage("Sender.Commands.Edit.Help.Footer"));
75 | }
76 |
77 | }
78 |
--------------------------------------------------------------------------------
/bukkit/src/main/java/io/github/rothes/protocolstringreplacer/command/subcommands/Reload.java:
--------------------------------------------------------------------------------
1 | package io.github.rothes.protocolstringreplacer.command.subcommands;
2 |
3 | import io.github.rothes.protocolstringreplacer.PsrLocalization;
4 | import io.github.rothes.protocolstringreplacer.ProtocolStringReplacer;
5 | import io.github.rothes.protocolstringreplacer.api.user.PsrUser;
6 | import io.github.rothes.protocolstringreplacer.command.SubCommand;
7 | import org.jetbrains.annotations.NotNull;
8 |
9 | import javax.annotation.Nonnull;
10 | import java.util.List;
11 |
12 | public class Reload extends SubCommand {
13 |
14 | public Reload() {
15 | super("reload", "protocolstringreplacer.command.reload", PsrLocalization
16 | .getLocaledMessage("Sender.Commands.Reload.Description"));
17 | }
18 |
19 | @Override
20 | public void onExecute(@Nonnull PsrUser user, @Nonnull String[] args) {
21 | if (args.length == 1) {
22 | if (ProtocolStringReplacer.getInstance().isReloading()) {
23 | user.sendFilteredText(PsrLocalization.getPrefixedLocaledMessage("Sender.Commands.Reload.Already-Reloading"));
24 | return;
25 | }
26 | ProtocolStringReplacer.getInstance().reload(user);
27 | } else {
28 | sendHelp(user);
29 | }
30 | }
31 |
32 | @Override
33 | public List onTab(@NotNull PsrUser user, @NotNull String[] args) {
34 | return null;
35 | }
36 |
37 | @Override
38 | public void sendHelp(@Nonnull PsrUser user) {
39 | user.sendFilteredText(PsrLocalization.getLocaledMessage("Sender.Commands.Reload.Help.Header"));
40 | user.sendFilteredText("§7 * §e/psr reload§7- §b " + this.getDescription());
41 | user.sendFilteredText(PsrLocalization.getLocaledMessage("Sender.Commands.Reload.Help.Footer"));
42 | }
43 |
44 | }
45 |
--------------------------------------------------------------------------------
/bukkit/src/main/java/io/github/rothes/protocolstringreplacer/console/PsrJndiLookup.java:
--------------------------------------------------------------------------------
1 | package io.github.rothes.protocolstringreplacer.console;
2 |
3 | import io.github.rothes.protocolstringreplacer.ProtocolStringReplacer;
4 | import io.github.rothes.protocolstringreplacer.util.scheduler.PsrScheduler;
5 | import org.apache.logging.log4j.core.LogEvent;
6 | import org.apache.logging.log4j.core.config.plugins.Plugin;
7 | import org.apache.logging.log4j.core.lookup.StrLookup;
8 |
9 | @Plugin(name = "jndi", category = StrLookup.CATEGORY)
10 | public class PsrJndiLookup implements StrLookup {
11 |
12 | // static final String CONTAINER_JNDI_RESOURCE_PATH_PREFIX = "java:comp/env/";
13 |
14 | @Override
15 | public String lookup(final String key) {
16 | return lookup(null, key);
17 | }
18 |
19 | @Override
20 | public String lookup(LogEvent event, String key) {
21 | if (key == null) {
22 | return null;
23 | }
24 | // runTaskLater to avoid errors.
25 | PsrScheduler.runTaskLater(() -> ProtocolStringReplacer.info("Blocked not whitelisted Jndi looking up [" + key + "]")
26 | , 0L);
27 | return null;
28 |
29 | // TODO: Maybe add a config for those really need jndi..?
30 | // try (final JndiManager jndiManager = JndiManager.getDefaultManager()) {
31 | // final String jndiName = convertJndiName(key);
32 | // return Objects.toString(jndiManager.lookup(jndiName), null);
33 | // } catch (final NamingException e) {
34 | // return null;
35 | // }
36 | }
37 |
38 | // private String convertJndiName(final String jndiName) {
39 | // if (!jndiName.startsWith(CONTAINER_JNDI_RESOURCE_PATH_PREFIX) && jndiName.indexOf(':') == -1) {
40 | // return CONTAINER_JNDI_RESOURCE_PATH_PREFIX + jndiName;
41 | // }
42 | // return jndiName;
43 | // }
44 |
45 | }
46 |
--------------------------------------------------------------------------------
/bukkit/src/main/java/io/github/rothes/protocolstringreplacer/console/PsrMessageFactory.java:
--------------------------------------------------------------------------------
1 | package io.github.rothes.protocolstringreplacer.console;
2 |
3 | import org.apache.logging.log4j.message.AbstractMessageFactory;
4 | import org.apache.logging.log4j.message.Message;
5 |
6 | public class PsrMessageFactory extends AbstractMessageFactory {
7 |
8 | @Override
9 | public Message newMessage(String message) {
10 | return new PsrMessage(message);
11 | }
12 |
13 | @Override
14 | public Message newMessage(CharSequence message) {
15 | return new PsrMessage(message);
16 | }
17 |
18 | @Override
19 | public Message newMessage(String message, Object... params) {
20 | return new PsrMessage(message);
21 | }
22 |
23 | }
24 |
--------------------------------------------------------------------------------
/bukkit/src/main/java/io/github/rothes/protocolstringreplacer/events/PsrReloadEvent.java:
--------------------------------------------------------------------------------
1 | package io.github.rothes.protocolstringreplacer.events;
2 |
3 | import io.github.rothes.protocolstringreplacer.api.user.PsrUser;
4 | import org.bukkit.command.CommandSender;
5 | import org.bukkit.event.Cancellable;
6 | import org.bukkit.event.Event;
7 | import org.bukkit.event.HandlerList;
8 | import org.jetbrains.annotations.NotNull;
9 |
10 | public class PsrReloadEvent extends Event implements Cancellable {
11 |
12 | private static final HandlerList handlers = new HandlerList();
13 | private final ReloadState reloadState;
14 | private final PsrUser user;
15 | private boolean cancelled = false;
16 |
17 | public PsrReloadEvent(ReloadState reloadState, PsrUser user) {
18 | this.reloadState = reloadState;
19 | this.user = user;
20 | }
21 |
22 | public ReloadState getReloadState() {
23 | return reloadState;
24 | }
25 |
26 | public PsrUser getUser() {
27 | return user;
28 | }
29 |
30 | public CommandSender getActor() {
31 | return user.getSender();
32 | }
33 |
34 | @NotNull
35 | @Override
36 | public HandlerList getHandlers() {
37 | return handlers;
38 | }
39 |
40 | @Override
41 | public boolean isCancelled() {
42 | return cancelled;
43 | }
44 |
45 | @Override
46 | public void setCancelled(boolean cancelled) {
47 | this.cancelled = cancelled;
48 | }
49 |
50 | @NotNull
51 | public static HandlerList getHandlerList() {
52 | return handlers;
53 | }
54 |
55 | public enum ReloadState {
56 | BEFORE,
57 | FINISH
58 | }
59 |
60 | }
61 |
--------------------------------------------------------------------------------
/bukkit/src/main/java/io/github/rothes/protocolstringreplacer/listeners/PlayerJoinListener.java:
--------------------------------------------------------------------------------
1 | package io.github.rothes.protocolstringreplacer.listeners;
2 |
3 | import io.github.rothes.protocolstringreplacer.ProtocolStringReplacer;
4 | import org.bukkit.entity.Player;
5 | import org.bukkit.event.EventHandler;
6 | import org.bukkit.event.Listener;
7 | import org.bukkit.event.player.PlayerJoinEvent;
8 |
9 | public class PlayerJoinListener implements Listener {
10 |
11 | @EventHandler
12 | public void onPlayerJoin(PlayerJoinEvent event) {
13 | Player player = event.getPlayer();
14 | ProtocolStringReplacer.getInstance().getUserManager().loadUser(player);
15 | }
16 |
17 | }
18 |
--------------------------------------------------------------------------------
/bukkit/src/main/java/io/github/rothes/protocolstringreplacer/listeners/PlayerQuitListener.java:
--------------------------------------------------------------------------------
1 | package io.github.rothes.protocolstringreplacer.listeners;
2 |
3 | import io.github.rothes.protocolstringreplacer.ProtocolStringReplacer;
4 | import org.bukkit.entity.Player;
5 | import org.bukkit.event.EventHandler;
6 | import org.bukkit.event.Listener;
7 | import org.bukkit.event.player.PlayerQuitEvent;
8 |
9 | public class PlayerQuitListener implements Listener {
10 |
11 | @EventHandler
12 | public void onPlayerQuit(PlayerQuitEvent event) {
13 | Player player = event.getPlayer();
14 | ProtocolStringReplacer.getInstance().getUserManager().unloadUser(player);
15 | }
16 |
17 | }
18 |
--------------------------------------------------------------------------------
/bukkit/src/main/java/io/github/rothes/protocolstringreplacer/listeners/PsrInternalListeners.java:
--------------------------------------------------------------------------------
1 | package io.github.rothes.protocolstringreplacer.listeners;
2 |
3 | import io.github.rothes.protocolstringreplacer.ProtocolStringReplacer;
4 | import io.github.rothes.protocolstringreplacer.api.user.PsrUser;
5 | import io.github.rothes.protocolstringreplacer.api.user.PsrUserManager;
6 | import io.github.rothes.protocolstringreplacer.events.PsrReloadEvent;
7 | import io.github.rothes.protocolstringreplacer.replacer.ListenType;
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 |
14 | public class PsrInternalListeners implements Listener {
15 |
16 | private int maxRecords;
17 |
18 | @EventHandler(priority = EventPriority.MONITOR)
19 | public void onPsrReload(PsrReloadEvent e) {
20 | if (e.getReloadState() == PsrReloadEvent.ReloadState.BEFORE) {
21 | maxRecords = ProtocolStringReplacer.getInstance().getConfigManager().maxCaptureRecords;
22 | } else if (e.getReloadState() == PsrReloadEvent.ReloadState.FINISH
23 | // maxCaptureRecords changed, reset user capture status.
24 | && maxRecords != ProtocolStringReplacer.getInstance().getConfigManager().maxCaptureRecords) {
25 | PsrUserManager userManager = ProtocolStringReplacer.getInstance().getUserManager();
26 | for (Player player : Bukkit.getOnlinePlayers()) {
27 | PsrUser user = userManager.getUser(player);
28 | for (ListenType value : ListenType.values()) {
29 | user.removeCaptureType(value);
30 | }
31 | }
32 | }
33 | }
34 |
35 | }
36 |
--------------------------------------------------------------------------------
/bukkit/src/main/java/io/github/rothes/protocolstringreplacer/packetlistener/BasePacketListener.java:
--------------------------------------------------------------------------------
1 | package io.github.rothes.protocolstringreplacer.packetlistener;
2 |
3 | import com.comphenix.protocol.PacketType;
4 | import com.comphenix.protocol.ProtocolLibrary;
5 | import com.comphenix.protocol.events.PacketAdapter;
6 | import com.comphenix.protocol.events.PacketEvent;
7 | import io.github.rothes.protocolstringreplacer.ProtocolStringReplacer;
8 | import io.github.rothes.protocolstringreplacer.api.user.PsrUser;
9 | import org.apache.commons.lang.Validate;
10 | import org.bukkit.entity.Player;
11 | import org.jetbrains.annotations.Nullable;
12 |
13 | import javax.annotation.Nonnull;
14 |
15 | public abstract class BasePacketListener {
16 |
17 | protected final PacketType packetType;
18 | protected PacketAdapter packetAdapter;
19 |
20 | protected BasePacketListener(@Nonnull PacketType packetType) {
21 | this.packetType = packetType;
22 | }
23 |
24 | protected void register() {
25 | ProtocolLibrary.getProtocolManager().addPacketListener(packetAdapter);
26 | }
27 |
28 | @Nullable
29 | protected final PsrUser getEventUser(@Nonnull PacketEvent packetEvent) {
30 | Validate.notNull(packetEvent, "Packet Event cannot be null");
31 | Player player = packetEvent.getPlayer();
32 | if (packetEvent.isPlayerTemporary()) {
33 | ProtocolStringReplacer.warn("ProtocolLib returns temporary player [" + player.getAddress() + "] for packet " + packetType.name() + ". "
34 | + "It cannot be processed.");
35 | return null;
36 | } else {
37 | return ProtocolStringReplacer.getInstance().getUserManager().getUser(player);
38 | }
39 | }
40 |
41 | protected boolean canWrite(@Nonnull PacketEvent packetEvent) {
42 | Validate.notNull(packetEvent, "Packet Event cannot be null");
43 |
44 | if (packetEvent.isReadOnly()) {
45 | if (ProtocolStringReplacer.getInstance().getConfigManager().forceReplace) {
46 | packetEvent.setReadOnly(false);
47 | } else {
48 | return false;
49 | }
50 | }
51 | return true;
52 | }
53 |
54 | abstract protected void process(@Nonnull PacketEvent packetEvent);
55 |
56 | }
57 |
--------------------------------------------------------------------------------
/bukkit/src/main/java/io/github/rothes/protocolstringreplacer/packetlistener/client/BaseClientPacketListener.java:
--------------------------------------------------------------------------------
1 | package io.github.rothes.protocolstringreplacer.packetlistener.client;
2 |
3 | import com.comphenix.protocol.PacketType;
4 | import com.comphenix.protocol.events.PacketAdapter;
5 | import com.comphenix.protocol.events.PacketEvent;
6 | import io.github.rothes.protocolstringreplacer.ProtocolStringReplacer;
7 | import io.github.rothes.protocolstringreplacer.packetlistener.BasePacketListener;
8 |
9 | public abstract class BaseClientPacketListener extends BasePacketListener {
10 |
11 | protected BaseClientPacketListener(PacketType packetType) {
12 | super(packetType);
13 | packetAdapter = new PacketAdapter(ProtocolStringReplacer.getInstance(), ProtocolStringReplacer.getInstance().getPacketListenerManager().getListenerPriority(), packetType) {
14 | public void onPacketReceiving(PacketEvent packetEvent) {
15 | boolean readOnly = packetEvent.isReadOnly();
16 | if (!canWrite(packetEvent)) {
17 | return;
18 | }
19 | process(packetEvent);
20 | if (readOnly) {
21 | packetEvent.setReadOnly(true);
22 | }
23 | }
24 | };
25 | }
26 |
27 | }
28 |
--------------------------------------------------------------------------------
/bukkit/src/main/java/io/github/rothes/protocolstringreplacer/packetlistener/client/CloseWindow.java:
--------------------------------------------------------------------------------
1 | package io.github.rothes.protocolstringreplacer.packetlistener.client;
2 |
3 | import com.comphenix.protocol.PacketType;
4 | import com.comphenix.protocol.events.PacketEvent;
5 | import io.github.rothes.protocolstringreplacer.api.user.PsrUser;
6 | import io.github.rothes.protocolstringreplacer.packetlistener.client.itemstack.BaseClientItemPacketListener;
7 | import io.github.rothes.protocolstringreplacer.util.scheduler.PsrScheduler;
8 |
9 | public class CloseWindow extends BaseClientItemPacketListener {
10 |
11 | public CloseWindow() {
12 | super(PacketType.Play.Client.CLOSE_WINDOW);
13 | }
14 |
15 | protected void process(PacketEvent packetEvent) {
16 | PsrUser user = getEventUser(packetEvent);
17 | user.setCurrentWindowTitle(null);
18 | user.setInAnvil(false);
19 | if (user.isInMerchant()) {
20 | user.setInMerchant(false);
21 | // Must be called in other threads or the inventory won't update.
22 | PsrScheduler.runTaskAsynchronously(() -> user.getPlayer().updateInventory());
23 | }
24 | }
25 |
26 | }
27 |
--------------------------------------------------------------------------------
/bukkit/src/main/java/io/github/rothes/protocolstringreplacer/packetlistener/client/SettingsLocale.java:
--------------------------------------------------------------------------------
1 | package io.github.rothes.protocolstringreplacer.packetlistener.client;
2 |
3 | import com.comphenix.protocol.PacketType;
4 | import com.comphenix.protocol.events.PacketEvent;
5 | import io.github.rothes.protocolstringreplacer.api.user.PsrUser;
6 | import org.jetbrains.annotations.NotNull;
7 |
8 | import java.util.Locale;
9 |
10 | public class SettingsLocale extends BaseClientPacketListener {
11 |
12 | public SettingsLocale() {
13 | super(PacketType.Play.Client.SETTINGS);
14 | }
15 |
16 | @Override
17 | protected void process(@NotNull PacketEvent packetEvent) {
18 | PsrUser user = getEventUser(packetEvent);
19 | if (user == null) {
20 | return;
21 | }
22 | String read = packetEvent.getPacket().getStrings().read(0);
23 | user.setClientLocale(read.toLowerCase(Locale.ROOT).replace('-', '_'));
24 | }
25 |
26 | @Override
27 | protected boolean canWrite(@NotNull PacketEvent packetEvent) {
28 | // We just read it.
29 | return true;
30 | }
31 |
32 | }
33 |
--------------------------------------------------------------------------------
/bukkit/src/main/java/io/github/rothes/protocolstringreplacer/packetlistener/client/SettingsLocaleUpper20.java:
--------------------------------------------------------------------------------
1 | package io.github.rothes.protocolstringreplacer.packetlistener.client;
2 |
3 | import com.comphenix.protocol.PacketType;
4 | import com.comphenix.protocol.events.PacketEvent;
5 | import io.github.rothes.protocolstringreplacer.api.user.PsrUser;
6 | import org.jetbrains.annotations.NotNull;
7 |
8 | import java.lang.reflect.Field;
9 | import java.util.Locale;
10 |
11 | public class SettingsLocaleUpper20 extends BaseClientPacketListener {
12 |
13 | private Field language;
14 |
15 | public SettingsLocaleUpper20() {
16 | super(PacketType.Play.Client.SETTINGS);
17 | }
18 |
19 | @Override
20 | protected void process(@NotNull PacketEvent packetEvent) {
21 | PsrUser user = getEventUser(packetEvent);
22 | if (user == null) {
23 | return;
24 | }
25 | Object record = packetEvent.getPacket().getModifier().read(0);
26 | String read;
27 | try {
28 | read = (String) field().get(record);
29 | } catch (IllegalAccessException e) {
30 | throw new RuntimeException(e);
31 | }
32 | user.setClientLocale(read.toLowerCase(Locale.ROOT).replace('-', '_'));
33 | }
34 |
35 | private Field field() {
36 | if (language == null) {
37 | language = PacketType.Play.Client.SETTINGS.getPacketClass().getDeclaredFields()[0].getType().getDeclaredFields()[0];
38 | language.setAccessible(true);
39 | }
40 | return language;
41 | }
42 |
43 | @Override
44 | protected boolean canWrite(@NotNull PacketEvent packetEvent) {
45 | // We just read it.
46 | return true;
47 | }
48 |
49 | }
50 |
--------------------------------------------------------------------------------
/bukkit/src/main/java/io/github/rothes/protocolstringreplacer/packetlistener/client/itemstack/BaseClientItemPacketListener.java:
--------------------------------------------------------------------------------
1 | package io.github.rothes.protocolstringreplacer.packetlistener.client.itemstack;
2 |
3 | import com.comphenix.protocol.PacketType;
4 | import de.tr7zw.changeme.nbtapi.NBT;
5 | import io.github.rothes.protocolstringreplacer.ProtocolStringReplacer;
6 | import io.github.rothes.protocolstringreplacer.packetlistener.client.BaseClientPacketListener;
7 | import io.github.rothes.protocolstringreplacer.api.user.PsrUser;
8 | import org.bukkit.inventory.ItemStack;
9 |
10 | import java.util.HashMap;
11 |
12 | public abstract class BaseClientItemPacketListener extends BaseClientPacketListener {
13 |
14 | protected BaseClientItemPacketListener(PacketType packetType) {
15 | super(packetType);
16 | }
17 |
18 | protected ItemStack restoreItem(PsrUser user, ItemStack itemStack) {
19 | if (!itemStack.hasItemMeta()) {
20 | return itemStack;
21 | }
22 | return NBT.get(itemStack, nbt -> {
23 | if (nbt.hasTag("ProtocolStringReplacer")) {
24 | Short uniqueCacheKey = nbt.getCompound("ProtocolStringReplacer").getShort("UserMetaCacheKey");
25 | if (uniqueCacheKey != null) {
26 | HashMap userItemRestoreCache = user.getItemRestoreCache();
27 | ItemStack original = userItemRestoreCache.get(uniqueCacheKey);
28 | if (original == null) {
29 | ProtocolStringReplacer.warn("Failed to get original ItemMeta by meta-cache key, ignoring.\n" + itemStack);
30 | return itemStack;
31 | }
32 | return original;
33 | } else {
34 | ProtocolStringReplacer.warn("Failed to get original ItemMeta by meta-cache key due to null, ignoring.\n" + itemStack);
35 | }
36 | }
37 | return itemStack;
38 | });
39 | }
40 |
41 | }
42 |
--------------------------------------------------------------------------------
/bukkit/src/main/java/io/github/rothes/protocolstringreplacer/packetlistener/client/itemstack/SetCreativeSlot.java:
--------------------------------------------------------------------------------
1 | package io.github.rothes.protocolstringreplacer.packetlistener.client.itemstack;
2 |
3 | import com.comphenix.protocol.PacketType;
4 | import com.comphenix.protocol.events.PacketEvent;
5 | import com.comphenix.protocol.reflect.StructureModifier;
6 | import io.github.rothes.protocolstringreplacer.api.user.PsrUser;
7 | import org.bukkit.inventory.ItemStack;
8 |
9 | public final class SetCreativeSlot extends BaseClientItemPacketListener {
10 |
11 | public SetCreativeSlot() {
12 | super(PacketType.Play.Client.SET_CREATIVE_SLOT);
13 | }
14 |
15 | protected void process(PacketEvent packetEvent) {
16 | PsrUser user = getEventUser(packetEvent);
17 | if (user == null) {
18 | return;
19 | }
20 | if (user.hasPermission("protocolstringreplacer.feature.usermetacache")) {
21 | StructureModifier itemModifier = packetEvent.getPacket().getItemModifier();
22 | ItemStack itemStack = itemModifier.read(0);
23 | itemModifier.write(0, restoreItem(user, itemStack));
24 | }
25 | }
26 |
27 | }
28 |
--------------------------------------------------------------------------------
/bukkit/src/main/java/io/github/rothes/protocolstringreplacer/packetlistener/client/itemstack/WindowClick.java:
--------------------------------------------------------------------------------
1 | package io.github.rothes.protocolstringreplacer.packetlistener.client.itemstack;
2 |
3 | import com.comphenix.protocol.PacketType;
4 | import com.comphenix.protocol.events.PacketEvent;
5 | import io.github.rothes.protocolstringreplacer.api.user.PsrUser;
6 | import org.bukkit.inventory.ItemStack;
7 |
8 | public final class WindowClick extends BaseClientItemPacketListener {
9 |
10 | public WindowClick() {
11 | super(PacketType.Play.Client.WINDOW_CLICK);
12 | }
13 |
14 | protected void process(PacketEvent packetEvent) {
15 | PsrUser user = getEventUser(packetEvent);
16 | if (user == null) {
17 | return;
18 | }
19 | if (user.hasPermission("protocolstringreplacer.feature.usermetacache.noncreative")) {
20 | com.comphenix.protocol.reflect.StructureModifier itemModifier = packetEvent.getPacket().getItemModifier();
21 | ItemStack itemStack = itemModifier.read(0);
22 | itemModifier.write(0, restoreItem(user, itemStack));
23 | }
24 | }
25 |
26 | }
27 |
--------------------------------------------------------------------------------
/bukkit/src/main/java/io/github/rothes/protocolstringreplacer/packetlistener/server/BaseServerComponentsPacketListener.java:
--------------------------------------------------------------------------------
1 | package io.github.rothes.protocolstringreplacer.packetlistener.server;
2 |
3 | import com.comphenix.protocol.PacketType;
4 | import com.comphenix.protocol.events.PacketEvent;
5 | import com.comphenix.protocol.reflect.StructureModifier;
6 | import io.github.rothes.protocolstringreplacer.ProtocolStringReplacer;
7 | import io.github.rothes.protocolstringreplacer.api.user.PsrUser;
8 | import io.github.rothes.protocolstringreplacer.util.SpigotUtils;
9 | import io.github.rothes.protocolstringreplacer.replacer.ListenType;
10 | import io.github.rothes.protocolstringreplacer.util.PaperUtils;
11 | import net.kyori.adventure.text.Component;
12 | import net.md_5.bungee.api.chat.BaseComponent;
13 |
14 | public abstract class BaseServerComponentsPacketListener extends BaseServerPacketListener {
15 |
16 | protected static final String BLOCKED_JSON = "{\"text\":\"ProtocolStringReplacer blocked message. If you see this, it's caused by other plugin(s).\"}";
17 |
18 | protected BaseServerComponentsPacketListener(PacketType packetType, ListenType listenType) {
19 | super(packetType, listenType);
20 | }
21 |
22 | protected static BaseComponent[] getSpigotComponent(StructureModifier