SteamWar/BauSystem2.0
Archiviert
12
0

Remove unused features

Signed-off-by: yoyosource <yoyosource@nidido.de>
Dieser Commit ist enthalten in:
yoyosource 2022-04-16 17:38:47 +02:00
Ursprung 20e907a5a2
Commit 38102154ae
2 geänderte Dateien mit 0 neuen und 200 gelöschten Zeilen

Datei anzeigen

@ -19,18 +19,11 @@
package de.steamwar.bausystem.features.gui; package de.steamwar.bausystem.features.gui;
import de.steamwar.bausystem.BauSystem;
import de.steamwar.bausystem.features.gui.editor.BauGuiEditor; import de.steamwar.bausystem.features.gui.editor.BauGuiEditor;
import de.steamwar.bausystem.features.gui.editor.BauGuiImportExport;
import de.steamwar.bausystem.features.gui.editor.BauGuiMapping;
import de.steamwar.bausystem.linkage.LinkageType; import de.steamwar.bausystem.linkage.LinkageType;
import de.steamwar.bausystem.linkage.Linked; import de.steamwar.bausystem.linkage.Linked;
import de.steamwar.command.SWCommand; import de.steamwar.command.SWCommand;
import de.steamwar.inventory.SWItem; import de.steamwar.inventory.SWItem;
import net.md_5.bungee.api.ChatColor;
import net.md_5.bungee.api.chat.ClickEvent;
import net.md_5.bungee.api.chat.HoverEvent;
import net.md_5.bungee.api.chat.TextComponent;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
@Linked(LinkageType.COMMAND) @Linked(LinkageType.COMMAND)
@ -54,29 +47,4 @@ public class BauGUICommand extends SWCommand {
public void openEditor(Player p) { public void openEditor(Player p) {
BauGuiEditor.openGuiEditor(p, new SWItem().getItemStack()); BauGuiEditor.openGuiEditor(p, new SWItem().getItemStack());
} }
@Register("export")
public void exportGui(Player p) {
String export = BauGuiImportExport.exportGui(BauGuiMapping.getGuiMapping(p));
TextComponent component = new TextComponent();
component.setColor(ChatColor.YELLOW);
component.setBold(true);
component.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, TextComponent.fromLegacyText(BauSystem.MESSAGE.parse("GUI_EXPORT_CODE_HOVER", p))));
component.setClickEvent(new ClickEvent(ClickEvent.Action.COPY_TO_CLIPBOARD, export));
component.setText(export);
BauSystem.MESSAGE.send("GUI_EXPORT_CODE", p);
p.spigot().sendMessage(component);
}
@Register("import")
public void importGui(Player p, String code) {
try {
if (BauGuiImportExport.importGui(code, p)) {
BauSystem.MESSAGE.send("GUI_IMPORT_CODE_SUCCESSFUL", p);
}
} catch (Exception e) {
e.printStackTrace();
BauSystem.MESSAGE.send("GUI_IMPORT_INVALID_CODE", p);
}
}
} }

Datei anzeigen

@ -1,168 +0,0 @@
/*
* This file is a part of the SteamWar software.
*
* Copyright (C) 2021 SteamWar.de-Serverteam
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
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.*;
import java.util.stream.Collectors;
@UtilityClass
public class BauGuiImportExport {
private static final String VERSION = "00000";
public String exportGui(BauGuiMapping mapping) {
StringBuilder st = new StringBuilder();
st.append(VERSION); // Version in Binary (0 - 32)
append(st, Integer.toBinaryString(mapping.getSize() / 9), 3); // Menu Size
Map<Integer, Integer> map = new HashMap<>();
mapping.getMapping().forEach((integer, integer2) -> map.put(integer2, integer));
List<Integer> integerList = map.keySet().stream().sorted().collect(Collectors.toList());
for (int i = 0; i < integerList.size(); i++) {
int current = integerList.get(i);
int last = i == 0 ? -1 : integerList.get(i - 1);
if (current - last > 1) {
binaryConvert(st, Integer.toBinaryString(current - last - 1), '0');
}
binaryConvert(st, Integer.toBinaryString(map.get(current)), '1');
}
byte[] bytes = new byte[st.length() / 8 + 1];
if (st.length() / 8 == (int) Math.ceil(st.length() / 8.0)) {
bytes = new byte[st.length() / 8];
}
int index = 0;
while (st.length() > 0) {
byte result = 0;
for (int i = 0; i < Math.min(8, st.length()); i++) {
result |= (st.charAt(i) - '0') << (7 - i);
}
bytes[index] = result;
index++;
st.delete(0, Math.min(8, st.length()));
}
return Base64.getEncoder().encodeToString(bytes);
}
private static void append(StringBuilder st, String s, int length) {
for (int i = 0; i < length - s.length(); i++) {
st.append("0");
}
st.append(s);
}
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, 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));
current.delete(0, 4);
}
st.append('0').append(current);
}
public static boolean importGui(String str, Player p) {
byte[] bytes = Base64.getDecoder().decode(str);
StringBuilder st = new StringBuilder();
for (byte b : bytes) {
append(st, Integer.toBinaryString(b & 0xFF), 8);
}
if (!st.substring(0, 5).equals(VERSION)) {
BauSystem.MESSAGE.send("GUI_IMPORT_INVALID_CODE", p);
return false;
}
int size = Integer.parseInt(st.substring(5, 8), 2);
if (size <= 0 || size > 5) {
BauSystem.MESSAGE.send("GUI_IMPORT_INVALID_CODE", p);
return false;
}
size *= 9;
st.delete(0, 8);
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;
}
}