Dudemister1999

eCrud Example Plugin

Oct 26th, 2014
34
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import org.bukkit.Bukkit;
  2. import org.bukkit.entity.Player;
  3. import org.bukkit.event.EventHandler;
  4. import org.bukkit.event.Listener;
  5. import org.bukkit.event.player.PlayerJoinEvent;
  6. import org.bukkit.plugin.java.JavaPlugin;
  7.  
  8. public class ExamplePlugin extends JavaPlugin implements Listener
  9. {
  10.     private Config cfg;
  11.    
  12.     public static String joinMessage = "&cWelcome, &6{player}!";
  13.     public static boolean replaceJoinMessage = true;
  14.    
  15.     @Override
  16.     public void onEnable()
  17.     {
  18.         Bukkit.getPluginManager().registerEvents(this, this);
  19.         cfg = ConfigManager.createConfig(getDataFolder(), "config.yml");
  20.        
  21.         if(cfg.getYaml().contains("join.message") && cfg.getYaml().contains("join.replacemessage"))
  22.         {
  23.             replaceJoinMessage = (boolean)cfg.getValue("join.replacemessage", true);
  24.             joinMessage = (String)cfg.getValue("join.message");
  25.         }
  26.         else
  27.         {
  28.             cfg.setValue("join.message", joinMessage);
  29.             cfg.setValue("join.replacemessage", true);
  30.         }
  31.     }
  32.    
  33.     @Override
  34.     public void onDisable()
  35.     {
  36.         ConfigManager.onDisable();
  37.     }
  38.    
  39.     @EventHandler
  40.     public void join(PlayerJoinEvent event)
  41.     {
  42.         Player player = event.getPlayer();
  43.        
  44.         if(replaceJoinMessage)
  45.         {
  46.             event.setJoinMessage(ChatColor.translateAlternateColorCodes('&', joinMessage.replaceAll("{player}", player.getDisplayName())));
  47.         }
  48.     }
  49. }
RAW Paste Data