Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class WMFLMain extends JavaPlugin implements Listener {
- private File configFile = new File(getDataFolder() + File.separator, "config.yml");
- private FileConfiguration config = YamlConfiguration.loadConfiguration(configFile);
- private Map<String, String> map = new TreeMap<String, String>();
- private String defaultMsg = "Welcome %PLAYER% on server.";
- @Override
- public void onEnable() {
- Bukkit.getPluginManager().registerEvents(this, this);
- try {
- loadConfiguration();
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- public void loadConfiguration() throws IOException {
- config.addDefault("defaultMsg", defaultMsg);
- config.addDefault("lliyt.msg", "Welcome dno :)");
- config.options().copyDefaults(true);
- config.save(configFile);
- defaultMsg = config.getString("defaultMsg");
- for (String key : config.getKeys(false)) {
- map.put(key.toLowerCase(), config.getString(key + ".msg"));
- }
- }
- @EventHandler
- public void onPlayerJoin(PlayerJoinEvent event) {
- String playerName = event.getPlayer().getDisplayName();
- event.setJoinMessage(defaultMsg.replaceAll("%PLAYER%", playerName));
- if (map.containsKey(playerName.toLowerCase())) {
- event.getPlayer().sendMessage(map.get(playerName.toLowerCase()).replaceAll("%PLAYER%", playerName).replaceAll("&([0-9a-f])", "\u00A7$1"));
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement