Skip to content

Commit

Permalink
1.20
Browse files Browse the repository at this point in the history
  • Loading branch information
BasiqueEvangelist committed Jun 23, 2023
1 parent 1def030 commit d873bd3
Show file tree
Hide file tree
Showing 13 changed files with 66 additions and 46 deletions.
10 changes: 5 additions & 5 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
plugins {
id 'com.github.johnrengelman.shadow' version '7.1.2'
id 'com.github.johnrengelman.shadow' version '8.1.1'
id 'java'
id 'fabric-loom' version '1.1-SNAPSHOT'
id 'io.github.juuxel.loom-quiltflower' version '1.8.0'
id 'fabric-loom' version '1.2-SNAPSHOT'
id 'io.github.juuxel.loom-quiltflower' version '1.10.0'
id 'maven-publish'
}

sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17

archivesBaseName = project.archives_base_name
version = project.mod_version + "+" + project.minecraft_version
version = "${project.mod_version}+${rootProject.minecraft_base_version}"
group = project.maven_group

configurations {
Expand Down Expand Up @@ -53,7 +53,7 @@ dependencies {
modImplementation include('me.lucko:fabric-permissions-api:0.2-SNAPSHOT')
shadow implementation("blue.endless:jankson:1.2.0")

modImplementation include('me.basiqueevangelist:onedatastore:0.1.2+1.19') {
modImplementation include("me.basiqueevangelist:onedatastore:${project.onedatastore_version}") {
transitive = false
}
// PSA: Some older mods, compiled on Loom 0.2.1, might have outdated Maven POMs.
Expand Down
12 changes: 7 additions & 5 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,17 @@ org.gradle.jvmargs=-Xmx1G

# Fabric Properties
# check these on https://fabricmc.net/develop
minecraft_version=1.19.3
yarn_mappings=1.19.3+build.5
loader_version=0.14.13
minecraft_base_version=1.20
minecraft_version=1.20.1
yarn_mappings=1.20.1+build.5
loader_version=0.14.21

# Mod Properties
mod_version = 1.3.1
maven_group = me.basiqueevangelist
archives_base_name = pingspam

# Dependencies
fabric_version=0.73.0+1.19.3
modmenu_version=5.0.2
fabric_version=0.84.0+1.20.1
modmenu_version=7.1.0
onedatastore_version=0.1.3-pre.1+1.20
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.4-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.1.1-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,11 @@ public class PingSpamConfig {

@Comment("Process pings from messages with nil UUIDs. Disabling this will disallow pings from command blocks and the server console, but will also disallow random unprivileged discord users from pinging @everyone with a discord link.")
public boolean processPingsFromUnknownPlayers = true;

@Comment("""
Makes Pingspam send all important packets to all clients, regardless of whether that client registered Pingspam
channels as receivable.
Can be important if your proxy somehow blocks these registrations.
""")
public boolean ignoreCanSend = false;
}
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ private static int removePlayerAlias(CommandContext<ServerCommandSource> ctx) th
ServerNetworkLogic.removePossibleName(src.getServer().getPlayerManager(), alias);

src.sendFeedback(
Text.literal("Removed alias ")
() -> Text.literal("Removed alias ")
.formatted(Formatting.GREEN)
.append(Text.literal('"' + alias + '"')
.formatted(Formatting.YELLOW))
Expand Down Expand Up @@ -149,7 +149,7 @@ private static int addPlayerAlias(CommandContext<ServerCommandSource> ctx) throw
ServerNetworkLogic.addPossibleName(src.getServer().getPlayerManager(), newAlias);

src.sendFeedback(
Text.literal("Added alias ")
() -> Text.literal("Added alias ")
.formatted(Formatting.GREEN)
.append(Text.literal('"' + newAlias + '"')
.formatted(Formatting.YELLOW))
Expand Down Expand Up @@ -188,7 +188,7 @@ private static int listPlayerAliases(CommandContext<ServerCommandSource> ctx) th
headerBuilder.append('.');
}

src.sendFeedback(Text.literal(player.getName())
src.sendFeedback(() -> Text.literal(player.getName())
.formatted(Formatting.AQUA)
.append(
Text.literal(headerBuilder.toString())
Expand Down Expand Up @@ -219,7 +219,7 @@ private static int removeAlias(CommandContext<ServerCommandSource> ctx) throws C
if (!NameLogic.isValidName(src.getServer(), alias, false))
ServerNetworkLogic.removePossibleName(src.getServer().getPlayerManager(), alias);

src.sendFeedback(Text.literal("Removed alias ")
src.sendFeedback(() -> Text.literal("Removed alias ")
.formatted(Formatting.GREEN)
.append(Text.literal('"' + alias + '"')
.formatted(Formatting.YELLOW))
Expand Down Expand Up @@ -249,7 +249,7 @@ private static int addAliases(CommandContext<ServerCommandSource> ctx) throws Co
data.aliases().add(newAlias);
ServerNetworkLogic.addPossibleName(src.getServer().getPlayerManager(), newAlias);

src.sendFeedback(Text.literal("Added alias ")
src.sendFeedback(() -> Text.literal("Added alias ")
.formatted(Formatting.GREEN)
.append(Text.literal('"' + newAlias + '"')
.formatted(Formatting.YELLOW))
Expand Down Expand Up @@ -287,7 +287,7 @@ private static int listAliases(CommandContext<ServerCommandSource> ctx) throws C
}

src.sendFeedback(
Text.literal(headerBuilder.toString())
() -> Text.literal(headerBuilder.toString())
.formatted(Formatting.GREEN)
.append(Text.literal(contentBuilder.toString())
.formatted(Formatting.YELLOW)), false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ private static int listPlayersInGroup(CommandContext<ServerCommandSource> ctx) t
headerBuilder.append('.');
}

src.sendFeedback(Text.literal("Group ")
src.sendFeedback(() -> Text.literal("Group ")
.formatted(Formatting.GREEN)
.append(Text.literal("@" + groupName)
.formatted(Formatting.YELLOW))
Expand Down Expand Up @@ -132,7 +132,7 @@ private static int removePlayerFromGroup(CommandContext<ServerCommandSource> ctx
ServerNetworkLogic.removePossibleName(src.getServer().getPlayerManager(), group);

src.sendFeedback(
Text.literal("Removed player ")
() -> Text.literal("Removed player ")
.formatted(Formatting.GREEN)
.append(Text.literal(player.getName())
.formatted(Formatting.AQUA))
Expand Down Expand Up @@ -164,7 +164,7 @@ private static int addPlayerToGroup(CommandContext<ServerCommandSource> ctx) thr
ServerNetworkLogic.addPossibleName(src.getServer().getPlayerManager(), group);

src.sendFeedback(
Text.literal("Added player ")
() -> Text.literal("Added player ")
.formatted(Formatting.GREEN)
.append(Text.literal(player.getName())
.formatted(Formatting.AQUA))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,21 +31,23 @@ public static int showNotifications(CommandContext<ServerCommandSource> ctx) thr
PingspamPlayerData data = DataStore.getFor(src.getServer()).getPlayer(src.getPlayerOrThrow().getUuid(), PingSpam.PLAYER_DATA);

if (!data.unreadPings().isEmpty()) {
MutableText response = Text.literal("You have " + data.unreadPings().size() + " unread message" + (data.unreadPings().size() != 1 ? "s" : "") + ":")
.formatted(Formatting.GREEN);

for (Text notif : data.unreadPings()) {
response.append(Text.literal("\n- ")
.formatted(Formatting.WHITE)
.append(notif));
}

src.sendFeedback(response, false);
src.sendFeedback(() -> {
MutableText response = Text.literal("You have " + data.unreadPings().size() + " unread message" + (data.unreadPings().size() != 1 ? "s" : "") + ":")
.formatted(Formatting.GREEN);

for (Text notif : data.unreadPings()) {
response.append(Text.literal("\n- ")
.formatted(Formatting.WHITE)
.append(notif));
}

return response;
}, false);
data.unreadPings().clear();

return 1;
} else {
src.sendFeedback(Text.literal("You have no unread messages.")
src.sendFeedback(() -> Text.literal("You have no unread messages.")
.formatted(Formatting.GREEN), false);

return 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ private static int addIgnoredPlayer(CommandContext<ServerCommandSource> ctx) thr

data.ignoredPlayers().add(offender.getId());

src.sendFeedback(Text.literal("You are now ignoring ")
src.sendFeedback(() -> Text.literal("You are now ignoring ")
.formatted(Formatting.GREEN)
.append(Text.literal(offender.getName())
.formatted(Formatting.AQUA))
Expand All @@ -89,7 +89,7 @@ private static int removeIgnoredPlayer(CommandContext<ServerCommandSource> ctx)

data.ignoredPlayers().remove(pardonee.getId());

src.sendFeedback(Text.literal("You are no longer ignoring ")
src.sendFeedback(() -> Text.literal("You are no longer ignoring ")
.formatted(Formatting.GREEN)
.append(Text.literal(pardonee.getName())
.formatted(Formatting.AQUA))
Expand All @@ -104,7 +104,7 @@ private static int listIgnoredPlayers(CommandContext<ServerCommandSource> ctx) t
PingspamPlayerData data = DataStore.getFor(src.getServer()).getPlayer(player.getUuid(), PingSpam.PLAYER_DATA);

if (data.ignoredPlayers().isEmpty()) {
src.sendFeedback(Text.literal("You are not ignoring any players.")
src.sendFeedback(() -> Text.literal("You are not ignoring any players.")
.formatted(Formatting.GREEN), false);
return 0;
}
Expand All @@ -114,7 +114,7 @@ private static int listIgnoredPlayers(CommandContext<ServerCommandSource> ctx) t
contentBuilder.append("\n - ").append(NameUtil.getNameFromUUID(ignoredPlayerUuid));
}

src.sendFeedback(Text.literal("You are ignoring " + data.ignoredPlayers().size() + " player(s):")
src.sendFeedback(() -> Text.literal("You are ignoring " + data.ignoredPlayers().size() + " player(s):")
.formatted(Formatting.GREEN)
.append(Text.literal(contentBuilder.toString())
.formatted(Formatting.AQUA)), false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ private static int setPingSound(CommandContext<ServerCommandSource> ctx) throws

data.setPingSound(event);

src.sendFeedback(Text.literal("Set ping sound to ")
src.sendFeedback(() -> Text.literal("Set ping sound to ")
.formatted(Formatting.GREEN)
.append(Text.literal(soundId.toString())
.formatted(Formatting.YELLOW))
Expand All @@ -61,7 +61,7 @@ private static int removePingSound(CommandContext<ServerCommandSource> ctx) thro

data.setPingSound(null);

src.sendFeedback(Text.literal("Disabled ping sound.")
src.sendFeedback(() -> Text.literal("Disabled ping sound.")
.formatted(Formatting.GREEN), false);

return 0;
Expand All @@ -73,13 +73,13 @@ private static int getPingSound(CommandContext<ServerCommandSource> ctx) throws
PingspamPlayerData data = DataStore.getFor(src.getServer()).getPlayer(player.getUuid(), PingSpam.PLAYER_DATA);

if (data.pingSound() != null) {
src.sendFeedback(Text.literal("Your current ping sound is ")
src.sendFeedback(() -> Text.literal("Your current ping sound is ")
.formatted(Formatting.GREEN)
.append(Text.literal(data.pingSound().getId().toString())
.formatted(Formatting.YELLOW))
.append(Text.literal(".")), false);
} else {
src.sendFeedback(Text.literal("You have disabled ping sounds.")
src.sendFeedback(() -> Text.literal("You have disabled ping sounds.")
.formatted(Formatting.GREEN), false);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public ServerPlayerEntityMixin(World world, BlockPos pos, float yaw, GameProfile

@Unique private PingspamPlayerData pingspamData;
@Unique private int actionbarTime = 0;
@Unique private int prevPingsCount = -1;

@Inject(method = "<init>", at = @At("RETURN"))
private void loadPingspamData(MinecraftServer server, ServerWorld world, GameProfile profile, CallbackInfo ci) {
Expand All @@ -49,6 +50,11 @@ private void tick(CallbackInfo ci) {

var pings = pingspamData.unreadPings();

if (prevPingsCount != pings.size()) {
prevPingsCount = pings.size();
actionbarTime = 0;
}

if (pings.size() > 0 && PingSpam.CONFIG.getConfig().showUnreadMessagesInActionbar) {
actionbarTime--;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
package me.basiqueevangelist.pingspam.network;

import me.basiqueevangelist.pingspam.PingSpam;
import me.basiqueevangelist.pingspam.utils.NameLogic;
import me.lucko.fabric.api.permissions.v0.Permissions;
import net.fabricmc.fabric.api.networking.v1.PacketByteBufs;
import net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking;
import net.minecraft.network.ClientConnection;
import net.minecraft.network.Packet;
import net.minecraft.network.PacketByteBuf;
import net.minecraft.network.packet.Packet;
import net.minecraft.server.PlayerManager;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.util.Identifier;
Expand Down Expand Up @@ -53,7 +54,7 @@ public static void addPossibleName(PlayerManager manager, String possibleName) {
public static void sendToAll(PlayerManager manager, Identifier channel, PacketByteBuf buf) {
Packet<?> packet = ServerPlayNetworking.createS2CPacket(channel, buf);
for (ServerPlayerEntity player : manager.getPlayerList()) {
if (ServerPlayNetworking.canSend(player, channel))
if (ServerPlayNetworking.canSend(player, channel) || PingSpam.CONFIG.getConfig().ignoreCanSend)
player.networkHandler.sendPacket(packet);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import me.basiqueevangelist.pingspam.PingSpam;
import net.minecraft.datafixer.DataFixTypes;
import net.minecraft.datafixer.Schemas;
import net.minecraft.nbt.NbtCompound;
import net.minecraft.nbt.NbtHelper;
import net.minecraft.nbt.NbtIo;
Expand Down Expand Up @@ -31,8 +30,11 @@ public static NbtCompound get(UUID player) throws IOException {
Path savedPlayersPath = PingSpam.SERVER.getSavePath(WorldSavePath.PLAYERDATA);
Path savedDataPath = savedPlayersPath.resolve(player.toString() + ".dat");
NbtCompound rawTag = NbtIo.readCompressed(savedDataPath.toFile());
int dataVersion = rawTag.contains("DataVersion", 3) ? rawTag.getInt("DataVersion") : -1;
return NbtHelper.update(Schemas.getFixer(), DataFixTypes.PLAYER, rawTag, dataVersion);
return DataFixTypes.PLAYER.update(
PingSpam.SERVER.getDataFixer(),
rawTag,
NbtHelper.getDataVersion(rawTag, -1)
);
}

public static List<UUID> listSavedPlayers() {
Expand Down
4 changes: 2 additions & 2 deletions src/main/resources/fabric.mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@
"depends": {
"fabricloader": ">=0.7.4",
"fabric": "*",
"minecraft": "1.19.3",
"minecraft": "1.20.x",
"fabric-permissions-api-v0": "*",
"onedatastore": ">=0.1.2"
"onedatastore": ">=0.1.3-pre.1"
}
}

0 comments on commit d873bd3

Please sign in to comment.