Java Code Examples for org.bukkit.event.player.PlayerChatEvent

The following are top voted examples for showing how to use org.bukkit.event.player.PlayerChatEvent. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: PetBlocks   File: PetDataListener.java   View source code 6 votes vote down vote up
private void handleChatMessage(PlayerChatEvent event) {
    if (this.namingPlayers.contains(event.getPlayer()) || this.namingSkull.contains(event.getPlayer()))
        event.setCancelled(true);
    final PetBlock petBlock;
    if ((petBlock = this.getPetBlock(event.getPlayer())) != null) {
        if (this.namingSkull.contains(event.getPlayer())) {
            this.renameSkull(event.getPlayer(), event.getMessage(), petBlock.getMeta(), petBlock);
        } else if (this.namingPlayers.contains(event.getPlayer())) {
            this.renameName(event.getPlayer(), event.getMessage(), petBlock.getMeta(), petBlock);
        }
    } else {
        this.plugin.getServer().getScheduler().runTaskAsynchronously(this.plugin, () -> {
            final com.github.shynixn.petblocks.api.persistence.entity.PetMeta petMeta = this.manager.getPetMetaController().getByPlayer(event.getPlayer());
            if (this.namingSkull.contains(event.getPlayer())) {
                this.plugin.getServer().getScheduler().runTask(this.plugin, () -> this.renameSkull(event.getPlayer(), event.getMessage(), petMeta, null));
            } else if (this.namingPlayers.contains(event.getPlayer())) {
                this.plugin.getServer().getScheduler().runTask(this.plugin, () -> this.renameName(event.getPlayer(), event.getMessage(), petMeta, null));
            }
        });
    }
}
 
Example 2
Project: FlexMC   File: ChatListener.java   View source code 6 votes vote down vote up
@SuppressWarnings( "deprecation" )
@Override
public void handle( ConnectionHandler connectionHandler, MessageC02ChatMessage message ) {
    FlexPlayer player = connectionHandler.getPlayer();
    if( player != null && message.getMessage().length() < 256 ) {
        if( message.getMessage().startsWith( "/" ) ) {
            String commandLine = message.getMessage().length() == 1 ? "" : message.getMessage().substring( 1 );
            if( !Flex.getServer().getCommandMap().dispatch( player, commandLine ) ) {
                player.sendMessage( "Unknown command. Type /help for help" );
            }
            return;
        }
        PlayerChatEvent oldEvent = EventFactory.call( new PlayerChatEvent( player, message.getMessage(), "<%1$s> %2$s", new HashSet<>( Flex.getServer().getPlayerManager().getOnlinePlayers() ) ) );
        AsyncPlayerChatEvent event = new AsyncPlayerChatEvent( true, player, oldEvent.getMessage(), oldEvent.getRecipients() );
        event.setFormat( oldEvent.getFormat() );
        EventFactory.call( event );
        if( !event.isCancelled() ) {
            for( Player target : event.getRecipients() ) {
                if( target.isOnline() ) {
                    target.sendMessage( String.format( event.getFormat(), player.getDisplayName(), message.getMessage() ) );
                }
            }
        }
    }
}
 
Example 3
Project: Pugna   File: PlayerListener.java   View source code 6 votes vote down vote up
@EventHandler(priority = EventPriority.NORMAL)
public void onChat(PlayerChatEvent event)
{
    Player player = event.getPlayer();
    PugnaPlayer play = pg.track.getPlayerData(player);

    if (play.getChatState() && play.getTeamState())
    {
        event.setCancelled(true);
        String teamName = play.getTeam();
        PugnaTeam team = pg.teams.getTeam(teamName); //
        team.sendMessage(player, " " + event.getMessage());
    }
    else if (player.getPlayerListName().equals(pg.emperor.getEmperorName()))
    {
        event.setFormat(ChatColor.DARK_PURPLE + pg.config.emperorTitle + " %s: %s");
    }
}
 
