mirror of
https://github.com/PaperMC/Paper.git
synced 2025-01-16 06:30:46 +01:00
Merge branch 'master' of github.com:Dinnerbone/Bukkit
By: Dinnerbone <dinnerbone@dinnerbone.com>
This commit is contained in:
commit
d520767525
14 changed files with 112 additions and 99 deletions
|
@ -3,6 +3,7 @@ package com.dinnerbone.bukkit.sample;
|
||||||
|
|
||||||
import org.bukkit.Block;
|
import org.bukkit.Block;
|
||||||
import org.bukkit.BlockFace;
|
import org.bukkit.BlockFace;
|
||||||
|
import org.bukkit.event.block.BlockCanBuildEvent;
|
||||||
import org.bukkit.event.block.BlockListener;
|
import org.bukkit.event.block.BlockListener;
|
||||||
import org.bukkit.event.block.BlockPhysicsEvent;
|
import org.bukkit.event.block.BlockPhysicsEvent;
|
||||||
|
|
||||||
|
@ -28,4 +29,13 @@ public class SampleBlockListener extends BlockListener {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onBlockCanBuild(BlockCanBuildEvent event) {
|
||||||
|
Block block = event.getBlock();
|
||||||
|
|
||||||
|
if (block.getType() == 81) {
|
||||||
|
event.setCancelled(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
6
paper-api/src/org/bukkit/event/Cancellable.java
Normal file
6
paper-api/src/org/bukkit/event/Cancellable.java
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
package org.bukkit.event;
|
||||||
|
|
||||||
|
public interface Cancellable {
|
||||||
|
public boolean isCancelled();
|
||||||
|
public void setCancelled(boolean cancel);
|
||||||
|
}
|
|
@ -76,7 +76,8 @@ public abstract class Event {
|
||||||
/**
|
/**
|
||||||
* Block Events
|
* Block Events
|
||||||
*/
|
*/
|
||||||
BLOCK_DAMAGED (Category.BLOCK),
|
BLOCK_BROKEN (Category.BLOCK),
|
||||||
|
BLOCK_CANBUILD (Category.BLOCK),
|
||||||
BLOCK_FLOW (Category.BLOCK),
|
BLOCK_FLOW (Category.BLOCK),
|
||||||
BLOCK_IGNITE (Category.BLOCK),
|
BLOCK_IGNITE (Category.BLOCK),
|
||||||
BLOCK_PHYSICS (Category.BLOCK),
|
BLOCK_PHYSICS (Category.BLOCK),
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package org.bukkit.event;
|
package org.bukkit.event;
|
||||||
|
|
||||||
public class EventException extends Exception {
|
public class EventException extends Exception {
|
||||||
|
private static final long serialVersionUID = 3532808232324183999L;
|
||||||
private final Throwable cause;
|
private final Throwable cause;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
39
paper-api/src/org/bukkit/event/block/BlockCanBuildEvent.java
Normal file
39
paper-api/src/org/bukkit/event/block/BlockCanBuildEvent.java
Normal file
|
@ -0,0 +1,39 @@
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
package org.bukkit.event.block;
|
||||||
|
|
||||||
|
import org.bukkit.Block;
|
||||||
|
import org.bukkit.event.Cancellable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author durron597
|
||||||
|
*/
|
||||||
|
public class BlockCanBuildEvent extends BlockEvent implements Cancellable {
|
||||||
|
protected boolean cancel;
|
||||||
|
|
||||||
|
public BlockCanBuildEvent(Type type, Block block, boolean canBuild) {
|
||||||
|
super(type, block);
|
||||||
|
|
||||||
|
cancel = canBuild;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns whether or not the block can be built here. By default, returns
|
||||||
|
* Minecraft's answer on whether the block can be built
|
||||||
|
*
|
||||||
|
* @return boolean whether or not the block can be built
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public boolean isCancelled() {
|
||||||
|
return cancel;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set whether the block can be built here.
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void setCancelled(boolean cancel) {
|
||||||
|
this.cancel = cancel;
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,85 +0,0 @@
|
||||||
package org.bukkit.event.block;
|
|
||||||
|
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import org.bukkit.Block;
|
|
||||||
import org.bukkit.BlockFace;
|
|
||||||
import org.bukkit.event.Event;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Holds information for events with a source block and a destination block
|
|
||||||
*/
|
|
||||||
public class BlockFlowEvent extends BlockEvent {
|
|
||||||
protected final HashSet<BlockFlow> faceList;
|
|
||||||
|
|
||||||
public BlockFlowEvent(final Event.Type type, final Block block, BlockFace... faces) {
|
|
||||||
super(type, block);
|
|
||||||
this.faceList = new HashSet<BlockFlow>();
|
|
||||||
if (faces != null && faces.length > 0) {
|
|
||||||
for (BlockFace theFace : faces) {
|
|
||||||
faceList.add(new BlockFlow(theFace));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public BlockFlowEvent(final Event.Type type, final Block block, List<BlockFace> faces) {
|
|
||||||
super(type, block);
|
|
||||||
this.faceList = new HashSet<BlockFlow>();
|
|
||||||
if (faces != null && faces.size() > 0) {
|
|
||||||
for (BlockFace theFace : faces) {
|
|
||||||
faceList.add(new BlockFlow(theFace));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* We don't want plugins changing the eligible flowing faces
|
|
||||||
* therefore give them a new HashSet instance
|
|
||||||
*
|
|
||||||
* @return Block the block is event originated from
|
|
||||||
*/
|
|
||||||
public HashSet<BlockFlow> getFaces() {
|
|
||||||
return new HashSet<BlockFlow>(faceList);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Class that represents a flow direction and whether it's cancelled
|
|
||||||
*/
|
|
||||||
public class BlockFlow {
|
|
||||||
private final BlockFace flowDirection;
|
|
||||||
private boolean cancelled;
|
|
||||||
|
|
||||||
public BlockFlow(BlockFace flowDirection) {
|
|
||||||
this.flowDirection = flowDirection;
|
|
||||||
cancelled = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public BlockFace getFlowDirection() {
|
|
||||||
return flowDirection;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isCancelled() {
|
|
||||||
return cancelled;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setCancelled(boolean cancel) {
|
|
||||||
cancelled = cancel;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean equals(Object o) {
|
|
||||||
if (!(o instanceof BlockFlow)) return false;
|
|
||||||
return equals((BlockFlow) o);
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean equals(BlockFlow flow) {
|
|
||||||
return flowDirection.equals(flow.flowDirection);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int hashCode() {
|
|
||||||
return flowDirection.hashCode();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -2,19 +2,22 @@ package org.bukkit.event.block;
|
||||||
|
|
||||||
import org.bukkit.Block;
|
import org.bukkit.Block;
|
||||||
import org.bukkit.BlockFace;
|
import org.bukkit.BlockFace;
|
||||||
|
import org.bukkit.event.Cancellable;
|
||||||
import org.bukkit.event.Event;
|
import org.bukkit.event.Event;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Holds information for events with a source block and a destination block
|
* Holds information for events with a source block and a destination block
|
||||||
*/
|
*/
|
||||||
public class BlockFromToEvent extends BlockEvent {
|
public class BlockFromToEvent extends BlockEvent implements Cancellable {
|
||||||
protected Block from;
|
protected Block from;
|
||||||
protected BlockFace face;
|
protected BlockFace face;
|
||||||
|
protected boolean cancel;
|
||||||
|
|
||||||
public BlockFromToEvent(final Event.Type type, final Block block, final BlockFace face) {
|
public BlockFromToEvent(final Event.Type type, final Block block, final BlockFace face) {
|
||||||
super(type, block);
|
super(type, block);
|
||||||
this.face = face;
|
this.face = face;
|
||||||
this.from = block.getRelative(face.getModX(), face.getModY(), face.getModZ());
|
this.from = block.getRelative(face.getModX(), face.getModY(), face.getModZ());
|
||||||
|
this.cancel = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -34,4 +37,14 @@ public class BlockFromToEvent extends BlockEvent {
|
||||||
public Block getFromBlock() {
|
public Block getFromBlock() {
|
||||||
return from;
|
return from;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isCancelled() {
|
||||||
|
return cancel;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setCancelled(boolean cancel) {
|
||||||
|
this.cancel = cancel;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,12 +22,18 @@ public class BlockListener implements Listener {
|
||||||
public void onBlockBroken(BlockBrokenEvent event) {
|
public void onBlockBroken(BlockBrokenEvent event) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Called when we try to place a block, to see if we can build it
|
||||||
|
*/
|
||||||
|
public void onBlockCanBuild(BlockCanBuildEvent event) {
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called when a block flows (water/lava)
|
* Called when a block flows (water/lava)
|
||||||
*
|
*
|
||||||
* @param event Relevant event details
|
* @param event Relevant event details
|
||||||
*/
|
*/
|
||||||
public void onBlockFlow(BlockFlowEvent event) {
|
public void onBlockFlow(BlockFromToEvent event) {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -1,11 +1,13 @@
|
||||||
package org.bukkit.event.block;
|
package org.bukkit.event.block;
|
||||||
|
|
||||||
import org.bukkit.Block;
|
import org.bukkit.Block;
|
||||||
|
import org.bukkit.event.Cancellable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Not implemented yet
|
* Not implemented yet
|
||||||
*/
|
*/
|
||||||
public class BlockPlacedEvent extends BlockEvent {
|
public class BlockPlacedEvent extends BlockEvent implements Cancellable {
|
||||||
|
private boolean cancel;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param type
|
* @param type
|
||||||
|
@ -13,7 +15,18 @@ public class BlockPlacedEvent extends BlockEvent {
|
||||||
*/
|
*/
|
||||||
public BlockPlacedEvent(Type type, Block theBlock) {
|
public BlockPlacedEvent(Type type, Block theBlock) {
|
||||||
super(type, theBlock);
|
super(type, theBlock);
|
||||||
// TODO Auto-generated constructor stub
|
cancel = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isCancelled() {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
return cancel;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setCancelled(boolean cancel) {
|
||||||
|
this.cancel = cancel;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,11 +2,12 @@
|
||||||
package org.bukkit.event.player;
|
package org.bukkit.event.player;
|
||||||
|
|
||||||
import org.bukkit.Player;
|
import org.bukkit.Player;
|
||||||
|
import org.bukkit.event.Cancellable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Holds information for player chat and commands
|
* Holds information for player chat and commands
|
||||||
*/
|
*/
|
||||||
public class PlayerChatEvent extends PlayerEvent {
|
public class PlayerChatEvent extends PlayerEvent implements Cancellable {
|
||||||
private boolean cancel = false;
|
private boolean cancel = false;
|
||||||
private String message;
|
private String message;
|
||||||
|
|
||||||
|
|
|
@ -3,12 +3,13 @@ package org.bukkit.event.player;
|
||||||
|
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.Player;
|
import org.bukkit.Player;
|
||||||
|
import org.bukkit.event.Cancellable;
|
||||||
import org.bukkit.event.Event;
|
import org.bukkit.event.Event;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Holds information for player movement and teleportation events
|
* Holds information for player movement and teleportation events
|
||||||
*/
|
*/
|
||||||
public class PlayerMoveEvent extends PlayerEvent {
|
public class PlayerMoveEvent extends PlayerEvent implements Cancellable {
|
||||||
private boolean cancel = false;
|
private boolean cancel = false;
|
||||||
private Location from;
|
private Location from;
|
||||||
private Location to;
|
private Location to;
|
||||||
|
|
|
@ -5,6 +5,7 @@ package org.bukkit.plugin;
|
||||||
* Thrown when attempting to load an invalid PluginDescriptionFile
|
* Thrown when attempting to load an invalid PluginDescriptionFile
|
||||||
*/
|
*/
|
||||||
public class InvalidDescriptionException extends Exception {
|
public class InvalidDescriptionException extends Exception {
|
||||||
|
private static final long serialVersionUID = 5721389122281775894L;
|
||||||
private final Throwable cause;
|
private final Throwable cause;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -5,6 +5,7 @@ package org.bukkit.plugin;
|
||||||
* Thrown when attempting to load an invalid Plugin file
|
* Thrown when attempting to load an invalid Plugin file
|
||||||
*/
|
*/
|
||||||
public class InvalidPluginException extends Exception {
|
public class InvalidPluginException extends Exception {
|
||||||
|
private static final long serialVersionUID = -8242141640709409542L;
|
||||||
private final Throwable cause;
|
private final Throwable cause;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -14,8 +14,7 @@ import java.util.regex.Pattern;
|
||||||
import org.bukkit.Server;
|
import org.bukkit.Server;
|
||||||
import org.bukkit.event.Event;
|
import org.bukkit.event.Event;
|
||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
import org.bukkit.event.block.BlockListener;
|
import org.bukkit.event.block.*;
|
||||||
import org.bukkit.event.block.BlockPhysicsEvent;
|
|
||||||
import org.bukkit.event.player.*;
|
import org.bukkit.event.player.*;
|
||||||
import org.bukkit.plugin.*;
|
import org.bukkit.plugin.*;
|
||||||
|
|
||||||
|
@ -112,6 +111,12 @@ public final class JavaPluginLoader implements PluginLoader {
|
||||||
case BLOCK_PHYSICS:
|
case BLOCK_PHYSICS:
|
||||||
trueListener.onBlockPhysics((BlockPhysicsEvent)event);
|
trueListener.onBlockPhysics((BlockPhysicsEvent)event);
|
||||||
break;
|
break;
|
||||||
|
case BLOCK_CANBUILD:
|
||||||
|
trueListener.onBlockCanBuild((BlockCanBuildEvent)event);
|
||||||
|
break;
|
||||||
|
case BLOCK_FLOW:
|
||||||
|
trueListener.onBlockFlow((BlockFromToEvent)event);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue