Java Code Examples for org.bukkit.metadata.MetadataValue#value()

The following examples show how to use org.bukkit.metadata.MetadataValue#value() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MapInteractEvent.java    From MapManager with MIT License 6 votes vote down vote up
/**
 * @return the {@link MapWrapper} of the clicked frame
 */
public MapWrapper getMapWrapper() {
	if (this.mapWrapper != null) { return this.mapWrapper; }
	ItemFrame itemFrame = getItemFrame();
	if (itemFrame != null) {
		if (itemFrame.hasMetadata("MAP_WRAPPER_REF")) {
			List<MetadataValue> metadataValues = itemFrame.getMetadata("MAP_WRAPPER_REF");
			for (MetadataValue value : metadataValues) {
				MapWrapper wrapper = (MapWrapper) value.value();
				if (wrapper != null) {
					return this.mapWrapper = wrapper;
				}
			}
		}
	}
	return null;
}
 
Example 2
Source File: ProjectileMatchModule.java    From PGM with GNU Affero General Public License v3.0 5 votes vote down vote up
public static @Nullable ProjectileDefinition getProjectileDefinition(Entity entity) {
  MetadataValue metadataValue = entity.getMetadata("projectileDefinition", PGM.get());

  if (metadataValue != null) {
    return (ProjectileDefinition) metadataValue.value();
  } else if (launchingDefinition.get() != null) {
    return launchingDefinition.get();
  } else {
    return null;
  }
}
 
Example 3
Source File: ListenerMobCombat.java    From CombatLogX with GNU General Public License v3.0 5 votes vote down vote up
private SpawnReason getSpawnReason(LivingEntity entity) {
    if(entity == null) return SpawnReason.DEFAULT;
    if(!entity.hasMetadata("combatlogx_spawn_reason")) return SpawnReason.DEFAULT;

    List<MetadataValue> spawnReasonValues = entity.getMetadata("combatlogx_spawn_reason");
    for(MetadataValue metadataValue : spawnReasonValues) {
        Object object = metadataValue.value();
        if(!(object instanceof SpawnReason)) continue;
        
        return (SpawnReason) object;
    }
    
    return SpawnReason.DEFAULT;
}
 
Example 4
Source File: FlagSplegg.java    From HeavySpleef with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler
public void onEntityExplode(EntityExplodeEvent event) {
	Entity entity = event.getEntity();
	
	Game game = null;
	List<MetadataValue> metadatas = entity.getMetadata(TNT_METADATA_KEY);
	for (MetadataValue value : metadatas) {
		if (value.getOwningPlugin() != getHeavySpleef().getPlugin()) {
			continue;
		}
		
		game = (Game) value.value();
	}
	
	if (game != null) {
		List<Block> blocks = event.blockList();
		for (Block block : blocks) {
			if (!game.canSpleef(block)) {
				continue;
			}
			
			block.setType(Material.AIR);
		}
		
		blocks.clear();
	}
}
 
Example 5
Source File: Database.java    From ScoreboardStats with MIT License 5 votes vote down vote up
public Optional<PlayerStats> getStats(Player request) {
    if (request != null) {
        for (MetadataValue metadata : request.getMetadata(METAKEY)) {
            if (metadata.value() instanceof PlayerStats) {
                return Optional.of((PlayerStats) metadata.value());
            }
        }
    }

    return Optional.empty();
}
 
Example 6
Source File: BlockListener.java    From MineTinker with GNU General Public License v3.0 4 votes vote down vote up
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onBlockBreak(BlockBreakEvent event) {
	Player player = event.getPlayer();
	ItemStack tool = player.getInventory().getItemInMainHand();

	if (Lists.WORLDS.contains(player.getWorld().getName())) {
		return;
	}

	if (event.getBlock().getType().getHardness() == 0 && !(tool.getType() == Material.SHEARS
			|| ToolType.HOE.contains(tool.getType()))) {
		return;
	}

	if (!modManager.isToolViable(tool)) {
		return;
	}

	FileConfiguration config = MineTinker.getPlugin().getConfig();

	//--------------------------------------EXP-CALCULATIONS--------------------------------------------
	if (player.getGameMode() != GameMode.CREATIVE) {
		long cooldown = MineTinker.getPlugin().getConfig().getLong("BlockExpCooldownInSeconds", 60) * 1000;
		boolean eligible = true;
		if (cooldown > 0) {
			List<MetadataValue> blockPlaced = event.getBlock().getMetadata("blockPlaced");
			for(MetadataValue val : blockPlaced) {
				if (val == null) continue;
				if (!MineTinker.getPlugin().equals(val.getOwningPlugin())) continue; //Not MTs value

				Object value = val.value();
				if (value instanceof Long) {
					long time = (long) value;
					eligible = System.currentTimeMillis() - cooldown > time;
					break;
				}
			}
		}

		if (eligible) {
			int expAmount = config.getInt("ExpPerBlockBreak");
			if (!(!config.getBoolean("ExtraExpPerBlock.ApplicableToSilkTouch")
					&& modManager.hasMod(tool, SilkTouch.instance()))) {
				expAmount += config.getInt("ExtraExpPerBlock." + event.getBlock().getType().toString());
				//adds 0 if not in found in config (negative values are also fine)
			}

			modManager.addExp(player, tool, expAmount);
		}
	}

	//-------------------------------------------POWERCHECK---------------------------------------------
	if (Power.HAS_POWER.get(player).get() && !ToolType.PICKAXE.contains(tool.getType())
			&& event.getBlock().getDrops(tool).isEmpty()
			&& event.getBlock().getType() != Material.NETHER_WART) { //Necessary for EasyHarvest NetherWard-Break

		event.setCancelled(true);
		return;
	}

	MTBlockBreakEvent breakEvent = new MTBlockBreakEvent(tool, event);
	Bukkit.getPluginManager().callEvent(breakEvent); //Event-Trigger for Modifiers
}
 
Example 7
Source File: Projectiles.java    From ProjectAres with GNU Affero General Public License v3.0 4 votes vote down vote up
static @Nullable ProjectileDefinition getProjectileDefinition(Entity entity) {
    final MetadataValue metadataValue = entity.getMetadata(METADATA_KEY, PGM.get());
    return metadataValue == null ? null : (ProjectileDefinition) metadataValue.value();
}