More than 2 lines

This commit is contained in:
Jesse Boyd 2016-04-02 17:15:28 +11:00
parent 3edfd39af9
commit dffa00858d
12 changed files with 121 additions and 88 deletions

View File

@ -726,7 +726,7 @@ public class PlayerEvents extends PlotListener implements Listener {
plotExit(pp, plot);
}
if (BukkitMain.worldEdit != null) {
if (BukkitMain.worldEdit != null && PS.get().worldedit != null) {
if (!Permissions.hasPermission(pp, C.PERMISSION_WORLDEDIT_BYPASS)) {
if (pp.getAttribute("worldedit")) {
pp.removeAttribute("worldedit");

View File

@ -673,22 +673,6 @@ public class BukkitChunkManager extends ChunkManager {
return chunks;
}
@Override
public void regenerateChunk(String world, ChunkLoc loc) {
World worldObj = Bukkit.getWorld(world);
worldObj.regenerateChunk(loc.x, loc.z);
SetQueue.IMP.queue.sendChunk(world, Collections.singletonList(loc));
for (Entry<String, PlotPlayer> entry : UUIDHandler.getPlayers().entrySet()) {
PlotPlayer pp = entry.getValue();
Location pLoc = pp.getLocation();
if (!StringMan.isEqual(world, pLoc.getWorld()) || !pLoc.getChunkLoc().equals(loc)) {
continue;
}
pLoc.setY(WorldUtil.IMP.getHighestBlock(world, pLoc.getX(), pLoc.getZ()));
pp.teleport(pLoc);
}
}
@Override
public boolean copyRegion(Location pos1, Location pos2, Location newPos, final Runnable whenDone) {
final int relX = newPos.getX() - pos1.getX();

View File

@ -13,6 +13,7 @@ import com.intellectualcrafters.plot.util.ReflectionUtils.RefMethod.RefExecutor;
import com.intellectualcrafters.plot.util.SetQueue;
import com.intellectualcrafters.plot.util.SetQueue.ChunkWrapper;
import com.intellectualcrafters.plot.util.TaskManager;
import com.plotsquared.bukkit.util.BukkitUtil;
import com.plotsquared.bukkit.util.SendChunk;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
@ -37,6 +38,7 @@ public class FastQueue_1_8_3 extends SlowQueue {
private final SendChunk sendChunk;
private final HashMap<ChunkWrapper, Chunk> toUpdate = new HashMap<>();
private final RefMethod methodGetHandleChunk;
private final RefMethod methodGetHandleWorld;
private final RefMethod methodInitLighting;
private final RefConstructor classBlockPositionConstructor;
private final RefConstructor classChunkSectionConstructor;
@ -50,6 +52,7 @@ public class FastQueue_1_8_3 extends SlowQueue {
public FastQueue_1_8_3() throws RuntimeException {
RefClass classCraftChunk = getRefClass("{cb}.CraftChunk");
RefClass classCraftWorld = getRefClass("{cb}.CraftWorld");
this.methodGetHandleChunk = classCraftChunk.getMethod("getHandle");
RefClass classChunk = getRefClass("{nms}.Chunk");
this.methodInitLighting = classChunk.getMethod("initLighting");
@ -64,6 +67,7 @@ public class FastQueue_1_8_3 extends SlowQueue {
this.methodAreNeighborsLoaded = classChunk.getMethod("areNeighborsLoaded", int.class);
this.classChunkSectionConstructor = classChunkSection.getConstructor(int.class, boolean.class, char[].class);
this.tileEntityListTick = classWorld.getField("tileEntityList");
this.methodGetHandleWorld = classCraftWorld.getMethod("getHandle");
this.methodGetWorld = classChunk.getMethod("getWorld");
this.sendChunk = new SendChunk();
TaskManager.runTaskRepeat(new Runnable() {
@ -257,6 +261,17 @@ public class FastQueue_1_8_3 extends SlowQueue {
return new FastChunk_1_8_3(wrap);
}
@Override
public void regenerateChunk(String worldname, ChunkLoc loc) {
World world = BukkitUtil.getWorld(worldname);
Chunk chunk = world.getChunkAt(loc.x, loc.z);
if (chunk.getTileEntities().length > 0) {
Object w = methodGetHandleWorld.of(world).call();
((Collection) this.tileEntityListTick.of(w).get()).clear();
}
super.regenerateChunk(worldname, loc);
}
/**
* This should be overridden by any specialized queues
* @param plotChunk

View File

@ -80,6 +80,18 @@ public class FastQueue_1_9 extends SlowQueue {
MainUtil.initCache();
}
@Override
public void regenerateChunk(String worldname, ChunkLoc loc) {
World world = BukkitUtil.getWorld(worldname);
Chunk chunk = world.getChunkAt(loc.x, loc.z);
if (chunk.getTileEntities().length > 0) {
Object c = methodGetHandleChunk.of(chunk).call();
Object w = methodGetWorld.of(c).call();
((Collection) this.tileEntityListTick.of(w).get()).clear();
}
super.regenerateChunk(worldname, loc);
}
/**
* This should be overridden by any specialized queues
* @param plotChunk

View File

@ -8,6 +8,7 @@ import com.intellectualcrafters.plot.util.PlotChunk;
import com.intellectualcrafters.plot.util.PlotQueue;
import com.intellectualcrafters.plot.util.SetQueue;
import com.intellectualcrafters.plot.util.SetQueue.ChunkWrapper;
import com.plotsquared.bukkit.util.BukkitUtil;
import java.util.Collection;
import java.util.Iterator;
import java.util.Map.Entry;
@ -103,6 +104,11 @@ public class SlowQueue implements PlotQueue<Chunk> {
this.blocks.clear();
}
@Override
public void regenerateChunk(String world, ChunkLoc loc) {
BukkitUtil.getWorld(world).regenerateChunk(loc.x, loc.z);
}
/**
* This should be overridden by any specialized queues.
* @param plotChunk

View File

@ -5,13 +5,16 @@ import com.intellectualcrafters.plot.object.ChunkLoc;
import com.intellectualcrafters.plot.object.ConsolePlayer;
import com.intellectualcrafters.plot.object.Location;
import com.intellectualcrafters.plot.object.Plot;
import com.intellectualcrafters.plot.object.PlotPlayer;
import com.intellectualcrafters.plot.object.RegionWrapper;
import com.intellectualcrafters.plot.object.RunnableVal;
import com.intellectualcrafters.plot.util.SetQueue.ChunkWrapper;
import java.io.File;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
public abstract class ChunkManager {
@ -226,7 +229,19 @@ public abstract class ChunkManager {
return chunks;
}
public abstract void regenerateChunk(String world, ChunkLoc loc);
public void regenerateChunk(String world, ChunkLoc loc) {
SetQueue.IMP.regenerateChunk(world, loc);
SetQueue.IMP.queue.sendChunk(world, Collections.singletonList(loc));
for (Map.Entry<String, PlotPlayer> entry : UUIDHandler.getPlayers().entrySet()) {
PlotPlayer pp = entry.getValue();
Location pLoc = pp.getLocation();
if (!StringMan.isEqual(world, pLoc.getWorld()) || !pLoc.getChunkLoc().equals(loc)) {
continue;
}
pLoc.setY(WorldUtil.IMP.getHighestBlock(world, pLoc.getX(), pLoc.getZ()));
pp.teleport(pLoc);
}
}
public void deleteRegionFiles(String world, Collection<ChunkLoc> chunks) {
deleteRegionFiles(world, chunks, null);

View File

@ -26,5 +26,7 @@ public interface PlotQueue<T> {
PlotChunk<T> next(ChunkWrapper wrap, boolean fixLighting);
void clear();
void regenerateChunk(String world, ChunkLoc loc);
}

View File

@ -1,7 +1,7 @@
package com.intellectualcrafters.plot.util;
import com.intellectualcrafters.plot.object.ChunkLoc;
import com.intellectualcrafters.plot.object.PlotBlock;
import java.util.ArrayDeque;
import java.util.concurrent.atomic.AtomicInteger;
@ -149,6 +149,10 @@ public class SetQueue {
return this.queue.setBlock(world, x, y, z, (short) id, (byte) 0);
}
public void regenerateChunk(String world, ChunkLoc loc) {
queue.regenerateChunk(world, loc);
}
public class ChunkWrapper {
public final int x;

View File

@ -76,10 +76,6 @@ import java.util.Collection;
import java.util.List;
import java.util.UUID;
/**
* Created by robin on 01/11/2014
*/
@Plugin(id = "com.plotsquared", name = "PlotSquared", description = "Easy, yet powerful Plot World generation and management.", url = "https://github.com/IntellectualSites/PlotSquared", version = "3.3.3")
public class SpongeMain implements IPlotMain {
public static SpongeMain THIS;

View File

@ -1,13 +1,13 @@
package com.plotsquared.sponge.util;
import com.intellectualcrafters.plot.PS;
import com.intellectualcrafters.plot.object.ChunkLoc;
import com.intellectualcrafters.plot.object.Location;
import com.intellectualcrafters.plot.object.Plot;
import com.intellectualcrafters.plot.util.ChunkManager;
import com.intellectualcrafters.plot.util.TaskManager;
import net.minecraft.world.chunk.IChunkProvider;
import net.minecraft.world.gen.ChunkProviderServer;
import java.util.Optional;
import java.util.Set;
import java.util.function.Predicate;
import org.spongepowered.api.entity.Entity;
import org.spongepowered.api.entity.living.Living;
import org.spongepowered.api.entity.living.animal.Animal;
@ -15,10 +15,6 @@ import org.spongepowered.api.entity.living.monster.Monster;
import org.spongepowered.api.world.Chunk;
import org.spongepowered.api.world.World;
import java.util.Optional;
import java.util.Set;
import java.util.function.Predicate;
public class SpongeChunkManager extends ChunkManager {
@Override
@ -68,55 +64,6 @@ public class SpongeChunkManager extends ChunkManager {
return super.getChunkChunks(world);
}
@Override
public void regenerateChunk(String world, ChunkLoc loc) {
World spongeWorld = SpongeUtil.getWorld(world);
net.minecraft.world.World nmsWorld = (net.minecraft.world.World) spongeWorld;
Optional<Chunk> chunkOpt = spongeWorld.getChunk(loc.x, 0, loc.z);
if (chunkOpt.isPresent()) {
try {
Chunk spongeChunk = chunkOpt.get();
IChunkProvider provider = nmsWorld.getChunkProvider();
if (!(provider instanceof ChunkProviderServer)) {
PS.debug("Not valid world generator for: " + world);
return;
}
/* ChunkProviderServer chunkServer = (ChunkProviderServer) provider;
IChunkProvider chunkProvider = chunkServer.serverChunkGenerator;
long pos = ChunkCoordIntPair.chunkXZ2Int(loc.x, loc.z);
net.minecraft.world.chunk.Chunk mcChunk = (net.minecraft.world.chunk.Chunk) spongeChunk;
if (chunkServer.chunkExists(loc.x, loc.z)) {
mcChunk = chunkServer.loadChunk(loc.x, loc.z);
mcChunk.onChunkUnload();
}
Field fieldDroppedChunksSet;
try {
fieldDroppedChunksSet = chunkServer.getClass().getField("droppedChunksSet");
} catch (Throwable t) {
fieldDroppedChunksSet = ReflectionUtils.findField(chunkServer.getClass(), Set.class);
}
Set<Long> set = (Set<Long>) fieldDroppedChunksSet.get(chunkServer);
set.remove(pos);
ReflectionUtils.findField(chunkServer.getClass(),)
chunkServer.id2ChunkMap.remove(pos);
mcChunk = chunkProvider.provideChunk(loc.x, loc.z);
chunkServer.id2ChunkMap.add(pos, mcChunk);
chunkServer.loadedChunks.add(mcChunk);
if (mcChunk != null) {
mcChunk.onChunkLoad();
mcChunk.populateChunk(chunkProvider, chunkProvider, loc.x, loc.z);
SetQueue.IMP.queue.sendChunk(world, Arrays.asList(loc));
}
else {
PS.debug("CHUNK IS NULL!?");
}*/
} catch (Throwable e){
e.printStackTrace();
}
}
}
@Override
public boolean copyRegion(Location pos1, Location pos2, Location newPos, Runnable whenDone) {
// TODO copy a region

View File

@ -17,6 +17,13 @@ import com.intellectualcrafters.plot.util.UUIDHandler;
import com.intellectualcrafters.plot.util.WorldUtil;
import com.plotsquared.sponge.SpongeMain;
import com.plotsquared.sponge.object.SpongePlayer;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Optional;
import net.minecraft.block.Block;
import net.minecraft.world.biome.BiomeGenBase;
import org.apache.commons.lang3.NotImplementedException;
@ -42,14 +49,6 @@ import org.spongepowered.api.world.biome.BiomeType;
import org.spongepowered.api.world.biome.BiomeTypes;
import org.spongepowered.api.world.extent.Extent;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Optional;
public class SpongeUtil extends WorldUtil {
public static Cause CAUSE = Cause.of(NamedCause.source("PlotSquared"));

View File

@ -10,6 +10,9 @@ import com.intellectualcrafters.plot.util.PlotQueue;
import com.intellectualcrafters.plot.util.SetQueue;
import com.intellectualcrafters.plot.util.SetQueue.ChunkWrapper;
import com.plotsquared.sponge.util.SpongeUtil;
import java.util.Optional;
import net.minecraft.world.chunk.IChunkProvider;
import net.minecraft.world.gen.ChunkProviderServer;
import org.spongepowered.api.block.BlockState;
import org.spongepowered.api.world.Chunk;
@ -17,6 +20,7 @@ import java.util.Collection;
import java.util.Iterator;
import java.util.Map.Entry;
import java.util.concurrent.ConcurrentHashMap;
import org.spongepowered.api.world.World;
public class SlowQueue implements PlotQueue<Chunk> {
@ -100,7 +104,56 @@ public class SlowQueue implements PlotQueue<Chunk> {
public void clear() {
this.blocks.clear();
}
@Override
public void regenerateChunk(String world, ChunkLoc loc) {
World spongeWorld = SpongeUtil.getWorld(world);
net.minecraft.world.World nmsWorld = (net.minecraft.world.World) spongeWorld;
Optional<Chunk> chunkOpt = spongeWorld.getChunk(loc.x, 0, loc.z);
if (chunkOpt.isPresent()) {
try {
Chunk spongeChunk = chunkOpt.get();
IChunkProvider provider = nmsWorld.getChunkProvider();
if (!(provider instanceof ChunkProviderServer)) {
PS.debug("Not valid world generator for: " + world);
return;
}
/* ChunkProviderServer chunkServer = (ChunkProviderServer) provider;
IChunkProvider chunkProvider = chunkServer.serverChunkGenerator;
long pos = ChunkCoordIntPair.chunkXZ2Int(loc.x, loc.z);
net.minecraft.world.chunk.Chunk mcChunk = (net.minecraft.world.chunk.Chunk) spongeChunk;
if (chunkServer.chunkExists(loc.x, loc.z)) {
mcChunk = chunkServer.loadChunk(loc.x, loc.z);
mcChunk.onChunkUnload();
}
Field fieldDroppedChunksSet;
try {
fieldDroppedChunksSet = chunkServer.getClass().getField("droppedChunksSet");
} catch (Throwable t) {
fieldDroppedChunksSet = ReflectionUtils.findField(chunkServer.getClass(), Set.class);
}
Set<Long> set = (Set<Long>) fieldDroppedChunksSet.get(chunkServer);
set.remove(pos);
ReflectionUtils.findField(chunkServer.getClass(),)
chunkServer.id2ChunkMap.remove(pos);
mcChunk = chunkProvider.provideChunk(loc.x, loc.z);
chunkServer.id2ChunkMap.add(pos, mcChunk);
chunkServer.loadedChunks.add(mcChunk);
if (mcChunk != null) {
mcChunk.onChunkLoad();
mcChunk.populateChunk(chunkProvider, chunkProvider, loc.x, loc.z);
SetQueue.IMP.queue.sendChunk(world, Arrays.asList(loc));
}
else {
PS.debug("CHUNK IS NULL!?");
}*/
} catch (Throwable e){
e.printStackTrace();
}
}
}
/**
* This should be overriden by any specialized queues.
* @param plotChunk