package org.bukkit.craftbukkit.block; import java.util.ArrayList; import java.util.Collection; import net.minecraft.world.ChestLock; import net.minecraft.world.entity.player.EntityHuman; import net.minecraft.world.level.block.entity.TileEntity; import net.minecraft.world.level.block.entity.TileEntityBeacon; import org.bukkit.World; import org.bukkit.block.Beacon; import org.bukkit.craftbukkit.potion.CraftPotionEffectType; import org.bukkit.craftbukkit.util.CraftChatMessage; import org.bukkit.entity.LivingEntity; import org.bukkit.potion.PotionEffect; import org.bukkit.potion.PotionEffectType; public class CraftBeacon extends CraftBlockEntityState implements Beacon { public CraftBeacon(World world, TileEntityBeacon tileEntity) { super(world, tileEntity); } protected CraftBeacon(CraftBeacon state) { super(state); } @Override public Collection getEntitiesInRange() { ensureNoWorldGeneration(); TileEntity tileEntity = this.getTileEntityFromWorld(); if (tileEntity instanceof TileEntityBeacon) { TileEntityBeacon beacon = (TileEntityBeacon) tileEntity; Collection nms = TileEntityBeacon.getHumansInRange(beacon.getLevel(), beacon.getBlockPos(), beacon.levels); Collection bukkit = new ArrayList(nms.size()); for (EntityHuman human : nms) { bukkit.add(human.getBukkitEntity()); } return bukkit; } // block is no longer a beacon return new ArrayList(); } @Override public int getTier() { return this.getSnapshot().levels; } @Override public PotionEffect getPrimaryEffect() { return this.getSnapshot().getPrimaryEffect(); } @Override public void setPrimaryEffect(PotionEffectType effect) { this.getSnapshot().primaryPower = (effect != null) ? CraftPotionEffectType.bukkitToMinecraft(effect) : null; } @Override public PotionEffect getSecondaryEffect() { return this.getSnapshot().getSecondaryEffect(); } @Override public void setSecondaryEffect(PotionEffectType effect) { this.getSnapshot().secondaryPower = (effect != null) ? CraftPotionEffectType.bukkitToMinecraft(effect) : null; } @Override public String getCustomName() { TileEntityBeacon beacon = this.getSnapshot(); return beacon.name != null ? CraftChatMessage.fromComponent(beacon.name) : null; } @Override public void setCustomName(String name) { this.getSnapshot().setCustomName(CraftChatMessage.fromStringOrNull(name)); } @Override public boolean isLocked() { return !this.getSnapshot().lockKey.key.isEmpty(); } @Override public String getLock() { return this.getSnapshot().lockKey.key; } @Override public void setLock(String key) { this.getSnapshot().lockKey = (key == null) ? ChestLock.NO_LOCK : new ChestLock(key); } @Override public CraftBeacon copy() { return new CraftBeacon(this); } }