Search in sources :

Example 1 with Advent21Config

use of gg.projecteden.nexus.models.pugmas21.Advent21Config in project Nexus by ProjectEdenGG.

the class Advent method onClickPresent.

@EventHandler
public void onClickPresent(PlayerInteractEvent event) {
    final Player player = event.getPlayer();
    if (event.getHand() != EquipmentSlot.HAND)
        return;
    if (!Pugmas21.isAtPugmas(player))
        return;
    final Block block = event.getClickedBlock();
    if (block == null)
        return;
    if (block.getType() != Material.BARRIER)
        return;
    if (Pugmas21.isPastPugmas())
        return;
    final Advent21Config adventConfig = new Advent21ConfigService().get0();
    final AdventPresent present = adventConfig.get(block.getLocation());
    if (present == null)
        return;
    new Pugmas21UserService().edit(player, user -> user.advent().tryCollect(present));
}
Also used : Player(org.bukkit.entity.Player) Pugmas21UserService(gg.projecteden.nexus.models.pugmas21.Pugmas21UserService) Advent21Config(gg.projecteden.nexus.models.pugmas21.Advent21Config) Advent21ConfigService(gg.projecteden.nexus.models.pugmas21.Advent21ConfigService) Block(org.bukkit.block.Block) AdventPresent(gg.projecteden.nexus.models.pugmas21.Advent21Config.AdventPresent) EventHandler(org.bukkit.event.EventHandler)

Example 2 with Advent21Config

use of gg.projecteden.nexus.models.pugmas21.Advent21Config in project Nexus by ProjectEdenGG.

the class Advent method updateItems.

public static void updateItems() {
    Advent21ConfigService configService = new Advent21ConfigService();
    Advent21Config adventConfig = Advent21Config.get();
    Location lootOrigin = adventConfig.getLootOrigin();
    int index = 1;
    for (int z = 0; z <= 6; z++) {
        // 0-3 col (Every other)
        for (int x = 0; x <= 12; x++) {
            // 0-6 row (Every other)
            Block block = lootOrigin.getBlock().getRelative(x, 0, z);
            if (isNullOrAir(block.getType()) || !block.getType().equals(Material.CHEST))
                continue;
            Chest chest = (Chest) block.getState();
            List<ItemStack> contents = Arrays.stream(chest.getBlockInventory().getContents()).filter(Nullables::isNotNullOrAir).collect(Collectors.toList());
            if (isNullOrEmpty(contents))
                Nexus.warn("Contents of advent present " + index + " is empty!");
            adventConfig.get(index++).setContents(contents);
        }
    }
    configService.save(adventConfig);
}
Also used : Chest(org.bukkit.block.Chest) Advent21ConfigService(gg.projecteden.nexus.models.pugmas21.Advent21ConfigService) Advent21Config(gg.projecteden.nexus.models.pugmas21.Advent21Config) Block(org.bukkit.block.Block) ItemStack(org.bukkit.inventory.ItemStack) Location(org.bukkit.Location)

Aggregations

Advent21Config (gg.projecteden.nexus.models.pugmas21.Advent21Config)2 Advent21ConfigService (gg.projecteden.nexus.models.pugmas21.Advent21ConfigService)2 Block (org.bukkit.block.Block)2 AdventPresent (gg.projecteden.nexus.models.pugmas21.Advent21Config.AdventPresent)1 Pugmas21UserService (gg.projecteden.nexus.models.pugmas21.Pugmas21UserService)1 Location (org.bukkit.Location)1 Chest (org.bukkit.block.Chest)1 Player (org.bukkit.entity.Player)1 EventHandler (org.bukkit.event.EventHandler)1 ItemStack (org.bukkit.inventory.ItemStack)1