-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
110 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
70 changes: 70 additions & 0 deletions
70
...ain/java/org/screamingsandals/lib/impl/bukkit/event/server/BukkitServerListPingEvent.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
/* | ||
* Copyright 2024 ScreamingSandals | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.screamingsandals.lib.impl.bukkit.event.server; | ||
|
||
import lombok.EqualsAndHashCode; | ||
import lombok.Getter; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.ToString; | ||
import lombok.experimental.Accessors; | ||
import org.jetbrains.annotations.NotNull; | ||
import org.screamingsandals.lib.event.server.ServerListPingEvent; | ||
import org.screamingsandals.lib.impl.adventure.spectator.AdventureBackend; | ||
import org.screamingsandals.lib.impl.bukkit.BukkitCore; | ||
import org.screamingsandals.lib.impl.bukkit.event.BukkitCancellable; | ||
import org.screamingsandals.lib.spectator.Component; | ||
|
||
import java.net.InetAddress; | ||
|
||
@Accessors(fluent = true) | ||
@RequiredArgsConstructor | ||
@EqualsAndHashCode(onlyExplicitlyIncluded = true) | ||
@ToString(onlyExplicitlyIncluded = true) | ||
public class BukkitServerListPingEvent implements ServerListPingEvent, BukkitCancellable { | ||
@Getter | ||
@EqualsAndHashCode.Include | ||
@ToString.Include | ||
private final @NotNull org.bukkit.event.server.ServerListPingEvent event; | ||
|
||
@Override | ||
public @NotNull InetAddress address() { | ||
return event.getAddress(); | ||
} | ||
|
||
@Override | ||
public @NotNull Component description() { | ||
if (BukkitCore.getSpectatorBackend().hasAdventure()) { | ||
return AdventureBackend.wrapComponent(event.motd()); | ||
} else { | ||
return Component.fromLegacy(event.getMotd()); | ||
} | ||
} | ||
|
||
@Override | ||
public void description(@NotNull Component description) { | ||
if (BukkitCore.getSpectatorBackend().hasAdventure()) { | ||
event.motd(description.as(net.kyori.adventure.text.Component.class)); | ||
} else { | ||
event.setMotd(description.toLegacy()); | ||
} | ||
} | ||
|
||
@Override | ||
public int maxPlayers() { | ||
return event.getMaxPlayers(); | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
core/common/src/main/java/org/screamingsandals/lib/event/server/ServerListPingEvent.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/* | ||
* Copyright 2024 ScreamingSandals | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.screamingsandals.lib.event.server; | ||
|
||
import org.jetbrains.annotations.NotNull; | ||
import org.screamingsandals.lib.event.CancellableEvent; | ||
import org.screamingsandals.lib.event.PlatformEvent; | ||
import org.screamingsandals.lib.spectator.Component; | ||
|
||
import java.net.InetAddress; | ||
|
||
// TODO: move to shared-core? | ||
public interface ServerListPingEvent extends CancellableEvent, PlatformEvent { | ||
@NotNull InetAddress address(); | ||
|
||
@NotNull Component description(); | ||
|
||
void description(@NotNull Component description); | ||
|
||
int maxPlayers(); | ||
} |