use of pl.plajer.villagedefense3.arena.Arena in project Village_Defense by Plajer.
the class MainCommand method performSetup.
void performSetup(Player player, String[] args) {
if (args[1].equalsIgnoreCase("setup") || args[1].equals("edit")) {
if (ArenaRegistry.getArena(args[0]) == null) {
player.sendMessage(ChatManager.PLUGIN_PREFIX + ChatManager.colorMessage("Commands.No-Arena-Like-That"));
return;
}
new SetupInventory(ArenaRegistry.getArena(args[0])).openInventory(player);
return;
}
if (!(args.length > 2))
return;
FileConfiguration config = ConfigurationManager.getConfig("arenas");
if (!config.contains("instances." + args[0])) {
player.sendMessage(ChatManager.PLUGIN_PREFIX + ChatManager.colorMessage("Commands.No-Arena-Like-That"));
player.sendMessage(ChatColor.RED + "Usage: /vd < ARENA ID > set <MINPLAYRS | MAXPLAYERS | MAPNAME | SCHEMATIC | LOBBYLOCATION | EndLOCATION | STARTLOCATION > < VALUE>");
return;
}
if (args[1].equalsIgnoreCase("addspawn")) {
if (args[2].equalsIgnoreCase("zombie")) {
int i;
if (!config.contains("instances." + args[0] + ".zombiespawns")) {
i = 0;
} else {
i = config.getConfigurationSection("instances." + args[0] + ".zombiespawns").getKeys(false).size();
}
i++;
Util.saveLoc("instances." + args[0] + ".zombiespawns." + i, player.getLocation(), false);
player.sendMessage(ChatColor.GREEN + "Zombie spawn added!");
return;
}
if (args[2].equalsIgnoreCase("villager")) {
int i;
if (!config.contains("instances." + args[0] + ".villagerspawns")) {
i = 0;
} else {
i = config.getConfigurationSection("instances." + args[0] + ".villagerspawns").getKeys(false).size();
}
i++;
Util.saveLoc("instances." + args[0] + ".villagerspawns." + i, player.getLocation(), false);
player.sendMessage(ChatColor.GREEN + "Villager spawn added!");
return;
}
if (args[2].equalsIgnoreCase("doors")) {
String ID = args[0];
int counter = 0;
int i;
if (plugin.getWorldEditPlugin().getSelection(player) == null)
return;
if (!config.contains("instances." + ID + ".doors")) {
i = 0;
} else {
i = config.getConfigurationSection("instances." + ID + ".doors").getKeys(false).size();
}
i++;
Selection selection = plugin.getWorldEditPlugin().getSelection(player);
if (selection instanceof CuboidSelection) {
CuboidSelection cuboidSelection = (CuboidSelection) selection;
Vector min = cuboidSelection.getNativeMinimumPoint();
Vector max = cuboidSelection.getNativeMaximumPoint();
for (int x = min.getBlockX(); x <= max.getBlockX(); x = x + 1) {
for (int y = min.getBlockY(); y <= max.getBlockY(); y = y + 1) {
for (int z = min.getBlockZ(); z <= max.getBlockZ(); z = z + 1) {
Location temporaryBlock = new Location(player.getWorld(), x, y, z);
if (temporaryBlock.getBlock().getType() == Material.WOODEN_DOOR) {
String location = temporaryBlock.getWorld().getName() + "," + temporaryBlock.getX() + "," + temporaryBlock.getY() + "," + temporaryBlock.getZ() + "," + temporaryBlock.getYaw() + "," + temporaryBlock.getPitch();
config.set("instances." + ID + ".doors." + i + ".location", location);
config.set("instances." + ID + ".doors." + i + ".byte", temporaryBlock.getBlock().getData());
counter++;
i++;
}
}
}
}
} else {
if (selection.getMaximumPoint().getBlock().getType() == Material.WOODEN_DOOR) {
String location = selection.getMaximumPoint().getWorld().getName() + "," + selection.getMaximumPoint().getX() + "," + selection.getMaximumPoint().getY() + "," + selection.getMaximumPoint().getZ() + "," + selection.getMaximumPoint().getYaw() + "," + selection.getMaximumPoint().getPitch();
config.set("instances." + ID + ".doors." + i + ".location", location);
config.set("instances." + ID + ".doors." + i + ".byte", selection.getMaximumPoint().getBlock().getData());
counter++;
i++;
}
if (selection.getMinimumPoint().getBlock().getType() == Material.WOODEN_DOOR) {
String location = selection.getMaximumPoint().getWorld().getName() + "," + selection.getMaximumPoint().getX() + "," + selection.getMaximumPoint().getY() + "," + selection.getMaximumPoint().getZ() + "," + selection.getMaximumPoint().getYaw() + "," + selection.getMaximumPoint().getPitch();
config.set("instances." + ID + ".doors." + i + ".location", location);
config.set("instances." + ID + ".doors." + i + ".byte", selection.getMinimumPoint().getBlock().getData());
counter++;
i++;
}
}
player.sendMessage(ChatColor.GREEN + "" + (int) Math.ceil(counter / 2) + " doors were added!");
}
ConfigurationManager.saveConfig(config, "arenas");
return;
}
if (!(args[1].equalsIgnoreCase("set")))
return;
if (args.length == 3) {
if (args[2].equalsIgnoreCase("lobbylocation") || args[2].equalsIgnoreCase("lobbyloc")) {
String location = player.getLocation().getWorld().getName() + "," + player.getLocation().getX() + "," + player.getLocation().getY() + "," + player.getLocation().getZ() + "," + player.getLocation().getYaw() + "," + player.getLocation().getPitch();
config.set("instances." + args[0] + ".lobbylocation", location);
player.sendMessage("VillageDefense: Lobby location for arena/instance " + args[0] + " set to " + Util.locationToString(player.getLocation()));
} else if (args[2].equalsIgnoreCase("Startlocation") || args[2].equalsIgnoreCase("Startloc")) {
String location = player.getLocation().getWorld().getName() + "," + player.getLocation().getX() + "," + player.getLocation().getY() + "," + player.getLocation().getZ() + "," + player.getLocation().getYaw() + "," + player.getLocation().getPitch();
config.set("instances." + args[0] + ".Startlocation", location);
player.sendMessage("VillageDefense: Start location for arena/instance " + args[0] + " set to " + Util.locationToString(player.getLocation()));
} else if (args[2].equalsIgnoreCase("Endlocation") || args[2].equalsIgnoreCase("Endloc")) {
String location = player.getLocation().getWorld().getName() + "," + player.getLocation().getX() + "," + player.getLocation().getY() + "," + player.getLocation().getZ() + "," + player.getLocation().getYaw() + "," + player.getLocation().getPitch();
config.set("instances." + args[0] + ".Endlocation", location);
player.sendMessage("VillageDefense: End location for arena/instance " + args[0] + " set to " + Util.locationToString(player.getLocation()));
} else {
player.sendMessage(ChatColor.RED + "Invalid Command!");
player.sendMessage(ChatColor.RED + "Usage: /vd <ARENA > set <StartLOCTION | LOBBYLOCATION | EndLOCATION>");
}
} else if (args.length == 4) {
if (args[2].equalsIgnoreCase("MAXPLAYERS") || args[2].equalsIgnoreCase("maximumplayers")) {
config.set("instances." + args[0] + ".maximumplayers", Integer.parseInt(args[3]));
player.sendMessage("VillageDefense: Maximum players for arena/instance " + args[0] + " set to " + Integer.parseInt(args[3]));
} else if (args[2].equalsIgnoreCase("MINPLAYERS") || args[2].equalsIgnoreCase("minimumplayers")) {
config.set("instances." + args[0] + ".minimumplayers", Integer.parseInt(args[3]));
player.sendMessage("VillageDefense: Minimum players for arena/instance " + args[0] + " set to " + Integer.parseInt(args[3]));
} else if (args[2].equalsIgnoreCase("MAPNAME") || args[2].equalsIgnoreCase("NAME")) {
config.set("instances." + args[0] + ".mapname", args[3]);
player.sendMessage("VillageDefense: Map name for arena/instance " + args[0] + " set to " + args[3]);
} else if (args[2].equalsIgnoreCase("WORLD") || args[2].equalsIgnoreCase("MAP")) {
boolean exists = false;
for (World world : Bukkit.getWorlds()) {
if (world.getName().equalsIgnoreCase(args[3]))
exists = true;
}
if (!exists) {
player.sendMessage(ChatManager.PLUGIN_PREFIX + ChatColor.RED + "That world doesn't exists!");
return;
}
config.set("instances." + args[0] + ".world", args[3]);
player.sendMessage("VillageDefense: World for arena/instance " + args[0] + " set to " + args[3]);
} else {
player.sendMessage(ChatColor.RED + "Invalid Command!");
player.sendMessage(ChatColor.RED + "Usage: /vd set <MINPLAYERS | MAXPLAYERS> <value>");
}
}
ConfigurationManager.saveConfig(config, "arenas");
}
use of pl.plajer.villagedefense3.arena.Arena in project Village_Defense by Plajer.
the class MainCommand method createInstanceInConfig.
private void createInstanceInConfig(String ID, String worldName) {
String path = "instances." + ID + ".";
Util.saveLoc(path + "lobbylocation", Bukkit.getServer().getWorlds().get(0).getSpawnLocation(), false);
Util.saveLoc(path + "Startlocation", Bukkit.getServer().getWorlds().get(0).getSpawnLocation(), false);
Util.saveLoc(path + "Endlocation", Bukkit.getServer().getWorlds().get(0).getSpawnLocation(), false);
FileConfiguration config = ConfigurationManager.getConfig("arenas");
config.set(path + "minimumplayers", 1);
config.set(path + "maximumplayers", 10);
config.set(path + "mapname", ID);
config.set(path + "signs", new ArrayList<>());
config.set(path + "isdone", false);
config.set(path + "world", worldName);
ConfigurationManager.saveConfig(config, "arenas");
Arena arena;
if (plugin.is1_8_R3()) {
arena = new ArenaInitializer1_8_R3(ID, plugin);
} else if (plugin.is1_9_R1()) {
arena = new ArenaInitializer1_9_R1(ID, plugin);
} else if (plugin.is1_11_R1()) {
arena = new ArenaInitializer1_11_R1(ID, plugin);
} else {
arena = new ArenaInitializer1_12_R1(ID, plugin);
}
arena.setMinimumPlayers(ConfigurationManager.getConfig("arenas").getInt(path + "minimumplayers"));
arena.setMaximumPlayers(ConfigurationManager.getConfig("arenas").getInt(path + "maximumplayers"));
arena.setMapName(ConfigurationManager.getConfig("arenas").getString(path + "mapname"));
arena.setLobbyLocation(Util.getLocation(false, ConfigurationManager.getConfig("arenas").getString(path + "lobbylocation")));
arena.setStartLocation(Util.getLocation(false, ConfigurationManager.getConfig("arenas").getString(path + "Startlocation")));
arena.setEndLocation(Util.getLocation(false, ConfigurationManager.getConfig("arenas").getString(path + "Endlocation")));
arena.setReady(false);
ArenaRegistry.registerArena(arena);
}
use of pl.plajer.villagedefense3.arena.Arena in project Village_Defense by Plajer.
the class MainCommand method onTpCommand.
void onTpCommand(Player player, String ID, LocationType type) {
if (!ConfigurationManager.getConfig("arenas").contains("instances." + ID)) {
player.sendMessage(ChatManager.PLUGIN_PREFIX + ChatManager.colorMessage("Commands.No-Arena-Like-That"));
return;
}
Arena arena = ArenaRegistry.getArena(ID);
switch(type) {
case LOBBY:
if (arena.getLobbyLocation() == null) {
player.sendMessage(ChatColor.RED + "Lobby location isn't set for this arena!");
return;
}
arena.teleportToLobby(player);
player.sendMessage(ChatColor.GRAY + "Teleported to LOBBY location from arena" + ID);
break;
case START:
if (arena.getLobbyLocation() == null) {
player.sendMessage(ChatColor.RED + "Start location isn't set for this arena!");
return;
}
arena.teleportToStartLocation(player);
player.sendMessage(ChatColor.GRAY + "Teleported to START location from arena" + ID);
break;
case END:
if (arena.getLobbyLocation() == null) {
player.sendMessage(ChatColor.RED + "End location isn't set for this arena!");
return;
}
arena.teleportToEndLocation(player);
player.sendMessage(ChatColor.GRAY + "Teleported to END location from arena" + ID);
break;
default:
// o.o
break;
}
}
use of pl.plajer.villagedefense3.arena.Arena in project Village_Defense by Plajer.
the class Arena method leaveAttempt.
/**
* Attempts player to leave arena.
* Calls VillageGameLeaveAttemptEvent event.
*
* @param p player to join
* @see VillageGameLeaveAttemptEvent
*/
public void leaveAttempt(Player p) {
VillageGameLeaveAttemptEvent villageGameLeaveAttemptEvent = new VillageGameLeaveAttemptEvent(p, this);
Bukkit.getPluginManager().callEvent(villageGameLeaveAttemptEvent);
if (Main.isDebugged()) {
System.out.println("[Village Debugger] Player " + p.getName() + " is attemping to leave arena!");
}
User user = UserManager.getUser(p.getUniqueId());
user.setInt("orbs", 0);
p.getInventory().clear();
ArmorHelper.clearArmor(p);
this.removePlayer(p);
if (!user.isSpectator()) {
ChatManager.broadcastLeaveMessage(this, p);
}
user.setFakeDead(false);
user.setSpectator(false);
user.removeScoreboard();
if (user.getKit() instanceof GolemFriendKit) {
for (IronGolem ironGolem : getIronGolems()) {
if (ironGolem.getCustomName().contains(user.toPlayer().getName()))
ironGolem.remove();
}
}
if (plugin.isBossbarEnabled()) {
gameBar.removePlayer(p);
}
p.setMaxHealth(20.0);
p.setHealth(p.getMaxHealth());
p.setFoodLevel(20);
p.setFlying(false);
p.setAllowFlight(false);
for (PotionEffect effect : p.getActivePotionEffects()) {
p.removePotionEffect(effect.getType());
}
p.setFireTicks(0);
if (getPlayers().size() == 0) {
this.setArenaState(ArenaState.RESTARTING);
}
p.setGameMode(GameMode.SURVIVAL);
for (Player players : plugin.getServer().getOnlinePlayers()) {
if (ArenaRegistry.getArena(players) != null)
players.showPlayer(p);
p.showPlayer(players);
}
this.teleportToEndLocation(p);
if (!plugin.isBungeeActivated() && plugin.isInventoryManagerEnabled()) {
plugin.getInventoryManager().loadInventory(p);
}
}
use of pl.plajer.villagedefense3.arena.Arena in project Village_Defense by Plajer.
the class Arena method stopGame.
/**
* Stops current arena. Calls VillageGameStopEvent event
*
* @param quickStop should arena be stopped immediately? (use only in important cases)
* @see VillageGameStopEvent
*/
public void stopGame(boolean quickStop) {
VillageGameStopEvent villageGameStopEvent = new VillageGameStopEvent(this);
Bukkit.getPluginManager().callEvent(villageGameStopEvent);
if (getPlayersLeft().size() > 0) {
for (Player p : getPlayers()) {
p.sendMessage(ChatManager.PLUGIN_PREFIX + ChatManager.colorMessage("In-Game.Messages.Game-End-Messages.All-Villagers-Died"));
p.sendMessage(ChatManager.PLUGIN_PREFIX + ChatManager.colorMessage("In-Game.Messages.Game-End-Messages.Reached-Wave-X").replaceAll("%NUMBER%", String.valueOf(getWave())));
p.sendMessage(ChatManager.PLUGIN_PREFIX + ChatManager.colorMessage("In-Game.Messages.Game-End-Messages.Teleporting-To-Lobby-In-10-Seconds"));
}
} else {
for (Player p : getPlayers()) {
p.sendMessage(ChatManager.PLUGIN_PREFIX + ChatManager.colorMessage("In-Game.Messages.Game-End-Messages.All-Players-Died"));
p.sendMessage(ChatManager.PLUGIN_PREFIX + ChatManager.colorMessage("In-Game.Messages.Game-End-Messages.Reached-Wave-X").replaceAll("%NUMBER%", String.valueOf(getWave())));
p.sendMessage(ChatManager.PLUGIN_PREFIX + ChatManager.colorMessage("In-Game.Messages.Game-End-Messages.Teleporting-To-Lobby-In-10-Seconds"));
}
}
for (final Player player : getPlayers()) {
setStat(player, "highestwave", wave);
addExperience(player, wave);
UserManager.getUser(player.getUniqueId()).removeScoreboard();
if (!quickStop) {
if (plugin.getConfig().getBoolean("Firework-When-Game-Ends")) {
new BukkitRunnable() {
int i = 0;
public void run() {
if (i == 4)
this.cancel();
if (!getPlayers().contains(player))
this.cancel();
Util.spawnRandomFirework(player.getLocation());
i++;
}
}.runTaskTimer(plugin, 30, 30);
}
}
}
this.resetRottenFlesh();
this.restoreDoors();
for (Zombie zombie : getZombies()) {
zombie.remove();
}
zombies.clear();
for (IronGolem ironGolem : getIronGolems()) {
ironGolem.remove();
}
ironGolems.clear();
for (Villager villager : getVillagers()) {
villager.remove();
}
villagers.clear();
for (Wolf wolf : getWolfs()) {
wolf.remove();
}
wolfs.clear();
clearZombies();
clearGolems();
clearVillagers();
clearWolfs();
for (Entity entity : getStartLocation().getWorld().getEntities()) {
if (entity.getWorld().getName().equalsIgnoreCase(getStartLocation().getWorld().getName()) && entity.getLocation().distance(getStartLocation()) < 300)
if (entity.getType() != EntityType.PLAYER)
entity.remove();
}
}
Aggregations