Add a RIDE flag for vehicles.

This commit is contained in:
sk89q 2015-01-04 17:52:32 -08:00
parent e61b2e18c1
commit c95b619974
3 changed files with 19 additions and 16 deletions

View File

@ -389,6 +389,11 @@ public void onUseEntity(UseEntityEvent event) {
canUse = query.testBuild(target, associable); canUse = query.testBuild(target, associable);
what = "change that"; what = "change that";
/* Ridden on use */
} else if (Entities.isRiddenOnUse(event.getEntity())) {
canUse = query.testBuild(target, associable, DefaultFlag.RIDE, DefaultFlag.INTERACT);
what = "ride that";
/* Everything else */ /* Everything else */
} else { } else {
canUse = query.testBuild(target, associable, DefaultFlag.INTERACT); canUse = query.testBuild(target, associable, DefaultFlag.INTERACT);
@ -466,7 +471,7 @@ public void onVehicleExit(VehicleExitEvent event) {
if (!isWhitelisted(Cause.create(player), vehicle.getWorld())) { if (!isWhitelisted(Cause.create(player), vehicle.getWorld())) {
RegionQuery query = getPlugin().getRegionContainer().createQuery(); RegionQuery query = getPlugin().getRegionContainer().createQuery();
Location location = vehicle.getLocation(); Location location = vehicle.getLocation();
if (!query.testBuild(location, player, DefaultFlag.INTERACT)) { if (!query.testBuild(location, player, DefaultFlag.RIDE, DefaultFlag.INTERACT)) {
long now = System.currentTimeMillis(); long now = System.currentTimeMillis();
Long lastTime = WGMetadata.getIfPresent(player, DISEMBARK_MESSAGE_KEY, Long.class); Long lastTime = WGMetadata.getIfPresent(player, DISEMBARK_MESSAGE_KEY, Long.class);
if (lastTime == null || now - lastTime >= LAST_MESSAGE_DELAY) { if (lastTime == null || now - lastTime >= LAST_MESSAGE_DELAY) {

View File

@ -19,20 +19,7 @@
package com.sk89q.worldguard.bukkit.util; package com.sk89q.worldguard.bukkit.util;
import org.bukkit.entity.Ambient; import org.bukkit.entity.*;
import org.bukkit.entity.EnderDragon;
import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Flying;
import org.bukkit.entity.Hanging;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Monster;
import org.bukkit.entity.NPC;
import org.bukkit.entity.Player;
import org.bukkit.entity.Projectile;
import org.bukkit.entity.Slime;
import org.bukkit.entity.TNTPrimed;
import org.bukkit.entity.Tameable;
import org.bukkit.entity.minecart.ExplosiveMinecart; import org.bukkit.entity.minecart.ExplosiveMinecart;
import org.bukkit.projectiles.ProjectileSource; import org.bukkit.projectiles.ProjectileSource;
@ -74,6 +61,16 @@ public static boolean isFireball(EntityType type) {
return type == EntityType.FIREBALL || type == EntityType.SMALL_FIREBALL; return type == EntityType.FIREBALL || type == EntityType.SMALL_FIREBALL;
} }
/**
* Test whether the given entity can be ridden if it is right clicked.
*
* @param entity the entity
* @return true if the entity can be ridden
*/
public static boolean isRiddenOnUse(Entity entity) {
return entity instanceof Vehicle;
}
/** /**
* Test whether the given entity type is a vehicle type. * Test whether the given entity type is a vehicle type.
* *

View File

@ -55,6 +55,7 @@ public final class DefaultFlag {
public static final StateFlag PLACE_VEHICLE = new StateFlag("vehicle-place", false); public static final StateFlag PLACE_VEHICLE = new StateFlag("vehicle-place", false);
public static final StateFlag DESTROY_VEHICLE = new StateFlag("vehicle-destroy", false); public static final StateFlag DESTROY_VEHICLE = new StateFlag("vehicle-destroy", false);
public static final StateFlag LIGHTER = new StateFlag("lighter", false); public static final StateFlag LIGHTER = new StateFlag("lighter", false);
public static final StateFlag RIDE = new StateFlag("ride", false);
// These flags are similar to the ones above (used in tandem with BUILD), // These flags are similar to the ones above (used in tandem with BUILD),
// but their defaults are set to TRUE because it is more user friendly. // but their defaults are set to TRUE because it is more user friendly.
@ -129,7 +130,7 @@ public final class DefaultFlag {
public static final Flag<?>[] flagsList = new Flag<?>[] { public static final Flag<?>[] flagsList = new Flag<?>[] {
PASSTHROUGH, BUILD, CONSTRUCT, BLOCK_BREAK, BLOCK_PLACE, PVP, CHEST_ACCESS, PISTONS, PASSTHROUGH, BUILD, CONSTRUCT, BLOCK_BREAK, BLOCK_PLACE, PVP, CHEST_ACCESS, PISTONS,
TNT, LIGHTER, USE, INTERACT, PLACE_VEHICLE, DESTROY_VEHICLE, SLEEP, TNT, LIGHTER, RIDE, USE, INTERACT, PLACE_VEHICLE, DESTROY_VEHICLE, SLEEP,
MOB_DAMAGE, MOB_SPAWNING, DENY_SPAWN, INVINCIBILITY, EXP_DROPS, MOB_DAMAGE, MOB_SPAWNING, DENY_SPAWN, INVINCIBILITY, EXP_DROPS,
CREEPER_EXPLOSION, OTHER_EXPLOSION, ENDERDRAGON_BLOCK_DAMAGE, GHAST_FIREBALL, ENDER_BUILD, CREEPER_EXPLOSION, OTHER_EXPLOSION, ENDERDRAGON_BLOCK_DAMAGE, GHAST_FIREBALL, ENDER_BUILD,
DENY_MESSAGE, GREET_MESSAGE, FAREWELL_MESSAGE, NOTIFY_ENTER, NOTIFY_LEAVE, DENY_MESSAGE, GREET_MESSAGE, FAREWELL_MESSAGE, NOTIFY_ENTER, NOTIFY_LEAVE,