Example 4
Project: xEssentials-deprecated-bukkit   File: FloodSpamEvent.java   View source code 6 votes vote down vote up
@EventHandler(priority = EventPriority.LOWEST)
public void playerChatTime(PlayerChatEvent e) {
	if(chatTime.containsKey(e.getPlayer().getName())) {
		if(System.currentTimeMillis() - chatTime.get(e.getPlayer().getName()) < 300) {
			e.setCancelled(true);
			XPlayer xp = pl.getManagers().getPlayerManager().getPlayer(e.getPlayer().getName());
			Date date = new Date(System.currentTimeMillis());
			date.setDate(date.getDate() + 1);
			xp.setTempbanned(date.getTime(), pl.getConfiguration().getBanConfig().getFloodSpamBanMessage(), "CONSOLE");
		} else {
			chatTime.put(e.getPlayer().getName(), System.currentTimeMillis());
		}
	} else {
		chatTime.put(e.getPlayer().getName(), System.currentTimeMillis());
	}
}
 
Example 5
Project: xEssentials-deprecated-bukkit   File: SilenceChatEvent.java   View source code 6 votes vote down vote up
@EventHandler(priority = EventPriority.LOW)
public void onChat(PlayerChatEvent e) {
	if(pl.getConfiguration().isChatSillenced()) {
		sendMessage(e.getPlayer(), ChatColor.GREEN + "all chat activity has been halted!, please wait a few minuts.");
		e.setCancelled(true);
	} else {
		XPlayer xp = pl.getManagers().getPlayerManager().getPlayer(e.getPlayer().getName());
		if(xp.isSilenced()) {
			sendMessage(e.getPlayer(), ChatColor.GREEN + "you have silenced your chat, so you cannot chat unless you unmute your self with /silence");
			e.setCancelled(true);
			return;
		}

		//credits to feildmaster his silence source

		Iterator<Player> it = e.getRecipients().iterator();

		for(Player p = (it.hasNext() ? it.next() : null); it.hasNext(); p=it.next()) {
			XPlayer xp2 = pl.getManagers().getPlayerManager().getPlayer(p.getName());
			if(xp2.isSilenced()) {
				it.remove();
			}
		}
	}
}
 
Example 6
Project: xEssentials-deprecated-bukkit   File: CallPlayerChatSmilleyEvent.java   View source code 6 votes vote down vote up
@EventHandler
public void onChatSmilleyEvent(PlayerChatEvent e) {
	List<String> SmilleyList = new ArrayList<String>();
	String[] args = e.getMessage().split(" ");
	for(int i = 0; i < args.length; i++) {
		if(args[i].equalsIgnoreCase(":D")) {
			SmilleyList.add(args[i]);
		} else if(args[i].equalsIgnoreCase(":@")) {
			SmilleyList.add(args[i]);
		} else if(args[i].equalsIgnoreCase("<3")) {
			SmilleyList.add(args[i]);
		} else if(args[i].equalsIgnoreCase(":)")) {
			SmilleyList.add(args[i]);
		}
	}
	String[] SmilleyNames = SmilleyList.toArray(new String[SmilleyList.size()]);
	if(SmilleyNames.length > 0) {
		Bukkit.getPluginManager().callEvent(new PlayerChatSmilleyEvent(e, SmilleyNames, pl));
	}
}
 
Example 7
Project: xEssentials_old_Source   File: afkChat.java   View source code 6 votes vote down vote up
@EventHandler
public void afkCheckChat(PlayerChatEvent e) {
	for(Player p : Bukkit.getOnlinePlayers()) {
		if(e.getMessage().contains(p.getName())) {
			if(afkCheck.afkList.contains(p.getName())) {
				if(afkCheck.afkMessage.containsKey(p.getName())) {
					e.getPlayer().sendMessage(ChatColor.GREEN + p.getName() + " has been afk [ " + afkCheck.afkMessage.get(p.getName()) + " ]");
					//e.setCancelled(true);	
				} else {
					e.getPlayer().sendMessage(ChatColor.GREEN + p.getName() + " has been afk");
					//e.setCancelled(true);
				}
			}
		}
	}
}
 
