fixes. + added DebugClaimTest command

This commit is contained in:
boy0001 2014-10-22 23:22:00 +11:00
parent b0351b5c99
commit 2f90adac52
7 changed files with 326 additions and 130 deletions

View File

@ -371,7 +371,7 @@ public enum C {
}
}
if (this.s.length() < 1) {
return this.d.replace("\\n", "\n");
return "";
}
return this.s.replace("\\n", "\n");
}

View File

@ -595,7 +595,6 @@ public class PlotHelper {
PlayerFunctions.sendMessage(requester, C.WAIT_FOR_TIMER);
return;
}
PlayerFunctions.sendMessage(requester, C.GENERATING_WALL_FILLING);
World world = requester.getWorld();
PlotManager manager = PlotMain.getPlotManager(world);
PlotWorld plotworld = PlotMain.getWorldSettings(world);
@ -612,7 +611,6 @@ public class PlotHelper {
return;
}
PlayerFunctions.sendMessage(requester, C.GENERATING_FLOOR);
World world = requester.getWorld();
PlotManager manager = PlotMain.getPlotManager(world);
PlotWorld plotworld = PlotMain.getWorldSettings(world);

View File

@ -220,129 +220,126 @@ public class SchematicHandler {
// save as a schematic
int MAX_SIZE = Short.MAX_VALUE - Short.MIN_VALUE;
int width = region.getWidth();
int height = region.getHeight();
int length = region.getLength();
return null;
if (width > MAX_SIZE) {
throw new IllegalArgumentException("Width of region too large for a .schematic");
}
if (height > MAX_SIZE) {
throw new IllegalArgumentException("Height of region too large for a .schematic");
}
if (length > MAX_SIZE) {
throw new IllegalArgumentException("Length of region too large for a .schematic");
}
// int width = region.getWidth();
// int height = region.getHeight();
// int length = region.getLength();
//
// if (width > MAX_SIZE) {
// throw new IllegalArgumentException("Width of region too large for a .schematic");
// }
// if (height > MAX_SIZE) {
// throw new IllegalArgumentException("Height of region too large for a .schematic");
// }
// if (length > MAX_SIZE) {
// throw new IllegalArgumentException("Length of region too large for a .schematic");
// }
//
// // ====================================================================
// // Metadata
// // ====================================================================
//
// HashMap<String, Tag> schematic = new HashMap<String, Tag>();
// schematic.put("Width", new ShortTag("Width", (short) width));
// schematic.put("Length", new ShortTag("Length", (short) length));
// schematic.put("Height", new ShortTag("Height", (short) height));
// schematic.put("Materials", new StringTag("Materials", "Alpha"));
// schematic.put("WEOriginX", new IntTag("WEOriginX", min.getBlockX()));
// schematic.put("WEOriginY", new IntTag("WEOriginY", min.getBlockY()));
// schematic.put("WEOriginZ", new IntTag("WEOriginZ", min.getBlockZ()));
// schematic.put("WEOffsetX", new IntTag("WEOffsetX", offset.getBlockX()));
// schematic.put("WEOffsetY", new IntTag("WEOffsetY", offset.getBlockY()));
// schematic.put("WEOffsetZ", new IntTag("WEOffsetZ", offset.getBlockZ()));
//
// // ====================================================================
// // Block handling
// // ====================================================================
//
// byte[] blocks = new byte[width * height * length];
// byte[] addBlocks = null;
// byte[] blockData = new byte[width * height * length];
// List<Tag> tileEntities = new ArrayList<Tag>();
//
// for (Vector point : region) {
// Vector relative = point.subtract(min);
// int x = relative.getBlockX();
// int y = relative.getBlockY();
// int z = relative.getBlockZ();
//
// int index = y * width * length + z * width + x;
// BaseBlock block = clipboard.getBlock(point);
//
// // Save 4096 IDs in an AddBlocks section
// if (block.getType() > 255) {
// if (addBlocks == null) { // Lazily create section
// addBlocks = new byte[(blocks.length >> 1) + 1];
// }
//
// addBlocks[index >> 1] = (byte) (((index & 1) == 0) ?
// addBlocks[index >> 1] & 0xF0 | (block.getType() >> 8) & 0xF
// : addBlocks[index >> 1] & 0xF | ((block.getType() >> 8) & 0xF) << 4);
// }
//
// blocks[index] = (byte) block.getType();
// blockData[index] = (byte) block.getData();
//
// // Store TileEntity data
// CompoundTag rawTag = block.getNbtData();
// if (rawTag != null) {
// Map<String, Tag> values = new HashMap<String, Tag>();
// for (Entry<String, Tag> entry : rawTag.getValue().entrySet()) {
// values.put(entry.getKey(), entry.getValue());
// }
//
// values.put("id", new StringTag("id", block.getNbtId()));
// values.put("x", new IntTag("x", x));
// values.put("y", new IntTag("y", y));
// values.put("z", new IntTag("z", z));
//
// CompoundTag tileEntityTag = new CompoundTag("TileEntity", values);
// tileEntities.add(tileEntityTag);
// }
// }
//
// schematic.put("Blocks", new ByteArrayTag("Blocks", blocks));
// schematic.put("Data", new ByteArrayTag("Data", blockData));
// schematic.put("TileEntities", new ListTag("TileEntities", CompoundTag.class, tileEntities));
//
// if (addBlocks != null) {
// schematic.put("AddBlocks", new ByteArrayTag("AddBlocks", addBlocks));
// }
//
// // ====================================================================
// // Entities
// // ====================================================================
//
// List<Tag> entities = new ArrayList<Tag>();
// for (Entity entity : clipboard.getEntities()) {
// BaseEntity state = entity.getState();
//
// if (state != null) {
// Map<String, Tag> values = new HashMap<String, Tag>();
//
// // Put NBT provided data
// CompoundTag rawTag = state.getNbtData();
// if (rawTag != null) {
// values.putAll(rawTag.getValue());
// }
//
// // Store our location data, overwriting any
// values.put("id", new StringTag("id", state.getTypeId()));
// values.put("Pos", writeVector(entity.getLocation().toVector(), "Pos"));
// values.put("Rotation", writeRotation(entity.getLocation(), "Rotation"));
//
// CompoundTag entityTag = new CompoundTag("Entity", values);
// entities.add(entityTag);
// }
// }
//
// schematic.put("Entities", new ListTag("Entities", CompoundTag.class, entities));
//
//
// CompoundTag schematicTag = new CompoundTag("Schematic", schematic);
// return schematicTag;
// ====================================================================
// Metadata
// ====================================================================
HashMap<String, Tag> schematic = new HashMap<String, Tag>();
schematic.put("Width", new ShortTag("Width", (short) width));
schematic.put("Length", new ShortTag("Length", (short) length));
schematic.put("Height", new ShortTag("Height", (short) height));
schematic.put("Materials", new StringTag("Materials", "Alpha"));
schematic.put("WEOriginX", new IntTag("WEOriginX", min.getBlockX()));
schematic.put("WEOriginY", new IntTag("WEOriginY", min.getBlockY()));
schematic.put("WEOriginZ", new IntTag("WEOriginZ", min.getBlockZ()));
schematic.put("WEOffsetX", new IntTag("WEOffsetX", offset.getBlockX()));
schematic.put("WEOffsetY", new IntTag("WEOffsetY", offset.getBlockY()));
schematic.put("WEOffsetZ", new IntTag("WEOffsetZ", offset.getBlockZ()));
// ====================================================================
// Block handling
// ====================================================================
byte[] blocks = new byte[width * height * length];
byte[] addBlocks = null;
byte[] blockData = new byte[width * height * length];
List<Tag> tileEntities = new ArrayList<Tag>();
for (Vector point : region) {
Vector relative = point.subtract(min);
int x = relative.getBlockX();
int y = relative.getBlockY();
int z = relative.getBlockZ();
int index = y * width * length + z * width + x;
BaseBlock block = clipboard.getBlock(point);
// Save 4096 IDs in an AddBlocks section
if (block.getType() > 255) {
if (addBlocks == null) { // Lazily create section
addBlocks = new byte[(blocks.length >> 1) + 1];
}
addBlocks[index >> 1] = (byte) (((index & 1) == 0) ?
addBlocks[index >> 1] & 0xF0 | (block.getType() >> 8) & 0xF
: addBlocks[index >> 1] & 0xF | ((block.getType() >> 8) & 0xF) << 4);
}
blocks[index] = (byte) block.getType();
blockData[index] = (byte) block.getData();
// Store TileEntity data
CompoundTag rawTag = block.getNbtData();
if (rawTag != null) {
Map<String, Tag> values = new HashMap<String, Tag>();
for (Entry<String, Tag> entry : rawTag.getValue().entrySet()) {
values.put(entry.getKey(), entry.getValue());
}
values.put("id", new StringTag("id", block.getNbtId()));
values.put("x", new IntTag("x", x));
values.put("y", new IntTag("y", y));
values.put("z", new IntTag("z", z));
CompoundTag tileEntityTag = new CompoundTag("TileEntity", values);
tileEntities.add(tileEntityTag);
}
}
schematic.put("Blocks", new ByteArrayTag("Blocks", blocks));
schematic.put("Data", new ByteArrayTag("Data", blockData));
schematic.put("TileEntities", new ListTag("TileEntities", CompoundTag.class, tileEntities));
if (addBlocks != null) {
schematic.put("AddBlocks", new ByteArrayTag("AddBlocks", addBlocks));
}
// ====================================================================
// Entities
// ====================================================================
List<Tag> entities = new ArrayList<Tag>();
for (Entity entity : clipboard.getEntities()) {
BaseEntity state = entity.getState();
if (state != null) {
Map<String, Tag> values = new HashMap<String, Tag>();
// Put NBT provided data
CompoundTag rawTag = state.getNbtData();
if (rawTag != null) {
values.putAll(rawTag.getValue());
}
// Store our location data, overwriting any
values.put("id", new StringTag("id", state.getTypeId()));
values.put("Pos", writeVector(entity.getLocation().toVector(), "Pos"));
values.put("Rotation", writeRotation(entity.getLocation(), "Rotation"));
CompoundTag entityTag = new CompoundTag("Entity", values);
entities.add(entityTag);
}
}
schematic.put("Entities", new ListTag("Entities", CompoundTag.class, entities));
CompoundTag schematicTag = new CompoundTag("Schematic", schematic);
return schematicTag;
}
public class DataCollection {

View File

@ -25,6 +25,10 @@ public enum Command {
// - /plot list <some parameter to list the most popular, and highest rated
// plots>
INBOX("inbox"),
/**
*
*/
DEBUGCLAIMTEST("debugclaimtest"),
/**
*
*/

View File

@ -0,0 +1,197 @@
/*
* Copyright (c) IntellectualCrafters - 2014. You are not allowed to distribute
* and/or monetize any of our intellectual property. IntellectualCrafters is not
* affiliated with Mojang AB. Minecraft is a trademark of Mojang AB.
*
* >> File = Claim.java >> Generated by: Citymonstret at 2014-08-09 01:41
*/
package com.intellectualcrafters.plot.commands;
import java.util.ArrayList;
import java.util.UUID;
import net.milkbowl.vault.economy.Economy;
import org.bukkit.Bukkit;
import org.bukkit.Chunk;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.block.Block;
import org.bukkit.block.Sign;
import org.bukkit.entity.Player;
import com.google.common.collect.BiMap;
import com.intellectualcrafters.plot.C;
import com.intellectualcrafters.plot.FlagManager;
import com.intellectualcrafters.plot.PlayerFunctions;
import com.intellectualcrafters.plot.Plot;
import com.intellectualcrafters.plot.PlotHelper;
import com.intellectualcrafters.plot.PlotId;
import com.intellectualcrafters.plot.PlotMain;
import com.intellectualcrafters.plot.PlotManager;
import com.intellectualcrafters.plot.PlotWorld;
import com.intellectualcrafters.plot.SchematicHandler;
import com.intellectualcrafters.plot.StringWrapper;
import com.intellectualcrafters.plot.UUIDHandler;
import com.intellectualcrafters.plot.database.DBFunc;
import com.intellectualcrafters.plot.events.PlayerClaimPlotEvent;
/**
* @author Citymonstret
*/
public class DebugClaimTest extends SubCommand {
public DebugClaimTest() {
super(Command.DEBUGCLAIMTEST, "If you accidentally delete your database, this command will attempt to restore all plots based on the data from the plot signs. Execution time may vary", "claim", CommandCategory.INFO, false);
}
@Override
public boolean execute(Player plr, String... args) {
if (plr==null) {
if (args.length<3) {
PlayerFunctions.sendMessage(plr, "If you accidentally delete your database, this command will attempt to restore all plots based on the data from the plot signs. \n\n&cMissing world arg /plot debugclaimtest {world} {PlotId min} {PlotId max}");
return false;
}
World world = Bukkit.getWorld(args[0]);
if (world==null || !PlotMain.isPlotWorld(world)) {
PlayerFunctions.sendMessage(plr, "&cInvalid plot world!");
return false;
}
PlotId min, max;
try {
String[] split1 = args[1].split(";");
String[] split2 = args[2].split(";");
min = new PlotId(Integer.parseInt(split1[0]), Integer.parseInt(split1[1]));
max = new PlotId(Integer.parseInt(split2[0]), Integer.parseInt(split2[1]));
}
catch (Exception e) {
PlayerFunctions.sendMessage(plr, "&cInvalid min/max values. &7The values are to Plot IDs in the format &cX;Y &7where X,Y are the plot coords\nThe conversion will only check the plots in the selected area.");
return false;
}
PlayerFunctions.sendMessage(plr, "&3Sign Block&8->&3PlotSquared&8: &7Beginning sign to plot conversion. This may take a while...");
PlayerFunctions.sendMessage(plr, "&3Sign Block&8->&3PlotSquared&8: Found an excess of 250,000 chunks. Limiting search radius... (~3.8 min)");
PlotManager manager = PlotMain.getPlotManager(world);
PlotWorld plotworld = PlotMain.getWorldSettings(world);
ArrayList<Plot> plots = new ArrayList<Plot>();
for (PlotId id : PlayerFunctions.getPlotSelectionIds(world, min, max)) {
Plot plot = PlotHelper.getPlot(world, id);
boolean contains = PlotMain.getPlots(world).containsKey(plot.id);
if (contains) {
PlayerFunctions.sendMessage(plr, " - &cDB Already contains: "+plot.id);
continue;
}
Location loc = manager.getSignLoc(world, plotworld, plot);
Chunk chunk = world.getChunkAt(loc);
if (!chunk.isLoaded()) {
boolean result = chunk.load(false);
if (!result) {
continue;
}
}
Block block = world.getBlockAt(loc);
if (block!=null) {
if (block.getState() instanceof Sign) {
Sign sign = (Sign) block.getState();
if (sign!=null) {
String line = sign.getLine(2);
if (line!=null && line.length() > 2) {
line = line.substring(2);
BiMap<StringWrapper, UUID> map = UUIDHandler.getUuidMap();
UUID uuid = (map.get(new StringWrapper(line)));
if (uuid==null) {
for (StringWrapper string : map.keySet()) {
if (string.value.toLowerCase().startsWith(line.toLowerCase())) {
uuid = map.get(string);
break;
}
}
}
if (uuid==null) {
uuid = UUIDHandler.getUUID(line);
}
if (uuid!=null) {
PlayerFunctions.sendMessage(plr, " - &aFound plot: "+plot.id+" : "+line);
plot.owner = uuid;
plot.hasChanged = true;
plots.add(plot);
}
else {
PlayerFunctions.sendMessage(plr, " - &cInvalid playername: "+plot.id+" : "+line);
}
}
}
}
}
}
if (plots.size()>0) {
PlayerFunctions.sendMessage(plr, "&3Sign Block&8->&3PlotSquared&8: &7Updating '"+plots.size()+"' plots!");
DBFunc.createPlots(plots);
DBFunc.createAllSettingsAndHelpers(plots);
for (Plot plot : plots) {
PlotMain.updatePlot(plot);
}
PlayerFunctions.sendMessage(plr, "&3Sign Block&8->&3PlotSquared&8: &7Complete!");
}
else {
PlayerFunctions.sendMessage(plr, "No plots were found for the given search.");
}
}
else {
PlayerFunctions.sendMessage(plr, "This debug command can only be executed by console as it has been deemed unsafe if abused.");
}
return true;
}
public static boolean claimPlot(Player player, Plot plot, boolean teleport) {
return claimPlot(player, plot, teleport, "");
}
public static boolean claimPlot(Player player, Plot plot, boolean teleport, String schematic) {
PlayerClaimPlotEvent event = new PlayerClaimPlotEvent(player, plot);
Bukkit.getPluginManager().callEvent(event);
if (!event.isCancelled()) {
PlotHelper.createPlot(player, plot);
PlotHelper.setSign(player, plot);
PlayerFunctions.sendMessage(player, C.CLAIMED);
if (teleport) {
PlotMain.teleportPlayer(player, player.getLocation(), plot);
}
PlotWorld world = PlotMain.getWorldSettings(plot.getWorld());
if (world.SCHEMATIC_ON_CLAIM) {
SchematicHandler handler = new SchematicHandler();
SchematicHandler.Schematic sch;
if (schematic.equals("")) {
sch = handler.getSchematic(world.SCHEMATIC_FILE);
}
else {
sch = handler.getSchematic(schematic);
if (sch == null) {
sch = handler.getSchematic(world.SCHEMATIC_FILE);
}
}
handler.paste(player.getLocation(), sch, plot);
}
plot.settings.setFlags(FlagManager.parseFlags(PlotMain.getWorldSettings(player.getWorld()).DEFAULT_FLAGS));
}
return event.isCancelled();
}
}

View File

@ -30,7 +30,7 @@ public class MainCommand implements CommandExecutor {
private static SubCommand[] _subCommands = new SubCommand[] { new Claim(), new Paste(), new Copy(), new Clipboard(), new Auto(), new Home(), new Visit(),
new TP(), new Set(), new Clear(), new Delete(), new SetOwner(), new Denied(), new Helpers(), new Trusted(),
new Info(), new list(), new Help(), new Debug(), new Schematic(), new plugin(), new Inventory(), new Purge(),
new Reload(), new Merge(), new Unlink(), new Kick(), new Setup() };
new Reload(), new Merge(), new Unlink(), new Kick(), new Setup(), new DebugClaimTest() };
public static ArrayList<SubCommand> subCommands = new ArrayList<SubCommand>() {
{

View File

@ -227,7 +227,7 @@ public class DefaultPlotManager extends PlotManager {
final Location pos2 = PlotHelper.getPlotTopLoc(world, plot.id);
PlotBlock[] plotfloor = dpw.TOP_BLOCK;
PlotBlock[] filling = dpw.TOP_BLOCK;
PlotBlock[] filling = dpw.MAIN_BLOCK;
PlotBlock wall = dpw.WALL_BLOCK;
PlotBlock wall_filling = dpw.WALL_FILLING;
@ -239,7 +239,7 @@ public class DefaultPlotManager extends PlotManager {
block = world.getBlockAt(new Location(world, pos1.getBlockX()-1, dpw.WALL_HEIGHT+1, pos1.getBlockZ()));
if (block.getTypeId()!=wall.id || block.getData()!=wall.data) {
setWall(world, dpw, plot.id, wall_filling);
setWall(world, dpw, plot.id, wall);
}
if ((pos2.getBlockX() - pos1.getBlockX()) < 48) {
@ -347,7 +347,7 @@ public class DefaultPlotManager extends PlotManager {
PlotHelper.setCuboid(world, new Location(world, min.getBlockX(), dpw.PLOT_HEIGHT, max.getBlockZ()), new Location(world, max.getBlockX() + 1, dpw.PLOT_HEIGHT + 1, plotMaxZ + 1), plotfloor);
PlotHelper.setSimpleCuboid(world, new Location(world, max.getBlockX(), 0, min.getBlockZ()), new Location(world, plotMaxX + 1, 1, max.getBlockZ() + 1), new PlotBlock((short) 7, (byte) 0));
PlotHelper.setSimpleCuboid(world, new Location(world, max.getBlockX(), dpw.PLOT_HEIGHT + 1, min.getBlockZ()), new Location(world, plotMaxX + 1, world.getMaxHeight() + 1, max.getBlockZ() + 1), new PlotBlock((short) 7, (byte) 0));
PlotHelper.setSimpleCuboid(world, new Location(world, max.getBlockX(), dpw.PLOT_HEIGHT + 1, min.getBlockZ()), new Location(world, plotMaxX + 1, world.getMaxHeight() + 1, max.getBlockZ() + 1), new PlotBlock((short) 0, (byte) 0));
PlotHelper.setCuboid(world, new Location(world, max.getBlockX(), 1, min.getBlockZ()), new Location(world, plotMaxX + 1, dpw.PLOT_HEIGHT, max.getBlockZ() + 1), filling);
PlotHelper.setCuboid(world, new Location(world, max.getBlockX(), dpw.PLOT_HEIGHT, min.getBlockZ()), new Location(world, plotMaxX + 1, dpw.PLOT_HEIGHT + 1, max.getBlockZ() + 1), plotfloor);