Brought back all inventory code. Everything should be ported now. Needs more testing.

This commit is contained in:
taoneill 2011-01-10 01:52:22 -05:00
parent 9f53f0265e
commit 61ecb3b7ba
7 changed files with 57 additions and 121 deletions

View File

@ -1,6 +1,7 @@
package com.tommytony.war; package com.tommytony.war;
import org.bukkit.*; import org.bukkit.Location;
import org.bukkit.Material;
import com.tommytony.war.volumes.CenteredVolume; import com.tommytony.war.volumes.CenteredVolume;
import com.tommytony.war.volumes.Volume; import com.tommytony.war.volumes.Volume;
@ -27,7 +28,6 @@ public class Monument {
} }
public void addMonumentBlocks() { public void addMonumentBlocks() {
// TODO Auto-generated method stub
this.ownerTeam = null; this.ownerTeam = null;
int x = location.getBlockX(); int x = location.getBlockX();
int y = location.getBlockY(); int y = location.getBlockY();
@ -113,11 +113,11 @@ public class Monument {
return ownerTeam != null; return ownerTeam != null;
} }
public void ignite(Team team) { public void capture(Team team) {
ownerTeam = team; ownerTeam = team;
} }
public void smother() { public void uncapture() {
ownerTeam = null; ownerTeam = null;
@ -149,7 +149,6 @@ public class Monument {
} }
public Volume getVolume() { public Volume getVolume() {
// TODO Auto-generated method stub
return volume; return volume;
} }

View File

@ -19,12 +19,10 @@ public class Team {
private int remainingTickets; private int remainingTickets;
private int points = 0; private int points = 0;
private Volume volume; private Volume volume;
private final War war;
private final Warzone warzone; private final Warzone warzone;
private Material material; private Material material;
public Team(String name, Material material, Location teamSpawn, War war, Warzone warzone) { public Team(String name, Material material, Location teamSpawn, War war, Warzone warzone) {
this.war = war;
this.warzone = warzone; this.warzone = warzone;
this.setName(name); this.setName(name);
this.teamSpawn = teamSpawn; this.teamSpawn = teamSpawn;

View File

@ -170,7 +170,6 @@ public class War extends JavaPlugin {
} }
public String getName() { public String getName() {
// TODO Auto-generated method stub
return name; return name;
} }

View File

@ -3,12 +3,9 @@ package com.tommytony.war;
import java.util.List; import java.util.List;
import org.bukkit.Block; import org.bukkit.Block;
import org.bukkit.Material; import org.bukkit.BlockDamageLevel;
import org.bukkit.Player; import org.bukkit.Player;
import org.bukkit.event.block.BlockCanBuildEvent;
import org.bukkit.event.block.BlockDamagedEvent; import org.bukkit.event.block.BlockDamagedEvent;
import org.bukkit.event.block.BlockFromToEvent;
import org.bukkit.event.block.BlockIgniteEvent;
import org.bukkit.event.block.BlockListener; import org.bukkit.event.block.BlockListener;
import org.bukkit.event.block.BlockPlacedEvent; import org.bukkit.event.block.BlockPlacedEvent;
@ -29,115 +26,59 @@ public class WarBlockListener extends BlockListener {
Warzone zone = war.getPlayerWarzone(player.getName()); Warzone zone = war.getPlayerWarzone(player.getName());
if(team != null && block != null && zone != null if(team != null && block != null && zone != null
&& zone.isMonumentCenterBlock(block) && zone.isMonumentCenterBlock(block)
&& (block.getType() == Material.YellowFlower || block.getType() == Material.RedRose || block.getType() == Material.Sapling)) { && block.getType() == team.getMaterial()) {
Monument monument = zone.getMonumentFromCenterBlock(block); Monument monument = zone.getMonumentFromCenterBlock(block);
if(!monument.hasOwner()) { if(!monument.hasOwner()) {
monument.ignite(team); monument.capture(team);
List<Team> teams = zone.getTeams(); List<Team> teams = zone.getTeams();
for(Team t : teams) { for(Team t : teams) {
t.teamcast(war.str("Monument " + monument.getName() + " has been ignited by team " + team.getName() + ".")); t.teamcast(war.str("Monument " + monument.getName() + " has been captured by team " + team.getName() + "."));
} }
} else {
player.sendMessage(war.str("Monument must be smothered first."));
} }
} else {
player.sendMessage(war.str("You can't capture a monument without team block. Get one from your team spawn."));
event.setCancelled(true);
} }
} }
} }
public void onBlockDamaged(BlockDamagedEvent event) { public void onBlockDamaged(BlockDamagedEvent event) {
Player player = event.getPlayer(); Player player = event.getPlayer();
Block block = event.getBlock(); Block block = event.getBlock();
if(player != null && block != null) { if(player != null && block != null && event.getDamageLevel() == BlockDamageLevel.BROKEN) {
Warzone warzone = war.warzone(player.getLocation()); Warzone warzone = war.warzone(player.getLocation());
Team team = war.getPlayerTeam(player.getName());
if(warzone != null && war.getPlayerTeam(player.getName()) == null) { if(warzone != null && war.getPlayerTeam(player.getName()) == null) {
// can't actually destroy blocks in a warzone if not part of a team // can't actually destroy blocks in a warzone if not part of a team
player.sendMessage(war.str("Can't destroy part of a warzone if you're not in a team.")); player.sendMessage(war.str("Can't destroy part of a warzone if you're not in a team."));
// BUKKIT event.setCancelled(true);
// event.setCancelled(true);
} }
if(warzone != null && warzone.isImportantBlock(block)) { if(warzone != null && warzone.isImportantBlock(block)) {
player.sendMessage(war.str("Can't destroy this.")); if(team != null && team.getVolume().contains(block)) {
// BUKKIT if(player.getInventory().contains(team.getMaterial())) {
// event.setCancelled(true); player.sendMessage(war.str("You already have a " + team.getName() + " block."));
}
// let team members loot one block the spawn for monument captures
} else {
player.sendMessage(war.str("Can't destroy this."));
event.setCancelled(true);
}
} }
Team team = war.getPlayerTeam(player.getName());
if(team != null && block != null && warzone != null if(team != null && block != null && warzone != null
&& warzone.isMonumentCenterBlock(block)){ && warzone.isMonumentCenterBlock(block)
){
Monument monument = warzone.getMonumentFromCenterBlock(block); Monument monument = warzone.getMonumentFromCenterBlock(block);
if(monument.hasOwner()) { if(monument.hasOwner()) {
monument.smother(); monument.uncapture();
List<Team> teams = warzone.getTeams(); List<Team> teams = warzone.getTeams();
for(Team t : teams) { for(Team t : teams) {
t.teamcast(war.str("Monument " + monument.getName() + " has been smothered.")); t.teamcast(war.str("Team " + team.getName() + " loses control of monument " + monument.getName()));
} }
} }
} }
} }
} }
public void onBlockCanBuild(BlockCanBuildEvent event) {
// BUKKIT
// Block blockPlaced = event.getBlock();
//
// Warzone warzone = war.warzone(new Location(warblockPlaced.getX());
// if(warzone != null) {
// if(warzone.isImportantBlock(blockPlaced) || warzone.isImportantBlock(blockClicked)) {
// event.setCancelled(true);
// }
// }
}
public void onBlockFlow(BlockFromToEvent event) {
// Block block = null;
// Block blockTo = event.getBlock();
// Block blockFrom = event.getFromBlock();
// if(blockTo != null) {
// block = blockTo;
// } else if (blockFrom != null) {
// block = blockFrom;
// }
//
// if(block != null) {
// Warzone zone = war.warzone(new Location(block.getWorld(), block.getX(), block.getY(), block.getZ()));
// if(zone != null &&
// ((blockTo != null && zone.isMonumentCenterBlock(blockTo)
// || (blockFrom != null && zone.isMonumentCenterBlock(blockFrom))))) {
// Monument monument = null;
// if(blockTo != null) monument = zone.getMonumentFromCenterBlock(blockTo);
// if(monument == null && blockFrom != null) monument = zone.getMonumentFromCenterBlock(blockFrom);
// if(monument.hasOwner()) {
// monument.setOwnerTeam(null);
// List<Team> teams = zone.getTeams();
// for(Team team : teams) {
// team.teamcast(war.str("Monument " + monument.getName() + " has been smothered."));
// }
// }
// }
// }
}
public void onBlockIgnite(BlockIgniteEvent event) {
// BUKKIT
// Player player = event.getPlayer();
// Block block = event.getBlock();
// if(player != null) {
// Team team = war.getPlayerTeam(player.getName());
// Warzone zone = war.getPlayerWarzone(player.getName());
// if(team != null && block != null && zone != null && zone.isMonumentFirestone(block)) {
// Monument monument = zone.getMonumentForFirestone(block);
// if(!monument.hasOwner()) {
// monument.ignite(team);
// List<Team> teams = zone.getTeams();
// for(Team t : teams) {
// t.teamcast(war.str("Monument " + monument.getName() + " has been ignited by team " + team.getName() + "."));
// }
// } else {
// player.sendMessage(war.str("Monument must be smothered first."));
// }
// }
// }
}
} }

