Closes gh-65. Can now set zone loadout with /setzoneloadout and change default with /setwarloadout instead of having to reboot the server.

This commit is contained in:
taoneill 2011-02-20 23:03:23 -05:00
parent 89d7509b0c
commit f9beef2073
4 changed files with 76 additions and 10 deletions

View File

@ -20,6 +20,7 @@ import org.bukkit.entity.Player;
import org.bukkit.event.Event;
import org.bukkit.event.Event.Priority;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.PlayerInventory;
import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.PluginDescriptionFile;
import org.bukkit.plugin.PluginManager;
@ -185,6 +186,8 @@ public class War extends JavaPlugin {
performSetZone(player, arguments);
} else if(command.equals("setzonelobby")) {
performSetZoneLobby(player, arguments);
} else if(command.equals("setzoneloadout")) {
performSetZoneLoadout(player, arguments);
} else if(command.equals("savezone")) {
performSaveZone(player, arguments);
} else if(command.equals("setzoneconfig")) {
@ -209,6 +212,8 @@ public class War extends JavaPlugin {
performDeleteWarhub(player);
} else if(command.equals("setwarconfig")) {
performSetWarConfig(player, arguments);
} else if(command.equals("setwarloadout")) {
performSetWarLoadout(player, arguments);
} else if(command.equals("zonemaker")) {
performZonemakerAsZonemaker(player, arguments);
}
@ -234,6 +239,57 @@ public class War extends JavaPlugin {
return true;
}
private void performSetZoneLoadout(Player player, String[] arguments) {
if(arguments.length > 0 || (!this.inAnyWarzone(player.getLocation())
&& !this.inAnyWarzoneLobby(player.getLocation()))) {
this.badMsg(player, "Usage: Fill you inventory with what you want players to spawn with in this zone, then use /setzoneloadout. Must be in a warzone or lobby.");
} else {
Warzone zone = this.warzone(player.getLocation());
if(zone == null) {
ZoneLobby lobby = this.lobby(player.getLocation());
zone = lobby.getZone();
}
HashMap<Integer, ItemStack> loadout = zone.getLoadout();
inventoryToLoadout(player, loadout);
WarzoneMapper.save(this, zone, false);
this.msg(player, "Zone loadout changed.");
}
}
private void performSetWarLoadout(Player player, String[] arguments) {
if(arguments.length > 0) {
this.badMsg(player, "Usage: Fill you inventory with what you want players to spawn with in all new zone, then use /setwarloadout.");
} else {
HashMap<Integer, ItemStack> loadout = this.getDefaultLoadout();
inventoryToLoadout(player, loadout);
WarMapper.save(this);
this.msg(player, "War default loadout changed.");
}
}
private void inventoryToLoadout(Player player,
HashMap<Integer, ItemStack> loadout) {
loadout.clear();
PlayerInventory inv = player.getInventory();
int i = 0;
for(ItemStack stack : inv.getContents()){
if(stack.getType() != Material.AIR) {
loadout.put(i, stack);
}
i++;
}
if(inv.getBoots() != null && inv.getBoots().getType() != Material.AIR) {
loadout.put(100, inv.getBoots());
}
if(inv.getLeggings() != null && inv.getLeggings().getType() != Material.AIR) {
loadout.put(101, inv.getLeggings());
}
if(inv.getChestplate() != null && inv.getChestplate().getType() != Material.AIR) {
loadout.put(102, inv.getChestplate());
}
}
public void performZonemakerAsPlayer(Player player) {
boolean wasImpersonating = false;
for(String name : getZoneMakersImpersonatingPlayers()) {

View File

@ -391,8 +391,6 @@ public class Warzone {
playerInv.setLeggings(loadout.get(slot));
} else if(slot == 102) {
playerInv.setChestplate(loadout.get(slot));
} else if(slot == 103) {
playerInv.setHelmet(loadout.get(slot));
} else {
playerInv.addItem(loadout.get(slot));
}

View File

@ -36,7 +36,7 @@ commands:
# Warzone maker commands
# 1- Battle-related commands
nextbattle:
description: War makers only. Zone blocks are restored (from memory). Teams are respawned. Just as if a team's life pool had been exhausted.
description: Zone makers only. Zone blocks are restored (from memory). Teams are respawned. Just as if a team's life pool had been exhausted.
usage: /nextbattle
# 2- Warzone creation commands
setzone:
@ -48,6 +48,9 @@ commands:
setzonelobby:
description: Zone makers only. Creates or changes the position of the warzone lobby. Must be in warzone or lobby.
usage: /setzonelobby <north/east/south/west/n/e/s/w>
setzoneloadout:
description: Zone makers only. Changes the zone's respawn loadout to your current inventory. Must be in warzone or lobby.
usage: /setzoneloadout
setteam:
description: Zone makers only. Creates or moves a team spawn. The lobby is updated to reflect any new team. The only available teams are diamond, iron and gold. Must be warzone.
usage: /setteam <diamond/iron/gold/d/i/g>
@ -77,15 +80,18 @@ commands:
usage: /zonemaker, /zonemaker <new-or-kicked-maker-name>
# 3- War hub
setwarhub:
description: War makers only. Create or moves a West-facing wall of portals. One portal per warzone. Warzones get a portal back to the warhub.
description: Zone makers only. Create or moves a West-facing wall of portals. One portal per warzone. Warzones get a portal back to the warhub.
usage: /setwarhub
deletewarhub:
description: War makers only. Deletes the warhub if it exists. Resets all warzone lobbies.
description: Zone makers only. Deletes the warhub if it exists. Resets all warzone lobbies.
usage: /deletewarhub
# 4- Defaults
setwarconfig:
description: War makers only. Change the default warzone configuration values.
description: Zone makers only. Change the default warzone configuration values.
usage: /setwarconfig pvpinzonesonly:on lifepool:8 teamsize:5 maxscore:7 autoassign:on outline:off ff:on
setwarloadout:
description: Zone makers only. Changes the default respawn loadout for all new zones.
usage: /setzoneloadout
# Fallback
war:
description: Prompts you to use /warhub, /zones and /zone. Can also be used as a prefix for all commands as a fallback if they are taken.

View File

@ -36,7 +36,7 @@ commands:
# Warzone maker commands
# 1- Battle-related commands
nextbattle:
description: War makers only. Zone blocks are restored (from memory). Teams are respawned. Just as if a team's life pool had been exhausted.
description: Zone makers only. Zone blocks are restored (from memory). Teams are respawned. Just as if a team's life pool had been exhausted.
usage: /nextbattle
# 2- Warzone creation commands
setzone:
@ -48,6 +48,9 @@ commands:
setzonelobby:
description: Zone makers only. Creates or changes the position of the warzone lobby. Must be in warzone or lobby.
usage: /setzonelobby <north/east/south/west/n/e/s/w>
setzoneloadout:
description: Zone makers only. Changes the zone's respawn loadout to your current inventory. Must be in warzone or lobby.
usage: /setzoneloadout
setteam:
description: Zone makers only. Creates or moves a team spawn. The lobby is updated to reflect any new team. The only available teams are diamond, iron and gold. Must be warzone.
usage: /setteam <diamond/iron/gold/d/i/g>
@ -77,15 +80,18 @@ commands:
usage: /zonemaker, /zonemaker <new-or-kicked-maker-name>
# 3- War hub
setwarhub:
description: War makers only. Create or moves a West-facing wall of portals. One portal per warzone. Warzones get a portal back to the warhub.
description: Zone makers only. Create or moves a West-facing wall of portals. One portal per warzone. Warzones get a portal back to the warhub.
usage: /setwarhub
deletewarhub:
description: War makers only. Deletes the warhub if it exists. Resets all warzone lobbies.
description: Zone makers only. Deletes the warhub if it exists. Resets all warzone lobbies.
usage: /deletewarhub
# 4- Defaults
setwarconfig:
description: War makers only. Change the default warzone configuration values.
description: Zone makers only. Change the default warzone configuration values.
usage: /setwarconfig pvpinzonesonly:on lifepool:8 teamsize:5 maxscore:7 autoassign:on outline:off ff:on
setwarloadout:
description: Zone makers only. Changes the default respawn loadout for all new zones.
usage: /setzoneloadout
# Fallback
war:
description: Prompts you to use /warhub, /zones and /zone. Can also be used as a prefix for all commands as a fallback if they are taken.