Fix the problem with colour signs

Apparently sign colour plugins do not consider &0 to be a colour that
needs to be removed if there is no other code like that on the sign,
thus ChestShop did not register the initial SignChangeEvent, however
after the server software removes the redundant colour from the sign, it
appeared and worked just like a ChestShop one. This commit "fixes" this
by stripping the colour codes from the sign before it is created.
This commit is contained in:
Andrzej Pomirski 2015-05-31 18:27:11 +02:00
parent 44d801db46
commit 99959f2ca0
2 changed files with 30 additions and 1 deletions

View File

@ -2,6 +2,10 @@ package com.Acrobot.Breeze.Utils;
import com.google.common.base.Joiner;
import org.apache.commons.lang.WordUtils;
import org.bukkit.ChatColor;
import java.util.ArrayList;
import java.util.List;
/**
* @author Acrobot
@ -51,4 +55,28 @@ public class StringUtil {
public static String joinArray(Iterable<?> array) {
return Joiner.on(' ').join(array);
}
/**
* Strips colour codes from a string
* @param string String to strip
* @return Stripped string
*/
public static String stripColourCodes(String string) {
return ChatColor.stripColor(string);
}
/**
* Stips colour codes from an array of strings
* @param strings Strings to strip the codes from
* @return Stripped strings
*/
public static String[] stripColourCodes(String[] strings) {
List<String> output = new ArrayList<String>();
for (String string : strings) {
output.add(stripColourCodes(string));
}
return output.toArray(new String[output.size()]);
}
}

View File

@ -1,6 +1,7 @@
package com.Acrobot.ChestShop.Listeners.Block;
import com.Acrobot.Breeze.Utils.BlockUtil;
import com.Acrobot.Breeze.Utils.StringUtil;
import com.Acrobot.ChestShop.ChestShop;
import com.Acrobot.ChestShop.Events.PreShopCreationEvent;
import com.Acrobot.ChestShop.Events.ShopCreatedEvent;
@ -20,7 +21,7 @@ public class SignCreate implements Listener {
@EventHandler
public static void onSignChange(SignChangeEvent event) {
Block signBlock = event.getBlock();
String[] line = event.getLines();
String[] line = StringUtil.stripColourCodes(event.getLines());
if (!BlockUtil.isSign(signBlock)) {
return;