Add simple VentureChat integration
This integration can filter the recipients of a chat message
This commit is contained in:
		@@ -63,6 +63,7 @@ import com.massivecraft.factions.integration.V18.IntegrationV18;
 | 
			
		||||
import com.massivecraft.factions.integration.V19.IntegrationV19;
 | 
			
		||||
import com.massivecraft.factions.integration.lwc.IntegrationLwc;
 | 
			
		||||
import com.massivecraft.factions.integration.placeholderapi.IntegrationPlaceholderAPI;
 | 
			
		||||
import com.massivecraft.factions.integration.venturechat.IntegrationVentureChat;
 | 
			
		||||
import com.massivecraft.factions.integration.worldguard.IntegrationWorldGuard;
 | 
			
		||||
import com.massivecraft.factions.mixin.PowerMixin;
 | 
			
		||||
import com.massivecraft.factions.task.TaskEconLandReward;
 | 
			
		||||
@@ -180,6 +181,7 @@ public class Factions extends MassivePlugin
 | 
			
		||||
	{
 | 
			
		||||
		return MUtil.list(
 | 
			
		||||
			IntegrationPlaceholderAPI.class,
 | 
			
		||||
			IntegrationVentureChat.class,
 | 
			
		||||
			IntegrationV18.class,
 | 
			
		||||
			IntegrationV19.class,
 | 
			
		||||
			IntegrationLwc.class,
 | 
			
		||||
 
 | 
			
		||||
@@ -1,8 +1,12 @@
 | 
			
		||||
package com.massivecraft.factions.engine;
 | 
			
		||||
 | 
			
		||||
import com.massivecraft.factions.Factions;
 | 
			
		||||
import com.massivecraft.factions.Rel;
 | 
			
		||||
import com.massivecraft.factions.RelationParticipator;
 | 
			
		||||
import com.massivecraft.factions.chat.ChatFormatter;
 | 
			
		||||
import com.massivecraft.factions.entity.Faction;
 | 
			
		||||
import com.massivecraft.factions.entity.MConf;
 | 
			
		||||
import com.massivecraft.factions.entity.MPlayer;
 | 
			
		||||
import com.massivecraft.massivecore.Engine;
 | 
			
		||||
import com.massivecraft.massivecore.event.EventMassiveCorePlayerToRecipientChat;
 | 
			
		||||
import com.massivecraft.massivecore.util.MUtil;
 | 
			
		||||
@@ -15,6 +19,9 @@ import org.bukkit.event.Listener;
 | 
			
		||||
import org.bukkit.event.player.AsyncPlayerChatEvent;
 | 
			
		||||
import org.bukkit.plugin.EventExecutor;
 | 
			
		||||
 | 
			
		||||
import java.util.Iterator;
 | 
			
		||||
import java.util.function.Predicate;
 | 
			
		||||
 | 
			
		||||
public class EngineChat extends Engine
 | 
			
		||||
{
 | 
			
		||||
	// -------------------------------------------- //
 | 
			
		||||
@@ -138,5 +145,35 @@ public class EngineChat extends Engine
 | 
			
		||||
		format = ChatFormatter.format(format, event.getSender(), event.getRecipient());
 | 
			
		||||
		event.setFormat(format);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	// -------------------------------------------- //
 | 
			
		||||
	// FILTER CHAT CHANNEL
 | 
			
		||||
	// -------------------------------------------- //
 | 
			
		||||
 | 
			
		||||
	public static Predicate<Player> getPredicateIsInFaction(RelationParticipator participator)
 | 
			
		||||
	{
 | 
			
		||||
		return player -> MPlayer.get(player).getRelationTo(participator).isAtLeast(Rel.FACTION);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	public static Predicate<Player> getPredicateIsAlly(RelationParticipator participator)
 | 
			
		||||
	{
 | 
			
		||||
		return player -> MPlayer.get(player).getFaction().getRelationTo(participator).isAtLeast(Rel.ALLY);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	public static void filterToPredicate(AsyncPlayerChatEvent event, Predicate<Player> predicate)
 | 
			
		||||
	{
 | 
			
		||||
		Player player = event.getPlayer();
 | 
			
		||||
		MPlayer mplayer = MPlayer.get(player);
 | 
			
		||||
		Faction faction = mplayer.getFaction();
 | 
			
		||||
 | 
			
		||||
		// Get and filter recipients
 | 
			
		||||
		for (Iterator<Player> it = event.getRecipients().iterator(); it.hasNext();)
 | 
			
		||||
		{
 | 
			
		||||
			Player recipient = it.next();
 | 
			
		||||
			if (predicate.test(recipient)) continue;
 | 
			
		||||
 | 
			
		||||
			it.remove();
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
	
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -553,7 +553,15 @@ public class MConf extends Entity<MConf>
 | 
			
		||||
	// Enable the WorldGuard check per-world 
 | 
			
		||||
	// Specify which worlds the WorldGuard Check can be used in
 | 
			
		||||
	public WorldExceptionSet worldguardCheckWorldsEnabled = new WorldExceptionSet();
 | 
			
		||||
	
 | 
			
		||||
 | 
			
		||||
	// -------------------------------------------- //
 | 
			
		||||
	// INTEGRATION: VentureChat
 | 
			
		||||
	// -------------------------------------------- //
 | 
			
		||||
 | 
			
		||||
	public String ventureChatFactionChannelName = "faction";
 | 
			
		||||
	public String ventureChatAllyChannelName = "ally";
 | 
			
		||||
	public boolean ventureChatAllowFactionchatBetweenFactionless = false;
 | 
			
		||||
 | 
			
		||||
	// -------------------------------------------- //
 | 
			
		||||
	// INTEGRATION: ECONOMY
 | 
			
		||||
	// -------------------------------------------- //
 | 
			
		||||
 
 | 
			
		||||
@@ -0,0 +1,74 @@
 | 
			
		||||
package com.massivecraft.factions.integration.venturechat;
 | 
			
		||||
 | 
			
		||||
import com.massivecraft.factions.engine.EngineChat;
 | 
			
		||||
import com.massivecraft.factions.entity.Faction;
 | 
			
		||||
import com.massivecraft.factions.entity.MConf;
 | 
			
		||||
import com.massivecraft.factions.entity.MPlayer;
 | 
			
		||||
import com.massivecraft.massivecore.Engine;
 | 
			
		||||
import kangarko.chatcontrol.ChatControl;
 | 
			
		||||
import mineverse.Aust1n46.chat.api.MineverseChatAPI;
 | 
			
		||||
import mineverse.Aust1n46.chat.api.MineverseChatPlayer;
 | 
			
		||||
import mineverse.Aust1n46.chat.channel.ChatChannel;
 | 
			
		||||
import org.bukkit.entity.Player;
 | 
			
		||||
import org.bukkit.event.EventHandler;
 | 
			
		||||
import org.bukkit.event.EventPriority;
 | 
			
		||||
import org.bukkit.event.player.AsyncPlayerChatEvent;
 | 
			
		||||
 | 
			
		||||
import java.util.function.Predicate;
 | 
			
		||||
 | 
			
		||||
public class EngineVentureChat extends Engine
 | 
			
		||||
{
 | 
			
		||||
	// -------------------------------------------- //
 | 
			
		||||
	// INSTANCE & CONSTRUCT
 | 
			
		||||
	// -------------------------------------------- //
 | 
			
		||||
	
 | 
			
		||||
	private static EngineVentureChat i = new EngineVentureChat();
 | 
			
		||||
	public static EngineVentureChat get() { return i; }
 | 
			
		||||
 | 
			
		||||
	// -------------------------------------------- //
 | 
			
		||||
	// OVERRIDE
 | 
			
		||||
	// -------------------------------------------- //
 | 
			
		||||
	
 | 
			
		||||
	@Override
 | 
			
		||||
	public void setActiveInner(boolean active)
 | 
			
		||||
	{
 | 
			
		||||
 | 
			
		||||
	}
 | 
			
		||||
	
 | 
			
		||||
	// -------------------------------------------- //
 | 
			
		||||
	// LISTENER
 | 
			
		||||
	// -------------------------------------------- //
 | 
			
		||||
 | 
			
		||||
	@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
 | 
			
		||||
	public void filterFaction(AsyncPlayerChatEvent event)
 | 
			
		||||
	{
 | 
			
		||||
		// Get player
 | 
			
		||||
		Player player = event.getPlayer();
 | 
			
		||||
		MineverseChatPlayer chatPlayer = MineverseChatAPI.getMineverseChatPlayer(player);
 | 
			
		||||
		ChatChannel channel = chatPlayer.getCurrentChannel();
 | 
			
		||||
		String channelName = channel.getName();
 | 
			
		||||
 | 
			
		||||
		// If the channel is the Factions channel
 | 
			
		||||
		boolean factionChat = channelName.equalsIgnoreCase(MConf.get().ventureChatFactionChannelName);
 | 
			
		||||
		boolean allyChat = channelName.equalsIgnoreCase(MConf.get().ventureChatAllyChannelName);
 | 
			
		||||
		if (!(factionChat || allyChat)) return;
 | 
			
		||||
 | 
			
		||||
		MPlayer mplayer = MPlayer.get(player);
 | 
			
		||||
		Faction faction = mplayer.getFaction();
 | 
			
		||||
 | 
			
		||||
		// Wilderness check
 | 
			
		||||
		if ( !  MConf.get().ventureChatAllowFactionchatBetweenFactionless && faction.isNone())
 | 
			
		||||
		{
 | 
			
		||||
			mplayer.msg("<b>Factionless can't use faction chat.");
 | 
			
		||||
			event.setCancelled(true);
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		Predicate<Player> predicateChannel = factionChat ? EngineChat.getPredicateIsInFaction(faction) : EngineChat.getPredicateIsAlly(faction);
 | 
			
		||||
		Predicate<Player> isSpy = recipient -> MineverseChatAPI.getMineverseChatPlayer(recipient).isSpy();
 | 
			
		||||
		Predicate<Player> predicate = isSpy.or(predicateChannel);
 | 
			
		||||
 | 
			
		||||
		EngineChat.filterToPredicate(event, predicate);
 | 
			
		||||
		ChatControl
 | 
			
		||||
	}
 | 
			
		||||
	
 | 
			
		||||
}
 | 
			
		||||
@@ -0,0 +1,29 @@
 | 
			
		||||
package com.massivecraft.factions.integration.venturechat;
 | 
			
		||||
 | 
			
		||||
import com.massivecraft.massivecore.Engine;
 | 
			
		||||
import com.massivecraft.massivecore.Integration;
 | 
			
		||||
 | 
			
		||||
public class IntegrationVentureChat extends Integration
 | 
			
		||||
{
 | 
			
		||||
	// -------------------------------------------- //
 | 
			
		||||
	// INSTANCE & CONSTRUCT
 | 
			
		||||
	// -------------------------------------------- //
 | 
			
		||||
 | 
			
		||||
	private static IntegrationVentureChat i = new IntegrationVentureChat();
 | 
			
		||||
	public static IntegrationVentureChat get() { return i; }
 | 
			
		||||
	private IntegrationVentureChat()
 | 
			
		||||
	{
 | 
			
		||||
		this.setPluginName("VentureChat");
 | 
			
		||||
	}
 | 
			
		||||
	
 | 
			
		||||
	// -------------------------------------------- //
 | 
			
		||||
	// OVERRIDE
 | 
			
		||||
	// -------------------------------------------- //
 | 
			
		||||
 | 
			
		||||
	@Override
 | 
			
		||||
	public Engine getEngine()
 | 
			
		||||
	{
 | 
			
		||||
		return EngineVentureChat.get();
 | 
			
		||||
	}
 | 
			
		||||
	
 | 
			
		||||
}
 | 
			
		||||
		Reference in New Issue
	
	Block a user