Add colors to world aliases

Now World aliases take priority over world folder names. Bit of cleanup
This commit is contained in:
Eric Stokes 2011-06-26 19:50:40 -06:00
parent 1a31fca6a7
commit a62d341d8f
5 changed files with 85 additions and 53 deletions

View File

@ -3,7 +3,9 @@ package com.onarandombox.MultiverseCore;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.logging.Level;
import org.bukkit.ChatColor;
import org.bukkit.World;
import org.bukkit.World.Environment;
import org.bukkit.util.config.Configuration;
@ -19,23 +21,24 @@ public class MVWorld {
private String name; // The Worlds Name, EG its folder name.
private String alias = ""; // Short Alias for the World, this will be used in Chat Prefixes.
private ChatColor aliasColor; // Color for this world
private boolean allowAnimals; // Does this World allow Animals to Spawn?
//public List<String> animals = new ArrayList<String>(); // Contain a list of Animals which we want to ignore the Spawn Setting.
// public List<String> animals = new ArrayList<String>(); // Contain a list of Animals which we want to ignore the Spawn Setting.
private boolean allowMonsters; // Does this World allow Monsters to Spawn?
//public List<String> monsters = new ArrayList<String>(); // Contain a list of Monsters which we want to ignore the Spawn Setting.
// public List<String> monsters = new ArrayList<String>(); // Contain a list of Monsters which we want to ignore the Spawn Setting.
private Boolean pvp; // Does this World allow PVP?
private List<Integer> blockBlacklist; // Contain a list of Blocks which we won't allow on this World.
// These have been moved to a hash, for easy editing with strings.
// private List<String> playerWhitelist; // Contain a list of Players/Groups which can join this World.
// private List<String> playerBlacklist; // Contain a list of Players/Groups which cannot join this World.
// private List<String> editWhitelist; // Contain a list of Players/Groups which can edit this World. (Place/Destroy Blocks)
// private List<String> editBlacklist; // Contain a list of Players/Groups which cannot edit this World. (Place/Destroy Blocks)
// private List<String> worldBlacklist; // Contain a list of Worlds which Players cannot use to Portal to this World.
// private List<String> playerWhitelist; // Contain a list of Players/Groups which can join this World.
// private List<String> playerBlacklist; // Contain a list of Players/Groups which cannot join this World.
// private List<String> editWhitelist; // Contain a list of Players/Groups which can edit this World. (Place/Destroy Blocks)
// private List<String> editBlacklist; // Contain a list of Players/Groups which cannot edit this World. (Place/Destroy Blocks)
// private List<String> worldBlacklist; // Contain a list of Worlds which Players cannot use to Portal to this World.
private HashMap<String, List<String>> masterList;
@ -69,7 +72,8 @@ public class MVWorld {
config.setProperty("worlds." + this.name + ".environment", this.environment.toString());
// Set local values that CAN be changed by the user
this.setAlias(config.getString("worlds." + this.name + ".alias", ""));
this.setAlias(config.getString("worlds." + this.name + ".alias.name", ""));
this.setAliasColor(config.getString("worlds." + this.name + ".alias.color", ChatColor.WHITE.toString()));
this.setPvp(config.getBoolean("worlds." + this.name + ".pvp", true));
this.setScaling(config.getDouble("worlds." + this.name + ".scale", 1.0));
@ -326,7 +330,7 @@ public class MVWorld {
public void setAlias(String alias) {
this.alias = alias;
this.config.setProperty("worlds." + this.name + ".alias", alias);
this.config.setProperty("worlds." + this.name + ".alias.name", alias);
this.config.save();
}
@ -415,4 +419,58 @@ public class MVWorld {
this.config.setProperty("worlds." + this.name + ".scaling", scaling);
this.config.save();
}
public void setAliasColor(String aliasColor) {
this.aliasColor = translateStringToChatColor(aliasColor);
if (this.aliasColor != null) {
this.config.setProperty("worlds." + this.name + ".alias.color", aliasColor);
this.config.save();
} else {
this.plugin.log(Level.WARNING, "Color \"" + aliasColor + "\" was not found.");
this.aliasColor = ChatColor.WHITE;
}
return;
}
public ChatColor getAliasColor() {
return this.aliasColor;
}
// I disgust myself. Seriously is there not a better way?
private ChatColor translateStringToChatColor(String color) {
if (color.equalsIgnoreCase("aqua"))
return ChatColor.AQUA;
if (color.equalsIgnoreCase("aqua"))
return ChatColor.BLACK;
if (color.equalsIgnoreCase("blue"))
return ChatColor.BLUE;
if (color.equalsIgnoreCase("darkaqua"))
return ChatColor.DARK_AQUA;
if (color.equalsIgnoreCase("darkblue"))
return ChatColor.DARK_BLUE;
if (color.equalsIgnoreCase("darkgray"))
return ChatColor.DARK_GRAY;
if (color.equalsIgnoreCase("darkgreen"))
return ChatColor.DARK_GREEN;
if (color.equalsIgnoreCase("darkpurple"))
return ChatColor.DARK_PURPLE;
if (color.equalsIgnoreCase("darkred"))
return ChatColor.DARK_RED;
if (color.equalsIgnoreCase("gold"))
return ChatColor.GOLD;
if (color.equalsIgnoreCase("gray"))
return ChatColor.GRAY;
if (color.equalsIgnoreCase("green"))
return ChatColor.GREEN;
if (color.equalsIgnoreCase("lightpurple"))
return ChatColor.LIGHT_PURPLE;
if (color.equalsIgnoreCase("red"))
return ChatColor.RED;
if (color.equalsIgnoreCase("yellow"))
return ChatColor.YELLOW;
if (color.equalsIgnoreCase("white"))
return ChatColor.WHITE;
return null;
}
}

View File

@ -49,7 +49,6 @@ import com.onarandombox.MultiverseCore.command.QueuedCommand;
import com.onarandombox.MultiverseCore.command.commands.*;
import com.onarandombox.MultiverseCore.configuration.DefaultConfiguration;
import com.onarandombox.utils.DebugLog;
import com.onarandombox.utils.Messaging;
import com.onarandombox.utils.UpdateChecker;
public class MultiverseCore extends JavaPlugin {
@ -66,9 +65,6 @@ public class MultiverseCore extends JavaPlugin {
private final String tag = "[Multiverse-Core]";
// Messaging
private Messaging messaging = new Messaging();
// Multiverse Permissions Handler
public MVPermissions ph = new MVPermissions(this);
@ -115,16 +111,16 @@ public class MultiverseCore extends JavaPlugin {
@Override
public void onEnable() {
// Output a little snippet to show it's enabled.
log(Level.INFO, "- Version " + this.getDescription().getVersion() + " Enabled - By " + getAuthors());
this.log(Level.INFO, "- Version " + this.getDescription().getVersion() + " Enabled - By " + getAuthors());
// Setup all the Events the plugin needs to Monitor.
registerEvents();
this.registerEvents();
// Setup Permissions, we'll do an initial check for the Permissions plugin then fall back on isOP().
setupPermissions();
this.setupPermissions();
// Setup iConomy.
setupEconomy();
this.setupEconomy();
// Call the Function to assign all the Commands to their Class.
registerCommands();
this.registerCommands();
// Start the Update Checker
// updateCheck = new UpdateChecker(this.getDescription().getName(), this.getDescription().getVersion());
@ -132,10 +128,10 @@ public class MultiverseCore extends JavaPlugin {
// Call the Function to load all the Worlds and setup the HashMap
// When called with null, it tries to load ALL
// this function will be called every time a plugin registers a new envtype with MV
loadWorlds(null);
this.loadWorlds(true);
// Purge Worlds of old Monsters/Animals which don't adhere to the setup.
purgeWorlds();
this.purgeWorlds();
}
/**
@ -309,12 +305,16 @@ public class MultiverseCore extends JavaPlugin {
/**
* Load the Worlds & Settings from the configuration file.
*/
public void loadWorlds(String filter) {
public void loadWorlds(boolean forceLoad) {
// Basic Counter to count how many Worlds we are loading.
int count = 0;
// Grab all the Worlds from the Config.
List<String> worldKeys = this.configWorlds.getKeys("worlds");
if(forceLoad) {
this.worlds.clear();
}
// Check that the list is not null.
if (worldKeys != null) {
for (String worldKey : worldKeys) {
@ -599,10 +599,6 @@ public class MultiverseCore extends JavaPlugin {
debugLog.log(level, "[Debug] " + msg);
}
public Messaging getMessaging() {
return this.messaging;
}
/**
* Parse the Authors Array into a readable String with ',' and 'and'.
*

View File

@ -46,8 +46,11 @@ public class ListCommand extends BaseCommand {
} else if (env == Environment.SKYLANDS) {
color = ChatColor.AQUA;
}
output += ChatColor.WHITE + world.getName() + " - " + color + world.getEnvironment() + " \n";
String worldName = world.getName();
if(world.getAlias() != null && world.getAlias().length() > 0) {
worldName = world.getAliasColor() + world.getAlias() + ChatColor.WHITE;
}
output += ChatColor.WHITE + worldName + " - " + color + world.getEnvironment() + " \n";
}
String[] response = output.split("\n");

View File

@ -25,7 +25,7 @@ public class ReloadCommand extends BaseCommand {
public void execute(CommandSender sender, String[] args) {
this.plugin.log(Level.INFO, "Reloading Multiverse-Core config");
this.plugin.loadConfigs();
this.plugin.loadWorlds(null);
this.plugin.loadWorlds(true);
this.plugin.log(Level.INFO, "Reload Complete!");
}

View File

@ -1,25 +0,0 @@
package com.onarandombox.utils;
import org.bukkit.command.CommandSender;
import com.onarandombox.MultiverseCore.MultiverseCore;
public class Messaging {
public void send(CommandSender player, String msg, String... params) {
player.sendMessage(parameterizeMessage(msg, params));
}
public void broadcast(MultiverseCore plugin, String msg, String... params) {
plugin.getServer().broadcastMessage(parameterizeMessage(msg, params));
}
private String parameterizeMessage(String msg, String... params) {
msg = "§cHeroes: " + msg;
for (int i = 0; i < params.length; i++) {
msg = msg.replace("$" + (i + 1), "§f" + params[i] + "§c");
}
return msg;
}
}