use of org.bukkit.entity.Boat in project askyblock by tastybento.
the class GridManager method homeTeleport.
/**
* Teleport player to a home location. If one cannot be found a search is done to
* find a safe place.
* @param player player object
* @param number - home location to do to
* @return true if successful, false if not
*/
@SuppressWarnings("deprecation")
public void homeTeleport(final Player player, int number) {
Location home = null;
// plugin.getLogger().info("home teleport called for #" + number);
home = getSafeHomeLocation(player.getUniqueId(), number);
// Check if the player is a passenger in a boat
if (player.isInsideVehicle()) {
Entity boat = player.getVehicle();
if (boat instanceof Boat) {
player.leaveVehicle();
// Remove the boat so they don't lie around everywhere
boat.remove();
player.getInventory().addItem(new ItemStack(Material.BOAT, 1));
player.updateInventory();
}
}
if (home == null) {
// plugin.getLogger().info("Fixing home location using safe spot teleport");
// Try to fix this teleport location and teleport the player if possible
new SafeTeleportBuilder(plugin).entity(player).location(plugin.getPlayers().getHomeLocation(player.getUniqueId(), number)).homeNumber(number).build();
return;
}
// plugin.getLogger().info("DEBUG: home loc = " + home + " teleporting");
// home.getChunk().load();
IslandPreTeleportEvent event = new IslandPreTeleportEvent(player, IslandPreTeleportEvent.Type.HOME, home);
Bukkit.getPluginManager().callEvent(event);
if (!event.isCancelled()) {
player.teleport(event.getLocation());
// player.sendBlockChange(home, Material.GLOWSTONE, (byte)0);
if (number == 1) {
Util.sendMessage(player, ChatColor.GREEN + plugin.myLocale(player.getUniqueId()).islandteleport);
} else {
Util.sendMessage(player, ChatColor.GREEN + plugin.myLocale(player.getUniqueId()).islandteleport + " #" + number);
}
}
plugin.getPlayers().setInTeleport(player.getUniqueId(), false);
}
use of org.bukkit.entity.Boat 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.Boat in project L2X9RebootCore by 254nm.
the class BoatFly method onPlayerMove.
// TODO Rewrite this dogshit code
@EventHandler
public void onPlayerMove(PlayerMoveEvent event) {
time++;
Player player = event.getPlayer();
double ax = 0.0D;
double ay = 0.0D;
double az = 0.0D;
if (time == 2) {
ax = player.getLocation().getX();
ay = player.getLocation().getY();
az = player.getLocation().getZ();
time = 0;
}
double x = 0.0D;
double y = 0.0D;
double z = 0.0D;
if (player.isInsideVehicle() && player.getVehicle() instanceof Boat) {
Boat boat = (Boat) player.getVehicle();
Material m = boat.getLocation().getBlock().getType();
if (m != Material.STATIONARY_WATER && m != Material.WATER && !boat.isOnGround()) {
if (!list.contains(player)) {
list.add(player);
x = player.getLocation().getX();
y = player.getLocation().getY();
z = player.getLocation().getZ();
}
if ((boat.getVelocity().getY() > 0.0D || boat.getVelocity().getY() < 0.12D) && list.contains(player))
if (x != 0.0D && y != 0.0D && z != 0.0D) {
boat.teleport(new Location(boat.getWorld(), x, y, z));
player.teleport(new Location(player.getWorld(), x, y + 0.5D, z));
boat.remove();
Utils.log("&3Prevented&r&a " + player.getName() + "&r&3 from boatflying");
list.remove(player);
} else {
boat.teleport(new Location(boat.getWorld(), ax, ay, az));
player.teleport(new Location(player.getWorld(), ax, ay, az));
}
}
}
}
use of org.bukkit.entity.Boat in project BuildPortals by jusdino.
the class BuildPortals method onCommand.
@Override
public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
if (cmd.getName().equalsIgnoreCase("buildportals") || cmd.getName().equalsIgnoreCase("bp")) {
if (args.length < 1) {
return false;
}
Material mat = null;
switch(args[0].toLowerCase()) {
case "version":
sender.sendMessage("This is BuildPortals version " + this.getDescription().getVersion());
return true;
case "check":
if (!(sender instanceof Player)) {
sender.sendMessage("Only a player can check their location.");
return false;
}
Player player = (Player) sender;
Location loc = player.getLocation().getBlock().getLocation();
if (player.getVehicle() instanceof Minecart) {
loc.add(0, 1, 0);
}
if (player.getVehicle() instanceof Boat) {
loc.add(0, 2, 0);
}
sender.sendMessage("Your location is: " + loc.toVector().toString());
if (Portal.isInAPortal(loc)) {
player.sendMessage("You ARE in a portal!");
} else {
player.sendMessage("You ARE NOT in a portal.");
}
return true;
case "setmaterial":
if (!sender.hasPermission("buildportals.*")) {
sender.sendMessage("You do not have permission to use this command.");
return true;
}
try {
mat = Material.getMaterial(args[1].toUpperCase());
} catch (NullPointerException | ArrayIndexOutOfBoundsException exc) {
sender.sendMessage("You must specify a material.");
}
if (mat == null) {
sender.sendMessage("Material name invalid.");
sender.sendMessage("Setting portal material failed.");
logger.warning("Setting portal material failed.");
return false;
}
if (!mat.isBlock()) {
sender.sendMessage("Material must be a placeable block type.");
sender.sendMessage("Setting portal material failed.");
logger.warning("Setting portal material failed.");
return false;
}
sender.sendMessage("Setting portal material to " + mat.name());
logger.info("Setting portal material to " + mat.name());
config.set("PortalMaterial", mat.name());
this.saveConfig();
sender.sendMessage("Converting existing portals to " + mat.name());
logger.info("Converting existing portals to " + mat.name());
Portal.loadPortalsFromConfig();
IncompletePortal.loadPortalsFromConfig();
return true;
case "listmaterial":
if (sender.hasPermission("buildportals.listmaterial")) {
String matName = config.getString("PortalMaterial");
sender.sendMessage("Portal material is: " + matName);
return true;
} else {
sender.sendMessage("You do not have permission to use this command.");
return true;
}
case "addactivator":
if (!sender.hasPermission("buildportals.*")) {
sender.sendMessage("You do not have permission to use this command.");
return true;
}
try {
mat = Material.getMaterial(args[1].toUpperCase());
} catch (NullPointerException | ArrayIndexOutOfBoundsException exc) {
sender.sendMessage("You must specify a material.");
}
if (mat == null) {
sender.sendMessage("Material name invalid.");
sender.sendMessage("Adding activator material failed.");
logger.warning("Adding activator material failed.");
return false;
}
if (!mat.isBlock()) {
sender.sendMessage("Material must be a placeable block type.");
sender.sendMessage("Adding activator material failed.");
logger.warning("Adding activator material failed.");
return false;
}
if (activatorMaterials.contains(mat)) {
sender.sendMessage("That is already an activator material.");
logger.warning(sender.getName() + " attempted to add an already configured activator material.");
return false;
}
activatorMaterials.add(mat);
sender.sendMessage("Adding " + mat.name() + " as an activator.");
logger.info("Adding " + mat.name() + " as an activator.");
config.set("PortalActivators", activatorMaterials);
this.saveConfig();
return true;
case "removeactivator":
if (!sender.hasPermission("buildportals.*")) {
sender.sendMessage("You do not have permission to use this command.");
return true;
}
try {
mat = Material.getMaterial(args[1].toUpperCase());
} catch (NullPointerException | ArrayIndexOutOfBoundsException exc) {
sender.sendMessage("You must specify a material.");
}
if (mat == null) {
sender.sendMessage("Removing activator material failed.");
logger.warning("Removing activator material failed.");
return false;
}
if (!activatorMaterials.contains(mat)) {
sender.sendMessage("That is not an activator material.");
logger.warning(sender.getName() + " attempted to remove to an unconfigured activator material.");
return false;
}
activatorMaterials.remove(mat);
sender.sendMessage("Removing " + mat.name() + " from activators.");
logger.info("Removing " + mat.name() + " from activators.");
config.set("PortalActivators", activatorMaterials);
this.saveConfig();
return true;
case "listactivators":
if (sender.hasPermission("buildportals.listactivators")) {
sender.sendMessage("Activators are: " + activatorMaterials);
return true;
} else {
sender.sendMessage("You do not have permission to use this command.");
return true;
}
default:
sender.sendMessage("BuildPortals command usage:");
sender.sendMessage(" /BP Version ");
sender.sendMessage(" Returns the BuildPortals Version info.");
sender.sendMessage(" /BP Check ");
sender.sendMessage(" Returns whether you are currently in a portal.");
sender.sendMessage(" /BP SetMaterial <Material_Name>");
sender.sendMessage(" Sets the material from which portals should be built. Note that this will change all existing portals to this material.");
sender.sendMessage(" /BP AddActivator <Material_Name>");
sender.sendMessage(" Adds to the list of activator materials.");
sender.sendMessage(" /BP RemoveActivator <Material_Name>");
sender.sendMessage(" Removes an activator material.");
sender.sendMessage(" /BP ListMaterial");
sender.sendMessage(" Lists the configured portal material.");
sender.sendMessage(" /BP ListActivators");
sender.sendMessage(" Lists all configured activator materials.");
return false;
}
}
return true;
}
use of org.bukkit.entity.Boat in project BuildPortals by jusdino.
the class Teleporter method teleport.
static Entity teleport(Entity entity, @Nonnull Location destination) {
BuildPortals.logger.log(BuildPortals.logLevel, "Entering teleport(Entity, ...) method");
if (entity instanceof Vehicle) {
List<Entity> passengers = (entity).getPassengers();
List<Entity> destPassengers = new ArrayList<>();
for (Entity passenger : passengers) {
if ((entity).removePassenger(passenger)) {
Entity destPassenger = teleport(passenger, destination);
if (destPassenger != null) {
destPassengers.add(destPassenger);
}
}
}
if (entity instanceof AbstractHorse) {
entity = teleport((AbstractHorse) entity, destination);
} else if (entity instanceof Minecart) {
entity = teleport((Minecart) entity, destination);
} else if (entity instanceof Boat) {
destination.add(0, 1, 0);
entity = teleport((Boat) entity, destination);
} else if (entity instanceof Pig) {
entity = teleport((Pig) entity, destination);
}
if (entity != null) {
for (Entity passenger : destPassengers) {
(entity).addPassenger(passenger);
}
}
return entity;
} else if (entity instanceof Player) {
Player player;
player = (Player) entity;
if (!player.hasPermission("buildportals.teleport")) {
player.sendMessage("You do not have permission to use portals!");
return null;
}
Location source = player.getLocation();
ArrayList<LivingEntity> leadees = new ArrayList<>();
// There doesn't seem to be an easy way to get a collection of leashed entities
// from the player directly...
World world = source.getWorld();
if (world == null) {
return null;
}
Collection<Entity> entities = world.getNearbyEntities(source, 11, 11, 11);
for (Entity ent : entities) {
if (ent instanceof LivingEntity) {
if (((LivingEntity) ent).isLeashed() && ((LivingEntity) ent).getLeashHolder() == entity) {
Entity destEnt = teleport(ent, destination);
leadees.add((LivingEntity) destEnt);
}
}
}
entity = teleport((Player) entity, destination);
for (LivingEntity ent : leadees) {
ent.setLeashHolder(entity);
}
} else if (entity instanceof Cow) {
entity = teleport((Cow) entity, destination);
} else if (entity instanceof Sheep) {
entity = teleport((Sheep) entity, destination);
} else if (entity instanceof PolarBear) {
entity = teleport((PolarBear) entity, destination);
} else if (entity instanceof Chicken) {
entity = teleport((Chicken) entity, destination);
} else if (entity instanceof Villager) {
entity = teleport((Villager) entity, destination);
} else {
// Bail on the teleport for unhandled Entities
return null;
}
return entity;
}
Aggregations