mirror of
https://github.com/Xiao-MoMi/Custom-Nameplates.git
synced 2025-12-19 15:09:23 +00:00
velocity module
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
dependencies {
|
||||
implementation(project(":common"))
|
||||
compileOnly("dev.folia:folia-api:1.20.1-R0.1-SNAPSHOT")
|
||||
compileOnly("me.clip:placeholderapi:2.11.5")
|
||||
}
|
||||
@@ -25,9 +25,9 @@ import org.bukkit.entity.Player;
|
||||
|
||||
public interface AdventureManager {
|
||||
|
||||
net.momirealms.customnameplates.api.common.Key keyToKey(Key key);
|
||||
net.momirealms.customnameplates.common.Key keyToKey(Key key);
|
||||
|
||||
Key keyToKey(net.momirealms.customnameplates.api.common.Key key);
|
||||
Key keyToKey(net.momirealms.customnameplates.common.Key key);
|
||||
|
||||
Object getIChatComponentFromMiniMessage(String text);
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@ import net.momirealms.customnameplates.api.mechanic.nameplate.CachedNameplate;
|
||||
import net.momirealms.customnameplates.api.mechanic.nameplate.Nameplate;
|
||||
import net.momirealms.customnameplates.api.mechanic.nameplate.TagMode;
|
||||
import net.momirealms.customnameplates.api.mechanic.tag.NameplatePlayer;
|
||||
import net.momirealms.customnameplates.api.mechanic.team.TeamColor;
|
||||
import net.momirealms.customnameplates.common.team.TeamColor;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
package net.momirealms.customnameplates.api.manager;
|
||||
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.momirealms.customnameplates.api.mechanic.team.TeamColor;
|
||||
import net.momirealms.customnameplates.api.mechanic.team.TeamTagVisibility;
|
||||
import net.momirealms.customnameplates.common.team.TeamColor;
|
||||
import net.momirealms.customnameplates.common.team.TeamTagVisibility;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public interface TeamManager {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package net.momirealms.customnameplates.api.manager;
|
||||
|
||||
import net.momirealms.customnameplates.api.common.Key;
|
||||
import net.momirealms.customnameplates.api.mechanic.font.FontData;
|
||||
import net.momirealms.customnameplates.common.Key;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public interface WidthManager {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package net.momirealms.customnameplates.api.mechanic.nameplate;
|
||||
|
||||
import net.momirealms.customnameplates.api.mechanic.team.TeamColor;
|
||||
import net.momirealms.customnameplates.common.team.TeamColor;
|
||||
|
||||
public class CachedNameplate {
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@ package net.momirealms.customnameplates.api.mechanic.nameplate;
|
||||
|
||||
import net.momirealms.customnameplates.api.mechanic.character.ConfiguredChar;
|
||||
import net.momirealms.customnameplates.api.mechanic.font.OffsetFont;
|
||||
import net.momirealms.customnameplates.api.mechanic.team.TeamColor;
|
||||
import net.momirealms.customnameplates.common.team.TeamColor;
|
||||
import net.momirealms.customnameplates.api.util.FontUtils;
|
||||
|
||||
public class Nameplate {
|
||||
@@ -86,6 +86,7 @@ public class Nameplate {
|
||||
|
||||
public String getPrefix(int textWidth) {
|
||||
StringBuilder stringBuilder = new StringBuilder();
|
||||
stringBuilder.append("<#FEFEFE>");
|
||||
stringBuilder.append(OffsetFont.getShortestNegChars(textWidth + left.getWidth() + 1));
|
||||
stringBuilder.append(left.getCharacter());
|
||||
stringBuilder.append(OffsetFont.NEG_1.getCharacter());
|
||||
@@ -97,10 +98,13 @@ public class Nameplate {
|
||||
}
|
||||
stringBuilder.append(OffsetFont.getShortestNegChars(middle.getWidth() - (textWidth+2) % middle.getWidth() + 1)); // +1
|
||||
}
|
||||
stringBuilder.append("<#FDFEFE>");
|
||||
stringBuilder.append(middle.getCharacter());
|
||||
stringBuilder.append("</#FDFEFE>");
|
||||
stringBuilder.append(OffsetFont.NEG_1.getCharacter());
|
||||
stringBuilder.append(right.getCharacter());
|
||||
stringBuilder.append(OffsetFont.getShortestNegChars(textWidth + right.getWidth() + 1)); // -1
|
||||
stringBuilder.append("</#FEFEFE>");
|
||||
stringBuilder.append(OffsetFont.getShortestNegChars(textWidth + right.getWidth() + 1)); // -1;
|
||||
return stringBuilder.toString();
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package net.momirealms.customnameplates.api.mechanic.placeholder;
|
||||
|
||||
import me.clip.placeholderapi.PlaceholderAPI;
|
||||
import net.momirealms.customnameplates.api.common.Pair;
|
||||
import net.momirealms.customnameplates.common.Pair;
|
||||
import net.momirealms.customnameplates.api.manager.RequirementManager;
|
||||
import net.momirealms.customnameplates.api.requirement.Condition;
|
||||
import net.momirealms.customnameplates.api.requirement.Requirement;
|
||||
|
||||
@@ -6,8 +6,8 @@ import net.momirealms.customnameplates.api.manager.TeamTagManager;
|
||||
import net.momirealms.customnameplates.api.mechanic.misc.ViewerText;
|
||||
import net.momirealms.customnameplates.api.mechanic.nameplate.Nameplate;
|
||||
import net.momirealms.customnameplates.api.mechanic.tag.NameplatePlayer;
|
||||
import net.momirealms.customnameplates.api.mechanic.team.TeamColor;
|
||||
import net.momirealms.customnameplates.api.mechanic.team.TeamTagVisibility;
|
||||
import net.momirealms.customnameplates.common.team.TeamColor;
|
||||
import net.momirealms.customnameplates.common.team.TeamTagVisibility;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.Vector;
|
||||
|
||||
@@ -5,8 +5,8 @@ import net.momirealms.customnameplates.api.CustomNameplatesPlugin;
|
||||
import net.momirealms.customnameplates.api.manager.UnlimitedTagManager;
|
||||
import net.momirealms.customnameplates.api.mechanic.nameplate.Nameplate;
|
||||
import net.momirealms.customnameplates.api.mechanic.tag.NameplatePlayer;
|
||||
import net.momirealms.customnameplates.api.mechanic.team.TeamColor;
|
||||
import net.momirealms.customnameplates.api.mechanic.team.TeamTagVisibility;
|
||||
import net.momirealms.customnameplates.common.team.TeamColor;
|
||||
import net.momirealms.customnameplates.common.team.TeamTagVisibility;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.entity.Pose;
|
||||
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
package net.momirealms.customnameplates.api.mechanic.team;
|
||||
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.momirealms.customnameplates.common.team.TeamCollisionRule;
|
||||
import net.momirealms.customnameplates.common.team.TeamColor;
|
||||
import net.momirealms.customnameplates.common.team.TeamTagVisibility;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
package net.momirealms.customnameplates.api.mechanic.team;
|
||||
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.momirealms.customnameplates.common.team.TeamCollisionRule;
|
||||
import net.momirealms.customnameplates.common.team.TeamColor;
|
||||
import net.momirealms.customnameplates.common.team.TeamTagVisibility;
|
||||
|
||||
public class TeamUpdatePacket {
|
||||
|
||||
|
||||
@@ -36,6 +36,7 @@ allprojects {
|
||||
maven("https://repo.auxilor.io/repository/maven-public/")
|
||||
maven("https://betonquest.org/nexus/repository/betonquest/")
|
||||
maven("https://repo.william278.net/releases/")
|
||||
maven("https://repo.william278.net/velocity/")
|
||||
maven("https://s01.oss.sonatype.org/content/repositories/snapshots/")
|
||||
maven("https://repo.minebench.de/")
|
||||
maven("https://repo.xenondevs.xyz/releases/")
|
||||
|
||||
42
common/.gitignore
vendored
Normal file
42
common/.gitignore
vendored
Normal file
@@ -0,0 +1,42 @@
|
||||
.gradle
|
||||
build/
|
||||
!gradle/wrapper/gradle-wrapper.jar
|
||||
!**/src/main/**/build/
|
||||
!**/src/test/**/build/
|
||||
|
||||
### IntelliJ IDEA ###
|
||||
.idea/modules.xml
|
||||
.idea/jarRepositories.xml
|
||||
.idea/compiler.xml
|
||||
.idea/libraries/
|
||||
*.iws
|
||||
*.iml
|
||||
*.ipr
|
||||
out/
|
||||
!**/src/main/**/out/
|
||||
!**/src/test/**/out/
|
||||
|
||||
### Eclipse ###
|
||||
.apt_generated
|
||||
.classpath
|
||||
.factorypath
|
||||
.project
|
||||
.settings
|
||||
.springBeans
|
||||
.sts4-cache
|
||||
bin/
|
||||
!**/src/main/**/bin/
|
||||
!**/src/test/**/bin/
|
||||
|
||||
### NetBeans ###
|
||||
/nbproject/private/
|
||||
/nbbuild/
|
||||
/dist/
|
||||
/nbdist/
|
||||
/.nb-gradle/
|
||||
|
||||
### VS Code ###
|
||||
.vscode/
|
||||
|
||||
### Mac OS ###
|
||||
.DS_Store
|
||||
3
common/build.gradle.kts
Normal file
3
common/build.gradle.kts
Normal file
@@ -0,0 +1,3 @@
|
||||
dependencies {
|
||||
compileOnly("org.jetbrains:annotations:24.1.0")
|
||||
}
|
||||
@@ -15,7 +15,7 @@
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package net.momirealms.customnameplates.api.common;
|
||||
package net.momirealms.customnameplates.common;
|
||||
|
||||
public record Key(String namespace, String value) {
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package net.momirealms.customnameplates.api.common;
|
||||
package net.momirealms.customnameplates.common;
|
||||
|
||||
public record Pair<L, R>(L left, R right) {
|
||||
|
||||
@@ -15,9 +15,7 @@
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package net.momirealms.customnameplates.api.common;
|
||||
|
||||
import org.bukkit.Location;
|
||||
package net.momirealms.customnameplates.common;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
@@ -56,8 +54,4 @@ public record SimpleLocation(String worldName, int x, int y, int z) {
|
||||
hash = 19 * hash + (int) (Double.doubleToLongBits(this.z) ^ (Double.doubleToLongBits(this.z) >>> 32));
|
||||
return hash;
|
||||
}
|
||||
|
||||
public static SimpleLocation getByBukkitLocation(Location location) {
|
||||
return new SimpleLocation(location.getWorld().getName(), location.getBlockX(), location.getBlockY(), location.getBlockZ());
|
||||
}
|
||||
}
|
||||
@@ -15,7 +15,7 @@
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package net.momirealms.customnameplates.api.common;
|
||||
package net.momirealms.customnameplates.common;
|
||||
|
||||
public class Tuple<L, M, R> {
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
package net.momirealms.customnameplates.common.message;
|
||||
|
||||
public class MessageType {
|
||||
|
||||
public static final String CREATE = "0";
|
||||
public static final String REMOVE = "1";
|
||||
public static final String UPDATE = "2";
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
package net.momirealms.customnameplates.api.mechanic.team;
|
||||
package net.momirealms.customnameplates.common.team;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package net.momirealms.customnameplates.api.mechanic.team;
|
||||
package net.momirealms.customnameplates.common.team;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package net.momirealms.customnameplates.api.mechanic.team;
|
||||
package net.momirealms.customnameplates.common.team;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
@@ -39,6 +39,7 @@ dependencies {
|
||||
|
||||
// api module
|
||||
implementation(project(":api"))
|
||||
implementation(project(":common"))
|
||||
|
||||
// adventure
|
||||
implementation("net.kyori:adventure-api:4.15.0")
|
||||
@@ -55,7 +56,7 @@ dependencies {
|
||||
|
||||
tasks {
|
||||
shadowJar {
|
||||
// relocate ("net.kyori", "net.momirealms.customnameplates.libraries")
|
||||
relocate ("net.kyori", "net.momirealms.customnameplates.libraries")
|
||||
relocate ("org.bstats", "net.momirealms.customnameplates.libraries.bstats")
|
||||
relocate ("net.momirealms.biomeapi", "net.momirealms.customnameplates.libraries.biomeapi")
|
||||
}
|
||||
|
||||
@@ -70,7 +70,7 @@ public class CustomNameplatesPluginImpl extends CustomNameplatesPlugin {
|
||||
public void onDisable() {
|
||||
((SchedulerImpl) this.scheduler).shutdown();
|
||||
((ActionBarManagerImpl) actionBarManager).unload();
|
||||
((NameplateManagerImpl) this.nameplateManager).unload();
|
||||
((NameplateManagerImpl) this.nameplateManager).disable();
|
||||
((TeamManagerImpl) this.teamManager).unload();
|
||||
((BossBarManagerImpl) this.bossBarManager).unload();
|
||||
((ImageManagerImpl) this.imageManager).unload();
|
||||
|
||||
@@ -75,12 +75,12 @@ public class AdventureManagerImpl implements AdventureManager {
|
||||
}
|
||||
|
||||
@Override
|
||||
public net.momirealms.customnameplates.api.common.Key keyToKey(Key key) {
|
||||
return net.momirealms.customnameplates.api.common.Key.of(key.namespace(), key.value());
|
||||
public net.momirealms.customnameplates.common.Key keyToKey(Key key) {
|
||||
return net.momirealms.customnameplates.common.Key.of(key.namespace(), key.value());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Key keyToKey(net.momirealms.customnameplates.api.common.Key key) {
|
||||
public Key keyToKey(net.momirealms.customnameplates.common.Key key) {
|
||||
return Key.key(key.namespace(), key.value());
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package net.momirealms.customnameplates.paper.mechanic.bossbar;
|
||||
|
||||
import net.momirealms.customnameplates.api.CustomNameplatesPlugin;
|
||||
import net.momirealms.customnameplates.api.common.Pair;
|
||||
import net.momirealms.customnameplates.common.Pair;
|
||||
import net.momirealms.customnameplates.api.manager.BossBarManager;
|
||||
import net.momirealms.customnameplates.api.util.LogUtils;
|
||||
import net.momirealms.customnameplates.paper.mechanic.misc.DisplayController;
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package net.momirealms.customnameplates.paper.mechanic.bossbar;
|
||||
|
||||
import net.momirealms.customnameplates.api.CustomNameplatesPlugin;
|
||||
import net.momirealms.customnameplates.api.common.Pair;
|
||||
import net.momirealms.customnameplates.common.Pair;
|
||||
import net.momirealms.customnameplates.api.requirement.Condition;
|
||||
import net.momirealms.customnameplates.api.scheduler.CancellableTask;
|
||||
import net.momirealms.customnameplates.api.util.LogUtils;
|
||||
|
||||
@@ -13,15 +13,14 @@ import net.kyori.adventure.text.minimessage.internal.parser.node.TagNode;
|
||||
import net.kyori.adventure.text.minimessage.internal.parser.node.ValueNode;
|
||||
import net.kyori.adventure.text.minimessage.tag.Inserting;
|
||||
import net.momirealms.customnameplates.api.CustomNameplatesPlugin;
|
||||
import net.momirealms.customnameplates.api.common.Key;
|
||||
import net.momirealms.customnameplates.api.common.Tuple;
|
||||
import net.momirealms.customnameplates.common.Key;
|
||||
import net.momirealms.customnameplates.common.Tuple;
|
||||
import net.momirealms.customnameplates.api.manager.WidthManager;
|
||||
import net.momirealms.customnameplates.api.mechanic.background.BackGround;
|
||||
import net.momirealms.customnameplates.api.mechanic.character.ConfiguredChar;
|
||||
import net.momirealms.customnameplates.api.mechanic.font.FontData;
|
||||
import net.momirealms.customnameplates.api.mechanic.font.OffsetFont;
|
||||
import net.momirealms.customnameplates.api.mechanic.nameplate.Nameplate;
|
||||
import net.momirealms.customnameplates.api.util.FontUtils;
|
||||
import net.momirealms.customnameplates.api.util.LogUtils;
|
||||
import net.momirealms.customnameplates.paper.adventure.AdventureManagerImpl;
|
||||
import net.momirealms.customnameplates.paper.setting.CNConfig;
|
||||
@@ -80,8 +79,7 @@ public class WidthManagerImpl implements WidthManager {
|
||||
|
||||
private void loadInternalConfigs() {
|
||||
FontData fontData = new FontData(8);
|
||||
ArrayList<ConfiguredChar> chars = new ArrayList<>();
|
||||
chars.addAll(plugin.getImageManager().getImages());
|
||||
ArrayList<ConfiguredChar> chars = new ArrayList<>(plugin.getImageManager().getImages());
|
||||
for (Nameplate nameplate : plugin.getNameplateManager().getNameplates()) {
|
||||
chars.add(nameplate.getLeft());
|
||||
chars.add(nameplate.getMiddle());
|
||||
@@ -241,7 +239,6 @@ public class WidthManagerImpl implements WidthManager {
|
||||
try (BufferedReader reader = new BufferedReader(new InputStreamReader(zipFile.getInputStream(entry)))) {
|
||||
YamlConfiguration yml = new YamlConfiguration();
|
||||
String line;
|
||||
loop:
|
||||
while ((line = reader.readLine()) != null) {
|
||||
String[] parts = line.split(":");
|
||||
if (parts.length > 1) {
|
||||
@@ -263,7 +260,8 @@ public class WidthManagerImpl implements WidthManager {
|
||||
|
||||
int x;
|
||||
int n;
|
||||
outer: {
|
||||
outer:
|
||||
{
|
||||
for (x = 0; x < splitInterval; x++) {
|
||||
inner:
|
||||
for (int y = 0; y < 16; y++) {
|
||||
|
||||
@@ -15,7 +15,7 @@ import net.momirealms.customnameplates.api.mechanic.nameplate.Nameplate;
|
||||
import net.momirealms.customnameplates.api.mechanic.nameplate.TagMode;
|
||||
import net.momirealms.customnameplates.api.mechanic.tag.NameplatePlayer;
|
||||
import net.momirealms.customnameplates.api.mechanic.tag.unlimited.UnlimitedTagSetting;
|
||||
import net.momirealms.customnameplates.api.mechanic.team.TeamColor;
|
||||
import net.momirealms.customnameplates.common.team.TeamColor;
|
||||
import net.momirealms.customnameplates.api.scheduler.CancellableTask;
|
||||
import net.momirealms.customnameplates.api.util.FontUtils;
|
||||
import net.momirealms.customnameplates.api.util.LogUtils;
|
||||
@@ -120,6 +120,11 @@ public class NameplateManagerImpl implements NameplateManager, Listener {
|
||||
ProtocolLibrary.getProtocolManager().removePacketListener(entityTeleportListener);
|
||||
}
|
||||
|
||||
public void disable() {
|
||||
this.proxyMode = false;
|
||||
unload();
|
||||
}
|
||||
|
||||
public void load() {
|
||||
if (!CNConfig.nameplateModule) return;
|
||||
this.loadConfig();
|
||||
@@ -411,7 +416,7 @@ public class NameplateManagerImpl implements NameplateManager, Listener {
|
||||
public String getNameplatePrefix(Player player) {
|
||||
CachedNameplate cachedNameplate = cachedNameplateMap.get(player.getUniqueId());
|
||||
if (cachedNameplate == null) return "";
|
||||
return "<#FEFEFE>" + cachedNameplate.getTagPrefix() + "</#FEFEFE>";
|
||||
return cachedNameplate.getTagPrefix();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -428,7 +433,7 @@ public class NameplateManagerImpl implements NameplateManager, Listener {
|
||||
return player.getName();
|
||||
}
|
||||
|
||||
return "<#FEFEFE>" + cachedNameplate.getTagPrefix() + "</#FEFEFE>"
|
||||
return cachedNameplate.getTagPrefix()
|
||||
+ cachedNameplate.getNamePrefix()
|
||||
+ cachedNameplate.getPlayerName()
|
||||
+ cachedNameplate.getNameSuffix()
|
||||
|
||||
@@ -184,7 +184,6 @@ public class ResourcePackManagerImpl implements ResourcePackManager {
|
||||
image.setRGB(i, j, 0);
|
||||
}
|
||||
}
|
||||
|
||||
ImageIO.write(image, "png", inputFile);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
@@ -389,12 +388,16 @@ public class ResourcePackManagerImpl implements ResourcePackManager {
|
||||
public static final String Nameplates_Shader =
|
||||
"if (Color.xyz == vec3(255., 254., 253.) / 255.) {\n" +
|
||||
" vertexColor = Color*texelFetch(Sampler2, UV2 / 16, 0);\n" +
|
||||
" vertex.y+= 1;\n" +
|
||||
" vertex.x+= 1;\n" +
|
||||
" vertex.y += 1;\n" +
|
||||
" vertex.x += 1;\n" +
|
||||
" gl_Position = ProjMat * ModelViewMat * vertex;\n" +
|
||||
" } else if (Color.xyz == vec3(254., 254., 254.) / 255.) {\n" +
|
||||
" vertexColor = Color*texelFetch(Sampler2, UV2 / 16, 0);\n" +
|
||||
" vertex.z-= 0.01;\n" +
|
||||
" vertex.z -= 0.001;\n" +
|
||||
" gl_Position = ProjMat * ModelViewMat * vertex;\n" +
|
||||
" } else if (Color.xyz == vec3(253., 254., 254.) / 255.) {\n" +
|
||||
" vertexColor = Color*texelFetch(Sampler2, UV2 / 16, 0);\n" +
|
||||
" vertex.z -= 0.0011;\n" +
|
||||
" gl_Position = ProjMat * ModelViewMat * vertex;\n" +
|
||||
" } else {\n" +
|
||||
" vertexColor = Color*texelFetch(Sampler2, UV2 / 16, 0);\n" +
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package net.momirealms.customnameplates.paper.mechanic.placeholder;
|
||||
|
||||
import net.momirealms.customnameplates.api.CustomNameplatesPlugin;
|
||||
import net.momirealms.customnameplates.api.common.Pair;
|
||||
import net.momirealms.customnameplates.common.Pair;
|
||||
import net.momirealms.customnameplates.api.manager.PlaceholderManager;
|
||||
import net.momirealms.customnameplates.api.mechanic.placeholder.*;
|
||||
import net.momirealms.customnameplates.api.requirement.Requirement;
|
||||
|
||||
@@ -19,7 +19,7 @@ package net.momirealms.customnameplates.paper.mechanic.requirement;
|
||||
|
||||
import me.clip.placeholderapi.PlaceholderAPI;
|
||||
import net.momirealms.biomeapi.BiomeAPI;
|
||||
import net.momirealms.customnameplates.api.common.Pair;
|
||||
import net.momirealms.customnameplates.common.Pair;
|
||||
import net.momirealms.customnameplates.api.manager.RequirementManager;
|
||||
import net.momirealms.customnameplates.api.requirement.Requirement;
|
||||
import net.momirealms.customnameplates.api.requirement.RequirementExpansion;
|
||||
|
||||
@@ -5,9 +5,13 @@ import com.google.common.io.ByteArrayDataInput;
|
||||
import com.google.common.io.ByteArrayDataOutput;
|
||||
import com.google.common.io.ByteStreams;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
|
||||
import net.momirealms.customnameplates.api.CustomNameplatesPlugin;
|
||||
import net.momirealms.customnameplates.api.manager.TeamManager;
|
||||
import net.momirealms.customnameplates.api.mechanic.team.*;
|
||||
import net.momirealms.customnameplates.common.message.MessageType;
|
||||
import net.momirealms.customnameplates.common.team.TeamColor;
|
||||
import net.momirealms.customnameplates.common.team.TeamTagVisibility;
|
||||
import net.momirealms.customnameplates.paper.mechanic.misc.PacketManager;
|
||||
import net.momirealms.customnameplates.paper.mechanic.team.packet.TeamPacketAdaptor;
|
||||
import net.momirealms.customnameplates.paper.mechanic.team.packet.TeamPacket_1_17;
|
||||
@@ -75,7 +79,10 @@ public class TeamManagerImpl implements TeamManager, PluginMessageListener {
|
||||
|
||||
@Override
|
||||
public void createProxyTeam(Player player) {
|
||||
|
||||
sendPluginMessage(
|
||||
MessageType.CREATE,
|
||||
player.getUniqueId().toString()
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -94,7 +101,8 @@ public class TeamManagerImpl implements TeamManager, PluginMessageListener {
|
||||
|
||||
@Override
|
||||
public void removeProxyTeam(Player player) {
|
||||
this.sendPluginMessage(MessageType.REMOVE,
|
||||
this.sendPluginMessage(
|
||||
MessageType.REMOVE,
|
||||
player.getName()
|
||||
);
|
||||
}
|
||||
@@ -103,16 +111,28 @@ public class TeamManagerImpl implements TeamManager, PluginMessageListener {
|
||||
public void updateTeam(Player owner, Player viewer, Component prefix, Component suffix, TeamColor color, TeamTagVisibility visibility) {
|
||||
if (color == TeamColor.NONE || color == TeamColor.CUSTOM)
|
||||
color = TeamColor.WHITE;
|
||||
PacketContainer packet = teamPacketAdaptor.getTeamUpdatePacket(
|
||||
TeamUpdatePacket.builder()
|
||||
.teamName(teamProvider.getTeam(owner))
|
||||
.color(color)
|
||||
.prefix(prefix)
|
||||
.suffix(suffix)
|
||||
.tagVisibility(visibility)
|
||||
.build()
|
||||
);
|
||||
PacketManager.getInstance().send(viewer, packet);
|
||||
if (plugin.getNameplateManager().isProxyMode()) {
|
||||
this.sendPluginMessage(
|
||||
MessageType.UPDATE,
|
||||
owner.getName(),
|
||||
viewer.getName(),
|
||||
GsonComponentSerializer.gson().serialize(prefix),
|
||||
GsonComponentSerializer.gson().serialize(suffix),
|
||||
color.name(),
|
||||
visibility.name()
|
||||
);
|
||||
} else {
|
||||
PacketContainer packet = teamPacketAdaptor.getTeamUpdatePacket(
|
||||
TeamUpdatePacket.builder()
|
||||
.teamName(teamProvider.getTeam(owner))
|
||||
.color(color)
|
||||
.prefix(prefix)
|
||||
.suffix(suffix)
|
||||
.tagVisibility(visibility)
|
||||
.build()
|
||||
);
|
||||
PacketManager.getInstance().send(viewer, packet);
|
||||
}
|
||||
}
|
||||
|
||||
public void reload() {
|
||||
@@ -159,16 +179,11 @@ public class TeamManagerImpl implements TeamManager, PluginMessageListener {
|
||||
ByteArrayDataOutput dataOutput = ByteStreams.newDataOutput();
|
||||
dataOutput.writeByte(messages.length);
|
||||
for (String message : messages) {
|
||||
plugin.debug(message);
|
||||
dataOutput.writeUTF(message);
|
||||
}
|
||||
Bukkit.getOnlinePlayers().stream().findAny().ifPresent(player -> {
|
||||
player.sendPluginMessage(plugin, CHANNEL, dataOutput.toByteArray());
|
||||
});
|
||||
}
|
||||
|
||||
public static class MessageType {
|
||||
|
||||
public static final String CREATE = "create";
|
||||
public static final String REMOVE = "remove";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@ import com.comphenix.protocol.events.PacketContainer;
|
||||
import com.comphenix.protocol.utility.MinecraftReflection;
|
||||
import com.comphenix.protocol.wrappers.WrappedChatComponent;
|
||||
import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
|
||||
import net.momirealms.customnameplates.api.mechanic.team.TeamColor;
|
||||
import net.momirealms.customnameplates.common.team.TeamColor;
|
||||
import net.momirealms.customnameplates.api.mechanic.team.TeamCreatePacket;
|
||||
import net.momirealms.customnameplates.api.mechanic.team.TeamRemovePacket;
|
||||
import net.momirealms.customnameplates.api.mechanic.team.TeamUpdatePacket;
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package net.momirealms.customnameplates.paper.util;
|
||||
|
||||
import net.momirealms.customnameplates.api.CustomNameplatesPlugin;
|
||||
import net.momirealms.customnameplates.api.common.Pair;
|
||||
import net.momirealms.customnameplates.common.Pair;
|
||||
import net.momirealms.customnameplates.api.requirement.Requirement;
|
||||
import net.momirealms.customnameplates.api.util.LogUtils;
|
||||
import net.momirealms.customnameplates.paper.mechanic.misc.TimeLimitText;
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
# Team / Unlimited / Disable
|
||||
mode: TEAM
|
||||
|
||||
# If you are using BungeeCord/Velocity, it's advised to install CustomNameplates on proxy too and enable this option.
|
||||
# You should enable this when you are
|
||||
# ① using Velocitab by William278 on Velocity
|
||||
# ② using TAB by NEZNAMY on BungeeCord
|
||||
proxy: false
|
||||
|
||||
# The duration (in seconds) that the nameplate preview will last for.
|
||||
|
||||
@@ -4,4 +4,5 @@ main: net.momirealms.customnameplates.paper.CustomNameplatesPluginImpl
|
||||
api-version: 1.17
|
||||
authors: [ XiaoMoMi ]
|
||||
folia-supported: true
|
||||
depend: [ ProtocolLib ,PlaceholderAPI ]
|
||||
depend: [ ProtocolLib ,PlaceholderAPI ]
|
||||
softdepend: [ MagicCosmetics, TAB, CMI, TrChat, ItemsAdder, Oraxen ]
|
||||
@@ -3,3 +3,4 @@ include("api")
|
||||
include("bungeecord")
|
||||
include("velocity")
|
||||
include("paper")
|
||||
include("common")
|
||||
|
||||
@@ -1,2 +1,10 @@
|
||||
dependencies {
|
||||
implementation(project(":common"))
|
||||
compileOnly("io.netty:netty-codec-http:4.1.105.Final")
|
||||
// velocity
|
||||
compileOnly("com.velocitypowered:velocity-api:3.3.0-SNAPSHOT")
|
||||
compileOnly("com.velocitypowered:velocity-proxy:3.3.0-SNAPSHOT")
|
||||
annotationProcessor("com.velocitypowered:velocity-api:3.3.0-SNAPSHOT")
|
||||
// velocitab
|
||||
compileOnly("net.william278:velocitab:1.6.1")
|
||||
}
|
||||
@@ -0,0 +1,121 @@
|
||||
package net.momirealms.customnameplates.velocity;
|
||||
|
||||
import com.google.common.io.ByteArrayDataInput;
|
||||
import com.google.common.io.ByteStreams;
|
||||
import com.google.inject.Inject;
|
||||
import com.velocitypowered.api.event.Subscribe;
|
||||
import com.velocitypowered.api.event.connection.PluginMessageEvent;
|
||||
import com.velocitypowered.api.event.proxy.ProxyInitializeEvent;
|
||||
import com.velocitypowered.api.event.proxy.ProxyShutdownEvent;
|
||||
import com.velocitypowered.api.plugin.Dependency;
|
||||
import com.velocitypowered.api.plugin.Plugin;
|
||||
import com.velocitypowered.api.plugin.PluginContainer;
|
||||
import com.velocitypowered.api.proxy.Player;
|
||||
import com.velocitypowered.api.proxy.ProxyServer;
|
||||
import com.velocitypowered.api.proxy.messages.MinecraftChannelIdentifier;
|
||||
import net.momirealms.customnameplates.common.message.MessageType;
|
||||
import net.momirealms.customnameplates.common.team.TeamColor;
|
||||
import net.momirealms.customnameplates.common.team.TeamTagVisibility;
|
||||
import org.slf4j.Logger;
|
||||
|
||||
import java.time.Duration;
|
||||
import java.util.Optional;
|
||||
|
||||
@Plugin(
|
||||
id = "customnameplates",
|
||||
name = "CustomNameplates",
|
||||
version = "2.3",
|
||||
authors = {"XiaoMoMi"},
|
||||
dependencies = {@Dependency(id = "velocitab", optional = true)}
|
||||
)
|
||||
public class CustomNameplatesVelocity {
|
||||
|
||||
private static final String CHANNEL = "customnameplates:cnp";
|
||||
private static CustomNameplatesVelocity instance;
|
||||
private final ProxyServer server;
|
||||
private final Logger logger;
|
||||
private VelocityTeamManager teamManager;
|
||||
|
||||
@Inject
|
||||
public CustomNameplatesVelocity(ProxyServer server, Logger logger) {
|
||||
this.server = server;
|
||||
this.logger = logger;
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void onInit(ProxyInitializeEvent event) {
|
||||
instance = this;
|
||||
server.getChannelRegistrar().register(MinecraftChannelIdentifier.from(CHANNEL));
|
||||
Optional<PluginContainer> optContainer = server.getPluginManager().getPlugin("velocitab");
|
||||
if (optContainer.isEmpty()) {
|
||||
logger.warn("You don't have to install CustomNameplates on Velocity if you don't use Velocitab");
|
||||
server.shutdown();
|
||||
} else {
|
||||
teamManager = new VelocitabManager(optContainer.get());
|
||||
}
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void onShutdown(ProxyShutdownEvent event) {
|
||||
server.getChannelRegistrar().unregister(MinecraftChannelIdentifier.from(CHANNEL));
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
@SuppressWarnings("UnstableApiUsage")
|
||||
public void onPluginMessage(PluginMessageEvent event) {
|
||||
if (!event.getIdentifier().getId().equals(CHANNEL)) {
|
||||
return;
|
||||
}
|
||||
if (teamManager == null) {
|
||||
this.logger.warn("No team manager available");
|
||||
return;
|
||||
}
|
||||
ByteArrayDataInput dataInput = ByteStreams.newDataInput(event.getData());
|
||||
byte length = dataInput.readByte();
|
||||
if (length != 7) {
|
||||
return;
|
||||
}
|
||||
String type = dataInput.readUTF();
|
||||
if (!type.equals(MessageType.UPDATE)) {
|
||||
return;
|
||||
}
|
||||
Optional<Player> optionalOwner = server.getPlayer(dataInput.readUTF());
|
||||
if (optionalOwner.isEmpty()) return;
|
||||
Player owner = optionalOwner.get();
|
||||
|
||||
String team = teamManager.getTeamName(owner);
|
||||
|
||||
Optional<Player> optionalViewer = server.getPlayer(dataInput.readUTF());
|
||||
if (optionalViewer.isEmpty()) return;
|
||||
Player viewer = optionalViewer.get();
|
||||
|
||||
String prefixJson = dataInput.readUTF();
|
||||
String suffixJson = dataInput.readUTF();
|
||||
|
||||
TeamColor teamColor = TeamColor.valueOf(dataInput.readUTF());
|
||||
TeamTagVisibility visibility = TeamTagVisibility.valueOf(dataInput.readUTF());
|
||||
|
||||
if (teamManager instanceof VelocitabManager) {
|
||||
server.getScheduler().buildTask(this, () -> {
|
||||
if (!owner.isActive() || !viewer.isActive()) {
|
||||
return;
|
||||
}
|
||||
String teamNameRetry = teamManager.getTeamName(owner);
|
||||
if (teamNameRetry != null)
|
||||
teamManager.sendTeamUpdatePacket(viewer, teamNameRetry, teamColor, visibility, prefixJson, suffixJson);
|
||||
else
|
||||
logger.warn("Failed to get player " + owner.getUsername() + "'s team name.");
|
||||
}).delay(Duration.ofMillis(500)).schedule();
|
||||
} else {
|
||||
teamManager.sendTeamUpdatePacket(viewer, team, teamColor, visibility, prefixJson, suffixJson);
|
||||
}
|
||||
}
|
||||
|
||||
public static CustomNameplatesVelocity get() {
|
||||
return instance;
|
||||
}
|
||||
|
||||
public static CustomNameplatesVelocity getPlugin() {
|
||||
return instance;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
package net.momirealms.customnameplates.velocity;
|
||||
|
||||
import com.velocitypowered.api.plugin.PluginContainer;
|
||||
import com.velocitypowered.api.proxy.Player;
|
||||
import com.velocitypowered.proxy.connection.client.ConnectedPlayer;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
|
||||
import net.momirealms.customnameplates.common.team.TeamColor;
|
||||
import net.momirealms.customnameplates.common.team.TeamTagVisibility;
|
||||
import net.william278.velocitab.Velocitab;
|
||||
import net.william278.velocitab.api.VelocitabAPI;
|
||||
import net.william278.velocitab.packet.UpdateTeamsPacket;
|
||||
import net.william278.velocitab.player.TabPlayer;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
public class VelocitabManager implements VelocityTeamManager {
|
||||
|
||||
private final Velocitab velocitab;
|
||||
private final VelocitabAPI velocitabAPI;
|
||||
|
||||
public VelocitabManager(PluginContainer pluginContainer) {
|
||||
velocitab = (Velocitab) pluginContainer.getInstance().get();
|
||||
velocitabAPI = VelocitabAPI.getInstance();
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public String getTeamName(Player player) {
|
||||
Optional<TabPlayer> playerOptional = velocitabAPI.getUser(player);
|
||||
return playerOptional.map(TabPlayer::getTeamName).orElse(null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendTeamUpdatePacket(Player receiver, String team, TeamColor color, TeamTagVisibility visibility, String prefix, String suffix) {
|
||||
UpdateTeamsPacket packet = new UpdateTeamsPacket(velocitab)
|
||||
.teamName(team.length() > 16 ? team.substring(0, 16) : team)
|
||||
.mode(UpdateTeamsPacket.UpdateMode.UPDATE_INFO)
|
||||
.displayName(Component.empty())
|
||||
.friendlyFlags(List.of(UpdateTeamsPacket.FriendlyFlag.CAN_HURT_FRIENDLY))
|
||||
.nametagVisibility(UpdateTeamsPacket.NametagVisibility.valueOf(visibility.name()))
|
||||
.collisionRule(UpdateTeamsPacket.CollisionRule.ALWAYS)
|
||||
.color(UpdateTeamsPacket.TeamColor.valueOf(color.name()).ordinal())
|
||||
.prefix(GsonComponentSerializer.gson().deserialize(prefix))
|
||||
.suffix(GsonComponentSerializer.gson().deserialize(suffix));
|
||||
|
||||
ConnectedPlayer connectedPlayer = (ConnectedPlayer) receiver;
|
||||
connectedPlayer.getConnection().write(packet);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
package net.momirealms.customnameplates.velocity;
|
||||
|
||||
import com.velocitypowered.api.proxy.Player;
|
||||
import net.momirealms.customnameplates.common.team.TeamColor;
|
||||
import net.momirealms.customnameplates.common.team.TeamTagVisibility;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public interface VelocityTeamManager {
|
||||
|
||||
@Nullable
|
||||
String getTeamName(Player player);
|
||||
|
||||
void sendTeamUpdatePacket(Player receiver, String team, TeamColor color, TeamTagVisibility visibility, String prefix, String suffix);
|
||||
}
|
||||
@@ -1,9 +0,0 @@
|
||||
name: CustomNameplates
|
||||
version: '${version}'
|
||||
main: net.momirealms.customnameplates.paper.Main
|
||||
api-version: 1.17
|
||||
authors: [ XiaoMoMi ]
|
||||
folia-supported: true
|
||||
depend:
|
||||
- ProtocolLib
|
||||
- PlaceholderAPI
|
||||
Reference in New Issue
Block a user