Fix singleworlds

This commit is contained in:
dordsor21
2021-01-07 21:24:38 +00:00
committed by Alexander Söderberg
parent 7ac3f7ca03
commit 3cea734b9b
13 changed files with 71 additions and 34 deletions

View File

@ -490,6 +490,7 @@ public final class BukkitPlatform extends JavaPlugin implements Listener, PlotPl
TaskManager.getPlatformImplementation().taskRepeat(this::unload, TaskTime.seconds(1L));
try {
singleWorldListener = injector().getInstance(SingleWorldListener.class);
Bukkit.getPluginManager().registerEvents(singleWorldListener, this);
} catch (Exception e) {
e.printStackTrace();
}

View File

@ -31,6 +31,7 @@ import com.google.inject.Singleton;
import com.google.inject.assistedinject.FactoryModuleBuilder;
import com.google.inject.assistedinject.FactoryProvider;
import com.plotsquared.bukkit.BukkitPlatform;
import com.plotsquared.bukkit.listener.SingleWorldListener;
import com.plotsquared.bukkit.player.BukkitPlayerManager;
import com.plotsquared.bukkit.queue.BukkitChunkCoordinator;
import com.plotsquared.bukkit.queue.BukkitQueueCoordinator;
@ -104,6 +105,11 @@ public class BukkitModule extends AbstractModule {
bind(SchematicHandler.class).to(BukkitSchematicHandler.class);
if (Settings.Enabled_Components.WORLDS) {
bind(PlotAreaManager.class).to(SinglePlotAreaManager.class);
try {
bind(SingleWorldListener.class).toInstance(new SingleWorldListener());
} catch (Exception e) {
e.printStackTrace();
}
} else {
bind(PlotAreaManager.class).to(DefaultPlotAreaManager.class);
}

View File

@ -29,7 +29,6 @@ import com.plotsquared.core.PlotSquared;
import com.plotsquared.core.plot.world.PlotAreaManager;
import com.plotsquared.core.plot.world.SinglePlotAreaManager;
import com.plotsquared.core.util.ReflectionUtils;
import org.bukkit.Bukkit;
import org.bukkit.Chunk;
import org.bukkit.World;
import org.bukkit.event.EventHandler;
@ -37,7 +36,6 @@ import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.world.ChunkEvent;
import org.bukkit.event.world.ChunkLoadEvent;
import org.bukkit.plugin.java.JavaPlugin;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
@ -49,24 +47,29 @@ public class SingleWorldListener implements Listener {
private Method methodGetHandleChunk;
private Field mustSave;
private boolean isTrueForNotSave = true;
public SingleWorldListener(JavaPlugin plugin) throws Exception {
public SingleWorldListener() throws Exception {
ReflectionUtils.RefClass classChunk = getRefClass("{nms}.Chunk");
ReflectionUtils.RefClass classCraftChunk = getRefClass("{cb}.CraftChunk");
this.methodGetHandleChunk = classCraftChunk.getMethod("getHandle").getRealMethod();
try {
this.mustSave = classChunk.getField("mustSave").getRealField();
if (PlotSquared.platform().serverVersion()[1] == 13) {
this.mustSave = classChunk.getField("mustSave").getRealField();
this.isTrueForNotSave = false;
} else {
this.mustSave = classChunk.getField("mustNotSave").getRealField();
}
} catch (NoSuchFieldException e) {
e.printStackTrace();
}
Bukkit.getPluginManager().registerEvents(this, plugin);
}
public void markChunkAsClean(Chunk chunk) {
try {
Object nmsChunk = methodGetHandleChunk.invoke(chunk);
if (mustSave != null) {
this.mustSave.set(nmsChunk, false);
this.mustSave.set(nmsChunk, isTrueForNotSave);
}
} catch (Throwable e) {
e.printStackTrace();
@ -101,8 +104,7 @@ public class SingleWorldListener implements Listener {
int separator = 0;
for (int i = 0; i < len; i++) {
switch (worldName.charAt(i)) {
case ',':
case ';':
case '_':
separator++;
break;
case '-':

View File

@ -32,6 +32,7 @@ import org.bukkit.Bukkit;
import org.bukkit.World;
import org.bukkit.WorldCreator;
import org.bukkit.WorldType;
import org.jetbrains.annotations.NotNull;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
@ -63,7 +64,7 @@ import java.util.List;
}
protected void setGenerator(@Nullable final String worldName, @Nullable final String generator) {
if (generator == null || worldName != null && worldName.contains(".")) {
if (generator == null) {
return;
}
File file = new File("bukkit.yml").getAbsoluteFile();