SteamWar/BauSystem2.0
Archiviert
12
0

Merge remote-tracking branch 'origin/master'

Dieser Commit ist enthalten in:
Chaoscaot 2021-05-27 22:52:49 +02:00
Commit 8dbb9cb940
5 geänderte Dateien mit 197 neuen und 67 gelöschten Zeilen

Datei anzeigen

@ -35,6 +35,7 @@ public enum Detoblock {
TRIPWIRE(30, "DETONATOR_BUTTON_TRIPWIRE"),
NOTEBLOCK(1, "DETONATOR_BUTTON_NOTEBLOCK"),
DAYLIGHTSENSOR(0, true, "DETONATOR_BUTTON_DAYLIGHTSENSOR"),
POWERABLE(0, true, "DETONATOR_BUTTON_POWERABLE"),
INVALID(-1, "DETONATOR_BUTTON_INVALID");
private final int time;

Datei anzeigen

@ -139,6 +139,7 @@ DETONATOR_BUTTON_WEIGHTED-PRESSURE-PLATE = Druckplatte
DETONATOR_BUTTON_TRIPWIRE = Tripwire
DETONATOR_BUTTON_NOTEBLOCK = Noteblock
DETONATOR_BUTTON_DAYLIGHTSENSOR = Tageslichtsensor
DETONATOR_BUTTON_POWERABLE = Aktivierbarer Block
DETONATOR_BUTTON_INVALID = Invalider
# Hotbar
@ -185,33 +186,47 @@ LOADER_MESSAGE_CLEAR-HELP = §cDu must im Setup-Modus sein um den Loader zu clea
LOADER_MESSAGE_TNT = §eTNT hinzugefügt {0}
LOADER_MESSAGE_INTERACT = §e{0} hinzugefügt {1}
LOADER_BUTTON_SWITCH=Hebel
LOADER_BUTTON_WOOD-Button=Knopf
LOADER_BUTTON_STONE-Button=Knopf
LOADER_BUTTON_PRESSURE-PLATE=Druckplatte
LOADER_BUTTON_WEIGHTED-PRESSURE-PLATE=Druckplatte
LOADER_BUTTON_TRIPWIRE=Tripwire
LOADER_BUTTON_NOTEBLOCK=Noteblock
LOADER_BUTTON_DAYLIGHTSENSOR=Tageslichtsensor
LOADER_BUTTON_INVALID=Invalider
#Loadtimer
LOADTIMER_WAITING=§7Platziere ein TNT zum starten...
LOADTIMER_BOSSBAR=§7Tick: §e{0}§7(§e{1}§7) Zeit: §e{2}s §7Tnt: §e{3} §7Blöcke
LOADTIMER_ACTIVATED=§7Warte auf Zündung
LOADTIMER_IGNITION=§7Warte auf Explosion
LOADTIMER_SUMARY_HEAD=§7---=== (§eLoadtimer-Auswertung§7) ===---
LOADTIMER_SUMARY_PLAYERTABLE_HEAD=§7Spieler: §eTNT §7(§eTNT/s§7)
LOADTIMER_SUMARY_PLAYERTABLE_PLAYER=§7{0}: §e{1} §7(§e{2}/s§7)
LOADTIMER_SUMARY_PLAYERTABLE_ALL=Insgesamt
LOADTIMER_SUMARY_TIMES_HEAD=§7Zeiten: §eSekunden §7(§eTicks§7)
LOADTIMER_SUMARY_TIMES_START=§7 || §7Start!
LOADTIMER_SUMARY_TIMES_ACTIVATION=§7 || Aktivierung: §e{0}s §7(§e{1}t§7)
LOADTIMER_SUMARY_TIMES_IGNITION=§7 || Zündung: §e{0}s §7(§e{1}t§7)
LOADTIMER_SUMARY_TIMES_EXPLOSION=§7 || Explosion: §e{0}s §7(§e{1}t§7)
LOADTIMER_SUMARY_TIMES_LAST=§7\\/
LOADTIMER_SUMARY_STATS_HEAD=§7Kanonen-Stats§8:
LOADTIMER_SUMARY_STATS_TNT=§7TNT: §e{0}
LOADTIMER_SUMARY_STATS_FREQ=§7Belade Frequenz: §e{0}/m§8, §7Schuss Frequenz: §e{1}/m
LOADER_BUTTON_SWITCH = Hebel
LOADER_BUTTON_WOOD-Button = Knopf
LOADER_BUTTON_STONE-Button = Knopf
LOADER_BUTTON_PRESSURE-PLATE = Druckplatte
LOADER_BUTTON_WEIGHTED-PRESSURE-PLATE = Druckplatte
LOADER_BUTTON_TRIPWIRE = Tripwire
LOADER_BUTTON_NOTEBLOCK = Noteblock
LOADER_BUTTON_DAYLIGHTSENSOR = Tageslichtsensor
LOADER_BUTTON_INVALID = Invalider
# Loadtimer
LOADTIMER_WAITING = §7Platziere ein TNT zum starten...
LOADTIMER_BOSSBAR = §7Tick: §e{0}§7(§e{1}§7) Zeit: §e{2}s §7Tnt: §e{3} §7Blöcke
LOADTIMER_ACTIVATED = §7Warte auf Zündung
LOADTIMER_IGNITION = §7Warte auf Explosion
LOADTIMER_SUMARY_HEAD = §7---=== (§eLoadtimer-Auswertung§7) ===---
LOADTIMER_SUMARY_PLAYERTABLE_HEAD = §7Spieler: §eTNT §7(§eTNT/s§7)
LOADTIMER_SUMARY_PLAYERTABLE_PLAYER = §7{0}: §e{1} §7(§e{2}/s§7)
LOADTIMER_SUMARY_PLAYERTABLE_ALL = Insgesamt
LOADTIMER_SUMARY_TIMES_HEAD = §7Zeiten: §eSekunden §7(§eTicks§7)
LOADTIMER_SUMARY_TIMES_START = §7 || §7Start!
LOADTIMER_SUMARY_TIMES_ACTIVATION = §7 || Aktivierung: §e{0}s §7(§e{1}t§7)
LOADTIMER_SUMARY_TIMES_IGNITION = §7 || Zündung: §e{0}s §7(§e{1}t§7)
LOADTIMER_SUMARY_TIMES_EXPLOSION = §7 || Explosion: §e{0}s §7(§e{1}t§7)
LOADTIMER_SUMARY_TIMES_LAST = §7\\/
LOADTIMER_SUMARY_STATS_HEAD = §7Kanonen-Stats§8:
LOADTIMER_SUMARY_STATS_TNT = §7TNT: §e{0}
LOADTIMER_SUMARY_STATS_FREQ = §7Belade Frequenz: §e{0}/m§8, §7Schuss Frequenz: §e{1}/m
# Other
OTHER_ITEMS_TELEPORT_GUI-NAME=Teleportieren
OTHER_ITEMS_TELEPORT_PLAYER-OFFLINE=§cDer Spieler ist Offline
OTHER_ITEMS_TELEPORT_GUI-NAME = Teleportieren
OTHER_ITEMS_TELEPORT_PLAYER-OFFLINE = §cDer Spieler ist Offline
# Material
MATERIAL_BLAST-RESISTANCE = §8- §eBlast Resistance§8: §7{0}
MATERIAL_TNT_BREAKABLE = §8- §eZerstörbar durch TNT
MATERIAL_TNT_UNBREAKABLE = §8- §eNicht Zerstörbar durch TNT
MATERIAL_TRANSPARENT = §8- §eTransparenter Block
MATERIAL_SOLID = §8- §eSolider Block
MATERIAL_GRAVITY = §8- §eFallender Block
MATERIAL_OCCLUDING = §8- §eOccluding Block
MATERIAL_INTERACT-ABLE = §8- §eInterargierbarer Block
MATERIAL_FLAMMABLE = §8- §eFlammbarer Block

Datei anzeigen

@ -70,8 +70,12 @@ public class BauGUICommand extends SWCommand {
@Register("import")
public void importGui(Player p, String code) {
if (BauGuiImportExport.importGui(code, p)) {
BauSystem.MESSAGE.send("GUI_IMPORT_CODE-SUCCESSFUL", p);
try {
if (BauGuiImportExport.importGui(code, p)) {
BauSystem.MESSAGE.send("GUI_IMPORT_CODE-SUCCESSFUL", p);
}
} catch (Exception e) {
BauSystem.MESSAGE.send("GUI_IMPORT_INVALID-CODE", p);
}
}
}

Datei anzeigen

@ -20,67 +20,99 @@
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.stream.Collectors;
@UtilityClass
public class BauGuiImportExport {
public static String exportGui(BauGuiMapping mapping) {
private static final String VERSION = "00000";
byte[] bytes = new byte[(mapping.getMapping().size() * 2) + 1];
Map<Integer, Integer> map = mapping.getMapping();
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
int head = 0;
for (Map.Entry<Integer, Integer> e : map.entrySet()) {
bytes[head] = e.getKey().byteValue();
head++;
bytes[head] = e.getValue().byteValue();
head++;
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];
}
System.out.println(st.toString());
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()));
}
bytes[head] = (byte) mapping.getSize();
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);
while (current.length() % 4 != 0) {
current.insert(0, '0');
}
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);
if (bytes.length % 2 != 1 || bytes.length < 2) {
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;
}
final int size = bytes[bytes.length - 1];
if (size > 9 * 5) {
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;
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++;
st.delete(0, 8);
System.out.println(st.toString());
// BauGUI.getITEMS().containsKey()
// TODO: Implement this @yoyo
if (map.containsKey((int) key) || map.containsValue((int) value) ||
value >= size || key > itemSize) {
BauSystem.MESSAGE.send("GUI_IMPORT_INVALID-CODE", p);
return false;
}
map.put((int) key, (int) value);
} while (head + 2 < bytes.length);
BauGuiMapping mapping = BauGuiMapping.getGuiMapping(p);
mapping.setMapping(map);
mapping.setSize(size);
mapping.save();
return true;
}
}

