forked from SteamWar/SteamWar
Add BauSystem module
Fix ci java version Fix LinkageProcessor
This commit is contained in:
@@ -0,0 +1,93 @@
|
||||
/*
|
||||
* 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 de.steamwar.core.Core;
|
||||
import lombok.experimental.UtilityClass;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import yapion.hierarchy.types.YAPIONArray;
|
||||
import yapion.hierarchy.types.YAPIONObject;
|
||||
import yapion.hierarchy.types.YAPIONValue;
|
||||
import yapion.parser.YAPIONParser;
|
||||
import yapion.serializing.YAPIONDeserializer;
|
||||
import yapion.serializing.YAPIONSerializer;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
@UtilityClass
|
||||
public class DefaultHotbar {
|
||||
|
||||
private final YAPIONArray DEFAULT_HOTBAR = YAPIONParser.parse("{[{@type(org.bukkit.inventory.ItemStack)v(2230)type(WOODEN_AXE)meta{@type(org.bukkit.inventory.meta.ItemMeta)meta-type(UNSPECIFIC)display-name(WorldEdit Wand)lore{@type(java.util.ArrayList)values[Left click: select pos #1,Right click: select pos #2]}}},{@type(org.bukkit.inventory.ItemStack)v(2230)type(COMPASS)meta{@type(org.bukkit.inventory.meta.ItemMeta)meta-type(UNSPECIFIC)display-name(Navigation Wand)lore{@type(java.util.ArrayList)values[Left click: jump to location,Right click: pass through walls]}}},null,null,null,null,null,null,{@type(org.bukkit.inventory.ItemStack)v(2230)type(NETHER_STAR)meta{@type(org.bukkit.inventory.meta.ItemMeta)meta-type(UNSPECIFIC)display-name(§eBau GUI)}},null,null,{@type(org.bukkit.inventory.ItemStack)v(3117)type(ELYTRA)},null]}").getArray("");
|
||||
|
||||
public void updateHotbar(Player p) {
|
||||
ItemStack[] hotbar = new ItemStack[13];
|
||||
System.arraycopy(p.getInventory().getContents(), 0, hotbar, 0, 9);
|
||||
System.arraycopy(p.getInventory().getArmorContents(), 0, hotbar, 9, 4);
|
||||
YAPIONArray yapionArray = new YAPIONArray();
|
||||
for (ItemStack itemStack : hotbar) {
|
||||
if (itemStack != null) {
|
||||
yapionArray.add(YAPIONSerializer.serialize(itemStack));
|
||||
} else {
|
||||
yapionArray.add(new YAPIONValue<>(null));
|
||||
}
|
||||
}
|
||||
Config.getInstance().get(p).add("hotbar-" + Core.getVersion(), yapionArray);
|
||||
Config.getInstance().save(p);
|
||||
}
|
||||
|
||||
public void setHotbar(Player p) {
|
||||
ItemStack[] hotbar = getItems(p);
|
||||
ItemStack[] inv = p.getInventory().getContents();
|
||||
ItemStack[] armor = p.getInventory().getArmorContents();
|
||||
System.arraycopy(hotbar, 0, inv, 0, 9);
|
||||
System.arraycopy(hotbar, 9, armor, 0, 4);
|
||||
p.getInventory().setContents(inv);
|
||||
p.getInventory().setArmorContents(armor);
|
||||
}
|
||||
|
||||
public ItemStack[] getItems(Player p) {
|
||||
Config.getInstance().get(p).remap("hotbar", "hotbar-19");
|
||||
YAPIONArray yapionArray = Config.getInstance().get(p).getYAPIONArrayOrSetDefault("hotbar-" + Core.getVersion(), defaultHotbar());
|
||||
ItemStack[] hotbar = new ItemStack[13];
|
||||
Set<Integer> invalid = new HashSet<>();
|
||||
yapionArray.forEach((integer, yapionAnyType) -> {
|
||||
if (yapionAnyType instanceof YAPIONValue) {
|
||||
hotbar[integer] = null;
|
||||
} else {
|
||||
try {
|
||||
hotbar[integer] = YAPIONDeserializer.deserialize((YAPIONObject) yapionAnyType);
|
||||
} catch (Exception e) {
|
||||
invalid.add(integer);
|
||||
hotbar[integer] = null;
|
||||
}
|
||||
}
|
||||
});
|
||||
invalid.forEach(i -> yapionArray.set(i, new YAPIONValue<>(null)));
|
||||
if (!invalid.isEmpty()) Config.getInstance().save(p);
|
||||
return hotbar;
|
||||
}
|
||||
|
||||
public YAPIONArray defaultHotbar() {
|
||||
return DEFAULT_HOTBAR;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
/*
|
||||
* 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.command.SWCommand;
|
||||
import de.steamwar.inventory.SWInventory;
|
||||
import de.steamwar.linkage.Linked;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
@Linked
|
||||
public class HotbarCommand extends SWCommand {
|
||||
|
||||
public HotbarCommand() {
|
||||
super("hotbar", "hb");
|
||||
addDefaultHelpMessage("HOTBAR_HELP_GENERIC");
|
||||
}
|
||||
|
||||
@Register(value = "load", description = "HOTBAR_HELP_LOAD")
|
||||
public void loadHotbar(@Validator Player p) {
|
||||
DefaultHotbar.setHotbar(p);
|
||||
BauSystem.MESSAGE.send("HOTBAR_LOADED", p);
|
||||
}
|
||||
|
||||
@Register(value = "save", description = "HOTBAR_HELP_SAVE")
|
||||
public void saveHotbar(Player p) {
|
||||
DefaultHotbar.updateHotbar(p);
|
||||
BauSystem.MESSAGE.send("HOTBAR_SAVED", p);
|
||||
}
|
||||
|
||||
@Register(value = "show", description = "HOTBAR_HELP_SHOW")
|
||||
public void showHotbar(Player p) {
|
||||
SWInventory inv = new SWInventory(p, 18, 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();
|
||||
}
|
||||
}
|
||||
+48
@@ -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.Permission;
|
||||
import de.steamwar.linkage.Linked;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
|
||||
@Linked
|
||||
public class HotbarListener implements Listener {
|
||||
|
||||
@EventHandler(priority = EventPriority.LOWEST)
|
||||
public void onPlayerJoin(PlayerJoinEvent event) {
|
||||
if(!Permission.BUILD.hasPermission(event.getPlayer())) return;
|
||||
if (allNull(event.getPlayer().getInventory().getContents()) && allNull(event.getPlayer().getInventory().getArmorContents())) {
|
||||
DefaultHotbar.setHotbar(event.getPlayer());
|
||||
}
|
||||
}
|
||||
|
||||
private boolean allNull(Object[] arr) {
|
||||
for (Object o : arr) {
|
||||
if (o != null) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user