Nickname impr., Towny spy, RP channel

- Added nickname cache update on nick change for mentions
- Added support for Towny spy (again)
- Removed RPMode and added RP channel
This commit is contained in:
Norbi Peti 2017-08-27 23:35:46 +02:00
parent 91c22e650b
commit 2ab6a5f4eb
7 changed files with 36 additions and 47 deletions

View file

@ -42,7 +42,6 @@ public class ChatPlayer extends TBMCPlayerBase {
return data(false);
}
public boolean RPMode = true;
public Location SavedLocation;
public boolean Working;
// public int Tables = 10;

View file

@ -2,6 +2,7 @@ package buttondevteam.chat;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.regex.Pattern;
@ -115,7 +116,7 @@ public class ChatProcessing {
}).build());
}
pingedconsole = false; // Will set it to true onmatch (static constructor)
final String channelidentifier = getChannelID(channel, sender, mp);
final String channelidentifier = getChannelID(channel, sender);
TellrawPart json = createTellraw(sender, message, player, mp, channelidentifier);
long combinetime = System.nanoTime();
@ -148,10 +149,18 @@ public class ChatProcessing {
score = e.getMCScore(sender);
if (score < 0) // Never send messages to score below 0
sender.sendMessage("§cYou don't have permission to send this message or something went wrong");
else
else {
PluginMain.Instance.getServer().dispatchCommand(PluginMain.Console,
String.format("tellraw @a[score_%s=%d,score_%s_min=%d] %s", channel.ID, score, channel.ID,
score, jsonstr));
if (e.getChannel().ID.equals(PluginMain.TownChat.ID)
|| e.getChannel().ID.equals(PluginMain.NationChat.ID)) {
((List<TellrawPart>) json.getExtra()).add(0, new TellrawPart("[SPY]"));
jsonstr = toJson(json);
Bukkit.getServer().dispatchCommand(PluginMain.Console, String.format(
"tellraw @a[score_%s=1000,score_%s_min=1000 %s", channel.ID, channel.ID, jsonstr));
}
}
} else
PluginMain.Instance.getServer().dispatchCommand(PluginMain.Console,
String.format("tellraw @a %s", jsonstr));
@ -235,9 +244,9 @@ public class ChatProcessing {
return json;
}
static String getChannelID(Channel channel, CommandSender sender, ChatPlayer mp) {
static String getChannelID(Channel channel, CommandSender sender) {
final String channelidentifier = ("[" + (sender instanceof IDiscordSender ? "d|" : "") + channel.DisplayName)
+ "]" + (mp != null && !mp.RPMode ? "[OOC]" : "");
+ "]";
return channelidentifier;
}

View file

@ -23,7 +23,6 @@ import buttondevteam.lib.chat.Color;
import buttondevteam.lib.chat.TBMCChatAPI;
import buttondevteam.lib.chat.Channel.RecipientTestResult;
import buttondevteam.lib.player.TBMCPlayerBase;
import com.earth2me.essentials.Essentials;
import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
@ -63,6 +62,7 @@ public class PluginMain extends JavaPlugin { // Translated to Java: 2015.07.15.
public static Channel TownChat;
public static Channel NationChat;
public static Channel RPChannel;
/**
* <p>
@ -93,6 +93,11 @@ public class PluginMain extends JavaPlugin { // Translated to Java: 2015.07.15.
TownChat = new Channel("§3TC§f", Color.DarkAqua, "tc", s -> checkTownNationChat(s, false)));
TBMCChatAPI.RegisterChatChannel(
NationChat = new Channel("§6NC§f", Color.Gold, "nc", s -> checkTownNationChat(s, true)));
TBMCChatAPI.RegisterChatChannel(RPChannel = new Channel("§7RP§f", Color.Gray, "rp", Channel.noScoreResult(s -> {
if (s instanceof ConsoleCommandSender)
return true;
return true; // TODO: Allow hiding it
}, "You need to show the RP chat in order to speak in it.")));
setupChat();
setupEconomy();
@ -324,10 +329,18 @@ public class PluginMain extends JavaPlugin { // Translated to Java: 2015.07.15.
private static RecipientTestResult checkTownNationChat(CommandSender sender, boolean nationchat) {
if (!(sender instanceof Player))
return new RecipientTestResult("§cYou are not a player!");
Resident resident = PluginMain.TU.getResidentMap().get(sender.getName().toLowerCase());
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
result = new RecipientTestResult(1000); // There won't be more than a thousand towns/nations probably
return result;
}
private static RecipientTestResult checkTownNationChatInternal(CommandSender sender, boolean nationchat,
Resident resident) {
try {
Resident resident = PluginMain.TU.getResidentMap().get(sender.getName().toLowerCase());
if (resident != null && resident.getModes().contains("spy"))
return null;
return new RecipientTestResult(1000); // There won't be more than a thousand towns/nations probably
/*
* p.sendMessage(String.format("[SPY-%s] - %s: %s", channel.DisplayName, ((Player) sender).getDisplayName(), message));
*/

View file

@ -1,36 +0,0 @@
package buttondevteam.chat.commands;
import org.bukkit.entity.Player;
import buttondevteam.chat.ChatPlayer;
import buttondevteam.lib.chat.CommandClass;
import buttondevteam.lib.chat.PlayerCommandBase;
import buttondevteam.lib.player.TBMCPlayer;
@CommandClass(modOnly = false)
public final class OOCCommand extends PlayerCommandBase {
@Override
public String[] GetHelpText(String alias) {
return new String[] { "§6---- Out-of-character message ----",
"This command will put a [OCC] tag before your message indicating that you are talking out of character",
"Usage: /" + alias + " <message>" };
}
@Override
public boolean OnCommand(Player player, String alias, String[] args) {
if (args.length == 0) {
return false;
} else {
final ChatPlayer cp = TBMCPlayer.getPlayer(player.getUniqueId(), ChatPlayer.class);
cp.RPMode = false;
String message = "";
for (String arg : args)
message += arg + " ";
player.chat(message.substring(0, message.length() - 1));
cp.RPMode = true;
}
return true;
}
}

View file

@ -86,8 +86,6 @@ public class PlayerJoinLeaveListener implements Listener {
nwithoutformatting = p.getName();
PlayerListener.nicknames.put(nwithoutformatting, p.getUniqueId());
cp.RPMode = true;
cp.FlairUpdate();
if (cp.ChatOnly || p.getGameMode().equals(GameMode.SPECTATOR)) {

View file

@ -21,6 +21,7 @@ import buttondevteam.lib.chat.ChatChannelRegisterEvent;
import buttondevteam.lib.chat.TBMCChatAPI;
import buttondevteam.lib.player.TBMCPlayer;
import buttondevteam.lib.player.TBMCPlayerGetInfoEvent;
import net.ess3.api.events.NickChangeEvent;
import buttondevteam.lib.player.ChromaGamerBase.InfoTarget;
import com.google.common.collect.BiMap;
@ -292,4 +293,9 @@ public class PlayerListener implements Listener {
if (e.getChannel().filteranderrormsg != null && PluginMain.SB.getObjective(e.getChannel().ID) == null) // Not global chat and doesn't exist yet
PluginMain.SB.registerNewObjective(e.getChannel().ID, "dummy");
}
@EventHandler
public void onNickChange(NickChangeEvent e) {
nicknames.inverse().put(e.getAffected().getBase().getUniqueId(), e.getValue());
}
}

View file

@ -63,7 +63,7 @@ public class ChatFormatIT extends TestCase {
@Test
public void testMessage() {
ArrayList<ChatFormatter> cfs = ChatProcessing.addFormatters(Color.White);
final String chid = ChatProcessing.getChannelID(Channel.GlobalChat, sender, null);
final String chid = ChatProcessing.getChannelID(Channel.GlobalChat, sender);
final TellrawPart tp = ChatProcessing.createTellraw(sender, message, null, null, chid);
ChatFormatter.Combine(cfs, message, tp);
System.out.println("Testing: " + message);