-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Created config reader to work with MC config files outside of the FML environment
- Loading branch information
Showing
6 changed files
with
233 additions
and
73 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
src/main/java/com/superzanti/serversync/util/MCConfigReader/MCCArray.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package com.superzanti.serversync.util.MCConfigReader; | ||
|
||
import java.util.ArrayList; | ||
|
||
public class MCCArray extends ArrayList<MCCElement> { | ||
|
||
|
||
/** | ||
* | ||
*/ | ||
private static final long serialVersionUID = -8982760081192740589L; | ||
|
||
public MCCElement getElementByName(String name) { | ||
for (MCCElement e : this) { | ||
if (e.getName().equals(name)) { | ||
return e; | ||
} | ||
} | ||
return null; | ||
} | ||
} |
74 changes: 74 additions & 0 deletions
74
src/main/java/com/superzanti/serversync/util/MCConfigReader/MCCElement.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
package com.superzanti.serversync.util.MCConfigReader; | ||
|
||
import java.lang.reflect.Type; | ||
import java.util.ArrayList; | ||
|
||
public class MCCElement { | ||
private final String category; | ||
private Type type; | ||
private String value; | ||
private String name; | ||
private ArrayList<String> values; | ||
public final boolean isArray; | ||
|
||
public MCCElement(String category,String type,String name,String value) { | ||
this.category = category; | ||
this.name = name; | ||
setType(type); | ||
this.isArray = false; | ||
this.value = value; | ||
this.values = null; | ||
} | ||
|
||
public MCCElement(String category,String type,String name, ArrayList<String> values) { | ||
this.category = category; | ||
this.name = name; | ||
setType(type); | ||
this.values = values; | ||
this.isArray = true; | ||
this.value = null; | ||
} | ||
|
||
private void setType(String type) { | ||
if (type.equals("B")) { | ||
this.type = Boolean.class; | ||
} | ||
if (type.equals("S")) { | ||
this.type = String.class; | ||
} | ||
if (type.equals("I")) { | ||
this.type = Integer.class; | ||
} | ||
} | ||
|
||
public ArrayList<String> getList() { | ||
if (isArray) { | ||
return values; | ||
} | ||
return null; | ||
} | ||
|
||
public String getCategoryName() { | ||
return category; | ||
} | ||
|
||
public java.lang.reflect.Type getType() { | ||
return type; | ||
} | ||
|
||
public boolean getBoolean() { | ||
return Boolean.valueOf(value); | ||
} | ||
|
||
public String getName() { | ||
return name; | ||
} | ||
|
||
public String getString() { | ||
return value; | ||
} | ||
|
||
public int getInt() { | ||
return Integer.parseInt(value); | ||
} | ||
} |
82 changes: 82 additions & 0 deletions
82
src/main/java/com/superzanti/serversync/util/MCConfigReader/MCCReader.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
package com.superzanti.serversync.util.MCConfigReader; | ||
|
||
import java.io.BufferedReader; | ||
import java.io.IOException; | ||
import java.util.ArrayList; | ||
|
||
public class MCCReader extends BufferedReader { | ||
|
||
//TODO create separate server/client config files | ||
//TODO have server send handshake secure codes and remove from clients config | ||
|
||
public String category; | ||
|
||
public MCCReader(BufferedReader read) throws IOException { | ||
super(read); | ||
} | ||
|
||
public MCCElement readNextElement() throws IOException { | ||
String line; | ||
while ((line = this.readLine()) != null) { | ||
if (line.contains("#")) { | ||
continue; | ||
} | ||
if (line.contains("}")) { | ||
category = null; | ||
continue; | ||
} | ||
if (line.contains("{")) { | ||
String[] cat = line.trim().split(" "); | ||
// Should get category name | ||
category = cat[0]; | ||
// Move to next line | ||
continue; | ||
} | ||
if (line.contains(":") && line.contains("=")) { | ||
String type = getType(line); | ||
String name = getName(line); | ||
String value = getValue(line); | ||
return new MCCElement(category,type,name,value); | ||
} | ||
if (line.contains(":") && line.contains("<")) { | ||
String type = getType(line); | ||
String name = getName(line); | ||
return new MCCElement(category,type,name,getValues()); | ||
} | ||
} | ||
return null; | ||
} | ||
|
||
private ArrayList<String> getValues() throws IOException { | ||
ArrayList<String> temp = new ArrayList<String>(); | ||
String line; | ||
while (true) { | ||
line = this.readLine(); | ||
if (line.contains(">")) { | ||
break; | ||
} | ||
temp.add(line.replace(",", "").trim()); | ||
} | ||
return temp; | ||
} | ||
|
||
private String getType(String line) { | ||
String sub = line.substring(line.indexOf(":") - 1, line.indexOf(":")).trim(); | ||
return sub; | ||
} | ||
|
||
private String getName(String line) { | ||
String sub; | ||
if (line.contains("=")) { | ||
sub = line.substring(line.indexOf(":")+1,line.indexOf("=")).trim(); | ||
return sub; | ||
} | ||
sub = line.substring(line.indexOf(":")+1,line.indexOf("<")).trim(); | ||
return sub; | ||
} | ||
|
||
private String getValue(String line) { | ||
String sub = line.substring(line.indexOf("=")+1).trim(); | ||
return sub; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters