From 13233dd7a8c9178f030b1bf0dc82f477277ce3a3 Mon Sep 17 00:00:00 2001 From: samolego <34912839+samolego@users.noreply.github.com> Date: Tue, 14 Sep 2021 11:12:06 +0200 Subject: [PATCH] Minor changes --- .../java/org/samo_lego/taterzens/commands/NpcCommand.java | 8 ++------ .../org/samo_lego/taterzens/commands/PresetCommand.java | 4 +++- .../mixin/ServerPlayerMixinCast_ITaterzenEditor.java | 6 ++++++ 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/common/src/main/java/org/samo_lego/taterzens/commands/NpcCommand.java b/common/src/main/java/org/samo_lego/taterzens/commands/NpcCommand.java index 7cf6c625d..660a9183c 100644 --- a/common/src/main/java/org/samo_lego/taterzens/commands/NpcCommand.java +++ b/common/src/main/java/org/samo_lego/taterzens/commands/NpcCommand.java @@ -112,7 +112,8 @@ else if(entity instanceof TaterzenNPC taterzenNPC) private static int deselectTaterzen(CommandContext context) throws CommandSyntaxException { CommandSourceStack source = context.getSource(); - ((ITaterzenEditor) source.getPlayerOrException()).selectNpc(null); + ServerPlayer player = source.getPlayerOrException(); + ((ITaterzenEditor) player).selectNpc(null); source.sendSuccess(translate("taterzens.command.deselect").withStyle(ChatFormatting.GREEN), false); return 0; } @@ -173,10 +174,8 @@ private static int selectTaterzenById(CommandContext context TaterzenNPC npc = ((ITaterzenEditor) player).getNpc(); if(npc != null) { ((ITaterzenEditor) player).selectNpc(null); - npc.sendProfileUpdates(); } ((ITaterzenEditor) player).selectNpc(taterzen); - taterzen.sendProfileUpdates(); source.sendSuccess( successText("taterzens.command.select", taterzen.getName().getString()), false @@ -208,14 +207,12 @@ private static int selectTaterzen(CommandContext context) th TaterzenNPC npc = ((ITaterzenEditor) player).getNpc(); if(npc != null) { ((ITaterzenEditor) player).selectNpc(null); - npc.sendProfileUpdates(); } player.getLevel().getEntities(player, box, entity -> { // null check in order to select first one colliding if(entity instanceof TaterzenNPC taterzen && ((ITaterzenEditor) player).getNpc() == null) { ((ITaterzenEditor) player).selectNpc(taterzen); - taterzen.sendProfileUpdates(); source.sendSuccess( successText("taterzens.command.select", entity.getName().getString()), false @@ -254,7 +251,6 @@ private static int spawnTaterzen(CommandContext context) thr TaterzenNPC npc = ((ITaterzenEditor) player).getNpc(); if(npc != null) { ((ITaterzenEditor) player).selectNpc(null); - npc.sendProfileUpdates(); } String taterzenName; diff --git a/common/src/main/java/org/samo_lego/taterzens/commands/PresetCommand.java b/common/src/main/java/org/samo_lego/taterzens/commands/PresetCommand.java index 20ce6f790..0979083ee 100644 --- a/common/src/main/java/org/samo_lego/taterzens/commands/PresetCommand.java +++ b/common/src/main/java/org/samo_lego/taterzens/commands/PresetCommand.java @@ -51,7 +51,6 @@ private static int loadTaterzenFromPreset(CommandContext con String filename = StringArgumentType.getString(context, "preset name") + ".json"; File preset = new File(presetsDir + "/" + filename); CommandSourceStack source = context.getSource(); - ServerPlayer player = source.getPlayerOrException(); if(preset.exists()) { TaterzenNPC taterzenNPC = TaterzensAPI.loadTaterzenFromPreset(preset, source.getLevel()); @@ -62,6 +61,9 @@ private static int loadTaterzenFromPreset(CommandContext con source.getLevel().addFreshEntity(taterzenNPC); ((ITaterzenEditor) source.getPlayerOrException()).selectNpc(taterzenNPC); + + taterzenNPC.sendProfileUpdates(); + source.sendSuccess( successText("taterzens.command.preset.import.success", filename), false diff --git a/common/src/main/java/org/samo_lego/taterzens/mixin/ServerPlayerMixinCast_ITaterzenEditor.java b/common/src/main/java/org/samo_lego/taterzens/mixin/ServerPlayerMixinCast_ITaterzenEditor.java index 51cc2c9e4..c4baf40a8 100644 --- a/common/src/main/java/org/samo_lego/taterzens/mixin/ServerPlayerMixinCast_ITaterzenEditor.java +++ b/common/src/main/java/org/samo_lego/taterzens/mixin/ServerPlayerMixinCast_ITaterzenEditor.java @@ -121,7 +121,13 @@ public TaterzenNPC getNpc() { @Override public void selectNpc(@Nullable TaterzenNPC npc) { + TaterzenNPC selectedNpc = this.taterzens$selectedNpc; this.taterzens$selectedNpc = npc; + + if(npc != null) + npc.sendProfileUpdates(); + if(selectedNpc != null) + selectedNpc.sendProfileUpdates(); } @Override