Skip to content

Commit

Permalink
feat(core): ServerListPingEvent
Browse files Browse the repository at this point in the history
  • Loading branch information
Misat11 committed Aug 21, 2024
1 parent 9c36d2e commit b1154d4
Show file tree
Hide file tree
Showing 3 changed files with 110 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import org.bukkit.plugin.Plugin;
import org.jetbrains.annotations.NotNull;
import org.screamingsandals.lib.Core;
import org.screamingsandals.lib.event.server.ServerListPingEvent;
import org.screamingsandals.lib.impl.bukkit.attribute.BukkitAttributeTypeServiceFactory;
import org.screamingsandals.lib.impl.bukkit.attribute.BukkitAttributesServiceFactory;
import org.screamingsandals.lib.impl.bukkit.block.snapshot.BukkitBlockSnapshots;
Expand Down Expand Up @@ -176,6 +177,7 @@
import org.screamingsandals.lib.impl.bukkit.event.player.BukkitPlayerUpdateSignEvent;
import org.screamingsandals.lib.impl.bukkit.event.player.BukkitPlayerVelocityChangeEvent;
import org.screamingsandals.lib.impl.bukkit.event.player.BukkitPlayerWorldChangeEvent;
import org.screamingsandals.lib.impl.bukkit.event.server.BukkitServerListPingEvent;
import org.screamingsandals.lib.impl.bukkit.event.world.BukkitPlantGrowEvent;
import org.screamingsandals.lib.impl.bukkit.event.world.BukkitSpawnChangeEvent;
import org.screamingsandals.lib.impl.bukkit.event.world.BukkitSpongeAbsorbEvent;
Expand Down Expand Up @@ -692,6 +694,9 @@ protected PlayerMoveEvent wrapEvent(@NotNull org.bukkit.event.player.PlayerMoveE
// plugins
constructDefaultListener(org.bukkit.event.server.PluginEnableEvent.class, PluginEnabledEvent.class, event -> () -> new BukkitPlugin(event.getPlugin()));
constructDefaultListener(org.bukkit.event.server.PluginDisableEvent.class, PluginDisabledEvent.class, event -> () -> new BukkitPlugin(event.getPlugin()));

// server
constructDefaultListener(org.bukkit.event.server.ServerListPingEvent.class, ServerListPingEvent.class, BukkitServerListPingEvent::new);
}

/**
Expand Down
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();
}
}
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();
}

0 comments on commit b1154d4

Please sign in to comment.