mirror of
https://github.com/Xiao-MoMi/Custom-Nameplates.git
synced 2025-12-19 15:09:23 +00:00
channel mode
This commit is contained in:
@@ -18,6 +18,7 @@
|
||||
package net.momirealms.customnameplates.api.manager;
|
||||
|
||||
import net.momirealms.customnameplates.api.mechanic.bubble.Bubble;
|
||||
import net.momirealms.customnameplates.api.mechanic.bubble.provider.AbstractChatProvider;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@@ -26,6 +27,21 @@ import java.util.List;
|
||||
|
||||
public interface BubbleManager {
|
||||
|
||||
/**
|
||||
* Set a custom chat provider
|
||||
*
|
||||
* @param provider provider
|
||||
* @return success or not
|
||||
*/
|
||||
boolean setCustomChatProvider(AbstractChatProvider provider);
|
||||
|
||||
/**
|
||||
* Remove a custom chat provider
|
||||
*
|
||||
* @return success or not
|
||||
*/
|
||||
boolean removeCustomChatProvider();
|
||||
|
||||
/**
|
||||
* Register a bubble into map
|
||||
*
|
||||
@@ -118,6 +134,8 @@ public interface BubbleManager {
|
||||
*/
|
||||
String getDefaultBubble();
|
||||
|
||||
void onChat(Player player, String text, String channel);
|
||||
|
||||
/**
|
||||
* Get all the bubbles' keys
|
||||
*
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
/*
|
||||
* 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.api.mechanic.bubble;
|
||||
|
||||
public enum ChannelMode {
|
||||
|
||||
ALL,
|
||||
JOINED,
|
||||
CAN_JOIN
|
||||
}
|
||||
@@ -15,20 +15,25 @@
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package net.momirealms.customnameplates.api.mechanic.bubble.listener;
|
||||
package net.momirealms.customnameplates.api.mechanic.bubble.provider;
|
||||
|
||||
import net.momirealms.customnameplates.api.manager.BubbleManager;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.Listener;
|
||||
|
||||
public abstract class AbstractChatListener implements Listener {
|
||||
public abstract class AbstractChatProvider implements Listener {
|
||||
|
||||
protected BubbleManager chatBubblesManager;
|
||||
|
||||
public AbstractChatListener(BubbleManager chatBubblesManager) {
|
||||
public AbstractChatProvider(BubbleManager chatBubblesManager) {
|
||||
this.chatBubblesManager = chatBubblesManager;
|
||||
}
|
||||
|
||||
public abstract void register();
|
||||
|
||||
public abstract void unregister();
|
||||
|
||||
public abstract boolean hasJoinedChannel(Player player, String channelID);
|
||||
|
||||
public abstract boolean canJoinChannel(Player player, String channelID);
|
||||
}
|
||||
@@ -44,9 +44,11 @@ public class ViewerText {
|
||||
for (String placeholder : placeholders) {
|
||||
processedText = processedText.replace(placeholder, "%s");
|
||||
if (placeholder.startsWith("%viewer_")) {
|
||||
this.placeholders[i] = new ClaimedText(null, "%" + placeholder.substring("%viewer_".length()));
|
||||
this.placeholders[i] = new ClaimedText(null, "%" + placeholder.substring("%viewer_".length()), false);
|
||||
} else if (placeholder.startsWith("%rel_")) {
|
||||
this.placeholders[i] = new ClaimedText(owner, placeholder, true);
|
||||
} else {
|
||||
this.placeholders[i] = new ClaimedText(owner, placeholder);
|
||||
this.placeholders[i] = new ClaimedText(owner, placeholder, false);
|
||||
}
|
||||
i++;
|
||||
}
|
||||
@@ -109,11 +111,13 @@ public class ViewerText {
|
||||
private final String placeholder;
|
||||
private final Player owner;
|
||||
private String latestValue;
|
||||
private final boolean relational;
|
||||
|
||||
public ClaimedText(Player owner, String placeholder) {
|
||||
public ClaimedText(Player owner, String placeholder, boolean relational) {
|
||||
this.placeholder = placeholder;
|
||||
this.owner = owner;
|
||||
this.latestValue = null;
|
||||
this.relational = relational;
|
||||
this.update();
|
||||
}
|
||||
|
||||
@@ -125,7 +129,13 @@ public class ViewerText {
|
||||
public String getValue(Player viewer) {
|
||||
return Objects.requireNonNullElseGet(
|
||||
latestValue,
|
||||
() -> PlaceholderAPI.setPlaceholders(owner == null ? viewer : owner, placeholder)
|
||||
() -> {
|
||||
if (relational) {
|
||||
return PlaceholderAPI.setRelationalPlaceholders(viewer, owner, placeholder);
|
||||
} else {
|
||||
return PlaceholderAPI.setPlaceholders(owner == null ? viewer : owner, placeholder);
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user