mirror of
https://github.com/taoneill/war.git
synced 2024-11-14 06:17:01 +01:00
Some javaDoc
This commit is contained in:
parent
0e48e6539f
commit
ba1a0fef3a
@ -31,9 +31,10 @@ import com.tommytony.war.mappers.*;
|
||||
import com.tommytony.war.utils.*;
|
||||
|
||||
/**
|
||||
* Main class of War
|
||||
*
|
||||
* @author tommytony
|
||||
*
|
||||
* @author tommytony, Tim Düsterhus
|
||||
* @package bukkit.tommytony.war
|
||||
*/
|
||||
public class War extends JavaPlugin {
|
||||
public static PermissionHandler permissionHandler;
|
||||
@ -86,6 +87,9 @@ public class War extends JavaPlugin {
|
||||
this.unloadWar();
|
||||
}
|
||||
|
||||
/**
|
||||
* Cleans up war
|
||||
*/
|
||||
public void unloadWar() {
|
||||
this.setLoaded(false);
|
||||
for (Warzone warzone : this.warzones) {
|
||||
@ -104,6 +108,9 @@ public class War extends JavaPlugin {
|
||||
this.loadWar();
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes war
|
||||
*/
|
||||
public void loadWar() {
|
||||
this.setLoaded(true);
|
||||
this.warzones = new ArrayList<Warzone>();
|
||||
@ -113,7 +120,6 @@ public class War extends JavaPlugin {
|
||||
|
||||
// Register hooks
|
||||
PluginManager pm = this.getServer().getPluginManager();
|
||||
|
||||
pm.registerEvent(Event.Type.PLAYER_QUIT, this.playerListener, Priority.Normal, this);
|
||||
pm.registerEvent(Event.Type.PLAYER_KICK, this.playerListener, Priority.Normal, this);
|
||||
pm.registerEvent(Event.Type.PLAYER_MOVE, this.playerListener, Priority.Normal, this);
|
||||
@ -124,7 +130,6 @@ public class War extends JavaPlugin {
|
||||
pm.registerEvent(Event.Type.PLAYER_INTERACT, this.playerListener, Priority.Normal, this);
|
||||
|
||||
pm.registerEvent(Event.Type.ENTITY_EXPLODE, this.entityListener, Priority.Normal, this);
|
||||
// pm.registerEvent(Event.Type.ENTITY_DEATH, entityListener, Priority.Normal, this);
|
||||
pm.registerEvent(Event.Type.ENTITY_DAMAGE, this.entityListener, Priority.High, this);
|
||||
pm.registerEvent(Event.Type.ENTITY_COMBUST, this.entityListener, Priority.Normal, this);
|
||||
pm.registerEvent(Event.Type.CREATURE_SPAWN, this.entityListener, Priority.Normal, this);
|
||||
@ -133,7 +138,6 @@ public class War extends JavaPlugin {
|
||||
pm.registerEvent(Event.Type.BLOCK_PLACE, this.blockListener, Priority.Normal, this);
|
||||
pm.registerEvent(Event.Type.BLOCK_BREAK, this.blockListener, Priority.Normal, this);
|
||||
|
||||
// pm.registerEvent(Event.Type.CHUNK_UNLOADED, blockListener, Priority.Normal, this);
|
||||
|
||||
// Load files from disk or create them (using these defaults)
|
||||
this.defaultLoadout.put(0, new ItemStack(Material.STONE_SWORD, 1, (byte) 8));
|
||||
@ -149,6 +153,23 @@ public class War extends JavaPlugin {
|
||||
this.logInfo("War v" + this.desc.getVersion() + " is on.");
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes Permissions
|
||||
*/
|
||||
public void setupPermissions() {
|
||||
Plugin permissionsPlugin = this.getServer().getPluginManager().getPlugin("Permissions");
|
||||
if (War.permissionHandler == null) {
|
||||
if (permissionsPlugin != null) {
|
||||
War.permissionHandler = ((Permissions) permissionsPlugin).getHandler();
|
||||
} else {
|
||||
this.logInfo("Permissions system not enabled. Defaulting to regular War config.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles war commands
|
||||
*/
|
||||
public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
|
||||
if (sender instanceof Player) {
|
||||
Player player = (Player) sender;
|
||||
@ -237,9 +258,14 @@ public class War extends JavaPlugin {
|
||||
return true;
|
||||
}
|
||||
|
||||
private void inventoryToLoadout(Player player, HashMap<Integer, ItemStack> loadout) {
|
||||
/**
|
||||
* Converts the player-inventory to a loadout hashmap
|
||||
*
|
||||
* @param PlayerInventory inv inventory to get the items from
|
||||
* @param HashMap<Integer, ItemStack> loadout the hashmap to save to
|
||||
*/
|
||||
private void inventoryToLoadout(PlayerInventory inv, HashMap<Integer, ItemStack> loadout) {
|
||||
loadout.clear();
|
||||
PlayerInventory inv = player.getInventory();
|
||||
int i = 0;
|
||||
for (ItemStack stack : inv.getContents()) {
|
||||
if (stack != null && stack.getType() != Material.AIR) {
|
||||
@ -259,6 +285,16 @@ public class War extends JavaPlugin {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts the player-inventory to a loadout hashmap
|
||||
*
|
||||
* @param Player player player to get the inventory to get the items from
|
||||
* @param HashMap<Integer, ItemStack> loadout the hashmap to save to
|
||||
*/
|
||||
private void inventoryToLoadout(Player player, HashMap<Integer, ItemStack> loadout) {
|
||||
this.inventoryToLoadout(player.getInventory(), loadout);
|
||||
}
|
||||
|
||||
public void performZonemakerAsPlayer(Player player) {
|
||||
boolean wasImpersonating = false;
|
||||
for (String name : this.getZoneMakersImpersonatingPlayers()) {
|
||||
@ -1199,6 +1235,13 @@ public class War extends JavaPlugin {
|
||||
ChatFixUtil.sendMessage(player, out);
|
||||
}
|
||||
|
||||
/**
|
||||
* Colors the teams in messages
|
||||
*
|
||||
* @param String str message-string
|
||||
* @param String msgColor current message-color
|
||||
* @return String Message with colored teams
|
||||
*/
|
||||
private String colorTeams(String str, ChatColor msgColor) {
|
||||
for (TeamKind kind : TeamKinds.getTeamkinds()) {
|
||||
str = str.replaceAll(" " + kind.getDefaultName(), " " + kind.getColor() + kind.getDefaultName() + msgColor);
|
||||
@ -1206,12 +1249,36 @@ public class War extends JavaPlugin {
|
||||
return str;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends a message of Level Info to the logger
|
||||
*
|
||||
* @param String str message to send
|
||||
* @deprecated Use War.log() now
|
||||
*/
|
||||
@Deprecated
|
||||
public void logInfo(String str) {
|
||||
this.getLogger().log(Level.INFO, "War> " + str);
|
||||
this.log(str, Level.INFO);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends a message of Level Warning to the logger
|
||||
*
|
||||
* @param String str message to send
|
||||
* @deprecated Use War.log() now
|
||||
*/
|
||||
@Deprecated
|
||||
public void logWarn(String str) {
|
||||
this.getLogger().log(Level.WARNING, "War> " + str);
|
||||
this.log(str, Level.WARNING);
|
||||
}
|
||||
|
||||
/**
|
||||
* Logs a specified message with a specified level
|
||||
*
|
||||
* @param String str message to log
|
||||
* @param Level lvl level to use
|
||||
*/
|
||||
public void log(String str, Level lvl) {
|
||||
this.getLogger().log(lvl, "War> " + str);
|
||||
}
|
||||
|
||||
// the only way to find a zone that has only one corner
|
||||
@ -1472,17 +1539,6 @@ public class War extends JavaPlugin {
|
||||
return this.zoneMakersImpersonatingPlayers;
|
||||
}
|
||||
|
||||
public void setupPermissions() {
|
||||
Plugin permissionsPlugin = this.getServer().getPluginManager().getPlugin("Permissions");
|
||||
if (War.permissionHandler == null) {
|
||||
if (permissionsPlugin != null) {
|
||||
War.permissionHandler = ((Permissions) permissionsPlugin).getHandler();
|
||||
} else {
|
||||
this.logInfo("Permissions system not enabled. Defaulting to regular War config.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void setDefaultBlockHeads(boolean defaultBlockHeads) {
|
||||
this.defaultBlockHeads = defaultBlockHeads;
|
||||
}
|
||||
@ -1590,5 +1646,4 @@ public class War extends JavaPlugin {
|
||||
public boolean isDefaultResetOnUnload() {
|
||||
return this.defaultResetOnUnload;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
package bukkit.tommytony.war;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.logging.Level;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Location;
|
||||
@ -24,18 +25,29 @@ import com.tommytony.war.Team;
|
||||
import com.tommytony.war.Warzone;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author tommytony
|
||||
*
|
||||
* Handles Entity-Events
|
||||
*
|
||||
* @author tommytony, Tim Düsterhus
|
||||
* @package bukkit.tommytony.war
|
||||
*/
|
||||
public class WarEntityListener extends EntityListener {
|
||||
|
||||
/**
|
||||
* Instance of war
|
||||
*
|
||||
* @var War
|
||||
*/
|
||||
private final War war;
|
||||
|
||||
public WarEntityListener(War war) {
|
||||
this.war = war;
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles PVP-Damage
|
||||
*
|
||||
* @param EntityDamageByEntityEvent event fired event
|
||||
*/
|
||||
private void handlerAttackDefend(EntityDamageByEntityEvent event) {
|
||||
Entity attacker = event.getDamager();
|
||||
Entity defender = event.getEntity();
|
||||
@ -116,7 +128,7 @@ public class WarEntityListener extends EntityListener {
|
||||
deathMessage = "A dispenser killed " + this.war.getPlayerTeam(d.getName()).getKind().getColor() + d.getDisplayName();
|
||||
else if (event.getDamager() instanceof CraftTNTPrimed)
|
||||
deathMessage = this.war.getPlayerTeam(d.getName()).getKind().getColor() + d.getDisplayName() + ChatColor.WHITE + " exploded";
|
||||
else
|
||||
else
|
||||
deathMessage = this.war.getPlayerTeam(d.getName()).getKind().getColor() + d.getDisplayName() + ChatColor.WHITE + " died";
|
||||
for (Team team : defenderWarzone.getTeams()) {
|
||||
team.teamcast(deathMessage);
|
||||
@ -127,6 +139,9 @@ public class WarEntityListener extends EntityListener {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Protects important structures from explosions
|
||||
*/
|
||||
@Override
|
||||
public void onEntityExplode(EntityExplodeEvent event) {
|
||||
if (this.war.isLoaded()) {
|
||||
@ -135,17 +150,17 @@ public class WarEntityListener extends EntityListener {
|
||||
for (Block block : explodedBlocks) {
|
||||
if (this.war.getWarHub() != null && this.war.getWarHub().getVolume().contains(block)) {
|
||||
event.setCancelled(true);
|
||||
this.war.logInfo("Explosion prevented at warhub.");
|
||||
this.war.log("Explosion prevented at warhub.", Level.INFO);
|
||||
return;
|
||||
}
|
||||
for (Warzone zone : this.war.getWarzones()) {
|
||||
if (zone.isImportantBlock(block)) {
|
||||
event.setCancelled(true);
|
||||
this.war.logInfo("Explosion prevented in zone " + zone.getName() + ".");
|
||||
this.war.log("Explosion prevented in zone " + zone.getName() + ".", Level.INFO);
|
||||
return;
|
||||
} else if (zone.getLobby() != null && zone.getLobby().getVolume().contains(block)) {
|
||||
event.setCancelled(true);
|
||||
this.war.logInfo("Explosion prevented at zone " + zone.getName() + " lobby.");
|
||||
this.war.log("Explosion prevented at zone " + zone.getName() + " lobby.", Level.INFO);
|
||||
return;
|
||||
}
|
||||
}
|
||||
@ -153,18 +168,23 @@ public class WarEntityListener extends EntityListener {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles damage on Players
|
||||
*/
|
||||
@Override
|
||||
public void onEntityDamage(EntityDamageEvent event) {
|
||||
if (this.war.isLoaded()) {
|
||||
Entity entity = event.getEntity();
|
||||
// prevent godmode
|
||||
if (entity instanceof Player && this.war.getPlayerTeamWarzone(((Player) entity).getName()) != null) {
|
||||
event.setCancelled(false);
|
||||
}
|
||||
|
||||
// pass pvp-damage
|
||||
if (event instanceof EntityDamageByEntityEvent || event instanceof EntityDamageByProjectileEvent) {
|
||||
this.handlerAttackDefend((EntityDamageByEntityEvent) event);
|
||||
} else {
|
||||
// Detect death (from , prevent it and respawn the player
|
||||
// Detect death, prevent it and respawn the player
|
||||
if (entity instanceof Player) {
|
||||
Player player = (Player) entity;
|
||||
Warzone zone = this.war.getPlayerTeamWarzone(player.getName());
|
||||
@ -202,6 +222,9 @@ public class WarEntityListener extends EntityListener {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Prevents creatures from spawning in warzones if no creatures is active
|
||||
*/
|
||||
@Override
|
||||
public void onCreatureSpawn(CreatureSpawnEvent event) {
|
||||
if (this.war.isLoaded()) {
|
||||
@ -214,6 +237,9 @@ public class WarEntityListener extends EntityListener {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Prevents health regaining caused by peaceful mode
|
||||
*/
|
||||
@Override
|
||||
public void onEntityRegainHealth(EntityRegainHealthEvent event) {
|
||||
if (this.war.isLoaded() && event.getRegainReason() == RegainReason.REGEN) {
|
||||
|
@ -192,7 +192,7 @@ public class WarPlayerListener extends PlayerListener {
|
||||
}
|
||||
if (inWarzone || inLobby || inWarhub) {
|
||||
event.setCancelled(true);
|
||||
this.war.logWarn("Prevented " + player.getName() + " from getting kicked.");
|
||||
this.war.log("Prevented " + player.getName() + " from getting kicked.", java.util.logging.Level.WARNING);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -434,7 +434,7 @@ public class WarPlayerListener extends PlayerListener {
|
||||
Team previousTeam = this.war.getPlayerTeam(player.getName());
|
||||
if (previousTeam != null) {
|
||||
if (!previousTeam.removePlayer(player.getName())) {
|
||||
this.war.logWarn("Could not remove player " + player.getName() + " from team " + previousTeam.getName());
|
||||
this.war.log("Could not remove player " + player.getName() + " from team " + previousTeam.getName(), java.util.logging.Level.WARNING);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -3,6 +3,7 @@ package com.tommytony.war;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.logging.Level;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Location;
|
||||
@ -25,9 +26,9 @@ import com.tommytony.war.utils.InventoryStash;
|
||||
import com.tommytony.war.volumes.ZoneVolume;
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @author tommytony
|
||||
*
|
||||
*
|
||||
*/
|
||||
public class Warzone {
|
||||
private String name;
|
||||
@ -157,7 +158,7 @@ public class Warzone {
|
||||
|
||||
/**
|
||||
* Goes back to the saved state of the warzone (resets only block types, not physics). Also teleports all players back to their respective spawns.
|
||||
*
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public void initializeZone() {
|
||||
@ -813,7 +814,7 @@ public class Warzone {
|
||||
}
|
||||
this.getVolume().resetBlocksAsJob();
|
||||
this.initializeZoneAsJob();
|
||||
this.war.logInfo("Last player left warzone " + this.getName() + ". Warzone blocks resetting automatically...");
|
||||
this.war.log("Last player left warzone " + this.getName() + ". Warzone blocks resetting automatically...", Level.INFO);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -968,7 +969,7 @@ public class Warzone {
|
||||
}
|
||||
|
||||
public void unload() {
|
||||
this.war.logInfo("Unloading zone " + this.getName() + "...");
|
||||
this.war.log("Unloading zone " + this.getName() + "...", Level.INFO);
|
||||
for (Team team : this.getTeams()) {
|
||||
for (Player player : team.getPlayers()) {
|
||||
this.handlePlayerLeave(player, this.getTeleport(), false);
|
||||
|
@ -17,9 +17,9 @@ import com.tommytony.war.volumes.Volume;
|
||||
import com.tommytony.war.volumes.ZoneVolume;
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @author tommytony
|
||||
*
|
||||
*
|
||||
*/
|
||||
public class ZoneLobby {
|
||||
private final War war;
|
||||
@ -41,7 +41,7 @@ public class ZoneLobby {
|
||||
|
||||
/**
|
||||
* Use this constructor with /setzonelobby <n/s/e/w>
|
||||
*
|
||||
*
|
||||
* @param war
|
||||
* @param warzone
|
||||
* @param wall
|
||||
@ -60,7 +60,7 @@ public class ZoneLobby {
|
||||
|
||||
/**
|
||||
* Use this constructor with /setzonelobby <zonename>. Makes sure the lobby is not sticking inside the zone.
|
||||
*
|
||||
*
|
||||
* @param war
|
||||
* @param warzone
|
||||
* @param wall
|
||||
@ -105,7 +105,7 @@ public class ZoneLobby {
|
||||
|
||||
/**
|
||||
* Changes the lobby's position. Orientation is determined from the player location. Creates volume or resets. Saves new lobby blocks.
|
||||
*
|
||||
*
|
||||
* @param playerLocation
|
||||
*/
|
||||
public void setLocation(Location playerLocation) {
|
||||
@ -165,7 +165,7 @@ public class ZoneLobby {
|
||||
|
||||
/**
|
||||
* Classic way of creating a lobby. Lobby position goes to middle of zone wall. Creates volume or resets. Saves new lobby blocks.
|
||||
*
|
||||
*
|
||||
* @param newWall
|
||||
*/
|
||||
public void setWall(BlockFace newWall) {
|
||||
@ -328,7 +328,7 @@ public class ZoneLobby {
|
||||
BlockInfo.getBlock(this.warzone.getWorld(), this.lobbyMiddleWallBlock).getFace(BlockFace.DOWN).getFace(BlockFace.SOUTH, this.lobbyHalfSide - 1).getFace(this.wall, 9).setType(Material.GLOWSTONE);
|
||||
}
|
||||
} else {
|
||||
this.war.logWarn("Failed to initalize zone lobby for zone " + this.warzone.getName());
|
||||
this.war.log("Failed to initalize zone lobby for zone " + this.warzone.getName(), java.util.logging.Level.WARNING);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,5 +1,7 @@
|
||||
package com.tommytony.war.jobs;
|
||||
|
||||
import java.util.logging.Level;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
|
||||
@ -55,9 +57,9 @@ public class RestoreWarhubJob implements Runnable {
|
||||
zone.getLobby().initialize();
|
||||
}
|
||||
}
|
||||
this.war.logInfo("Warhub ready.");
|
||||
this.war.log("Warhub ready.", Level.INFO);
|
||||
} else {
|
||||
this.war.logWarn("Failed to restore warhub. The specified world (name: " + worldName + ") does not exist!");
|
||||
this.war.log("Failed to restore warhub. The specified world (name: " + worldName + ") does not exist!", Level.WARNING);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,7 @@
|
||||
package com.tommytony.war.jobs;
|
||||
|
||||
import java.util.logging.Level;
|
||||
|
||||
import bukkit.tommytony.war.War;
|
||||
|
||||
import com.tommytony.war.Warzone;
|
||||
@ -22,7 +24,7 @@ public class RestoreWarzonesJob implements Runnable {
|
||||
this.war.getWarzones().clear();
|
||||
for (String warzoneName : warzoneSplit) {
|
||||
if (warzoneName != null && !warzoneName.equals("")) {
|
||||
this.war.logInfo("Loading zone " + warzoneName + "...");
|
||||
this.war.log("Loading zone " + warzoneName + "...", Level.INFO);
|
||||
Warzone zone = WarzoneMapper.load(this.war, warzoneName, !this.newWarInstall);
|
||||
if (zone != null) { // could have failed, would've been logged already
|
||||
this.war.getWarzones().add(zone);
|
||||
@ -39,7 +41,7 @@ public class RestoreWarzonesJob implements Runnable {
|
||||
}
|
||||
}
|
||||
if (this.war.getWarzones().size() > 0) {
|
||||
this.war.logInfo("Warzones ready.");
|
||||
this.war.log("Warzones ready.", Level.INFO);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -8,6 +8,7 @@ import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.logging.Level;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.World;
|
||||
@ -29,9 +30,9 @@ import com.tommytony.war.volumes.ZoneVolume;
|
||||
|
||||
/**
|
||||
* The ZoneVolumeMapper take the blocks from disk and sets them in the worlds, since the ZoneVolume doesn't hold its blocks in memory like regular Volumes.
|
||||
*
|
||||
*
|
||||
* @author tommytony
|
||||
*
|
||||
*
|
||||
*/
|
||||
public class PreDeGaulleZoneVolumeMapper {
|
||||
|
||||
@ -261,10 +262,10 @@ public class PreDeGaulleZoneVolumeMapper {
|
||||
}
|
||||
}
|
||||
} catch (IOException e) {
|
||||
war.logWarn("Failed to read volume file " + volume.getName() + " for warzone " + zoneName + ". " + e.getClass().getName() + " " + e.getMessage());
|
||||
war.log("Failed to read volume file " + volume.getName() + " for warzone " + zoneName + ". " + e.getClass().getName() + " " + e.getMessage(), Level.WARNING);
|
||||
e.printStackTrace();
|
||||
} catch (Exception e) {
|
||||
war.logWarn("Unexpected error caused failure to read volume file " + zoneName + " for warzone " + volume.getName() + ". " + e.getClass().getName() + " " + e.getMessage());
|
||||
war.log("Unexpected error caused failure to read volume file " + zoneName + " for warzone " + volume.getName() + ". " + e.getClass().getName() + " " + e.getMessage(), Level.WARNING);
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
if (in != null) {
|
||||
@ -275,7 +276,7 @@ public class PreDeGaulleZoneVolumeMapper {
|
||||
// scanner.close();
|
||||
// scanner = null;
|
||||
} catch (IOException e) {
|
||||
war.logWarn("Failed to close file reader for volume " + volume.getName() + " for warzone " + zoneName + ". " + e.getClass().getName() + " " + e.getMessage());
|
||||
war.log("Failed to close file reader for volume " + volume.getName() + " for warzone " + zoneName + ". " + e.getClass().getName() + " " + e.getMessage(), Level.WARNING);
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
@ -399,7 +400,7 @@ public class PreDeGaulleZoneVolumeMapper {
|
||||
noOfSavedBlocks++;
|
||||
out.newLine();
|
||||
} catch (Exception e) {
|
||||
war.logWarn("Unexpected error while saving a block to " + " file for zone " + zoneName + ". Blocks saved so far: " + noOfSavedBlocks + "Position: x:" + x + " y:" + y + " z:" + z + ". " + e.getClass().getName() + " " + e.getMessage());
|
||||
war.log("Unexpected error while saving a block to " + " file for zone " + zoneName + ". Blocks saved so far: " + noOfSavedBlocks + "Position: x:" + x + " y:" + y + " z:" + z + ". " + e.getClass().getName() + " " + e.getMessage(), Level.WARNING);
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
z++;
|
||||
@ -410,17 +411,17 @@ public class PreDeGaulleZoneVolumeMapper {
|
||||
x++;
|
||||
}
|
||||
} catch (IOException e) {
|
||||
war.logWarn("Failed to write volume file " + zoneName + " for warzone " + volume.getName() + ". " + e.getClass().getName() + " " + e.getMessage());
|
||||
war.log("Failed to write volume file " + zoneName + " for warzone " + volume.getName() + ". " + e.getClass().getName() + " " + e.getMessage(), Level.WARNING);
|
||||
e.printStackTrace();
|
||||
} catch (Exception e) {
|
||||
war.logWarn("Unexpected error caused failure to write volume file " + zoneName + " for warzone " + volume.getName() + ". " + e.getClass().getName() + " " + e.getMessage());
|
||||
war.log("Unexpected error caused failure to write volume file " + zoneName + " for warzone " + volume.getName() + ". " + e.getClass().getName() + " " + e.getMessage(), Level.WARNING);
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
if (out != null) {
|
||||
try {
|
||||
out.close();
|
||||
} catch (IOException e) {
|
||||
war.logWarn("Failed to close file writer for volume " + volume.getName() + " for warzone " + zoneName + ". " + e.getClass().getName() + " " + e.getMessage());
|
||||
war.log("Failed to close file writer for volume " + volume.getName() + " for warzone " + zoneName + ". " + e.getClass().getName() + " " + e.getMessage(), Level.WARNING);
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
@ -8,6 +8,7 @@ import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.logging.Level;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.World;
|
||||
@ -19,9 +20,9 @@ import bukkit.tommytony.war.War;
|
||||
import com.tommytony.war.volumes.Volume;
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @author tommytony
|
||||
*
|
||||
*
|
||||
*/
|
||||
public class VolumeMapper {
|
||||
|
||||
@ -150,7 +151,7 @@ public class VolumeMapper {
|
||||
blockReads++;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
war.logWarn("Unexpected error while reading block from volume " + volume.getName() + " file for zone " + zoneName + ". Blocks read so far: " + blockReads + "Position: x:" + i + " y:" + j + " z:" + k + ". " + e.getClass().getName() + " " + e.getMessage());
|
||||
war.log("Unexpected error while reading block from volume " + volume.getName() + " file for zone " + zoneName + ". Blocks read so far: " + blockReads + "Position: x:" + i + " y:" + j + " z:" + k + ". " + e.getClass().getName() + " " + e.getMessage(), Level.WARNING);
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
@ -163,17 +164,17 @@ public class VolumeMapper {
|
||||
}
|
||||
}
|
||||
} catch (IOException e) {
|
||||
war.logWarn("Failed to read volume file " + volume.getName() + " for warzone " + zoneName + ". " + e.getClass().getName() + " " + e.getMessage());
|
||||
war.log("Failed to read volume file " + volume.getName() + " for warzone " + zoneName + ". " + e.getClass().getName() + " " + e.getMessage(), Level.WARNING);
|
||||
e.printStackTrace();
|
||||
} catch (Exception e) {
|
||||
war.logWarn("Unexpected error caused failure to read volume file " + zoneName + " for warzone " + volume.getName() + ". " + e.getClass().getName() + " " + e.getMessage());
|
||||
war.log("Unexpected error caused failure to read volume file " + zoneName + " for warzone " + volume.getName() + ". " + e.getClass().getName() + " " + e.getMessage(), Level.WARNING);
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
if (in != null) {
|
||||
try {
|
||||
in.close();
|
||||
} catch (IOException e) {
|
||||
war.logWarn("Failed to close file reader for volume " + volume.getName() + " for warzone " + zoneName + ". " + e.getClass().getName() + " " + e.getMessage());
|
||||
war.log("Failed to close file reader for volume " + volume.getName() + " for warzone " + zoneName + ". " + e.getClass().getName() + " " + e.getMessage(), Level.WARNING);
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
@ -259,24 +260,24 @@ public class VolumeMapper {
|
||||
}
|
||||
out.newLine();
|
||||
} catch (Exception e) {
|
||||
war.logWarn("Unexpected error while writing block into volume " + volume.getName() + " file for zone " + zoneName + ". Blocks written so far: " + blockWrites + "Position: x:" + i + " y:" + j + " z:" + k + ". " + e.getClass().getName() + " " + e.getMessage());
|
||||
war.log("Unexpected error while writing block into volume " + volume.getName() + " file for zone " + zoneName + ". Blocks written so far: " + blockWrites + "Position: x:" + i + " y:" + j + " z:" + k + ". " + e.getClass().getName() + " " + e.getMessage(), Level.WARNING);
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (IOException e) {
|
||||
war.logWarn("Failed to write volume file " + zoneName + " for warzone " + volume.getName() + ". " + e.getClass().getName() + " " + e.getMessage());
|
||||
war.log("Failed to write volume file " + zoneName + " for warzone " + volume.getName() + ". " + e.getClass().getName() + " " + e.getMessage(), Level.WARNING);
|
||||
e.printStackTrace();
|
||||
} catch (Exception e) {
|
||||
war.logWarn("Unexpected error caused failure to write volume file " + zoneName + " for warzone " + volume.getName() + ". " + e.getClass().getName() + " " + e.getMessage());
|
||||
war.log("Unexpected error caused failure to write volume file " + zoneName + " for warzone " + volume.getName() + ". " + e.getClass().getName() + " " + e.getMessage(), Level.WARNING);
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
if (out != null) {
|
||||
try {
|
||||
out.close();
|
||||
} catch (IOException e) {
|
||||
war.logWarn("Failed to close file writer for volume " + volume.getName() + " for warzone " + zoneName + ". " + e.getClass().getName() + " " + e.getMessage());
|
||||
war.log("Failed to close file writer for volume " + volume.getName() + " for warzone " + zoneName + ". " + e.getClass().getName() + " " + e.getMessage(), Level.WARNING);
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
@ -288,7 +289,7 @@ public class VolumeMapper {
|
||||
File volFile = new File("War/dat/volume-" + volume.getName());
|
||||
boolean deletedData = volFile.delete();
|
||||
if (!deletedData) {
|
||||
war.logWarn("Failed to delete file " + volFile.getName());
|
||||
war.log("Failed to delete file " + volFile.getName(), Level.WARNING);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -3,6 +3,7 @@ package com.tommytony.war.mappers;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
import java.util.logging.Level;
|
||||
|
||||
import org.bukkit.block.BlockFace;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
@ -30,7 +31,7 @@ public class WarMapper {
|
||||
try {
|
||||
warConfig.load();
|
||||
} catch (IOException e) {
|
||||
war.logWarn("Failed to load war.txt file.");
|
||||
war.log("Failed to load war.txt file.", Level.WARNING);
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
@ -39,11 +40,11 @@ public class WarMapper {
|
||||
if (!warConfig.containsKey("warzones")) {
|
||||
newWar = true;
|
||||
WarMapper.save(war);
|
||||
war.logInfo("war.txt settings file created.");
|
||||
war.log("war.txt settings file created.", Level.INFO);
|
||||
try {
|
||||
warConfig.load();
|
||||
} catch (IOException e) {
|
||||
war.logWarn("Failed to reload war.txt file after creating it.");
|
||||
war.log("Failed to reload war.txt file after creating it.", Level.WARNING);
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
@ -52,7 +53,7 @@ public class WarMapper {
|
||||
String warzonesStr = warConfig.getString("warzones");
|
||||
RestoreWarzonesJob restoreWarzones = new RestoreWarzonesJob(war, warzonesStr, newWar);
|
||||
if (war.getServer().getScheduler().scheduleSyncDelayedTask(war, restoreWarzones) == -1) {
|
||||
war.logWarn("Failed to schedule warzone-restore job. No warzone was loaded.");
|
||||
war.log("Failed to schedule warzone-restore job. No warzone was loaded.", Level.WARNING);
|
||||
}
|
||||
|
||||
// zone makers
|
||||
@ -166,7 +167,7 @@ public class WarMapper {
|
||||
if (hubStr != null && !hubStr.equals("")) {
|
||||
RestoreWarhubJob restoreWarhub = new RestoreWarhubJob(war, hubStr);
|
||||
if (war.getServer().getScheduler().scheduleSyncDelayedTask(war, restoreWarhub) == -1) {
|
||||
war.logWarn("Failed to schedule warhub-restore job. War hub was not loaded.");
|
||||
war.log("Failed to schedule warhub-restore job. War hub was not loaded.", Level.WARNING);
|
||||
}
|
||||
}
|
||||
|
||||
@ -284,7 +285,7 @@ public class WarMapper {
|
||||
} else {
|
||||
orientationStr = "west";
|
||||
}
|
||||
hubStr = hub.getLocation().getBlockX() + "," + hub.getLocation().getBlockY() + "," + hub.getLocation().getBlockZ() + ","
|
||||
hubStr = hub.getLocation().getBlockX() + "," + hub.getLocation().getBlockY() + "," + hub.getLocation().getBlockZ() + ","
|
||||
+ hub.getLocation().getWorld().getName() + "," + orientationStr;
|
||||
VolumeMapper.save(hub.getVolume(), "", war);
|
||||
}
|
||||
|
@ -4,6 +4,7 @@ import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.logging.Level;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
@ -22,9 +23,9 @@ import com.tommytony.war.volumes.Volume;
|
||||
import com.tommytony.war.volumes.ZoneVolume;
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @author tommytony
|
||||
*
|
||||
*
|
||||
*/
|
||||
public class WarzoneMapper {
|
||||
|
||||
@ -48,7 +49,7 @@ public class WarzoneMapper {
|
||||
}
|
||||
|
||||
if (world == null) {
|
||||
war.logWarn("Failed to restore warzone " + name + ". The specified world (name: " + worldStr + ") does not exist!");
|
||||
war.log("Failed to restore warzone " + name + ". The specified world (name: " + worldStr + ") does not exist!", Level.WARNING);
|
||||
} else {
|
||||
// Create the zone
|
||||
Warzone warzone = new Warzone(war, world, name);
|
||||
@ -473,17 +474,17 @@ public class WarzoneMapper {
|
||||
for (File file : files) {
|
||||
boolean deletedData = file.delete();
|
||||
if (!deletedData) {
|
||||
war.logWarn("Failed to delete file " + file.getName());
|
||||
war.log("Failed to delete file " + file.getName(), Level.WARNING);
|
||||
}
|
||||
}
|
||||
boolean deletedData = zoneFolder.delete();
|
||||
if (!deletedData) {
|
||||
war.logWarn("Failed to delete folder " + zoneFolder.getName());
|
||||
war.log("Failed to delete folder " + zoneFolder.getName(), Level.WARNING);
|
||||
}
|
||||
File zoneFile = new File(war.getDataFolder().getPath() + "/warzone-" + name + ".txt");
|
||||
deletedData = zoneFile.delete();
|
||||
if (!deletedData) {
|
||||
war.logWarn("Failed to delete file " + zoneFile.getName());
|
||||
war.log("Failed to delete file " + zoneFile.getName(), Level.WARNING);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -11,6 +11,7 @@ import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.logging.Level;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.World;
|
||||
@ -33,12 +34,22 @@ import com.tommytony.war.volumes.ZoneVolume;
|
||||
|
||||
/**
|
||||
* The ZoneVolumeMapper take the blocks from disk and sets them in the worlds, since the ZoneVolume doesn't hold its blocks in memory like regular Volumes.
|
||||
*
|
||||
* @author tommytony
|
||||
*
|
||||
*
|
||||
* @author tommytony, Tim Düsterhus
|
||||
* @package com.tommytony.war.mappers
|
||||
*/
|
||||
public class ZoneVolumeMapper {
|
||||
|
||||
/**
|
||||
* Loads the given volume
|
||||
*
|
||||
* @param ZoneVolume volume Volume to load
|
||||
* @param String zoneName Zone to load the volume from
|
||||
* @param War war Instance of War
|
||||
* @param World world The world the zone is located
|
||||
* @param boolean onlyLoadCorners Should only the corners be loaded
|
||||
* @return integer Changed blocks
|
||||
*/
|
||||
public static int load(ZoneVolume volume, String zoneName, War war, World world, boolean onlyLoadCorners) {
|
||||
File cornersFile = new File(war.getDataFolder().getPath() + "/dat/warzone-" + zoneName + "/volume-" + volume.getName() + ".corners");
|
||||
File blocksFile = new File(war.getDataFolder().getPath() + "/dat/warzone-" + zoneName + "/volume-" + volume.getName() + ".blocks");
|
||||
@ -53,7 +64,7 @@ public class ZoneVolumeMapper {
|
||||
// The new 1.6 files aren't created yet. We just reset the zone (except deferred blocks which will soon execute on main thread ),
|
||||
// so let's save to the new format as soon as the zone is fully reset.
|
||||
ZoneVolumeMapper.saveAsJob(volume, zoneName, war, 2);
|
||||
war.logInfo("Warzone " + zoneName + " file converted!");
|
||||
war.log("Warzone " + zoneName + " file converted!", Level.INFO);
|
||||
|
||||
return noOfResetBlocks;
|
||||
} else {
|
||||
@ -234,10 +245,10 @@ public class ZoneVolumeMapper {
|
||||
}
|
||||
}
|
||||
} catch (FileNotFoundException e) {
|
||||
war.logWarn("Failed to find volume file " + volume.getName() + " for warzone " + zoneName + ". " + e.getClass().getName() + " " + e.getMessage());
|
||||
war.log("Failed to find volume file " + volume.getName() + " for warzone " + zoneName + ". " + e.getClass().getName() + " " + e.getMessage(), Level.WARNING);
|
||||
e.printStackTrace();
|
||||
} catch (IOException e) {
|
||||
war.logWarn("Failed to read volume file " + volume.getName() + " for warzone " + zoneName + ". " + e.getClass().getName() + " " + e.getMessage());
|
||||
war.log("Failed to read volume file " + volume.getName() + " for warzone " + zoneName + ". " + e.getClass().getName() + " " + e.getMessage(), Level.WARNING);
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
try {
|
||||
@ -254,7 +265,7 @@ public class ZoneVolumeMapper {
|
||||
invsReader.close();
|
||||
}
|
||||
} catch (IOException e) {
|
||||
war.logWarn("Failed to close volume file " + volume.getName() + " for warzone " + zoneName + ". " + e.getClass().getName() + " " + e.getMessage());
|
||||
war.log("Failed to close volume file " + volume.getName() + " for warzone " + zoneName + ". " + e.getClass().getName() + " " + e.getMessage(), Level.WARNING);
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
@ -262,6 +273,12 @@ public class ZoneVolumeMapper {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses an inventory string
|
||||
*
|
||||
* @param String invString string to parse
|
||||
* @return List<ItemStack> Parsed items
|
||||
*/
|
||||
private static List<ItemStack> readInventoryString(String invString) {
|
||||
List<ItemStack> items = new ArrayList<ItemStack>();
|
||||
if (invString != null && !invString.equals("")) {
|
||||
@ -287,6 +304,14 @@ public class ZoneVolumeMapper {
|
||||
return items;
|
||||
}
|
||||
|
||||
/**
|
||||
* Saves the given volume
|
||||
*
|
||||
* @param Volume volume Volume to save
|
||||
* @param String zoneName The warzone the volume is located
|
||||
* @param War war Instance of war
|
||||
* @return integer Number of written blocks
|
||||
*/
|
||||
public static int save(Volume volume, String zoneName, War war) {
|
||||
int noOfSavedBlocks = 0;
|
||||
if (volume.hasTwoCorners()) {
|
||||
@ -408,7 +433,7 @@ public class ZoneVolumeMapper {
|
||||
}
|
||||
noOfSavedBlocks++;
|
||||
} catch (Exception e) {
|
||||
war.logWarn("Unexpected error while saving a block to " + " file for zone " + zoneName + ". Blocks saved so far: " + noOfSavedBlocks + "Position: x:" + x + " y:" + y + " z:" + z + ". " + e.getClass().getName() + " " + e.getMessage());
|
||||
war.log("Unexpected error while saving a block to " + " file for zone " + zoneName + ". Blocks saved so far: " + noOfSavedBlocks + "Position: x:" + x + " y:" + y + " z:" + z + ". " + e.getClass().getName() + " " + e.getMessage(), Level.WARNING);
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
z++;
|
||||
@ -419,10 +444,10 @@ public class ZoneVolumeMapper {
|
||||
x++;
|
||||
}
|
||||
} catch (IOException e) {
|
||||
war.logWarn("Failed to write volume file " + zoneName + " for warzone " + volume.getName() + ". " + e.getClass().getName() + " " + e.getMessage());
|
||||
war.log("Failed to write volume file " + zoneName + " for warzone " + volume.getName() + ". " + e.getClass().getName() + " " + e.getMessage(), Level.WARNING);
|
||||
e.printStackTrace();
|
||||
} catch (Exception e) {
|
||||
war.logWarn("Unexpected error caused failure to write volume file " + zoneName + " for warzone " + volume.getName() + ". " + e.getClass().getName() + " " + e.getMessage());
|
||||
war.log("Unexpected error caused failure to write volume file " + zoneName + " for warzone " + volume.getName() + ". " + e.getClass().getName() + " " + e.getMessage(), Level.WARNING);
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
try {
|
||||
@ -439,7 +464,7 @@ public class ZoneVolumeMapper {
|
||||
invsWriter.close();
|
||||
}
|
||||
} catch (IOException e) {
|
||||
war.logWarn("Failed to close volume file " + volume.getName() + " for warzone " + zoneName + ". " + e.getClass().getName() + " " + e.getMessage());
|
||||
war.log("Failed to close volume file " + volume.getName() + " for warzone " + zoneName + ". " + e.getClass().getName() + " " + e.getMessage(), Level.WARNING);
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
@ -447,11 +472,25 @@ public class ZoneVolumeMapper {
|
||||
return noOfSavedBlocks;
|
||||
}
|
||||
|
||||
/**
|
||||
* Saves the Volume as a background-job
|
||||
*
|
||||
* @param ZoneVolme volume volume to save
|
||||
* @param String zoneName The zone the volume is located
|
||||
* @param War war Instance of war
|
||||
* @param long tickDelay delay before beginning the task
|
||||
*/
|
||||
private static void saveAsJob(ZoneVolume volume, String zoneName, War war, long tickDelay) {
|
||||
ZoneVolumeSaveJob job = new ZoneVolumeSaveJob(volume, zoneName, war);
|
||||
war.getServer().getScheduler().scheduleSyncDelayedTask(war, job, tickDelay);
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes the given volume
|
||||
*
|
||||
* @param Volume volume volume to delete
|
||||
* @param War war Instance of war
|
||||
*/
|
||||
public static void delete(Volume volume, War war) {
|
||||
ZoneVolumeMapper.deleteFile("War/dat/volume-" + volume.getName() + ".dat", war);
|
||||
ZoneVolumeMapper.deleteFile("War/dat/volume-" + volume.getName() + ".corners", war);
|
||||
@ -460,14 +499,19 @@ public class ZoneVolumeMapper {
|
||||
ZoneVolumeMapper.deleteFile("War/dat/volume-" + volume.getName() + ".invs", war);
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes a volume file
|
||||
*
|
||||
* @param String path path of file
|
||||
* @param War war Instance of war
|
||||
*/
|
||||
private static void deleteFile(String path, War war) {
|
||||
File volFile = new File(path);
|
||||
if (volFile.exists()) {
|
||||
boolean deletedData = volFile.delete();
|
||||
if (!deletedData) {
|
||||
war.logWarn("Failed to delete file " + volFile.getName());
|
||||
war.log("Failed to delete file " + volFile.getName(), Level.WARNING);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@ -3,6 +3,7 @@ package com.tommytony.war.volumes;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.logging.Level;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
@ -21,9 +22,9 @@ import bukkit.tommytony.war.War;
|
||||
import com.tommytony.war.jobs.BlockResetJob;
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @author tommytony
|
||||
*
|
||||
*
|
||||
*/
|
||||
public class Volume {
|
||||
private final String name;
|
||||
@ -281,7 +282,7 @@ public class Volume {
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
this.getWar().logWarn("Failed to reset volume " + this.getName() + " blocks. Blocks visited: " + visitedBlocks + ". Blocks reset: " + noOfResetBlocks + ". Error at x:" + x + " y:" + y + " z:" + z + ". Current block: " + currentBlockId + ". Old block: " + oldBlockType + ". Exception: " + e.getClass().toString() + " " + e.getMessage());
|
||||
this.getWar().log("Failed to reset volume " + this.getName() + " blocks. Blocks visited: " + visitedBlocks + ". Blocks reset: " + noOfResetBlocks + ". Error at x:" + x + " y:" + y + " z:" + z + ". Current block: " + currentBlockId + ". Old block: " + oldBlockType + ". Exception: " + e.getClass().toString() + " " + e.getMessage(), Level.WARNING);
|
||||
e.printStackTrace();
|
||||
}
|
||||
return noOfResetBlocks;
|
||||
@ -443,7 +444,7 @@ public class Volume {
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
this.getWar().logWarn("Failed to set block to " + material + "in volume " + this.name + "." + e.getClass().toString() + " " + e.getMessage());
|
||||
this.getWar().log("Failed to set block to " + material + "in volume " + this.name + "." + e.getClass().toString() + " " + e.getMessage(), Level.WARNING);
|
||||
}
|
||||
}
|
||||
|
||||
@ -468,7 +469,7 @@ public class Volume {
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
this.getWar().logWarn("Failed to set block to " + material + "in volume " + this.name + "." + e.getClass().toString() + " " + e.getMessage());
|
||||
this.getWar().log("Failed to set block to " + material + "in volume " + this.name + "." + e.getClass().toString() + " " + e.getMessage(), Level.WARNING);
|
||||
}
|
||||
}
|
||||
|
||||
@ -503,7 +504,7 @@ public class Volume {
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
this.getWar().logWarn("Failed to switch block to " + newType + "in volume " + this.name + "." + e.getClass().toString() + " " + e.getMessage());
|
||||
this.getWar().log("Failed to switch block to " + newType + "in volume " + this.name + "." + e.getClass().toString() + " " + e.getMessage(), Level.WARNING);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -11,9 +11,9 @@ import com.tommytony.war.Warzone;
|
||||
import com.tommytony.war.mappers.ZoneVolumeMapper;
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @author tommytony
|
||||
*
|
||||
*
|
||||
*/
|
||||
public class ZoneVolume extends Volume {
|
||||
|
||||
@ -29,7 +29,7 @@ public class ZoneVolume extends Volume {
|
||||
public int saveBlocks() {
|
||||
// Save blocks directly to disk (i.e. don't put everything in memory)
|
||||
int saved = ZoneVolumeMapper.save(this, this.zone.getName(), this.getWar());
|
||||
this.getWar().logInfo("Saved " + saved + " blocks in warzone " + this.zone.getName() + ".");
|
||||
this.getWar().log("Saved " + saved + " blocks in warzone " + this.zone.getName() + ".", java.util.logging.Level.INFO);
|
||||
this.isSaved = true;
|
||||
return saved;
|
||||
}
|
||||
@ -48,7 +48,7 @@ public class ZoneVolume extends Volume {
|
||||
public int resetBlocks() {
|
||||
// Load blocks directly from disk and onto the map (i.e. no more in-memory warzone blocks)
|
||||
int reset = ZoneVolumeMapper.load(this, this.zone.getName(), this.getWar(), this.getWorld(), false);
|
||||
this.getWar().logInfo("Reset " + reset + " blocks in warzone " + this.zone.getName() + ".");
|
||||
this.getWar().log("Reset " + reset + " blocks in warzone " + this.zone.getName() + ".", java.util.logging.Level.INFO);
|
||||
this.isSaved = true;
|
||||
return reset;
|
||||
}
|
||||
@ -303,12 +303,4 @@ public class ZoneVolume extends Volume {
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/*
|
||||
* public int resetWallBlocks(BlockFace wall) { int noOfResetBlocks = 0; try { if (hasTwoCorners() && getBlockTypes() != null) { if (wall == BlockFace.EAST) { int z = getMinZ(); int k = 0; int y = getMinY(); for (int j = 0; j < getSizeY(); j++) { int x = getMinX(); for (int i = 0; i < getSizeX(); i++) { int oldBlockType = getBlockTypes()[i][j][k]; byte oldBlockData = getBlockDatas()[i][j][k]; Block currentBlock = getWorld().getBlockAt(x, y, z); if (resetBlock(oldBlockType, oldBlockData, currentBlock)) { noOfResetBlocks++; } x++; } y++; } } else if (wall == BlockFace.WEST) { int z = getMaxZ(); int k = getSizeZ()-1; int y = getMinY(); for (int j = 0; j < getSizeY(); j++) { int x = getMinX(); for (int i = 0; i < getSizeX(); i++) { int oldBlockType = getBlockTypes()[i][j][k]; byte oldBlockData = getBlockDatas()[i][j][k]; Block currentBlock = getWorld().getBlockAt(x, y, z); if (resetBlock(oldBlockType, oldBlockData, currentBlock)) { noOfResetBlocks++; } x++; } y++; } } else if (wall == BlockFace.NORTH) { int x = getMinX(); int i = 0; int y = getMinY(); for (int j = 0; j < getSizeY(); j++) { int z = getMinZ(); for (int k = 0; k < getSizeZ(); k++) { int oldBlockType = getBlockTypes()[i][j][k]; byte oldBlockData = getBlockDatas()[i][j][k]; Block currentBlock = getWorld().getBlockAt(x, y, z); if (resetBlock(oldBlockType, oldBlockData, currentBlock)) { noOfResetBlocks++; } z++; } y++; } } else if (wall == BlockFace.SOUTH) { int x = getMaxX(); int i = getSizeX()-1; int y = getMinY(); for (int j = 0; j < getSizeY(); j++) { int z = getMinZ(); for (int k = 0; k < getSizeZ(); k++) { int oldBlockType = getBlockTypes()[i][j][k]; byte oldBlockData = getBlockDatas()[i][j][k]; Block currentBlock = getWorld().getBlockAt(x, y, z); if (resetBlock(oldBlockType, oldBlockData, currentBlock)) { noOfResetBlocks++; } z++; } y++; } } else if (wall == BlockFace.UP) { int x = getMinX(); int y = getMaxY(); int j = getSizeY()-1; for (int i = 0;i < getSizeX(); i++) { int z = getMinZ(); for (int k = 0; k < getSizeZ(); k++) { int oldBlockType = getBlockTypes()[i][j][k]; byte oldBlockData = getBlockDatas()[i][j][k]; Block currentBlock = getWorld().getBlockAt(x, y, z); if (resetBlock(oldBlockType, oldBlockData, currentBlock)) { noOfResetBlocks++; } z++; } x++; } } else if (wall == BlockFace.DOWN) { int x = getMinX(); int y = getMinY(); int j = 0; for (int i = 0;i < getSizeX(); i++) { int z = getMinZ(); for (int k = 0; k < getSizeZ(); k++) { int oldBlockType = getBlockTypes()[i][j][k]; byte oldBlockData = getBlockDatas()[i][j][k]; Block currentBlock = getWorld().getBlockAt(x, y, z); if (resetBlock(oldBlockType, oldBlockData, currentBlock)) { noOfResetBlocks++; } z++; } x++; } } } } catch (Exception e) { this.getWar().logWarn("Failed to reset wall " + wall + " in volume " + getName() + ". " + e.getClass().toString() + " " + e.getMessage()); } return noOfResetBlocks; }
|
||||
*
|
||||
*
|
||||
* private boolean resetBlock(int oldBlockType, byte oldBlockData, Block currentBlock) { if (currentBlock.getTypeId() != oldBlockType || (currentBlock.getTypeId() == oldBlockType && currentBlock.getData() != oldBlockData) || (currentBlock.getTypeId() == oldBlockType && currentBlock.getData() == oldBlockData && (oldBlockType == Material.WALL_SIGN.getId() || oldBlockType == Material.SIGN_POST.getId()) ) ) { currentBlock.setTypeId(oldBlockType); currentBlock.setData(oldBlockData); // TODO: reset wall signs, chests and dispensers properly like in resetBlocks return true; } return false; }
|
||||
*/
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user