Fix #790, add playercount and switching scoreboards

* Switching scoreboard jumps between all scoreboard types every minute
* Playercount scoreboard shows number of players per team
This commit is contained in:
Connor Monahan 2017-07-29 02:14:18 -05:00
parent 22cbba62b3
commit 821c66c556
5 changed files with 266 additions and 231 deletions

View File

@ -1,17 +1,10 @@
package com.tommytony.war; package com.tommytony.war;
import java.io.File; import com.tommytony.war.config.*;
import java.text.MessageFormat; import com.tommytony.war.spout.SpoutDisplayer;
import java.util.ArrayList; import com.tommytony.war.utility.Direction;
import java.util.HashMap; import com.tommytony.war.volume.Volume;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Random;
import java.util.logging.Level;
import org.apache.commons.lang.Validate; import org.apache.commons.lang.Validate;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.Material; import org.bukkit.Material;
@ -22,21 +15,15 @@ import org.bukkit.block.BlockState;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import org.bukkit.material.Sign; import org.bukkit.material.Sign;
import org.bukkit.scoreboard.DisplaySlot;
import org.bukkit.scoreboard.Objective;
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 org.kitteh.tag.TagAPI;
import com.tommytony.war.config.InventoryBag; import java.io.File;
import com.tommytony.war.config.ScoreboardType; import java.text.MessageFormat;
import com.tommytony.war.config.TeamConfig; import java.util.*;
import com.tommytony.war.config.TeamConfigBag; import java.util.Map.Entry;
import com.tommytony.war.config.TeamKind; import java.util.logging.Level;
import com.tommytony.war.config.TeamSpawnStyle;
import com.tommytony.war.spout.SpoutDisplayer;
import com.tommytony.war.utility.Direction;
import com.tommytony.war.volume.Volume;
/** /**
* *
@ -44,6 +31,8 @@ import com.tommytony.war.volume.Volume;
* *
*/ */
public class Team { public class Team {
private final Warzone warzone;
Random teamSpawnRandomizer = new Random();
private List<Player> players = new ArrayList<Player>(); private List<Player> players = new ArrayList<Player>();
private List<Player> teamChatPlayers = new ArrayList<Player>(); private List<Player> teamChatPlayers = new ArrayList<Player>();
private List<Location> teamSpawns; private List<Location> teamSpawns;
@ -53,9 +42,7 @@ public class Team {
private int points = 0; private int points = 0;
private Map<Location, Volume> spawnVolumes; private Map<Location, Volume> spawnVolumes;
private Volume flagVolume; private Volume flagVolume;
private final Warzone warzone;
private TeamKind kind; private TeamKind kind;
private TeamConfigBag teamConfig; private TeamConfigBag teamConfig;
private InventoryBag inventories; private InventoryBag inventories;
@ -82,7 +69,7 @@ public class Team {
} }
return null; return null;
} }
public Warzone getZone() { public Warzone getZone() {
return this.warzone; return this.warzone;
} }
@ -119,12 +106,13 @@ public class Team {
initializeTeamSpawn(teamSpawn); initializeTeamSpawn(teamSpawn);
} }
} }
public void initializeTeamSpawn(Location teamSpawn) { public void initializeTeamSpawn(Location teamSpawn) {
// Set the spawn // Set the spawn
int x = teamSpawn.getBlockX(); int x = teamSpawn.getBlockX();
int y = teamSpawn.getBlockY(); int y = teamSpawn.getBlockY();
int z = teamSpawn.getBlockZ(); int z = teamSpawn.getBlockZ();
ItemStack light = this.warzone.getWarzoneMaterials().getLightBlock(); ItemStack light = this.warzone.getWarzoneMaterials().getLightBlock();
TeamSpawnStyle style = this.getTeamConfig().resolveSpawnStyle(); TeamSpawnStyle style = this.getTeamConfig().resolveSpawnStyle();
@ -353,7 +341,7 @@ public class Team {
} }
block.update(true); block.update(true);
} }
if (War.war.isSpoutServer()) { if (War.war.isSpoutServer()) {
War.war.getSpoutDisplayer().updateStats(this.warzone); War.war.getSpoutDisplayer().updateStats(this.warzone);
} }
@ -382,7 +370,6 @@ public class Team {
return this.teamSpawns; return this.teamSpawns;
} }
Random teamSpawnRandomizer = new Random();
public Location getRandomSpawn() { public Location getRandomSpawn() {
return this.teamSpawns.get(teamSpawnRandomizer.nextInt(this.teamSpawns.size())); return this.teamSpawns.get(teamSpawnRandomizer.nextInt(this.teamSpawns.size()));
} }
@ -395,6 +382,7 @@ public class Team {
if (this.warzone.getScoreboard() != null && this.warzone.getScoreboardType() != ScoreboardType.NONE) { if (this.warzone.getScoreboard() != null && this.warzone.getScoreboardType() != ScoreboardType.NONE) {
player.setScoreboard(this.warzone.getScoreboard()); player.setScoreboard(this.warzone.getScoreboard());
} }
warzone.updateScoreboard();
} }
public List<Player> getPlayers() { public List<Player> getPlayers() {
@ -464,14 +452,14 @@ public class Team {
} }
} }
public void setName(String name) {
this.name = name;
}
public String getName() { public String getName() {
return this.name; return this.name;
} }
public void setName(String name) {
this.name = name;
}
public void removePlayer(Player thePlayer) { public void removePlayer(Player thePlayer) {
this.players.remove(thePlayer); this.players.remove(thePlayer);
synchronized (teamChatPlayers) { synchronized (teamChatPlayers) {
@ -490,21 +478,18 @@ public class Team {
this.warzone.restorePlayerState(thePlayer); this.warzone.restorePlayerState(thePlayer);
} }
this.warzone.getLoadoutSelections().remove(thePlayer); this.warzone.getLoadoutSelections().remove(thePlayer);
} warzone.updateScoreboard();
public void setRemainingLives(int remainingLives) {
this.remainingLives = remainingLives;
if (this.warzone.getScoreboard() != null && this.warzone.getScoreboardType() == ScoreboardType.LIFEPOOL) {
String teamName = kind.getColor() + name + ChatColor.RESET;
Objective obj = this.warzone.getScoreboard().getObjective("Lifepool");
obj.getScore(teamName).setScore(remainingLives);
}
} }
public int getRemainingLives() { public int getRemainingLives() {
return this.remainingLives; return this.remainingLives;
} }
public void setRemainingLives(int remainingLives) {
this.remainingLives = remainingLives;
warzone.updateScoreboard();
}
public void addPoint() { public void addPoint() {
boolean atLeastOnePlayerOnTeam = this.players.size() != 0; boolean atLeastOnePlayerOnTeam = this.players.size() != 0;
boolean atLeastOnePlayerOnOtherTeam = false; boolean atLeastOnePlayerOnOtherTeam = false;
@ -518,11 +503,7 @@ public class Team {
} else if (!atLeastOnePlayerOnOtherTeam) { } else if (!atLeastOnePlayerOnOtherTeam) {
this.teamcast("zone.score.empty"); this.teamcast("zone.score.empty");
} }
if (this.warzone.getScoreboardType() == ScoreboardType.POINTS) { this.warzone.updateScoreboard();
String teamName = kind.getColor() + name + ChatColor.RESET;
this.warzone.getScoreboard().getObjective(DisplaySlot.SIDEBAR)
.getScore(teamName).setScore(points);
}
} }
public int getPoints() { public int getPoints() {
@ -553,22 +534,17 @@ public class Team {
public void resetPoints() { public void resetPoints() {
this.points = 0; this.points = 0;
if (this.warzone.getScoreboardType() == ScoreboardType.POINTS warzone.updateScoreboard();
&& this.warzone.getScoreboard() != null) {
String teamName = kind.getColor() + name + ChatColor.RESET;
this.warzone.getScoreboard().getObjective(DisplaySlot.SIDEBAR)
.getScore(teamName).setScore(points);
}
}
public void setFlagVolume(Volume flagVolume) {
this.flagVolume = flagVolume;
} }
public Volume getFlagVolume() { public Volume getFlagVolume() {
return this.flagVolume; return this.flagVolume;
} }
public void setFlagVolume(Volume flagVolume) {
this.flagVolume = flagVolume;
}
private void setFlagVolume() { private void setFlagVolume() {
if (this.flagVolume == null) { if (this.flagVolume == null) {
this.flagVolume = new Volume(this.getName() + "flag", this.warzone.getWorld()); this.flagVolume = new Volume(this.getName() + "flag", this.warzone.getWorld());
@ -689,16 +665,6 @@ public class Team {
} }
} }
public void setTeamFlag(Location teamFlag) {
this.teamFlag = teamFlag;
// this resets the block to old state
this.setFlagVolume();
this.getFlagVolume().saveBlocks();
this.initializeTeamFlag();
}
public boolean isTeamFlagBlock(Block block) { public boolean isTeamFlagBlock(Block block) {
if (this.teamFlag != null) { if (this.teamFlag != null) {
int flagX = this.teamFlag.getBlockX(); int flagX = this.teamFlag.getBlockX();
@ -714,6 +680,16 @@ public class Team {
public Location getTeamFlag() { public Location getTeamFlag() {
return this.teamFlag; return this.teamFlag;
} }
public void setTeamFlag(Location teamFlag) {
this.teamFlag = teamFlag;
// this resets the block to old state
this.setFlagVolume();
this.getFlagVolume().saveBlocks();
this.initializeTeamFlag();
}
public void deleteTeamFlag() { public void deleteTeamFlag() {
this.getFlagVolume().resetBlocks(); this.getFlagVolume().resetBlocks();

View File

@ -1,17 +1,23 @@
package com.tommytony.war; package com.tommytony.war;
import java.io.File; import com.tommytony.war.command.WarCommandHandler;
import java.io.IOException; import com.tommytony.war.config.*;
import java.text.MessageFormat; import com.tommytony.war.event.*;
import java.util.*;
import java.util.logging.FileHandler;
import java.util.logging.Formatter;
import java.util.logging.Level;
import com.tommytony.war.job.CapturePointTimer; import com.tommytony.war.job.CapturePointTimer;
import com.tommytony.war.job.HelmetProtectionTask;
import com.tommytony.war.job.ScoreboardSwitchTimer;
import com.tommytony.war.job.SpoutFadeOutMessageJob;
import com.tommytony.war.mapper.WarYmlMapper;
import com.tommytony.war.mapper.WarzoneYmlMapper;
import com.tommytony.war.spout.SpoutDisplayer;
import com.tommytony.war.structure.*;
import com.tommytony.war.ui.UIManager; import com.tommytony.war.ui.UIManager;
import com.tommytony.war.utility.Loadout;
import com.tommytony.war.utility.PlayerState;
import com.tommytony.war.utility.SizeCounter;
import com.tommytony.war.utility.WarLogFormatter;
import com.tommytony.war.volume.Volume;
import net.milkbowl.vault.economy.Economy; import net.milkbowl.vault.economy.Economy;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.Material; import org.bukkit.Material;
@ -29,41 +35,13 @@ import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.potion.PotionEffect; import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType; import org.bukkit.potion.PotionEffectType;
import com.tommytony.war.command.WarCommandHandler; import java.io.File;
import com.tommytony.war.config.FlagReturn; import java.io.IOException;
import com.tommytony.war.config.InventoryBag; import java.text.MessageFormat;
import com.tommytony.war.config.ScoreboardType; import java.util.*;
import com.tommytony.war.config.KillstreakReward; import java.util.logging.FileHandler;
import com.tommytony.war.config.MySQLConfig; import java.util.logging.Formatter;
import com.tommytony.war.config.TeamConfig; import java.util.logging.Level;
import com.tommytony.war.config.TeamConfigBag;
import com.tommytony.war.config.TeamKind;
import com.tommytony.war.config.TeamSpawnStyle;
import com.tommytony.war.config.WarConfig;
import com.tommytony.war.config.WarConfigBag;
import com.tommytony.war.config.WarzoneConfig;
import com.tommytony.war.config.WarzoneConfigBag;
import com.tommytony.war.event.WarBlockListener;
import com.tommytony.war.event.WarEntityListener;
import com.tommytony.war.event.WarPlayerListener;
import com.tommytony.war.event.WarServerListener;
import com.tommytony.war.event.WarTagListener;
import com.tommytony.war.job.HelmetProtectionTask;
import com.tommytony.war.job.SpoutFadeOutMessageJob;
import com.tommytony.war.mapper.WarYmlMapper;
import com.tommytony.war.mapper.WarzoneYmlMapper;
import com.tommytony.war.spout.SpoutDisplayer;
import com.tommytony.war.structure.Bomb;
import com.tommytony.war.structure.Cake;
import com.tommytony.war.structure.HubLobbyMaterials;
import com.tommytony.war.structure.Monument;
import com.tommytony.war.structure.WarHub;
import com.tommytony.war.structure.ZoneLobby;
import com.tommytony.war.utility.Loadout;
import com.tommytony.war.utility.PlayerState;
import com.tommytony.war.utility.SizeCounter;
import com.tommytony.war.utility.WarLogFormatter;
import com.tommytony.war.volume.Volume;
/** /**
* Main class of War * Main class of War
@ -72,47 +50,38 @@ import com.tommytony.war.volume.Volume;
* @package bukkit.tommytony.war * @package bukkit.tommytony.war
*/ */
public class War extends JavaPlugin { public class War extends JavaPlugin {
static final boolean HIDE_BLANK_MESSAGES = true;
public static War war; public static War war;
private static ResourceBundle messages = ResourceBundle.getBundle("messages");
private final List<String> zoneMakerNames = new ArrayList<String>();
private final List<String> commandWhitelist = new ArrayList<String>();
private final List<Warzone> incompleteZones = new ArrayList<Warzone>();
private final List<String> zoneMakersImpersonatingPlayers = new ArrayList<String>();
private final HashMap<String, String> wandBearers = new HashMap<String, String>(); // playername to zonename
private final List<String> deadlyAdjectives = new ArrayList<String>();
private final List<String> killerVerbs = new ArrayList<String>();
private final InventoryBag defaultInventories = new InventoryBag();
private final WarConfigBag warConfig = new WarConfigBag();
private final WarzoneConfigBag warzoneDefaultConfig = new WarzoneConfigBag();
private final TeamConfigBag teamDefaultConfig = new TeamConfigBag();
// general // general
private WarPlayerListener playerListener = new WarPlayerListener(); private WarPlayerListener playerListener = new WarPlayerListener();
private WarEntityListener entityListener = new WarEntityListener(); private WarEntityListener entityListener = new WarEntityListener();
private WarBlockListener blockListener = new WarBlockListener(); private WarBlockListener blockListener = new WarBlockListener();
private WarServerListener serverListener = new WarServerListener(); private WarServerListener serverListener = new WarServerListener();
private WarCommandHandler commandHandler = new WarCommandHandler(); private WarCommandHandler commandHandler = new WarCommandHandler();
private PluginDescriptionFile desc = null; private PluginDescriptionFile desc = null;
private boolean loaded = false; private boolean loaded = false;
private boolean isSpoutServer = false; private boolean isSpoutServer = false;
private boolean tagServer = false; private boolean tagServer = false;
// Zones and hub // Zones and hub
private List<Warzone> warzones = new ArrayList<Warzone>(); private List<Warzone> warzones = new ArrayList<Warzone>();
private WarHub warHub; private WarHub warHub;
private final List<String> zoneMakerNames = new ArrayList<String>();
private final List<String> commandWhitelist = new ArrayList<String>();
private final List<Warzone> incompleteZones = new ArrayList<Warzone>();
private final List<String> zoneMakersImpersonatingPlayers = new ArrayList<String>();
private HashMap<String, PlayerState> disconnected = new HashMap<String, PlayerState>(); private HashMap<String, PlayerState> disconnected = new HashMap<String, PlayerState>();
private final HashMap<String, String> wandBearers = new HashMap<String, String>(); // playername to zonename
private final List<String> deadlyAdjectives = new ArrayList<String>();
private final List<String> killerVerbs = new ArrayList<String>();
private final InventoryBag defaultInventories = new InventoryBag();
private KillstreakReward killstreakReward; private KillstreakReward killstreakReward;
private MySQLConfig mysqlConfig; private MySQLConfig mysqlConfig;
private Economy econ = null; private Economy econ = null;
private final WarConfigBag warConfig = new WarConfigBag();
private final WarzoneConfigBag warzoneDefaultConfig = new WarzoneConfigBag();
private final TeamConfigBag teamDefaultConfig = new TeamConfigBag();
private SpoutDisplayer spoutMessenger = null; private SpoutDisplayer spoutMessenger = null;
private static ResourceBundle messages = ResourceBundle.getBundle("messages");
private HubLobbyMaterials warhubMaterials = new HubLobbyMaterials( private HubLobbyMaterials warhubMaterials = new HubLobbyMaterials(
new ItemStack(Material.GLASS), new ItemStack(Material.WOOD), new ItemStack(Material.GLASS), new ItemStack(Material.WOOD),
new ItemStack(Material.OBSIDIAN), new ItemStack(Material.GLOWSTONE)); new ItemStack(Material.OBSIDIAN), new ItemStack(Material.GLOWSTONE));
@ -123,6 +92,15 @@ public class War extends JavaPlugin {
War.war = this; War.war = this;
} }
public static void reloadLanguage() {
String[] parts = War.war.getWarConfig().getString(WarConfig.LANGUAGE).replace("-", "_").split("_");
Locale lang = new Locale(parts[0]);
if (parts.length >= 2) {
lang = new Locale(parts[0], parts[1]);
}
War.messages = ResourceBundle.getBundle("messages", lang);
}
/** /**
* @see JavaPlugin#onEnable() * @see JavaPlugin#onEnable()
* @see War#loadWar() * @see War#loadWar()
@ -145,7 +123,7 @@ public class War extends JavaPlugin {
public void loadWar() { public void loadWar() {
this.setLoaded(true); this.setLoaded(true);
this.desc = this.getDescription(); this.desc = this.getDescription();
// Spout server detection // Spout server detection
try { try {
Class.forName("org.getspout.spoutapi.player.SpoutPlayer"); Class.forName("org.getspout.spoutapi.player.SpoutPlayer");
@ -245,37 +223,37 @@ public class War extends JavaPlugin {
this.getDefaultInventories().clearLoadouts(); this.getDefaultInventories().clearLoadouts();
HashMap<Integer, ItemStack> defaultLoadout = new HashMap<Integer, ItemStack>(); HashMap<Integer, ItemStack> defaultLoadout = new HashMap<Integer, ItemStack>();
ItemStack stoneSword = new ItemStack(Material.STONE_SWORD, 1, (byte) 8); ItemStack stoneSword = new ItemStack(Material.STONE_SWORD, 1, (byte) 8);
stoneSword.setDurability((short) 8); stoneSword.setDurability((short) 8);
defaultLoadout.put(0, stoneSword); defaultLoadout.put(0, stoneSword);
ItemStack bow = new ItemStack(Material.BOW, 1, (byte) 8); ItemStack bow = new ItemStack(Material.BOW, 1, (byte) 8);
bow.setDurability((short) 8); bow.setDurability((short) 8);
defaultLoadout.put(1, bow); defaultLoadout.put(1, bow);
ItemStack arrows = new ItemStack(Material.ARROW, 7); ItemStack arrows = new ItemStack(Material.ARROW, 7);
defaultLoadout.put(2, arrows); defaultLoadout.put(2, arrows);
ItemStack stonePick = new ItemStack(Material.IRON_PICKAXE, 1, (byte) 8); ItemStack stonePick = new ItemStack(Material.IRON_PICKAXE, 1, (byte) 8);
stonePick.setDurability((short) 8); stonePick.setDurability((short) 8);
defaultLoadout.put(3, stonePick); defaultLoadout.put(3, stonePick);
ItemStack stoneSpade = new ItemStack(Material.STONE_SPADE, 1, (byte) 8); ItemStack stoneSpade = new ItemStack(Material.STONE_SPADE, 1, (byte) 8);
stoneSword.setDurability((short) 8); stoneSword.setDurability((short) 8);
defaultLoadout.put(4, stoneSpade); defaultLoadout.put(4, stoneSpade);
this.getDefaultInventories().addLoadout("default", defaultLoadout); this.getDefaultInventories().addLoadout("default", defaultLoadout);
HashMap<Integer, ItemStack> reward = new HashMap<Integer, ItemStack>(); HashMap<Integer, ItemStack> reward = new HashMap<Integer, ItemStack>();
reward.put(0, new ItemStack(Material.CAKE, 1)); reward.put(0, new ItemStack(Material.CAKE, 1));
this.getDefaultInventories().setReward(reward); this.getDefaultInventories().setReward(reward);
this.getCommandWhitelist().add("who"); this.getCommandWhitelist().add("who");
this.getZoneMakerNames().add("tommytony"); this.getZoneMakerNames().add("tommytony");
this.setKillstreakReward(new KillstreakReward()); this.setKillstreakReward(new KillstreakReward());
this.setMysqlConfig(new MySQLConfig()); this.setMysqlConfig(new MySQLConfig());
// Add constants // Add constants
this.getDeadlyAdjectives().clear(); this.getDeadlyAdjectives().clear();
for (String adjective : this.getString("pvp.kill.adjectives").split(";")) { for (String adjective : this.getString("pvp.kill.adjectives").split(";")) {
@ -285,17 +263,19 @@ public class War extends JavaPlugin {
for (String verb : this.getString("pvp.kill.verbs").split(";")) { for (String verb : this.getString("pvp.kill.verbs").split(";")) {
this.getKillerVerbs().add(verb); this.getKillerVerbs().add(verb);
} }
// Load files // Load files
WarYmlMapper.load(); WarYmlMapper.load();
// Start tasks // Start tasks
HelmetProtectionTask helmetProtectionTask = new HelmetProtectionTask(); HelmetProtectionTask helmetProtectionTask = new HelmetProtectionTask();
this.getServer().getScheduler().scheduleSyncRepeatingTask(this, helmetProtectionTask, 250, 100); this.getServer().getScheduler().scheduleSyncRepeatingTask(this, helmetProtectionTask, 250, 100);
CapturePointTimer cpt = new CapturePointTimer(); CapturePointTimer cpt = new CapturePointTimer();
cpt.runTaskTimer(this, 100, 20); cpt.runTaskTimer(this, 100, 20);
ScoreboardSwitchTimer sst = new ScoreboardSwitchTimer();
sst.runTaskTimer(this, 500, 20 * 60);
if (this.isSpoutServer) { if (this.isSpoutServer) {
SpoutFadeOutMessageJob fadeOutMessagesTask = new SpoutFadeOutMessageJob(); SpoutFadeOutMessageJob fadeOutMessagesTask = new SpoutFadeOutMessageJob();
this.getServer().getScheduler().scheduleSyncRepeatingTask(this, fadeOutMessagesTask, 100, 100); this.getServer().getScheduler().scheduleSyncRepeatingTask(this, fadeOutMessagesTask, 100, 100);
@ -331,25 +311,16 @@ public class War extends JavaPlugin {
} catch (IOException e) { } catch (IOException e) {
this.getLogger().log(Level.WARNING, "Failed to create War log file"); this.getLogger().log(Level.WARNING, "Failed to create War log file");
} }
// Size check // Size check
long datSize = SizeCounter.getFileOrDirectorySize(new File(this.getDataFolder() + "/dat/")) / 1024 / 1024; long datSize = SizeCounter.getFileOrDirectorySize(new File(this.getDataFolder() + "/dat/")) / 1024 / 1024;
long tempSize = SizeCounter.getFileOrDirectorySize(new File(this.getDataFolder() + "/temp/")) / 1024 / 1024; long tempSize = SizeCounter.getFileOrDirectorySize(new File(this.getDataFolder() + "/temp/")) / 1024 / 1024;
if (datSize + tempSize > 100) { if (datSize + tempSize > 100) {
this.log("War data files are taking " + datSize + "MB and its temp files " + tempSize + "MB. Consider permanently deleting old warzone versions and backups in /plugins/War/temp/.", Level.WARNING); this.log("War data files are taking " + datSize + "MB and its temp files " + tempSize + "MB. Consider permanently deleting old warzone versions and backups in /plugins/War/temp/.", Level.WARNING);
} }
this.log("War v" + this.desc.getVersion() + " is on.", Level.INFO);
}
public static void reloadLanguage() { this.log("War v" + this.desc.getVersion() + " is on.", Level.INFO);
String[] parts = War.war.getWarConfig().getString(WarConfig.LANGUAGE).replace("-", "_").split("_");
Locale lang = new Locale(parts[0]);
if (parts.length >= 2) {
lang = new Locale(parts[0], parts[1]);
}
War.messages = ResourceBundle.getBundle("messages", lang);
} }
/** /**
@ -430,7 +401,7 @@ public class War extends JavaPlugin {
private void inventoryToLoadout(Player player, HashMap<Integer, ItemStack> loadout) { private void inventoryToLoadout(Player player, HashMap<Integer, ItemStack> loadout) {
this.inventoryToLoadout(player.getInventory(), loadout); this.inventoryToLoadout(player.getInventory(), loadout);
} }
public String updateTeamFromNamedParams(Team team, CommandSender commandSender, String[] arguments) { public String updateTeamFromNamedParams(Team team, CommandSender commandSender, String[] arguments) {
try { try {
Map<String, String> namedParams = new HashMap<String, String>(); Map<String, String> namedParams = new HashMap<String, String>();
@ -444,10 +415,10 @@ public class War extends JavaPlugin {
thirdParameter.put(pairSplit[0].toLowerCase(), pairSplit[2]); thirdParameter.put(pairSplit[0].toLowerCase(), pairSplit[2]);
} }
} }
StringBuilder returnMessage = new StringBuilder(); StringBuilder returnMessage = new StringBuilder();
returnMessage.append(team.getTeamConfig().updateFromNamedParams(namedParams)); returnMessage.append(team.getTeamConfig().updateFromNamedParams(namedParams));
if (commandSender instanceof Player) { if (commandSender instanceof Player) {
Player player = (Player) commandSender; Player player = (Player) commandSender;
if (namedParams.containsKey("loadout")) { if (namedParams.containsKey("loadout")) {
@ -466,7 +437,7 @@ public class War extends JavaPlugin {
} }
} }
} }
loadout = new HashMap<Integer, ItemStack>(); loadout = new HashMap<Integer, ItemStack>();
team.getInventories().setLoadout(loadoutName, loadout); team.getInventories().setLoadout(loadoutName, loadout);
returnMessage.append(loadoutName + " respawn loadout added."); returnMessage.append(loadoutName + " respawn loadout added.");
@ -483,7 +454,7 @@ public class War extends JavaPlugin {
ldt.setPermission(null); ldt.setPermission(null);
returnMessage.append(' ').append(loadoutName).append(" respawn loadout permission deleted."); returnMessage.append(' ').append(loadoutName).append(" respawn loadout permission deleted.");
} }
} }
if (namedParams.containsKey("deleteloadout")) { if (namedParams.containsKey("deleteloadout")) {
String loadoutName = namedParams.get("deleteloadout"); String loadoutName = namedParams.get("deleteloadout");
if (team.getInventories().containsLoadout(loadoutName)) { if (team.getInventories().containsLoadout(loadoutName)) {
@ -520,7 +491,7 @@ public class War extends JavaPlugin {
thirdParameter.put(pairSplit[0].toLowerCase(), pairSplit[2]); thirdParameter.put(pairSplit[0].toLowerCase(), pairSplit[2]);
} }
} }
StringBuilder returnMessage = new StringBuilder(); StringBuilder returnMessage = new StringBuilder();
if (namedParams.containsKey("author")) { if (namedParams.containsKey("author")) {
for(String author : namedParams.get("author").split(",")) { for(String author : namedParams.get("author").split(",")) {
@ -538,7 +509,7 @@ public class War extends JavaPlugin {
} }
} }
} }
returnMessage.append(warzone.getWarzoneConfig().updateFromNamedParams(namedParams)); returnMessage.append(warzone.getWarzoneConfig().updateFromNamedParams(namedParams));
returnMessage.append(warzone.getTeamDefaultConfig().updateFromNamedParams(namedParams)); returnMessage.append(warzone.getTeamDefaultConfig().updateFromNamedParams(namedParams));
@ -561,7 +532,7 @@ public class War extends JavaPlugin {
} }
} }
} }
warzone.getDefaultInventories().setLoadout(loadoutName, loadout); warzone.getDefaultInventories().setLoadout(loadoutName, loadout);
returnMessage.append(loadoutName).append(" respawn loadout added."); returnMessage.append(loadoutName).append(" respawn loadout added.");
} else { } else {
@ -577,7 +548,7 @@ public class War extends JavaPlugin {
ldt.setPermission(null); ldt.setPermission(null);
returnMessage.append(' ').append(loadoutName).append(" respawn loadout permission deleted."); returnMessage.append(' ').append(loadoutName).append(" respawn loadout permission deleted.");
} }
} }
if (namedParams.containsKey("deleteloadout")) { if (namedParams.containsKey("deleteloadout")) {
String loadoutName = namedParams.get("deleteloadout"); String loadoutName = namedParams.get("deleteloadout");
if (warzone.getDefaultInventories().containsLoadout(loadoutName)) { if (warzone.getDefaultInventories().containsLoadout(loadoutName)) {
@ -597,7 +568,7 @@ public class War extends JavaPlugin {
String whichBlocks = namedParams.get("lobbymaterial"); String whichBlocks = namedParams.get("lobbymaterial");
ItemStack blockInHand = player.getInventory().getItemInMainHand(); ItemStack blockInHand = player.getInventory().getItemInMainHand();
boolean updatedLobbyMaterials = false; boolean updatedLobbyMaterials = false;
if (!blockInHand.getType().isBlock() && !blockInHand.getType().equals(Material.AIR)) { if (!blockInHand.getType().isBlock() && !blockInHand.getType().equals(Material.AIR)) {
this.badMsg(player, "Can only use blocks or air as lobby material."); this.badMsg(player, "Can only use blocks or air as lobby material.");
} else { } else {
@ -618,7 +589,7 @@ public class War extends JavaPlugin {
returnMessage.append(" lobby light material set to ").append(blockInHand.getType()); returnMessage.append(" lobby light material set to ").append(blockInHand.getType());
updatedLobbyMaterials = true; updatedLobbyMaterials = true;
} }
if (updatedLobbyMaterials && warzone.getLobby() != null) { if (updatedLobbyMaterials && warzone.getLobby() != null) {
warzone.getLobby().getVolume().resetBlocks(); warzone.getLobby().getVolume().resetBlocks();
warzone.getLobby().initialize(); warzone.getLobby().initialize();
@ -629,7 +600,7 @@ public class War extends JavaPlugin {
String whichBlocks = namedParams.get("material"); String whichBlocks = namedParams.get("material");
ItemStack blockInHand = player.getInventory().getItemInMainHand(); ItemStack blockInHand = player.getInventory().getItemInMainHand();
boolean updatedMaterials = false; boolean updatedMaterials = false;
if (!blockInHand.getType().isBlock()) { if (!blockInHand.getType().isBlock()) {
this.badMsg(player, "Can only use blocks as material."); this.badMsg(player, "Can only use blocks as material.");
} else { } else {
@ -646,7 +617,7 @@ public class War extends JavaPlugin {
returnMessage.append(" light material set to ").append(blockInHand.getType()); returnMessage.append(" light material set to ").append(blockInHand.getType());
updatedMaterials = true; updatedMaterials = true;
} }
if (updatedMaterials) { if (updatedMaterials) {
// reset all structures // reset all structures
for (Monument monument : warzone.getMonuments()) { for (Monument monument : warzone.getMonuments()) {
@ -695,13 +666,13 @@ public class War extends JavaPlugin {
thirdParameter.put(pairSplit[0].toLowerCase(), pairSplit[2]); thirdParameter.put(pairSplit[0].toLowerCase(), pairSplit[2]);
} }
} }
StringBuilder returnMessage = new StringBuilder(); StringBuilder returnMessage = new StringBuilder();
returnMessage.append(this.getWarConfig().updateFromNamedParams(namedParams)); returnMessage.append(this.getWarConfig().updateFromNamedParams(namedParams));
returnMessage.append(this.getWarzoneDefaultConfig().updateFromNamedParams(namedParams)); returnMessage.append(this.getWarzoneDefaultConfig().updateFromNamedParams(namedParams));
returnMessage.append(this.getTeamDefaultConfig().updateFromNamedParams(namedParams)); returnMessage.append(this.getTeamDefaultConfig().updateFromNamedParams(namedParams));
if (commandSender instanceof Player) { if (commandSender instanceof Player) {
Player player = (Player) commandSender; Player player = (Player) commandSender;
if (namedParams.containsKey("loadout")) { if (namedParams.containsKey("loadout")) {
@ -724,7 +695,7 @@ public class War extends JavaPlugin {
ldt.setPermission(null); ldt.setPermission(null);
returnMessage.append(' ').append(loadoutName).append(" respawn loadout permission deleted."); returnMessage.append(' ').append(loadoutName).append(" respawn loadout permission deleted.");
} }
} }
if (namedParams.containsKey("deleteloadout")) { if (namedParams.containsKey("deleteloadout")) {
String loadoutName = namedParams.get("deleteloadout"); String loadoutName = namedParams.get("deleteloadout");
if (this.getDefaultInventories().containsLoadout(loadoutName)) { if (this.getDefaultInventories().containsLoadout(loadoutName)) {
@ -753,7 +724,7 @@ public class War extends JavaPlugin {
String whichBlocks = namedParams.get("warhubmaterial"); String whichBlocks = namedParams.get("warhubmaterial");
ItemStack blockInHand = player.getInventory().getItemInMainHand(); ItemStack blockInHand = player.getInventory().getItemInMainHand();
boolean updatedWarhubMaterials = false; boolean updatedWarhubMaterials = false;
if (!blockInHand.getType().isBlock() && !blockInHand.getType().equals(Material.AIR)) { if (!blockInHand.getType().isBlock() && !blockInHand.getType().equals(Material.AIR)) {
this.badMsg(player, "Can only use blocks or air as warhub material."); this.badMsg(player, "Can only use blocks or air as warhub material.");
} else { } else {
@ -774,7 +745,7 @@ public class War extends JavaPlugin {
returnMessage.append(" warhub light material set to " + blockInHand.getType()); returnMessage.append(" warhub light material set to " + blockInHand.getType());
updatedWarhubMaterials = true; updatedWarhubMaterials = true;
} }
if (updatedWarhubMaterials && War.war.getWarHub() != null) { if (updatedWarhubMaterials && War.war.getWarHub() != null) {
War.war.getWarHub().getVolume().resetBlocks(); War.war.getWarHub().getVolume().resetBlocks();
War.war.getWarHub().initialize(); War.war.getWarHub().initialize();
@ -788,24 +759,24 @@ public class War extends JavaPlugin {
return "PARSE-ERROR"; return "PARSE-ERROR";
} }
} }
public String printConfig(Team team) { public String printConfig(Team team) {
ChatColor teamColor = ChatColor.AQUA; ChatColor teamColor = ChatColor.AQUA;
ChatColor normalColor = ChatColor.WHITE; ChatColor normalColor = ChatColor.WHITE;
String teamConfigStr = ""; String teamConfigStr = "";
InventoryBag invs = team.getInventories(); InventoryBag invs = team.getInventories();
teamConfigStr += getLoadoutsString(invs); teamConfigStr += getLoadoutsString(invs);
for (TeamConfig teamConfig : TeamConfig.values()) { for (TeamConfig teamConfig : TeamConfig.values()) {
Object value = team.getTeamConfig().getValue(teamConfig); Object value = team.getTeamConfig().getValue(teamConfig);
if (value != null) { if (value != null) {
teamConfigStr += " " + teamConfig.toStringWithValue(value).replace(":", ":" + teamColor) + normalColor; teamConfigStr += " " + teamConfig.toStringWithValue(value).replace(":", ":" + teamColor) + normalColor;
} }
} }
return " ::" + teamColor + "Team " + team.getName() + teamColor + " config" + normalColor + "::" return " ::" + teamColor + "Team " + team.getName() + teamColor + " config" + normalColor + "::"
+ ifEmptyInheritedForTeam(teamConfigStr); + ifEmptyInheritedForTeam(teamConfigStr);
} }
@ -813,7 +784,7 @@ public class War extends JavaPlugin {
StringBuilder loadoutsString = new StringBuilder(); StringBuilder loadoutsString = new StringBuilder();
ChatColor loadoutColor = ChatColor.GREEN; ChatColor loadoutColor = ChatColor.GREEN;
ChatColor normalColor = ChatColor.WHITE; ChatColor normalColor = ChatColor.WHITE;
if (invs.hasLoadouts()) { if (invs.hasLoadouts()) {
StringBuilder loadouts = new StringBuilder(); StringBuilder loadouts = new StringBuilder();
for (Loadout ldt : invs.getNewLoadouts()) { for (Loadout ldt : invs.getNewLoadouts()) {
@ -825,11 +796,11 @@ public class War extends JavaPlugin {
} }
loadoutsString.append(" loadout:").append(loadoutColor).append(loadouts.toString()).append(normalColor); loadoutsString.append(" loadout:").append(loadoutColor).append(loadouts.toString()).append(normalColor);
} }
if (invs.hasReward()) { if (invs.hasReward()) {
loadoutsString.append(" reward:").append(loadoutColor).append("default").append(normalColor); loadoutsString.append(" reward:").append(loadoutColor).append("default").append(normalColor);
} }
return loadoutsString.toString(); return loadoutsString.toString();
} }
@ -838,7 +809,7 @@ public class War extends JavaPlugin {
ChatColor zoneColor = ChatColor.DARK_AQUA; ChatColor zoneColor = ChatColor.DARK_AQUA;
ChatColor authorColor = ChatColor.GREEN; ChatColor authorColor = ChatColor.GREEN;
ChatColor normalColor = ChatColor.WHITE; ChatColor normalColor = ChatColor.WHITE;
String warzoneConfigStr = ""; String warzoneConfigStr = "";
for (WarzoneConfig warzoneConfig : WarzoneConfig.values()) { for (WarzoneConfig warzoneConfig : WarzoneConfig.values()) {
Object value = zone.getWarzoneConfig().getValue(warzoneConfig); Object value = zone.getWarzoneConfig().getValue(warzoneConfig);
@ -846,7 +817,7 @@ public class War extends JavaPlugin {
warzoneConfigStr += " " + warzoneConfig.toStringWithValue(value).replace(":", ":" + zoneColor) + normalColor; warzoneConfigStr += " " + warzoneConfig.toStringWithValue(value).replace(":", ":" + zoneColor) + normalColor;
} }
} }
String teamDefaultsStr = ""; String teamDefaultsStr = "";
teamDefaultsStr += getLoadoutsString( zone.getDefaultInventories()); teamDefaultsStr += getLoadoutsString( zone.getDefaultInventories());
for (TeamConfig teamConfig : TeamConfig.values()) { for (TeamConfig teamConfig : TeamConfig.values()) {
@ -855,8 +826,8 @@ public class War extends JavaPlugin {
teamDefaultsStr += " " + teamConfig.toStringWithValue(value).replace(":", ":" + teamColor) + normalColor; teamDefaultsStr += " " + teamConfig.toStringWithValue(value).replace(":", ":" + teamColor) + normalColor;
} }
} }
return "::" + zoneColor + "Warzone " + authorColor + zone.getName() + zoneColor + " config" + normalColor + "::" return "::" + zoneColor + "Warzone " + authorColor + zone.getName() + zoneColor + " config" + normalColor + "::"
+ " author:" + authorColor + ifEmptyEveryone(zone.getAuthorsString()) + normalColor + " author:" + authorColor + ifEmptyEveryone(zone.getAuthorsString()) + normalColor
+ ifEmptyInheritedForWarzone(warzoneConfigStr) + ifEmptyInheritedForWarzone(warzoneConfigStr)
+ " ::" + teamColor + "Team defaults" + normalColor + "::" + " ::" + teamColor + "Team defaults" + normalColor + "::"
@ -869,10 +840,10 @@ public class War extends JavaPlugin {
} }
return maybeEmpty; return maybeEmpty;
} }
private String ifEmptyInheritedForTeam(String maybeEmpty) { private String ifEmptyInheritedForTeam(String maybeEmpty) {
if (maybeEmpty.equals("")) { if (maybeEmpty.equals("")) {
maybeEmpty = " all values inherited (see " + ChatColor.GREEN + "/warcfg -p" + ChatColor.WHITE maybeEmpty = " all values inherited (see " + ChatColor.GREEN + "/warcfg -p" + ChatColor.WHITE
+ " and " + ChatColor.GREEN + "/zonecfg -p" + ChatColor.WHITE + ")"; + " and " + ChatColor.GREEN + "/zonecfg -p" + ChatColor.WHITE + ")";
} }
return maybeEmpty; return maybeEmpty;
@ -890,26 +861,26 @@ public class War extends JavaPlugin {
ChatColor zoneColor = ChatColor.DARK_AQUA; ChatColor zoneColor = ChatColor.DARK_AQUA;
ChatColor globalColor = ChatColor.DARK_GREEN; ChatColor globalColor = ChatColor.DARK_GREEN;
ChatColor normalColor = ChatColor.WHITE; ChatColor normalColor = ChatColor.WHITE;
String warConfigStr = ""; String warConfigStr = "";
for (WarConfig warConfig : WarConfig.values()) { for (WarConfig warConfig : WarConfig.values()) {
warConfigStr += " " + warConfig.toStringWithValue(this.getWarConfig().getValue(warConfig)).replace(":", ":" + globalColor) + normalColor; warConfigStr += " " + warConfig.toStringWithValue(this.getWarConfig().getValue(warConfig)).replace(":", ":" + globalColor) + normalColor;
} }
String warzoneDefaultsStr = ""; String warzoneDefaultsStr = "";
for (WarzoneConfig warzoneConfig : WarzoneConfig.values()) { for (WarzoneConfig warzoneConfig : WarzoneConfig.values()) {
warzoneDefaultsStr += " " + warzoneConfig.toStringWithValue(this.getWarzoneDefaultConfig().getValue(warzoneConfig)).replace(":", ":" + zoneColor) + normalColor; warzoneDefaultsStr += " " + warzoneConfig.toStringWithValue(this.getWarzoneDefaultConfig().getValue(warzoneConfig)).replace(":", ":" + zoneColor) + normalColor;
} }
String teamDefaultsStr = ""; String teamDefaultsStr = "";
teamDefaultsStr += getLoadoutsString(this.getDefaultInventories()); teamDefaultsStr += getLoadoutsString(this.getDefaultInventories());
for (TeamConfig teamConfig : TeamConfig.values()) { for (TeamConfig teamConfig : TeamConfig.values()) {
teamDefaultsStr += " " + teamConfig.toStringWithValue(this.getTeamDefaultConfig().getValue(teamConfig)).replace(":", ":" + teamColor) + normalColor; teamDefaultsStr += " " + teamConfig.toStringWithValue(this.getTeamDefaultConfig().getValue(teamConfig)).replace(":", ":" + teamColor) + normalColor;
} }
return normalColor + "::" + globalColor + "War config" + normalColor + "::" + warConfigStr return normalColor + "::" + globalColor + "War config" + normalColor + "::" + warConfigStr
+ normalColor + " ::" + zoneColor + "Warzone defaults" + normalColor + "::" + warzoneDefaultsStr + normalColor + " ::" + zoneColor + "Warzone defaults" + normalColor + "::" + warzoneDefaultsStr
+ normalColor + " ::" + teamColor + "Team defaults" + normalColor + "::" + teamDefaultsStr; + normalColor + " ::" + teamColor + "Team defaults" + normalColor + "::" + teamDefaultsStr;
} }
private void setZoneRallyPoint(String warzoneName, Player player) { private void setZoneRallyPoint(String warzoneName, Player player) {
@ -959,8 +930,6 @@ public class War extends JavaPlugin {
return activeZones; return activeZones;
} }
static final boolean HIDE_BLANK_MESSAGES = true;
public void msg(CommandSender sender, String str) { public void msg(CommandSender sender, String str) {
if (messages.containsKey(str)) str = this.getString(str); if (messages.containsKey(str)) str = this.getString(str);
if (HIDE_BLANK_MESSAGES && (str == null || str.isEmpty())) return; if (HIDE_BLANK_MESSAGES && (str == null || str.isEmpty())) return;
@ -1227,10 +1196,7 @@ public class War extends JavaPlugin {
} }
public boolean inAnyWarzoneLobby(Location location) { public boolean inAnyWarzoneLobby(Location location) {
if (ZoneLobby.getLobbyByLocation(location) == null) { return ZoneLobby.getLobbyByLocation(location) != null;
return false;
}
return true;
} }
public List<String> getZoneMakersImpersonatingPlayers() { public List<String> getZoneMakersImpersonatingPlayers() {
@ -1293,14 +1259,14 @@ public class War extends JavaPlugin {
return this.spoutMessenger ; return this.spoutMessenger ;
} }
public void setWarhubMaterials(HubLobbyMaterials warhubMaterials) {
this.warhubMaterials = warhubMaterials;
}
public HubLobbyMaterials getWarhubMaterials() { public HubLobbyMaterials getWarhubMaterials() {
return this.warhubMaterials; return this.warhubMaterials;
} }
public void setWarhubMaterials(HubLobbyMaterials warhubMaterials) {
this.warhubMaterials = warhubMaterials;
}
public boolean isTagServer() { public boolean isTagServer() {
return tagServer; return tagServer;
} }

View File

@ -114,6 +114,7 @@ public class Warzone {
private Random killSeed = new Random(); private Random killSeed = new Random();
// prevent tryCallDelayedPlayers from being recursively called by Warzone#assign // prevent tryCallDelayedPlayers from being recursively called by Warzone#assign
private boolean activeDelayedCall = false; private boolean activeDelayedCall = false;
private ScoreboardType scoreboardType;
public Warzone(World world, String name) { public Warzone(World world, String name) {
this.world = world; this.world = world;
@ -123,6 +124,9 @@ public class Warzone {
this.volume = new ZoneVolume(name, this.getWorld(), this); this.volume = new ZoneVolume(name, this.getWorld(), this);
this.lobbyMaterials = War.war.getWarhubMaterials().clone(); this.lobbyMaterials = War.war.getWarhubMaterials().clone();
this.pvpReady = true; this.pvpReady = true;
this.scoreboardType = this.getWarzoneConfig().getScoreboardType(WarzoneConfig.SCOREBOARD);
if (scoreboardType == ScoreboardType.SWITCHING)
scoreboardType = ScoreboardType.LIFEPOOL;
} }
public static Warzone getZoneByName(String name) { public static Warzone getZoneByName(String name) {
@ -386,18 +390,7 @@ public class Warzone {
this.cakeThieves.clear(); this.cakeThieves.clear();
if (this.getScoreboardType() != ScoreboardType.NONE) { if (this.getScoreboardType() != ScoreboardType.NONE) {
this.scoreboard = Bukkit.getScoreboardManager().getNewScoreboard(); this.scoreboard = Bukkit.getScoreboardManager().getNewScoreboard();
scoreboard.registerNewObjective(this.getScoreboardType().getDisplayName(), "dummy"); this.updateScoreboard();
Objective obj = scoreboard.getObjective(this.getScoreboardType().getDisplayName());
Validate.isTrue(obj.isModifiable(), "Cannot modify players' scores on the " + this.name + " scoreboard.");
for (Team team : this.getTeams()) {
String teamName = team.getKind().getColor() + team.getName() + ChatColor.RESET;
if (this.getScoreboardType() == ScoreboardType.POINTS) {
obj.getScore(teamName).setScore(team.getPoints());
} else if (this.getScoreboardType() == ScoreboardType.LIFEPOOL) {
obj.getScore(teamName).setScore(team.getRemainingLives());
}
}
obj.setDisplaySlot(DisplaySlot.SIDEBAR);
for (Team team : this.getTeams()) { for (Team team : this.getTeams()) {
for (Player player : team.getPlayers()) { for (Player player : team.getPlayers()) {
player.setScoreboard(scoreboard); player.setScoreboard(scoreboard);
@ -1117,16 +1110,60 @@ public class Warzone {
if (attackerTeam.getTeamConfig().resolveBoolean(TeamConfig.KILLSTREAK)) { if (attackerTeam.getTeamConfig().resolveBoolean(TeamConfig.KILLSTREAK)) {
War.war.getKillstreakReward().rewardPlayer(attacker, this.getKillCount(attacker.getName())); War.war.getKillstreakReward().rewardPlayer(attacker, this.getKillCount(attacker.getName()));
} }
if (this.getScoreboard() != null && this.getScoreboardType() == ScoreboardType.TOPKILLS) { this.updateScoreboard();
Objective obj = this.getScoreboard().getObjective("Top kills");
obj.getScore(attacker.getName()).setScore(this.getKillCount(attacker.getName()));
}
if (defenderTeam.getTeamConfig().resolveBoolean(TeamConfig.INVENTORYDROP)) { if (defenderTeam.getTeamConfig().resolveBoolean(TeamConfig.INVENTORYDROP)) {
dropItems(defender.getLocation(), defender.getInventory().getContents()); dropItems(defender.getLocation(), defender.getInventory().getContents());
dropItems(defender.getLocation(), defender.getInventory().getArmorContents()); dropItems(defender.getLocation(), defender.getInventory().getArmorContents());
} }
this.handleDeath(defender); this.handleDeath(defender);
} }
public void updateScoreboard() {
if (this.getScoreboardType() == ScoreboardType.NONE)
return;
if (this.getScoreboard() == null)
return;
if (this.scoreboard.getObjective(this.getScoreboardType().getDisplayName()) == null) {
for (String entry : this.scoreboard.getEntries()) {
this.scoreboard.resetScores(entry);
}
this.scoreboard.clearSlot(DisplaySlot.SIDEBAR);
for (Objective obj : this.scoreboard.getObjectives()) {
obj.unregister();
}
scoreboard.registerNewObjective(this.getScoreboardType().getDisplayName(), "dummy");
Objective obj = scoreboard.getObjective(this.getScoreboardType().getDisplayName());
Validate.isTrue(obj.isModifiable(), "Cannot modify players' scores on the " + this.name + " scoreboard.");
obj.setDisplaySlot(DisplaySlot.SIDEBAR);
}
switch (this.getScoreboardType()) {
case POINTS:
for (Team team : this.getTeams()) {
String teamName = team.getKind().getColor() + team.getName() + ChatColor.RESET;
this.getScoreboard().getObjective(DisplaySlot.SIDEBAR).getScore(teamName).setScore(team.getPoints());
}
break;
case LIFEPOOL:
for (Team team : this.getTeams()) {
String teamName = team.getKind().getColor() + team.getName() + ChatColor.RESET;
this.getScoreboard().getObjective(DisplaySlot.SIDEBAR).getScore(teamName).setScore(team.getRemainingLives());
}
break;
case TOPKILLS:
for (Player player : this.getPlayers()) {
this.getScoreboard().getObjective(DisplaySlot.SIDEBAR).getScore(player.getName()).setScore(this.getKillCount(player.getName()));
}
break;
case PLAYERCOUNT:
for (Team team : this.getTeams()) {
String teamName = team.getKind().getColor() + team.getName() + ChatColor.RESET;
this.getScoreboard().getObjective(DisplaySlot.SIDEBAR).getScore(teamName).setScore(team.getPlayers().size());
}
break;
default:
break;
}
}
/** /**
* Handle death messages before passing to {@link #handleDeath(Player)} * Handle death messages before passing to {@link #handleDeath(Player)}
@ -1831,7 +1868,17 @@ public class Warzone {
} }
public ScoreboardType getScoreboardType() { public ScoreboardType getScoreboardType() {
return this.getWarzoneConfig().getScoreboardType(WarzoneConfig.SCOREBOARD); return scoreboardType;
}
/**
* Sets the TEMPORARY scoreboard type for use in this warzone.
* This type will NOT be persisted in the Warzone config.
*
* @param scoreboardType temporary scoreboard type
*/
public void setScoreboardType(ScoreboardType scoreboardType) {
this.scoreboardType = scoreboardType;
} }
public boolean hasKillCount(String player) { public boolean hasKillCount(String player) {

View File

@ -5,18 +5,15 @@ public enum ScoreboardType {
NONE(null), NONE(null),
POINTS("Points"), POINTS("Points"),
LIFEPOOL("Lifepool"), LIFEPOOL("Lifepool"),
TOPKILLS("Top kills"); TOPKILLS("Top kills"),
PLAYERCOUNT("Player count"),
SWITCHING("Switching");
private final String displayName; private final String displayName;
private ScoreboardType(String displayName) { ScoreboardType(String displayName) {
this.displayName = displayName; this.displayName = displayName;
} }
@Override
public String toString() {
return super.toString().toLowerCase();
}
public static ScoreboardType getFromString(String string) { public static ScoreboardType getFromString(String string) {
for (ScoreboardType boardMode : ScoreboardType.values()) { for (ScoreboardType boardMode : ScoreboardType.values()) {
if (string.toLowerCase().equals(boardMode.toString())) { if (string.toLowerCase().equals(boardMode.toString())) {
@ -27,6 +24,11 @@ public enum ScoreboardType {
return ScoreboardType.NONE; return ScoreboardType.NONE;
} }
@Override
public String toString() {
return super.toString().toLowerCase();
}
public String getDisplayName() { public String getDisplayName() {
return displayName; return displayName;
} }

View File

@ -0,0 +1,44 @@
package com.tommytony.war.job;
import com.tommytony.war.War;
import com.tommytony.war.Warzone;
import com.tommytony.war.config.ScoreboardType;
import com.tommytony.war.config.WarzoneConfig;
import org.bukkit.scheduler.BukkitRunnable;
/**
* Switches scoreboards periodically
* Github #790
*/
public class ScoreboardSwitchTimer extends BukkitRunnable {
@Override
public void run() {
if (!War.war.isLoaded()) {
return;
}
for (Warzone zone : War.war.getEnabledWarzones()) {
if (zone.getWarzoneConfig().getScoreboardType(WarzoneConfig.SCOREBOARD) == ScoreboardType.SWITCHING) {
switch (zone.getScoreboardType()) {
case SWITCHING:
zone.setScoreboardType(ScoreboardType.POINTS);
break;
case POINTS:
zone.setScoreboardType(ScoreboardType.LIFEPOOL);
break;
case LIFEPOOL:
zone.setScoreboardType(ScoreboardType.TOPKILLS);
break;
case TOPKILLS:
zone.setScoreboardType(ScoreboardType.PLAYERCOUNT);
break;
case PLAYERCOUNT:
zone.setScoreboardType(ScoreboardType.POINTS);
break;
default:
break;
}
zone.updateScoreboard();
}
}
}
}