mirror of
https://github.com/IntellectualSites/PlotSquared.git
synced 2024-11-12 10:24:07 +01:00
Tried to fix #143, this has to be tested
This commit is contained in:
parent
2be941cc18
commit
21514ca3e3
@ -21,11 +21,9 @@
|
|||||||
|
|
||||||
package com.intellectualcrafters.plot.commands;
|
package com.intellectualcrafters.plot.commands;
|
||||||
|
|
||||||
import org.bukkit.World;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
|
|
||||||
import com.intellectualcrafters.plot.PlotMain;
|
import com.intellectualcrafters.plot.PlotMain;
|
||||||
import com.intellectualcrafters.plot.config.C;
|
import com.intellectualcrafters.plot.config.C;
|
||||||
|
import com.intellectualcrafters.plot.database.DBFunc;
|
||||||
import com.intellectualcrafters.plot.object.Plot;
|
import com.intellectualcrafters.plot.object.Plot;
|
||||||
import com.intellectualcrafters.plot.object.PlotId;
|
import com.intellectualcrafters.plot.object.PlotId;
|
||||||
import com.intellectualcrafters.plot.object.PlotSelection;
|
import com.intellectualcrafters.plot.object.PlotSelection;
|
||||||
@ -33,6 +31,8 @@ import com.intellectualcrafters.plot.util.PlayerFunctions;
|
|||||||
import com.intellectualcrafters.plot.util.PlotHelper;
|
import com.intellectualcrafters.plot.util.PlotHelper;
|
||||||
import com.intellectualcrafters.plot.util.SetBlockFast;
|
import com.intellectualcrafters.plot.util.SetBlockFast;
|
||||||
import com.intellectualcrafters.plot.util.UUIDHandler;
|
import com.intellectualcrafters.plot.util.UUIDHandler;
|
||||||
|
import org.bukkit.World;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created 2014-08-01 for PlotSquared
|
* Created 2014-08-01 for PlotSquared
|
||||||
@ -87,6 +87,11 @@ public class Swap extends SubCommand {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
PlotSelection.swap(world, plot.id, plotid);
|
PlotSelection.swap(world, plot.id, plotid);
|
||||||
|
|
||||||
|
// TODO Requires testing!!
|
||||||
|
DBFunc.dbManager.swapPlots(plot, PlotHelper.getPlot(world, plotid));
|
||||||
|
// TODO Requires testing!!
|
||||||
|
|
||||||
PlayerFunctions.sendMessage(plr, C.SWAP_SUCCESS);
|
PlayerFunctions.sendMessage(plr, C.SWAP_SUCCESS);
|
||||||
|
|
||||||
if (PlotHelper.canSetFast) {
|
if (PlotHelper.canSetFast) {
|
||||||
|
@ -21,20 +21,11 @@
|
|||||||
|
|
||||||
package com.intellectualcrafters.plot.database;
|
package com.intellectualcrafters.plot.database;
|
||||||
|
|
||||||
import java.sql.SQLException;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.LinkedHashMap;
|
|
||||||
import java.util.Set;
|
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
import com.intellectualcrafters.plot.flag.Flag;
|
import com.intellectualcrafters.plot.flag.Flag;
|
||||||
import com.intellectualcrafters.plot.object.Plot;
|
import com.intellectualcrafters.plot.object.*;
|
||||||
import com.intellectualcrafters.plot.object.PlotCluster;
|
|
||||||
import com.intellectualcrafters.plot.object.PlotClusterId;
|
import java.sql.SQLException;
|
||||||
import com.intellectualcrafters.plot.object.PlotComment;
|
import java.util.*;
|
||||||
import com.intellectualcrafters.plot.object.PlotId;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Citymonstret
|
* @author Citymonstret
|
||||||
@ -144,6 +135,13 @@ public interface AbstractDB {
|
|||||||
*/
|
*/
|
||||||
public void setMerged(final String world, final Plot plot, final boolean[] merged);
|
public void setMerged(final String world, final Plot plot, final boolean[] merged);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Swap the settings, helpers etc. of two plots
|
||||||
|
* @param p1 Plot1
|
||||||
|
* @param p2 Plot2
|
||||||
|
*/
|
||||||
|
public void swapPlots(final Plot p1, final Plot p2);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set plot flags
|
* Set plot flags
|
||||||
*
|
*
|
||||||
|
@ -21,35 +21,18 @@
|
|||||||
|
|
||||||
package com.intellectualcrafters.plot.database;
|
package com.intellectualcrafters.plot.database;
|
||||||
|
|
||||||
import java.sql.Connection;
|
import com.intellectualcrafters.plot.PlotMain;
|
||||||
import java.sql.DatabaseMetaData;
|
import com.intellectualcrafters.plot.flag.Flag;
|
||||||
import java.sql.PreparedStatement;
|
import com.intellectualcrafters.plot.flag.FlagManager;
|
||||||
import java.sql.ResultSet;
|
import com.intellectualcrafters.plot.object.*;
|
||||||
import java.sql.SQLException;
|
import com.intellectualcrafters.plot.util.ClusterManager;
|
||||||
import java.sql.Statement;
|
import com.intellectualcrafters.plot.util.TaskManager;
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.LinkedHashMap;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Set;
|
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
import org.apache.commons.lang.StringUtils;
|
import org.apache.commons.lang.StringUtils;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.block.Biome;
|
import org.bukkit.block.Biome;
|
||||||
|
|
||||||
import com.intellectualcrafters.plot.PlotMain;
|
import java.sql.*;
|
||||||
import com.intellectualcrafters.plot.flag.Flag;
|
import java.util.*;
|
||||||
import com.intellectualcrafters.plot.flag.FlagManager;
|
|
||||||
import com.intellectualcrafters.plot.object.BlockLoc;
|
|
||||||
import com.intellectualcrafters.plot.object.Plot;
|
|
||||||
import com.intellectualcrafters.plot.object.PlotCluster;
|
|
||||||
import com.intellectualcrafters.plot.object.PlotClusterId;
|
|
||||||
import com.intellectualcrafters.plot.object.PlotComment;
|
|
||||||
import com.intellectualcrafters.plot.object.PlotId;
|
|
||||||
import com.intellectualcrafters.plot.util.ClusterManager;
|
|
||||||
import com.intellectualcrafters.plot.util.TaskManager;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Citymonstret
|
* @author Citymonstret
|
||||||
@ -64,9 +47,9 @@ public class SQLManager implements AbstractDB {
|
|||||||
public final String CREATE_HELPERS;
|
public final String CREATE_HELPERS;
|
||||||
public final String CREATE_PLOT;
|
public final String CREATE_PLOT;
|
||||||
public final String CREATE_CLUSTER;
|
public final String CREATE_CLUSTER;
|
||||||
|
private final String prefix;
|
||||||
// Private Final
|
// Private Final
|
||||||
private Connection connection;
|
private Connection connection;
|
||||||
private final String prefix;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor
|
* Constructor
|
||||||
@ -437,7 +420,7 @@ public class SQLManager implements AbstractDB {
|
|||||||
stmt.close();
|
stmt.close();
|
||||||
} catch (final SQLException e) {
|
} catch (final SQLException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
PlotMain.sendConsoleSenderMessage("&c[ERROR] "+"Failed to delete plot " + plot.id);
|
PlotMain.sendConsoleSenderMessage("&c[ERROR] " + "Failed to delete plot " + plot.id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -751,6 +734,71 @@ public class SQLManager implements AbstractDB {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void swapPlots(final Plot p1, final Plot p2) {
|
||||||
|
TaskManager.runTask(
|
||||||
|
new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
/*
|
||||||
|
update ticket
|
||||||
|
set ticket_index = case when ticket_index = :x then :y else :x end
|
||||||
|
where ticket_index in (:x, :y);
|
||||||
|
|
||||||
|
FROM
|
||||||
|
http://stackoverflow.com/questions/6018374/swap-two-rows-using-sql-query
|
||||||
|
|
||||||
|
*/
|
||||||
|
try {
|
||||||
|
PreparedStatement stmt = SQLManager.this.connection.prepareStatement(
|
||||||
|
"UPDATE `" + SQLManager.this.prefix + "plot_settings` SET `plot_plot_id` = CASE WHEN `plot_plot_id` = ? then ? else ? END WHERE `plot_plot_id` IN (?, ?)"
|
||||||
|
);
|
||||||
|
int id1 = getId(p1.getWorld().getName(), p1.id), id2 = getId(p2.getWorld().getName(), p2.id);
|
||||||
|
stmt.setInt(1, id1);
|
||||||
|
stmt.setInt(2, id2);
|
||||||
|
stmt.setInt(3, id1);
|
||||||
|
stmt.setInt(4, id1);
|
||||||
|
stmt.setInt(5, id2);
|
||||||
|
stmt.executeUpdate();
|
||||||
|
stmt.close();
|
||||||
|
stmt = SQLManager.this.connection.prepareStatement(
|
||||||
|
"UPDATE `" + SQLManager.this.prefix + "plot_helpers` SET `plot_plot_id` = CASE WHEN `plot_plot_id` = ? then ? else ? END WHERE `plot_plot_id` IN (?, ?)"
|
||||||
|
);
|
||||||
|
stmt.setInt(1, id1);
|
||||||
|
stmt.setInt(2, id2);
|
||||||
|
stmt.setInt(3, id1);
|
||||||
|
stmt.setInt(4, id1);
|
||||||
|
stmt.setInt(5, id2);
|
||||||
|
stmt.executeUpdate();
|
||||||
|
stmt.close();
|
||||||
|
stmt = SQLManager.this.connection.prepareStatement(
|
||||||
|
"UPDATE `" + SQLManager.this.prefix + "plot_denied` SET `plot_plot_id` = CASE WHEN `plot_plot_id` = ? then ? else ? END WHERE `plot_plot_id` IN (?, ?)"
|
||||||
|
);
|
||||||
|
stmt.setInt(1, id1);
|
||||||
|
stmt.setInt(2, id2);
|
||||||
|
stmt.setInt(3, id1);
|
||||||
|
stmt.setInt(4, id1);
|
||||||
|
stmt.setInt(5, id2);
|
||||||
|
stmt.executeUpdate();
|
||||||
|
stmt.close();
|
||||||
|
stmt = SQLManager.this.connection.prepareStatement(
|
||||||
|
"UPDATE `" + SQLManager.this.prefix + "plot_trusted` SET `plot_plot_id` = CASE WHEN `plot_plot_id` = ? then ? else ? END WHERE `plot_plot_id` IN (?, ?)"
|
||||||
|
);
|
||||||
|
stmt.setInt(1, id1);
|
||||||
|
stmt.setInt(2, id2);
|
||||||
|
stmt.setInt(3, id1);
|
||||||
|
stmt.setInt(4, id1);
|
||||||
|
stmt.setInt(5, id2);
|
||||||
|
stmt.executeUpdate();
|
||||||
|
stmt.close();
|
||||||
|
} catch (final Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setFlags(final String world, final Plot plot, final Set<Flag> flags) {
|
public void setFlags(final String world, final Plot plot, final Set<Flag> flags) {
|
||||||
final StringBuilder flag_string = new StringBuilder();
|
final StringBuilder flag_string = new StringBuilder();
|
||||||
|
Loading…
Reference in New Issue
Block a user