Skocz do zawartości
  • 0

Wchodznie na nicku o takim samym nicku lecz Dużych/Małych zankach


sKNIGHT
 Udostępnij

Pytanie

9 odpowiedzi na to pytanie

Rekomendowane odpowiedzi

  • 0
49 minut temu, sKNIGHT napisał:

na razie żadnego ale jak w funnyguilds tak się zrobi to wtedy graczoiw setuje punkty na 0 i chce takie cos

No to się nie dziw. Wgraj ten plugin i będzie okej :) Zarejestruj się lub zaloguj, aby zobaczyć ukrytą treść!

Odnośnik do komentarza
Udostępnij na innych stronach

  • 0

No to najprościej będzie stworzyć bazę danych i bawić się funkcją onPlayerJoin + zapisywanie nicku do bazy danych.

Jak chcesz to masz tu gotowy skrypt do podłączenia pluginu pod bazę danych:

Spoiler
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;




public class MySQL {

	protected static Connection connection = null;
	
	String ip = "";
	String port = "";
	String user = "";
	String password = "";
	String database = "";
	
	public MySQL( String ip, String port, String user, String password, String database ) 
	{
		this.ip = ip;
		this.port = port;
		this.user = user;
		this.password = password;
		this.database = database;
		
		if( isOpen() ){
			System.out.println("MYSQL> Connection is open!");
			return;
		}
		
        try {
            Class.forName("com.mysql.jdbc.Driver").newInstance();
        } catch (Exception ex) {
            System.err.println(ex.getMessage());
        }
		
		try {
			connection = DriverManager.getConnection("jdbc:mysql://" + ip + ":" + port + "/" + database, user, password );
		} catch (Exception e) {
			System.out.println("MYSQL> Can't close connection witch database!");
			e.printStackTrace();
		}
		System.out.println("MYSQL> Connection was opened");
	}

	public void createTable( String table, String args) {
		
		try {
			Statement st = connection.createStatement();
		      
		     try {
		         String nowa_tabela = "CREATE TABLE IF NOT EXISTS " + table +"( " + args + " ) DEFAULT CHARSET=cp1250 collate cp1250_polish_ci"; 
		         st.executeUpdate(nowa_tabela);
		         st.close();      
		     } catch (SQLException e){
		    	 e.printStackTrace();
		    	 st.close();
		    	 System.out.println("MYSQL> Can't create table!");
		     } 
		} catch (SQLException e) {
			refreshConnection();
			System.out.println("MYSQL> No connected to the database!");
		} 
	}

	
	public void addRecord(String table, String args) {
		
		if( !isOpen() ){
			System.out.println("MYSQL> No connected to the database!");
			return;
		}
		try {
			Statement st = connection.createStatement();
			try {
				st.executeUpdate( "INSERT IGNORE " + table + " VALUES ( " + args + ")" );
				st.close();
			}
			   
			catch (SQLException e) {
				e.printStackTrace();
				st.close();
				System.out.println("MYSQL> Can't add new record!");
				System.out.println("INSERT IGNORE " + table + " VALUES ( " + args + ")");
			} 
		} catch (SQLException e) {
			refreshConnection();
			System.out.println("MYSQL> No connected to the database!");
		}
	}


	
	public void updateRecord(String table, String column, Object record, String where ) {
		
		if( !isOpen() ){
			System.out.println("MYSQL> No connected to the database!");
			return;
		}
		
		try {
			Statement st = connection.createStatement();

			try {
	        	st.executeUpdate("UPDATE " + table + " SET " + column + " = '" + record + "' WHERE " + where);
	        	st.close();
	        }
			catch (SQLException e) {
				e.printStackTrace();
				st.close();
				System.out.println("MYSQL> Can't update record!");
				System.out.println("UPDATE " + table + " SET " + column + " = '" + record + "' WHERE " + where);
			}	
		} catch (SQLException e) {
			refreshConnection();
			System.out.println("MYSQL> No connected to the database!");
		}
	}
	

	public void insertRecord(String table, String column, String column2, String record, long record2) {
		
		if( !isOpen() ){
			System.out.println("MYSQL> No connected to the database!");
			return;
		}
		
		try {
			Statement st = connection.createStatement();

			try {
	        	st.executeUpdate("INSERT INTO " + "`" + table + "`" + " (`" + column + "`," + " `" + column2 + "`)" + " VALUES " + "('" + record + "', '"+ record2 + "');");
	        	st.close();
	        }
			catch (SQLException e) {
				e.printStackTrace();
				st.close();
				System.out.println("MYSQL> Can't update record!");
				System.out.println("INSERT INTO " + "`" + table + "`" + " (`" + column + "`," + " `" + column2 + "`)" + " VALUES " + "('" + record + "', '"+ record2 + "');");
			}	
		} catch (SQLException e) {
			refreshConnection();
			System.out.println("MYSQL> No connected to the database!");
		}
	}
	
