Fix color of ShowItem insert bleeding into message

This commit is contained in:
Phoenix616 2018-10-23 19:02:09 +01:00
parent 470f9d8d99
commit b5f77d67b5

View File

@ -6,6 +6,7 @@ import com.Acrobot.ChestShop.Configuration.Properties;
import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap;
import de.themoep.ShowItem.api.ShowItem; import de.themoep.ShowItem.api.ShowItem;
import info.somethingodd.OddItem.OddItem; import info.somethingodd.OddItem.OddItem;
import org.bukkit.ChatColor;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
@ -493,9 +494,14 @@ public class MaterialUtil {
String joinedItemJson = itemJson.stream().collect(Collectors.joining("," + new JSONObject(ImmutableMap.of("text", " ")).toJSONString() + ", ")); String joinedItemJson = itemJson.stream().collect(Collectors.joining("," + new JSONObject(ImmutableMap.of("text", " ")).toJSONString() + ", "));
String messageJsonString = Arrays.stream(message.split("%item")) String prevColor = "";
.map(s -> new JSONObject(ImmutableMap.of("text", s)).toJSONString()) List<String> parts = new ArrayList<>();
.collect(Collectors.joining("," + joinedItemJson + ",")); for (String s : message.split("%item")) {
parts.add(new JSONObject(ImmutableMap.of("text", prevColor + s)).toJSONString());
prevColor = ChatColor.getLastColors(s);
}
String messageJsonString = String.join("," + joinedItemJson + ",", parts);
while (messageJsonString.startsWith(",")) { while (messageJsonString.startsWith(",")) {
messageJsonString = messageJsonString.substring(1); messageJsonString = messageJsonString.substring(1);