More components, broadcasts #98

Merged
NorbiPeti merged 13 commits from dev into master 2019-03-17 01:28:22 +00:00
6 changed files with 25 additions and 25 deletions
Showing only changes of commit 8ff45ad676 - Show all commits

View file

@ -144,7 +144,7 @@ public class ChatProcessing {
}).build());
}
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());
long combinetime = System.nanoTime();
@ -238,7 +238,7 @@ public class ChatProcessing {
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())
+ "]";
}

View file

@ -7,8 +7,8 @@ import buttondevteam.core.ComponentManager;
import buttondevteam.lib.architecture.Component;
import buttondevteam.lib.player.TBMCPlayer;
import buttondevteam.lib.player.TBMCPlayerJoinEvent;
import lombok.val;
import org.bukkit.GameMode;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
@ -27,9 +27,10 @@ public class ChatOnlyComponent extends Component implements Listener {
}
public static void playerJoin(ChatPlayer cp, Player p) {
if(!ComponentManager.isEnabled(ChatOnlyComponent.class))
return;
@EventHandler
public void playerJoin(TBMCPlayerJoinEvent event) {
val p = event.getPlayer();
val cp = event.GetPlayer().asPluginPlayer(ChatPlayer.class);
if (cp.ChatOnly || p.getGameMode().equals(GameMode.SPECTATOR)) {
cp.ChatOnly = false;
p.setGameMode(GameMode.SURVIVAL);

View file

@ -10,6 +10,7 @@ import buttondevteam.lib.architecture.Component;
import buttondevteam.lib.architecture.ComponentMetadata;
import buttondevteam.lib.architecture.ConfigData;
import buttondevteam.lib.chat.Color;
import buttondevteam.lib.player.TBMCPlayerJoinEvent;
import com.earth2me.essentials.User;
import com.palmergames.bukkit.towny.exceptions.NotRegisteredException;
import com.palmergames.bukkit.towny.object.Nation;
@ -20,6 +21,8 @@ import org.bukkit.ChatColor;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.dynmap.towny.DTBridge;
import org.dynmap.towny.DynmapTownyPlugin;
@ -32,7 +35,7 @@ import java.util.function.Function;
import java.util.stream.Collectors;
@ComponentMetadata(depends = TownyComponent.class)
public class TownColorComponent extends Component {
public class TownColorComponent extends Component implements Listener {
/**
* Names lowercased
*/
@ -98,6 +101,7 @@ public class TownColorComponent extends Component {
registerCommand(new buttondevteam.chat.components.towncolors.admin.NationColorCommand());
registerCommand(new TCCount());
registerListener(new TownyListener());
registerListener(this);
}
@Override
@ -181,7 +185,7 @@ public class TownColorComponent extends Component {
/**
* 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))
return;
User user = PluginMain.essentials.getUser(player);
@ -190,6 +194,11 @@ public class TownColorComponent extends Component {
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,
Consumer<ConfigurationSection> loadNC) {
PluginMain.Instance.getLogger().info("Loading files...");

View file

@ -3,17 +3,13 @@ package buttondevteam.chat.listener;
import buttondevteam.chat.ChatPlayer;
import buttondevteam.chat.PlayerJoinTimerTask;
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.components.flair.FlairComponent;
import buttondevteam.chat.components.flair.FlairStates;
import buttondevteam.chat.components.towncolors.TownColorComponent;
import buttondevteam.core.ComponentManager;
import buttondevteam.lib.player.TBMCPlayerJoinEvent;
import buttondevteam.lib.player.TBMCPlayerLoadEvent;
import buttondevteam.lib.player.TBMCPlayerSaveEvent;
import org.bukkit.GameMode;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
@ -59,11 +55,7 @@ public class PlayerJoinLeaveListener implements Listener {
nwithoutformatting = nwithoutformatting.replace("§" + nwithoutformatting.charAt(index + 1), "");
} else
nwithoutformatting = p.getName();
PlayerListener.nicknames.forcePut(nwithoutformatting.toLowerCase(), p.getUniqueId());
TownColorComponent.updatePlayerColors(p, cp); //TO!DO: Doesn't have effect - It can help to register the listener
ChatOnlyComponent.playerJoin(cp, p);
PlayerListener.nicknames.forcePut(nwithoutformatting.toLowerCase(), p.getUniqueId()); //TODO: FormatterComponent
HistoryCommand.showHistory(e.getPlayer(), "u history", new String[0], null);
}

View file

@ -18,7 +18,6 @@ import buttondevteam.lib.chat.ChatMessage;
import buttondevteam.lib.chat.TBMCChatAPI;
import buttondevteam.lib.player.ChromaGamerBase;
import buttondevteam.lib.player.ChromaGamerBase.InfoTarget;
import buttondevteam.lib.player.TBMCPlayer;
import buttondevteam.lib.player.TBMCPlayerGetInfoEvent;
import com.google.common.collect.BiMap;
import com.google.common.collect.HashBiMap;
@ -52,8 +51,7 @@ public class PlayerListener implements Listener {
public void onPlayerChat(AsyncPlayerChatEvent event) {
if (event.isCancelled())
return;
ChatPlayer cp = TBMCPlayer.getPlayer(event.getPlayer().getUniqueId(), ChatPlayer.class);
TBMCChatAPI.SendChatMessage(ChatMessage.builder(event.getPlayer(), cp, event.getMessage()).build());
//The custom event is called in the core, but doesn't cancel the MC event
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());
e.setCancelled(ChatProcessing.ProcessChat(e));
} 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())
if (e.shouldSendTo(p))
p.sendMessage("§c!§r["
+ e.getChannel().DisplayName().get() + "] <" + (e.getSender() instanceof Player
? ((Player) e.getSender()).getDisplayName() : e.getSender().getName())
+ "> " + e.getMessage());
p.sendMessage(str);
Bukkit.getConsoleSender().sendMessage(str);
TBMCCoreAPI.SendException("An error occured while processing a chat message!", ex);
}
}

View file

@ -92,7 +92,7 @@ public class ChatFormatIT {
@Test
public void testMessage() {
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);
ChatFormatter.Combine(cfs, message, tp);
System.out.println("Testing: " + message);