Added configurable airstrikes, based on work from @grinning.

This commit is contained in:
cmastudios 2013-06-01 00:54:11 -05:00
parent 26ec11f46c
commit 0dc7ac837f
3 changed files with 65 additions and 5 deletions

View File

@ -452,7 +452,9 @@ public class Warzone {
if (War.war.isSpoutServer()) {
SpoutManager.getPlayer(player).setTitle(team.getKind().getColor() + player.getName());
}
War.war.getKillstreakReward().getAirstrikePlayers().remove(player.getName());
final LoadoutResetJob job = new LoadoutResetJob(this, team, player, isFirstRespawn, false);
if (team.getTeamConfig().resolveInt(TeamConfig.RESPAWNTIMER) == 0 || isFirstRespawn) {
job.run();

View File

@ -1,14 +1,13 @@
package com.tommytony.war.config;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.tommytony.war.Team;
import com.tommytony.war.War;
import com.tommytony.war.Warzone;
import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.List;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import org.apache.commons.lang.Validate;
import org.bukkit.ChatColor;
import org.bukkit.Material;
@ -27,18 +26,20 @@ import org.bukkit.inventory.meta.ItemMeta;
public class KillstreakReward {
private ConfigurationSection section;
private Set<String> airstrikePlayers;
/**
* Creates a new killstreak reward class with default options.
*/
public KillstreakReward() {
section = new MemoryConfiguration();
this(new MemoryConfiguration());
section.set("3.privmsg", "You have been rewarded with some health for your kills.");
section.set("3.reward.health", 8);
section.set("4.reward.xp", 3);
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.points", 1);
section.set("5.reward.airstrike", true);
section.set("5.reward.items", ImmutableList.of(new ItemStack(Material.ARROW, 15), new ItemStack(Material.EGG)));
ItemStack sword = new ItemStack(Material.WOOD_SWORD);
sword.addEnchantment(Enchantment.DAMAGE_ALL, 2);
@ -59,6 +60,7 @@ public class KillstreakReward {
*/
public KillstreakReward(ConfigurationSection section) {
this.section = section;
this.airstrikePlayers = new HashSet();
}
/**
@ -126,6 +128,9 @@ public class KillstreakReward {
zone.getLobby().resetTeamGateSign(playerTeam);
}
}
if (killSection.getBoolean("reward.airstrike")) {
this.airstrikePlayers.add(player.getName());
}
}
}
@ -135,4 +140,8 @@ public class KillstreakReward {
section.set(entry.getKey(), entry.getValue());
}
}
public Set<String> getAirstrikePlayers() {
return airstrikePlayers;
}
}

View File

@ -45,6 +45,12 @@ import com.tommytony.war.spout.SpoutDisplayer;
import com.tommytony.war.structure.Bomb;
import com.tommytony.war.utility.DeferredBlockReset;
import com.tommytony.war.utility.LoadoutSelection;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.LivingEntity;
import org.bukkit.event.entity.ProjectileHitEvent;
import org.bukkit.event.entity.ProjectileLaunchEvent;
import org.bukkit.metadata.FixedMetadataValue;
import org.bukkit.util.Vector;
/**
* Handles Entity-Events
@ -607,4 +613,47 @@ public class WarEntityListener implements Listener {
}
}
@EventHandler
public void onProjectileHit(final ProjectileHitEvent event) {
if (!War.war.isLoaded()) {
return;
}
if (event.getEntityType() == EntityType.EGG) {
if (event.getEntity().hasMetadata("warAirstrike")) {
Location loc = event.getEntity().getLocation();
Warzone zone = Warzone.getZoneByLocation(loc);
if (zone == null) {
return;
}
Location tntPlace = new Location(loc.getWorld(), loc.getX(), Warzone.getZoneByLocation(loc).getVolume().getMaxY(), loc.getZ());
loc.getWorld().spawnEntity(tntPlace, EntityType.PRIMED_TNT);
loc.getWorld().spawnEntity(tntPlace.clone().add(new Vector(2, 0, 0)), EntityType.PRIMED_TNT);
loc.getWorld().spawnEntity(tntPlace.clone().add(new Vector(-2, 0, 0)), EntityType.PRIMED_TNT);
loc.getWorld().spawnEntity(tntPlace.clone().add(new Vector(0, 0, 2)), EntityType.PRIMED_TNT);
loc.getWorld().spawnEntity(tntPlace.clone().add(new Vector(0, 0, -2)), EntityType.PRIMED_TNT);
}
}
}
@EventHandler
public void onProjectileLaunch(final ProjectileLaunchEvent event) {
if (!War.war.isLoaded()) {
return;
}
if (event.getEntityType() == EntityType.EGG) {
LivingEntity shooter = event.getEntity().getShooter();
if (shooter instanceof Player) {
Player player = (Player) shooter;
Warzone zone = Warzone.getZoneByPlayerName(player.getName());
Team team = Team.getTeamByPlayerName(player.getName());
if (zone != null) {
if (War.war.getKillstreakReward().getAirstrikePlayers().remove(player.getName())) {
event.getEntity().setMetadata("warAirstrike", new FixedMetadataValue(War.war, true));
team.teamcast(String.format("%s called in an airstrike!", team.getKind().getColor() + player.getName() + ChatColor.WHITE));
}
}
}
}
}
}