mirror of
https://github.com/Xiao-MoMi/Custom-Nameplates.git
synced 2025-12-30 12:19:12 +00:00
2.2.3.11
This commit is contained in:
@@ -19,9 +19,9 @@ package net.momirealms.customnameplates.bungeecord;
|
||||
|
||||
public class BungeeConfigManager {
|
||||
|
||||
private final CustomNameplates plugin;
|
||||
private final CustomNameplatesBC plugin;
|
||||
|
||||
public BungeeConfigManager(CustomNameplates plugin) {
|
||||
public BungeeConfigManager(CustomNameplatesBC plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
|
||||
@@ -32,10 +32,10 @@ import java.util.Objects;
|
||||
|
||||
public class BungeeEventListener implements Listener {
|
||||
|
||||
private final CustomNameplates plugin;
|
||||
private final CustomNameplatesBC plugin;
|
||||
private final SortingManager sortingManager;
|
||||
|
||||
public BungeeEventListener (CustomNameplates plugin) {
|
||||
public BungeeEventListener (CustomNameplatesBC plugin) {
|
||||
this.plugin = plugin;
|
||||
this.sortingManager = TAB.getInstance().getSortingManager();
|
||||
}
|
||||
|
||||
@@ -0,0 +1,51 @@
|
||||
/*
|
||||
* 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.bungeecord;
|
||||
|
||||
import net.md_5.bungee.api.plugin.Plugin;
|
||||
|
||||
public class CustomNameplatesBC extends Plugin {
|
||||
|
||||
public static CustomNameplatesBC bungeePlugin;
|
||||
private BungeeEventListener bungeeEventListener;
|
||||
private BungeeConfigManager bungeeConfigManager;
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
bungeePlugin = this;
|
||||
this.bungeeEventListener = new BungeeEventListener(this);
|
||||
this.getProxy().registerChannel("customnameplates:cnp");
|
||||
this.getProxy().getPluginManager().registerListener(this, bungeeEventListener);
|
||||
this.bungeeConfigManager = new BungeeConfigManager(this);
|
||||
this.bungeeConfigManager.load();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDisable() {
|
||||
this.getProxy().unregisterChannel("customnameplates:cnp");
|
||||
this.getProxy().getPluginManager().unregisterListener(bungeeEventListener);
|
||||
}
|
||||
|
||||
public BungeeConfigManager getBungeeConfig() {
|
||||
return bungeeConfigManager;
|
||||
}
|
||||
|
||||
public static CustomNameplatesBC getPlugin() {
|
||||
return bungeePlugin;
|
||||
}
|
||||
}
|
||||
@@ -56,7 +56,6 @@ public class VersionHelper {
|
||||
|
||||
public void initialize() {
|
||||
if (serverVersion == null) {
|
||||
System.out.println(Bukkit.getServer().getBukkitVersion());
|
||||
this.serverVersion = Bukkit.getServer().getClass().getPackage().getName().split("\\.")[3];
|
||||
String[] split = serverVersion.split("_");
|
||||
int main_ver = Integer.parseInt(split[1]);
|
||||
|
||||
@@ -93,6 +93,7 @@ public class BossBarManager extends Function {
|
||||
Overlay.valueOf(bossBarSection.getString("overlay","progress").toUpperCase(Locale.ENGLISH)),
|
||||
BarColor.valueOf(bossBarSection.getString("color","white").toUpperCase(Locale.ENGLISH)),
|
||||
bossBarSection.getInt("switch-interval", 5) * 20,
|
||||
Math.max(1, bossBarSection.getInt("refresh-rate", 1)),
|
||||
ConfigUtils.getRequirements(bossBarSection.getConfigurationSection("conditions"))
|
||||
));
|
||||
}
|
||||
|
||||
@@ -181,8 +181,7 @@ public class ChatBubblesManager extends Function {
|
||||
if (!config.contains("tail.ascent")) config.set("tail.ascent", 12);
|
||||
try {
|
||||
config.save(bb_config_file);
|
||||
}
|
||||
catch (IOException ignored) {
|
||||
} catch (IOException ignored) {
|
||||
}
|
||||
SimpleChar leftChar = new SimpleChar(config.getInt("left.height"), config.getInt("left.ascent"), config.getInt("left.width"), left, config.getString("left.image") + ".png");
|
||||
SimpleChar middleChar = new SimpleChar(config.getInt("middle.height"), config.getInt("middle.ascent"), config.getInt("middle.width"), middle, config.getString("middle.image") + ".png");
|
||||
|
||||
@@ -39,6 +39,7 @@ public class ConfigManager extends Function {
|
||||
public static boolean thin_font;
|
||||
public static boolean tab_hook;
|
||||
public static boolean tab_BC_hook;
|
||||
public static boolean velocitab_hook;
|
||||
public static boolean oraxenHook;
|
||||
public static boolean trChat_Hook;
|
||||
public static boolean ventureChat_Hook;
|
||||
@@ -78,6 +79,7 @@ public class ConfigManager extends Function {
|
||||
if (section != null) {
|
||||
tab_hook = section.getBoolean("TAB",false) && Bukkit.getPluginManager().isPluginEnabled("TAB");
|
||||
tab_BC_hook = section.getBoolean("TAB-BC",false);
|
||||
velocitab_hook = section.getBoolean("Velocitab",false);
|
||||
trChat_Hook = section.getBoolean("TrChat",false) && Bukkit.getPluginManager().isPluginEnabled("TrChat");
|
||||
itemsAdderHook = section.getBoolean("ItemsAdder",false) && Bukkit.getPluginManager().isPluginEnabled("ItemsAdder");
|
||||
oraxenHook = section.getBoolean("Oraxen",false) && Bukkit.getPluginManager().isPluginEnabled("Oraxen");
|
||||
|
||||
@@ -101,7 +101,6 @@ public class FontManager extends Function {
|
||||
}
|
||||
}
|
||||
plugin.saveResource("templates" + File.separator + "default.json", true);
|
||||
plugin.saveResource("templates" + File.separator + "default1_20.json", true);
|
||||
plugin.saveResource("templates" + File.separator + "unicode.json", true);
|
||||
}
|
||||
|
||||
|
||||
@@ -277,7 +277,7 @@ public class ResourceManager {
|
||||
for (int ascent : plugin.getPlaceholderManager().getDescent_fonts()) {
|
||||
String line;
|
||||
StringBuilder sb = new StringBuilder();
|
||||
try (BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(new File(plugin.getDataFolder(), "templates" + File.separator + (plugin.getVersionHelper().isVersionNewerThan1_20() ? "default1_20.json" : "default.json"))), StandardCharsets.UTF_8))) {
|
||||
try (BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(new File(plugin.getDataFolder(), "templates" + File.separator + "default.json")), StandardCharsets.UTF_8))) {
|
||||
while ((line = reader.readLine()) != null) {
|
||||
sb.append(line).append(System.lineSeparator());
|
||||
}
|
||||
|
||||
@@ -27,6 +27,7 @@ import net.momirealms.customnameplates.object.team.TeamPacketInterface;
|
||||
import net.momirealms.customnameplates.object.team.name.PlayerNameTeamImpl;
|
||||
import net.momirealms.customnameplates.object.team.name.TABBungeeCordImpl;
|
||||
import net.momirealms.customnameplates.object.team.name.TABImpl;
|
||||
import net.momirealms.customnameplates.object.team.name.VelocitabImpl;
|
||||
import net.momirealms.customnameplates.object.team.packet.TeamInfoImpl;
|
||||
import net.momirealms.customnameplates.object.team.packet.TeamVisibilityImpl;
|
||||
import org.bukkit.Bukkit;
|
||||
@@ -60,6 +61,8 @@ public class TeamManager extends Function {
|
||||
teamNameInterface = new TABBungeeCordImpl();
|
||||
} else if (ConfigManager.tab_hook) {
|
||||
teamNameInterface = new TABImpl();
|
||||
} else if (ConfigManager.velocitab_hook) {
|
||||
teamNameInterface = new VelocitabImpl();
|
||||
} else {
|
||||
teamNameInterface = new PlayerNameTeamImpl(this);
|
||||
}
|
||||
|
||||
@@ -20,6 +20,6 @@ package net.momirealms.customnameplates.object.bossbar;
|
||||
import net.momirealms.customnameplates.object.requirements.Requirement;
|
||||
import org.bukkit.boss.BarColor;
|
||||
|
||||
public record BossBarConfig(String[] texts, Overlay overlay, BarColor color, int interval, Requirement[] conditions) {
|
||||
public record BossBarConfig(String[] texts, Overlay overlay, BarColor color, int interval, int refreshRate, Requirement[] conditions) {
|
||||
|
||||
}
|
||||
|
||||
@@ -42,6 +42,7 @@ public class BossBarSender {
|
||||
private final Player player;
|
||||
private final int switch_interval;
|
||||
private int timer;
|
||||
private int refresh_rate;
|
||||
private int current_text_id;
|
||||
private final DynamicText[] dynamicTexts;
|
||||
private final Requirement[] requirements;
|
||||
@@ -51,7 +52,7 @@ public class BossBarSender {
|
||||
private final Overlay overlay;
|
||||
private final BarColor barColor;
|
||||
|
||||
public BossBarSender(int switch_interval, String[] texts, Requirement[] requirements, Overlay overlay, BarColor barColor,Player player) {
|
||||
public BossBarSender(int switch_interval, int refreshRate, String[] texts, Requirement[] requirements, Overlay overlay, BarColor barColor,Player player) {
|
||||
this.player = player;
|
||||
this.switch_interval = switch_interval;
|
||||
this.overlay = overlay;
|
||||
@@ -63,6 +64,7 @@ public class BossBarSender {
|
||||
dynamicTexts[i] = new DynamicText(player, texts[i]);
|
||||
}
|
||||
this.current_text_id = 0;
|
||||
this.refresh_rate = refreshRate;
|
||||
}
|
||||
|
||||
public boolean isShown() {
|
||||
@@ -70,7 +72,7 @@ public class BossBarSender {
|
||||
}
|
||||
|
||||
public boolean canSend() {
|
||||
if (requirements.length == 0) return true;
|
||||
if (requirements == null) return true;
|
||||
for (Requirement requirement : requirements) {
|
||||
if (!requirement.isConditionMet(player)) {
|
||||
return false;
|
||||
@@ -91,15 +93,14 @@ public class BossBarSender {
|
||||
|
||||
public void update() {
|
||||
timer++;
|
||||
if (timer > switch_interval) {
|
||||
timer = 0;
|
||||
if (timer % switch_interval == 0) {
|
||||
current_text_id++;
|
||||
if (current_text_id >= dynamicTexts.length) {
|
||||
current_text_id = 0;
|
||||
}
|
||||
force = true;
|
||||
}
|
||||
if (dynamicTexts[current_text_id].update() || force) {
|
||||
if (timer % refresh_rate == 0 && dynamicTexts[current_text_id].update() || force) {
|
||||
force = false;
|
||||
CustomNameplates.getProtocolManager().sendServerPacket(player, getUpdatePacket());
|
||||
}
|
||||
|
||||
@@ -32,6 +32,7 @@ public class BossBarTask {
|
||||
BossBarConfig bossBarConfig = configs[i];
|
||||
this.bossBarSenders[i] = new BossBarSender(
|
||||
bossBarConfig.interval(),
|
||||
bossBarConfig.refreshRate(),
|
||||
bossBarConfig.texts(),
|
||||
bossBarConfig.conditions(),
|
||||
bossBarConfig.overlay(),
|
||||
|
||||
@@ -58,7 +58,7 @@ public class TABBungeeCordImpl implements TeamNameInterface {
|
||||
String teamName = teamNameMap.get(player.getName());
|
||||
if (teamName == null) {
|
||||
sendRequest(player);
|
||||
return player.getName();
|
||||
return null;
|
||||
} else {
|
||||
return teamName;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,108 @@
|
||||
/*
|
||||
* 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.object.team.name;
|
||||
|
||||
import com.google.common.io.ByteArrayDataInput;
|
||||
import com.google.common.io.ByteArrayDataOutput;
|
||||
import com.google.common.io.ByteStreams;
|
||||
import net.momirealms.customnameplates.CustomNameplates;
|
||||
import net.momirealms.customnameplates.object.team.TeamNameInterface;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.messaging.PluginMessageListener;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Objects;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
public class VelocitabImpl implements TeamNameInterface {
|
||||
|
||||
private final ConcurrentHashMap<String, String> teamNameMap;
|
||||
private final ProxyDataListener proxyDataListener;
|
||||
|
||||
public VelocitabImpl() {
|
||||
this.teamNameMap = new ConcurrentHashMap<>();
|
||||
this.proxyDataListener = new ProxyDataListener(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void load() {
|
||||
Bukkit.getServer().getMessenger().registerOutgoingPluginChannel(CustomNameplates.getInstance(), "customnameplates:cnp");
|
||||
Bukkit.getServer().getMessenger().registerIncomingPluginChannel(CustomNameplates.getInstance(), "customnameplates:cnp", proxyDataListener);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unload() {
|
||||
this.teamNameMap.clear();
|
||||
Bukkit.getServer().getMessenger().unregisterIncomingPluginChannel(CustomNameplates.getInstance(), "customnameplates:cnp");
|
||||
Bukkit.getServer().getMessenger().unregisterOutgoingPluginChannel(CustomNameplates.getInstance(), "customnameplates:cnp");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTeamName(Player player) {
|
||||
String teamName = teamNameMap.get(player.getName());
|
||||
if (teamName == null) {
|
||||
sendRequest(player);
|
||||
return null;
|
||||
} else {
|
||||
return teamName;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onJoin(Player player) {
|
||||
sendRequest(player);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onQuit(Player player) {
|
||||
teamNameMap.remove(player.getName());
|
||||
}
|
||||
|
||||
@SuppressWarnings("UnstableApiUsage")
|
||||
private void sendRequest(Player player) {
|
||||
ByteArrayDataOutput dataOutput = ByteStreams.newDataOutput();
|
||||
dataOutput.writeUTF(player.getName());
|
||||
player.sendPluginMessage(CustomNameplates.getInstance(), "customnameplates:cnp", dataOutput.toByteArray());
|
||||
}
|
||||
|
||||
public void addPlayerToCache(String playerName, String teamName) {
|
||||
teamNameMap.put(playerName, teamName);
|
||||
}
|
||||
|
||||
public static class ProxyDataListener implements PluginMessageListener {
|
||||
|
||||
private final VelocitabImpl TABBungeeCordImpl;
|
||||
|
||||
public ProxyDataListener(VelocitabImpl TABBungeeCordImpl) {
|
||||
this.TABBungeeCordImpl = TABBungeeCordImpl;
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("UnstableApiUsage")
|
||||
public void onPluginMessageReceived(@NotNull String channel, @NotNull Player player, @NotNull byte[] message) {
|
||||
if (!Objects.equals("customnameplates:cnp", channel)) {
|
||||
return;
|
||||
}
|
||||
ByteArrayDataInput dataInput = ByteStreams.newDataInput(message);
|
||||
String playerName = dataInput.readUTF();
|
||||
String teamName = dataInput.readUTF();
|
||||
TABBungeeCordImpl.addPlayerToCache(playerName, teamName);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,82 @@
|
||||
package net.momirealms.customnameplates.velocity;
|
||||
|
||||
import com.google.common.io.ByteArrayDataInput;
|
||||
import com.google.common.io.ByteArrayDataOutput;
|
||||
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.william278.velocitab.Velocitab;
|
||||
import org.slf4j.Logger;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
@Plugin(id = "customnameplates", name = "CustomNameplates", version = "2.2", authors = {"XiaoMoMi"},
|
||||
dependencies = {
|
||||
@Dependency(id = "velocitab")
|
||||
}
|
||||
)
|
||||
public class CustomNameplatesVC {
|
||||
|
||||
private static CustomNameplatesVC instance;
|
||||
private final ProxyServer server;
|
||||
private final Logger logger;
|
||||
private Velocitab tab;
|
||||
|
||||
@Inject
|
||||
public CustomNameplatesVC(ProxyServer server, Logger logger) {
|
||||
instance = this;
|
||||
this.server = server;
|
||||
this.logger = logger;
|
||||
}
|
||||
|
||||
public static CustomNameplatesVC getInstance() {
|
||||
return instance;
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void onProxyInitialization(ProxyInitializeEvent event) {
|
||||
server.getChannelRegistrar().register(MinecraftChannelIdentifier.from("customnameplates:cnp"));
|
||||
Optional<PluginContainer> optContainer = server.getPluginManager().getPlugin("velocitab");
|
||||
optContainer.ifPresent(pluginContainer -> tab = (Velocitab) pluginContainer.getInstance().get());
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void onProxyShutdown(ProxyShutdownEvent event) {
|
||||
server.getChannelRegistrar().unregister(MinecraftChannelIdentifier.from("customnameplates:cnp"));
|
||||
}
|
||||
|
||||
public ProxyServer getServer() {
|
||||
return server;
|
||||
}
|
||||
|
||||
public Logger getLogger() {
|
||||
return logger;
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
@SuppressWarnings("UnstableApiUsage")
|
||||
public void onPluginMessage(PluginMessageEvent event) {
|
||||
if (!event.getIdentifier().getId().equals("customnameplates:cnp")) {
|
||||
return;
|
||||
}
|
||||
ByteArrayDataInput dataInput = ByteStreams.newDataInput(event.getData());
|
||||
String playerName = dataInput.readUTF();
|
||||
Optional<Player> optPlayer = server.getPlayer(playerName);
|
||||
if (optPlayer.isEmpty()) return;
|
||||
var player = tab.getTabPlayer(optPlayer.get());
|
||||
|
||||
ByteArrayDataOutput byteArrayDataOutput = ByteStreams.newDataOutput();
|
||||
byteArrayDataOutput.writeUTF(playerName);
|
||||
byteArrayDataOutput.writeUTF(player.getTeamName(tab));
|
||||
optPlayer.get().getCurrentServer().ifPresent(it -> it.sendPluginMessage(MinecraftChannelIdentifier.from("customnameplates:cnp"), byteArrayDataOutput.toByteArray()));
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
name: CustomNameplates
|
||||
main: net.momirealms.customnameplates.bungeecord.CustomNameplates
|
||||
main: net.momirealms.customnameplates.bungeecord.CustomNameplatesBC
|
||||
version: '2.2.1.2'
|
||||
author: XiaoMoMi
|
||||
softDepends: [TAB, BungeeTabListPlus]
|
||||
@@ -1,5 +1,5 @@
|
||||
# Do not change
|
||||
config-version: '19'
|
||||
config-version: '20'
|
||||
|
||||
# bStats
|
||||
metrics: true
|
||||
@@ -35,6 +35,8 @@ integrations:
|
||||
# You need to install CustomNameplates on BungeeCord too, otherwise you might be kicked from the server if you enabled "create-fake-team" in nameplate.yml
|
||||
# 启用后,插件会从BungeeCord端接收TAB的队伍信息
|
||||
TAB-BC: false
|
||||
# Receive Team info from Velocitab
|
||||
Velocitab: false
|
||||
# TrChat channels
|
||||
# TrChat频道
|
||||
TrChat: false
|
||||
|
||||
@@ -5,7 +5,10 @@ basic_info_hud:
|
||||
- '%nameplates_background_weather% %nameplates_background_position%'
|
||||
- '%nameplates_background_time% %nameplates_background_hello%'
|
||||
#- '%nameplates_conditional_region%'
|
||||
# switch the line of text every 15 seconds
|
||||
switch-interval: 15
|
||||
# Refresh the text every 1 tick
|
||||
refresh-rate: 1
|
||||
conditions:
|
||||
permission: bossbar.show
|
||||
|
||||
@@ -14,6 +17,7 @@ update_info:
|
||||
overlay: PROGRESS
|
||||
text: '%nameplates_background_update%'
|
||||
switch-interval: 15
|
||||
refresh-rate: 20
|
||||
conditions:
|
||||
permission: customnameplates.admin
|
||||
papi-condition:
|
||||
|
||||
@@ -186,11 +186,6 @@
|
||||
"\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u2205\u2208\u0000",
|
||||
"\u2261\u00b1\u2265\u2264\u2320\u2321\u00f7\u2248\u00b0\u2219\u0000\u221a\u207f\u00b2\u25a0\u0000"
|
||||
]
|
||||
},
|
||||
{
|
||||
"type": "legacy_unicode",
|
||||
"sizes": "minecraft:font/glyph_sizes.bin",
|
||||
"template": "minecraft:font/unicode_page_%s.png"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user