Big changes. /renamezone fix, zone backups, logs.

Closes gh-444. Fixed hopelessly broken /renamezone command. Now making
backup copy of renamed and deleted warzone to temp folder. Also,
/savezone now makes backups of old versions before saving if the
keepoldzoneversion:true setting. No more will you have to suffer the
pain of a mistakenly overwritten warzone. Hurray! New standalone War
logger and log file in same temp folder. More logging added to every
command to make tracking down history easier.
This commit is contained in:
taoneill 2012-06-17 01:26:00 -04:00
parent 380025f147
commit a258bd8995
30 changed files with 337 additions and 111 deletions

View File

@ -1,10 +1,14 @@
package com.tommytony.war;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.logging.FileHandler;
import java.util.logging.Formatter;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.bukkit.ChatColor;
import org.bukkit.Location;
@ -43,6 +47,7 @@ import com.tommytony.war.structure.WarHub;
import com.tommytony.war.structure.ZoneLobby;
import com.tommytony.war.utility.ChatFixUtil;
import com.tommytony.war.utility.PlayerState;
import com.tommytony.war.utility.WarLogFormatter;
/**
* Main class of War
@ -86,6 +91,8 @@ public class War extends JavaPlugin {
private final TeamConfigBag teamDefaultConfig = new TeamConfigBag();
private SpoutDisplayer spoutMessenger = null;
private Logger warLogger;
public War() {
super();
War.war = this;
@ -134,6 +141,7 @@ public class War extends JavaPlugin {
warConfig.put(WarConfig.BUILDINZONESONLY, false);
warConfig.put(WarConfig.DISABLEBUILDMESSAGE, false);
warConfig.put(WarConfig.DISABLEPVPMESSAGE, false);
warConfig.put(WarConfig.KEEPOLDZONEVERSIONS, true);
warConfig.put(WarConfig.MAXZONES, 12);
warConfig.put(WarConfig.PVPINZONESONLY, false);
warConfig.put(WarConfig.TNTINZONESONLY, false);
@ -158,6 +166,7 @@ public class War extends JavaPlugin {
warzoneDefaultConfig.put(WarzoneConfig.UNBREAKABLE, false);
warzoneDefaultConfig.put(WarzoneConfig.DEATHMESSAGES, true);
teamDefaultConfig.put(TeamConfig.FLAGMUSTBEHOME, true);
teamDefaultConfig.put(TeamConfig.FLAGPOINTSONLY, false);
teamDefaultConfig.put(TeamConfig.FLAGRETURN, FlagReturn.BOTH);
@ -232,6 +241,21 @@ public class War extends JavaPlugin {
SpoutFadeOutMessageJob fadeOutMessagesTask = new SpoutFadeOutMessageJob();
this.getServer().getScheduler().scheduleSyncRepeatingTask(this, fadeOutMessagesTask, 100, 100);
}
// Get own log file
try {
// Create an appending file handler
FileHandler handler = new FileHandler(this.getDataFolder() + "/temp/war.log", true);
// Add to War-specific logger
this.warLogger = Logger.getLogger("com.tommytony.War.log");
this.warLogger.setUseParentHandlers(false);
Formatter formatter = new WarLogFormatter();
handler.setFormatter(formatter);
this.warLogger.addHandler(handler);
} catch (IOException e) {
this.getLogger().log(Level.WARNING, "Failed to create War log file");
}
this.log("War v" + this.desc.getVersion() + " is on.", Level.INFO);
}
@ -621,7 +645,7 @@ public class War extends JavaPlugin {
this.badMsg(player, "Can't set rally point. No such warzone.");
} else {
zone.setRallyPoint(player.getLocation());
WarzoneYmlMapper.save(zone, false);
WarzoneYmlMapper.save(zone);
}
}
@ -677,7 +701,12 @@ public class War extends JavaPlugin {
* lvl level to use
*/
public void log(String str, Level lvl) {
this.getLogger().log(lvl, "War> " + str);
// Log to Bukkit console
this.getLogger().log(lvl, str);
if (this.warLogger != null) {
this.warLogger.log(lvl, str);
}
}
// the only way to find a zone that has only one corner
@ -804,6 +833,7 @@ public class War extends JavaPlugin {
player.getInventory().addItem(new ItemStack(Material.WOOD_SWORD, 1, (byte) 8));
// player.getWorld().dropItem(player.getLocation(), new ItemStack(Material.WOOD_SWORD));
this.msg(player, "You now have a wand for zone " + zoneName + ". Left-click with wodden sword for corner 1. Right-click for corner 2.");
War.war.log(player.getName() + " now has a wand for warzone " + zoneName, Level.INFO);
}
}
}

View File

