9
0
mirror of https://github.com/Xiao-MoMi/Custom-Nameplates.git synced 2025-12-19 15:09:23 +00:00
This commit is contained in:
Xiao-MoMi
2022-10-20 23:29:09 +08:00
parent ee720cd8ca
commit 4109358def
12 changed files with 99 additions and 16 deletions

View File

@@ -4,7 +4,7 @@ plugins {
} }
group = 'net.momirealms' group = 'net.momirealms'
version = '2.0.5-hotfix-2' version = '2.0.6'
repositories { repositories {
mavenCentral() mavenCentral()
@@ -54,6 +54,7 @@ dependencies {
implementation('net.kyori:adventure-platform-bukkit:4.1.2') implementation('net.kyori:adventure-platform-bukkit:4.1.2')
implementation('net.kyori:adventure-text-minimessage:4.11.0') implementation('net.kyori:adventure-text-minimessage:4.11.0')
implementation('net.kyori:adventure-text-serializer-gson:4.11.0') implementation('net.kyori:adventure-text-serializer-gson:4.11.0')
implementation("org.bstats:bstats-bukkit:3.0.0")
} }
def targetJavaVersion = 16 def targetJavaVersion = 16
@@ -86,7 +87,8 @@ tasks.withType(JavaCompile) {
} }
shadowJar { shadowJar {
relocate ('net.kyori', 'net.momirealms.customnameplates.libs') relocate ('net.kyori', 'net.momirealms.customnameplates.libs.net.kyori')
relocate ('org.bstats', 'net.momirealms.customnameplates.libs.org.bstats')
} }
tasks.register("delete", Delete).get().delete("build/libs/"+project.name+"-"+project.version+".jar") tasks.register("delete", Delete).get().delete("build/libs/"+project.name+"-"+project.version+".jar")

View File

