@EventHandler public void PlaceCheckDoor(BlockPlaceEvent e) { if(ConfigPatch.AntiInfSuagrenable){ if(e.isCancelled()){ Player p = e.getPlayer(); List<Entity> entities = p.getNearbyEntities(2, 2, 2); for(int i=0;i<entities.size();i++){ Entity ent = entities.get(i); if(ent.getType() == EntityType.DROPPED_ITEM){ Item item = (Item)ent; if(item.getItemStack().getType() == Material.SUGAR_CANE||item.getItemStack().getType() == Material.CACTUS){ ent.remove(); } } } } } }
private void checkPedestal(Block pedestal) { Item item = AncientAltarListener.findItem(pedestal); if(item == null) { abort(); } else { particles.add(pedestal.getLocation().add(0.5D, 1.5D, 0.5D)); items.add(AncientAltarListener.fixItemStack(item.getItemStack(), item.getCustomName())); pedestal.getWorld().playSound(pedestal.getLocation(), Sound.ENTITY_ENDERMEN_TELEPORT, 5F, 2.0F); try { ParticleEffect.ENCHANTMENT_TABLE.display(pedestal.getLocation().add(0.5D, 1.5D, 0.5D), 0.3F, 0.2F, 0.3F, 0.0F, 16); ParticleEffect.CRIT_MAGIC.display(pedestal.getLocation().add(0.5D, 1.5D, 0.5D), 0.3F, 0.2F, 0.3F, 0.0F, 8); } catch(Exception e) { e.printStackTrace(); } item.remove(); pedestal.removeMetadata("item_placed", SlimefunStartup.instance); } }
@SuppressWarnings("deprecation") @EventHandler public void grenadeEvent(PlayerInteractEvent e){ final Player p = e.getPlayer(); if(e.getAction().equals(Action.RIGHT_CLICK_AIR) || e.getAction().equals(Action.RIGHT_CLICK_BLOCK)){ if(p.getItemInHand().hasItemMeta()){ if(p.getItemInHand().getItemMeta().getLore() == null) return; if(p.getItemInHand().getItemMeta().getLore().contains(ChatColor.GRAY + "Grenade I")){ p.getItemInHand().setDurability((short) (p.getItemInHand().getDurability() - 4)); final Item grenade = p.getWorld().dropItem(p.getEyeLocation(), new ItemStack(Material.CLAY_BALL)); grenade.setVelocity(p.getEyeLocation().getDirection().normalize().multiply(0.8D)); Bukkit.getScheduler().scheduleSyncDelayedTask(this, new Runnable(){ public void run(){ p.getWorld().createExplosion(grenade.getLocation().getX(), grenade.getLocation().getY(), grenade.getLocation().getZ(), 3, false, false); grenade.remove(); } },30L); } } } }
@EventHandler(priority = EventPriority.MONITOR) public void handleItemDespawn(final EntityDespawnInVoidEvent event) { Entity entity = event.getEntity(); if (!(entity instanceof Item)) return; ItemStack stack = ((Item) entity).getItemStack(); PlayerId playerId = this.droppedWools.remove(entity); if (playerId == null) return; ParticipantState player = PGM.getMatchManager().getParticipantState(playerId); if (player == null) return; if(isDestroyableWool(stack, player.getParty())) { giveWoolDestroyRaindrops(player, ((Wool) stack.getData()).getColor()); } }
@EventHandler public void playerInteract(final PlayerInteractEvent event) { if(event.getAction() == Action.PHYSICAL || !(Gizmos.gizmoMap.get(event.getPlayer()) instanceof GunGizmo) || event.getItem() == null || event.getItem().getType() != this.getIcon()) return; final Player player = event.getPlayer(); RaindropUtil.giveRaindrops(Users.playerId(player), -1, new RaindropResult() { @Override public void run() { if(success) { Vector velocity = player.getLocation().getDirection().multiply(1.75D); Item item = player.getWorld().dropItem(event.getPlayer().getEyeLocation(), new ItemStack(Material.GHAST_TEAR)); item.setVelocity(velocity); item.setTicksLived((5 * 60 * 20) - (5 * 20)); // 5 minutes - 5 seconds items.put(item, player.getUniqueId()); } else { player.sendMessage(ChatColor.RED + LobbyTranslations.get().t("gizmo.gun.empty", player)); player.playSound(player.getLocation(), Sound.UI_BUTTON_CLICK, 1f, 1f); } } }, null, false, true, false); }
@Override public void run() { for(Item item : Bukkit.getWorlds().get(0).getEntitiesByClass(Item.class)) { if(item.getItemStack().getType() != Material.GHAST_TEAR) continue; UUID skip = Gizmos.gunGizmo.items.get(item); for(Entity entity : item.getNearbyEntities(0.5d, 0.5d, 0.5d)) { if(entity instanceof Player && !entity.getUniqueId().equals(skip)) { Player player = (Player) entity; if(player.hasPermission("gizmo.immunity")) continue; player.damage(0d, item); Gizmos.gunGizmo.gifts.add(player.getUniqueId()); item.remove(); break; } } if(item.getTicksLived() >= 6000) item.remove(); } }
public boolean craft(Player crafter) { // TODO Block crafting operation when not allowed for player String spell = getSpell(); if (spell != null) { ItemStack tome = SpellTome.getSpellTome(spell, crafter); Location spawnLoc = block.getLocation().add(0.5, 1.5, 0.5); spawnLoc.getWorld().spawnParticle(Particle.ENCHANTMENT_TABLE, spawnLoc, 40); for (Entry<Item, BukkitRunnable> entry : items.entrySet()) { Item item = entry.getKey(); item.remove(); entry.getValue().cancel(); } book.setCustomNameVisible(false); new BukkitRunnable() { public void run() { book.setItemStack(tome); book.setGlowing(false); book.setPickupDelay(0); book.getWorld().playSound(book.getLocation(), Sound.ENTITY_EXPERIENCE_ORB_PICKUP, 1, 1); } }.runTaskLater(MystiCraft.getInstance(), 32); return true; } else { return false; } }
@EventHandler public void onItemPickUpEvent(PlayerPickupItemEvent event) { final Game game; if ((game = this.controller.getGameFromPlayer(event.getPlayer())) != null) { for (final Item item : game.getArena().getBoostItemHandler().getDroppedItems()) { final BoostItem boostItem; if (item.equals(event.getItem()) && ((boostItem = game.getArena().getBoostItemHandler().getBoostFromItem(item)) != null)) { try { new FastSound("NOTE_PLING", 2.0, 2.0).play(event.getPlayer().getLocation(), event.getPlayer()); } catch (final InterPreter19Exception e) { Bukkit.getLogger().log(Level.WARNING, "Failed to play sound.", e); } game.getArena().getBoostItemHandler().removeItem(event.getItem()); boostItem.apply(event.getPlayer()); event.setCancelled(true); event.getItem().remove(); } } } }
@Override public void run(Game game) { final Arena arena = game.getArena(); if (this.rate == Spawnrate.NONE) return; if (this.bumper <= 0) { if (game.getPlayers().isEmpty()) { this.clearGroundItems(); this.bumper = 40; return; } for (final Item item : this.getLDroppedItems().keySet().toArray(new Item[this.getLDroppedItems().size()])) { if (item.isDead() || item.getTicksLived() > 1000) { item.remove(); this.getLDroppedItems().remove(item); } } if (this.getRandom().nextInt(100) < this.rate.getSpawnChance()) { if (this.getLDroppedItems().size() < this.rate.getMaxAmount()) { this.spawnRandomItem(arena); } } this.bumper = 40; } this.bumper--; }
/** * Clean the cache */ @Override public void run() { long currentTime = System.currentTimeMillis(); List<Map.Entry<Chunk, Long>> temp = new ArrayList<>(); temp.addAll(this.lastChunkCleanUp.entrySet()); for (Map.Entry<Chunk, Long> entry : temp) { Chunk chunk = entry.getKey(); if (!chunk.isLoaded() || (currentTime - entry.getValue() <= 60000)) continue; for (Entity entity : chunk.getEntities()) if (!(entity instanceof Item || entity instanceof HumanEntity || entity instanceof Minecart)) entity.remove(); this.lastChunkCleanUp.remove(chunk); } }
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) public void onPlace(BlockPlaceEvent e) { if (!cm.isAntiPlaceDoorDupe) { return; } // 判断手里的物品是否为门 if (e.getItemInHand().getType() == Material.WOOD_DOOR || e.getItemInHand().getType() == Material.IRON_DOOR) { // 清理所在区块的甘蔗掉落物 for (Entity entity : e.getPlayer().getLocation().getChunk().getEntities()) { if (entity instanceof Item) { Material itemType = ((Item) entity).getItemStack().getType(); if (itemType == Material.SUGAR_CANE || itemType == Material.CACTUS) { entity.remove(); } } } } }
public void play(TOAUser u){ if (!canUse(u)) return; if (isInCooldown(u, getName())) return; int lvl = u.getUserData().getLvl(); for (int x = 0; x < r.nextInt(4) + 2; x++) { final Item d1 = u.getLoc().getWorld().dropItemNaturally(u.getLoc(), new ItemStack(Material.IRON_SWORD)); d1.setVelocity(u.getPlayer().getVelocity().multiply(2)); plugin.getServer().getScheduler().runTaskTimer(plugin, () -> { World w = d1.getLocation().getWorld(); w.getNearbyEntities(d1.getLocation(), 1, 1, 1).stream() .filter(en -> !en.getType().equals(EntityType.PLAYER)).forEach(en -> { if (en instanceof Monster) ((Monster) en).damage(40 + (lvl * 0.7)); d1.remove(); }); }, 0, 20); } cool.setOnCooldown(getName()); }
@EventHandler public void onInteract(PlayerInteractEvent e) { if (e.getAction() == Action.RIGHT_CLICK_BLOCK) { if (e.getClickedBlock().getType() == Material.CAULDRON) { if (e.getClickedBlock().getLocation().add(0, -1, 0).getBlock().getType() == Material.DIAMOND_BLOCK) { Item item = e.getPlayer().getWorld().dropItem(e.getClickedBlock().getLocation().add(0.5, 2, 0.5), e.getPlayer().getEquipment().getItemInMainHand()); item.setMetadata("item-owner", new FixedMetadataValue(NationZ.plugin, e.getPlayer().getUniqueId().toString())); item.setVelocity(new Vector(0, 0, 0)); item.setCustomName(item.getName()); item.setCustomNameVisible(true); e.getPlayer().getEquipment().setItemInMainHand(null); e.setCancelled(true); } } } }
@Override public Relation compare(final EntityData e, final ItemType i) { if (e instanceof Item) return Relation.get(i.isOfType(((Item) e).getItemStack())); if (e instanceof ThrownPotion) return Relation.get(i.isOfType(Material.POTION.getId(), PotionEffectUtils.guessData((ThrownPotion) e))); if (Skript.classExists("org.bukkit.entity.WitherSkull") && e instanceof WitherSkull) return Relation.get(i.isOfType(Material.SKULL_ITEM.getId(), (short) 1)); if (entityMaterials.containsKey(e.getType())) return Relation.get(i.isOfType(entityMaterials.get(e.getType()).getId(), (short) 0)); for (final Entry<Class<? extends Entity>, Material> m : entityMaterials.entrySet()) { if (m.getKey().isAssignableFrom(e.getType())) return Relation.get(i.isOfType(m.getValue().getId(), (short) 0)); } return Relation.NOT_EQUAL; }
@EventHandler public void onItemDrop(PlayerDropItemEvent event) { System.out.println("Item drop"); Item item = event.getItemDrop(); ItemStack stack = item.getItemStack(); Location location = item.getLocation(); Player player = event.getPlayer(); String playerName = player == null ? "null" : player.getName(); DropItemObsel obsel = new DropItemObsel( new Date().getTime(), stack.getType().toString(), stack.getAmount(), stack.getData().getData(), location.getBlockX(), location.getBlockY(), location.getBlockZ(), location.getWorld().getName(), playerName); JSONObselManager.getInstance().addObsel(obsel); }
@EventHandler public void onItemPickup(PlayerPickupItemEvent event) { System.out.println("Item pickup"); Item item = event.getItem(); ItemStack stack = item.getItemStack(); Location location = item.getLocation(); Player player = event.getPlayer(); String playerName = player == null ? "null" : player.getName(); PickupItemObsel obsel = new PickupItemObsel( new Date().getTime(), stack.getType().toString(), stack.getAmount(), stack.getData().getData(), location.getBlockX(), location.getBlockY(), location.getBlockZ(), location.getWorld().getName(), playerName); JSONObselManager.getInstance().addObsel(obsel); }
@EventHandler(priority = EventPriority.HIGHEST) public void specialItemActionCheck(final PlayerInteractEvent event) { if(event.getAction() == Action.RIGHT_CLICK_AIR || event.getAction() == Action.RIGHT_CLICK_BLOCK) { Player player = event.getPlayer(); AnniPlayer pl = AnniPlayer.getPlayer(player.getUniqueId()); if(pl != null && pl.getKit().equals(this)) { if(this.isHookItem(player.getItemInHand())) { if(!Delays.getInstance().hasActiveDelay(player, this.getInternalName())) { Delays.getInstance().addDelay(player, System.currentTimeMillis()+5000, this.getInternalName());//kits.addDelay(player.getName(), DelayType.SCORPIO, 10, TimeUnit.SECONDS); Item item = player.getWorld().dropItem(player.getEyeLocation(), new ItemStack(Material.NETHER_STAR,1)); item.setPickupDelay(Integer.MAX_VALUE); item.setVelocity(player.getEyeLocation().getDirection().multiply(2)); Bukkit.getScheduler().scheduleSyncDelayedTask(AnnihilationMain.getInstance(), new HookTracer(item,pl,90,this.getName()), 1); } } } } }
@EventHandler(priority=EventPriority.HIGHEST, ignoreCancelled=true) public void StopDrops(PlayerDropItemEvent event) { Player player = event.getPlayer(); Item item = event.getItemDrop(); if(item != null) { ItemStack stack = item.getItemStack(); if(stack != null) { if(KitUtils.isSoulbound(stack)) { player.playSound(player.getLocation(), Sound.BLAZE_HIT, 1.0F, 0.3F); event.getItemDrop().remove(); } } } }
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) public void onFish(PlayerFishEvent event) { if (event.getState() == PlayerFishEvent.State.CAUGHT_FISH && event.getCaught() instanceof Item) { if (!contest.hasStarted() && plugin.getConfig().getBoolean("general.no-fishing-unless-contest")) { event.setCancelled(true); String msg = plugin.getLocale().getString("no-fishing-allowed"); event.getPlayer().sendMessage(msg); return; } if (!isFishingEnabled(event)) { return; } executeFishingActions(event.getPlayer(), event); } }
private void executeFishingActions(Player catcher, PlayerFishEvent event) { CaughtFish fish = plugin.getFishManager().generateRandomFish(catcher); PlayerCatchCustomFishEvent customEvent = new PlayerCatchCustomFishEvent(catcher, fish, event); plugin.getServer().getPluginManager().callEvent(customEvent); if (customEvent.isCancelled()) { return; } boolean new1st = contest.hasStarted() && contest.isNew1st(fish); announceMessages(catcher, fish, new1st); if (fish.getRarity().hasFirework()) launchFirework(catcher.getLocation().add(0, 1, 0)); if (!fish.getCommands().isEmpty()) executeCommands(catcher, fish); if (new1st) { contest.addRecord(catcher, fish); } ItemStack itemStack = plugin.getFishManager().getItemStack(fish, event.getPlayer().getName()); Item caught = (Item) event.getCaught(); caught.setItemStack(itemStack); }
/** * Prevent chunk that contain pearls from unloading * @param e The event args */ @EventHandler(priority=EventPriority.HIGH, ignoreCancelled = true) public void onChunkUnload(ChunkUnloadEvent e) { Chunk chunk = e.getChunk(); for (Entity entity : chunk.getEntities()) { if (!(entity instanceof Item)) { continue; } Item item = (Item)entity; ExilePearl pearl = pearlApi.getPearlFromItemStack(item.getItemStack()); if (pearl != null) { e.setCancelled(true); pearlApi.log("Prevented chunk (%d, %d) from unloading because it contained an exile pearl for player %s.", chunk.getX(), chunk.getZ(), pearl.getPlayerName()); } } }
@Test public void testGetLocationDescription() { World world = mock(World.class); when(world.getName()).thenReturn("world"); Location l = new Location(world, 1, 2, 3); Block b = mock(Block.class); when(b.getLocation()).thenReturn(l); when(b.getType()).thenReturn(Material.CHEST); when(pearlApi.isPlayerExiled(playerId)).thenReturn(true); pearl.setHolder(b); assertEquals(pearl.getLocationDescription(), "held by a chest at world 1 2 3"); Item item = mock(Item.class); when(item.getLocation()).thenReturn(l); pearl.setHolder(item); assertEquals(pearl.getLocationDescription(), "held by nobody at world 1 2 3"); }
@EventHandler(priority = EventPriority.MONITOR) public void onPlayerDropItem(PlayerDropItemEvent event) { if (!event.isCancelled() && TeamUtils.getTeamByPlayer(event.getPlayer()) != null && event.getItemDrop().getItemStack().getType().equals(Material.WOOL)) { for (TeamModule team : TeamUtils.getTeams()) { if (!team.isObserver() && TeamUtils.getTeamByPlayer(event.getPlayer()) != team) { for (GameObjective obj : TeamUtils.getShownObjectives(team)) { if (obj instanceof WoolObjective && event.getItemDrop().getItemStack().getData().getData() == ((WoolObjective) obj).getColor().getData()) { if (!items.containsKey(event.getPlayer())) { items.put(event.getPlayer(), new ArrayList<Item>()); } List<Item> list = items.get(event.getPlayer()); list.add(event.getItemDrop()); items.put(event.getPlayer(), list); } } } } } }
public int addLots(List<Item> items) { int addedCount = 0; for(Item itemEntity : items) { ItemStack item = itemEntity.getItemStack(); AuctionableItem ai = regionalConfigManager.getAuctionableItemConfig(itemEntity); if(null == ai) continue; double startingPrice = (((int)(ai.getStartingPrice() * 100)) * item.getAmount()) / 100D; double minimumIncrement = (((int)(ai.getMinimumIncrement() * 100)) * item.getAmount()) / 100D; Lot lot = new Lot(item, false, startingPrice, null, null, null, -1, minimumIncrement, System.currentTimeMillis() + ai.getPreserveTimeInSeconds() * 1000, ai.getAuctionDurationInSeconds() * 1000); lots.add(lot); addedCount++; } LotShowcase.updateAll(); return addedCount; }
@EventHandler(priority = EventPriority.NORMAL) public void onEntityPortalTeleport(EntityPortalEvent event) { if (!(event.getEntity() instanceof Item)) return; ConsoleLogger.debug("[ENTITYPORTALEVENT] A '" + event.getEntity().getName() + "' is going through a portal!"); String worldFrom = event.getFrom().getWorld().getName(); // For some reason, event.getTo().getWorld().getName() is sometimes null if (event.getTo() == null || event.getTo().getWorld() == null) { // Not gonna bother checking name; its already a WTF that this is needed ConsoleLogger.debug("[ENTITYPORTALEVENT] event.getTo().getWorld().getName() would throw a NPE! Exiting method!"); return; } String worldTo = event.getTo().getWorld().getName(); Group from = groupManager.getGroupFromWorld(worldFrom); Group to = groupManager.getGroupFromWorld(worldTo); // If the groups are different, cancel the event if (!from.equals(to)) { ConsoleLogger.debug("[ENTITYPORTALEVENT] Group '" + from.getName() + "' and group '" + to.getName() + "' are different! Canceling event!"); event.setCancelled(true); } }
@Test public void shouldTeleportBecauseSameGroup() { // given Group group = mockGroup("test_group", GameMode.SURVIVAL, false); Item entity = mock(Item.class); World world = mock(World.class); given(world.getName()).willReturn("test_group"); Location from = new Location(world, 1, 2, 3); World worldNether = mock(World.class); given(worldNether.getName()).willReturn("test_group_nether"); Location to = new Location(worldNether, 1, 2, 3); given(groupManager.getGroupFromWorld("test_group")).willReturn(group); given(groupManager.getGroupFromWorld("test_group_nether")).willReturn(group); EntityPortalEvent event = new EntityPortalEvent(entity, from, to, mock(TravelAgent.class)); // when listener.onEntityPortalTeleport(event); // then assertThat(event.isCancelled(), equalTo(false)); }
@Override public void onPacketSending( PacketEvent event ) { PacketContainer packet = event.getPacket(); int entityID = packet.getIntegers().read( 0 ); int type = packet.getIntegers().read( 9 ); /* ItemStacks are ID'd as 2. */ if( type == 2 ) { Entity entity = packet.getEntityModifier( event ).read( 0 ); //Lets just make sure if( entity instanceof Item ) { ItemStack item = ( (Item) entity ).getItemStack(); if( plugin.getGlintManager().isGlintDisabled( event.getPlayer().getUniqueId() ) ) { GlintUtils.removeGlint( item ); } } } }
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) public void onPlayerFish(PlayerFishEvent event) { if (event.getState() != PlayerFishEvent.State.CAUGHT_FISH) { return; } Player player = event.getPlayer(); NormalAchievements category; Item caughtItem = (Item) event.getCaught(); if (caughtItem.getItemStack().getType() == Material.RAW_FISH) { category = NormalAchievements.FISH; } else { category = NormalAchievements.TREASURES; } if (plugin.getDisabledCategorySet().contains(category.toString())) { return; } if (!shouldIncreaseBeTakenIntoAccount(player, category)) { return; } updateStatisticAndAwardAchievementsIfAvailable(player, category, 1); }
@EventHandler(ignoreCancelled = true) public void onNPCSpawn(NPCSpawnEvent event) { Entity npc = event.getNpc(); if (hasData(event.getData(), NPCProperties.MAX_HEALTH)) { if (npc instanceof LivingEntity) { ((LivingEntity) npc).setMaxHealth(Double.MAX_VALUE); ((LivingEntity) npc).setHealth(Double.MAX_VALUE); entities.add(npc); } else if (npc instanceof Item) { setItemMax(((Item) npc)); entities.add(npc); } else { warn("%s is not a %s, thus the %s property was ignored.", event.getData().getId(), "living entity or item", NPCProperties.MAX_HEALTH); } } if (hasData(event.getData(), NPCProperties.INVULNERABLE)) { if (npc instanceof LivingEntity) { setMetadata(event, this.invulnerable, true); } else { warn("%s is not a %s, thus the %s property was ignored.", event.getData().getId(), "living entity", NPCProperties.INVULNERABLE); } } }
@Override public void run() { Iterator<Entity> it = entities.iterator(); while (it.hasNext()) { Entity npc = it.next(); if (!npc.isValid()) { it.remove(); continue; } if (npc instanceof Item) { setItemMax(((Item) npc)); } else if (npc instanceof LivingEntity) { ((LivingEntity) npc).setMaxHealth(Double.MAX_VALUE); ((LivingEntity) npc).setHealth(Double.MAX_VALUE); } else { warn("%s somehow got into the MaxHeathTask. Removing it from the List...", getDataName(npc)); it.remove(); } } }
public static void teleportEntity() { final List<BungeeQueue> entityQueue = Plugin.bungeeCordEntityInQueue; final Iterator<BungeeQueue> it = entityQueue.iterator(); while (it.hasNext()) { final BungeeQueue queue = it.next(); // Spawn incoming BungeeCord entity final Location destination = queue.getDestination(); final World world = destination.getWorld(); checkChunkLoad(destination.getBlock()); if (queue.getEntityType().isSpawnable()) { final Entity entity = world.spawnEntity(destination, queue.getEntityType()); // Entity EntityUtil.setEntityTypeData(entity, queue.getEntityTypeData()); entity.teleport(destination); } else if (queue.getEntityType() == EntityType.DROPPED_ITEM) { final Item item = world.dropItemNaturally(destination, ItemStackUtil.stringToItemStack(queue.getEntityTypeData())[0]); // Dropped // ItemStack item.teleport(destination); } // Remove from queue it.remove(); } }
@EventHandler(priority = EventPriority.NORMAL) public void onItemSpawn(final ItemSpawnEvent event) { if (event.isCancelled()) return; final Entity item = event.getEntity(); if (item.getType() != EntityType.DROPPED_ITEM || ((Item) item).getItemStack().getType() != Material.SUGAR_CANE) return; // Stop sugarcane block from decaying (workaround for lack of 1.7.2-R0.1 physics support) final WorldCoord coord = new WorldCoord((Item) item); final Gate nearestGate = Gates.gateFromPortal(coord); if (nearestGate != null) { if (nearestGate.getMaterial() != Material.SUGAR_CANE_BLOCK) return; event.getEntity().remove(); plugin.getServer().getScheduler().scheduleSyncDelayedTask(Plugin.instance, new Runnable() { @Override public void run() { coord.getBlock().setType(Material.SUGAR_CANE_BLOCK); } }, 1); } }
@EventHandler public void onPickup(PlayerPickupItemEvent e){ Item item = e.getItem(); if(item.getCustomName()!=null) { String name = ChatColor.stripColor(item.getCustomName()); // if(name!=null && ChatColor.stripColor(language.get("nameSyntax")).replace("{money}", "").equals(name.replaceAll(regex, ""))){ e.setCancelled(true); String money = plugin.getMoney(name); Player p = e.getPlayer(); if (p.hasPermission("PickupMoney.pickup")) { item.remove(); float amount = Float.parseFloat(money); if(plugin.pickupMulti.containsKey(p.getUniqueId())) amount*=plugin.pickupMulti.get(p.getUniqueId()); plugin.giveMoney(amount, p); p.sendMessage(plugin.language.get("pickup").replace("{money}", String.valueOf(amount))); if (plugin.fc.getBoolean("sound.enable")) { p.getLocation().getWorld().playSound(p.getLocation(), Sound.valueOf(plugin.fc.getString("sound.type")) , (float) plugin.fc.getDouble("sound.volumn") , (float) plugin.fc.getDouble("sound.pitch")); } } // } } }
@EventHandler(priority=EventPriority.LOWEST) public void onItemSpawn(ItemSpawnEvent event) { Item entity = event.getEntity(); Chunk chunk = entity.getLocation().getChunk(); if (chunk == lastChunk) { event.getEntity().remove(); event.setCancelled(true); return; } if (!PlotSquared.isPlotWorld(chunk.getWorld().getName())) { return; } Entity[] entities = chunk.getEntities(); if (entities.length > Settings.CHUNK_PROCESSOR_MAX_ENTITIES) { event.getEntity().remove(); event.setCancelled(true); lastChunk = chunk; } else { lastChunk = null; } }
@EventHandler(priority = EventPriority.MONITOR) public void OnChunkUnload(ChunkUnloadEvent event) { BonusGoodie goodie; for (Entity entity : event.getChunk().getEntities()) { if (!(entity instanceof Item)) { continue; } goodie = CivGlobal.getBonusGoodie(((Item)entity).getItemStack()); if (goodie == null) { continue; } goodie.replenish(((Item)entity).getItemStack(), (Item)entity, null, null); } }
@EventHandler(priority = EventPriority.MONITOR) public void OnItemSpawn(ItemSpawnEvent event) { Item item = event.getEntity(); BonusGoodie goodie = CivGlobal.getBonusGoodie(item.getItemStack()); if (goodie == null) { return; } // Cant validate here, validate in drop item events... goodie.setItem(item); try { goodie.update(false); goodie.updateLore(item.getItemStack()); } catch (CivException e) { e.printStackTrace(); } }
private void checkPedestal(Block pedestal) { Item item = AncientAltarListener.findItem(pedestal); if (item == null) abort(); else { particles.add(pedestal.getLocation().add(0.5, 1.5, 0.5)); items.add(AncientAltarListener.fixItemStack(item.getItemStack(), item.getCustomName())); pedestal.getWorld().playSound(pedestal.getLocation(), Sound.ENTITY_ENDERMEN_TELEPORT, 5F, 2F); try { ParticleEffect.ENCHANTMENT_TABLE.display(pedestal.getLocation().add(0.5, 1.5, 0.5), 0.3F, 0.2F, 0.3F, 0, 16); ParticleEffect.CRIT_MAGIC.display(pedestal.getLocation().add(0.5, 1.5, 0.5), 0.3F, 0.2F, 0.3F, 0, 8); } catch (Exception e) { e.printStackTrace(); } item.remove(); pedestal.removeMetadata("item_placed", SlimefunStartup.instance); } }
public void resetEntities(final String chunk) { Bukkit.getScheduler().callSyncMethod(SurvivalGames.instance, new Callable<Void>() { @Override public Void call() { String[] split = chunk.split(","); Chunk c = world.getChunkAt(Integer.parseInt(split[0]), Integer.parseInt(split[1])); boolean l = c.isLoaded(); if(!l) c.load(); for(Entity e : c.getEntities()) { if(e instanceof Item || e instanceof LivingEntity || e instanceof Arrow) { e.remove(); } } if(!l) c.unload(); return null; } }); }