mirror of
https://github.com/darksaid98/TownyChat.git
synced 2026-12-02 22:23:18 +00:00
Merge pull request #37 from TownyAdvanced/hotfix/remove_old_meta_splitter
Hotfix/remove old meta splitter
This commit is contained in:
3 files changed
+61
-9
No files matched your search
@@ -401,4 +401,5 @@ v0.94:
|
||||
v0.95:
|
||||
- Regression: channels.yml not handling /townychat reload, bug began in 0.92.
|
||||
v0.96:
|
||||
- Display invalid subcommand message when /ch is used with an invalid subcommand.
|
||||
- Display invalid subcommand message when /ch is used with an invalid subcommand.
|
||||
- Replace the splitter for channels saved in metadata with the # symbol.
|
||||
@@ -317,7 +317,7 @@ public abstract class Channel {
|
||||
CustomDataField<?> cdf = resident.getMetadata(icdf.getKey());
|
||||
if (cdf instanceof StringDataField) {
|
||||
StringDataField sdf = (StringDataField) cdf;
|
||||
sdf.setValue(sdf.getValue().concat("\uFF0C " + this.getName()));
|
||||
sdf.setValue(sdf.getValue().concat("#" + this.getName()));
|
||||
TownyUniverse.getInstance().getDataSource().saveResident(resident);
|
||||
}
|
||||
|
||||
@@ -336,13 +336,13 @@ public abstract class Channel {
|
||||
if (cdf instanceof StringDataField) {
|
||||
StringDataField sdf = (StringDataField) cdf;
|
||||
String newValues = "";
|
||||
String[] values = sdf.getValue().split("\uFF0C ");
|
||||
String[] values = sdf.getValue().split("#");
|
||||
for (String chanName : values)
|
||||
if (!chanName.equalsIgnoreCase(this.getName()))
|
||||
if (newValues.isEmpty())
|
||||
newValues = chanName;
|
||||
else
|
||||
newValues += "\uFF0C " + chanName;
|
||||
newValues += "#" + chanName;
|
||||
|
||||
if (!newValues.isEmpty()) {
|
||||
sdf.setValue(newValues);
|
||||
@@ -361,7 +361,7 @@ public abstract class Channel {
|
||||
CustomDataField<?> cdf = resident.getMetadata(idf.getKey());
|
||||
if (cdf instanceof StringDataField) {
|
||||
StringDataField sdf = (StringDataField) cdf;
|
||||
String[] split = sdf.getValue().split("\uFF0C ");
|
||||
String[] split = sdf.getValue().split("#");
|
||||
for (String string : split)
|
||||
if (string.equalsIgnoreCase(this.getName()))
|
||||
return true;
|
||||
@@ -380,7 +380,7 @@ public abstract class Channel {
|
||||
CustomDataField<?> cdf = resident.getMetadata(icdf.getKey());
|
||||
if (cdf instanceof StringDataField) {
|
||||
StringDataField sdf = (StringDataField) cdf;
|
||||
sdf.setValue(sdf.getValue().concat("\uFF0C " + this.getName()));
|
||||
sdf.setValue(sdf.getValue().concat("#" + this.getName()));
|
||||
TownyUniverse.getInstance().getDataSource().saveResident(resident);
|
||||
}
|
||||
} else {
|
||||
@@ -398,13 +398,13 @@ public abstract class Channel {
|
||||
if (cdf instanceof StringDataField) {
|
||||
StringDataField sdf = (StringDataField) cdf;
|
||||
String newValues = "";
|
||||
String[] values = sdf.getValue().split("\uFF0C ");
|
||||
String[] values = sdf.getValue().split("#");
|
||||
for (String chanName : values)
|
||||
if (!chanName.equalsIgnoreCase(this.getName()))
|
||||
if (newValues.isEmpty())
|
||||
newValues = chanName;
|
||||
else
|
||||
newValues += "\uFF0C " + chanName;
|
||||
newValues += "#" + chanName;
|
||||
|
||||
if (!newValues.isEmpty()) {
|
||||
sdf.setValue(newValues);
|
||||
@@ -422,7 +422,7 @@ public abstract class Channel {
|
||||
CustomDataField<?> cdf = resident.getMetadata(idf.getKey());
|
||||
if (cdf instanceof StringDataField) {
|
||||
StringDataField sdf = (StringDataField) cdf;
|
||||
String[] split = sdf.getValue().split("\uFF0C ");
|
||||
String[] split = sdf.getValue().split("#");
|
||||
for (String string : split)
|
||||
if (string.equalsIgnoreCase(this.getName()))
|
||||
return true;
|
||||
|
||||
@@ -7,10 +7,13 @@ import com.palmergames.bukkit.TownyChat.channels.Channel;
|
||||
import com.palmergames.bukkit.TownyChat.channels.channelTypes;
|
||||
import com.palmergames.bukkit.TownyChat.config.ChatSettings;
|
||||
import com.palmergames.bukkit.towny.Towny;
|
||||
import com.palmergames.bukkit.towny.TownyAPI;
|
||||
import com.palmergames.bukkit.towny.TownyMessaging;
|
||||
import com.palmergames.bukkit.towny.exceptions.TownyException;
|
||||
import com.palmergames.bukkit.towny.object.Resident;
|
||||
import com.palmergames.bukkit.towny.object.Translatable;
|
||||
import com.palmergames.bukkit.towny.object.metadata.StringDataField;
|
||||
import com.palmergames.bukkit.towny.utils.MetaDataUtil;
|
||||
import com.palmergames.bukkit.towny.TownyUniverse;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
@@ -42,6 +45,8 @@ public class TownyChatPlayerListener implements Listener {
|
||||
}
|
||||
|
||||
private void loginPlayer(Player player) {
|
||||
checkPlayerForOldMeta(player);
|
||||
|
||||
refreshPlayerChannels(player);
|
||||
|
||||
Channel channel = plugin.getChannelsHandler().getDefaultChannel();
|
||||
@@ -218,4 +223,50 @@ public class TownyChatPlayerListener implements Listener {
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
// From TownyChat 0.84-0.95 the symbol used to separate the channels in the meta
|
||||
// was not good for non-unicode-using mysql servers.
|
||||
private void checkPlayerForOldMeta(Player player) {
|
||||
Resident resident = TownyAPI.getInstance().getResident(player);
|
||||
if (resident != null && playerHasTCMeta(resident))
|
||||
checkIfMetaContainsOldSplitter(resident);
|
||||
}
|
||||
|
||||
private boolean playerHasTCMeta(Resident resident) {
|
||||
StringDataField icsdf = new StringDataField("townychat_ignoredChannels", "", "Ignored TownyChat Channels");
|
||||
StringDataField socsdf = new StringDataField("townychat_soundOffChannels", "", "TownyChat Channels with Sound Toggle Off");
|
||||
return MetaDataUtil.hasMeta(resident, icsdf) || MetaDataUtil.hasMeta(resident, socsdf);
|
||||
}
|
||||
|
||||
private void checkIfMetaContainsOldSplitter(Resident resident) {
|
||||
StringDataField icsdf = new StringDataField("townychat_ignoredChannels", "", "Ignored TownyChat Channels");
|
||||
if (MetaDataUtil.hasMeta(resident, icsdf)) {
|
||||
String meta = MetaDataUtil.getString(resident, icsdf);
|
||||
if (meta.contains("\uFF0c ")) {
|
||||
meta = replaceSymbol(meta);
|
||||
meta = meta.replaceAll(" ", "");
|
||||
MetaDataUtil.setString(resident, icsdf, meta, true);
|
||||
}
|
||||
}
|
||||
StringDataField socsdf = new StringDataField("townychat_soundOffChannels", "", "TownyChat Channels with Sound Toggle Off");
|
||||
if (MetaDataUtil.hasMeta(resident, socsdf)) {
|
||||
String meta = MetaDataUtil.getString(resident, socsdf);
|
||||
if (meta.contains("\uFF0c ")) {
|
||||
meta = replaceSymbol(meta);
|
||||
meta = meta.replaceAll(" ", "");
|
||||
MetaDataUtil.setString(resident, socsdf, meta, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private String replaceSymbol(String meta) {
|
||||
char[] charray = meta.toCharArray();
|
||||
for (int i = 0; i < meta.length(); i++) {
|
||||
char n = meta.charAt(i);
|
||||
if (n == '\uFF0c')
|
||||
charray[i] = '#';
|
||||
}
|
||||
return new String(charray);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user