aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/io/github/moulberry/notenoughupdates/infopanes/DevInfoPane.java
blob: 613442370b6bc1052b450eb5da206a3c000509c6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
package io.github.moulberry.notenoughupdates.infopanes;

import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonPrimitive;
import io.github.moulberry.notenoughupdates.NEUManager;
import io.github.moulberry.notenoughupdates.NEUOverlay;
import io.github.moulberry.notenoughupdates.Utils;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.FontRenderer;
import net.minecraft.client.gui.ScaledResolution;
import net.minecraft.item.Item;
import net.minecraft.util.ResourceLocation;
import org.lwjgl.input.Keyboard;

import java.awt.*;
import java.io.*;
import java.nio.charset.StandardCharsets;
import java.util.*;
import java.util.List;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicInteger;

public class DevInfoPane extends TextInfoPane {

    /**
     * Provides some dev functions used to help with adding new items/detecting missing items.
     */

    public DevInfoPane(NEUOverlay overlay, NEUManager manager) {
        super(overlay, manager, "Dev", "");
        text = getText();
    }

    private String getText() {
        String text = "";

        /*for(Map.Entry<String, JsonObject> item : manager.getItemInformation().entrySet()) {
            if(!item.getValue().has("infoType") || item.getValue().get("infoType").getAsString().isEmpty()) {
                text += item.getKey() + "\n";
            }
        }*/
        for(String s : manager.neuio.getRemovedItems(manager.getItemInformation().keySet())) {
            text += s + "\n";
        }

        if(true) return text;

        /*for(Map.Entry<String, JsonObject> item : manager.getItemInformation().entrySet()) {
            if(!item.getValue().has("infoType") || item.getValue().get("infoType").getAsString().isEmpty()) {
                text += item.getKey() + "\n";
            }
        }*/
        //if(true) return text;

        for(Map.Entry<String, JsonElement> entry : manager.getAuctionPricesJson().get("prices").getAsJsonObject().entrySet()) {
            if(!manager.getItemInformation().keySet().contains(entry.getKey())) {
                if(entry.getKey().contains("-")) {
                    continue;
                }
                if(entry.getKey().startsWith("PERFECT")) continue;
                if(Item.itemRegistry.getObject(new ResourceLocation(entry.getKey().toLowerCase())) != null) {
                    continue;
                }
                text += entry.getKey() + "\n";
            }
        }
        return text;
    }

    AtomicBoolean running = new AtomicBoolean(false);
    ScheduledExecutorService ses = Executors.newScheduledThreadPool(1);

