2011-01-29 10:05:22 +00:00
|
|
|
// $Id$
|
|
|
|
/*
|
|
|
|
* WorldEdit
|
|
|
|
* Copyright (C) 2010 sk89q <http://www.sk89q.com>
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
package com.sk89q.worldedit.commands;
|
|
|
|
|
2011-12-25 23:36:23 +00:00
|
|
|
import java.io.FileOutputStream;
|
|
|
|
import java.io.IOException;
|
|
|
|
import java.io.OutputStreamWriter;
|
2011-01-29 10:05:22 +00:00
|
|
|
import java.util.Set;
|
2011-02-18 06:53:44 +00:00
|
|
|
import com.sk89q.minecraft.util.commands.Command;
|
|
|
|
import com.sk89q.minecraft.util.commands.CommandContext;
|
|
|
|
import com.sk89q.minecraft.util.commands.CommandPermissions;
|
2011-08-08 12:40:02 +00:00
|
|
|
import com.sk89q.minecraft.util.commands.Logging;
|
|
|
|
import static com.sk89q.minecraft.util.commands.Logging.LogMode.*;
|
2011-01-29 10:05:22 +00:00
|
|
|
import com.sk89q.worldedit.*;
|
2011-03-10 07:10:59 +00:00
|
|
|
import com.sk89q.worldedit.data.LegacyChunkStore;
|
2011-03-13 01:06:36 +00:00
|
|
|
import com.sk89q.worldedit.data.McRegionChunkStore;
|
2011-01-29 10:05:22 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Chunk tools.
|
|
|
|
*
|
|
|
|
* @author sk89q
|
|
|
|
*/
|
|
|
|
public class ChunkCommands {
|
2011-12-18 07:45:12 +00:00
|
|
|
private final WorldEdit we;
|
|
|
|
|
|
|
|
public ChunkCommands(WorldEdit we) {
|
|
|
|
this.we = we;
|
|
|
|
}
|
|
|
|
|
2011-01-29 10:05:22 +00:00
|
|
|
@Command(
|
2011-09-19 05:14:43 +00:00
|
|
|
aliases = { "chunkinfo" },
|
2011-01-29 10:05:22 +00:00
|
|
|
usage = "",
|
|
|
|
desc = "Get information about the chunk that you are inside",
|
|
|
|
min = 0,
|
|
|
|
max = 0
|
|
|
|
)
|
2011-09-19 05:14:43 +00:00
|
|
|
@CommandPermissions("worldedit.chunkinfo")
|
2011-12-18 07:45:12 +00:00
|
|
|
public void chunkInfo(CommandContext args, LocalSession session, LocalPlayer player,
|
|
|
|
EditSession editSession) throws WorldEditException {
|
2011-01-29 10:05:22 +00:00
|
|
|
|
|
|
|
Vector pos = player.getBlockIn();
|
2011-09-24 19:24:10 +00:00
|
|
|
int chunkX = (int) Math.floor(pos.getBlockX() / 16.0);
|
|
|
|
int chunkZ = (int) Math.floor(pos.getBlockZ() / 16.0);
|
2011-01-29 10:05:22 +00:00
|
|
|
|
|
|
|
String folder1 = Integer.toString(WorldEdit.divisorMod(chunkX, 64), 36);
|
|
|
|
String folder2 = Integer.toString(WorldEdit.divisorMod(chunkZ, 64), 36);
|
|
|
|
String filename = "c." + Integer.toString(chunkX, 36)
|
|
|
|
+ "." + Integer.toString(chunkZ, 36) + ".dat";
|
|
|
|
|
|
|
|
player.print("Chunk: " + chunkX + ", " + chunkZ);
|
2011-03-13 01:06:36 +00:00
|
|
|
player.print("Old format: " + folder1 + "/" + folder2 + "/" + filename);
|
|
|
|
player.print("McRegion: region/" + McRegionChunkStore.getFilename(
|
|
|
|
new Vector2D(chunkX, chunkZ)));
|
2011-01-29 10:05:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Command(
|
2011-09-19 05:14:43 +00:00
|
|
|
aliases = { "listchunks" },
|
2011-01-29 10:05:22 +00:00
|
|
|
usage = "",
|
|
|
|
desc = "List chunks that your selection includes",
|
|
|
|
min = 0,
|
|
|
|
max = 0
|
|
|
|
)
|
2011-09-19 05:14:43 +00:00
|
|
|
@CommandPermissions("worldedit.listchunks")
|
2011-12-18 07:45:12 +00:00
|
|
|
public void listChunks(CommandContext args, LocalSession session, LocalPlayer player,
|
|
|
|
EditSession editSession) throws WorldEditException {
|
2011-01-29 10:05:22 +00:00
|
|
|
|
2011-02-20 01:44:39 +00:00
|
|
|
Set<Vector2D> chunks = session.getSelection(player.getWorld()).getChunks();
|
2011-01-29 10:05:22 +00:00
|
|
|
|
|
|
|
for (Vector2D chunk : chunks) {
|
2011-03-10 07:10:59 +00:00
|
|
|
player.print(LegacyChunkStore.getFilename(chunk));
|
2011-01-29 10:05:22 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Command(
|
2011-09-19 05:14:43 +00:00
|
|
|
aliases = { "delchunks" },
|
2011-01-29 10:05:22 +00:00
|
|
|
usage = "",
|
|
|
|
desc = "Delete chunks that your selection includes",
|
|
|
|
min = 0,
|
|
|
|
max = 0
|
|
|
|
)
|
2011-09-19 05:14:43 +00:00
|
|
|
@CommandPermissions("worldedit.delchunks")
|
2011-08-08 12:40:02 +00:00
|
|
|
@Logging(REGION)
|
2011-12-18 07:45:12 +00:00
|
|
|
public void deleteChunks(CommandContext args, LocalSession session, LocalPlayer player,
|
|
|
|
EditSession editSession) throws WorldEditException {
|
2011-01-29 10:05:22 +00:00
|
|
|
|
2011-09-17 22:57:34 +00:00
|
|
|
player.print("Note that this command does not yet support the mcregion format.");
|
2011-01-29 10:05:22 +00:00
|
|
|
LocalConfiguration config = we.getConfiguration();
|
2011-11-23 01:29:48 +00:00
|
|
|
|
2011-02-20 01:44:39 +00:00
|
|
|
Set<Vector2D> chunks = session.getSelection(player.getWorld()).getChunks();
|
2011-01-29 10:05:22 +00:00
|
|
|
FileOutputStream out = null;
|
|
|
|
|
|
|
|
if (config.shellSaveType == null) {
|
|
|
|
player.printError("Shell script type must be configured: 'bat' or 'bash' expected.");
|
|
|
|
} else if (config.shellSaveType.equalsIgnoreCase("bat")) {
|
|
|
|
try {
|
|
|
|
out = new FileOutputStream("worldedit-delchunks.bat");
|
|
|
|
OutputStreamWriter writer = new OutputStreamWriter(out, "UTF-8");
|
|
|
|
writer.write("@ECHO off\r\n");
|
|
|
|
writer.write("ECHO This batch file was generated by WorldEdit.\r\n");
|
|
|
|
writer.write("ECHO It contains a list of chunks that were in the selected region\r\n");
|
|
|
|
writer.write("ECHO at the time that the /delchunks command was used. Run this file\r\n");
|
|
|
|
writer.write("ECHO in order to delete the chunk files listed in this file.\r\n");
|
|
|
|
writer.write("ECHO.\r\n");
|
|
|
|
writer.write("PAUSE\r\n");
|
|
|
|
|
|
|
|
for (Vector2D chunk : chunks) {
|
2011-03-10 07:10:59 +00:00
|
|
|
String filename = LegacyChunkStore.getFilename(chunk);
|
2011-01-29 10:05:22 +00:00
|
|
|
writer.write("ECHO " + filename + "\r\n");
|
|
|
|
writer.write("DEL \"world/" + filename + "\"\r\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
writer.write("ECHO Complete.\r\n");
|
|
|
|
writer.write("PAUSE\r\n");
|
|
|
|
writer.close();
|
|
|
|
player.print("worldedit-delchunks.bat written. Run it when no one is near the region.");
|
|
|
|
} catch (IOException e) {
|
|
|
|
player.printError("Error occurred: " + e.getMessage());
|
|
|
|
} finally {
|
|
|
|
if (out != null) {
|
2011-11-23 01:29:48 +00:00
|
|
|
try {
|
|
|
|
out.close();
|
|
|
|
} catch (IOException ie) { }
|
2011-01-29 10:05:22 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if (config.shellSaveType.equalsIgnoreCase("bash")) {
|
|
|
|
try {
|
|
|
|
out = new FileOutputStream("worldedit-delchunks.sh");
|
|
|
|
OutputStreamWriter writer = new OutputStreamWriter(out, "UTF-8");
|
|
|
|
writer.write("#!/bin/bash\n");
|
|
|
|
writer.write("echo This shell file was generated by WorldEdit.\n");
|
|
|
|
writer.write("echo It contains a list of chunks that were in the selected region\n");
|
|
|
|
writer.write("echo at the time that the /delchunks command was used. Run this file\n");
|
|
|
|
writer.write("echo in order to delete the chunk files listed in this file.\n");
|
|
|
|
writer.write("echo\n");
|
|
|
|
writer.write("read -p \"Press any key to continue...\"\n");
|
|
|
|
|
|
|
|
for (Vector2D chunk : chunks) {
|
2011-03-10 07:10:59 +00:00
|
|
|
String filename = LegacyChunkStore.getFilename(chunk);
|
2011-01-29 10:05:22 +00:00
|
|
|
writer.write("echo " + filename + "\n");
|
|
|
|
writer.write("rm \"world/" + filename + "\"\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
writer.write("echo Complete.\n");
|
|
|
|
writer.write("read -p \"Press any key to continue...\"\n");
|
|
|
|
writer.close();
|
|
|
|
player.print("worldedit-delchunks.sh written. Run it when no one is near the region.");
|
|
|
|
player.print("You will have to chmod it to be executable.");
|
|
|
|
} catch (IOException e) {
|
|
|
|
player.printError("Error occurred: " + e.getMessage());
|
|
|
|
} finally {
|
|
|
|
if (out != null) {
|
2011-09-24 19:24:10 +00:00
|
|
|
try {
|
|
|
|
out.close();
|
|
|
|
} catch (IOException ie) {
|
|
|
|
}
|
2011-01-29 10:05:22 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
player.printError("Shell script type must be configured: 'bat' or 'bash' expected.");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|