mirror of
https://github.com/darksaid98/Builders-Utilities.git
synced 2026-12-03 22:15:34 +00:00
Little cleanup & setup (#4)
* Setup project * Update namespace - Relocate bstats * Some reformatting and documentation * Setup issue templates * chmod+x gradlew * Create pull request template * Apply license * Exclude XMaterial from licensing
This commit is contained in:
1 parent
f763d4c472
commit
9806a083bc
129 files changed
+5068
-1506
No files matched your search
@@ -0,0 +1,36 @@
|
||||
/*
|
||||
* ____ _ _ _ _ _ _ _ _ _ _ _
|
||||
* | _ \ (_) | | | | | | | | (_) (_) | (_)
|
||||
* | |_) |_ _ _| | __| | ___ _ __ ___ ______| | | | |_ _| |_| |_ _ ___ ___
|
||||
* | _ <| | | | | |/ _` |/ _ \ '__/ __|______| | | | __| | | | __| |/ _ \/ __|
|
||||
* | |_) | |_| | | | (_| | __/ | \__ \ | |__| | |_| | | | |_| | __/\__ \
|
||||
* |____/ \__,_|_|_|\__,_|\___|_| |___/ \____/ \__|_|_|_|\__|_|\___||___/
|
||||
*
|
||||
* Builder's Utilities is a collection of a lot of tiny features that help with building.
|
||||
* Copyright (C) 2020 Arcaniax
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU 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 General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package net.arcaniax.buildersutilities.menus;
|
||||
|
||||
import net.arcaniax.buildersutilities.menus.inv.content.InventoryContents;
|
||||
import net.arcaniax.buildersutilities.menus.inv.content.InventoryProvider;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class BannerMenuProvider implements InventoryProvider {
|
||||
@Override
|
||||
public void init(Player player, InventoryContents contents) {
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,157 @@
|
||||
/*
|
||||
* ____ _ _ _ _ _ _ _ _ _ _ _
|
||||
* | _ \ (_) | | | | | | | | (_) (_) | (_)
|
||||
* | |_) |_ _ _| | __| | ___ _ __ ___ ______| | | | |_ _| |_| |_ _ ___ ___
|
||||
* | _ <| | | | | |/ _` |/ _ \ '__/ __|______| | | | __| | | | __| |/ _ \/ __|
|
||||
* | |_) | |_| | | | (_| | __/ | \__ \ | |__| | |_| | | | |_| | __/\__ \
|
||||
* |____/ \__,_|_|_|\__,_|\___|_| |___/ \____/ \__|_|_|_|\__|_|\___||___/
|
||||
*
|
||||
* Builder's Utilities is a collection of a lot of tiny features that help with building.
|
||||
* Copyright (C) 2020 Arcaniax
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU 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 General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package net.arcaniax.buildersutilities.menus;
|
||||
|
||||
import net.arcaniax.buildersutilities.menus.inv.ClickableItem;
|
||||
import net.arcaniax.buildersutilities.menus.inv.content.InventoryContents;
|
||||
import net.arcaniax.buildersutilities.menus.inv.content.InventoryProvider;
|
||||
import net.arcaniax.buildersutilities.utils.Items;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.util.concurrent.ThreadLocalRandom;
|
||||
|
||||
public class ColorMenuProvider implements InventoryProvider {
|
||||
private static final float MULTIPLIER = 255f / 20f;
|
||||
private static final String LORE = "&7__&7Left click to increase__&7Right click to decrease__&7Shift click to change by 5";
|
||||
|
||||
@Override
|
||||
public void init(Player player, InventoryContents contents) {
|
||||
setRedItem(player, contents, 10);
|
||||
setRedRandomItem(player, contents);
|
||||
setGreenItem(player, contents, 10);
|
||||
setGreenRandomItem(player, contents);
|
||||
setBlueItem(player, contents, 10);
|
||||
setBlueRandomItem(player, contents);
|
||||
|
||||
setLeatherItems(player, contents);
|
||||
}
|
||||
|
||||
private void setLeatherItems(Player player, InventoryContents contents) {
|
||||
int r;
|
||||
if (contents.get(3, 4).get().getItem().getType().equals(Material.RED_STAINED_GLASS)) {
|
||||
r = 0;
|
||||
} else {
|
||||
r = (int) (contents.get(3, 4).get().getItem().getAmount() * MULTIPLIER);
|
||||
}
|
||||
|
||||
int g;
|
||||
if (contents.get(3, 5).get().getItem().getType().equals(Material.GREEN_STAINED_GLASS)) {
|
||||
g = 0;
|
||||
} else {
|
||||
g = (int) (contents.get(3, 5).get().getItem().getAmount() * MULTIPLIER);
|
||||
}
|
||||
|
||||
int b;
|
||||
if (contents.get(3, 6).get().getItem().getType().equals(Material.BLUE_STAINED_GLASS)) {
|
||||
b = 0;
|
||||
} else {
|
||||
b = (int) (contents.get(3, 6).get().getItem().getAmount() * MULTIPLIER);
|
||||
}
|
||||
|
||||
contents.set(1, 1, ClickableItem.of(Items.color(new ItemStack(Material.LEATHER_HELMET), r, g, b),
|
||||
inventoryClickEvent -> player.getInventory().addItem(Items.color(new ItemStack(Material.LEATHER_HELMET), r, g, b))));
|
||||
contents.set(2, 1, ClickableItem.of(Items.color(new ItemStack(Material.LEATHER_CHESTPLATE), r, g, b),
|
||||
inventoryClickEvent -> player.getInventory().addItem(Items.color(new ItemStack(Material.LEATHER_CHESTPLATE), r, g, b))));
|
||||
contents.set(3, 1, ClickableItem.of(Items.color(new ItemStack(Material.LEATHER_LEGGINGS), r, g, b),
|
||||
inventoryClickEvent -> player.getInventory().addItem(Items.color(new ItemStack(Material.LEATHER_LEGGINGS), r, g, b))));
|
||||
contents.set(4, 1, ClickableItem.of(Items.color(new ItemStack(Material.LEATHER_BOOTS), r, g, b),
|
||||
inventoryClickEvent -> player.getInventory().addItem(Items.color(new ItemStack(Material.LEATHER_BOOTS), r, g, b))));
|
||||
}
|
||||
|
||||
private void setRedItem(Player player, InventoryContents contents, int amount) {
|
||||
contents.set(3, 4, ClickableItem.of(
|
||||
amount == 0 ? Items.create(Material.RED_STAINED_GLASS, "&cRed", LORE) :
|
||||
Items.createHead("eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvM2Y0NmMzMWQ2ZWU2ZWE2MTlmNzJlNzg1MjMyY2IwNDhhYjI3MDQ2MmRiMGNiMTQ1NDUxNDQzNjI1MWMxYSJ9fX0=",
|
||||
amount, "&cRed", LORE), inventoryClickEvent -> {
|
||||
if (inventoryClickEvent.isShiftClick()) {
|
||||
setRedItem(player, contents,
|
||||
inventoryClickEvent.isLeftClick() ? Math.min(amount + 5, 20) : Math.max(amount - 5, 0));
|
||||
} else {
|
||||
setRedItem(player, contents,
|
||||
inventoryClickEvent.isLeftClick() ? Math.min(amount + 1, 20) : Math.max(amount - 1, 0));
|
||||
}
|
||||
setLeatherItems(player, contents);
|
||||
}));
|
||||
}
|
||||
|
||||
private void setRedRandomItem(Player player, InventoryContents contents) {
|
||||
contents.set(2, 4, ClickableItem.of(Items.createHead("eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvNTEzMWRlOGU5NTFmZGQ3YjlhM2QyMzlkN2NjM2FhM2U4NjU1YTMzNmI5OTliOWVkYmI0ZmIzMjljYmQ4NyJ9fX0=",
|
||||
1, "&cClick to randomize", ""), inventoryClickEvent -> {
|
||||
setRedItem(player, contents, ThreadLocalRandom.current().nextInt(0, 21));
|
||||
setLeatherItems(player, contents);
|
||||
}));
|
||||
}
|
||||
|
||||
private void setGreenItem(Player player, InventoryContents contents, int amount) {
|
||||
contents.set(3, 5, ClickableItem.of(
|
||||
amount == 0 ? Items.create(Material.GREEN_STAINED_GLASS, "&aGreen", LORE) :
|
||||
Items.createHead("eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvMzZmNjlmN2I3NTM4YjQxZGMzNDM5ZjM2NThhYmJkNTlmYWNjYTM2NmYxOTBiY2YxZDZkMGEwMjZjOGY5NiJ9fX0=",
|
||||
amount, "&aGreen", LORE), inventoryClickEvent -> {
|
||||
if (inventoryClickEvent.isShiftClick()) {
|
||||
setGreenItem(player, contents,
|
||||
inventoryClickEvent.isLeftClick() ? Math.min(amount + 5, 20) : Math.max(amount - 5, 0));
|
||||
} else {
|
||||
setGreenItem(player, contents,
|
||||
inventoryClickEvent.isLeftClick() ? Math.min(amount + 1, 20) : Math.max(amount - 1, 0));
|
||||
}
|
||||
setLeatherItems(player, contents);
|
||||
}));
|
||||
}
|
||||
|
||||
private void setGreenRandomItem(Player player, InventoryContents contents) {
|
||||
contents.set(2, 5, ClickableItem.of(Items.createHead("eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvMWMzY2VjNjg3NjlmZTljOTcxMjkxZWRiN2VmOTZhNGUzYjYwNDYyY2ZkNWZiNWJhYTFjYmIzYTcxNTEzZTdiIn19fQ==",
|
||||
1, "&aClick to randomize", ""), inventoryClickEvent -> {
|
||||
setGreenItem(player, contents, ThreadLocalRandom.current().nextInt(0, 21));
|
||||
setLeatherItems(player, contents);
|
||||
}));
|
||||
}
|
||||
|
||||
private void setBlueItem(Player player, InventoryContents contents, int amount) {
|
||||
contents.set(3, 6, ClickableItem.of(
|
||||
amount == 0 ? Items.create(Material.BLUE_STAINED_GLASS, "&bBlue", LORE) :
|
||||
Items.createHead("eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvYjgzOWUzODFkOWZlZGFiNmY4YjU5Mzk2YTI3NjQyMzhkY2ViMmY3ZWVhODU2ZGM2ZmM0NDc2N2RhMzgyZjEifX19",
|
||||
amount, "&bBlue", LORE), inventoryClickEvent -> {
|
||||
if (inventoryClickEvent.isShiftClick()) {
|
||||
setBlueItem(player, contents,
|
||||
inventoryClickEvent.isLeftClick() ? Math.min(amount + 5, 20) : Math.max(amount - 5, 0));
|
||||
} else {
|
||||
setBlueItem(player, contents,
|
||||
inventoryClickEvent.isLeftClick() ? Math.min(amount + 1, 20) : Math.max(amount - 1, 0));
|
||||
}
|
||||
setLeatherItems(player, contents);
|
||||
}));
|
||||
}
|
||||
|
||||
private void setBlueRandomItem(Player player, InventoryContents contents) {
|
||||
contents.set(2, 6, ClickableItem.of(Items.createHead("eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvMjMyOGYzNzhmMjhhOTg3MjIyNmY1Y2UwNGQ2ZTFkZmExMTE2MTg1ODdmNDhkZmExZmU4MmQwNDMyMTZhNWNmIn19fQ==",
|
||||
1, "&bClick to randomize", ""), inventoryClickEvent -> {
|
||||
setBlueItem(player, contents, ThreadLocalRandom.current().nextInt(0, 21));
|
||||
setLeatherItems(player, contents);
|
||||
}));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,85 @@
|
||||
/*
|
||||
* ____ _ _ _ _ _ _ _ _ _ _ _
|
||||
* | _ \ (_) | | | | | | | | (_) (_) | (_)
|
||||
* | |_) |_ _ _| | __| | ___ _ __ ___ ______| | | | |_ _| |_| |_ _ ___ ___
|
||||
* | _ <| | | | | |/ _` |/ _ \ '__/ __|______| | | | __| | | | __| |/ _ \/ __|
|
||||
* | |_) | |_| | | | (_| | __/ | \__ \ | |__| | |_| | | | |_| | __/\__ \
|
||||
* |____/ \__,_|_|_|\__,_|\___|_| |___/ \____/ \__|_|_|_|\__|_|\___||___/
|
||||
*
|
||||
* Builder's Utilities is a collection of a lot of tiny features that help with building.
|
||||
* Copyright (C) 2020 Arcaniax
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU 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 General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package net.arcaniax.buildersutilities.menus;
|
||||
|
||||
import net.arcaniax.buildersutilities.Main;
|
||||
import net.arcaniax.buildersutilities.menus.bannermenus.BannerMenuProvider;
|
||||
import net.arcaniax.buildersutilities.menus.inv.InventoryListener;
|
||||
import net.arcaniax.buildersutilities.menus.inv.SmartInventory;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.inventory.InventoryCloseEvent;
|
||||
|
||||
public class Menus {
|
||||
|
||||
private static final InventoryListener<InventoryCloseEvent> removeGhostItemsListener =
|
||||
new InventoryListener<>(InventoryCloseEvent.class, inventoryCloseEvent -> {
|
||||
Bukkit.getScheduler().runTaskLater(Main.getInstance(), () -> {
|
||||
((Player) inventoryCloseEvent.getPlayer()).updateInventory();
|
||||
}, 1L);
|
||||
});
|
||||
|
||||
public static final SmartInventory BANNER_MENU = SmartInventory.builder()
|
||||
.manager(Main.getInstance().getInventoryManager())
|
||||
.id("buildersutilsbanner")
|
||||
.provider(new BannerMenuProvider())
|
||||
.size(6, 9)
|
||||
.listener(removeGhostItemsListener)
|
||||
.title(ChatColor.BLUE + "Select a base color")
|
||||
.closeable(true)
|
||||
.build();
|
||||
|
||||
public static final SmartInventory COLOR_MENU = SmartInventory.builder()
|
||||
.manager(Main.getInstance().getInventoryManager())
|
||||
.id("buildersutilscolor")
|
||||
.provider(new ColorMenuProvider())
|
||||
.size(6, 9)
|
||||
.listener(removeGhostItemsListener)
|
||||
.title(ChatColor.BLUE + "Armor Color Creator")
|
||||
.closeable(true)
|
||||
.build();
|
||||
|
||||
public static final SmartInventory SECRET_BLOCK_MENU = SmartInventory.builder()
|
||||
.manager(Main.getInstance().getInventoryManager())
|
||||
.id("buildersutilssecretblock")
|
||||
.provider(new SecretBlockMenuProvider())
|
||||
.size(1, 9)
|
||||
.listener(removeGhostItemsListener)
|
||||
.title(ChatColor.BLUE + "Secret Blocks")
|
||||
.closeable(true)
|
||||
.build();
|
||||
|
||||
public static final SmartInventory TOGGLE_MENU = SmartInventory.builder()
|
||||
.manager(Main.getInstance().getInventoryManager())
|
||||
.id("buildersutilstoggle")
|
||||
.provider(new UtilitiesMenuProvider())
|
||||
.size(3, 9)
|
||||
.listener(removeGhostItemsListener)
|
||||
.title(ChatColor.BLUE + "Builder's Utilities")
|
||||
.closeable(true)
|
||||
.build();
|
||||
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
/*
|
||||
* ____ _ _ _ _ _ _ _ _ _ _ _
|
||||
* | _ \ (_) | | | | | | | | (_) (_) | (_)
|
||||
* | |_) |_ _ _| | __| | ___ _ __ ___ ______| | | | |_ _| |_| |_ _ ___ ___
|
||||
* | _ <| | | | | |/ _` |/ _ \ '__/ __|______| | | | __| | | | __| |/ _ \/ __|
|
||||
* | |_) | |_| | | | (_| | __/ | \__ \ | |__| | |_| | | | |_| | __/\__ \
|
||||
* |____/ \__,_|_|_|\__,_|\___|_| |___/ \____/ \__|_|_|_|\__|_|\___||___/
|
||||
*
|
||||
* Builder's Utilities is a collection of a lot of tiny features that help with building.
|
||||
* Copyright (C) 2020 Arcaniax
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU 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 General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package net.arcaniax.buildersutilities.menus;
|
||||
|
||||
import net.arcaniax.buildersutilities.Main;
|
||||
import net.arcaniax.buildersutilities.menus.inv.ClickableItem;
|
||||
import net.arcaniax.buildersutilities.menus.inv.content.InventoryContents;
|
||||
import net.arcaniax.buildersutilities.menus.inv.content.InventoryProvider;
|
||||
import net.arcaniax.buildersutilities.utils.Items;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
public class SecretBlockMenuProvider implements InventoryProvider {
|
||||
private static final ItemStack SPAWNER = Items.create(Material.SPAWNER, (short) 0, 1, ChatColor.DARK_AQUA + "Spawner Cage", "");
|
||||
private static final ItemStack BARRIER = Items.create(Material.BARRIER, (short) 0, 1, ChatColor.DARK_AQUA + "Barrier", "");
|
||||
private static final ItemStack DRAGON_EGG = Items.create(Material.DRAGON_EGG, (short) 0, 1, ChatColor.DARK_AQUA + "Dragon Egg", "");
|
||||
private static final ItemStack GRASS_PATH = Items.create(Material.GRASS_PATH, (short) 0, 1, ChatColor.DARK_AQUA + "Grass Path", "");
|
||||
|
||||
@Override
|
||||
public void init(Player player, InventoryContents contents) {
|
||||
contents.set(0, 0, ClickableItem.of(SPAWNER, inventoryClickEvent -> player.getInventory().addItem(new ItemStack(Material.SPAWNER))));
|
||||
contents.set(0, 1, ClickableItem.of(BARRIER, inventoryClickEvent -> player.getInventory().addItem(new ItemStack(Material.BARRIER))));
|
||||
contents.set(0, 2, ClickableItem.of(DRAGON_EGG, inventoryClickEvent -> player.getInventory().addItem(new ItemStack(Material.DRAGON_EGG))));
|
||||
if (Main.getInstance().getNmsManager().isAtLeastVersion(1, 9, 0)) {
|
||||
contents.set(0, 3, ClickableItem.of(GRASS_PATH, inventoryClickEvent -> player.getInventory().addItem(new ItemStack(Material.GRASS_PATH))));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,240 @@
|
||||
/*
|
||||
* ____ _ _ _ _ _ _ _ _ _ _ _
|
||||
* | _ \ (_) | | | | | | | | (_) (_) | (_)
|
||||
* | |_) |_ _ _| | __| | ___ _ __ ___ ______| | | | |_ _| |_| |_ _ ___ ___
|
||||
* | _ <| | | | | |/ _` |/ _ \ '__/ __|______| | | | __| | | | __| |/ _ \/ __|
|
||||
* | |_) | |_| | | | (_| | __/ | \__ \ | |__| | |_| | | | |_| | __/\__ \
|
||||
* |____/ \__,_|_|_|\__,_|\___|_| |___/ \____/ \__|_|_|_|\__|_|\___||___/
|
||||
*
|
||||
* Builder's Utilities is a collection of a lot of tiny features that help with building.
|
||||
* Copyright (C) 2020 Arcaniax
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU 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 General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package net.arcaniax.buildersutilities.menus;
|
||||
|
||||
import net.arcaniax.buildersutilities.NoClipManager;
|
||||
import net.arcaniax.buildersutilities.listeners.BlockBreakListener;
|
||||
import net.arcaniax.buildersutilities.listeners.IronTrapdoorListener;
|
||||
import net.arcaniax.buildersutilities.listeners.PlayerMoveListener;
|
||||
import net.arcaniax.buildersutilities.listeners.TerracottaInteractListener;
|
||||
import net.arcaniax.buildersutilities.menus.inv.ClickableItem;
|
||||
import net.arcaniax.buildersutilities.menus.inv.content.InventoryContents;
|
||||
import net.arcaniax.buildersutilities.menus.inv.content.InventoryProvider;
|
||||
import net.arcaniax.buildersutilities.utils.Items;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.potion.PotionEffect;
|
||||
import org.bukkit.potion.PotionEffectType;
|
||||
|
||||
public class UtilitiesMenuProvider implements InventoryProvider {
|
||||
private static final ItemStack ENABLED = new ItemStack(Material.GREEN_STAINED_GLASS_PANE);
|
||||
private static final ItemStack DISABLED = new ItemStack(Material.RED_STAINED_GLASS_PANE);
|
||||
private static final ItemStack NO_PERMISSION = new ItemStack(Material.ORANGE_STAINED_GLASS_PANE);
|
||||
|
||||
private static final String ENABLED_LORE = "&a&lEnabled__&7__&7Click to toggle";
|
||||
private static final String DISABLED_LORE = "&c&lDisabled__&7__&7Click to toggle";
|
||||
|
||||
@Override
|
||||
public void init(Player player, InventoryContents contents) {
|
||||
setIronTrapdoorItem(player, contents);
|
||||
setSlabItem(player, contents);
|
||||
setTerracottaItem(player, contents);
|
||||
setNightVisionItem(player, contents);
|
||||
setNoClipItem(player, contents);
|
||||
setFlyItem(player, contents);
|
||||
}
|
||||
|
||||
private void setIronTrapdoorItem(Player player, InventoryContents contents) {
|
||||
if (!player.hasPermission("builders.util.irontrapdoor")) {
|
||||
setNoPermission(1, contents);
|
||||
contents.set(1, 1, ClickableItem.empty(
|
||||
Items.create(Material.IRON_TRAPDOOR, "&6Iron Trapdoor Interaction", "&7&lNo Permission")));
|
||||
return;
|
||||
}
|
||||
|
||||
if (IronTrapdoorListener.ironTrapdoorIds.contains(player.getUniqueId())) {
|
||||
setEnabledGlassPanes(1, true, contents);
|
||||
contents.set(1, 1, ClickableItem.of(Items.create(Material.IRON_TRAPDOOR,
|
||||
"&6Iron Trapdoor Interaction", ENABLED_LORE),
|
||||
inventoryClickEvent -> {
|
||||
IronTrapdoorListener.ironTrapdoorIds.remove(player.getUniqueId());
|
||||
setIronTrapdoorItem(player, contents);
|
||||
}));
|
||||
} else {
|
||||
setEnabledGlassPanes(1, false, contents);
|
||||
contents.set(1, 1, ClickableItem.of(Items.create(Material.IRON_TRAPDOOR,
|
||||
"&6Iron Trapdoor Interaction", DISABLED_LORE),
|
||||
inventoryClickEvent -> {
|
||||
IronTrapdoorListener.ironTrapdoorIds.add(player.getUniqueId());
|
||||
setIronTrapdoorItem(player, contents);
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
private void setSlabItem(Player player, InventoryContents contents) {
|
||||
if (!player.hasPermission("builders.util.slabs")) {
|
||||
setNoPermission(2, contents);
|
||||
contents.set(1, 2, ClickableItem.empty(
|
||||
Items.create(Material.STONE_SLAB, "&6Custom Slab Breaking", "&7&lNo Permission")));
|
||||
return;
|
||||
}
|
||||
|
||||
if (BlockBreakListener.slabIds.contains(player.getUniqueId())) {
|
||||
setEnabledGlassPanes(2, true, contents);
|
||||
contents.set(1, 2, ClickableItem.of(Items.create(Material.STONE_SLAB,
|
||||
"&6Custom Slab Breaking", ENABLED_LORE),
|
||||
inventoryClickEvent -> {
|
||||
BlockBreakListener.slabIds.remove(player.getUniqueId());
|
||||
setSlabItem(player, contents);
|
||||
}));
|
||||
} else {
|
||||
setEnabledGlassPanes(2, false, contents);
|
||||
contents.set(1, 2, ClickableItem.of(Items.create(Material.STONE_SLAB,
|
||||
"&6Custom Slab Breaking", DISABLED_LORE),
|
||||
inventoryClickEvent -> {
|
||||
BlockBreakListener.slabIds.add(player.getUniqueId());
|
||||
setSlabItem(player, contents);
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
private void setTerracottaItem(Player player, InventoryContents contents) {
|
||||
if (!player.hasPermission("builders.util.terracotta")) {
|
||||
setNoPermission(3, contents);
|
||||
contents.set(1, 3, ClickableItem.empty(
|
||||
Items.create(Material.ORANGE_GLAZED_TERRACOTTA, "&6Glazed Terracotta Rotating", "&7&lNo Permission")));
|
||||
return;
|
||||
}
|
||||
|
||||
if (TerracottaInteractListener.terracottaIds.contains(player.getUniqueId())) {
|
||||
setEnabledGlassPanes(3, true, contents);
|
||||
contents.set(1, 3, ClickableItem.of(Items.create(Material.ORANGE_GLAZED_TERRACOTTA,
|
||||
"&6Glazed Terracotta Rotating", ENABLED_LORE),
|
||||
inventoryClickEvent -> {
|
||||
TerracottaInteractListener.terracottaIds.remove(player.getUniqueId());
|
||||
setTerracottaItem(player, contents);
|
||||
}));
|
||||
} else {
|
||||
setEnabledGlassPanes(3, false, contents);
|
||||
contents.set(1, 3, ClickableItem.of(Items.create(Material.ORANGE_GLAZED_TERRACOTTA,
|
||||
"&6Glazed Terracotta Rotating", DISABLED_LORE),
|
||||
inventoryClickEvent -> {
|
||||
TerracottaInteractListener.terracottaIds.add(player.getUniqueId());
|
||||
setTerracottaItem(player, contents);
|
||||
}));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void setNightVisionItem(Player player, InventoryContents contents) {
|
||||
if (!player.hasPermission("builders.util.nightvision")) {
|
||||
setNoPermission(5, contents);
|
||||
contents.set(1, 5, ClickableItem.empty(
|
||||
Items.create(Material.ENDER_EYE, "&6Night Vision", "&7&lNo Permission")));
|
||||
return;
|
||||
}
|
||||
|
||||
if (player.hasPotionEffect(PotionEffectType.NIGHT_VISION)) {
|
||||
setEnabledGlassPanes(5, true, contents);
|
||||
contents.set(1, 5, ClickableItem.of(Items.create(Material.ENDER_EYE,
|
||||
"&6Night Vision", ENABLED_LORE),
|
||||
inventoryClickEvent -> {
|
||||
player.removePotionEffect(PotionEffectType.NIGHT_VISION);
|
||||
setNightVisionItem(player, contents);
|
||||
}));
|
||||
} else {
|
||||
setEnabledGlassPanes(5, false, contents);
|
||||
contents.set(1, 5, ClickableItem.of(Items.create(Material.ENDER_EYE,
|
||||
"&6Night Vision", DISABLED_LORE),
|
||||
inventoryClickEvent -> {
|
||||
player.addPotionEffect(new PotionEffect(PotionEffectType.NIGHT_VISION, Integer.MAX_VALUE, 0, true, false));
|
||||
setNightVisionItem(player, contents);
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
private void setNoClipItem(Player player, InventoryContents contents) {
|
||||
if (!player.hasPermission("builders.util.noclip")) {
|
||||
setNoPermission(6, contents);
|
||||
contents.set(1, 6, ClickableItem.empty(
|
||||
Items.create(Material.COMPASS, "&6No Clip", "&7&lNo Permission")));
|
||||
return;
|
||||
}
|
||||
|
||||
if (NoClipManager.noClipPlayerIds.contains(player.getUniqueId())) {
|
||||
setEnabledGlassPanes(6, true, contents);
|
||||
contents.set(1, 6, ClickableItem.of(Items.create(Material.COMPASS,
|
||||
"&6No Clip", ENABLED_LORE),
|
||||
inventoryClickEvent -> {
|
||||
NoClipManager.noClipPlayerIds.remove(player.getUniqueId());
|
||||
setNoClipItem(player, contents);
|
||||
}));
|
||||
} else {
|
||||
setEnabledGlassPanes(6, false, contents);
|
||||
contents.set(1, 6, ClickableItem.of(Items.create(Material.COMPASS,
|
||||
"&6No Clip", DISABLED_LORE),
|
||||
inventoryClickEvent -> {
|
||||
NoClipManager.noClipPlayerIds.add(player.getUniqueId());
|
||||
setNoClipItem(player, contents);
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
private void setFlyItem(Player player, InventoryContents contents) {
|
||||
if (!player.hasPermission("builders.util.advancedfly")) {
|
||||
setNoPermission(7, contents);
|
||||
contents.set(1, 7, ClickableItem.empty(
|
||||
Items.create(Material.FEATHER, "&6Advanced Fly", "&7&lNo Permission")));
|
||||
return;
|
||||
}
|
||||
|
||||
if (PlayerMoveListener.enabledPlayers.contains(player.getUniqueId())) {
|
||||
setEnabledGlassPanes(7, true, contents);
|
||||
contents.set(1, 7, ClickableItem.of(Items.create(Material.FEATHER,
|
||||
"&6Advanced Fly", ENABLED_LORE),
|
||||
inventoryClickEvent -> {
|
||||
PlayerMoveListener.enabledPlayers.remove(player.getUniqueId());
|
||||
setFlyItem(player, contents);
|
||||
}));
|
||||
} else {
|
||||
setEnabledGlassPanes(7, false, contents);
|
||||
contents.set(1, 7, ClickableItem.of(Items.create(Material.FEATHER,
|
||||
"&6Advanced Fly", DISABLED_LORE),
|
||||
inventoryClickEvent -> {
|
||||
PlayerMoveListener.enabledPlayers.add(player.getUniqueId());
|
||||
setFlyItem(player, contents);
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the glass panes above and below the center row to
|
||||
* show if a feature is enabled or disabled.
|
||||
* https://i.imgur.com/ETI22Py.png
|
||||
*
|
||||
* @param col the column to set the glass panes in
|
||||
* @param enabled true if green panes, false if red panes
|
||||
*/
|
||||
private void setEnabledGlassPanes(int col, boolean enabled, InventoryContents contents) {
|
||||
contents.set(0, col, ClickableItem.empty(enabled ? ENABLED : DISABLED));
|
||||
contents.set(2, col, ClickableItem.empty(enabled ? ENABLED : DISABLED));
|
||||
}
|
||||
|
||||
private void setNoPermission(int col, InventoryContents contents) {
|
||||
contents.set(0, col, ClickableItem.empty(NO_PERMISSION));
|
||||
contents.set(2, col, ClickableItem.empty(NO_PERMISSION));
|
||||
}
|
||||
}
|
||||
+61
@@ -0,0 +1,61 @@
|
||||
/*
|
||||
* ____ _ _ _ _ _ _ _ _ _ _ _
|
||||
* | _ \ (_) | | | | | | | | (_) (_) | (_)
|
||||
* | |_) |_ _ _| | __| | ___ _ __ ___ ______| | | | |_ _| |_| |_ _ ___ ___
|
||||
* | _ <| | | | | |/ _` |/ _ \ '__/ __|______| | | | __| | | | __| |/ _ \/ __|
|
||||
* | |_) | |_| | | | (_| | __/ | \__ \ | |__| | |_| | | | |_| | __/\__ \
|
||||
* |____/ \__,_|_|_|\__,_|\___|_| |___/ \____/ \__|_|_|_|\__|_|\___||___/
|
||||
*
|
||||
* Builder's Utilities is a collection of a lot of tiny features that help with building.
|
||||
* Copyright (C) 2020 Arcaniax
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU 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 General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package net.arcaniax.buildersutilities.menus.bannermenus;
|
||||
|
||||
import net.arcaniax.buildersutilities.menus.inv.content.InventoryContents;
|
||||
import net.arcaniax.buildersutilities.menus.inv.content.InventoryProvider;
|
||||
import net.arcaniax.buildersutilities.utils.Items;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
public class BannerColorMenuProvider implements InventoryProvider {
|
||||
|
||||
private static final ItemStack grayPane = Items
|
||||
.create(Material.LIGHT_GRAY_STAINED_GLASS_PANE, (short) 0, 1, "&7", "");
|
||||
private static final ItemStack head = Items.createHead(
|
||||
"eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvNzk3OTU1NDYyZTRlNTc2NjY0NDk5YWM0YTFjNTcyZjYxNDNmMTlhZDJkNjE5NDc3NjE5OGY4ZDEzNmZkYjIifX19",
|
||||
1, "&7Click to randomise", "");
|
||||
|
||||
@Override
|
||||
public void init(Player player, InventoryContents contents) {
|
||||
// for (int x = 0; x < 54; x++) {
|
||||
// contents.set(x / 9, x % 9, grayPane);
|
||||
// }
|
||||
// inv1.setItem(1, );
|
||||
// if (first) {
|
||||
// inv1.setItem(4, bU.createBanner("&aClick to get the banner", 1, DyeColor.valueOf(clicked.getType().toString().replace("_BANNER", "")), ""));
|
||||
// } else {
|
||||
// inv1.setItem(4, bU.addPattern(inv.getItem(4), new Pattern(bU.getColorFromBanner(clicked), bU.getPatternType(clicked))));
|
||||
// }
|
||||
// inv1.setItem(7, i.create(Material.BARRIER, (short) 0, 1, "&cClick to close", ""));
|
||||
// for (int x = 19; x < 27; x++) {
|
||||
// inv1.setItem(x, i.create(Material.LEGACY_INK_SACK, (short) (x - 19), 1, "&3" + bU.getAllColors().get(x - 19).toString().toLowerCase().replace("_", " "), "&7__&7click to select"));
|
||||
// }
|
||||
// for (int x = 28; x < 36; x++) {
|
||||
// inv1.setItem(x, i.create(Material.LEGACY_INK_SACK, (short) (x - 20), 1, "&3" + bU.getAllColors().get(x - 20).toString().toLowerCase().replace("_", " "), "&7__&7click to select"));
|
||||
// }
|
||||
}
|
||||
}
|
||||
+62
@@ -0,0 +1,62 @@
|
||||
/*
|
||||
* ____ _ _ _ _ _ _ _ _ _ _ _
|
||||
* | _ \ (_) | | | | | | | | (_) (_) | (_)
|
||||
* | |_) |_ _ _| | __| | ___ _ __ ___ ______| | | | |_ _| |_| |_ _ ___ ___
|
||||
* | _ <| | | | | |/ _` |/ _ \ '__/ __|______| | | | __| | | | __| |/ _ \/ __|
|
||||
* | |_) | |_| | | | (_| | __/ | \__ \ | |__| | |_| | | | |_| | __/\__ \
|
||||
* |____/ \__,_|_|_|\__,_|\___|_| |___/ \____/ \__|_|_|_|\__|_|\___||___/
|
||||
*
|
||||
* Builder's Utilities is a collection of a lot of tiny features that help with building.
|
||||
* Copyright (C) 2020 Arcaniax
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU 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 General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package net.arcaniax.buildersutilities.menus.bannermenus;
|
||||
|
||||
import net.arcaniax.buildersutilities.menus.inv.content.InventoryContents;
|
||||
import net.arcaniax.buildersutilities.menus.inv.content.InventoryProvider;
|
||||
import net.arcaniax.buildersutilities.utils.Items;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
public class BannerMenuProvider implements InventoryProvider {
|
||||
|
||||
private static final ItemStack grayPane = Items
|
||||
.create(Material.LIGHT_GRAY_STAINED_GLASS_PANE, (short) 0, 1, "&7", "");
|
||||
private static final ItemStack randomizeHead = Items.createHead(
|
||||
"eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvNzk3OTU1NDYyZTRlNTc2NjY0NDk5YWM0YTFjNTcyZjYxNDNmMTlhZDJkNjE5NDc3NjE5OGY4ZDEzNmZkYjIifX19",
|
||||
1, "&7Click to randomise", "");
|
||||
// private static final ItemStack currentColor = BannerUtil.createBanner("&a", 1, DyeColor.WHITE, "");
|
||||
private static final ItemStack closeButton = Items
|
||||
.create(Material.BARRIER, (short) 0, 1, "&cClick to close", "");
|
||||
|
||||
@Override
|
||||
public void init(Player player, InventoryContents contents) {
|
||||
// for (int x = 0; x < 54; x++) {
|
||||
// contents.set(x / 9, x % 9, ClickableItem.empty(grayPane));
|
||||
// }
|
||||
// contents.set(0, 1, ClickableItem.of(randomizeHead, NULL));
|
||||
// contents.set(0, 4, ClickableItem.empty(currentColor));
|
||||
// contents.set(0, 7, ClickableItem.of(closeButton, inventoryClickEvent -> contents.inventory().close(player)));
|
||||
// for (int x = 19; x < 27; x++) {
|
||||
// ItemStack banner = BannerUtil.createBanner("&3" + BannerUtil.allColors.get(x - 19).toString().toLowerCase().replace("_", " "), 1, BannerUtil.allColors.get(x - 19), "&7__&7click to select");
|
||||
// contents.set(x / 9, x % 9, ClickableItem.of(banner, NULL));
|
||||
// }
|
||||
// for (int x = 28; x < 36; x++) {
|
||||
// ItemStack banner = BannerUtil.createBanner("&3" + BannerUtil.allColors.get(x - 28 + 8).toString().toLowerCase().replace("_", " "), 1, BannerUtil.allColors.get(x - 28 + 8), "&7__&7click to select");
|
||||
// contents.set(x / 9, x % 9, ClickableItem.of(banner, NULL));
|
||||
// }
|
||||
}
|
||||
}
|
||||
+62
@@ -0,0 +1,62 @@
|
||||
/*
|
||||
* ____ _ _ _ _ _ _ _ _ _ _ _
|
||||
* | _ \ (_) | | | | | | | | (_) (_) | (_)
|
||||
* | |_) |_ _ _| | __| | ___ _ __ ___ ______| | | | |_ _| |_| |_ _ ___ ___
|
||||
* | _ <| | | | | |/ _` |/ _ \ '__/ __|______| | | | __| | | | __| |/ _ \/ __|
|
||||
* | |_) | |_| | | | (_| | __/ | \__ \ | |__| | |_| | | | |_| | __/\__ \
|
||||
* |____/ \__,_|_|_|\__,_|\___|_| |___/ \____/ \__|_|_|_|\__|_|\___||___/
|
||||
*
|
||||
* Builder's Utilities is a collection of a lot of tiny features that help with building.
|
||||
* Copyright (C) 2020 Arcaniax
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU 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 General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package net.arcaniax.buildersutilities.menus.bannermenus;
|
||||
|
||||
import net.arcaniax.buildersutilities.menus.inv.content.InventoryContents;
|
||||
import net.arcaniax.buildersutilities.menus.inv.content.InventoryProvider;
|
||||
import net.arcaniax.buildersutilities.utils.Items;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
public class BannerPatternMenuProvider implements InventoryProvider {
|
||||
|
||||
private static final ItemStack grayPane = Items
|
||||
.create(Material.LIGHT_GRAY_STAINED_GLASS_PANE, (short) 0, 1, "&7", "");
|
||||
private static final ItemStack randomizeHead = Items.createHead(
|
||||
"eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvNzk3OTU1NDYyZTRlNTc2NjY0NDk5YWM0YTFjNTcyZjYxNDNmMTlhZDJkNjE5NDc3NjE5OGY4ZDEzNmZkYjIifX19",
|
||||
1, "&7Click to randomise", "");
|
||||
// private static final ItemStack currentColor = BannerUtil.createBanner("&a", 1, DyeColor.WHITE, "");
|
||||
private static final ItemStack closeButton = Items
|
||||
.create(Material.BARRIER, (short) 0, 1, "&cClick to close", "");
|
||||
|
||||
@Override
|
||||
public void init(Player player, InventoryContents contents) {
|
||||
// for (int x = 0; x < 54; x++) {
|
||||
// contents.set(x / 9, x % 9, ClickableItem.empty(grayPane));
|
||||
// }
|
||||
// contents.set(0, 1, ClickableItem.of(randomizeHead, NULL));
|
||||
// contents.set(0, 4, ClickableItem.empty(currentColor));
|
||||
// contents.set(0, 7, ClickableItem.of(closeButton, inventoryClickEvent -> contents.inventory().close(player)));
|
||||
// for (int x = 19; x < 27; x++) {
|
||||
// ItemStack banner = BannerUtil.createBanner("&3" + BannerUtil.allColors.get(x - 19).toString().toLowerCase().replace("_", " "), 1, BannerUtil.allColors.get(x - 19), "&7__&7click to select");
|
||||
// contents.set(x / 9, x % 9, ClickableItem.of(banner, NULL));
|
||||
// }
|
||||
// for (int x = 28; x < 36; x++) {
|
||||
// ItemStack banner = BannerUtil.createBanner("&3" + BannerUtil.allColors.get(x - 28 + 8).toString().toLowerCase().replace("_", " "), 1, BannerUtil.allColors.get(x - 28 + 8), "&7__&7click to select");
|
||||
// contents.set(x / 9, x % 9, ClickableItem.of(banner, NULL));
|
||||
// }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
/*
|
||||
* ____ _ _ _ _ _ _ _ _ _ _ _
|
||||
* | _ \ (_) | | | | | | | | (_) (_) | (_)
|
||||
* | |_) |_ _ _| | __| | ___ _ __ ___ ______| | | | |_ _| |_| |_ _ ___ ___
|
||||
* | _ <| | | | | |/ _` |/ _ \ '__/ __|______| | | | __| | | | __| |/ _ \/ __|
|
||||
* | |_) | |_| | | | (_| | __/ | \__ \ | |__| | |_| | | | |_| | __/\__ \
|
||||
* |____/ \__,_|_|_|\__,_|\___|_| |___/ \____/ \__|_|_|_|\__|_|\___||___/
|
||||
*
|
||||
* Builder's Utilities is a collection of a lot of tiny features that help with building.
|
||||
* Copyright (C) 2020 Arcaniax
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU 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 General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package net.arcaniax.buildersutilities.menus.inv;
|
||||
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.util.function.Consumer;
|
||||
|
||||
public class ClickableItem {
|
||||
|
||||
private final ItemStack item;
|
||||
private final Consumer<InventoryClickEvent> consumer;
|
||||
|
||||
private ClickableItem(ItemStack item, Consumer<InventoryClickEvent> consumer) {
|
||||
this.item = item;
|
||||
this.consumer = consumer;
|
||||
}
|
||||
|
||||
public static ClickableItem empty(ItemStack item) {
|
||||
return of(item, e -> {
|
||||
});
|
||||
}
|
||||
|
||||
public static ClickableItem of(ItemStack item, Consumer<InventoryClickEvent> consumer) {
|
||||
return new ClickableItem(item, consumer);
|
||||
}
|
||||
|
||||
public void run(InventoryClickEvent e) {
|
||||
consumer.accept(e);
|
||||
}
|
||||
|
||||
public ItemStack getItem() {
|
||||
return item;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
/*
|
||||
* ____ _ _ _ _ _ _ _ _ _ _ _
|
||||
* | _ \ (_) | | | | | | | | (_) (_) | (_)
|
||||
* | |_) |_ _ _| | __| | ___ _ __ ___ ______| | | | |_ _| |_| |_ _ ___ ___
|
||||
* | _ <| | | | | |/ _` |/ _ \ '__/ __|______| | | | __| | | | __| |/ _ \/ __|
|
||||
* | |_) | |_| | | | (_| | __/ | \__ \ | |__| | |_| | | | |_| | __/\__ \
|
||||
* |____/ \__,_|_|_|\__,_|\___|_| |___/ \____/ \__|_|_|_|\__|_|\___||___/
|
||||
*
|
||||
* Builder's Utilities is a collection of a lot of tiny features that help with building.
|
||||
* Copyright (C) 2020 Arcaniax
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU 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 General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package net.arcaniax.buildersutilities.menus.inv;
|
||||
|
||||
import java.util.function.Consumer;
|
||||
|
||||
public class InventoryListener<T> {
|
||||
|
||||
private final Class<T> type;
|
||||
private final Consumer<T> consumer;
|
||||
|
||||
public InventoryListener(Class<T> type, Consumer<T> consumer) {
|
||||
this.type = type;
|
||||
this.consumer = consumer;
|
||||
}
|
||||
|
||||
public void accept(T t) {
|
||||
consumer.accept(t);
|
||||
}
|
||||
|
||||
public Class<T> getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,288 @@
|
||||
/*
|
||||
* ____ _ _ _ _ _ _ _ _ _ _ _
|
||||
* | _ \ (_) | | | | | | | | (_) (_) | (_)
|
||||
* | |_) |_ _ _| | __| | ___ _ __ ___ ______| | | | |_ _| |_| |_ _ ___ ___
|
||||
* | _ <| | | | | |/ _` |/ _ \ '__/ __|______| | | | __| | | | __| |/ _ \/ __|
|
||||
* | |_) | |_| | | | (_| | __/ | \__ \ | |__| | |_| | | | |_| | __/\__ \
|
||||
* |____/ \__,_|_|_|\__,_|\___|_| |___/ \____/ \__|_|_|_|\__|_|\___||___/
|
||||
*
|
||||
* Builder's Utilities is a collection of a lot of tiny features that help with building.
|
||||
* Copyright (C) 2020 Arcaniax
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU 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 General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package net.arcaniax.buildersutilities.menus.inv;
|
||||
|
||||
import net.arcaniax.buildersutilities.menus.inv.content.InventoryContents;
|
||||
import net.arcaniax.buildersutilities.menus.inv.opener.ChestInventoryOpener;
|
||||
import net.arcaniax.buildersutilities.menus.inv.opener.InventoryOpener;
|
||||
import net.arcaniax.buildersutilities.menus.inv.opener.SpecialInventoryOpener;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.inventory.*;
|
||||
import org.bukkit.event.player.PlayerQuitEvent;
|
||||
import org.bukkit.event.server.PluginDisableEvent;
|
||||
import org.bukkit.plugin.PluginManager;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public class InventoryManager {
|
||||
|
||||
private final JavaPlugin plugin;
|
||||
private final PluginManager pluginManager;
|
||||
|
||||
private final Map<Player, SmartInventory> inventories;
|
||||
private final Map<Player, InventoryContents> contents;
|
||||
|
||||
private final List<InventoryOpener> defaultOpeners;
|
||||
private final List<InventoryOpener> openers;
|
||||
|
||||
public InventoryManager(JavaPlugin plugin) {
|
||||
this.plugin = plugin;
|
||||
this.pluginManager = Bukkit.getPluginManager();
|
||||
|
||||
this.inventories = new HashMap<>();
|
||||
this.contents = new HashMap<>();
|
||||
|
||||
this.defaultOpeners = Arrays.asList(
|
||||
new ChestInventoryOpener(),
|
||||
new SpecialInventoryOpener()
|
||||
);
|
||||
|
||||
this.openers = new ArrayList<>();
|
||||
}
|
||||
|
||||
public void init() {
|
||||
pluginManager.registerEvents(new InvListener(), plugin);
|
||||
|
||||
new InvTask().runTaskTimer(plugin, 1, 1);
|
||||
}
|
||||
|
||||
public Optional<InventoryOpener> findOpener(InventoryType type) {
|
||||
Optional<InventoryOpener> opInv = this.openers.stream()
|
||||
.filter(opener -> opener.supports(type))
|
||||
.findAny();
|
||||
|
||||
if (!opInv.isPresent()) {
|
||||
opInv = this.defaultOpeners.stream()
|
||||
.filter(opener -> opener.supports(type))
|
||||
.findAny();
|
||||
}
|
||||
|
||||
return opInv;
|
||||
}
|
||||
|
||||
public void registerOpeners(InventoryOpener... openers) {
|
||||
this.openers.addAll(Arrays.asList(openers));
|
||||
}
|
||||
|
||||
public List<Player> getOpenedPlayers(SmartInventory inv) {
|
||||
List<Player> list = new ArrayList<>();
|
||||
|
||||
this.inventories.forEach((player, playerInv) -> {
|
||||
if (inv.equals(playerInv)) {
|
||||
list.add(player);
|
||||
}
|
||||
});
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
public Optional<SmartInventory> getInventory(Player p) {
|
||||
return Optional.ofNullable(this.inventories.get(p));
|
||||
}
|
||||
|
||||
protected void setInventory(Player p, SmartInventory inv) {
|
||||
if (inv == null) {
|
||||
this.inventories.remove(p);
|
||||
} else {
|
||||
this.inventories.put(p, inv);
|
||||
}
|
||||
}
|
||||
|
||||
public Optional<InventoryContents> getContents(Player p) {
|
||||
return Optional.ofNullable(this.contents.get(p));
|
||||
}
|
||||
|
||||
protected void setContents(Player p, InventoryContents contents) {
|
||||
if (contents == null) {
|
||||
this.contents.remove(p);
|
||||
} else {
|
||||
this.contents.put(p, contents);
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
class InvListener implements Listener {
|
||||
|
||||
@EventHandler(priority = EventPriority.LOW)
|
||||
public void onInventoryClick(InventoryClickEvent e) {
|
||||
Player p = (Player) e.getWhoClicked();
|
||||
|
||||
if (!inventories.containsKey(p)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (e.getAction() == InventoryAction.MOVE_TO_OTHER_INVENTORY) {
|
||||
e.setCancelled(true);
|
||||
}
|
||||
|
||||
if (e.getAction() == InventoryAction.COLLECT_TO_CURSOR) {
|
||||
e.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
if (e.getAction() == InventoryAction.NOTHING && e.getClick() != ClickType.MIDDLE) {
|
||||
e.setCancelled(true);
|
||||
}
|
||||
|
||||
if (e.getClickedInventory() == p.getOpenInventory().getTopInventory()) {
|
||||
e.setCancelled(true);
|
||||
|
||||
int row = e.getSlot() / 9;
|
||||
int column = e.getSlot() % 9;
|
||||
|
||||
if (row < 0 || column < 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
SmartInventory inv = inventories.get(p);
|
||||
|
||||
if (row >= inv.getRows() || column >= inv.getColumns()) {
|
||||
return;
|
||||
}
|
||||
|
||||
inv.getListeners().stream()
|
||||
.filter(listener -> listener.getType() == InventoryClickEvent.class)
|
||||
.forEach(listener -> ((InventoryListener<InventoryClickEvent>) listener).accept(e));
|
||||
|
||||
contents.get(p).get(row, column).ifPresent(item -> item.run(e));
|
||||
|
||||
p.updateInventory();
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.LOW)
|
||||
public void onInventoryDrag(InventoryDragEvent e) {
|
||||
Player p = (Player) e.getWhoClicked();
|
||||
|
||||
if (!inventories.containsKey(p)) {
|
||||
return;
|
||||
}
|
||||
|
||||
SmartInventory inv = inventories.get(p);
|
||||
|
||||
for (int slot : e.getRawSlots()) {
|
||||
if (slot >= p.getOpenInventory().getTopInventory().getSize()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
e.setCancelled(true);
|
||||
break;
|
||||
}
|
||||
|
||||
inv.getListeners().stream()
|
||||
.filter(listener -> listener.getType() == InventoryDragEvent.class)
|
||||
.forEach(listener -> ((InventoryListener<InventoryDragEvent>) listener).accept(e));
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.LOW)
|
||||
public void onInventoryOpen(InventoryOpenEvent e) {
|
||||
Player p = (Player) e.getPlayer();
|
||||
|
||||
if (!inventories.containsKey(p)) {
|
||||
return;
|
||||
}
|
||||
|
||||
SmartInventory inv = inventories.get(p);
|
||||
|
||||
inv.getListeners().stream()
|
||||
.filter(listener -> listener.getType() == InventoryOpenEvent.class)
|
||||
.forEach(listener -> ((InventoryListener<InventoryOpenEvent>) listener).accept(e));
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.LOW)
|
||||
public void onInventoryClose(InventoryCloseEvent e) {
|
||||
Player p = (Player) e.getPlayer();
|
||||
|
||||
if (!inventories.containsKey(p)) {
|
||||
return;
|
||||
}
|
||||
|
||||
SmartInventory inv = inventories.get(p);
|
||||
|
||||
inv.getListeners().stream()
|
||||
.filter(listener -> listener.getType() == InventoryCloseEvent.class)
|
||||
.forEach(listener -> ((InventoryListener<InventoryCloseEvent>) listener).accept(e));
|
||||
|
||||
if (inv.isCloseable()) {
|
||||
e.getInventory().clear();
|
||||
|
||||
inventories.remove(p);
|
||||
contents.remove(p);
|
||||
} else {
|
||||
Bukkit.getScheduler().runTask(plugin, () -> p.openInventory(e.getInventory()));
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.LOW)
|
||||
public void onPlayerQuit(PlayerQuitEvent e) {
|
||||
Player p = e.getPlayer();
|
||||
|
||||
if (!inventories.containsKey(p)) {
|
||||
return;
|
||||
}
|
||||
|
||||
SmartInventory inv = inventories.get(p);
|
||||
|
||||
inv.getListeners().stream()
|
||||
.filter(listener -> listener.getType() == PlayerQuitEvent.class)
|
||||
.forEach(listener -> ((InventoryListener<PlayerQuitEvent>) listener).accept(e));
|
||||
|
||||
inventories.remove(p);
|
||||
contents.remove(p);
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.LOW)
|
||||
public void onPluginDisable(PluginDisableEvent e) {
|
||||
new HashMap<>(inventories).forEach((player, inv) -> {
|
||||
inv.getListeners().stream()
|
||||
.filter(listener -> listener.getType() == PluginDisableEvent.class)
|
||||
.forEach(listener -> ((InventoryListener<PluginDisableEvent>) listener).accept(e));
|
||||
|
||||
inv.close(player);
|
||||
});
|
||||
|
||||
inventories.clear();
|
||||
contents.clear();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class InvTask extends BukkitRunnable {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
new HashMap<>(inventories)
|
||||
.forEach((player, inv) -> inv.getProvider().update(player, contents.get(player)));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,240 @@
|
||||
/*
|
||||
* ____ _ _ _ _ _ _ _ _ _ _ _
|
||||
* | _ \ (_) | | | | | | | | (_) (_) | (_)
|
||||
* | |_) |_ _ _| | __| | ___ _ __ ___ ______| | | | |_ _| |_| |_ _ ___ ___
|
||||
* | _ <| | | | | |/ _` |/ _ \ '__/ __|______| | | | __| | | | __| |/ _ \/ __|
|
||||
* | |_) | |_| | | | (_| | __/ | \__ \ | |__| | |_| | | | |_| | __/\__ \
|
||||
* |____/ \__,_|_|_|\__,_|\___|_| |___/ \____/ \__|_|_|_|\__|_|\___||___/
|
||||
*
|
||||
* Builder's Utilities is a collection of a lot of tiny features that help with building.
|
||||
* Copyright (C) 2020 Arcaniax
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU 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 General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package net.arcaniax.buildersutilities.menus.inv;
|
||||
|
||||
import net.arcaniax.buildersutilities.menus.inv.content.InventoryContents;
|
||||
import net.arcaniax.buildersutilities.menus.inv.content.InventoryProvider;
|
||||
import net.arcaniax.buildersutilities.menus.inv.opener.InventoryOpener;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.inventory.InventoryCloseEvent;
|
||||
import org.bukkit.event.inventory.InventoryType;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public class SmartInventory {
|
||||
|
||||
private final InventoryManager manager;
|
||||
private String id;
|
||||
private String title;
|
||||
private InventoryType type;
|
||||
private int rows, columns;
|
||||
private boolean closeable;
|
||||
private InventoryProvider provider;
|
||||
private SmartInventory parent;
|
||||
private List<InventoryListener<? extends Event>> listeners;
|
||||
|
||||
private SmartInventory(InventoryManager manager) {
|
||||
this.manager = manager;
|
||||
}
|
||||
|
||||
public static Builder builder() {
|
||||
return new Builder();
|
||||
}
|
||||
|
||||
public Inventory open(Player player) {
|
||||
return open(player, 0);
|
||||
}
|
||||
|
||||
public Inventory open(Player player, int page) {
|
||||
Optional<SmartInventory> oldInv = this.manager.getInventory(player);
|
||||
|
||||
oldInv.ifPresent(inv -> {
|
||||
inv.getListeners().stream()
|
||||
.filter(listener -> listener.getType() == InventoryCloseEvent.class)
|
||||
.forEach(listener -> ((InventoryListener<InventoryCloseEvent>) listener)
|
||||
.accept(new InventoryCloseEvent(player.getOpenInventory())));
|
||||
|
||||
this.manager.setInventory(player, null);
|
||||
});
|
||||
|
||||
InventoryContents contents = new InventoryContents.Impl(this, player);
|
||||
contents.pagination().page(page);
|
||||
|
||||
this.manager.setContents(player, contents);
|
||||
this.provider.init(player, contents);
|
||||
|
||||
InventoryOpener opener = this.manager.findOpener(type)
|
||||
.orElseThrow(() -> new IllegalStateException(
|
||||
"No opener found for the inventory type " + type.name()));
|
||||
Inventory handle = opener.open(this, player);
|
||||
|
||||
this.manager.setInventory(player, this);
|
||||
|
||||
return handle;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public void close(Player player) {
|
||||
listeners.stream()
|
||||
.filter(listener -> listener.getType() == InventoryCloseEvent.class)
|
||||
.forEach(listener -> ((InventoryListener<InventoryCloseEvent>) listener)
|
||||
.accept(new InventoryCloseEvent(player.getOpenInventory())));
|
||||
|
||||
this.manager.setInventory(player, null);
|
||||
player.closeInventory();
|
||||
|
||||
this.manager.setContents(player, null);
|
||||
}
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public String getTitle() {
|
||||
return title;
|
||||
}
|
||||
|
||||
public InventoryType getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public int getRows() {
|
||||
return rows;
|
||||
}
|
||||
|
||||
public int getColumns() {
|
||||
return columns;
|
||||
}
|
||||
|
||||
public boolean isCloseable() {
|
||||
return closeable;
|
||||
}
|
||||
|
||||
public void setCloseable(boolean closeable) {
|
||||
this.closeable = closeable;
|
||||
}
|
||||
|
||||
public InventoryProvider getProvider() {
|
||||
return provider;
|
||||
}
|
||||
|
||||
public Optional<SmartInventory> getParent() {
|
||||
return Optional.ofNullable(parent);
|
||||
}
|
||||
|
||||
public InventoryManager getManager() {
|
||||
return manager;
|
||||
}
|
||||
|
||||
List<InventoryListener<? extends Event>> getListeners() {
|
||||
return listeners;
|
||||
}
|
||||
|
||||
public static final class Builder {
|
||||
|
||||
private final List<InventoryListener<? extends Event>> listeners = new ArrayList<>();
|
||||
private String id = "unknown";
|
||||
private String title = "";
|
||||
private InventoryType type = InventoryType.CHEST;
|
||||
private int rows = 6, columns = 9;
|
||||
private boolean closeable = true;
|
||||
private InventoryManager manager;
|
||||
private InventoryProvider provider;
|
||||
private SmartInventory parent;
|
||||
|
||||
private Builder() {
|
||||
}
|
||||
|
||||
public Builder id(String id) {
|
||||
this.id = id;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder title(String title) {
|
||||
this.title = title;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder type(InventoryType type) {
|
||||
this.type = type;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder size(int rows, int columns) {
|
||||
this.rows = rows;
|
||||
this.columns = columns;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder closeable(boolean closeable) {
|
||||
this.closeable = closeable;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder provider(InventoryProvider provider) {
|
||||
this.provider = provider;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder parent(SmartInventory parent) {
|
||||
this.parent = parent;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder listener(InventoryListener<? extends Event> listener) {
|
||||
this.listeners.add(listener);
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder manager(InventoryManager manager) {
|
||||
this.manager = manager;
|
||||
return this;
|
||||
}
|
||||
|
||||
public SmartInventory build() {
|
||||
if (this.provider == null) {
|
||||
throw new IllegalStateException(
|
||||
"The provider of the SmartInventory.Builder must be set.");
|
||||
}
|
||||
|
||||
InventoryManager manager = this.manager;
|
||||
|
||||
if (manager == null) {
|
||||
throw new IllegalStateException(
|
||||
"The manager of the SmartInventory.Builder must be set, "
|
||||
+ "or the SmartInvs should be loaded as a plugin.");
|
||||
}
|
||||
|
||||
SmartInventory inv = new SmartInventory(manager);
|
||||
inv.id = this.id;
|
||||
inv.title = this.title;
|
||||
inv.type = this.type;
|
||||
inv.rows = this.rows;
|
||||
inv.columns = this.columns;
|
||||
inv.closeable = this.closeable;
|
||||
inv.provider = this.provider;
|
||||
inv.parent = this.parent;
|
||||
inv.listeners = this.listeners;
|
||||
|
||||
return inv;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
+301
@@ -0,0 +1,301 @@
|
||||
/*
|
||||
* ____ _ _ _ _ _ _ _ _ _ _ _
|
||||
* | _ \ (_) | | | | | | | | (_) (_) | (_)
|
||||
* | |_) |_ _ _| | __| | ___ _ __ ___ ______| | | | |_ _| |_| |_ _ ___ ___
|
||||
* | _ <| | | | | |/ _` |/ _ \ '__/ __|______| | | | __| | | | __| |/ _ \/ __|
|
||||
* | |_) | |_| | | | (_| | __/ | \__ \ | |__| | |_| | | | |_| | __/\__ \
|
||||
* |____/ \__,_|_|_|\__,_|\___|_| |___/ \____/ \__|_|_|_|\__|_|\___||___/
|
||||
*
|
||||
* Builder's Utilities is a collection of a lot of tiny features that help with building.
|
||||
* Copyright (C) 2020 Arcaniax
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU 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 General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package net.arcaniax.buildersutilities.menus.inv.content;
|
||||
|
||||
import net.arcaniax.buildersutilities.menus.inv.ClickableItem;
|
||||
import net.arcaniax.buildersutilities.menus.inv.SmartInventory;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
||||
public interface InventoryContents {
|
||||
|
||||
SmartInventory inventory();
|
||||
|
||||
Pagination pagination();
|
||||
|
||||
Optional<SlotIterator> iterator(String id);
|
||||
|
||||
SlotIterator newIterator(String id, SlotIterator.Type type, int startRow, int startColumn);
|
||||
|
||||
SlotIterator newIterator(SlotIterator.Type type, int startRow, int startColumn);
|
||||
|
||||
SlotIterator newIterator(String id, SlotIterator.Type type, SlotPos startPos);
|
||||
|
||||
SlotIterator newIterator(SlotIterator.Type type, SlotPos startPos);
|
||||
|
||||
ClickableItem[][] all();
|
||||
|
||||
Optional<SlotPos> firstEmpty();
|
||||
|
||||
Optional<ClickableItem> get(int row, int column);
|
||||
|
||||
Optional<ClickableItem> get(SlotPos slotPos);
|
||||
|
||||
InventoryContents set(int row, int column, ClickableItem item);
|
||||
|
||||
InventoryContents set(SlotPos slotPos, ClickableItem item);
|
||||
|
||||
InventoryContents add(ClickableItem item);
|
||||
|
||||
InventoryContents fill(ClickableItem item);
|
||||
|
||||
InventoryContents fillRow(int row, ClickableItem item);
|
||||
|
||||
InventoryContents fillColumn(int column, ClickableItem item);
|
||||
|
||||
InventoryContents fillBorders(ClickableItem item);
|
||||
|
||||
InventoryContents fillRect(int fromRow, int fromColumn,
|
||||
int toRow, int toColumn, ClickableItem item);
|
||||
|
||||
InventoryContents fillRect(SlotPos fromPos, SlotPos toPos, ClickableItem item);
|
||||
|
||||
<T> T property(String name);
|
||||
|
||||
<T> T property(String name, T def);
|
||||
|
||||
InventoryContents setProperty(String name, Object value);
|
||||
|
||||
class Impl implements InventoryContents {
|
||||
|
||||
private final SmartInventory inv;
|
||||
private final Player player;
|
||||
|
||||
private final ClickableItem[][] contents;
|
||||
|
||||
private final Pagination pagination = new Pagination.Impl();
|
||||
private final Map<String, SlotIterator> iterators = new HashMap<>();
|
||||
private final Map<String, Object> properties = new HashMap<>();
|
||||
|
||||
public Impl(SmartInventory inv, Player player) {
|
||||
this.inv = inv;
|
||||
this.player = player;
|
||||
this.contents = new ClickableItem[inv.getRows()][inv.getColumns()];
|
||||
}
|
||||
|
||||
@Override
|
||||
public SmartInventory inventory() {
|
||||
return inv;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Pagination pagination() {
|
||||
return pagination;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<SlotIterator> iterator(String id) {
|
||||
return Optional.ofNullable(this.iterators.get(id));
|
||||
}
|
||||
|
||||
@Override
|
||||
public SlotIterator newIterator(String id, SlotIterator.Type type, int startRow,
|
||||
int startColumn) {
|
||||
SlotIterator iterator = new SlotIterator.Impl(this, inv,
|
||||
type, startRow, startColumn);
|
||||
|
||||
this.iterators.put(id, iterator);
|
||||
return iterator;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SlotIterator newIterator(String id, SlotIterator.Type type, SlotPos startPos) {
|
||||
return newIterator(id, type, startPos.getRow(), startPos.getColumn());
|
||||
}
|
||||
|
||||
@Override
|
||||
public SlotIterator newIterator(SlotIterator.Type type, int startRow, int startColumn) {
|
||||
return new SlotIterator.Impl(this, inv, type, startRow, startColumn);
|
||||
}
|
||||
|
||||
@Override
|
||||
public SlotIterator newIterator(SlotIterator.Type type, SlotPos startPos) {
|
||||
return newIterator(type, startPos.getRow(), startPos.getColumn());
|
||||
}
|
||||
|
||||
@Override
|
||||
public ClickableItem[][] all() {
|
||||
return contents;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<SlotPos> firstEmpty() {
|
||||
for (int row = 0; row < contents.length; row++) {
|
||||
for (int column = 0; column < contents[0].length; column++) {
|
||||
if (!this.get(row, column).isPresent()) {
|
||||
return Optional.of(new SlotPos(row, column));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<ClickableItem> get(int row, int column) {
|
||||
if (row >= contents.length) {
|
||||
return Optional.empty();
|
||||
}
|
||||
if (column >= contents[row].length) {
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
return Optional.ofNullable(contents[row][column]);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<ClickableItem> get(SlotPos slotPos) {
|
||||
return get(slotPos.getRow(), slotPos.getColumn());
|
||||
}
|
||||
|
||||
@Override
|
||||
public InventoryContents set(int row, int column, ClickableItem item) {
|
||||
if (row >= contents.length) {
|
||||
return this;
|
||||
}
|
||||
if (column >= contents[row].length) {
|
||||
return this;
|
||||
}
|
||||
|
||||
contents[row][column] = item;
|
||||
update(row, column, item != null ? item.getItem() : null);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public InventoryContents set(SlotPos slotPos, ClickableItem item) {
|
||||
return set(slotPos.getRow(), slotPos.getColumn(), item);
|
||||
}
|
||||
|
||||
@Override
|
||||
public InventoryContents add(ClickableItem item) {
|
||||
for (int row = 0; row < contents.length; row++) {
|
||||
for (int column = 0; column < contents[0].length; column++) {
|
||||
if (contents[row][column] == null) {
|
||||
set(row, column, item);
|
||||
return this;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public InventoryContents fill(ClickableItem item) {
|
||||
for (int row = 0; row < contents.length; row++) {
|
||||
for (int column = 0; column < contents[row].length; column++) {
|
||||
set(row, column, item);
|
||||
}
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public InventoryContents fillRow(int row, ClickableItem item) {
|
||||
if (row >= contents.length) {
|
||||
return this;
|
||||
}
|
||||
|
||||
for (int column = 0; column < contents[row].length; column++) {
|
||||
set(row, column, item);
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public InventoryContents fillColumn(int column, ClickableItem item) {
|
||||
for (int row = 0; row < contents.length; row++) {
|
||||
set(row, column, item);
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public InventoryContents fillBorders(ClickableItem item) {
|
||||
fillRect(0, 0, inv.getRows() - 1, inv.getColumns() - 1, item);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public InventoryContents fillRect(int fromRow, int fromColumn, int toRow, int toColumn,
|
||||
ClickableItem item) {
|
||||
for (int row = fromRow; row <= toRow; row++) {
|
||||
for (int column = fromColumn; column <= toColumn; column++) {
|
||||
if (row != fromRow && row != toRow && column != fromColumn && column != toColumn) {
|
||||
continue;
|
||||
}
|
||||
|
||||
set(row, column, item);
|
||||
}
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public InventoryContents fillRect(SlotPos fromPos, SlotPos toPos, ClickableItem item) {
|
||||
return fillRect(fromPos.getRow(), fromPos.getColumn(), toPos.getRow(), toPos.getColumn(),
|
||||
item);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public <T> T property(String name) {
|
||||
return (T) properties.get(name);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public <T> T property(String name, T def) {
|
||||
return properties.containsKey(name) ? (T) properties.get(name) : def;
|
||||
}
|
||||
|
||||
@Override
|
||||
public InventoryContents setProperty(String name, Object value) {
|
||||
properties.put(name, value);
|
||||
return this;
|
||||
}
|
||||
|
||||
private void update(int row, int column, ItemStack item) {
|
||||
if (!inv.getManager().getOpenedPlayers(inv).contains(player)) {
|
||||
return;
|
||||
}
|
||||
|
||||
Inventory topInventory = player.getOpenInventory().getTopInventory();
|
||||
topInventory.setItem(inv.getColumns() * row + column, item);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
/*
|
||||
* ____ _ _ _ _ _ _ _ _ _ _ _
|
||||
* | _ \ (_) | | | | | | | | (_) (_) | (_)
|
||||
* | |_) |_ _ _| | __| | ___ _ __ ___ ______| | | | |_ _| |_| |_ _ ___ ___
|
||||
* | _ <| | | | | |/ _` |/ _ \ '__/ __|______| | | | __| | | | __| |/ _ \/ __|
|
||||
* | |_) | |_| | | | (_| | __/ | \__ \ | |__| | |_| | | | |_| | __/\__ \
|
||||
* |____/ \__,_|_|_|\__,_|\___|_| |___/ \____/ \__|_|_|_|\__|_|\___||___/
|
||||
*
|
||||
* Builder's Utilities is a collection of a lot of tiny features that help with building.
|
||||
* Copyright (C) 2020 Arcaniax
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU 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 General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package net.arcaniax.buildersutilities.menus.inv.content;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public interface InventoryProvider {
|
||||
|
||||
void init(Player player, InventoryContents contents);
|
||||
|
||||
default void update(Player player, InventoryContents contents) {
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,151 @@
|
||||
/*
|
||||
* ____ _ _ _ _ _ _ _ _ _ _ _
|
||||
* | _ \ (_) | | | | | | | | (_) (_) | (_)
|
||||
* | |_) |_ _ _| | __| | ___ _ __ ___ ______| | | | |_ _| |_| |_ _ ___ ___
|
||||
* | _ <| | | | | |/ _` |/ _ \ '__/ __|______| | | | __| | | | __| |/ _ \/ __|
|
||||
* | |_) | |_| | | | (_| | __/ | \__ \ | |__| | |_| | | | |_| | __/\__ \
|
||||
* |____/ \__,_|_|_|\__,_|\___|_| |___/ \____/ \__|_|_|_|\__|_|\___||___/
|
||||
*
|
||||
* Builder's Utilities is a collection of a lot of tiny features that help with building.
|
||||
* Copyright (C) 2020 Arcaniax
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU 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 General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package net.arcaniax.buildersutilities.menus.inv.content;
|
||||
|
||||
import net.arcaniax.buildersutilities.menus.inv.ClickableItem;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
public interface Pagination {
|
||||
|
||||
ClickableItem[] getPageItems();
|
||||
|
||||
int getPage();
|
||||
|
||||
Pagination page(int page);
|
||||
|
||||
boolean isFirst();
|
||||
|
||||
boolean isLast();
|
||||
|
||||
Pagination first();
|
||||
|
||||
Pagination previous();
|
||||
|
||||
Pagination next();
|
||||
|
||||
Pagination last();
|
||||
|
||||
Pagination addToIterator(SlotIterator iterator);
|
||||
|
||||
Pagination setItems(ClickableItem... items);
|
||||
|
||||
Pagination setItemsPerPage(int itemsPerPage);
|
||||
|
||||
|
||||
class Impl implements Pagination {
|
||||
|
||||
private int currentPage;
|
||||
|
||||
private ClickableItem[] items = new ClickableItem[0];
|
||||
private int itemsPerPage = 5;
|
||||
|
||||
@Override
|
||||
public ClickableItem[] getPageItems() {
|
||||
return Arrays.copyOfRange(items,
|
||||
currentPage * itemsPerPage,
|
||||
(currentPage + 1) * itemsPerPage);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getPage() {
|
||||
return this.currentPage;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Pagination page(int page) {
|
||||
this.currentPage = page;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isFirst() {
|
||||
return this.currentPage == 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isLast() {
|
||||
int pageCount = (int) Math.ceil((double) this.items.length / this.itemsPerPage);
|
||||
return this.currentPage >= pageCount - 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Pagination first() {
|
||||
this.currentPage = 0;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Pagination previous() {
|
||||
if (!isFirst()) {
|
||||
this.currentPage--;
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Pagination next() {
|
||||
if (!isLast()) {
|
||||
this.currentPage++;
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Pagination last() {
|
||||
this.currentPage = this.items.length / this.itemsPerPage;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Pagination addToIterator(SlotIterator iterator) {
|
||||
for (ClickableItem item : getPageItems()) {
|
||||
iterator.next().set(item);
|
||||
|
||||
if (iterator.ended()) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Pagination setItems(ClickableItem... items) {
|
||||
this.items = items;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Pagination setItemsPerPage(int itemsPerPage) {
|
||||
this.itemsPerPage = itemsPerPage;
|
||||
return this;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,244 @@
|
||||
/*
|
||||
* ____ _ _ _ _ _ _ _ _ _ _ _
|
||||
* | _ \ (_) | | | | | | | | (_) (_) | (_)
|
||||
* | |_) |_ _ _| | __| | ___ _ __ ___ ______| | | | |_ _| |_| |_ _ ___ ___
|
||||
* | _ <| | | | | |/ _` |/ _ \ '__/ __|______| | | | __| | | | __| |/ _ \/ __|
|
||||
* | |_) | |_| | | | (_| | __/ | \__ \ | |__| | |_| | | | |_| | __/\__ \
|
||||
* |____/ \__,_|_|_|\__,_|\___|_| |___/ \____/ \__|_|_|_|\__|_|\___||___/
|
||||
*
|
||||
* Builder's Utilities is a collection of a lot of tiny features that help with building.
|
||||
* Copyright (C) 2020 Arcaniax
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU 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 General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package net.arcaniax.buildersutilities.menus.inv.content;
|
||||
|
||||
import net.arcaniax.buildersutilities.menus.inv.ClickableItem;
|
||||
import net.arcaniax.buildersutilities.menus.inv.SmartInventory;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
|
||||
public interface SlotIterator {
|
||||
|
||||
Optional<ClickableItem> get();
|
||||
|
||||
SlotIterator set(ClickableItem item);
|
||||
|
||||
SlotIterator previous();
|
||||
|
||||
SlotIterator next();
|
||||
|
||||
SlotIterator blacklist(int row, int column);
|
||||
|
||||
SlotIterator blacklist(SlotPos slotPos);
|
||||
|
||||
int row();
|
||||
|
||||
SlotIterator row(int row);
|
||||
|
||||
int column();
|
||||
|
||||
SlotIterator column(int column);
|
||||
|
||||
boolean started();
|
||||
|
||||
boolean ended();
|
||||
|
||||
boolean doesAllowOverride();
|
||||
|
||||
SlotIterator allowOverride(boolean override);
|
||||
|
||||
enum Type {
|
||||
HORIZONTAL,
|
||||
VERTICAL
|
||||
}
|
||||
|
||||
class Impl implements SlotIterator {
|
||||
|
||||
private final InventoryContents contents;
|
||||
private final SmartInventory inv;
|
||||
|
||||
private final Type type;
|
||||
private final Set<SlotPos> blacklisted = new HashSet<>();
|
||||
private boolean started = false;
|
||||
private boolean allowOverride = true;
|
||||
private int row, column;
|
||||
|
||||
public Impl(InventoryContents contents, SmartInventory inv,
|
||||
Type type, int startRow, int startColumn) {
|
||||
|
||||
this.contents = contents;
|
||||
this.inv = inv;
|
||||
|
||||
this.type = type;
|
||||
|
||||
this.row = startRow;
|
||||
this.column = startColumn;
|
||||
}
|
||||
|
||||
public Impl(InventoryContents contents, SmartInventory inv,
|
||||
Type type) {
|
||||
|
||||
this(contents, inv, type, 0, 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<ClickableItem> get() {
|
||||
return contents.get(row, column);
|
||||
}
|
||||
|
||||
@Override
|
||||
public SlotIterator set(ClickableItem item) {
|
||||
if (canPlace()) {
|
||||
contents.set(row, column, item);
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SlotIterator previous() {
|
||||
if (row == 0 && column == 0) {
|
||||
this.started = true;
|
||||
return this;
|
||||
}
|
||||
|
||||
do {
|
||||
if (!this.started) {
|
||||
this.started = true;
|
||||
} else {
|
||||
switch (type) {
|
||||
case HORIZONTAL:
|
||||
column--;
|
||||
|
||||
if (column == 0) {
|
||||
column = inv.getColumns() - 1;
|
||||
row--;
|
||||
}
|
||||
break;
|
||||
case VERTICAL:
|
||||
row--;
|
||||
|
||||
if (row == 0) {
|
||||
row = inv.getRows() - 1;
|
||||
column--;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
while (!canPlace() && (row != 0 || column != 0));
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SlotIterator next() {
|
||||
if (ended()) {
|
||||
this.started = true;
|
||||
return this;
|
||||
}
|
||||
|
||||
do {
|
||||
if (!this.started) {
|
||||
this.started = true;
|
||||
} else {
|
||||
switch (type) {
|
||||
case HORIZONTAL:
|
||||
column = ++column % inv.getColumns();
|
||||
|
||||
if (column == 0) {
|
||||
row++;
|
||||
}
|
||||
break;
|
||||
case VERTICAL:
|
||||
row = ++row % inv.getRows();
|
||||
|
||||
if (row == 0) {
|
||||
column++;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
while (!canPlace() && !ended());
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SlotIterator blacklist(int row, int column) {
|
||||
this.blacklisted.add(SlotPos.of(row, column));
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SlotIterator blacklist(SlotPos slotPos) {
|
||||
return blacklist(slotPos.getRow(), slotPos.getColumn());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int row() {
|
||||
return row;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SlotIterator row(int row) {
|
||||
this.row = row;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int column() {
|
||||
return column;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SlotIterator column(int column) {
|
||||
this.column = column;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean started() {
|
||||
return this.started;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean ended() {
|
||||
return row == inv.getRows() - 1
|
||||
&& column == inv.getColumns() - 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean doesAllowOverride() {
|
||||
return allowOverride;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SlotIterator allowOverride(boolean override) {
|
||||
this.allowOverride = override;
|
||||
return this;
|
||||
}
|
||||
|
||||
private boolean canPlace() {
|
||||
return !blacklisted.contains(SlotPos.of(row, column)) && (allowOverride || !this.get()
|
||||
.isPresent());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
/*
|
||||
* ____ _ _ _ _ _ _ _ _ _ _ _
|
||||
* | _ \ (_) | | | | | | | | (_) (_) | (_)
|
||||
* | |_) |_ _ _| | __| | ___ _ __ ___ ______| | | | |_ _| |_| |_ _ ___ ___
|
||||
* | _ <| | | | | |/ _` |/ _ \ '__/ __|______| | | | __| | | | __| |/ _ \/ __|
|
||||
* | |_) | |_| | | | (_| | __/ | \__ \ | |__| | |_| | | | |_| | __/\__ \
|
||||
* |____/ \__,_|_|_|\__,_|\___|_| |___/ \____/ \__|_|_|_|\__|_|\___||___/
|
||||
*
|
||||
* Builder's Utilities is a collection of a lot of tiny features that help with building.
|
||||
* Copyright (C) 2020 Arcaniax
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU 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 General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package net.arcaniax.buildersutilities.menus.inv.content;
|
||||
|
||||
public class SlotPos {
|
||||
|
||||
private final int row;
|
||||
private final int column;
|
||||
|
||||
public SlotPos(int row, int column) {
|
||||
this.row = row;
|
||||
this.column = column;
|
||||
}
|
||||
|
||||
public static SlotPos of(int row, int column) {
|
||||
return new SlotPos(row, column);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj) {
|
||||
return true;
|
||||
}
|
||||
if (obj == null || getClass() != obj.getClass()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
SlotPos slotPos = (SlotPos) obj;
|
||||
|
||||
return row == slotPos.row && column == slotPos.column;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int result = row;
|
||||
result = 31 * result + column;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public int getRow() {
|
||||
return row;
|
||||
}
|
||||
|
||||
public int getColumn() {
|
||||
return column;
|
||||
}
|
||||
|
||||
}
|
||||
+59
@@ -0,0 +1,59 @@
|
||||
/*
|
||||
* ____ _ _ _ _ _ _ _ _ _ _ _
|
||||
* | _ \ (_) | | | | | | | | (_) (_) | (_)
|
||||
* | |_) |_ _ _| | __| | ___ _ __ ___ ______| | | | |_ _| |_| |_ _ ___ ___
|
||||
* | _ <| | | | | |/ _` |/ _ \ '__/ __|______| | | | __| | | | __| |/ _ \/ __|
|
||||
* | |_) | |_| | | | (_| | __/ | \__ \ | |__| | |_| | | | |_| | __/\__ \
|
||||
* |____/ \__,_|_|_|\__,_|\___|_| |___/ \____/ \__|_|_|_|\__|_|\___||___/
|
||||
*
|
||||
* Builder's Utilities is a collection of a lot of tiny features that help with building.
|
||||
* Copyright (C) 2020 Arcaniax
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU 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 General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package net.arcaniax.buildersutilities.menus.inv.opener;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import net.arcaniax.buildersutilities.menus.inv.InventoryManager;
|
||||
import net.arcaniax.buildersutilities.menus.inv.SmartInventory;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.inventory.InventoryType;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
|
||||
public class ChestInventoryOpener implements InventoryOpener {
|
||||
|
||||
@Override
|
||||
public Inventory open(SmartInventory inv, Player player) {
|
||||
Preconditions.checkArgument(inv.getColumns() == 9,
|
||||
"The column count for the chest inventory must be 9, found: %s.", inv.getColumns());
|
||||
Preconditions.checkArgument(inv.getRows() >= 1 && inv.getRows() <= 6,
|
||||
"The row count for the chest inventory must be between 1 and 6, found: %s", inv.getRows());
|
||||
|
||||
InventoryManager manager = inv.getManager();
|
||||
Inventory handle = Bukkit
|
||||
.createInventory(player, inv.getRows() * inv.getColumns(), inv.getTitle());
|
||||
|
||||
fill(handle, manager.getContents(player).get());
|
||||
|
||||
player.openInventory(handle);
|
||||
return handle;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean supports(InventoryType type) {
|
||||
return type == InventoryType.CHEST || type == InventoryType.ENDER_CHEST;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
/*
|
||||
* ____ _ _ _ _ _ _ _ _ _ _ _
|
||||
* | _ \ (_) | | | | | | | | (_) (_) | (_)
|
||||
* | |_) |_ _ _| | __| | ___ _ __ ___ ______| | | | |_ _| |_| |_ _ ___ ___
|
||||
* | _ <| | | | | |/ _` |/ _ \ '__/ __|______| | | | __| | | | __| |/ _ \/ __|
|
||||
* | |_) | |_| | | | (_| | __/ | \__ \ | |__| | |_| | | | |_| | __/\__ \
|
||||
* |____/ \__,_|_|_|\__,_|\___|_| |___/ \____/ \__|_|_|_|\__|_|\___||___/
|
||||
*
|
||||
* Builder's Utilities is a collection of a lot of tiny features that help with building.
|
||||
* Copyright (C) 2020 Arcaniax
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU 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 General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package net.arcaniax.buildersutilities.menus.inv.opener;
|
||||
|
||||
import net.arcaniax.buildersutilities.menus.inv.ClickableItem;
|
||||
import net.arcaniax.buildersutilities.menus.inv.SmartInventory;
|
||||
import net.arcaniax.buildersutilities.menus.inv.content.InventoryContents;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.inventory.InventoryType;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
|
||||
public interface InventoryOpener {
|
||||
|
||||
Inventory open(SmartInventory inv, Player player);
|
||||
|
||||
boolean supports(InventoryType type);
|
||||
|
||||
default void fill(Inventory handle, InventoryContents contents) {
|
||||
ClickableItem[][] items = contents.all();
|
||||
|
||||
for (int row = 0; row < items.length; row++) {
|
||||
for (int column = 0; column < items[row].length; column++) {
|
||||
if (items[row][column] != null) {
|
||||
handle.setItem(9 * row + column, items[row][column].getItem());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
+67
@@ -0,0 +1,67 @@
|
||||
/*
|
||||
* ____ _ _ _ _ _ _ _ _ _ _ _
|
||||
* | _ \ (_) | | | | | | | | (_) (_) | (_)
|
||||
* | |_) |_ _ _| | __| | ___ _ __ ___ ______| | | | |_ _| |_| |_ _ ___ ___
|
||||
* | _ <| | | | | |/ _` |/ _ \ '__/ __|______| | | | __| | | | __| |/ _ \/ __|
|
||||
* | |_) | |_| | | | (_| | __/ | \__ \ | |__| | |_| | | | |_| | __/\__ \
|
||||
* |____/ \__,_|_|_|\__,_|\___|_| |___/ \____/ \__|_|_|_|\__|_|\___||___/
|
||||
*
|
||||
* Builder's Utilities is a collection of a lot of tiny features that help with building.
|
||||
* Copyright (C) 2020 Arcaniax
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU 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 General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package net.arcaniax.buildersutilities.menus.inv.opener;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import net.arcaniax.buildersutilities.menus.inv.InventoryManager;
|
||||
import net.arcaniax.buildersutilities.menus.inv.SmartInventory;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.inventory.InventoryType;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class SpecialInventoryOpener implements InventoryOpener {
|
||||
|
||||
private static final List<InventoryType> SUPPORTED = ImmutableList.of(
|
||||
InventoryType.FURNACE,
|
||||
InventoryType.WORKBENCH,
|
||||
InventoryType.DISPENSER,
|
||||
InventoryType.DROPPER,
|
||||
InventoryType.ENCHANTING,
|
||||
InventoryType.BREWING,
|
||||
InventoryType.ANVIL,
|
||||
InventoryType.BEACON,
|
||||
InventoryType.HOPPER
|
||||
);
|
||||
|
||||
@Override
|
||||
public Inventory open(SmartInventory inv, Player player) {
|
||||
InventoryManager manager = inv.getManager();
|
||||
Inventory handle = Bukkit.createInventory(player, inv.getType(), inv.getTitle());
|
||||
|
||||
fill(handle, manager.getContents(player).get());
|
||||
|
||||
player.openInventory(handle);
|
||||
return handle;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean supports(InventoryType type) {
|
||||
return SUPPORTED.contains(type);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user