ChatFeelings API

Sep 15, 2019
ChatFeelings API
  • [​IMG]

    Welcome!
    The ChatFeelingsAPI was created with the developer in mind.
    Making it as easy as possible to add your own touch to your server.


    Adding a Soft Dependency

    First, let's make sure that ChatFeelings is included as a soft-dependency in your plugin.yml so that way ChatFeelings is started before your plugin.
    Code (Text):
    name: MyTestPlugin
    version: 0.1
    main: com.zach_attack.my_plugin.Main
    softdepend: [ChatFeelings]
    api-version: 1.14
    As you can see, we added softdepend: ChatFeelings
    to our plugin.yml. Do note that the other variables can be changed to your liking :)


    Adding an onEnable() check

    Second, let's make sure that ChatFeelings is available to use on this server. To do so, we will be using a boolean that we can just check if it's true before using anything.
    Code (Java):
    public class Main extends JavaPlugin implements Listener {
        boolean useCF;
        public void onEnable() {
            if (getServer().getPluginManager().isPluginEnabled("ChatFeelings") &&
             (getServer().getPluginManager().getPlugin("ChatFeelings") != null))  {
                useCF = true;
            } else {
                useCF = false;
            }
        }
    }

    Code Explanation:
    boolean useCF; - This is just a variable that is either true or false. Right now it has no setting until the onEnable() sets it to true or false.

    if (getServer().getPluginManager().isPluginEnabled("ChatFeelings") &&
    (getServer().getPluginManager().getPlugin("ChatFeelings")
    != null)) - This line checks to see if ChatFeelings is not only enabled, but also not returning null. (Basically ensuring we can use the API without any problems)

    useCF = true; - This sets that boolean we told you about earlier to true. Now we can do if(useCF) { } to run things only if ChatFeelings is available.


    Adding Functionality
    Now onto the good stuff. For the sake of simplicity, we are going to check if ChatFeelings is available using our boolean, and if(useCF) is true, we will see if a player is muted on join, and send them a message..

    Now, after our onEnable(), we are going to check for PlayerJoinEvent and see if they’re muted. This checks Chatfeelings’ mute system in addition to Essentials, LiteBans, & AdvancedBan.
    Code (Java):
        @EventHandler
        public void onJoin(PlayerJoinEvent e)
        {
            Player player = e.getPlayer();
     
            if(useCF) {  // Checks that boolean from our onEnable if ChatFeelings is ready to use.
            if(ChatFeelingsAPI.isMuted(player)) {  // Checks through all plugins and CF on the server to see if the player is muted.
                    player.sendMessage(¨You are unable to use ChatFeelingś emotions.");
                 }
            }
        }
    }
    Code Explanation:
    @EventHandler - Tells our plugin to listen to the event we are about to declare below.

    public void onJoin(PlayerJoinEvent e) - This is us saying that we want to do what's below on PlayerJoinEvent, AKA, when the player joins the server.

    if(useCF) - This tells the plugin, only do what's below if ChatFeelings is loaded. You can get this to work by doing the code put above where we specify the boolean in the onEnable(). While optional, it's a nice thing to have to prevent any errors on every single join if the plugin is ever not found.

    Player player = e.getPlayer(); - This just helps us not have to type e.getPlayer() everytime we want the player from the event. Also is a bit more efficient.

    ChatFeelingsAPI.isMuted(playername) - Similar to ChatFeelingsAPI.isBanned(playername), this checks through any loaded ignoring/mute plugins in addition to ChatFeeling's own database to test and see if a certain player is muted from chatting on the server. There is no need to use ChatFeelingsAPI.hasPlayedBefore, as isMuted will check for you!

    Events
    ChatFeelings also has 3 events you can listen to. I'm going to assume you understand how events typically work. If you don't understand, I layed the basics out above for you. (Just replace PlayerJoinEvent with these events)

    • FeelingRecieveEvent - Fires before a player receives a feeling. This can be cancelled, and returns the sender, the target, and the feeling received (as a string).

    • FeelingSendEvent - Fires before a player sends a feeling to someone and passes all the ChatFeelings checks. Can also be cancelled, and returns the sender, their target, and the feeling sent (as a string).

    • FeelingGlobalNotifyEvent - Fires for every notification sent to a player (only when global feelings are enabled). Returns the player the notification was sent to (p), the person who sent the feeling, the target of said feeling, and the feeling that was sent. This can be cancelled, but doing so will just cancel the notification.

    Need Help? Having Trouble?
    If you're having issues using our API, please join our support discord below!

    [​IMG]


    Click to view our GitHub
  • Loading...
  • Loading...