mirror of
https://github.com/taoneill/war.git
synced 2025-01-21 14:51:25 +01:00
Taking ownership of the /war prefix
This commit is contained in:
parent
6f3b4c8275
commit
631ff256c1
@ -1,3 +1,3 @@
|
||||
War, a simple hmod plugin that adds team deathmatch to minecraft multiplayer.
|
||||
|
||||
All credit goes to Mojang and the hey0 team for being so awesome.
|
||||
All credit goes to Mojang, hey0 and the Bukkit team for being so awesome.
|
@ -42,397 +42,418 @@ public class WarPlayerListener extends PlayerListener {
|
||||
Player player = event.getPlayer();
|
||||
String[] split = event.getMessage().split(" ");
|
||||
String command = split[0];
|
||||
|
||||
// Player commands: /warzones, /warzone, /teams, /join, /leave
|
||||
|
||||
// warzones
|
||||
if(command.equals("/warzones")){
|
||||
if(command.startsWith("/")) {
|
||||
|
||||
String warzonesMessage = "Warzones: ";
|
||||
if(war.getWarzones().isEmpty()){
|
||||
warzonesMessage += "none.";
|
||||
}
|
||||
for(Warzone warzone : war.getWarzones()) {
|
||||
|
||||
warzonesMessage += warzone.getName() + " ("
|
||||
+ warzone.getTeams().size() + " teams, ";
|
||||
int playerTotal = 0;
|
||||
for(Team team : warzone.getTeams()) {
|
||||
playerTotal += team.getPlayers().size();
|
||||
// Handle both /war <command> and /<war command>. I.e. "/war zone temple" == "/zone temple"
|
||||
String[] arguments = null;
|
||||
if(command.equals("/war")) {
|
||||
command = split[1];
|
||||
arguments = new String[split.length - 2];
|
||||
for(int i = 1; i <= arguments.length; i++) {
|
||||
arguments[i-1] = split[i];
|
||||
}
|
||||
warzonesMessage += playerTotal + " players) ";
|
||||
}
|
||||
player.sendMessage(war.str(warzonesMessage + " Use /warzone <zone-name> to " +
|
||||
"teleport to a warzone. "));
|
||||
event.setCancelled(true);
|
||||
}
|
||||
|
||||
// warzone
|
||||
else if(command.equals("/zone") || command.equals("/warzone")) {
|
||||
if(split.length < 2) {
|
||||
player.sendMessage(war.str("Usage: /zone <warzone-name>."));
|
||||
} else {
|
||||
boolean warped = false;
|
||||
command = command.substring(1, command.length()-1);
|
||||
arguments = new String[split.length - 1];
|
||||
for(int i = 1; i <= arguments.length; i++) {
|
||||
arguments[i-1] = split[i];
|
||||
}
|
||||
}
|
||||
|
||||
// Player commands: /warzones, /warzone, /teams, /join, /leave
|
||||
|
||||
// warzones
|
||||
if(command.equals("/warzones")){
|
||||
|
||||
String warzonesMessage = "Warzones: ";
|
||||
if(war.getWarzones().isEmpty()){
|
||||
warzonesMessage += "none.";
|
||||
}
|
||||
for(Warzone warzone : war.getWarzones()) {
|
||||
if(warzone.getName().equals(split[1]) && warzone.getTeleport() != null){
|
||||
player.teleportTo(warzone.getTeleport());
|
||||
warped = true;
|
||||
|
||||
warzonesMessage += warzone.getName() + " ("
|
||||
+ warzone.getTeams().size() + " teams, ";
|
||||
int playerTotal = 0;
|
||||
for(Team team : warzone.getTeams()) {
|
||||
playerTotal += team.getPlayers().size();
|
||||
}
|
||||
warzonesMessage += playerTotal + " players) ";
|
||||
}
|
||||
if(!warped) {
|
||||
player.sendMessage("No such warzone.");
|
||||
}
|
||||
player.sendMessage(war.str(warzonesMessage + " Use /warzone <zone-name> to " +
|
||||
"teleport to a warzone. "));
|
||||
event.setCancelled(true);
|
||||
}
|
||||
event.setCancelled(true);
|
||||
}
|
||||
|
||||
// /teams
|
||||
else if(command.equals("/teams")){
|
||||
if(!war.inAnyWarzone(player.getLocation())) {
|
||||
player.sendMessage(war.str("Usage: /teams. " +
|
||||
"Must be in a warzone (try /warzones and /warzone)."));
|
||||
} else {
|
||||
player.sendMessage(war.str("" + getAllTeamsMsg(player)));
|
||||
}
|
||||
event.setCancelled(true);
|
||||
}
|
||||
|
||||
// /join <teamname>
|
||||
else if(command.equals("/join")) {
|
||||
if(split.length < 2 || !war.inAnyWarzone(player.getLocation()) || (split.length > 2 && TeamMaterials.teamMaterialFromString(split[1]) == null)) {
|
||||
player.sendMessage(war.str("Usage: /join <diamond/iron/gold/d/i/g>." +
|
||||
" Teams are warzone specific." +
|
||||
" You must be inside a warzone to join a team."));
|
||||
} else {
|
||||
// drop from old team if any
|
||||
Team previousTeam = war.getPlayerTeam(player.getName());
|
||||
if(previousTeam != null) {
|
||||
if(!previousTeam.removePlayer(player.getName())){
|
||||
war.getLogger().log(Level.WARNING, "Could not remove player " + player.getName() + " from team " + previousTeam.getName());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// join new team
|
||||
String name = split[1];
|
||||
Warzone warzone = war.warzone(player.getLocation());
|
||||
List<Team> teams = warzone.getTeams();
|
||||
boolean foundTeam = false;
|
||||
for(Team team : teams) {
|
||||
if(team.getName().equals(name)) {
|
||||
if(!warzone.hasPlayerInventory(player.getName())) {
|
||||
warzone.keepPlayerInventory(player);
|
||||
player.sendMessage(war.str("Your inventory is is storage until you /leave."));
|
||||
|
||||
// warzone
|
||||
else if(command.equals("/zone") || command.equals("/warzone")) {
|
||||
if(arguments.length < 1) {
|
||||
player.sendMessage(war.str("Usage: /zone <warzone-name>."));
|
||||
} else {
|
||||
boolean warped = false;
|
||||
for(Warzone warzone : war.getWarzones()) {
|
||||
if(warzone.getName().equals(arguments[0]) && warzone.getTeleport() != null){
|
||||
player.teleportTo(warzone.getTeleport());
|
||||
warped = true;
|
||||
}
|
||||
team.addPlayer(player);
|
||||
Warzone zone = war.warzone(player.getLocation());
|
||||
zone.respawnPlayer(team, player);
|
||||
foundTeam = true;
|
||||
}
|
||||
if(!warped) {
|
||||
player.sendMessage("No such warzone.");
|
||||
}
|
||||
}
|
||||
if(foundTeam) {
|
||||
for(Team team : teams){
|
||||
team.teamcast(war.str("" + player.getName() + " joined " + name));
|
||||
}
|
||||
event.setCancelled(true);
|
||||
}
|
||||
|
||||
// /teams
|
||||
else if(command.equals("/teams")){
|
||||
if(!war.inAnyWarzone(player.getLocation())) {
|
||||
player.sendMessage(war.str("Usage: /teams. " +
|
||||
"Must be in a warzone (try /warzones and /warzone)."));
|
||||
} else {
|
||||
player.sendMessage(war.str("No such team. Try /teams."));
|
||||
player.sendMessage(war.str("" + getAllTeamsMsg(player)));
|
||||
}
|
||||
event.setCancelled(true);
|
||||
}
|
||||
event.setCancelled(true);
|
||||
}
|
||||
|
||||
// /leave
|
||||
else if(command.equals("/leave")) {
|
||||
if(!war.inAnyWarzone(player.getLocation()) || war.getPlayerTeam(player.getName()) == null) {
|
||||
player.sendMessage(war.str("Usage: /leave. " +
|
||||
"Must be in a team already."));
|
||||
} else {
|
||||
Team playerTeam = war.getPlayerTeam(player.getName());
|
||||
playerTeam.removePlayer(player.getName());
|
||||
player.sendMessage(war.str("Left the team. You can now exit the warzone."));
|
||||
Warzone zone = war.warzone(player.getLocation());
|
||||
zone.restorePlayerInventory(player);
|
||||
player.sendMessage(war.str("Your inventory has (hopefully) been restored."));
|
||||
}
|
||||
event.setCancelled(true);
|
||||
}
|
||||
|
||||
|
||||
// /team <msg>
|
||||
else if(command.equals("/team")) {
|
||||
if(!war.inAnyWarzone(player.getLocation())) {
|
||||
player.sendMessage(war.str("Usage: /team <message>. " +
|
||||
"Sends a message only to your teammates."));
|
||||
} else {
|
||||
Team playerTeam = war.getPlayerTeam(player.getName());
|
||||
String teamMessage = player.getName();
|
||||
for(int j = 1 ; j<split.length; j++) {
|
||||
String part = split[j];
|
||||
teamMessage += part + " ";
|
||||
}
|
||||
playerTeam.teamcast(war.str(teamMessage));
|
||||
}
|
||||
event.setCancelled(true);
|
||||
}
|
||||
|
||||
// Mod commands : /nextbattle
|
||||
|
||||
// /restartbattle
|
||||
else if(command.equals("/nextbattle") || command.equals("/restartbattle")) {
|
||||
if(!war.inAnyWarzone(player.getLocation())) {
|
||||
player.sendMessage(war.str("Usage: /nextbattle. Resets the zone blocks and all teams' life pools. Must be in warzone."));
|
||||
} else {
|
||||
Warzone warzone = war.warzone(player.getLocation());
|
||||
for(Team team: warzone.getTeams()) {
|
||||
team.teamcast(war.str("The battle was interrupted. " + getAllTeamsMsg(player) + " Resetting warzone " + warzone.getName() + " and life pools..."));
|
||||
}
|
||||
int resetBlocks = warzone.resetState();
|
||||
player.sendMessage(war.str("Warzone reset. " + resetBlocks + " blocks reset."));
|
||||
war.getLogger().info(resetBlocks + " blocks reset in warzone " + warzone.getName() + ".");
|
||||
}
|
||||
event.setCancelled(true);
|
||||
}
|
||||
|
||||
// Warzone maker commands: /setzone, /savezone, /setteam, /setmonument, /resetzone
|
||||
|
||||
// /setteam <diamond/iron/gold/d/i/g>
|
||||
else if(command.equals("/setteam") || command.equals("/newteam") || command.equals("/teamspawn")) {
|
||||
if(split.length < 2 || !war.inAnyWarzone(player.getLocation()) || (split.length > 2 && TeamMaterials.teamMaterialFromString(split[1]) == null)) {
|
||||
player.sendMessage(war.str("Usage: /setteam <diamond/iron/gold/d/i/g>." +
|
||||
" Sets the team spawn to the current location. " +
|
||||
"Must be in a warzone (try /zones and /zone). "));
|
||||
} else {
|
||||
String name = split[1];
|
||||
Material teamMaterial = TeamMaterials.teamMaterialFromString(name);
|
||||
Warzone warzone = war.warzone(player.getLocation());
|
||||
Team existingTeam = warzone.getTeamByMaterial(teamMaterial);
|
||||
if(existingTeam != null) {
|
||||
// relocate
|
||||
existingTeam.setTeamSpawn(player.getLocation());
|
||||
player.sendMessage(war.str("Team " + existingTeam.getName() + " spawn relocated."));
|
||||
} else {
|
||||
// new team
|
||||
Team newTeam = new Team(name, teamMaterial, player.getLocation(), war, warzone);
|
||||
newTeam.setRemainingTickets(warzone.getLifePool());
|
||||
warzone.getTeams().add(newTeam);
|
||||
newTeam.setTeamSpawn(player.getLocation());
|
||||
player.sendMessage(war.str("Team " + name + " created with spawn here."));
|
||||
}
|
||||
|
||||
|
||||
|
||||
WarzoneMapper.save(war, warzone, false);
|
||||
}
|
||||
event.setCancelled(true);
|
||||
}
|
||||
|
||||
// /deleteteam <teamname>
|
||||
else if(command.equals("/deleteteam")) {
|
||||
if(split.length < 2 || !war.inAnyWarzone(player.getLocation())) {
|
||||
player.sendMessage(war.str("Usage: /deleteteam <team-name>." +
|
||||
" Deletes the team and its spawn. " +
|
||||
"Must be in a warzone (try /zones and /zone). "));
|
||||
} else {
|
||||
String name = split[1];
|
||||
Warzone warzone = war.warzone(player.getLocation());
|
||||
List<Team> teams = warzone.getTeams();
|
||||
Team team = null;
|
||||
for(Team t : teams) {
|
||||
if(name.equals(t.getName())) {
|
||||
team = t;
|
||||
}
|
||||
}
|
||||
if(team != null) {
|
||||
team.getVolume().resetBlocks();
|
||||
warzone.getTeams().remove(team);
|
||||
WarzoneMapper.save(war, warzone, false);
|
||||
player.sendMessage(war.str("Team " + name + " removed."));
|
||||
} else {
|
||||
player.sendMessage(war.str("No such team."));
|
||||
}
|
||||
}
|
||||
event.setCancelled(true);
|
||||
}
|
||||
|
||||
// /setwarzone
|
||||
else if(command.equals("/setzone") || command.equals("/setwarzone")) {
|
||||
if(split.length < 3 || (split.length == 3 && (!split[2].equals("southeast") && !split[2].equals("northwest")
|
||||
&& !split[2].equals("se") && !split[2].equals("nw")))) {
|
||||
player.sendMessage(war.str("Usage: /setzone <warzone-name> <'southeast'/'northwest'/'se'/'nw'>. " +
|
||||
"Defines the battleground boundary. " +
|
||||
"The warzone is reset at the start of every battle. " +
|
||||
"This command overwrites any previously saved blocks " +
|
||||
"(i.e. make sure you reset with /restartbattle " +
|
||||
"or /resetwarzone before changing the boundary). "));
|
||||
} else {
|
||||
Warzone warzone = war.findWarzone(split[1]);
|
||||
if(warzone == null) {
|
||||
// create the warzone
|
||||
warzone = new Warzone(war, player.getLocation().getWorld(), split[1]);
|
||||
war.addWarzone(warzone);
|
||||
WarMapper.save(war);
|
||||
if(split[2].equals("northwest") || split[2].equals("nw")) {
|
||||
warzone.setNorthwest(player.getLocation());
|
||||
player.sendMessage(war.str("Warzone " + warzone.getName() + " added. Northwesternmost point set at x="
|
||||
+ (int)warzone.getNorthwest().getBlockX() + " z=" + (int)warzone.getNorthwest().getBlockZ() + "."));
|
||||
} else {
|
||||
warzone.setSoutheast(player.getLocation());
|
||||
player.sendMessage(war.str("Warzone " + warzone.getName() + " added. Southeasternmost point set at x="
|
||||
+ (int)warzone.getSoutheast().getBlockX() + " z=" + (int)warzone.getSoutheast().getBlockZ() + "."));
|
||||
}
|
||||
} else {
|
||||
String message = "";
|
||||
if(split[2].equals("northwest") || split[2].equals("nw")) {
|
||||
warzone.setNorthwest(player.getLocation());
|
||||
message += "Northwesternmost point set at x=" + (int)warzone.getNorthwest().getBlockX()
|
||||
+ " z=" + (int)warzone.getNorthwest().getBlockZ() + " on warzone " + warzone.getName() + ".";
|
||||
} else {
|
||||
warzone.setSoutheast(player.getLocation());
|
||||
message += "Southeasternmost point set at x=" + (int)warzone.getSoutheast().getBlockX()
|
||||
+ " z=" + (int)warzone.getSoutheast().getBlockZ() + " on warzone " + warzone.getName() + ".";
|
||||
|
||||
// /join <teamname>
|
||||
else if(command.equals("/join")) {
|
||||
if(arguments.length < 1 || !war.inAnyWarzone(player.getLocation())
|
||||
|| (arguments.length > 0 && TeamMaterials.teamMaterialFromString(arguments[0]) == null)) {
|
||||
player.sendMessage(war.str("Usage: /join <diamond/iron/gold/d/i/g>." +
|
||||
" Teams are warzone specific." +
|
||||
" You must be inside a warzone to join a team."));
|
||||
} else {
|
||||
// drop from old team if any
|
||||
Team previousTeam = war.getPlayerTeam(player.getName());
|
||||
if(previousTeam != null) {
|
||||
if(!previousTeam.removePlayer(player.getName())){
|
||||
war.getLogger().log(Level.WARNING, "Could not remove player " + player.getName() + " from team " + previousTeam.getName());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if(warzone.getNorthwest() == null) {
|
||||
message += " Still missing northwesternmost point.";
|
||||
}
|
||||
if(warzone.getSoutheast() == null) {
|
||||
message += " Still missing southeasternmost point.";
|
||||
}
|
||||
if(warzone.getNorthwest() != null && warzone.getSoutheast() != null) {
|
||||
if(warzone.ready()) {
|
||||
message += " Warzone " + warzone.getName() + " almost ready. Use /setteam while inside the warzone to create new teams. Make sure to use /savezone to " +
|
||||
"set the warzone teleport point and initial state.";
|
||||
} else if (warzone.tooSmall()) {
|
||||
message += " Warzone " + warzone.getName() + " is too small. Min north-south size: 20. Min east-west size: 20.";
|
||||
} else if (warzone.tooBig()) {
|
||||
message += " Warzone " + warzone.getName() + " is too Big. Max north-south size: 1000. Max east-west size: 1000.";
|
||||
// join new team
|
||||
String name = arguments[0];
|
||||
Warzone warzone = war.warzone(player.getLocation());
|
||||
List<Team> teams = warzone.getTeams();
|
||||
boolean foundTeam = false;
|
||||
for(Team team : teams) {
|
||||
if(team.getName().equals(name)) {
|
||||
if(!warzone.hasPlayerInventory(player.getName())) {
|
||||
warzone.keepPlayerInventory(player);
|
||||
player.sendMessage(war.str("Your inventory is is storage until you /leave."));
|
||||
}
|
||||
team.addPlayer(player);
|
||||
Warzone zone = war.warzone(player.getLocation());
|
||||
zone.respawnPlayer(team, player);
|
||||
foundTeam = true;
|
||||
}
|
||||
}
|
||||
player.sendMessage(war.str(message));
|
||||
}
|
||||
WarzoneMapper.save(war, warzone, false);
|
||||
|
||||
}
|
||||
event.setCancelled(true);
|
||||
}
|
||||
|
||||
// /savewarzone
|
||||
else if(command.equals("/savezone") || command.equals("/savewarzone")) {
|
||||
if(!war.inAnyWarzone(player.getLocation())) {
|
||||
player.sendMessage(war.str("Usage: /savezone. Must be in warzone. " +
|
||||
"Changes the warzone state loaded at the beginning of every battle. " +
|
||||
"Also sets the teleport point for this warzone where you're standing." +
|
||||
"(i.e. make sure to use /zone or the warzone tp point will change). " +
|
||||
"Just like /setzone, this command overwrites any previously saved blocks " +
|
||||
"(i.e. make sure you reset with /restartbattle " +
|
||||
"or /resetzone before changing start state). "));
|
||||
} else {
|
||||
Warzone warzone = war.warzone(player.getLocation());
|
||||
int savedBlocks = warzone.saveState();
|
||||
warzone.setTeleport(player.getLocation());
|
||||
player.sendMessage(war.str("Warzone " + warzone.getName() + " initial state and teleport location changed. Saved " + savedBlocks + " blocks."));
|
||||
WarzoneMapper.save(war, warzone, true);
|
||||
}
|
||||
event.setCancelled(true);
|
||||
}
|
||||
|
||||
// /resetwarzone
|
||||
else if(command.equals("/resetzone") || command.equals("/resetwarzone")) {
|
||||
if(!war.inAnyWarzone(player.getLocation())) {
|
||||
player.sendMessage(war.str("Usage: /resetzone pool=10 maxScore=5. Reloads the zone. All named parameter are optional. Defaults: pool=7 maxScore=-1 (infinite). Must be in warzone."));
|
||||
} else {
|
||||
Warzone warzone = war.warzone(player.getLocation());
|
||||
int resetBlocks = warzone.resetState();
|
||||
for(Team team: warzone.getTeams()) {
|
||||
team.teamcast(war.str("The war has ended. " + getAllTeamsMsg(player) + " Resetting warzone " + warzone.getName() + " and teams..."));
|
||||
for(Player p : team.getPlayers()) {
|
||||
p.teleportTo(warzone.getTeleport());
|
||||
warzone.restorePlayerInventory(p);
|
||||
player.sendMessage(war.str("You have left the warzone. Your inventory has (hopefully) been restored."));
|
||||
if(foundTeam) {
|
||||
for(Team team : teams){
|
||||
team.teamcast(war.str("" + player.getName() + " joined " + name));
|
||||
}
|
||||
} else {
|
||||
player.sendMessage(war.str("No such team. Try /teams."));
|
||||
}
|
||||
}
|
||||
war.getWarzones().remove(warzone);
|
||||
Warzone resetWarzone = WarzoneMapper.load(war, warzone.getName(), true);
|
||||
war.getWarzones().add(resetWarzone);
|
||||
if(split.length > 1) {
|
||||
int overrideLifepool = Integer.parseInt(split[1]);
|
||||
resetWarzone.setLifePool(overrideLifepool);
|
||||
}
|
||||
resetWarzone.resetState();
|
||||
player.sendMessage(war.str("Warzone and teams reset. " + resetBlocks + " blocks reset."));
|
||||
war.getLogger().info(resetBlocks + " blocks reset in warzone " + warzone.getName() + ".");
|
||||
event.setCancelled(true);
|
||||
}
|
||||
event.setCancelled(true);
|
||||
}
|
||||
|
||||
// /deletewarzone
|
||||
else if(command.equals("/deletewarzone")) {
|
||||
if(!war.inAnyWarzone(player.getLocation())) {
|
||||
player.sendMessage(war.str("Usage: /deletewarzone." +
|
||||
" Deletes the warzone. " +
|
||||
"Must be in the warzone (try /warzones and /warzone). "));
|
||||
} else {
|
||||
Warzone warzone = war.warzone(player.getLocation());
|
||||
warzone.removeSoutheast();
|
||||
warzone.removeNorthwest();
|
||||
for(Team t : warzone.getTeams()) {
|
||||
t.getVolume().resetBlocks();
|
||||
}
|
||||
for(Monument m : warzone.getMonuments()) {
|
||||
m.remove();
|
||||
}
|
||||
war.getWarzones().remove(warzone);
|
||||
WarMapper.save(war);
|
||||
WarzoneMapper.delete(war, warzone.getName());
|
||||
player.sendMessage(war.str("Warzone " + warzone.getName() + " removed."));
|
||||
}
|
||||
event.setCancelled(true);
|
||||
}
|
||||
|
||||
// /monument
|
||||
else if(command.equals("/setmonument")) {
|
||||
if(!war.inAnyWarzone(player.getLocation())) {
|
||||
player.sendMessage(war.str("Usage: /setmonument <name>. Creates or moves a monument. Must be in warzone."));
|
||||
} else {
|
||||
Warzone warzone = war.warzone(player.getLocation());
|
||||
String monumentName = split[1];
|
||||
if(warzone.hasMonument(monumentName)) {
|
||||
// move the existing monument
|
||||
Monument monument = warzone.getMonument(monumentName);
|
||||
monument.remove();
|
||||
monument.setLocation(player.getLocation());
|
||||
player.sendMessage(war.str("Monument " + monument.getName() + " was moved."));
|
||||
|
||||
// /leave
|
||||
else if(command.equals("/leave")) {
|
||||
if(!war.inAnyWarzone(player.getLocation()) || war.getPlayerTeam(player.getName()) == null) {
|
||||
player.sendMessage(war.str("Usage: /leave. " +
|
||||
"Must be in a team already."));
|
||||
} else {
|
||||
// create a new monument
|
||||
Monument monument = new Monument(split[1], war, warzone, player.getLocation());
|
||||
warzone.getMonuments().add(monument);
|
||||
player.sendMessage(war.str("Monument " + monument.getName() + " created."));
|
||||
Team playerTeam = war.getPlayerTeam(player.getName());
|
||||
playerTeam.removePlayer(player.getName());
|
||||
player.sendMessage(war.str("Left the team. You can now exit the warzone."));
|
||||
Warzone zone = war.warzone(player.getLocation());
|
||||
zone.restorePlayerInventory(player);
|
||||
player.sendMessage(war.str("Your inventory has (hopefully) been restored."));
|
||||
}
|
||||
WarzoneMapper.save(war, warzone, false);
|
||||
event.setCancelled(true);
|
||||
}
|
||||
event.setCancelled(true);
|
||||
}
|
||||
|
||||
// /deletemonument <name>
|
||||
else if(command.equals("/deletemonument")) {
|
||||
if(split.length < 2 || !war.inAnyWarzone(player.getLocation())) {
|
||||
player.sendMessage(war.str("Usage: /deletemonument <team-name>." +
|
||||
" Deletes the monument. " +
|
||||
"Must be in a warzone (try /warzones and /warzone). "));
|
||||
} else {
|
||||
String name = split[1];
|
||||
Warzone warzone = war.warzone(player.getLocation());
|
||||
Monument monument = warzone.getMonument(name);
|
||||
if(monument != null) {
|
||||
monument.remove();
|
||||
warzone.getMonuments().remove(monument);
|
||||
|
||||
|
||||
// /team <msg>
|
||||
else if(command.equals("/team")) {
|
||||
if(!war.inAnyWarzone(player.getLocation())) {
|
||||
player.sendMessage(war.str("Usage: /team <message>. " +
|
||||
"Sends a message only to your teammates."));
|
||||
} else {
|
||||
Team playerTeam = war.getPlayerTeam(player.getName());
|
||||
String teamMessage = player.getName();
|
||||
for(int j = 0 ; j<arguments.length; j++) {
|
||||
String part = arguments[j];
|
||||
teamMessage += part + " ";
|
||||
}
|
||||
playerTeam.teamcast(war.str(teamMessage));
|
||||
}
|
||||
event.setCancelled(true);
|
||||
}
|
||||
|
||||
// Mod commands : /nextbattle
|
||||
|
||||
// /restartbattle
|
||||
else if(command.equals("/nextbattle") || command.equals("/restartbattle")) {
|
||||
if(!war.inAnyWarzone(player.getLocation())) {
|
||||
player.sendMessage(war.str("Usage: /nextbattle. Resets the zone blocks and all teams' life pools. Must be in warzone."));
|
||||
} else {
|
||||
Warzone warzone = war.warzone(player.getLocation());
|
||||
for(Team team: warzone.getTeams()) {
|
||||
team.teamcast(war.str("The battle was interrupted. " + getAllTeamsMsg(player) + " Resetting warzone " + warzone.getName() + " and life pools..."));
|
||||
}
|
||||
int resetBlocks = warzone.resetState();
|
||||
player.sendMessage(war.str("Warzone reset. " + resetBlocks + " blocks reset."));
|
||||
war.getLogger().info(resetBlocks + " blocks reset in warzone " + warzone.getName() + ".");
|
||||
}
|
||||
event.setCancelled(true);
|
||||
}
|
||||
|
||||
// Warzone maker commands: /setzone, /savezone, /setteam, /setmonument, /resetzone
|
||||
|
||||
// /setteam <diamond/iron/gold/d/i/g>
|
||||
else if(command.equals("/setteam") || command.equals("/newteam") || command.equals("/teamspawn")) {
|
||||
if(arguments.length < 1 || !war.inAnyWarzone(player.getLocation())
|
||||
|| (arguments.length > 0 && TeamMaterials.teamMaterialFromString(arguments[0]) == null)) {
|
||||
player.sendMessage(war.str("Usage: /setteam <diamond/iron/gold/d/i/g>." +
|
||||
" Sets the team spawn to the current location. " +
|
||||
"Must be in a warzone (try /zones and /zone). "));
|
||||
} else {
|
||||
String name = arguments[0];
|
||||
Material teamMaterial = TeamMaterials.teamMaterialFromString(name);
|
||||
Warzone warzone = war.warzone(player.getLocation());
|
||||
Team existingTeam = warzone.getTeamByMaterial(teamMaterial);
|
||||
if(existingTeam != null) {
|
||||
// relocate
|
||||
existingTeam.setTeamSpawn(player.getLocation());
|
||||
player.sendMessage(war.str("Team " + existingTeam.getName() + " spawn relocated."));
|
||||
} else {
|
||||
// new team
|
||||
Team newTeam = new Team(name, teamMaterial, player.getLocation(), war, warzone);
|
||||
newTeam.setRemainingTickets(warzone.getLifePool());
|
||||
warzone.getTeams().add(newTeam);
|
||||
newTeam.setTeamSpawn(player.getLocation());
|
||||
player.sendMessage(war.str("Team " + name + " created with spawn here."));
|
||||
}
|
||||
|
||||
|
||||
|
||||
WarzoneMapper.save(war, warzone, false);
|
||||
player.sendMessage(war.str("Monument " + name + " removed."));
|
||||
} else {
|
||||
player.sendMessage(war.str("No such monument."));
|
||||
}
|
||||
event.setCancelled(true);
|
||||
}
|
||||
|
||||
// /deleteteam <teamname>
|
||||
else if(command.equals("/deleteteam")) {
|
||||
if(arguments.length < 1 || !war.inAnyWarzone(player.getLocation())) {
|
||||
player.sendMessage(war.str("Usage: /deleteteam <team-name>." +
|
||||
" Deletes the team and its spawn. " +
|
||||
"Must be in a warzone (try /zones and /zone). "));
|
||||
} else {
|
||||
String name = arguments[1];
|
||||
Warzone warzone = war.warzone(player.getLocation());
|
||||
List<Team> teams = warzone.getTeams();
|
||||
Team team = null;
|
||||
for(Team t : teams) {
|
||||
if(name.equals(t.getName())) {
|
||||
team = t;
|
||||
}
|
||||
}
|
||||
if(team != null) {
|
||||
team.getVolume().resetBlocks();
|
||||
warzone.getTeams().remove(team);
|
||||
WarzoneMapper.save(war, warzone, false);
|
||||
player.sendMessage(war.str("Team " + name + " removed."));
|
||||
} else {
|
||||
player.sendMessage(war.str("No such team."));
|
||||
}
|
||||
}
|
||||
event.setCancelled(true);
|
||||
}
|
||||
|
||||
// /setwarzone
|
||||
else if(command.equals("/setzone") || command.equals("/setwarzone")) {
|
||||
if(arguments.length < 2 || arguments.length > 2
|
||||
|| (arguments.length == 2 && (!arguments[1].equals("southeast") && !arguments[1].equals("northwest")
|
||||
&& !arguments[1].equals("se") && !arguments[1].equals("nw")))) {
|
||||
player.sendMessage(war.str("Usage: /setzone <warzone-name> <'southeast'/'northwest'/'se'/'nw'>. " +
|
||||
"Defines the battleground boundary. " +
|
||||
"The warzone is reset at the start of every battle. " +
|
||||
"This command overwrites any previously saved blocks " +
|
||||
"(i.e. make sure you reset with /restartbattle " +
|
||||
"or /resetwarzone before changing the boundary). "));
|
||||
} else {
|
||||
Warzone warzone = war.findWarzone(arguments[0]);
|
||||
if(warzone == null) {
|
||||
// create the warzone
|
||||
warzone = new Warzone(war, player.getLocation().getWorld(), arguments[0]);
|
||||
war.addWarzone(warzone);
|
||||
WarMapper.save(war);
|
||||
if(arguments[1].equals("northwest") || arguments[1].equals("nw")) {
|
||||
warzone.setNorthwest(player.getLocation());
|
||||
player.sendMessage(war.str("Warzone " + warzone.getName() + " added. Northwesternmost point set at x="
|
||||
+ (int)warzone.getNorthwest().getBlockX() + " z=" + (int)warzone.getNorthwest().getBlockZ() + "."));
|
||||
} else {
|
||||
warzone.setSoutheast(player.getLocation());
|
||||
player.sendMessage(war.str("Warzone " + warzone.getName() + " added. Southeasternmost point set at x="
|
||||
+ (int)warzone.getSoutheast().getBlockX() + " z=" + (int)warzone.getSoutheast().getBlockZ() + "."));
|
||||
}
|
||||
} else {
|
||||
String message = "";
|
||||
if(arguments[1].equals("northwest") || arguments[1].equals("nw")) {
|
||||
warzone.setNorthwest(player.getLocation());
|
||||
message += "Northwesternmost point set at x=" + (int)warzone.getNorthwest().getBlockX()
|
||||
+ " z=" + (int)warzone.getNorthwest().getBlockZ() + " on warzone " + warzone.getName() + ".";
|
||||
} else {
|
||||
warzone.setSoutheast(player.getLocation());
|
||||
message += "Southeasternmost point set at x=" + (int)warzone.getSoutheast().getBlockX()
|
||||
+ " z=" + (int)warzone.getSoutheast().getBlockZ() + " on warzone " + warzone.getName() + ".";
|
||||
}
|
||||
|
||||
if(warzone.getNorthwest() == null) {
|
||||
message += " Still missing northwesternmost point.";
|
||||
}
|
||||
if(warzone.getSoutheast() == null) {
|
||||
message += " Still missing southeasternmost point.";
|
||||
}
|
||||
if(warzone.getNorthwest() != null && warzone.getSoutheast() != null) {
|
||||
if(warzone.ready()) {
|
||||
message += " Warzone " + warzone.getName() + " almost ready. Use /setteam while inside the warzone to create new teams. Make sure to use /savezone to " +
|
||||
"set the warzone teleport point and initial state.";
|
||||
} else if (warzone.tooSmall()) {
|
||||
message += " Warzone " + warzone.getName() + " is too small. Min north-south size: 20. Min east-west size: 20.";
|
||||
} else if (warzone.tooBig()) {
|
||||
message += " Warzone " + warzone.getName() + " is too Big. Max north-south size: 1000. Max east-west size: 1000.";
|
||||
}
|
||||
}
|
||||
player.sendMessage(war.str(message));
|
||||
}
|
||||
WarzoneMapper.save(war, warzone, false);
|
||||
|
||||
}
|
||||
event.setCancelled(true);
|
||||
}
|
||||
|
||||
// /savewarzone
|
||||
else if(command.equals("/savezone") || command.equals("/savewarzone")) {
|
||||
if(!war.inAnyWarzone(player.getLocation())) {
|
||||
player.sendMessage(war.str("Usage: /savezone. Must be in warzone. " +
|
||||
"Changes the warzone state loaded at the beginning of every battle. " +
|
||||
"Also sets the teleport point for this warzone where you're standing." +
|
||||
"(i.e. make sure to use /zone or the warzone tp point will change). " +
|
||||
"Just like /setzone, this command overwrites any previously saved blocks " +
|
||||
"(i.e. make sure you reset with /restartbattle " +
|
||||
"or /resetzone before changing start state). "));
|
||||
} else {
|
||||
Warzone warzone = war.warzone(player.getLocation());
|
||||
int savedBlocks = warzone.saveState();
|
||||
warzone.setTeleport(player.getLocation());
|
||||
player.sendMessage(war.str("Warzone " + warzone.getName() + " initial state and teleport location changed. Saved " + savedBlocks + " blocks."));
|
||||
WarzoneMapper.save(war, warzone, true);
|
||||
}
|
||||
event.setCancelled(true);
|
||||
}
|
||||
|
||||
// /resetwarzone
|
||||
else if(command.equals("/resetzone") || command.equals("/resetwarzone")) {
|
||||
if(!war.inAnyWarzone(player.getLocation())) {
|
||||
player.sendMessage(war.str("Usage: /resetzone pool=10 maxScore=5. Reloads the zone. All named parameter are optional. Defaults: pool=7 maxScore=-1 (infinite). Must be in warzone."));
|
||||
} else {
|
||||
Warzone warzone = war.warzone(player.getLocation());
|
||||
int resetBlocks = warzone.resetState();
|
||||
for(Team team: warzone.getTeams()) {
|
||||
team.teamcast(war.str("The war has ended. " + getAllTeamsMsg(player) + " Resetting warzone " + warzone.getName() + " and teams..."));
|
||||
for(Player p : team.getPlayers()) {
|
||||
p.teleportTo(warzone.getTeleport());
|
||||
warzone.restorePlayerInventory(p);
|
||||
player.sendMessage(war.str("You have left the warzone. Your inventory has (hopefully) been restored."));
|
||||
}
|
||||
}
|
||||
war.getWarzones().remove(warzone);
|
||||
Warzone resetWarzone = WarzoneMapper.load(war, warzone.getName(), true);
|
||||
war.getWarzones().add(resetWarzone);
|
||||
if(split.length > 1) {
|
||||
int overrideLifepool = Integer.parseInt(split[1]);
|
||||
resetWarzone.setLifePool(overrideLifepool);
|
||||
}
|
||||
resetWarzone.resetState();
|
||||
player.sendMessage(war.str("Warzone and teams reset. " + resetBlocks + " blocks reset."));
|
||||
war.getLogger().info(resetBlocks + " blocks reset in warzone " + warzone.getName() + ".");
|
||||
}
|
||||
event.setCancelled(true);
|
||||
}
|
||||
|
||||
// /deletewarzone
|
||||
else if(command.equals("/deletewarzone")) {
|
||||
if(!war.inAnyWarzone(player.getLocation())) {
|
||||
player.sendMessage(war.str("Usage: /deletewarzone." +
|
||||
" Deletes the warzone. " +
|
||||
"Must be in the warzone (try /warzones and /warzone). "));
|
||||
} else {
|
||||
Warzone warzone = war.warzone(player.getLocation());
|
||||
warzone.removeSoutheast();
|
||||
warzone.removeNorthwest();
|
||||
for(Team t : warzone.getTeams()) {
|
||||
t.getVolume().resetBlocks();
|
||||
}
|
||||
for(Monument m : warzone.getMonuments()) {
|
||||
m.remove();
|
||||
}
|
||||
war.getWarzones().remove(warzone);
|
||||
WarMapper.save(war);
|
||||
WarzoneMapper.delete(war, warzone.getName());
|
||||
player.sendMessage(war.str("Warzone " + warzone.getName() + " removed."));
|
||||
}
|
||||
event.setCancelled(true);
|
||||
}
|
||||
|
||||
// /monument
|
||||
else if(command.equals("/setmonument")) {
|
||||
if(!war.inAnyWarzone(player.getLocation())) {
|
||||
player.sendMessage(war.str("Usage: /setmonument <name>. Creates or moves a monument. Must be in warzone."));
|
||||
} else {
|
||||
Warzone warzone = war.warzone(player.getLocation());
|
||||
String monumentName = split[1];
|
||||
if(warzone.hasMonument(monumentName)) {
|
||||
// move the existing monument
|
||||
Monument monument = warzone.getMonument(monumentName);
|
||||
monument.remove();
|
||||
monument.setLocation(player.getLocation());
|
||||
player.sendMessage(war.str("Monument " + monument.getName() + " was moved."));
|
||||
} else {
|
||||
// create a new monument
|
||||
Monument monument = new Monument(split[1], war, warzone, player.getLocation());
|
||||
warzone.getMonuments().add(monument);
|
||||
player.sendMessage(war.str("Monument " + monument.getName() + " created."));
|
||||
}
|
||||
WarzoneMapper.save(war, warzone, false);
|
||||
}
|
||||
event.setCancelled(true);
|
||||
}
|
||||
|
||||
// /deletemonument <name>
|
||||
else if(command.equals("/deletemonument")) {
|
||||
if(arguments.length < 1 || !war.inAnyWarzone(player.getLocation())) {
|
||||
player.sendMessage(war.str("Usage: /deletemonument <team-name>." +
|
||||
" Deletes the monument. " +
|
||||
"Must be in a warzone (try /warzones and /warzone). "));
|
||||
} else {
|
||||
String name = arguments[0];
|
||||
Warzone warzone = war.warzone(player.getLocation());
|
||||
Monument monument = warzone.getMonument(name);
|
||||
if(monument != null) {
|
||||
monument.remove();
|
||||
warzone.getMonuments().remove(monument);
|
||||
WarzoneMapper.save(war, warzone, false);
|
||||
player.sendMessage(war.str("Monument " + name + " removed."));
|
||||
} else {
|
||||
player.sendMessage(war.str("No such monument."));
|
||||
}
|
||||
}
|
||||
event.setCancelled(true);
|
||||
}
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user