-
-
Notifications
You must be signed in to change notification settings - Fork 546
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
chestnutcase
wants to merge
1
commit into
EngineHub:master
Choose a base branch
from
chestnutcase:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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; | ||
|
@@ -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){ | ||
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 */ | ||
|
@@ -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){ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.