refactor: clean source code
This commit is contained in:
3
Plugins[Original]/Mineplex.MapParser/plugin.yml
Normal file
3
Plugins[Original]/Mineplex.MapParser/plugin.yml
Normal file
@ -0,0 +1,3 @@
|
||||
name: MapParser
|
||||
main: mineplex.mapparser.MapParser
|
||||
version: 1
|
27
Plugins[Original]/Mineplex.MapParser/pom.xml
Normal file
27
Plugins[Original]/Mineplex.MapParser/pom.xml
Normal file
@ -0,0 +1,27 @@
|
||||
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<parent>
|
||||
<groupId>com.mineplex</groupId>
|
||||
<artifactId>mineplex-plugin</artifactId>
|
||||
<version>dev-SNAPSHOT</version>
|
||||
<relativePath>../plugin.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
<name>MapParser</name>
|
||||
<artifactId>mineplex-mapparser</artifactId>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>commons-io</groupId>
|
||||
<artifactId>commons-io</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>${project.groupId}</groupId>
|
||||
<artifactId>mineplex-core-common-base</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
@ -0,0 +1,90 @@
|
||||
package mineplex.mapparser;
|
||||
|
||||
import java.io.File;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import mineplex.core.common.util.Callback;
|
||||
import mineplex.core.common.util.ZipUtil;
|
||||
|
||||
/**
|
||||
* Created by shaun on 14-09-23.
|
||||
*/
|
||||
public class BackupTask implements Runnable
|
||||
{
|
||||
private final String _worldName;
|
||||
private final Callback<Boolean> _callback;
|
||||
private final JavaPlugin _plugin;
|
||||
|
||||
public BackupTask(JavaPlugin plugin, String worldName, Callback<Boolean> callback)
|
||||
{
|
||||
_plugin = plugin;
|
||||
_worldName = worldName;
|
||||
_callback = callback;
|
||||
|
||||
plugin.getServer().getScheduler().runTaskAsynchronously(plugin, this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
Date date = new Date();
|
||||
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH-mm-ss");
|
||||
List<String> fileList = new ArrayList<String>();
|
||||
List<String> folderList = new ArrayList<String>();
|
||||
String dest = "backup" + _worldName.substring(3) + "/" + format.format(date) + ".zip";
|
||||
File srcFile = new File(_worldName);
|
||||
|
||||
// Create backup folder if it doesnt already exist
|
||||
File folder = new File(dest.substring(0, dest.lastIndexOf('/')));
|
||||
if (!folder.exists())
|
||||
folder.mkdirs();
|
||||
|
||||
// Get all files to backup
|
||||
for (File file : srcFile.listFiles())
|
||||
{
|
||||
if (file.isFile())
|
||||
fileList.add(_worldName + File.separator + file.getName());
|
||||
else if (file.isDirectory())
|
||||
folderList.add(_worldName + File.separator + file.getName());
|
||||
}
|
||||
|
||||
// Delete old folders if more than 20 backups exist
|
||||
if (folder.listFiles().length > 20)
|
||||
{
|
||||
File[] files = folder.listFiles();
|
||||
File oldestFile = files[0];
|
||||
|
||||
for (int i = 1; i < files.length; i++)
|
||||
{
|
||||
File file = files[i];
|
||||
if (file.getName().endsWith(".zip") && file.lastModified() < oldestFile.lastModified())
|
||||
{
|
||||
oldestFile = file;
|
||||
}
|
||||
}
|
||||
|
||||
System.out.println("Deleting oldest file: " + oldestFile.getName());
|
||||
oldestFile.delete();
|
||||
}
|
||||
|
||||
|
||||
ZipUtil.ZipFolders(srcFile.getAbsolutePath(), dest, folderList, fileList);
|
||||
|
||||
if (_callback != null)
|
||||
{
|
||||
_plugin.getServer().getScheduler().runTask(_plugin, new Runnable()
|
||||
{
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
_callback.run(true);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,25 @@
|
||||
package mineplex.mapparser;
|
||||
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.Material;
|
||||
|
||||
public class BlockData
|
||||
{
|
||||
public Block Block;
|
||||
public Material Material;
|
||||
public byte Data;
|
||||
public long Time;
|
||||
|
||||
public BlockData(Block block)
|
||||
{
|
||||
Block = block;
|
||||
Material = block.getType();
|
||||
Data = block.getData();
|
||||
Time = System.currentTimeMillis();
|
||||
}
|
||||
|
||||
public void restore()
|
||||
{
|
||||
Block.setTypeIdAndData(Material.getId(), Data, true);
|
||||
}
|
||||
}
|
@ -0,0 +1,180 @@
|
||||
package mineplex.mapparser;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public enum GameType
|
||||
{
|
||||
// Stand Alone
|
||||
Other("Other"),
|
||||
Unknown("Unknown"),
|
||||
Lobby("Lobby"),
|
||||
Event("Mineplex Event"),
|
||||
GemHunters("Gem Hunters"),
|
||||
|
||||
// Games
|
||||
BaconBrawl("Bacon Brawl"),
|
||||
Barbarians("A Barbarians Life"),
|
||||
Bridge("The Bridges"),
|
||||
Build("Master Builders"),
|
||||
BuildMavericks("Mavericks Master Builders"),
|
||||
CakeWars2("Cake Wars Duos"),
|
||||
CakeWars4("Cake Wars Standard"),
|
||||
CastleSiege("Castle Siege"),
|
||||
CastleAssault("Castle Assault"),
|
||||
CastleAssaultTDM("Castle Assault TDM"),
|
||||
ChampionsTDM("Champions TDM", "Champions"),
|
||||
ChampionsDominate("Champions Domination", "Champions"),
|
||||
ChampionsCTF("Champions CTF", "Champions"),
|
||||
ChampionsMOBA("Champions MOBA", "Champions"),
|
||||
Christmas("Christmas Chaos"),
|
||||
DeathTag("Death Tag"),
|
||||
DragonEscape("Dragon Escape"),
|
||||
DragonEscapeTeams("Dragon Escape Teams"),
|
||||
DragonRiders("Dragon Riders"),
|
||||
Dragons("Dragons"),
|
||||
DragonsTeams("Dragons Teams"),
|
||||
Draw("Draw My Thing"),
|
||||
Evolution("Evolution"),
|
||||
FlappyBird("Flappy Bird"),
|
||||
Gladiators("Gladiators"),
|
||||
Gravity("Gravity"),
|
||||
Halloween("Halloween Horror"),
|
||||
Halloween2016("Halloween Horror 2016"),
|
||||
HideSeek("Block Hunt"),
|
||||
Horse("Horseback"),
|
||||
Lobbers("Bomb Lobbers"),
|
||||
SurvivalGames("Survival Games"),
|
||||
SurvivalGamesTeams("Survival Games Teams"),
|
||||
Micro("Micro Battle"),
|
||||
MineStrike("MineStrike"),
|
||||
MineWare("MineWare"),
|
||||
MinecraftLeague("MCL"),
|
||||
MilkCow("Milk the Cow"),
|
||||
HOG("Heroes of GWEN"),
|
||||
MonsterLeague("MonsterLeague"),
|
||||
MonsterMaze("Monster Maze"),
|
||||
NanoGames("Nano Games"),
|
||||
Paintball("Super Paintball"),
|
||||
Quiver("One in the Quiver"),
|
||||
QuiverTeams("One in the Quiver Teams"),
|
||||
Runner("Runner"),
|
||||
SearchAndDestroy("Search and Destroy"),
|
||||
Sheep("Sheep Quest"),
|
||||
Skyfall("Skyfall"),
|
||||
Skywars("Skywars"),
|
||||
Smash("Super Smash Mobs"),
|
||||
SmashTeams("Super Smash Mobs Teams", "Super Smash Mobs"),
|
||||
SmashDomination("Super Smash Mobs Domination", "Super Smash Mobs"),
|
||||
Snake("Snake"),
|
||||
SneakyAssassins("Sneaky Assassins"),
|
||||
SpeedBuilders("Speed Builders"),
|
||||
SnowFight("Snow Fight"),
|
||||
Spleef("Super Spleef"),
|
||||
SpleefTeams("Super Spleef Teams"),
|
||||
Stacker("Super Stacker"),
|
||||
SquidShooter("Squid Shooter"),
|
||||
Tug("Tug of Wool"),
|
||||
TurfWars("Turf Wars"),
|
||||
UHC("Ultra Hardcore"),
|
||||
WitherAssault("Wither Assault"),
|
||||
Wizards("Wizards"),
|
||||
ZombieSurvival("Zombie Survival"),
|
||||
|
||||
// Build States
|
||||
Upload("Upload"),
|
||||
Submissions("Submissions"),
|
||||
InProgress("In Progress"),
|
||||
|
||||
None("None");
|
||||
|
||||
String _name;
|
||||
String _lobbyName;
|
||||
|
||||
GameType(String name)
|
||||
{
|
||||
_name = name;
|
||||
_lobbyName = name;
|
||||
}
|
||||
|
||||
GameType(String name, String lobbyName)
|
||||
{
|
||||
_name = name;
|
||||
_lobbyName = lobbyName;
|
||||
}
|
||||
|
||||
public String GetName()
|
||||
{
|
||||
return _name;
|
||||
}
|
||||
|
||||
public String GetLobbyName()
|
||||
{
|
||||
return _lobbyName;
|
||||
}
|
||||
|
||||
public static GameType match(String string)
|
||||
{
|
||||
GameType gameType = null;
|
||||
string = string.toLowerCase();
|
||||
for (GameType type : values())
|
||||
{
|
||||
if (type.name().toLowerCase().startsWith(string) || type.GetName().toLowerCase().startsWith(string))
|
||||
{
|
||||
gameType = type;
|
||||
}
|
||||
}
|
||||
return gameType;
|
||||
}
|
||||
|
||||
public List<String> getMapNames()
|
||||
{
|
||||
File mapsFolder = new File("map" + File.separator + GetName());
|
||||
|
||||
if (!mapsFolder.exists())
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
List<String> mapNames = new ArrayList<>();
|
||||
|
||||
File[] files = mapsFolder.listFiles();
|
||||
|
||||
if (files == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
for (File file : files)
|
||||
{
|
||||
if (!file.isDirectory())
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
mapNames.add(file.getName());
|
||||
}
|
||||
|
||||
return mapNames;
|
||||
}
|
||||
|
||||
public static List<String> getAllMapNames()
|
||||
{
|
||||
List<String> mapNames = new ArrayList<>();
|
||||
|
||||
for (GameType gameType : GameType.values())
|
||||
{
|
||||
List<String> gameMapNames = gameType.getMapNames();
|
||||
|
||||
if (gameMapNames == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
mapNames.addAll(gameMapNames);
|
||||
}
|
||||
|
||||
return mapNames;
|
||||
}
|
||||
}
|
@ -0,0 +1,60 @@
|
||||
package mineplex.mapparser;
|
||||
|
||||
import mineplex.core.common.util.C;
|
||||
import mineplex.core.common.util.F;
|
||||
import net.md_5.bungee.api.ChatColor;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public class GameTypeInfo
|
||||
{
|
||||
|
||||
private final String LINE = C.cAqua + C.Bold + C.Strike + "========================================";
|
||||
|
||||
private GameType _gameType;
|
||||
private List<String> _info;
|
||||
|
||||
public GameTypeInfo(GameType gameType, List<String> info)
|
||||
{
|
||||
_gameType = gameType;
|
||||
_info = info;
|
||||
}
|
||||
|
||||
public void addInfo(String info)
|
||||
{
|
||||
_info.add(info);
|
||||
}
|
||||
|
||||
public void remove(int index)
|
||||
{
|
||||
_info.remove(index);
|
||||
}
|
||||
|
||||
public List<String> getInfo()
|
||||
{
|
||||
return _info;
|
||||
}
|
||||
|
||||
public void sendInfo(Player player)
|
||||
{
|
||||
player.sendMessage(LINE);
|
||||
player.sendMessage(" ");
|
||||
player.sendMessage(F.elem(_gameType.GetName()));
|
||||
player.sendMessage(" ");
|
||||
for(String s : _info)
|
||||
{
|
||||
player.sendMessage(ChatColor.translateAlternateColorCodes('&', s));
|
||||
}
|
||||
player.sendMessage(" ");
|
||||
player.sendMessage(LINE);
|
||||
}
|
||||
|
||||
public GameType getGameType()
|
||||
{
|
||||
return _gameType;
|
||||
}
|
||||
}
|
@ -0,0 +1,215 @@
|
||||
package mineplex.mapparser;
|
||||
|
||||
import com.google.common.collect.Maps;
|
||||
import com.google.common.collect.Sets;
|
||||
|
||||
import mineplex.core.common.util.F;
|
||||
import mineplex.core.common.util.UtilPlayerBase;
|
||||
import mineplex.core.common.util.UtilWorld;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.WorldCreator;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.DataInputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileWriter;
|
||||
import java.io.InputStreamReader;
|
||||
import java.util.Collections;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Set;
|
||||
|
||||
public class MapData
|
||||
{
|
||||
public String MapFolder;
|
||||
public boolean _currentlyLive;
|
||||
public boolean _locked;
|
||||
public Map<String, Location> _warps;
|
||||
|
||||
public GameType MapGameType = null;
|
||||
public String MapName = "null";
|
||||
public String MapCreator = "null";
|
||||
|
||||
public Set<String> AdminList;
|
||||
|
||||
public MapData(String mapFolder)
|
||||
{
|
||||
MapFolder = mapFolder;
|
||||
|
||||
AdminList = Sets.newHashSet();
|
||||
_warps = Maps.newHashMap();
|
||||
_currentlyLive = false;
|
||||
|
||||
if ((new File(MapFolder + File.separator + "Map.dat")).exists())
|
||||
{
|
||||
Read();
|
||||
} else
|
||||
{
|
||||
Write();
|
||||
}
|
||||
}
|
||||
|
||||
public void Read()
|
||||
{
|
||||
String line = null;
|
||||
|
||||
try
|
||||
{
|
||||
FileInputStream fstream = new FileInputStream(MapFolder + File.separator + "Map.dat");
|
||||
DataInputStream in = new DataInputStream(fstream);
|
||||
BufferedReader br = new BufferedReader(new InputStreamReader(in));
|
||||
|
||||
while ((line = br.readLine()) != null)
|
||||
{
|
||||
String[] tokens = line.split(":");
|
||||
|
||||
if (tokens.length < 2)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (tokens[0].length() == 0)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
if (tokens[0].equalsIgnoreCase("MAP_AUTHOR"))
|
||||
{
|
||||
MapCreator = tokens[1];
|
||||
continue;
|
||||
}
|
||||
|
||||
if (tokens[0].equalsIgnoreCase("GAME_TYPE"))
|
||||
{
|
||||
try
|
||||
{
|
||||
MapGameType = GameType.valueOf(tokens[1] == null ? "Unknown" : tokens[1]);
|
||||
} catch (Exception e)
|
||||
{
|
||||
MapGameType = GameType.Unknown;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
if (tokens[0].equalsIgnoreCase("ADMIN_LIST") || tokens[0].equalsIgnoreCase("BUILD_LIST"))
|
||||
{
|
||||
Collections.addAll(AdminList, tokens[1].split(","));
|
||||
}
|
||||
}
|
||||
|
||||
in.close();
|
||||
} catch (Exception e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
System.err.println("Line: " + line);
|
||||
}
|
||||
}
|
||||
|
||||
public void Write()
|
||||
{
|
||||
//Save
|
||||
try
|
||||
{
|
||||
FileWriter fstream = new FileWriter(MapFolder + File.separator + "Map.dat");
|
||||
BufferedWriter out = new BufferedWriter(fstream);
|
||||
|
||||
out.write("MAP_NAME:" + MapName);
|
||||
out.write("\n");
|
||||
out.write("MAP_AUTHOR:" + MapCreator);
|
||||
out.write("\n");
|
||||
out.write("GAME_TYPE:" + MapGameType);
|
||||
|
||||
String adminList = "";
|
||||
|
||||
for (String cur : AdminList)
|
||||
{
|
||||
adminList += cur + ",";
|
||||
}
|
||||
|
||||
out.write("\n");
|
||||
out.write("ADMIN_LIST:" + adminList);
|
||||
out.write("\n");
|
||||
out.write("currentlyLive:" + _currentlyLive);
|
||||
out.write("\n");
|
||||
out.write("warps:" + warpsToString());
|
||||
out.write("\n");
|
||||
out.write("LOCKED:" + _locked);
|
||||
|
||||
out.close();
|
||||
} catch (Exception e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public String warpsToString()
|
||||
{
|
||||
StringBuilder builder = new StringBuilder();
|
||||
int i = 0;
|
||||
for (Entry<String, Location> entry : _warps.entrySet())
|
||||
{
|
||||
builder.append(entry.getKey()).append("@").append(UtilWorld.locToStr(entry.getValue()));
|
||||
if (++i != _warps.size())
|
||||
{
|
||||
builder.append(",");
|
||||
}
|
||||
}
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
public boolean HasAccess(Player player)
|
||||
{
|
||||
return AdminList.contains(player.getName()) || player.isOp();
|
||||
}
|
||||
|
||||
public boolean CanJoin(Player player)
|
||||
{
|
||||
return !_locked || (player.isOp() || AdminList.contains(player.getName()));
|
||||
}
|
||||
|
||||
public boolean CanRename(Player player)
|
||||
{
|
||||
return !_locked || (player.isOp() || AdminList.contains(player.getName()));
|
||||
}
|
||||
|
||||
public void sendInfo(Player player)
|
||||
{
|
||||
UtilPlayerBase.message(player, F.value("Map Name", MapName));
|
||||
UtilPlayerBase.message(player, F.value("Author", MapCreator));
|
||||
UtilPlayerBase.message(player, F.value("Game Type", MapGameType.GetName()));
|
||||
}
|
||||
}
|
@ -0,0 +1,474 @@
|
||||
package mineplex.mapparser;
|
||||
|
||||
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;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.WorldCreator;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
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.F;
|
||||
import mineplex.core.common.util.UtilBlockBase;
|
||||
import mineplex.core.common.util.UtilPlayerBase;
|
||||
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.CommandListCommand;
|
||||
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.FlySpeedCommand;
|
||||
import mineplex.mapparser.command.GameTypeCommand;
|
||||
import mineplex.mapparser.command.HubCommand;
|
||||
import mineplex.mapparser.command.GameTypeInfoCommand;
|
||||
import mineplex.mapparser.command.ItemNameCommand;
|
||||
import mineplex.mapparser.command.ListCommand;
|
||||
import mineplex.mapparser.command.LockCommand;
|
||||
import mineplex.mapparser.command.MapCommand;
|
||||
import mineplex.mapparser.command.MapInfoCommand;
|
||||
import mineplex.mapparser.command.NameCommand;
|
||||
import mineplex.mapparser.command.PMCommand;
|
||||
import mineplex.mapparser.command.ParseCommand;
|
||||
import mineplex.mapparser.command.ParseCommand200;
|
||||
import mineplex.mapparser.command.ParseCommand400;
|
||||
import mineplex.mapparser.command.ParseCommand600;
|
||||
import mineplex.mapparser.command.ParseCommand1000;
|
||||
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.TimeCommand;
|
||||
import mineplex.mapparser.command.WarpCommand;
|
||||
import mineplex.mapparser.command.WorldsCommand;
|
||||
import mineplex.mapparser.command.teleport.BackCommand;
|
||||
import mineplex.mapparser.command.teleport.TeleportCommand;
|
||||
import mineplex.mapparser.command.teleport.TeleportManager;
|
||||
import mineplex.mapparser.command.teleport.TopCommand;
|
||||
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;
|
||||
|
||||
public class MapParser extends JavaPlugin
|
||||
{
|
||||
private WorldManager _worldManager;
|
||||
|
||||
private Parse _curParse = null;
|
||||
private final Map<Class<? extends Module>, Module> _modules = Maps.newHashMap();
|
||||
private final Map<GameType, GameTypeInfo> _infoMap = Maps.newHashMap();
|
||||
private final Map<String, MapData> _mapData = Maps.newHashMap();
|
||||
public final Set<String> _mapsBeingZipped = Sets.newHashSet();
|
||||
private List<String> _additionalText = Lists.newArrayList();
|
||||
private Location _spawnLocation;
|
||||
private TeleportManager _teleportManager;
|
||||
|
||||
@Override
|
||||
public void onEnable()
|
||||
{
|
||||
_worldManager = new WorldManager(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);
|
||||
|
||||
_teleportManager = new TeleportManager(this);
|
||||
|
||||
new EventModule(this);
|
||||
new MMMazeModule(this);
|
||||
new SignModule(this);
|
||||
new TreeToolModule(this);
|
||||
|
||||
CommandModule commandModule = new CommandModule(this);
|
||||
|
||||
// Normal Commands
|
||||
commandModule.add(new AuthorCommand(this));
|
||||
commandModule.add(new AdminCommand(this));
|
||||
commandModule.add(new CopySchematicsCommand(this));
|
||||
commandModule.add(new DeleteCommand(this));
|
||||
commandModule.add(new GameTypeCommand(this));
|
||||
commandModule.add(new ListCommand(this));
|
||||
commandModule.add(new NameCommand(this));
|
||||
commandModule.add(new ParseCommand200(this));
|
||||
commandModule.add(new ParseCommand400(this));
|
||||
commandModule.add(new ParseCommand600(this));
|
||||
commandModule.add(new ParseCommand1000(this));
|
||||
commandModule.add(new RenameCommand(this));
|
||||
commandModule.add(new SaveCommand(this));
|
||||
commandModule.add(new WorldsCommand(this));
|
||||
commandModule.add(new CopyCommand(this));
|
||||
commandModule.add(new SetSpawnCommand(this));
|
||||
commandModule.add(new ItemNameCommand(this));
|
||||
commandModule.add(new AddLoreCommand(this));
|
||||
commandModule.add(new ClearLoreCommand(this));
|
||||
commandModule.add(new GameTypeInfoCommand(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));
|
||||
commandModule.add(new PMCommand(this));
|
||||
commandModule.add(new TimeCommand(this));
|
||||
commandModule.add(new MapInfoCommand(this));
|
||||
commandModule.add(new ParseCommand(this));
|
||||
commandModule.add(new FlySpeedCommand(this));
|
||||
commandModule.add(new CommandListCommand(this, commandModule));
|
||||
|
||||
// Teleport-related commands
|
||||
commandModule.add(new HubCommand(_teleportManager));
|
||||
commandModule.add(new CreateCommand(_teleportManager));
|
||||
commandModule.add(new MapCommand(_teleportManager));
|
||||
|
||||
commandModule.add(new TeleportCommand(_teleportManager));
|
||||
commandModule.add(new BackCommand(_teleportManager));
|
||||
commandModule.add(new TopCommand(_teleportManager));
|
||||
|
||||
commandModule.add(new SpawnCommand(_teleportManager));
|
||||
|
||||
loadInfo();
|
||||
addSplashText();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDisable()
|
||||
{
|
||||
_infoMap.values().forEach(this::saveInfo);
|
||||
saveSplashText();
|
||||
}
|
||||
|
||||
public Parse getCurParse()
|
||||
{
|
||||
return _curParse;
|
||||
}
|
||||
|
||||
public void sendValidGameTypes(Player player)
|
||||
{
|
||||
UtilPlayerBase.message(player, F.main("Parser", "Valid Game Types;"));
|
||||
|
||||
String gameTypes = "";
|
||||
|
||||
for (GameType game : GameType.values())
|
||||
{
|
||||
gameTypes += game.toString() + " ";
|
||||
}
|
||||
|
||||
player.sendMessage(gameTypes);
|
||||
}
|
||||
|
||||
public GameTypeInfo getInfo(GameType type)
|
||||
{
|
||||
return _infoMap.get(type);
|
||||
}
|
||||
|
||||
private void addSplashText()
|
||||
{
|
||||
File file = new File(getDataFolder(), "join-text.yml");
|
||||
if(!file.exists())
|
||||
{
|
||||
try
|
||||
{
|
||||
file.createNewFile();
|
||||
} catch (IOException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
FileConfiguration config = YamlConfiguration.loadConfiguration(file);
|
||||
List<String> messages = config.getStringList("messages");
|
||||
if(messages == null)
|
||||
{
|
||||
messages = Lists.newArrayList();
|
||||
}
|
||||
_additionalText = messages;
|
||||
}
|
||||
|
||||
private void saveSplashText()
|
||||
{
|
||||
File file = new File(getDataFolder(), "join-text.yml");
|
||||
if(!file.exists())
|
||||
{
|
||||
try
|
||||
{
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
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<String> 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 : Bukkit.getOnlinePlayers())
|
||||
{
|
||||
player.sendMessage(C.cGold + msg);
|
||||
}
|
||||
|
||||
System.out.println("[Announce] " + msg);
|
||||
}
|
||||
|
||||
public boolean doesMapExist(String mapName, GameType gameType)
|
||||
{
|
||||
return doesMapExist(getWorldString(mapName, gameType));
|
||||
}
|
||||
|
||||
public boolean doesMapExist(String worldName)
|
||||
{
|
||||
File file = new File(worldName);
|
||||
|
||||
return file.exists() && file.isDirectory();
|
||||
|
||||
}
|
||||
|
||||
public String getShortWorldName(String worldName)
|
||||
{
|
||||
int lastIndexOfSeperator = worldName.lastIndexOf('/');
|
||||
|
||||
if (lastIndexOfSeperator != -1)
|
||||
return worldName.substring(lastIndexOfSeperator + 1);
|
||||
|
||||
return worldName;
|
||||
}
|
||||
|
||||
public World getMapWorld(String worldName)
|
||||
{
|
||||
for (World world : this.getServer().getWorlds())
|
||||
{
|
||||
if (world.getName().equals(worldName))
|
||||
return world;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public String getWorldString(String mapName, GameType type)
|
||||
{
|
||||
return "map" + "/" + type.GetName() + "/" + mapName;
|
||||
}
|
||||
|
||||
public List<String> getMapsByName(String name)
|
||||
{
|
||||
name = name.toLowerCase();
|
||||
|
||||
List<String> maps = new LinkedList<>();
|
||||
boolean matchesExact = false;
|
||||
|
||||
for (GameType type : GameType.values())
|
||||
{
|
||||
|
||||
File mapsFolder = new File("map" + File.separator + type.GetName());
|
||||
if (!mapsFolder.exists() || mapsFolder.listFiles() == null)
|
||||
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;
|
||||
}
|
||||
|
||||
public MapData getData(String mapName)
|
||||
{
|
||||
if (_mapData.containsKey(mapName))
|
||||
return _mapData.get(mapName);
|
||||
|
||||
MapData data = new MapData(mapName);
|
||||
|
||||
_mapData.put(mapName, data);
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
public Location getSpawnLocation()
|
||||
{
|
||||
return _spawnLocation;
|
||||
}
|
||||
|
||||
public WorldManager getWorldManager()
|
||||
{
|
||||
return _worldManager;
|
||||
}
|
||||
|
||||
public void setCurrentParse(Parse parse)
|
||||
{
|
||||
_curParse = parse;
|
||||
}
|
||||
|
||||
public Set<String> getMapsBeingZipped()
|
||||
{
|
||||
return _mapsBeingZipped;
|
||||
}
|
||||
|
||||
public Set<Block> searchLog(Set<Block> blocks, Block current)
|
||||
{
|
||||
//Not Tree
|
||||
if (current.getType() != Material.LOG && current.getType() != Material.LEAVES)
|
||||
return blocks;
|
||||
|
||||
if (!blocks.add(current))
|
||||
return blocks;
|
||||
|
||||
for (Block other : UtilBlockBase.getSurrounding(current, true))
|
||||
{
|
||||
if (current.getType() != Material.LOG && current.getType() != Material.LEAVES)
|
||||
continue;
|
||||
|
||||
if (blocks.contains(other))
|
||||
continue;
|
||||
|
||||
//Dont spread from leaves to log
|
||||
if (current.getType() == Material.LEAVES && other.getType() == Material.LOG)
|
||||
continue;
|
||||
|
||||
searchLog(blocks, other);
|
||||
}
|
||||
|
||||
return blocks;
|
||||
}
|
||||
|
||||
public Map<Class<? extends Module>, Module> getModules()
|
||||
{
|
||||
return _modules;
|
||||
}
|
||||
|
||||
public void setInfo(GameType gameType, GameTypeInfo info)
|
||||
{
|
||||
_infoMap.put(gameType, info);
|
||||
}
|
||||
|
||||
public List<String> getAdditionalText()
|
||||
{
|
||||
return _additionalText;
|
||||
}
|
||||
|
||||
public void addAdditionalText(String s)
|
||||
{
|
||||
_additionalText.add(s);
|
||||
}
|
||||
|
||||
public World getWorldFromName(String worldName)
|
||||
{
|
||||
World world = getMapWorld(worldName);
|
||||
if (world == null)
|
||||
{
|
||||
if (doesMapExist(worldName))
|
||||
{
|
||||
world = Bukkit.createWorld(new WorldCreator(worldName));
|
||||
}
|
||||
else
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
return world;
|
||||
}
|
||||
}
|
@ -0,0 +1,537 @@
|
||||
package mineplex.mapparser;
|
||||
|
||||
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;
|
||||
import org.bukkit.block.Block;
|
||||
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
|
||||
private MapParser Host;
|
||||
private World _world;
|
||||
private String[] _args;
|
||||
private Location _callLoc;
|
||||
|
||||
private int _size = 600;
|
||||
private int _x = 0;
|
||||
private int _y = 0;
|
||||
private int _z = 0;
|
||||
|
||||
//Map Data
|
||||
private MapData _mapData;
|
||||
|
||||
//World Data
|
||||
private HashSet<Integer> _dataId = new HashSet<Integer>();
|
||||
private HashMap<String, ArrayList<Location>> _teamLocs = new HashMap<String, ArrayList<Location>>();
|
||||
private HashMap<String, ArrayList<Location>> _dataLocs = new HashMap<String, ArrayList<Location>>();
|
||||
private HashMap<String, ArrayList<Location>> _customLocs = new HashMap<String, ArrayList<Location>>();
|
||||
|
||||
private Location _cornerA = null;
|
||||
private Location _cornerB = null;
|
||||
|
||||
private int _processed = 0;
|
||||
|
||||
public Parse(MapParser host, World world, String[] args, Location loc, MapData data, int size)
|
||||
{
|
||||
Host = host;
|
||||
|
||||
_world = world;
|
||||
_args = args;
|
||||
_callLoc = new Location(world, loc.getX(), loc.getY(), loc.getZ());
|
||||
|
||||
_mapData = data;
|
||||
|
||||
_size = size;
|
||||
|
||||
for (String arg : args)
|
||||
Host.announce("Parse Arg: " + F.elem(arg));
|
||||
|
||||
Initialize();
|
||||
}
|
||||
|
||||
private void Initialize()
|
||||
{
|
||||
Host.announce("Commencing Parse of World: " + F.elem(_world.getName()));
|
||||
|
||||
//Take BlockID Arguments
|
||||
for (String arg : _args)
|
||||
{
|
||||
try
|
||||
{
|
||||
_dataId.add(Integer.parseInt(arg));
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Host.announce("Invalid Data ID: " + F.elem(arg));
|
||||
}
|
||||
}
|
||||
|
||||
_x = -_size;
|
||||
_z = -_size;
|
||||
_y = 0;
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public boolean Update()
|
||||
{
|
||||
long startTime = System.currentTimeMillis();
|
||||
|
||||
for ( ; _x <= _size ; _x++)
|
||||
{
|
||||
for ( ; _z <= _size ; _z++)
|
||||
{
|
||||
for ( ; _y <= 256 ; _y++)
|
||||
{
|
||||
if (UtilTime.elapsed(startTime, 10))
|
||||
return false;
|
||||
|
||||
_processed++;
|
||||
if (_processed % 10000000 == 0)
|
||||
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);
|
||||
|
||||
//ID DATA
|
||||
if (_dataId.contains(block.getTypeId()))
|
||||
{
|
||||
String key = ""+block.getTypeId();
|
||||
|
||||
if (!_customLocs.containsKey(key))
|
||||
_customLocs.put(key, new ArrayList<Location>());
|
||||
|
||||
_customLocs.get(key).add(block.getLocation());
|
||||
continue;
|
||||
}
|
||||
|
||||
//Signs
|
||||
if (block.getType() == Material.SIGN_POST || block.getType() == Material.WALL_SIGN)
|
||||
{
|
||||
if (block.getRelative(BlockFace.DOWN).getType() == Material.SPONGE)
|
||||
{
|
||||
Sign s = (Sign) block.getState();
|
||||
|
||||
String name = "";
|
||||
|
||||
try
|
||||
{
|
||||
name = s.getLine(0);
|
||||
|
||||
if (s.getLine(1) != null && s.getLine(1).length() > 0)
|
||||
name += " " + s.getLine(1);
|
||||
|
||||
if (s.getLine(2) != null && s.getLine(2).length() > 0)
|
||||
name += " " + s.getLine(2);
|
||||
|
||||
if (s.getLine(3) != null && s.getLine(3).length() > 0)
|
||||
name += " " + s.getLine(3);
|
||||
|
||||
System.out.println("Custom Location: " + name);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Host.announce("Invalid Sign Data: " + UtilWorld.locToStr(block.getLocation()));
|
||||
}
|
||||
|
||||
//Add
|
||||
if (!_customLocs.containsKey(name))
|
||||
_customLocs.put(name, new ArrayList<Location>());
|
||||
|
||||
_customLocs.get(name).add(block.getRelative(BlockFace.DOWN).getLocation());
|
||||
|
||||
//Remove Blocks
|
||||
block.setTypeId(0);
|
||||
block.getRelative(BlockFace.DOWN).setTypeId(0);
|
||||
}
|
||||
}
|
||||
else if (block.getType() == Material.LEAVES || block.getType() == Material.LEAVES_2)
|
||||
{
|
||||
if (block.getData() <= 3)
|
||||
{
|
||||
// https://minecraft.gamepedia.com/Java_Edition_data_values#Leaves
|
||||
// For leaves, you add 4 to get the no decay version
|
||||
block.setData((byte) ((int)block.getData() + 4));
|
||||
}
|
||||
}
|
||||
|
||||
//Spawns + Borders
|
||||
if (block.getTypeId() == 147)
|
||||
{
|
||||
Block wool = block.getRelative(BlockFace.DOWN);
|
||||
if (wool == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
if (wool.getType() == Material.WOOL)
|
||||
{
|
||||
if (wool.getData() == 0)
|
||||
{
|
||||
if (_cornerA == null)
|
||||
{
|
||||
_cornerA = wool.getLocation();
|
||||
Host.announce("Corner A: " + UtilWorld.locToStrClean(_cornerA));
|
||||
}
|
||||
|
||||
else if (_cornerB == null)
|
||||
{
|
||||
_cornerB = wool.getLocation();
|
||||
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()));
|
||||
}
|
||||
|
||||
//Remove Blocks
|
||||
block.setTypeId(0);
|
||||
wool.setTypeId(0);
|
||||
}
|
||||
|
||||
if (wool.getData() == 1)
|
||||
{
|
||||
if (!_teamLocs.containsKey("Orange"))
|
||||
_teamLocs.put("Orange", new ArrayList<Location>());
|
||||
|
||||
_teamLocs.get("Orange").add(wool.getLocation());
|
||||
|
||||
//Remove Blocks
|
||||
block.setTypeId(0);
|
||||
wool.setTypeId(0);
|
||||
}
|
||||
|
||||
if (wool.getData() == 2)
|
||||
{
|
||||
if (!_teamLocs.containsKey("Magenta"))
|
||||
_teamLocs.put("Magenta", new ArrayList<Location>());
|
||||
|
||||
_teamLocs.get("Magenta").add(wool.getLocation());
|
||||
|
||||
//Remove Blocks
|
||||
block.setTypeId(0);
|
||||
wool.setTypeId(0);
|
||||
}
|
||||
|
||||
if (wool.getData() == 3)
|
||||
{
|
||||
if (!_teamLocs.containsKey("Sky"))
|
||||
_teamLocs.put("Sky", new ArrayList<Location>());
|
||||
|
||||
_teamLocs.get("Sky").add(wool.getLocation());
|
||||
|
||||
//Remove Blocks
|
||||
block.setTypeId(0);
|
||||
wool.setTypeId(0);
|
||||
}
|
||||
|
||||
if (wool.getData() == 4)
|
||||
{
|
||||
if (!_teamLocs.containsKey("Yellow"))
|
||||
_teamLocs.put("Yellow", new ArrayList<Location>());
|
||||
|
||||
_teamLocs.get("Yellow").add(wool.getLocation());
|
||||
|
||||
//Remove Blocks
|
||||
block.setTypeId(0);
|
||||
wool.setTypeId(0);
|
||||
}
|
||||
|
||||
if (wool.getData() == 5)
|
||||
{
|
||||
if (!_teamLocs.containsKey("Lime"))
|
||||
_teamLocs.put("Lime", new ArrayList<Location>());
|
||||
|
||||
_teamLocs.get("Lime").add(wool.getLocation());
|
||||
|
||||
//Remove Blocks
|
||||
block.setTypeId(0);
|
||||
wool.setTypeId(0);
|
||||
}
|
||||
|
||||
if (wool.getData() == 6)
|
||||
{
|
||||
if (!_teamLocs.containsKey("Pink"))
|
||||
_teamLocs.put("Pink", new ArrayList<Location>());
|
||||
|
||||
_teamLocs.get("Pink").add(wool.getLocation());
|
||||
|
||||
//Remove Blocks
|
||||
block.setTypeId(0);
|
||||
wool.setTypeId(0);
|
||||
}
|
||||
|
||||
if (wool.getData() == 7)
|
||||
{
|
||||
if (!_teamLocs.containsKey("Gray"))
|
||||
_teamLocs.put("Gray", new ArrayList<Location>());
|
||||
|
||||
_teamLocs.get("Gray").add(wool.getLocation());
|
||||
|
||||
//Remove Blocks
|
||||
block.setTypeId(0);
|
||||
wool.setTypeId(0);
|
||||
}
|
||||
|
||||
if (wool.getData() == 8)
|
||||
{
|
||||
if (!_teamLocs.containsKey("LGray"))
|
||||
_teamLocs.put("LGray", new ArrayList<Location>());
|
||||
|
||||
_teamLocs.get("LGray").add(wool.getLocation());
|
||||
|
||||
//Remove Blocks
|
||||
block.setTypeId(0);
|
||||
wool.setTypeId(0);
|
||||
}
|
||||
|
||||
if (wool.getData() == 9)
|
||||
{
|
||||
if (!_teamLocs.containsKey("Cyan"))
|
||||
_teamLocs.put("Cyan", new ArrayList<Location>());
|
||||
|
||||
_teamLocs.get("Cyan").add(wool.getLocation());
|
||||
|
||||
//Remove Blocks
|
||||
block.setTypeId(0);
|
||||
wool.setTypeId(0);
|
||||
}
|
||||
|
||||
if (wool.getData() == 10)
|
||||
{
|
||||
if (!_teamLocs.containsKey("Purple"))
|
||||
_teamLocs.put("Purple", new ArrayList<Location>());
|
||||
|
||||
_teamLocs.get("Purple").add(wool.getLocation());
|
||||
|
||||
//Remove Blocks
|
||||
block.setTypeId(0);
|
||||
wool.setTypeId(0);
|
||||
}
|
||||
|
||||
if (wool.getData() == 11)
|
||||
{
|
||||
if (!_teamLocs.containsKey("Blue"))
|
||||
_teamLocs.put("Blue", new ArrayList<Location>());
|
||||
|
||||
_teamLocs.get("Blue").add(wool.getLocation());
|
||||
|
||||
//Remove Blocks
|
||||
block.setTypeId(0);
|
||||
wool.setTypeId(0);
|
||||
}
|
||||
|
||||
if (wool.getData() == 12)
|
||||
{
|
||||
if (!_teamLocs.containsKey("Brown"))
|
||||
_teamLocs.put("Brown", new ArrayList<Location>());
|
||||
|
||||
_teamLocs.get("Brown").add(wool.getLocation());
|
||||
|
||||
//Remove Blocks
|
||||
block.setTypeId(0);
|
||||
wool.setTypeId(0);
|
||||
}
|
||||
|
||||
if (wool.getData() == 13)
|
||||
{
|
||||
if (!_teamLocs.containsKey("Green"))
|
||||
_teamLocs.put("Green", new ArrayList<Location>());
|
||||
|
||||
_teamLocs.get("Green").add(wool.getLocation());
|
||||
|
||||
//Remove Blocks
|
||||
block.setTypeId(0);
|
||||
wool.setTypeId(0);
|
||||
}
|
||||
|
||||
if (wool.getData() == 14)
|
||||
{
|
||||
if (!_teamLocs.containsKey("Red"))
|
||||
_teamLocs.put("Red", new ArrayList<Location>());
|
||||
|
||||
_teamLocs.get("Red").add(wool.getLocation());
|
||||
|
||||
//Remove Blocks
|
||||
block.setTypeId(0);
|
||||
wool.setTypeId(0);
|
||||
}
|
||||
|
||||
if (wool.getData() == 15)
|
||||
{
|
||||
if (!_teamLocs.containsKey("Black"))
|
||||
_teamLocs.put("Black", new ArrayList<Location>());
|
||||
|
||||
_teamLocs.get("Black").add(wool.getLocation());
|
||||
|
||||
//Remove Blocks
|
||||
block.setTypeId(0);
|
||||
wool.setTypeId(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (block.getTypeId() != 148)
|
||||
continue;
|
||||
|
||||
Block wool = block.getRelative(BlockFace.DOWN);
|
||||
if (wool == null)
|
||||
continue;
|
||||
|
||||
if (wool.getType() != Material.WOOL)
|
||||
continue;
|
||||
|
||||
Wool woolData = new Wool(wool.getType(), wool.getData());
|
||||
|
||||
String dataType = woolData.getColor().name();
|
||||
|
||||
if (!_dataLocs.containsKey(dataType))
|
||||
_dataLocs.put(dataType, new ArrayList<Location>());
|
||||
|
||||
_dataLocs.get(dataType).add(wool.getLocation());
|
||||
|
||||
//Remove Blocks
|
||||
block.setTypeId(0);
|
||||
wool.setTypeId(0);
|
||||
}
|
||||
|
||||
_y = 0;
|
||||
}
|
||||
|
||||
_z = -_size;
|
||||
}
|
||||
|
||||
//Finalize
|
||||
|
||||
if (_cornerA == null || _cornerB == null)
|
||||
{
|
||||
Host.announce("Missing Corner Locations! Defaulted to -256 to +256.");
|
||||
|
||||
_cornerA = new Location(_world, -256, 0, -256);
|
||||
_cornerB = new Location(_world, 256, 0, 256);
|
||||
}
|
||||
|
||||
//Save
|
||||
try
|
||||
{
|
||||
FileWriter fstream = new FileWriter(_world.getName() + File.separator + "WorldConfig.dat");
|
||||
BufferedWriter out = new BufferedWriter(fstream);
|
||||
|
||||
out.write("MAP_NAME:"+_mapData.MapName);
|
||||
out.write("\n");
|
||||
out.write("MAP_AUTHOR:"+_mapData.MapCreator);
|
||||
out.write("\n");
|
||||
out.write("\n");
|
||||
out.write("MIN_X:"+Math.min(_cornerA.getBlockX(), _cornerB.getBlockX()));
|
||||
out.write("\n");
|
||||
out.write("MAX_X:"+Math.max(_cornerA.getBlockX(), _cornerB.getBlockX()));
|
||||
out.write("\n");
|
||||
out.write("MIN_Z:"+Math.min(_cornerA.getBlockZ(), _cornerB.getBlockZ()));
|
||||
out.write("\n");
|
||||
out.write("MAX_Z:"+Math.max(_cornerA.getBlockZ(), _cornerB.getBlockZ()));
|
||||
out.write("\n");
|
||||
out.write("\n");
|
||||
if (_cornerA.getBlockY() == _cornerB.getBlockY())
|
||||
{
|
||||
out.write("MIN_Y:0");
|
||||
out.write("\n");
|
||||
out.write("MAX_Y:256");
|
||||
}
|
||||
else
|
||||
{
|
||||
out.write("MIN_Y:"+Math.min(_cornerA.getBlockY(), _cornerB.getBlockY()));
|
||||
out.write("\n");
|
||||
out.write("MAX_Y:"+Math.max(_cornerA.getBlockY(), _cornerB.getBlockY()));
|
||||
}
|
||||
|
||||
//Teams
|
||||
for (String team : _teamLocs.keySet())
|
||||
{
|
||||
out.write("\n");
|
||||
out.write("\n");
|
||||
out.write("TEAM_NAME:" + team);
|
||||
out.write("\n");
|
||||
out.write("TEAM_SPAWNS:" + LocationsToString(_teamLocs.get(team)));
|
||||
}
|
||||
|
||||
//Data
|
||||
for (String data : _dataLocs.keySet())
|
||||
{
|
||||
out.write("\n");
|
||||
out.write("\n");
|
||||
out.write("DATA_NAME:" + data);
|
||||
out.write("\n");
|
||||
out.write("DATA_LOCS:" + LocationsToString(_dataLocs.get(data)));
|
||||
}
|
||||
|
||||
//Custom
|
||||
for (String data : _customLocs.keySet())
|
||||
{
|
||||
out.write("\n");
|
||||
out.write("\n");
|
||||
out.write("CUSTOM_NAME:" + data);
|
||||
out.write("\n");
|
||||
out.write("CUSTOM_LOCS:" + LocationsToString(_customLocs.get(data)));
|
||||
}
|
||||
|
||||
out.close();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Host.announce("Error: File Write Error");
|
||||
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
Host.announce("WorldConfig.dat Saved.");
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public String LocationsToString(ArrayList<Location> locs)
|
||||
{
|
||||
String out = "";
|
||||
|
||||
for (Location loc : locs)
|
||||
out += loc.getBlockX() + "," + loc.getBlockY() + "," + loc.getBlockZ() + ":";
|
||||
|
||||
return out;
|
||||
}
|
||||
|
||||
public String LocationSignsToString(HashMap<Location, String> locs)
|
||||
{
|
||||
String out = "";
|
||||
|
||||
for (Location loc : locs.keySet())
|
||||
out += locs.get(loc) + "@" + loc.getBlockX() + "," + loc.getBlockY() + "," + loc.getBlockZ() + ":";
|
||||
|
||||
return out;
|
||||
}
|
||||
|
||||
public GameType getGameType()
|
||||
{
|
||||
return _mapData.MapGameType;
|
||||
}
|
||||
|
||||
public World getWorld()
|
||||
{
|
||||
return _world;
|
||||
}
|
||||
}
|
@ -0,0 +1,19 @@
|
||||
package mineplex.mapparser;
|
||||
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.HandlerList;
|
||||
|
||||
public class TickEvent extends Event
|
||||
{
|
||||
private static final HandlerList handlers = new HandlerList();
|
||||
|
||||
public HandlerList getHandlers()
|
||||
{
|
||||
return handlers;
|
||||
}
|
||||
|
||||
public static HandlerList getHandlerList()
|
||||
{
|
||||
return handlers;
|
||||
}
|
||||
}
|
@ -0,0 +1,20 @@
|
||||
package mineplex.mapparser;
|
||||
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
public class Ticker implements Runnable
|
||||
{
|
||||
private JavaPlugin _plugin;
|
||||
|
||||
public Ticker(JavaPlugin plugin)
|
||||
{
|
||||
_plugin = plugin;
|
||||
_plugin.getServer().getScheduler().scheduleSyncRepeatingTask(_plugin, this, 0L, 1L);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
_plugin.getServer().getPluginManager().callEvent(new TickEvent());
|
||||
}
|
||||
}
|
@ -0,0 +1,121 @@
|
||||
package mineplex.mapparser;
|
||||
|
||||
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;
|
||||
|
||||
public class WorldManager
|
||||
{
|
||||
private MapParser Host;
|
||||
|
||||
public WorldManager(MapParser plugin)
|
||||
{
|
||||
Host = plugin;
|
||||
}
|
||||
|
||||
public World prepMapParse(World world)
|
||||
{
|
||||
//Unload World
|
||||
Host.getServer().unloadWorld(world, true);
|
||||
|
||||
//Delete Non-Map Files
|
||||
String[] folders = new File(world.getName()).list();
|
||||
for (String fileName : folders)
|
||||
{
|
||||
if (fileName.equalsIgnoreCase("level.dat"))
|
||||
continue;
|
||||
|
||||
if (fileName.equalsIgnoreCase("region"))
|
||||
continue;
|
||||
|
||||
if (fileName.equalsIgnoreCase("WorldConfig.dat"))
|
||||
continue;
|
||||
|
||||
if (fileName.equalsIgnoreCase("Map.dat"))
|
||||
continue;
|
||||
|
||||
FileUtils.deleteQuietly(new File(world.getName() + File.separator + fileName));
|
||||
}
|
||||
|
||||
//Copy for Parsing
|
||||
|
||||
String parseWorldName = "parse" + world.getName().replaceFirst("map", "");
|
||||
|
||||
try
|
||||
{
|
||||
//Delete if already exists
|
||||
File destination = new File(parseWorldName);
|
||||
if (destination.exists())
|
||||
FileUtils.deleteDirectory(destination);
|
||||
|
||||
FileUtils.copyDirectory(new File(world.getName()), destination);
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
|
||||
return Bukkit.createWorld(new WorldCreator(parseWorldName));
|
||||
}
|
||||
|
||||
public void finalizeParsedWorld(World world)
|
||||
{
|
||||
Host.getServer().unloadWorld(world, true);
|
||||
|
||||
ArrayList<String> fileList = new ArrayList<String>();
|
||||
ArrayList<String> dirList = new ArrayList<String>();
|
||||
|
||||
File[] files = new File(world.getName()).listFiles();
|
||||
for (File file : files)
|
||||
{
|
||||
if (file.getName().equalsIgnoreCase("level.dat"))
|
||||
{
|
||||
fileList.add(world.getName() + File.separator + file.getName());
|
||||
continue;
|
||||
}
|
||||
|
||||
if (file.getName().equalsIgnoreCase("region"))
|
||||
{
|
||||
dirList.add(world.getName() + File.separator + file.getName());
|
||||
continue;
|
||||
}
|
||||
|
||||
if (file.getName().equalsIgnoreCase("WorldConfig.dat"))
|
||||
{
|
||||
fileList.add(world.getName() + File.separator + file.getName());
|
||||
continue;
|
||||
}
|
||||
|
||||
FileUtils.deleteQuietly(new File(world.getName() + File.separator + file.getName()));
|
||||
}
|
||||
|
||||
MapData data = Host.getData(world.getName().replace("parse", "map"));
|
||||
GameType gameType = data.MapGameType;
|
||||
String fileName = gameType + "_" + data.MapName + ".zip";
|
||||
|
||||
ZipUtil.ZipFolders(Paths.get(world.getName()).toAbsolutePath().toString(), fileName, dirList, fileList);
|
||||
|
||||
try
|
||||
{
|
||||
File zipFile = new File(fileName);
|
||||
FileUtils.copyFile(zipFile, new File(File.separator + "home" + File.separator + "mineplex" + File.separator + "update" + File.separator + "maps" + File.separator + gameType.GetName() + File.separator + fileName));
|
||||
// Delete the zip file in root directory once zip is copied
|
||||
FileUtils.deleteQuietly(zipFile);
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
//Delete Parse Map
|
||||
FileUtils.deleteQuietly(new File(world.getName()));
|
||||
}
|
||||
}
|
@ -0,0 +1,58 @@
|
||||
package mineplex.mapparser.command;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
|
||||
import mineplex.core.common.util.F;
|
||||
import mineplex.mapparser.MapParser;
|
||||
|
||||
public class AddLoreCommand extends BaseCommand
|
||||
{
|
||||
public AddLoreCommand(MapParser plugin)
|
||||
{
|
||||
super(plugin, "addlore", "al");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(Player player, String alias, String[] args)
|
||||
{
|
||||
if (args == null || args.length < 1)
|
||||
{
|
||||
message(player, "Invalid Usage: " + F.elem("/" + alias + " <text>"));
|
||||
return true;
|
||||
}
|
||||
|
||||
ItemStack is = player.getItemInHand();
|
||||
|
||||
if (is == null || is.getType() == Material.AIR)
|
||||
{
|
||||
message(player, "You must be holding an item in your hand.");
|
||||
return true;
|
||||
}
|
||||
|
||||
ItemMeta im = is.getItemMeta();
|
||||
|
||||
StringBuilder line = new StringBuilder();
|
||||
for (String arg : args)
|
||||
{
|
||||
line.append(arg).append(" ");
|
||||
}
|
||||
line = new StringBuilder(line.toString().replaceAll("&", "§").trim());
|
||||
|
||||
List<String> lore = (im.getLore() != null ? new ArrayList<>(im.getLore()) : new ArrayList<>());
|
||||
lore.add(line.toString());
|
||||
im.setLore(lore);
|
||||
is.setItemMeta(im);
|
||||
|
||||
player.setItemInHand(is);
|
||||
player.updateInventory();
|
||||
message(player, "Added lore: " + line);
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
@ -0,0 +1,53 @@
|
||||
package mineplex.mapparser.command;
|
||||
|
||||
import mineplex.core.common.util.C;
|
||||
import mineplex.core.common.util.F;
|
||||
import mineplex.mapparser.MapParser;
|
||||
import net.md_5.bungee.api.ChatColor;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public class AddSplashTextCommand extends OpCommand
|
||||
{
|
||||
|
||||
public AddSplashTextCommand(MapParser plugin)
|
||||
{
|
||||
super(plugin, "addtext");
|
||||
setUsage("/addText <text>");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(Player player, String alias, String[] args)
|
||||
{
|
||||
if(args.length == 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if(args[0].equalsIgnoreCase("clear"))
|
||||
{
|
||||
getPlugin().getAdditionalText().clear();
|
||||
player.sendMessage(F.main(getPlugin().getName(), "Cleared all splash 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(F.main(getPlugin().getName(), "Added splash text: "));
|
||||
player.sendMessage(F.main("", ChatColor.translateAlternateColorCodes('&', builder.toString())));
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
@ -0,0 +1,66 @@
|
||||
package mineplex.mapparser.command;
|
||||
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import mineplex.core.common.util.F;
|
||||
import mineplex.core.common.util.UtilPlayerBase;
|
||||
import mineplex.mapparser.MapData;
|
||||
import mineplex.mapparser.MapParser;
|
||||
|
||||
/**
|
||||
* Created by Shaun on 8/16/2014.
|
||||
*/
|
||||
public class AdminCommand extends MapAdminCommand
|
||||
{
|
||||
public AdminCommand(MapParser plugin)
|
||||
{
|
||||
super(plugin, "admin");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(Player player, String alias, String[] args)
|
||||
{
|
||||
if (args.length != 1)
|
||||
{
|
||||
message(player, "Invalid Input. " + F.elem("/admin <Name>"));
|
||||
return true;
|
||||
}
|
||||
|
||||
World world = player.getWorld();
|
||||
|
||||
if (world.getName().equals("world_lobby"))
|
||||
{
|
||||
message(player, "Cannot change Admin-List for Lobby.");
|
||||
return true;
|
||||
}
|
||||
|
||||
Player other = UtilPlayerBase.searchOnline(player, args[0], true);
|
||||
|
||||
if (other != null)
|
||||
{
|
||||
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) + ")");
|
||||
}
|
||||
else
|
||||
{
|
||||
data.AdminList.add(other.getName());
|
||||
data.Write();
|
||||
|
||||
getPlugin().announce("Admin-List for " + F.elem(world.getName()) + " (" + other.getName() + " = " + F.tf(true) + ")");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
player.sendMessage(F.main(getPlugin().getName(), "That player is not online."));
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
@ -0,0 +1,51 @@
|
||||
package mineplex.mapparser.command;
|
||||
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import mineplex.core.common.util.F;
|
||||
import mineplex.mapparser.MapData;
|
||||
import mineplex.mapparser.MapParser;
|
||||
|
||||
/**
|
||||
* Created by Shaun on 8/15/2014.
|
||||
*/
|
||||
public class AuthorCommand extends MapAdminCommand
|
||||
{
|
||||
public AuthorCommand(MapParser plugin)
|
||||
{
|
||||
super(plugin, "author");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(Player player, String alias, String[] args)
|
||||
{
|
||||
World world = player.getWorld();
|
||||
|
||||
if (args.length < 1)
|
||||
{
|
||||
message(player, "Invalid Input. " + F.elem("/author <MapAuthor>"));
|
||||
return true;
|
||||
}
|
||||
|
||||
StringBuilder authorName = new StringBuilder();
|
||||
for (String arg : args)
|
||||
authorName.append(arg).append(" ");
|
||||
authorName = new StringBuilder(authorName.toString().trim());
|
||||
|
||||
if (world.getName().equals("world_lobby"))
|
||||
{
|
||||
message(player, "Cannot set author for Lobby.");
|
||||
return true;
|
||||
}
|
||||
|
||||
MapData data = getPlugin().getData(world.getName());
|
||||
|
||||
data.MapCreator = authorName.toString();
|
||||
data.Write();
|
||||
|
||||
getPlugin().announce("Map Author for " + F.elem(world.getName()) + " set to " + F.elem(authorName.toString()) + ".");
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
@ -0,0 +1,69 @@
|
||||
package mineplex.mapparser.command;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import mineplex.core.common.util.F;
|
||||
import mineplex.core.common.util.UtilPlayerBase;
|
||||
import mineplex.mapparser.MapParser;
|
||||
|
||||
/**
|
||||
* Created by Shaun on 8/15/2014.
|
||||
*/
|
||||
public abstract class BaseCommand
|
||||
{
|
||||
private MapParser _plugin;
|
||||
private List<String> _aliases;
|
||||
private String _description = null;
|
||||
private String _usage = null;
|
||||
|
||||
public BaseCommand(MapParser plugin, String... aliases)
|
||||
{
|
||||
_plugin = plugin;
|
||||
_aliases = Arrays.asList(aliases);
|
||||
}
|
||||
|
||||
public boolean canRun(Player player)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public abstract boolean execute(Player player, String alias, String[] args);
|
||||
|
||||
public String getDescription()
|
||||
{
|
||||
return _description;
|
||||
}
|
||||
|
||||
protected void setDescription(String description)
|
||||
{
|
||||
_description = description;
|
||||
}
|
||||
|
||||
public String getUsage()
|
||||
{
|
||||
return _usage;
|
||||
}
|
||||
|
||||
protected void setUsage(String usage)
|
||||
{
|
||||
_usage = usage;
|
||||
}
|
||||
|
||||
public List<String> getAliases()
|
||||
{
|
||||
return _aliases;
|
||||
}
|
||||
|
||||
protected MapParser getPlugin()
|
||||
{
|
||||
return _plugin;
|
||||
}
|
||||
|
||||
protected void message(Player player, String message)
|
||||
{
|
||||
UtilPlayerBase.message(player, F.main("Parser", message));
|
||||
}
|
||||
}
|
@ -0,0 +1,40 @@
|
||||
package mineplex.mapparser.command;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
|
||||
import mineplex.mapparser.MapParser;
|
||||
|
||||
public class ClearLoreCommand extends BaseCommand
|
||||
{
|
||||
public ClearLoreCommand(MapParser plugin)
|
||||
{
|
||||
super(plugin, "clearlore", "cl");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(Player player, String alias, String[] args)
|
||||
{
|
||||
ItemStack is = player.getItemInHand();
|
||||
|
||||
if (is == null || is.getType() == Material.AIR)
|
||||
{
|
||||
message(player, "You must be holding an item in your hand.");
|
||||
return true;
|
||||
}
|
||||
|
||||
ItemMeta im = is.getItemMeta();
|
||||
im.setLore(new ArrayList<>());
|
||||
is.setItemMeta(im);
|
||||
|
||||
player.setItemInHand(is);
|
||||
player.updateInventory();
|
||||
message(player, "Cleared lore on item!");
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
@ -0,0 +1,73 @@
|
||||
package mineplex.mapparser.command;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import mineplex.core.common.util.C;
|
||||
import mineplex.core.common.util.F;
|
||||
import mineplex.mapparser.MapParser;
|
||||
import mineplex.mapparser.module.modules.CommandModule;
|
||||
|
||||
public class CommandListCommand extends BaseCommand
|
||||
{
|
||||
private final static String MESSAGE_PREFIX = C.cGray + "• ";
|
||||
private CommandModule _commandModule;
|
||||
|
||||
public CommandListCommand(MapParser plugin, CommandModule commandModule)
|
||||
{
|
||||
super(plugin, "commands");
|
||||
|
||||
_commandModule = commandModule;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(Player player, String alias, String[] args)
|
||||
{
|
||||
player.sendMessage(F.main(getPlugin().getName(), "Commands list:"));
|
||||
player.sendMessage("");
|
||||
player.sendMessage(C.cPurple + C.Italics + "Some of these commands may require OP/Map Admin");
|
||||
player.sendMessage("");
|
||||
|
||||
List<String> commandsWithoutInformation = new ArrayList<>();
|
||||
List<String> commandsWithInformation = new ArrayList<>();
|
||||
|
||||
for (Map.Entry<String, BaseCommand> entry : _commandModule.getCommands().entrySet())
|
||||
{
|
||||
BaseCommand command = entry.getValue();
|
||||
|
||||
if (command.getUsage() != null || command.getDescription() != null)
|
||||
{
|
||||
String commandText = command.getUsage() == null ? entry.getKey() : command.getUsage();
|
||||
|
||||
String message = MESSAGE_PREFIX + C.cYellow + commandText;
|
||||
|
||||
if (command.getDescription() != null)
|
||||
{
|
||||
message += C.cGray + " - " + C.cGold + C.Italics + command.getDescription();
|
||||
}
|
||||
|
||||
commandsWithInformation.add(message);
|
||||
}
|
||||
else
|
||||
{
|
||||
commandsWithoutInformation.add("/" + entry.getKey());
|
||||
}
|
||||
}
|
||||
|
||||
if (commandsWithoutInformation.size() > 0)
|
||||
{
|
||||
player.sendMessage(MESSAGE_PREFIX + commandsWithoutInformation.stream().map(c -> C.cAqua + c).collect(Collectors.joining(C.cGray + ", ")));
|
||||
}
|
||||
|
||||
if (commandsWithInformation.size() > 0)
|
||||
{
|
||||
player.sendMessage(commandsWithInformation.toArray(new String[0]));
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
@ -0,0 +1,93 @@
|
||||
package mineplex.mapparser.command;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import mineplex.core.common.util.F;
|
||||
import mineplex.mapparser.GameType;
|
||||
import mineplex.mapparser.MapParser;
|
||||
import org.apache.commons.io.FileUtils;
|
||||
|
||||
/**
|
||||
* Created by Shaun on 8/16/2014.
|
||||
*/
|
||||
public class CopyCommand extends BaseCommand
|
||||
{
|
||||
public CopyCommand(MapParser plugin)
|
||||
{
|
||||
super(plugin, "copy");
|
||||
setUsage("/copy <map name> <game type> <copy map name> <copy game time>");
|
||||
setDescription("Copy the data of a map into a new map. This preserves Build List.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(Player player, String alias, String[] args)
|
||||
{
|
||||
if (args.length != 4)
|
||||
return false;
|
||||
|
||||
String originalMapName = args[0];
|
||||
String newMapName = args[2];
|
||||
|
||||
GameType originalGametype = null;
|
||||
GameType newGameType = null;
|
||||
|
||||
try
|
||||
{
|
||||
originalGametype = GameType.valueOf(args[1]);
|
||||
newGameType = GameType.valueOf(args[3]);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
getPlugin().sendValidGameTypes(player);
|
||||
return true;
|
||||
}
|
||||
|
||||
String worldName = getPlugin().getWorldString(originalMapName, originalGametype);
|
||||
String newWorldName = getPlugin().getWorldString(newMapName, newGameType);
|
||||
|
||||
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))
|
||||
{
|
||||
message(player, "Destination map already exists " + F.elem(newMapName) + " of type " + F.elem(newGameType.toString()));
|
||||
return true;
|
||||
}
|
||||
|
||||
World world = getPlugin().getMapWorld(worldName);
|
||||
|
||||
if (world != null)
|
||||
{
|
||||
// World is loaded, save and unload it.
|
||||
|
||||
for (Player other : world.getPlayers())
|
||||
{
|
||||
other.teleport(getPlugin().getSpawnLocation());
|
||||
message(other, "Unloading world for copy...");
|
||||
}
|
||||
getPlugin().getServer().unloadWorld(world, true);
|
||||
}
|
||||
|
||||
File source = new File(worldName);
|
||||
File destination = new File(newWorldName);
|
||||
try
|
||||
{
|
||||
FileUtils.copyDirectory(source, destination);
|
||||
message(player, "Copy completed successfully!");
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
message(player, "An error occurred during map copy!");
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
@ -0,0 +1,40 @@
|
||||
package mineplex.mapparser.command;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import mineplex.mapparser.MapParser;
|
||||
import org.apache.commons.io.FileUtils;
|
||||
|
||||
/**
|
||||
* Created by Shaun on 8/16/2014.
|
||||
*/
|
||||
public class CopySchematicsCommand extends BaseCommand
|
||||
{
|
||||
public CopySchematicsCommand(MapParser plugin)
|
||||
{
|
||||
super(plugin, "copyschematics");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(Player player, String alias, String[] args)
|
||||
{
|
||||
try
|
||||
{
|
||||
FileUtils.copyDirectory(new File(".." + File.separator + "Build-1" + File.separator + "plugins" + File.separator + "WorldEdit" + File.separator + "schematics"),
|
||||
new File("plugins" + File.separator + "WorldEdit" + File.separator + "schematics"));
|
||||
|
||||
message(player, "Schematics Copied.");
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
|
||||
message(player, "Schematics Copy Failed! Contact Jonalon.");
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
@ -0,0 +1,89 @@
|
||||
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 mineplex.mapparser.command.teleport.TeleportManager;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.WorldCreator;
|
||||
import org.bukkit.WorldType;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
/**
|
||||
* Created by Shaun on 8/16/2014.
|
||||
*/
|
||||
public class CreateCommand extends BaseCommand
|
||||
{
|
||||
private TeleportManager _teleportManager;
|
||||
|
||||
public CreateCommand(TeleportManager teleportManager)
|
||||
{
|
||||
super(teleportManager.getPlugin(), "create");
|
||||
|
||||
_teleportManager = teleportManager;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(Player player, String alias, String[] args)
|
||||
{
|
||||
if (args.length < 1)
|
||||
{
|
||||
message(player, "Invalid Input. " + F.elem("/create <MapName> [-v]"));
|
||||
return true;
|
||||
}
|
||||
|
||||
GameType gameType = GameType.InProgress;
|
||||
|
||||
String worldName = "map/" + gameType.GetName() + "/" + args[0];
|
||||
|
||||
if (getPlugin().doesMapExist(worldName))
|
||||
{
|
||||
message(player, "Map name is already in use!");
|
||||
return true;
|
||||
}
|
||||
|
||||
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));
|
||||
|
||||
_teleportManager.teleportPlayer(player, world.getSpawnLocation());
|
||||
|
||||
//Give Access
|
||||
MapData mapData = getPlugin().getData(worldName);
|
||||
mapData.AdminList.add(player.getName());
|
||||
mapData.MapGameType = gameType;
|
||||
mapData.Write();
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
@ -0,0 +1,43 @@
|
||||
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)
|
||||
{
|
||||
if (player.getWorld().getName().equals("world_lobby"))
|
||||
{
|
||||
message(player, "Cannot set live status for Lobby.");
|
||||
return true;
|
||||
}
|
||||
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;
|
||||
}
|
||||
}
|
@ -0,0 +1,81 @@
|
||||
package mineplex.mapparser.command;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import mineplex.core.common.util.F;
|
||||
import mineplex.mapparser.GameType;
|
||||
import mineplex.mapparser.MapParser;
|
||||
import org.apache.commons.io.FileUtils;
|
||||
|
||||
/**
|
||||
* Created by Shaun on 8/16/2014.
|
||||
*/
|
||||
public class DeleteCommand extends BaseCommand
|
||||
{
|
||||
public DeleteCommand(MapParser plugin)
|
||||
{
|
||||
super(plugin, "delete");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(Player player, String alias, String[] args)
|
||||
{
|
||||
if (args.length < 2)
|
||||
{
|
||||
message(player, "Invalid Input. " + F.elem("/delete <MapName> [GameType]"));
|
||||
return true;
|
||||
}
|
||||
|
||||
String mapName = args[0];
|
||||
GameType gameType = null;
|
||||
|
||||
try
|
||||
{
|
||||
gameType = GameType.valueOf(args[1]);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
getPlugin().sendValidGameTypes(player);
|
||||
}
|
||||
|
||||
final String worldName = getPlugin().getWorldString(mapName, gameType);
|
||||
|
||||
if (!getPlugin().doesMapExist(worldName))
|
||||
{
|
||||
message(player, "Map does not exist: " + F.elem(worldName));
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!getPlugin().getData(worldName).HasAccess(player))
|
||||
{
|
||||
message(player, "You do not have Build-Access on this Map.");
|
||||
return true;
|
||||
}
|
||||
|
||||
if (getPlugin().getMapWorld(worldName) != null)
|
||||
{
|
||||
World world = getPlugin().getMapWorld(worldName);
|
||||
|
||||
//Teleport Out
|
||||
for (Player other : world.getPlayers())
|
||||
other.teleport(getPlugin().getSpawnLocation());
|
||||
|
||||
//Unload World
|
||||
//Things break if this isn't set to true for saving the world
|
||||
getPlugin().getServer().unloadWorld(world, true);
|
||||
}
|
||||
|
||||
//Delete
|
||||
boolean deleted = FileUtils.deleteQuietly(new File(worldName));
|
||||
|
||||
if (deleted)
|
||||
getPlugin().announce("Deleted World: " + F.elem(worldName));
|
||||
else
|
||||
getPlugin().announce("Failed to delete World: " + F.elem(worldName));
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
@ -0,0 +1,45 @@
|
||||
package mineplex.mapparser.command;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import mineplex.core.common.util.C;
|
||||
import mineplex.core.common.util.F;
|
||||
import mineplex.mapparser.MapParser;
|
||||
|
||||
public class FlySpeedCommand extends BaseCommand
|
||||
{
|
||||
private final static float BASE_SPEED = 1F;
|
||||
|
||||
public FlySpeedCommand(MapParser plugin)
|
||||
{
|
||||
super(plugin, "speed", "flyspeed");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(Player player, String alias, String[] args)
|
||||
{
|
||||
float newSpeed = BASE_SPEED;
|
||||
|
||||
if (args.length > 0)
|
||||
{
|
||||
try
|
||||
{
|
||||
newSpeed = Float.parseFloat(args[0]);
|
||||
|
||||
if (newSpeed > 10 || newSpeed < 0)
|
||||
{
|
||||
throw new NumberFormatException("Speed must be between 0 and 10.");
|
||||
}
|
||||
}
|
||||
catch (NumberFormatException ex)
|
||||
{
|
||||
message(player, "Please enter a valid speed value from " + C.cYellow + "0" + C.mBody + " to " + C.cYellow + "10");
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
player.setFlySpeed(newSpeed / 10);
|
||||
message(player, "Set your flight speed to " + F.elem(newSpeed));
|
||||
return true;
|
||||
}
|
||||
}
|
@ -0,0 +1,93 @@
|
||||
package mineplex.mapparser.command;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import mineplex.core.common.util.F;
|
||||
import mineplex.mapparser.GameType;
|
||||
import mineplex.mapparser.MapData;
|
||||
import mineplex.mapparser.MapParser;
|
||||
|
||||
/**
|
||||
* Created by Shaun on 8/16/2014.
|
||||
*/
|
||||
public class GameTypeCommand extends BaseCommand
|
||||
{
|
||||
public GameTypeCommand(MapParser plugin)
|
||||
{
|
||||
super(plugin, "gametype");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(Player player, String alias, String[] args)
|
||||
{
|
||||
World world = player.getWorld();
|
||||
|
||||
if (args.length != 1)
|
||||
{
|
||||
message(player, "Invalid Input. " + F.elem("/gametype <GameType>"));
|
||||
return true;
|
||||
}
|
||||
|
||||
if (world.getName().equals("world_lobby"))
|
||||
{
|
||||
message(player, "Cannot set GameType for Lobby.");
|
||||
return true;
|
||||
}
|
||||
|
||||
//Permission
|
||||
if (!getPlugin().getData(world.getName()).HasAccess(player))
|
||||
{
|
||||
message(player, "You do not have Build-Access on this Map.");
|
||||
return true;
|
||||
}
|
||||
|
||||
//Check Gametype
|
||||
GameType type = null;
|
||||
try
|
||||
{
|
||||
type = GameType.valueOf(args[0]);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
getPlugin().sendValidGameTypes(player);
|
||||
return true;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
// Rename world
|
||||
for (Player other : world.getPlayers())
|
||||
{
|
||||
other.teleport(getPlugin().getSpawnLocation());
|
||||
message(player, "Unloading world for rename...");
|
||||
}
|
||||
getPlugin().getServer().unloadWorld(world, true);
|
||||
|
||||
File typeFolder = new File("map/" + type.GetName());
|
||||
if (!typeFolder.exists())
|
||||
typeFolder.mkdir();
|
||||
|
||||
File mapFolder = new File(world.getName());
|
||||
String newName = "map/" + type.GetName() + "/" + getPlugin().getShortWorldName(world.getName());
|
||||
File newFolder = new File(newName);
|
||||
mapFolder.renameTo(newFolder);
|
||||
|
||||
message(player, "Map " + world.getName() + " renamed to " + newName);
|
||||
|
||||
|
||||
MapData data = getPlugin().getData(newName);
|
||||
data.MapGameType = type;
|
||||
data.Write();
|
||||
|
||||
getPlugin().announce("GameType for " + F.elem(newName) + " set to " + F.elem(args[0]) + ".");
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
@ -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 GameTypeInfoCommand extends BaseCommand
|
||||
{
|
||||
|
||||
public GameTypeInfoCommand(MapParser plugin)
|
||||
{
|
||||
super(plugin, "gameinfo", "gametypeinfo");
|
||||
setUsage("/info <gametype> & /info addInfo <gameType> <info>");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(Player player, String alias, String[] args)
|
||||
{
|
||||
if (args.length == 1)
|
||||
{
|
||||
String gameRaw = args[0];
|
||||
GameType gameType;
|
||||
try
|
||||
{
|
||||
gameType = GameType.match(gameRaw);
|
||||
} catch (Exception e)
|
||||
{
|
||||
player.sendMessage(C.cRed + "Invalid Game Type: " + gameRaw);
|
||||
return true;
|
||||
}
|
||||
GameTypeInfo info = getPlugin().getInfo(gameType);
|
||||
if (info == null)
|
||||
{
|
||||
player.sendMessage(C.cRed + "No info found for " + gameType.GetName());
|
||||
return true;
|
||||
}
|
||||
info.sendInfo(player);
|
||||
return true;
|
||||
}
|
||||
if (args.length >= 3 && args[0].equalsIgnoreCase("addInfo"))
|
||||
{
|
||||
String gameRaw = args[1];
|
||||
GameType gameType;
|
||||
try
|
||||
{
|
||||
gameType = GameType.match(gameRaw);
|
||||
} catch (Exception e)
|
||||
{
|
||||
player.sendMessage(C.cRed + "Invalid Game Type: " + gameRaw);
|
||||
return true;
|
||||
}
|
||||
GameTypeInfo info = getPlugin().getInfo(gameType);
|
||||
StringBuilder builder = new StringBuilder();
|
||||
for (int i = 2; i < args.length; i++)
|
||||
{
|
||||
builder.append(args[i]);
|
||||
if ((i + 1) != args.length)
|
||||
{
|
||||
builder.append(" ");
|
||||
}
|
||||
}
|
||||
if (info == null)
|
||||
{
|
||||
info = new GameTypeInfo(gameType, Lists.newArrayList());
|
||||
getPlugin().setInfo(gameType, info);
|
||||
}
|
||||
|
||||
info.addInfo(builder.toString());
|
||||
player.sendMessage(C.cGray + "Added new info to " + F.elem(gameRaw));
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
@ -0,0 +1,29 @@
|
||||
package mineplex.mapparser.command;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import mineplex.mapparser.MapParser;
|
||||
import mineplex.mapparser.command.teleport.TeleportManager;
|
||||
|
||||
/**
|
||||
* Created by Shaun on 8/15/2014.
|
||||
*/
|
||||
public class HubCommand extends BaseCommand
|
||||
{
|
||||
private TeleportManager _teleportManager;
|
||||
|
||||
public HubCommand(TeleportManager teleportManager)
|
||||
{
|
||||
super(teleportManager.getPlugin(), "hub");
|
||||
|
||||
_teleportManager = teleportManager;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(Player player, String alias, String[] args)
|
||||
{
|
||||
_teleportManager.teleportPlayer(player, getPlugin().getSpawnLocation());
|
||||
return true;
|
||||
}
|
||||
}
|
@ -0,0 +1,52 @@
|
||||
package mineplex.mapparser.command;
|
||||
|
||||
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.ItemMeta;
|
||||
|
||||
public class ItemNameCommand extends BaseCommand
|
||||
{
|
||||
public ItemNameCommand(MapParser plugin)
|
||||
{
|
||||
super(plugin, "itemname", "in");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(Player player, String alias, String[] args)
|
||||
{
|
||||
if (args == null || args.length < 1)
|
||||
{
|
||||
message(player, "Invalid Usage: " + F.elem("/" + alias + " <name>"));
|
||||
return true;
|
||||
}
|
||||
|
||||
ItemStack is = player.getItemInHand();
|
||||
|
||||
if (is == null || is.getType() == Material.AIR)
|
||||
{
|
||||
message(player, "You must be holding an item in your hand.");
|
||||
return true;
|
||||
}
|
||||
|
||||
ItemMeta im = is.getItemMeta();
|
||||
|
||||
StringBuilder name = new StringBuilder();
|
||||
for (String arg : args)
|
||||
{
|
||||
name.append(arg).append(" ");
|
||||
}
|
||||
name = new StringBuilder(name.toString().replaceAll("&", "§").trim());
|
||||
|
||||
im.setDisplayName(name.toString());
|
||||
is.setItemMeta(im);
|
||||
|
||||
player.setItemInHand(is);
|
||||
player.updateInventory();
|
||||
message(player, "Set name: " + name);
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
@ -0,0 +1,189 @@
|
||||
package mineplex.mapparser.command;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import mineplex.core.common.util.C;
|
||||
import mineplex.core.common.util.F;
|
||||
import mineplex.core.common.util.UtilPlayerBase;
|
||||
import mineplex.mapparser.GameType;
|
||||
import mineplex.mapparser.MapData;
|
||||
import mineplex.mapparser.MapParser;
|
||||
|
||||
/**
|
||||
* Created by Shaun on 8/15/2014.
|
||||
*/
|
||||
public class ListCommand extends BaseCommand
|
||||
{
|
||||
//private static final List<String> AUTHOR_ALISES = Arrays.asList("author", "creator", "a");
|
||||
private static final List<String> NAME_ALIASES = Arrays.asList("name", "mapname", "title", "n");
|
||||
private static final List<String> TYPE_ALIASES = Arrays.asList("type", "game", "gametype", "g");
|
||||
|
||||
public ListCommand(MapParser plugin)
|
||||
{
|
||||
super(plugin, "list");
|
||||
|
||||
setUsage("/list <author|name|type> <search term(s)>");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(Player player, String alias, String[] args)
|
||||
{
|
||||
if (args.length == 0)
|
||||
{
|
||||
UtilPlayerBase.message(player, F.main("Parser", "Listing Maps;"));
|
||||
|
||||
boolean colorSwitch = false;
|
||||
|
||||
for (GameType gameType : GameType.values())
|
||||
{
|
||||
if (gameType == GameType.InProgress)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (listMapsForGameType(player, gameType, colorSwitch))
|
||||
{
|
||||
colorSwitch = !colorSwitch;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (args.length == 1)
|
||||
{
|
||||
message(player, F.elem(getUsage()));
|
||||
}
|
||||
else
|
||||
{
|
||||
String subCommand = args[0].toLowerCase();
|
||||
|
||||
if (TYPE_ALIASES.contains(subCommand))
|
||||
{
|
||||
String input = args[1];
|
||||
|
||||
GameType gameType = getGameType(input);
|
||||
|
||||
if (gameType == null)
|
||||
{
|
||||
getPlugin().sendValidGameTypes(player);
|
||||
return true;
|
||||
}
|
||||
|
||||
UtilPlayerBase.message(player, F.main("Parser", "Listing Maps for gametype " + F.elem(gameType.GetName())));
|
||||
listMapsForGameType(player, gameType, false);
|
||||
}
|
||||
else
|
||||
{
|
||||
String search = Arrays.asList(args).subList(1, args.length).stream().collect(Collectors.joining());
|
||||
|
||||
if (NAME_ALIASES.contains(subCommand))
|
||||
{
|
||||
List<String> mapNames = GameType.getAllMapNames()
|
||||
.stream()
|
||||
.filter(n -> n.toLowerCase().contains(search))
|
||||
.collect(Collectors.toList());
|
||||
|
||||
message(player, "Listing maps whose name contains " + F.elem(search) + C.mBody + ":");
|
||||
message(player, getMapsMessage(mapNames, false));
|
||||
}
|
||||
else
|
||||
{
|
||||
message(player, "Invalid sub-command.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private GameType getGameType(String input)
|
||||
{
|
||||
GameType gameType;
|
||||
if (input.equalsIgnoreCase("p"))
|
||||
{
|
||||
gameType = GameType.InProgress;
|
||||
}
|
||||
else
|
||||
{
|
||||
try
|
||||
{
|
||||
gameType = GameType.valueOf(input);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
return gameType;
|
||||
}
|
||||
|
||||
private String getMapsMessage(List<String> mapNames, boolean colorSwitch)
|
||||
{
|
||||
StringBuilder maps = new StringBuilder();
|
||||
ChatColor color = ChatColor.AQUA;
|
||||
if (colorSwitch)
|
||||
color = ChatColor.GREEN;
|
||||
|
||||
for (String name : mapNames)
|
||||
{
|
||||
maps.append(color).append(name).append(" ");
|
||||
|
||||
if (color == ChatColor.AQUA)
|
||||
color = ChatColor.DARK_AQUA;
|
||||
else if (color == ChatColor.DARK_AQUA)
|
||||
color = ChatColor.AQUA;
|
||||
else if (color == ChatColor.GREEN)
|
||||
color = ChatColor.DARK_GREEN;
|
||||
else color = ChatColor.GREEN;
|
||||
}
|
||||
|
||||
return maps.toString();
|
||||
}
|
||||
|
||||
private boolean listMapsForGameType(Player player, GameType gameType, boolean colorSwitch)
|
||||
{
|
||||
List<String> mapNames = gameType.getMapNames();
|
||||
|
||||
if (mapNames == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
String maps = getMapsMessage(mapNames, colorSwitch);
|
||||
|
||||
// Print line of maps for specific gametype
|
||||
if (maps.length() > 0)
|
||||
{
|
||||
player.sendMessage(F.elem(ChatColor.RESET + C.Scramble + "!" + ChatColor.RESET + C.Bold + gameType.name()) + "> " + maps);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public List<MapData> getAllMapData()
|
||||
{
|
||||
List<String> mapNames = GameType.getAllMapNames();
|
||||
List<MapData> mapData = new ArrayList<>();
|
||||
|
||||
for (String mapName : mapNames)
|
||||
{
|
||||
MapData data = getPlugin().getData(mapName);
|
||||
|
||||
if (data == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
mapData.add(data);
|
||||
}
|
||||
|
||||
return mapData;
|
||||
}
|
||||
}
|
@ -0,0 +1,42 @@
|
||||
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 OpCommand
|
||||
{
|
||||
|
||||
public LockCommand(MapParser plugin)
|
||||
{
|
||||
super(plugin, "lock");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(Player player, String alias, String[] args)
|
||||
{
|
||||
if (player.getWorld().getName().equals("world_lobby"))
|
||||
{
|
||||
message(player, "Cannot toggle lock for Lobby.");
|
||||
return true;
|
||||
}
|
||||
|
||||
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;
|
||||
data.Write();
|
||||
message(player, "Lock for world " + F.elem(player.getWorld().getName()) + ": " + F.tf(data._locked));
|
||||
return true;
|
||||
}
|
||||
}
|
@ -0,0 +1,32 @@
|
||||
package mineplex.mapparser.command;
|
||||
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import mineplex.mapparser.MapParser;
|
||||
|
||||
public abstract class MapAdminCommand extends BaseCommand
|
||||
{
|
||||
public MapAdminCommand(MapParser plugin, String... aliases)
|
||||
{
|
||||
super(plugin, aliases);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canRun(Player player)
|
||||
{
|
||||
if (player.isOp())
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
World world = player.getWorld();
|
||||
|
||||
if (world.getName().equals("world_lobby"))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return getPlugin().getData(world.getName()).HasAccess(player);
|
||||
}
|
||||
}
|
@ -0,0 +1,127 @@
|
||||
package mineplex.mapparser.command;
|
||||
|
||||
import mineplex.core.common.util.F;
|
||||
import mineplex.core.common.util.UtilPlayerBase;
|
||||
import mineplex.mapparser.GameType;
|
||||
import mineplex.mapparser.MapData;
|
||||
import mineplex.mapparser.MapParser;
|
||||
import mineplex.mapparser.command.teleport.TeleportManager;
|
||||
|
||||
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.
|
||||
*/
|
||||
public class MapCommand extends BaseCommand
|
||||
{
|
||||
private TeleportManager _teleportManager;
|
||||
|
||||
public MapCommand(TeleportManager teleportManager)
|
||||
{
|
||||
super(teleportManager.getPlugin(), "map");
|
||||
|
||||
setDescription("Teleport to a map");
|
||||
setUsage("/map <name> [gametype]");
|
||||
|
||||
_teleportManager = teleportManager;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(Player player, String alias, String[] args)
|
||||
{
|
||||
if (args.length < 1)
|
||||
{
|
||||
//UtilPlayerBase.message(event.getPlayer(), F.main("Parser", "Invalid Input. " + F.elem("/map <MapName> [GameType]")));
|
||||
return false;
|
||||
}
|
||||
|
||||
String worldName = null;
|
||||
// Look up maps without a specific game type
|
||||
if (args.length == 1)
|
||||
{
|
||||
List<String> possibleMaps = getPlugin().getMapsByName(args[0]);
|
||||
if (possibleMaps.size() == 0)
|
||||
{
|
||||
message(player, "No maps found with the name: " + F.elem(args[0]));
|
||||
return true;
|
||||
}
|
||||
if (possibleMaps.size() > 1)
|
||||
{
|
||||
message(player, "Found more than one possible match:");
|
||||
for (String s : possibleMaps)
|
||||
UtilPlayerBase.message(player, s);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
worldName = possibleMaps.get(0);
|
||||
}
|
||||
else // Get map with specified name and gametype
|
||||
{
|
||||
GameType gameType = null;
|
||||
try
|
||||
{
|
||||
gameType = GameType.valueOf(args[1]);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
getPlugin().sendValidGameTypes(player);
|
||||
return true;
|
||||
}
|
||||
|
||||
worldName = getPlugin().getWorldString(args[0], gameType);
|
||||
}
|
||||
|
||||
if (getPlugin().getMapsBeingZipped().contains(worldName))
|
||||
{
|
||||
message(player, "That map is being backed up now. Try again soon");
|
||||
return true;
|
||||
}
|
||||
|
||||
//Delete UID
|
||||
File file = new File(worldName + "/uid.dat");
|
||||
if (file.exists())
|
||||
{
|
||||
System.out.println("Deleting uid.dat for " + worldName);
|
||||
file.delete();
|
||||
}
|
||||
else
|
||||
{
|
||||
System.out.println("Could not delete uid.dat for " + worldName);
|
||||
}
|
||||
|
||||
World world = getPlugin().getWorldFromName(worldName);
|
||||
|
||||
//Error (This should not occur!)
|
||||
if (world == null)
|
||||
{
|
||||
message(player, "Null World Error: " + F.elem(worldName));
|
||||
return true;
|
||||
}
|
||||
|
||||
//Permission
|
||||
if (!_teleportManager.canTeleportTo(player, world.getSpawnLocation()))
|
||||
{
|
||||
message(player, "You are not permitted to access this map.");
|
||||
return true;
|
||||
}
|
||||
|
||||
//Teleport
|
||||
message(player, "Teleporting to World: " + F.elem(worldName));
|
||||
|
||||
_teleportManager.teleportPlayer(player, new Location(world, 0, 106, 0));
|
||||
player.setFlying(true);
|
||||
|
||||
MapData data = getPlugin().getData(worldName);
|
||||
|
||||
data.sendInfo(player);
|
||||
return true;
|
||||
}
|
||||
}
|
@ -0,0 +1,24 @@
|
||||
package mineplex.mapparser.command;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import mineplex.mapparser.MapData;
|
||||
import mineplex.mapparser.MapParser;
|
||||
import mineplex.mapparser.command.BaseCommand;
|
||||
|
||||
public class MapInfoCommand extends BaseCommand
|
||||
{
|
||||
public MapInfoCommand(MapParser plugin)
|
||||
{
|
||||
super(plugin, "mapinfo", "info");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(Player player, String alias, String[] args)
|
||||
{
|
||||
MapData data = getPlugin().getData(player.getWorld().getName());
|
||||
|
||||
data.sendInfo(player);
|
||||
return true;
|
||||
}
|
||||
}
|
@ -0,0 +1,53 @@
|
||||
package mineplex.mapparser.command;
|
||||
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import mineplex.core.common.util.F;
|
||||
import mineplex.mapparser.MapData;
|
||||
import mineplex.mapparser.MapParser;
|
||||
|
||||
/**
|
||||
* Created by Shaun on 8/15/2014.
|
||||
*/
|
||||
public class NameCommand extends MapAdminCommand
|
||||
{
|
||||
|
||||
public NameCommand(MapParser plugin)
|
||||
{
|
||||
super(plugin, "name");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(Player player, String alias, String[] args)
|
||||
{
|
||||
World world = player.getWorld();
|
||||
|
||||
if (args.length < 1)
|
||||
{
|
||||
message(player, "Invalid Input. " + F.elem("/name <MapName>"));
|
||||
return true;
|
||||
}
|
||||
|
||||
if (world.getName().equals("world_lobby"))
|
||||
{
|
||||
message(player, "Cannot set name for Lobby.");
|
||||
return true;
|
||||
}
|
||||
|
||||
StringBuilder mapName = new StringBuilder();
|
||||
for(String arg : args)
|
||||
mapName.append(arg).append(" ");
|
||||
|
||||
mapName = new StringBuilder(mapName.toString().trim());
|
||||
|
||||
MapData data = getPlugin().getData(world.getName());
|
||||
|
||||
data.MapName = mapName.toString();
|
||||
data.Write();
|
||||
|
||||
getPlugin().announce("Map Name for " + F.elem(world.getName()) + " set to " + F.elem(mapName.toString()) + ".");
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
@ -0,0 +1,19 @@
|
||||
package mineplex.mapparser.command;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import mineplex.mapparser.MapParser;
|
||||
|
||||
public abstract class OpCommand extends BaseCommand
|
||||
{
|
||||
public OpCommand(MapParser plugin, String... aliases)
|
||||
{
|
||||
super(plugin, aliases);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canRun(Player player)
|
||||
{
|
||||
return player.isOp();
|
||||
}
|
||||
}
|
@ -0,0 +1,36 @@
|
||||
package mineplex.mapparser.command;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import mineplex.core.common.util.C;
|
||||
import mineplex.core.common.util.F;
|
||||
import mineplex.mapparser.MapParser;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public class PMCommand extends OpCommand
|
||||
{
|
||||
public PMCommand(MapParser plugin)
|
||||
{
|
||||
super(plugin, "m", "message");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(Player player, String alias, String[] args)
|
||||
{
|
||||
if (args.length == 0)
|
||||
{
|
||||
player.sendMessage(F.main(getPlugin().getName(), "Please put a message in!"));
|
||||
return true;
|
||||
}
|
||||
|
||||
String message = C.cDRed + "OP " + player.getName() + " " + C.cPurple + Arrays.stream(args).collect(Collectors.joining(" ")).trim();
|
||||
|
||||
getPlugin().getServer().getOnlinePlayers().stream().filter(Player::isOp).forEach(p -> p.sendMessage(message));
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
@ -0,0 +1,100 @@
|
||||
package mineplex.mapparser.command;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import mineplex.core.common.util.F;
|
||||
import mineplex.mapparser.MapData;
|
||||
import mineplex.mapparser.MapParser;
|
||||
import mineplex.mapparser.Parse;
|
||||
|
||||
public class ParseCommand extends OpCommand
|
||||
{
|
||||
private static final String LOBBY_NAME = "world_lobby";
|
||||
|
||||
public ParseCommand(MapParser plugin)
|
||||
{
|
||||
super(plugin, "parse");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(Player player, String alias, String[] args)
|
||||
{
|
||||
int radius = 200;
|
||||
|
||||
// Custom radius settings
|
||||
if (args.length > 0)
|
||||
{
|
||||
try
|
||||
{
|
||||
radius = Integer.parseInt(args[0]);
|
||||
|
||||
if (radius < 1)
|
||||
{
|
||||
throw new NumberFormatException("Radius cannot be less than 1.");
|
||||
}
|
||||
}
|
||||
catch (NumberFormatException ex)
|
||||
{
|
||||
message(player, "Please enter a valid radius.");
|
||||
return true;
|
||||
}
|
||||
|
||||
// If there are more args, set the new args
|
||||
// to everything past the radius
|
||||
if (args.length > 1)
|
||||
{
|
||||
args = Arrays.asList(args).subList(1, args.length).toArray(new String[] {});
|
||||
}
|
||||
// Otherwise, set it to an empty array.
|
||||
else
|
||||
{
|
||||
args = new String[] {};
|
||||
}
|
||||
}
|
||||
|
||||
Location parseLoc = player.getLocation();
|
||||
|
||||
World world = parseLoc.getWorld();
|
||||
|
||||
if (world.getName().equals(LOBBY_NAME))
|
||||
{
|
||||
message(player, "You can't parse the Lobby!");
|
||||
return true;
|
||||
}
|
||||
|
||||
MapData data = getPlugin().getData(world.getName());
|
||||
|
||||
if (data.MapName.equals("null") || data.MapCreator.equals("null") || data.MapGameType == null)
|
||||
{
|
||||
message(player, "Map Name/Author/GameType are not set!");
|
||||
return true;
|
||||
}
|
||||
|
||||
// Teleport Players Out
|
||||
for (Player worldPlayer : world.getPlayers())
|
||||
{
|
||||
worldPlayer.teleport(getPlugin().getSpawnLocation());
|
||||
message(player, "World " + F.elem(world.getName()) + " is preparing to be parsed, so you were sent back to the lobby.");
|
||||
}
|
||||
|
||||
// Unload World > Copy
|
||||
World parseableWorld = getPlugin().getWorldManager().prepMapParse(world);
|
||||
|
||||
if (parseableWorld == null)
|
||||
{
|
||||
message(player, "Could not prepare world for parsing! Parse aborted.");
|
||||
return true;
|
||||
}
|
||||
|
||||
//Parse the World
|
||||
getPlugin().setCurrentParse(new Parse(getPlugin(), parseableWorld, args, parseLoc, getPlugin().getData(parseLoc.getWorld().getName()), radius));
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
@ -0,0 +1,70 @@
|
||||
package mineplex.mapparser.command;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import mineplex.core.common.util.F;
|
||||
import mineplex.mapparser.MapData;
|
||||
import mineplex.mapparser.MapParser;
|
||||
import mineplex.mapparser.Parse;
|
||||
|
||||
/**
|
||||
* Larger parse command
|
||||
*/
|
||||
public class ParseCommand1000 extends BaseCommand
|
||||
{
|
||||
public ParseCommand1000(MapParser plugin)
|
||||
{
|
||||
super(plugin, "parse1000");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(Player player, String alias, String[] args)
|
||||
{
|
||||
if (!player.isOp())
|
||||
{
|
||||
message(player, "Only OPs can parse maps!");
|
||||
return true;
|
||||
}
|
||||
|
||||
Location parseLoc = player.getLocation();
|
||||
|
||||
World world = parseLoc.getWorld();
|
||||
|
||||
if (world.getName().equals("world_lobby"))
|
||||
{
|
||||
message(player, "Cannot parse Lobby.");
|
||||
return true;
|
||||
}
|
||||
|
||||
MapData data = getPlugin().getData(world.getName());
|
||||
|
||||
if (data.MapName.equals("null") || data.MapCreator.equals("null") || data.MapGameType.equals("null"))
|
||||
{
|
||||
message(player, "Map Name/Author/GameType are not set!");
|
||||
return true;
|
||||
}
|
||||
|
||||
//Teleport Players Out
|
||||
for (Player worldPlayer : world.getPlayers())
|
||||
{
|
||||
worldPlayer.teleport(getPlugin().getSpawnLocation());
|
||||
message(player, "World " + F.elem(world.getName()) + " is preparing to be parsed.");
|
||||
}
|
||||
|
||||
//Unload World > Copy
|
||||
World parseableWorld = getPlugin().getWorldManager().prepMapParse(world);
|
||||
|
||||
if (parseableWorld == null)
|
||||
{
|
||||
message(player, "Could not prepare world for parsing!");
|
||||
return true;
|
||||
}
|
||||
|
||||
//Parse the World
|
||||
getPlugin().setCurrentParse(new Parse(getPlugin(), parseableWorld, args, parseLoc, getPlugin().getData(parseLoc.getWorld().getName()), 1000));
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
@ -0,0 +1,70 @@
|
||||
package mineplex.mapparser.command;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import mineplex.core.common.util.F;
|
||||
import mineplex.mapparser.MapData;
|
||||
import mineplex.mapparser.MapParser;
|
||||
import mineplex.mapparser.Parse;
|
||||
|
||||
/**
|
||||
* Created by Shaun on 8/15/2014.
|
||||
*/
|
||||
public class ParseCommand200 extends BaseCommand
|
||||
{
|
||||
public ParseCommand200(MapParser plugin)
|
||||
{
|
||||
super(plugin, "parse200");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(Player player, String alias, String[] args)
|
||||
{
|
||||
if (!player.isOp())
|
||||
{
|
||||
message(player, "Only OPs can parse maps!");
|
||||
return true;
|
||||
}
|
||||
|
||||
Location parseLoc = player.getLocation();
|
||||
|
||||
World world = parseLoc.getWorld();
|
||||
|
||||
if (world.getName().equals("world_lobby"))
|
||||
{
|
||||
message(player, "Cannot parse Lobby.");
|
||||
return true;
|
||||
}
|
||||
|
||||
MapData data = getPlugin().getData(world.getName());
|
||||
|
||||
if (data.MapName.equals("null") || data.MapCreator.equals("null") || data.MapGameType.equals("null"))
|
||||
{
|
||||
message(player, "Map Name/Author/GameType are not set!");
|
||||
return true;
|
||||
}
|
||||
|
||||
//Teleport Players Out
|
||||
for (Player worldPlayer : world.getPlayers())
|
||||
{
|
||||
worldPlayer.teleport(getPlugin().getSpawnLocation());
|
||||
message(player, "World " + F.elem(world.getName()) + " is preparing to be parsed.");
|
||||
}
|
||||
|
||||
//Unload World > Copy
|
||||
World parseableWorld = getPlugin().getWorldManager().prepMapParse(world);
|
||||
|
||||
if (parseableWorld == null)
|
||||
{
|
||||
message(player, "Could not prepare world for parsing!");
|
||||
return true;
|
||||
}
|
||||
|
||||
//Parse the World
|
||||
getPlugin().setCurrentParse(new Parse(getPlugin(), parseableWorld, args, parseLoc, getPlugin().getData(parseLoc.getWorld().getName()), 200));
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
@ -0,0 +1,70 @@
|
||||
package mineplex.mapparser.command;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import mineplex.core.common.util.F;
|
||||
import mineplex.mapparser.MapData;
|
||||
import mineplex.mapparser.MapParser;
|
||||
import mineplex.mapparser.Parse;
|
||||
|
||||
/**
|
||||
* Created by Shaun on 8/15/2014.
|
||||
*/
|
||||
public class ParseCommand400 extends BaseCommand
|
||||
{
|
||||
public ParseCommand400(MapParser plugin)
|
||||
{
|
||||
super(plugin, "parse400");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(Player player, String alias, String[] args)
|
||||
{
|
||||
if (!player.isOp())
|
||||
{
|
||||
message(player, "Only OPs can parse maps!");
|
||||
return true;
|
||||
}
|
||||
|
||||
Location parseLoc = player.getLocation();
|
||||
|
||||
World world = parseLoc.getWorld();
|
||||
|
||||
if (world.getName().equals("world_lobby"))
|
||||
{
|
||||
message(player, "Cannot parse Lobby.");
|
||||
return true;
|
||||
}
|
||||
|
||||
MapData data = getPlugin().getData(world.getName());
|
||||
|
||||
if (data.MapName.equals("null") || data.MapCreator.equals("null") || data.MapGameType.equals("null"))
|
||||
{
|
||||
message(player, "Map Name/Author/GameType are not set!");
|
||||
return true;
|
||||
}
|
||||
|
||||
//Teleport Players Out
|
||||
for (Player worldPlayer : world.getPlayers())
|
||||
{
|
||||
worldPlayer.teleport(getPlugin().getSpawnLocation());
|
||||
message(player, "World " + F.elem(world.getName()) + " is preparing to be parsed.");
|
||||
}
|
||||
|
||||
//Unload World > Copy
|
||||
World parseableWorld = getPlugin().getWorldManager().prepMapParse(world);
|
||||
|
||||
if (parseableWorld == null)
|
||||
{
|
||||
message(player, "Could not prepare world for parsing!");
|
||||
return true;
|
||||
}
|
||||
|
||||
//Parse the World
|
||||
getPlugin().setCurrentParse(new Parse(getPlugin(), parseableWorld, args, parseLoc, getPlugin().getData(parseLoc.getWorld().getName()), 400));
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
@ -0,0 +1,70 @@
|
||||
package mineplex.mapparser.command;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import mineplex.core.common.util.F;
|
||||
import mineplex.mapparser.MapData;
|
||||
import mineplex.mapparser.MapParser;
|
||||
import mineplex.mapparser.Parse;
|
||||
|
||||
/**
|
||||
* Created by Shaun on 8/15/2014.
|
||||
*/
|
||||
public class ParseCommand600 extends BaseCommand
|
||||
{
|
||||
public ParseCommand600(MapParser plugin)
|
||||
{
|
||||
super(plugin, "parse600");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(Player player, String alias, String[] args)
|
||||
{
|
||||
if (!player.isOp())
|
||||
{
|
||||
message(player, "Only OPs can parse maps!");
|
||||
return true;
|
||||
}
|
||||
|
||||
Location parseLoc = player.getLocation();
|
||||
|
||||
World world = parseLoc.getWorld();
|
||||
|
||||
if (world.getName().equals("world_lobby"))
|
||||
{
|
||||
message(player, "Cannot parse Lobby.");
|
||||
return true;
|
||||
}
|
||||
|
||||
MapData data = getPlugin().getData(world.getName());
|
||||
|
||||
if (data.MapName.equals("null") || data.MapCreator.equals("null") || data.MapGameType.equals("null"))
|
||||
{
|
||||
message(player, "Map Name/Author/GameType are not set!");
|
||||
return true;
|
||||
}
|
||||
|
||||
//Teleport Players Out
|
||||
for (Player worldPlayer : world.getPlayers())
|
||||
{
|
||||
worldPlayer.teleport(getPlugin().getSpawnLocation());
|
||||
message(player, "World " + F.elem(world.getName()) + " is preparing to be parsed.");
|
||||
}
|
||||
|
||||
//Unload World > Copy
|
||||
World parseableWorld = getPlugin().getWorldManager().prepMapParse(world);
|
||||
|
||||
if (parseableWorld == null)
|
||||
{
|
||||
message(player, "Could not prepare world for parsing!");
|
||||
return true;
|
||||
}
|
||||
|
||||
//Parse the World
|
||||
getPlugin().setCurrentParse(new Parse(getPlugin(), parseableWorld, args, parseLoc, getPlugin().getData(parseLoc.getWorld().getName()), 600));
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
@ -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;
|
||||
}
|
||||
}
|
@ -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;
|
||||
}
|
||||
}
|
@ -0,0 +1,70 @@
|
||||
package mineplex.mapparser.command;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import mineplex.core.common.util.F;
|
||||
import mineplex.mapparser.MapData;
|
||||
import mineplex.mapparser.MapParser;
|
||||
|
||||
/**
|
||||
* Created by Shaun on 8/16/2014.
|
||||
*/
|
||||
public class RenameCommand extends BaseCommand
|
||||
{
|
||||
public RenameCommand(MapParser plugin)
|
||||
{
|
||||
super(plugin, "rename");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(Player player, String alias, String[] args)
|
||||
{
|
||||
World world = player.getWorld();
|
||||
|
||||
if (world.getName().equals("world_lobby"))
|
||||
{
|
||||
message(player, "Cannot rename Lobby.");
|
||||
return true;
|
||||
}
|
||||
|
||||
MapData data = getPlugin().getData(world.getName());
|
||||
|
||||
if (data == null)
|
||||
{
|
||||
message(player, "Map not found: " + F.elem(args[0]));
|
||||
return true;
|
||||
}
|
||||
else if (!data.CanRename(player))
|
||||
{
|
||||
message(player, "You do not have access to rename this map");
|
||||
return true;
|
||||
}
|
||||
else if (args.length != 1)
|
||||
{
|
||||
message(player, "Usage: /rename <new name>");
|
||||
return true;
|
||||
}
|
||||
|
||||
String newName = args[0];
|
||||
|
||||
for (Player other : world.getPlayers())
|
||||
{
|
||||
other.teleport(getPlugin().getSpawnLocation());
|
||||
message(other, "Unloading world for rename...");
|
||||
}
|
||||
getPlugin().getServer().unloadWorld(world, true);
|
||||
message(player, "World unloaded!");
|
||||
|
||||
|
||||
File mapFolder = new File(world.getName());
|
||||
File newFolder = new File("map" + File.separator + data.MapGameType.GetName() + File.separator + newName);
|
||||
mapFolder.renameTo(newFolder);
|
||||
|
||||
message(player, "Map " + world.getName() + " renamed to " + newFolder.getName());
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
@ -0,0 +1,77 @@
|
||||
package mineplex.mapparser.command;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import mineplex.core.common.util.F;
|
||||
import mineplex.core.common.util.UtilPlayerBase;
|
||||
import mineplex.mapparser.MapParser;
|
||||
|
||||
/**
|
||||
* Created by Shaun on 8/16/2014.
|
||||
*/
|
||||
public class SaveCommand extends BaseCommand
|
||||
{
|
||||
public SaveCommand(MapParser plugin)
|
||||
{
|
||||
super(plugin, "save");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(Player player, String alias, String[] args)
|
||||
{
|
||||
if (args.length < 1)
|
||||
{
|
||||
message(player, "Invalid Input. " + F.elem("/save <MapName>"));
|
||||
return true;
|
||||
}
|
||||
|
||||
String name = args[0];
|
||||
|
||||
List<String> possibleMaps = getPlugin().getMapsByName(name);
|
||||
|
||||
if (possibleMaps.size() > 1)
|
||||
{
|
||||
message(player, "More than one map found:");
|
||||
for (String s : possibleMaps)
|
||||
UtilPlayerBase.message(player, s);
|
||||
|
||||
return true;
|
||||
}
|
||||
else if (possibleMaps.size() == 0)
|
||||
{
|
||||
message(player, "No maps found with the name: " + F.elem(name));
|
||||
return true;
|
||||
}
|
||||
|
||||
String worldName = possibleMaps.get(0);
|
||||
World world = getPlugin().getMapWorld(worldName);
|
||||
|
||||
if (world != null)
|
||||
{
|
||||
if (!getPlugin().getData(worldName).HasAccess(player))
|
||||
{
|
||||
message(player, "You do not have Build-Access on this Map.");
|
||||
return true;
|
||||
}
|
||||
|
||||
//Teleport Out
|
||||
for (Player other : world.getPlayers())
|
||||
other.teleport(getPlugin().getSpawnLocation());
|
||||
|
||||
//Unload World
|
||||
getPlugin().getServer().unloadWorld(world, true);
|
||||
}
|
||||
else
|
||||
{
|
||||
message(player, "World is not loaded: " + F.elem(worldName));
|
||||
return true;
|
||||
}
|
||||
|
||||
getPlugin().announce("Saved World: " + F.elem(args[0]));
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
@ -0,0 +1,31 @@
|
||||
package mineplex.mapparser.command;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import mineplex.mapparser.MapParser;
|
||||
|
||||
public class SetSpawnCommand extends BaseCommand
|
||||
{
|
||||
|
||||
public SetSpawnCommand(MapParser plugin)
|
||||
{
|
||||
super(plugin, "setspawn");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(Player player, String alias, String[] args)
|
||||
{
|
||||
Location loc = player.getLocation();
|
||||
|
||||
player.getWorld().setSpawnLocation(loc.getBlockX(), loc.getBlockY(), loc.getBlockZ());
|
||||
|
||||
player.sendMessage(ChatColor.YELLOW + "Spawn saved for world '" + ChatColor.GOLD + loc.getWorld().getName()
|
||||
+ ChatColor.YELLOW + "' to X: " + ChatColor.GOLD + loc.getBlockX() + ChatColor.YELLOW + ", Y: "
|
||||
+ ChatColor.GOLD + loc.getBlockY() + ChatColor.YELLOW + ", Z: " + ChatColor.GOLD + loc.getBlockZ());
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,26 @@
|
||||
package mineplex.mapparser.command;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import mineplex.mapparser.MapParser;
|
||||
import mineplex.mapparser.command.teleport.TeleportManager;
|
||||
|
||||
public class SpawnCommand extends BaseCommand
|
||||
{
|
||||
private TeleportManager _teleportManager;
|
||||
|
||||
public SpawnCommand(TeleportManager plugin)
|
||||
{
|
||||
super(plugin.getPlugin(), "spawn");
|
||||
|
||||
_teleportManager = plugin;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(Player player, String alias, String[] args)
|
||||
{
|
||||
_teleportManager.teleportPlayer(player, player.getWorld().getSpawnLocation());
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,47 @@
|
||||
package mineplex.mapparser.command;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import mineplex.core.common.util.C;
|
||||
import mineplex.mapparser.MapParser;
|
||||
|
||||
public class TimeCommand extends BaseCommand
|
||||
{
|
||||
|
||||
public TimeCommand(MapParser plugin)
|
||||
{
|
||||
super(plugin, "time");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(Player player, String alias, String[] args)
|
||||
{
|
||||
if (args.length == 0)
|
||||
{
|
||||
player.resetPlayerTime();
|
||||
|
||||
message(player, "Reset your local player time.");
|
||||
return true;
|
||||
}
|
||||
|
||||
long time;
|
||||
try
|
||||
{
|
||||
time = Long.parseLong(args[0]);
|
||||
|
||||
if (time < 0)
|
||||
{
|
||||
throw new NumberFormatException("Time must be positive");
|
||||
}
|
||||
}
|
||||
catch (NumberFormatException ex)
|
||||
{
|
||||
message(player, "Please enter a valid value for time.");
|
||||
return true;
|
||||
}
|
||||
|
||||
player.setPlayerTime(time, false);
|
||||
message(player, "Your local player time has been updated to " + C.cYellow + time + C.mBody + ".");
|
||||
return true;
|
||||
}
|
||||
}
|
@ -0,0 +1,87 @@
|
||||
package mineplex.mapparser.command;
|
||||
|
||||
import mineplex.core.common.util.C;
|
||||
import mineplex.core.common.util.F;
|
||||
import mineplex.core.common.util.UtilWorld;
|
||||
import mineplex.mapparser.MapData;
|
||||
import mineplex.mapparser.MapParser;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public class WarpCommand extends BaseCommand
|
||||
{
|
||||
|
||||
public WarpCommand(MapParser plugin)
|
||||
{
|
||||
super(plugin, "warp");
|
||||
setUsage("/warp <name> & /warp <set> <name>");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(Player player, String alias, String[] args)
|
||||
{
|
||||
if (player.getWorld().getName().equals("world_lobby"))
|
||||
{
|
||||
message(player, "Cannot use warps in Lobby.");
|
||||
return true;
|
||||
}
|
||||
MapData data = getPlugin().getData(player.getWorld().getName());
|
||||
|
||||
if(data == null)
|
||||
{
|
||||
player.sendMessage(C.cRed + "There was an error with your map.");
|
||||
return true;
|
||||
}
|
||||
|
||||
Map<String, Location> warps = data._warps;
|
||||
|
||||
if(args.length == 1)
|
||||
{
|
||||
if(args[0].equalsIgnoreCase("list"))
|
||||
{
|
||||
for(String s : warps.keySet())
|
||||
{
|
||||
player.sendMessage(F.elem(s) + " @ " + F.elem(UtilWorld.locToStrClean(warps.get(s))));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
Location location = warps.get(args[0].toLowerCase());
|
||||
|
||||
if(location == null){
|
||||
player.sendMessage(C.cRed + "Unknown warp!");
|
||||
return true;
|
||||
}
|
||||
|
||||
player.sendMessage(C.cGray + "Warping to " + F.elem(args[0]));
|
||||
player.teleport(location);
|
||||
return true;
|
||||
}
|
||||
|
||||
if(args.length == 2)
|
||||
{
|
||||
if(!args[0].equalsIgnoreCase("set"))
|
||||
{
|
||||
player.sendMessage(C.cRed + "Please use " + F.elem("/warp set <name>") + C.cRed + " to set a warp");
|
||||
return true;
|
||||
}
|
||||
String warp = args[1].toLowerCase();
|
||||
if(warps.containsKey(warp))
|
||||
{
|
||||
player.sendMessage(C.cRed + "That warp already exists!");
|
||||
return true;
|
||||
}
|
||||
warps.put(warp, player.getLocation());
|
||||
player.sendMessage(C.cGray + "Created a new warp: " + F.elem(warp));
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,29 @@
|
||||
package mineplex.mapparser.command;
|
||||
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import mineplex.mapparser.MapParser;
|
||||
|
||||
/**
|
||||
* Created by Shaun on 8/15/2014.
|
||||
*/
|
||||
public class WorldsCommand extends BaseCommand
|
||||
{
|
||||
public WorldsCommand(MapParser plugin)
|
||||
{
|
||||
super(plugin, "worlds");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(Player player, String alias, String[] args)
|
||||
{
|
||||
message(player, "Listing Active Worlds;");
|
||||
|
||||
for (World world : getPlugin().getServer().getWorlds())
|
||||
{
|
||||
player.sendMessage(world.getName());
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
@ -0,0 +1,91 @@
|
||||
package mineplex.mapparser.command.teleport;
|
||||
|
||||
import java.util.LinkedList;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
import mineplex.core.common.Pair;
|
||||
import mineplex.core.common.util.C;
|
||||
import mineplex.core.common.util.F;
|
||||
import mineplex.mapparser.command.BaseCommand;
|
||||
|
||||
public class BackCommand extends BaseCommand
|
||||
{
|
||||
private TeleportManager _teleportManager;
|
||||
|
||||
public BackCommand(TeleportManager teleportManager)
|
||||
{
|
||||
super(teleportManager.getPlugin(), "back", "tpback");
|
||||
|
||||
_teleportManager = teleportManager;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(Player player, String alias, String[] args)
|
||||
{
|
||||
LinkedList<Pair<Vector, String>> teleportHistory = _teleportManager.getTeleportHistory(player);
|
||||
|
||||
if (teleportHistory == null || teleportHistory.isEmpty())
|
||||
{
|
||||
message(player, "You don't have any teleport history.");
|
||||
return true;
|
||||
}
|
||||
|
||||
int steps = 1;
|
||||
|
||||
if (args.length > 0)
|
||||
{
|
||||
try
|
||||
{
|
||||
steps = Integer.parseInt(args[0]);
|
||||
|
||||
if (steps < 1)
|
||||
{
|
||||
throw new NumberFormatException("Steps must be >0");
|
||||
}
|
||||
}
|
||||
catch (NumberFormatException ex)
|
||||
{
|
||||
message(player, "Please enter a valid number of steps to teleport back.");
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
Pair<Vector, String> locationPair = null;
|
||||
|
||||
if (steps == 1)
|
||||
{
|
||||
locationPair = teleportHistory.removeFirst();
|
||||
}
|
||||
else
|
||||
{
|
||||
for (int i = 0; i < steps; i++)
|
||||
{
|
||||
locationPair = teleportHistory.remove(i);
|
||||
}
|
||||
}
|
||||
|
||||
if (locationPair == null)
|
||||
{
|
||||
message(player, "Something went wrong. Couldn't teleport you back.");
|
||||
return true;
|
||||
}
|
||||
|
||||
World locationWorld =_teleportManager.getPlugin().getWorldFromName(locationPair.getRight());
|
||||
Vector locationVec = locationPair.getLeft();
|
||||
Location location = new Location(locationWorld, locationVec.getX(), locationVec.getY(), locationVec.getZ());
|
||||
|
||||
if (!_teleportManager.canTeleportTo(player, location))
|
||||
{
|
||||
message(player, "You don't have access to teleport back to that location.");
|
||||
return true;
|
||||
}
|
||||
|
||||
player.teleport(location);
|
||||
message(player, "You undid your last " + ((steps == 1) ? "teleport." : F.count(steps) + C.mBody + " teleports."));
|
||||
return true;
|
||||
}
|
||||
}
|
@ -0,0 +1,173 @@
|
||||
package mineplex.mapparser.command.teleport;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import mineplex.core.common.util.C;
|
||||
import mineplex.core.common.util.F;
|
||||
import mineplex.core.common.util.UtilPlayerBase;
|
||||
import mineplex.mapparser.MapData;
|
||||
import mineplex.mapparser.MapParser;
|
||||
import mineplex.mapparser.command.BaseCommand;
|
||||
|
||||
public class TeleportCommand extends BaseCommand
|
||||
{
|
||||
private final static List<String> COMMANDS = Arrays.asList(
|
||||
"/tp <player> - Teleport to another player",
|
||||
"/tp <from> <destination> - Teleport the from player to the destination player",
|
||||
"/tp <x> <y> <z> - Teleport to coordinates"
|
||||
);
|
||||
private final static String COORDINATE_FORMAT = "%.2f";
|
||||
private TeleportManager _teleportManager;
|
||||
|
||||
public TeleportCommand(TeleportManager teleportManager)
|
||||
{
|
||||
super(teleportManager.getPlugin(), "tp", "teleport");
|
||||
|
||||
_teleportManager = teleportManager;
|
||||
}
|
||||
|
||||
private static String formatCoordinate(double in)
|
||||
{
|
||||
return String.format(COORDINATE_FORMAT, in);
|
||||
}
|
||||
|
||||
private static Double parseCoordinate(String in, double beginning)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (in.startsWith("~"))
|
||||
{
|
||||
if (in.length() == 1)
|
||||
{
|
||||
return beginning;
|
||||
}
|
||||
|
||||
String relativeIn = in.substring(1);
|
||||
|
||||
double relative = Double.parseDouble(relativeIn);
|
||||
|
||||
return beginning + relative;
|
||||
}
|
||||
|
||||
return Double.parseDouble(in);
|
||||
}
|
||||
catch (NumberFormatException ex)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private void help(Player player)
|
||||
{
|
||||
player.sendMessage(F.main(getPlugin().getName(), "Teleport command usage:"));
|
||||
COMMANDS.stream().map(c ->
|
||||
{
|
||||
List<String> parts = Arrays.stream(c.split("\\s*-\\s*")).collect(Collectors.toList());
|
||||
|
||||
String commandMessage = " ";
|
||||
|
||||
commandMessage += C.cYellow + parts.get(0);
|
||||
commandMessage += C.cGray + " - ";
|
||||
commandMessage += C.cGold + parts.get(1);
|
||||
|
||||
return commandMessage;
|
||||
}).forEach(player::sendMessage);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(Player player, String alias, String[] args)
|
||||
{
|
||||
if (args.length == 1)
|
||||
{
|
||||
Player target = UtilPlayerBase.searchOnline(player, args[0], true);
|
||||
|
||||
if (target == null)
|
||||
{
|
||||
// Player has already been informed
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!_teleportManager.canTeleportTo(player, target.getLocation()))
|
||||
{
|
||||
message(player, "That map is currently locked, and you don't have access to enter it.");
|
||||
return true;
|
||||
}
|
||||
|
||||
message(player, "You teleported to " + F.name(target.getName()) + C.mBody + ".");
|
||||
_teleportManager.teleportPlayer(player, target);
|
||||
}
|
||||
// Teleport player to player
|
||||
else if (args.length == 2)
|
||||
{
|
||||
// They must be OP to teleport a player to another player
|
||||
if (!player.isOp())
|
||||
{
|
||||
message(player, "You don't have permission to teleport players to other players.");
|
||||
return true;
|
||||
}
|
||||
|
||||
Player sending = UtilPlayerBase.searchOnline(player, args[0], true);
|
||||
|
||||
if (sending == null)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
Player destination = UtilPlayerBase.searchOnline(player, args[1], true);
|
||||
|
||||
if (destination == null)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
message(player, "You teleported " + F.name(sending.getName()) + " to " + F.name(destination.getName()) + C.mBody + ".");
|
||||
_teleportManager.teleportPlayer(sending, destination);
|
||||
}
|
||||
// Teleport to coordinates...
|
||||
else if (args.length == 3)
|
||||
{
|
||||
List<Double> coordinates = new ArrayList<>();
|
||||
|
||||
coordinates.add(parseCoordinate(args[0], player.getLocation().getX()));
|
||||
coordinates.add(parseCoordinate(args[1], player.getLocation().getY()));
|
||||
coordinates.add(parseCoordinate(args[2], player.getLocation().getZ()));
|
||||
|
||||
for (Double coordinate : coordinates)
|
||||
{
|
||||
if (coordinate == null)
|
||||
{
|
||||
message(player, "Hmm, those coordinates don't look quite right.");
|
||||
help(player);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
Location destination = player.getLocation().clone();
|
||||
destination.setX(coordinates.get(0));
|
||||
destination.setY(coordinates.get(1));
|
||||
destination.setZ(coordinates.get(2));
|
||||
|
||||
message(player, "You teleported to ("
|
||||
+ F.name(formatCoordinate(destination.getX()))
|
||||
+ C.mBody + ", "
|
||||
+ F.name(formatCoordinate(destination.getY()))
|
||||
+ C.mBody + ", "
|
||||
+ F.name(formatCoordinate(destination.getZ()))
|
||||
+ C.mBody + ").");
|
||||
_teleportManager.teleportPlayer(player, destination);
|
||||
}
|
||||
else
|
||||
{
|
||||
message(player, "Hmm, your command doesn't look quite right.");
|
||||
help(player);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
@ -0,0 +1,63 @@
|
||||
package mineplex.mapparser.command.teleport;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedList;
|
||||
import java.util.Map;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
import mineplex.core.common.Pair;
|
||||
import mineplex.mapparser.MapData;
|
||||
import mineplex.mapparser.MapParser;
|
||||
|
||||
public class TeleportManager
|
||||
{
|
||||
private MapParser _plugin;
|
||||
private Map<Player, LinkedList<Pair<Vector, String>>> _teleportHistory;
|
||||
|
||||
public TeleportManager(MapParser plugin)
|
||||
{
|
||||
_plugin = plugin;
|
||||
_teleportHistory = new HashMap<>();
|
||||
}
|
||||
|
||||
private void addToHistory(Player player, Location location)
|
||||
{
|
||||
_teleportHistory.computeIfAbsent(player, key -> new LinkedList<>()).addFirst(Pair.create(new Vector(location.getX(), location.getY(), location.getZ()), location.getWorld().getName()));
|
||||
}
|
||||
|
||||
public LinkedList<Pair<Vector, String>> getTeleportHistory(Player player)
|
||||
{
|
||||
return _teleportHistory.get(player);
|
||||
}
|
||||
|
||||
public void teleportPlayer(Player player, Location destination)
|
||||
{
|
||||
addToHistory(player, player.getLocation().clone());
|
||||
player.teleport(destination);
|
||||
}
|
||||
|
||||
public void teleportPlayer(Player player, Player destination)
|
||||
{
|
||||
teleportPlayer(player, destination.getLocation());
|
||||
}
|
||||
|
||||
public boolean canTeleportTo(Player player, Location target)
|
||||
{
|
||||
if (target.getWorld().getName().equals("world") || target.getWorld().getName().equals("world_lobby"))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
MapData data = getPlugin().getData(target.getWorld().getName());
|
||||
|
||||
return data.CanJoin(player);
|
||||
}
|
||||
|
||||
public MapParser getPlugin()
|
||||
{
|
||||
return _plugin;
|
||||
}
|
||||
}
|
@ -0,0 +1,39 @@
|
||||
package mineplex.mapparser.command.teleport;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import mineplex.core.common.util.C;
|
||||
import mineplex.mapparser.command.BaseCommand;
|
||||
|
||||
public class TopCommand extends BaseCommand
|
||||
{
|
||||
private TeleportManager _teleportManager;
|
||||
|
||||
public TopCommand(TeleportManager teleportManager)
|
||||
{
|
||||
super(teleportManager.getPlugin(), "top");
|
||||
|
||||
_teleportManager = teleportManager;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(Player player, String alias, String[] args)
|
||||
{
|
||||
Location destination = player.getLocation().clone();
|
||||
|
||||
destination.setY(256);
|
||||
|
||||
while (destination.getBlock().getType().equals(Material.AIR))
|
||||
{
|
||||
destination.add(0, -1, 0);
|
||||
}
|
||||
|
||||
_teleportManager.teleportPlayer(player, destination.add(0, 1, 0));
|
||||
|
||||
message(player, "You have been teleported to Y = " + C.cYellow + destination.getY());
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
@ -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));
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,124 @@
|
||||
package mineplex.mapparser.module.modules;
|
||||
|
||||
import com.google.common.collect.Maps;
|
||||
import mineplex.core.common.util.F;
|
||||
import mineplex.core.common.util.UtilPlayerBase;
|
||||
import mineplex.mapparser.MapParser;
|
||||
import mineplex.mapparser.command.BaseCommand;
|
||||
import mineplex.mapparser.module.Module;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public class CommandModule extends Module
|
||||
{
|
||||
private Map<String, BaseCommand> _commands = Maps.newHashMap();
|
||||
private Map<String, BaseCommand> _commandsByAlias = Maps.newHashMap();
|
||||
|
||||
public CommandModule(MapParser plugin)
|
||||
{
|
||||
super("Commands", plugin);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void preventMe(PlayerCommandPreprocessEvent event)
|
||||
{
|
||||
if (event.getMessage().toLowerCase().startsWith("/bukkit")
|
||||
|| event.getMessage().toLowerCase().startsWith("/minecraft"))
|
||||
{
|
||||
if (!event.getPlayer().isOp())
|
||||
{
|
||||
event.getPlayer().sendMessage(F.main("Parser", "Nope, not allowed!"));
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@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)
|
||||
{
|
||||
UtilPlayerBase.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.canRun(player))
|
||||
{
|
||||
player.sendMessage(F.main(getPlugin().getName(), "You don't have permission to do that."));
|
||||
return;
|
||||
}
|
||||
|
||||
if (!baseCommand.execute(player, commandLabel, args))
|
||||
{
|
||||
UtilPlayerBase.message(player, F.main("Parser", "Invalid Input."));
|
||||
UtilPlayerBase.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);
|
||||
}
|
||||
}
|
||||
|
||||
public Map<String, BaseCommand> getCommands()
|
||||
{
|
||||
return _commands;
|
||||
}
|
||||
}
|
@ -0,0 +1,276 @@
|
||||
package mineplex.mapparser.module.modules;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.GameMode;
|
||||
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 org.bukkit.event.weather.WeatherChangeEvent;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
|
||||
import mineplex.core.common.util.C;
|
||||
import mineplex.core.common.util.F;
|
||||
import mineplex.core.common.util.UtilPlayerBase;
|
||||
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;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public class EventModule extends Module
|
||||
{
|
||||
|
||||
private List<World> _updated = Lists.newArrayList();
|
||||
|
||||
public EventModule(MapParser plugin)
|
||||
{
|
||||
super("Events", plugin);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void PlayerJoin(PlayerJoinEvent event)
|
||||
{
|
||||
Player player = event.getPlayer();
|
||||
|
||||
player.teleport(getPlugin().getSpawnLocation());
|
||||
|
||||
displayHelp(player);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onTick(TickEvent event)
|
||||
{
|
||||
for (World world : getPlugin().getServer().getWorlds())
|
||||
{
|
||||
if (_updated.contains(world))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if (world.getName().toLowerCase().contains("halloween"))
|
||||
{
|
||||
world.setTime(16000);
|
||||
}
|
||||
else
|
||||
{
|
||||
world.setTime(8000);
|
||||
}
|
||||
world.setStorm(false);
|
||||
world.setGameRuleValue("doDaylightCycle", "false");
|
||||
_updated.add(world);
|
||||
}
|
||||
}
|
||||
|
||||
@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_lobby"))
|
||||
{
|
||||
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()));
|
||||
getPlugin().getServer().unloadWorld(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 : getPlugin().getServer().getOnlinePlayers())
|
||||
{
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
//#################################################################################################
|
||||
//# #
|
||||
//# Simple methods #
|
||||
//# #
|
||||
//# #
|
||||
//#################################################################################################
|
||||
|
||||
@EventHandler
|
||||
public void Join(PlayerJoinEvent event)
|
||||
{
|
||||
event.setJoinMessage(F.sys("Player Join", event.getPlayer().getName()));
|
||||
|
||||
event.getPlayer().setGameMode(GameMode.CREATIVE);
|
||||
event.getPlayer().setFlying(true);
|
||||
}
|
||||
|
||||
@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);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void DisableWeather(WeatherChangeEvent event)
|
||||
{
|
||||
if (!_updated.contains(event.getWorld()))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,112 @@
|
||||
package mineplex.mapparser.module.modules;
|
||||
|
||||
import mineplex.core.common.util.UtilTime;
|
||||
import mineplex.core.common.util.UtilWorld;
|
||||
import mineplex.mapparser.MapParser;
|
||||
import mineplex.mapparser.module.Module;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.block.SignChangeEvent;
|
||||
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
|
||||
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.File;
|
||||
import java.io.FileWriter;
|
||||
import java.util.ArrayList;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public class SignModule extends Module
|
||||
{
|
||||
public SignModule(MapParser plugin)
|
||||
{
|
||||
super("Sign", plugin);
|
||||
}
|
||||
|
||||
|
||||
@EventHandler(priority = EventPriority.LOWEST)
|
||||
public void signChangeLog(SignChangeEvent event)
|
||||
{
|
||||
if (GetData(event.getPlayer().getWorld().getName()).HasAccess(event.getPlayer()))
|
||||
{
|
||||
ArrayList<String> text = new ArrayList<>();
|
||||
|
||||
text.add("Date: " + UtilTime.now());
|
||||
text.add("Player: " + event.getPlayer().getName());
|
||||
text.add("Location: " + UtilWorld.locToStrClean(event.getBlock().getLocation()));
|
||||
for (int i = 0; i < event.getLines().length; i++)
|
||||
{
|
||||
text.add("Line " + i + ": " + event.getLines()[i]);
|
||||
}
|
||||
writeSignLog(text, event.getPlayer().getWorld());
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.LOWEST)
|
||||
public void signCommand(PlayerCommandPreprocessEvent event)
|
||||
{
|
||||
if (event.getMessage().toLowerCase().contains("set"))
|
||||
{
|
||||
ArrayList<String> text = new ArrayList<>();
|
||||
|
||||
text.add("Date: " + UtilTime.now());
|
||||
text.add("Player: " + event.getPlayer().getName());
|
||||
text.add("Location: " + UtilWorld.locToStrClean(event.getPlayer().getLocation()));
|
||||
text.add("Message: " + event.getMessage());
|
||||
|
||||
writeSignCommandLog(text, event.getPlayer().getWorld());
|
||||
}
|
||||
}
|
||||
|
||||
public void writeSignCommandLog(ArrayList<String> text, World world)
|
||||
{
|
||||
try
|
||||
{
|
||||
File file = new File(world.getName() + "/" + "command_sign_log.txt");
|
||||
|
||||
if (!file.exists())
|
||||
{
|
||||
file.createNewFile();
|
||||
}
|
||||
|
||||
FileWriter fw = new FileWriter(file.getAbsoluteFile(), true);
|
||||
BufferedWriter bw = new BufferedWriter(fw);
|
||||
|
||||
bw.write("\n\n");
|
||||
for (String line : text)
|
||||
bw.write("\n" + line);
|
||||
|
||||
bw.close();
|
||||
} catch (Exception e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public void writeSignLog(ArrayList<String> text, World world)
|
||||
{
|
||||
try
|
||||
{
|
||||
File file = new File(world.getName() + "/" + "sign_log.txt");
|
||||
|
||||
if (!file.exists())
|
||||
{
|
||||
file.createNewFile();
|
||||
}
|
||||
|
||||
FileWriter fw = new FileWriter(file.getAbsoluteFile(), true);
|
||||
BufferedWriter bw = new BufferedWriter(fw);
|
||||
|
||||
bw.write("\n\n");
|
||||
for (String line : text)
|
||||
bw.write("\n" + line);
|
||||
|
||||
bw.close();
|
||||
} catch (Exception e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,119 @@
|
||||
package mineplex.mapparser.module.modules;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.collect.Maps;
|
||||
import com.google.common.collect.Sets;
|
||||
import mineplex.core.common.util.C;
|
||||
import mineplex.core.common.util.UtilEvent;
|
||||
import mineplex.core.common.util.UtilEvent.ActionType;
|
||||
import mineplex.core.common.util.UtilGear;
|
||||
import mineplex.mapparser.BlockData;
|
||||
import mineplex.mapparser.MapParser;
|
||||
import mineplex.mapparser.module.Module;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.block.Action;
|
||||
import org.bukkit.event.player.PlayerInteractEvent;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public class TreeToolModule extends Module
|
||||
{
|
||||
|
||||
private Map<UUID, List<Set<BlockData>>> _treeHistory = Maps.newHashMap();
|
||||
|
||||
public TreeToolModule(MapParser plugin)
|
||||
{
|
||||
super("TreeTool", plugin);
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST)
|
||||
public void treeRemover(PlayerInteractEvent event)
|
||||
{
|
||||
if (event.isCancelled())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
//Permission
|
||||
if (!getPlugin().getData(event.getPlayer().getWorld().getName()).HasAccess(event.getPlayer()))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Player player = event.getPlayer();
|
||||
|
||||
if (!UtilGear.isMat(player.getItemInHand(), Material.NETHER_STAR))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
event.setCancelled(true);
|
||||
|
||||
//Remove
|
||||
if (event.getAction() == Action.LEFT_CLICK_BLOCK)
|
||||
{
|
||||
if (event.getClickedBlock().getType() != Material.LOG)
|
||||
{
|
||||
player.sendMessage(C.cRed + C.Bold + "TreeTool: " + ChatColor.RESET + "Left-Click on Log");
|
||||
return;
|
||||
}
|
||||
|
||||
Set<Block> toRemove = getPlugin().searchLog(Sets.newHashSet(), event.getClickedBlock());
|
||||
|
||||
if (toRemove.isEmpty())
|
||||
{
|
||||
player.sendMessage(C.cRed + C.Bold + "TreeTool: " + ChatColor.RESET + "Left-Click on Log");
|
||||
return;
|
||||
}
|
||||
|
||||
Set<BlockData> history = Sets.newHashSet();
|
||||
|
||||
for (Block block : toRemove)
|
||||
{
|
||||
history.add(new BlockData(block));
|
||||
|
||||
block.setType(Material.AIR);
|
||||
}
|
||||
|
||||
if (!_treeHistory.containsKey(player.getUniqueId()))
|
||||
{
|
||||
_treeHistory.put(player.getUniqueId(), Lists.newArrayList());
|
||||
}
|
||||
|
||||
_treeHistory.get(player.getUniqueId()).add(0, history);
|
||||
|
||||
player.sendMessage(C.cRed + C.Bold + "TreeTool: " + ChatColor.RESET + "Tree Removed");
|
||||
|
||||
while (_treeHistory.get(player.getUniqueId()).size() > 10)
|
||||
{
|
||||
_treeHistory.get(player.getUniqueId()).remove(10);
|
||||
}
|
||||
|
||||
} else if (UtilEvent.isAction(event, ActionType.R))
|
||||
{
|
||||
if (!_treeHistory.containsKey(player.getUniqueId()) || _treeHistory.get(player.getUniqueId()).isEmpty())
|
||||
{
|
||||
player.sendMessage(C.cGreen + C.Bold + "TreeTool: " + ChatColor.RESET + "No Tree History");
|
||||
return;
|
||||
}
|
||||
|
||||
Set<BlockData> datas = _treeHistory.get(player.getUniqueId()).remove(0);
|
||||
|
||||
datas.forEach(BlockData::restore);
|
||||
|
||||
player.sendMessage(C.cGreen + C.Bold + "TreeTool: " + ChatColor.RESET + "Tree Restored");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user