@@ -107,7 +107,7 @@ public class ConfigManager {
public static String ss_folder_path; public static String ss_folder_path;
public static String bb_folder_path; public static String bb_folder_path;
public static String font; public static String font;
public static String trChatChannel; public static String[] trChatChannel;
public static boolean itemsAdder; public static boolean itemsAdder;
public static boolean placeholderAPI; public static boolean placeholderAPI;
@@ -147,7 +147,7 @@ public class ConfigManager {
tab_bc = config.getBoolean("config.integrations.TAB-BC",false); tab_bc = config.getBoolean("config.integrations.TAB-BC",false);
oraxen = config.getBoolean("config.integrations.Oraxen",false); oraxen = config.getBoolean("config.integrations.Oraxen",false);
trChat = config.getBoolean("config.integrations.TrChat",false); trChat = config.getBoolean("config.integrations.TrChat",false);
trChatChannel = config.getString("config.integrations.TrChat-private-channel","Private"); trChatChannel = config.getStringList("config.integrations.TrChat-exlude-channels").toArray(new String[0]);
offsets = config.getIntegerList("config.ascii-y-offset.offset"); offsets = config.getIntegerList("config.ascii-y-offset.offset");
if(config.getBoolean("config.extract-shader",true)) { if(config.getBoolean("config.extract-shader",true)) {

View File

@@ -48,6 +48,7 @@ import net.momirealms.customnameplates.nameplates.mode.tmpackets.TeamPacketUtil;
import net.momirealms.customnameplates.nameplates.mode.tp.TeleportingTag; import net.momirealms.customnameplates.nameplates.mode.tp.TeleportingTag;
import net.momirealms.customnameplates.resource.ResourceManager; import net.momirealms.customnameplates.resource.ResourceManager;
import net.momirealms.customnameplates.utils.AdventureUtil; import net.momirealms.customnameplates.utils.AdventureUtil;
import org.bstats.bukkit.Metrics;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.plugin.java.JavaPlugin;
@@ -102,6 +103,8 @@ public final class CustomNameplates extends JavaPlugin {
this.resourceManager.generateResourcePack(); this.resourceManager.generateResourcePack();
AdventureUtil.consoleMessage("<gradient:#2E8B57:#48D1CC>[CustomNameplates]</gradient> <color:#baffd1>Plugin Enabled!"); AdventureUtil.consoleMessage("<gradient:#2E8B57:#48D1CC>[CustomNameplates]</gradient> <color:#baffd1>Plugin Enabled!");
new Metrics(this, 16649);
} }
@Override @Override

View File

@@ -29,7 +29,7 @@ import org.bukkit.scheduler.BukkitTask;
public class ActionBarTask { public class ActionBarTask {
private ActionBarConfig config; private final ActionBarConfig config;
private int timer_1; private int timer_1;
private int timer_2; private int timer_2;
private int counter; private int counter;

View File

@@ -0,0 +1,53 @@
package net.momirealms.customnameplates.api.events;
import org.bukkit.entity.Player;
import org.bukkit.event.Cancellable;
import org.bukkit.event.HandlerList;
import org.bukkit.event.player.PlayerEvent;
import org.jetbrains.annotations.NotNull;
public class BubblesEvent extends PlayerEvent implements Cancellable {
private boolean cancelled;
private String bubble;
private String text;
private static final HandlerList handlerList = new HandlerList();
public BubblesEvent(@NotNull Player who, String bubble, String text) {
super(who);
this.cancelled = false;
this.bubble = bubble;
this.text = text;
}
@Override
public boolean isCancelled() {
return cancelled;
}
@Override
public void setCancelled(boolean cancel) {
cancelled = cancel;
}
@Override
public @NotNull HandlerList getHandlers() {
return handlerList;
}
public String getBubble() {
return bubble;
}
public void setBubble(String bubble) {
this.bubble = bubble;
}
public String getText() {
return text;
}
public void setText(String text) {
this.text = text;
}
}

View File

@@ -26,10 +26,11 @@ import org.bukkit.entity.Player;
import java.util.HashMap; import java.util.HashMap;
import java.util.Optional; import java.util.Optional;
import java.util.UUID; import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap;
public class DataManager { public class DataManager {
private final HashMap<UUID, PlayerData> cache = new HashMap<>(); private final ConcurrentHashMap<UUID, PlayerData> cache = new ConcurrentHashMap<>();
public PlayerData getOrEmpty(Player player) { public PlayerData getOrEmpty(Player player) {
if (cache.get(player.getUniqueId()) == null) { if (cache.get(player.getUniqueId()) == null) {
@@ -107,7 +108,7 @@ public class DataManager {
else return false; else return false;
} }
public HashMap<UUID, PlayerData> getCache() { public ConcurrentHashMap<UUID, PlayerData> getCache() {
return cache; return cache;
} }
} }

View File

@@ -27,6 +27,7 @@ import org.jetbrains.annotations.Nullable;
import java.sql.*; import java.sql.*;
import java.util.HashMap; import java.util.HashMap;
import java.util.UUID; import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap;
public class SqlHandler { public class SqlHandler {
@@ -63,8 +64,9 @@ public class SqlHandler {
} }
public static void createTable() { public static void createTable() {
Connection connection = database.getConnectionAndCheck();
try { try {
Connection connection = database.getConnectionAndCheck();
Statement statement = connection.createStatement(); Statement statement = connection.createStatement();
if (statement == null) { if (statement == null) {
return; return;
@@ -116,7 +118,8 @@ public class SqlHandler {
ResultSet rs = statement.executeQuery(); ResultSet rs = statement.executeQuery();
if (rs.next()) { if (rs.next()) {
playerData = new PlayerData(rs.getString(2), rs.getString(3)); playerData = new PlayerData(rs.getString(2), rs.getString(3));
}else { }
else {
sql = "INSERT INTO " + ConfigManager.Database.tableName + "(player,equipped,bubble) values(?,?,?)"; sql = "INSERT INTO " + ConfigManager.Database.tableName + "(player,equipped,bubble) values(?,?,?)";
statement = connection.prepareStatement(sql); statement = connection.prepareStatement(sql);
statement.setString(1, uuid.toString()); statement.setString(1, uuid.toString());
@@ -151,7 +154,7 @@ public class SqlHandler {
public static void saveAll() { public static void saveAll() {
Connection connection = database.getConnectionAndCheck(); Connection connection = database.getConnectionAndCheck();
HashMap<UUID, PlayerData> data = CustomNameplates.instance.getDataManager().getCache(); ConcurrentHashMap<UUID, PlayerData> data = CustomNameplates.instance.getDataManager().getCache();
Bukkit.getOnlinePlayers().forEach(player -> { Bukkit.getOnlinePlayers().forEach(player -> {
try { try {
PlayerData playerData = data.get(player.getUniqueId()); PlayerData playerData = data.get(player.getUniqueId());

View File

@@ -24,6 +24,7 @@ import net.kyori.adventure.text.minimessage.MiniMessage;
import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer; import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
import net.momirealms.customnameplates.ConfigManager; import net.momirealms.customnameplates.ConfigManager;
import net.momirealms.customnameplates.CustomNameplates; import net.momirealms.customnameplates.CustomNameplates;
import net.momirealms.customnameplates.api.events.BubblesEvent;
import net.momirealms.customnameplates.data.PlayerData; import net.momirealms.customnameplates.data.PlayerData;
import net.momirealms.customnameplates.nameplates.ArmorStandManager; import net.momirealms.customnameplates.nameplates.ArmorStandManager;
import net.momirealms.customnameplates.nameplates.BubbleConfig; import net.momirealms.customnameplates.nameplates.BubbleConfig;
@@ -33,6 +34,7 @@ import net.momirealms.customnameplates.nameplates.mode.EntityTag;
import net.momirealms.customnameplates.nameplates.mode.EventListener; import net.momirealms.customnameplates.nameplates.mode.EventListener;
import net.momirealms.customnameplates.resource.ResourceManager; import net.momirealms.customnameplates.resource.ResourceManager;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.GameMode;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.HandlerList; import org.bukkit.event.HandlerList;
@@ -129,13 +131,23 @@ public class ChatBubblesManager extends EntityTag {
public void onChat(Player player, String text) { public void onChat(Player player, String text) {
if (player.getGameMode() == GameMode.SPECTATOR) return;
if (!player.hasPermission("bubbles.use")) return;
long time = System.currentTimeMillis(); long time = System.currentTimeMillis();
if (time - (coolDown.getOrDefault(player, time - ConfigManager.Bubbles.coolDown)) < ConfigManager.Bubbles.coolDown) return; if (time - (coolDown.getOrDefault(player, time - ConfigManager.Bubbles.coolDown)) < ConfigManager.Bubbles.coolDown) return;
coolDown.put(player, time); coolDown.put(player, time);
PlayerData playerData = CustomNameplates.instance.getDataManager().getOrEmpty(player); PlayerData playerData = CustomNameplates.instance.getDataManager().getOrEmpty(player);
String bubbles = playerData.getBubbles(); String bubbles = playerData.getBubbles();
BubbleConfig bubbleConfig = ResourceManager.BUBBLES.get(bubbles);
BubblesEvent bubblesEvent = new BubblesEvent(player, bubbles, text);
Bukkit.getPluginManager().callEvent(bubblesEvent);
if (bubblesEvent.isCancelled()) {
return;
}
text = bubblesEvent.getText();
BubbleConfig bubbleConfig = ResourceManager.BUBBLES.get(bubblesEvent.getBubble());
WrappedChatComponent wrappedChatComponent; WrappedChatComponent wrappedChatComponent;
if (CustomNameplates.instance.getImageParser() != null) { if (CustomNameplates.instance.getImageParser() != null) {
text = CustomNameplates.instance.getImageParser().parse(player, text); text = CustomNameplates.instance.getImageParser().parse(player, text);

View File

@@ -22,6 +22,7 @@ import org.bukkit.ChatColor;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
import org.bukkit.event.player.AsyncPlayerChatEvent; import org.bukkit.event.player.AsyncPlayerChatEvent;
import org.bukkit.event.player.PlayerChatEvent;
public class ChatListener implements Listener { public class ChatListener implements Listener {
@@ -32,7 +33,7 @@ public class ChatListener implements Listener {
} }
@EventHandler @EventHandler
public void onChat(AsyncPlayerChatEvent event) { public void onChat(PlayerChatEvent event) {
if (!event.isCancelled()) { if (!event.isCancelled()) {
chatBubblesManager.onChat(event.getPlayer(), MiniMessage.miniMessage().stripTags(ChatColor.stripColor(event.getMessage()))); chatBubblesManager.onChat(event.getPlayer(), MiniMessage.miniMessage().stripTags(ChatColor.stripColor(event.getMessage())));
} }

View File

@@ -29,7 +29,9 @@ public record TrChatListener(
public void onTrChat(TrChatEvent event) { public void onTrChat(TrChatEvent event) {
if (event.isCancelled()) return; if (event.isCancelled()) return;
if (!event.getForward()) return; if (!event.getForward()) return;
if (event.getChannel().getId().equals(ConfigManager.Main.trChatChannel)) return; for (String channel : ConfigManager.Main.trChatChannel) {
if (event.getChannel().getId().equals(channel)) return;
}
chatBubblesManager.onChat(event.getSession().getPlayer(), event.getMessage()); chatBubblesManager.onChat(event.getSession().getPlayer(), event.getMessage());
} }
} }

View File

@@ -1,5 +1,5 @@
# Do not change # Do not change
config-version: '11' config-version: '12'
config: config:
# Language # Language
@@ -24,7 +24,10 @@ config:
TAB-BC: false TAB-BC: false
# TrChat # TrChat
TrChat: false TrChat: false
TrChat-private-channel: 'Private' # Prevent players from seeing chatting bubble texts in specified channels
TrChat-exlude-channels:
- 'Private'
- 'Staff'
# Your namespace # Your namespace
# If you don't know how font works, don't change this # If you don't know how font works, don't change this

View File

@@ -59,6 +59,7 @@ permissions:
bubbles.forceequip: true bubbles.forceequip: true
bubbles.forceunequip: true bubbles.forceunequip: true
bubbles.list: true bubbles.list: true
bubbles.use: true
bubbles.help: bubbles.help:
default: op default: op
@@ -71,4 +72,6 @@ permissions:
bubbles.forceequip: bubbles.forceequip:
default: op default: op
bubbles.forceunequip: bubbles.forceunequip:
default: op default: op
bubbles.use:
default: true