Update from Git Manager GUI
This commit is contained in:
@@ -13,6 +13,8 @@ import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class DataManager {
|
||||
private static final String FORCE_OFFLINE_PATH = "Status.force-offline";
|
||||
|
||||
private static File file;
|
||||
private static FileConfiguration data;
|
||||
|
||||
@@ -94,6 +96,7 @@ public class DataManager {
|
||||
}
|
||||
if (removed) {
|
||||
data.set("JoinDates." + name, null);
|
||||
data.set(FORCE_OFFLINE_PATH + "." + normalizeName(name), null);
|
||||
save();
|
||||
}
|
||||
}
|
||||
@@ -177,4 +180,17 @@ public class DataManager {
|
||||
public static String getJoinDate(String name) {
|
||||
return data.getString("JoinDates." + name, "");
|
||||
}
|
||||
|
||||
public static boolean isForcedOffline(String name) {
|
||||
return data.getBoolean(FORCE_OFFLINE_PATH + "." + normalizeName(name), false);
|
||||
}
|
||||
|
||||
public static void setForcedOffline(String name, boolean forcedOffline) {
|
||||
data.set(FORCE_OFFLINE_PATH + "." + normalizeName(name), forcedOffline ? true : null);
|
||||
save();
|
||||
}
|
||||
|
||||
private static String normalizeName(String name) {
|
||||
return name == null ? "" : name.toLowerCase(Locale.ROOT);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,6 +6,10 @@ import org.bukkit.configuration.file.YamlConfiguration;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class LangManager {
|
||||
@@ -17,6 +21,8 @@ public class LangManager {
|
||||
// ── Setup ─────────────────────────────────────────────────────────
|
||||
|
||||
public static void setup() {
|
||||
syncLanguageFiles();
|
||||
|
||||
String lang = Main.getInstance().getConfig().getString("language", "de").toLowerCase();
|
||||
String fileName = "lang_" + lang + ".yml";
|
||||
|
||||
@@ -31,6 +37,58 @@ public class LangManager {
|
||||
"[LangManager] Loaded language: " + lang + " (" + fileName + ")");
|
||||
}
|
||||
|
||||
private static void syncLanguageFiles() {
|
||||
syncLanguageFile("lang_de.yml");
|
||||
syncLanguageFile("lang_en.yml");
|
||||
}
|
||||
|
||||
private static void syncLanguageFile(String fileName) {
|
||||
Main plugin = Main.getInstance();
|
||||
File target = new File(plugin.getDataFolder(), fileName);
|
||||
|
||||
if (!target.exists()) {
|
||||
plugin.saveResource(fileName, false);
|
||||
plugin.getLogger().info("[LangManager] Created missing file: " + fileName);
|
||||
return;
|
||||
}
|
||||
|
||||
YamlConfiguration onDisk = YamlConfiguration.loadConfiguration(target);
|
||||
YamlConfiguration defaults = loadLangDefaults(plugin, fileName);
|
||||
if (defaults == null) return;
|
||||
|
||||
List<String> added = new ArrayList<>();
|
||||
for (String path : defaults.getKeys(true)) {
|
||||
if (defaults.isConfigurationSection(path)) continue;
|
||||
if (!onDisk.isSet(path)) {
|
||||
onDisk.set(path, defaults.get(path));
|
||||
added.add(path);
|
||||
}
|
||||
}
|
||||
|
||||
if (added.isEmpty()) return;
|
||||
|
||||
try {
|
||||
onDisk.save(target);
|
||||
plugin.getLogger().info("[LangManager] " + fileName + ": " + added.size()
|
||||
+ " missing key(s) added.");
|
||||
} catch (IOException e) {
|
||||
plugin.getLogger().warning("[LangManager] Failed to save " + fileName + ": " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
private static YamlConfiguration loadLangDefaults(Main plugin, String fileName) {
|
||||
try (InputStream in = plugin.getResource(fileName)) {
|
||||
if (in == null) {
|
||||
plugin.getLogger().warning("[LangManager] Missing bundled language file: " + fileName);
|
||||
return null;
|
||||
}
|
||||
return YamlConfiguration.loadConfiguration(new InputStreamReader(in, StandardCharsets.UTF_8));
|
||||
} catch (IOException e) {
|
||||
plugin.getLogger().warning("[LangManager] Failed to load bundled " + fileName + ": " + e.getMessage());
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
// ── Getters ───────────────────────────────────────────────────────
|
||||
|
||||
public static String get(String path) {
|
||||
|
||||
@@ -0,0 +1,64 @@
|
||||
package me.viper.teamplugin.manager;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.metadata.MetadataValue;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Zentraler Präsenz-Status für Team-Anzeige.
|
||||
* Spieler gelten als offline, wenn sie wirklich offline sind,
|
||||
* manuell auf offline gesetzt wurden oder im Vanish sind.
|
||||
*/
|
||||
public final class PresenceManager {
|
||||
|
||||
private PresenceManager() {}
|
||||
|
||||
public static boolean isShownAsOnline(String playerName) {
|
||||
if (playerName == null || playerName.isEmpty()) return false;
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
OfflinePlayer off = Bukkit.getOfflinePlayer(playerName);
|
||||
if (!off.isOnline()) return false;
|
||||
|
||||
Player player = off.getPlayer();
|
||||
if (player == null) return false;
|
||||
|
||||
if (DataManager.isForcedOffline(playerName)) return false;
|
||||
return !isVanished(player);
|
||||
}
|
||||
|
||||
public static boolean isForcedOffline(String playerName) {
|
||||
return DataManager.isForcedOffline(playerName);
|
||||
}
|
||||
|
||||
public static void setForcedOffline(String playerName, boolean forcedOffline) {
|
||||
DataManager.setForcedOffline(playerName, forcedOffline);
|
||||
}
|
||||
|
||||
private static boolean isVanished(Player player) {
|
||||
if (player == null) return false;
|
||||
|
||||
// Common metadata keys used by vanish plugins.
|
||||
// Important: check metadata BOOLEAN value, not just key existence.
|
||||
if (hasTrueMetadata(player, "vanished")
|
||||
|| hasTrueMetadata(player, "vanish")
|
||||
|| hasTrueMetadata(player, "essentials.vanish")
|
||||
|| hasTrueMetadata(player, "supervanish")) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// Fallback for plugins that toggle entity invisibility directly.
|
||||
return player.isInvisible();
|
||||
}
|
||||
|
||||
private static boolean hasTrueMetadata(Player player, String key) {
|
||||
List<MetadataValue> values = player.getMetadata(key);
|
||||
for (MetadataValue value : values) {
|
||||
if (value != null && value.asBoolean()) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user