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