mirror of https://github.com/taoneill/war.git
Add base for configurable KS rewards. Fixes gh-506
Killstreak rewards can be configured in the set.war.killstreak section of war.yml. Rewards will only be applied to players if the team/warzone has KILLSTREAK set to true. The configuration section will get populated on generation of war.yml, or may be manually added to older configurations. Currently the system supports messaging the entire warzone and just the attacker. It only supports rewards of items and health at the moment; more are expected to arrive. This commit also moves XPKILLMETER into the team-specific section of the config.
This commit is contained in:
parent
c66120c4fa
commit
17aef5e162
|
@ -29,6 +29,7 @@ import com.tommytony.war.command.WarCommandHandler;
|
|||
import com.tommytony.war.config.FlagReturn;
|
||||
import com.tommytony.war.config.InventoryBag;
|
||||
import com.tommytony.war.config.ScoreboardType;
|
||||
import com.tommytony.war.config.KillstreakReward;
|
||||
import com.tommytony.war.config.TeamConfig;
|
||||
import com.tommytony.war.config.TeamConfigBag;
|
||||
import com.tommytony.war.config.TeamKind;
|
||||
|
@ -96,6 +97,7 @@ public class War extends JavaPlugin {
|
|||
private final List<String> killerVerbs = new ArrayList<String>();
|
||||
|
||||
private final InventoryBag defaultInventories = new InventoryBag();
|
||||
private KillstreakReward killstreakReward;
|
||||
|
||||
private final WarConfigBag warConfig = new WarConfigBag();
|
||||
private final WarzoneConfigBag warzoneDefaultConfig = new WarzoneConfigBag();
|
||||
|
@ -204,7 +206,9 @@ public class War extends JavaPlugin {
|
|||
teamDefaultConfig.put(TeamConfig.SPAWNSTYLE, TeamSpawnStyle.SMALL);
|
||||
teamDefaultConfig.put(TeamConfig.TEAMSIZE, 10);
|
||||
teamDefaultConfig.put(TeamConfig.PERMISSION, "war.player");
|
||||
|
||||
teamDefaultConfig.put(TeamConfig.XPKILLMETER, false);
|
||||
teamDefaultConfig.put(TeamConfig.KILLSTREAK, false);
|
||||
|
||||
this.getDefaultInventories().clearLoadouts();
|
||||
HashMap<Integer, ItemStack> defaultLoadout = new HashMap<Integer, ItemStack>();
|
||||
|
||||
|
@ -235,6 +239,7 @@ public class War extends JavaPlugin {
|
|||
|
||||
this.getCommandWhitelist().add("who");
|
||||
this.getZoneMakerNames().add("tommytony");
|
||||
this.setKillstreakReward(new KillstreakReward());
|
||||
|
||||
// Add constants
|
||||
this.getDeadlyAdjectives().clear();
|
||||
|
@ -1232,4 +1237,12 @@ public class War extends JavaPlugin {
|
|||
public boolean isTagServer() {
|
||||
return tagServer;
|
||||
}
|
||||
|
||||
public KillstreakReward getKillstreakReward() {
|
||||
return killstreakReward;
|
||||
}
|
||||
|
||||
public void setKillstreakReward(KillstreakReward killstreakReward) {
|
||||
this.killstreakReward = killstreakReward;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,96 @@
|
|||
package com.tommytony.war.config;
|
||||
|
||||
import com.tommytony.war.Team;
|
||||
import com.tommytony.war.War;
|
||||
import com.tommytony.war.Warzone;
|
||||
import java.text.MessageFormat;
|
||||
import java.util.Map;
|
||||
import org.apache.commons.lang.Validate;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.configuration.MemoryConfiguration;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
/**
|
||||
* Manage rewards for certain killstreaks.
|
||||
*
|
||||
* @author cmastudios
|
||||
*/
|
||||
public class KillstreakReward {
|
||||
|
||||
private ConfigurationSection section;
|
||||
|
||||
/**
|
||||
* Creates a new killstreak reward class with default options.
|
||||
*/
|
||||
public KillstreakReward() {
|
||||
section = new MemoryConfiguration();
|
||||
section.set("3.privmsg", "You have been rewarded with some health for your kills.");
|
||||
section.set("3.reward.health", 8);
|
||||
section.set("5.message", "{0} is on a &ckillstreak&f! 5 kills this life.");
|
||||
section.set("5.privmsg", "You have received some items for your kills.");
|
||||
section.set("5.reward.item.id", 262);
|
||||
section.set("5.reward.item.damage", (short) 0);
|
||||
section.set("5.reward.item.amount", 15);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new killstreak reward class with options from the provided
|
||||
* config.
|
||||
*
|
||||
* @param section Section to load killstreak options from, such as
|
||||
* set.war.killstreak
|
||||
*/
|
||||
public KillstreakReward(ConfigurationSection section) {
|
||||
this.section = section;
|
||||
}
|
||||
|
||||
/**
|
||||
* Rewards a player for their current killstreak. The player must be in a
|
||||
* warzone.
|
||||
*
|
||||
* @param player Player to reward
|
||||
* @param kills Amount of kills to reward for
|
||||
*/
|
||||
public void rewardPlayer(Player player, int kills) {
|
||||
Warzone zone = Warzone.getZoneByPlayerName(player.getName());
|
||||
Team playerTeam = Team.getTeamByPlayerName(player.getName());
|
||||
Validate.notNull(zone, "Cannot reward player if they are not in a warzone");
|
||||
Validate.notNull(playerTeam, "Cannot reward player if they are not in a team");
|
||||
if (section.contains(Integer.toString(kills))) {
|
||||
ConfigurationSection killSection = section.getConfigurationSection(Integer.toString(kills));
|
||||
if (killSection.contains("message")) {
|
||||
final String playerName = playerTeam.getKind().getColor() + player.getName() + ChatColor.WHITE;
|
||||
final String message = ChatColor.translateAlternateColorCodes('&', MessageFormat.format(killSection.getString("message"), playerName));
|
||||
for (Team team : zone.getTeams()) {
|
||||
team.teamcast(message);
|
||||
}
|
||||
}
|
||||
if (killSection.contains("privmsg")) {
|
||||
War.war.msg(player, ChatColor.translateAlternateColorCodes('&', killSection.getString("privmsg")));
|
||||
}
|
||||
if (killSection.contains("reward.health")) {
|
||||
double health = player.getHealth() + killSection.getInt("reward.health");
|
||||
player.setHealth(health > 20 ? 20 : health); // Grant up to full health only
|
||||
}
|
||||
if (killSection.contains("reward.item")) {
|
||||
player.getInventory().addItem(this.assembleItemStack(killSection.getConfigurationSection("reward.item")));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private ItemStack assembleItemStack(ConfigurationSection itemSection) {
|
||||
int type = itemSection.getInt("id");
|
||||
int amount = itemSection.getInt("amount");
|
||||
short damage = (short) itemSection.getInt("damage");
|
||||
return new ItemStack(type, amount, damage);
|
||||
}
|
||||
|
||||
public void saveTo(ConfigurationSection section) {
|
||||
Map<String, Object> values = this.section.getValues(true);
|
||||
for (Map.Entry<String, Object> entry : values.entrySet()) {
|
||||
section.set(entry.getKey(), entry.getValue());
|
||||
}
|
||||
}
|
||||
}
|
|
@ -13,7 +13,9 @@ public enum TeamConfig {
|
|||
SATURATION (Integer.class),
|
||||
SPAWNSTYLE (TeamSpawnStyle.class),
|
||||
TEAMSIZE (Integer.class),
|
||||
PERMISSION (String.class);
|
||||
PERMISSION (String.class),
|
||||
XPKILLMETER (Boolean.class),
|
||||
KILLSTREAK (Boolean.class);
|
||||
|
||||
private final Class<?> configType;
|
||||
|
||||
|
|
|
@ -174,15 +174,14 @@ public class WarEntityListener implements Listener {
|
|||
// }
|
||||
// }
|
||||
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.addKillCount(a.getName(), 1);
|
||||
if (attackerTeam.getTeamConfig().resolveBoolean(TeamConfig.XPKILLMETER)) {
|
||||
a.setLevel(defenderWarzone.getKillCount(a.getName()));
|
||||
}
|
||||
if (attackerTeam.getTeamConfig().resolveBoolean(TeamConfig.KILLSTREAK)) {
|
||||
War.war.getKillstreakReward().rewardPlayer(a, defenderWarzone.getKillCount(a.getName()));
|
||||
}
|
||||
}
|
||||
if (attacker.getEntityId() != defender.getEntityId() && defenderWarzone.getWarzoneConfig().getBoolean(WarzoneConfig.XPKILLMETER)) {
|
||||
a.setLevel(defenderWarzone.getKillCount(a.getName()));
|
||||
}
|
||||
|
||||
if (!defenderWarzone.getWarzoneConfig().getBoolean(WarzoneConfig.REALDEATHS)) {
|
||||
|
|
|
@ -234,14 +234,15 @@ 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)) {
|
||||
Team team = Team.getTeamByPlayerName(player.getName());
|
||||
if (team != null && event.getAction() == Action.RIGHT_CLICK_BLOCK && event.getClickedBlock().getType() == Material.ENCHANTMENT_TABLE && team.getTeamConfig().resolveBoolean(TeamConfig.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)) {
|
||||
if (team != null && event.getAction() == Action.RIGHT_CLICK_BLOCK && event.getClickedBlock().getType() == Material.ANVIL && team.getTeamConfig().resolveBoolean(TeamConfig.XPKILLMETER)) {
|
||||
event.setCancelled(true);
|
||||
War.war.badMsg(player, "Can't use anvils in this warzone!");
|
||||
if (zone.getAuthors().contains(player.getName())) {
|
||||
|
@ -1005,8 +1006,8 @@ 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)) {
|
||||
Team team = Team.getTeamByPlayerName(event.getPlayer().getName());
|
||||
if (team != null && team.getTeamConfig().resolveBoolean(TeamConfig.XPKILLMETER)) {
|
||||
event.setAmount(0);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,6 +14,7 @@ import org.bukkit.inventory.ItemStack;
|
|||
|
||||
import com.tommytony.war.War;
|
||||
import com.tommytony.war.Warzone;
|
||||
import com.tommytony.war.config.KillstreakReward;
|
||||
import com.tommytony.war.job.RestoreYmlWarhubJob;
|
||||
import com.tommytony.war.job.RestoreYmlWarzonesJob;
|
||||
import com.tommytony.war.structure.WarHub;
|
||||
|
@ -98,6 +99,10 @@ public class WarYmlMapper {
|
|||
War.war.log("Failed to schedule warhub-restore job. War hub was not loaded.", Level.WARNING);
|
||||
}
|
||||
}
|
||||
|
||||
// Killstreak config
|
||||
ConfigurationSection killstreakSection = warRootSection.getConfigurationSection("war.killstreak");
|
||||
War.war.setKillstreakReward(new KillstreakReward(killstreakSection));
|
||||
}
|
||||
|
||||
public static void save() {
|
||||
|
@ -189,6 +194,9 @@ public class WarYmlMapper {
|
|||
VolumeMapper.save(hub.getVolume(), "");
|
||||
}
|
||||
|
||||
ConfigurationSection killstreakSection = warRootSection.createSection("war.killstreak");
|
||||
War.war.getKillstreakReward().saveTo(killstreakSection);
|
||||
|
||||
// Save to disk
|
||||
File warConfigFile = new File(War.war.getDataFolder().getPath() + "/war.yml");
|
||||
try {
|
||||
|
|
Loading…
Reference in New Issue