| 1 | package net.minecraft.server.notifications;
|
| 2 |
|
| 3 | import com.google.common.collect.Lists;
|
| 4 | import java.util.List;
|
| 5 | import net.minecraft.server.dedicated.DedicatedServer;
|
| 6 | import net.minecraft.server.level.ServerPlayer;
|
| 7 | import net.minecraft.server.players.IpBanListEntry;
|
| 8 | import net.minecraft.server.players.NameAndId;
|
| 9 | import net.minecraft.server.players.ServerOpListEntry;
|
| 10 | import net.minecraft.server.players.UserBanListEntry;
|
| 11 | import net.minecraft.world.level.gamerules.GameRule;
|
| 12 | import org.jspecify.annotations.Nullable;
|
| 13 |
|
| 14 | public class NotificationManager implements NotificationService {
|
| 15 | private final List<NotificationService> notificationServices = Lists.newArrayList();
|
| 16 | private @Nullable DedicatedServer server;
|
| 17 |
|
| 18 | public void registerService(final NotificationService notificationService) {
|
| 19 | this.notificationServices.add(notificationService);
|
| 20 | }
|
| 21 |
|
| 22 | public void setServer(final DedicatedServer server) {
|
| 23 | if (this.server != null) {
|
| 24 | throw new IllegalStateException("Server already set");
|
| 25 | }
|
| 26 |
|
| 27 | this.server = server;
|
| 28 | }
|
| 29 |
|
| 30 | public @Nullable DedicatedServer server() {
|
| 31 | return this.server;
|
| 32 | }
|
| 33 |
|
| 34 | @Override
|
| 35 | public void playerJoined(final ServerPlayer player) {
|
| 36 | this.notificationServices.forEach(notificationService -> notificationService.playerJoined(player));
|
| 37 | }
|
| 38 |
|
| 39 | @Override
|
| 40 | public void playerLeft(final ServerPlayer player) {
|
| 41 | this.notificationServices.forEach(notificationService -> notificationService.playerLeft(player));
|
| 42 | }
|
| 43 |
|
| 44 | @Override
|
| 45 | public void serverStarted() {
|
| 46 | this.notificationServices.forEach(NotificationService::serverStarted);
|
| 47 | }
|
| 48 |
|
| 49 | @Override
|
| 50 | public void serverShuttingDown() {
|
| 51 | this.notificationServices.forEach(NotificationService::serverShuttingDown);
|
| 52 | }
|
| 53 |
|
| 54 | @Override
|
| 55 | public void serverSaveStarted() {
|
| 56 | this.notificationServices.forEach(NotificationService::serverSaveStarted);
|
| 57 | }
|
| 58 |
|
| 59 | @Override
|
| 60 | public void serverSaveCompleted() {
|
| 61 | this.notificationServices.forEach(NotificationService::serverSaveCompleted);
|
| 62 | }
|
| 63 |
|
| 64 | @Override
|
| 65 | public void serverActivityOccured() {
|
| 66 | this.notificationServices.forEach(NotificationService::serverActivityOccured);
|
| 67 | }
|
| 68 |
|
| 69 | @Override
|
| 70 | public void worldUpgradeStarted() {
|
| 71 | this.notificationServices.forEach(notificationService -> notificationService.worldUpgradeStarted());
|
| 72 | }
|
| 73 |
|
| 74 | @Override
|
| 75 | public void worldUpgradeProgress(final float progressPercentage) {
|
| 76 | this.notificationServices.forEach(notificationService -> notificationService.worldUpgradeProgress(progressPercentage));
|
| 77 | }
|
| 78 |
|
| 79 | @Override
|
| 80 | public void worldUpgradeFinished() {
|
| 81 | this.notificationServices.forEach(notificationService -> notificationService.worldUpgradeFinished());
|
| 82 | }
|
| 83 |
|
| 84 | @Override
|
| 85 | public void worldUpgradeFailed(final String reason) {
|
| 86 | this.notificationServices.forEach(notificationService -> notificationService.worldUpgradeFailed(reason));
|
| 87 | }
|
| 88 |
|
| 89 | @Override
|
| 90 | public void playerOped(final ServerOpListEntry operator) {
|
| 91 | this.notificationServices.forEach(notificationService -> notificationService.playerOped(operator));
|
| 92 | }
|
| 93 |
|
| 94 | @Override
|
| 95 | public void playerDeoped(final ServerOpListEntry operator) {
|
| 96 | this.notificationServices.forEach(notificationService -> notificationService.playerDeoped(operator));
|
| 97 | }
|
| 98 |
|
| 99 | @Override
|
| 100 | public void playerAddedToAllowlist(final NameAndId player) {
|
| 101 | this.notificationServices.forEach(notificationService -> notificationService.playerAddedToAllowlist(player));
|
| 102 | }
|
| 103 |
|
| 104 | @Override
|
| 105 | public void playerRemovedFromAllowlist(final NameAndId player) {
|
| 106 | this.notificationServices.forEach(notificationService -> notificationService.playerRemovedFromAllowlist(player));
|
| 107 | }
|
| 108 |
|
| 109 | @Override
|
| 110 | public void ipBanned(final IpBanListEntry ban) {
|
| 111 | this.notificationServices.forEach(notificationService -> notificationService.ipBanned(ban));
|
| 112 | }
|
| 113 |
|
| 114 | @Override
|
| 115 | public void ipUnbanned(final String ip) {
|
| 116 | this.notificationServices.forEach(notificationService -> notificationService.ipUnbanned(ip));
|
| 117 | }
|
| 118 |
|
| 119 | @Override
|
| 120 | public void playerBanned(final UserBanListEntry ban) {
|
| 121 | this.notificationServices.forEach(notificationService -> notificationService.playerBanned(ban));
|
| 122 | }
|
| 123 |
|
| 124 | @Override
|
| 125 | public void playerUnbanned(final NameAndId player) {
|
| 126 | this.notificationServices.forEach(notificationService -> notificationService.playerUnbanned(player));
|
| 127 | }
|
| 128 |
|
| 129 | @Override
|
| 130 | public <T> void onGameRuleChanged(final GameRule<T> gameRule, final T value) {
|
| 131 | this.notificationServices.forEach(notificationService -> notificationService.onGameRuleChanged(gameRule, value));
|
| 132 | }
|
| 133 |
|
| 134 | @Override
|
| 135 | public void statusHeartbeat() {
|
| 136 | this.notificationServices.forEach(NotificationService::statusHeartbeat);
|
| 137 | }
|
| 138 | }
|
| 139 |
|