use of org.bukkit.entity.Boat in project acidisland 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 RedProtect by FabioZumbi12.
the class RPGlobalListener method onPlayerInteract.
@EventHandler
public void onPlayerInteract(PlayerInteractEntityEvent e) {
if (e.isCancelled()) {
return;
}
Player p = e.getPlayer();
Entity ent = e.getRightClicked();
Location l = ent.getLocation();
Region r = RedProtect.get().rm.getTopRegion(l);
if (r != null) {
return;
}
if (ent instanceof ItemFrame || ent instanceof Painting) {
if (!bypassBuild(p, null, 0)) {
e.setCancelled(true);
return;
}
}
if (ent instanceof Minecart || ent instanceof Boat) {
if (!RPConfig.getGlobalFlagBool(l.getWorld().getName() + ".use-minecart") && !p.hasPermission("redprotect.bypass.world")) {
e.setCancelled(true);
return;
}
}
if (!RPConfig.getGlobalFlagBool(l.getWorld().getName() + ".interact") && !p.hasPermission("redprotect.bypass.world") && (!(ent instanceof Player))) {
if (RPConfig.getGlobalFlagList(p.getWorld().getName() + ".if-interact-false.allow-entities").contains(ent.getType().name())) {
return;
}
e.setCancelled(true);
}
}
use of org.bukkit.entity.Boat in project RedProtect by FabioZumbi12.
the class RPGlobalListener method onEntityDamageEntity.
@EventHandler
public void onEntityDamageEntity(EntityDamageByEntityEvent e) {
if (e.isCancelled()) {
return;
}
Entity e1 = e.getEntity();
Entity e2 = e.getDamager();
Location loc = e1.getLocation();
Region r1 = RedProtect.get().rm.getTopRegion(loc);
if (r1 != null) {
return;
}
if (e2 instanceof Creeper || e2.getType().equals(EntityType.PRIMED_TNT) || e2.getType().equals(EntityType.MINECART_TNT)) {
if (e1 instanceof Player) {
if (!RPConfig.getGlobalFlagBool(loc.getWorld().getName() + ".explosion-entity-damage")) {
e.setCancelled(true);
return;
}
}
if (e1 instanceof Animals || e1 instanceof Villager || e1 instanceof Golem) {
if (!RPConfig.getGlobalFlagBool(loc.getWorld().getName() + ".explosion-entity-damage")) {
e.setCancelled(true);
return;
}
}
if (e1 instanceof Monster) {
if (!RPConfig.getGlobalFlagBool(loc.getWorld().getName() + ".explosion-entity-damage")) {
e.setCancelled(true);
return;
}
}
}
if (e2 instanceof Player) {
Player p = (Player) e2;
if (e.getCause().equals(DamageCause.LIGHTNING) || e.getCause().equals(DamageCause.BLOCK_EXPLOSION) || e.getCause().equals(DamageCause.ENTITY_EXPLOSION)) {
if (!RPConfig.getGlobalFlagBool(loc.getWorld().getName() + ".entity-block-damage")) {
e.setCancelled(true);
return;
}
}
if ((e1 instanceof Minecart || e1 instanceof Boat) && !RPConfig.getGlobalFlagBool(loc.getWorld().getName() + ".use-minecart") && !p.hasPermission("redprotect.bypass.world")) {
e.setCancelled(true);
return;
}
if (e1 instanceof Player) {
if (!RPConfig.getGlobalFlagBool(loc.getWorld().getName() + ".pvp") && !p.hasPermission("redprotect.bypass.world")) {
e.setCancelled(true);
return;
}
}
if (e1 instanceof Animals || e1 instanceof Villager || e1 instanceof Golem) {
if (!RPConfig.getGlobalFlagBool(loc.getWorld().getName() + ".player-hurt-passives") && !p.hasPermission("redprotect.bypass.world")) {
e.setCancelled(true);
return;
}
}
if (e1 instanceof Monster) {
if (!RPConfig.getGlobalFlagBool(loc.getWorld().getName() + ".player-hurt-monsters") && !p.hasPermission("redprotect.bypass.world")) {
e.setCancelled(true);
return;
}
}
if (e1 instanceof Hanging || e1 instanceof EnderCrystal || e1 instanceof ArmorStand) {
if (!RPConfig.getGlobalFlagList(p.getWorld().getName() + ".if-build-false.break-blocks").contains(e1.getType().name()) && !bypassBuild(p, null, 0)) {
e.setCancelled(true);
return;
}
}
}
if (e2 instanceof Projectile) {
Projectile proj = (Projectile) e2;
if (proj.getShooter() instanceof Player) {
Player p = (Player) proj.getShooter();
if (e1 instanceof Player) {
if (!RPConfig.getGlobalFlagBool(loc.getWorld().getName() + ".pvp") && !p.hasPermission("redprotect.bypass.world")) {
e.setCancelled(true);
return;
}
}
if (e1 instanceof Animals || e1 instanceof Villager || e1 instanceof Golem) {
if (!RPConfig.getGlobalFlagBool(loc.getWorld().getName() + ".player-hurt-passives") && !p.hasPermission("redprotect.bypass.world")) {
e.setCancelled(true);
return;
}
}
if (e1 instanceof Monster) {
if (!RPConfig.getGlobalFlagBool(loc.getWorld().getName() + ".player-hurt-monsters") && !p.hasPermission("redprotect.bypass.world")) {
e.setCancelled(true);
return;
}
}
if (e1 instanceof Hanging || e1 instanceof EnderCrystal || e1 instanceof ArmorStand) {
if (!RPConfig.getGlobalFlagList(p.getWorld().getName() + ".if-build-false.break-blocks").contains(e1.getType().name()) && !bypassBuild(p, null, 0)) {
e.setCancelled(true);
}
}
}
}
}
use of org.bukkit.entity.Boat in project RedProtect by FabioZumbi12.
the class RPPlayerListener method onPlayerInteract.
@EventHandler(priority = EventPriority.LOWEST)
public void onPlayerInteract(PlayerInteractEntityEvent event) {
Entity e = event.getRightClicked();
Player p = event.getPlayer();
if (e == null) {
return;
}
RedProtect.get().logger.debug("RPPlayerListener - Is PlayerInteractEntityEvent event: " + e.getType().name());
Location l = e.getLocation();
if (e instanceof ItemFrame || e instanceof Painting) {
Region r = RedProtect.get().rm.getTopRegion(l);
if (r != null && !r.canBuild(p)) {
RPLang.sendMessage(p, "playerlistener.region.cantedit");
event.setCancelled(true);
}
} else if ((e instanceof Minecart || e instanceof Boat)) {
Region r = RedProtect.get().rm.getTopRegion(l);
if (r != null && !r.canMinecart(p)) {
RPLang.sendMessage(p, "blocklistener.region.cantenter");
event.setCancelled(true);
}
} else if (RedProtect.get().MyPet && e instanceof MyPetBukkitEntity) {
if (((MyPetBukkitEntity) e).getOwner().getPlayer().equals(p)) {
}
} else if (!RPUtil.isBukkitEntity(e) && (!(event.getRightClicked() instanceof Player))) {
Region r = RedProtect.get().rm.getTopRegion(l);
if (r != null && !r.allowMod(p)) {
RedProtect.get().logger.debug("PlayerInteractEntityEvent - Block is " + event.getRightClicked().getType().name());
RPLang.sendMessage(p, "playerlistener.region.cantinteract");
event.setCancelled(true);
}
}
}
use of org.bukkit.entity.Boat in project Glowstone by GlowstoneMC.
the class VehicleMoveHandler method handle.
@Override
public void handle(GlowSession session, VehicleMoveMessage message) {
GlowPlayer player = session.getPlayer();
if (!player.isInsideVehicle() || !(player.getVehicle() instanceof Vehicle)) {
return;
}
GlowEntity vehicle = (GlowEntity) player.getVehicle();
Location oldLocation = vehicle.getLocation();
Location newLocation = oldLocation.clone();
message.update(newLocation);
// don't let players reach an illegal position
if (Math.abs(newLocation.getBlockX()) > 32000000 || Math.abs(newLocation.getBlockZ()) > 32000000) {
session.getPlayer().kickPlayer("Illegal position");
return;
}
/*
don't let players move more than 100 blocks in a single packet
if they move greater than 10 blocks, but less than 100, just warn
this is NOT robust hack prevention - only to prevent client
confusion about where its actual location is (e.g. during login)
*/
if (Position.hasMoved(oldLocation, newLocation) && !player.isDead() && !vehicle.isDead()) {
double distance = newLocation.distanceSquared(oldLocation);
if (distance > 100 * 100) {
session.getPlayer().kickPlayer("You moved too quickly :( (Hacking?)");
return;
} else if (distance > 100) {
GlowServer.logger.warning(session.getPlayer().getName() + " moved too quickly!");
}
}
if (!isValidMovement(vehicle, oldLocation, newLocation)) {
vehicle.teleport(oldLocation);
return;
}
// call move event if movement actually occurred and there are handlers registered
if (!oldLocation.equals(newLocation) && VehicleMoveEvent.getHandlerList().getRegisteredListeners().length > 0) {
EventFactory.getInstance().callEvent(new VehicleMoveEvent((Vehicle) vehicle, oldLocation, newLocation.clone()));
}
// simply update location
vehicle.setRawLocation(newLocation);
player.setRawLocation(vehicle.getMountLocation());
// track movement stats
Vector delta = newLocation.clone().subtract(oldLocation).toVector();
delta.setX(Math.abs(delta.getX()));
delta.setY(Math.abs(delta.getY()));
delta.setZ(Math.abs(delta.getZ()));
int flatDistance = (int) Math.round(Math.hypot(delta.getX(), delta.getZ()) * 100.0);
if (vehicle instanceof Boat) {
player.incrementStatistic(Statistic.BOAT_ONE_CM, flatDistance);
} else if (vehicle instanceof Minecart) {
player.incrementStatistic(Statistic.MINECART_ONE_CM, flatDistance);
}
}
Aggregations