Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add mount/dismount vehicles/animals flags #426

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
import com.sk89q.worldguard.protection.flags.StateFlag;
import com.sk89q.worldguard.protection.flags.StateFlag.State;
import com.sk89q.worldguard.protection.regions.RegionQuery;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Location;
import org.bukkit.Material;
Expand Down Expand Up @@ -414,7 +415,15 @@ public void onUseEntity(UseEntityEvent event) {
}
/* Ridden on use */
} else if (Entities.isRiddenOnUse(entity)) {
canUse = query.testBuild(BukkitAdapter.adapt(target), associable, combine(event, Flags.RIDE, Flags.INTERACT));
StateFlag flagToCheck;
if (entity instanceof Tameable){
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pigs can be ridden but aren't tameable, what happens here? maybe check the Animal interface?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch - I admit I was only thinking of horses while working on this. I'll check the Animal interface instead.

flagToCheck = Flags.MOUNT_ANIMALS;
}else {
flagToCheck = Flags.MOUNT_VEHICLES;
}
// backward compatibility – if Flag.RIDE is allowed, just allow
canUse = query.testBuild(BukkitAdapter.adapt(target), associable, combine(event, Flags.RIDE, Flags.INTERACT))
|| query.testBuild(BukkitAdapter.adapt(target), associable, combine(event, flagToCheck));
what = "ride that";

/* Everything else */
Expand Down Expand Up @@ -511,13 +520,23 @@ public void onVehicleExit(VehicleExitEvent event) {
if (!isRegionSupportEnabled(BukkitAdapter.adapt(vehicle.getWorld()))) return; // Region support disabled
Entity exited = event.getExited();

if (vehicle instanceof Tameable && exited instanceof Player) {
if(exited instanceof Player){
Player player = (Player) exited;
LocalPlayer localPlayer = WorldGuardPlugin.inst().wrapPlayer(player);
StateFlag flagToCheck;
if (vehicle instanceof Tameable){
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as above

flagToCheck = Flags.DISMOUNT_ANIMALS;
} else {
flagToCheck = Flags.DISMOUNT_VEHICLES;
}
if (!isWhitelisted(Cause.create(player), vehicle.getWorld(), false)) {
RegionQuery query = WorldGuard.getInstance().getPlatform().getRegionContainer().createQuery();
Location location = vehicle.getLocation();
if (!query.testBuild(BukkitAdapter.adapt(location), localPlayer, Flags.RIDE, Flags.INTERACT)) {
// don't let the INTERACT flag override dismounting
// the player might need to interact with world objects while staying mounted (buttons, doors etc)
// for backward compatibility, still allow the old Flags.RIDE | Flags.INTERACT
if (!query.testBuild(BukkitAdapter.adapt(location), localPlayer, flagToCheck)
&& !query.testBuild(BukkitAdapter.adapt(location), localPlayer, Flags.RIDE, Flags.INTERACT)) {
long now = System.currentTimeMillis();
Long lastTime = WGMetadata.getIfPresent(player, DISEMBARK_MESSAGE_KEY, Long.class);
if (lastTime == null || now - lastTime >= LAST_MESSAGE_DELAY) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@ public final class Flags {
public static final StateFlag DESTROY_VEHICLE = register(new StateFlag("vehicle-destroy", false));
public static final StateFlag LIGHTER = register(new StateFlag("lighter", false));
public static final StateFlag RIDE = register(new StateFlag("ride", false));
public static final StateFlag MOUNT_ANIMALS = register(new StateFlag("mount-animals", false));
public static final StateFlag MOUNT_VEHICLES = register(new StateFlag("mount-vehicles", false));
public static final StateFlag DISMOUNT_ANIMALS = register(new StateFlag("dismount-animals", false));
public static final StateFlag DISMOUNT_VEHICLES = register(new StateFlag("dismount-vehicles", false));
public static final StateFlag POTION_SPLASH = register(new StateFlag("potion-splash", false));
public static final StateFlag ITEM_FRAME_ROTATE = register(new StateFlag("item-frame-rotation", false));
public static final StateFlag TRAMPLE_BLOCKS = register(new StateFlag("block-trampling", false));
Expand Down