use of org.bukkit.entity.Vehicle in project RedProtect by FabioZumbi12.
the class RPBlockListener method onVehicleBreak.
@EventHandler
public void onVehicleBreak(VehicleDestroyEvent e) {
RedProtect.get().logger.debug("RPBlockListener - Is VehicleDestroyEvent event");
if (e.isCancelled()) {
return;
}
if (!(e.getAttacker() instanceof Player)) {
return;
}
Vehicle cart = e.getVehicle();
Player p = (Player) e.getAttacker();
Region r = RedProtect.get().rm.getTopRegion(cart.getLocation());
if (r != null && !r.canMinecart(p)) {
RPLang.sendMessage(p, "blocklistener.region.cantbreak");
e.setCancelled(true);
}
}
use of org.bukkit.entity.Vehicle in project CommandHelper by EngineHub.
the class BukkitConvertor method BukkitGetCorrectEntity.
// /**
// * We don't want to allow scripts to clear other plugin's tasks
// * on accident, so only ids registered through our interface
// * can also be cancelled.
// */
// private static final Set<Integer> validIDs = new TreeSet<Integer>();
//
// @Override
// public synchronized int SetFutureRunnable(DaemonManager dm, long ms, Runnable r) {
// int id = Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(CommandHelperPlugin.self, r, Static.msToTicks(ms));
// validIDs.add(id);
// return id;
// }
//
// @Override
// public synchronized int SetFutureRepeater(DaemonManager dm, long ms, long initialDelay, Runnable r){
// int id = Bukkit.getServer().getScheduler().scheduleSyncRepeatingTask(CommandHelperPlugin.self, r, Static.msToTicks(initialDelay), Static.msToTicks(ms));
// validIDs.add(id);
// return id;
// }
//
// @Override
// public synchronized void ClearAllRunnables() {
// //Doing cancelTasks apparently does not work, so let's just manually cancel each task, which does appear to work.
// //Anyways, it's better that way anyhow, because we actually remove IDs from validIDs that way.
// //((BukkitMCServer)Static.getServer()).__Server().getScheduler().cancelTasks(CommandHelperPlugin.self);
// Set<Integer> ids = new TreeSet<Integer>(validIDs);
// for(int id : ids){
// try{
// //If this doesn't work, it shouldn't kill everything.
// ClearFutureRunnable(id);
// } catch(Exception e){
// Logger.getLogger(BukkitConvertor.class.getName()).log(null, Level.SEVERE, e);
// }
// }
// }
//
// @Override
// public void ClearFutureRunnable(int id) {
// if(validIDs.contains(id)){
// Bukkit.getServer().getScheduler().cancelTask(id);
// validIDs.remove(id);
// }
// }
public static MCEntity BukkitGetCorrectEntity(Entity be) {
if (be == null) {
return null;
}
BukkitMCEntityType type = BukkitMCEntityType.valueOfConcrete(be.getType());
if (type.getWrapperClass() != null) {
return ReflectionUtils.newInstance(type.getWrapperClass(), new Class[] { Entity.class }, new Object[] { be });
}
if (be instanceof Hanging) {
type.setWrapperClass(BukkitMCHanging.class);
return new BukkitMCHanging(be);
}
if (be instanceof Minecart) {
// Must come before Vehicle
type.setWrapperClass(BukkitMCMinecart.class);
return new BukkitMCMinecart(be);
}
if (be instanceof Projectile) {
type.setWrapperClass(BukkitMCProjectile.class);
return new BukkitMCProjectile(be);
}
if (be instanceof Tameable) {
// Must come before Ageable
type.setWrapperClass(BukkitMCTameable.class);
return new BukkitMCTameable(be);
}
if (be instanceof Ageable) {
// Must come before LivingEntity
type.setWrapperClass(BukkitMCAgeable.class);
return new BukkitMCAgeable(be);
}
if (be instanceof HumanEntity) {
// Must come before LivingEntity
type.setWrapperClass(BukkitMCHumanEntity.class);
return new BukkitMCHumanEntity(be);
}
if (be instanceof ComplexEntityPart) {
type.setWrapperClass(BukkitMCComplexEntityPart.class);
return new BukkitMCComplexEntityPart(be);
}
if (be instanceof ComplexLivingEntity) {
// Must come before LivingEntity
type.setWrapperClass(BukkitMCComplexLivingEntity.class);
return new BukkitMCComplexLivingEntity(be);
}
if (be instanceof LivingEntity) {
type.setWrapperClass(BukkitMCLivingEntity.class);
return new BukkitMCLivingEntity(be);
}
if (be instanceof Vehicle) {
type.setWrapperClass(BukkitMCVehicle.class);
return new BukkitMCVehicle(be);
}
// Handle generically if we can't find a more specific type
type.setWrapperClass(BukkitMCEntity.class);
return new BukkitMCEntity(be);
}
use of org.bukkit.entity.Vehicle in project askyblock by tastybento.
the class SafeBoat method onClick.
/**
* @param e - event
* This event check throws the boat at a player when they hit it
* unless someone is in it
*/
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
public void onClick(VehicleDamageEvent e) {
// plugin.getLogger().info("Damage event " + e.getDamage());
// Find out what block is being clicked
Vehicle boat = e.getVehicle();
if (!(boat instanceof Boat)) {
return;
}
if (!boat.isEmpty()) {
return;
}
final World playerWorld = boat.getWorld();
if (!playerWorld.getName().equalsIgnoreCase(Settings.worldName)) {
// Not the right world
return;
}
// Find out who is doing the clicking
if (!(e.getAttacker() instanceof Player)) {
// If a creeper blows up the boat, tough cookies!
return;
}
Player p = (Player) e.getAttacker();
if (p == null) {
return;
}
// Try to remove the boat and throw it at the player
Location boatSpot = new Location(boat.getWorld(), boat.getLocation().getX(), boat.getLocation().getY() + 2, boat.getLocation().getZ());
Location throwTo = new Location(boat.getWorld(), p.getLocation().getX(), p.getLocation().getY() + 1, p.getLocation().getZ());
ItemStack newBoat = new ItemStack(Material.BOAT, 1);
// Find the direction the boat should move in
Vector dir = throwTo.toVector().subtract(boatSpot.toVector()).normalize();
dir = dir.multiply(0.5);
Entity newB = boat.getWorld().dropItem(boatSpot, newBoat);
newB.setVelocity(dir);
boat.remove();
e.setCancelled(true);
}
use of org.bukkit.entity.Vehicle in project Statz by Staartvin.
the class DistanceTravelledVehicleListener method onMove.
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onMove(final VehicleMoveEvent event) {
final PlayerStat stat = PlayerStat.DISTANCE_TRAVELLED;
Vehicle vehicle = event.getVehicle();
if (vehicle.getPassenger() == null)
return;
// Get player
final Player player;
String movementType;
if (vehicle.getPassenger() instanceof Player) {
player = (Player) vehicle.getPassenger();
movementType = StatzUtil.getMovementType(player);
} else {
// No passenger on the passenger
if (vehicle.getPassenger().getPassenger() == null)
return;
// There is no player riding.
if (!(vehicle.getPassenger().getPassenger() instanceof Player))
return;
player = (Player) vehicle.getPassenger().getPassenger();
movementType = StatzUtil.getMovementType(player);
}
// No player found, no movementType found.
if (player == null || movementType == null)
return;
// Do general check
if (!plugin.doGeneralCheck(player, stat))
return;
final double distTravelled = event.getFrom().distance(event.getTo());
if (distTravelled == 0) {
return;
}
final String movement = movementType;
// Update value to new stat.
plugin.getDataManager().setPlayerInfo(player.getUniqueId(), stat, StatzUtil.makeQuery("uuid", player.getUniqueId().toString(), "value", distTravelled, "moveType", movement, "world", player.getWorld().getName()));
}
use of org.bukkit.entity.Vehicle in project Prism-Bukkit by prism.
the class PrismVehicleEvents method onVehicleCreate.
/**
* VehicleCreateEvent.
*
* @param event VehicleCreateEvent
*/
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onVehicleCreate(final VehicleCreateEvent event) {
final Vehicle vehicle = event.getVehicle();
final Location loc = vehicle.getLocation();
final String coord_key = loc.getBlockX() + ":" + loc.getBlockY() + ":" + loc.getBlockZ();
String value = plugin.preplannedVehiclePlacement.get(coord_key);
UUID uuid = null;
try {
uuid = UUID.fromString(value);
} catch (Exception ignored) {
// ignored.
}
final OfflinePlayer player = uuid != null ? Bukkit.getOfflinePlayer(uuid) : null;
if (player != null) {
// TODO: name ref
if (!Prism.getIgnore().event("vehicle-place", loc.getWorld(), player.getName())) {
return;
}
RecordingQueue.addToQueue(ActionFactory.createVehicle("vehicle-place", vehicle, player));
}
}
Aggregations