use of dev.rosewood.rosestacker.conversion.handler.ConversionHandler in project RoseStacker by Rosewood-Development.
the class ConversionManager method convertChunkEntities.
/**
* Runs the chunk data conversion for any conversion handlers
*
* @param chunkEntities The entities in the chunk to convert
*/
public void convertChunkEntities(List<Entity> chunkEntities) {
Set<StackType> requiredStackTypes = new HashSet<>();
for (ConversionHandler conversionHandler : this.conversionHandlers) requiredStackTypes.add(conversionHandler.getRequiredDataStackType());
Map<StackType, Set<ConversionData>> conversionData = this.dataManager.getConversionData(chunkEntities, requiredStackTypes);
Set<Stack<?>> convertedStacks = new HashSet<>();
for (ConversionHandler conversionHandler : this.conversionHandlers) {
Set<ConversionData> data;
if (conversionHandler.shouldUseChunkEntities()) {
data = new HashSet<>();
switch(conversionHandler.getRequiredDataStackType()) {
case ENTITY:
for (Entity entity : chunkEntities) if (entity.getType() != EntityType.DROPPED_ITEM)
data.add(new ConversionData(entity));
break;
case ITEM:
for (Entity entity : chunkEntities) if (entity.getType() == EntityType.DROPPED_ITEM)
data.add(new ConversionData(entity));
break;
default:
break;
}
} else {
data = conversionData.get(conversionHandler.getRequiredDataStackType());
}
if (data.isEmpty())
continue;
convertedStacks.addAll(conversionHandler.handleConversion(data));
}
// Update nametags synchronously
if (!convertedStacks.isEmpty())
Bukkit.getScheduler().runTask(this.rosePlugin, () -> convertedStacks.forEach(Stack::updateDisplay));
}
use of dev.rosewood.rosestacker.conversion.handler.ConversionHandler in project RoseStacker by Rosewood-Development.
the class CommandManager method reload.
@Override
public void reload() {
LocaleManager localeManager = this.rosePlugin.getManager(LocaleManager.class);
ConversionManager conversionManager = this.rosePlugin.getManager(ConversionManager.class);
StackSettingManager stackSettingManager = this.rosePlugin.getManager(StackSettingManager.class);
// Load custom message strings
Map<String, String> acfCoreMessages = localeManager.getAcfCoreMessages();
Map<String, String> acfMinecraftMessages = localeManager.getAcfMinecraftMessages();
for (Entry<String, String> entry : acfCoreMessages.entrySet()) this.commandManager.getLocales().addMessage(Locale.ENGLISH, MessageKey.of("acf-core." + entry.getKey()), HexUtils.colorify(localeManager.getLocaleMessage("prefix") + entry.getValue()));
for (Entry<String, String> entry : acfMinecraftMessages.entrySet()) this.commandManager.getLocales().addMessage(Locale.ENGLISH, MessageKey.of("acf-minecraft." + entry.getKey()), HexUtils.colorify(localeManager.getLocaleMessage("prefix") + entry.getValue()));
CommandCompletions<BukkitCommandCompletionContext> completions = this.commandManager.getCommandCompletions();
completions.registerStaticCompletion("stackableBlockMaterial", () -> stackSettingManager.getStackableBlockTypes().stream().map(Enum::name).map(String::toLowerCase).collect(Collectors.toSet()));
completions.registerStaticCompletion("spawnableSpawnerEntityType", () -> stackSettingManager.getStackableSpawnerTypes().stream().map(Enum::name).map(String::toLowerCase).collect(Collectors.toSet()));
completions.registerStaticCompletion("spawnableEggEntityType", () -> stackSettingManager.getStackableEntityTypes().stream().filter(x -> {
EntityStackSettings stackSettings = stackSettingManager.getEntityStackSettings(x);
return stackSettings.getEntityTypeData().getSpawnEggMaterial() != null;
}).map(Enum::name).map(String::toLowerCase).collect(Collectors.toSet()));
completions.registerAsyncCompletion("blockStackAmounts", ctx -> {
Material blockType = ctx.getContextValue(Material.class);
if (blockType == null)
return Collections.emptyList();
BlockStackSettings blockStackSettings = stackSettingManager.getBlockStackSettings(blockType);
int maxStackAmount = blockStackSettings.getMaxStackSize();
return Arrays.asList(String.valueOf(maxStackAmount), String.valueOf(maxStackAmount / 2), String.valueOf(maxStackAmount / 4), "<amount>");
});
completions.registerAsyncCompletion("spawnerStackAmounts", ctx -> {
EntityType entityType = ctx.getContextValue(EntityType.class);
if (entityType == null)
return Collections.emptySet();
SpawnerStackSettings spawnerStackSettings = stackSettingManager.getSpawnerStackSettings(entityType);
int maxStackAmount = spawnerStackSettings.getMaxStackSize();
return Arrays.asList(String.valueOf(maxStackAmount), String.valueOf(maxStackAmount / 2), String.valueOf(maxStackAmount / 4), "<amount>");
});
completions.registerAsyncCompletion("entityStackAmounts", ctx -> {
EntityType entityType = ctx.getContextValue(EntityType.class);
if (entityType == null)
return Collections.emptySet();
EntityStackSettings entityStackSettings = stackSettingManager.getEntityStackSettings(entityType);
int maxStackAmount = entityStackSettings.getMaxStackSize();
return Arrays.asList(String.valueOf(maxStackAmount), String.valueOf(maxStackAmount / 2), String.valueOf(maxStackAmount / 4), "<amount>");
});
completions.registerStaticCompletion("giveAmounts", () -> IntStream.rangeClosed(1, 5).mapToObj(String::valueOf).collect(Collectors.toList()));
completions.registerStaticCompletion("clearallType", () -> Stream.of(ClearallType.values()).map(Enum::name).map(String::toLowerCase).collect(Collectors.toSet()));
completions.registerStaticCompletion("stackType", () -> Stream.of(StackType.values()).map(Enum::name).map(String::toLowerCase).collect(Collectors.toSet()));
completions.registerAsyncCompletion("conversionType", ctx -> conversionManager.getEnabledConverters().stream().map(Enum::name).collect(Collectors.toSet()));
completions.registerAsyncCompletion("conversionEnabledType", ctx -> conversionManager.getEnabledHandlers().stream().map(ConversionHandler::getRequiredDataStackType).map(Enum::name).map(String::toLowerCase).collect(Collectors.toSet()));
completions.registerAsyncCompletion("translationLocales", ctx -> localeManager.getPossibleTranslationLocales());
this.commandManager.getCommandConditions().addCondition(int.class, "limits", (c, exec, value) -> {
if (value == null)
return;
if (c.hasConfig("min") && c.getConfigValue("min", 0) > value)
throw new ConditionFailedException(MessageKeys.PLEASE_SPECIFY_AT_LEAST, "{min}", String.valueOf(c.getConfigValue("min", 0)));
if (c.hasConfig("max") && c.getConfigValue("max", Integer.MAX_VALUE) < value)
throw new ConditionFailedException(MessageKeys.PLEASE_SPECIFY_AT_MOST, "{max}", String.valueOf(c.getConfigValue("max", Integer.MAX_VALUE)));
});
}
Aggregations