Add lore parsing for \n, change version to v6.1

This commit is contained in:
Esophose 2018-12-03 02:21:11 -07:00
parent c71bd75b53
commit a95aaa52d2
7 changed files with 39 additions and 6 deletions

View file

@ -2,7 +2,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.esophose.playerparticles</groupId>
<artifactId>PlayerParticles</artifactId>
<version>6.0</version>
<version>6.1</version>
<name>PlayerParticles</name>
<url>https://github.com/Esophose/PlayerParticles</url>
<description>Display particles around your player using customized styles and data!</description>

View file

@ -39,6 +39,8 @@ public class DataUpdater {
updateFrom_legacy_to_current();
} else if (configVersion == 5.3) {
updateFrom_5_3_to_current();
} else if (configVersion == 6.0) {
PlayerParticles.getPlugin().getLogger().warning("Found nothing to update.");
}
PlayerParticles.getPlugin().getLogger().warning("Finished updating SQLite/MySQL data from " + (configVersion < 5.3 ? "a legacy version" : "v" + configVersion) + " to v" + PlayerParticles.getPlugin().getDescription().getVersion());

View file

@ -1,7 +1,9 @@
package com.esophose.playerparticles.gui;
import java.util.Arrays;
import java.util.ArrayList;
import java.util.List;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.inventory.ItemFlag;
import org.bukkit.inventory.ItemStack;
@ -112,7 +114,7 @@ public class GuiActionButton {
ItemMeta itemMeta = itemStack.getItemMeta();
itemMeta.setDisplayName(this.name);
itemMeta.setLore(Arrays.asList(this.lore));
itemMeta.setLore(parseLore(this.lore));
itemMeta.addItemFlags(ItemFlag.HIDE_ATTRIBUTES, ItemFlag.HIDE_POTION_EFFECTS);
itemStack.setItemMeta(itemMeta);
@ -147,6 +149,34 @@ public class GuiActionButton {
return this.icons != null ? this.icons.length > 1 : this.colors.length > 1;
}
/**
* Builds lore from a list of Strings
* Parses \n as a new lore line
* Ignores empty lore lines
*
* @param lore The lines of lore
* @return A parsed list of lore text
*/
private List<String> parseLore(String... lore) {
List<String> parsedLore = new ArrayList<String>();
for (String line : lore) {
// Try to maintain the color going to the next line if it's split
// If there is no color, just ignore it
String lineColor = "";
if (line.length() >= 2 && line.charAt(0) == ChatColor.COLOR_CHAR) {
lineColor = line.substring(0, 2);
}
// Split the lore along \n onto a new line if any exist
String[] splitLines = line.split("\\\\n");
for (String parsedLine : splitLines) {
if (ChatColor.stripColor(parsedLine).isEmpty()) continue;
parsedLore.add(lineColor + parsedLine);
}
}
return parsedLore;
}
/**
* Allows button click callbacks as parameters
*/

View file

@ -97,7 +97,7 @@ public class GuiInventoryDefault extends GuiInventory {
callbacks.add(() -> GuiHandler.transition(new GuiInventoryEditEffect(pplayer, editingParticle, callbacks, 1)));
callbacks.add(() -> {
ParticleGroup group = pplayer.getActiveParticleGroup();
if (!group.getParticles().isEmpty()) {
if (canEditPrimaryStyleAndData) {
for (ParticlePair particle : group.getParticles()) {
if (particle.getId() == editingParticle.getId()) {
particle.setEffect(editingParticle.getEffect());

View file

@ -13,7 +13,7 @@
# This value is the version of the plugin that last modified the config file
# Changing this value manually will likely result in data loss and errors!
# Do not change this manually unless specifically told to by the plugin author
version: 6.0
version: 6.1
# Check for new versions of the plugin
# Default: true

View file

@ -3,6 +3,7 @@
# Important Notes: #
# * You can use the & symbol to color the messages #
# * {#} Will be replaced with whatever that message requires #
# * \n Will split the lore line in the #GUI section #
# * Do NOT use the apostrophe character in any message! ( ' ) #
# * PLEASE MAKE YOUR OWN .lang FILE IF YOU WANT CUSTOM MESSAGES! #
# * This file will be overridden almost every plugin update! #

View file

@ -1,6 +1,6 @@
name: PlayerParticles
main: com.esophose.playerparticles.PlayerParticles
version: 6.0
version: 6.1
api-version: 1.13
description: Display particles around your player using customized styles and data!
author: Esophose