View File

@ -26,7 +26,6 @@ public class Warzone {
private Location teleport; private Location teleport;
private boolean friendlyFire; private boolean friendlyFire;
private War war;
private int lifePool; private int lifePool;
private HashMap<Integer, ItemStack> loadout; private HashMap<Integer, ItemStack> loadout;
@ -34,7 +33,6 @@ public class Warzone {
private World world; private World world;
public Warzone(War war, World world, String name) { public Warzone(War war, World world, String name) {
this.war = war;
this.world = world; this.world = world;
this.name = name; this.name = name;
this.friendlyFire = war.getDefaultFriendlyFire(); this.friendlyFire = war.getDefaultFriendlyFire();

View File

@ -104,7 +104,8 @@ public final class PropertiesFile {
* @return <code>map</code> - Simple Map HashMap of the entire <code>key=value</code> as <code>&lt;key (java.lang.String), value (java.lang.String)></code> * @return <code>map</code> - Simple Map HashMap of the entire <code>key=value</code> as <code>&lt;key (java.lang.String), value (java.lang.String)></code>
* @throws Exception If the properties file doesn't exist. * @throws Exception If the properties file doesn't exist.
*/ */
public Map<String, String> returnMap() throws Exception { @SuppressWarnings("unchecked")
public Map<String, String> returnMap() throws Exception {
return (Map<String, String>) props.clone(); return (Map<String, String>) props.clone();
} }

View File

@ -1,19 +1,20 @@
package com.tommytony.war.mappers; package com.tommytony.war.mappers;
import org.bukkit.*; import java.io.File;
import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import org.bukkit.ItemStack;
import org.bukkit.Location;
import org.bukkit.World;
import com.tommytony.war.Monument; import com.tommytony.war.Monument;
import com.tommytony.war.Team; import com.tommytony.war.Team;
import com.tommytony.war.TeamMaterials; import com.tommytony.war.TeamMaterials;
import com.tommytony.war.War; import com.tommytony.war.War;
import com.tommytony.war.Warzone; import com.tommytony.war.Warzone;
import com.tommytony.war.volumes.CenteredVolume;
import com.tommytony.war.volumes.VerticalVolume; import com.tommytony.war.volumes.VerticalVolume;
import com.tommytony.war.volumes.Volume;
import java.io.File;
import java.io.IOException;
import java.util.List;
public class WarzoneMapper { public class WarzoneMapper {
@ -45,8 +46,7 @@ public class WarzoneMapper {
} }
// world // world
String worldStr = warzoneConfig.getProperty("world"); //String worldStr = warzoneConfig.getProperty("world");
warzone.setWorld(world); // default world for now warzone.setWorld(world); // default world for now
// northwest // northwest
@ -100,17 +100,17 @@ public class WarzoneMapper {
warzone.setFriendlyFire(warzoneConfig.getBoolean("friendlyFire")); warzone.setFriendlyFire(warzoneConfig.getBoolean("friendlyFire"));
// loadout // loadout
// String loadoutStr = warzoneConfig.getString("loadout"); String loadoutStr = warzoneConfig.getString("loadout");
// String[] loadoutStrSplit = loadoutStr.split(";"); String[] loadoutStrSplit = loadoutStr.split(";");
// warzone.getLoadout().clear(); warzone.getLoadout().clear();
// for(String itemStr : loadoutStrSplit) { for(String itemStr : loadoutStrSplit) {
// if(itemStr != null && !itemStr.equals("")) { if(itemStr != null && !itemStr.equals("")) {
// String[] itemStrSplit = itemStr.split(","); String[] itemStrSplit = itemStr.split(",");
// Item item = new Item(Integer.parseInt(itemStrSplit[0]), ItemStack item = new ItemStack(Integer.parseInt(itemStrSplit[0]),
// Integer.parseInt(itemStrSplit[1]), Integer.parseInt(itemStrSplit[2])); Integer.parseInt(itemStrSplit[1]));
// warzone.getLoadout().add(item); warzone.getLoadout().put(Integer.parseInt(itemStrSplit[2]), item);
// } }
// } }
// life pool // life pool
warzone.setLifePool(warzoneConfig.getInt("lifePool")); warzone.setLifePool(warzoneConfig.getInt("lifePool"));
@ -212,12 +212,13 @@ public class WarzoneMapper {
warzoneConfig.setBoolean("firendlyFire", warzone.getFriendlyFire()); warzoneConfig.setBoolean("firendlyFire", warzone.getFriendlyFire());
// loadout // loadout
// String loadoutStr = ""; String loadoutStr = "";
// List<Item> items = warzone.getLoadout(); HashMap<Integer, ItemStack> items = warzone.getLoadout();
// for(Item item : items) { for(Integer slot : items.keySet()) {
// loadoutStr += item.getItemId() + "," + item.getAmount() + "," + item.getSlot() + ";"; ItemStack item = items.get(slot);
// } loadoutStr += item.getTypeID() + "," + item.getAmount() + "," + slot + ";";
// warzoneConfig.setString("loadout", loadoutStr); }
warzoneConfig.setString("loadout", loadoutStr);
// life pool // life pool
warzoneConfig.setInt("lifePool", warzone.getLifePool()); warzoneConfig.setInt("lifePool", warzone.getLifePool());
@ -236,7 +237,6 @@ public class WarzoneMapper {
if(saveBlocks) { if(saveBlocks) {
// zone blocks // zone blocks
PropertiesFile warzoneBlocksFile = new PropertiesFile(war.getName() + "/warzone-" + warzone.getName() + ".dat"); PropertiesFile warzoneBlocksFile = new PropertiesFile(war.getName() + "/warzone-" + warzone.getName() + ".dat");
StringBuilder zoneBlocksBuilder = new StringBuilder();
warzoneBlocksFile.setString("zoneBlocks", warzone.getVolume().blocksToString()); // oh boy warzoneBlocksFile.setString("zoneBlocks", warzone.getVolume().blocksToString()); // oh boy
// monument blocks // monument blocks