mirror of
https://github.com/IntellectualSites/PlotSquared.git
synced 2025-06-28 11:44:42 +02:00
Copy and paste, doesn't work for mega plots.
This commit is contained in:
@ -16,6 +16,13 @@ import org.bukkit.ChatColor;
|
||||
* @author Citymonstret
|
||||
*/
|
||||
public enum C {
|
||||
/*
|
||||
Clipboard
|
||||
*/
|
||||
CLIPBOARD_SET("&cThe current plot is now copied, use &6/plot paste&c to pate it"),
|
||||
PASTED("&cThe plot selection was successfully pasted"),
|
||||
PASTE_FAILED("&cFailed to paste the selection. Reason: &c%s"),
|
||||
NO_CLIPBOARD("&cYou don't have a selection in your clipboard"),
|
||||
/*
|
||||
* Ratings
|
||||
*/
|
||||
|
@ -0,0 +1,82 @@
|
||||
package com.intellectualcrafters.plot;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.block.Block;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
/**
|
||||
* Created by Citymonstret on 2014-10-12.
|
||||
*/
|
||||
public class PlotSelection {
|
||||
|
||||
public static HashMap<String, PlotSelection> currentSelection = new HashMap<>();
|
||||
|
||||
private PlotBlock[] plotBlocks;
|
||||
|
||||
private int width;
|
||||
|
||||
public PlotSelection(int width, World world, Plot plot) {
|
||||
this.width = width;
|
||||
|
||||
plotBlocks = new PlotBlock[(width * width) * (world.getMaxHeight() - 1)];
|
||||
|
||||
Location
|
||||
bot = PlotHelper.getPlotBottomLocAbs(world, plot.getId()),
|
||||
top = PlotHelper.getPlotTopLocAbs(world, plot.getId());
|
||||
int
|
||||
minX = bot.getBlockX(),
|
||||
maxX = top.getBlockX(),
|
||||
minZ = bot.getBlockZ(),
|
||||
maxZ = top.getBlockZ(),
|
||||
minY = 1,
|
||||
maxY = world.getMaxHeight();
|
||||
Block current;
|
||||
|
||||
int index = 0;
|
||||
for (int x = minX; x < maxX; x++) {
|
||||
for (int z = minZ; z < maxZ; z++) {
|
||||
for (int y = minY; y < maxY; y++) {
|
||||
current = world.getBlockAt(x + 1, y, z + 1);
|
||||
plotBlocks[index++] = new PlotBlock(
|
||||
(short) current.getTypeId(),
|
||||
current.getData()
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
//Yay :D
|
||||
}
|
||||
|
||||
public PlotBlock[] getBlocks() {
|
||||
return plotBlocks;
|
||||
}
|
||||
|
||||
public int getWidth() {
|
||||
return width;
|
||||
}
|
||||
|
||||
public void paste(World world, Plot plot) {
|
||||
Location
|
||||
bot = PlotHelper.getPlotBottomLocAbs(world, plot.getId()),
|
||||
top = PlotHelper.getPlotTopLocAbs(world, plot.getId());
|
||||
int
|
||||
minX = bot.getBlockX(),
|
||||
maxX = top.getBlockX(),
|
||||
minZ = bot.getBlockZ(),
|
||||
maxZ = top.getBlockZ(),
|
||||
minY = 1,
|
||||
maxY = world.getMaxHeight();
|
||||
int index = 0;
|
||||
PlotBlock current;
|
||||
for (int x = minX; x < maxX; x++) {
|
||||
for (int z = minZ; z < maxZ; z++) {
|
||||
for (int y = minY; y < maxY; y++) {
|
||||
current = plotBlocks[index++];
|
||||
world.getBlockAt(x + 1, y, z + 1).setTypeIdAndData(current.id, current.data, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,24 +1,19 @@
|
||||
package com.intellectualcrafters.plot;
|
||||
|
||||
import com.sk89q.jnbt.*;
|
||||
import com.sk89q.worldedit.CuboidClipboard;
|
||||
import com.sk89q.worldedit.EditSession;
|
||||
import com.sk89q.worldedit.Vector;
|
||||
import com.sk89q.worldedit.bukkit.BukkitWorld;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.InputStream;
|
||||
import java.util.Map;
|
||||
import java.util.zip.GZIPInputStream;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import com.sk89q.jnbt.ByteArrayTag;
|
||||
import com.sk89q.jnbt.CompoundTag;
|
||||
import com.sk89q.jnbt.NBTInputStream;
|
||||
import com.sk89q.jnbt.ShortTag;
|
||||
import com.sk89q.jnbt.Tag;
|
||||
import com.sk89q.worldedit.CuboidClipboard;
|
||||
import com.sk89q.worldedit.EditSession;
|
||||
import com.sk89q.worldedit.Vector;
|
||||
import com.sk89q.worldedit.bukkit.BukkitWorld;
|
||||
|
||||
/**
|
||||
* Created by Citymonstret on 2014-09-15.
|
||||
*/
|
||||
|
@ -32,6 +32,7 @@ public enum Command {
|
||||
/**
|
||||
*
|
||||
*/
|
||||
PASTE("paste"),
|
||||
COPY("copy"),
|
||||
/**
|
||||
*
|
||||
|
@ -8,12 +8,9 @@
|
||||
|
||||
package com.intellectualcrafters.plot.commands;
|
||||
|
||||
import com.intellectualcrafters.plot.*;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.intellectualcrafters.plot.C;
|
||||
import com.intellectualcrafters.plot.PlayerFunctions;
|
||||
import com.intellectualcrafters.plot.Plot;
|
||||
|
||||
/**
|
||||
* Created by Citymonstret on 2014-08-01.
|
||||
*/
|
||||
@ -35,7 +32,15 @@ public class Copy extends SubCommand {
|
||||
PlayerFunctions.sendMessage(plr, C.NO_PLOT_PERMS);
|
||||
return false;
|
||||
}
|
||||
plot.clear(plr);
|
||||
assert plot != null;
|
||||
int size = (PlotHelper.getPlotTopLocAbs(plr.getWorld(), plot.getId()).getBlockX() - PlotHelper.getPlotBottomLocAbs(plr.getWorld(), plot.getId()).getBlockX());
|
||||
PlotSelection selection = new PlotSelection(size, plr.getWorld(), plot);
|
||||
if(PlotSelection.currentSelection.containsKey(plr.getName())) {
|
||||
PlotSelection.currentSelection.remove(plr.getName());
|
||||
}
|
||||
PlotSelection.currentSelection.put(plr.getName(), selection);
|
||||
sendMessage(plr, C.CLIPBOARD_SET);
|
||||
//section.paste(plr.getWorld(), PlotHelper.getPlot(plr.getWorld()zs, new PlotId(plot.getId().x + 1, plot.getId().y)));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -8,18 +8,17 @@
|
||||
|
||||
package com.intellectualcrafters.plot.commands;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
|
||||
import com.intellectualcrafters.plot.C;
|
||||
import com.intellectualcrafters.plot.PlayerFunctions;
|
||||
import com.intellectualcrafters.plot.PlotMain;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.intellectualcrafters.plot.C;
|
||||
import com.intellectualcrafters.plot.PlayerFunctions;
|
||||
import com.intellectualcrafters.plot.PlotMain;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
|
||||
/**
|
||||
* PlotMain command class
|
||||
@ -28,7 +27,7 @@ import com.intellectualcrafters.plot.PlotMain;
|
||||
*/
|
||||
public class MainCommand implements CommandExecutor {
|
||||
|
||||
private static SubCommand[] _subCommands = new SubCommand[] { new Claim(), new Auto(), new Home(), new Visit(),
|
||||
private static SubCommand[] _subCommands = new SubCommand[] { new Claim(), new Paste(), new Copy(), 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 Reload(), new Merge(), new Unlink(), new Kick(), new Setup() };
|
||||
|
@ -0,0 +1,45 @@
|
||||
package com.intellectualcrafters.plot.commands;
|
||||
|
||||
import com.intellectualcrafters.plot.*;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
/**
|
||||
* Created by Citymonstret on 2014-10-12.
|
||||
*/
|
||||
public class Paste extends SubCommand {
|
||||
|
||||
public Paste() {
|
||||
super(Command.PASTE, "Paste a plot", "paste", CommandCategory.ACTIONS);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(Player plr, String... args) {
|
||||
if (!PlayerFunctions.isInPlot(plr)) {
|
||||
PlayerFunctions.sendMessage(plr, "You're not in a plot.");
|
||||
return false;
|
||||
}
|
||||
Plot plot = PlayerFunctions.getCurrentPlot(plr);
|
||||
if (((plot == null) || !plot.hasOwner() || !plot.getOwner().equals(plr.getUniqueId()))
|
||||
&& !plr.hasPermission("plots.admin")) {
|
||||
PlayerFunctions.sendMessage(plr, C.NO_PLOT_PERMS);
|
||||
return false;
|
||||
}
|
||||
assert plot != null;
|
||||
int size = (PlotHelper.getPlotTopLocAbs(plr.getWorld(), plot.getId()).getBlockX() - PlotHelper.getPlotBottomLocAbs(plr.getWorld(), plot.getId()).getBlockX());
|
||||
|
||||
if(PlotSelection.currentSelection.containsKey(plr.getName())) {
|
||||
PlotSelection selection = PlotSelection.currentSelection.get(plr.getName());
|
||||
if(size != selection.getWidth()) {
|
||||
sendMessage(plr, C.PASTE_FAILED, "The size of the current plot is not the same as the paste");
|
||||
return false;
|
||||
}
|
||||
selection.paste(plr.getWorld(), plot);
|
||||
sendMessage(plr, C.PASTED);
|
||||
} else {
|
||||
sendMessage(plr, C.NO_CLIPBOARD);
|
||||
return false;
|
||||
}
|
||||
PlotSelection.currentSelection.remove(plr.getName());
|
||||
return true;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user