SteamWar/BauSystem2.0
Archiviert
12
0

Update BauGuiImportExport

Signed-off-by: yoyosource <yoyosource@nidido.de>
Dieser Commit ist enthalten in:
yoyosource 2021-06-14 13:32:00 +02:00
Ursprung 80bd8e8e4e
Commit 4d80a3b0d1
2 geänderte Dateien mit 60 neuen und 9 gelöschten Zeilen

Datei anzeigen

@ -75,6 +75,7 @@ public class BauGUICommand extends SWCommand {
BauSystem.MESSAGE.send("GUI_IMPORT_CODE-SUCCESSFUL", p);
}
} catch (Exception e) {
e.printStackTrace();
BauSystem.MESSAGE.send("GUI_IMPORT_INVALID-CODE", p);
}
}

Datei anzeigen

@ -20,13 +20,11 @@
package de.steamwar.bausystem.features.gui.editor;
import de.steamwar.bausystem.BauSystem;
import de.steamwar.bausystem.features.gui.BauGUI;
import lombok.experimental.UtilityClass;
import org.bukkit.entity.Player;
import java.util.Base64;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.*;
import java.util.stream.Collectors;
@UtilityClass
@ -56,7 +54,6 @@ public class BauGuiImportExport {
if (st.length() / 8 == (int) Math.ceil(st.length() / 8.0)) {
bytes = new byte[st.length() / 8];
}
System.out.println(st.toString());
int index = 0;
while (st.length() > 0) {
@ -81,8 +78,17 @@ public class BauGuiImportExport {
private static void binaryConvert(StringBuilder st, String s, char identifier) {
StringBuilder current = new StringBuilder().append(identifier).append(s);
char reverseIdentifier = identifier == '0' ? '1' : '0';
boolean added = false;
while (current.length() % 4 != 0) {
current.insert(0, '0');
current.insert(0, reverseIdentifier);
added = true;
}
if (!added) {
current.insert(0, reverseIdentifier);
current.insert(0, reverseIdentifier);
current.insert(0, reverseIdentifier);
current.insert(0, reverseIdentifier);
}
while (current.length() > 4) {
st.append('1').append(current.substring(0, 4));
@ -109,10 +115,54 @@ public class BauGuiImportExport {
size *= 9;
st.delete(0, 8);
System.out.println(st.toString());
// BauGUI.getITEMS().containsKey()
// TODO: Implement this @yoyo
List<String> blobs = new ArrayList<>();
if (st.length() > 0) {
blobs.add("");
}
while (st.length() > 4) {
String current = st.substring(0, 5);
int last = blobs.size() - 1;
blobs.set(last, blobs.get(last) + current.substring(1));
if (current.startsWith("0")) {
blobs.add("");
}
st.delete(0, 5);
}
blobs.removeIf(String::isEmpty);
blobs.replaceAll(s -> {
char start = s.charAt(0);
for (int i = 0; i < s.length(); i++) {
if (s.charAt(i) != start) {
return s.substring(i);
}
}
return s;
});
int currentIndex = 0;
Map<Integer, Integer> map = new HashMap<>();
boolean initial = true;
for (String s : blobs) {
if (s.startsWith("0")) {
currentIndex += Integer.parseInt(s.substring(1), 2);
} else {
if (!initial) {
currentIndex++;
}
initial = false;
s = s.substring(1);
int itemID = Integer.parseInt(s, 2);
if (!BauGUI.getITEMS().containsKey(itemID)) {
BauSystem.MESSAGE.send("GUI_IMPORT_INVALID-CODE", p);
return false;
}
map.put(itemID, currentIndex);
}
}
BauGuiMapping mapping = BauGuiMapping.getGuiMapping(p);
mapping.setMapping(map);
mapping.setSize(size);
return true;
}
}