mirror of
https://github.com/taoneill/war.git
synced 2025-01-07 00:08:25 +01:00
Brought back all inventory code. Everything should be ported now. Needs more testing.
This commit is contained in:
parent
9f53f0265e
commit
61ecb3b7ba
@ -1,6 +1,7 @@
|
||||
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.Volume;
|
||||
@ -27,7 +28,6 @@ public class Monument {
|
||||
}
|
||||
|
||||
public void addMonumentBlocks() {
|
||||
// TODO Auto-generated method stub
|
||||
this.ownerTeam = null;
|
||||
int x = location.getBlockX();
|
||||
int y = location.getBlockY();
|
||||
@ -113,11 +113,11 @@ public class Monument {
|
||||
return ownerTeam != null;
|
||||
}
|
||||
|
||||
public void ignite(Team team) {
|
||||
public void capture(Team team) {
|
||||
ownerTeam = team;
|
||||
}
|
||||
|
||||
public void smother() {
|
||||
public void uncapture() {
|
||||
ownerTeam = null;
|
||||
|
||||
|
||||
@ -149,7 +149,6 @@ public class Monument {
|
||||
}
|
||||
|
||||
public Volume getVolume() {
|
||||
// TODO Auto-generated method stub
|
||||
return volume;
|
||||
}
|
||||
|
||||
|
@ -19,12 +19,10 @@ public class Team {
|
||||
private int remainingTickets;
|
||||
private int points = 0;
|
||||
private Volume volume;
|
||||
private final War war;
|
||||
private final Warzone warzone;
|
||||
private Material material;
|
||||
|
||||
public Team(String name, Material material, Location teamSpawn, War war, Warzone warzone) {
|
||||
this.war = war;
|
||||
this.warzone = warzone;
|
||||
this.setName(name);
|
||||
this.teamSpawn = teamSpawn;
|
||||
|
@ -170,7 +170,6 @@ public class War extends JavaPlugin {
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
// TODO Auto-generated method stub
|
||||
return name;
|
||||
}
|
||||
|
||||
|
@ -3,12 +3,9 @@ package com.tommytony.war;
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.Block;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.BlockDamageLevel;
|
||||
import org.bukkit.Player;
|
||||
import org.bukkit.event.block.BlockCanBuildEvent;
|
||||
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.BlockPlacedEvent;
|
||||
|
||||
@ -29,115 +26,59 @@ public class WarBlockListener extends BlockListener {
|
||||
Warzone zone = war.getPlayerWarzone(player.getName());
|
||||
if(team != null && block != null && zone != null
|
||||
&& zone.isMonumentCenterBlock(block)
|
||||
&& (block.getType() == Material.YellowFlower || block.getType() == Material.RedRose || block.getType() == Material.Sapling)) {
|
||||
&& block.getType() == team.getMaterial()) {
|
||||
Monument monument = zone.getMonumentFromCenterBlock(block);
|
||||
if(!monument.hasOwner()) {
|
||||
monument.ignite(team);
|
||||
monument.capture(team);
|
||||
List<Team> teams = zone.getTeams();
|
||||
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) {
|
||||
Player player = event.getPlayer();
|
||||
Block block = event.getBlock();
|
||||
if(player != null && block != null) {
|
||||
if(player != null && block != null && event.getDamageLevel() == BlockDamageLevel.BROKEN) {
|
||||
Warzone warzone = war.warzone(player.getLocation());
|
||||
Team team = war.getPlayerTeam(player.getName());
|
||||
|
||||
if(warzone != null && war.getPlayerTeam(player.getName()) == null) {
|
||||
// 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."));
|
||||
// BUKKIT
|
||||
// event.setCancelled(true);
|
||||
event.setCancelled(true);
|
||||
}
|
||||
|
||||
if(warzone != null && warzone.isImportantBlock(block)) {
|
||||
player.sendMessage(war.str("Can't destroy this."));
|
||||
// BUKKIT
|
||||
// event.setCancelled(true);
|
||||
if(team != null && team.getVolume().contains(block)) {
|
||||
if(player.getInventory().contains(team.getMaterial())) {
|
||||
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
|
||||
&& warzone.isMonumentCenterBlock(block)){
|
||||
&& warzone.isMonumentCenterBlock(block)
|
||||
){
|
||||
Monument monument = warzone.getMonumentFromCenterBlock(block);
|
||||
if(monument.hasOwner()) {
|
||||
monument.smother();
|
||||
monument.uncapture();
|
||||
List<Team> teams = warzone.getTeams();
|
||||
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."));
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
@ -26,7 +26,6 @@ public class Warzone {
|
||||
|
||||
private Location teleport;
|
||||
private boolean friendlyFire;
|
||||
private War war;
|
||||
private int lifePool;
|
||||
private HashMap<Integer, ItemStack> loadout;
|
||||
|
||||
@ -34,7 +33,6 @@ public class Warzone {
|
||||
private World world;
|
||||
|
||||
public Warzone(War war, World world, String name) {
|
||||
this.war = war;
|
||||
this.world = world;
|
||||
this.name = name;
|
||||
this.friendlyFire = war.getDefaultFriendlyFire();
|
||||
|
@ -104,7 +104,8 @@ public final class PropertiesFile {
|
||||
* @return <code>map</code> - Simple Map HashMap of the entire <code>key=value</code> as <code><key (java.lang.String), value (java.lang.String)></code>
|
||||
* @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();
|
||||
}
|
||||
|
||||
|
@ -1,19 +1,20 @@
|
||||
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.Team;
|
||||
import com.tommytony.war.TeamMaterials;
|
||||
import com.tommytony.war.War;
|
||||
import com.tommytony.war.Warzone;
|
||||
import com.tommytony.war.volumes.CenteredVolume;
|
||||
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 {
|
||||
@ -45,8 +46,7 @@ public class WarzoneMapper {
|
||||
}
|
||||
|
||||
// world
|
||||
String worldStr = warzoneConfig.getProperty("world");
|
||||
|
||||
//String worldStr = warzoneConfig.getProperty("world");
|
||||
warzone.setWorld(world); // default world for now
|
||||
|
||||
// northwest
|
||||
@ -100,17 +100,17 @@ public class WarzoneMapper {
|
||||
warzone.setFriendlyFire(warzoneConfig.getBoolean("friendlyFire"));
|
||||
|
||||
// loadout
|
||||
// String loadoutStr = warzoneConfig.getString("loadout");
|
||||
// String[] loadoutStrSplit = loadoutStr.split(";");
|
||||
// warzone.getLoadout().clear();
|
||||
// for(String itemStr : loadoutStrSplit) {
|
||||
// if(itemStr != null && !itemStr.equals("")) {
|
||||
// String[] itemStrSplit = itemStr.split(",");
|
||||
// Item item = new Item(Integer.parseInt(itemStrSplit[0]),
|
||||
// Integer.parseInt(itemStrSplit[1]), Integer.parseInt(itemStrSplit[2]));
|
||||
// warzone.getLoadout().add(item);
|
||||
// }
|
||||
// }
|
||||
String loadoutStr = warzoneConfig.getString("loadout");
|
||||
String[] loadoutStrSplit = loadoutStr.split(";");
|
||||
warzone.getLoadout().clear();
|
||||
for(String itemStr : loadoutStrSplit) {
|
||||
if(itemStr != null && !itemStr.equals("")) {
|
||||
String[] itemStrSplit = itemStr.split(",");
|
||||
ItemStack item = new ItemStack(Integer.parseInt(itemStrSplit[0]),
|
||||
Integer.parseInt(itemStrSplit[1]));
|
||||
warzone.getLoadout().put(Integer.parseInt(itemStrSplit[2]), item);
|
||||
}
|
||||
}
|
||||
|
||||
// life pool
|
||||
warzone.setLifePool(warzoneConfig.getInt("lifePool"));
|
||||
@ -212,12 +212,13 @@ public class WarzoneMapper {
|
||||
warzoneConfig.setBoolean("firendlyFire", warzone.getFriendlyFire());
|
||||
|
||||
// loadout
|
||||
// String loadoutStr = "";
|
||||
// List<Item> items = warzone.getLoadout();
|
||||
// for(Item item : items) {
|
||||
// loadoutStr += item.getItemId() + "," + item.getAmount() + "," + item.getSlot() + ";";
|
||||
// }
|
||||
// warzoneConfig.setString("loadout", loadoutStr);
|
||||
String loadoutStr = "";
|
||||
HashMap<Integer, ItemStack> items = warzone.getLoadout();
|
||||
for(Integer slot : items.keySet()) {
|
||||
ItemStack item = items.get(slot);
|
||||
loadoutStr += item.getTypeID() + "," + item.getAmount() + "," + slot + ";";
|
||||
}
|
||||
warzoneConfig.setString("loadout", loadoutStr);
|
||||
|
||||
// life pool
|
||||
warzoneConfig.setInt("lifePool", warzone.getLifePool());
|
||||
@ -236,7 +237,6 @@ public class WarzoneMapper {
|
||||
if(saveBlocks) {
|
||||
// zone blocks
|
||||
PropertiesFile warzoneBlocksFile = new PropertiesFile(war.getName() + "/warzone-" + warzone.getName() + ".dat");
|
||||
StringBuilder zoneBlocksBuilder = new StringBuilder();
|
||||
warzoneBlocksFile.setString("zoneBlocks", warzone.getVolume().blocksToString()); // oh boy
|
||||
|
||||
// monument blocks
|
||||
|
Loading…
Reference in New Issue
Block a user