Added Permissions support. Trying everything to get gates and teleports in player_move working again to no avail.

This commit is contained in:
taoneill 2011-01-22 02:05:04 -05:00
parent b45af8cad0
commit 06ba048797
8 changed files with 283 additions and 252 deletions

View File

@ -4,5 +4,6 @@
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5"/> <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5"/>
<classpathentry kind="con" path="org.maven.ide.eclipse.MAVEN2_CLASSPATH_CONTAINER"/> <classpathentry kind="con" path="org.maven.ide.eclipse.MAVEN2_CLASSPATH_CONTAINER"/>
<classpathentry combineaccessrules="false" kind="src" path="/bukkit"/> <classpathentry combineaccessrules="false" kind="src" path="/bukkit"/>
<classpathentry kind="lib" path="C:/dev/war/war/lib/Permissions.jar"/>
<classpathentry kind="output" path="target/classes"/> <classpathentry kind="output" path="target/classes"/>
</classpath> </classpath>

View File

@ -8,6 +8,7 @@ import org.bukkit.entity.Player;
import org.bukkit.event.Event; import org.bukkit.event.Event;
import org.bukkit.event.Event.Priority; import org.bukkit.event.Event.Priority;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.PluginDescriptionFile; import org.bukkit.plugin.PluginDescriptionFile;
import org.bukkit.plugin.PluginLoader; import org.bukkit.plugin.PluginLoader;
import org.bukkit.plugin.PluginManager; import org.bukkit.plugin.PluginManager;
@ -31,12 +32,15 @@ import java.util.Map;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
import com.nijikokun.bukkit.Permissions.Permissions;
/** /**
* *
* @author tommytony * @author tommytony
* *
*/ */
public class War extends JavaPlugin { public class War extends JavaPlugin {
public static Permissions Permissions = null;
public War(PluginLoader pluginLoader, Server instance, public War(PluginLoader pluginLoader, Server instance,
PluginDescriptionFile desc, File folder, File plugin, ClassLoader cLoader) { PluginDescriptionFile desc, File folder, File plugin, ClassLoader cLoader) {
@ -45,7 +49,6 @@ public class War extends JavaPlugin {
this.desc = desc; this.desc = desc;
} }
private WarPlayerListener playerListener = new WarPlayerListener(this); private WarPlayerListener playerListener = new WarPlayerListener(this);
private WarEntityListener entityListener = new WarEntityListener(this); private WarEntityListener entityListener = new WarEntityListener(this);
private WarBlockListener blockListener = new WarBlockListener(this); private WarBlockListener blockListener = new WarBlockListener(this);
@ -88,7 +91,7 @@ public class War extends JavaPlugin {
public void onEnable() { public void onEnable() {
this.log = Logger.getLogger("Minecraft"); this.log = Logger.getLogger("Minecraft");
this.setupPermissions();
// Register hooks // Register hooks
PluginManager pm = getServer().getPluginManager(); PluginManager pm = getServer().getPluginManager();
@ -185,7 +188,7 @@ public class War extends JavaPlugin {
} }
// /join <teamname> // /join <teamname>
else if(command.equals("join")) { else if(command.equals("join") && canPlayWar(player)) {
if(arguments.length < 1 || (!this.inAnyWarzone(player.getLocation()) && !this.inAnyWarzoneLobby(player.getLocation())) if(arguments.length < 1 || (!this.inAnyWarzone(player.getLocation()) && !this.inAnyWarzoneLobby(player.getLocation()))
|| (arguments.length > 0 && TeamMaterials.teamMaterialFromString(arguments[0]) == null)) { || (arguments.length > 0 && TeamMaterials.teamMaterialFromString(arguments[0]) == null)) {
player.sendMessage(this.str("Usage: /join <diamond/iron/gold/d/i/g>." + player.sendMessage(this.str("Usage: /join <diamond/iron/gold/d/i/g>." +
@ -267,11 +270,11 @@ public class War extends JavaPlugin {
// /team <msg> // /team <msg>
else if(command.equals("team")) { else if(command.equals("team")) {
if(!this.inAnyWarzone(player.getLocation())) { Team playerTeam = this.getPlayerTeam(player.getName());
if(!this.inAnyWarzone(player.getLocation()) && playerTeam != null) {
player.sendMessage(this.str("Usage: /team <message>. " + player.sendMessage(this.str("Usage: /team <message>. " +
"Sends a message only to your teammates.")); "Sends a message only to your teammates."));
} else { } else {
Team playerTeam = this.getPlayerTeam(player.getName());
ChatColor color = null; ChatColor color = null;
if(playerTeam.getMaterial() == TeamMaterials.TEAMDIAMOND) { if(playerTeam.getMaterial() == TeamMaterials.TEAMDIAMOND) {
color = ChatColor.DARK_AQUA; color = ChatColor.DARK_AQUA;
@ -295,7 +298,7 @@ public class War extends JavaPlugin {
player.sendMessage("No warhub on this War server. Try /zones and /zone."); player.sendMessage("No warhub on this War server. Try /zones and /zone.");
} else { } else {
Team playerTeam = this.getPlayerTeam(player.getName()); Team playerTeam = this.getPlayerTeam(player.getName());
Warzone playerWarzone = getPlayerWarzone(player.getName()); Warzone playerWarzone = getPlayerTeamWarzone(player.getName());
if(playerTeam != null) { // was in zone if(playerTeam != null) { // was in zone
playerTeam.removePlayer(player.getName()); playerTeam.removePlayer(player.getName());
} }
@ -306,7 +309,7 @@ public class War extends JavaPlugin {
player.teleportTo(this.getWarHub().getLocation()); player.teleportTo(this.getWarHub().getLocation());
} }
} else if(this.isZoneMaker(player.getName())) { } else if(this.isZoneMaker(player)) {
// Mod commands : /nextbattle // Mod commands : /nextbattle
// /nextbattle // /nextbattle
@ -988,7 +991,7 @@ public class War extends JavaPlugin {
return null; return null;
} }
public Warzone getPlayerWarzone(String playerName) { public Warzone getPlayerTeamWarzone(String playerName) {
for(Warzone warzone : warzones) { for(Warzone warzone : warzones) {
Team team = warzone.getPlayerTeam(playerName); Team team = warzone.getPlayerTeam(playerName);
if(team != null) return warzone; if(team != null) return warzone;
@ -1093,9 +1096,23 @@ public class War extends JavaPlugin {
return zoneMakerNames; return zoneMakerNames;
} }
public boolean isZoneMaker(String playerName) { public boolean canPlayWar(Player player) {
if(Permissions != null && Permissions.Security.permission(player, "war.player")) {
return true;
}
if(Permissions == null) {
// w/o Permissions, everyone can play
return true;
}
return false;
}
public boolean isZoneMaker(Player player) {
for(String zoneMaker : zoneMakerNames) { for(String zoneMaker : zoneMakerNames) {
if(zoneMaker.equals(playerName)) return true; if(zoneMaker.equals(player.getName())) return true;
}
if(Permissions != null && Permissions.Security.permission(player, "war.*")) {
return true;
} }
return false; return false;
} }
@ -1184,4 +1201,16 @@ public class War extends JavaPlugin {
return zoneMakersImpersonatingPlayers; return zoneMakersImpersonatingPlayers;
} }
public void setupPermissions() {
Plugin test = this.getServer().getPluginManager().getPlugin("Permissions");
if(this.Permissions == null) {
if(test != null) {
this.Permissions = (Permissions)test;
} else {
info(str("Permission system not enabled. Defaulting to regular War config."));
}
}
}
} }

View File

@ -32,8 +32,8 @@ public class WarBlockListener extends BlockListener {
boolean captured = false; boolean captured = false;
if(player != null) { if(player != null) {
Team team = war.getPlayerTeam(player.getName()); Team team = war.getPlayerTeam(player.getName());
Warzone zone = war.getPlayerWarzone(player.getName()); Warzone zone = war.getPlayerTeamWarzone(player.getName());
boolean isZoneMaker = war.isZoneMaker(player.getName()); boolean isZoneMaker = war.isZoneMaker(player);
if(team != null && block != null && zone != null if(team != null && block != null && zone != null
&& zone.isMonumentCenterBlock(block) && zone.isMonumentCenterBlock(block)
&& block.getType() == team.getMaterial()) { && block.getType() == team.getMaterial()) {
@ -75,7 +75,7 @@ public class WarBlockListener extends BlockListener {
if(player != null && block != null && event.getDamageLevel() == BlockDamageLevel.BROKEN) { 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()); Team team = war.getPlayerTeam(player.getName());
boolean isZoneMaker = war.isZoneMaker(player.getName()); boolean isZoneMaker = war.isZoneMaker(player);
if(warzone != null && war.getPlayerTeam(player.getName()) == null && !isZoneMaker) { if(warzone != null && war.getPlayerTeam(player.getName()) == null && !isZoneMaker) {
// 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

View File

@ -35,65 +35,20 @@ public class WarEntityListener extends EntityListener {
if(defender instanceof Player) { if(defender instanceof Player) {
Player d = (Player)defender; Player d = (Player)defender;
synchronized(defender) { if(event.getDamage() >= d.getHealth()) {
if(event.getDamage() >= d.getHealth()) { // Player died
// Player died Warzone defenderWarzone = war.getPlayerTeamWarzone(d.getName());
Warzone defenderWarzone = war.getPlayerWarzone(d.getName()); Team defenderTeam = war.getPlayerTeam(d.getName());
Team defenderTeam = war.getPlayerTeam(d.getName()); if(defenderTeam != null) {
if(defenderTeam != null) {
handleDeath(d, defenderWarzone, defenderTeam); handleDeath(d, defenderWarzone, defenderTeam);
event.setCancelled(true); // Don't let the killing blow fall down. event.setCancelled(true); // Don't let the killing blow fall down.
}
} }
} }
} }
} }
// public void onEntityDamaged(EntityDamagedEvent event) {
// Entity damaged = event.getEntity();
// DamageCause cause = event.getCause();
// if(damaged != null && damaged instanceof Player){
// Player player = (Player)damaged;
// int damage = event.getDamage();
// int currentPlayerHp = player.getHealth();
// if(damage >= currentPlayerHp) {
// Warzone zone = war.warzone(player.getLocation());
// if(war.getPlayerTeam(player.getName()) != null) {
// // player on a team killed himself
// handleDeath(((Player)damaged));
//
// } else if (zone != null ) {
// player.teleportTo(zone.getTeleport());
// }
// event.setCancelled(true); // Don't totally kill the player
// }
// }
// }
//
// public void onEntityDamagedByBlock(EntityDamagedByBlockEvent event) {
// Entity damaged = event.getEntity();
//
// if(damaged != null && damaged instanceof Player){
// Player player = (Player)damaged;
// int damage = event.getDamage();
// int currentPlayerHp = player.getHealth();
// if(damage >= currentPlayerHp) {
// Warzone zone = war.warzone(player.getLocation());
// if(war.getPlayerTeam(player.getName()) != null) {
// // player on a team killed himself
// handleDeath(((Player)damaged));
//
// } else if (zone != null ) {
// player.teleportTo(zone.getTeleport());
// }
// event.setCancelled(true); // Don't let the block totally kill the player
// }
// }
//
// }
public void onEntityDamageByEntity(EntityDamageByEntityEvent event) { public void onEntityDamageByEntity(EntityDamageByEntityEvent event) {
Entity attacker = event.getDamager(); Entity attacker = event.getDamager();
Entity defender = event.getEntity(); Entity defender = event.getEntity();
@ -102,16 +57,16 @@ public class WarEntityListener extends EntityListener {
// only let adversaries (same warzone, different team) attack each other // only let adversaries (same warzone, different team) attack each other
Player a = (Player)attacker; Player a = (Player)attacker;
Player d = (Player)defender; Player d = (Player)defender;
Warzone attackerWarzone = war.getPlayerWarzone(a.getName()); Warzone attackerWarzone = war.getPlayerTeamWarzone(a.getName());
Team attackerTeam = war.getPlayerTeam(a.getName()); Team attackerTeam = war.getPlayerTeam(a.getName());
Warzone defenderWarzone = war.getPlayerWarzone(d.getName()); Warzone defenderWarzone = war.getPlayerTeamWarzone(d.getName());
Team defenderTeam = war.getPlayerTeam(d.getName()); Team defenderTeam = war.getPlayerTeam(d.getName());
if(attackerTeam != null && defenderTeam != null if(attackerTeam != null && defenderTeam != null
&& attackerTeam != defenderTeam && attackerTeam != defenderTeam
&& attackerWarzone == defenderWarzone) { && attackerWarzone == defenderWarzone) {
// A real attack: handle death scenario. ==> now handled in entity damage as well // A real attack: handle death scenario. ==> now handled in entity damage as well
synchronized(d) { //synchronized(d) {
if(event.getDamage() >= d.getHealth()) { if(d.getHealth() <= 0) {
// // Player died, loot him! // // Player died, loot him!
// PlayerInventory attackerInv = a.getInventory(); // PlayerInventory attackerInv = a.getInventory();
// PlayerInventory defenderInv = d.getInventory(); // PlayerInventory defenderInv = d.getInventory();
@ -132,7 +87,7 @@ public class WarEntityListener extends EntityListener {
handleDeath(d, defenderWarzone, defenderTeam); handleDeath(d, defenderWarzone, defenderTeam);
event.setCancelled(true); event.setCancelled(true);
} }
} //}
} else if (attackerTeam != null && defenderTeam != null } else if (attackerTeam != null && defenderTeam != null
&& attackerTeam == defenderTeam && attackerTeam == defenderTeam
&& attackerWarzone == defenderWarzone) { && attackerWarzone == defenderWarzone) {

View File

@ -39,7 +39,7 @@ public class WarPlayerListener extends PlayerListener {
Player player = event.getPlayer(); Player player = event.getPlayer();
Team team = war.getPlayerTeam(player.getName()); Team team = war.getPlayerTeam(player.getName());
if(team != null) { if(team != null) {
Warzone zone = war.getPlayerWarzone(player.getName()); Warzone zone = war.getPlayerTeamWarzone(player.getName());
if(zone != null && zone.hasPlayerInventory(player.getName())) { if(zone != null && zone.hasPlayerInventory(player.getName())) {
player.teleportTo(zone.getTeleport()); player.teleportTo(zone.getTeleport());
zone.restorePlayerInventory(player); zone.restorePlayerInventory(player);
@ -59,186 +59,230 @@ public class WarPlayerListener extends PlayerListener {
public void onPlayerMove(PlayerMoveEvent event) { public void onPlayerMove(PlayerMoveEvent event) {
Player player = event.getPlayer(); Player player = event.getPlayer();
synchronized(player) { Location from = event.getFrom();
Location to = event.getTo(); Warzone locZone = null;
ZoneLobby locLobby = null;
if(from != null) {
locZone = war.warzone(from);
locLobby = war.lobby(from);
}
// synchronized(player) {
Location to = event.getTo();
boolean canPlay = war.canPlayWar(player);
boolean isMaker = war.isZoneMaker(player);
// Zone walls // Zone walls
if(to != null && !war.isZoneMaker(player.getName())) { // zone makers don't get bothered with guard walls if(!isMaker && to != null) { // zone makers don't get bothered with guard walls
Warzone nearbyZone = war.zoneOfZoneWallAtProximity(to); Warzone nearbyZone = war.zoneOfZoneWallAtProximity(to);
if(nearbyZone != null) { if(nearbyZone != null) {
nearbyZone.protectZoneWallAgainstPlayer(player); nearbyZone.protectZoneWallAgainstPlayer(player);
} else { } else {
// make sure to delete any wall guards as you leave // make sure to delete any wall guards as you leave
for(Warzone zone : war.getWarzones()) { for(Warzone zone : war.getWarzones()) {
zone.dropZoneWallGuardIfAny(player); zone.dropZoneWallGuardIfAny(player);
}
} }
} }
}
Warzone playerWarzone = war.getPlayerWarzone(player.getName()); // this uses the teams, so it asks: get the player's team's warzone, to be clearer Warzone playerWarzone = war.getPlayerTeamWarzone(player.getName());
// this uses the teams, so it asks: get the player's team's warzone, to be clearer
boolean enteredGate = false; boolean enteredGate = false;
if(to != null) { // Warzone lobby gates
// Warzone lobby gates if(locLobby != null && to != null) {
for(Warzone zone : war.getWarzones()){ Warzone zone = locLobby.getZone();
if(zone.getLobby() != null) { Team oldTeam = war.getPlayerTeam(player.getName());
Team oldTeam = war.getPlayerTeam(player.getName()); boolean isAutoAssignGate = false;
if(oldTeam == null) { // trying to counter spammy player move boolean isDiamondGate = false;
if(zone.getLobby().isAutoAssignGate(to)) { boolean isIronGate = false;
enteredGate = true; boolean isGoldGate = false;
dropFromOldTeamIfAny(player); if(oldTeam == null && canPlay) { // trying to counter spammy player move
int noOfPlayers = 0; isAutoAssignGate = zone.getLobby().isAutoAssignGate(to);
for(Team t : zone.getTeams()) { if(isAutoAssignGate) {
noOfPlayers += t.getPlayers().size(); enteredGate = true;
} dropFromOldTeamIfAny(player);
if(noOfPlayers < zone.getTeams().size() * zone.getTeamCap()) { int noOfPlayers = 0;
//zone.autoAssign(event, player); for(Team t : zone.getTeams()) {
zone.autoAssign(player); noOfPlayers += t.getPlayers().size();
event.setCancelled(true);
} else {
//event.setTo(zone.getTeleport());
player.teleportTo(zone.getTeleport());
event.setCancelled(true);
player.sendMessage("All teams are full.");
}
} else if (zone.getLobby().isInTeamGate(TeamMaterials.TEAMDIAMOND, to)){
enteredGate = true;
dropFromOldTeamIfAny(player);
Team diamondTeam = zone.getTeamByMaterial(TeamMaterials.TEAMDIAMOND);
if(diamondTeam.getPlayers().size() < zone.getTeamCap()) {
diamondTeam.addPlayer(player);
diamondTeam.resetSign();
zone.keepPlayerInventory(player);
player.sendMessage(war.str("Your inventory is is storage until you /leave."));
//zone.respawnPlayer(event, diamondTeam, player);
zone.respawnPlayer(diamondTeam, player);
event.setCancelled(true);
for(Team team : zone.getTeams()){
team.teamcast(war.str("" + player.getName() + " joined team diamond."));
}
} else {
//event.setTo(zone.getTeleport());
player.teleportTo(zone.getTeleport());
event.setCancelled(true);
player.sendMessage("Team diamond is full.");
}
} else if (zone.getLobby().isInTeamGate(TeamMaterials.TEAMIRON, to)){
enteredGate = true;
dropFromOldTeamIfAny(player);
Team ironTeam = zone.getTeamByMaterial(TeamMaterials.TEAMIRON);
if(ironTeam.getPlayers().size() < zone.getTeamCap()) {
ironTeam.addPlayer(player);
ironTeam.resetSign();
zone.keepPlayerInventory(player);
player.sendMessage(war.str("Your inventory is is storage until you /leave."));
//zone.respawnPlayer(event, ironTeam, player);
zone.respawnPlayer(ironTeam, player);
event.setCancelled(true);
for(Team team : zone.getTeams()){
team.teamcast(war.str("" + player.getName() + " joined team iron."));
}
} else {
//event.setTo(zone.getTeleport());
player.teleportTo(zone.getTeleport());
event.setCancelled(true);
player.sendMessage("Team iron is full.");
}
} else if (zone.getLobby().isInTeamGate(TeamMaterials.TEAMGOLD, to)){
enteredGate = true;
dropFromOldTeamIfAny(player);
Team goldTeam = zone.getTeamByMaterial(TeamMaterials.TEAMGOLD);
if(goldTeam.getPlayers().size() < zone.getTeamCap()) {
goldTeam.addPlayer(player);
goldTeam.resetSign();
zone.keepPlayerInventory(player);
player.sendMessage(war.str("Your inventory is is storage until you /leave."));
//zone.respawnPlayer(event, goldTeam, player);
zone.respawnPlayer(goldTeam, player);
event.setCancelled(true);
for(Team team : zone.getTeams()){
team.teamcast(war.str("" + player.getName() + " joined team gold."));
}
} else {
//event.setTo(zone.getTeleport());
player.teleportTo(zone.getTeleport());
event.setCancelled(true);
player.sendMessage("Team gold is full.");
}
} else if (zone.getLobby().isInWarHubLinkGate(to)){
enteredGate = true;
dropFromOldTeamIfAny(player);
//event.setTo(war.getWarHub().getLocation());
player.teleportTo(war.getWarHub().getLocation());
event.setCancelled(true);
player.sendMessage(war.str("Welcome to the War hub."));
}
} else if(zone.getLobby().isLeavingZone(to)) { // already in a team and in warzone, leaving
enteredGate = true;
// same as leave, except event.setTo
Team playerTeam = war.getPlayerTeam(player.getName());
playerTeam.removePlayer(player.getName());
playerTeam.resetSign();
//event.setTo(playerWarzone.getTeleport());
player.teleportTo(zone.getTeleport());
event.setCancelled(true);
playerWarzone.restorePlayerInventory(player);
if(playerWarzone.getLobby() != null) {
playerWarzone.getLobby().resetTeamGateSign(playerTeam);
}
player.sendMessage(war.str("Left the zone. Your inventory has (hopefully) been restored."));
if(war.getWarHub() != null) {
war.getWarHub().resetZoneSign(zone);
}
}
} }
if(noOfPlayers < zone.getTeams().size() * zone.getTeamCap()) {
zone.autoAssign(event, player);
//zone.autoAssign(player);
//event.setCancelled(true);
} else {
event.setTo(zone.getTeleport());
//player.teleportTo(zone.getTeleport());
//event.setCancelled(true);
player.sendMessage("All teams are full.");
}
return;
} }
// Warhub zone gates isDiamondGate = zone.getLobby().isInTeamGate(TeamMaterials.TEAMDIAMOND, to);
WarHub hub = war.getWarHub(); if (isDiamondGate){
if(hub != null) { enteredGate = true;
Warzone zone = hub.getDestinationWarzoneForLocation(to); dropFromOldTeamIfAny(player);
synchronized(player) { Team diamondTeam = zone.getTeamByMaterial(TeamMaterials.TEAMDIAMOND);
if(zone != null) { if(diamondTeam.getPlayers().size() < zone.getTeamCap()) {
enteredGate = true; diamondTeam.addPlayer(player);
event.setTo(zone.getTeleport()); diamondTeam.resetSign();
zone.keepPlayerInventory(player);
player.sendMessage(war.str("Your inventory is is storage until you /leave."));
zone.respawnPlayer(event, diamondTeam, player);
//zone.respawnPlayer(diamondTeam, player);
//event.setCancelled(true);
for(Team team : zone.getTeams()){
team.teamcast(war.str("" + player.getName() + " joined team diamond."));
}
} else {
event.setTo(zone.getTeleport());
//player.teleportTo(zone.getTeleport());
//event.setCancelled(true);
player.sendMessage("Team diamond is full.");
}
return;
}
isIronGate = zone.getLobby().isInTeamGate(TeamMaterials.TEAMIRON, to);
if (isIronGate){
enteredGate = true;
dropFromOldTeamIfAny(player);
Team ironTeam = zone.getTeamByMaterial(TeamMaterials.TEAMIRON);
if(ironTeam.getPlayers().size() < zone.getTeamCap()) {
ironTeam.addPlayer(player);
ironTeam.resetSign();
zone.keepPlayerInventory(player);
player.sendMessage(war.str("Your inventory is is storage until you /leave."));
zone.respawnPlayer(event, ironTeam, player);
// zone.respawnPlayer(ironTeam, player);
// event.setCancelled(true);
for(Team team : zone.getTeams()){
team.teamcast(war.str("" + player.getName() + " joined team iron."));
}
} else {
event.setTo(zone.getTeleport());
// player.teleportTo(zone.getTeleport());
// event.setCancelled(true);
player.sendMessage("Team iron is full.");
}
return;
}
isGoldGate = zone.getLobby().isInTeamGate(TeamMaterials.TEAMGOLD, to);
if (isGoldGate){
enteredGate = true;
dropFromOldTeamIfAny(player);
Team goldTeam = zone.getTeamByMaterial(TeamMaterials.TEAMGOLD);
if(goldTeam.getPlayers().size() < zone.getTeamCap()) {
goldTeam.addPlayer(player);
goldTeam.resetSign();
zone.keepPlayerInventory(player);
player.sendMessage(war.str("Your inventory is is storage until you /leave."));
zone.respawnPlayer(event, goldTeam, player);
//zone.respawnPlayer(goldTeam, player);
//event.setCancelled(true);
for(Team team : zone.getTeams()){
team.teamcast(war.str("" + player.getName() + " joined team gold."));
}
} else {
event.setTo(zone.getTeleport());
// player.teleportTo(zone.getTeleport());
// event.setCancelled(true);
player.sendMessage("Team gold is full.");
}
return;
}
if (zone.getLobby().isInWarHubLinkGate(to)){
enteredGate = true;
dropFromOldTeamIfAny(player);
event.setTo(war.getWarHub().getLocation());
// player.teleportTo(war.getWarHub().getLocation());
// event.setCancelled(true);
player.sendMessage(war.str("Welcome to the War hub."));
return;
}
} else if ((isAutoAssignGate || isDiamondGate || isGoldGate || isIronGate) &&
!canPlay) {
event.setTo(zone.getTeleport());
// player.teleportTo(zone.getTeleport());
// event.setCancelled(true);
player.sendMessage(war.str("You don't have permission to play War. Ask a mod, please."));
return;
}
}
// Warhub zone gates
WarHub hub = war.getWarHub();
if(hub != null && from != null && to != null && hub.getVolume().contains(from)) {
Warzone zone = hub.getDestinationWarzoneForLocation(to);
//synchronized(player) {
if(zone != null) {
enteredGate = true;
event.setTo(zone.getTeleport());
// player.teleportTo(zone.getTeleport()); // player.teleportTo(zone.getTeleport());
// //
// event.setCancelled(true); // event.setCancelled(true);
player.sendMessage(war.str("Welcome to warzone " + zone.getName() + ".")); player.sendMessage(war.str("Welcome to warzone " + zone.getName() + "."));
} return;
}
} }
//}
}
if(playerWarzone != null && !enteredGate) { if(locZone != null && to != null && locZone.getLobby() != null
Team team = war.getPlayerTeam(player.getName()); && locZone.getLobby().isLeavingZone(to)) { // already in a team and in warzone, leaving
enteredGate = true;
// Player belongs to a warzone team but is outside: he snuck out!. // same as leave, except event.setTo
if(war.warzone(to) == null && team != null) { Team playerTeam = war.getPlayerTeam(player.getName());
//player.sendMessage(war.str("Teleporting you back to spawn. Please /leave your team if you want to exit the zone.")); if(playerTeam != null) {
//event.setTo(team.getTeamSpawn()); playerTeam.removePlayer(player.getName());
playerWarzone.respawnPlayer(team, player); playerTeam.resetSign();
//player.teleportTo(team.getTeamSpawn()); event.setTo(playerWarzone.getTeleport());
event.setCancelled(true); // player.teleportTo(zone.getTeleport());
} // event.setCancelled(true);
playerWarzone.restorePlayerInventory(player);
// Monuments if(playerWarzone.getLobby() != null) {
if(to != null && team != null playerWarzone.getLobby().resetTeamGateSign(playerTeam);
&& playerWarzone.nearAnyOwnedMonument(to, team)
&& player.getHealth() < 20
&& random.nextInt(42) == 3 ) { // one chance out of many of getting healed
player.setHealth(20);
player.sendMessage(war.str("Your dance pleases the monument's voodoo. You gain full health!"));
}
} else if (!enteredGate && war.inAnyWarzone(to) && !war.warzone(to).getLobby().isLeavingZone(to) && !war.isZoneMaker(player.getName())) { // player is not in any team, but inside warzone boundaries, get him out
Warzone zone = war.warzone(to);
//event.setTo(zone.getTeleport());
player.teleportTo(zone.getTeleport());
event.setCancelled(true);
//player.sendMessage(war.str("You can't be inside a warzone without a team."));
} }
player.sendMessage(war.str("Left the zone. Your inventory has (hopefully) been restored."));
if(war.getWarHub() != null) {
war.getWarHub().resetZoneSign(locZone);
}
return;
} }
} }
if(playerWarzone != null && !enteredGate) {
Team team = war.getPlayerTeam(player.getName());
// Player belongs to a warzone team but is outside: he snuck out!.
if(locZone == null && team != null) {
//player.sendMessage(war.str("Teleporting you back to spawn. Please /leave your team if you want to exit the zone."));
event.setTo(team.getTeamSpawn());
//playerWarzone.respawnPlayer(team, player);
//player.teleportTo(team.getTeamSpawn());
//event.setCancelled(true);
}
// Monuments
if(to != null && team != null
&& playerWarzone.nearAnyOwnedMonument(to, team)
&& player.getHealth() < 20
&& random.nextInt(42) == 3 ) { // one chance out of many of getting healed
player.setHealth(20);
player.sendMessage(war.str("Your dance pleases the monument's voodoo. You gain full health!"));
}
} else if (locZone != null && locZone.getLobby() != null
&& locZone.getLobby().isLeavingZone(to) && !isMaker) {
// player is not in any team, but inside warzone boundaries, get him out
Warzone zone = war.warzone(to);
event.setTo(zone.getTeleport());
// player.teleportTo(zone.getTeleport());
// event.setCancelled(true);
//player.sendMessage(war.str("You can't be inside a warzone without a team."));
}
} }
private void dropFromOldTeamIfAny(Player player) { private void dropFromOldTeamIfAny(Player player) {

View File

@ -40,8 +40,9 @@ public class VolumeMapper {
public static void load(Volume volume, String zoneName, War war, World world) { public static void load(Volume volume, String zoneName, War war, World world) {
BufferedReader in = null; BufferedReader in = null;
try { try {
if(zoneName.equals("")) in = new BufferedReader(new FileReader(new File("War/dat/volume-" + volume.getName() + ".dat"))); // for the warhub if(zoneName.equals("")) in = new BufferedReader(new FileReader(new File(war.getDataFolder().getPath() +
else in = new BufferedReader(new FileReader(new File("War/dat/warzone-" + zoneName + "/volume-" + volume.getName() + ".dat"))); "/dat/volume-" + volume.getName() + ".dat"))); // for the warhub
else in = new BufferedReader(new FileReader(new File(war.getDataFolder().getPath() + "/dat/warzone-" + zoneName + "/volume-" + volume.getName() + ".dat")));
String firstLine = in.readLine(); String firstLine = in.readLine();
if(firstLine != null && !firstLine.equals("")) { if(firstLine != null && !firstLine.equals("")) {
int x1 = Integer.parseInt(in.readLine()); int x1 = Integer.parseInt(in.readLine());
@ -109,8 +110,9 @@ public class VolumeMapper {
if(volume.isSaved() && volume.getBlockTypes() != null) { if(volume.isSaved() && volume.getBlockTypes() != null) {
BufferedWriter out = null; BufferedWriter out = null;
try { try {
if(zoneName.equals("")) out = new BufferedWriter(new FileWriter(new File("War/dat/volume-" + volume.getName() + ".dat"))); if(zoneName.equals("")) out = new BufferedWriter(new FileWriter(new File(war.getDataFolder().getPath() + "/dat/volume-" + volume.getName() + ".dat")));
else out = new BufferedWriter(new FileWriter(new File("War/dat/warzone-" + zoneName + "/volume-" + volume.getName() + ".dat"))); else out = new BufferedWriter(new FileWriter(new File(war.getDataFolder().getPath() +
"/dat/warzone-" + zoneName + "/volume-" + volume.getName() + ".dat")));
out.write("corner1"); out.newLine(); out.write("corner1"); out.newLine();
out.write(Integer.toString(volume.getCornerOne().getX())); out.newLine(); out.write(Integer.toString(volume.getCornerOne().getX())); out.newLine();

View File

@ -22,9 +22,9 @@ public class WarMapper {
public static void load(War war, World world) { public static void load(War war, World world) {
//war.getLogger().info("Loading war config..."); //war.getLogger().info("Loading war config...");
(new File("War")).mkdir(); (war.getDataFolder()).mkdir();
(new File("War/dat")).mkdir(); (new File(war.getDataFolder().getPath() + "/dat")).mkdir();
PropertiesFile warConfig = new PropertiesFile(war.getName() + "/war.txt"); PropertiesFile warConfig = new PropertiesFile(war.getDataFolder().getPath() + "/war.txt");
try { try {
warConfig.load(); warConfig.load();
} catch (IOException e) { } catch (IOException e) {
@ -138,7 +138,7 @@ public class WarMapper {
public static void save(War war) { public static void save(War war) {
//war.getLogger().info("Saving war config..."); //war.getLogger().info("Saving war config...");
PropertiesFile warConfig = new PropertiesFile(war.getName() + "/war.txt"); PropertiesFile warConfig = new PropertiesFile(war.getDataFolder().getPath() + "/war.txt");
String warzonesStr = ""; String warzonesStr = "";
// warzones // warzones

View File

@ -29,7 +29,7 @@ public class WarzoneMapper {
public static Warzone load(War war, String name, boolean loadBlocks) { public static Warzone load(War war, String name, boolean loadBlocks) {
//war.getLogger().info("Loading warzone " + name + " config and blocks..."); //war.getLogger().info("Loading warzone " + name + " config and blocks...");
PropertiesFile warzoneConfig = new PropertiesFile(war.getName() + "/warzone-" + name + ".txt"); PropertiesFile warzoneConfig = new PropertiesFile(war.getDataFolder().getPath() + "/warzone-" + name + ".txt");
try { try {
warzoneConfig.load(); warzoneConfig.load();
} catch (IOException e) { } catch (IOException e) {
@ -208,8 +208,8 @@ public class WarzoneMapper {
} }
public static void save(War war, Warzone warzone, boolean saveAllBlocks) { public static void save(War war, Warzone warzone, boolean saveAllBlocks) {
(new File(war.getName()+"/dat/warzone-"+warzone.getName())).mkdir(); (new File(war.getDataFolder().getPath() +"/dat/warzone-"+warzone.getName())).mkdir();
PropertiesFile warzoneConfig = new PropertiesFile(war.getName() + "/warzone-" + warzone.getName() + ".txt"); PropertiesFile warzoneConfig = new PropertiesFile(war.getDataFolder().getPath() + "/warzone-" + warzone.getName() + ".txt");
//war.getLogger().info("Saving warzone " + warzone.getName() + "..."); //war.getLogger().info("Saving warzone " + warzone.getName() + "...");
// name // name
@ -332,7 +332,7 @@ public class WarzoneMapper {
} }
public static void delete(War war, String name) { public static void delete(War war, String name) {
File zoneFolder = new File(war.getName() + "/dat/warzone-" + name); File zoneFolder = new File(war.getDataFolder().getPath() + "/dat/warzone-" + name);
File[] files = zoneFolder.listFiles(); File[] files = zoneFolder.listFiles();
for(File file : files) { for(File file : files) {
boolean deletedData = file.delete(); boolean deletedData = file.delete();
@ -344,7 +344,7 @@ public class WarzoneMapper {
if(!deletedData) { if(!deletedData) {
war.warn("Failed to delete folder " + zoneFolder.getName()); war.warn("Failed to delete folder " + zoneFolder.getName());
} }
File zoneFile = new File(war.getName() + "/warzone-" + name + ".txt"); File zoneFile = new File(war.getDataFolder().getPath() + "/warzone-" + name + ".txt");
deletedData = zoneFile.delete(); deletedData = zoneFile.delete();
if(!deletedData) { if(!deletedData) {
war.warn("Failed to delete file " + zoneFile.getName()); war.warn("Failed to delete file " + zoneFile.getName());