@ -1251,12 +1251,10 @@ public class Warzone {
}
if (this.getLobby() != null) {
this.getLobby().getVolume().resetBlocks();
this.getLobby().getVolume().finalize();
}
if (this.getWarzoneConfig().getBoolean(WarzoneConfig.RESETONUNLOAD)) {
this.getVolume().resetBlocks();
}
this.getVolume().finalize();
}
public boolean isEnoughPlayers() {
@ -1372,4 +1370,9 @@ public class Warzone {
public Object getGameEndLock() {
return gameEndLock;
}
public void setName(String newName) {
this.name = newName;
this.volume.setName(newName);
}
}

View File

@ -1,9 +1,12 @@
package com.tommytony.war.command;
import java.util.logging.Level;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import com.tommytony.war.War;
import com.tommytony.war.Warzone;
import com.tommytony.war.mapper.WarzoneYmlMapper;
import com.tommytony.war.structure.Bomb;
@ -54,8 +57,9 @@ public class DeleteBombCommand extends AbstractZoneMakerCommand {
if (bomb != null) {
bomb.getVolume().resetBlocks();
zone.getBombs().remove(bomb);
WarzoneYmlMapper.save(zone, false);
WarzoneYmlMapper.save(zone);
this.msg("Bomb " + bomb.getName() + " removed.");
War.war.log(this.getSender().getName() + " deleted bomb " + bomb.getName() + " in warzone " + zone.getName(), Level.INFO);
} else {
this.badMsg("No such bomb.");
}

View File

@ -1,9 +1,12 @@
package com.tommytony.war.command;
import java.util.logging.Level;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import com.tommytony.war.War;
import com.tommytony.war.Warzone;
import com.tommytony.war.mapper.WarzoneYmlMapper;
import com.tommytony.war.structure.Cake;
@ -54,8 +57,9 @@ public class DeleteCakeCommand extends AbstractZoneMakerCommand {
if (cake != null) {
cake.getVolume().resetBlocks();
zone.getCakes().remove(cake);
WarzoneYmlMapper.save(zone, false);
WarzoneYmlMapper.save(zone);
this.msg("Cake " + cake.getName() + " removed.");
War.war.log(this.getSender().getName() + " deleted cake " + cake.getName() + " in warzone " + zone.getName(), Level.INFO);
} else {
this.badMsg("No such cake.");
}

View File

@ -1,9 +1,12 @@
package com.tommytony.war.command;
import java.util.logging.Level;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import com.tommytony.war.War;
import com.tommytony.war.Warzone;
import com.tommytony.war.mapper.WarzoneYmlMapper;
import com.tommytony.war.structure.Monument;
@ -54,8 +57,9 @@ public class DeleteMonumentCommand extends AbstractZoneMakerCommand {
if (monument != null) {
monument.getVolume().resetBlocks();
zone.getMonuments().remove(monument);
WarzoneYmlMapper.save(zone, false);
WarzoneYmlMapper.save(zone);
this.msg("Monument " + monument.getName() + " removed.");
War.war.log(this.getSender().getName() + " deleted monument " + monument.getName() + " in warzone " + zone.getName(), Level.INFO);
} else {
this.badMsg("No such monument.");
}

View File

@ -1,10 +1,13 @@
package com.tommytony.war.command;
import java.util.logging.Level;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import com.tommytony.war.Team;
import com.tommytony.war.War;
import com.tommytony.war.Warzone;
import com.tommytony.war.config.TeamKind;
import com.tommytony.war.mapper.WarzoneYmlMapper;
@ -62,8 +65,9 @@ public class DeleteTeamCommand extends AbstractZoneMakerCommand {
zone.getLobby().setLocation(zone.getTeleport());
zone.getLobby().initialize();
}
WarzoneYmlMapper.save(zone, false);
WarzoneYmlMapper.save(zone);
this.msg("Team " + team.getName() + " removed.");
War.war.log(this.getSender().getName() + " deleted team " + team.getName() + " in warzone " + zone.getName(), Level.INFO);
} else {
this.badMsg("No such team.");
}

View File

@ -1,10 +1,13 @@
package com.tommytony.war.command;
import java.util.logging.Level;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import com.tommytony.war.Team;
import com.tommytony.war.War;
import com.tommytony.war.Warzone;
import com.tommytony.war.mapper.WarzoneYmlMapper;
import com.tommytony.war.structure.ZoneLobby;
@ -59,8 +62,9 @@ public class DeleteTeamFlagCommand extends AbstractZoneMakerCommand {
if (teamFlagTeam != null) {
teamFlagTeam.deleteTeamFlag();
WarzoneYmlMapper.save(zone, false);
WarzoneYmlMapper.save(zone);
this.msg(teamFlagTeam.getName() + " flag removed.");
War.war.log(this.getSender().getName() + " deleted team " + teamFlagTeam.getName() + " flag in warzone " + zone.getName(), Level.INFO);
} else {
this.badMsg("No such team flag.");
}

View File

@ -1,5 +1,7 @@
package com.tommytony.war.command;
import java.util.logging.Level;
import org.bukkit.command.CommandSender;
@ -38,6 +40,7 @@ public class DeleteWarhubCommand extends AbstractWarAdminCommand {
}
this.msg("War hub removed.");
War.war.log(this.getSender().getName() + " deleted warhub", Level.INFO);
} else {
this.badMsg("No War hub to delete.");
}

View File

@ -1,5 +1,7 @@
package com.tommytony.war.command;
import java.util.logging.Level;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
@ -50,32 +52,19 @@ public class DeleteZoneCommand extends AbstractZoneMakerCommand {
return true;
}
for (Team t : zone.getTeams()) {
if (t.getTeamFlag() != null) {
t.getFlagVolume().resetBlocks();
}
t.getSpawnVolume().resetBlocks();
// reset inventory
for (Player p : t.getPlayers()) {
zone.restorePlayerState(p);
}
}
for (Monument m : zone.getMonuments()) {
m.getVolume().resetBlocks();
}
if (zone.getLobby() != null) {
zone.getLobby().getVolume().resetBlocks();
}
zone.getVolume().resetBlocks();
War.war.getWarzones().remove(zone);
WarYmlMapper.save();
WarzoneYmlMapper.delete(zone.getName());
WarzoneYmlMapper.delete(zone);
if (War.war.getWarHub() != null) { // warhub has to change
War.war.getWarHub().getVolume().resetBlocks();
War.war.getWarHub().initialize();
}
this.msg("Warzone " + zone.getName() + " removed.");
String msg = "Warzone " + zone.getName() + " removed by " + this.getSender().getName() + ".";
War.war.log(msg, Level.INFO);
this.msg(msg);
return true;
}

View File

@ -1,9 +1,12 @@
package com.tommytony.war.command;
import java.util.logging.Level;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import com.tommytony.war.Team;
import com.tommytony.war.War;
import com.tommytony.war.Warzone;
import com.tommytony.war.structure.ZoneLobby;
@ -43,6 +46,8 @@ public class NextBattleCommand extends AbstractZoneMakerCommand {
team.teamcast("The battle was interrupted. " + zone.getTeamInformation() + " Resetting warzone " + zone.getName() + " and life pools...");
}
zone.reinitialize();
War.war.log(this.getSender().getName() + " used nextbattle in warzone " + zone.getName(), Level.INFO);
return true;
}

View File

@ -6,11 +6,10 @@ import java.util.logging.Level;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import com.tommytony.war.War;
import com.tommytony.war.Warzone;
import com.tommytony.war.config.WarzoneConfig;
import com.tommytony.war.mapper.PropertiesFile;
import com.tommytony.war.mapper.VolumeMapper;
import com.tommytony.war.mapper.WarYmlMapper;
import com.tommytony.war.mapper.WarzoneYmlMapper;
import com.tommytony.war.structure.ZoneLobby;
@ -23,7 +22,7 @@ public class RenameZoneCommand extends AbstractZoneMakerCommand {
@Override
public boolean handle() {
Warzone zone;
if (this.args.length == 2) {
zone = Warzone.getZoneByName(this.args[0]);
this.args[0] = this.args[1];
@ -48,43 +47,52 @@ public class RenameZoneCommand extends AbstractZoneMakerCommand {
} else if (!this.isSenderAuthorOfZone(zone)) {
return true;
}
// kill old reference
// Kill old warzone, but use it to create the renamed copy
zone.unload();
zone.getVolume().resetBlocks(); // We're going to use the blocks to save the new copy, reset to base state.
String newName = this.args[0];
String oldName = zone.getName();
// Update the name
zone.setName(newName);
zone.saveState(false); // Save new volume files. Don't clear anything, we already unloaded.
WarzoneYmlMapper.save(zone); // Save new config files for warzone.
// Get rid of old unloaded zone instance
War.war.getWarzones().remove(zone);
// Move old files
(new File(War.war.getDataFolder().getPath() + "/temp/renamed/")).mkdir();
(new File(War.war.getDataFolder().getPath() + "/warzone-" + oldName + ".yml")).renameTo(new File(War.war.getDataFolder().getPath() + "/temp/renamed/warzone-" + oldName + ".yml"));
(new File(War.war.getDataFolder().getPath() + "/temp/renamed/dat/warzone-" + oldName)).mkdirs();
// rename zone file
(new File(War.war.getDataFolder().getPath() + "/warzone-" + zone.getName() + ".yml")).renameTo(new File(War.war.getDataFolder().getPath() + "/warzone-" + this.args[0] + ".yml"));
// rename zone folder
(new File(War.war.getDataFolder().getPath() + "/dat/warzone-" + zone.getName())).renameTo(new File(War.war.getDataFolder().getPath() + "/dat/warzone-" + this.args[0]));
String oldPath = War.war.getDataFolder().getPath() + "/dat/warzone-" + oldName + "/";
File oldZoneFolder = new File(oldPath);
File[] oldZoneFiles = oldZoneFolder.listFiles();
for (File file : oldZoneFiles) {
file.renameTo(new File(War.war.getDataFolder().getPath() + "/temp/renamed/dat/warzone-" + oldName + "/" + file.getName()));
}
oldZoneFolder.delete();
// TODO: Move renaming into ZoneVolumeMapper?
// rename volume files
String oldStart = War.war.getDataFolder().getPath() + "/dat/warzone-" + this.args[0] + "/volume-" + zone.getName() + ".";
String newStart = War.war.getDataFolder().getPath() + "/dat/warzone-" + this.args[0] + "/volume-" + this.args[0] + ".";
(new File(oldStart + "corners")).renameTo(new File(newStart + "corners"));
(new File(oldStart + "blocks")).renameTo(new File(newStart + "blocks"));
(new File(oldStart + "signs")).renameTo(new File(newStart + "signs"));
(new File(oldStart + "invs")).renameTo(new File(newStart + "invs"));
// set new name
PropertiesFile warzoneConfig = new PropertiesFile(War.war.getDataFolder().getPath() + "/warzone-" + this.args[0] + ".yml");
warzoneConfig.setString("name", this.args[0]);
warzoneConfig.save();
warzoneConfig.close();
War.war.log("Loading zone " + this.args[0] + "...", Level.INFO);
Warzone newZone = WarzoneYmlMapper.load(this.args[0], false);
// Load new warzone
War.war.log("Loading zone " + newName + "...", Level.INFO);
Warzone newZone = WarzoneYmlMapper.load(newName, false);
War.war.getWarzones().add(newZone);
// zone.getVolume().loadCorners();
newZone.getVolume().loadCorners();
if (newZone.getWarzoneConfig().getBoolean(WarzoneConfig.RESETONLOAD)) {
newZone.getVolume().resetBlocks();
zone.getVolume().loadCorners();
if (zone.getLobby() != null) {
zone.getLobby().getVolume().resetBlocks();
}
if (zone.getWarzoneConfig().getBoolean(WarzoneConfig.RESETONLOAD)) {
zone.getVolume().resetBlocks();
}
newZone.initializeZone();
// save war config
// Update war config
WarYmlMapper.save();
if (War.war.getWarHub() != null) { // warhub has to change
@ -92,7 +100,8 @@ public class RenameZoneCommand extends AbstractZoneMakerCommand {
War.war.getWarHub().initialize();
}
this.msg("Warzone " + zone.getName() + " renamed to " + this.args[0] + ".");
War.war.log(this.getSender().getName() + " renamed warzone " + oldName + " to " + newName, Level.INFO);
this.msg("Warzone " + oldName + " renamed to " + newName + ".");
return true;
}

View File

@ -1,5 +1,7 @@
package com.tommytony.war.command;
import java.util.logging.Level;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
@ -54,8 +56,10 @@ public class ResetZoneCommand extends AbstractZoneMakerCommand {
}
this.msg("Reloading warzone " + zone.getName() + ".");
zone.reinitialize();
War.war.log(this.getSender().getName() + " reset warzone " + zone.getName(), Level.INFO);
return true;
}

View File

@ -1,11 +1,21 @@
package com.tommytony.war.command;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.channels.FileChannel;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.logging.Level;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import com.tommytony.war.War;
import com.tommytony.war.Warzone;
import com.tommytony.war.config.WarConfig;
import com.tommytony.war.config.WarzoneConfig;
import com.tommytony.war.mapper.WarzoneYmlMapper;
import com.tommytony.war.structure.ZoneLobby;
@ -61,12 +71,65 @@ public class SaveZoneCommand extends AbstractZoneMakerCommand {
}
}
// We have a warzone and indexed-from-0 arguments, let's updatethis.msg(player, "Saving warzone " + warzone.getName() + ".");
// We have a warzone and indexed-from-0 arguments
if (War.war.getWarConfig().getBoolean(WarConfig.KEEPOLDZONEVERSIONS)) {
// Keep a copy of the old version, just in case. First, find the version number
File oldVersionsFolder = new File(War.war.getDataFolder().getPath() + "/temp/oldversions/warzone-" + zone.getName());
oldVersionsFolder.mkdirs();
File[] versionFolders = oldVersionsFolder.listFiles();
File last = null;
if (versionFolders.length > 0) {
last = versionFolders[versionFolders.length - 1];
}
int oldVersion = 0;
if (last != null) {
// at least one version
try {
String numVersion = last.getName().split("-")[1]; // get rid of datetime prefix
oldVersion = Integer.parseInt(numVersion);
} catch (NumberFormatException badname) {
War.war.log("Failed to read old version of warzone " + zone.getName(), Level.WARNING);
}
}
int newVersion = oldVersion + 1;
SimpleDateFormat format = new SimpleDateFormat("yyyyMMddHHmmss");
String newVersionString = format.format(new Date()) + "-" + newVersion;
String newVersionPath = War.war.getDataFolder().getPath() + "/temp/oldversions/warzone-" + zone.getName() + "/" + newVersionString;
File newVersionFolder = new File(newVersionPath);
newVersionFolder.mkdir();
// Copy all warzone files to new version folder before they get overwritten
try {
copyFile(new File(War.war.getDataFolder().getPath() + "/warzone-" + zone.getName() + ".yml"), new File(newVersionPath + "/warzone-" + zone.getName() + ".yml"));
(new File(newVersionPath + "/dat/warzone-" + zone.getName())).mkdirs();
String oldPath = War.war.getDataFolder().getPath() + "/dat/warzone-" + zone.getName() + "/";
File currentZoneFolder = new File(oldPath);
File[] currentZoneFiles = currentZoneFolder.listFiles();
for (File file : currentZoneFiles) {
copyFile(file, new File(newVersionPath + "/dat/warzone-" + zone.getName() + "/" + file.getName()));
}
} catch (IOException badCopy) {
War.war.log("Failed to make backup copy version " + newVersion + " of warzone " + zone.getName(), Level.WARNING);
}
int currentVersion = newVersion + 1;
this.msg("Saving version " + currentVersion + " of warzone " + zone.getName());
War.war.log(this.getSender().getName() + " is saving version " + currentVersion + " of warzone " + zone.getName(), Level.INFO);
} else {
this.msg("Saving new permanent version of warzone " + zone.getName());
War.war.log(this.getSender().getName() + " is saving new permanent version of warzone " + zone.getName(), Level.INFO);
}
// Let's save the new version update
int savedBlocks = zone.saveState(true);
// changed settings: must reinitialize with new settings
String namedParamResult = War.war.updateZoneFromNamedParams(zone, commandSender, this.args);
WarzoneYmlMapper.save(zone, true);
WarzoneYmlMapper.save(zone);
if (this.args.length > 0) {
// the config may have changed, requiring a reset for spawn styles etc.
zone.getVolume().resetBlocks();
@ -81,8 +144,34 @@ public class SaveZoneCommand extends AbstractZoneMakerCommand {
War.war.getWarHub().initialize();
}
this.msg("Warzone " + zone.getName() + " initial state changed. Saved " + savedBlocks + " blocks." + namedParamResult);
this.msg("Saved " + savedBlocks + " blocks in warzone " + zone.getName() + "." + namedParamResult);
if (namedParamResult != null && namedParamResult.length() > 0) {
War.war.log(this.getSender().getName() + " also updated warzone " + zone.getName() + " configuration." + namedParamResult, Level.INFO);
}
return true;
}
public static void copyFile(File sourceFile, File destFile) throws IOException {
if(!destFile.exists()) {
destFile.createNewFile();
}
FileChannel source = null;
FileChannel destination = null;
try {
source = new FileInputStream(sourceFile).getChannel();
destination = new FileOutputStream(destFile).getChannel();
destination.transferFrom(source, 0, source.size());
}
finally {
if(source != null) {
source.close();
}
if(destination != null) {
destination.close();
}
}
}
}

View File

@ -1,9 +1,12 @@
package com.tommytony.war.command;
import java.util.logging.Level;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import com.tommytony.war.War;
import com.tommytony.war.Warzone;
import com.tommytony.war.mapper.WarzoneYmlMapper;
import com.tommytony.war.structure.Bomb;
@ -49,14 +52,16 @@ public class SetBombCommand extends AbstractZoneMakerCommand {
bomb.getVolume().resetBlocks();
bomb.setLocation(player.getLocation());
this.msg("Bomb " + bomb.getName() + " was moved.");
War.war.log(this.getSender().getName() + " moved bomb " + bomb.getName() + " in warzone " + zone.getName(), Level.INFO);
} else {
// create a new bomb
Bomb bomb = new Bomb(this.args[0], zone, player.getLocation());
zone.getBombs().add(bomb);
this.msg("Bomb " + bomb.getName() + " created.");
War.war.log(this.getSender().getName() + " created bomb " + bomb.getName() + " in warzone " + zone.getName(), Level.INFO);
}
WarzoneYmlMapper.save(zone, false);
WarzoneYmlMapper.save(zone);
return true;
}

View File

@ -1,9 +1,12 @@
package com.tommytony.war.command;
import java.util.logging.Level;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import com.tommytony.war.War;
import com.tommytony.war.Warzone;
import com.tommytony.war.mapper.WarzoneYmlMapper;
import com.tommytony.war.structure.Cake;
@ -49,14 +52,16 @@ public class SetCakeCommand extends AbstractZoneMakerCommand {
cake.getVolume().resetBlocks();
cake.setLocation(player.getLocation());
this.msg("Cake " + cake.getName() + " was moved.");
War.war.log(this.getSender().getName() + " moved cake " + cake.getName() + " in warzone " + zone.getName(), Level.INFO);
} else {
// create a new cake
Cake cake = new Cake(this.args[0], zone, player.getLocation());
zone.getCakes().add(cake);
this.msg("Cake " + cake.getName() + " created.");
War.war.log(this.getSender().getName() + " created cake " + cake.getName() + " in warzone " + zone.getName(), Level.INFO);
}
WarzoneYmlMapper.save(zone, false);
WarzoneYmlMapper.save(zone);
return true;
}

