Chat fixes, town color fixes, some features #72
4 changed files with 19 additions and 11 deletions
2
pom.xml
2
pom.xml
|
@ -111,7 +111,7 @@
|
||||||
</repository>
|
</repository>
|
||||||
<repository>
|
<repository>
|
||||||
<id>Essentials</id>
|
<id>Essentials</id>
|
||||||
<url>http://repo.ess3.net/</url>
|
<url>http://repo.ess3.net/content/repositories/essrel/</url>
|
||||||
</repository>
|
</repository>
|
||||||
<repository>
|
<repository>
|
||||||
<id>Votifier</id>
|
<id>Votifier</id>
|
||||||
|
|
|
@ -9,6 +9,7 @@ import buttondevteam.lib.player.TBMCPlayerJoinEvent;
|
||||||
import buttondevteam.lib.player.TBMCPlayerLoadEvent;
|
import buttondevteam.lib.player.TBMCPlayerLoadEvent;
|
||||||
import buttondevteam.lib.player.TBMCPlayerSaveEvent;
|
import buttondevteam.lib.player.TBMCPlayerSaveEvent;
|
||||||
import com.earth2me.essentials.Essentials;
|
import com.earth2me.essentials.Essentials;
|
||||||
|
import com.earth2me.essentials.User;
|
||||||
import com.palmergames.bukkit.towny.exceptions.NotRegisteredException;
|
import com.palmergames.bukkit.towny.exceptions.NotRegisteredException;
|
||||||
import lombok.val;
|
import lombok.val;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
|
@ -88,9 +89,9 @@ public class PlayerJoinLeaveListener implements Listener {
|
||||||
nwithoutformatting = p.getName();
|
nwithoutformatting = p.getName();
|
||||||
PlayerListener.nicknames.put(nwithoutformatting, p.getUniqueId());
|
PlayerListener.nicknames.put(nwithoutformatting, p.getUniqueId());
|
||||||
|
|
||||||
Bukkit.getScheduler().runTask(PluginMain.Instance, () -> {
|
Bukkit.getScheduler().runTaskLater(PluginMain.Instance, () -> {
|
||||||
updatePlayerColors(p, cp); //TODO: Doesn't have effect
|
updatePlayerColors(p, cp); //TODO: Doesn't have effect
|
||||||
});
|
}, 5);
|
||||||
|
|
||||||
if (cp.ChatOnly || p.getGameMode().equals(GameMode.SPECTATOR)) {
|
if (cp.ChatOnly || p.getGameMode().equals(GameMode.SPECTATOR)) {
|
||||||
cp.ChatOnly = false;
|
cp.ChatOnly = false;
|
||||||
|
@ -108,8 +109,10 @@ public class PlayerJoinLeaveListener implements Listener {
|
||||||
UnlolCommand.Lastlol.values().removeIf(lld -> lld.getLolowner().equals(event.getPlayer()));
|
UnlolCommand.Lastlol.values().removeIf(lld -> lld.getLolowner().equals(event.getPlayer()));
|
||||||
}
|
}
|
||||||
|
|
||||||
private static String getPlayerDisplayName(Player player) {
|
private static String getPlayerNickname(Player player, User user) {
|
||||||
String nickname = PluginMain.essentials.getUser(player).getNick(true);
|
String nickname = user.getNick(true);
|
||||||
|
if (nickname.contains("~")) //StartsWith doesn't work because of color codes
|
||||||
|
nickname = nickname.replace("~", ""); //It gets stacked otherwise
|
||||||
val res = PluginMain.TU.getResidentMap().get(player.getName().toLowerCase());
|
val res = PluginMain.TU.getResidentMap().get(player.getName().toLowerCase());
|
||||||
if (res == null || !res.hasTown())
|
if (res == null || !res.hasTown())
|
||||||
return nickname;
|
return nickname;
|
||||||
|
@ -129,10 +132,6 @@ public class PlayerJoinLeaveListener implements Listener {
|
||||||
int[] ncl = nclar == null ? null : nclar.stream().mapToInt(Integer::intValue).toArray();
|
int[] ncl = nclar == null ? null : nclar.stream().mapToInt(Integer::intValue).toArray();
|
||||||
if (ncl != null && (Arrays.stream(ncl).sum() != name.length() || ncl.length != clrs.length))
|
if (ncl != null && (Arrays.stream(ncl).sum() != name.length() || ncl.length != clrs.length))
|
||||||
ncl = null; // Reset if name length changed
|
ncl = null; // Reset if name length changed
|
||||||
if (name.charAt(0) == '~') { // Ignore ~ in nicknames
|
|
||||||
prevlen.incrementAndGet();
|
|
||||||
ret.append("~");
|
|
||||||
}
|
|
||||||
for (int i = 0; i < clrs.length; i++)
|
for (int i = 0; i < clrs.length; i++)
|
||||||
ret.append(coloredNamePart.apply(ncl == null ? len : ncl[i], i));
|
ret.append(coloredNamePart.apply(ncl == null ? len : ncl[i], i));
|
||||||
return ret.toString();
|
return ret.toString();
|
||||||
|
@ -145,8 +144,10 @@ public class PlayerJoinLeaveListener implements Listener {
|
||||||
updatePlayerColors(player, ChatPlayer.getPlayer(player.getUniqueId(), ChatPlayer.class));
|
updatePlayerColors(player, ChatPlayer.getPlayer(player.getUniqueId(), ChatPlayer.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void updatePlayerColors(Player player, ChatPlayer cp) { //Probably at join
|
public static void updatePlayerColors(Player player, ChatPlayer cp) { //Probably at join - nop, nicknames
|
||||||
player.setDisplayName(getPlayerDisplayName(player));
|
User user = PluginMain.essentials.getUser(player);
|
||||||
|
user.setNickname(getPlayerNickname(player, user));
|
||||||
|
user.setDisplayNick(); //These won't fire the nick change event
|
||||||
cp.FlairUpdate(); //Update in list
|
cp.FlairUpdate(); //Update in list
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -292,5 +292,10 @@ public class PlayerListener implements Listener {
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onNickChange(NickChangeEvent e) {
|
public void onNickChange(NickChangeEvent e) {
|
||||||
nicknames.inverse().put(e.getAffected().getBase().getUniqueId(), e.getValue());
|
nicknames.inverse().put(e.getAffected().getBase().getUniqueId(), e.getValue());
|
||||||
|
//PlayerJoinLeaveListener.updatePlayerColors(e.getAffected().getBase()); //Won't fire this event again
|
||||||
|
|
||||||
|
Bukkit.getScheduler().runTaskLater(PluginMain.Instance, () -> {
|
||||||
|
PlayerJoinLeaveListener.updatePlayerColors(e.getAffected().getBase()); //TODO: Doesn't have effect
|
||||||
|
}, 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,6 +28,8 @@ commands:
|
||||||
aliases: ww
|
aliases: ww
|
||||||
lenny:
|
lenny:
|
||||||
description: Lenny face.
|
description: Lenny face.
|
||||||
|
ftop:
|
||||||
|
description: Top respect.
|
||||||
author: NorbiPeti
|
author: NorbiPeti
|
||||||
depend:
|
depend:
|
||||||
- Essentials
|
- Essentials
|
||||||
|
|
Loading…
Reference in a new issue