use of com.sk89q.worldedit.forge.net.packet.LeftClickAirEventMessage in project FastAsyncWorldEdit by IntellectualSites.
the class ForgeWorldEdit method onPlayerInteract.
@SubscribeEvent
public void onPlayerInteract(PlayerInteractEvent event) {
if (platform == null) {
return;
}
if (!platform.isHookingEvents())
// We have to be told to catch these events
return;
if (event.getWorld().isRemote && event instanceof LeftClickEmpty) {
// catch LCE, pass it to server
InternalPacketHandler.getHandler().sendToServer(new LeftClickAirEventMessage());
return;
}
boolean isLeftDeny = event instanceof PlayerInteractEvent.LeftClickBlock && ((PlayerInteractEvent.LeftClickBlock) event).getUseItem() == Event.Result.DENY;
boolean isRightDeny = event instanceof PlayerInteractEvent.RightClickBlock && ((PlayerInteractEvent.RightClickBlock) event).getUseItem() == Event.Result.DENY;
if (isLeftDeny || isRightDeny || event.getEntity().world.isRemote || event.getHand() == Hand.OFF_HAND) {
return;
}
WorldEdit we = WorldEdit.getInstance();
ForgePlayer player = adaptPlayer((ServerPlayerEntity) event.getPlayer());
ForgeWorld world = getWorld(event.getPlayer().world);
if (event instanceof PlayerInteractEvent.LeftClickEmpty) {
// this event cannot be canceled
we.handleArmSwing(player);
} else if (event instanceof PlayerInteractEvent.LeftClickBlock) {
Location pos = new Location(world, event.getPos().getX(), event.getPos().getY(), event.getPos().getZ());
if (we.handleBlockLeftClick(player, pos)) {
event.setCanceled(true);
}
if (we.handleArmSwing(player)) {
event.setCanceled(true);
}
} else if (event instanceof PlayerInteractEvent.RightClickBlock) {
Location pos = new Location(world, event.getPos().getX(), event.getPos().getY(), event.getPos().getZ());
if (we.handleBlockRightClick(player, pos)) {
event.setCanceled(true);
}
if (we.handleRightClick(player)) {
event.setCanceled(true);
}
} else if (event instanceof PlayerInteractEvent.RightClickItem) {
if (we.handleRightClick(player)) {
event.setCanceled(true);
}
}
}
Aggregations