Datei anzeigen

@ -0,0 +1,78 @@
/*
* 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.util;
import de.steamwar.bausystem.BauSystem;
import de.steamwar.bausystem.linkage.LinkageType;
import de.steamwar.bausystem.linkage.Linked;
import de.steamwar.command.SWCommand;
import de.steamwar.inventory.SWItem;
import de.steamwar.inventory.SWListInv;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import java.util.ArrayList;
import java.util.List;
@Linked(LinkageType.COMMAND)
public class MaterialCommand extends SWCommand {
public MaterialCommand() {
super("material");
}
@Register
public void materialGUI(Player p) {
List<SWListInv.SWListEntry<Material>> swListEntries = new ArrayList<>();
for (Material value : Material.values()) {
if (!value.isBlock()) {
continue;
}
if (value.isLegacy()) {
continue;
}
List<String> lore = new ArrayList<>();
lore.add(BauSystem.MESSAGE.parse("MATERIAL_BLAST-RESISTANCE", p, value.getBlastResistance()));
lore.add(BauSystem.MESSAGE.parse(value.getBlastResistance() > 9 ? "MATERIAL_TNT_UNBREAKABLE" : "MATERIAL_TNT_BREAKABLE", p));
if (value.isTransparent()) {
lore.add(BauSystem.MESSAGE.parse("MATERIAL_TRANSPARENT", p));
}
if (value.isSolid()) {
lore.add(BauSystem.MESSAGE.parse("MATERIAL_SOLID", p));
}
if (value.hasGravity()) {
lore.add(BauSystem.MESSAGE.parse("MATERIAL_GRAVITY", p));
}
if (value.isOccluding()) {
lore.add(BauSystem.MESSAGE.parse("MATERIAL_OCCLUDING", p));
}
if (value.isInteractable()) {
lore.add(BauSystem.MESSAGE.parse("MATERIAL_INTERACT-ABLE", p));
}
if (value.isFlammable()) {
lore.add(BauSystem.MESSAGE.parse("MATERIAL_FLAMMABLE", p));
}
SWItem swItem = new SWItem(value.isItem() ? value : Material.GHAST_TEAR, "§e" + value.name(), lore, false, clickType -> {});
swListEntries.add(new SWListInv.SWListEntry<>(swItem, value));
}
SWListInv<Material> materialSWListInv = new SWListInv<>(p, "Material", false, swListEntries, (clickType, material) -> {});
materialSWListInv.open();
}
}