Advertisement
Guest User

Untitled

a guest
Sep 15th, 2019
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.52 KB | None | 0 0
  1. package me.MCBankApp;
  2.  
  3. import java.io.IOException;
  4. import java.io.InputStream;
  5. import java.io.OutputStream;
  6. import java.net.InetAddress;
  7. import java.net.Socket;
  8. import java.net.UnknownHostException;
  9. import java.nio.charset.StandardCharsets;
  10. import java.util.ArrayList;
  11. import org.bukkit.command.CommandExecutor;
  12. import org.bukkit.plugin.java.JavaPlugin;
  13. import me.MCBankApp.Commands.*;
  14.  
  15. public class Main extends JavaPlugin{
  16.    
  17.     public static ArrayList<OnlineUser> users = new ArrayList<OnlineUser>();
  18.    
  19.     static Socket clientSocket;
  20.    
  21.     public void onEnable(){
  22.         try {
  23.             clientSocket();
  24.         } catch (Exception e)
  25.         {
  26.            
  27.         }
  28.        
  29.         new ListenerClass(this);
  30.        
  31.         this.getCommand("check").setExecutor((CommandExecutor) new Check());   
  32.         this.getCommand("login").setExecutor((CommandExecutor) new Login());
  33.         this.getCommand("signup").setExecutor((CommandExecutor) new Signup());
  34.         this.getCommand("logout").setExecutor((CommandExecutor) new Logout());
  35.         this.getCommand("fund").setExecutor((CommandExecutor) new Fund());
  36.         this.getCommand("withdraw").setExecutor((CommandExecutor) new Withdraw());
  37.         this.getCommand("set").setExecutor((CommandExecutor) new Set());
  38.         this.getCommand("get").setExecutor((CommandExecutor) new Get());
  39.         this.getCommand("helpme").setExecutor((CommandExecutor) new HelpMe());
  40.     }
  41.    
  42.     public void onDisable() {
  43.         try {
  44.             clientSocket.close();
  45.         } catch (Exception e) {}
  46.  
  47.     }
  48.    
  49.     public static String SendCommand(String cmd) throws IOException
  50.     {
  51.         OutputStream socketWrite = clientSocket.getOutputStream();
  52.        
  53.         InputStream socketRead = clientSocket.getInputStream();
  54.        
  55.         byte[] buf = cmd.getBytes(StandardCharsets.US_ASCII);
  56.        
  57.         socketWrite.write(buf);
  58.        
  59.         byte[] receivedBuf = new byte[1024];
  60.        
  61.         int c = socketRead.read(receivedBuf);
  62.        
  63.         byte[] data = new byte[c];
  64.        
  65.         System.arraycopy(receivedBuf, 0, data, 0, c);
  66.  
  67.         return new String(data, StandardCharsets.US_ASCII);
  68.     }
  69.    
  70.     public static void clientSocket() throws NumberFormatException, UnknownHostException, IOException
  71.     {
  72.         clientSocket = new Socket(InetAddress.getByName("127.0.0.1"), 100);
  73.     }
  74.    
  75.     public static boolean checkOnlineUsers(String inGameName)
  76.     {
  77.         for(OnlineUser user : users)
  78.         {
  79.             if (user.inGameName.equalsIgnoreCase(inGameName))
  80.             {
  81.                 return true;
  82.             }
  83.         }
  84.        
  85.         return false;
  86.     }
  87.    
  88.     public static OnlineUser returnOnlineUser(String inGameName)
  89.     {
  90.         for(OnlineUser user : users)
  91.         {
  92.             if (user.inGameName.equalsIgnoreCase(inGameName))
  93.             {
  94.                 return user;
  95.             }
  96.         }
  97.         return null;
  98.     }
  99. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement