Untitled

mail@pastecode.io avatar
unknown
plain_text
6 months ago
1.6 kB
0
Indexable
Never
package org.lifestealsmp.ipauthlogin;

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.plugin.java.JavaPlugin;

public class main extends JavaPlugin implements Listener{

    public void onEnable() {
        Bukkit.getServer().getPluginManager().registerEvents(this, this);
        saveDefaultConfig();
    }
	
	@EventHandler
	public void onPlayerJoin(PlayerJoinEvent event) {
		Player player = (Player) event.getPlayer();
		String playerAddress = player.getAddress().getAddress().getHostAddress();
		if(!player.hasPlayedBefore()) {
			getConfig().set(player.getName(), playerAddress); 
			saveConfig();
			player.performCommand("register " + playerAddress + " " + playerAddress);
			Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "authme forcelogin " + player.getName());
		    return;
		}
		
		if(getConfig().contains(player.getName())) {
			String configAddress = getConfig().getString(player.getName());
			if (playerAddress.equals(configAddress)) {
				Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "authme forcelogin " + player.getName());
			    return;
			} 
		} else {
			getConfig().set(player.getName(), playerAddress); 
			saveConfig();
			Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "authme password " + player.getName() + " " + playerAddress);
			Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "authme forcelogin " + player.getName());
		    return;
		}
	}
}
Leave a Comment