Map Parser update.

This commit is contained in:
TadahTech 2016-07-18 19:00:11 -05:00
parent 370b0693d9
commit 36f2873e15
32 changed files with 1677 additions and 867 deletions

View File

@ -38,6 +38,7 @@ public enum GameType
Micro("Micro Battle"), Micro("Micro Battle"),
MineStrike("MineStrike"), MineStrike("MineStrike"),
MineWare("MineWare"), MineWare("MineWare"),
MinecraftLeague("MCL"),
MilkCow("Milk the Cow"), MilkCow("Milk the Cow"),
MonsterLeague("MonsterLeague"), MonsterLeague("MonsterLeague"),
MonsterMaze("Monster Maze"), MonsterMaze("Monster Maze"),
@ -53,6 +54,7 @@ public enum GameType
SmashDomination("Super Smash Mobs Domination", "Super Smash Mobs"), SmashDomination("Super Smash Mobs Domination", "Super Smash Mobs"),
Snake("Snake"), Snake("Snake"),
SneakyAssassins("Sneaky Assassins"), SneakyAssassins("Sneaky Assassins"),
SpeedBuilders("SpeedBuilders"),
SnowFight("Snow Fight"), SnowFight("Snow Fight"),
Spleef("Super Spleef"), Spleef("Super Spleef"),
SpleefTeams("Super Spleef Teams"), SpleefTeams("Super Spleef Teams"),

View File

@ -0,0 +1,60 @@
package mineplex.mapparser;
import mineplex.core.common.util.C;
import mineplex.core.common.util.F;
import net.md_5.bungee.api.ChatColor;
import org.bukkit.entity.Player;
import java.util.List;
/**
*
*/
public class GameTypeInfo
{
private final String LINE = C.cAqua + C.Bold + C.Strike + "========================================";
private GameType _gameType;
private List<String> _info;
public GameTypeInfo(GameType gameType, List<String> info)
{
_gameType = gameType;
_info = info;
}
public void addInfo(String info)
{
_info.add(info);
}
public void remove(int index)
{
_info.remove(index);
}
public List<String> getInfo()
{
return _info;
}
public void sendInfo(Player player)
{
player.sendMessage(LINE);
player.sendMessage(" ");
player.sendMessage(F.elem(_gameType.GetName()));
player.sendMessage(" ");
for(String s : _info)
{
player.sendMessage(ChatColor.translateAlternateColorCodes('&', s));
}
player.sendMessage(" ");
player.sendMessage(LINE);
}
public GameType getGameType()
{
return _gameType;
}
}

View File

@ -1,5 +1,11 @@
package mineplex.mapparser; package mineplex.mapparser;
import com.google.common.collect.Maps;
import com.google.common.collect.Sets;
import mineplex.core.common.util.UtilWorld;
import org.bukkit.Location;
import org.bukkit.entity.Player;
import java.io.BufferedReader; import java.io.BufferedReader;
import java.io.BufferedWriter; import java.io.BufferedWriter;
import java.io.DataInputStream; import java.io.DataInputStream;
@ -7,31 +13,40 @@ import java.io.File;
import java.io.FileInputStream; import java.io.FileInputStream;
import java.io.FileWriter; import java.io.FileWriter;
import java.io.InputStreamReader; import java.io.InputStreamReader;
import java.util.HashSet; import java.util.Collections;
import java.util.Map;
import org.bukkit.entity.Player; import java.util.Map.Entry;
import java.util.Set;
public class MapData public class MapData
{ {
public String MapFolder; public String MapFolder;
public boolean _currentlyLive;
public boolean _locked;
public Map<String, Location> _warps;
public GameType MapGameType = null; public GameType MapGameType = null;
public String MapName = "null"; public String MapName = "null";
public String MapCreator = "null"; public String MapCreator = "null";
public HashSet<String> AdminList; public Set<String> AdminList;
public MapData(String mapFolder) public MapData(String mapFolder)
{ {
MapFolder = mapFolder; MapFolder = mapFolder;
AdminList = new HashSet<String>(); AdminList = Sets.newHashSet();
_warps = Maps.newHashMap();
_currentlyLive = false;
if ((new File(MapFolder + File.separator + "Map.dat")).exists()) if ((new File(MapFolder + File.separator + "Map.dat")).exists())
{
Read(); Read();
else } else
{
Write(); Write();
} }
}
public void Read() public void Read()
{ {
@ -48,41 +63,69 @@ public class MapData
String[] tokens = line.split(":"); String[] tokens = line.split(":");
if (tokens.length < 2) if (tokens.length < 2)
{
continue; continue;
}
if (tokens[0].length() == 0) if (tokens[0].length() == 0)
{
continue; continue;
}
if(tokens[0].equalsIgnoreCase("locked"))
{
_locked = tokens[1].equalsIgnoreCase("true");
continue;
}
if (tokens[0].equalsIgnoreCase("currentlyLive"))
{
_currentlyLive = tokens[1].equalsIgnoreCase("true");
continue;
}
if (tokens[0].equalsIgnoreCase("warps"))
{
for (String s : tokens[1].split(";"))
{
String[] str = s.split("@");
_warps.put(str[0], UtilWorld.strToLoc(str[1]));
}
continue;
}
//Name & Author //Name & Author
if (tokens[0].equalsIgnoreCase("MAP_NAME")) if (tokens[0].equalsIgnoreCase("MAP_NAME"))
{ {
MapName = tokens[1]; MapName = tokens[1];
continue;
} }
else if (tokens[0].equalsIgnoreCase("MAP_AUTHOR"))
if (tokens[0].equalsIgnoreCase("MAP_AUTHOR"))
{ {
MapCreator = tokens[1]; MapCreator = tokens[1];
continue;
} }
else if (tokens[0].equalsIgnoreCase("GAME_TYPE"))
if (tokens[0].equalsIgnoreCase("GAME_TYPE"))
{ {
try try
{ {
MapGameType = GameType.valueOf(tokens[1] == null ? "Unknown" : tokens[1]); MapGameType = GameType.valueOf(tokens[1] == null ? "Unknown" : tokens[1]);
} } catch (Exception e)
catch (Exception e)
{ {
MapGameType = GameType.Unknown; MapGameType = GameType.Unknown;
} }
continue;
} }
else if (tokens[0].equalsIgnoreCase("ADMIN_LIST") || tokens[0].equalsIgnoreCase("BUILD_LIST")) if (tokens[0].equalsIgnoreCase("ADMIN_LIST") || tokens[0].equalsIgnoreCase("BUILD_LIST"))
{ {
for (String cur : tokens[1].split(",")) Collections.addAll(AdminList, tokens[1].split(","));
AdminList.add(cur);
} }
} }
in.close(); in.close();
} } catch (Exception e)
catch (Exception e)
{ {
e.printStackTrace(); e.printStackTrace();
System.err.println("Line: " + line); System.err.println("Line: " + line);
@ -97,27 +140,48 @@ public class MapData
FileWriter fstream = new FileWriter(MapFolder + File.separator + "Map.dat"); FileWriter fstream = new FileWriter(MapFolder + File.separator + "Map.dat");
BufferedWriter out = new BufferedWriter(fstream); BufferedWriter out = new BufferedWriter(fstream);
out.write("MAP_NAME:"+MapName); out.write("MAP_NAME:" + MapName);
out.write("\n"); out.write("\n");
out.write("MAP_AUTHOR:"+MapCreator); out.write("MAP_AUTHOR:" + MapCreator);
out.write("\n"); out.write("\n");
out.write("GAME_TYPE:"+MapGameType); out.write("GAME_TYPE:" + MapGameType);
String adminList = ""; String adminList = "";
for (String cur : AdminList) for (String cur : AdminList)
{
adminList += cur + ","; adminList += cur + ",";
}
out.write("\n"); out.write("\n");
out.write("ADMIN_LIST:"+adminList); out.write("ADMIN_LIST:" + adminList);
out.write("\n");
out.write("currentlyLive:" + _currentlyLive);
out.write("\n");
out.write("warps:" + warpsToString());
out.close(); out.close();
} } catch (Exception e)
catch (Exception e)
{ {
e.printStackTrace(); e.printStackTrace();
} }
} }
public String warpsToString()
{
StringBuilder builder = new StringBuilder();
int i = 0;
for (Entry<String, Location> entry : _warps.entrySet())
{
builder.append(entry.getKey()).append("@").append(UtilWorld.locToStr(entry.getValue()));
if (++i != _warps.size())
{
builder.append(",");
}
}
return builder.toString();
}
public boolean HasAccess(Player player) public boolean HasAccess(Player player)
{ {
return AdminList.contains(player.getName()) || player.isOp(); return AdminList.contains(player.getName()) || player.isOp();
@ -125,11 +189,11 @@ public class MapData
public boolean CanJoin(Player player) public boolean CanJoin(Player player)
{ {
return true; return !_locked || (player.isOp() || AdminList.contains(player.getName()));
} }
public boolean CanRename(Player player) public boolean CanRename(Player player)
{ {
return true; return !_locked || (player.isOp() || AdminList.contains(player.getName()));
} }
} }

