Skip to content

Instantly share code, notes, and snippets.

@redwallhp
Created July 17, 2016 05:12
Show Gist options
  • Save redwallhp/9dfdf50be0dd95e33c714da4dbb3932b to your computer and use it in GitHub Desktop.
Save redwallhp/9dfdf50be0dd95e33c714da4dbb3932b to your computer and use it in GitHub Desktop.
Spigot Beacon API Update
package org.bukkit.block;
import org.bukkit.entity.Player;
import org.bukkit.inventory.InventoryHolder;
import org.bukkit.potion.PotionEffect;
import java.util.List;
/**
* Represents a beacon.
*/
public interface Beacon extends BlockState, InventoryHolder {
/**
* Returns the list of players within the beacon's range of effect
* @return the players in range
*/
List<Player> getPlayersInRange();
/**
* Returns whether a specified player is in range of the beacon
* @param player the player to check
* @return true if the player is in range
*/
boolean isPlayerInRange(Player player);
/**
* Returns the tier of the beacon pyramid (0-4)
* @return the beacon tier
*/
int getTier();
/**
* Returns the primary effect set on the beacon
* @return the primary effect
*/
PotionEffect getPrimaryEffect();
/**
* Returns the secondary effect set on the beacon
* @return the secondary effect
*/
PotionEffect getSecondaryEffect();
}
package org.bukkit.event.block;
import org.bukkit.block.Beacon;
import org.bukkit.entity.Player;
import org.bukkit.event.Cancellable;
import org.bukkit.event.HandlerList;
import org.bukkit.potion.PotionEffect;
/**
* Called when a beacon applies an effect to a player
*/
public class BeaconApplyEffectEvent extends BlockEvent implements Cancellable {
private static final HandlerList handlers = new HandlerList();
private boolean cancelled;
private final Beacon beacon;
private final Player player;
private PotionEffect effect;
private PotionEffect originalEffect;
public BeaconApplyEffectEvent(final Beacon beacon, final Player player, PotionEffect effect) {
super(beacon.getBlock());
this.cancelled = false;
this.beacon = beacon;
this.player = player;
this.effect = effect;
this.originalEffect = effect;
}
/**
* Returns the beacon associated with this event
* @return the beacon
*/
public Beacon getBeacon() {
return beacon;
}
/**
* Returns the player receiving the effect
* @return the player
*/
public Player getPlayer() {
return player;
}
/**
* Get the effect that will be applied to the player
* @return the effect
*/
public PotionEffect getEffect() {
return effect;
}
/**
* Set the effect that will be applied to the player
* @param effect the effect
*/
public void setEffect(PotionEffect effect) {
this.effect = effect;
}
/**
* Returns whether this is the beacon's primary effect
* @return true if this is the primary effect
*/
public boolean isPrimaryEffect() {
return originalEffect.getType() == beacon.getPrimaryEffect().getType();
}
public boolean isCancelled() {
return cancelled;
}
public void setCancelled(boolean cancel) {
this.cancelled = cancel;
}
@Override
public HandlerList getHandlers() {
return handlers;
}
public static HandlerList getHandlerList() {
return handlers;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment