diff --git a/Plugins/Mineplex.MapParser/src/mineplex/mapparser/GameType.java b/Plugins/Mineplex.MapParser/src/mineplex/mapparser/GameType.java index a6a4c2880..c0deac097 100644 --- a/Plugins/Mineplex.MapParser/src/mineplex/mapparser/GameType.java +++ b/Plugins/Mineplex.MapParser/src/mineplex/mapparser/GameType.java @@ -38,6 +38,7 @@ public enum GameType Micro("Micro Battle"), MineStrike("MineStrike"), MineWare("MineWare"), + MinecraftLeague("MCL"), MilkCow("Milk the Cow"), MonsterLeague("MonsterLeague"), MonsterMaze("Monster Maze"), @@ -53,6 +54,7 @@ public enum GameType SmashDomination("Super Smash Mobs Domination", "Super Smash Mobs"), Snake("Snake"), SneakyAssassins("Sneaky Assassins"), + SpeedBuilders("SpeedBuilders"), SnowFight("Snow Fight"), Spleef("Super Spleef"), SpleefTeams("Super Spleef Teams"), diff --git a/Plugins/Mineplex.MapParser/src/mineplex/mapparser/GameTypeInfo.java b/Plugins/Mineplex.MapParser/src/mineplex/mapparser/GameTypeInfo.java new file mode 100644 index 000000000..7ff04194b --- /dev/null +++ b/Plugins/Mineplex.MapParser/src/mineplex/mapparser/GameTypeInfo.java @@ -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 _info; + + public GameTypeInfo(GameType gameType, List info) + { + _gameType = gameType; + _info = info; + } + + public void addInfo(String info) + { + _info.add(info); + } + + public void remove(int index) + { + _info.remove(index); + } + + public List 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; + } +} diff --git a/Plugins/Mineplex.MapParser/src/mineplex/mapparser/MapData.java b/Plugins/Mineplex.MapParser/src/mineplex/mapparser/MapData.java index 3248ac842..a87e4e8b9 100644 --- a/Plugins/Mineplex.MapParser/src/mineplex/mapparser/MapData.java +++ b/Plugins/Mineplex.MapParser/src/mineplex/mapparser/MapData.java @@ -1,5 +1,11 @@ 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.BufferedWriter; import java.io.DataInputStream; @@ -7,30 +13,39 @@ import java.io.File; import java.io.FileInputStream; import java.io.FileWriter; import java.io.InputStreamReader; -import java.util.HashSet; +import java.util.Collections; +import java.util.Map; +import java.util.Map.Entry; +import java.util.Set; -import org.bukkit.entity.Player; - -public class MapData +public class MapData { public String MapFolder; + public boolean _currentlyLive; + public boolean _locked; + public Map _warps; public GameType MapGameType = null; public String MapName = "null"; public String MapCreator = "null"; - public HashSet AdminList; - + public Set AdminList; + public MapData(String mapFolder) { MapFolder = mapFolder; - AdminList = new HashSet(); - + AdminList = Sets.newHashSet(); + _warps = Maps.newHashMap(); + _currentlyLive = false; + if ((new File(MapFolder + File.separator + "Map.dat")).exists()) + { Read(); - else + } else + { Write(); + } } public void Read() @@ -43,46 +58,74 @@ public class MapData DataInputStream in = new DataInputStream(fstream); BufferedReader br = new BufferedReader(new InputStreamReader(in)); - while ((line = br.readLine()) != null) + while ((line = br.readLine()) != null) { String[] tokens = line.split(":"); if (tokens.length < 2) + { continue; + } if (tokens[0].length() == 0) + { 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 if (tokens[0].equalsIgnoreCase("MAP_NAME")) { MapName = tokens[1]; + continue; } - else if (tokens[0].equalsIgnoreCase("MAP_AUTHOR")) + + if (tokens[0].equalsIgnoreCase("MAP_AUTHOR")) { MapCreator = tokens[1]; + continue; } - else if (tokens[0].equalsIgnoreCase("GAME_TYPE")) + + if (tokens[0].equalsIgnoreCase("GAME_TYPE")) { try { MapGameType = GameType.valueOf(tokens[1] == null ? "Unknown" : tokens[1]); - } - catch (Exception e) + } catch (Exception e) { 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(",")) - AdminList.add(cur); + Collections.addAll(AdminList, tokens[1].split(",")); } } in.close(); - } - catch (Exception e) + } catch (Exception e) { e.printStackTrace(); System.err.println("Line: " + line); @@ -97,39 +140,60 @@ public class MapData FileWriter fstream = new FileWriter(MapFolder + File.separator + "Map.dat"); BufferedWriter out = new BufferedWriter(fstream); - out.write("MAP_NAME:"+MapName); + out.write("MAP_NAME:" + MapName); out.write("\n"); - out.write("MAP_AUTHOR:"+MapCreator); + out.write("MAP_AUTHOR:" + MapCreator); out.write("\n"); - out.write("GAME_TYPE:"+MapGameType); - + out.write("GAME_TYPE:" + MapGameType); + String adminList = ""; + for (String cur : AdminList) + { adminList += cur + ","; - + } + 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(); - } - catch (Exception e) + } catch (Exception e) { e.printStackTrace(); } } - public boolean HasAccess(Player player) + public String warpsToString() + { + StringBuilder builder = new StringBuilder(); + int i = 0; + for (Entry 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) { return AdminList.contains(player.getName()) || player.isOp(); } - - 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) { - return true; + return !_locked || (player.isOp() || AdminList.contains(player.getName())); } } diff --git a/Plugins/Mineplex.MapParser/src/mineplex/mapparser/MapParser.java b/Plugins/Mineplex.MapParser/src/mineplex/mapparser/MapParser.java index 86a7e7b6c..0d4a5c937 100644 --- a/Plugins/Mineplex.MapParser/src/mineplex/mapparser/MapParser.java +++ b/Plugins/Mineplex.MapParser/src/mineplex/mapparser/MapParser.java @@ -1,222 +1,138 @@ 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 java.util.Iterator; -import java.util.LinkedList; -import java.util.List; - +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.Callback; import mineplex.core.common.util.F; -import mineplex.core.common.util.MapUtil; import mineplex.core.common.util.UtilBlock; -import mineplex.core.common.util.UtilEvent; -import mineplex.core.common.util.UtilEvent.ActionType; -import mineplex.core.common.util.UtilGear; import mineplex.core.common.util.UtilPlayer; import mineplex.core.common.util.UtilServer; -import mineplex.core.common.util.UtilTime; -import mineplex.core.common.util.UtilWorld; -import mineplex.mapparser.command.*; - -import org.bukkit.Bukkit; -import org.bukkit.ChatColor; -import org.bukkit.GameMode; +import mineplex.mapparser.command.AddLoreCommand; +import mineplex.mapparser.command.AddSplashTextCommand; +import mineplex.mapparser.command.AdminCommand; +import mineplex.mapparser.command.AuthorCommand; +import mineplex.mapparser.command.ClearLoreCommand; +import mineplex.mapparser.command.CopyCommand; +import mineplex.mapparser.command.CopySchematicsCommand; +import mineplex.mapparser.command.CreateCommand; +import mineplex.mapparser.command.CurrentlyLiveCommand; +import mineplex.mapparser.command.DeleteCommand; +import mineplex.mapparser.command.GameTypeCommand; +import mineplex.mapparser.command.HubCommand; +import mineplex.mapparser.command.InfoCommand; +import mineplex.mapparser.command.ItemNameCommand; +import mineplex.mapparser.command.ListCommand; +import mineplex.mapparser.command.LockCommand; +import mineplex.mapparser.command.MapCommand; +import mineplex.mapparser.command.NameCommand; +import mineplex.mapparser.command.ParseCommand200; +import mineplex.mapparser.command.ParseCommand400; +import mineplex.mapparser.command.ParseCommand600; +import mineplex.mapparser.command.PlayerHeadCommand; +import mineplex.mapparser.command.RefreshWorldEditCommand; +import mineplex.mapparser.command.RenameCommand; +import mineplex.mapparser.command.SaveCommand; +import mineplex.mapparser.command.SetSpawnCommand; +import mineplex.mapparser.command.SpawnCommand; +import mineplex.mapparser.command.WarpCommand; +import mineplex.mapparser.command.WorldsCommand; +import mineplex.mapparser.module.Module; +import mineplex.mapparser.module.modules.CommandModule; +import mineplex.mapparser.module.modules.EventModule; +import mineplex.mapparser.module.modules.MMMazeModule; +import mineplex.mapparser.module.modules.SignModule; +import mineplex.mapparser.module.modules.TreeToolModule; import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.World; import org.bukkit.block.Block; -import org.bukkit.entity.EntityType; -import org.bukkit.entity.LivingEntity; +import org.bukkit.configuration.file.FileConfiguration; +import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.entity.Player; -import org.bukkit.event.EventHandler; -import org.bukkit.event.EventPriority; -import org.bukkit.event.Listener; -import org.bukkit.event.block.Action; -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.block.SignChangeEvent; -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.plugin.Plugin; import org.bukkit.plugin.java.JavaPlugin; -import org.bukkit.util.Vector; -public class MapParser extends JavaPlugin implements Listener +import java.io.File; +import java.io.IOException; +import java.util.Iterator; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; +import java.util.Set; + +public class MapParser extends JavaPlugin { private WorldManager _worldManager; private Parse _curParse = null; - private HashMap _mapData = new HashMap(); - private HashSet _mapsBeingZipped = new HashSet(); - private List _commands = new ArrayList(); + private final Map, Module> _modules = Maps.newHashMap(); + private final Map _infoMap = Maps.newHashMap(); + private final Map _mapData = Maps.newHashMap(); + public final Set _mapsBeingZipped = Sets.newHashSet(); + private List _additionalText = Lists.newArrayList(); private Location _spawnLocation; - private HashMap _permissionMap = new HashMap(); @Override public void onEnable() { _worldManager = new WorldManager(this); - getServer().getPluginManager().registerEvents(this, this); - getServer().getWorlds().get(0).setSpawnLocation(0, 106, 0); _spawnLocation = new Location(getServer().getWorlds().get(0), 0, 106, 0); //Updates getServer().getScheduler().scheduleSyncRepeatingTask(this, new Ticker(this), 1, 1); - _commands.add(new AuthorCommand(this)); - _commands.add(new AdminCommand(this)); - _commands.add(new CopySchematicsCommand(this)); - _commands.add(new CreateCommand(this)); - _commands.add(new DeleteCommand(this)); - _commands.add(new GameTypeCommand(this)); - _commands.add(new HubCommand(this)); - _commands.add(new ListCommand(this)); - _commands.add(new MapCommand(this)); - _commands.add(new NameCommand(this)); - _commands.add(new ParseCommand200(this)); - _commands.add(new ParseCommand400(this)); - _commands.add(new ParseCommand600(this)); - _commands.add(new RenameCommand(this)); - _commands.add(new SaveCommand(this)); - _commands.add(new WorldsCommand(this)); - _commands.add(new CopyCommand(this)); - _commands.add(new SpawnCommand(this)); - _commands.add(new SetSpawnCommand(this)); - _commands.add(new ItemNameCommand(this)); - _commands.add(new AddLoreCommand(this)); - _commands.add(new ClearLoreCommand(this)); + CommandModule commandModule = new CommandModule(this); + new EventModule(this); + new MMMazeModule(this); + new SignModule(this); + new TreeToolModule(this); + + commandModule.add(new AuthorCommand(this)); + commandModule.add(new AdminCommand(this)); + commandModule.add(new CopySchematicsCommand(this)); + commandModule.add(new CreateCommand(this)); + commandModule.add(new DeleteCommand(this)); + commandModule.add(new GameTypeCommand(this)); + commandModule.add(new HubCommand(this)); + commandModule.add(new ListCommand(this)); + commandModule.add(new MapCommand(this)); + commandModule.add(new NameCommand(this)); + commandModule.add(new ParseCommand200(this)); + commandModule.add(new ParseCommand400(this)); + commandModule.add(new ParseCommand600(this)); + commandModule.add(new RenameCommand(this)); + commandModule.add(new SaveCommand(this)); + commandModule.add(new WorldsCommand(this)); + commandModule.add(new CopyCommand(this)); + commandModule.add(new SpawnCommand(this)); + commandModule.add(new SetSpawnCommand(this)); + commandModule.add(new ItemNameCommand(this)); + commandModule.add(new AddLoreCommand(this)); + commandModule.add(new ClearLoreCommand(this)); + commandModule.add(new InfoCommand(this)); + commandModule.add(new LockCommand(this)); + commandModule.add(new PlayerHeadCommand(this)); + commandModule.add(new RefreshWorldEditCommand(this)); + commandModule.add(new WarpCommand(this)); + commandModule.add(new CurrentlyLiveCommand(this)); + commandModule.add(new AddSplashTextCommand(this)); + loadInfo(); + addSplashText(); } @Override public void onDisable() { - - } - - @EventHandler - public void PlayerJoin(PlayerJoinEvent event) - { - Player player = event.getPlayer(); - - player.teleport(getSpawnLocation()); - - ResetInventory(event.getPlayer()); - - DisplayHelp(player); + _infoMap.values().forEach(this::saveInfo); + saveSplashText(); } - @EventHandler - public void permissionUpdate(TickEvent event) + public Parse getCurParse() { - for (Player player : UtilServer.getPlayers()) - { - permissionSet(player); - } - } - - public void permissionSet(Player player) - { - boolean hasPermission = GetData(player.getWorld().getName()).HasAccess(player); - - if (!_permissionMap.containsKey(player) || _permissionMap.get(player) != hasPermission) - { - for (Plugin plugin : Bukkit.getPluginManager().getPlugins()) - { - player.addAttachment(plugin, "worldedit.*", hasPermission); - player.addAttachment(plugin, "voxelsniper.sniper", hasPermission); - player.addAttachment(plugin, "voxelsniper.brush.*", hasPermission); - player.addAttachment(plugin, "coloredsigns.format", hasPermission); - } - - _permissionMap.put(player, hasPermission); - - UtilPlayer.message(player, "Plugin Permissions: " + F.tf(hasPermission)); - } - } - - - public void DisplayHelp(Player player) - { - UtilPlayer.message(player, F.main("Parser", "Listing Commands;")); - UtilPlayer.message(player, F.value("Parameters", "Parameters: = Required, [?] = Optional")); - UtilPlayer.message(player, F.value("/hub", "Return to hub world")); - 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 ", "Set gametype for current map")); - UtilPlayer.message(player, " "); - UtilPlayer.message(player, F.value("/admin ", "Toggle admin for player on map")); - UtilPlayer.message(player, " "); - UtilPlayer.message(player, F.value("/create [gametype]", "Creates a new map")); - UtilPlayer.message(player, F.value("/delete [gametype]", "Deletes an existing map")); - UtilPlayer.message(player, F.value("/copy ", "Copies an existing map")); - UtilPlayer.message(player, " "); - UtilPlayer.message(player, F.value("/list", "List maps")); - UtilPlayer.message(player, F.value("/map [gametype]", "Teleport to a map")); - UtilPlayer.message(player, " "); - UtilPlayer.message(player, C.cYellow + "Documentation: " + C.cGreen + "http://tinyurl.com/mpxmaps"); - - } - - @EventHandler - public void Command(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 (_curParse != 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); - } - - for (BaseCommand command : _commands) - { - for (String alias : command.getAliases()) - { - if (alias.equalsIgnoreCase(commandLabel)) - { - event.setCancelled(true); - - if (!command.execute(player, commandLabel, args)) - { - UtilPlayer.message(player, F.main("Parser", "Invalid Input.")); - UtilPlayer.message(player, F.elem(command.getUsage())); - } - - return; - } - } - } + return _curParse; } public void sendValidGameTypes(Player player) @@ -233,128 +149,105 @@ public class MapParser extends JavaPlugin implements Listener player.sendMessage(gameTypes); } - @EventHandler - public void ParseUpdate(TickEvent event) + public GameTypeInfo getInfo(GameType type) { - if (_curParse == null) - return; + return _infoMap.get(type); + } - if (_curParse.Update()) + private void addSplashText() + { + File file = new File(getDataFolder(), "join-text.yml"); + if(!file.exists()) { - Announce("Parse Completed!"); - - Announce("Cleaning and Creating ZIP..."); - try { - _worldManager.finalizeParsedWorld(_curParse.getWorld()); - } - catch (Exception e) + file.createNewFile(); + } catch (IOException e) { - Announce("Creating ZIP Failed! Please Try Again!"); e.printStackTrace(); } - - _curParse = null; } - } - - @EventHandler - public void DisableCreatures(EntitySpawnEvent event) - { - if (event.getEntityType() == EntityType.DROPPED_ITEM || event.getEntity() instanceof LivingEntity) - 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); - } - - @EventHandler - public void Updates(PlayerMoveEvent event) - { - for (World world : this.getServer().getWorlds()) + FileConfiguration config = YamlConfiguration.loadConfiguration(file); + List messages = config.getStringList("messages"); + if(messages == null) { - if (world.getName().toLowerCase().contains("halloween")) - world.setTime(16000); - else - world.setTime(8000); - world.setStorm(false); + messages = Lists.newArrayList(); } - - - if (event.getPlayer().getGameMode() != GameMode.CREATIVE) - event.getPlayer().setGameMode(GameMode.CREATIVE); + _additionalText = messages; } - @EventHandler - public void SaveUnloadWorlds(TickEvent event) + private void saveSplashText() { - for (final World world : getServer().getWorlds()) + File file = new File(getDataFolder(), "join-text.yml"); + if(!file.exists()) { - if (world.getName().equalsIgnoreCase("world")) - continue; - - if (world.getName().startsWith("parse_")) - continue; - - if (!world.getName().startsWith("map")) - continue; - - if (world.getPlayers().isEmpty()) + try { - Announce("Saving & Closing World: " + F.elem(world.getName())); - MapUtil.UnloadWorld(this, world, true); - - _mapsBeingZipped.add(world.getName()); - System.out.println("Starting backup of " + world); - BackupTask backupTask = new BackupTask(this, world.getName(), new Callback() - { - @Override - public void run(Boolean data) - { - System.out.println("Finished backup of " + world); - _mapsBeingZipped.remove(world.getName()); - } - }); + file.createNewFile(); + } catch (IOException e) + { + e.printStackTrace(); } } + FileConfiguration config = YamlConfiguration.loadConfiguration(file); + config.set("messages", _additionalText); + try + { + config.save(file); + } catch (IOException e) + { + e.printStackTrace(); + } } - public void Announce(String msg) + private void loadInfo() + { + File file = new File(getDataFolder(), "info.yml"); + if(!file.exists()) + { + try + { + file.createNewFile(); + } catch (IOException e) + { + e.printStackTrace(); + } + } + FileConfiguration config = YamlConfiguration.loadConfiguration(file); + + for(String s : config.getKeys(false)) + { + GameType gameType = GameType.valueOf(s); + List messages = config.getStringList(s); + _infoMap.put(gameType, new GameTypeInfo(gameType, messages)); + } + } + + private void saveInfo(GameTypeInfo info) + { + File file = new File(getDataFolder(), "info.yml"); + if(!file.exists()) + { + try + { + file.createNewFile(); + } catch (IOException e) + { + e.printStackTrace(); + } + } + FileConfiguration config = YamlConfiguration.loadConfiguration(file); + config.set(info.getGameType().name(), info.getInfo()); + try + { + config.save(file); + } catch (IOException e) + { + e.printStackTrace(); + } + } + + public void announce(String msg) { for (Player player : UtilServer.getPlayers()) { @@ -364,19 +257,17 @@ public class MapParser extends JavaPlugin implements Listener System.out.println("[Announce] " + msg); } - public boolean DoesMapExist(String mapName, GameType gameType) + public boolean doesMapExist(String mapName, GameType gameType) { - return DoesMapExist(getWorldString(mapName, gameType)); + return doesMapExist(getWorldString(mapName, gameType)); } - public boolean DoesMapExist(String worldName) + public boolean doesMapExist(String worldName) { File file = new File(worldName); - if (file.exists() && file.isDirectory()) - return true; + return file.exists() && file.isDirectory(); - return false; } public String getShortWorldName(String worldName) @@ -389,12 +280,7 @@ public class MapParser extends JavaPlugin implements Listener return worldName; } - public World GetMapWorld(String mapName, GameType gameType) - { - return GetMapWorld(getWorldString(mapName, gameType)); - } - - public World GetMapWorld(String worldName) + public World getMapWorld(String worldName) { for (World world : this.getServer().getWorlds()) { @@ -414,14 +300,14 @@ public class MapParser extends JavaPlugin implements Listener { name = name.toLowerCase(); - List maps = new LinkedList(); + List maps = new LinkedList<>(); boolean matchesExact = false; for (GameType type : GameType.values()) { File mapsFolder = new File("map" + File.separator + type.GetName()); - if (!mapsFolder.exists()) + if (!mapsFolder.exists() || mapsFolder.listFiles() == null) continue; for (File file : mapsFolder.listFiles()) @@ -456,7 +342,7 @@ public class MapParser extends JavaPlugin implements Listener return maps; } - public MapData GetData(String mapName) + public MapData getData(String mapName) { if (_mapData.containsKey(mapName)) return _mapData.get(mapName); @@ -473,17 +359,6 @@ public class MapParser extends JavaPlugin implements Listener return _spawnLocation; } - 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)); - // player.getInventory().addItem(new ItemStack(Material.WOOD_AXE)); - } - public WorldManager getWorldManager() { return _worldManager; @@ -494,346 +369,12 @@ public class MapParser extends JavaPlugin implements Listener _curParse = parse; } - @EventHandler - public void Chat(AsyncPlayerChatEvent event) - { - event.setCancelled(true); - - String world = C.cDGreen + C.Bold + getShortWorldName(event.getPlayer().getWorld().getName()); - - - - String name = C.cYellow + event.getPlayer().getName(); - if (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) - { - //Permission - if (!GetData(event.getPlayer().getWorld().getName()).HasAccess(event.getPlayer())) - { - event.setCancelled(true); - } - } - - @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 (!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); - } - } - - public HashSet getMapsBeingZipped() + public Set getMapsBeingZipped() { return _mapsBeingZipped; } - - @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())); - } - - @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) - { - UtilPlayer.message(player, F.main("Game", "You teleported to " + F.name(target.getName()) + ".")); - player.teleport(target); - } - } - - @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.")); - } - } - - private HashMap>> treeHistory = new HashMap>>(); - - @EventHandler(priority = EventPriority.HIGHEST) - public void treeRemover(PlayerInteractEvent event) - { - if (event.isCancelled()) - return; - - //Permission - if (!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; - } - - HashSet toRemove = searchLog(new HashSet(), event.getClickedBlock()); - - if (toRemove.isEmpty()) - { - player.sendMessage(C.cRed + C.Bold + "TreeTool: " + ChatColor.RESET + "Left-Click on Log"); - return; - } - - HashSet history = new HashSet(); - - for (Block block : toRemove) - { - history.add(new BlockData(block)); - - block.setType(Material.AIR); - } - - if (!treeHistory.containsKey(player)) - treeHistory.put(player, new ArrayList>()); - - treeHistory.get(player).add(0, history); - - player.sendMessage(C.cRed + C.Bold + "TreeTool: " + ChatColor.RESET + "Tree Removed"); - - while (treeHistory.get(player).size() > 10) - treeHistory.get(player).remove(10); - } - else if (UtilEvent.isAction(event, ActionType.R)) - { - if (!treeHistory.containsKey(player) || treeHistory.get(player).isEmpty()) - { - player.sendMessage(C.cGreen + C.Bold + "TreeTool: " + ChatColor.RESET + "No Tree History"); - return; - } - - HashSet datas = treeHistory.get(player).remove(0); - - for (BlockData data : datas) - data.restore(); - - player.sendMessage(C.cGreen + C.Bold + "TreeTool: " + ChatColor.RESET + "Tree Restored"); - } - } - - @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]; - - /*Iterator iter = blocks.iterator(); - while(iter.hasNext()) - { - Block b = iter.next(); - switch (b.getType()) { - case QUARTZ_BLOCK: - maze[x][y] = 1; - break; - - case GOLD_BLOCK: - maze[x][y] = 2; - break; - - case STONE: - maze[x][y] = 3; - break; - - default: - maze[x][y] = 0; - break; - } - x++; - if(x > 99) - { - y++; - x = 0; - } - if(y > 99) - { - System.out.println("y > 99"); - break; - } - }*/ - - 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; - } - } - - private HashSet searchLog(HashSet blocks, Block current) + public Set searchLog(Set blocks, Block current) { //Not Tree if (current.getType() != Material.LOG && current.getType() != Material.LEAVES) @@ -860,110 +401,23 @@ public class MapParser extends JavaPlugin implements Listener return blocks; } - long lastUse = 0; - @EventHandler(priority = EventPriority.LOWEST) - public void leaptest(PlayerInteractEvent event) + public Map, Module> getModules() { - - if (event.getPlayer().getItemInHand() == null) - return; - - if (event.getPlayer().getItemInHand().getType() != Material.FEATHER) - return; - - if (System.currentTimeMillis() - lastUse < 800) - { - Bukkit.broadcastMessage("Cooldown"); - return; - } - - - lastUse = System.currentTimeMillis(); - - Vector vel = event.getPlayer().getLocation().getDirection().multiply(1.2); - vel.add(new Vector(0,0.6,0)); - - event.getPlayer().setVelocity(vel); + return _modules; } - @EventHandler(priority = EventPriority.LOWEST) - public void signChangeLog(SignChangeEvent event) + public void setInfo(GameType gameType, GameTypeInfo info) { - if (GetData(event.getPlayer().getWorld().getName()).HasAccess(event.getPlayer())) - { - ArrayList 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 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 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 text, World world) + public List getAdditionalText() { - try - { - File file = new File(world.getName() + "/" + "sign_log.txt"); + return _additionalText; + } - 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 addAdditionalText(String s) + { + _additionalText.add(s); } } diff --git a/Plugins/Mineplex.MapParser/src/mineplex/mapparser/Parse.java b/Plugins/Mineplex.MapParser/src/mineplex/mapparser/Parse.java index 79d74e141..27184accb 100644 --- a/Plugins/Mineplex.MapParser/src/mineplex/mapparser/Parse.java +++ b/Plugins/Mineplex.MapParser/src/mineplex/mapparser/Parse.java @@ -1,16 +1,8 @@ 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.UtilTime; import mineplex.core.common.util.UtilWorld; - import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.World; @@ -19,6 +11,13 @@ import org.bukkit.block.BlockFace; import org.bukkit.block.Sign; 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 { //Parse Data @@ -59,14 +58,14 @@ public class Parse _size = size; for (String arg : args) - Host.Announce("Parse Arg: " + F.elem(arg)); + Host.announce("Parse Arg: " + F.elem(arg)); 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 for (String arg : _args) @@ -77,7 +76,7 @@ public class Parse } 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++; 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); @@ -144,7 +143,7 @@ public class Parse } catch (Exception e) { - Host.Announce("Invalid Sign Data: " + UtilWorld.locToStr(block.getLocation())); + Host.announce("Invalid Sign Data: " + UtilWorld.locToStr(block.getLocation())); } //Add @@ -176,21 +175,21 @@ public class Parse if (_cornerA == null) { _cornerA = wool.getLocation(); - Host.Announce("Corner A: " + UtilWorld.locToStrClean(_cornerA)); + Host.announce("Corner A: " + UtilWorld.locToStrClean(_cornerA)); } else if (_cornerB == null) { _cornerB = wool.getLocation(); - Host.Announce("Corner B: " + UtilWorld.locToStrClean(_cornerB)); + Host.announce("Corner B: " + UtilWorld.locToStrClean(_cornerB)); } else { - Host.Announce("More than 2 Corner Markers:"); - Host.Announce("Corner A: " + UtilWorld.locToStrClean(_cornerA)); - Host.Announce("Corner B: " + UtilWorld.locToStrClean(_cornerB)); - Host.Announce("Excess: " + UtilWorld.locToStrClean(wool.getLocation())); + Host.announce("More than 2 Corner Markers:"); + Host.announce("Corner A: " + UtilWorld.locToStrClean(_cornerA)); + Host.announce("Corner B: " + UtilWorld.locToStrClean(_cornerB)); + Host.announce("Excess: " + UtilWorld.locToStrClean(wool.getLocation())); } //Remove Blocks @@ -414,7 +413,7 @@ public class Parse 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); _cornerB = new Location(_world, 256, 0, 256); @@ -487,12 +486,12 @@ public class Parse } catch (Exception e) { - Host.Announce("Error: File Write Error"); + Host.announce("Error: File Write Error"); e.printStackTrace(); } - Host.Announce("WorldConfig.dat Saved."); + Host.announce("WorldConfig.dat Saved."); return true; } diff --git a/Plugins/Mineplex.MapParser/src/mineplex/mapparser/WorldManager.java b/Plugins/Mineplex.MapParser/src/mineplex/mapparser/WorldManager.java index 8658ae526..56e3b7218 100644 --- a/Plugins/Mineplex.MapParser/src/mineplex/mapparser/WorldManager.java +++ b/Plugins/Mineplex.MapParser/src/mineplex/mapparser/WorldManager.java @@ -1,18 +1,17 @@ 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.IOException; import java.nio.file.Paths; 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 { private MapParser Host; @@ -99,7 +98,7 @@ public class WorldManager 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; String fileName = gameType + "_" + data.MapName + ".zip"; diff --git a/Plugins/Mineplex.MapParser/src/mineplex/mapparser/command/AddSplashTextCommand.java b/Plugins/Mineplex.MapParser/src/mineplex/mapparser/command/AddSplashTextCommand.java new file mode 100644 index 000000000..652785f33 --- /dev/null +++ b/Plugins/Mineplex.MapParser/src/mineplex/mapparser/command/AddSplashTextCommand.java @@ -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 "); + } + + @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; + } +} diff --git a/Plugins/Mineplex.MapParser/src/mineplex/mapparser/command/AdminCommand.java b/Plugins/Mineplex.MapParser/src/mineplex/mapparser/command/AdminCommand.java index 40af0b55b..ad52b7f98 100644 --- a/Plugins/Mineplex.MapParser/src/mineplex/mapparser/command/AdminCommand.java +++ b/Plugins/Mineplex.MapParser/src/mineplex/mapparser/command/AdminCommand.java @@ -36,7 +36,7 @@ public class AdminCommand extends BaseCommand } //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."); return true; @@ -46,21 +46,21 @@ public class AdminCommand extends BaseCommand if (player != null) { - MapData data = getPlugin().GetData(world.getName()); + MapData data = getPlugin().getData(world.getName()); if (data.AdminList.contains(other.getName())) { data.AdminList.remove(other.getName()); 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 { data.AdminList.add(other.getName()); 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; diff --git a/Plugins/Mineplex.MapParser/src/mineplex/mapparser/command/AuthorCommand.java b/Plugins/Mineplex.MapParser/src/mineplex/mapparser/command/AuthorCommand.java index 3dabd87c9..c267e7d4d 100644 --- a/Plugins/Mineplex.MapParser/src/mineplex/mapparser/command/AuthorCommand.java +++ b/Plugins/Mineplex.MapParser/src/mineplex/mapparser/command/AuthorCommand.java @@ -4,7 +4,6 @@ import org.bukkit.World; import org.bukkit.entity.Player; import mineplex.core.common.util.F; -import mineplex.core.common.util.UtilPlayer; import mineplex.mapparser.MapData; import mineplex.mapparser.MapParser; @@ -41,18 +40,18 @@ public class AuthorCommand extends BaseCommand } //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."); return true; } - MapData data = getPlugin().GetData(world.getName()); + MapData data = getPlugin().getData(world.getName()); data.MapCreator = authorName; 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; } diff --git a/Plugins/Mineplex.MapParser/src/mineplex/mapparser/command/CopyCommand.java b/Plugins/Mineplex.MapParser/src/mineplex/mapparser/command/CopyCommand.java index 3448f8545..4354a90a1 100644 --- a/Plugins/Mineplex.MapParser/src/mineplex/mapparser/command/CopyCommand.java +++ b/Plugins/Mineplex.MapParser/src/mineplex/mapparser/command/CopyCommand.java @@ -50,19 +50,19 @@ public class CopyCommand extends BaseCommand String worldName = getPlugin().getWorldString(originalMapName, originalGametype); 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())); 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())); return true; } - World world = getPlugin().GetMapWorld(worldName); + World world = getPlugin().getMapWorld(worldName); if (world != null) { diff --git a/Plugins/Mineplex.MapParser/src/mineplex/mapparser/command/CreateCommand.java b/Plugins/Mineplex.MapParser/src/mineplex/mapparser/command/CreateCommand.java index 2f44c7558..28ff49418 100644 --- a/Plugins/Mineplex.MapParser/src/mineplex/mapparser/command/CreateCommand.java +++ b/Plugins/Mineplex.MapParser/src/mineplex/mapparser/command/CreateCommand.java @@ -1,18 +1,16 @@ 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.Location; import org.bukkit.World; import org.bukkit.WorldCreator; import org.bukkit.WorldType; 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. */ @@ -28,7 +26,7 @@ public class CreateCommand extends BaseCommand { if (args.length < 1) { - message(player, "Invalid Input. " + F.elem("/create ")); + message(player, "Invalid Input. " + F.elem("/create [-v]")); return true; } @@ -36,21 +34,38 @@ public class CreateCommand extends BaseCommand String worldName = "map/" + gameType.GetName() + "/" + args[0]; - if (getPlugin().DoesMapExist(worldName)) + if (getPlugin().doesMapExist(worldName)) { message(player, "Map name is already in use!"); 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.environment(World.Environment.NORMAL); 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); World world = Bukkit.getServer().createWorld(worldCreator); - + world.setSpawnLocation(0, 100, 0); message(player, "Teleporting to World: " + F.elem(worldName)); @@ -58,7 +73,7 @@ public class CreateCommand extends BaseCommand player.teleport(world.getSpawnLocation()); //Give Access - MapData mapData = getPlugin().GetData(worldName); + MapData mapData = getPlugin().getData(worldName); mapData.AdminList.add(player.getName()); mapData.MapGameType = gameType; mapData.Write(); diff --git a/Plugins/Mineplex.MapParser/src/mineplex/mapparser/command/CurrentlyLiveCommand.java b/Plugins/Mineplex.MapParser/src/mineplex/mapparser/command/CurrentlyLiveCommand.java new file mode 100644 index 000000000..7244346b9 --- /dev/null +++ b/Plugins/Mineplex.MapParser/src/mineplex/mapparser/command/CurrentlyLiveCommand.java @@ -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; + } +} diff --git a/Plugins/Mineplex.MapParser/src/mineplex/mapparser/command/DeleteCommand.java b/Plugins/Mineplex.MapParser/src/mineplex/mapparser/command/DeleteCommand.java index 4128c38e8..59b357c42 100644 --- a/Plugins/Mineplex.MapParser/src/mineplex/mapparser/command/DeleteCommand.java +++ b/Plugins/Mineplex.MapParser/src/mineplex/mapparser/command/DeleteCommand.java @@ -44,21 +44,21 @@ public class DeleteCommand extends BaseCommand final String worldName = getPlugin().getWorldString(mapName, gameType); - if (!getPlugin().DoesMapExist(worldName)) + if (!getPlugin().doesMapExist(worldName)) { message(player, "Map does not exist: " + F.elem(worldName)); 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."); return true; } - if (getPlugin().GetMapWorld(worldName) != null) + if (getPlugin().getMapWorld(worldName) != null) { - World world = getPlugin().GetMapWorld(worldName); + World world = getPlugin().getMapWorld(worldName); //Teleport Out for (Player other : world.getPlayers()) @@ -73,9 +73,9 @@ public class DeleteCommand extends BaseCommand boolean deleted = FileUtils.deleteQuietly(new File(worldName)); if (deleted) - getPlugin().Announce("Deleted World: " + F.elem(worldName)); + getPlugin().announce("Deleted World: " + F.elem(worldName)); else - getPlugin().Announce("Failed to delete World: " + F.elem(worldName)); + getPlugin().announce("Failed to delete World: " + F.elem(worldName)); return true; } diff --git a/Plugins/Mineplex.MapParser/src/mineplex/mapparser/command/GameTypeCommand.java b/Plugins/Mineplex.MapParser/src/mineplex/mapparser/command/GameTypeCommand.java index 098eed8c3..edf2482a9 100644 --- a/Plugins/Mineplex.MapParser/src/mineplex/mapparser/command/GameTypeCommand.java +++ b/Plugins/Mineplex.MapParser/src/mineplex/mapparser/command/GameTypeCommand.java @@ -2,13 +2,11 @@ package mineplex.mapparser.command; import java.io.File; -import org.bukkit.Location; import org.bukkit.World; import org.bukkit.entity.Player; import mineplex.core.common.util.F; import mineplex.core.common.util.MapUtil; -import mineplex.core.common.util.UtilPlayer; import mineplex.mapparser.GameType; import mineplex.mapparser.MapData; import mineplex.mapparser.MapParser; @@ -41,7 +39,7 @@ public class GameTypeCommand extends BaseCommand } //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."); return true; @@ -59,7 +57,7 @@ public class GameTypeCommand extends BaseCommand 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()); return true; @@ -85,11 +83,11 @@ public class GameTypeCommand extends BaseCommand message(player, "Map " + world.getName() + " renamed to " + newName); - MapData data = getPlugin().GetData(newName); + MapData data = getPlugin().getData(newName); data.MapGameType = type; 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; } diff --git a/Plugins/Mineplex.MapParser/src/mineplex/mapparser/command/InfoCommand.java b/Plugins/Mineplex.MapParser/src/mineplex/mapparser/command/InfoCommand.java new file mode 100644 index 000000000..f5fa36ac1 --- /dev/null +++ b/Plugins/Mineplex.MapParser/src/mineplex/mapparser/command/InfoCommand.java @@ -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 & /info addInfo "); + } + + @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; + } +} diff --git a/Plugins/Mineplex.MapParser/src/mineplex/mapparser/command/LockCommand.java b/Plugins/Mineplex.MapParser/src/mineplex/mapparser/command/LockCommand.java new file mode 100644 index 000000000..a8dd0082d --- /dev/null +++ b/Plugins/Mineplex.MapParser/src/mineplex/mapparser/command/LockCommand.java @@ -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; + } +} diff --git a/Plugins/Mineplex.MapParser/src/mineplex/mapparser/command/MapCommand.java b/Plugins/Mineplex.MapParser/src/mineplex/mapparser/command/MapCommand.java index a229e5e07..6c504b634 100644 --- a/Plugins/Mineplex.MapParser/src/mineplex/mapparser/command/MapCommand.java +++ b/Plugins/Mineplex.MapParser/src/mineplex/mapparser/command/MapCommand.java @@ -1,19 +1,18 @@ 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.UtilPlayer; import mineplex.mapparser.GameType; import mineplex.mapparser.MapData; 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. @@ -45,8 +44,9 @@ public class MapCommand extends BaseCommand if (possibleMaps.size() == 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:"); for (String s : possibleMaps) @@ -91,10 +91,10 @@ public class MapCommand extends BaseCommand System.out.println("Could not delete uid.dat for " + worldName); } - World world = getPlugin().GetMapWorld(worldName); + World world = getPlugin().getMapWorld(worldName); if (world == null) { - if (getPlugin().DoesMapExist(worldName)) + if (getPlugin().doesMapExist(worldName)) { world = Bukkit.createWorld(new WorldCreator(worldName)); } @@ -113,7 +113,7 @@ public class MapCommand extends BaseCommand } //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."); return true; @@ -124,7 +124,7 @@ public class MapCommand extends BaseCommand 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("Author", data.MapCreator)); diff --git a/Plugins/Mineplex.MapParser/src/mineplex/mapparser/command/NameCommand.java b/Plugins/Mineplex.MapParser/src/mineplex/mapparser/command/NameCommand.java index 580c088da..a7988c3ff 100644 --- a/Plugins/Mineplex.MapParser/src/mineplex/mapparser/command/NameCommand.java +++ b/Plugins/Mineplex.MapParser/src/mineplex/mapparser/command/NameCommand.java @@ -4,7 +4,6 @@ import org.bukkit.World; import org.bukkit.entity.Player; import mineplex.core.common.util.F; -import mineplex.core.common.util.UtilPlayer; import mineplex.mapparser.MapData; import mineplex.mapparser.MapParser; @@ -43,18 +42,18 @@ public class NameCommand extends BaseCommand mapName = mapName.trim(); //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."); return true; } - MapData data = getPlugin().GetData(world.getName()); + MapData data = getPlugin().getData(world.getName()); data.MapName = mapName; 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; } diff --git a/Plugins/Mineplex.MapParser/src/mineplex/mapparser/command/ParseCommand200.java b/Plugins/Mineplex.MapParser/src/mineplex/mapparser/command/ParseCommand200.java index 91b88a840..9cd58144b 100644 --- a/Plugins/Mineplex.MapParser/src/mineplex/mapparser/command/ParseCommand200.java +++ b/Plugins/Mineplex.MapParser/src/mineplex/mapparser/command/ParseCommand200.java @@ -32,7 +32,7 @@ public class ParseCommand200 extends BaseCommand 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")) { @@ -57,7 +57,7 @@ public class ParseCommand200 extends BaseCommand } //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; } diff --git a/Plugins/Mineplex.MapParser/src/mineplex/mapparser/command/ParseCommand400.java b/Plugins/Mineplex.MapParser/src/mineplex/mapparser/command/ParseCommand400.java index 02f0a0493..d08d60103 100644 --- a/Plugins/Mineplex.MapParser/src/mineplex/mapparser/command/ParseCommand400.java +++ b/Plugins/Mineplex.MapParser/src/mineplex/mapparser/command/ParseCommand400.java @@ -32,7 +32,7 @@ public class ParseCommand400 extends BaseCommand 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")) { @@ -57,7 +57,7 @@ public class ParseCommand400 extends BaseCommand } //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; } diff --git a/Plugins/Mineplex.MapParser/src/mineplex/mapparser/command/ParseCommand600.java b/Plugins/Mineplex.MapParser/src/mineplex/mapparser/command/ParseCommand600.java index 9271553ef..daa28b4fa 100644 --- a/Plugins/Mineplex.MapParser/src/mineplex/mapparser/command/ParseCommand600.java +++ b/Plugins/Mineplex.MapParser/src/mineplex/mapparser/command/ParseCommand600.java @@ -32,7 +32,7 @@ public class ParseCommand600 extends BaseCommand 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")) { @@ -57,7 +57,7 @@ public class ParseCommand600 extends BaseCommand } //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; } diff --git a/Plugins/Mineplex.MapParser/src/mineplex/mapparser/command/PlayerHeadCommand.java b/Plugins/Mineplex.MapParser/src/mineplex/mapparser/command/PlayerHeadCommand.java new file mode 100644 index 000000000..d0a7a485d --- /dev/null +++ b/Plugins/Mineplex.MapParser/src/mineplex/mapparser/command/PlayerHeadCommand.java @@ -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; + } +} diff --git a/Plugins/Mineplex.MapParser/src/mineplex/mapparser/command/RefreshWorldEditCommand.java b/Plugins/Mineplex.MapParser/src/mineplex/mapparser/command/RefreshWorldEditCommand.java new file mode 100644 index 000000000..8cfbf1c6e --- /dev/null +++ b/Plugins/Mineplex.MapParser/src/mineplex/mapparser/command/RefreshWorldEditCommand.java @@ -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; + } +} diff --git a/Plugins/Mineplex.MapParser/src/mineplex/mapparser/command/RenameCommand.java b/Plugins/Mineplex.MapParser/src/mineplex/mapparser/command/RenameCommand.java index ae95e8ec4..b2e539bb4 100644 --- a/Plugins/Mineplex.MapParser/src/mineplex/mapparser/command/RenameCommand.java +++ b/Plugins/Mineplex.MapParser/src/mineplex/mapparser/command/RenameCommand.java @@ -2,7 +2,6 @@ package mineplex.mapparser.command; import java.io.File; -import org.bukkit.Location; import org.bukkit.World; import org.bukkit.entity.Player; @@ -25,7 +24,7 @@ public class RenameCommand extends BaseCommand public boolean execute(Player player, String alias, String[] args) { World world = player.getWorld(); - MapData data = getPlugin().GetData(world.getName()); + MapData data = getPlugin().getData(world.getName()); if (data == null) { diff --git a/Plugins/Mineplex.MapParser/src/mineplex/mapparser/command/SaveCommand.java b/Plugins/Mineplex.MapParser/src/mineplex/mapparser/command/SaveCommand.java index 4f2658660..c201f152c 100644 --- a/Plugins/Mineplex.MapParser/src/mineplex/mapparser/command/SaveCommand.java +++ b/Plugins/Mineplex.MapParser/src/mineplex/mapparser/command/SaveCommand.java @@ -48,11 +48,11 @@ public class SaveCommand extends BaseCommand } String worldName = possibleMaps.get(0); - World world = getPlugin().GetMapWorld(worldName); + World world = getPlugin().getMapWorld(worldName); 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."); return true; @@ -71,7 +71,7 @@ public class SaveCommand extends BaseCommand return true; } - getPlugin().Announce("Saved World: " + F.elem(args[0])); + getPlugin().announce("Saved World: " + F.elem(args[0])); return true; } diff --git a/Plugins/Mineplex.MapParser/src/mineplex/mapparser/command/WarpCommand.java b/Plugins/Mineplex.MapParser/src/mineplex/mapparser/command/WarpCommand.java new file mode 100644 index 000000000..dd533e4d8 --- /dev/null +++ b/Plugins/Mineplex.MapParser/src/mineplex/mapparser/command/WarpCommand.java @@ -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 & /warp "); + } + + @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 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 ") + 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; + } + +} diff --git a/Plugins/Mineplex.MapParser/src/mineplex/mapparser/module/Module.java b/Plugins/Mineplex.MapParser/src/mineplex/mapparser/module/Module.java new file mode 100644 index 000000000..0862b4b3c --- /dev/null +++ b/Plugins/Mineplex.MapParser/src/mineplex/mapparser/module/Module.java @@ -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)); + } + } +} diff --git a/Plugins/Mineplex.MapParser/src/mineplex/mapparser/module/modules/CommandModule.java b/Plugins/Mineplex.MapParser/src/mineplex/mapparser/module/modules/CommandModule.java new file mode 100644 index 000000000..368b24df9 --- /dev/null +++ b/Plugins/Mineplex.MapParser/src/mineplex/mapparser/module/modules/CommandModule.java @@ -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 _commands = Maps.newHashMap(); + private Map _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); + } + } +} diff --git a/Plugins/Mineplex.MapParser/src/mineplex/mapparser/module/modules/EventModule.java b/Plugins/Mineplex.MapParser/src/mineplex/mapparser/module/modules/EventModule.java new file mode 100644 index 000000000..3b0a05afc --- /dev/null +++ b/Plugins/Mineplex.MapParser/src/mineplex/mapparser/module/modules/EventModule.java @@ -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 _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); + } +} diff --git a/Plugins/Mineplex.MapParser/src/mineplex/mapparser/module/modules/MMMazeModule.java b/Plugins/Mineplex.MapParser/src/mineplex/mapparser/module/modules/MMMazeModule.java new file mode 100644 index 000000000..0160c923b --- /dev/null +++ b/Plugins/Mineplex.MapParser/src/mineplex/mapparser/module/modules/MMMazeModule.java @@ -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; + } + } +} diff --git a/Plugins/Mineplex.MapParser/src/mineplex/mapparser/module/modules/SignModule.java b/Plugins/Mineplex.MapParser/src/mineplex/mapparser/module/modules/SignModule.java new file mode 100644 index 000000000..47e4d5aed --- /dev/null +++ b/Plugins/Mineplex.MapParser/src/mineplex/mapparser/module/modules/SignModule.java @@ -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 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 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 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 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(); + } + } +} diff --git a/Plugins/Mineplex.MapParser/src/mineplex/mapparser/module/modules/TreeToolModule.java b/Plugins/Mineplex.MapParser/src/mineplex/mapparser/module/modules/TreeToolModule.java new file mode 100644 index 000000000..8e6df1c01 --- /dev/null +++ b/Plugins/Mineplex.MapParser/src/mineplex/mapparser/module/modules/TreeToolModule.java @@ -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>> _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 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 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 datas = _treeHistory.get(player.getUniqueId()).remove(0); + + datas.forEach(BlockData::restore); + + player.sendMessage(C.cGreen + C.Bold + "TreeTool: " + ChatColor.RESET + "Tree Restored"); + } + } + +}