mirror of
https://github.com/taoneill/war.git
synced 2025-01-05 23:37:37 +01:00
First pass at extraLoadouts/class system. Needs testing.
This commit is contained in:
parent
e0a2d6092b
commit
c6a8bc555c
@ -66,6 +66,7 @@ public class War extends JavaPlugin {
|
||||
|
||||
// Default warzone settings
|
||||
private final HashMap<Integer, ItemStack> defaultLoadout = new HashMap<Integer, ItemStack>();
|
||||
private final HashMap<String, HashMap<Integer, ItemStack>> defaultExtraLoadouts = new HashMap<String, HashMap<Integer, ItemStack>>();
|
||||
private int defaultLifepool = 7;
|
||||
private int defaultTeamCap = 7;
|
||||
private int defaultScoreCap = 10;
|
||||
@ -128,6 +129,7 @@ public class War extends JavaPlugin {
|
||||
pm.registerEvent(Event.Type.PLAYER_DROP_ITEM, this.playerListener, Priority.Normal, this);
|
||||
pm.registerEvent(Event.Type.PLAYER_COMMAND_PREPROCESS, this.playerListener, Priority.Normal, this);
|
||||
pm.registerEvent(Event.Type.PLAYER_INTERACT, this.playerListener, Priority.Normal, this);
|
||||
pm.registerEvent(Event.Type.PLAYER_TOGGLE_SNEAK, this.playerListener, Priority.Normal, this);
|
||||
|
||||
pm.registerEvent(Event.Type.ENTITY_EXPLODE, this.entityListener, Priority.Normal, this);
|
||||
pm.registerEvent(Event.Type.ENTITY_DAMAGE, this.entityListener, Priority.High, this);
|
||||
@ -355,8 +357,18 @@ public class War extends JavaPlugin {
|
||||
if (commandSender instanceof Player) {
|
||||
Player player = (Player) commandSender;
|
||||
if (namedParams.containsKey("loadout")) {
|
||||
this.inventoryToLoadout(player, warzone.getLoadout());
|
||||
returnMessage.append(" respawn loadout updated.");
|
||||
String loadoutName = namedParams.get("loadout");
|
||||
if (loadoutName.equals("default")) {
|
||||
this.inventoryToLoadout(player, warzone.getLoadout());
|
||||
} else {
|
||||
HashMap<Integer, ItemStack> extraLoadout = this.getDefaultExtraLoadouts().get(loadoutName);
|
||||
if (extraLoadout == null) {
|
||||
HashMap<Integer, ItemStack> newLoadout = new HashMap<Integer, ItemStack>();
|
||||
this.getDefaultExtraLoadouts().put(loadoutName, newLoadout);
|
||||
}
|
||||
this.inventoryToLoadout(player, extraLoadout);
|
||||
}
|
||||
returnMessage.append(loadoutName + " respawn loadout updated.");
|
||||
}
|
||||
if (namedParams.containsKey("reward")) {
|
||||
this.inventoryToLoadout(player, warzone.getReward());
|
||||
@ -1046,4 +1058,8 @@ public class War extends JavaPlugin {
|
||||
public int getDefaultMinTeams() {
|
||||
return defaultMinTeams;
|
||||
}
|
||||
|
||||
public HashMap<String, HashMap<Integer, ItemStack>> getDefaultExtraLoadouts() {
|
||||
return defaultExtraLoadouts;
|
||||
}
|
||||
}
|
||||
|
@ -10,6 +10,7 @@ import org.bukkit.craftbukkit.entity.CraftPlayer;
|
||||
import org.bukkit.craftbukkit.entity.CraftTNTPrimed;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.entity.Projectile;
|
||||
import org.bukkit.event.entity.CreatureSpawnEvent;
|
||||
import org.bukkit.event.entity.EntityCombustEvent;
|
||||
import org.bukkit.event.entity.EntityDamageByEntityEvent;
|
||||
@ -115,8 +116,8 @@ public class WarEntityListener extends EntityListener {
|
||||
if (d != null && defenderWarzone != null && event.getDamage() >= d.getHealth()) {
|
||||
String deathMessage = "";
|
||||
String defenderString = Team.getTeamByPlayerName(d.getName()).getKind().getColor() + d.getDisplayName();
|
||||
if (event instanceof EntityDamageByProjectileEvent) {
|
||||
deathMessage = "A dispenser killed " + defenderString;
|
||||
if (event.getDamager() instanceof Projectile && ((Projectile)event.getDamager()).getShooter() instanceof Player){
|
||||
deathMessage = ((Player)((Projectile)event.getDamager()).getShooter()).getDisplayName() + "'s deadly aim killed " + defenderString;
|
||||
} else if (event.getDamager() instanceof CraftTNTPrimed) {
|
||||
deathMessage = defenderString + ChatColor.WHITE + " exploded";
|
||||
} else {
|
||||
@ -240,7 +241,6 @@ public class WarEntityListener extends EntityListener {
|
||||
Warzone zone = Warzone.getZoneByLocation(location);
|
||||
if (zone != null && zone.isNoCreatures()) {
|
||||
event.setCancelled(true);
|
||||
// war.logInfo("Prevented " + event.getMobType().getName() + " from spawning in zone " + zone.getName());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,6 +1,7 @@
|
||||
package bukkit.tommytony.war;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Location;
|
||||
@ -19,6 +20,7 @@ import org.bukkit.event.player.PlayerListener;
|
||||
import org.bukkit.event.player.PlayerMoveEvent;
|
||||
import org.bukkit.event.player.PlayerPickupItemEvent;
|
||||
import org.bukkit.event.player.PlayerQuitEvent;
|
||||
import org.bukkit.event.player.PlayerToggleSneakEvent;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.PlayerInventory;
|
||||
@ -448,6 +450,13 @@ public class WarPlayerListener extends PlayerListener {
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
// Class selection lock
|
||||
if (!playerTeam.getSpawnVolume().contains(player.getLocation()) &&
|
||||
playerWarzone.getNewlyRespawned().keySet().contains(player.getName())) {
|
||||
playerWarzone.getNewlyRespawned().remove(player.getName());
|
||||
}
|
||||
|
||||
} else if (locZone != null && locZone.getLobby() != null && !locZone.getLobby().isLeavingZone(playerLoc) && !isMaker) {
|
||||
// player is not in any team, but inside warzone boundaries, get him out
|
||||
Warzone zone = Warzone.getZoneByLocation(playerLoc);
|
||||
@ -457,6 +466,29 @@ public class WarPlayerListener extends PlayerListener {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPlayerToggleSneak(PlayerToggleSneakEvent event) {
|
||||
if (War.war.isLoaded()) {
|
||||
Warzone playerWarzone = Warzone.getZoneByLocation(event.getPlayer());
|
||||
if (playerWarzone != null && playerWarzone.getNewlyRespawned().keySet().contains(event.getPlayer().getName())) {
|
||||
Integer currentIndex = playerWarzone.getNewlyRespawned().get(event.getPlayer().getName());
|
||||
currentIndex = (currentIndex + 1) % (playerWarzone.getExtraLoadouts().keySet().size() + 1);
|
||||
playerWarzone.getNewlyRespawned().put(event.getPlayer().getName(), currentIndex);
|
||||
|
||||
Team playerTeam = Team.getTeamByPlayerName(event.getPlayer().getName());
|
||||
|
||||
if (currentIndex == 0) {
|
||||
playerWarzone.resetInventory(playerTeam, event.getPlayer(), playerWarzone.getLoadout());
|
||||
} else {
|
||||
String[] array = (String[]) playerWarzone.getExtraLoadouts().keySet().toArray();
|
||||
playerWarzone.resetInventory(playerTeam, event.getPlayer(), playerWarzone.getExtraLoadouts().get(array[currentIndex-1]));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
public void purgeLatestPositions() {
|
||||
this.latestLocations.clear();
|
||||
}
|
||||
|
@ -41,6 +41,7 @@ public class Warzone {
|
||||
private boolean friendlyFire;
|
||||
private int lifePool;
|
||||
private HashMap<Integer, ItemStack> loadout = new HashMap<Integer, ItemStack>();
|
||||
private HashMap<String, HashMap<Integer, ItemStack>> extraLoadouts = new HashMap<String, HashMap<Integer, ItemStack>>();
|
||||
private int teamCap = 5;
|
||||
private int scoreCap = 5;
|
||||
private int monumentHeal = 5;
|
||||
@ -50,6 +51,7 @@ public class Warzone {
|
||||
|
||||
private HashMap<String, InventoryStash> inventories = new HashMap<String, InventoryStash>();
|
||||
private HashMap<String, Team> flagThieves = new HashMap<String, Team>();
|
||||
private HashMap<String, Integer> newlyRespawned = new HashMap<String, Integer>();
|
||||
private World world;
|
||||
private final int minSafeDistanceFromWall = 6;
|
||||
private List<ZoneWallGuard> zoneWallGuards = new ArrayList<ZoneWallGuard>();
|
||||
@ -71,12 +73,15 @@ public class Warzone {
|
||||
private HashMap<String, InventoryStash> deadMenInventories = new HashMap<String, InventoryStash>();
|
||||
private Location rallyPoint;
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public Warzone(World world, String name) {
|
||||
this.world = world;
|
||||
this.name = name;
|
||||
this.friendlyFire = War.war.isDefaultFriendlyFire();
|
||||
this.setLifePool(War.war.getDefaultLifepool());
|
||||
this.setLoadout(War.war.getDefaultLoadout());
|
||||
this.setLoadout((HashMap<Integer, ItemStack>)War.war.getDefaultLoadout().clone());
|
||||
this.extraLoadouts = (HashMap<String, HashMap<Integer, ItemStack>>)War.war.getDefaultExtraLoadouts().clone();
|
||||
this.reward = (HashMap<Integer, ItemStack>)War.war.getDefaultReward().clone();
|
||||
this.setAutoAssignOnly(War.war.isDefaultAutoAssignOnly());
|
||||
this.setFlagPointsOnly(War.war.isDefaultFlagPointsOnly());
|
||||
this.teamCap = War.war.getDefaultTeamCap();
|
||||
@ -311,12 +316,19 @@ public class Warzone {
|
||||
// Fill hp
|
||||
player.setRemainingAir(300);
|
||||
player.setHealth(20);
|
||||
if (!this.getNewlyRespawned().keySet().contains(player.getName())) {
|
||||
this.getNewlyRespawned().put(player.getName(), 0);
|
||||
}
|
||||
|
||||
LoadoutResetJob job = new LoadoutResetJob(this, team, player);
|
||||
War.war.getServer().getScheduler().scheduleSyncDelayedTask(War.war, job);
|
||||
}
|
||||
|
||||
|
||||
public void resetInventory(Team team, Player player) {
|
||||
this.resetInventory(team, player, this.loadout);
|
||||
}
|
||||
|
||||
public void resetInventory(Team team, Player player, HashMap<Integer, ItemStack> loadout) {
|
||||
// Reset inventory to loadout
|
||||
PlayerInventory playerInv = player.getInventory();
|
||||
playerInv.clear();
|
||||
@ -324,15 +336,15 @@ public class Warzone {
|
||||
playerInv.clear(playerInv.getSize() + 1);
|
||||
playerInv.clear(playerInv.getSize() + 2);
|
||||
playerInv.clear(playerInv.getSize() + 3); // helmet/blockHead
|
||||
for (Integer slot : this.loadout.keySet()) {
|
||||
for (Integer slot : loadout.keySet()) {
|
||||
if (slot == 100) {
|
||||
playerInv.setBoots(this.loadout.get(slot));
|
||||
playerInv.setBoots(loadout.get(slot));
|
||||
} else if (slot == 101) {
|
||||
playerInv.setLeggings(this.loadout.get(slot));
|
||||
playerInv.setLeggings(loadout.get(slot));
|
||||
} else if (slot == 102) {
|
||||
playerInv.setChestplate(this.loadout.get(slot));
|
||||
playerInv.setChestplate(loadout.get(slot));
|
||||
} else {
|
||||
ItemStack item = this.loadout.get(slot);
|
||||
ItemStack item = loadout.get(slot);
|
||||
if (item != null) {
|
||||
playerInv.addItem(item);
|
||||
}
|
||||
@ -1130,4 +1142,16 @@ public class Warzone {
|
||||
public int getMinTeams() {
|
||||
return minTeams;
|
||||
}
|
||||
|
||||
public HashMap<String, HashMap<Integer, ItemStack>> getExtraLoadouts() {
|
||||
return extraLoadouts;
|
||||
}
|
||||
|
||||
public void setNewlyRespawned(HashMap<String, Integer> newlyRespawned) {
|
||||
this.newlyRespawned = newlyRespawned;
|
||||
}
|
||||
|
||||
public HashMap<String, Integer> getNewlyRespawned() {
|
||||
return newlyRespawned;
|
||||
}
|
||||
}
|
||||
|
@ -85,6 +85,30 @@ public class WarMapper {
|
||||
War.war.getDefaultLoadout().put(Integer.parseInt(itemStrSplit[2]), item);
|
||||
}
|
||||
}
|
||||
|
||||
// defaultExtraLoadouts
|
||||
String extraLoadoutStr = warConfig.getString("defaultExtraLoadouts");
|
||||
String[] extraLoadoutsSplit = extraLoadoutStr.split(",");
|
||||
War.war.getDefaultExtraLoadouts().clear();
|
||||
for (String nameStr : extraLoadoutsSplit) {
|
||||
if (nameStr != null && !nameStr.equals("")) {
|
||||
War.war.getDefaultExtraLoadouts().put(nameStr, new HashMap<Integer, ItemStack>());
|
||||
}
|
||||
}
|
||||
|
||||
for (String name : War.war.getDefaultExtraLoadouts().keySet()) {
|
||||
String loadoutStr = warConfig.getString(name + "Loadout");
|
||||
String[] loadoutSplit = loadoutStr.split(";");
|
||||
HashMap<Integer, ItemStack> loadout = War.war.getDefaultExtraLoadouts().get(name);
|
||||
loadout.clear();
|
||||
for (String str : loadoutSplit) {
|
||||
if (str != null && !str.equals("")) {
|
||||
String[] strSplit = str.split(",");
|
||||
ItemStack item = new ItemStack(Integer.parseInt(strSplit[0]), Integer.parseInt(strSplit[1]));
|
||||
loadout.put(Integer.parseInt(strSplit[2]), item);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// defaultLifePool
|
||||
War.war.setDefaultLifepool(warConfig.getInt("defaultLifePool"));
|
||||
@ -219,6 +243,23 @@ public class WarMapper {
|
||||
}
|
||||
warConfig.setString("defaultLoadout", defaultLoadoutStr);
|
||||
|
||||
// defaultExtraLoadouts
|
||||
String defaultExtraLoadoutsStr = "";
|
||||
for (String name : War.war.getDefaultExtraLoadouts().keySet()) {
|
||||
defaultExtraLoadoutsStr += name + ",";
|
||||
|
||||
String loadoutStr = "";
|
||||
HashMap<Integer, ItemStack> loadout = War.war.getDefaultExtraLoadouts().get(name);
|
||||
for (Integer slot : loadout.keySet()) {
|
||||
ItemStack item = loadout.get(slot);
|
||||
if (item != null) {
|
||||
loadoutStr += item.getTypeId() + "," + item.getAmount() + "," + slot + ";";
|
||||
}
|
||||
}
|
||||
warConfig.setString(name + "Loadout", loadoutStr);
|
||||
}
|
||||
warConfig.setString("defaultExtraLoadouts", defaultExtraLoadoutsStr);
|
||||
|
||||
// defaultLifepool
|
||||
warConfig.setInt("defaultLifePool", War.war.getDefaultLifepool());
|
||||
|
||||
|
@ -140,6 +140,31 @@ public class WarzoneMapper {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// extraLoadouts
|
||||
String extraLoadoutStr = warzoneConfig.getString("extraLoadouts");
|
||||
String[] extraLoadoutsSplit = extraLoadoutStr.split(",");
|
||||
War.war.getDefaultExtraLoadouts().clear();
|
||||
for (String nameStr : extraLoadoutsSplit) {
|
||||
if (nameStr != null && !nameStr.equals("")) {
|
||||
warzone.getExtraLoadouts().put(nameStr, new HashMap<Integer, ItemStack>());
|
||||
}
|
||||
}
|
||||
|
||||
for (String extraName : warzone.getExtraLoadouts().keySet()) {
|
||||
String loadoutString = warzoneConfig.getString(extraName + "Loadout");
|
||||
String[] loadoutSplit = loadoutString.split(";");
|
||||
HashMap<Integer, ItemStack> loadout = War.war.getDefaultExtraLoadouts().get(extraName);
|
||||
loadout.clear();
|
||||
for (String str : loadoutSplit) {
|
||||
if (str != null && !str.equals("")) {
|
||||
String[] strSplit = str.split(",");
|
||||
ItemStack item = new ItemStack(Integer.parseInt(strSplit[0]), Integer.parseInt(strSplit[1]));
|
||||
loadout.put(Integer.parseInt(strSplit[2]), item);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// life pool (always set after teams, so the teams' remaining lives get initialized properly by this setter)
|
||||
warzone.setLifePool(warzoneConfig.getInt("lifePool"));
|
||||
@ -358,6 +383,23 @@ public class WarzoneMapper {
|
||||
}
|
||||
}
|
||||
warzoneConfig.setString("loadout", loadoutStr);
|
||||
|
||||
// defaultExtraLoadouts
|
||||
String extraLoadoutsStr = "";
|
||||
for (String name : warzone.getExtraLoadouts().keySet()) {
|
||||
extraLoadoutsStr += name + ",";
|
||||
|
||||
String str = "";
|
||||
HashMap<Integer, ItemStack> loadout = warzone.getExtraLoadouts().get(name);
|
||||
for (Integer slot : loadout.keySet()) {
|
||||
ItemStack item = loadout.get(slot);
|
||||
if (item != null) {
|
||||
str += item.getTypeId() + "," + item.getAmount() + "," + slot + ";";
|
||||
}
|
||||
}
|
||||
warzoneConfig.setString(name + "Loadout", str);
|
||||
}
|
||||
warzoneConfig.setString("extraLoadouts", extraLoadoutsStr);
|
||||
|
||||
// life pool
|
||||
warzoneConfig.setInt("lifePool", warzone.getLifePool());
|
||||
|
Loading…
Reference in New Issue
Block a user