Example 8
Project: Chatter   File: Chatter.java   View source code 6 votes vote down vote up
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
public void onPlayerChatEvent(PlayerChatEvent event) {
  Player player = event.getPlayer();

  // replace message color codes
  if (player.hasPermission("chatter.colour")) {
    String message = event.getMessage();
    message = replaceColorCodes(message);
    event.setMessage(message);
  }

  // set the format
  String format = config.getString("chat.format");
  format = replacePlayerPlaceholders(player, format);
  format = replaceColorCodes(format);
  event.setFormat(format);
}
 
Example 9
Project: PetBlocks   File: PetDataListener.java   View source code 5 votes vote down vote up
@EventHandler(priority = EventPriority.HIGHEST)
public void playerChatEvent3(final AsyncPlayerChatEvent event) {
    if (Config.getInstance().isChat_async() && Config.getInstance().isChatHighestPriority()) {
        if (this.namingPlayers.contains(event.getPlayer()) || this.namingSkull.contains(event.getPlayer()))
            event.setCancelled(true);
        this.plugin.getServer().getScheduler().runTaskLater(this.plugin, () -> PetDataListener.this.handleChatMessage(new PlayerChatEvent(event.getPlayer(), event.getMessage())), 1L);
    }
}
 
Example 10
Project: PetBlocks   File: PetDataListener.java   View source code 5 votes vote down vote up
@EventHandler(priority = EventPriority.LOW)
public void playerChatEvent4(final AsyncPlayerChatEvent event) {
    if (Config.getInstance().isChat_async() && !Config.getInstance().isChatHighestPriority()) {
        if (this.namingPlayers.contains(event.getPlayer()) || this.namingSkull.contains(event.getPlayer()))
            event.setCancelled(true);
        this.plugin.getServer().getScheduler().runTaskLater(this.plugin, () -> PetDataListener.this.handleChatMessage(new PlayerChatEvent(event.getPlayer(), event.getMessage())), 1L);
    }
}
 
Example 11
Project: BlockBall   File: SChatMenuManager.java   View source code 5 votes vote down vote up
@EventHandler(priority = EventPriority.LOWEST)
public void onPlayerAsyncChatEvent2(PlayerChatEvent event) {
    if (!Config.getInstance().isAsyncChat() && !Config.getInstance().isHighpriority()) {
        if (this.pages.containsKey(event.getPlayer())) {
            event.setCancelled(true);
            final String message = ChatColor.stripColor(event.getMessage());
            this.handleChatMessage(event.getPlayer(), message);
        }
    }
}
 
Example 12
Project: BlockBall   File: SChatMenuManager.java   View source code 5 votes vote down vote up
@EventHandler(priority = EventPriority.HIGHEST)
public void onPlayerAsyncChatEvent(PlayerChatEvent event) {
    if (!Config.getInstance().isAsyncChat() && Config.getInstance().isHighpriority()) {
        if (this.pages.containsKey(event.getPlayer())) {
            event.setCancelled(true);
            final String message = ChatColor.stripColor(event.getMessage());
            this.handleChatMessage(event.getPlayer(), message);
        }
    }
}
 
Example 13
Project: Skript   File: ExprMessage.java   View source code 5 votes vote down vote up
@Override
@Nullable
String get(final Event e) {
	if (PlayerChatEventHandler.usesAsyncEvent)
		return ((AsyncPlayerChatEvent) e).getMessage();
	else
		return ((PlayerChatEvent) e).getMessage();
}
 
Example 14
Project: Skript   File: ExprMessage.java   View source code 5 votes vote down vote up
@Override
void set(final Event e, final String message) {
	if (PlayerChatEventHandler.usesAsyncEvent)
		((AsyncPlayerChatEvent) e).setMessage(message);
	else
		((PlayerChatEvent) e).setMessage(message);
}
 
Example 15
Project: Skript   File: Commands.java   View source code 5 votes vote down vote up
@SuppressWarnings("null")
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
public void onPlayerChat(final PlayerChatEvent e) {
	if (!SkriptConfig.enableEffectCommands.value() || !e.getMessage().startsWith(SkriptConfig.effectCommandToken.value()))
		return;
	if (handleEffectCommand(e.getPlayer(), e.getMessage()))
		e.setCancelled(true);
}
 
Example 16
Project: CraftPlugins   File: Blockode.java   View source code 5 votes vote down vote up
@EventHandler(priority = EventPriority.NORMAL,ignoreCancelled = true)
public void onPlayerChat(PlayerChatEvent event) {
    if(this.isQuoteBlocked(event.getMessage())){
    	event.getPlayer().sendMessage(ChatColor.RED+"这话你可不能说啊。。。!");
    	event.setCancelled(true);
    }
}
 
Example 17
Project: CraftPlugins   File: Banner.java   View source code 5 votes vote down vote up
@EventHandler(priority = EventPriority.NORMAL,ignoreCancelled = true)
public void onPlayerChat(PlayerChatEvent event) {
    if(this.isQuoteBlocked(event.getMessage()) && !event.getPlayer().isOp()){
    	event.getPlayer().sendMessage(ChatColor.RED+"这话你可不能说啊。。。!");
    	event.setCancelled(true);
    }
}
 
Example 18
Project: CraftPlugins   File: Blockode.java   View source code 5 votes vote down vote up
@EventHandler(priority = EventPriority.NORMAL,ignoreCancelled = true)
public void onPlayerChat(PlayerChatEvent event) {
    if(this.isQuoteBlocked(event.getMessage())){
    	event.getPlayer().sendMessage(ChatColor.RED+"这话你可不能说啊。。。!");
    	event.setCancelled(true);
    }
}
 
Example 19
Project: JAATP   File: Mentions.java   View source code 5 votes vote down vote up
@EventHandler
public void onChat(PlayerChatEvent e){
	
	if(!e.getMessage().contains("@")) return;
	
	ArrayList<String> words = new ArrayList<>(Arrays.asList(e.getMessage().split(" ")));
	ArrayList<String> mentions = new ArrayList<>();
	
	for(String word : words){
		if(word.contains("@")){
			
			mentions.add(word.split("@")[1]);
		}
	}
	
	for(String pname : mentions){
		String before = new String(pname);
		Player p = Bukkit.getPlayer(pname);
		if(p == null){
			e.getPlayer().sendMessage(MessageConfig.ERROR_PLAYER_MENTION_NOT_ONLINE);
			return;
		}
		pname = ChatColor.AQUA + pname;
		e.setMessage(e.getMessage().replaceAll("@" + before,ChatColor.AQUA + "@" + pname + ChatColor.RESET));
		p.playSound(p.getLocation(), Sound.BLOCK_NOTE_PLING, 1F, 1F);
	}
	
	
	
}
 
Example 20
Project: RoyalIRC   File: BChatListener.java   View source code 5 votes vote down vote up
@SuppressWarnings("deprecation")
@EventHandler(priority = EventPriority.MONITOR)
public void syncOnChat(PlayerChatEvent e) {
    if (!Config.useSyncChat) return;
    if (e.isCancelled() || e.getRecipients().isEmpty()) return;
    String message = Config.btiMessage;
    message = replaceVars(e, message);
    message = message.replace("{message}", e.getMessage());
    plugin.bh.sendMessage(message);
}
 
