RuneHive-Game
Loading...
Searching...
No Matches
DebugAction.java
Go to the documentation of this file.
1package com.runehive.game.action.impl;
2
3import com.google.gson.Gson;
4import com.google.gson.GsonBuilder;
5import com.runehive.game.task.Task;
6import com.runehive.net.packet.out.SendInputMessage;
7import com.runehive.net.packet.out.SendMessage;
8import com.runehive.game.world.entity.mob.player.Player;
9import com.runehive.util.MessageColor;
10
11import java.io.FileWriter;
12import java.util.HashMap;
13import java.util.Map;
14
15/**
16 * This is a debug action. Feel free to modify this how you want to test
17 * whatever.
18 *
19 * @author Daniel
20 */
21public class DebugAction extends Task {
22
23 private Map<Integer, String> DATA = new HashMap<>();
24
25 private final Player player;
26
27 private int identification;
28
29 private int tick;
30
31 private boolean pause;
32
33 private boolean inputTaken;
34
36 super(true, 1);
37 this.player = player;
38 this.tick = 0;
39 this.identification = 0;
40 this.inputTaken = false;
41 this.pause = false;
42 this.DATA = new HashMap<>();
43 }
44
45 private final void save() {
46 Gson gson = new GsonBuilder().setPrettyPrinting().disableHtmlEscaping().create();
47 try (FileWriter fw = new FileWriter("./data/INTERFACES.json")) {
48 fw.write(gson.toJson(DATA));
49 } catch (final Exception e) {
50 e.printStackTrace();
51 }
52 }
53
54 private void input(Player player) {
55 player.send(new SendInputMessage("Enter the itemcontainer description", 100, input -> {
57 inputTaken = false;
58 pause = false;
59 }));
60 }
61
62
63 @Override
64 public void execute() {
65 if (inputTaken) {
66 if (tick++ == 1) {
68 }
69 return;
70 }
71
72 if (pause) {
73 player.dialogueFactory.sendOption(
74 "Empty",
75 () -> pause = false,
76
77 "Enter", () -> {
78 player.dialogueFactory.clear();
79 tick = 0;
80 inputTaken = true;
81 },
82 "Save & End",
83 () -> {
84 save();
85 cancel();
86 player.send(new SendMessage("A total of " + DATA.size() + " interfaces were saved."));
87 }).execute();
88 return;
89 }
90
92 player.interfaceManager.open(identification);
93 player.send(new SendMessage("Opening itemcontainer: " + identification, MessageColor.DARK_RED));
94 pause = true;
95 }
96
97}
void execute()
A function representing the unit of work that will be carried out.
synchronized final void cancel()
Cancels all subsequent executions.
Definition Task.java:113
Task(boolean instant, int delay)
Creates a new Task.
Definition Task.java:41
This class represents a character controlled by a player.
Definition Player.java:125
Sends a chatbox input prompt that accepts full text with spaces.
The OutgoingPacket that sends a message to a Players chatbox in the client.
Holds an enum of colors for ease.