9
0
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:
XiaoMoMi
2024-01-24 04:45:56 +08:00
parent 60549ade96
commit 60dfefe3bc
14 changed files with 278 additions and 62 deletions

View File

@@ -56,7 +56,7 @@ public abstract class CustomNameplatesPlugin extends JavaPlugin {
}
/* reload the plugin */
public abstract void reload(boolean generatePack);
public abstract void reload();
/* Get the scheduler */
public Scheduler getScheduler() {

View File

@@ -100,4 +100,8 @@ public interface PlaceholderManager {
BackGroundText getBackGroundText(String key);
Collection<BackGroundText> getBackGroundTexts();
VanillaHud getVanillaHud(String key);
Collection<VanillaHud> getVanillaHuds();
}

View File

@@ -19,29 +19,38 @@ package net.momirealms.customnameplates.api.mechanic.placeholder;
import me.clip.placeholderapi.PlaceholderAPI;
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.LogUtils;
import org.bukkit.OfflinePlayer;
import org.bukkit.entity.Player;
public class VanillaHud {
private final char empty;
private final char half;
private final char full;
private final String maxPapi;
private final String currentPapi;
private final boolean reverse;
private String empty;
private String half;
private String full;
private String maxPapi;
private String currentPapi;
private boolean reverse;
public VanillaHud(String empty, String half, String full, String maxPapi, String currentPapi, boolean reverse) {
this.empty = CustomNameplatesPlugin.get().getImageManager().getImage(empty).getCharacter();
this.half = CustomNameplatesPlugin.get().getImageManager().getImage(half).getCharacter();
this.full = CustomNameplatesPlugin.get().getImageManager().getImage(full).getCharacter();
private VanillaHud() {
}
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.currentPapi = currentPapi;
this.reverse = reverse;
}
public String getValue(Player player) {
public static Builder builder() {
return new Builder();
}
public String getValue(OfflinePlayer player) {
double current;
double max;
try {
@@ -72,4 +81,51 @@ public class VanillaHud {
}
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;
}
}
}

View File

@@ -86,7 +86,7 @@ public class CustomNameplatesPluginImpl extends CustomNameplatesPlugin implement
this.actionBarManager = new ActionBarManagerImpl(this);
this.coolDownManager = new CoolDownManager(this);
this.packetManager = new PacketManager(this);
this.reload(CNConfig.generatePackOnStart);
this.reload();
new CommandManager(this).load();
this.versionManager.checkUpdate().thenAccept(outDated -> {
if (!outDated) this.getAdventure().sendConsoleMessage("[CustomNameplates] You are using the latest version.");
@@ -115,7 +115,7 @@ public class CustomNameplatesPluginImpl extends CustomNameplatesPlugin implement
}
@Override
public void reload(boolean generatePack) {
public void reload() {
CNConfig.load();
CNLocale.load();
((SchedulerImpl) this.scheduler).reload();
@@ -132,7 +132,6 @@ public class CustomNameplatesPluginImpl extends CustomNameplatesPlugin implement
((PlaceholderManagerImpl) this.placeholderManager).reload();
((WidthManagerImpl) this.widthManager).reload();
((ResourcePackManagerImpl) this.resourcePackManager).reload();
this.resourcePackManager.generateResourcePack();
CustomNameplatesReloadEvent event = new CustomNameplatesReloadEvent(this);
this.getServer().getPluginManager().callEvent(event);
}

View File

@@ -262,13 +262,14 @@ public class CommandManager {
LogUtils.warn(player.getName() + " failed to preview because data not loaded");
return;
}
if (!nameplate.equals("")) {
String previous = user.get().getNameplateKey();
if (!CustomNameplatesPlugin.get().getNameplateManager().equipNameplate(player, nameplate, true)) {
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()));
nameplatePlayer.setPreview(true);
CustomNameplatesPlugin.get().getScheduler().runTaskAsyncLater(() -> {
nameplatePlayer.setPreview(false);
if (previous.equals("none")) {
@@ -277,6 +278,13 @@ public class CommandManager {
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() {
return new CommandAPICommand("reload")
.withPermission("customnameplates.admin")
.withOptionalArguments(new BooleanArgument("generate pack"))
.executes((sender, args) -> {
AdventureManagerImpl.getInstance().sendMessageWithPrefix(sender, "<red>Usage: /nameplates reload all/pack/config");
})
.withSubcommands(
new CommandAPICommand("all")
.withOptionalArguments(new BooleanArgument("async-pack-generation"))
.executes((sender, args) -> {
boolean async = (boolean) args.getOrDefault("async-pack-generation", false);
long time = System.currentTimeMillis();
CustomNameplatesPlugin.get().reload(false);
CustomNameplatesPlugin.get().reload();
AdventureManagerImpl.getInstance().sendMessageWithPrefix(sender, CNLocale.MSG_RELOAD.replace("{time}", String.valueOf(System.currentTimeMillis()-time)));
boolean generate = (boolean) args.getOrDefault("generate pack", true);
if (generate) {
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() {

View File

@@ -105,15 +105,22 @@ public class ActionBarManagerImpl implements ActionBarManager, Listener {
private void loadConfigs() {
YamlConfiguration config = plugin.getConfig("configs" + File.separator + "actionbar.yml");
boolean temp = false;
for (Map.Entry<String, Object> barEntry : config.getValues(false).entrySet()) {
if (!(barEntry.getValue() instanceof ConfigurationSection section))
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()
.checkFrequency(section.getInt("check-frequency", 10))
.requirement(plugin.getRequirementManager().getRequirements(section.getConfigurationSection("conditions")))
.displayOrder(ConfigUtils.getTimeLimitTexts(section.getConfigurationSection("text-display-order")))
.build();
temp = true;
}
}

View File

@@ -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.character.CharacterArranger;
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.StaticTextEntity;
import net.momirealms.customnameplates.api.mechanic.tag.unlimited.StaticTextTagSetting;

View File

@@ -31,10 +31,10 @@ import net.momirealms.customnameplates.api.mechanic.placeholder.DescentText;
import net.momirealms.customnameplates.api.util.LogUtils;
import net.momirealms.customnameplates.paper.setting.CNConfig;
import net.momirealms.customnameplates.paper.util.ConfigUtils;
import org.apache.commons.io.FileUtils;
import org.bukkit.Bukkit;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.plugin.Plugin;
import org.codehaus.plexus.util.FileUtils;
import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
@@ -43,6 +43,7 @@ import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
import java.util.Objects;
public class ResourcePackManagerImpl implements ResourcePackManager {
@@ -338,14 +339,15 @@ public class ResourcePackManagerImpl implements ResourcePackManager {
}
}
}
// if (CNConfig.copyPackOraxen) {
// try {
// FileUtils.copyDirectory(new File(resourcePackFolder, "assets"), new File(Objects.requireNonNull(Bukkit.getPluginManager().getPlugin("Oraxen")).getDataFolder() + File.separator + "pack" + File.separator + "assets"));
// } catch (IOException e) {
// e.printStackTrace();
// }
// }
if (CNConfig.copyPackOraxen){
try {
FileUtils.copyDirectory(new File(resourcePackFolder, "assets"), new File(Objects.requireNonNull(Bukkit.getPluginManager().getPlugin("Oraxen")).getDataFolder() + File.separator + "pack" + File.separator + "assets"));
}
catch (IOException e){
e.printStackTrace();
LogUtils.warn("Failed to copy files to Oraxen...");
}
}
}
private List<JsonObject> getNameplates(File texturesFolder) {

View File

@@ -19,6 +19,7 @@ package net.momirealms.customnameplates.paper.mechanic.placeholder;
import net.momirealms.customnameplates.api.CustomNameplatesPlugin;
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.requirement.Requirement;
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, NameplateText> nameplateTextMap;
private final HashMap<String, BackGroundText> backGroundTextMap;
private final HashMap<String, VanillaHud> vanillaHudMap;
private final CustomNameplatesPlugin plugin;
public PlaceholderManagerImpl(CustomNameplatesPlugin plugin) {
@@ -53,6 +55,7 @@ public class PlaceholderManagerImpl implements PlaceholderManager {
this.conditionalTextMap = new HashMap<>();
this.nameplateTextMap = new HashMap<>();
this.backGroundTextMap = new HashMap<>();
this.vanillaHudMap = new HashMap<>();
}
@NotNull
@@ -84,6 +87,9 @@ public class PlaceholderManagerImpl implements PlaceholderManager {
this.switchTextMap.clear();
this.descentTextMap.clear();
this.conditionalTextMap.clear();
this.nameplateTextMap.clear();
this.backGroundTextMap.clear();
this.vanillaHudMap.clear();
}
@Override
@@ -146,6 +152,16 @@ public class PlaceholderManagerImpl implements PlaceholderManager {
return backGroundTextMap.values();
}
@Override
public VanillaHud getVanillaHud(String key) {
return vanillaHudMap.get(key);
}
@Override
public Collection<VanillaHud> getVanillaHuds() {
return vanillaHudMap.values();
}
public void loadConfigs() {
YamlConfiguration config = plugin.getConfig("configs" + File.separator + "custom-placeholders.yml");
ConfigurationSection staticSection = config.getConfigurationSection("static-text");
@@ -182,6 +198,46 @@ public class PlaceholderManagerImpl implements PlaceholderManager {
if (backgroundSection != null) {
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) {

View File

@@ -91,29 +91,34 @@ public class PluginPlaceholders extends PlaceholderExpansion {
}
case "static" -> {
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);
}
case "unicode", "descent" -> {
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);
}
case "conditional" -> {
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);
}
case "nameplate" -> {
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);
}
case "background" -> {
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);
}
case "vanilla" -> {
VanillaHud vanillaHud = placeholderManager.getVanillaHud(mainArg);
if (vanillaHud == null) return "Vanilla text not exists: " + mainArg;
return vanillaHud.getValue(offlinePlayer);
}
}
Player onlinePlayer = offlinePlayer.getPlayer();
@@ -170,5 +175,4 @@ public class PluginPlaceholders extends PlaceholderExpansion {
}
return null;
}
}

View File

@@ -119,6 +119,8 @@ public class RequirementManagerImpl implements RequirementManager {
this.registerEnvironmentRequirement();
this.registerPotionEffectRequirement();
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() {
registerRequirement("potion-effect", (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.
* Each expansion JAR should contain classes that extends the RequirementExpansion class.

View File

@@ -26,7 +26,6 @@ import net.momirealms.customnameplates.api.data.PlayerData;
import net.momirealms.customnameplates.api.data.StorageType;
import net.momirealms.customnameplates.api.event.NameplateDataLoadEvent;
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.paper.CustomNameplatesPluginImpl;
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 org.bukkit.Bukkit;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.HandlerList;
import org.bukkit.event.Listener;
@@ -54,7 +52,6 @@ import java.util.Optional;
import java.util.UUID;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.TimeUnit;
/**
* This class implements the StorageManager interface and is responsible for managing player data storage.

View File

@@ -1,5 +1,9 @@
conditional-text:
actionbar:
priority_0:
text: '%nameplates_background_other_actionbar%'
conditions:
'!gamemode': survival
priority_1:
text: '%nameplates_background_other_actionbar%'
conditions:

View File

@@ -29,7 +29,7 @@ unlimited:
text: '%nameplates_nametag%'
vertical-offset: -1
owner-conditions:
potion-effect: "INVISIBILITY=0"
potion-effect: "INVISIBILITY==0"
viewer-conditions: { }
tag_2:
text: "IP: %player_ip% My IP: %viewer_player_ip%"
@@ -37,7 +37,7 @@ unlimited:
refresh-frequency: 10
check-frequency: 20
owner-conditions:
potion-effect: "INVISIBILITY=0"
potion-effect: "INVISIBILITY==0"
viewer-conditions:
condition_1:
type: permission