mirror of
https://github.com/Xiao-MoMi/Custom-Nameplates.git
synced 2025-12-21 07:59:22 +00:00
fix fix fix
This commit is contained in:
@@ -56,7 +56,7 @@ public abstract class CustomNameplatesPlugin extends JavaPlugin {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* reload the plugin */
|
/* reload the plugin */
|
||||||
public abstract void reload(boolean generatePack);
|
public abstract void reload();
|
||||||
|
|
||||||
/* Get the scheduler */
|
/* Get the scheduler */
|
||||||
public Scheduler getScheduler() {
|
public Scheduler getScheduler() {
|
||||||
|
|||||||
@@ -100,4 +100,8 @@ public interface PlaceholderManager {
|
|||||||
BackGroundText getBackGroundText(String key);
|
BackGroundText getBackGroundText(String key);
|
||||||
|
|
||||||
Collection<BackGroundText> getBackGroundTexts();
|
Collection<BackGroundText> getBackGroundTexts();
|
||||||
|
|
||||||
|
VanillaHud getVanillaHud(String key);
|
||||||
|
|
||||||
|
Collection<VanillaHud> getVanillaHuds();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,29 +19,38 @@ package net.momirealms.customnameplates.api.mechanic.placeholder;
|
|||||||
|
|
||||||
import me.clip.placeholderapi.PlaceholderAPI;
|
import me.clip.placeholderapi.PlaceholderAPI;
|
||||||
import net.momirealms.customnameplates.api.CustomNameplatesPlugin;
|
import net.momirealms.customnameplates.api.CustomNameplatesPlugin;
|
||||||
|
import net.momirealms.customnameplates.api.mechanic.font.OffsetFont;
|
||||||
import net.momirealms.customnameplates.api.util.FontUtils;
|
import net.momirealms.customnameplates.api.util.FontUtils;
|
||||||
import net.momirealms.customnameplates.api.util.LogUtils;
|
import net.momirealms.customnameplates.api.util.LogUtils;
|
||||||
|
import org.bukkit.OfflinePlayer;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
public class VanillaHud {
|
public class VanillaHud {
|
||||||
|
|
||||||
private final char empty;
|
private String empty;
|
||||||
private final char half;
|
private String half;
|
||||||
private final char full;
|
private String full;
|
||||||
private final String maxPapi;
|
private String maxPapi;
|
||||||
private final String currentPapi;
|
private String currentPapi;
|
||||||
private final boolean reverse;
|
private boolean reverse;
|
||||||
|
|
||||||
public VanillaHud(String empty, String half, String full, String maxPapi, String currentPapi, boolean reverse) {
|
private VanillaHud() {
|
||||||
this.empty = CustomNameplatesPlugin.get().getImageManager().getImage(empty).getCharacter();
|
}
|
||||||
this.half = CustomNameplatesPlugin.get().getImageManager().getImage(half).getCharacter();
|
|
||||||
this.full = CustomNameplatesPlugin.get().getImageManager().getImage(full).getCharacter();
|
public VanillaHud(char empty, char half, char full, String maxPapi, String currentPapi, boolean reverse) {
|
||||||
|
this.empty = String.valueOf(empty) + OffsetFont.NEG_2.getCharacter();
|
||||||
|
this.half = String.valueOf(half) + OffsetFont.NEG_2.getCharacter();
|
||||||
|
this.full = String.valueOf(full) + OffsetFont.NEG_2.getCharacter();
|
||||||
this.maxPapi = maxPapi;
|
this.maxPapi = maxPapi;
|
||||||
this.currentPapi = currentPapi;
|
this.currentPapi = currentPapi;
|
||||||
this.reverse = reverse;
|
this.reverse = reverse;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getValue(Player player) {
|
public static Builder builder() {
|
||||||
|
return new Builder();
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getValue(OfflinePlayer player) {
|
||||||
double current;
|
double current;
|
||||||
double max;
|
double max;
|
||||||
try {
|
try {
|
||||||
@@ -72,4 +81,51 @@ public class VanillaHud {
|
|||||||
}
|
}
|
||||||
return FontUtils.surroundNameplateFont(builder.toString());
|
return FontUtils.surroundNameplateFont(builder.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static class Builder{
|
||||||
|
|
||||||
|
private final VanillaHud hud;
|
||||||
|
|
||||||
|
public Builder() {
|
||||||
|
hud = new VanillaHud();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Builder of() {
|
||||||
|
return new Builder();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Builder full(char full) {
|
||||||
|
hud.full = String.valueOf(full) + OffsetFont.NEG_2.getCharacter();
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Builder half(char half) {
|
||||||
|
hud.half = String.valueOf(half) + OffsetFont.NEG_2.getCharacter();
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Builder empty(char empty) {
|
||||||
|
hud.empty = String.valueOf(empty) + OffsetFont.NEG_2.getCharacter();
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Builder reverse(boolean reverse) {
|
||||||
|
hud.reverse = reverse;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Builder max(String max) {
|
||||||
|
hud.maxPapi = max;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Builder current(String current) {
|
||||||
|
hud.currentPapi = current;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public VanillaHud build() {
|
||||||
|
return hud;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -86,7 +86,7 @@ public class CustomNameplatesPluginImpl extends CustomNameplatesPlugin implement
|
|||||||
this.actionBarManager = new ActionBarManagerImpl(this);
|
this.actionBarManager = new ActionBarManagerImpl(this);
|
||||||
this.coolDownManager = new CoolDownManager(this);
|
this.coolDownManager = new CoolDownManager(this);
|
||||||
this.packetManager = new PacketManager(this);
|
this.packetManager = new PacketManager(this);
|
||||||
this.reload(CNConfig.generatePackOnStart);
|
this.reload();
|
||||||
new CommandManager(this).load();
|
new CommandManager(this).load();
|
||||||
this.versionManager.checkUpdate().thenAccept(outDated -> {
|
this.versionManager.checkUpdate().thenAccept(outDated -> {
|
||||||
if (!outDated) this.getAdventure().sendConsoleMessage("[CustomNameplates] You are using the latest version.");
|
if (!outDated) this.getAdventure().sendConsoleMessage("[CustomNameplates] You are using the latest version.");
|
||||||
@@ -115,7 +115,7 @@ public class CustomNameplatesPluginImpl extends CustomNameplatesPlugin implement
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void reload(boolean generatePack) {
|
public void reload() {
|
||||||
CNConfig.load();
|
CNConfig.load();
|
||||||
CNLocale.load();
|
CNLocale.load();
|
||||||
((SchedulerImpl) this.scheduler).reload();
|
((SchedulerImpl) this.scheduler).reload();
|
||||||
@@ -132,7 +132,6 @@ public class CustomNameplatesPluginImpl extends CustomNameplatesPlugin implement
|
|||||||
((PlaceholderManagerImpl) this.placeholderManager).reload();
|
((PlaceholderManagerImpl) this.placeholderManager).reload();
|
||||||
((WidthManagerImpl) this.widthManager).reload();
|
((WidthManagerImpl) this.widthManager).reload();
|
||||||
((ResourcePackManagerImpl) this.resourcePackManager).reload();
|
((ResourcePackManagerImpl) this.resourcePackManager).reload();
|
||||||
this.resourcePackManager.generateResourcePack();
|
|
||||||
CustomNameplatesReloadEvent event = new CustomNameplatesReloadEvent(this);
|
CustomNameplatesReloadEvent event = new CustomNameplatesReloadEvent(this);
|
||||||
this.getServer().getPluginManager().callEvent(event);
|
this.getServer().getPluginManager().callEvent(event);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -262,21 +262,29 @@ public class CommandManager {
|
|||||||
LogUtils.warn(player.getName() + " failed to preview because data not loaded");
|
LogUtils.warn(player.getName() + " failed to preview because data not loaded");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
String previous = user.get().getNameplateKey();
|
if (!nameplate.equals("")) {
|
||||||
if (!CustomNameplatesPlugin.get().getNameplateManager().equipNameplate(player, nameplate, true)) {
|
String previous = user.get().getNameplateKey();
|
||||||
AdventureManagerImpl.getInstance().sendMessageWithPrefix(sender, CNLocale.MSG_NAMEPLATE_NOT_EXISTS);
|
if (!CustomNameplatesPlugin.get().getNameplateManager().equipNameplate(player, nameplate, true)) {
|
||||||
return;
|
AdventureManagerImpl.getInstance().sendMessageWithPrefix(sender, CNLocale.MSG_NAMEPLATE_NOT_EXISTS);
|
||||||
}
|
return;
|
||||||
nameplatePlayer.setPreview(true);
|
|
||||||
AdventureManagerImpl.getInstance().sendMessageWithPrefix(sender, CNLocale.MSG_FORCE_PREVIEW.replace("{Player}", player.getName()));
|
|
||||||
CustomNameplatesPlugin.get().getScheduler().runTaskAsyncLater(() -> {
|
|
||||||
nameplatePlayer.setPreview(false);
|
|
||||||
if (previous.equals("none")) {
|
|
||||||
CustomNameplatesPlugin.get().getNameplateManager().unEquipNameplate(player, true);
|
|
||||||
} else {
|
|
||||||
CustomNameplatesPlugin.get().getNameplateManager().equipNameplate(player, previous, true);
|
|
||||||
}
|
}
|
||||||
}, CustomNameplatesPlugin.get().getNameplateManager().getPreviewDuration(), TimeUnit.SECONDS);
|
AdventureManagerImpl.getInstance().sendMessageWithPrefix(sender, CNLocale.MSG_FORCE_PREVIEW.replace("{Player}", player.getName()));
|
||||||
|
nameplatePlayer.setPreview(true);
|
||||||
|
CustomNameplatesPlugin.get().getScheduler().runTaskAsyncLater(() -> {
|
||||||
|
nameplatePlayer.setPreview(false);
|
||||||
|
if (previous.equals("none")) {
|
||||||
|
CustomNameplatesPlugin.get().getNameplateManager().unEquipNameplate(player, true);
|
||||||
|
} else {
|
||||||
|
CustomNameplatesPlugin.get().getNameplateManager().equipNameplate(player, previous, true);
|
||||||
|
}
|
||||||
|
}, CustomNameplatesPlugin.get().getNameplateManager().getPreviewDuration(), TimeUnit.SECONDS);
|
||||||
|
} else {
|
||||||
|
AdventureManagerImpl.getInstance().sendMessageWithPrefix(sender, CNLocale.MSG_FORCE_PREVIEW.replace("{Player}", player.getName()));
|
||||||
|
nameplatePlayer.setPreview(true);
|
||||||
|
CustomNameplatesPlugin.get().getScheduler().runTaskAsyncLater(() -> {
|
||||||
|
nameplatePlayer.setPreview(false);
|
||||||
|
}, CustomNameplatesPlugin.get().getNameplateManager().getPreviewDuration(), TimeUnit.SECONDS);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -327,18 +335,50 @@ public class CommandManager {
|
|||||||
public static CommandAPICommand getReloadCommand() {
|
public static CommandAPICommand getReloadCommand() {
|
||||||
return new CommandAPICommand("reload")
|
return new CommandAPICommand("reload")
|
||||||
.withPermission("customnameplates.admin")
|
.withPermission("customnameplates.admin")
|
||||||
.withOptionalArguments(new BooleanArgument("generate pack"))
|
|
||||||
.executes((sender, args) -> {
|
.executes((sender, args) -> {
|
||||||
long time = System.currentTimeMillis();
|
AdventureManagerImpl.getInstance().sendMessageWithPrefix(sender, "<red>Usage: /nameplates reload all/pack/config");
|
||||||
CustomNameplatesPlugin.get().reload(false);
|
})
|
||||||
AdventureManagerImpl.getInstance().sendMessageWithPrefix(sender, CNLocale.MSG_RELOAD.replace("{time}", String.valueOf(System.currentTimeMillis()-time)));
|
.withSubcommands(
|
||||||
boolean generate = (boolean) args.getOrDefault("generate pack", true);
|
new CommandAPICommand("all")
|
||||||
if (generate) {
|
.withOptionalArguments(new BooleanArgument("async-pack-generation"))
|
||||||
AdventureManagerImpl.getInstance().sendMessageWithPrefix(sender, CNLocale.MSG_GENERATING);
|
.executes((sender, args) -> {
|
||||||
CustomNameplatesPlugin.get().getResourcePackManager().generateResourcePack();
|
boolean async = (boolean) args.getOrDefault("async-pack-generation", false);
|
||||||
AdventureManagerImpl.getInstance().sendMessageWithPrefix(sender, CNLocale.MSG_PACK_GENERATED);
|
long time = System.currentTimeMillis();
|
||||||
}
|
CustomNameplatesPlugin.get().reload();
|
||||||
});
|
AdventureManagerImpl.getInstance().sendMessageWithPrefix(sender, CNLocale.MSG_RELOAD.replace("{time}", String.valueOf(System.currentTimeMillis()-time)));
|
||||||
|
AdventureManagerImpl.getInstance().sendMessageWithPrefix(sender, CNLocale.MSG_GENERATING);
|
||||||
|
if (async) {
|
||||||
|
CustomNameplatesPlugin.get().getScheduler().runTaskAsync(() -> {
|
||||||
|
CustomNameplatesPlugin.get().getResourcePackManager().generateResourcePack();
|
||||||
|
AdventureManagerImpl.getInstance().sendMessageWithPrefix(sender, CNLocale.MSG_PACK_GENERATED);
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
CustomNameplatesPlugin.get().getResourcePackManager().generateResourcePack();
|
||||||
|
AdventureManagerImpl.getInstance().sendMessageWithPrefix(sender, CNLocale.MSG_PACK_GENERATED);
|
||||||
|
}
|
||||||
|
}),
|
||||||
|
new CommandAPICommand("pack")
|
||||||
|
.withOptionalArguments(new BooleanArgument("async-pack-generation"))
|
||||||
|
.executes((sender, args) -> {
|
||||||
|
boolean async = (boolean) args.getOrDefault("async-pack-generation", false);
|
||||||
|
AdventureManagerImpl.getInstance().sendMessageWithPrefix(sender, CNLocale.MSG_GENERATING);
|
||||||
|
if (async) {
|
||||||
|
CustomNameplatesPlugin.get().getScheduler().runTaskAsync(() -> {
|
||||||
|
CustomNameplatesPlugin.get().getResourcePackManager().generateResourcePack();
|
||||||
|
AdventureManagerImpl.getInstance().sendMessageWithPrefix(sender, CNLocale.MSG_PACK_GENERATED);
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
CustomNameplatesPlugin.get().getResourcePackManager().generateResourcePack();
|
||||||
|
AdventureManagerImpl.getInstance().sendMessageWithPrefix(sender, CNLocale.MSG_PACK_GENERATED);
|
||||||
|
}
|
||||||
|
}),
|
||||||
|
new CommandAPICommand("config")
|
||||||
|
.executes((sender, args) -> {
|
||||||
|
long time = System.currentTimeMillis();
|
||||||
|
CustomNameplatesPlugin.get().reload();
|
||||||
|
AdventureManagerImpl.getInstance().sendMessageWithPrefix(sender, CNLocale.MSG_RELOAD.replace("{time}", String.valueOf(System.currentTimeMillis()-time)));
|
||||||
|
})
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static CommandAPICommand getAboutCommand() {
|
public static CommandAPICommand getAboutCommand() {
|
||||||
|
|||||||
@@ -105,15 +105,22 @@ public class ActionBarManagerImpl implements ActionBarManager, Listener {
|
|||||||
|
|
||||||
private void loadConfigs() {
|
private void loadConfigs() {
|
||||||
YamlConfiguration config = plugin.getConfig("configs" + File.separator + "actionbar.yml");
|
YamlConfiguration config = plugin.getConfig("configs" + File.separator + "actionbar.yml");
|
||||||
|
boolean temp = false;
|
||||||
for (Map.Entry<String, Object> barEntry : config.getValues(false).entrySet()) {
|
for (Map.Entry<String, Object> barEntry : config.getValues(false).entrySet()) {
|
||||||
if (!(barEntry.getValue() instanceof ConfigurationSection section))
|
if (!(barEntry.getValue() instanceof ConfigurationSection section))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
if (temp) {
|
||||||
|
LogUtils.warn("You can create at most 1 actionbar in actionbar.yml. Actionbar " + barEntry.getKey() + " would not work.");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
this.config = ActionBarConfig.builder()
|
this.config = ActionBarConfig.builder()
|
||||||
.checkFrequency(section.getInt("check-frequency", 10))
|
.checkFrequency(section.getInt("check-frequency", 10))
|
||||||
.requirement(plugin.getRequirementManager().getRequirements(section.getConfigurationSection("conditions")))
|
.requirement(plugin.getRequirementManager().getRequirements(section.getConfigurationSection("conditions")))
|
||||||
.displayOrder(ConfigUtils.getTimeLimitTexts(section.getConfigurationSection("text-display-order")))
|
.displayOrder(ConfigUtils.getTimeLimitTexts(section.getConfigurationSection("text-display-order")))
|
||||||
.build();
|
.build();
|
||||||
|
temp = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -26,8 +26,6 @@ import net.momirealms.customnameplates.api.manager.BubbleManager;
|
|||||||
import net.momirealms.customnameplates.api.mechanic.bubble.Bubble;
|
import net.momirealms.customnameplates.api.mechanic.bubble.Bubble;
|
||||||
import net.momirealms.customnameplates.api.mechanic.character.CharacterArranger;
|
import net.momirealms.customnameplates.api.mechanic.character.CharacterArranger;
|
||||||
import net.momirealms.customnameplates.api.mechanic.character.ConfiguredChar;
|
import net.momirealms.customnameplates.api.mechanic.character.ConfiguredChar;
|
||||||
import net.momirealms.customnameplates.api.mechanic.nameplate.CachedNameplate;
|
|
||||||
import net.momirealms.customnameplates.api.mechanic.nameplate.Nameplate;
|
|
||||||
import net.momirealms.customnameplates.api.mechanic.tag.unlimited.EntityTagPlayer;
|
import net.momirealms.customnameplates.api.mechanic.tag.unlimited.EntityTagPlayer;
|
||||||
import net.momirealms.customnameplates.api.mechanic.tag.unlimited.StaticTextEntity;
|
import net.momirealms.customnameplates.api.mechanic.tag.unlimited.StaticTextEntity;
|
||||||
import net.momirealms.customnameplates.api.mechanic.tag.unlimited.StaticTextTagSetting;
|
import net.momirealms.customnameplates.api.mechanic.tag.unlimited.StaticTextTagSetting;
|
||||||
|
|||||||
@@ -31,10 +31,10 @@ import net.momirealms.customnameplates.api.mechanic.placeholder.DescentText;
|
|||||||
import net.momirealms.customnameplates.api.util.LogUtils;
|
import net.momirealms.customnameplates.api.util.LogUtils;
|
||||||
import net.momirealms.customnameplates.paper.setting.CNConfig;
|
import net.momirealms.customnameplates.paper.setting.CNConfig;
|
||||||
import net.momirealms.customnameplates.paper.util.ConfigUtils;
|
import net.momirealms.customnameplates.paper.util.ConfigUtils;
|
||||||
|
import org.apache.commons.io.FileUtils;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.configuration.file.YamlConfiguration;
|
import org.bukkit.configuration.file.YamlConfiguration;
|
||||||
import org.bukkit.plugin.Plugin;
|
import org.bukkit.plugin.Plugin;
|
||||||
import org.codehaus.plexus.util.FileUtils;
|
|
||||||
|
|
||||||
import javax.imageio.ImageIO;
|
import javax.imageio.ImageIO;
|
||||||
import java.awt.image.BufferedImage;
|
import java.awt.image.BufferedImage;
|
||||||
@@ -43,6 +43,7 @@ import java.nio.charset.StandardCharsets;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
public class ResourcePackManagerImpl implements ResourcePackManager {
|
public class ResourcePackManagerImpl implements ResourcePackManager {
|
||||||
|
|
||||||
@@ -338,14 +339,15 @@ public class ResourcePackManagerImpl implements ResourcePackManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (CNConfig.copyPackOraxen){
|
||||||
// if (CNConfig.copyPackOraxen) {
|
try {
|
||||||
// try {
|
FileUtils.copyDirectory(new File(resourcePackFolder, "assets"), new File(Objects.requireNonNull(Bukkit.getPluginManager().getPlugin("Oraxen")).getDataFolder() + File.separator + "pack" + File.separator + "assets"));
|
||||||
// FileUtils.copyDirectory(new File(resourcePackFolder, "assets"), new File(Objects.requireNonNull(Bukkit.getPluginManager().getPlugin("Oraxen")).getDataFolder() + File.separator + "pack" + File.separator + "assets"));
|
}
|
||||||
// } catch (IOException e) {
|
catch (IOException e){
|
||||||
// e.printStackTrace();
|
e.printStackTrace();
|
||||||
// }
|
LogUtils.warn("Failed to copy files to Oraxen...");
|
||||||
// }
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<JsonObject> getNameplates(File texturesFolder) {
|
private List<JsonObject> getNameplates(File texturesFolder) {
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ package net.momirealms.customnameplates.paper.mechanic.placeholder;
|
|||||||
|
|
||||||
import net.momirealms.customnameplates.api.CustomNameplatesPlugin;
|
import net.momirealms.customnameplates.api.CustomNameplatesPlugin;
|
||||||
import net.momirealms.customnameplates.api.manager.PlaceholderManager;
|
import net.momirealms.customnameplates.api.manager.PlaceholderManager;
|
||||||
|
import net.momirealms.customnameplates.api.mechanic.character.ConfiguredChar;
|
||||||
import net.momirealms.customnameplates.api.mechanic.placeholder.*;
|
import net.momirealms.customnameplates.api.mechanic.placeholder.*;
|
||||||
import net.momirealms.customnameplates.api.requirement.Requirement;
|
import net.momirealms.customnameplates.api.requirement.Requirement;
|
||||||
import net.momirealms.customnameplates.api.util.LogUtils;
|
import net.momirealms.customnameplates.api.util.LogUtils;
|
||||||
@@ -42,6 +43,7 @@ public class PlaceholderManagerImpl implements PlaceholderManager {
|
|||||||
private final HashMap<String, ConditionalText> conditionalTextMap;
|
private final HashMap<String, ConditionalText> conditionalTextMap;
|
||||||
private final HashMap<String, NameplateText> nameplateTextMap;
|
private final HashMap<String, NameplateText> nameplateTextMap;
|
||||||
private final HashMap<String, BackGroundText> backGroundTextMap;
|
private final HashMap<String, BackGroundText> backGroundTextMap;
|
||||||
|
private final HashMap<String, VanillaHud> vanillaHudMap;
|
||||||
private final CustomNameplatesPlugin plugin;
|
private final CustomNameplatesPlugin plugin;
|
||||||
|
|
||||||
public PlaceholderManagerImpl(CustomNameplatesPlugin plugin) {
|
public PlaceholderManagerImpl(CustomNameplatesPlugin plugin) {
|
||||||
@@ -53,6 +55,7 @@ public class PlaceholderManagerImpl implements PlaceholderManager {
|
|||||||
this.conditionalTextMap = new HashMap<>();
|
this.conditionalTextMap = new HashMap<>();
|
||||||
this.nameplateTextMap = new HashMap<>();
|
this.nameplateTextMap = new HashMap<>();
|
||||||
this.backGroundTextMap = new HashMap<>();
|
this.backGroundTextMap = new HashMap<>();
|
||||||
|
this.vanillaHudMap = new HashMap<>();
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
@@ -84,6 +87,9 @@ public class PlaceholderManagerImpl implements PlaceholderManager {
|
|||||||
this.switchTextMap.clear();
|
this.switchTextMap.clear();
|
||||||
this.descentTextMap.clear();
|
this.descentTextMap.clear();
|
||||||
this.conditionalTextMap.clear();
|
this.conditionalTextMap.clear();
|
||||||
|
this.nameplateTextMap.clear();
|
||||||
|
this.backGroundTextMap.clear();
|
||||||
|
this.vanillaHudMap.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -146,6 +152,16 @@ public class PlaceholderManagerImpl implements PlaceholderManager {
|
|||||||
return backGroundTextMap.values();
|
return backGroundTextMap.values();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public VanillaHud getVanillaHud(String key) {
|
||||||
|
return vanillaHudMap.get(key);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Collection<VanillaHud> getVanillaHuds() {
|
||||||
|
return vanillaHudMap.values();
|
||||||
|
}
|
||||||
|
|
||||||
public void loadConfigs() {
|
public void loadConfigs() {
|
||||||
YamlConfiguration config = plugin.getConfig("configs" + File.separator + "custom-placeholders.yml");
|
YamlConfiguration config = plugin.getConfig("configs" + File.separator + "custom-placeholders.yml");
|
||||||
ConfigurationSection staticSection = config.getConfigurationSection("static-text");
|
ConfigurationSection staticSection = config.getConfigurationSection("static-text");
|
||||||
@@ -182,6 +198,46 @@ public class PlaceholderManagerImpl implements PlaceholderManager {
|
|||||||
if (backgroundSection != null) {
|
if (backgroundSection != null) {
|
||||||
loadBackGroundTexts(backgroundSection);
|
loadBackGroundTexts(backgroundSection);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ConfigurationSection vanillaSection = config.getConfigurationSection("vanilla-hud");
|
||||||
|
if (vanillaSection != null) {
|
||||||
|
loadVanillaHuds(vanillaSection);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void loadVanillaHuds(ConfigurationSection section) {
|
||||||
|
for (Map.Entry<String, Object> entry : section.getValues(false).entrySet()) {
|
||||||
|
if (!(entry.getValue() instanceof ConfigurationSection innerSection))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
ConfiguredChar fullC = plugin.getImageManager().getImage(innerSection.getString("images.full",""));
|
||||||
|
if (fullC == null) {
|
||||||
|
LogUtils.warn("Vanilla hud placeholder wouldn't work because image " + innerSection.getString("full","") + " doesn't exist.");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
ConfiguredChar emptyC = plugin.getImageManager().getImage(innerSection.getString("images.empty",""));
|
||||||
|
if (emptyC == null) {
|
||||||
|
LogUtils.warn("Vanilla hud placeholder wouldn't work because image " + innerSection.getString("empty","") + " doesn't exist.");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
ConfiguredChar halfC = plugin.getImageManager().getImage(innerSection.getString("images.half",""));
|
||||||
|
if (halfC == null) {
|
||||||
|
LogUtils.warn("Vanilla hud placeholder wouldn't work because image " + innerSection.getString("half","") + " doesn't exist.");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
vanillaHudMap.put(entry.getKey(),
|
||||||
|
VanillaHud.builder()
|
||||||
|
.half(halfC.getCharacter())
|
||||||
|
.empty(emptyC.getCharacter())
|
||||||
|
.full(fullC.getCharacter())
|
||||||
|
.max(innerSection.getString("placeholder.max-value"))
|
||||||
|
.current(innerSection.getString("placeholder.value"))
|
||||||
|
.build()
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void loadBackGroundTexts(ConfigurationSection section) {
|
private void loadBackGroundTexts(ConfigurationSection section) {
|
||||||
|
|||||||
@@ -91,29 +91,34 @@ public class PluginPlaceholders extends PlaceholderExpansion {
|
|||||||
}
|
}
|
||||||
case "static" -> {
|
case "static" -> {
|
||||||
StaticText text = placeholderManager.getStaticText(mainArg);
|
StaticText text = placeholderManager.getStaticText(mainArg);
|
||||||
if (text == null) return "Static text not exists";
|
if (text == null) return "Static text not exists: " + mainArg;
|
||||||
return text.getValue(offlinePlayer);
|
return text.getValue(offlinePlayer);
|
||||||
}
|
}
|
||||||
case "unicode", "descent" -> {
|
case "unicode", "descent" -> {
|
||||||
DescentText descentText = placeholderManager.getDescentText(mainArg);
|
DescentText descentText = placeholderManager.getDescentText(mainArg);
|
||||||
if (descentText == null) return "Descent text not exists";
|
if (descentText == null) return "Descent text not exists: " + mainArg;
|
||||||
return descentText.getValue(offlinePlayer);
|
return descentText.getValue(offlinePlayer);
|
||||||
}
|
}
|
||||||
case "conditional" -> {
|
case "conditional" -> {
|
||||||
ConditionalText conditionalText = placeholderManager.getConditionalText(mainArg);
|
ConditionalText conditionalText = placeholderManager.getConditionalText(mainArg);
|
||||||
if (conditionalText == null) return "Conditional text not exists";
|
if (conditionalText == null) return "Conditional text not exists: " + mainArg;
|
||||||
return conditionalText.getValue(offlinePlayer);
|
return conditionalText.getValue(offlinePlayer);
|
||||||
}
|
}
|
||||||
case "nameplate" -> {
|
case "nameplate" -> {
|
||||||
NameplateText nameplateText = placeholderManager.getNameplateText(mainArg);
|
NameplateText nameplateText = placeholderManager.getNameplateText(mainArg);
|
||||||
if (nameplateText == null) return "Nameplate text not exists";
|
if (nameplateText == null) return "Nameplate text not exists: " + mainArg;
|
||||||
return nameplateText.getValue(offlinePlayer);
|
return nameplateText.getValue(offlinePlayer);
|
||||||
}
|
}
|
||||||
case "background" -> {
|
case "background" -> {
|
||||||
BackGroundText backGroundText = placeholderManager.getBackGroundText(mainArg);
|
BackGroundText backGroundText = placeholderManager.getBackGroundText(mainArg);
|
||||||
if (backGroundText == null) return "Background text not exists";
|
if (backGroundText == null) return "Background text not exists: " + mainArg;
|
||||||
return backGroundText.getValue(offlinePlayer);
|
return backGroundText.getValue(offlinePlayer);
|
||||||
}
|
}
|
||||||
|
case "vanilla" -> {
|
||||||
|
VanillaHud vanillaHud = placeholderManager.getVanillaHud(mainArg);
|
||||||
|
if (vanillaHud == null) return "Vanilla text not exists: " + mainArg;
|
||||||
|
return vanillaHud.getValue(offlinePlayer);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Player onlinePlayer = offlinePlayer.getPlayer();
|
Player onlinePlayer = offlinePlayer.getPlayer();
|
||||||
@@ -170,5 +175,4 @@ public class PluginPlaceholders extends PlaceholderExpansion {
|
|||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -119,6 +119,8 @@ public class RequirementManagerImpl implements RequirementManager {
|
|||||||
this.registerEnvironmentRequirement();
|
this.registerEnvironmentRequirement();
|
||||||
this.registerPotionEffectRequirement();
|
this.registerPotionEffectRequirement();
|
||||||
this.registerPapiRequirement();
|
this.registerPapiRequirement();
|
||||||
|
this.registerInListRequirement();
|
||||||
|
this.registerGameModeRequirement();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -637,6 +639,24 @@ public class RequirementManagerImpl implements RequirementManager {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void registerGameModeRequirement() {
|
||||||
|
registerRequirement("gamemode", (args) -> {
|
||||||
|
List<String> modes = ConfigUtils.stringListArgs(args);
|
||||||
|
return condition -> {
|
||||||
|
var name = condition.getOfflinePlayer().getPlayer().getGameMode().name().toLowerCase(Locale.ENGLISH);
|
||||||
|
return modes.contains(name);
|
||||||
|
};
|
||||||
|
});
|
||||||
|
registerRequirement("!gamemode", (args) -> {
|
||||||
|
List<String> modes = ConfigUtils.stringListArgs(args);
|
||||||
|
return condition -> {
|
||||||
|
var name = condition.getOfflinePlayer().getPlayer().getGameMode().name().toLowerCase(Locale.ENGLISH);
|
||||||
|
return !modes.contains(name);
|
||||||
|
};
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
private void registerPotionEffectRequirement() {
|
private void registerPotionEffectRequirement() {
|
||||||
registerRequirement("potion-effect", (args) -> {
|
registerRequirement("potion-effect", (args) -> {
|
||||||
String potions = (String) args;
|
String potions = (String) args;
|
||||||
@@ -680,6 +700,35 @@ public class RequirementManagerImpl implements RequirementManager {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void registerInListRequirement() {
|
||||||
|
registerRequirement("in-list", (args) -> {
|
||||||
|
if (args instanceof ConfigurationSection section) {
|
||||||
|
String papi = section.getString("papi", "");
|
||||||
|
List<String> values = ConfigUtils.stringListArgs(section.get("values"));
|
||||||
|
return condition -> {
|
||||||
|
String p1 = PlaceholderAPI.setPlaceholders(condition.getOfflinePlayer(), papi);
|
||||||
|
return values.contains(p1);
|
||||||
|
};
|
||||||
|
} else {
|
||||||
|
LogUtils.warn("Wrong value format found at in-list requirement.");
|
||||||
|
return EmptyRequirement.instance;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
registerRequirement("!in-list", (args) -> {
|
||||||
|
if (args instanceof ConfigurationSection section) {
|
||||||
|
String papi = section.getString("papi", "");
|
||||||
|
List<String> values = ConfigUtils.stringListArgs(section.get("values"));
|
||||||
|
return condition -> {
|
||||||
|
String p1 = PlaceholderAPI.setPlaceholders(condition.getOfflinePlayer(), papi);
|
||||||
|
return !values.contains(p1);
|
||||||
|
};
|
||||||
|
} else {
|
||||||
|
LogUtils.warn("Wrong value format found at in-list requirement.");
|
||||||
|
return EmptyRequirement.instance;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Loads requirement expansions from external JAR files located in the expansion folder.
|
* Loads requirement expansions from external JAR files located in the expansion folder.
|
||||||
* Each expansion JAR should contain classes that extends the RequirementExpansion class.
|
* Each expansion JAR should contain classes that extends the RequirementExpansion class.
|
||||||
|
|||||||
@@ -26,7 +26,6 @@ import net.momirealms.customnameplates.api.data.PlayerData;
|
|||||||
import net.momirealms.customnameplates.api.data.StorageType;
|
import net.momirealms.customnameplates.api.data.StorageType;
|
||||||
import net.momirealms.customnameplates.api.event.NameplateDataLoadEvent;
|
import net.momirealms.customnameplates.api.event.NameplateDataLoadEvent;
|
||||||
import net.momirealms.customnameplates.api.manager.StorageManager;
|
import net.momirealms.customnameplates.api.manager.StorageManager;
|
||||||
import net.momirealms.customnameplates.api.scheduler.CancellableTask;
|
|
||||||
import net.momirealms.customnameplates.api.util.LogUtils;
|
import net.momirealms.customnameplates.api.util.LogUtils;
|
||||||
import net.momirealms.customnameplates.paper.CustomNameplatesPluginImpl;
|
import net.momirealms.customnameplates.paper.CustomNameplatesPluginImpl;
|
||||||
import net.momirealms.customnameplates.paper.storage.method.database.nosql.MongoDBImpl;
|
import net.momirealms.customnameplates.paper.storage.method.database.nosql.MongoDBImpl;
|
||||||
@@ -39,7 +38,6 @@ import net.momirealms.customnameplates.paper.storage.method.file.JsonImpl;
|
|||||||
import net.momirealms.customnameplates.paper.storage.method.file.YAMLImpl;
|
import net.momirealms.customnameplates.paper.storage.method.file.YAMLImpl;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.configuration.file.YamlConfiguration;
|
import org.bukkit.configuration.file.YamlConfiguration;
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
import org.bukkit.event.HandlerList;
|
import org.bukkit.event.HandlerList;
|
||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
@@ -54,7 +52,6 @@ import java.util.Optional;
|
|||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import java.util.concurrent.CompletableFuture;
|
import java.util.concurrent.CompletableFuture;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
import java.util.concurrent.TimeUnit;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This class implements the StorageManager interface and is responsible for managing player data storage.
|
* This class implements the StorageManager interface and is responsible for managing player data storage.
|
||||||
|
|||||||
@@ -1,5 +1,9 @@
|
|||||||
conditional-text:
|
conditional-text:
|
||||||
actionbar:
|
actionbar:
|
||||||
|
priority_0:
|
||||||
|
text: '%nameplates_background_other_actionbar%'
|
||||||
|
conditions:
|
||||||
|
'!gamemode': survival
|
||||||
priority_1:
|
priority_1:
|
||||||
text: '%nameplates_background_other_actionbar%'
|
text: '%nameplates_background_other_actionbar%'
|
||||||
conditions:
|
conditions:
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ unlimited:
|
|||||||
text: '%nameplates_nametag%'
|
text: '%nameplates_nametag%'
|
||||||
vertical-offset: -1
|
vertical-offset: -1
|
||||||
owner-conditions:
|
owner-conditions:
|
||||||
potion-effect: "INVISIBILITY=0"
|
potion-effect: "INVISIBILITY==0"
|
||||||
viewer-conditions: { }
|
viewer-conditions: { }
|
||||||
tag_2:
|
tag_2:
|
||||||
text: "IP: %player_ip% My IP: %viewer_player_ip%"
|
text: "IP: %player_ip% My IP: %viewer_player_ip%"
|
||||||
@@ -37,7 +37,7 @@ unlimited:
|
|||||||
refresh-frequency: 10
|
refresh-frequency: 10
|
||||||
check-frequency: 20
|
check-frequency: 20
|
||||||
owner-conditions:
|
owner-conditions:
|
||||||
potion-effect: "INVISIBILITY=0"
|
potion-effect: "INVISIBILITY==0"
|
||||||
viewer-conditions:
|
viewer-conditions:
|
||||||
condition_1:
|
condition_1:
|
||||||
type: permission
|
type: permission
|
||||||
|
|||||||
Reference in New Issue
Block a user