Jump to content
View in the app

A better way to browse. Learn more.

ClassiCube Forum

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Cancel event in MCGalaxy plugin using C#

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);
            }
        }
    }
}

 

Solved by Goodly

Go to solution

Featured Replies

p.cancelchat = true;

This is how the chat event should be cancelled.

Edited by deewend

  • Solution

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!";
}

 

READ THE RULES BEFORE YOU POST

Create an account or sign in to comment

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.