mirror of
https://github.com/NEZNAMY/TAB.git
synced 2026-11-12 20:22:01 -05:00
Compare commits
258
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c231220b42 | ||
|
|
1c6e5bec73 | ||
|
|
8919aaad94 | ||
|
|
ff6a2fe734 | ||
|
|
5ca4f7e411 | ||
|
|
2c105718b0 | ||
|
|
9cc471f66f | ||
|
|
e18867c938 | ||
|
|
27bd942c4c | ||
|
|
234ca72e73 | ||
|
|
f35a09a34d | ||
|
|
fa6d06a4ac | ||
|
|
ec6daeeadb | ||
|
|
f24f25f071 | ||
|
|
dbf0e3af9f | ||
|
|
6ecb607c0b | ||
|
|
1bf6b00be0 | ||
|
|
4b4f52e39a | ||
|
|
1170efbe02 | ||
|
|
3e86e73fed | ||
|
|
dd43861572 | ||
|
|
61a19ca9e0 | ||
|
|
d02af31e7c | ||
|
|
ab7b88b67b | ||
|
|
b80c816c5a | ||
|
|
c0ad6f49e7 | ||
|
|
91a56a8c2c | ||
|
|
135a473dc5 | ||
|
|
a8b53b07e4 | ||
|
|
171cbd4497 | ||
|
|
a1383612bc | ||
|
|
fe798c19f3 | ||
|
|
ead3add4cc | ||
|
|
db13c2d1c5 | ||
|
|
f2daab4b80 | ||
|
|
6fd02c83ab | ||
|
|
c288a0503a | ||
|
|
2e2b65a4bb | ||
|
|
982d0a53f9 | ||
|
|
f89ecfb595 | ||
|
|
bddb96a5fa | ||
|
|
39b29d12e4 | ||
|
|
6cb1e2c06d | ||
|
|
d932a9a862 | ||
|
|
341b552d0b | ||
|
|
1586bd9768 | ||
|
|
e8dde3a756 | ||
|
|
bb591bf56d | ||
|
|
8cf83b276a | ||
|
|
a1547a7288 | ||
|
|
0722403a23 | ||
|
|
cd4a91d975 | ||
|
|
c7870b4e9d | ||
|
|
239dae5a65 | ||
|
|
13c89d18d7 | ||
|
|
c5dc42eafe | ||
|
|
59b3faab1e | ||
|
|
b88beb5002 | ||
|
|
9fea35c25d | ||
|
|
372013bcc6 | ||
|
|
20ca58b570 | ||
|
|
9c4cca20fb | ||
|
|
6b8536a86e | ||
|
|
3b41857637 | ||
|
|
fa78ac2157 | ||
|
|
0a0bb9c83c | ||
|
|
36834a039e | ||
|
|
4960c898bb | ||
|
|
af61edbc5c | ||
|
|
237bfc08a1 | ||
|
|
032e9a089d | ||
|
|
ba83779dde | ||
|
|
267d72f844 | ||
|
|
b533cdb89f | ||
|
|
3f118ac76b | ||
|
|
08a8f0097c | ||
|
|
c7a3599e46 | ||
|
|
62f80baa69 | ||
|
|
09dc8cd437 | ||
|
|
c613ba401b | ||
|
|
866df0b5cf | ||
|
|
8f2b56ba05 | ||
|
|
2049885f11 | ||
|
|
4caef337d5 | ||
|
|
a644792bf6 | ||
|
|
54c7f8fc6a | ||
|
|
2e59b87bbe | ||
|
|
f89242ad8f | ||
|
|
845903788c | ||
|
|
53a9047c20 | ||
|
|
a2b74bbc30 | ||
|
|
50ef93cc45 | ||
|
|
e2a5da9c14 | ||
|
|
bf31116d0d | ||
|
|
d79fa8c4f3 | ||
|
|
87e0a7bea3 | ||
|
|
b34cabd55c | ||
|
|
704bd36c77 | ||
|
|
5c2c4d0f4b | ||
|
|
80cca5cb34 | ||
|
|
dcd603f2f5 | ||
|
|
1bee3b49bf | ||
|
|
11bcccb8f9 | ||
|
|
7425493706 | ||
|
|
dca0cfd424 | ||
|
|
21314def89 | ||
|
|
90e544d279 | ||
|
|
89e21558a1 | ||
|
|
b28cc51457 | ||
|
|
2d0a203b5f | ||
|
|
2948666c1d | ||
|
|
b2a2659546 | ||
|
|
e2eb7102c9 | ||
|
|
56301e653b | ||
|
|
1d825e08d2 | ||
|
|
c81a27709c | ||
|
|
2b143172f8 | ||
|
|
84330ec6eb | ||
|
|
0bd703de7f | ||
|
|
e6a55b7d5c | ||
|
|
b6ec7631d2 | ||
|
|
5abbd00d63 | ||
|
|
515c94976e | ||
|
|
912adad8f6 | ||
|
|
70fdd193a3 | ||
|
|
9d83e968fc | ||
|
|
04329da133 | ||
|
|
19ccfbb1a6 | ||
|
|
c53ab09abc | ||
|
|
a4d8daac1d | ||
|
|
99d566d521 | ||
|
|
aa37f73161 | ||
|
|
087518378d | ||
|
|
913d27929b | ||
|
|
530d39bec5 | ||
|
|
cf70dc3845 | ||
|
|
d1421fee3f | ||
|
|
3ec490b36e | ||
|
|
ee42685179 | ||
|
|
e02d687771 | ||
|
|
dddb592253 | ||
|
|
d0ad88d317 | ||
|
|
3d3ce0151f | ||
|
|
f017b0e562 | ||
|
|
4ba2bb669b | ||
|
|
9fc2424736 | ||
|
|
980c01ea70 | ||
|
|
758edcaf5c | ||
|
|
950f825e31 | ||
|
|
0a985f5c78 | ||
|
|
58353f4e6d | ||
|
|
c3d2b5c4b0 | ||
|
|
c2764b4b8a | ||
|
|
9bc8ad0d23 | ||
|
|
488c3540a8 | ||
|
|
1d03950a64 | ||
|
|
e24ea7df2e | ||
|
|
fe5e3d6405 | ||
|
|
db8584e40b | ||
|
|
2e4db38d1a | ||
|
|
f82470c1b1 | ||
|
|
650cc93fc0 | ||
|
|
e61070307a | ||
|
|
2fa46867e5 | ||
|
|
636b2e760a | ||
|
|
8cecf46310 | ||
|
|
a7bcda7eba | ||
|
|
a610dd2c70 | ||
|
|
df98c77a48 | ||
|
|
331dc33c86 | ||
|
|
8493b37171 | ||
|
|
2449c46165 | ||
|
|
a642c2d344 | ||
|
|
88c7b988e7 | ||
|
|
36651260c6 | ||
|
|
6c0072dc54 | ||
|
|
e38f5a77c0 | ||
|
|
6443926a79 | ||
|
|
489deb9ee6 | ||
|
|
a2039110e0 | ||
|
|
f1666b64ee | ||
|
|
d7e419c88b | ||
|
|
de8f8053be | ||
|
|
7aadef5c21 | ||
|
|
f8384dfbdf | ||
|
|
b91cbf827c | ||
|
|
096619d9f7 | ||
|
|
7b8006406c | ||
|
|
90483d549a | ||
|
|
5473055c1c | ||
|
|
f3b082b8e1 | ||
|
|
52fe99a080 | ||
|
|
68b1e941d1 | ||
|
|
109fce9b1a | ||
|
|
014d73dd3f | ||
|
|
ad82744e91 | ||
|
|
638f66ade4 | ||
|
|
c190efa7c4 | ||
|
|
b071eb3366 | ||
|
|
a7c7a86a90 | ||
|
|
0c21519cf6 | ||
|
|
d7f805b26e | ||
|
|
4f702feab3 | ||
|
|
46175ceb1f | ||
|
|
c206860736 | ||
|
|
b97c222490 | ||
|
|
53ad5e3cec | ||
|
|
e67ce8dbf4 | ||
|
|
ac661be5c4 | ||
|
|
ab4e386491 | ||
|
|
aa125b535e | ||
|
|
29df3bb5e2 | ||
|
|
80ee30a532 | ||
|
|
a20b1bcd89 | ||
|
|
4269abd2ca | ||
|
|
a73397065c | ||
|
|
5805a6c5a3 | ||
|
|
e813077c92 | ||
|
|
b1ae68e8c2 | ||
|
|
b6162b2d4a | ||
|
|
0da7854f7f | ||
|
|
a073747e66 | ||
|
|
0975e31371 | ||
|
|
a1231f1708 | ||
|
|
3581da0fe7 | ||
|
|
531810e633 | ||
|
|
36a1db78e2 | ||
|
|
0e58009ced | ||
|
|
ecdcc6894b | ||
|
|
677a2f9396 | ||
|
|
b14f30d4d1 | ||
|
|
4396df55ae | ||
|
|
de6ce93a31 | ||
|
|
b449b7cdfc | ||
|
|
de4412fcff | ||
|
|
8e9b34125d | ||
|
|
024b3175fa | ||
|
|
9fadc6df3b | ||
|
|
f51f8f0f2d | ||
|
|
d805df4887 | ||
|
|
d161c6c074 | ||
|
|
6603c9e682 | ||
|
|
157360c26c | ||
|
|
e16199b360 | ||
|
|
df42424970 | ||
|
|
22ce6ce75e | ||
|
|
e8dde142d2 | ||
|
|
44fe272ce5 | ||
|
|
23a8f32910 | ||
|
|
d523c0408e | ||
|
|
0c2edba316 | ||
|
|
7cfc643522 | ||
|
|
98b446efd2 | ||
|
|
bbf9aaed64 | ||
|
|
13d36457af | ||
|
|
4f850b0f2e | ||
|
|
7118e0d9d3 | ||
|
|
900edef407 |
No files matched your search
@@ -0,0 +1,12 @@
|
||||
# These are supported funding model platforms
|
||||
|
||||
github: # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2]
|
||||
patreon: # Replace with a single Patreon username
|
||||
open_collective: # Replace with a single Open Collective username
|
||||
ko_fi: # Replace with a single Ko-fi username
|
||||
tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel
|
||||
community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry
|
||||
liberapay: # Replace with a single Liberapay username
|
||||
issuehunt: # Replace with a single IssueHunt username
|
||||
otechie: # Replace with a single Otechie username
|
||||
custom: ['https://paypal.me/neznamy1'] # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2']
|
||||
@@ -0,0 +1,36 @@
|
||||
name: Build
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- master
|
||||
pull_request:
|
||||
types: [opened, synchronize, reopened]
|
||||
jobs:
|
||||
build:
|
||||
name: Build
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
with:
|
||||
fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis
|
||||
- name: Set up JDK 11
|
||||
uses: actions/setup-java@v1
|
||||
with:
|
||||
java-version: 11
|
||||
- name: Cache SonarCloud packages
|
||||
uses: actions/cache@v1
|
||||
with:
|
||||
path: ~/.sonar/cache
|
||||
key: ${{ runner.os }}-sonar
|
||||
restore-keys: ${{ runner.os }}-sonar
|
||||
- name: Cache Maven packages
|
||||
uses: actions/cache@v1
|
||||
with:
|
||||
path: ~/.m2
|
||||
key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }}
|
||||
restore-keys: ${{ runner.os }}-m2
|
||||
- name: Build and analyze
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any
|
||||
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
|
||||
run: mvn -B verify org.sonarsource.scanner.maven:sonar-maven-plugin:sonar
|
||||
+4
-5
@@ -1,8 +1,7 @@
|
||||
# Compiled class file
|
||||
*.class
|
||||
/bin/
|
||||
/target/
|
||||
/src/test/
|
||||
bin/
|
||||
target/
|
||||
|
||||
# Log file
|
||||
*.log
|
||||
@@ -31,8 +30,8 @@ hs_err_pid*
|
||||
.project
|
||||
|
||||
# intellij
|
||||
/.idea/
|
||||
.idea/
|
||||
|
||||
# other
|
||||
.gitattributes
|
||||
*.iml
|
||||
*.iml
|
||||
@@ -1,12 +1,11 @@
|
||||
## Introduction
|
||||
Here it is. After countless requests to go opensource, I did it to make those people quiet. It worked.
|
||||
It's already been a year and I still can't see any positives of it. This way I just made it easier for everyone to make a plugin as good, so people can stop using it and switch to something better.
|
||||
If you have a great argument why was making this open-source worth not only for those looking for premium features for free, please take your time and explain it to: Lionel#5648 (more names coming soon).
|
||||
It's already been a year and I still can't see any positives of it. This way I just made it easier for everyone to make a plugin as good, so people can stop using it and switch to something better. Or just get premium version for free.
|
||||
|
||||
|
||||
## Compiling
|
||||
Plugin can be compiled using maven. Once you've purchased the premium version, you can enable premium features by setting [this line to return true](https://github.com/NEZNAMY/TAB/blob/master/src/main/java/me/neznamy/tab/shared/TAB.java#L79) and apply your code improvements. Enabling it without purchasing the plugin may result in the features not working correctly.
|
||||
**No support is provided for self-compiled jars, only for official compilations.** If you compiled it yourself, it is highly likely you modified something, which might be the reason why is the plugin not working. If you didn't modify anything, you can just get the plugin from official download places.
|
||||
Plugin can be compiled using maven. Once you've purchased the premium version, you can enable premium features by setting [this line to return true](https://github.com/NEZNAMY/TAB/blob/master/shared/src/main/java/me/neznamy/tab/shared/TAB.java#L82) and apply your code improvements. Enabling it without purchasing the plugin may result in the features not working correctly.
|
||||
**No support is provided for self-compiled jars, only for official compilations.** If you compiled it yourself, it is highly likely you modified something, which might be the reason why is the plugin not working. If you didn't modify anything, you can just get the plugin from official download locations.
|
||||
|
||||
|
||||
## Links
|
||||
@@ -20,13 +19,8 @@ Premium version
|
||||
Bukkit bridge https://www.spigotmc.org/resources/83966/
|
||||
Wiki https://github.com/NEZNAMY/TAB/wiki
|
||||
Discord invite link: https://discord.gg/EaSvdk6
|
||||
|
||||
|
||||
## Downloads
|
||||
Official release: https://www.spigotmc.org/resources/57806/
|
||||
Pre-releases: https://github.com/NEZNAMY/TAB/releases
|
||||
|
||||
|
||||
|
||||
|
||||
## Maven Repository
|
||||
```
|
||||
<repositories>
|
||||
@@ -40,8 +34,8 @@ Pre-releases: https://github.com/NEZNAMY/TAB/releases
|
||||
<!-- TAB -->
|
||||
<dependency>
|
||||
<groupId>com.github.NEZNAMY</groupId>
|
||||
<artifactId>TAB-API</artifactId>
|
||||
<version>2.8.10</version>
|
||||
<artifactId>TAB</artifactId>
|
||||
<version>2.9.0</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
```
|
||||
```
|
||||
+150
@@ -0,0 +1,150 @@
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>me.neznamy</groupId>
|
||||
<artifactId>TAB</artifactId>
|
||||
<version>2.9.2</version>
|
||||
</parent>
|
||||
<artifactId>bukkit</artifactId>
|
||||
|
||||
<repositories>
|
||||
|
||||
<!-- Spigot API -->
|
||||
<repository>
|
||||
<id>spigot-repo</id>
|
||||
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
|
||||
</repository>
|
||||
|
||||
<!-- PlaceholderAPI -->
|
||||
<repository>
|
||||
<id>placeholderapi</id>
|
||||
<url>https://repo.extendedclip.com/content/repositories/placeholderapi/</url>
|
||||
</repository>
|
||||
|
||||
<!-- Vault -->
|
||||
<repository>
|
||||
<id>jitpack.io</id>
|
||||
<url>https://jitpack.io</url>
|
||||
</repository>
|
||||
|
||||
<!-- ViaVersion -->
|
||||
<repository>
|
||||
<id>viaversion</id>
|
||||
<url>https://repo.viaversion.com/</url>
|
||||
</repository>
|
||||
|
||||
<repository>
|
||||
<id>aikar</id>
|
||||
<url>https://repo.aikar.co/content/groups/aikar/</url>
|
||||
</repository>
|
||||
</repositories>
|
||||
|
||||
<dependencies>
|
||||
|
||||
<!-- TAB Core -->
|
||||
<dependency>
|
||||
<groupId>me.neznamy</groupId>
|
||||
<artifactId>shared</artifactId>
|
||||
<version>${project.version}</version>
|
||||
<scope>provided</scope>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>com.github.NEZNAMY</groupId>
|
||||
<artifactId>YamlAssist</artifactId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<groupId>com.googlecode.json-simple</groupId>
|
||||
<artifactId>json-simple</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
|
||||
<!-- Spigot API -->
|
||||
<dependency>
|
||||
<groupId>org.spigotmc</groupId>
|
||||
<artifactId>spigot-api</artifactId>
|
||||
<version>1.17-R0.1-SNAPSHOT</version>
|
||||
<scope>provided</scope>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>commons-lang</groupId>
|
||||
<artifactId>commons-lang</artifactId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<groupId>net.md-5</groupId>
|
||||
<artifactId>bungeecord-chat</artifactId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<groupId>com.google.code.gson</groupId>
|
||||
<artifactId>gson</artifactId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<groupId>org.yaml</groupId>
|
||||
<artifactId>snakeyaml</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
|
||||
<!-- PlaceholderAPI -->
|
||||
<dependency>
|
||||
<groupId>me.clip</groupId>
|
||||
<artifactId>placeholderapi</artifactId>
|
||||
<version>2.10.9</version>
|
||||
<scope>provided</scope>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>org.jetbrains</groupId>
|
||||
<artifactId>annotations</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
|
||||
<!-- Vault -->
|
||||
<dependency>
|
||||
<groupId>com.github.MilkBowl</groupId>
|
||||
<artifactId>VaultAPI</artifactId>
|
||||
<version>1.7</version>
|
||||
<scope>provided</scope>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>commons-lang</groupId>
|
||||
<artifactId>commons-lang</artifactId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<groupId>com.google.code.gson</groupId>
|
||||
<artifactId>gson</artifactId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<groupId>org.bukkit</groupId>
|
||||
<artifactId>bukkit</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
|
||||
<!-- ViaVersion -->
|
||||
<dependency>
|
||||
<groupId>com.viaversion</groupId>
|
||||
<artifactId>viaversion-api</artifactId>
|
||||
<version>4.0.0</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.mojang</groupId>
|
||||
<artifactId>authlib</artifactId>
|
||||
<version>1.11</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
|
||||
<!-- Bukkit Metrics -->
|
||||
<dependency>
|
||||
<groupId>org.bstats</groupId>
|
||||
<artifactId>bstats-bukkit</artifactId>
|
||||
<version>2.2.1</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
+16
-34
@@ -3,13 +3,10 @@ package me.neznamy.tab.platforms.bukkit;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.AsyncPlayerChatEvent;
|
||||
import org.bukkit.event.player.PlayerChangedWorldEvent;
|
||||
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
import org.bukkit.event.player.PlayerQuitEvent;
|
||||
import org.bukkit.event.player.PlayerRespawnEvent;
|
||||
import org.bukkit.event.player.PlayerToggleSneakEvent;
|
||||
|
||||
import me.neznamy.tab.shared.TAB;
|
||||
|
||||
@@ -35,7 +32,22 @@ public class BukkitEventListener implements Listener {
|
||||
@EventHandler(priority = EventPriority.LOWEST)
|
||||
public void onJoin(PlayerJoinEvent e) {
|
||||
if (TAB.getInstance().isDisabled()) return;
|
||||
TAB.getInstance().getCPUManager().runTask("processing PlayerJoinEvent", () -> TAB.getInstance().getFeatureManager().onJoin(new BukkitTabPlayer(e.getPlayer())));
|
||||
TAB.getInstance().getCPUManager().runTask("processing PlayerJoinEvent", () -> {
|
||||
try {
|
||||
int i = 0;
|
||||
int version;
|
||||
while ((version = Main.getProtocolVersion(e.getPlayer())) == -1 && ++i < 100) {
|
||||
Thread.sleep(2);
|
||||
}
|
||||
if (!e.getPlayer().isOnline()) return;
|
||||
if (i == 50) {
|
||||
TAB.getInstance().getErrorManager().printError("Failed to get protocol version of " + e.getPlayer().getName() + " after 50 retries");
|
||||
}
|
||||
TAB.getInstance().getFeatureManager().onJoin(new BukkitTabPlayer(e.getPlayer(), version));
|
||||
} catch (InterruptedException pluginDisabled) {
|
||||
Thread.currentThread().interrupt();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -57,34 +69,4 @@ public class BukkitEventListener implements Listener {
|
||||
if (TAB.getInstance().isDisabled()) return;
|
||||
if (TAB.getInstance().getFeatureManager().onCommand(TAB.getInstance().getPlayer(e.getPlayer().getUniqueId()), e.getMessage())) e.setCancelled(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Listener to AsyncPlayerChatEvent to forward the event to features
|
||||
* @param e chat event
|
||||
*/
|
||||
@EventHandler
|
||||
public void onChat(AsyncPlayerChatEvent e) {
|
||||
if (TAB.getInstance().isDisabled()) return;
|
||||
if (TAB.getInstance().getFeatureManager().onChat(TAB.getInstance().getPlayer(e.getPlayer().getUniqueId()), e.getMessage(), e.isCancelled())) e.setCancelled(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Listener to PlayerRespawnEvent to forward the event to features
|
||||
* @param e respawn event
|
||||
*/
|
||||
@EventHandler
|
||||
public void onRespawn(PlayerRespawnEvent e) {
|
||||
if (TAB.getInstance().isDisabled()) return;
|
||||
TAB.getInstance().getCPUManager().runTask("processing PlayerRespawnEvent", () -> TAB.getInstance().getFeatureManager().onRespawn(TAB.getInstance().getPlayer(e.getPlayer().getUniqueId())));
|
||||
}
|
||||
|
||||
/**
|
||||
* Listener to PlayerToggleSneakEvent to forward the event to features
|
||||
* @param e sneak event
|
||||
*/
|
||||
@EventHandler
|
||||
public void onSneak(PlayerToggleSneakEvent e) {
|
||||
if (TAB.getInstance().isDisabled()) return;
|
||||
TAB.getInstance().getCPUManager().runTask("processing PlayerToggleSneakEvent", () -> TAB.getInstance().getFeatureManager().onSneak(TAB.getInstance().getPlayer(e.getPlayer().getUniqueId()), e.isSneaking()));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,595 @@
|
||||
package me.neznamy.tab.platforms.bukkit;
|
||||
|
||||
import java.lang.reflect.Array;
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.EnumMap;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.EntityType;
|
||||
|
||||
import com.mojang.authlib.GameProfile;
|
||||
import com.mojang.authlib.properties.PropertyMap;
|
||||
import com.viaversion.viaversion.api.type.Type;
|
||||
import com.viaversion.viaversion.libs.gson.JsonParser;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.buffer.Unpooled;
|
||||
import me.neznamy.tab.platforms.bukkit.nms.NMSStorage;
|
||||
import me.neznamy.tab.platforms.bukkit.nms.datawatcher.DataWatcher;
|
||||
import me.neznamy.tab.shared.ProtocolVersion;
|
||||
import me.neznamy.tab.shared.TAB;
|
||||
import me.neznamy.tab.shared.packets.EnumChatFormat;
|
||||
import me.neznamy.tab.shared.packets.IChatBaseComponent;
|
||||
import me.neznamy.tab.shared.packets.IChatBaseComponent.ClickAction;
|
||||
import me.neznamy.tab.shared.packets.PacketBuilder;
|
||||
import me.neznamy.tab.shared.packets.PacketPlayOutBoss;
|
||||
import me.neznamy.tab.shared.packets.PacketPlayOutBoss.Action;
|
||||
import me.neznamy.tab.shared.packets.PacketPlayOutChat;
|
||||
import me.neznamy.tab.shared.packets.PacketPlayOutPlayerInfo;
|
||||
import me.neznamy.tab.shared.packets.PacketPlayOutPlayerInfo.EnumGamemode;
|
||||
import me.neznamy.tab.shared.packets.PacketPlayOutPlayerInfo.EnumPlayerInfoAction;
|
||||
import me.neznamy.tab.shared.packets.PacketPlayOutPlayerInfo.PlayerInfoData;
|
||||
import me.neznamy.tab.shared.packets.PacketPlayOutPlayerListHeaderFooter;
|
||||
import me.neznamy.tab.shared.packets.PacketPlayOutScoreboardDisplayObjective;
|
||||
import me.neznamy.tab.shared.packets.PacketPlayOutScoreboardObjective;
|
||||
import me.neznamy.tab.shared.packets.PacketPlayOutScoreboardObjective.EnumScoreboardHealthDisplay;
|
||||
import me.neznamy.tab.shared.packets.PacketPlayOutScoreboardScore;
|
||||
import me.neznamy.tab.shared.packets.PacketPlayOutScoreboardTeam;
|
||||
import me.neznamy.tab.shared.rgb.TextColor;
|
||||
|
||||
@SuppressWarnings({"unchecked", "rawtypes"})
|
||||
public class BukkitPacketBuilder implements PacketBuilder {
|
||||
|
||||
//nms storage
|
||||
private NMSStorage nms;
|
||||
|
||||
//entity type ids
|
||||
private EnumMap<EntityType, Integer> entityIds = new EnumMap<>(EntityType.class);
|
||||
|
||||
/**
|
||||
* Constructs new instance with given parameter
|
||||
* @param nms - nms storage
|
||||
*/
|
||||
public BukkitPacketBuilder(NMSStorage nms) {
|
||||
this.nms = nms;
|
||||
if (nms.getMinorVersion() >= 13) {
|
||||
entityIds.put(EntityType.ARMOR_STAND, 1);
|
||||
entityIds.put(EntityType.WITHER, 83);
|
||||
} else {
|
||||
entityIds.put(EntityType.WITHER, 64);
|
||||
if (nms.getMinorVersion() >= 8){
|
||||
entityIds.put(EntityType.ARMOR_STAND, 30);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object build(PacketPlayOutBoss packet, ProtocolVersion clientVersion) throws InstantiationException, IllegalAccessException, InvocationTargetException {
|
||||
if (nms.getMinorVersion() >= 9) {
|
||||
//1.9+ server, handled using bukkit api
|
||||
return packet;
|
||||
}
|
||||
if (clientVersion.getMinorVersion() >= 9 && Bukkit.getPluginManager().isPluginEnabled("ViaVersion")) {
|
||||
//1.9+ client on 1.8 server
|
||||
//technically redundant VV check as there is no other way to get 1.9 client on 1.8 server
|
||||
return buildBossPacketVia(packet, clientVersion);
|
||||
}
|
||||
|
||||
//<1.9 client and server
|
||||
return buildBossPacketEntity(packet, clientVersion);
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds 1.9 bossbar packet bytebuf using viaversion
|
||||
* @param packet - packet to build
|
||||
* @param clientVersion - client version
|
||||
* @return bytebuf with 1.9 bossbar packet content
|
||||
*/
|
||||
private ByteBuf buildBossPacketVia(PacketPlayOutBoss packet, ProtocolVersion clientVersion) {
|
||||
if (clientVersion == ProtocolVersion.UNKNOWN) return null; //preventing disconnect if packet ID changes and users do not update
|
||||
try {
|
||||
ByteBuf buf = Unpooled.buffer();
|
||||
Type.VAR_INT.writePrimitive(buf, clientVersion.getMinorVersion() == 15 || clientVersion.getMinorVersion() >= 17 ? 0x0D : 0x0C);
|
||||
Type.UUID.write(buf, packet.getId());
|
||||
Type.VAR_INT.writePrimitive(buf, packet.getOperation().ordinal());
|
||||
switch (packet.getOperation()) {
|
||||
case ADD:
|
||||
Type.COMPONENT.write(buf, JsonParser.parseString(IChatBaseComponent.optimizedComponent(packet.getName()).toString(clientVersion)));
|
||||
Type.FLOAT.writePrimitive(buf, packet.getPct());
|
||||
Type.VAR_INT.writePrimitive(buf, packet.getColor().ordinal());
|
||||
Type.VAR_INT.writePrimitive(buf, packet.getOverlay().ordinal());
|
||||
Type.BYTE.write(buf, packet.getFlags());
|
||||
break;
|
||||
case REMOVE:
|
||||
break;
|
||||
case UPDATE_PCT:
|
||||
Type.FLOAT.writePrimitive(buf, packet.getPct());
|
||||
break;
|
||||
case UPDATE_NAME:
|
||||
Type.COMPONENT.write(buf, JsonParser.parseString(IChatBaseComponent.optimizedComponent(packet.getName()).toString(clientVersion)));
|
||||
break;
|
||||
case UPDATE_STYLE:
|
||||
Type.VAR_INT.writePrimitive(buf, packet.getColor().ordinal());
|
||||
Type.VAR_INT.writePrimitive(buf, packet.getOverlay().ordinal());
|
||||
break;
|
||||
case UPDATE_PROPERTIES:
|
||||
Type.BYTE.write(buf, packet.getFlags());
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return buf;
|
||||
} catch (Exception t) {
|
||||
return TAB.getInstance().getErrorManager().printError(null, "Failed to create 1.9 bossbar packet using ViaVersion v" + Bukkit.getPluginManager().getPlugin("ViaVersion").getDescription().getVersion() + ". Is it the latest version?", t);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds entity bossbar packet
|
||||
* @param packet - packet to build
|
||||
* @param clientVersion - client version
|
||||
* @return entity bossbar packet
|
||||
* @throws InvocationTargetException
|
||||
* @throws IllegalAccessException
|
||||
* @throws InstantiationException
|
||||
*/
|
||||
private Object buildBossPacketEntity(PacketPlayOutBoss packet, ProtocolVersion clientVersion) throws InstantiationException, IllegalAccessException, InvocationTargetException {
|
||||
if (packet.getOperation() == Action.UPDATE_STYLE) return null; //nothing to do here
|
||||
|
||||
int entityId = packet.getId().hashCode();
|
||||
if (packet.getOperation() == Action.REMOVE) {
|
||||
return buildEntityDestroyPacket(entityId);
|
||||
}
|
||||
DataWatcher w = new DataWatcher();
|
||||
if (packet.getOperation() == Action.UPDATE_PCT || packet.getOperation() == Action.ADD) {
|
||||
float health = 300*packet.getPct();
|
||||
if (health == 0) health = 1;
|
||||
w.helper().setHealth(health);
|
||||
}
|
||||
if (packet.getOperation() == Action.UPDATE_NAME || packet.getOperation() == Action.ADD) {
|
||||
w.helper().setCustomName(packet.getName(), clientVersion);
|
||||
}
|
||||
if (packet.getOperation() == Action.ADD) {
|
||||
w.helper().setEntityFlags((byte) 32);
|
||||
return buildEntitySpawnPacket(entityId, null, EntityType.WITHER, new Location(null, 0,0,0), w);
|
||||
} else {
|
||||
return buildEntityMetadataPacket(entityId, w);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object build(PacketPlayOutChat packet, ProtocolVersion clientVersion) throws IllegalAccessException, InvocationTargetException, InstantiationException, NoSuchMethodException, SecurityException {
|
||||
Object component = stringToComponent(packet.getMessage().toString(clientVersion));
|
||||
Constructor<?> c = nms.getConstructor("PacketPlayOutChat");
|
||||
if (nms.getMinorVersion() >= 16) {
|
||||
return c.newInstance(component, nms.getEnum("ChatMessageType")[packet.getType().ordinal()], UUID.randomUUID());
|
||||
}
|
||||
if (nms.getMinorVersion() >= 12) {
|
||||
return c.newInstance(component, Enum.valueOf((Class<Enum>) nms.getClass("ChatMessageType"), packet.getType().toString()));
|
||||
}
|
||||
if (nms.getMinorVersion() >= 8) {
|
||||
return c.newInstance(component, (byte) packet.getType().ordinal());
|
||||
}
|
||||
if (nms.getMinorVersion() == 7) {
|
||||
return c.newInstance(component);
|
||||
}
|
||||
throw new IllegalStateException("Not supported on <1.7");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object build(PacketPlayOutPlayerInfo packet, ProtocolVersion clientVersion) throws InstantiationException, IllegalAccessException, InvocationTargetException, NoSuchMethodException, SecurityException, NegativeArraySizeException {
|
||||
if (nms.getMinorVersion() < 8) return null;
|
||||
Object nmsPacket = nms.getConstructor("PacketPlayOutPlayerInfo").newInstance(nms.getEnum("EnumPlayerInfoAction")[packet.getAction().ordinal()], Array.newInstance(nms.getClass("EntityPlayer"), 0));
|
||||
List<Object> items = new ArrayList<>();
|
||||
for (PlayerInfoData data : packet.getEntries()) {
|
||||
GameProfile profile = new GameProfile(data.getUniqueId(), data.getName());
|
||||
|
||||
if (data.getSkin() != null) profile.getProperties().putAll((PropertyMap) data.getSkin());
|
||||
List<Object> parameters = new ArrayList<>();
|
||||
if (nms.getConstructor("PlayerInfoData").getParameterCount() == 5) {
|
||||
parameters.add(nmsPacket);
|
||||
}
|
||||
parameters.add(profile);
|
||||
parameters.add(data.getLatency());
|
||||
parameters.add(data.getGameMode() == null ? null : nms.getEnum("EnumGamemode")[nms.getEnum("EnumGamemode").length-EnumGamemode.values().length+data.getGameMode().ordinal()]); //not_set was removed in 1.17
|
||||
parameters.add(data.getDisplayName() == null ? null : toNMSComponent(data.getDisplayName(), clientVersion));
|
||||
items.add(nms.getConstructor("PlayerInfoData").newInstance(parameters.toArray()));
|
||||
}
|
||||
nms.setField(nmsPacket, "PacketPlayOutPlayerInfo_PLAYERS", items);
|
||||
return nmsPacket;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object build(PacketPlayOutPlayerListHeaderFooter packet, ProtocolVersion clientVersion) throws InstantiationException, IllegalAccessException, InvocationTargetException {
|
||||
if (nms.getMinorVersion() < 8) return null;
|
||||
if (nms.getMinorVersion() >= 17) {
|
||||
return nms.getConstructor("PacketPlayOutPlayerListHeaderFooter").newInstance(toNMSComponent(packet.getHeader(), clientVersion), toNMSComponent(packet.getFooter(), clientVersion));
|
||||
}
|
||||
Object nmsPacket = nms.getConstructor("PacketPlayOutPlayerListHeaderFooter").newInstance();
|
||||
nms.setField(nmsPacket, "PacketPlayOutPlayerListHeaderFooter_HEADER", toNMSComponent(packet.getHeader(), clientVersion));
|
||||
nms.setField(nmsPacket, "PacketPlayOutPlayerListHeaderFooter_FOOTER", toNMSComponent(packet.getFooter(), clientVersion));
|
||||
return nmsPacket;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object build(PacketPlayOutScoreboardDisplayObjective packet, ProtocolVersion clientVersion) throws InstantiationException, IllegalAccessException, InvocationTargetException {
|
||||
return nms.getConstructor("PacketPlayOutScoreboardDisplayObjective").newInstance(packet.getSlot(), newScoreboardObjective(packet.getObjectiveName()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object build(PacketPlayOutScoreboardObjective packet, ProtocolVersion clientVersion) throws InstantiationException, IllegalAccessException, InvocationTargetException, NoSuchMethodException, SecurityException {
|
||||
String displayName = clientVersion.getMinorVersion() < 13 ? cutTo(packet.getDisplayName(), 32) : packet.getDisplayName();
|
||||
if (nms.getMinorVersion() >= 13) {
|
||||
return nms.getConstructor("PacketPlayOutScoreboardObjective").newInstance(nms.getConstructor("ScoreboardObjective").newInstance(null, packet.getObjectiveName(), null,
|
||||
toNMSComponent(IChatBaseComponent.optimizedComponent(displayName), clientVersion),
|
||||
packet.getRenderType() == null ? null : nms.getEnum("EnumScoreboardHealthDisplay")[packet.getRenderType().ordinal()]),
|
||||
packet.getMethod());
|
||||
}
|
||||
|
||||
Object nmsPacket = nms.getConstructor("PacketPlayOutScoreboardObjective").newInstance();
|
||||
nms.setField(nmsPacket, "PacketPlayOutScoreboardObjective_OBJECTIVENAME", packet.getObjectiveName());
|
||||
nms.setField(nmsPacket, "PacketPlayOutScoreboardObjective_DISPLAYNAME", displayName);
|
||||
if (nms.getMinorVersion() >= 8 && packet.getRenderType() != null) {
|
||||
nms.setField(nmsPacket, "PacketPlayOutScoreboardObjective_RENDERTYPE", Enum.valueOf((Class<Enum>) nms.getClass("EnumScoreboardHealthDisplay"), packet.getRenderType().toString()));
|
||||
}
|
||||
nms.setField(nmsPacket, "PacketPlayOutScoreboardObjective_METHOD", packet.getMethod());
|
||||
return nmsPacket;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object build(PacketPlayOutScoreboardScore packet, ProtocolVersion clientVersion) throws InstantiationException, IllegalAccessException, InvocationTargetException, NoSuchMethodException, SecurityException {
|
||||
if (nms.getMinorVersion() >= 13) {
|
||||
return nms.getConstructor("PacketPlayOutScoreboardScore_1_13").newInstance(nms.getEnum("EnumScoreboardAction")[packet.getAction().ordinal()], packet.getObjectiveName(), packet.getPlayer(), packet.getScore());
|
||||
}
|
||||
if (packet.getAction() == PacketPlayOutScoreboardScore.Action.REMOVE) {
|
||||
return nms.getConstructor("PacketPlayOutScoreboardScore_String").newInstance(packet.getPlayer());
|
||||
}
|
||||
Object score = nms.getConstructor("ScoreboardScore").newInstance(nms.getConstructor("Scoreboard").newInstance(), newScoreboardObjective(packet.getObjectiveName()), packet.getPlayer());
|
||||
nms.getMethod("ScoreboardScore_setScore").invoke(score, packet.getScore());
|
||||
if (nms.getMinorVersion() >= 8) {
|
||||
return nms.getConstructor("PacketPlayOutScoreboardScore").newInstance(score);
|
||||
}
|
||||
return nms.getConstructor("PacketPlayOutScoreboardScore").newInstance(score, 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object build(PacketPlayOutScoreboardTeam packet, ProtocolVersion clientVersion) throws IllegalAccessException, InvocationTargetException, InstantiationException, NoSuchMethodException, SecurityException {
|
||||
Object team;
|
||||
if (nms.getMinorVersion() >= 13) {
|
||||
team = createTeamModern(packet, clientVersion);
|
||||
} else {
|
||||
team = createTeamLegacy(packet, clientVersion);
|
||||
}
|
||||
if (nms.getMinorVersion() >= 17) {
|
||||
switch (packet.getMethod()) {
|
||||
case 0:
|
||||
return nms.getMethod("PacketPlayOutScoreboardTeam_ofBoolean").invoke(null, team, true);
|
||||
case 1:
|
||||
return nms.getMethod("PacketPlayOutScoreboardTeam_of").invoke(null, team);
|
||||
case 2:
|
||||
return nms.getMethod("PacketPlayOutScoreboardTeam_ofBoolean").invoke(null, team, false);
|
||||
case 3:
|
||||
return nms.getMethod("PacketPlayOutScoreboardTeam_ofString").invoke(null, team, packet.getPlayers().toArray(new String[0])[0], nms.getEnum("PacketPlayOutScoreboardTeam_a")[0]);
|
||||
case 4:
|
||||
return nms.getMethod("PacketPlayOutScoreboardTeam_ofString").invoke(null, team, packet.getPlayers().toArray(new String[0])[0], nms.getEnum("PacketPlayOutScoreboardTeam_a")[1]);
|
||||
default:
|
||||
throw new IllegalArgumentException("Invalid action: " + packet.getMethod());
|
||||
}
|
||||
}
|
||||
return nms.getConstructor("PacketPlayOutScoreboardTeam").newInstance(team, packet.getMethod());
|
||||
}
|
||||
|
||||
private Object createTeamModern(PacketPlayOutScoreboardTeam packet, ProtocolVersion clientVersion) throws InstantiationException, IllegalAccessException, InvocationTargetException, SecurityException {
|
||||
String prefix = packet.getPlayerPrefix();
|
||||
String suffix = packet.getPlayerSuffix();
|
||||
if (clientVersion.getMinorVersion() < 13) {
|
||||
prefix = cutTo(prefix, 16);
|
||||
suffix = cutTo(suffix, 16);
|
||||
}
|
||||
Object team = nms.getConstructor("ScoreboardTeam").newInstance(nms.getConstructor("Scoreboard").newInstance(), packet.getName());
|
||||
((Collection<String>)nms.getMethod("ScoreboardTeam_getPlayerNameSet").invoke(team)).addAll(packet.getPlayers());
|
||||
if (prefix != null && prefix.length() > 0) nms.getMethod("ScoreboardTeam_setPrefix").invoke(team, toNMSComponent(IChatBaseComponent.optimizedComponent(prefix), clientVersion));
|
||||
if (suffix != null && suffix.length() > 0) nms.getMethod("ScoreboardTeam_setSuffix").invoke(team, toNMSComponent(IChatBaseComponent.optimizedComponent(suffix), clientVersion));
|
||||
EnumChatFormat format = packet.getColor() != null ? packet.getColor() : EnumChatFormat.lastColorsOf(prefix);
|
||||
nms.getMethod("ScoreboardTeam_setColor").invoke(team, nms.getEnum("EnumChatFormat")[format.ordinal()]);
|
||||
nms.getMethod("ScoreboardTeam_setNameTagVisibility").invoke(team, String.valueOf(packet.getNametagVisibility()).equals("always") ? nms.getEnum("EnumNameTagVisibility")[0] : nms.getEnum("EnumNameTagVisibility")[1]);
|
||||
nms.getMethod("ScoreboardTeam_setCollisionRule").invoke(team, String.valueOf(packet.getCollisionRule()).equals("always") ? nms.getEnum("EnumTeamPush")[0] : nms.getEnum("EnumTeamPush")[1]);
|
||||
return team;
|
||||
}
|
||||
|
||||
private Object createTeamLegacy(PacketPlayOutScoreboardTeam packet, ProtocolVersion clientVersion) throws IllegalAccessException, InvocationTargetException, InstantiationException, SecurityException {
|
||||
String prefix = packet.getPlayerPrefix();
|
||||
String suffix = packet.getPlayerSuffix();
|
||||
if (clientVersion.getMinorVersion() < 13) {
|
||||
prefix = cutTo(prefix, 16);
|
||||
suffix = cutTo(suffix, 16);
|
||||
}
|
||||
Object team = nms.getConstructor("ScoreboardTeam").newInstance(nms.getConstructor("Scoreboard").newInstance(), packet.getName());
|
||||
((Collection<String>)nms.getMethod("ScoreboardTeam_getPlayerNameSet").invoke(team)).addAll(packet.getPlayers());
|
||||
if (prefix != null) nms.getMethod("ScoreboardTeam_setPrefix").invoke(team, prefix);
|
||||
if (suffix != null) nms.getMethod("ScoreboardTeam_setSuffix").invoke(team, suffix);
|
||||
if (nms.getMinorVersion() >= 8) nms.getMethod("ScoreboardTeam_setNameTagVisibility").invoke(team, String.valueOf(packet.getNametagVisibility()).equals("always") ? nms.getEnum("EnumNameTagVisibility")[0] : nms.getEnum("EnumNameTagVisibility")[1]);
|
||||
if (nms.getMinorVersion() >= 9) nms.getMethod("ScoreboardTeam_setCollisionRule").invoke(team, String.valueOf(packet.getCollisionRule()).equals("always") ? nms.getEnum("EnumTeamPush")[0] : nms.getEnum("EnumTeamPush")[1]);
|
||||
return team;
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds entity destroy packet with given parameter
|
||||
* @param id - entity id to destroy
|
||||
* @return destroy packet
|
||||
* @throws InvocationTargetException
|
||||
* @throws IllegalAccessException
|
||||
* @throws InstantiationException
|
||||
*/
|
||||
public Object buildEntityDestroyPacket(int id) throws InstantiationException, IllegalAccessException, InvocationTargetException {
|
||||
try {
|
||||
return nms.getConstructor("PacketPlayOutEntityDestroy").newInstance(new int[] {id});
|
||||
} catch (IllegalArgumentException e) {
|
||||
//1.17.0
|
||||
return nms.getConstructor("PacketPlayOutEntityDestroy").newInstance(id);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds entity metadata packet with given parameters
|
||||
* @param entityId - entity id
|
||||
* @param dataWatcher - datawatcher
|
||||
* @return metadata packet
|
||||
* @throws InvocationTargetException
|
||||
* @throws IllegalAccessException
|
||||
* @throws InstantiationException
|
||||
*/
|
||||
public Object buildEntityMetadataPacket(int entityId, DataWatcher dataWatcher) throws InstantiationException, IllegalAccessException, InvocationTargetException {
|
||||
return nms.getConstructor("PacketPlayOutEntityMetadata").newInstance(entityId, dataWatcher.toNMS(), true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds entity spawn packet with given parameters
|
||||
* @param entityId - entity id
|
||||
* @param uuid - entity uuid
|
||||
* @param entityType - entity type
|
||||
* @param loc - location to spawn at
|
||||
* @param dataWatcher - datawatcher
|
||||
* @return entity spawn packet
|
||||
* @throws IllegalAccessException
|
||||
* @throws InvocationTargetException
|
||||
* @throws InstantiationException
|
||||
*/
|
||||
public Object buildEntitySpawnPacket(int entityId, UUID uuid, EntityType entityType, Location loc, DataWatcher dataWatcher) throws IllegalAccessException, InstantiationException, InvocationTargetException {
|
||||
Object nmsPacket = nms.getConstructor("PacketPlayOutSpawnEntityLiving").newInstance(nms.getMethod("getHandle").invoke(Bukkit.getOnlinePlayers().iterator().next()));
|
||||
nms.setField(nmsPacket, "PacketPlayOutSpawnEntityLiving_ENTITYID", entityId);
|
||||
nms.setField(nmsPacket, "PacketPlayOutSpawnEntityLiving_ENTITYTYPE", entityIds.get(entityType));
|
||||
nms.setField(nmsPacket, "PacketPlayOutSpawnEntityLiving_YAW", (byte)(loc.getYaw() * 256.0f / 360.0f));
|
||||
nms.setField(nmsPacket, "PacketPlayOutSpawnEntityLiving_PITCH", (byte)(loc.getPitch() * 256.0f / 360.0f));
|
||||
if (nms.getMinorVersion() <= 14) {
|
||||
nms.setField(nmsPacket, "PacketPlayOutSpawnEntityLiving_DATAWATCHER", dataWatcher.toNMS());
|
||||
}
|
||||
if (nms.getMinorVersion() >= 9) {
|
||||
nms.setField(nmsPacket, "PacketPlayOutSpawnEntityLiving_UUID", uuid);
|
||||
nms.setField(nmsPacket, "PacketPlayOutSpawnEntityLiving_X", loc.getX());
|
||||
nms.setField(nmsPacket, "PacketPlayOutSpawnEntityLiving_Y", loc.getY());
|
||||
nms.setField(nmsPacket, "PacketPlayOutSpawnEntityLiving_Z", loc.getZ());
|
||||
} else {
|
||||
nms.setField(nmsPacket, "PacketPlayOutSpawnEntityLiving_X", floor(loc.getX()*32));
|
||||
nms.setField(nmsPacket, "PacketPlayOutSpawnEntityLiving_Y", floor(loc.getY()*32));
|
||||
nms.setField(nmsPacket, "PacketPlayOutSpawnEntityLiving_Z", floor(loc.getZ()*32));
|
||||
}
|
||||
return nmsPacket;
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds entity teleport packet with given parameters
|
||||
* @param entityId - entity id
|
||||
* @param location - location to teleport to
|
||||
* @return entity teleport packet
|
||||
* @throws IllegalAccessException
|
||||
* @throws InvocationTargetException
|
||||
* @throws InstantiationException
|
||||
*/
|
||||
public Object buildEntityTeleportPacket(int entityId, Location location) throws IllegalAccessException, InstantiationException, InvocationTargetException {
|
||||
Object nmsPacket = nms.getConstructor("PacketPlayOutEntityTeleport").newInstance(nms.getMethod("getHandle").invoke(Bukkit.getOnlinePlayers().iterator().next()));
|
||||
nms.setField(nmsPacket, "PacketPlayOutEntityTeleport_ENTITYID", entityId);
|
||||
if (nms.getMinorVersion() >= 9) {
|
||||
nms.setField(nmsPacket, "PacketPlayOutEntityTeleport_X", location.getX());
|
||||
nms.setField(nmsPacket, "PacketPlayOutEntityTeleport_Y", location.getY());
|
||||
nms.setField(nmsPacket, "PacketPlayOutEntityTeleport_Z", location.getZ());
|
||||
} else {
|
||||
nms.setField(nmsPacket, "PacketPlayOutEntityTeleport_X", floor(location.getX()*32));
|
||||
nms.setField(nmsPacket, "PacketPlayOutEntityTeleport_Y", floor(location.getY()*32));
|
||||
nms.setField(nmsPacket, "PacketPlayOutEntityTeleport_Z", floor(location.getZ()*32));
|
||||
}
|
||||
nms.setField(nmsPacket, "PacketPlayOutEntityTeleport_YAW", (byte) (location.getYaw()/360*256));
|
||||
nms.setField(nmsPacket, "PacketPlayOutEntityTeleport_PITCH", (byte) (location.getPitch()/360*256));
|
||||
return nmsPacket;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PacketPlayOutPlayerInfo readPlayerInfo(Object nmsPacket, ProtocolVersion clientVersion) throws IllegalAccessException, InvocationTargetException {
|
||||
if (nms.getMinorVersion() < 8) return null;
|
||||
EnumPlayerInfoAction action = EnumPlayerInfoAction.valueOf(nms.getField("PacketPlayOutPlayerInfo_ACTION").get(nmsPacket).toString());
|
||||
List<PlayerInfoData> listData = new ArrayList<>();
|
||||
for (Object nmsData : (List<?>) nms.getField("PacketPlayOutPlayerInfo_PLAYERS").get(nmsPacket)) {
|
||||
Object nmsGamemode = nms.getMethod("PlayerInfoData_getGamemode").invoke(nmsData);
|
||||
EnumGamemode gamemode = (nmsGamemode == null) ? null : EnumGamemode.valueOf(nmsGamemode.toString());
|
||||
GameProfile profile = (GameProfile) nms.getMethod("PlayerInfoData_getProfile").invoke(nmsData);
|
||||
Object nmsComponent = nms.getMethod("PlayerInfoData_getDisplayName").invoke(nmsData);
|
||||
IChatBaseComponent listName = nmsComponent == null ? null : fromNMSComponent(nmsComponent);
|
||||
listData.add(new PlayerInfoData(profile.getName(), profile.getId(), profile.getProperties(), (int) nms.getMethod("PlayerInfoData_getLatency").invoke(nmsData), gamemode, listName));
|
||||
}
|
||||
return new PacketPlayOutPlayerInfo(action, listData);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PacketPlayOutScoreboardObjective readObjective(Object nmsPacket, ProtocolVersion clientVersion) throws IllegalAccessException {
|
||||
String objective = (String) nms.getField("PacketPlayOutScoreboardObjective_OBJECTIVENAME").get(nmsPacket);
|
||||
String displayName;
|
||||
Object component = nms.getField("PacketPlayOutScoreboardObjective_DISPLAYNAME").get(nmsPacket);
|
||||
if (nms.getMinorVersion() >= 13) {
|
||||
IChatBaseComponent c = component == null ? null : fromNMSComponent(component);
|
||||
displayName = c == null ? null : c.toLegacyText();
|
||||
} else {
|
||||
displayName = (String) component;
|
||||
}
|
||||
EnumScoreboardHealthDisplay renderType = null;
|
||||
if (nms.getMinorVersion() >= 8) {
|
||||
Object nmsRender = nms.getField("PacketPlayOutScoreboardObjective_RENDERTYPE").get(nmsPacket);
|
||||
if (nmsRender != null) {
|
||||
renderType = EnumScoreboardHealthDisplay.valueOf(nmsRender.toString());
|
||||
}
|
||||
}
|
||||
int method = nms.getField("PacketPlayOutScoreboardObjective_METHOD").getInt(nmsPacket);
|
||||
return new PacketPlayOutScoreboardObjective(method, objective, displayName, renderType);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PacketPlayOutScoreboardDisplayObjective readDisplayObjective(Object nmsPacket, ProtocolVersion clientVersion) throws IllegalAccessException {
|
||||
return new PacketPlayOutScoreboardDisplayObjective(
|
||||
nms.getField("PacketPlayOutScoreboardDisplayObjective_POSITION").getInt(nmsPacket),
|
||||
(String) nms.getField("PacketPlayOutScoreboardDisplayObjective_OBJECTIVENAME").get(nmsPacket)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* A method yoinked from minecraft code used to convert double to int
|
||||
* @param paramDouble double value
|
||||
* @return int value
|
||||
*/
|
||||
private int floor(double paramDouble){
|
||||
int i = (int)paramDouble;
|
||||
return paramDouble < i ? i - 1 : i;
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts json string into a component
|
||||
* @param json json as string
|
||||
* @return NMS component
|
||||
* @throws InvocationTargetException
|
||||
* @throws IllegalAccessException
|
||||
*/
|
||||
public Object stringToComponent(String json) throws IllegalAccessException, InvocationTargetException {
|
||||
if (json == null) return null;
|
||||
return nms.getMethod("ChatSerializer_DESERIALIZE").invoke(null, json);
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts minecraft IChatBaseComponent into TAB's component class. Currently does not support hover event.
|
||||
* @param component - component to convert
|
||||
* @return converted component
|
||||
* @throws IllegalAccessException
|
||||
*/
|
||||
public IChatBaseComponent fromNMSComponent(Object component) throws IllegalAccessException {
|
||||
long time = System.nanoTime();
|
||||
IChatBaseComponent obj = fromNMSComponent0(component);
|
||||
TAB.getInstance().getCPUManager().addMethodTime("fromNMSComponent", System.nanoTime()-time);
|
||||
return obj;
|
||||
}
|
||||
|
||||
//separate method to prevent extras counting cpu again due to recursion and finally showing higher usage than real
|
||||
public IChatBaseComponent fromNMSComponent0(Object component) throws IllegalAccessException {
|
||||
if (!nms.getClass("ChatComponentText").isInstance(component)) return null; //paper
|
||||
IChatBaseComponent chat = new IChatBaseComponent((String) nms.getField("ChatComponentText_text").get(component));
|
||||
Object modifier = nms.getField("ChatBaseComponent_modifier").get(component);
|
||||
if (modifier != null) {
|
||||
Object color = nms.getField("ChatModifier_color").get(modifier);
|
||||
if (color != null) {
|
||||
if (nms.getMinorVersion() >= 16) {
|
||||
String name = (String) nms.getField("ChatHexColor_name").get(color);
|
||||
if (name != null) {
|
||||
//legacy code
|
||||
chat.setColor(new TextColor(EnumChatFormat.valueOf(name.toUpperCase())));
|
||||
} else {
|
||||
int rgb = (int) nms.getField("ChatHexColor_rgb").get(color);
|
||||
chat.setColor(new TextColor((rgb >> 16) & 0xFF, (rgb >> 8) & 0xFF, rgb & 0xFF));
|
||||
}
|
||||
} else {
|
||||
chat.setColor(new TextColor(EnumChatFormat.valueOf(((Enum)color).name())));
|
||||
}
|
||||
}
|
||||
chat.setBold((Boolean) nms.getField("ChatModifier_bold").get(modifier));
|
||||
chat.setItalic((Boolean) nms.getField("ChatModifier_italic").get(modifier));
|
||||
chat.setObfuscated((Boolean) nms.getField("ChatModifier_obfuscated").get(modifier));
|
||||
chat.setStrikethrough((Boolean) nms.getField("ChatModifier_strikethrough").get(modifier));
|
||||
chat.setUnderlined((Boolean) nms.getField("ChatModifier_underlined").get(modifier));
|
||||
Object clickEvent = nms.getField("ChatModifier_clickEvent").get(modifier);
|
||||
if (clickEvent != null) {
|
||||
chat.onClick(ClickAction.valueOf(nms.getField("ChatClickable_action").get(clickEvent).toString().toUpperCase()), (String) nms.getField("ChatClickable_value").get(clickEvent));
|
||||
}
|
||||
}
|
||||
for (Object extra : (List<Object>) nms.getField("ChatBaseComponent_extra").get(component)) {
|
||||
chat.addExtra(fromNMSComponent0(extra));
|
||||
}
|
||||
return chat;
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts TAB's IChatBaseComponent into minecraft's component. Currently does not support hover event.
|
||||
* @param component - component to convert
|
||||
* @param clientVersion - client version used to decide RGB conversion
|
||||
* @return converted component
|
||||
* @throws InvocationTargetException
|
||||
* @throws IllegalAccessException
|
||||
* @throws InstantiationException
|
||||
*/
|
||||
public Object toNMSComponent(IChatBaseComponent component, ProtocolVersion clientVersion) throws InstantiationException, IllegalAccessException, InvocationTargetException {
|
||||
long time = System.nanoTime();
|
||||
Object obj = toNMSComponent0(component, clientVersion);
|
||||
TAB.getInstance().getCPUManager().addMethodTime("toNMSComponent", System.nanoTime()-time);
|
||||
return obj;
|
||||
}
|
||||
|
||||
//separate method to prevent extras counting cpu again due to recursion and finally showing higher usage than real
|
||||
private Object toNMSComponent0(IChatBaseComponent component, ProtocolVersion clientVersion) throws InstantiationException, IllegalAccessException, InvocationTargetException {
|
||||
if (component == null) return null;
|
||||
Object chat = nms.getConstructor("ChatComponentText").newInstance(component.getText());
|
||||
Object modifier;
|
||||
if (nms.getMinorVersion() >= 16) {
|
||||
Object color = null;
|
||||
if (component.getColor() != null) {
|
||||
if (clientVersion.getMinorVersion() >= 16) {
|
||||
color = nms.getMethod("ChatHexColor_ofInt").invoke(null, (component.getColor().getRed() << 16) + (component.getColor().getGreen() << 8) + component.getColor().getBlue());
|
||||
} else {
|
||||
color = nms.getMethod("ChatHexColor_ofString").invoke(null, component.getColor().getLegacyColor().toString().toLowerCase());
|
||||
}
|
||||
}
|
||||
modifier = nms.getConstructor("ChatModifier").newInstance(
|
||||
color,
|
||||
component.getBold(),
|
||||
component.getItalic(),
|
||||
component.getUnderlined(),
|
||||
component.getStrikethrough(),
|
||||
component.getObfuscated(),
|
||||
component.getClickAction() == null ? null : nms.getConstructor("ChatClickable").newInstance(nms.getMethod("EnumClickAction_a").invoke(null, component.getClickAction().toString().toLowerCase()), component.getClickValue().toString()),
|
||||
null, //need to make it for 1.16
|
||||
null, null);
|
||||
} else {
|
||||
modifier = nms.getConstructor("ChatModifier").newInstance();
|
||||
if (component.getClickAction() != null){
|
||||
nms.setField(modifier, "ChatModifier_clickEvent", nms.getConstructor("ChatClickable").newInstance(nms.getMethod("EnumClickAction_a").invoke(null, component.getClickAction().toString().toLowerCase()), component.getClickValue().toString()));
|
||||
}
|
||||
if (component.getColor() != null) nms.setField(modifier, "ChatModifier_color", Enum.valueOf((Class<Enum>) nms.getClass("EnumChatFormat"), component.getColor().getLegacyColor().toString()));
|
||||
nms.setField(modifier, "ChatModifier_bold", component.getBold());
|
||||
nms.setField(modifier, "ChatModifier_italic", component.getItalic());
|
||||
nms.setField(modifier, "ChatModifier_underlined", component.getUnderlined());
|
||||
nms.setField(modifier, "ChatModifier_strikethrough", component.getStrikethrough());
|
||||
nms.setField(modifier, "ChatModifier_obfuscated", component.getObfuscated());
|
||||
}
|
||||
nms.setField(chat, "ChatBaseComponent_modifier", modifier);
|
||||
for (IChatBaseComponent extra : component.getExtra()) {
|
||||
nms.getMethod("ChatComponentText_addSibling").invoke(chat, toNMSComponent0(extra, clientVersion));
|
||||
}
|
||||
return chat;
|
||||
}
|
||||
|
||||
private Object newScoreboardObjective(String objectiveName) throws InstantiationException, IllegalAccessException, InvocationTargetException {
|
||||
if (nms.getMinorVersion() >= 13) {
|
||||
return nms.getConstructor("ScoreboardObjective").newInstance(null, objectiveName, null, stringToComponent("{\"text\":\"\"}"), null);
|
||||
}
|
||||
return nms.getConstructor("ScoreboardObjective").newInstance(null, objectiveName, nms.getFields(nms.getClass("IScoreboardCriteria"), nms.getClass("IScoreboardCriteria")).get(0).get(null));
|
||||
}
|
||||
}
|
||||
+43
-38
@@ -17,7 +17,7 @@ import me.neznamy.tab.shared.features.PipelineInjector;
|
||||
public class BukkitPipelineInjector extends PipelineInjector {
|
||||
|
||||
//handler to inject before
|
||||
private final String INJECT_POSITION = "packet_handler";
|
||||
private static final String INJECT_POSITION = "packet_handler";
|
||||
|
||||
//nms storage
|
||||
private NMSStorage nms;
|
||||
@@ -55,35 +55,6 @@ public class BukkitPipelineInjector extends PipelineInjector {
|
||||
//java.util.NoSuchElementException: TABReader
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes all real players from team if packet does not come from TAB and reports this to override log
|
||||
* @param packetPlayOutScoreboardTeam - team packet
|
||||
* @throws Exception - if reflection fails
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
private void modifyPlayers(Object packetPlayOutScoreboardTeam) throws Exception {
|
||||
long time = System.nanoTime();
|
||||
if (nms.PacketPlayOutScoreboardTeam_SIGNATURE.getInt(packetPlayOutScoreboardTeam) != 69) {
|
||||
Collection<String> players = (Collection<String>) nms.PacketPlayOutScoreboardTeam_PLAYERS.get(packetPlayOutScoreboardTeam);
|
||||
//creating a new list to prevent NoSuchFieldException in minecraft packet encoder when a player is removed
|
||||
Collection<String> newList = new ArrayList<String>();
|
||||
for (String entry : players) {
|
||||
TabPlayer p = tab.getPlayer(entry);
|
||||
if (p == null) {
|
||||
newList.add(entry);
|
||||
continue;
|
||||
}
|
||||
if (tab.getFeatureManager().getNameTagFeature().isDisabledWorld(p.getWorldName())) {
|
||||
newList.add(entry);
|
||||
} else {
|
||||
logTeamOverride((String) nms.PacketPlayOutScoreboardTeam_NAME.get(packetPlayOutScoreboardTeam), entry);
|
||||
}
|
||||
}
|
||||
nms.PacketPlayOutScoreboardTeam_PLAYERS.set(packetPlayOutScoreboardTeam, newList);
|
||||
}
|
||||
tab.getCPUManager().addTime(TabFeature.NAMETAGS, UsageType.ANTI_OVERRIDE, System.nanoTime()-time);
|
||||
}
|
||||
|
||||
/**
|
||||
* Custom channel duplex handler override
|
||||
@@ -102,38 +73,72 @@ public class BukkitPipelineInjector extends PipelineInjector {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void channelRead(ChannelHandlerContext context, Object packet) throws Exception {
|
||||
public void channelRead(ChannelHandlerContext context, Object packet) {
|
||||
try {
|
||||
Object modifiedPacket = tab.getFeatureManager().onPacketReceive(player, packet);
|
||||
if (modifiedPacket != null) super.channelRead(context, modifiedPacket);
|
||||
} catch (Throwable e){
|
||||
} catch (Exception e){
|
||||
tab.getErrorManager().printError("An error occurred when reading packets", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(ChannelHandlerContext context, Object packet, ChannelPromise channelPromise) throws Exception {
|
||||
public void write(ChannelHandlerContext context, Object packet, ChannelPromise channelPromise) {
|
||||
try {
|
||||
if (nms.PacketPlayOutPlayerInfo.isInstance(packet)) {
|
||||
if (nms.getClass("PacketPlayOutPlayerInfo").isInstance(packet)) {
|
||||
super.write(context, tab.getFeatureManager().onPacketPlayOutPlayerInfo(player, packet), channelPromise);
|
||||
return;
|
||||
}
|
||||
if (tab.getFeatureManager().getNameTagFeature() != null && antiOverrideTeams && nms.PacketPlayOutScoreboardTeam.isInstance(packet)) {
|
||||
if (tab.getFeatureManager().getNameTagFeature() != null && antiOverrideTeams && nms.getClass("PacketPlayOutScoreboardTeam").isInstance(packet)) {
|
||||
modifyPlayers(packet);
|
||||
super.write(context, packet, channelPromise);
|
||||
return;
|
||||
}
|
||||
if (nms.PacketPlayOutScoreboardDisplayObjective.isInstance(packet) && antiOverrideObjectives && tab.getFeatureManager().onDisplayObjective(player, packet)) {
|
||||
if (nms.getClass("PacketPlayOutScoreboardDisplayObjective").isInstance(packet) && antiOverrideObjectives && tab.getFeatureManager().onDisplayObjective(player, packet)) {
|
||||
return;
|
||||
}
|
||||
if (antiOverrideObjectives && nms.PacketPlayOutScoreboardObjective.isInstance(packet)) {
|
||||
if (antiOverrideObjectives && nms.getClass("PacketPlayOutScoreboardObjective").isInstance(packet)) {
|
||||
tab.getFeatureManager().onObjective(player, packet);
|
||||
}
|
||||
tab.getFeatureManager().onPacketSend(player, packet);
|
||||
} catch (Throwable e){
|
||||
tab.getErrorManager().printError("An error occurred when reading packets", e);
|
||||
}
|
||||
super.write(context, packet, channelPromise);
|
||||
try {
|
||||
super.write(context, packet, channelPromise);
|
||||
} catch (Throwable e) {
|
||||
tab.getErrorManager().printError("Failed to forward packet " + packet.getClass().getSimpleName() + " to " + player.getName(), e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes all real players from team if packet does not come from TAB and reports this to override log
|
||||
* @param packetPlayOutScoreboardTeam - team packet
|
||||
* @throws IllegalAccessException
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
private void modifyPlayers(Object packetPlayOutScoreboardTeam) throws IllegalAccessException {
|
||||
long time = System.nanoTime();
|
||||
Collection<String> players = (Collection<String>) nms.getField("PacketPlayOutScoreboardTeam_PLAYERS").get(packetPlayOutScoreboardTeam);
|
||||
String teamName = (String) nms.getField("PacketPlayOutScoreboardTeam_NAME").get(packetPlayOutScoreboardTeam);
|
||||
if (players == null) return;
|
||||
//creating a new list to prevent NoSuchFieldException in minecraft packet encoder when a player is removed
|
||||
Collection<String> newList = new ArrayList<>();
|
||||
for (String entry : players) {
|
||||
TabPlayer p = tab.getPlayer(entry);
|
||||
if (p == null) {
|
||||
newList.add(entry);
|
||||
continue;
|
||||
}
|
||||
if (!tab.getFeatureManager().getNameTagFeature().getPlayersInDisabledWorlds().contains(p) && !p.hasTeamHandlingPaused() &&
|
||||
!teamName.equals(p.getTeamName())) {
|
||||
logTeamOverride(teamName, entry);
|
||||
} else {
|
||||
newList.add(entry);
|
||||
}
|
||||
}
|
||||
nms.setField(packetPlayOutScoreboardTeam, "PacketPlayOutScoreboardTeam_PLAYERS", newList);
|
||||
tab.getCPUManager().addTime(TabFeature.NAMETAGS, UsageType.ANTI_OVERRIDE, System.nanoTime()-time);
|
||||
}
|
||||
}
|
||||
}
|
||||
+74
-77
@@ -1,11 +1,9 @@
|
||||
package me.neznamy.tab.platforms.bukkit;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Method;
|
||||
import java.text.DecimalFormat;
|
||||
import java.text.NumberFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.UUID;
|
||||
@@ -13,10 +11,12 @@ import java.util.UUID;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Statistic;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.bukkit.plugin.RegisteredServiceProvider;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import me.neznamy.tab.api.TabPlayer;
|
||||
import me.neznamy.tab.platforms.bukkit.nms.NMSStorage;
|
||||
import me.neznamy.tab.shared.TAB;
|
||||
import me.neznamy.tab.shared.features.PlaceholderManager;
|
||||
import me.neznamy.tab.shared.placeholders.Placeholder;
|
||||
@@ -46,9 +46,14 @@ public class BukkitPlaceholderRegistry implements PlaceholderRegistry {
|
||||
//placeholder registry buffer
|
||||
private List<Placeholder> placeholders;
|
||||
|
||||
private Object essentials;
|
||||
|
||||
//essentials methods
|
||||
private Method getUser;
|
||||
private Method getNickname;
|
||||
private Method essGetUser;
|
||||
private Method essGetNickname;
|
||||
private Method essIsAfk;
|
||||
|
||||
private Method purpurIsAfk;
|
||||
|
||||
/**
|
||||
* Constructs new instance with given parameter
|
||||
@@ -57,16 +62,18 @@ public class BukkitPlaceholderRegistry implements PlaceholderRegistry {
|
||||
public BukkitPlaceholderRegistry(JavaPlugin plugin) {
|
||||
decimal2.applyPattern("#.##");
|
||||
this.plugin = plugin;
|
||||
essentials = Bukkit.getPluginManager().getPlugin("Essentials");
|
||||
if (Bukkit.getPluginManager().isPluginEnabled("Vault")) {
|
||||
RegisteredServiceProvider<Economy> rspEconomy = Bukkit.getServicesManager().getRegistration(Economy.class);
|
||||
if (rspEconomy != null) economy = rspEconomy.getProvider();
|
||||
RegisteredServiceProvider<Chat> rspChat = Bukkit.getServicesManager().getRegistration(Chat.class);
|
||||
if (rspChat != null) chat = rspChat.getProvider();
|
||||
}
|
||||
if (Bukkit.getPluginManager().isPluginEnabled("Essentials")) {
|
||||
if (essentials != null) {
|
||||
try {
|
||||
getUser = Class.forName("com.earth2me.essentials.Essentials").getMethod("getUser", Player.class);
|
||||
getNickname = Class.forName("com.earth2me.essentials.User").getMethod("getNickname");
|
||||
essGetUser = Class.forName("com.earth2me.essentials.Essentials").getMethod("getUser", Player.class);
|
||||
essGetNickname = Class.forName("com.earth2me.essentials.User").getMethod("getNickname");
|
||||
essIsAfk = Class.forName("com.earth2me.essentials.User").getMethod("isAfk");
|
||||
} catch (Exception e) {
|
||||
TAB.getInstance().getErrorManager().printError("Failed to load essentials methods", e);
|
||||
}
|
||||
@@ -75,7 +82,7 @@ public class BukkitPlaceholderRegistry implements PlaceholderRegistry {
|
||||
|
||||
@Override
|
||||
public List<Placeholder> registerPlaceholders() {
|
||||
placeholders = new ArrayList<Placeholder>();
|
||||
placeholders = new ArrayList<>();
|
||||
placeholders.add(new PlayerPlaceholder("%money%", 1000) {
|
||||
public String get(TabPlayer p) {
|
||||
if (economy != null) return decimal2.format(economy.getBalance((Player) p.getPlayer()));
|
||||
@@ -93,40 +100,42 @@ public class BukkitPlaceholderRegistry implements PlaceholderRegistry {
|
||||
return String.valueOf(((Player) p.getPlayer()).getStatistic(Statistic.DEATHS));
|
||||
}
|
||||
});
|
||||
placeholders.add(new PlayerPlaceholder("%health%", 100) {
|
||||
public String get(TabPlayer p) {
|
||||
return String.valueOf((int) Math.ceil(((Player) p.getPlayer()).getHealth()));
|
||||
}
|
||||
});
|
||||
placeholders.add(new ServerPlaceholder("%tps%", 1000) {
|
||||
public String get() {
|
||||
try {
|
||||
Object nmsServer = Bukkit.getServer().getClass().getMethod("getServer").invoke(Bukkit.getServer());
|
||||
double value = ((double[]) nmsServer.getClass().getField("recentTps").get(nmsServer))[0];
|
||||
return decimal2.format(Math.min(20, value));
|
||||
} catch (Throwable t) {
|
||||
} catch (Exception t) {
|
||||
return "-1";
|
||||
}
|
||||
}
|
||||
});
|
||||
placeholders.add(new PlayerPlaceholder("%canseeonline%", 2000) {
|
||||
public String get(TabPlayer p) {
|
||||
int var = 0;
|
||||
int count = 0;
|
||||
for (TabPlayer all : TAB.getInstance().getPlayers()){
|
||||
if (((Player) p.getPlayer()).canSee((Player) all.getPlayer())) var++;
|
||||
if (((Player) p.getPlayer()).canSee((Player) all.getPlayer())) count++;
|
||||
}
|
||||
return String.valueOf(var);
|
||||
return String.valueOf(count);
|
||||
}
|
||||
});
|
||||
placeholders.add(new PlayerPlaceholder("%canseestaffonline%", 2000) {
|
||||
public String get(TabPlayer p) {
|
||||
int var = 0;
|
||||
int count = 0;
|
||||
for (TabPlayer all : TAB.getInstance().getPlayers()){
|
||||
if (all.isStaff() && ((Player) p.getPlayer()).canSee((Player) all.getPlayer())) var++;
|
||||
if (all.isStaff() && ((Player) p.getPlayer()).canSee((Player) all.getPlayer())) count++;
|
||||
}
|
||||
return String.valueOf(var);
|
||||
return String.valueOf(count);
|
||||
}
|
||||
});
|
||||
if (NMSStorage.getInstance().getMinorVersion() >= 6) {
|
||||
placeholders.add(new PlayerPlaceholder("%health%", 100) {
|
||||
public String get(TabPlayer p) {
|
||||
return String.valueOf((int) Math.ceil(((Player) p.getPlayer()).getHealth()));
|
||||
}
|
||||
});
|
||||
}
|
||||
registerAFKPlaceholder();
|
||||
registerVaultPlaceholders();
|
||||
registerPositionPlaceholders();
|
||||
@@ -139,39 +148,39 @@ public class BukkitPlaceholderRegistry implements PlaceholderRegistry {
|
||||
* Registers AFK placeholder
|
||||
*/
|
||||
private void registerAFKPlaceholder() {
|
||||
String noAfk = TAB.getInstance().getConfiguration().config.getString("placeholders.afk-no", "");
|
||||
String yesAfk = TAB.getInstance().getConfiguration().config.getString("placeholders.afk-yes", " &4*&4&lAFK&4*&r");
|
||||
Plugin afkplus = Bukkit.getPluginManager().getPlugin("AFKPlus");
|
||||
boolean antiafkplus = Bukkit.getPluginManager().isPluginEnabled("AntiAFKPlus");
|
||||
try {
|
||||
purpurIsAfk = Player.class.getMethod("isAfk");
|
||||
} catch (NoSuchMethodException | SecurityException e1) {
|
||||
//not purpur
|
||||
}
|
||||
String noAfk = TAB.getInstance().getConfiguration().getConfig().getString("placeholders.afk-no", "");
|
||||
String yesAfk = TAB.getInstance().getConfiguration().getConfig().getString("placeholders.afk-yes", " &4*&4&lAFK&4*&r");
|
||||
placeholders.add(new PlayerPlaceholder("%afk%", 500) {
|
||||
public String get(TabPlayer p) {
|
||||
boolean afk = false;
|
||||
try {
|
||||
if (Bukkit.getPluginManager().isPluginEnabled("Essentials")) {
|
||||
Object user = Bukkit.getPluginManager().getPlugin("Essentials").getClass().getMethod("getUser", Player.class).invoke(Bukkit.getPluginManager().getPlugin("Essentials"), p.getPlayer());
|
||||
afk = (boolean) user.getClass().getMethod("isAfk").invoke(user);
|
||||
if (essentials != null) {
|
||||
Object user = essGetUser.invoke(Bukkit.getPluginManager().getPlugin("Essentials"), p.getPlayer());
|
||||
if ((boolean) essIsAfk.invoke(user)) return yesAfk;
|
||||
}
|
||||
if (Bukkit.getPluginManager().isPluginEnabled("AFKPlus")) {
|
||||
Object AFKPlus = Bukkit.getPluginManager().getPlugin("AFKPlus");
|
||||
Object AFKPlusPlayer = AFKPlus.getClass().getMethod("getPlayer", UUID.class).invoke(AFKPlus, p.getUniqueId());
|
||||
afk = (boolean) AFKPlusPlayer.getClass().getMethod("isAFK").invoke(AFKPlusPlayer);
|
||||
if (afkplus != null) {
|
||||
Object afkplusplayer = afkplus.getClass().getMethod("getPlayer", UUID.class).invoke(afkplus, p.getUniqueId());
|
||||
if ((boolean) afkplusplayer.getClass().getMethod("isAFK").invoke(afkplusplayer)) return yesAfk;
|
||||
}
|
||||
if (Bukkit.getPluginManager().isPluginEnabled("AntiAFKPlus")) {
|
||||
if (antiafkplus) {
|
||||
Object api = Class.forName("de.kinglol12345.AntiAFKPlus.api.AntiAFKPlusAPI").getDeclaredMethod("getAPI").invoke(null);
|
||||
afk = (boolean) api.getClass().getMethod("isAFK", Player.class).invoke(api, p.getPlayer());
|
||||
if ((boolean) api.getClass().getMethod("isAFK", Player.class).invoke(api, p.getPlayer())) return yesAfk;
|
||||
}
|
||||
if (Bukkit.getPluginManager().isPluginEnabled("xAntiAFK")) {
|
||||
afk = (boolean) Class.forName("ch.soolz.xantiafk.xAntiAFKAPI").getMethod("isAfk", Player.class).invoke(null, p.getPlayer());
|
||||
}
|
||||
if (Bukkit.getPluginManager().isPluginEnabled("AutoAFK")) {
|
||||
Object plugin = Bukkit.getPluginManager().getPlugin("AutoAFK");
|
||||
Field f = plugin.getClass().getDeclaredField("afkList");
|
||||
f.setAccessible(true);
|
||||
HashMap<?, ?> map = (HashMap<?, ?>) f.get(plugin);
|
||||
afk = map.containsKey(p.getPlayer());
|
||||
}
|
||||
} catch (Throwable t) {
|
||||
return TAB.getInstance().getErrorManager().printError("", "Failed to check AFK status of " + p.getName(), t);
|
||||
} catch (Exception e) {
|
||||
return TAB.getInstance().getErrorManager().printError("", "Failed to check AFK status of " + p.getName(), e);
|
||||
}
|
||||
return afk ? yesAfk : noAfk;
|
||||
try {
|
||||
if (purpurIsAfk != null && (boolean) purpurIsAfk.invoke(p.getPlayer())) return yesAfk;
|
||||
} catch (Exception e) {
|
||||
//not purpur
|
||||
}
|
||||
return noAfk;
|
||||
}
|
||||
@Override
|
||||
public String[] getNestedStrings(){
|
||||
@@ -188,23 +197,13 @@ public class BukkitPlaceholderRegistry implements PlaceholderRegistry {
|
||||
placeholders.add(new PlayerPlaceholder("%vault-prefix%", 500) {
|
||||
|
||||
public String get(TabPlayer p) {
|
||||
try {
|
||||
String prefix = chat.getPlayerPrefix((Player) p.getPlayer());
|
||||
return prefix != null ? prefix : "";
|
||||
} catch (Exception e) {
|
||||
return TAB.getInstance().getErrorManager().printError("", "Placeholder %vault-prefix% threw an exception", e);
|
||||
}
|
||||
return chat.getPlayerPrefix((Player) p.getPlayer());
|
||||
}
|
||||
});
|
||||
placeholders.add(new PlayerPlaceholder("%vault-suffix%", 500) {
|
||||
|
||||
public String get(TabPlayer p) {
|
||||
try {
|
||||
String suffix = chat.getPlayerSuffix((Player) p.getPlayer());
|
||||
return suffix != null ? suffix : "";
|
||||
} catch (Exception e) {
|
||||
return TAB.getInstance().getErrorManager().printError("", "Placeholder %vault-suffix% threw an exception", e);
|
||||
}
|
||||
return chat.getPlayerSuffix((Player) p.getPlayer());
|
||||
}
|
||||
});
|
||||
} else {
|
||||
@@ -246,17 +245,18 @@ public class BukkitPlaceholderRegistry implements PlaceholderRegistry {
|
||||
* Registers essentials placeholders
|
||||
*/
|
||||
private void registerEssentialsPlaceholders() {
|
||||
if (Bukkit.getPluginManager().isPluginEnabled("Essentials")) {
|
||||
if (essentials != null) {
|
||||
placeholders.add(new PlayerPlaceholder("%essentialsnick%", 1000) {
|
||||
public String get(TabPlayer p) {
|
||||
if (essGetNickname == null) return "<Internal plugin error>";
|
||||
String name = null;
|
||||
try {
|
||||
name = (String) getNickname.invoke(getUser.invoke(Bukkit.getPluginManager().getPlugin("Essentials"), p.getPlayer()));
|
||||
name = (String) essGetNickname.invoke(essGetUser.invoke(essentials, p.getPlayer()));
|
||||
} catch (Exception e) {
|
||||
TAB.getInstance().getErrorManager().printError("Failed to get Essentials nickname of " + p.getName(), e);
|
||||
}
|
||||
if (name == null || name.length() == 0) return p.getName();
|
||||
return TAB.getInstance().getConfiguration().essentialsNickPrefix + name;
|
||||
return TAB.getInstance().getConfiguration().getEssentialsNickPrefix() + name;
|
||||
}
|
||||
});
|
||||
} else {
|
||||
@@ -273,33 +273,30 @@ public class BukkitPlaceholderRegistry implements PlaceholderRegistry {
|
||||
*/
|
||||
private void registerSyncPlaceholders() {
|
||||
PlaceholderManager pl = TAB.getInstance().getPlaceholderManager();
|
||||
for (String identifier : pl.allUsedPlaceholderIdentifiers) {
|
||||
for (String identifier : pl.getAllUsedPlaceholderIdentifiers()) {
|
||||
if (identifier.startsWith("%sync:")) {
|
||||
int refresh;
|
||||
if (pl.serverPlaceholderRefreshIntervals.containsKey(identifier)) {
|
||||
refresh = pl.serverPlaceholderRefreshIntervals.get(identifier);
|
||||
} else if (pl.playerPlaceholderRefreshIntervals.containsKey(identifier)) {
|
||||
refresh = pl.playerPlaceholderRefreshIntervals.get(identifier);
|
||||
if (pl.getServerPlaceholderRefreshIntervals().containsKey(identifier)) {
|
||||
refresh = pl.getServerPlaceholderRefreshIntervals().get(identifier);
|
||||
} else if (pl.getPlayerPlaceholderRefreshIntervals().containsKey(identifier)) {
|
||||
refresh = pl.getPlayerPlaceholderRefreshIntervals().get(identifier);
|
||||
} else {
|
||||
refresh = pl.defaultRefresh;
|
||||
refresh = pl.getDefaultRefresh();
|
||||
}
|
||||
placeholders.add(new PlayerPlaceholder(identifier, refresh) {
|
||||
|
||||
@Override
|
||||
public String get(TabPlayer p) {
|
||||
Bukkit.getScheduler().runTask(plugin, new Runnable() {
|
||||
Bukkit.getScheduler().runTask(plugin, () -> {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
long time = System.nanoTime();
|
||||
String syncedPlaceholder = identifier.substring(6, identifier.length()-1);
|
||||
String value = ((BukkitPlatform) TAB.getInstance().getPlatform()).setPlaceholders((Player) p.getPlayer(), "%" + syncedPlaceholder + "%");
|
||||
lastValue.put(p.getName(), value);
|
||||
if (!forceUpdate.contains(p.getName())) forceUpdate.add(p.getName());
|
||||
TAB.getInstance().getCPUManager().addPlaceholderTime(getIdentifier(), System.nanoTime()-time);
|
||||
}
|
||||
long time = System.nanoTime();
|
||||
String syncedPlaceholder = identifier.substring(6, identifier.length()-1);
|
||||
String value = ((BukkitPlatform) TAB.getInstance().getPlatform()).setPlaceholders((Player) p.getPlayer(), "%" + syncedPlaceholder + "%");
|
||||
getLastValues().put(p.getName(), value);
|
||||
if (!getForceUpdate().contains(p.getName())) getForceUpdate().add(p.getName());
|
||||
TAB.getInstance().getCPUManager().addPlaceholderTime(getIdentifier(), System.nanoTime()-time);
|
||||
});
|
||||
return getLastValue(p);
|
||||
return getLastValues().get(p.getName());
|
||||
}
|
||||
});
|
||||
}
|
||||
+79
-107
@@ -1,23 +1,17 @@
|
||||
package me.neznamy.tab.platforms.bukkit;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import me.clip.placeholderapi.PlaceholderAPI;
|
||||
import me.neznamy.tab.api.TabPlayer;
|
||||
import me.neznamy.tab.api.event.BukkitTABLoadEvent;
|
||||
import me.neznamy.tab.platforms.bukkit.features.BossBar_legacy;
|
||||
import me.neznamy.tab.platforms.bukkit.features.ExpansionDownloader;
|
||||
import me.neznamy.tab.platforms.bukkit.features.WitherBossBar;
|
||||
import me.neznamy.tab.platforms.bukkit.features.PerWorldPlayerlist;
|
||||
import me.neznamy.tab.platforms.bukkit.features.PetFix;
|
||||
import me.neznamy.tab.platforms.bukkit.features.TabExpansion;
|
||||
@@ -25,11 +19,14 @@ import me.neznamy.tab.platforms.bukkit.features.unlimitedtags.NameTagX;
|
||||
import me.neznamy.tab.platforms.bukkit.nms.NMSStorage;
|
||||
import me.neznamy.tab.platforms.bukkit.permission.Vault;
|
||||
import me.neznamy.tab.shared.Platform;
|
||||
import me.neznamy.tab.shared.ProtocolVersion;
|
||||
import me.neznamy.tab.shared.TAB;
|
||||
import me.neznamy.tab.shared.config.ConfigurationFile;
|
||||
import me.neznamy.tab.shared.features.BelowName;
|
||||
import me.neznamy.tab.shared.features.NameTag;
|
||||
import me.neznamy.tab.shared.features.PingSpoof;
|
||||
import me.neznamy.tab.shared.features.PlaceholderManager;
|
||||
import me.neznamy.tab.shared.features.SpectatorFix;
|
||||
import me.neznamy.tab.shared.features.TabObjective;
|
||||
import me.neznamy.tab.shared.features.scoreboard.ScoreboardManager;
|
||||
import me.neznamy.tab.shared.permission.LuckPerms;
|
||||
import me.neznamy.tab.shared.permission.None;
|
||||
import me.neznamy.tab.shared.permission.PermissionPlugin;
|
||||
@@ -45,9 +42,6 @@ import net.milkbowl.vault.permission.Permission;
|
||||
* Bukkit implementation of Platform
|
||||
*/
|
||||
public class BukkitPlatform implements Platform {
|
||||
|
||||
//list of used expansions
|
||||
private Set<String> usedExpansions;
|
||||
|
||||
//plugin instance
|
||||
private JavaPlugin plugin;
|
||||
@@ -56,10 +50,11 @@ public class BukkitPlatform implements Platform {
|
||||
private NMSStorage nms;
|
||||
|
||||
//booleans to check plugin presence
|
||||
public boolean placeholderAPI;
|
||||
public boolean viaversion;
|
||||
public boolean idisguise;
|
||||
public boolean libsdisguises;
|
||||
private Plugin placeholderAPI;
|
||||
private boolean viaversion;
|
||||
private boolean idisguise;
|
||||
private boolean libsdisguises;
|
||||
private boolean essentials;
|
||||
|
||||
/**
|
||||
* Constructs new instance with given parameters
|
||||
@@ -85,32 +80,34 @@ public class BukkitPlatform implements Platform {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadFeatures() throws Exception {
|
||||
placeholderAPI = Bukkit.getPluginManager().isPluginEnabled("PlaceholderAPI");
|
||||
public void loadFeatures() {
|
||||
placeholderAPI = Bukkit.getPluginManager().getPlugin("PlaceholderAPI");
|
||||
viaversion = Bukkit.getPluginManager().isPluginEnabled("ViaVersion");
|
||||
idisguise = Bukkit.getPluginManager().isPluginEnabled("iDisguise");
|
||||
libsdisguises = Bukkit.getPluginManager().isPluginEnabled("LibsDisguises");
|
||||
int version = ProtocolVersion.SERVER_VERSION.getMinorVersion();
|
||||
essentials = Bukkit.getPluginManager().isPluginEnabled("Essentials");
|
||||
TAB tab = TAB.getInstance();
|
||||
usedExpansions = new HashSet<String>();
|
||||
tab.getPlaceholderManager().addRegistry(new BukkitPlaceholderRegistry(plugin));
|
||||
tab.getPlaceholderManager().addRegistry(new UniversalPlaceholderRegistry());
|
||||
tab.getPlaceholderManager().registerPlaceholders();
|
||||
if (version >= 8) {
|
||||
if (nms.getMinorVersion() >= 8 && tab.getConfiguration().isPipelineInjection()) {
|
||||
tab.getFeatureManager().registerFeature("injection", new BukkitPipelineInjector(tab, nms));
|
||||
}
|
||||
loadNametagFeature(tab);
|
||||
loadUniversalFeatures();
|
||||
if (tab.getConfiguration().BossBarEnabled && version < 9) tab.getFeatureManager().registerFeature("bossbar1.8", new BossBar_legacy(tab));
|
||||
if (version >= 9 && tab.getConfiguration().config.getBoolean("fix-pet-names", false)) tab.getFeatureManager().registerFeature("petfix", new PetFix(nms));
|
||||
if (tab.getConfiguration().config.getBoolean("per-world-playerlist.enabled", false)) tab.getFeatureManager().registerFeature("pwp", new PerWorldPlayerlist(plugin, tab));
|
||||
if (placeholderAPI) {
|
||||
if (tab.getConfiguration().getConfig().getBoolean("ping-spoof.enabled", false)) tab.getFeatureManager().registerFeature("pingspoof", new PingSpoof());
|
||||
if (tab.getConfiguration().getConfig().getString("yellow-number-in-tablist", "%ping%").length() > 0) tab.getFeatureManager().registerFeature("tabobjective", new TabObjective(tab));
|
||||
if (tab.getConfiguration().getConfig().getBoolean("do-not-move-spectators", false)) tab.getFeatureManager().registerFeature("spectatorfix", new SpectatorFix());
|
||||
if (tab.getConfiguration().getConfig().getBoolean("classic-vanilla-belowname.enabled", true)) tab.getFeatureManager().registerFeature("belowname", new BelowName(tab));
|
||||
if (tab.getConfiguration().getPremiumConfig() != null && tab.getConfiguration().getPremiumConfig().getBoolean("scoreboard.enabled", false)) tab.getFeatureManager().registerFeature("scoreboard", new ScoreboardManager(tab));
|
||||
if (tab.getConfiguration().getBossbarConfig().getBoolean("bossbar-enabled", false) && nms.getMinorVersion() < 9) tab.getFeatureManager().registerFeature("bossbar1.8", new WitherBossBar(tab, plugin));
|
||||
if (nms.getMinorVersion() >= 9 && tab.getConfiguration().getConfig().getBoolean("fix-pet-names", false)) tab.getFeatureManager().registerFeature("petfix", new PetFix(nms));
|
||||
if (tab.getConfiguration().getConfig().getBoolean("per-world-playerlist.enabled", false)) tab.getFeatureManager().registerFeature("pwp", new PerWorldPlayerlist(plugin, tab));
|
||||
if (placeholderAPI != null) {
|
||||
new TabExpansion(plugin);
|
||||
new ExpansionDownloader(plugin).download(usedExpansions);
|
||||
}
|
||||
|
||||
for (Player p : getOnlinePlayers()) {
|
||||
tab.addPlayer(new BukkitTabPlayer(p));
|
||||
tab.addPlayer(new BukkitTabPlayer(p, Main.getProtocolVersion(p)));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -119,8 +116,8 @@ public class BukkitPlatform implements Platform {
|
||||
* @param tab - tab instance
|
||||
*/
|
||||
private void loadNametagFeature(TAB tab) {
|
||||
if (tab.getConfiguration().config.getBoolean("change-nametag-prefix-suffix", true)) {
|
||||
if (tab.getConfiguration().config.getBoolean("unlimited-nametag-prefix-suffix-mode.enabled", false) && ProtocolVersion.SERVER_VERSION.getMinorVersion() >= 8) {
|
||||
if (tab.getConfiguration().getConfig().getBoolean("change-nametag-prefix-suffix", true)) {
|
||||
if (tab.getConfiguration().getConfig().getBoolean("unlimited-nametag-prefix-suffix-mode.enabled", false) && nms.getMinorVersion() >= 8) {
|
||||
tab.getFeatureManager().registerFeature("nametagx", new NameTagX(plugin, nms, tab));
|
||||
} else {
|
||||
tab.getFeatureManager().registerFeature("nametag16", new NameTag(tab));
|
||||
@@ -131,17 +128,21 @@ public class BukkitPlatform implements Platform {
|
||||
/**
|
||||
* Returns list of online players from Bukkit API
|
||||
* @return list of online players from Bukkit API
|
||||
* @throws Exception - if reflection fails
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
private Player[] getOnlinePlayers() throws Exception {
|
||||
Object players = Bukkit.class.getMethod("getOnlinePlayers").invoke(null);
|
||||
if (players instanceof Player[]) {
|
||||
//1.7.x
|
||||
return (Player[]) players;
|
||||
} else {
|
||||
//1.8+
|
||||
return ((Collection<Player>)players).toArray(new Player[0]);
|
||||
private Player[] getOnlinePlayers() {
|
||||
try {
|
||||
Object players = Bukkit.class.getMethod("getOnlinePlayers").invoke(null);
|
||||
if (players instanceof Player[]) {
|
||||
//1.7.x
|
||||
return (Player[]) players;
|
||||
} else {
|
||||
//1.8+
|
||||
return ((Collection<Player>)players).toArray(new Player[0]);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
TAB.getInstance().getErrorManager().printError("Failed to get online players", e);
|
||||
return new Player[0];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -159,18 +160,17 @@ public class BukkitPlatform implements Platform {
|
||||
registerRelationalPlaceholder(identifier, pl.getRelationalRefresh(identifier));
|
||||
} else {
|
||||
//normal placeholder
|
||||
String plugin = identifier.split("_")[0].substring(1).toLowerCase();
|
||||
if (plugin.equals("some")) return;
|
||||
usedExpansions.add(plugin);
|
||||
if (pl.serverPlaceholderRefreshIntervals.containsKey(identifier)) {
|
||||
registerServerPlaceholder(identifier, pl.serverPlaceholderRefreshIntervals.get(identifier));
|
||||
String expansion = identifier.split("_")[0].substring(1).toLowerCase();
|
||||
if (expansion.equals("some")) return;
|
||||
if (pl.getServerPlaceholderRefreshIntervals().containsKey(identifier)) {
|
||||
registerServerPlaceholder(identifier, pl.getServerPlaceholderRefreshIntervals().get(identifier));
|
||||
return;
|
||||
}
|
||||
if (pl.playerPlaceholderRefreshIntervals.containsKey(identifier)) {
|
||||
registerPlayerPlaceholder(identifier, pl.playerPlaceholderRefreshIntervals.get(identifier));
|
||||
if (pl.getPlayerPlaceholderRefreshIntervals().containsKey(identifier)) {
|
||||
registerPlayerPlaceholder(identifier, pl.getPlayerPlaceholderRefreshIntervals().get(identifier));
|
||||
return;
|
||||
}
|
||||
registerPlayerPlaceholder(identifier, pl.defaultRefresh);
|
||||
registerPlayerPlaceholder(identifier, pl.getDefaultRefresh());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -181,11 +181,12 @@ public class BukkitPlatform implements Platform {
|
||||
* @param refresh - refresh interval in milliseconds
|
||||
*/
|
||||
private void registerServerPlaceholder(String identifier, int refresh) {
|
||||
BukkitPlatform pl = this;
|
||||
TAB.getInstance().getPlaceholderManager().registerPlaceholder(new ServerPlaceholder(identifier, TAB.getInstance().getErrorManager().fixPlaceholderInterval(identifier, refresh)){
|
||||
|
||||
@Override
|
||||
public String get() {
|
||||
return setPlaceholders(null, identifier);
|
||||
return pl.setPlaceholders(null, identifier);
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -196,11 +197,12 @@ public class BukkitPlatform implements Platform {
|
||||
* @param refresh - refresh interval in milliseconds
|
||||
*/
|
||||
private void registerPlayerPlaceholder(String identifier, int refresh) {
|
||||
BukkitPlatform pl = this;
|
||||
TAB.getInstance().getPlaceholderManager().registerPlaceholder(new PlayerPlaceholder(identifier, TAB.getInstance().getErrorManager().fixPlaceholderInterval(identifier, refresh)) {
|
||||
|
||||
@Override
|
||||
public String get(TabPlayer p) {
|
||||
return setPlaceholders((Player) p.getPlayer(), identifier);
|
||||
return pl.setPlaceholders((Player) p.getPlayer(), identifier);
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -215,11 +217,11 @@ public class BukkitPlatform implements Platform {
|
||||
|
||||
@Override
|
||||
public String get(TabPlayer viewer, TabPlayer target) {
|
||||
if (!placeholderAPI) return identifier;
|
||||
if (placeholderAPI == null) return identifier;
|
||||
try {
|
||||
return PlaceholderAPI.setRelationalPlaceholders((Player) viewer.getPlayer(), (Player) target.getPlayer(), identifier);
|
||||
} catch (Throwable t) {
|
||||
TAB.getInstance().getErrorManager().printError("PlaceholderAPI v" + Bukkit.getPluginManager().getPlugin("PlaceholderAPI").getDescription().getVersion() + " generated an error when setting relational placeholder " + identifier + " for viewer " + viewer.getName() + " and target " + target.getName(), t, false, TAB.getInstance().getErrorManager().papiErrorLog);
|
||||
} catch (Exception t) {
|
||||
TAB.getInstance().getErrorManager().printError("PlaceholderAPI v" + placeholderAPI.getDescription().getVersion() + " generated an error when setting relational placeholder " + identifier + " for viewer " + viewer.getName() + " and target " + target.getName(), t, false, TAB.getInstance().getErrorManager().getPapiErrorLog());
|
||||
}
|
||||
return identifier;
|
||||
}
|
||||
@@ -233,67 +235,16 @@ public class BukkitPlatform implements Platform {
|
||||
* @return result from PlaceholderAPI
|
||||
*/
|
||||
public String setPlaceholders(Player player, String placeholder) {
|
||||
if (!placeholderAPI) return placeholder;
|
||||
if (placeholderAPI == null) return placeholder;
|
||||
try {
|
||||
return PlaceholderAPI.setPlaceholders(player, placeholder);
|
||||
} catch (Throwable t) {
|
||||
} catch (Exception t) {
|
||||
String playername = (player == null ? "<null>" : player.getName());
|
||||
TAB.getInstance().getErrorManager().printError("PlaceholderAPI v" + Bukkit.getPluginManager().getPlugin("PlaceholderAPI").getDescription().getVersion() + " generated an error when setting placeholder " + placeholder + " for player " + playername, t, false, TAB.getInstance().getErrorManager().papiErrorLog);
|
||||
TAB.getInstance().getErrorManager().printError("PlaceholderAPI v" + placeholderAPI.getDescription().getVersion() + " generated an error when setting placeholder " + placeholder + " for player " + playername, t, false, TAB.getInstance().getErrorManager().getPapiErrorLog());
|
||||
return "ERROR";
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void convertConfig(ConfigurationFile config) {
|
||||
convertUniversalOptions(config);
|
||||
if (config.getName().equals("config.yml")) {
|
||||
removeOld(config, "nametag-refresh-interval-ticks");
|
||||
removeOld(config, "tablist-refresh-interval-ticks");
|
||||
removeOld(config, "header-footer-refresh-interval-ticks");
|
||||
removeOld(config, "belowname.refresh-interval-ticks");
|
||||
removeOld(config, "placeholders.deluxetag-yes");
|
||||
removeOld(config, "placeholders.deluxetag-no");
|
||||
removeOld(config, "placeholders.faction-yes");
|
||||
removeOld(config, "placeholders.faction-no");
|
||||
removeOld(config, "staff-groups");
|
||||
removeOld(config, "use-essentials-nickname");
|
||||
removeOld(config, "deluxetag-empty-value");
|
||||
removeOld(config, "factions-faction");
|
||||
removeOld(config, "factions-nofaction");
|
||||
removeOld(config, "date-format");
|
||||
removeOld(config, "time-format");
|
||||
removeOld(config, "relational-placeholders-refresh");
|
||||
removeOld(config, "bukkit-bridge-mode");
|
||||
if (config.hasConfigOption("tablist-objective")) {
|
||||
String type = config.getString("tablist-objective");
|
||||
String value;
|
||||
if (type.equals("NONE")) {
|
||||
value = "";
|
||||
} else if (type.equals("PING")){
|
||||
value = "%ping%";
|
||||
} else if (type.equals("HEARTS")) {
|
||||
value = "%health%";
|
||||
} else {
|
||||
value = config.getString("tablist-objective-custom-value");
|
||||
}
|
||||
config.set("tablist-objective", null);
|
||||
config.set("tablist-objective-custom-value", null);
|
||||
config.set("yellow-number-in-tablist", value);
|
||||
TAB.getInstance().print('2', "Converted old tablist-objective config option to new yellow-number-in-tablist");
|
||||
}
|
||||
if (config.getObject("per-world-playerlist") instanceof Boolean) {
|
||||
rename(config, "per-world-playerlist", "per-world-playerlist.enabled");
|
||||
rename(config, "allow-pwp-bypass-permission", "per-world-playerlist.allow-bypass-permission");
|
||||
rename(config, "ignore-pwp-in-worlds", "per-world-playerlist.ignore-effect-in-worlds");
|
||||
Map<String, List<String>> sharedWorlds = new HashMap<String, List<String>>();
|
||||
sharedWorlds.put("lobby", Arrays.asList("lobby1", "lobby2"));
|
||||
sharedWorlds.put("minigames", Arrays.asList("paintball", "bedwars"));
|
||||
config.set("per-world-playerlist.shared-playerlist-world-groups", sharedWorlds);
|
||||
TAB.getInstance().print('2', "Converted old per-world-playerlist section to new one in advancedconfig.yml.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getServerVersion() {
|
||||
return Bukkit.getBukkitVersion().split("-")[0] + " (" + Bukkit.getServer().getClass().getPackage().getName().split("\\.")[3] + ")";
|
||||
@@ -337,4 +288,25 @@ public class BukkitPlatform implements Platform {
|
||||
public int getMaxPlayers() {
|
||||
return Bukkit.getMaxPlayers();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getConfigName() {
|
||||
return "bukkitconfig.yml";
|
||||
}
|
||||
|
||||
public boolean isViaversionEnabled() {
|
||||
return viaversion;
|
||||
}
|
||||
|
||||
public boolean isLibsdisguisesEnabled() {
|
||||
return libsdisguises;
|
||||
}
|
||||
|
||||
public boolean isIdisguiseEnabled() {
|
||||
return idisguise;
|
||||
}
|
||||
|
||||
public boolean isEssentialsEnabled() {
|
||||
return essentials;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,219 @@
|
||||
package me.neznamy.tab.platforms.bukkit;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.boss.BarColor;
|
||||
import org.bukkit.boss.BarFlag;
|
||||
import org.bukkit.boss.BarStyle;
|
||||
import org.bukkit.boss.BossBar;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.metadata.MetadataValue;
|
||||
import org.bukkit.potion.PotionEffectType;
|
||||
|
||||
import com.viaversion.viaversion.api.Via;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.channel.Channel;
|
||||
import me.neznamy.tab.platforms.bukkit.nms.NMSStorage;
|
||||
import me.neznamy.tab.shared.ITabPlayer;
|
||||
import me.neznamy.tab.shared.ProtocolVersion;
|
||||
import me.neznamy.tab.shared.TAB;
|
||||
import me.neznamy.tab.shared.packets.PacketPlayOutBoss;
|
||||
import me.neznamy.tab.shared.rgb.RGBUtils;
|
||||
|
||||
/**
|
||||
* TabPlayer for Bukkit
|
||||
*/
|
||||
public class BukkitTabPlayer extends ITabPlayer {
|
||||
|
||||
//bukkit player
|
||||
private Player player;
|
||||
|
||||
//nms handle
|
||||
private Object handle;
|
||||
|
||||
//nms player connection
|
||||
private Object playerConnection;
|
||||
|
||||
//player's visible boss bars
|
||||
private Map<UUID, BossBar> bossbars = new HashMap<>();
|
||||
|
||||
/**
|
||||
* Constructs new instance with given parameter
|
||||
* @param p - bukkit player
|
||||
*/
|
||||
public BukkitTabPlayer(Player p, int protocolVersion){
|
||||
player = p;
|
||||
world = p.getWorld().getName();
|
||||
try {
|
||||
handle = NMSStorage.getInstance().getMethod("getHandle").invoke(player);
|
||||
playerConnection = NMSStorage.getInstance().getField("PLAYER_CONNECTION").get(handle);
|
||||
} catch (Exception e) {
|
||||
TAB.getInstance().getErrorManager().printError("Failed to get playerConnection of " + p.getName(), e);
|
||||
}
|
||||
try {
|
||||
if (NMSStorage.getInstance().getField("CHANNEL") != null)
|
||||
channel = (Channel) NMSStorage.getInstance().getField("CHANNEL").get(NMSStorage.getInstance().getField("NETWORK_MANAGER").get(playerConnection));
|
||||
} catch (Exception e) {
|
||||
TAB.getInstance().getErrorManager().printError("Failed to get channel of " + p.getName(), e);
|
||||
}
|
||||
uniqueId = p.getUniqueId();
|
||||
name = p.getName();
|
||||
version = ProtocolVersion.fromNetworkId(protocolVersion);
|
||||
init();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasPermission(String permission) {
|
||||
return player.hasPermission(permission);
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getPing() {
|
||||
try {
|
||||
int ping = NMSStorage.getInstance().getField("PING").getInt(handle);
|
||||
if (ping > 10000 || ping < 0) ping = -1;
|
||||
return ping;
|
||||
} catch (Exception e) {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendPacket(Object nmsPacket) {
|
||||
if (nmsPacket == null || !player.isOnline()) return;
|
||||
try {
|
||||
if (((BukkitPlatform)TAB.getInstance().getPlatform()).isViaversionEnabled() && nmsPacket instanceof ByteBuf) {
|
||||
Via.getAPI().sendRawPacket(uniqueId, (ByteBuf) nmsPacket);
|
||||
return;
|
||||
}
|
||||
if (nmsPacket instanceof PacketPlayOutBoss) {
|
||||
handle((PacketPlayOutBoss) nmsPacket);
|
||||
return;
|
||||
}
|
||||
NMSStorage.getInstance().getMethod("sendPacket").invoke(playerConnection, nmsPacket);
|
||||
} catch (IllegalArgumentException e) {
|
||||
//java.lang.IllegalArgumentException: This player is not controlled by ViaVersion!
|
||||
//this is only used to send 1.9 bossbar packets on 1.8 servers, no idea why it does this sometimes
|
||||
} catch (Exception e) {
|
||||
TAB.getInstance().getErrorManager().printError("An error occurred when sending " + nmsPacket.getClass().getSimpleName(), e);
|
||||
}
|
||||
}
|
||||
|
||||
private void handle(PacketPlayOutBoss packet) {
|
||||
Set<BarFlag> flags = new HashSet<>();
|
||||
BossBar bar;
|
||||
switch (packet.getOperation()) {
|
||||
case ADD:
|
||||
if (packet.isCreateWorldFog()) flags.add(BarFlag.CREATE_FOG);
|
||||
if (packet.isDarkenScreen()) flags.add(BarFlag.DARKEN_SKY);
|
||||
if (packet.isPlayMusic()) flags.add(BarFlag.PLAY_BOSS_MUSIC);
|
||||
bar = Bukkit.createBossBar(RGBUtils.getInstance().convertToBukkitFormat(packet.getName(), getVersion().getMinorVersion() >= 16 && NMSStorage.getInstance().getMinorVersion() >= 16),
|
||||
BarColor.valueOf(packet.getColor().name()),
|
||||
BarStyle.valueOf(packet.getOverlay().name().replace("PROGRESS", "SOLID").replace("NOTCHED", "SEGMENTED")),
|
||||
flags.toArray(new BarFlag[0]));
|
||||
bar.setProgress(packet.getPct());
|
||||
bossbars.put(packet.getId(), bar);
|
||||
bar.addPlayer(player);
|
||||
break;
|
||||
case REMOVE:
|
||||
bossbars.get(packet.getId()).removePlayer(player);
|
||||
bossbars.remove(packet.getId());
|
||||
break;
|
||||
case UPDATE_PCT:
|
||||
bossbars.get(packet.getId()).setProgress(packet.getPct());
|
||||
break;
|
||||
case UPDATE_NAME:
|
||||
bossbars.get(packet.getId()).setTitle(RGBUtils.getInstance().convertToBukkitFormat(packet.getName(), getVersion().getMinorVersion() >= 16 && NMSStorage.getInstance().getMinorVersion() >= 16));
|
||||
break;
|
||||
case UPDATE_STYLE:
|
||||
bossbars.get(packet.getId()).setColor(BarColor.valueOf(packet.getColor().name()));
|
||||
bossbars.get(packet.getId()).setStyle(BarStyle.valueOf(packet.getOverlay().name().replace("PROGRESS", "SOLID").replace("NOTCHED", "SEGMENTED")));
|
||||
break;
|
||||
case UPDATE_PROPERTIES:
|
||||
bar = bossbars.get(packet.getId());
|
||||
processFlag(bar, packet.isCreateWorldFog(), BarFlag.CREATE_FOG);
|
||||
processFlag(bar, packet.isDarkenScreen(), BarFlag.DARKEN_SKY);
|
||||
processFlag(bar, packet.isPlayMusic(), BarFlag.PLAY_BOSS_MUSIC);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private void processFlag(BossBar bar, boolean targetValue, BarFlag flag) {
|
||||
if (targetValue) {
|
||||
if (!bar.hasFlag(flag)) {
|
||||
bar.addFlag(flag);
|
||||
}
|
||||
} else {
|
||||
if (bar.hasFlag(flag)) {
|
||||
bar.removeFlag(flag);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasInvisibilityPotion() {
|
||||
return player.hasPotionEffect(PotionEffectType.INVISIBILITY);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDisguised() {
|
||||
try {
|
||||
if (!((BukkitPlatform)TAB.getInstance().getPlatform()).isLibsdisguisesEnabled()) return false;
|
||||
return (boolean) Class.forName("me.libraryaddict.disguise.DisguiseAPI").getMethod("isDisguised", Entity.class).invoke(null, player);
|
||||
} catch (Exception e) {
|
||||
return TAB.getInstance().getErrorManager().printError(false, "Failed to check disguise status using LibsDisguises", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getSkin() {
|
||||
try {
|
||||
return Class.forName("com.mojang.authlib.GameProfile").getMethod("getProperties").invoke(NMSStorage.getInstance().getMethod("getProfile").invoke(handle));
|
||||
} catch (Exception e) {
|
||||
return TAB.getInstance().getErrorManager().printError(null, "Failed to get skin of " + getName(), e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Player getPlayer() {
|
||||
return player;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isOnline() {
|
||||
return player.isOnline();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isVanished() {
|
||||
try {
|
||||
if (((BukkitPlatform)TAB.getInstance().getPlatform()).isEssentialsEnabled()) {
|
||||
Object essentials = Bukkit.getPluginManager().getPlugin("Essentials");
|
||||
Object user = essentials.getClass().getMethod("getUser", Player.class).invoke(essentials, player);
|
||||
boolean vanished = (boolean) user.getClass().getMethod("isVanished").invoke(user);
|
||||
if (vanished) return true;
|
||||
}
|
||||
List<MetadataValue> metadata = player.getMetadata("vanished");
|
||||
return !metadata.isEmpty() && metadata.get(0).asBoolean();
|
||||
} catch (Exception e) {
|
||||
TAB.getInstance().getErrorManager().printError("Failed to check vanish status of " + player.getName(), e);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@Override
|
||||
public int getGamemode() {
|
||||
return player.getGameMode().getValue();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,167 @@
|
||||
package me.neznamy.tab.platforms.bukkit;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import org.bstats.bukkit.Metrics;
|
||||
import org.bstats.charts.SimplePie;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.command.TabCompleter;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import com.viaversion.viaversion.api.Via;
|
||||
|
||||
import me.neznamy.tab.api.TabPlayer;
|
||||
import me.neznamy.tab.platforms.bukkit.nms.NMSStorage;
|
||||
import me.neznamy.tab.shared.ProtocolVersion;
|
||||
import me.neznamy.tab.shared.TAB;
|
||||
|
||||
/**
|
||||
* Main class for Bukkit platform
|
||||
*/
|
||||
public class Main extends JavaPlugin {
|
||||
|
||||
@Override
|
||||
public void onEnable(){
|
||||
Bukkit.getConsoleSender().sendMessage("\u00a77[TAB] Server version: " + Bukkit.getBukkitVersion().split("-")[0] + " (" + Bukkit.getServer().getClass().getPackage().getName().split("\\.")[3] + ")");
|
||||
if (!isVersionSupported()){
|
||||
Bukkit.getPluginManager().disablePlugin(this);
|
||||
return;
|
||||
}
|
||||
TAB.setInstance(new TAB(new BukkitPlatform(this, NMSStorage.getInstance()), new BukkitPacketBuilder(NMSStorage.getInstance()), ProtocolVersion.fromFriendlyName(Bukkit.getBukkitVersion().split("-")[0])));
|
||||
if (TAB.getInstance().getServerVersion() == ProtocolVersion.UNKNOWN) {
|
||||
Bukkit.getConsoleSender().sendMessage("\u00a7c[TAB] Unknown server version: " + Bukkit.getBukkitVersion() + "! Plugin may not work correctly.");
|
||||
}
|
||||
Bukkit.getPluginManager().registerEvents(new BukkitEventListener(), this);
|
||||
TABCommand command = new TABCommand();
|
||||
Bukkit.getPluginCommand("tab").setExecutor(command);
|
||||
Bukkit.getPluginCommand("tab").setTabCompleter(command);
|
||||
TAB.getInstance().load();
|
||||
Metrics metrics = new Metrics(this, 5304);
|
||||
metrics.addCustomChart(new SimplePie("unlimited_nametag_mode_enabled", () -> TAB.getInstance().getFeatureManager().isFeatureEnabled("nametagx") ? "Yes" : "No"));
|
||||
metrics.addCustomChart(new SimplePie("placeholderapi", () -> Bukkit.getPluginManager().isPluginEnabled("PlaceholderAPI") ? "Yes" : "No"));
|
||||
metrics.addCustomChart(new SimplePie("permission_system", () -> TAB.getInstance().getPermissionPlugin().getName()));
|
||||
metrics.addCustomChart(new SimplePie("server_version", () -> "1." + NMSStorage.getInstance().getMinorVersion() + ".x"));
|
||||
metrics.addCustomChart(new SimplePie("using_premium_version", () -> TAB.getInstance().isPremium() ? "Yes" : "No"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDisable() {
|
||||
//null check due to L23 return making L30 not run
|
||||
if (TAB.getInstance() != null) TAB.getInstance().unload();
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes all used NMS classes, constructors, fields and methods and returns true if everything went successfully and version is marked as compatible
|
||||
* @return true if compatible, false if not
|
||||
*/
|
||||
private boolean isVersionSupported(){
|
||||
List<String> supportedVersions = Arrays.asList(
|
||||
"v1_5_R1", "v1_5_R2", "v1_5_R3", "v1_6_R1", "v1_6_R2", "v1_6_R3",
|
||||
"v1_7_R1", "v1_7_R2", "v1_7_R3", "v1_7_R4", "v1_8_R1", "v1_8_R2", "v1_8_R3",
|
||||
"v1_9_R1", "v1_9_R2", "v1_10_R1", "v1_11_R1", "v1_12_R1", "v1_13_R1", "v1_13_R2",
|
||||
"v1_14_R1", "v1_15_R1", "v1_16_R1", "v1_16_R2", "v1_16_R3", "v1_17_R1");
|
||||
String serverPackage = Bukkit.getServer().getClass().getPackage().getName().split("\\.")[3];
|
||||
try {
|
||||
NMSStorage.setInstance(new NMSStorage());
|
||||
if (supportedVersions.contains(serverPackage)) {
|
||||
return true;
|
||||
} else {
|
||||
Bukkit.getConsoleSender().sendMessage("\u00a7c[TAB] No compatibility issue was found, but this plugin version does not claim to support your server version. This jar has only been tested on 1.5.x - 1.17. Disabling just to stay safe.");
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
if (supportedVersions.contains(serverPackage)) {
|
||||
Bukkit.getConsoleSender().sendMessage("\u00a7c[TAB] Your server version is marked as compatible, but a compatibility issue was found. Please report the error below (include your server version & fork too)");
|
||||
Bukkit.getConsoleSender().sendMessage(ex.getClass().getName() + ": " + ex.getMessage());
|
||||
for (StackTraceElement e : ex.getStackTrace()) {
|
||||
Bukkit.getConsoleSender().sendMessage("\t" + e.toString());
|
||||
}
|
||||
} else {
|
||||
Bukkit.getConsoleSender().sendMessage("\u00a7c[TAB] Your server version is completely unsupported. This plugin version only supports 1.5.x - 1.17. Disabling.");
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets protocol version and returns it
|
||||
* @return protocol version of this player
|
||||
*/
|
||||
public static int getProtocolVersion(Player player) {
|
||||
if (Bukkit.getPluginManager().isPluginEnabled("ProtocolSupport")){
|
||||
int version = getProtocolVersionPS(player);
|
||||
//some PS versions return -1 on unsupported server versions instead of throwing exception
|
||||
if (version != -1 && version < TAB.getInstance().getServerVersion().getNetworkId()) return version;
|
||||
}
|
||||
if (Bukkit.getPluginManager().isPluginEnabled("ViaVersion")) {
|
||||
return getProtocolVersionVia(player);
|
||||
}
|
||||
return TAB.getInstance().getServerVersion().getNetworkId();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns protocol version of this player using ProtocolSupport
|
||||
* @return protocol version of this player using ProtocolSupport
|
||||
*/
|
||||
private static int getProtocolVersionPS(Player player){
|
||||
try {
|
||||
Object protocolVersion = Class.forName("protocolsupport.api.ProtocolSupportAPI").getMethod("getProtocolVersion", Player.class).invoke(null, player);
|
||||
int version = (int) protocolVersion.getClass().getMethod("getId").invoke(protocolVersion);
|
||||
TAB.getInstance().debug("ProtocolSupport returned protocol version " + version + " for " + player.getName() + "(online=" + player.isOnline() + ")");
|
||||
return version;
|
||||
} catch (Exception e) {
|
||||
TAB.getInstance().getErrorManager().printError("Failed to get protocol version of " + player.getName() + " using ProtocolSupport", e);
|
||||
return TAB.getInstance().getServerVersion().getNetworkId();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns protocol version of this player using ViaVersion
|
||||
* @return protocol version of this player using ViaVersion
|
||||
*/
|
||||
private static int getProtocolVersionVia(Player player){
|
||||
try {
|
||||
int version = Via.getAPI().getPlayerVersion(player.getUniqueId());
|
||||
TAB.getInstance().debug("ViaVersion returned protocol version " + version + " for " + player.getName() + "(online=" + player.isOnline() + ")");
|
||||
return version;
|
||||
} catch (Exception e) {
|
||||
TAB.getInstance().getErrorManager().printError("Failed to get protocol version of " + player.getName() + " using ViaVersion v" + Bukkit.getPluginManager().getPlugin("ViaVersion").getDescription().getVersion(), e);
|
||||
return TAB.getInstance().getServerVersion().getNetworkId();
|
||||
}
|
||||
}
|
||||
|
||||
public class TABCommand implements CommandExecutor, TabCompleter {
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||
if (TAB.getInstance().isDisabled()) {
|
||||
for (String message : TAB.getInstance().getDisabledCommand().execute(args, sender.hasPermission("tab.reload"), sender.hasPermission("tab.admin"))) {
|
||||
sender.sendMessage(message.replace('&', '\u00a7'));
|
||||
}
|
||||
} else {
|
||||
TabPlayer p = null;
|
||||
if (sender instanceof Player) {
|
||||
p = TAB.getInstance().getPlayer(((Player)sender).getUniqueId());
|
||||
if (p == null) return true; //player not loaded correctly
|
||||
}
|
||||
TAB.getInstance().getCommand().execute(p, args);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> onTabComplete(CommandSender sender, Command command, String alias, String[] args) {
|
||||
TabPlayer p = null;
|
||||
if (sender instanceof Player) {
|
||||
p = TAB.getInstance().getPlayer(((Player)sender).getUniqueId());
|
||||
if (p == null) return new ArrayList<>(); //player not loaded correctly
|
||||
}
|
||||
return TAB.getInstance().getCommand().complete(p, args);
|
||||
}
|
||||
}
|
||||
}
|
||||
+110
@@ -0,0 +1,110 @@
|
||||
package me.neznamy.tab.platforms.bukkit.features;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.HandlerList;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerChangedWorldEvent;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import me.neznamy.tab.shared.TAB;
|
||||
import me.neznamy.tab.shared.cpu.TabFeature;
|
||||
import me.neznamy.tab.shared.cpu.UsageType;
|
||||
import me.neznamy.tab.shared.features.types.Loadable;
|
||||
|
||||
/**
|
||||
* Per-world-playerlist feature handler
|
||||
*/
|
||||
@SuppressWarnings("deprecation")
|
||||
public class PerWorldPlayerlist implements Loadable, Listener {
|
||||
|
||||
//plugin instance
|
||||
private JavaPlugin plugin;
|
||||
|
||||
//config options
|
||||
private boolean allowBypass;
|
||||
private List<String> ignoredWorlds;
|
||||
private Map<String, List<String>> sharedWorlds;
|
||||
|
||||
/**
|
||||
* Constructs new instance with given parameters and loads config options
|
||||
* @param plugin - plugin instance
|
||||
* @param tab - tab instance
|
||||
*/
|
||||
public PerWorldPlayerlist(JavaPlugin plugin, TAB tab) {
|
||||
this.plugin = plugin;
|
||||
allowBypass = tab.getConfiguration().getConfig().getBoolean("per-world-playerlist.allow-bypass-permission", false);
|
||||
ignoredWorlds = tab.getConfiguration().getConfig().getStringList("per-world-playerlist.ignore-effect-in-worlds", Arrays.asList("ignoredworld", "build"));
|
||||
sharedWorlds = tab.getConfiguration().getConfig().getConfigurationSection("per-world-playerlist.shared-playerlist-world-groups");
|
||||
for (Entry<String, List<String>> group : sharedWorlds.entrySet()) {
|
||||
if (group.getValue() == null) {
|
||||
tab.getErrorManager().startupWarn("World group \"" + group + "\" in per-world-playerlist does not contain any worlds. You can just remove the group.");
|
||||
} else if (group.getValue().size() == 1) {
|
||||
tab.getErrorManager().startupWarn("World group \"" + group + "\" in per-world-playerlist only contain a single world (\"" + group.getValue().get(0) +
|
||||
"\"), which has no effect and only makes config less readable. Delete the group entirely for a cleaner config.");
|
||||
}
|
||||
}
|
||||
tab.debug(String.format("Loaded PerWorldPlayerlist feature with parameters allowBypass=%s, ignoredWorlds=%s, sharedWorlds=%s", allowBypass, ignoredWorlds, sharedWorlds));
|
||||
Bukkit.getPluginManager().registerEvents(this, plugin);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void load(){
|
||||
Bukkit.getScheduler().runTask(plugin, () -> Bukkit.getOnlinePlayers().forEach(this::checkPlayer));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unload(){
|
||||
for (Player p : Bukkit.getOnlinePlayers()) {
|
||||
for (Player pl : Bukkit.getOnlinePlayers()) {
|
||||
p.showPlayer(pl);
|
||||
}
|
||||
}
|
||||
HandlerList.unregisterAll(this);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onJoin(PlayerJoinEvent e) {
|
||||
long time = System.nanoTime();
|
||||
checkPlayer(e.getPlayer());
|
||||
TAB.getInstance().getCPUManager().addTime(TabFeature.PER_WORLD_PLAYERLIST, UsageType.PLAYER_JOIN_EVENT, System.nanoTime()-time);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onWorldChange(PlayerChangedWorldEvent e) {
|
||||
long time = System.nanoTime();
|
||||
checkPlayer(e.getPlayer());
|
||||
TAB.getInstance().getCPUManager().addTime(TabFeature.PER_WORLD_PLAYERLIST, UsageType.WORLD_SWITCH_EVENT, System.nanoTime()-time);
|
||||
}
|
||||
|
||||
private void checkPlayer(Player p) {
|
||||
for (Player all : Bukkit.getOnlinePlayers()){
|
||||
if (all == p) continue;
|
||||
if (!shouldSee(p, all) && p.canSee(all)) p.hidePlayer(all);
|
||||
if (shouldSee(p, all) && !p.canSee(all)) p.showPlayer(all);
|
||||
if (!shouldSee(all, p) && all.canSee(p)) all.hidePlayer(p);
|
||||
if (shouldSee(all, p) && !all.canSee(p)) all.showPlayer(p);
|
||||
}
|
||||
}
|
||||
|
||||
private boolean shouldSee(Player viewer, Player target) {
|
||||
if (target == viewer) return true;
|
||||
if ((allowBypass && viewer.hasPermission("tab.bypass")) || ignoredWorlds.contains(viewer.getWorld().getName())) return true;
|
||||
String viewerWorldGroup = viewer.getWorld().getName() + "-default"; //preventing unwanted behavior when some group is called exactly like a world
|
||||
String targetWorldGroup = target.getWorld().getName() + "-default";
|
||||
for (Entry<String, List<String>> group : sharedWorlds.entrySet()) {
|
||||
if (group.getValue() != null) {
|
||||
if (group.getValue().contains(viewer.getWorld().getName())) viewerWorldGroup = group.getKey();
|
||||
if (group.getValue().contains(target.getWorld().getName())) targetWorldGroup = group.getKey();
|
||||
}
|
||||
}
|
||||
return viewerWorldGroup.equals(targetWorldGroup);
|
||||
}
|
||||
}
|
||||
+50
-24
@@ -1,6 +1,7 @@
|
||||
package me.neznamy.tab.platforms.bukkit.features;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@@ -9,7 +10,7 @@ import me.neznamy.tab.api.TabPlayer;
|
||||
import me.neznamy.tab.platforms.bukkit.nms.NMSStorage;
|
||||
import me.neznamy.tab.platforms.bukkit.nms.datawatcher.DataWatcher;
|
||||
import me.neznamy.tab.platforms.bukkit.nms.datawatcher.DataWatcherItem;
|
||||
import me.neznamy.tab.shared.ProtocolVersion;
|
||||
import me.neznamy.tab.shared.TAB;
|
||||
import me.neznamy.tab.shared.cpu.TabFeature;
|
||||
import me.neznamy.tab.shared.features.types.event.QuitEventListener;
|
||||
import me.neznamy.tab.shared.features.types.packet.RawPacketListener;
|
||||
@@ -22,10 +23,10 @@ import me.neznamy.tab.shared.features.types.packet.RawPacketListener;
|
||||
public class PetFix implements RawPacketListener, QuitEventListener {
|
||||
|
||||
//datawatcher position of pet owner field
|
||||
private int PET_OWNER_POSITION = getPetOwnerPosition();
|
||||
private int petOwnerPosition;
|
||||
|
||||
//logger of last interacts to prevent feature not working on 1.16
|
||||
private Map<String, Long> lastInteractFix = new HashMap<String, Long>();
|
||||
private Map<String, Long> lastInteractFix = new HashMap<>();
|
||||
|
||||
//nms storage
|
||||
private NMSStorage nms;
|
||||
@@ -36,6 +37,8 @@ public class PetFix implements RawPacketListener, QuitEventListener {
|
||||
*/
|
||||
public PetFix(NMSStorage nms) {
|
||||
this.nms = nms;
|
||||
petOwnerPosition = getPetOwnerPosition();
|
||||
TAB.getInstance().debug("Loaded PetFix feature");
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -43,13 +46,16 @@ public class PetFix implements RawPacketListener, QuitEventListener {
|
||||
* @return position of pet owner field based on server version
|
||||
*/
|
||||
private int getPetOwnerPosition() {
|
||||
if (ProtocolVersion.SERVER_VERSION.getMinorVersion() >= 15) {
|
||||
if (nms.getMinorVersion() >= 17) {
|
||||
//1.17.x
|
||||
return 18;
|
||||
} else if (nms.getMinorVersion() >= 15) {
|
||||
//1.15.x, 1.16.x
|
||||
return 17;
|
||||
} else if (ProtocolVersion.SERVER_VERSION.getMinorVersion() >= 14) {
|
||||
} else if (nms.getMinorVersion() >= 14) {
|
||||
//1.14.x
|
||||
return 16;
|
||||
} else if (ProtocolVersion.SERVER_VERSION.getMinorVersion() >= 10) {
|
||||
} else if (nms.getMinorVersion() >= 10) {
|
||||
//1.10.x - 1.13.x
|
||||
return 14;
|
||||
} else {
|
||||
@@ -60,15 +66,16 @@ public class PetFix implements RawPacketListener, QuitEventListener {
|
||||
|
||||
/**
|
||||
* Cancels a packet if previous one arrived with no delay to prevent double toggle on 1.16
|
||||
* @throws IllegalAccessException
|
||||
*/
|
||||
@Override
|
||||
public Object onPacketReceive(TabPlayer sender, Object packet) throws Throwable {
|
||||
if (nms.PacketPlayInUseEntity.isInstance(packet)) {
|
||||
public Object onPacketReceive(TabPlayer sender, Object packet) throws IllegalAccessException {
|
||||
if (nms.getClass("PacketPlayInUseEntity").isInstance(packet)) {
|
||||
if (lastInteractFix.containsKey(sender.getName()) && (System.currentTimeMillis() - lastInteractFix.get(sender.getName()) < 5)) {
|
||||
//last interact packet was sent right now, cancelling to prevent double-toggle due to this feature enabled
|
||||
return null;
|
||||
}
|
||||
if (nms.PacketPlayInUseEntity_ACTION.get(packet).toString().equals("INTERACT")) {
|
||||
if (isInteract(nms.getField("PacketPlayInUseEntity_ACTION").get(packet))) {
|
||||
//this is the first packet, saving player so the next packet can be cancelled
|
||||
lastInteractFix.put(sender.getName(), System.currentTimeMillis());
|
||||
}
|
||||
@@ -76,29 +83,48 @@ public class PetFix implements RawPacketListener, QuitEventListener {
|
||||
return packet;
|
||||
}
|
||||
|
||||
private boolean isInteract(Object action) {
|
||||
if (nms.getMinorVersion() >= 17) {
|
||||
return nms.getClass("PacketPlayInUseEntity$d").isInstance(action);
|
||||
} else {
|
||||
return action.toString().equals("INTERACT");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes pet owner field from datawatcher
|
||||
* @throws IllegalAccessException
|
||||
* @throws SecurityException
|
||||
* @throws NoSuchMethodException
|
||||
* @throws InvocationTargetException
|
||||
* @throws InstantiationException
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public void onPacketSend(TabPlayer receiver, Object packet) throws Throwable {
|
||||
if (nms.PacketPlayOutEntityMetadata.isInstance(packet)) {
|
||||
List<Object> items = (List<Object>) nms.PacketPlayOutEntityMetadata_LIST.get(packet);
|
||||
public void onPacketSend(TabPlayer receiver, Object packet) throws IllegalAccessException, InvocationTargetException, NoSuchMethodException, SecurityException, InstantiationException {
|
||||
if (nms.getClass("PacketPlayOutEntityMetadata").isInstance(packet)) {
|
||||
Object removedEntry = null;
|
||||
List<Object> items = (List<Object>) nms.getField("PacketPlayOutEntityMetadata_LIST").get(packet);
|
||||
if (items == null) return;
|
||||
List<Object> newList = new ArrayList<Object>();
|
||||
for (Object item : items) {
|
||||
DataWatcherItem i = DataWatcherItem.fromNMS(item);
|
||||
if (i.type.position == PET_OWNER_POSITION && i.value.toString().startsWith("Optional")) continue;
|
||||
newList.add(item);
|
||||
if (nms.getField("DataWatcherObject_SLOT").getInt(nms.getField("DataWatcherItem_TYPE").get(item)) == petOwnerPosition) {
|
||||
Object value = nms.getField("DataWatcherItem_VALUE").get(item);
|
||||
if (value instanceof java.util.Optional || value instanceof com.google.common.base.Optional) {
|
||||
removedEntry = item;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
nms.PacketPlayOutEntityMetadata_LIST.set(packet, newList);
|
||||
if (removedEntry != null) items.remove(removedEntry);
|
||||
}
|
||||
if (nms.PacketPlayOutSpawnEntityLiving.isInstance(packet) && nms.PacketPlayOutSpawnEntityLiving_DATAWATCHER != null) {
|
||||
DataWatcher watcher = DataWatcher.fromNMS(nms.PacketPlayOutSpawnEntityLiving_DATAWATCHER.get(packet));
|
||||
DataWatcherItem petOwner = watcher.getItem(PET_OWNER_POSITION);
|
||||
if (petOwner != null && petOwner.value.toString().startsWith("Optional")) {
|
||||
watcher.removeValue(PET_OWNER_POSITION);
|
||||
nms.PacketPlayOutSpawnEntityLiving_DATAWATCHER.set(packet, watcher.toNMS());
|
||||
//<1.15
|
||||
Field datawatcher = nms.getField("PacketPlayOutSpawnEntityLiving_DATAWATCHER");
|
||||
if (nms.getClass("PacketPlayOutSpawnEntityLiving").isInstance(packet) && datawatcher != null) {
|
||||
DataWatcher watcher = DataWatcher.fromNMS(datawatcher.get(packet));
|
||||
DataWatcherItem petOwner = watcher.getItem(petOwnerPosition);
|
||||
if (petOwner != null && (petOwner.getValue() instanceof java.util.Optional || petOwner.getValue() instanceof com.google.common.base.Optional)) {
|
||||
watcher.removeValue(petOwnerPosition);
|
||||
nms.setField(packet, "PacketPlayOutSpawnEntityLiving_DATAWATCHER", watcher.toNMS());
|
||||
}
|
||||
}
|
||||
}
|
||||
+8
-4
@@ -60,13 +60,13 @@ public class TabExpansion extends PlaceholderExpansion {
|
||||
if (player == null) return "";
|
||||
TabPlayer p = TAB.getInstance().getPlayer(player.getUniqueId());
|
||||
if (identifier.equals("scoreboard_visible")) {
|
||||
return p.isScoreboardVisible() ? "Enabled" : "Disabled";
|
||||
return translate(p.isScoreboardVisible());
|
||||
}
|
||||
if (identifier.equals("bossbar_visible")) {
|
||||
return p.hasBossbarVisible() ? "Enabled" : "Disabled";
|
||||
return translate(p.hasBossbarVisible());
|
||||
}
|
||||
if (identifier.equals("ntpreview")) {
|
||||
return p.isPreviewingNametag() ? "Enabled" : "Disabled";
|
||||
return translate(p.isPreviewingNametag());
|
||||
}
|
||||
if (identifier.startsWith("replace_")) {
|
||||
return findReplacement("%" + identifier.substring(8) + "%", player);
|
||||
@@ -78,6 +78,10 @@ public class TabExpansion extends PlaceholderExpansion {
|
||||
return getProperty(identifier, p);
|
||||
}
|
||||
|
||||
private String translate(boolean b) {
|
||||
return b ? "Enabled" : "Disabled";
|
||||
}
|
||||
|
||||
/**
|
||||
* Find replacement for specified placeholder
|
||||
* @param placeholder - placeholder to find replacement for
|
||||
@@ -87,7 +91,7 @@ public class TabExpansion extends PlaceholderExpansion {
|
||||
private String findReplacement(String placeholder, Player player) {
|
||||
if (!TAB.getInstance().isPremium()) return "Placeholder output replacements require premium version to work";
|
||||
String output = ((BukkitPlatform) TAB.getInstance().getPlatform()).setPlaceholders(player, placeholder);
|
||||
Map<Object, String> replacements = TAB.getInstance().getConfiguration().premiumconfig.getConfigurationSection("placeholder-output-replacements." + placeholder);
|
||||
Map<Object, String> replacements = TAB.getInstance().getConfiguration().getPremiumConfig().getConfigurationSection("placeholder-output-replacements." + placeholder);
|
||||
return Placeholder.findReplacement(replacements, output).replace("%value%", output);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,87 @@
|
||||
package me.neznamy.tab.platforms.bukkit.features;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.HandlerList;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerRespawnEvent;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import me.neznamy.tab.api.TabPlayer;
|
||||
import me.neznamy.tab.platforms.bukkit.BukkitPacketBuilder;
|
||||
import me.neznamy.tab.shared.TAB;
|
||||
import me.neznamy.tab.shared.cpu.TabFeature;
|
||||
import me.neznamy.tab.shared.cpu.UsageType;
|
||||
import me.neznamy.tab.shared.features.bossbar.BossBar;
|
||||
import me.neznamy.tab.shared.features.types.Loadable;
|
||||
|
||||
/**
|
||||
* An additional class with additional code for <1.9 servers due to an entity being required
|
||||
*/
|
||||
public class WitherBossBar implements Listener, Loadable {
|
||||
|
||||
//distance of wither in blocks
|
||||
private static final int WITHER_DISTANCE = 75;
|
||||
|
||||
//main bossbar feature
|
||||
private BossBar mainFeature;
|
||||
|
||||
/**
|
||||
* Constructs a new instance of the class
|
||||
* @param mainFeature - main bossbar feature
|
||||
*/
|
||||
public WitherBossBar(TAB tab, JavaPlugin plugin) {
|
||||
this.mainFeature = (BossBar) tab.getFeatureManager().getFeature("bossbar");
|
||||
Bukkit.getPluginManager().registerEvents(this, plugin);
|
||||
//bar disappears in client after ~1 second of not seeing boss entity
|
||||
tab.getCPUManager().startRepeatingMeasuredTask(900, "refreshing bossbar", TabFeature.BOSSBAR, UsageType.TELEPORTING_ENTITY, this::teleport);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void load() {
|
||||
teleport();
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates wither location for all players
|
||||
*/
|
||||
private void teleport() {
|
||||
for (TabPlayer all : TAB.getInstance().getPlayers()) {
|
||||
if (all.getVersion().getMinorVersion() > 8) continue; //sending VV packets to those
|
||||
for (me.neznamy.tab.api.bossbar.BossBar l : all.getActiveBossBars()) {
|
||||
try {
|
||||
all.sendPacket(((BukkitPacketBuilder)TAB.getInstance().getPacketBuilder()).buildEntityTeleportPacket(l.getUniqueId().hashCode(), getWitherLocation(all)), TabFeature.BOSSBAR);
|
||||
} catch (Exception e) {
|
||||
TAB.getInstance().getErrorManager().printError("Failed to create PacketPlayOutEntityTeleport", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unload() {
|
||||
HandlerList.unregisterAll(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Respawning wither as respawn screen destroys all entities in client
|
||||
*/
|
||||
@EventHandler
|
||||
public void onRespawn(PlayerRespawnEvent e) {
|
||||
TAB.getInstance().getCPUManager().runMeasuredTask("processing PlayerRespawnEvent", TabFeature.BOSSBAR, UsageType.PLAYER_RESPAWN_EVENT, () -> mainFeature.detectBossBarsAndSend(TAB.getInstance().getPlayer(e.getPlayer().getUniqueId())));
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns location where wither should be located based on where player is looking
|
||||
* @param p - player to get wither location for
|
||||
* @return location of wither
|
||||
*/
|
||||
public Location getWitherLocation(TabPlayer p) {
|
||||
Player pl = (Player) p.getPlayer();
|
||||
Location loc = pl.getEyeLocation().add(pl.getEyeLocation().getDirection().normalize().multiply(WITHER_DISTANCE));
|
||||
if (loc.getY() < 1) loc.setY(1);
|
||||
return loc;
|
||||
}
|
||||
}
|
||||
+34
-34
@@ -17,9 +17,9 @@ import me.neznamy.tab.api.ArmorStand;
|
||||
import me.neznamy.tab.api.TabPlayer;
|
||||
import me.neznamy.tab.platforms.bukkit.BukkitPacketBuilder;
|
||||
import me.neznamy.tab.platforms.bukkit.BukkitTabPlayer;
|
||||
import me.neznamy.tab.platforms.bukkit.nms.NMSStorage;
|
||||
import me.neznamy.tab.platforms.bukkit.nms.datawatcher.DataWatcher;
|
||||
import me.neznamy.tab.shared.Property;
|
||||
import me.neznamy.tab.shared.ProtocolVersion;
|
||||
import me.neznamy.tab.shared.TAB;
|
||||
import me.neznamy.tab.shared.cpu.TabFeature;
|
||||
import me.neznamy.tab.shared.cpu.UsageType;
|
||||
@@ -70,14 +70,14 @@ public class BukkitArmorStand implements ArmorStand {
|
||||
* @param yOffset - offset in blocks
|
||||
* @param staticOffset - if offset is static or not
|
||||
*/
|
||||
public BukkitArmorStand(int entityId, TabPlayer owner, Property property, double yOffset, boolean staticOffset) {
|
||||
public BukkitArmorStand(int entityId, TabPlayer owner, Property property, double yOffset, boolean staticOffset, boolean markerFor18x) {
|
||||
this.entityId = entityId;
|
||||
this.owner = owner;
|
||||
this.staticOffset = staticOffset;
|
||||
player = (Player) owner.getPlayer();
|
||||
this.yOffset = yOffset;
|
||||
this.property = property;
|
||||
markerFor18x = ((NameTagX)TAB.getInstance().getFeatureManager().getFeature("nametagx")).markerFor18x;
|
||||
this.markerFor18x = markerFor18x;
|
||||
visible = getVisibility();
|
||||
}
|
||||
|
||||
@@ -121,7 +121,7 @@ public class BukkitArmorStand implements ArmorStand {
|
||||
visible = getVisibility();
|
||||
nearbyPlayers.add(viewer);
|
||||
DataWatcher dataWatcher = createDataWatcher(property.getFormat(viewer), viewer);
|
||||
if (ProtocolVersion.SERVER_VERSION.getMinorVersion() >= 15) {
|
||||
if (NMSStorage.getInstance().getMinorVersion() >= 15) {
|
||||
return new Object[] {
|
||||
getSpawnPacket(getArmorStandLocationFor(viewer), null),
|
||||
getMetadataPacket(dataWatcher)
|
||||
@@ -145,7 +145,7 @@ public class BukkitArmorStand implements ArmorStand {
|
||||
* @param viewer - player to get location for
|
||||
* @return location of armor stand
|
||||
*/
|
||||
private Location getArmorStandLocationFor(TabPlayer viewer) {
|
||||
protected Location getArmorStandLocationFor(TabPlayer viewer) {
|
||||
return viewer.getVersion().getMinorVersion() == 8 && !markerFor18x ? getLocation().clone().add(0,-2,0) : getLocation();
|
||||
}
|
||||
|
||||
@@ -172,7 +172,7 @@ public class BukkitArmorStand implements ArmorStand {
|
||||
if (this.sneaking == sneaking) return; //idk
|
||||
this.sneaking = sneaking;
|
||||
for (TabPlayer viewer : getNearbyPlayers()) {
|
||||
if (viewer.getVersion().getMinorVersion() == 14 && !TAB.getInstance().getConfiguration().armorStandsAlwaysVisible) {
|
||||
if (viewer.getVersion().getMinorVersion() == 14 && !TAB.getInstance().getConfiguration().isArmorStandsAlwaysVisible()) {
|
||||
//1.14.x client sided bug, despawning completely
|
||||
if (sneaking) {
|
||||
viewer.sendPacket(getDestroyPacket(), TabFeature.NAMETAGX);
|
||||
@@ -185,7 +185,7 @@ public class BukkitArmorStand implements ArmorStand {
|
||||
Runnable spawn = () -> spawn(viewer);
|
||||
if (viewer.getVersion().getMinorVersion() == 8) {
|
||||
//1.8.0 client sided bug
|
||||
TAB.getInstance().getCPUManager().runTaskLater(50, "compensating for 1.8.0 bugs", TabFeature.NAMETAGX, UsageType.v1_8_0_BUG_COMPENSATION, spawn);
|
||||
TAB.getInstance().getCPUManager().runTaskLater(50, "compensating for 1.8.0 bugs", TabFeature.NAMETAGX, UsageType.V1_8_0_BUG_COMPENSATION, spawn);
|
||||
} else {
|
||||
spawn.run();
|
||||
}
|
||||
@@ -201,9 +201,9 @@ public class BukkitArmorStand implements ArmorStand {
|
||||
|
||||
@Override
|
||||
public void updateVisibility(boolean force) {
|
||||
boolean visible = getVisibility();
|
||||
if (this.visible != visible || force) {
|
||||
this.visible = visible;
|
||||
boolean visibility = getVisibility();
|
||||
if (visible != visibility || force) {
|
||||
visible = visibility;
|
||||
updateMetadata();
|
||||
}
|
||||
}
|
||||
@@ -214,7 +214,7 @@ public class BukkitArmorStand implements ArmorStand {
|
||||
* @param viewer - player to get location for
|
||||
* @return teleport packet
|
||||
*/
|
||||
private Object getTeleportPacket(TabPlayer viewer) {
|
||||
protected Object getTeleportPacket(TabPlayer viewer) {
|
||||
try {
|
||||
return ((BukkitPacketBuilder)TAB.getInstance().getPacketBuilder()).buildEntityTeleportPacket(entityId, getArmorStandLocationFor(viewer));
|
||||
} catch (Exception e) {
|
||||
@@ -226,7 +226,7 @@ public class BukkitArmorStand implements ArmorStand {
|
||||
* Returns destroy packet
|
||||
* @return destroy packet
|
||||
*/
|
||||
private Object getDestroyPacket() {
|
||||
protected Object getDestroyPacket() {
|
||||
try {
|
||||
return ((BukkitPacketBuilder)TAB.getInstance().getPacketBuilder()).buildEntityDestroyPacket(entityId);
|
||||
} catch (Exception e) {
|
||||
@@ -239,7 +239,7 @@ public class BukkitArmorStand implements ArmorStand {
|
||||
* @param dataWatcher - datawatcher
|
||||
* @return metadata packet
|
||||
*/
|
||||
private Object getMetadataPacket(DataWatcher dataWatcher) {
|
||||
protected Object getMetadataPacket(DataWatcher dataWatcher) {
|
||||
try {
|
||||
return ((BukkitPacketBuilder)TAB.getInstance().getPacketBuilder()).buildEntityMetadataPacket(entityId, dataWatcher);
|
||||
} catch (Exception e) {
|
||||
@@ -253,7 +253,7 @@ public class BukkitArmorStand implements ArmorStand {
|
||||
* @param dataWatcher - datawatcher
|
||||
* @return spawn packet
|
||||
*/
|
||||
private Object getSpawnPacket(Location loc, DataWatcher dataWatcher) {
|
||||
protected Object getSpawnPacket(Location loc, DataWatcher dataWatcher) {
|
||||
try {
|
||||
return ((BukkitPacketBuilder)TAB.getInstance().getPacketBuilder()).buildEntitySpawnPacket(entityId, uuid, EntityType.ARMOR_STAND, loc, dataWatcher);
|
||||
} catch (Exception e) {
|
||||
@@ -264,7 +264,7 @@ public class BukkitArmorStand implements ArmorStand {
|
||||
/**
|
||||
* Updates armor stand's metadata
|
||||
*/
|
||||
private void updateMetadata() {
|
||||
protected void updateMetadata() {
|
||||
for (TabPlayer viewer : getNearbyPlayers()) {
|
||||
viewer.sendPacket(getMetadataPacket(createDataWatcher(property.getFormat(viewer), viewer)), TabFeature.NAMETAGX);
|
||||
}
|
||||
@@ -274,9 +274,9 @@ public class BukkitArmorStand implements ArmorStand {
|
||||
* Returns general visibility rule for everyone with limited info
|
||||
* @return true if should be visible, false if not
|
||||
*/
|
||||
private boolean getVisibility() {
|
||||
if (((BukkitTabPlayer)owner).isDisguised() || (((NameTagX)TAB.getInstance().getFeatureManager().getFeature("nametagx")).playersOnBoats.contains(owner))) return false;
|
||||
if (TAB.getInstance().getConfiguration().armorStandsAlwaysVisible) return true;
|
||||
protected boolean getVisibility() {
|
||||
if (((BukkitTabPlayer)owner).isDisguised() || (((NameTagX)TAB.getInstance().getFeatureManager().getFeature("nametagx")).getPlayersOnBoats().contains(owner))) return false;
|
||||
if (TAB.getInstance().getConfiguration().isArmorStandsAlwaysVisible()) return true;
|
||||
return !player.hasPotionEffect(PotionEffectType.INVISIBILITY) && player.getGameMode() != GameMode.SPECTATOR && !owner.hasHiddenNametag() && property.get().length() > 0;
|
||||
}
|
||||
|
||||
@@ -284,14 +284,14 @@ public class BukkitArmorStand implements ArmorStand {
|
||||
* Returns general location where armor stand should be at time of calling
|
||||
* @return Location where armor stand should be for everyone
|
||||
*/
|
||||
private Location getLocation() {
|
||||
protected Location getLocation() {
|
||||
double x = player.getLocation().getX();
|
||||
double y = getY() + yOffset + 2;
|
||||
double z = player.getLocation().getZ();
|
||||
if (player.isSleeping()) {
|
||||
y -= 1.76;
|
||||
} else {
|
||||
if (ProtocolVersion.SERVER_VERSION.getMinorVersion() >= 9) {
|
||||
if (NMSStorage.getInstance().getMinorVersion() >= 9) {
|
||||
y -= (sneaking ? 0.45 : 0.18);
|
||||
} else {
|
||||
y -= (sneaking ? 0.30 : 0.18);
|
||||
@@ -304,33 +304,33 @@ public class BukkitArmorStand implements ArmorStand {
|
||||
* Returns Y where player is based on player's vehicle due to bukkit API bug
|
||||
* @return correct player's Y
|
||||
*/
|
||||
private double getY() {
|
||||
//1.14+ bukkit api bug
|
||||
protected double getY() {
|
||||
//1.14+ server sided bug
|
||||
Entity vehicle = player.getVehicle();
|
||||
if (vehicle != null) {
|
||||
if (vehicle.getType() == EntityType.HORSE) {
|
||||
if (vehicle.getType().toString().contains("HORSE")) { //covering all 3 horse types
|
||||
return vehicle.getLocation().getY() + 0.85;
|
||||
}
|
||||
if (vehicle.getType().toString().equals("DONKEY")) {
|
||||
if (vehicle.getType().toString().equals("DONKEY")) { //1.11+
|
||||
return vehicle.getLocation().getY() + 0.525;
|
||||
}
|
||||
if (vehicle.getType() == EntityType.PIG) {
|
||||
return vehicle.getLocation().getY() + 0.325;
|
||||
}
|
||||
if (vehicle.getType().toString().equals("STRIDER")) { //preventing errors on <1.16
|
||||
if (vehicle.getType().toString().equals("STRIDER")) { //1.16+
|
||||
return vehicle.getLocation().getY() + 1.15;
|
||||
}
|
||||
}
|
||||
//1.13+ swimming or 1.9+ flying with elytra
|
||||
if (isSwimming() || (ProtocolVersion.SERVER_VERSION.getMinorVersion() >= 9 && player.isGliding())) {
|
||||
if (isSwimming() || (NMSStorage.getInstance().getMinorVersion() >= 9 && player.isGliding())) {
|
||||
return player.getLocation().getY()-1.22;
|
||||
}
|
||||
return player.getLocation().getY();
|
||||
}
|
||||
|
||||
private boolean isSwimming() {
|
||||
if (ProtocolVersion.SERVER_VERSION.getMinorVersion() >= 14 && player.getPose() == Pose.SWIMMING) return true;
|
||||
return ProtocolVersion.SERVER_VERSION.getMinorVersion() == 13 && player.isSwimming();
|
||||
if (NMSStorage.getInstance().getMinorVersion() >= 14 && player.getPose() == Pose.SWIMMING) return true;
|
||||
return NMSStorage.getInstance().getMinorVersion() == 13 && player.isSwimming();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -349,7 +349,7 @@ public class BukkitArmorStand implements ArmorStand {
|
||||
* @param viewer - player to apply checks against
|
||||
* @return datawatcher for viewer
|
||||
*/
|
||||
private DataWatcher createDataWatcher(String displayName, TabPlayer viewer) {
|
||||
protected DataWatcher createDataWatcher(String displayName, TabPlayer viewer) {
|
||||
DataWatcher datawatcher = new DataWatcher();
|
||||
|
||||
byte flag = 32; //invisible
|
||||
@@ -357,13 +357,13 @@ public class BukkitArmorStand implements ArmorStand {
|
||||
datawatcher.helper().setEntityFlags(flag);
|
||||
datawatcher.helper().setCustomName(displayName, viewer.getVersion());
|
||||
|
||||
boolean visible;
|
||||
boolean visibility;
|
||||
if (isNameVisiblyEmpty(displayName) || !((Player) viewer.getPlayer()).canSee(player) || owner.hasHiddenNametag(viewer.getUniqueId())) {
|
||||
visible = false;
|
||||
visibility = false;
|
||||
} else {
|
||||
visible = this.visible;
|
||||
visibility = visible;
|
||||
}
|
||||
datawatcher.helper().setCustomNameVisible(visible);
|
||||
datawatcher.helper().setCustomNameVisible(visibility);
|
||||
|
||||
if (viewer.getVersion().getMinorVersion() > 8 || markerFor18x) datawatcher.helper().setArmorStandFlags((byte)16);
|
||||
return datawatcher;
|
||||
@@ -372,7 +372,7 @@ public class BukkitArmorStand implements ArmorStand {
|
||||
@Override
|
||||
public Set<TabPlayer> getNearbyPlayers(){
|
||||
synchronized (nearbyPlayers) {
|
||||
return new HashSet<TabPlayer>(nearbyPlayers);
|
||||
return new HashSet<>(nearbyPlayers);
|
||||
}
|
||||
}
|
||||
|
||||
+55
@@ -0,0 +1,55 @@
|
||||
package me.neznamy.tab.platforms.bukkit.features.unlimitedtags;
|
||||
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerRespawnEvent;
|
||||
import org.bukkit.event.player.PlayerToggleSneakEvent;
|
||||
|
||||
import me.neznamy.tab.api.TabPlayer;
|
||||
import me.neznamy.tab.shared.TAB;
|
||||
import me.neznamy.tab.shared.cpu.TabFeature;
|
||||
import me.neznamy.tab.shared.cpu.UsageType;
|
||||
|
||||
/**
|
||||
* The event listener part for securing proper functionality of armor stands
|
||||
*/
|
||||
public class EventListener implements Listener {
|
||||
|
||||
//the nametag feature handler
|
||||
private NameTagX feature;
|
||||
|
||||
/**
|
||||
* Constructs new instance with given parameters
|
||||
* @param feature - nametagx feature handler
|
||||
*/
|
||||
public EventListener(NameTagX feature) {
|
||||
this.feature = feature;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sneak event listener to despawn & spawn armor stands to skip animation
|
||||
* @param e - sneak event
|
||||
*/
|
||||
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
||||
public void onSneak(PlayerToggleSneakEvent e) {
|
||||
TabPlayer p = TAB.getInstance().getPlayer(e.getPlayer().getUniqueId());
|
||||
if (p == null || !p.isLoaded() || feature.isInDisabledWorld(p)) return;
|
||||
TAB.getInstance().getCPUManager().runMeasuredTask("processing PlayerToggleSneakEvent", TabFeature.NAMETAGX, UsageType.PLAYER_TOGGLE_SNEAK_EVENT, () -> {
|
||||
if (p.getArmorStandManager() != null) p.getArmorStandManager().sneak(e.isSneaking());
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Respawning armor stands as respawn screen destroys all entities in client
|
||||
* @param e - respawn event
|
||||
*/
|
||||
@EventHandler
|
||||
public void onRespawn(PlayerRespawnEvent e) {
|
||||
TAB.getInstance().getCPUManager().runMeasuredTask("processing PlayerRespawnEvent", TabFeature.NAMETAGX, UsageType.PLAYER_RESPAWN_EVENT, () -> {
|
||||
TabPlayer respawned = TAB.getInstance().getPlayer(e.getPlayer().getUniqueId());
|
||||
if (feature.isInDisabledWorld(respawned)) return;
|
||||
respawned.getArmorStandManager().teleport();
|
||||
});
|
||||
}
|
||||
}
|
||||
+441
@@ -0,0 +1,441 @@
|
||||
package me.neznamy.tab.platforms.bukkit.features.unlimitedtags;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.HandlerList;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import me.neznamy.tab.api.ArmorStand;
|
||||
import me.neznamy.tab.api.ArmorStandManager;
|
||||
import me.neznamy.tab.api.TabPlayer;
|
||||
import me.neznamy.tab.platforms.bukkit.nms.NMSStorage;
|
||||
import me.neznamy.tab.shared.Property;
|
||||
import me.neznamy.tab.shared.PropertyUtils;
|
||||
import me.neznamy.tab.shared.TAB;
|
||||
import me.neznamy.tab.shared.cpu.TabFeature;
|
||||
import me.neznamy.tab.shared.cpu.UsageType;
|
||||
import me.neznamy.tab.shared.features.NameTag;
|
||||
|
||||
/**
|
||||
* The core class for unlimited nametag mode
|
||||
*/
|
||||
public class NameTagX extends NameTag {
|
||||
|
||||
//config options
|
||||
private boolean markerFor18x;
|
||||
private boolean disableOnBoats;
|
||||
private double spaceBetweenLines;
|
||||
|
||||
//list of worlds with unlimited nametag mode disabled
|
||||
protected List<String> disabledUnlimitedWorlds;
|
||||
|
||||
//list of defined dynamic lines
|
||||
private List<String> dynamicLines = Arrays.asList(PropertyUtils.BELOWNAME, PropertyUtils.NAMETAG, PropertyUtils.ABOVENAME);
|
||||
|
||||
//map of defined static lines
|
||||
private Map<String, Object> staticLines = new ConcurrentHashMap<>();
|
||||
|
||||
//entity id counter to pick unique entity IDs
|
||||
private int idCounter = 2000000000;
|
||||
|
||||
//player data by entityId, used for better performance
|
||||
private Map<Integer, TabPlayer> entityIdMap = new ConcurrentHashMap<>();
|
||||
|
||||
//map of vehicles carrying players
|
||||
private Map<Integer, List<Entity>> vehicles = new ConcurrentHashMap<>();
|
||||
|
||||
//bukkit event listener
|
||||
private EventListener eventListener;
|
||||
|
||||
//list of players currently on boats
|
||||
private List<TabPlayer> playersOnBoats = new ArrayList<>();
|
||||
|
||||
//list of players currently in a vehicle
|
||||
private Map<TabPlayer, Entity> playersInVehicle = new ConcurrentHashMap<>();
|
||||
|
||||
private Map<TabPlayer, Location> playerLocations = new ConcurrentHashMap<>();
|
||||
|
||||
private Set<TabPlayer> playersInDisabledUnlimitedWorlds = new HashSet<>();
|
||||
|
||||
/**
|
||||
* Constructs new instance with given parameters and loads config options
|
||||
* @param plugin - plugin instance
|
||||
* @param nms - nms storage
|
||||
* @param tab - tab instance
|
||||
*/
|
||||
public NameTagX(JavaPlugin plugin, NMSStorage nms, TAB tab) {
|
||||
super(tab);
|
||||
markerFor18x = tab.getConfiguration().getConfig().getBoolean("unlimited-nametag-prefix-suffix-mode.use-marker-tag-for-1-8-x-clients", false);
|
||||
disableOnBoats = tab.getConfiguration().getConfig().getBoolean("unlimited-nametag-prefix-suffix-mode.disable-on-boats", true);
|
||||
spaceBetweenLines = tab.getConfiguration().getConfig().getDouble("unlimited-nametag-prefix-suffix-mode.space-between-lines", 0.22);
|
||||
disabledUnlimitedWorlds = tab.getConfiguration().getConfig().getStringList("disable-features-in-worlds.unlimited-nametags", Arrays.asList("disabledworld"));
|
||||
if (tab.getConfiguration().getPremiumConfig() != null) {
|
||||
List<String> realList = tab.getConfiguration().getPremiumConfig().getStringList("unlimited-nametag-mode-dynamic-lines", Arrays.asList(PropertyUtils.ABOVENAME, PropertyUtils.NAMETAG, PropertyUtils.BELOWNAME, "another"));
|
||||
dynamicLines = new ArrayList<>();
|
||||
dynamicLines.addAll(realList);
|
||||
Collections.reverse(dynamicLines);
|
||||
staticLines = tab.getConfiguration().getPremiumConfig().getConfigurationSection("unlimited-nametag-mode-static-lines");
|
||||
}
|
||||
refreshUsedPlaceholders();
|
||||
eventListener = new EventListener(this);
|
||||
Bukkit.getPluginManager().registerEvents(eventListener, plugin);
|
||||
tab.getFeatureManager().registerFeature("nametagx-packet", new PacketListener(this, nms, tab));
|
||||
tab.debug(String.format("Loaded Unlimited nametag feature with parameters markerFor18x=%s, disableOnBoats=%s, spaceBetweenLines=%s, disabledUnlimitedWorlds=%s",
|
||||
markerFor18x, disableOnBoats, spaceBetweenLines, disabledUnlimitedWorlds));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void load() {
|
||||
super.load();
|
||||
for (TabPlayer all : tab.getPlayers()) {
|
||||
getEntityIdMap().put(((Player) all.getPlayer()).getEntityId(), all);
|
||||
loadArmorStands(all);
|
||||
if (isDisabledWorld(disabledUnlimitedWorlds, all.getWorldName())) {
|
||||
playersInDisabledUnlimitedWorlds.add(all);
|
||||
}
|
||||
if (isInDisabledWorld(all)) continue;
|
||||
loadPassengers(all);
|
||||
for (TabPlayer viewer : tab.getPlayers()) {
|
||||
spawnArmorStands(all, viewer, false);
|
||||
}
|
||||
}
|
||||
startVisibilityRefreshTask();
|
||||
startVehicleTickingTask();
|
||||
}
|
||||
|
||||
private void startVisibilityRefreshTask() {
|
||||
tab.getCPUManager().startRepeatingMeasuredTask(500, "refreshing nametag visibility", getFeatureType(), UsageType.REFRESHING_NAMETAG_VISIBILITY_AND_COLLISION, () -> {
|
||||
|
||||
for (TabPlayer p : tab.getPlayers()) {
|
||||
if (!p.isLoaded() || isInDisabledWorld(p)) continue;
|
||||
p.getArmorStandManager().updateVisibility(false);
|
||||
if (disableOnBoats) processBoats(p);
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void processBoats(TabPlayer p) {
|
||||
boolean onBoat = ((Player)p.getPlayer()).getVehicle() != null && ((Player)p.getPlayer()).getVehicle().getType() == EntityType.BOAT;
|
||||
if (onBoat) {
|
||||
if (!getPlayersOnBoats().contains(p)) {
|
||||
getPlayersOnBoats().add(p);
|
||||
updateTeamData(p);
|
||||
}
|
||||
} else {
|
||||
if (getPlayersOnBoats().contains(p)) {
|
||||
getPlayersOnBoats().remove(p);
|
||||
updateTeamData(p);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void startVehicleTickingTask() {
|
||||
tab.getCPUManager().startRepeatingMeasuredTask(100, "ticking vehicles", TabFeature.NAMETAGX, UsageType.TICKING_VEHICLES, () -> {
|
||||
|
||||
for (TabPlayer p : TAB.getInstance().getPlayers()) {
|
||||
if (!p.isLoaded()) continue;
|
||||
if (isInDisabledWorld(p)) {
|
||||
playersInVehicle.remove(p);
|
||||
playerLocations.remove(p);
|
||||
} else {
|
||||
processVehicles(p);
|
||||
if (!playerLocations.containsKey(p) || !playerLocations.get(p).equals(((Player)p.getPlayer()).getLocation())) {
|
||||
playerLocations.put(p, ((Player)p.getPlayer()).getLocation());
|
||||
processPassengers((Entity) p.getPlayer());
|
||||
//also updating position if player is previewing since we're here as the code would be same if we want to avoid listening to move event
|
||||
if (p.isPreviewingNametag() && p.getArmorStandManager() != null) {
|
||||
p.getArmorStandManager().teleport(p);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks for vehicle changes of player and sends packets if needed
|
||||
* @param p - player to check
|
||||
*/
|
||||
private void processVehicles(TabPlayer p) {
|
||||
Entity vehicle = ((Player)p.getPlayer()).getVehicle();
|
||||
if (playersInVehicle.containsKey(p) && vehicle == null) {
|
||||
//vehicle exit
|
||||
getVehicles().remove(playersInVehicle.get(p).getEntityId());
|
||||
p.getArmorStandManager().teleport();
|
||||
playersInVehicle.remove(p);
|
||||
}
|
||||
if (!playersInVehicle.containsKey(p) && vehicle != null) {
|
||||
//vehicle enter
|
||||
getVehicles().put(vehicle.getEntityId(), getPassengers(vehicle));
|
||||
p.getArmorStandManager().teleport();
|
||||
playersInVehicle.put(p, vehicle);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Teleports armor stands of all passengers on specified vehicle
|
||||
* @param vehicle - entity to check passengers of
|
||||
*/
|
||||
private void processPassengers(Entity vehicle) {
|
||||
for (Entity passenger : getPassengers(vehicle)) {
|
||||
if (passenger instanceof Player) {
|
||||
TabPlayer pl = TAB.getInstance().getPlayer(passenger.getUniqueId());
|
||||
pl.getArmorStandManager().teleport();
|
||||
} else {
|
||||
processPassengers(passenger);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unload() {
|
||||
super.unload();
|
||||
HandlerList.unregisterAll(eventListener);
|
||||
for (TabPlayer p : tab.getPlayers()) {
|
||||
if (p.getArmorStandManager() != null) p.getArmorStandManager().destroy();
|
||||
}
|
||||
getEntityIdMap().clear();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onJoin(TabPlayer connectedPlayer) {
|
||||
super.onJoin(connectedPlayer);
|
||||
getEntityIdMap().put(((Player) connectedPlayer.getPlayer()).getEntityId(), connectedPlayer);
|
||||
loadArmorStands(connectedPlayer);
|
||||
if (isDisabledWorld(disabledUnlimitedWorlds, connectedPlayer.getWorldName())) {
|
||||
playersInDisabledUnlimitedWorlds.add(connectedPlayer);
|
||||
return;
|
||||
}
|
||||
if (isInDisabledWorld(connectedPlayer)) return;
|
||||
loadPassengers(connectedPlayer);
|
||||
for (TabPlayer viewer : tab.getPlayers()) {
|
||||
spawnArmorStands(connectedPlayer, viewer, true);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns flat distance between two players ignoring Y value
|
||||
* @param player1 - first player
|
||||
* @param player2 - second player
|
||||
* @return flat distance in blocks
|
||||
*/
|
||||
private double getDistance(TabPlayer player1, TabPlayer player2) {
|
||||
Location loc1 = ((Player) player1.getPlayer()).getLocation();
|
||||
Location loc2 = ((Player) player2.getPlayer()).getLocation();
|
||||
return Math.sqrt(Math.pow(loc1.getX()-loc2.getX(), 2) + Math.pow(loc1.getZ()-loc2.getZ(), 2));
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads all passengers riding this player and adds them to vehicle list
|
||||
* @param p - player to load passengers of
|
||||
*/
|
||||
private void loadPassengers(TabPlayer p) {
|
||||
if (((Entity) p.getPlayer()).getVehicle() == null) return;
|
||||
Entity vehicle = ((Entity) p.getPlayer()).getVehicle();
|
||||
getVehicles().put(vehicle.getEntityId(), getPassengers(vehicle));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onQuit(TabPlayer disconnectedPlayer) {
|
||||
super.onQuit(disconnectedPlayer);
|
||||
for (TabPlayer all : tab.getPlayers()) {
|
||||
if (all.getArmorStandManager() != null) all.getArmorStandManager().unregisterPlayer(disconnectedPlayer);
|
||||
}
|
||||
getEntityIdMap().remove(((Player) disconnectedPlayer.getPlayer()).getEntityId());
|
||||
playersInVehicle.remove(disconnectedPlayer);
|
||||
playerLocations.remove(disconnectedPlayer);
|
||||
playersInDisabledUnlimitedWorlds.remove(disconnectedPlayer);
|
||||
tab.getCPUManager().runTaskLater(100, "processing onQuit", getFeatureType(), UsageType.PLAYER_QUIT_EVENT, () -> disconnectedPlayer.getArmorStandManager().destroy());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onWorldChange(TabPlayer p, String from, String to) {
|
||||
super.onWorldChange(p, from, to);
|
||||
if (isDisabledWorld(disabledWorlds, p.getWorldName())) {
|
||||
playersInDisabledWorlds.add(p);
|
||||
} else {
|
||||
playersInDisabledWorlds.remove(p);
|
||||
}
|
||||
Set<TabPlayer> nearby = p.getArmorStandManager().getNearbyPlayers();
|
||||
p.getArmorStandManager().destroy();
|
||||
loadArmorStands(p);
|
||||
loadPassengers(p);
|
||||
for (TabPlayer viewer : tab.getPlayers()) {
|
||||
viewer.getArmorStandManager().destroy(p);
|
||||
if (nearby.contains(viewer) && to.equals(viewer.getWorldName())) spawnArmorStands(p, viewer, true);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Spawns armor stands of specified owner to viewer and, mutually if set
|
||||
* @param owner - armor stand owner
|
||||
* @param viewer - player to spawn armor stands for
|
||||
* @param sendMutually - if packets should be sent both ways
|
||||
*/
|
||||
private void spawnArmorStands(TabPlayer owner, TabPlayer viewer, boolean sendMutually) {
|
||||
if (owner == viewer) return; //not displaying own armorstands
|
||||
if (((Player) viewer.getPlayer()).getWorld() != ((Player) owner.getPlayer()).getWorld()) return; //different world
|
||||
if (isInDisabledWorld(owner)) return;
|
||||
if (getDistance(viewer, owner) <= 48) {
|
||||
if (((Player)viewer.getPlayer()).canSee((Player)owner.getPlayer()) && !owner.isVanished()) owner.getArmorStandManager().spawn(viewer);
|
||||
if (sendMutually && viewer.getArmorStandManager() != null && ((Player)owner.getPlayer()).canSee((Player)viewer.getPlayer())
|
||||
&& !viewer.isVanished()) viewer.getArmorStandManager().spawn(owner);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Restarts and loads armor stands from config
|
||||
* @param pl - player to load
|
||||
*/
|
||||
public void loadArmorStands(TabPlayer pl) {
|
||||
pl.setArmorStandManager(new ArmorStandManager());
|
||||
pl.setProperty(PropertyUtils.NAMETAG, pl.getProperty(PropertyUtils.TAGPREFIX).getCurrentRawValue() + pl.getProperty(PropertyUtils.CUSTOMTAGNAME).getCurrentRawValue() + pl.getProperty(PropertyUtils.TAGSUFFIX).getCurrentRawValue());
|
||||
double height = 0;
|
||||
for (String line : dynamicLines) {
|
||||
Property p = pl.getProperty(line);
|
||||
if (p.getCurrentRawValue().length() == 0) continue;
|
||||
pl.getArmorStandManager().addArmorStand(line, new BukkitArmorStand(idCounter++, pl, p, height, false, markerFor18x));
|
||||
height += spaceBetweenLines;
|
||||
}
|
||||
for (Entry<String, Object> line : staticLines.entrySet()) {
|
||||
Property p = pl.getProperty(line.getKey());
|
||||
if (p.getCurrentRawValue().length() == 0) continue;
|
||||
pl.getArmorStandManager().addArmorStand(line.getKey(), new BukkitArmorStand(idCounter++, pl, p, Double.parseDouble(line.getValue().toString()), true, markerFor18x));
|
||||
}
|
||||
fixArmorStandHeights(pl);
|
||||
}
|
||||
|
||||
/**
|
||||
* Fixes heights of all armor stands of specified player due to dynamic lines
|
||||
* @param p - player to fix armor stands heights for
|
||||
*/
|
||||
public void fixArmorStandHeights(TabPlayer p) {
|
||||
p.getArmorStandManager().refresh();
|
||||
double currentY = -spaceBetweenLines;
|
||||
for (ArmorStand as : p.getArmorStandManager().getArmorStands()) {
|
||||
if (as.hasStaticOffset()) continue;
|
||||
if (as.getProperty().get().length() != 0) {
|
||||
currentY += spaceBetweenLines;
|
||||
as.setOffset(currentY);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void refresh(TabPlayer refreshed, boolean force) {
|
||||
super.refresh(refreshed, force);
|
||||
if (isInDisabledWorld(refreshed)) return;
|
||||
if (force) {
|
||||
refreshed.getArmorStandManager().destroy();
|
||||
loadArmorStands(refreshed);
|
||||
loadPassengers(refreshed);
|
||||
for (TabPlayer viewer : tab.getPlayers()) {
|
||||
if (viewer == refreshed) continue;
|
||||
if (viewer.getWorldName().equals(refreshed.getWorldName())) {
|
||||
refreshed.getArmorStandManager().spawn(viewer);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
boolean fix = false;
|
||||
for (ArmorStand as : refreshed.getArmorStandManager().getArmorStands()) {
|
||||
if (as.getProperty().update()) {
|
||||
as.refresh();
|
||||
fix = true;
|
||||
}
|
||||
}
|
||||
if (fix) fixArmorStandHeights(refreshed);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates raw values of properties for specified player
|
||||
* @param p - player to update
|
||||
*/
|
||||
@Override
|
||||
public void updateProperties(TabPlayer p) {
|
||||
super.updateProperties(p);
|
||||
p.loadPropertyFromConfig(PropertyUtils.CUSTOMTAGNAME, p.getName());
|
||||
p.setProperty(PropertyUtils.NAMETAG, p.getProperty(PropertyUtils.TAGPREFIX).getCurrentRawValue() + p.getProperty(PropertyUtils.CUSTOMTAGNAME).getCurrentRawValue() + p.getProperty(PropertyUtils.TAGSUFFIX).getCurrentRawValue());
|
||||
for (String property : dynamicLines) {
|
||||
if (!property.equals(PropertyUtils.NAMETAG)) p.loadPropertyFromConfig(property);
|
||||
}
|
||||
for (String property : staticLines.keySet()) {
|
||||
if (!property.equals(PropertyUtils.NAMETAG)) p.loadPropertyFromConfig(property);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns list of all passengers on specified vehicle
|
||||
* @param vehicle - vehicle to check passengers of
|
||||
* @return list of passengers
|
||||
*/
|
||||
@SuppressWarnings("deprecation")
|
||||
public List<Entity> getPassengers(Entity vehicle){
|
||||
if (NMSStorage.getInstance().getMinorVersion() >= 11) {
|
||||
return vehicle.getPassengers();
|
||||
} else {
|
||||
if (vehicle.getPassenger() != null) {
|
||||
return Arrays.asList(vehicle.getPassenger());
|
||||
} else {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void refreshUsedPlaceholders() {
|
||||
usedPlaceholders = new HashSet<>(tab.getConfiguration().getConfig().getUsedPlaceholderIdentifiersRecursive(PropertyUtils.TAGPREFIX, PropertyUtils.CUSTOMTAGNAME, PropertyUtils.TAGSUFFIX));
|
||||
for (String line : dynamicLines) {
|
||||
usedPlaceholders.addAll(tab.getConfiguration().getConfig().getUsedPlaceholderIdentifiersRecursive(line));
|
||||
}
|
||||
for (String line : staticLines.keySet()) {
|
||||
usedPlaceholders.addAll(tab.getConfiguration().getConfig().getUsedPlaceholderIdentifiersRecursive(line));
|
||||
}
|
||||
for (TabPlayer p : tab.getPlayers()) {
|
||||
usedPlaceholders.addAll(tab.getPlaceholderManager().getUsedPlaceholderIdentifiersRecursive(p.getProperty(PropertyUtils.TAGPREFIX).getCurrentRawValue(),
|
||||
p.getProperty(PropertyUtils.CUSTOMTAGNAME).getCurrentRawValue(), p.getProperty(PropertyUtils.TAGSUFFIX).getCurrentRawValue(),
|
||||
p.getProperty(PropertyUtils.ABOVENAME).getCurrentRawValue(), p.getProperty(PropertyUtils.BELOWNAME).getCurrentRawValue()));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public TabFeature getFeatureType() {
|
||||
return TabFeature.NAMETAGX;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean getTeamVisibility(TabPlayer p, TabPlayer viewer) {
|
||||
//only visible if player is on boat & config option is enabled and player is not invisible (1.8 bug) or feature is disabled
|
||||
return (getPlayersOnBoats().contains(p) && !invisiblePlayers.contains(p.getName())) || isInDisabledWorld(p);
|
||||
}
|
||||
|
||||
public Map<Integer, TabPlayer> getEntityIdMap() {
|
||||
return entityIdMap;
|
||||
}
|
||||
|
||||
public Map<Integer, List<Entity>> getVehicles() {
|
||||
return vehicles;
|
||||
}
|
||||
|
||||
public List<TabPlayer> getPlayersOnBoats() {
|
||||
return playersOnBoats;
|
||||
}
|
||||
|
||||
public boolean isInDisabledWorld(TabPlayer p) {
|
||||
return playersInDisabledWorlds.contains(p) || isDisabledWorld(disabledUnlimitedWorlds, p.getWorldName());
|
||||
}
|
||||
}
|
||||
+138
@@ -0,0 +1,138 @@
|
||||
package me.neznamy.tab.platforms.bukkit.features.unlimitedtags;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import me.neznamy.tab.api.TabPlayer;
|
||||
import me.neznamy.tab.platforms.bukkit.nms.NMSStorage;
|
||||
import me.neznamy.tab.shared.TAB;
|
||||
import me.neznamy.tab.shared.cpu.TabFeature;
|
||||
import me.neznamy.tab.shared.cpu.UsageType;
|
||||
import me.neznamy.tab.shared.features.types.packet.RawPacketListener;
|
||||
|
||||
/**
|
||||
* The packet listening part for securing proper functionality of armor stands
|
||||
* Bukkit events are too unreliable and delayed/ahead which causes desync
|
||||
*/
|
||||
public class PacketListener implements RawPacketListener {
|
||||
|
||||
//main feature
|
||||
private NameTagX nameTagX;
|
||||
|
||||
//nms storage
|
||||
private NMSStorage nms;
|
||||
|
||||
//tab instance
|
||||
private TAB tab;
|
||||
|
||||
/**
|
||||
* Constructs new instance with given parameters and loads config options
|
||||
* @param nameTagX - main feature
|
||||
* @param nms - nms storage
|
||||
* @param tab - tab instance
|
||||
*/
|
||||
public PacketListener(NameTagX nameTagX, NMSStorage nms, TAB tab) {
|
||||
this.nameTagX = nameTagX;
|
||||
this.nms = nms;
|
||||
this.tab = tab;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object onPacketReceive(TabPlayer sender, Object packet) throws IllegalAccessException {
|
||||
if (sender.getVersion().getMinorVersion() == 8 && nms.getClass("PacketPlayInUseEntity").isInstance(packet)) {
|
||||
int entityId = nms.getField("PacketPlayInUseEntity_ENTITY").getInt(packet);
|
||||
TabPlayer attacked = null;
|
||||
for (TabPlayer all : tab.getPlayers()) {
|
||||
if (all.isLoaded() && all.getArmorStandManager().hasArmorStandWithID(entityId)) {
|
||||
attacked = all;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (attacked != null && attacked != sender) {
|
||||
nms.setField(packet, "PacketPlayInUseEntity_ENTITY", ((Player) attacked.getPlayer()).getEntityId());
|
||||
}
|
||||
}
|
||||
return packet;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public void onPacketSend(TabPlayer receiver, Object packet) throws IllegalAccessException {
|
||||
if (receiver.getVersion().getMinorVersion() < 8) return;
|
||||
//using bukkit player to check world due to old data on world change due to asynchronous processing & world name changing
|
||||
String world = ((Player)receiver.getPlayer()).getWorld().getName();
|
||||
if (!receiver.isLoaded() || nameTagX.getPlayersInDisabledWorlds().contains(receiver) || nameTagX.isDisabledWorld(nameTagX.disabledUnlimitedWorlds, world)) return;
|
||||
if (nms.getClass("PacketPlayOutEntity").isInstance(packet) && !nms.getClass("PacketPlayOutEntityLook").isInstance(packet)) { //ignoring head rotation only packets
|
||||
onEntityMove(receiver, nms.getField("PacketPlayOutEntity_ENTITYID").getInt(packet));
|
||||
} else if (nms.getClass("PacketPlayOutEntityTeleport").isInstance(packet)) {
|
||||
onEntityMove(receiver, nms.getField("PacketPlayOutEntityTeleport_ENTITYID").getInt(packet));
|
||||
} else if (nms.getClass("PacketPlayOutNamedEntitySpawn").isInstance(packet)) {
|
||||
onEntitySpawn(receiver, nms.getField("PacketPlayOutNamedEntitySpawn_ENTITYID").getInt(packet));
|
||||
} else if (nms.getClass("PacketPlayOutEntityDestroy").isInstance(packet)) {
|
||||
if (nms.getMinorVersion() >= 17) {
|
||||
try {
|
||||
onEntityDestroy(receiver, (List<Integer>) nms.getField("PacketPlayOutEntityDestroy_ENTITIES").get(packet));
|
||||
} catch (ClassCastException e) {
|
||||
//1.17.0
|
||||
onEntityDestroy(receiver, nms.getField("PacketPlayOutEntityDestroy_ENTITIES").getInt(packet));
|
||||
}
|
||||
} else {
|
||||
onEntityDestroy(receiver, (int[]) nms.getField("PacketPlayOutEntityDestroy_ENTITIES").get(packet));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Processes entity move packet
|
||||
* @param receiver - packet receiver
|
||||
* @param entityId - entity that moved
|
||||
*/
|
||||
private void onEntityMove(TabPlayer receiver, int entityId) {
|
||||
TabPlayer pl = nameTagX.getEntityIdMap().get(entityId);
|
||||
List<Entity> vehicleList;
|
||||
if (pl != null) {
|
||||
//player moved
|
||||
tab.getCPUManager().runMeasuredTask("processing EntityMove", getFeatureType(), UsageType.PACKET_ENTITY_MOVE, () -> pl.getArmorStandManager().teleport(receiver));
|
||||
} else if ((vehicleList = nameTagX.getVehicles().get(entityId)) != null){
|
||||
//a vehicle carrying something moved
|
||||
for (Entity entity : vehicleList) {
|
||||
TabPlayer passenger = nameTagX.getEntityIdMap().get(entity.getEntityId());
|
||||
if (passenger != null && passenger.getArmorStandManager() != null) {
|
||||
tab.getCPUManager().runMeasuredTask("processing EntityMove", getFeatureType(), UsageType.PACKET_ENTITY_MOVE, () -> passenger.getArmorStandManager().teleport(receiver));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void onEntitySpawn(TabPlayer receiver, int entityId) {
|
||||
TabPlayer spawnedPlayer = nameTagX.getEntityIdMap().get(entityId);
|
||||
if (spawnedPlayer != null && spawnedPlayer.isLoaded()) {
|
||||
tab.getCPUManager().runMeasuredTask("processing NamedEntitySpawn", getFeatureType(), UsageType.PACKET_NAMED_ENTITY_SPAWN, () -> spawnedPlayer.getArmorStandManager().spawn(receiver));
|
||||
}
|
||||
}
|
||||
|
||||
private void onEntityDestroy(TabPlayer receiver, List<Integer> entities) {
|
||||
for (int entity : entities) {
|
||||
onEntityDestroy(receiver, entity);
|
||||
}
|
||||
}
|
||||
|
||||
private void onEntityDestroy(TabPlayer receiver, int... entities) {
|
||||
for (int entity : entities) {
|
||||
onEntityDestroy(receiver, entity);
|
||||
}
|
||||
}
|
||||
|
||||
private void onEntityDestroy(TabPlayer receiver, int entity) {
|
||||
TabPlayer despawnedPlayer = nameTagX.getEntityIdMap().get(entity);
|
||||
if (despawnedPlayer != null && despawnedPlayer.isLoaded())
|
||||
tab.getCPUManager().runMeasuredTask("processing EntityDestroy", getFeatureType(), UsageType.PACKET_ENTITY_DESTROY, () -> despawnedPlayer.getArmorStandManager().destroy(receiver));
|
||||
}
|
||||
|
||||
@Override
|
||||
public TabFeature getFeatureType() {
|
||||
return TabFeature.NAMETAGX;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,524 @@
|
||||
package me.neznamy.tab.platforms.bukkit.nms;
|
||||
|
||||
import java.lang.reflect.Array;
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
|
||||
import io.netty.channel.Channel;
|
||||
import me.neznamy.tab.platforms.bukkit.Main;
|
||||
import me.neznamy.tab.platforms.bukkit.nms.datawatcher.DataWatcherRegistry;
|
||||
import me.neznamy.tab.shared.TAB;
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
public class NMSStorage {
|
||||
|
||||
//instance of this class
|
||||
private static NMSStorage instance;
|
||||
|
||||
//data watcher registry
|
||||
private DataWatcherRegistry dataWatcherRegistry;
|
||||
|
||||
//server package, such as "v1_16_R3"
|
||||
private String serverPackage;
|
||||
|
||||
//server minor version such as "16"
|
||||
private int minorVersion;
|
||||
|
||||
private Map<String, Class<?>> classes = new HashMap<>();
|
||||
private Map<String, Constructor<?>> constructors = new HashMap<>();
|
||||
private Map<String, Field> fields = new HashMap<>();
|
||||
private Map<String, Method> methods = new HashMap<>();
|
||||
private Map<String, Enum[]> enums = new HashMap<>();
|
||||
|
||||
/**
|
||||
* Creates new instance, initializes required NMS classes and fields
|
||||
* @throws NoSuchFieldException
|
||||
* @throws SecurityException
|
||||
* @throws NoSuchMethodException
|
||||
* @throws ClassNotFoundException
|
||||
* @throws InvocationTargetException
|
||||
* @throws IllegalAccessException
|
||||
*/
|
||||
public NMSStorage() throws NoSuchFieldException, NoSuchMethodException, SecurityException, ClassNotFoundException, IllegalAccessException, InvocationTargetException {
|
||||
serverPackage = Bukkit.getServer().getClass().getPackage().getName().split("\\.")[3];
|
||||
minorVersion = Integer.parseInt(serverPackage.split("_")[1]);
|
||||
classes.put("EnumChatFormat", getNMSClass("net.minecraft.EnumChatFormat", "EnumChatFormat"));
|
||||
classes.put("EntityPlayer", getNMSClass("net.minecraft.server.level.EntityPlayer", "EntityPlayer"));
|
||||
classes.put("Entity", getNMSClass("net.minecraft.world.entity.Entity", "Entity"));
|
||||
classes.put("EntityLiving", getNMSClass("net.minecraft.world.entity.EntityLiving", "EntityLiving"));
|
||||
classes.put("Packet", getNMSClass("net.minecraft.network.protocol.Packet", "Packet"));
|
||||
classes.put("PlayerConnection", getNMSClass("net.minecraft.server.network.PlayerConnection", "PlayerConnection"));
|
||||
classes.put("NetworkManager", getNMSClass("net.minecraft.network.NetworkManager", "NetworkManager"));
|
||||
fields.put("PING", getField(getClass("EntityPlayer"), "ping", "latency", "e"));
|
||||
fields.put("PLAYER_CONNECTION", getFields(getClass("EntityPlayer"), getClass("PlayerConnection")).get(0));
|
||||
methods.put("getHandle", Class.forName("org.bukkit.craftbukkit." + serverPackage + ".entity.CraftPlayer").getMethod("getHandle"));
|
||||
methods.put("sendPacket", getMethod(getClass("PlayerConnection"), new String[]{"sendPacket", "func_147359_a"}, getClass("Packet")));
|
||||
if (minorVersion >= 7) {
|
||||
fields.put("NETWORK_MANAGER", getFields(getClass("PlayerConnection"), getClass("NetworkManager")).get(0));
|
||||
}
|
||||
if (minorVersion >= 8) {
|
||||
fields.put("CHANNEL", getFields(getClass("NetworkManager"), Channel.class).get(0));
|
||||
methods.put("getProfile", getClass("EntityPlayer").getMethod("getProfile"));
|
||||
}
|
||||
initializeChatComponents();
|
||||
initializeChatPacket();
|
||||
initializeDataWatcher();
|
||||
initializeEntitySpawnPacket();
|
||||
initializeEntityTeleportPacket();
|
||||
initializeHeaderFooterPacket();
|
||||
initializeOtherEntityPackets();
|
||||
initializePlayerInfoPacket();
|
||||
initializeScoreboardPackets();
|
||||
initializeEnums();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets new instance
|
||||
* @param instance - new instance
|
||||
*/
|
||||
public static void setInstance(NMSStorage instance) {
|
||||
NMSStorage.instance = instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns instance
|
||||
* @return instance
|
||||
*/
|
||||
public static NMSStorage getInstance() {
|
||||
return instance;
|
||||
}
|
||||
|
||||
private void initializeEnums() throws IllegalAccessException, InvocationTargetException, NoSuchMethodException, SecurityException {
|
||||
for (String name : Arrays.asList("ChatMessageType", "EnumPlayerInfoAction", "EnumGamemode", "EnumScoreboardHealthDisplay", "EnumScoreboardAction",
|
||||
"PacketPlayOutScoreboardTeam_a", "EnumChatFormat", "EnumNameTagVisibility", "EnumTeamPush")) {
|
||||
if (classes.containsKey(name)) enums.put(name, (Enum[]) getClass(name).getMethod("values").invoke(null));
|
||||
}
|
||||
}
|
||||
|
||||
private void initializeChatComponents() throws ClassNotFoundException, NoSuchMethodException, SecurityException {
|
||||
if (minorVersion >= 7) {
|
||||
classes.put("ChatBaseComponent", getNMSClass("net.minecraft.network.chat.ChatBaseComponent", "ChatBaseComponent"));
|
||||
classes.put("ChatClickable", getNMSClass("net.minecraft.network.chat.ChatClickable", "ChatClickable"));
|
||||
classes.put("ChatComponentText", getNMSClass("net.minecraft.network.chat.ChatComponentText", "ChatComponentText"));
|
||||
classes.put("ChatHoverable", getNMSClass("net.minecraft.network.chat.ChatHoverable", "ChatHoverable"));
|
||||
classes.put("ChatModifier", getNMSClass("net.minecraft.network.chat.ChatModifier", "ChatModifier"));
|
||||
classes.put("ChatSerializer", getNMSClass("net.minecraft.network.chat.IChatBaseComponent$ChatSerializer", "IChatBaseComponent$ChatSerializer", "ChatSerializer"));
|
||||
classes.put("EnumClickAction", getNMSClass("net.minecraft.network.chat.ChatClickable$EnumClickAction", "ChatClickable$EnumClickAction", "EnumClickAction"));
|
||||
classes.put("EnumHoverAction", getNMSClass("net.minecraft.network.chat.ChatHoverable$EnumHoverAction", "ChatHoverable$EnumHoverAction", "EnumHoverAction"));
|
||||
classes.put("IChatBaseComponent", getNMSClass("net.minecraft.network.chat.IChatBaseComponent", "IChatBaseComponent"));
|
||||
constructors.put("ChatComponentText", getClass("ChatComponentText").getConstructor(String.class));
|
||||
constructors.put("ChatClickable", getClass("ChatClickable").getConstructor(getClass("EnumClickAction"), String.class));
|
||||
constructors.put("ChatHoverable", getClass("ChatHoverable").getConstructors()[0]);
|
||||
fields.put("ChatBaseComponent_extra", getFields(getClass("ChatBaseComponent"), List.class).get(0));
|
||||
fields.put("ChatBaseComponent_modifier", getFields(getClass("ChatBaseComponent"), getClass("ChatModifier")).get(0));
|
||||
fields.put("ChatComponentText_text", getFields(getClass("ChatComponentText"), String.class).get(0));
|
||||
fields.put("ChatClickable_action", getFields(getClass("ChatClickable"), getClass("EnumClickAction")).get(0));
|
||||
fields.put("ChatClickable_value", getFields(getClass("ChatClickable"), String.class).get(0));
|
||||
fields.put("ChatHoverable_action", getFields(getClass("ChatHoverable"), getClass("EnumHoverAction")).get(0));
|
||||
List<Field> booleans = getFields(getClass("ChatModifier"), Boolean.class);
|
||||
fields.put("ChatModifier_bold", booleans.get(0));
|
||||
fields.put("ChatModifier_italic", booleans.get(1));
|
||||
fields.put("ChatModifier_underlined", booleans.get(2));
|
||||
fields.put("ChatModifier_strikethrough", booleans.get(3));
|
||||
fields.put("ChatModifier_obfuscated", booleans.get(4));
|
||||
fields.put("ChatModifier_clickEvent", getFields(getClass("ChatModifier"), getClass("ChatClickable")).get(0));
|
||||
fields.put("ChatModifier_hoverEvent", getFields(getClass("ChatModifier"), getClass("ChatHoverable")).get(0));
|
||||
methods.put("ChatComponentText_addSibling", getMethod(getClass("ChatComponentText"), new String[]{"addSibling", "a", "func_150257_a"}, getClass("IChatBaseComponent"))); //v1.7.R4+, v1.7.R3-
|
||||
methods.put("ChatSerializer_DESERIALIZE", getMethod(getClass("ChatSerializer"), new String[]{"a", "func_150699_a"}, String.class));
|
||||
methods.put("EnumClickAction_a", getMethod(getClass("EnumClickAction"), new String[]{"a", "func_150672_a"}, String.class));
|
||||
methods.put("EnumHoverAction_a", getMethod(getClass("EnumHoverAction"), new String[]{"a", "func_150684_a"}, String.class));
|
||||
}
|
||||
if (minorVersion >= 16) {
|
||||
classes.put("ChatHexColor", getNMSClass("net.minecraft.network.chat.ChatHexColor", "ChatHexColor"));
|
||||
constructors.put("ChatModifier", getConstructor(getClass("ChatModifier"), 10));
|
||||
List<Field> list = getFields(getClass("ChatHexColor"), String.class);
|
||||
fields.put("ChatHexColor_name", list.get(list.size()-1));
|
||||
fields.put("ChatHexColor_rgb", getFields(getClass("ChatHexColor"), int.class).get(0));
|
||||
fields.put("ChatHoverable_value", getFields(getClass("ChatHoverable"), Object.class).get(0));
|
||||
fields.put("ChatModifier_color", getFields(getClass("ChatModifier"), getClass("ChatHexColor")).get(0));
|
||||
methods.put("ChatHexColor_ofInt", getClass("ChatHexColor").getMethod("a", int.class));
|
||||
methods.put("ChatHexColor_ofString", getClass("ChatHexColor").getMethod("a", String.class));
|
||||
} else if (minorVersion >= 7) {
|
||||
constructors.put("ChatModifier", getClass("ChatModifier").getConstructor());
|
||||
fields.put("ChatHoverable_value", getFields(getClass("ChatHoverable"), getClass("IChatBaseComponent")).get(0));
|
||||
fields.put("ChatModifier_color", getFields(getClass("ChatModifier"), getClass("EnumChatFormat")).get(0));
|
||||
}
|
||||
}
|
||||
|
||||
private void initializeChatPacket() throws ClassNotFoundException, NoSuchMethodException, SecurityException {
|
||||
classes.put("PacketPlayOutChat", getNMSClass("net.minecraft.network.protocol.game.PacketPlayOutChat", "PacketPlayOutChat", "Packet3Chat"));
|
||||
if (minorVersion >= 12) {
|
||||
classes.put("ChatMessageType", getNMSClass("net.minecraft.network.chat.ChatMessageType", "ChatMessageType"));
|
||||
}
|
||||
if (minorVersion >= 16) {
|
||||
constructors.put("PacketPlayOutChat", getClass("PacketPlayOutChat").getConstructor(getClass("IChatBaseComponent"), getClass("ChatMessageType"), UUID.class));
|
||||
} else if (minorVersion >= 12) {
|
||||
constructors.put("PacketPlayOutChat", getClass("PacketPlayOutChat").getConstructor(getClass("IChatBaseComponent"), getClass("ChatMessageType")));
|
||||
} else if (minorVersion >= 8) {
|
||||
constructors.put("PacketPlayOutChat", getClass("PacketPlayOutChat").getConstructor(getClass("IChatBaseComponent"), byte.class));
|
||||
} else if (minorVersion >= 7){
|
||||
constructors.put("PacketPlayOutChat", getClass("PacketPlayOutChat").getConstructor(getClass("IChatBaseComponent")));
|
||||
}
|
||||
}
|
||||
|
||||
private void initializeDataWatcher() throws ClassNotFoundException, NoSuchMethodException, SecurityException {
|
||||
classes.put("DataWatcher", getNMSClass("net.minecraft.network.syncher.DataWatcher", "DataWatcher"));
|
||||
classes.put("DataWatcherItem", getNMSClass("net.minecraft.network.syncher.DataWatcher$Item", "DataWatcher$Item", "DataWatcher$WatchableObject", "WatchableObject"));
|
||||
if (minorVersion >= 7) {
|
||||
constructors.put("DataWatcher", getClass("DataWatcher").getConstructor(getClass("Entity")));
|
||||
} else {
|
||||
constructors.put("DataWatcher", getClass("DataWatcher").getConstructor());
|
||||
}
|
||||
if (minorVersion >= 9) {
|
||||
classes.put("DataWatcherObject", getNMSClass("net.minecraft.network.syncher.DataWatcherObject", "DataWatcherObject"));
|
||||
classes.put("DataWatcherRegistry", getNMSClass("net.minecraft.network.syncher.DataWatcherRegistry", "DataWatcherRegistry"));
|
||||
classes.put("DataWatcherSerializer", getNMSClass("net.minecraft.network.syncher.DataWatcherSerializer", "DataWatcherSerializer"));
|
||||
constructors.put("DataWatcherObject", getClass("DataWatcherObject").getConstructor(int.class, getClass("DataWatcherSerializer")));
|
||||
fields.put("DataWatcherItem_TYPE", getFields(getClass("DataWatcherItem"), getClass("DataWatcherObject")).get(0));
|
||||
fields.put("DataWatcherItem_VALUE", getFields(getClass("DataWatcherItem"), Object.class).get(0));
|
||||
fields.put("DataWatcherObject_SLOT", getFields(getClass("DataWatcherObject"), int.class).get(0));
|
||||
fields.put("DataWatcherObject_SERIALIZER", getFields(getClass("DataWatcherObject"), getClass("DataWatcherSerializer")).get(0));
|
||||
methods.put("DataWatcher_REGISTER", getClass("DataWatcher").getMethod("register", getClass("DataWatcherObject"), Object.class));
|
||||
} else {
|
||||
fields.put("DataWatcherItem_TYPE", getFields(getClass("DataWatcherItem"), int.class).get(1));
|
||||
fields.put("DataWatcherItem_VALUE", getFields(getClass("DataWatcherItem"), Object.class).get(0));
|
||||
methods.put("DataWatcher_REGISTER", getMethod(getClass("DataWatcher"), new String[]{"a", "func_75682_a"}, int.class, Object.class));
|
||||
}
|
||||
dataWatcherRegistry = new DataWatcherRegistry(this, getClass("DataWatcherRegistry"));
|
||||
}
|
||||
|
||||
private void initializeEntitySpawnPacket() throws ClassNotFoundException, NoSuchMethodException, SecurityException {
|
||||
classes.put("PacketPlayOutSpawnEntityLiving", getNMSClass("net.minecraft.network.protocol.game.PacketPlayOutSpawnEntityLiving", "PacketPlayOutSpawnEntityLiving", "Packet24MobSpawn"));
|
||||
constructors.put("PacketPlayOutSpawnEntityLiving", getClass("PacketPlayOutSpawnEntityLiving").getConstructor(getClass("EntityLiving")));
|
||||
fields.put("PacketPlayOutSpawnEntityLiving_ENTITYID", getFields(getClass("PacketPlayOutSpawnEntityLiving"), int.class).get(0));
|
||||
fields.put("PacketPlayOutSpawnEntityLiving_ENTITYTYPE", getFields(getClass("PacketPlayOutSpawnEntityLiving"), int.class).get(1));
|
||||
fields.put("PacketPlayOutSpawnEntityLiving_YAW", getFields(getClass("PacketPlayOutSpawnEntityLiving"), byte.class).get(0));
|
||||
fields.put("PacketPlayOutSpawnEntityLiving_PITCH", getFields(getClass("PacketPlayOutSpawnEntityLiving"), byte.class).get(0));
|
||||
if (minorVersion >= 9) {
|
||||
fields.put("PacketPlayOutSpawnEntityLiving_UUID", getFields(getClass("PacketPlayOutSpawnEntityLiving"), UUID.class).get(0));
|
||||
fields.put("PacketPlayOutSpawnEntityLiving_X", getFields(getClass("PacketPlayOutSpawnEntityLiving"), double.class).get(0));
|
||||
fields.put("PacketPlayOutSpawnEntityLiving_Y", getFields(getClass("PacketPlayOutSpawnEntityLiving"), double.class).get(1));
|
||||
fields.put("PacketPlayOutSpawnEntityLiving_Z", getFields(getClass("PacketPlayOutSpawnEntityLiving"), double.class).get(2));
|
||||
} else {
|
||||
fields.put("PacketPlayOutSpawnEntityLiving_X", getFields(getClass("PacketPlayOutSpawnEntityLiving"), int.class).get(2));
|
||||
fields.put("PacketPlayOutSpawnEntityLiving_Y", getFields(getClass("PacketPlayOutSpawnEntityLiving"), int.class).get(3));
|
||||
fields.put("PacketPlayOutSpawnEntityLiving_Z", getFields(getClass("PacketPlayOutSpawnEntityLiving"), int.class).get(4));
|
||||
}
|
||||
if (minorVersion <= 14) {
|
||||
fields.put("PacketPlayOutSpawnEntityLiving_DATAWATCHER", getFields(getClass("PacketPlayOutSpawnEntityLiving"), getClass("DataWatcher")).get(0));
|
||||
}
|
||||
}
|
||||
|
||||
private void initializeEntityTeleportPacket() throws NoSuchMethodException, SecurityException, ClassNotFoundException {
|
||||
classes.put("PacketPlayOutEntityTeleport", getNMSClass("net.minecraft.network.protocol.game.PacketPlayOutEntityTeleport", "PacketPlayOutEntityTeleport", "Packet34EntityTeleport"));
|
||||
constructors.put("PacketPlayOutEntityTeleport", getClass("PacketPlayOutEntityTeleport").getConstructor(getClass("Entity")));
|
||||
fields.put("PacketPlayOutEntityTeleport_ENTITYID", getFields(getClass("PacketPlayOutEntityTeleport"), int.class).get(0));
|
||||
fields.put("PacketPlayOutEntityTeleport_YAW", getFields(getClass("PacketPlayOutEntityTeleport"), byte.class).get(0));
|
||||
fields.put("PacketPlayOutEntityTeleport_PITCH", getFields(getClass("PacketPlayOutEntityTeleport"), byte.class).get(1));
|
||||
if (minorVersion >= 9) {
|
||||
fields.put("PacketPlayOutEntityTeleport_X", getFields(getClass("PacketPlayOutEntityTeleport"), double.class).get(0));
|
||||
fields.put("PacketPlayOutEntityTeleport_Y", getFields(getClass("PacketPlayOutEntityTeleport"), double.class).get(1));
|
||||
fields.put("PacketPlayOutEntityTeleport_Z", getFields(getClass("PacketPlayOutEntityTeleport"), double.class).get(2));
|
||||
} else {
|
||||
fields.put("PacketPlayOutEntityTeleport_X", getFields(getClass("PacketPlayOutEntityTeleport"), int.class).get(1));
|
||||
fields.put("PacketPlayOutEntityTeleport_Y", getFields(getClass("PacketPlayOutEntityTeleport"), int.class).get(2));
|
||||
fields.put("PacketPlayOutEntityTeleport_Z", getFields(getClass("PacketPlayOutEntityTeleport"), int.class).get(3));
|
||||
}
|
||||
}
|
||||
|
||||
private void initializeHeaderFooterPacket() throws ClassNotFoundException, NoSuchMethodException, SecurityException {
|
||||
if (minorVersion >= 8) {
|
||||
classes.put("PacketPlayOutPlayerListHeaderFooter", getNMSClass("net.minecraft.network.protocol.game.PacketPlayOutPlayerListHeaderFooter", "PacketPlayOutPlayerListHeaderFooter"));
|
||||
fields.put("PacketPlayOutPlayerListHeaderFooter_HEADER", getFields(getClass("PacketPlayOutPlayerListHeaderFooter"), getClass("IChatBaseComponent")).get(0));
|
||||
fields.put("PacketPlayOutPlayerListHeaderFooter_FOOTER", getFields(getClass("PacketPlayOutPlayerListHeaderFooter"), getClass("IChatBaseComponent")).get(1));
|
||||
if (minorVersion >= 17) {
|
||||
constructors.put("PacketPlayOutPlayerListHeaderFooter", getClass("PacketPlayOutPlayerListHeaderFooter").getConstructor(getClass("IChatBaseComponent"), getClass("IChatBaseComponent")));
|
||||
} else {
|
||||
constructors.put("PacketPlayOutPlayerListHeaderFooter", getClass("PacketPlayOutPlayerListHeaderFooter").getConstructor());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void initializeOtherEntityPackets() throws ClassNotFoundException, NoSuchMethodException {
|
||||
classes.put("PacketPlayInUseEntity", getNMSClass("net.minecraft.network.protocol.game.PacketPlayInUseEntity", "PacketPlayInUseEntity", "Packet7UseEntity"));
|
||||
classes.put("PacketPlayOutEntity", getNMSClass("net.minecraft.network.protocol.game.PacketPlayOutEntity", "PacketPlayOutEntity", "Packet30Entity"));
|
||||
classes.put("PacketPlayOutEntityDestroy", getNMSClass("net.minecraft.network.protocol.game.PacketPlayOutEntityDestroy", "PacketPlayOutEntityDestroy", "Packet29DestroyEntity"));
|
||||
classes.put("PacketPlayOutEntityLook", getNMSClass("net.minecraft.network.protocol.game.PacketPlayOutEntity$PacketPlayOutEntityLook", "PacketPlayOutEntity$PacketPlayOutEntityLook", "PacketPlayOutEntityLook", "Packet32EntityLook"));
|
||||
classes.put("PacketPlayOutEntityMetadata", getNMSClass("net.minecraft.network.protocol.game.PacketPlayOutEntityMetadata", "PacketPlayOutEntityMetadata", "Packet40EntityMetadata"));
|
||||
classes.put("PacketPlayOutNamedEntitySpawn", getNMSClass("net.minecraft.network.protocol.game.PacketPlayOutNamedEntitySpawn", "PacketPlayOutNamedEntitySpawn", "Packet20NamedEntitySpawn"));
|
||||
constructors.put("PacketPlayOutEntityMetadata", getClass("PacketPlayOutEntityMetadata").getConstructor(int.class, getClass("DataWatcher"), boolean.class));
|
||||
fields.put("PacketPlayOutEntity_ENTITYID", getFields(getClass("PacketPlayOutEntity"), int.class).get(0));
|
||||
fields.put("PacketPlayOutEntityDestroy_ENTITIES", getClass("PacketPlayOutEntityDestroy").getDeclaredFields()[0]);
|
||||
fields.get("PacketPlayOutEntityDestroy_ENTITIES").setAccessible(true);
|
||||
fields.put("PacketPlayOutEntityMetadata_LIST", getFields(getClass("PacketPlayOutEntityMetadata"), List.class).get(0));
|
||||
fields.put("PacketPlayOutNamedEntitySpawn_ENTITYID", getFields(getClass("PacketPlayOutNamedEntitySpawn"), int.class).get(0));
|
||||
if (minorVersion >= 7) {
|
||||
classes.put("EnumEntityUseAction", getNMSClass("net.minecraft.network.protocol.game.PacketPlayInUseEntity$EnumEntityUseAction", "PacketPlayInUseEntity$EnumEntityUseAction", "EnumEntityUseAction"));
|
||||
fields.put("PacketPlayInUseEntity_ENTITY", getFields(getClass("PacketPlayInUseEntity"), int.class).get(0));
|
||||
fields.put("PacketPlayInUseEntity_ACTION", getFields(getClass("PacketPlayInUseEntity"), getClass("EnumEntityUseAction")).get(0));
|
||||
}
|
||||
if (minorVersion >= 17) {
|
||||
classes.put("PacketPlayInUseEntity$d", Class.forName("net.minecraft.network.protocol.game.PacketPlayInUseEntity$d"));
|
||||
}
|
||||
try {
|
||||
constructors.put("PacketPlayOutEntityDestroy", getClass("PacketPlayOutEntityDestroy").getConstructor(int[].class));
|
||||
} catch (NoSuchMethodException e) {
|
||||
//1.17.0
|
||||
constructors.put("PacketPlayOutEntityDestroy", getClass("PacketPlayOutEntityDestroy").getConstructor(int.class));
|
||||
}
|
||||
}
|
||||
|
||||
private void initializePlayerInfoPacket() throws ClassNotFoundException, NoSuchMethodException, SecurityException {
|
||||
if (minorVersion >= 8) {
|
||||
classes.put("PacketPlayOutPlayerInfo", getNMSClass("net.minecraft.network.protocol.game.PacketPlayOutPlayerInfo", "PacketPlayOutPlayerInfo"));
|
||||
classes.put("EnumPlayerInfoAction", getNMSClass("net.minecraft.network.protocol.game.PacketPlayOutPlayerInfo$EnumPlayerInfoAction", "PacketPlayOutPlayerInfo$EnumPlayerInfoAction", "EnumPlayerInfoAction"));
|
||||
classes.put("PlayerInfoData", getNMSClass("net.minecraft.network.protocol.game.PacketPlayOutPlayerInfo$PlayerInfoData", "PacketPlayOutPlayerInfo$PlayerInfoData", "PlayerInfoData"));
|
||||
classes.put("EnumGamemode", getNMSClass("net.minecraft.world.level.EnumGamemode", "EnumGamemode", "WorldSettings$EnumGamemode"));
|
||||
constructors.put("PacketPlayOutPlayerInfo", getClass("PacketPlayOutPlayerInfo").getConstructor(getClass("EnumPlayerInfoAction"), Array.newInstance(getClass("EntityPlayer"), 0).getClass()));
|
||||
constructors.put("PlayerInfoData", getClass("PlayerInfoData").getConstructors()[0]);
|
||||
fields.put("PacketPlayOutPlayerInfo_ACTION", getFields(getClass("PacketPlayOutPlayerInfo"), getClass("EnumPlayerInfoAction")).get(0));
|
||||
fields.put("PacketPlayOutPlayerInfo_PLAYERS", getFields(getClass("PacketPlayOutPlayerInfo"), List.class).get(0));
|
||||
methods.put("PlayerInfoData_getProfile", getClass("PlayerInfoData").getMethod("a"));
|
||||
methods.put("PlayerInfoData_getLatency", getClass("PlayerInfoData").getMethod("b"));
|
||||
methods.put("PlayerInfoData_getGamemode", getClass("PlayerInfoData").getMethod("c"));
|
||||
methods.put("PlayerInfoData_getDisplayName", getClass("PlayerInfoData").getMethod("d"));
|
||||
}
|
||||
}
|
||||
|
||||
private void initializeScoreboardPackets() throws ClassNotFoundException, NoSuchMethodException, SecurityException {
|
||||
classes.put("PacketPlayOutScoreboardDisplayObjective", getNMSClass("net.minecraft.network.protocol.game.PacketPlayOutScoreboardDisplayObjective", "PacketPlayOutScoreboardDisplayObjective", "Packet208SetScoreboardDisplayObjective"));
|
||||
classes.put("PacketPlayOutScoreboardObjective", getNMSClass("net.minecraft.network.protocol.game.PacketPlayOutScoreboardObjective", "PacketPlayOutScoreboardObjective", "Packet206SetScoreboardObjective"));
|
||||
classes.put("PacketPlayOutScoreboardScore", getNMSClass("net.minecraft.network.protocol.game.PacketPlayOutScoreboardScore", "PacketPlayOutScoreboardScore", "Packet207SetScoreboardScore"));
|
||||
classes.put("PacketPlayOutScoreboardTeam", getNMSClass("net.minecraft.network.protocol.game.PacketPlayOutScoreboardTeam", "PacketPlayOutScoreboardTeam", "Packet209SetScoreboardTeam"));
|
||||
classes.put("Scoreboard", getNMSClass("net.minecraft.world.scores.Scoreboard", "Scoreboard"));
|
||||
classes.put("ScoreboardObjective", getNMSClass("net.minecraft.world.scores.ScoreboardObjective", "ScoreboardObjective"));
|
||||
classes.put("ScoreboardTeam", getNMSClass("net.minecraft.world.scores.ScoreboardTeam", "ScoreboardTeam"));
|
||||
classes.put("ScoreboardScore", getNMSClass("net.minecraft.world.scores.ScoreboardScore", "ScoreboardScore"));
|
||||
classes.put("IScoreboardCriteria", getNMSClass("net.minecraft.world.scores.criteria.IScoreboardCriteria", "IScoreboardCriteria"));
|
||||
constructors.put("ScoreboardObjective", getClass("ScoreboardObjective").getConstructors()[0]);
|
||||
constructors.put("Scoreboard", getClass("Scoreboard").getConstructor());
|
||||
constructors.put("ScoreboardTeam", getClass("ScoreboardTeam").getConstructor(getClass("Scoreboard"), String.class));
|
||||
constructors.put("ScoreboardScore", getClass("ScoreboardScore").getConstructor(getClass("Scoreboard"), getClass("ScoreboardObjective"), String.class));
|
||||
constructors.put("PacketPlayOutScoreboardDisplayObjective", getClass("PacketPlayOutScoreboardDisplayObjective").getConstructor(int.class, getClass("ScoreboardObjective")));
|
||||
fields.put("PacketPlayOutScoreboardDisplayObjective_POSITION", getFields(getClass("PacketPlayOutScoreboardDisplayObjective"), int.class).get(0));
|
||||
fields.put("PacketPlayOutScoreboardDisplayObjective_OBJECTIVENAME", getFields(getClass("PacketPlayOutScoreboardDisplayObjective"), String.class).get(0));
|
||||
fields.put("PacketPlayOutScoreboardObjective_OBJECTIVENAME", getFields(getClass("PacketPlayOutScoreboardObjective"), String.class).get(0));
|
||||
List<Field> list = getFields(getClass("PacketPlayOutScoreboardObjective"), int.class);
|
||||
fields.put("PacketPlayOutScoreboardObjective_METHOD", list.get(list.size()-1));
|
||||
fields.put("PacketPlayOutScoreboardTeam_NAME", getFields(getClass("PacketPlayOutScoreboardTeam"), String.class).get(0));
|
||||
fields.put("PacketPlayOutScoreboardTeam_PLAYERS", getFields(getClass("PacketPlayOutScoreboardTeam"), Collection.class).get(0));
|
||||
methods.put("ScoreboardTeam_getPlayerNameSet", getMethod(getClass("ScoreboardTeam"), new String[]{"getPlayerNameSet", "func_96670_d"}));
|
||||
methods.put("ScoreboardScore_setScore", getMethod(getClass("ScoreboardScore"), new String[]{"setScore", "func_96647_c"}, int.class));
|
||||
if (minorVersion >= 8) {
|
||||
classes.put("EnumScoreboardHealthDisplay", getNMSClass("net.minecraft.world.scores.criteria.IScoreboardCriteria$EnumScoreboardHealthDisplay", "IScoreboardCriteria$EnumScoreboardHealthDisplay", "EnumScoreboardHealthDisplay"));
|
||||
classes.put("EnumScoreboardAction", getNMSClass("net.minecraft.server.ScoreboardServer$Action", "ScoreboardServer$Action", "PacketPlayOutScoreboardScore$EnumScoreboardAction", "EnumScoreboardAction"));
|
||||
classes.put("EnumNameTagVisibility", getNMSClass("net.minecraft.world.scores.ScoreboardTeamBase$EnumNameTagVisibility", "ScoreboardTeamBase$EnumNameTagVisibility", "EnumNameTagVisibility"));
|
||||
fields.put("PacketPlayOutScoreboardObjective_RENDERTYPE", getFields(getClass("PacketPlayOutScoreboardObjective"), getClass("EnumScoreboardHealthDisplay")).get(0));
|
||||
methods.put("ScoreboardTeam_setNameTagVisibility", getMethod(getClass("ScoreboardTeam"), new String[]{"setNameTagVisibility", "a"}, getClass("EnumNameTagVisibility")));
|
||||
}
|
||||
if (minorVersion >= 9) {
|
||||
classes.put("EnumTeamPush", getNMSClass("net.minecraft.world.scores.ScoreboardTeamBase$EnumTeamPush", "ScoreboardTeamBase$EnumTeamPush"));
|
||||
methods.put("ScoreboardTeam_setCollisionRule", getClass("ScoreboardTeam").getMethod("setCollisionRule", getClass("EnumTeamPush")));
|
||||
}
|
||||
if (minorVersion >= 13) {
|
||||
constructors.put("PacketPlayOutScoreboardObjective", getClass("PacketPlayOutScoreboardObjective").getConstructor(getClass("ScoreboardObjective"), int.class));
|
||||
constructors.put("PacketPlayOutScoreboardScore_1_13", getClass("PacketPlayOutScoreboardScore").getConstructor(getClass("EnumScoreboardAction"), String.class, String.class, int.class));
|
||||
fields.put("PacketPlayOutScoreboardObjective_DISPLAYNAME", getFields(getClass("PacketPlayOutScoreboardObjective"), getClass("IChatBaseComponent")).get(0));
|
||||
methods.put("ScoreboardTeam_setPrefix", getClass("ScoreboardTeam").getMethod("setPrefix", getClass("IChatBaseComponent")));
|
||||
methods.put("ScoreboardTeam_setSuffix", getClass("ScoreboardTeam").getMethod("setSuffix", getClass("IChatBaseComponent")));
|
||||
methods.put("ScoreboardTeam_setColor", getClass("ScoreboardTeam").getMethod("setColor", getClass("EnumChatFormat")));
|
||||
} else {
|
||||
constructors.put("PacketPlayOutScoreboardObjective", getClass("PacketPlayOutScoreboardObjective").getConstructor());
|
||||
constructors.put("PacketPlayOutScoreboardScore_String", getClass("PacketPlayOutScoreboardScore").getConstructor(String.class));
|
||||
fields.put("PacketPlayOutScoreboardObjective_DISPLAYNAME", getFields(getClass("PacketPlayOutScoreboardObjective"), String.class).get(1));
|
||||
methods.put("ScoreboardTeam_setPrefix", getMethod(getClass("ScoreboardTeam"), new String[]{"setPrefix", "func_96666_b"}, String.class));
|
||||
methods.put("ScoreboardTeam_setSuffix", getMethod(getClass("ScoreboardTeam"), new String[]{"setSuffix", "func_96662_c"}, String.class));
|
||||
if (minorVersion >= 8) {
|
||||
constructors.put("PacketPlayOutScoreboardScore", getClass("PacketPlayOutScoreboardScore").getConstructor(getClass("ScoreboardScore")));
|
||||
} else {
|
||||
constructors.put("PacketPlayOutScoreboardScore", getClass("PacketPlayOutScoreboardScore").getConstructor(getClass("ScoreboardScore"), int.class));
|
||||
}
|
||||
}
|
||||
if (minorVersion >= 17) {
|
||||
classes.put("PacketPlayOutScoreboardTeam_a", Class.forName("net.minecraft.network.protocol.game.PacketPlayOutScoreboardTeam$a"));
|
||||
methods.put("PacketPlayOutScoreboardTeam_of", getClass("PacketPlayOutScoreboardTeam").getMethod("a", getClass("ScoreboardTeam")));
|
||||
methods.put("PacketPlayOutScoreboardTeam_ofBoolean", getClass("PacketPlayOutScoreboardTeam").getMethod("a", getClass("ScoreboardTeam"), boolean.class));
|
||||
methods.put("PacketPlayOutScoreboardTeam_ofString", getClass("PacketPlayOutScoreboardTeam").getMethod("a", getClass("ScoreboardTeam"), String.class, getClass("PacketPlayOutScoreboardTeam_a")));
|
||||
} else {
|
||||
constructors.put("PacketPlayOutScoreboardTeam", getClass("PacketPlayOutScoreboardTeam").getConstructor(getClass("ScoreboardTeam"), int.class));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* A helper method that prints all methods of class into console, including their return type, name and parameters
|
||||
* Useful for modded servers which code I can not access
|
||||
* @param clazz - class to show methods of
|
||||
*/
|
||||
@SuppressWarnings("unused")
|
||||
private void showMethods(Class<?> clazz) {
|
||||
TAB.getInstance().getPlatform().sendConsoleMessage("--- " + clazz.getSimpleName() + " ---", false);
|
||||
for (Method m : clazz.getMethods()) {
|
||||
TAB.getInstance().getPlatform().sendConsoleMessage(m.getReturnType().getName() + " " + m.getName() + "(" + Arrays.toString(m.getParameterTypes()) + ")", false);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns class with given potential names in same order
|
||||
* @param names - possible class names
|
||||
* @return class for specified name(s)
|
||||
* @throws ClassNotFoundException if class does not exist
|
||||
*/
|
||||
private Class<?> getNMSClass(String... names) throws ClassNotFoundException {
|
||||
for (String name : names) {
|
||||
try {
|
||||
return getNMSClass(name);
|
||||
} catch (ClassNotFoundException e) {
|
||||
//not the first class name in array
|
||||
}
|
||||
}
|
||||
throw new ClassNotFoundException("No class found with possible names " + Arrays.toString(names));
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns class from given name
|
||||
* @param name - class name
|
||||
* @return class from given name
|
||||
* @throws ClassNotFoundException if class was not found
|
||||
*/
|
||||
private Class<?> getNMSClass(String name) throws ClassNotFoundException {
|
||||
if (minorVersion >= 17) {
|
||||
return Class.forName(name);
|
||||
} else {
|
||||
try {
|
||||
return Class.forName("net.minecraft.server." + serverPackage + "." + name);
|
||||
} catch (ClassNotFoundException e) {
|
||||
//modded server?
|
||||
return Main.class.getClassLoader().loadClass("net.minecraft.server." + serverPackage + "." + name);
|
||||
} catch (NullPointerException e) {
|
||||
//nested class in modded server
|
||||
throw new ClassNotFoundException(name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns method with specified possible names and parameters. Throws exception if no such method was found
|
||||
* @param clazz - class to get method from
|
||||
* @param names - possible method names
|
||||
* @param parameterTypes - parameter types of the method
|
||||
* @return method with specified name and parameters
|
||||
* @throws NoSuchMethodException if no such method exists
|
||||
*/
|
||||
private Method getMethod(Class<?> clazz, String[] names, Class<?>... parameterTypes) throws NoSuchMethodException {
|
||||
for (String name : names) {
|
||||
try {
|
||||
return clazz.getMethod(name, parameterTypes);
|
||||
} catch (Exception e) {
|
||||
//not the first method in array
|
||||
}
|
||||
}
|
||||
throw new NoSuchMethodException("No method found with possible names " + Arrays.toString(names) + " in class " + clazz.getName());
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns all fields of class with defined class type
|
||||
* @param clazz - class to check fields of
|
||||
* @param type - field type to check for
|
||||
* @return list of all fields with specified class type
|
||||
*/
|
||||
public List<Field> getFields(Class<?> clazz, Class<?> type){
|
||||
if (clazz == null) throw new IllegalArgumentException("Source class cannot be null");
|
||||
List<Field> list = new ArrayList<>();
|
||||
for (Field field : clazz.getDeclaredFields()) {
|
||||
if (field.getType() == type) {
|
||||
field.setAccessible(true);
|
||||
list.add(field);
|
||||
}
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns field with specified name and makes it accessible
|
||||
* @param clazz - class to get field from
|
||||
* @param name - field name
|
||||
* @return accessible field with defined name
|
||||
* @throws NoSuchFieldException if field was not found
|
||||
*/
|
||||
private Field getField(Class<?> clazz, String name) throws NoSuchFieldException {
|
||||
for (Field f : clazz.getDeclaredFields()) {
|
||||
if (f.getName().equals(name) || (f.getName().split("_").length == 3 && f.getName().split("_")[2].equals(name))) {
|
||||
f.setAccessible(true);
|
||||
return f;
|
||||
}
|
||||
}
|
||||
if (name.equals("ping")){
|
||||
return getField(clazz, "field_71138_i"); //thermos
|
||||
}
|
||||
throw new NoSuchFieldException("Field \"" + name + "\" was not found in class " + clazz.getName());
|
||||
}
|
||||
|
||||
private Constructor<?> getConstructor(Class<?> clazz, int parameterCount) throws NoSuchMethodException {
|
||||
for (Constructor<?> c : clazz.getDeclaredConstructors()) {
|
||||
if (c.getParameterCount() == parameterCount) {
|
||||
c.setAccessible(true);
|
||||
return c;
|
||||
}
|
||||
}
|
||||
throw new NoSuchMethodException("No constructor found in class " + clazz.getName() + " with " + parameterCount + " parameters");
|
||||
}
|
||||
|
||||
private Field getField(Class<?> clazz, String... potentialNames) throws NoSuchFieldException {
|
||||
for (String name : potentialNames) {
|
||||
try {
|
||||
return getField(clazz, name);
|
||||
} catch (NoSuchFieldException e) {
|
||||
//not the first field name from array
|
||||
}
|
||||
}
|
||||
throw new NoSuchFieldException("No field found in class " + clazz.getName() + " with potential names " + Arrays.toString(potentialNames));
|
||||
}
|
||||
|
||||
public int getMinorVersion() {
|
||||
return minorVersion;
|
||||
}
|
||||
|
||||
public Class<?> getClass(String name){
|
||||
return classes.get(name);
|
||||
}
|
||||
|
||||
public Constructor getConstructor(String name){
|
||||
return constructors.get(name);
|
||||
}
|
||||
|
||||
public Field getField(String name){
|
||||
return fields.get(name);
|
||||
}
|
||||
|
||||
public Method getMethod(String name) {
|
||||
return methods.get(name);
|
||||
}
|
||||
|
||||
public Enum[] getEnum(String name) {
|
||||
return enums.get(name);
|
||||
}
|
||||
|
||||
public void setField(Object obj, String field, Object value) throws IllegalAccessException {
|
||||
fields.get(field).set(obj, value);
|
||||
}
|
||||
|
||||
public DataWatcherRegistry getDataWatcherRegistry() {
|
||||
return dataWatcherRegistry;
|
||||
}
|
||||
}
|
||||
+23
-13
@@ -1,11 +1,11 @@
|
||||
package me.neznamy.tab.platforms.bukkit.nms.datawatcher;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import me.neznamy.tab.platforms.bukkit.nms.NMSStorage;
|
||||
import me.neznamy.tab.shared.ProtocolVersion;
|
||||
|
||||
/**
|
||||
* A class representing the n.m.s.DataWatcher class to make work with it much easier
|
||||
@@ -13,7 +13,7 @@ import me.neznamy.tab.shared.ProtocolVersion;
|
||||
public class DataWatcher {
|
||||
|
||||
//datawatcher data
|
||||
private Map<Integer, DataWatcherItem> dataValues = new HashMap<Integer, DataWatcherItem>();
|
||||
private Map<Integer, DataWatcherItem> dataValues = new HashMap<>();
|
||||
|
||||
//a helper for easier data write
|
||||
private DataWatcherHelper helper = new DataWatcherHelper(this);
|
||||
@@ -24,7 +24,7 @@ public class DataWatcher {
|
||||
* @param value - value
|
||||
*/
|
||||
public void setValue(DataWatcherObject type, Object value){
|
||||
dataValues.put(type.position, new DataWatcherItem(type, value));
|
||||
dataValues.put(type.getPosition(), new DataWatcherItem(type, value));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -55,19 +55,26 @@ public class DataWatcher {
|
||||
/**
|
||||
* Converts the class into an instance of NMS.DataWatcher
|
||||
* @return an instance of NMS.DataWatcher with same data
|
||||
* @throws Exception - if something fails
|
||||
* @throws InvocationTargetException
|
||||
* @throws IllegalAccessException
|
||||
* @throws InstantiationException
|
||||
*/
|
||||
public Object toNMS() throws Exception {
|
||||
public Object toNMS() throws InstantiationException, IllegalAccessException, InvocationTargetException {
|
||||
NMSStorage nms = NMSStorage.getInstance();
|
||||
Object nmsWatcher = nms.newDataWatcher.newInstance(new Object[] {null});
|
||||
Object nmsWatcher;
|
||||
if (nms.getMinorVersion() >= 7) {
|
||||
nmsWatcher = nms.getConstructor("DataWatcher").newInstance(new Object[] {null});
|
||||
} else {
|
||||
nmsWatcher = nms.getConstructor("DataWatcher").newInstance();
|
||||
}
|
||||
for (DataWatcherItem item : dataValues.values()) {
|
||||
Object position;
|
||||
if (ProtocolVersion.SERVER_VERSION.getMinorVersion() >= 9) {
|
||||
position = nms.newDataWatcherObject.newInstance(item.type.position, item.type.classType);
|
||||
if (nms.getMinorVersion() >= 9) {
|
||||
position = nms.getConstructor("DataWatcherObject").newInstance(item.getType().getPosition(), item.getType().getClassType());
|
||||
} else {
|
||||
position = item.type.position;
|
||||
position = item.getType().getPosition();
|
||||
}
|
||||
nms.DataWatcher_REGISTER.invoke(nmsWatcher, position, item.value);
|
||||
nms.getMethod("DataWatcher_REGISTER").invoke(nmsWatcher, position, item.getValue());
|
||||
}
|
||||
return nmsWatcher;
|
||||
}
|
||||
@@ -76,16 +83,19 @@ public class DataWatcher {
|
||||
* Reads NMS data watcher and returns and instance of this class with same data
|
||||
* @param nmsWatcher - NMS datawatcher to read
|
||||
* @return an instance of this class with same values
|
||||
* @throws Exception - if something fails
|
||||
* @throws SecurityException
|
||||
* @throws NoSuchMethodException
|
||||
* @throws InvocationTargetException
|
||||
* @throws IllegalAccessException
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public static DataWatcher fromNMS(Object nmsWatcher) throws Exception{
|
||||
public static DataWatcher fromNMS(Object nmsWatcher) throws IllegalAccessException, InvocationTargetException, NoSuchMethodException, SecurityException{
|
||||
DataWatcher watcher = new DataWatcher();
|
||||
List<Object> items = (List<Object>) nmsWatcher.getClass().getMethod("c").invoke(nmsWatcher);
|
||||
if (items != null) {
|
||||
for (Object watchableObject : items) {
|
||||
DataWatcherItem w = DataWatcherItem.fromNMS(watchableObject);
|
||||
watcher.setValue(w.type, w.value);
|
||||
watcher.setValue(w.getType(), w.getValue());
|
||||
}
|
||||
}
|
||||
return watcher;
|
||||
+28
-16
@@ -14,7 +14,7 @@ import me.neznamy.tab.shared.packets.IChatBaseComponent;
|
||||
public class DataWatcherHelper {
|
||||
|
||||
//position of armor stand flags
|
||||
private final int ARMOR_STAND_BYTEFLAGS_POSITION = getArmorStandFlagsPosition();
|
||||
private final int armorStandFlagsPosition = getArmorStandFlagsPosition();
|
||||
|
||||
//original datawatcher to write to
|
||||
private DataWatcher data;
|
||||
@@ -28,7 +28,7 @@ public class DataWatcherHelper {
|
||||
*/
|
||||
public DataWatcherHelper(DataWatcher data) {
|
||||
this.data = data;
|
||||
this.registry = NMSStorage.getInstance().dataWatcherRegistry;
|
||||
this.registry = NMSStorage.getInstance().getDataWatcherRegistry();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -36,13 +36,16 @@ public class DataWatcherHelper {
|
||||
* @return armor stand flags position based on server version
|
||||
*/
|
||||
private int getArmorStandFlagsPosition() {
|
||||
if (ProtocolVersion.SERVER_VERSION.getMinorVersion() >= 15) {
|
||||
if (NMSStorage.getInstance().getMinorVersion() >= 17) {
|
||||
//1.17.x
|
||||
return 15;
|
||||
} else if (NMSStorage.getInstance().getMinorVersion() >= 15) {
|
||||
//1.15.x, 1.16.x
|
||||
return 14;
|
||||
} else if (ProtocolVersion.SERVER_VERSION.getMinorVersion() >= 14) {
|
||||
} else if (NMSStorage.getInstance().getMinorVersion() >= 14) {
|
||||
//1.14.x
|
||||
return 13;
|
||||
} else if (ProtocolVersion.SERVER_VERSION.getMinorVersion() >= 10) {
|
||||
} else if (NMSStorage.getInstance().getMinorVersion() >= 10) {
|
||||
//1.10.x - 1.13.x
|
||||
return 11;
|
||||
} else {
|
||||
@@ -56,7 +59,7 @@ public class DataWatcherHelper {
|
||||
* @param flags - flags to write
|
||||
*/
|
||||
public void setEntityFlags(byte flags) {
|
||||
data.setValue(new DataWatcherObject(0, registry.Byte), flags);
|
||||
data.setValue(new DataWatcherObject(0, registry.getByte()), flags);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -65,17 +68,22 @@ public class DataWatcherHelper {
|
||||
* @param clientVersion - client version
|
||||
*/
|
||||
public void setCustomName(String customName, ProtocolVersion clientVersion) {
|
||||
if (ProtocolVersion.SERVER_VERSION.getMinorVersion() >= 13) {
|
||||
if (NMSStorage.getInstance().getMinorVersion() >= 13) {
|
||||
try {
|
||||
data.setValue(new DataWatcherObject(2, registry.Optional_IChatBaseComponent), Optional.ofNullable(((BukkitPacketBuilder)TAB.getInstance().getPacketBuilder()).toNMSComponent(IChatBaseComponent.optimizedComponent(customName), clientVersion)));
|
||||
data.setValue(new DataWatcherObject(2, registry.getOptionalComponent()), Optional.ofNullable(((BukkitPacketBuilder)TAB.getInstance().getPacketBuilder()).toNMSComponent(IChatBaseComponent.optimizedComponent(customName), clientVersion)));
|
||||
} catch (Exception e) {
|
||||
TAB.getInstance().getErrorManager().printError("Failed to create component", e);
|
||||
}
|
||||
} else if (ProtocolVersion.SERVER_VERSION.getMinorVersion() >= 8){
|
||||
data.setValue(new DataWatcherObject(2, registry.String), customName);
|
||||
} else if (NMSStorage.getInstance().getMinorVersion() >= 8){
|
||||
data.setValue(new DataWatcherObject(2, registry.getString()), customName);
|
||||
} else {
|
||||
//name length is limited to 64 characters on <1.8
|
||||
String cutName = (customName.length() > 64 ? customName.substring(0, 64) : customName);
|
||||
data.setValue(new DataWatcherObject(10, registry.String), cutName);
|
||||
if (NMSStorage.getInstance().getMinorVersion() >= 6){
|
||||
data.setValue(new DataWatcherObject(10, registry.getString()), cutName);
|
||||
} else {
|
||||
data.setValue(new DataWatcherObject(5, registry.getString()), cutName);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -85,10 +93,10 @@ public class DataWatcherHelper {
|
||||
* @param visible - if visible or not
|
||||
*/
|
||||
public void setCustomNameVisible(boolean visible) {
|
||||
if (ProtocolVersion.SERVER_VERSION.getMinorVersion() >= 9) {
|
||||
data.setValue(new DataWatcherObject(3, registry.Boolean), visible);
|
||||
if (NMSStorage.getInstance().getMinorVersion() >= 9) {
|
||||
data.setValue(new DataWatcherObject(3, registry.getBoolean()), visible);
|
||||
} else {
|
||||
data.setValue(new DataWatcherObject(3, registry.Byte), (byte)(visible?1:0));
|
||||
data.setValue(new DataWatcherObject(3, registry.getByte()), (byte)(visible?1:0));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -97,7 +105,11 @@ public class DataWatcherHelper {
|
||||
* @param health - health of entity
|
||||
*/
|
||||
public void setHealth(float health) {
|
||||
data.setValue(new DataWatcherObject(6, registry.Float), health);
|
||||
if (NMSStorage.getInstance().getMinorVersion() >= 6) {
|
||||
data.setValue(new DataWatcherObject(6, registry.getFloat()), health);
|
||||
} else {
|
||||
data.setValue(new DataWatcherObject(16, registry.getInteger()), (int)health);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -105,6 +117,6 @@ public class DataWatcherHelper {
|
||||
* @param flags - flags to write
|
||||
*/
|
||||
public void setArmorStandFlags(byte flags) {
|
||||
data.setValue(new DataWatcherObject(ARMOR_STAND_BYTEFLAGS_POSITION, registry.Byte), flags);
|
||||
data.setValue(new DataWatcherObject(armorStandFlagsPosition, registry.getByte()), flags);
|
||||
}
|
||||
}
|
||||
+46
@@ -0,0 +1,46 @@
|
||||
package me.neznamy.tab.platforms.bukkit.nms.datawatcher;
|
||||
|
||||
import me.neznamy.tab.platforms.bukkit.nms.NMSStorage;
|
||||
|
||||
public class DataWatcherItem {
|
||||
|
||||
//type of value (position + data type (1.9+))
|
||||
private DataWatcherObject type;
|
||||
|
||||
//actual data value
|
||||
private Object value;
|
||||
|
||||
/**
|
||||
* Constructs new instance of the object with given parameters
|
||||
* @param type - value type
|
||||
* @param value - value
|
||||
*/
|
||||
public DataWatcherItem(DataWatcherObject type, Object value){
|
||||
this.type = type;
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns and instance of this class from given NMS item
|
||||
* @param nmsItem - NMS item
|
||||
* @return instance of this class with same data
|
||||
* @throws IllegalAccessException
|
||||
*/
|
||||
public static DataWatcherItem fromNMS(Object nmsItem) throws IllegalAccessException {
|
||||
NMSStorage nms = NMSStorage.getInstance();
|
||||
if (NMSStorage.getInstance().getMinorVersion() >= 9) {
|
||||
Object nmsObject = nms.getField("DataWatcherItem_TYPE").get(nmsItem);
|
||||
return new DataWatcherItem(new DataWatcherObject(nms.getField("DataWatcherObject_SLOT").getInt(nmsObject), nms.getField("DataWatcherObject_SERIALIZER").get(nmsObject)), nms.getField("DataWatcherItem_VALUE").get(nmsItem));
|
||||
} else {
|
||||
return new DataWatcherItem(new DataWatcherObject(nms.getField("DataWatcherItem_TYPE").getInt(nmsItem), null), nms.getField("DataWatcherItem_VALUE").get(nmsItem));
|
||||
}
|
||||
}
|
||||
|
||||
public DataWatcherObject getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public Object getValue() {
|
||||
return value;
|
||||
}
|
||||
}
|
||||
+10
-2
@@ -6,10 +6,10 @@ package me.neznamy.tab.platforms.bukkit.nms.datawatcher;
|
||||
public class DataWatcherObject {
|
||||
|
||||
//position in datawatcher
|
||||
public int position;
|
||||
private int position;
|
||||
|
||||
//value class type used since 1.9
|
||||
public Object classType;
|
||||
private Object classType;
|
||||
|
||||
/**
|
||||
* Constructs a new instance of this class with given parameters
|
||||
@@ -20,4 +20,12 @@ public class DataWatcherObject {
|
||||
this.position = position;
|
||||
this.classType = classType;
|
||||
}
|
||||
|
||||
public int getPosition() {
|
||||
return position;
|
||||
}
|
||||
|
||||
public Object getClassType() {
|
||||
return classType;
|
||||
}
|
||||
}
|
||||
+85
@@ -0,0 +1,85 @@
|
||||
package me.neznamy.tab.platforms.bukkit.nms.datawatcher;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Modifier;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import me.neznamy.tab.platforms.bukkit.nms.NMSStorage;
|
||||
|
||||
/**
|
||||
* A class representing the n.m.s.DataWatcherRegistry class to make work with it much easier
|
||||
*/
|
||||
public class DataWatcherRegistry {
|
||||
|
||||
//used registry types
|
||||
private Object registryByte;
|
||||
private Object registryInteger;
|
||||
private Object registryFloat;
|
||||
private Object registryString;
|
||||
private Object registryOptionalComponent;
|
||||
private Object registryBoolean;
|
||||
|
||||
/**
|
||||
* Initializes required NMS classes and fields
|
||||
*/
|
||||
public DataWatcherRegistry(NMSStorage nms, Class<?> registry) {
|
||||
if (nms.getMinorVersion() >= 9) {
|
||||
Map<String, Object> fields = getStaticFields(registry);
|
||||
registryByte = fields.get("a");
|
||||
registryInteger = fields.get("b");
|
||||
registryFloat = fields.get("c");
|
||||
registryString = fields.get("d");
|
||||
if (nms.getMinorVersion() >= 13) {
|
||||
registryOptionalComponent = fields.get("f");
|
||||
registryBoolean = fields.get("i");
|
||||
} else {
|
||||
registryBoolean = fields.get("h");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets values of all static fields in a class
|
||||
* @param clazz class to return field values from
|
||||
* @return map of values
|
||||
*/
|
||||
private Map<String, Object> getStaticFields(Class<?> clazz){
|
||||
Map<String, Object> fields = new HashMap<>();
|
||||
if (clazz == null) return fields;
|
||||
for (Field field : clazz.getDeclaredFields()) {
|
||||
if (Modifier.isStatic(field.getModifiers())) {
|
||||
try {
|
||||
fields.put(field.getName(), field.get(null));
|
||||
} catch (Exception e) {
|
||||
//this will never happen
|
||||
}
|
||||
}
|
||||
}
|
||||
return fields;
|
||||
}
|
||||
|
||||
public Object getBoolean() {
|
||||
return registryBoolean;
|
||||
}
|
||||
|
||||
public Object getByte() {
|
||||
return registryByte;
|
||||
}
|
||||
|
||||
public Object getFloat() {
|
||||
return registryFloat;
|
||||
}
|
||||
|
||||
public Object getInteger() {
|
||||
return registryInteger;
|
||||
}
|
||||
|
||||
public Object getString() {
|
||||
return registryString;
|
||||
}
|
||||
|
||||
public Object getOptionalComponent() {
|
||||
return registryOptionalComponent;
|
||||
}
|
||||
}
|
||||
File renamed without changes.
+250
-249
@@ -1,249 +1,250 @@
|
||||
# Detailed explanation of all options available at https://github.com/NEZNAMY/TAB/wiki/config.yml
|
||||
|
||||
#changing nametags, affecting sorting, collision rule
|
||||
change-nametag-prefix-suffix: true
|
||||
|
||||
#prefix/suffix in tablist
|
||||
change-tablist-prefix-suffix: true
|
||||
|
||||
#header/footer
|
||||
enable-header-footer: true
|
||||
|
||||
header:
|
||||
- "&3&lServer name"
|
||||
- "&7&l>> %animation:Welcome%&3 &l%player%&7&l! &7&l<<"
|
||||
- "&7Online players: &f%online%"
|
||||
- "&6Online staff: &e%staffonline%"
|
||||
- "%animation:ping-tps%"
|
||||
- ""
|
||||
- "&7&l Used memory: %memory-used% MB / %memory-max% MB"
|
||||
- "%animation:MyAnimation1%"
|
||||
footer:
|
||||
- "%animation:MyAnimation1%"
|
||||
- "%animation:time%"
|
||||
- ""
|
||||
- "&7Visit our webpage %animation:web%"
|
||||
|
||||
#supports any numeric placeholder, set to "" to disable the feature
|
||||
yellow-number-in-tablist: "%ping%"
|
||||
|
||||
#literally what it says
|
||||
group-sorting-priority-list:
|
||||
- owner
|
||||
- admin
|
||||
- mod
|
||||
- helper
|
||||
- builder
|
||||
- premium
|
||||
- player
|
||||
- default
|
||||
|
||||
Groups:
|
||||
Owner:
|
||||
tabprefix: "&0&l[&a&lOwner&0&l] &a"
|
||||
tagprefix: "&2&lOwner &a"
|
||||
Admin:
|
||||
tabprefix: "&0&l[&4&lAdmin&0&l] &1"
|
||||
tagprefix: "%animation:admin_prefix%"
|
||||
Player:
|
||||
tabprefix: "&0&l[&7&lPlayer&0&l] &3"
|
||||
tagprefix: "&2&lPlayer &3"
|
||||
example_group:
|
||||
header:
|
||||
- "This is an example of per-group header/footer"
|
||||
footer:
|
||||
- "applied to a group"
|
||||
|
||||
#default settings for all groups, all groups will take properties from this section unless player's primary group overrides a specific setting
|
||||
_OTHER_:
|
||||
tabprefix: "%vault-prefix%"
|
||||
tagprefix: "%vault-prefix%"
|
||||
tabsuffix: "%afk%"
|
||||
tagsuffix: "%afk%"
|
||||
customtabname: "%essentialsnick%"
|
||||
customtagname: "%essentialsnick%"
|
||||
|
||||
Users:
|
||||
_NEZNAMY_:
|
||||
tabprefix: "&6&lTAB Author &a"
|
||||
tagprefix: "&6&lTAB &r&a"
|
||||
abovename: "&bOh look, 3 lines of text !"
|
||||
belowname: "&eThere's only one plugin out there supporting it"
|
||||
|
||||
#additional very limited line of text below nametag
|
||||
#don't forget this enables on all player entities, which includes NPCs
|
||||
#tags so you can find this section using the mighty ctrl + f feature: [NPC, Citizens, below_name, health]
|
||||
classic-vanilla-belowname:
|
||||
|
||||
#enabling the feature
|
||||
enabled: true
|
||||
|
||||
#number or numeric placeholder, supports per-player placeholders
|
||||
number: "%health%"
|
||||
|
||||
#text after number, must be same on all players
|
||||
text: "Health"
|
||||
|
||||
#controlling the collision rule
|
||||
enable-collision: true
|
||||
|
||||
#using the opposite of the setting above for worlds
|
||||
revert-collision-rule-in-worlds:
|
||||
- revertedworld
|
||||
|
||||
#preventing players with spectator gamemode from being moved to the bottom of tablist with transparent name
|
||||
do-not-move-spectators: false
|
||||
|
||||
#allows players with tab.spectatorbypass permission to see spectators moved despite the option above enabled
|
||||
allow-spectator-bypass-permission: false
|
||||
|
||||
#using armor stands for nametags, bypassing all limits
|
||||
#THEY ARE CLIENT SIDED AND DO NOT EXIST ON SERVER SO STOP SAYING YOUR SERVER IS LAGGING FROM THIS
|
||||
unlimited-nametag-prefix-suffix-mode:
|
||||
|
||||
#enabling the feature
|
||||
enabled: false
|
||||
|
||||
#enabling will result in NPCs ignoring nametag prefix/suffix/visibility to prevent NPCs with names of online players from being invisible
|
||||
modify-npc-names: false
|
||||
|
||||
#using a feature introduced in 1.8.1 to make hitbox zero so you can't cry it affects pvp despite hit redirection
|
||||
#1.8.0 clients will see wild things
|
||||
#automatically enabled for 1.9+
|
||||
use-marker-tag-for-1-8-x-clients: false
|
||||
|
||||
#disabling the feature for players riding boats to prevent massive desync
|
||||
disable-on-boats: true
|
||||
|
||||
#in blocks
|
||||
space-between-lines: 0.22
|
||||
tracking-range: 48
|
||||
|
||||
per-world-settings:
|
||||
world1:
|
||||
header:
|
||||
- "an example of world with custom"
|
||||
footer:
|
||||
- "header/footer and prefix/suffix"
|
||||
Groups:
|
||||
Owner:
|
||||
tabprefix: "&0&l[&a&lOwner&0&l] &a"
|
||||
tagprefix: "&2&lOwner &a"
|
||||
|
||||
#separating multiple worlds with "-"
|
||||
world2-world3:
|
||||
header:
|
||||
- "This is a shared header for"
|
||||
- "world2 and world3"
|
||||
|
||||
placeholders:
|
||||
#output of %afk%
|
||||
afk-yes: " &4*&4&lAFK&4*&r"
|
||||
afk-no: ""
|
||||
|
||||
#%date%
|
||||
date-format: "dd.MM.yyyy"
|
||||
|
||||
#%time%
|
||||
time-format: "[HH:mm:ss / h:mm a]"
|
||||
|
||||
#in hours, in case of wrong timezone
|
||||
time-offset: 0
|
||||
|
||||
#don't forget color codes
|
||||
remove-strings:
|
||||
- "[]"
|
||||
- "< >"
|
||||
|
||||
#aliases for %rank%, this is not the place where group prefix is defined!
|
||||
rank-aliases:
|
||||
Admin: "&4&lADMIN"
|
||||
Mod: "&b&lMOD"
|
||||
Premium: "&6&lPREMIUM"
|
||||
Ultra: "&b&lULTRA"
|
||||
Legend: "&a&lLEGEND"
|
||||
Titan: "&c&lTITAN"
|
||||
Youtuber: "&c&lYOUTUBE"
|
||||
_OTHER_: "&7No Rank"
|
||||
|
||||
disable-features-in-worlds:
|
||||
header-footer:
|
||||
- disabledworld
|
||||
tablist-names:
|
||||
- disabledworld
|
||||
nametag:
|
||||
- disabledworld
|
||||
yellow-number:
|
||||
- disabledworld
|
||||
bossbar:
|
||||
- disabledworld
|
||||
belowname:
|
||||
- disabledworld
|
||||
unlimited-nametags:
|
||||
- disabledworld
|
||||
|
||||
placeholderapi-refresh-intervals:
|
||||
default-refresh-interval: 100
|
||||
server:
|
||||
"%server_uptime%": 1000
|
||||
"%server_tps_1_colored%": 1000
|
||||
player:
|
||||
"%player_health%": 200
|
||||
"%player_ping%": 1000
|
||||
"%vault_prefix%": 1000
|
||||
relational:
|
||||
"%rel_factionsuuid_relation_color%": 500
|
||||
|
||||
#different playerlist in different worlds
|
||||
per-world-playerlist:
|
||||
|
||||
#to enable the feature
|
||||
enabled: false
|
||||
|
||||
#allows players with tab.bypass permission to see everyone in tablist despite this option enabled
|
||||
allow-bypass-permission: false
|
||||
|
||||
#players in these worlds will see everyone despite the feature enabled
|
||||
ignore-effect-in-worlds:
|
||||
- ignoredworld
|
||||
- build
|
||||
|
||||
#groups of worlds to share playerlist
|
||||
shared-playerlist-world-groups:
|
||||
#group name, can be anything
|
||||
lobby:
|
||||
- lobby1
|
||||
- lobby2
|
||||
minigames:
|
||||
- paintball
|
||||
- bedwars
|
||||
|
||||
#permission node is tab.sort.<permission group from sorting list>
|
||||
sort-players-by-permissions: false
|
||||
|
||||
#making tamed animals no longer copy nametag properties from their owner (prefix/suffix/visibility)
|
||||
#do not enable this if you're on paper, you'll feed the trolls even more
|
||||
fix-pet-names: false
|
||||
|
||||
#taking primary group from permission plugin
|
||||
use-primary-group: true
|
||||
|
||||
#if the option above is false, all groups are taken from permission plugin and the one higher in this list is used as primary
|
||||
primary-group-finding-list:
|
||||
- Owner
|
||||
- Admin
|
||||
- Helper
|
||||
- default
|
||||
|
||||
#if none of the above fits your needs, you can enable this to give groups using tab.group.<group name from the list above> permission
|
||||
assign-groups-by-permissions: false
|
||||
|
||||
#preventing other plugins from overriding TAB
|
||||
anti-override:
|
||||
scoreboard-teams: true
|
||||
scoreboard-objectives: true
|
||||
tablist-names: true
|
||||
usernames: true
|
||||
|
||||
#permanently invisible nametags
|
||||
invisible-nametags: false
|
||||
# Detailed explanation of all options available at https://github.com/NEZNAMY/TAB/wiki/config.yml
|
||||
|
||||
#changing nametags, affecting sorting, collision rule
|
||||
change-nametag-prefix-suffix: true
|
||||
|
||||
#prefix/suffix in tablist
|
||||
change-tablist-prefix-suffix: true
|
||||
|
||||
#header/footer
|
||||
enable-header-footer: true
|
||||
|
||||
header:
|
||||
- "&3&lServer name"
|
||||
- "&7&l>> %animation:Welcome%&3 &l%player%&7&l! &7&l<<"
|
||||
- "&7Online players: &f%online%"
|
||||
- "&6Online staff: &e%staffonline%"
|
||||
- "%animation:ping-tps%"
|
||||
- ""
|
||||
- "&7&l Used memory: %memory-used% MB / %memory-max% MB"
|
||||
- "%animation:MyAnimation1%"
|
||||
footer:
|
||||
- "%animation:MyAnimation1%"
|
||||
- "%animation:time%"
|
||||
- ""
|
||||
- "&7Visit our webpage %animation:web%"
|
||||
|
||||
#supports any numeric placeholder, set to "" to disable the feature
|
||||
yellow-number-in-tablist: "%ping%"
|
||||
|
||||
group-sorting-priority-list:
|
||||
- owner
|
||||
- admin
|
||||
- mod
|
||||
- helper
|
||||
- builder
|
||||
- premium
|
||||
- player
|
||||
- default
|
||||
|
||||
Groups:
|
||||
Owner:
|
||||
tabprefix: "&0&l[&a&lOwner&0&l] &a"
|
||||
tagprefix: "&2&lOwner &a"
|
||||
Admin:
|
||||
tabprefix: "&0&l[&4&lAdmin&0&l] &1"
|
||||
tagprefix: "%animation:admin_prefix%"
|
||||
Player:
|
||||
tabprefix: "&0&l[&7&lPlayer&0&l] &3"
|
||||
tagprefix: "&2&lPlayer &3"
|
||||
example_group:
|
||||
header:
|
||||
- "This is an example of per-group header/footer"
|
||||
footer:
|
||||
- "applied to a group"
|
||||
|
||||
#default settings for all groups, all groups will take properties from this section unless player's primary group overrides a specific setting
|
||||
_OTHER_:
|
||||
tabprefix: "%vault-prefix%"
|
||||
tagprefix: "%vault-prefix%"
|
||||
tabsuffix: "%afk%"
|
||||
tagsuffix: "%afk%"
|
||||
customtabname: "%essentialsnick%"
|
||||
customtagname: "%essentialsnick%"
|
||||
|
||||
Users:
|
||||
_NEZNAMY_:
|
||||
tabprefix: "&6&lTAB Author &a"
|
||||
tagprefix: "&6&lTAB &r&a"
|
||||
abovename: "&bOh look, 3 lines of text !"
|
||||
belowname: "&eThere's only one plugin out there supporting it"
|
||||
|
||||
#additional very limited line of text below nametag
|
||||
#don't forget this enables on all player entities, which includes NPCs
|
||||
#tags so you can find this section using the mighty ctrl + f feature: [NPC, Citizens, below_name, health]
|
||||
classic-vanilla-belowname:
|
||||
|
||||
#enabling the feature
|
||||
enabled: true
|
||||
|
||||
#number or numeric placeholder, supports per-player placeholders
|
||||
number: "%health%"
|
||||
|
||||
#text after number, must be same on all players
|
||||
text: "Health"
|
||||
|
||||
#controlling the collision rule
|
||||
enable-collision: true
|
||||
|
||||
#using the opposite of the setting above for worlds
|
||||
revert-collision-rule-in-worlds:
|
||||
- revertedworld
|
||||
|
||||
#preventing players with spectator gamemode from being moved to the bottom of tablist with transparent name
|
||||
do-not-move-spectators: false
|
||||
|
||||
#allows players with tab.spectatorbypass permission to see spectators moved despite the option above enabled
|
||||
allow-spectator-bypass-permission: false
|
||||
|
||||
#using armor stands for nametags, bypassing all limits (they are not on server sided & asynchronous - no TPS loss)
|
||||
unlimited-nametag-prefix-suffix-mode:
|
||||
|
||||
#enabling the feature
|
||||
enabled: false
|
||||
|
||||
#using a feature introduced in 1.8.1 to make hitbox zero so you can't cry it affects pvp despite hit redirection
|
||||
#1.8.0 clients will see wild things
|
||||
#automatically enabled for 1.9+
|
||||
use-marker-tag-for-1-8-x-clients: false
|
||||
|
||||
#disabling the feature for players riding boats to prevent massive desync
|
||||
disable-on-boats: true
|
||||
|
||||
#in blocks
|
||||
space-between-lines: 0.22
|
||||
|
||||
per-world-settings:
|
||||
world1:
|
||||
header:
|
||||
- "an example of world with custom"
|
||||
footer:
|
||||
- "header/footer and prefix/suffix"
|
||||
Groups:
|
||||
Owner:
|
||||
tabprefix: "&0&l[&a&lOwner&0&l] &a"
|
||||
tagprefix: "&2&lOwner &a"
|
||||
|
||||
#separating multiple worlds with "-"
|
||||
world2-world3:
|
||||
header:
|
||||
- "This is a shared header for"
|
||||
- "world2 and world3"
|
||||
|
||||
placeholders:
|
||||
#output of %afk%
|
||||
afk-yes: " &4*&4&lAFK&4*&r"
|
||||
afk-no: ""
|
||||
|
||||
#%date%
|
||||
date-format: "dd.MM.yyyy"
|
||||
|
||||
#%time%
|
||||
time-format: "[HH:mm:ss / h:mm a]"
|
||||
|
||||
#in hours, in case of wrong timezone
|
||||
time-offset: 0
|
||||
|
||||
#don't forget color codes
|
||||
remove-strings:
|
||||
- "[]"
|
||||
- "< >"
|
||||
|
||||
#aliases for %rank%, this is not the place where group prefix is defined!
|
||||
rank-aliases:
|
||||
Admin: "&4&lADMIN"
|
||||
Mod: "&b&lMOD"
|
||||
Premium: "&6&lPREMIUM"
|
||||
Ultra: "&b&lULTRA"
|
||||
Legend: "&a&lLEGEND"
|
||||
Titan: "&c&lTITAN"
|
||||
Youtuber: "&c&lYOUTUBE"
|
||||
_OTHER_: "&7No Rank"
|
||||
|
||||
disable-features-in-worlds:
|
||||
header-footer:
|
||||
- disabledworld
|
||||
tablist-names:
|
||||
- disabledworld
|
||||
nametag:
|
||||
- disabledworld
|
||||
yellow-number:
|
||||
- disabledworld
|
||||
bossbar:
|
||||
- disabledworld
|
||||
belowname:
|
||||
- disabledworld
|
||||
unlimited-nametags:
|
||||
- disabledworld
|
||||
|
||||
placeholderapi-refresh-intervals:
|
||||
default-refresh-interval: 500
|
||||
server:
|
||||
"%server_uptime%": 1000
|
||||
"%server_tps_1_colored%": 1000
|
||||
player:
|
||||
"%player_health%": 200
|
||||
"%player_ping%": 1000
|
||||
"%vault_prefix%": 1000
|
||||
relational:
|
||||
"%rel_factionsuuid_relation_color%": 500
|
||||
|
||||
#different playerlist in different worlds
|
||||
per-world-playerlist:
|
||||
|
||||
#to enable the feature
|
||||
enabled: false
|
||||
|
||||
#allows players with tab.bypass permission to see everyone in tablist despite this option enabled
|
||||
allow-bypass-permission: false
|
||||
|
||||
#players in these worlds will see everyone despite the feature enabled
|
||||
ignore-effect-in-worlds:
|
||||
- ignoredworld
|
||||
- build
|
||||
|
||||
#groups of worlds to share playerlist
|
||||
shared-playerlist-world-groups:
|
||||
#group name, can be anything
|
||||
lobby:
|
||||
- lobby1
|
||||
- lobby2
|
||||
minigames:
|
||||
- paintball
|
||||
- bedwars
|
||||
|
||||
#permission node is tab.sort.<permission group from sorting list>
|
||||
sort-players-by-permissions: false
|
||||
|
||||
#making tamed animals no longer copy nametag properties from their owner (prefix/suffix/visibility)
|
||||
fix-pet-names: false
|
||||
|
||||
#taking primary group from permission plugin
|
||||
use-primary-group: true
|
||||
|
||||
#if the option above is false, all groups are taken from permission plugin and the one higher in this list is used as primary
|
||||
primary-group-finding-list:
|
||||
- Owner
|
||||
- Admin
|
||||
- Helper
|
||||
- default
|
||||
|
||||
#if none of the above fits your needs, you can enable this to give groups using tab.group.<group name from the list above> permission
|
||||
assign-groups-by-permissions: false
|
||||
|
||||
#preventing other plugins from overriding TAB
|
||||
anti-override:
|
||||
scoreboard-teams: true
|
||||
scoreboard-objectives: true
|
||||
tablist-names: true
|
||||
usernames: true
|
||||
|
||||
#permanently invisible nametags
|
||||
invisible-nametags: false
|
||||
|
||||
#faking ping of players
|
||||
ping-spoof:
|
||||
enabled: false
|
||||
value: 0
|
||||
|
||||
#unlocks extra console messages
|
||||
debug: false
|
||||
@@ -1,10 +1,10 @@
|
||||
name: ${project.name}
|
||||
version: ${project.version}
|
||||
author: NEZNAMY
|
||||
main: me.neznamy.tab.platforms.bukkit.Main
|
||||
api-version: 1.13
|
||||
softdepend: [PlaceholderAPI, Vault, UltraPermissions, LuckPerms, Essentials, LibsDisguises]
|
||||
website: "https://www.spigotmc.org/resources/57806/"
|
||||
description: ${project.description}
|
||||
commands:
|
||||
name: ${project.parent.name}
|
||||
version: ${project.parent.version}
|
||||
author: NEZNAMY
|
||||
main: me.neznamy.tab.platforms.bukkit.Main
|
||||
api-version: 1.13
|
||||
softdepend: [PlaceholderAPI, Vault, UltraPermissions, LuckPerms, Essentials, LibsDisguises, ProtocolSupport, ViaVersion]
|
||||
website: "https://www.spigotmc.org/resources/57806/"
|
||||
description: ${project.parent.description}
|
||||
commands:
|
||||
tab:
|
||||
@@ -0,0 +1,164 @@
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>me.neznamy</groupId>
|
||||
<artifactId>TAB</artifactId>
|
||||
<version>2.9.2</version>
|
||||
</parent>
|
||||
<artifactId>bungeecord</artifactId>
|
||||
|
||||
<repositories>
|
||||
|
||||
<!-- PremiumVanishAPI -->
|
||||
<repository>
|
||||
<id>jitpack.io</id>
|
||||
<url>https://jitpack.io</url>
|
||||
</repository>
|
||||
|
||||
<!-- BungeeCord -->
|
||||
<repository>
|
||||
<id>luck-repo</id>
|
||||
<url>https://ci.lucko.me/plugin/repository/everything/</url>
|
||||
</repository>
|
||||
|
||||
</repositories>
|
||||
|
||||
<dependencies>
|
||||
|
||||
<!-- TAB Core -->
|
||||
<dependency>
|
||||
<groupId>me.neznamy</groupId>
|
||||
<artifactId>shared</artifactId>
|
||||
<version>${project.version}</version>
|
||||
<scope>provided</scope>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>com.googlecode.json-simple</groupId>
|
||||
<artifactId>json-simple</artifactId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<groupId>com.github.NEZNAMY</groupId>
|
||||
<artifactId>YamlAssist</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
|
||||
<!-- BungeeCord -->
|
||||
<dependency>
|
||||
<groupId>net.md-5</groupId>
|
||||
<artifactId>bungeecord-proxy</artifactId>
|
||||
<version>1.17-R0.1-SNAPSHOT</version>
|
||||
<scope>provided</scope>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>io.netty</groupId>
|
||||
<artifactId>netty-codec-haproxy</artifactId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<groupId>io.netty</groupId>
|
||||
<artifactId>netty-codec-http</artifactId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<groupId>io.netty</groupId>
|
||||
<artifactId>netty-handler</artifactId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<groupId>io.netty</groupId>
|
||||
<artifactId>netty-transport-native-epoll</artifactId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<groupId>io.netty</groupId>
|
||||
<artifactId>netty-transport-native-unix-common</artifactId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<groupId>net.md-5</groupId>
|
||||
<artifactId>brigadier</artifactId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<groupId>jline</groupId>
|
||||
<artifactId>jline</artifactId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<groupId>io.netty</groupId>
|
||||
<artifactId>netty-transport</artifactId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<groupId>io.netty</groupId>
|
||||
<artifactId>netty-codec</artifactId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<groupId>net.sf.trove4j</groupId>
|
||||
<artifactId>core</artifactId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<groupId>net.md-5</groupId>
|
||||
<artifactId>bungeecord-query</artifactId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<groupId>se.llbit</groupId>
|
||||
<artifactId>jo-nbt</artifactId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<groupId>net.sf.jopt-simple</groupId>
|
||||
<artifactId>jopt-simple</artifactId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<groupId>mysql</groupId>
|
||||
<artifactId>mysql-connector-java</artifactId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<groupId>com.google.code.gson</groupId>
|
||||
<artifactId>gson</artifactId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<groupId>org.apache.maven</groupId>
|
||||
<artifactId>maven-resolver-provider</artifactId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<groupId>org.apache.maven.resolver</groupId>
|
||||
<artifactId>
|
||||
maven-resolver-connector-basic
|
||||
</artifactId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<groupId>org.apache.maven.resolver</groupId>
|
||||
<artifactId>
|
||||
maven-resolver-transport-http
|
||||
</artifactId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-jdk14</artifactId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<groupId>org.yaml</groupId>
|
||||
<artifactId>snakeyaml</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
|
||||
<!-- PremiumVanishAPI -->
|
||||
<dependency>
|
||||
<groupId>com.github.MyzelYam</groupId>
|
||||
<artifactId>PremiumVanishAPI</artifactId>
|
||||
<version>2.0.3</version>
|
||||
<scope>provided</scope>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>com.google.code.findbugs</groupId>
|
||||
<artifactId>jsr305</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
|
||||
<!-- Bungee Metrics -->
|
||||
<dependency>
|
||||
<groupId>org.bstats</groupId>
|
||||
<artifactId>bstats-bungeecord</artifactId>
|
||||
<version>2.2.1</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
+11
-8
@@ -1,6 +1,7 @@
|
||||
package me.neznamy.tab.platforms.bungeecord;
|
||||
|
||||
import me.neznamy.tab.shared.TAB;
|
||||
import me.neznamy.tab.shared.features.PluginMessageHandler;
|
||||
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
||||
import net.md_5.bungee.api.event.ChatEvent;
|
||||
import net.md_5.bungee.api.event.PlayerDisconnectEvent;
|
||||
@@ -14,6 +15,12 @@ import net.md_5.bungee.event.EventPriority;
|
||||
*/
|
||||
public class BungeeEventListener implements Listener {
|
||||
|
||||
private PluginMessageHandler plm;
|
||||
|
||||
public BungeeEventListener(PluginMessageHandler plm) {
|
||||
this.plm = plm;
|
||||
}
|
||||
|
||||
/**
|
||||
* Disconnect event listener to forward the event to all features
|
||||
* @param e - disconnect event
|
||||
@@ -32,12 +39,12 @@ public class BungeeEventListener implements Listener {
|
||||
public void onSwitch(ServerSwitchEvent e){
|
||||
if (TAB.getInstance().isDisabled()) return;
|
||||
try {
|
||||
if (!TAB.getInstance().data.containsKey(e.getPlayer().getUniqueId())) {
|
||||
TAB.getInstance().getFeatureManager().onJoin(new BungeeTabPlayer(e.getPlayer()));
|
||||
if (TAB.getInstance().getPlayer(e.getPlayer().getUniqueId()) == null) {
|
||||
TAB.getInstance().getFeatureManager().onJoin(new BungeeTabPlayer(e.getPlayer(), plm));
|
||||
} else {
|
||||
TAB.getInstance().getFeatureManager().onWorldChange(e.getPlayer().getUniqueId(), e.getPlayer().getServer().getInfo().getName());
|
||||
}
|
||||
} catch (Throwable ex){
|
||||
} catch (Exception ex){
|
||||
TAB.getInstance().getErrorManager().criticalError("An error occurred when player joined/changed server", ex);
|
||||
}
|
||||
}
|
||||
@@ -49,10 +56,6 @@ public class BungeeEventListener implements Listener {
|
||||
@EventHandler
|
||||
public void onChat(ChatEvent e) {
|
||||
if (TAB.getInstance().isDisabled()) return;
|
||||
if (e.getMessage().startsWith("/")) {
|
||||
if (TAB.getInstance().getFeatureManager().onCommand(TAB.getInstance().getPlayer(((ProxiedPlayer)e.getSender()).getUniqueId()), e.getMessage())) e.setCancelled(true);
|
||||
} else {
|
||||
if (TAB.getInstance().getFeatureManager().onChat(TAB.getInstance().getPlayer(((ProxiedPlayer)e.getSender()).getUniqueId()), e.getMessage(), e.isCancelled())) e.setCancelled(true);
|
||||
}
|
||||
if (e.getMessage().startsWith("/") && TAB.getInstance().getFeatureManager().onCommand(TAB.getInstance().getPlayer(((ProxiedPlayer)e.getSender()).getUniqueId()), e.getMessage())) e.setCancelled(true);
|
||||
}
|
||||
}
|
||||
+33
-46
@@ -19,18 +19,16 @@ import me.neznamy.tab.shared.packets.PacketPlayOutScoreboardObjective;
|
||||
import me.neznamy.tab.shared.packets.PacketPlayOutScoreboardObjective.EnumScoreboardHealthDisplay;
|
||||
import me.neznamy.tab.shared.packets.PacketPlayOutScoreboardScore;
|
||||
import me.neznamy.tab.shared.packets.PacketPlayOutScoreboardTeam;
|
||||
import me.neznamy.tab.shared.packets.PacketPlayOutTitle;
|
||||
import net.md_5.bungee.protocol.packet.BossBar;
|
||||
import net.md_5.bungee.protocol.packet.Chat;
|
||||
import net.md_5.bungee.protocol.packet.PlayerListHeaderFooter;
|
||||
import net.md_5.bungee.protocol.packet.PlayerListItem;
|
||||
import net.md_5.bungee.protocol.packet.PlayerListItem.Item;
|
||||
import net.md_5.bungee.protocol.packet.ScoreboardDisplay;
|
||||
import net.md_5.bungee.protocol.packet.ScoreboardObjective;
|
||||
import net.md_5.bungee.protocol.packet.ScoreboardObjective.HealthDisplay;
|
||||
import net.md_5.bungee.protocol.packet.ScoreboardScore;
|
||||
import net.md_5.bungee.protocol.packet.Team;
|
||||
import net.md_5.bungee.protocol.packet.Title;
|
||||
import net.md_5.bungee.protocol.packet.PlayerListItem.Item;
|
||||
|
||||
/**
|
||||
* Packet builder for BungeeCord platform
|
||||
@@ -40,96 +38,85 @@ public class BungeePacketBuilder implements PacketBuilder {
|
||||
@Override
|
||||
public Object build(PacketPlayOutBoss packet, ProtocolVersion clientVersion) {
|
||||
if (clientVersion.getMinorVersion() < 9) return null;
|
||||
BossBar bungeePacket = new BossBar(packet.id, packet.operation.ordinal());
|
||||
bungeePacket.setHealth(packet.pct);
|
||||
bungeePacket.setTitle(packet.name == null ? null : IChatBaseComponent.optimizedComponent(packet.name).toString(clientVersion));
|
||||
bungeePacket.setColor(packet.color == null ? 0 : packet.color.ordinal());
|
||||
bungeePacket.setDivision(packet.overlay == null ? 0: packet.overlay.ordinal());
|
||||
BossBar bungeePacket = new BossBar(packet.getId(), packet.getOperation().ordinal());
|
||||
bungeePacket.setHealth(packet.getPct());
|
||||
bungeePacket.setTitle(packet.getName() == null ? null : IChatBaseComponent.optimizedComponent(packet.getName()).toString(clientVersion));
|
||||
bungeePacket.setColor(packet.getColor() == null ? 0 : packet.getColor().ordinal());
|
||||
bungeePacket.setDivision(packet.getOverlay() == null ? 0: packet.getOverlay().ordinal());
|
||||
bungeePacket.setFlags(packet.getFlags());
|
||||
return bungeePacket;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object build(PacketPlayOutChat packet, ProtocolVersion clientVersion) {
|
||||
return new Chat(packet.message.toString(clientVersion), (byte) packet.type.ordinal());
|
||||
return new Chat(packet.getMessage().toString(clientVersion), (byte) packet.getType().ordinal());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object build(PacketPlayOutPlayerInfo packet, ProtocolVersion clientVersion) {
|
||||
List<Item> items = new ArrayList<Item>();
|
||||
for (PlayerInfoData data : packet.entries) {
|
||||
List<Item> items = new ArrayList<>();
|
||||
for (PlayerInfoData data : packet.getEntries()) {
|
||||
Item item = new Item();
|
||||
if (data.displayName != null) {
|
||||
if (clientVersion.getNetworkId() >= ProtocolVersion.v1_8.getNetworkId()) {
|
||||
item.setDisplayName(data.displayName.toString(clientVersion));
|
||||
if (data.getDisplayName() != null) {
|
||||
if (clientVersion.getMinorVersion() >= 8) {
|
||||
item.setDisplayName(data.getDisplayName().toString(clientVersion));
|
||||
} else {
|
||||
item.setDisplayName(data.displayName.toLegacyText());
|
||||
item.setDisplayName(data.getDisplayName().toLegacyText());
|
||||
}
|
||||
} else if (clientVersion.getNetworkId() < ProtocolVersion.v1_8.getNetworkId()) {
|
||||
item.setDisplayName(data.name); //avoiding NPE, 1.7 client requires this, 1.8 added a leading boolean
|
||||
} else if (clientVersion.getMinorVersion() < 8) {
|
||||
item.setDisplayName(data.getName()); //avoiding NPE, 1.7 client requires this, 1.8 added a leading boolean
|
||||
}
|
||||
if (data.gameMode != null) item.setGamemode(data.gameMode.ordinal()-1);
|
||||
item.setPing(data.latency);
|
||||
if (data.skin != null) {
|
||||
item.setProperties((String[][]) data.skin);
|
||||
if (data.getGameMode() != null) item.setGamemode(data.getGameMode().ordinal()-1);
|
||||
item.setPing(data.getLatency());
|
||||
if (data.getSkin() != null) {
|
||||
item.setProperties((String[][]) data.getSkin());
|
||||
} else {
|
||||
item.setProperties(new String[0][0]);
|
||||
}
|
||||
item.setUsername(data.name);
|
||||
item.setUuid(data.uniqueId);
|
||||
item.setUsername(data.getName());
|
||||
item.setUuid(data.getUniqueId());
|
||||
items.add(item);
|
||||
}
|
||||
PlayerListItem bungeePacket = new PlayerListItem();
|
||||
bungeePacket.setAction(PlayerListItem.Action.valueOf(packet.action.toString().replace("GAME_MODE", "GAMEMODE")));
|
||||
bungeePacket.setAction(PlayerListItem.Action.valueOf(packet.getAction().toString().replace("GAME_MODE", "GAMEMODE")));
|
||||
bungeePacket.setItems(items.toArray(new Item[0]));
|
||||
return bungeePacket;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object build(PacketPlayOutPlayerListHeaderFooter packet, ProtocolVersion clientVersion) {
|
||||
return new PlayerListHeaderFooter(packet.header.toString(clientVersion, true), packet.footer.toString(clientVersion, true));
|
||||
return new PlayerListHeaderFooter(packet.getHeader().toString(clientVersion, true), packet.getFooter().toString(clientVersion, true));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object build(PacketPlayOutScoreboardDisplayObjective packet, ProtocolVersion clientVersion) {
|
||||
return new ScoreboardDisplay((byte)packet.slot, packet.objectiveName);
|
||||
return new ScoreboardDisplay((byte)packet.getSlot(), packet.getObjectiveName());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object build(PacketPlayOutScoreboardObjective packet, ProtocolVersion clientVersion) {
|
||||
return new ScoreboardObjective(packet.objectiveName, jsonOrCut(packet.displayName, clientVersion, 32), packet.renderType == null ? null : HealthDisplay.valueOf(packet.renderType.toString()), (byte)packet.method);
|
||||
return new ScoreboardObjective(packet.getObjectiveName(), jsonOrCut(packet.getDisplayName(), clientVersion, 32), packet.getRenderType() == null ? null : HealthDisplay.valueOf(packet.getRenderType().toString()), (byte)packet.getMethod());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object build(PacketPlayOutScoreboardScore packet, ProtocolVersion clientVersion) {
|
||||
return new ScoreboardScore(packet.player, (byte) packet.action.ordinal(), packet.objectiveName, packet.score);
|
||||
return new ScoreboardScore(packet.getPlayer(), (byte) packet.getAction().ordinal(), packet.getObjectiveName(), packet.getScore());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object build(PacketPlayOutScoreboardTeam packet, ProtocolVersion clientVersion) {
|
||||
int color = 0;
|
||||
if (clientVersion.getMinorVersion() >= 13) {
|
||||
color = (packet.color != null ? packet.color : EnumChatFormat.lastColorsOf(packet.playerPrefix)).getNetworkId();
|
||||
color = (packet.getColor() != null ? packet.getColor() : EnumChatFormat.lastColorsOf(packet.getPlayerPrefix())).getNetworkId();
|
||||
}
|
||||
return new Team(packet.name, (byte)packet.method, jsonOrCut(packet.name, clientVersion, 16), jsonOrCut(packet.playerPrefix, clientVersion, 16), jsonOrCut(packet.playerSuffix, clientVersion, 16),
|
||||
packet.nametagVisibility, packet.collisionRule, color, (byte)packet.options, packet.players.toArray(new String[0]));
|
||||
return new Team(packet.getName(), (byte)packet.getMethod(), jsonOrCut(packet.getName(), clientVersion, 16), jsonOrCut(packet.getPlayerPrefix(), clientVersion, 16), jsonOrCut(packet.getPlayerSuffix(), clientVersion, 16),
|
||||
packet.getNametagVisibility(), packet.getCollisionRule(), color, (byte)packet.getOptions(), packet.getPlayers().toArray(new String[0]));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object build(PacketPlayOutTitle packet, ProtocolVersion clientVersion) throws Exception {
|
||||
Title bungeePacket = new Title();
|
||||
bungeePacket.setAction(Title.Action.valueOf(packet.action.toString()));
|
||||
if (packet.text != null) bungeePacket.setText(IChatBaseComponent.optimizedComponent(packet.text).toString(clientVersion));
|
||||
bungeePacket.setFadeIn(packet.fadeIn);
|
||||
bungeePacket.setStay(packet.stay);
|
||||
bungeePacket.setFadeOut(packet.fadeOut);
|
||||
return bungeePacket;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PacketPlayOutPlayerInfo readPlayerInfo(Object bungeePacket, ProtocolVersion clientVersion){
|
||||
public PacketPlayOutPlayerInfo readPlayerInfo(Object bungeePacket, ProtocolVersion clientVersion) {
|
||||
PlayerListItem item = (PlayerListItem) bungeePacket;
|
||||
List<PlayerInfoData> listData = new ArrayList<PlayerInfoData>();
|
||||
List<PlayerInfoData> listData = new ArrayList<>();
|
||||
for (Item i : item.getItems()) {
|
||||
listData.add(new PlayerInfoData(i.getUsername(), i.getUuid(), i.getProperties(), i.getPing(), EnumGamemode.values()[i.getGamemode()+1], IChatBaseComponent.fromString(i.getDisplayName())));
|
||||
}
|
||||
@@ -137,7 +124,7 @@ public class BungeePacketBuilder implements PacketBuilder {
|
||||
}
|
||||
|
||||
@Override
|
||||
public PacketPlayOutScoreboardObjective readObjective(Object bungeePacket, ProtocolVersion clientVersion) throws Exception {
|
||||
public PacketPlayOutScoreboardObjective readObjective(Object bungeePacket, ProtocolVersion clientVersion) {
|
||||
ScoreboardObjective packet = (ScoreboardObjective) bungeePacket;
|
||||
String title;
|
||||
if (clientVersion.getMinorVersion() >= 13) {
|
||||
@@ -150,7 +137,7 @@ public class BungeePacketBuilder implements PacketBuilder {
|
||||
}
|
||||
|
||||
@Override
|
||||
public PacketPlayOutScoreboardDisplayObjective readDisplayObjective(Object bungeePacket, ProtocolVersion clientVersion) throws Exception {
|
||||
public PacketPlayOutScoreboardDisplayObjective readDisplayObjective(Object bungeePacket, ProtocolVersion clientVersion){
|
||||
return new PacketPlayOutScoreboardDisplayObjective(((ScoreboardDisplay) bungeePacket).getPosition(), ((ScoreboardDisplay) bungeePacket).getName());
|
||||
}
|
||||
}
|
||||
+161
@@ -0,0 +1,161 @@
|
||||
package me.neznamy.tab.platforms.bungeecord;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.NoSuchElementException;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.channel.ChannelDuplexHandler;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import io.netty.channel.ChannelPromise;
|
||||
import me.neznamy.tab.api.TabPlayer;
|
||||
import me.neznamy.tab.shared.TAB;
|
||||
import me.neznamy.tab.shared.cpu.TabFeature;
|
||||
import me.neznamy.tab.shared.cpu.UsageType;
|
||||
import me.neznamy.tab.shared.features.PipelineInjector;
|
||||
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
||||
import net.md_5.bungee.protocol.DefinedPacket;
|
||||
import net.md_5.bungee.protocol.packet.Login;
|
||||
import net.md_5.bungee.protocol.packet.PlayerListItem;
|
||||
import net.md_5.bungee.protocol.packet.ScoreboardDisplay;
|
||||
import net.md_5.bungee.protocol.packet.ScoreboardObjective;
|
||||
import net.md_5.bungee.protocol.packet.Team;
|
||||
|
||||
public class BungeePipelineInjector extends PipelineInjector {
|
||||
|
||||
//handler to inject before
|
||||
private static final String INJECT_POSITION = "inbound-boss";
|
||||
|
||||
//packets that must be deserialized and bungeecord does not do it automatically
|
||||
private Map<Class<? extends DefinedPacket>, Supplier<DefinedPacket>> extraPackets = new HashMap<>();
|
||||
|
||||
/**
|
||||
* Constructs new instance with given parameter
|
||||
* @param tab - tab instance
|
||||
*/
|
||||
public BungeePipelineInjector(TAB tab) {
|
||||
super(tab);
|
||||
extraPackets.put(Team.class, Team::new);
|
||||
extraPackets.put(ScoreboardDisplay.class, ScoreboardDisplay::new);
|
||||
extraPackets.put(ScoreboardObjective.class, ScoreboardObjective::new);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void inject(TabPlayer player) {
|
||||
if (player.getVersion().getMinorVersion() < 8) return;
|
||||
uninject(player);
|
||||
try {
|
||||
player.getChannel().pipeline().addBefore(INJECT_POSITION, DECODER_NAME, new BungeeChannelDuplexHandler(player));
|
||||
} catch (NoSuchElementException | IllegalArgumentException e) {
|
||||
//idk how does this keep happening but whatever
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void uninject(TabPlayer player) {
|
||||
if (player.getVersion().getMinorVersion() < 8) return;
|
||||
if (player.getChannel().pipeline().names().contains(DECODER_NAME)) player.getChannel().pipeline().remove(DECODER_NAME);
|
||||
}
|
||||
|
||||
/**
|
||||
* Custom channel duplex handler override
|
||||
*/
|
||||
public class BungeeChannelDuplexHandler extends ChannelDuplexHandler {
|
||||
|
||||
//injected player
|
||||
private TabPlayer player;
|
||||
|
||||
/**
|
||||
* Constructs new instance with given player
|
||||
* @param player - player to inject
|
||||
*/
|
||||
public BungeeChannelDuplexHandler(TabPlayer player) {
|
||||
this.player = player;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(ChannelHandlerContext context, Object packet, ChannelPromise channelPromise) {
|
||||
long time = System.nanoTime();
|
||||
Object modifiedPacket = packet instanceof ByteBuf ? deserialize((ByteBuf) packet) : packet;
|
||||
tab.getCPUManager().addTime(TabFeature.PACKET_DESERIALIZING, UsageType.PACKET_READING_OUT, System.nanoTime()-time);
|
||||
try {
|
||||
if (modifiedPacket instanceof PlayerListItem) {
|
||||
super.write(context, tab.getFeatureManager().onPacketPlayOutPlayerInfo(player, modifiedPacket), channelPromise);
|
||||
return;
|
||||
}
|
||||
if (tab.getFeatureManager().isFeatureEnabled("nametag16") && antiOverrideTeams) {
|
||||
time = System.nanoTime();
|
||||
if (modifiedPacket instanceof Team) {
|
||||
modifyPlayers((Team) modifiedPacket);
|
||||
}
|
||||
tab.getCPUManager().addTime(TabFeature.NAMETAGS, UsageType.ANTI_OVERRIDE, System.nanoTime()-time);
|
||||
}
|
||||
if (modifiedPacket instanceof ScoreboardDisplay && antiOverrideObjectives && tab.getFeatureManager().onDisplayObjective(player, modifiedPacket)) {
|
||||
return;
|
||||
}
|
||||
if (modifiedPacket instanceof ScoreboardObjective && antiOverrideObjectives) {
|
||||
tab.getFeatureManager().onObjective(player, modifiedPacket);
|
||||
}
|
||||
//client reset packet
|
||||
if (modifiedPacket instanceof Login) {
|
||||
//making sure to not send own packets before login packet is actually sent
|
||||
super.write(context, modifiedPacket, channelPromise);
|
||||
tab.getFeatureManager().onLoginPacket(player);
|
||||
return;
|
||||
}
|
||||
} catch (Throwable e){
|
||||
tab.getErrorManager().printError("An error occurred when analyzing packets for player " + player.getName() + " with client version " + player.getVersion().getFriendlyName(), e);
|
||||
}
|
||||
try {
|
||||
super.write(context, modifiedPacket, channelPromise);
|
||||
} catch (Throwable e) {
|
||||
tab.getErrorManager().printError("Failed to forward packet " + modifiedPacket.getClass().getSimpleName() + " to " + player.getName(), e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes all real players from packet if the packet doesn't come from TAB
|
||||
* @param packet - packet to modify
|
||||
*/
|
||||
private void modifyPlayers(Team packet){
|
||||
long time = System.nanoTime();
|
||||
if (packet.getPlayers() == null) return;
|
||||
Collection<String> col = Lists.newArrayList(packet.getPlayers());
|
||||
for (TabPlayer p : tab.getPlayers()) {
|
||||
if (col.contains(p.getName()) && !tab.getFeatureManager().getNameTagFeature().getPlayersInDisabledWorlds().contains(p) &&
|
||||
!p.hasTeamHandlingPaused() && !packet.getName().equals(p.getTeamName())) {
|
||||
logTeamOverride(packet.getName(), p.getName());
|
||||
col.remove(p.getName());
|
||||
}
|
||||
}
|
||||
packet.setPlayers(col.toArray(new String[0]));
|
||||
tab.getCPUManager().addTime(TabFeature.NAMETAGS, UsageType.ANTI_OVERRIDE, System.nanoTime()-time);
|
||||
}
|
||||
|
||||
/**
|
||||
* Deserializes bytebuf in case it is one of the tracked packets coming from backend server and returns it.
|
||||
* If the packet is not one of them, returns input
|
||||
* @param buf - bytebuf to deserialize
|
||||
* @return deserialized packet or input bytebuf if packet is not tracked
|
||||
*/
|
||||
private Object deserialize(ByteBuf buf) {
|
||||
int marker = buf.readerIndex();
|
||||
int packetId = buf.readByte();
|
||||
for (Entry<Class<? extends DefinedPacket>, Supplier<DefinedPacket>> e : extraPackets.entrySet()) {
|
||||
if (packetId == ((BungeeTabPlayer)player).getPacketId(e.getKey())) {
|
||||
DefinedPacket packet = e.getValue().get();
|
||||
packet.read(buf, null, ((ProxiedPlayer)player.getPlayer()).getPendingConnection().getVersion());
|
||||
buf.release();
|
||||
return packet;
|
||||
}
|
||||
}
|
||||
buf.readerIndex(marker);
|
||||
return buf;
|
||||
}
|
||||
}
|
||||
}
|
||||
+3
-21
@@ -1,16 +1,14 @@
|
||||
package me.neznamy.tab.platforms.bungeecord;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import de.myzelyam.api.vanish.BungeeVanishAPI;
|
||||
import me.neznamy.tab.api.TabPlayer;
|
||||
import me.neznamy.tab.shared.TAB;
|
||||
import me.neznamy.tab.shared.placeholders.Placeholder;
|
||||
import me.neznamy.tab.shared.placeholders.PlaceholderRegistry;
|
||||
import me.neznamy.tab.shared.placeholders.PlayerPlaceholder;
|
||||
import me.neznamy.tab.shared.placeholders.ServerPlaceholder;
|
||||
import me.neznamy.tab.shared.proxy.ProxyPlaceholderRegistry;
|
||||
import net.md_5.bungee.api.ProxyServer;
|
||||
import net.md_5.bungee.api.config.ServerInfo;
|
||||
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
||||
@@ -18,27 +16,11 @@ import net.md_5.bungee.api.connection.ProxiedPlayer;
|
||||
/**
|
||||
* Bungeecord registry to register bungeecord-only placeholders
|
||||
*/
|
||||
public class BungeePlaceholderRegistry implements PlaceholderRegistry {
|
||||
public class BungeePlaceholderRegistry extends ProxyPlaceholderRegistry {
|
||||
|
||||
@Override
|
||||
public List<Placeholder> registerPlaceholders() {
|
||||
List<Placeholder> placeholders = new ArrayList<Placeholder>();
|
||||
if (ProxyServer.getInstance().getPluginManager().getPlugin("PremiumVanish") != null) {
|
||||
placeholders.add(new ServerPlaceholder("%canseeonline%", 1000) {
|
||||
public String get() {
|
||||
return String.valueOf(TAB.getInstance().getPlayers().size() - BungeeVanishAPI.getInvisiblePlayers().size());
|
||||
}
|
||||
});
|
||||
placeholders.add(new ServerPlaceholder("%canseestaffonline%", 1000) {
|
||||
public String get() {
|
||||
int count = 0;
|
||||
for (TabPlayer all : TAB.getInstance().getPlayers()) {
|
||||
if (!((BungeeTabPlayer)all).isVanished() && all.isStaff()) count++;
|
||||
}
|
||||
return String.valueOf(count);
|
||||
}
|
||||
});
|
||||
}
|
||||
List<Placeholder> placeholders = super.registerPlaceholders();
|
||||
placeholders.add(new PlayerPlaceholder("%displayname%", 500) {
|
||||
public String get(TabPlayer p) {
|
||||
return ((ProxiedPlayer) p.getPlayer()).getDisplayName();
|
||||
@@ -0,0 +1,110 @@
|
||||
package me.neznamy.tab.platforms.bungeecord;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import me.neznamy.tab.api.event.BungeeTABLoadEvent;
|
||||
import me.neznamy.tab.shared.TAB;
|
||||
import me.neznamy.tab.shared.features.BelowName;
|
||||
import me.neznamy.tab.shared.features.GlobalPlayerlist;
|
||||
import me.neznamy.tab.shared.features.NameTag;
|
||||
import me.neznamy.tab.shared.features.PingSpoof;
|
||||
import me.neznamy.tab.shared.features.PluginMessageHandler;
|
||||
import me.neznamy.tab.shared.features.SpectatorFix;
|
||||
import me.neznamy.tab.shared.features.TabObjective;
|
||||
import me.neznamy.tab.shared.features.scoreboard.ScoreboardManager;
|
||||
import me.neznamy.tab.shared.permission.LuckPerms;
|
||||
import me.neznamy.tab.shared.permission.PermissionPlugin;
|
||||
import me.neznamy.tab.shared.permission.UltraPermissions;
|
||||
import me.neznamy.tab.shared.permission.VaultBridge;
|
||||
import me.neznamy.tab.shared.placeholders.UniversalPlaceholderRegistry;
|
||||
import me.neznamy.tab.shared.proxy.ProxyPlatform;
|
||||
import net.md_5.bungee.api.ProxyServer;
|
||||
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
||||
import net.md_5.bungee.api.plugin.Plugin;
|
||||
|
||||
/**
|
||||
* Bungeecord implementation of Platform
|
||||
*/
|
||||
public class BungeePlatform extends ProxyPlatform {
|
||||
|
||||
//instance of plugin
|
||||
private Plugin plugin;
|
||||
|
||||
/**
|
||||
* Constructs new instance with given parameter
|
||||
* @param plugin - main class
|
||||
*/
|
||||
public BungeePlatform(Plugin plugin, PluginMessageHandler plm) {
|
||||
super(plm);
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PermissionPlugin detectPermissionPlugin() {
|
||||
if (TAB.getInstance().getConfiguration().isBukkitPermissions()) {
|
||||
return new VaultBridge(plm);
|
||||
} else if (ProxyServer.getInstance().getPluginManager().getPlugin("LuckPerms") != null) {
|
||||
return new LuckPerms(ProxyServer.getInstance().getPluginManager().getPlugin("LuckPerms").getDescription().getVersion());
|
||||
} else if (ProxyServer.getInstance().getPluginManager().getPlugin("UltraPermissions") != null) {
|
||||
return new UltraPermissions(ProxyServer.getInstance().getPluginManager().getPlugin("UltraPermissions").getDescription().getVersion());
|
||||
} else {
|
||||
return new VaultBridge(plm);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadFeatures() throws IllegalAccessException {
|
||||
TAB tab = TAB.getInstance();
|
||||
tab.getPlaceholderManager().addRegistry(new BungeePlaceholderRegistry());
|
||||
tab.getPlaceholderManager().addRegistry(new UniversalPlaceholderRegistry());
|
||||
tab.getPlaceholderManager().registerPlaceholders();
|
||||
if (tab.getConfiguration().isPipelineInjection()) tab.getFeatureManager().registerFeature("injection", new BungeePipelineInjector(tab));
|
||||
if (tab.getConfiguration().getConfig().getBoolean("change-nametag-prefix-suffix", true)) tab.getFeatureManager().registerFeature("nametag16", new NameTag(tab));
|
||||
loadUniversalFeatures();
|
||||
if (tab.getConfiguration().getConfig().getBoolean("ping-spoof.enabled", false)) tab.getFeatureManager().registerFeature("pingspoof", new PingSpoof());
|
||||
if (tab.getConfiguration().getConfig().getString("yellow-number-in-tablist", "%ping%").length() > 0) tab.getFeatureManager().registerFeature("tabobjective", new TabObjective(tab));
|
||||
if (tab.getConfiguration().getConfig().getBoolean("do-not-move-spectators", false)) tab.getFeatureManager().registerFeature("spectatorfix", new SpectatorFix());
|
||||
if (tab.getConfiguration().getConfig().getBoolean("classic-vanilla-belowname.enabled", true)) tab.getFeatureManager().registerFeature("belowname", new BelowName(tab));
|
||||
if (tab.getConfiguration().getPremiumConfig() != null && tab.getConfiguration().getPremiumConfig().getBoolean("scoreboard.enabled", false)) tab.getFeatureManager().registerFeature("scoreboard", new ScoreboardManager(tab));
|
||||
if (tab.getConfiguration().getConfig().getBoolean("global-playerlist.enabled", false)) tab.getFeatureManager().registerFeature("globalplayerlist", new GlobalPlayerlist(tab));
|
||||
for (ProxiedPlayer p : ProxyServer.getInstance().getPlayers()) {
|
||||
tab.addPlayer(new BungeeTabPlayer(p, plm));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("deprecation")
|
||||
public void sendConsoleMessage(String message, boolean translateColors) {
|
||||
ProxyServer.getInstance().getConsole().sendMessage(translateColors ? message.replace('&', '\u00a7') : message);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getServerVersion() {
|
||||
return ProxyServer.getInstance().getVersion();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSeparatorType() {
|
||||
return "server";
|
||||
}
|
||||
|
||||
@Override
|
||||
public File getDataFolder() {
|
||||
return plugin.getDataFolder();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void callLoadEvent() {
|
||||
ProxyServer.getInstance().getPluginManager().callEvent(new BungeeTABLoadEvent());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxPlayers() {
|
||||
return ProxyServer.getInstance().getConfigurationAdapter().getListeners().iterator().next().getMaxPlayers();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getConfigName() {
|
||||
return "bungeeconfig.yml";
|
||||
}
|
||||
}
|
||||
File renamed without changes.
+18
-22
@@ -4,9 +4,11 @@ import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
import de.myzelyam.api.vanish.BungeeVanishAPI;
|
||||
import me.neznamy.tab.shared.ITabPlayer;
|
||||
import me.neznamy.tab.shared.ProtocolVersion;
|
||||
import me.neznamy.tab.shared.TAB;
|
||||
import me.neznamy.tab.shared.features.PluginMessageHandler;
|
||||
import me.neznamy.tab.shared.proxy.ProxyTabPlayer;
|
||||
import net.md_5.bungee.UserConnection;
|
||||
import net.md_5.bungee.api.ProxyServer;
|
||||
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
||||
import net.md_5.bungee.connection.InitialHandler;
|
||||
@@ -18,7 +20,7 @@ import net.md_5.bungee.protocol.Protocol;
|
||||
/**
|
||||
* TabPlayer for BungeeCord
|
||||
*/
|
||||
public class BungeeTabPlayer extends ITabPlayer {
|
||||
public class BungeeTabPlayer extends ProxyTabPlayer {
|
||||
|
||||
//bungee internals to get player channel
|
||||
private static Field wrapperField;
|
||||
@@ -35,7 +37,8 @@ public class BungeeTabPlayer extends ITabPlayer {
|
||||
directionData = f.get(Protocol.GAME);
|
||||
getId = directionData.getClass().getDeclaredMethod("getId", Class.class, int.class);
|
||||
getId.setAccessible(true);
|
||||
(wrapperField = InitialHandler.class.getDeclaredField("ch")).setAccessible(true);
|
||||
wrapperField = InitialHandler.class.getDeclaredField("ch");
|
||||
wrapperField.setAccessible(true);
|
||||
} catch (Exception e) {
|
||||
TAB.getInstance().getErrorManager().criticalError("Failed to initialize fields for packet analysis", e);
|
||||
}
|
||||
@@ -47,9 +50,10 @@ public class BungeeTabPlayer extends ITabPlayer {
|
||||
/**
|
||||
* Constructs new instance for given player
|
||||
* @param p - velocity player
|
||||
* @throws Exception - if reflection fails
|
||||
* @throws IllegalAccessException
|
||||
*/
|
||||
public BungeeTabPlayer(ProxiedPlayer p) throws Exception {
|
||||
public BungeeTabPlayer(ProxiedPlayer p, PluginMessageHandler plm) throws IllegalAccessException {
|
||||
super (plm);
|
||||
player = p;
|
||||
if (p.getServer() != null) {
|
||||
world = p.getServer().getInfo().getName();
|
||||
@@ -63,7 +67,7 @@ public class BungeeTabPlayer extends ITabPlayer {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasPermission(String permission) {
|
||||
public boolean hasPermission0(String permission) {
|
||||
return player.hasPermission(permission);
|
||||
}
|
||||
|
||||
@@ -97,7 +101,7 @@ public class BungeeTabPlayer extends ITabPlayer {
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns packet ID for this packet of provided packet class
|
||||
* Returns packet ID for this player of provided packet class
|
||||
* @param clazz - packet class
|
||||
* @return - packet ID
|
||||
*/
|
||||
@@ -117,25 +121,17 @@ public class BungeeTabPlayer extends ITabPlayer {
|
||||
|
||||
@Override
|
||||
public boolean isVanished() {
|
||||
return ProxyServer.getInstance().getPluginManager().getPlugin("PremiumVanish") != null && BungeeVanishAPI.isInvisible(player);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDisguised() {
|
||||
Main.plm.requestAttribute(this, "disguised");
|
||||
if (!attributes.containsKey("disguised")) return false;
|
||||
return Boolean.parseBoolean(attributes.get("disguised"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasInvisibilityPotion() {
|
||||
Main.plm.requestAttribute(this, "invisible");
|
||||
if (!attributes.containsKey("invisible")) return false;
|
||||
return Boolean.parseBoolean(attributes.get("invisible"));
|
||||
if (ProxyServer.getInstance().getPluginManager().getPlugin("PremiumVanish") != null && BungeeVanishAPI.isInvisible(player)) return true;
|
||||
return super.isVanished();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isOnline() {
|
||||
return player.isConnected();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getGamemode() {
|
||||
return ((UserConnection)player).getGamemode();
|
||||
}
|
||||
}
|
||||
+18
-12
@@ -5,6 +5,7 @@ import java.util.ArrayList;
|
||||
import org.bstats.bungeecord.Metrics;
|
||||
import org.bstats.charts.SimplePie;
|
||||
|
||||
import me.neznamy.tab.api.TabPlayer;
|
||||
import me.neznamy.tab.shared.ProtocolVersion;
|
||||
import me.neznamy.tab.shared.TAB;
|
||||
import me.neznamy.tab.shared.features.PluginMessageHandler;
|
||||
@@ -20,9 +21,6 @@ import net.md_5.bungee.api.plugin.TabExecutor;
|
||||
*/
|
||||
public class Main extends Plugin {
|
||||
|
||||
//plugin message handler
|
||||
public static PluginMessageHandler plm;
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@Override
|
||||
public void onEnable(){
|
||||
@@ -30,12 +28,11 @@ public class Main extends Plugin {
|
||||
ProxyServer.getInstance().getConsole().sendMessage("\u00a7c[TAB] The plugin requires BungeeCord build #1330 and up to work. Get it at https://ci.md-5.net/job/BungeeCord/");
|
||||
return;
|
||||
}
|
||||
ProtocolVersion.SERVER_VERSION = ProtocolVersion.values()[1];
|
||||
TAB.setInstance(new TAB(new BungeePlatform(this), new BungeePacketBuilder()));
|
||||
getProxy().getPluginManager().registerListener(this, new BungeeEventListener());
|
||||
PluginMessageHandler plm = new BungeePluginMessageHandler(this);
|
||||
TAB.setInstance(new TAB(new BungeePlatform(this, plm), new BungeePacketBuilder(), ProtocolVersion.values()[1]));
|
||||
getProxy().getPluginManager().registerListener(this, new BungeeEventListener(plm));
|
||||
if (getProxy().getPluginManager().getPlugin("PremiumVanish") != null) getProxy().getPluginManager().registerListener(this, new PremiumVanishListener());
|
||||
getProxy().getPluginManager().registerCommand(this, new BTABCommand());
|
||||
plm = new BungeePluginMessageHandler(this);
|
||||
TAB.getInstance().load();
|
||||
Metrics metrics = new Metrics(this, 10535);
|
||||
metrics.addCustomChart(new SimplePie("permission_system", () -> TAB.getInstance().getPermissionPlugin().getName()));
|
||||
@@ -60,7 +57,7 @@ public class Main extends Plugin {
|
||||
public void onDisable() {
|
||||
if (TAB.getInstance() != null) TAB.getInstance().unload();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* TAB command for bungeecord
|
||||
*/
|
||||
@@ -77,18 +74,27 @@ public class Main extends Plugin {
|
||||
@Override
|
||||
public void execute(CommandSender sender, String[] args) {
|
||||
if (TAB.getInstance().isDisabled()) {
|
||||
for (String message : TAB.getInstance().disabledCommand.execute(args, sender.hasPermission("tab.reload"), sender.hasPermission("tab.admin"))) {
|
||||
for (String message : TAB.getInstance().getDisabledCommand().execute(args, sender.hasPermission("tab.reload"), sender.hasPermission("tab.admin"))) {
|
||||
sender.sendMessage(message.replace('&', '\u00a7'));
|
||||
}
|
||||
} else {
|
||||
TAB.getInstance().command.execute(sender instanceof ProxiedPlayer ? TAB.getInstance().getPlayer(((ProxiedPlayer)sender).getUniqueId()) : null, args);
|
||||
TabPlayer p = null;
|
||||
if (sender instanceof ProxiedPlayer) {
|
||||
p = TAB.getInstance().getPlayer(((ProxiedPlayer)sender).getUniqueId());
|
||||
if (p == null) return; //player not loaded correctly
|
||||
}
|
||||
TAB.getInstance().getCommand().execute(p, args);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterable<String> onTabComplete(CommandSender sender, String[] args) {
|
||||
if (TAB.getInstance().isDisabled()) return new ArrayList<String>();
|
||||
return TAB.getInstance().command.complete(sender instanceof ProxiedPlayer ? TAB.getInstance().getPlayer(((ProxiedPlayer)sender).getUniqueId()) : null, args);
|
||||
TabPlayer p = null;
|
||||
if (sender instanceof ProxiedPlayer) {
|
||||
p = TAB.getInstance().getPlayer(((ProxiedPlayer)sender).getUniqueId());
|
||||
if (p == null) return new ArrayList<>(); //player not loaded correctly
|
||||
}
|
||||
return TAB.getInstance().getCommand().complete(p, args);
|
||||
}
|
||||
}
|
||||
}
|
||||
+2
-2
@@ -28,9 +28,9 @@ public class PremiumVanishListener implements Listener {
|
||||
if (list == null) return;
|
||||
TabPlayer vanished = TAB.getInstance().getPlayer(e.getPlayer().getUniqueId());
|
||||
for (TabPlayer all : TAB.getInstance().getPlayers()) {
|
||||
boolean perm = all.hasPermission(list.PREMIUMVANISH_SEE_VANISHED_PERMISSION);
|
||||
boolean perm = all.hasPermission("tab.seevanished");
|
||||
if (all == vanished || perm) {
|
||||
if (perm && list.vanishedAsSpectators) {
|
||||
if (perm && list.isVanishedAsSpectators()) {
|
||||
all.sendCustomPacket(new PacketPlayOutPlayerInfo(EnumPlayerInfoAction.UPDATE_GAME_MODE, new PlayerInfoData(vanished.getUniqueId(), EnumGamemode.SPECTATOR)), TabFeature.GLOBAL_PLAYERLIST);
|
||||
}
|
||||
} else {
|
||||
@@ -0,0 +1,4 @@
|
||||
name: ${project.parent.name}
|
||||
main: me.neznamy.tab.platforms.bungeecord.Main
|
||||
version: ${project.parent.version}
|
||||
author: NEZNAMY
|
||||
+217
-207
@@ -1,207 +1,217 @@
|
||||
# Detailed explanation of all options available at https://github.com/NEZNAMY/TAB/wiki/config.yml
|
||||
|
||||
#changing nametags, affecting sorting, collision rule
|
||||
change-nametag-prefix-suffix: true
|
||||
|
||||
#prefix/suffix in tablist
|
||||
change-tablist-prefix-suffix: true
|
||||
|
||||
#header/footer
|
||||
enable-header-footer: true
|
||||
|
||||
global-playerlist:
|
||||
enabled: false
|
||||
display-others-as-spectators: false
|
||||
display-vanished-players-as-spectators: true
|
||||
isolate-unlisted-servers: false
|
||||
spy-servers:
|
||||
- spyserver1
|
||||
- spyserver2
|
||||
server-groups:
|
||||
lobbies:
|
||||
- lobby1
|
||||
- lobby2
|
||||
group2:
|
||||
- server1
|
||||
- server2
|
||||
|
||||
header:
|
||||
- "&3&lServer name"
|
||||
- "&6&lRank: %rank%"
|
||||
- "&7&l>> %animation:Welcome%&3 &l%player%&7&l! &7&l<<"
|
||||
- "&7Online players: &f%online%"
|
||||
- "&6Online staff: &e%staffonline%"
|
||||
- ""
|
||||
- "&7&l Used memory: %memory-used% MB / %memory-max% MB"
|
||||
- "%animation:MyAnimation1%"
|
||||
footer:
|
||||
- "%animation:MyAnimation1%"
|
||||
- "%animation:time%"
|
||||
- ""
|
||||
- "&7Visit our webpage %animation:web%"
|
||||
|
||||
#supports any numeric placeholder, set to "" to disable the feature
|
||||
yellow-number-in-tablist: "%ping%"
|
||||
|
||||
#literally what it says
|
||||
group-sorting-priority-list:
|
||||
- owner
|
||||
- admin
|
||||
- mod
|
||||
- helper
|
||||
- builder
|
||||
- premium
|
||||
- player
|
||||
- default
|
||||
|
||||
Groups:
|
||||
Owner:
|
||||
tabprefix: "&0&l[&a&lOwner&0&l] &a"
|
||||
tagprefix: "&2&lOwner &a"
|
||||
Admin:
|
||||
tabprefix: "&0&l[&4&lAdmin&0&l] &1"
|
||||
tagprefix: "%animation:admin_prefix%"
|
||||
Player:
|
||||
tabprefix: "&0&l[&7&lPlayer&0&l] &3"
|
||||
tagprefix: "&2&lPlayer &3"
|
||||
example_group:
|
||||
header:
|
||||
- "This is an example of per-group header/footer"
|
||||
footer:
|
||||
- "applied to a group"
|
||||
|
||||
#default settings for all groups, all groups will take properties from this section unless player's primary group overrides a specific setting
|
||||
_OTHER_:
|
||||
tabprefix: "%rank% "
|
||||
tagprefix: "%rank% "
|
||||
|
||||
Users:
|
||||
_NEZNAMY_:
|
||||
tabprefix: "&6&lTAB Author &a"
|
||||
tagprefix: "&6&lTAB &r&a"
|
||||
|
||||
#additional very limited line of text below nametag
|
||||
#don't forget this enables on all player entities, which includes NPCs
|
||||
#tags so you can find this section using the mighty ctrl + f feature: [NPC, Citizens, below_name, health]
|
||||
classic-vanilla-belowname:
|
||||
|
||||
#enabling the feature
|
||||
enabled: true
|
||||
|
||||
#number or numeric placeholder, supports per-player placeholders
|
||||
number: "%ping%"
|
||||
|
||||
#text after number, must be same on all players
|
||||
text: "Ping"
|
||||
|
||||
#controlling the collision rule
|
||||
enable-collision: true
|
||||
|
||||
#using the opposite of the setting above for worlds
|
||||
revert-collision-rule-in-worlds:
|
||||
- revertedworld
|
||||
|
||||
#preventing players with spectator gamemode from being moved to the bottom of tablist with transparent name
|
||||
do-not-move-spectators: false
|
||||
|
||||
#allows players with tab.spectatorbypass permission to see spectators moved despite the option above enabled
|
||||
allow-spectator-bypass-permission: false
|
||||
|
||||
per-server-settings:
|
||||
server1:
|
||||
header:
|
||||
- "an example of world with custom"
|
||||
footer:
|
||||
- "header/footer and prefix/suffix"
|
||||
Groups:
|
||||
Owner:
|
||||
tabprefix: "&0&l[&a&lOwner&0&l] &a"
|
||||
tagprefix: "&2&lOwner &a"
|
||||
server2-server3:
|
||||
header:
|
||||
- "This is a shared header for"
|
||||
- "server2 and server3"
|
||||
placeholders:
|
||||
#%date%
|
||||
date-format: "dd.MM.yyyy"
|
||||
|
||||
#%time%
|
||||
time-format: "[HH:mm:ss / h:mm a]"
|
||||
|
||||
#in hours, in case of wrong timezone
|
||||
time-offset: 0
|
||||
|
||||
#don't forget color codes
|
||||
remove-strings:
|
||||
- "[]"
|
||||
- "< >"
|
||||
|
||||
#aliases for %server%
|
||||
server-aliases:
|
||||
hub: "&eHub"
|
||||
survival: "&bSurvival"
|
||||
plot: "&cPlot"
|
||||
|
||||
#aliases for %rank%, this is not the place where group prefix is defined!
|
||||
rank-aliases:
|
||||
Admin: "&4&lADMIN"
|
||||
Mod: "&b&lMOD"
|
||||
Premium: "&6&lPREMIUM"
|
||||
Ultra: "&b&lULTRA"
|
||||
Legend: "&a&lLEGEND"
|
||||
Titan: "&c&lTITAN"
|
||||
Youtuber: "&c&lYOUTUBE"
|
||||
_OTHER_: "&7No Rank"
|
||||
|
||||
disable-features-in-servers:
|
||||
header-footer:
|
||||
- disabledserver
|
||||
tablist-names:
|
||||
- disabledserver
|
||||
nametag:
|
||||
- disabledserver
|
||||
yellow-number:
|
||||
- disabledserver
|
||||
bossbar:
|
||||
- disabledserver
|
||||
belowname:
|
||||
- disabledserver
|
||||
|
||||
placeholderapi-refresh-intervals:
|
||||
default-refresh-interval: 100
|
||||
server:
|
||||
"%server_uptime%": 1000
|
||||
"%server_tps_1_colored%": 1000
|
||||
player:
|
||||
"%player_health%": 200
|
||||
"%player_ping%": 1000
|
||||
"%vault_prefix%": 1000
|
||||
relational:
|
||||
"%rel_factionsuuid_relation_color%": 500
|
||||
|
||||
|
||||
#permission node is tab.sort.<permission group from sorting list>
|
||||
sort-players-by-permissions: false
|
||||
|
||||
#taking primary group from permission plugin
|
||||
use-primary-group: true
|
||||
|
||||
#if the option above is false, all groups are taken from permission plugin and the one higher in this list is used as primary
|
||||
primary-group-finding-list:
|
||||
- Owner
|
||||
- Admin
|
||||
- Helper
|
||||
- default
|
||||
|
||||
#if none of the above fits your needs, you can enable this to give groups using tab.group.<group name from the list above> permission
|
||||
assign-groups-by-permissions: false
|
||||
|
||||
#preventing other plugins from overriding TAB
|
||||
anti-override:
|
||||
scoreboard-teams: true
|
||||
scoreboard-objectives: true
|
||||
tablist-names: true
|
||||
usernames: true
|
||||
|
||||
#permanently invisible nametags
|
||||
invisible-nametags: false
|
||||
# Detailed explanation of all options available at https://github.com/NEZNAMY/TAB/wiki/config.yml
|
||||
|
||||
#taking permission nodes and groups from backend servers
|
||||
use-bukkit-permissions-manager: false
|
||||
|
||||
#changing nametags, affecting sorting, collision rule
|
||||
change-nametag-prefix-suffix: true
|
||||
|
||||
#prefix/suffix in tablist
|
||||
change-tablist-prefix-suffix: true
|
||||
|
||||
#header/footer
|
||||
enable-header-footer: true
|
||||
|
||||
global-playerlist:
|
||||
enabled: false
|
||||
display-others-as-spectators: false
|
||||
display-vanished-players-as-spectators: true
|
||||
isolate-unlisted-servers: false
|
||||
spy-servers:
|
||||
- spyserver1
|
||||
- spyserver2
|
||||
server-groups:
|
||||
lobbies:
|
||||
- lobby1
|
||||
- lobby2
|
||||
group2:
|
||||
- server1
|
||||
- server2
|
||||
|
||||
header:
|
||||
- "&3&lServer name"
|
||||
- "&6&lRank: %rank%"
|
||||
- "&7&l>> %animation:Welcome%&3 &l%player%&7&l! &7&l<<"
|
||||
- "&7Online players: &f%online%"
|
||||
- "&6Online staff: &e%staffonline%"
|
||||
- ""
|
||||
- "&7&l Used memory: %memory-used% MB / %memory-max% MB"
|
||||
- "%animation:MyAnimation1%"
|
||||
footer:
|
||||
- "%animation:MyAnimation1%"
|
||||
- "%animation:time%"
|
||||
- ""
|
||||
- "&7Visit our webpage %animation:web%"
|
||||
|
||||
#supports any numeric placeholder, set to "" to disable the feature
|
||||
yellow-number-in-tablist: "%ping%"
|
||||
|
||||
group-sorting-priority-list:
|
||||
- owner
|
||||
- admin
|
||||
- mod
|
||||
- helper
|
||||
- builder
|
||||
- premium
|
||||
- player
|
||||
- default
|
||||
|
||||
Groups:
|
||||
Owner:
|
||||
tabprefix: "&0&l[&a&lOwner&0&l] &a"
|
||||
tagprefix: "&2&lOwner &a"
|
||||
Admin:
|
||||
tabprefix: "&0&l[&4&lAdmin&0&l] &1"
|
||||
tagprefix: "%animation:admin_prefix%"
|
||||
Player:
|
||||
tabprefix: "&0&l[&7&lPlayer&0&l] &3"
|
||||
tagprefix: "&2&lPlayer &3"
|
||||
example_group:
|
||||
header:
|
||||
- "This is an example of per-group header/footer"
|
||||
footer:
|
||||
- "applied to a group"
|
||||
|
||||
#default settings for all groups, all groups will take properties from this section unless player's primary group overrides a specific setting
|
||||
_OTHER_:
|
||||
tabprefix: "%rank% "
|
||||
tagprefix: "%rank% "
|
||||
|
||||
Users:
|
||||
_NEZNAMY_:
|
||||
tabprefix: "&6&lTAB Author &a"
|
||||
tagprefix: "&6&lTAB &r&a"
|
||||
|
||||
#additional very limited line of text below nametag
|
||||
#don't forget this enables on all player entities, which includes NPCs
|
||||
#tags so you can find this section using the mighty ctrl + f feature: [NPC, Citizens, below_name, health]
|
||||
classic-vanilla-belowname:
|
||||
|
||||
#enabling the feature
|
||||
enabled: true
|
||||
|
||||
#number or numeric placeholder, supports per-player placeholders
|
||||
number: "%ping%"
|
||||
|
||||
#text after number, must be same on all players
|
||||
text: "Ping"
|
||||
|
||||
#controlling the collision rule
|
||||
enable-collision: true
|
||||
|
||||
#using the opposite of the setting above for servers
|
||||
revert-collision-rule-in-servers:
|
||||
- revertedserver
|
||||
|
||||
#preventing players with spectator gamemode from being moved to the bottom of tablist with transparent name
|
||||
do-not-move-spectators: false
|
||||
|
||||
#allows players with tab.spectatorbypass permission to see spectators moved despite the option above enabled
|
||||
allow-spectator-bypass-permission: false
|
||||
|
||||
per-server-settings:
|
||||
server1:
|
||||
header:
|
||||
- "an example of world with custom"
|
||||
footer:
|
||||
- "header/footer and prefix/suffix"
|
||||
Groups:
|
||||
Owner:
|
||||
tabprefix: "&0&l[&a&lOwner&0&l] &a"
|
||||
tagprefix: "&2&lOwner &a"
|
||||
server2-server3:
|
||||
header:
|
||||
- "This is a shared header for"
|
||||
- "server2 and server3"
|
||||
placeholders:
|
||||
#%date%
|
||||
date-format: "dd.MM.yyyy"
|
||||
|
||||
#%time%
|
||||
time-format: "[HH:mm:ss / h:mm a]"
|
||||
|
||||
#in hours, in case of wrong timezone
|
||||
time-offset: 0
|
||||
|
||||
#don't forget color codes
|
||||
remove-strings:
|
||||
- "[]"
|
||||
- "< >"
|
||||
|
||||
#aliases for %server%
|
||||
server-aliases:
|
||||
hub: "&eHub"
|
||||
survival: "&bSurvival"
|
||||
plot: "&cPlot"
|
||||
|
||||
#aliases for %rank%, this is not the place where group prefix is defined!
|
||||
rank-aliases:
|
||||
Admin: "&4&lADMIN"
|
||||
Mod: "&b&lMOD"
|
||||
Premium: "&6&lPREMIUM"
|
||||
Ultra: "&b&lULTRA"
|
||||
Legend: "&a&lLEGEND"
|
||||
Titan: "&c&lTITAN"
|
||||
Youtuber: "&c&lYOUTUBE"
|
||||
_OTHER_: "&7No Rank"
|
||||
|
||||
disable-features-in-servers:
|
||||
header-footer:
|
||||
- disabledserver
|
||||
tablist-names:
|
||||
- disabledserver
|
||||
nametag:
|
||||
- disabledserver
|
||||
yellow-number:
|
||||
- disabledserver
|
||||
bossbar:
|
||||
- disabledserver
|
||||
belowname:
|
||||
- disabledserver
|
||||
|
||||
placeholderapi-refresh-intervals:
|
||||
default-refresh-interval: 500
|
||||
server:
|
||||
"%server_uptime%": 1000
|
||||
"%server_tps_1_colored%": 1000
|
||||
player:
|
||||
"%player_health%": 200
|
||||
"%player_ping%": 1000
|
||||
"%vault_prefix%": 1000
|
||||
relational:
|
||||
"%rel_factionsuuid_relation_color%": 500
|
||||
|
||||
|
||||
#permission node is tab.sort.<permission group from sorting list>
|
||||
sort-players-by-permissions: false
|
||||
|
||||
#taking primary group from permission plugin
|
||||
use-primary-group: true
|
||||
|
||||
#if the option above is false, all groups are taken from permission plugin and the one higher in this list is used as primary
|
||||
primary-group-finding-list:
|
||||
- Owner
|
||||
- Admin
|
||||
- Helper
|
||||
- default
|
||||
|
||||
#if none of the above fits your needs, you can enable this to give groups using tab.group.<group name from the list above> permission
|
||||
assign-groups-by-permissions: false
|
||||
|
||||
#preventing other plugins from overriding TAB
|
||||
anti-override:
|
||||
scoreboard-teams: true
|
||||
scoreboard-objectives: true
|
||||
tablist-names: true
|
||||
usernames: true
|
||||
|
||||
#permanently invisible nametags
|
||||
invisible-nametags: false
|
||||
|
||||
#faking ping of players
|
||||
ping-spoof:
|
||||
enabled: false
|
||||
value: 0
|
||||
|
||||
#unlocks extra console messages
|
||||
debug: false
|
||||
+92
@@ -0,0 +1,92 @@
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>me.neznamy</groupId>
|
||||
<artifactId>TAB</artifactId>
|
||||
<version>2.9.2</version>
|
||||
</parent>
|
||||
<artifactId>jar</artifactId>
|
||||
<build>
|
||||
<finalName>TAB-${project.version}</finalName>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-shade-plugin</artifactId>
|
||||
<version>3.2.2</version>
|
||||
<configuration>
|
||||
<createDependencyReducedPom>false</createDependencyReducedPom>
|
||||
<artifactSet>
|
||||
<includes>
|
||||
<include>com.googlecode.json-simple:json-simple</include>
|
||||
<include>com.github.NEZNAMY:YamlAssist</include>
|
||||
<include>org.bstats:*</include>
|
||||
<include>me.neznamy:*</include>
|
||||
</includes>
|
||||
</artifactSet>
|
||||
<relocations>
|
||||
<relocation>
|
||||
<pattern>org.bstats</pattern>
|
||||
<shadedPattern>me.neznamy.tab.libs.org.bstats</shadedPattern>
|
||||
</relocation>
|
||||
<relocation>
|
||||
<pattern>org.json.simple</pattern>
|
||||
<shadedPattern>me.neznamy.tab.libs.org.json.simple</shadedPattern>
|
||||
</relocation>
|
||||
</relocations>
|
||||
</configuration>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>package</phase>
|
||||
<goals>
|
||||
<goal>shade</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>me.neznamy</groupId>
|
||||
<artifactId>bukkit</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>me.neznamy</groupId>
|
||||
<artifactId>bungeecord</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>me.neznamy</groupId>
|
||||
<artifactId>shared</artifactId>
|
||||
<version>${project.version}</version>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>com.google.guava</groupId>
|
||||
<artifactId>guava</artifactId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<groupId>io.netty</groupId>
|
||||
<artifactId>netty-all</artifactId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<groupId>org.yaml</groupId>
|
||||
<artifactId>snakeyaml</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>me.neznamy</groupId>
|
||||
<artifactId>velocity-1.1.0</artifactId>
|
||||
<version>${project.version}</version>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>com.google.code.gson</groupId>
|
||||
<artifactId>gson</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
@@ -1,13 +1,29 @@
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>me.neznamy</groupId>
|
||||
<artifactId>TAB</artifactId>
|
||||
<version>2.8.11-pre13</version>
|
||||
<name>TAB</name>
|
||||
<version>2.9.2</version>
|
||||
<packaging>pom</packaging>
|
||||
<description>An all-in-one solution that works</description>
|
||||
|
||||
<modules>
|
||||
<module>shared</module>
|
||||
<module>bukkit</module>
|
||||
<module>bungeecord</module>
|
||||
<module>velocity-1.1.0</module>
|
||||
<module>jar</module>
|
||||
</modules>
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<project.build.outputEncoding>UTF-8</project.build.outputEncoding>
|
||||
<maven.compiler.source>1.8</maven.compiler.source>
|
||||
<maven.compiler.target>1.8</maven.compiler.target>
|
||||
<sonar.projectKey>NEZNAMY_TAB</sonar.projectKey>
|
||||
<sonar.moduleKey>${project.artifactId}</sonar.moduleKey>
|
||||
<sonar.organization>neznamy</sonar.organization>
|
||||
<sonar.host.url>https://sonarcloud.io</sonar.host.url>
|
||||
</properties>
|
||||
<build>
|
||||
<resources>
|
||||
<resource>
|
||||
@@ -15,431 +31,5 @@
|
||||
<filtering>true</filtering>
|
||||
</resource>
|
||||
</resources>
|
||||
|
||||
<plugins>
|
||||
<plugin>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>3.8.1</version>
|
||||
<configuration>
|
||||
<source>1.8</source>
|
||||
<target>1.8</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-shade-plugin</artifactId>
|
||||
<version>3.2.3</version>
|
||||
<configuration>
|
||||
|
||||
<createDependencyReducedPom>false</createDependencyReducedPom>
|
||||
|
||||
<artifactSet>
|
||||
<includes>
|
||||
<include>com.googlecode.json-simple:json-simple</include>
|
||||
<include>com.github.NEZNAMY:YamlAssist</include>
|
||||
<include>com.github.NEZNAMY:VelocityPacketInjector</include>
|
||||
<include>org.bstats:bstats-base</include>
|
||||
<include>org.bstats:bstats-bungeecord</include>
|
||||
<include>org.bstats:bstats-velocity</include>
|
||||
|
||||
</includes>
|
||||
</artifactSet>
|
||||
|
||||
<relocations>
|
||||
<relocation>
|
||||
<pattern>org.bstats</pattern>
|
||||
<shadedPattern>me.neznamy.tab.platforms</shadedPattern>
|
||||
</relocation>
|
||||
</relocations>
|
||||
|
||||
</configuration>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>package</phase>
|
||||
<goals>
|
||||
<goal>shade</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
|
||||
<repositories>
|
||||
|
||||
<!-- Spigot API -->
|
||||
<repository>
|
||||
<id>spigot-repo</id>
|
||||
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
|
||||
</repository>
|
||||
|
||||
<!-- PlaceholderAPI -->
|
||||
<repository>
|
||||
<id>placeholderapi</id>
|
||||
<url>https://repo.extendedclip.com/content/repositories/placeholderapi/</url>
|
||||
</repository>
|
||||
|
||||
<!-- Vault -->
|
||||
<!-- PremiumVanishAPI -->
|
||||
<repository>
|
||||
<id>jitpack.io</id>
|
||||
<url>https://jitpack.io</url>
|
||||
</repository>
|
||||
|
||||
<!-- LuckPerms5 -->
|
||||
<!-- BungeeCord -->
|
||||
<repository>
|
||||
<id>luck-repo</id>
|
||||
<url>https://ci.lucko.me/plugin/repository/everything/</url>
|
||||
</repository>
|
||||
|
||||
<!-- ViaVersion -->
|
||||
<repository>
|
||||
<id>viaversion</id>
|
||||
<url>https://repo.viaversion.com/</url>
|
||||
</repository>
|
||||
|
||||
<repository>
|
||||
<id>velocity</id>
|
||||
<url>https://nexus.velocitypowered.com/repository/maven-public/</url>
|
||||
</repository>
|
||||
|
||||
</repositories>
|
||||
|
||||
<dependencies>
|
||||
|
||||
<!-- Spigot API -->
|
||||
<dependency>
|
||||
<groupId>org.spigotmc</groupId>
|
||||
<artifactId>spigot-api</artifactId>
|
||||
<version>1.16.5-R0.1-SNAPSHOT</version>
|
||||
<scope>provided</scope>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>commons-lang</groupId>
|
||||
<artifactId>commons-lang</artifactId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<groupId>com.google.guava</groupId>
|
||||
<artifactId>guava</artifactId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<groupId>net.md-5</groupId>
|
||||
<artifactId>bungeecord-chat</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
|
||||
<!-- json-simple, shaded -->
|
||||
<dependency>
|
||||
<groupId>com.googlecode.json-simple</groupId>
|
||||
<artifactId>json-simple</artifactId>
|
||||
<version>1.1.1</version>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
|
||||
<!-- BungeeCord -->
|
||||
<!-- com.google.common.io -->
|
||||
<dependency>
|
||||
<groupId>net.md-5</groupId>
|
||||
<artifactId>bungeecord-proxy</artifactId>
|
||||
<version>1.16-R0.5-SNAPSHOT</version>
|
||||
<scope>provided</scope>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>io.netty</groupId>
|
||||
<artifactId>netty-codec-haproxy</artifactId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<groupId>io.netty</groupId>
|
||||
<artifactId>netty-codec-http</artifactId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<groupId>io.netty</groupId>
|
||||
<artifactId>netty-handler</artifactId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<groupId>io.netty</groupId>
|
||||
<artifactId>netty-transport-native-epoll</artifactId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<groupId>io.netty</groupId>
|
||||
<artifactId>netty-transport-native-unix-common</artifactId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<groupId>net.md-5</groupId>
|
||||
<artifactId>brigadier</artifactId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<groupId>jline</groupId>
|
||||
<artifactId>jline</artifactId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<groupId>io.netty</groupId>
|
||||
<artifactId>netty-transport</artifactId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<groupId>io.netty</groupId>
|
||||
<artifactId>netty-codec</artifactId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<groupId>net.sf.trove4j</groupId>
|
||||
<artifactId>core</artifactId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<groupId>net.md-5</groupId>
|
||||
<artifactId>bungeecord-query</artifactId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<groupId>se.llbit</groupId>
|
||||
<artifactId>jo-nbt</artifactId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<groupId>net.sf.jopt-simple</groupId>
|
||||
<artifactId>jopt-simple</artifactId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<groupId>mysql</groupId>
|
||||
<artifactId>mysql-connector-java</artifactId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<groupId>com.google.code.gson</groupId>
|
||||
<artifactId>gson</artifactId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<groupId>com.google.guava</groupId>
|
||||
<artifactId>guava</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
|
||||
<!-- PlaceholderAPI -->
|
||||
<dependency>
|
||||
<groupId>me.clip</groupId>
|
||||
<artifactId>placeholderapi</artifactId>
|
||||
<version>2.10.9</version>
|
||||
<scope>provided</scope>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>org.jetbrains</groupId>
|
||||
<artifactId>annotations</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
|
||||
<!-- Vault -->
|
||||
<dependency>
|
||||
<groupId>com.github.MilkBowl</groupId>
|
||||
<artifactId>VaultAPI</artifactId>
|
||||
<version>1.7</version>
|
||||
<scope>provided</scope>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>commons-lang</groupId>
|
||||
<artifactId>commons-lang</artifactId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<groupId>com.google.guava</groupId>
|
||||
<artifactId>guava</artifactId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<groupId>com.google.code.gson</groupId>
|
||||
<artifactId>gson</artifactId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<groupId>org.bukkit</groupId>
|
||||
<artifactId>bukkit</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
|
||||
<!-- LuckPerms5 -->
|
||||
<dependency>
|
||||
<groupId>net.luckperms</groupId>
|
||||
<artifactId>api</artifactId>
|
||||
<version>5.2</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
<!-- ViaVersion -->
|
||||
<dependency>
|
||||
<groupId>us.myles</groupId>
|
||||
<artifactId>viaversion</artifactId>
|
||||
<version>3.2.0</version>
|
||||
<scope>provided</scope>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>us.myles</groupId>
|
||||
<artifactId>viaversion-common</artifactId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<groupId>us.myles</groupId>
|
||||
<artifactId>viaversion-bukkit</artifactId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<groupId>us.myles</groupId>
|
||||
<artifactId>viaversion-bungee</artifactId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<groupId>us.myles</groupId>
|
||||
<artifactId>viaversion-fabric</artifactId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<groupId>us.myles</groupId>
|
||||
<artifactId>viaversion-sponge</artifactId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<groupId>us.myles</groupId>
|
||||
<artifactId>viaversion-velocity</artifactId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<groupId>net.md-5</groupId>
|
||||
<artifactId>bungeecord-chat</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
|
||||
<!-- PremiumVanishAPI -->
|
||||
<dependency>
|
||||
<groupId>com.github.MyzelYam</groupId>
|
||||
<artifactId>PremiumVanishAPI</artifactId>
|
||||
<version>2.0.3</version>
|
||||
<scope>provided</scope>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>com.google.code.findbugs</groupId>
|
||||
<artifactId>jsr305</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
|
||||
<!-- YamlAssist -->
|
||||
<dependency>
|
||||
<groupId>com.github.NEZNAMY</groupId>
|
||||
<artifactId>YamlAssist</artifactId>
|
||||
<version>1.0.3</version>
|
||||
</dependency>
|
||||
|
||||
<!-- Velocity API -->
|
||||
<dependency>
|
||||
<groupId>com.velocitypowered</groupId>
|
||||
<artifactId>velocity-api</artifactId>
|
||||
<version>1.1.0</version>
|
||||
<scope>provided</scope>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>com.moandjiezana.toml</groupId>
|
||||
<artifactId>toml4j</artifactId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<groupId>org.checkerframework</groupId>
|
||||
<artifactId>checker-qual</artifactId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<groupId>org.spongepowered</groupId>
|
||||
<artifactId>configurate-gson</artifactId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<groupId>org.spongepowered</groupId>
|
||||
<artifactId>configurate-hocon</artifactId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<groupId>com.mojang</groupId>
|
||||
<artifactId>brigadier</artifactId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<groupId>org.spongepowered</groupId>
|
||||
<artifactId>configurate-yaml</artifactId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<groupId>com.google.code.gson</groupId>
|
||||
<artifactId>gson</artifactId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<groupId>net.kyori</groupId>
|
||||
<artifactId>
|
||||
adventure-text-serializer-legacy-text3
|
||||
</artifactId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<groupId>net.kyori</groupId>
|
||||
<artifactId>
|
||||
adventure-text-serializer-legacy
|
||||
</artifactId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<groupId>net.kyori</groupId>
|
||||
<artifactId>
|
||||
adventure-text-serializer-plain
|
||||
</artifactId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<groupId>net.kyori</groupId>
|
||||
<artifactId>text-serializer-plain</artifactId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<groupId>org.codehaus.mojo</groupId>
|
||||
<artifactId>animal-sniffer-annotations</artifactId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<groupId>com.google.j2objc</groupId>
|
||||
<artifactId>j2objc-annotations</artifactId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<groupId>com.google.code.findbugs</groupId>
|
||||
<artifactId>jsr305</artifactId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<groupId>com.google.errorprone</groupId>
|
||||
<artifactId>error_prone_annotations</artifactId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<groupId>net.kyori</groupId>
|
||||
<artifactId>text-serializer-legacy</artifactId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<groupId>net.kyori</groupId>
|
||||
<artifactId>text-serializer-gson</artifactId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<groupId>net.kyori</groupId>
|
||||
<artifactId>examination-string</artifactId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<groupId>aopalliance</groupId>
|
||||
<artifactId>aopalliance</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
|
||||
<!-- Bungee Metrics -->
|
||||
<dependency>
|
||||
<groupId>org.bstats</groupId>
|
||||
<artifactId>bstats-bungeecord</artifactId>
|
||||
<version>2.2.1</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
|
||||
<!-- Velocity Metrics -->
|
||||
<dependency>
|
||||
<groupId>org.bstats</groupId>
|
||||
<artifactId>bstats-velocity</artifactId>
|
||||
<version>2.2.1</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
|
||||
<!-- Missing velocity packets -->
|
||||
<dependency>
|
||||
<groupId>com.github.NEZNAMY</groupId>
|
||||
<artifactId>VelocityPacketInjector</artifactId>
|
||||
<version>1.0.0_fix</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
+121
@@ -0,0 +1,121 @@
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>me.neznamy</groupId>
|
||||
<artifactId>TAB</artifactId>
|
||||
<version>2.9.2</version>
|
||||
</parent>
|
||||
<artifactId>shared</artifactId>
|
||||
|
||||
<repositories>
|
||||
|
||||
<!-- LuckPerms5 -->
|
||||
<repository>
|
||||
<id>luck-repo</id>
|
||||
<url>https://ci.lucko.me/plugin/repository/everything/</url>
|
||||
</repository>
|
||||
|
||||
<!-- YamlAssist -->
|
||||
<repository>
|
||||
<id>jitpack.io</id>
|
||||
<url>https://jitpack.io</url>
|
||||
</repository>
|
||||
|
||||
<repository>
|
||||
<id>spigot-repo</id>
|
||||
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
|
||||
</repository>
|
||||
|
||||
</repositories>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>io.netty</groupId>
|
||||
<artifactId>netty-all</artifactId>
|
||||
<version>4.1.63.Final</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.spigotmc</groupId>
|
||||
<artifactId>spigot-api</artifactId>
|
||||
<version>1.17-R0.1-SNAPSHOT</version>
|
||||
<scope>provided</scope>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>commons-lang</groupId>
|
||||
<artifactId>commons-lang</artifactId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<groupId>net.md-5</groupId>
|
||||
<artifactId>bungeecord-chat</artifactId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<groupId>com.google.code.gson</groupId>
|
||||
<artifactId>gson</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>net.md-5</groupId>
|
||||
<artifactId>bungeecord-api</artifactId>
|
||||
<version>1.17-R0.1-SNAPSHOT</version>
|
||||
<scope>provided</scope>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>net.md-5</groupId>
|
||||
<artifactId>bungeecord-config</artifactId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<groupId>io.netty</groupId>
|
||||
<artifactId>
|
||||
netty-transport-native-unix-common
|
||||
</artifactId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<groupId>net.md-5</groupId>
|
||||
<artifactId>bungeecord-protocol</artifactId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<groupId>net.md-5</groupId>
|
||||
<artifactId>bungeecord-event</artifactId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<groupId>net.md-5</groupId>
|
||||
<artifactId>bungeecord-chat</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
|
||||
<!-- json-simple, shaded -->
|
||||
<dependency>
|
||||
<groupId>com.googlecode.json-simple</groupId>
|
||||
<artifactId>json-simple</artifactId>
|
||||
<version>1.1.1</version>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
|
||||
<!-- LuckPerms5 -->
|
||||
<dependency>
|
||||
<groupId>net.luckperms</groupId>
|
||||
<artifactId>api</artifactId>
|
||||
<version>5.2</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
<!-- YamlAssist -->
|
||||
<dependency>
|
||||
<groupId>com.github.NEZNAMY</groupId>
|
||||
<artifactId>YamlAssist</artifactId>
|
||||
<version>1.0.4</version>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
</project>
|
||||
File renamed without changes.
+45
-23
@@ -1,7 +1,7 @@
|
||||
package me.neznamy.tab.api;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
@@ -12,8 +12,8 @@ import java.util.Set;
|
||||
*/
|
||||
public class ArmorStandManager {
|
||||
|
||||
//list of registered armor stands
|
||||
private Map<String, ArmorStand> armorStands = new LinkedHashMap<String, ArmorStand>();
|
||||
//map of registered armor stands
|
||||
private Map<String, ArmorStand> armorStands = Collections.synchronizedMap(new LinkedHashMap<String, ArmorStand>());
|
||||
|
||||
/**
|
||||
* Adds armor stand into list
|
||||
@@ -23,7 +23,7 @@ public class ArmorStandManager {
|
||||
public void addArmorStand(String name, ArmorStand as) {
|
||||
armorStands.put(name, as);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Removes armor stand from list. It is not automatically destroyed for players
|
||||
* @param name - name of armor stand to remove
|
||||
@@ -31,14 +31,16 @@ public class ArmorStandManager {
|
||||
public void removeArmorStand(String name) {
|
||||
armorStands.remove(name);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Spawns all armor stands for specified viewer and adds them into nearby players
|
||||
* @param viewer - player to spawn armor stands for
|
||||
*/
|
||||
public void spawn(TabPlayer viewer) {
|
||||
if (viewer.getVersion().getMinorVersion() < 8) return;
|
||||
getArmorStands().forEach(a -> a.spawn(viewer));
|
||||
synchronized (armorStands) {
|
||||
armorStands.values().forEach(a -> a.spawn(viewer));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -46,14 +48,18 @@ public class ArmorStandManager {
|
||||
* @param sneaking - new sneaking status
|
||||
*/
|
||||
public void sneak(boolean sneaking) {
|
||||
getArmorStands().forEach(a -> a.sneak(sneaking));
|
||||
synchronized (armorStands) {
|
||||
armorStands.values().forEach(a -> a.sneak(sneaking));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Teleports armor stands to player's current location for all nearby players
|
||||
*/
|
||||
public void teleport() {
|
||||
getArmorStands().forEach(a -> a.teleport());
|
||||
synchronized (armorStands) {
|
||||
armorStands.values().forEach(ArmorStand::teleport);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -61,14 +67,18 @@ public class ArmorStandManager {
|
||||
* @param viewer - player to teleport armor stands for
|
||||
*/
|
||||
public void teleport(TabPlayer viewer) {
|
||||
getArmorStands().forEach(a -> a.teleport(viewer));
|
||||
synchronized (armorStands) {
|
||||
armorStands.values().forEach(a -> a.teleport(viewer));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Refreshes name of all armor stands for all nearby players
|
||||
*/
|
||||
public void refresh() {
|
||||
getArmorStands().forEach(a -> a.refresh());
|
||||
synchronized (armorStands) {
|
||||
armorStands.values().forEach(ArmorStand::refresh);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -76,7 +86,9 @@ public class ArmorStandManager {
|
||||
* @param force - true if packets should be sent despite seemingly not needed
|
||||
*/
|
||||
public void updateVisibility(boolean force) {
|
||||
getArmorStands().forEach(a -> a.updateVisibility(force));
|
||||
synchronized (armorStands) {
|
||||
armorStands.values().forEach(a -> a.updateVisibility(force));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -84,14 +96,18 @@ public class ArmorStandManager {
|
||||
* @param viewer - player to remove
|
||||
*/
|
||||
public void unregisterPlayer(TabPlayer viewer) {
|
||||
getArmorStands().forEach(a -> a.removeFromRegistered(viewer));
|
||||
synchronized (armorStands) {
|
||||
armorStands.values().forEach(a -> a.removeFromRegistered(viewer));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends destroy packet of all armor stands to everyone and clears nearby players list
|
||||
*/
|
||||
public void destroy() {
|
||||
getArmorStands().forEach(a -> a.destroy());
|
||||
synchronized (armorStands) {
|
||||
armorStands.values().forEach(ArmorStand::destroy);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -99,7 +115,9 @@ public class ArmorStandManager {
|
||||
* @param viewer - player to destroy armor stands for
|
||||
*/
|
||||
public void destroy(TabPlayer viewer) {
|
||||
getArmorStands().forEach(a -> a.destroy(viewer));
|
||||
synchronized (armorStands) {
|
||||
armorStands.values().forEach(a -> a.destroy(viewer));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -108,28 +126,32 @@ public class ArmorStandManager {
|
||||
* @return true if armor stand with specified entity id exists, false if not
|
||||
*/
|
||||
public boolean hasArmorStandWithID(int entityId) {
|
||||
for (ArmorStand as : getArmorStands()) {
|
||||
if (as.getEntityId() == entityId) {
|
||||
return true;
|
||||
synchronized (armorStands) {
|
||||
for (ArmorStand as : armorStands.values()) {
|
||||
if (as.getEntityId() == entityId) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns a copy of list of all registered armor stands
|
||||
* @return copy of armor stands
|
||||
*/
|
||||
public Collection<ArmorStand> getArmorStands(){
|
||||
return new ArrayList<>(armorStands.values());
|
||||
return armorStands.values();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns list of nearby players
|
||||
* @return list of nearby players
|
||||
*/
|
||||
public Set<TabPlayer> getNearbyPlayers(){
|
||||
if (armorStands.values().size() == 0) return new HashSet<>(); //not initialized yet
|
||||
return armorStands.values().iterator().next().getNearbyPlayers();
|
||||
if (armorStands.isEmpty()) return new HashSet<>(); //not initialized yet
|
||||
synchronized (armorStands) {
|
||||
return armorStands.values().iterator().next().getNearbyPlayers();
|
||||
}
|
||||
}
|
||||
}
|
||||
File renamed without changes.
File renamed without changes.
+26
-15
@@ -5,12 +5,15 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
|
||||
import me.neznamy.tab.api.bossbar.BarColor;
|
||||
import me.neznamy.tab.api.bossbar.BarStyle;
|
||||
import me.neznamy.tab.api.bossbar.BossBar;
|
||||
import me.neznamy.tab.shared.TAB;
|
||||
import me.neznamy.tab.shared.features.PlaceholderManager;
|
||||
import me.neznamy.tab.shared.features.bossbar.BossBarLine;
|
||||
import me.neznamy.tab.shared.features.scoreboard.ScoreboardImpl;
|
||||
import me.neznamy.tab.shared.features.scoreboard.ScoreboardManager;
|
||||
import me.neznamy.tab.shared.permission.PermissionPlugin;
|
||||
import me.neznamy.tab.shared.placeholders.Placeholder;
|
||||
@@ -25,7 +28,10 @@ import me.neznamy.tab.shared.placeholders.conditions.simple.SimpleCondition;
|
||||
public class TABAPI {
|
||||
|
||||
//placeholders registered via API
|
||||
public static Map<String, Placeholder> APIPlaceholders = new HashMap<String, Placeholder>();
|
||||
private static final Map<String, Placeholder> apiPlaceholders = new HashMap<>();
|
||||
|
||||
private TABAPI() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns player object from given UUID
|
||||
@@ -56,13 +62,12 @@ public class TABAPI {
|
||||
|
||||
/**
|
||||
* Enables unlimited nametag mode permanently in config
|
||||
* @throws IllegalStateException if called from a proxy
|
||||
* @see isUnlimitedNameTagModeEnabled
|
||||
*/
|
||||
public static void enableUnlimitedNameTagModePermanently() {
|
||||
if (isUnlimitedNameTagModeEnabled()) return;
|
||||
TAB.getInstance().getConfiguration().config.set("change-nametag-prefix-suffix", true);
|
||||
TAB.getInstance().getConfiguration().config.set("unlimited-nametag-prefix-suffix-mode.enabled", true);
|
||||
TAB.getInstance().getConfiguration().getConfig().set("change-nametag-prefix-suffix", true);
|
||||
TAB.getInstance().getConfiguration().getConfig().set("unlimited-nametag-prefix-suffix-mode.enabled", true);
|
||||
TAB.getInstance().unload();
|
||||
TAB.getInstance().load();
|
||||
}
|
||||
@@ -74,10 +79,12 @@ public class TABAPI {
|
||||
* @see registerServerConstant
|
||||
*/
|
||||
public static void registerPlayerPlaceholder(PlayerPlaceholder placeholder) {
|
||||
APIPlaceholders.put(placeholder.getIdentifier(), placeholder);
|
||||
Preconditions.checkNotNull(placeholder, "placeholder");
|
||||
apiPlaceholders.put(placeholder.getIdentifier(), placeholder);
|
||||
PlaceholderManager pl = TAB.getInstance().getPlaceholderManager();
|
||||
pl.registerPlaceholder(placeholder);
|
||||
pl.allUsedPlaceholderIdentifiers.add(placeholder.getIdentifier());
|
||||
pl.getAllUsedPlaceholderIdentifiers().add(placeholder.getIdentifier());
|
||||
pl.refreshPlaceholderUsage();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -87,10 +94,12 @@ public class TABAPI {
|
||||
* @see registerServerConstant
|
||||
*/
|
||||
public static void registerServerPlaceholder(ServerPlaceholder placeholder) {
|
||||
APIPlaceholders.put(placeholder.getIdentifier(), placeholder);
|
||||
Preconditions.checkNotNull(placeholder, "placeholder");
|
||||
apiPlaceholders.put(placeholder.getIdentifier(), placeholder);
|
||||
PlaceholderManager pl = TAB.getInstance().getPlaceholderManager();
|
||||
pl.registerPlaceholder(placeholder);
|
||||
pl.allUsedPlaceholderIdentifiers.add(placeholder.getIdentifier());
|
||||
pl.getAllUsedPlaceholderIdentifiers().add(placeholder.getIdentifier());
|
||||
pl.refreshPlaceholderUsage();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -98,10 +107,12 @@ public class TABAPI {
|
||||
* @param placeholder - Placeholder handler
|
||||
*/
|
||||
public static void registerRelationalPlaceholder(RelationalPlaceholder placeholder) {
|
||||
APIPlaceholders.put(placeholder.getIdentifier(), placeholder);
|
||||
Preconditions.checkNotNull(placeholder, "placeholder");
|
||||
apiPlaceholders.put(placeholder.getIdentifier(), placeholder);
|
||||
PlaceholderManager pl = TAB.getInstance().getPlaceholderManager();
|
||||
pl.registerPlaceholder(placeholder);
|
||||
pl.allUsedPlaceholderIdentifiers.add(placeholder.getIdentifier());
|
||||
pl.getAllUsedPlaceholderIdentifiers().add(placeholder.getIdentifier());
|
||||
pl.refreshPlaceholderUsage();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -117,8 +128,8 @@ public class TABAPI {
|
||||
}
|
||||
ScoreboardManager sbm = (ScoreboardManager) TAB.getInstance().getFeatureManager().getFeature("scoreboard");
|
||||
if (sbm == null) throw new IllegalStateException("Scoreboard feature is not enabled");
|
||||
Scoreboard sb = new me.neznamy.tab.shared.features.scoreboard.Scoreboard(sbm, name, title, lines);
|
||||
sbm.APIscoreboards.add(sb);
|
||||
Scoreboard sb = new ScoreboardImpl(sbm, name, title, lines);
|
||||
sbm.getApiScoreboards().add(sb);
|
||||
return sb;
|
||||
}
|
||||
|
||||
@@ -156,7 +167,7 @@ public class TABAPI {
|
||||
me.neznamy.tab.shared.features.bossbar.BossBar feature = (me.neznamy.tab.shared.features.bossbar.BossBar) TAB.getInstance().getFeatureManager().getFeature("bossbar");
|
||||
if (feature == null) throw new IllegalStateException("Bossbar feature is not enabled");
|
||||
BossBar bar = new BossBarLine(name, null, color, style, title, progress);
|
||||
feature.lines.put(bar.getName(), (BossBarLine) bar);
|
||||
feature.getLines().put(bar.getName(), (BossBarLine) bar);
|
||||
return bar;
|
||||
}
|
||||
|
||||
@@ -165,7 +176,7 @@ public class TABAPI {
|
||||
* @return placeholders registered via API
|
||||
*/
|
||||
public static Map<String, Placeholder> getAPIPlaceholders(){
|
||||
return APIPlaceholders;
|
||||
return apiPlaceholders;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -176,6 +187,6 @@ public class TABAPI {
|
||||
* @return true if it was registered, false if it already was registered before
|
||||
*/
|
||||
public static boolean registerSubCondition(String identifier, Class<? extends SimpleCondition> clazz) {
|
||||
return SimpleCondition.conditionTypes.put(identifier, clazz) == null;
|
||||
return SimpleCondition.getConditionTypes().put(identifier, clazz) == null;
|
||||
}
|
||||
}
|
||||
+25
-51
@@ -147,7 +147,7 @@ public interface TabPlayer {
|
||||
/**
|
||||
* Returns player's uuid used in tablist. This may only be different than real uuid if
|
||||
* TAB is installed on velocity with some specific velocity setup
|
||||
* @return
|
||||
* @return player's uuid in tablist
|
||||
*/
|
||||
public UUID getTablistUUID();
|
||||
|
||||
@@ -232,7 +232,6 @@ public interface TabPlayer {
|
||||
|
||||
/**
|
||||
* Toggles armor stands preview mode for the player
|
||||
* @throws IllegalStateException - if unlimited nametag mode is not enabled
|
||||
*/
|
||||
public void toggleNametagPreview();
|
||||
|
||||
@@ -272,11 +271,6 @@ public interface TabPlayer {
|
||||
*/
|
||||
public boolean isLoaded();
|
||||
|
||||
/**
|
||||
* Marks the player as loaded and makes isLoaded() return true
|
||||
*/
|
||||
public void markAsLoaded();
|
||||
|
||||
/**
|
||||
* Returns true if player has bossbar visible, false if player hid bossbar(s) using bossbar
|
||||
* toggle command
|
||||
@@ -427,30 +421,6 @@ public interface TabPlayer {
|
||||
* @param armorStandManager - new instance
|
||||
*/
|
||||
public void setArmorStandManager(ArmorStandManager armorStandManager);
|
||||
|
||||
/**
|
||||
* Internal method to set world name
|
||||
* @param name - name of new world
|
||||
*/
|
||||
public void setWorldName(String name);
|
||||
|
||||
/**
|
||||
* Internal method to set team name
|
||||
* @param name - name of team
|
||||
*/
|
||||
public void setTeamName(String name);
|
||||
|
||||
/**
|
||||
* Internal method to set team name note
|
||||
* @param note - team name note
|
||||
*/
|
||||
public void setTeamNameNote(String note);
|
||||
|
||||
/**
|
||||
* Internal method to track currently active scoreboard
|
||||
* @param board - new active scoreboard
|
||||
*/
|
||||
public void setActiveScoreboard(Scoreboard board);
|
||||
|
||||
/**
|
||||
* Internal method that returns player's active scoreboard
|
||||
@@ -458,26 +428,6 @@ public interface TabPlayer {
|
||||
*/
|
||||
public Scoreboard getActiveScoreboard();
|
||||
|
||||
/**
|
||||
* Internal method that sets player's group
|
||||
* @param group - new group
|
||||
* @param refreshIfChanged - whether to refresh properties if value changed or not
|
||||
*/
|
||||
public void setGroup(String group, boolean refreshIfChanged);
|
||||
|
||||
/**
|
||||
* Internal method to track scoreboards from other plugins
|
||||
* @param objectiveName - objective name of scoreboard from other plugins
|
||||
*/
|
||||
public void setOtherPluginScoreboard(String objectiveName);
|
||||
|
||||
/**
|
||||
* Internal method that returns scoreboard objective name of scoreboard from other plugin or null
|
||||
* if not scoreboard from other plugin is set
|
||||
* @return name of scoreboard objective from other plugin
|
||||
*/
|
||||
public String getOtherPluginScoreboard();
|
||||
|
||||
/**
|
||||
* Forces new team name for the player until this method is called again with null argument and
|
||||
* performs all actions to change player's team name
|
||||
@@ -490,4 +440,28 @@ public interface TabPlayer {
|
||||
* @return forced team name or null if not forced
|
||||
*/
|
||||
public String getForcedTeamName();
|
||||
|
||||
/**
|
||||
* Returns gamemode of the player (0 for survival, 1 creative, 2 adventure, 3 spectator)
|
||||
* @return gamemode of the player
|
||||
*/
|
||||
public int getGamemode();
|
||||
|
||||
/**
|
||||
* Unregisters player's team and no longer handles it, as well as disables anti-override for teams.
|
||||
* This can be resumed using resumeTeamHandling(). If team handling was paused already, nothing happens.
|
||||
*/
|
||||
public void pauseTeamHandling();
|
||||
|
||||
/**
|
||||
* Resumes team handling if it was before paused using pauseTeamHandling(), if not, nothing happens
|
||||
*/
|
||||
public void resumeTeamHandling();
|
||||
|
||||
/**
|
||||
* Returns true if team handling is paused for this player using pauseTeamHandling(), false if not or
|
||||
* it was resumed already using resumeTeamHandling
|
||||
* @return true if paused, false if not
|
||||
*/
|
||||
public boolean hasTeamHandlingPaused();
|
||||
}
|
||||
File renamed without changes.
File renamed without changes.
+28
-1
@@ -57,4 +57,31 @@ public interface BossBar {
|
||||
* @param style - new style
|
||||
*/
|
||||
public void setStyle(BarStyle style);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns title of the bossbar
|
||||
* @return title of the bossbar
|
||||
*/
|
||||
public String getTitle();
|
||||
|
||||
/**
|
||||
* Returns progress of the bossbar as string, which is either entered string
|
||||
* containing placeholders or entered number converted to string
|
||||
* @return entered progress as string
|
||||
*/
|
||||
public String getProgress();
|
||||
|
||||
/**
|
||||
* Returns color of the bossbar as string, which is either entered string
|
||||
* containing placeholders or entered enum value converted to string
|
||||
* @return entered color as string
|
||||
*/
|
||||
public String getColor();
|
||||
|
||||
/**
|
||||
* Returns style of the bossbar as string, which is either entered string
|
||||
* containing placeholders or entered enum value converted to string
|
||||
* @return entered style as string
|
||||
*/
|
||||
public String getStyle();
|
||||
}
|
||||
+2
-2
@@ -15,8 +15,8 @@ public class BukkitTABLoadEvent extends Event {
|
||||
public HandlerList getHandlers(){
|
||||
return handlers;
|
||||
}
|
||||
|
||||
public static HandlerList getHandlerList(){
|
||||
|
||||
public static HandlerList getHandlerList() {
|
||||
return handlers;
|
||||
}
|
||||
}
|
||||
File renamed without changes.
+59
-55
@@ -10,6 +10,7 @@ import java.util.Arrays;
|
||||
import java.util.Date;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Set;
|
||||
|
||||
import me.neznamy.tab.api.bossbar.BarColor;
|
||||
@@ -24,15 +25,15 @@ public class ErrorManager {
|
||||
private final SimpleDateFormat dateformat = new SimpleDateFormat("dd.MM.yyyy - HH:mm:ss - ");
|
||||
|
||||
//one time messages already sent into console so they are not sent again
|
||||
private Set<String> oneTimeMessages = new HashSet<String>();
|
||||
private Set<String> oneTimeMessages = new HashSet<>();
|
||||
|
||||
//amount of logged startup warns
|
||||
private int startupWarns = 0;
|
||||
|
||||
//error logs
|
||||
public File errorLog;
|
||||
public File papiErrorLog;
|
||||
public File antiOverrideLog;
|
||||
private File errorLog;
|
||||
private File papiErrorLog;
|
||||
private File antiOverrideLog;
|
||||
|
||||
//plugin instance
|
||||
private TAB tab;
|
||||
@@ -46,8 +47,8 @@ public class ErrorManager {
|
||||
errorLog = new File(tab.getPlatform().getDataFolder(), "errors.log");
|
||||
papiErrorLog = new File(tab.getPlatform().getDataFolder(), "PlaceholderAPI.errors.log");
|
||||
antiOverrideLog = new File(tab.getPlatform().getDataFolder(), "anti-override.log");
|
||||
if (errorLog.exists() && errorLog.length() > 10) {
|
||||
startupWarn("File &e" + errorLog.getPath() + "&c exists and is not empty. Take a look at the error messages and try to resolve them. After you do, delete the file.");
|
||||
if (getErrorLog().exists() && getErrorLog().length() > 10) {
|
||||
startupWarn("File &e" + getErrorLog().getPath() + "&c exists and is not empty. Take a look at the error messages and try to resolve them. After you do, delete the file.");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -87,7 +88,7 @@ public class ErrorManager {
|
||||
* @param intoConsoleToo - if the message should be printed into console as well
|
||||
*/
|
||||
public void printError(String message, Throwable t, boolean intoConsoleToo) {
|
||||
printError(message, t, intoConsoleToo, errorLog);
|
||||
printError(message, t, intoConsoleToo, getErrorLog());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -105,22 +106,30 @@ public class ErrorManager {
|
||||
try {
|
||||
if (!createFile(file)) return;
|
||||
if (file.length() > 1000000) return; //not going over 1 MB
|
||||
BufferedWriter buf = new BufferedWriter(new FileWriter(file, true));
|
||||
if (message != null) {
|
||||
write(buf, "&c[TAB v" + tab.getPluginVersion() + (tab.isPremium() ? " Premium": "") + "] " + message, intoConsoleToo);
|
||||
}
|
||||
if (error != null) {
|
||||
write(buf, "&c" + error.getClass().getName() + ": " + error.getMessage(), intoConsoleToo);
|
||||
for (StackTraceElement ste : error.getStackTrace()) {
|
||||
write(buf, "&c at " + ste.toString(), intoConsoleToo);
|
||||
try (BufferedWriter buf = new BufferedWriter(new FileWriter(file, true))){
|
||||
if (message != null) {
|
||||
write(buf, "&c[TAB v" + tab.getPluginVersion() + (tab.isPremium() ? " Premium": "") + "] ", message.replace('\u00a7', '&'), intoConsoleToo);
|
||||
}
|
||||
if (error != null) {
|
||||
write(buf, "&c", error.getClass().getName() + ": " + error.getMessage(), intoConsoleToo);
|
||||
for (StackTraceElement ste : error.getStackTrace()) {
|
||||
write(buf, "&c at ", ste.toString(), intoConsoleToo);
|
||||
}
|
||||
}
|
||||
}
|
||||
buf.close();
|
||||
} catch (Throwable ex) {
|
||||
} catch (Exception ex) {
|
||||
tab.getPlatform().sendConsoleMessage("&c[TAB] An error occurred when printing error message into file", true);
|
||||
ex.printStackTrace();
|
||||
tab.getPlatform().sendConsoleMessage(ex.getClass().getName() + ": " + ex.getMessage(), true);
|
||||
for (StackTraceElement e : ex.getStackTrace()) {
|
||||
tab.getPlatform().sendConsoleMessage("\t" + e.toString(), true);
|
||||
}
|
||||
tab.getPlatform().sendConsoleMessage("&c[TAB] Original error: " + message, true);
|
||||
if (error != null) error.printStackTrace();
|
||||
if (error != null) {
|
||||
tab.getPlatform().sendConsoleMessage(error.getClass().getName() + ": " + error.getMessage(), true);
|
||||
for (StackTraceElement e : error.getStackTrace()) {
|
||||
tab.getPlatform().sendConsoleMessage("\t" + e.toString(), true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -133,8 +142,7 @@ public class ErrorManager {
|
||||
private boolean createFile(File file) {
|
||||
if (file.exists()) return true;
|
||||
try {
|
||||
file.createNewFile();
|
||||
return true;
|
||||
return file.createNewFile();
|
||||
} catch (IOException e) {
|
||||
tab.getPlatform().sendConsoleMessage("&c[TAB] Failed to create file " + file.getPath() + ": " + e.getMessage(), true);
|
||||
return false;
|
||||
@@ -148,9 +156,9 @@ public class ErrorManager {
|
||||
* @param forceConsole - send into console even without debug mode
|
||||
* @throws IOException - if IO writer operation fails
|
||||
*/
|
||||
private void write(BufferedWriter buf, String message, boolean forceConsole) throws IOException {
|
||||
buf.write(getCurrentTime() + removeColors(message) + System.getProperty("line.separator"));
|
||||
if (tab.debugMode || forceConsole) tab.getPlatform().sendConsoleMessage(message, true);
|
||||
private void write(BufferedWriter buf, String prefix, String message, boolean forceConsole) throws IOException {
|
||||
buf.write(getCurrentTime() + removeColors(prefix) + message + System.getProperty("line.separator"));
|
||||
if (tab.isDebugMode() || forceConsole) tab.getPlatform().sendConsoleMessage(prefix.replace('&', '\u00a7') + message, false);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -220,12 +228,8 @@ public class ErrorManager {
|
||||
if (string == null || string.length() == 0) return 0; //preventing error message on bungee with papi placeholders due to them not being initialized yet
|
||||
try {
|
||||
return (int) Math.round(Double.parseDouble(string));
|
||||
} catch (Throwable e) {
|
||||
if (string.contains("%")) {
|
||||
return oneTimeConsoleError(defaultValue, "Value \"" + string + "\" used in " + place + " still has unparsed placeholders! Did you forget to download an expansion ?");
|
||||
} else {
|
||||
return oneTimeConsoleError(defaultValue, place + " only accepts numeric values! (Attempted to use \"" + string + "\")");
|
||||
}
|
||||
} catch (NumberFormatException e) {
|
||||
return oneTimeConsoleError(defaultValue, formatNumberError(place, string));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -239,12 +243,8 @@ public class ErrorManager {
|
||||
public float parseFloat(String string, float defaultValue, String place) {
|
||||
try {
|
||||
return Float.parseFloat(string);
|
||||
} catch (Throwable e) {
|
||||
if (string.contains("%")) {
|
||||
return oneTimeConsoleError(defaultValue, "Value \"" + string + "\" used in " + place + " still has unparsed placeholders! Did you forget to download an expansion ?");
|
||||
} else {
|
||||
return oneTimeConsoleError(defaultValue, place + " only accepts numeric values! (Attempted to use \"" + string + "\")");
|
||||
}
|
||||
} catch (NumberFormatException e) {
|
||||
return oneTimeConsoleError(defaultValue, formatNumberError(place, string));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -259,14 +259,14 @@ public class ErrorManager {
|
||||
if (string == null || string.length() == 0) return 0; //preventing error message on bungee with papi placeholders due to them not being initialized yet
|
||||
try {
|
||||
return Double.parseDouble(string);
|
||||
} catch (Throwable e) {
|
||||
if (string.contains("%")) {
|
||||
return oneTimeConsoleError(defaultValue, "Value \"" + string + "\" used in " + place + " still has unparsed placeholders! Did you forget to download an expansion ?");
|
||||
} else {
|
||||
return oneTimeConsoleError(defaultValue, place + " only accepts numeric values! (Attempted to use \"" + string + "\")");
|
||||
}
|
||||
} catch (NumberFormatException e) {
|
||||
return oneTimeConsoleError(defaultValue, formatNumberError(place, string));
|
||||
}
|
||||
}
|
||||
|
||||
private String formatNumberError(String place, String value) {
|
||||
return String.format("%s only accepts numeric values! (Attempted to use \"%s\")", place, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses bar color in given string, returns second argument if string is not valid
|
||||
@@ -278,12 +278,8 @@ public class ErrorManager {
|
||||
public BarColor parseColor(String string, BarColor defaultValue, String place) {
|
||||
try {
|
||||
return BarColor.valueOf(string);
|
||||
} catch (Throwable e) {
|
||||
if (string.contains("%")) {
|
||||
return oneTimeConsoleError(defaultValue, "Value \"" + string + "\" used in " + place + " still has unparsed placeholders! Did you forget to download an expansion ?");
|
||||
} else {
|
||||
return oneTimeConsoleError(defaultValue, place + " only accepts one of the defined colors! (Attempted to use \"" + string + "\")");
|
||||
}
|
||||
} catch (Exception e) {
|
||||
return oneTimeConsoleError(defaultValue, String.format("%s only accepts one of the defined colors! (Attempted to use \"%s\")", place, string));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -297,12 +293,8 @@ public class ErrorManager {
|
||||
public BarStyle parseStyle(String string, BarStyle defaultValue, String place) {
|
||||
try {
|
||||
return BarStyle.valueOf(string);
|
||||
} catch (Throwable e) {
|
||||
if (string.contains("%")) {
|
||||
return oneTimeConsoleError(defaultValue, "Value \"" + string + "\" used in " + place + " still has unparsed placeholders! Did you forget to download an expansion ?");
|
||||
} else {
|
||||
return oneTimeConsoleError(defaultValue, place + " only accepts one of the defined styles! (Attempted to use \"" + string + "\")");
|
||||
}
|
||||
} catch (Exception e) {
|
||||
return oneTimeConsoleError(defaultValue, String.format("%s only accepts one of the defined styles! (Attempted to use \"%s\")", place, string));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -410,10 +402,22 @@ public class ErrorManager {
|
||||
*/
|
||||
public SimpleDateFormat createDateFormat(String value, String defaultValue) {
|
||||
try {
|
||||
return new SimpleDateFormat(value);
|
||||
return new SimpleDateFormat(value, Locale.ENGLISH);
|
||||
} catch (Exception e) {
|
||||
startupWarn("Format \"" + value + "\" is not a valid date/time format. Did you try to use color codes?");
|
||||
return new SimpleDateFormat(defaultValue);
|
||||
}
|
||||
}
|
||||
|
||||
public File getAntiOverrideLog() {
|
||||
return antiOverrideLog;
|
||||
}
|
||||
|
||||
public File getErrorLog() {
|
||||
return errorLog;
|
||||
}
|
||||
|
||||
public File getPapiErrorLog() {
|
||||
return papiErrorLog;
|
||||
}
|
||||
}
|
||||
+16
-61
@@ -1,5 +1,6 @@
|
||||
package me.neznamy.tab.shared;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.ConcurrentModificationException;
|
||||
@@ -15,12 +16,9 @@ import me.neznamy.tab.shared.features.NameTag;
|
||||
import me.neznamy.tab.shared.features.types.Feature;
|
||||
import me.neznamy.tab.shared.features.types.Loadable;
|
||||
import me.neznamy.tab.shared.features.types.Refreshable;
|
||||
import me.neznamy.tab.shared.features.types.event.ChatEventListener;
|
||||
import me.neznamy.tab.shared.features.types.event.CommandListener;
|
||||
import me.neznamy.tab.shared.features.types.event.JoinEventListener;
|
||||
import me.neznamy.tab.shared.features.types.event.QuitEventListener;
|
||||
import me.neznamy.tab.shared.features.types.event.RespawnEventListener;
|
||||
import me.neznamy.tab.shared.features.types.event.SneakEventListener;
|
||||
import me.neznamy.tab.shared.features.types.event.WorldChangeListener;
|
||||
import me.neznamy.tab.shared.features.types.packet.DisplayObjectivePacketListener;
|
||||
import me.neznamy.tab.shared.features.types.packet.LoginPacketListener;
|
||||
@@ -37,7 +35,7 @@ import me.neznamy.tab.shared.packets.PacketPlayOutScoreboardObjective;
|
||||
public class FeatureManager {
|
||||
|
||||
//list of registered features
|
||||
private Map<String, Feature> features = new LinkedHashMap<String, Feature>();
|
||||
private Map<String, Feature> features = new LinkedHashMap<>();
|
||||
|
||||
//tab instance
|
||||
private TAB tab;
|
||||
@@ -153,10 +151,12 @@ public class FeatureManager {
|
||||
* @param receiver - packet receiver
|
||||
* @param packet - an instance of custom packet class PacketPlayOutPlayerInfo
|
||||
* @return altered packet or null if packet should be cancelled
|
||||
* @throws Exception
|
||||
* @throws InvocationTargetException
|
||||
* @throws IllegalAccessException
|
||||
*/
|
||||
public Object onPacketPlayOutPlayerInfo(TabPlayer receiver, Object packet) throws Exception {
|
||||
List<PlayerInfoPacketListener> listeners = new ArrayList<PlayerInfoPacketListener>();
|
||||
public Object onPacketPlayOutPlayerInfo(TabPlayer receiver, Object packet) throws IllegalAccessException, InvocationTargetException {
|
||||
if (receiver.getVersion().getMinorVersion() < 8) return packet;
|
||||
List<PlayerInfoPacketListener> listeners = new ArrayList<>();
|
||||
for (Feature f : getAllFeatures()) {
|
||||
if (f instanceof PlayerInfoPacketListener) listeners.add((PlayerInfoPacketListener) f);
|
||||
}
|
||||
@@ -168,7 +168,7 @@ public class FeatureManager {
|
||||
tab.getCPUManager().addTime(TabFeature.PACKET_DESERIALIZING, UsageType.PACKET_PLAYER_INFO, System.nanoTime()-time);
|
||||
for (PlayerInfoPacketListener f : listeners) {
|
||||
time = System.nanoTime();
|
||||
((PlayerInfoPacketListener)f).onPacketSend(receiver, info);
|
||||
f.onPacketSend(receiver, info);
|
||||
tab.getCPUManager().addTime(f.getFeatureType(), UsageType.PACKET_READING_OUT, System.nanoTime()-time);
|
||||
}
|
||||
time = System.nanoTime();
|
||||
@@ -211,7 +211,7 @@ public class FeatureManager {
|
||||
((JoinEventListener)f).onJoin(connectedPlayer);
|
||||
tab.getCPUManager().addTime(f.getFeatureType(), UsageType.PLAYER_JOIN_EVENT, System.nanoTime()-time);
|
||||
}
|
||||
connectedPlayer.markAsLoaded();
|
||||
((ITabPlayer)connectedPlayer).markAsLoaded();
|
||||
tab.debug("Player join of " + connectedPlayer.getName() + " processed in " + (System.currentTimeMillis()-millis) + "ms");
|
||||
}
|
||||
|
||||
@@ -229,7 +229,7 @@ public class FeatureManager {
|
||||
return;
|
||||
}
|
||||
String from = changed.getWorldName();
|
||||
changed.setWorldName(to);
|
||||
((ITabPlayer)changed).setWorldName(to);
|
||||
for (Feature f : getAllFeatures()) {
|
||||
if (!(f instanceof WorldChangeListener)) continue;
|
||||
long time = System.nanoTime();
|
||||
@@ -271,7 +271,7 @@ public class FeatureManager {
|
||||
long time = System.nanoTime();
|
||||
try {
|
||||
if (newPacket != null) newPacket = ((RawPacketListener)f).onPacketReceive(receiver, newPacket);
|
||||
} catch (Throwable e) {
|
||||
} catch (IllegalAccessException e) {
|
||||
tab.getErrorManager().printError("Feature " + f.getFeatureType() + " failed to read packet", e);
|
||||
}
|
||||
tab.getCPUManager().addTime(f.getFeatureType(), UsageType.PACKET_READING_IN, System.nanoTime()-time);
|
||||
@@ -291,27 +291,13 @@ public class FeatureManager {
|
||||
long time = System.nanoTime();
|
||||
try {
|
||||
((RawPacketListener)f).onPacketSend(receiver, packet);
|
||||
} catch (Throwable e) {
|
||||
} catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException | SecurityException | InstantiationException e) {
|
||||
tab.getErrorManager().printError("Feature " + f.getFeatureType() + " failed to read packet", e);
|
||||
}
|
||||
tab.getCPUManager().addTime(f.getFeatureType(), UsageType.PACKET_READING_OUT, System.nanoTime()-time);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Calls onRespawn on all featurs that implement RespawnEventListener and measures how long it took them to process
|
||||
* @param respawned - player who respawned
|
||||
*/
|
||||
public void onRespawn(TabPlayer respawned) {
|
||||
if (respawned == null) return;
|
||||
for (Feature f : getAllFeatures()) {
|
||||
if (!(f instanceof RespawnEventListener)) continue;
|
||||
long time = System.nanoTime();
|
||||
((RespawnEventListener)f).onRespawn(respawned);
|
||||
tab.getCPUManager().addTime(f.getFeatureType(), UsageType.PLAYER_RESPAWN_EVENT, System.nanoTime()-time);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Calls onLoginPacket on all featurs that implement LoginPacketListener and measures how long it took them to process
|
||||
* @param packetReceiver - player who received the packet
|
||||
@@ -330,9 +316,9 @@ public class FeatureManager {
|
||||
* @param packetReceiver - player who received the packet
|
||||
* @param packet - the packet
|
||||
* @return true if packet should be cancelled, false if not
|
||||
* @throws Exception - if something fails
|
||||
* @throws IllegalAccessException
|
||||
*/
|
||||
public boolean onDisplayObjective(TabPlayer packetReceiver, Object packet) throws Exception {
|
||||
public boolean onDisplayObjective(TabPlayer packetReceiver, Object packet) throws IllegalAccessException {
|
||||
long time = System.nanoTime();
|
||||
PacketPlayOutScoreboardDisplayObjective display = tab.getPacketBuilder().readDisplayObjective(packet, packetReceiver.getVersion());
|
||||
tab.getCPUManager().addTime(TabFeature.PACKET_DESERIALIZING, UsageType.PACKET_DISPLAY_OBJECTIVE, System.nanoTime()-time);
|
||||
@@ -349,8 +335,9 @@ public class FeatureManager {
|
||||
/**
|
||||
* Calls onObjective on all featurs that implement ObjectivePacketListener and measures how long it took them to process
|
||||
* @param packetReceiver - player who received the packet
|
||||
* @throws IllegalAccessException
|
||||
*/
|
||||
public void onObjective(TabPlayer packetReceiver, Object packet) throws Exception {
|
||||
public void onObjective(TabPlayer packetReceiver, Object packet) throws IllegalAccessException {
|
||||
long time = System.nanoTime();
|
||||
PacketPlayOutScoreboardObjective display = tab.getPacketBuilder().readObjective(packet, packetReceiver.getVersion());
|
||||
tab.getCPUManager().addTime(TabFeature.PACKET_DESERIALIZING, UsageType.PACKET_OBJECTIVE, System.nanoTime()-time);
|
||||
@@ -362,38 +349,6 @@ public class FeatureManager {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Calls onChat on all featurs that implement ChatEventListener and measures how long it took them to process
|
||||
* @param sender - player who sent chat message
|
||||
* @param message - the message
|
||||
* @param cancelled - if event is cancelled or not
|
||||
* @return true if event should be cancelled, false if not
|
||||
*/
|
||||
public boolean onChat(TabPlayer sender, String message, boolean cancelled) {
|
||||
boolean cancel = false;
|
||||
for (Feature f : getAllFeatures()) {
|
||||
if (!(f instanceof ChatEventListener)) continue;
|
||||
long time = System.nanoTime();
|
||||
if (((ChatEventListener)f).onChat(sender, message, cancelled)) cancel = true;
|
||||
tab.getCPUManager().addTime(f.getFeatureType(), UsageType.PLAYER_CHAT_EVENT, System.nanoTime()-time);
|
||||
}
|
||||
return cancel;
|
||||
}
|
||||
|
||||
/**
|
||||
* Calls onSneak on all featurs that implement SneakEventListener and measures how long it took them to process
|
||||
* @param player - player who sneaked
|
||||
* @param isSneaking - new sneak status
|
||||
*/
|
||||
public void onSneak(TabPlayer player, boolean isSneaking) {
|
||||
for (Feature f : getAllFeatures()) {
|
||||
if (!(f instanceof SneakEventListener)) continue;
|
||||
long time = System.nanoTime();
|
||||
((SneakEventListener)f).onSneak(player, isSneaking);
|
||||
tab.getCPUManager().addTime(f.getFeatureType(), UsageType.PLAYER_TOGGLE_SNEAK_EVENT, System.nanoTime()-time);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns currently loaded nametag feature or null if disabled
|
||||
* @return currently loaded nametag feature
|
||||
+94
-83
@@ -1,8 +1,11 @@
|
||||
package me.neznamy.tab.shared;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
@@ -21,6 +24,7 @@ import me.neznamy.tab.shared.features.scoreboard.ScoreboardManager;
|
||||
import me.neznamy.tab.shared.packets.IChatBaseComponent;
|
||||
import me.neznamy.tab.shared.packets.PacketPlayOutChat;
|
||||
import me.neznamy.tab.shared.packets.UniversalPacketPlayOut;
|
||||
import me.neznamy.tab.shared.packets.PacketPlayOutChat.ChatMessageType;
|
||||
|
||||
/**
|
||||
* The core class for player
|
||||
@@ -30,30 +34,31 @@ public abstract class ITabPlayer implements TabPlayer {
|
||||
protected String name;
|
||||
protected UUID uniqueId;
|
||||
protected String world;
|
||||
private String permissionGroup = "<null>";
|
||||
private String permissionGroup = GroupRefresher.DEFAULT_GROUP;
|
||||
private String teamName;
|
||||
private String teamNameNote;
|
||||
private String forcedTeamName;
|
||||
|
||||
private Map<String, Property> properties = new HashMap<String, Property>();
|
||||
private Map<String, Property> properties = new HashMap<>();
|
||||
private ArmorStandManager armorStandManager;
|
||||
protected ProtocolVersion version = ProtocolVersion.SERVER_VERSION;
|
||||
protected ProtocolVersion version = TAB.getInstance().getServerVersion();
|
||||
protected Channel channel;
|
||||
private boolean bossbarVisible;
|
||||
|
||||
private boolean previewingNametag;
|
||||
private Set<BossBar> activeBossBars = new HashSet<BossBar>();
|
||||
private Set<BossBar> activeBossBars = new HashSet<>();
|
||||
private Boolean forcedCollision;
|
||||
private boolean onJoinFinished;
|
||||
private boolean hiddenNametag;
|
||||
private Set<UUID> hiddenNametagFor = new HashSet<UUID>();
|
||||
private Set<UUID> hiddenNametagFor = new HashSet<>();
|
||||
|
||||
private Scoreboard activeScoreboard;
|
||||
private boolean scoreboardVisible;
|
||||
private Scoreboard forcedScoreboard;
|
||||
private String otherPluginScoreboard;
|
||||
private boolean teamHandlingPaused;
|
||||
|
||||
protected Map<String, String> attributes = new HashMap<String, String>();
|
||||
protected Map<String, String> attributes = new HashMap<>();
|
||||
|
||||
protected void init() {
|
||||
setGroup(((GroupRefresher)TAB.getInstance().getFeatureManager().getFeature("group")).detectPermissionGroup(this), false);
|
||||
@@ -78,12 +83,12 @@ public abstract class ITabPlayer implements TabPlayer {
|
||||
} else {
|
||||
component = new IChatBaseComponent(message);
|
||||
}
|
||||
sendCustomPacket(new PacketPlayOutChat(component));
|
||||
sendCustomPacket(new PacketPlayOutChat(component, ChatMessageType.CHAT));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendMessage(IChatBaseComponent message) {
|
||||
sendCustomPacket(new PacketPlayOutChat(message));
|
||||
sendCustomPacket(new PacketPlayOutChat(message, ChatMessageType.CHAT));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -103,32 +108,35 @@ public abstract class ITabPlayer implements TabPlayer {
|
||||
|
||||
@Override
|
||||
public void setValueTemporarily(EnumProperty type, String value) {
|
||||
TAB.getInstance().getPlaceholderManager().checkForRegistration(value);
|
||||
TAB.getInstance().debug("Received API request to set property " + type + " of " + getName() + " temporarily to " + value + " by " + Thread.currentThread().getStackTrace()[2].toString());
|
||||
Property pr = getProperty(type.toString());
|
||||
if (pr == null) throw new IllegalStateException("Feature handling this property is not enabled");
|
||||
if (pr == null) throw new IllegalStateException("Feature handling this property (" + type + ") is not enabled");
|
||||
pr.setTemporaryValue(value);
|
||||
if (TAB.getInstance().getFeatureManager().isFeatureEnabled("nametagx") && type.toString().contains("tag")) {
|
||||
setProperty("nametag",getProperty("tagprefix").getCurrentRawValue() + getProperty("customtagname").getCurrentRawValue() + getProperty("tagsuffix").getCurrentRawValue(), null);
|
||||
setProperty(PropertyUtils.NAMETAG,getProperty(PropertyUtils.TAGPREFIX).getCurrentRawValue() + getProperty(PropertyUtils.CUSTOMTAGNAME).getCurrentRawValue() + getProperty(PropertyUtils.TAGSUFFIX).getCurrentRawValue(), null);
|
||||
}
|
||||
TAB.getInstance().getPlaceholderManager().checkForRegistration(value);
|
||||
forceRefresh();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setValuePermanently(EnumProperty type, String value) {
|
||||
TAB.getInstance().getPlaceholderManager().checkForRegistration(value);
|
||||
((PlayerCommand)TAB.getInstance().command.subcommands.get("player")).savePlayer(null, getName(), type.toString(), value);
|
||||
TAB.getInstance().debug("Received API request to set property " + type + " of " + getName() + " permanently to " + value + " by " + Thread.currentThread().getStackTrace()[2].toString());
|
||||
((PlayerCommand)TAB.getInstance().getCommand().getSubcommands().get("player")).savePlayer(null, getName(), type.toString(), value);
|
||||
if (TAB.getInstance().getFeatureManager().isFeatureEnabled("nametagx") && type.toString().contains("tag")) {
|
||||
setProperty("nametag", getProperty("tagprefix").getCurrentRawValue() + getProperty("customtagname").getCurrentRawValue() + getProperty("tagsuffix").getCurrentRawValue(), null);
|
||||
setProperty(PropertyUtils.NAMETAG, getProperty(PropertyUtils.TAGPREFIX).getCurrentRawValue() + getProperty(PropertyUtils.CUSTOMTAGNAME).getCurrentRawValue() + getProperty(PropertyUtils.TAGSUFFIX).getCurrentRawValue(), null);
|
||||
}
|
||||
Property pr = getProperty(type.toString());
|
||||
if (pr == null) return;
|
||||
pr.changeRawValue(value);
|
||||
TAB.getInstance().getPlaceholderManager().checkForRegistration(value);
|
||||
forceRefresh();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTemporaryValue(EnumProperty type) {
|
||||
return getProperty(type.toString()).getTemporaryValue();
|
||||
Property pr = getProperty(type.toString());
|
||||
return pr == null ? null : pr.getTemporaryValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -179,8 +187,8 @@ public abstract class ITabPlayer implements TabPlayer {
|
||||
activeScoreboard.unregister(this);
|
||||
activeScoreboard = null;
|
||||
}
|
||||
forcedScoreboard = (Scoreboard) scoreboard;
|
||||
((Scoreboard)scoreboard).register(this);
|
||||
forcedScoreboard = scoreboard;
|
||||
scoreboard.register(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -214,7 +222,6 @@ public abstract class ITabPlayer implements TabPlayer {
|
||||
return world;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setWorldName(String name) {
|
||||
world = name;
|
||||
}
|
||||
@@ -248,10 +255,10 @@ public abstract class ITabPlayer implements TabPlayer {
|
||||
if (armorStandManager == null) throw new IllegalStateException("Unlimited nametag mode is not enabled");
|
||||
if (previewingNametag) {
|
||||
armorStandManager.destroy(this);
|
||||
sendMessage(TAB.getInstance().getConfiguration().translation.getString("preview-off"), true);
|
||||
sendMessage(TAB.getInstance().getConfiguration().getTranslation().getString("preview-off"), true);
|
||||
} else {
|
||||
armorStandManager.spawn(this);
|
||||
sendMessage(TAB.getInstance().getConfiguration().translation.getString("preview-on"), true);
|
||||
sendMessage(TAB.getInstance().getConfiguration().getTranslation().getString("preview-on"), true);
|
||||
}
|
||||
previewingNametag = !previewingNametag;
|
||||
}
|
||||
@@ -276,7 +283,6 @@ public abstract class ITabPlayer implements TabPlayer {
|
||||
return onJoinFinished;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void markAsLoaded() {
|
||||
onJoinFinished = true;
|
||||
}
|
||||
@@ -293,20 +299,20 @@ public abstract class ITabPlayer implements TabPlayer {
|
||||
if (feature == null) return;
|
||||
if (hasBossbarVisible()) {
|
||||
feature.detectBossBarsAndSend(this);
|
||||
if (sendToggleMessage) sendMessage(TAB.getInstance().getConfiguration().translation.getString("bossbar-toggle-on"), true);
|
||||
if (feature.remember_toggle_choice) {
|
||||
feature.bossbar_off_players.remove(getName());
|
||||
TAB.getInstance().getConfiguration().playerdata.set("bossbar-off", feature.bossbar_off_players);
|
||||
if (sendToggleMessage) sendMessage(TAB.getInstance().getConfiguration().getTranslation().getString("bossbar-toggle-on"), true);
|
||||
if (feature.isRememberToggleChoice()) {
|
||||
feature.getBossbarOffPlayers().remove(getName());
|
||||
TAB.getInstance().getConfiguration().getPlayerDataFile().set("bossbar-off", feature.getBossbarOffPlayers());
|
||||
}
|
||||
} else {
|
||||
for (BossBar line : getActiveBossBars().toArray(new BossBar[0])) {
|
||||
removeBossBar(line);
|
||||
}
|
||||
getActiveBossBars().clear();
|
||||
if (sendToggleMessage) sendMessage(TAB.getInstance().getConfiguration().translation.getString("bossbar-toggle-off"), true);
|
||||
if (feature.remember_toggle_choice && !feature.bossbar_off_players.contains(getName())) {
|
||||
feature.bossbar_off_players.add(getName());
|
||||
TAB.getInstance().getConfiguration().playerdata.set("bossbar-off", feature.bossbar_off_players);
|
||||
if (sendToggleMessage) sendMessage(TAB.getInstance().getConfiguration().getTranslation().getString("bossbar-toggle-off"), true);
|
||||
if (feature.isRememberToggleChoice() && !feature.getBossbarOffPlayers().contains(getName())) {
|
||||
feature.getBossbarOffPlayers().add(getName());
|
||||
TAB.getInstance().getConfiguration().getPlayerDataFile().set("bossbar-off", feature.getBossbarOffPlayers());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -329,39 +335,22 @@ public abstract class ITabPlayer implements TabPlayer {
|
||||
@Override
|
||||
public void loadPropertyFromConfig(String property, String ifNotSet) {
|
||||
String playerGroupFromConfig = permissionGroup.replace(".", "@#@");
|
||||
String worldGroup = TAB.getInstance().getConfiguration().getWorldGroupOf(getWorldName());
|
||||
String worldGroup = TAB.getInstance().getConfiguration().getWorldGroupOf(TAB.getInstance().getConfiguration().getConfig().getConfigurationSection("per-" + TAB.getInstance().getPlatform().getSeparatorType() + "-settings").keySet(), getWorldName());
|
||||
String value;
|
||||
if ((value = TAB.getInstance().getConfiguration().config.getString("per-" + TAB.getInstance().getPlatform().getSeparatorType() + "-settings." + worldGroup + ".Users." + getName() + "." + property)) != null) {
|
||||
setProperty(property, value, "Player: " + getName() + ", " + TAB.getInstance().getPlatform().getSeparatorType() + ": " + worldGroup);
|
||||
return;
|
||||
}
|
||||
if ((value = TAB.getInstance().getConfiguration().config.getString("per-" + TAB.getInstance().getPlatform().getSeparatorType() + "-settings." + worldGroup + ".Users." + getUniqueId().toString() + "." + property)) != null) {
|
||||
setProperty(property, value, "PlayerUUID: " + getName() + ", " + TAB.getInstance().getPlatform().getSeparatorType() + ": " + worldGroup);
|
||||
return;
|
||||
}
|
||||
if ((value = TAB.getInstance().getConfiguration().config.getString("Users." + getName() + "." + property)) != null) {
|
||||
setProperty(property, value, "Player: " + getName());
|
||||
return;
|
||||
}
|
||||
if ((value = TAB.getInstance().getConfiguration().config.getString("Users." + getUniqueId().toString() + "." + property)) != null) {
|
||||
setProperty(property, value, "PlayerUUID: " + getName());
|
||||
return;
|
||||
}
|
||||
if ((value = TAB.getInstance().getConfiguration().config.getString("per-" + TAB.getInstance().getPlatform().getSeparatorType() + "-settings." + worldGroup + ".Groups." + playerGroupFromConfig + "." + property)) != null) {
|
||||
setProperty(property, value, "Group: " + permissionGroup + ", " + TAB.getInstance().getPlatform().getSeparatorType() + ": " + worldGroup);
|
||||
return;
|
||||
}
|
||||
if ((value = TAB.getInstance().getConfiguration().config.getString("per-" + TAB.getInstance().getPlatform().getSeparatorType() + "-settings." + worldGroup + ".Groups._OTHER_." + property)) != null) {
|
||||
setProperty(property, value, "Group: _OTHER_," + TAB.getInstance().getPlatform().getSeparatorType() + ": " + worldGroup);
|
||||
return;
|
||||
}
|
||||
if ((value = TAB.getInstance().getConfiguration().config.getString("Groups." + playerGroupFromConfig + "." + property)) != null) {
|
||||
setProperty(property, value, "Group: " + permissionGroup);
|
||||
return;
|
||||
}
|
||||
if ((value = TAB.getInstance().getConfiguration().config.getString("Groups._OTHER_." + property)) != null) {
|
||||
setProperty(property, value, "Group: _OTHER_");
|
||||
return;
|
||||
Map<String, String> priorities = new LinkedHashMap<>();
|
||||
priorities.put("per-" + TAB.getInstance().getPlatform().getSeparatorType() + "-settings." + worldGroup + ".Users." + getName() + "." + property, "Player: " + getName() + ", " + TAB.getInstance().getPlatform().getSeparatorType() + ": " + worldGroup);
|
||||
priorities.put("per-" + TAB.getInstance().getPlatform().getSeparatorType() + "-settings." + worldGroup + ".Users." + getUniqueId().toString() + "." + property, "PlayerUUID: " + getName() + ", " + TAB.getInstance().getPlatform().getSeparatorType() + ": " + worldGroup);
|
||||
priorities.put("Users." + getName() + "." + property, "Player: " + getName());
|
||||
priorities.put("Users." + getUniqueId().toString() + "." + property, "PlayerUUID: " + getName());
|
||||
priorities.put("per-" + TAB.getInstance().getPlatform().getSeparatorType() + "-settings." + worldGroup + ".Groups." + playerGroupFromConfig + "." + property, "Group: " + permissionGroup + ", " + TAB.getInstance().getPlatform().getSeparatorType() + ": " + worldGroup);
|
||||
priorities.put("per-" + TAB.getInstance().getPlatform().getSeparatorType() + "-settings." + worldGroup + ".Groups._OTHER_." + property, "Group: _OTHER_," + TAB.getInstance().getPlatform().getSeparatorType() + ": " + worldGroup);
|
||||
priorities.put("Groups." + playerGroupFromConfig + "." + property, "Group: " + permissionGroup);
|
||||
priorities.put("Groups._OTHER_." + property, "Group: _OTHER_");
|
||||
for (Entry<String, String> entry : priorities.entrySet()) {
|
||||
if ((value = TAB.getInstance().getConfiguration().getConfig().getString(entry.getKey())) != null) {
|
||||
setProperty(property, value, entry.getValue());
|
||||
return;
|
||||
}
|
||||
}
|
||||
setProperty(property, ifNotSet, "None");
|
||||
}
|
||||
@@ -376,7 +365,6 @@ public abstract class ITabPlayer implements TabPlayer {
|
||||
this.armorStandManager = armorStandManager;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setTeamName(String name) {
|
||||
teamName = name;
|
||||
}
|
||||
@@ -387,7 +375,6 @@ public abstract class ITabPlayer implements TabPlayer {
|
||||
return teamName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setTeamNameNote(String note) {
|
||||
teamNameNote = note;
|
||||
}
|
||||
@@ -416,23 +403,31 @@ public abstract class ITabPlayer implements TabPlayer {
|
||||
if (visible) {
|
||||
scoreboardManager.sendHighestScoreboard(this);
|
||||
if (sendToggleMessage) {
|
||||
sendMessage(scoreboardManager.scoreboard_on, true);
|
||||
sendMessage(scoreboardManager.getScoreboardOn(), true);
|
||||
}
|
||||
if (scoreboardManager.remember_toggle_choice) {
|
||||
scoreboardManager.sb_off_players.remove(getName());
|
||||
synchronized (scoreboardManager.sb_off_players){
|
||||
TAB.getInstance().getConfiguration().playerdata.set("scoreboard-off", scoreboardManager.sb_off_players);
|
||||
if (scoreboardManager.isRememberToggleChoice()) {
|
||||
if (scoreboardManager.isHiddenByDefault()) {
|
||||
scoreboardManager.getSbOffPlayers().add(getName());
|
||||
} else {
|
||||
scoreboardManager.getSbOffPlayers().remove(getName());
|
||||
}
|
||||
synchronized (scoreboardManager.getSbOffPlayers()){
|
||||
TAB.getInstance().getConfiguration().getPlayerDataFile().set("scoreboard-off", new ArrayList<>(scoreboardManager.getSbOffPlayers()));
|
||||
}
|
||||
}
|
||||
} else {
|
||||
scoreboardManager.unregisterScoreboard(this, true);
|
||||
if (sendToggleMessage) {
|
||||
sendMessage(scoreboardManager.scoreboard_off, true);
|
||||
sendMessage(scoreboardManager.getScoreboardOff(), true);
|
||||
}
|
||||
if (scoreboardManager.remember_toggle_choice) {
|
||||
scoreboardManager.sb_off_players.add(getName());
|
||||
TAB.getInstance().getConfiguration().playerdata.set("scoreboard-off", scoreboardManager.sb_off_players);synchronized (scoreboardManager.sb_off_players){
|
||||
TAB.getInstance().getConfiguration().playerdata.set("scoreboard-off", scoreboardManager.sb_off_players);
|
||||
if (scoreboardManager.isRememberToggleChoice()) {
|
||||
if (scoreboardManager.isHiddenByDefault()) {
|
||||
scoreboardManager.getSbOffPlayers().remove(getName());
|
||||
} else {
|
||||
scoreboardManager.getSbOffPlayers().add(getName());
|
||||
}
|
||||
synchronized (scoreboardManager.getSbOffPlayers()){
|
||||
TAB.getInstance().getConfiguration().getPlayerDataFile().set("scoreboard-off", new ArrayList<>(scoreboardManager.getSbOffPlayers()));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -448,7 +443,6 @@ public abstract class ITabPlayer implements TabPlayer {
|
||||
return scoreboardVisible;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setActiveScoreboard(Scoreboard board) {
|
||||
activeScoreboard = board;
|
||||
}
|
||||
@@ -458,7 +452,6 @@ public abstract class ITabPlayer implements TabPlayer {
|
||||
return activeScoreboard;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setGroup(String permissionGroup, boolean refreshIfChanged) {
|
||||
if (this.permissionGroup.equals(permissionGroup)) return;
|
||||
if (permissionGroup != null) {
|
||||
@@ -477,11 +470,6 @@ public abstract class ITabPlayer implements TabPlayer {
|
||||
return forcedScoreboard != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isVanished() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void showBossBar(BossBar bossbar) {
|
||||
BossBarLine line = (BossBarLine) bossbar;
|
||||
@@ -524,12 +512,10 @@ public abstract class ITabPlayer implements TabPlayer {
|
||||
attributes.put(attribute, value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setOtherPluginScoreboard(String objectiveName) {
|
||||
this.otherPluginScoreboard = objectiveName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getOtherPluginScoreboard() {
|
||||
return otherPluginScoreboard;
|
||||
}
|
||||
@@ -542,7 +528,7 @@ public abstract class ITabPlayer implements TabPlayer {
|
||||
|
||||
@Override
|
||||
public void forceTeamName(String name) {
|
||||
if (forcedTeamName == name) return;
|
||||
if (String.valueOf(forcedTeamName).equals(name)) return;
|
||||
if (name != null && name.length() > 16) throw new IllegalArgumentException("Team name cannot be more than 16 characters long.");
|
||||
NameTag nametags = TAB.getInstance().getFeatureManager().getNameTagFeature();
|
||||
if (nametags == null) return;
|
||||
@@ -556,4 +542,29 @@ public abstract class ITabPlayer implements TabPlayer {
|
||||
public String getForcedTeamName() {
|
||||
return forcedTeamName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void pauseTeamHandling() {
|
||||
if (teamHandlingPaused) return;
|
||||
NameTag f = TAB.getInstance().getFeatureManager().getNameTagFeature();
|
||||
if (f != null && !f.isDisabledWorld(getWorldName())) {
|
||||
f.unregisterTeam(this);
|
||||
}
|
||||
teamHandlingPaused = true; //setting to true after, so unregisterTeam method runs
|
||||
}
|
||||
|
||||
@Override
|
||||
public void resumeTeamHandling() {
|
||||
if (!teamHandlingPaused) return;
|
||||
teamHandlingPaused = false; //setting to false before, so registerTeam method runs
|
||||
NameTag f = TAB.getInstance().getFeatureManager().getNameTagFeature();
|
||||
if (f != null && !f.isDisabledWorld(getWorldName())) {
|
||||
f.registerTeam(this);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasTeamHandlingPaused() {
|
||||
return teamHandlingPaused;
|
||||
}
|
||||
}
|
||||
+7
-4
@@ -15,6 +15,9 @@ import me.neznamy.tab.shared.packets.PacketPlayOutScoreboardTeam;
|
||||
*/
|
||||
public class PacketAPI {
|
||||
|
||||
private PacketAPI() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers scoreboard team with given properties but sends unregister packet first unless disabled to avoid bungeecord kick
|
||||
* @param to - player to send the packet to
|
||||
@@ -27,10 +30,10 @@ public class PacketAPI {
|
||||
* @param color - color field (1.13+)
|
||||
*/
|
||||
public static synchronized void registerScoreboardTeam(TabPlayer to, String teamName, String prefix, String suffix, boolean enumNameTagVisibility, boolean enumTeamPush, Collection<String> players, EnumChatFormat color, TabFeature feature) {
|
||||
if (to.getVersion().getMinorVersion() >= 8 && TAB.getInstance().getConfiguration().unregisterBeforeRegister && TAB.getInstance().getPlatform().getSeparatorType().equals("world")) {
|
||||
to.sendCustomPacket(new PacketPlayOutScoreboardTeam(teamName).setTeamOptions(69), feature);
|
||||
if (to.getVersion().getMinorVersion() >= 8 && TAB.getInstance().getConfiguration().isUnregisterBeforeRegister() && TAB.getInstance().getPlatform().getSeparatorType().equals("world")) {
|
||||
to.sendCustomPacket(new PacketPlayOutScoreboardTeam(teamName), feature);
|
||||
}
|
||||
to.sendCustomPacket(new PacketPlayOutScoreboardTeam(teamName, prefix, suffix, enumNameTagVisibility?"always":"never", enumTeamPush?"always":"never", players, 69).setColor(color), feature);
|
||||
to.sendCustomPacket(new PacketPlayOutScoreboardTeam(teamName, prefix, suffix, enumNameTagVisibility?"always":"never", enumTeamPush?"always":"never", players, 0).setColor(color), feature);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -42,7 +45,7 @@ public class PacketAPI {
|
||||
* @param displayType - display type of the value (only supported in Playerlist)
|
||||
*/
|
||||
public static synchronized void registerScoreboardObjective(TabPlayer to, String objectiveName, String title, int position, EnumScoreboardHealthDisplay displayType, TabFeature feature) {
|
||||
if (to.getVersion().getMinorVersion() >= 8 && TAB.getInstance().getConfiguration().unregisterBeforeRegister && TAB.getInstance().getPlatform().getSeparatorType().equals("world")) {
|
||||
if (to.getVersion().getMinorVersion() >= 8 && TAB.getInstance().getConfiguration().isUnregisterBeforeRegister() && TAB.getInstance().getPlatform().getSeparatorType().equals("world")) {
|
||||
to.sendCustomPacket(new PacketPlayOutScoreboardObjective(objectiveName), feature);
|
||||
}
|
||||
to.sendCustomPacket(new PacketPlayOutScoreboardObjective(0, objectiveName, title, displayType), feature);
|
||||
@@ -0,0 +1,175 @@
|
||||
package me.neznamy.tab.shared;
|
||||
|
||||
import java.io.File;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.util.Map;
|
||||
|
||||
import me.neznamy.tab.api.TabPlayer;
|
||||
import me.neznamy.tab.shared.config.ConfigurationFile;
|
||||
import me.neznamy.tab.shared.features.AlignedSuffix;
|
||||
import me.neznamy.tab.shared.features.GhostPlayerFix;
|
||||
import me.neznamy.tab.shared.features.GroupRefresher;
|
||||
import me.neznamy.tab.shared.features.HeaderFooter;
|
||||
import me.neznamy.tab.shared.features.Playerlist;
|
||||
import me.neznamy.tab.shared.features.PluginInfo;
|
||||
import me.neznamy.tab.shared.features.UpdateChecker;
|
||||
import me.neznamy.tab.shared.features.bossbar.BossBar;
|
||||
import me.neznamy.tab.shared.features.layout.Layout;
|
||||
import me.neznamy.tab.shared.permission.PermissionPlugin;
|
||||
import me.neznamy.tab.shared.placeholders.Placeholder;
|
||||
import me.neznamy.tab.shared.placeholders.PlayerPlaceholder;
|
||||
import me.neznamy.tab.shared.placeholders.ServerPlaceholder;
|
||||
|
||||
/**
|
||||
* An interface with methods that are called in universal code, but require platform-specific API calls
|
||||
*/
|
||||
public interface Platform {
|
||||
|
||||
/**
|
||||
* Detects permission plugin and returns it's representing object
|
||||
* @return the interface representing the permission hook
|
||||
*/
|
||||
public PermissionPlugin detectPermissionPlugin();
|
||||
|
||||
/**
|
||||
* Loads features from config
|
||||
* @throws IllegalAccessException
|
||||
* @throws SecurityException
|
||||
* @throws NoSuchMethodException
|
||||
* @throws InvocationTargetException
|
||||
*/
|
||||
public void loadFeatures() throws IllegalAccessException, InvocationTargetException, NoSuchMethodException, SecurityException;
|
||||
|
||||
/**
|
||||
* Sends a message into console
|
||||
* @param message - the message
|
||||
* @param translateColors - if color codes should be translated
|
||||
*/
|
||||
public void sendConsoleMessage(String message, boolean translateColors);
|
||||
|
||||
/**
|
||||
* Creates an instance of me.neznamy.tab.shared.placeholders.Placeholder to handle this unknown placeholder (typically a PAPI placeholder)
|
||||
* @param identifier - placeholder's identifier
|
||||
*/
|
||||
public void registerUnknownPlaceholder(String identifier);
|
||||
|
||||
/**
|
||||
* Returns server's version
|
||||
* @return server's version
|
||||
*/
|
||||
public String getServerVersion();
|
||||
|
||||
/**
|
||||
* Returns the word used to separate config options. It's value is "world" for bukkit and "server" for proxies
|
||||
* @return "world" on bukkit, "server" on proxies
|
||||
*/
|
||||
public String getSeparatorType();
|
||||
|
||||
/**
|
||||
* Returns plugin's data folder
|
||||
* @return plugin's data folder
|
||||
*/
|
||||
public File getDataFolder();
|
||||
|
||||
/**
|
||||
* Calls platform-specific event
|
||||
* This method is called when plugin is fully enabled
|
||||
*/
|
||||
public void callLoadEvent();
|
||||
|
||||
/**
|
||||
* Returns max player count configured in server files
|
||||
* @return max player count
|
||||
*/
|
||||
public int getMaxPlayers();
|
||||
|
||||
/**
|
||||
* Returns name of config file in the jar file on specific platform
|
||||
* @return name of config file of the platform
|
||||
*/
|
||||
public String getConfigName();
|
||||
|
||||
/**
|
||||
* Removes an old config option that is not present anymore
|
||||
* @param config - configuration file
|
||||
* @param oldKey - name of removed config option
|
||||
*/
|
||||
public default void removeOld(ConfigurationFile config, String oldKey) {
|
||||
if (config.hasConfigOption(oldKey)) {
|
||||
config.set(oldKey, null);
|
||||
TAB.getInstance().print('2', "Removed old " + config.getName() + " option " + oldKey);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Renames variable in given configuration file
|
||||
* @param config - configuration file to rename variable in
|
||||
* @param oldName - old config option's name
|
||||
* @param newName - new config option's name
|
||||
*/
|
||||
public default void rename(ConfigurationFile config, String oldName, String newName) {
|
||||
if (config.hasConfigOption(oldName)) {
|
||||
Object value = config.getObject(oldName);
|
||||
config.set(oldName, null);
|
||||
config.set(newName, value);
|
||||
TAB.getInstance().print('2', "Renamed config option " + oldName + " to " + newName);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Replaces all placeholders in given string
|
||||
* @param string - string to replace
|
||||
* @param player - player to replaced placeholders for
|
||||
* @return replaced string
|
||||
*/
|
||||
public default String replaceAllPlaceholders(String string, TabPlayer player) {
|
||||
if (string == null) return null;
|
||||
String replaced = string;
|
||||
for (Placeholder p : TAB.getInstance().getPlaceholderManager().getAllPlaceholders()) {
|
||||
if (replaced.contains(p.getIdentifier())) {
|
||||
if (p instanceof ServerPlaceholder) {
|
||||
((ServerPlaceholder)p).update();
|
||||
}
|
||||
if (p instanceof PlayerPlaceholder) {
|
||||
((PlayerPlaceholder)p).update(player);
|
||||
}
|
||||
replaced = p.set(replaced, player);
|
||||
}
|
||||
}
|
||||
return replaced;
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts configuration options same on all platforms
|
||||
* @param file - file to convert
|
||||
*/
|
||||
public default void convertUniversalOptions(ConfigurationFile file) {
|
||||
if (file.getName().equals("animations.yml")) {
|
||||
Map<String, Object> values = file.getValues();
|
||||
if (values.size() == 1 && values.containsKey("animations")) {
|
||||
file.setValues(file.getConfigurationSection("animations"));
|
||||
file.save();
|
||||
TAB.getInstance().print('2', "Converted animations.yml to new format.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads universal features present on all platforms with the same configuration
|
||||
*/
|
||||
public default void loadUniversalFeatures() {
|
||||
TAB tab = TAB.getInstance();
|
||||
if (tab.getConfiguration().getConfig().getBoolean("enable-header-footer", true)) tab.getFeatureManager().registerFeature("headerfooter", new HeaderFooter(tab));
|
||||
if (tab.getConfiguration().isRemoveGhostPlayers()) tab.getFeatureManager().registerFeature("ghostplayerfix", new GhostPlayerFix());
|
||||
if (TAB.getInstance().getServerVersion().getMinorVersion() >= 8 && tab.getConfiguration().getConfig().getBoolean("change-tablist-prefix-suffix", true)) {
|
||||
Playerlist playerlist = new Playerlist(tab);
|
||||
tab.getFeatureManager().registerFeature("playerlist", playerlist);
|
||||
if (tab.getConfiguration().getPremiumConfig() != null && tab.getConfiguration().getPremiumConfig().getBoolean("align-tabsuffix-on-the-right", false)) tab.getFeatureManager().registerFeature("alignedsuffix", new AlignedSuffix(playerlist, tab));
|
||||
}
|
||||
tab.getFeatureManager().registerFeature("group", new GroupRefresher(tab));
|
||||
tab.getFeatureManager().registerFeature("info", new PluginInfo());
|
||||
new UpdateChecker(tab);
|
||||
if (tab.getConfiguration().isLayout()) tab.getFeatureManager().registerFeature("layout", new Layout(tab));
|
||||
if (tab.getConfiguration().getBossbarConfig().getBoolean("bossbar-enabled", false)) tab.getFeatureManager().registerFeature("bossbar", new BossBar(tab));
|
||||
}
|
||||
}
|
||||
+17
-14
@@ -23,16 +23,16 @@ public class Property {
|
||||
private String temporaryValue;
|
||||
|
||||
//last known output after placeholder replacement
|
||||
public String lastReplacedValue;
|
||||
private String lastReplacedValue;
|
||||
|
||||
//source of property's raw value
|
||||
private String source;
|
||||
|
||||
//used placeholders in current raw value
|
||||
public List<String> placeholders;
|
||||
private List<String> placeholders;
|
||||
|
||||
//used relational placeholders in current raw value
|
||||
public List<String> relPlaceholders;
|
||||
private List<String> relPlaceholders;
|
||||
|
||||
public Property(TabPlayer owner, String rawValue) {
|
||||
this(owner, rawValue, null);
|
||||
@@ -41,7 +41,7 @@ public class Property {
|
||||
public Property(TabPlayer owner, String rawValue, String source) {
|
||||
this.owner = owner;
|
||||
this.source = source;
|
||||
this.rawValue = RGBUtils.getInstance().applyFormats((rawValue == null ? "" : rawValue), true);
|
||||
this.rawValue = RGBUtils.getInstance().applyFormats((rawValue == null ? "" : TAB.getInstance().getPlaceholderManager().color(rawValue)), true);
|
||||
analyze(this.rawValue);
|
||||
update();
|
||||
}
|
||||
@@ -51,15 +51,18 @@ public class Property {
|
||||
* @param value - raw value to be checked
|
||||
*/
|
||||
private void analyze(String value) {
|
||||
placeholders = new ArrayList<String>();
|
||||
relPlaceholders = new ArrayList<String>();
|
||||
List<String> placeholders0 = new ArrayList<>();
|
||||
List<String> relPlaceholders0 = new ArrayList<>();
|
||||
for (String identifier : TAB.getInstance().getPlaceholderManager().getUsedPlaceholderIdentifiersRecursive(value)) {
|
||||
if (identifier.startsWith("%rel_")) {
|
||||
relPlaceholders.add(identifier);
|
||||
relPlaceholders0.add(identifier);
|
||||
} else {
|
||||
placeholders.add(identifier);
|
||||
placeholders0.add(identifier);
|
||||
}
|
||||
}
|
||||
//avoiding rare concurrent modification in #update
|
||||
placeholders = placeholders0;
|
||||
relPlaceholders = relPlaceholders0;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -67,10 +70,11 @@ public class Property {
|
||||
* @param temporaryValue - temporary value to be assigned
|
||||
*/
|
||||
public void setTemporaryValue(String temporaryValue) {
|
||||
this.temporaryValue = RGBUtils.getInstance().applyFormats(temporaryValue, true);
|
||||
if (temporaryValue != null) {
|
||||
analyze(temporaryValue);
|
||||
this.temporaryValue = RGBUtils.getInstance().applyFormats(TAB.getInstance().getPlaceholderManager().color(temporaryValue), true);
|
||||
analyze(this.temporaryValue);
|
||||
} else {
|
||||
this.temporaryValue = null;
|
||||
analyze(rawValue);
|
||||
}
|
||||
update();
|
||||
@@ -82,7 +86,7 @@ public class Property {
|
||||
*/
|
||||
public void changeRawValue(String newValue) {
|
||||
if (rawValue.equals(newValue)) return;
|
||||
rawValue = RGBUtils.getInstance().applyFormats(newValue, true);
|
||||
rawValue = RGBUtils.getInstance().applyFormats(TAB.getInstance().getPlaceholderManager().color(newValue), true);
|
||||
if (temporaryValue == null) {
|
||||
analyze(rawValue);
|
||||
update();
|
||||
@@ -162,7 +166,7 @@ public class Property {
|
||||
|
||||
private String applyRemoveStrings(String text) {
|
||||
String reformatted = text;
|
||||
for (String removed : TAB.getInstance().getConfiguration().removeStrings) {
|
||||
for (String removed : TAB.getInstance().getConfiguration().getRemoveStrings()) {
|
||||
if (removed.startsWith("CONTAINS:") && reformatted.contains(removed.substring(9))) return "";
|
||||
if (removed.startsWith("STARTS:") && reformatted.startsWith(removed.substring(7))) return "";
|
||||
if (removed.startsWith("ENDS:") && reformatted.endsWith(removed.substring(5))) return "";
|
||||
@@ -185,11 +189,10 @@ public class Property {
|
||||
* @return format for the viewer
|
||||
*/
|
||||
public String getFormat(TabPlayer viewer) {
|
||||
if (viewer == null) return lastReplacedValue;
|
||||
String format = lastReplacedValue;
|
||||
for (String identifier : relPlaceholders) {
|
||||
RelationalPlaceholder pl = (RelationalPlaceholder) TAB.getInstance().getPlaceholderManager().getPlaceholder(identifier);
|
||||
if (pl != null) format = format.replace(pl.getIdentifier(), pl.getLastValue(viewer, owner));
|
||||
if (pl != null) format = format.replace(pl.getIdentifier(), viewer == null ? "" : pl.getLastValue(viewer, owner));
|
||||
}
|
||||
return format;
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
package me.neznamy.tab.shared;
|
||||
|
||||
public class PropertyUtils {
|
||||
|
||||
public static final String HEADER = "header";
|
||||
public static final String FOOTER = "footer";
|
||||
|
||||
public static final String TABPREFIX = "tabprefix";
|
||||
public static final String CUSTOMTABNAME = "customtabname";
|
||||
public static final String TABSUFFIX = "tabsuffix";
|
||||
|
||||
public static final String TAGPREFIX = "tagprefix";
|
||||
public static final String CUSTOMTAGNAME = "customtagname";
|
||||
public static final String TAGSUFFIX = "tagsuffix";
|
||||
|
||||
public static final String ABOVENAME = "abovename";
|
||||
public static final String NAMETAG = "nametag";
|
||||
public static final String BELOWNAME = "belowname";
|
||||
|
||||
private PropertyUtils() {
|
||||
}
|
||||
|
||||
public static String bossbarTitle(String name) {
|
||||
return "bossbar-title-" + name;
|
||||
}
|
||||
|
||||
public static String bossbarProgress(String name) {
|
||||
return "bossbar-progress-" + name;
|
||||
}
|
||||
|
||||
public static String bossbarColor(String name) {
|
||||
return "bossbar-color-" + name;
|
||||
}
|
||||
|
||||
public static String bossbarStyle(String name) {
|
||||
return "bossbar-style-" + name;
|
||||
}
|
||||
}
|
||||
+55
-56
@@ -6,62 +6,61 @@ package me.neznamy.tab.shared;
|
||||
public enum ProtocolVersion {
|
||||
|
||||
UNKNOWN (999),
|
||||
v1_16_5 (754),
|
||||
v1_16_4 (754),
|
||||
v1_16_3 (753),
|
||||
v1_16_2 (751),
|
||||
v1_16_1 (736),
|
||||
v1_16 (735),
|
||||
v1_15_2 (578),
|
||||
v1_15_1 (575),
|
||||
v1_15 (573),
|
||||
v1_14_4 (498),
|
||||
v1_14_3 (490),
|
||||
v1_14_2 (485),
|
||||
v1_14_1 (480),
|
||||
v1_14 (477),
|
||||
v1_13_2 (404),
|
||||
v1_13_1 (401),
|
||||
v1_13 (393),
|
||||
v1_12_2 (340),
|
||||
v1_12_1 (338),
|
||||
v1_12 (335),
|
||||
v1_11_2 (316),
|
||||
v1_11_1 (316),
|
||||
v1_11 (315),
|
||||
v1_10_2 (210),
|
||||
v1_10_1 (210),
|
||||
v1_10 (210),
|
||||
v1_9_4 (110),
|
||||
v1_9_3 (110),
|
||||
v1_9_2 (109),
|
||||
v1_9_1 (108),
|
||||
v1_9 (107),
|
||||
v1_8 (47),
|
||||
v1_7_10 (5),
|
||||
v1_7_9 (5),
|
||||
v1_7_8 (5),
|
||||
v1_7_7 (5),
|
||||
v1_7_6 (5),
|
||||
v1_7_5 (4),
|
||||
v1_7_4 (4),
|
||||
v1_7_2 (4),
|
||||
v1_6_4 (78),
|
||||
v1_6_2 (74),
|
||||
v1_6_1 (73),
|
||||
v1_5_2 (61),
|
||||
v1_5_1 (60),
|
||||
v1_5 (60),
|
||||
v1_4_7 (51),
|
||||
v1_4_6 (51);
|
||||
|
||||
//server version, always using latest on proxies
|
||||
public static ProtocolVersion SERVER_VERSION;
|
||||
V1_17_1 (756),
|
||||
V1_17 (755),
|
||||
V1_16_5 (754),
|
||||
V1_16_4 (754),
|
||||
V1_16_3 (753),
|
||||
V1_16_2 (751),
|
||||
V1_16_1 (736),
|
||||
V1_16 (735),
|
||||
V1_15_2 (578),
|
||||
V1_15_1 (575),
|
||||
V1_15 (573),
|
||||
V1_14_4 (498),
|
||||
V1_14_3 (490),
|
||||
V1_14_2 (485),
|
||||
V1_14_1 (480),
|
||||
V1_14 (477),
|
||||
V1_13_2 (404),
|
||||
V1_13_1 (401),
|
||||
V1_13 (393),
|
||||
V1_12_2 (340),
|
||||
V1_12_1 (338),
|
||||
V1_12 (335),
|
||||
V1_11_2 (316),
|
||||
V1_11_1 (316),
|
||||
V1_11 (315),
|
||||
V1_10_2 (210),
|
||||
V1_10_1 (210),
|
||||
V1_10 (210),
|
||||
V1_9_4 (110),
|
||||
V1_9_3 (110),
|
||||
V1_9_2 (109),
|
||||
V1_9_1 (108),
|
||||
V1_9 (107),
|
||||
V1_8 (47),
|
||||
V1_7_10 (5),
|
||||
V1_7_9 (5),
|
||||
V1_7_8 (5),
|
||||
V1_7_7 (5),
|
||||
V1_7_6 (5),
|
||||
V1_7_5 (4),
|
||||
V1_7_4 (4),
|
||||
V1_7_2 (4),
|
||||
V1_6_4 (78),
|
||||
V1_6_2 (74),
|
||||
V1_6_1 (73),
|
||||
V1_5_2 (61),
|
||||
V1_5_1 (60),
|
||||
V1_5 (60),
|
||||
V1_4_7 (51),
|
||||
V1_4_6 (51);
|
||||
|
||||
//version's network id found at https://wiki.vg/Protocol_version_numbers
|
||||
private int networkId;
|
||||
|
||||
//minor versio, such as 16
|
||||
//minor version, such as 16
|
||||
private int minorVersion;
|
||||
|
||||
//friendly name displayed in %player-version% placeholder
|
||||
@@ -91,7 +90,7 @@ public enum ProtocolVersion {
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns user-friendly name of the version (such as 1.16.2 instead of v1_16_2)
|
||||
* Returns user-friendly name of the version (such as 1.16.2 instead of V1_16_2)
|
||||
* @return
|
||||
*/
|
||||
public String getFriendlyName() {
|
||||
@@ -112,10 +111,10 @@ public enum ProtocolVersion {
|
||||
* @return version or UNKNOWN if version is unknown
|
||||
*/
|
||||
public static ProtocolVersion fromFriendlyName(String friendlyName) {
|
||||
if (friendlyName.startsWith("1.8")) return v1_8;
|
||||
if (friendlyName.startsWith("1.8")) return V1_8;
|
||||
try {
|
||||
return valueOf("v" + friendlyName.replace(".", "_"));
|
||||
} catch (Throwable e) {
|
||||
return valueOf("V" + friendlyName.replace(".", "_"));
|
||||
} catch (Exception e) {
|
||||
return UNKNOWN;
|
||||
}
|
||||
}
|
||||
+50
-14
@@ -25,16 +25,16 @@ public class TAB {
|
||||
private static TAB instance;
|
||||
|
||||
//version of plugin
|
||||
public static final String pluginVersion = "2.8.11-pre13";
|
||||
public static final String PLUGIN_VERSION = "2.9.2";
|
||||
|
||||
//player data
|
||||
public final Map<UUID, TabPlayer> data = new ConcurrentHashMap<UUID, TabPlayer>();
|
||||
private final Map<UUID, TabPlayer> data = new ConcurrentHashMap<>();
|
||||
|
||||
//the command
|
||||
public TabCommand command;
|
||||
|
||||
private TabCommand command;
|
||||
|
||||
//command used if plugin is disabled due to a broken configuration file
|
||||
public final DisabledCommand disabledCommand = new DisabledCommand();
|
||||
private final DisabledCommand disabledCommand = new DisabledCommand();
|
||||
|
||||
//platform interface
|
||||
private Platform platform;
|
||||
@@ -52,22 +52,26 @@ public class TAB {
|
||||
private FeatureManager featureManager;
|
||||
|
||||
//name of broken configuration file filled on load and used in disabledCommand
|
||||
public String brokenFile = "-";
|
||||
private String brokenFile = "-";
|
||||
|
||||
//platform-specific packet builder
|
||||
private PacketBuilder packetBuilder;
|
||||
|
||||
private Configs configuration;
|
||||
|
||||
public boolean debugMode;
|
||||
private boolean debugMode;
|
||||
|
||||
private boolean disabled;
|
||||
|
||||
private PlaceholderManager placeholderManager;
|
||||
|
||||
//server version, always using latest on proxies
|
||||
private ProtocolVersion serverVersion;
|
||||
|
||||
public TAB(Platform platform, PacketBuilder packetBuilder) {
|
||||
public TAB(Platform platform, PacketBuilder packetBuilder, ProtocolVersion serverVersion) {
|
||||
this.platform = platform;
|
||||
this.packetBuilder = packetBuilder;
|
||||
this.serverVersion = serverVersion;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -133,7 +137,7 @@ public class TAB {
|
||||
* @param message - message to be sent into console
|
||||
*/
|
||||
public void debug(String message) {
|
||||
if (debugMode) platform.sendConsoleMessage("&9[TAB DEBUG] " + message, true);
|
||||
if (isDebugMode()) platform.sendConsoleMessage("&9[TAB DEBUG] " + message, true);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -151,9 +155,9 @@ public class TAB {
|
||||
placeholderManager = new PlaceholderManager(this);
|
||||
featureManager.registerFeature("placeholders", placeholderManager);
|
||||
platform.loadFeatures();
|
||||
command = new TabCommand(this);
|
||||
setCommand(new TabCommand(this));
|
||||
featureManager.load();
|
||||
getPlayers().forEach(p -> p.markAsLoaded());
|
||||
getPlayers().forEach(p -> ((ITabPlayer)p).markAsLoaded());
|
||||
errorManager.printConsoleWarnCount();
|
||||
print('a', "Enabled in " + (System.currentTimeMillis()-time) + "ms");
|
||||
platform.callLoadEvent();
|
||||
@@ -161,7 +165,7 @@ public class TAB {
|
||||
} catch (YAMLException e) {
|
||||
print('c', "Did not enable due to a broken configuration file.");
|
||||
disabled = true;
|
||||
} catch (Throwable e) {
|
||||
} catch (Exception e) {
|
||||
errorManager.criticalError("Failed to enable. Did you just invent a new way to break the plugin by misconfiguring it?", e);
|
||||
disabled = true;
|
||||
}
|
||||
@@ -179,7 +183,7 @@ public class TAB {
|
||||
featureManager.unload();
|
||||
data.clear();
|
||||
platform.sendConsoleMessage("&a[TAB] Disabled in " + (System.currentTimeMillis()-time) + "ms", true);
|
||||
} catch (Throwable e) {
|
||||
} catch (Exception e) {
|
||||
errorManager.criticalError("Failed to disable", e);
|
||||
}
|
||||
}
|
||||
@@ -229,7 +233,7 @@ public class TAB {
|
||||
}
|
||||
|
||||
public String getPluginVersion() {
|
||||
return pluginVersion;
|
||||
return PLUGIN_VERSION;
|
||||
}
|
||||
|
||||
public Configs getConfiguration() {
|
||||
@@ -243,4 +247,36 @@ public class TAB {
|
||||
public PlaceholderManager getPlaceholderManager() {
|
||||
return placeholderManager;
|
||||
}
|
||||
|
||||
public TabCommand getCommand() {
|
||||
return command;
|
||||
}
|
||||
|
||||
public void setCommand(TabCommand command) {
|
||||
this.command = command;
|
||||
}
|
||||
|
||||
public boolean isDebugMode() {
|
||||
return debugMode;
|
||||
}
|
||||
|
||||
public void setDebugMode(boolean debugMode) {
|
||||
this.debugMode = debugMode;
|
||||
}
|
||||
|
||||
public String getBrokenFile() {
|
||||
return brokenFile;
|
||||
}
|
||||
|
||||
public void setBrokenFile(String brokenFile) {
|
||||
this.brokenFile = brokenFile;
|
||||
}
|
||||
|
||||
public DisabledCommand getDisabledCommand() {
|
||||
return disabledCommand;
|
||||
}
|
||||
|
||||
public ProtocolVersion getServerVersion() {
|
||||
return serverVersion;
|
||||
}
|
||||
}
|
||||
+6
-5
@@ -18,23 +18,24 @@ public class DisabledCommand {
|
||||
* @return list of messages to send back
|
||||
*/
|
||||
public List<String> execute(String[] args, boolean hasReloadPermission, boolean hasAdminPermission) {
|
||||
List<String> messages = new ArrayList<String>();
|
||||
List<String> messages = new ArrayList<>();
|
||||
if (args.length == 1 && args[0].equalsIgnoreCase("reload")) {
|
||||
if (hasReloadPermission) {
|
||||
TAB.getInstance().load();
|
||||
if (TAB.getInstance().isDisabled()) {
|
||||
messages.add(TAB.getInstance().getConfiguration().reloadFailed.replace("%file%", TAB.getInstance().brokenFile));
|
||||
messages.add(TAB.getInstance().getConfiguration().getReloadFailedMessage().replace("%file%", TAB.getInstance().getBrokenFile()));
|
||||
} else {
|
||||
messages.add(TAB.getInstance().getConfiguration().translation.getString("reloaded"));
|
||||
messages.add(TAB.getInstance().getConfiguration().getTranslation().getString("reloaded"));
|
||||
}
|
||||
} else {
|
||||
messages.add(TAB.getInstance().getConfiguration().translation.getString("no_permission"));
|
||||
//cannot take message from file when syntax is broken
|
||||
messages.add("&cI'm sorry, but you do not have permission to perform this command. Please contact the server administrators if you believe that this is in error.");
|
||||
}
|
||||
} else {
|
||||
if (hasAdminPermission) {
|
||||
String command = TAB.getInstance().getPlatform().getSeparatorType().equals("world") ? "/tab" : "/btab";
|
||||
messages.add("&m ");
|
||||
messages.add(" &cPlugin is disabled due to a broken configuration file (" + TAB.getInstance().brokenFile + "). Check console for more details.");
|
||||
messages.add(" &cPlugin is disabled due to a broken configuration file (" + TAB.getInstance().getBrokenFile() + "). Check console for more details.");
|
||||
messages.add(" &8>> &3&l" + command + " reload");
|
||||
messages.add(" - &7Reloads plugin and config");
|
||||
messages.add("&m ");
|
||||
+28
-11
@@ -6,6 +6,7 @@ import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import me.neznamy.tab.api.TabPlayer;
|
||||
import me.neznamy.tab.shared.PropertyUtils;
|
||||
import me.neznamy.tab.shared.TAB;
|
||||
/**
|
||||
* Abstract class representing a subcommand of "/tab" command
|
||||
@@ -13,10 +14,10 @@ import me.neznamy.tab.shared.TAB;
|
||||
public abstract class SubCommand {
|
||||
|
||||
//all properties assignable with a command
|
||||
public static String[] allProperties = {"tabprefix", "tabsuffix", "tagprefix", "tagsuffix", "customtabname", "abovename", "belowname", "customtagname"};
|
||||
private static String[] allProperties = {PropertyUtils.TABPREFIX, PropertyUtils.TABSUFFIX, PropertyUtils.TAGPREFIX, PropertyUtils.TAGSUFFIX, PropertyUtils.CUSTOMTABNAME, PropertyUtils.ABOVENAME, PropertyUtils.BELOWNAME, PropertyUtils.CUSTOMTAGNAME};
|
||||
|
||||
//properties that require unlimited nametag mode
|
||||
protected final List<String> extraProperties = Arrays.asList("abovename", "belowname", "customtagname");
|
||||
protected final List<String> extraProperties = Arrays.asList(PropertyUtils.ABOVENAME, PropertyUtils.BELOWNAME, PropertyUtils.CUSTOMTAGNAME);
|
||||
|
||||
//name of this subcommand
|
||||
private String name;
|
||||
@@ -25,14 +26,14 @@ public abstract class SubCommand {
|
||||
private String permission;
|
||||
|
||||
//subcommands of this command
|
||||
public Map<String, SubCommand> subcommands = new HashMap<String, SubCommand>();
|
||||
private Map<String, SubCommand> subcommands = new HashMap<>();
|
||||
|
||||
/**
|
||||
* Constructs new instance with given parameters
|
||||
* @param name - command name
|
||||
* @param permission - permission requirement
|
||||
*/
|
||||
public SubCommand(String name, String permission) {
|
||||
protected SubCommand(String name, String permission) {
|
||||
this.name = name;
|
||||
this.permission = permission;
|
||||
}
|
||||
@@ -42,7 +43,7 @@ public abstract class SubCommand {
|
||||
* @param subcommand - subcommand to register
|
||||
*/
|
||||
public void registerSubCommand(SubCommand subcommand) {
|
||||
subcommands.put(subcommand.getName(), subcommand);
|
||||
getSubcommands().put(subcommand.getName(), subcommand);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -109,7 +110,7 @@ public abstract class SubCommand {
|
||||
* @return List of compatible players
|
||||
*/
|
||||
public List<String> getPlayers(String nameStart){
|
||||
List<String> suggestions = new ArrayList<String>();
|
||||
List<String> suggestions = new ArrayList<>();
|
||||
for (TabPlayer all : TAB.getInstance().getPlayers()) {
|
||||
if (all.getName().toLowerCase().startsWith(nameStart.toLowerCase())) suggestions.add(all.getName());
|
||||
}
|
||||
@@ -130,17 +131,17 @@ public abstract class SubCommand {
|
||||
argument = arguments[0].toLowerCase();
|
||||
}
|
||||
if (arguments.length < 2) {
|
||||
List<String> suggestions = new ArrayList<String>();
|
||||
for (String subcommand : subcommands.keySet()) {
|
||||
List<String> suggestions = new ArrayList<>();
|
||||
for (String subcommand : getSubcommands().keySet()) {
|
||||
if (subcommand.startsWith(argument)) suggestions.add(subcommand);
|
||||
}
|
||||
return suggestions;
|
||||
}
|
||||
SubCommand subcommand = subcommands.get(argument);
|
||||
SubCommand subcommand = getSubcommands().get(argument);
|
||||
if (subcommand != null) {
|
||||
return subcommand.complete(sender, Arrays.copyOfRange(arguments, 1, arguments.length));
|
||||
}
|
||||
return new ArrayList<String>();
|
||||
return new ArrayList<>();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -162,7 +163,7 @@ public abstract class SubCommand {
|
||||
* @return translation from file
|
||||
*/
|
||||
public String getTranslation(String key) {
|
||||
return TAB.getInstance().getConfiguration().translation.getString(key);
|
||||
return TAB.getInstance().getConfiguration().getTranslation().getString(key);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -171,4 +172,20 @@ public abstract class SubCommand {
|
||||
* @param args - arguments of the command
|
||||
*/
|
||||
public abstract void execute(TabPlayer sender, String[] args);
|
||||
|
||||
public static String[] getAllProperties() {
|
||||
return allProperties;
|
||||
}
|
||||
|
||||
public static void setAllProperties(String[] allProperties) {
|
||||
SubCommand.allProperties = allProperties;
|
||||
}
|
||||
|
||||
public Map<String, SubCommand> getSubcommands() {
|
||||
return subcommands;
|
||||
}
|
||||
|
||||
public void setSubcommands(Map<String, SubCommand> subcommands) {
|
||||
this.subcommands = subcommands;
|
||||
}
|
||||
}
|
||||
+15
-15
@@ -8,6 +8,7 @@ import java.util.Set;
|
||||
import com.google.common.collect.Sets;
|
||||
|
||||
import me.neznamy.tab.api.TabPlayer;
|
||||
import me.neznamy.tab.shared.PropertyUtils;
|
||||
import me.neznamy.tab.shared.TAB;
|
||||
import me.neznamy.tab.shared.command.level1.AnnounceCommand;
|
||||
import me.neznamy.tab.shared.command.level1.BossBarCommand;
|
||||
@@ -23,7 +24,6 @@ import me.neznamy.tab.shared.command.level1.ReloadCommand;
|
||||
import me.neznamy.tab.shared.command.level1.ScoreboardCommand;
|
||||
import me.neznamy.tab.shared.command.level1.SendCommand;
|
||||
import me.neznamy.tab.shared.command.level1.SetCollisionCommand;
|
||||
import me.neznamy.tab.shared.command.level1.WidthCommand;
|
||||
|
||||
/**
|
||||
* The core command handler
|
||||
@@ -55,20 +55,19 @@ public class TabCommand extends SubCommand {
|
||||
registerSubCommand(new SetCollisionCommand());
|
||||
if (tab.isPremium()) {
|
||||
registerSubCommand(new ScoreboardCommand());
|
||||
registerSubCommand(new WidthCommand());
|
||||
}
|
||||
Set<String> properties = Sets.newHashSet("tabprefix", "tabsuffix", "tagprefix", "tagsuffix", "customtabname", "abovename", "belowname", "customtagname");
|
||||
for (Object line : ((DebugCommand)subcommands.get("debug")).getExtraLines()) {
|
||||
Set<String> properties = Sets.newHashSet(PropertyUtils.TABPREFIX, PropertyUtils.TABSUFFIX, PropertyUtils.TAGPREFIX, PropertyUtils.TAGSUFFIX, PropertyUtils.CUSTOMTABNAME, PropertyUtils.ABOVENAME, PropertyUtils.BELOWNAME, PropertyUtils.CUSTOMTAGNAME);
|
||||
for (Object line : ((DebugCommand)getSubcommands().get("debug")).getExtraLines()) {
|
||||
properties.add(line.toString());
|
||||
}
|
||||
SubCommand.allProperties = properties.toArray(new String[0]);
|
||||
SubCommand.setAllProperties(properties.toArray(new String[0]));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(TabPlayer sender, String[] args) {
|
||||
if (args.length > 0) {
|
||||
String arg0 = args[0];
|
||||
SubCommand command = subcommands.get(arg0.toLowerCase());
|
||||
SubCommand command = getSubcommands().get(arg0.toLowerCase());
|
||||
if (command != null) {
|
||||
if (command.hasPermission(sender)) {
|
||||
command.execute(sender, Arrays.copyOfRange(args, 1, args.length));
|
||||
@@ -91,22 +90,23 @@ public class TabCommand extends SubCommand {
|
||||
if (sender == null) tab.getPlatform().sendConsoleMessage("&3TAB v" + tab.getPluginVersion(), true);
|
||||
if ((sender == null || sender.hasPermission("tab.admin"))) {
|
||||
String command = tab.getPlatform().getSeparatorType().equals("world") ? "/tab" : "/btab";
|
||||
String prefix = " &8>> &3&l";
|
||||
sendMessage(sender, "&m ");
|
||||
sendMessage(sender, " &8>> &3&l" + command + " reload");
|
||||
sendMessage(sender, prefix + command + " reload");
|
||||
sendMessage(sender, " - &7Reloads plugin and config");
|
||||
sendMessage(sender, " &8>> &3&l" + command + " &9group&3/&9player &3<name> &9<property> &3<value...>");
|
||||
sendMessage(sender, prefix + command + " &9group&3/&9player &3<name> &9<property> &3<value...>");
|
||||
sendMessage(sender, " - &7Do &8/tab group/player &7to show properties");
|
||||
sendMessage(sender, " &8>> &3&l" + command + " ntpreview");
|
||||
sendMessage(sender, prefix + command + " ntpreview");
|
||||
sendMessage(sender, " - &7Shows your nametag for yourself, for testing purposes");
|
||||
sendMessage(sender, " &8>> &3&l" + command + " announce bar &3<name> &9<seconds>");
|
||||
sendMessage(sender, prefix + command + " announce bar &3<name> &9<seconds>");
|
||||
sendMessage(sender, " - &7Temporarily displays bossbar to all players");
|
||||
sendMessage(sender, " &8>> &3&l" + command + " parse <placeholder> ");
|
||||
sendMessage(sender, prefix + command + " parse <placeholder> ");
|
||||
sendMessage(sender, " - &7Test if a placeholder works");
|
||||
sendMessage(sender, " &8>> &3&l" + command + " debug [player]");
|
||||
sendMessage(sender, prefix + command + " debug [player]");
|
||||
sendMessage(sender, " - &7displays debug information about player");
|
||||
sendMessage(sender, " &8>> &3&l" + command + " cpu");
|
||||
sendMessage(sender, prefix + command + " cpu");
|
||||
sendMessage(sender, " - &7shows CPU usage of the plugin");
|
||||
sendMessage(sender, " &8>> &4&l" + command + " group/player <name> remove");
|
||||
sendMessage(sender, prefix + command + " group/player <name> remove");
|
||||
sendMessage(sender, " - &7Clears all data about player/group");
|
||||
sendMessage(sender, "&m ");
|
||||
}
|
||||
@@ -114,7 +114,7 @@ public class TabCommand extends SubCommand {
|
||||
|
||||
@Override
|
||||
public List<String> complete(TabPlayer sender, String[] arguments) {
|
||||
if (!sender.hasPermission("tab.tabcomplete")) return new ArrayList<String>();
|
||||
if (!hasPermission(sender, "tab.tabcomplete")) return new ArrayList<>();
|
||||
return super.complete(sender, arguments);
|
||||
}
|
||||
}
|
||||
+3
-3
@@ -17,8 +17,8 @@ public class AnnounceCommand extends SubCommand {
|
||||
*/
|
||||
public AnnounceCommand() {
|
||||
super("announce", null);
|
||||
subcommands.put("bar", new AnnounceBarCommand());
|
||||
subcommands.put("scoreboard", new AnnounceScoreboardCommand());
|
||||
getSubcommands().put("bar", new AnnounceBarCommand());
|
||||
getSubcommands().put("scoreboard", new AnnounceScoreboardCommand());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -29,7 +29,7 @@ public class AnnounceCommand extends SubCommand {
|
||||
return;
|
||||
}
|
||||
String arg0 = args[0].toLowerCase();
|
||||
SubCommand command = subcommands.get(arg0);
|
||||
SubCommand command = getSubcommands().get(arg0);
|
||||
if (command != null) {
|
||||
if (command.hasPermission(sender)) {
|
||||
command.execute(sender, Arrays.copyOfRange(args, 1, args.length));
|
||||
+2
-2
@@ -21,14 +21,14 @@ public class BossBarCommand extends SubCommand{
|
||||
public void execute(TabPlayer sender, String[] args) {
|
||||
BossBar bossbar = (BossBar) TAB.getInstance().getFeatureManager().getFeature("bossbar");
|
||||
if (bossbar == null) {
|
||||
sender.sendMessage("&cBossbar feature is not enabled, therefore toggle command cannot be used.", true);
|
||||
sendMessage(sender, "&cBossbar feature is not enabled, therefore toggle command cannot be used.");
|
||||
return;
|
||||
}
|
||||
if (sender == null) {
|
||||
sendMessage(sender, "&cThis command must be ran from the game");
|
||||
return;
|
||||
}
|
||||
if (!bossbar.permToToggle || sender.hasPermission("tab.togglebar")) {
|
||||
if (!bossbar.isPermToToggle() || sender.hasPermission("tab.togglebar")) {
|
||||
sender.setBossbarVisible(!sender.hasBossbarVisible(), true);
|
||||
} else {
|
||||
sender.sendMessage(getTranslation("no_permission"), true);
|
||||
+18
-18
@@ -21,8 +21,8 @@ public class CpuCommand extends SubCommand {
|
||||
|
||||
private final DecimalFormat decimal3 = new DecimalFormat("#.###");
|
||||
|
||||
private final char LINE_CHAR = (char)9553;
|
||||
private final String SEPARATOR = "&8&l" + LINE_CHAR + "&8&m ";
|
||||
private static final char LINE_CHAR = (char)9553;
|
||||
private static final String SEPARATOR = "&8&l" + LINE_CHAR + "&8&m ";
|
||||
|
||||
/**
|
||||
* Constructs new instance
|
||||
@@ -59,21 +59,21 @@ public class CpuCommand extends SubCommand {
|
||||
for (Entry<String, Float> entry : placeholders.entrySet()) {
|
||||
if (printCounter++ == 5) break;
|
||||
String refresh = "";
|
||||
Placeholder p = TAB.getInstance().getPlaceholderManager().getPlaceholder(entry.getKey().toString());
|
||||
Placeholder p = TAB.getInstance().getPlaceholderManager().getPlaceholder(entry.getKey());
|
||||
if (p != null) refresh = " &8(" + p.getRefresh() + ")&7";
|
||||
sendMessage(sender, String.format("&8&l" + LINE_CHAR + " &7%s - %s%%", entry.getKey() + refresh, colorize(decimal3.format(entry.getValue()), 1, 0.3f)));
|
||||
sendMessage(sender, String.format("&8&l%s &7%s - %s%%", LINE_CHAR, entry.getKey() + refresh, colorize(decimal3.format(entry.getValue()), 1, 0.3f)));
|
||||
}
|
||||
sendMessage(sender, SEPARATOR);
|
||||
sendMessage(sender, "&8&l" + LINE_CHAR + " &6Some internal separately measured methods:");
|
||||
for (Entry<String, Float> entry : tab.getCPUManager().getMethodUsage().entrySet()) {
|
||||
sendMessage(sender, String.format("&8&l" + LINE_CHAR + " &7%s: %s%%", entry.getKey(), colorize(decimal3.format(entry.getValue()), 5, 2)));
|
||||
sendMessage(sender, String.format("&8&l%s &7%s: %s%%", LINE_CHAR, entry.getKey(), colorize(decimal3.format(entry.getValue()), 5, 2)));
|
||||
}
|
||||
sendMessage(sender, SEPARATOR);
|
||||
if (tab.getPlatform().getSeparatorType().equals("server")) {
|
||||
sendMessage(sender, "&8&l" + LINE_CHAR + " &6Placeholder usage on Bukkit servers:");
|
||||
for (Entry<String, Float> entry : bridgeplaceholders.entrySet()) {
|
||||
if (entry.getValue() < 0.1) continue;
|
||||
sendMessage(sender, String.format("&8&l" + LINE_CHAR + " &7%s - %s%%", entry.getKey(), colorize(decimal3.format(entry.getValue()), 1, 0.3f)));
|
||||
sendMessage(sender, String.format("&8&l%s &7%s - %s%%", LINE_CHAR, entry.getKey(), colorize(decimal3.format(entry.getValue()), 1, 0.3f)));
|
||||
}
|
||||
sendMessage(sender, SEPARATOR);
|
||||
}
|
||||
@@ -83,18 +83,18 @@ public class CpuCommand extends SubCommand {
|
||||
sendToConsole(features);
|
||||
}
|
||||
sendMessage(sender, SEPARATOR);
|
||||
sendMessage(sender, String.format("&8&l" + LINE_CHAR + " &7Threads created by the plugin (active/total): &7%s", tab.getCPUManager().getThreadCount()));
|
||||
sendMessage(sender, String.format("&8&l%s &7Threads created by the plugin (active/total): &7%s", LINE_CHAR, tab.getCPUManager().getThreadCount()));
|
||||
if (sender != null) {
|
||||
sendPacketCountToPlayer(sender);
|
||||
} else {
|
||||
sendPacketCountToConsole();
|
||||
}
|
||||
sendMessage(sender, String.format("&8&l" + LINE_CHAR + " &6&lPlaceholders Total: &a&l%s%%", colorize(decimal3.format(placeholdersTotal), 10, 5)));
|
||||
sendMessage(sender, String.format("&8&l%s &6&lPlaceholders Total: &a&l%s%%", LINE_CHAR, colorize(decimal3.format(placeholdersTotal), 10, 5)));
|
||||
if (tab.getPlatform().getSeparatorType().equals("server")) {
|
||||
sendMessage(sender, String.format("&8&l" + LINE_CHAR + " &6&lBukkit bridge placeholders Total: &a&l%s%%", colorize(decimal3.format(bridgeplaceholdersTotal), 10, 5)));
|
||||
sendMessage(sender, String.format("&8&l%s &6&lBukkit bridge placeholders Total: &a&l%s%%", LINE_CHAR, colorize(decimal3.format(bridgeplaceholdersTotal), 10, 5)));
|
||||
}
|
||||
sendMessage(sender, String.format("&8&l" + LINE_CHAR + " &6&lPlugin internals: &a&l%s%%", colorize(decimal3.format(featuresTotal-placeholdersTotal), 10, 5)));
|
||||
sendMessage(sender, String.format("&8&l" + LINE_CHAR + " &6&lTotal: &e&l%s%%", colorize(decimal3.format(featuresTotal + bridgeplaceholdersTotal), 10, 5)));
|
||||
sendMessage(sender, String.format("&8&l%s &6&lPlugin internals: &a&l%s%%", LINE_CHAR, colorize(decimal3.format(featuresTotal-placeholdersTotal), 10, 5)));
|
||||
sendMessage(sender, String.format("&8&l%s &6&lTotal: &e&l%s%%", LINE_CHAR, colorize(decimal3.format(featuresTotal + bridgeplaceholdersTotal), 10, 5)));
|
||||
sendMessage(sender, "&8&l" + LINE_CHAR + "&8&m &r&8&l[ &bTAB CPU Stats &8&l]&r&8&l&m ");
|
||||
sendMessage(sender, " ");
|
||||
}
|
||||
@@ -106,10 +106,10 @@ public class CpuCommand extends SubCommand {
|
||||
for (Float f : entry.getValue().values()) {
|
||||
featureTotal += f;
|
||||
}
|
||||
String core = String.format("&8&l" + LINE_CHAR + " &7%s (%s%%&7):", entry.getKey(), colorize(decimal3.format(featureTotal), 5, 1));
|
||||
List<String> messages = new ArrayList<String>();
|
||||
String core = String.format("&8&l%s &7%s (%s%%&7):", LINE_CHAR, entry.getKey(), colorize(decimal3.format(featureTotal), 5, 1));
|
||||
List<String> messages = new ArrayList<>();
|
||||
for (Entry<UsageType, Float> type : entry.getValue().entrySet()){
|
||||
messages.add(String.format("&8&l" + LINE_CHAR + " &7%s - %s%%", type.getKey(), colorize(decimal3.format(type.getValue()), 5, 1)));
|
||||
messages.add(String.format("&8&l%s &7%s - %s%%", LINE_CHAR, type.getKey(), colorize(decimal3.format(type.getValue()), 5, 1)));
|
||||
}
|
||||
TAB.getInstance().getPlatform().sendConsoleMessage(core, true);
|
||||
for (String message : messages) {
|
||||
@@ -125,8 +125,8 @@ public class CpuCommand extends SubCommand {
|
||||
for (Float f : entry.getValue().values()) {
|
||||
featureTotal += f;
|
||||
}
|
||||
String core = String.format("&8&l" + LINE_CHAR + " &7%s (%s%%&7):", entry.getKey(), colorize(decimal3.format(featureTotal), 5, 1));
|
||||
List<String> messages = new ArrayList<String>();
|
||||
String core = String.format("&8&l%s &7%s (%s%%&7):", LINE_CHAR, entry.getKey(), colorize(decimal3.format(featureTotal), 5, 1));
|
||||
List<String> messages = new ArrayList<>();
|
||||
for (Entry<UsageType, Float> type : entry.getValue().entrySet()){
|
||||
messages.add("&3" + type.getKey().toString() + " - " + colorize(decimal3.format(type.getValue()), 5, 1) + "%");
|
||||
}
|
||||
@@ -139,7 +139,7 @@ public class CpuCommand extends SubCommand {
|
||||
public void sendPacketCountToConsole() {
|
||||
Map<Object, AtomicInteger> packets = TAB.getInstance().getCPUManager().getSentPackets();
|
||||
int count = 0;
|
||||
List<String> messages = new ArrayList<String>();
|
||||
List<String> messages = new ArrayList<>();
|
||||
for (Entry<Object, AtomicInteger> entry : packets.entrySet()) {
|
||||
count += entry.getValue().get();
|
||||
messages.add("&8&l" + LINE_CHAR + " &7" + entry.getKey().toString() + " - " + entry.getValue());
|
||||
@@ -153,7 +153,7 @@ public class CpuCommand extends SubCommand {
|
||||
public void sendPacketCountToPlayer(TabPlayer sender) {
|
||||
Map<Object, AtomicInteger> packets = TAB.getInstance().getCPUManager().getSentPackets();
|
||||
int count = 0;
|
||||
List<String> messages = new ArrayList<String>();
|
||||
List<String> messages = new ArrayList<>();
|
||||
for (Entry<Object, AtomicInteger> entry : packets.entrySet()) {
|
||||
count += entry.getValue().get();
|
||||
messages.add("&3" + entry.getKey().toString() + " - " + entry.getValue());
|
||||
+5
-8
@@ -19,15 +19,12 @@ public class CpuTestCommand extends SubCommand {
|
||||
|
||||
@Override
|
||||
public void execute(TabPlayer sender, String[] args) {
|
||||
new Thread(new Runnable() {
|
||||
new Thread(() -> {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
sendMessage(sender, "&9Performing CPU test");
|
||||
long time = System.currentTimeMillis();
|
||||
test();
|
||||
sendMessage(sender, "&9Task took &6" + (System.currentTimeMillis()-time) + "ms &9to process");
|
||||
}
|
||||
sendMessage(sender, "&9Performing CPU test");
|
||||
long time = System.currentTimeMillis();
|
||||
test();
|
||||
sendMessage(sender, "&9Task took &6" + (System.currentTimeMillis()-time) + "ms &9to process");
|
||||
}).start();
|
||||
}
|
||||
|
||||
+57
-38
@@ -1,5 +1,6 @@
|
||||
package me.neznamy.tab.shared.command.level1;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
@@ -8,11 +9,13 @@ import com.google.common.collect.Lists;
|
||||
|
||||
import me.neznamy.tab.api.TabPlayer;
|
||||
import me.neznamy.tab.shared.Property;
|
||||
import me.neznamy.tab.shared.PropertyUtils;
|
||||
import me.neznamy.tab.shared.TAB;
|
||||
import me.neznamy.tab.shared.command.SubCommand;
|
||||
import me.neznamy.tab.shared.features.GroupRefresher;
|
||||
import me.neznamy.tab.shared.features.NameTag;
|
||||
import me.neznamy.tab.shared.features.Playerlist;
|
||||
import me.neznamy.tab.shared.features.sorting.types.GroupPermission;
|
||||
|
||||
/**
|
||||
* Handler for "/tab debug" subcommand
|
||||
@@ -49,27 +52,30 @@ public class DebugCommand extends SubCommand {
|
||||
*/
|
||||
private void debug(TabPlayer sender, TabPlayer analyzed) {
|
||||
TAB tab = TAB.getInstance();
|
||||
String separator = "&7&m>-------------------------------<";
|
||||
sendMessage(sender, "&3[TAB] &a&lShowing debug information");
|
||||
sendMessage(sender, "&7&m>-------------------------------<");
|
||||
sendMessage(sender, "&6Server version: &a" + tab.getPlatform().getServerVersion());
|
||||
sendMessage(sender, "&6Plugin version: &a" + tab.getPluginVersion() + (tab.isPremium() ? " Premium" : ""));
|
||||
if (tab.getErrorManager().errorLog.exists()) {
|
||||
sendMessage(sender, "&6" + tab.getErrorManager().errorLog.getPath() + " size: &c" + tab.getErrorManager().errorLog.length()/1024 + "KB");
|
||||
sendMessage(sender, separator);
|
||||
String c2 = tab.isPremium() ? "&b" : "&a";
|
||||
sendMessage(sender, "&6Server version: " + c2 + tab.getPlatform().getServerVersion());
|
||||
sendMessage(sender, "&6Plugin version: " + c2 + tab.getPluginVersion() + (tab.isPremium() ? " Premium" : ""));
|
||||
if (tab.getErrorManager().getErrorLog().exists()) {
|
||||
sendMessage(sender, "&6" + tab.getErrorManager().getErrorLog().getPath() + " size: &c" + tab.getErrorManager().getErrorLog().length()/1024 + "KB");
|
||||
}
|
||||
sendMessage(sender, "&6Permission plugin: &a" + tab.getPermissionPlugin().getName());
|
||||
sendMessage(sender, getGroupChoiceLogic());
|
||||
sendMessage(sender, "&6Sorting system: &a" + getSortingType());
|
||||
sendMessage(sender, "&7&m>-------------------------------<");
|
||||
sendMessage(sender, "&6Permission plugin: " + c2 + tab.getPermissionPlugin().getName());
|
||||
sendMessage(sender, "&6Permission group choice logic: " + c2 + getGroupChoiceLogic());
|
||||
sendMessage(sender, "&6Sorting system: " + c2 + getSortingType());
|
||||
sendMessage(sender, separator);
|
||||
if (analyzed == null) return;
|
||||
sendMessage(sender, "&ePlayer: &a" + analyzed.getName());
|
||||
sendMessage(sender, getGroup(analyzed));
|
||||
sendMessage(sender, getTeamName(analyzed));
|
||||
sendMessage(sender, getTeamNameNote(analyzed));
|
||||
if (tab.getFeatureManager().isFeatureEnabled("playerlist")) {
|
||||
Playerlist playerlist = (Playerlist) tab.getFeatureManager().getFeature("playerlist");
|
||||
boolean disabledPlayerlist = playerlist.isDisabledWorld(playerlist.disabledWorlds, analyzed.getWorldName());
|
||||
showProperty(sender, analyzed, "tabprefix", disabledPlayerlist);
|
||||
showProperty(sender, analyzed, "tabsuffix", disabledPlayerlist);
|
||||
showProperty(sender, analyzed, "customtabname", disabledPlayerlist);
|
||||
boolean disabledPlayerlist = playerlist.isDisabledWorld(playerlist.getDisabledWorlds(), analyzed.getWorldName());
|
||||
showProperty(sender, analyzed, PropertyUtils.TABPREFIX, disabledPlayerlist);
|
||||
showProperty(sender, analyzed, PropertyUtils.TABSUFFIX, disabledPlayerlist);
|
||||
showProperty(sender, analyzed, PropertyUtils.CUSTOMTABNAME, disabledPlayerlist);
|
||||
} else {
|
||||
sendMessage(sender, "&atabprefix: &cDisabled");
|
||||
sendMessage(sender, "&atabsuffix: &cDisabled");
|
||||
@@ -77,8 +83,8 @@ public class DebugCommand extends SubCommand {
|
||||
}
|
||||
if (tab.getFeatureManager().getNameTagFeature() != null) {
|
||||
boolean disabledNametags = tab.getFeatureManager().getNameTagFeature().isDisabledWorld(analyzed.getWorldName());
|
||||
showProperty(sender, analyzed, "tagprefix", disabledNametags);
|
||||
showProperty(sender, analyzed, "tagsuffix", disabledNametags);
|
||||
showProperty(sender, analyzed, PropertyUtils.TAGPREFIX, disabledNametags);
|
||||
showProperty(sender, analyzed, PropertyUtils.TAGSUFFIX, disabledNametags);
|
||||
for (Object line : getExtraLines()) {
|
||||
showProperty(sender, analyzed, line.toString(), disabledNametags);
|
||||
}
|
||||
@@ -86,7 +92,7 @@ public class DebugCommand extends SubCommand {
|
||||
sendMessage(sender, "&atagprefix: &cDisabled");
|
||||
sendMessage(sender, "&atagsuffix: &cDisabled");
|
||||
}
|
||||
sendMessage(sender, "&7&m>-------------------------------<");
|
||||
sendMessage(sender, separator);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -95,12 +101,12 @@ public class DebugCommand extends SubCommand {
|
||||
*/
|
||||
private String getGroupChoiceLogic() {
|
||||
GroupRefresher group = (GroupRefresher) TAB.getInstance().getFeatureManager().getFeature("group");
|
||||
if (group.groupsByPermissions) {
|
||||
return "&6Permission group choice logic: &8&mPrimary group&8 / &r&8&mChoose from list&8 / &aPermissions";
|
||||
} else if (group.usePrimaryGroup) {
|
||||
return "&6Permission group choice logic: &aPrimary group&8 / &r&8&mChoose from list&8 / &r&8&mPermissions";
|
||||
if (group.isGroupsByPermissions()) {
|
||||
return "Permissions";
|
||||
} else if (group.isUsePrimaryGroup()) {
|
||||
return "Primary group";
|
||||
} else {
|
||||
return "&6Permission group choice logic: &8&mPrimary group&r&8 / &aChoose from list&8 / &r&8&mPermissions";
|
||||
return "Choose from list";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -112,12 +118,12 @@ public class DebugCommand extends SubCommand {
|
||||
NameTag nametag = TAB.getInstance().getFeatureManager().getNameTagFeature();
|
||||
if (nametag != null) {
|
||||
if (TAB.getInstance().isPremium()) {
|
||||
String sortingType = nametag.sorting.typesToString();
|
||||
String sortingType = nametag.getSorting().typesToString();
|
||||
if (sortingType.contains("PLACEHOLDER")) {
|
||||
sortingType += " - " + nametag.sorting.sortingPlaceholder;
|
||||
sortingType += " - " + nametag.getSorting().getSortingPlaceholder();
|
||||
}
|
||||
return sortingType;
|
||||
} else if (nametag.sorting.sorting.get(0).getClass().getSimpleName().equals("GroupPermission")) {
|
||||
} else if (nametag.getSorting().getSorting().get(0) instanceof GroupPermission) {
|
||||
return "Permissions &c(this option was enabled by user, it is disabled by default!)";
|
||||
} else {
|
||||
return "Groups";
|
||||
@@ -134,14 +140,14 @@ public class DebugCommand extends SubCommand {
|
||||
*/
|
||||
private String getGroup(TabPlayer analyzed) {
|
||||
GroupRefresher group = (GroupRefresher) TAB.getInstance().getFeatureManager().getFeature("group");
|
||||
if (group.groupsByPermissions) {
|
||||
if (group.isGroupsByPermissions()) {
|
||||
return "&eHighest permission for group: &a" + analyzed.getGroup();
|
||||
} else if (group.usePrimaryGroup) {
|
||||
} else if (group.isUsePrimaryGroup()) {
|
||||
return "&ePrimary permission group: &a" + analyzed.getGroup();
|
||||
} else {
|
||||
try {
|
||||
return "&eFull permission group list: &a" + Arrays.toString(TAB.getInstance().getPermissionPlugin().getAllGroups(analyzed)) + "\n&eChosen group: &a" + analyzed.getGroup();
|
||||
} catch (Throwable e) {
|
||||
} catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException | SecurityException | ClassNotFoundException e) {
|
||||
return "&eFull permission group list: &a[]\n&eChosen group: &a" + analyzed.getGroup();
|
||||
}
|
||||
}
|
||||
@@ -157,29 +163,41 @@ public class DebugCommand extends SubCommand {
|
||||
if (TAB.getInstance().getFeatureManager().getNameTagFeature().isDisabledWorld(analyzed.getWorldName())) {
|
||||
return "&eTeam name: &cSorting is disabled in player's " + TAB.getInstance().getPlatform().getSeparatorType();
|
||||
} else {
|
||||
String s = "&eTeam name: &a" + analyzed.getTeamName();
|
||||
if (analyzed.getTeamNameNote() != null) s += "\n&eTeam name note: &a" + analyzed.getTeamNameNote();
|
||||
return s;
|
||||
return "&eTeam name: &a" + analyzed.getTeamName();
|
||||
}
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns team name note of specified player
|
||||
* @param analyzed - player to get team name note of
|
||||
* @return team name note of specified player
|
||||
*/
|
||||
private String getTeamNameNote(TabPlayer analyzed) {
|
||||
if (TAB.getInstance().getFeatureManager().getNameTagFeature() != null &&
|
||||
!TAB.getInstance().getFeatureManager().getNameTagFeature().isDisabledWorld(analyzed.getWorldName()) &&
|
||||
analyzed.getTeamNameNote() != null)
|
||||
return "&eTeam name note: &a" + analyzed.getTeamNameNote();
|
||||
return "";
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns list of extra properties if unlimited nametag mode is enabled
|
||||
* @return list of extra properties
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public List<Object> getExtraLines(){
|
||||
if (!TAB.getInstance().getFeatureManager().isFeatureEnabled("nametagx")) return new ArrayList<Object>();
|
||||
if (!TAB.getInstance().getFeatureManager().isFeatureEnabled("nametagx")) return new ArrayList<>();
|
||||
if (TAB.getInstance().isPremium()) {
|
||||
List<Object> lines = Lists.newArrayList((List<Object>) TAB.getInstance().getConfiguration().premiumconfig.getObject("unlimited-nametag-mode-dynamic-lines"));
|
||||
lines.addAll(TAB.getInstance().getConfiguration().premiumconfig.getConfigurationSection("unlimited-nametag-mode-static-lines").keySet());
|
||||
lines.remove("nametag");
|
||||
lines.add("customtagname");
|
||||
List<Object> lines = Lists.newArrayList((List<Object>) TAB.getInstance().getConfiguration().getPremiumConfig().getObject("unlimited-nametag-mode-dynamic-lines"));
|
||||
lines.addAll(TAB.getInstance().getConfiguration().getPremiumConfig().getConfigurationSection("unlimited-nametag-mode-static-lines").keySet());
|
||||
lines.remove(PropertyUtils.NAMETAG);
|
||||
lines.add(PropertyUtils.CUSTOMTAGNAME);
|
||||
return lines;
|
||||
} else {
|
||||
return Arrays.asList("customtagname", "belowname", "abovename");
|
||||
return Arrays.asList(PropertyUtils.CUSTOMTAGNAME, PropertyUtils.BELOWNAME, PropertyUtils.ABOVENAME);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -196,13 +214,14 @@ public class DebugCommand extends SubCommand {
|
||||
} else {
|
||||
Property pr = analyzed.getProperty(property);
|
||||
String rawValue = pr.getCurrentRawValue().replace('\u00a7', '&');
|
||||
String value = String.format("&a%s: &e\"&r%s&r&e\" &7(%s) &9(Source: %s)".replace('&', '\u00a7'), property, rawValue, rawValue.length(), pr.getSource());
|
||||
String c = TAB.getInstance().isPremium() ? "&7" : "&9";
|
||||
String value = String.format(("&a%s: &e\"&r%s&r&e\" &7(%s) " + c + "(Source: %s)").replace('&', '\u00a7'), property, rawValue, rawValue.length(), pr.getSource());
|
||||
sendRawMessage(sender, value);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> complete(TabPlayer sender, String[] arguments) {
|
||||
return arguments.length == 1 ? getPlayers(arguments[0]) : new ArrayList<String>();
|
||||
return arguments.length == 1 ? getPlayers(arguments[0]) : new ArrayList<>();
|
||||
}
|
||||
}
|
||||
+5
-19
@@ -1,17 +1,14 @@
|
||||
package me.neznamy.tab.shared.command.level1;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import me.neznamy.tab.api.TabPlayer;
|
||||
import me.neznamy.tab.shared.TAB;
|
||||
import me.neznamy.tab.shared.command.SubCommand;
|
||||
|
||||
/**
|
||||
* Handler for "/tab group" subcommand
|
||||
*/
|
||||
public class GroupCommand extends SubCommand {
|
||||
public class GroupCommand extends PropertyCommand {
|
||||
|
||||
/**
|
||||
* Constructs new instance
|
||||
@@ -29,7 +26,7 @@ public class GroupCommand extends SubCommand {
|
||||
String value = buildArgument(Arrays.copyOfRange(args, 2, args.length));
|
||||
if (type.equals("remove")) {
|
||||
if (hasPermission(sender, "tab.remove")) {
|
||||
TAB.getInstance().getConfiguration().config.set("Groups." + group, null);
|
||||
TAB.getInstance().getConfiguration().getConfig().set("Groups." + group, null);
|
||||
for (TabPlayer pl : TAB.getInstance().getPlayers()) {
|
||||
if (pl.getGroup().equals(group) || group.equals("_OTHER_")){
|
||||
pl.forceRefresh();
|
||||
@@ -39,7 +36,7 @@ public class GroupCommand extends SubCommand {
|
||||
}
|
||||
return;
|
||||
}
|
||||
for (String property : allProperties) {
|
||||
for (String property : getAllProperties()) {
|
||||
if (type.equals(property)) {
|
||||
if (hasPermission(sender, "tab.change." + property)) {
|
||||
saveGroup(sender, group, type, value);
|
||||
@@ -73,8 +70,8 @@ public class GroupCommand extends SubCommand {
|
||||
} else {
|
||||
sendMessage(sender, getTranslation("value_removed").replace("%type%", type).replace("%unit%", group).replace("%category%", "group"));
|
||||
}
|
||||
if (String.valueOf(value.length() == 0 ? null : value).equals(String.valueOf(TAB.getInstance().getConfiguration().config.getObject("Groups." + group.replace(".", "@#@") + "." + type)))) return;
|
||||
TAB.getInstance().getConfiguration().config.set("Groups." + group.replace(".", "@#@") + "." + type, value.length() == 0 ? null : value);
|
||||
if (String.valueOf(value.length() == 0 ? null : value).equals(String.valueOf(TAB.getInstance().getConfiguration().getConfig().getObject("Groups." + group.replace(".", "@#@") + "." + type)))) return;
|
||||
TAB.getInstance().getConfiguration().getConfig().set("Groups." + group.replace(".", "@#@") + "." + type, value.length() == 0 ? null : value);
|
||||
TAB.getInstance().getPlaceholderManager().checkForRegistration(value);
|
||||
for (TabPlayer pl : TAB.getInstance().getPlayers()) {
|
||||
if (pl.getGroup().equals(group) || group.equals("_OTHER_")){
|
||||
@@ -82,15 +79,4 @@ public class GroupCommand extends SubCommand {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> complete(TabPlayer sender, String[] arguments) {
|
||||
List<String> suggestions = new ArrayList<String>();
|
||||
if (arguments.length == 2) {
|
||||
for (String property : allProperties) {
|
||||
if (property.startsWith(arguments[1].toLowerCase())) suggestions.add(property);
|
||||
}
|
||||
}
|
||||
return suggestions;
|
||||
}
|
||||
}
|
||||
File renamed without changes.
File renamed without changes.
+5
-12
@@ -1,6 +1,5 @@
|
||||
package me.neznamy.tab.shared.command.level1;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
@@ -29,7 +28,7 @@ public class PlayerCommand extends SubCommand {
|
||||
String value = buildArgument(Arrays.copyOfRange(args, 2, args.length));
|
||||
if (type.equals("remove")) {
|
||||
if (hasPermission(sender, "tab.remove")) {
|
||||
TAB.getInstance().getConfiguration().config.set("Users." + player, null);
|
||||
TAB.getInstance().getConfiguration().getConfig().set("Users." + player, null);
|
||||
TabPlayer pl = TAB.getInstance().getPlayer(player);
|
||||
if (pl != null) {
|
||||
pl.forceRefresh();
|
||||
@@ -38,7 +37,7 @@ public class PlayerCommand extends SubCommand {
|
||||
}
|
||||
return;
|
||||
}
|
||||
for (String property : allProperties) {
|
||||
for (String property : getAllProperties()) {
|
||||
if (type.equals(property)) {
|
||||
if (hasPermission(sender, "tab.change." + property)) {
|
||||
savePlayer(sender, player, type, value);
|
||||
@@ -72,8 +71,8 @@ public class PlayerCommand extends SubCommand {
|
||||
} else {
|
||||
sendMessage(sender, getTranslation("value_removed").replace("%type%", type).replace("%unit%", player).replace("%category%", "player"));
|
||||
}
|
||||
if (String.valueOf(value.length() == 0 ? null : value).equals(String.valueOf(TAB.getInstance().getConfiguration().config.getObject("Users." + player + "." + type)))) return;
|
||||
TAB.getInstance().getConfiguration().config.set("Users." + player + "." + type, value.length() == 0 ? null : value);
|
||||
if (String.valueOf(value.length() == 0 ? null : value).equals(String.valueOf(TAB.getInstance().getConfiguration().getConfig().getObject("Users." + player + "." + type)))) return;
|
||||
TAB.getInstance().getConfiguration().getConfig().set("Users." + player + "." + type, value.length() == 0 ? null : value);
|
||||
TAB.getInstance().getPlaceholderManager().checkForRegistration(value);
|
||||
TabPlayer pl = TAB.getInstance().getPlayer(player);
|
||||
if (pl != null) {
|
||||
@@ -84,12 +83,6 @@ public class PlayerCommand extends SubCommand {
|
||||
@Override
|
||||
public List<String> complete(TabPlayer sender, String[] arguments) {
|
||||
if (arguments.length == 1) return getPlayers(arguments[0]);
|
||||
List<String> suggestions = new ArrayList<String>();
|
||||
if (arguments.length == 2) {
|
||||
for (String property : allProperties) {
|
||||
if (property.startsWith(arguments[1].toLowerCase())) suggestions.add(property);
|
||||
}
|
||||
}
|
||||
return suggestions;
|
||||
return super.complete(sender, arguments);
|
||||
}
|
||||
}
|
||||
+5
-12
@@ -1,6 +1,5 @@
|
||||
package me.neznamy.tab.shared.command.level1;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
@@ -34,13 +33,13 @@ public class PlayerUUIDCommand extends SubCommand {
|
||||
String value = buildArgument(Arrays.copyOfRange(args, 2, args.length));
|
||||
if (type.equals("remove")) {
|
||||
if (hasPermission(sender, "tab.remove")) {
|
||||
TAB.getInstance().getConfiguration().config.set("Users." + changed.getUniqueId().toString(), null);
|
||||
TAB.getInstance().getConfiguration().getConfig().set("Users." + changed.getUniqueId().toString(), null);
|
||||
changed.forceRefresh();
|
||||
sendMessage(sender, getTranslation("data_removed").replace("%category%", "player").replace("%value%", changed.getName() + "(" + changed.getUniqueId().toString() + ")"));
|
||||
}
|
||||
return;
|
||||
}
|
||||
for (String property : allProperties) {
|
||||
for (String property : getAllProperties()) {
|
||||
if (type.equals(property)) {
|
||||
if (hasPermission(sender, "tab.change." + property)) {
|
||||
savePlayer(sender, changed, type, value);
|
||||
@@ -74,8 +73,8 @@ public class PlayerUUIDCommand extends SubCommand {
|
||||
} else {
|
||||
sendMessage(sender, getTranslation("value_removed").replace("%type%", type).replace("%unit%", player.getName() + "(" + player.getUniqueId().toString() + ")").replace("%category%", "UUID"));
|
||||
}
|
||||
if (String.valueOf(value.length() == 0 ? null : value).equals(String.valueOf(TAB.getInstance().getConfiguration().config.getObject("Users." + player.getUniqueId() + "." + type)))) return;
|
||||
TAB.getInstance().getConfiguration().config.set("Users." + player.getUniqueId() + "." + type, value.length() == 0 ? null : value);
|
||||
if (String.valueOf(value.length() == 0 ? null : value).equals(String.valueOf(TAB.getInstance().getConfiguration().getConfig().getObject("Users." + player.getUniqueId() + "." + type)))) return;
|
||||
TAB.getInstance().getConfiguration().getConfig().set("Users." + player.getUniqueId() + "." + type, value.length() == 0 ? null : value);
|
||||
TAB.getInstance().getPlaceholderManager().checkForRegistration(value);
|
||||
player.forceRefresh();
|
||||
}
|
||||
@@ -83,12 +82,6 @@ public class PlayerUUIDCommand extends SubCommand {
|
||||
@Override
|
||||
public List<String> complete(TabPlayer sender, String[] arguments) {
|
||||
if (arguments.length == 1) return getPlayers(arguments[0]);
|
||||
List<String> suggestions = new ArrayList<String>();
|
||||
if (arguments.length == 2) {
|
||||
for (String property : allProperties) {
|
||||
if (property.startsWith(arguments[1].toLowerCase())) suggestions.add(property);
|
||||
}
|
||||
}
|
||||
return suggestions;
|
||||
return super.complete(sender, arguments);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
package me.neznamy.tab.shared.command.level1;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import me.neznamy.tab.api.TabPlayer;
|
||||
import me.neznamy.tab.shared.command.SubCommand;
|
||||
|
||||
public abstract class PropertyCommand extends SubCommand {
|
||||
|
||||
protected PropertyCommand(String name, String permission) {
|
||||
super(name, permission);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> complete(TabPlayer sender, String[] arguments) {
|
||||
List<String> suggestions = new ArrayList<>();
|
||||
if (arguments.length == 2) {
|
||||
for (String property : getAllProperties()) {
|
||||
if (property.startsWith(arguments[1].toLowerCase())) suggestions.add(property);
|
||||
}
|
||||
}
|
||||
return suggestions;
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -22,7 +22,7 @@ public class ReloadCommand extends SubCommand {
|
||||
TAB.getInstance().load();
|
||||
if (TAB.getInstance().isDisabled()) {
|
||||
if (sender != null) {
|
||||
sendMessage(sender, TAB.getInstance().getConfiguration().reloadFailed.replace("%file%", TAB.getInstance().brokenFile));
|
||||
sendMessage(sender, TAB.getInstance().getConfiguration().getReloadFailedMessage().replace("%file%", TAB.getInstance().getBrokenFile()));
|
||||
}
|
||||
} else {
|
||||
sendMessage(sender, getTranslation("reloaded"));
|
||||
+13
-7
@@ -1,6 +1,7 @@
|
||||
package me.neznamy.tab.shared.command.level1;
|
||||
|
||||
import me.neznamy.tab.api.TabPlayer;
|
||||
import me.neznamy.tab.shared.ITabPlayer;
|
||||
import me.neznamy.tab.shared.TAB;
|
||||
import me.neznamy.tab.shared.command.SubCommand;
|
||||
import me.neznamy.tab.shared.features.scoreboard.ScoreboardManager;
|
||||
@@ -24,7 +25,7 @@ public class ScoreboardCommand extends SubCommand {
|
||||
sendMessage(sender, "&cScoreboard feature is not enabled, therefore toggle command cannot be used.");
|
||||
return;
|
||||
}
|
||||
if (scoreboard.permToToggle && !hasPermission(sender, "tab.togglescoreboard")) {
|
||||
if (scoreboard.isPermToToggle() && !hasPermission(sender, "tab.togglescoreboard")) {
|
||||
sendMessage(sender, getTranslation("no_permission"));
|
||||
return;
|
||||
}
|
||||
@@ -45,17 +46,22 @@ public class ScoreboardCommand extends SubCommand {
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (p.getOtherPluginScoreboard() != null) return; //not overriding other plugins
|
||||
if (((ITabPlayer)p).getOtherPluginScoreboard() != null) return; //not overriding other plugins
|
||||
boolean silent = args.length >= 3 && args[2].equals("-s");
|
||||
if (args.length >= 1) {
|
||||
if (args[0].equalsIgnoreCase("on"))
|
||||
switch(args[0]) {
|
||||
case "on":
|
||||
p.setScoreboardVisible(true, !silent);
|
||||
|
||||
if (args[0].equalsIgnoreCase("off"))
|
||||
break;
|
||||
case "off":
|
||||
p.setScoreboardVisible(false, !silent);
|
||||
|
||||
if (args[0].equalsIgnoreCase("toggle"))
|
||||
break;
|
||||
case "toggle":
|
||||
p.toggleScoreboard(!silent);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+2
-2
@@ -16,14 +16,14 @@ public class SendCommand extends SubCommand {
|
||||
*/
|
||||
public SendCommand() {
|
||||
super("send", null);
|
||||
subcommands.put("bar", new SendBarCommand());
|
||||
getSubcommands().put("bar", new SendBarCommand());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(TabPlayer sender, String[] args) {
|
||||
if (args.length > 0) {
|
||||
String arg0 = args[0].toLowerCase();
|
||||
SubCommand command = subcommands.get(arg0);
|
||||
SubCommand command = getSubcommands().get(arg0);
|
||||
if (command != null) {
|
||||
if (command.hasPermission(sender)) {
|
||||
command.execute(sender, Arrays.copyOfRange(args, 1, args.length));
|
||||
File renamed without changes.
+13
-13
@@ -38,32 +38,32 @@ public class AnnounceBarCommand extends SubCommand{
|
||||
try {
|
||||
duration = Integer.parseInt(args[1]);
|
||||
} catch (Exception e) {
|
||||
sender.sendMessage(args[1] + " is not a number!", false);
|
||||
sendMessage(sender, args[1] + " is not a number!");
|
||||
return;
|
||||
}
|
||||
BossBarLine bar = feature.lines.get(barname);
|
||||
BossBarLine bar = feature.getLines().get(barname);
|
||||
if (bar == null) {
|
||||
sender.sendMessage("Bar not found", false);
|
||||
sendMessage(sender, "Bar not found");
|
||||
return;
|
||||
}
|
||||
new Thread(() -> {
|
||||
try {
|
||||
feature.announcements.add(barname);
|
||||
feature.announceEndTime = System.currentTimeMillis() + duration*1000;
|
||||
feature.getAnnouncements().add(barname);
|
||||
feature.setAnnounceEndTime(System.currentTimeMillis() + duration*1000);
|
||||
for (TabPlayer all : TAB.getInstance().getPlayers()) {
|
||||
if (!all.hasBossbarVisible()) continue;
|
||||
bar.create(all);
|
||||
all.getActiveBossBars().add(bar);
|
||||
}
|
||||
Thread.sleep(duration*1000);
|
||||
Thread.sleep(duration*1000L);
|
||||
for (TabPlayer all : TAB.getInstance().getPlayers()) {
|
||||
if (!all.hasBossbarVisible()) continue;
|
||||
bar.remove(all);
|
||||
all.getActiveBossBars().remove(bar);
|
||||
}
|
||||
feature.announcements.remove(barname);
|
||||
} catch (Exception e) {
|
||||
|
||||
feature.getAnnouncements().remove(barname);
|
||||
} catch (InterruptedException pluginDisabled) {
|
||||
Thread.currentThread().interrupt();
|
||||
}
|
||||
}).start();
|
||||
}
|
||||
@@ -71,13 +71,13 @@ public class AnnounceBarCommand extends SubCommand{
|
||||
@Override
|
||||
public List<String> complete(TabPlayer sender, String[] arguments) {
|
||||
BossBar b = (BossBar) TAB.getInstance().getFeatureManager().getFeature("bossbar");
|
||||
if (b == null) return new ArrayList<String>();
|
||||
List<String> suggestions = new ArrayList<String>();
|
||||
if (b == null) return new ArrayList<>();
|
||||
List<String> suggestions = new ArrayList<>();
|
||||
if (arguments.length == 1) {
|
||||
for (String bar : b.lines.keySet()) {
|
||||
for (String bar : b.getLines().keySet()) {
|
||||
if (bar.toLowerCase().startsWith(arguments[0].toLowerCase())) suggestions.add(bar);
|
||||
}
|
||||
} else if (arguments.length == 2 && b.lines.get(arguments[0]) != null){
|
||||
} else if (arguments.length == 2 && b.getLines().get(arguments[0]) != null){
|
||||
for (String time : Arrays.asList("5", "10", "30", "60", "120")) {
|
||||
if (time.startsWith(arguments[1])) suggestions.add(time);
|
||||
}
|
||||
+10
-10
@@ -40,12 +40,12 @@ public class AnnounceScoreboardCommand extends SubCommand{
|
||||
try {
|
||||
duration = Integer.parseInt(args[1]);
|
||||
} catch (Exception e) {
|
||||
sender.sendMessage(args[1] + " is not a number!", false);
|
||||
sendMessage(sender, args[1] + " is not a number!");
|
||||
return;
|
||||
}
|
||||
Scoreboard sb = feature.getScoreboards().get(scoreboard);
|
||||
if (sb == null) {
|
||||
sender.sendMessage("Scoreboard not found", false);
|
||||
sendMessage(sender, "Scoreboard not found");
|
||||
return;
|
||||
}
|
||||
announce(feature, sb, duration);
|
||||
@@ -60,23 +60,23 @@ public class AnnounceScoreboardCommand extends SubCommand{
|
||||
private void announce(ScoreboardManager feature, Scoreboard sb, int duration) {
|
||||
new Thread(() -> {
|
||||
try {
|
||||
feature.announcement = sb;
|
||||
Map<TabPlayer, Scoreboard> previous = new HashMap<TabPlayer, Scoreboard>();
|
||||
feature.setAnnouncement(sb);
|
||||
Map<TabPlayer, Scoreboard> previous = new HashMap<>();
|
||||
for (TabPlayer all : TAB.getInstance().getPlayers()) {
|
||||
if (!all.isScoreboardVisible()) continue;
|
||||
previous.put(all, all.getActiveScoreboard());
|
||||
if (all.getActiveScoreboard() != null) all.getActiveScoreboard().unregister(all);
|
||||
sb.register(all);
|
||||
}
|
||||
Thread.sleep(duration*1000);
|
||||
Thread.sleep(duration*1000L);
|
||||
for (TabPlayer all : TAB.getInstance().getPlayers()) {
|
||||
if (!all.hasBossbarVisible()) continue;
|
||||
sb.unregister(all);
|
||||
if (previous.get(all) != null) previous.get(all).register(all);
|
||||
}
|
||||
feature.announcement = null;
|
||||
} catch (Exception e) {
|
||||
|
||||
feature.setAnnouncement(null);
|
||||
} catch (InterruptedException pluginDisabled) {
|
||||
Thread.currentThread().interrupt();
|
||||
}
|
||||
}).start();
|
||||
}
|
||||
@@ -84,8 +84,8 @@ public class AnnounceScoreboardCommand extends SubCommand{
|
||||
@Override
|
||||
public List<String> complete(TabPlayer sender, String[] arguments) {
|
||||
ScoreboardManager s = (ScoreboardManager) TAB.getInstance().getFeatureManager().getFeature("scoreboard");
|
||||
if (s == null) return new ArrayList<String>();
|
||||
List<String> suggestions = new ArrayList<String>();
|
||||
if (s == null) return new ArrayList<>();
|
||||
List<String> suggestions = new ArrayList<>();
|
||||
if (arguments.length == 1) {
|
||||
for (String bar : s.getScoreboards().keySet()) {
|
||||
if (bar.toLowerCase().startsWith(arguments[0].toLowerCase())) suggestions.add(bar);
|
||||
+9
-9
@@ -46,9 +46,9 @@ public class SendBarCommand extends SubCommand{
|
||||
sendMessage(sender, args[1] + " is not a number!");
|
||||
return;
|
||||
}
|
||||
BossBarLine bar = feature.lines.get(barname);
|
||||
BossBarLine bar = feature.getLines().get(barname);
|
||||
if (bar == null) {
|
||||
sender.sendMessage("Bar not found", false);
|
||||
sendMessage(sender, "No bar found with name \"" + bar + "\"");
|
||||
return;
|
||||
}
|
||||
new Thread(() -> {
|
||||
@@ -57,13 +57,13 @@ public class SendBarCommand extends SubCommand{
|
||||
bar.create(target);
|
||||
target.getActiveBossBars().add(bar);
|
||||
}
|
||||
Thread.sleep(duration*1000);
|
||||
Thread.sleep(duration*1000L);
|
||||
if (target.hasBossbarVisible()) {
|
||||
bar.remove(target);
|
||||
target.getActiveBossBars().remove(bar);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
|
||||
} catch (InterruptedException pluginDisabled) {
|
||||
Thread.currentThread().interrupt();
|
||||
}
|
||||
}).start();
|
||||
}
|
||||
@@ -71,15 +71,15 @@ public class SendBarCommand extends SubCommand{
|
||||
@Override
|
||||
public List<String> complete(TabPlayer sender, String[] arguments) {
|
||||
BossBar b = (BossBar) TAB.getInstance().getFeatureManager().getFeature("bossbar");
|
||||
if (b == null) return new ArrayList<String>();
|
||||
List<String> suggestions = new ArrayList<String>();
|
||||
if (b == null) return new ArrayList<>();
|
||||
List<String> suggestions = new ArrayList<>();
|
||||
if (arguments.length == 1) {
|
||||
return getPlayers(arguments[0]);
|
||||
} else if (arguments.length == 2) {
|
||||
for (String bar : b.lines.keySet()) {
|
||||
for (String bar : b.getLines().keySet()) {
|
||||
if (bar.toLowerCase().startsWith(arguments[1].toLowerCase())) suggestions.add(bar);
|
||||
}
|
||||
} else if (arguments.length == 3 && b.lines.get(arguments[1]) != null){
|
||||
} else if (arguments.length == 3 && b.getLines().get(arguments[1]) != null){
|
||||
for (String time : Arrays.asList("5", "10", "30", "60", "120")) {
|
||||
if (time.startsWith(arguments[2])) suggestions.add(time);
|
||||
}
|
||||
@@ -0,0 +1,288 @@
|
||||
package me.neznamy.tab.shared.config;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.OutputStreamWriter;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Set;
|
||||
|
||||
import org.yaml.snakeyaml.error.YAMLException;
|
||||
|
||||
import me.neznamy.tab.shared.TAB;
|
||||
|
||||
/**
|
||||
* Core of loading configuration files
|
||||
*/
|
||||
public class Configs {
|
||||
|
||||
private TAB tab;
|
||||
|
||||
//config.yml file
|
||||
private ConfigurationFile config;
|
||||
|
||||
private List<String> removeStrings;
|
||||
private boolean bukkitPermissions;
|
||||
|
||||
//hidden config options
|
||||
private boolean rgbSupport;
|
||||
private boolean unregisterBeforeRegister;
|
||||
private String multiWorldSeparator;
|
||||
private String essentialsNickPrefix;
|
||||
private boolean armorStandsAlwaysVisible; //paid private addition
|
||||
private boolean removeGhostPlayers;
|
||||
private boolean layout;
|
||||
private boolean pipelineInjection;
|
||||
|
||||
//animations.yml file
|
||||
private ConfigurationFile animation;
|
||||
|
||||
//bossbar.yml file
|
||||
private ConfigurationFile bossbar;
|
||||
|
||||
//translation.yml file
|
||||
private ConfigurationFile translation;
|
||||
|
||||
//default reload message in case plugin did not load translation file due to an error
|
||||
private String reloadFailed = "&4Failed to reload, file %file% has broken syntax. Check console for more info.";
|
||||
|
||||
//premiumconfig.yml
|
||||
private ConfigurationFile premiumconfig;
|
||||
|
||||
//playerdata.yml, used for bossbar & scoreboard toggle saving
|
||||
private ConfigurationFile playerdata;
|
||||
|
||||
/**
|
||||
* Constructs new instance with given parameter
|
||||
* @param tab - tab instance
|
||||
*/
|
||||
public Configs(TAB tab) {
|
||||
this.tab = tab;
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads all configuration files and converts files to latest version
|
||||
* @throws IOException
|
||||
* @throws YAMLException
|
||||
*/
|
||||
public void loadFiles() throws YAMLException, IOException {
|
||||
ClassLoader loader = Configs.class.getClassLoader();
|
||||
loadConfig();
|
||||
animation = new YamlConfigurationFile(loader.getResourceAsStream("animations.yml"), new File(tab.getPlatform().getDataFolder(), "animations.yml"));
|
||||
Map<String, Object> values = getAnimationFile().getValues();
|
||||
if (values.size() == 1 && values.containsKey("animations")) {
|
||||
getAnimationFile().setValues(getAnimationFile().getConfigurationSection("animations"));
|
||||
getAnimationFile().save();
|
||||
TAB.getInstance().print('2', "Converted animations.yml to new format.");
|
||||
}
|
||||
bossbar = new YamlConfigurationFile(loader.getResourceAsStream("bossbar.yml"), new File(tab.getPlatform().getDataFolder(), "bossbar.yml"));
|
||||
translation = new YamlConfigurationFile(loader.getResourceAsStream("translation.yml"), new File(tab.getPlatform().getDataFolder(), "translation.yml"));
|
||||
reloadFailed = getTranslation().getString("reload-failed", "&4Failed to reload, file %file% has broken syntax. Check console for more info.");
|
||||
if (tab.isPremium()) premiumconfig = new YamlConfigurationFile(loader.getResourceAsStream("premiumconfig.yml"), new File(tab.getPlatform().getDataFolder(), "premiumconfig.yml"));
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads config.yml and some of it's values
|
||||
* @throws IOException
|
||||
* @throws YAMLException
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public void loadConfig() throws YAMLException, IOException {
|
||||
config = new YamlConfigurationFile(Configs.class.getClassLoader().getResourceAsStream(tab.getPlatform().getConfigName()), new File(tab.getPlatform().getDataFolder(), "config.yml"), Arrays.asList("# Detailed explanation of all options available at https://github.com/NEZNAMY/TAB/wiki/config.yml", ""));
|
||||
removeStrings = new ArrayList<>();
|
||||
for (String s : getConfig().getStringList("placeholders.remove-strings", Arrays.asList("[] ", "< > "))) {
|
||||
getRemoveStrings().add(s.replace('&', '\u00a7'));
|
||||
}
|
||||
tab.setDebugMode(getConfig().getBoolean("debug", false));
|
||||
rgbSupport = (boolean) getSecretOption("rgb-support", true);
|
||||
unregisterBeforeRegister = (boolean) getSecretOption("unregister-before-register", true);
|
||||
multiWorldSeparator = (String) getSecretOption("multi-world-separator", "-");
|
||||
essentialsNickPrefix = (String) getSecretOption("essentials-nickname-prefix", "");
|
||||
armorStandsAlwaysVisible = (boolean) getSecretOption("unlimited-nametag-prefix-suffix-mode.always-visible", false);
|
||||
removeGhostPlayers = (boolean) getSecretOption("remove-ghost-players", false);
|
||||
layout = (boolean) getSecretOption("layout", false);
|
||||
pipelineInjection = (boolean) getSecretOption("pipeline-injection", true);
|
||||
if (tab.getPlatform().getSeparatorType().equals("server")) {
|
||||
bukkitPermissions = getConfig().getBoolean("use-bukkit-permissions-manager", false);
|
||||
}
|
||||
|
||||
//checking for unnecessary copypaste in config
|
||||
Set<Object> groups = getConfig().getConfigurationSection("Groups").keySet();
|
||||
if (groups.size() < 2) return;
|
||||
Map<Object, Object> sharedProperties = new HashMap<>(getConfig().getConfigurationSection("Groups." + groups.toArray()[0])); //cloning to not delete from original one
|
||||
for (Object groupSettings : getConfig().getConfigurationSection("Groups").values()) {
|
||||
if (!(groupSettings instanceof Map)) continue;
|
||||
Map<String, Object> group = (Map<String, Object>) groupSettings;
|
||||
for (Entry<Object, Object> sharedProperty : new HashSet<>(sharedProperties.entrySet())) {
|
||||
String property = sharedProperty.getKey().toString();
|
||||
if (!group.containsKey(property) || !String.valueOf(group.get(property)).equals(sharedProperty.getValue())) {
|
||||
sharedProperties.remove(property);
|
||||
}
|
||||
}
|
||||
}
|
||||
for (Object property : sharedProperties.keySet()) {
|
||||
tab.print('9', "Hint: All of your groups have the same value of \"&d" + property + "&9\" set. Delete it from all groups and add it only to _OTHER_ for cleaner and smaller config.");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns value of hidden config option with specified path if it exists, defaultValue otherwise
|
||||
* @param path - path to value
|
||||
* @param defaultValue - value to return if option is not present in file
|
||||
* @return value with specified path or default value if not present
|
||||
*/
|
||||
private Object getSecretOption(String path, Object defaultValue) {
|
||||
if (getConfig() == null) return defaultValue;
|
||||
Object value = getConfig().getObject(path);
|
||||
return value == null ? defaultValue : value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns player data with specified key
|
||||
* @param key - data key
|
||||
* @return list of players logged in this data key
|
||||
*/
|
||||
public List<String> getPlayerData(String key) {
|
||||
if (playerdata == null) {
|
||||
File file = new File(tab.getPlatform().getDataFolder(), "playerdata.yml");
|
||||
try {
|
||||
if (file.exists() || file.createNewFile()) {
|
||||
playerdata = new YamlConfigurationFile(null, file);
|
||||
return playerdata.getStringList(key, new ArrayList<>());
|
||||
}
|
||||
} catch (Exception e) {
|
||||
tab.getErrorManager().criticalError("Failed to load playerdata.yml", e);
|
||||
}
|
||||
} else {
|
||||
return playerdata.getStringList(key, new ArrayList<>());
|
||||
}
|
||||
return new ArrayList<>();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns name of world group in specified set that may consist of multiple
|
||||
* worlds separated with "-" or something else defined in config
|
||||
* @param world - name of world to find group of
|
||||
* @return name of world group
|
||||
*/
|
||||
public String getWorldGroupOf(Set<?> groups, String world) {
|
||||
if (groups.isEmpty()) return world;
|
||||
for (Object worldGroup : groups) {
|
||||
for (String definedWorld : worldGroup.toString().split(multiWorldSeparator)) {
|
||||
if (definedWorld.endsWith("*")) {
|
||||
if (world.toLowerCase().startsWith(definedWorld.substring(0, definedWorld.length()-1).toLowerCase())) return worldGroup.toString();
|
||||
} else {
|
||||
if (world.equalsIgnoreCase(definedWorld)) return worldGroup.toString();
|
||||
}
|
||||
}
|
||||
}
|
||||
return world;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads all lines in file and returns them as List
|
||||
* @return list of lines in file
|
||||
*/
|
||||
public static List<String> readAllLines(File file) {
|
||||
List<String> list = new ArrayList<>();
|
||||
try (BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(file), StandardCharsets.UTF_8))){
|
||||
String line;
|
||||
while ((line = br.readLine()) != null) {
|
||||
list.add(line);
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
TAB.getInstance().getErrorManager().criticalError("Failed to read file " + file, ex);
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes defined line of text to file
|
||||
* @param f - file to write to
|
||||
* @param line - line to write
|
||||
*/
|
||||
public static void write(File file, List<String> lines){
|
||||
try (BufferedWriter buf = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file, true), StandardCharsets.UTF_8))){
|
||||
for (String line : lines) {
|
||||
buf.write(line + System.getProperty("line.separator"));
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
TAB.getInstance().getErrorManager().criticalError("Failed to write to file " + file.getName(), ex);
|
||||
}
|
||||
}
|
||||
|
||||
public List<String> getRemoveStrings() {
|
||||
return removeStrings;
|
||||
}
|
||||
|
||||
public boolean isUnregisterBeforeRegister() {
|
||||
return unregisterBeforeRegister;
|
||||
}
|
||||
|
||||
public ConfigurationFile getTranslation() {
|
||||
return translation;
|
||||
}
|
||||
|
||||
public ConfigurationFile getConfig() {
|
||||
return config;
|
||||
}
|
||||
|
||||
public boolean isRemoveGhostPlayers() {
|
||||
return removeGhostPlayers;
|
||||
}
|
||||
|
||||
public ConfigurationFile getPremiumConfig() {
|
||||
return premiumconfig;
|
||||
}
|
||||
|
||||
public ConfigurationFile getBossbarConfig() {
|
||||
return bossbar;
|
||||
}
|
||||
|
||||
public boolean isLayout() {
|
||||
return layout;
|
||||
}
|
||||
|
||||
public ConfigurationFile getAnimationFile() {
|
||||
return animation;
|
||||
}
|
||||
|
||||
public boolean isRgbSupport() {
|
||||
return rgbSupport;
|
||||
}
|
||||
|
||||
public boolean isBukkitPermissions() {
|
||||
return bukkitPermissions;
|
||||
}
|
||||
|
||||
public boolean isPipelineInjection() {
|
||||
return pipelineInjection;
|
||||
}
|
||||
|
||||
public boolean isArmorStandsAlwaysVisible() {
|
||||
return armorStandsAlwaysVisible;
|
||||
}
|
||||
|
||||
public String getEssentialsNickPrefix() {
|
||||
return essentialsNickPrefix;
|
||||
}
|
||||
|
||||
public String getReloadFailedMessage() {
|
||||
return reloadFailed;
|
||||
}
|
||||
|
||||
public ConfigurationFile getPlayerDataFile() {
|
||||
return playerdata;
|
||||
}
|
||||
}
|
||||
+28
-50
@@ -1,15 +1,8 @@
|
||||
package me.neznamy.tab.shared.config;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.OutputStreamWriter;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
@@ -44,7 +37,7 @@ public abstract class ConfigurationFile {
|
||||
* @throws IllegalStateException - if file does not exist and source is null
|
||||
* @throws IOException - if I/O file operation fails
|
||||
*/
|
||||
public ConfigurationFile(InputStream source, File destination, List<String> header) throws IllegalStateException, IOException {
|
||||
protected ConfigurationFile(InputStream source, File destination, List<String> header) throws IOException {
|
||||
this.header = header;
|
||||
this.file = destination;
|
||||
if (file.getParentFile() != null) file.getParentFile().mkdirs();
|
||||
@@ -103,7 +96,7 @@ public abstract class ConfigurationFile {
|
||||
return defaultValue;
|
||||
}
|
||||
return value;
|
||||
} catch (Throwable e) {
|
||||
} catch (Exception e) {
|
||||
if (defaultValue != null) set(path, defaultValue);
|
||||
return defaultValue;
|
||||
}
|
||||
@@ -125,8 +118,8 @@ public abstract class ConfigurationFile {
|
||||
* @return value from map
|
||||
*/
|
||||
private Object getIgnoreCase(Map<Object, Object> map, String key) {
|
||||
for (Object mapkey : map.keySet()) {
|
||||
if (mapkey.toString().equalsIgnoreCase(key)) return map.get(mapkey);
|
||||
for (Entry<Object, Object> entry : map.entrySet()) {
|
||||
if (entry.getKey().toString().equalsIgnoreCase(key)) return entry.getValue();
|
||||
}
|
||||
return map.get(key);
|
||||
}
|
||||
@@ -174,9 +167,9 @@ public abstract class ConfigurationFile {
|
||||
if (value == null) return defaultValue;
|
||||
if (!(value instanceof List)) {
|
||||
dataMismatch(path, ArrayList.class, value.getClass());
|
||||
return new ArrayList<String>();
|
||||
return new ArrayList<>();
|
||||
}
|
||||
List<String> fixedList = new ArrayList<String>();
|
||||
List<String> fixedList = new ArrayList<>();
|
||||
for (Object key : (List<Object>)value) {
|
||||
fixedList.add(key.toString());
|
||||
}
|
||||
@@ -225,7 +218,14 @@ public abstract class ConfigurationFile {
|
||||
* @return value from file or null if not present
|
||||
*/
|
||||
public Boolean getBoolean(String path) {
|
||||
return getBoolean(path, null);
|
||||
Object value = getObject(path, null);
|
||||
if (value == null) return null;
|
||||
try {
|
||||
return Boolean.parseBoolean(value.toString());
|
||||
} catch (Exception e) {
|
||||
dataMismatch(path, Boolean.class, value.getClass());
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -235,10 +235,10 @@ public abstract class ConfigurationFile {
|
||||
* @param defaultValue - value to be inserted and returned if option is not present
|
||||
* @return value from config
|
||||
*/
|
||||
public Boolean getBoolean(String path, Boolean defaultValue) {
|
||||
public boolean getBoolean(String path, boolean defaultValue) {
|
||||
Object value = getObject(path, defaultValue);
|
||||
if (value == null) return defaultValue;
|
||||
try{
|
||||
try {
|
||||
return Boolean.parseBoolean(value.toString());
|
||||
} catch (Exception e) {
|
||||
dataMismatch(path, Boolean.class, value.getClass());
|
||||
@@ -312,7 +312,7 @@ public abstract class ConfigurationFile {
|
||||
if (path.contains(".")) {
|
||||
String keyWord = getRealKey(map, path.split("\\.")[0]);
|
||||
Object submap = map.get(keyWord);
|
||||
if (submap == null || !(submap instanceof Map)) {
|
||||
if (!(submap instanceof Map)) {
|
||||
submap = new HashMap<String, Object>();
|
||||
}
|
||||
map.put(keyWord.replace("@#@", "."), set((Map<String, Object>) submap, path.substring(keyWord.length()+1, path.length()), value));
|
||||
@@ -345,7 +345,7 @@ public abstract class ConfigurationFile {
|
||||
*/
|
||||
public boolean hasHeader() {
|
||||
if (header == null) return true;
|
||||
for (String line : readAllLines(file)) {
|
||||
for (String line : Configs.readAllLines(file)) {
|
||||
if (line.contains("#")) return true;
|
||||
}
|
||||
return false;
|
||||
@@ -357,39 +357,17 @@ public abstract class ConfigurationFile {
|
||||
public void fixHeader() {
|
||||
if (header == null) return;
|
||||
try {
|
||||
List<String> content = new ArrayList<String>(header);
|
||||
content.addAll(readAllLines(file));
|
||||
file.delete();
|
||||
file.createNewFile();
|
||||
BufferedWriter buf = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file, true), StandardCharsets.UTF_8));
|
||||
for (String line : content) {
|
||||
buf.write(line + System.getProperty("line.separator"));
|
||||
List<String> content = new ArrayList<>(header);
|
||||
content.addAll(Configs.readAllLines(file));
|
||||
Files.delete(file.toPath());
|
||||
if (file.createNewFile()) {
|
||||
Configs.write(file, content);
|
||||
}
|
||||
buf.close();
|
||||
} catch (Exception ex) {
|
||||
TAB.getInstance().getErrorManager().criticalError("Failed to modify file " + file, ex);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads all lines in file and returns them as List
|
||||
* @return list of lines in file
|
||||
*/
|
||||
private List<String> readAllLines(File file) {
|
||||
List<String> list = new ArrayList<String>();
|
||||
try {
|
||||
BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(file), StandardCharsets.UTF_8));
|
||||
String line;
|
||||
while ((line = br.readLine()) != null) {
|
||||
list.add(line);
|
||||
}
|
||||
br.close();
|
||||
} catch (Exception ex) {
|
||||
TAB.getInstance().getErrorManager().criticalError("Failed to read file " + file, ex);
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
/**
|
||||
* Finds all used placeholder identifiers in the file including nested placeholders in given keys
|
||||
* @param simpleKeys - keys to check
|
||||
@@ -406,22 +384,22 @@ public abstract class ConfigurationFile {
|
||||
* @return Set of used identifiers
|
||||
*/
|
||||
private Set<String> getUsedPlaceholders(Map<String, Object> map, String... simpleKeys){
|
||||
Set<String> values = new HashSet<String>();
|
||||
Set<String> placeholders = new HashSet<>();
|
||||
for (Entry<String, Object> entry : map.entrySet()) {
|
||||
for (String simpleKey : simpleKeys) {
|
||||
if (String.valueOf(entry.getKey()).equals(simpleKey)) values.addAll(TAB.getInstance().getPlaceholderManager().detectAll(String.valueOf(entry.getValue())));
|
||||
if (String.valueOf(entry.getKey()).equals(simpleKey)) placeholders.addAll(TAB.getInstance().getPlaceholderManager().detectAll(String.valueOf(entry.getValue())));
|
||||
}
|
||||
if (entry.getValue() instanceof Map) {
|
||||
values.addAll(getUsedPlaceholders((Map<String, Object>)entry.getValue(), simpleKeys));
|
||||
placeholders.addAll(getUsedPlaceholders((Map<String, Object>)entry.getValue(), simpleKeys));
|
||||
}
|
||||
if (entry.getValue() instanceof List) {
|
||||
for (Object obj : (List<Object>)entry.getValue()) {
|
||||
for (String simpleKey : simpleKeys) {
|
||||
if (String.valueOf(obj).equals(simpleKey)) values.addAll(TAB.getInstance().getPlaceholderManager().detectAll(String.valueOf(entry.getValue())));
|
||||
if (String.valueOf(obj).equals(simpleKey)) placeholders.addAll(TAB.getInstance().getPlaceholderManager().detectAll(String.valueOf(entry.getValue())));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return values;
|
||||
return placeholders;
|
||||
}
|
||||
}
|
||||
+3
-3
@@ -63,10 +63,10 @@ public class YamlConfigurationFile extends ConfigurationFile {
|
||||
input.close();
|
||||
if (!hasHeader()) fixHeader();
|
||||
} catch (YAMLException e) {
|
||||
input.close();
|
||||
if (input != null) input.close();
|
||||
TAB tab = TAB.getInstance();
|
||||
tab.getErrorManager().startupWarn("File " + destination + " has broken syntax.");
|
||||
tab.brokenFile = file.getPath();
|
||||
tab.setBrokenFile(file.getPath());
|
||||
tab.getPlatform().sendConsoleMessage("&6[TAB] Error message from yaml parser: " + e.getMessage(), true);
|
||||
List<String> suggestions = YamlAssist.getSuggestions(file);
|
||||
if (!suggestions.isEmpty()) {
|
||||
@@ -86,7 +86,7 @@ public class YamlConfigurationFile extends ConfigurationFile {
|
||||
yaml.dump(values, writer);
|
||||
writer.close();
|
||||
if (!hasHeader()) fixHeader();
|
||||
} catch (Throwable e) {
|
||||
} catch (IOException e) {
|
||||
TAB.getInstance().getErrorManager().criticalError("Failed to save yaml file " + file.getPath() + " with content " + values.toString(), e);
|
||||
}
|
||||
}
|
||||
+90
-140
@@ -2,6 +2,7 @@ package me.neznamy.tab.shared.cpu;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Comparator;
|
||||
import java.util.EnumMap;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
@@ -23,25 +24,25 @@ import me.neznamy.tab.shared.ErrorManager;
|
||||
public class CPUManager {
|
||||
|
||||
//data reset interval in milliseconds
|
||||
private final int bufferSizeMillis = 10000;
|
||||
private static final int BUFFER_SIZE_MILLIS = 10000;
|
||||
|
||||
//nanoseconds worked in the current 10 seconds
|
||||
private Map<Object, Map<UsageType, AtomicLong>> featureUsageCurrent = new ConcurrentHashMap<Object, Map<UsageType, AtomicLong>>();
|
||||
private Map<String, AtomicLong> placeholderUsageCurrent = new ConcurrentHashMap<String, AtomicLong>();
|
||||
private Map<String, AtomicLong> bridgePlaceholderUsageCurrent = new ConcurrentHashMap<String, AtomicLong>();
|
||||
private Map<String, AtomicLong> methodUsageCurrent = new ConcurrentHashMap<String, AtomicLong>();
|
||||
private Map<Object, Map<UsageType, AtomicLong>> featureUsageCurrent = new ConcurrentHashMap<>();
|
||||
private Map<String, AtomicLong> placeholderUsageCurrent = new ConcurrentHashMap<>();
|
||||
private Map<String, AtomicLong> bridgePlaceholderUsageCurrent = new ConcurrentHashMap<>();
|
||||
private Map<String, AtomicLong> methodUsageCurrent = new ConcurrentHashMap<>();
|
||||
|
||||
//packets sent in the current 10 seconds
|
||||
private Map<Object, AtomicInteger> packetsCurrent = new ConcurrentHashMap<Object, AtomicInteger>();
|
||||
private Map<Object, AtomicInteger> packetsCurrent = new ConcurrentHashMap<>();
|
||||
|
||||
//nanoseconds worked in the previous 10 seconds
|
||||
private Map<Object, Map<UsageType, AtomicLong>> featureUsagePrevious = new HashMap<Object, Map<UsageType, AtomicLong>>();
|
||||
private Map<String, AtomicLong> placeholderUsagePrevious = new HashMap<String, AtomicLong>();
|
||||
private Map<String, AtomicLong> bridgePlaceholderUsagePrevious = new HashMap<String, AtomicLong>();
|
||||
private Map<String, AtomicLong> methodUsagePrevious = new HashMap<String, AtomicLong>();
|
||||
private Map<Object, Map<UsageType, AtomicLong>> featureUsagePrevious = new HashMap<>();
|
||||
private Map<String, AtomicLong> placeholderUsagePrevious = new HashMap<>();
|
||||
private Map<String, AtomicLong> bridgePlaceholderUsagePrevious = new HashMap<>();
|
||||
private Map<String, AtomicLong> methodUsagePrevious = new HashMap<>();
|
||||
|
||||
//packets sent in the previous 10 seconds
|
||||
private Map<Object, AtomicInteger> packetsPrevious = new ConcurrentHashMap<Object, AtomicInteger>();
|
||||
private Map<Object, AtomicInteger> packetsPrevious = new ConcurrentHashMap<>();
|
||||
|
||||
//thread pool
|
||||
private ThreadPoolExecutor exe = (ThreadPoolExecutor) Executors.newCachedThreadPool();
|
||||
@@ -55,29 +56,26 @@ public class CPUManager {
|
||||
*/
|
||||
public CPUManager(ErrorManager errorManager) {
|
||||
this.errorManager = errorManager;
|
||||
exe.submit(new Runnable() {
|
||||
exe.submit(() -> {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
while (true) {
|
||||
Thread.sleep(bufferSizeMillis);
|
||||
try {
|
||||
while (true) {
|
||||
Thread.sleep(BUFFER_SIZE_MILLIS);
|
||||
|
||||
featureUsagePrevious = featureUsageCurrent;
|
||||
placeholderUsagePrevious = placeholderUsageCurrent;
|
||||
bridgePlaceholderUsagePrevious = bridgePlaceholderUsageCurrent;
|
||||
methodUsagePrevious = methodUsageCurrent;
|
||||
packetsPrevious = packetsCurrent;
|
||||
|
||||
featureUsageCurrent = new ConcurrentHashMap<Object, Map<UsageType, AtomicLong>>();
|
||||
placeholderUsageCurrent = new ConcurrentHashMap<String, AtomicLong>();
|
||||
bridgePlaceholderUsageCurrent = new ConcurrentHashMap<String, AtomicLong>();
|
||||
methodUsageCurrent = new ConcurrentHashMap<String, AtomicLong>();
|
||||
packetsCurrent = new ConcurrentHashMap<Object, AtomicInteger>();
|
||||
}
|
||||
} catch (InterruptedException pluginDisabled) {
|
||||
featureUsagePrevious = featureUsageCurrent;
|
||||
placeholderUsagePrevious = placeholderUsageCurrent;
|
||||
bridgePlaceholderUsagePrevious = bridgePlaceholderUsageCurrent;
|
||||
methodUsagePrevious = methodUsageCurrent;
|
||||
packetsPrevious = packetsCurrent;
|
||||
|
||||
featureUsageCurrent = new ConcurrentHashMap<>();
|
||||
placeholderUsageCurrent = new ConcurrentHashMap<>();
|
||||
bridgePlaceholderUsageCurrent = new ConcurrentHashMap<>();
|
||||
methodUsageCurrent = new ConcurrentHashMap<>();
|
||||
packetsCurrent = new ConcurrentHashMap<>();
|
||||
}
|
||||
} catch (InterruptedException pluginDisabled) {
|
||||
Thread.currentThread().interrupt();
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -108,17 +106,10 @@ public class CPUManager {
|
||||
* @param task - the task
|
||||
*/
|
||||
public void runMeasuredTask(String errorDescription, Object feature, UsageType type, Runnable task) {
|
||||
exe.submit(new Runnable() {
|
||||
|
||||
public void run() {
|
||||
try {
|
||||
long time = System.nanoTime();
|
||||
task.run();
|
||||
addTime(feature, type, System.nanoTime()-time);
|
||||
} catch (Throwable t) {
|
||||
errorManager.printError("An error occurred when " + errorDescription, t);
|
||||
}
|
||||
}
|
||||
submit(errorDescription, () -> {
|
||||
long time = System.nanoTime();
|
||||
task.run();
|
||||
addTime(feature, type, System.nanoTime()-time);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -128,16 +119,7 @@ public class CPUManager {
|
||||
* @param task - the task
|
||||
*/
|
||||
public void runTask(String errorDescription, Runnable task) {
|
||||
exe.submit(new Runnable() {
|
||||
|
||||
public void run() {
|
||||
try {
|
||||
task.run();
|
||||
} catch (Throwable t) {
|
||||
errorManager.printError("An error occurred when " + errorDescription, t);
|
||||
}
|
||||
}
|
||||
});
|
||||
submit(errorDescription, task);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -150,26 +132,22 @@ public class CPUManager {
|
||||
*/
|
||||
public void startRepeatingMeasuredTask(int intervalMilliseconds, String errorDescription, Object feature, UsageType type, Runnable task) {
|
||||
if (intervalMilliseconds <= 0) return;
|
||||
exe.submit(new Runnable() {
|
||||
|
||||
public void run() {
|
||||
long lastLoop = System.currentTimeMillis()-intervalMilliseconds;
|
||||
while (true) {
|
||||
try {
|
||||
long sleep = intervalMilliseconds - (System.currentTimeMillis()-lastLoop);
|
||||
if (sleep < 0) {
|
||||
sleep = 0;
|
||||
}
|
||||
Thread.sleep(sleep);
|
||||
lastLoop = System.currentTimeMillis();
|
||||
long time = System.nanoTime();
|
||||
task.run();
|
||||
addTime(feature, type, System.nanoTime()-time);
|
||||
} catch (InterruptedException pluginDisabled) {
|
||||
break;
|
||||
} catch (Throwable t) {
|
||||
errorManager.printError("An error occurred when " + errorDescription, t);
|
||||
submit(errorDescription, () -> {
|
||||
long lastLoop = System.currentTimeMillis()-intervalMilliseconds;
|
||||
while (true) {
|
||||
try {
|
||||
long sleep = intervalMilliseconds - (System.currentTimeMillis()-lastLoop);
|
||||
if (sleep < 0) {
|
||||
sleep = 0;
|
||||
}
|
||||
Thread.sleep(sleep);
|
||||
lastLoop = System.currentTimeMillis();
|
||||
long time = System.nanoTime();
|
||||
task.run();
|
||||
addTime(feature, type, System.nanoTime()-time);
|
||||
} catch (InterruptedException pluginDisabled) {
|
||||
Thread.currentThread().interrupt();
|
||||
break;
|
||||
}
|
||||
}
|
||||
});
|
||||
@@ -184,18 +162,24 @@ public class CPUManager {
|
||||
* @param task - the task
|
||||
*/
|
||||
public void runTaskLater(int delayMilliseconds, String errorDescription, Object feature, UsageType type, Runnable task) {
|
||||
exe.submit(new Runnable() {
|
||||
|
||||
public void run() {
|
||||
try {
|
||||
Thread.sleep(delayMilliseconds);
|
||||
long time = System.nanoTime();
|
||||
task.run();
|
||||
addTime(feature, type, System.nanoTime()-time);
|
||||
} catch (InterruptedException pluginDisabled) {
|
||||
} catch (Throwable t) {
|
||||
errorManager.printError("An error occurred when " + errorDescription, t);
|
||||
}
|
||||
submit(errorDescription, () -> {
|
||||
try {
|
||||
Thread.sleep(delayMilliseconds);
|
||||
long time = System.nanoTime();
|
||||
task.run();
|
||||
addTime(feature, type, System.nanoTime()-time);
|
||||
} catch (InterruptedException pluginDisabled) {
|
||||
Thread.currentThread().interrupt();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void submit(String errorDescription, Runnable task) {
|
||||
exe.submit(() -> {
|
||||
try {
|
||||
task.run();
|
||||
} catch (Exception | Error e) {
|
||||
errorManager.printError("An error occurred when " + errorDescription, e);
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -239,14 +223,14 @@ public class CPUManager {
|
||||
* @return converted and sorted map
|
||||
*/
|
||||
private Map<String, Float> getUsage(Map<String, AtomicLong> map){
|
||||
Map<String, Long> nanoMap = new HashMap<String, Long>();
|
||||
Map<String, Long> nanoMap = new HashMap<>();
|
||||
String key;
|
||||
for (Entry<String, AtomicLong> nanos : map.entrySet()) {
|
||||
key = nanos.getKey();
|
||||
if (!nanoMap.containsKey(key)) nanoMap.put(key, 0L);
|
||||
nanoMap.put(key, nanoMap.get(key)+nanos.getValue().get());
|
||||
}
|
||||
Map<String, Float> percentMap = new HashMap<String, Float>();
|
||||
Map<String, Float> percentMap = new HashMap<>();
|
||||
for (Entry<String, Long> entry : nanoMap.entrySet()) {
|
||||
percentMap.put(entry.getKey(), nanosToPercent(entry.getValue()));
|
||||
}
|
||||
@@ -258,11 +242,11 @@ public class CPUManager {
|
||||
* @return map of CPU usage per feature per type
|
||||
*/
|
||||
public Map<Object, Map<UsageType, Float>> getFeatureUsage(){
|
||||
Map<Object, Map<UsageType, Long>> total = new HashMap<Object, Map<UsageType, Long>>();
|
||||
Map<Object, EnumMap<UsageType, Long>> total = new HashMap<>();
|
||||
for (Entry<Object, Map<UsageType, AtomicLong>> nanos : featureUsagePrevious.entrySet()) {
|
||||
Object key = nanos.getKey();
|
||||
if (!total.containsKey(key)) {
|
||||
total.put(key, new HashMap<UsageType, Long>());
|
||||
total.put(key, new EnumMap<>(UsageType.class));
|
||||
}
|
||||
Map<UsageType, Long> usage = total.get(key);
|
||||
for (Entry<UsageType, AtomicLong> entry : nanos.getValue().entrySet()) {
|
||||
@@ -272,10 +256,10 @@ public class CPUManager {
|
||||
usage.put(entry.getKey(), usage.get(entry.getKey()) + entry.getValue().get());
|
||||
}
|
||||
}
|
||||
Map<Object, Map<UsageType, Float>> sorted = new LinkedHashMap<Object, Map<UsageType, Float>>();
|
||||
Map<Object, Map<UsageType, Float>> sorted = new LinkedHashMap<>();
|
||||
for (Object key : sortKeys(total)) {
|
||||
Map<UsageType, Long> local = sortByValue(total.get(key));
|
||||
Map<UsageType, Float> percent = new LinkedHashMap<UsageType, Float>();
|
||||
Map<UsageType, Float> percent = new LinkedHashMap<>();
|
||||
for (Entry<UsageType, Long> entry : local.entrySet()) {
|
||||
percent.put(entry.getKey(), nanosToPercent(entry.getValue()));
|
||||
}
|
||||
@@ -290,7 +274,7 @@ public class CPUManager {
|
||||
* @return usage in % (0-100)
|
||||
*/
|
||||
private float nanosToPercent(long nanos) {
|
||||
float percent = (float) nanos / bufferSizeMillis / 1000000; //relative usage (0-1)
|
||||
float percent = (float) nanos / BUFFER_SIZE_MILLIS / 1000000; //relative usage (0-1)
|
||||
percent *= 100; //relative into %
|
||||
return percent;
|
||||
}
|
||||
@@ -303,14 +287,12 @@ public class CPUManager {
|
||||
* @return sorted map
|
||||
*/
|
||||
private <K, V extends Comparable<V>> Map<K, V> sortByValue(Map<K, V> map) {
|
||||
Comparator<K> valueComparator = new Comparator<K>() {
|
||||
public int compare(K k1, K k2) {
|
||||
int compare = map.get(k2).compareTo(map.get(k1));
|
||||
if (compare == 0) return 1;
|
||||
else return compare;
|
||||
}
|
||||
Comparator<K> valueComparator = (k1, k2) -> {
|
||||
int compare = map.get(k2).compareTo(map.get(k1));
|
||||
if (compare == 0) return 1;
|
||||
else return compare;
|
||||
};
|
||||
Map<K, V> sortedByValues = new TreeMap<K, V>(valueComparator);
|
||||
Map<K, V> sortedByValues = new TreeMap<>(valueComparator);
|
||||
sortedByValues.putAll(map);
|
||||
return sortedByValues;
|
||||
}
|
||||
@@ -323,14 +305,12 @@ public class CPUManager {
|
||||
* @return sorted map
|
||||
*/
|
||||
private <K> Map<K, AtomicInteger> sortByValue1(Map<K, AtomicInteger> map) {
|
||||
Comparator<K> valueComparator = new Comparator<K>() {
|
||||
public int compare(K k1, K k2) {
|
||||
int compare = ((Comparable<Integer>)map.get(k2).get()).compareTo(map.get(k1).get());
|
||||
if (compare == 0) return 1;
|
||||
else return compare;
|
||||
}
|
||||
Comparator<K> valueComparator = (k1, k2) -> {
|
||||
int compare = ((Comparable<Integer>)map.get(k2).get()).compareTo(map.get(k1).get());
|
||||
if (compare == 0) return 1;
|
||||
else return compare;
|
||||
};
|
||||
Map<K, AtomicInteger> sortedByValues = new TreeMap<K, AtomicInteger>(valueComparator);
|
||||
Map<K, AtomicInteger> sortedByValues = new TreeMap<>(valueComparator);
|
||||
sortedByValues.putAll(map);
|
||||
return sortedByValues;
|
||||
}
|
||||
@@ -342,13 +322,13 @@ public class CPUManager {
|
||||
* @param map - map to sort
|
||||
* @return list of keys sorted from highest usage to lowest
|
||||
*/
|
||||
private <K, L> List<K> sortKeys(Map<K, Map<L, Long>> map){
|
||||
Map<K, Long> simplified = new LinkedHashMap<K, Long>();
|
||||
for (Entry<K, Map<L, Long>> entry : map.entrySet()) {
|
||||
private <K> List<K> sortKeys(Map<K, EnumMap<UsageType, Long>> map){
|
||||
Map<K, Long> simplified = new LinkedHashMap<>();
|
||||
for (Entry<K, EnumMap<UsageType, Long>> entry : map.entrySet()) {
|
||||
simplified.put(entry.getKey(), sumValues(entry.getValue()));
|
||||
}
|
||||
simplified = sortByValue(simplified);
|
||||
List<K> sortedKeys = new ArrayList<K>();
|
||||
List<K> sortedKeys = new ArrayList<>();
|
||||
for (K key : simplified.keySet()) {
|
||||
sortedKeys.add(key);
|
||||
}
|
||||
@@ -375,27 +355,7 @@ public class CPUManager {
|
||||
* @param nanoseconds - time to add
|
||||
*/
|
||||
public void addTime(Object feature, UsageType type, long nanoseconds) {
|
||||
Map<UsageType, AtomicLong> usage = featureUsageCurrent.get(feature);
|
||||
if (usage == null) {
|
||||
usage = new ConcurrentHashMap<UsageType, AtomicLong>();
|
||||
featureUsageCurrent.put(feature, usage);
|
||||
}
|
||||
try {
|
||||
if (!usage.containsKey(type)) {
|
||||
usage.put(type, new AtomicLong());
|
||||
}
|
||||
} catch (NullPointerException e) {
|
||||
//java.lang.NullPointerException: null
|
||||
//at java.base/java.util.concurrent.ConcurrentHashMap.get(ConcurrentHashMap.java:936)
|
||||
//at java.base/java.util.concurrent.ConcurrentHashMap.containsKey(ConcurrentHashMap.java:964)
|
||||
return;
|
||||
}
|
||||
AtomicLong current = usage.get(type);
|
||||
if (current == null) {
|
||||
usage.put(type, new AtomicLong(nanoseconds));
|
||||
} else {
|
||||
current.addAndGet(nanoseconds);
|
||||
}
|
||||
featureUsageCurrent.computeIfAbsent(feature, f -> new ConcurrentHashMap<>()).computeIfAbsent(type, t -> new AtomicLong()).addAndGet(nanoseconds);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -432,12 +392,7 @@ public class CPUManager {
|
||||
* @param time - nanoseconds the task took
|
||||
*/
|
||||
private void addTime(Map<String, AtomicLong> map, String key, long time) {
|
||||
AtomicLong current = map.get(key);
|
||||
if (current == null) {
|
||||
map.put(key, new AtomicLong(time));
|
||||
} else {
|
||||
current.addAndGet(time);
|
||||
}
|
||||
map.computeIfAbsent(key, k -> new AtomicLong()).addAndGet(time);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -445,11 +400,6 @@ public class CPUManager {
|
||||
* @param feature - feature to increment packet counter of
|
||||
*/
|
||||
public void packetSent(Object feature) {
|
||||
AtomicInteger current = packetsCurrent.get(feature);
|
||||
if (current == null) {
|
||||
packetsCurrent.put(feature, new AtomicInteger(1));
|
||||
} else {
|
||||
current.addAndGet(1);
|
||||
}
|
||||
packetsCurrent.computeIfAbsent(feature, f -> new AtomicInteger()).incrementAndGet();
|
||||
}
|
||||
}
|
||||
+1
@@ -28,6 +28,7 @@ public enum TabFeature {
|
||||
PACKET_SERIALIZING("Packet serializing"),
|
||||
TABLIST_LAYOUT("Tablist layout"),
|
||||
PLUGIN_MESSAGE_HANDLING("Plugin message handling"),
|
||||
PING_SPOOF("Ping spoof"),
|
||||
OTHER("Other");
|
||||
|
||||
//user-friendly name to be used in /tab cpu
|
||||
+4
-3
@@ -12,7 +12,6 @@ public enum UsageType {
|
||||
WORLD_SWITCH_EVENT("PlayerChangedWorldEvent"),
|
||||
PLAYER_TOGGLE_SNEAK_EVENT("PlayerToggleSneakEvent"),
|
||||
PLAYER_MOVE_EVENT("PlayerMoveEvent"),
|
||||
PLAYER_TELEPORT_EVENT("PlayerTeleportEvent"),
|
||||
PLAYER_RESPAWN_EVENT("PlayerRespawnEvent"),
|
||||
COMMAND_PREPROCESS("PlayerCommandPreprocessEvent"),
|
||||
PLUGIN_MESSAGE_EVENT("PluginMessageEvent"),
|
||||
@@ -28,6 +27,8 @@ public enum UsageType {
|
||||
PACKET_LOGIN("PacketLogin"),
|
||||
PACKET_DISPLAY_OBJECTIVE("PacketPlayOutScoreboardDisplayObjective"),
|
||||
PACKET_OBJECTIVE("PacketPlayOutScoreboardObjective"),
|
||||
PACKET_NAMED_ENTITY_SPAWN("PacketPlayOutNamedEntitySpawn"),
|
||||
PACKET_ENTITY_DESTROY("PacketPlayOutEntityDestroy"),
|
||||
|
||||
//nametags
|
||||
REFRESHING_COLLISION("Refreshing collision rule"),
|
||||
@@ -40,8 +41,8 @@ public enum UsageType {
|
||||
//other
|
||||
REFRESHING("Refreshing"),
|
||||
REPEATING_TASK("Repeating task"),
|
||||
TICKING_UNLIMITED_NAMETAGS("Ticking unlimited nametag mode"),
|
||||
v1_8_0_BUG_COMPENSATION("Compensating for 1.8.0 bugs");
|
||||
TICKING_VEHICLES("Ticking vehicles"),
|
||||
V1_8_0_BUG_COMPENSATION("Compensating for 1.8.0 bugs");
|
||||
|
||||
//user-friendly name to be used in /tab cpu
|
||||
private String friendlyName;
|
||||
+22
-78
@@ -4,14 +4,13 @@ import java.io.BufferedReader;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import me.neznamy.tab.api.TabPlayer;
|
||||
import me.neznamy.tab.shared.PropertyUtils;
|
||||
import me.neznamy.tab.shared.TAB;
|
||||
import me.neznamy.tab.shared.cpu.TabFeature;
|
||||
import me.neznamy.tab.shared.features.types.Loadable;
|
||||
import me.neznamy.tab.shared.features.types.event.JoinEventListener;
|
||||
import me.neznamy.tab.shared.features.types.event.QuitEventListener;
|
||||
import me.neznamy.tab.shared.features.types.event.WorldChangeListener;
|
||||
import me.neznamy.tab.shared.packets.IChatBaseComponent;
|
||||
@@ -19,21 +18,23 @@ import me.neznamy.tab.shared.packets.IChatBaseComponent;
|
||||
/**
|
||||
* Additional code for Playerlist class to secure alignment
|
||||
*/
|
||||
public class AlignedSuffix implements Loadable, JoinEventListener, QuitEventListener, WorldChangeListener {
|
||||
public class AlignedSuffix implements QuitEventListener, WorldChangeListener {
|
||||
|
||||
private TAB tab;
|
||||
private int maxWidth;
|
||||
private TabPlayer maxPlayer;
|
||||
private Map<Character, Byte> widths = new HashMap<Character, Byte>();
|
||||
private Map<Character, Byte> widths = new HashMap<>();
|
||||
private Playerlist playerlist;
|
||||
|
||||
public AlignedSuffix(Playerlist playerlist, TAB tab) {
|
||||
this.tab = tab;
|
||||
this.playerlist = playerlist;
|
||||
tab.debug("Loading widths from file");
|
||||
loadWidthsFromFile();
|
||||
loadExtraWidths();
|
||||
tab.debug("Loaded " + widths.size() + " character widths.");
|
||||
Map<Integer, Integer> widthOverrides = tab.getConfiguration().getPremiumConfig().getConfigurationSection("character-width-overrides");
|
||||
for (Entry<Integer, Integer> entry : widthOverrides.entrySet()) {
|
||||
widths.put((char)(int)entry.getKey(), (byte)(int)entry.getValue());
|
||||
}
|
||||
tab.debug(String.format("Loaded AlignedSuffix feature with parameters widthOverrides=%s", widthOverrides));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -44,44 +45,18 @@ public class AlignedSuffix implements Loadable, JoinEventListener, QuitEventList
|
||||
InputStream input = getClass().getClassLoader().getResourceAsStream("widths.txt");
|
||||
BufferedReader br = new BufferedReader(new InputStreamReader(input));
|
||||
String line;
|
||||
//int i=0;
|
||||
int characterId = 1;
|
||||
while ((line = br.readLine()) != null) {
|
||||
//i++;
|
||||
if (line.isEmpty()) {
|
||||
//tab.debug("Skipping missing character " + i);
|
||||
continue;
|
||||
}
|
||||
String[] arr = line.split(":");
|
||||
widths.put((char)Integer.parseInt(arr[0]), (byte)Float.parseFloat(arr[1]));
|
||||
widths.put((char)characterId++, (byte)Float.parseFloat(line));
|
||||
}
|
||||
br.close();
|
||||
} catch (Exception ex) {
|
||||
tab.getErrorManager().criticalError("Failed to read character widths from file", ex);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads extra widths defined in premiumconfig and deletes redundant ones already listed in widths.txt
|
||||
*/
|
||||
private void loadExtraWidths() {
|
||||
boolean save = false;
|
||||
Map<Integer, Number> extraWidths = tab.getConfiguration().premiumconfig.getConfigurationSection("extra-character-widths");
|
||||
for (Integer entry : new HashSet<>(extraWidths.keySet())) {
|
||||
char c = (char)(int)entry;
|
||||
int width = (int)extraWidths.get(entry);
|
||||
if (widths.containsKey(c)) {
|
||||
extraWidths.remove((int)c);
|
||||
tab.print('2', "Deleting character width of " + (int)c + " from extra-character-widths because it already exists inside the plugin.");
|
||||
save = true;
|
||||
} else {
|
||||
widths.put(c, (byte)width);
|
||||
}
|
||||
}
|
||||
if (save) tab.getConfiguration().premiumconfig.save();
|
||||
}
|
||||
|
||||
public String formatNameAndUpdateLeader(TabPlayer player, String prefixAndName, String suffix) {
|
||||
int playerNameWidth = getTextWidth(IChatBaseComponent.fromColoredText(prefixAndName + suffix));
|
||||
|
||||
public String formatNameAndUpdateLeader(TabPlayer player, TabPlayer viewer) {
|
||||
int playerNameWidth = getTextWidth(IChatBaseComponent.fromColoredText(player.getProperty(PropertyUtils.TABPREFIX).getFormat(null) + player.getProperty(PropertyUtils.CUSTOMTABNAME).getFormat(null) + player.getProperty(PropertyUtils.TABSUFFIX).getFormat(null)));
|
||||
if (player == maxPlayer && playerNameWidth < maxWidth) {
|
||||
maxWidth = playerNameWidth;
|
||||
for (TabPlayer all : tab.getPlayers()) {
|
||||
@@ -97,7 +72,7 @@ public class AlignedSuffix implements Loadable, JoinEventListener, QuitEventList
|
||||
maxPlayer = player;
|
||||
updateAllNames(player);
|
||||
}
|
||||
return formatName(prefixAndName, suffix);
|
||||
return formatName(player.getProperty(PropertyUtils.TABPREFIX).getFormat(viewer) + player.getProperty(PropertyUtils.CUSTOMTABNAME).getFormat(viewer), player.getProperty(PropertyUtils.TABSUFFIX).getFormat(viewer));
|
||||
}
|
||||
|
||||
public String formatName(String prefixAndName, String suffix) {
|
||||
@@ -122,26 +97,15 @@ public class AlignedSuffix implements Loadable, JoinEventListener, QuitEventList
|
||||
int width = 0;
|
||||
if (component.getText() != null) {
|
||||
for (Character c : component.getText().toCharArray()) {
|
||||
if (widths.containsKey(c)) {
|
||||
int localWidth = widths.get(c);
|
||||
if (component.isBold()) {
|
||||
width += localWidth+1;
|
||||
} else {
|
||||
width += localWidth;
|
||||
}
|
||||
if (component.isBold()) {
|
||||
width += widths.get(c)+2;
|
||||
} else {
|
||||
tab.getErrorManager().oneTimeConsoleError("Unknown character " + c + " (" + ((int)c) + ") found when aligning tabsuffix. Configure it using /tab width <character|ID>.");
|
||||
width += widths.get(c)+1;
|
||||
}
|
||||
}
|
||||
//there is 1 pixel space between characters, but not after last one
|
||||
width += component.getText().length()-1;
|
||||
}
|
||||
for (IChatBaseComponent extra : component.getExtra()) {
|
||||
int extraWidth = getTextWidth(extra);
|
||||
//ignoring empty components
|
||||
if (extraWidth > 0) {
|
||||
width += extraWidth + 1; //1 pixel space between characters
|
||||
}
|
||||
width += getTextWidth(extra);
|
||||
}
|
||||
return width;
|
||||
}
|
||||
@@ -152,7 +116,7 @@ public class AlignedSuffix implements Loadable, JoinEventListener, QuitEventList
|
||||
* @return width of player's tablist name format
|
||||
*/
|
||||
private int getPlayerNameWidth(TabPlayer p) {
|
||||
String format = p.getProperty("tabprefix").get() + p.getProperty("customtabname").get() + p.getProperty("tabsuffix").get();
|
||||
String format = p.getProperty(PropertyUtils.TABPREFIX).getFormat(null) + p.getProperty(PropertyUtils.CUSTOMTABNAME).getFormat(null) + p.getProperty(PropertyUtils.TABSUFFIX).getFormat(null);
|
||||
return getTextWidth(IChatBaseComponent.fromColoredText(format));
|
||||
}
|
||||
|
||||
@@ -180,37 +144,17 @@ public class AlignedSuffix implements Loadable, JoinEventListener, QuitEventList
|
||||
output.append("\u00a7r");
|
||||
return output.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void load() {
|
||||
recalculateMaxWidth(null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unload() {
|
||||
//nothing to do here, Playerlist feature handles unloading
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onJoin(TabPlayer p) {
|
||||
int width = getPlayerNameWidth(p);
|
||||
if (width > maxWidth) {
|
||||
maxWidth = width;
|
||||
maxPlayer = p;
|
||||
updateAllNames(null);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onQuit(TabPlayer p) {
|
||||
if (maxPlayer == p && recalculateMaxWidth(p)) {
|
||||
if (recalculateMaxWidth(p)) {
|
||||
updateAllNames(p);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onWorldChange(TabPlayer p, String from, String to) {
|
||||
if (maxPlayer == p && recalculateMaxWidth(null)) {
|
||||
if (recalculateMaxWidth(null)) {
|
||||
updateAllNames(null);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,193 @@
|
||||
package me.neznamy.tab.shared.features;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import me.neznamy.tab.api.TabPlayer;
|
||||
import me.neznamy.tab.shared.PacketAPI;
|
||||
import me.neznamy.tab.shared.TAB;
|
||||
import me.neznamy.tab.shared.cpu.TabFeature;
|
||||
import me.neznamy.tab.shared.features.types.Loadable;
|
||||
import me.neznamy.tab.shared.features.types.Refreshable;
|
||||
import me.neznamy.tab.shared.features.types.event.JoinEventListener;
|
||||
import me.neznamy.tab.shared.features.types.event.QuitEventListener;
|
||||
import me.neznamy.tab.shared.features.types.event.WorldChangeListener;
|
||||
import me.neznamy.tab.shared.features.types.packet.DisplayObjectivePacketListener;
|
||||
import me.neznamy.tab.shared.features.types.packet.LoginPacketListener;
|
||||
import me.neznamy.tab.shared.packets.PacketPlayOutScoreboardDisplayObjective;
|
||||
import me.neznamy.tab.shared.packets.PacketPlayOutScoreboardObjective;
|
||||
import me.neznamy.tab.shared.packets.PacketPlayOutScoreboardObjective.EnumScoreboardHealthDisplay;
|
||||
import me.neznamy.tab.shared.packets.PacketPlayOutScoreboardScore;
|
||||
import me.neznamy.tab.shared.packets.PacketPlayOutScoreboardScore.Action;
|
||||
|
||||
/**
|
||||
* Feature handler for BelowName feature
|
||||
*/
|
||||
public class BelowName implements Loadable, JoinEventListener, QuitEventListener, WorldChangeListener, Refreshable, LoginPacketListener, DisplayObjectivePacketListener {
|
||||
|
||||
public static final String OBJECTIVE_NAME = "TAB-BelowName";
|
||||
public static final int DISPLAY_SLOT = 2;
|
||||
private static final String NUMBER_PROPERTY = "belowname-number";
|
||||
private static final String TEXT_PROPERTY = "belowname-text";
|
||||
|
||||
private TAB tab;
|
||||
private String rawNumber;
|
||||
private String rawText;
|
||||
private List<String> usedPlaceholders;
|
||||
private List<String> disabledWorlds;
|
||||
private Set<TabPlayer> playersInDisabledWorlds = new HashSet<>();
|
||||
|
||||
public BelowName(TAB tab) {
|
||||
this.tab = tab;
|
||||
rawNumber = tab.getConfiguration().getConfig().getString("classic-vanilla-belowname.number", "%health%");
|
||||
rawText = tab.getConfiguration().getConfig().getString("classic-vanilla-belowname.text", "Health");
|
||||
disabledWorlds = tab.getConfiguration().getConfig().getStringList("disable-features-in-"+tab.getPlatform().getSeparatorType()+"s.belowname", Arrays.asList("disabled" + tab.getPlatform().getSeparatorType()));
|
||||
refreshUsedPlaceholders();
|
||||
tab.debug(String.format("Loaded BelowName feature with parameters number=%s, text=%s, disabledWorlds=%s", rawNumber, rawText, disabledWorlds));
|
||||
tab.getFeatureManager().registerFeature("belowname-text-refresher", new TextRefresher());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void load() {
|
||||
for (TabPlayer loaded : tab.getPlayers()){
|
||||
loaded.setProperty(NUMBER_PROPERTY, rawNumber);
|
||||
loaded.setProperty(TEXT_PROPERTY, rawText);
|
||||
if (isDisabledWorld(disabledWorlds, loaded.getWorldName())) {
|
||||
playersInDisabledWorlds.add(loaded);
|
||||
continue;
|
||||
}
|
||||
PacketAPI.registerScoreboardObjective(loaded, OBJECTIVE_NAME, loaded.getProperty(TEXT_PROPERTY).updateAndGet(), DISPLAY_SLOT, EnumScoreboardHealthDisplay.INTEGER, TabFeature.BELOWNAME_TEXT);
|
||||
}
|
||||
for (TabPlayer viewer : tab.getPlayers()){
|
||||
for (TabPlayer target : tab.getPlayers()){
|
||||
viewer.sendCustomPacket(new PacketPlayOutScoreboardScore(Action.CHANGE, OBJECTIVE_NAME, target.getName(), getValue(target)), TabFeature.BELOWNAME_NUMBER);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unload() {
|
||||
for (TabPlayer p : tab.getPlayers()){
|
||||
if (playersInDisabledWorlds.contains(p)) continue;
|
||||
p.sendCustomPacket(new PacketPlayOutScoreboardObjective(OBJECTIVE_NAME), TabFeature.BELOWNAME_TEXT);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onJoin(TabPlayer connectedPlayer) {
|
||||
connectedPlayer.setProperty(NUMBER_PROPERTY, rawNumber);
|
||||
connectedPlayer.setProperty(TEXT_PROPERTY, rawText);
|
||||
if (isDisabledWorld(disabledWorlds, connectedPlayer.getWorldName())) {
|
||||
playersInDisabledWorlds.add(connectedPlayer);
|
||||
return;
|
||||
}
|
||||
PacketAPI.registerScoreboardObjective(connectedPlayer, OBJECTIVE_NAME, connectedPlayer.getProperty(TEXT_PROPERTY).get(), DISPLAY_SLOT, EnumScoreboardHealthDisplay.INTEGER, TabFeature.BELOWNAME_TEXT);
|
||||
int number = getValue(connectedPlayer);
|
||||
for (TabPlayer all : tab.getPlayers()){
|
||||
all.sendCustomPacket(new PacketPlayOutScoreboardScore(Action.CHANGE, OBJECTIVE_NAME, connectedPlayer.getName(), number), TabFeature.BELOWNAME_NUMBER);
|
||||
if (all.isLoaded()) connectedPlayer.sendCustomPacket(new PacketPlayOutScoreboardScore(Action.CHANGE, OBJECTIVE_NAME, all.getName(), getValue(all)), TabFeature.BELOWNAME_NUMBER);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onWorldChange(TabPlayer p, String from, String to) {
|
||||
boolean disabledBefore = playersInDisabledWorlds.contains(p);
|
||||
boolean disabledNow = false;
|
||||
if (isDisabledWorld(disabledWorlds, p.getWorldName())) {
|
||||
disabledNow = true;
|
||||
playersInDisabledWorlds.add(p);
|
||||
} else {
|
||||
playersInDisabledWorlds.remove(p);
|
||||
}
|
||||
if (disabledNow && !disabledBefore) {
|
||||
p.sendCustomPacket(new PacketPlayOutScoreboardObjective(OBJECTIVE_NAME), TabFeature.BELOWNAME_TEXT);
|
||||
}
|
||||
if (!disabledNow && disabledBefore) {
|
||||
onJoin(p);
|
||||
}
|
||||
}
|
||||
|
||||
private int getValue(TabPlayer p) {
|
||||
return tab.getErrorManager().parseInteger(p.getProperty(NUMBER_PROPERTY).updateAndGet(), 0, "belowname number");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void refresh(TabPlayer refreshed, boolean force) {
|
||||
if (playersInDisabledWorlds.contains(refreshed)) return;
|
||||
int number = getValue(refreshed);
|
||||
for (TabPlayer all : tab.getPlayers()) {
|
||||
all.sendCustomPacket(new PacketPlayOutScoreboardScore(Action.CHANGE, OBJECTIVE_NAME, refreshed.getName(), number), TabFeature.BELOWNAME_NUMBER);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getUsedPlaceholders() {
|
||||
return usedPlaceholders;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void refreshUsedPlaceholders() {
|
||||
usedPlaceholders = tab.getPlaceholderManager().getUsedPlaceholderIdentifiersRecursive(rawNumber);
|
||||
}
|
||||
|
||||
@Override
|
||||
public TabFeature getFeatureType() {
|
||||
return TabFeature.BELOWNAME_NUMBER;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLoginPacket(TabPlayer packetReceiver) {
|
||||
if (playersInDisabledWorlds.contains(packetReceiver)) return;
|
||||
PacketAPI.registerScoreboardObjective(packetReceiver, OBJECTIVE_NAME, packetReceiver.getProperty(TEXT_PROPERTY).get(), DISPLAY_SLOT, EnumScoreboardHealthDisplay.INTEGER, TabFeature.BELOWNAME_TEXT);
|
||||
for (TabPlayer all : tab.getPlayers()){
|
||||
if (all.isLoaded()) packetReceiver.sendCustomPacket(new PacketPlayOutScoreboardScore(Action.CHANGE, OBJECTIVE_NAME, all.getName(), getValue(all)), TabFeature.BELOWNAME_NUMBER);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onPacketSend(TabPlayer receiver, PacketPlayOutScoreboardDisplayObjective packet) {
|
||||
if (playersInDisabledWorlds.contains(receiver)) return false;
|
||||
if (packet.getSlot() == DISPLAY_SLOT && !packet.getObjectiveName().equals(OBJECTIVE_NAME)) {
|
||||
tab.getErrorManager().printError("Something just tried to register objective \"" + packet.getObjectiveName() + "\" in position " + packet.getSlot() + " (belowname)", null, false, tab.getErrorManager().getAntiOverrideLog());
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public class TextRefresher implements Refreshable {
|
||||
|
||||
private List<String> usedPlaceholders;
|
||||
|
||||
public TextRefresher(){
|
||||
refreshUsedPlaceholders();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void refresh(TabPlayer refreshed, boolean force) {
|
||||
if (playersInDisabledWorlds.contains(refreshed)) return;
|
||||
refreshed.sendCustomPacket(new PacketPlayOutScoreboardObjective(2, OBJECTIVE_NAME, refreshed.getProperty(TEXT_PROPERTY).updateAndGet(), EnumScoreboardHealthDisplay.INTEGER), TabFeature.BELOWNAME_TEXT);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getUsedPlaceholders() {
|
||||
return usedPlaceholders;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void refreshUsedPlaceholders() {
|
||||
usedPlaceholders = tab.getPlaceholderManager().getUsedPlaceholderIdentifiersRecursive(rawText);
|
||||
}
|
||||
|
||||
@Override
|
||||
public TabFeature getFeatureType() {
|
||||
return TabFeature.BELOWNAME_TEXT;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onQuit(TabPlayer disconnectedPlayer) {
|
||||
playersInDisabledWorlds.remove(disconnectedPlayer);
|
||||
}
|
||||
}
|
||||
+9
-7
@@ -14,16 +14,18 @@ import me.neznamy.tab.shared.packets.PacketPlayOutPlayerInfo.PlayerInfoData;
|
||||
*/
|
||||
public class GhostPlayerFix implements QuitEventListener {
|
||||
|
||||
public GhostPlayerFix() {
|
||||
TAB.getInstance().debug("Loaded GhostPlayerFix feature");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onQuit(TabPlayer disconnectedPlayer) {
|
||||
TAB.getInstance().getCPUManager().runTaskLater(500, "removing players", getFeatureType(), UsageType.PLAYER_QUIT_EVENT, new Runnable() {
|
||||
TAB.getInstance().getCPUManager().runTaskLater(500, "removing players", getFeatureType(), UsageType.PLAYER_QUIT_EVENT, () -> {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
for (TabPlayer all : TAB.getInstance().getPlayers()) {
|
||||
if (all == disconnectedPlayer) continue;
|
||||
all.sendCustomPacket(new PacketPlayOutPlayerInfo(EnumPlayerInfoAction.REMOVE_PLAYER, new PlayerInfoData(disconnectedPlayer.getUniqueId())), getFeatureType());
|
||||
}
|
||||
if (TAB.getInstance().getPlayer(disconnectedPlayer.getName()) != null) return; //player reconnected meanwhile, not removing then
|
||||
for (TabPlayer all : TAB.getInstance().getPlayers()) {
|
||||
if (all == disconnectedPlayer) continue;
|
||||
all.sendCustomPacket(new PacketPlayOutPlayerInfo(EnumPlayerInfoAction.REMOVE_PLAYER, new PlayerInfoData(disconnectedPlayer.getUniqueId())), getFeatureType());
|
||||
}
|
||||
});
|
||||
}
|
||||
+61
-20
@@ -1,8 +1,10 @@
|
||||
package me.neznamy.tab.shared.features;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.UUID;
|
||||
|
||||
import me.neznamy.tab.api.TabPlayer;
|
||||
@@ -26,12 +28,14 @@ import me.neznamy.tab.shared.packets.PacketPlayOutPlayerInfo.PlayerInfoData;
|
||||
public class GlobalPlayerlist implements Loadable, JoinEventListener, QuitEventListener, WorldChangeListener, PlayerInfoPacketListener{
|
||||
|
||||
private TAB tab;
|
||||
public final String PREMIUMVANISH_SEE_VANISHED_PERMISSION = "pv.see";
|
||||
|
||||
private List<String> spyServers;
|
||||
private Map<String, List<String>> sharedServers;
|
||||
private boolean displayAsSpectators;
|
||||
public boolean vanishedAsSpectators;
|
||||
private boolean vanishedAsSpectators;
|
||||
private boolean isolateUnlistedServers;
|
||||
|
||||
private List<TabPlayer> vanishedPlayers = new ArrayList<>();
|
||||
|
||||
public GlobalPlayerlist(TAB tab) {
|
||||
this.tab = tab;
|
||||
@@ -39,29 +43,58 @@ public class GlobalPlayerlist implements Loadable, JoinEventListener, QuitEventL
|
||||
|
||||
@Override
|
||||
public void load() {
|
||||
spyServers = tab.getConfiguration().config.getStringList("global-playerlist.spy-servers", Arrays.asList("spaserver1"));
|
||||
sharedServers = tab.getConfiguration().config.getConfigurationSection("global-playerlist.server-groups");
|
||||
displayAsSpectators = tab.getConfiguration().config.getBoolean("global-playerlist.display-others-as-spectators", false);
|
||||
vanishedAsSpectators = tab.getConfiguration().config.getBoolean("global-playerlist.display-vanished-players-as-spectators", true);
|
||||
isolateUnlistedServers = tab.getConfiguration().config.getBoolean("global-playerlist.isolate-unlisted-servers", false);
|
||||
spyServers = tab.getConfiguration().getConfig().getStringList("global-playerlist.spy-servers", Arrays.asList("spaserver1"));
|
||||
sharedServers = tab.getConfiguration().getConfig().getConfigurationSection("global-playerlist.server-groups");
|
||||
displayAsSpectators = tab.getConfiguration().getConfig().getBoolean("global-playerlist.display-others-as-spectators", false);
|
||||
setVanishedAsSpectators(tab.getConfiguration().getConfig().getBoolean("global-playerlist.display-vanished-players-as-spectators", true));
|
||||
isolateUnlistedServers = tab.getConfiguration().getConfig().getBoolean("global-playerlist.isolate-unlisted-servers", false);
|
||||
for (TabPlayer displayed : tab.getPlayers()) {
|
||||
for (TabPlayer viewer : tab.getPlayers()) {
|
||||
if (viewer.getWorldName().equals(displayed.getWorldName())) continue;
|
||||
if (shouldSee(viewer, displayed)) viewer.sendCustomPacket(getAddPacket(displayed, viewer), getFeatureType());
|
||||
}
|
||||
}
|
||||
tab.debug(String.format("Loaded GlobalPlayerlist feature with parameters spyServers=%s, sharedServers=%s, displayAsSpectators=%s, vanishedAsSpectators=%s, isolateUnlistedServers=%s",
|
||||
spyServers, sharedServers, displayAsSpectators, isVanishedAsSpectators(), isolateUnlistedServers));
|
||||
startTask();
|
||||
}
|
||||
|
||||
private void startTask() {
|
||||
tab.getCPUManager().startRepeatingMeasuredTask(500, "refreshing vanished players", getFeatureType(), UsageType.REPEATING_TASK, () -> {
|
||||
|
||||
for (TabPlayer p : tab.getPlayers()) {
|
||||
if (vanishedPlayers.contains(p) && !p.isVanished()) {
|
||||
vanishedPlayers.remove(p);
|
||||
for (TabPlayer viewer : tab.getPlayers()) {
|
||||
if (viewer == p) continue;
|
||||
if (shouldSee(viewer, p)) {
|
||||
viewer.sendCustomPacket(getAddPacket(p, viewer), getFeatureType());
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!vanishedPlayers.contains(p) && p.isVanished()) {
|
||||
vanishedPlayers.add(p);
|
||||
for (TabPlayer all : tab.getPlayers()) {
|
||||
if (all == p) continue;
|
||||
if (!shouldSee(all, p)) {
|
||||
all.sendCustomPacket(getRemovePacket(p), getFeatureType());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public boolean shouldSee(TabPlayer viewer, TabPlayer displayed) {
|
||||
if (displayed == viewer) return true;
|
||||
if (displayed.isVanished() && !viewer.hasPermission(PREMIUMVANISH_SEE_VANISHED_PERMISSION)) return false;
|
||||
if (displayed.isVanished() && !viewer.hasPermission("tab.seevanished")) return false;
|
||||
if (spyServers.contains(viewer.getWorldName())) return true;
|
||||
return getServerGroup(viewer.getWorldName()).equals(getServerGroup(displayed.getWorldName()));
|
||||
}
|
||||
|
||||
private String getServerGroup(String serverName) {
|
||||
for (String group : sharedServers.keySet()) {
|
||||
if (sharedServers.get(group).contains(serverName)) return group;
|
||||
for (Entry<String, List<String>> group : sharedServers.entrySet()) {
|
||||
if (group.getValue().contains(serverName)) return group.getKey();
|
||||
}
|
||||
return isolateUnlistedServers ? "isolated:" + serverName : "DEFAULT";
|
||||
}
|
||||
@@ -122,7 +155,7 @@ public class GlobalPlayerlist implements Loadable, JoinEventListener, QuitEventL
|
||||
|
||||
public PacketPlayOutPlayerInfo getRemovePacket(TabPlayer p) {
|
||||
PlayerInfoData data = new PlayerInfoData(p.getTablistUUID());
|
||||
data.name = p.getName();
|
||||
data.setName(p.getName());
|
||||
return new PacketPlayOutPlayerInfo(EnumPlayerInfoAction.REMOVE_PLAYER, data);
|
||||
}
|
||||
|
||||
@@ -133,27 +166,27 @@ public class GlobalPlayerlist implements Loadable, JoinEventListener, QuitEventL
|
||||
format = playerlist.getTabFormat(p, viewer);
|
||||
}
|
||||
return new PacketPlayOutPlayerInfo(EnumPlayerInfoAction.ADD_PLAYER, new PlayerInfoData(p.getName(), p.getTablistUUID(), p.getSkin(),
|
||||
(int)p.getPing(), vanishedAsSpectators && p.isVanished() ? EnumGamemode.SPECTATOR : EnumGamemode.CREATIVE, format));
|
||||
(int)p.getPing(), isVanishedAsSpectators() && p.isVanished() ? EnumGamemode.SPECTATOR : EnumGamemode.CREATIVE, format));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPacketSend(TabPlayer receiver, PacketPlayOutPlayerInfo info) {
|
||||
if (info.action == EnumPlayerInfoAction.REMOVE_PLAYER) {
|
||||
for (PlayerInfoData playerInfoData : info.entries) {
|
||||
if (info.getAction() == EnumPlayerInfoAction.REMOVE_PLAYER) {
|
||||
for (PlayerInfoData playerInfoData : info.getEntries()) {
|
||||
//not preventing NPC removals
|
||||
if (tab.getPlayerByTablistUUID(playerInfoData.uniqueId) != null && (playerInfoData.name == null || playerInfoData.name.length() == 0)) {
|
||||
if (tab.getPlayerByTablistUUID(playerInfoData.getUniqueId()) != null && (playerInfoData.getName() == null || playerInfoData.getName().length() == 0)) {
|
||||
//remove packet not coming from tab
|
||||
//changing to random non-existing player, the easiest way to cancel the removal
|
||||
playerInfoData.uniqueId = UUID.randomUUID();
|
||||
playerInfoData.setUniqueId(UUID.randomUUID());
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!displayAsSpectators) return;
|
||||
if (info.action == EnumPlayerInfoAction.ADD_PLAYER || info.action == EnumPlayerInfoAction.UPDATE_GAME_MODE) {
|
||||
for (PlayerInfoData playerInfoData : info.entries) {
|
||||
TabPlayer packetPlayer = tab.getPlayerByTablistUUID(playerInfoData.uniqueId);
|
||||
if (info.getAction() == EnumPlayerInfoAction.ADD_PLAYER || info.getAction() == EnumPlayerInfoAction.UPDATE_GAME_MODE) {
|
||||
for (PlayerInfoData playerInfoData : info.getEntries()) {
|
||||
TabPlayer packetPlayer = tab.getPlayerByTablistUUID(playerInfoData.getUniqueId());
|
||||
if (packetPlayer != null && !receiver.getWorldName().equals(packetPlayer.getWorldName())) {
|
||||
playerInfoData.gameMode = EnumGamemode.SPECTATOR;
|
||||
playerInfoData.setGameMode(EnumGamemode.SPECTATOR);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -163,4 +196,12 @@ public class GlobalPlayerlist implements Loadable, JoinEventListener, QuitEventL
|
||||
public TabFeature getFeatureType() {
|
||||
return TabFeature.GLOBAL_PLAYERLIST;
|
||||
}
|
||||
|
||||
public boolean isVanishedAsSpectators() {
|
||||
return vanishedAsSpectators;
|
||||
}
|
||||
|
||||
public void setVanishedAsSpectators(boolean vanishedAsSpectators) {
|
||||
this.vanishedAsSpectators = vanishedAsSpectators;
|
||||
}
|
||||
}
|
||||
+33
-21
@@ -1,9 +1,11 @@
|
||||
package me.neznamy.tab.shared.features;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import me.neznamy.tab.api.TabPlayer;
|
||||
import me.neznamy.tab.shared.ITabPlayer;
|
||||
import me.neznamy.tab.shared.TAB;
|
||||
import me.neznamy.tab.shared.cpu.TabFeature;
|
||||
import me.neznamy.tab.shared.cpu.UsageType;
|
||||
@@ -14,32 +16,34 @@ import me.neznamy.tab.shared.features.types.Feature;
|
||||
*/
|
||||
public class GroupRefresher implements Feature {
|
||||
|
||||
public static final String DEFAULT_GROUP = "NONE";
|
||||
|
||||
private TAB tab;
|
||||
public boolean groupsByPermissions;
|
||||
public boolean usePrimaryGroup;
|
||||
private boolean groupsByPermissions;
|
||||
private boolean usePrimaryGroup;
|
||||
private List<String> primaryGroupFindingList;
|
||||
|
||||
public GroupRefresher(TAB tab) {
|
||||
this.tab = tab;
|
||||
usePrimaryGroup = tab.getConfiguration().config.getBoolean("use-primary-group", true);
|
||||
groupsByPermissions = tab.getConfiguration().config.getBoolean("assign-groups-by-permissions", false);
|
||||
primaryGroupFindingList = tab.getConfiguration().config.getStringList("primary-group-finding-list", Arrays.asList("Owner", "Admin", "Helper", "default"));
|
||||
tab.getCPUManager().startRepeatingMeasuredTask(1000, "refreshing permission groups", getFeatureType(), UsageType.REPEATING_TASK, new Runnable() {
|
||||
usePrimaryGroup = tab.getConfiguration().getConfig().getBoolean("use-primary-group", true);
|
||||
groupsByPermissions = tab.getConfiguration().getConfig().getBoolean("assign-groups-by-permissions", false);
|
||||
primaryGroupFindingList = new ArrayList<>();
|
||||
for (Object group : tab.getConfiguration().getConfig().getStringList("primary-group-finding-list", Arrays.asList("Owner", "Admin", "Helper", "default"))){
|
||||
primaryGroupFindingList.add(group.toString());
|
||||
}
|
||||
tab.getCPUManager().startRepeatingMeasuredTask(1000, "refreshing permission groups", getFeatureType(), UsageType.REPEATING_TASK, () -> {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
for (TabPlayer p : tab.getPlayers()) {
|
||||
p.setGroup(detectPermissionGroup(p), true);
|
||||
}
|
||||
for (TabPlayer p : tab.getPlayers()) {
|
||||
((ITabPlayer) p).setGroup(detectPermissionGroup(p), true);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public String detectPermissionGroup(TabPlayer p) {
|
||||
if (groupsByPermissions) {
|
||||
if (isGroupsByPermissions()) {
|
||||
return getByPermission(p);
|
||||
}
|
||||
if (usePrimaryGroup) {
|
||||
if (isUsePrimaryGroup()) {
|
||||
return getByPrimary(p);
|
||||
}
|
||||
return getFromList(p);
|
||||
@@ -48,8 +52,8 @@ public class GroupRefresher implements Feature {
|
||||
public String getByPrimary(TabPlayer p) {
|
||||
try {
|
||||
return tab.getPermissionPlugin().getPrimaryGroup(p);
|
||||
} catch (Throwable e) {
|
||||
return tab.getErrorManager().printError("<null>", "Failed to get permission group of " + p.getName() + " using " + tab.getPermissionPlugin().getName() + " v" + tab.getPermissionPlugin().getVersion(), e);
|
||||
} catch (Exception e) {
|
||||
return tab.getErrorManager().printError(DEFAULT_GROUP, "Failed to get permission group of " + p.getName() + " using " + tab.getPermissionPlugin().getName() + " v" + tab.getPermissionPlugin().getVersion(), e);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -57,19 +61,19 @@ public class GroupRefresher implements Feature {
|
||||
try {
|
||||
String[] playerGroups = tab.getPermissionPlugin().getAllGroups(p);
|
||||
if (playerGroups != null && playerGroups.length > 0) {
|
||||
for (Object groupFromList : primaryGroupFindingList) {
|
||||
for (String groupFromList : primaryGroupFindingList) {
|
||||
for (String playerGroup : playerGroups) {
|
||||
if (playerGroup.equalsIgnoreCase(groupFromList.toString())) {
|
||||
if (playerGroup.equalsIgnoreCase(groupFromList)) {
|
||||
return playerGroup;
|
||||
}
|
||||
}
|
||||
}
|
||||
return playerGroups[0];
|
||||
} else {
|
||||
return "<null>";
|
||||
return DEFAULT_GROUP;
|
||||
}
|
||||
} catch (Throwable e) {
|
||||
return tab.getErrorManager().printError("<null>", "Failed to get permission groups of " + p.getName() + " using " + tab.getPermissionPlugin().getName() + " v" + tab.getPermissionPlugin().getVersion(), e);
|
||||
} catch (Exception e) {
|
||||
return tab.getErrorManager().printError(DEFAULT_GROUP, "Failed to get permission groups of " + p.getName() + " using " + tab.getPermissionPlugin().getName() + " v" + tab.getPermissionPlugin().getVersion(), e);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -80,11 +84,19 @@ public class GroupRefresher implements Feature {
|
||||
}
|
||||
}
|
||||
tab.getErrorManager().oneTimeConsoleError("Player " + p.getName() + " does not have any group permission while assign-groups-by-permissions is enabled! Did you forget to add his group to primary-group-finding-list?");
|
||||
return "<null>";
|
||||
return DEFAULT_GROUP;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TabFeature getFeatureType() {
|
||||
return TabFeature.GROUP_REFRESHING;
|
||||
}
|
||||
|
||||
public boolean isGroupsByPermissions() {
|
||||
return groupsByPermissions;
|
||||
}
|
||||
|
||||
public boolean isUsePrimaryGroup() {
|
||||
return usePrimaryGroup;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,160 @@
|
||||
package me.neznamy.tab.shared.features;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import me.neznamy.tab.api.TabPlayer;
|
||||
import me.neznamy.tab.shared.PropertyUtils;
|
||||
import me.neznamy.tab.shared.TAB;
|
||||
import me.neznamy.tab.shared.cpu.TabFeature;
|
||||
import me.neznamy.tab.shared.features.types.Loadable;
|
||||
import me.neznamy.tab.shared.features.types.Refreshable;
|
||||
import me.neznamy.tab.shared.features.types.event.JoinEventListener;
|
||||
import me.neznamy.tab.shared.features.types.event.QuitEventListener;
|
||||
import me.neznamy.tab.shared.features.types.event.WorldChangeListener;
|
||||
import me.neznamy.tab.shared.packets.IChatBaseComponent;
|
||||
import me.neznamy.tab.shared.packets.PacketPlayOutPlayerListHeaderFooter;
|
||||
|
||||
/**
|
||||
* Feature handler for header and footer
|
||||
*/
|
||||
public class HeaderFooter implements Loadable, JoinEventListener, QuitEventListener, WorldChangeListener, Refreshable {
|
||||
|
||||
private static final String LINE_SEPARATOR = "\n\u00a7r";
|
||||
private TAB tab;
|
||||
private List<String> usedPlaceholders;
|
||||
private List<String> disabledWorlds;
|
||||
private Set<TabPlayer> playersInDisabledWorlds = new HashSet<>();
|
||||
|
||||
public HeaderFooter(TAB tab) {
|
||||
this.tab = tab;
|
||||
disabledWorlds = tab.getConfiguration().getConfig().getStringList("disable-features-in-"+tab.getPlatform().getSeparatorType()+"s.header-footer", Arrays.asList("disabled" + tab.getPlatform().getSeparatorType()));
|
||||
refreshUsedPlaceholders();
|
||||
tab.debug(String.format("Loaded HeaderFooter feature with parameters disabledWorlds=%s", disabledWorlds));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void load() {
|
||||
for (TabPlayer p : tab.getPlayers()) {
|
||||
onJoin(p);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unload() {
|
||||
for (TabPlayer p : tab.getPlayers()) {
|
||||
if (playersInDisabledWorlds.contains(p) || p.getVersion().getMinorVersion() < 8) continue;
|
||||
p.sendCustomPacket(new PacketPlayOutPlayerListHeaderFooter("",""), getFeatureType());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onJoin(TabPlayer connectedPlayer) {
|
||||
if (isDisabledWorld(disabledWorlds, connectedPlayer.getWorldName())) {
|
||||
playersInDisabledWorlds.add(connectedPlayer);
|
||||
return;
|
||||
}
|
||||
refresh(connectedPlayer, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onWorldChange(TabPlayer p, String from, String to) {
|
||||
boolean disabledBefore = playersInDisabledWorlds.contains(p);
|
||||
boolean disabledNow = false;
|
||||
if (isDisabledWorld(disabledWorlds, p.getWorldName())) {
|
||||
disabledNow = true;
|
||||
playersInDisabledWorlds.add(p);
|
||||
} else {
|
||||
playersInDisabledWorlds.remove(p);
|
||||
}
|
||||
if (p.getVersion().getMinorVersion() < 8) return;
|
||||
if (disabledNow) {
|
||||
if (!disabledBefore) p.sendCustomPacket(new PacketPlayOutPlayerListHeaderFooter("", ""), getFeatureType());
|
||||
} else {
|
||||
if (disabledBefore) {
|
||||
refresh(p, true);
|
||||
return;
|
||||
}
|
||||
boolean refresh = false;
|
||||
String headerAppend = getValue(p, "headerappend");
|
||||
if (headerAppend.length() > 0) headerAppend = LINE_SEPARATOR + headerAppend;
|
||||
String header = getValue(p, PropertyUtils.HEADER) + headerAppend;
|
||||
if (!p.getProperty(PropertyUtils.HEADER).getOriginalRawValue().equals(header)) {
|
||||
p.setProperty(PropertyUtils.HEADER, header);
|
||||
refresh = true;
|
||||
}
|
||||
|
||||
String footerAppend = getValue(p, "footerappend");
|
||||
if (footerAppend.length() > 0) footerAppend = LINE_SEPARATOR + footerAppend;
|
||||
String footer = getValue(p, PropertyUtils.FOOTER) + footerAppend;
|
||||
if (!p.getProperty(PropertyUtils.FOOTER).getOriginalRawValue().equals(footer)) {
|
||||
p.setProperty(PropertyUtils.FOOTER, footer);
|
||||
refresh = true;
|
||||
}
|
||||
if (refresh) {
|
||||
p.sendCustomPacket(new PacketPlayOutPlayerListHeaderFooter(IChatBaseComponent.optimizedComponent(p.getProperty(PropertyUtils.HEADER).updateAndGet()),
|
||||
IChatBaseComponent.optimizedComponent(p.getProperty(PropertyUtils.FOOTER).updateAndGet())), getFeatureType());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void refresh(TabPlayer p, boolean force) {
|
||||
if (force) {
|
||||
String headerAppend = getValue(p, "headerappend");
|
||||
if (headerAppend.length() > 0) headerAppend = LINE_SEPARATOR + headerAppend;
|
||||
p.setProperty(PropertyUtils.HEADER, getValue(p, PropertyUtils.HEADER) + headerAppend);
|
||||
|
||||
String footerAppend = getValue(p, "footerappend");
|
||||
if (footerAppend.length() > 0) footerAppend = LINE_SEPARATOR + footerAppend;
|
||||
p.setProperty(PropertyUtils.FOOTER, getValue(p, PropertyUtils.FOOTER) + footerAppend);
|
||||
}
|
||||
if (playersInDisabledWorlds.contains(p) || p.getVersion().getMinorVersion() < 8) return;
|
||||
p.sendCustomPacket(new PacketPlayOutPlayerListHeaderFooter(IChatBaseComponent.optimizedComponent(p.getProperty(PropertyUtils.HEADER).updateAndGet()),
|
||||
IChatBaseComponent.optimizedComponent(p.getProperty(PropertyUtils.FOOTER).updateAndGet())), getFeatureType());
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getUsedPlaceholders() {
|
||||
return usedPlaceholders;
|
||||
}
|
||||
|
||||
private String getValue(TabPlayer p, String property) {
|
||||
String worldGroup = tab.getConfiguration().getWorldGroupOf(tab.getConfiguration().getConfig().getConfigurationSection("per-" + tab.getPlatform().getSeparatorType() + "-settings").keySet(), p.getWorldName());
|
||||
String[] priorities = {
|
||||
"per-" + tab.getPlatform().getSeparatorType() + "-settings." + worldGroup + ".Users." + p.getName() + "." + property,
|
||||
"per-" + tab.getPlatform().getSeparatorType() + "-settings." + worldGroup + ".Users." + p.getUniqueId().toString() + "." + property,
|
||||
"Users." + p.getName() + "." + property,
|
||||
"Users." + p.getUniqueId().toString() + "." + property,
|
||||
"per-" + tab.getPlatform().getSeparatorType() + "-settings." + worldGroup + ".Groups." + p.getGroup() + "." + property,
|
||||
"per-" + tab.getPlatform().getSeparatorType() + "-settings." + worldGroup + "." + property,
|
||||
"Groups." + p.getGroup() + "." + property,
|
||||
property
|
||||
};
|
||||
List<String> lines = null;
|
||||
for (String path : priorities) {
|
||||
lines = tab.getConfiguration().getConfig().getStringList(path);
|
||||
if (lines != null) break;
|
||||
}
|
||||
if (lines == null) lines = new ArrayList<>();
|
||||
return String.join(LINE_SEPARATOR, lines);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void refreshUsedPlaceholders() {
|
||||
usedPlaceholders = tab.getConfiguration().getConfig().getUsedPlaceholderIdentifiersRecursive(PropertyUtils.HEADER, PropertyUtils.FOOTER);
|
||||
}
|
||||
|
||||
@Override
|
||||
public TabFeature getFeatureType() {
|
||||
return TabFeature.HEADER_FOOTER;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onQuit(TabPlayer disconnectedPlayer) {
|
||||
playersInDisabledWorlds.remove(disconnectedPlayer);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,315 @@
|
||||
package me.neznamy.tab.shared.features;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import me.neznamy.tab.api.TabPlayer;
|
||||
import me.neznamy.tab.shared.ITabPlayer;
|
||||
import me.neznamy.tab.shared.PacketAPI;
|
||||
import me.neznamy.tab.shared.Property;
|
||||
import me.neznamy.tab.shared.PropertyUtils;
|
||||
import me.neznamy.tab.shared.TAB;
|
||||
import me.neznamy.tab.shared.cpu.TabFeature;
|
||||
import me.neznamy.tab.shared.cpu.UsageType;
|
||||
import me.neznamy.tab.shared.features.sorting.Sorting;
|
||||
import me.neznamy.tab.shared.features.types.Loadable;
|
||||
import me.neznamy.tab.shared.features.types.Refreshable;
|
||||
import me.neznamy.tab.shared.features.types.event.JoinEventListener;
|
||||
import me.neznamy.tab.shared.features.types.event.QuitEventListener;
|
||||
import me.neznamy.tab.shared.features.types.event.WorldChangeListener;
|
||||
import me.neznamy.tab.shared.features.types.packet.LoginPacketListener;
|
||||
import me.neznamy.tab.shared.packets.PacketPlayOutScoreboardTeam;
|
||||
|
||||
public class NameTag implements Loadable, Refreshable, LoginPacketListener, QuitEventListener, WorldChangeListener, JoinEventListener {
|
||||
|
||||
protected TAB tab;
|
||||
protected Set<String> usedPlaceholders;
|
||||
protected List<String> disabledWorlds;
|
||||
private boolean collisionRule;
|
||||
private List<String> revertedCollision;
|
||||
private boolean invisibleNametags;
|
||||
protected Set<String> invisiblePlayers = new HashSet<>();
|
||||
private Sorting sorting;
|
||||
protected Map<String, Boolean> collision = new HashMap<>();
|
||||
protected Set<TabPlayer> playersInDisabledWorlds = new HashSet<>();
|
||||
|
||||
public NameTag(TAB tab) {
|
||||
this.tab = tab;
|
||||
disabledWorlds = tab.getConfiguration().getConfig().getStringList("disable-features-in-"+tab.getPlatform().getSeparatorType()+"s.nametag", Arrays.asList("disabled" + tab.getPlatform().getSeparatorType()));
|
||||
collisionRule = tab.getConfiguration().getConfig().getBoolean("enable-collision", true);
|
||||
revertedCollision = tab.getConfiguration().getConfig().getStringList("revert-collision-rule-in-" + tab.getPlatform().getSeparatorType()+"s", Arrays.asList("reverted" + tab.getPlatform().getSeparatorType()));
|
||||
invisibleNametags = tab.getConfiguration().getConfig().getBoolean("invisible-nametags", false);
|
||||
sorting = new Sorting(tab, this);
|
||||
usedPlaceholders = new HashSet<>(tab.getConfiguration().getConfig().getUsedPlaceholderIdentifiersRecursive(PropertyUtils.TAGPREFIX, PropertyUtils.TAGSUFFIX));
|
||||
for (TabPlayer p : tab.getPlayers()) {
|
||||
usedPlaceholders.addAll(tab.getPlaceholderManager().getUsedPlaceholderIdentifiersRecursive(
|
||||
p.getProperty(PropertyUtils.TAGPREFIX).getCurrentRawValue(), p.getProperty(PropertyUtils.TAGSUFFIX).getCurrentRawValue()));
|
||||
}
|
||||
tab.debug(String.format("Loaded NameTag feature with parameters collisionRule=%s, revertedCollision=%s, disabledWorlds=%s, invisibleNametags=%s",
|
||||
collisionRule, revertedCollision, disabledWorlds, invisibleNametags));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void load(){
|
||||
for (TabPlayer all : tab.getPlayers()) {
|
||||
((ITabPlayer) all).setTeamName(getSorting().getTeamName(all));
|
||||
updateProperties(all);
|
||||
collision.put(all.getName(), true);
|
||||
if (all.hasInvisibilityPotion()) invisiblePlayers.add(all.getName());
|
||||
if (isDisabledWorld(disabledWorlds, all.getWorldName())) {
|
||||
playersInDisabledWorlds.add(all);
|
||||
continue;
|
||||
}
|
||||
registerTeam(all);
|
||||
}
|
||||
startRefreshingTasks();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unload() {
|
||||
for (TabPlayer p : tab.getPlayers()) {
|
||||
if (!playersInDisabledWorlds.contains(p)) unregisterTeam(p);
|
||||
}
|
||||
}
|
||||
|
||||
public void startRefreshingTasks() {
|
||||
//workaround for a 1.8.x client-sided bug
|
||||
tab.getCPUManager().startRepeatingMeasuredTask(500, "refreshing nametag visibility", TabFeature.NAMETAGS, UsageType.REFRESHING_NAMETAG_VISIBILITY_AND_COLLISION, () -> {
|
||||
|
||||
for (TabPlayer p : tab.getPlayers()) {
|
||||
if (!p.isLoaded() || playersInDisabledWorlds.contains(p)) continue;
|
||||
//nametag visibility
|
||||
boolean invisible = p.hasInvisibilityPotion();
|
||||
if (invisible && !invisiblePlayers.contains(p.getName())) {
|
||||
invisiblePlayers.add(p.getName());
|
||||
updateTeamData(p);
|
||||
}
|
||||
if (!invisible && invisiblePlayers.contains(p.getName())) {
|
||||
invisiblePlayers.remove(p.getName());
|
||||
updateTeamData(p);
|
||||
}
|
||||
//cannot control collision rule on <1.9 servers in any way
|
||||
if (TAB.getInstance().getServerVersion().getMinorVersion() >= 9) updateCollision(p);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public boolean isDisabledWorld(String world) {
|
||||
return isDisabledWorld(disabledWorlds, world);
|
||||
}
|
||||
|
||||
public Set<String> getInvisiblePlayers(){
|
||||
return invisiblePlayers;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getUsedPlaceholders() {
|
||||
return new ArrayList<>(usedPlaceholders);
|
||||
}
|
||||
|
||||
public void unregisterTeam(TabPlayer p) {
|
||||
if (p.hasTeamHandlingPaused()) return;
|
||||
if (p.getTeamName() == null) return;
|
||||
for (TabPlayer viewer : tab.getPlayers()) {
|
||||
viewer.sendCustomPacket(new PacketPlayOutScoreboardTeam(p.getTeamName()), TabFeature.NAMETAGS);
|
||||
}
|
||||
}
|
||||
|
||||
public void unregisterTeam(TabPlayer p, TabPlayer viewer) {
|
||||
if (p.hasTeamHandlingPaused()) return;
|
||||
viewer.sendCustomPacket(new PacketPlayOutScoreboardTeam(p.getTeamName()), TabFeature.NAMETAGS);
|
||||
}
|
||||
|
||||
public void registerTeam(TabPlayer p) {
|
||||
if (p.hasTeamHandlingPaused()) return;
|
||||
Property tagprefix = p.getProperty(PropertyUtils.TAGPREFIX);
|
||||
Property tagsuffix = p.getProperty(PropertyUtils.TAGSUFFIX);
|
||||
for (TabPlayer viewer : tab.getPlayers()) {
|
||||
String currentPrefix = tagprefix.getFormat(viewer);
|
||||
String currentSuffix = tagsuffix.getFormat(viewer);
|
||||
PacketAPI.registerScoreboardTeam(viewer, p.getTeamName(), currentPrefix, currentSuffix, getTeamVisibility(p, viewer), getCollision(p), Arrays.asList(p.getName()), null, TabFeature.NAMETAGS);
|
||||
}
|
||||
}
|
||||
|
||||
public void registerTeam(TabPlayer p, TabPlayer viewer) {
|
||||
if (p.hasTeamHandlingPaused()) return;
|
||||
Property tagprefix = p.getProperty(PropertyUtils.TAGPREFIX);
|
||||
Property tagsuffix = p.getProperty(PropertyUtils.TAGSUFFIX);
|
||||
String replacedPrefix = tagprefix.getFormat(viewer);
|
||||
String replacedSuffix = tagsuffix.getFormat(viewer);
|
||||
PacketAPI.registerScoreboardTeam(viewer, p.getTeamName(), replacedPrefix, replacedSuffix, getTeamVisibility(p, viewer), getCollision(p), Arrays.asList(p.getName()), null, TabFeature.NAMETAGS);
|
||||
}
|
||||
|
||||
public void updateTeam(TabPlayer p) {
|
||||
if (p.getTeamName() == null) return; //player not loaded yet
|
||||
String newName = getSorting().getTeamName(p);
|
||||
if (p.getTeamName().equals(newName)) {
|
||||
updateTeamData(p);
|
||||
} else {
|
||||
unregisterTeam(p);
|
||||
((ITabPlayer) p).setTeamName(newName);
|
||||
registerTeam(p);
|
||||
}
|
||||
}
|
||||
|
||||
public void updateTeamData(TabPlayer p) {
|
||||
Property tagprefix = p.getProperty(PropertyUtils.TAGPREFIX);
|
||||
Property tagsuffix = p.getProperty(PropertyUtils.TAGSUFFIX);
|
||||
for (TabPlayer viewer : tab.getPlayers()) {
|
||||
String currentPrefix = tagprefix.getFormat(viewer);
|
||||
String currentSuffix = tagsuffix.getFormat(viewer);
|
||||
boolean visible = getTeamVisibility(p, viewer);
|
||||
viewer.sendCustomPacket(new PacketPlayOutScoreboardTeam(p.getTeamName(), currentPrefix, currentSuffix, translate(visible), translate(getCollision(p)), 0), TabFeature.NAMETAGS);
|
||||
}
|
||||
}
|
||||
|
||||
public void updateTeamData(TabPlayer p, TabPlayer viewer) {
|
||||
Property tagprefix = p.getProperty(PropertyUtils.TAGPREFIX);
|
||||
Property tagsuffix = p.getProperty(PropertyUtils.TAGSUFFIX);
|
||||
boolean visible = getTeamVisibility(p, viewer);
|
||||
String currentPrefix = tagprefix.getFormat(viewer);
|
||||
String currentSuffix = tagsuffix.getFormat(viewer);
|
||||
viewer.sendCustomPacket(new PacketPlayOutScoreboardTeam(p.getTeamName(), currentPrefix, currentSuffix, translate(visible), translate(getCollision(p)), 0), TabFeature.NAMETAGS);
|
||||
}
|
||||
|
||||
private String translate(boolean b) {
|
||||
return b ? "always" : "never";
|
||||
}
|
||||
|
||||
private void updateCollision(TabPlayer p) {
|
||||
if (TAB.getInstance().getFeatureManager().getNameTagFeature() == null || !p.isOnline()) return;
|
||||
if (p.getCollisionRule() != null) {
|
||||
if (getCollision(p) != p.getCollisionRule()) {
|
||||
collision.put(p.getName(), p.getCollisionRule());
|
||||
updateTeamData(p);
|
||||
}
|
||||
} else {
|
||||
boolean newCollision = !p.isDisguised() && revertedCollision.contains(p.getWorldName()) ? !collisionRule : collisionRule;
|
||||
if (collision.get(p.getName()) == null || getCollision(p) != newCollision) {
|
||||
collision.put(p.getName(), newCollision);
|
||||
updateTeamData(p);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected Boolean getCollision(TabPlayer p) {
|
||||
if (!p.isOnline()) return false;
|
||||
if (p.getCollisionRule() != null) return p.getCollisionRule();
|
||||
if (!collision.containsKey(p.getName())) {
|
||||
collision.put(p.getName(), revertedCollision.contains(p.getWorldName()) ? !collisionRule : collisionRule);
|
||||
}
|
||||
return collision.get(p.getName());
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onLoginPacket(TabPlayer packetReceiver) {
|
||||
for (TabPlayer all : tab.getPlayers()) {
|
||||
if (!all.isLoaded()) continue;
|
||||
if (!playersInDisabledWorlds.contains(all)) registerTeam(all, packetReceiver);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void refresh(TabPlayer refreshed, boolean force) {
|
||||
if (playersInDisabledWorlds.contains(refreshed)) return;
|
||||
boolean refresh;
|
||||
if (force) {
|
||||
updateProperties(refreshed);
|
||||
refresh = true;
|
||||
} else {
|
||||
boolean prefix = refreshed.getProperty(PropertyUtils.TAGPREFIX).update();
|
||||
boolean suffix = refreshed.getProperty(PropertyUtils.TAGSUFFIX).update();
|
||||
refresh = prefix || suffix;
|
||||
}
|
||||
|
||||
if (refresh) updateTeam(refreshed);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onJoin(TabPlayer connectedPlayer) {
|
||||
((ITabPlayer) connectedPlayer).setTeamName(getSorting().getTeamName(connectedPlayer));
|
||||
updateProperties(connectedPlayer);
|
||||
collision.put(connectedPlayer.getName(), true);
|
||||
for (TabPlayer all : tab.getPlayers()) {
|
||||
if (!all.isLoaded() || all == connectedPlayer) continue; //avoiding double registration
|
||||
if (!playersInDisabledWorlds.contains(all)) {
|
||||
registerTeam(all, connectedPlayer);
|
||||
}
|
||||
}
|
||||
if (isDisabledWorld(disabledWorlds, connectedPlayer.getWorldName())) {
|
||||
playersInDisabledWorlds.add(connectedPlayer);
|
||||
return;
|
||||
}
|
||||
registerTeam(connectedPlayer);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onQuit(TabPlayer disconnectedPlayer) {
|
||||
if (!playersInDisabledWorlds.contains(disconnectedPlayer)) unregisterTeam(disconnectedPlayer);
|
||||
invisiblePlayers.remove(disconnectedPlayer.getName());
|
||||
collision.remove(disconnectedPlayer.getName());
|
||||
playersInDisabledWorlds.remove(disconnectedPlayer);
|
||||
for (TabPlayer all : tab.getPlayers()) {
|
||||
if (all == disconnectedPlayer) continue;
|
||||
all.showNametag(disconnectedPlayer.getUniqueId()); //clearing memory from API method
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onWorldChange(TabPlayer p, String from, String to) {
|
||||
boolean disabledBefore = playersInDisabledWorlds.contains(p);
|
||||
boolean disabledNow = false;
|
||||
if (isDisabledWorld(disabledWorlds, p.getWorldName())) {
|
||||
disabledNow = true;
|
||||
playersInDisabledWorlds.add(p);
|
||||
} else {
|
||||
playersInDisabledWorlds.remove(p);
|
||||
}
|
||||
updateProperties(p);
|
||||
if (disabledNow && !disabledBefore) {
|
||||
unregisterTeam(p);
|
||||
} else if (!disabledNow && disabledBefore) {
|
||||
registerTeam(p);
|
||||
} else {
|
||||
updateTeam(p);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void refreshUsedPlaceholders() {
|
||||
usedPlaceholders = new HashSet<>(tab.getConfiguration().getConfig().getUsedPlaceholderIdentifiersRecursive(PropertyUtils.TAGPREFIX, PropertyUtils.TAGSUFFIX));
|
||||
for (TabPlayer p : tab.getPlayers()) {
|
||||
usedPlaceholders.addAll(tab.getPlaceholderManager().getUsedPlaceholderIdentifiersRecursive(
|
||||
p.getProperty(PropertyUtils.TAGPREFIX).getCurrentRawValue(), p.getProperty(PropertyUtils.TAGSUFFIX).getCurrentRawValue()));
|
||||
}
|
||||
}
|
||||
|
||||
public void updateProperties(TabPlayer p) {
|
||||
p.loadPropertyFromConfig(PropertyUtils.TAGPREFIX);
|
||||
p.loadPropertyFromConfig(PropertyUtils.TAGSUFFIX);
|
||||
}
|
||||
|
||||
public boolean getTeamVisibility(TabPlayer p, TabPlayer viewer) {
|
||||
return !p.hasHiddenNametag() && !p.hasHiddenNametag(viewer.getUniqueId()) &&
|
||||
!invisibleNametags && !invisiblePlayers.contains(p.getName());
|
||||
}
|
||||
|
||||
@Override
|
||||
public TabFeature getFeatureType() {
|
||||
return TabFeature.NAMETAGS;
|
||||
}
|
||||
|
||||
public Sorting getSorting() {
|
||||
return sorting;
|
||||
}
|
||||
|
||||
public Set<TabPlayer> getPlayersInDisabledWorlds(){
|
||||
return playersInDisabledWorlds;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
package me.neznamy.tab.shared.features;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import me.neznamy.tab.api.TabPlayer;
|
||||
import me.neznamy.tab.shared.TAB;
|
||||
import me.neznamy.tab.shared.cpu.TabFeature;
|
||||
import me.neznamy.tab.shared.features.types.Loadable;
|
||||
import me.neznamy.tab.shared.features.types.packet.PlayerInfoPacketListener;
|
||||
import me.neznamy.tab.shared.packets.PacketPlayOutPlayerInfo;
|
||||
import me.neznamy.tab.shared.packets.PacketPlayOutPlayerInfo.EnumPlayerInfoAction;
|
||||
import me.neznamy.tab.shared.packets.PacketPlayOutPlayerInfo.PlayerInfoData;
|
||||
|
||||
/**
|
||||
* Sets ping of all players in the packet to configured value to prevent hacked clients from seeing exact ping value of each player
|
||||
*/
|
||||
public class PingSpoof implements PlayerInfoPacketListener, Loadable {
|
||||
|
||||
//fake ping value
|
||||
private int value;
|
||||
|
||||
/**
|
||||
* Constructs new instance and loads config options
|
||||
*/
|
||||
public PingSpoof() {
|
||||
value = TAB.getInstance().getConfiguration().getConfig().getInt("ping-spoof.value", 0);
|
||||
TAB.getInstance().debug(String.format("Loaded PingSpoof feature with parameters value=%s", value));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPacketSend(TabPlayer receiver, PacketPlayOutPlayerInfo info) {
|
||||
if (info.getAction() != EnumPlayerInfoAction.UPDATE_LATENCY && info.getAction() != EnumPlayerInfoAction.ADD_PLAYER) return;
|
||||
for (PlayerInfoData playerInfoData : info.getEntries()) {
|
||||
playerInfoData.setLatency(value);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public TabFeature getFeatureType() {
|
||||
return TabFeature.PING_SPOOF;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void load() {
|
||||
updateAll(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unload() {
|
||||
updateAll(true);
|
||||
}
|
||||
|
||||
private void updateAll(boolean realPing) {
|
||||
List<PlayerInfoData> list = new ArrayList<>();
|
||||
for (TabPlayer p : TAB.getInstance().getPlayers()) {
|
||||
list.add(new PlayerInfoData(p.getUniqueId(), realPing ? (int) p.getPing() : 0));
|
||||
}
|
||||
for (TabPlayer p : TAB.getInstance().getPlayers()) {
|
||||
p.sendCustomPacket(new PacketPlayOutPlayerInfo(EnumPlayerInfoAction.UPDATE_LATENCY, list), getFeatureType());
|
||||
}
|
||||
}
|
||||
}
|
||||
+5
-5
@@ -19,7 +19,7 @@ import me.neznamy.tab.shared.features.types.event.JoinEventListener;
|
||||
public abstract class PipelineInjector implements JoinEventListener, Loadable {
|
||||
|
||||
//name of the pipeline decoder injected in netty
|
||||
public final String DECODER_NAME = "TAB";
|
||||
public static final String DECODER_NAME = "TAB";
|
||||
|
||||
//tab instance
|
||||
protected TAB tab;
|
||||
@@ -35,10 +35,10 @@ public abstract class PipelineInjector implements JoinEventListener, Loadable {
|
||||
* Constructs new instance
|
||||
* @param tab
|
||||
*/
|
||||
public PipelineInjector(TAB tab) {
|
||||
protected PipelineInjector(TAB tab) {
|
||||
this.tab = tab;
|
||||
antiOverrideTeams = tab.getConfiguration().config.getBoolean("anti-override.scoreboard-teams", true);
|
||||
antiOverrideObjectives = tab.getConfiguration().config.getBoolean("anti-override.scoreboard-objectives", true);
|
||||
antiOverrideTeams = tab.getConfiguration().getConfig().getBoolean("anti-override.scoreboard-teams", true);
|
||||
antiOverrideObjectives = tab.getConfiguration().getConfig().getBoolean("anti-override.scoreboard-objectives", true);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -78,7 +78,7 @@ public abstract class PipelineInjector implements JoinEventListener, Loadable {
|
||||
//not logging the same message for every online player who received the packet
|
||||
if (lastTeamOverrideMessage == null || !message.equals(lastTeamOverrideMessage)) {
|
||||
lastTeamOverrideMessage = message;
|
||||
tab.getErrorManager().printError(message, null, false, tab.getErrorManager().antiOverrideLog);
|
||||
tab.getErrorManager().printError(message, null, false, tab.getErrorManager().getAntiOverrideLog());
|
||||
}
|
||||
}
|
||||
}
|
||||
Loaded 100 of 256 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user