Upstream merges and a few code cleanups

Dieser Commit ist enthalten in:
MattBDev 2019-05-30 16:07:30 -04:00
Ursprung 5ae8f20b73
Commit aea5b68ced
17 geänderte Dateien mit 102 neuen und 89 gelöschten Zeilen

Datei anzeigen

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

Datei anzeigen

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

Datei anzeigen

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

Datei anzeigen

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

Datei anzeigen

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

Datei anzeigen

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

Datei anzeigen

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

Datei anzeigen

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

Datei anzeigen

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

Datei anzeigen

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

Datei anzeigen

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

Datei anzeigen

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

Datei anzeigen

@ -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();
}

Datei anzeigen

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

Datei anzeigen

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

Datei anzeigen

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

Datei anzeigen

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