View File

@ -1,9 +1,12 @@
package com.tommytony.war.command;
import java.util.logging.Level;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import com.tommytony.war.War;
import com.tommytony.war.Warzone;
import com.tommytony.war.mapper.WarzoneYmlMapper;
import com.tommytony.war.structure.Monument;
@ -49,14 +52,15 @@ public class SetMonumentCommand extends AbstractZoneMakerCommand {
monument.getVolume().resetBlocks();
monument.setLocation(player.getLocation());
this.msg("Monument " + monument.getName() + " was moved.");
War.war.log(this.getSender().getName() + " moved monument " + monument.getName() + " in warzone " + zone.getName(), Level.INFO);
} else {
// create a new monument
Monument monument = new Monument(this.args[0], zone, player.getLocation());
zone.getMonuments().add(monument);
this.msg("Monument " + monument.getName() + " created.");
War.war.log(this.getSender().getName() + " created monument " + monument.getName() + " in warzone " + zone.getName(), Level.INFO);
}
WarzoneYmlMapper.save(zone, false);
WarzoneYmlMapper.save(zone);
return true;
}

View File

@ -1,10 +1,13 @@
package com.tommytony.war.command;
import java.util.logging.Level;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import com.tommytony.war.Team;
import com.tommytony.war.War;
import com.tommytony.war.Warzone;
import com.tommytony.war.config.TeamConfig;
import com.tommytony.war.config.TeamKind;
@ -50,6 +53,7 @@ public class SetTeamCommand extends AbstractZoneMakerCommand {
// relocate
existingTeam.setTeamSpawn(player.getLocation());
this.msg("Team " + existingTeam.getName() + " spawn relocated.");
War.war.log(this.getSender().getName() + " moved team " + existingTeam.getName() + " in warzone " + zone.getName(), Level.INFO);
} else {
// new team (use default TeamKind name for now)
Team newTeam = new Team(teamKind.toString(), teamKind, player.getLocation(), zone);
@ -61,10 +65,11 @@ public class SetTeamCommand extends AbstractZoneMakerCommand {
}
newTeam.setTeamSpawn(player.getLocation());
this.msg("Team " + newTeam.getName() + " created with spawn here.");
War.war.log(this.getSender().getName() + " created team " + newTeam.getName() + " in warzone " + zone.getName(), Level.INFO);
}
}
WarzoneYmlMapper.save(zone, false);
WarzoneYmlMapper.save(zone);
return true;
}

