mirror of
https://github.com/taoneill/war.git
synced 2024-11-13 05:54:31 +01:00
Closes gh-109. Closes gh-110. Warzones are now REALLY loaded with a delay, giving time to Multiverse to load its worlds. HeroicDeath compatibility should fix all respawn inventory issues. This is v1.3.1.
This commit is contained in:
parent
e32745662b
commit
3aad54cefe
@ -139,7 +139,7 @@ public class War extends JavaPlugin {
|
||||
this.defaultAutoAssignOnly = false;
|
||||
this.getDefaultReward().put(0, new ItemStack(Material.CAKE, 1));
|
||||
WarMapper.load(this);
|
||||
this.logInfo("Done. War v"+ desc.getVersion() + " is on.");
|
||||
this.logInfo("War v"+ desc.getVersion() + " is on.");
|
||||
}
|
||||
|
||||
public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
|
||||
|
@ -1,6 +1,5 @@
|
||||
package bukkit.tommytony.war;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.Location;
|
||||
@ -13,15 +12,13 @@ import org.bukkit.event.entity.EntityCombustEvent;
|
||||
import org.bukkit.event.entity.EntityDamageByEntityEvent;
|
||||
import org.bukkit.event.entity.EntityDamageByProjectileEvent;
|
||||
import org.bukkit.event.entity.EntityDamageEvent;
|
||||
import org.bukkit.event.entity.EntityDamageEvent.DamageCause;
|
||||
import org.bukkit.event.entity.EntityDeathEvent;
|
||||
import org.bukkit.event.entity.EntityExplodeEvent;
|
||||
import org.bukkit.event.entity.EntityListener;
|
||||
import org.bukkit.event.entity.EntityDamageEvent.DamageCause;
|
||||
import org.bukkit.event.player.PlayerMoveEvent;
|
||||
|
||||
import com.tommytony.war.Team;
|
||||
import com.tommytony.war.Warzone;
|
||||
import com.tommytony.war.jobs.LootDropperTask;
|
||||
|
||||
/**
|
||||
*
|
||||
|
@ -16,7 +16,9 @@ import org.bukkit.inventory.PlayerInventory;
|
||||
import bukkit.tommytony.war.War;
|
||||
|
||||
import com.tommytony.war.jobs.InitZoneJob;
|
||||
import com.tommytony.war.jobs.LoadoutResetJob;
|
||||
import com.tommytony.war.jobs.ResetCursorJob;
|
||||
import com.tommytony.war.jobs.RespawnPlayerJob;
|
||||
import com.tommytony.war.jobs.ScoreCapReachedJob;
|
||||
import com.tommytony.war.utils.InventoryStash;
|
||||
import com.tommytony.war.volumes.BlockInfo;
|
||||
@ -364,6 +366,19 @@ public class Warzone {
|
||||
}
|
||||
|
||||
private void handleRespawn(Team team, Player player){
|
||||
// Fill hp
|
||||
player.setFireTicks(0);
|
||||
player.setRemainingAir(300);
|
||||
player.setHealth(20);
|
||||
|
||||
// Teleport the player back to spawn
|
||||
player.teleportTo(team.getTeamSpawn());
|
||||
|
||||
LoadoutResetJob job = new LoadoutResetJob(this, team, player);
|
||||
war.getServer().getScheduler().scheduleSyncDelayedTask(war, job);
|
||||
}
|
||||
|
||||
public void resetInventory(Team team, Player player) {
|
||||
// Reset inventory to loadout
|
||||
PlayerInventory playerInv = player.getInventory();
|
||||
playerInv.clear();
|
||||
@ -395,27 +410,6 @@ public class Warzone {
|
||||
playerInv.setHelmet(new ItemStack(Material.LEATHER_HELMET));
|
||||
}
|
||||
}
|
||||
|
||||
// Fill hp
|
||||
player.setHealth(20);
|
||||
player.setFireTicks(0);
|
||||
player.setRemainingAir(300);
|
||||
|
||||
// Teleport the player back to spawn
|
||||
// Location playerLoc = player.getLocation();
|
||||
// int x = playerLoc.getBlockX();
|
||||
// int y = playerLoc.getBlockY();
|
||||
// int z = playerLoc.getBlockZ();
|
||||
// Block playerBlock = world.getBlockAt(x, y, z).getFace(BlockFace.UP);
|
||||
// Material playerBlockType = playerBlock.getType();
|
||||
// if(playerBlockType.getId() == Material.WATER.getId()
|
||||
// || playerBlockType.getId() == Material.STATIONARY_WATER.getId()) {
|
||||
// // If in water, make arbitrary adjustments to fix drowning deaths causing "Player moved wrongly!" error
|
||||
// player.teleportTo(new Location(playerLoc.getWorld(),
|
||||
// team.getTeamSpawn().getX(), team.getTeamSpawn().getY() + 3, team.getTeamSpawn().getZ()));
|
||||
// } else {
|
||||
player.teleportTo(team.getTeamSpawn());
|
||||
// }
|
||||
}
|
||||
|
||||
public boolean isMonumentCenterBlock(Block block) {
|
||||
@ -862,83 +856,80 @@ public class Warzone {
|
||||
war.msg(player, "You died.");
|
||||
boolean newBattle = false;
|
||||
boolean scoreCapReached = false;
|
||||
//synchronized(playerWarzone) {
|
||||
//synchronized(player) {
|
||||
int remaining = playerTeam.getRemainingLifes();
|
||||
if(remaining == 0) { // your death caused your team to lose
|
||||
List<Team> teams = playerWarzone.getTeams();
|
||||
String scores = "";
|
||||
for(Team t : teams) {
|
||||
t.teamcast("The battle is over. Team " + playerTeam.getName() + " lost: "
|
||||
+ player.getName() + " died and there were no lives left in their life pool.");
|
||||
|
||||
if(!t.getName().equals(playerTeam.getName())) {
|
||||
// all other teams get a point
|
||||
t.addPoint();
|
||||
t.resetSign();
|
||||
}
|
||||
scores += t.getName() + "(" + t.getPoints() + ") " ;
|
||||
}
|
||||
if(!scores.equals("")){
|
||||
for(Team t : teams) {
|
||||
t.teamcast("New scores - " + scores + " (/" + getScoreCap() + ")" );
|
||||
}
|
||||
}
|
||||
// detect score cap
|
||||
List<Team> scoreCapTeams = new ArrayList<Team>();
|
||||
for(Team t : teams) {
|
||||
if(t.getPoints() == playerWarzone.getScoreCap()) {
|
||||
scoreCapTeams.add(t);
|
||||
}
|
||||
}
|
||||
if(!scoreCapTeams.isEmpty()) {
|
||||
String winnersStr = "";
|
||||
for(Team winner : scoreCapTeams) {
|
||||
winnersStr += winner.getName() + " ";
|
||||
}
|
||||
|
||||
playerWarzone.handleScoreCapReached(player, winnersStr);
|
||||
//player.teleportTo(playerWarzone.getTeleport());
|
||||
// player will die because it took too long :(
|
||||
// we dont restore his inventory in handleScoreCapReached
|
||||
// check out PLAYER_MOVE for the rest of the fix
|
||||
|
||||
scoreCapReached = true;
|
||||
} else {
|
||||
// A new battle starts. Reset the zone but not the teams.
|
||||
for(Team t : teams) {
|
||||
t.teamcast("A new battle begins. Resetting warzone...");
|
||||
}
|
||||
playerWarzone.getVolume().resetBlocksAsJob();
|
||||
playerWarzone.initializeZoneAsJob(player);
|
||||
newBattle = true;
|
||||
}
|
||||
} else {
|
||||
// player died without causing his team's demise
|
||||
if(playerWarzone.isFlagThief(player.getName())) {
|
||||
// died while carrying flag.. dropped it
|
||||
Team victim = playerWarzone.getVictimTeamForThief(player.getName());
|
||||
victim.getFlagVolume().resetBlocks();
|
||||
victim.initializeTeamFlag();
|
||||
playerWarzone.removeThief(player.getName());
|
||||
for(Team t : playerWarzone.getTeams()) {
|
||||
t.teamcast(player.getName() + " died and dropped team " + victim.getName() + "'s flag.");
|
||||
}
|
||||
}
|
||||
playerTeam.setRemainingLives(remaining - 1);
|
||||
if(remaining - 1 == 0) {
|
||||
for(Team t : playerWarzone.getTeams()) {
|
||||
t.teamcast("Team " + playerTeam.getName() + "'s life pool is empty. One more death and they lose the battle!");
|
||||
}
|
||||
}
|
||||
playerWarzone.respawnPlayer(playerTeam, player);
|
||||
int remaining = playerTeam.getRemainingLifes();
|
||||
if(remaining == 0) { // your death caused your team to lose
|
||||
List<Team> teams = playerWarzone.getTeams();
|
||||
String scores = "";
|
||||
for(Team t : teams) {
|
||||
t.teamcast("The battle is over. Team " + playerTeam.getName() + " lost: "
|
||||
+ player.getName() + " died and there were no lives left in their life pool.");
|
||||
|
||||
if(!t.getName().equals(playerTeam.getName())) {
|
||||
// all other teams get a point
|
||||
t.addPoint();
|
||||
t.resetSign();
|
||||
}
|
||||
//if(!newBattle /*&& !scoreCapReached*/) {
|
||||
playerTeam.resetSign();
|
||||
playerWarzone.respawnPlayer(playerTeam, player);
|
||||
//}
|
||||
scores += t.getName() + "(" + t.getPoints() + ") " ;
|
||||
}
|
||||
if(!scores.equals("")){
|
||||
for(Team t : teams) {
|
||||
t.teamcast("New scores - " + scores + " (/" + getScoreCap() + ")" );
|
||||
}
|
||||
}
|
||||
// detect score cap
|
||||
List<Team> scoreCapTeams = new ArrayList<Team>();
|
||||
for(Team t : teams) {
|
||||
if(t.getPoints() == playerWarzone.getScoreCap()) {
|
||||
scoreCapTeams.add(t);
|
||||
}
|
||||
}
|
||||
if(!scoreCapTeams.isEmpty()) {
|
||||
String winnersStr = "";
|
||||
for(Team winner : scoreCapTeams) {
|
||||
winnersStr += winner.getName() + " ";
|
||||
}
|
||||
|
||||
playerWarzone.handleScoreCapReached(player, winnersStr);
|
||||
//player.teleportTo(playerWarzone.getTeleport());
|
||||
// player will die because it took too long :(
|
||||
// we dont restore his inventory in handleScoreCapReached
|
||||
// check out PLAYER_MOVE for the rest of the fix
|
||||
|
||||
scoreCapReached = true;
|
||||
} else {
|
||||
// A new battle starts. Reset the zone but not the teams.
|
||||
for(Team t : teams) {
|
||||
t.teamcast("A new battle begins. Resetting warzone...");
|
||||
}
|
||||
playerWarzone.getVolume().resetBlocksAsJob();
|
||||
playerWarzone.initializeZoneAsJob(player);
|
||||
newBattle = true;
|
||||
}
|
||||
} else {
|
||||
// player died without causing his team's demise
|
||||
if(playerWarzone.isFlagThief(player.getName())) {
|
||||
// died while carrying flag.. dropped it
|
||||
Team victim = playerWarzone.getVictimTeamForThief(player.getName());
|
||||
victim.getFlagVolume().resetBlocks();
|
||||
victim.initializeTeamFlag();
|
||||
playerWarzone.removeThief(player.getName());
|
||||
for(Team t : playerWarzone.getTeams()) {
|
||||
t.teamcast(player.getName() + " died and dropped team " + victim.getName() + "'s flag.");
|
||||
}
|
||||
}
|
||||
playerTeam.setRemainingLives(remaining - 1);
|
||||
if(remaining - 1 == 0) {
|
||||
for(Team t : playerWarzone.getTeams()) {
|
||||
t.teamcast("Team " + playerTeam.getName() + "'s life pool is empty. One more death and they lose the battle!");
|
||||
}
|
||||
}
|
||||
}
|
||||
playerTeam.resetSign();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void handlePlayerLeave(Player player, Location destination, boolean removeFromTeam) {
|
||||
Team playerTeam = war.getPlayerTeam(player.getName());
|
||||
if(playerTeam !=null) {
|
||||
|
@ -0,0 +1,24 @@
|
||||
package com.tommytony.war.jobs;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.tommytony.war.Team;
|
||||
import com.tommytony.war.Warzone;
|
||||
|
||||
public class LoadoutResetJob implements Runnable {
|
||||
|
||||
private final Player player;
|
||||
private final Warzone zone;
|
||||
private final Team team;
|
||||
|
||||
public LoadoutResetJob(Warzone zone, Team team, Player player) {
|
||||
this.zone = zone;
|
||||
this.team = team;
|
||||
this.player = player;
|
||||
}
|
||||
|
||||
public void run() {
|
||||
zone.resetInventory(team, player);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,25 @@
|
||||
package com.tommytony.war.jobs;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.tommytony.war.Team;
|
||||
import com.tommytony.war.Warzone;
|
||||
|
||||
public class RespawnPlayerJob implements Runnable {
|
||||
|
||||
private final Team team;
|
||||
private final Player player;
|
||||
private final Warzone zone;
|
||||
|
||||
public RespawnPlayerJob(Warzone zone, Team playerTeam, Player player) {
|
||||
this.zone = zone;
|
||||
// TODO Auto-generated constructor stub
|
||||
team = playerTeam;
|
||||
this.player = player;
|
||||
}
|
||||
|
||||
public void run() {
|
||||
zone.respawnPlayer(team, player);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,55 @@
|
||||
package com.tommytony.war.jobs;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
|
||||
import bukkit.tommytony.war.War;
|
||||
|
||||
import com.tommytony.war.WarHub;
|
||||
import com.tommytony.war.Warzone;
|
||||
import com.tommytony.war.mappers.VolumeMapper;
|
||||
import com.tommytony.war.volumes.Volume;
|
||||
|
||||
public class RestoreWarhubJob implements Runnable {
|
||||
|
||||
private final War war;
|
||||
private final String hubStr;
|
||||
|
||||
public RestoreWarhubJob(War war, String hubStr) {
|
||||
this.war = war;
|
||||
this.hubStr = hubStr;
|
||||
}
|
||||
|
||||
public void run() {
|
||||
String[] hubStrSplit = hubStr.split(",");
|
||||
|
||||
int hubX = Integer.parseInt(hubStrSplit[0]);
|
||||
int hubY = Integer.parseInt(hubStrSplit[1]);
|
||||
int hubZ = Integer.parseInt(hubStrSplit[2]);
|
||||
World world = null;
|
||||
if(hubStrSplit.length > 3) {
|
||||
String worldName = hubStrSplit[3];
|
||||
world = war.getServer().getWorld(worldName);
|
||||
} else {
|
||||
world = war.getServer().getWorlds().get(0); // default to first world
|
||||
}
|
||||
Location hubLocation = new Location(world, hubX, hubY, hubZ);
|
||||
WarHub hub = new WarHub(war, hubLocation);
|
||||
war.setWarHub(hub);
|
||||
Volume vol = VolumeMapper.loadVolume("warhub", "", war, world);
|
||||
hub.setVolume(vol);
|
||||
hub.getVolume().resetBlocks();
|
||||
hub.initialize();
|
||||
|
||||
// In the previous job started by the mapper, warzones were created, but their lobbies are missing the war hub gate (because it didn't exist yet)
|
||||
for(Warzone zone : war.getWarzones()) {
|
||||
if(zone.getLobby() != null) {
|
||||
zone.getLobby().getVolume().resetBlocks();
|
||||
zone.getLobby().initialize();
|
||||
}
|
||||
}
|
||||
|
||||
war.logInfo("Warhub ready.");
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,40 @@
|
||||
package com.tommytony.war.jobs;
|
||||
|
||||
import bukkit.tommytony.war.War;
|
||||
|
||||
import com.tommytony.war.Warzone;
|
||||
import com.tommytony.war.mappers.WarzoneMapper;
|
||||
|
||||
public class RestoreWarzonesJob implements Runnable {
|
||||
|
||||
private final War war;
|
||||
private final String warzonesStr;
|
||||
private final boolean newWarInstall;
|
||||
|
||||
public RestoreWarzonesJob(War war, String warzonesStr, boolean newWarInstall) {
|
||||
this.war = war;
|
||||
this.warzonesStr = warzonesStr;
|
||||
this.newWarInstall = newWarInstall;
|
||||
}
|
||||
|
||||
public void run() {
|
||||
String[] warzoneSplit = warzonesStr.split(",");
|
||||
war.getWarzones().clear();
|
||||
for(String warzoneName : warzoneSplit) {
|
||||
if(warzoneName != null && !warzoneName.equals("")){
|
||||
war.logInfo("Restoring zone " + warzoneName + "...");
|
||||
Warzone zone = WarzoneMapper.load(war, warzoneName, !newWarInstall); // cascade load, only load blocks if warzone exists
|
||||
if(zone != null) { // could have failed, would've been logged already
|
||||
war.getWarzones().add(zone);
|
||||
zone.getVolume().resetBlocks();
|
||||
if(zone.getLobby() != null) {
|
||||
zone.getLobby().getVolume().resetBlocks();
|
||||
}
|
||||
zone.initializeZone();
|
||||
}
|
||||
}
|
||||
}
|
||||
war.logInfo("Warzones ready.");
|
||||
}
|
||||
|
||||
}
|
@ -12,6 +12,8 @@ import bukkit.tommytony.war.War;
|
||||
import com.tommytony.war.TeamSpawnStyles;
|
||||
import com.tommytony.war.WarHub;
|
||||
import com.tommytony.war.Warzone;
|
||||
import com.tommytony.war.jobs.RestoreWarhubJob;
|
||||
import com.tommytony.war.jobs.RestoreWarzonesJob;
|
||||
import com.tommytony.war.volumes.Volume;
|
||||
|
||||
/**
|
||||
@ -49,21 +51,9 @@ public class WarMapper {
|
||||
|
||||
// warzones
|
||||
String warzonesStr = warConfig.getString("warzones");
|
||||
String[] warzoneSplit = warzonesStr.split(",");
|
||||
war.getWarzones().clear();
|
||||
for(String warzoneName : warzoneSplit) {
|
||||
if(warzoneName != null && !warzoneName.equals("")){
|
||||
war.logInfo("Starting zone " + warzoneName + " restore...");
|
||||
Warzone zone = WarzoneMapper.load(war, warzoneName, !newWar); // cascade load, only load blocks if warzone exists
|
||||
if(zone != null) { // could have failed, would've been logged already
|
||||
war.getWarzones().add(zone);
|
||||
zone.getVolume().resetBlocksAsJob();
|
||||
if(zone.getLobby() != null) {
|
||||
zone.getLobby().getVolume().resetBlocksAsJob();
|
||||
}
|
||||
zone.initializeZoneAsJob();
|
||||
}
|
||||
}
|
||||
RestoreWarzonesJob restoreWarzones = new RestoreWarzonesJob(war, warzonesStr, newWar);
|
||||
if(war.getServer().getScheduler().scheduleSyncDelayedTask(war, restoreWarzones) == -1) {
|
||||
war.logWarn("Failed to schedule warzone-restore job. No warzone was loaded.");
|
||||
}
|
||||
|
||||
// zone makers
|
||||
@ -155,41 +145,16 @@ public class WarMapper {
|
||||
// warhub
|
||||
String hubStr = warConfig.getString("warhub");
|
||||
if(hubStr != null && !hubStr.equals("")) {
|
||||
String[] hubStrSplit = hubStr.split(",");
|
||||
|
||||
int hubX = Integer.parseInt(hubStrSplit[0]);
|
||||
int hubY = Integer.parseInt(hubStrSplit[1]);
|
||||
int hubZ = Integer.parseInt(hubStrSplit[2]);
|
||||
World world = null;
|
||||
if(hubStrSplit.length > 3) {
|
||||
String worldName = hubStrSplit[3];
|
||||
world = war.getServer().getWorld(worldName);
|
||||
} else {
|
||||
world = war.getServer().getWorlds().get(0); // default to first world
|
||||
RestoreWarhubJob restoreWarhub = new RestoreWarhubJob(war, hubStr);
|
||||
if(war.getServer().getScheduler().scheduleSyncDelayedTask(war, restoreWarhub) == -1) {
|
||||
war.logWarn("Failed to schedule warhub-restore job. War hub was not loaded.");
|
||||
}
|
||||
Location hubLocation = new Location(world, hubX, hubY, hubZ);
|
||||
WarHub hub = new WarHub(war, hubLocation);
|
||||
war.setWarHub(hub);
|
||||
Volume vol = VolumeMapper.loadVolume("warhub", "", war, world);
|
||||
hub.setVolume(vol);
|
||||
hub.getVolume().resetBlocks();
|
||||
hub.initialize();
|
||||
|
||||
// for(Warzone zone : war.getWarzones()) {
|
||||
// if(zone.getLobby() != null) {
|
||||
// zone.getLobby().getVolume().resetBlocksAsJob();
|
||||
// zone.getLobby().initialize(); // adds the warhub link gate
|
||||
// }
|
||||
//
|
||||
// }
|
||||
}
|
||||
|
||||
warConfig.close();
|
||||
//war.getLogger().info("Loaded war config.");
|
||||
}
|
||||
|
||||
public static void save(War war) {
|
||||
//war.getLogger().info("Saving war config...");
|
||||
PropertiesFile warConfig = new PropertiesFile(war.getDataFolder().getPath() + "/war.txt");
|
||||
String warzonesStr = "";
|
||||
|
||||
@ -275,6 +240,5 @@ public class WarMapper {
|
||||
|
||||
warConfig.save();
|
||||
warConfig.close();
|
||||
//war.getLogger().info("Saved war config.");
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
name: War
|
||||
version: 1.3 (Rokossovsky)
|
||||
version: 1.3.1 (Rokossovsky)
|
||||
description: Lets you create TDM and CTF (warzones) for a more structured PVP experience.
|
||||
author: tommytony
|
||||
website: war.tommytony.com
|
||||
|
@ -1,5 +1,5 @@
|
||||
name: War
|
||||
version: 1.3 (Rokossovsky)
|
||||
version: 1.3.1 (Rokossovsky)
|
||||
description: Lets you create TDM and CTF (warzones) for a more structured PVP experience.
|
||||
author: tommytony
|
||||
website: war.tommytony.com
|
||||
|
Loading…
Reference in New Issue
Block a user