Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added ShockChat support for Factions mod/truce/etc chats. #7

Open
wants to merge 1 commit into
base: 1.6.x
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions modules/Main/pom.xml
Original file line number Diff line number Diff line change
@@ -457,6 +457,18 @@
<scope>system</scope>
<systemPath>${project.basedir}/../../locallibs/CombatTagPlus.jar</systemPath>
</dependency>
<dependency>
<groupId>not.savage</groupId>
<artifactId>ShockChat</artifactId>
<version>1.1.4</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>not.savage</groupId>
<artifactId>SVCommonLib</artifactId>
<version>1.0.16</version>
<scope>provided</scope>
</dependency>
</dependencies>

<repositories>
@@ -496,6 +508,10 @@
<id>magic</id>
<url>https://maven.elmakers.com/repository/</url>
</repository>
<repository>
<id>supreme-ventures-nexus</id>
<url>https://nexus.supremeventures.ca/repository/maven-releases/</url>
</repository>
<repository>
<id>local</id>
<url>file://../../locallibs/m2/</url>
Original file line number Diff line number Diff line change
@@ -392,6 +392,7 @@ public void close() throws SecurityException {
// Register Event Handlers
getServer().getPluginManager().registerEvents(new FactionsPlayerListener(this), this);
getServer().getPluginManager().registerEvents(new FactionsChatListener(this), this);
new ShockChatListener();
getServer().getPluginManager().registerEvents(new FactionsEntityListener(this), this);
getServer().getPluginManager().registerEvents(new FactionsExploitListener(this), this);
getServer().getPluginManager().registerEvents(new FactionsBlockListener(this), this);
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
package com.massivecraft.factions.listeners;

import com.massivecraft.factions.FPlayer;
import com.massivecraft.factions.FPlayers;
import com.massivecraft.factions.Faction;
import com.massivecraft.factions.FactionsPlugin;
import com.massivecraft.factions.config.file.MainConfig;
import com.massivecraft.factions.perms.Relation;
import com.massivecraft.factions.perms.Role;
import com.massivecraft.factions.struct.ChatMode;
import not.savage.chat.spigot.api.events.PlayerChatEvent;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.plugin.Plugin;

import java.util.logging.Level;

public class ShockChatListener extends AbstractListener {

private final FactionsPlugin plugin;

public ShockChatListener(FactionsPlugin plugin) {
this.plugin = plugin;
Plugin chat = Bukkit.getPluginManager().getPlugin("ShockChat");
if (chat != null && chat.isEnabled()) {
Bukkit.getPluginManager().registerEvents(this, this.plugin);
}
}

@EventHandler
public void onPlayerChat(PlayerChatEvent event) {
if (!plugin.worldUtil().isEnabled(event.getPlayer().getPlayer().getWorld())) {
return;
}

Player talkingPlayer = event.getPlayer().getPlayer();
String msg = event.getMessage();
FPlayer me = FPlayers.getInstance().getByPlayer(talkingPlayer);
ChatMode chat = me.getChatMode();
MainConfig.Factions.Chat chatConf = FactionsPlugin.getInstance().conf().factions().chat();
//Is it a MOD chat
if (chat == ChatMode.MOD) {
Faction myFaction = me.getFaction();

String message = String.format(chatConf.getModChatFormat(), ChatColor.stripColor(me.getNameAndTag()), msg);

//Send to all mods
for (FPlayer fplayer : FPlayers.getInstance().getOnlinePlayers()) {
if (myFaction == fplayer.getFaction() && fplayer.getRole().isAtLeast(Role.MODERATOR)) {
fplayer.sendMessage(message);
} else if (fplayer.isSpyingChat() && me != fplayer) {
fplayer.sendMessage("[MCspy]: " + message);
}
}

FactionsPlugin.getInstance().log(Level.INFO, ChatColor.stripColor("ModChat " + myFaction.getTag() + ": " + message));

event.setCancelled(true);
} else if (chat == ChatMode.FACTION) {
Faction myFaction = me.getFaction();

String message = String.format(chatConf.getFactionChatFormat(), me.describeTo(myFaction), msg);
myFaction.sendMessage(message);

FactionsPlugin.getInstance().log(Level.INFO, ChatColor.stripColor("FactionChat " + myFaction.getTag() + ": " + message));

//Send to any players who are spying chat
for (FPlayer fplayer : FPlayers.getInstance().getOnlinePlayers()) {
if (fplayer.isSpyingChat() && fplayer.getFaction() != myFaction && me != fplayer) {
fplayer.sendMessage("[FCspy] " + myFaction.getTag() + ": " + message);
}
}

event.setCancelled(true);
} else if (chat == ChatMode.ALLIANCE) {
Faction myFaction = me.getFaction();

String message = String.format(chatConf.getAllianceChatFormat(), ChatColor.stripColor(me.getNameAndTag()), msg);

//Send message to our own faction
myFaction.sendMessage(message);

//Send to all our allies
for (FPlayer fplayer : FPlayers.getInstance().getOnlinePlayers()) {
if (myFaction.getRelationTo(fplayer) == Relation.ALLY && !fplayer.isIgnoreAllianceChat()) {
fplayer.sendMessage(message);
} else if (fplayer.isSpyingChat() && me != fplayer) {
fplayer.sendMessage("[ACspy]: " + message);
}
}

FactionsPlugin.getInstance().log(Level.INFO, ChatColor.stripColor("AllianceChat: " + message));

event.setCancelled(true);
} else if (chat == ChatMode.TRUCE) {
Faction myFaction = me.getFaction();

String message = String.format(chatConf.getTruceChatFormat(), ChatColor.stripColor(me.getNameAndTag()), msg);

//Send message to our own faction
myFaction.sendMessage(message);

//Send to all our truces
for (FPlayer fplayer : FPlayers.getInstance().getOnlinePlayers()) {
if (myFaction.getRelationTo(fplayer) == Relation.TRUCE) {
fplayer.sendMessage(message);
} else if (fplayer.isSpyingChat() && fplayer != me) {
fplayer.sendMessage("[TCspy]: " + message);
}
}

FactionsPlugin.getInstance().log(Level.INFO, ChatColor.stripColor("TruceChat: " + message));
event.setCancelled(true);
}
}

}