mirror of
				https://github.com/IntellectualSites/PlotSquared.git
				synced 2025-10-30 17:13:43 +01:00 
			
		
		
		
	Fix plot auto merge + plot offset + add unmerge alias
This commit is contained in:
		| @@ -33,7 +33,7 @@ import com.plotsquared.general.commands.CommandDeclaration; | ||||
|  | ||||
| @CommandDeclaration( | ||||
|         command = "unlink", | ||||
|         aliases = {"u"}, | ||||
|         aliases = {"u", "unmerge"}, | ||||
|         description = "Unlink a mega-plot", | ||||
|         usage = "/plot unlink", | ||||
|         requiredType = RequiredType.NONE, | ||||
|   | ||||
| @@ -337,7 +337,7 @@ public interface AbstractDB { | ||||
|      */ | ||||
|     void getComments(final Plot plot, final String inbox, RunnableVal whenDone); | ||||
|  | ||||
|     void createPlotAndSettings(Plot plot); | ||||
|     void createPlotAndSettings(Plot plot, Runnable whenDone); | ||||
|  | ||||
|     void createCluster(PlotCluster cluster); | ||||
|  | ||||
|   | ||||
| @@ -127,11 +127,11 @@ public class DBFunc { | ||||
|      * | ||||
|      * @param plot Plot to create | ||||
|      */ | ||||
|     public static void createPlotAndSettings(final Plot plot) { | ||||
|     public static void createPlotAndSettings(final Plot plot, Runnable whenDone) { | ||||
|         if (plot.temp == -1) { | ||||
|             return; | ||||
|         } | ||||
|         dbManager.createPlotAndSettings(plot); | ||||
|         dbManager.createPlotAndSettings(plot, whenDone); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|   | ||||
| @@ -81,6 +81,23 @@ public class SQLManager implements AbstractDB { | ||||
|     public SQLManager(final Connection c, final String p) { | ||||
|         // Private final | ||||
|         this.connection = c; | ||||
|         try { | ||||
|             if (this.connection.getAutoCommit()) { | ||||
|                 this.connection.setAutoCommit(false); | ||||
|             } | ||||
|             TaskManager.runTaskRepeat(new Runnable() { | ||||
|                 @Override | ||||
|                 public void run() { | ||||
|                     try { | ||||
|                         SQLManager.this.connection.commit(); | ||||
|                     } catch (SQLException e) { | ||||
|                         e.printStackTrace(); | ||||
|                     } | ||||
|                 } | ||||
|             }, 200); | ||||
|         } catch (SQLException e) { | ||||
|             e.printStackTrace(); | ||||
|         } | ||||
|         this.prefix = p; | ||||
|         // Set timout | ||||
|         // setTimout(); | ||||
| @@ -145,10 +162,6 @@ public class SQLManager implements AbstractDB { | ||||
|             @Override | ||||
|             public void run() { | ||||
|                 try { | ||||
|                     try { | ||||
|                         connection.setAutoCommit(false); | ||||
|                     } | ||||
|                     catch (SQLException e) {} | ||||
|                     // Create the plots | ||||
|                     createPlots(myList, new Runnable() { | ||||
|                         @Override | ||||
| @@ -206,7 +219,6 @@ public class SQLManager implements AbstractDB { | ||||
|                                                         public void run() { | ||||
|                                                             try { | ||||
|                                                                 connection.commit(); | ||||
|                                                                 connection.setAutoCommit(true); | ||||
|                                                             } catch (SQLException e) { | ||||
|                                                                 e.printStackTrace(); | ||||
|                                                             } | ||||
| @@ -225,7 +237,6 @@ public class SQLManager implements AbstractDB { | ||||
|                                 PS.debug("&7[WARN] " + "Failed to set all helpers for plots"); | ||||
|                                 try { | ||||
|                                     connection.commit(); | ||||
|                                     connection.setAutoCommit(true); | ||||
|                                 } catch (SQLException e1) { | ||||
|                                     e1.printStackTrace(); | ||||
|                                 } | ||||
| @@ -237,7 +248,6 @@ public class SQLManager implements AbstractDB { | ||||
|                     PS.debug("&7[WARN] " + "Failed to set all helpers for plots"); | ||||
|                     try { | ||||
|                         connection.commit(); | ||||
|                         connection.setAutoCommit(true); | ||||
|                     } catch (SQLException e1) { | ||||
|                         e1.printStackTrace(); | ||||
|                     } | ||||
| @@ -658,9 +668,17 @@ public class SQLManager implements AbstractDB { | ||||
|             } | ||||
|         }); | ||||
|     } | ||||
|      | ||||
|     public void commit() { | ||||
|         try { | ||||
|             this.connection.commit(); | ||||
|         } catch (SQLException e) { | ||||
|             e.printStackTrace(); | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public void createPlotAndSettings(final Plot plot) { | ||||
|     public void createPlotAndSettings(final Plot plot, final Runnable whenDone) { | ||||
|         TaskManager.runTaskAsync(new Runnable() { | ||||
|             @Override | ||||
|             public void run() { | ||||
| @@ -673,8 +691,17 @@ public class SQLManager implements AbstractDB { | ||||
|                     stmt.setString(4, plot.world); | ||||
|                     stmt.setTimestamp(5, new Timestamp(plot.getTimestamp())); | ||||
|                     stmt.executeUpdate(); | ||||
|                     ResultSet keys = stmt.getGeneratedKeys(); | ||||
|                     int id = -1; | ||||
|                     if (keys.next()) { | ||||
|                         plot.temp = keys.getInt(1); | ||||
|                         stmt.close(); | ||||
|                     } | ||||
|                     else { | ||||
|                         commit(); | ||||
|                     } | ||||
|                     stmt.close(); | ||||
|                     final int id = getId(plot); | ||||
|                     id = getId(plot); | ||||
|                     stmt = SQLManager.this.connection.prepareStatement("INSERT INTO `" + SQLManager.this.prefix + "plot_settings`(`plot_plot_id`) VALUES(" + "?)"); | ||||
|                     stmt.setInt(1, id); | ||||
|                     stmt.executeUpdate(); | ||||
| @@ -683,6 +710,7 @@ public class SQLManager implements AbstractDB { | ||||
|                     e.printStackTrace(); | ||||
|                     PS.debug("&c[ERROR] " + "Failed to save plot " + plot.id); | ||||
|                 } | ||||
|                 TaskManager.runTask(whenDone); | ||||
|             } | ||||
|         }); | ||||
|     } | ||||
| @@ -827,6 +855,11 @@ public class SQLManager implements AbstractDB { | ||||
|         } | ||||
|         PreparedStatement stmt = null; | ||||
|         try { | ||||
|             commit(); | ||||
|             commit(); | ||||
|             if (plot.temp > 0) { | ||||
|                 return plot.temp; | ||||
|             } | ||||
|             stmt = this.connection.prepareStatement("SELECT `id` FROM `" + this.prefix + "plot` WHERE `plot_id_x` = ? AND `plot_id_z` = ? AND world = ? ORDER BY `timestamp` ASC"); | ||||
|             stmt.setInt(1, plot.id.x); | ||||
|             stmt.setInt(2, plot.id.y); | ||||
| @@ -838,6 +871,12 @@ public class SQLManager implements AbstractDB { | ||||
|             } | ||||
|             r.close(); | ||||
|             stmt.close(); | ||||
|             if (id == Integer.MAX_VALUE || id == 0) { | ||||
|                 if (plot.temp > 0) { | ||||
|                     return plot.temp; | ||||
|                 } | ||||
|                 id = 1/0; | ||||
|             } | ||||
|             plot.temp = id; | ||||
|             return id; | ||||
|         } catch (final SQLException e) { | ||||
| @@ -845,7 +884,7 @@ public class SQLManager implements AbstractDB { | ||||
|         } | ||||
|         return Integer.MAX_VALUE; | ||||
|     } | ||||
|  | ||||
|      | ||||
|     public void updateTables() { | ||||
|         if (PS.get().getVersion().equals(PS.get().getLastVersion()) ||  PS.get().getLastVersion() == null) { | ||||
|             return; | ||||
| @@ -2276,15 +2315,11 @@ public class SQLManager implements AbstractDB { | ||||
|         PS.debug("$1All DB transactions during this session are being validated (This may take a while if corrections need to be made)"); | ||||
|         try { | ||||
|             connection.commit(); | ||||
|             connection.setAutoCommit(false); | ||||
|         } | ||||
|         catch (SQLException e) {} | ||||
|         ConcurrentHashMap<String, ConcurrentHashMap<PlotId, Plot>> database = getPlots(); | ||||
|          | ||||
|         ArrayList<Plot> toCreate = new ArrayList<>(); | ||||
|         ArrayList<UUID> toTrusted = new ArrayList<>(); | ||||
|         ArrayList<Plot> toMember = new ArrayList<>(); | ||||
|         ArrayList<Plot> toDenied = new ArrayList<>(); | ||||
|          | ||||
|         for (Plot plot : PS.get().getPlotsRaw()) { | ||||
|             if (plot.temp == -1) { | ||||
| @@ -2393,7 +2428,6 @@ public class SQLManager implements AbstractDB { | ||||
|         PS.debug("$4Done!"); | ||||
|         try { | ||||
|             connection.commit(); | ||||
|             connection.setAutoCommit(true); | ||||
|         } | ||||
|         catch (SQLException e) {} | ||||
|     } | ||||
|   | ||||
| @@ -90,12 +90,12 @@ public class HybridPlotManager extends ClassicPlotManager { | ||||
|     public void createSchemAbs(HybridPlotWorld hpw, Location pos1, Location pos2, int height, boolean clear) { | ||||
|         final int size = hpw.SIZE; | ||||
|         for (int x = pos1.getX(); x <= pos2.getX(); x++) { | ||||
|             short absX = (short) ((x - hpw.ROAD_OFFSET_X) % size); | ||||
|             short absX = (short) ((x - hpw.ROAD_OFFSET_X) & (size - 1)); | ||||
|             if (absX < 0) { | ||||
|                 absX += size; | ||||
|             } | ||||
|             for (int z = pos1.getZ(); z <= pos2.getZ(); z++) { | ||||
|                 short absZ = (short) ((z - hpw.ROAD_OFFSET_Z) % size); | ||||
|                 short absZ = (short) ((z - hpw.ROAD_OFFSET_Z) & (size - 1)); | ||||
|                 if (absZ < 0) { | ||||
|                     absZ += size; | ||||
|                 } | ||||
|   | ||||
| @@ -59,7 +59,7 @@ public class HybridPlotWorld extends ClassicPlotWorld { | ||||
|     @Override | ||||
|     public void loadConfiguration(final ConfigurationSection config) { | ||||
|         super.loadConfiguration(config); | ||||
|         if ((this.ROAD_WIDTH % 2) == 0) { | ||||
|         if ((this.ROAD_WIDTH & 1) == 0) { | ||||
|             this.PATH_WIDTH_LOWER = (short) (Math.floor(this.ROAD_WIDTH / 2) - 1); | ||||
|         } else { | ||||
|             this.PATH_WIDTH_LOWER = (short) (Math.floor(this.ROAD_WIDTH / 2)); | ||||
| @@ -83,7 +83,7 @@ public class HybridPlotWorld extends ClassicPlotWorld { | ||||
|         final Schematic schem3 = SchematicHandler.manager.getSchematic(schem3Str); | ||||
|         final int shift = (int) this.ROAD_WIDTH / 2; | ||||
|         int oddshift = 0; | ||||
|         if ((this.ROAD_WIDTH % 2) != 0) { | ||||
|         if ((this.ROAD_WIDTH & 1) != 0) { | ||||
|             oddshift = 1; | ||||
|         } | ||||
|         if (schem3 != null) { | ||||
| @@ -184,14 +184,14 @@ public class HybridPlotWorld extends ClassicPlotWorld { | ||||
|      | ||||
|     public static byte wrap(byte data, int start) { | ||||
|         if (data >= start && data < start + 4) { | ||||
|             data = (byte) ((((data - start) + 2) % 4) + start); | ||||
|             data = (byte) ((((data - start) + 2) & 3) + start); | ||||
|         } | ||||
|         return data; | ||||
|     } | ||||
|      | ||||
|     public static byte wrap2(byte data, int start) { | ||||
|         if (data >= start && data < start + 2) { | ||||
|             data = (byte) ((((data - start) + 1) % 2) + start); | ||||
|             data = (byte) ((((data - start) + 1) & 1) + start); | ||||
|         } | ||||
|         return data; | ||||
|     } | ||||
|   | ||||
| @@ -53,16 +53,16 @@ public abstract class SquarePlotManager extends GridPlotManager { | ||||
|         int idx; | ||||
|         int idz; | ||||
|         if (x < 0) { | ||||
|             idx = (x/size); | ||||
|             x = size + (x % size); | ||||
|             idx = ((x - 1)/size); | ||||
|             x = size + ((x - 1) % size); | ||||
|         } | ||||
|         else { | ||||
|             idx = (x/size) + 1; | ||||
|             x = (x % size); | ||||
|         } | ||||
|         if (z < 0) { | ||||
|             idz = (z/size); | ||||
|             z = size + (z % size); | ||||
|             idz = ((z - 1)/size); | ||||
|             z = size + ((z - 1) % size); | ||||
|         } | ||||
|         else { | ||||
|             idz = (z/size) + 1; | ||||
| @@ -104,16 +104,16 @@ public abstract class SquarePlotManager extends GridPlotManager { | ||||
|         int rx; | ||||
|         int rz; | ||||
|         if (x < 0) { | ||||
|             dx = (x/size); | ||||
|             rx = size + (x % size); | ||||
|             dx = ((x - 1) / size); | ||||
|             rx = size + ((x - 1) % size); | ||||
|         } | ||||
|         else { | ||||
|             dx = (x/size) + 1; | ||||
|             rx = (x % size); | ||||
|         } | ||||
|         if (z < 0) { | ||||
|             dz = (z/size); | ||||
|             rz = size + (z % size); | ||||
|             dz = ((z - 1)/size); | ||||
|             rz = size + ((z - 1) % size); | ||||
|         } | ||||
|         else { | ||||
|             dz = (z/size) + 1; | ||||
|   | ||||
| @@ -944,14 +944,24 @@ public class MainUtil { | ||||
|         if (MainUtil.worldBorder.containsKey(plot.world)) { | ||||
|             updateWorldBorder(plot); | ||||
|         } | ||||
|         final Plot p = createPlotAbs(uuid, plot); | ||||
|         if (p == null) { | ||||
|         final String w = plot.world; | ||||
|         if (PS.get().getPlot(plot.world, plot.id) != null) { | ||||
|             return true; | ||||
|         } | ||||
|         final Plot p = new Plot(w, plot.id, uuid); | ||||
|         if (p.owner == null) { | ||||
|             return false; | ||||
|         } | ||||
|         final PlotWorld plotworld = PS.get().getPlotWorld(plot.world); | ||||
|         if (plotworld.AUTO_MERGE) { | ||||
|             autoMerge(p, uuid, true); | ||||
|         } | ||||
|         PS.get().updatePlot(p); | ||||
|         DBFunc.createPlotAndSettings(p, new Runnable() { | ||||
|             @Override | ||||
|             public void run() { | ||||
|                 final PlotWorld plotworld = PS.get().getPlotWorld(plot.world); | ||||
|                 if (plotworld.AUTO_MERGE) { | ||||
|                     autoMerge(p, uuid, true); | ||||
|                 } | ||||
|             } | ||||
|         }); | ||||
|         return true; | ||||
|     } | ||||
|  | ||||
| @@ -969,7 +979,7 @@ public class MainUtil { | ||||
|             return null; | ||||
|         } | ||||
|         PS.get().updatePlot(p); | ||||
|         DBFunc.createPlotAndSettings(p); | ||||
|         DBFunc.createPlotAndSettings(p, null); | ||||
|         return p; | ||||
|     } | ||||
|  | ||||
|   | ||||
| @@ -122,6 +122,8 @@ permissions: | ||||
|       plots.untrust: true | ||||
|       plots.undeny: true | ||||
|       plots.kick: true | ||||
|       plots.download: true | ||||
|       plots.save: true | ||||
|   plots.worldedit.bypass: | ||||
|     default: false | ||||
|   plots.gamemode.bypass: | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 boy0001
					boy0001