Jump to content
  • Sign Up
  • 0
AllergenX

Cancel event in MCGalaxy plugin using C#

Question

I am trying to make a tone indicators plugin, where when people say something like '\j', it puts JOKING in their chat message

But I can't figure out how to cancel events, since I don't want the player to send the chat message and instead have the server send it with the word "JOKING" in it.

Here's my code incase needed:
 

using System;
using MCGalaxy;
using MCGalaxy.Events.ServerEvents;
using MCGalaxy.Events.PlayerEvents;


namespace PluginToneIndicators
{
    public sealed class ToneIndicators : Plugin 
    {
        public override string name { get { return "ToneIndicators"; } }
        public override string MCGalaxy_Version { get { return "0.1"; } }
        public override string creator { get { return "AllergenX"; } }
        
        public override void Load(bool startup) {
            OnPlayerChatEvent.Register(HandlePlayerChat, Priority.High);
        }
        
        public override void Unload(bool shutdown) {
            OnPlayerChatEvent.Unregister(HandlePlayerChat);
        }

        static void HandlePlayerChat(Player p, string message)
        {
            if (message.Contains("\\j") == true)
            {
                // Cancel the event somehow
                // Ignore the rest of the code from this comment
                Chat.Message(ChatScope.Global, "&aJOKING", null, null, true);
            }
        }
    }
}

 

Share this post


Link to post

2 answers to this question

Recommended Posts

  • 1

To modify messages sent by players, use OnChatEvent and modify the ref "msg" argument. I believe you will need to be using the latest build of MCGalaxy to do this, though. You can find latest builds here: https://123dmwm.com/MCGalaxy/

https://github.com/ClassiCube/MCGalaxy/blob/master/MCGalaxy/Events/ServerEvents.cs#L107

For instance

public static void OnChat(ChatScope scope, Player source, ref string msg, object arg, ref ChatMessageFilter filter, bool relay) {
	if (message.CaselessContains("sign")) msg += " I STEPPED ON THE SIGN!";
}

 

Share this post


Link to post
  • -1
Posted (edited)
p.cancelchat = true;

This is how the chat event should be cancelled.

Edited by deewend

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...