Add Hotbar Save Space in Config
Signed-off-by: Chaoscaot <chaoscaot444@gmail.com>
Dieser Commit ist enthalten in:
Ursprung
b515ba31eb
Commit
133a0a5a65
@ -118,7 +118,6 @@ BAU-INFO_COMMAND_HELP = §8/§ebauinfo §8- §7Gibt Informationen über den Bau
|
||||
BAU-INFO_COMMAND_OWNER = §7Besitzer: §e{0}
|
||||
BAU-INFO_COMMAND_MEMBER=§7Mitglieder: §e{0}
|
||||
BAU-INFO_COMMAND_FLAG=§e{0} §8: §7{1}
|
||||
|
||||
# Countingwand
|
||||
COUNTINGWAND_ITEM_NAME=§eZollstock
|
||||
COUNTINGWAND_ITEM_LORE1=§eLinksklick §8- §7Setzt die 1. Position
|
||||
@ -126,14 +125,16 @@ COUNTINGWAND_ITEM_LORE2 = §eRechtsklick §8- §7Setzt die 2. Position
|
||||
COUNTINGWAND_MESSAGE_R-CLICK=§7Erste Position bei: §8[§7{0}§8, §7{1}§8, §7{2}§8] ({3})
|
||||
COUNTINGWAND_MESSAGE_L-CLICK=§7Zweite Position bei: §8[§7{0}§8, §7{1}§8, §7{2}§8] ({3})
|
||||
COUNTINGWAND_MESSAGE_DIMENSION=§e{0}§8, §e{1}§8, §e{2}
|
||||
|
||||
# Hotbar
|
||||
HOTBAR_SAVED=§7Deine Hotbar wurde als Standard gespeichert
|
||||
HOTBAR_LOADED=§7Deine Standard Hotbar wurde geladen
|
||||
HOTBAR_INVENTORY=Standard Hotbar
|
||||
# GUI
|
||||
GUI_EDITOR_ITEM-NAME=§eGui Editor
|
||||
GUI_EXPORT_CODE=§eDein Gui-Code:
|
||||
GUI_EXPORT_CODE-HOVER=§eKopieren
|
||||
GUI_IMPORT_INVALID-CODE=§eInvalieder Gui-Code
|
||||
GUI_IMPORT_CODE-SUCCESSFUL=§eGui-Code eingelesen
|
||||
|
||||
# Trace
|
||||
TRACE_RECORD=§aan
|
||||
TRACE_RECORD-AUTO = §an
|
||||
|
@ -1,5 +1,25 @@
|
||||
/*
|
||||
* 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.configplayer;
|
||||
|
||||
import de.steamwar.bausystem.configplayer.serializer.ConfigurationSerializableSerializer;
|
||||
import de.steamwar.bausystem.linkage.LinkageType;
|
||||
import de.steamwar.bausystem.linkage.Linked;
|
||||
import de.steamwar.sql.UserConfig;
|
||||
@ -13,6 +33,7 @@ import org.bukkit.event.player.PlayerQuitEvent;
|
||||
import yapion.hierarchy.output.StringOutput;
|
||||
import yapion.hierarchy.types.YAPIONObject;
|
||||
import yapion.parser.YAPIONParser;
|
||||
import yapion.serializing.SerializeManager;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
@ -22,6 +43,10 @@ import java.util.logging.Level;
|
||||
@Linked(LinkageType.LISTENER)
|
||||
public class Config implements Listener {
|
||||
|
||||
static {
|
||||
SerializeManager.add(new ConfigurationSerializableSerializer());
|
||||
}
|
||||
|
||||
@Getter
|
||||
private static Config instance;
|
||||
|
||||
|
@ -19,6 +19,7 @@
|
||||
|
||||
package de.steamwar.bausystem.configplayer;
|
||||
|
||||
import de.steamwar.bausystem.features.hotbar.DefaultHotbar;
|
||||
import lombok.experimental.UtilityClass;
|
||||
import yapion.hierarchy.types.YAPIONObject;
|
||||
|
||||
@ -34,6 +35,9 @@ public class ConfigCreator {
|
||||
|
||||
// Any initialising goes into here
|
||||
yapionObject.add("baugui", defaultBauGui());
|
||||
|
||||
// Default Hotbar Gui
|
||||
yapionObject.add("hotbar", DefaultHotbar.defaultHotbar());
|
||||
return yapionObject;
|
||||
}
|
||||
|
||||
@ -54,5 +58,4 @@ public class ConfigCreator {
|
||||
yapionObject.add("size", 45);
|
||||
return yapionObject;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,66 @@
|
||||
/*
|
||||
* 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.configplayer.serializer;
|
||||
|
||||
import org.bukkit.configuration.serialization.ConfigurationSerializable;
|
||||
import org.bukkit.configuration.serialization.ConfigurationSerialization;
|
||||
import yapion.hierarchy.types.YAPIONObject;
|
||||
import yapion.serializing.api.SerializerObject;
|
||||
import yapion.serializing.data.DeserializeData;
|
||||
import yapion.serializing.data.SerializeData;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import static yapion.utils.IdentifierUtils.TYPE_IDENTIFIER;
|
||||
|
||||
public class ConfigurationSerializableSerializer extends SerializerObject<ConfigurationSerializable> {
|
||||
|
||||
@Override
|
||||
public Class<ConfigurationSerializable> type() {
|
||||
return ConfigurationSerializable.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isInterface() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public YAPIONObject serialize(SerializeData<ConfigurationSerializable> serializeData) {
|
||||
YAPIONObject yapionObject = new YAPIONObject();
|
||||
yapionObject.add(TYPE_IDENTIFIER, type().getTypeName());
|
||||
Map<String, Object> serializeDataMap = serializeData.object.serialize();
|
||||
serializeDataMap.forEach((s, o) -> {
|
||||
yapionObject.add(s, serializeData.serialize(o));
|
||||
});
|
||||
return yapionObject;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ConfigurationSerializable deserialize(DeserializeData<YAPIONObject> deserializeData) {
|
||||
Map<String, Object> deserializeDataMap = new HashMap<>();
|
||||
deserializeData.object.forEach((s, yapionAnyType) -> {
|
||||
if (s.equals(TYPE_IDENTIFIER)) return;
|
||||
deserializeDataMap.put(s, deserializeData.deserialize(yapionAnyType));
|
||||
});
|
||||
return ConfigurationSerialization.deserializeObject(deserializeDataMap);
|
||||
}
|
||||
}
|
@ -0,0 +1,90 @@
|
||||
/*
|
||||
* 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.hotbar;
|
||||
|
||||
import de.steamwar.bausystem.configplayer.Config;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.io.StringReader;
|
||||
|
||||
// TODO: 16.05.2021 @Yoyo muss mal was Fixen, dann Item Save auf Yapion umstellen
|
||||
public class DefaultHotbar {
|
||||
|
||||
public static void updateHotbar(Player p) {
|
||||
ItemStack[] hotbar = new ItemStack[9];
|
||||
System.arraycopy(p.getInventory().getContents(), 0, hotbar, 0, 9);
|
||||
YamlConfiguration configuration = new YamlConfiguration();
|
||||
configuration.set("Items", hotbar);
|
||||
Config.getInstance().get(p).add("hotbar", configuration.saveToString());
|
||||
Config.getInstance().save(p);
|
||||
}
|
||||
|
||||
public static void setHotbar(Player p) {
|
||||
ItemStack[] hotbar = getItems(p);
|
||||
ItemStack[] inv = p.getInventory().getContents();
|
||||
System.arraycopy(hotbar, 0, inv, 0, 9);
|
||||
p.getInventory().setContents(inv);
|
||||
}
|
||||
|
||||
public static ItemStack[] getItems(Player p) {
|
||||
YamlConfiguration hb = YamlConfiguration.loadConfiguration(new StringReader(Config.getInstance().get(p).getPlainValueOrDefault("hotbar", defaultHotbar())));
|
||||
ItemStack[] hotbar = hb.getList("Items").toArray(new ItemStack[9]);
|
||||
return hotbar;
|
||||
}
|
||||
|
||||
public static String defaultHotbar() {
|
||||
return "Items:\n" +
|
||||
"- ==: org.bukkit.inventory.ItemStack\n" +
|
||||
" v: 2230\n" +
|
||||
" type: WOODEN_AXE\n" +
|
||||
" meta:\n" +
|
||||
" ==: ItemMeta\n" +
|
||||
" meta-type: UNSPECIFIC\n" +
|
||||
" display-name: WorldEdit Wand\n" +
|
||||
" lore:\n" +
|
||||
" - 'Left click: select pos #1'\n" +
|
||||
" - 'Right click: select pos #2'\n" +
|
||||
"- ==: org.bukkit.inventory.ItemStack\n" +
|
||||
" v: 2230\n" +
|
||||
" type: COMPASS\n" +
|
||||
" meta:\n" +
|
||||
" ==: ItemMeta\n" +
|
||||
" meta-type: UNSPECIFIC\n" +
|
||||
" display-name: Navigation Wand\n" +
|
||||
" lore:\n" +
|
||||
" - 'Left click: jump to location'\n" +
|
||||
" - 'Right click: pass through walls'\n" +
|
||||
"- null\n" +
|
||||
"- null\n" +
|
||||
"- null\n" +
|
||||
"- null\n" +
|
||||
"- null\n" +
|
||||
"- null\n" +
|
||||
"- ==: org.bukkit.inventory.ItemStack\n" +
|
||||
" v: 2230\n" +
|
||||
" type: NETHER_STAR\n" +
|
||||
" meta:\n" +
|
||||
" ==: ItemMeta\n" +
|
||||
" meta-type: UNSPECIFIC\n" +
|
||||
" display-name: §eBau GUI\n";
|
||||
}
|
||||
}
|
@ -0,0 +1,70 @@
|
||||
/*
|
||||
* 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.hotbar;
|
||||
|
||||
import de.steamwar.bausystem.BauSystem;
|
||||
import de.steamwar.bausystem.config.ColorConfig;
|
||||
import de.steamwar.bausystem.linkage.LinkageType;
|
||||
import de.steamwar.bausystem.linkage.Linked;
|
||||
import de.steamwar.command.SWCommand;
|
||||
import de.steamwar.inventory.SWInventory;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
@Linked(LinkageType.COMMAND)
|
||||
public class HotbarCommand extends SWCommand {
|
||||
|
||||
protected HotbarCommand() {
|
||||
super("hotbar", "hb");
|
||||
}
|
||||
|
||||
@Register(help = true)
|
||||
public void genericHelp(Player p, String... args) {
|
||||
p.sendMessage(ColorConfig.BASE + "---=== (" + ColorConfig.HIGHLIGHT + "Hotbar" + ColorConfig.BASE + ") ===---");
|
||||
p.sendMessage(ColorConfig.BASE + "Speichert eine Hotbar. Diese wird beim Joinen eines Bauserver, wo du ein Leeres Inventar hast geladen.");
|
||||
p.sendMessage(ColorConfig.OTHER + "/" + ColorConfig.HIGHLIGHT + "hotbar save" + ColorConfig.OTHER + " - " + ColorConfig.BASE + "Speicher deine Aktuelle Hotbar");
|
||||
p.sendMessage(ColorConfig.OTHER + "/" + ColorConfig.HIGHLIGHT + "hotbar load" + ColorConfig.OTHER + " - " + ColorConfig.BASE + "Lade deine Standard Hotbar");
|
||||
p.sendMessage(ColorConfig.OTHER + "/" + ColorConfig.HIGHLIGHT + "hotbar show" + ColorConfig.OTHER + " - " + ColorConfig.BASE + "Zeigt dir deine Standard Hotbar");
|
||||
}
|
||||
|
||||
@Register("load")
|
||||
public void loadHotbar(Player p) {
|
||||
DefaultHotbar.setHotbar(p);
|
||||
BauSystem.MESSAGE.send("HOTBAR_SAVED", p);
|
||||
}
|
||||
|
||||
@Register("save")
|
||||
public void saveHotbar(Player p) {
|
||||
DefaultHotbar.updateHotbar(p);
|
||||
BauSystem.MESSAGE.send("HOTBAR_LOADED", p);
|
||||
}
|
||||
|
||||
@Register("show")
|
||||
public void showHotbar(Player p) {
|
||||
SWInventory inv = new SWInventory(p, 9, BauSystem.MESSAGE.parse("HOTBAR_INVENTORY", p));
|
||||
ItemStack[] hotbar = DefaultHotbar.getItems(p);
|
||||
for (int i = 0; i < hotbar.length; i++) {
|
||||
if (hotbar[i] == null) continue;
|
||||
inv.setItem(i, hotbar[i], clickType -> {
|
||||
});
|
||||
}
|
||||
inv.open();
|
||||
}
|
||||
}
|
@ -0,0 +1,48 @@
|
||||
/*
|
||||
* 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.hotbar;
|
||||
|
||||
import de.steamwar.bausystem.linkage.LinkageType;
|
||||
import de.steamwar.bausystem.linkage.Linked;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
|
||||
@Linked(LinkageType.LISTENER)
|
||||
public class HotbarListener implements Listener {
|
||||
|
||||
@EventHandler(priority = EventPriority.LOWEST)
|
||||
public void onPlayerJoin(PlayerJoinEvent event) {
|
||||
System.out.println(event.getPlayer().getInventory().getContents());
|
||||
if (allNull(event.getPlayer().getInventory().getContents())) {
|
||||
DefaultHotbar.setHotbar(event.getPlayer());
|
||||
}
|
||||
}
|
||||
|
||||
private boolean allNull(Object[] arr) {
|
||||
for (Object o : arr) {
|
||||
if (o != null) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
In neuem Issue referenzieren
Einen Benutzer sperren