Skip to content

Commit 70fe3c3

Browse files
committed
feat: complete abiphone
1 parent 3e9be6d commit 70fe3c3

14 files changed

Lines changed: 272 additions & 72 deletions

File tree

type.deepcaverns/src/main/java/net/swofty/type/deepcaverns/npcs/NPCWalter.java

Lines changed: 8 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import net.minestom.server.item.ItemStack;
66
import net.swofty.type.deepcaverns.gui.GUIShopWalter;
77
import net.swofty.type.generic.entity.npc.HypixelNPC;
8+
import net.swofty.type.generic.entity.npc.NPCAbiphoneTrait;
89
import net.swofty.type.generic.entity.npc.NPCOption;
910
import net.swofty.type.generic.entity.npc.configuration.HumanConfiguration;
1011
import net.swofty.type.generic.user.HypixelPlayer;
@@ -18,7 +19,7 @@
1819

1920
import net.swofty.type.generic.event.custom.NPCInteractEvent;
2021

21-
public class NPCWalter extends HypixelNPC {
22+
public class NPCWalter extends HypixelNPC implements NPCAbiphoneTrait {
2223

2324
public NPCWalter() {
2425
super(new HumanConfiguration() {
@@ -54,23 +55,6 @@ public void onClick(NPCInteractEvent event) {
5455
SkyBlockPlayer player = (SkyBlockPlayer) event.player();
5556
if (isInDialogue(player)) return;
5657

57-
ItemStack itemStack = player.getItemInMainHand();
58-
SkyBlockItem item = new SkyBlockItem(itemStack);
59-
60-
if (item.hasComponent(AbiphoneComponent.class)) {
61-
setDialogue(player, "abiphone").thenRun(() -> {
62-
NPCOption.sendOption(player, "walter", Collections.singletonList(new NPCOption.Option(
63-
"pay", // actual id from Hypixel
64-
NamedTextColor.GREEN,
65-
"DONATE CUBE",
66-
(p) -> {
67-
setDialogue(player, "donate_cube_no_requirements");
68-
}
69-
)));
70-
});
71-
return;
72-
}
73-
7458
setDialogue(player, "none").thenRun(() -> {
7559
MathUtility.delay(() -> new GUIShopWalter().open(player), 20);
7660
});
@@ -82,23 +66,12 @@ public DialogueSet[] dialogues(HypixelPlayer player) {
8266
DialogueSet.builder()
8367
.key("none").lines(new String[]{
8468
"With the right tools, you can get through anything!",
85-
}).build(),
86-
DialogueSet.builder()
87-
.key("abiphone").lines(new String[]{ // when clicking with an Abiphone
88-
"My abiphone is for Platinum-level donors of the Walter cause only.",
89-
"You know these superbooms don't craft themselves right?",
90-
"You just need §3Sulphur Collection 7 §fand to then donate an Enchanted Sulphur Cube!", // then show "donate cube" option
91-
}).abiPhone(true).build(),
92-
DialogueSet.builder()
93-
.key("donate_cube").lines(new String[]{ // when donating the cube with requirements met
94-
"Welcome to the Platinum club, high roller!",
95-
"Call me anytime!",
96-
"And before you ask... yes, I do try to commercialize all of my friendships.",
97-
}).abiPhone(true).build(),
98-
DialogueSet.builder()
99-
.key("donate_cube_no_requirements").lines(new String[]{ // when donating the cube without requirements met
100-
"Mmh... you're missing something to become a Platinum-level donor...",
101-
}).abiPhone(true).build()
69+
}).build()
10270
).toArray(DialogueSet[]::new);
10371
}
72+
73+
@Override
74+
public String getAbiphoneKey() {
75+
return "walter";
76+
}
10477
}

type.generic/src/main/java/net/swofty/type/generic/data/datapoints/DatapointToggles.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,8 @@ public enum ToggleType {
8080
HAS_SPOKEN_TO_BAKER(false),
8181
HAS_SPOKEN_TO_RUSTY(false),
8282
HAS_SPOKEN_TO_RUSTY_ABOUT_PICKAXE(false),
83+
HAS_SPOKEN_TO_RUSTY_ABOUT_ABIPHONE(false),
84+
HAS_GIVEN_WALTER_CUBE(false),
8385
HAS_SPOKEN_TO_CURATOR(false),
8486
HAS_SPOKEN_TO_MADAME_ELEANOR(false),
8587
HAS_DONE_COAL_TRADE_WITH_BLACKSMITH(false),

type.generic/src/main/java/net/swofty/type/generic/entity/npc/DialogueController.java

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -64,11 +64,8 @@ public void cancelDialogue(HypixelPlayer player) {
6464
}
6565

6666
private void handleLineSendingLoop(HypixelPlayer player, HypixelNPC.DialogueSet dialogueSet) {
67-
if (dialogueSet.abiPhone()) {
68-
npc.sendNPCAbiphoneMessage(player, dialogueSet.lines()[0]);
69-
} else {
70-
npc.sendNPCMessage(player, dialogueSet.lines()[0]);
71-
}
67+
npc.sendNPCMessage(player, dialogueSet.lines()[0]);
68+
7269

7370
String[] newLines = new String[dialogueSet.lines().length - 1];
7471
System.arraycopy(dialogueSet.lines(), 1, newLines, 0, dialogueSet.lines().length - 1);
@@ -89,7 +86,6 @@ private void handleLineSendingLoop(HypixelPlayer player, HypixelNPC.DialogueSet
8986
handleLineSendingLoop(player, HypixelNPC.DialogueSet.builder()
9087
.key(dialogueSet.key())
9188
.lines(newLines)
92-
.abiPhone(dialogueSet.abiPhone())
9389
.build());
9490
}
9591
}).delay(TaskSchedule.seconds(2)).schedule();

type.generic/src/main/java/net/swofty/type/generic/entity/npc/HypixelNPC.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -228,10 +228,6 @@ public void sendNPCMessage(HypixelPlayer player, String message) {
228228
player.sendMessage("§e[NPC] " + getName() + "§f: " + message);
229229
}
230230

231-
public void sendNPCAbiphoneMessage(HypixelPlayer player, String message) {
232-
player.sendMessage("§e[NPC] " + getName() + "§f: §b✆ §f" + message);
233-
}
234-
235231
protected DialogueController dialogue() {
236232
return dialogueController;
237233
}
@@ -296,7 +292,7 @@ public Map.Entry<PlayerHolograms.ExternalPlayerHologram, Entity> get(HypixelNPC
296292
}
297293

298294
@Builder
299-
public record DialogueSet(String key, String[] lines, boolean abiPhone) {
295+
public record DialogueSet(String key, String[] lines) {
300296
public static final DialogueSet[] EMPTY = new DialogueSet[0];
301297
}
302298
}

type.goldmine/src/main/java/net/swofty/type/goldmine/npcs/villagers/VillagerRusty.java

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -97,20 +97,7 @@ public DialogueSet[] dialogues(HypixelPlayer player) {
9797
"It drives me insane, but at least you'll unlock §aAuto-pickup §fat §3SkyBlock Level 6.",
9898
"It makes my job a lot easier, but despite that, I still find so many items on the ground.",
9999
"Maybe some of those items are yours? In which case I'll let you buy them back."
100-
}).build(),
101-
DialogueSet.builder()
102-
.key("abiphone").lines(new String[]{ // when clicking with an Abiphone
103-
"§fDid I find an Abiphone?",
104-
"§fYes, sometimes I do find one lying around.",
105-
"§fWhat?",
106-
"§fYou?",
107-
"§fYou want my contact?",
108-
"§fMe?",
109-
"§fThe janitor?",
110-
"§fI...",
111-
"§fI don't... don't know what to say...",
112-
"§fYes of course you can have it!",
113-
}).abiPhone(true).build()
100+
}).build()
114101
).toArray(DialogueSet[]::new);
115102
}
116103

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
package net.swofty.type.skyblockgeneric.abiphone;
2+
3+
import net.minestom.server.MinecraftServer;
4+
import net.minestom.server.timer.Scheduler;
5+
import net.minestom.server.timer.TaskSchedule;
6+
import net.swofty.type.generic.user.HypixelPlayer;
7+
8+
import java.util.HashMap;
9+
import java.util.Map;
10+
import java.util.concurrent.CompletableFuture;
11+
12+
public class AbiphoneDialogueController {
13+
private final HashMap<HypixelPlayer, Map.Entry<AbiphoneNPC.DialogueSet, CompletableFuture<String>>> activeDialogues = new HashMap<>();
14+
private final AbiphoneNPC npc;
15+
16+
public AbiphoneDialogueController(AbiphoneNPC npc) {
17+
this.npc = npc;
18+
}
19+
20+
/**
21+
* Checks if the player is currently in a dialogue with this NPC.
22+
*
23+
* @param player The player to check.
24+
* @return True if the player is in dialogue, false otherwise.
25+
*/
26+
public boolean isInDialogue(HypixelPlayer player) {
27+
return activeDialogues.containsKey(player);
28+
}
29+
30+
/**
31+
* Starts a dialogue with the player using the specified dialogue key.
32+
*
33+
* @param player The player to start the dialogue with.
34+
* @param key The key of the dialogue set to play.
35+
* @return A CompletableFuture that completes when the dialogue finishes, with the dialogue key.
36+
*/
37+
public CompletableFuture<String> setDialogue(HypixelPlayer player, String key) {
38+
CompletableFuture<String> future = new CompletableFuture<>();
39+
40+
AbiphoneNPC.DialogueSet[] dialogueSets = npc.dialogues(player);
41+
for (AbiphoneNPC.DialogueSet dialogueSet : dialogueSets) {
42+
if (dialogueSet.key().equals(key)) {
43+
activeDialogues.put(player, Map.entry(dialogueSet, future));
44+
handleLineSendingLoop(player, dialogueSet);
45+
return future;
46+
}
47+
}
48+
49+
future.completeExceptionally(new NullPointerException("Dialogue set with key '" + key + "' not found."));
50+
return future;
51+
}
52+
53+
/**
54+
* Removes the player from the dialogue, completing the future with null.
55+
*
56+
* @param player The player to remove from dialogue.
57+
*/
58+
public void cancelDialogue(HypixelPlayer player) {
59+
Map.Entry<AbiphoneNPC.DialogueSet, CompletableFuture<String>> entry = activeDialogues.get(player);
60+
if (entry != null) {
61+
entry.getValue().complete(null);
62+
activeDialogues.remove(player);
63+
}
64+
}
65+
66+
private void handleLineSendingLoop(HypixelPlayer player, AbiphoneNPC.DialogueSet dialogueSet) {
67+
npc.sendNPCMessage(player, dialogueSet.lines()[0]);
68+
69+
String[] newLines = new String[dialogueSet.lines().length - 1];
70+
System.arraycopy(dialogueSet.lines(), 1, newLines, 0, dialogueSet.lines().length - 1);
71+
72+
if (newLines.length == 0) {
73+
Map.Entry<AbiphoneNPC.DialogueSet, CompletableFuture<String>> entry = activeDialogues.get(player);
74+
if (entry != null) {
75+
entry.getValue().complete(dialogueSet.key());
76+
}
77+
activeDialogues.remove(player);
78+
return;
79+
}
80+
81+
Scheduler scheduler = MinecraftServer.getSchedulerManager();
82+
scheduler.buildTask(() -> {
83+
// Check if the player is still in dialogue (might have been canceled)
84+
if (activeDialogues.containsKey(player)) {
85+
handleLineSendingLoop(player, AbiphoneNPC.DialogueSet.builder()
86+
.key(dialogueSet.key())
87+
.lines(newLines)
88+
.build());
89+
}
90+
}).delay(TaskSchedule.seconds(2)).schedule();
91+
}
92+
93+
public static void removeAllDialogues(HypixelPlayer player) {
94+
for (AbiphoneNPC npc : AbiphoneRegistry.getRegisteredContactNPCs()) {
95+
npc.dialogue().cancelDialogue(player);
96+
}
97+
}
98+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,49 @@
11
package net.swofty.type.skyblockgeneric.abiphone;
22

33
import lombok.AllArgsConstructor;
4+
import lombok.Builder;
45
import lombok.Getter;
56
import net.minestom.server.item.ItemStack;
67
import net.swofty.type.generic.user.HypixelPlayer;
8+
import net.swofty.type.skyblockgeneric.item.components.AbiphoneComponent;
9+
import net.swofty.type.skyblockgeneric.item.updater.PlayerItemOrigin;
10+
import net.swofty.type.skyblockgeneric.user.SkyBlockPlayer;
711

812
@Getter
913
@AllArgsConstructor
1014
public abstract class AbiphoneNPC {
1115
private final String id;
1216
private final String name;
1317
private final String description;
18+
private final AbiphoneDialogueController dialogueController = new AbiphoneDialogueController(this);
1419

1520
public abstract void onCall(HypixelPlayer player);
1621

22+
public void onAdd(SkyBlockPlayer player, int slot) {
23+
player.updateItemInSlot(slot, (i) -> {
24+
if (!i.hasComponent(AbiphoneComponent.class)) return;
25+
i.getAttributeHandler().addAbiphoneNPC(this);
26+
player.sendMessage("§b✆ " + getName() + " §fhas been added to your Abiphone's contacts!");
27+
});
28+
}
29+
30+
protected AbiphoneDialogueController dialogue() {
31+
return dialogueController;
32+
}
33+
34+
public DialogueSet[] dialogues(HypixelPlayer player) {
35+
return DialogueSet.EMPTY;
36+
}
37+
1738
public abstract ItemStack.Builder getIcon();
1839

40+
public void sendNPCMessage(HypixelPlayer player, String message) {
41+
player.sendMessage("§e[NPC] " + getName() + "§f: §b✆ §f" + message);
42+
}
43+
44+
@Builder
45+
public record DialogueSet(String key, String[] lines, boolean abiPhone) {
46+
public static final DialogueSet[] EMPTY = new DialogueSet[0];
47+
}
48+
1949
}

type.skyblockgeneric/src/main/java/net/swofty/type/skyblockgeneric/abiphone/impl/AbiphoneRusty.java

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,31 @@
22

33
import net.minestom.server.item.ItemStack;
44
import net.minestom.server.item.Material;
5+
import net.swofty.type.generic.data.datapoints.DatapointToggles;
56
import net.swofty.type.generic.user.HypixelPlayer;
67
import net.swofty.type.skyblockgeneric.abiphone.AbiphoneNPC;
7-
import net.swofty.type.skyblockgeneric.gui.inventories.GUIRusty;
8+
import net.swofty.type.skyblockgeneric.gui.inventories.rusty.GUIRusty;
9+
import net.swofty.type.skyblockgeneric.user.SkyBlockPlayer;
810

911
public class AbiphoneRusty extends AbiphoneNPC {
1012

1113
public AbiphoneRusty() {
1214
super("rusty", "Rusty", "SkyBlock's Janitor");
1315
}
1416

17+
@Override
18+
public void onAdd(SkyBlockPlayer player, int slot) {
19+
if (!player.getToggles().get(DatapointToggles.Toggles.ToggleType.HAS_SPOKEN_TO_RUSTY_ABOUT_ABIPHONE)) {
20+
if (dialogue().isInDialogue(player)) return;
21+
dialogue().setDialogue(player, "abiphone").thenRun(() -> {
22+
player.getToggles().set(DatapointToggles.Toggles.ToggleType.HAS_SPOKEN_TO_RUSTY_ABOUT_ABIPHONE, true);
23+
super.onAdd(player, slot);
24+
});
25+
return;
26+
}
27+
super.onAdd(player, slot);
28+
}
29+
1530
@Override
1631
public void onCall(HypixelPlayer player) {
1732
new GUIRusty().open(player);
@@ -22,4 +37,22 @@ public ItemStack.Builder getIcon() {
2237
return ItemStack.builder(Material.VILLAGER_SPAWN_EGG);
2338
}
2439

40+
@Override
41+
public DialogueSet[] dialogues(HypixelPlayer player) {
42+
return new DialogueSet[]{
43+
DialogueSet.builder()
44+
.key("abiphone").lines(new String[]{
45+
"§fDid I find an Abiphone?",
46+
"§fYes, sometimes I do find one lying around.",
47+
"§fWhat?",
48+
"§fYou?",
49+
"§fYou want my contact?",
50+
"§fMe?",
51+
"§fThe janitor?",
52+
"§fI...",
53+
"§fI don't... don't know what to say...",
54+
"§fYes of course you can have it!",
55+
}).build()
56+
};
57+
}
2558
}

0 commit comments

Comments
 (0)