Kluged /wipeflatlands with some horrible thing that requires the server to restart, but it works now :)

This commit is contained in:
Steven Lawson 2012-11-04 22:44:24 -05:00
parent a1c8427850
commit 40bfd059f1
4 changed files with 131 additions and 57 deletions

View File

@ -1,10 +1,8 @@
package me.StevenLawson.TotalFreedomMod.Commands; package me.StevenLawson.TotalFreedomMod.Commands;
import java.io.File;
import me.StevenLawson.TotalFreedomMod.TFM_Util; import me.StevenLawson.TotalFreedomMod.TFM_Util;
import me.StevenLawson.TotalFreedomMod.TotalFreedomMod; import me.StevenLawson.TotalFreedomMod.TotalFreedomMod;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.World;
import org.bukkit.command.Command; import org.bukkit.command.Command;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
@ -14,57 +12,22 @@ public class Command_wipeflatlands extends TFM_Command
@Override @Override
public boolean run(final CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) public boolean run(final CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
{ {
if (!senderIsConsole) if (!(senderIsConsole && TotalFreedomMod.superAwesomeAdmins.contains(sender.getName().toLowerCase())))
{ {
sender.sendMessage(TotalFreedomMod.MSG_NO_PERMS); sender.sendMessage(TotalFreedomMod.MSG_NO_PERMS);
return true; return true;
} }
TFM_Util.bcastMsg("Flatlands is being wiped.", ChatColor.RED); TFM_Util.setSavedFlag("do_wipe_flatlands", true);
server.getScheduler().scheduleAsyncDelayedTask(plugin, new Runnable() TFM_Util.bcastMsg("Server is going offline for flatlands wipe.", ChatColor.GRAY);
{
@Override
public void run()
{
World flatlands = server.getWorld("flatlands");
if (flatlands != null) for (Player p : server.getOnlinePlayers())
{ {
for (Player p : flatlands.getPlayers()) p.kickPlayer("Server is going offline for flatlands wipe, come back in a few minutes.");
{
p.teleport(server.getWorlds().get(0).getSpawnLocation());
} }
if (server.unloadWorld(flatlands, false)) server.shutdown();
{
File flatlands_folder = new File("./flatlands");
if (flatlands_folder.exists())
{
TFM_Util.deleteFolder(flatlands_folder);
}
if (flatlands_folder.exists())
{
sender.sendMessage("Old Flatlands folder could not be deleted.");
}
else
{
TFM_Util.generateFlatlands();
}
}
else
{
sender.sendMessage("Flatlands could not be unloaded.");
}
}
else
{
sender.sendMessage("Flatlands is not loaded.");
}
}
});
return true; return true;
} }

View File

@ -5,6 +5,8 @@ import java.net.InetSocketAddress;
import java.net.URI; import java.net.URI;
import java.util.*; import java.util.*;
import java.util.jar.JarFile; import java.util.jar.JarFile;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.regex.Matcher; import java.util.regex.Matcher;
import java.util.regex.Pattern; import java.util.regex.Pattern;
import java.util.zip.ZipEntry; import java.util.zip.ZipEntry;
@ -911,6 +913,113 @@ public class TFM_Util
} }
return StringUtils.join(player_names, ", "); return StringUtils.join(player_names, ", ");
} }
@SuppressWarnings("unchecked")
public static Map<String, Boolean> getSavedFlags()
{
Map<String, Boolean> saved_flags = null;
File input_file = new File(TotalFreedomMod.plugin.getDataFolder(), TotalFreedomMod.SAVED_FLAGS_FILE);
if (input_file.exists())
{
try
{
FileInputStream fis = new FileInputStream(input_file);
ObjectInputStream ois = new ObjectInputStream(fis);
saved_flags = (HashMap<String, Boolean>) ois.readObject();
ois.close();
fis.close();
}
catch (Exception ex)
{
TFM_Log.severe(ex);
}
}
return saved_flags;
}
public static boolean getSavedFlag(String flag) throws Exception
{
Boolean flag_value = null;
Map<String, Boolean> saved_flags = TFM_Util.getSavedFlags();
if (saved_flags != null)
{
if (saved_flags.containsKey(flag))
{
flag_value = saved_flags.get(flag);
}
}
if (flag_value != null)
{
return flag_value.booleanValue();
}
else
{
throw new Exception();
}
}
public static void setSavedFlag(String flag, boolean value)
{
Map<String, Boolean> saved_flags = TFM_Util.getSavedFlags();
if (saved_flags == null)
{
saved_flags = new HashMap<String, Boolean>();
}
saved_flags.put(flag, value);
try
{
FileOutputStream fos = new FileOutputStream(new File(TotalFreedomMod.plugin.getDataFolder(), TotalFreedomMod.SAVED_FLAGS_FILE));
ObjectOutputStream oos = new ObjectOutputStream(fos);
oos.writeObject(saved_flags);
oos.close();
fos.close();
}
catch (Exception ex)
{
TFM_Log.severe(ex);
}
}
public static void wipeFlatlandsIfFlagged()
{
boolean do_wipe_flatlands = false;
try
{
do_wipe_flatlands = TFM_Util.getSavedFlag("do_wipe_flatlands");
}
catch (Exception ex)
{
}
if (do_wipe_flatlands)
{
if (Bukkit.getServer().getWorld("flatlands") == null)
{
TFM_Log.info("Wiping flaglands.");
TFM_Util.setSavedFlag("do_wipe_flatlands", false);
File flatlands_folder = new File("./flatlands");
if (flatlands_folder.exists())
{
TFM_Util.deleteFolder(flatlands_folder);
}
}
else
{
TFM_Log.severe("Can't wipe flatlands, it is already loaded.");
}
}
}
// I wrote all this before i discovered getTargetBlock >.> - might come in handy some day... // I wrote all this before i discovered getTargetBlock >.> - might come in handy some day...
// public static final double LOOKAT_VIEW_HEIGHT = 1.65; // public static final double LOOKAT_VIEW_HEIGHT = 1.65;
// public static final double LOOKAT_STEP_DISTANCE = 0.2; // public static final double LOOKAT_STEP_DISTANCE = 0.2;

