Update from Git Manager GUI

This commit is contained in:
2026-01-12 00:03:14 +01:00
parent 3f3d1c7d37
commit 25339444da
18 changed files with 968 additions and 289 deletions

View File

@@ -1,30 +1,83 @@
package de.viper.survivalplus.Manager;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.Player;
import java.io.File;
import java.io.IOException;
import java.util.*;
import org.bukkit.entity.Player;
import de.viper.survivalplus.SurvivalPlus;
public class BlockManager {
private final SurvivalPlus plugin;
private final Map<UUID, Set<UUID>> blockedPlayers = new HashMap<>();
private File blocksFile;
private FileConfiguration blocksConfig;
public BlockManager(SurvivalPlus plugin) {
this.plugin = plugin;
this.blocksFile = new File(plugin.getDataFolder(), "blocks.yml");
if (!blocksFile.exists()) {
try {
blocksFile.createNewFile();
} catch (IOException e) {
e.printStackTrace();
}
}
this.blocksConfig = YamlConfiguration.loadConfiguration(blocksFile);
loadBlocks();
}
private void saveBlocks() {
for (UUID key : blockedPlayers.keySet()) {
List<String> uuids = new ArrayList<>();
for (UUID uuid : blockedPlayers.get(key)) {
uuids.add(uuid.toString());
}
blocksConfig.set(key.toString(), uuids);
}
try {
blocksConfig.save(blocksFile);
} catch (IOException e) {
e.printStackTrace();
}
}
private void loadBlocks() {
blockedPlayers.clear();
for (String key : blocksConfig.getKeys(false)) {
UUID blockerUUID = UUID.fromString(key);
List<String> blockedUUIDs = blocksConfig.getStringList(key);
Set<UUID> blockedSet = new HashSet<>();
for (String uuidStr : blockedUUIDs) {
blockedSet.add(UUID.fromString(uuidStr));
}
blockedPlayers.put(blockerUUID, blockedSet);
}
}
public void blockPlayer(Player blocker, Player toBlock) {
blockedPlayers.computeIfAbsent(blocker.getUniqueId(), k -> new HashSet<>()).add(toBlock.getUniqueId());
saveBlocks(); // Sofort speichern
}
public void unblockPlayer(Player blocker, Player toUnblock) {
Set<UUID> blocked = blockedPlayers.get(blocker.getUniqueId());
if (blocked != null) {
blocked.remove(toUnblock.getUniqueId());
if (blocked.isEmpty()) {
blockedPlayers.remove(blocker.getUniqueId());
Set<UUID> blocked = blockedPlayers.get(blocker.getUniqueId());
if (blocked != null) {
blocked.remove(toUnblock.getUniqueId());
if (blocked.isEmpty()) {
blockedPlayers.remove(blocker.getUniqueId());
}
saveBlocks(); // Sofort speichern
}
}
}
public boolean hasBlocked(Player blocker, Player potentialBlocked) {
return blockedPlayers.getOrDefault(blocker.getUniqueId(), Collections.emptySet())
.contains(potentialBlocked.getUniqueId());
.contains(potentialBlocked.getUniqueId());
}
public Set<UUID> getBlockedPlayers(Player player) {
@@ -33,5 +86,6 @@ public class BlockManager {
public void clear(Player player) {
blockedPlayers.remove(player.getUniqueId());
saveBlocks();
}
}
}