mirror of
https://github.com/TotalFreedomMC/ZeroTelnetClient.git
synced 2024-12-22 16:25:14 +00:00
Converted PlayerCommandEntry to new config.
This commit is contained in:
parent
15ac9c013f
commit
ab27c3e1d1
4 changed files with 40 additions and 54 deletions
|
@ -34,8 +34,8 @@ public class BTC_ConfigLoader
|
||||||
{
|
{
|
||||||
private static final String SETTINGS_FILE = "settings.xml";
|
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 ServerEntry.ServerEntryList servers = new ServerEntry.ServerEntryList();
|
||||||
|
private final PlayerCommandEntry.PlayerCommandEntryList playerCommands = new PlayerCommandEntry.PlayerCommandEntryList();
|
||||||
|
|
||||||
public BTC_ConfigLoader()
|
public BTC_ConfigLoader()
|
||||||
{
|
{
|
||||||
|
@ -92,9 +92,9 @@ public class BTC_ConfigLoader
|
||||||
return generateXML(new File(SETTINGS_FILE));
|
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()
|
public Collection<ServerEntry> getServers()
|
||||||
|
@ -111,7 +111,7 @@ public class BTC_ConfigLoader
|
||||||
final Element rootElement = doc.createElement("configuration");
|
final Element rootElement = doc.createElement("configuration");
|
||||||
doc.appendChild(rootElement);
|
doc.appendChild(rootElement);
|
||||||
|
|
||||||
rootElement.appendChild(PlayerCommandEntry.listToXML(this.playerCommands, doc));
|
rootElement.appendChild(this.playerCommands.toXML(doc));
|
||||||
rootElement.appendChild(this.servers.toXML(doc));
|
rootElement.appendChild(this.servers.toXML(doc));
|
||||||
|
|
||||||
final Transformer transformer = TransformerFactory.newInstance().newTransformer();
|
final Transformer transformer = TransformerFactory.newInstance().newTransformer();
|
||||||
|
@ -139,7 +139,7 @@ public class BTC_ConfigLoader
|
||||||
final Document doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(file);
|
final Document doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(file);
|
||||||
doc.getDocumentElement().normalize();
|
doc.getDocumentElement().normalize();
|
||||||
|
|
||||||
if (!PlayerCommandEntry.xmlToList(this.playerCommands, doc))
|
if (!this.playerCommands.fromXML(doc))
|
||||||
{
|
{
|
||||||
System.out.println("Error loading playerCommands.");
|
System.out.println("Error loading playerCommands.");
|
||||||
hadErrors = true;
|
hadErrors = true;
|
||||||
|
|
|
@ -422,4 +422,4 @@
|
||||||
</SubComponents>
|
</SubComponents>
|
||||||
</Container>
|
</Container>
|
||||||
</SubComponents>
|
</SubComponents>
|
||||||
</Form>
|
</Form>
|
||||||
|
|
|
@ -397,7 +397,7 @@ public class BTC_MainPanel extends javax.swing.JFrame
|
||||||
}
|
}
|
||||||
case "Copy UUID":
|
case "Copy UUID":
|
||||||
{
|
{
|
||||||
copyToClipboard(_player.getName());
|
copyToClipboard(_player.getUuid());
|
||||||
BTC_MainPanel.this.writeToConsole(new BTC_ConsoleMessage("Copied UUID to clipboard: " + _player.getUuid()));
|
BTC_MainPanel.this.writeToConsole(new BTC_ConsoleMessage("Copied UUID to clipboard: " + _player.getUuid()));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,13 +18,16 @@
|
||||||
*/
|
*/
|
||||||
package me.StevenLawson.BukkitTelnetClient;
|
package me.StevenLawson.BukkitTelnetClient;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.HashSet;
|
||||||
import org.w3c.dom.*;
|
|
||||||
|
|
||||||
public class PlayerCommandEntry
|
public class PlayerCommandEntry implements ConfigEntry
|
||||||
{
|
{
|
||||||
private final String name;
|
private String name;
|
||||||
private final String format;
|
private String format;
|
||||||
|
|
||||||
|
public PlayerCommandEntry()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
public PlayerCommandEntry(String name, String format)
|
public PlayerCommandEntry(String name, String format)
|
||||||
{
|
{
|
||||||
|
@ -32,64 +35,47 @@ public class PlayerCommandEntry
|
||||||
this.format = format;
|
this.format = format;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ConfigEntryList.ParameterGetter(name = "format")
|
||||||
public String getFormat()
|
public String getFormat()
|
||||||
{
|
{
|
||||||
return format;
|
return format;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ConfigEntryList.ParameterSetter(name = "format")
|
||||||
|
public void setFormat(String format)
|
||||||
|
{
|
||||||
|
this.format = format;
|
||||||
|
}
|
||||||
|
|
||||||
|
@ConfigEntryList.ParameterGetter(name = "name")
|
||||||
public String getName()
|
public String getName()
|
||||||
{
|
{
|
||||||
return name;
|
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)
|
|
||||||
{
|
|
||||||
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 static class PlayerCommandEntryList extends ConfigEntryList<PlayerCommandEntry>
|
||||||
{
|
{
|
||||||
NodeList playerCommandNodes = doc.getDocumentElement().getElementsByTagName("playerCommands");
|
public PlayerCommandEntryList()
|
||||||
if (playerCommandNodes.getLength() < 1)
|
|
||||||
{
|
{
|
||||||
return false;
|
super(new HashSet<PlayerCommandEntry>(), PlayerCommandEntry.class);
|
||||||
}
|
|
||||||
playerCommandNodes = playerCommandNodes.item(0).getChildNodes();
|
|
||||||
|
|
||||||
playerCommands.clear();
|
|
||||||
|
|
||||||
for (int i = 0; i < playerCommandNodes.getLength(); i++)
|
|
||||||
{
|
|
||||||
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 true;
|
@Override
|
||||||
|
public String getParentElementName()
|
||||||
|
{
|
||||||
|
return "playerCommands";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getItemElementName()
|
||||||
|
{
|
||||||
|
return "playerCommand";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue