mirror of
https://github.com/MassiveCraft/Factions.git
synced 2024-11-05 01:59:46 +01:00
added a secondary low priority event listener for chat events, to try and make sure Factions is able to handle slashless commands and faction chat before other plugins do anything
This commit is contained in:
parent
c818ddff99
commit
c3f57d5105
@ -22,6 +22,7 @@ import com.massivecraft.factions.commands.*;
|
||||
import com.massivecraft.factions.gson.Gson;
|
||||
import com.massivecraft.factions.gson.GsonBuilder;
|
||||
import com.massivecraft.factions.listeners.FactionsBlockListener;
|
||||
import com.massivecraft.factions.listeners.FactionsChatEarlyListener;
|
||||
import com.massivecraft.factions.listeners.FactionsEntityListener;
|
||||
import com.massivecraft.factions.listeners.FactionsPlayerListener;
|
||||
|
||||
@ -47,6 +48,7 @@ public class Factions extends JavaPlugin {
|
||||
.create();
|
||||
|
||||
private final FactionsPlayerListener playerListener = new FactionsPlayerListener();
|
||||
private final FactionsChatEarlyListener chatEarlyListener = new FactionsChatEarlyListener();
|
||||
private final FactionsEntityListener entityListener = new FactionsEntityListener();
|
||||
private final FactionsBlockListener blockListener = new FactionsBlockListener();
|
||||
|
||||
@ -127,6 +129,7 @@ public class Factions extends JavaPlugin {
|
||||
// Register events
|
||||
PluginManager pm = this.getServer().getPluginManager();
|
||||
pm.registerEvent(Event.Type.PLAYER_CHAT, this.playerListener, Event.Priority.Highest, this);
|
||||
pm.registerEvent(Event.Type.PLAYER_CHAT, this.chatEarlyListener, Event.Priority.Lowest, this);
|
||||
pm.registerEvent(Event.Type.PLAYER_INTERACT, this.playerListener, Event.Priority.Normal, this);
|
||||
pm.registerEvent(Event.Type.PLAYER_MOVE, this.playerListener, Event.Priority.Normal, this);
|
||||
pm.registerEvent(Event.Type.PLAYER_JOIN, this.playerListener, Event.Priority.Normal, this);
|
||||
|
@ -0,0 +1,51 @@
|
||||
package com.massivecraft.factions.listeners;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.player.PlayerChatEvent;
|
||||
import org.bukkit.event.player.PlayerListener;
|
||||
|
||||
import com.massivecraft.factions.Conf;
|
||||
import com.massivecraft.factions.FPlayer;
|
||||
import com.massivecraft.factions.Factions;
|
||||
import com.massivecraft.factions.util.TextUtil;
|
||||
|
||||
|
||||
// this is an addtional PlayerListener for handling slashless command usage and faction chat, to be set at low priority so Factions gets to them first
|
||||
public class FactionsChatEarlyListener extends PlayerListener{
|
||||
|
||||
@Override
|
||||
public void onPlayerChat(PlayerChatEvent event) {
|
||||
if ((event.getMessage().startsWith(Factions.instance.getBaseCommand()+" ") || event.getMessage().equals(Factions.instance.getBaseCommand())) && Conf.allowNoSlashCommand) {
|
||||
List<String> parameters = TextUtil.split(event.getMessage().trim());
|
||||
parameters.remove(0);
|
||||
CommandSender sender = event.getPlayer();
|
||||
Factions.instance.handleCommand(sender, parameters);
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
if (event.isCancelled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
Player talkingPlayer = event.getPlayer();
|
||||
String msg = event.getMessage();
|
||||
|
||||
// ... it was not a command. This means that it is a chat message!
|
||||
FPlayer me = FPlayer.get(talkingPlayer);
|
||||
|
||||
// Is it a faction chat message?
|
||||
if (me.isFactionChatting()) {
|
||||
String message = String.format(Conf.factionChatFormat, me.getNameAndRelevant(me), msg);
|
||||
me.getFaction().sendMessage(message);
|
||||
Logger.getLogger("Minecraft").info(ChatColor.stripColor("FactionChat "+me.getFaction().getTag()+": "+message));
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
@ -35,15 +35,6 @@ public class FactionsPlayerListener extends PlayerListener{
|
||||
|
||||
@Override
|
||||
public void onPlayerChat(PlayerChatEvent event) {
|
||||
if ((event.getMessage().startsWith(Factions.instance.getBaseCommand()+" ") || event.getMessage().equals(Factions.instance.getBaseCommand())) && Conf.allowNoSlashCommand) {
|
||||
List<String> parameters = TextUtil.split(event.getMessage().trim());
|
||||
parameters.remove(0);
|
||||
CommandSender sender = event.getPlayer();
|
||||
Factions.instance.handleCommand(sender, parameters);
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
if (event.isCancelled()) {
|
||||
return;
|
||||
}
|
||||
@ -54,15 +45,6 @@ public class FactionsPlayerListener extends PlayerListener{
|
||||
// ... it was not a command. This means that it is a chat message!
|
||||
FPlayer me = FPlayer.get(talkingPlayer);
|
||||
|
||||
// Is it a faction chat message?
|
||||
if (me.isFactionChatting()) {
|
||||
String message = String.format(Conf.factionChatFormat, me.getNameAndRelevant(me), msg);
|
||||
me.getFaction().sendMessage(message);
|
||||
Logger.getLogger("Minecraft").info(ChatColor.stripColor("FactionChat "+me.getFaction().getTag()+": "+message));
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
// Are we to insert the Faction tag into the format?
|
||||
// If we are not to insert it - we are done.
|
||||
if ( ! Conf.chatTagEnabled || Conf.chatTagHandledByAnotherPlugin) {
|
||||
|
Loading…
Reference in New Issue
Block a user