View File

@ -1,16 +1,8 @@
package mineplex.mapparser; package mineplex.mapparser;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import mineplex.core.common.util.F; import mineplex.core.common.util.F;
import mineplex.core.common.util.UtilTime; import mineplex.core.common.util.UtilTime;
import mineplex.core.common.util.UtilWorld; import mineplex.core.common.util.UtilWorld;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.World; import org.bukkit.World;
@ -19,6 +11,13 @@ import org.bukkit.block.BlockFace;
import org.bukkit.block.Sign; import org.bukkit.block.Sign;
import org.bukkit.material.Wool; import org.bukkit.material.Wool;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
public class Parse public class Parse
{ {
//Parse Data //Parse Data
@ -59,14 +58,14 @@ public class Parse
_size = size; _size = size;
for (String arg : args) for (String arg : args)
Host.Announce("Parse Arg: " + F.elem(arg)); Host.announce("Parse Arg: " + F.elem(arg));
Initialize(); Initialize();
} }
private void Initialize() private void Initialize()
{ {
Host.Announce("Commencing Parse of World: " + F.elem(_world.getName())); Host.announce("Commencing Parse of World: " + F.elem(_world.getName()));
//Take BlockID Arguments //Take BlockID Arguments
for (String arg : _args) for (String arg : _args)
@ -77,7 +76,7 @@ public class Parse
} }
catch (Exception e) catch (Exception e)
{ {
Host.Announce("Invalid Data ID: " + F.elem(arg)); Host.announce("Invalid Data ID: " + F.elem(arg));
} }
} }
@ -102,7 +101,7 @@ public class Parse
_processed++; _processed++;
if (_processed % 10000000 == 0) if (_processed % 10000000 == 0)
Host.Announce("Scanning World: " + F.elem((int)(_processed/1000000) + "M of " + (int)(((_size*2)*(_size*2)*256)/1000000) + "M")); Host.announce("Scanning World: " + F.elem((int)(_processed/1000000) + "M of " + (int)(((_size*2)*(_size*2)*256)/1000000) + "M"));
Block block = _world.getBlockAt(_callLoc.getBlockX()+_x, _y, _callLoc.getBlockZ()+_z); Block block = _world.getBlockAt(_callLoc.getBlockX()+_x, _y, _callLoc.getBlockZ()+_z);
@ -144,7 +143,7 @@ public class Parse
} }
catch (Exception e) catch (Exception e)
{ {
Host.Announce("Invalid Sign Data: " + UtilWorld.locToStr(block.getLocation())); Host.announce("Invalid Sign Data: " + UtilWorld.locToStr(block.getLocation()));
} }
//Add //Add
@ -176,21 +175,21 @@ public class Parse
if (_cornerA == null) if (_cornerA == null)
{ {
_cornerA = wool.getLocation(); _cornerA = wool.getLocation();
Host.Announce("Corner A: " + UtilWorld.locToStrClean(_cornerA)); Host.announce("Corner A: " + UtilWorld.locToStrClean(_cornerA));
} }
else if (_cornerB == null) else if (_cornerB == null)
{ {
_cornerB = wool.getLocation(); _cornerB = wool.getLocation();
Host.Announce("Corner B: " + UtilWorld.locToStrClean(_cornerB)); Host.announce("Corner B: " + UtilWorld.locToStrClean(_cornerB));
} }
else else
{ {
Host.Announce("More than 2 Corner Markers:"); Host.announce("More than 2 Corner Markers:");
Host.Announce("Corner A: " + UtilWorld.locToStrClean(_cornerA)); Host.announce("Corner A: " + UtilWorld.locToStrClean(_cornerA));
Host.Announce("Corner B: " + UtilWorld.locToStrClean(_cornerB)); Host.announce("Corner B: " + UtilWorld.locToStrClean(_cornerB));
Host.Announce("Excess: " + UtilWorld.locToStrClean(wool.getLocation())); Host.announce("Excess: " + UtilWorld.locToStrClean(wool.getLocation()));
} }
//Remove Blocks //Remove Blocks
@ -414,7 +413,7 @@ public class Parse
if (_cornerA == null || _cornerB == null) if (_cornerA == null || _cornerB == null)
{ {
Host.Announce("Missing Corner Locations! Defaulted to -256 to +256."); Host.announce("Missing Corner Locations! Defaulted to -256 to +256.");
_cornerA = new Location(_world, -256, 0, -256); _cornerA = new Location(_world, -256, 0, -256);
_cornerB = new Location(_world, 256, 0, 256); _cornerB = new Location(_world, 256, 0, 256);
@ -487,12 +486,12 @@ public class Parse
} }
catch (Exception e) catch (Exception e)
{ {
Host.Announce("Error: File Write Error"); Host.announce("Error: File Write Error");
e.printStackTrace(); e.printStackTrace();
} }
Host.Announce("WorldConfig.dat Saved."); Host.announce("WorldConfig.dat Saved.");
return true; return true;
} }

View File

@ -1,18 +1,17 @@
package mineplex.mapparser; package mineplex.mapparser;
import mineplex.core.common.util.MapUtil;
import mineplex.core.common.util.ZipUtil;
import org.apache.commons.io.FileUtils;
import org.bukkit.Bukkit;
import org.bukkit.World;
import org.bukkit.WorldCreator;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.nio.file.Paths; import java.nio.file.Paths;
import java.util.ArrayList; import java.util.ArrayList;
import org.bukkit.Bukkit;
import org.bukkit.World;
import org.bukkit.WorldCreator;
import mineplex.core.common.util.MapUtil;
import mineplex.core.common.util.ZipUtil;
import org.apache.commons.io.FileUtils;
public class WorldManager public class WorldManager
{ {
private MapParser Host; private MapParser Host;
@ -99,7 +98,7 @@ public class WorldManager
FileUtils.deleteQuietly(new File(world.getName() + File.separator + file.getName())); FileUtils.deleteQuietly(new File(world.getName() + File.separator + file.getName()));
} }
MapData data = Host.GetData(world.getName().replace("parse", "map")); MapData data = Host.getData(world.getName().replace("parse", "map"));
GameType gameType = data.MapGameType; GameType gameType = data.MapGameType;
String fileName = gameType + "_" + data.MapName + ".zip"; String fileName = gameType + "_" + data.MapName + ".zip";

View File

@ -0,0 +1,58 @@
package mineplex.mapparser.command;
import mineplex.core.common.util.C;
import mineplex.mapparser.MapParser;
import net.md_5.bungee.api.ChatColor;
import org.bukkit.entity.Player;
/**
*
*/
public class AddSplashTextCommand extends BaseCommand
{
public AddSplashTextCommand(MapParser plugin)
{
super(plugin, "addtext");
setUsage("/addText <text>");
}
@Override
public boolean execute(Player player, String alias, String[] args)
{
if(!player.isOp())
{
player.sendMessage(C.cRed + "You cannot do this command!");
return true;
}
if(args.length == 0)
{
return false;
}
if(args[0].equalsIgnoreCase("clear"))
{
getPlugin().getAdditionalText().clear();
player.sendMessage(C.cRed + "Cleared all text.");
return true;
}
StringBuilder builder = new StringBuilder();
for (int i = 0; i < args.length; i++)
{
builder.append(args[i]);
if ((i + 1) != args.length)
{
builder.append(" ");
}
}
getPlugin().addAdditionalText(builder.toString());
player.sendMessage(C.cGreen + "Added text!");
player.sendMessage(ChatColor.translateAlternateColorCodes('&', builder.toString()));
return true;
}
}

