Option to treat hiddenplayers.txt as a whitelist.

This commit is contained in:
zeeZ 2011-04-11 04:10:47 +02:00
parent ab6352a17d
commit 69fcc1706e
3 changed files with 15 additions and 9 deletions

View File

@ -1,5 +1,8 @@
# All paths in this configuration file are relative to Dynmap's data-folder: minecraft_server/plugins/dynmap/
# Treat hiddenplayers.txt as a whitelist for players to be shown on the map? (Default false)
display-whitelist: false
# How often a tile gets rendered (in seconds).
renderinterval: 1

View File

@ -88,7 +88,7 @@ public class DynmapPlugin extends JavaPlugin {
log.warning("Could not create directory for tiles ('" + tilesDirectory + "').");
}
playerList = new PlayerList(getServer(), getFile("hiddenplayers.txt"));
playerList = new PlayerList(getServer(), getFile("hiddenplayers.txt"), configuration);
playerList.load();
mapManager = new MapManager(this, configuration);
@ -320,13 +320,13 @@ public class DynmapPlugin extends JavaPlugin {
} else if (c.equals("hide")) {
if (args.length == 1) {
if(player != null && checkPlayerPermission(sender,"hide.self")) {
playerList.hide(player.getName());
playerList.setVisible(player.getName(),false);
sender.sendMessage("You are now hidden on Dynmap.");
return true;
}
} else if (checkPlayerPermission(sender,"hide.others")) {
for (int i = 1; i < args.length; i++) {
playerList.hide(args[i]);
playerList.setVisible(args[i],false);
sender.sendMessage(args[i] + " is now hidden on Dynmap.");
}
return true;
@ -334,13 +334,13 @@ public class DynmapPlugin extends JavaPlugin {
} else if (c.equals("show")) {
if (args.length == 1) {
if(player != null && checkPlayerPermission(sender,"show.self")) {
playerList.show(player.getName());
playerList.setVisible(player.getName(),true);
sender.sendMessage("You are now visible on Dynmap.");
return true;
}
} else if (checkPlayerPermission(sender,"show.others")) {
for (int i = 1; i < args.length; i++) {
playerList.show(args[i]);
playerList.setVisible(args[i],true);
sender.sendMessage(args[i] + " is now visible on Dynmap.");
}
return true;

View File

@ -12,15 +12,18 @@ import java.util.Scanner;
import org.bukkit.Server;
import org.bukkit.entity.Player;
import org.bukkit.util.config.Configuration;
public class PlayerList {
private Server server;
private HashSet<String> hiddenPlayerNames = new HashSet<String>();
private File hiddenPlayersFile;
private Configuration configuration;
public PlayerList(Server server, File hiddenPlayersFile) {
public PlayerList(Server server, File hiddenPlayersFile, Configuration configuration) {
this.server = server;
this.hiddenPlayersFile = hiddenPlayersFile;
this.configuration = configuration;
}
public void save() {
@ -63,7 +66,7 @@ public class PlayerList {
}
public void setVisible(String playerName, boolean visible) {
if (visible)
if (visible ^ configuration.getBoolean("display-whitelist", false))
show(playerName);
else
hide(playerName);
@ -75,7 +78,7 @@ public class PlayerList {
Player[] onlinePlayers = server.getOnlinePlayers();
for (int i = 0; i < onlinePlayers.length; i++) {
Player p = onlinePlayers[i];
if (p.getWorld().getName().equals(worldName) && !hiddenPlayerNames.contains(p.getName().toLowerCase())) {
if (p.getWorld().getName().equals(worldName) && !(configuration.getBoolean("display-whitelist", false) ^ hiddenPlayerNames.contains(p.getName().toLowerCase()))) {
visiblePlayers.add(p);
}
}
@ -89,7 +92,7 @@ public class PlayerList {
Player[] onlinePlayers = server.getOnlinePlayers();
for (int i = 0; i < onlinePlayers.length; i++) {
Player p = onlinePlayers[i];
if (!hiddenPlayerNames.contains(p.getName().toLowerCase())) {
if (!(configuration.getBoolean("display-whitelist", false) ^ hiddenPlayerNames.contains(p.getName().toLowerCase()))) {
visiblePlayers.add(p);
}
}