9
0
mirror of https://github.com/Xiao-MoMi/Custom-Nameplates.git synced 2025-12-19 15:09:23 +00:00

some changes

This commit is contained in:
XiaoMoMi
2024-06-24 00:14:44 +08:00
parent eb730c8631
commit b36d0c23e1
20 changed files with 245 additions and 618 deletions

View File

@@ -28,13 +28,6 @@ public interface VersionManager {
*/
boolean isFolia();
/**
* Get bukkit version
*
* @return version
*/
String getServerVersion();
/**
* Check update
*
@@ -66,6 +59,8 @@ public interface VersionManager {
boolean isVersionNewerThan1_19();
boolean isMojmap();
boolean isVersionNewerThan1_19_R2();
boolean isVersionNewerThan1_19_R3();

View File

@@ -2,17 +2,17 @@ plugins {
id("java")
id("application")
id("maven-publish")
id("com.github.johnrengelman.shadow") version "8.1.1"
id("io.github.goooler.shadow") version "8.1.7"
}
allprojects {
version = "2.3.3.9"
version = "2.4.0"
apply<JavaPlugin>()
apply(plugin = "java")
apply(plugin = "application")
apply(plugin = "com.github.johnrengelman.shadow")
apply(plugin = "io.github.goooler.shadow")
apply(plugin = "org.gradle.maven-publish")
application {
@@ -20,8 +20,8 @@ allprojects {
}
repositories {
maven("https://maven.aliyun.com/repository/public/")
mavenCentral()
maven("https://maven.aliyun.com/repository/public/")
maven("https://papermc.io/repo/repository/maven-public/")
maven("https://oss.sonatype.org/content/groups/public/")
maven("https://repo.dmulloy2.net/repository/public/")

View File

@@ -38,7 +38,6 @@ dependencies {
compileOnly("commons-io:commons-io:2.15.1")
compileOnly("org.geysermc.geyser:api:2.2.0-SNAPSHOT")
compileOnly("LibsDisguises:LibsDisguises:10.0.42")
implementation("com.github.Xiao-MoMi:BiomeAPI:0.3")
// chat channels
compileOnly(files("libs/VentureChat-3.7.1.jar"))
@@ -49,17 +48,18 @@ dependencies {
// api module
implementation(project(":api"))
implementation(project(":common"))
implementation(files("libs/Sparrow-Heart-0.17.jar"))
// adventure
compileOnly("net.kyori:adventure-api:4.16.0")
compileOnly("net.kyori:adventure-platform-bukkit:4.3.2")
compileOnly("net.kyori:adventure-api:4.17.0")
compileOnly("net.kyori:adventure-platform-bukkit:4.3.3")
}
tasks {
shadowJar {
relocate ("net.kyori", "net.momirealms.customnameplates.libraries")
relocate ("org.bstats", "net.momirealms.customnameplates.libraries.bstats")
relocate ("net.momirealms.biomeapi", "net.momirealms.customnameplates.libraries.biomeapi")
relocate ("net.momirealms.sparrow.heart", "net.momirealms.customnameplates.libraries.sparrow")
relocate ("org.apache.commons.pool2", "net.momirealms.customnameplates.libraries.commonspool2")
relocate ("com.mysql", "net.momirealms.customnameplates.libraries.mysql")
relocate ("org.mariadb", "net.momirealms.customnameplates.libraries.mariadb")

Binary file not shown.

View File

@@ -64,13 +64,14 @@ public class CustomNameplatesPluginImpl extends CustomNameplatesPlugin implement
@Override
public void onLoad() {
this.versionManager = new VersionManagerImpl(this);
this.dependencyManager = new DependencyManagerImpl(this, new ReflectionClassPathAppender(this.getClassLoader()));
this.dependencyManager.loadDependencies(new ArrayList<>(
List.of(
Dependency.GSON,
Dependency.SLF4J_API,
Dependency.SLF4J_SIMPLE,
Dependency.COMMAND_API,
versionManager.isMojmap() ? Dependency.COMMAND_API_MOJMAP : Dependency.COMMAND_API,
Dependency.BOOSTED_YAML,
Dependency.BIOME_API,
Dependency.ADVENTURE_BUNDLE,
@@ -99,7 +100,6 @@ public class CustomNameplatesPluginImpl extends CustomNameplatesPlugin implement
return;
}
this.adventureManager = new AdventureManagerImpl(this);
this.versionManager = new VersionManagerImpl(this);
this.scheduler = new SchedulerImpl(this);
this.storageManager = new StorageManagerImpl(this);
this.requirementManager = new RequirementManagerImpl(this);

View File

@@ -286,6 +286,10 @@ public class AdventureManagerImpl implements AdventureManager {
}
}
public Audience audience(Player player) {
return adventure.player(player);
}
public class CacheSystem {
private final LoadingCache<String, Object> miniMessageToIChatComponentCache;

View File

@@ -63,11 +63,19 @@ public enum Dependency {
COMMAND_API(
"dev{}jorel",
"commandapi-bukkit-shade",
"9.4.0",
"9.5.1",
null,
"commandapi-bukkit",
Relocation.of("commandapi", "dev{}jorel{}commandapi")
),
COMMAND_API_MOJMAP(
"dev{}jorel",
"commandapi-bukkit-shade-mojang-mapped",
"9.5.1",
null,
"commandapi-bukkit-mojang-mapped",
Relocation.of("commandapi", "dev{}jorel{}commandapi")
),
MARIADB_DRIVER(
"org{}mariadb{}jdbc",
"mariadb-java-client",

View File

@@ -22,6 +22,7 @@ import net.momirealms.customnameplates.api.manager.VersionManager;
import net.momirealms.customnameplates.api.util.LogUtils;
import net.momirealms.customnameplates.paper.CustomNameplatesPluginImpl;
import net.momirealms.customnameplates.paper.adventure.AdventureManagerImpl;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
@@ -40,14 +41,11 @@ import java.util.concurrent.CompletableFuture;
*/
public class VersionManagerImpl implements VersionManager, Listener {
private final boolean isNewerThan1_19;
private final boolean isNewerThan1_19_R2;
private final boolean isNewerThan1_19_R3;
private final boolean isNewerThan1_20;
private final boolean isNewerThan1_20_R2;
private final String serverVersion;
private final float mcVersion;
private final CustomNameplatesPluginImpl plugin;
private boolean isFolia;
private boolean isMojmap;
private final String pluginVersion;
private boolean isLatest = true;
@@ -55,47 +53,47 @@ public class VersionManagerImpl implements VersionManager, Listener {
public VersionManagerImpl(CustomNameplatesPluginImpl plugin) {
this.plugin = plugin;
// Get the server version
serverVersion = plugin.getServer().getClass().getPackage().getName().split("\\.")[3];
String[] split = serverVersion.split("_");
int main_ver = Integer.parseInt(split[1]);
// Determine if the server version is newer than 1_19_R2 and 1_20_R1
if (main_ver >= 20) {
isNewerThan1_20_R2 = Integer.parseInt(split[2].substring(1)) >= 2;
isNewerThan1_19_R2 = isNewerThan1_19_R3 = true;
isNewerThan1_20 = true;
isNewerThan1_19 = true;
} else if (main_ver == 19) {
isNewerThan1_19_R2 = Integer.parseInt(split[2].substring(1)) >= 2;
isNewerThan1_19_R3 = Integer.parseInt(split[2].substring(1)) >= 3;
isNewerThan1_20 = isNewerThan1_20_R2 = false;
isNewerThan1_19 = true;
} else {
isNewerThan1_19 = isNewerThan1_19_R2= isNewerThan1_19_R3 = false;
isNewerThan1_20 = isNewerThan1_20_R2 = false;
}
// Check if the server is Folia
try {
Class.forName("io.papermc.paper.threadedregions.scheduler.AsyncScheduler");
this.isFolia = true;
} catch (ClassNotFoundException ignored) {
}
String[] split = Bukkit.getServer().getBukkitVersion().split("-")[0].split("\\.");
this.mcVersion = Float.parseFloat(split[1] + "." + split[2]);
// Get the plugin version
this.pluginVersion = plugin.getDescription().getVersion();
// Check if the server is Folia
try {
Class.forName("io.papermc.paper.threadedregions.RegionizedServer");
this.isFolia = true;
} catch (ClassNotFoundException ignored) {
this.isFolia = false;
}
// Check if the server is Mojmap
try {
Class.forName("net.minecraft.network.protocol.game.ClientboundBossEventPacket");
this.isMojmap = true;
} catch (ClassNotFoundException ignored) {
}
}
@Override
public boolean isMojmap() {
return isMojmap;
}
@Override
public boolean isVersionNewerThan1_19_R2() {
return isNewerThan1_19_R2;
return mcVersion >= 19.3;
}
@Override
public boolean isVersionNewerThan1_20() {
return isNewerThan1_20;
return mcVersion >= 20;
}
@Override
public boolean isVersionNewerThan1_20_R2() {
return isNewerThan1_20_R2;
return mcVersion >= 20.2;
}
@NotNull
@@ -111,36 +109,42 @@ public class VersionManagerImpl implements VersionManager, Listener {
@Override
public boolean isVersionNewerThan1_19() {
return isNewerThan1_19;
return mcVersion >= 19;
}
@Override
public boolean isVersionNewerThan1_19_R3() {
return isNewerThan1_19_R3;
return mcVersion >= 19.4;
}
@Override
public int getPackFormat() {
switch (serverVersion) {
case "v1_20_R3" -> {
switch (Bukkit.getServer().getBukkitVersion().split("-")[0]) {
case "1.21" -> {
return 34;
}
case "1.20.5", "1.20.6" -> {
return 32;
}
case "1.20.3", "1.20.4" -> {
return 22;
}
case "v1_20_R2" -> {
case "1.20.2" -> {
return 18;
}
case "v1_20_R1" -> {
case "1.20", "1.20.1" -> {
return 15;
}
case "v1_19_R3" -> {
case "1.19.4" -> {
return 13;
}
case "v1_19_R2" -> {
case "1.19.3" -> {
return 12;
}
case "v1_19_R1" -> {
case "1.19", "1.19.1", "1.19.2" -> {
return 9;
}
case "v1_18_R1", "v1_18_R2" -> {
case "1.18", "1.18.1", "1.18.2" -> {
return 8;
}
default -> {
@@ -154,11 +158,6 @@ public class VersionManagerImpl implements VersionManager, Listener {
return isFolia;
}
@Override
public String getServerVersion() {
return serverVersion;
}
// Method to asynchronously check for plugin updates
public CompletableFuture<Boolean> checkUpdate() {
CompletableFuture<Boolean> updateFuture = new CompletableFuture<>();

View File

@@ -18,7 +18,6 @@
package net.momirealms.customnameplates.paper.mechanic.requirement;
import me.clip.placeholderapi.PlaceholderAPI;
import net.momirealms.biomeapi.BiomeAPI;
import net.momirealms.customnameplates.api.manager.RequirementManager;
import net.momirealms.customnameplates.api.requirement.Requirement;
import net.momirealms.customnameplates.api.requirement.RequirementExpansion;
@@ -32,6 +31,7 @@ import net.momirealms.customnameplates.paper.util.ClassUtils;
import net.momirealms.customnameplates.paper.util.ConfigUtils;
import net.momirealms.customnameplates.paper.util.DisguiseUtils;
import net.momirealms.customnameplates.paper.util.GeyserUtils;
import net.momirealms.sparrow.heart.SparrowHeart;
import org.bukkit.World;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.entity.Player;
@@ -327,14 +327,14 @@ public class RequirementManagerImpl implements RequirementManager {
registerRequirement("biome", (args) -> {
HashSet<String> biomes = new HashSet<>(ConfigUtils.stringListArgs(args));
return condition -> {
String currentBiome = BiomeAPI.getBiomeAt(Objects.requireNonNull(condition.getOfflinePlayer().getPlayer()).getLocation());
String currentBiome = SparrowHeart.getInstance().getBiomeResourceLocation(Objects.requireNonNull(condition.getOfflinePlayer().getPlayer()).getLocation());
return biomes.contains(currentBiome);
};
});
registerRequirement("!biome", (args) -> {
HashSet<String> biomes = new HashSet<>(ConfigUtils.stringListArgs(args));
return condition -> {
String currentBiome = BiomeAPI.getBiomeAt(Objects.requireNonNull(condition.getOfflinePlayer().getPlayer()).getLocation());
String currentBiome = SparrowHeart.getInstance().getBiomeResourceLocation(Objects.requireNonNull(condition.getOfflinePlayer().getPlayer()).getLocation());
return !biomes.contains(currentBiome);
};
});

View File

@@ -27,13 +27,15 @@ import net.momirealms.customnameplates.api.CustomNameplatesPlugin;
import net.momirealms.customnameplates.api.manager.TeamManager;
import net.momirealms.customnameplates.api.util.LogUtils;
import net.momirealms.customnameplates.common.message.MessageType;
import net.momirealms.customnameplates.common.team.TeamCollisionRule;
import net.momirealms.customnameplates.common.team.TeamColor;
import net.momirealms.customnameplates.common.team.TeamTagVisibility;
import net.momirealms.customnameplates.paper.adventure.AdventureManagerImpl;
import net.momirealms.customnameplates.paper.mechanic.misc.PacketManager;
import net.momirealms.customnameplates.paper.mechanic.team.packet.*;
import net.momirealms.customnameplates.paper.mechanic.team.provider.*;
import net.momirealms.customnameplates.paper.setting.CNConfig;
import net.momirealms.sparrow.heart.SparrowHeart;
import net.momirealms.sparrow.heart.feature.team.TeamCollisionRule;
import net.momirealms.sparrow.heart.feature.team.TeamColor;
import net.momirealms.sparrow.heart.feature.team.TeamVisibility;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.event.HandlerList;
@@ -50,13 +52,11 @@ import java.util.Optional;
public class TeamManagerImpl implements TeamManager, PluginMessageListener {
private final CustomNameplatesPlugin plugin;
private final TeamPacketAdaptor teamPacketAdaptor;
private TeamProvider teamProvider;
private static final String CHANNEL = "customnameplates:cnp";
public TeamManagerImpl(CustomNameplatesPlugin plugin) {
this.plugin = plugin;
this.teamPacketAdaptor = new TeamPacket_1_17();
}
/**
@@ -78,35 +78,33 @@ public class TeamManagerImpl implements TeamManager, PluginMessageListener {
}
playerTeam.addPlayer(player);
} else {
PacketContainer createOwner = teamPacketAdaptor.getTeamCreatePacket(
TeamCreate.builder()
.teamName(team)
.color(TeamColor.WHITE)
.display("")
.prefix("")
.suffix("")
.members(Collections.singletonList(player.getName()))
.collisionRule(TeamCollisionRule.ALWAYS)
.tagVisibility(TeamTagVisibility.ALWAYS)
.build()
);
for (Player online : Bukkit.getOnlinePlayers()) {
PacketManager.getInstance().send(online, createOwner);
SparrowHeart.getInstance().addClientSideTeam(online, team,
Collections.singletonList(player.getName()),
"{\"text\":\"\"}",
"{\"text\":\"\"}",
"{\"text\":\"\"}",
TeamVisibility.ALWAYS,
TeamVisibility.ALWAYS,
TeamCollisionRule.ALWAYS,
TeamColor.WHITE,
true,
true
);
if (online == player) continue;
String onlineTeam = teamProvider.getTeam(online, null);
PacketContainer createOther = teamPacketAdaptor.getTeamCreatePacket(
TeamCreate.builder()
.teamName(onlineTeam)
.color(TeamColor.WHITE)
.display("")
.prefix("")
.suffix("")
.members(Collections.singletonList(online.getName()))
.collisionRule(TeamCollisionRule.ALWAYS)
.tagVisibility(TeamTagVisibility.ALWAYS)
.build()
SparrowHeart.getInstance().addClientSideTeam(player, team,
Collections.singletonList(onlineTeam),
"{\"text\":\"\"}",
"{\"text\":\"\"}",
"{\"text\":\"\"}",
TeamVisibility.ALWAYS,
TeamVisibility.ALWAYS,
TeamCollisionRule.ALWAYS,
TeamColor.WHITE,
true,
true
);
PacketManager.getInstance().send(player, createOther);
}
}
}
@@ -127,28 +125,23 @@ public class TeamManagerImpl implements TeamManager, PluginMessageListener {
Scoreboard scoreboard = Bukkit.getScoreboardManager().getMainScoreboard();
Optional.ofNullable(scoreboard.getTeam(team)).ifPresent(Team::unregister);
} else {
PacketContainer packet = teamPacketAdaptor.getTeamRemovePacket(
TeamRemove.builder()
.teamName(team)
.build()
);
for (Player online : Bukkit.getOnlinePlayers()) {
if (player == online) continue;
PacketManager.getInstance().send(online, packet);
SparrowHeart.getInstance().removeClientSideTeam(online, team);
}
}
}
@Override
public void updateTeam(Player owner, Player viewer, String prefix, String suffix, TeamColor color, TeamTagVisibility visibility) {
public void updateTeam(Player owner, Player viewer, String prefix, String suffix, net.momirealms.customnameplates.common.team.TeamColor color, TeamTagVisibility visibility) {
if (CNConfig.disableTeamManage) return;
String team = teamProvider.getTeam(owner, viewer);
if (team == null) {
LogUtils.warn("Failed to get player " + owner.getName() + "'s team for viewer " + viewer.getName());
return;
}
if (color == TeamColor.NONE || color == TeamColor.CUSTOM)
color = TeamColor.WHITE;
if (color == net.momirealms.customnameplates.common.team.TeamColor.NONE || color == net.momirealms.customnameplates.common.team.TeamColor.CUSTOM)
color = net.momirealms.customnameplates.common.team.TeamColor.WHITE;
if (plugin.getNameplateManager().isProxyMode()) {
this.sendPluginMessage(
MessageType.UPDATE,
@@ -160,18 +153,18 @@ public class TeamManagerImpl implements TeamManager, PluginMessageListener {
visibility.name()
);
} else {
PacketContainer packet = teamPacketAdaptor.getTeamUpdatePacket(
TeamUpdate.builder()
.teamName(team)
.color(color)
.display("")
.prefix(prefix)
.suffix(suffix)
.tagVisibility(visibility)
.collisionRule(TeamCollisionRule.ALWAYS)
.build()
SparrowHeart.getInstance().updateClientSideTeam(
viewer, team,
"{\"text\":\"\"}",
AdventureManagerImpl.getInstance().componentToJson(AdventureManagerImpl.getInstance().getComponentFromMiniMessage(prefix)),
AdventureManagerImpl.getInstance().componentToJson(AdventureManagerImpl.getInstance().getComponentFromMiniMessage(suffix)),
TeamVisibility.ALWAYS,
TeamVisibility.ALWAYS,
TeamCollisionRule.ALWAYS,
TeamColor.valueOf(color.name()),
true,
true
);
PacketManager.getInstance().send(viewer, packet);
}
}

View File

@@ -1,166 +0,0 @@
/*
* Copyright (C) <2022> <XiaoMoMi>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package net.momirealms.customnameplates.paper.mechanic.team.packet;
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 net.momirealms.customnameplates.paper.adventure.AdventureManagerImpl;
import java.util.Collection;
public class TeamCreate {
// String i
private String teamName;
// Collection<String> j
private Collection<String> members;
/*
Optional<b> k
*/
// IChatBaseComponent a
private Object teamDisplay;
// IChatBaseComponent b
private Object teamPrefix;
// IChatBaseComponent c
private Object teamSuffix;
// String d
private TeamTagVisibility tagVisibility;
// String e
private TeamCollisionRule collisionRule;
// Enum f
private TeamColor teamColor;
private TeamCreate() {
}
public TeamCreate(
String teamName,
Collection<String> members,
Component teamDisplay,
Component teamPrefix,
Component teamSuffix,
TeamTagVisibility tagVisibility,
TeamCollisionRule collisionRule,
TeamColor teamColor
) {
this.teamName = teamName;
this.members = members;
this.teamDisplay = teamDisplay;
this.teamPrefix = teamPrefix;
this.teamSuffix = teamSuffix;
this.tagVisibility = tagVisibility;
this.collisionRule = collisionRule;
this.teamColor = teamColor;
}
public String getTeamName() {
return teamName;
}
public Collection<String> getMembers() {
return members;
}
public Object getTeamDisplay() {
return teamDisplay;
}
public Object getTeamPrefix() {
return teamPrefix;
}
public Object getTeamSuffix() {
return teamSuffix;
}
public TeamTagVisibility getTagVisibility() {
return tagVisibility;
}
public TeamCollisionRule getCollisionRule() {
return collisionRule;
}
public TeamColor getTeamColor() {
return teamColor;
}
public static Builder builder() {
return new Builder();
}
public static class Builder {
private final TeamCreate packet;
public Builder() {
this.packet = new TeamCreate();
}
public static Builder of() {
return new Builder();
}
public Builder teamName(String name) {
packet.teamName = name;
return this;
}
public Builder members(Collection<String> members) {
packet.members = members;
return this;
}
public Builder display(String display) {
packet.teamDisplay = AdventureManagerImpl.getInstance().getIChatComponentFromMiniMessage(display);
return this;
}
public Builder prefix(String prefix) {
packet.teamPrefix = AdventureManagerImpl.getInstance().getIChatComponentFromMiniMessage(prefix);
return this;
}
public Builder suffix(String suffix) {
packet.teamSuffix = AdventureManagerImpl.getInstance().getIChatComponentFromMiniMessage(suffix);
return this;
}
public Builder color(TeamColor color) {
packet.teamColor = color;
return this;
}
public Builder tagVisibility(TeamTagVisibility visibility) {
packet.tagVisibility = visibility;
return this;
}
public Builder collisionRule(TeamCollisionRule rule) {
packet.collisionRule = rule;
return this;
}
public TeamCreate build() {
return packet;
}
}
}

View File

@@ -1,29 +0,0 @@
/*
* Copyright (C) <2022> <XiaoMoMi>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package net.momirealms.customnameplates.paper.mechanic.team.packet;
import com.comphenix.protocol.events.PacketContainer;
public interface TeamPacketAdaptor {
PacketContainer getTeamCreatePacket(TeamCreate teamCreate);
PacketContainer getTeamUpdatePacket(TeamUpdate teamUpdate);
PacketContainer getTeamRemovePacket(TeamRemove teamRemove);
}

View File

@@ -1,81 +0,0 @@
/*
* Copyright (C) <2022> <XiaoMoMi>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package net.momirealms.customnameplates.paper.mechanic.team.packet;
import com.comphenix.protocol.PacketType;
import com.comphenix.protocol.events.InternalStructure;
import com.comphenix.protocol.events.PacketContainer;
import com.comphenix.protocol.utility.MinecraftReflection;
import net.momirealms.customnameplates.common.team.TeamColor;
import java.util.Optional;
@SuppressWarnings("DuplicatedCode")
public class TeamPacket_1_17 implements TeamPacketAdaptor {
@Override
public PacketContainer getTeamCreatePacket(TeamCreate teamCreate) {
PacketContainer packet = new PacketContainer(PacketType.Play.Server.SCOREBOARD_TEAM);
// 0 = create team
packet.getModifier().write(0,0);
packet.getModifier().write(1, teamCreate.getTeamName());
packet.getModifier().write(2, teamCreate.getMembers());
Optional<InternalStructure> optionalInternalStructure = packet.getOptionalStructures().read(0);
if (optionalInternalStructure.isPresent()) {
InternalStructure is = optionalInternalStructure.get();
// Team
is.getModifier().write(0, teamCreate.getTeamDisplay());
is.getModifier().write(1, teamCreate.getTeamPrefix());
is.getModifier().write(2, teamCreate.getTeamSuffix());
is.getModifier().write(3, teamCreate.getTagVisibility().getId());
is.getModifier().write(4, teamCreate.getCollisionRule().getId());
is.getEnumModifier(TeamColor.class, MinecraftReflection.getMinecraftClass("EnumChatFormat")).write(0, teamCreate.getTeamColor());
is.getModifier().write(6, teamCreate.getMembers().size());
}
return packet;
}
@Override
public PacketContainer getTeamRemovePacket(TeamRemove teamRemove) {
PacketContainer packet = new PacketContainer(PacketType.Play.Server.SCOREBOARD_TEAM);
// 1 = remove team
packet.getModifier().write(0,1);
packet.getStrings().write(0, teamRemove.getTeamName());
return packet;
}
@Override
public PacketContainer getTeamUpdatePacket(TeamUpdate teamUpdate) {
PacketContainer packet = new PacketContainer(PacketType.Play.Server.SCOREBOARD_TEAM);
// 2 = update team
packet.getModifier().write(0,2);
packet.getModifier().write(1, teamUpdate.getTeamName());
Optional<InternalStructure> optionalInternalStructure = packet.getOptionalStructures().read(0);
if (optionalInternalStructure.isPresent()) {
InternalStructure is = optionalInternalStructure.get();
// Team
is.getModifier().write(0, teamUpdate.getTeamDisplay());
is.getModifier().write(1, teamUpdate.getTeamPrefix());
is.getModifier().write(2, teamUpdate.getTeamSuffix());
is.getModifier().write(3, teamUpdate.getTagVisibility().getId());
is.getModifier().write(4, teamUpdate.getCollisionRule().getId());
is.getEnumModifier(TeamColor.class, MinecraftReflection.getMinecraftClass("EnumChatFormat")).write(0, teamUpdate.getTeamColor());
}
return packet;
}
}

View File

@@ -1,56 +0,0 @@
/*
* Copyright (C) <2022> <XiaoMoMi>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package net.momirealms.customnameplates.paper.mechanic.team.packet;
public class TeamRemove {
private String teamName;
private TeamRemove() {
}
public TeamRemove(String teamName) {
this.teamName = teamName;
}
public String getTeamName() {
return teamName;
}
public static Builder builder() {
return new Builder();
}
public static class Builder {
private final TeamRemove packet;
public Builder() {
this.packet = new TeamRemove();
}
public Builder teamName(String teamName) {
packet.teamName = teamName;
return this;
}
public TeamRemove build() {
return packet;
}
}
}

View File

@@ -1,149 +0,0 @@
/*
* Copyright (C) <2022> <XiaoMoMi>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package net.momirealms.customnameplates.paper.mechanic.team.packet;
import net.momirealms.customnameplates.common.team.TeamCollisionRule;
import net.momirealms.customnameplates.common.team.TeamColor;
import net.momirealms.customnameplates.common.team.TeamTagVisibility;
import net.momirealms.customnameplates.paper.adventure.AdventureManagerImpl;
public class TeamUpdate {
private String teamName;
/*
Optional<b> k
*/
// IChatBaseComponent a
private Object teamDisplay;
// IChatBaseComponent b
private Object teamPrefix;
// IChatBaseComponent c
private Object teamSuffix;
// String d
private TeamTagVisibility tagVisibility;
// String e
private TeamCollisionRule collisionRule;
// Enum f
private TeamColor teamColor;
private TeamUpdate() {
}
public TeamUpdate(
String teamName,
Object teamDisplay,
Object teamPrefix,
Object teamSuffix,
TeamTagVisibility tagVisibility,
TeamCollisionRule collisionRule,
TeamColor teamColor
) {
this.teamName = teamName;
this.teamDisplay = teamDisplay;
this.teamPrefix = teamPrefix;
this.teamSuffix = teamSuffix;
this.tagVisibility = tagVisibility;
this.collisionRule = collisionRule;
this.teamColor = teamColor;
}
public String getTeamName() {
return teamName;
}
public Object getTeamDisplay() {
return teamDisplay;
}
public Object getTeamPrefix() {
return teamPrefix;
}
public Object getTeamSuffix() {
return teamSuffix;
}
public TeamTagVisibility getTagVisibility() {
return tagVisibility;
}
public TeamCollisionRule getCollisionRule() {
return collisionRule;
}
public TeamColor getTeamColor() {
return teamColor;
}
public static Builder builder() {
return new Builder();
}
public static class Builder {
private final TeamUpdate packet;
public Builder() {
this.packet = new TeamUpdate();
}
public static Builder of() {
return new Builder();
}
public Builder teamName(String name) {
packet.teamName = name;
return this;
}
public Builder display(String display) {
packet.teamDisplay = AdventureManagerImpl.getInstance().getIChatComponentFromMiniMessage(display);
return this;
}
public Builder prefix(String prefix) {
packet.teamPrefix = AdventureManagerImpl.getInstance().getIChatComponentFromMiniMessage(prefix);
return this;
}
public Builder suffix(String suffix) {
packet.teamSuffix = AdventureManagerImpl.getInstance().getIChatComponentFromMiniMessage(suffix);;
return this;
}
public Builder color(TeamColor color) {
packet.teamColor = color;
return this;
}
public Builder tagVisibility(TeamTagVisibility visibility) {
packet.tagVisibility = visibility;
return this;
}
public Builder collisionRule(TeamCollisionRule rule) {
packet.collisionRule = rule;
return this;
}
public TeamUpdate build() {
return packet;
}
}
}

View File

@@ -18,6 +18,7 @@
package net.momirealms.customnameplates.paper.util;
import com.comphenix.protocol.utility.MinecraftReflection;
import net.momirealms.customnameplates.api.CustomNameplatesPlugin;
import net.momirealms.customnameplates.api.util.LogUtils;
import java.lang.reflect.Constructor;
@@ -42,23 +43,43 @@ public class ReflectionUtils {
private static boolean isPaper;
public static void load() {
try {
Class<?> bar = Class.forName("net.minecraft.network.protocol.game.PacketPlayOutBoss");
Field remove = bar.getDeclaredField("f");
remove.setAccessible(true);
removeBossBarPacket = remove.get(null);
Class<?> packetBossClassF = Class.forName("net.minecraft.network.protocol.game.PacketPlayOutBoss$f");
progressConstructor = packetBossClassF.getDeclaredConstructor(float.class);
progressConstructor.setAccessible(true);
Class<?> packetBossClassE = Class.forName("net.minecraft.network.protocol.game.PacketPlayOutBoss$e");
updateConstructor = packetBossClassE.getDeclaredConstructor(MinecraftReflection.getIChatBaseComponentClass());
updateConstructor.setAccessible(true);
iChatComponentMethod = MinecraftReflection.getChatSerializerClass().getMethod("a", String.class);
iChatComponentMethod.setAccessible(true);
emptyComponent = iChatComponentMethod.invoke(null, "{\"text\":\"\"}");
} catch (ClassNotFoundException | NoSuchFieldException | IllegalAccessException | NoSuchMethodException | InvocationTargetException exception) {
LogUtils.severe("Error occurred when loading reflections", exception);
exception.printStackTrace();
if (CustomNameplatesPlugin.get().getVersionManager().isMojmap()) {
try {
Class<?> bar = Class.forName("net.minecraft.network.protocol.game.ClientboundBossEventPacket");
Field remove = bar.getDeclaredField("REMOVE_OPERATION");
remove.setAccessible(true);
removeBossBarPacket = remove.get(null);
Class<?> packetBossClassF = Class.forName("net.minecraft.network.protocol.game.ClientboundBossEventPacket$UpdateProgressOperation");
progressConstructor = packetBossClassF.getDeclaredConstructor(float.class);
progressConstructor.setAccessible(true);
Class<?> packetBossClassE = Class.forName("net.minecraft.network.protocol.game.ClientboundBossEventPacket$UpdateNameOperation");
updateConstructor = packetBossClassE.getDeclaredConstructor(MinecraftReflection.getIChatBaseComponentClass());
updateConstructor.setAccessible(true);
Class<?> craftChatMessageClass = Class.forName("org.bukkit.craftbukkit.util.CraftChatMessage");
iChatComponentMethod = craftChatMessageClass.getDeclaredMethod("fromJSON", String.class);
iChatComponentMethod.setAccessible(true);
emptyComponent = iChatComponentMethod.invoke(null, "{\"text\":\"\"}");
} catch (ClassNotFoundException | NoSuchFieldException | IllegalAccessException | NoSuchMethodException | InvocationTargetException exception) {
LogUtils.severe("Error occurred while loading reflections", exception);
}
} else {
try {
Class<?> bar = Class.forName("net.minecraft.network.protocol.game.PacketPlayOutBoss");
Field remove = bar.getDeclaredField("f");
remove.setAccessible(true);
removeBossBarPacket = remove.get(null);
Class<?> packetBossClassF = Class.forName("net.minecraft.network.protocol.game.PacketPlayOutBoss$f");
progressConstructor = packetBossClassF.getDeclaredConstructor(float.class);
progressConstructor.setAccessible(true);
Class<?> packetBossClassE = Class.forName("net.minecraft.network.protocol.game.PacketPlayOutBoss$e");
updateConstructor = packetBossClassE.getDeclaredConstructor(MinecraftReflection.getIChatBaseComponentClass());
updateConstructor.setAccessible(true);
iChatComponentMethod = MinecraftReflection.getChatSerializerClass().getMethod("a", String.class);
iChatComponentMethod.setAccessible(true);
emptyComponent = iChatComponentMethod.invoke(null, "{\"text\":\"\"}");
} catch (ClassNotFoundException | NoSuchFieldException | IllegalAccessException | NoSuchMethodException | InvocationTargetException exception) {
LogUtils.severe("Error occurred while loading reflections", exception);
}
}
try {
Class<?> componentClass = Class.forName("net;kyori;adventure;text;Component".replace(";", "."));

View File

@@ -0,0 +1,31 @@
#version 150
#moj_import<fog.glsl>
uniform sampler2D Sampler0;
uniform vec4 ColorModulator;
uniform float FogStart,FogEnd;
uniform vec4 FogColor;
uniform float GameTime;
in float vertexDistance;
in vec4 vertexColor;
in vec2 texCoord0;
in float depthLevel;
%SHADER_0%
out vec4 fragColor;
void main() {
vec4 texColor = texture(Sampler0, texCoord0);
vec4 color = texColor * vertexColor * ColorModulator;%SHADER_1%
if (color.a < 0.1) {
discard;
}
if (texColor.a == 254.0/255.0) {
if (depthLevel == 0.00) {
discard;
} else {
color = vec4(texColor.rgb, 1.0) * vertexColor * ColorModulator;
}
}
fragColor = linear_fog(color, vertexDistance, FogStart, FogEnd, FogColor);
}

View File

@@ -0,0 +1,29 @@
{
"blend": {
"func": "add",
"srcrgb": "srcalpha",
"dstrgb": "1-srcalpha"
},
"vertex": "rendertype_text",
"fragment": "rendertype_text",
"attributes": [
"Position",
"Color",
"UV0",
"UV2"
],
"samplers": [
{ "name": "Sampler0" },
{ "name": "Sampler2" }
],
"uniforms": [
{ "name": "ModelViewMat", "type": "matrix4x4", "count": 16, "values": [ 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0 ] },
{ "name": "ProjMat", "type": "matrix4x4", "count": 16, "values": [ 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0 ] },
{ "name": "IViewRotMat", "type": "matrix3x3", "count": 9, "values": [ 1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0 ] },
{ "name": "ColorModulator", "type": "float", "count": 4, "values": [ 1.0, 1.0, 1.0, 1.0 ] },
{ "name": "FogStart", "type": "float", "count": 1, "values": [ 0.0 ] },
{ "name": "FogEnd", "type": "float", "count": 1, "values": [ 1.0 ] },
{ "name": "GameTime", "type": "float", "count": 1, "values": [ 1.0 ] },
{ "name": "FogColor", "type": "float", "count": 4, "values": [ 0.0, 0.0, 0.0, 0.0 ] }
]
}

View File

@@ -0,0 +1,28 @@
#version 150
#moj_import <fog.glsl>
in vec3 Position;
in vec4 Color;
in vec2 UV0;
in ivec2 UV2;
uniform sampler2D Sampler2;
uniform mat4 ModelViewMat;
uniform mat4 ProjMat;
uniform mat3 IViewRotMat;
uniform float GameTime;
uniform int FogShape;
uniform vec2 ScreenSize;
out float vertexDistance;
out vec4 vertexColor;
out vec2 texCoord0;
out float depthLevel;
%SHADER_0%
void main() {
vec4 vertex = vec4(Position, 1.0);
vertexDistance = fog_distance(ModelViewMat, IViewRotMat * Position, FogShape);
depthLevel = Position.z;
texCoord0 = UV0;
%SHADER_1%%SHADER_2%%SHADER_3%
}

View File

@@ -10,7 +10,7 @@ tasks {
shadowJar {
relocate ("net.kyori", "net.momirealms.customnameplates.libraries")
relocate ("org.bstats", "net.momirealms.customnameplates.libraries.bstats")
relocate ("net.momirealms.biomeapi", "net.momirealms.customnameplates.libraries.biomeapi")
relocate ("net.momirealms.sparrow.heart", "net.momirealms.customnameplates.libraries.sparrow")
relocate ("org.apache.commons.pool2", "net.momirealms.customnameplates.libraries.commonspool2")
relocate ("com.mysql", "net.momirealms.customnameplates.libraries.mysql")
relocate ("org.mariadb", "net.momirealms.customnameplates.libraries.mariadb")