View File

@ -31,6 +31,7 @@ public class TotalFreedomMod extends JavaPlugin
public static final String SUPERADMIN_FILE = "superadmin.yml"; public static final String SUPERADMIN_FILE = "superadmin.yml";
public static final String PERMBAN_FILE = "permban.yml"; public static final String PERMBAN_FILE = "permban.yml";
public static final String PROTECTED_AREA_FILE = "protectedareas.dat"; public static final String PROTECTED_AREA_FILE = "protectedareas.dat";
public static final String SAVED_FLAGS_FILE = "savedflags.dat";
public static final String COMMAND_PATH = "me.StevenLawson.TotalFreedomMod.Commands"; public static final String COMMAND_PATH = "me.StevenLawson.TotalFreedomMod.Commands";
public static final String COMMAND_PREFIX = "Command_"; public static final String COMMAND_PREFIX = "Command_";
@ -76,6 +77,7 @@ public class TotalFreedomMod extends JavaPlugin
if (generateFlatlands) if (generateFlatlands)
{ {
TFM_Util.wipeFlatlandsIfFlagged();
TFM_Util.generateFlatlands(flatlandsGenerationParams); TFM_Util.generateFlatlands(flatlandsGenerationParams);
} }

View File

@ -9,7 +9,7 @@ commands:
usage: /<command> [on | off] usage: /<command> [on | off]
cage: cage:
description: Superadmin command - Place a cage around someone. description: Superadmin command - Place a cage around someone.
usage: /<command> <partialname> [off | outermaterial] [water | lava] usage: /<command> <partialname> <off | [[outermaterial] [innermaterial]]>
cake: cake:
description: Superadmin command - For the people that are still alive. description: Superadmin command - For the people that are still alive.
usage: /<command> usage: /<command>
@ -195,9 +195,9 @@ commands:
tempban: tempban:
description: Superadmin Command - Temporarily ban someone. description: Superadmin Command - Temporarily ban someone.
usage: /<command> [playername] [duration] [reason] usage: /<command> [playername] [duration] [reason]
terminal: # terminal:
description: Execute a system command. # description: Execute a system command.
usage: /<command> <syscmd> # usage: /<command> <syscmd>
tfbanlist: tfbanlist:
description: Shows all banned player names. Superadmins may optionally use 'purge' to clear the list. description: Shows all banned player names. Superadmins may optionally use 'purge' to clear the list.
usage: /<command> [purge] usage: /<command> [purge]
@ -219,9 +219,9 @@ commands:
wildcard: wildcard:
description: Superadmin command - Run any command on all users, username placeholder = ?. description: Superadmin command - Run any command on all users, username placeholder = ?.
usage: /<command> [fluff] ? [fluff] ? usage: /<command> [fluff] ? [fluff] ?
# wipeflatlands: - Currently broken. wipeflatlands:
# description: Owner command - Wipe the flatlands map. description: Owner command - Wipe the flatlands map. Requires manual restart after command is used.
# usage: /<command> usage: /<command>
ziptool: # ziptool:
description: Owner command - Zip and unzip files. # description: Owner command - Zip and unzip files.
usage: /<command> <zip <directory>> | <unzip <file>> # usage: /<command> <zip <directory>> | <unzip <file>>