Upstream merge of TranslationManager and ResourceLoader

This commit is contained in:
MattBDev
2020-08-24 12:38:30 -04:00
parent 1bef8901bf
commit fd336feb46
16 changed files with 489 additions and 246 deletions

View File

@ -14,7 +14,21 @@ import com.sk89q.worldedit.world.block.BlockState;
import com.sk89q.worldedit.world.block.BlockTypesCache;
import io.papermc.lib.PaperLib;
import net.jpountz.util.UnsafeUtils;
import net.minecraft.server.v1_16_R2.*;
import net.minecraft.server.v1_16_R2.Block;
import net.minecraft.server.v1_16_R2.Chunk;
import net.minecraft.server.v1_16_R2.ChunkCoordIntPair;
import net.minecraft.server.v1_16_R2.ChunkSection;
import net.minecraft.server.v1_16_R2.DataBits;
import net.minecraft.server.v1_16_R2.DataPalette;
import net.minecraft.server.v1_16_R2.DataPaletteBlock;
import net.minecraft.server.v1_16_R2.DataPaletteLinear;
import net.minecraft.server.v1_16_R2.GameProfileSerializer;
import net.minecraft.server.v1_16_R2.IBlockData;
import net.minecraft.server.v1_16_R2.PacketPlayOutLightUpdate;
import net.minecraft.server.v1_16_R2.PlayerChunk;
import net.minecraft.server.v1_16_R2.PlayerChunkMap;
import net.minecraft.server.v1_16_R2.World;
import net.minecraft.server.v1_16_R2.WorldServer;
import org.bukkit.craftbukkit.v1_16_R2.CraftChunk;
import org.bukkit.craftbukkit.v1_16_R2.CraftWorld;
import sun.misc.Unsafe;
@ -34,20 +48,20 @@ public final class BukkitAdapter_1_16_2 extends NMSAdapter {
/*
NMS fields
*/
public final static Field fieldBits;
public final static Field fieldPalette;
public final static Field fieldSize;
public static final Field fieldBits;
public static final Field fieldPalette;
public static final Field fieldSize;
public final static Field fieldBitsPerEntry;
public static final Field fieldBitsPerEntry;
public final static Field fieldFluidCount;
public final static Field fieldTickingBlockCount;
public final static Field fieldNonEmptyBlockCount;
public static final Field fieldFluidCount;
public static final Field fieldTickingBlockCount;
public static final Field fieldNonEmptyBlockCount;
private final static Field fieldDirtyCount;
private final static Field fieldDirtyBits;
private static final Field fieldDirtyCount;
private static final Field fieldDirtyBits;
private final static MethodHandle methodGetVisibleChunk;
private static final MethodHandle methodGetVisibleChunk;
private static final int CHUNKSECTION_BASE;
private static final int CHUNKSECTION_SHIFT;
@ -128,17 +142,17 @@ public final class BukkitAdapter_1_16_2 extends NMSAdapter {
}
}
public static Chunk ensureLoaded(World nmsWorld, int X, int Z) {
Chunk nmsChunk = nmsWorld.getChunkProvider().getChunkAt(X, Z, false);
public static Chunk ensureLoaded(World nmsWorld, int chunkX, int chunkZ) {
Chunk nmsChunk = nmsWorld.getChunkProvider().getChunkAt(chunkX, chunkZ, false);
if (nmsChunk != null) {
return nmsChunk;
}
if (Fawe.isMainThread()) {
return nmsWorld.getChunkAt(X, Z);
return nmsWorld.getChunkAt(chunkX, chunkZ);
}
if (PaperLib.isPaper()) {
CraftWorld craftWorld = nmsWorld.getWorld();
CompletableFuture<org.bukkit.Chunk> future = craftWorld.getChunkAtAsync(X, Z, true);
CompletableFuture<org.bukkit.Chunk> future = craftWorld.getChunkAtAsync(chunkX, chunkZ, true);
try {
CraftChunk chunk = (CraftChunk) future.get();
return chunk.getHandle();
@ -147,20 +161,20 @@ public final class BukkitAdapter_1_16_2 extends NMSAdapter {
}
}
// TODO optimize
return TaskManager.IMP.sync(() -> nmsWorld.getChunkAt(X, Z));
return TaskManager.IMP.sync(() -> nmsWorld.getChunkAt(chunkX, chunkZ));
}
public static PlayerChunk getPlayerChunk(WorldServer nmsWorld, final int cx, final int cz) {
public static PlayerChunk getPlayerChunk(WorldServer nmsWorld, final int chunkX, final int chunkZ) {
PlayerChunkMap chunkMap = nmsWorld.getChunkProvider().playerChunkMap;
try {
return (PlayerChunk)methodGetVisibleChunk.invoke(chunkMap, ChunkCoordIntPair.pair(cx, cz));
return (PlayerChunk)methodGetVisibleChunk.invoke(chunkMap, ChunkCoordIntPair.pair(chunkX, chunkZ));
} catch (Throwable thr) {
throw new RuntimeException(thr);
}
}
public static void sendChunk(WorldServer nmsWorld, int X, int Z, int mask, boolean lighting) {
PlayerChunk playerChunk = getPlayerChunk(nmsWorld, X, Z);
public static void sendChunk(WorldServer nmsWorld, int chunkX, int chunkZ, int mask, boolean lighting) {
PlayerChunk playerChunk = getPlayerChunk(nmsWorld, chunkX, chunkZ);
if (playerChunk == null) {
return;
}
@ -181,7 +195,7 @@ public final class BukkitAdapter_1_16_2 extends NMSAdapter {
fieldDirtyCount.set(playerChunk, 64);
if (lighting) {
ChunkCoordIntPair chunkCoordIntPair = new ChunkCoordIntPair(X, Z);
ChunkCoordIntPair chunkCoordIntPair = new ChunkCoordIntPair(chunkX, chunkZ);
boolean trustEdges = false; //Added in 1.16.1 Not sure what it does.
PacketPlayOutLightUpdate packet = new PacketPlayOutLightUpdate(chunkCoordIntPair, nmsWorld.getChunkProvider().getLightEngine(), trustEdges);
playerChunk.players.a(chunkCoordIntPair, false).forEach(p -> {

View File

@ -1,8 +1,26 @@
/*
* WorldEdit, a Minecraft world manipulation toolkit
* Copyright (C) sk89q <http://www.sk89q.com>
* Copyright (C) WorldEdit team and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.sk89q.worldedit.bukkit;
import com.sk89q.worldedit.world.registry.BundledItemRegistry;
import org.bukkit.Material;
import org.bukkit.block.data.BlockData;
import java.util.ArrayList;
import java.util.Collection;

View File

@ -3,18 +3,18 @@
* Copyright (C) sk89q <http://www.sk89q.com>
* Copyright (C) WorldEdit team and contributors
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by the
* Free Software Foundation, either version 3 of the License, or
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
* for more details.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.sk89q.worldedit.bukkit;
@ -26,6 +26,7 @@ import com.sk89q.worldedit.LocalConfiguration;
import com.sk89q.worldedit.WorldEdit;
import com.sk89q.worldedit.command.util.PermissionCondition;
import com.sk89q.worldedit.entity.Player;
import com.sk89q.worldedit.extension.platform.AbstractPlatform;
import com.sk89q.worldedit.extension.platform.Actor;
import com.sk89q.worldedit.extension.platform.Capability;
import com.sk89q.worldedit.extension.platform.MultiUserPlatform;
@ -41,7 +42,6 @@ import org.bukkit.World;
import org.bukkit.entity.EntityType;
import org.enginehub.piston.CommandManager;
import javax.annotation.Nullable;
import java.util.ArrayList;
import java.util.Collection;
import java.util.EnumMap;
@ -50,27 +50,30 @@ import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import javax.annotation.Nullable;
import static com.sk89q.worldedit.util.formatting.WorldEditText.reduceToText;
public class BukkitServerInterface implements MultiUserPlatform {
public Server server;
public WorldEditPlugin plugin;
private CommandRegistration dynamicCommands;
public class BukkitServerInterface extends AbstractPlatform implements MultiUserPlatform {
public final Server server;
public final WorldEditPlugin plugin;
private final CommandRegistration dynamicCommands;
private final LazyReference<Watchdog> watchdog;
private boolean hookingEvents;
private final LazyReference<Watchdog> watchdog = LazyReference.from(() -> {
if (plugin.getBukkitImplAdapter() != null) {
return plugin.getBukkitImplAdapter().supportsWatchdog()
? new BukkitWatchdog(plugin.getBukkitImplAdapter())
: null;
}
return null;
});
public BukkitServerInterface(WorldEditPlugin plugin, Server server) {
this.plugin = plugin;
this.server = server;
dynamicCommands = new CommandRegistration(plugin);
this.dynamicCommands = new CommandRegistration(plugin);
this.watchdog = LazyReference.from(() -> {
if (plugin.getBukkitImplAdapter() != null) {
return plugin.getBukkitImplAdapter().supportsWatchdog()
? new BukkitWatchdog(plugin.getBukkitImplAdapter())
: null;
}
return null;
});
}
CommandRegistration getDynamicCommands() {
@ -107,6 +110,7 @@ public class BukkitServerInterface implements MultiUserPlatform {
if (!type.startsWith("minecraft:")) {
return false;
}
@SuppressWarnings("deprecation")
final EntityType entityType = EntityType.fromName(type.substring(10));
return entityType != null && entityType.isAlive();
}