mirror of
https://github.com/Xiao-MoMi/Custom-Nameplates.git
synced 2025-12-30 20:29:07 +00:00
2.1.7.2.2
This commit is contained in:
@@ -25,6 +25,7 @@ import net.kyori.adventure.platform.bukkit.BukkitAudiences;
|
||||
import net.momirealms.customnameplates.commands.BubblesCommand;
|
||||
import net.momirealms.customnameplates.commands.NameplateCommand;
|
||||
import net.momirealms.customnameplates.helper.LibraryLoader;
|
||||
import net.momirealms.customnameplates.helper.VersionHelper;
|
||||
import net.momirealms.customnameplates.manager.*;
|
||||
import net.momirealms.customnameplates.utils.AdventureUtil;
|
||||
import net.momirealms.customnameplates.utils.ConfigUtil;
|
||||
@@ -37,7 +38,6 @@ public final class CustomNameplates extends JavaPlugin {
|
||||
public static CustomNameplates plugin;
|
||||
public static BukkitAudiences adventure;
|
||||
public static ProtocolManager protocolManager;
|
||||
public static String version;
|
||||
|
||||
private ResourceManager resourceManager;
|
||||
private BossBarManager bossBarManager;
|
||||
@@ -49,6 +49,7 @@ public final class CustomNameplates extends JavaPlugin {
|
||||
private ConfigManager configManager;
|
||||
private MessageManager messageManager;
|
||||
private WidthManager widthManager;
|
||||
private VersionHelper versionHelper;
|
||||
|
||||
@Override
|
||||
public void onLoad(){
|
||||
@@ -63,7 +64,6 @@ public final class CustomNameplates extends JavaPlugin {
|
||||
public void onEnable() {
|
||||
adventure = BukkitAudiences.create(this);
|
||||
protocolManager = ProtocolLibrary.getProtocolManager();
|
||||
version = Bukkit.getServer().getClass().getPackage().getName().split("\\.")[3];
|
||||
|
||||
//Don't delete this
|
||||
PacketContainer packet = new PacketContainer(PacketType.Play.Server.SCOREBOARD_TEAM);
|
||||
@@ -80,6 +80,7 @@ public final class CustomNameplates extends JavaPlugin {
|
||||
this.messageManager = new MessageManager();
|
||||
this.widthManager = new WidthManager();
|
||||
this.chatBubblesManager = new ChatBubblesManager();
|
||||
this.versionHelper = new VersionHelper();
|
||||
|
||||
ConfigUtil.reloadConfigs();
|
||||
|
||||
@@ -163,4 +164,8 @@ public final class CustomNameplates extends JavaPlugin {
|
||||
public WidthManager getWidthManager() {
|
||||
return widthManager;
|
||||
}
|
||||
|
||||
public VersionHelper getVersionHelper() {
|
||||
return versionHelper;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
package net.momirealms.customnameplates.helper;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
|
||||
public class VersionHelper {
|
||||
|
||||
private boolean isNewerThan1_19_R2;
|
||||
private String version;
|
||||
|
||||
public boolean isVersionNewerThan1_19_R2() {
|
||||
if (version == null) {
|
||||
version = Bukkit.getServer().getClass().getPackage().getName().split("\\.")[3];
|
||||
String[] split = version.split("_");
|
||||
int main_ver = Integer.parseInt(split[1]);
|
||||
if (main_ver >= 20) isNewerThan1_19_R2 = true;
|
||||
else if (main_ver == 19) isNewerThan1_19_R2 = Integer.parseInt(split[2].substring(1)) >= 2;
|
||||
else isNewerThan1_19_R2 = false;
|
||||
}
|
||||
return isNewerThan1_19_R2;
|
||||
}
|
||||
}
|
||||
@@ -32,21 +32,18 @@ import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.HandlerList;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.TreeMap;
|
||||
import java.util.*;
|
||||
|
||||
public class BossBarManager extends Function {
|
||||
|
||||
private final SimpleListener simpleListener;
|
||||
private final TreeMap<String, BossBarConfig> bossBars;
|
||||
private final LinkedHashMap<String, BossBarConfig> bossBars;
|
||||
private final HashMap<Player, TimerTaskP> taskCache;
|
||||
|
||||
public BossBarManager() {
|
||||
this.simpleListener = new SimpleListener(this);
|
||||
this.taskCache = new HashMap<>();
|
||||
this.bossBars = new TreeMap<>();
|
||||
this.bossBars = new LinkedHashMap<>();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -119,7 +116,7 @@ public class BossBarManager extends Function {
|
||||
AdventureUtil.consoleMessage("[CustomNameplates] Loaded <green>" + bossBars.size() + " <gray>bossbars");
|
||||
}
|
||||
|
||||
public TreeMap<String, BossBarConfig> getBossBars() {
|
||||
public LinkedHashMap<String, BossBarConfig> getBossBars() {
|
||||
return bossBars;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -174,7 +174,7 @@ public class ChatBubblesManager extends EntityTag {
|
||||
return;
|
||||
}
|
||||
|
||||
text = AdventureUtil.replaceLegacy(text);
|
||||
text = AdventureUtil.replaceLegacy(bubblesEvent.getText());
|
||||
|
||||
BubbleConfig bubbleConfig = ResourceManager.BUBBLES.get(bubblesEvent.getBubble());
|
||||
WrappedChatComponent wrappedChatComponent;
|
||||
@@ -199,6 +199,7 @@ public class ChatBubblesManager extends EntityTag {
|
||||
}
|
||||
|
||||
ArmorStandManager asm = getArmorStandManager(player);
|
||||
if (asm == null) return;
|
||||
asm.ascent();
|
||||
String name = UUID.randomUUID().toString();
|
||||
FakeArmorStand fakeArmorStand = new FakeArmorStand(asm, player, wrappedChatComponent);
|
||||
|
||||
@@ -114,7 +114,7 @@ public class BossBarSender {
|
||||
}
|
||||
}
|
||||
}
|
||||
}.runTaskTimerAsynchronously(CustomNameplates.plugin,0,1);
|
||||
}.runTaskTimerAsynchronously(CustomNameplates.plugin, 0,1);
|
||||
}
|
||||
|
||||
private PacketContainer getPacket() {
|
||||
|
||||
@@ -47,24 +47,23 @@ public class TimerTaskP {
|
||||
PlayerCondition playerCondition = new PlayerCondition(player.getLocation(), player);
|
||||
|
||||
outer:
|
||||
for (BossBarSender bossBarSender : bossBarCache) {
|
||||
if (bossBarSender.canConditionCheck()) {
|
||||
for (Requirement requirement : bossBarSender.getConfig().getConditions()) {
|
||||
if (!requirement.isConditionMet(playerCondition)) {
|
||||
if (bossBarSender.getStatus()) {
|
||||
bossBarSender.hide();
|
||||
}
|
||||
continue outer;
|
||||
for (BossBarSender bossBarSender : bossBarCache) {
|
||||
if (bossBarSender.canConditionCheck()) {
|
||||
for (Requirement requirement : bossBarSender.getConfig().getConditions()) {
|
||||
if (!requirement.isConditionMet(playerCondition)) {
|
||||
if (bossBarSender.getStatus()) {
|
||||
bossBarSender.hide();
|
||||
}
|
||||
}
|
||||
if (!bossBarSender.getStatus()) {
|
||||
bossBarSender.show();
|
||||
continue outer;
|
||||
}
|
||||
}
|
||||
if (!bossBarSender.getStatus()) {
|
||||
bossBarSender.show();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}.runTaskTimerAsynchronously(CustomNameplates.plugin, 1, 1);
|
||||
}.runTaskTimerAsynchronously(CustomNameplates.plugin, 0, 1);
|
||||
}
|
||||
|
||||
public void stopTimer() {
|
||||
|
||||
@@ -36,17 +36,17 @@ public enum FontOffset {
|
||||
NEG_128('\uf80c', -128, -130),
|
||||
|
||||
POS_1('\uf811', 1, -1),
|
||||
POS_2('\uf812', 2, 0),
|
||||
POS_3('\uf813', 3, 1),
|
||||
POS_4('\uf814', 4, 2),
|
||||
POS_5('\uf815', 5, 3),
|
||||
POS_6('\uf816', 6, 4),
|
||||
POS_7('\uf817', 7, 5),
|
||||
POS_8('\uf818', 8, 6),
|
||||
POS_16('\uf819', 16, 14),
|
||||
POS_32('\uf81a', 32, 30),
|
||||
POS_64('\uf81b', 64, 62),
|
||||
POS_128('\uf81c', 128, 126);
|
||||
POS_2('\uf812', 2, 1),
|
||||
POS_3('\uf813', 3, 2),
|
||||
POS_4('\uf814', 4, 3),
|
||||
POS_5('\uf815', 5, 4),
|
||||
POS_6('\uf816', 6, 5),
|
||||
POS_7('\uf817', 7, 6),
|
||||
POS_8('\uf818', 8, 7),
|
||||
POS_16('\uf819', 16, 15),
|
||||
POS_32('\uf81a', 32, 31),
|
||||
POS_64('\uf81b', 64, 63),
|
||||
POS_128('\uf81c', 128, 127);
|
||||
|
||||
private final char character;
|
||||
private final int space;
|
||||
|
||||
@@ -23,8 +23,10 @@ import net.momirealms.customnameplates.CustomNameplates;
|
||||
import net.momirealms.customnameplates.manager.ChatBubblesManager;
|
||||
import net.momirealms.customnameplates.objects.TextCache;
|
||||
import net.momirealms.customnameplates.utils.AdventureUtil;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
import org.bukkit.scheduler.BukkitTask;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.util.ArrayList;
|
||||
|
||||
@@ -54,12 +54,14 @@ public class FakeArmorStand implements ArmorStand {
|
||||
private TextCache text;
|
||||
private final PacketContainer destroyPacket;
|
||||
private WrappedChatComponent wrappedChatComponent;
|
||||
private int counter;
|
||||
|
||||
public FakeArmorStand(ArmorStandManager asm, Player owner, TextCache text, double yOffset) {
|
||||
this.asm = asm;
|
||||
this.owner = owner;
|
||||
this.yOffset = yOffset;
|
||||
this.text = text;
|
||||
this.counter = 0;
|
||||
sneaking = owner.isSneaking();
|
||||
destroyPacket = new PacketContainer(PacketType.Play.Server.ENTITY_DESTROY);
|
||||
destroyPacket.getIntLists().write(0, List.of(entityId));
|
||||
@@ -176,7 +178,7 @@ public class FakeArmorStand implements ArmorStand {
|
||||
for (Player viewer : asm.getNearbyPlayers()) {
|
||||
PacketContainer metaPacket = new PacketContainer(PacketType.Play.Server.ENTITY_METADATA);
|
||||
metaPacket.getIntegers().write(0, entityId);
|
||||
if (CustomNameplates.version.equals("v1_19_R2")) {
|
||||
if (CustomNameplates.plugin.getVersionHelper().isVersionNewerThan1_19_R2()) {
|
||||
WrappedDataWatcher wrappedDataWatcher = createDataWatcher(getText().getLatestText(), true);
|
||||
List<WrappedDataValue> wrappedDataValueList = Lists.newArrayList();
|
||||
wrappedDataWatcher.getWatchableObjects().stream().filter(Objects::nonNull).forEach(entry -> {
|
||||
@@ -197,7 +199,7 @@ public class FakeArmorStand implements ArmorStand {
|
||||
double y = getY() + yOffset;
|
||||
double z = owner.getLocation().getZ();
|
||||
if (!owner.isSleeping()) {
|
||||
if (sneaking) y += 1.37;
|
||||
if (sneaking) y += 1.5;
|
||||
else y += 1.8;
|
||||
}
|
||||
else y += 0.2;
|
||||
@@ -267,7 +269,7 @@ public class FakeArmorStand implements ArmorStand {
|
||||
PacketContainer metaPacket = new PacketContainer(PacketType.Play.Server.ENTITY_METADATA);
|
||||
metaPacket.getIntegers().write(0, entityId);
|
||||
if (this.wrappedChatComponent == null) {
|
||||
if (CustomNameplates.version.equals("v1_19_R2")) {
|
||||
if (CustomNameplates.plugin.getVersionHelper().isVersionNewerThan1_19_R2()) {
|
||||
WrappedDataWatcher wrappedDataWatcher = createDataWatcher(getText().getLatestText(), true);
|
||||
List<WrappedDataValue> wrappedDataValueList = Lists.newArrayList();
|
||||
wrappedDataWatcher.getWatchableObjects().stream().filter(Objects::nonNull).forEach(entry -> {
|
||||
@@ -280,7 +282,7 @@ public class FakeArmorStand implements ArmorStand {
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (CustomNameplates.version.equals("v1_19_R2")) {
|
||||
if (CustomNameplates.plugin.getVersionHelper().isVersionNewerThan1_19_R2()) {
|
||||
WrappedDataWatcher wrappedDataWatcher = createDataWatcher("", false);
|
||||
List<WrappedDataValue> wrappedDataValueList = Lists.newArrayList();
|
||||
wrappedDataWatcher.getWatchableObjects().stream().filter(Objects::nonNull).forEach(entry -> {
|
||||
|
||||
@@ -25,10 +25,11 @@ import org.bukkit.entity.Player;
|
||||
import org.bukkit.scheduler.BukkitTask;
|
||||
|
||||
import java.util.WeakHashMap;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
public class VehicleChecker extends Function {
|
||||
|
||||
private final WeakHashMap<Player, Entity> playersOnVehicle = new WeakHashMap<>();
|
||||
private final ConcurrentHashMap<Player, Entity> playersOnVehicle;
|
||||
|
||||
private final TeleportingTag teleportingTag;
|
||||
|
||||
@@ -36,6 +37,7 @@ public class VehicleChecker extends Function {
|
||||
|
||||
public VehicleChecker(TeleportingTag teleportingTag) {
|
||||
this.teleportingTag = teleportingTag;
|
||||
this.playersOnVehicle = new ConcurrentHashMap<>();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -60,6 +60,7 @@ public class TeamPrefixSuffix implements TeamPacketInterface {
|
||||
public void sendUpdateToAll(Player player, boolean force) {
|
||||
String teamName = teamManager.getTeamName(player);
|
||||
NameplatesTeam nameplatesTeam = teamManager.getTeams().get(teamName);
|
||||
if (nameplatesTeam == null) return;
|
||||
String newInfo = nameplatesTeam.getDynamic();
|
||||
String oldInfo = teamInfoCache.get(player);
|
||||
if (newInfo != null && newInfo.equals(oldInfo) && !force) {
|
||||
|
||||
@@ -69,7 +69,7 @@ public class HoloUtil {
|
||||
wrappedDataWatcher.setObject(new WrappedDataWatcher.WrappedDataWatcherObject(15, serializer2), mask2);
|
||||
packet2.getModifier().write(0,id);
|
||||
|
||||
if (CustomNameplates.version.equals("v1_19_R2")) {
|
||||
if (CustomNameplates.plugin.getVersionHelper().isVersionNewerThan1_19_R2()) {
|
||||
List<WrappedDataValue> wrappedDataValueList = Lists.newArrayList();
|
||||
wrappedDataWatcher.getWatchableObjects().stream().filter(Objects::nonNull).forEach(entry -> {
|
||||
final WrappedDataWatcher.WrappedDataWatcherObject dataWatcherObject = entry.getWatcherObject();
|
||||
@@ -98,7 +98,7 @@ public class HoloUtil {
|
||||
|
||||
Bukkit.getScheduler().runTaskLater(CustomNameplates.plugin, ()->{
|
||||
removeHolo(player, id);
|
||||
cache.remove(location);
|
||||
cache.remove(player);
|
||||
}, duration * 20L);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user