use of dev.rosewood.rosegarden.utils.StringPlaceholders in project RoseGarden by Rosewood-Development.
the class EnumArgumentHandler method handleInternal.
@Override
protected T handleInternal(RoseCommandArgumentInfo argumentInfo, ArgumentParser argumentParser) {
String input = argumentParser.next();
T[] enumConstants = this.getHandledType().getEnumConstants();
Optional<T> value = Stream.of(enumConstants).filter(x -> x.name().equalsIgnoreCase(input)).findFirst();
if (!value.isPresent()) {
String messageKey;
StringPlaceholders placeholders = StringPlaceholders.builder("enum", this.handledType.getSimpleName()).addPlaceholder("input", input).addPlaceholder("types", Stream.of(enumConstants).map(x -> x.name().toLowerCase()).collect(Collectors.joining(", "))).build();
if (enumConstants.length <= 10) {
messageKey = "argument-handler-enum-list";
} else {
messageKey = "argument-handler-enum";
}
throw new HandledArgumentException(messageKey, placeholders);
}
return value.get();
}
use of dev.rosewood.rosegarden.utils.StringPlaceholders in project RoseStacker by Rosewood-Development.
the class ItemUtils method getSpawnerAsStackedItemStack.
public static ItemStack getSpawnerAsStackedItemStack(EntityType entityType, int amount) {
ItemStack itemStack = new ItemStack(Material.SPAWNER);
ItemMeta itemMeta = itemStack.getItemMeta();
if (itemMeta == null)
return itemStack;
SpawnerStackSettings stackSettings = RoseStacker.getInstance().getManager(StackSettingManager.class).getSpawnerStackSettings(entityType);
StringPlaceholders placeholders = StringPlaceholders.builder("amount", amount).addPlaceholder("name", stackSettings.getDisplayName()).build();
String displayString;
if (amount == 1) {
displayString = RoseStacker.getInstance().getManager(LocaleManager.class).getLocaleMessage("spawner-stack-display-single", placeholders);
} else {
displayString = RoseStacker.getInstance().getManager(LocaleManager.class).getLocaleMessage("spawner-stack-display", placeholders);
}
itemMeta.setDisplayName(displayString);
// Set the lore, if defined
List<String> lore = RoseStacker.getInstance().getManager(LocaleManager.class).getLocaleMessages("stack-item-lore-spawner", placeholders);
if (!lore.isEmpty())
itemMeta.setLore(lore);
// Set the spawned type directly onto the spawner item for hopeful compatibility with other plugins
BlockStateMeta blockStateMeta = (BlockStateMeta) itemMeta;
CreatureSpawner creatureSpawner = (CreatureSpawner) blockStateMeta.getBlockState();
creatureSpawner.setSpawnedType(entityType);
blockStateMeta.setBlockState(creatureSpawner);
itemStack.setItemMeta(itemMeta);
// Set stack size and spawned entity type
NMSHandler nmsHandler = NMSAdapter.getHandler();
itemStack = nmsHandler.setItemStackNBT(itemStack, "StackSize", amount);
itemStack = nmsHandler.setItemStackNBT(itemStack, "EntityType", entityType.name());
return itemStack;
}
use of dev.rosewood.rosegarden.utils.StringPlaceholders in project RoseStacker by Rosewood-Development.
the class ItemUtils method getEntityAsStackedItemStack.
public static ItemStack getEntityAsStackedItemStack(EntityType entityType, int amount) {
EntityStackSettings stackSettings = RoseStacker.getInstance().getManager(StackSettingManager.class).getEntityStackSettings(entityType);
Material spawnEggMaterial = stackSettings.getEntityTypeData().getSpawnEggMaterial();
if (spawnEggMaterial == null)
return null;
ItemStack itemStack = new ItemStack(spawnEggMaterial);
if (amount == 1)
return itemStack;
ItemMeta itemMeta = itemStack.getItemMeta();
if (itemMeta == null)
return itemStack;
StringPlaceholders placeholders = StringPlaceholders.builder("amount", amount).addPlaceholder("name", stackSettings.getDisplayName()).build();
String displayString = RoseStacker.getInstance().getManager(LocaleManager.class).getLocaleMessage("entity-stack-display-spawn-egg", placeholders);
itemMeta.setDisplayName(displayString);
// Set the lore, if defined
List<String> lore = RoseStacker.getInstance().getManager(LocaleManager.class).getLocaleMessages("stack-item-lore-entity", placeholders);
if (!lore.isEmpty())
itemMeta.setLore(lore);
itemStack.setItemMeta(itemMeta);
// Set stack size
NMSHandler nmsHandler = NMSAdapter.getHandler();
itemStack = nmsHandler.setItemStackNBT(itemStack, "StackSize", amount);
return itemStack;
}
use of dev.rosewood.rosegarden.utils.StringPlaceholders in project RoseStacker by Rosewood-Development.
the class ItemUtils method getBlockAsStackedItemStack.
public static ItemStack getBlockAsStackedItemStack(Material material, int amount) {
ItemStack itemStack = new ItemStack(material);
if (amount == 1)
return itemStack;
ItemMeta itemMeta = itemStack.getItemMeta();
if (itemMeta == null)
return itemStack;
BlockStackSettings stackSettings = RoseStacker.getInstance().getManager(StackSettingManager.class).getBlockStackSettings(material);
StringPlaceholders placeholders = StringPlaceholders.builder("amount", amount).addPlaceholder("name", stackSettings.getDisplayName()).build();
String displayString = RoseStacker.getInstance().getManager(LocaleManager.class).getLocaleMessage("block-stack-display", placeholders);
itemMeta.setDisplayName(displayString);
// Set the lore, if defined
List<String> lore = RoseStacker.getInstance().getManager(LocaleManager.class).getLocaleMessages("stack-item-lore-block", placeholders);
if (!lore.isEmpty())
itemMeta.setLore(lore);
itemStack.setItemMeta(itemMeta);
// Set stack size
NMSHandler nmsHandler = NMSAdapter.getHandler();
itemStack = nmsHandler.setItemStackNBT(itemStack, "StackSize", amount);
return itemStack;
}
use of dev.rosewood.rosegarden.utils.StringPlaceholders in project RoseGarden by Rosewood-Development.
the class PluginUpdateManager method onPlayerJoin.
/**
* Called when a player joins and notifies ops if an update is available
*
* @param event The join event
*/
@EventHandler
public void onPlayerJoin(PlayerJoinEvent event) {
Player player = event.getPlayer();
if (this.updateVersion == null || !player.isOp())
return;
String website = this.rosePlugin.getDescription().getWebsite();
String updateMessage = "&eAn update for <g:#8A2387:#E94057:#F27121>" + this.rosePlugin.getName() + " &e(&bv%new%&e) is available! You are running &bv%current%&e." + (website != null ? " " + website : "");
StringPlaceholders placeholders = StringPlaceholders.builder("new", this.updateVersion).addPlaceholder("current", this.rosePlugin.getDescription().getVersion()).build();
RoseGardenUtils.sendMessage(player, updateMessage, placeholders);
}
Aggregations