Search in sources :

Example 21 with Jukebox

use of org.bukkit.block.Jukebox in project FN-FAL-s-Amplifications by FN-FAL113.

the class ElectricJukebox method onTick.

public void onTick(@Nonnull Block b) {
    BlockMenu invMenu = BlockStorage.getInventory(b);
    if (!(b.getBlockData() instanceof org.bukkit.block.data.type.Jukebox)) {
        return;
    }
    Jukebox jukebox = (Jukebox) invMenu.getBlock().getState();
    JukeboxCache cache = getCACHE_MAP().get(b.getLocation());
    if (getCharge(b.getLocation()) > 0) {
        // is jukebox powered
        if (invMenu.hasViewer()) {
            invMenu.replaceExistingItem(48, NOT_RUNNING);
        }
        if (cache.isOn) {
            // is jukebox turned on
            if (cache.isPlaying) {
                int currentTime = durationMap.getOrDefault(b.getLocation(), 0);
                if (isNewMusic()) {
                    durationMap.put(b.getLocation(), 0);
                    setNewMusic(false);
                    return;
                }
                if (invMenu.hasViewer()) {
                    invMenu.replaceExistingItem(48, OPERATING);
                    if (jukebox.getPlaying() != Material.AIR) {
                        invMenu.replaceExistingItem(49, new CustomItemStack(Material.PINK_STAINED_GLASS_PANE, "&d&lPlaying: " + jukebox.getPlaying().toString().replace("_", " "), "&eDuration : " + durationMap.get(b.getLocation()) + "/" + (DiscDurationsEnum.valueOf(jukebox.getPlaying().toString().toUpperCase()).getDurationInSec() * 2)));
                    }
                }
                if (durationMap.containsKey(b.getLocation())) {
                    if (durationMap.get(b.getLocation()) >= (DiscDurationsEnum.valueOf(jukebox.getPlaying().toString().toUpperCase()).getDurationInSec() * 2)) {
                        nextDiscButton(null, invMenu);
                        currentTime = 0;
                    } else // when disc duration is done, check next slot if there is a disc else stop the jukebox or go back to default slot when upper bound is reached
                    {
                        // increment current time if music has not reached the duration
                        currentTime++;
                        if (currentTime == 1) {
                            // re-update the jukebox state, for persistent state after server restart (might not work on 1.18 below)
                            jukebox.update(true);
                        }
                    }
                }
                durationMap.put(b.getLocation(), currentTime);
                Objects.requireNonNull(jukebox.getLocation().getWorld()).spawnParticle(Particle.NOTE, b.getLocation().add(0, 0.8, 0), 2);
            } else {
                // reset current jukebox duration and change the status of the gui panels
                durationMap.put(b.getLocation(), 0);
                if (invMenu.hasViewer()) {
                    invMenu.replaceExistingItem(48, NOT_OPERATING);
                    changeStatus(invMenu, cache.currentSlot);
                }
            }
            takeCharge(b.getLocation());
        } else if (cache.isPlaying) {
            // jukebox is turned off. stop current music disc and change status of gui panels
            stopCurrentSlot(jukebox, invMenu.getLocation(), cache, invMenu);
            durationMap.put(b.getLocation(), 0);
            if (invMenu.hasViewer()) {
                changeStatus(invMenu, cache.currentSlot);
            }
        }
    }
}
Also used : Jukebox(org.bukkit.block.Jukebox) BlockMenu(me.mrCookieSlime.Slimefun.api.inventory.BlockMenu) org.bukkit(org.bukkit) CustomItemStack(io.github.thebusybiscuit.slimefun4.libraries.dough.items.CustomItemStack)

Example 22 with Jukebox

use of org.bukkit.block.Jukebox in project PlotSquared by IntellectualSites.

the class PaperListener113 method onBlockPlace.

@EventHandler
public void onBlockPlace(BlockPlaceEvent event) {
    if (!Settings.Paper_Components.TILE_ENTITY_CHECK || !Settings.Enabled_Components.CHUNK_PROCESSOR) {
        return;
    }
    BlockState state = event.getBlock().getState(false);
    if (!(state instanceof Banner || state instanceof Beacon || state instanceof Bed || state instanceof CommandBlock || state instanceof Comparator || state instanceof Conduit || state instanceof Container || state instanceof CreatureSpawner || state instanceof DaylightDetector || state instanceof EnchantingTable || state instanceof EnderChest || state instanceof EndGateway || state instanceof Jukebox || state instanceof Sign || state instanceof Skull || state instanceof Structure)) {
        return;
    }
    final Location location = BukkitUtil.adapt(event.getBlock().getLocation());
    final PlotArea plotArea = location.getPlotArea();
    if (plotArea == null) {
        return;
    }
    final int tileEntityCount = event.getBlock().getChunk().getTileEntities(false).length;
    if (tileEntityCount >= Settings.Chunk_Processor.MAX_TILES) {
        final PlotPlayer<?> plotPlayer = BukkitUtil.adapt(event.getPlayer());
        plotPlayer.sendMessage(TranslatableCaption.of("errors.tile_entity_cap_reached"), Template.of("amount", String.valueOf(Settings.Chunk_Processor.MAX_TILES)));
        event.setCancelled(true);
        event.setBuild(false);
    }
}
Also used : Bed(org.bukkit.block.data.type.Bed) Jukebox(org.bukkit.block.Jukebox) PlotArea(com.plotsquared.core.plot.PlotArea) Banner(org.bukkit.block.Banner) CommandBlock(org.bukkit.block.CommandBlock) DaylightDetector(org.bukkit.block.DaylightDetector) Comparator(org.bukkit.block.Comparator) CreatureSpawner(org.bukkit.block.CreatureSpawner) Container(org.bukkit.block.Container) EndGateway(org.bukkit.block.EndGateway) BlockState(org.bukkit.block.BlockState) Conduit(org.bukkit.block.Conduit) Beacon(org.bukkit.block.Beacon) Skull(org.bukkit.block.Skull) Sign(org.bukkit.block.Sign) Structure(org.bukkit.block.Structure) EnchantingTable(org.bukkit.block.EnchantingTable) EnderChest(org.bukkit.block.EnderChest) Location(com.plotsquared.core.location.Location) EventHandler(org.bukkit.event.EventHandler)

Aggregations

Jukebox (org.bukkit.block.Jukebox)22 ItemStack (org.bukkit.inventory.ItemStack)13 Block (org.bukkit.block.Block)12 BlockState (org.bukkit.block.BlockState)10 InventoryHolder (org.bukkit.inventory.InventoryHolder)8 Location (org.bukkit.Location)6 CompoundTag (net.minecraft.nbt.CompoundTag)5 ListTag (net.minecraft.nbt.ListTag)5 FallingBlockEntity (net.minecraft.world.entity.item.FallingBlockEntity)5 BlockEntity (net.minecraft.world.level.block.entity.BlockEntity)5 SignBlockEntity (net.minecraft.world.level.block.entity.SignBlockEntity)5 Lectern (org.bukkit.block.Lectern)5 FallingBlock (org.bukkit.entity.FallingBlock)5 Lootable (org.bukkit.loot.Lootable)5 Sign (org.bukkit.block.Sign)4 Material (org.bukkit.Material)3 NoteBlock (org.bukkit.block.NoteBlock)3 EventHandler (org.bukkit.event.EventHandler)3 Banner (org.bukkit.block.Banner)2 BlockFace (org.bukkit.block.BlockFace)2