diff --git a/war/src/main/java/com/tommytony/war/Team.java b/war/src/main/java/com/tommytony/war/Team.java index a8cbaea..ab64189 100644 --- a/war/src/main/java/com/tommytony/war/Team.java +++ b/war/src/main/java/com/tommytony/war/Team.java @@ -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; + } } diff --git a/war/src/main/java/com/tommytony/war/War.java b/war/src/main/java/com/tommytony/war/War.java index c3e26bd..cf539aa 100644 --- a/war/src/main/java/com/tommytony/war/War.java +++ b/war/src/main/java/com/tommytony/war/War.java @@ -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 defaultLoadout = new HashMap(); diff --git a/war/src/main/java/com/tommytony/war/Warzone.java b/war/src/main/java/com/tommytony/war/Warzone.java index e7a2376..5b371c2 100644 --- a/war/src/main/java/com/tommytony/war/Warzone.java +++ b/war/src/main/java/com/tommytony/war/Warzone.java @@ -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 scoreCapTeams = new ArrayList(); for (Team t : teams) { diff --git a/war/src/main/java/com/tommytony/war/config/TeamConfig.java b/war/src/main/java/com/tommytony/war/config/TeamConfig.java index bb25ba0..222c0d5 100644 --- a/war/src/main/java/com/tommytony/war/config/TeamConfig.java +++ b/war/src/main/java/com/tommytony/war/config/TeamConfig.java @@ -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; diff --git a/war/src/main/java/com/tommytony/war/config/TeamKind.java b/war/src/main/java/com/tommytony/war/config/TeamKind.java index 2e44c02..c823dec 100644 --- a/war/src/main/java/com/tommytony/war/config/TeamKind.java +++ b/war/src/main/java/com/tommytony/war/config/TeamKind.java @@ -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()); } /** diff --git a/war/src/main/java/com/tommytony/war/event/WarBlockListener.java b/war/src/main/java/com/tommytony/war/event/WarBlockListener.java index bb5f6b3..eec5b07 100644 --- a/war/src/main/java/com/tommytony/war/event/WarBlockListener.java +++ b/war/src/main/java/com/tommytony/war/event/WarBlockListener.java @@ -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; + } } } diff --git a/war/src/main/java/com/tommytony/war/job/ScoreCapReachedJob.java b/war/src/main/java/com/tommytony/war/job/ScoreCapReachedJob.java index 53e5f11..5af1371 100644 --- a/war/src/main/java/com/tommytony/war/job/ScoreCapReachedJob.java +++ b/war/src/main/java/com/tommytony/war/job/ScoreCapReachedJob.java @@ -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(); } } diff --git a/war/src/main/java/com/tommytony/war/utility/PlayerState.java b/war/src/main/java/com/tommytony/war/utility/PlayerState.java index e500dc5..7ff2820 100644 --- a/war/src/main/java/com/tommytony/war/utility/PlayerState.java +++ b/war/src/main/java/com/tommytony/war/utility/PlayerState.java @@ -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 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 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; + } + } diff --git a/war/src/main/resources/messages.properties b/war/src/main/resources/messages.properties index 79159a0..1ab7c65 100644 --- a/war/src/main/resources/messages.properties +++ b/war/src/main/resources/messages.properties @@ -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.