Search in sources :

Example 16 with StackManager

use of dev.rosewood.rosestacker.manager.StackManager in project RoseStacker by Rosewood-Development.

the class InteractListener method onInteractEntity.

@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void onInteractEntity(PlayerInteractEntityEvent event) {
    if (!(event.getRightClicked() instanceof LivingEntity))
        return;
    StackManager stackManager = this.rosePlugin.getManager(StackManager.class);
    if (stackManager.isWorldDisabled(event.getPlayer().getWorld()))
        return;
    if (!stackManager.isEntityStackingEnabled())
        return;
    LivingEntity entity = (LivingEntity) event.getRightClicked();
    StackedEntity stackedEntity = stackManager.getStackedEntity(entity);
    if (stackedEntity == null)
        return;
    Player player = event.getPlayer();
    ItemStack itemStack = event.getHand() == EquipmentSlot.HAND ? player.getInventory().getItemInMainHand() : player.getInventory().getItemInOffHand();
    if (itemStack.getType() == Material.NAME_TAG) {
        Bukkit.getScheduler().runTask(this.rosePlugin, stackedEntity::updateDisplay);
        return;
    } else if (itemStack.getType() == Material.WATER_BUCKET) {
        switch(entity.getType()) {
            case COD:
            case SALMON:
            case PUFFERFISH:
            case TROPICAL_FISH:
            case AXOLOTL:
                break;
            default:
                return;
        }
        if (stackedEntity.getStackSize() != 1)
            Bukkit.getScheduler().runTask(this.rosePlugin, stackedEntity::decreaseStackSize);
        return;
    }
    if (this.spawnEntities(entity, entity.getLocation(), itemStack)) {
        ItemUtils.takeOneItem(event.getPlayer(), event.getHand());
        event.setCancelled(true);
    }
}
Also used : LivingEntity(org.bukkit.entity.LivingEntity) StackedEntity(dev.rosewood.rosestacker.stack.StackedEntity) Player(org.bukkit.entity.Player) StackManager(dev.rosewood.rosestacker.manager.StackManager) ItemStack(org.bukkit.inventory.ItemStack) EventHandler(org.bukkit.event.EventHandler)

Example 17 with StackManager

use of dev.rosewood.rosestacker.manager.StackManager in project RoseStacker by Rosewood-Development.

the class InteractListener method spawnEntities.

private boolean spawnEntities(Entity original, Location spawnLocation, ItemStack itemStack) {
    if (!ItemUtils.isSpawnEgg(itemStack.getType()) || !ItemUtils.hasStoredStackSize(itemStack))
        return false;
    int spawnAmount = ItemUtils.getStackedItemStackAmount(itemStack);
    EntityStackSettings stackSettings = this.rosePlugin.getManager(StackSettingManager.class).getEntityStackSettings(itemStack.getType());
    EntityType entityType = stackSettings.getEntityType();
    if (original != null && original.getType() != entityType)
        return false;
    if (spawnLocation.getWorld() == null)
        return false;
    StackManager stackManager = this.rosePlugin.getManager(StackManager.class);
    if (stackManager.isWorldDisabled(spawnLocation.getWorld()))
        return false;
    stackManager.preStackEntities(entityType, spawnAmount, spawnLocation, SpawnReason.SPAWNER_EGG);
    return true;
}
Also used : EntityStackSettings(dev.rosewood.rosestacker.stack.settings.EntityStackSettings) EntityType(org.bukkit.entity.EntityType) StackManager(dev.rosewood.rosestacker.manager.StackManager) StackSettingManager(dev.rosewood.rosestacker.manager.StackSettingManager)

Example 18 with StackManager

use of dev.rosewood.rosestacker.manager.StackManager in project RoseStacker by Rosewood-Development.

the class RoseCommand method onClearall.

