Code clean up, add preconditions, and correct Javadocs.

This commit is contained in:
sk89q 2014-07-26 00:29:12 -07:00
parent 70bca47be7
commit e95eeefa2b
132 changed files with 857 additions and 651 deletions

View File

@ -53,6 +53,7 @@ import java.util.Collection;
* as a "wildcard" block value, even though a {@link Mask} would be
* more appropriate.</p>
*/
@SuppressWarnings("deprecation")
public class BaseBlock extends Block implements TileEntityBlock {
/**
@ -251,9 +252,8 @@ public class BaseBlock extends Block implements TileEntityBlock {
return nbtData;
}
@Nullable
@Override
public void setNbtData(CompoundTag nbtData) {
public void setNbtData(@Nullable CompoundTag nbtData) {
this.nbtData = nbtData;
}
@ -359,11 +359,9 @@ public class BaseBlock extends Block implements TileEntityBlock {
}
final BaseBlock otherBlock = (BaseBlock) o;
if (getType() != otherBlock.getType()) {
return false;
}
return getData() == otherBlock.getData();
return getType() == otherBlock.getType() && getData() == otherBlock.getData();
}
/**

View File

@ -21,8 +21,6 @@ package com.sk89q.worldedit.blocks;
/**
* List of block IDs.
*
* @author sk89q
*/
public final class BlockID {
public static final int AIR = 0;

View File

@ -24,48 +24,160 @@ package com.sk89q.worldedit.blocks;
*/
public interface BlockMaterial {
/**
* Get whether this block is rendered like a normal block.
*
* @return the value of the test
*/
boolean isRenderedAsNormalBlock();
/**
* Get whether this block is a full sized cube.
*
* @return the value of the test
*/
boolean isFullCube();
/**
* Get whether this block is opaque.
*
* @return the value of the test
*/
boolean isOpaque();
/**
* Get whether this block emits a Redstone signal.
*
* @return the value of the test
*/
boolean isPowerSource();
/**
* Get whether this block is a liquid.
*
* @return the value of the test
*/
boolean isLiquid();
/**
* Get whether this block is a solid.
*
* @return the value of the test
*/
boolean isSolid();
/**
* Get the hardness factor for this block.
*
* @return the hardness factor
*/
float getHardness();
/**
* Get the resistance factor for this block.
*
* @return the resistance factor
*/
float getResistance();
/**
* Get the slipperiness factor for this block.
*
* @return the slipperiness factor
*/
float getSlipperiness();
/**
* Get whether this block blocks grass from growing.
*
* @return whether this block blocks grass
*/
boolean isGrassBlocking();
/**
* Get the ambient occlusion light value.
*
* @return the ambient occlusion light value
*/
float getAmbientOcclusionLightValue();
/**
* Get the opacity of this block for light to pass through.
*
* @return the opacity
*/
int getLightOpacity();
/**
* Get the light value for this block.
*
* @return the light value
*/
int getLightValue();
/**
* Get whether this block breaks when it is pushed by a piston.
*
* @return true if the block breaks
*/
boolean isFragileWhenPushed();
/**
* Get whether this block can be pushed by a piston.
*
* @return true if the block cannot be pushed
*/
boolean isUnpushable();
/**
* Get whether this block can be used in adventure mode.
*
* @return true if the block can be used in adventure mode
*/
boolean isAdventureModeExempt();
/**
* Get whether this block is ticked randomly.
*
* @return true if this block is ticked randomly
*/
boolean isTicksRandomly();
/**
* Gets whether this block uses a neighbor's light value.
*
* @return true if this block does
*/
boolean isUsingNeighborLight();
/**
* Get whether this block prevents movement.
*
* @return true if this block blocks movement
*/
boolean isMovementBlocker();
/**
* Get whether this block will burn.
*
* @return true if this block will burn
*/
boolean isBurnable();
/**
* Get whether this block needs to be broken by a tool for maximum
* speed.
*
* @return true if a tool is required
*/
boolean isToolRequired();
/**
* Get whether this block is replaced when a block is placed over it
* (for example, tall grass).
*
* @return true if the block is replaced
*/
boolean isReplacedDuringPlacement();
}

View File

@ -22,10 +22,22 @@ package com.sk89q.worldedit.entity;
import com.sk89q.jnbt.CompoundTag;
import com.sk89q.worldedit.world.NbtValued;
import javax.annotation.Nullable;
import static com.google.common.base.Preconditions.checkNotNull;
/**
* A snapshot of an entity that can be reused and passed around.
* Represents a mutable "snapshot" of an entity.
*
* <p>An instance of this class contains all the information needed to
* accurately reproduce the entity, provided that the instance was
* made correctly. In some implementations, it may not be possible to get a
* snapshot of entities correctly, so, for example, the NBT data for an entity
* may be missing.</p>
*
* <p>This class identifies entities using its entity type string, although
* this is not very efficient as the types are currently not interned. This
* may be changed in the future.</p>
*/
public class BaseEntity implements NbtValued {
@ -68,14 +80,14 @@ public class BaseEntity implements NbtValued {
return true;
}
@Nullable
@Override
public CompoundTag getNbtData() {
return nbtData;
}
@Override
public void setNbtData(CompoundTag nbtData) {
checkNotNull(nbtData);
public void setNbtData(@Nullable CompoundTag nbtData) {
this.nbtData = nbtData;
}

View File

@ -28,19 +28,21 @@ import javax.annotation.Nullable;
/**
* A reference to an instance of an entity that exists in an {@link Extent}
* and thus would have position and similar details.
* </p>
* This object cannot be directly cloned because it represents a particular
*
* <p>This object cannot be directly cloned because it represents a particular
* instance of an entity, but a {@link BaseEntity} can be created from
* this entity (or at least, it will be possible in the future), which
* can then be used to spawn new instances of that particular entity
* description.
* this entity by calling {@link #getState()}.</p>
*/
public interface Entity extends Faceted {
/**
* Get a copy of the entity's state.
*
* @return the entity's state or null if one cannot be gotten
* <p>In some cases, this method may return {@code null} if a snapshot
* of the entity can't be created. It may not be possible, for example,
* to get a snapshot of a player.</p>
*
* @return the entity's state or null if one cannot be created
*/
@Nullable
BaseEntity getState();

View File

@ -30,7 +30,7 @@ import com.sk89q.worldedit.extent.inventory.BlockBag;
import com.sk89q.worldedit.world.World;
/**
* A player.
* Represents a player
*/
public interface Player extends Entity, Actor {
@ -192,12 +192,19 @@ public interface Player extends Entity, Actor {
* Get the point of the block being looked at. May return null.
* Will return the farthest away air block if useLastBlock is true and no other block is found.
*
* @param range How far to checks for blocks
* @param useLastBlock Try to return the last valid air block found.
* @param range how far to checks for blocks
* @param useLastBlock try to return the last valid air block found
* @return point
*/
WorldVector getBlockTrace(int range, boolean useLastBlock);
/**
* Get the face that the player is looking at.
*
* @param range the range
* @param useLastBlock try to return the last valid air block found
* @return a face
*/
WorldVectorFace getBlockTraceFace(int range, boolean useLastBlock);
/**
@ -225,25 +232,31 @@ public interface Player extends Entity, Actor {
/**
* Get the actor's position.
* </p>
* If the actor has no permission, then return a dummy location.
*
* <p>If the actor has no permission, then a dummy location is returned.</p>
*
* @return the actor's position
* @deprecated use {@link #getLocation()}
*/
@Deprecated
WorldVector getPosition();
/**
* Get the player's view pitch.
* Get the player's view pitch in degrees.
*
* @return pitch
* @deprecated use {@link #getLocation()}
*/
@Deprecated
double getPitch();
/**
* Get the player's view yaw.
* Get the player's view yaw in degrees.
*
* @return yaw
* @deprecated use {@link #getLocation()}
*/
@Deprecated
double getYaw();
/**
@ -257,16 +270,16 @@ public interface Player extends Entity, Actor {
/**
* Move the player.
*
* @param pos Where to move them
* @param pitch The pitch (up/down) of the player's view
* @param yaw The yaw (left/right) of the player's view
* @param pos where to move them
* @param pitch the pitch (up/down) of the player's view in degrees
* @param yaw the yaw (left/right) of the player's view in degrees
*/
void setPosition(Vector pos, float pitch, float yaw);
/**
* Move the player.
*
* @param pos Where to move them
* @param pos where to move them
*/
void setPosition(Vector pos);

View File

@ -34,17 +34,19 @@ import static com.sk89q.worldedit.EditSession.Stage;
/**
* Raised (several times) when a new {@link EditSession} is being instantiated.
* </p>
* Block loggers, as well as block set interceptors, can use this event to wrap
*
* <p></p>Block loggers, as well as block set interceptors, can use this event to wrap
* the given {@link Extent} with their own, which would allow them to intercept
* all changes made to the world. For example, the code below would wrap the
* existing extent with a custom one, and the custom extent would receive
* all method calls <strong>before</strong> the extent fetched from
* {@link #getExtent()} would.
* {@link #getExtent()} would.</p>
*
* <pre>
* event.setExtent(new MyExtent(event.getExtent())
* </pre>
* This event is fired several times during the creation of a single
*
* <p></p>This event is fired several times during the creation of a single
* {@link EditSession}, but {@link #getStage()} will differ each time.
* The stage determines at which point {@link Extent}s added to this event
* will be called. For example, if you inject an extent when the stage
@ -55,7 +57,7 @@ import static com.sk89q.worldedit.EditSession.Stage;
* custom {@link Extent} because that method bypasses history (and reorder).
* It is thus recommended that loggers intercept at {@link Stage#BEFORE_CHANGE}
* and block interceptors intercept at BOTH {@link Stage#BEFORE_CHANGE} and
* {@link Stage#BEFORE_HISTORY}.
* {@link Stage#BEFORE_HISTORY}.</p>
*/
public class EditSessionEvent extends Event {

View File

@ -31,9 +31,9 @@ import java.util.Set;
/**
* A registry of known {@link BaseBlock}s. Provides methods to instantiate
* new blocks from input.
* </p>
* Instances of this class can be taken from
* {@link WorldEdit#getBlockFactory()}.
*
* <p>Instances of this class can be taken from
* {@link WorldEdit#getBlockFactory()}.</p>
*/
public class BlockFactory extends AbstractFactory<BaseBlock> {

View File

@ -144,7 +144,7 @@ class DefaultBlockParser extends InputParser<BaseBlock> {
if (parseDataValue) { // Block data not yet detected
// Parse the block data (optional)
try {
if (typeAndData.length > 1 && typeAndData[1].length() > 0) {
if (typeAndData.length > 1 && !typeAndData[1].isEmpty()) {
data = Integer.parseInt(typeAndData[1]);
}

View File

@ -63,7 +63,7 @@ class DefaultMaskParser extends InputParser<Mask> {
List<Mask> masks = new ArrayList<Mask>();
for (String component : input.split(" ")) {
if (component.length() == 0) {
if (component.isEmpty()) {
continue;
}

View File

@ -26,9 +26,9 @@ import com.sk89q.worldedit.internal.registry.AbstractFactory;
/**
* A registry of known {@link Mask}s. Provides methods to instantiate
* new masks from input.
* </p>
* Instances of this class can be taken from
* {@link WorldEdit#getMaskFactory()}.
*
* <p>Instances of this class can be taken from
* {@link WorldEdit#getMaskFactory()}.</p>
*/
public final class MaskFactory extends AbstractFactory<Mask> {

View File

@ -26,9 +26,9 @@ import com.sk89q.worldedit.internal.registry.AbstractFactory;
/**
* A registry of known {@link Pattern}s. Provides methods to instantiate
* new patterns from input.
* </p>
* Instances of this class can be taken from
* {@link WorldEdit#getPatternFactory()}.
*
* <p>Instances of this class can be taken from
* {@link WorldEdit#getPatternFactory()}.</p>
*/
public final class PatternFactory extends AbstractFactory<Pattern> {

View File

@ -30,8 +30,8 @@ import javax.annotation.Nullable;
/**
* Contains contextual information that may be useful when constructing
* objects from a registry (such as {@link MaskFactory}).
* </p>
* By default, {@link #isRestricted()} will return true.
*
* <p>By default, {@link #isRestricted()} will return true.</p>
*/
public class ParserContext {

View File

@ -59,8 +59,8 @@ import static com.google.common.base.Preconditions.checkNotNull;
/**
* Handles the registration and invocation of commands.
* </p>
* This class is primarily for internal usage.
*
* <p>This class is primarily for internal usage.</p>
*/
public final class CommandManager {
@ -206,7 +206,7 @@ public final class CommandManager {
Request.reset();
Actor actor = platformManager.createProxyActor(event.getActor());
String split[] = commandDetection(event.getArguments().split(" "));
String[] split = commandDetection(event.getArguments().split(" "));
// No command found!
if (!dispatcher.contains(split[0])) {

View File

@ -44,8 +44,8 @@ import static com.google.common.base.Preconditions.checkNotNull;
/**
* Manages registered {@link Platform}s for WorldEdit. Platforms are
* implementations of WorldEdit.
* </p>
* This class is thread-safe.
*
* <p>This class is thread-safe.</p>
*/
public class PlatformManager {
@ -99,9 +99,9 @@ public class PlatformManager {
/**
* Unregister a platform from WorldEdit.
* </p>
* If the platform has been chosen for any capabilities, then a new
* platform will be found.
*
* <p>If the platform has been chosen for any capabilities, then a new
* platform will be found.</p>
*
* @param platform the platform
*/
@ -189,8 +189,8 @@ public class PlatformManager {
/**
* Get a list of loaded platforms.
* </p>
* The returned list is a copy of the original and is mutable.
*
* <p>The returned list is a copy of the original and is mutable.</p>
*
* @return a list of platforms
*/
@ -252,9 +252,9 @@ public class PlatformManager {
/**
* Get the current configuration.
* </p>
* If no platform has been registered yet, then a default configuration
* will be returned.
*
* <p>If no platform has been registered yet, then a default configuration
* will be returned.</p>
*
* @return the configuration
*/
@ -365,7 +365,6 @@ public class PlatformManager {
// Create a proxy actor with a potentially different world for
// making changes to the world
Player player = createProxyActor(event.getPlayer());
World world = player.getWorld();
switch (event.getInputType()) {
case PRIMARY: {

View File

@ -39,9 +39,9 @@ public interface Extent extends InputExtent, OutputExtent {
/**
* Get the minimum point in the extent.
* </p>
* If the extent is unbounded, then a large (negative) value may
* be returned.
*
* <p>If the extent is unbounded, then a large (negative) value may
* be returned.</p>
*
* @return the minimum point
*/
@ -49,9 +49,9 @@ public interface Extent extends InputExtent, OutputExtent {
/**
* Get the maximum point in the extent.
* </p>
* If the extent is unbounded, then a large (positive) value may
* be returned.
*
* <p>If the extent is unbounded, then a large (positive) value may
* be returned.</p>
*
* @return the maximum point
*/
@ -59,10 +59,10 @@ public interface Extent extends InputExtent, OutputExtent {
/**
* Get a list of all entities within the given region.
* </p>
* If the extent is not wholly loaded (i.e. a world being simulated in the
*
* <p>If the extent is not wholly loaded (i.e. a world being simulated in the
* game will not have every chunk loaded), then this list may not be
* incomplete.
* incomplete.</p>
*
* @return a list of entities
*/
@ -70,10 +70,10 @@ public interface Extent extends InputExtent, OutputExtent {
/**
* Get a list of all entities.
* </p>
* If the extent is not wholly loaded (i.e. a world being simulated in the
*
* <p>If the extent is not wholly loaded (i.e. a world being simulated in the
* game will not have every chunk loaded), then this list may not be
* incomplete.
* incomplete.</p>
*
* @return a list of entities
*/

View File

@ -32,20 +32,20 @@ public interface InputExtent {
/**
* Get a snapshot of the block at the given location.
* </p>
* If the given position is out of the bounds of the extent, then the behavior
* is undefined (an air block could be returned). However, <code>null</code>
* should <strong>not</strong> be returned.
* </p>
* The returned block is mutable and is a snapshot of the block at the time
*
* <p>If the given position is out of the bounds of the extent, then the behavior
* is undefined (an air block could be returned). However, {@code null}
* should <strong>not</strong> be returned.</p>
*
* <p>The returned block is mutable and is a snapshot of the block at the time
* of call. It has no position attached to it, so it could be reused in
* {@link Pattern}s and so on.
* </p>
* Calls to this method can actually be quite expensive, so cache results
* {@link Pattern}s and so on.</p>
*
* <p>Calls to this method can actually be quite expensive, so cache results
* whenever it is possible, while being aware of the mutability aspect.
* The cost, however, depends on the implementation and particular extent.
* If only basic information about the block is required, then use of
* {@link #getLazyBlock(Vector)} is recommended.
* {@link #getLazyBlock(Vector)} is recommended.</p>
*
* @param position position of the block
* @return the block
@ -55,20 +55,20 @@ public interface InputExtent {
/**
* Get a lazy, immutable snapshot of the block at the given location that only
* immediately contains information about the block's type (and metadata).
* </p>
* Further information (such as NBT data) will be available <strong>by the
*
* <p>Further information (such as NBT data) will be available <strong>by the
* time of access</strong>. Therefore, it is not recommended that
* this method is used if the world is being simulated at the time of
* call. If the block needs to be stored for future use, then this method should
* definitely not be used. Moreover, the block that is returned is immutable (or
* should be), and therefore modifications should not be attempted on it. If a
* modifiable copy is required, then the block should be cloned.
* </p>
* This method exists because it is sometimes important to inspect the block
* modifiable copy is required, then the block should be cloned.</p>
*
* <p>This method exists because it is sometimes important to inspect the block
* at a given location, but {@link #getBlock(Vector)} may be too expensive in
* the underlying implementation. It is also not possible to implement
* caching if the returned object is mutable, so this methods allows caching
* implementations to be used.
* implementations to be used.</p>
*
* @param position position of the block
* @return the block

View File

@ -37,13 +37,13 @@ public interface OutputExtent {
* Change the block at the given location to the given block. The operation may
* not tie the given {@link BaseBlock} to the world, so future changes to the
* {@link BaseBlock} do not affect the world until this method is called again.
* </p>
* The return value of this method indicates whether the change was probably
*
* <p>The return value of this method indicates whether the change was probably
* successful. It may not be successful if, for example, the location is out
* of the bounds of the extent. It may be unsuccessful if the block passed
* is the same as the one in the world. However, the return value is only an
* estimation and it may be incorrect, but it could be used to count, for
* example, the approximate number of changes.
* example, the approximate number of changes.</p>
*
* @param position position of the block
* @param block block to set

View File

@ -42,9 +42,9 @@ import static com.google.common.base.Preconditions.checkNotNull;
/**
* Buffers changes to an {@link Extent} and allows later retrieval for
* actual application of the changes.
* </p>
* This buffer will not attempt to return results from the buffer when
* accessor methods (such as {@link #getBlock(Vector)}) are called.
*
* <p>This buffer will not attempt to return results from the buffer when
* accessor methods (such as {@link #getBlock(Vector)}) are called.</p>
*/
public class ForgetfulExtentBuffer extends AbstractDelegateExtent implements Pattern {

View File

@ -51,8 +51,8 @@ public class BlockArrayClipboard implements Clipboard {
/**
* Create a new instance.
* <p>
* The origin will be placed at the region's lowest minimum point.
*
* <p>The origin will be placed at the region's lowest minimum point.</p>
*
* @param region the bounding region
*/

View File

@ -28,8 +28,8 @@ import static com.google.common.base.Preconditions.checkNotNull;
/**
* An implementation of {@link Entity} that stores a {@link BaseEntity} with it.
* </p>
* Calls to {@link #getState()} return a clone.
*
* <p>Calls to {@link #getState()} return a clone.</p>
*/
abstract class StoredEntity implements Entity {

View File

@ -24,15 +24,14 @@ import com.sk89q.worldedit.blocks.*;
/**
* Represents a source to get blocks from and store removed ones.
*
* @author sk89q
*/
public abstract class BlockBag {
/**
* Stores a block as if it was mined.
*
* @param id
* @throws BlockBagException
* @param id the type ID
* @throws BlockBagException on error
* @deprecated Use {@link BlockBag#storeDroppedBlock(int, int)} instead
*/
@Deprecated
@ -43,9 +42,9 @@ public abstract class BlockBag {
/**
* Stores a block as if it was mined.
*
* @param id
* @param data
* @throws BlockBagException
* @param id the type ID
* @param data the data value
* @throws BlockBagException on error
*/
public void storeDroppedBlock(int id, int data) throws BlockBagException {
BaseItem dropped = BlockType.getBlockBagItem(id, data);
@ -58,8 +57,8 @@ public abstract class BlockBag {
/**
* Sets a block as if it was placed by hand.
*
* @param id
* @throws BlockBagException
* @param id the type ID
* @throws BlockBagException on error
* @deprecated Use {@link #fetchPlacedBlock(int,int)} instead
*/
@Deprecated
@ -70,9 +69,9 @@ public abstract class BlockBag {
/**
* Sets a block as if it was placed by hand.
*
* @param id
* @param data TODO
* @throws BlockBagException
* @param id the type ID
* @param data the data value
* @throws BlockBagException on error
*/
public void fetchPlacedBlock(int id, int data) throws BlockBagException {
try {
@ -117,10 +116,10 @@ public abstract class BlockBag {
/**
* Get a block.
*
* Either this method or fetchItem needs to be overridden
* <p>Either this method or fetchItem needs to be overridden.</p>
*
* @param id
* @throws BlockBagException
* @param id the type ID
* @throws BlockBagException on error
*/
public void fetchBlock(int id) throws BlockBagException {
fetchItem(new BaseItem(id));
@ -129,10 +128,10 @@ public abstract class BlockBag {
/**
* Get a block.
*
* Either this method or fetchBlock needs to be overridden
* <p>Either this method or fetchItem needs to be overridden.</p>
*
* @param item
* @throws BlockBagException
* @param item the item
* @throws BlockBagException on error
*/
public void fetchItem(BaseItem item) throws BlockBagException {
fetchBlock(item.getType());
@ -140,11 +139,11 @@ public abstract class BlockBag {
/**
* Store a block.
*
* <p>Either this method or fetchItem needs to be overridden.</p>
*
* Either this method or storeItem needs to be overridden
*
* @param id
* @throws BlockBagException
* @param id the type ID
* @throws BlockBagException on error
*/
public void storeBlock(int id) throws BlockBagException {
storeItem(new BaseItem(id));
@ -152,11 +151,11 @@ public abstract class BlockBag {
/**
* Store a block.
*
* <p>Either this method or fetchItem needs to be overridden.</p>
*
* Either this method or storeBlock needs to be overridden
*
* @param item
* @throws BlockBagException
* @param item the item
* @throws BlockBagException on error
*/
public void storeItem(BaseItem item) throws BlockBagException {
storeBlock(item.getType());
@ -165,7 +164,7 @@ public abstract class BlockBag {
/**
* Checks to see if a block exists without removing it.
*
* @param id
* @param id the type ID
* @return whether the block exists
*/
public boolean peekBlock(int id) {
@ -186,14 +185,14 @@ public abstract class BlockBag {
/**
* Adds a position to be used a source.
*
* @param pos
* @param pos the position
*/
public abstract void addSourcePosition(WorldVector pos);
/**
* Adds a position to be used a source.
*
* @param pos
* @param pos the position
*/
public abstract void addSingleSourcePosition(WorldVector pos);
}

View File

@ -20,9 +20,7 @@
package com.sk89q.worldedit.extent.inventory;
/**
*
* @author sk89q
* Thrown when a block bag detects a problem.
*/
public class BlockBagException extends Exception {
private static final long serialVersionUID = 4672190086028430655L;
}

View File

@ -44,7 +44,6 @@ public class BlockBagExtent extends AbstractDelegateExtent {
* Create a new instance.
*
* @param extent the extent
* @param world the world
* @param blockBag the block bag
*/
public BlockBagExtent(Extent extent, @Nullable BlockBag blockBag) {

View File

@ -20,9 +20,7 @@
package com.sk89q.worldedit.extent.inventory;
/**
*
* @author sk89q
* Thrown when there are no more blocks left.
*/
public class OutOfBlocksException extends BlockBagException {
private static final long serialVersionUID = 7495899825677689509L;
}

View File

@ -20,26 +20,24 @@
package com.sk89q.worldedit.extent.inventory;
/**
*
* @author sk89q
* Thrown when the target inventory of a block bag is full.
*/
public class OutOfSpaceException extends BlockBagException {
private static final long serialVersionUID = -2962840237632916821L;
/**
* Stores the block ID.
*/
private int id;
/**
* Construct the object.
* @param id
*
* @param id the ID of the block
*/
public OutOfSpaceException(int id) {
this.id = id;
}
/**
* Get the ID of the block
*
* @return the id
*/
public int getID() {

View File

@ -20,10 +20,7 @@
package com.sk89q.worldedit.extent.inventory;
/**
*
* @author sk89q
* Thrown when a block that can't be placed is used.
*/
public class UnplaceableBlockException extends BlockBagException {
private static final long serialVersionUID = 7227883966999843526L;
}

View File

@ -186,7 +186,7 @@ public class MultiStageReorder extends AbstractDelegateExtent implements Reorder
current = current.add(attachment.vector()).toBlockVector();
if (!blocks.contains(current)) {
// We ran outside the remaing set => assume we can place blocks on this
// We ran outside the remaining set => assume we can place blocks on this
break;
}

View File

@ -24,10 +24,10 @@ import com.sk89q.worldedit.extent.Extent;
/**
* An interface for {@link Extent}s that are meant to reorder changes so
* that they are more successful.
* </p>
* For example, torches in Minecraft need to be placed on a block. A smart
*
* <p>For example, torches in Minecraft need to be placed on a block. A smart
* reordering implementation might place the torch after the block has
* been placed.
* been placed.</p>
*/
public interface ReorderingExtent extends Extent {

View File

@ -31,11 +31,11 @@ import static com.google.common.base.Preconditions.checkNotNull;
/**
* Makes changes to the world as if a player had done so during survival mode.
* </p>
* Note that this extent may choose to not call the underlying
*
* <p>Note that this extent may choose to not call the underlying
* extent and may instead call methods on the {@link World} that is passed
* in the constructor. For that reason, if you wish to "catch" changes, you
* should catch them before the changes reach this extent.
* should catch them before the changes reach this extent.</p>
*/
public class SurvivalModeExtent extends AbstractDelegateExtent {
@ -57,10 +57,10 @@ public class SurvivalModeExtent extends AbstractDelegateExtent {
/**
* Return whether changes to the world should be simulated with the
* use of game tools (such as pickaxes) whenever possible and reasonable.
* </p>
* For example, we could pretend that the act of setting a coal ore block
*
* <p>For example, we could pretend that the act of setting a coal ore block
* to air (nothing) was the act of a player mining that coal ore block
* with a pickaxe, which would mean that a coal item would be dropped.
* with a pickaxe, which would mean that a coal item would be dropped.</p>
*
* @return true if tool use is to be simulated
*/

View File

@ -39,9 +39,9 @@ public interface LayerFunction {
/**
* Apply the function to the given position.
* </p>
* The depth would be the number of blocks from the surface if
* a {@link LayerVisitor} was used.
*
* <p>The depth would be the number of blocks from the surface if
* a {@link LayerVisitor} was used.</p>
*
* @param position the position
* @param depth the depth as a number starting from 0

View File

@ -31,9 +31,9 @@ import com.sk89q.worldedit.function.pattern.RandomPattern;
/**
* Generates flora (which may include tall grass, flowers, etc.).
* <p>
* The current implementation is not biome-aware, but it may become so in
* the future.
*
* <p>The current implementation is not biome-aware, but it may become so in
* the future.</p>
*/
public class FloraGenerator implements RegionFunction {
@ -53,8 +53,9 @@ public class FloraGenerator implements RegionFunction {
/**
* Return whether the flora generator is set to be biome-aware.
* <p>
* By default, it is currently disabled by default, but this may change.
*
* <p>By default, it is currently disabled by default, but
* this may change.</p>
*
* @return true if biome aware
*/
@ -64,8 +65,8 @@ public class FloraGenerator implements RegionFunction {
/**
* Set whether the generator is biome aware.
* <p>
* It is currently not possible to make the generator biome-aware.
*
* <p>It is currently not possible to make the generator biome-aware.</p>
*
* @param biomeAware must always be false
*/
@ -73,7 +74,6 @@ public class FloraGenerator implements RegionFunction {
if (biomeAware) {
throw new IllegalArgumentException("Cannot enable biome-aware mode; not yet implemented");
}
this.biomeAware = biomeAware;
}
/**

View File

@ -133,10 +133,10 @@ public final class Masks {
/**
* Wrap an old-style mask and convert it to a new mask.
* </p>
* Note, however, that this is strongly not recommended because
*
* <p>Note, however, that this is strongly not recommended because
* {@link com.sk89q.worldedit.masks.Mask#prepare(LocalSession, LocalPlayer, Vector)}
* is not called.
* is not called.</p>
*
* @param mask the old-style mask
* @param editSession the edit session to bind to
@ -163,10 +163,10 @@ public final class Masks {
/**
* Wrap an old-style mask and convert it to a new mask.
* </p>
* As an {@link EditSession} is not provided in this case, one will be
*
* <p>As an {@link EditSession} is not provided in this case, one will be
* taken from the {@link Request}, if possible. If not possible, then the
* mask will return false.
* mask will return false.</p>
*
* @param mask the old-style mask
* @return a new-style mask

View File

@ -77,8 +77,6 @@ public class NoiseFilter extends AbstractMask {
/**
* Set the probability of passing as a number between 0 and 1 (inclusive).
*
* @return the density
*/
public void setDensity(double density) {
checkArgument(density >= 0, "density must be >= 0");

View File

@ -75,8 +75,6 @@ public class NoiseFilter2D extends AbstractMask2D {
/**
* Set the probability of passing as a number between 0 and 1 (inclusive).
*
* @return the density
*/
public void setDensity(double density) {
checkArgument(density >= 0, "density must be >= 0");

View File

@ -43,10 +43,10 @@ import static com.google.common.base.Preconditions.checkNotNull;
/**
* Makes a copy of a portion of one extent to another extent or another point.
* </p>
* This is a forward extent copy, meaning that it iterates over the blocks in the
* source extent, and will copy as many blocks as there are in the source.
* Therefore, interpolation will not occur to fill in the gaps.
*
* <p>This is a forward extent copy, meaning that it iterates over the blocks
* in the source extent, and will copy as many blocks as there are in the
* source. Therefore, interpolation will not occur to fill in the gaps.</p>
*/
public class ForwardExtentCopy implements Operation {
@ -102,8 +102,8 @@ public class ForwardExtentCopy implements Operation {
/**
* Get the transformation that will occur on every point.
* </p>
* The transformation will stack with each repetition.
*
* <p>The transformation will stack with each repetition.</p>
*
* @return a transformation
*/
@ -124,8 +124,8 @@ public class ForwardExtentCopy implements Operation {
/**
* Get the mask that gets applied to the source extent.
* </p>
* This mask can be used to filter what will be copied from the source.
*
* <p>This mask can be used to filter what will be copied from the source.</p>
*
* @return a source mask
*/
@ -195,7 +195,7 @@ public class ForwardExtentCopy implements Operation {
/**
* Set whether entities that are copied should be removed.
*
* @param removing true if removing
* @param removingEntities true if removing
*/
public void setRemovingEntities(boolean removingEntities) {
this.removingEntities = removingEntities;

View File

@ -77,7 +77,7 @@ public class OperationQueue implements Operation {
@Override
public Operation resume(RunContext run) throws WorldEditException {
if (current == null && queue.size() > 0) {
if (current == null && !queue.isEmpty()) {
current = queue.poll();
}

View File

@ -26,8 +26,8 @@ public class RunContext {
/**
* Return whether the current operation should still continue running.
* </p>
* This method can be called frequently.
*
* <p>This method can be called frequently.</p>
*
* @return true if the operation should continue running
*/

View File

@ -39,9 +39,9 @@ public class RandomPattern extends AbstractPattern {
/**
* Add a pattern to the weight list of patterns.
* </p>
* The probability for the pattern added is chance / max where max is the sum
* of the probabilities of all added patterns.
*
* <p>The probability for the pattern added is chance / max where max is
* the sum of the probabilities of all added patterns.</p>
*
* @param pattern the pattern
* @param chance the chance, which can be any positive number

View File

@ -36,10 +36,10 @@ import static com.google.common.base.Preconditions.checkNotNull;
* to a certain adjacent point provided that the method
* {@link #isVisitable(com.sk89q.worldedit.Vector, com.sk89q.worldedit.Vector)}
* returns true for that point.
* </p>
* As an abstract implementation, this class can be used to implement
*
* <p>As an abstract implementation, this class can be used to implement
* functionality that starts at certain points and extends outward from
* those points.
* those points.</p>
*/
public abstract class BreadthFirstSearch implements Operation {
@ -62,12 +62,13 @@ public abstract class BreadthFirstSearch implements Operation {
/**
* Get the list of directions will be visited.
* </p>
* Directions are {@link com.sk89q.worldedit.Vector}s that determine
*
* <p>Directions are {@link com.sk89q.worldedit.Vector}s that determine
* what adjacent points area available. Vectors should not be
* unit vectors. An example of a valid direction is {@code new Vector(1, 0, 1)}.
* </p>
* The list of directions can be cleared.
* unit vectors. An example of a valid direction is
* {@code new Vector(1, 0, 1)}.</p>
*
* <p>The list of directions can be cleared.</p>
*
* @return the list of directions
*/

View File

@ -31,8 +31,8 @@ import static com.google.common.base.Preconditions.checkNotNull;
* Visits adjacent points on the same X-Z plane as long as the points
* pass the given mask, and then executes the provided region
* function on the entire column.
* </p>
* This is used by <code>//fill</code>.
*
* <p>This is used by {@code //fill}.</p>
*/
public class DownwardVisitor extends RecursiveVisitor {

View File

@ -34,11 +34,11 @@ import static com.google.common.base.Preconditions.checkNotNull;
/**
* Visits the layers within a region.
* </p>
* This class works by iterating over all the columns in a {@link FlatRegion},
*
* <p>This class works by iterating over all the columns in a {@link FlatRegion},
* finding the first ground block in each column (searching from a given
* maximum Y down to a minimum Y), and then applies a {@link LayerFunction} to
* each layer.
* each layer.</p>
*/
public class LayerVisitor implements Operation {

View File

@ -26,9 +26,9 @@ import javax.annotation.Nullable;
/**
* Provides context for undo and redo operations.
* </p>
* For example, {@link BlockChange}s take the {@link Extent} from the
* context rather than store a reference to one.
*
* <p>For example, {@link BlockChange}s take the {@link Extent} from the
* context rather than store a reference to one.</p>
*/
public class UndoContext {

View File

@ -29,10 +29,10 @@ import static com.google.common.base.Preconditions.checkNotNull;
/**
* Represents a block change that may be undone or replayed.
* </p>
* This block change does not have an {@link Extent} assigned to it because
*
* <p>This block change does not have an {@link Extent} assigned to it because
* one will be taken from the passed {@link UndoContext}. If the context
* does not have an extent (it is null), cryptic errors may occur.
* does not have an extent (it is null), cryptic errors may occur.</p>
*/
public class BlockChange implements Change {

View File

@ -36,10 +36,10 @@ import static java.util.Map.Entry;
/**
* An extension of {@link ArrayListHistory} that stores {@link BlockChange}s
* separately in two {@link ArrayList}s.
* </p>
* Whether this is a good idea or not is highly questionable, but this class
*
* <p>Whether this is a good idea or not is highly questionable, but this class
* exists because this is how history was implemented in WorldEdit for
* many years.
* many years.</p>
*/
public class BlockOptimizedHistory extends ArrayListHistory {

View File

@ -38,9 +38,9 @@ public interface ChangeSet {
/**
* Get a backward directed iterator that can be used for undo.
* </p>
* The iterator may return the changes out of order, as long as the final
* result after all changes have been applied is correct.
*
* <p>The iterator may return the changes out of order, as long as the final
* result after all changes have been applied is correct.</p>
*
* @return a undo directed iterator
*/
@ -48,9 +48,9 @@ public interface ChangeSet {
/**
* Get a forward directed iterator that can be used for redo.
* </p>
* The iterator may return the changes out of order, as long as the final
* result after all changes have been applied is correct.
*
* <p>The iterator may return the changes out of order, as long as the final
* result after all changes have been applied is correct.</p>
*
* @return a forward directed iterator
*/

View File

@ -47,6 +47,7 @@ import static com.google.common.base.Preconditions.checkNotNull;
/**
* Wraps {@link World}s into {@link LocalWorld}.
*/
@SuppressWarnings("deprecation")
public class LocalWorldAdapter extends LocalWorld {
private final World world;
@ -203,6 +204,7 @@ public class LocalWorldAdapter extends LocalWorld {
return world.getWorldData();
}
@SuppressWarnings("EqualsWhichDoesntCheckParameterClass")
@Override
public boolean equals(Object other) {
return world.equals(other);

View File

@ -37,6 +37,7 @@ import static com.google.common.base.Preconditions.checkNotNull;
/**
* Adapts {@link Platform}s into the legacy {@link ServerInterface}.
*/
@SuppressWarnings("ALL")
public class ServerInterfaceAdapter extends ServerInterface {
private final Platform platform;

View File

@ -19,7 +19,6 @@
package com.sk89q.worldedit.internal.cui;
import com.sk89q.worldedit.LocalPlayer;
import com.sk89q.worldedit.LocalSession;
import com.sk89q.worldedit.extension.platform.Actor;
@ -46,13 +45,14 @@ public interface CUIRegion {
* up-to-date data. If the CUI version is smaller than
* this value, the legacy methods will be called.
*
* @return
* @return the protocol version
*/
public int getProtocolVersion();
/**
* Returns the type ID to send to CUI in the selection event.
* @return
* Returns the type ID to send to CUI in the selection event.
*
* @return the type ID
*/
public String getTypeID();
@ -60,7 +60,7 @@ public interface CUIRegion {
* Returns the type ID to send to CUI in the selection
* event if the CUI is in legacy mode.
*
* @return
* @return the legacy type ID
*/
public String getLegacyTypeID();
}

View File

@ -34,10 +34,12 @@ public class SelectionCylinderEvent implements CUIEvent {
this.radius = radius;
}
@Override
public String getTypeId() {
return "cyl";
}
@Override
public String[] getParameters() {
return new String[] {
String.valueOf(pos.getBlockX()),

View File

@ -22,6 +22,7 @@ package com.sk89q.worldedit.internal.cui;
import com.sk89q.worldedit.Vector;
public class SelectionEllipsoidPointEvent implements CUIEvent {
protected final int id;
protected final Vector pos;
@ -30,10 +31,12 @@ public class SelectionEllipsoidPointEvent implements CUIEvent {
this.pos = pos;
}
@Override
public String getTypeId() {
return "e";
}
@Override
public String[] getParameters() {
return new String[] {
String.valueOf(id),
@ -42,4 +45,5 @@ public class SelectionEllipsoidPointEvent implements CUIEvent {
String.valueOf(pos.getBlockZ())
};
}
}

View File

@ -29,10 +29,12 @@ public class SelectionMinMaxEvent implements CUIEvent {
this.max = max;
}
@Override
public String getTypeId() {
return "mm";
}
@Override
public String[] getParameters() {
return new String[] {
String.valueOf(min),

View File

@ -43,10 +43,12 @@ public class SelectionPoint2DEvent implements CUIEvent {
this.area = area;
}
@Override
public String getTypeId() {
return "p2";
}
@Override
public String[] getParameters() {
return new String[] {
String.valueOf(id),

View File

@ -33,10 +33,12 @@ public class SelectionPointEvent implements CUIEvent {
this.area = area;
}
@Override
public String getTypeId() {
return "p";
}
@Override
public String[] getParameters() {
return new String[] {
String.valueOf(id),

View File

@ -22,16 +22,19 @@
package com.sk89q.worldedit.internal.cui;
public class SelectionPolygonEvent implements CUIEvent {
protected final int[] vertices;
public SelectionPolygonEvent(int... vertices) {
this.vertices = vertices;
}
@Override
public String getTypeId() {
return "poly";
}
@Override
public String[] getParameters() {
final String[] ret = new String[vertices.length];
@ -42,4 +45,5 @@ public class SelectionPolygonEvent implements CUIEvent {
return ret;
}
}

View File

@ -27,10 +27,12 @@ public class SelectionShapeEvent implements CUIEvent {
this.shapeName = shapeName;
}
@Override
public String getTypeId() {
return "s";
}
@Override
public String[] getParameters() {
return new String[] { shapeName };
}

View File

@ -19,47 +19,57 @@
package com.sk89q.worldedit.internal.expression;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Stack;
import com.sk89q.worldedit.internal.expression.lexer.Lexer;
import com.sk89q.worldedit.internal.expression.lexer.tokens.Token;
import com.sk89q.worldedit.internal.expression.parser.Parser;
import com.sk89q.worldedit.internal.expression.runtime.ExpressionEnvironment;
import com.sk89q.worldedit.internal.expression.runtime.Constant;
import com.sk89q.worldedit.internal.expression.runtime.EvaluationException;
import com.sk89q.worldedit.internal.expression.runtime.ExpressionEnvironment;
import com.sk89q.worldedit.internal.expression.runtime.Functions;
import com.sk89q.worldedit.internal.expression.runtime.RValue;
import com.sk89q.worldedit.internal.expression.runtime.ReturnException;
import com.sk89q.worldedit.internal.expression.runtime.Variable;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Stack;
/**
* Compiles and evaluates expressions.
*
* Supported operators:
* Logical: &&, ||, ! (unary)
* Bitwise: ~ (unary), >>, <<
* Arithmetic: +, -, *, /, % (modulo), ^ (power), - (unary), --, ++ (prefix only)
* Comparison: <=, >=, >, <, ==, !=, ~= (near)
* <p>Supported operators:</p>
*
* Supported functions: abs, acos, asin, atan, atan2, cbrt, ceil, cos, cosh, exp, floor, ln, log, log10, max, max, min, min, rint, round, sin, sinh, sqrt, tan, tanh and more. (See the Functions class or the wiki)
* <ul>
* <li>Logical: &&, ||, ! (unary)</li>
* <li>Bitwise: ~ (unary), &gt;&gt;, &lt;&lt;</li>
* <li>Arithmetic: +, -, *, /, % (modulo), ^ (power), - (unary), --, ++ (prefix only)</li>
* <li>Comparison: &lt;=, &gt;=, &gt;, &lt;, ==, !=, ~= (near)</li>
* </ul>
*
* Constants: e, pi
* <p>Supported functions: abs, acos, asin, atan, atan2, cbrt, ceil, cos, cosh,
* exp, floor, ln, log, log10, max, max, min, min, rint, round, sin, sinh,
* sqrt, tan, tanh and more. (See the Functions class or the wiki)</p>
*
* To compile an equation, run <code>Expression.compile("expression here", "var1", "var2"...)</code>
* If you wish to run the equation multiple times, you can then optimize it, by calling myExpression.optimize();
* You can then run the equation as many times as you want by calling myExpression.evaluate(var1, var2...)
* You do not need to pass values for all variables specified while compiling.
* To query variables after evaluation, you can use myExpression.getVariable("variable name").
* To get a value out of these, use myVariable.getValue()
* <p>Constants: e, pi</p>
*
* Variables are also supported and can be set either by passing values to <code>evaluate</code>
* <p>To compile an equation, run
* {@code Expression.compile("expression here", "var1", "var2"...)}.
* If you wish to run the equation multiple times, you can then optimize it,
* by calling {@link #optimize()}. You can then run the equation as many times
* as you want by calling {@link #evaluate(double...)}. You do not need to
* pass values for all variables specified while compiling.
* To query variables after evaluation, you can use
* {@link #getVariable(String, boolean)}. To get a value out of these, use
* {@link Variable#getValue()}.</p>
*
* <p>Variables are also supported and can be set either by passing values
* to {@link #evaluate(double...)}.</p>
*
* @author TomyLobo
*/
public class Expression {
private static final ThreadLocal<Stack<Expression>> instance = new ThreadLocal<Stack<Expression>>();
private final Map<String, RValue> variables = new HashMap<String, RValue>();
@ -167,4 +177,5 @@ public class Expression {
public void setEnvironment(ExpressionEnvironment environment) {
this.environment = environment;
}
}

View File

@ -20,12 +20,10 @@
package com.sk89q.worldedit.internal.expression;
/**
* Thrown when there's a problem during any stage of the expression compilation or evaluation.
*
* @author TomyLobo
* Thrown when there's a problem during any stage of the expression
* compilation or evaluation.
*/
public class ExpressionException extends Exception {
private static final long serialVersionUID = 1L;
private final int position;
@ -51,4 +49,5 @@ public class ExpressionException extends Exception {
public int getPosition() {
return position;
}
}

View File

@ -21,10 +21,9 @@ package com.sk89q.worldedit.internal.expression;
/**
* A common superinterface for everything passed to parser processors.
*
* @author TomyLobo
*/
public interface Identifiable {
/**
* Returns a character that helps identify the token, pseudo-token or invokable in question.
*
@ -58,4 +57,5 @@ public interface Identifiable {
public abstract char id();
public int getPosition();
}

View File

@ -19,6 +19,13 @@
package com.sk89q.worldedit.internal.expression.lexer;
import com.sk89q.worldedit.internal.expression.lexer.tokens.CharacterToken;
import com.sk89q.worldedit.internal.expression.lexer.tokens.IdentifierToken;
import com.sk89q.worldedit.internal.expression.lexer.tokens.KeywordToken;
import com.sk89q.worldedit.internal.expression.lexer.tokens.NumberToken;
import com.sk89q.worldedit.internal.expression.lexer.tokens.OperatorToken;
import com.sk89q.worldedit.internal.expression.lexer.tokens.Token;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
@ -29,16 +36,14 @@ import java.util.Set;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import com.sk89q.worldedit.internal.expression.lexer.tokens.*;
/**
* Processes a string into a list of tokens.
*
* Tokens can be numbers, identifiers, operators and assorted other characters.
*
* @author TomyLobo
* <p>Tokens can be numbers, identifiers, operators and assorted other
* characters.</p>
*/
public class Lexer {
private final String expression;
private int position = 0;
@ -46,7 +51,7 @@ public class Lexer {
this.expression = expression;
}
public static final List<Token> tokenize(String expression) throws LexerException {
public static List<Token> tokenize(String expression) throws LexerException {
return new Lexer(expression).tokenize();
}
@ -114,7 +119,7 @@ public class Lexer {
private static final Pattern numberPattern = Pattern.compile("^([0-9]*(?:\\.[0-9]+)?(?:[eE][+-]?[0-9]+)?)");
private static final Pattern identifierPattern = Pattern.compile("^([A-Za-z][0-9A-Za-z_]*)");
private final List<Token> tokenize() throws LexerException {
private List<Token> tokenize() throws LexerException {
List<Token> tokens = new ArrayList<Token>();
do {
@ -139,7 +144,7 @@ public class Lexer {
final Matcher numberMatcher = numberPattern.matcher(expression.substring(position));
if (numberMatcher.lookingAt()) {
String numberPart = numberMatcher.group(1);
if (numberPart.length() > 0) {
if (!numberPart.isEmpty()) {
try {
tokens.add(new NumberToken(position, Double.parseDouble(numberPart)));
} catch (NumberFormatException e) {
@ -154,7 +159,7 @@ public class Lexer {
final Matcher identifierMatcher = identifierPattern.matcher(expression.substring(position));
if (identifierMatcher.lookingAt()) {
String identifierPart = identifierMatcher.group(1);
if (identifierPart.length() > 0) {
if (!identifierPart.isEmpty()) {
if (keywords.contains(identifierPart)) {
tokens.add(new KeywordToken(position, identifierPart));
} else {
@ -176,7 +181,7 @@ public class Lexer {
return expression.charAt(position);
}
private final void skipWhitespace() {
private void skipWhitespace() {
while (position < expression.length() && Character.isWhitespace(peek())) {
++position;
}
@ -230,4 +235,5 @@ public class Lexer {
return new OperatorToken(startPosition, tokenName);
}
}
}

View File

@ -23,11 +23,8 @@ import com.sk89q.worldedit.internal.expression.ExpressionException;
/**
* Thrown when the lexer encounters a problem.
*
* @author TomyLobo
*/
public class LexerException extends ExpressionException {
private static final long serialVersionUID = 1L;
public LexerException(int position) {
super(position, getPrefix(position));
@ -48,4 +45,5 @@ public class LexerException extends ExpressionException {
private static String getPrefix(int position) {
return position < 0 ? "Lexer error" : ("Lexer error at " + (position + 1));
}
}

View File

@ -21,10 +21,9 @@ package com.sk89q.worldedit.internal.expression.lexer.tokens;
/**
* A single character that doesn't fit any of the other token categories.
*
* @author TomyLobo
*/
public class CharacterToken extends Token {
public final char character;
public CharacterToken(int position, char character) {
@ -41,4 +40,5 @@ public class CharacterToken extends Token {
public String toString() {
return "CharacterToken(" + character + ")";
}
}

View File

@ -20,11 +20,10 @@
package com.sk89q.worldedit.internal.expression.lexer.tokens;
/**
* An identifier
*
* @author TomyLobo
* An identifier.
*/
public class IdentifierToken extends Token {
public final String value;
public IdentifierToken(int position, String value) {
@ -41,4 +40,5 @@ public class IdentifierToken extends Token {
public String toString() {
return "IdentifierToken(" + value + ")";
}
}

View File

@ -20,11 +20,10 @@
package com.sk89q.worldedit.internal.expression.lexer.tokens;
/**
* A keyword
*
* @author TomyLobo
* A keyword.
*/
public class KeywordToken extends Token {
public final String value;
public KeywordToken(int position, String value) {
@ -41,4 +40,5 @@ public class KeywordToken extends Token {
public String toString() {
return "KeywordToken(" + value + ")";
}
}

View File

@ -20,11 +20,10 @@
package com.sk89q.worldedit.internal.expression.lexer.tokens;
/**
* A number
*
* @author TomyLobo
* A number.
*/
public class NumberToken extends Token {
public final double value;
public NumberToken(int position, double value) {
@ -41,4 +40,5 @@ public class NumberToken extends Token {
public String toString() {
return "NumberToken(" + value + ")";
}
}

View File

@ -21,10 +21,9 @@ package com.sk89q.worldedit.internal.expression.lexer.tokens;
/**
* A unary or binary operator.
*
* @author TomyLobo
*/
public class OperatorToken extends Token {
public final String operator;
public OperatorToken(int position, String operator) {
@ -41,4 +40,5 @@ public class OperatorToken extends Token {
public String toString() {
return "OperatorToken(" + operator + ")";
}
}

View File

@ -23,10 +23,9 @@ import com.sk89q.worldedit.internal.expression.Identifiable;
/**
* A token. The lexer generates these to make the parser's job easier.
*
* @author TomyLobo
*/
public abstract class Token implements Identifiable {
private final int position;
public Token(int position) {
@ -37,4 +36,5 @@ public abstract class Token implements Identifiable {
public int getPosition() {
return position;
}
}

View File

@ -19,9 +19,6 @@
package com.sk89q.worldedit.internal.expression.parser;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import com.sk89q.worldedit.internal.expression.Expression;
import com.sk89q.worldedit.internal.expression.Identifiable;
import com.sk89q.worldedit.internal.expression.lexer.tokens.IdentifierToken;
@ -43,12 +40,14 @@ import com.sk89q.worldedit.internal.expression.runtime.SimpleFor;
import com.sk89q.worldedit.internal.expression.runtime.Switch;
import com.sk89q.worldedit.internal.expression.runtime.While;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
/**
* Processes a list of tokens into an executable tree.
*
* Tokens can be numbers, identifiers, operators and assorted other characters.
*
* @author TomyLobo
* <p>Tokens can be numbers, identifiers, operators and assorted other characters.</p>
*/
public class Parser {
private final class NullToken extends Token {
@ -56,6 +55,7 @@ public class Parser {
super(position);
}
@Override
public char id() {
return '\0';
}
@ -75,7 +75,7 @@ public class Parser {
this.expression = expression;
}
public static final RValue parse(List<Token> tokens, Expression expression) throws ParserException {
public static RValue parse(List<Token> tokens, Expression expression) throws ParserException {
return new Parser(tokens, expression).parse();
}
@ -309,7 +309,7 @@ public class Parser {
}
}
private final RValue parseExpression(boolean canBeEmpty) throws ParserException {
private RValue parseExpression(boolean canBeEmpty) throws ParserException {
LinkedList<Identifiable> halfProcessed = new LinkedList<Identifiable>();
// process brackets, numbers, functions, variables and detect prefix operators
@ -423,7 +423,7 @@ public class Parser {
}
}
private final RValue parseBracket() throws ParserException {
private RValue parseBracket() throws ParserException {
consumeCharacter('(');
final RValue ret = parseExpression(false);
@ -435,10 +435,8 @@ public class Parser {
private boolean hasKeyword(String keyword) {
final Token next = peek();
if (!(next instanceof KeywordToken)) {
return false;
}
return ((KeywordToken) next).value.equals(keyword);
return next instanceof KeywordToken && ((KeywordToken) next).value.equals(keyword);
}
private void assertCharacter(char character) throws ParserException {

View File

@ -23,11 +23,8 @@ import com.sk89q.worldedit.internal.expression.ExpressionException;
/**
* Thrown when the parser encounters a problem.
*
* @author TomyLobo
*/
public class ParserException extends ExpressionException {
private static final long serialVersionUID = 1L;
public ParserException(int position) {
super(position, getPrefix(position));
@ -48,4 +45,5 @@ public class ParserException extends ExpressionException {
private static String getPrefix(int position) {
return position < 0 ? "Parser error" : ("Parser error at " + (position + 1));
}
}

View File

@ -30,10 +30,9 @@ import java.util.*;
/**
* Helper classfor Parser. Contains processors for statements and operators.
*
* @author TomyLobo
*/
public final class ParserProcessors {
private static final Map<String, String> unaryOpMap = new HashMap<String, String>();
private static final Map<String, String>[] binaryOpMapsLA;
@ -347,4 +346,5 @@ public final class ParserProcessors {
}
return ret;
}
}

View File

@ -23,10 +23,9 @@ import com.sk89q.worldedit.internal.expression.Identifiable;
/**
* A pseudo-token, inserted by the parser instead of the lexer.
*
* @author TomyLobo
*/
public abstract class PseudoToken implements Identifiable {
private final int position;
public PseudoToken(int position) {
@ -40,4 +39,5 @@ public abstract class PseudoToken implements Identifiable {
public int getPosition() {
return position;
}
}

View File

@ -23,10 +23,9 @@ import com.sk89q.worldedit.internal.expression.lexer.tokens.OperatorToken;
/**
* The parser uses this pseudo-token to mark operators as unary operators.
*
* @author TomyLobo
*/
public class UnaryOperator extends PseudoToken {
final String operator;
public UnaryOperator(OperatorToken operatorToken) {
@ -47,4 +46,5 @@ public class UnaryOperator extends PseudoToken {
public String toString() {
return "UnaryOperator(" + operator + ")";
}
}

View File

@ -25,17 +25,16 @@ import com.sk89q.worldedit.internal.expression.runtime.LValue;
import com.sk89q.worldedit.internal.expression.runtime.RValue;
public class UnboundVariable extends PseudoToken implements LValue {
public final String name;
public UnboundVariable(int position, String name) {
super(position);
this.name = name;
// TODO Auto-generated constructor stub
}
@Override
public char id() {
// TODO Auto-generated method stub
return 'V';
}
@ -77,4 +76,5 @@ public class UnboundVariable extends PseudoToken implements LValue {
return (LValue) variable;
}
}

View File

@ -21,10 +21,9 @@ package com.sk89q.worldedit.internal.expression.runtime;
/**
* A break or continue statement.
*
* @author TomyLobo
*/
public class Break extends Node {
boolean doContinue;
public Break(int position, boolean doContinue) {
@ -47,4 +46,5 @@ public class Break extends Node {
public String toString() {
return doContinue ? "continue" : "break";
}
}

View File

@ -22,11 +22,8 @@ package com.sk89q.worldedit.internal.expression.runtime;
/**
* Thrown when a break or continue is encountered.
* Loop constructs catch this exception.
*
* @author TomyLobo
*/
public class BreakException extends EvaluationException {
private static final long serialVersionUID = 1L;
final boolean doContinue;
@ -35,4 +32,5 @@ public class BreakException extends EvaluationException {
this.doContinue = doContinue;
}
}

View File

@ -24,10 +24,9 @@ import com.sk89q.worldedit.internal.expression.parser.ParserException;
/**
* An if/else statement or a ternary operator.
*
* @author TomyLobo
*/
public class Conditional extends Node {
private RValue condition;
private RValue truePart;
private RValue falsePart;
@ -90,4 +89,5 @@ public class Conditional extends Node {
return this;
}
}

View File

@ -21,10 +21,9 @@ package com.sk89q.worldedit.internal.expression.runtime;
/**
* A constant.
*
* @author TomyLobo
*/
public final class Constant extends Node {
private final double value;
public Constant(int position, double value) {
@ -46,4 +45,5 @@ public final class Constant extends Node {
public char id() {
return 'c';
}
}

View File

@ -23,11 +23,8 @@ import com.sk89q.worldedit.internal.expression.ExpressionException;
/**
* Thrown when there's a problem during expression evaluation.
*
* @author TomyLobo
*/
public class EvaluationException extends ExpressionException {
private static final long serialVersionUID = 1L;
public EvaluationException(int position) {
super(position, getPrefix(position));
@ -48,4 +45,5 @@ public class EvaluationException extends ExpressionException {
private static String getPrefix(int position) {
return position < 0 ? "Evaluation error" : ("Evaluation error at " + (position + 1));
}
}

View File

@ -23,10 +23,12 @@ package com.sk89q.worldedit.internal.expression.runtime;
* Represents a way to access blocks in a world. Has to accept non-rounded coordinates.
*/
public interface ExpressionEnvironment {
int getBlockType(double x, double y, double z);
int getBlockData(double x, double y, double z);
int getBlockTypeAbs(double x, double y, double z);
int getBlockDataAbs(double x, double y, double z);
int getBlockTypeRel(double x, double y, double z);
int getBlockDataRel(double x, double y, double z);
}

View File

@ -24,10 +24,9 @@ import com.sk89q.worldedit.internal.expression.parser.ParserException;
/**
* A Java/C-style for loop.
*
* @author TomyLobo
*/
public class For extends Node {
RValue init;
RValue condition;
RValue increment;
@ -101,4 +100,5 @@ public class For extends Node {
return this;
}
}

View File

@ -19,20 +19,19 @@
package com.sk89q.worldedit.internal.expression.runtime;
import com.sk89q.worldedit.internal.expression.Expression;
import com.sk89q.worldedit.internal.expression.parser.ParserException;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import com.sk89q.worldedit.internal.expression.Expression;
import com.sk89q.worldedit.internal.expression.parser.ParserException;
/**
* Wrapper for a Java method and its arguments (other Nodes)
*
* @author TomyLobo
* Wrapper for a Java method and its arguments (other Nodes).
*/
public class Function extends Node {
/**
* Add this annotation on functions that don't always return the same value
* for the same inputs and on functions with side-effects.
@ -120,4 +119,5 @@ public class Function extends Node {
return this;
}
}

View File

@ -27,17 +27,16 @@ import java.util.*;
/**
* Contains all functions that can be used in expressions.
*
* @author TomyLobo
*/
@SuppressWarnings("UnusedDeclaration")
public final class Functions {
private static class Overload {
private final Method method;
private final int mask;
private final boolean isSetter;
public Overload(Method method) throws IllegalArgumentException {
private Overload(Method method) throws IllegalArgumentException {
this.method = method;
boolean isSetter = false;
@ -436,4 +435,5 @@ public final class Functions {
return queryInternal(type, data, typeId, dataValue);
}
}

View File

@ -24,13 +24,15 @@ import com.sk89q.worldedit.internal.expression.parser.ParserException;
/**
* A value that can be used on the left side of an assignment.
*
* @author TomyLobo
*/
public interface LValue extends RValue {
public double assign(double value) throws EvaluationException;
@Override
public LValue optimize() throws EvaluationException;
@Override
public LValue bindVariables(Expression expression, boolean preferLValue) throws ParserException;
}

View File

@ -19,17 +19,17 @@
package com.sk89q.worldedit.internal.expression.runtime;
import java.lang.reflect.Method;
import com.sk89q.worldedit.internal.expression.Expression;
import com.sk89q.worldedit.internal.expression.parser.ParserException;
import java.lang.reflect.Method;
/**
* Wrapper for a pair of Java methods and their arguments (other Nodes), forming an LValue
*
* @author TomyLobo
* Wrapper for a pair of Java methods and their arguments (other Nodes),
* forming an LValue.
*/
public class LValueFunction extends Function implements LValue {
private final Object[] setterArgs;
private final Method setter;
@ -73,4 +73,5 @@ public class LValueFunction extends Function implements LValue {
return this;
}
}

View File

@ -24,10 +24,9 @@ import com.sk89q.worldedit.internal.expression.parser.ParserException;
/**
* A node in the execution tree of an expression.
*
* @author TomyLobo
*/
public abstract class Node implements RValue {
private final int position;
public Node(int position) {
@ -37,6 +36,7 @@ public abstract class Node implements RValue {
@Override
public abstract String toString();
@Override
public RValue optimize() throws EvaluationException {
return this;
}
@ -50,4 +50,5 @@ public abstract class Node implements RValue {
public RValue bindVariables(Expression expression, boolean preferLValue) throws ParserException {
return this;
}
}

View File

@ -21,11 +21,10 @@ package com.sk89q.worldedit.internal.expression.runtime;
/**
* Contains all unary and binary operators.
*
* @author TomyLobo
*/
@SuppressWarnings("UnusedDeclaration")
public final class Operators {
private Operators() {
}
@ -225,4 +224,5 @@ public final class Operators {
final long longDiff = Math.abs(aLong - bLong);
return longDiff <= maxUlps;
}
}

View File

@ -25,13 +25,13 @@ import com.sk89q.worldedit.internal.expression.parser.ParserException;
/**
* A value that can be used on the right side of an assignment.
*
* @author TomyLobo
*/
public interface RValue extends Identifiable {
public double getValue() throws EvaluationException;
public RValue optimize() throws EvaluationException;
public RValue bindVariables(Expression expression, boolean preferLValue) throws ParserException;
}

View File

@ -24,10 +24,9 @@ import com.sk89q.worldedit.internal.expression.parser.ParserException;
/**
* A return statement.
*
* @author TomyLobo
*/
public class Return extends Node {
RValue value;
public Return(int position, RValue value) {
@ -57,4 +56,5 @@ public class Return extends Node {
return this;
}
}

View File

@ -21,12 +21,10 @@ package com.sk89q.worldedit.internal.expression.runtime;
/**
* Thrown when a return statement is encountered.
* {@link com.sk89q.worldedit.internal.expression.Expression#evaluate} catches this exception and returns the enclosed value.
*
* @author TomyLobo
* {@link com.sk89q.worldedit.internal.expression.Expression#evaluate}
* catches this exception and returns the enclosed value.
*/
public class ReturnException extends EvaluationException {
private static final long serialVersionUID = 1L;
final double value;
@ -39,4 +37,5 @@ public class ReturnException extends EvaluationException {
public double getValue() {
return value;
}
}

View File

@ -19,18 +19,19 @@
package com.sk89q.worldedit.internal.expression.runtime;
import java.util.ArrayList;
import java.util.List;
import com.sk89q.worldedit.internal.expression.Expression;
import com.sk89q.worldedit.internal.expression.parser.ParserException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
/**
* A sequence of operations, usually separated by semicolons in the input stream.
*
* @author TomyLobo
* A sequence of operations, usually separated by semicolons in the
* input stream.
*/
public class Sequence extends Node {
final RValue[] sequence;
public Sequence(int position, RValue... sequence) {
@ -77,9 +78,7 @@ public class Sequence extends Node {
droppedLast = null;
invokable = invokable.optimize();
if (invokable instanceof Sequence) {
for (RValue subInvokable : ((Sequence) invokable).sequence) {
newSequence.add(subInvokable);
}
Collections.addAll(newSequence, ((Sequence) invokable).sequence);
} else if (invokable instanceof Constant) {
droppedLast = invokable;
} else {
@ -106,4 +105,5 @@ public class Sequence extends Node {
return this;
}
}

View File

@ -24,10 +24,9 @@ import com.sk89q.worldedit.internal.expression.parser.ParserException;
/**
* A simple-style for loop.
*
* @author TomyLobo
*/
public class SimpleFor extends Node {
LValue counter;
RValue first;
RValue last;
@ -98,4 +97,5 @@ public class SimpleFor extends Node {
return this;
}
}

View File

@ -19,6 +19,9 @@
package com.sk89q.worldedit.internal.expression.runtime;
import com.sk89q.worldedit.internal.expression.Expression;
import com.sk89q.worldedit.internal.expression.parser.ParserException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
@ -26,15 +29,11 @@ import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import com.sk89q.worldedit.internal.expression.Expression;
import com.sk89q.worldedit.internal.expression.parser.ParserException;
/**
* A switch/case construct.
*
* @author TomyLobo
*/
public class Switch extends Node implements RValue {
private RValue parameter;
private final Map<Double, Integer> valueMap;
private final RValue[] caseStatements;
@ -205,4 +204,5 @@ public class Switch extends Node implements RValue {
return this;
}
}

View File

@ -24,10 +24,9 @@ import com.sk89q.worldedit.internal.expression.parser.ParserException;
/**
* A variable.
*
* @author TomyLobo
*/
public final class Variable extends Node implements LValue {
public double value;
public Variable(double value) {
@ -64,4 +63,5 @@ public final class Variable extends Node implements LValue {
public LValue bindVariables(Expression expression, boolean preferLValue) throws ParserException {
return this;
}
}

View File

@ -24,10 +24,9 @@ import com.sk89q.worldedit.internal.expression.parser.ParserException;
/**
* A while loop.
*
* @author TomyLobo
*/
public class While extends Node {
RValue condition;
RValue body;
boolean footChecked;
@ -124,4 +123,5 @@ public class While extends Node {
return this;
}
}

View File

@ -33,7 +33,9 @@ import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
@SuppressWarnings("UseOfSystemOutOrSystemErr")
public final class DocumentationPrinter {
private DocumentationPrinter() {
}
@ -191,7 +193,6 @@ public final class DocumentationPrinter {
}
private static void writeBukkitYAML(PrintStream stream) {
stream.println("name: WorldEdit");
stream.println("main: com.sk89q.worldedit.bukkit.WorldEditPlugin");
stream.println("version: ${project.version}");
@ -202,4 +203,5 @@ public final class DocumentationPrinter {
stream.println("# Permissions aren't here. Read http://wiki.sk89q.com/wiki/WEPIF/DinnerPerms");
stream.println("# for how WorldEdit permissions actually work.");
}
}

View File

@ -26,10 +26,10 @@ public final class MathUtils {
/**
* Safe minimum, such that 1 / SAFE_MIN does not overflow.
* <p>
* In IEEE 754 arithmetic, this is also the smallest normalized number
*
* <p>In IEEE 754 arithmetic, this is also the smallest normalized number
* 2<sup>-1022</sup>. The value of this constant is from Apache Commons
* Math 2.2.
* Math 2.2.</p>
*/
public static final double SAFE_MIN = 0x1.0p-1022;

View File

@ -22,11 +22,8 @@ package com.sk89q.worldedit.math.convolution;
import java.awt.image.Kernel;
/**
* A Gaussian Kernel generator (2D bellcurve)
*
* @author Grum
* A Gaussian Kernel generator (2D bellcurve).
*/
public class GaussianKernel extends Kernel {
/**
@ -35,7 +32,6 @@ public class GaussianKernel extends Kernel {
* @param radius the resulting diameter will be radius * 2 + 1
* @param sigma controls 'flatness'
*/
public GaussianKernel(int radius, double sigma) {
super(radius * 2 + 1, radius * 2 + 1, createKernel(radius, sigma));
}
@ -54,4 +50,5 @@ public class GaussianKernel extends Kernel {
return data;
}
}

View File

@ -26,14 +26,15 @@ import com.sk89q.worldedit.blocks.BaseBlock;
import com.sk89q.worldedit.blocks.BlockID;
import com.sk89q.worldedit.regions.Region;
/**
* Allows applications of Kernels onto the region's heightmap.
* Currently only used for smoothing (with a GaussianKernel).
*
* @author Grum
*/
import static com.google.common.base.Preconditions.checkNotNull;
/**
* Allows applications of Kernels onto the region's height map.
*
* <p>Currently only used for smoothing (with a GaussianKernel)</p>.
*/
public class HeightMap {
private int[] data;
private int width;
private int height;
@ -44,8 +45,8 @@ public class HeightMap {
/**
* Constructs the HeightMap
*
* @param session
* @param region
* @param session an edit session
* @param region the region
*/
public HeightMap(EditSession session, Region region) {
this(session, region, false);
@ -53,12 +54,15 @@ public class HeightMap {
/**
* Constructs the HeightMap
*
* @param session
* @param region
*
* @param session an edit session
* @param region the region
* @param naturalOnly ignore non-natural blocks
*/
public HeightMap(EditSession session, Region region, boolean naturalOnly) {
checkNotNull(session);
checkNotNull(region);
this.session = session;
this.region = region;
@ -82,13 +86,15 @@ public class HeightMap {
/**
* Apply the filter 'iterations' amount times.
*
* @param filter
* @param iterations
* @param filter the filter
* @param iterations the number of iterations
* @return number of blocks affected
* @throws MaxChangedBlocksException
*/
public int applyFilter(HeightMapFilter filter, int iterations) throws MaxChangedBlocksException {
checkNotNull(filter);
int[] newData = new int[data.length];
System.arraycopy(data, 0, newData, 0, data.length);
@ -102,12 +108,14 @@ public class HeightMap {
/**
* Apply a raw heightmap to the region
*
* @param data
* @param data the data
* @return number of blocks affected
* @throws MaxChangedBlocksException
*/
public int apply(int[] data) throws MaxChangedBlocksException {
checkNotNull(data);
Vector minY = region.getMinimumPoint();
int originX = minY.getBlockX();
int originY = minY.getBlockY();
@ -178,4 +186,5 @@ public class HeightMap {
return blocksChanged;
}
}

View File

@ -21,33 +21,36 @@ package com.sk89q.worldedit.math.convolution;
import java.awt.image.Kernel;
/**
* Allows applications of Kernels onto the region's heightmap.
* Only used for smoothing (with a GaussianKernel).
*
* @author Grum
*/
import static com.google.common.base.Preconditions.checkNotNull;
/**
* Allows applications of Kernels onto the region's height map.
*
* <p>Only used for smoothing (with a GaussianKernel).</p>
*/
public class HeightMapFilter {
private Kernel kernel;
/**
* Construct the HeightMapFilter object.
*
* @param kernel
* @param kernel the kernel
*/
public HeightMapFilter(Kernel kernel) {
checkNotNull(kernel);
this.kernel = kernel;
}
/**
* Construct the HeightMapFilter object.
*
* @param kernelWidth
* @param kernelHeight
* @param kernelData
* @param kernelWidth the width
* @param kernelHeight the height
* @param kernelData the data
*/
public HeightMapFilter(int kernelWidth, int kernelHeight, float[] kernelData) {
checkNotNull(kernelData);
this.kernel = new Kernel(kernelWidth, kernelHeight, kernelData);
}
@ -61,21 +64,26 @@ public class HeightMapFilter {
/**
* Set Kernel
*
* @param kernel
* @param kernel the kernel
*/
public void setKernel(Kernel kernel) {
checkNotNull(kernel);
this.kernel = kernel;
}
/**
* Filter with a 2D kernel
*
* @param inData
* @param width
* @param height
* @return the modified heightmap
*
* @param inData the data
* @param width the width
* @param height the height
*
* @return the modified height map
*/
public int[] filter(int[] inData, int width, int height) {
checkNotNull(inData);
int index = 0;
float[] matrix = kernel.getKernelData(null);
int[] outData = new int[inData.length];
@ -117,4 +125,5 @@ public class HeightMapFilter {
}
return outData;
}
}

View File

@ -23,10 +23,7 @@ import java.awt.image.Kernel;
/**
* A linear Kernel generator (all cells weight the same)
*
* @author Grum
*/
public class LinearKernel extends Kernel {
public LinearKernel(int radius) {
@ -37,8 +34,9 @@ public class LinearKernel extends Kernel {
int diameter = radius * 2 + 1;
float[] data = new float[diameter * diameter];
for (int i = 0; i < data.length; data[i++] = 1.0f / data.length) ;
for (int i = 0; i < data.length; data[i++] = 1.0f / data.length);
return data;
}
}

Some files were not shown because too many files have changed in this diff Show More