Upstream merges and a few code cleanups

This commit is contained in:
MattBDev 2019-05-30 16:07:30 -04:00
parent 5ae8f20b73
commit aea5b68ced
17 changed files with 102 additions and 89 deletions

View File

@ -192,11 +192,11 @@ public class BukkitChunk_1_13 extends IntFaweChunk<Chunk, BukkitQueue_1_13> {
byte[] newBlockBytes = newBlockLight.asBytes();
byte[] blockLightBytes = blockLight.asBytes();
for (int i = 0; i < 2048; i++) newBlockBytes[i] = blockLightBytes[i];
System.arraycopy(blockLightBytes, 0, newBlockBytes, 0, 2048);
if (skyLight != null) {
byte[] newSkyBytes = newSkyLight.asBytes();
byte[] skyLightBytes = skyLight.asBytes();
for (int i = 0; i < 2048; i++) newSkyBytes[i] = skyLightBytes[i];
System.arraycopy(skyLightBytes, 0, newSkyBytes, 0, 2048);
}
// Copy counters
@ -241,7 +241,7 @@ public class BukkitChunk_1_13 extends IntFaweChunk<Chunk, BukkitQueue_1_13> {
Object[] currArray = ((Object[]) BukkitQueue_1_13.fieldLinearBlocks.get(currentPalette));
Object[] newArray = ((Object[]) BukkitQueue_1_13.fieldLinearBlocks.get(newPalette));
BukkitQueue_1_13.fieldLinearIndex.set(newPalette, BukkitQueue_1_13.fieldLinearIndex.get(currentPalette));
for (int i = 0; i < newArray.length; i++) newArray[i] = currArray[i];
System.arraycopy(currArray, 0, newArray, 0, newArray.length);
}
BukkitQueue_1_13.fieldPalette.set(paletteBlock, newPalette);
@ -348,8 +348,7 @@ public class BukkitChunk_1_13 extends IntFaweChunk<Chunk, BukkitQueue_1_13> {
// Remove entities
HashSet<UUID> entsToRemove = this.getEntityRemoves();
if (!entsToRemove.isEmpty()) {
for (int i = 0; i < entities.length; i++) {
Collection<Entity> ents = entities[i];
for (Collection<Entity> ents : entities) {
if (!ents.isEmpty()) {
Iterator<Entity> iter = ents.iterator();
while (iter.hasNext()) {
@ -445,13 +444,11 @@ public class BukkitChunk_1_13 extends IntFaweChunk<Chunk, BukkitQueue_1_13> {
UUID uuid = entity.getUniqueID();
entityTagMap.put("UUIDMost", new LongTag(uuid.getMostSignificantBits()));
entityTagMap.put("UUIDLeast", new LongTag(uuid.getLeastSignificantBits()));
if (nativeTag != null) {
NBTTagCompound tag = (NBTTagCompound) BukkitQueue_1_13.fromNative(nativeTag);
for (String name : Constants.NO_COPY_ENTITY_NBT_FIELDS) {
tag.remove(name);
}
entity.f(tag);
NBTTagCompound tag = (NBTTagCompound) BukkitQueue_1_13.fromNative(nativeTag);
for (String name : Constants.NO_COPY_ENTITY_NBT_FIELDS) {
tag.remove(name);
}
entity.f(tag);
entity.setLocation(x, y, z, yaw, pitch);
synchronized (BukkitQueue_0.class) {
nmsWorld.addEntity(entity, CreatureSpawnEvent.SpawnReason.CUSTOM);
@ -547,9 +544,7 @@ public class BukkitChunk_1_13 extends IntFaweChunk<Chunk, BukkitQueue_1_13> {
// Trim tiles
HashMap<BlockPosition, TileEntity> toRemove = null;
if (!tiles.isEmpty()) {
Iterator<Map.Entry<BlockPosition, TileEntity>> iterator = tiles.entrySet().iterator();
while (iterator.hasNext()) {
Map.Entry<BlockPosition, TileEntity> tile = iterator.next();
for (Map.Entry<BlockPosition, TileEntity> tile : tiles.entrySet()) {
BlockPosition pos = tile.getKey();
int lx = pos.getX() & 15;
int ly = pos.getY();
@ -629,4 +624,4 @@ public class BukkitChunk_1_13 extends IntFaweChunk<Chunk, BukkitQueue_1_13> {
}
return this;
}
}
}

View File

@ -691,27 +691,24 @@ public class BukkitQueue_1_13 extends BukkitQueue_0<net.minecraft.server.v1_13_R
sections[layer] = new ChunkSection(layer << 4, nmsWorld.worldProvider.g());
}
}
TaskManager.IMP.sync(new Supplier<Object>() {
@Override
public Object get() {
try {
int dirtyBits = fieldDirtyBits.getInt(playerChunk);
if (dirtyBits == 0) {
((CraftWorld) getWorld()).getHandle().getPlayerChunkMap().a(playerChunk);
}
if (mask == 0) {
dirtyBits = 65535;
} else {
dirtyBits |= mask;
}
fieldDirtyBits.set(playerChunk, dirtyBits);
fieldDirtyCount.set(playerChunk, 64);
} catch (IllegalAccessException e) {
e.printStackTrace();
TaskManager.IMP.sync(() -> {
try {
int dirtyBits = fieldDirtyBits.getInt(playerChunk);
if (dirtyBits == 0) {
((CraftWorld) getWorld()).getHandle().getPlayerChunkMap().a(playerChunk);
}
return null;
if (mask == 0) {
dirtyBits = 65535;
} else {
dirtyBits |= mask;
}
fieldDirtyBits.set(playerChunk, dirtyBits);
fieldDirtyCount.set(playerChunk, 64);
} catch (IllegalAccessException e) {
e.printStackTrace();
}
return null;
});
}
// if (mask == 0) {
@ -754,8 +751,7 @@ public class BukkitQueue_1_13 extends BukkitQueue_0<net.minecraft.server.v1_13_R
public boolean hasEntities(net.minecraft.server.v1_13_R2.Chunk nmsChunk) {
try {
final Collection<Entity>[] entities = nmsChunk.entitySlices;
for (int i = 0; i < entities.length; i++) {
Collection<Entity> slice = entities[i];
for (Collection<Entity> slice : entities) {
if (slice != null && !slice.isEmpty()) {
return true;
}
@ -781,8 +777,7 @@ public class BukkitQueue_1_13 extends BukkitQueue_0<net.minecraft.server.v1_13_R
@Override
public void setFullbright(ChunkSection[] sections) {
for (int i = 0; i < sections.length; i++) {
ChunkSection section = sections[i];
for (ChunkSection section : sections) {
if (section != null) {
byte[] bytes = section.getSkyLightArray().asBytes();
Arrays.fill(bytes, (byte) 255);

View File

@ -4,18 +4,13 @@ import com.boydti.fawe.Fawe;
import com.boydti.fawe.FaweAPI;
import com.boydti.fawe.config.BBC;
import com.boydti.fawe.config.Settings;
import com.boydti.fawe.object.FaweCommand;
import com.boydti.fawe.object.FaweLocation;
import com.boydti.fawe.object.FawePlayer;
import com.boydti.fawe.object.RegionWrapper;
import com.boydti.fawe.object.RunnableVal;
import com.boydti.fawe.object.*;
import com.boydti.fawe.object.changeset.DiskStorageHistory;
import com.boydti.fawe.util.MainUtil;
import com.boydti.fawe.util.MathMan;
import com.sk89q.worldedit.EditSession;
import com.sk89q.worldedit.world.World;
import com.sk89q.worldedit.world.block.BlockState;
import com.sk89q.worldedit.world.block.BlockStateHolder;
import java.util.Arrays;
import java.util.List;
@ -137,8 +132,8 @@ public class Rollback extends FaweCommand {
UUID user = null;
int radius = Integer.MAX_VALUE;
long time = Long.MAX_VALUE;
for (int i = 0; i < args.length; i++) {
String[] split = args[i].split(":");
for (String arg : args) {
String[] split = arg.split(":");
if (split.length != 2) {
BBC.COMMAND_SYNTAX.send(player, "/frb <info|undo> u:<uuid> r:<radius> t:<time>");
return;

View File

@ -84,16 +84,16 @@ public abstract class IntFaweChunk<T, V extends FaweQueue> extends FaweChunk<T>
public int getTotalCount() {
int total = 0;
for (int i = 0; i < count.length; i++) {
total += Math.min(4096, this.count[i]);
for (short value : count) {
total += Math.min(4096, value);
}
return total;
}
public int getTotalAir() {
int total = 0;
for (int i = 0; i < air.length; i++) {
total += Math.min(4096, this.air[i]);
for (short value : air) {
total += Math.min(4096, value);
}
return total;
}

View File

@ -293,8 +293,7 @@ public class CorruptSchematicStreamer {
int vx = 0, vy = 0, vz = 0;
for (int x = 0; x < factors.size(); x++) {
int xValue = factors.get(x);
for (int y = 0; y < factors.size(); y++) {
int yValue = factors.get(y);
for (int yValue : factors) {
long area = xValue * yValue;
if (volume % area == 0) {
int z = (int) (volume / area);

View File

@ -108,8 +108,8 @@ public class MCAChunk extends FaweChunk<Void> {
out.writeNamedTagName("Sections", NBTConstants.TYPE_LIST);
nbtOut.getOutputStream().writeByte(NBTConstants.TYPE_COMPOUND);
int len = 0;
for (int layer = 0; layer < ids.length; layer++) {
if (ids[layer] != null) len++;
for (int[] id : ids) {
if (id != null) len++;
}
nbtOut.getOutputStream().writeInt(len);
for (int layer = 0; layer < ids.length; layer++) {

View File

@ -165,8 +165,7 @@ public abstract class MCAWriter {
pool.submit(() -> {
try {
int totalLength = 8192;
for (int i = 0; i < compressed.length; i++) {
byte[] compressedBytes = compressed[i];
for (byte[] compressedBytes : compressed) {
if (compressedBytes != null) {
int blocks = ((4095 + compressedBytes.length + 5) / 4096) * 4096;
totalLength += blocks;

View File

@ -112,8 +112,8 @@ public class WritableMCAChunk extends FaweChunk<Void> {
out.writeNamedTag("Biomes", biomes);
}
int len = 0;
for (int layer = 0; layer < hasSections.length; layer++) {
if (hasSections[layer]) len++;
for (boolean hasSection : hasSections) {
if (hasSection) len++;
}
out.writeNamedTagName("Sections", NBTConstants.TYPE_LIST);
nbtOut.writeByte(NBTConstants.TYPE_COMPOUND);

View File

@ -47,8 +47,8 @@ public class FaweOutputStream extends DataOutputStream {
public void write(long[] data) throws IOException {
this.writeVarInt(data.length);
for(int j = 0; j < data.length; ++j) {
this.writeLong(data[j]);
for (long datum : data) {
this.writeLong(datum);
}
}

View File

@ -507,8 +507,8 @@ public class DiskStorageHistory extends FaweStreamChangeSet {
public int getSize() {
int count = 0;
for (int i = 0; i < blocks.length; i++) {
count += blocks[i];
for (int block : blocks) {
count += block;
}
return count;
}

View File

@ -71,12 +71,7 @@ public class MainUtil {
if (suggestions.getClass() != ArrayList.class) {
suggestions = new ArrayList<>(suggestions);
}
Iterator<String> iter = suggestions.iterator();
while (iter.hasNext()) {
if (!iter.next().startsWith(prefix)) {
iter.remove();
}
}
suggestions.removeIf(s -> !s.startsWith(prefix));
return suggestions;
}
@ -917,11 +912,11 @@ public class MainUtil {
if (directory.exists()) {
File[] files = directory.listFiles();
if (null != files) {
for (int i = 0; i < files.length; i++) {
if (files[i].isDirectory()) {
iterateFiles(files[i], task);
for (File file : files) {
if (file.isDirectory()) {
iterateFiles(file, task);
} else {
task.accept(files[i]);
task.accept(file);
}
}
}

View File

@ -243,8 +243,8 @@ public class BlockMaskBuilder {
private boolean optimizedStates = true;
public boolean isEmpty() {
for (int i = 0; i < bitSets.length; i++) {
if (bitSets[i] != null) return false;
for (long[] bitSet : bitSets) {
if (bitSet != null) return false;
}
return true;
}

View File

@ -0,0 +1,31 @@
/*
* WorldEdit, a Minecraft world manipulation toolkit
* Copyright (C) sk89q <http://www.sk89q.com>
* Copyright (C) WorldEdit team and contributors
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by the
* Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.sk89q.worldedit.registry;
/**
* Represents an objects that can be added to a registry and referenced by an id which is unique within its registry.
*/
public interface Keyed {
/**
* The id of this object in the registry. Must be unique, and lowercase. Certain registries (e.g Namespaced ones) may have additional restrictions.
* @return an id
*/
String getId();
}

View File

@ -26,6 +26,7 @@ import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Locale;
import java.util.Map;
import java.util.Set;
@ -33,7 +34,6 @@ import javax.annotation.Nullable;
public class Registry<V> implements Iterable<V> {
private final Map<String, V> map = new HashMap<>();
private Collection<V> values = Collections.unmodifiableCollection(map.values());
private final String name;
public Registry(final String name) {
@ -44,14 +44,16 @@ public class Registry<V> implements Iterable<V> {
return this.map.get(key);
}
public @Nullable V get(final String key) {
return get((CharSequence) key);
@Nullable
public V get(final String key) {
checkState(key.equals(key.toLowerCase(Locale.ROOT)), "key must be lowercase");
return this.map.get(key);
}
public V register(final String key, final V value) {
requireNonNull(key, "key");
requireNonNull(value, "value");
checkState(key.equals(key.toLowerCase()), "key must be lowercase");
checkState(key.equals(key.toLowerCase(Locale.ROOT)), "key must be lowercase");
checkState(!this.map.containsKey(key), "key '%s' already has an associated %s", key, this.name);
this.map.put(key, value);
return value;
@ -62,7 +64,7 @@ public class Registry<V> implements Iterable<V> {
}
public Collection<V> values() {
return values;
return Collections.unmodifiableCollection(this.map.values());
}
@Override

View File

@ -44,8 +44,7 @@ public class FunctionParametricCallable extends AParametricCallable {
Object[] param = null; // name | type | optional value
boolean checkEq = false;
int checkEqI = 0;
for (int i = 0; i < arguments.size(); i++) {
String arg = arguments.get(i);
for (String arg : arguments) {
if (arg.equals("=")) {
checkEqI++;
checkEq = true;
@ -65,8 +64,7 @@ public class FunctionParametricCallable extends AParametricCallable {
if (checkEqI == 1) {
param[1] = unqualified.getOrDefault(arg, String.class);
checkEq = false;
}
else if (checkEqI == 2) {
} else if (checkEqI == 2) {
char c = arg.charAt(0);
if (c == '\'' || c == '"') arg = arg.substring(1, arg.length() - 1);
param[2] = arg;

View File

@ -352,6 +352,8 @@ public class BlockState implements BlockStateHolder<BlockState>, FawePattern {
return equalsFuzzy((BlockState) obj);
}
private Integer hashCodeCache = null;
@Override
public int hashCode() {
return getOrdinal();

View File

@ -29,6 +29,7 @@ import com.sk89q.worldedit.function.mask.SingleBlockTypeMask;
import com.sk89q.worldedit.function.pattern.FawePattern;
import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.WorldEdit;
import com.sk89q.worldedit.registry.Keyed;
import com.sk89q.worldedit.world.item.ItemTypes;
import com.sk89q.worldedit.world.registry.BlockMaterial;
import com.sk89q.worldedit.extension.platform.Capability;
@ -45,7 +46,7 @@ import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
public class BlockType implements FawePattern {
public class BlockType implements FawePattern, Keyed {
private final String id;
private final BlockTypes.Settings settings;
@ -68,6 +69,7 @@ public class BlockType implements FawePattern {
*
* @return The id
*/
@Override
public String getId() {
return this.id;
}
@ -188,10 +190,10 @@ public class BlockType implements FawePattern {
}
/**
* Slow
* @return collection of states
* Gets a list of all possible states for this BlockType.
*
* @return All possible states
*/
@Deprecated
public List<BlockState> getAllStates() {
if (settings.stateOrdinals == null) return Collections.singletonList(getDefaultState());
return IntStream.of(settings.stateOrdinals).filter(i -> i != -1).mapToObj(i -> BlockTypes.states[i]).collect(Collectors.toList());
@ -239,7 +241,7 @@ public class BlockType implements FawePattern {
public ItemType getItemType() {
if(!initItemType) {
initItemType = true;
itemType = ItemTypes.get(getId());
itemType = ItemTypes.get(this.id);
}
return itemType;
}
@ -278,7 +280,7 @@ public class BlockType implements FawePattern {
@Override
public int hashCode() {
return settings.internalId;
return this.id.hashCode();
}
@Override