@Subcommand("clearall")
@CommandPermission("rosestacker.clearall")
@CommandCompletion("@clearallType")
public void onClearall(CommandSender sender, ClearallType clearallType) {
    StackManager stackManager = this.rosePlugin.getManager(StackManager.class);
    LocaleManager localeManager = this.rosePlugin.getManager(LocaleManager.class);
    int amount;
    switch(clearallType) {
        case ENTITY:
            amount = stackManager.removeAllEntityStacks();
            localeManager.sendMessage(sender, "command-clearall-killed-entities", StringPlaceholders.single("amount", amount));
            break;
        case ITEM:
            amount = stackManager.removeAllItemStacks();
            localeManager.sendMessage(sender, "command-clearall-killed-items", StringPlaceholders.single("amount", amount));
            break;
        case ALL:
            int entities = stackManager.removeAllEntityStacks();
            int items = stackManager.removeAllItemStacks();
            localeManager.sendMessage(sender, "command-clearall-killed-all", StringPlaceholders.builder("entityAmount", entities).addPlaceholder("itemAmount", items).build());
            break;
    }
}
Also used : StackManager(dev.rosewood.rosestacker.manager.StackManager) LocaleManager(dev.rosewood.rosestacker.manager.LocaleManager) Subcommand(co.aikar.commands.annotation.Subcommand) CommandCompletion(co.aikar.commands.annotation.CommandCompletion) CommandPermission(co.aikar.commands.annotation.CommandPermission)

Example 19 with StackManager

use of dev.rosewood.rosestacker.manager.StackManager in project RoseStacker by Rosewood-Development.

the class RoseCommand method onStats.

@Subcommand("stats")
@CommandPermission("rosestacker.stats")
public void onStats(CommandSender sender) {
    StackManager stackManager = this.rosePlugin.getManager(StackManager.class);
    LocaleManager localeManager = this.rosePlugin.getManager(LocaleManager.class);
    int threadAmount = stackManager.getStackingThreads().size();
    int entityStackAmount = stackManager.getStackedEntities().size();
    int itemStackAmount = stackManager.getStackedItems().size();
    int blockStackAmount = stackManager.getStackedBlocks().size();
    int spawnerStackAmount = stackManager.getStackedSpawners().size();
    int entityAmount = stackManager.getStackedEntities().values().stream().mapToInt(Stack::getStackSize).sum();
    int itemAmount = stackManager.getStackedItems().values().stream().mapToInt(Stack::getStackSize).sum();
    int blockAmount = stackManager.getStackedBlocks().values().stream().mapToInt(Stack::getStackSize).sum();
    int spawnerAmount = stackManager.getStackedSpawners().values().stream().mapToInt(Stack::getStackSize).sum();
    localeManager.sendMessage(sender, "command-stats-header");
    localeManager.sendSimpleMessage(sender, "command-stats-threads", StringPlaceholders.single("amount", threadAmount));
    localeManager.sendSimpleMessage(sender, "command-stats-stacked-entities", StringPlaceholders.builder("stackAmount", entityStackAmount).addPlaceholder("total", entityAmount).build());
    localeManager.sendSimpleMessage(sender, "command-stats-stacked-items", StringPlaceholders.builder("stackAmount", itemStackAmount).addPlaceholder("total", itemAmount).build());
    localeManager.sendSimpleMessage(sender, "command-stats-stacked-blocks", StringPlaceholders.builder("stackAmount", blockStackAmount).addPlaceholder("total", blockAmount).build());
    localeManager.sendSimpleMessage(sender, "command-stats-stacked-spawners", StringPlaceholders.builder("stackAmount", spawnerStackAmount).addPlaceholder("total", spawnerAmount).build());
}
Also used : StackManager(dev.rosewood.rosestacker.manager.StackManager) LocaleManager(dev.rosewood.rosestacker.manager.LocaleManager) Subcommand(co.aikar.commands.annotation.Subcommand) CommandPermission(co.aikar.commands.annotation.CommandPermission)

Example 20 with StackManager

use of dev.rosewood.rosestacker.manager.StackManager in project RoseStacker by Rosewood-Development.

the class WildStackerPluginConverter method convert.

