mirror of
https://github.com/Xiao-MoMi/Custom-Nameplates.git
synced 2025-12-31 04:36:29 +00:00
2.0.1
This commit is contained in:
@@ -18,12 +18,15 @@
|
||||
package net.momirealms.customnameplates;
|
||||
|
||||
import net.kyori.adventure.key.Key;
|
||||
import net.momirealms.customnameplates.actionbar.ActionBarConfig;
|
||||
import net.momirealms.customnameplates.bossbar.BossBarConfig;
|
||||
import net.momirealms.customnameplates.bossbar.Overlay;
|
||||
import net.momirealms.customnameplates.data.SqlHandler;
|
||||
import net.momirealms.customnameplates.font.FontOffset;
|
||||
import net.momirealms.customnameplates.font.FontWidthNormal;
|
||||
import net.momirealms.customnameplates.font.FontWidthThin;
|
||||
import net.momirealms.customnameplates.helper.Log;
|
||||
import net.momirealms.customnameplates.requirements.*;
|
||||
import net.momirealms.customnameplates.utils.AdventureUtil;
|
||||
import net.momirealms.customnameplates.objects.BackGroundText;
|
||||
import net.momirealms.customnameplates.objects.NameplateText;
|
||||
@@ -36,14 +39,12 @@ import org.bukkit.configuration.file.YamlConfiguration;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.TreeMap;
|
||||
import java.util.*;
|
||||
|
||||
public class ConfigManager {
|
||||
|
||||
public static TreeMap<String, BossBarConfig> bossBars = new TreeMap<>();
|
||||
public static HashMap<String, ActionBarConfig> actionBars = new HashMap<>();
|
||||
public static HashMap<String, BackGroundText> papiBG = new HashMap<>();
|
||||
public static HashMap<String, NameplateText> papiNP = new HashMap<>();
|
||||
public static HashMap<Character, Integer> fontWidth = new HashMap<>();
|
||||
@@ -302,25 +303,59 @@ public class ConfigManager {
|
||||
public static void loadBossBar() {
|
||||
bossBars.clear();
|
||||
YamlConfiguration config = getConfig("bossbar.yml");
|
||||
Objects.requireNonNull(config.getConfigurationSection("bossbar")).getKeys(false).forEach(key -> {
|
||||
String[] texts;
|
||||
String text = config.getString("bossbar." + key + ".text");
|
||||
if (text != null) {
|
||||
texts = new String[]{text};
|
||||
if (config.contains("bossbar")) {
|
||||
config.getConfigurationSection("bossbar").getKeys(false).forEach(key -> {
|
||||
String[] texts;
|
||||
String text = config.getString("bossbar." + key + ".text");
|
||||
if (text != null) {
|
||||
texts = new String[]{text};
|
||||
}
|
||||
else {
|
||||
List<String> strings = config.getStringList("bossbar." + key + ".dynamic-text");
|
||||
texts = strings.toArray(new String[0]);
|
||||
}
|
||||
List<Requirement> requirements = new ArrayList<>();
|
||||
if (config.contains("bossbar." + key + ".conditions")){
|
||||
config.getConfigurationSection("bossbar." + key + ".conditions").getKeys(false).forEach(requirement -> {
|
||||
switch (requirement){
|
||||
case "weather" -> requirements.add(new Weather(config.getStringList("bossbar." + key + ".conditions.weather")));
|
||||
case "ypos" -> requirements.add(new YPos(config.getStringList("bossbar." + key + ".conditions.ypos")));
|
||||
case "world" -> requirements.add(new World(config.getStringList("bossbar." + key + ".conditions.world")));
|
||||
case "biome" -> requirements.add(new Biome(config.getStringList("bossbar." + key + ".conditions.biome")));
|
||||
case "permission" -> requirements.add(new Permission(config.getString("bossbar." + key + ".conditions.permission")));
|
||||
case "time" -> requirements.add(new Time(config.getStringList("bossbar." + key + ".conditions.time")));
|
||||
case "papi-condition" -> {
|
||||
if (Main.placeholderAPI) requirements.add(new CustomPapi(config.getConfigurationSection("bossbar." + key + ".conditions.papi-condition").getValues(false)));
|
||||
else AdventureUtil.consoleMessage("<red>[CustomNameplates] You need to enable PlaceholderAPI Integration to use papi condition!</red>");
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
BossBarConfig bossBarConfig = new BossBarConfig(
|
||||
texts,
|
||||
Overlay.valueOf(config.getString("bossbar."+key+".overlay","progress").toUpperCase()),
|
||||
BarColor.valueOf(config.getString("bossbar."+key+".color","white").toUpperCase()),
|
||||
config.getInt("bossbar." + key + ".refresh-rate", 15) - 1,
|
||||
config.getInt("bossbar." + key + ".switch-interval", 5) * 20,
|
||||
requirements
|
||||
);
|
||||
bossBars.put(key, bossBarConfig);
|
||||
});
|
||||
AdventureUtil.consoleMessage("[CustomNameplates] Loaded <green>" + bossBars.size() + " <gray>bossbars");
|
||||
}
|
||||
else {
|
||||
File file = new File(CustomNameplates.instance.getDataFolder(), "bossbar.yml");
|
||||
File backFile = new File(CustomNameplates.instance.getDataFolder(), "bossbar_backup.yml");
|
||||
try {
|
||||
config.save(backFile);
|
||||
}
|
||||
else {
|
||||
List<String> strings = config.getStringList("bossbar." + key + ".dynamic-text");
|
||||
texts = strings.toArray(new String[0]);
|
||||
catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
BossBarConfig bossBarConfig = new BossBarConfig(
|
||||
texts,
|
||||
Overlay.valueOf(config.getString("bossbar."+key+".overlay","progress").toUpperCase()),
|
||||
BarColor.valueOf(config.getString("bossbar."+key+".color","white").toUpperCase()),
|
||||
config.getInt("bossbar." + key + ".refresh-rate") - 1
|
||||
);
|
||||
bossBarConfig.setInternal(config.getInt("bossbar." + key + ".switch-interval", 5) * 20);
|
||||
bossBars.put(key, bossBarConfig);
|
||||
});
|
||||
if (file.delete()) {
|
||||
loadBossBar();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -341,13 +376,60 @@ public class ConfigManager {
|
||||
/**
|
||||
* 加载actionbar模块相关功能
|
||||
*/
|
||||
public static class ActionbarConfig {
|
||||
public static int rate;
|
||||
public static String text;
|
||||
public static void load() {
|
||||
YamlConfiguration config = getConfig("actionbar.yml");
|
||||
rate = config.getInt("refresh-rate") - 1;
|
||||
text = config.getString("text");
|
||||
|
||||
public static void loadActionBar() {
|
||||
actionBars.clear();
|
||||
YamlConfiguration config = getConfig("actionbar.yml");
|
||||
if (config.contains("actionbar")) {
|
||||
for (String key : config.getConfigurationSection("actionbar").getKeys(false)) {
|
||||
String[] texts;
|
||||
String text = config.getString("actionbar." + key + ".text");
|
||||
if (text != null) {
|
||||
texts = new String[]{text};
|
||||
}
|
||||
else {
|
||||
List<String> strings = config.getStringList("actionbar." + key + ".dynamic-text");
|
||||
texts = strings.toArray(new String[0]);
|
||||
}
|
||||
List<Requirement> requirements = new ArrayList<>();
|
||||
if (config.contains("actionbar." + key + ".conditions")){
|
||||
config.getConfigurationSection("actionbar." + key + ".conditions").getKeys(false).forEach(requirement -> {
|
||||
switch (requirement){
|
||||
case "weather" -> requirements.add(new Weather(config.getStringList("actionbar." + key + ".conditions.weather")));
|
||||
case "ypos" -> requirements.add(new YPos(config.getStringList("actionbar." + key + ".conditions.ypos")));
|
||||
case "world" -> requirements.add(new World(config.getStringList("actionbar." + key + ".conditions.world")));
|
||||
case "biome" -> requirements.add(new Biome(config.getStringList("actionbar." + key + ".conditions.biome")));
|
||||
case "permission" -> requirements.add(new Permission(config.getString("actionbar." + key + ".conditions.permission")));
|
||||
case "time" -> requirements.add(new Time(config.getStringList("actionbar." + key + ".conditions.time")));
|
||||
case "papi-condition" -> {
|
||||
if (Main.placeholderAPI) requirements.add(new CustomPapi(config.getConfigurationSection("actionbar." + key + ".conditions.papi-condition").getValues(false)));
|
||||
else AdventureUtil.consoleMessage("<red>[CustomNameplates] You need to enable PlaceholderAPI Integration to use papi condition!</red>");
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
ActionBarConfig actionBarConfig = new ActionBarConfig(
|
||||
config.getInt("actionbar." + key + ".refresh-rate", 5) - 1,
|
||||
config.getInt("actionbar." + key + ".switch-interval", 15) * 20,
|
||||
texts,
|
||||
requirements
|
||||
);
|
||||
actionBars.put(key, actionBarConfig);
|
||||
}
|
||||
AdventureUtil.consoleMessage("[CustomNameplates] Loaded <green>" + actionBars.size() + " <gray>actionbars");
|
||||
}
|
||||
else {
|
||||
File file = new File(CustomNameplates.instance.getDataFolder(), "actionbar.yml");
|
||||
if (file.delete()) {
|
||||
loadActionBar();
|
||||
}
|
||||
File backFile = new File(CustomNameplates.instance.getDataFolder(), "actionbar_backup.yml");
|
||||
try {
|
||||
config.save(backFile);
|
||||
}
|
||||
catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -384,7 +466,14 @@ public class ConfigManager {
|
||||
public static void loadWidth() {
|
||||
fontWidth.clear();
|
||||
YamlConfiguration config = getConfig("char-width.yml");
|
||||
config.getConfigurationSection("").getKeys(false).forEach(key -> fontWidth.put(key.charAt(0), config.getInt(key)));
|
||||
for (String key : config.getKeys(false)) {
|
||||
if (key.length() == 1) {
|
||||
fontWidth.put(key.charAt(0), config.getInt(key));
|
||||
}
|
||||
else {
|
||||
AdventureUtil.consoleMessage("<red>[CustomNameplates] " + key + " in custom char-width.yml is in wrong format or not supported");
|
||||
}
|
||||
}
|
||||
AdventureUtil.consoleMessage("[CustomNameplates] Loaded <green>" + fontWidth.size() + " <gray>custom char-width");
|
||||
if (Main.thin_font)
|
||||
for (int i = 0; i < FontWidthThin.values().length; i++)
|
||||
|
||||
@@ -176,7 +176,7 @@ public final class CustomNameplates extends JavaPlugin {
|
||||
}
|
||||
|
||||
if (ConfigManager.Module.actionbar){
|
||||
ConfigManager.ActionbarConfig.load();
|
||||
ConfigManager.loadActionBar();
|
||||
if (actionBarManager != null) {
|
||||
this.actionBarManager.unload();
|
||||
this.actionBarManager.load();
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
package net.momirealms.customnameplates.actionbar;
|
||||
|
||||
import net.momirealms.customnameplates.requirements.Requirement;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class ActionBarConfig {
|
||||
|
||||
private final int rate;
|
||||
private final int interval;
|
||||
private final String[] text;
|
||||
private final List<Requirement> conditions;
|
||||
|
||||
public ActionBarConfig(int rate, int interval, String[] text, List<Requirement> conditions) {
|
||||
this.rate = rate;
|
||||
this.text = text;
|
||||
this.conditions = conditions;
|
||||
this.interval = interval;
|
||||
}
|
||||
|
||||
public int getRate() {
|
||||
return rate;
|
||||
}
|
||||
|
||||
public String[] getText() {
|
||||
return text;
|
||||
}
|
||||
|
||||
public List<Requirement> getConditions() {
|
||||
return conditions;
|
||||
}
|
||||
|
||||
public int getInterval() {
|
||||
return interval;
|
||||
}
|
||||
}
|
||||
@@ -18,21 +18,13 @@
|
||||
package net.momirealms.customnameplates.actionbar;
|
||||
|
||||
import net.momirealms.customnameplates.ConfigManager;
|
||||
import net.momirealms.customnameplates.CustomNameplates;
|
||||
import net.momirealms.customnameplates.Function;
|
||||
import net.momirealms.customnameplates.hook.PlaceholderManager;
|
||||
import net.momirealms.customnameplates.utils.AdventureUtil;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
import org.bukkit.scheduler.BukkitTask;
|
||||
|
||||
import java.util.HashSet;
|
||||
|
||||
public class ActionBarManager extends Function {
|
||||
|
||||
private BukkitTask bukkitTask;
|
||||
|
||||
// private ActionBarPacketsListener actionBarPacketsListener;
|
||||
|
||||
private int timer;
|
||||
private HashSet<ActionBarTask> tasks = new HashSet<>();
|
||||
|
||||
public ActionBarManager(String name) {
|
||||
super(name);
|
||||
@@ -40,29 +32,16 @@ public class ActionBarManager extends Function {
|
||||
|
||||
@Override
|
||||
public void load() {
|
||||
|
||||
// this.actionBarPacketsListener = new ActionBarPacketsListener(this);
|
||||
// CustomNameplates.protocolManager.addPacketListener(actionBarPacketsListener);
|
||||
|
||||
PlaceholderManager placeholderManager = CustomNameplates.instance.getPlaceholderManager();
|
||||
|
||||
this.bukkitTask = new BukkitRunnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (timer < ConfigManager.ActionbarConfig.rate){
|
||||
timer++;
|
||||
}
|
||||
else {
|
||||
Bukkit.getOnlinePlayers().forEach(player -> AdventureUtil.playerActionbar(player, ConfigManager.Main.placeholderAPI ? placeholderManager.parsePlaceholders(player, ConfigManager.ActionbarConfig.text) : ConfigManager.ActionbarConfig.text));
|
||||
timer = 0;
|
||||
}
|
||||
}
|
||||
}.runTaskTimerAsynchronously(CustomNameplates.instance, 1, 1);
|
||||
for (ActionBarConfig config : ConfigManager.actionBars.values()) {
|
||||
tasks.add(new ActionBarTask(config));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unload() {
|
||||
// CustomNameplates.protocolManager.removePacketListener(actionBarPacketsListener);
|
||||
this.bukkitTask.cancel();
|
||||
for (ActionBarTask task : tasks) {
|
||||
task.stop();
|
||||
}
|
||||
tasks.clear();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,43 +0,0 @@
|
||||
package net.momirealms.customnameplates.actionbar;
|
||||
|
||||
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.WrappedChatComponent;
|
||||
import com.google.gson.*;
|
||||
import me.clip.placeholderapi.PlaceholderAPI;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||
import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
|
||||
import net.momirealms.customnameplates.ConfigManager;
|
||||
import net.momirealms.customnameplates.CustomNameplates;
|
||||
import net.momirealms.customnameplates.font.FontOffset;
|
||||
import net.momirealms.customnameplates.font.FontUtil;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public class ActionBarPacketsListener extends PacketAdapter {
|
||||
|
||||
private final ActionBarManager manager;
|
||||
|
||||
public ActionBarPacketsListener(ActionBarManager manager) {
|
||||
super(CustomNameplates.instance, ListenerPriority.HIGHEST, PacketType.Play.Server.SET_ACTION_BAR_TEXT);
|
||||
this.manager = manager;
|
||||
}
|
||||
|
||||
public void onPacketSending(PacketEvent event) {
|
||||
// PacketContainer packet = event.getPacket();
|
||||
// WrappedChatComponent chatComponent = packet.getChatComponents().read(0);
|
||||
// String json = chatComponent.getJson();
|
||||
// JsonElement jsonElement = new JsonParser().parse(json);
|
||||
// StringBuilder sb = new StringBuilder();
|
||||
// getJsonText(jsonElement, sb);
|
||||
// int width = FontUtil.getTotalWidth(sb + MiniMessage.miniMessage().stripTags(PlaceholderAPI.setPlaceholders(event.getPlayer(),ConfigManager.ActionbarConfig.text)));
|
||||
// String neg = FontOffset.getShortestNegChars(width/2);
|
||||
// Component raw = GsonComponentSerializer.gson().deserialize(json).append(Component.text(neg).font(ConfigManager.Main.key)).append(MiniMessage.miniMessage().deserialize(PlaceholderAPI.setPlaceholders(event.getPlayer(),ConfigManager.ActionbarConfig.text))).append(Component.text(neg).font(ConfigManager.Main.key));
|
||||
// WrappedChatComponent chatComponent1 = WrappedChatComponent.fromJson(GsonComponentSerializer.gson().serialize(raw));
|
||||
// packet.getChatComponents().write(0, chatComponent1);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,77 @@
|
||||
package net.momirealms.customnameplates.actionbar;
|
||||
|
||||
import net.momirealms.customnameplates.ConfigManager;
|
||||
import net.momirealms.customnameplates.CustomNameplates;
|
||||
import net.momirealms.customnameplates.requirements.PlayerCondition;
|
||||
import net.momirealms.customnameplates.requirements.Requirement;
|
||||
import net.momirealms.customnameplates.utils.AdventureUtil;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
import org.bukkit.scheduler.BukkitTask;
|
||||
|
||||
public class ActionBarTask {
|
||||
|
||||
private ActionBarConfig config;
|
||||
private int timer_1;
|
||||
private int timer_2;
|
||||
private int counter;
|
||||
private String text;
|
||||
private final int size;
|
||||
private BukkitTask task;
|
||||
|
||||
public ActionBarTask(ActionBarConfig config) {
|
||||
this.config = config;
|
||||
size = config.getText().length;
|
||||
text = config.getText()[0];
|
||||
start();
|
||||
}
|
||||
|
||||
public void setText(int position) {
|
||||
this.text = config.getText()[position];
|
||||
}
|
||||
|
||||
private void start() {
|
||||
|
||||
this.task = new BukkitRunnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (size != 1) {
|
||||
timer_2++;
|
||||
if (timer_2 > config.getInterval()) {
|
||||
timer_2 = 0;
|
||||
counter++;
|
||||
if (counter == size) {
|
||||
counter = 0;
|
||||
}
|
||||
setText(counter);
|
||||
}
|
||||
}
|
||||
if (timer_1 < config.getRate()){
|
||||
timer_1++;
|
||||
}
|
||||
else {
|
||||
outer:
|
||||
for (Player player : Bukkit.getOnlinePlayers()) {
|
||||
|
||||
PlayerCondition condition = new PlayerCondition(player.getLocation(), player);
|
||||
|
||||
for (Requirement requirement : config.getConditions()) {
|
||||
if (!requirement.isConditionMet(condition)) {
|
||||
continue outer;
|
||||
}
|
||||
}
|
||||
|
||||
AdventureUtil.playerActionbar(player, ConfigManager.Main.placeholderAPI ? CustomNameplates.instance.getPlaceholderManager().parsePlaceholders(player, text) : text);
|
||||
}
|
||||
}
|
||||
}
|
||||
}.runTaskTimerAsynchronously(CustomNameplates.instance, 1, 1);
|
||||
}
|
||||
|
||||
public void stop() {
|
||||
if (this.task != null) {
|
||||
task.cancel();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -17,62 +17,51 @@
|
||||
|
||||
package net.momirealms.customnameplates.bossbar;
|
||||
|
||||
import net.momirealms.customnameplates.requirements.Requirement;
|
||||
import org.bukkit.boss.BarColor;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class BossBarConfig {
|
||||
|
||||
private String[] text;
|
||||
private int internal;
|
||||
private Overlay overlay;
|
||||
private BarColor color;
|
||||
private int rate;
|
||||
private final String[] text;
|
||||
private final int interval;
|
||||
private final Overlay overlay;
|
||||
private final BarColor color;
|
||||
private final int rate;
|
||||
private final List<Requirement> conditions;
|
||||
|
||||
public BossBarConfig(String[] text, Overlay overlay, BarColor color, int rate) {
|
||||
public BossBarConfig(String[] text, Overlay overlay, BarColor color, int rate, int interval, @NotNull List<Requirement> conditions) {
|
||||
this.text = text;
|
||||
this.overlay = overlay;
|
||||
this.color = color;
|
||||
this.rate = rate;
|
||||
this.interval = interval;
|
||||
this.conditions = conditions;
|
||||
}
|
||||
|
||||
public String[] getText() {
|
||||
return text;
|
||||
}
|
||||
|
||||
public void setText(String[] text) {
|
||||
this.text = text;
|
||||
}
|
||||
|
||||
public int getInternal() {
|
||||
return internal;
|
||||
}
|
||||
|
||||
public void setInternal(int internal) {
|
||||
this.internal = internal;
|
||||
public int getInterval() {
|
||||
return interval;
|
||||
}
|
||||
|
||||
public Overlay getOverlay() {
|
||||
return overlay;
|
||||
}
|
||||
|
||||
public void setOverlay(Overlay overlay) {
|
||||
this.overlay = overlay;
|
||||
}
|
||||
|
||||
public BarColor getColor() {
|
||||
return color;
|
||||
}
|
||||
|
||||
public void setColor(BarColor color) {
|
||||
this.color = color;
|
||||
}
|
||||
|
||||
public int getRate() {
|
||||
return rate;
|
||||
}
|
||||
|
||||
public void setRate(int rate) {
|
||||
this.rate = rate;
|
||||
public List<Requirement> getConditions() {
|
||||
return conditions;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -41,11 +41,14 @@ public class Sender {
|
||||
private int timer_1;
|
||||
private int timer_2;
|
||||
private int counter;
|
||||
private final int size;
|
||||
private final TextCache[] texts;
|
||||
private TextCache text;
|
||||
private final BukkitTask bukkitTask;
|
||||
private BukkitTask bukkitTask;
|
||||
private final UUID uuid;
|
||||
private boolean force;
|
||||
private final BossBarConfig config;
|
||||
private boolean isShown;
|
||||
|
||||
public void setText(int position) {
|
||||
this.text = texts[position];
|
||||
@@ -54,7 +57,7 @@ public class Sender {
|
||||
|
||||
public Sender(Player player, BossBarConfig config){
|
||||
String[] str = config.getText();
|
||||
int size = str.length;
|
||||
this.size = str.length;
|
||||
texts = new TextCache[str.length];
|
||||
for (int i = 0; i < str.length; i++) {
|
||||
texts[i] = new TextCache(player, str[i]);
|
||||
@@ -62,58 +65,55 @@ public class Sender {
|
||||
text = texts[0];
|
||||
this.player = player;
|
||||
this.uuid = UUID.randomUUID();
|
||||
|
||||
show(config);
|
||||
|
||||
this.bukkitTask = new BukkitRunnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (size != 1) {
|
||||
timer_2++;
|
||||
if (timer_2 > config.getInternal()) {
|
||||
timer_2 = 0;
|
||||
counter++;
|
||||
if (counter == size) {
|
||||
counter = 0;
|
||||
}
|
||||
setText(counter);
|
||||
}
|
||||
}
|
||||
if (timer_1 < config.getRate()){
|
||||
timer_1++;
|
||||
}
|
||||
else {
|
||||
timer_1 = 0;
|
||||
if (text.update() || force) {
|
||||
force = false;
|
||||
PacketContainer packet = new PacketContainer(PacketType.Play.Server.BOSS);
|
||||
packet.getModifier().write(0, uuid);
|
||||
InternalStructure internalStructure = packet.getStructures().read(1);
|
||||
internalStructure.getChatComponents().write(0, WrappedChatComponent.fromJson(GsonComponentSerializer.gson().serialize(MiniMessage.miniMessage().deserialize(text.getLatestValue()))));
|
||||
internalStructure.getFloat().write(0,1F);
|
||||
internalStructure.getEnumModifier(BarColor.class, 2).write(0, config.getColor());
|
||||
internalStructure.getEnumModifier(Overlay.class, 3).write(0, config.getOverlay());
|
||||
internalStructure.getModifier().write(4, false);
|
||||
internalStructure.getModifier().write(5, false);
|
||||
internalStructure.getModifier().write(6, false);
|
||||
try{
|
||||
CustomNameplates.protocolManager.sendServerPacket(player, packet);
|
||||
}catch (InvocationTargetException e){
|
||||
AdventureUtil.consoleMessage("<red>[CustomNameplates] Failed to update bossbar for " + player.getName());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}.runTaskTimerAsynchronously(CustomNameplates.instance,1,1);
|
||||
|
||||
this.config = config;
|
||||
this.isShown = false;
|
||||
}
|
||||
|
||||
private void show(BossBarConfig config){
|
||||
public void show() {
|
||||
this.isShown = true;
|
||||
|
||||
try{
|
||||
CustomNameplates.protocolManager.sendServerPacket(player, getPacket());
|
||||
}catch (InvocationTargetException e){
|
||||
AdventureUtil.consoleMessage("<red>[CustomNameplates] Failed to display bossbar for " + player.getName());
|
||||
}
|
||||
|
||||
this.bukkitTask = new BukkitRunnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (size != 1) {
|
||||
timer_2++;
|
||||
if (timer_2 > config.getInterval()) {
|
||||
timer_2 = 0;
|
||||
counter++;
|
||||
if (counter == size) {
|
||||
counter = 0;
|
||||
}
|
||||
setText(counter);
|
||||
}
|
||||
}
|
||||
if (timer_1 < config.getRate()){
|
||||
timer_1++;
|
||||
}
|
||||
else {
|
||||
timer_1 = 0;
|
||||
if (text.update() || force) {
|
||||
force = false;
|
||||
try{
|
||||
CustomNameplates.protocolManager.sendServerPacket(player, getPacket());
|
||||
}
|
||||
catch (InvocationTargetException e){
|
||||
AdventureUtil.consoleMessage("<red>[CustomNameplates] Failed to update bossbar for " + player.getName());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}.runTaskTimerAsynchronously(CustomNameplates.instance,1,1);
|
||||
}
|
||||
|
||||
private PacketContainer getPacket() {
|
||||
PacketContainer packet = new PacketContainer(PacketType.Play.Server.BOSS);
|
||||
|
||||
packet.getModifier().write(0, uuid);
|
||||
|
||||
InternalStructure internalStructure = packet.getStructures().read(1);
|
||||
internalStructure.getChatComponents().write(0, WrappedChatComponent.fromJson(GsonComponentSerializer.gson().serialize(MiniMessage.miniMessage().deserialize(text.getLatestValue()))));
|
||||
internalStructure.getFloat().write(0,1F);
|
||||
@@ -122,16 +122,13 @@ public class Sender {
|
||||
internalStructure.getModifier().write(4, false);
|
||||
internalStructure.getModifier().write(5, false);
|
||||
internalStructure.getModifier().write(6, false);
|
||||
try{
|
||||
CustomNameplates.protocolManager.sendServerPacket(player, packet);
|
||||
}catch (InvocationTargetException e){
|
||||
AdventureUtil.consoleMessage("<red>[CustomNameplates] Failed to display bossbar for " + player.getName());
|
||||
}
|
||||
return packet;
|
||||
}
|
||||
|
||||
public void hide() {
|
||||
remove();
|
||||
bukkitTask.cancel();
|
||||
this.isShown = false;
|
||||
}
|
||||
|
||||
private void remove() {
|
||||
@@ -144,4 +141,12 @@ public class Sender {
|
||||
AdventureUtil.consoleMessage("<red>[CustomNameplates] Failed to remove bossbar for " + player.getName());
|
||||
}
|
||||
}
|
||||
|
||||
public boolean getStatus() {
|
||||
return this.isShown;
|
||||
}
|
||||
|
||||
public BossBarConfig getConfig() {
|
||||
return config;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,22 +18,58 @@
|
||||
package net.momirealms.customnameplates.bossbar;
|
||||
|
||||
import net.momirealms.customnameplates.ConfigManager;
|
||||
import net.momirealms.customnameplates.CustomNameplates;
|
||||
import net.momirealms.customnameplates.requirements.PlayerCondition;
|
||||
import net.momirealms.customnameplates.requirements.Requirement;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
import org.bukkit.scheduler.BukkitTask;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class TimerTaskP {
|
||||
|
||||
private final HashSet<Sender> bossBarCache = new HashSet<>();
|
||||
private final List<Sender> bossBarCache = new ArrayList<>();
|
||||
|
||||
private final BukkitTask conditionTask;
|
||||
|
||||
public TimerTaskP(Player player){
|
||||
|
||||
for (BossBarConfig config : ConfigManager.bossBars.values()) {
|
||||
Sender sender = new Sender(player, config);
|
||||
bossBarCache.add(sender);
|
||||
}
|
||||
|
||||
this.conditionTask = new BukkitRunnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
|
||||
PlayerCondition playerCondition = new PlayerCondition(player.getLocation(), player);
|
||||
|
||||
outer:
|
||||
for (Sender sender : bossBarCache) {
|
||||
for (Requirement requirement : sender.getConfig().getConditions()) {
|
||||
if (!requirement.isConditionMet(playerCondition)) {
|
||||
if (sender.getStatus()) {
|
||||
sender.hide();
|
||||
}
|
||||
continue outer;
|
||||
}
|
||||
}
|
||||
if (!sender.getStatus()) {
|
||||
sender.show();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}.runTaskTimerAsynchronously(CustomNameplates.instance, 1, 20);
|
||||
}
|
||||
|
||||
public void stopTimer(){
|
||||
if (this.conditionTask != null) {
|
||||
this.conditionTask.cancel();
|
||||
}
|
||||
bossBarCache.forEach(Sender::hide);
|
||||
bossBarCache.clear();
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@ package net.momirealms.customnameplates.bungeecord;
|
||||
|
||||
public class BungeeConfig {
|
||||
|
||||
private Main plugin;
|
||||
private final Main plugin;
|
||||
|
||||
public BungeeConfig(Main plugin) {
|
||||
this.plugin = plugin;
|
||||
|
||||
@@ -4,6 +4,7 @@ import com.google.common.io.ByteArrayDataInput;
|
||||
import com.google.common.io.ByteArrayDataOutput;
|
||||
import com.google.common.io.ByteStreams;
|
||||
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
||||
import net.md_5.bungee.api.event.PlayerDisconnectEvent;
|
||||
import net.md_5.bungee.api.event.PluginMessageEvent;
|
||||
import net.md_5.bungee.api.plugin.Listener;
|
||||
import net.md_5.bungee.event.EventHandler;
|
||||
@@ -41,4 +42,4 @@ public class BungeeEventListener implements Listener {
|
||||
byteArrayDataOutput.writeUTF(teamName);
|
||||
proxiedPlayer.getServer().sendData("customnameplates:cnp", byteArrayDataOutput.toByteArray());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -53,11 +53,6 @@ public abstract class EntityTag extends NameplateManager {
|
||||
super.onQuit(player);
|
||||
}
|
||||
|
||||
// @Override
|
||||
// public void onRP(Player player, PlayerResourcePackStatusEvent.Status status) {
|
||||
// super.onRP(player, status);
|
||||
// }
|
||||
|
||||
public void onSneak(Player player, boolean isSneaking) {
|
||||
}
|
||||
|
||||
|
||||
@@ -36,9 +36,4 @@ public record EventListener(NameplateManager nameplateManager) implements Listen
|
||||
nameplateManager.onQuit(event.getPlayer());
|
||||
}
|
||||
|
||||
|
||||
// @EventHandler
|
||||
// public void onAccept(PlayerResourcePackStatusEvent event) {
|
||||
// nameplateManager.onRP(event.getPlayer(), event.getStatus());
|
||||
// }
|
||||
}
|
||||
@@ -71,25 +71,4 @@ public abstract class NameplateManager extends Function {
|
||||
}
|
||||
CustomNameplates.instance.getTeamManager().getTeams().remove(teamName);
|
||||
}
|
||||
|
||||
// public void onRP(Player player, PlayerResourcePackStatusEvent.Status status) {
|
||||
// if (!ConfigManager.Nameplate.show_after) return;
|
||||
// new BukkitRunnable() {
|
||||
// @Override
|
||||
// public void run() {
|
||||
// PlayerData playerData = CustomNameplates.instance.getDataManager().getCache().get(player.getUniqueId());
|
||||
// if (playerData == null) return;
|
||||
// if (status == PlayerResourcePackStatusEvent.Status.SUCCESSFULLY_LOADED) {
|
||||
// playerData.setAccepted(true);
|
||||
// SqlHandler.save(playerData, player.getUniqueId());
|
||||
// CustomNameplates.instance.getTeamPacketManager().sendUpdateToOne(player);
|
||||
// }
|
||||
// else if (status == PlayerResourcePackStatusEvent.Status.DECLINED || status == PlayerResourcePackStatusEvent.Status.FAILED_DOWNLOAD) {
|
||||
// playerData.setAccepted(false);
|
||||
// SqlHandler.save(playerData, player.getUniqueId());
|
||||
// CustomNameplates.instance.getTeamPacketManager().sendUpdateToOne(player);
|
||||
// }
|
||||
// }
|
||||
// }.runTaskAsynchronously(CustomNameplates.instance);
|
||||
// }
|
||||
}
|
||||
@@ -131,10 +131,6 @@ public class TeleportingTag extends EntityTag {
|
||||
|
||||
@Override
|
||||
public void onQuit(Player player) {
|
||||
// for (Player all : Bukkit.getOnlinePlayers()) {
|
||||
// if (getArmorStandManager(all) == null) continue;
|
||||
// getArmorStandManager(all) .unregisterPlayer(player);
|
||||
// }
|
||||
ArmorStandManager asm = armorStandManagerMap.remove(player);
|
||||
if (asm != null) {
|
||||
asm.destroy();
|
||||
|
||||
@@ -91,6 +91,7 @@ public class TextCache {
|
||||
}
|
||||
|
||||
public String getViewerText(Player viewer) {
|
||||
//还没写完
|
||||
return latestValue;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
* 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.requirements;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public record Biome(List<String> biomes) implements Requirement {
|
||||
|
||||
public List<String> getBiomes() {
|
||||
return this.biomes;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isConditionMet(PlayerCondition playerCondition) {
|
||||
String currentBiome = playerCondition.getLocation().getBlock().getBiome().getKey().toString();
|
||||
for (String biome : biomes) {
|
||||
if (currentBiome.equalsIgnoreCase(biome)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,118 @@
|
||||
package net.momirealms.customnameplates.requirements;
|
||||
|
||||
import net.momirealms.customnameplates.requirements.papi.*;
|
||||
import org.bukkit.configuration.MemorySection;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class CustomPapi implements Requirement {
|
||||
|
||||
public static HashSet<String> allPapi = new HashSet<>();
|
||||
|
||||
private PapiRequirement papiRequirement;
|
||||
|
||||
public CustomPapi(Map<String, Object> expressions){
|
||||
expressions.keySet().forEach(key -> {
|
||||
if (key.startsWith("&&")){
|
||||
List<PapiRequirement> papiRequirements = new ArrayList<>();
|
||||
if (expressions.get(key) instanceof MemorySection map2){
|
||||
addAndRequirements(papiRequirements, map2.getValues(false));
|
||||
}
|
||||
papiRequirement = new ExpressionAnd(papiRequirements);
|
||||
}
|
||||
else if (key.startsWith("||")){
|
||||
List<PapiRequirement> papiRequirements = new ArrayList<>();
|
||||
if (expressions.get(key) instanceof MemorySection map2){
|
||||
addOrRequirements(papiRequirements, map2.getValues(false));
|
||||
}
|
||||
papiRequirement = new ExpressionOr(papiRequirements);
|
||||
}
|
||||
else {
|
||||
if (expressions.get(key) instanceof MemorySection map){
|
||||
String type = map.getString("type");
|
||||
String papi = map.getString("papi");
|
||||
String value = map.getString("value");
|
||||
allPapi.add(papi);
|
||||
switch (type){
|
||||
case "==" -> papiRequirement = new PapiEquals(papi, value);
|
||||
case "!=" -> papiRequirement = new PapiNotEquals(papi, value);
|
||||
case ">=" -> papiRequirement = new PapiNoLess(papi, Double.parseDouble(value));
|
||||
case "<=" -> papiRequirement = new PapiNoLarger(papi, Double.parseDouble(value));
|
||||
case "<" -> papiRequirement = new PapiSmaller(papi, Double.parseDouble(value));
|
||||
case ">" -> papiRequirement = new PapiGreater(papi, Double.parseDouble(value));
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isConditionMet(PlayerCondition playerCondition) {
|
||||
return papiRequirement.isMet(playerCondition.getPapiMap());
|
||||
}
|
||||
|
||||
private void addAndRequirements(List<PapiRequirement> requirements, Map<String, Object> map){
|
||||
List<PapiRequirement> andRequirements = new ArrayList<>();
|
||||
map.keySet().forEach(key -> {
|
||||
if (key.startsWith("&&")){
|
||||
if (map.get(key) instanceof MemorySection map2){
|
||||
addAndRequirements(andRequirements, map2.getValues(false));
|
||||
}
|
||||
}else if (key.startsWith("||")){
|
||||
if (map.get(key) instanceof MemorySection map2){
|
||||
addOrRequirements(andRequirements, map2.getValues(false));
|
||||
}
|
||||
}else {
|
||||
if (map.get(key) instanceof MemorySection map2){
|
||||
String type = map2.getString("type");
|
||||
String papi = map2.getString("papi");
|
||||
String value = map2.getString("value");
|
||||
allPapi.add(papi);
|
||||
switch (type){
|
||||
case "==" -> andRequirements.add(new PapiEquals(papi, value));
|
||||
case "!=" -> andRequirements.add(new PapiNotEquals(papi, value));
|
||||
case ">=" -> andRequirements.add(new PapiNoLess(papi, Double.parseDouble(value)));
|
||||
case "<=" -> andRequirements.add(new PapiNoLarger(papi, Double.parseDouble(value)));
|
||||
case "<" -> andRequirements.add(new PapiSmaller(papi, Double.parseDouble(value)));
|
||||
case ">" -> andRequirements.add(new PapiGreater(papi, Double.parseDouble(value)));
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
requirements.add(new ExpressionAnd(andRequirements));
|
||||
}
|
||||
|
||||
private void addOrRequirements(List<PapiRequirement> requirements, Map<String, Object> map){
|
||||
List<PapiRequirement> orRequirements = new ArrayList<>();
|
||||
map.keySet().forEach(key -> {
|
||||
if (key.startsWith("&&")){
|
||||
if (map.get(key) instanceof MemorySection map2){
|
||||
addAndRequirements(orRequirements, map2.getValues(false));
|
||||
}
|
||||
}else if (key.startsWith("||")){
|
||||
if (map.get(key) instanceof MemorySection map2){
|
||||
addOrRequirements(orRequirements, map2.getValues(false));
|
||||
}
|
||||
}else {
|
||||
if (map.get(key) instanceof MemorySection map2){
|
||||
String type = map2.getString("type");
|
||||
String papi = map2.getString("papi");
|
||||
String value = map2.getString("value");
|
||||
allPapi.add(papi);
|
||||
switch (type){
|
||||
case "==" -> orRequirements.add(new PapiEquals(papi, value));
|
||||
case "!=" -> orRequirements.add(new PapiNotEquals(papi, value));
|
||||
case ">=" -> orRequirements.add(new PapiNoLess(papi, Double.parseDouble(value)));
|
||||
case "<=" -> orRequirements.add(new PapiNoLarger(papi, Double.parseDouble(value)));
|
||||
case "<" -> orRequirements.add(new PapiSmaller(papi, Double.parseDouble(value)));
|
||||
case ">" -> orRequirements.add(new PapiGreater(papi, Double.parseDouble(value)));
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
requirements.add(new ExpressionOr(orRequirements));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
/*
|
||||
* 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.requirements;
|
||||
|
||||
public record Permission(String permission) implements Requirement {
|
||||
|
||||
public String getPermission() {
|
||||
return this.permission;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isConditionMet(PlayerCondition playerCondition) {
|
||||
return playerCondition.getPlayer().hasPermission(permission);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
/*
|
||||
* 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.requirements;
|
||||
|
||||
import net.momirealms.customnameplates.ConfigManager;
|
||||
import net.momirealms.customnameplates.CustomNameplates;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
public class PlayerCondition {
|
||||
|
||||
private final Location location;
|
||||
private final Player player;
|
||||
private HashMap<String, String> papiMap;
|
||||
|
||||
public PlayerCondition(Location location, Player player) {
|
||||
this.location = location;
|
||||
this.player = player;
|
||||
if (ConfigManager.Main.placeholderAPI){
|
||||
this.papiMap = new HashMap<>();
|
||||
CustomPapi.allPapi.forEach(papi -> {
|
||||
this.papiMap.put(papi, CustomNameplates.instance.getPlaceholderManager().parsePlaceholders(player, papi));
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
public HashMap<String, String> getPapiMap() {
|
||||
return papiMap;
|
||||
}
|
||||
|
||||
public Location getLocation() {
|
||||
return location;
|
||||
}
|
||||
|
||||
public Player getPlayer() {
|
||||
return player;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
/*
|
||||
* 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.requirements;
|
||||
|
||||
public interface Requirement {
|
||||
boolean isConditionMet(PlayerCondition playerCondition);
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
* 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.requirements;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public record Time(List<String> times) implements Requirement{
|
||||
|
||||
public List<String> getTimes() {
|
||||
return this.times;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isConditionMet(PlayerCondition playerCondition) {
|
||||
long time = playerCondition.getLocation().getWorld().getTime();
|
||||
for (String range : times) {
|
||||
String[] timeMinMax = StringUtils.split(range, "~");
|
||||
if (time > Long.parseLong(timeMinMax[0]) && time < Long.parseLong(timeMinMax[1])) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -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.requirements;
|
||||
|
||||
import org.bukkit.World;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public record Weather(List<String> weathers) implements Requirement {
|
||||
|
||||
public List<String> getWeathers() {
|
||||
return this.weathers;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isConditionMet(PlayerCondition playerCondition) {
|
||||
World world = playerCondition.getLocation().getWorld();
|
||||
if (world != null) {
|
||||
String currentWeather;
|
||||
if (world.isThundering()) {
|
||||
currentWeather = "thunder";
|
||||
} else if (world.isClearWeather()) {
|
||||
currentWeather = "clear";
|
||||
} else {
|
||||
currentWeather = "rain";
|
||||
}
|
||||
for (String weather : weathers) {
|
||||
if (weather.equalsIgnoreCase(currentWeather)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
/*
|
||||
* 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.requirements;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public record World(List<String> worlds) implements Requirement {
|
||||
|
||||
public List<String> getWorlds() {
|
||||
return this.worlds;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isConditionMet(PlayerCondition playerCondition) {
|
||||
org.bukkit.World world = playerCondition.getLocation().getWorld();
|
||||
if (world != null) {
|
||||
return worlds.contains(world.getName());
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
* 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.requirements;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public record YPos(List<String> yPos) implements Requirement {
|
||||
|
||||
public List<String> getYPos() {
|
||||
return this.yPos;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isConditionMet(PlayerCondition playerCondition) {
|
||||
int y = (int) playerCondition.getLocation().getY();
|
||||
for (String range : yPos) {
|
||||
String[] yMinMax = StringUtils.split(range, "~");
|
||||
if (y > Integer.parseInt(yMinMax[0]) && y < Integer.parseInt(yMinMax[1])) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package net.momirealms.customnameplates.requirements.papi;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
public record ExpressionAnd(List<PapiRequirement> requirements) implements PapiRequirement{
|
||||
|
||||
@Override
|
||||
public boolean isMet(HashMap<String, String> papiMap) {
|
||||
for (PapiRequirement requirement : requirements) {
|
||||
if (!requirement.isMet(papiMap)) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package net.momirealms.customnameplates.requirements.papi;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
public record ExpressionOr(List<PapiRequirement> requirements) implements PapiRequirement{
|
||||
|
||||
@Override
|
||||
public boolean isMet(HashMap<String, String> papiMap) {
|
||||
for (PapiRequirement requirement : requirements) {
|
||||
if (requirement.isMet(papiMap)) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package net.momirealms.customnameplates.requirements.papi;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Objects;
|
||||
|
||||
public record PapiEquals(String papi, String requirement) implements PapiRequirement{
|
||||
|
||||
@Override
|
||||
public boolean isMet(HashMap<String, String> papiMap) {
|
||||
String value = papiMap.get(papi);
|
||||
return Objects.equals(value, requirement);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
package net.momirealms.customnameplates.requirements.papi;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
public record PapiGreater(String papi, double requirement) implements PapiRequirement{
|
||||
|
||||
@Override
|
||||
public boolean isMet(HashMap<String, String> papiMap) {
|
||||
double value = Double.parseDouble(papiMap.get(papi));
|
||||
return value > requirement;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
package net.momirealms.customnameplates.requirements.papi;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
public record PapiNoLarger(String papi, double requirement) implements PapiRequirement{
|
||||
|
||||
@Override
|
||||
public boolean isMet(HashMap<String, String> papiMap) {
|
||||
double value = Double.parseDouble(papiMap.get(papi));
|
||||
return value <= requirement;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
package net.momirealms.customnameplates.requirements.papi;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
public record PapiNoLess(String papi, double requirement) implements PapiRequirement{
|
||||
|
||||
@Override
|
||||
public boolean isMet(HashMap<String, String> papiMap) {
|
||||
double value = Double.parseDouble(papiMap.get(papi));
|
||||
return value >= requirement;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package net.momirealms.customnameplates.requirements.papi;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Objects;
|
||||
|
||||
public record PapiNotEquals(String papi, String requirement) implements PapiRequirement{
|
||||
|
||||
@Override
|
||||
public boolean isMet(HashMap<String, String> papiMap) {
|
||||
String value = papiMap.get(papi);
|
||||
return !Objects.equals(value, requirement);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
package net.momirealms.customnameplates.requirements.papi;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
public interface PapiRequirement {
|
||||
boolean isMet(HashMap<String, String> papiMap);
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
package net.momirealms.customnameplates.requirements.papi;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
public record PapiSmaller(String papi, double requirement) implements PapiRequirement{
|
||||
|
||||
@Override
|
||||
public boolean isMet(HashMap<String, String> papiMap) {
|
||||
double value = Double.parseDouble(papiMap.get(papi));
|
||||
return value < requirement;
|
||||
}
|
||||
}
|
||||
@@ -1,3 +1,34 @@
|
||||
# Please use MiniMessage format: https://docs.adventure.kyori.net/minimessage/format.html
|
||||
text: '<font:nameplates:default>%nameplates_bg_health%</font><font:nameplates:offset_-11><red>%player_health_rounded% Health</font> <font:nameplates:default>%nameplates_bg_food%</font><font:nameplates:offset_-11><#F0E68C>%player_food_level% Hunger</font>'
|
||||
refresh-rate: 5
|
||||
actionbar:
|
||||
high:
|
||||
text: '<font:nameplates:default>%nameplates_bg_health%</font><font:nameplates:offset_-11><green>%player_health_rounded% <white>Health</font> <font:nameplates:default>%nameplates_bg_food%</font><font:nameplates:offset_-11><#F0E68C>%player_food_level% <white>Hunger</font>'
|
||||
refresh-rate: 5
|
||||
conditions:
|
||||
papi-condition:
|
||||
condition_1:
|
||||
type: '>='
|
||||
papi: '%player_health_rounded%'
|
||||
value: 12
|
||||
mid:
|
||||
text: '<font:nameplates:default>%nameplates_bg_health%</font><font:nameplates:offset_-11><yellow>%player_health_rounded% <white>Health</font> <font:nameplates:default>%nameplates_bg_food%</font><font:nameplates:offset_-11><#F0E68C>%player_food_level% <white>Hunger</font>'
|
||||
refresh-rate: 5
|
||||
conditions:
|
||||
papi-condition:
|
||||
'&&':
|
||||
condition_1:
|
||||
type: '<'
|
||||
papi: '%player_health_rounded%'
|
||||
value: 12
|
||||
condition_2:
|
||||
type: '>='
|
||||
papi: '%player_health_rounded%'
|
||||
value: 5
|
||||
low:
|
||||
text: '<font:nameplates:default>%nameplates_bg_health%</font><font:nameplates:offset_-11><red>%player_health_rounded% <white>Health</font> <font:nameplates:default>%nameplates_bg_food%</font><font:nameplates:offset_-11><#F0E68C>%player_food_level% <white>Hunger</font>'
|
||||
refresh-rate: 5
|
||||
conditions:
|
||||
papi-condition:
|
||||
condition_1:
|
||||
type: '<'
|
||||
papi: '%player_health_rounded%'
|
||||
value: 5
|
||||
@@ -18,4 +18,58 @@ bossbar:
|
||||
text: '<font:nameplates:default><color:#FFFEFD>%nameplates_bg_text%</font><font:nameplates:offset_5>Thanks for your purchase!</font>'
|
||||
refresh-rate: 5
|
||||
color: YELLOW
|
||||
overlay: PROGRESS
|
||||
overlay: PROGRESS
|
||||
conditions:
|
||||
permission: 'nameplates.admin'
|
||||
|
||||
|
||||
# Available conditions & Examples
|
||||
#
|
||||
# #Biome
|
||||
# biome:
|
||||
# - minecraft:plains
|
||||
# - minecraft:taiga
|
||||
#
|
||||
# #Y coordinate
|
||||
# ypos:
|
||||
# - 50~100
|
||||
# - 150~200
|
||||
#
|
||||
# #World weather
|
||||
# weather:
|
||||
# - rain
|
||||
# - clear
|
||||
# - thunder
|
||||
#
|
||||
# #Player permission
|
||||
# permission: 'customfishing.rainbowfish'
|
||||
#
|
||||
# #Specified world
|
||||
# world:
|
||||
# - world
|
||||
#
|
||||
# #Game Time Range
|
||||
# time:
|
||||
# - 0~12000
|
||||
#
|
||||
# Requires PlaceholderAPI
|
||||
# Create complex condition as you want
|
||||
# "||" means one of the conditions is true, it would be true
|
||||
# "&&" means all the conditions must be true to be true
|
||||
# available types "==" "!=" ">" "<" ">=" "<="
|
||||
#
|
||||
# papi-condition:
|
||||
# '||':
|
||||
# condition_1:
|
||||
# type: '=='
|
||||
# papi: '%player_world%'
|
||||
# value: world
|
||||
# '&&':
|
||||
# condition_1:
|
||||
# type: '>='
|
||||
# papi: '%player_health%'
|
||||
# value: 5
|
||||
# condition_2:
|
||||
# type: '<'
|
||||
# papi: '%player_health%'
|
||||
# value: 15
|
||||
@@ -1,5 +1,8 @@
|
||||
# Font is processed by client
|
||||
# Server side doesn't know the width of you custom font
|
||||
# So you can tell the plugin each character's width here
|
||||
# You can use command /papi parse player %placeholder% to get the unicode in the console
|
||||
|
||||
♥: 5
|
||||
# unicode
|
||||
♥: 5
|
||||
뀈: 8
|
||||
@@ -23,6 +23,7 @@ papi:
|
||||
text: '%player_food_level% Hunger'
|
||||
background: bedrock_3
|
||||
|
||||
|
||||
#This papi will not return text with nameplate
|
||||
#It will only return the nameplate
|
||||
#So you need to do something like this in your bossbar/actionbar plugin:
|
||||
|
||||
Reference in New Issue
Block a user