View File

@ -1,5 +1,7 @@
package com.tommytony.war.command;
import java.util.logging.Level;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
@ -133,7 +135,7 @@ public class SetTeamConfigCommand extends AbstractZoneMakerCommand {
String namedParamReturn = War.war.updateTeamFromNamedParams(team, player, this.args);
if (!namedParamReturn.equals("") && !namedParamReturn.equals("PARSE-ERROR")) {
WarzoneYmlMapper.save(zone, false);
WarzoneYmlMapper.save(zone);
String zoneReset = "Some changes may require a /resetzone. ";
if (zone.getWarzoneConfig().getBoolean(WarzoneConfig.RESETONCONFIGCHANGE)) {
@ -146,6 +148,8 @@ public class SetTeamConfigCommand extends AbstractZoneMakerCommand {
} else {
this.msg("Team config saved. " + zoneReset + namedParamReturn);
}
War.war.log(this.getSender().getName() + " updated team " + team.getName() + " configuration in warzone " + zone.getName() + "." + namedParamReturn, Level.INFO);
if (War.war.getWarHub() != null) { // maybe the zone was disabled/enabled
War.war.getWarHub().getVolume().resetBlocks();

View File

@ -1,11 +1,14 @@
package com.tommytony.war.command;
import java.util.logging.Level;
import org.bukkit.Location;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import com.tommytony.war.Team;
import com.tommytony.war.War;
import com.tommytony.war.Warzone;
import com.tommytony.war.config.TeamKind;
import com.tommytony.war.mapper.WarzoneYmlMapper;
@ -51,7 +54,8 @@ public class SetTeamFlagCommand extends AbstractZoneMakerCommand {
Location playerLoc = player.getLocation();
player.teleport(new Location(playerLoc.getWorld(), playerLoc.getBlockX() + 1, playerLoc.getBlockY(), playerLoc.getBlockZ()));
this.msg("Team " + team.getName() + " flag added here.");
WarzoneYmlMapper.save(zone, false);
WarzoneYmlMapper.save(zone);
War.war.log(this.getSender().getName() + " created team " + team.getName() + " flag in warzone " + zone.getName(), Level.INFO);
} else {
// relocate flag
team.getFlagVolume().resetBlocks();
@ -59,7 +63,8 @@ public class SetTeamFlagCommand extends AbstractZoneMakerCommand {
Location playerLoc = player.getLocation();
player.teleport(new Location(playerLoc.getWorld(), playerLoc.getBlockX() + 1, playerLoc.getBlockY(), playerLoc.getBlockZ() + 1));
this.msg("Team " + team.getName() + " flag moved.");
WarzoneYmlMapper.save(zone, false);
WarzoneYmlMapper.save(zone);
War.war.log(this.getSender().getName() + " moved team " + team.getName() + " flag in warzone " + zone.getName(), Level.INFO);
}
return true;

View File

@ -1,5 +1,7 @@
package com.tommytony.war.command;
import java.util.logging.Level;
import org.bukkit.command.CommandSender;
@ -30,10 +32,11 @@ public class SetWarConfigCommand extends AbstractWarAdminCommand {
WarYmlMapper.save();
if (wantsToPrint) {
String config = War.war.printConfig();
this.msg("War config saved." + namedParamReturn + " " + config);
this.msg("War config saved. " + namedParamReturn + " " + config);
} else {
this.msg("War config saved." + namedParamReturn);
this.msg("War config saved. " + namedParamReturn);
}
War.war.log(this.getSender().getName() + " updated War configuration. " + namedParamReturn, Level.INFO);
} else if (namedParamReturn.equals("PARSE-ERROR")) {
this.msg("Failed to read named parameters.");
} else {

View File

@ -1,5 +1,7 @@
package com.tommytony.war.command;
import java.util.logging.Level;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
@ -38,6 +40,7 @@ public class SetWarHubCommand extends AbstractWarAdminCommand {
War.war.getWarHub().setLocation(player.getLocation());
War.war.getWarHub().initialize();
this.msg("War hub moved.");
War.war.log(this.getSender().getName() + " moved the warhub", Level.INFO);
} else {
War.war.setWarHub(new WarHub(player.getLocation()));
War.war.getWarHub().initialize();
@ -48,6 +51,7 @@ public class SetWarHubCommand extends AbstractWarAdminCommand {
}
}
this.msg("War hub created.");
War.war.log(this.getSender().getName() + " created the warhub", Level.INFO);
}
WarYmlMapper.save();
} else {

View File

@ -1,5 +1,7 @@
package com.tommytony.war.command;
import java.util.logging.Level;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
@ -94,7 +96,7 @@ public class SetZoneConfigCommand extends AbstractZoneMakerCommand {
String namedParamReturn = War.war.updateZoneFromNamedParams(zone, player, this.args);
if (!namedParamReturn.equals("") && !namedParamReturn.equals("PARSE-ERROR")) {
WarzoneYmlMapper.save(zone, false);
WarzoneYmlMapper.save(zone);
String zoneReset = "Some changes may require a /resetzone. ";
if (zone.getWarzoneConfig().getBoolean(WarzoneConfig.RESETONCONFIGCHANGE)) {
@ -107,6 +109,8 @@ public class SetZoneConfigCommand extends AbstractZoneMakerCommand {
} else {
this.msg("Warzone config saved. " + zoneReset + namedParamReturn);
}
War.war.log(this.getSender().getName() + " updated warzone " + zone.getName() + " configuration." + namedParamReturn, Level.INFO);
if (War.war.getWarHub() != null) { // maybe the zone was disabled/enabled
War.war.getWarHub().getVolume().resetBlocks();

View File

@ -1,5 +1,7 @@
package com.tommytony.war.command;
import java.util.logging.Level;
import org.bukkit.block.BlockFace;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
@ -65,7 +67,7 @@ public class SetZoneLobbyCommand extends AbstractZoneMakerCommand {
}
this.msg("Warzone lobby moved to your location.");
}
WarzoneYmlMapper.save(givenWarzone, false);
WarzoneYmlMapper.save(givenWarzone);
}
} else if (!this.isSenderAuthorOfZone(zone)) {
return true;
@ -109,7 +111,8 @@ public class SetZoneLobbyCommand extends AbstractZoneMakerCommand {
}
this.msg("Warzone lobby created on " + wallStr + "side of zone.");
}
WarzoneYmlMapper.save(zone, false);
WarzoneYmlMapper.save(zone);
War.war.log(player.getName() + " moved lobby of warzone " + zone.getName(), Level.INFO);
}
return true;

View File

@ -1,5 +1,7 @@
package com.tommytony.war.command;
import java.util.logging.Level;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
@ -50,6 +52,7 @@ public class ZoneMakerCommand extends AbstractWarCommand {
Player kickedMaker = War.war.getServer().getPlayer(this.args[0]);
if (kickedMaker != null) {
War.war.msg(kickedMaker, player.getName() + " took away your warzone maker priviledges.");
War.war.log(player.getName() + " took away zonemaker rights from " + kickedMaker, Level.INFO);
}
} else {
// add
@ -58,6 +61,7 @@ public class ZoneMakerCommand extends AbstractWarCommand {
Player newMaker = War.war.getServer().getPlayer(this.args[0]);
if (newMaker != null) {
War.war.msg(newMaker, player.getName() + " made you warzone maker.");
War.war.log(player.getName() + " made " + newMaker + " a zonemaker", Level.INFO);
}
}
} else {

View File

@ -1,5 +1,7 @@
package com.tommytony.war.command;
import java.util.logging.Level;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.entity.Player;
@ -42,6 +44,7 @@ public class ZoneSetter {
War.war.getIncompleteZones().add(warzone);
warzone.getVolume().setNorthwest(northwestBlock);
War.war.msg(this.player, "Warzone " + warzone.getName() + " created. Northwesternmost point set to x:" + warzone.getVolume().getNorthwestX() + " z:" + warzone.getVolume().getNorthwestZ() + ". ");
War.war.log(player.getName() + " created warzone " + zoneName + " by setting its nw corner", Level.INFO);
} else if (!this.isPlayerAuthorOfZoneOrAdmin(warzone)) {
return;
} else {
@ -49,6 +52,7 @@ public class ZoneSetter {
this.resetWarzone(warzone, msgString);
warzone.getVolume().setNorthwest(northwestBlock);
msgString.append("Warzone " + warzone.getName() + " modified. Northwesternmost point set to x:" + warzone.getVolume().getNorthwestX() + " z:" + warzone.getVolume().getNorthwestZ() + ". ");
War.war.log(player.getName() + " updated warzone " + zoneName + " by setting its nw corner", Level.INFO);
}
this.saveIfReady(warzone, msgString);
} catch (NotNorthwestException e) {
@ -85,6 +89,7 @@ public class ZoneSetter {
War.war.getIncompleteZones().add(warzone);
warzone.getVolume().setSoutheast(southeastBlock);
War.war.msg(this.player, "Warzone " + warzone.getName() + " created. Southeasternmost point set to x:" + warzone.getVolume().getSoutheastX() + " z:" + warzone.getVolume().getSoutheastZ() + ". ");
War.war.log(player.getName() + " created warzone " + zoneName + " by setting its se corner", Level.INFO);
} else if (!this.isPlayerAuthorOfZoneOrAdmin(warzone)) {
return;
} else {
@ -92,6 +97,7 @@ public class ZoneSetter {
this.resetWarzone(warzone, msgString);
warzone.getVolume().setSoutheast(southeastBlock);
msgString.append("Warzone " + warzone.getName() + " modified. Southeasternmost point set to x:" + warzone.getVolume().getSoutheastX() + " z:" + warzone.getVolume().getSoutheastZ() + ". ");
War.war.log(player.getName() + " updated warzone " + zoneName + " by setting its se corner", Level.INFO);
}
this.saveIfReady(warzone, msgString);
} catch (NotSoutheastException e) {
@ -132,6 +138,7 @@ public class ZoneSetter {
War.war.getIncompleteZones().add(warzone);
warzone.getVolume().setZoneCornerOne(corner1Block);
War.war.msg(this.player, "Warzone " + warzone.getName() + " created. Corner 1 set to x:" + corner1Block.getX() + " y:" + corner1Block.getY() + " z:" + corner1Block.getZ() + ". ");
War.war.log(player.getName() + " created warzone " + zoneName + " by setting its corner 1", Level.INFO);
} else if (!this.isPlayerAuthorOfZoneOrAdmin(warzone)) {
return;
} else {
@ -139,6 +146,7 @@ public class ZoneSetter {
this.resetWarzone(warzone, msgString);
warzone.getVolume().setZoneCornerOne(corner1Block);
msgString.append("Warzone " + warzone.getName() + " modified. Corner 1 set to x:" + corner1Block.getX() + " y:" + corner1Block.getY() + " z:" + corner1Block.getZ() + ". ");
War.war.log(player.getName() + " updated warzone " + zoneName + " by setting its corner 1", Level.INFO);
}
this.saveIfReady(warzone, msgString);
} catch (TooSmallException e) {
@ -174,6 +182,7 @@ public class ZoneSetter {
War.war.getIncompleteZones().add(warzone);
warzone.getVolume().setZoneCornerTwo(corner2Block);
War.war.msg(this.player, "Warzone " + warzone.getName() + " created. Corner 2 set to x:" + corner2Block.getX() + " y:" + corner2Block.getY() + " z:" + corner2Block.getZ() + ". ");
War.war.log(player.getName() + " created warzone " + zoneName + " by setting its corner 2", Level.INFO);
} else if (!this.isPlayerAuthorOfZoneOrAdmin(warzone)) {
return;
} else {
@ -181,6 +190,7 @@ public class ZoneSetter {
this.resetWarzone(warzone, msgString);
warzone.getVolume().setZoneCornerTwo(corner2Block);
msgString.append("Warzone " + warzone.getName() + " modified. Corner 2 set to x:" + corner2Block.getX() + " y:" + corner2Block.getY() + " z:" + corner2Block.getZ() + ". ");
War.war.log(player.getName() + " updated warzone " + zoneName + " by setting its corner 2", Level.INFO);
}
this.saveIfReady(warzone, msgString);
} catch (TooSmallException e) {
@ -249,8 +259,9 @@ public class ZoneSetter {
}
warzone.initializeZone();
WarzoneYmlMapper.save(warzone, true);
WarzoneYmlMapper.save(warzone);
War.war.msg(this.player, "Warzone saved.");
War.war.log(this.player.getName() + " saved first version of warzone " + zoneName, Level.INFO);
} else {
if (warzone.getVolume().getCornerOne() == null) {
msgString.append("Still missing corner 1.");

View File

@ -5,6 +5,7 @@ public enum WarConfig {
BUILDINZONESONLY (Boolean.class),
DISABLEBUILDMESSAGE (Boolean.class),
DISABLEPVPMESSAGE (Boolean.class),
KEEPOLDZONEVERSIONS (Boolean.class),
MAXZONES (Integer.class),
PVPINZONESONLY (Boolean.class),
TNTINZONESONLY (Boolean.class);

View File

@ -55,7 +55,7 @@ public class RestoreWarzonesJob implements Runnable {
War.war.log("Converted war.txt to war.yml.", Level.INFO);
for (Warzone zone : War.war.getWarzones()) {
WarzoneYmlMapper.save(zone, false);
WarzoneYmlMapper.save(zone);
War.war.log("Converted warzone-" + zone.getName() + ".txt to warzone-" + zone.getName() + ".yml.", Level.INFO);
}
}

View File

@ -38,7 +38,7 @@ public class WarzoneYmlMapper {
// Since we're converting, WarTxtMapper didn't load the warzones.
// We need to load the old-text-format-Warzone into memory.
Warzone zoneToConvert = WarzoneTxtMapper.load(name, false);
WarzoneYmlMapper.save(zoneToConvert, false);
WarzoneYmlMapper.save(zoneToConvert);
War.war.log("Converted warzone-" + name + ".txt to warzone-" + name + ".yml", Level.INFO);
}
@ -311,7 +311,7 @@ public class WarzoneYmlMapper {
return null;
}
public static void save(Warzone warzone, boolean saveAllBlocks) {
public static void save(Warzone warzone) {
YamlConfiguration warzoneYmlConfig = new YamlConfiguration();
ConfigurationSection warzoneRootSection = warzoneYmlConfig.createSection("set");
(new File(War.war.getDataFolder().getPath() + "/dat/warzone-" + warzone.getName())).mkdir(); // create folder
@ -542,30 +542,24 @@ public class WarzoneYmlMapper {
return intYaw;
}
public static void delete(String name) {
File zoneFolder = new File(War.war.getDataFolder().getPath() + "/dat/warzone-" + name);
File[] files = zoneFolder.listFiles();
for (File file : files) {
boolean deletedData = file.delete();
if (!deletedData) {
War.war.log("Failed to delete file " + file.getName(), Level.WARNING);
}
}
boolean deletedData = zoneFolder.delete();
if (!deletedData) {
War.war.log("Failed to delete folder " + zoneFolder.getName(), Level.WARNING);
}
File zoneFile = new File(War.war.getDataFolder().getPath() + "/warzone-" + name + ".txt");
if (zoneFile.exists()) {
deletedData = zoneFile.delete();
if (!deletedData) {
War.war.log("Failed to delete file " + zoneFile.getName(), Level.WARNING);
}
}
zoneFile = new File(War.war.getDataFolder().getPath() + "/warzone-" + name + ".yml");
deletedData = zoneFile.delete();
if (!deletedData) {
War.war.log("Failed to delete file " + zoneFile.getName(), Level.WARNING);
public static void delete(Warzone zone) {
// Kill old warzone, but use it to create the renamed copy
zone.unload();
zone.getVolume().resetBlocks(); // We're need a clean land
String name = zone.getName();
// Move old files
(new File(War.war.getDataFolder().getPath() + "/temp/deleted/")).mkdir();
(new File(War.war.getDataFolder().getPath() + "/warzone-" + name + ".yml")).renameTo(new File(War.war.getDataFolder().getPath() + "/temp/deleted/warzone-" + name + ".yml"));
(new File(War.war.getDataFolder().getPath() + "/temp/deleted/dat/warzone-" + name)).mkdirs();
String oldPath = War.war.getDataFolder().getPath() + "/dat/warzone-" + name + "/";
File oldZoneFolder = new File(oldPath);
File[] oldZoneFiles = oldZoneFolder.listFiles();
for (File file : oldZoneFiles) {
file.renameTo(new File(War.war.getDataFolder().getPath() + "/temp/deleted/dat/warzone-" + name + "/" + file.getName()));
}
oldZoneFolder.delete();
}
}

View File

@ -0,0 +1,22 @@
package com.tommytony.war.utility;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.logging.Formatter;
import java.util.logging.LogRecord;
public class WarLogFormatter extends Formatter {
@Override
public String format(LogRecord arg0) {
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
StringBuilder b = new StringBuilder();
b.append(dateFormat.format(new Date()));
b.append(" [");
b.append(arg0.getLevel());
b.append("] ");
b.append(arg0.getMessage());
b.append(System.getProperty("line.separator"));
return b.toString();
}
}

View File

@ -27,9 +27,8 @@ import com.tommytony.war.job.BlockResetJob;
*
*/
public class Volume {
private final String name;
private String name;
private World world;
// private final Warzone warzone;
private BlockInfo cornerOne;
private BlockInfo cornerTwo;
private int[][][] blockTypes = null;
@ -41,6 +40,10 @@ public class Volume {
this.name = name;
this.world = world;
}
public void setName(String newName) {
this.name = newName;
}
public World getWorld() {
return this.world;
@ -63,9 +66,6 @@ public class Volume {
}
public int saveBlocks() {
// BlockSaveJob job = new BlockSaveJob(this);
// war.getServer().getScheduler().scheduleSyncDelayedTask(war, job);
// return 0;
int noOfSavedBlocks = 0;
int x = 0;
int y = 0;