Remap CraftBukkit to Mojang+Yarn Mappings
By: Initial Source <noreply+automated@papermc.io>
This commit is contained in:
@@ -43,10 +43,10 @@ public final class ApiVersion implements Comparable<ApiVersion>, Serializable {
|
||||
|
||||
public static ApiVersion getOrCreateVersion(String versionString) {
|
||||
if (versionString == null || versionString.trim().isEmpty() || versionString.equalsIgnoreCase("none")) {
|
||||
return versions.computeIfAbsent("none", s -> new ApiVersion());
|
||||
return ApiVersion.versions.computeIfAbsent("none", s -> new ApiVersion());
|
||||
}
|
||||
|
||||
ApiVersion version = versions.get(versionString);
|
||||
ApiVersion version = ApiVersion.versions.get(versionString);
|
||||
|
||||
if (version != null) {
|
||||
return version;
|
||||
@@ -58,18 +58,18 @@ public final class ApiVersion implements Comparable<ApiVersion>, Serializable {
|
||||
throw new IllegalArgumentException(String.format("API version string should be of format \"major.minor.patch\" or \"major.minor\", where \"major\", \"minor\" and \"patch\" are numbers. For example \"1.18.2\" or \"1.13\", but got '%s' instead.", versionString));
|
||||
}
|
||||
|
||||
int major = parseNumber(versionParts[0]);
|
||||
int minor = parseNumber(versionParts[1]);
|
||||
int major = ApiVersion.parseNumber(versionParts[0]);
|
||||
int minor = ApiVersion.parseNumber(versionParts[1]);
|
||||
|
||||
int patch;
|
||||
if (versionParts.length == 3) {
|
||||
patch = parseNumber(versionParts[2]);
|
||||
patch = ApiVersion.parseNumber(versionParts[2]);
|
||||
} else {
|
||||
patch = 0;
|
||||
}
|
||||
|
||||
versionString = toVersionString(major, minor, patch);
|
||||
return versions.computeIfAbsent(versionString, s -> new ApiVersion(major, minor, patch));
|
||||
versionString = ApiVersion.toVersionString(major, minor, patch);
|
||||
return ApiVersion.versions.computeIfAbsent(versionString, s -> new ApiVersion(major, minor, patch));
|
||||
}
|
||||
|
||||
private static int parseNumber(String number) {
|
||||
@@ -82,46 +82,46 @@ public final class ApiVersion implements Comparable<ApiVersion>, Serializable {
|
||||
|
||||
@Override
|
||||
public int compareTo(@NotNull ApiVersion other) {
|
||||
int result = Integer.compare(major, other.major);
|
||||
int result = Integer.compare(this.major, other.major);
|
||||
|
||||
if (result == 0) {
|
||||
result = Integer.compare(minor, other.minor);
|
||||
result = Integer.compare(this.minor, other.minor);
|
||||
}
|
||||
|
||||
if (result == 0) {
|
||||
result = Integer.compare(patch, other.patch);
|
||||
result = Integer.compare(this.patch, other.patch);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public String getVersionString() {
|
||||
if (none) {
|
||||
if (this.none) {
|
||||
return "none";
|
||||
}
|
||||
|
||||
return toVersionString(major, minor, patch);
|
||||
return ApiVersion.toVersionString(this.major, this.minor, this.patch);
|
||||
}
|
||||
|
||||
public boolean isNewerThan(ApiVersion apiVersion) {
|
||||
return compareTo(apiVersion) > 0;
|
||||
return this.compareTo(apiVersion) > 0;
|
||||
}
|
||||
|
||||
public boolean isOlderThan(ApiVersion apiVersion) {
|
||||
return compareTo(apiVersion) < 0;
|
||||
return this.compareTo(apiVersion) < 0;
|
||||
}
|
||||
|
||||
public boolean isNewerThanOrSameAs(ApiVersion apiVersion) {
|
||||
return compareTo(apiVersion) >= 0;
|
||||
return this.compareTo(apiVersion) >= 0;
|
||||
}
|
||||
|
||||
public boolean isOlderThanOrSameAs(ApiVersion apiVersion) {
|
||||
return compareTo(apiVersion) <= 0;
|
||||
return this.compareTo(apiVersion) <= 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return getVersionString();
|
||||
return this.getVersionString();
|
||||
}
|
||||
|
||||
private static final long serialVersionUID = 0L;
|
||||
|
||||
@@ -7,88 +7,87 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.function.Predicate;
|
||||
import net.minecraft.core.BlockPosition;
|
||||
import net.minecraft.core.IRegistryCustom;
|
||||
import net.minecraft.server.level.WorldServer;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.RegistryAccess;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import net.minecraft.util.RandomSource;
|
||||
import net.minecraft.world.level.GeneratorAccess;
|
||||
import net.minecraft.world.level.block.ITileEntity;
|
||||
import net.minecraft.world.level.block.entity.TileEntity;
|
||||
import net.minecraft.world.level.block.state.IBlockData;
|
||||
import net.minecraft.world.level.dimension.DimensionManager;
|
||||
import net.minecraft.world.level.material.Fluid;
|
||||
import net.minecraft.world.level.storage.WorldData;
|
||||
import net.minecraft.world.level.LevelAccessor;
|
||||
import net.minecraft.world.level.block.EntityBlock;
|
||||
import net.minecraft.world.level.block.entity.BlockEntity;
|
||||
import net.minecraft.world.level.dimension.DimensionType;
|
||||
import net.minecraft.world.level.material.FluidState;
|
||||
import net.minecraft.world.level.storage.LevelData;
|
||||
import org.bukkit.block.BlockState;
|
||||
import org.bukkit.craftbukkit.block.CraftBlock;
|
||||
import org.bukkit.craftbukkit.block.CraftBlockEntityState;
|
||||
import org.bukkit.craftbukkit.block.CraftBlockState;
|
||||
|
||||
public class BlockStateListPopulator extends DummyGeneratorAccess {
|
||||
private final GeneratorAccess world;
|
||||
private final Map<BlockPosition, IBlockData> dataMap = new HashMap<>();
|
||||
private final Map<BlockPosition, TileEntity> entityMap = new HashMap<>();
|
||||
private final LinkedHashMap<BlockPosition, CraftBlockState> list;
|
||||
private final LevelAccessor world;
|
||||
private final Map<BlockPos, net.minecraft.world.level.block.state.BlockState> dataMap = new HashMap<>();
|
||||
private final Map<BlockPos, BlockEntity> entityMap = new HashMap<>();
|
||||
private final LinkedHashMap<BlockPos, CraftBlockState> list;
|
||||
|
||||
public BlockStateListPopulator(GeneratorAccess world) {
|
||||
public BlockStateListPopulator(LevelAccessor world) {
|
||||
this(world, new LinkedHashMap<>());
|
||||
}
|
||||
|
||||
private BlockStateListPopulator(GeneratorAccess world, LinkedHashMap<BlockPosition, CraftBlockState> list) {
|
||||
private BlockStateListPopulator(LevelAccessor world, LinkedHashMap<BlockPos, CraftBlockState> list) {
|
||||
this.world = world;
|
||||
this.list = list;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IBlockData getBlockState(BlockPosition bp) {
|
||||
IBlockData blockData = dataMap.get(bp);
|
||||
return (blockData != null) ? blockData : world.getBlockState(bp);
|
||||
public net.minecraft.world.level.block.state.BlockState getBlockState(BlockPos pos) {
|
||||
net.minecraft.world.level.block.state.BlockState blockData = this.dataMap.get(pos);
|
||||
return (blockData != null) ? blockData : this.world.getBlockState(pos);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Fluid getFluidState(BlockPosition bp) {
|
||||
IBlockData blockData = dataMap.get(bp);
|
||||
return (blockData != null) ? blockData.getFluidState() : world.getFluidState(bp);
|
||||
public FluidState getFluidState(BlockPos pos) {
|
||||
net.minecraft.world.level.block.state.BlockState blockData = this.dataMap.get(pos);
|
||||
return (blockData != null) ? blockData.getFluidState() : this.world.getFluidState(pos);
|
||||
}
|
||||
|
||||
@Override
|
||||
public TileEntity getBlockEntity(BlockPosition blockposition) {
|
||||
public BlockEntity getBlockEntity(BlockPos pos) {
|
||||
// The contains is important to check for null values
|
||||
if (entityMap.containsKey(blockposition)) {
|
||||
return entityMap.get(blockposition);
|
||||
if (this.entityMap.containsKey(pos)) {
|
||||
return this.entityMap.get(pos);
|
||||
}
|
||||
|
||||
return world.getBlockEntity(blockposition);
|
||||
return this.world.getBlockEntity(pos);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean setBlock(BlockPosition position, IBlockData data, int flag) {
|
||||
position = position.immutable();
|
||||
public boolean setBlock(BlockPos pos, net.minecraft.world.level.block.state.BlockState state, int flags) {
|
||||
pos = pos.immutable();
|
||||
// remove first to keep insertion order
|
||||
list.remove(position);
|
||||
this.list.remove(pos);
|
||||
|
||||
dataMap.put(position, data);
|
||||
if (data.hasBlockEntity()) {
|
||||
entityMap.put(position, ((ITileEntity) data.getBlock()).newBlockEntity(position, data));
|
||||
this.dataMap.put(pos, state);
|
||||
if (state.hasBlockEntity()) {
|
||||
this.entityMap.put(pos, ((EntityBlock) state.getBlock()).newBlockEntity(pos, state));
|
||||
} else {
|
||||
entityMap.put(position, null);
|
||||
this.entityMap.put(pos, null);
|
||||
}
|
||||
|
||||
// use 'this' to ensure that the block state is the correct TileState
|
||||
CraftBlockState state = (CraftBlockState) CraftBlock.at(this, position).getState();
|
||||
state.setFlag(flag);
|
||||
CraftBlockState state1 = (CraftBlockState) CraftBlock.at(this, pos).getState();
|
||||
state1.setFlag(flags);
|
||||
// set world handle to ensure that updated calls are done to the world and not to this populator
|
||||
state.setWorldHandle(world);
|
||||
list.put(position, state);
|
||||
state1.setWorldHandle(this.world);
|
||||
this.list.put(pos, state1);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public WorldServer getMinecraftWorld() {
|
||||
return world.getMinecraftWorld();
|
||||
public ServerLevel getMinecraftWorld() {
|
||||
return this.world.getMinecraftWorld();
|
||||
}
|
||||
|
||||
public void refreshTiles() {
|
||||
for (CraftBlockState state : list.values()) {
|
||||
for (CraftBlockState state : this.list.values()) {
|
||||
if (state instanceof CraftBlockEntityState) {
|
||||
((CraftBlockEntityState<?>) state).refreshSnapshot();
|
||||
}
|
||||
@@ -96,68 +95,68 @@ public class BlockStateListPopulator extends DummyGeneratorAccess {
|
||||
}
|
||||
|
||||
public void updateList() {
|
||||
for (BlockState state : list.values()) {
|
||||
for (BlockState state : this.list.values()) {
|
||||
state.update(true);
|
||||
}
|
||||
}
|
||||
|
||||
public Set<BlockPosition> getBlocks() {
|
||||
return list.keySet();
|
||||
public Set<BlockPos> getBlocks() {
|
||||
return this.list.keySet();
|
||||
}
|
||||
|
||||
public List<CraftBlockState> getList() {
|
||||
return new ArrayList<>(list.values());
|
||||
return new ArrayList<>(this.list.values());
|
||||
}
|
||||
|
||||
public GeneratorAccess getWorld() {
|
||||
return world;
|
||||
public LevelAccessor getWorld() {
|
||||
return this.world;
|
||||
}
|
||||
|
||||
// For tree generation
|
||||
@Override
|
||||
public int getMinY() {
|
||||
return getWorld().getMinY();
|
||||
return this.getWorld().getMinY();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getHeight() {
|
||||
return getWorld().getHeight();
|
||||
return this.getWorld().getHeight();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isStateAtPosition(BlockPosition blockposition, Predicate<IBlockData> predicate) {
|
||||
return predicate.test(getBlockState(blockposition));
|
||||
public boolean isStateAtPosition(BlockPos pos, Predicate<net.minecraft.world.level.block.state.BlockState> state) {
|
||||
return state.test(this.getBlockState(pos));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isFluidAtPosition(BlockPosition bp, Predicate<Fluid> prdct) {
|
||||
return world.isFluidAtPosition(bp, prdct);
|
||||
public boolean isFluidAtPosition(BlockPos pos, Predicate<FluidState> state) {
|
||||
return this.world.isFluidAtPosition(pos, state);
|
||||
}
|
||||
|
||||
@Override
|
||||
public DimensionManager dimensionType() {
|
||||
return world.dimensionType();
|
||||
public DimensionType dimensionType() {
|
||||
return this.world.dimensionType();
|
||||
}
|
||||
|
||||
@Override
|
||||
public IRegistryCustom registryAccess() {
|
||||
return world.registryAccess();
|
||||
public RegistryAccess registryAccess() {
|
||||
return this.world.registryAccess();
|
||||
}
|
||||
|
||||
// Needed when a tree generates in water
|
||||
@Override
|
||||
public WorldData getLevelData() {
|
||||
return world.getLevelData();
|
||||
public LevelData getLevelData() {
|
||||
return this.world.getLevelData();
|
||||
}
|
||||
|
||||
@Override
|
||||
public long nextSubTickCount() {
|
||||
return world.nextSubTickCount();
|
||||
return this.world.nextSubTickCount();
|
||||
}
|
||||
|
||||
// SPIGOT-7966: Needed for some tree generations
|
||||
@Override
|
||||
public RandomSource getRandom() {
|
||||
return world.getRandom();
|
||||
return this.world.getRandom();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,28 +18,28 @@ public class ClassTraverser implements Iterator<Class<?>> {
|
||||
|
||||
@Override
|
||||
public boolean hasNext() {
|
||||
return next != null;
|
||||
return this.next != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<?> next() {
|
||||
Class<?> clazz = next;
|
||||
Class<?> clazz = this.next;
|
||||
|
||||
visit.add(next);
|
||||
this.visit.add(this.next);
|
||||
|
||||
Set<Class<?>> classes = Sets.newHashSet(clazz.getInterfaces());
|
||||
classes.add(clazz.getSuperclass());
|
||||
classes.remove(null); // Super class can be null, remove it if this is the case
|
||||
classes.removeAll(visit);
|
||||
toVisit.addAll(classes);
|
||||
classes.removeAll(this.visit);
|
||||
this.toVisit.addAll(classes);
|
||||
|
||||
if (toVisit.isEmpty()) {
|
||||
next = null;
|
||||
if (this.toVisit.isEmpty()) {
|
||||
this.next = null;
|
||||
return clazz;
|
||||
}
|
||||
|
||||
next = toVisit.iterator().next();
|
||||
toVisit.remove(next);
|
||||
this.next = this.toVisit.iterator().next();
|
||||
this.toVisit.remove(this.next);
|
||||
|
||||
return clazz;
|
||||
}
|
||||
|
||||
@@ -103,29 +103,29 @@ public class Commodore {
|
||||
}
|
||||
|
||||
public Commodore(Predicate<String> compatibilityPresent) {
|
||||
updateReroute(compatibilityPresent);
|
||||
this.updateReroute(compatibilityPresent);
|
||||
}
|
||||
|
||||
public void updateReroute(Predicate<String> compatibilityPresent) {
|
||||
materialReroute = RerouteBuilder
|
||||
this.materialReroute = RerouteBuilder
|
||||
.create(compatibilityPresent)
|
||||
.forClass(MaterialRerouting.class)
|
||||
.build();
|
||||
reroute = RerouteBuilder
|
||||
this.reroute = RerouteBuilder
|
||||
.create(compatibilityPresent)
|
||||
.forClass(FieldRename.class)
|
||||
.forClass(MethodRerouting.class)
|
||||
.forClass(EnumEvil.class)
|
||||
.build();
|
||||
|
||||
reroutes.clear();
|
||||
reroutes.add(materialReroute);
|
||||
reroutes.add(reroute);
|
||||
this.reroutes.clear();
|
||||
this.reroutes.add(this.materialReroute);
|
||||
this.reroutes.add(this.reroute);
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
public List<Reroute> getReroutes() {
|
||||
return reroutes;
|
||||
return this.reroutes;
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
@@ -148,11 +148,11 @@ public class Commodore {
|
||||
|
||||
for (File in : input.listFiles()) {
|
||||
if (in.getName().endsWith(".jar")) {
|
||||
convert(in, new File(output, in.getName()), commodore);
|
||||
Commodore.convert(in, new File(output, in.getName()), commodore);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
convert(input, output, commodore);
|
||||
Commodore.convert(input, output, commodore);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -198,7 +198,7 @@ public class Commodore {
|
||||
ClassReader cr = new ClassReader(b);
|
||||
ClassWriter cw = new ClassWriter(cr, 0);
|
||||
|
||||
List<String> methodEnumSignatures = getMethodSignatures(b);
|
||||
List<String> methodEnumSignatures = Commodore.getMethodSignatures(b);
|
||||
Multimap<String, String> enumLessToEnum = HashMultimap.create();
|
||||
for (String method : methodEnumSignatures) {
|
||||
enumLessToEnum.put(method.replace("Ljava/lang/Enum;", "Ljava/lang/Object;"), method);
|
||||
@@ -206,7 +206,7 @@ public class Commodore {
|
||||
|
||||
ClassVisitor visitor = cw;
|
||||
if (enumCompatibility) {
|
||||
visitor = new LimitedClassRemapper(cw, new SimpleRemapper(ENUM_RENAMES));
|
||||
visitor = new LimitedClassRemapper(cw, new SimpleRemapper(Commodore.ENUM_RENAMES));
|
||||
}
|
||||
|
||||
cr.accept(new ClassRemapper(new ClassVisitor(Opcodes.ASM9, visitor) {
|
||||
@@ -216,9 +216,9 @@ public class Commodore {
|
||||
|
||||
@Override
|
||||
public void visit(int version, int access, String name, String signature, String superName, String[] interfaces) {
|
||||
className = name;
|
||||
isInterface = (access & Opcodes.ACC_INTERFACE) != 0;
|
||||
String craftbukkitClass = CLASS_TO_INTERFACE.get(superName);
|
||||
this.className = name;
|
||||
this.isInterface = (access & Opcodes.ACC_INTERFACE) != 0;
|
||||
String craftbukkitClass = Commodore.CLASS_TO_INTERFACE.get(superName);
|
||||
if (craftbukkitClass != null) {
|
||||
superName = craftbukkitClass;
|
||||
}
|
||||
@@ -227,8 +227,8 @@ public class Commodore {
|
||||
|
||||
@Override
|
||||
public void visitEnd() {
|
||||
for (RerouteMethodData rerouteMethodData : rerouteMethodData) {
|
||||
MethodVisitor methodVisitor = super.visitMethod(Opcodes.ACC_STATIC | Opcodes.ACC_SYNTHETIC | Opcodes.ACC_PUBLIC, buildMethodName(rerouteMethodData), buildMethodDesc(rerouteMethodData), null, null);
|
||||
for (RerouteMethodData rerouteMethodData : this.rerouteMethodData) {
|
||||
MethodVisitor methodVisitor = super.visitMethod(Opcodes.ACC_STATIC | Opcodes.ACC_SYNTHETIC | Opcodes.ACC_PUBLIC, Commodore.buildMethodName(rerouteMethodData), Commodore.buildMethodDesc(rerouteMethodData), null, null);
|
||||
methodVisitor.visitCode();
|
||||
int index = 0;
|
||||
int extraSize = 0;
|
||||
@@ -263,12 +263,12 @@ public class Commodore {
|
||||
|
||||
@Override
|
||||
public AnnotationVisitor visitAnnotation(String descriptor, boolean visible) {
|
||||
return createAnnotationVisitor(pluginVersion, api, super.visitAnnotation(descriptor, visible));
|
||||
return Commodore.createAnnotationVisitor(pluginVersion, this.api, super.visitAnnotation(descriptor, visible));
|
||||
}
|
||||
|
||||
@Override
|
||||
public AnnotationVisitor visitTypeAnnotation(int typeRef, TypePath typePath, String descriptor, boolean visible) {
|
||||
return createAnnotationVisitor(pluginVersion, api, super.visitTypeAnnotation(typeRef, typePath, descriptor, visible));
|
||||
return Commodore.createAnnotationVisitor(pluginVersion, this.api, super.visitTypeAnnotation(typeRef, typePath, descriptor, visible));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -282,7 +282,7 @@ public class Commodore {
|
||||
}
|
||||
}
|
||||
|
||||
return new MethodVisitor(api, super.visitMethod(access, name, desc, signature, exceptions)) {
|
||||
return new MethodVisitor(this.api, super.visitMethod(access, name, desc, signature, exceptions)) {
|
||||
|
||||
@Override
|
||||
public void visitFieldInsn(int opcode, String owner, String name, String desc) {
|
||||
@@ -359,11 +359,11 @@ public class Commodore {
|
||||
}
|
||||
|
||||
private void handleMethod(MethodPrinter visitor, int opcode, String owner, String name, String desc, boolean itf, Type samMethodType, Type instantiatedMethodType) {
|
||||
if (checkReroute(visitor, reroute, opcode, owner, name, desc, samMethodType, instantiatedMethodType)) {
|
||||
if (this.checkReroute(visitor, Commodore.this.reroute, opcode, owner, name, desc, samMethodType, instantiatedMethodType)) {
|
||||
return;
|
||||
}
|
||||
|
||||
String craftbukkitClass = CLASS_TO_INTERFACE.get(owner);
|
||||
String craftbukkitClass = Commodore.CLASS_TO_INTERFACE.get(owner);
|
||||
if (craftbukkitClass != null) {
|
||||
if (opcode == Opcodes.INVOKESPECIAL || opcode == Opcodes.H_INVOKESPECIAL) {
|
||||
owner = craftbukkitClass;
|
||||
@@ -428,7 +428,7 @@ public class Commodore {
|
||||
Type retType = Type.getReturnType(desc);
|
||||
|
||||
// TODO 2024-05-22: This can be moved over to use the reroute api
|
||||
if (EVIL.contains(owner + " " + desc + " " + name)
|
||||
if (Commodore.EVIL.contains(owner + " " + desc + " " + name)
|
||||
|| (owner.startsWith("org/bukkit/block/") && (desc + " " + name).equals("()I getTypeId"))
|
||||
|| (owner.startsWith("org/bukkit/block/") && (desc + " " + name).equals("(I)Z setTypeId"))) {
|
||||
Type[] args = Type.getArgumentTypes(desc);
|
||||
@@ -471,7 +471,7 @@ public class Commodore {
|
||||
}
|
||||
|
||||
// TODO 2024-05-21: Move this up, when material gets fully replaced with ItemType and BlockType
|
||||
if (owner.startsWith("org/bukkit") && checkReroute(visitor, materialReroute, opcode, owner, name, desc, samMethodType, instantiatedMethodType)) {
|
||||
if (owner.startsWith("org/bukkit") && this.checkReroute(visitor, Commodore.this.materialReroute, opcode, owner, name, desc, samMethodType, instantiatedMethodType)) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -479,15 +479,15 @@ public class Commodore {
|
||||
}
|
||||
|
||||
private boolean checkReroute(MethodPrinter visitor, Reroute reroute, int opcode, String owner, String name, String desc, Type samMethodType, Type instantiatedMethodType) {
|
||||
return rerouteMethods(pluginVersion, reroute, opcode == Opcodes.INVOKESTATIC || opcode == Opcodes.H_INVOKESTATIC, owner, name, desc, data -> {
|
||||
visitor.visit(Opcodes.INVOKESTATIC, className, buildMethodName(data), buildMethodDesc(data), isInterface, samMethodType, instantiatedMethodType);
|
||||
return Commodore.rerouteMethods(pluginVersion, reroute, opcode == Opcodes.INVOKESTATIC || opcode == Opcodes.H_INVOKESTATIC, owner, name, desc, data -> {
|
||||
visitor.visit(Opcodes.INVOKESTATIC, className, Commodore.buildMethodName(data), Commodore.buildMethodDesc(data), isInterface, samMethodType, instantiatedMethodType);
|
||||
rerouteMethodData.add(data);
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitMethodInsn(int opcode, String owner, String name, String desc, boolean itf) {
|
||||
handleMethod((newOpcode, newOwner, newName, newDescription, newItf, newSam, newInstantiated) -> {
|
||||
this.handleMethod((newOpcode, newOwner, newName, newDescription, newItf, newSam, newInstantiated) -> {
|
||||
super.visitMethodInsn(newOpcode, newOwner, newName, newDescription, newItf);
|
||||
}, opcode, owner, name, desc, itf, null, null);
|
||||
}
|
||||
@@ -510,7 +510,7 @@ public class Commodore {
|
||||
Handle implMethod = (Handle) bootstrapMethodArguments[1];
|
||||
Type instantiatedMethodType = (Type) bootstrapMethodArguments[2];
|
||||
|
||||
handleMethod((newOpcode, newOwner, newName, newDescription, newItf, newSam, newInstantiated) -> {
|
||||
this.handleMethod((newOpcode, newOwner, newName, newDescription, newItf, newSam, newInstantiated) -> {
|
||||
if (newOpcode == Opcodes.INVOKESTATIC) {
|
||||
newOpcode = Opcodes.H_INVOKESTATIC;
|
||||
}
|
||||
@@ -534,71 +534,71 @@ public class Commodore {
|
||||
|
||||
@Override
|
||||
public AnnotationVisitor visitAnnotation(String descriptor, boolean visible) {
|
||||
return createAnnotationVisitor(pluginVersion, api, super.visitAnnotation(descriptor, visible));
|
||||
return Commodore.createAnnotationVisitor(pluginVersion, this.api, super.visitAnnotation(descriptor, visible));
|
||||
}
|
||||
|
||||
@Override
|
||||
public AnnotationVisitor visitAnnotationDefault() {
|
||||
return createAnnotationVisitor(pluginVersion, api, super.visitAnnotationDefault());
|
||||
return Commodore.createAnnotationVisitor(pluginVersion, this.api, super.visitAnnotationDefault());
|
||||
}
|
||||
|
||||
@Override
|
||||
public AnnotationVisitor visitInsnAnnotation(int typeRef, TypePath typePath, String descriptor, boolean visible) {
|
||||
return createAnnotationVisitor(pluginVersion, api, super.visitInsnAnnotation(typeRef, typePath, descriptor, visible));
|
||||
return Commodore.createAnnotationVisitor(pluginVersion, this.api, super.visitInsnAnnotation(typeRef, typePath, descriptor, visible));
|
||||
}
|
||||
|
||||
@Override
|
||||
public AnnotationVisitor visitLocalVariableAnnotation(int typeRef, TypePath typePath, Label[] start, Label[] end, int[] index, String descriptor, boolean visible) {
|
||||
return createAnnotationVisitor(pluginVersion, api, super.visitLocalVariableAnnotation(typeRef, typePath, start, end, index, descriptor, visible));
|
||||
return Commodore.createAnnotationVisitor(pluginVersion, this.api, super.visitLocalVariableAnnotation(typeRef, typePath, start, end, index, descriptor, visible));
|
||||
}
|
||||
|
||||
@Override
|
||||
public AnnotationVisitor visitParameterAnnotation(int parameter, String descriptor, boolean visible) {
|
||||
return createAnnotationVisitor(pluginVersion, api, super.visitParameterAnnotation(parameter, descriptor, visible));
|
||||
return Commodore.createAnnotationVisitor(pluginVersion, this.api, super.visitParameterAnnotation(parameter, descriptor, visible));
|
||||
}
|
||||
|
||||
@Override
|
||||
public AnnotationVisitor visitTryCatchAnnotation(int typeRef, TypePath typePath, String descriptor, boolean visible) {
|
||||
return createAnnotationVisitor(pluginVersion, api, super.visitTryCatchAnnotation(typeRef, typePath, descriptor, visible));
|
||||
return Commodore.createAnnotationVisitor(pluginVersion, this.api, super.visitTryCatchAnnotation(typeRef, typePath, descriptor, visible));
|
||||
}
|
||||
|
||||
@Override
|
||||
public AnnotationVisitor visitTypeAnnotation(int typeRef, TypePath typePath, String descriptor, boolean visible) {
|
||||
return createAnnotationVisitor(pluginVersion, api, super.visitTypeAnnotation(typeRef, typePath, descriptor, visible));
|
||||
return Commodore.createAnnotationVisitor(pluginVersion, this.api, super.visitTypeAnnotation(typeRef, typePath, descriptor, visible));
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public FieldVisitor visitField(int access, String name, String descriptor, String signature, Object value) {
|
||||
return new FieldVisitor(api, super.visitField(access, name, descriptor, signature, value)) {
|
||||
return new FieldVisitor(this.api, super.visitField(access, name, descriptor, signature, value)) {
|
||||
@Override
|
||||
public AnnotationVisitor visitAnnotation(String descriptor, boolean visible) {
|
||||
return createAnnotationVisitor(pluginVersion, api, super.visitAnnotation(descriptor, visible));
|
||||
return Commodore.createAnnotationVisitor(pluginVersion, this.api, super.visitAnnotation(descriptor, visible));
|
||||
}
|
||||
|
||||
@Override
|
||||
public AnnotationVisitor visitTypeAnnotation(int typeRef, TypePath typePath, String descriptor, boolean visible) {
|
||||
return createAnnotationVisitor(pluginVersion, api, super.visitTypeAnnotation(typeRef, typePath, descriptor, visible));
|
||||
return Commodore.createAnnotationVisitor(pluginVersion, this.api, super.visitTypeAnnotation(typeRef, typePath, descriptor, visible));
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public RecordComponentVisitor visitRecordComponent(String name, String descriptor, String signature) {
|
||||
return new RecordComponentVisitor(api, super.visitRecordComponent(name, descriptor, signature)) {
|
||||
return new RecordComponentVisitor(this.api, super.visitRecordComponent(name, descriptor, signature)) {
|
||||
@Override
|
||||
public AnnotationVisitor visitAnnotation(String descriptor, boolean visible) {
|
||||
return createAnnotationVisitor(pluginVersion, api, super.visitAnnotation(descriptor, visible));
|
||||
return Commodore.createAnnotationVisitor(pluginVersion, this.api, super.visitAnnotation(descriptor, visible));
|
||||
}
|
||||
|
||||
@Override
|
||||
public AnnotationVisitor visitTypeAnnotation(int typeRef, TypePath typePath, String descriptor, boolean visible) {
|
||||
return createAnnotationVisitor(pluginVersion, api, super.visitTypeAnnotation(typeRef, typePath, descriptor, visible));
|
||||
return Commodore.createAnnotationVisitor(pluginVersion, this.api, super.visitTypeAnnotation(typeRef, typePath, descriptor, visible));
|
||||
}
|
||||
};
|
||||
}
|
||||
}, new SimpleRemapper(RENAMES)), 0);
|
||||
}, new SimpleRemapper(Commodore.RENAMES)), 0);
|
||||
|
||||
return cw.toByteArray();
|
||||
}
|
||||
@@ -612,12 +612,12 @@ public class Commodore {
|
||||
|
||||
@Override
|
||||
public AnnotationVisitor visitArray(String name) {
|
||||
return createAnnotationVisitor(apiVersion, api, super.visitArray(name));
|
||||
return Commodore.createAnnotationVisitor(apiVersion, this.api, super.visitArray(name));
|
||||
}
|
||||
|
||||
@Override
|
||||
public AnnotationVisitor visitAnnotation(String name, String descriptor) {
|
||||
return createAnnotationVisitor(apiVersion, api, super.visitAnnotation(name, descriptor));
|
||||
return Commodore.createAnnotationVisitor(apiVersion, this.api, super.visitAnnotation(name, descriptor));
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -641,7 +641,7 @@ public class Commodore {
|
||||
}
|
||||
|
||||
private static String buildMethodName(RerouteMethodData rerouteMethodData) {
|
||||
return BUKKIT_GENERATED_METHOD_PREFIX + rerouteMethodData.targetOwner().replace('/', '_') + "_" + rerouteMethodData.targetName();
|
||||
return Commodore.BUKKIT_GENERATED_METHOD_PREFIX + rerouteMethodData.targetOwner().replace('/', '_') + "_" + rerouteMethodData.targetName();
|
||||
}
|
||||
|
||||
private static String buildMethodDesc(RerouteMethodData rerouteMethodData) {
|
||||
|
||||
@@ -15,10 +15,10 @@ public class CraftBiomeSearchResult implements BiomeSearchResult {
|
||||
}
|
||||
|
||||
public Biome getBiome() {
|
||||
return biome;
|
||||
return this.biome;
|
||||
}
|
||||
|
||||
public Location getLocation() {
|
||||
return location;
|
||||
return this.location;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package org.bukkit.craftbukkit.util;
|
||||
|
||||
import net.minecraft.core.BaseBlockPosition;
|
||||
import net.minecraft.core.BlockPosition;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.Vec3i;
|
||||
import org.bukkit.util.BlockVector;
|
||||
|
||||
public final class CraftBlockVector {
|
||||
@@ -9,11 +9,11 @@ public final class CraftBlockVector {
|
||||
private CraftBlockVector() {
|
||||
}
|
||||
|
||||
public static BlockPosition toBlockPosition(BlockVector blockVector) {
|
||||
return new BlockPosition(blockVector.getBlockX(), blockVector.getBlockY(), blockVector.getBlockZ());
|
||||
public static BlockPos toBlockPosition(BlockVector blockVector) {
|
||||
return new BlockPos(blockVector.getBlockX(), blockVector.getBlockY(), blockVector.getBlockZ());
|
||||
}
|
||||
|
||||
public static BlockVector toBukkit(BaseBlockPosition baseBlockPosition) {
|
||||
public static BlockVector toBukkit(Vec3i baseBlockPosition) {
|
||||
return new BlockVector(baseBlockPosition.getX(), baseBlockPosition.getY(), baseBlockPosition.getZ());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,14 +10,14 @@ import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
import net.minecraft.EnumChatFormat;
|
||||
import net.minecraft.network.chat.ChatClickable;
|
||||
import net.minecraft.network.chat.ChatClickable.EnumClickAction;
|
||||
import net.minecraft.network.chat.ChatHexColor;
|
||||
import net.minecraft.network.chat.ChatModifier;
|
||||
import net.minecraft.network.chat.IChatBaseComponent;
|
||||
import net.minecraft.network.chat.IChatMutableComponent;
|
||||
import net.minecraft.network.chat.contents.LiteralContents;
|
||||
import net.minecraft.ChatFormatting;
|
||||
import net.minecraft.network.chat.ClickEvent;
|
||||
import net.minecraft.network.chat.ClickEvent.Action;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.network.chat.MutableComponent;
|
||||
import net.minecraft.network.chat.Style;
|
||||
import net.minecraft.network.chat.TextColor;
|
||||
import net.minecraft.network.chat.contents.PlainTextContents;
|
||||
import net.minecraft.network.chat.contents.TranslatableContents;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import org.bukkit.ChatColor;
|
||||
@@ -25,21 +25,21 @@ import org.bukkit.ChatColor;
|
||||
public final class CraftChatMessage {
|
||||
|
||||
private static final Pattern LINK_PATTERN = Pattern.compile("((?:(?:https?):\\/\\/)?(?:[-\\w_\\.]{2,}\\.[a-z]{2,4}.*?(?=[\\.\\?!,;:]?(?:[" + String.valueOf(org.bukkit.ChatColor.COLOR_CHAR) + " \\n]|$))))");
|
||||
private static final Map<Character, EnumChatFormat> formatMap;
|
||||
private static final Map<Character, ChatFormatting> formatMap;
|
||||
|
||||
static {
|
||||
Builder<Character, EnumChatFormat> builder = ImmutableMap.builder();
|
||||
for (EnumChatFormat format : EnumChatFormat.values()) {
|
||||
Builder<Character, ChatFormatting> builder = ImmutableMap.builder();
|
||||
for (ChatFormatting format : ChatFormatting.values()) {
|
||||
builder.put(Character.toLowerCase(format.toString().charAt(1)), format);
|
||||
}
|
||||
formatMap = builder.build();
|
||||
}
|
||||
|
||||
public static EnumChatFormat getColor(ChatColor color) {
|
||||
return formatMap.get(color.getChar());
|
||||
public static ChatFormatting getColor(ChatColor color) {
|
||||
return CraftChatMessage.formatMap.get(color.getChar());
|
||||
}
|
||||
|
||||
public static ChatColor getColor(EnumChatFormat format) {
|
||||
public static ChatColor getColor(ChatFormatting format) {
|
||||
return ChatColor.getByChar(format.code);
|
||||
}
|
||||
|
||||
@@ -48,12 +48,12 @@ public final class CraftChatMessage {
|
||||
// Separate pattern with no group 3, new lines are part of previous string
|
||||
private static final Pattern INCREMENTAL_PATTERN_KEEP_NEWLINES = Pattern.compile("(" + String.valueOf(org.bukkit.ChatColor.COLOR_CHAR) + "[0-9a-fk-orx])|((?:(?:https?):\\/\\/)?(?:[-\\w_\\.]{2,}\\.[a-z]{2,4}.*?(?=[\\.\\?!,;:]?(?:[" + String.valueOf(org.bukkit.ChatColor.COLOR_CHAR) + " ]|$))))", Pattern.CASE_INSENSITIVE);
|
||||
// ChatColor.b does not explicitly reset, its more of empty
|
||||
private static final ChatModifier RESET = ChatModifier.EMPTY.withBold(false).withItalic(false).withUnderlined(false).withStrikethrough(false).withObfuscated(false);
|
||||
private static final Style RESET = Style.EMPTY.withBold(false).withItalic(false).withUnderlined(false).withStrikethrough(false).withObfuscated(false);
|
||||
|
||||
private final List<IChatBaseComponent> list = new ArrayList<IChatBaseComponent>();
|
||||
private IChatMutableComponent currentChatComponent = IChatBaseComponent.empty();
|
||||
private ChatModifier modifier = ChatModifier.EMPTY;
|
||||
private final IChatBaseComponent[] output;
|
||||
private final List<Component> list = new ArrayList<Component>();
|
||||
private MutableComponent currentChatComponent = Component.empty();
|
||||
private Style modifier = Style.EMPTY;
|
||||
private final Component[] output;
|
||||
private int currentIndex;
|
||||
private StringBuilder hex;
|
||||
private final String message;
|
||||
@@ -61,12 +61,12 @@ public final class CraftChatMessage {
|
||||
private StringMessage(String message, boolean keepNewlines, boolean plain) {
|
||||
this.message = message;
|
||||
if (message == null) {
|
||||
output = new IChatBaseComponent[]{currentChatComponent};
|
||||
this.output = new Component[]{this.currentChatComponent};
|
||||
return;
|
||||
}
|
||||
list.add(currentChatComponent);
|
||||
this.list.add(this.currentChatComponent);
|
||||
|
||||
Matcher matcher = (keepNewlines ? INCREMENTAL_PATTERN_KEEP_NEWLINES : INCREMENTAL_PATTERN).matcher(message);
|
||||
Matcher matcher = (keepNewlines ? StringMessage.INCREMENTAL_PATTERN_KEEP_NEWLINES : StringMessage.INCREMENTAL_PATTERN).matcher(message);
|
||||
String match = null;
|
||||
boolean needsAdd = false;
|
||||
while (matcher.find()) {
|
||||
@@ -75,182 +75,182 @@ public final class CraftChatMessage {
|
||||
// NOOP
|
||||
}
|
||||
int index = matcher.start(groupId);
|
||||
if (index > currentIndex) {
|
||||
if (index > this.currentIndex) {
|
||||
needsAdd = false;
|
||||
appendNewComponent(index);
|
||||
this.appendNewComponent(index);
|
||||
}
|
||||
switch (groupId) {
|
||||
case 1:
|
||||
char c = match.toLowerCase(Locale.ROOT).charAt(1);
|
||||
EnumChatFormat format = formatMap.get(c);
|
||||
ChatFormatting format = CraftChatMessage.formatMap.get(c);
|
||||
|
||||
if (c == 'x') {
|
||||
hex = new StringBuilder("#");
|
||||
} else if (hex != null) {
|
||||
hex.append(c);
|
||||
this.hex = new StringBuilder("#");
|
||||
} else if (this.hex != null) {
|
||||
this.hex.append(c);
|
||||
|
||||
if (hex.length() == 7) {
|
||||
modifier = RESET.withColor(ChatHexColor.parseColor(hex.toString()).result().get());
|
||||
hex = null;
|
||||
if (this.hex.length() == 7) {
|
||||
this.modifier = StringMessage.RESET.withColor(TextColor.parseColor(this.hex.toString()).result().get());
|
||||
this.hex = null;
|
||||
}
|
||||
} else if (format.isFormat() && format != EnumChatFormat.RESET) {
|
||||
} else if (format.isFormat() && format != ChatFormatting.RESET) {
|
||||
switch (format) {
|
||||
case BOLD:
|
||||
modifier = modifier.withBold(Boolean.TRUE);
|
||||
this.modifier = this.modifier.withBold(Boolean.TRUE);
|
||||
break;
|
||||
case ITALIC:
|
||||
modifier = modifier.withItalic(Boolean.TRUE);
|
||||
this.modifier = this.modifier.withItalic(Boolean.TRUE);
|
||||
break;
|
||||
case STRIKETHROUGH:
|
||||
modifier = modifier.withStrikethrough(Boolean.TRUE);
|
||||
this.modifier = this.modifier.withStrikethrough(Boolean.TRUE);
|
||||
break;
|
||||
case UNDERLINE:
|
||||
modifier = modifier.withUnderlined(Boolean.TRUE);
|
||||
this.modifier = this.modifier.withUnderlined(Boolean.TRUE);
|
||||
break;
|
||||
case OBFUSCATED:
|
||||
modifier = modifier.withObfuscated(Boolean.TRUE);
|
||||
this.modifier = this.modifier.withObfuscated(Boolean.TRUE);
|
||||
break;
|
||||
default:
|
||||
throw new AssertionError("Unexpected message format");
|
||||
}
|
||||
} else { // Color resets formatting
|
||||
modifier = RESET.withColor(format);
|
||||
this.modifier = StringMessage.RESET.withColor(format);
|
||||
}
|
||||
needsAdd = true;
|
||||
break;
|
||||
case 2:
|
||||
if (plain) {
|
||||
appendNewComponent(matcher.end(groupId));
|
||||
this.appendNewComponent(matcher.end(groupId));
|
||||
} else {
|
||||
if (!(match.startsWith("http://") || match.startsWith("https://"))) {
|
||||
match = "http://" + match;
|
||||
}
|
||||
modifier = modifier.withClickEvent(new ChatClickable(EnumClickAction.OPEN_URL, match));
|
||||
appendNewComponent(matcher.end(groupId));
|
||||
modifier = modifier.withClickEvent((ChatClickable) null);
|
||||
this.modifier = this.modifier.withClickEvent(new ClickEvent(Action.OPEN_URL, match));
|
||||
this.appendNewComponent(matcher.end(groupId));
|
||||
this.modifier = this.modifier.withClickEvent((ClickEvent) null);
|
||||
}
|
||||
break;
|
||||
case 3:
|
||||
if (needsAdd) {
|
||||
appendNewComponent(index);
|
||||
this.appendNewComponent(index);
|
||||
}
|
||||
currentChatComponent = null;
|
||||
this.currentChatComponent = null;
|
||||
break;
|
||||
}
|
||||
currentIndex = matcher.end(groupId);
|
||||
this.currentIndex = matcher.end(groupId);
|
||||
}
|
||||
|
||||
if (currentIndex < message.length() || needsAdd) {
|
||||
appendNewComponent(message.length());
|
||||
if (this.currentIndex < message.length() || needsAdd) {
|
||||
this.appendNewComponent(message.length());
|
||||
}
|
||||
|
||||
output = list.toArray(new IChatBaseComponent[list.size()]);
|
||||
this.output = this.list.toArray(new Component[this.list.size()]);
|
||||
}
|
||||
|
||||
private void appendNewComponent(int index) {
|
||||
IChatBaseComponent addition = IChatBaseComponent.literal(message.substring(currentIndex, index)).setStyle(modifier);
|
||||
currentIndex = index;
|
||||
if (currentChatComponent == null) {
|
||||
currentChatComponent = IChatBaseComponent.empty();
|
||||
list.add(currentChatComponent);
|
||||
Component addition = Component.literal(this.message.substring(this.currentIndex, index)).setStyle(this.modifier);
|
||||
this.currentIndex = index;
|
||||
if (this.currentChatComponent == null) {
|
||||
this.currentChatComponent = Component.empty();
|
||||
this.list.add(this.currentChatComponent);
|
||||
}
|
||||
currentChatComponent.append(addition);
|
||||
this.currentChatComponent.append(addition);
|
||||
}
|
||||
|
||||
private IChatBaseComponent[] getOutput() {
|
||||
return output;
|
||||
private Component[] getOutput() {
|
||||
return this.output;
|
||||
}
|
||||
}
|
||||
|
||||
public static Optional<IChatBaseComponent> fromStringOrOptional(String message) {
|
||||
return Optional.ofNullable(fromStringOrNull(message));
|
||||
public static Optional<Component> fromStringOrOptional(String message) {
|
||||
return Optional.ofNullable(CraftChatMessage.fromStringOrNull(message));
|
||||
}
|
||||
|
||||
public static Optional<IChatBaseComponent> fromStringOrOptional(String message, boolean keepNewlines) {
|
||||
return Optional.ofNullable(fromStringOrNull(message, keepNewlines));
|
||||
public static Optional<Component> fromStringOrOptional(String message, boolean keepNewlines) {
|
||||
return Optional.ofNullable(CraftChatMessage.fromStringOrNull(message, keepNewlines));
|
||||
}
|
||||
|
||||
public static IChatBaseComponent fromStringOrNull(String message) {
|
||||
return fromStringOrNull(message, false);
|
||||
public static Component fromStringOrNull(String message) {
|
||||
return CraftChatMessage.fromStringOrNull(message, false);
|
||||
}
|
||||
|
||||
public static IChatBaseComponent fromStringOrNull(String message, boolean keepNewlines) {
|
||||
return (message == null || message.isEmpty()) ? null : fromString(message, keepNewlines)[0];
|
||||
public static Component fromStringOrNull(String message, boolean keepNewlines) {
|
||||
return (message == null || message.isEmpty()) ? null : CraftChatMessage.fromString(message, keepNewlines)[0];
|
||||
}
|
||||
|
||||
public static IChatBaseComponent fromStringOrEmpty(String message) {
|
||||
return fromStringOrEmpty(message, false);
|
||||
public static Component fromStringOrEmpty(String message) {
|
||||
return CraftChatMessage.fromStringOrEmpty(message, false);
|
||||
}
|
||||
|
||||
public static IChatBaseComponent fromStringOrEmpty(String message, boolean keepNewlines) {
|
||||
return fromString(message, keepNewlines)[0];
|
||||
public static Component fromStringOrEmpty(String message, boolean keepNewlines) {
|
||||
return CraftChatMessage.fromString(message, keepNewlines)[0];
|
||||
}
|
||||
|
||||
public static IChatBaseComponent[] fromString(String message) {
|
||||
return fromString(message, false);
|
||||
public static Component[] fromString(String message) {
|
||||
return CraftChatMessage.fromString(message, false);
|
||||
}
|
||||
|
||||
public static IChatBaseComponent[] fromString(String message, boolean keepNewlines) {
|
||||
return fromString(message, keepNewlines, false);
|
||||
public static Component[] fromString(String message, boolean keepNewlines) {
|
||||
return CraftChatMessage.fromString(message, keepNewlines, false);
|
||||
}
|
||||
|
||||
public static IChatBaseComponent[] fromString(String message, boolean keepNewlines, boolean plain) {
|
||||
public static Component[] fromString(String message, boolean keepNewlines, boolean plain) {
|
||||
return new StringMessage(message, keepNewlines, plain).getOutput();
|
||||
}
|
||||
|
||||
public static String toJSON(IChatBaseComponent component) {
|
||||
return IChatBaseComponent.ChatSerializer.toJson(component, MinecraftServer.getDefaultRegistryAccess());
|
||||
public static String toJSON(Component component) {
|
||||
return Component.Serializer.toJson(component, MinecraftServer.getDefaultRegistryAccess());
|
||||
}
|
||||
|
||||
public static String toJSONOrNull(IChatBaseComponent component) {
|
||||
public static String toJSONOrNull(Component component) {
|
||||
if (component == null) return null;
|
||||
return toJSON(component);
|
||||
return CraftChatMessage.toJSON(component);
|
||||
}
|
||||
|
||||
public static IChatBaseComponent fromJSON(String jsonMessage) throws JsonParseException {
|
||||
public static Component fromJSON(String jsonMessage) throws JsonParseException {
|
||||
// Note: This also parses plain Strings to text components.
|
||||
// Note: An empty message (empty, or only consisting of whitespace) results in null rather than a parse exception.
|
||||
return IChatBaseComponent.ChatSerializer.fromJson(jsonMessage, MinecraftServer.getDefaultRegistryAccess());
|
||||
return Component.Serializer.fromJson(jsonMessage, MinecraftServer.getDefaultRegistryAccess());
|
||||
}
|
||||
|
||||
public static IChatBaseComponent fromJSONOrNull(String jsonMessage) {
|
||||
public static Component fromJSONOrNull(String jsonMessage) {
|
||||
if (jsonMessage == null) return null;
|
||||
try {
|
||||
return fromJSON(jsonMessage); // Can return null
|
||||
return CraftChatMessage.fromJSON(jsonMessage); // Can return null
|
||||
} catch (JsonParseException ex) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static IChatBaseComponent fromJSONOrString(String message) {
|
||||
return fromJSONOrString(message, false);
|
||||
public static Component fromJSONOrString(String message) {
|
||||
return CraftChatMessage.fromJSONOrString(message, false);
|
||||
}
|
||||
|
||||
public static IChatBaseComponent fromJSONOrString(String message, boolean keepNewlines) {
|
||||
return fromJSONOrString(message, false, keepNewlines);
|
||||
public static Component fromJSONOrString(String message, boolean keepNewlines) {
|
||||
return CraftChatMessage.fromJSONOrString(message, false, keepNewlines);
|
||||
}
|
||||
|
||||
public static IChatBaseComponent fromJSONOrString(String message, boolean nullable, boolean keepNewlines) {
|
||||
return fromJSONOrString(message, nullable, keepNewlines, Integer.MAX_VALUE, false);
|
||||
public static Component fromJSONOrString(String message, boolean nullable, boolean keepNewlines) {
|
||||
return CraftChatMessage.fromJSONOrString(message, nullable, keepNewlines, Integer.MAX_VALUE, false);
|
||||
}
|
||||
|
||||
public static IChatBaseComponent fromJSONOrString(String message, boolean nullable, boolean keepNewlines, int maxLength, boolean checkJsonContentLength) {
|
||||
public static Component fromJSONOrString(String message, boolean nullable, boolean keepNewlines, int maxLength, boolean checkJsonContentLength) {
|
||||
if (message == null) message = "";
|
||||
if (nullable && message.isEmpty()) return null;
|
||||
IChatBaseComponent component = fromJSONOrNull(message);
|
||||
Component component = CraftChatMessage.fromJSONOrNull(message);
|
||||
if (component != null) {
|
||||
if (checkJsonContentLength) {
|
||||
String content = fromComponent(component);
|
||||
String trimmedContent = trimMessage(content, maxLength);
|
||||
String content = CraftChatMessage.fromComponent(component);
|
||||
String trimmedContent = CraftChatMessage.trimMessage(content, maxLength);
|
||||
if (content != trimmedContent) { // Identity comparison is fine here
|
||||
// Note: The resulting text has all non-plain text features stripped.
|
||||
return fromString(trimmedContent, keepNewlines)[0];
|
||||
return CraftChatMessage.fromString(trimmedContent, keepNewlines)[0];
|
||||
}
|
||||
}
|
||||
return component;
|
||||
} else {
|
||||
message = trimMessage(message, maxLength);
|
||||
return fromString(message, keepNewlines)[0];
|
||||
message = CraftChatMessage.trimMessage(message, maxLength);
|
||||
return CraftChatMessage.fromString(message, keepNewlines)[0];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -262,15 +262,15 @@ public final class CraftChatMessage {
|
||||
}
|
||||
}
|
||||
|
||||
public static String fromComponent(IChatBaseComponent component) {
|
||||
public static String fromComponent(Component component) {
|
||||
if (component == null) return "";
|
||||
StringBuilder out = new StringBuilder();
|
||||
|
||||
boolean hadFormat = false;
|
||||
for (IChatBaseComponent c : component) {
|
||||
ChatModifier modi = c.getStyle();
|
||||
ChatHexColor color = modi.getColor();
|
||||
if (c.getContents() != LiteralContents.EMPTY || color != null) {
|
||||
for (Component c : component) {
|
||||
Style modi = c.getStyle();
|
||||
TextColor color = modi.getColor();
|
||||
if (c.getContents() != PlainTextContents.EMPTY || color != null) {
|
||||
if (color != null) {
|
||||
if (color.format != null) {
|
||||
out.append(color.format);
|
||||
@@ -287,23 +287,23 @@ public final class CraftChatMessage {
|
||||
}
|
||||
}
|
||||
if (modi.isBold()) {
|
||||
out.append(EnumChatFormat.BOLD);
|
||||
out.append(ChatFormatting.BOLD);
|
||||
hadFormat = true;
|
||||
}
|
||||
if (modi.isItalic()) {
|
||||
out.append(EnumChatFormat.ITALIC);
|
||||
out.append(ChatFormatting.ITALIC);
|
||||
hadFormat = true;
|
||||
}
|
||||
if (modi.isUnderlined()) {
|
||||
out.append(EnumChatFormat.UNDERLINE);
|
||||
out.append(ChatFormatting.UNDERLINE);
|
||||
hadFormat = true;
|
||||
}
|
||||
if (modi.isStrikethrough()) {
|
||||
out.append(EnumChatFormat.STRIKETHROUGH);
|
||||
out.append(ChatFormatting.STRIKETHROUGH);
|
||||
hadFormat = true;
|
||||
}
|
||||
if (modi.isObfuscated()) {
|
||||
out.append(EnumChatFormat.OBFUSCATED);
|
||||
out.append(ChatFormatting.OBFUSCATED);
|
||||
hadFormat = true;
|
||||
}
|
||||
c.getContents().visit((x) -> {
|
||||
@@ -314,22 +314,22 @@ public final class CraftChatMessage {
|
||||
return out.toString();
|
||||
}
|
||||
|
||||
public static IChatBaseComponent fixComponent(IChatMutableComponent component) {
|
||||
Matcher matcher = LINK_PATTERN.matcher("");
|
||||
return fixComponent(component, matcher);
|
||||
public static Component fixComponent(MutableComponent component) {
|
||||
Matcher matcher = CraftChatMessage.LINK_PATTERN.matcher("");
|
||||
return CraftChatMessage.fixComponent(component, matcher);
|
||||
}
|
||||
|
||||
private static IChatBaseComponent fixComponent(IChatMutableComponent component, Matcher matcher) {
|
||||
if (component.getContents() instanceof LiteralContents) {
|
||||
LiteralContents text = ((LiteralContents) component.getContents());
|
||||
private static Component fixComponent(MutableComponent component, Matcher matcher) {
|
||||
if (component.getContents() instanceof PlainTextContents) {
|
||||
PlainTextContents text = ((PlainTextContents) component.getContents());
|
||||
String msg = text.text();
|
||||
if (matcher.reset(msg).find()) {
|
||||
matcher.reset();
|
||||
|
||||
ChatModifier modifier = component.getStyle();
|
||||
List<IChatBaseComponent> extras = new ArrayList<IChatBaseComponent>();
|
||||
List<IChatBaseComponent> extrasOld = new ArrayList<IChatBaseComponent>(component.getSiblings());
|
||||
component = IChatBaseComponent.empty();
|
||||
Style modifier = component.getStyle();
|
||||
List<Component> extras = new ArrayList<Component>();
|
||||
List<Component> extrasOld = new ArrayList<Component>(component.getSiblings());
|
||||
component = Component.empty();
|
||||
|
||||
int pos = 0;
|
||||
while (matcher.find()) {
|
||||
@@ -339,34 +339,34 @@ public final class CraftChatMessage {
|
||||
match = "http://" + match;
|
||||
}
|
||||
|
||||
IChatMutableComponent prev = IChatBaseComponent.literal(msg.substring(pos, matcher.start()));
|
||||
MutableComponent prev = Component.literal(msg.substring(pos, matcher.start()));
|
||||
prev.setStyle(modifier);
|
||||
extras.add(prev);
|
||||
|
||||
IChatMutableComponent link = IChatBaseComponent.literal(matcher.group());
|
||||
ChatModifier linkModi = modifier.withClickEvent(new ChatClickable(EnumClickAction.OPEN_URL, match));
|
||||
MutableComponent link = Component.literal(matcher.group());
|
||||
Style linkModi = modifier.withClickEvent(new ClickEvent(Action.OPEN_URL, match));
|
||||
link.setStyle(linkModi);
|
||||
extras.add(link);
|
||||
|
||||
pos = matcher.end();
|
||||
}
|
||||
|
||||
IChatMutableComponent prev = IChatBaseComponent.literal(msg.substring(pos));
|
||||
MutableComponent prev = Component.literal(msg.substring(pos));
|
||||
prev.setStyle(modifier);
|
||||
extras.add(prev);
|
||||
extras.addAll(extrasOld);
|
||||
|
||||
for (IChatBaseComponent c : extras) {
|
||||
for (Component c : extras) {
|
||||
component.append(c);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
List<IChatBaseComponent> extras = component.getSiblings();
|
||||
List<Component> extras = component.getSiblings();
|
||||
for (int i = 0; i < extras.size(); i++) {
|
||||
IChatBaseComponent comp = extras.get(i);
|
||||
Component comp = extras.get(i);
|
||||
if (comp.getStyle() != null && comp.getStyle().getClickEvent() == null) {
|
||||
extras.set(i, fixComponent(comp.copy(), matcher));
|
||||
extras.set(i, CraftChatMessage.fixComponent(comp.copy(), matcher));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -374,13 +374,13 @@ public final class CraftChatMessage {
|
||||
Object[] subs = ((TranslatableContents) component.getContents()).getArgs();
|
||||
for (int i = 0; i < subs.length; i++) {
|
||||
Object comp = subs[i];
|
||||
if (comp instanceof IChatBaseComponent) {
|
||||
IChatBaseComponent c = (IChatBaseComponent) comp;
|
||||
if (comp instanceof Component) {
|
||||
Component c = (Component) comp;
|
||||
if (c.getStyle() != null && c.getStyle().getClickEvent() == null) {
|
||||
subs[i] = fixComponent(c.copy(), matcher);
|
||||
subs[i] = CraftChatMessage.fixComponent(c.copy(), matcher);
|
||||
}
|
||||
} else if (comp instanceof String && matcher.reset((String) comp).find()) {
|
||||
subs[i] = fixComponent(IChatBaseComponent.literal((String) comp), matcher);
|
||||
subs[i] = CraftChatMessage.fixComponent(Component.literal((String) comp), matcher);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,22 +1,22 @@
|
||||
package org.bukkit.craftbukkit.util;
|
||||
|
||||
import net.minecraft.resources.ResourceKey;
|
||||
import net.minecraft.world.level.World;
|
||||
import net.minecraft.world.level.dimension.WorldDimension;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.level.dimension.LevelStem;
|
||||
|
||||
public class CraftDimensionUtil {
|
||||
|
||||
private CraftDimensionUtil() {
|
||||
}
|
||||
|
||||
public static ResourceKey<World> getMainDimensionKey(World world) {
|
||||
ResourceKey<WorldDimension> typeKey = world.getTypeKey();
|
||||
if (typeKey == WorldDimension.OVERWORLD) {
|
||||
return World.OVERWORLD;
|
||||
} else if (typeKey == WorldDimension.NETHER) {
|
||||
return World.NETHER;
|
||||
} else if (typeKey == WorldDimension.END) {
|
||||
return World.END;
|
||||
public static ResourceKey<Level> getMainDimensionKey(Level world) {
|
||||
ResourceKey<LevelStem> typeKey = world.getTypeKey();
|
||||
if (typeKey == LevelStem.OVERWORLD) {
|
||||
return Level.OVERWORLD;
|
||||
} else if (typeKey == LevelStem.NETHER) {
|
||||
return Level.NETHER;
|
||||
} else if (typeKey == LevelStem.END) {
|
||||
return Level.END;
|
||||
}
|
||||
|
||||
return world.dimension();
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package org.bukkit.craftbukkit.util;
|
||||
|
||||
import net.minecraft.core.BlockPosition;
|
||||
import net.minecraft.world.phys.Vec3D;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.world.phys.Vec3;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
|
||||
@@ -10,37 +10,37 @@ public final class CraftLocation {
|
||||
private CraftLocation() {
|
||||
}
|
||||
|
||||
public static Location toBukkit(Vec3D vec3D) {
|
||||
return toBukkit(vec3D, null);
|
||||
public static Location toBukkit(Vec3 vec3D) {
|
||||
return CraftLocation.toBukkit(vec3D, null);
|
||||
}
|
||||
|
||||
public static Location toBukkit(Vec3D vec3D, World world) {
|
||||
return toBukkit(vec3D, world, 0.0F, 0.0F);
|
||||
public static Location toBukkit(Vec3 vec3D, World world) {
|
||||
return CraftLocation.toBukkit(vec3D, world, 0.0F, 0.0F);
|
||||
}
|
||||
|
||||
public static Location toBukkit(Vec3D vec3D, World world, float yaw, float pitch) {
|
||||
public static Location toBukkit(Vec3 vec3D, World world, float yaw, float pitch) {
|
||||
return new Location(world, vec3D.x(), vec3D.y(), vec3D.z(), yaw, pitch);
|
||||
}
|
||||
|
||||
public static Location toBukkit(BlockPosition blockPosition) {
|
||||
return toBukkit(blockPosition, (World) null);
|
||||
public static Location toBukkit(BlockPos blockPosition) {
|
||||
return CraftLocation.toBukkit(blockPosition, (World) null);
|
||||
}
|
||||
public static Location toBukkit(BlockPosition blockPosition, net.minecraft.world.level.World world) {
|
||||
return toBukkit(blockPosition, world.getWorld(), 0.0F, 0.0F);
|
||||
public static Location toBukkit(BlockPos blockPosition, net.minecraft.world.level.Level world) {
|
||||
return CraftLocation.toBukkit(blockPosition, world.getWorld(), 0.0F, 0.0F);
|
||||
}
|
||||
public static Location toBukkit(BlockPosition blockPosition, World world) {
|
||||
return toBukkit(blockPosition, world, 0.0F, 0.0F);
|
||||
public static Location toBukkit(BlockPos blockPosition, World world) {
|
||||
return CraftLocation.toBukkit(blockPosition, world, 0.0F, 0.0F);
|
||||
}
|
||||
|
||||
public static Location toBukkit(BlockPosition blockPosition, World world, float yaw, float pitch) {
|
||||
public static Location toBukkit(BlockPos blockPosition, World world, float yaw, float pitch) {
|
||||
return new Location(world, blockPosition.getX(), blockPosition.getY(), blockPosition.getZ(), yaw, pitch);
|
||||
}
|
||||
|
||||
public static BlockPosition toBlockPosition(Location location) {
|
||||
return new BlockPosition(location.getBlockX(), location.getBlockY(), location.getBlockZ());
|
||||
public static BlockPos toBlockPosition(Location location) {
|
||||
return new BlockPos(location.getBlockX(), location.getBlockY(), location.getBlockZ());
|
||||
}
|
||||
|
||||
public static Vec3D toVec3D(Location location) {
|
||||
return new Vec3D(location.getX(), location.getY(), location.getZ());
|
||||
public static Vec3 toVec3D(Location location) {
|
||||
return new Vec3(location.getX(), location.getY(), location.getZ());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,23 +20,22 @@ import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
import net.minecraft.SharedConstants;
|
||||
import net.minecraft.advancements.AdvancementHolder;
|
||||
import net.minecraft.commands.CommandDispatcher;
|
||||
import net.minecraft.commands.arguments.item.ArgumentParserItemStack;
|
||||
import net.minecraft.commands.Commands;
|
||||
import net.minecraft.commands.arguments.item.ItemParser;
|
||||
import net.minecraft.core.registries.BuiltInRegistries;
|
||||
import net.minecraft.core.registries.Registries;
|
||||
import net.minecraft.nbt.DynamicOpsNBT;
|
||||
import net.minecraft.nbt.NBTBase;
|
||||
import net.minecraft.nbt.NBTTagString;
|
||||
import net.minecraft.resources.MinecraftKey;
|
||||
import net.minecraft.nbt.NbtOps;
|
||||
import net.minecraft.nbt.StringTag;
|
||||
import net.minecraft.nbt.Tag;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.util.datafix.DataConverterRegistry;
|
||||
import net.minecraft.util.datafix.fixes.DataConverterTypes;
|
||||
import net.minecraft.world.entity.EntityTypes;
|
||||
import net.minecraft.util.datafix.DataFixers;
|
||||
import net.minecraft.util.datafix.fixes.References;
|
||||
import net.minecraft.world.item.Item;
|
||||
import net.minecraft.world.item.alchemy.PotionRegistry;
|
||||
import net.minecraft.world.item.alchemy.Potion;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
import net.minecraft.world.level.block.state.IBlockData;
|
||||
import net.minecraft.world.level.storage.SavedFile;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraft.world.level.storage.LevelResource;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.FeatureFlag;
|
||||
import org.bukkit.Keyed;
|
||||
@@ -81,16 +80,16 @@ public final class CraftMagicNumbers implements UnsafeValues {
|
||||
|
||||
private CraftMagicNumbers() {}
|
||||
|
||||
public static IBlockData getBlock(MaterialData material) {
|
||||
return getBlock(material.getItemType(), material.getData());
|
||||
public static BlockState getBlock(MaterialData material) {
|
||||
return CraftMagicNumbers.getBlock(material.getItemType(), material.getData());
|
||||
}
|
||||
|
||||
public static IBlockData getBlock(Material material, byte data) {
|
||||
public static BlockState getBlock(Material material, byte data) {
|
||||
return CraftLegacy.fromLegacyData(CraftLegacy.toLegacy(material), data);
|
||||
}
|
||||
|
||||
public static MaterialData getMaterial(IBlockData data) {
|
||||
return CraftLegacy.toLegacy(getMaterial(data.getBlock())).getNewData(toLegacyData(data));
|
||||
public static MaterialData getMaterial(BlockState data) {
|
||||
return CraftLegacy.toLegacy(CraftMagicNumbers.getMaterial(data.getBlock())).getNewData(CraftMagicNumbers.toLegacyData(data));
|
||||
}
|
||||
|
||||
public static Item getItem(Material material, short data) {
|
||||
@@ -98,11 +97,11 @@ public final class CraftMagicNumbers implements UnsafeValues {
|
||||
return CraftLegacy.fromLegacyData(CraftLegacy.toLegacy(material), data);
|
||||
}
|
||||
|
||||
return getItem(material);
|
||||
return CraftMagicNumbers.getItem(material);
|
||||
}
|
||||
|
||||
public static MaterialData getMaterialData(Item item) {
|
||||
return CraftLegacy.toLegacyData(getMaterial(item));
|
||||
return CraftLegacy.toLegacyData(CraftMagicNumbers.getMaterial(item));
|
||||
}
|
||||
|
||||
// ========================================================================
|
||||
@@ -125,22 +124,22 @@ public final class CraftMagicNumbers implements UnsafeValues {
|
||||
continue;
|
||||
}
|
||||
|
||||
MinecraftKey key = key(material);
|
||||
ResourceLocation key = key(material);
|
||||
BuiltInRegistries.ITEM.getOptional(key).ifPresent((item) -> {
|
||||
MATERIAL_ITEM.put(material, item);
|
||||
CraftMagicNumbers.MATERIAL_ITEM.put(material, item);
|
||||
});
|
||||
BuiltInRegistries.BLOCK.getOptional(key).ifPresent((block) -> {
|
||||
MATERIAL_BLOCK.put(material, block);
|
||||
CraftMagicNumbers.MATERIAL_BLOCK.put(material, block);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
public static Material getMaterial(Block block) {
|
||||
return BLOCK_MATERIAL.get(block);
|
||||
return CraftMagicNumbers.BLOCK_MATERIAL.get(block);
|
||||
}
|
||||
|
||||
public static Material getMaterial(Item item) {
|
||||
return ITEM_MATERIAL.getOrDefault(item, Material.AIR);
|
||||
return CraftMagicNumbers.ITEM_MATERIAL.getOrDefault(item, Material.AIR);
|
||||
}
|
||||
|
||||
public static Item getItem(Material material) {
|
||||
@@ -148,7 +147,7 @@ public final class CraftMagicNumbers implements UnsafeValues {
|
||||
material = CraftLegacy.fromLegacy(material);
|
||||
}
|
||||
|
||||
return MATERIAL_ITEM.get(material);
|
||||
return CraftMagicNumbers.MATERIAL_ITEM.get(material);
|
||||
}
|
||||
|
||||
public static Block getBlock(Material material) {
|
||||
@@ -156,15 +155,15 @@ public final class CraftMagicNumbers implements UnsafeValues {
|
||||
material = CraftLegacy.fromLegacy(material);
|
||||
}
|
||||
|
||||
return MATERIAL_BLOCK.get(material);
|
||||
return CraftMagicNumbers.MATERIAL_BLOCK.get(material);
|
||||
}
|
||||
|
||||
public static MinecraftKey key(Material mat) {
|
||||
public static ResourceLocation key(Material mat) {
|
||||
return CraftNamespacedKey.toMinecraft(mat.getKey());
|
||||
}
|
||||
// ========================================================================
|
||||
|
||||
public static byte toLegacyData(IBlockData data) {
|
||||
public static byte toLegacyData(BlockState data) {
|
||||
return CraftLegacy.toLegacyData(data);
|
||||
}
|
||||
|
||||
@@ -194,7 +193,7 @@ public final class CraftMagicNumbers implements UnsafeValues {
|
||||
|
||||
@Override
|
||||
public BlockData fromLegacy(Material material, byte data) {
|
||||
return CraftBlockData.fromData(getBlock(material, data));
|
||||
return CraftBlockData.fromData(CraftMagicNumbers.getBlock(material, data));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -207,11 +206,11 @@ public final class CraftMagicNumbers implements UnsafeValues {
|
||||
return Material.getMaterial(material);
|
||||
}
|
||||
|
||||
Dynamic<NBTBase> name = new Dynamic<>(DynamicOpsNBT.INSTANCE, NBTTagString.valueOf("minecraft:" + material.toLowerCase(Locale.ROOT)));
|
||||
Dynamic<NBTBase> converted = DataConverterRegistry.getDataFixer().update(DataConverterTypes.ITEM_NAME, name, version, this.getDataVersion());
|
||||
Dynamic<Tag> name = new Dynamic<>(NbtOps.INSTANCE, StringTag.valueOf("minecraft:" + material.toLowerCase(Locale.ROOT)));
|
||||
Dynamic<Tag> converted = DataFixers.getDataFixer().update(References.ITEM_NAME, name, version, this.getDataVersion());
|
||||
|
||||
if (name.equals(converted)) {
|
||||
converted = DataConverterRegistry.getDataFixer().update(DataConverterTypes.BLOCK_NAME, name, version, this.getDataVersion());
|
||||
converted = DataFixers.getDataFixer().update(References.BLOCK_NAME, name, version, this.getDataVersion());
|
||||
}
|
||||
|
||||
return Material.matchMaterial(converted.asString(""));
|
||||
@@ -246,7 +245,7 @@ public final class CraftMagicNumbers implements UnsafeValues {
|
||||
net.minecraft.world.item.ItemStack nmsStack = CraftItemStack.asNMSCopy(stack);
|
||||
|
||||
try {
|
||||
nmsStack.applyComponents(new ArgumentParserItemStack(CommandDispatcher.createValidationContext(MinecraftServer.getDefaultRegistryAccess())).parse(new StringReader(arguments)).components());
|
||||
nmsStack.applyComponents(new ItemParser(Commands.createValidationContext(MinecraftServer.getDefaultRegistryAccess())).parse(new StringReader(arguments)).components());
|
||||
} catch (CommandSyntaxException ex) {
|
||||
Logger.getLogger(CraftMagicNumbers.class.getName()).log(Level.SEVERE, null, ex);
|
||||
}
|
||||
@@ -257,13 +256,13 @@ public final class CraftMagicNumbers implements UnsafeValues {
|
||||
}
|
||||
|
||||
private static File getBukkitDataPackFolder() {
|
||||
return new File(MinecraftServer.getServer().getWorldPath(SavedFile.DATAPACK_DIR).toFile(), "bukkit");
|
||||
return new File(MinecraftServer.getServer().getWorldPath(LevelResource.DATAPACK_DIR).toFile(), "bukkit");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Advancement loadAdvancement(NamespacedKey key, String advancement) {
|
||||
Preconditions.checkArgument(Bukkit.getAdvancement(key) == null, "Advancement %s already exists", key);
|
||||
MinecraftKey minecraftkey = CraftNamespacedKey.toMinecraft(key);
|
||||
ResourceLocation minecraftkey = CraftNamespacedKey.toMinecraft(key);
|
||||
|
||||
JsonElement jsonelement = JsonParser.parseString(advancement);
|
||||
net.minecraft.advancements.Advancement nms = net.minecraft.advancements.Advancement.CODEC.parse(JsonOps.INSTANCE, jsonelement).getOrThrow(JsonParseException::new);
|
||||
@@ -272,7 +271,7 @@ public final class CraftMagicNumbers implements UnsafeValues {
|
||||
Advancement bukkit = Bukkit.getAdvancement(key);
|
||||
|
||||
if (bukkit != null) {
|
||||
File file = new File(getBukkitDataPackFolder(), "data" + File.separator + key.getNamespace() + File.separator + "advancements" + File.separator + key.getKey() + ".json");
|
||||
File file = new File(CraftMagicNumbers.getBukkitDataPackFolder(), "data" + File.separator + key.getNamespace() + File.separator + "advancements" + File.separator + key.getKey() + ".json");
|
||||
file.getParentFile().mkdirs();
|
||||
|
||||
try {
|
||||
@@ -292,7 +291,7 @@ public final class CraftMagicNumbers implements UnsafeValues {
|
||||
|
||||
@Override
|
||||
public boolean removeAdvancement(NamespacedKey key) {
|
||||
File file = new File(getBukkitDataPackFolder(), "data" + File.separator + key.getNamespace() + File.separator + "advancements" + File.separator + key.getKey() + ".json");
|
||||
File file = new File(CraftMagicNumbers.getBukkitDataPackFolder(), "data" + File.separator + key.getNamespace() + File.separator + "advancements" + File.separator + key.getKey() + ".json");
|
||||
return file.delete();
|
||||
}
|
||||
|
||||
@@ -327,7 +326,7 @@ public final class CraftMagicNumbers implements UnsafeValues {
|
||||
@Override
|
||||
public byte[] processClass(PluginDescriptionFile pdf, String path, byte[] clazz) {
|
||||
try {
|
||||
clazz = commodore.convert(clazz, pdf.getName(), ApiVersion.getOrCreateVersion(pdf.getAPIVersion()), ((CraftServer) Bukkit.getServer()).activeCompatibilities);
|
||||
clazz = this.commodore.convert(clazz, pdf.getName(), ApiVersion.getOrCreateVersion(pdf.getAPIVersion()), ((CraftServer) Bukkit.getServer()).activeCompatibilities);
|
||||
} catch (Exception ex) {
|
||||
Bukkit.getLogger().log(Level.SEVERE, "Fatal error trying to convert " + pdf.getFullName() + ":" + path, ex);
|
||||
}
|
||||
@@ -358,7 +357,7 @@ public final class CraftMagicNumbers implements UnsafeValues {
|
||||
@Override
|
||||
public String getTranslationKey(EntityType entityType) {
|
||||
Preconditions.checkArgument(entityType.getName() != null, "Invalid name of EntityType %s for translation key", entityType);
|
||||
return EntityTypes.byString(entityType.getName()).map(EntityTypes::getDescriptionId).orElseThrow();
|
||||
return net.minecraft.world.entity.EntityType.byString(entityType.getName()).map(net.minecraft.world.entity.EntityType::getDescriptionId).orElseThrow();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -380,7 +379,7 @@ public final class CraftMagicNumbers implements UnsafeValues {
|
||||
|
||||
@Override
|
||||
public PotionType.InternalPotionData getInternalPotionData(NamespacedKey namespacedKey) {
|
||||
PotionRegistry potionRegistry = CraftRegistry.getMinecraftRegistry(Registries.POTION)
|
||||
Potion potionRegistry = CraftRegistry.getMinecraftRegistry(Registries.POTION)
|
||||
.getOptional(CraftNamespacedKey.toMinecraft(namespacedKey)).orElseThrow();
|
||||
|
||||
return new CraftPotionType(namespacedKey, potionRegistry);
|
||||
@@ -415,11 +414,11 @@ public final class CraftMagicNumbers implements UnsafeValues {
|
||||
private Biome customBiome;
|
||||
@Override
|
||||
public Biome getCustomBiome() {
|
||||
if (customBiome == null) {
|
||||
customBiome = new CraftBiome(NamespacedKey.minecraft("custom"), null);
|
||||
if (this.customBiome == null) {
|
||||
this.customBiome = new CraftBiome(NamespacedKey.minecraft("custom"), null);
|
||||
}
|
||||
|
||||
return customBiome;
|
||||
return this.customBiome;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -5,14 +5,14 @@ import com.mojang.brigadier.exceptions.CommandSyntaxException;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.regex.Pattern;
|
||||
import net.minecraft.nbt.MojangsonParser;
|
||||
import net.minecraft.nbt.NBTBase;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.nbt.NBTTagDouble;
|
||||
import net.minecraft.nbt.NBTTagInt;
|
||||
import net.minecraft.nbt.NBTTagList;
|
||||
import net.minecraft.nbt.NBTTagString;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.nbt.DoubleTag;
|
||||
import net.minecraft.nbt.IntTag;
|
||||
import net.minecraft.nbt.ListTag;
|
||||
import net.minecraft.nbt.SnbtPrinterTagVisitor;
|
||||
import net.minecraft.nbt.StringTag;
|
||||
import net.minecraft.nbt.Tag;
|
||||
import net.minecraft.nbt.TagParser;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class CraftNBTTagConfigSerializer {
|
||||
@@ -20,66 +20,66 @@ public class CraftNBTTagConfigSerializer {
|
||||
private static final Pattern ARRAY = Pattern.compile("^\\[.*]");
|
||||
private static final Pattern INTEGER = Pattern.compile("[-+]?(?:0|[1-9][0-9]*)?i", Pattern.CASE_INSENSITIVE);
|
||||
private static final Pattern DOUBLE = Pattern.compile("[-+]?(?:[0-9]+[.]?|[0-9]*[.][0-9]+)(?:e[-+]?[0-9]+)?d", Pattern.CASE_INSENSITIVE);
|
||||
private static final MojangsonParser MOJANGSON_PARSER = new MojangsonParser(new StringReader(""));
|
||||
private static final TagParser MOJANGSON_PARSER = new TagParser(new StringReader(""));
|
||||
|
||||
public static String serialize(@NotNull final NBTBase base) {
|
||||
public static String serialize(@NotNull final Tag base) {
|
||||
final SnbtPrinterTagVisitor snbtVisitor = new SnbtPrinterTagVisitor();
|
||||
return snbtVisitor.visit(base);
|
||||
}
|
||||
|
||||
public static NBTBase deserialize(final Object object) {
|
||||
public static Tag deserialize(final Object object) {
|
||||
// The new logic expects the top level object to be a single string, holding the entire nbt tag as SNBT.
|
||||
if (object instanceof final String snbtString) {
|
||||
try {
|
||||
return MojangsonParser.parseTag(snbtString);
|
||||
return TagParser.parseTag(snbtString);
|
||||
} catch (final CommandSyntaxException e) {
|
||||
throw new RuntimeException("Failed to deserialise nbt", e);
|
||||
}
|
||||
} else { // Legacy logic is passed to the internal legacy deserialization that attempts to read the old format that *unsuccessfully* attempted to read/write nbt to a full yml tree.
|
||||
return internalLegacyDeserialization(object);
|
||||
return CraftNBTTagConfigSerializer.internalLegacyDeserialization(object);
|
||||
}
|
||||
}
|
||||
|
||||
private static NBTBase internalLegacyDeserialization(@NotNull final Object object) {
|
||||
private static Tag internalLegacyDeserialization(@NotNull final Object object) {
|
||||
if (object instanceof Map) {
|
||||
NBTTagCompound compound = new NBTTagCompound();
|
||||
CompoundTag compound = new CompoundTag();
|
||||
for (Map.Entry<String, Object> entry : ((Map<String, Object>) object).entrySet()) {
|
||||
compound.put(entry.getKey(), internalLegacyDeserialization(entry.getValue()));
|
||||
compound.put(entry.getKey(), CraftNBTTagConfigSerializer.internalLegacyDeserialization(entry.getValue()));
|
||||
}
|
||||
|
||||
return compound;
|
||||
} else if (object instanceof List) {
|
||||
List<Object> list = (List<Object>) object;
|
||||
if (list.isEmpty()) {
|
||||
return new NBTTagList(); // Default
|
||||
return new ListTag(); // Default
|
||||
}
|
||||
|
||||
NBTTagList tagList = new NBTTagList();
|
||||
ListTag tagList = new ListTag();
|
||||
for (Object tag : list) {
|
||||
tagList.add(internalLegacyDeserialization(tag));
|
||||
tagList.add(CraftNBTTagConfigSerializer.internalLegacyDeserialization(tag));
|
||||
}
|
||||
|
||||
return tagList;
|
||||
} else if (object instanceof String) {
|
||||
String string = (String) object;
|
||||
|
||||
if (ARRAY.matcher(string).matches()) {
|
||||
if (CraftNBTTagConfigSerializer.ARRAY.matcher(string).matches()) {
|
||||
try {
|
||||
return new MojangsonParser(new StringReader(string)).readArrayTag();
|
||||
return new TagParser(new StringReader(string)).readArrayTag();
|
||||
} catch (CommandSyntaxException e) {
|
||||
throw new RuntimeException("Could not deserialize found list ", e);
|
||||
}
|
||||
} else if (INTEGER.matcher(string).matches()) { //Read integers on our own
|
||||
return NBTTagInt.valueOf(Integer.parseInt(string.substring(0, string.length() - 1)));
|
||||
} else if (DOUBLE.matcher(string).matches()) {
|
||||
return NBTTagDouble.valueOf(Double.parseDouble(string.substring(0, string.length() - 1)));
|
||||
} else if (CraftNBTTagConfigSerializer.INTEGER.matcher(string).matches()) { //Read integers on our own
|
||||
return IntTag.valueOf(Integer.parseInt(string.substring(0, string.length() - 1)));
|
||||
} else if (CraftNBTTagConfigSerializer.DOUBLE.matcher(string).matches()) {
|
||||
return DoubleTag.valueOf(Double.parseDouble(string.substring(0, string.length() - 1)));
|
||||
} else {
|
||||
NBTBase nbtBase = MOJANGSON_PARSER.type(string);
|
||||
Tag nbtBase = CraftNBTTagConfigSerializer.MOJANGSON_PARSER.type(string);
|
||||
|
||||
if (nbtBase instanceof NBTTagInt) { // If this returns an integer, it did not use our method from above
|
||||
return NBTTagString.valueOf(nbtBase.getAsString()); // It then is a string that was falsely read as an int
|
||||
} else if (nbtBase instanceof NBTTagDouble) {
|
||||
return NBTTagString.valueOf(String.valueOf(((NBTTagDouble) nbtBase).getAsDouble())); // Doubles add "d" at the end
|
||||
if (nbtBase instanceof IntTag) { // If this returns an integer, it did not use our method from above
|
||||
return StringTag.valueOf(nbtBase.getAsString()); // It then is a string that was falsely read as an int
|
||||
} else if (nbtBase instanceof DoubleTag) {
|
||||
return StringTag.valueOf(String.valueOf(((DoubleTag) nbtBase).getAsDouble())); // Doubles add "d" at the end
|
||||
} else {
|
||||
return nbtBase;
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package org.bukkit.craftbukkit.util;
|
||||
|
||||
import net.minecraft.resources.MinecraftKey;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import org.bukkit.NamespacedKey;
|
||||
|
||||
public final class CraftNamespacedKey {
|
||||
@@ -12,19 +12,19 @@ public final class CraftNamespacedKey {
|
||||
if (string == null || string.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
MinecraftKey minecraft = MinecraftKey.tryParse(string);
|
||||
return (minecraft == null) ? null : fromMinecraft(minecraft);
|
||||
ResourceLocation minecraft = ResourceLocation.tryParse(string);
|
||||
return (minecraft == null) ? null : CraftNamespacedKey.fromMinecraft(minecraft);
|
||||
}
|
||||
|
||||
public static NamespacedKey fromString(String string) {
|
||||
return fromMinecraft(MinecraftKey.parse(string));
|
||||
return CraftNamespacedKey.fromMinecraft(ResourceLocation.parse(string));
|
||||
}
|
||||
|
||||
public static NamespacedKey fromMinecraft(MinecraftKey minecraft) {
|
||||
public static NamespacedKey fromMinecraft(ResourceLocation minecraft) {
|
||||
return new NamespacedKey(minecraft.getNamespace(), minecraft.getPath());
|
||||
}
|
||||
|
||||
public static MinecraftKey toMinecraft(NamespacedKey key) {
|
||||
return MinecraftKey.fromNamespaceAndPath(key.getNamespace(), key.getKey());
|
||||
public static ResourceLocation toMinecraft(NamespacedKey key) {
|
||||
return ResourceLocation.fromNamespaceAndPath(key.getNamespace(), key.getKey());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
package org.bukkit.craftbukkit.util;
|
||||
|
||||
import net.minecraft.core.BlockPosition;
|
||||
import net.minecraft.world.phys.MovingObjectPosition;
|
||||
import net.minecraft.world.phys.MovingObjectPosition.EnumMovingObjectType;
|
||||
import net.minecraft.world.phys.MovingObjectPositionBlock;
|
||||
import net.minecraft.world.phys.MovingObjectPositionEntity;
|
||||
import net.minecraft.world.phys.Vec3D;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.world.phys.BlockHitResult;
|
||||
import net.minecraft.world.phys.EntityHitResult;
|
||||
import net.minecraft.world.phys.HitResult;
|
||||
import net.minecraft.world.phys.HitResult.Type;
|
||||
import net.minecraft.world.phys.Vec3;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.BlockFace;
|
||||
@@ -18,22 +18,22 @@ public final class CraftRayTraceResult {
|
||||
|
||||
private CraftRayTraceResult() {}
|
||||
|
||||
public static RayTraceResult fromNMS(World world, MovingObjectPosition nmsHitResult) {
|
||||
if (nmsHitResult == null || nmsHitResult.getType() == EnumMovingObjectType.MISS) return null;
|
||||
public static RayTraceResult fromNMS(World world, HitResult nmsHitResult) {
|
||||
if (nmsHitResult == null || nmsHitResult.getType() == Type.MISS) return null;
|
||||
|
||||
Vec3D nmsHitPos = nmsHitResult.getLocation();
|
||||
Vec3 nmsHitPos = nmsHitResult.getLocation();
|
||||
Vector hitPosition = new Vector(nmsHitPos.x, nmsHitPos.y, nmsHitPos.z);
|
||||
BlockFace hitBlockFace = null;
|
||||
|
||||
if (nmsHitResult.getType() == EnumMovingObjectType.ENTITY) {
|
||||
Entity hitEntity = ((MovingObjectPositionEntity) nmsHitResult).getEntity().getBukkitEntity();
|
||||
if (nmsHitResult.getType() == Type.ENTITY) {
|
||||
Entity hitEntity = ((EntityHitResult) nmsHitResult).getEntity().getBukkitEntity();
|
||||
return new RayTraceResult(hitPosition, hitEntity, null);
|
||||
}
|
||||
|
||||
Block hitBlock = null;
|
||||
BlockPosition nmsBlockPos = null;
|
||||
if (nmsHitResult.getType() == EnumMovingObjectType.BLOCK) {
|
||||
MovingObjectPositionBlock blockHitResult = (MovingObjectPositionBlock) nmsHitResult;
|
||||
BlockPos nmsBlockPos = null;
|
||||
if (nmsHitResult.getType() == Type.BLOCK) {
|
||||
BlockHitResult blockHitResult = (BlockHitResult) nmsHitResult;
|
||||
hitBlockFace = CraftBlock.notchToBlockFace(blockHitResult.getDirection());
|
||||
nmsBlockPos = blockHitResult.getBlockPos();
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package org.bukkit.craftbukkit.util;
|
||||
|
||||
import net.minecraft.world.entity.EnumCreatureType;
|
||||
import net.minecraft.world.entity.MobCategory;
|
||||
import org.bukkit.entity.SpawnCategory;
|
||||
|
||||
public class CraftSpawnCategory {
|
||||
@@ -43,7 +43,7 @@ public class CraftSpawnCategory {
|
||||
};
|
||||
}
|
||||
|
||||
public static SpawnCategory toBukkit(EnumCreatureType enumCreatureType) {
|
||||
public static SpawnCategory toBukkit(MobCategory enumCreatureType) {
|
||||
return switch (enumCreatureType) {
|
||||
case MONSTER -> SpawnCategory.MONSTER;
|
||||
case CREATURE -> SpawnCategory.ANIMAL;
|
||||
@@ -57,16 +57,16 @@ public class CraftSpawnCategory {
|
||||
};
|
||||
}
|
||||
|
||||
public static EnumCreatureType toNMS(SpawnCategory spawnCategory) {
|
||||
public static MobCategory toNMS(SpawnCategory spawnCategory) {
|
||||
return switch (spawnCategory) {
|
||||
case MONSTER -> EnumCreatureType.MONSTER;
|
||||
case ANIMAL -> EnumCreatureType.CREATURE;
|
||||
case AMBIENT -> EnumCreatureType.AMBIENT;
|
||||
case AXOLOTL -> EnumCreatureType.AXOLOTLS;
|
||||
case WATER_ANIMAL -> EnumCreatureType.WATER_CREATURE;
|
||||
case WATER_AMBIENT -> EnumCreatureType.WATER_AMBIENT;
|
||||
case WATER_UNDERGROUND_CREATURE -> EnumCreatureType.UNDERGROUND_WATER_CREATURE;
|
||||
case MISC -> EnumCreatureType.MISC;
|
||||
case MONSTER -> MobCategory.MONSTER;
|
||||
case ANIMAL -> MobCategory.CREATURE;
|
||||
case AMBIENT -> MobCategory.AMBIENT;
|
||||
case AXOLOTL -> MobCategory.AXOLOTLS;
|
||||
case WATER_ANIMAL -> MobCategory.WATER_CREATURE;
|
||||
case WATER_AMBIENT -> MobCategory.WATER_AMBIENT;
|
||||
case WATER_UNDERGROUND_CREATURE -> MobCategory.UNDERGROUND_WATER_CREATURE;
|
||||
case MISC -> MobCategory.MISC;
|
||||
default -> throw new UnsupportedOperationException("Unknown SpawnCategory " + spawnCategory + " for EnumCreatureType");
|
||||
};
|
||||
}
|
||||
|
||||
@@ -15,10 +15,10 @@ public class CraftStructureSearchResult implements StructureSearchResult {
|
||||
}
|
||||
|
||||
public Structure getStructure() {
|
||||
return structure;
|
||||
return this.structure;
|
||||
}
|
||||
|
||||
public Location getLocation() {
|
||||
return location;
|
||||
return this.location;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,13 +2,13 @@ package org.bukkit.craftbukkit.util;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Objects;
|
||||
import net.minecraft.core.BlockPosition;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
import net.minecraft.world.level.ChunkCoordIntPair;
|
||||
import net.minecraft.world.level.GeneratorAccessSeed;
|
||||
import net.minecraft.world.level.ChunkPos;
|
||||
import net.minecraft.world.level.StructureManager;
|
||||
import net.minecraft.world.level.WorldGenLevel;
|
||||
import net.minecraft.world.level.levelgen.structure.BoundingBox;
|
||||
import net.minecraft.world.level.levelgen.structure.Structure;
|
||||
import net.minecraft.world.level.levelgen.structure.StructureBoundingBox;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.block.BlockState;
|
||||
import org.bukkit.craftbukkit.block.CraftBlockState;
|
||||
@@ -38,23 +38,23 @@ public class CraftStructureTransformer {
|
||||
|
||||
@Override
|
||||
public BlockState getOriginal() {
|
||||
if (originalCopy != null) {
|
||||
return originalCopy;
|
||||
if (this.originalCopy != null) {
|
||||
return this.originalCopy;
|
||||
}
|
||||
return originalCopy = original.copy();
|
||||
return this.originalCopy = this.original.copy();
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockState getWorld() {
|
||||
if (worldCopy != null) {
|
||||
return worldCopy;
|
||||
if (this.worldCopy != null) {
|
||||
return this.worldCopy;
|
||||
}
|
||||
return worldCopy = world.copy();
|
||||
return this.worldCopy = this.world.copy();
|
||||
}
|
||||
|
||||
private void destroyCopies() {
|
||||
originalCopy = null;
|
||||
worldCopy = null;
|
||||
this.originalCopy = null;
|
||||
this.worldCopy = null;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -63,7 +63,7 @@ public class CraftStructureTransformer {
|
||||
private BlockTransformer[] blockTransformers;
|
||||
private EntityTransformer[] entityTransformers;
|
||||
|
||||
public CraftStructureTransformer(Cause cause, GeneratorAccessSeed generatoraccessseed, StructureManager structuremanager, Structure structure, StructureBoundingBox structureboundingbox, ChunkCoordIntPair chunkcoordintpair) {
|
||||
public CraftStructureTransformer(Cause cause, WorldGenLevel generatoraccessseed, StructureManager structuremanager, Structure structure, BoundingBox structureboundingbox, ChunkPos chunkcoordintpair) {
|
||||
AsyncStructureGenerateEvent event = new AsyncStructureGenerateEvent(structuremanager.level.getMinecraftWorld().getWorld(), !Bukkit.isPrimaryThread(), cause, CraftStructure.minecraftToBukkit(structure), new org.bukkit.util.BoundingBox(structureboundingbox.minX(), structureboundingbox.minY(), structureboundingbox.minZ(), structureboundingbox.maxX(), structureboundingbox.maxY(), structureboundingbox.maxZ()), chunkcoordintpair.x, chunkcoordintpair.z);
|
||||
Bukkit.getPluginManager().callEvent(event);
|
||||
this.blockTransformers = event.getBlockTransformers().values().toArray(BlockTransformer[]::new);
|
||||
@@ -71,18 +71,18 @@ public class CraftStructureTransformer {
|
||||
this.limitedRegion = new CraftLimitedRegion(generatoraccessseed, chunkcoordintpair);
|
||||
}
|
||||
|
||||
public CraftStructureTransformer(GeneratorAccessSeed generatoraccessseed, ChunkCoordIntPair chunkcoordintpair, Collection<BlockTransformer> blockTransformers, Collection<EntityTransformer> entityTransformers) {
|
||||
public CraftStructureTransformer(WorldGenLevel generatoraccessseed, ChunkPos chunkcoordintpair, Collection<BlockTransformer> blockTransformers, Collection<EntityTransformer> entityTransformers) {
|
||||
this.blockTransformers = blockTransformers.toArray(BlockTransformer[]::new);
|
||||
this.entityTransformers = entityTransformers.toArray(EntityTransformer[]::new);
|
||||
this.limitedRegion = new CraftLimitedRegion(generatoraccessseed, chunkcoordintpair);
|
||||
}
|
||||
|
||||
public boolean transformEntity(Entity entity) {
|
||||
EntityTransformer[] transformers = entityTransformers;
|
||||
EntityTransformer[] transformers = this.entityTransformers;
|
||||
if (transformers == null || transformers.length == 0) {
|
||||
return true;
|
||||
}
|
||||
CraftLimitedRegion region = limitedRegion;
|
||||
CraftLimitedRegion region = this.limitedRegion;
|
||||
if (region == null) {
|
||||
return true;
|
||||
}
|
||||
@@ -99,20 +99,20 @@ public class CraftStructureTransformer {
|
||||
}
|
||||
|
||||
public boolean canTransformBlocks() {
|
||||
return blockTransformers != null && blockTransformers.length != 0 && limitedRegion != null;
|
||||
return this.blockTransformers != null && this.blockTransformers.length != 0 && this.limitedRegion != null;
|
||||
}
|
||||
|
||||
public CraftBlockState transformCraftState(CraftBlockState originalState) {
|
||||
BlockTransformer[] transformers = blockTransformers;
|
||||
BlockTransformer[] transformers = this.blockTransformers;
|
||||
if (transformers == null || transformers.length == 0) {
|
||||
return originalState;
|
||||
}
|
||||
CraftLimitedRegion region = limitedRegion;
|
||||
CraftLimitedRegion region = this.limitedRegion;
|
||||
if (region == null) {
|
||||
return originalState;
|
||||
}
|
||||
originalState.setWorldHandle(region.getHandle());
|
||||
BlockPosition position = originalState.getPosition();
|
||||
BlockPos position = originalState.getPosition();
|
||||
BlockState blockState = originalState.copy();
|
||||
CraftTransformationState transformationState = new CraftTransformationState(originalState, region.getBlockState(position.getX(), position.getY(), position.getZ()));
|
||||
for (BlockTransformer transformer : transformers) {
|
||||
@@ -123,8 +123,8 @@ public class CraftStructureTransformer {
|
||||
}
|
||||
|
||||
public void discard() {
|
||||
limitedRegion.saveEntities();
|
||||
limitedRegion.breakLink();
|
||||
this.limitedRegion.saveEntities();
|
||||
this.limitedRegion.breakLink();
|
||||
this.limitedRegion = null;
|
||||
this.blockTransformers = null;
|
||||
this.entityTransformers = null;
|
||||
|
||||
@@ -5,11 +5,11 @@ public final class CraftVector {
|
||||
private CraftVector() {
|
||||
}
|
||||
|
||||
public static org.bukkit.util.Vector toBukkit(net.minecraft.world.phys.Vec3D nms) {
|
||||
public static org.bukkit.util.Vector toBukkit(net.minecraft.world.phys.Vec3 nms) {
|
||||
return new org.bukkit.util.Vector(nms.x, nms.y, nms.z);
|
||||
}
|
||||
|
||||
public static net.minecraft.world.phys.Vec3D toNMS(org.bukkit.util.Vector bukkit) {
|
||||
return new net.minecraft.world.phys.Vec3D(bukkit.getX(), bukkit.getY(), bukkit.getZ());
|
||||
public static net.minecraft.world.phys.Vec3 toNMS(org.bukkit.util.Vector bukkit) {
|
||||
return new net.minecraft.world.phys.Vec3(bukkit.getX(), bukkit.getY(), bukkit.getZ());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@ import com.google.common.base.Preconditions;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import net.minecraft.world.phys.AxisAlignedBB;
|
||||
import net.minecraft.world.phys.AABB;
|
||||
import net.minecraft.world.phys.shapes.VoxelShape;
|
||||
import org.bukkit.util.BoundingBox;
|
||||
|
||||
@@ -18,9 +18,9 @@ public final class CraftVoxelShape implements org.bukkit.util.VoxelShape {
|
||||
|
||||
@Override
|
||||
public Collection<BoundingBox> getBoundingBoxes() {
|
||||
List<AxisAlignedBB> boxes = shape.toAabbs();
|
||||
List<AABB> boxes = this.shape.toAabbs();
|
||||
List<BoundingBox> craftBoxes = new ArrayList<>(boxes.size());
|
||||
for (AxisAlignedBB aabb : boxes) {
|
||||
for (AABB aabb : boxes) {
|
||||
craftBoxes.add(new BoundingBox(aabb.minX, aabb.minY, aabb.minZ, aabb.maxX, aabb.maxY, aabb.maxZ));
|
||||
}
|
||||
return craftBoxes;
|
||||
@@ -30,7 +30,7 @@ public final class CraftVoxelShape implements org.bukkit.util.VoxelShape {
|
||||
public boolean overlaps(BoundingBox other) {
|
||||
Preconditions.checkArgument(other != null, "Other cannot be null");
|
||||
|
||||
for (BoundingBox box : getBoundingBoxes()) {
|
||||
for (BoundingBox box : this.getBoundingBoxes()) {
|
||||
if (box.overlaps(other)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -2,48 +2,48 @@ package org.bukkit.craftbukkit.util;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.function.Predicate;
|
||||
import net.minecraft.core.BlockPosition;
|
||||
import net.minecraft.core.EnumDirection;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.Direction;
|
||||
import net.minecraft.core.Holder;
|
||||
import net.minecraft.core.IRegistryCustom;
|
||||
import net.minecraft.core.particles.ParticleParam;
|
||||
import net.minecraft.core.RegistryAccess;
|
||||
import net.minecraft.core.particles.ParticleOptions;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.server.level.WorldServer;
|
||||
import net.minecraft.sounds.SoundCategory;
|
||||
import net.minecraft.sounds.SoundEffect;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import net.minecraft.sounds.SoundEvent;
|
||||
import net.minecraft.sounds.SoundSource;
|
||||
import net.minecraft.util.RandomSource;
|
||||
import net.minecraft.world.DifficultyDamageScaler;
|
||||
import net.minecraft.world.DifficultyInstance;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
import net.minecraft.world.entity.player.EntityHuman;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.flag.FeatureFlagSet;
|
||||
import net.minecraft.world.level.GeneratorAccessSeed;
|
||||
import net.minecraft.world.level.biome.BiomeBase;
|
||||
import net.minecraft.world.level.WorldGenLevel;
|
||||
import net.minecraft.world.level.biome.Biome;
|
||||
import net.minecraft.world.level.biome.BiomeManager;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
import net.minecraft.world.level.block.Blocks;
|
||||
import net.minecraft.world.level.block.entity.TileEntity;
|
||||
import net.minecraft.world.level.block.state.IBlockData;
|
||||
import net.minecraft.world.level.block.entity.BlockEntity;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraft.world.level.border.WorldBorder;
|
||||
import net.minecraft.world.level.chunk.IChunkAccess;
|
||||
import net.minecraft.world.level.chunk.IChunkProvider;
|
||||
import net.minecraft.world.level.chunk.ChunkAccess;
|
||||
import net.minecraft.world.level.chunk.ChunkSource;
|
||||
import net.minecraft.world.level.chunk.status.ChunkStatus;
|
||||
import net.minecraft.world.level.dimension.DimensionManager;
|
||||
import net.minecraft.world.level.dimension.DimensionType;
|
||||
import net.minecraft.world.level.entity.EntityTypeTest;
|
||||
import net.minecraft.world.level.gameevent.GameEvent;
|
||||
import net.minecraft.world.level.levelgen.HeightMap;
|
||||
import net.minecraft.world.level.levelgen.Heightmap;
|
||||
import net.minecraft.world.level.lighting.LevelLightEngine;
|
||||
import net.minecraft.world.level.material.Fluid;
|
||||
import net.minecraft.world.level.material.FluidType;
|
||||
import net.minecraft.world.level.material.FluidTypes;
|
||||
import net.minecraft.world.level.storage.WorldData;
|
||||
import net.minecraft.world.phys.AxisAlignedBB;
|
||||
import net.minecraft.world.phys.Vec3D;
|
||||
import net.minecraft.world.level.material.FluidState;
|
||||
import net.minecraft.world.level.material.Fluids;
|
||||
import net.minecraft.world.level.storage.LevelData;
|
||||
import net.minecraft.world.phys.AABB;
|
||||
import net.minecraft.world.phys.Vec3;
|
||||
import net.minecraft.world.ticks.BlackholeTickAccess;
|
||||
import net.minecraft.world.ticks.LevelTickAccess;
|
||||
import net.minecraft.world.ticks.TickListEmpty;
|
||||
|
||||
public class DummyGeneratorAccess implements GeneratorAccessSeed {
|
||||
public class DummyGeneratorAccess implements WorldGenLevel {
|
||||
|
||||
public static final GeneratorAccessSeed INSTANCE = new DummyGeneratorAccess();
|
||||
public static final WorldGenLevel INSTANCE = new DummyGeneratorAccess();
|
||||
|
||||
protected DummyGeneratorAccess() {
|
||||
}
|
||||
@@ -54,7 +54,7 @@ public class DummyGeneratorAccess implements GeneratorAccessSeed {
|
||||
}
|
||||
|
||||
@Override
|
||||
public WorldServer getLevel() {
|
||||
public ServerLevel getLevel() {
|
||||
throw new UnsupportedOperationException("Not supported yet.");
|
||||
}
|
||||
|
||||
@@ -65,26 +65,26 @@ public class DummyGeneratorAccess implements GeneratorAccessSeed {
|
||||
|
||||
@Override
|
||||
public LevelTickAccess<Block> getBlockTicks() {
|
||||
return TickListEmpty.emptyLevelList();
|
||||
return BlackholeTickAccess.emptyLevelList();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void scheduleTick(BlockPosition blockposition, Block block, int i) {
|
||||
public void scheduleTick(BlockPos pos, Block block, int delay) {
|
||||
// Used by BlockComposter
|
||||
}
|
||||
|
||||
@Override
|
||||
public LevelTickAccess<FluidType> getFluidTicks() {
|
||||
return TickListEmpty.emptyLevelList();
|
||||
public LevelTickAccess<Fluid> getFluidTicks() {
|
||||
return BlackholeTickAccess.emptyLevelList();
|
||||
}
|
||||
|
||||
@Override
|
||||
public WorldData getLevelData() {
|
||||
public LevelData getLevelData() {
|
||||
throw new UnsupportedOperationException("Not supported yet.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public DifficultyDamageScaler getCurrentDifficultyAt(BlockPosition blockposition) {
|
||||
public DifficultyInstance getCurrentDifficultyAt(BlockPos pos) {
|
||||
throw new UnsupportedOperationException("Not supported yet.");
|
||||
}
|
||||
|
||||
@@ -94,7 +94,7 @@ public class DummyGeneratorAccess implements GeneratorAccessSeed {
|
||||
}
|
||||
|
||||
@Override
|
||||
public IChunkProvider getChunkSource() {
|
||||
public ChunkSource getChunkSource() {
|
||||
throw new UnsupportedOperationException("Not supported yet.");
|
||||
}
|
||||
|
||||
@@ -104,47 +104,47 @@ public class DummyGeneratorAccess implements GeneratorAccessSeed {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void playSound(EntityHuman entityhuman, BlockPosition blockposition, SoundEffect soundeffect, SoundCategory soundcategory, float f, float f1) {
|
||||
public void playSound(Player source, BlockPos pos, SoundEvent sound, SoundSource category, float volume, float pitch) {
|
||||
throw new UnsupportedOperationException("Not supported yet.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addParticle(ParticleParam particleparam, double d0, double d1, double d2, double d3, double d4, double d5) {
|
||||
public void addParticle(ParticleOptions parameters, double x, double y, double z, double velocityX, double velocityY, double velocityZ) {
|
||||
throw new UnsupportedOperationException("Not supported yet.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void levelEvent(EntityHuman entityhuman, int i, BlockPosition blockposition, int j) {
|
||||
public void levelEvent(Player player, int eventId, BlockPos pos, int data) {
|
||||
// Used by PowderSnowBlock.removeFluid
|
||||
}
|
||||
|
||||
@Override
|
||||
public void gameEvent(Holder<GameEvent> gameevent, Vec3D vec3d, GameEvent.a gameevent_a) {
|
||||
public void gameEvent(Holder<GameEvent> event, Vec3 emitterPos, GameEvent.Context emitter) {
|
||||
// Used by BlockComposter
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Entity> getEntities(Entity entity, AxisAlignedBB aabb, Predicate<? super Entity> prdct) {
|
||||
public List<Entity> getEntities(Entity except, AABB box, Predicate<? super Entity> predicate) {
|
||||
throw new UnsupportedOperationException("Not supported yet.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T extends Entity> List<T> getEntities(EntityTypeTest<Entity, T> ett, AxisAlignedBB aabb, Predicate<? super T> prdct) {
|
||||
public <T extends Entity> List<T> getEntities(EntityTypeTest<Entity, T> filter, AABB box, Predicate<? super T> predicate) {
|
||||
throw new UnsupportedOperationException("Not supported yet.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<? extends EntityHuman> players() {
|
||||
public List<? extends Player> players() {
|
||||
throw new UnsupportedOperationException("Not supported yet.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public IChunkAccess getChunk(int i, int i1, ChunkStatus cs, boolean bln) {
|
||||
public ChunkAccess getChunk(int chunkX, int chunkZ, ChunkStatus leastStatus, boolean create) {
|
||||
throw new UnsupportedOperationException("Not supported yet.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getHeight(HeightMap.Type type, int i, int i1) {
|
||||
public int getHeight(Heightmap.Types heightmap, int x, int z) {
|
||||
throw new UnsupportedOperationException("Not supported yet.");
|
||||
}
|
||||
|
||||
@@ -159,7 +159,7 @@ public class DummyGeneratorAccess implements GeneratorAccessSeed {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Holder<BiomeBase> getUncachedNoiseBiome(int i, int i1, int i2) {
|
||||
public Holder<Biome> getUncachedNoiseBiome(int biomeX, int biomeY, int biomeZ) {
|
||||
throw new UnsupportedOperationException("Not supported yet.");
|
||||
}
|
||||
|
||||
@@ -174,12 +174,12 @@ public class DummyGeneratorAccess implements GeneratorAccessSeed {
|
||||
}
|
||||
|
||||
@Override
|
||||
public DimensionManager dimensionType() {
|
||||
public DimensionType dimensionType() {
|
||||
throw new UnsupportedOperationException("Not supported yet.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public IRegistryCustom registryAccess() {
|
||||
public RegistryAccess registryAccess() {
|
||||
throw new UnsupportedOperationException("Not supported yet.");
|
||||
}
|
||||
|
||||
@@ -189,7 +189,7 @@ public class DummyGeneratorAccess implements GeneratorAccessSeed {
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getShade(EnumDirection ed, boolean bln) {
|
||||
public float getShade(Direction direction, boolean shaded) {
|
||||
throw new UnsupportedOperationException("Not supported yet.");
|
||||
}
|
||||
|
||||
@@ -199,18 +199,18 @@ public class DummyGeneratorAccess implements GeneratorAccessSeed {
|
||||
}
|
||||
|
||||
@Override
|
||||
public TileEntity getBlockEntity(BlockPosition blockposition) {
|
||||
public BlockEntity getBlockEntity(BlockPos pos) {
|
||||
throw new UnsupportedOperationException("Not supported yet.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public IBlockData getBlockState(BlockPosition blockposition) {
|
||||
public BlockState getBlockState(BlockPos pos) {
|
||||
return Blocks.AIR.defaultBlockState(); // SPIGOT-6515
|
||||
}
|
||||
|
||||
@Override
|
||||
public Fluid getFluidState(BlockPosition blockposition) {
|
||||
return FluidTypes.EMPTY.defaultFluidState(); // SPIGOT-6634
|
||||
public FluidState getFluidState(BlockPos pos) {
|
||||
return Fluids.EMPTY.defaultFluidState(); // SPIGOT-6634
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -219,27 +219,27 @@ public class DummyGeneratorAccess implements GeneratorAccessSeed {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isStateAtPosition(BlockPosition bp, Predicate<IBlockData> prdct) {
|
||||
public boolean isStateAtPosition(BlockPos pos, Predicate<BlockState> state) {
|
||||
throw new UnsupportedOperationException("Not supported yet.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isFluidAtPosition(BlockPosition bp, Predicate<Fluid> prdct) {
|
||||
public boolean isFluidAtPosition(BlockPos pos, Predicate<FluidState> state) {
|
||||
throw new UnsupportedOperationException("Not supported yet.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean setBlock(BlockPosition blockposition, IBlockData iblockdata, int i, int j) {
|
||||
public boolean setBlock(BlockPos pos, BlockState state, int flags, int maxUpdateDepth) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean removeBlock(BlockPosition blockposition, boolean flag) {
|
||||
public boolean removeBlock(BlockPos pos, boolean move) {
|
||||
throw new UnsupportedOperationException("Not supported yet.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean destroyBlock(BlockPosition blockposition, boolean flag, Entity entity, int i) {
|
||||
public boolean destroyBlock(BlockPos pos, boolean drop, Entity breakingEntity, int maxUpdateDepth) {
|
||||
return false; // SPIGOT-6515
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,10 +12,10 @@ public class ForwardLogHandler extends ConsoleHandler {
|
||||
private Map<String, Logger> cachedLoggers = new ConcurrentHashMap<String, Logger>();
|
||||
|
||||
private Logger getLogger(String name) {
|
||||
Logger logger = cachedLoggers.get(name);
|
||||
Logger logger = this.cachedLoggers.get(name);
|
||||
if (logger == null) {
|
||||
logger = LogManager.getLogger(name);
|
||||
cachedLoggers.put(name, logger);
|
||||
this.cachedLoggers.put(name, logger);
|
||||
}
|
||||
|
||||
return logger;
|
||||
@@ -23,10 +23,10 @@ public class ForwardLogHandler extends ConsoleHandler {
|
||||
|
||||
@Override
|
||||
public void publish(LogRecord record) {
|
||||
Logger logger = getLogger(String.valueOf(record.getLoggerName())); // See SPIGOT-1230
|
||||
Logger logger = this.getLogger(String.valueOf(record.getLoggerName())); // See SPIGOT-1230
|
||||
Throwable exception = record.getThrown();
|
||||
Level level = record.getLevel();
|
||||
String message = getFormatter().formatMessage(record);
|
||||
String message = this.getFormatter().formatMessage(record);
|
||||
|
||||
if (level == Level.SEVERE) {
|
||||
logger.error(message, exception);
|
||||
|
||||
@@ -16,7 +16,7 @@ public final class JsonHelper {
|
||||
|
||||
@Nonnull
|
||||
public static JsonObject getOrCreateObject(@Nonnull JsonObject parent, @Nonnull String key) {
|
||||
JsonObject jsonObject = getObjectOrNull(parent, key);
|
||||
JsonObject jsonObject = JsonHelper.getObjectOrNull(parent, key);
|
||||
if (jsonObject == null) {
|
||||
jsonObject = new JsonObject();
|
||||
parent.add(key, jsonObject);
|
||||
@@ -32,7 +32,7 @@ public final class JsonHelper {
|
||||
|
||||
@Nullable
|
||||
public static String getStringOrNull(JsonObject parent, String key) {
|
||||
JsonPrimitive primitive = getPrimitiveOrNull(parent, key);
|
||||
JsonPrimitive primitive = JsonHelper.getPrimitiveOrNull(parent, key);
|
||||
return (primitive != null) ? primitive.getAsString() : null;
|
||||
}
|
||||
|
||||
|
||||
@@ -9,67 +9,67 @@ public abstract class LazyHashSet<E> implements Set<E> {
|
||||
|
||||
@Override
|
||||
public int size() {
|
||||
return getReference().size();
|
||||
return this.getReference().size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEmpty() {
|
||||
return getReference().isEmpty();
|
||||
return this.getReference().isEmpty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean contains(Object o) {
|
||||
return getReference().contains(o);
|
||||
return this.getReference().contains(o);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterator<E> iterator() {
|
||||
return getReference().iterator();
|
||||
return this.getReference().iterator();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object[] toArray() {
|
||||
return getReference().toArray();
|
||||
return this.getReference().toArray();
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> T[] toArray(T[] a) {
|
||||
return getReference().toArray(a);
|
||||
return this.getReference().toArray(a);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean add(E o) {
|
||||
return getReference().add(o);
|
||||
return this.getReference().add(o);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean remove(Object o) {
|
||||
return getReference().remove(o);
|
||||
return this.getReference().remove(o);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean containsAll(Collection<?> c) {
|
||||
return getReference().containsAll(c);
|
||||
return this.getReference().containsAll(c);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean addAll(Collection<? extends E> c) {
|
||||
return getReference().addAll(c);
|
||||
return this.getReference().addAll(c);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean retainAll(Collection<?> c) {
|
||||
return getReference().retainAll(c);
|
||||
return this.getReference().retainAll(c);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean removeAll(Collection<?> c) {
|
||||
return getReference().removeAll(c);
|
||||
return this.getReference().removeAll(c);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clear() {
|
||||
getReference().clear();
|
||||
this.getReference().clear();
|
||||
}
|
||||
|
||||
public Set<E> getReference() {
|
||||
@@ -77,18 +77,18 @@ public abstract class LazyHashSet<E> implements Set<E> {
|
||||
if (reference != null) {
|
||||
return reference;
|
||||
}
|
||||
return this.reference = makeReference();
|
||||
return this.reference = this.makeReference();
|
||||
}
|
||||
|
||||
abstract Set<E> makeReference();
|
||||
|
||||
public boolean isLazy() {
|
||||
return reference == null;
|
||||
return this.reference == null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return 157 * getReference().hashCode();
|
||||
return 157 * this.getReference().hashCode();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -105,6 +105,6 @@ public abstract class LazyHashSet<E> implements Set<E> {
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return getReference().toString();
|
||||
return this.getReference().toString();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@ import com.google.common.base.Preconditions;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.server.level.EntityPlayer;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class LazyPlayerSet extends LazyHashSet<Player> {
|
||||
@@ -17,10 +17,10 @@ public class LazyPlayerSet extends LazyHashSet<Player> {
|
||||
|
||||
@Override
|
||||
HashSet<Player> makeReference() {
|
||||
Preconditions.checkState(reference == null, "Reference already created!");
|
||||
List<EntityPlayer> players = server.getPlayerList().players;
|
||||
Preconditions.checkState(this.reference == null, "Reference already created!");
|
||||
List<ServerPlayer> players = this.server.getPlayerList().players;
|
||||
HashSet<Player> reference = new HashSet<Player>(players.size());
|
||||
for (EntityPlayer player : players) {
|
||||
for (ServerPlayer player : players) {
|
||||
reference.add(player.getBukkitEntity());
|
||||
}
|
||||
return reference;
|
||||
|
||||
@@ -16,12 +16,12 @@ public class LimitedClassRemapper extends ClassRemapper {
|
||||
public void visit(int version, int access, String name, String signature, String superName, String[] interfaces) {
|
||||
this.className = name;
|
||||
// We do not want to remap superName and interfaces for the enums
|
||||
cv.visit(version, access, this.remapper.mapType(name), this.remapper.mapSignature(signature, false), superName, interfaces);
|
||||
this.cv.visit(version, access, this.remapper.mapType(name), this.remapper.mapSignature(signature, false), superName, interfaces);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected MethodVisitor createMethodRemapper(MethodVisitor methodVisitor) {
|
||||
return new LimitedMethodRemapper(api, methodVisitor, remapper);
|
||||
return new LimitedMethodRemapper(this.api, methodVisitor, this.remapper);
|
||||
}
|
||||
|
||||
private class LimitedMethodRemapper extends MethodRemapper {
|
||||
@@ -34,7 +34,7 @@ public class LimitedClassRemapper extends ClassRemapper {
|
||||
public void visitMethodInsn(int opcodeAndSource, String owner, String name, String descriptor, boolean isInterface) {
|
||||
if (owner != null && owner.equals("java/lang/Enum") && name != null && name.equals("<init>")) {
|
||||
// We also do not want to remap the init method for enums
|
||||
mv.visitMethodInsn(opcodeAndSource, owner, name, descriptor, isInterface);
|
||||
this.mv.visitMethodInsn(opcodeAndSource, owner, name, descriptor, isInterface);
|
||||
return;
|
||||
}
|
||||
super.visitMethodInsn(opcodeAndSource, owner, name, descriptor, isInterface);
|
||||
|
||||
@@ -24,42 +24,42 @@ public final class RandomSourceWrapper implements RandomSource {
|
||||
|
||||
@Override
|
||||
public synchronized void setSeed(long seed) {
|
||||
random.setSeed(seed);
|
||||
this.random.setSeed(seed);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int nextInt() {
|
||||
return random.nextInt();
|
||||
return this.random.nextInt();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int nextInt(int bound) {
|
||||
return random.nextInt(bound);
|
||||
return this.random.nextInt(bound);
|
||||
}
|
||||
|
||||
@Override
|
||||
public long nextLong() {
|
||||
return random.nextLong();
|
||||
return this.random.nextLong();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean nextBoolean() {
|
||||
return random.nextBoolean();
|
||||
return this.random.nextBoolean();
|
||||
}
|
||||
|
||||
@Override
|
||||
public float nextFloat() {
|
||||
return random.nextFloat();
|
||||
return this.random.nextFloat();
|
||||
}
|
||||
|
||||
@Override
|
||||
public double nextDouble() {
|
||||
return random.nextDouble();
|
||||
return this.random.nextDouble();
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized double nextGaussian() {
|
||||
return random.nextGaussian();
|
||||
return this.random.nextGaussian();
|
||||
}
|
||||
|
||||
public static final class RandomWrapper extends Random {
|
||||
@@ -72,49 +72,49 @@ public final class RandomSourceWrapper implements RandomSource {
|
||||
|
||||
@Override
|
||||
public void setSeed(long l) {
|
||||
if (random != null) {
|
||||
random.setSeed(l);
|
||||
if (this.random != null) {
|
||||
this.random.setSeed(l);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int nextInt() {
|
||||
return random.nextInt();
|
||||
return this.random.nextInt();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int nextInt(int i) {
|
||||
return random.nextInt(i);
|
||||
return this.random.nextInt(i);
|
||||
}
|
||||
|
||||
@Override
|
||||
public long nextLong() {
|
||||
return random.nextLong();
|
||||
return this.random.nextLong();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean nextBoolean() {
|
||||
return random.nextBoolean();
|
||||
return this.random.nextBoolean();
|
||||
}
|
||||
|
||||
@Override
|
||||
public float nextFloat() {
|
||||
return random.nextFloat();
|
||||
return this.random.nextFloat();
|
||||
}
|
||||
|
||||
@Override
|
||||
public double nextDouble() {
|
||||
return random.nextDouble();
|
||||
return this.random.nextDouble();
|
||||
}
|
||||
|
||||
@Override
|
||||
public double nextGaussian() {
|
||||
return random.nextGaussian();
|
||||
return this.random.nextGaussian();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int nextInt(int var0, int var1) {
|
||||
return random.nextInt(var0, var1);
|
||||
return this.random.nextInt(var0, var1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,10 +12,10 @@ public class ServerShutdownThread extends Thread {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
server.close();
|
||||
this.server.close();
|
||||
} finally {
|
||||
try {
|
||||
server.reader.getTerminal().restore();
|
||||
this.server.reader.getTerminal().restore();
|
||||
} catch (Exception e) {
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,23 +25,23 @@ public class TerminalCompletionHandler implements CompletionHandler {
|
||||
public boolean complete(ConsoleReader reader, List<CharSequence> candidates, int position) throws IOException {
|
||||
// First check normal list, so that we do not unnecessarily create a new HashSet if the not distinct list is already lower
|
||||
if (candidates.size() <= reader.getAutoprintThreshold()) {
|
||||
return delegate.complete(reader, candidates, position);
|
||||
return this.delegate.complete(reader, candidates, position);
|
||||
}
|
||||
|
||||
Set<CharSequence> distinct = new HashSet<>(candidates);
|
||||
if (distinct.size() <= reader.getAutoprintThreshold()) {
|
||||
return delegate.complete(reader, candidates, position);
|
||||
return this.delegate.complete(reader, candidates, position);
|
||||
}
|
||||
|
||||
writerThread.setCompletion(distinct.size());
|
||||
this.writerThread.setCompletion(distinct.size());
|
||||
|
||||
// FIXME: Potential concurrency issue, when terminal writer prints the display message before the delegate does it
|
||||
// resulting in two display message being present, until a new message gets logged or the user presses y / n
|
||||
// But the probability of this happening are probably lower than the effort needed to fix this
|
||||
// And seeing the display message at all should be a higher priority than seeing it two times in rare cases.
|
||||
boolean result = delegate.complete(reader, candidates, position);
|
||||
boolean result = this.delegate.complete(reader, candidates, position);
|
||||
|
||||
writerThread.setCompletion(-1);
|
||||
this.writerThread.setCompletion(-1);
|
||||
// draw line to prevent concurrency issue,
|
||||
// where terminal write would print the display message between delegate#complete finished and the completion set back to -1
|
||||
// Resulting in the display message being present even after pressing y / n
|
||||
|
||||
@@ -40,26 +40,26 @@ public class TerminalConsoleWriterThread extends Thread {
|
||||
|
||||
try {
|
||||
if (Main.useJline) {
|
||||
reader.print(Ansi.ansi().eraseLine(Erase.ALL).toString() + ConsoleReader.RESET_LINE);
|
||||
reader.flush();
|
||||
output.write(message.getBytes());
|
||||
output.flush();
|
||||
this.reader.print(Ansi.ansi().eraseLine(Erase.ALL).toString() + ConsoleReader.RESET_LINE);
|
||||
this.reader.flush();
|
||||
this.output.write(message.getBytes());
|
||||
this.output.flush();
|
||||
|
||||
try {
|
||||
reader.drawLine();
|
||||
this.reader.drawLine();
|
||||
} catch (Throwable ex) {
|
||||
reader.getCursorBuffer().clear();
|
||||
this.reader.getCursorBuffer().clear();
|
||||
}
|
||||
|
||||
if (completion > -1) {
|
||||
if (this.completion > -1) {
|
||||
// SPIGOT-6705: Make sure we print the display line again on tab completion, so that the user does not get stuck on it
|
||||
reader.print(String.format(bundle.getString("DISPLAY_CANDIDATES"), completion));
|
||||
this.reader.print(String.format(this.bundle.getString("DISPLAY_CANDIDATES"), this.completion));
|
||||
}
|
||||
|
||||
reader.flush();
|
||||
this.reader.flush();
|
||||
} else {
|
||||
output.write(message.getBytes());
|
||||
output.flush();
|
||||
this.output.write(message.getBytes());
|
||||
this.output.flush();
|
||||
}
|
||||
} catch (IOException ex) {
|
||||
Logger.getLogger(TerminalConsoleWriterThread.class.getName()).log(Level.SEVERE, null, ex);
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
package org.bukkit.craftbukkit.util;
|
||||
|
||||
import net.minecraft.core.BlockPosition;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
import net.minecraft.world.level.block.entity.TileEntity;
|
||||
import net.minecraft.world.level.block.state.IBlockData;
|
||||
import net.minecraft.world.level.block.entity.BlockEntity;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraft.world.level.levelgen.structure.StructurePiece;
|
||||
import net.minecraft.world.level.material.Fluid;
|
||||
import net.minecraft.world.level.material.FluidState;
|
||||
import org.bukkit.craftbukkit.block.CraftBlockEntityState;
|
||||
import org.bukkit.craftbukkit.block.CraftBlockState;
|
||||
import org.bukkit.craftbukkit.block.CraftBlockStates;
|
||||
@@ -20,77 +20,77 @@ public class TransformerGeneratorAccess extends DelegatedGeneratorAccess {
|
||||
}
|
||||
|
||||
public CraftStructureTransformer getStructureTransformer() {
|
||||
return structureTransformer;
|
||||
return this.structureTransformer;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean addFreshEntity(Entity arg0) {
|
||||
if (structureTransformer != null && !structureTransformer.transformEntity(arg0)) {
|
||||
public boolean addFreshEntity(Entity entity) {
|
||||
if (this.structureTransformer != null && !this.structureTransformer.transformEntity(entity)) {
|
||||
return false;
|
||||
}
|
||||
return super.addFreshEntity(arg0);
|
||||
return super.addFreshEntity(entity);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean addFreshEntity(Entity arg0, SpawnReason arg1) {
|
||||
if (structureTransformer != null && !structureTransformer.transformEntity(arg0)) {
|
||||
if (this.structureTransformer != null && !this.structureTransformer.transformEntity(arg0)) {
|
||||
return false;
|
||||
}
|
||||
return super.addFreshEntity(arg0, arg1);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addFreshEntityWithPassengers(Entity arg0) {
|
||||
if (structureTransformer != null && !structureTransformer.transformEntity(arg0)) {
|
||||
public void addFreshEntityWithPassengers(Entity entity) {
|
||||
if (this.structureTransformer != null && !this.structureTransformer.transformEntity(entity)) {
|
||||
return;
|
||||
}
|
||||
super.addFreshEntityWithPassengers(arg0);
|
||||
super.addFreshEntityWithPassengers(entity);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addFreshEntityWithPassengers(Entity arg0, SpawnReason arg1) {
|
||||
if (structureTransformer != null && !structureTransformer.transformEntity(arg0)) {
|
||||
if (this.structureTransformer != null && !this.structureTransformer.transformEntity(arg0)) {
|
||||
return;
|
||||
}
|
||||
super.addFreshEntityWithPassengers(arg0, arg1);
|
||||
}
|
||||
|
||||
public boolean setCraftBlock(BlockPosition position, CraftBlockState craftBlockState, int i, int j) {
|
||||
if (structureTransformer != null) {
|
||||
craftBlockState = structureTransformer.transformCraftState(craftBlockState);
|
||||
public boolean setCraftBlock(BlockPos position, CraftBlockState craftBlockState, int i, int j) {
|
||||
if (this.structureTransformer != null) {
|
||||
craftBlockState = this.structureTransformer.transformCraftState(craftBlockState);
|
||||
}
|
||||
// This code is based on the method 'net.minecraft.world.level.levelgen.structure.StructurePiece#placeBlock'
|
||||
// It ensures that any kind of block is updated correctly upon placing it
|
||||
IBlockData iblockdata = craftBlockState.getHandle();
|
||||
BlockState iblockdata = craftBlockState.getHandle();
|
||||
boolean result = super.setBlock(position, iblockdata, i, j);
|
||||
Fluid fluid = getFluidState(position);
|
||||
FluidState fluid = this.getFluidState(position);
|
||||
if (!fluid.isEmpty()) {
|
||||
scheduleTick(position, fluid.getType(), 0);
|
||||
this.scheduleTick(position, fluid.getType(), 0);
|
||||
}
|
||||
if (StructurePiece.SHAPE_CHECK_BLOCKS.contains(iblockdata.getBlock())) {
|
||||
getChunk(position).markPosForPostprocessing(position);
|
||||
this.getChunk(position).markPosForPostprocessing(position);
|
||||
}
|
||||
TileEntity tileEntity = getBlockEntity(position);
|
||||
BlockEntity tileEntity = this.getBlockEntity(position);
|
||||
if (tileEntity != null && craftBlockState instanceof CraftBlockEntityState<?> craftEntityState) {
|
||||
tileEntity.loadWithComponents(craftEntityState.getSnapshotNBT(), this.registryAccess());
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public boolean setCraftBlock(BlockPosition position, CraftBlockState craftBlockState, int i) {
|
||||
return setCraftBlock(position, craftBlockState, i, 512);
|
||||
public boolean setCraftBlock(BlockPos position, CraftBlockState craftBlockState, int i) {
|
||||
return this.setCraftBlock(position, craftBlockState, i, 512);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean setBlock(BlockPosition position, IBlockData iblockdata, int i, int j) {
|
||||
if (structureTransformer == null || !structureTransformer.canTransformBlocks()) {
|
||||
return super.setBlock(position, iblockdata, i, j);
|
||||
public boolean setBlock(BlockPos pos, BlockState state, int flags, int maxUpdateDepth) {
|
||||
if (this.structureTransformer == null || !this.structureTransformer.canTransformBlocks()) {
|
||||
return super.setBlock(pos, state, flags, maxUpdateDepth);
|
||||
}
|
||||
return setCraftBlock(position, (CraftBlockState) CraftBlockStates.getBlockState(this, position, iblockdata, null), i, j);
|
||||
return this.setCraftBlock(pos, (CraftBlockState) CraftBlockStates.getBlockState(this, pos, state, null), flags, maxUpdateDepth);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean setBlock(BlockPosition position, IBlockData iblockdata, int i) {
|
||||
return setBlock(position, iblockdata, i, 512);
|
||||
public boolean setBlock(BlockPos pos, BlockState state, int flags) {
|
||||
return this.setBlock(pos, state, flags, 512);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,10 +30,10 @@ public class UnsafeList<E> extends AbstractList<E> implements List<E>, RandomAcc
|
||||
super();
|
||||
if (capacity < 0) capacity = 32;
|
||||
int rounded = Integer.highestOneBit(capacity - 1) << 1;
|
||||
data = new Object[rounded];
|
||||
initialCapacity = rounded;
|
||||
maxPool = maxIterPool;
|
||||
iterPool[0] = new Itr();
|
||||
this.data = new Object[rounded];
|
||||
this.initialCapacity = rounded;
|
||||
this.maxPool = maxIterPool;
|
||||
this.iterPool[0] = new Itr();
|
||||
}
|
||||
|
||||
public UnsafeList(int capacity) {
|
||||
@@ -46,58 +46,58 @@ public class UnsafeList<E> extends AbstractList<E> implements List<E>, RandomAcc
|
||||
|
||||
@Override
|
||||
public E get(int index) {
|
||||
rangeCheck(index);
|
||||
this.rangeCheck(index);
|
||||
|
||||
return (E) data[index];
|
||||
return (E) this.data[index];
|
||||
}
|
||||
|
||||
public E unsafeGet(int index) {
|
||||
return (E) data[index];
|
||||
return (E) this.data[index];
|
||||
}
|
||||
|
||||
@Override
|
||||
public E set(int index, E element) {
|
||||
rangeCheck(index);
|
||||
this.rangeCheck(index);
|
||||
|
||||
E old = (E) data[index];
|
||||
data[index] = element;
|
||||
E old = (E) this.data[index];
|
||||
this.data[index] = element;
|
||||
return old;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean add(E element) {
|
||||
growIfNeeded();
|
||||
data[size++] = element;
|
||||
this.growIfNeeded();
|
||||
this.data[this.size++] = element;
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void add(int index, E element) {
|
||||
growIfNeeded();
|
||||
System.arraycopy(data, index, data, index + 1, size - index);
|
||||
data[index] = element;
|
||||
size++;
|
||||
this.growIfNeeded();
|
||||
System.arraycopy(this.data, index, this.data, index + 1, this.size - index);
|
||||
this.data[index] = element;
|
||||
this.size++;
|
||||
}
|
||||
|
||||
@Override
|
||||
public E remove(int index) {
|
||||
rangeCheck(index);
|
||||
this.rangeCheck(index);
|
||||
|
||||
E old = (E) data[index];
|
||||
int movedCount = size - index - 1;
|
||||
E old = (E) this.data[index];
|
||||
int movedCount = this.size - index - 1;
|
||||
if (movedCount > 0) {
|
||||
System.arraycopy(data, index + 1, data, index, movedCount);
|
||||
System.arraycopy(this.data, index + 1, this.data, index, movedCount);
|
||||
}
|
||||
data[--size] = null;
|
||||
this.data[--this.size] = null;
|
||||
|
||||
return old;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean remove(Object o) {
|
||||
int index = indexOf(o);
|
||||
int index = this.indexOf(o);
|
||||
if (index >= 0) {
|
||||
remove(index);
|
||||
this.remove(index);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -106,8 +106,8 @@ public class UnsafeList<E> extends AbstractList<E> implements List<E>, RandomAcc
|
||||
|
||||
@Override
|
||||
public int indexOf(Object o) {
|
||||
for (int i = 0; i < size; i++) {
|
||||
if (o == data[i] || o.equals(data[i])) {
|
||||
for (int i = 0; i < this.size; i++) {
|
||||
if (o == this.data[i] || o.equals(this.data[i])) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
@@ -117,52 +117,52 @@ public class UnsafeList<E> extends AbstractList<E> implements List<E>, RandomAcc
|
||||
|
||||
@Override
|
||||
public boolean contains(Object o) {
|
||||
return indexOf(o) >= 0;
|
||||
return this.indexOf(o) >= 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clear() {
|
||||
// Create new array to reset memory usage to initial capacity
|
||||
size = 0;
|
||||
this.size = 0;
|
||||
|
||||
// If array has grown too large create new one, otherwise just clear it
|
||||
if (data.length > initialCapacity << 3) {
|
||||
data = new Object[initialCapacity];
|
||||
if (this.data.length > this.initialCapacity << 3) {
|
||||
this.data = new Object[this.initialCapacity];
|
||||
} else {
|
||||
for (int i = 0; i < data.length; i++) {
|
||||
data[i] = null;
|
||||
for (int i = 0; i < this.data.length; i++) {
|
||||
this.data[i] = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// actually rounds up to nearest power of two
|
||||
public void trimToSize() {
|
||||
int old = data.length;
|
||||
int rounded = Integer.highestOneBit(size - 1) << 1;
|
||||
int old = this.data.length;
|
||||
int rounded = Integer.highestOneBit(this.size - 1) << 1;
|
||||
if (rounded < old) {
|
||||
data = Arrays.copyOf(data, rounded);
|
||||
this.data = Arrays.copyOf(this.data, rounded);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int size() {
|
||||
return size;
|
||||
return this.size;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEmpty() {
|
||||
return size == 0;
|
||||
return this.size == 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object clone() throws CloneNotSupportedException {
|
||||
UnsafeList<E> copy = (UnsafeList<E>) super.clone();
|
||||
copy.data = Arrays.copyOf(data, size);
|
||||
copy.size = size;
|
||||
copy.initialCapacity = initialCapacity;
|
||||
copy.data = Arrays.copyOf(this.data, this.size);
|
||||
copy.size = this.size;
|
||||
copy.initialCapacity = this.initialCapacity;
|
||||
copy.iterPool = new Iterator[1];
|
||||
copy.iterPool[0] = new Itr();
|
||||
copy.maxPool = maxPool;
|
||||
copy.maxPool = this.maxPool;
|
||||
copy.poolCounter = 0;
|
||||
return copy;
|
||||
}
|
||||
@@ -170,7 +170,7 @@ public class UnsafeList<E> extends AbstractList<E> implements List<E>, RandomAcc
|
||||
@Override
|
||||
public Iterator<E> iterator() {
|
||||
// Try to find an iterator that isn't in use
|
||||
for (Iterator iter : iterPool) {
|
||||
for (Iterator iter : this.iterPool) {
|
||||
if (!((Itr) iter).valid) {
|
||||
Itr iterator = (Itr) iter;
|
||||
iterator.reset();
|
||||
@@ -179,112 +179,112 @@ public class UnsafeList<E> extends AbstractList<E> implements List<E>, RandomAcc
|
||||
}
|
||||
|
||||
// Couldn't find one, see if we can grow our pool size
|
||||
if (iterPool.length < maxPool) {
|
||||
Iterator[] newPool = new Iterator[iterPool.length + 1];
|
||||
System.arraycopy(iterPool, 0, newPool, 0, iterPool.length);
|
||||
iterPool = newPool;
|
||||
if (this.iterPool.length < this.maxPool) {
|
||||
Iterator[] newPool = new Iterator[this.iterPool.length + 1];
|
||||
System.arraycopy(this.iterPool, 0, newPool, 0, this.iterPool.length);
|
||||
this.iterPool = newPool;
|
||||
|
||||
iterPool[iterPool.length - 1] = new Itr();
|
||||
return iterPool[iterPool.length - 1];
|
||||
this.iterPool[this.iterPool.length - 1] = new Itr();
|
||||
return this.iterPool[this.iterPool.length - 1];
|
||||
}
|
||||
|
||||
// Still couldn't find a free one, round robin replace one with a new iterator
|
||||
// This is done in the hope that the new one finishes so can be reused
|
||||
poolCounter = ++poolCounter % iterPool.length;
|
||||
iterPool[poolCounter] = new Itr();
|
||||
return iterPool[poolCounter];
|
||||
this.poolCounter = ++this.poolCounter % this.iterPool.length;
|
||||
this.iterPool[this.poolCounter] = new Itr();
|
||||
return this.iterPool[this.poolCounter];
|
||||
}
|
||||
|
||||
private void rangeCheck(int index) {
|
||||
if (index >= size || index < 0) {
|
||||
throw new IndexOutOfBoundsException("Index: " + index + ", Size: " + size);
|
||||
if (index >= this.size || index < 0) {
|
||||
throw new IndexOutOfBoundsException("Index: " + index + ", Size: " + this.size);
|
||||
}
|
||||
}
|
||||
|
||||
private void growIfNeeded() {
|
||||
if (size == data.length) {
|
||||
Object[] newData = new Object[data.length << 1];
|
||||
System.arraycopy(data, 0, newData, 0, size);
|
||||
data = newData;
|
||||
if (this.size == this.data.length) {
|
||||
Object[] newData = new Object[this.data.length << 1];
|
||||
System.arraycopy(this.data, 0, newData, 0, this.size);
|
||||
this.data = newData;
|
||||
}
|
||||
}
|
||||
|
||||
private void writeObject(ObjectOutputStream os) throws IOException {
|
||||
os.defaultWriteObject();
|
||||
|
||||
os.writeInt(size);
|
||||
os.writeInt(initialCapacity);
|
||||
for (int i = 0; i < size; i++) {
|
||||
os.writeObject(data[i]);
|
||||
os.writeInt(this.size);
|
||||
os.writeInt(this.initialCapacity);
|
||||
for (int i = 0; i < this.size; i++) {
|
||||
os.writeObject(this.data[i]);
|
||||
}
|
||||
os.writeInt(maxPool);
|
||||
os.writeInt(this.maxPool);
|
||||
}
|
||||
|
||||
private void readObject(ObjectInputStream is) throws IOException, ClassNotFoundException {
|
||||
is.defaultReadObject();
|
||||
|
||||
size = is.readInt();
|
||||
initialCapacity = is.readInt();
|
||||
data = new Object[Integer.highestOneBit(size - 1) << 1];
|
||||
for (int i = 0; i < size; i++) {
|
||||
data[i] = is.readObject();
|
||||
this.size = is.readInt();
|
||||
this.initialCapacity = is.readInt();
|
||||
this.data = new Object[Integer.highestOneBit(this.size - 1) << 1];
|
||||
for (int i = 0; i < this.size; i++) {
|
||||
this.data[i] = is.readObject();
|
||||
}
|
||||
maxPool = is.readInt();
|
||||
iterPool = new Iterator[1];
|
||||
iterPool[0] = new Itr();
|
||||
this.maxPool = is.readInt();
|
||||
this.iterPool = new Iterator[1];
|
||||
this.iterPool[0] = new Itr();
|
||||
}
|
||||
|
||||
public class Itr implements Iterator<E> {
|
||||
int index;
|
||||
int lastRet = -1;
|
||||
int expectedModCount = modCount;
|
||||
int expectedModCount = UnsafeList.this.modCount;
|
||||
public boolean valid = true;
|
||||
|
||||
public void reset() {
|
||||
index = 0;
|
||||
lastRet = -1;
|
||||
expectedModCount = modCount;
|
||||
valid = true;
|
||||
this.index = 0;
|
||||
this.lastRet = -1;
|
||||
this.expectedModCount = UnsafeList.this.modCount;
|
||||
this.valid = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasNext() {
|
||||
valid = index != size;
|
||||
return valid;
|
||||
this.valid = this.index != UnsafeList.this.size;
|
||||
return this.valid;
|
||||
}
|
||||
|
||||
@Override
|
||||
public E next() {
|
||||
if (modCount != expectedModCount) {
|
||||
if (UnsafeList.this.modCount != this.expectedModCount) {
|
||||
throw new ConcurrentModificationException();
|
||||
}
|
||||
|
||||
int i = index;
|
||||
if (i >= size) {
|
||||
int i = this.index;
|
||||
if (i >= UnsafeList.this.size) {
|
||||
throw new NoSuchElementException();
|
||||
}
|
||||
|
||||
if (i >= data.length) {
|
||||
if (i >= UnsafeList.this.data.length) {
|
||||
throw new ConcurrentModificationException();
|
||||
}
|
||||
|
||||
index = i + 1;
|
||||
return (E) data[lastRet = i];
|
||||
this.index = i + 1;
|
||||
return (E) UnsafeList.this.data[this.lastRet = i];
|
||||
}
|
||||
|
||||
@Override
|
||||
public void remove() {
|
||||
Preconditions.checkState(lastRet >= 0, "");
|
||||
Preconditions.checkState(this.lastRet >= 0, "");
|
||||
|
||||
if (modCount != expectedModCount) {
|
||||
if (UnsafeList.this.modCount != this.expectedModCount) {
|
||||
throw new ConcurrentModificationException();
|
||||
}
|
||||
|
||||
try {
|
||||
UnsafeList.this.remove(lastRet);
|
||||
index = lastRet;
|
||||
lastRet = -1;
|
||||
expectedModCount = modCount;
|
||||
UnsafeList.this.remove(this.lastRet);
|
||||
this.index = this.lastRet;
|
||||
this.lastRet = -1;
|
||||
this.expectedModCount = UnsafeList.this.modCount;
|
||||
} catch (IndexOutOfBoundsException ex) {
|
||||
throw new ConcurrentModificationException();
|
||||
}
|
||||
|
||||
@@ -16,16 +16,16 @@ public abstract class Waitable<T> implements Runnable {
|
||||
@Override
|
||||
public final void run() {
|
||||
synchronized (this) {
|
||||
Preconditions.checkState(status == Status.WAITING, "Invalid state %s", status);
|
||||
status = Status.RUNNING;
|
||||
Preconditions.checkState(this.status == Status.WAITING, "Invalid state %s", this.status);
|
||||
this.status = Status.RUNNING;
|
||||
}
|
||||
try {
|
||||
value = evaluate();
|
||||
this.value = this.evaluate();
|
||||
} catch (Throwable t) {
|
||||
this.t = t;
|
||||
} finally {
|
||||
synchronized (this) {
|
||||
status = Status.FINISHED;
|
||||
this.status = Status.FINISHED;
|
||||
this.notifyAll();
|
||||
}
|
||||
}
|
||||
@@ -34,12 +34,12 @@ public abstract class Waitable<T> implements Runnable {
|
||||
protected abstract T evaluate();
|
||||
|
||||
public synchronized T get() throws InterruptedException, ExecutionException {
|
||||
while (status != Status.FINISHED) {
|
||||
while (this.status != Status.FINISHED) {
|
||||
this.wait();
|
||||
}
|
||||
if (t != null) {
|
||||
throw new ExecutionException(t);
|
||||
if (this.t != null) {
|
||||
throw new ExecutionException(this.t);
|
||||
}
|
||||
return value;
|
||||
return this.value;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,13 +12,13 @@ public final class WeakCollection<T> implements Collection<T> {
|
||||
private final Collection<WeakReference<T>> collection;
|
||||
|
||||
public WeakCollection() {
|
||||
collection = new ArrayList<>();
|
||||
this.collection = new ArrayList<>();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean add(T value) {
|
||||
Preconditions.checkArgument(value != null, "Cannot add null value");
|
||||
return collection.add(new WeakReference<T>(value));
|
||||
return this.collection.add(new WeakReference<T>(value));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -34,7 +34,7 @@ public final class WeakCollection<T> implements Collection<T> {
|
||||
|
||||
@Override
|
||||
public void clear() {
|
||||
collection.clear();
|
||||
this.collection.clear();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -52,24 +52,24 @@ public final class WeakCollection<T> implements Collection<T> {
|
||||
|
||||
@Override
|
||||
public boolean containsAll(Collection<?> collection) {
|
||||
return toCollection().containsAll(collection);
|
||||
return this.toCollection().containsAll(collection);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEmpty() {
|
||||
return !iterator().hasNext();
|
||||
return !this.iterator().hasNext();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterator<T> iterator() {
|
||||
return new Iterator<T>() {
|
||||
Iterator<WeakReference<T>> it = collection.iterator();
|
||||
Object value = NO_VALUE;
|
||||
Iterator<WeakReference<T>> it = WeakCollection.this.collection.iterator();
|
||||
Object value = WeakCollection.NO_VALUE;
|
||||
|
||||
@Override
|
||||
public boolean hasNext() {
|
||||
Object value = this.value;
|
||||
if (value != null && value != NO_VALUE) {
|
||||
if (value != null && value != WeakCollection.NO_VALUE) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -91,22 +91,22 @@ public final class WeakCollection<T> implements Collection<T> {
|
||||
|
||||
@Override
|
||||
public T next() throws NoSuchElementException {
|
||||
if (!hasNext()) {
|
||||
if (!this.hasNext()) {
|
||||
throw new NoSuchElementException("No more elements");
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
T value = (T) this.value;
|
||||
this.value = NO_VALUE;
|
||||
this.value = WeakCollection.NO_VALUE;
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void remove() throws IllegalStateException {
|
||||
Preconditions.checkState(value == NO_VALUE, "No last element");
|
||||
Preconditions.checkState(this.value == WeakCollection.NO_VALUE, "No last element");
|
||||
|
||||
value = null;
|
||||
it.remove();
|
||||
this.value = null;
|
||||
this.it.remove();
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -169,7 +169,7 @@ public final class WeakCollection<T> implements Collection<T> {
|
||||
|
||||
@Override
|
||||
public <T> T[] toArray(T[] array) {
|
||||
return toCollection().toArray(array);
|
||||
return this.toCollection().toArray(array);
|
||||
}
|
||||
|
||||
private Collection<T> toCollection() {
|
||||
|
||||
@@ -25,7 +25,7 @@ public final class WorldUUID {
|
||||
dis = new DataInputStream(new FileInputStream(file1));
|
||||
return new UUID(dis.readLong(), dis.readLong());
|
||||
} catch (IOException ex) {
|
||||
LOGGER.warn("Failed to read " + file1 + ", generating new random UUID", ex);
|
||||
WorldUUID.LOGGER.warn("Failed to read " + file1 + ", generating new random UUID", ex);
|
||||
} finally {
|
||||
if (dis != null) {
|
||||
try {
|
||||
@@ -43,7 +43,7 @@ public final class WorldUUID {
|
||||
dos.writeLong(uuid.getMostSignificantBits());
|
||||
dos.writeLong(uuid.getLeastSignificantBits());
|
||||
} catch (IOException ex) {
|
||||
LOGGER.warn("Failed to write " + file1, ex);
|
||||
WorldUUID.LOGGER.warn("Failed to write " + file1, ex);
|
||||
} finally {
|
||||
if (dos != null) {
|
||||
try {
|
||||
|
||||
@@ -6,31 +6,31 @@ import org.bukkit.util.permissions.DefaultPermissions;
|
||||
|
||||
public final class CommandPermissions {
|
||||
private static final String ROOT = "minecraft.command";
|
||||
private static final String PREFIX = ROOT + ".";
|
||||
private static final String PREFIX = CommandPermissions.ROOT + ".";
|
||||
|
||||
private CommandPermissions() {}
|
||||
|
||||
public static Permission registerPermissions(Permission parent) {
|
||||
Permission commands = DefaultPermissions.registerPermission(ROOT, "Gives the user the ability to use all vanilla minecraft commands", parent);
|
||||
Permission commands = DefaultPermissions.registerPermission(CommandPermissions.ROOT, "Gives the user the ability to use all vanilla minecraft commands", parent);
|
||||
|
||||
DefaultPermissions.registerPermission(PREFIX + "kill", "Allows the user to commit suicide", PermissionDefault.OP, commands);
|
||||
DefaultPermissions.registerPermission(PREFIX + "me", "Allows the user to perform a chat action", PermissionDefault.TRUE, commands);
|
||||
DefaultPermissions.registerPermission(PREFIX + "msg", "Allows the user to privately message another player", PermissionDefault.TRUE, commands);
|
||||
DefaultPermissions.registerPermission(PREFIX + "help", "Allows the user to access Vanilla command help", PermissionDefault.TRUE, commands);
|
||||
DefaultPermissions.registerPermission(PREFIX + "say", "Allows the user to talk as the console", PermissionDefault.OP, commands);
|
||||
DefaultPermissions.registerPermission(PREFIX + "give", "Allows the user to give items to players", PermissionDefault.OP, commands);
|
||||
DefaultPermissions.registerPermission(PREFIX + "teleport", "Allows the user to teleport players", PermissionDefault.OP, commands);
|
||||
DefaultPermissions.registerPermission(PREFIX + "kick", "Allows the user to kick players", PermissionDefault.OP, commands);
|
||||
DefaultPermissions.registerPermission(PREFIX + "stop", "Allows the user to stop the server", PermissionDefault.OP, commands);
|
||||
DefaultPermissions.registerPermission(PREFIX + "list", "Allows the user to list all online players", PermissionDefault.OP, commands);
|
||||
DefaultPermissions.registerPermission(PREFIX + "gamemode", "Allows the user to change the gamemode of another player", PermissionDefault.OP, commands);
|
||||
DefaultPermissions.registerPermission(PREFIX + "xp", "Allows the user to give themselves or others arbitrary values of experience", PermissionDefault.OP, commands);
|
||||
DefaultPermissions.registerPermission(PREFIX + "toggledownfall", "Allows the user to toggle rain on/off for a given world", PermissionDefault.OP, commands);
|
||||
DefaultPermissions.registerPermission(PREFIX + "defaultgamemode", "Allows the user to change the default gamemode of the server", PermissionDefault.OP, commands);
|
||||
DefaultPermissions.registerPermission(PREFIX + "seed", "Allows the user to view the seed of the world", PermissionDefault.OP, commands);
|
||||
DefaultPermissions.registerPermission(PREFIX + "effect", "Allows the user to add/remove effects on players", PermissionDefault.OP, commands);
|
||||
DefaultPermissions.registerPermission(PREFIX + "selector", "Allows the use of selectors", PermissionDefault.OP, commands);
|
||||
DefaultPermissions.registerPermission(PREFIX + "trigger", "Allows the use of the trigger command", PermissionDefault.TRUE, commands);
|
||||
DefaultPermissions.registerPermission(CommandPermissions.PREFIX + "kill", "Allows the user to commit suicide", PermissionDefault.OP, commands);
|
||||
DefaultPermissions.registerPermission(CommandPermissions.PREFIX + "me", "Allows the user to perform a chat action", PermissionDefault.TRUE, commands);
|
||||
DefaultPermissions.registerPermission(CommandPermissions.PREFIX + "msg", "Allows the user to privately message another player", PermissionDefault.TRUE, commands);
|
||||
DefaultPermissions.registerPermission(CommandPermissions.PREFIX + "help", "Allows the user to access Vanilla command help", PermissionDefault.TRUE, commands);
|
||||
DefaultPermissions.registerPermission(CommandPermissions.PREFIX + "say", "Allows the user to talk as the console", PermissionDefault.OP, commands);
|
||||
DefaultPermissions.registerPermission(CommandPermissions.PREFIX + "give", "Allows the user to give items to players", PermissionDefault.OP, commands);
|
||||
DefaultPermissions.registerPermission(CommandPermissions.PREFIX + "teleport", "Allows the user to teleport players", PermissionDefault.OP, commands);
|
||||
DefaultPermissions.registerPermission(CommandPermissions.PREFIX + "kick", "Allows the user to kick players", PermissionDefault.OP, commands);
|
||||
DefaultPermissions.registerPermission(CommandPermissions.PREFIX + "stop", "Allows the user to stop the server", PermissionDefault.OP, commands);
|
||||
DefaultPermissions.registerPermission(CommandPermissions.PREFIX + "list", "Allows the user to list all online players", PermissionDefault.OP, commands);
|
||||
DefaultPermissions.registerPermission(CommandPermissions.PREFIX + "gamemode", "Allows the user to change the gamemode of another player", PermissionDefault.OP, commands);
|
||||
DefaultPermissions.registerPermission(CommandPermissions.PREFIX + "xp", "Allows the user to give themselves or others arbitrary values of experience", PermissionDefault.OP, commands);
|
||||
DefaultPermissions.registerPermission(CommandPermissions.PREFIX + "toggledownfall", "Allows the user to toggle rain on/off for a given world", PermissionDefault.OP, commands);
|
||||
DefaultPermissions.registerPermission(CommandPermissions.PREFIX + "defaultgamemode", "Allows the user to change the default gamemode of the server", PermissionDefault.OP, commands);
|
||||
DefaultPermissions.registerPermission(CommandPermissions.PREFIX + "seed", "Allows the user to view the seed of the world", PermissionDefault.OP, commands);
|
||||
DefaultPermissions.registerPermission(CommandPermissions.PREFIX + "effect", "Allows the user to add/remove effects on players", PermissionDefault.OP, commands);
|
||||
DefaultPermissions.registerPermission(CommandPermissions.PREFIX + "selector", "Allows the use of selectors", PermissionDefault.OP, commands);
|
||||
DefaultPermissions.registerPermission(CommandPermissions.PREFIX + "trigger", "Allows the use of the trigger command", PermissionDefault.TRUE, commands);
|
||||
|
||||
DefaultPermissions.registerPermission("minecraft.admin.command_feedback", "Receive command broadcasts when sendCommandFeedback is true", PermissionDefault.OP, commands);
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@ public final class CraftDefaultPermissions {
|
||||
private CraftDefaultPermissions() {}
|
||||
|
||||
public static void registerCorePermissions() {
|
||||
Permission parent = DefaultPermissions.registerPermission(ROOT, "Gives the user the ability to use all vanilla utilities and commands");
|
||||
Permission parent = DefaultPermissions.registerPermission(CraftDefaultPermissions.ROOT, "Gives the user the ability to use all vanilla utilities and commands");
|
||||
CommandPermissions.registerPermissions(parent);
|
||||
parent.recalculatePermissibles();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user