@Override public void change(Event e, Object[] delta, Changer.ChangeMode mode){ if (mode == ChangeMode.SET) { if (block != null) { if (block.getSingle(e) instanceof Jukebox) { String type = (String)delta[0]; try { Material material = Material.valueOf(type.replace("\"", "").trim().replace(" ", "_").toUpperCase()); ((Jukebox)block.getSingle(e)).setPlaying(material); } catch (IllegalArgumentException error) { Bukkit.getConsoleSender().sendMessage(Skellett.cc(Skellett.prefix + "&cUnknown material type " + type)); return; } } } } else if (mode == ChangeMode.RESET) { if (((Jukebox)block.getSingle(e)).isPlaying()) { ((Jukebox)block.getSingle(e)).eject(); } } }
@Override protected void execute(Event e) { if (block != null) { BlockState state = block.getSingle(e).getState(); if (state instanceof Jukebox) { Jukebox jukebox = (Jukebox) state; jukebox.eject(); jukebox.update(); } } }
@Override @Nullable protected Material[] get(Event e) { if (block != null) { if (block.getSingle(e) instanceof Jukebox) { return new Material[]{((Jukebox)block.getSingle(e)).getPlaying()}; } } return null; }
public boolean check(Event e) { if (block.getSingle(e) instanceof Jukebox) { if (((Jukebox)block.getSingle(e)).isPlaying()) { return isNegated(); } else { return !isNegated(); } } return false; }
@SuppressWarnings("deprecation") public static Optional<String> serializeState(BlockState state) { YamlConfiguration yaml = new YamlConfiguration(); // http://minecraft.gamepedia.com/Block_entity was used as a reference for this method if (state instanceof InventoryHolder) { yaml.set(INVENTORY_KEY, InventoryHelper.serializeInventory(((InventoryHolder) state).getInventory())); } if (state instanceof Sign) { yaml.set(SIGN_LINES_KEY, Arrays.asList(((Sign) state).getLines())); } else if (Support.BANNER && state instanceof Banner) { yaml.set(BANNER_BASE_COLOR_KEY, ((Banner) state).getBaseColor().name()); ConfigurationSection patternSection = yaml.createSection(BANNER_PATTERNS_KEY); List<Pattern> patterns = ((Banner) state).getPatterns(); for (int i = 0; i < patterns.size(); i++) { ConfigurationSection subSection = patternSection.createSection("" + i); subSection.set(BANNER_PATTERN_COLOR_KEY, patterns.get(i).getColor().name()); subSection.set(BANNER_PATTERN_TYPE_KEY, patterns.get(i).getPattern().name()); } } else if (state instanceof CreatureSpawner) { yaml.set(SPAWNER_TYPE_KEY, ((CreatureSpawner) state).getSpawnedType().name()); yaml.set(SPAWNER_DELAY_KEY, ((CreatureSpawner) state).getDelay()); } else if (state instanceof NoteBlock) { yaml.set(NOTE_OCTAVE_KEY, ((NoteBlock) state).getNote().getOctave()); yaml.set(NOTE_TONE_KEY, ((NoteBlock) state).getNote().getTone().name()); } else if (state instanceof Jukebox) { if (((Jukebox) state).isPlaying()) { yaml.set(JUKEBOX_DISC_KEY, ((Jukebox) state).getPlaying()); } } else if (state instanceof Skull) { yaml.set(SKULL_OWNER_KEY, ((Skull) state).getOwner()); yaml.set(SKULL_ROTATION_KEY, ((Skull) state).getRotation().name()); } else if (state instanceof CommandBlock) { yaml.set(COMMAND_NAME_KEY, ((CommandBlock) state).getName()); yaml.set(COMMAND_CMD_KEY, ((CommandBlock) state).getCommand()); } else if (state instanceof FlowerPot) { yaml.set(FLOWER_TYPE_KEY, ((FlowerPot) state).getContents().getItemType().name()); yaml.set(FLOWER_DATA_KEY, ((FlowerPot) state).getContents().getData()); } if (yaml.getKeys(false).size() > 0) { return Optional.of(yaml.saveToString()); } return Optional.absent(); }
private void playMusic(Player p) { p.getLocation().getBlock().setType(Material.JUKEBOX); final Jukebox jb = (Jukebox) p.getLocation().getBlock().getState(); jb.setPlaying(Material.RECORD_11); MiscUtils.shootFirework(jb.getLocation().add(0.5,0,0.5), p.getWorld().getName()); ScheduleUtils.scheduleTask(500, new Runnable() { @Override public void run() { jb.setPlaying(null); jb.getBlock().setType(Material.AIR); } }); }
public void enable() { Bukkit.getScheduler().scheduleSyncRepeatingTask(plugin, new Runnable() { @SuppressWarnings("deprecation") @Override public void run() { World w = Bukkit.getWorld("Survival"); Jukebox a = (Jukebox) w.getBlockAt(64, 70, 198).getState(); ArrayList<Material> discs = new ArrayList<Material>(); discs.add(Material.getMaterial(2257)); discs.add(Material.getMaterial(2258)); discs.add(Material.getMaterial(2260)); discs.add(Material.getMaterial(2261)); discs.add(Material.getMaterial(2263)); discs.add(Material.getMaterial(2264)); discs.add(Material.getMaterial(2267)); Block db = w.getBlockAt(a.getBlock().getLocation().clone().add(0,-1,0)); int type = db.getData(); type++; if (type > 6) { type = 0; } a.setPlaying(discs.get(type)); db.setData((byte) type); // } }, 20*5, 20*60*3); log("Enabled"); }
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) public void onBlockBreak(BlockBreakEvent event) { if (event.getBlock().getType() == AIR) { return; // breaking air !? -> no logging } if (!this.isActive(PlayerBlockBreak.class, event.getBlock().getWorld())) { return; } BlockState blockState = event.getBlock().getState(); PlayerBlockBreak action; if (blockState instanceof NoteBlock) { action = this.newAction(PlayerNoteBlockBreak.class); ((PlayerNoteBlockBreak)action).setNote(((NoteBlock)blockState).getNote()); } else if (blockState instanceof Sign) { action = this.newAction(PlayerSignBreak.class); ((PlayerSignBreak)action).setLines(((Sign)blockState).getLines()); } else if (blockState instanceof Jukebox && ((Jukebox)blockState).getPlaying() != null) { action = this.newAction(PlayerJukeboxBreak.class); ((PlayerJukeboxBreak)action).setDisc(((Jukebox)blockState).getPlaying()); } else if (blockState instanceof InventoryHolder) { action = this.newAction(PlayerContainerBreak.class, event.getBlock().getWorld()); if (action == null) { action = this.newAction(PlayerBlockBreak.class); } else { ((PlayerContainerBreak)action).setContents(((InventoryHolder)blockState).getInventory().getContents()); } // TODO item drops // itemDrop.logDropsFromChest((InventoryHolder)blockState,location,event.getPlayer()); } else { action = this.newAction(PlayerBlockBreak.class); blockState = adjustBlockForDoubleBlocks(blockState); // WOOD_DOOR IRON_DOOR OR BED_BLOCK } action.setPlayer(event.getPlayer()); action.setLocation(event.getBlock().getLocation()); action.setOldBlock(blockState); action.setNewBlock(AIR); this.logAction(action); if (blockState.getType() == OBSIDIAN) // portal? { // TODO better & complete Block block = blockState.getBlock(); for (BlockFace face : BLOCK_FACES) { if (block.getRelative(face).getType() == PORTAL) { Block portal = block.getRelative(face); PlayerBlockBreak pAction = this.newAction(PlayerBlockBreak.class); pAction.setPlayer(event.getPlayer()); pAction.setLocation(portal.getLocation()); pAction.setOldBlock(portal.getState()); pAction.setNewBlock(AIR); pAction.reference = this.reference(action); this.logAction(pAction); break; } } } // TODO attached & falling ListenerBlock.logAttachedBlocks(this, module.getCore().getEventManager(), event.getBlock(), action); ListenerBlock.logFallingBlocks(this, module.getCore().getEventManager(), event.getBlock(), action); }