mirror of
				https://github.com/IntellectualSites/PlotSquared.git
				synced 2025-10-30 17:13:43 +01:00 
			
		
		
		
	Compare commits
	
		
			1 Commits
		
	
	
		
			fix/chunk-
			...
			fix/missin
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
|   | 932b7d1a4e | 
| @@ -26,7 +26,6 @@ import com.plotsquared.core.plot.Plot; | |||||||
| import com.plotsquared.core.plot.PlotArea; | import com.plotsquared.core.plot.PlotArea; | ||||||
| import com.plotsquared.core.plot.world.PlotAreaManager; | import com.plotsquared.core.plot.world.PlotAreaManager; | ||||||
| import com.plotsquared.core.plot.world.SinglePlotArea; | import com.plotsquared.core.plot.world.SinglePlotArea; | ||||||
| import com.plotsquared.core.util.ReflectionUtils; |  | ||||||
| import com.plotsquared.core.util.ReflectionUtils.RefClass; | import com.plotsquared.core.util.ReflectionUtils.RefClass; | ||||||
| import com.plotsquared.core.util.ReflectionUtils.RefField; | import com.plotsquared.core.util.ReflectionUtils.RefField; | ||||||
| import com.plotsquared.core.util.ReflectionUtils.RefMethod; | import com.plotsquared.core.util.ReflectionUtils.RefMethod; | ||||||
| @@ -65,11 +64,9 @@ public class ChunkListener implements Listener { | |||||||
|     private final PlotAreaManager plotAreaManager; |     private final PlotAreaManager plotAreaManager; | ||||||
|     private final int version; |     private final int version; | ||||||
|  |  | ||||||
|     private RefMethod methodSetUnsaved; |  | ||||||
|     private RefMethod methodGetHandleChunk; |     private RefMethod methodGetHandleChunk; | ||||||
|     private RefMethod methodGetHandleWorld; |     private RefMethod methodGetHandleWorld; | ||||||
|     private RefField mustNotSave; |     private RefField mustSave; | ||||||
|     private Object objChunkStatusFull = null; |  | ||||||
|     /* |     /* | ||||||
|     private RefMethod methodGetFullChunk; |     private RefMethod methodGetFullChunk; | ||||||
|     private RefMethod methodGetBukkitChunk; |     private RefMethod methodGetBukkitChunk; | ||||||
| @@ -82,6 +79,7 @@ public class ChunkListener implements Listener { | |||||||
|     */ |     */ | ||||||
|     private Chunk lastChunk; |     private Chunk lastChunk; | ||||||
|     private boolean ignoreUnload = false; |     private boolean ignoreUnload = false; | ||||||
|  |     private boolean isTrueForNotSave = true; | ||||||
|  |  | ||||||
|     @Inject |     @Inject | ||||||
|     public ChunkListener(final @NonNull PlotAreaManager plotAreaManager) { |     public ChunkListener(final @NonNull PlotAreaManager plotAreaManager) { | ||||||
| @@ -92,27 +90,22 @@ public class ChunkListener implements Listener { | |||||||
|         } |         } | ||||||
|         try { |         try { | ||||||
|             RefClass classCraftWorld = getRefClass("{cb}.CraftWorld"); |             RefClass classCraftWorld = getRefClass("{cb}.CraftWorld"); | ||||||
|  |             this.methodGetHandleWorld = classCraftWorld.getMethod("getHandle"); | ||||||
|             RefClass classCraftChunk = getRefClass("{cb}.CraftChunk"); |             RefClass classCraftChunk = getRefClass("{cb}.CraftChunk"); | ||||||
|             ReflectionUtils.RefClass classChunkAccess = getRefClass("net.minecraft.world.level.chunk.IChunkAccess"); |  | ||||||
|             this.methodSetUnsaved = classChunkAccess.getMethod("a", boolean.class); |  | ||||||
|             try { |  | ||||||
|             this.methodGetHandleChunk = classCraftChunk.getMethod("getHandle"); |             this.methodGetHandleChunk = classCraftChunk.getMethod("getHandle"); | ||||||
|             } catch (NoSuchMethodException ignored) { |  | ||||||
|                 try { |  | ||||||
|                     RefClass classChunkStatus = getRefClass("net.minecraft.world.level.chunk.ChunkStatus"); |  | ||||||
|                     this.objChunkStatusFull = classChunkStatus.getRealClass().getField("n").get(null); |  | ||||||
|                     this.methodGetHandleChunk = classCraftChunk.getMethod("getHandle", classChunkStatus.getRealClass()); |  | ||||||
|                 } catch (NoSuchMethodException ex) { |  | ||||||
|                     throw new RuntimeException(ex); |  | ||||||
|                 } |  | ||||||
|             } |  | ||||||
|             try { |             try { | ||||||
|                 if (version < 17) { |                 if (version < 17) { | ||||||
|                     RefClass classChunk = getRefClass("{nms}.Chunk"); |                     RefClass classChunk = getRefClass("{nms}.Chunk"); | ||||||
|                     this.mustNotSave = classChunk.getField("mustNotSave"); |                     if (version == 13) { | ||||||
|  |                         this.mustSave = classChunk.getField("mustSave"); | ||||||
|  |                         this.isTrueForNotSave = false; | ||||||
|  |                     } else { | ||||||
|  |                         this.mustSave = classChunk.getField("mustNotSave"); | ||||||
|  |                     } | ||||||
|                 } else { |                 } else { | ||||||
|                     RefClass classChunk = getRefClass("net.minecraft.world.level.chunk.Chunk"); |                     RefClass classChunk = getRefClass("net.minecraft.world.level.chunk.Chunk"); | ||||||
|                     this.mustNotSave = classChunk.getField("mustNotSave"); |                     this.mustSave = classChunk.getField("mustNotSave"); | ||||||
|  |  | ||||||
|                 } |                 } | ||||||
|             } catch (NoSuchFieldException e) { |             } catch (NoSuchFieldException e) { | ||||||
|                 e.printStackTrace(); |                 e.printStackTrace(); | ||||||
| @@ -174,13 +167,10 @@ public class ChunkListener implements Listener { | |||||||
|         if (safe && shouldSave(world, chunk.getX(), chunk.getZ())) { |         if (safe && shouldSave(world, chunk.getX(), chunk.getZ())) { | ||||||
|             return false; |             return false; | ||||||
|         } |         } | ||||||
|         Object c = objChunkStatusFull != null |         Object c = this.methodGetHandleChunk.of(chunk).call(); | ||||||
|                 ? this.methodGetHandleChunk.of(chunk).call(objChunkStatusFull) |         RefField.RefExecutor field = this.mustSave.of(c); | ||||||
|                 : this.methodGetHandleChunk.of(chunk).call(); |         if ((Boolean) field.get() != isTrueForNotSave) { | ||||||
|         RefField.RefExecutor field = this.mustNotSave.of(c); |             field.set(isTrueForNotSave); | ||||||
|         methodSetUnsaved.of(c).call(false); |  | ||||||
|         if (!((Boolean) field.get())) { |  | ||||||
|             field.set(true); |  | ||||||
|             if (chunk.isLoaded()) { |             if (chunk.isLoaded()) { | ||||||
|                 ignoreUnload = true; |                 ignoreUnload = true; | ||||||
|                 chunk.unload(false); |                 chunk.unload(false); | ||||||
|   | |||||||
| @@ -31,39 +31,45 @@ import org.bukkit.event.Listener; | |||||||
| import org.bukkit.event.world.ChunkEvent; | import org.bukkit.event.world.ChunkEvent; | ||||||
| import org.bukkit.event.world.ChunkLoadEvent; | import org.bukkit.event.world.ChunkLoadEvent; | ||||||
|  |  | ||||||
|  | import java.lang.reflect.Field; | ||||||
| import java.lang.reflect.Method; | import java.lang.reflect.Method; | ||||||
|  |  | ||||||
| import static com.plotsquared.core.util.ReflectionUtils.getRefClass; | import static com.plotsquared.core.util.ReflectionUtils.getRefClass; | ||||||
|  |  | ||||||
| public class SingleWorldListener implements Listener { | public class SingleWorldListener implements Listener { | ||||||
|  |  | ||||||
|     private final Method methodSetUnsaved; |     private final Method methodGetHandleChunk; | ||||||
|     private Method methodGetHandleChunk; |     private Field shouldSave = null; | ||||||
|     private Object objChunkStatusFull = null; |  | ||||||
|  |  | ||||||
|     public SingleWorldListener() throws Exception { |     public SingleWorldListener() throws Exception { | ||||||
|         ReflectionUtils.RefClass classCraftChunk = getRefClass("{cb}.CraftChunk"); |         ReflectionUtils.RefClass classCraftChunk = getRefClass("{cb}.CraftChunk"); | ||||||
|         ReflectionUtils.RefClass classChunkAccess = getRefClass("net.minecraft.world.level.chunk.IChunkAccess"); |  | ||||||
|         this.methodSetUnsaved = classChunkAccess.getMethod("a", boolean.class).getRealMethod(); |  | ||||||
|         try { |  | ||||||
|         this.methodGetHandleChunk = classCraftChunk.getMethod("getHandle").getRealMethod(); |         this.methodGetHandleChunk = classCraftChunk.getMethod("getHandle").getRealMethod(); | ||||||
|         } catch (NoSuchMethodException ignored) { |  | ||||||
|         try { |         try { | ||||||
|                 ReflectionUtils.RefClass classChunkStatus = getRefClass("net.minecraft.world.level.chunk.ChunkStatus"); |             if (PlotSquared.platform().serverVersion()[1] < 17) { | ||||||
|                 this.objChunkStatusFull = classChunkStatus.getRealClass().getField("n").get(null); |                 ReflectionUtils.RefClass classChunk = getRefClass("{nms}.Chunk"); | ||||||
|                 this.methodGetHandleChunk = classCraftChunk.getMethod("getHandle", classChunkStatus.getRealClass()).getRealMethod(); |                 if (PlotSquared.platform().serverVersion()[1] == 13) { | ||||||
|             } catch (NoSuchMethodException ex) { |                     this.shouldSave = classChunk.getField("mustSave").getRealField(); | ||||||
|                 throw new RuntimeException(ex); |                 } else { | ||||||
|  |                     this.shouldSave = classChunk.getField("s").getRealField(); | ||||||
|                 } |                 } | ||||||
|  |             } else if (PlotSquared.platform().serverVersion()[1] == 17) { | ||||||
|  |                 ReflectionUtils.RefClass classChunk = getRefClass("net.minecraft.world.level.chunk.Chunk"); | ||||||
|  |                 this.shouldSave = classChunk.getField("r").getRealField(); | ||||||
|  |             } else if (PlotSquared.platform().serverVersion()[1] == 18) { | ||||||
|  |                 ReflectionUtils.RefClass classChunk = getRefClass("net.minecraft.world.level.chunk.IChunkAccess"); | ||||||
|  |                 this.shouldSave = classChunk.getField("b").getRealField(); | ||||||
|  |             } | ||||||
|  |         } catch (NoSuchFieldException e) { | ||||||
|  |             e.printStackTrace(); | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     public void markChunkAsClean(Chunk chunk) { |     public void markChunkAsClean(Chunk chunk) { | ||||||
|         try { |         try { | ||||||
|             Object nmsChunk = objChunkStatusFull != null |             Object nmsChunk = methodGetHandleChunk.invoke(chunk); | ||||||
|                     ? this.methodGetHandleChunk.invoke(chunk, objChunkStatusFull) |             if (shouldSave != null) { | ||||||
|                     : this.methodGetHandleChunk.invoke(chunk); |                 this.shouldSave.set(nmsChunk, false); | ||||||
|             methodSetUnsaved.invoke(nmsChunk, false); |             } | ||||||
|         } catch (Throwable e) { |         } catch (Throwable e) { | ||||||
|             e.printStackTrace(); |             e.printStackTrace(); | ||||||
|         } |         } | ||||||
| @@ -79,12 +85,7 @@ public class SingleWorldListener implements Listener { | |||||||
|         if (!SinglePlotArea.isSinglePlotWorld(name)) { |         if (!SinglePlotArea.isSinglePlotWorld(name)) { | ||||||
|             return; |             return; | ||||||
|         } |         } | ||||||
|         int x = event.getChunk().getX(); |  | ||||||
|         int z = event.getChunk().getZ(); |  | ||||||
|         if (x < 16 && x > -16 && z < 16 && z > -16) { |  | ||||||
|             // Allow spawn to generate |  | ||||||
|             return; |  | ||||||
|         } |  | ||||||
|         markChunkAsClean(event.getChunk()); |         markChunkAsClean(event.getChunk()); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|   | |||||||
| @@ -60,6 +60,19 @@ public final class UncheckedWorldLocation extends Location { | |||||||
|         return new UncheckedWorldLocation(world, x, y, z); |         return new UncheckedWorldLocation(world, x, y, z); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  |     /** | ||||||
|  |      * Construct a new location with yaw and pitch equal to 0 | ||||||
|  |      * | ||||||
|  |      * @param world World | ||||||
|  |      * @param loc   Coordinates | ||||||
|  |      * @return New location | ||||||
|  |      * @since 6.9.0 | ||||||
|  |      */ | ||||||
|  |     @DoNotUse | ||||||
|  |     public static @NonNull UncheckedWorldLocation at(final @NonNull String world, BlockVector3 loc) { | ||||||
|  |         return new UncheckedWorldLocation(world, loc.getX(), loc.getY(), loc.getZ()); | ||||||
|  |     } | ||||||
|  |  | ||||||
|     @Override |     @Override | ||||||
|     @DoNotUse |     @DoNotUse | ||||||
|     public @NonNull String getWorldName() { |     public @NonNull String getWorldName() { | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user