@Override public String asString() { return this.value.asString(); }
private Player getPlayerFromFurnace(Block furnaceBlock) { List<MetadataValue> metadata = furnaceBlock.getMetadata(mcMMO.furnaceMetadataKey); if (metadata.isEmpty()) { return null; } return plugin.getServer().getPlayerExact(metadata.get(0).asString()); } }
private Player getPlayerFromFurnace(Block furnaceBlock) { List<MetadataValue> metadata = furnaceBlock.getMetadata(mcMMO.furnaceMetadataKey); if (metadata.isEmpty()) { return null; } return plugin.getServer().getPlayerExact(metadata.get(0).asString()); }
public MobHealthDisplayUpdaterTask(LivingEntity target) { if (target.isValid()) { this.target = target; this.oldName = target.getMetadata(mcMMO.customNameKey).get(0).asString(); this.oldNameVisible = target.getMetadata(mcMMO.customVisibleKey).get(0).asBoolean(); } }
@Override public void run(String playerID) throws QuestRuntimeException { Location location = loc.getLocation(playerID); final double radius_squared = this.radius.getDouble(playerID) * this.radius.getDouble(playerID); location .getWorld() .getEntitiesByClass(type.getEntityClass()) .stream() //get only nearby entities .filter(entity -> entity.getLocation().distanceSquared(location) <= radius_squared) //only entities with given name .filter(entity -> { if (name == null) return true; return name.equals(entity.getName()); }) //only entities marked .filter(entity -> { if (marked == null) return true; return entity .getMetadata("betonquest-marked") .stream() .anyMatch(metadataValue -> metadataValue.asString().equals(marked)); }) //remove them .forEach(Entity::remove); } }
@EventHandler public void onEntityDeath(EntityDeathEvent event) { int i = 0; while (event.getEntity().hasMetadata("betonquest-drops-" + i)) { try { List<MetadataValue> metadata = event.getEntity().getMetadata("betonquest-drops-" + i); for (MetadataValue m : metadata) { String item = m.asString(); int index = item.indexOf(':'); event.getDrops().add(new QuestItem(new ItemID(null, item.substring(0, index))) .generate(Integer.valueOf(item.substring(index + 1)))); } } catch (Exception e) { Debug.error("Error when dropping custom item from entity: " + e.getMessage()); } i++; } }
public static boolean processBlastMiningExplosion(EntityDamageByEntityEvent event, TNTPrimed tnt, Player defender) { if (!tnt.hasMetadata(mcMMO.tntMetadataKey) || !UserManager.hasPlayerDataKey(defender)) { return false; } // We can make this assumption because we (should) be the only ones using this exact metadata Player player = mcMMO.p.getServer().getPlayerExact(tnt.getMetadata(mcMMO.tntMetadataKey).get(0).asString()); if (!player.equals(defender)) { return false; } MiningManager miningManager = UserManager.getPlayer(defender).getMiningManager(); if (!miningManager.canUseDemolitionsExpertise()) { return false; } event.setDamage(DamageModifier.BASE, miningManager.processDemolitionsExpertise(event.getDamage())); if (event.getFinalDamage() == 0) { event.setCancelled(true); return false; } return true; } }
if (!m.asString().equals(marked)) { continue loop;
if (!m.asString().equals(marked)) { return false;
if (!m.asString().equals(marked)) { return;
/** * Monitor EntityDeath events. * * @param event * The event to watch */ @EventHandler(priority = EventPriority.LOWEST) public void onEntityDeathLowest(EntityDeathEvent event) { /* WORLD BLACKLIST CHECK */ if(WorldBlacklist.isWorldBlacklisted(event.getEntity().getWorld())) return; LivingEntity entity = event.getEntity(); if (Misc.isNPCEntity(entity)) { return; } if (entity.hasMetadata(mcMMO.customNameKey)) { entity.setCustomName(entity.getMetadata(mcMMO.customNameKey).get(0).asString()); entity.removeMetadata(mcMMO.customNameKey, plugin); } if (entity.hasMetadata(mcMMO.customVisibleKey)) { entity.setCustomNameVisible(entity.getMetadata(mcMMO.customVisibleKey).get(0).asBoolean()); entity.removeMetadata(mcMMO.customVisibleKey, plugin); } if (entity.hasMetadata(mcMMO.entityMetadataKey)) { entity.removeMetadata(mcMMO.entityMetadataKey, plugin); } }
if (!m.asString().equals(marked)) { continue loop;
Player player = plugin.getServer().getPlayerExact(entity.getMetadata(mcMMO.tntMetadataKey).get(0).asString());
@Test public void getMetadata_MultipleMetaDataSetByMultiplePlugins_TwoMetadataValuesFound() { MockPlugin plugin1 = MockBukkit.createMockPlugin(); TestPlugin plugin2 = MockBukkit.load(TestPlugin.class); assertFalse(mt.hasMetadata("MyMetadata")); mt.setMetadata("MyMetadata", new FixedMetadataValue(plugin1, "wee")); mt.setMetadata("MyMetadata", new FixedMetadataValue(plugin1, "woo")); mt.setMetadata("MyMetadata", new FixedMetadataValue(plugin2, "also wee")); assertTrue(mt.hasMetadata("MyMetadata")); List<MetadataValue> metadata = mt.getMetadata("MyMetadata"); assertEquals(2, metadata.size()); MetadataValue value1 = metadata.get(0); MetadataValue value2 = metadata.get(1); if (value1.getOwningPlugin() == plugin2) { value2 = value1; value1 = metadata.get(1); } assertEquals("woo", value1.asString()); assertEquals(plugin1, value1.getOwningPlugin()); assertEquals("also wee", value2.asString()); assertEquals(plugin2, value2.getOwningPlugin()); }
if (!player.getName().equals(drop.getMetadata(mcMMO.disarmedItemKey).get(0).asString())) { event.setCancelled(true);
Player player = plugin.getServer().getPlayerExact(entity.getMetadata(mcMMO.tntMetadataKey).get(0).asString());