SteamWar/BauSystem2.0
Archiviert
12
0
Signed-off-by: Chaoscaot <chaoscaot444@gmail.com>
Dieser Commit ist enthalten in:
Chaoscaot 2021-04-20 09:14:44 +02:00
Ursprung da392a5d9c
Commit 84f05e4f68
3 geänderte Dateien mit 107 neuen und 2 gelöschten Zeilen

Datei anzeigen

@ -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.gui;
import de.steamwar.bausystem.linkage.GuiItem;
import de.steamwar.inventory.SWInventory;
import lombok.experimental.UtilityClass;
import org.bukkit.entity.Player;
import java.util.HashSet;
import java.util.Set;
@UtilityClass
public class BauGUI {
private static final Set<GuiItem> ITEMS = new HashSet<>();
private static final Set<Player> OPEN_INVS = new HashSet<>();
private static boolean updating = false;
public static void addItem(GuiItem item) {
ITEMS.add(item);
}
public static void openBauGui(Player p) {
if (!updating) {
OPEN_INVS.add(p);
}
SWInventory inv = new SWInventory(p, 5 * 9, "Bau GUI");
ITEMS.forEach(item -> inv.setItem(item.getSlot(), item.getItem(p), item::click));
inv.addCloseCallback(clickType -> {
if (!updating) {
OPEN_INVS.remove(p);
}
});
}
public static void update() {
updating = true;
OPEN_INVS.forEach(BauGUI::openBauGui);
updating = false;
}
}

Datei anzeigen

@ -0,0 +1,42 @@
/*
* 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.linkage;
import de.steamwar.bausystem.features.gui.BauGUI;
import lombok.AllArgsConstructor;
import lombok.Getter;
import org.bukkit.entity.Player;
import org.bukkit.event.inventory.ClickType;
import org.bukkit.inventory.ItemStack;
@AllArgsConstructor
public abstract class GuiItem {
@Getter
private final int slot;
public abstract ItemStack getItem(Player player);
public abstract boolean click(ClickType click);
public void update() {
BauGUI.update();
}
}

Datei anzeigen

@ -20,6 +20,7 @@
package de.steamwar.bausystem.linkage;
import de.steamwar.bausystem.BauSystem;
import de.steamwar.bausystem.features.gui.BauGUI;
import de.steamwar.command.SWCommand;
import lombok.AllArgsConstructor;
import lombok.Getter;
@ -40,7 +41,8 @@ public enum LinkageType {
DISABLE_LINK(0, true, Disable.class::isAssignableFrom, o -> ((Disable) o).disable()),
PLAIN(1, false, clazz -> true),
LISTENER(2, false, Listener.class::isAssignableFrom, o -> Bukkit.getPluginManager().registerEvents((Listener) o, BauSystem.getInstance())),
UNLINK_LISTENER(2, true, Listener.class::isAssignableFrom, o -> HandlerList.unregisterAll((Listener) o));
UNLINK_LISTENER(2, true, Listener.class::isAssignableFrom, o -> HandlerList.unregisterAll((Listener) o)),
GUIITEM(3, false, GuiItem.class::isAssignableFrom, o -> BauGUI.addItem((GuiItem) o));
private final int order;
@ -49,5 +51,6 @@ public enum LinkageType {
private final Predicate<Class<?>> linkagePredicate;
@SuppressWarnings("FieldMayBeFinal")
private Consumer<Object> linkageConsumer = o -> {};
private Consumer<Object> linkageConsumer = o -> {
};
}