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);
}
}
}
}
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);
}
}
Aggregations