Skip to content

Commit

Permalink
feat: add ApolloPlayerLocation and it's conversion util methods
Browse files Browse the repository at this point in the history
  • Loading branch information
ItsNature committed Aug 18, 2023
1 parent d6acdbf commit d296c04
Show file tree
Hide file tree
Showing 3 changed files with 97 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/*
* This file is part of Apollo, licensed under the MIT License.
*
* Copyright (c) 2023 Moonsworth
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package com.lunarclient.apollo.common.location;

import lombok.Builder;
import lombok.Getter;

/**
* Represents a player location in the world.
*
* @since 1.0.0
*/
@Getter
@Builder
public final class ApolloPlayerLocation {

/**
* Returns the {@link ApolloLocation} for this player.
*
* @return the apollo location
* @since 1.0.0
*/
ApolloLocation location;

/**
* Returns the {@code float} yaw for this player location.
*
* @return the yaw
* @since 1.0.0
*/
float yaw;

/**
* Returns the {@code float} pitch for this player location.
*
* @return the pitch
* @since 1.0.0
*/
float pitch;

}
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,6 @@
*/
public final class AntiCheatImpl extends AntiCheatModule {



}
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import com.lunarclient.apollo.common.icon.SimpleResourceLocationIcon;
import com.lunarclient.apollo.common.location.ApolloBlockLocation;
import com.lunarclient.apollo.common.location.ApolloLocation;
import com.lunarclient.apollo.common.location.ApolloPlayerLocation;
import com.lunarclient.apollo.common.v1.EntityId;
import com.lunarclient.apollo.common.v1.Uuid;
import java.awt.Color;
Expand Down Expand Up @@ -224,6 +225,38 @@ public static ApolloBlockLocation fromProtobuf(com.lunarclient.apollo.common.v1.
.build();
}

/**
* Converts an {@link ApolloPlayerLocation} object to an
* {@link com.lunarclient.apollo.common.v1.PlayerLocation} proto message.
*
* @param object the player location
* @return the proto player location message
* @since 1.0.0
*/
public static com.lunarclient.apollo.common.v1.PlayerLocation toProtobuf(ApolloPlayerLocation object) {
return com.lunarclient.apollo.common.v1.PlayerLocation.newBuilder()
.setLocation(NetworkTypes.toProtobuf(object.getLocation()))
.setYaw(object.getYaw())
.setPitch(object.getPitch())
.build();
}

/**
* Converts an {@link com.lunarclient.apollo.common.v1.PlayerLocation}
* proto message to an {@link ApolloPlayerLocation} object.
*
* @param message the player location message
* @return the apollo player location object
* @since 1.0.0
*/
public static ApolloPlayerLocation fromProtobuf(com.lunarclient.apollo.common.v1.PlayerLocation message) {
return ApolloPlayerLocation.builder()
.location(NetworkTypes.fromProtobuf(message.getLocation()))
.yaw(message.getYaw())
.pitch(message.getPitch())
.build();
}

/**
* Converts an {@link Cuboid2D} object to an
* {@link com.lunarclient.apollo.common.v1.Cuboid2D} proto message.
Expand Down

0 comments on commit d296c04

Please sign in to comment.