mirror of
https://github.com/taoneill/war.git
synced 2025-02-02 20:51:20 +01:00
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:
parent
6e9efc7a8a
commit
7621bdd321
@ -549,7 +549,8 @@ public class Team {
|
|||||||
|
|
||||||
public void resetPoints() {
|
public void resetPoints() {
|
||||||
this.points = 0;
|
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;
|
String teamName = kind.getColor() + name + ChatColor.RESET;
|
||||||
this.warzone.getScoreboard().getObjective(DisplaySlot.SIDEBAR)
|
this.warzone.getScoreboard().getObjective(DisplaySlot.SIDEBAR)
|
||||||
.getScore(Bukkit.getOfflinePlayer(teamName)).setScore(points);
|
.getScore(Bukkit.getOfflinePlayer(teamName)).setScore(points);
|
||||||
@ -767,4 +768,23 @@ public class Team {
|
|||||||
}
|
}
|
||||||
return ret;
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -216,6 +216,8 @@ public class War extends JavaPlugin {
|
|||||||
teamDefaultConfig.put(TeamConfig.PERMISSION, "war.player");
|
teamDefaultConfig.put(TeamConfig.PERMISSION, "war.player");
|
||||||
teamDefaultConfig.put(TeamConfig.XPKILLMETER, false);
|
teamDefaultConfig.put(TeamConfig.XPKILLMETER, false);
|
||||||
teamDefaultConfig.put(TeamConfig.KILLSTREAK, false);
|
teamDefaultConfig.put(TeamConfig.KILLSTREAK, false);
|
||||||
|
teamDefaultConfig.put(TeamConfig.BLOCKWHITELIST, "all");
|
||||||
|
teamDefaultConfig.put(TeamConfig.PLACEBLOCK, true);
|
||||||
|
|
||||||
this.getDefaultInventories().clearLoadouts();
|
this.getDefaultInventories().clearLoadouts();
|
||||||
HashMap<Integer, ItemStack> defaultLoadout = new HashMap<Integer, ItemStack>();
|
HashMap<Integer, ItemStack> defaultLoadout = new HashMap<Integer, ItemStack>();
|
||||||
|
@ -31,6 +31,7 @@ import org.bukkit.scoreboard.Scoreboard;
|
|||||||
import org.getspout.spoutapi.SpoutManager;
|
import org.getspout.spoutapi.SpoutManager;
|
||||||
import org.getspout.spoutapi.player.SpoutPlayer;
|
import org.getspout.spoutapi.player.SpoutPlayer;
|
||||||
|
|
||||||
|
import com.google.common.collect.ImmutableList;
|
||||||
import com.tommytony.war.config.InventoryBag;
|
import com.tommytony.war.config.InventoryBag;
|
||||||
import com.tommytony.war.config.ScoreboardType;
|
import com.tommytony.war.config.ScoreboardType;
|
||||||
import com.tommytony.war.config.TeamConfig;
|
import com.tommytony.war.config.TeamConfig;
|
||||||
@ -424,12 +425,14 @@ public class Warzone {
|
|||||||
player.getOpenInventory().close();
|
player.getOpenInventory().close();
|
||||||
player.setLevel(0);
|
player.setLevel(0);
|
||||||
player.setExp(0);
|
player.setExp(0);
|
||||||
|
player.setAllowFlight(false);
|
||||||
|
player.setFlying(false);
|
||||||
|
|
||||||
player.getInventory().clear();
|
player.getInventory().clear();
|
||||||
|
|
||||||
this.setKillCount(player.getName(), 0);
|
this.setKillCount(player.getName(), 0);
|
||||||
|
|
||||||
if (player.getGameMode() == GameMode.CREATIVE) {
|
if (player.getGameMode() != GameMode.SURVIVAL) {
|
||||||
// Players are always in survival mode in warzones
|
// Players are always in survival mode in warzones
|
||||||
player.setGameMode(GameMode.SURVIVAL);
|
player.setGameMode(GameMode.SURVIVAL);
|
||||||
}
|
}
|
||||||
@ -561,20 +564,15 @@ public class Warzone {
|
|||||||
playerTitle = SpoutManager.getPlayer(player).getTitle();
|
playerTitle = SpoutManager.getPlayer(player).getTitle();
|
||||||
}
|
}
|
||||||
|
|
||||||
this.playerStates.put(player.getName(), new PlayerState(player.getGameMode(),
|
this.playerStates.put(
|
||||||
contents,
|
player.getName(),
|
||||||
inventory.getHelmet(),
|
new PlayerState(player.getGameMode(), contents, inventory
|
||||||
inventory.getChestplate(),
|
.getHelmet(), inventory.getChestplate(), inventory
|
||||||
inventory.getLeggings(),
|
.getLeggings(), inventory.getBoots(), player
|
||||||
inventory.getBoots(),
|
.getHealth(), player.getExhaustion(), player
|
||||||
player.getHealth(),
|
.getSaturation(), player.getFoodLevel(), player
|
||||||
player.getExhaustion(),
|
.getActivePotionEffects(), playerTitle, player
|
||||||
player.getSaturation(),
|
.getLevel(), player.getExp(), player.getAllowFlight()));
|
||||||
player.getFoodLevel(),
|
|
||||||
player.getActivePotionEffects(),
|
|
||||||
playerTitle,
|
|
||||||
player.getLevel(),
|
|
||||||
player.getExp()));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void restorePlayerState(Player player) {
|
public void restorePlayerState(Player player) {
|
||||||
@ -591,6 +589,7 @@ public class Warzone {
|
|||||||
PotionEffectHelper.restorePotionEffects(player, originalState.getPotionEffects());
|
PotionEffectHelper.restorePotionEffects(player, originalState.getPotionEffects());
|
||||||
player.setLevel(originalState.getLevel());
|
player.setLevel(originalState.getLevel());
|
||||||
player.setExp(originalState.getExp());
|
player.setExp(originalState.getExp());
|
||||||
|
player.setAllowFlight(originalState.canFly());
|
||||||
|
|
||||||
if (War.war.isSpoutServer()) {
|
if (War.war.isSpoutServer()) {
|
||||||
SpoutManager.getPlayer(player).setTitle(originalState.getPlayerTitle());
|
SpoutManager.getPlayer(player).setTitle(originalState.getPlayerTitle());
|
||||||
@ -986,6 +985,11 @@ public class Warzone {
|
|||||||
if (!scores.equals("")) {
|
if (!scores.equals("")) {
|
||||||
this.broadcast("zone.battle.newscores", scores);
|
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
|
// detect score cap
|
||||||
List<Team> scoreCapTeams = new ArrayList<Team>();
|
List<Team> scoreCapTeams = new ArrayList<Team>();
|
||||||
for (Team t : teams) {
|
for (Team t : teams) {
|
||||||
|
@ -15,7 +15,9 @@ public enum TeamConfig {
|
|||||||
TEAMSIZE (Integer.class),
|
TEAMSIZE (Integer.class),
|
||||||
PERMISSION (String.class),
|
PERMISSION (String.class),
|
||||||
XPKILLMETER (Boolean.class),
|
XPKILLMETER (Boolean.class),
|
||||||
KILLSTREAK (Boolean.class);
|
KILLSTREAK (Boolean.class),
|
||||||
|
BLOCKWHITELIST (String.class),
|
||||||
|
PLACEBLOCK (Boolean.class);
|
||||||
|
|
||||||
private final Class<?> configType;
|
private final Class<?> configType;
|
||||||
|
|
||||||
|
@ -85,7 +85,7 @@ public enum TeamKind {
|
|||||||
public Color getSpoutColor() {
|
public Color getSpoutColor() {
|
||||||
return new org.getspout.spoutapi.gui.Color(
|
return new org.getspout.spoutapi.gui.Color(
|
||||||
dyeColor.getColor().getRed(), dyeColor.getColor().getGreen(),
|
dyeColor.getColor().getRed(), dyeColor.getColor().getGreen(),
|
||||||
dyeColor.getColor().getRed());
|
dyeColor.getColor().getBlue());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -20,6 +20,7 @@ import org.getspout.spoutapi.player.SpoutPlayer;
|
|||||||
import com.tommytony.war.Team;
|
import com.tommytony.war.Team;
|
||||||
import com.tommytony.war.War;
|
import com.tommytony.war.War;
|
||||||
import com.tommytony.war.Warzone;
|
import com.tommytony.war.Warzone;
|
||||||
|
import com.tommytony.war.config.TeamConfig;
|
||||||
import com.tommytony.war.config.WarConfig;
|
import com.tommytony.war.config.WarConfig;
|
||||||
import com.tommytony.war.config.WarzoneConfig;
|
import com.tommytony.war.config.WarzoneConfig;
|
||||||
import com.tommytony.war.spout.SpoutDisplayer;
|
import com.tommytony.war.spout.SpoutDisplayer;
|
||||||
@ -145,12 +146,20 @@ public class WarBlockListener implements Listener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// unbreakableZoneBlocks
|
// 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)
|
// 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");
|
War.war.badMsg(player, "build.denied.zone.place");
|
||||||
cancelAndKeepItem(event);
|
cancelAndKeepItem(event);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (team != null && !team.canModify(block.getType())) {
|
||||||
|
War.war.badMsg(player, "build.denied.zone.type");
|
||||||
|
cancelAndKeepItem(event);
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void cancelAndKeepItem(BlockPlaceEvent event) {
|
private void cancelAndKeepItem(BlockPlaceEvent event) {
|
||||||
@ -224,7 +233,7 @@ public class WarBlockListener implements Listener {
|
|||||||
Warzone playerZone = Warzone.getZoneByLocation(player);
|
Warzone playerZone = Warzone.getZoneByLocation(player);
|
||||||
if (player != null && block != null && playerZone != null && playerZone.getWarzoneConfig().getBoolean(WarzoneConfig.INSTABREAK)) {
|
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()));
|
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);
|
event.setInstaBreak(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -435,5 +444,11 @@ public class WarBlockListener implements Listener {
|
|||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (team != null && !team.canModify(block.getType())) {
|
||||||
|
War.war.badMsg(player, "build.denied.zone.type");
|
||||||
|
event.setCancelled(true);
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,20 +1,19 @@
|
|||||||
package com.tommytony.war.job;
|
package com.tommytony.war.job;
|
||||||
|
|
||||||
import com.google.common.collect.ImmutableList;
|
import java.util.Iterator;
|
||||||
|
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
import org.getspout.spoutapi.SpoutManager;
|
import org.getspout.spoutapi.SpoutManager;
|
||||||
import org.getspout.spoutapi.player.SpoutPlayer;
|
import org.getspout.spoutapi.player.SpoutPlayer;
|
||||||
|
import org.kitteh.tag.TagAPI;
|
||||||
|
|
||||||
import com.tommytony.war.Team;
|
import com.tommytony.war.Team;
|
||||||
import com.tommytony.war.War;
|
import com.tommytony.war.War;
|
||||||
import com.tommytony.war.Warzone;
|
import com.tommytony.war.Warzone;
|
||||||
import com.tommytony.war.spout.SpoutDisplayer;
|
import com.tommytony.war.spout.SpoutDisplayer;
|
||||||
import java.util.Iterator;
|
|
||||||
import org.kitteh.tag.TagAPI;
|
|
||||||
|
|
||||||
public class ScoreCapReachedJob implements Runnable {
|
public class ScoreCapReachedJob implements Runnable {
|
||||||
|
|
||||||
@ -64,10 +63,5 @@ public class ScoreCapReachedJob implements Runnable {
|
|||||||
t.resetPoints();
|
t.resetPoints();
|
||||||
t.getPlayers().clear(); // empty the team
|
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();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -22,8 +22,13 @@ public class PlayerState {
|
|||||||
private final String playerTitle;
|
private final String playerTitle;
|
||||||
private final float exp;
|
private final float exp;
|
||||||
private final int level;
|
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.gamemode = gamemode;
|
||||||
this.health = health;
|
this.health = health;
|
||||||
this.exhaustion = exhaustion;
|
this.exhaustion = exhaustion;
|
||||||
@ -33,6 +38,7 @@ public class PlayerState {
|
|||||||
this.playerTitle = playerTitle;
|
this.playerTitle = playerTitle;
|
||||||
this.level = level;
|
this.level = level;
|
||||||
this.exp = exp;
|
this.exp = exp;
|
||||||
|
this.fly = fly;
|
||||||
this.setContents(contents);
|
this.setContents(contents);
|
||||||
this.setHelmet(helmet);
|
this.setHelmet(helmet);
|
||||||
this.setChest(chest);
|
this.setChest(chest);
|
||||||
@ -116,4 +122,8 @@ public class PlayerState {
|
|||||||
return level;
|
return level;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean canFly() {
|
||||||
|
return fly;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -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.break = The blocks in this warzone are unbreakable!
|
||||||
build.denied.zone.multteam = You already have a {0} block.
|
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.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.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.
|
command.disabled = You can only use War commands (e.g. /leave) while playing.
|
||||||
|
Loading…
Reference in New Issue
Block a user