Advertisement
WinSide

Untitled

Nov 22nd, 2016
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.33 KB | None | 0 0
  1. public class WMFLMain extends JavaPlugin implements Listener {
  2.  
  3.     private File configFile = new File(getDataFolder() + File.separator, "config.yml");
  4.     private FileConfiguration config = YamlConfiguration.loadConfiguration(configFile);
  5.  
  6.     private Map<String, String> map = new TreeMap<String, String>();
  7.  
  8.     private String defaultMsg = "Welcome %PLAYER% on server.";
  9.  
  10.     @Override
  11.     public void onEnable() {
  12.         Bukkit.getPluginManager().registerEvents(this, this);
  13.         try {
  14.             loadConfiguration();
  15.         } catch (IOException e) {
  16.             e.printStackTrace();
  17.         }
  18.     }
  19.  
  20.     public void loadConfiguration() throws IOException {
  21.         config.addDefault("defaultMsg", defaultMsg);
  22.         config.addDefault("lliyt.msg", "Welcome dno :)");
  23.         config.options().copyDefaults(true);
  24.         config.save(configFile);
  25.         defaultMsg = config.getString("defaultMsg");
  26.         for (String key : config.getKeys(false)) {
  27.             map.put(key.toLowerCase(), config.getString(key + ".msg"));
  28.         }
  29.     }
  30.  
  31.     @EventHandler
  32.     public void onPlayerJoin(PlayerJoinEvent event) {
  33.         String playerName = event.getPlayer().getDisplayName();
  34.         event.setJoinMessage(defaultMsg.replaceAll("%PLAYER%", playerName));
  35.         if (map.containsKey(playerName.toLowerCase())) {
  36.             event.getPlayer().sendMessage(map.get(playerName.toLowerCase()).replaceAll("%PLAYER%", playerName).replaceAll("&([0-9a-f])", "\u00A7$1"));
  37.         }
  38.     }
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement