geforkt von Mirrors/Paper
Added Block.getPistonMoveReaction, BlockPistonExtend and BlockPistonRetractEvent
By: Erik Broes <erikbroes@grum.nl>
Dieser Commit ist enthalten in:
Ursprung
402794beff
Commit
86ab32254f
@ -66,6 +66,15 @@ public interface Block {
|
|||||||
*/
|
*/
|
||||||
Block getRelative(BlockFace face);
|
Block getRelative(BlockFace face);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the block at the given offsets
|
||||||
|
*
|
||||||
|
* @param face face
|
||||||
|
* @param distance distance
|
||||||
|
* @return Block at the given offset and distance
|
||||||
|
*/
|
||||||
|
Block getRelative(BlockFace face, int distance);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the type of this block
|
* Gets the type of this block
|
||||||
*
|
*
|
||||||
@ -268,4 +277,11 @@ public interface Block {
|
|||||||
* @return Humidity of this block
|
* @return Humidity of this block
|
||||||
*/
|
*/
|
||||||
double getHumidity();
|
double getHumidity();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the reaction of the block when moved by a piston
|
||||||
|
*
|
||||||
|
* @return reaction
|
||||||
|
*/
|
||||||
|
PistonMoveReaction getPistonMoveReaction();
|
||||||
}
|
}
|
||||||
|
30
paper-api/src/main/java/org/bukkit/block/PistonMoveReaction.java
Normale Datei
30
paper-api/src/main/java/org/bukkit/block/PistonMoveReaction.java
Normale Datei
@ -0,0 +1,30 @@
|
|||||||
|
package org.bukkit.block;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
public enum PistonMoveReaction {
|
||||||
|
MOVE(0),
|
||||||
|
BREAK(1),
|
||||||
|
BLOCK(2);
|
||||||
|
|
||||||
|
private int id;
|
||||||
|
private static Map<Integer, PistonMoveReaction> byId = new HashMap<Integer, PistonMoveReaction>();
|
||||||
|
static {
|
||||||
|
for (PistonMoveReaction reaction: PistonMoveReaction.values()) {
|
||||||
|
byId.put(reaction.id, reaction);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private PistonMoveReaction(int id) {
|
||||||
|
this.id = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getId() {
|
||||||
|
return this.id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static PistonMoveReaction getById(int id) {
|
||||||
|
return byId.get(id);
|
||||||
|
}
|
||||||
|
}
|
@ -1,6 +1,19 @@
|
|||||||
package org.bukkit.event;
|
package org.bukkit.event;
|
||||||
|
|
||||||
public interface Cancellable {
|
public interface Cancellable {
|
||||||
|
/**
|
||||||
|
* Gets the cancellation state of this event. A cancelled event will not
|
||||||
|
* be executed in the server, but will still pass to other plugins
|
||||||
|
*
|
||||||
|
* @return true if this event is cancelled
|
||||||
|
*/
|
||||||
public boolean isCancelled();
|
public boolean isCancelled();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the cancellation state of this event. A cancelled event will not
|
||||||
|
* be executed in the server, but will still pass to other plugins.
|
||||||
|
*
|
||||||
|
* @param cancel true if you wish to cancel this event
|
||||||
|
*/
|
||||||
public void setCancelled(boolean cancel);
|
public void setCancelled(boolean cancel);
|
||||||
}
|
}
|
||||||
|
@ -404,6 +404,18 @@ public abstract class Event implements Serializable {
|
|||||||
* @see org.bukkit.event.block.BlockFadeEvent
|
* @see org.bukkit.event.block.BlockFadeEvent
|
||||||
*/
|
*/
|
||||||
BLOCK_FADE (Category.BLOCK),
|
BLOCK_FADE (Category.BLOCK),
|
||||||
|
/**
|
||||||
|
* Called when a piston extends
|
||||||
|
*
|
||||||
|
* @see org.bukkit.event.block.PistonExtendEvent
|
||||||
|
*/
|
||||||
|
BLOCK_PISTON_EXTEND (Category.BLOCK),
|
||||||
|
/**
|
||||||
|
* Called when a piston retracts
|
||||||
|
*
|
||||||
|
* @see org.bukkit.event.block.PistonRetractEvent
|
||||||
|
*/
|
||||||
|
BLOCK_PISTON_RETRACT (Category.BLOCK),
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* INVENTORY EVENTS
|
* INVENTORY EVENTS
|
||||||
|
@ -183,4 +183,18 @@ public class BlockListener implements Listener {
|
|||||||
* @param event Relevant event details
|
* @param event Relevant event details
|
||||||
*/
|
*/
|
||||||
public void onBlockDispense(BlockDispenseEvent event) {}
|
public void onBlockDispense(BlockDispenseEvent event) {}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Called when a piston retracts
|
||||||
|
*
|
||||||
|
* @param event Relevant event details
|
||||||
|
*/
|
||||||
|
public void onBlockPistonRetract(BlockPistonRetractEvent event) {}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Called when a piston extends
|
||||||
|
*
|
||||||
|
* @param event Relevant event details
|
||||||
|
*/
|
||||||
|
public void onBlockPistonExtend(BlockPistonExtendEvent event) {}
|
||||||
}
|
}
|
||||||
|
43
paper-api/src/main/java/org/bukkit/event/block/BlockPistonEvent.java
Normale Datei
43
paper-api/src/main/java/org/bukkit/event/block/BlockPistonEvent.java
Normale Datei
@ -0,0 +1,43 @@
|
|||||||
|
package org.bukkit.event.block;
|
||||||
|
|
||||||
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.block.Block;
|
||||||
|
import org.bukkit.block.BlockFace;
|
||||||
|
import org.bukkit.event.Cancellable;
|
||||||
|
import org.bukkit.material.PistonBaseMaterial;
|
||||||
|
|
||||||
|
public abstract class BlockPistonEvent extends BlockEvent implements Cancellable {
|
||||||
|
private boolean cancelled;
|
||||||
|
|
||||||
|
public BlockPistonEvent(Type type, Block block) {
|
||||||
|
super(type, block);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isCancelled() {
|
||||||
|
return this.cancelled;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCancelled(boolean cancelled) {
|
||||||
|
this.cancelled = cancelled;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns true if the Piston in the event is sticky.
|
||||||
|
*
|
||||||
|
* @return stickiness of the piston
|
||||||
|
*/
|
||||||
|
public boolean isSticky() {
|
||||||
|
return block.getType() == Material.PISTON_STICKY_BASE;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return the direction in which the piston will operate.
|
||||||
|
*
|
||||||
|
* @return direction of the piston
|
||||||
|
*/
|
||||||
|
public BlockFace getDirection() {
|
||||||
|
// Both are meh!
|
||||||
|
// return ((PistonBaseMaterial) block.getType().getNewData(block.getData ())).getFacing();
|
||||||
|
return ((PistonBaseMaterial) block.getState().getData()).getFacing();
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,43 @@
|
|||||||
|
package org.bukkit.event.block;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.bukkit.block.Block;
|
||||||
|
|
||||||
|
public class BlockPistonExtendEvent extends BlockPistonEvent {
|
||||||
|
private int length;
|
||||||
|
private List<Block> blocks;
|
||||||
|
|
||||||
|
public BlockPistonExtendEvent(Block block, int length) {
|
||||||
|
super(Type.BLOCK_PISTON_EXTEND, block);
|
||||||
|
|
||||||
|
this.length = length;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the amount of blocks which will be moved while extending.
|
||||||
|
*
|
||||||
|
* @return the amount of moving blocks
|
||||||
|
*/
|
||||||
|
public int getLength() {
|
||||||
|
return this.length;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get an immutable list of the blocks which will be moved by the extending.
|
||||||
|
*
|
||||||
|
* @return Immutable list of the moved blocks.
|
||||||
|
*/
|
||||||
|
public List<Block> getBlocks() {
|
||||||
|
if (blocks == null) {
|
||||||
|
ArrayList<Block> tmp = new ArrayList<Block>();
|
||||||
|
for (int i = 0; i < this.getLength(); i++) {
|
||||||
|
tmp.add(block.getRelative(getDirection(), i + 1));
|
||||||
|
}
|
||||||
|
blocks = Collections.unmodifiableList(tmp);
|
||||||
|
}
|
||||||
|
return blocks;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,20 @@
|
|||||||
|
package org.bukkit.event.block;
|
||||||
|
|
||||||
|
import org.bukkit.Location;
|
||||||
|
import org.bukkit.block.Block;
|
||||||
|
|
||||||
|
public class BlockPistonRetractEvent extends BlockPistonEvent {
|
||||||
|
public BlockPistonRetractEvent(Block block) {
|
||||||
|
super(Type.BLOCK_PISTON_RETRACT, block);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the location where the possible moving block might be if the retracting
|
||||||
|
* piston is sticky.
|
||||||
|
*
|
||||||
|
* @return The possible location of the possibly moving block.
|
||||||
|
*/
|
||||||
|
public Location getRetractLocation() {
|
||||||
|
return getBlock().getRelative(getDirection(), 2).getLocation();
|
||||||
|
}
|
||||||
|
}
|
@ -527,6 +527,20 @@ public final class JavaPluginLoader implements PluginLoader {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
case BLOCK_PISTON_RETRACT:
|
||||||
|
return new EventExecutor() {
|
||||||
|
public void execute(Listener listener, Event event) {
|
||||||
|
((BlockListener) listener).onBlockPistonRetract((BlockPistonRetractEvent) event);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
case BLOCK_PISTON_EXTEND:
|
||||||
|
return new EventExecutor() {
|
||||||
|
public void execute(Listener listener, Event event) {
|
||||||
|
((BlockListener) listener).onBlockPistonExtend((BlockPistonExtendEvent) event);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
// Server Events
|
// Server Events
|
||||||
case PLUGIN_ENABLE:
|
case PLUGIN_ENABLE:
|
||||||
return new EventExecutor() {
|
return new EventExecutor() {
|
||||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren