-
Notifications
You must be signed in to change notification settings - Fork 34
Expand file tree
/
Copy pathFoliaApollo.java
More file actions
206 lines (189 loc) · 6.97 KB
/
Copy pathFoliaApollo.java
File metadata and controls
206 lines (189 loc) · 6.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
/*
* This file is part of Apollo, licensed under the MIT License.
*
* Copyright (c) 2026 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;
import com.lunarclient.apollo.common.ApolloEntity;
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.player.ApolloPlayer;
import com.lunarclient.apollo.player.ApolloPlayerManager;
import com.lunarclient.apollo.recipients.Recipients;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.UUID;
import java.util.function.Consumer;
import lombok.NonNull;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
/**
* Utility class for converting objects to and from their corresponding Bukkit
* representations with additional helper methods for easier integration.
*
* @since 1.1.8
*/
public final class FoliaApollo {
/**
* Runs a specified operation for a {@link Player}.
*
* @param player the player
* @param playerConsumer the operation to be performed
* @since 1.1.8
*/
public static void runForPlayer(@NonNull Player player, @NonNull Consumer<ApolloPlayer> playerConsumer) {
runForPlayer(player.getUniqueId(), playerConsumer);
}
/**
* Runs a specified operation for a {@link ApolloPlayer} from the provided {@link UUID}.
*
* @param playerUuid the player
* @param playerConsumer the operation to be performed
* @since 1.1.8
*/
public static void runForPlayer(@NonNull UUID playerUuid, @NonNull Consumer<ApolloPlayer> playerConsumer) {
Apollo.getPlayerManager().getPlayer(playerUuid).ifPresent(playerConsumer);
}
/**
* Converts a {@link Collection} of {@link Player}s to an {@link Recipients}.
*
* @param players the players
* @return the recipients object containing the converted ApolloPlayer objects
* @since 1.1.8
*/
public static Recipients getRecipientsFrom(@NonNull Collection<Player> players) {
ApolloPlayerManager playerManager = Apollo.getPlayerManager();
List<ApolloPlayer> apolloPlayers = new ArrayList<>(players.size());
for (Player player : players) {
playerManager.getPlayer(player.getUniqueId())
.ifPresent(apolloPlayers::add);
}
return Recipients.of(apolloPlayers);
}
/**
* Converts a {@link Location} to an {@link ApolloLocation} object.
*
* @param location the location
* @return the converted apollo location object
* @since 1.1.8
*/
public static ApolloLocation toApolloLocation(@NonNull Location location) {
return ApolloLocation.builder()
.world(location.getWorld().getName())
.x(location.getX())
.y(location.getY())
.z(location.getZ())
.build();
}
/**
* Converts a {@link Location} to an {@link ApolloBlockLocation} object.
*
* @param location the location
* @return the converted apollo block location object
* @since 1.1.8
*/
public static ApolloBlockLocation toApolloBlockLocation(@NonNull Location location) {
return ApolloBlockLocation.builder()
.world(location.getWorld().getName())
.x(location.getBlockX())
.y(location.getBlockY())
.z(location.getBlockZ())
.build();
}
/**
* Converts a {@link Location} to an {@link ApolloPlayerLocation} object.
*
* @param location the location
* @return the converted apollo player location object
* @since 1.1.8
*/
public static ApolloPlayerLocation toApolloPlayerLocation(@NonNull Location location) {
return ApolloPlayerLocation.builder()
.location(FoliaApollo.toApolloLocation(location))
.yaw(location.getYaw())
.pitch(location.getPitch())
.build();
}
/**
* Converts a {@link Entity} to an {@link ApolloEntity} object.
*
* @param entity the entity
* @return the converted apollo entity object
* @since 1.1.8
*/
public static ApolloEntity toApolloEntity(@NonNull Entity entity) {
return new ApolloEntity(entity.getEntityId(), entity.getUniqueId());
}
/**
* Converts a {@link ApolloLocation} to an {@link Location} object.
*
* @param location the apollo location
* @return the converted location object
* @since 1.1.8
*/
public static Location toBukkitLocation(@NonNull ApolloLocation location) {
return new Location(
Bukkit.getWorld(location.getWorld()),
location.getX(),
location.getY(),
location.getZ()
);
}
/**
* Converts a {@link ApolloBlockLocation} to an {@link Location} object.
*
* @param location the apollo block location
* @return the converted location object
* @since 1.1.8
*/
public static Location toBukkitLocation(@NonNull ApolloBlockLocation location) {
return new Location(
Bukkit.getWorld(location.getWorld()),
location.getX(),
location.getY(),
location.getZ()
);
}
/**
* Converts a {@link ApolloPlayerLocation} to an {@link Location} object.
*
* @param location the apollo location
* @return the converted location object
* @since 1.1.8
*/
public static Location toBukkitLocation(@NonNull ApolloPlayerLocation location) {
ApolloLocation apolloLocation = location.getLocation();
return new Location(
Bukkit.getWorld(apolloLocation.getWorld()),
apolloLocation.getX(),
apolloLocation.getY(),
apolloLocation.getZ(),
location.getYaw(),
location.getPitch()
);
}
private FoliaApollo() {
}
}