Skip to content

Commit

Permalink
Packet handler now executes code on the correct thread
Browse files Browse the repository at this point in the history
Known issue still: Restoring twice breaks the client/world
  • Loading branch information
B1n-ry committed Dec 15, 2023
1 parent 5d09680 commit 25f1af3
Show file tree
Hide file tree
Showing 10 changed files with 69 additions and 47 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
# You're in Grave Danger 2.0.0-beta.6

### Changes
* Added back soulbound blacklist tag. Items in this tag can't be enchanted with soulbound

### Fixes
* Players can't retrieve their graves while dead anymore
* Restore command should now delete the grave appropriately

---

Expand Down
8 changes: 4 additions & 4 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,10 @@ dependencies {

// Dev dependencies
// modImplementation "net.fabricmc:fabric-language-kotlin:${project.fabric_kotlin_version}"
// modCompileOnly "dev.onyxstudios.cardinal-components-api:cardinal-components-base:${project.cardinal_components_version}"
// modCompileOnly "dev.onyxstudios.cardinal-components-api:cardinal-components-entity:${project.cardinal_components_version}"
// modCompileOnly "curse.maven:libz-${project.libz_version}"
// modCompileOnly "io.wispforest:owo-lib:${project.owo_version}"
// modImplementation "dev.onyxstudios.cardinal-components-api:cardinal-components-base:${project.cardinal_components_version}"
// modImplementation "dev.onyxstudios.cardinal-components-api:cardinal-components-entity:${project.cardinal_components_version}"
// modImplementation "curse.maven:libz-${project.libz_version}"
// modImplementation "io.wispforest:owo-lib:${project.owo_version}"
}

