mirror of https://github.com/taoneill/war.git
Fixes in zone and team-specific loadout creation
Closes gh-480. When you add a new loadout to a warzone, you now inherit the default loadouts automatically - they are copied from War's default inventories. Similarly, when you add a new loadout to a team, the warzone's (or War's default) loadouts are copied and the new loadout is added to that collection. This was the intended behavior.
This commit is contained in:
parent
b7ae19a439
commit
68b5ca755b
|
@ -361,6 +361,19 @@ public class War extends JavaPlugin {
|
||||||
String loadoutName = namedParams.get("loadout");
|
String loadoutName = namedParams.get("loadout");
|
||||||
HashMap<Integer, ItemStack> loadout = team.getInventories().getLoadouts().get(loadoutName);
|
HashMap<Integer, ItemStack> loadout = team.getInventories().getLoadouts().get(loadoutName);
|
||||||
if (loadout == null) {
|
if (loadout == null) {
|
||||||
|
// Check if any loadouts exist, if not gotta use the default inventories then add the newly created one
|
||||||
|
if(team.getInventories().getLoadouts().isEmpty()) {
|
||||||
|
Warzone warzone = Warzone.getZoneByTeam(team);
|
||||||
|
for (String key : warzone.getDefaultInventories().resolveLoadouts().keySet()) {
|
||||||
|
HashMap<Integer, ItemStack> transferredLoadout = warzone.getDefaultInventories().resolveLoadouts().get(key);
|
||||||
|
if (transferredLoadout != null) {
|
||||||
|
team.getInventories().getLoadouts().put(key, transferredLoadout);
|
||||||
|
} else {
|
||||||
|
War.war.log("Failed to transfer loadout " + key + " down to team " + team.getName() + " in warzone " + warzone.getName(), Level.WARNING);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
loadout = new HashMap<Integer, ItemStack>();
|
loadout = new HashMap<Integer, ItemStack>();
|
||||||
team.getInventories().getLoadouts().put(loadoutName, loadout);
|
team.getInventories().getLoadouts().put(loadoutName, loadout);
|
||||||
returnMessage.append(loadoutName + " respawn loadout added.");
|
returnMessage.append(loadoutName + " respawn loadout added.");
|
||||||
|
@ -430,6 +443,19 @@ public class War extends JavaPlugin {
|
||||||
HashMap<Integer, ItemStack> loadout = warzone.getDefaultInventories().getLoadouts().get(loadoutName);
|
HashMap<Integer, ItemStack> loadout = warzone.getDefaultInventories().getLoadouts().get(loadoutName);
|
||||||
if (loadout == null) {
|
if (loadout == null) {
|
||||||
loadout = new HashMap<Integer, ItemStack>();
|
loadout = new HashMap<Integer, ItemStack>();
|
||||||
|
|
||||||
|
// Check if any loadouts exist, if not gotta use the default inventories then add the newly created one
|
||||||
|
if(warzone.getDefaultInventories().getLoadouts().isEmpty()) {
|
||||||
|
for (String key : warzone.getDefaultInventories().resolveLoadouts().keySet()) {
|
||||||
|
HashMap<Integer, ItemStack> transferredLoadout = warzone.getDefaultInventories().resolveLoadouts().get(key);
|
||||||
|
if (transferredLoadout != null) {
|
||||||
|
warzone.getDefaultInventories().getLoadouts().put(key, transferredLoadout);
|
||||||
|
} else {
|
||||||
|
War.war.log("Failed to transfer loadout " + key + " down to warzone " + warzone.getName(), Level.WARNING);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
warzone.getDefaultInventories().getLoadouts().put(loadoutName, loadout);
|
warzone.getDefaultInventories().getLoadouts().put(loadoutName, loadout);
|
||||||
returnMessage.append(loadoutName + " respawn loadout added.");
|
returnMessage.append(loadoutName + " respawn loadout added.");
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
package com.tommytony.war;
|
package com.tommytony.war;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
|
@ -127,6 +128,18 @@ public class Warzone {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static Warzone getZoneByTeam(Team team) {
|
||||||
|
for (Warzone warzone : War.war.getWarzones()) {
|
||||||
|
for (Team teamToCheck : warzone.getTeams()) {
|
||||||
|
if (teamToCheck.getName().equals(team.getName())) {
|
||||||
|
return warzone;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
public boolean ready() {
|
public boolean ready() {
|
||||||
if (this.volume.hasTwoCorners() && !this.volume.tooSmall() && !this.volume.tooBig()) {
|
if (this.volume.hasTwoCorners() && !this.volume.tooSmall() && !this.volume.tooBig()) {
|
||||||
return true;
|
return true;
|
||||||
|
|
Loading…
Reference in New Issue