Example 21
Project: xEssentials-deprecated-bukkit   File: HumanSpamEvent.java   View source code 5 votes vote down vote up
@EventHandler(priority = EventPriority.LOWEST)
public void slowSpamCheck(PlayerChatEvent e) {
	final Player p = (Player) e.getPlayer();
	if(message2.containsKey(e.getPlayer().getName())) {
		if(message2.get(e.getPlayer().getName()).equalsIgnoreCase(e.getMessage())) {
			e.getPlayer().kickPlayer(pl.getConfiguration().getBanConfig().getHumanSpamBanMessage());
			message2.remove(e.getPlayer().getName());
		} else {
			message2.remove(e.getPlayer().getName());
		}
	} else if(message1.containsKey(e.getPlayer().getName())) {
		if(message1.get(e.getPlayer().getName()).equalsIgnoreCase(e.getMessage())) {
			message1.remove(e.getPlayer().getName());
			message2.put(e.getPlayer().getName(), e.getMessage());
			sendMessage(e.getPlayer(), ChatColor.RED + "Warning if you post one more time the same message you will be kicked!");
		} else {
			message1.put(e.getPlayer().getName(), e.getMessage());
		}
	} else {
		message1.put(e.getPlayer().getName(), e.getMessage());
	}
	Bukkit.getScheduler().scheduleSyncDelayedTask(pl, new Runnable() {

		@Override
		public void run() {
			if(message1.containsKey(p.getPlayer().getName())) {
				message1.remove(p.getPlayer().getName());
			} else if(message2.containsKey(p.getPlayer().getName())) {
				message2.remove(p.getPlayer().getName());
			}
		}
	}, 300);
}
 
Example 22
Project: xEssentials-deprecated-bukkit   File: PlayerIgnorePlayerChatEvent.java   View source code 5 votes vote down vote up
@EventHandler(priority = EventPriority.LOWEST)
public void onIgnoreChat(PlayerChatEvent e) {
	for(XPlayer xp : pl.getManagers().getPlayerManager().getPlayers()) {
		if(xp.hasIgnoredPlayers()) {
			if(xp.getIgnoredPlayers().contains(e.getPlayer().getName())) {
				e.getRecipients().remove(xp.getBukkitPlayer());
			}
		}
	}
}
 
Example 23
Project: xEssentials-deprecated-bukkit   File: ChatFormatEvent.java   View source code 5 votes vote down vote up
@EventHandler(priority = EventPriority.HIGHEST)
public void onChat(PlayerChatEvent e) {
	if(e.isCancelled()) {
		return;
	}
	
	String prefix = pl.getConfiguration().getChatConfig().getPrefixByPlayer(e.getPlayer());
	String suffix = pl.getConfiguration().getChatConfig().getSuffixByPlayer(e.getPlayer());
	Player p = e.getPlayer();
	e.setFormat(prefix +  p.getName() + ": " + suffix + e.getMessage());
}
 
Example 24
Project: xEssentials-deprecated-bukkit   File: MuteEvent.java   View source code 5 votes vote down vote up
@EventHandler(priority = EventPriority.HIGHEST)
public void onMute(PlayerChatEvent e) {
	if(pl.getManagers().getPlayerManager().isOnline(e.getPlayer().getName())) {
		XPlayer xp = pl.getManagers().getPlayerManager().getPlayer(e.getPlayer().getName());
		if(xp.isMuted()) {
			if(System.currentTimeMillis() > xp.getMutedTime()) {
				sendMessage(e.getPlayer(), ChatColor.GREEN + "you are now allowed to talk again!");
				xp.unmute();
			} else {
				sendMessage(e.getPlayer(), ChatColor.GREEN + "you are muted! till: " + new Date(xp.getMutedTime()).toString());
				e.setCancelled(true);
			}
		}
	}
}
 
Example 25
Project: xEssentials-deprecated-bukkit   File: DrunkChatEvent.java   View source code 5 votes vote down vote up
@EventHandler(priority = EventPriority.HIGH)
public void onDrunk(PlayerChatEvent e) {
	if(e.isCancelled()) {
		return;
	}
	
	XPlayer xp = pl.getManagers().getPlayerManager().getPlayer(e.getPlayer().getName());
	if(xp.isDrunk()) {
		String derp = xp.getDrunkMessageFrom(e.getMessage(), false);
		e.setMessage(derp);
	}
}
 
Example 26
Project: xEssentials-deprecated-bukkit   File: CallPlayerHighLightEvent.java   View source code 5 votes vote down vote up
@EventHandler
public void onChatHighLightEvent(PlayerChatEvent e) {
	List<String> playerList = new ArrayList<String>();
	String[] args = e.getMessage().split(" ");
	for(int i = 0; i < args.length; i++) {
		String name = args[i].replace("?", "").replace(",", "").replace(":", "").replace("=", "").replace("!", "").replace(".", "");
		if(pl.getManagers().getPlayerManager().isEssentialsPlayer(name)) {
			playerList.add(name);
		}
	}
	String[] PlayerNames = playerList.toArray(new String[playerList.size()]);
	if(PlayerNames.length > 0) {
		Bukkit.getPluginManager().callEvent(new PlayerChatHighLightEvent(e, PlayerNames, pl));
	}
}
 
Example 27
Project: xEssentials-deprecated-bukkit   File: AfkCheckEvent.java   View source code 5 votes vote down vote up
@EventHandler
public void chatAfk(PlayerChatEvent e) {
	for(XPlayer xp : pl.getManagers().getPlayerManager().getPlayers()) {
		if(e.getMessage().contains(xp.getBukkitPlayer().getName())) {
			if(xp.isAfk()) {
				sendMessage(e.getPlayer(), ChatColor.GREEN + xp.getBukkitPlayer().getName() + " has been afk [ " + xp.getAfkReason() + " ]");
			}
		}
	}
}
 
Example 28
Project: xEssentials_old_Source   File: muteManager.java   View source code 5 votes vote down vote up
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void getMutes(PlayerChatEvent e) {
	if(isMuted(e.getPlayer())) {
		Long time = (Long) xEssentialsMemory.returnPlayer(e.getPlayer()).get("muted");
		if(timeunits.isOverTime(time)) {
			xEssentialsMemory.returnPlayer(e.getPlayer()).put("muted", 0);
			xEssentialsMemory.updatePlayerConfig(e.getPlayer());	
		} else {
			e.setCancelled(true);
		}
	}
}
 
Example 29
Project: xEssentials_old_Source   File: AntiFloodSpam.java   View source code 5 votes vote down vote up
@EventHandler
public void playerChatTime(PlayerChatEvent e) {
	if(chatTime.containsKey(e.getPlayer().getName())) {
		if(System.currentTimeMillis() < chatTime.get(e.getPlayer().getName())) {
			cmdban.setBanned(xEssentialsMemory.antiFloodSpamMessage, e.getPlayer(), banType.floodspam);
		} else {
			chatTime.remove(e.getPlayer().getName());
		}
	} else {
		chatTime.put(e.getPlayer().getName(), System.currentTimeMillis());
	}
}
 
Example 30
Project: PetBlocks   File: PetDataListener.java   View source code 4 votes vote down vote up
@EventHandler(priority = EventPriority.HIGHEST)
public void playerChatEvent(PlayerChatEvent event) {
    if (!Config.getInstance().isChat_async() && Config.getInstance().isChatHighestPriority()) {
        this.handleChatMessage(event);
    }
}
 
Example 31
Project: PetBlocks   File: PetDataListener.java   View source code 4 votes vote down vote up
@EventHandler(priority = EventPriority.LOWEST)
public void playerChatEvent2(PlayerChatEvent event) {
    if (!Config.getInstance().isChat_async() && !Config.getInstance().isChatHighestPriority()) {
        this.handleChatMessage(event);
    }
}
 
Example 32
Project: SurvivalPlus   File: LocalChat.java   View source code 4 votes vote down vote up
@EventHandler(priority = EventPriority.HIGHEST)
public void onChat(PlayerChatEvent event)
{
	if(event.isCancelled()) return;
	Player player = event.getPlayer();
	String msg = event.getMessage();
	
	if(Survival.settings.getBoolean("LegendaryItems.GoldArmorBuff"))
	{
		if(player.getInventory().getHelmet() != null)
		{
			if(player.getInventory().getHelmet().getType() == Material.GOLD_HELMET)
			{
				event.setCancelled(false);
				event.setFormat(ChatColor.GOLD + "<%1$s> " + ChatColor.YELLOW + "%2$s");
				return;
			}
		}
	}
	
	int channel = Survival.board.getObjective("Chat").getScore(player).getScore();
	if(channel > 0)
	{
		event.setFormat(ChatColor.GREEN + "<%1$s> " + ChatColor.RESET + "%2$s");
		return;
	}
	
	event.setCancelled(true);

	Bukkit.getConsoleSender().sendMessage("<" + player.getDisplayName() + "> " + msg);
	for(Player other : Bukkit.getServer().getOnlinePlayers())
       {
		if(other.getLocation().getWorld() == player.getLocation().getWorld())
		{
            if(other.getLocation().distance(player.getLocation()) <= maxDist)
            {
                other.sendMessage(ChatColor.RESET + "<" + player.getDisplayName() + "> " + msg);
            }
		}
       }
}
 
Example 33
Project: ChatModerator   File: ChatModeratorListener.java   View source code 4 votes vote down vote up
@SuppressWarnings("deprecation")
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
public void onPlayerChat(final PlayerChatEvent event) {
    Zone chatZone = this.getZoneManager().getZone(ZoneType.CHAT);

    if (!(chatZone.isEnabled()) || event.getPlayer() == null) {
        return;
    }

    String message = Preconditions.checkNotNull(event, "Event").getMessage();
    Player player = event.getPlayer();

    FixedMessage fixedMessage = new FixedMessage(message, Instant.now());

    for (Filter filter : this.getFilterManager().getFiltersForZone(chatZone)) {
        if (fixedMessage.getFixed() == null || fixedMessage.getFixed().equals("")) {
            break;
        }

        filter.filter(fixedMessage, player, ZoneType.CHAT, event);
    }
    this.plugin.getPlayerManager().getViolationSet(player).setLastMessage(fixedMessage);

    event.setMessage(fixedMessage.getOriginal());

    for (Violation v : plugin.getPlayerManager().getViolationSet(player).getViolationsForTime(fixedMessage.getTimeSent())) {
        if (v.isCancelled()) {
            event.setMessage(null);
            event.setCancelled(true);
            break;
        }

        if (v.isFixed()) {
            event.setMessage(fixedMessage.getFixed());
        }
    }

    if (event.getMessage() == null) {
        event.setCancelled(true);
    }
}
 
Example 34
Project: Skript   File: PlayerChatEventHandler.java   View source code 4 votes vote down vote up
public final static void registerChatEvent(final EventPriority priority, final EventExecutor executor, final boolean ignoreCancelled) {
	if (Skript.classExists("org.bukkit.event.player.AsyncPlayerChatEvent"))
		Bukkit.getPluginManager().registerEvent(AsyncPlayerChatEvent.class, new Listener() {}, priority, executor, Skript.getInstance(), ignoreCancelled);
	else
		Bukkit.getPluginManager().registerEvent(PlayerChatEvent.class, new Listener() {}, priority, executor, Skript.getInstance(), ignoreCancelled);
}
 
Example 35
Project: JAATP   File: ChatFormat.java   View source code 4 votes vote down vote up
@EventHandler
public void onChat(PlayerChatEvent evt){
	
	String message = evt.getMessage();
	String player = evt.getPlayer().getDisplayName();
	String pex_prefix = "";
	
	//PEX
	if(HookManager.isEnabled(Bukkit.getPluginManager().getPlugin("PermissionsEx"))){
		
		pex_prefix = HookManager.getPexHook().getPrefix(evt.getPlayer());
		
		
	}
	
	
	
	if(!MainConfig.USE_CUSTOM_FORMAT) return;
	evt.setFormat(MainConfig.CUSTOM_CHAT_FORMAT.replaceAll("\\{MESSAGE}", message).replaceAll("\\{PLAYER}", player).replaceAll("\\{PEX_PREFIX}", pex_prefix));
	
	
}
 
