下面列出了怎么用org.bukkit.event.vehicle.VehicleCreateEvent的API类实例代码及写法,或者点击链接到github查看源代码。
@EventHandler
public void onVehicleSpawn(VehicleCreateEvent event) {
final Vehicle vehicle = event.getVehicle();
final IslandManager islandManager = IridiumSkyblock.getIslandManager();
final Location location = vehicle.getLocation();
final Island island = islandManager.getIslandViaLocation(location);
if (island == null) return;
if (!IridiumSkyblock.getConfiguration().blockedEntities.contains(vehicle.getType())) return;
IridiumSkyblock.getInstance().entities.put(vehicle.getUniqueId(), island);
monitorEntity(vehicle);
}
public static VehicleCreateEvent callVehicleCreateEvent(Entity entity) {
Vehicle bukkitEntity = (Vehicle) entity.getBukkitEntity();
VehicleCreateEvent event = new VehicleCreateEvent(bukkitEntity);
Bukkit.getPluginManager().callEvent(event);
return event;
}
/**
* Handles minecart placing
* @param e - event
*/
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
public void onMinecart(VehicleCreateEvent e) {
if (DEBUG) {
plugin.getLogger().info("DEBUG: " + e.getEventName());
plugin.getLogger().info("DEBUG: Vehicle type = " + e.getVehicle().getType());
}
if (!IslandGuard.inWorld(e.getVehicle())) {
if (DEBUG)
plugin.getLogger().info("DEBUG: Not in world");
return;
}
if (DEBUG)
plugin.getLogger().info("DEBUG: Checking entity types");
if (Settings.entityLimits.containsKey(e.getVehicle().getType())) {
// If someone in that area has the bypass permission, allow the spawning
for (Entity entity : e.getVehicle().getLocation().getWorld().getNearbyEntities(e.getVehicle().getLocation(), 5, 5, 5)) {
if (entity instanceof Player) {
Player player = (Player)entity;
Boolean bypass = false;
if (player.isOp() || VaultHelper.checkPerm(player, Settings.PERMPREFIX + "mod.bypass")) {
if (DEBUG)
plugin.getLogger().info("DEBUG: op or bypass");
bypass = true;
}
// Check island
Island island = plugin.getGrid().getProtectedIslandAt(e.getVehicle().getLocation());
if (island == null) {
// Only count island entities
if (DEBUG)
plugin.getLogger().info("DEBUG: island is null");
return;
}
// Ignore spawn
if (island.isSpawn()) {
if (DEBUG)
plugin.getLogger().info("DEBUG: ignore spawn");
return;
}
if (DEBUG)
plugin.getLogger().info("DEBUG: Checking entity limits");
// Check if the player is at the limit
if (atLimit(island, bypass, e.getVehicle())) {
e.setCancelled(true);
for (Entity ent : e.getVehicle().getLocation().getWorld().getNearbyEntities(e.getVehicle().getLocation(), 5, 5, 5)) {
if (ent instanceof Player) {
Util.sendMessage((Player)ent, ChatColor.RED
+ (plugin.myLocale(player.getUniqueId()).entityLimitReached.replace("[entity]",
Util.prettifyText(e.getVehicle().getType().toString()))
.replace("[number]", String.valueOf(Settings.entityLimits.get(e.getVehicle().getType())))));
}
}
}
}
}
}
}