	public void removeRecord(String table, String where_args) {	   
		try {
			
			Statement st = connection.createStatement();
			
			try {
				st.executeUpdate("DELETE FROM " + table + " WHERE " + where_args);
				st.close();
			}
			   
			catch (SQLException e) {
				e.printStackTrace();
				st.close();
				System.out.println("MYSQL> Can't remove record!");
				System.out.println("DELETE FROM " + table + " WHERE " + where_args);
			} 
		} catch (SQLException e) {
			refreshConnection();
			System.out.println("MYSQL> No connected to the database!");
		}
	}
	
	public Object getRecord(String table, String column, String where_args){
		
		try {
			Statement st = connection.createStatement();
			
			try {
				ResultSet rs = st.executeQuery("SELECT " + column + " FROM " + table + " WHERE " + where_args);
				rs.next();
				
				return rs.getObject(1);
			} 

			catch (SQLException e) {
				e.printStackTrace();
				st.close();
				
				System.out.println("MYSQL> Can't get record from database!");
				System.out.println("SELECT " + column + " FROM " + table + " WHERE " + where_args);
				return null;
			}   
		} catch (SQLException e) {
			refreshConnection();
			System.out.println("MYSQL> No connected to the database!");
			return null;
		}
	}
	
	public boolean checkRecord(String table, String where_args){
		
		try {
			Statement st = connection.createStatement();
			
			try {
				ResultSet rs = st.executeQuery("SELECT * FROM " + table + " WHERE " + where_args);
				
				if( rs.next() ) return true;
				return false;
				
			} 

			catch (SQLException e) {
				e.printStackTrace();
				st.close();
				
				System.out.println("MYSQL> Can't check record!");
				System.out.println("SELECT * FROM " + table + " WHERE " + where_args);
				return false;
			}   
		} catch (SQLException e) {
			e.printStackTrace();
			refreshConnection();
			System.out.println("MYSQL> No connected to the database!");
			return false;
		}
	}
	
	public boolean isOpen(){
		if( connection == null ) return false;
		try {
			if( !connection.isClosed() ) return true;
			else return false;
		} catch (SQLException e) {
			e.printStackTrace();
			return false;	
		}
	}
	
	public void open(){
		
		if( isOpen() ){
			System.out.println("MYSQL> Connection is open!");
			return;
		}
		
        try {
            Class.forName("com.mysql.jdbc.Driver").newInstance();
        } catch (Exception ex) {
            System.err.println(ex.getMessage());
        }
		
		try {
			connection = DriverManager.getConnection("jdbc:mysql://" + ip + ":" + port + "/" + database, user, password );
		} catch (Exception e) {
			System.out.println("MYSQL> Can't close connection witch database!");
			e.printStackTrace();
		}
		if( !isOpen() ) System.out.println("MySQL> Can't open connection!");
	}
	
	public void close(){
		
		if( !isOpen() ){
			System.out.println("MYSQL> No connected to the database!");
			return;
		}
		
        try {
            Class.forName("com.mysql.jdbc.Driver").newInstance();
        } catch (Exception ex) {
            System.err.println(ex.getMessage());
        }
		
		try {
			connection.close();
		} catch (Exception e) {
			System.out.println("MYSQL> Can't close connection witch database!");
			e.printStackTrace();
		}
	}	
	
	
	public void refreshConnection()
	{
		close();
		open();
		if( isOpen() ) System.out.println("MySQL> Connection was refreshed!");
		else System.out.println("MySQL> Can't refresh connection!");
	}
	
}

 

 

Edytowane przez Arczi98
Odnośnik do komentarza
Udostępnij na innych stronach

  • 0
/*
Obiekt user
*/

private String nickname;

public User(..., String nickname){
	...
	this.nickname = nickname;
}

public String getNickname(){
	return this.nickname;
}

/*
event onjoin, listener
*/

public class PlayerConnectListener implements Listener{
	
	@EventHandler
	public void onConnect(AsyncPlayerPreLoginEvent e){
		final User u = User.get(...);
		if (!/*e.getnickname/*.equals(u.getNickname()){
			e.dissalow(...KICK_OTHER, ChatColor.GREEN+"Twoj poprawny nick: "+u.getNickname());
		}
	}
}

 

Odnośnik do komentarza
Udostępnij na innych stronach

Nieaktywny
Ten temat został zamknięty. Brak możliwości dodania odpowiedzi.
 Udostępnij

  • Ostatnio przeglądający   0 użytkowników

    • Brak zarejestrowanych użytkowników przeglądających tę stronę.
×
×
  • Dodaj nową pozycję...