SteamWar/BauSystem2.0
Archiviert
12
0

Add Gui Export and Import

Signed-off-by: Chaoscaot <chaoscaot444@gmail.com>
Dieser Commit ist enthalten in:
Chaoscaot 2021-05-12 21:47:43 +02:00
Ursprung 97eeb78d03
Commit 42e9472463
4 geänderte Dateien mit 139 neuen und 10 gelöschten Zeilen

Datei anzeigen

@ -1,3 +1,22 @@
#
# 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/>.
#
PREFIX = §eBau§8System §8» PREFIX = §eBau§8System §8»
TIME = HH:mm:ss TIME = HH:mm:ss
DATE = ........ DATE = ........
@ -9,11 +28,14 @@ PERMISSION_CHANGE_YOU_ENABLE=§aDer Spieler darf nun {0}
PERMISSION_CHANGE_YOU_DISABLE=§cDer Spieler darf nun nicht mehr {0} PERMISSION_CHANGE_YOU_DISABLE=§cDer Spieler darf nun nicht mehr {0}
PERMISSION_CHANGE_OTHER_ENABLE=§aDu kannst nun auf der Welt von §6{0} §a{1} PERMISSION_CHANGE_OTHER_ENABLE=§aDu kannst nun auf der Welt von §6{0} §a{1}
PERMISSION_CHANGE_OTHER_DISABLE=§cDu kannst nun nicht mehr auf der Welt von §6{0} §c{1} PERMISSION_CHANGE_OTHER_DISABLE=§cDu kannst nun nicht mehr auf der Welt von §6{0} §c{1}
# Feature # Feature
FEATURE_OTHER_ITEMS_TELEPORT_GUI_NAME=Teleportieren FEATURE_OTHER_ITEMS_TELEPORT_GUI_NAME=Teleportieren
FEATURE_OTHER_ITEMS_TELEPORT_PLAYER_OFFLINE=§cDer Spieler ist Offline FEATURE_OTHER_ITEMS_TELEPORT_PLAYER_OFFLINE=§cDer Spieler ist Offline
FEATURE_GUI_EDITOR_ITEM_NAME=§eGui Editor FEATURE_GUI_EDITOR_ITEM_NAME=§eGui Editor
FEATURE_GUI_EXPORT_CODE=§eDein Gui-Code:
FEATURE_GUI_EXPORT_CODE_HOVER=§eKopieren
FEATURE_GUI_IMPORT_INVALID_CODE=§eInvalieder Gui-Code
FEATURE_GUI_IMPORT_CODE_SUCCESFULL=§eGui-Code eingelesen
FEATURE_TRACER_GUI_NAME=Tracer Gui FEATURE_TRACER_GUI_NAME=Tracer Gui
FEATURE_TRACER_GUI_TRACE_INACTIVE=§eTracer Starten FEATURE_TRACER_GUI_TRACE_INACTIVE=§eTracer Starten
FEATURE_TRACER_GUI_TRACE_ACTIVE=§eTracer Stoppen FEATURE_TRACER_GUI_TRACE_ACTIVE=§eTracer Stoppen
@ -22,7 +44,6 @@ FEATURE_TRACER_GUI_AUTO_TRACE_INACTIVE=§eAuto-Tracer Aktivieren
FEATURE_TRACER_GUI_AUTO_TRACE_ACTIVE=§eAuto-Tracer Deaktivieren FEATURE_TRACER_GUI_AUTO_TRACE_ACTIVE=§eAuto-Tracer Deaktivieren
FEATURE_TRACER_GUI_SHOW_GUI=§eTrace Show Gui FEATURE_TRACER_GUI_SHOW_GUI=§eTrace Show Gui
FEATURE_TRACER_GUI_DELETE=§eTrace Löschen FEATURE_TRACER_GUI_DELETE=§eTrace Löschen
# Scoreboard # Scoreboard
SCOREBOARD_TIME = Uhrzeit SCOREBOARD_TIME = Uhrzeit
SCOREBOARD_REGION = Region SCOREBOARD_REGION = Region
@ -39,14 +60,7 @@ FLAG_TNT=TNT
FLAG_FIRE=Fire FLAG_FIRE=Fire
FLAG_FREEZE=Freeze FLAG_FREEZE=Freeze
FLAG_PROTECT=Protect FLAG_PROTECT=Protect
FLAG_FIRE_ALLOW=§can
FLAG_FIRE_DENY=§aaus
FLAG_COLOR = Color
FLAG_TNT = TNT
FLAG_FIRE = Fire
FLAG_DAMAGE = Damage FLAG_DAMAGE = Damage
FLAG_FREEZE = Freeze
FLAG_PROTECT = Protect
FLAG_FIRE_ALLOW = §can FLAG_FIRE_ALLOW = §can
FLAG_FIRE_DENY = §aaus FLAG_FIRE_DENY = §aaus

Datei anzeigen

@ -19,11 +19,18 @@
package de.steamwar.bausystem.features.gui; package de.steamwar.bausystem.features.gui;
import de.steamwar.bausystem.BauSystem;
import de.steamwar.bausystem.config.ColorConfig;
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.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)
@ -47,4 +54,24 @@ 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(ColorConfig.HIGHLIGHT);
component.setBold(true);
component.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, TextComponent.fromLegacyText(BauSystem.MESSAGE.parse("FEATURE_GUI_EXPORT_CODE_HOVER", p))));
component.setClickEvent(new ClickEvent(ClickEvent.Action.COPY_TO_CLIPBOARD, export));
component.setText(export);
BauSystem.MESSAGE.send("FEATURE_GUI_EXPORT_CODE", p);
p.spigot().sendMessage(component);
}
@Register("import")
public void importGui(Player p, String code) {
if (BauGuiImportExport.importGui(code, p)) {
BauSystem.MESSAGE.send("FEATURE_GUI_IMPORT_CODE_SUCCESFULL", p);
}
}
} }

Datei anzeigen

@ -34,7 +34,7 @@ import org.bukkit.inventory.ItemStack;
public class BauGuiEditorGuiItem extends BauGuiItem { public class BauGuiEditorGuiItem extends BauGuiItem {
public BauGuiEditorGuiItem() { public BauGuiEditorGuiItem() {
super(23); super(25);
} }
@Override @Override

Datei anzeigen

@ -0,0 +1,88 @@
/*
* 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 org.bukkit.entity.Player;
import java.util.Base64;
import java.util.HashMap;
import java.util.Map;
public class BauGuiImportExport {
public static String exportGui(BauGuiMapping mapping) {
byte[] bytes = new byte[(mapping.getMapping().size() * 2) + 1];
Map<Integer, Integer> map = mapping.getMapping();
int head = 0;
for (Map.Entry<Integer, Integer> e : map.entrySet()) {
bytes[head] = e.getKey().byteValue();
head++;
bytes[head] = e.getValue().byteValue();
head++;
}
bytes[head] = (byte) mapping.getSize();
return Base64.getEncoder().encodeToString(bytes);
}
public static boolean importGui(String str, Player p) {
byte[] bytes = Base64.getDecoder().decode(str);
if (bytes.length % 2 != 1 || bytes.length < 2) {
BauSystem.MESSAGE.send("FEATURE_GUI_IMPORT_INVALID_CODE", p);
System.out.println("t1");
return false;
}
final int size = bytes[bytes.length - 1];
if (size > 9 * 5) {
BauSystem.MESSAGE.send("FEATURE_GUI_IMPORT_INVALID_CODE", p);
System.out.println("t2");
return false;
}
final Map<Integer, Integer> map = new HashMap<>();
final int itemSize = BauGUI.getITEMS().size();
int head = 0;
do {
byte key = bytes[head];
head++;
byte value = bytes[head];
head++;
if (map.containsKey((int) key) || map.containsValue((int) value) ||
value >= size || key > itemSize) {
BauSystem.MESSAGE.send("FEATURE_GUI_IMPORT_INVALID_CODE", p);
System.out.println("t3");
return false;
}
map.put((int) key, (int) value);
} while (head + 2 < bytes.length);
BauGuiMapping mapping = BauGuiMapping.getGuiMapping(p);
mapping.setMapping(map);
mapping.setSize(size);
return true;
}
}