Minecraft Blogs / Tutorial

[Bukkit Coding] How to code a custom join message.

  • 8,663 views, 1 today
  • 2
  • 0
  • 6
Masstrix's Avatar Masstrix
Level 43 : Master Botanist
29
How to start off.Good place to start of with: Plugin Tutorial

If you found this helpfull give it a diamond!

Importing - click to reveal
To start of you have to import you .jar
1.downlaod the latest bukkit
2.right click on your project folder and goto properties
3.under Java Build Class go add External Jars
4.locate you bukkit.jar and add it
5.done!
How to make it a .jar - click to reveal
How to export:
1. Goto file, export
2. Save it as a jar the hit next
3. Select your resorce then hit Finish
4.Put it in your plugins folder and have fun coding!
To allow Bukkit to load your plugin, you must create the plugin.yml file. This file will contain essential information, and without it your plugin will NOT work. This time we want to right click on src/main/resources. Select New > File. Name the file "plugin.yml" and click finish.
plugin.yml - click to reveal
name: <plugin name>
main: me.<main package>.<main class>
version: <version>
description: <descrpition>
author: <your name>
permissions:
          lobby.join.test:
            description: <description>
Now you have setup the project and the main class. To allow Bukkit to load your plugin, you must create the config.yml file. This file will contain essential information,This time we want to right click on src/main/resources. Select New > File. Name the file "config.yml" and click finish
config.yml - click to reveal
# Use: %player% for a players name

test: '&d[Join] %player% has joined'
main class / code - click to reveal
package me.<your name>.<class>;

import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.plugin.java.JavaPlugin;

public final class Join extends JavaPlugin implements Listener {

              public void onEnable() {
              saveDefaultConfig();
              //save config on startup/reload
              }

              @EventHandler
              public void onJoin(PlayerJoinEvent event){
                      for (Player player: Bukkit.getServer().getOnlinePlayers()) {

                            if (player.hasPermission("lobby.join.test")) {
                            //check for player has permission

                                event.setJoinMessage(getConfig().getString("test").replace("&", "§").replace("%player%", player.getDisplayName()));
//set player join message by config

                           } else {
                           event.setJoinMessage("");
                           //if player has no permission set message to null
                           }
                  }

         }

         @EventHandler
          public void onQuit(PlayerQuitEvent event) {
                  event.setQuitMessage("");
                  //set quit message to null
                }

}
Tags

Create an account or sign in to comment.

1
06/04/2016 6:07 am
Level 32 : Artisan Architect
DeagleScope
DeagleScope's Avatar
Can you update like add prefix
1
06/12/2016 8:55 am
Level 43 : Master Botanist
Masstrix
Masstrix's Avatar
As in like adding a prefix to the join message?
1
06/24/2016 5:20 am
Level 32 : Artisan Architect
DeagleScope
DeagleScope's Avatar
yeah like %prefix% %player% has joined :D
1
06/24/2016 6:36 am
Level 43 : Master Botanist
Masstrix
Masstrix's Avatar
If you want to add a prefix to the message you can achieve in multiple ways, the simple on being storing all the prefixes/suffixes in the plugins config then having a permission for each one and just add them into the users group to apply them. While in the chat format you get those prefixes/suffixes and adding them into the message's format.

The other way would be using the permission plugins API (if it has one) and getting the players prefix and adding it into the chat format.

Both work just as well, making a plugin less reliant on another plugin can be very useful if your making a public plugin as it means you don't need to worry about the relent plugins going out of date or waiting for them to update.

Personally I do everything custom now and just have everything all working under a single mainframe to manage everything when I do my custom systems. But that is only useful if it's a one off and it won't be used publicly really.
1
02/04/2016 3:36 pm
Level 1 : New Miner
Antonventa
Antonventa's Avatar
thanks for this :D
1
02/05/2016 8:29 pm
Level 43 : Master Botanist
Masstrix
Masstrix's Avatar
Thanks :)
Planet Minecraft

Website

© 2010 - 2024
www.planetminecraft.com

Welcome