Update 2 - Bugfixes (town colors) & fromcmd #80
8 changed files with 78 additions and 24 deletions
|
@ -221,7 +221,7 @@ public class ChatProcessing {
|
||||||
}
|
}
|
||||||
|
|
||||||
static String getChannelID(Channel channel, CommandSender sender) {
|
static String getChannelID(Channel channel, CommandSender sender) {
|
||||||
return ("[" + (sender instanceof IDiscordSender ? "§bD§r|" : "") + channel.DisplayName)
|
return ("[" + (sender instanceof IDiscordSender ? "§8D§r|" : "") + channel.DisplayName)
|
||||||
+ "]";
|
+ "]";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -3,6 +3,7 @@ package buttondevteam.chat;
|
||||||
import buttondevteam.chat.commands.YeehawCommand;
|
import buttondevteam.chat.commands.YeehawCommand;
|
||||||
import buttondevteam.chat.commands.ucmds.TownColorCommand;
|
import buttondevteam.chat.commands.ucmds.TownColorCommand;
|
||||||
import buttondevteam.chat.listener.PlayerListener;
|
import buttondevteam.chat.listener.PlayerListener;
|
||||||
|
import buttondevteam.chat.listener.TownyListener;
|
||||||
import buttondevteam.lib.TBMCCoreAPI;
|
import buttondevteam.lib.TBMCCoreAPI;
|
||||||
import buttondevteam.lib.chat.Channel;
|
import buttondevteam.lib.chat.Channel;
|
||||||
import buttondevteam.lib.chat.Channel.RecipientTestResult;
|
import buttondevteam.lib.chat.Channel.RecipientTestResult;
|
||||||
|
@ -80,6 +81,7 @@ public class PluginMain extends JavaPlugin { // Translated to Java: 2015.07.15.
|
||||||
Instance = this;
|
Instance = this;
|
||||||
|
|
||||||
TBMCCoreAPI.RegisterEventsForExceptions(new PlayerListener(), this);
|
TBMCCoreAPI.RegisterEventsForExceptions(new PlayerListener(), this);
|
||||||
|
TBMCCoreAPI.RegisterEventsForExceptions(new TownyListener(), this);
|
||||||
TBMCChatAPI.AddCommands(this, YeehawCommand.class);
|
TBMCChatAPI.AddCommands(this, YeehawCommand.class);
|
||||||
Console = this.getServer().getConsoleSender();
|
Console = this.getServer().getConsoleSender();
|
||||||
LoadFiles();
|
LoadFiles();
|
||||||
|
@ -373,7 +375,7 @@ public class PluginMain extends JavaPlugin { // Translated to Java: 2015.07.15.
|
||||||
Resident resident = PluginMain.TU.getResidentMap().get(sender.getName().toLowerCase());
|
Resident resident = PluginMain.TU.getResidentMap().get(sender.getName().toLowerCase());
|
||||||
RecipientTestResult result = checkTownNationChatInternal(sender, nationchat, resident);
|
RecipientTestResult result = checkTownNationChatInternal(sender, nationchat, resident);
|
||||||
if (result.errormessage != null && resident != null && resident.getModes().contains("spy")) // Only use spy if they wouldn't see it
|
if (result.errormessage != null && resident != null && resident.getModes().contains("spy")) // Only use spy if they wouldn't see it
|
||||||
result = new RecipientTestResult(1000); // There won't be more than a thousand towns/nations probably
|
result = new RecipientTestResult(1000, "allspies"); // There won't be more than a thousand towns/nations probably
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -407,7 +409,7 @@ public class PluginMain extends JavaPlugin { // Translated to Java: 2015.07.15.
|
||||||
index = PluginMain.Towns.size() - 1;
|
index = PluginMain.Towns.size() - 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return new RecipientTestResult(index);
|
return new RecipientTestResult(index, nationchat ? nation.getName() : town.getName());
|
||||||
} catch (NotRegisteredException e) {
|
} catch (NotRegisteredException e) {
|
||||||
return new RecipientTestResult("You (probably) aren't knwon by Towny! (Not in a town)");
|
return new RecipientTestResult("You (probably) aren't knwon by Towny! (Not in a town)");
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,8 +1,5 @@
|
||||||
package buttondevteam.chat.commands.appendtext;
|
package buttondevteam.chat.commands.appendtext;
|
||||||
|
|
||||||
import org.bukkit.command.CommandSender;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
|
|
||||||
import buttondevteam.chat.ChatPlayer;
|
import buttondevteam.chat.ChatPlayer;
|
||||||
import buttondevteam.chat.listener.PlayerListener;
|
import buttondevteam.chat.listener.PlayerListener;
|
||||||
import buttondevteam.lib.chat.Channel;
|
import buttondevteam.lib.chat.Channel;
|
||||||
|
@ -10,6 +7,8 @@ import buttondevteam.lib.chat.CommandClass;
|
||||||
import buttondevteam.lib.chat.TBMCChatAPI;
|
import buttondevteam.lib.chat.TBMCChatAPI;
|
||||||
import buttondevteam.lib.chat.TBMCCommandBase;
|
import buttondevteam.lib.chat.TBMCCommandBase;
|
||||||
import buttondevteam.lib.player.TBMCPlayer;
|
import buttondevteam.lib.player.TBMCPlayer;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
@CommandClass(modOnly = false, excludeFromPath = true)
|
@CommandClass(modOnly = false, excludeFromPath = true)
|
||||||
public abstract class AppendTextCommandBase extends TBMCCommandBase {
|
public abstract class AppendTextCommandBase extends TBMCCommandBase {
|
||||||
|
@ -26,7 +25,7 @@ public abstract class AppendTextCommandBase extends TBMCCommandBase {
|
||||||
if (sender instanceof Player)
|
if (sender instanceof Player)
|
||||||
TBMCChatAPI.SendChatMessage(
|
TBMCChatAPI.SendChatMessage(
|
||||||
TBMCPlayer.getPlayer(((Player) sender).getUniqueId(), ChatPlayer.class).CurrentChannel, sender,
|
TBMCPlayer.getPlayer(((Player) sender).getUniqueId(), ChatPlayer.class).CurrentChannel, sender,
|
||||||
msg);
|
msg, true);
|
||||||
else if (sender.isOp())
|
else if (sender.isOp())
|
||||||
TBMCChatAPI.SendChatMessage(PlayerListener.ConsoleChannel, sender, msg);
|
TBMCChatAPI.SendChatMessage(PlayerListener.ConsoleChannel, sender, msg);
|
||||||
else
|
else
|
||||||
|
|
|
@ -45,14 +45,14 @@ public class NColorCommand extends UCommandBase {
|
||||||
}
|
}
|
||||||
if (args.length == 0)
|
if (args.length == 0)
|
||||||
return false;
|
return false;
|
||||||
final String name = ChatColor.stripColor(player.getDisplayName());
|
final String name = ChatColor.stripColor(player.getDisplayName()).replace("~", ""); //Remove ~
|
||||||
String arg = name.startsWith("~") ? "~" + args[0] : args[0]; //Add ~ for nicknames
|
String arg = args[0]; //Don't add ~ for nicknames
|
||||||
if (!arg.replace("|", "").replace(":", "").equalsIgnoreCase(name)) {
|
if (!arg.replace("|", "").replace(":", "").equalsIgnoreCase(name)) {
|
||||||
player.sendMessage("§cThe name you gave doesn't match your name. Make sure to use "
|
player.sendMessage("§cThe name you gave doesn't match your name. Make sure to use "
|
||||||
+ name + "§c with added vertical lines (|) or colons (:).");
|
+ name + "§c with added vertical lines (|) or colons (:).");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
String[] nameparts = arg.split("\\|");
|
String[] nameparts = arg.split("[|:]");
|
||||||
Color[] towncolors = PluginMain.TownColors.get(town.getName().toLowerCase());
|
Color[] towncolors = PluginMain.TownColors.get(town.getName().toLowerCase());
|
||||||
if (towncolors == null) {
|
if (towncolors == null) {
|
||||||
player.sendMessage("§cYour town doesn't have a color set. The town mayor can set it using /u towncolor.");
|
player.sendMessage("§cYour town doesn't have a color set. The town mayor can set it using /u towncolor.");
|
||||||
|
|
|
@ -132,6 +132,7 @@ 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
|
||||||
|
//System.out.println("ncl: "+Arrays.toString(ncl)+" - sum: "+Arrays.stream(ncl).sum()+" - name len: "+name.length());
|
||||||
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();
|
||||||
|
|
|
@ -172,7 +172,7 @@ public class PlayerListener implements Listener {
|
||||||
String name = e.getLastToken();
|
String name = e.getLastToken();
|
||||||
for (Entry<String, UUID> nicknamekv : nicknames.entrySet()) {
|
for (Entry<String, UUID> nicknamekv : nicknames.entrySet()) {
|
||||||
if (nicknamekv.getKey().startsWith(name.toLowerCase()))
|
if (nicknamekv.getKey().startsWith(name.toLowerCase()))
|
||||||
e.getTabCompletions().add(Bukkit.getPlayer(nicknamekv.getValue()).getName()); //Tabcomplete with the correct case
|
e.getTabCompletions().add(PluginMain.essentials.getUser(Bukkit.getPlayer(nicknamekv.getValue())).getNick(true)); //Tabcomplete with the correct case
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -293,11 +293,14 @@ public class PlayerListener implements Listener {
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onNickChange(NickChangeEvent e) {
|
public void onNickChange(NickChangeEvent e) {
|
||||||
nicknames.inverse().forcePut(e.getAffected().getBase().getUniqueId(), ChatColor.stripColor(e.getValue()).toLowerCase());
|
String nick = e.getValue();
|
||||||
//PlayerJoinLeaveListener.updatePlayerColors(e.getAffected().getBase()); //Won't fire this event again
|
if (nick == null)
|
||||||
|
nicknames.inverse().remove(e.getAffected().getBase().getUniqueId());
|
||||||
|
else
|
||||||
|
nicknames.inverse().forcePut(e.getAffected().getBase().getUniqueId(), ChatColor.stripColor(nick).toLowerCase());
|
||||||
|
|
||||||
Bukkit.getScheduler().runTaskLater(PluginMain.Instance, () -> {
|
Bukkit.getScheduler().runTaskLater(PluginMain.Instance, () -> {
|
||||||
PlayerJoinLeaveListener.updatePlayerColors(e.getAffected().getBase()); //TODO: Doesn't have effect
|
PlayerJoinLeaveListener.updatePlayerColors(e.getAffected().getBase()); //Won't fire this event again
|
||||||
}, 1);
|
}, 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
48
src/main/java/buttondevteam/chat/listener/TownyListener.java
Normal file
48
src/main/java/buttondevteam/chat/listener/TownyListener.java
Normal file
|
@ -0,0 +1,48 @@
|
||||||
|
package buttondevteam.chat.listener;
|
||||||
|
|
||||||
|
import buttondevteam.chat.PluginMain;
|
||||||
|
import com.earth2me.essentials.User;
|
||||||
|
import com.palmergames.bukkit.towny.event.*;
|
||||||
|
import lombok.val;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.ChatColor;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.event.EventHandler;
|
||||||
|
import org.bukkit.event.Listener;
|
||||||
|
|
||||||
|
public class TownyListener implements Listener {
|
||||||
|
@EventHandler
|
||||||
|
public void onTownRename(RenameTownEvent event) {
|
||||||
|
val clrs = PluginMain.TownColors.remove(event.getOldName().toLowerCase());
|
||||||
|
if (clrs != null)
|
||||||
|
PluginMain.TownColors.put(event.getTown().getName().toLowerCase(), clrs);
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler //Gets called on town load as well
|
||||||
|
public void onTownJoin(TownAddResidentEvent event) {
|
||||||
|
Player p = Bukkit.getPlayer(event.getResident().getName());
|
||||||
|
if (p != null)
|
||||||
|
PlayerJoinLeaveListener.updatePlayerColors(p);
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onTownLeave(TownRemoveResidentEvent event) {
|
||||||
|
Player p = Bukkit.getPlayer(event.getResident().getName());
|
||||||
|
if (p != null) {
|
||||||
|
User user = PluginMain.essentials.getUser(p);
|
||||||
|
user.setNickname(ChatColor.stripColor(user.getNick(true).replace("~", "")));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onTownDelete(DeleteTownEvent event) {
|
||||||
|
PluginMain.TownColors.remove(event.getTownName().toLowerCase());
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onTownCreate(NewTownEvent event) {
|
||||||
|
Player p = Bukkit.getPlayer(event.getTown().getMayor().getName());
|
||||||
|
if (p != null)
|
||||||
|
p.sendMessage("§6Use /u towncolor <color1> [color2] to set a color for the town.");
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,15 +1,5 @@
|
||||||
package buttondevteam.chat;
|
package buttondevteam.chat;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import org.bukkit.command.CommandSender;
|
|
||||||
import org.junit.Test;
|
|
||||||
import org.junit.runner.RunWith;
|
|
||||||
import org.mockito.Mockito;
|
|
||||||
|
|
||||||
import buttondevteam.chat.ObjectTestRunner.Objects;
|
import buttondevteam.chat.ObjectTestRunner.Objects;
|
||||||
import buttondevteam.chat.commands.ucmds.admin.DebugCommand;
|
import buttondevteam.chat.commands.ucmds.admin.DebugCommand;
|
||||||
import buttondevteam.chat.formatting.ChatFormatter;
|
import buttondevteam.chat.formatting.ChatFormatter;
|
||||||
|
@ -20,6 +10,16 @@ import buttondevteam.chat.formatting.TellrawPart;
|
||||||
import buttondevteam.core.TestPrepare;
|
import buttondevteam.core.TestPrepare;
|
||||||
import buttondevteam.lib.chat.Channel;
|
import buttondevteam.lib.chat.Channel;
|
||||||
import buttondevteam.lib.chat.Color;
|
import buttondevteam.lib.chat.Color;
|
||||||
|
import net.milkbowl.vault.permission.Permission;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.junit.runner.RunWith;
|
||||||
|
import org.mockito.Mockito;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
|
|
||||||
@RunWith(ObjectTestRunner.class)
|
@RunWith(ObjectTestRunner.class)
|
||||||
public class ChatFormatIT {
|
public class ChatFormatIT {
|
||||||
|
@ -28,6 +28,7 @@ public class ChatFormatIT {
|
||||||
TestPrepare.PrepareServer();
|
TestPrepare.PrepareServer();
|
||||||
final CommandSender sender = Mockito.mock(CommandSender.class);
|
final CommandSender sender = Mockito.mock(CommandSender.class);
|
||||||
DebugCommand.DebugMode = true;
|
DebugCommand.DebugMode = true;
|
||||||
|
PluginMain.permission = Mockito.mock(Permission.class);
|
||||||
|
|
||||||
List<Object> list = new ArrayList<Object>();
|
List<Object> list = new ArrayList<Object>();
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue