Update BauGuiImportExport
Signed-off-by: yoyosource <yoyosource@nidido.de>
Dieser Commit ist enthalten in:
Ursprung
80bd8e8e4e
Commit
4d80a3b0d1
@ -75,6 +75,7 @@ public class BauGUICommand extends SWCommand {
|
|||||||
BauSystem.MESSAGE.send("GUI_IMPORT_CODE-SUCCESSFUL", p);
|
BauSystem.MESSAGE.send("GUI_IMPORT_CODE-SUCCESSFUL", p);
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
BauSystem.MESSAGE.send("GUI_IMPORT_INVALID-CODE", p);
|
BauSystem.MESSAGE.send("GUI_IMPORT_INVALID-CODE", p);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -20,13 +20,11 @@
|
|||||||
package de.steamwar.bausystem.features.gui.editor;
|
package de.steamwar.bausystem.features.gui.editor;
|
||||||
|
|
||||||
import de.steamwar.bausystem.BauSystem;
|
import de.steamwar.bausystem.BauSystem;
|
||||||
|
import de.steamwar.bausystem.features.gui.BauGUI;
|
||||||
import lombok.experimental.UtilityClass;
|
import lombok.experimental.UtilityClass;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
import java.util.Base64;
|
import java.util.*;
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
@UtilityClass
|
@UtilityClass
|
||||||
@ -56,7 +54,6 @@ public class BauGuiImportExport {
|
|||||||
if (st.length() / 8 == (int) Math.ceil(st.length() / 8.0)) {
|
if (st.length() / 8 == (int) Math.ceil(st.length() / 8.0)) {
|
||||||
bytes = new byte[st.length() / 8];
|
bytes = new byte[st.length() / 8];
|
||||||
}
|
}
|
||||||
System.out.println(st.toString());
|
|
||||||
|
|
||||||
int index = 0;
|
int index = 0;
|
||||||
while (st.length() > 0) {
|
while (st.length() > 0) {
|
||||||
@ -81,8 +78,17 @@ public class BauGuiImportExport {
|
|||||||
|
|
||||||
private static void binaryConvert(StringBuilder st, String s, char identifier) {
|
private static void binaryConvert(StringBuilder st, String s, char identifier) {
|
||||||
StringBuilder current = new StringBuilder().append(identifier).append(s);
|
StringBuilder current = new StringBuilder().append(identifier).append(s);
|
||||||
|
char reverseIdentifier = identifier == '0' ? '1' : '0';
|
||||||
|
boolean added = false;
|
||||||
while (current.length() % 4 != 0) {
|
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) {
|
while (current.length() > 4) {
|
||||||
st.append('1').append(current.substring(0, 4));
|
st.append('1').append(current.substring(0, 4));
|
||||||
@ -109,10 +115,54 @@ public class BauGuiImportExport {
|
|||||||
size *= 9;
|
size *= 9;
|
||||||
|
|
||||||
st.delete(0, 8);
|
st.delete(0, 8);
|
||||||
System.out.println(st.toString());
|
List<String> blobs = new ArrayList<>();
|
||||||
// BauGUI.getITEMS().containsKey()
|
if (st.length() > 0) {
|
||||||
// TODO: Implement this @yoyo
|
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;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
In neuem Issue referenzieren
Einen Benutzer sperren