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

2.3 release

This commit is contained in:
XiaoMoMi
2024-01-25 04:53:43 +08:00
parent 4850d0b25c
commit 5f26759b06
19 changed files with 229 additions and 54 deletions

View File

@@ -167,14 +167,6 @@ public interface AdventureManager {
*/ */
String componentToJson(Component component); String componentToJson(Component component);
/**
* Get the component in original package
*
* @param component shaded component
* @return paper component
*/
Object shadedToOriginal(Component component);
/** /**
* Get MiniMessage format text from component * Get MiniMessage format text from component
* *

View File

@@ -7,7 +7,7 @@ plugins {
allprojects { allprojects {
version = "2.3.0.0-beta-5" version = "2.3.0.0"
apply<JavaPlugin>() apply<JavaPlugin>()
apply(plugin = "java") apply(plugin = "java")

View File

@@ -1,8 +1,8 @@
systemProp.socks.proxyHost=127.0.0.1 #systemProp.socks.proxyHost=127.0.0.1
systemProp.socks.proxyPort=7890 #systemProp.socks.proxyPort=7890
#
systemProp.http.proxyHost=127.0.0.1 #systemProp.http.proxyHost=127.0.0.1
systemProp.http.proxyPort=7890 #systemProp.http.proxyPort=7890
#
systemProp.https.proxyHost=127.0.0.1 #systemProp.https.proxyHost=127.0.0.1
systemProp.https.proxyPort=7890 #systemProp.https.proxyPort=7890

View File

@@ -271,18 +271,6 @@ public class AdventureManagerImpl implements AdventureManager {
return GsonComponentSerializer.gson().serialize(component); return GsonComponentSerializer.gson().serialize(component);
} }
@Override
public Object shadedToOriginal(Component component) {
Object cp;
try {
cp = ReflectionUtils.gsonDeserializeMethod.invoke(ReflectionUtils.gsonInstance, GsonComponentSerializer.gson().serialize(component));
} catch (InvocationTargetException | IllegalAccessException e) {
e.printStackTrace();
return null;
}
return cp;
}
@Override @Override
public String getMiniMessageFormat(Component component) { public String getMiniMessageFormat(Component component) {
return MiniMessage.miniMessage().serialize(component); return MiniMessage.miniMessage().serialize(component);
@@ -291,10 +279,10 @@ public class AdventureManagerImpl implements AdventureManager {
@Override @Override
public Object getIChatComponent(String json) { public Object getIChatComponent(String json) {
try { try {
return ReflectionUtils.iChatComponentMethod.invoke(null, json); return ReflectionUtils.getiChatComponentMethod().invoke(null, json);
} catch (InvocationTargetException | IllegalAccessException exception) { } catch (InvocationTargetException | IllegalAccessException exception) {
exception.printStackTrace(); exception.printStackTrace();
return ReflectionUtils.emptyComponent; return ReflectionUtils.getEmptyComponent();
} }
} }
@@ -374,7 +362,7 @@ public class AdventureManagerImpl implements AdventureManager {
return miniMessageToIChatComponentCache.get(text); return miniMessageToIChatComponentCache.get(text);
} catch (ExecutionException e) { } catch (ExecutionException e) {
e.printStackTrace(); e.printStackTrace();
return ReflectionUtils.emptyComponent; return ReflectionUtils.getEmptyComponent();
} }
} }

View File

@@ -86,7 +86,7 @@ public class BossBar {
packet.getModifier().write(0, uuid); packet.getModifier().write(0, uuid);
try { try {
Object chatComponent = AdventureManagerImpl.getInstance().getIChatComponentFromMiniMessage(latestMiniMessage); Object chatComponent = AdventureManagerImpl.getInstance().getIChatComponentFromMiniMessage(latestMiniMessage);
Object updatePacket = ReflectionUtils.updateConstructor.newInstance(chatComponent); Object updatePacket = ReflectionUtils.getUpdateConstructor().newInstance(chatComponent);
packet.getModifier().write(1, updatePacket); packet.getModifier().write(1, updatePacket);
} catch (InvocationTargetException | IllegalAccessException | InstantiationException e) { } catch (InvocationTargetException | IllegalAccessException | InstantiationException e) {
throw new RuntimeException(e); throw new RuntimeException(e);
@@ -97,7 +97,7 @@ public class BossBar {
private PacketContainer getRemovePacket() { private PacketContainer getRemovePacket() {
PacketContainer packet = new PacketContainer(PacketType.Play.Server.BOSS); PacketContainer packet = new PacketContainer(PacketType.Play.Server.BOSS);
packet.getModifier().write(0, uuid); packet.getModifier().write(0, uuid);
packet.getModifier().write(1, ReflectionUtils.removeBossBarPacket); packet.getModifier().write(1, ReflectionUtils.getRemoveBossBarPacket());
return packet; return packet;
} }
} }

View File

@@ -19,6 +19,7 @@ package net.momirealms.customnameplates.paper.mechanic.bubble.listener;
import me.arasple.mc.trchat.api.event.TrChatEvent; import me.arasple.mc.trchat.api.event.TrChatEvent;
import me.arasple.mc.trchat.module.display.channel.Channel; import me.arasple.mc.trchat.module.display.channel.Channel;
import net.momirealms.customnameplates.api.CustomNameplatesPlugin;
import net.momirealms.customnameplates.paper.mechanic.bubble.BubbleManagerImpl; import net.momirealms.customnameplates.paper.mechanic.bubble.BubbleManagerImpl;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
@@ -35,6 +36,8 @@ public class TrChatListener extends AbstractChatListener {
for (String channel : chatBubblesManager.getBlacklistChannels()) { for (String channel : chatBubblesManager.getBlacklistChannels()) {
if (channelName.equals(channel)) return; if (channelName.equals(channel)) return;
} }
chatBubblesManager.onChat(event.getSession().getPlayer(), event.getMessage()); CustomNameplatesPlugin.get().getScheduler().runTaskAsync(() -> {
chatBubblesManager.onChat(event.getSession().getPlayer(), event.getMessage());
});
} }
} }

View File

@@ -19,6 +19,7 @@ package net.momirealms.customnameplates.paper.mechanic.bubble.listener;
import mineverse.Aust1n46.chat.api.MineverseChatPlayer; import mineverse.Aust1n46.chat.api.MineverseChatPlayer;
import mineverse.Aust1n46.chat.api.events.VentureChatEvent; import mineverse.Aust1n46.chat.api.events.VentureChatEvent;
import net.momirealms.customnameplates.api.CustomNameplatesPlugin;
import net.momirealms.customnameplates.paper.mechanic.bubble.BubbleManagerImpl; import net.momirealms.customnameplates.paper.mechanic.bubble.BubbleManagerImpl;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
@@ -38,6 +39,8 @@ public class VentureChatListener extends AbstractChatListener {
if (chatPlayer == null) { if (chatPlayer == null) {
return; return;
} }
chatBubblesManager.onChat(chatPlayer.getPlayer(), event.getChat()); CustomNameplatesPlugin.get().getScheduler().runTaskAsync(() -> {
chatBubblesManager.onChat(chatPlayer.getPlayer(), event.getChat());
});
} }
} }

View File

@@ -184,7 +184,7 @@ public class NameplateManagerImpl implements NameplateManager, Listener {
teamPrefix = config.getString("team.prefix", ""); teamPrefix = config.getString("team.prefix", "");
teamSuffix = config.getString("team.suffix", ""); teamSuffix = config.getString("team.suffix", "");
teamRefreshFrequency = config.getInt("team.refresh-frequency", 10); teamRefreshFrequency = config.getInt("team.refresh-frequency", 10);
fixTab = config.getBoolean("team.fix-Tab", true); fixTab = config.getBoolean("team.fix-Tab", false);
ConfigurationSection unlimitedSection = config.getConfigurationSection("unlimited"); ConfigurationSection unlimitedSection = config.getConfigurationSection("unlimited");
if (unlimitedSection != null) { if (unlimitedSection != null) {

View File

@@ -0,0 +1,72 @@
/*
* 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.nameplate.tag.listener;
import com.comphenix.protocol.PacketType;
import com.comphenix.protocol.events.ListenerPriority;
import com.comphenix.protocol.events.PacketAdapter;
import com.comphenix.protocol.events.PacketContainer;
import com.comphenix.protocol.events.PacketEvent;
import com.comphenix.protocol.wrappers.EnumWrappers;
import com.comphenix.protocol.wrappers.PlayerInfoData;
import com.comphenix.protocol.wrappers.WrappedChatComponent;
import com.comphenix.protocol.wrappers.WrappedGameProfile;
import com.destroystokyo.paper.profile.PlayerProfile;
import net.momirealms.customnameplates.api.CustomNameplatesPlugin;
import net.momirealms.customnameplates.paper.mechanic.nameplate.NameplateManagerImpl;
import net.momirealms.customnameplates.paper.mechanic.nameplate.tag.team.TeamTagManagerImpl;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
public class PlayerInfoListener extends PacketAdapter {
private final TeamTagManagerImpl manager;
public PlayerInfoListener(TeamTagManagerImpl manager) {
super(CustomNameplatesPlugin.getInstance(), ListenerPriority.HIGHEST, PacketType.Play.Server.PLAYER_INFO);
this.manager = manager;
}
public void onPacketSending(PacketEvent event) {
PacketContainer packet = event.getPacket();
Set<EnumWrappers.PlayerInfoAction> actions = packet.getPlayerInfoActions().read(0);
if (!actions.contains(EnumWrappers.PlayerInfoAction.UPDATE_DISPLAY_NAME))
return;
List<?> list = (List<?>) packet.getModifier().read(1);
List<Object> newList = new ArrayList<>();
int size = list.size();
for (int i = 0; i < size; i++) {
Object dataHandle = list.get(i);
if (dataHandle == null) {
continue;
}
PlayerInfoData data = PlayerInfoData.getConverter().getSpecific(dataHandle);
WrappedGameProfile profile = data.getProfile();
PlayerInfoData newData = new PlayerInfoData(
profile,
data.getLatency(),
data.getGameMode(),
WrappedChatComponent.fromJson(String.format("{\"text\":\"%s\"}", profile.getName()))
);
newList.add(PlayerInfoData.getConverter().getGeneric(newData));
}
packet.getModifier().write(1, newList);
}
}

View File

@@ -17,12 +17,14 @@
package net.momirealms.customnameplates.paper.mechanic.nameplate.tag.team; package net.momirealms.customnameplates.paper.mechanic.nameplate.tag.team;
import com.comphenix.protocol.ProtocolLibrary;
import net.momirealms.customnameplates.api.CustomNameplatesPlugin; import net.momirealms.customnameplates.api.CustomNameplatesPlugin;
import net.momirealms.customnameplates.api.manager.NameplateManager; import net.momirealms.customnameplates.api.manager.NameplateManager;
import net.momirealms.customnameplates.api.manager.TeamTagManager; import net.momirealms.customnameplates.api.manager.TeamTagManager;
import net.momirealms.customnameplates.api.scheduler.CancellableTask; import net.momirealms.customnameplates.api.scheduler.CancellableTask;
import net.momirealms.customnameplates.api.util.LocationUtils; import net.momirealms.customnameplates.api.util.LocationUtils;
import net.momirealms.customnameplates.api.util.LogUtils; import net.momirealms.customnameplates.api.util.LogUtils;
import net.momirealms.customnameplates.paper.mechanic.nameplate.tag.listener.PlayerInfoListener;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.entity.Entity; import org.bukkit.entity.Entity;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
@@ -38,10 +40,12 @@ public class TeamTagManagerImpl implements TeamTagManager {
private final NameplateManager manager; private final NameplateManager manager;
private final ConcurrentHashMap<UUID, TeamPlayer> teamPlayerMap; private final ConcurrentHashMap<UUID, TeamPlayer> teamPlayerMap;
private CancellableTask refreshTask; private CancellableTask refreshTask;
private PlayerInfoListener tabListener;
public TeamTagManagerImpl(NameplateManager manager) { public TeamTagManagerImpl(NameplateManager manager) {
this.manager = manager; this.manager = manager;
this.teamPlayerMap = new ConcurrentHashMap<>(); this.teamPlayerMap = new ConcurrentHashMap<>();
this.tabListener = new PlayerInfoListener(this);
} }
public void load(long refreshFrequency, boolean fixTab) { public void load(long refreshFrequency, boolean fixTab) {
@@ -66,7 +70,7 @@ public class TeamTagManagerImpl implements TeamTagManager {
TimeUnit.MILLISECONDS TimeUnit.MILLISECONDS
); );
if (fixTab) { if (fixTab) {
// TODO ProtocolLibrary.getProtocolManager().addPacketListener(tabListener);
} }
} }
@@ -77,6 +81,7 @@ public class TeamTagManagerImpl implements TeamTagManager {
for (TeamPlayer entry : teamPlayerMap.values()) { for (TeamPlayer entry : teamPlayerMap.values()) {
entry.destroy(); entry.destroy();
} }
ProtocolLibrary.getProtocolManager().removePacketListener(tabListener);
} }
@Override @Override

View File

@@ -17,25 +17,27 @@
package net.momirealms.customnameplates.paper.util; package net.momirealms.customnameplates.paper.util;
import com.comphenix.protocol.utility.MinecraftFields;
import com.comphenix.protocol.utility.MinecraftMethods;
import com.comphenix.protocol.utility.MinecraftReflection; import com.comphenix.protocol.utility.MinecraftReflection;
import com.comphenix.protocol.wrappers.WrappedGameProfile;
import net.momirealms.customnameplates.api.util.LogUtils; import net.momirealms.customnameplates.api.util.LogUtils;
import java.lang.reflect.Constructor; import java.lang.reflect.Constructor;
import java.lang.reflect.Field; import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException; import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.util.UUID;
public class ReflectionUtils { public class ReflectionUtils {
private ReflectionUtils() {} private ReflectionUtils() {}
public static Object removeBossBarPacket; private static Object removeBossBarPacket;
public static Constructor<?> progressConstructor; private static Constructor<?> progressConstructor;
public static Constructor<?> updateConstructor; private static Constructor<?> updateConstructor;
public static Method iChatComponentMethod; private static Method iChatComponentMethod;
public static Method gsonDeserializeMethod; private static Object emptyComponent;
public static Object gsonInstance;
public static Object emptyComponent;
public static void load() { public static void load() {
try { try {
@@ -57,4 +59,24 @@ public class ReflectionUtils {
exception.printStackTrace(); exception.printStackTrace();
} }
} }
public static Object getRemoveBossBarPacket() {
return removeBossBarPacket;
}
public static Constructor<?> getProgressConstructor() {
return progressConstructor;
}
public static Constructor<?> getUpdateConstructor() {
return updateConstructor;
}
public static Method getiChatComponentMethod() {
return iChatComponentMethod;
}
public static Object getEmptyComponent() {
return emptyComponent;
}
} }

View File

@@ -1,5 +1,6 @@
# Player can only receive at most 1 actionbar at the same time # Player can only receive at most 1 actionbar at the same time
actionbar: actionbar:
# The frequency of checking conditions for a bar, measured in ticks
check-frequency: 10 check-frequency: 10
conditions: conditions:
permission: "actionbar.show" permission: "actionbar.show"
@@ -11,4 +12,10 @@ actionbar:
text: '%nameplates_conditional_actionbar%' text: '%nameplates_conditional_actionbar%'
# The frequency of refreshing the text, the lower the value is, the faster the placeholders are updated # The frequency of refreshing the text, the lower the value is, the faster the placeholders are updated
# measured in ticks, -1 = disable refreshing # measured in ticks, -1 = disable refreshing
refresh-frequency: 1 refresh-frequency: 1
# Optional
# When enabling conditions, make sure that players would see at least one in the order,
# otherwise it will fall into a dead cycle
# If your player doesn't meet the conditions, it would be skipped
# This condition would only be checked once until the next turn
conditions: {}

View File

@@ -29,8 +29,9 @@ bossbar_1:
# Optional # Optional
# When enabling conditions, make sure that players would see at least one in the order, # When enabling conditions, make sure that players would see at least one in the order,
# otherwise it will fall into a dead cycle # otherwise it will fall into a dead cycle
# If your player doesn't meet the conditions, it would be skipped
# This condition would only be checked once until the next turn
conditions: conditions:
# If your player doesn't meet the conditions, it would be skipped
permission: nameplates.admin permission: nameplates.admin
equals: equals:
value1: '%nameplates_is-latest%' value1: '%nameplates_is-latest%'

View File

@@ -1,3 +1,4 @@
# https://mo-mi.gitbook.io/xiaomomi-plugins/plugin-wiki/customnameplates/custom-placeholders/conditional-text
conditional-text: conditional-text:
actionbar: actionbar:
priority_0: priority_0:
@@ -40,11 +41,13 @@ conditional-text:
weather: weather:
- rainstorm - rainstorm
# https://mo-mi.gitbook.io/xiaomomi-plugins/plugin-wiki/customnameplates/custom-placeholders/nameplate-text
nameplate-text: nameplate-text:
halloween: halloween:
nameplate: halloween nameplate: halloween
text: '<gradient:#FFD700:#FFA500:#FFD700>Today is Halloween! Trick or treat!</gradient>' text: '<gradient:#FFD700:#FFA500:#FFD700>Today is Halloween! Trick or treat!</gradient>'
# https://mo-mi.gitbook.io/xiaomomi-plugins/plugin-wiki/customnameplates/custom-placeholders/background-text
background-text: background-text:
location: location:
background: bedrock_1 background: bedrock_1
@@ -71,6 +74,7 @@ background-text:
text: '%nameplates_actionbar%' text: '%nameplates_actionbar%'
remove-shadow: true remove-shadow: true
# https://mo-mi.gitbook.io/xiaomomi-plugins/plugin-wiki/customnameplates/custom-placeholders/static-text
static-text: static-text:
money_hud: money_hud:
position: right position: right
@@ -81,6 +85,7 @@ static-text:
text: "%nameplates_background_other_actionbar%" text: "%nameplates_background_other_actionbar%"
value: 180 value: 180
# https://mo-mi.gitbook.io/xiaomomi-plugins/plugin-wiki/customnameplates/custom-placeholders/static-text
descent-text: descent-text:
location: location:
text: "Your Location: %player_x%, %player_y%, %player_z%" text: "Your Location: %player_x%, %player_y%, %player_z%"
@@ -107,6 +112,7 @@ descent-text:
descent: 5 descent: 5
is-unicode: true is-unicode: true
# https://mo-mi.gitbook.io/xiaomomi-plugins/plugin-wiki/customnameplates/custom-placeholders/switch-text
switch-text: switch-text:
season: season:
switch: '%customcrops_season%' switch: '%customcrops_season%'
@@ -117,6 +123,7 @@ switch-text:
'Winter': '<blue>Winter</blue>' 'Winter': '<blue>Winter</blue>'
default: 'Invalid season' default: 'Invalid season'
# https://mo-mi.gitbook.io/xiaomomi-plugins/plugin-wiki/customnameplates/custom-placeholders/vanilla-hud
vanilla-hud: vanilla-hud:
stamina_hud: stamina_hud:
reverse: true reverse: true

View File

@@ -13,8 +13,6 @@ nameplate:
prefix: '' prefix: ''
player-name: '%player_name%' player-name: '%player_name%'
suffix: '' suffix: ''
# Disable this if you are using a custom Tab plugin
fix-Tab: true
# Settings for Team mode # Settings for Team mode
team: team:
@@ -22,20 +20,26 @@ team:
refresh-frequency: 10 refresh-frequency: 10
prefix: '%nameplates_prefix%' prefix: '%nameplates_prefix%'
suffix: '%nameplates_suffix%' suffix: '%nameplates_suffix%'
# Don't enable this if you are using a custom Tab plugin
fix-Tab: false
# Settings for Unlimited mode # Settings for Unlimited mode
unlimited: unlimited:
tag_1: tag_1:
# The texts to display
text: '%nameplates_nametag%' text: '%nameplates_nametag%'
# Verticle offset of the fake entity
vertical-offset: -1 vertical-offset: -1
# Conditions (Owner side)
owner-conditions: owner-conditions:
potion-effect: "INVISIBILITY<0" potion-effect: "INVISIBILITY<0"
# Conditions (Viewer side)
viewer-conditions: { } viewer-conditions: { }
tag_2: tag_2:
text: "IP: %player_ip% My IP: %viewer_player_ip%" text: "IP: %player_ip% My IP: %viewer_player_ip%" # If a placeholder starts with "%viewer_", it would display the viewer's.
vertical-offset: -0.7 vertical-offset: -0.7
refresh-frequency: 10 refresh-frequency: 10 # Decides the frequency of the text refreshing
check-frequency: 20 check-frequency: 20 # Decides the frequency of the condition check
owner-conditions: owner-conditions:
potion-effect: "INVISIBILITY<0" potion-effect: "INVISIBILITY<0"
viewer-conditions: viewer-conditions:

View File

@@ -8,7 +8,7 @@ depend: [ ProtocolLib ,PlaceholderAPI ]
softdepend: [ MagicCosmetics, TAB, CMI, TrChat, ItemsAdder, Oraxen ] softdepend: [ MagicCosmetics, TAB, CMI, TrChat, ItemsAdder, Oraxen ]
permissions: permissions:
nameplates.*: nameplates.*:
description: Gives access to all user commands description: Gives access to all nameplate user commands
children: children:
nameplates.equip: true nameplates.equip: true
nameplates.unequip: true nameplates.unequip: true
@@ -23,4 +23,17 @@ permissions:
nameplates.list: nameplates.list:
default: true default: true
customnameplates.admin: customnameplates.admin:
default: op default: op
bubbles.*:
description: Gives access to bubble all user commands
children:
bubbles.equip: true
bubbles.unequip: true
bubbles.list: true
bubbles.equip:
default: true
bubbles.unequip:
default: true
bubbles.list:
default: true

View File

@@ -4,3 +4,4 @@ include("bungeecord")
include("velocity") include("velocity")
include("paper") include("paper")
include("common") include("common")
include("universe")

42
universe/.gitignore vendored Normal file
View 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

15
universe/build.gradle.kts Normal file
View File

@@ -0,0 +1,15 @@
dependencies {
implementation(project(":api"))
implementation(project(":common"))
implementation(project(":paper"))
implementation(project(":velocity"))
implementation(project(":bungeecord"))
}
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")
}
}