Fixes gh-611, gh-612 - Add kill count system and kill meters with XP.

The killstreak counter shows a message if the player has more than 5
kills. I have also added an example reward system with points, but did not
enable it yet (needs discussion).

Through the warzone option xpkillmeter the XP level will get updated with
your current kill streak amount. This gets reset every time you die and
is added to every time you kill a player. If this option is enabled,
players cannot gain XP in the warzone.
This commit is contained in:
cmastudios 2013-03-07 19:26:19 -06:00
parent 2738d2e358
commit c66120c4fa
5 changed files with 73 additions and 2 deletions

View File

@ -190,6 +190,7 @@ public class War extends JavaPlugin {
warzoneDefaultConfig.put(WarzoneConfig.JOINMIDBATTLE, true);
warzoneDefaultConfig.put(WarzoneConfig.AUTOJOIN, false);
warzoneDefaultConfig.put(WarzoneConfig.SCOREBOARD, ScoreboardType.NONE);
warzoneDefaultConfig.put(WarzoneConfig.XPKILLMETER, false);
teamDefaultConfig.put(TeamConfig.FLAGMUSTBEHOME, true);
teamDefaultConfig.put(TeamConfig.FLAGPOINTSONLY, false);

View File

@ -85,6 +85,7 @@ public class Warzone {
private HashMap<String, Cake> cakeThieves = new HashMap<String, 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>();
private final List<Player> respawn = new ArrayList<Player>();
private final List<String> reallyDeadFighters = new ArrayList<String>();
@ -421,8 +422,13 @@ public class Warzone {
player.setFireTicks(0); //this works fine here, why put it in LoudoutResetJob...? I'll keep it over there though
player.getOpenInventory().close();
player.setLevel(0);
player.setExp(0);
player.getInventory().clear();
this.setKillCount(player.getName(), 0);
if (player.getGameMode() == GameMode.CREATIVE) {
// Players are always in survival mode in warzones
player.setGameMode(GameMode.SURVIVAL);
@ -1563,4 +1569,25 @@ public class Warzone {
public ScoreboardType getScoreboardType() {
return this.getWarzoneConfig().getScoreboardType(WarzoneConfig.SCOREBOARD);
}
public boolean hasKillCount(String player) {
return killCount.containsKey(player);
}
public int getKillCount(String player) {
return killCount.get(player);
}
public void setKillCount(String player, int totalKills) {
if (totalKills < 0) {
throw new IllegalArgumentException("Amount of kills to set cannot be a negative number.");
}
killCount.put(player, totalKills);
}
public void addKillCount(String player, int amount) {
if (amount < 0) {
throw new IllegalArgumentException("Amount of kills to add cannot be a negative number.");
}
killCount.put(player, killCount.get(player) + amount);
}
}

View File

@ -22,7 +22,8 @@ public enum WarzoneConfig {
UNBREAKABLE (Boolean.class),
JOINMIDBATTLE (Boolean.class),
AUTOJOIN (Boolean.class),
SCOREBOARD (ScoreboardType.class)
SCOREBOARD (ScoreboardType.class),
XPKILLMETER (Boolean.class)
;

View File

@ -165,8 +165,25 @@ public class WarEntityListener implements Listener {
team.teamcast(killMessage);
}
}
// this is just an idea for further discussion
// if (defenderWarzone.getKillCount(d.getName()) >= 5) {
// defenderTeam.addPoint();
// for (Team team : defenderWarzone.getTeams()) {
// team.teamcast(defenderTeam.getKind().getColor() + d.getName() + ChatColor.WHITE + " killed " + attackerTeam.getKind().getColor() + a.getName()
// + ChatColor.WHITE + " and scored an extra point for their team.");
// }
// }
defenderWarzone.handleDeath(d);
defenderWarzone.addKillCount(a.getName(), 1);
if (attacker.getEntityId() != defender.getEntityId() && defenderWarzone.getKillCount(a.getName()) >= 5) {
for (Team team : defenderWarzone.getTeams()) {
team.teamcast(attackerTeam.getKind().getColor() + a.getName() + ChatColor.WHITE + " is on a " + ChatColor.RED + "killstreak"
+ ChatColor.WHITE + "! (" + defenderWarzone.getKillCount(a.getName()) + " kills)");
}
}
if (attacker.getEntityId() != defender.getEntityId() && defenderWarzone.getWarzoneConfig().getBoolean(WarzoneConfig.XPKILLMETER)) {
a.setLevel(defenderWarzone.getKillCount(a.getName()));
}
if (!defenderWarzone.getWarzoneConfig().getBoolean(WarzoneConfig.REALDEATHS)) {
// fast respawn, don't really die

View File

@ -46,6 +46,7 @@ import com.tommytony.war.volume.Volume;
import java.util.ArrayList;
import java.util.Iterator;
import org.bukkit.event.player.PlayerTeleportEvent;
import org.bukkit.event.player.PlayerExpChangeEvent;
/**
* @author tommytony, Tim Düsterhus
@ -233,6 +234,20 @@ public class WarPlayerListener implements Listener {
event.setCancelled(true);
War.war.badMsg(player, "Can't use ender chests while playing in a warzone!");
}
if (zone != null && event.getAction() == Action.RIGHT_CLICK_BLOCK && event.getClickedBlock().getType() == Material.ENCHANTMENT_TABLE && zone.getWarzoneConfig().getBoolean(WarzoneConfig.XPKILLMETER)) {
event.setCancelled(true);
War.war.badMsg(player, "Can't use enchantment tables in this warzone!");
if (zone.getAuthors().contains(player.getName())) {
War.war.badMsg(player, "This is due to the xpkillmeter option being enabled.");
}
}
if (zone != null && event.getAction() == Action.RIGHT_CLICK_BLOCK && event.getClickedBlock().getType() == Material.ANVIL && zone.getWarzoneConfig().getBoolean(WarzoneConfig.XPKILLMETER)) {
event.setCancelled(true);
War.war.badMsg(player, "Can't use anvils in this warzone!");
if (zone.getAuthors().contains(player.getName())) {
War.war.badMsg(player, "This is due to the xpkillmeter option being enabled.");
}
}
}
}
@ -987,6 +1002,16 @@ public class WarPlayerListener implements Listener {
}
}
@EventHandler
public void onPlayerExpChange(PlayerExpChangeEvent event) {
if (War.war.isLoaded()) {
Warzone zone = Warzone.getZoneByPlayerName(event.getPlayer().getName());
if (zone != null && zone.getWarzoneConfig().getBoolean(WarzoneConfig.XPKILLMETER)) {
event.setAmount(0);
}
}
}
public void purgeLatestPositions() {
this.latestLocations.clear();
}