View File

@ -36,7 +36,7 @@ public class AdminCommand extends BaseCommand
} }
//Permission //Permission
if (!getPlugin().GetData(world.getName()).HasAccess(player)) if (!getPlugin().getData(world.getName()).HasAccess(player))
{ {
message(player, "You are not on Admin-List for this Map."); message(player, "You are not on Admin-List for this Map.");
return true; return true;
@ -46,21 +46,21 @@ public class AdminCommand extends BaseCommand
if (player != null) if (player != null)
{ {
MapData data = getPlugin().GetData(world.getName()); MapData data = getPlugin().getData(world.getName());
if (data.AdminList.contains(other.getName())) if (data.AdminList.contains(other.getName()))
{ {
data.AdminList.remove(other.getName()); data.AdminList.remove(other.getName());
data.Write(); data.Write();
getPlugin().Announce("Admin-List for " + F.elem(world.getName()) + " (" + other.getName() + " = " + F.tf(false) + ")"); getPlugin().announce("Admin-List for " + F.elem(world.getName()) + " (" + other.getName() + " = " + F.tf(false) + ")");
} }
else else
{ {
data.AdminList.add(other.getName()); data.AdminList.add(other.getName());
data.Write(); data.Write();
getPlugin().Announce("Admin-List for " + F.elem(world.getName()) + " (" + other.getName() + " = " + F.tf(true) + ")"); getPlugin().announce("Admin-List for " + F.elem(world.getName()) + " (" + other.getName() + " = " + F.tf(true) + ")");
} }
} }
return true; return true;

View File

@ -4,7 +4,6 @@ import org.bukkit.World;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import mineplex.core.common.util.F; import mineplex.core.common.util.F;
import mineplex.core.common.util.UtilPlayer;
import mineplex.mapparser.MapData; import mineplex.mapparser.MapData;
import mineplex.mapparser.MapParser; import mineplex.mapparser.MapParser;
@ -41,18 +40,18 @@ public class AuthorCommand extends BaseCommand
} }
//Permission //Permission
if (!getPlugin().GetData(world.getName()).HasAccess(player)) if (!getPlugin().getData(world.getName()).HasAccess(player))
{ {
message(player, "You do not have Build-Access on this Map."); message(player, "You do not have Build-Access on this Map.");
return true; return true;
} }
MapData data = getPlugin().GetData(world.getName()); MapData data = getPlugin().getData(world.getName());
data.MapCreator = authorName; data.MapCreator = authorName;
data.Write(); data.Write();
getPlugin().Announce("Map Author for " + F.elem(world.getName()) + " set to " + F.elem(authorName) + "."); getPlugin().announce("Map Author for " + F.elem(world.getName()) + " set to " + F.elem(authorName) + ".");
return true; return true;
} }

View File

