Entity-Riding and safe teleports (#126)

* Fixed dismount being blocked

* Added safe teleports for flying and entity-riding

* Cancel move event on teleport
This commit is contained in:
Hutchy 2020-03-08 15:42:59 +11:00 committed by GitHub
parent c1acd88667
commit 27c4b80954
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 26 additions and 2 deletions

View File

@ -120,6 +120,7 @@ public boolean onEntityMove(MoveEntityEvent event, Location<World> fromLocation,
GDTimings.ENTITY_MOVE_EVENT.startTimingIfSync();
Player player = null;
GDPermissionUser user = null;
boolean onMount = false;
if (targetEntity instanceof Player) {
player = (Player) targetEntity;
user = PermissionHolderCache.getInstance().getOrCreateUser(player);
@ -128,6 +129,7 @@ public boolean onEntityMove(MoveEntityEvent event, Location<World> fromLocation,
if (controller != null && controller instanceof Player) {
player = (Player) controller;
user = PermissionHolderCache.getInstance().getOrCreateUser(player);
onMount = true;
} else {
user = PermissionHolderCache.getInstance().getOrCreateUser(targetEntity.getCreator().orElse(null));
}
@ -328,6 +330,21 @@ public boolean onEntityMove(MoveEntityEvent event, Location<World> fromLocation,
}
if (player != null) {
if (GDFlags.ENTITY_RIDING && onMount) {
if (GDPermissionManager.getInstance().getFinalPermission(event, targetEntity.getLocation(), toClaim, Flags.ENTITY_RIDING, player, targetEntity, player, TrustTypes.ACCESSOR, true) == Tristate.FALSE) {
event.setCancelled(true);
Location<World> safeLocation = Sponge.getGame().getTeleportHelper()
.getSafeLocation(fromLocation, 80, 0)
.orElseGet(() -> Sponge.getGame().getTeleportHelper()
.getSafeLocation(fromLocation, 80, 6)
.orElse(world.getSpawnLocation())
);
targetEntity.getBaseVehicle().clearPassengers();
player.setTransform(player.getTransform().setLocation(safeLocation));
GDTimings.ENTITY_MOVE_EVENT.stopTimingIfSync();
return false;
}
}
final GDPlayerData playerData = user.getInternalPlayerData();
final boolean showGpPrefix = GriefDefenderPlugin.getGlobalConfig().getConfig().message.enterExitShowGdPrefix;
playerData.lastClaim = new WeakReference<>(toClaim);
@ -482,6 +499,13 @@ private void checkPlayerFlight(GDPermissionUser user, GDClaim fromClaim, GDClaim
player.offer(Keys.CAN_FLY, false);
player.offer(Keys.IS_FLYING, false);
playerData.ignoreFallDamage = true;
Location<World> safeLocation = Sponge.getGame().getTeleportHelper()
.getSafeLocation(player.getLocation(), 80, 0)
.orElseGet(() -> Sponge.getGame().getTeleportHelper()
.getSafeLocation(player.getLocation(), 80, 6)
.orElse(player.getWorld().getSpawnLocation())
);
player.setTransform(player.getTransform().setLocation(safeLocation));
GriefDefenderPlugin.sendMessage(player, MessageCache.getInstance().OPTION_APPLY_PLAYER_DENY_FLIGHT);
}
}
@ -615,4 +639,4 @@ public void sendInteractEntityDenyMessage(ItemStack playerItem, Entity entity, G
GriefDefenderPlugin.sendClaimDenyMessage(claim, player, message);
}
}
}
}

View File

@ -919,7 +919,7 @@ public void onProjectileImpactEntity(CollideEntityEvent.Impact event) {
}
@Listener(order = Order.FIRST, beforeModifications = true)
public void onEntityMount(RideEntityEvent event) {
public void onEntityMount(RideEntityEvent.Mount event) {
if (!GDFlags.ENTITY_RIDING) {
return;
}