private static ServerInfo createServerFromTag(CompoundMap compound){ String ipString, ip, name, icon = null; int port; ipString = compound.get("ip").getValue().toString(); name = compound.get("name").getValue().toString(); if(ipString.contains(":")){ ip = ipString.split(":")[0]; port = Integer.parseInt(ipString.split(":")[1]); } else { ip = ipString; port = DEFAULT_PORT; } if(compound.containsKey("icon")){ icon = ((StringTag)compound.get("icon")).getValue(); } return new ServerInfo(ip, name, icon,port); }
/** * Get this field from a CompoundTag * * @param tag The tag to get this field from * @return The value */ public T load(CompoundTag tag) { Tag subTag = tag.getValue().get(key); if (subTag == null) { return (value = defaultValue); } return (value = field.getValue(subTag)); }
/** * Get this field from a CompoundTag * * @param tag The tag to get this field from * @return The value */ public T load(CompoundTag tag) { Tag subTag = tag.getValue().get(key); if (subTag == null) { return (value = defaultValue); } return (value = field.getValue(subTag)); }
/** * Get this field from a CompoundTag * * @param tag The tag to get this field from * @return The value */ public T load(CompoundTag tag) { Tag subTag = tag.getValue().get(key); if (subTag == null) { return (value = defaultValue); } return (value = field.getValue(subTag)); }
public ServerInfo[] loadServers() throws Exception{ final FileInputStream fis = new FileInputStream(file); NBTInputStream nbtIs = new NBTInputStream(fis, false); // the cast should be safe, because compound tag is also a root container of contents in the file... final CompoundTag root = (CompoundTag) nbtIs.readTag(); nbtIs.close(); ListTag serversListTag = (ListTag) root.getValue().get("servers"); if(serversListTag.getElementType() != CompoundTag.class) { throw new Exception("Type of list value in servers file is not tag_compound!"); } List<CompoundTag> serversList = serversListTag.getValue(); ServerInfo[] result = new ServerInfo[serversList.size()]; for(int i = 0; i < serversList.size(); ++i){ result[i] = createServerFromTag(serversList.get(i).getValue()); } return result; }