Replace deprecated Bukkit functions

This commit is contained in:
Connor Monahan 2017-07-18 14:33:44 -04:00
parent 334620e4b1
commit 66445eb61d
13 changed files with 145 additions and 164 deletions

View File

@ -496,9 +496,8 @@ public class Team {
this.remainingLives = remainingLives;
if (this.warzone.getScoreboard() != null && this.warzone.getScoreboardType() == ScoreboardType.LIFEPOOL) {
String teamName = kind.getColor() + name + ChatColor.RESET;
OfflinePlayer teamPlayer = Bukkit.getOfflinePlayer(teamName);
Objective obj = this.warzone.getScoreboard().getObjective("Lifepool");
obj.getScore(teamPlayer).setScore(remainingLives);
obj.getScore(teamName).setScore(remainingLives);
}
}
@ -522,7 +521,7 @@ public class Team {
if (this.warzone.getScoreboardType() == ScoreboardType.POINTS) {
String teamName = kind.getColor() + name + ChatColor.RESET;
this.warzone.getScoreboard().getObjective(DisplaySlot.SIDEBAR)
.getScore(Bukkit.getOfflinePlayer(teamName)).setScore(points);
.getScore(teamName).setScore(points);
}
}
@ -558,7 +557,7 @@ public class Team {
&& this.warzone.getScoreboard() != null) {
String teamName = kind.getColor() + name + ChatColor.RESET;
this.warzone.getScoreboard().getObjective(DisplaySlot.SIDEBAR)
.getScore(Bukkit.getOfflinePlayer(teamName)).setScore(points);
.getScore(teamName).setScore(points);
}
}

View File

