Skip to content

Commit

Permalink
add basic api
Browse files Browse the repository at this point in the history
  • Loading branch information
BasiqueEvangelist committed Mar 7, 2022
1 parent 971e647 commit 6a3fac1
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 7 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ dependencies {
modImplementation include('me.lucko:fabric-permissions-api:0.1-SNAPSHOT')
shadow implementation("blue.endless:jankson:1.2.0")

modImplementation include('me.basiqueevangelist:onedatastore:0.1.0')
modImplementation include('me.basiqueevangelist:onedatastore:0.1.1')
// PSA: Some older mods, compiled on Loom 0.2.1, might have outdated Maven POMs.
// You may need to force-disable transitiveness on them.
}
Expand Down
17 changes: 17 additions & 0 deletions src/main/java/me/basiqueevangelist/pingspam/api/PingspamApiV0.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package me.basiqueevangelist.pingspam.api;

import me.basiqueevangelist.pingspam.utils.PingLogic;
import net.minecraft.server.MinecraftServer;
import net.minecraft.text.Text;

import java.util.UUID;

public final class PingspamApiV0 {
private PingspamApiV0() {

}

public static void sendNotificationTo(MinecraftServer server, UUID playerId, Text message) {
PingLogic.sendNotification(server, playerId, message);
}
}
19 changes: 13 additions & 6 deletions src/main/java/me/basiqueevangelist/pingspam/utils/PingLogic.java
Original file line number Diff line number Diff line change
Expand Up @@ -132,21 +132,28 @@ private static void processMention(ProcessedPing result, String mention, Text me
public static void pingPlayer(ProcessedPing ping, UUID playerUuid, Text pingMsg, MessageType type, UUID senderUUID) {
if (ping.pingedPlayers.contains(playerUuid)) return;

PingspamPlayerData data = DataStore.getFor(ping.server).getPlayer(playerUuid, PingSpam.PLAYER_DATA);

data.addPing(pingMsg);
ping.pingedPlayers.add(playerUuid);
sendNotification(ping.server, playerUuid, pingMsg);

ServerPlayerEntity onlinePlayer = ping.server.getPlayerManager().getPlayer(playerUuid);
if (onlinePlayer != null) {
Text pingMessage = pingMsg.shallowCopy().formatted(Formatting.AQUA);
onlinePlayer.networkHandler.sendPacket(new GameMessageS2CPacket(pingMessage, type, senderUUID));
}
}

public static void sendNotification(MinecraftServer server, UUID playerId, Text pingMsg) {
PingspamPlayerData data = DataStore.getFor(server).getPlayer(playerId, PingSpam.PLAYER_DATA);

data.addPing(pingMsg);

ServerPlayerEntity onlinePlayer = server.getPlayerManager().getPlayer(playerId);
if (onlinePlayer != null) {
SoundEvent pingSound = data.pingSound();

if (pingSound != null) {
onlinePlayer.playSound(pingSound, SoundCategory.PLAYERS, 1.0F, 1.0F);
}

Text pingMessage = pingMsg.shallowCopy().formatted(Formatting.AQUA);
onlinePlayer.networkHandler.sendPacket(new GameMessageS2CPacket(pingMessage, type, senderUUID));
}
}

Expand Down

0 comments on commit 6a3fac1

Please sign in to comment.