mirror of
https://github.com/YouHaveTrouble/NotJustNameplates.git
synced 2026-05-11 22:16:57 +00:00
fix default config shenanigans
This commit is contained in:
@@ -8,6 +8,7 @@ import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.entity.Display;
|
||||
import org.bukkit.permissions.Permission;
|
||||
import org.bukkit.permissions.PermissionDefault;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.HashMap;
|
||||
@@ -64,7 +65,7 @@ public class NJNConfig {
|
||||
return displayContents.get(name);
|
||||
}
|
||||
|
||||
protected HashMap<String, DisplayContent> getDisplayContents() {
|
||||
public HashMap<String, DisplayContent> getDisplayContents() {
|
||||
return displayContents;
|
||||
}
|
||||
|
||||
@@ -91,7 +92,7 @@ public class NJNConfig {
|
||||
framesSection.getKeys(false).forEach(frameName -> {
|
||||
ConfigurationSection frameSection = framesSection.getConfigurationSection(frameName);
|
||||
if (frameSection == null) return;
|
||||
String text = frameSection.getString("text");
|
||||
String text = frameSection.getString("text", null);
|
||||
String backgroundColor = frameSection.getString("background");
|
||||
displayContent.addFrame(new DisplayFrame(text, colorFromHex(backgroundColor)));
|
||||
});
|
||||
|
||||
@@ -2,6 +2,7 @@ package me.youhavetrouble.notjustnameplates;
|
||||
|
||||
import me.youhavetrouble.notjustnameplates.commands.MainCommand;
|
||||
import me.youhavetrouble.notjustnameplates.displays.DisplayContent;
|
||||
import me.youhavetrouble.notjustnameplates.nameplates.Nameplate;
|
||||
import me.youhavetrouble.notjustnameplates.nameplates.NameplateManager;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
@@ -64,18 +65,22 @@ public final class NotJustNameplates extends JavaPlugin {
|
||||
nameplateManager.getNameplates().forEach(((uuid, nameplate) -> {
|
||||
Player player = Bukkit.getPlayer(uuid);
|
||||
if (player == null || !player.isOnline()) return;
|
||||
for (Map.Entry<String, DisplayContent> entry : config.getDisplayContents().entrySet()) {
|
||||
String id = entry.getKey();
|
||||
if (id.equalsIgnoreCase("default")) continue;
|
||||
if (player.hasPermission("notjustnameplates.display." + id)) {
|
||||
nameplate.setContent(entry.getValue());
|
||||
return;
|
||||
}
|
||||
}
|
||||
nameplate.setContent(config.getDisplayContent("default"));
|
||||
nameplate.setContent(getDisplayContentForPlayerBasedOnPermission(player));
|
||||
}));
|
||||
}
|
||||
|
||||
public DisplayContent getDisplayContentForPlayerBasedOnPermission(Player player) {
|
||||
if (player == null) return null;
|
||||
for (Map.Entry<String, DisplayContent> entry : config.getDisplayContents().entrySet()) {
|
||||
String id = entry.getKey();
|
||||
if (id.equalsIgnoreCase("default")) continue;
|
||||
if (player.hasPermission("notjustnameplates.display." + id)) {
|
||||
return entry.getValue();
|
||||
}
|
||||
}
|
||||
return config.getDisplayContent("default");
|
||||
}
|
||||
|
||||
public TeamManager getTeamManager() {
|
||||
return teamManager;
|
||||
}
|
||||
|
||||
@@ -81,8 +81,8 @@ public class Nameplate {
|
||||
player.addPassenger(textDisplay);
|
||||
}
|
||||
|
||||
public void setContent(@NotNull DisplayContent content) {
|
||||
if (this.content == content) return;
|
||||
public void setContent(DisplayContent content) {
|
||||
if (content == null || this.content == content) return;
|
||||
this.content = content;
|
||||
Bukkit.getScheduler().runTask(NotJustNameplates.getInstance(), this::remove);
|
||||
}
|
||||
|
||||
@@ -30,7 +30,7 @@ public class NameplateManager implements Listener {
|
||||
@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGHEST)
|
||||
public void onPlayerJoin(PlayerJoinEvent event) {
|
||||
UUID joinerUuid = event.getPlayer().getUniqueId();
|
||||
DisplayContent displayContent = NotJustNameplates.getPluginConfig().getDisplayContent("default");
|
||||
DisplayContent displayContent = NotJustNameplates.getInstance().getDisplayContentForPlayerBasedOnPermission(event.getPlayer());
|
||||
if (displayContent == null) return;
|
||||
nameplates.put(joinerUuid, new Nameplate(joinerUuid, displayContent));
|
||||
}
|
||||
@@ -96,9 +96,14 @@ public class NameplateManager implements Listener {
|
||||
this.nameplates.clear();
|
||||
for (Player player : Bukkit.getOnlinePlayers()) {
|
||||
DisplayContent displayContent = NotJustNameplates.getPluginConfig().getDisplayContent("default");
|
||||
nameplates.put(player.getUniqueId(), new Nameplate(player.getUniqueId(), displayContent != null ? displayContent : new DisplayContent()));
|
||||
for (Map.Entry<String, DisplayContent> entry : NotJustNameplates.getPluginConfig().getDisplayContents().entrySet()) {
|
||||
if (player.hasPermission("notjustnameplates.display." + entry.getKey())) {
|
||||
displayContent = entry.getValue();
|
||||
break;
|
||||
}
|
||||
}
|
||||
nameplates.put(player.getUniqueId(), new Nameplate(player.getUniqueId(), displayContent));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public Map<UUID, Nameplate> getNameplates() {
|
||||
|
||||
@@ -9,10 +9,6 @@ nameplates:
|
||||
frames:
|
||||
1:
|
||||
text: "%displayname%"
|
||||
background: "#0000FFAA"
|
||||
2:
|
||||
text: "%displayname%"
|
||||
background: "#FF0000AA"
|
||||
|
||||
# Billboard options are as follows:
|
||||
# "center" - pivots around center point
|
||||
|
||||
Reference in New Issue
Block a user