mirror of
				https://github.com/IntellectualSites/PlotSquared.git
				synced 2025-11-04 11:13:45 +01:00 
			
		
		
		
	autodetect move DB if null
This commit is contained in:
		@@ -112,7 +112,7 @@ public class Swap extends SubCommand {
 | 
			
		||||
        
 | 
			
		||||
        // Swapping the plot data
 | 
			
		||||
        for (int i = 0; i < selection1.size(); i++) {
 | 
			
		||||
            final boolean last = i == selection1.size() - 1; 
 | 
			
		||||
            final boolean last = i == selection1.size() - 1;
 | 
			
		||||
            PlotId swaper = selection1.get(i);
 | 
			
		||||
            PlotId swapee = selection2.get(i);
 | 
			
		||||
            MainUtil.swapData(world, swaper, swapee, new Runnable() {
 | 
			
		||||
 
 | 
			
		||||
@@ -805,7 +805,18 @@ public class MainUtil {
 | 
			
		||||
    public static boolean swapData(final String world, final PlotId current, final PlotId newPlot, final Runnable whenDone) {
 | 
			
		||||
        Plot p1 = PlotSquared.getPlots(world).get(current);
 | 
			
		||||
        Plot p2 = PlotSquared.getPlots(world).get(newPlot);
 | 
			
		||||
        if (p1==null || p2 == null || p1.owner == null || !p1.owner.equals(p2.owner)) {
 | 
			
		||||
        if (p1 == null || p1.owner == null) {
 | 
			
		||||
            if (p2 != null && p2.owner != null) {
 | 
			
		||||
                moveData(world, newPlot, current, whenDone);
 | 
			
		||||
                return true;
 | 
			
		||||
            }
 | 
			
		||||
            return false;
 | 
			
		||||
        }
 | 
			
		||||
        if (p2 == null || p2.owner == null) {
 | 
			
		||||
            if (p1 != null && p1.owner != null) {
 | 
			
		||||
                moveData(world, current, newPlot, whenDone);
 | 
			
		||||
                return true;
 | 
			
		||||
            }
 | 
			
		||||
            return false;
 | 
			
		||||
        }
 | 
			
		||||
        // Swap cached
 | 
			
		||||
@@ -823,6 +834,33 @@ public class MainUtil {
 | 
			
		||||
        return true;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public static boolean moveData(final String world, final PlotId current, final PlotId newPlot, final Runnable whenDone) {
 | 
			
		||||
        final Plot currentPlot = MainUtil.getPlot(world, current);
 | 
			
		||||
        if (currentPlot.owner == null) {
 | 
			
		||||
            TaskManager.runTaskLater(whenDone, 1);
 | 
			
		||||
            return false;
 | 
			
		||||
        }
 | 
			
		||||
        final Plot pos1 = getBottomPlot(currentPlot);
 | 
			
		||||
        final Plot pos2 = getTopPlot(currentPlot);
 | 
			
		||||
        final PlotId size = MainUtil.getSize(world, currentPlot);
 | 
			
		||||
        if (!MainUtil.isUnowned(world, newPlot, new PlotId((newPlot.x + size.x) - 1, (newPlot.y + size.y) - 1))) {
 | 
			
		||||
            TaskManager.runTaskLater(whenDone, 1);
 | 
			
		||||
            return false;
 | 
			
		||||
        }
 | 
			
		||||
        final int offset_x = newPlot.x - pos1.id.x;
 | 
			
		||||
        final int offset_y = newPlot.y - pos1.id.y;
 | 
			
		||||
        final ArrayList<PlotId> selection = getPlotSelectionIds(pos1.id, pos2.id);
 | 
			
		||||
        for (final PlotId id : selection) {
 | 
			
		||||
            DBFunc.movePlot(world, new PlotId(id.x, id.y), new PlotId(id.x + offset_x, id.y + offset_y));
 | 
			
		||||
            final Plot plot = PlotSquared.getPlots(world).get(id);
 | 
			
		||||
            PlotSquared.getPlots(world).remove(id);
 | 
			
		||||
            plot.id.x += offset_x;
 | 
			
		||||
            plot.id.y += offset_y;
 | 
			
		||||
            PlotSquared.getPlots(world).put(plot.id, plot);
 | 
			
		||||
        }
 | 
			
		||||
        return true;
 | 
			
		||||
    }
 | 
			
		||||
    
 | 
			
		||||
    public static boolean move(final String world, final PlotId current, final PlotId newPlot, final Runnable whenDone) {
 | 
			
		||||
        final com.intellectualcrafters.plot.object.Location bot1 = MainUtil.getPlotBottomLoc(world, current);
 | 
			
		||||
        final com.intellectualcrafters.plot.object.Location bot2 = MainUtil.getPlotBottomLoc(world, newPlot);
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user