2014-06-15 02:12:08 +02:00
|
|
|
package mineplex.mapparser;
|
|
|
|
|
2015-09-12 18:50:06 +02:00
|
|
|
import java.io.BufferedWriter;
|
2014-06-15 02:12:08 +02:00
|
|
|
import java.io.File;
|
2015-09-12 18:50:06 +02:00
|
|
|
import java.io.FileWriter;
|
2014-08-16 22:50:33 +02:00
|
|
|
import java.util.ArrayList;
|
2014-07-09 00:13:30 +02:00
|
|
|
import java.util.HashMap;
|
2014-10-15 22:04:44 +02:00
|
|
|
import java.util.HashSet;
|
2014-08-16 22:50:33 +02:00
|
|
|
import java.util.Iterator;
|
|
|
|
import java.util.LinkedList;
|
|
|
|
import java.util.List;
|
2014-06-15 02:12:08 +02:00
|
|
|
|
2015-09-26 21:08:43 +02:00
|
|
|
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;
|
2015-10-11 16:52:45 +02:00
|
|
|
import mineplex.core.common.util.UtilTime;
|
|
|
|
import mineplex.core.common.util.UtilWorld;
|
2016-02-25 16:29:47 +01:00
|
|
|
import mineplex.mapparser.command.*;
|
2015-09-26 21:08:43 +02:00
|
|
|
|
2014-09-09 02:52:51 +02:00
|
|
|
import org.bukkit.Bukkit;
|
2014-07-09 02:33:22 +02:00
|
|
|
import org.bukkit.ChatColor;
|
2014-07-05 08:04:46 +02:00
|
|
|
import org.bukkit.GameMode;
|
2014-06-15 02:12:08 +02:00
|
|
|
import org.bukkit.Location;
|
2014-07-09 02:33:22 +02:00
|
|
|
import org.bukkit.Material;
|
2014-06-26 05:53:28 +02:00
|
|
|
import org.bukkit.World;
|
2014-11-14 04:14:31 +01:00
|
|
|
import org.bukkit.block.Block;
|
2014-07-05 08:04:46 +02:00
|
|
|
import org.bukkit.entity.EntityType;
|
|
|
|
import org.bukkit.entity.LivingEntity;
|
2014-06-15 02:12:08 +02:00
|
|
|
import org.bukkit.entity.Player;
|
|
|
|
import org.bukkit.event.EventHandler;
|
2014-10-17 12:20:04 +02:00
|
|
|
import org.bukkit.event.EventPriority;
|
2014-06-15 02:12:08 +02:00
|
|
|
import org.bukkit.event.Listener;
|
2014-11-14 04:14:31 +01:00
|
|
|
import org.bukkit.event.block.Action;
|
2014-08-15 07:28:50 +02:00
|
|
|
import org.bukkit.event.block.BlockBurnEvent;
|
|
|
|
import org.bukkit.event.block.BlockFadeEvent;
|
2015-07-02 02:09:39 +02:00
|
|
|
import org.bukkit.event.block.BlockFormEvent;
|
2015-08-07 21:45:38 +02:00
|
|
|
import org.bukkit.event.block.BlockIgniteEvent;
|
|
|
|
import org.bukkit.event.block.BlockIgniteEvent.IgniteCause;
|
2014-08-15 07:28:50 +02:00
|
|
|
import org.bukkit.event.block.BlockSpreadEvent;
|
|
|
|
import org.bukkit.event.block.LeavesDecayEvent;
|
2015-10-11 02:26:09 +02:00
|
|
|
import org.bukkit.event.block.SignChangeEvent;
|
2014-07-05 08:04:46 +02:00
|
|
|
import org.bukkit.event.entity.EntitySpawnEvent;
|
2014-07-09 02:33:22 +02:00
|
|
|
import org.bukkit.event.player.AsyncPlayerChatEvent;
|
2014-06-15 02:12:08 +02:00
|
|
|
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
|
2014-07-09 02:33:22 +02:00
|
|
|
import org.bukkit.event.player.PlayerInteractEvent;
|
2014-07-08 01:23:55 +02:00
|
|
|
import org.bukkit.event.player.PlayerJoinEvent;
|
2014-07-05 08:04:46 +02:00
|
|
|
import org.bukkit.event.player.PlayerMoveEvent;
|
2014-07-09 02:33:22 +02:00
|
|
|
import org.bukkit.event.player.PlayerQuitEvent;
|
2014-09-09 02:52:51 +02:00
|
|
|
import org.bukkit.plugin.Plugin;
|
2014-06-15 02:12:08 +02:00
|
|
|
import org.bukkit.plugin.java.JavaPlugin;
|
2015-08-09 00:09:26 +02:00
|
|
|
import org.bukkit.util.Vector;
|
2014-06-15 02:12:08 +02:00
|
|
|
|
|
|
|
public class MapParser extends JavaPlugin implements Listener
|
|
|
|
{
|
2014-06-26 05:53:28 +02:00
|
|
|
private WorldManager _worldManager;
|
2015-10-11 02:26:09 +02:00
|
|
|
|
2014-07-08 01:23:55 +02:00
|
|
|
private Parse _curParse = null;
|
2014-07-09 00:13:30 +02:00
|
|
|
private HashMap<String, MapData> _mapData = new HashMap<String, MapData>();
|
2014-10-15 22:04:44 +02:00
|
|
|
private HashSet<String> _mapsBeingZipped = new HashSet<String>();
|
2014-08-16 22:50:33 +02:00
|
|
|
private List<BaseCommand> _commands = new ArrayList<BaseCommand>();
|
2014-08-16 23:01:00 +02:00
|
|
|
private Location _spawnLocation;
|
2015-10-11 02:26:09 +02:00
|
|
|
|
2015-01-26 01:23:08 +01:00
|
|
|
private HashMap<Player, Boolean> _permissionMap = new HashMap<Player, Boolean>();
|
2015-10-11 02:26:09 +02:00
|
|
|
|
2014-06-15 02:12:08 +02:00
|
|
|
@Override
|
|
|
|
public void onEnable()
|
|
|
|
{
|
2014-06-26 05:53:28 +02:00
|
|
|
_worldManager = new WorldManager(this);
|
2015-10-11 02:26:09 +02:00
|
|
|
|
2014-06-26 05:53:28 +02:00
|
|
|
getServer().getPluginManager().registerEvents(this, this);
|
2015-10-11 02:26:09 +02:00
|
|
|
|
2014-07-08 01:23:55 +02:00
|
|
|
getServer().getWorlds().get(0).setSpawnLocation(0, 106, 0);
|
2014-08-16 23:01:00 +02:00
|
|
|
_spawnLocation = new Location(getServer().getWorlds().get(0), 0, 106, 0);
|
2015-10-11 02:26:09 +02:00
|
|
|
|
2014-07-08 01:23:55 +02:00
|
|
|
//Updates
|
|
|
|
getServer().getScheduler().scheduleSyncRepeatingTask(this, new Ticker(this), 1, 1);
|
2014-08-16 22:50:33 +02:00
|
|
|
|
|
|
|
_commands.add(new AuthorCommand(this));
|
2014-08-20 03:02:12 +02:00
|
|
|
_commands.add(new AdminCommand(this));
|
2014-08-16 22:50:33 +02:00
|
|
|
_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));
|
2015-01-29 01:54:59 +01:00
|
|
|
_commands.add(new ParseCommand200(this));
|
|
|
|
_commands.add(new ParseCommand400(this));
|
2015-01-27 03:59:28 +01:00
|
|
|
_commands.add(new ParseCommand600(this));
|
2014-08-16 22:50:33 +02:00
|
|
|
_commands.add(new RenameCommand(this));
|
|
|
|
_commands.add(new SaveCommand(this));
|
|
|
|
_commands.add(new WorldsCommand(this));
|
2014-08-17 03:17:21 +02:00
|
|
|
_commands.add(new CopyCommand(this));
|
2015-02-26 09:40:09 +01:00
|
|
|
_commands.add(new SpawnCommand(this));
|
|
|
|
_commands.add(new SetSpawnCommand(this));
|
2016-02-25 16:29:47 +01:00
|
|
|
_commands.add(new ItemNameCommand(this));
|
|
|
|
_commands.add(new AddLoreCommand(this));
|
|
|
|
_commands.add(new ClearLoreCommand(this));
|
2014-06-15 02:12:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onDisable()
|
|
|
|
{
|
2015-10-11 02:26:09 +02:00
|
|
|
|
2014-06-15 02:12:08 +02:00
|
|
|
}
|
2015-10-11 02:26:09 +02:00
|
|
|
|
2014-06-15 02:12:08 +02:00
|
|
|
@EventHandler
|
2014-07-08 01:23:55 +02:00
|
|
|
public void PlayerJoin(PlayerJoinEvent event)
|
2014-06-15 02:12:08 +02:00
|
|
|
{
|
2014-07-05 08:04:46 +02:00
|
|
|
Player player = event.getPlayer();
|
2015-10-11 02:26:09 +02:00
|
|
|
|
2014-08-16 23:01:00 +02:00
|
|
|
player.teleport(getSpawnLocation());
|
2015-10-11 02:26:09 +02:00
|
|
|
|
2014-07-09 02:33:22 +02:00
|
|
|
ResetInventory(event.getPlayer());
|
2015-10-11 02:26:09 +02:00
|
|
|
|
2014-07-08 01:23:55 +02:00
|
|
|
DisplayHelp(player);
|
2015-01-26 01:23:08 +01:00
|
|
|
}
|
2015-10-11 02:26:09 +02:00
|
|
|
|
2015-01-26 01:23:08 +01:00
|
|
|
@EventHandler
|
|
|
|
public void permissionUpdate(TickEvent event)
|
|
|
|
{
|
|
|
|
for (Player player : UtilServer.getPlayers())
|
|
|
|
{
|
|
|
|
permissionSet(player);
|
|
|
|
}
|
|
|
|
}
|
2015-10-11 02:26:09 +02:00
|
|
|
|
2015-01-26 01:23:08 +01:00
|
|
|
public void permissionSet(Player player)
|
|
|
|
{
|
|
|
|
boolean hasPermission = GetData(player.getWorld().getName()).HasAccess(player);
|
2015-10-11 02:26:09 +02:00
|
|
|
|
2015-01-26 01:23:08 +01:00
|
|
|
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);
|
2015-11-27 03:35:25 +01:00
|
|
|
player.addAttachment(plugin, "coloredsigns.format", hasPermission);
|
2015-01-26 01:23:08 +01:00
|
|
|
}
|
2015-10-11 02:26:09 +02:00
|
|
|
|
2015-01-26 01:23:08 +01:00
|
|
|
_permissionMap.put(player, hasPermission);
|
2015-10-11 02:26:09 +02:00
|
|
|
|
2015-01-26 01:23:08 +01:00
|
|
|
UtilPlayer.message(player, "Plugin Permissions: " + F.tf(hasPermission));
|
|
|
|
}
|
2014-07-08 01:23:55 +02:00
|
|
|
}
|
2015-10-11 02:26:09 +02:00
|
|
|
|
|
|
|
|
2014-07-08 01:23:55 +02:00
|
|
|
public void DisplayHelp(Player player)
|
|
|
|
{
|
|
|
|
UtilPlayer.message(player, F.main("Parser", "Listing Commands;"));
|
2015-10-11 02:26:09 +02:00
|
|
|
UtilPlayer.message(player, F.value("Parameters", "Parameters: <?> = Required, [?] = Optional"));
|
2014-07-08 01:23:55 +02:00
|
|
|
UtilPlayer.message(player, F.value("/hub", "Return to hub world"));
|
2014-07-09 02:33:22 +02:00
|
|
|
UtilPlayer.message(player, " ");
|
|
|
|
UtilPlayer.message(player, F.value("/name <name>", "Set name for current map"));
|
|
|
|
UtilPlayer.message(player, F.value("/author <name>", "Set author for current map"));
|
2014-08-16 22:50:33 +02:00
|
|
|
UtilPlayer.message(player, F.value("/gametype <type>", "Set gametype for current map"));
|
2014-07-09 03:08:37 +02:00
|
|
|
UtilPlayer.message(player, " ");
|
2014-08-20 03:02:12 +02:00
|
|
|
UtilPlayer.message(player, F.value("/admin <name>", "Toggle admin for player on map"));
|
|
|
|
UtilPlayer.message(player, " ");
|
|
|
|
UtilPlayer.message(player, F.value("/create <name> [gametype]", "Creates a new map"));
|
|
|
|
UtilPlayer.message(player, F.value("/delete <name> [gametype]", "Deletes an existing map"));
|
|
|
|
UtilPlayer.message(player, F.value("/copy <name> <copy name>", "Copies an existing map"));
|
|
|
|
UtilPlayer.message(player, " ");
|
|
|
|
UtilPlayer.message(player, F.value("/list", "List maps"));
|
|
|
|
UtilPlayer.message(player, F.value("/map <name> [gametype]", "Teleport to a map"));
|
|
|
|
UtilPlayer.message(player, " ");
|
2014-07-09 03:08:37 +02:00
|
|
|
UtilPlayer.message(player, C.cYellow + "Documentation: " + C.cGreen + "http://tinyurl.com/mpxmaps");
|
2015-10-11 02:26:09 +02:00
|
|
|
|
2014-07-08 01:23:55 +02:00
|
|
|
}
|
2015-10-11 02:26:09 +02:00
|
|
|
|
2014-07-08 01:23:55 +02:00
|
|
|
@EventHandler
|
|
|
|
public void Command(PlayerCommandPreprocessEvent event)
|
2014-10-15 22:04:44 +02:00
|
|
|
{
|
2014-08-16 22:50:33 +02:00
|
|
|
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);
|
|
|
|
|
2014-07-08 01:23:55 +02:00
|
|
|
if (_curParse != null)
|
|
|
|
{
|
2014-08-16 22:50:33 +02:00
|
|
|
UtilPlayer.message(player, F.main("Parser", "Cannot use commands during Map Parse!"));
|
2014-07-08 01:23:55 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (event.getMessage().toLowerCase().startsWith("/help"))
|
|
|
|
{
|
|
|
|
event.setCancelled(true);
|
2015-10-11 02:26:09 +02:00
|
|
|
|
2014-08-16 22:50:33 +02:00
|
|
|
DisplayHelp(player);
|
2014-06-26 05:53:28 +02:00
|
|
|
}
|
2014-07-09 02:33:22 +02:00
|
|
|
|
2014-08-16 22:50:33 +02:00
|
|
|
for (BaseCommand command : _commands)
|
2014-07-08 04:04:44 +02:00
|
|
|
{
|
2014-08-16 22:50:33 +02:00
|
|
|
for (String alias : command.getAliases())
|
2014-07-08 21:18:43 +02:00
|
|
|
{
|
2014-08-16 22:50:33 +02:00
|
|
|
if (alias.equalsIgnoreCase(commandLabel))
|
2014-07-09 02:33:22 +02:00
|
|
|
{
|
2015-02-26 09:40:09 +01:00
|
|
|
event.setCancelled(true);
|
2015-10-11 02:26:09 +02:00
|
|
|
|
2014-08-16 22:50:33 +02:00
|
|
|
if (!command.execute(player, commandLabel, args))
|
|
|
|
{
|
2014-08-17 03:17:21 +02:00
|
|
|
UtilPlayer.message(player, F.main("Parser", "Invalid Input."));
|
|
|
|
UtilPlayer.message(player, F.elem(command.getUsage()));
|
2014-08-16 22:50:33 +02:00
|
|
|
}
|
2014-07-08 04:04:44 +02:00
|
|
|
|
2014-07-08 01:23:55 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2014-08-16 22:50:33 +02:00
|
|
|
}
|
|
|
|
}
|
2014-07-08 01:23:55 +02:00
|
|
|
|
2014-08-16 22:50:33 +02:00
|
|
|
public void sendValidGameTypes(Player player)
|
|
|
|
{
|
|
|
|
UtilPlayer.message(player, F.main("Parser", "Valid Game Types;"));
|
2014-07-08 01:23:55 +02:00
|
|
|
|
2014-08-16 22:50:33 +02:00
|
|
|
String gameTypes = "";
|
2014-06-26 21:09:29 +02:00
|
|
|
|
2014-08-16 22:50:33 +02:00
|
|
|
for (GameType game : GameType.values())
|
2014-07-09 02:33:22 +02:00
|
|
|
{
|
2014-08-16 22:50:33 +02:00
|
|
|
gameTypes += game.toString() + " ";
|
2014-06-15 02:12:08 +02:00
|
|
|
}
|
2014-08-16 22:50:33 +02:00
|
|
|
|
|
|
|
player.sendMessage(gameTypes);
|
2014-07-08 01:23:55 +02:00
|
|
|
}
|
2014-08-16 22:50:33 +02:00
|
|
|
|
2014-07-08 01:23:55 +02:00
|
|
|
@EventHandler
|
|
|
|
public void ParseUpdate(TickEvent event)
|
|
|
|
{
|
|
|
|
if (_curParse == null)
|
2014-06-15 02:12:08 +02:00
|
|
|
return;
|
2015-10-11 02:26:09 +02:00
|
|
|
|
2014-07-08 01:23:55 +02:00
|
|
|
if (_curParse.Update())
|
2014-06-15 02:12:08 +02:00
|
|
|
{
|
2014-07-08 21:40:28 +02:00
|
|
|
Announce("Parse Completed!");
|
2015-10-11 02:26:09 +02:00
|
|
|
|
2014-07-08 21:40:28 +02:00
|
|
|
Announce("Cleaning and Creating ZIP...");
|
2015-10-11 02:26:09 +02:00
|
|
|
|
2014-07-08 21:40:28 +02:00
|
|
|
try
|
|
|
|
{
|
2014-07-09 00:13:30 +02:00
|
|
|
_worldManager.finalizeParsedWorld(_curParse.getWorld());
|
2014-07-08 21:40:28 +02:00
|
|
|
}
|
|
|
|
catch (Exception e)
|
|
|
|
{
|
|
|
|
Announce("Creating ZIP Failed! Please Try Again!");
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
2015-10-11 02:26:09 +02:00
|
|
|
|
2014-07-08 21:40:28 +02:00
|
|
|
_curParse = null;
|
2014-06-15 02:12:08 +02:00
|
|
|
}
|
|
|
|
}
|
2015-10-11 02:26:09 +02:00
|
|
|
|
2014-11-07 13:10:33 +01:00
|
|
|
@EventHandler
|
2014-07-05 08:04:46 +02:00
|
|
|
public void DisableCreatures(EntitySpawnEvent event)
|
|
|
|
{
|
|
|
|
if (event.getEntityType() == EntityType.DROPPED_ITEM || event.getEntity() instanceof LivingEntity)
|
|
|
|
event.setCancelled(true);
|
|
|
|
}
|
2015-10-11 02:26:09 +02:00
|
|
|
|
2014-08-15 07:28:50 +02:00
|
|
|
@EventHandler
|
|
|
|
public void DisableBurn(BlockBurnEvent event)
|
|
|
|
{
|
|
|
|
event.setCancelled(true);
|
|
|
|
}
|
2015-10-11 02:26:09 +02:00
|
|
|
|
2015-08-07 21:45:38 +02:00
|
|
|
@EventHandler
|
|
|
|
public void DisableIgnite(BlockIgniteEvent event)
|
|
|
|
{
|
|
|
|
if (event.getCause() == IgniteCause.LAVA || event.getCause() == IgniteCause.SPREAD)
|
|
|
|
event.setCancelled(true);
|
|
|
|
}
|
2015-10-11 02:26:09 +02:00
|
|
|
|
2014-08-15 07:28:50 +02:00
|
|
|
@EventHandler
|
|
|
|
public void DisableFire(BlockSpreadEvent event)
|
|
|
|
{
|
|
|
|
event.setCancelled(true);
|
|
|
|
}
|
2015-10-11 02:26:09 +02:00
|
|
|
|
2014-08-15 07:28:50 +02:00
|
|
|
@EventHandler
|
|
|
|
public void DisableFade(BlockFadeEvent event)
|
|
|
|
{
|
|
|
|
event.setCancelled(true);
|
|
|
|
}
|
2015-10-11 02:26:09 +02:00
|
|
|
|
2014-08-15 07:28:50 +02:00
|
|
|
@EventHandler
|
|
|
|
public void DisableDecay(LeavesDecayEvent event)
|
|
|
|
{
|
|
|
|
event.setCancelled(true);
|
|
|
|
}
|
2015-10-11 02:26:09 +02:00
|
|
|
|
2015-07-02 02:09:39 +02:00
|
|
|
@EventHandler
|
|
|
|
public void DisableIceForm(BlockFormEvent event)
|
|
|
|
{
|
|
|
|
event.setCancelled(true);
|
|
|
|
}
|
2015-10-11 02:26:09 +02:00
|
|
|
|
2014-07-05 08:04:46 +02:00
|
|
|
@EventHandler
|
|
|
|
public void Updates(PlayerMoveEvent event)
|
|
|
|
{
|
|
|
|
for (World world : this.getServer().getWorlds())
|
2014-08-06 03:07:49 +02:00
|
|
|
{
|
2014-10-15 07:57:25 +02:00
|
|
|
if (world.getName().toLowerCase().contains("halloween"))
|
|
|
|
world.setTime(16000);
|
|
|
|
else
|
|
|
|
world.setTime(8000);
|
2014-08-06 03:07:49 +02:00
|
|
|
world.setStorm(false);
|
|
|
|
}
|
2015-10-11 02:26:09 +02:00
|
|
|
|
|
|
|
|
2014-07-05 08:04:46 +02:00
|
|
|
if (event.getPlayer().getGameMode() != GameMode.CREATIVE)
|
|
|
|
event.getPlayer().setGameMode(GameMode.CREATIVE);
|
|
|
|
}
|
2015-10-11 02:26:09 +02:00
|
|
|
|
2014-07-08 04:04:44 +02:00
|
|
|
@EventHandler
|
|
|
|
public void SaveUnloadWorlds(TickEvent event)
|
|
|
|
{
|
2014-10-15 22:04:44 +02:00
|
|
|
for (final World world : getServer().getWorlds())
|
2014-07-08 04:04:44 +02:00
|
|
|
{
|
|
|
|
if (world.getName().equalsIgnoreCase("world"))
|
|
|
|
continue;
|
2014-10-15 07:57:25 +02:00
|
|
|
|
2014-07-08 21:18:43 +02:00
|
|
|
if (world.getName().startsWith("parse_"))
|
|
|
|
continue;
|
2014-10-15 07:57:25 +02:00
|
|
|
|
2014-08-16 22:50:33 +02:00
|
|
|
if (!world.getName().startsWith("map"))
|
2014-07-08 21:18:43 +02:00
|
|
|
continue;
|
2014-10-15 07:57:25 +02:00
|
|
|
|
2014-07-08 04:04:44 +02:00
|
|
|
if (world.getPlayers().isEmpty())
|
|
|
|
{
|
2014-08-17 03:17:21 +02:00
|
|
|
Announce("Saving & Closing World: " + F.elem(world.getName()));
|
2014-07-08 04:04:44 +02:00
|
|
|
MapUtil.UnloadWorld(this, world, true);
|
2014-10-15 22:04:44 +02:00
|
|
|
|
|
|
|
_mapsBeingZipped.add(world.getName());
|
|
|
|
System.out.println("Starting backup of " + world);
|
|
|
|
BackupTask backupTask = new BackupTask(this, world.getName(), new Callback<Boolean>()
|
2015-10-11 02:26:09 +02:00
|
|
|
{
|
2014-10-15 22:04:44 +02:00
|
|
|
@Override
|
|
|
|
public void run(Boolean data)
|
|
|
|
{
|
|
|
|
System.out.println("Finished backup of " + world);
|
|
|
|
_mapsBeingZipped.remove(world.getName());
|
|
|
|
}
|
2015-10-11 02:26:09 +02:00
|
|
|
});
|
2014-07-08 04:04:44 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-10-15 22:04:44 +02:00
|
|
|
|
2014-07-08 01:23:55 +02:00
|
|
|
public void Announce(String msg)
|
|
|
|
{
|
|
|
|
for (Player player : UtilServer.getPlayers())
|
|
|
|
{
|
|
|
|
player.sendMessage(C.cGold + msg);
|
|
|
|
}
|
2014-10-15 07:57:25 +02:00
|
|
|
|
2014-08-24 08:45:47 +02:00
|
|
|
System.out.println("[Announce] " + msg);
|
2014-07-08 01:23:55 +02:00
|
|
|
}
|
2014-10-15 07:57:25 +02:00
|
|
|
|
2014-08-16 22:50:33 +02:00
|
|
|
public boolean DoesMapExist(String mapName, GameType gameType)
|
2014-07-08 01:23:55 +02:00
|
|
|
{
|
2014-08-16 22:50:33 +02:00
|
|
|
return DoesMapExist(getWorldString(mapName, gameType));
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean DoesMapExist(String worldName)
|
|
|
|
{
|
|
|
|
File file = new File(worldName);
|
|
|
|
|
|
|
|
if (file.exists() && file.isDirectory())
|
|
|
|
return true;
|
|
|
|
|
2014-07-08 01:23:55 +02:00
|
|
|
return false;
|
|
|
|
}
|
2014-08-16 22:50:33 +02:00
|
|
|
|
|
|
|
public String getShortWorldName(String worldName)
|
|
|
|
{
|
|
|
|
int lastIndexOfSeperator = worldName.lastIndexOf('/');
|
|
|
|
|
|
|
|
if (lastIndexOfSeperator != -1)
|
|
|
|
return worldName.substring(lastIndexOfSeperator + 1);
|
|
|
|
|
|
|
|
return worldName;
|
|
|
|
}
|
|
|
|
|
|
|
|
public World GetMapWorld(String mapName, GameType gameType)
|
|
|
|
{
|
|
|
|
return GetMapWorld(getWorldString(mapName, gameType));
|
|
|
|
}
|
|
|
|
|
|
|
|
public World GetMapWorld(String worldName)
|
2014-07-08 01:23:55 +02:00
|
|
|
{
|
|
|
|
for (World world : this.getServer().getWorlds())
|
|
|
|
{
|
2014-08-16 22:50:33 +02:00
|
|
|
if (world.getName().equals(worldName))
|
2014-07-08 01:23:55 +02:00
|
|
|
return world;
|
|
|
|
}
|
2014-08-16 22:50:33 +02:00
|
|
|
|
2014-07-08 01:23:55 +02:00
|
|
|
return null;
|
|
|
|
}
|
2014-08-16 22:50:33 +02:00
|
|
|
|
2014-08-17 03:17:21 +02:00
|
|
|
public String getWorldString(String mapName, GameType type)
|
2014-08-16 22:50:33 +02:00
|
|
|
{
|
2014-08-17 03:17:21 +02:00
|
|
|
return "map" + "/" + type.GetName() + "/" + mapName;
|
2014-08-16 22:50:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public List<String> getMapsByName(String name)
|
|
|
|
{
|
|
|
|
name = name.toLowerCase();
|
|
|
|
|
|
|
|
List<String> maps = new LinkedList<String>();
|
|
|
|
boolean matchesExact = false;
|
|
|
|
|
|
|
|
for (GameType type : GameType.values())
|
|
|
|
{
|
|
|
|
|
|
|
|
File mapsFolder = new File("map" + File.separator + type.GetName());
|
|
|
|
if (!mapsFolder.exists())
|
|
|
|
continue;
|
|
|
|
|
|
|
|
for (File file : mapsFolder.listFiles())
|
|
|
|
{
|
|
|
|
if (!file.isDirectory())
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (!file.getName().toLowerCase().contains(name))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (file.getName().equalsIgnoreCase(name))
|
|
|
|
matchesExact = true;
|
|
|
|
|
|
|
|
maps.add(getWorldString(file.getName(), type));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (matchesExact)
|
|
|
|
{
|
|
|
|
Iterator<String> it = maps.iterator();
|
|
|
|
while (it.hasNext())
|
|
|
|
{
|
|
|
|
String mapString = it.next();
|
|
|
|
|
|
|
|
if (!mapString.toLowerCase().endsWith(name))
|
|
|
|
{
|
|
|
|
it.remove();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return maps;
|
|
|
|
}
|
2014-10-15 07:57:25 +02:00
|
|
|
|
2014-07-09 00:13:30 +02:00
|
|
|
public MapData GetData(String mapName)
|
|
|
|
{
|
|
|
|
if (_mapData.containsKey(mapName))
|
|
|
|
return _mapData.get(mapName);
|
2014-10-15 07:57:25 +02:00
|
|
|
|
2014-07-09 00:13:30 +02:00
|
|
|
MapData data = new MapData(mapName);
|
2014-10-15 07:57:25 +02:00
|
|
|
|
2014-07-09 00:13:30 +02:00
|
|
|
_mapData.put(mapName, data);
|
2014-10-15 07:57:25 +02:00
|
|
|
|
2014-07-09 00:13:30 +02:00
|
|
|
return data;
|
|
|
|
}
|
2014-08-16 23:01:00 +02:00
|
|
|
|
|
|
|
public Location getSpawnLocation()
|
|
|
|
{
|
|
|
|
return _spawnLocation;
|
|
|
|
}
|
2014-10-15 07:57:25 +02:00
|
|
|
|
2014-07-09 02:33:22 +02:00
|
|
|
public void ResetInventory(Player player)
|
|
|
|
{
|
2015-10-11 02:26:09 +02:00
|
|
|
// 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));
|
2014-07-09 02:33:22 +02:00
|
|
|
}
|
2014-08-16 22:50:33 +02:00
|
|
|
|
|
|
|
public WorldManager getWorldManager()
|
|
|
|
{
|
|
|
|
return _worldManager;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setCurrentParse(Parse parse)
|
|
|
|
{
|
|
|
|
_curParse = parse;
|
|
|
|
}
|
2014-10-15 07:57:25 +02:00
|
|
|
|
2014-07-09 02:33:22 +02:00
|
|
|
@EventHandler
|
|
|
|
public void Chat(AsyncPlayerChatEvent event)
|
|
|
|
{
|
|
|
|
event.setCancelled(true);
|
2014-08-16 22:50:33 +02:00
|
|
|
|
|
|
|
String world = C.cDGreen + C.Bold + getShortWorldName(event.getPlayer().getWorld().getName());
|
|
|
|
|
|
|
|
|
2014-10-15 07:57:25 +02:00
|
|
|
|
2014-07-09 02:33:22 +02:00
|
|
|
String name = C.cYellow + event.getPlayer().getName();
|
2014-08-20 03:02:12 +02:00
|
|
|
if (GetData(event.getPlayer().getWorld().getName()).HasAccess(event.getPlayer()))
|
2014-07-09 02:33:22 +02:00
|
|
|
name = C.cGreen + event.getPlayer().getName();
|
2014-10-15 07:57:25 +02:00
|
|
|
|
2014-07-09 02:33:22 +02:00
|
|
|
String grayName = C.cBlue + event.getPlayer().getName();
|
|
|
|
String grayWorld = C.cBlue + C.Bold + event.getPlayer().getWorld().getName();
|
2014-10-15 07:57:25 +02:00
|
|
|
|
2014-07-09 02:33:22 +02:00
|
|
|
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());
|
|
|
|
}
|
2014-10-15 07:57:25 +02:00
|
|
|
|
2014-07-09 02:33:22 +02:00
|
|
|
}
|
2014-10-15 07:57:25 +02:00
|
|
|
|
2014-07-09 02:33:22 +02:00
|
|
|
System.out.println(world + ChatColor.RESET + " " + name + ChatColor.RESET + " " + event.getMessage());
|
|
|
|
}
|
2014-10-15 07:57:25 +02:00
|
|
|
|
2015-01-26 01:23:08 +01:00
|
|
|
@EventHandler(priority = EventPriority.LOWEST)
|
2014-07-09 02:33:22 +02:00
|
|
|
public void InteractCancel(PlayerInteractEvent event)
|
|
|
|
{
|
|
|
|
//Permission
|
2014-08-20 03:02:12 +02:00
|
|
|
if (!GetData(event.getPlayer().getWorld().getName()).HasAccess(event.getPlayer()))
|
2014-07-09 02:33:22 +02:00
|
|
|
{
|
|
|
|
event.setCancelled(true);
|
|
|
|
}
|
|
|
|
}
|
2014-10-15 07:57:25 +02:00
|
|
|
|
2015-01-26 01:23:08 +01:00
|
|
|
@EventHandler(priority = EventPriority.LOWEST)
|
|
|
|
public void commandCancel(PlayerCommandPreprocessEvent event)
|
2014-07-09 02:33:22 +02:00
|
|
|
{
|
2015-01-26 01:23:08 +01:00
|
|
|
if (event.getMessage().startsWith("/tp") ||
|
2015-10-11 02:26:09 +02:00
|
|
|
event.getMessage().startsWith("/hub") ||
|
|
|
|
event.getMessage().startsWith("/list") ||
|
|
|
|
event.getMessage().startsWith("/map") ||
|
|
|
|
event.getMessage().startsWith("/create") ||
|
|
|
|
event.getMessage().startsWith("/copy") ||
|
|
|
|
event.getMessage().startsWith("/delete"))
|
2015-01-26 01:23:08 +01:00
|
|
|
return;
|
2015-10-11 02:26:09 +02:00
|
|
|
|
2015-01-26 01:23:08 +01:00
|
|
|
//Permission
|
|
|
|
if (!GetData(event.getPlayer().getWorld().getName()).HasAccess(event.getPlayer()))
|
2014-07-09 02:33:22 +02:00
|
|
|
{
|
2015-01-26 01:23:08 +01:00
|
|
|
UtilPlayer.message(event.getPlayer(), F.main("Parser", "You do not have Build-Access for this Map."));
|
|
|
|
event.setCancelled(true);
|
2014-07-09 02:33:22 +02:00
|
|
|
}
|
|
|
|
}
|
2014-10-15 22:04:44 +02:00
|
|
|
|
|
|
|
public HashSet<String> getMapsBeingZipped()
|
|
|
|
{
|
|
|
|
return _mapsBeingZipped;
|
|
|
|
}
|
2014-10-17 00:51:32 +02:00
|
|
|
|
2014-07-09 02:33:22 +02:00
|
|
|
@EventHandler
|
|
|
|
public void Join(PlayerJoinEvent event)
|
|
|
|
{
|
|
|
|
event.setJoinMessage(F.sys("Player Join", event.getPlayer().getName()));
|
|
|
|
}
|
2014-10-15 07:57:25 +02:00
|
|
|
|
2014-07-09 02:33:22 +02:00
|
|
|
@EventHandler
|
|
|
|
public void Join(PlayerQuitEvent event)
|
|
|
|
{
|
|
|
|
event.setQuitMessage(F.sys("Player Quit", event.getPlayer().getName()));
|
|
|
|
}
|
2015-10-11 02:26:09 +02:00
|
|
|
|
2014-10-25 02:17:32 +02:00
|
|
|
@EventHandler(priority = EventPriority.LOWEST)
|
|
|
|
public void TeleportCommand(PlayerCommandPreprocessEvent event)
|
2014-10-23 05:05:35 +02:00
|
|
|
{
|
2014-10-25 02:17:32 +02:00
|
|
|
if (!event.getMessage().toLowerCase().startsWith("/tp"))
|
|
|
|
return;
|
2015-10-11 02:26:09 +02:00
|
|
|
|
2014-10-23 05:05:35 +02:00
|
|
|
Player player = event.getPlayer();
|
2015-10-11 02:26:09 +02:00
|
|
|
|
2014-10-25 02:17:32 +02:00
|
|
|
String[] tokens = event.getMessage().split(" ");
|
2015-10-11 02:26:09 +02:00
|
|
|
|
2014-10-25 02:17:32 +02:00
|
|
|
if (tokens.length != 2)
|
2014-10-23 05:05:35 +02:00
|
|
|
{
|
2014-10-25 02:17:32 +02:00
|
|
|
return;
|
2014-10-23 05:05:35 +02:00
|
|
|
}
|
2015-10-11 02:26:09 +02:00
|
|
|
|
2014-11-14 04:14:31 +01:00
|
|
|
event.setCancelled(true);
|
2015-10-11 02:26:09 +02:00
|
|
|
|
2014-10-25 02:17:32 +02:00
|
|
|
Player target = UtilPlayer.searchOnline(player, tokens[1], true);
|
|
|
|
if (target != null)
|
2014-10-23 05:05:35 +02:00
|
|
|
{
|
2014-10-25 02:17:32 +02:00
|
|
|
UtilPlayer.message(player, F.main("Game", "You teleported to " + F.name(target.getName()) + "."));
|
|
|
|
player.teleport(target);
|
2014-10-23 05:05:35 +02:00
|
|
|
}
|
|
|
|
}
|
2015-10-11 02:26:09 +02:00
|
|
|
|
2014-11-14 04:14:31 +01:00
|
|
|
@EventHandler(priority = EventPriority.LOWEST)
|
|
|
|
public void FlySpeed(PlayerCommandPreprocessEvent event)
|
|
|
|
{
|
|
|
|
if (!event.getMessage().toLowerCase().startsWith("/speed"))
|
|
|
|
return;
|
2015-10-11 02:26:09 +02:00
|
|
|
|
2014-11-14 04:14:31 +01:00
|
|
|
Player player = event.getPlayer();
|
2015-10-11 02:26:09 +02:00
|
|
|
|
2014-11-14 04:14:31 +01:00
|
|
|
String[] tokens = event.getMessage().split(" ");
|
2015-10-11 02:26:09 +02:00
|
|
|
|
2014-11-14 04:14:31 +01:00
|
|
|
if (tokens.length != 2)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
2015-10-11 02:26:09 +02:00
|
|
|
|
2014-11-14 04:14:31 +01:00
|
|
|
event.setCancelled(true);
|
2015-10-11 02:26:09 +02:00
|
|
|
|
2014-11-14 04:14:31 +01:00
|
|
|
try
|
|
|
|
{
|
|
|
|
float speed = Float.parseFloat(tokens[1]);
|
2015-10-11 02:26:09 +02:00
|
|
|
|
2014-11-14 04:14:31 +01:00
|
|
|
player.setFlySpeed(speed);
|
2015-10-11 02:26:09 +02:00
|
|
|
|
2014-11-14 04:14:31 +01:00
|
|
|
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."));
|
|
|
|
}
|
|
|
|
}
|
2015-10-11 02:26:09 +02:00
|
|
|
|
2014-11-14 04:14:31 +01:00
|
|
|
private HashMap<Player, ArrayList<HashSet<BlockData>>> treeHistory = new HashMap<Player, ArrayList<HashSet<BlockData>>>();
|
2015-10-11 02:26:09 +02:00
|
|
|
|
2014-11-14 04:14:31 +01:00
|
|
|
@EventHandler(priority = EventPriority.HIGHEST)
|
|
|
|
public void treeRemover(PlayerInteractEvent event)
|
|
|
|
{
|
|
|
|
if (event.isCancelled())
|
|
|
|
return;
|
2015-10-11 02:26:09 +02:00
|
|
|
|
2014-11-14 04:14:31 +01:00
|
|
|
//Permission
|
|
|
|
if (!GetData(event.getPlayer().getWorld().getName()).HasAccess(event.getPlayer()))
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
2015-10-11 02:26:09 +02:00
|
|
|
|
2014-11-14 04:14:31 +01:00
|
|
|
Player player = event.getPlayer();
|
2015-10-11 02:26:09 +02:00
|
|
|
|
2014-11-14 04:14:31 +01:00
|
|
|
if (!UtilGear.isMat(player.getItemInHand(), Material.NETHER_STAR))
|
|
|
|
return;
|
2015-10-11 02:26:09 +02:00
|
|
|
|
2014-11-14 04:14:31 +01:00
|
|
|
event.setCancelled(true);
|
2015-10-11 02:26:09 +02:00
|
|
|
|
2014-11-14 04:14:31 +01:00
|
|
|
//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;
|
|
|
|
}
|
2015-10-11 02:26:09 +02:00
|
|
|
|
2014-11-14 04:14:31 +01:00
|
|
|
HashSet<Block> toRemove = searchLog(new HashSet<Block>(), event.getClickedBlock());
|
2015-10-11 02:26:09 +02:00
|
|
|
|
2014-11-14 04:14:31 +01:00
|
|
|
if (toRemove.isEmpty())
|
|
|
|
{
|
|
|
|
player.sendMessage(C.cRed + C.Bold + "TreeTool: " + ChatColor.RESET + "Left-Click on Log");
|
|
|
|
return;
|
|
|
|
}
|
2015-10-11 02:26:09 +02:00
|
|
|
|
2014-11-14 04:14:31 +01:00
|
|
|
HashSet<BlockData> history = new HashSet<BlockData>();
|
2015-10-11 02:26:09 +02:00
|
|
|
|
2014-11-14 04:14:31 +01:00
|
|
|
for (Block block : toRemove)
|
|
|
|
{
|
|
|
|
history.add(new BlockData(block));
|
2015-10-11 02:26:09 +02:00
|
|
|
|
2014-11-14 04:14:31 +01:00
|
|
|
block.setType(Material.AIR);
|
|
|
|
}
|
2015-10-11 02:26:09 +02:00
|
|
|
|
2014-11-14 04:14:31 +01:00
|
|
|
if (!treeHistory.containsKey(player))
|
|
|
|
treeHistory.put(player, new ArrayList<HashSet<BlockData>>());
|
2015-10-11 02:26:09 +02:00
|
|
|
|
2014-11-14 04:14:31 +01:00
|
|
|
treeHistory.get(player).add(0, history);
|
2015-10-11 02:26:09 +02:00
|
|
|
|
2014-11-14 04:14:31 +01:00
|
|
|
player.sendMessage(C.cRed + C.Bold + "TreeTool: " + ChatColor.RESET + "Tree Removed");
|
2015-10-11 02:26:09 +02:00
|
|
|
|
2014-11-14 04:14:31 +01:00
|
|
|
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;
|
|
|
|
}
|
2015-10-11 02:26:09 +02:00
|
|
|
|
2014-11-14 04:14:31 +01:00
|
|
|
HashSet<BlockData> datas = treeHistory.get(player).remove(0);
|
2015-10-11 02:26:09 +02:00
|
|
|
|
2014-11-14 04:14:31 +01:00
|
|
|
for (BlockData data : datas)
|
|
|
|
data.restore();
|
2015-10-11 02:26:09 +02:00
|
|
|
|
2014-11-14 04:14:31 +01:00
|
|
|
player.sendMessage(C.cGreen + C.Bold + "TreeTool: " + ChatColor.RESET + "Tree Restored");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-09-12 18:50:06 +02:00
|
|
|
@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();
|
2015-09-18 17:25:11 +02:00
|
|
|
Location lowestCorner = center.clone().subtract(49, 0, 49);
|
2015-09-12 18:50:06 +02:00
|
|
|
|
|
|
|
// 0 = air or other
|
|
|
|
// 1 = path - quartz
|
|
|
|
// 2 = mob spawn - gold
|
|
|
|
// 3 = safe spawn - stone
|
|
|
|
|
2015-09-18 17:25:11 +02:00
|
|
|
int[][] maze = new int[99][99];
|
2015-09-12 18:50:06 +02:00
|
|
|
|
|
|
|
/*Iterator<Block> 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;
|
|
|
|
}
|
|
|
|
}*/
|
|
|
|
|
2015-09-18 17:25:11 +02:00
|
|
|
for (int i = 0; i < 99; i++)
|
|
|
|
for (int j = 0; j < 99; j++)
|
2015-09-12 18:50:06 +02:00
|
|
|
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;
|
2015-09-26 21:08:43 +02:00
|
|
|
|
|
|
|
case COBBLESTONE:
|
|
|
|
return 5;
|
|
|
|
|
|
|
|
case BRICK:
|
|
|
|
return 6;
|
2015-09-12 18:50:06 +02:00
|
|
|
|
|
|
|
default:
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-11-14 04:14:31 +01:00
|
|
|
private HashSet<Block> searchLog(HashSet<Block> blocks, Block current)
|
|
|
|
{
|
|
|
|
//Not Tree
|
|
|
|
if (current.getType() != Material.LOG && current.getType() != Material.LEAVES)
|
|
|
|
return blocks;
|
2015-10-11 02:26:09 +02:00
|
|
|
|
2014-11-14 04:14:31 +01:00
|
|
|
if (!blocks.add(current))
|
|
|
|
return blocks;
|
2015-10-11 02:26:09 +02:00
|
|
|
|
2014-11-14 04:14:31 +01:00
|
|
|
for (Block other : UtilBlock.getSurrounding(current, true))
|
|
|
|
{
|
|
|
|
if (current.getType() != Material.LOG && current.getType() != Material.LEAVES)
|
|
|
|
continue;
|
2015-10-11 02:26:09 +02:00
|
|
|
|
2014-11-14 04:14:31 +01:00
|
|
|
if (blocks.contains(other))
|
|
|
|
continue;
|
2015-10-11 02:26:09 +02:00
|
|
|
|
2014-11-14 04:14:31 +01:00
|
|
|
//Dont spread from leaves to log
|
|
|
|
if (current.getType() == Material.LEAVES && other.getType() == Material.LOG)
|
|
|
|
continue;
|
2015-10-11 02:26:09 +02:00
|
|
|
|
2014-11-14 04:14:31 +01:00
|
|
|
searchLog(blocks, other);
|
|
|
|
}
|
2015-10-11 02:26:09 +02:00
|
|
|
|
2014-11-14 04:14:31 +01:00
|
|
|
return blocks;
|
|
|
|
}
|
2015-10-11 02:26:09 +02:00
|
|
|
|
2015-08-09 00:09:26 +02:00
|
|
|
long lastUse = 0;
|
2015-08-07 22:59:50 +02:00
|
|
|
@EventHandler(priority = EventPriority.LOWEST)
|
|
|
|
public void leaptest(PlayerInteractEvent event)
|
|
|
|
{
|
2015-10-11 02:26:09 +02:00
|
|
|
|
2015-08-07 22:59:50 +02:00
|
|
|
if (event.getPlayer().getItemInHand() == null)
|
|
|
|
return;
|
2015-10-11 02:26:09 +02:00
|
|
|
|
2015-08-07 22:59:50 +02:00
|
|
|
if (event.getPlayer().getItemInHand().getType() != Material.FEATHER)
|
|
|
|
return;
|
2015-10-11 02:26:09 +02:00
|
|
|
|
2015-08-09 00:09:26 +02:00
|
|
|
if (System.currentTimeMillis() - lastUse < 800)
|
|
|
|
{
|
|
|
|
Bukkit.broadcastMessage("Cooldown");
|
|
|
|
return;
|
|
|
|
}
|
2015-10-11 02:26:09 +02:00
|
|
|
|
|
|
|
|
2015-08-09 00:09:26 +02:00
|
|
|
lastUse = System.currentTimeMillis();
|
2015-10-11 02:26:09 +02:00
|
|
|
|
2015-08-09 00:09:26 +02:00
|
|
|
Vector vel = event.getPlayer().getLocation().getDirection().multiply(1.2);
|
|
|
|
vel.add(new Vector(0,0.6,0));
|
2015-10-11 02:26:09 +02:00
|
|
|
|
2015-08-09 00:09:26 +02:00
|
|
|
event.getPlayer().setVelocity(vel);
|
2015-08-07 22:59:50 +02:00
|
|
|
}
|
2015-10-11 02:26:09 +02:00
|
|
|
|
2015-11-02 04:37:12 +01:00
|
|
|
@EventHandler(priority = EventPriority.LOWEST)
|
2015-10-11 02:26:09 +02:00
|
|
|
public void signChangeLog(SignChangeEvent event)
|
|
|
|
{
|
|
|
|
if (GetData(event.getPlayer().getWorld().getName()).HasAccess(event.getPlayer()))
|
|
|
|
{
|
2015-11-02 04:37:12 +01:00
|
|
|
ArrayList<String> text = new ArrayList<String>();
|
|
|
|
|
|
|
|
text.add("Date: " + UtilTime.now());
|
|
|
|
text.add("Player: " + event.getPlayer().getName());
|
|
|
|
text.add("Location: " + UtilWorld.locToStrClean(event.getBlock().getLocation()));
|
|
|
|
for (int i=0 ; i<event.getLines().length ; i++)
|
|
|
|
text.add("Line " + i + ": " + event.getLines()[i]);
|
|
|
|
|
|
|
|
writeSignLog(text, event.getPlayer().getWorld());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@EventHandler(priority = EventPriority.LOWEST)
|
|
|
|
public void signCommand(PlayerCommandPreprocessEvent event)
|
|
|
|
{
|
|
|
|
if (event.getMessage().toLowerCase().contains("set"))
|
|
|
|
{
|
|
|
|
ArrayList<String> text = new ArrayList<String>();
|
|
|
|
|
|
|
|
text.add("Date: " + UtilTime.now());
|
|
|
|
text.add("Player: " + event.getPlayer().getName());
|
|
|
|
text.add("Location: " + UtilWorld.locToStrClean(event.getPlayer().getLocation()));
|
|
|
|
text.add("Message: " + event.getMessage());
|
|
|
|
|
|
|
|
writeSignCommandLog(text, event.getPlayer().getWorld());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void writeSignCommandLog(ArrayList<String> text, World world)
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
File file = new File(world.getName() + "/" + "command_sign_log.txt");
|
2015-10-11 02:26:09 +02:00
|
|
|
|
2015-11-02 04:37:12 +01:00
|
|
|
if (!file.exists())
|
|
|
|
file.createNewFile();
|
|
|
|
|
|
|
|
FileWriter fw = new FileWriter(file.getAbsoluteFile(), true);
|
|
|
|
BufferedWriter bw = new BufferedWriter(fw);
|
|
|
|
|
|
|
|
bw.write("\n\n");
|
|
|
|
for (String line : text)
|
|
|
|
bw.write("\n" + line);
|
|
|
|
|
|
|
|
bw.close();
|
|
|
|
}
|
|
|
|
catch (Exception e)
|
|
|
|
{
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void writeSignLog(ArrayList<String> text, World world)
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
File file = new File(world.getName() + "/" + "sign_log.txt");
|
|
|
|
|
|
|
|
if (!file.exists())
|
|
|
|
file.createNewFile();
|
|
|
|
|
|
|
|
FileWriter fw = new FileWriter(file.getAbsoluteFile(), true);
|
|
|
|
BufferedWriter bw = new BufferedWriter(fw);
|
|
|
|
|
|
|
|
bw.write("\n\n");
|
|
|
|
for (String line : text)
|
|
|
|
bw.write("\n" + line);
|
|
|
|
|
|
|
|
bw.close();
|
|
|
|
}
|
|
|
|
catch (Exception e)
|
|
|
|
{
|
|
|
|
e.printStackTrace();
|
2015-10-11 02:26:09 +02:00
|
|
|
}
|
|
|
|
}
|
2014-06-15 02:12:08 +02:00
|
|
|
}
|