diff --git a/Core/src/main/java/com/intellectualcrafters/plot/commands/Leave.java b/Core/src/main/java/com/intellectualcrafters/plot/commands/Leave.java index abc3d26ba..7df2372f7 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/commands/Leave.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/commands/Leave.java @@ -5,10 +5,11 @@ import com.intellectualcrafters.plot.object.Plot; import com.intellectualcrafters.plot.object.PlotPlayer; import com.intellectualcrafters.plot.object.RunnableVal2; import com.intellectualcrafters.plot.object.RunnableVal3; +import com.intellectualcrafters.plot.util.EventUtil; +import com.intellectualcrafters.plot.util.MainUtil; import com.plotsquared.general.commands.Command; import com.plotsquared.general.commands.CommandDeclaration; -import java.util.*; -import java.util.Set; +import java.util.UUID; @CommandDeclaration(command = "leave", description = "Leave a plot", @@ -16,7 +17,7 @@ import java.util.Set; category = CommandCategory.CLAIMING, requiredType = RequiredType.NONE) public class Leave extends Command { - public Leave(Command parent, boolean isStatic) { + public Leave() { super(MainCommand.getInstance(), true); } @@ -27,9 +28,21 @@ public class Leave extends Command { checkTrue(plot.isAdded(player.getUUID()), C.NO_PLOT_PERMS); checkTrue(args.length == 0, C.COMMAND_SYNTAX, getUsage()); if (plot.isOwner(player.getUUID())) { - Set owners = plot.getOwners(); + checkTrue(plot.hasOwner(), C.ALREADY_OWNER); + // TODO setowner, other } else { - + UUID uuid = player.getUUID(); + if (plot.isAdded(uuid)) { + if (plot.removeTrusted(uuid)) { + EventUtil.manager.callTrusted(player, plot, uuid, false); + } + if (plot.removeMember(uuid)) { + EventUtil.manager.callMember(player, plot, uuid, false); + } + MainUtil.sendMessage(player, C.INVALID_PLAYER, args[0]); + } else { + MainUtil.sendMessage(player, C.REMOVED_PLAYERS, 1); + } } } -} +} \ No newline at end of file diff --git a/Core/src/main/java/com/intellectualcrafters/plot/commands/MainCommand.java b/Core/src/main/java/com/intellectualcrafters/plot/commands/MainCommand.java index d0f77bcbd..e9b571829 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/commands/MainCommand.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/commands/MainCommand.java @@ -61,6 +61,7 @@ public class MainCommand extends Command { new Delete(); new Trust(); new Add(); + new Leave(); new Deny(); new Remove(); new Info(); diff --git a/Core/src/main/java/com/intellectualcrafters/plot/util/SchematicHandler.java b/Core/src/main/java/com/intellectualcrafters/plot/util/SchematicHandler.java index 4457d25d9..e5540d6ed 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/util/SchematicHandler.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/util/SchematicHandler.java @@ -123,8 +123,6 @@ public abstract class SchematicHandler { return true; } - - /** * Paste a schematic. * @@ -352,12 +350,10 @@ public abstract class SchematicHandler { public Schematic getSchematic(CompoundTag tag) { Map tagMap = tag.getValue(); - // Slow - // byte[] addId = new byte[0]; - // if (tagMap.containsKey("AddBlocks")) { - // addId = ByteArrayTag.class.cast(tagMap.get("AddBlocks")).getValue(); - // } - // end slow + byte[] addBlocks = null; + if (tagMap.containsKey("AddBlocks")) { + addBlocks = ByteArrayTag.class.cast(tagMap.get("AddBlocks")).getValue(); + } short width = ShortTag.class.cast(tagMap.get("Width")).getValue(); short length = ShortTag.class.cast(tagMap.get("Length")).getValue(); @@ -379,19 +375,26 @@ public abstract class SchematicHandler { } block[i] = id; } - - // Slow + has code for exceptions (addId) inside the loop rather than outside - // for (int index = 0; index < b.length; index++) { - // if ((index >> 1) >= addId.length) { - // blocks[index] = (short) (b[index] & 0xFF); - // } else { - // if ((index & 1) == 0) { - // blocks[index] = (short) (((addId[index >> 1] & 0x0F) << 8) + (b[index] & 0xFF)); - // } else { - // blocks[index] = (short) (((addId[index >> 1] & 0xF0) << 4) + (b[index] & 0xFF)); - // } - // } - // } + + if (addBlocks != null) { + if (addBlocks.length == block.length) { + for (int i = 0; i < addBlocks.length; i++) { + byte val = addBlocks[i]; + if (val != 0) { + block[i] |= (val << 8); + } + } + } else { + for (int index = 0; index < block.length; index++) { + if ((index & 1) == 0) { + block[index] = (short) (((addBlocks[index >> 1] & 0x0F) << 8) + (block[index])); + } else { + block[index] = (short) (((addBlocks[index >> 1] & 0xF0) << 4) + (block[index])); + } + } + } + } + // Slow as wrapper for each block // final DataCollection[] collection = new DataCollection[b.length]; // for (int x = 0; x < b.length; x++) {