Converted PlayerCommandEntry to new config.

This commit is contained in:
StevenLawson 2014-08-27 21:47:09 -04:00
parent 15ac9c013f
commit ab27c3e1d1
4 changed files with 40 additions and 54 deletions

View file

@ -34,8 +34,8 @@ public class BTC_ConfigLoader
{
private static final String SETTINGS_FILE = "settings.xml";
private final List<PlayerCommandEntry> playerCommands = new ArrayList<>();
private final ServerEntry.ServerEntryList servers = new ServerEntry.ServerEntryList();
private final PlayerCommandEntry.PlayerCommandEntryList playerCommands = new PlayerCommandEntry.PlayerCommandEntryList();
public BTC_ConfigLoader()
{
@ -92,9 +92,9 @@ public class BTC_ConfigLoader
return generateXML(new File(SETTINGS_FILE));
}
public List<PlayerCommandEntry> getCommands()
public Collection<PlayerCommandEntry> getCommands()
{
return this.playerCommands;
return this.playerCommands.getList();
}
public Collection<ServerEntry> getServers()
@ -111,7 +111,7 @@ public class BTC_ConfigLoader
final Element rootElement = doc.createElement("configuration");
doc.appendChild(rootElement);
rootElement.appendChild(PlayerCommandEntry.listToXML(this.playerCommands, doc));
rootElement.appendChild(this.playerCommands.toXML(doc));
rootElement.appendChild(this.servers.toXML(doc));
final Transformer transformer = TransformerFactory.newInstance().newTransformer();
@ -139,7 +139,7 @@ public class BTC_ConfigLoader
final Document doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(file);
doc.getDocumentElement().normalize();
if (!PlayerCommandEntry.xmlToList(this.playerCommands, doc))
if (!this.playerCommands.fromXML(doc))
{
System.out.println("Error loading playerCommands.");
hadErrors = true;

View file

@ -397,7 +397,7 @@ public class BTC_MainPanel extends javax.swing.JFrame
}
case "Copy UUID":
{
copyToClipboard(_player.getName());
copyToClipboard(_player.getUuid());
BTC_MainPanel.this.writeToConsole(new BTC_ConsoleMessage("Copied UUID to clipboard: " + _player.getUuid()));
break;
}

View file

@ -18,13 +18,16 @@
*/
package me.StevenLawson.BukkitTelnetClient;
import java.util.List;
import org.w3c.dom.*;
import java.util.HashSet;
public class PlayerCommandEntry
public class PlayerCommandEntry implements ConfigEntry
{
private final String name;
private final String format;
private String name;
private String format;
public PlayerCommandEntry()
{
}
public PlayerCommandEntry(String name, String format)
{
@ -32,64 +35,47 @@ public class PlayerCommandEntry
this.format = format;
}
@ConfigEntryList.ParameterGetter(name = "format")
public String getFormat()
{
return format;
}
@ConfigEntryList.ParameterSetter(name = "format")
public void setFormat(String format)
{
this.format = format;
}
@ConfigEntryList.ParameterGetter(name = "name")
public String getName()
{
return name;
}
public static Element listToXML(final List<PlayerCommandEntry> playerCommands, final Document doc)
@ConfigEntryList.ParameterSetter(name = "name")
public void setName(String name)
{
final Element plcElement = doc.createElement("playerCommands");
this.name = name;
}
for (final PlayerCommandEntry command : playerCommands)
public static class PlayerCommandEntryList extends ConfigEntryList<PlayerCommandEntry>
{
final Element commandElement = doc.createElement("playerCommand");
plcElement.appendChild(commandElement);
final Element commandName = doc.createElement("name");
commandName.appendChild(doc.createTextNode(command.getName()));
commandElement.appendChild(commandName);
final Element commandFormat = doc.createElement("format");
commandFormat.appendChild(doc.createTextNode(command.getFormat()));
commandElement.appendChild(commandFormat);
}
return plcElement;
}
public static boolean xmlToList(final List<PlayerCommandEntry> playerCommands, final Document doc)
public PlayerCommandEntryList()
{
NodeList playerCommandNodes = doc.getDocumentElement().getElementsByTagName("playerCommands");
if (playerCommandNodes.getLength() < 1)
super(new HashSet<PlayerCommandEntry>(), PlayerCommandEntry.class);
}
@Override
public String getParentElementName()
{
return false;
return "playerCommands";
}
playerCommandNodes = playerCommandNodes.item(0).getChildNodes();
playerCommands.clear();
for (int i = 0; i < playerCommandNodes.getLength(); i++)
@Override
public String getItemElementName()
{
final Node node = playerCommandNodes.item(i);
if (node.getNodeType() == Node.ELEMENT_NODE)
{
final Element element = (Element) node;
final PlayerCommandEntry command = new PlayerCommandEntry(
element.getElementsByTagName("name").item(0).getTextContent(),
element.getElementsByTagName("format").item(0).getTextContent()
);
playerCommands.add(command);
return "playerCommand";
}
}
return true;
}
}