Closes gh-12. Added rewards. Default reward when score cap is reach is one cake. Rewards can be customized just like loadouts. Added runnable task that will help to make loot drops configurable in the future. Added defaultSpawnStyle to War config.

This commit is contained in:
taoneill 2011-02-09 23:50:35 -05:00
parent f9d33cf803
commit 662c0622a0
6 changed files with 158 additions and 21 deletions

View File

@ -1,6 +1,18 @@
package bukkit.tommytony.war;
import org.bukkit.*;
import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.bukkit.ChatColor;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.Server;
import org.bukkit.World;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.block.BlockState;
@ -16,6 +28,7 @@ import org.bukkit.plugin.PluginLoader;
import org.bukkit.plugin.PluginManager;
import org.bukkit.plugin.java.JavaPlugin;
import com.nijikokun.bukkit.Permissions.Permissions;
import com.tommytony.war.Monument;
import com.tommytony.war.Team;
import com.tommytony.war.TeamChatColors;
@ -28,16 +41,6 @@ import com.tommytony.war.mappers.VolumeMapper;
import com.tommytony.war.mappers.WarMapper;
import com.tommytony.war.mappers.WarzoneMapper;
import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;
import com.nijikokun.bukkit.Permissions.Permissions;
/**
*
* @author tommytony
@ -70,7 +73,12 @@ public class War extends JavaPlugin {
private int defaultScoreCap = 10;
private boolean defaultBlockHeads = false;
private boolean defaultDropLootOnDeath = false;
private String defaultSpawnStyle = TeamSpawnStyles.BIG;
private final HashMap<Integer, ItemStack> defaultReward = new HashMap<Integer, ItemStack>();
private boolean pvpInZonesOnly = false;
private WarHub warHub;
public void onDisable() {
@ -122,6 +130,7 @@ public class War extends JavaPlugin {
this.defaultLifepool = 7;
this.defaultFriendlyFire = false;
this.defaultAutoAssignOnly = false;
this.getDefaultReward().put(0, new ItemStack(Material.CAKE, 1));
WarMapper.load(this);
this.info("Done. War v"+ desc.getVersion() + " is on.");
}
@ -448,7 +457,7 @@ public class War extends JavaPlugin {
team.setTeamFlag(player.getLocation());
Location playerLoc = player.getLocation();
player.teleportTo(new Location(playerLoc.getWorld(),
playerLoc.getBlockX(), playerLoc.getBlockY() + 1, playerLoc.getBlockZ()));
playerLoc.getBlockX()+1, playerLoc.getBlockY(), playerLoc.getBlockZ()+1));
player.sendMessage(this.str("Team " + name + " flag moved."));
WarzoneMapper.save(this, warzone, false);
}
@ -991,7 +1000,7 @@ public class War extends JavaPlugin {
private boolean updateZoneFromNamedParams(Warzone warzone, String[] arguments) {
try {
Map<String,String> namedParams = new HashMap();
Map<String,String> namedParams = new HashMap<String,String>();
for(String namedPair : arguments) {
String[] pairSplit = namedPair.split(":");
if(pairSplit.length == 2) {
@ -1045,7 +1054,7 @@ public class War extends JavaPlugin {
private boolean updateFromNamedParams(String[] arguments) {
try {
Map<String,String> namedParams = new HashMap();
Map<String,String> namedParams = new HashMap<String,String>();
for(String namedPair : arguments) {
String[] pairSplit = namedPair.split(":");
if(pairSplit.length == 2) {
@ -1077,10 +1086,20 @@ public class War extends JavaPlugin {
String onOff = namedParams.get("pvpinzonesonly");
setPvpInZonesOnly(onOff.equals("on") || onOff.equals("true"));
}
if(namedParams.containsKey("blockHeads")){
String onOff = namedParams.get("blockHeads");
if(namedParams.containsKey("blockheads")){
String onOff = namedParams.get("blockheads");
setDefaultBlockHeads(onOff.equals("on") || onOff.equals("true"));
}
if(namedParams.containsKey("spawnstyle")){
String spawnStyle = namedParams.get("spawnstyle").toLowerCase();
if(spawnStyle.equals(TeamSpawnStyles.SMALL)) {
setDefaultSpawnStyle(spawnStyle);
} else if (spawnStyle.equals(TeamSpawnStyles.FLAT)){
setDefaultSpawnStyle(spawnStyle);
} else {
setDefaultSpawnStyle(TeamSpawnStyles.BIG);
}
}
// if(namedParams.containsKey("dropLootOnDeath")){
// String onOff = namedParams.get("dropLootOnDeath");
// setDefaultDropLootOnDeath(onOff.equals("on") || onOff.equals("true"));
@ -1381,4 +1400,16 @@ public class War extends JavaPlugin {
return defaultDropLootOnDeath;
}
public void setDefaultSpawnStyle(String defaultSpawnStyle) {
this.defaultSpawnStyle = defaultSpawnStyle;
}
public String getDefaultSpawnStyle() {
return defaultSpawnStyle;
}
public HashMap<Integer, ItemStack> getDefaultReward() {
return defaultReward;
}
}

View File

@ -17,6 +17,7 @@ import org.bukkit.event.entity.EntityListener;
import org.bukkit.event.entity.EntityDamageEvent.DamageCause;
import org.bukkit.event.player.PlayerMoveEvent;
import com.tommytony.war.LootDropperTask;
import com.tommytony.war.Team;
import com.tommytony.war.Warzone;
@ -41,9 +42,12 @@ public class WarEntityListener extends EntityListener {
if(team != null) {
Warzone zone = war.getPlayerTeamWarzone(player.getName());
handleDeath(player, zone, team);
if(!zone.isDropLootOnDeath()) {
event.getDrops().clear(); // no loot
}
// if(zone.isDropLootOnDeath()) {
// war.getServer().getScheduler().scheduleAsyncDelayedTask(war,
// new LootDropperTask(player.getLocation(), event.getDrops()),
// 750);
// }
event.getDrops().clear(); // no loot
}
}
}

View File

@ -0,0 +1,23 @@
package com.tommytony.war;
import java.util.List;
import org.bukkit.Location;
import org.bukkit.inventory.ItemStack;
public class LootDropperTask implements Runnable {
private final List<ItemStack> drop;
private final Location location;
public LootDropperTask(Location location, List<ItemStack> drop) {
this.location = location;
this.drop = drop;
}
public void run() {
for(ItemStack item : drop) {
location.getWorld().dropItemNaturally(location, item);
}
}
}

View File

@ -41,6 +41,7 @@ public class Warzone {
private int teamCap = 5;
private int scoreCap = 5;
private String spawnStyle = TeamSpawnStyles.BIG;
private HashMap<Integer, ItemStack> reward = new HashMap<Integer, ItemStack>();
private HashMap<String, InventoryStash> inventories = new HashMap<String, InventoryStash>();
private HashMap<String, Team> flagThieves = new HashMap<String, Team>();
@ -952,7 +953,12 @@ public class Warzone {
}
tp.teleportTo(this.getTeleport());
}
if(winnersStr.contains(t.getName())) {
// give reward
for(Integer slot : getReward().keySet()){
tp.getInventory().addItem(getReward().get(slot));
}
}
}
t.setPoints(0);
t.getPlayers().clear(); // empty the team
@ -991,5 +997,13 @@ public class Warzone {
return spawnStyle;
}
public void setReward(HashMap<Integer, ItemStack> reward) {
this.reward = reward;
}
public HashMap<Integer, ItemStack> getReward() {
return reward;
}
}

View File

@ -9,6 +9,7 @@ import org.bukkit.inventory.ItemStack;
import bukkit.tommytony.war.War;
import com.tommytony.war.TeamSpawnStyles;
import com.tommytony.war.WarHub;
import com.tommytony.war.Warzone;
import com.tommytony.war.volumes.Volume;
@ -110,6 +111,33 @@ public class WarMapper {
// defaultBlockHeads
war.setDefaultBlockHeads(warConfig.getBoolean("defaultBlockHeads"));
// defaultSpawnStyle
String spawnStyle = warConfig.getString("defaultspawnStyle");
if(spawnStyle != null && !spawnStyle.equals("")){
spawnStyle = spawnStyle.toLowerCase();
if(spawnStyle.equals(TeamSpawnStyles.SMALL)) {
war.setDefaultSpawnStyle(spawnStyle);
} else if (spawnStyle.equals(TeamSpawnStyles.FLAT)){
war.setDefaultSpawnStyle(spawnStyle);
}
// default is already initialized to BIG (see Warzone)
}
// defaultReward
String defaultRewardStr = warConfig.getString("defaultReward");
if(defaultRewardStr != null && !defaultRewardStr.equals("")) {
String[] defaultRewardStrSplit = defaultRewardStr.split(";");
war.getDefaultReward().clear();
for(String itemStr : defaultRewardStrSplit) {
if(itemStr != null && !itemStr.equals("")) {
String[] itemStrSplit = itemStr.split(",");
ItemStack item = new ItemStack(Integer.parseInt(itemStrSplit[0]),
Integer.parseInt(itemStrSplit[1]));
war.getDefaultReward().put(Integer.parseInt(itemStrSplit[2]), item);
}
}
}
// defaultDropLootOnDeath
//war.setDefaultDropLootOnDeath(warConfig.getBoolean("defaultDropLootOnDeath"));
@ -200,6 +228,18 @@ public class WarMapper {
// defaultBlockHeads
warConfig.setBoolean("defaultBlockHeads", war.isDefaultBlockHeads());
// spawnStyle
warConfig.setString("spawnStyle", war.getDefaultSpawnStyle());
// defaultReward
String defaultRewardStr = "";
HashMap<Integer, ItemStack> rewardItems = war.getDefaultReward();
for(Integer slot : rewardItems.keySet()) {
ItemStack item = items.get(slot);
defaultRewardStr += item.getTypeId() + "," + item.getAmount() + "," + slot + ";";
}
warConfig.setString("defaultReward", defaultRewardStr);
// defaultDropLootOnDeath
//warConfig.setBoolean("defaultDropLootOnDeath", war.isDefaultDropLootOnDeath());

View File

@ -193,6 +193,21 @@ public class WarzoneMapper {
// default is already initialized to BIG (see Warzone)
}
// reward
String rewardStr = warzoneConfig.getString("reward");
if(rewardStr != null && !rewardStr.equals("")) {
String[] rewardStrSplit = rewardStr.split(";");
warzone.getReward().clear();
for(String itemStr : rewardStrSplit) {
if(itemStr != null && !itemStr.equals("")) {
String[] itemStrSplit = itemStr.split(",");
ItemStack item = new ItemStack(Integer.parseInt(itemStrSplit[0]),
Integer.parseInt(itemStrSplit[1]));
warzone.getReward().put(Integer.parseInt(itemStrSplit[2]), item);
}
}
}
// dropLootOnDeath
//warzone.setDropLootOnDeath(warzoneConfig.getBoolean("dropLootOnDeath"));
@ -365,6 +380,16 @@ public class WarzoneMapper {
// spawnStyle
warzoneConfig.setString("spawnStyle", warzone.getSpawnStyle());
// reward
String rewardStr = "";
HashMap<Integer, ItemStack> rewardItems = warzone.getReward();
for(Integer slot : rewardItems.keySet()) {
ItemStack item = items.get(slot);
rewardStr += item.getTypeId() + "," + item.getAmount() + "," + slot + ";";
}
warzoneConfig.setString("reward", rewardStr);
// defaultDropLootOnDeath
//warzoneConfig.setBoolean("dropLootOnDeath", warzone.isDropLootOnDeath());