Remove support for undoing autogenerated arenas.

The autogenerated arenas are backed up in a file that isn't valid in 1.13. It's also buggy, inducing a false sense of safety. Instead of trying to hack it together for 1.13, let's remove it and see if we can't live without it.
This commit is contained in:
Andreas Troelsen 2018-07-23 01:13:08 +02:00
parent 5937eb0631
commit 3b024235dc
3 changed files with 0 additions and 129 deletions

View File

@ -4,7 +4,6 @@ import com.garbagemule.MobArena.framework.Arena;
import com.garbagemule.MobArena.framework.ArenaMaster;
import com.garbagemule.MobArena.region.ArenaRegion;
import com.garbagemule.MobArena.things.Thing;
import com.garbagemule.MobArena.util.EntityPosition;
import com.garbagemule.MobArena.util.ItemParser;
import com.garbagemule.MobArena.util.TextUtils;
import org.bukkit.Location;
@ -19,11 +18,6 @@ import org.bukkit.entity.Wolf;
import org.bukkit.inventory.ItemStack;
import org.bukkit.plugin.java.JavaPlugin;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
@ -36,10 +30,6 @@ import java.util.Set;
public class MAUtils
{
public static final String sep = File.separator;
/* ///////////////////////////////////////////////////////////////////// //
INITIALIZATION METHODS
@ -260,9 +250,6 @@ public class MAUtils
*/
public static boolean doooooItHippieMonster(Location loc, int radius, String name, MobArena plugin)
{
// Try to restore the old patch first.
undoItHippieMonster(name, plugin, false);
// Grab the Configuration and ArenaMaster
ArenaMaster am = plugin.getArenaMaster();
@ -285,37 +272,6 @@ public class MAUtils
int lz1 = z1;
int lz2 = z1 + 6;
// Save the precious patch
HashMap<EntityPosition,Integer> preciousPatch = new HashMap<>();
Location lo;
int id;
for (int i = x1; i <= x2; i++)
{
for (int j = ly1; j <= y2; j++)
{
for (int k = z1; k <= z2; k++)
{
lo = world.getBlockAt(i,j,k).getLocation();
id = world.getBlockAt(i,j,k).getTypeId();
preciousPatch.put(new EntityPosition(lo),id);
}
}
}
try
{
new File("plugins" + sep + "MobArena" + sep + "agbackup").mkdir();
FileOutputStream fos = new FileOutputStream("plugins" + sep + "MobArena" + sep + "agbackup" + sep + name + ".tmp");
ObjectOutputStream oos = new ObjectOutputStream(fos);
oos.writeObject(preciousPatch);
oos.close();
}
catch (Exception e)
{
e.printStackTrace();
plugin.getLogger().warning("Couldn't create backup file. Aborting auto-generate...");
return false;
}
// Build some monster walls.
for (int i = x1; i <= x2; i++)
{
@ -433,41 +389,4 @@ public class MAUtils
am.reloadConfig();
return true;
}
/**
* This fixes everything!
*/
@SuppressWarnings("unchecked")
public static boolean undoItHippieMonster(String name, MobArena plugin, boolean error)
{
File file = new File("plugins" + sep + "MobArena" + sep + "agbackup" + sep + name + ".tmp");
HashMap<EntityPosition,Integer> preciousPatch;
try
{
FileInputStream fis = new FileInputStream(file);
ObjectInputStream ois = new ObjectInputStream(fis);
preciousPatch = (HashMap<EntityPosition,Integer>) ois.readObject();
ois.close();
}
catch (Exception e)
{
if (error) plugin.getLogger().warning("Couldn't find backup file for arena '" + name + "'");
return false;
}
World world = plugin.getServer().getWorld(preciousPatch.keySet().iterator().next().getWorld());
for (Map.Entry<EntityPosition,Integer> entry : preciousPatch.entrySet())
{
world.getBlockAt(entry.getKey().getLocation(world)).setTypeId(entry.getValue());
}
plugin.getConfig().set("arenas." + name, null);
plugin.saveConfig();
file.delete();
plugin.getArenaMaster().reloadConfig();
return true;
}
}

View File

@ -8,7 +8,6 @@ import com.garbagemule.MobArena.commands.admin.ForceCommand;
import com.garbagemule.MobArena.commands.admin.KickCommand;
import com.garbagemule.MobArena.commands.admin.RestoreCommand;
import com.garbagemule.MobArena.commands.setup.AddArenaCommand;
import com.garbagemule.MobArena.commands.setup.AutoDegenerateCommand;
import com.garbagemule.MobArena.commands.setup.AutoGenerateCommand;
import com.garbagemule.MobArena.commands.setup.CheckDataCommand;
import com.garbagemule.MobArena.commands.setup.CheckSpawnsCommand;
@ -240,7 +239,6 @@ public class CommandHandler implements CommandExecutor
register(RemoveLeaderboardCommand.class);
register(AutoGenerateCommand.class);
register(AutoDegenerateCommand.class);
}
/**

View File

@ -1,46 +0,0 @@
package com.garbagemule.MobArena.commands.setup;
import com.garbagemule.MobArena.MAUtils;
import com.garbagemule.MobArena.Msg;
import com.garbagemule.MobArena.commands.Command;
import com.garbagemule.MobArena.commands.CommandInfo;
import com.garbagemule.MobArena.framework.Arena;
import com.garbagemule.MobArena.framework.ArenaMaster;
import org.bukkit.command.CommandSender;
@CommandInfo(
name = "autodegenerate",
pattern = "auto(\\-)?degenerate",
usage = "/ma autodegenerate <arena>",
desc = "autodegenerate an existing arena",
permission = "mobarena.setup.autodegenerate"
)
public class AutoDegenerateCommand implements Command
{
@Override
public boolean execute(ArenaMaster am, CommandSender sender, String... args) {
// Require an arena name
if (args.length != 1) return false;
// We have to make sure at least one arena exists before degenerating
if (am.getArenas().size() < 2) {
am.getGlobalMessenger().tell(sender, "At least one arena must exist!");
return true;
}
// Check if arena exists.
Arena arena = am.getArenaWithName(args[0]);
if (arena == null) {
am.getGlobalMessenger().tell(sender, Msg.ARENA_DOES_NOT_EXIST);
return true;
}
if (!MAUtils.undoItHippieMonster(args[0], am.getPlugin(), true)) {
am.getGlobalMessenger().tell(sender, "Could not degenerate arena.");
return true;
}
am.getGlobalMessenger().tell(sender, "Arena with name '" + args[0] + "' degenerated.");
return true;
}
}