From fb5f92df2a6ffa51f39cf020c264926333198816 Mon Sep 17 00:00:00 2001 From: Jonathan Williams Date: Tue, 8 Jul 2014 15:04:59 -0700 Subject: [PATCH 1/7] Finalized internet status for bungees --- .../src/mineplex/bungee/status/InternetStatus.java | 2 -- .../src/mineplex/bungee/status/StatusRepository.java | 6 +++--- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/Plugins/Mineplex.Bungee.Mineplexer/src/mineplex/bungee/status/InternetStatus.java b/Plugins/Mineplex.Bungee.Mineplexer/src/mineplex/bungee/status/InternetStatus.java index 9cfed1df7..4ad382fbf 100644 --- a/Plugins/Mineplex.Bungee.Mineplexer/src/mineplex/bungee/status/InternetStatus.java +++ b/Plugins/Mineplex.Bungee.Mineplexer/src/mineplex/bungee/status/InternetStatus.java @@ -2,9 +2,7 @@ package mineplex.bungee.status; import java.io.File; import java.io.IOException; -import java.net.InetAddress; import java.net.Socket; -import java.net.UnknownHostException; import java.util.concurrent.TimeUnit; import net.md_5.bungee.api.config.ListenerInfo; diff --git a/Plugins/Mineplex.Bungee.Mineplexer/src/mineplex/bungee/status/StatusRepository.java b/Plugins/Mineplex.Bungee.Mineplexer/src/mineplex/bungee/status/StatusRepository.java index d33472952..c9a4a77cc 100644 --- a/Plugins/Mineplex.Bungee.Mineplexer/src/mineplex/bungee/status/StatusRepository.java +++ b/Plugins/Mineplex.Bungee.Mineplexer/src/mineplex/bungee/status/StatusRepository.java @@ -3,7 +3,6 @@ package mineplex.bungee.status; import java.sql.Connection; import java.sql.DriverManager; import java.sql.PreparedStatement; -import java.sql.ResultSet; import java.sql.SQLException; public class StatusRepository @@ -15,8 +14,9 @@ public class StatusRepository private String _address; private boolean _us; - private static String CREATE_TABLE = "CREATE TABLE IF NOT EXISTS bungeeOnlineStatus (id INT NOT NULL AUTO_INCREMENT, address VARCHAR(40), online BOOLEAN NOT NULL DEFAULT 0, updated LONG, us BOOLEAN NOT NULL DEFAULT 1, PRIMARY KEY (id), UNIQUE INDEX addressIndex(address));"; + private static String CREATE_TABLE = "CREATE TABLE IF NOT EXISTS bungeeOnlineStatus (id INT NOT NULL AUTO_INCREMENT, address VARCHAR(40), online BOOLEAN NOT NULL DEFAULT 0, updated LONG, us BOOLEAN NOT NULL DEFAULT 1, lastOnline LONG, PRIMARY KEY (id), UNIQUE INDEX addressIndex(address));"; private static String INSERT_SERVER = "INSERT INTO bungeeOnlineStatus (address, online, us, updated) values(?, ?, ?, now()) ON DUPLICATE KEY UPDATE online = VALUES(online);"; + private static String INSERT_ONLINE_SERVER = "INSERT INTO bungeeOnlineStatus (address, online, us, updated, lastOnline) values(?, ?, ?, now(), now()) ON DUPLICATE KEY UPDATE online = VALUES(online), lastOnline = VALUES(lastOnline);"; public StatusRepository(String address, boolean us) { @@ -78,7 +78,7 @@ public class StatusRepository { connection = DriverManager.getConnection(_connectionString, _userName, _password); - preparedStatement = connection.prepareStatement(INSERT_SERVER); + preparedStatement = connection.prepareStatement(online ? INSERT_ONLINE_SERVER : INSERT_SERVER); preparedStatement.setString(1, _address); preparedStatement.setBoolean(2, online); From 1455b4001f0dafb2c95bbcab02cf2c25cc335ab4 Mon Sep 17 00:00:00 2001 From: Mini-Chiss Date: Tue, 8 Jul 2014 15:13:30 -0700 Subject: [PATCH 2/7] Parser Update --- .../src/mineplex/mapparser/MapParser.java | 30 +- .../src/mineplex/mapparser/Parse.java | 16 +- .../src/mineplex/mapparser/WorldManager.java | 23 +- .../nautilus/game/arcade/ArcadeManager.java | 1 - .../game/arcade/command/ParseCommand.java | 24 - .../game/arcade/world/WorldParser.java | 439 ------------------ 6 files changed, 44 insertions(+), 489 deletions(-) delete mode 100644 Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/command/ParseCommand.java delete mode 100644 Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/world/WorldParser.java diff --git a/Plugins/Mineplex.MapParser/src/mineplex/mapparser/MapParser.java b/Plugins/Mineplex.MapParser/src/mineplex/mapparser/MapParser.java index e0ea00b85..a7b1db6db 100644 --- a/Plugins/Mineplex.MapParser/src/mineplex/mapparser/MapParser.java +++ b/Plugins/Mineplex.MapParser/src/mineplex/mapparser/MapParser.java @@ -2,6 +2,7 @@ package mineplex.mapparser; import java.io.File; import java.io.IOException; +import java.util.HashMap; import mineplex.core.common.util.C; import mineplex.core.common.util.F; @@ -34,6 +35,8 @@ public class MapParser extends JavaPlugin implements Listener private Parse _curParse = null; + private HashMap _mapData = new HashMap(); + @Override public void onEnable() { @@ -123,6 +126,12 @@ public class MapParser extends JavaPlugin implements Listener String worldName = "map_" + args[0]; + if (DoesMapExist(worldName)) + { + UtilPlayer.message(event.getPlayer(), F.main("Parser", "Map name is already in use!")); + return; + } + Announce("Creating World: " + F.elem(worldName)); WorldCreator worldCreator = new WorldCreator(worldName); @@ -328,10 +337,8 @@ public class MapParser extends JavaPlugin implements Listener return; } - //event.getPlayer().teleport(new Location(parseableWorld, 0, 30 ,0)); - //Parse the World - _curParse = new Parse(this, parseableWorld, msg.split(" "), parseLoc, gameType, "Default", "Default"); + _curParse = new Parse(this, parseableWorld, msg.split(" "), parseLoc, GetData(parseLoc.getWorld().getName())); } else if (event.getMessage().toLowerCase().startsWith("/worlds")) { @@ -360,7 +367,7 @@ public class MapParser extends JavaPlugin implements Listener try { - _worldManager.finalizeParsedWorld(_curParse.getGameType(), _curParse.getWorld()); + _worldManager.finalizeParsedWorld(_curParse.getWorld()); } catch (Exception e) { @@ -387,9 +394,6 @@ public class MapParser extends JavaPlugin implements Listener if (event.getPlayer().getGameMode() != GameMode.CREATIVE) event.getPlayer().setGameMode(GameMode.CREATIVE); - - if (!event.getPlayer().isOp()) - event.getPlayer().setOp(true); } @EventHandler @@ -449,4 +453,16 @@ public class MapParser extends JavaPlugin implements Listener return null; } + + public MapData GetData(String mapName) + { + if (_mapData.containsKey(mapName)) + return _mapData.get(mapName); + + MapData data = new MapData(mapName); + + _mapData.put(mapName, data); + + return data; + } } diff --git a/Plugins/Mineplex.MapParser/src/mineplex/mapparser/Parse.java b/Plugins/Mineplex.MapParser/src/mineplex/mapparser/Parse.java index d0192218e..fe45ca6c3 100644 --- a/Plugins/Mineplex.MapParser/src/mineplex/mapparser/Parse.java +++ b/Plugins/Mineplex.MapParser/src/mineplex/mapparser/Parse.java @@ -35,9 +35,7 @@ public class Parse private int _z = 0; //Map Data - private String _gameType; - private String _mapName; - private String _mapCreator; + private MapData _mapData; //World Data private HashSet _dataId = new HashSet(); @@ -50,7 +48,7 @@ public class Parse private int _processed = 0; - public Parse(MapParser host, World world, String[] args, Location loc, String gameType, String mapName, String mapCreator) + public Parse(MapParser host, World world, String[] args, Location loc, MapData data) { Host = host; @@ -58,9 +56,7 @@ public class Parse _args = args; _callLoc = new Location(world, loc.getX(), loc.getY(), loc.getZ()); - _gameType = gameType; - _mapName = mapName; - _mapCreator = mapCreator; + _mapData = data; Initialize(); } @@ -419,9 +415,9 @@ public class Parse FileWriter fstream = new FileWriter(_world.getName() + File.separator + "WorldConfig.dat"); BufferedWriter out = new BufferedWriter(fstream); - out.write("MAP_NAME:"+_mapName); + out.write("MAP_NAME:"+_mapData.MapName); out.write("\n"); - out.write("MAP_AUTHOR:"+_mapCreator); + out.write("MAP_AUTHOR:"+_mapData.MapCreator); out.write("\n"); out.write("\n"); out.write("MIN_X:"+Math.min(_cornerA.getBlockX(), _cornerB.getBlockX())); @@ -512,7 +508,7 @@ public class Parse public String getGameType() { - return _gameType; + return _mapData.GameType; } public World getWorld() diff --git a/Plugins/Mineplex.MapParser/src/mineplex/mapparser/WorldManager.java b/Plugins/Mineplex.MapParser/src/mineplex/mapparser/WorldManager.java index dd8398e49..0c3146410 100644 --- a/Plugins/Mineplex.MapParser/src/mineplex/mapparser/WorldManager.java +++ b/Plugins/Mineplex.MapParser/src/mineplex/mapparser/WorldManager.java @@ -18,17 +18,17 @@ import org.bukkit.plugin.java.JavaPlugin; public class WorldManager { - private JavaPlugin _plugin; + private MapParser Host; - public WorldManager(JavaPlugin plugin) + public WorldManager(MapParser plugin) { - _plugin = plugin; + Host = plugin; } public World prepMapParse(World world) { //Unload World - MapUtil.UnloadWorld(_plugin, world, true); + MapUtil.UnloadWorld(Host, world, true); //Delete Non-Map Files String[] folders = new File(world.getName()).list(); @@ -42,6 +42,9 @@ public class WorldManager if (fileName.equalsIgnoreCase("WorldConfig.dat")) continue; + + if (fileName.equalsIgnoreCase("Map.dat")) + continue; FileUtils.deleteQuietly(new File(world.getName() + File.separator + fileName)); } @@ -65,9 +68,9 @@ public class WorldManager return Bukkit.createWorld(new WorldCreator("parse_" + world.getName())); } - public void finalizeParsedWorld(String gameType, World world) + public void finalizeParsedWorld(World world) { - MapUtil.UnloadWorld(_plugin, world, true); + MapUtil.UnloadWorld(Host, world, true); ArrayList fileList = new ArrayList(); ArrayList dirList = new ArrayList(); @@ -96,12 +99,16 @@ public class WorldManager FileUtils.deleteQuietly(new File(world.getName() + File.separator + file.getName())); } + MapData data = Host.GetData(world.getName().substring(6)); + + String fileName = data.GameType + "_" + data.MapName + ".zip"; + GameType gameType = GameType.valueOf(data.GameType); - ZipUtil.ZipFolders(Paths.get(world.getName()).toAbsolutePath().toString(), world.getName() + ".zip", dirList, fileList); + ZipUtil.ZipFolders(Paths.get(world.getName()).toAbsolutePath().toString(), fileName, dirList, fileList); try { - FileUtils.copyFile(new File(world.getName() + ".zip"), new File(File.separator + "home" + File.separator + "mineplex" + File.separator + "update" + File.separator + "maps" + File.separator + gameType + File.separator + world.getName() + ".zip")); + FileUtils.copyFile(new File(world.getName() + ".zip"), new File(File.separator + "home" + File.separator + "mineplex" + File.separator + "update" + File.separator + "maps" + File.separator + gameType.GetName() + File.separator + fileName)); } catch (IOException e) { diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/ArcadeManager.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/ArcadeManager.java index 5141b22c0..1b91e43db 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/ArcadeManager.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/ArcadeManager.java @@ -217,7 +217,6 @@ public class ArcadeManager extends MiniPlugin implements IRelation public void AddCommands() { AddCommand(new GameCommand(this)); - AddCommand(new ParseCommand(this)); AddCommand(new WriteCommand(this)); } diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/command/ParseCommand.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/command/ParseCommand.java deleted file mode 100644 index 1610dcbf4..000000000 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/command/ParseCommand.java +++ /dev/null @@ -1,24 +0,0 @@ -package nautilus.game.arcade.command; - -import org.bukkit.entity.Player; - -import nautilus.game.arcade.ArcadeManager; -import nautilus.game.arcade.world.WorldParser; -import mineplex.core.command.CommandBase; -import mineplex.core.common.Rank; - -public class ParseCommand extends CommandBase -{ - public ParseCommand(ArcadeManager plugin) - { - super(plugin, Rank.ADMIN, "parse"); - } - - @Override - public void Execute(Player caller, String[] args) - { - caller.sendMessage("Parsing World"); - WorldParser parser = new WorldParser(); - parser.Parse(caller, args); - } -} diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/world/WorldParser.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/world/WorldParser.java deleted file mode 100644 index 359caa587..000000000 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/world/WorldParser.java +++ /dev/null @@ -1,439 +0,0 @@ -package nautilus.game.arcade.world; - -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.UtilWorld; - -import org.bukkit.Location; -import org.bukkit.Material; -import org.bukkit.block.Block; -import org.bukkit.block.BlockFace; -import org.bukkit.block.Sign; -import org.bukkit.entity.Player; -import org.bukkit.material.Wool; - -public class WorldParser -{ - public void Parse(Player caller, String[] args) - { - HashSet dataId = new HashSet(); - - if (args != null) - for (String arg : args) - { - try - { - dataId.add(Integer.parseInt(arg)); - } - catch (Exception e) - { - caller.sendMessage("Invalid Data ID: " + arg); - } - } - - HashMap> TeamLocs = new HashMap>(); - HashMap> DataLocs = new HashMap>(); - HashMap> CustomLocs = new HashMap>(); - - Location cornerA = null; - Location cornerB = null; - - int processed = 0; - - caller.sendMessage("Scanning for Blocks..."); - for (int x=-600 ; x < 600 ; x++) - for (int z=-600 ; z < 600 ; z++) - for (int y=0 ; y < 256 ; y++) - { - processed++; - if (processed % 20000000 == 0) - caller.sendMessage("Processed: " + processed); - - Block block = caller.getWorld().getBlockAt(caller.getLocation().getBlockX()+x, caller.getLocation().getBlockY()+y, caller.getLocation().getBlockZ()+z); - - //ID DATA - if (dataId.contains(block.getTypeId())) - { - String key = ""+block.getTypeId(); - - if (!CustomLocs.containsKey(key)) - CustomLocs.put(key, new ArrayList()); - - CustomLocs.get(key).add(block.getLocation()); - continue; - } - - //Signs - if (block.getType() == Material.SIGN_POST || block.getType() == Material.WALL_SIGN) - { - if (block.getRelative(BlockFace.DOWN).getType() == Material.SPONGE) - { - Sign s = (Sign) block.getState(); - - String name = ""; - - try - { - name = s.getLine(0); - } - catch (Exception e) - { - caller.sendMessage("Invalid Sign Data: " + UtilWorld.locToStr(block.getLocation())); - } - - //Add - if (!CustomLocs.containsKey(name)) - CustomLocs.put(name, new ArrayList()); - - CustomLocs.get(name).add(block.getRelative(BlockFace.DOWN).getLocation()); - - //Remove Blocks - block.setTypeId(0); - block.getRelative(BlockFace.DOWN).setTypeId(0); - } - } - - //Spawns - if (block.getTypeId() == 147) - { - Block wool = block.getRelative(BlockFace.DOWN); - if (wool == null) - continue; - - if (wool.getType() == Material.WOOL) - { - if (wool.getData() == 14) //RED > Spawn - { - if (!TeamLocs.containsKey("Red")) - TeamLocs.put("Red", new ArrayList()); - - TeamLocs.get("Red").add(wool.getLocation()); - - //Remove Blocks - block.setTypeId(0); - wool.setTypeId(0); - } - - if (wool.getData() == 4) //RED > Spawn - { - if (!TeamLocs.containsKey("Yellow")) - TeamLocs.put("Yellow", new ArrayList()); - - TeamLocs.get("Yellow").add(wool.getLocation()); - - //Remove Blocks - block.setTypeId(0); - wool.setTypeId(0); - } - - if (wool.getData() == 13) //RED > Spawn - { - if (!TeamLocs.containsKey("Green")) - TeamLocs.put("Green", new ArrayList()); - - TeamLocs.get("Green").add(wool.getLocation()); - - //Remove Blocks - block.setTypeId(0); - wool.setTypeId(0); - } - - if (wool.getData() == 11) //RED > Spawn - { - if (!TeamLocs.containsKey("Blue")) - TeamLocs.put("Blue", new ArrayList()); - - TeamLocs.get("Blue").add(wool.getLocation()); - - //Remove Blocks - block.setTypeId(0); - wool.setTypeId(0); - } - - if (wool.getData() == 1) - { - if (!TeamLocs.containsKey("Orange")) - TeamLocs.put("Orange", new ArrayList()); - - TeamLocs.get("Orange").add(wool.getLocation()); - - //Remove Blocks - block.setTypeId(0); - wool.setTypeId(0); - } - - if (wool.getData() == 2) - { - if (!TeamLocs.containsKey("Magenta")) - TeamLocs.put("Magenta", new ArrayList()); - - TeamLocs.get("Magenta").add(wool.getLocation()); - - //Remove Blocks - block.setTypeId(0); - wool.setTypeId(0); - } - - if (wool.getData() == 3) - { - if (!TeamLocs.containsKey("Sky")) - TeamLocs.put("Sky", new ArrayList()); - - TeamLocs.get("Sky").add(wool.getLocation()); - - //Remove Blocks - block.setTypeId(0); - wool.setTypeId(0); - } - - if (wool.getData() == 5) - { - if (!TeamLocs.containsKey("Lime")) - TeamLocs.put("Lime", new ArrayList()); - - TeamLocs.get("Lime").add(wool.getLocation()); - - //Remove Blocks - block.setTypeId(0); - wool.setTypeId(0); - } - - if (wool.getData() == 6) - { - if (!TeamLocs.containsKey("Pink")) - TeamLocs.put("Pink", new ArrayList()); - - TeamLocs.get("Pink").add(wool.getLocation()); - - //Remove Blocks - block.setTypeId(0); - wool.setTypeId(0); - } - - if (wool.getData() == 7) - { - if (!TeamLocs.containsKey("Gray")) - TeamLocs.put("Gray", new ArrayList()); - - TeamLocs.get("Gray").add(wool.getLocation()); - - //Remove Blocks - block.setTypeId(0); - wool.setTypeId(0); - } - - if (wool.getData() == 8) - { - if (!TeamLocs.containsKey("LGray")) - TeamLocs.put("LGray", new ArrayList()); - - TeamLocs.get("LGray").add(wool.getLocation()); - - //Remove Blocks - block.setTypeId(0); - wool.setTypeId(0); - } - - if (wool.getData() == 9) - { - if (!TeamLocs.containsKey("Cyan")) - TeamLocs.put("Cyan", new ArrayList()); - - TeamLocs.get("Cyan").add(wool.getLocation()); - - //Remove Blocks - block.setTypeId(0); - wool.setTypeId(0); - } - - if (wool.getData() == 10) - { - if (!TeamLocs.containsKey("Purple")) - TeamLocs.put("Purple", new ArrayList()); - - TeamLocs.get("Purple").add(wool.getLocation()); - - //Remove Blocks - block.setTypeId(0); - wool.setTypeId(0); - } - - if (wool.getData() == 11) - { - if (!TeamLocs.containsKey("DBlue")) - TeamLocs.put("DBlue", new ArrayList()); - - TeamLocs.get("DBlue").add(wool.getLocation()); - - //Remove Blocks - block.setTypeId(0); - wool.setTypeId(0); - } - - if (wool.getData() == 12) - { - if (!TeamLocs.containsKey("Brown")) - TeamLocs.put("Brown", new ArrayList()); - - TeamLocs.get("Brown").add(wool.getLocation()); - - //Remove Blocks - block.setTypeId(0); - wool.setTypeId(0); - } - - if (wool.getData() == 15) - { - if (!TeamLocs.containsKey("Black")) - TeamLocs.put("Black", new ArrayList()); - - TeamLocs.get("Black").add(wool.getLocation()); - - //Remove Blocks - block.setTypeId(0); - wool.setTypeId(0); - } - - if (wool.getData() == 0) //WHITE > Corner - { - if (cornerA == null) cornerA = wool.getLocation(); - else if (cornerB == null) cornerB = wool.getLocation(); - else caller.sendMessage("More than 2 Corner Locations found!"); - - //Remove Blocks - block.setTypeId(0); - wool.setTypeId(0); - } - } - } - - if (block.getTypeId() != 148) - continue; - - Block wool = block.getRelative(BlockFace.DOWN); - if (wool == null) - continue; - - if (wool.getType() != Material.WOOL) - continue; - - Wool woolData = new Wool(wool.getType(), wool.getData()); - - String dataType = woolData.getColor().name(); - - if (!DataLocs.containsKey(dataType)) - DataLocs.put(dataType, new ArrayList()); - - DataLocs.get(dataType).add(wool.getLocation()); - - //Remove Blocks - block.setTypeId(0); - wool.setTypeId(0); - } - - if (cornerA == null || cornerB == null) - { - caller.sendMessage("Missing Corner Locations!"); - return; - } - - //Save - try - { - FileWriter fstream = new FileWriter(caller.getWorld().getName() + File.separator + "WorldConfig.dat"); - BufferedWriter out = new BufferedWriter(fstream); - - out.write("MAP_NAME:"); - out.write("\n"); - out.write("MAP_AUTHOR:"); - out.write("\n"); - out.write("\n"); - out.write("MIN_X:"+Math.min(cornerA.getBlockX(), cornerB.getBlockX())); - out.write("\n"); - out.write("MAX_X:"+Math.max(cornerA.getBlockX(), cornerB.getBlockX())); - out.write("\n"); - out.write("MIN_Z:"+Math.min(cornerA.getBlockZ(), cornerB.getBlockZ())); - out.write("\n"); - out.write("MAX_Z:"+Math.max(cornerA.getBlockZ(), cornerB.getBlockZ())); - out.write("\n"); - out.write("\n"); - if (cornerA.getBlockY() == cornerB.getBlockY()) - { - out.write("MIN_Y:0"); - out.write("\n"); - out.write("MAX_Y:256"); - } - else - { - out.write("MIN_Y:"+Math.min(cornerA.getBlockY(), cornerB.getBlockY())); - out.write("\n"); - out.write("MAX_Y:"+Math.max(cornerA.getBlockY(), cornerB.getBlockY())); - } - - //Teams - for (String team : TeamLocs.keySet()) - { - out.write("\n"); - out.write("\n"); - out.write("TEAM_NAME:" + team); - out.write("\n"); - out.write("TEAM_SPAWNS:" + LocationsToString(TeamLocs.get(team))); - } - - //Data - for (String data : DataLocs.keySet()) - { - out.write("\n"); - out.write("\n"); - out.write("DATA_NAME:" + data); - out.write("\n"); - out.write("DATA_LOCS:" + LocationsToString(DataLocs.get(data))); - } - - //Custom - for (String data : CustomLocs.keySet()) - { - out.write("\n"); - out.write("\n"); - out.write("CUSTOM_NAME:" + data); - out.write("\n"); - out.write("CUSTOM_LOCS:" + LocationsToString(CustomLocs.get(data))); - } - - out.close(); - } - catch (Exception e) - { - caller.sendMessage("Error: File Write Error"); - } - - - caller.sendMessage("World Data Saved."); - } - - public String LocationsToString(ArrayList locs) - { - String out = ""; - - for (Location loc : locs) - out += loc.getBlockX() + "," + loc.getBlockY() + "," + loc.getBlockZ() + ":"; - - return out; - } - - public String LocationSignsToString(HashMap locs) - { - String out = ""; - - for (Location loc : locs.keySet()) - out += locs.get(loc) + "@" + loc.getBlockX() + "," + loc.getBlockY() + "," + loc.getBlockZ() + ":"; - - return out; - } -} - From dd0040086d6923f13b51a0265c9b12d8fb4e7fb0 Mon Sep 17 00:00:00 2001 From: Mini-Chiss Date: Tue, 8 Jul 2014 17:33:22 -0700 Subject: [PATCH 3/7] Parser Permissions Sneaky Assasssin thingy. --- .../src/mineplex/mapparser/MapParser.java | 413 +++++++++++++++--- .../src/mineplex/mapparser/Parse.java | 2 +- .../src/mineplex/mapparser/WorldManager.java | 2 +- .../sneakyassassins/SneakyAssassins.java | 22 + 4 files changed, 384 insertions(+), 55 deletions(-) diff --git a/Plugins/Mineplex.MapParser/src/mineplex/mapparser/MapParser.java b/Plugins/Mineplex.MapParser/src/mineplex/mapparser/MapParser.java index a7b1db6db..68f3b2d49 100644 --- a/Plugins/Mineplex.MapParser/src/mineplex/mapparser/MapParser.java +++ b/Plugins/Mineplex.MapParser/src/mineplex/mapparser/MapParser.java @@ -7,13 +7,16 @@ import java.util.HashMap; import mineplex.core.common.util.C; import mineplex.core.common.util.F; import mineplex.core.common.util.MapUtil; +import mineplex.core.common.util.UtilInv; import mineplex.core.common.util.UtilPlayer; import mineplex.core.common.util.UtilServer; import net.minecraft.util.org.apache.commons.io.FileUtils; import org.bukkit.Bukkit; +import org.bukkit.ChatColor; import org.bukkit.GameMode; import org.bukkit.Location; +import org.bukkit.Material; import org.bukkit.World; import org.bukkit.World.Environment; import org.bukkit.WorldCreator; @@ -24,9 +27,13 @@ import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; 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.PlayerMoveEvent; +import org.bukkit.event.player.PlayerQuitEvent; +import org.bukkit.inventory.ItemStack; import org.bukkit.plugin.java.JavaPlugin; public class MapParser extends JavaPlugin implements Listener @@ -63,6 +70,8 @@ public class MapParser extends JavaPlugin implements Listener player.teleport(new Location(getServer().getWorlds().get(0), 0, 106, 0)); + ResetInventory(event.getPlayer()); + DisplayHelp(player); } @@ -70,21 +79,30 @@ public class MapParser extends JavaPlugin implements Listener { UtilPlayer.message(player, F.main("Parser", "Listing Commands;")); UtilPlayer.message(player, F.value("/hub", "Return to hub world")); + UtilPlayer.message(player, " "); UtilPlayer.message(player, F.value("/create ", "Creates a new map")); UtilPlayer.message(player, F.value("/delete ", "Deletes an existing map")); UtilPlayer.message(player, F.value("/map ", "Teleport to a map")); UtilPlayer.message(player, F.value("/list", "List maps")); - UtilPlayer.message(player, F.value("/copyschematics", "Loads Schematics from Build-1")); + UtilPlayer.message(player, F.value("/parse", "Parse your current map!")); + UtilPlayer.message(player, " "); + UtilPlayer.message(player, F.value("/join ", "Toggle join for player on map")); + UtilPlayer.message(player, F.value("/build ", "Toggle build for player on map")); + UtilPlayer.message(player, " "); + UtilPlayer.message(player, F.value("/name ", "Set name for current map")); + UtilPlayer.message(player, F.value("/author ", "Set author for current map")); + UtilPlayer.message(player, F.value("/gametype "))); return; } - + + String[] args = event.getMessage().substring(event.getMessage().indexOf(' ') + 1).split(" "); + String worldName = "map_" + args[0]; if (DoesMapExist(worldName)) @@ -144,19 +162,24 @@ public class MapParser extends JavaPlugin implements Listener UtilPlayer.message(caller, F.main("Parser", "Teleporting to World: " + F.elem(worldName))); event.getPlayer().teleport(new Location(world, 0, 100, 0)); + + //Give Access + GetData(world.getName()).WhiteList.add(event.getPlayer().getName()); + GetData(world.getName()).BuildList.add(event.getPlayer().getName()); + GetData(world.getName()).Write(); } else if (event.getMessage().toLowerCase().startsWith("/delete")) { event.setCancelled(true); - String[] args = event.getMessage().substring(event.getMessage().indexOf(' ') + 1).split(" "); - - if (args.length < 1) + if (event.getMessage().split(" ").length < 2) { UtilPlayer.message(event.getPlayer(), F.main("Parser", "Invalid Input. " + F.elem("/delete "))); return; } + String[] args = event.getMessage().substring(event.getMessage().indexOf(' ') + 1).split(" "); + String worldName = "map_" + args[0]; if (!DoesMapExist(worldName)) @@ -165,6 +188,12 @@ public class MapParser extends JavaPlugin implements Listener return; } + if (!GetData(worldName).CanBuild(event.getPlayer())) + { + UtilPlayer.message(caller, F.main("Parser", "You do not have Build-Access on this Map.")); + return; + } + if (GetMapWorld(worldName) != null) { World world = GetMapWorld(worldName); @@ -186,20 +215,26 @@ public class MapParser extends JavaPlugin implements Listener { event.setCancelled(true); - String[] args = event.getMessage().substring(event.getMessage().indexOf(' ') + 1).split(" "); - - if (args.length < 1) + if (event.getMessage().split(" ").length < 2) { UtilPlayer.message(event.getPlayer(), F.main("Parser", "Invalid Input. " + F.elem("/save "))); return; } - String worldName = "map_" + args[0]; + String[] args = event.getMessage().substring(event.getMessage().indexOf(' ') + 1).split(" "); + String worldName = "map_" + args[0]; + if (GetMapWorld(worldName) != null) { World world = GetMapWorld(worldName); + if (!GetData(worldName).CanBuild(event.getPlayer())) + { + UtilPlayer.message(caller, F.main("Parser", "You do not have Build-Access on this Map.")); + return; + } + //Teleport Out for (Player other : world.getPlayers()) other.teleport(new Location(getServer().getWorlds().get(0), 0, 106, 0)); @@ -225,14 +260,14 @@ public class MapParser extends JavaPlugin implements Listener { event.setCancelled(true); - String[] args = event.getMessage().substring(event.getMessage().indexOf(' ') + 1).split(" "); - - if (args.length < 1) + if (event.getMessage().split(" ").length < 2) { UtilPlayer.message(event.getPlayer(), F.main("Parser", "Invalid Input. " + F.elem("/map "))); return; } + String[] args = event.getMessage().substring(event.getMessage().indexOf(' ') + 1).split(" "); + String worldName = "map_" + args[0]; World world = GetMapWorld(worldName); @@ -255,6 +290,13 @@ public class MapParser extends JavaPlugin implements Listener UtilPlayer.message(caller, F.main("Parser", "Null World Error: " + F.elem(worldName))); return; } + + //Permission + if (!GetData(world.getName()).CanJoin(event.getPlayer())) + { + UtilPlayer.message(caller, F.main("Parser", "You do not have Join-Access on this Map.")); + return; + } //Teleport UtilPlayer.message(caller, F.main("Parser", "Teleporting to World: " + F.elem(worldName))); @@ -278,49 +320,23 @@ public class MapParser extends JavaPlugin implements Listener caller.sendMessage(file.getName()); } - - //_worldManager.listPendingParses(event.getPlayer()); } else if (event.getMessage().toLowerCase().startsWith("/parse")) { event.setCancelled(true); Location parseLoc = event.getPlayer().getLocation(); - - String[] args = event.getMessage().substring(event.getMessage().indexOf(' ') + 1).split(" "); - - if (args.length < 1) - { - UtilPlayer.message(event.getPlayer(), F.main("Parser", "Invalid Input. " + F.elem("/parse "))); - return; - } - - String gameType = args[0]; - - try - { - GameType.valueOf(gameType); - } - catch (Exception ex) - { - UtilPlayer.message(event.getPlayer(), F.main("Parser", "Valid Game Types;")); - - String gameTypes = ""; - - for (GameType game : GameType.values()) - { - gameTypes += game.toString() + " "; - } - - event.getPlayer().sendMessage(gameTypes); - - return; - } - - String msg = event.getMessage().replace(gameType, "").toLowerCase(); - + World world = caller.getWorld(); + MapData data = GetData(caller.getWorld().getName()); + + if (data.MapName.equals("null") || data.MapCreator.equals("null") || data.GameType.equals("null")) + { + UtilPlayer.message(event.getPlayer(), F.main("Parser", "Map Name/Author/GameType are not set!")); + return; + } + //Teleport Players Out for (Player worldPlayer : world.getPlayers()) { @@ -338,7 +354,7 @@ public class MapParser extends JavaPlugin implements Listener } //Parse the World - _curParse = new Parse(this, parseableWorld, msg.split(" "), parseLoc, GetData(parseLoc.getWorld().getName())); + _curParse = new Parse(this, parseableWorld, event.getMessage().split(" "), parseLoc, GetData(parseLoc.getWorld().getName())); } else if (event.getMessage().toLowerCase().startsWith("/worlds")) { @@ -351,6 +367,221 @@ public class MapParser extends JavaPlugin implements Listener event.getPlayer().sendMessage(world.getName()); } } + + //XXX Set Map Data + else if (event.getMessage().toLowerCase().startsWith("/name")) + { + event.setCancelled(true); + + if (event.getMessage().split(" ").length < 2) + { + UtilPlayer.message(event.getPlayer(), F.main("Parser", "Invalid Input. " + F.elem("/name "))); + return; + } + + String input = event.getMessage().substring(event.getMessage().indexOf(' ') + 1); + + if (event.getPlayer().getWorld().getName().equals("world")) + { + UtilPlayer.message(event.getPlayer(), F.main("Parser", "Cannot set name for Lobby.")); + return; + } + + //Permission + if (!GetData(event.getPlayer().getWorld().getName()).CanBuild(event.getPlayer())) + { + UtilPlayer.message(caller, F.main("Parser", "You do not have Build-Access on this Map.")); + return; + } + + MapData data = GetData(event.getPlayer().getWorld().getName()); + + data.MapName = input; + data.Write(); + + Announce("Map Name for " + F.elem(event.getPlayer().getWorld().getName()) + " set to " + F.elem(input) + "."); + } + else if (event.getMessage().toLowerCase().startsWith("/author")) + { + event.setCancelled(true); + + if (event.getMessage().split(" ").length < 2) + { + UtilPlayer.message(event.getPlayer(), F.main("Parser", "Invalid Input. " + F.elem("/author "))); + return; + } + + String input = event.getMessage().substring(event.getMessage().indexOf(' ') + 1); + + if (event.getPlayer().getWorld().getName().equals("world")) + { + UtilPlayer.message(event.getPlayer(), F.main("Parser", "Cannot set author for Lobby.")); + return; + } + + //Permission + if (!GetData(event.getPlayer().getWorld().getName()).CanBuild(event.getPlayer())) + { + UtilPlayer.message(caller, F.main("Parser", "You do not have Build-Access on this Map.")); + return; + } + + MapData data = GetData(event.getPlayer().getWorld().getName()); + + data.MapCreator = input; + data.Write(); + + Announce("Map Author for " + F.elem(event.getPlayer().getWorld().getName()) + " set to " + F.elem(input) + "."); + } + else if (event.getMessage().toLowerCase().startsWith("/gametype")) + { + event.setCancelled(true); + + if (event.getMessage().split(" ").length < 2) + { + UtilPlayer.message(event.getPlayer(), F.main("Parser", "Invalid Input. " + F.elem("/gametype "))); + return; + } + + String[] args = event.getMessage().substring(event.getMessage().indexOf(' ') + 1).split(" "); + + if (event.getPlayer().getWorld().getName().equals("world")) + { + UtilPlayer.message(event.getPlayer(), F.main("Parser", "Cannot set GameType for Lobby.")); + return; + } + + //Permission + if (!GetData(event.getPlayer().getWorld().getName()).CanBuild(event.getPlayer())) + { + UtilPlayer.message(caller, F.main("Parser", "You do not have Build-Access on this Map.")); + return; + } + + //Check Gametype + try + { + GameType.valueOf(args[0]); + } + catch (Exception ex) + { + UtilPlayer.message(event.getPlayer(), F.main("Parser", "Valid Game Types;")); + + String gameTypes = ""; + + for (GameType game : GameType.values()) + { + gameTypes += game.toString() + " "; + } + + event.getPlayer().sendMessage(gameTypes); + + return; + } + + MapData data = GetData(event.getPlayer().getWorld().getName()); + + data.GameType = args[0]; + data.Write(); + + Announce("GameType for " + F.elem(event.getPlayer().getWorld().getName()) + " set to " + F.elem(args[0]) + "."); + } + + else if (event.getMessage().toLowerCase().startsWith("/join")) + { + event.setCancelled(true); + + if (event.getMessage().split(" ").length < 2) + { + UtilPlayer.message(event.getPlayer(), F.main("Parser", "Invalid Input. " + F.elem("/join "))); + return; + } + + String input = event.getMessage().substring(event.getMessage().indexOf(' ') + 1).split(" ")[0]; + + if (event.getPlayer().getWorld().getName().equals("world")) + { + UtilPlayer.message(event.getPlayer(), F.main("Parser", "Cannot change Join-List for Lobby.")); + return; + } + + //Permission + if (!GetData(event.getPlayer().getWorld().getName()).CanBuild(event.getPlayer())) + { + UtilPlayer.message(caller, F.main("Parser", "You do not have Build-Access on this Map.")); + return; + } + + Player player = UtilPlayer.searchOnline(event.getPlayer(), input, true); + + if (player != null) + { + MapData data = GetData(event.getPlayer().getWorld().getName()); + + if (data.WhiteList.contains(player.getName())) + { + data.WhiteList.remove(player.getName()); + data.Write(); + + Announce("Join-List for " + F.elem(event.getPlayer().getWorld().getName()) + " (" + player.getName() + " = " + F.tf(false) + ")"); + } + else + { + data.WhiteList.add(player.getName()); + data.Write(); + + Announce("Join-List for " + F.elem(event.getPlayer().getWorld().getName()) + " (" + player.getName() + " = " + F.tf(true) + ")"); + } + } + } + + else if (event.getMessage().toLowerCase().startsWith("/build")) + { + event.setCancelled(true); + + if (event.getMessage().split(" ").length < 2) + { + UtilPlayer.message(event.getPlayer(), F.main("Parser", "Invalid Input. " + F.elem("/build "))); + return; + } + + String input = event.getMessage().substring(event.getMessage().indexOf(' ') + 1).split(" ")[0]; + + if (event.getPlayer().getWorld().getName().equals("world")) + { + UtilPlayer.message(event.getPlayer(), F.main("Parser", "Cannot change Build-List for Lobby.")); + return; + } + + //Permission + if (!GetData(event.getPlayer().getWorld().getName()).CanBuild(event.getPlayer())) + { + UtilPlayer.message(caller, F.main("Parser", "You do not have Build-Access on this Map.")); + return; + } + + Player player = UtilPlayer.searchOnline(event.getPlayer(), input, true); + + if (player != null) + { + MapData data = GetData(event.getPlayer().getWorld().getName()); + + if (data.BuildList.contains(player.getName())) + { + data.BuildList.remove(player.getName()); + data.Write(); + + Announce("Build-List for " + F.elem(event.getPlayer().getWorld().getName()) + " (" + player.getName() + " = " + F.tf(false) + ")"); + } + else + { + data.BuildList.add(player.getName()); + data.Write(); + + Announce("Build-List for " + F.elem(event.getPlayer().getWorld().getName()) + " (" + player.getName() + " = " + F.tf(true) + ")"); + } + } + } } @EventHandler @@ -465,4 +696,80 @@ public class MapParser extends JavaPlugin implements Listener return data; } + + public void ResetInventory(Player player) + { + UtilInv.Clear(player); + + player.getInventory().addItem(new ItemStack(Material.STONE_SWORD)); + player.getInventory().addItem(new ItemStack(Material.STONE_SPADE)); + player.getInventory().addItem(new ItemStack(Material.STONE_PICKAXE)); + player.getInventory().addItem(new ItemStack(Material.STONE_AXE)); + } + + @EventHandler + public void Chat(AsyncPlayerChatEvent event) + { + event.setCancelled(true); + + String world = C.cDGreen + C.Bold + event.getPlayer().getWorld().getName(); + + String name = C.cYellow + event.getPlayer().getName(); + if (GetData(event.getPlayer().getWorld().getName()).CanBuild(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 + public void InteractCancel(PlayerInteractEvent event) + { + //Permission + if (!GetData(event.getPlayer().getWorld().getName()).CanBuild(event.getPlayer())) + { + event.setCancelled(true); + } + } + + @EventHandler + public void WorldeditCancel(PlayerCommandPreprocessEvent event) + { + if (event.getMessage().startsWith("//")) + { + //Permission + if (!GetData(event.getPlayer().getWorld().getName()).CanBuild(event.getPlayer())) + { + UtilPlayer.message(event.getPlayer(), F.main("Parser", "You do not have Build-Access for this Map.")); + event.setCancelled(true); + } + } + } + + @EventHandler + public void Join(PlayerJoinEvent event) + { + event.setJoinMessage(F.sys("Player Join", event.getPlayer().getName())); + } + + @EventHandler + public void Join(PlayerQuitEvent event) + { + event.setQuitMessage(F.sys("Player Quit", event.getPlayer().getName())); + } } diff --git a/Plugins/Mineplex.MapParser/src/mineplex/mapparser/Parse.java b/Plugins/Mineplex.MapParser/src/mineplex/mapparser/Parse.java index fe45ca6c3..9ea4f381f 100644 --- a/Plugins/Mineplex.MapParser/src/mineplex/mapparser/Parse.java +++ b/Plugins/Mineplex.MapParser/src/mineplex/mapparser/Parse.java @@ -171,7 +171,7 @@ public class Parse else if (_cornerB == null) { _cornerB = wool.getLocation(); - Host.Announce("Corner B: " + UtilWorld.locToStrClean(_cornerA)); + Host.Announce("Corner B: " + UtilWorld.locToStrClean(_cornerB)); } else diff --git a/Plugins/Mineplex.MapParser/src/mineplex/mapparser/WorldManager.java b/Plugins/Mineplex.MapParser/src/mineplex/mapparser/WorldManager.java index 0c3146410..c9cad10ac 100644 --- a/Plugins/Mineplex.MapParser/src/mineplex/mapparser/WorldManager.java +++ b/Plugins/Mineplex.MapParser/src/mineplex/mapparser/WorldManager.java @@ -108,7 +108,7 @@ public class WorldManager try { - FileUtils.copyFile(new File(world.getName() + ".zip"), new File(File.separator + "home" + File.separator + "mineplex" + File.separator + "update" + File.separator + "maps" + File.separator + gameType.GetName() + File.separator + fileName)); + FileUtils.copyFile(new File(fileName), new File(File.separator + "home" + File.separator + "mineplex" + File.separator + "update" + File.separator + "maps" + File.separator + gameType.GetName() + File.separator + fileName)); } catch (IOException e) { diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/sneakyassassins/SneakyAssassins.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/sneakyassassins/SneakyAssassins.java index 62876f137..4903f730c 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/sneakyassassins/SneakyAssassins.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/sneakyassassins/SneakyAssassins.java @@ -1,12 +1,14 @@ package nautilus.game.arcade.game.games.sneakyassassins; import mineplex.core.common.util.*; +import mineplex.minecraft.game.core.damage.CustomDamageEvent; import nautilus.game.arcade.*; import nautilus.game.arcade.events.*; import nautilus.game.arcade.game.*; import nautilus.game.arcade.game.games.sneakyassassins.kits.*; import nautilus.game.arcade.game.games.sneakyassassins.powerups.*; import nautilus.game.arcade.kit.*; + import org.bukkit.*; import org.bukkit.entity.*; import org.bukkit.event.*; @@ -70,6 +72,7 @@ public class SneakyAssassins extends SoloGame } } + /* @EventHandler(ignoreCancelled = true) public void onPlayerAttackWithSword(EntityDamageByEntityEvent event) { @@ -91,4 +94,23 @@ public class SneakyAssassins extends SoloGame event.setDamage(damage); } + */ + + @EventHandler + public void onPlayerAttackWithSword(CustomDamageEvent event) + { + Player damager = event.GetDamagerPlayer(false); + if (damager == null) + return; + + if (damager.getItemInHand() == null) + return; + + Double damage = SWORD_DAMAGE.get(damager.getItemInHand().getType()); + + if (damage == null) + return; + + event.AddMod(GetName(), "Sword Damage", damage - event.GetDamage(), false); + } } From c5e05523d3f98b3dfb6b59e1d092605900b7df14 Mon Sep 17 00:00:00 2001 From: Mini-Chiss Date: Tue, 8 Jul 2014 17:34:47 -0700 Subject: [PATCH 4/7] sneakyfix --- .../game/arcade/game/games/sneakyassassins/SneakyAssassins.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/sneakyassassins/SneakyAssassins.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/sneakyassassins/SneakyAssassins.java index 4903f730c..b23128a92 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/sneakyassassins/SneakyAssassins.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/sneakyassassins/SneakyAssassins.java @@ -96,7 +96,7 @@ public class SneakyAssassins extends SoloGame } */ - @EventHandler + @EventHandler(priority = EventPriority.LOW) public void onPlayerAttackWithSword(CustomDamageEvent event) { Player damager = event.GetDamagerPlayer(false); From bd6b9b8888228f34d5174c6e251f6463b5740a5d Mon Sep 17 00:00:00 2001 From: Mini-Chiss Date: Tue, 8 Jul 2014 17:35:27 -0700 Subject: [PATCH 5/7] so many fix --- .../arcade/game/games/sneakyassassins/SneakyAssassins.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/sneakyassassins/SneakyAssassins.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/sneakyassassins/SneakyAssassins.java index b23128a92..0a23f3842 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/sneakyassassins/SneakyAssassins.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/sneakyassassins/SneakyAssassins.java @@ -103,6 +103,9 @@ public class SneakyAssassins extends SoloGame if (damager == null) return; + if (!IsAlive(damager)) + return; + if (damager.getItemInHand() == null) return; From 74817f5f2eeab063c364dda825c24c16da4096af Mon Sep 17 00:00:00 2001 From: Jonathan Williams Date: Tue, 8 Jul 2014 18:01:03 -0700 Subject: [PATCH 6/7] Added rule book to Hub. Fixed mineplexer bungee internet status. Fixed up ddosprotectionswitcher. --- .../bungee/status/InternetStatus.java | 4 +- .../bungee/status/StatusRepository.java | 4 +- .../mineplex/ddos/DDoSProtectionSwitcher.java | 193 ++++++++++-------- .../mineplex/ddos/DnsMadeEasyRepository.java | 120 ++++++++++- .../src/mineplex/ddos/api/ApiDeleteCall.java | 19 ++ .../src/mineplex/hub/HubManager.java | 138 +++++++++++++ 6 files changed, 390 insertions(+), 88 deletions(-) create mode 100644 Plugins/Mineplex.DDoSProtectionSwitcher/src/mineplex/ddos/api/ApiDeleteCall.java diff --git a/Plugins/Mineplex.Bungee.Mineplexer/src/mineplex/bungee/status/InternetStatus.java b/Plugins/Mineplex.Bungee.Mineplexer/src/mineplex/bungee/status/InternetStatus.java index 4ad382fbf..008d6bc91 100644 --- a/Plugins/Mineplex.Bungee.Mineplexer/src/mineplex/bungee/status/InternetStatus.java +++ b/Plugins/Mineplex.Bungee.Mineplexer/src/mineplex/bungee/status/InternetStatus.java @@ -24,7 +24,7 @@ public class InternetStatus implements Runnable _repository = new StatusRepository(address, us); _repository.initialize(); - _plugin.getProxy().getScheduler().schedule(_plugin, this, 5L, 5L, TimeUnit.MINUTES); + _plugin.getProxy().getScheduler().schedule(_plugin, this, 1L, 1L, TimeUnit.MINUTES); } @Override @@ -41,7 +41,7 @@ public class InternetStatus implements Runnable return true; else if (testUrl("www.bing.com")) return true; - + return false; } diff --git a/Plugins/Mineplex.Bungee.Mineplexer/src/mineplex/bungee/status/StatusRepository.java b/Plugins/Mineplex.Bungee.Mineplexer/src/mineplex/bungee/status/StatusRepository.java index c9a4a77cc..3b300b28d 100644 --- a/Plugins/Mineplex.Bungee.Mineplexer/src/mineplex/bungee/status/StatusRepository.java +++ b/Plugins/Mineplex.Bungee.Mineplexer/src/mineplex/bungee/status/StatusRepository.java @@ -15,8 +15,8 @@ public class StatusRepository private boolean _us; private static String CREATE_TABLE = "CREATE TABLE IF NOT EXISTS bungeeOnlineStatus (id INT NOT NULL AUTO_INCREMENT, address VARCHAR(40), online BOOLEAN NOT NULL DEFAULT 0, updated LONG, us BOOLEAN NOT NULL DEFAULT 1, lastOnline LONG, PRIMARY KEY (id), UNIQUE INDEX addressIndex(address));"; - private static String INSERT_SERVER = "INSERT INTO bungeeOnlineStatus (address, online, us, updated) values(?, ?, ?, now()) ON DUPLICATE KEY UPDATE online = VALUES(online);"; - private static String INSERT_ONLINE_SERVER = "INSERT INTO bungeeOnlineStatus (address, online, us, updated, lastOnline) values(?, ?, ?, now(), now()) ON DUPLICATE KEY UPDATE online = VALUES(online), lastOnline = VALUES(lastOnline);"; + private static String INSERT_SERVER = "INSERT INTO bungeeOnlineStatus (address, online, us, updated) values(?, ?, ?, now()) ON DUPLICATE KEY UPDATE online = VALUES(online), updated = VALUES(updated);"; + private static String INSERT_ONLINE_SERVER = "INSERT INTO bungeeOnlineStatus (address, online, us, updated, lastOnline) values(?, ?, ?, now(), now()) ON DUPLICATE KEY UPDATE online = VALUES(online), updated = VALUES(updated), lastOnline = VALUES(lastOnline);"; public StatusRepository(String address, boolean us) { diff --git a/Plugins/Mineplex.DDoSProtectionSwitcher/src/mineplex/ddos/DDoSProtectionSwitcher.java b/Plugins/Mineplex.DDoSProtectionSwitcher/src/mineplex/ddos/DDoSProtectionSwitcher.java index ed9cf05be..a1778b1ad 100644 --- a/Plugins/Mineplex.DDoSProtectionSwitcher/src/mineplex/ddos/DDoSProtectionSwitcher.java +++ b/Plugins/Mineplex.DDoSProtectionSwitcher/src/mineplex/ddos/DDoSProtectionSwitcher.java @@ -1,103 +1,130 @@ package mineplex.ddos; import java.util.ArrayList; -import java.util.HashMap; import java.util.List; +import mineplex.ddos.api.ApiDeleteCall; import mineplex.ddos.api.ApiGetCall; import mineplex.ddos.api.ApiPostCall; import mineplex.ddos.api.ApiPutCall; -import mineplex.ddos.api.token.ARecord; -import mineplex.ddos.api.token.CNameRecord; import mineplex.ddos.api.token.DnsRecord; import mineplex.ddos.api.token.DomainRecords; public class DDoSProtectionSwitcher { + private static DnsMadeEasyRepository _repository = null; + public static void main(String args[]) { - - List records = new ArrayList(); + try + { + Class.forName("com.mysql.jdbc.Driver"); + } + catch (ClassNotFoundException e1) + { + e1.printStackTrace(); + } - /* - records.add(new ARecord("us", "108.178.20.166", 300)); - records.add(new ARecord("us", "108.163.217.110", 300)); - records.add(new ARecord("us", "108.178.34.142", 300)); - records.add(new ARecord("us", "108.163.254.134", 300)); - records.add(new ARecord("us", "108.163.216.250", 300)); - records.add(new ARecord("us", "108.163.216.106", 300)); - records.add(new ARecord("us", "184.154.215.170", 300)); - records.add(new ARecord("us", "96.127.174.206", 300)); - records.add(new ARecord("us", "184.154.127.10", 300)); - records.add(new ARecord("us", "96.127.174.146", 300)); - records.add(new ARecord("us", "108.178.7.206", 300)); - records.add(new ARecord("us", "184.154.39.146", 300)); - records.add(new ARecord("us", "108.163.217.250", 300)); - records.add(new ARecord("us", "69.175.15.242", 300)); - records.add(new ARecord("us", "107.6.129.126", 300)); - records.add(new ARecord("us", "108.163.222.174", 300)); - records.add(new ARecord("us", "108.178.34.118", 300)); - records.add(new ARecord("us", "69.175.4.38", 300)); - records.add(new ARecord("us", "107.6.158.78", 300)); - records.add(new ARecord("us", "184.154.13.118", 300)); - */ + _repository = new DnsMadeEasyRepository(); - records.add(new ARecord("eu", "107.6.176.194", 300)); - records.add(new ARecord("eu", "107.6.176.122", 300)); - records.add(new ARecord("eu", "107.6.176.166", 300)); - records.add(new ARecord("eu", "107.6.176.14", 300)); - records.add(new ARecord("eu", "107.6.176.114", 300)); - records.add(new ARecord("eu", "107.6.176.26", 300)); - records.add(new ARecord("eu", "107.6.176.110", 300)); - records.add(new ARecord("eu", "107.6.176.138", 300)); + while (true) + { + if (_repository.switchToDDOSProt()) + { + DomainRecords records = new ApiGetCall("https://api.dnsmadeeasy.com/V2.0/dns/managed/", 962728, "/records", "").Execute(DomainRecords.class); + List recordsToDelete = new ArrayList(); + List recordsToAdd = new ArrayList(); + List recordsToModify = new ArrayList(); + + // Switch on ddos protection + for (DnsRecord record : records.data) + { + if (record.type.equalsIgnoreCase("A")) + { + if (record.name.equalsIgnoreCase("neustar")) + { + record.name = "us"; + recordsToModify.add(record); + } + else if (record.name.equalsIgnoreCase("us")) + { + record.name = "us2"; + recordsToModify.add(record); + } + else if (record.name.equalsIgnoreCase("eu")) + { + record.name = "eu2"; + recordsToModify.add(record); + } + } + } + + if (recordsToAdd.size() > 0) + new ApiPostCall("https://api.dnsmadeeasy.com/V2.0/dns/managed/", 962728, "/records/", "createMulti").Execute(records); - new ApiPostCall("https://api.dnsmadeeasy.com/V2.0/dns/managed/", 962728, "/records/", "createMulti") - .Execute(records); - /* - * - * DomainRecords records = new - * ApiGetCall("https://api.dnsmadeeasy.com/V2.0/dns/managed/", 962728, - * "/records", "").Execute(DomainRecords.class); List - * recordsToDelete = new ArrayList(); List - * recordsToAdd = new ArrayList(); List - * recordsToModify = new ArrayList(); - * - * // Switch off ddos protection for (DnsRecord record : records.data) { - * if (record.type.equalsIgnoreCase("CNAME")) { if - * (record.name.equalsIgnoreCase("eu")) recordsToDelete.add(record); } - * else if (record.type.equalsIgnoreCase("A")) { if - * (record.name.equalsIgnoreCase("us")) { record.name = "neustar"; - * recordsToModify.add(record); } else if - * (record.name.equalsIgnoreCase("us2")) { record.name = "us"; - * recordsToModify.add(record); } else if - * (record.name.equalsIgnoreCase("eu2")) { record.name = "eu"; - * recordsToModify.add(record); } } } - * - * /* // Switch on ddos protection for (DnsRecord record : records.data) - * { if (record.type.equalsIgnoreCase("A")) { if - * (record.name.equalsIgnoreCase("neustar")) { record.name = "us"; - * recordsToModify.put(record.id, record); } else if - * (record.name.equalsIgnoreCase("us")) { record.name = "us2"; - * recordsToModify.put(record.id, record); } else if - * (record.name.equalsIgnoreCase("eu")) { record.name = "eu2"; - * recordsToModify.put(record.id, record); } } } - * - * recordsToAdd.add(new CNameRecord("eu", "us", 300)); - * - * - * if (recordsToAdd.size() > 0) new - * ApiPostCall("https://api.dnsmadeeasy.com/V2.0/dns/managed/", 962728, - * "/records/", "createMulti").Execute(records); - * - * if (recordsToModify.size() > 0) { new - * ApiPutCall("https://api.dnsmadeeasy.com/V2.0/dns/managed/", 962728, - * "/records/", "updateMulti").Execute(recordsToModify); } - * - * if (recordsToDelete.size() > 0) new - * ApiPostCall("https://api.dnsmadeeasy.com/V2.0/dns/managed/", 962728, - * "/records/", "createMulti").Execute(records); - * - * System.exit(0); - */ + if (recordsToModify.size() > 0) + { + new ApiPutCall("https://api.dnsmadeeasy.com/V2.0/dns/managed/", 962728, "/records/", "updateMulti").Execute(recordsToModify); + } + + if (recordsToDelete.size() > 0) + { + StringBuilder idBuilder = new StringBuilder(); + + for (DnsRecord record : recordsToDelete) + { + if (idBuilder.length() != 0) + idBuilder.append("&"); + + idBuilder.append("ids=" + record.id); + } + + new ApiDeleteCall("https://api.dnsmadeeasy.com/V2.0/dns/managed/", 962728, "/records?" + idBuilder.toString()).Execute(); + } + } + + try + { + System.out.println("Natural Sleep"); + Thread.sleep(60000); + } + catch (InterruptedException e) + { + e.printStackTrace(); + } + } +/* + // Switch off ddos protection + for (DnsRecord record : records.data) + { + if (record.type.equalsIgnoreCase("CNAME")) + { + if (record.name.equalsIgnoreCase("eu")) + recordsToDelete.add(record); + } + else if (record.type.equalsIgnoreCase("A")) + { + if (record.name.equalsIgnoreCase("us")) + { + record.name = "neustar"; + recordsToModify.add(record); + } + else if (record.name.equalsIgnoreCase("us2")) + { + record.name = "us"; + recordsToModify.add(record); + } + else if (record.name.equalsIgnoreCase("eu2")) + { + record.name = "eu"; + recordsToModify.add(record); + } + } + } + + + + recordsToAdd.add(new CNameRecord("eu", "us", 300)); +*/ } } diff --git a/Plugins/Mineplex.DDoSProtectionSwitcher/src/mineplex/ddos/DnsMadeEasyRepository.java b/Plugins/Mineplex.DDoSProtectionSwitcher/src/mineplex/ddos/DnsMadeEasyRepository.java index 6f190aa2e..1b4d15573 100644 --- a/Plugins/Mineplex.DDoSProtectionSwitcher/src/mineplex/ddos/DnsMadeEasyRepository.java +++ b/Plugins/Mineplex.DDoSProtectionSwitcher/src/mineplex/ddos/DnsMadeEasyRepository.java @@ -1,9 +1,127 @@ package mineplex.ddos; +import java.sql.Connection; +import java.sql.DriverManager; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.text.SimpleDateFormat; + public class DnsMadeEasyRepository { - public DnsMadeEasyRepository() + private String _connectionString = "jdbc:mysql://db.mineplex.com:3306/BungeeServers?autoReconnect=true&failOverReadOnly=false&maxReconnects=10"; + private String _userName = "root"; + private String _password = "tAbechAk3wR7tuTh"; + + private static String CREATE_TABLE = "CREATE TABLE IF NOT EXISTS bungeeOnlineStatus (id INT NOT NULL AUTO_INCREMENT, address VARCHAR(40), online BOOLEAN NOT NULL DEFAULT 0, updated LONG, us BOOLEAN NOT NULL DEFAULT 1, lastOnline LONG, PRIMARY KEY (id), UNIQUE INDEX addressIndex(address));"; + private static String SELECT_SERVERS = "SELECT updated, lastOnline, us, now() FROM bungeeOnlineStatus;"; + + public void initialize() { + Connection connection = null; + PreparedStatement preparedStatement = null; + try + { + connection = DriverManager.getConnection(_connectionString, _userName, _password); + + // Create table + preparedStatement = connection.prepareStatement(CREATE_TABLE); + preparedStatement.execute(); + } + catch (Exception exception) + { + exception.printStackTrace(); + } + finally + { + if (preparedStatement != null) + { + try + { + preparedStatement.close(); + } + catch (SQLException e) + { + e.printStackTrace(); + } + } + + if (connection != null) + { + try + { + connection.close(); + } + catch (SQLException e) + { + e.printStackTrace(); + } + } + } + } + + public boolean switchToDDOSProt() + { + Connection connection = null; + PreparedStatement preparedStatement = null; + ResultSet resultSet = null; + + SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + int countOffline = 0; + + try + { + connection = DriverManager.getConnection(_connectionString, _userName, _password); + + preparedStatement = connection.prepareStatement(SELECT_SERVERS); + + resultSet = preparedStatement.executeQuery(); + + while (resultSet.next()) + { + long current = dateFormat.parse(resultSet.getString(4)).getTime(); + long updated = dateFormat.parse(resultSet.getString(1)).getTime(); + long lastOnline = dateFormat.parse(resultSet.getString(2)).getTime(); + + if (current - updated < 70000 && current - lastOnline > 660000) + countOffline++; + } + } + catch (Exception exception) + { + exception.printStackTrace(); + } + finally + { + if (preparedStatement != null) + { + try + { + preparedStatement.close(); + } + catch (SQLException e) + { + e.printStackTrace(); + } + } + + if (connection != null) + { + try + { + connection.close(); + } + catch (SQLException e) + { + e.printStackTrace(); + } + } + } + + System.out.println("Offline count : " + countOffline); + + return false; + //countOffline >= 20; } } diff --git a/Plugins/Mineplex.DDoSProtectionSwitcher/src/mineplex/ddos/api/ApiDeleteCall.java b/Plugins/Mineplex.DDoSProtectionSwitcher/src/mineplex/ddos/api/ApiDeleteCall.java new file mode 100644 index 000000000..5e91aab89 --- /dev/null +++ b/Plugins/Mineplex.DDoSProtectionSwitcher/src/mineplex/ddos/api/ApiDeleteCall.java @@ -0,0 +1,19 @@ +package mineplex.ddos.api; + +import org.apache.http.client.methods.HttpDelete; + +public class ApiDeleteCall extends DnsMadeEasyApiCallBase +{ + public ApiDeleteCall(String apiUrl, int domainId, String category) + { + super(apiUrl, domainId, category); + } + + public void Execute() + { + HttpDelete request = new HttpDelete(ApiUrl + DomainId + Category); + System.out.println(request.getURI().toString()); + + System.out.println(execute(request)); + } +} diff --git a/Plugins/Mineplex.Hub/src/mineplex/hub/HubManager.java b/Plugins/Mineplex.Hub/src/mineplex/hub/HubManager.java index 1fce65064..ae8c909c4 100644 --- a/Plugins/Mineplex.Hub/src/mineplex/hub/HubManager.java +++ b/Plugins/Mineplex.Hub/src/mineplex/hub/HubManager.java @@ -6,6 +6,7 @@ import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.GameMode; import org.bukkit.Location; +import org.bukkit.Material; import org.bukkit.Sound; import org.bukkit.craftbukkit.v1_7_R3.CraftWorld; import org.bukkit.entity.Egg; @@ -26,6 +27,8 @@ import org.bukkit.event.player.PlayerQuitEvent; import org.bukkit.event.player.PlayerRespawnEvent; import org.bukkit.event.server.ServerListPingEvent; import org.bukkit.event.world.ChunkLoadEvent; +import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.meta.BookMeta; import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.scoreboard.DisplaySlot; import org.bukkit.scoreboard.Objective; @@ -53,6 +56,7 @@ import mineplex.core.disguise.DisguiseManager; import mineplex.core.disguise.disguises.DisguisePlayer; import mineplex.core.disguise.disguises.DisguiseSlime; import mineplex.core.donation.DonationManager; +import mineplex.core.itemstack.ItemStackFactory; import mineplex.core.logger.Logger; import mineplex.core.portal.Portal; import mineplex.core.preferences.PreferencesManager; @@ -101,6 +105,8 @@ public class HubManager extends MiniClientPlugin private HashMap _scoreboards = new HashMap(); private String _pigStacker = "0 - Nobody"; + + private ItemStack _ruleBook = null; private boolean _shuttingDown; @@ -146,6 +152,136 @@ public class HubManager extends MiniClientPlugin _statsManager = new StatsManager(plugin); ((CraftWorld)Bukkit.getWorlds().get(0)).getHandle().pvpMode = true; + + _ruleBook = ItemStackFactory.Instance.CreateStack(Material.WRITTEN_BOOK, (byte)0, 1, "Rule Book", new String[] { }); + BookMeta meta = (BookMeta)_ruleBook.getItemMeta(); + + meta.addPage("§m-------------------§r\n" + + "Welcome to §6§lMineplex§r\n" + + "§r§0§l§r§m§0§m-------------------§r§0\n" + + "\n" + + "§2Please §0take a moment to read through this book!\n" + + "\n" + + "\n" + + "Part 1 - Rules\n" + + "\n" + + "Part 2 - FAQ\n"); + + meta.addPage("§m-------------------\n" + + "§r §2§lRules§r§0\n" + + "§m-------------------\n" + + "§r\n" + + "§l1.§§§r §4No§r spamming.\n" + + "\n" + + "§0This is sending too many messages and/or repeating the same message in a short period of time.\n"); + + meta.addPage("§m-------------------\n" + + "§r §2§lRules§r§0\n" + + "§m-------------------\n" + + "§r\n" + + "§l2.§m§r §4No§0 use of excessive caps.\n" + + "\n" + + "This is sending messages with an excessive amount of capital letters.\n"); + + meta.addPage("§m-------------------\n" + + "§r §2§lRules§r§0\n" + + "§m-------------------\n" + + "§r\n" + + "§l3.§r §4No§0 hacking or use of any unapproved mods.\n" + + "\n" + + "This means we do not tolerate any sort of hacked client or any unapproved mods, such as fly hacks.\n"); + + meta.addPage("§m-------------------\n" + + "§r §2§lRules§r§0\n" + + "§m-------------------\n" + + "§r\n" + + "§l4.§r §4No§0 advertising non-Mineplex related links.\n" + + "\n" + + "This is when a link is sent in chat which directs others to non-Mineplex related content.\n"); + + meta.addPage("§m-------------------\n" + + "§r §2§lRules§r§0\n" + + "§m-------------------\n" + + "§r\n" + + "§l5.§r §4No§0 trolling or use of any exploits.\n" + + "\n" + + "This means that abuse of bugs/glitches is not tolerated. You also may not do things such as teamkilling and/or blocking spawns.\n"); + + meta.addPage("§m-------------------\n" + + "§r §2§lRules§r§0\n" + + "§m-------------------\n" + + "§r\n" + + "§l6.§r §2Be§0 respectful to others, yourself, and the environment around you.\n"); + + meta.addPage("§m-------------------\n" + + "§r §2§lRules§r§0\n" + + "§m-------------------\n" + + "§r\n" + + "§rPlease report any bugs, exploits, and/or rule breakers on our forums with evidence.\n" + + "§omineplex.com/forums\n"); + + meta.addPage("§m-------------------\n" + + "§r §2§lFAQ§r§0\n" + + "§m-------------------\n" + + "§r\n" + + "§lWhat is stacker and how do you play it?\n" + + "\n" + + "§rStacker is a hub game where you can stack & throw players/mobs.\n" + + "\n" + + "§9Right-Click: pick up\n" + + "Left-Click: throw\n"); + + meta.addPage("§m-------------------\n" + + "§r §2§lFAQ§r§0\n" + + "§m-------------------\n" + + "§r\n" + + "§lHow do I get §b§lUltra§0 §lor §5§lHero§0§l?\n" + + "\n" + + "§r§0You are able to purchase these ranks through our shop on our website at:\n" + + "\n" + + "§owww.mineplex.com/shop\n"); + + meta.addPage("§m-------------------\n" + + "§r §2§lFAQ§r§0\n" + + "§m-------------------\n" + + "§r\n" + + "§lWhy hasn't my rank been applied yet?\n" + + "\n" + + "§m§rYour rank may take a while to be applied. If it has been over 24 hours please email:\n" + + "\n" + + "§osupport@mineplex.com\n"); + + meta.addPage("§m-------------------\n" + + "§r §2§lFAQ§r§0\n" + + "§m-------------------\n" + + "§r\n" + + "§lWhat do I do if I was wrongfully punished?\n" + + "\n" + + "§0If you believe you were wrongfully punished, please submit an appeal at:\n" + + "\n" + + "§omineplex.com/forums\n"); + + meta.addPage("§m-------------------\n" + + "§r §2§lFAQ§r§0\n" + + "§m-------------------\n" + + "§r\n" + + "§lHow do I apply for Helper?\n" + + "\n" + + "§rYou may only apply for Helper if you have §bUltra §0or §5Hero§0.\n" + + "Apply at:\n" + + "§omineplex.com/application\n"); + + meta.addPage("§m-------------------\n" + + "§r §6§lThank you for \n" + + " reading!§r§0\n" + + "§m-------------------\n" + + "§r\n" + + "Remember to visit our website §2mineplex.com§0 for important news & updates!\n" + + "\n" + + "\n" + + " §c§lH§6§lA§a§lV§9§lE §c§lF§6§lU§a§lN§9§l!\n"); + + _ruleBook.setItemMeta(meta); } @Override @@ -288,6 +424,8 @@ public class HubManager extends MiniClientPlugin UtilInv.Clear(player); + player.getInventory().setItem(6, _ruleBook); + //Scoreboard Scoreboard board = Bukkit.getScoreboardManager().getNewScoreboard(); player.setScoreboard(board); From 03c56535efc5acd9a6a575d9130094cf4c8e693a Mon Sep 17 00:00:00 2001 From: Mini-Chiss Date: Tue, 8 Jul 2014 18:08:37 -0700 Subject: [PATCH 7/7] MAPDATA --- .../src/mineplex/mapparser/MapData.java | 137 ++++++++++++++++++ .../src/mineplex/mapparser/MapParser.java | 14 +- 2 files changed, 150 insertions(+), 1 deletion(-) create mode 100644 Plugins/Mineplex.MapParser/src/mineplex/mapparser/MapData.java diff --git a/Plugins/Mineplex.MapParser/src/mineplex/mapparser/MapData.java b/Plugins/Mineplex.MapParser/src/mineplex/mapparser/MapData.java new file mode 100644 index 000000000..5adea1189 --- /dev/null +++ b/Plugins/Mineplex.MapParser/src/mineplex/mapparser/MapData.java @@ -0,0 +1,137 @@ +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; + + public String GameType = "null"; + public String MapName = "null"; + public String MapCreator = "null"; + + public HashSet WhiteList; + public HashSet BuildList; + + public MapData(String mapFolder) + { + MapFolder = mapFolder; + + WhiteList = new HashSet(); + BuildList = new HashSet(); + + 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")) + { + GameType = tokens[1]; + } + else if (tokens[0].equalsIgnoreCase("WHITE_LIST")) + { + for (String cur : tokens[1].split(",")) + WhiteList.add(cur); + } + else if (tokens[0].equalsIgnoreCase("BUILD_LIST")) + { + for (String cur : tokens[1].split(",")) + BuildList.add(cur); + } + } + + 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"); + out.write("GAME_TYPE:"+GameType); + + String whiteList = ""; + for (String cur : WhiteList) + whiteList += cur + ","; + + out.write("\n"); + out.write("WHITE_LIST:"+whiteList); + + String buildList = ""; + for (String cur : BuildList) + buildList += cur + ","; + + out.write("\n"); + out.write("BUILD_LIST:"+buildList); + + out.close(); + } + catch (Exception e) + { + e.printStackTrace(); + } + } + + public boolean CanBuild(Player player) + { + return BuildList.contains(player.getName()) || player.isOp(); + } + + public boolean CanJoin(Player player) + { + return BuildList.contains(player.getName()) || WhiteList.contains(player.getName()) || player.isOp(); + } +} diff --git a/Plugins/Mineplex.MapParser/src/mineplex/mapparser/MapParser.java b/Plugins/Mineplex.MapParser/src/mineplex/mapparser/MapParser.java index 68f3b2d49..52ebf475f 100644 --- a/Plugins/Mineplex.MapParser/src/mineplex/mapparser/MapParser.java +++ b/Plugins/Mineplex.MapParser/src/mineplex/mapparser/MapParser.java @@ -92,6 +92,8 @@ public class MapParser extends JavaPlugin implements Listener UtilPlayer.message(player, F.value("/name ", "Set name for current map")); UtilPlayer.message(player, F.value("/author ", "Set author for current map")); UtilPlayer.message(player, F.value("/gametype