Example 36
Project: xEssentials-deprecated-bukkit   File: AntiSwearEvent.java   View source code 4 votes vote down vote up
@EventHandler
public void onChat(PlayerChatEvent e) {
	if(e.isCancelled()) {
		return;
	}

	boolean warning = false;

	Pattern pat = Pattern.compile("[A-Za-z]");
	Pattern p = Pattern.compile(pl.getConfiguration().getChatConfig().getSwearWords(), Pattern.CASE_INSENSITIVE);

	StringBuilder build = new StringBuilder(e.getMessage());

	Matcher match = p.matcher(e.getMessage());

	while(match.find()) {
		if(pl.getConfiguration().getChatConfig().isSwearWarningEnabled()) {
			if(match.group().length() > 0) {
				if(!warning) { //if true it means we ignore it because a chat could have more swear words than just one we count 1 warning per message.
					warning = true;
					if(warnings.containsKey(e.getPlayer().getName())) {
						int level = warnings.get(e.getPlayer().getName());
						if((level+1) > pl.getConfiguration().getChatConfig().getMaxWarningLevel()) {
							warnings.remove(e.getPlayer().getName());
							if(pl.getConfiguration().getDebugConfig().isEnabled()) {
								xEssentials.log("the console should now sent this command: " + pl.getConfiguration().getChatConfig().getWarningCommand().replaceAll("%p", e.getPlayer().getName()), LogType.DEBUG);
							}
							Bukkit.dispatchCommand(Bukkit.getConsoleSender(), pl.getConfiguration().getChatConfig().getWarningCommand().replaceAll("%p", e.getPlayer().getName()));
							e.setCancelled(true);
							return; //no need to go futher within the message.
						} else {
							warnings.put(e.getPlayer().getName(), (level+1));
							sendMessage(e.getPlayer(), pl.getConfiguration().getChatConfig().getWarningMessage().replaceAll("%w", (level+1)+"/"+pl.getConfiguration().getChatConfig().getMaxWarningLevel()));
						}
					} else {
						warnings.put(e.getPlayer().getName(), 1);
						sendMessage(e.getPlayer(), pl.getConfiguration().getChatConfig().getWarningMessage().replaceAll("%w", "1" + "/"+pl.getConfiguration().getChatConfig().getMaxWarningLevel()));
					}
				}
			}
		}

		build.replace(match.start(), match.end(), pat.matcher(match.group()).replaceAll("*"));
	}
	e.setMessage(build.toString());		
}
 
Example 37
Project: xEssentials-deprecated-bukkit   File: AntiAddvertiseEvent.java   View source code 4 votes vote down vote up
@EventHandler
public void onAntiAddvertise(PlayerChatEvent e) {
	XPlayer xp = pl.getManagers().getPlayerManager().getPlayer(e.getPlayer().getName());
	e.setMessage(ipcheck(e.getMessage(), xp));
}
 
Example 38
Project: xEssentials-deprecated-bukkit   File: PlayerChatSmilleyEvent.java   View source code 4 votes vote down vote up
public PlayerChatSmilleyEvent(PlayerChatEvent e, String[] CalledSmilleys, xEssentials pl) {
	super(e.getPlayer());
	this.e = e;
	this.CalledSmilleys = CalledSmilleys;
	this.pl = pl;
}
 
Example 39
Project: xEssentials-deprecated-bukkit   File: PlayerChatHighLightEvent.java   View source code 4 votes vote down vote up
public PlayerChatHighLightEvent(PlayerChatEvent e, String[] CalledPlayerNames, xEssentials pl) {
	super(e.getPlayer());
	this.e = e;
	this.CalledPlayerNames = CalledPlayerNames;
	this.pl = pl;
}