@Override
public void convert() {
    StackManager stackManager = this.rosePlugin.getManager(StackManager.class);
    // Force save loaded data
    SystemManager systemHandler = WildStackerAPI.getWildStacker().getSystemManager();
    systemHandler.performCacheSave();
    // Go through the database to be able to load all information
    DatabaseConnector connector = new SQLiteConnector(this.wildStacker, "database");
    connector.connect(connection -> {
        // Load barrels (blocks)
        Set<StackedBlock> stackedBlocks = new HashSet<>();
        try (Statement statement = connection.createStatement()) {
            ResultSet result = statement.executeQuery("SELECT location, stackAmount FROM barrels");
            while (result.next()) {
                Location location = this.parseLocation(result.getString("location"), ',');
                if (location == null)
                    continue;
                int amount = result.getInt("stackAmount");
                Material type = systemHandler.getStackedSnapshot(location.getChunk()).getStackedBarrelItem(location).getValue().getType();
                Block block = location.getBlock();
                // Remove hologram thingy
                StackedBarrel barrel = systemHandler.getStackedBarrel(block);
                if (barrel != null)
                    barrel.removeDisplayBlock();
                // Set the block type to the stack type since we just removed the hologram thingy
                block.setType(type);
                // Stacks of 1 aren't really stacks
                if (amount == 1)
                    continue;
                stackedBlocks.add(new StackedBlock(amount, block));
            }
        }
        // Load spawners
        Set<StackedSpawner> stackedSpawners = new HashSet<>();
        try (Statement statement = connection.createStatement()) {
            ResultSet result = statement.executeQuery("SELECT location, stackAmount FROM spawners");
            while (result.next()) {
                Location location = this.parseLocation(result.getString("location"), ',');
                if (location == null)
                    continue;
                Block block = location.getBlock();
                BlockState blockState = block.getState();
                if (!(blockState instanceof CreatureSpawner))
                    continue;
                int amount = result.getInt("stackAmount");
                stackedSpawners.add(new StackedSpawner(amount, location));
            }
        }
        if (!stackedBlocks.isEmpty() || !stackedSpawners.isEmpty()) {
            Bukkit.getScheduler().runTask(this.rosePlugin, () -> {
                for (StackedBlock stackedBlock : stackedBlocks) stackManager.createBlockStack(stackedBlock.getLocation().getBlock(), stackedBlock.getStackSize());
                for (StackedSpawner stackedSpawner : stackedSpawners) stackManager.createSpawnerStack(stackedSpawner.getLocation().getBlock(), stackedSpawner.getStackSize(), false);
            });
        }
    });
}
Also used : DatabaseConnector(dev.rosewood.rosegarden.database.DatabaseConnector) StackedSpawner(dev.rosewood.rosestacker.stack.StackedSpawner) StackManager(dev.rosewood.rosestacker.manager.StackManager) Statement(java.sql.Statement) SystemManager(com.bgsoftware.wildstacker.api.handlers.SystemManager) Material(org.bukkit.Material) CreatureSpawner(org.bukkit.block.CreatureSpawner) BlockState(org.bukkit.block.BlockState) StackedBlock(dev.rosewood.rosestacker.stack.StackedBlock) SQLiteConnector(dev.rosewood.rosegarden.database.SQLiteConnector) ResultSet(java.sql.ResultSet) StackedBarrel(com.bgsoftware.wildstacker.api.objects.StackedBarrel) Block(org.bukkit.block.Block) StackedBlock(dev.rosewood.rosestacker.stack.StackedBlock) HashSet(java.util.HashSet) Location(org.bukkit.Location)

Aggregations

StackManager (dev.rosewood.rosestacker.manager.StackManager)22 StackedSpawner (dev.rosewood.rosestacker.stack.StackedSpawner)12 EventHandler (org.bukkit.event.EventHandler)10 ItemStack (org.bukkit.inventory.ItemStack)10 Location (org.bukkit.Location)9 Block (org.bukkit.block.Block)9 EntityType (org.bukkit.entity.EntityType)7 StackSettingManager (dev.rosewood.rosestacker.manager.StackSettingManager)6 StackedBlock (dev.rosewood.rosestacker.stack.StackedBlock)6 StackedEntity (dev.rosewood.rosestacker.stack.StackedEntity)6 EntityStackSettings (dev.rosewood.rosestacker.stack.settings.EntityStackSettings)5 SpawnerStackSettings (dev.rosewood.rosestacker.stack.settings.SpawnerStackSettings)5 ArrayList (java.util.ArrayList)5 HashSet (java.util.HashSet)5 LivingEntity (org.bukkit.entity.LivingEntity)5 BlockUnstackEvent (dev.rosewood.rosestacker.event.BlockUnstackEvent)4 Setting (dev.rosewood.rosestacker.manager.ConfigurationManager.Setting)4 LocaleManager (dev.rosewood.rosestacker.manager.LocaleManager)4 PersistentDataUtils (dev.rosewood.rosestacker.utils.PersistentDataUtils)4 StackerUtils (dev.rosewood.rosestacker.utils.StackerUtils)4