processResources {
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ org.gradle.parallel=true
levelz_version=517130:4661487

# Dev dependencies
cardinal_components_version=5.1.0
cardinal_components_version=5.2.2
fabric_kotlin_version=1.10.8+kotlin.1.9.0
libz_version=841617:4661485
owo_version=0.11.1+1.20
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.b1n_ry.yigd.enchantment;

import com.b1n_ry.yigd.util.YigdTags;
import net.minecraft.enchantment.Enchantment;
import net.minecraft.enchantment.EnchantmentTarget;
import net.minecraft.entity.EquipmentSlot;
Expand All @@ -25,6 +26,6 @@ public boolean isAvailableForRandomSelection() {

@Override
public boolean isAcceptableItem(ItemStack stack) {
return true;
return !stack.isIn(YigdTags.SOULBOUND_BLACKLIST);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import com.b1n_ry.yigd.client.gui.screens.GraveSelectionScreen;
import com.b1n_ry.yigd.client.gui.screens.PlayerSelectionScreen;
import com.b1n_ry.yigd.components.GraveComponent;
import com.b1n_ry.yigd.config.ClaimPriority;
import com.b1n_ry.yigd.config.YigdConfig;
import com.mojang.authlib.GameProfile;
import net.fabricmc.fabric.api.client.networking.v1.ClientPlayNetworking;
Expand Down
84 changes: 46 additions & 38 deletions src/main/java/com/b1n_ry/yigd/packets/ServerPacketHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,22 +31,24 @@ public static void registerReceivers() {

UUID graveId = buf.readUuid();

Optional<GraveComponent> maybeComponent = DeathInfoManager.INSTANCE.getGrave(graveId);
maybeComponent.ifPresentOrElse(component -> {
GameProfile owner = component.getOwner();
ServerPlayerEntity restoringPlayer = server.getPlayerManager().getPlayer(owner.getId());
if (restoringPlayer == null) {
player.sendMessage(Text.translatable("text.yigd.command.restore.fail.offline_player"));
return;
}

component.applyToPlayer(restoringPlayer, restoringPlayer.getServerWorld(), restoringPlayer.getBlockPos(), true);
component.setStatus(GraveStatus.CLAIMED);

component.removeGraveBlock();

player.sendMessage(Text.translatable("text.yigd.command.restore.success"));
}, () -> player.sendMessage(Text.translatable("text.yigd.command.restore.fail")));
server.execute(() -> {
Optional<GraveComponent> maybeComponent = DeathInfoManager.INSTANCE.getGrave(graveId);
maybeComponent.ifPresentOrElse(component -> {
GameProfile owner = component.getOwner();
ServerPlayerEntity restoringPlayer = server.getPlayerManager().getPlayer(owner.getId());
if (restoringPlayer == null) {
player.sendMessage(Text.translatable("text.yigd.command.restore.fail.offline_player"));
return;
}

component.applyToPlayer(restoringPlayer, restoringPlayer.getServerWorld(), restoringPlayer.getBlockPos(), true);
component.setStatus(GraveStatus.CLAIMED);

component.removeGraveBlock();

player.sendMessage(Text.translatable("text.yigd.command.restore.success"));
}, () -> player.sendMessage(Text.translatable("text.yigd.command.restore.fail")));
});
});
ServerPlayNetworking.registerGlobalReceiver(PacketIdentifiers.GRAVE_ROBBING_C2S, (server, player, handler, buf, responseSender) -> {
YigdConfig config = YigdConfig.getConfig();
Expand All @@ -57,15 +59,17 @@ public static void registerReceivers() {

UUID graveId = buf.readUuid();

Optional<GraveComponent> maybeComponent = DeathInfoManager.INSTANCE.getGrave(graveId);
maybeComponent.ifPresentOrElse(component -> {
component.applyToPlayer(player, player.getServerWorld(), player.getBlockPos(), false);
component.setStatus(GraveStatus.CLAIMED);
server.execute(() -> {
Optional<GraveComponent> maybeComponent = DeathInfoManager.INSTANCE.getGrave(graveId);
maybeComponent.ifPresentOrElse(component -> {
component.applyToPlayer(player, player.getServerWorld(), player.getBlockPos(), false);
component.setStatus(GraveStatus.CLAIMED);

component.removeGraveBlock();
component.removeGraveBlock();

player.sendMessage(Text.translatable("text.yigd.command.rob.success"));
}, () -> player.sendMessage(Text.translatable("text.yigd.command.rob.fail")));
player.sendMessage(Text.translatable("text.yigd.command.rob.success"));
}, () -> player.sendMessage(Text.translatable("text.yigd.command.rob.fail")));
});
});
ServerPlayNetworking.registerGlobalReceiver(PacketIdentifiers.GRAVE_DELETE_C2S, (server, player, handler, buf, responseSender) -> {
YigdConfig config = YigdConfig.getConfig();
Expand All @@ -76,30 +80,34 @@ public static void registerReceivers() {

UUID graveId = buf.readUuid();

ActionResult deleted = DeathInfoManager.INSTANCE.delete(graveId);
DeathInfoManager.INSTANCE.markDirty();

String translatable = switch (deleted) {
case SUCCESS -> "text.yigd.command.delete.success";
case PASS -> "text.yigd.command.delete.pass";
case FAIL -> "text.yigd.command.delete.fail";
default -> "If you see this, congratulations. You've broken YIGD";
};
player.sendMessage(Text.translatable(translatable));
server.execute(() -> {
ActionResult deleted = DeathInfoManager.INSTANCE.delete(graveId);
DeathInfoManager.INSTANCE.markDirty();

String translatable = switch (deleted) {
case SUCCESS -> "text.yigd.command.delete.success";
case PASS -> "text.yigd.command.delete.pass";
case FAIL -> "text.yigd.command.delete.fail";
default -> "If you see this, congratulations. You've broken YIGD";
};
player.sendMessage(Text.translatable(translatable));
});
});
ServerPlayNetworking.registerGlobalReceiver(PacketIdentifiers.GRAVE_LOCKING_C2S, (server, player, handler, buf, responseSender) -> {
YigdConfig config = YigdConfig.getConfig();
if (!Permissions.check(player, "yigd.command.lock", config.commandConfig.unlockPermissionLevel)) {
if (!Permissions.check(player, "yigd.command.locking", config.commandConfig.unlockPermissionLevel)) {
player.sendMessage(Text.translatable("text.yigd.command.permission_fail"));
return;
}

UUID graveId = buf.readUuid();
boolean lockState = buf.readBoolean();

Optional<GraveComponent> component = DeathInfoManager.INSTANCE.getGrave(graveId);
component.ifPresentOrElse(grave -> grave.setLocked(lockState),
() -> player.sendMessage(Text.translatable("text.yigd.command.lock.fail")));
boolean lockState = buf.readBoolean();
server.execute(() -> {
Optional<GraveComponent> component = DeathInfoManager.INSTANCE.getGrave(graveId);
component.ifPresentOrElse(grave -> grave.setLocked(lockState),
() -> player.sendMessage(Text.translatable("text.yigd.command.lock.fail")));
});
});
ServerPlayNetworking.registerGlobalReceiver(PacketIdentifiers.GRAVE_OVERVIEW_REQUEST_C2S, (server, player, handler, buf, responseSender) -> {
YigdConfig config = YigdConfig.getConfig();
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/com/b1n_ry/yigd/util/YigdCommands.java
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,8 @@ private static int viewLatest(CommandContext<ServerCommandSource> context) {
List<GraveComponent> components = DeathInfoManager.INSTANCE.getBackupData(player.getGameProfile());
List<GraveComponent> unClaimedGraves = new ArrayList<>(components);
unClaimedGraves.removeIf(graveComponent -> graveComponent.getStatus() != GraveStatus.UNCLAIMED);
if (unClaimedGraves.size() == 0) {
player.sendMessage(Text.translatable("text.yigd.command_callback.latest.fail"));
if (unClaimedGraves.isEmpty()) {
player.sendMessage(Text.translatable("text.yigd.command.latest.fail"));
return -1;
}

Expand Down
1 change: 1 addition & 0 deletions src/main/java/com/b1n_ry/yigd/util/YigdTags.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,5 @@ public interface YigdTags {
TagKey<Item> NATURAL_VANISHING = TagKey.of(RegistryKeys.ITEM, new Identifier(Yigd.MOD_ID, "natural_vanishing"));
TagKey<Item> LOSS_IMMUNE = TagKey.of(RegistryKeys.ITEM, new Identifier(Yigd.MOD_ID, "loss_immune"));
TagKey<Item> GRAVE_INCOMPATIBLE = TagKey.of(RegistryKeys.ITEM, new Identifier(Yigd.MOD_ID, "grave_incompatible")); // For items that should be dropped instead of put into graves
TagKey<Item> SOULBOUND_BLACKLIST = TagKey.of(RegistryKeys.ITEM, new Identifier(Yigd.MOD_ID, "soulbound_blacklist"));
}
3 changes: 3 additions & 0 deletions src/main/resources/assets/yigd/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
"text.yigd.command.view_self.fail": "Failed to view grave. Couldn't find grave",
"text.yigd.command.whitelist.show_current": "List mode currently %s",
"text.yigd.command.whitelist.added_players": "Added %d players to %s",
"text.yigd.command.whitelist.removed_players": "Removed %d players from %s",
"text.yigd.command.whitelist.toggle": "Toggled list to %s",
"text.yigd.command.whitelist.set_mode": "Set list to %s",
"text.yigd.message.sellout_player": "%s logged off, and they have a grave at X: %d / Y: %d / Z: %d / %s",
Expand All @@ -58,6 +59,8 @@
"text.yigd.message.irl_time": " (%d %s, %d, %d:%d%s)",

"text.yigd.dimension.name.minecraft:overworld": "The Overworld",
"text.yigd.dimension.name.minecraft:the_nether": "The Nether",
"text.yigd.dimension.name.minecraft:the_end": "The End",

"text.autoconfig.yigd.option.inventoryConfig": "Inventory Component Config",
"text.autoconfig.yigd.option.inventoryConfig.dropPlayerHead": "Drop Player Head",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"replace": false,
"values": [

]
}

0 comments on commit 25f1af3

Please sign in to comment.