More components, broadcasts #98
6 changed files with 25 additions and 25 deletions
|
@ -144,7 +144,7 @@ public class ChatProcessing {
|
||||||
}).build());
|
}).build());
|
||||||
}
|
}
|
||||||
pingedconsole = false; // Will set it to true onmatch (static constructor)
|
pingedconsole = false; // Will set it to true onmatch (static constructor)
|
||||||
final String channelidentifier = getChannelID(channel, sender, e.getOrigin());
|
final String channelidentifier = getChannelID(channel, e.getOrigin());
|
||||||
|
|
||||||
TellrawPart json = createTellraw(sender, message, player, mp, e.getUser(), channelidentifier, e.getOrigin());
|
TellrawPart json = createTellraw(sender, message, player, mp, e.getUser(), channelidentifier, e.getOrigin());
|
||||||
long combinetime = System.nanoTime();
|
long combinetime = System.nanoTime();
|
||||||
|
@ -238,7 +238,7 @@ public class ChatProcessing {
|
||||||
return player.getDisplayName();
|
return player.getDisplayName();
|
||||||
}
|
}
|
||||||
|
|
||||||
static String getChannelID(Channel channel, CommandSender sender, String origin) {
|
static String getChannelID(Channel channel, String origin) {
|
||||||
return ("[" + (MCORIGIN.equals(origin) ? "" : "§8" + origin.substring(0, 1) + "§r|") + channel.DisplayName().get())
|
return ("[" + (MCORIGIN.equals(origin) ? "" : "§8" + origin.substring(0, 1) + "§r|") + channel.DisplayName().get())
|
||||||
+ "]";
|
+ "]";
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,8 +7,8 @@ import buttondevteam.core.ComponentManager;
|
||||||
import buttondevteam.lib.architecture.Component;
|
import buttondevteam.lib.architecture.Component;
|
||||||
import buttondevteam.lib.player.TBMCPlayer;
|
import buttondevteam.lib.player.TBMCPlayer;
|
||||||
import buttondevteam.lib.player.TBMCPlayerJoinEvent;
|
import buttondevteam.lib.player.TBMCPlayerJoinEvent;
|
||||||
|
import lombok.val;
|
||||||
import org.bukkit.GameMode;
|
import org.bukkit.GameMode;
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
import org.bukkit.event.EventPriority;
|
import org.bukkit.event.EventPriority;
|
||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
|
@ -27,9 +27,10 @@ public class ChatOnlyComponent extends Component implements Listener {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void playerJoin(ChatPlayer cp, Player p) {
|
@EventHandler
|
||||||
if(!ComponentManager.isEnabled(ChatOnlyComponent.class))
|
public void playerJoin(TBMCPlayerJoinEvent event) {
|
||||||
return;
|
val p = event.getPlayer();
|
||||||
|
val cp = event.GetPlayer().asPluginPlayer(ChatPlayer.class);
|
||||||
if (cp.ChatOnly || p.getGameMode().equals(GameMode.SPECTATOR)) {
|
if (cp.ChatOnly || p.getGameMode().equals(GameMode.SPECTATOR)) {
|
||||||
cp.ChatOnly = false;
|
cp.ChatOnly = false;
|
||||||
p.setGameMode(GameMode.SURVIVAL);
|
p.setGameMode(GameMode.SURVIVAL);
|
||||||
|
|
|
@ -10,6 +10,7 @@ import buttondevteam.lib.architecture.Component;
|
||||||
import buttondevteam.lib.architecture.ComponentMetadata;
|
import buttondevteam.lib.architecture.ComponentMetadata;
|
||||||
import buttondevteam.lib.architecture.ConfigData;
|
import buttondevteam.lib.architecture.ConfigData;
|
||||||
import buttondevteam.lib.chat.Color;
|
import buttondevteam.lib.chat.Color;
|
||||||
|
import buttondevteam.lib.player.TBMCPlayerJoinEvent;
|
||||||
import com.earth2me.essentials.User;
|
import com.earth2me.essentials.User;
|
||||||
import com.palmergames.bukkit.towny.exceptions.NotRegisteredException;
|
import com.palmergames.bukkit.towny.exceptions.NotRegisteredException;
|
||||||
import com.palmergames.bukkit.towny.object.Nation;
|
import com.palmergames.bukkit.towny.object.Nation;
|
||||||
|
@ -20,6 +21,8 @@ import org.bukkit.ChatColor;
|
||||||
import org.bukkit.configuration.ConfigurationSection;
|
import org.bukkit.configuration.ConfigurationSection;
|
||||||
import org.bukkit.configuration.file.YamlConfiguration;
|
import org.bukkit.configuration.file.YamlConfiguration;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.event.EventHandler;
|
||||||
|
import org.bukkit.event.Listener;
|
||||||
import org.dynmap.towny.DTBridge;
|
import org.dynmap.towny.DTBridge;
|
||||||
import org.dynmap.towny.DynmapTownyPlugin;
|
import org.dynmap.towny.DynmapTownyPlugin;
|
||||||
|
|
||||||
|
@ -32,7 +35,7 @@ import java.util.function.Function;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
@ComponentMetadata(depends = TownyComponent.class)
|
@ComponentMetadata(depends = TownyComponent.class)
|
||||||
public class TownColorComponent extends Component {
|
public class TownColorComponent extends Component implements Listener {
|
||||||
/**
|
/**
|
||||||
* Names lowercased
|
* Names lowercased
|
||||||
*/
|
*/
|
||||||
|
@ -98,6 +101,7 @@ public class TownColorComponent extends Component {
|
||||||
registerCommand(new buttondevteam.chat.components.towncolors.admin.NationColorCommand());
|
registerCommand(new buttondevteam.chat.components.towncolors.admin.NationColorCommand());
|
||||||
registerCommand(new TCCount());
|
registerCommand(new TCCount());
|
||||||
registerListener(new TownyListener());
|
registerListener(new TownyListener());
|
||||||
|
registerListener(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -181,7 +185,7 @@ public class TownColorComponent extends Component {
|
||||||
/**
|
/**
|
||||||
* Checks if the component is enabled
|
* Checks if the component is enabled
|
||||||
*/
|
*/
|
||||||
public static void updatePlayerColors(Player player, ChatPlayer cp) { //Probably at join - nop, nicknames
|
private static void updatePlayerColors(Player player, ChatPlayer cp) { //Probably at join - nop, nicknames
|
||||||
if (!ComponentManager.isEnabled(TownColorComponent.class))
|
if (!ComponentManager.isEnabled(TownColorComponent.class))
|
||||||
return;
|
return;
|
||||||
User user = PluginMain.essentials.getUser(player);
|
User user = PluginMain.essentials.getUser(player);
|
||||||
|
@ -190,6 +194,11 @@ public class TownColorComponent extends Component {
|
||||||
cp.FlairUpdate(); //Update in list
|
cp.FlairUpdate(); //Update in list
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onPlayerJoin(TBMCPlayerJoinEvent event) {
|
||||||
|
updatePlayerColors(event.getPlayer(), event.GetPlayer().asPluginPlayer(ChatPlayer.class));
|
||||||
|
}
|
||||||
|
|
||||||
private static void load_old(Consumer<ConfigurationSection> loadTC,
|
private static void load_old(Consumer<ConfigurationSection> loadTC,
|
||||||
Consumer<ConfigurationSection> loadNC) {
|
Consumer<ConfigurationSection> loadNC) {
|
||||||
PluginMain.Instance.getLogger().info("Loading files...");
|
PluginMain.Instance.getLogger().info("Loading files...");
|
||||||
|
|
|
@ -3,17 +3,13 @@ package buttondevteam.chat.listener;
|
||||||
import buttondevteam.chat.ChatPlayer;
|
import buttondevteam.chat.ChatPlayer;
|
||||||
import buttondevteam.chat.PlayerJoinTimerTask;
|
import buttondevteam.chat.PlayerJoinTimerTask;
|
||||||
import buttondevteam.chat.PluginMain;
|
import buttondevteam.chat.PluginMain;
|
||||||
import buttondevteam.chat.components.chatonly.ChatOnlyComponent;
|
|
||||||
import buttondevteam.chat.components.fun.UnlolCommand;
|
|
||||||
import buttondevteam.chat.commands.ucmds.HistoryCommand;
|
import buttondevteam.chat.commands.ucmds.HistoryCommand;
|
||||||
import buttondevteam.chat.components.flair.FlairComponent;
|
import buttondevteam.chat.components.flair.FlairComponent;
|
||||||
import buttondevteam.chat.components.flair.FlairStates;
|
import buttondevteam.chat.components.flair.FlairStates;
|
||||||
import buttondevteam.chat.components.towncolors.TownColorComponent;
|
|
||||||
import buttondevteam.core.ComponentManager;
|
import buttondevteam.core.ComponentManager;
|
||||||
import buttondevteam.lib.player.TBMCPlayerJoinEvent;
|
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 org.bukkit.GameMode;
|
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
|
@ -59,11 +55,7 @@ public class PlayerJoinLeaveListener implements Listener {
|
||||||
nwithoutformatting = nwithoutformatting.replace("§" + nwithoutformatting.charAt(index + 1), "");
|
nwithoutformatting = nwithoutformatting.replace("§" + nwithoutformatting.charAt(index + 1), "");
|
||||||
} else
|
} else
|
||||||
nwithoutformatting = p.getName();
|
nwithoutformatting = p.getName();
|
||||||
PlayerListener.nicknames.forcePut(nwithoutformatting.toLowerCase(), p.getUniqueId());
|
PlayerListener.nicknames.forcePut(nwithoutformatting.toLowerCase(), p.getUniqueId()); //TODO: FormatterComponent
|
||||||
|
|
||||||
TownColorComponent.updatePlayerColors(p, cp); //TO!DO: Doesn't have effect - It can help to register the listener
|
|
||||||
|
|
||||||
ChatOnlyComponent.playerJoin(cp, p);
|
|
||||||
|
|
||||||
HistoryCommand.showHistory(e.getPlayer(), "u history", new String[0], null);
|
HistoryCommand.showHistory(e.getPlayer(), "u history", new String[0], null);
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,7 +18,6 @@ import buttondevteam.lib.chat.ChatMessage;
|
||||||
import buttondevteam.lib.chat.TBMCChatAPI;
|
import buttondevteam.lib.chat.TBMCChatAPI;
|
||||||
import buttondevteam.lib.player.ChromaGamerBase;
|
import buttondevteam.lib.player.ChromaGamerBase;
|
||||||
import buttondevteam.lib.player.ChromaGamerBase.InfoTarget;
|
import buttondevteam.lib.player.ChromaGamerBase.InfoTarget;
|
||||||
import buttondevteam.lib.player.TBMCPlayer;
|
|
||||||
import buttondevteam.lib.player.TBMCPlayerGetInfoEvent;
|
import buttondevteam.lib.player.TBMCPlayerGetInfoEvent;
|
||||||
import com.google.common.collect.BiMap;
|
import com.google.common.collect.BiMap;
|
||||||
import com.google.common.collect.HashBiMap;
|
import com.google.common.collect.HashBiMap;
|
||||||
|
@ -52,8 +51,7 @@ public class PlayerListener implements Listener {
|
||||||
public void onPlayerChat(AsyncPlayerChatEvent event) {
|
public void onPlayerChat(AsyncPlayerChatEvent event) {
|
||||||
if (event.isCancelled())
|
if (event.isCancelled())
|
||||||
return;
|
return;
|
||||||
ChatPlayer cp = TBMCPlayer.getPlayer(event.getPlayer().getUniqueId(), ChatPlayer.class);
|
//The custom event is called in the core, but doesn't cancel the MC event
|
||||||
TBMCChatAPI.SendChatMessage(ChatMessage.builder(event.getPlayer(), cp, event.getMessage()).build());
|
|
||||||
event.setCancelled(true); // The custom event should only be cancelled when muted or similar
|
event.setCancelled(true); // The custom event should only be cancelled when muted or similar
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -170,12 +168,12 @@ public class PlayerListener implements Listener {
|
||||||
HistoryCommand.addChatMessage(e.getCm(), e.getChannel());
|
HistoryCommand.addChatMessage(e.getCm(), e.getChannel());
|
||||||
e.setCancelled(ChatProcessing.ProcessChat(e));
|
e.setCancelled(ChatProcessing.ProcessChat(e));
|
||||||
} catch (NoClassDefFoundError | Exception ex) { // Weird things can happen
|
} catch (NoClassDefFoundError | Exception ex) { // Weird things can happen
|
||||||
|
val str = "§c!§r[" + e.getChannel().DisplayName().get() + "] <"
|
||||||
|
+ ThorpeUtils.getDisplayName(e.getSender()) + "> " + e.getMessage();
|
||||||
for (Player p : Bukkit.getOnlinePlayers())
|
for (Player p : Bukkit.getOnlinePlayers())
|
||||||
if (e.shouldSendTo(p))
|
if (e.shouldSendTo(p))
|
||||||
p.sendMessage("§c!§r["
|
p.sendMessage(str);
|
||||||
+ e.getChannel().DisplayName().get() + "] <" + (e.getSender() instanceof Player
|
Bukkit.getConsoleSender().sendMessage(str);
|
||||||
? ((Player) e.getSender()).getDisplayName() : e.getSender().getName())
|
|
||||||
+ "> " + e.getMessage());
|
|
||||||
TBMCCoreAPI.SendException("An error occured while processing a chat message!", ex);
|
TBMCCoreAPI.SendException("An error occured while processing a chat message!", ex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -92,7 +92,7 @@ public class ChatFormatIT {
|
||||||
@Test
|
@Test
|
||||||
public void testMessage() {
|
public void testMessage() {
|
||||||
ArrayList<ChatFormatter> cfs = ChatProcessing.addFormatters(Color.White);
|
ArrayList<ChatFormatter> cfs = ChatProcessing.addFormatters(Color.White);
|
||||||
final String chid = ChatProcessing.getChannelID(Channel.GlobalChat, sender, ChatProcessing.MCORIGIN);
|
final String chid = ChatProcessing.getChannelID(Channel.GlobalChat, ChatProcessing.MCORIGIN);
|
||||||
final TellrawPart tp = ChatProcessing.createTellraw(sender, message, null, null, null, chid, ChatProcessing.MCORIGIN);
|
final TellrawPart tp = ChatProcessing.createTellraw(sender, message, null, null, null, chid, ChatProcessing.MCORIGIN);
|
||||||
ChatFormatter.Combine(cfs, message, tp);
|
ChatFormatter.Combine(cfs, message, tp);
|
||||||
System.out.println("Testing: " + message);
|
System.out.println("Testing: " + message);
|
||||||
|
|
Loading…
Reference in a new issue