Permalink
Browse files

Get rid of the string equality and convert a few more ID uses over.

  • Loading branch information...
me4502 committed Jan 3, 2018
1 parent 644d576 commit 224b587c9700757e9fbed5f907090804a1142949
Showing with 658 additions and 115 deletions.
  1. +3 −2 worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/EditSessionBlockChangeDelegate.java
  2. +1 −1 worldedit-core/src/legacy/java/com/sk89q/worldedit/blocks/SkullBlock.java
  3. +1 −1 worldedit-core/src/main/java/com/sk89q/worldedit/blocks/BaseBlock.java
  4. +1 −0 worldedit-core/src/main/java/com/sk89q/worldedit/blocks/type/BlockType.java
  5. +543 −10 worldedit-core/src/main/java/com/sk89q/worldedit/blocks/type/BlockTypes.java
  6. +3 −2 worldedit-core/src/main/java/com/sk89q/worldedit/command/BrushCommands.java
  7. +8 −7 worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/AreaPickaxe.java
  8. +2 −1 worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/FloatingTreeRemover.java
  9. +2 −6 worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/QueryTool.java
  10. +9 −7 worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/RecursivePickaxe.java
  11. +2 −1 worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/brush/CylinderBrush.java
  12. +2 −2 worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/brush/GravityBrush.java
  13. +2 −1 worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/brush/HollowCylinderBrush.java
  14. +2 −1 worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/brush/HollowSphereBrush.java
  15. +2 −1 worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/brush/SphereBrush.java
  16. +3 −2 worldedit-core/src/main/java/com/sk89q/worldedit/extent/NullExtent.java
  17. +2 −1 worldedit-core/src/main/java/com/sk89q/worldedit/extent/buffer/ForgetfulExtentBuffer.java
  18. +2 −1 worldedit-core/src/main/java/com/sk89q/worldedit/extent/clipboard/BlockArrayClipboard.java
  19. +2 −1 .../src/main/java/com/sk89q/worldedit/extent/clipboard/io/legacycompat/SignCompatibilityHandler.java
  20. +2 −1 worldedit-core/src/main/java/com/sk89q/worldedit/extent/reorder/MultiStageReorder.java
  21. +3 −2 worldedit-core/src/main/java/com/sk89q/worldedit/extent/validation/DataValidatorExtent.java
  22. +2 −1 worldedit-core/src/main/java/com/sk89q/worldedit/extent/world/BlockQuirkExtent.java
  23. +1 −1 worldedit-core/src/main/java/com/sk89q/worldedit/extent/world/SurvivalModeExtent.java
  24. +1 −1 worldedit-core/src/main/java/com/sk89q/worldedit/function/block/ExtentBlockCopy.java
  25. +4 −4 worldedit-core/src/main/java/com/sk89q/worldedit/function/block/Naturalizer.java
  26. +8 −8 worldedit-core/src/main/java/com/sk89q/worldedit/function/generator/FloraGenerator.java
  27. +8 −6 worldedit-core/src/main/java/com/sk89q/worldedit/function/generator/ForestGenerator.java
  28. +12 −10 worldedit-core/src/main/java/com/sk89q/worldedit/function/generator/GardenPatchGenerator.java
  29. +1 −1 worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/ExistingBlockMask.java
  30. +3 −4 worldedit-core/src/main/java/com/sk89q/worldedit/math/convolution/HeightMap.java
  31. +1 −3 worldedit-core/src/main/java/com/sk89q/worldedit/regions/RegionIntersection.java
  32. +2 −1 worldedit-core/src/main/java/com/sk89q/worldedit/regions/shape/ArbitraryShape.java
  33. +3 −2 worldedit-core/src/main/java/com/sk89q/worldedit/util/TreeGenerator.java
  34. +2 −3 worldedit-core/src/main/java/com/sk89q/worldedit/util/formatting/ColorCodeBuilder.java
  35. +6 −5 worldedit-core/src/main/java/com/sk89q/worldedit/world/AbstractWorld.java
  36. +3 −3 worldedit-core/src/main/java/com/sk89q/worldedit/world/NullWorld.java
  37. +1 −5 worldedit-core/src/main/java/com/sk89q/worldedit/world/storage/LegacyChunkStore.java
  38. +1 −4 worldedit-core/src/main/java/com/sk89q/worldedit/world/storage/McRegionChunkStore.java
  39. +2 −2 worldedit-sponge/src/main/java/com/sk89q/worldedit/sponge/SpongePlayer.java
@@ -20,6 +20,7 @@
package com.sk89q.worldedit.bukkit;
import com.sk89q.worldedit.blocks.BlockID;
import com.sk89q.worldedit.blocks.type.BlockTypes;
import org.bukkit.BlockChangeDelegate;
import com.sk89q.worldedit.EditSession;
import com.sk89q.worldedit.Vector;
@@ -67,7 +68,7 @@ public boolean setTypeIdAndData(int x, int y, int z, int typeId, int data) {
@Override
public int getTypeId(int x, int y, int z) {
return editSession.getBlockType(new Vector(x, y, z));
return editSession.getBlock(new Vector(x, y, z)).getId();
}
@Override
@@ -77,7 +78,7 @@ public int getHeight() {
@Override
public boolean isEmpty(int x, int y, int z) {
return editSession.getBlockType(new Vector(x, y, z)) == BlockID.AIR;
return editSession.getBlock(new Vector(x, y, z)).isAir();
}
}
@@ -100,7 +100,7 @@ public void setOwner(String owner) {
if (owner.length() > 16 || owner.isEmpty()) this.owner = "";
else this.owner = owner;
}
if (this.owner != null && !this.owner.isEmpty()) this.skullType = (byte) 3;
if (!this.owner.isEmpty()) this.skullType = (byte) 3;
}
/**
@@ -318,7 +318,7 @@ public BlockType getType() {
* @return if air
*/
public boolean isAir() {
return getType().getId().equals(BlockTypes.AIR);
return getType() == BlockTypes.AIR;
}
/**
@@ -50,6 +50,7 @@ public int getLegacyId() {
}
}
@Deprecated
public com.sk89q.worldedit.blocks.BlockType getLegacyType() {
return com.sk89q.worldedit.blocks.BlockType.fromID(getLegacyId());
}

Large diffs are not rendered by default.

Oops, something went wrong.
@@ -30,6 +30,7 @@
import com.sk89q.worldedit.WorldEditException;
import com.sk89q.worldedit.blocks.BaseBlock;
import com.sk89q.worldedit.blocks.BlockID;
import com.sk89q.worldedit.blocks.type.BlockTypes;
import com.sk89q.worldedit.command.tool.BrushTool;
import com.sk89q.worldedit.command.tool.brush.ButcherBrush;
import com.sk89q.worldedit.command.tool.brush.ClipboardBrush;
@@ -193,10 +194,10 @@ public void extinguishBrush(Player player, LocalSession session, EditSession edi
worldEdit.checkMaxBrushRadius(radius);
BrushTool tool = session.getBrushTool(player.getItemInHand());
Pattern fill = new BlockPattern(new BaseBlock(0));
Pattern fill = new BlockPattern(new BaseBlock(BlockTypes.AIR));
tool.setFill(fill);
tool.setSize(radius);
tool.setMask(new BlockMask(editSession, new BaseBlock(BlockID.FIRE)));
tool.setMask(new BlockMask(editSession, new BaseBlock(BlockTypes.FIRE)));
tool.setBrush(new SphereBrush(), "worldedit.brush.ex");
player.print(String.format("Extinguisher equipped (%.0f).", radius));
@@ -21,7 +21,8 @@
import com.sk89q.worldedit.*;
import com.sk89q.worldedit.blocks.BaseBlock;
import com.sk89q.worldedit.blocks.BlockID;
import com.sk89q.worldedit.blocks.type.BlockType;
import com.sk89q.worldedit.blocks.type.BlockTypes;
import com.sk89q.worldedit.entity.Player;
import com.sk89q.worldedit.extension.platform.Actor;
import com.sk89q.worldedit.extension.platform.Platform;
@@ -32,7 +33,7 @@
*/
public class AreaPickaxe implements BlockTool {
private static final BaseBlock air = new BaseBlock(0);
private static final BaseBlock air = new BaseBlock(BlockTypes.AIR);
private int range;
public AreaPickaxe(int range) {
@@ -49,13 +50,13 @@ public boolean actPrimary(Platform server, LocalConfiguration config, Player pla
int ox = clicked.getBlockX();
int oy = clicked.getBlockY();
int oz = clicked.getBlockZ();
int initialType = ((World) clicked.getExtent()).getBlockType(clicked.toVector());
BlockType initialType = ((World) clicked.getExtent()).getBlock(clicked.toVector()).getType();
if (initialType == 0) {
if (initialType == BlockTypes.AIR) {
return true;
}
if (initialType == BlockID.BEDROCK && !player.canDestroyBedrock()) {
if (initialType == BlockTypes.BEDROCK && !player.canDestroyBedrock()) {
return true;
}
@@ -67,11 +68,11 @@ public boolean actPrimary(Platform server, LocalConfiguration config, Player pla
for (int y = oy - range; y <= oy + range; ++y) {
for (int z = oz - range; z <= oz + range; ++z) {
Vector pos = new Vector(x, y, z);
if (editSession.getBlockType(pos) != initialType) {
if (editSession.getBlock(pos).getType() != initialType) {
continue;
}
((World) clicked.getExtent()).queueBlockBreakEffect(server, pos, initialType, clicked.toVector().distanceSq(pos));
((World) clicked.getExtent()).queueBlockBreakEffect(server, pos, initialType.getLegacyId(), clicked.toVector().distanceSq(pos));
editSession.setBlock(pos, air);
}
@@ -22,6 +22,7 @@
import com.sk89q.worldedit.*;
import com.sk89q.worldedit.blocks.BaseBlock;
import com.sk89q.worldedit.blocks.BlockID;
import com.sk89q.worldedit.blocks.type.BlockTypes;
import com.sk89q.worldedit.entity.Player;
import com.sk89q.worldedit.extension.platform.Actor;
import com.sk89q.worldedit.extension.platform.Platform;
@@ -37,7 +38,7 @@
* to anything else)
*/
public class FloatingTreeRemover implements BlockTool {
private static final BaseBlock AIR = new BaseBlock(BlockID.AIR);
private static final BaseBlock AIR = new BaseBlock(BlockTypes.AIR);
private int rangeSq;
public FloatingTreeRemover() {
@@ -56,7 +56,7 @@ public boolean actPrimary(Platform server, LocalConfiguration config, Player pla
World world = (World) clicked.getExtent();
EditSession editSession = session.createEditSession(player);
BaseBlock block = (editSession).rawGetBlock(clicked.toVector());
BaseBlock block = editSession.getBlock(clicked.toVector());
BlockType type = BlockType.fromID(block.getType().getLegacyId());
player.print("\u00A79@" + clicked.toVector() + ": " + "\u00A7e"
@@ -71,13 +71,9 @@ public boolean actPrimary(Platform server, LocalConfiguration config, Player pla
} else if (block instanceof NoteBlock) {
player.printRaw("\u00A7e" + "Note block: "
+ ((NoteBlock) block).getNote());
} else if (block.getType().getId().equals(BlockTypes.WOOL)) {
// Should never be null
player.printRaw("\u00A7e" + "Color: "
+ ClothColor.fromID(block.getData()).getName());
}
Map<String, ? extends State> states = BundledBlockData.getInstance().getStatesById(block.getId());
Map<String, ? extends State> states = BundledBlockData.getInstance().getStatesById(block.getType().getId());
if (states == null || states.isEmpty()) return true;
StringBuilder builder = new StringBuilder();
builder.append("States: ");
@@ -22,6 +22,8 @@
import com.sk89q.worldedit.*;
import com.sk89q.worldedit.blocks.BaseBlock;
import com.sk89q.worldedit.blocks.BlockID;
import com.sk89q.worldedit.blocks.type.BlockType;
import com.sk89q.worldedit.blocks.type.BlockTypes;
import com.sk89q.worldedit.entity.Player;
import com.sk89q.worldedit.extension.platform.Actor;
import com.sk89q.worldedit.extension.platform.Platform;
@@ -36,7 +38,7 @@
*/
public class RecursivePickaxe implements BlockTool {
private static final BaseBlock air = new BaseBlock(0);
private static final BaseBlock air = new BaseBlock(BlockTypes.AIR);
private double range;
public RecursivePickaxe(double range) {
@@ -52,13 +54,13 @@ public boolean canUse(Actor player) {
public boolean actPrimary(Platform server, LocalConfiguration config, Player player, LocalSession session, com.sk89q.worldedit.util.Location clicked) {
World world = (World) clicked.getExtent();
int initialType = world.getBlockType(clicked.toVector());
BlockType initialType = world.getBlock(clicked.toVector()).getType();
if (initialType == BlockID.AIR) {
if (initialType == BlockTypes.AIR) {
return true;
}
if (initialType == BlockID.BEDROCK && !player.canDestroyBedrock()) {
if (initialType == BlockTypes.BEDROCK && !player.canDestroyBedrock()) {
return true;
}
@@ -79,7 +81,7 @@ public boolean actPrimary(Platform server, LocalConfiguration config, Player pla
}
private static void recurse(Platform server, EditSession editSession, World world, BlockVector pos,
Vector origin, double size, int initialType, Set<BlockVector> visited) throws MaxChangedBlocksException {
Vector origin, double size, BlockType initialType, Set<BlockVector> visited) throws MaxChangedBlocksException {
final double distanceSq = origin.distanceSq(pos);
if (distanceSq > size*size || visited.contains(pos)) {
@@ -88,11 +90,11 @@ private static void recurse(Platform server, EditSession editSession, World worl
visited.add(pos);
if (editSession.getBlock(pos).getType().getLegacyId() != initialType) {
if (editSession.getBlock(pos).getType() != initialType) {
return;
}
world.queueBlockBreakEffect(server, pos, initialType, distanceSq);
world.queueBlockBreakEffect(server, pos, initialType.getLegacyId(), distanceSq);
editSession.setBlock(pos, air);
@@ -24,6 +24,7 @@
import com.sk89q.worldedit.Vector;
import com.sk89q.worldedit.blocks.BaseBlock;
import com.sk89q.worldedit.blocks.BlockID;
import com.sk89q.worldedit.blocks.type.BlockTypes;
import com.sk89q.worldedit.function.pattern.BlockPattern;
import com.sk89q.worldedit.function.pattern.Pattern;
import com.sk89q.worldedit.function.pattern.Patterns;
@@ -39,7 +40,7 @@ public CylinderBrush(int height) {
@Override
public void build(EditSession editSession, Vector position, Pattern pattern, double size) throws MaxChangedBlocksException {
if (pattern == null) {
pattern = new BlockPattern(new BaseBlock(BlockID.COBBLESTONE));
pattern = new BlockPattern(new BaseBlock(BlockTypes.COBBLESTONE));
}
editSession.makeCylinder(position, Patterns.wrap(pattern), size, size, height, true);
}
@@ -39,7 +39,7 @@ public GravityBrush(boolean fullHeight) {
@Override
public void build(EditSession editSession, Vector position, Pattern pattern, double size) throws MaxChangedBlocksException {
final BaseBlock air = new BaseBlock(BlockID.AIR, 0);
final BaseBlock air = new BaseBlock(BlockTypes.AIR);
final double startY = fullHeight ? editSession.getWorld().getMaxY() : position.getBlockY() + size;
for (double x = position.getBlockX() + size; x > position.getBlockX() - size; --x) {
for (double z = position.getBlockZ() + size; z > position.getBlockZ() - size; --z) {
@@ -56,7 +56,7 @@ public void build(EditSession editSession, Vector position, Pattern pattern, dou
Vector pt = new Vector(x, y, z);
Collections.reverse(blockTypes);
for (int i = 0; i < blockTypes.size();) {
if (editSession.getBlock(pt).getType().getId().equals(BlockTypes.AIR)) {
if (editSession.getBlock(pt).isAir()) {
editSession.setBlock(pt, blockTypes.get(i++));
}
pt = pt.add(0, 1, 0);
@@ -24,6 +24,7 @@
import com.sk89q.worldedit.Vector;
import com.sk89q.worldedit.blocks.BaseBlock;
import com.sk89q.worldedit.blocks.BlockID;
import com.sk89q.worldedit.blocks.type.BlockTypes;
import com.sk89q.worldedit.function.pattern.BlockPattern;
import com.sk89q.worldedit.function.pattern.Pattern;
import com.sk89q.worldedit.function.pattern.Patterns;
@@ -39,7 +40,7 @@ public HollowCylinderBrush(int height) {
@Override
public void build(EditSession editSession, Vector position, Pattern pattern, double size) throws MaxChangedBlocksException {
if (pattern == null) {
pattern = new BlockPattern(new BaseBlock(BlockID.COBBLESTONE));
pattern = new BlockPattern(new BaseBlock(BlockTypes.COBBLESTONE));
}
editSession.makeCylinder(position, Patterns.wrap(pattern), size, size, height, false);
}
@@ -24,6 +24,7 @@
import com.sk89q.worldedit.Vector;
import com.sk89q.worldedit.blocks.BaseBlock;
import com.sk89q.worldedit.blocks.BlockID;
import com.sk89q.worldedit.blocks.type.BlockTypes;
import com.sk89q.worldedit.function.pattern.BlockPattern;
import com.sk89q.worldedit.function.pattern.Pattern;
import com.sk89q.worldedit.function.pattern.Patterns;
@@ -33,7 +34,7 @@
@Override
public void build(EditSession editSession, Vector position, Pattern pattern, double size) throws MaxChangedBlocksException {
if (pattern == null) {
pattern = new BlockPattern(new BaseBlock(BlockID.COBBLESTONE));
pattern = new BlockPattern(new BaseBlock(BlockTypes.COBBLESTONE));
}
editSession.makeSphere(position, Patterns.wrap(pattern), size, size, size, false);
}
@@ -24,6 +24,7 @@
import com.sk89q.worldedit.Vector;
import com.sk89q.worldedit.blocks.BaseBlock;
import com.sk89q.worldedit.blocks.BlockID;
import com.sk89q.worldedit.blocks.type.BlockTypes;
import com.sk89q.worldedit.function.pattern.BlockPattern;
import com.sk89q.worldedit.function.pattern.Pattern;
import com.sk89q.worldedit.function.pattern.Patterns;
@@ -33,7 +34,7 @@
@Override
public void build(EditSession editSession, Vector position, Pattern pattern, double size) throws MaxChangedBlocksException {
if (pattern == null) {
pattern = new BlockPattern(new BaseBlock(BlockID.COBBLESTONE));
pattern = new BlockPattern(new BaseBlock(BlockTypes.COBBLESTONE));
}
editSession.makeSphere(position, Patterns.wrap(pattern), size, size, size, true);
}
@@ -23,6 +23,7 @@
import com.sk89q.worldedit.Vector2D;
import com.sk89q.worldedit.WorldEditException;
import com.sk89q.worldedit.blocks.BaseBlock;
import com.sk89q.worldedit.blocks.type.BlockTypes;
import com.sk89q.worldedit.entity.BaseEntity;
import com.sk89q.worldedit.entity.Entity;
import com.sk89q.worldedit.function.operation.Operation;
@@ -70,12 +71,12 @@ public Entity createEntity(Location location, BaseEntity entity) {
@Override
public BaseBlock getBlock(Vector position) {
return new BaseBlock(0);
return new BaseBlock(BlockTypes.AIR);
}
@Override
public BaseBlock getLazyBlock(Vector position) {
return new BaseBlock(0);
return new BaseBlock(BlockTypes.AIR);
}
@Nullable
@@ -24,6 +24,7 @@
import com.sk89q.worldedit.WorldEditException;
import com.sk89q.worldedit.blocks.BaseBlock;
import com.sk89q.worldedit.blocks.BlockID;
import com.sk89q.worldedit.blocks.type.BlockTypes;
import com.sk89q.worldedit.extent.AbstractDelegateExtent;
import com.sk89q.worldedit.extent.Extent;
import com.sk89q.worldedit.function.mask.Mask;
@@ -48,7 +49,7 @@
*/
public class ForgetfulExtentBuffer extends AbstractDelegateExtent implements Pattern {
private static final BaseBlock AIR = new BaseBlock(BlockID.AIR);
private static final BaseBlock AIR = new BaseBlock(BlockTypes.AIR);
private final Map<BlockVector, BaseBlock> buffer = new LinkedHashMap<BlockVector, BaseBlock>();
private final Mask mask;
@@ -24,6 +24,7 @@
import com.sk89q.worldedit.WorldEditException;
import com.sk89q.worldedit.blocks.BaseBlock;
import com.sk89q.worldedit.blocks.BlockID;
import com.sk89q.worldedit.blocks.type.BlockTypes;
import com.sk89q.worldedit.entity.BaseEntity;
import com.sk89q.worldedit.entity.Entity;
import com.sk89q.worldedit.function.operation.Operation;
@@ -129,7 +130,7 @@ public BaseBlock getBlock(Vector position) {
}
}
return new BaseBlock(BlockID.AIR);
return new BaseBlock(BlockTypes.AIR);
}
@Override
@@ -27,13 +27,14 @@
import com.sk89q.jnbt.Tag;
import com.sk89q.worldedit.blocks.BaseBlock;
import com.sk89q.worldedit.blocks.BlockID;
import com.sk89q.worldedit.blocks.type.BlockTypes;
import java.util.Map;
public class SignCompatibilityHandler implements NBTCompatibilityHandler {
@Override
public boolean isAffectedBlock(BaseBlock block) {
return block.getType().getLegacyId() == BlockID.SIGN_POST || block.getType().getLegacyId() == BlockID.WALL_SIGN;
return block.getType() == BlockTypes.SIGN || block.getType() == BlockTypes.WALL_SIGN;
}
@Override
@@ -27,6 +27,7 @@
import com.sk89q.worldedit.blocks.BaseBlock;
import com.sk89q.worldedit.blocks.BlockID;
import com.sk89q.worldedit.blocks.BlockType;
import com.sk89q.worldedit.blocks.type.BlockTypes;
import com.sk89q.worldedit.extent.AbstractDelegateExtent;
import com.sk89q.worldedit.extent.Extent;
import com.sk89q.worldedit.function.operation.BlockMapEntryPlacer;
@@ -103,7 +104,7 @@ public boolean setBlock(Vector location, BaseBlock block) throws WorldEditExcept
return !(lazyBlock.getType() == block.getType() && lazyBlock.getData() == block.getData());
} else if (BlockType.shouldPlaceLast(lazyBlock.getType().getLegacyId())) {
// Destroy torches, etc. first
super.setBlock(location, new BaseBlock(BlockID.AIR));
super.setBlock(location, new BaseBlock(BlockTypes.AIR));
return super.setBlock(location, block);
} else {
stage1.put(location.toBlockVector(), block);
Oops, something went wrong.

0 comments on commit 224b587

Please sign in to comment.