|
4 | 4 | import net.minecraft.server.players.NameAndId; |
5 | 5 | import net.minecraft.world.level.Level; |
6 | 6 | import org.jetbrains.annotations.ApiStatus; |
| 7 | +import org.jetbrains.annotations.NotNull; |
| 8 | +import org.jetbrains.annotations.Nullable; |
| 9 | +import pl.olafcio.avoid.net.player.OfflinePlayer; |
| 10 | +import pl.olafcio.avoid.net.team.Team; |
7 | 11 | import pl.olafcio.avoid_impl.AvoidInternal; |
8 | 12 | import pl.olafcio.avoid.platform.AvoidWrappedLoader; |
9 | 13 | import pl.olafcio.avoid.errors.ImproperEnvironment; |
|
13 | 17 | import pl.olafcio.avoid.net.player.Player; |
14 | 18 | import pl.olafcio.avoid.net.player.PlayerNative; |
15 | 19 | import pl.olafcio.avoid.net.world.World; |
| 20 | +import pl.olafcio.avoid_impl.net.team.TeamNative; |
16 | 21 | import pl.olafcio.avoid_impl.net.world.WorldNative; |
17 | 22 |
|
18 | | -import java.util.ArrayList; |
19 | | -import java.util.List; |
20 | | -import java.util.UUID; |
| 23 | +import java.util.*; |
21 | 24 | import java.util.function.Consumer; |
22 | 25 | import java.util.function.Predicate; |
23 | 26 |
|
@@ -60,6 +63,46 @@ public static Player getPlayer(UUID uuid) { |
60 | 63 | return PlayerNative.convertFrom(ret); |
61 | 64 | } |
62 | 65 |
|
| 66 | + public static OfflinePlayer getOfflinePlayer(String nick) { |
| 67 | + var optional = AvoidInternal.getServer().services().nameToIdCache().get(nick); |
| 68 | + if (optional.isEmpty()) |
| 69 | + return null; |
| 70 | + |
| 71 | + var uuid = optional.orElseThrow().id(); |
| 72 | + |
| 73 | + return new OfflinePlayer() { |
| 74 | + @Override |
| 75 | + public String getNick() { |
| 76 | + return nick; |
| 77 | + } |
| 78 | + |
| 79 | + @Override |
| 80 | + public UUID uuid() { |
| 81 | + return uuid; |
| 82 | + } |
| 83 | + }; |
| 84 | + } |
| 85 | + |
| 86 | + public static OfflinePlayer getOfflinePlayer(UUID uuid) { |
| 87 | + var optional = AvoidInternal.getServer().services().nameToIdCache().get(uuid); |
| 88 | + if (optional.isEmpty()) |
| 89 | + return null; |
| 90 | + |
| 91 | + var nick = optional.orElseThrow().name(); |
| 92 | + |
| 93 | + return new OfflinePlayer() { |
| 94 | + @Override |
| 95 | + public String getNick() { |
| 96 | + return nick; |
| 97 | + } |
| 98 | + |
| 99 | + @Override |
| 100 | + public UUID uuid() { |
| 101 | + return uuid; |
| 102 | + } |
| 103 | + }; |
| 104 | + } |
| 105 | + |
63 | 106 | public static List<Operator> getOperators() { |
64 | 107 | return AvoidInternal.getServer().getPlayerList().getOps().getEntries().stream().map(op -> { |
65 | 108 | var user = op.getUser(); |
@@ -168,4 +211,40 @@ public static Properties getProperties() { |
168 | 211 |
|
169 | 212 | return new Properties(((DedicatedServer) AvoidInternal.getServer()).getProperties()); |
170 | 213 | } |
| 214 | + |
| 215 | + @Nullable |
| 216 | + public static Team getTeam(String name) { |
| 217 | + var team = AvoidInternal.getServer().getScoreboard().getPlayerTeam(name); |
| 218 | + if (team == null) |
| 219 | + return null; |
| 220 | + |
| 221 | + return TeamNative.convert(team); |
| 222 | + } |
| 223 | + |
| 224 | + @NotNull |
| 225 | + public static Team createTeam(String name) { |
| 226 | + return TeamNative.convert(AvoidInternal.getServer().getScoreboard().addPlayerTeam(name)); |
| 227 | + } |
| 228 | + |
| 229 | + public static boolean deleteTeam(String name) { |
| 230 | + var scoreboard = AvoidInternal.getServer().getScoreboard(); |
| 231 | + var team = scoreboard.getPlayerTeam(name); |
| 232 | + |
| 233 | + if (team == null) |
| 234 | + return false; |
| 235 | + |
| 236 | + scoreboard.removePlayerTeam(team); |
| 237 | + return true; |
| 238 | + } |
| 239 | + |
| 240 | + public static List<Team> getTeams() { |
| 241 | + return AvoidInternal.getServer().getScoreboard().getPlayerTeams() |
| 242 | + .stream() |
| 243 | + .map(TeamNative::convert) |
| 244 | + .toList(); |
| 245 | + } |
| 246 | + |
| 247 | + public static Collection<String> getTeamNames() { |
| 248 | + return AvoidInternal.getServer().getScoreboard().getTeamNames(); |
| 249 | + } |
171 | 250 | } |
0 commit comments