@ -585,7 +585,7 @@ public class War extends JavaPlugin {
}
if (namedParams.containsKey("lobbymaterial")) {
String whichBlocks = namedParams.get("lobbymaterial");
ItemStack blockInHand = player.getItemInHand();
ItemStack blockInHand = player.getInventory().getItemInMainHand();
boolean updatedLobbyMaterials = false;
if (!blockInHand.getType().isBlock() && !blockInHand.getType().equals(Material.AIR)) {
@ -593,19 +593,19 @@ public class War extends JavaPlugin {
} else {
if (whichBlocks.equals("floor")) {
warzone.getLobbyMaterials().setFloorBlock(blockInHand);
returnMessage.append(" lobby floor material set to " + blockInHand.getType());
returnMessage.append(" lobby floor material set to ").append(blockInHand.getType());
updatedLobbyMaterials = true;
} else if (whichBlocks.equals("outline")) {
warzone.getLobbyMaterials().setOutlineBlock(blockInHand);
returnMessage.append(" lobby outline material set to " + blockInHand.getType());
returnMessage.append(" lobby outline material set to ").append(blockInHand.getType());
updatedLobbyMaterials = true;
} else if (whichBlocks.equals("gate")) {
warzone.getLobbyMaterials().setGateBlock(blockInHand);
returnMessage.append(" lobby gate material set to " + blockInHand.getType());
returnMessage.append(" lobby gate material set to ").append(blockInHand.getType());
updatedLobbyMaterials = true;
} else if (whichBlocks.equals("light")) {
warzone.getLobbyMaterials().setLightBlock(blockInHand);
returnMessage.append(" lobby light material set to " + blockInHand.getType());
returnMessage.append(" lobby light material set to ").append(blockInHand.getType());
updatedLobbyMaterials = true;
}
@ -617,7 +617,7 @@ public class War extends JavaPlugin {
}
if (namedParams.containsKey("material")) {
String whichBlocks = namedParams.get("material");
ItemStack blockInHand = player.getItemInHand();
ItemStack blockInHand = player.getInventory().getItemInMainHand();
boolean updatedMaterials = false;
if (!blockInHand.getType().isBlock()) {
@ -625,15 +625,15 @@ public class War extends JavaPlugin {
} else {
if (whichBlocks.equals("main")) {
warzone.getWarzoneMaterials().setMainBlock(blockInHand);
returnMessage.append(" main material set to " + blockInHand.getType());
returnMessage.append(" main material set to ").append(blockInHand.getType());
updatedMaterials = true;
} else if (whichBlocks.equals("stand")) {
warzone.getWarzoneMaterials().setStandBlock(blockInHand);
returnMessage.append(" stand material set to " + blockInHand.getType());
returnMessage.append(" stand material set to ").append(blockInHand.getType());
updatedMaterials = true;
} else if (whichBlocks.equals("light")) {
warzone.getWarzoneMaterials().setLightBlock(blockInHand);
returnMessage.append(" light material set to " + blockInHand.getType());
returnMessage.append(" light material set to ").append(blockInHand.getType());
updatedMaterials = true;
}
@ -741,7 +741,7 @@ public class War extends JavaPlugin {
}
if (namedParams.containsKey("warhubmaterial")) {
String whichBlocks = namedParams.get("warhubmaterial");
ItemStack blockInHand = player.getItemInHand();
ItemStack blockInHand = player.getInventory().getItemInMainHand();
boolean updatedWarhubMaterials = false;
if (!blockInHand.getType().isBlock() && !blockInHand.getType().equals(Material.AIR)) {

View File

@ -5,14 +5,7 @@ import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Random;
import java.util.*;
import java.util.logging.Level;
import net.milkbowl.vault.economy.EconomyResponse;
@ -117,9 +110,9 @@ public class Warzone {
private final int minSafeDistanceFromWall = 6;
private List<ZoneWallGuard> zoneWallGuards = new ArrayList<ZoneWallGuard>();
private HashMap<String, PlayerState> playerStates = new HashMap<String, PlayerState>();
private HashMap<String, Team> flagThieves = new HashMap<String, Team>();
private HashMap<String, Bomb> bombThieves = new HashMap<String, Bomb>();
private HashMap<String, Cake> cakeThieves = new HashMap<String, Cake>();
private HashMap<UUID, Team> flagThieves = new HashMap<UUID, Team>();
private HashMap<UUID, Bomb> bombThieves = new HashMap<UUID, Bomb>();
private HashMap<UUID, Cake> cakeThieves = new HashMap<UUID, Cake>();
private HashMap<String, LoadoutSelection> loadoutSelections = new HashMap<String, LoadoutSelection>();
private HashMap<String, PlayerState> deadMenInventories = new HashMap<String, PlayerState>();
private HashMap<String, Integer> killCount = new HashMap<String, Integer>();
@ -307,8 +300,8 @@ public class Warzone {
public void initializeZone(Player respawnExempted) {
if (this.ready() && this.volume.isSaved()) {
if (this.scoreboard != null) {
for (OfflinePlayer opl : this.scoreboard.getPlayers()) {
this.scoreboard.resetScores(opl);
for (String entry : this.scoreboard.getEntries()) {
this.scoreboard.resetScores(entry);
}
this.scoreboard.clearSlot(DisplaySlot.SIDEBAR);
for (Objective obj : this.scoreboard.getObjectives()) {
@ -399,9 +392,9 @@ public class Warzone {
for (Team team : this.getTeams()) {
String teamName = team.getKind().getColor() + team.getName() + ChatColor.RESET;
if (this.getScoreboardType() == ScoreboardType.POINTS) {
obj.getScore(Bukkit.getOfflinePlayer(teamName)).setScore(team.getPoints());
obj.getScore(teamName).setScore(team.getPoints());
} else if (this.getScoreboardType() == ScoreboardType.LIFEPOOL) {
obj.getScore(Bukkit.getOfflinePlayer(teamName)).setScore(team.getRemainingLifes());
obj.getScore(teamName).setScore(team.getRemainingLifes());
}
}
obj.setDisplaySlot(DisplaySlot.SIDEBAR);
@ -753,6 +746,9 @@ public class Warzone {
}
public boolean isImportantBlock(Block block) {
if (block == null) {
return false;
}
if (this.ready()) {
for (Monument m : this.monuments) {
if (m.getVolume().contains(block)) {
@ -1035,10 +1031,11 @@ public class Warzone {
if (this.getWarzoneConfig().getBoolean(WarzoneConfig.DEATHMESSAGES)) {
String attackerString = attackerTeam.getKind().getColor() + attacker.getName();
String defenderString = defenderTeam.getKind().getColor() + defender.getName();
Material killerWeapon = attacker.getItemInHand().getType();
ItemStack weapon = attacker.getInventory().getItemInMainHand(); // Not the right way to do this, as they could kill with their other hand, but whatever
Material killerWeapon = weapon.getType();
String weaponString = killerWeapon.toString();
if (attacker.getItemInHand().hasItemMeta() && attacker.getItemInHand().getItemMeta().hasDisplayName()) {
weaponString = attacker.getItemInHand().getItemMeta().getDisplayName() + ChatColor.WHITE;
if (weapon.hasItemMeta() && weapon.getItemMeta().hasDisplayName()) {
weaponString = weapon.getItemMeta().getDisplayName() + ChatColor.WHITE;
}
if (killerWeapon == Material.AIR) {
weaponString = War.war.getString("pvp.kill.weapon.hand");
@ -1068,7 +1065,7 @@ public class Warzone {
}
if (this.getScoreboard() != null && this.getScoreboardType() == ScoreboardType.TOPKILLS) {
Objective obj = this.getScoreboard().getObjective("Top kills");
obj.getScore(attacker).setScore(this.getKillCount(attacker.getName()));
obj.getScore(attacker.getName()).setScore(this.getKillCount(attacker.getName()));
}
if (defenderTeam.getTeamConfig().resolveBoolean(TeamConfig.INVENTORYDROP)) {
dropItems(defender.getLocation(), defender.getInventory().getContents());
@ -1166,7 +1163,7 @@ public class Warzone {
}
if (War.war.getMysqlConfig().isEnabled() && War.war.getMysqlConfig().isLoggingEnabled()) {
LogKillsDeathsJob logKillsDeathsJob = new LogKillsDeathsJob(ImmutableList.copyOf(this.getKillsDeathsTracker()));
War.war.getServer().getScheduler().runTaskAsynchronously(War.war, logKillsDeathsJob);
logKillsDeathsJob.runTaskAsynchronously(War.war);
}
this.getKillsDeathsTracker().clear();
if (!detectScoreCap()) {
@ -1297,70 +1294,61 @@ public class Warzone {
}
// Flags
public void addFlagThief(Team lostFlagTeam, String flagThief) {
this.flagThieves.put(flagThief, lostFlagTeam);
WarPlayerThiefEvent event1 = new WarPlayerThiefEvent(Bukkit.getPlayerExact(flagThief), WarPlayerThiefEvent.StolenObject.FLAG);
public void addFlagThief(Team lostFlagTeam, Player flagThief) {
this.flagThieves.put(flagThief.getUniqueId(), lostFlagTeam);
WarPlayerThiefEvent event1 = new WarPlayerThiefEvent(flagThief, WarPlayerThiefEvent.StolenObject.FLAG);
War.war.getServer().getPluginManager().callEvent(event1);
}
public boolean isFlagThief(String suspect) {
if (this.flagThieves.containsKey(suspect)) {
return true;
}
return false;
public boolean isFlagThief(Player suspect) {
return this.flagThieves.containsKey(suspect.getUniqueId());
}
public Team getVictimTeamForFlagThief(String thief) {
return this.flagThieves.get(thief);
public Team getVictimTeamForFlagThief(Player thief) {
return this.flagThieves.get(thief.getUniqueId());
}
public void removeFlagThief(String thief) {
this.flagThieves.remove(thief);
public void removeFlagThief(Player thief) {
this.flagThieves.remove(thief.getUniqueId());
}
// Bomb
public void addBombThief(Bomb bomb, String bombThief) {
this.bombThieves.put(bombThief, bomb);
WarPlayerThiefEvent event1 = new WarPlayerThiefEvent(Bukkit.getPlayerExact(bombThief), WarPlayerThiefEvent.StolenObject.BOMB);
public void addBombThief(Bomb bomb, Player bombThief) {
this.bombThieves.put(bombThief.getUniqueId(), bomb);
WarPlayerThiefEvent event1 = new WarPlayerThiefEvent(bombThief, WarPlayerThiefEvent.StolenObject.BOMB);
War.war.getServer().getPluginManager().callEvent(event1);
}
public boolean isBombThief(String suspect) {
if (this.bombThieves.containsKey(suspect)) {
return true;
}
return false;
public boolean isBombThief(Player suspect) {
return this.bombThieves.containsKey(suspect.getUniqueId());
}
public Bomb getBombForThief(String thief) {
return this.bombThieves.get(thief);
public Bomb getBombForThief(Player thief) {
return this.bombThieves.get(thief.getUniqueId());
}
public void removeBombThief(String thief) {
this.bombThieves.remove(thief);
public void removeBombThief(Player thief) {
this.bombThieves.remove(thief.getUniqueId());
}
// Cake
public void addCakeThief(Cake cake, String cakeThief) {
this.cakeThieves.put(cakeThief, cake);
WarPlayerThiefEvent event1 = new WarPlayerThiefEvent(Bukkit.getPlayerExact(cakeThief), WarPlayerThiefEvent.StolenObject.CAKE);
public void addCakeThief(Cake cake, Player cakeThief) {
this.cakeThieves.put(cakeThief.getUniqueId(), cake);
WarPlayerThiefEvent event1 = new WarPlayerThiefEvent(cakeThief, WarPlayerThiefEvent.StolenObject.CAKE);
War.war.getServer().getPluginManager().callEvent(event1);
}
public boolean isCakeThief(String suspect) {
if (this.cakeThieves.containsKey(suspect)) {
return true;
}
return false;
public boolean isCakeThief(Player suspect) {
return this.cakeThieves.containsKey(suspect.getUniqueId());
}
public Cake getCakeForThief(String thief) {
return this.cakeThieves.get(thief);
public Cake getCakeForThief(Player thief) {
return this.cakeThieves.get(thief.getUniqueId());
}
public void removeCakeThief(String thief) {
this.cakeThieves.remove(thief);
public void removeCakeThief(Player thief) {
this.cakeThieves.remove(thief.getUniqueId());
}
public void clearThieves() {
@ -1370,7 +1358,7 @@ public class Warzone {
}
public boolean isTeamFlagStolen(Team team) {
for (String playerKey : this.flagThieves.keySet()) {
for (UUID playerKey : this.flagThieves.keySet()) {
if (this.flagThieves.get(playerKey).getName().equals(team.getName())) {
return true;
}
@ -1860,10 +1848,10 @@ public class Warzone {
}
public void dropAllStolenObjects(Player player, boolean quiet) {
if (this.isFlagThief(player.getName())) {
Team victimTeam = this.getVictimTeamForFlagThief(player.getName());
if (this.isFlagThief(player)) {
Team victimTeam = this.getVictimTeamForFlagThief(player);
this.removeFlagThief(player.getName());
this.removeFlagThief(player);
// Bring back flag of victim team
victimTeam.getFlagVolume().resetBlocks();
@ -1872,10 +1860,10 @@ public class Warzone {
if (!quiet) {
this.broadcast("drop.flag.broadcast", player.getName(), victimTeam.getKind().getColor() + victimTeam.getName() + ChatColor.WHITE);
}
} else if (this.isCakeThief(player.getName())) {
Cake cake = this.getCakeForThief(player.getName());
} else if (this.isCakeThief(player)) {
Cake cake = this.getCakeForThief(player);
this.removeCakeThief(player.getName());
this.removeCakeThief(player);
// Bring back cake
cake.getVolume().resetBlocks();
@ -1884,10 +1872,10 @@ public class Warzone {
if (!quiet) {
this.broadcast("drop.cake.broadcast", player.getName(), ChatColor.GREEN + cake.getName() + ChatColor.WHITE);
}
} else if (this.isBombThief(player.getName())) {
Bomb bomb = this.getBombForThief(player.getName());
} else if (this.isBombThief(player)) {
Bomb bomb = this.getBombForThief(player);
this.removeBombThief(player.getName());
this.removeBombThief(player);
// Bring back bomb
bomb.getVolume().resetBlocks();
@ -1961,7 +1949,7 @@ public class Warzone {
* @param suspect Player to check.
* @return true if suspect has stolen a structure.
*/
public boolean isThief(String suspect) {
public boolean isThief(Player suspect) {
return this.isFlagThief(suspect) || this.isBombThief(suspect) || this.isCakeThief(suspect);
}
}

View File

@ -49,6 +49,7 @@ public class ZoneMakerCommand extends AbstractWarCommand {
// kick
War.war.getZoneMakerNames().remove(this.args[0]);
this.msg(this.args[0] + " is not a zone maker anymore.");
// TODO store zone makers using UUIDs
Player kickedMaker = War.war.getServer().getPlayer(this.args[0]);
if (kickedMaker != null) {
War.war.msg(kickedMaker, player.getName() + " took away your warzone maker priviledges.");

View File

@ -17,6 +17,7 @@ import org.bukkit.event.block.BlockPistonExtendEvent;
import org.bukkit.event.block.BlockPistonRetractEvent;
import org.bukkit.event.block.BlockPlaceEvent;
import org.bukkit.event.world.StructureGrowEvent;
import org.bukkit.inventory.EquipmentSlot;
import org.bukkit.inventory.ItemStack;
import org.getspout.spoutapi.SpoutManager;
import org.getspout.spoutapi.player.SpoutPlayer;
@ -39,9 +40,6 @@ import com.tommytony.war.structure.Monument;
*/
public class WarBlockListener implements Listener {
/**
* @see BlockListener.onBlockPlace()
*/
@EventHandler
public void onBlockPlace(final BlockPlaceEvent event) {
if (!War.war.isLoaded()) {
@ -129,21 +127,21 @@ public class WarBlockListener implements Listener {
}
// a flag thief can't drop his flag
if (team != null && zone != null && zone.isFlagThief(player.getName())) {
if (team != null && zone != null && zone.isFlagThief(player)) {
War.war.badMsg(player, "drop.flag.disabled");
cancelAndKeepItem(event);
return;
}
// a bomb thief can't drop his bomb
if (team != null && zone != null && zone.isBombThief(player.getName())) {
if (team != null && zone != null && zone.isBombThief(player)) {
War.war.badMsg(player, "drop.bomb.disabled");
cancelAndKeepItem(event);
return;
}
// a cake thief can't drop his cake
if (team != null && zone != null && zone.isCakeThief(player.getName())) {
if (team != null && zone != null && zone.isCakeThief(player)) {
War.war.badMsg(player, "drop.cake.disabled");
cancelAndKeepItem(event);
return;
@ -169,7 +167,7 @@ public class WarBlockListener implements Listener {
private void cancelAndKeepItem(BlockPlaceEvent event) {
event.setCancelled(true);
ItemStack inHand = event.getItemInHand();
ItemStack newItemInHand = null;
ItemStack newItemInHand;
if (inHand.getType() == Material.FIRE) {
// Weird bukkit/mc behavior where item in hand is reported as fire while using flint & steel.
@ -178,24 +176,27 @@ public class WarBlockListener implements Listener {
} else {
newItemInHand = inHand.clone();
}
event.getPlayer().setItemInHand(newItemInHand);
if (event.getHand() == EquipmentSlot.OFF_HAND) {
event.getPlayer().getInventory().setItemInOffHand(newItemInHand);
} else {
event.getPlayer().getInventory().setItemInMainHand(newItemInHand);
}
}
@EventHandler
// Do not allow moving of block into or from important zones
public void onBlockPistonExtend(final BlockPistonExtendEvent event) {
Warzone zone = Warzone.getZoneByLocation(event.getBlock().getLocation());
if (zone!=null) {
if (zone != null) {
for (Block b : event.getBlocks()) {
if (zone.isImportantBlock(b)) {
event.setCancelled(true);
return;
}
}
//noinspection deprecation
if (zone.isImportantBlock(event.getBlock().getRelative(event.getDirection(), event.getLength()+1))) {
event.setCancelled(true);
return;
}
}
}
@ -212,9 +213,6 @@ public class WarBlockListener implements Listener {
}
}
/**
* @see BlockListener.onBlockBreak()
*/
@EventHandler
public void onBlockBreak(final BlockBreakEvent event) {
if (!War.war.isLoaded()) {
@ -287,9 +285,9 @@ public class WarBlockListener implements Listener {
return;
}
// changes in parts of important areas
if (warzone != null && warzone.isImportantBlock(block) && (!isZoneMaker || (isZoneMaker && team != null))) {
if (warzone != null && warzone.isImportantBlock(block) && (!isZoneMaker || team != null)) {
// breakage of spawn
if (team != null && team.isSpawnLocation(block.getLocation())) {
if (team.isSpawnLocation(block.getLocation())) {
// let team members loot one block the spawn for monument captures
if (player.getInventory().containsAtLeast(team.getKind().getBlockHead(), 1)) {
War.war.badMsg(player, "build.denied.zone.multteam", team.getName());
@ -301,11 +299,11 @@ public class WarBlockListener implements Listener {
}
}
// stealing of flag
if (team != null && warzone.isEnemyTeamFlagBlock(team, block)) {
if (warzone.isFlagThief(player.getName())) {
if (warzone.isEnemyTeamFlagBlock(team, block)) {
if (warzone.isFlagThief(player)) {
// detect audacious thieves
War.war.badMsg(player, "zone.stealextra.flag");
} else if (warzone.isBombThief(player.getName()) || warzone.isCakeThief(player.getName())) {
} else if (warzone.isBombThief(player) || warzone.isCakeThief(player)) {
War.war.badMsg(player, "zone.stealextra.other");
} else {
Team lostFlagTeam = warzone.getTeamForFlagBlock(block);
@ -314,7 +312,7 @@ public class WarBlockListener implements Listener {
ItemStack teamKindBlock = lostFlagTeam.getKind().getBlockHead();
player.getInventory().clear();
player.getInventory().addItem(teamKindBlock);
warzone.addFlagThief(lostFlagTeam, player.getName());
warzone.addFlagThief(lostFlagTeam, player);
block.setType(Material.AIR);
for (Team t : warzone.getTeams()) {
t.teamcast("zone.steal.flag.broadcast", team.getKind().getColor() + player.getName() + ChatColor.WHITE, lostFlagTeam.getName());
@ -342,11 +340,11 @@ public class WarBlockListener implements Listener {
}
event.setCancelled(true);
return;
} else if (team != null && warzone.isBombBlock(block)) {
if (warzone.isBombThief(player.getName())) {
} else if (warzone.isBombBlock(block)) {
if (warzone.isBombThief(player)) {
// detect audacious thieves
War.war.badMsg(player, "zone.stealextra.bomb");
} else if (warzone.isFlagThief(player.getName()) || warzone.isCakeThief(player.getName())) {
} else if (warzone.isFlagThief(player) || warzone.isCakeThief(player)) {
War.war.badMsg(player, "zone.stealextra.other");
} else {
Bomb bomb = warzone.getBombForBlock(block);
@ -355,7 +353,7 @@ public class WarBlockListener implements Listener {
tntBlock.setDurability((short)8);
player.getInventory().clear();
player.getInventory().addItem(tntBlock);
warzone.addBombThief(bomb, player.getName());
warzone.addBombThief(bomb, player);
block.setType(Material.AIR);
for (Team t : warzone.getTeams()) {
t.teamcast("zone.steal.bomb.broadcast", team.getKind().getColor() + player.getName() + ChatColor.WHITE, ChatColor.GREEN + bomb.getName() + ChatColor.WHITE);
@ -378,11 +376,11 @@ public class WarBlockListener implements Listener {
}
event.setCancelled(true);
return;
} else if (team != null && warzone.isCakeBlock(block)) {
if (warzone.isCakeThief(player.getName())) {
} else if (warzone.isCakeBlock(block)) {
if (warzone.isCakeThief(player)) {
// detect audacious thieves
War.war.badMsg(player, "zone.stealextra.cake");
} else if (warzone.isFlagThief(player.getName()) || warzone.isBombThief(player.getName())) {
} else if (warzone.isFlagThief(player) || warzone.isBombThief(player)) {
War.war.badMsg(player, "zone.stealextra.other");
} else {
Cake cake = warzone.getCakeForBlock(block);
@ -391,7 +389,7 @@ public class WarBlockListener implements Listener {
cakeBlock.setDurability((short)8);
player.getInventory().clear();
player.getInventory().addItem(cakeBlock);
warzone.addCakeThief(cake, player.getName());
warzone.addCakeThief(cake, player);
block.setType(Material.AIR);
for (Team t : warzone.getTeams()) {
t.teamcast("zone.steal.cake.broadcast", team.getKind().getColor() + player.getName() + ChatColor.WHITE, ChatColor.GREEN + cake.getName() + ChatColor.WHITE);

View File

@ -130,9 +130,9 @@ public class WarEntityListener implements Listener {
} else {
defenderWarzone.handleKill(a, d, event.getDamager());
}
} else if (defenderWarzone.isBombThief(d.getName()) && d.getLocation().distance(a.getLocation()) < 2) {
} else if (defenderWarzone.isBombThief(d) && d.getLocation().distance(a.getLocation()) < 2) {
// Close combat, close enough to detonate
Bomb bomb = defenderWarzone.getBombForThief(d.getName());
Bomb bomb = defenderWarzone.getBombForThief(d);
// Kill the bomber
WarPlayerDeathEvent event1 = new WarPlayerDeathEvent(defenderWarzone, d, null, event.getCause());

View File

@ -113,15 +113,15 @@ public class WarPlayerListener implements Listener {
if (team != null) {
Warzone zone = Warzone.getZoneByPlayerName(player.getName());
if (zone.isFlagThief(player.getName())) {
if (zone.isFlagThief(player)) {
// a flag thief can't drop his flag
War.war.badMsg(player, "drop.flag.disabled");
event.setCancelled(true);
} else if (zone.isBombThief(player.getName())) {
} else if (zone.isBombThief(player)) {
// a bomb thief can't drop his bomb
War.war.badMsg(player, "drop.bomb.disabled");
event.setCancelled(true);
} else if (zone.isCakeThief(player.getName())) {
} else if (zone.isCakeThief(player)) {
// a cake thief can't drop his cake
War.war.badMsg(player, "drop.cake.disabled");
event.setCancelled(true);
@ -176,7 +176,7 @@ public class WarPlayerListener implements Listener {
if (team != null) {
Warzone zone = Warzone.getZoneByPlayerName(player.getName());
if (zone.isFlagThief(player.getName())) {
if (zone.isFlagThief(player)) {
// a flag thief can't pick up anything
event.setCancelled(true);
} else {
@ -237,7 +237,7 @@ public class WarPlayerListener implements Listener {
public void onPlayerInteract(PlayerInteractEvent event) {
if (War.war.isLoaded()) {
Player player = event.getPlayer();
if (player.getItemInHand().getType() == Material.WOOD_SWORD && War.war.isWandBearer(player)) {
if (event.getItem().getType() == Material.WOOD_SWORD && War.war.isWandBearer(player)) {
String zoneName = War.war.getWandBearerZone(player);
ZoneSetter setter = new ZoneSetter(player, zoneName);
if (event.getAction() == Action.LEFT_CLICK_AIR || event.getAction() == Action.RIGHT_CLICK_AIR) {
@ -284,7 +284,7 @@ public class WarPlayerListener implements Listener {
}
if (zone != null && team != null && event.getAction() == Action.RIGHT_CLICK_BLOCK
&& event.getClickedBlock().getState() instanceof InventoryHolder
&& zone.isFlagThief(player.getName())) {
&& zone.isFlagThief(player)) {
event.setCancelled(true);
War.war.badMsg(player, "drop.flag.disabled");
}
@ -544,9 +544,9 @@ public class WarPlayerListener implements Listener {
return;
}
} else if (loadoutSelectionState != null && !loadoutSelectionState.isStillInSpawn()
&& !playerWarzone.isCakeThief(player.getName())
&& !playerWarzone.isCakeThief(player)
&& (flagReturn.equals(FlagReturn.BOTH) || flagReturn.equals(FlagReturn.SPAWN))
&& !playerWarzone.isFlagThief(player.getName())) {
&& !playerWarzone.isFlagThief(player)) {
// player is in spawn, but has left already: he should NOT be let back in - kick him out gently
// if he sticks around too long.
@ -571,7 +571,7 @@ public class WarPlayerListener implements Listener {
}
// Flag capture
if (playerWarzone.isFlagThief(player.getName())) {
if (playerWarzone.isFlagThief(player)) {
// smoky
if (System.currentTimeMillis() % 13 == 0) {
@ -619,7 +619,7 @@ public class WarPlayerListener implements Listener {
} else {
// All good - proceed with scoring
playerTeam.addPoint();
Team victim = playerWarzone.getVictimTeamForFlagThief(player.getName());
Team victim = playerWarzone.getVictimTeamForFlagThief(player);
// Notify everyone
for (Team t : playerWarzone.getTeams()) {
@ -658,14 +658,14 @@ public class WarPlayerListener implements Listener {
}
}
playerWarzone.removeFlagThief(player.getName());
playerWarzone.removeFlagThief(player);
return;
}
}
// Bomb detonation
if (playerWarzone.isBombThief(player.getName())) {
if (playerWarzone.isBombThief(player)) {
// smoky
playerWarzone.getWorld().playEffect(player.getLocation(), Effect.SMOKE, 0);
@ -686,7 +686,7 @@ public class WarPlayerListener implements Listener {
if (inEnemySpawn && playerTeam.getPlayers().contains(player)) {
// Made sure player is still part of team, game may have ended while waiting.
// Ignored the scorers that happened immediately after the game end.
Bomb bomb = playerWarzone.getBombForThief(player.getName());
Bomb bomb = playerWarzone.getBombForThief(player);
// Boom!
if (!playerWarzone.getWarzoneConfig().getBoolean(WarzoneConfig.UNBREAKABLE)) {
@ -746,14 +746,14 @@ public class WarPlayerListener implements Listener {
}
}
playerWarzone.removeBombThief(player.getName());
playerWarzone.removeBombThief(player);
return;
}
}
// Cake retrieval
if (playerWarzone.isCakeThief(player.getName())) {
if (playerWarzone.isCakeThief(player)) {
// smoky
if (System.currentTimeMillis() % 13 == 0) {
playerWarzone.getWorld().playEffect(player.getLocation(), Effect.POTION_BREAK, playerTeam.getKind().getPotionEffectColor());
@ -775,7 +775,7 @@ public class WarPlayerListener implements Listener {
// Don't let someone alone make points off cakes
if (hasOpponent) {
Cake cake = playerWarzone.getCakeForThief(player.getName());
Cake cake = playerWarzone.getCakeForThief(player);
if (playerWarzone.isReinitializing()) {
// Battle already ended or interrupted
@ -825,7 +825,7 @@ public class WarPlayerListener implements Listener {
}
}
playerWarzone.removeCakeThief(player.getName());
playerWarzone.removeCakeThief(player);
}
return;
@ -950,15 +950,17 @@ public class WarPlayerListener implements Listener {
if (zone == null) {
return;
}
// Prevent thieves from taking their bomb/wool/cake into a chest, etc.
if (zone.isThief(player.getName())) {
if (zone.isThief(player)) {
// Prevent thieves from taking their bomb/wool/cake into a chest, etc.
event.setCancelled(true);
player.playSound(player.getLocation(), Sound.BLOCK_LAVA_EXTINGUISH, 10, 10);
} else // Magically give player a wool block when they click their helmet
if (event.getSlotType() == InventoryType.SlotType.ARMOR && event.getSlot() == 39
} else if (event.getSlotType() == InventoryType.SlotType.ARMOR && event.getSlot() == 39
&& zone.getWarzoneConfig().getBoolean(WarzoneConfig.BLOCKHEADS)) {
// Magically give player a wool block when they click their helmet
ItemStack teamBlock = zone.getPlayerTeam(player.getName()).getKind().getBlockHead();
player.getInventory().remove(teamBlock.getType());
// Deprecated behavior cannot be removed as it is essential to this function
//noinspection deprecation
event.setCursor(teamBlock);
event.setCancelled(true);
}

View File

@ -20,9 +20,6 @@ import com.tommytony.war.config.WarzoneConfig;
*/
public class HelmetProtectionTask implements Runnable {
/**
* @see Runnable.run()
*/
public void run() {
if (!War.war.isLoaded()) {
return;
@ -66,15 +63,21 @@ public class HelmetProtectionTask implements Runnable {
}
// check for thieves without their treasure in their hands
if (zone.isFlagThief(player.getName())) {
Team victim = zone.getVictimTeamForFlagThief(player.getName());
player.setItemInHand(null);
if (zone.isFlagThief(player)) {
Team victim = zone.getVictimTeamForFlagThief(player);
player.getInventory().setItemInMainHand(null);
player.getInventory().setItemInOffHand(null);
player.getInventory().setHeldItemSlot(0);
player.getInventory().addItem(victim.getKind().getBlockData().toItemStack(2240));
} else if (zone.isBombThief(player.getName())) {
player.setItemInHand(null);
} else if (zone.isBombThief(player)) {
player.getInventory().setItemInMainHand(null);
player.getInventory().setItemInOffHand(null);
player.getInventory().setHeldItemSlot(0);
player.getInventory().addItem(new ItemStack(Material.TNT, 2240));
} else if (zone.isCakeThief(player.getName())) {
player.setItemInHand(null);
} else if (zone.isCakeThief(player)) {
player.getInventory().setItemInMainHand(null);
player.getInventory().setItemInOffHand(null);
player.getInventory().setHeldItemSlot(0);
player.getInventory().addItem(new ItemStack(Material.CAKE_BLOCK, 2240));
}
}

View File

@ -98,14 +98,14 @@ public class PartialZoneResetJob extends BukkitRunnable implements Cloneable {
new Object[]{volume.getName(), secondsAsText});
conn.close();
} else {
War.war.getServer().getScheduler().runTaskLater(War.war, this.clone(), JOB_INTERVAL);
this.runTaskLater(War.war, JOB_INTERVAL);
}
} else {
int solidChanges = volume.resetSection(conn, completed, speed, changes);
completed += solidChanges;
totalChanges += solidChanges;
this.displayStatusMessage();
War.war.getServer().getScheduler().runTaskLater(War.war, this.clone(), JOB_INTERVAL);
this.runTaskLater(War.war, JOB_INTERVAL);
}
} catch (SQLException e) {
War.war.getLogger().log(Level.WARNING, "Failed to load zone during reset loop", e);

View File

@ -214,7 +214,7 @@ public class VolumeMapper {
dataStmt.setInt(2, relLoc.getBlockY());
dataStmt.setInt(3, relLoc.getBlockZ());
dataStmt.setString(4, block.getType().toString());
dataStmt.setShort(5, block.getData().toItemStack().getDurability());
dataStmt.setShort(5, block.getData().toItemStack(1).getDurability());
dataStmt.addBatch();
if (++changed % batchSize == 0) {
dataStmt.executeBatch();

View File

@ -14,12 +14,8 @@ import java.util.logging.Level;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang.Validate;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.Note;
import org.bukkit.*;
import org.bukkit.Note.Tone;
import org.bukkit.SkullType;
import org.bukkit.World;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.block.BlockState;
@ -185,7 +181,8 @@ public class ZoneVolumeMapper {
if (modify instanceof Skull) {
String[] opts = query.getString("metadata").split("\n");
if (!opts[0].isEmpty()) {
((Skull) modify).setOwner(opts[0]);
// TODO upgrade to store owning players by UUID
((Skull) modify).setOwningPlayer(Bukkit.getOfflinePlayer(opts[0]));
}
((Skull) modify).setSkullType(SkullType.valueOf(opts[1]));
((Skull) modify).setRotation(BlockFace.valueOf(opts[2]));
@ -248,7 +245,7 @@ public class ZoneVolumeMapper {
dataStmt.setInt(2, relLoc.getBlockY());
dataStmt.setInt(3, relLoc.getBlockZ());
dataStmt.setString(4, block.getType().toString());
dataStmt.setShort(5, block.getData().toItemStack().getDurability());
dataStmt.setShort(5, block.getData().toItemStack(1).getDurability());
dataStmt.addBatch();
if (++changed % batchSize == 0) {
dataStmt.executeBatch();
@ -356,7 +353,7 @@ public class ZoneVolumeMapper {
dataStmt.setInt(2, block.getY() - volume.getCornerOne().getBlockY());
dataStmt.setInt(3, block.getZ() - volume.getCornerOne().getBlockZ());
dataStmt.setString(4, block.getType().name());
dataStmt.setShort(5, state.getData().toItemStack().getDurability());
dataStmt.setShort(5, state.getData().toItemStack(1).getDurability());
if (state instanceof Sign) {
final String signText = StringUtils.join(((Sign) block.getState()).getLines(), "\n");
dataStmt.setString(6, signText);
@ -372,8 +369,9 @@ public class ZoneVolumeMapper {
} else if (state instanceof Jukebox) {
dataStmt.setString(6, ((Jukebox) block.getState()).getPlaying().toString());
} else if (state instanceof Skull) {
// TODO upgrade to store owning player by UUID
dataStmt.setString(6, String.format("%s\n%s\n%s",
((Skull) block.getState()).hasOwner() ? ((Skull) block.getState()).getOwner() : "",
((Skull) block.getState()).hasOwner() ? ((Skull) block.getState()).getOwningPlayer().getName() : "",
((Skull) block.getState()).getSkullType().toString(),
((Skull) block.getState()).getRotation().toString()));
} else if (state instanceof CommandBlock) {

View File

@ -70,15 +70,7 @@ public class SpoutDisplayer {
}
}
}
public void remove(String playerName) {
Player player = War.war.getServer().getPlayer(playerName);
if (player != null && playerMessages.containsKey(playerName)) {
clear(SpoutManager.getPlayer(player));
playerMessages.remove(playerName);
}
}
private void clear(SpoutPlayer player) {
player.getMainScreen().removeWidgets(War.war);
}

View File

@ -102,7 +102,7 @@ public class ZoneVolume extends Volume {
public void resetBlocksAsJob() {
try {
PartialZoneResetJob job = new PartialZoneResetJob(zone, War.war.getWarConfig().getInt(WarConfig.RESETSPEED));
War.war.getServer().getScheduler().runTask(War.war, job);
job.runTask(War.war);
} catch (SQLException e) {
War.war.getLogger().log(Level.WARNING, "Failed to reset warzone - cannot get count of saved blocks", e);
}