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);
}
}
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;
}
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;
}
}
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());
}
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);
});
}
});
}
Aggregations