Skip to content

Commit

Permalink
Minor changes
Browse files Browse the repository at this point in the history
  • Loading branch information
samolego committed Sep 14, 2021
1 parent 892d4cb commit 13233dd
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,8 @@ else if(entity instanceof TaterzenNPC taterzenNPC)

private static int deselectTaterzen(CommandContext<CommandSourceStack> 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;
}
Expand Down Expand Up @@ -173,10 +174,8 @@ private static int selectTaterzenById(CommandContext<CommandSourceStack> 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
Expand Down Expand Up @@ -208,14 +207,12 @@ private static int selectTaterzen(CommandContext<CommandSourceStack> 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
Expand Down Expand Up @@ -254,7 +251,6 @@ private static int spawnTaterzen(CommandContext<CommandSourceStack> context) thr
TaterzenNPC npc = ((ITaterzenEditor) player).getNpc();
if(npc != null) {
((ITaterzenEditor) player).selectNpc(null);
npc.sendProfileUpdates();
}

String taterzenName;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ private static int loadTaterzenFromPreset(CommandContext<CommandSourceStack> 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());
Expand All @@ -62,6 +61,9 @@ private static int loadTaterzenFromPreset(CommandContext<CommandSourceStack> con
source.getLevel().addFreshEntity(taterzenNPC);

((ITaterzenEditor) source.getPlayerOrException()).selectNpc(taterzenNPC);

taterzenNPC.sendProfileUpdates();

source.sendSuccess(
successText("taterzens.command.preset.import.success", filename),
false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 13233dd

Please sign in to comment.