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:
XiaoMoMi
2024-11-28 18:49:59 +08:00
parent 20d3919c6b
commit cd1a0bffb6
11 changed files with 143 additions and 10 deletions

View File

@@ -18,7 +18,6 @@
package net.momirealms.customnameplates.api; package net.momirealms.customnameplates.api;
import io.netty.channel.Channel; import io.netty.channel.Channel;
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
import it.unimi.dsi.fastutil.objects.ObjectArrayList; import it.unimi.dsi.fastutil.objects.ObjectArrayList;
import it.unimi.dsi.fastutil.objects.ObjectOpenHashSet; import it.unimi.dsi.fastutil.objects.ObjectOpenHashSet;
import net.momirealms.customnameplates.api.feature.Feature; import net.momirealms.customnameplates.api.feature.Feature;
@@ -56,13 +55,11 @@ public abstract class AbstractCNPlayer implements CNPlayer {
private final TeamView teamView = new TeamView(); private final TeamView teamView = new TeamView();
// these two maps can be visited by other threads // these maps might be visited by other threads through PlaceholderAPI
private final Map<Integer, TimeStampData<String>> cachedValues = new ConcurrentHashMap<>(128); private final Map<Integer, TimeStampData<String>> cachedValues = new ConcurrentHashMap<>(128);
private final Map<Integer, WeakHashMap<CNPlayer, TimeStampData<String>>> cachedRelationalValues = new ConcurrentHashMap<>(128); private final Map<Integer, WeakHashMap<CNPlayer, TimeStampData<String>>> cachedRelationalValues = new ConcurrentHashMap<>(128);
private final Map<Integer, TimeStampData<Boolean>> cachedRequirements = new ConcurrentHashMap<>(32);
// these two maps can only be modified in the same thread private final Map<Integer, WeakHashMap<CNPlayer, TimeStampData<Boolean>>> cachedRelationalRequirements = new ConcurrentHashMap<>(32);
private final Map<Integer, TimeStampData<Boolean>> cachedRequirements = new Int2ObjectOpenHashMap<>(32);
private final Map<Integer, WeakHashMap<CNPlayer, TimeStampData<Boolean>>> cachedRelationalRequirements = new Int2ObjectOpenHashMap<>(32);
private final Set<Feature> activeFeatures = new CopyOnWriteArraySet<>(); private final Set<Feature> activeFeatures = new CopyOnWriteArraySet<>();
private final Map<Placeholder, Set<Feature>> placeholder2Features = new ConcurrentHashMap<>(); private final Map<Placeholder, Set<Feature>> placeholder2Features = new ConcurrentHashMap<>();

View File

@@ -112,6 +112,7 @@ public abstract class ConfigManager implements ConfigLoader, Reloadable {
protected boolean chatAdvanced; protected boolean chatAdvanced;
protected boolean chatEss; protected boolean chatEss;
protected boolean chatChatControlRed; protected boolean chatChatControlRed;
protected boolean chatChatty;
protected String configVersion; protected String configVersion;
@@ -191,6 +192,7 @@ public abstract class ConfigManager implements ConfigLoader, Reloadable {
chatTR = config.getBoolean("integrations.chat.TrChat", false); chatTR = config.getBoolean("integrations.chat.TrChat", false);
chatVenture = config.getBoolean("integrations.chat.VentureChat", false); chatVenture = config.getBoolean("integrations.chat.VentureChat", false);
chatChatControlRed = config.getBoolean("integrations.chat.ChatControlRed", false); chatChatControlRed = config.getBoolean("integrations.chat.ChatControlRed", false);
chatChatty = config.getBoolean("integrations.chat.Chatty", false);
// Packs // Packs
generateOnStart = !config.getBoolean("resource-pack.disable-generation-on-start", false); generateOnStart = !config.getBoolean("resource-pack.disable-generation-on-start", false);
@@ -417,6 +419,10 @@ public abstract class ConfigManager implements ConfigLoader, Reloadable {
return instance.chatChatControlRed; return instance.chatChatControlRed;
} }
public static boolean chatChatty() {
return instance.chatChatty;
}
@Override @Override
public YamlDocument loadConfig(String filePath) { public YamlDocument loadConfig(String filePath) {
return loadConfig(filePath, '.'); return loadConfig(filePath, '.');

View File

@@ -128,6 +128,13 @@ public abstract class AbstractRequirementManager implements RequirementManager {
String regex = section.getString("regex", ""); String regex = section.getString("regex", "");
return new RegexRequirement(interval, dynamicText1, regex); return new RegexRequirement(interval, dynamicText1, regex);
}, "regex"); }, "regex");
this.registerRequirement((args, interval) -> {
Section section = ConfigUtils.safeCast(args, Section.class);
if (section == null) return Requirement.empty();
PreParsedDynamicText dynamicText1 = new PreParsedDynamicText(section.getString("papi", ""), true);
String regex = section.getString("regex", "");
return new NotRegexRequirement(interval, dynamicText1, regex);
}, "!regex");
this.registerRequirement((args, interval) -> { this.registerRequirement((args, interval) -> {
Section section = ConfigUtils.safeCast(args, Section.class); Section section = ConfigUtils.safeCast(args, Section.class);
if (section == null) return Requirement.empty(); if (section == null) return Requirement.empty();

View File

@@ -0,0 +1,37 @@
/*
* Copyright (C) <2024> <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.backend.requirement.builtin;
import net.momirealms.customnameplates.api.feature.PreParsedDynamicText;
public class NotRegexRequirement extends PlaceholderRequirement<String> {
public NotRegexRequirement(int refreshInterval, PreParsedDynamicText text, String any) {
super(refreshInterval, text, any);
}
@Override
protected boolean checkArgument(String a1, String a2) {
return !a1.matches(a2);
}
@Override
public String type() {
return "!regex";
}
}

View File

@@ -34,6 +34,7 @@ integrations:
AdvancedChat: false # Integration with AdvancedChat AdvancedChat: false # Integration with AdvancedChat
Essentials: false # Integration with Essentials chat Essentials: false # Integration with Essentials chat
ChatControlRed: false # Integration with ChatControlRed ChatControlRed: false # Integration with ChatControlRed
Chatty: false # Integration with Chatty
# Resource Pack Generation Settings: Configure resource pack generation behavior. # Resource Pack Generation Settings: Configure resource pack generation behavior.
resource-pack: resource-pack:

View File

@@ -1,6 +1,6 @@
# Project settings # Project settings
# Rule: [major update].[feature update].[bug fix] # Rule: [major update].[feature update].[bug fix]
project_version=3.0.14 project_version=3.0.15
config_version=33 config_version=33
project_group=net.momirealms project_group=net.momirealms

View File

@@ -33,6 +33,8 @@ dependencies {
compileOnly("net.william278.huskchat:huskchat-bukkit:3.0.4") compileOnly("net.william278.huskchat:huskchat-bukkit:3.0.4")
compileOnly("net.essentialsx:EssentialsX:2.20.1") compileOnly("net.essentialsx:EssentialsX:2.20.1")
compileOnly("net.essentialsx:EssentialsXChat:2.20.1") compileOnly("net.essentialsx:EssentialsXChat:2.20.1")
// compileOnly("com.github.Brikster:Chatty:v2.19.14")
compileOnly(files("libs/Chatty-3.0.0-SNAPSHOT.jar"))
// Emoji // Emoji
compileOnly("com.github.LoneDev6:api-itemsadder:3.6.3-beta-14") compileOnly("com.github.LoneDev6:api-itemsadder:3.6.3-beta-14")
compileOnly("io.th0rgal:oraxen:1.182.0") compileOnly("io.th0rgal:oraxen:1.182.0")

View File

@@ -41,9 +41,7 @@ public class ChatControlRedProvider extends AbstractChatMessageProvider implemen
@EventHandler(ignoreCancelled = true) @EventHandler(ignoreCancelled = true)
public void onChat(ChatChannelEvent event) { public void onChat(ChatChannelEvent event) {
plugin.debug(() -> { plugin.debug(() -> "ChatChannelEvent triggered");
return "ChatChannelEvent triggered";
});
final CommandSender sender = event.getSender(); final CommandSender sender = event.getSender();
if (!(sender instanceof Player player)) { if (!(sender instanceof Player player)) {
return; return;

View File

@@ -0,0 +1,82 @@
/*
* 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.bukkit.compatibility.chat;
import net.momirealms.customnameplates.api.CNPlayer;
import net.momirealms.customnameplates.api.CustomNameplates;
import net.momirealms.customnameplates.api.feature.chat.AbstractChatMessageProvider;
import net.momirealms.customnameplates.api.feature.chat.ChatManager;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.HandlerList;
import org.bukkit.event.Listener;
import ru.brikster.chatty.api.ChattyApi;
import ru.brikster.chatty.api.chat.Chat;
import ru.brikster.chatty.api.event.ChattyMessageEvent;
import java.util.Objects;
public class ChattyProvider extends AbstractChatMessageProvider implements Listener {
public ChattyProvider(CustomNameplates plugin, ChatManager manager) {
super(plugin, manager);
}
@EventHandler(ignoreCancelled = true)
public void onChat(ChattyMessageEvent event) {
final String message = event.getPlainMessage();
final Player player = event.getSender();
if (!player.isOnline()) return;
CNPlayer cnPlayer = plugin.getPlayer(player.getUniqueId());
if (cnPlayer == null) return;
plugin.getScheduler().async().execute(() -> {
manager.onChat(cnPlayer, message, event.getChat().getId());
});
}
@Override
public boolean hasJoinedChannel(CNPlayer player, String channelID) {
return true;
}
@Override
public boolean canJoinChannel(CNPlayer player, String channelID) {
Chat chat = ChattyApi.instance().getChats().get(channelID);
if (chat == null) {
return false;
}
if (!chat.isPermissionRequired()) return true;
return chat.hasReadPermission((Player) player.player());
}
@Override
public boolean isIgnoring(CNPlayer sender, CNPlayer receiver) {
return false;
}
@Override
public void register() {
Bukkit.getPluginManager().registerEvents(this, Objects.requireNonNull(Bukkit.getPluginManager().getPlugin("CustomNameplates")));
}
@Override
public void unregister() {
HandlerList.unregisterAll(this);
}
}

View File

@@ -54,6 +54,9 @@ public class BukkitChatManager extends AbstractChatManager {
} else if (ConfigManager.chatChatControlRed() && Bukkit.getPluginManager().isPluginEnabled("ChatControlRed")) { } else if (ConfigManager.chatChatControlRed() && Bukkit.getPluginManager().isPluginEnabled("ChatControlRed")) {
this.chatProvider = new ChatControlRedProvider(plugin, this); this.chatProvider = new ChatControlRedProvider(plugin, this);
plugin.getPluginLogger().info("ChatControlRed hooked!"); plugin.getPluginLogger().info("ChatControlRed hooked!");
} else if (ConfigManager.chatChatty() && Bukkit.getPluginManager().isPluginEnabled("Chatty")) {
this.chatProvider = new ChattyProvider(plugin, this);
plugin.getPluginLogger().info("Chatty hooked!");
} else { } else {
this.chatProvider = new AsyncChatProvider(plugin, this); this.chatProvider = new AsyncChatProvider(plugin, this);
} }