2014-07-09 03:08:37 +02:00
|
|
|
package mineplex.mapparser;
|
|
|
|
|
|
|
|
import java.io.BufferedReader;
|
|
|
|
import java.io.BufferedWriter;
|
|
|
|
import java.io.DataInputStream;
|
|
|
|
import java.io.File;
|
|
|
|
import java.io.FileInputStream;
|
|
|
|
import java.io.FileWriter;
|
|
|
|
import java.io.InputStreamReader;
|
|
|
|
import java.util.HashSet;
|
|
|
|
|
|
|
|
import org.bukkit.entity.Player;
|
|
|
|
|
|
|
|
public class MapData
|
|
|
|
{
|
|
|
|
public String MapFolder;
|
|
|
|
|
2014-08-20 04:06:24 +02:00
|
|
|
public GameType MapGameType = null;
|
2014-07-09 03:08:37 +02:00
|
|
|
public String MapName = "null";
|
|
|
|
public String MapCreator = "null";
|
|
|
|
|
2014-08-20 03:02:12 +02:00
|
|
|
public HashSet<String> AdminList;
|
2014-07-09 03:08:37 +02:00
|
|
|
|
|
|
|
public MapData(String mapFolder)
|
|
|
|
{
|
|
|
|
MapFolder = mapFolder;
|
|
|
|
|
2014-08-20 03:02:12 +02:00
|
|
|
AdminList = new HashSet<String>();
|
2014-07-09 03:08:37 +02:00
|
|
|
|
|
|
|
if ((new File(MapFolder + File.separator + "Map.dat")).exists())
|
|
|
|
Read();
|
|
|
|
else
|
|
|
|
Write();
|
|
|
|
}
|
|
|
|
|
|
|
|
public void Read()
|
|
|
|
{
|
|
|
|
String line = null;
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
FileInputStream fstream = new FileInputStream(MapFolder + File.separator + "Map.dat");
|
|
|
|
DataInputStream in = new DataInputStream(fstream);
|
|
|
|
BufferedReader br = new BufferedReader(new InputStreamReader(in));
|
|
|
|
|
|
|
|
while ((line = br.readLine()) != null)
|
|
|
|
{
|
|
|
|
String[] tokens = line.split(":");
|
|
|
|
|
|
|
|
if (tokens.length < 2)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (tokens[0].length() == 0)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
//Name & Author
|
|
|
|
if (tokens[0].equalsIgnoreCase("MAP_NAME"))
|
|
|
|
{
|
|
|
|
MapName = tokens[1];
|
|
|
|
}
|
|
|
|
else if (tokens[0].equalsIgnoreCase("MAP_AUTHOR"))
|
|
|
|
{
|
|
|
|
MapCreator = tokens[1];
|
|
|
|
}
|
|
|
|
else if (tokens[0].equalsIgnoreCase("GAME_TYPE"))
|
|
|
|
{
|
2014-08-20 04:06:24 +02:00
|
|
|
try
|
|
|
|
{
|
|
|
|
MapGameType = GameType.valueOf(tokens[1] == null ? "Unknown" : tokens[1]);
|
|
|
|
}
|
|
|
|
catch (Exception e)
|
|
|
|
{
|
|
|
|
MapGameType = GameType.Unknown;
|
|
|
|
}
|
2014-07-09 03:08:37 +02:00
|
|
|
}
|
2014-08-20 04:06:24 +02:00
|
|
|
else if (tokens[0].equalsIgnoreCase("ADMIN_LIST") || tokens[0].equalsIgnoreCase("BUILD_LIST"))
|
2014-07-09 03:08:37 +02:00
|
|
|
{
|
|
|
|
for (String cur : tokens[1].split(","))
|
2014-08-20 03:02:12 +02:00
|
|
|
AdminList.add(cur);
|
2014-07-09 03:08:37 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
in.close();
|
|
|
|
}
|
|
|
|
catch (Exception e)
|
|
|
|
{
|
|
|
|
e.printStackTrace();
|
|
|
|
System.err.println("Line: " + line);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void Write()
|
|
|
|
{
|
|
|
|
//Save
|
|
|
|
try
|
|
|
|
{
|
|
|
|
FileWriter fstream = new FileWriter(MapFolder + File.separator + "Map.dat");
|
|
|
|
BufferedWriter out = new BufferedWriter(fstream);
|
|
|
|
|
|
|
|
out.write("MAP_NAME:"+MapName);
|
|
|
|
out.write("\n");
|
|
|
|
out.write("MAP_AUTHOR:"+MapCreator);
|
|
|
|
out.write("\n");
|
2014-08-20 04:06:24 +02:00
|
|
|
out.write("GAME_TYPE:"+MapGameType);
|
2014-07-09 03:08:37 +02:00
|
|
|
|
2014-08-20 03:02:12 +02:00
|
|
|
String adminList = "";
|
|
|
|
for (String cur : AdminList)
|
|
|
|
adminList += cur + ",";
|
2014-07-09 03:08:37 +02:00
|
|
|
|
|
|
|
out.write("\n");
|
2014-08-20 03:02:12 +02:00
|
|
|
out.write("ADMIN_LIST:"+adminList);
|
2014-07-09 03:08:37 +02:00
|
|
|
|
|
|
|
out.close();
|
|
|
|
}
|
|
|
|
catch (Exception e)
|
|
|
|
{
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-08-20 03:02:12 +02:00
|
|
|
public boolean HasAccess(Player player)
|
2014-07-09 03:08:37 +02:00
|
|
|
{
|
2014-08-20 03:02:12 +02:00
|
|
|
return AdminList.contains(player.getName()) || player.isOp();
|
2014-07-09 03:08:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public boolean CanJoin(Player player)
|
|
|
|
{
|
2014-08-16 22:55:29 +02:00
|
|
|
return true;
|
2014-07-09 03:08:37 +02:00
|
|
|
}
|
2014-08-16 22:50:33 +02:00
|
|
|
|
|
|
|
public boolean CanRename(Player player)
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
2014-07-09 03:08:37 +02:00
|
|
|
}
|