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) { if (this.s.length() < 1) {
return this.d.replace("\\n", "\n"); return "";
} }
return this.s.replace("\\n", "\n"); return this.s.replace("\\n", "\n");
} }

View File

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

View File

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

View File

@ -25,6 +25,10 @@ public enum Command {
// - /plot list <some parameter to list the most popular, and highest rated // - /plot list <some parameter to list the most popular, and highest rated
// plots> // plots>
INBOX("inbox"), 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(), 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 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 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>() { 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); final Location pos2 = PlotHelper.getPlotTopLoc(world, plot.id);
PlotBlock[] plotfloor = dpw.TOP_BLOCK; PlotBlock[] plotfloor = dpw.TOP_BLOCK;
PlotBlock[] filling = dpw.TOP_BLOCK; PlotBlock[] filling = dpw.MAIN_BLOCK;
PlotBlock wall = dpw.WALL_BLOCK; PlotBlock wall = dpw.WALL_BLOCK;
PlotBlock wall_filling = dpw.WALL_FILLING; 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())); block = world.getBlockAt(new Location(world, pos1.getBlockX()-1, dpw.WALL_HEIGHT+1, pos1.getBlockZ()));
if (block.getTypeId()!=wall.id || block.getData()!=wall.data) { 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) { 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.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(), 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(), 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); 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);