    @Override
    public boolean keyboardInput() {
        if(Keyboard.isKeyDown(Keyboard.KEY_J)) {
            running.set(!running.get());

            for(Map.Entry<String, JsonObject> item : manager.getItemInformation().entrySet()) {
                /*if(!item.getValue().has("infoType") || item.getValue().get("infoType").getAsString().isEmpty()) {
                    if(item.getValue().has("info") && item.getValue().get("info").getAsJsonArray().size()>0) {
                        item.getValue().addProperty("infoType", "WIKI_URL");
                        try {
                            manager.writeJsonDefaultDir(item.getValue(), item.getKey()+".json");
                        } catch(IOException e){}
                        manager.loadItem(item.getKey());
                    }
                }*/
                /*if(item.getKey().startsWith("PET_ITEM_")) {
                    item.getValue().addProperty("infoType", "WIKI_URL");
                    JsonArray array = new JsonArray();
                    array.add(new JsonPrimitive("https://hypixel-skyblock.fandom.com/wiki/Pet_Items"));
                    item.getValue().add("info", array);
                    try {
                        manager.writeJsonDefaultDir(item.getValue(), item.getKey()+".json");
                    } catch(IOException e){}
                    manager.loadItem(item.getKey());
                }*/
                /*if(!item.getValue().has("infoType") || item.getValue().get("infoType").getAsString().isEmpty()) {
                    //String prettyName =

                    String itemS = item.getKey().split("-")[0].split(";")[0];
                    StringBuilder prettyName = new StringBuilder();
                    boolean capital = true;
                    for(int i=0; i<itemS.length(); i++) {
                        char c = itemS.charAt(i);
                        if(capital) {
                            prettyName.append(String.valueOf(c).toUpperCase());
                            capital = false;
                        } else {
                            prettyName.append(String.valueOf(c).toLowerCase());
                        }
                        if(String.valueOf(c).equals("_")) {
                            capital = true;
                        }
                    }
                    String prettyNameS = prettyName.toString();
                    File f = manager.getWebFile("https://hypixel-skyblock.fandom.com/wiki/"+prettyNameS);
                    if(f == null) {
                        continue;
                        //#REDIRECT [[Armor of Magma]]
                    }
                    StringBuilder sb = new StringBuilder();
                    try(BufferedReader br = new BufferedReader(new InputStreamReader(
                            new FileInputStream(f), StandardCharsets.UTF_8))) {
                        String l;
                        while((l = br.readLine()) != null){
                            sb.append(l).append("\n");
                        }
                    } catch(IOException e) {
                        continue;
                    }
                    if(sb.toString().isEmpty()) {
                        continue;
                    }
                    if(sb.toString().startsWith("#REDIRECT")) {
                        prettyNameS = sb.toString().split("\\[\\[")[1].split("]]")[0].replaceAll(" ", "_");
                    }
                    item.getValue().addProperty("infoType", "WIKI_URL");
                    JsonArray array = new JsonArray();
                    array.add(new JsonPrimitive("https://hypixel-skyblock.fandom.com/wiki/"+prettyNameS));
                    item.getValue().add("info", array);
                    try {
                        manager.writeJsonDefaultDir(item.getValue(), item.getKey()+".json");
                    } catch(IOException e){}
                    manager.loadItem(item.getKey());
                }*/
            }

            /*if(running.get()) {
                List<String> add = new ArrayList<>();
                for(Map.Entry<String, JsonObject> item : manager.getItemInformation().entrySet()) {
                    if(item.getValue().has("recipe")) {
                        if(!item.getKey().contains("-") && !item.getKey().contains(";")) {
                            add.add(item.getKey());
                        }
                    }
                }
                AtomicInteger index = new AtomicInteger(0);

                ses.schedule(new Runnable() {
                    public void run() {
                        if(!running.get()) return;

                        int i = index.getAndIncrement();
                        String item = add.get(i).split("-")[0].split(";")[0];
                        Minecraft.getMinecraft().thePlayer.sendChatMessage("/viewrecipe " + item);
                        ses.schedule(this, 1000L, TimeUnit.MILLISECONDS);
                    }
                }, 1000L, TimeUnit.MILLISECONDS);
            }*/
        }
        /*if(Keyboard.isKeyDown(Keyboard.KEY_J) && !running) {
            running = true;
            List<String> add = new ArrayList<>();
            for(Map.Entry<String, JsonElement> entry : manager.getAuctionPricesJson().get("prices").getAsJsonObject().entrySet()) {
                if(!manager.getItemInformation().keySet().contains(entry.getKey())) {
                    if(entry.getKey().contains("-")) {
                        continue;
                    }
                    if(entry.getKey().startsWith("PERFECT")) continue;
                    if(Item.itemRegistry.getObject(new ResourceLocation(entry.getKey().toLowerCase())) != null) {
                        continue;
                    }
                    add.add(entry.getKey());
                }
            }
            AtomicInteger index = new AtomicInteger(0);

            ses.schedule(new Runnable() {
                public void run() {
                    int i = index.getAndIncrement();
                    String item = add.get(i).split("-")[0].split(";")[0];
                    Minecraft.getMinecraft().thePlayer.sendChatMessage("/viewrecipe " + item);
                    ses.schedule(this, 1000L, TimeUnit.MILLISECONDS);
                }
            }, 1000L, TimeUnit.MILLISECONDS);
        }*/
        return false;
    }
}