@ -50,19 +50,19 @@ public class CopyCommand extends BaseCommand
String worldName = getPlugin().getWorldString(originalMapName, originalGametype); String worldName = getPlugin().getWorldString(originalMapName, originalGametype);
String newWorldName = getPlugin().getWorldString(newMapName, newGameType); String newWorldName = getPlugin().getWorldString(newMapName, newGameType);
if (!getPlugin().DoesMapExist(worldName)) if (!getPlugin().doesMapExist(worldName))
{ {
message(player, "Could not find a map with the name " + F.elem(originalMapName) + " of type " + F.elem(originalGametype.toString())); message(player, "Could not find a map with the name " + F.elem(originalMapName) + " of type " + F.elem(originalGametype.toString()));
return true; return true;
} }
if (getPlugin().DoesMapExist(newWorldName)) if (getPlugin().doesMapExist(newWorldName))
{ {
message(player, "Destination map already exists " + F.elem(newMapName) + " of type " + F.elem(newGameType.toString())); message(player, "Destination map already exists " + F.elem(newMapName) + " of type " + F.elem(newGameType.toString()));
return true; return true;
} }
World world = getPlugin().GetMapWorld(worldName); World world = getPlugin().getMapWorld(worldName);
if (world != null) if (world != null)
{ {

View File

@ -1,18 +1,16 @@
package mineplex.mapparser.command; package mineplex.mapparser.command;
import mineplex.core.common.util.C;
import mineplex.core.common.util.F;
import mineplex.mapparser.GameType;
import mineplex.mapparser.MapData;
import mineplex.mapparser.MapParser;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.World; import org.bukkit.World;
import org.bukkit.WorldCreator; import org.bukkit.WorldCreator;
import org.bukkit.WorldType; import org.bukkit.WorldType;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import mineplex.core.common.util.F;
import mineplex.core.common.util.UtilPlayer;
import mineplex.mapparser.GameType;
import mineplex.mapparser.MapData;
import mineplex.mapparser.MapParser;
/** /**
* Created by Shaun on 8/16/2014. * Created by Shaun on 8/16/2014.
*/ */
@ -28,7 +26,7 @@ public class CreateCommand extends BaseCommand
{ {
if (args.length < 1) if (args.length < 1)
{ {
message(player, "Invalid Input. " + F.elem("/create <MapName>")); message(player, "Invalid Input. " + F.elem("/create <MapName> [-v]"));
return true; return true;
} }
@ -36,17 +34,34 @@ public class CreateCommand extends BaseCommand
String worldName = "map/" + gameType.GetName() + "/" + args[0]; String worldName = "map/" + gameType.GetName() + "/" + args[0];
if (getPlugin().DoesMapExist(worldName)) if (getPlugin().doesMapExist(worldName))
{ {
message(player, "Map name is already in use!"); message(player, "Map name is already in use!");
return true; return true;
} }
getPlugin().Announce("Creating World: " + F.elem(worldName)); boolean voidWorld = false;
if (args.length == 2)
{
voidWorld = args[1].equalsIgnoreCase("-v");
}
WorldCreator worldCreator = new WorldCreator(worldName); WorldCreator worldCreator = new WorldCreator(worldName);
worldCreator.environment(World.Environment.NORMAL); worldCreator.environment(World.Environment.NORMAL);
worldCreator.type(WorldType.FLAT); worldCreator.type(WorldType.FLAT);
if (voidWorld)
{
//Cheeky little trick, saves time and energy.
worldCreator.generatorSettings("3;minecraft:air;2");
getPlugin().announce("Creating World: " + F.elem(worldName) + " -" + C.cRed + "VOID");
}
else
{
getPlugin().announce("Creating World: " + F.elem(worldName));
}
worldCreator.generateStructures(false); worldCreator.generateStructures(false);
World world = Bukkit.getServer().createWorld(worldCreator); World world = Bukkit.getServer().createWorld(worldCreator);
@ -58,7 +73,7 @@ public class CreateCommand extends BaseCommand
player.teleport(world.getSpawnLocation()); player.teleport(world.getSpawnLocation());
//Give Access //Give Access
MapData mapData = getPlugin().GetData(worldName); MapData mapData = getPlugin().getData(worldName);
mapData.AdminList.add(player.getName()); mapData.AdminList.add(player.getName());
mapData.MapGameType = gameType; mapData.MapGameType = gameType;
mapData.Write(); mapData.Write();

View File

@ -0,0 +1,38 @@
package mineplex.mapparser.command;
import mineplex.core.common.util.C;
import mineplex.mapparser.MapData;
import mineplex.mapparser.MapParser;
import org.bukkit.entity.Player;
/**
*
*/
public class CurrentlyLiveCommand extends BaseCommand
{
public CurrentlyLiveCommand(MapParser plugin, String... aliases)
{
super(plugin, "islive", "setlive");
}
@Override
public boolean execute(Player player, String alias, String[] args)
{
MapData data = getPlugin().getData(player.getWorld().getName());
if(data == null)
{
player.sendMessage(C.cRed + "There was an error with your map.");
return true;
}
if(alias.equalsIgnoreCase("setlive"))
{
data._currentlyLive = true;
}
player.sendMessage(C.cGray + "Currently Live: " + (data._currentlyLive ? C.cGreen + "True" : C.cRed + "False"));
return true;
}
}

View File

@ -44,21 +44,21 @@ public class DeleteCommand extends BaseCommand
final String worldName = getPlugin().getWorldString(mapName, gameType); final String worldName = getPlugin().getWorldString(mapName, gameType);
if (!getPlugin().DoesMapExist(worldName)) if (!getPlugin().doesMapExist(worldName))
{ {
message(player, "Map does not exist: " + F.elem(worldName)); message(player, "Map does not exist: " + F.elem(worldName));
return true; return true;
} }
if (!getPlugin().GetData(worldName).HasAccess(player)) if (!getPlugin().getData(worldName).HasAccess(player))
{ {
message(player, "You do not have Build-Access on this Map."); message(player, "You do not have Build-Access on this Map.");
return true; return true;
} }
if (getPlugin().GetMapWorld(worldName) != null) if (getPlugin().getMapWorld(worldName) != null)
{ {
World world = getPlugin().GetMapWorld(worldName); World world = getPlugin().getMapWorld(worldName);
//Teleport Out //Teleport Out
for (Player other : world.getPlayers()) for (Player other : world.getPlayers())
@ -73,9 +73,9 @@ public class DeleteCommand extends BaseCommand
boolean deleted = FileUtils.deleteQuietly(new File(worldName)); boolean deleted = FileUtils.deleteQuietly(new File(worldName));
if (deleted) if (deleted)
getPlugin().Announce("Deleted World: " + F.elem(worldName)); getPlugin().announce("Deleted World: " + F.elem(worldName));
else else
getPlugin().Announce("Failed to delete World: " + F.elem(worldName)); getPlugin().announce("Failed to delete World: " + F.elem(worldName));
return true; return true;
} }

View File

@ -2,13 +2,11 @@ package mineplex.mapparser.command;
import java.io.File; import java.io.File;
import org.bukkit.Location;
import org.bukkit.World; import org.bukkit.World;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import mineplex.core.common.util.F; import mineplex.core.common.util.F;
import mineplex.core.common.util.MapUtil; import mineplex.core.common.util.MapUtil;
import mineplex.core.common.util.UtilPlayer;
import mineplex.mapparser.GameType; import mineplex.mapparser.GameType;
import mineplex.mapparser.MapData; import mineplex.mapparser.MapData;
import mineplex.mapparser.MapParser; import mineplex.mapparser.MapParser;
@ -41,7 +39,7 @@ public class GameTypeCommand extends BaseCommand
} }
//Permission //Permission
if (!getPlugin().GetData(world.getName()).HasAccess(player)) if (!getPlugin().getData(world.getName()).HasAccess(player))
{ {
message(player, "You do not have Build-Access on this Map."); message(player, "You do not have Build-Access on this Map.");
return true; return true;
@ -59,7 +57,7 @@ public class GameTypeCommand extends BaseCommand
return true; return true;
} }
if (getPlugin().DoesMapExist(getPlugin().getShortWorldName(world.getName()), type)) if (getPlugin().doesMapExist(getPlugin().getShortWorldName(world.getName()), type))
{ {
message(player, "A world with the same name already exists for the new gametype: " + type.GetName()); message(player, "A world with the same name already exists for the new gametype: " + type.GetName());
return true; return true;
@ -85,11 +83,11 @@ public class GameTypeCommand extends BaseCommand
message(player, "Map " + world.getName() + " renamed to " + newName); message(player, "Map " + world.getName() + " renamed to " + newName);
MapData data = getPlugin().GetData(newName); MapData data = getPlugin().getData(newName);
data.MapGameType = type; data.MapGameType = type;
data.Write(); data.Write();
getPlugin().Announce("GameType for " + F.elem(newName) + " set to " + F.elem(args[0]) + "."); getPlugin().announce("GameType for " + F.elem(newName) + " set to " + F.elem(args[0]) + ".");
return true; return true;
} }

View File

@ -0,0 +1,81 @@
package mineplex.mapparser.command;
import com.google.common.collect.Lists;
import mineplex.core.common.util.C;
import mineplex.core.common.util.F;
import mineplex.mapparser.GameType;
import mineplex.mapparser.GameTypeInfo;
import mineplex.mapparser.MapParser;
import org.bukkit.entity.Player;
/**
*
*/
public class InfoCommand extends BaseCommand
{
public InfoCommand(MapParser plugin)
{
super(plugin, "info");
setUsage("/info <gametype> & /info addInfo <gameType> <info>");
}
@Override
public boolean execute(Player player, String alias, String[] args)
{
if (args.length == 1)
{
String gameRaw = args[0];
GameType gameType;
try
{
gameType = GameType.match(gameRaw);
} catch (Exception e)
{
player.sendMessage(C.cRed + "Invalid Game Type: " + gameRaw);
return true;
}
GameTypeInfo info = getPlugin().getInfo(gameType);
if (info == null)
{
player.sendMessage(C.cRed + "No info found for " + gameType.GetName());
return true;
}
info.sendInfo(player);
return true;
}
if (args.length >= 3 && args[0].equalsIgnoreCase("addInfo"))
{
String gameRaw = args[1];
GameType gameType;
try
{
gameType = GameType.match(gameRaw);
} catch (Exception e)
{
player.sendMessage(C.cRed + "Invalid Game Type: " + gameRaw);
return true;
}
GameTypeInfo info = getPlugin().getInfo(gameType);
StringBuilder builder = new StringBuilder();
for (int i = 2; i < args.length; i++)
{
builder.append(args[i]);
if ((i + 1) != args.length)
{
builder.append(" ");
}
}
if (info == null)
{
info = new GameTypeInfo(gameType, Lists.newArrayList());
getPlugin().setInfo(gameType, info);
}
info.addInfo(builder.toString());
player.sendMessage(C.cGray + "Added new info to " + F.elem(gameRaw));
return true;
}
return false;
}
}

View File

@ -0,0 +1,35 @@
package mineplex.mapparser.command;
import mineplex.core.common.util.C;
import mineplex.core.common.util.F;
import mineplex.mapparser.MapData;
import mineplex.mapparser.MapParser;
import org.bukkit.entity.Player;
/**
*
*/
public class LockCommand extends BaseCommand
{
public LockCommand(MapParser plugin)
{
super(plugin, "lock");
}
@Override
public boolean execute(Player player, String alias, String[] args)
{
MapData data = getPlugin().getData(player.getWorld().getName());
if(data == null)
{
player.sendMessage(C.cRed + "There was an error with your map.");
return true;
}
data._locked = !data._locked;
player.sendMessage(F.tf(data._locked) + " lock for world " + player.getWorld().getName());
return true;
}
}

View File

@ -1,19 +1,18 @@
package mineplex.mapparser.command; package mineplex.mapparser.command;
import java.io.File;
import java.util.List;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.WorldCreator;
import org.bukkit.entity.Player;
import mineplex.core.common.util.F; import mineplex.core.common.util.F;
import mineplex.core.common.util.UtilPlayer; import mineplex.core.common.util.UtilPlayer;
import mineplex.mapparser.GameType; import mineplex.mapparser.GameType;
import mineplex.mapparser.MapData; import mineplex.mapparser.MapData;
import mineplex.mapparser.MapParser; import mineplex.mapparser.MapParser;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.WorldCreator;
import org.bukkit.entity.Player;
import java.io.File;
import java.util.List;
/** /**
* Created by Shaun on 8/15/2014. * Created by Shaun on 8/15/2014.
@ -45,8 +44,9 @@ public class MapCommand extends BaseCommand
if (possibleMaps.size() == 0) if (possibleMaps.size() == 0)
{ {
message(player, "No maps found with the name: " + F.elem(args[0])); message(player, "No maps found with the name: " + F.elem(args[0]));
return true;
} }
else if (possibleMaps.size() > 1) if (possibleMaps.size() > 1)
{ {
message(player, "Found more than one possible match:"); message(player, "Found more than one possible match:");
for (String s : possibleMaps) for (String s : possibleMaps)
@ -91,10 +91,10 @@ public class MapCommand extends BaseCommand
System.out.println("Could not delete uid.dat for " + worldName); System.out.println("Could not delete uid.dat for " + worldName);
} }
World world = getPlugin().GetMapWorld(worldName); World world = getPlugin().getMapWorld(worldName);
if (world == null) if (world == null)
{ {
if (getPlugin().DoesMapExist(worldName)) if (getPlugin().doesMapExist(worldName))
{ {
world = Bukkit.createWorld(new WorldCreator(worldName)); world = Bukkit.createWorld(new WorldCreator(worldName));
} }
@ -113,7 +113,7 @@ public class MapCommand extends BaseCommand
} }
//Permission //Permission
if (!getPlugin().GetData(world.getName()).CanJoin(player)) if (!getPlugin().getData(world.getName()).CanJoin(player))
{ {
message(player, "You do not have Join-Access on this Map."); message(player, "You do not have Join-Access on this Map.");
return true; return true;
@ -124,7 +124,7 @@ public class MapCommand extends BaseCommand
player.teleport(new Location(world, 0, 106, 0)); player.teleport(new Location(world, 0, 106, 0));
MapData data = getPlugin().GetData(worldName); MapData data = getPlugin().getData(worldName);
UtilPlayer.message(player, F.value("Map Name", data.MapName)); UtilPlayer.message(player, F.value("Map Name", data.MapName));
UtilPlayer.message(player, F.value("Author", data.MapCreator)); UtilPlayer.message(player, F.value("Author", data.MapCreator));

View File

@ -4,7 +4,6 @@ import org.bukkit.World;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import mineplex.core.common.util.F; import mineplex.core.common.util.F;
import mineplex.core.common.util.UtilPlayer;
import mineplex.mapparser.MapData; import mineplex.mapparser.MapData;
import mineplex.mapparser.MapParser; import mineplex.mapparser.MapParser;
@ -43,18 +42,18 @@ public class NameCommand extends BaseCommand
mapName = mapName.trim(); mapName = mapName.trim();
//Permission //Permission
if (!getPlugin().GetData(world.getName()).HasAccess(player)) if (!getPlugin().getData(world.getName()).HasAccess(player))
{ {
message(player, "You do not have Build-Access on this Map."); message(player, "You do not have Build-Access on this Map.");
return true; return true;
} }
MapData data = getPlugin().GetData(world.getName()); MapData data = getPlugin().getData(world.getName());
data.MapName = mapName; data.MapName = mapName;
data.Write(); data.Write();
getPlugin().Announce("Map Name for " + F.elem(world.getName()) + " set to " + F.elem(mapName) + "."); getPlugin().announce("Map Name for " + F.elem(world.getName()) + " set to " + F.elem(mapName) + ".");
return true; return true;
} }

View File

@ -32,7 +32,7 @@ public class ParseCommand200 extends BaseCommand
World world = parseLoc.getWorld(); World world = parseLoc.getWorld();
MapData data = getPlugin().GetData(world.getName()); MapData data = getPlugin().getData(world.getName());
if (data.MapName.equals("null") || data.MapCreator.equals("null") || data.MapGameType.equals("null")) if (data.MapName.equals("null") || data.MapCreator.equals("null") || data.MapGameType.equals("null"))
{ {
@ -57,7 +57,7 @@ public class ParseCommand200 extends BaseCommand
} }
//Parse the World //Parse the World
getPlugin().setCurrentParse(new Parse(getPlugin(), parseableWorld, args, parseLoc, getPlugin().GetData(parseLoc.getWorld().getName()), 200)); getPlugin().setCurrentParse(new Parse(getPlugin(), parseableWorld, args, parseLoc, getPlugin().getData(parseLoc.getWorld().getName()), 200));
return true; return true;
} }

View File

@ -32,7 +32,7 @@ public class ParseCommand400 extends BaseCommand
World world = parseLoc.getWorld(); World world = parseLoc.getWorld();
MapData data = getPlugin().GetData(world.getName()); MapData data = getPlugin().getData(world.getName());
if (data.MapName.equals("null") || data.MapCreator.equals("null") || data.MapGameType.equals("null")) if (data.MapName.equals("null") || data.MapCreator.equals("null") || data.MapGameType.equals("null"))
{ {
@ -57,7 +57,7 @@ public class ParseCommand400 extends BaseCommand
} }
//Parse the World //Parse the World
getPlugin().setCurrentParse(new Parse(getPlugin(), parseableWorld, args, parseLoc, getPlugin().GetData(parseLoc.getWorld().getName()), 400)); getPlugin().setCurrentParse(new Parse(getPlugin(), parseableWorld, args, parseLoc, getPlugin().getData(parseLoc.getWorld().getName()), 400));
return true; return true;
} }

View File

@ -32,7 +32,7 @@ public class ParseCommand600 extends BaseCommand
World world = parseLoc.getWorld(); World world = parseLoc.getWorld();
MapData data = getPlugin().GetData(world.getName()); MapData data = getPlugin().getData(world.getName());
if (data.MapName.equals("null") || data.MapCreator.equals("null") || data.MapGameType.equals("null")) if (data.MapName.equals("null") || data.MapCreator.equals("null") || data.MapGameType.equals("null"))
{ {
@ -57,7 +57,7 @@ public class ParseCommand600 extends BaseCommand
} }
//Parse the World //Parse the World
getPlugin().setCurrentParse(new Parse(getPlugin(), parseableWorld, args, parseLoc, getPlugin().GetData(parseLoc.getWorld().getName()), 600)); getPlugin().setCurrentParse(new Parse(getPlugin(), parseableWorld, args, parseLoc, getPlugin().getData(parseLoc.getWorld().getName()), 600));
return true; return true;
} }

View File

@ -0,0 +1,37 @@
package mineplex.mapparser.command;
import mineplex.core.common.util.C;
import mineplex.core.common.util.F;
import mineplex.mapparser.MapParser;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.SkullMeta;
/**
*
*/
public class PlayerHeadCommand extends BaseCommand
{
public PlayerHeadCommand(MapParser plugin, String... aliases)
{
super(plugin, "playerhead");
}
@Override
public boolean execute(Player player, String alias, String[] args)
{
if(args.length == 1) {
String name = args[0];
ItemStack itemStack = new ItemStack(Material.SKULL_ITEM, 1, (byte) 3);
SkullMeta meta = (SkullMeta) itemStack.getItemMeta();
meta.setOwner(name);
itemStack.setItemMeta(meta);
player.getInventory().addItem(itemStack);
player.sendMessage(C.cGray + "Given " + F.elem(name) + "'s head");
return true;
}
return false;
}
}

View File

@ -0,0 +1,31 @@
package mineplex.mapparser.command;
import mineplex.core.common.util.F;
import mineplex.mapparser.MapParser;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.plugin.Plugin;
/**
*
*/
public class RefreshWorldEditCommand extends BaseCommand
{
public RefreshWorldEditCommand(MapParser plugin)
{
super(plugin, "refreshworldedit", "refreshwe", "wefresh");
setUsage("/refreshwe");
}
@Override
public boolean execute(Player player, String alias, String[] args)
{
Bukkit.broadcastMessage(F.name(player.getName()) + " is reloading World Edit");
Plugin plugin = getPlugin().getServer().getPluginManager().getPlugin("WorldEdit");
plugin.onDisable();
plugin.onEnable();
Bukkit.broadcastMessage(F.name(player.getName()) + " has reloaded World Edit");
return true;
}
}

View File

@ -2,7 +2,6 @@ package mineplex.mapparser.command;
import java.io.File; import java.io.File;
import org.bukkit.Location;
import org.bukkit.World; import org.bukkit.World;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
@ -25,7 +24,7 @@ public class RenameCommand extends BaseCommand
public boolean execute(Player player, String alias, String[] args) public boolean execute(Player player, String alias, String[] args)
{ {
World world = player.getWorld(); World world = player.getWorld();
MapData data = getPlugin().GetData(world.getName()); MapData data = getPlugin().getData(world.getName());
if (data == null) if (data == null)
{ {

View File

@ -48,11 +48,11 @@ public class SaveCommand extends BaseCommand
} }
String worldName = possibleMaps.get(0); String worldName = possibleMaps.get(0);
World world = getPlugin().GetMapWorld(worldName); World world = getPlugin().getMapWorld(worldName);
if (world != null) if (world != null)
{ {
if (!getPlugin().GetData(worldName).HasAccess(player)) if (!getPlugin().getData(worldName).HasAccess(player))
{ {
message(player, "You do not have Build-Access on this Map."); message(player, "You do not have Build-Access on this Map.");
return true; return true;
@ -71,7 +71,7 @@ public class SaveCommand extends BaseCommand
return true; return true;
} }
getPlugin().Announce("Saved World: " + F.elem(args[0])); getPlugin().announce("Saved World: " + F.elem(args[0]));
return true; return true;
} }

View File

@ -0,0 +1,82 @@
package mineplex.mapparser.command;
import mineplex.core.common.util.C;
import mineplex.core.common.util.F;
import mineplex.core.common.util.UtilWorld;
import mineplex.mapparser.MapData;
import mineplex.mapparser.MapParser;
import org.bukkit.Location;
import org.bukkit.entity.Player;
import java.util.Map;
/**
*
*/
public class WarpCommand extends BaseCommand
{
public WarpCommand(MapParser plugin)
{
super(plugin, "warp");
setUsage("/warp <name> & /warp <set> <name>");
}
@Override
public boolean execute(Player player, String alias, String[] args)
{
MapData data = getPlugin().getData(player.getWorld().getName());
if(data == null)
{
player.sendMessage(C.cRed + "There was an error with your map.");
return true;
}
Map<String, Location> warps = data._warps;
if(args.length == 1)
{
if(args[0].equalsIgnoreCase("list"))
{
for(String s : warps.keySet())
{
player.sendMessage(F.elem(s) + " @ " + F.elem(UtilWorld.locToStrClean(warps.get(s))));
}
return true;
}
Location location = warps.get(args[0].toLowerCase());
if(location == null){
player.sendMessage(C.cRed + "Unknown warp!");
return true;
}
player.sendMessage(C.cGray + "Warping to " + F.elem(args[0]));
player.teleport(location);
return true;
}
if(args.length == 2)
{
if(!args[0].equalsIgnoreCase("set"))
{
player.sendMessage(C.cRed + "Please use " + F.elem("/warp set <name>") + C.cRed + " to set a warp");
return true;
}
String warp = args[1].toLowerCase();
if(warps.containsKey(warp))
{
player.sendMessage(C.cRed + "That warp already exists!");
return true;
}
warps.put(warp, player.getLocation());
player.sendMessage(C.cGray + "Created a new warp: " + F.elem(warp));
return true;
}
return false;
}
}

View File

@ -0,0 +1,50 @@
package mineplex.mapparser.module;
import mineplex.core.common.util.C;
import mineplex.mapparser.MapData;
import mineplex.mapparser.MapParser;
import net.md_5.bungee.api.ChatColor;
import org.bukkit.entity.Player;
import org.bukkit.event.Listener;
/**
*
*/
public abstract class Module implements Listener
{
private MapParser _plugin;
private String _name;
public Module(String name, MapParser plugin) {
_name = name;
_plugin = plugin;
register();
plugin.getModules().put(this.getClass(), this);
}
public void register()
{
_plugin.getServer().getPluginManager().registerEvents(this, _plugin);
}
public MapParser getPlugin()
{
return _plugin;
}
public MapData GetData(String world)
{
return getPlugin().getData(world);
}
public void displayHelp(Player player)
{
MapData data = GetData(player.getWorld().getName());
player.sendMessage(C.cGray + "Currently Live: " + (data._currentlyLive ? C.cGreen + "True" : C.cRed + "False"));
for(String s : getPlugin().getAdditionalText())
{
player.sendMessage(ChatColor.translateAlternateColorCodes('&', s));
}
}
}

View File

@ -0,0 +1,99 @@
package mineplex.mapparser.module.modules;
import com.google.common.collect.Maps;
import mineplex.core.common.util.F;
import mineplex.core.common.util.UtilPlayer;
import mineplex.mapparser.MapParser;
import mineplex.mapparser.command.BaseCommand;
import mineplex.mapparser.module.Module;
import org.bukkit.GameMode;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
import java.util.Map;
/**
*
*/
public class CommandModule extends Module
{
private Map<String, BaseCommand> _commands = Maps.newHashMap();
private Map<String, BaseCommand> _commandsByAlias = Maps.newHashMap();
public CommandModule(MapParser plugin)
{
super("Commands", plugin);
}
@EventHandler
public void onCommand(PlayerCommandPreprocessEvent event)
{
Player player = event.getPlayer();
String[] parts = event.getMessage().split(" ");
String commandLabel = parts[0].substring(1);
String[] args = new String[parts.length - 1];
System.arraycopy(parts, 1, args, 0, parts.length - 1);
if (getPlugin().getCurParse() != null)
{
UtilPlayer.message(player, F.main("Parser", "Cannot use commands during Map Parse!"));
return;
}
if (event.getMessage().toLowerCase().startsWith("/help"))
{
event.setCancelled(true);
displayHelp(player);
return;
}
if (commandLabel.equalsIgnoreCase("gmc"))
{
player.setGameMode(GameMode.CREATIVE);
event.setCancelled(true);
return;
}
if (commandLabel.equalsIgnoreCase("gms"))
{
player.setGameMode(GameMode.SURVIVAL);
event.setCancelled(true);
return;
}
if (commandLabel.equalsIgnoreCase("gmsp"))
{
player.setGameMode(GameMode.SPECTATOR);
event.setCancelled(true);
return;
}
BaseCommand baseCommand = _commands.get(commandLabel.toLowerCase());
if (baseCommand == null)
{
baseCommand = _commandsByAlias.get(commandLabel.toLowerCase());
if (baseCommand == null)
{
return;
}
}
event.setCancelled(true);
if (!baseCommand.execute(player, commandLabel, args))
{
UtilPlayer.message(player, F.main("Parser", "Invalid Input."));
UtilPlayer.message(player, F.elem(baseCommand.getUsage()));
}
}
public void add(BaseCommand baseCommand)
{
_commands.put(baseCommand.getAliases().get(0).toLowerCase(), baseCommand);
for (String label : baseCommand.getAliases())
{
_commandsByAlias.put(label.toLowerCase(), baseCommand);
}
}
}

View File

@ -0,0 +1,353 @@
package mineplex.mapparser.module.modules;
import com.google.common.collect.Lists;
import mineplex.core.common.util.C;
import mineplex.core.common.util.F;
import mineplex.core.common.util.MapUtil;
import mineplex.core.common.util.UtilPlayer;
import mineplex.core.common.util.UtilServer;
import mineplex.mapparser.BackupTask;
import mineplex.mapparser.MapData;
import mineplex.mapparser.MapParser;
import mineplex.mapparser.Parse;
import mineplex.mapparser.TickEvent;
import mineplex.mapparser.module.Module;
import org.bukkit.ChatColor;
import org.bukkit.Sound;
import org.bukkit.World;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.block.BlockBurnEvent;
import org.bukkit.event.block.BlockFadeEvent;
import org.bukkit.event.block.BlockFormEvent;
import org.bukkit.event.block.BlockIgniteEvent;
import org.bukkit.event.block.BlockIgniteEvent.IgniteCause;
import org.bukkit.event.block.BlockSpreadEvent;
import org.bukkit.event.block.LeavesDecayEvent;
import org.bukkit.event.entity.EntitySpawnEvent;
import org.bukkit.event.player.AsyncPlayerChatEvent;
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerQuitEvent;
import java.util.List;
/**
*
*/
public class EventModule extends Module
{
private List<World> _updated = Lists.newArrayList();
public EventModule(MapParser plugin)
{
super("Events", plugin);
}
@EventHandler
public void PlayerJoin(PlayerJoinEvent event)
{
Player player = event.getPlayer();
player.teleport(getPlugin().getSpawnLocation());
displayHelp(player);
}
@EventHandler
public void onTick(TickEvent event)
{
for (World world : getPlugin().getServer().getWorlds())
{
if (_updated.contains(world))
{
continue;
}
if (world.getName().toLowerCase().contains("halloween"))
{
world.setTime(16000);
} else
{
world.setTime(8000);
}
_updated.add(world);
world.setGameRuleValue("doDaylightCycle", "false");
}
}
@EventHandler
public void onParseUpdate(TickEvent event)
{
if (getPlugin().getCurParse() == null)
{
return;
}
Parse parse = getPlugin().getCurParse();
if (parse.Update())
{
getPlugin().announce("Parse Completed!");
getPlugin().announce("Cleaning and Creating ZIP...");
try
{
getPlugin().getWorldManager().finalizeParsedWorld(parse.getWorld());
} catch (Exception e)
{
getPlugin().announce("Creating ZIP Failed! Please Try Again!");
e.printStackTrace();
}
getPlugin().setCurrentParse(null);
}
}
@EventHandler
public void SaveUnloadWorlds(TickEvent event)
{
for (World world : getPlugin().getServer().getWorlds())
{
if (world.getName().equalsIgnoreCase("world"))
{
continue;
}
if (world.getName().startsWith("parse_"))
{
continue;
}
if (!world.getName().startsWith("map"))
{
continue;
}
if (world.getPlayers().isEmpty())
{
getPlugin().announce("Saving & Closing World: " + F.elem(world.getName()));
MapUtil.UnloadWorld(getPlugin(), world, true);
_updated.remove(world);
getPlugin()._mapsBeingZipped.add(world.getName());
System.out.println("Starting backup of " + world);
new BackupTask(getPlugin(), world.getName(), data ->
{
System.out.println("Finished backup of " + world);
getPlugin()._mapsBeingZipped.remove(world.getName());
});
}
}
}
@EventHandler
public void Chat(AsyncPlayerChatEvent event)
{
event.setCancelled(true);
String world = C.cDGreen + C.Bold + getPlugin().getShortWorldName(event.getPlayer().getWorld().getName());
String name = C.cYellow + event.getPlayer().getName();
if (getPlugin().getData(event.getPlayer().getWorld().getName()).HasAccess(event.getPlayer()))
{
name = C.cGreen + event.getPlayer().getName();
}
String grayName = C.cBlue + event.getPlayer().getName();
String grayWorld = C.cBlue + C.Bold + event.getPlayer().getWorld().getName();
for (Player player : UtilServer.getPlayers())
{
if (player.getWorld().equals(event.getPlayer().getWorld()))
{
player.sendMessage(world + ChatColor.RESET + " " + name + ChatColor.RESET + " " + event.getMessage());
} else
{
player.sendMessage(grayWorld + ChatColor.RESET + " " + grayName + ChatColor.RESET + " " + C.cGray + event.getMessage());
}
}
System.out.println(world + ChatColor.RESET + " " + name + ChatColor.RESET + " " + event.getMessage());
}
@EventHandler(priority = EventPriority.LOWEST)
public void InteractCancel(PlayerInteractEvent event)
{
if (event.getPlayer().isOp())
{
return;
}
//Permission
if (!getPlugin().getData(event.getPlayer().getWorld().getName()).HasAccess(event.getPlayer()))
{
event.setCancelled(true);
}
}
@EventHandler(priority = EventPriority.LOWEST)
public void TeleportCommand(PlayerCommandPreprocessEvent event)
{
if (!event.getMessage().toLowerCase().startsWith("/tp"))
{
return;
}
Player player = event.getPlayer();
String[] tokens = event.getMessage().split(" ");
if (tokens.length != 2)
{
return;
}
event.setCancelled(true);
Player target = UtilPlayer.searchOnline(player, tokens[1], true);
if (target != null)
{
MapData data = getPlugin().getData(target.getWorld().getName());
if(!data.CanJoin(player))
{
player.sendMessage(C.cRed + "That server is currently locked, and you don't have access to it.");
return;
}
UtilPlayer.message(player, F.main("Game", "You teleported to " + F.name(target.getName()) + "."));
player.teleport(target);
}
}
@EventHandler(priority = EventPriority.LOWEST)
public void commandCancel(PlayerCommandPreprocessEvent event)
{
if (event.getMessage().startsWith("/tp") ||
event.getMessage().startsWith("/hub") ||
event.getMessage().startsWith("/list") ||
event.getMessage().startsWith("/map") ||
event.getMessage().startsWith("/create") ||
event.getMessage().startsWith("/copy") ||
event.getMessage().startsWith("/delete"))
{
return;
}
//Permission
if (!getPlugin().getData(event.getPlayer().getWorld().getName()).HasAccess(event.getPlayer()))
{
UtilPlayer.message(event.getPlayer(), F.main("Parser", "You do not have Build-Access for this Map."));
event.setCancelled(true);
}
}
@EventHandler(priority = EventPriority.LOWEST)
public void FlySpeed(PlayerCommandPreprocessEvent event)
{
if (!event.getMessage().toLowerCase().startsWith("/speed"))
{
return;
}
Player player = event.getPlayer();
String[] tokens = event.getMessage().split(" ");
if (tokens.length != 2)
{
return;
}
event.setCancelled(true);
try
{
float speed = Float.parseFloat(tokens[1]);
player.setFlySpeed(speed);
UtilPlayer.message(player, F.main("Game", "Fly Speed set to " + F.elem("" + speed) + "."));
} catch (Exception e)
{
UtilPlayer.message(player, F.main("Game", "Invalid Speed Input."));
}
}
//#################################################################################################
//# #
//# Simple methods #
//# #
//# #
//#################################################################################################
@EventHandler
public void Join(PlayerJoinEvent event)
{
Player player = event.getPlayer();
if (player.getName().equalsIgnoreCase("TadahTech"))
{
event.setJoinMessage(C.cGreenB + "Your build server Saviour, TIMOTHY! has arrived, please take a moment to thank him.");
getPlugin().getServer().getOnlinePlayers().forEach(o -> o.playSound(o.getLocation(), Sound.AMBIENCE_THUNDER, 1.0F, 1.0F));
return;
}
event.setJoinMessage(F.sys("Player Join", event.getPlayer().getName()));
}
@EventHandler
public void Join(PlayerQuitEvent event)
{
event.setQuitMessage(F.sys("Player Quit", event.getPlayer().getName()));
}
@EventHandler
public void onDroppedItemSpawn(EntitySpawnEvent event)
{
if (event.getEntityType() != EntityType.ARMOR_STAND)
{
event.setCancelled(true);
}
}
@EventHandler
public void DisableBurn(BlockBurnEvent event)
{
event.setCancelled(true);
}
@EventHandler
public void DisableIgnite(BlockIgniteEvent event)
{
if (event.getCause() == IgniteCause.LAVA || event.getCause() == IgniteCause.SPREAD)
{
event.setCancelled(true);
}
}
@EventHandler
public void DisableFire(BlockSpreadEvent event)
{
event.setCancelled(true);
}
@EventHandler
public void DisableFade(BlockFadeEvent event)
{
event.setCancelled(true);
}
@EventHandler
public void DisableDecay(LeavesDecayEvent event)
{
event.setCancelled(true);
}
@EventHandler
public void DisableIceForm(BlockFormEvent event)
{
event.setCancelled(true);
}
}

View File

@ -0,0 +1,127 @@
package mineplex.mapparser.module.modules;
import mineplex.core.common.util.C;
import mineplex.core.common.util.UtilGear;
import mineplex.mapparser.MapParser;
import mineplex.mapparser.module.Module;
import org.bukkit.ChatColor;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.block.Action;
import org.bukkit.event.player.PlayerInteractEvent;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
/**
*
*/
public class MMMazeModule extends Module
{
public MMMazeModule(MapParser plugin)
{
super("MM-Maze", plugin);
}
@EventHandler
public void mmMazeParser(PlayerInteractEvent event)
{
if (event.isCancelled())
return;
if (event.getAction() != Action.LEFT_CLICK_BLOCK) return;
//Permission
if (!GetData(event.getPlayer().getWorld().getName()).HasAccess(event.getPlayer()))
{
return;
}
Player player = event.getPlayer();
if (!UtilGear.isMat(player.getItemInHand(), Material.WEB))
return;
event.setCancelled(true);
// parse
Block clicked = event.getClickedBlock();
Location center = clicked.getLocation();
Location lowestCorner = center.clone().subtract(49, 0, 49);
// 0 = air or other
// 1 = path - quartz
// 2 = mob spawn - gold
// 3 = safe spawn - stone
int[][] maze = new int[99][99];
for (int i = 0; i < 99; i++)
for (int j = 0; j < 99; j++)
maze[i][j] = getMMParseValue(lowestCorner.clone().add(j, 0, i).getBlock().getType());
//Save
try
{
FileWriter fstream = new FileWriter(GetData(player.getWorld().getName()).MapFolder + File.separator + "Maze.dat");
BufferedWriter out = new BufferedWriter(fstream);
out.write("private static final int[][] PARSED_MAZE = {" + System.lineSeparator());
for (int j[] : maze)
{
out.write("{");
boolean first = true;
for (int k : j)
{
if(!first) out.write(",");
out.write(k + "");
first = false;
}
out.write("}," + System.lineSeparator());
}
out.write("};" + System.lineSeparator());
out.close();
}
catch (Exception e)
{
player.sendMessage(C.cRed + C.Bold + "MMMazeParse: " + ChatColor.RESET + "An error has occured, see console.");
e.printStackTrace();
}
player.sendMessage(C.cGreen + C.Bold + "MMMazeParse: " + ChatColor.RESET + "Maze parsed.");
}
private int getMMParseValue(Material m)
{
switch (m) {
case QUARTZ_BLOCK:
return 1;
case GOLD_BLOCK:
return 2;
case STONE:
return 3;
case DIRT:
return 4;
case COBBLESTONE:
return 5;
case BRICK:
return 6;
default:
return 0;
}
}
}

View File

@ -0,0 +1,112 @@
package mineplex.mapparser.module.modules;
import mineplex.core.common.util.UtilTime;
import mineplex.core.common.util.UtilWorld;
import mineplex.mapparser.MapParser;
import mineplex.mapparser.module.Module;
import org.bukkit.World;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.block.SignChangeEvent;
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.util.ArrayList;
/**
*
*/
public class SignModule extends Module
{
public SignModule(MapParser plugin)
{
super("Sign", plugin);
}
@EventHandler(priority = EventPriority.LOWEST)
public void signChangeLog(SignChangeEvent event)
{
if (GetData(event.getPlayer().getWorld().getName()).HasAccess(event.getPlayer()))
{
ArrayList<String> text = new ArrayList<>();
text.add("Date: " + UtilTime.now());
text.add("Player: " + event.getPlayer().getName());
text.add("Location: " + UtilWorld.locToStrClean(event.getBlock().getLocation()));
for (int i = 0; i < event.getLines().length; i++)
{
text.add("Line " + i + ": " + event.getLines()[i]);
}
writeSignLog(text, event.getPlayer().getWorld());
}
}
@EventHandler(priority = EventPriority.LOWEST)
public void signCommand(PlayerCommandPreprocessEvent event)
{
if (event.getMessage().toLowerCase().contains("set"))
{
ArrayList<String> text = new ArrayList<>();
text.add("Date: " + UtilTime.now());
text.add("Player: " + event.getPlayer().getName());
text.add("Location: " + UtilWorld.locToStrClean(event.getPlayer().getLocation()));
text.add("Message: " + event.getMessage());
writeSignCommandLog(text, event.getPlayer().getWorld());
}
}
public void writeSignCommandLog(ArrayList<String> text, World world)
{
try
{
File file = new File(world.getName() + "/" + "command_sign_log.txt");
if (!file.exists())
{
file.createNewFile();
}
FileWriter fw = new FileWriter(file.getAbsoluteFile(), true);
BufferedWriter bw = new BufferedWriter(fw);
bw.write("\n\n");
for (String line : text)
bw.write("\n" + line);
bw.close();
} catch (Exception e)
{
e.printStackTrace();
}
}
public void writeSignLog(ArrayList<String> text, World world)
{
try
{
File file = new File(world.getName() + "/" + "sign_log.txt");
if (!file.exists())
{
file.createNewFile();
}
FileWriter fw = new FileWriter(file.getAbsoluteFile(), true);
BufferedWriter bw = new BufferedWriter(fw);
bw.write("\n\n");
for (String line : text)
bw.write("\n" + line);
bw.close();
} catch (Exception e)
{
e.printStackTrace();
}
}
}

View File

@ -0,0 +1,119 @@
package mineplex.mapparser.module.modules;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.google.common.collect.Sets;
import mineplex.core.common.util.C;
import mineplex.core.common.util.UtilEvent;
import mineplex.core.common.util.UtilEvent.ActionType;
import mineplex.core.common.util.UtilGear;
import mineplex.mapparser.BlockData;
import mineplex.mapparser.MapParser;
import mineplex.mapparser.module.Module;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.block.Action;
import org.bukkit.event.player.PlayerInteractEvent;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.UUID;
/**
*
*/
public class TreeToolModule extends Module
{
private Map<UUID, List<Set<BlockData>>> _treeHistory = Maps.newHashMap();
public TreeToolModule(MapParser plugin)
{
super("TreeTool", plugin);
}
@EventHandler(priority = EventPriority.HIGHEST)
public void treeRemover(PlayerInteractEvent event)
{
if (event.isCancelled())
{
return;
}
//Permission
if (!getPlugin().getData(event.getPlayer().getWorld().getName()).HasAccess(event.getPlayer()))
{
return;
}
Player player = event.getPlayer();
if (!UtilGear.isMat(player.getItemInHand(), Material.NETHER_STAR))
{
return;
}
event.setCancelled(true);
//Remove
if (event.getAction() == Action.LEFT_CLICK_BLOCK)
{
if (event.getClickedBlock().getType() != Material.LOG)
{
player.sendMessage(C.cRed + C.Bold + "TreeTool: " + ChatColor.RESET + "Left-Click on Log");
return;
}
Set<Block> toRemove = getPlugin().searchLog(Sets.newHashSet(), event.getClickedBlock());
if (toRemove.isEmpty())
{
player.sendMessage(C.cRed + C.Bold + "TreeTool: " + ChatColor.RESET + "Left-Click on Log");
return;
}
Set<BlockData> history = Sets.newHashSet();
for (Block block : toRemove)
{
history.add(new BlockData(block));
block.setType(Material.AIR);
}
if (!_treeHistory.containsKey(player.getUniqueId()))
{
_treeHistory.put(player.getUniqueId(), Lists.newArrayList());
}
_treeHistory.get(player.getUniqueId()).add(0, history);
player.sendMessage(C.cRed + C.Bold + "TreeTool: " + ChatColor.RESET + "Tree Removed");
while (_treeHistory.get(player.getUniqueId()).size() > 10)
{
_treeHistory.get(player.getUniqueId()).remove(10);
}
} else if (UtilEvent.isAction(event, ActionType.R))
{
if (!_treeHistory.containsKey(player.getUniqueId()) || _treeHistory.get(player.getUniqueId()).isEmpty())
{
player.sendMessage(C.cGreen + C.Bold + "TreeTool: " + ChatColor.RESET + "No Tree History");
return;
}
Set<BlockData> datas = _treeHistory.get(player.getUniqueId()).remove(0);
datas.forEach(BlockData::restore);
player.sendMessage(C.cGreen + C.Bold + "TreeTool: " + ChatColor.RESET + "Tree Restored");
}
}
}