import org.spout.vanilla.inventory.window.block.BeaconWindow;
public class BeaconHandler extends MessageHandler<BeaconMessage> {
@Override
public void handleServer(ServerSession session, BeaconMessage msg) {
Window window = session.getPlayer().get(WindowHolder.class).getActiveWindow();
if (!(window instanceof BeaconWindow)) {
throw new IllegalStateException("Player tried to change Beacon but does not have an opened Beacon.");
}
Beacon beacon = ((BeaconWindow) window).getBeacon();
beacon.setPrimaryEffect(EntityEffectType.get(msg.getPrimaryEffect()));
beacon.setSecondaryEffect(EntityEffectType.get(msg.getSecondaryEffect()));
for (InventoryConverter converter : window.getInventoryConverters()) {
if (converter.getInventory() instanceof BeaconInventory) {
converter.getInventory().clear();
}
}
}