Fix some issues uncovered in review, add block features.

This fixes some issues found during @taoneill's review of the code. It
also adds a few features with blocks, such as a modify block whitelist.
KDR updates are now stored at the end of each battle in a warzone.
Closes #681, closes #672, closes #682, closes #683, closes #689, ping
#688.
This commit is contained in:
cmastudios 2013-10-16 18:55:07 -05:00
parent 6e9efc7a8a
commit 7621bdd321
9 changed files with 79 additions and 31 deletions

View File

@ -549,7 +549,8 @@ public class Team {
public void resetPoints() {
this.points = 0;
if (this.warzone.getScoreboardType() == ScoreboardType.POINTS) {
if (this.warzone.getScoreboardType() == ScoreboardType.POINTS
&& this.warzone.getScoreboard() != null) {
String teamName = kind.getColor() + name + ChatColor.RESET;
this.warzone.getScoreboard().getObjective(DisplaySlot.SIDEBAR)
.getScore(Bukkit.getOfflinePlayer(teamName)).setScore(points);
@ -767,4 +768,23 @@ public class Team {
}
return ret;
}
/**
* Check if a player on this team can modify a certain type of block defined in the block whitelist.
*
* @param type Type of block to check.
* @return true if this block can be modified, false otherwise.
*/
public boolean canModify(Material type) {
for (String whitelistedBlock : this.getTeamConfig()
.resolveString(TeamConfig.BLOCKWHITELIST).split(",")) {
if (whitelistedBlock.equalsIgnoreCase("all")) {
return true;
}
if (type.toString().equalsIgnoreCase(whitelistedBlock)) {
return true;
}
}
return false;
}
}

View File

@ -216,6 +216,8 @@ public class War extends JavaPlugin {
teamDefaultConfig.put(TeamConfig.PERMISSION, "war.player");
teamDefaultConfig.put(TeamConfig.XPKILLMETER, false);
teamDefaultConfig.put(TeamConfig.KILLSTREAK, false);
teamDefaultConfig.put(TeamConfig.BLOCKWHITELIST, "all");
teamDefaultConfig.put(TeamConfig.PLACEBLOCK, true);
this.getDefaultInventories().clearLoadouts();
HashMap<Integer, ItemStack> defaultLoadout = new HashMap<Integer, ItemStack>();

View File

@ -31,6 +31,7 @@ import org.bukkit.scoreboard.Scoreboard;
import org.getspout.spoutapi.SpoutManager;
import org.getspout.spoutapi.player.SpoutPlayer;
import com.google.common.collect.ImmutableList;
import com.tommytony.war.config.InventoryBag;
import com.tommytony.war.config.ScoreboardType;
import com.tommytony.war.config.TeamConfig;
@ -424,12 +425,14 @@ public class Warzone {
player.getOpenInventory().close();
player.setLevel(0);
player.setExp(0);
player.setAllowFlight(false);
player.setFlying(false);
player.getInventory().clear();
this.setKillCount(player.getName(), 0);
if (player.getGameMode() == GameMode.CREATIVE) {
if (player.getGameMode() != GameMode.SURVIVAL) {
// Players are always in survival mode in warzones
player.setGameMode(GameMode.SURVIVAL);
}
@ -561,20 +564,15 @@ public class Warzone {
playerTitle = SpoutManager.getPlayer(player).getTitle();
}
this.playerStates.put(player.getName(), new PlayerState(player.getGameMode(),
contents,
inventory.getHelmet(),
inventory.getChestplate(),
inventory.getLeggings(),
inventory.getBoots(),
player.getHealth(),
player.getExhaustion(),
player.getSaturation(),
player.getFoodLevel(),
player.getActivePotionEffects(),
playerTitle,
player.getLevel(),
player.getExp()));
this.playerStates.put(
player.getName(),
new PlayerState(player.getGameMode(), contents, inventory
.getHelmet(), inventory.getChestplate(), inventory
.getLeggings(), inventory.getBoots(), player
.getHealth(), player.getExhaustion(), player
.getSaturation(), player.getFoodLevel(), player
.getActivePotionEffects(), playerTitle, player
.getLevel(), player.getExp(), player.getAllowFlight()));
}
public void restorePlayerState(Player player) {
@ -591,6 +589,7 @@ public class Warzone {
PotionEffectHelper.restorePotionEffects(player, originalState.getPotionEffects());
player.setLevel(originalState.getLevel());
player.setExp(originalState.getExp());
player.setAllowFlight(originalState.canFly());
if (War.war.isSpoutServer()) {
SpoutManager.getPlayer(player).setTitle(originalState.getPlayerTitle());
@ -986,6 +985,11 @@ public class Warzone {
if (!scores.equals("")) {
this.broadcast("zone.battle.newscores", scores);
}
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);
}
this.getKillsDeathsTracker().clear();
// detect score cap
List<Team> scoreCapTeams = new ArrayList<Team>();
for (Team t : teams) {

View File

@ -15,7 +15,9 @@ public enum TeamConfig {
TEAMSIZE (Integer.class),
PERMISSION (String.class),
XPKILLMETER (Boolean.class),
KILLSTREAK (Boolean.class);
KILLSTREAK (Boolean.class),
BLOCKWHITELIST (String.class),
PLACEBLOCK (Boolean.class);
private final Class<?> configType;

View File

@ -85,7 +85,7 @@ public enum TeamKind {
public Color getSpoutColor() {
return new org.getspout.spoutapi.gui.Color(
dyeColor.getColor().getRed(), dyeColor.getColor().getGreen(),
dyeColor.getColor().getRed());
dyeColor.getColor().getBlue());
}
/**

View File

@ -20,6 +20,7 @@ import org.getspout.spoutapi.player.SpoutPlayer;
import com.tommytony.war.Team;
import com.tommytony.war.War;
import com.tommytony.war.Warzone;
import com.tommytony.war.config.TeamConfig;
import com.tommytony.war.config.WarConfig;
import com.tommytony.war.config.WarzoneConfig;
import com.tommytony.war.spout.SpoutDisplayer;
@ -145,12 +146,20 @@ public class WarBlockListener implements Listener {
}
// unbreakableZoneBlocks
if (zone != null && zone.getWarzoneConfig().getBoolean(WarzoneConfig.UNBREAKABLE) && (!isZoneMaker || (isZoneMaker && team != null))) {
if (zone != null && zone.getWarzoneConfig().getBoolean(WarzoneConfig.UNBREAKABLE)
|| (team != null && !team.getTeamConfig().resolveBoolean(TeamConfig.PLACEBLOCK))
&& (!isZoneMaker || (isZoneMaker && team != null))) {
// if the zone is unbreakable, no one but zone makers can break blocks (even then, zone makers in a team can't break blocks)
War.war.badMsg(player, "build.denied.zone.place");
cancelAndKeepItem(event);
return;
}
if (team != null && !team.canModify(block.getType())) {
War.war.badMsg(player, "build.denied.zone.type");
cancelAndKeepItem(event);
return;
}
}
private void cancelAndKeepItem(BlockPlaceEvent event) {
@ -224,7 +233,7 @@ public class WarBlockListener implements Listener {
Warzone playerZone = Warzone.getZoneByLocation(player);
if (player != null && block != null && playerZone != null && playerZone.getWarzoneConfig().getBoolean(WarzoneConfig.INSTABREAK)) {
Warzone blockZone = Warzone.getZoneByLocation(new Location(block.getWorld(), block.getX(), block.getY(), block.getZ()));
if (blockZone != null && blockZone == playerZone) {
if (blockZone != null && blockZone == playerZone && block.getType() != Material.BEDROCK) {
event.setInstaBreak(true);
}
}
@ -435,5 +444,11 @@ public class WarBlockListener implements Listener {
event.setCancelled(true);
return;
}
if (team != null && !team.canModify(block.getType())) {
War.war.badMsg(player, "build.denied.zone.type");
event.setCancelled(true);
return;
}
}
}

View File

@ -1,20 +1,19 @@
package com.tommytony.war.job;
import com.google.common.collect.ImmutableList;
import java.util.Iterator;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.getspout.spoutapi.SpoutManager;
import org.getspout.spoutapi.player.SpoutPlayer;
import org.kitteh.tag.TagAPI;
import com.tommytony.war.Team;
import com.tommytony.war.War;
import com.tommytony.war.Warzone;
import com.tommytony.war.spout.SpoutDisplayer;
import java.util.Iterator;
import org.kitteh.tag.TagAPI;
public class ScoreCapReachedJob implements Runnable {
@ -64,10 +63,5 @@ public class ScoreCapReachedJob implements Runnable {
t.resetPoints();
t.getPlayers().clear(); // empty the team
}
if (War.war.getMysqlConfig().isEnabled() && War.war.getMysqlConfig().isLoggingEnabled()) {
LogKillsDeathsJob logKillsDeathsJob = new LogKillsDeathsJob(ImmutableList.copyOf(zone.getKillsDeathsTracker()));
War.war.getServer().getScheduler().runTaskAsynchronously(War.war, logKillsDeathsJob);
}
zone.getKillsDeathsTracker().clear();
}
}

View File

@ -22,8 +22,13 @@ public class PlayerState {
private final String playerTitle;
private final float exp;
private final int level;
private final boolean fly;
public PlayerState(GameMode gamemode, ItemStack[] contents, ItemStack helmet, ItemStack chest, ItemStack legs, ItemStack feet, double health, float exhaustion, float saturation, int foodLevel, Collection<PotionEffect> potionEffects, String playerTitle, int level, float exp) {
public PlayerState(GameMode gamemode, ItemStack[] contents,
ItemStack helmet, ItemStack chest, ItemStack legs, ItemStack feet,
double health, float exhaustion, float saturation, int foodLevel,
Collection<PotionEffect> potionEffects, String playerTitle,
int level, float exp, boolean fly) {
this.gamemode = gamemode;
this.health = health;
this.exhaustion = exhaustion;
@ -33,6 +38,7 @@ public class PlayerState {
this.playerTitle = playerTitle;
this.level = level;
this.exp = exp;
this.fly = fly;
this.setContents(contents);
this.setHelmet(helmet);
this.setChest(chest);
@ -116,4 +122,8 @@ public class PlayerState {
return level;
}
public boolean canFly() {
return fly;
}
}

View File

@ -6,7 +6,8 @@ build.denied.teamblock = You can only use your team's blocks to capture monu
build.denied.zone.break = The blocks in this warzone are unbreakable!
build.denied.zone.multteam = You already have a {0} block.
build.denied.zone.outside = You can't destroy a warzone you are not playing in.
build.denied.zone.place = The blocks in this warzone are unbreakable - this also means you can't build!
build.denied.zone.place = You cannot place blocks in this warzone.
build.denied.zone.type = You cannot modify this type of block.
command.console = You can't do this if you are not in game.
command.disabled = You can only use War commands (e.g. /leave) while playing.