Advertisement
Guest User

Code de Farlax :)

a guest
Jan 19th, 2017
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 10.13 KB | None | 0 0
  1. BungeeMOTD:
  2. Class Main:
  3. package be.farlax.motd;
  4.  
  5. import net.md_5.bungee.api.ProxyServer;
  6. import net.md_5.bungee.api.plugin.Plugin;
  7. import net.md_5.bungee.api.plugin.PluginManager;
  8.  
  9. public class Main
  10.   extends Plugin
  11. {
  12.   public void onEnable()
  13.   {
  14.     getProxy().getPluginManager().registerListener(this, new MOTD());
  15.   }
  16. }
  17. Class MOTD:
  18. package be.farlax.motd;
  19.  
  20. import net.md_5.bungee.api.ServerPing;
  21. import net.md_5.bungee.api.ServerPing.Players;
  22. import net.md_5.bungee.api.ServerPing.Protocol;
  23. import net.md_5.bungee.api.event.ProxyPingEvent;
  24. import net.md_5.bungee.api.plugin.Listener;
  25. import net.md_5.bungee.api.plugin.Plugin;
  26. import net.md_5.bungee.event.EventHandler;
  27.  
  28. @SuppressWarnings("unused")
  29. public class MOTD
  30.   extends Plugin
  31.   implements Listener
  32. {
  33.   @SuppressWarnings("deprecation")
  34. @EventHandler
  35.   public void onProxyPing(ProxyPingEvent e)
  36.   {
  37.     ServerPing sp = e.getResponse();
  38.     if (sp == null) {
  39.       return;
  40.     }
  41.     sp.setPlayers(new ServerPing.Players(300, sp.getPlayers().getOnline(), e.getResponse().getPlayers().getSample()));
  42.     sp.setDescription("§b §bArcaGames §b \n§a §aServeur SkyWars/OpPrison/Fac §a?");
  43.     sp.setVersion(new ServerPing.Protocol("§c§l>> ArcaGames en dev !", 4));
  44.   }
  45. }
  46. API Coins:
  47. Class API:
  48. package be.farlax.azerapi;
  49.  
  50. import org.bukkit.entity.Player;
  51. import org.bukkit.event.EventHandler;
  52. import org.bukkit.event.Listener;
  53. import org.bukkit.event.player.PlayerJoinEvent;
  54. import org.bukkit.plugin.java.JavaPlugin;
  55.  
  56. public class API extends JavaPlugin implements Listener{
  57.    
  58.     public SqlConnection sql;
  59.    
  60.     public void onEnable(){
  61.         sql = new SqlConnection("jdbc:mysql://","localhost","azerapi","root","natan1999");
  62.         sql.connection();
  63.         getServer().getPluginManager().registerEvents(this, this);
  64.         getCommand("coins").setExecutor(new CmdCoins(sql));
  65.     }
  66.    
  67.     public void onDisable(){
  68.         sql.disconnect();
  69.     }
  70.    
  71.     @EventHandler
  72.     public void join(PlayerJoinEvent e){
  73.         Player p = e.getPlayer();
  74.         sql.createAccount(p);
  75.     }
  76.     }
  77. Class CmdCoins:
  78. package be.farlax.azerapi;
  79.  
  80. import org.bukkit.Bukkit;
  81. import org.bukkit.command.Command;
  82. import org.bukkit.command.CommandExecutor;
  83. import org.bukkit.command.CommandSender;
  84. import org.bukkit.entity.Player;
  85.  
  86. public class CmdCoins implements CommandExecutor {
  87.    
  88.     private SqlConnection sql;
  89.  
  90.     public CmdCoins(SqlConnection sql) {
  91.         this.sql = sql;
  92.     }
  93.     @Override
  94.     public boolean onCommand(CommandSender sender, Command cmd, String msg, String[] args) {
  95.    
  96.         if(sender instanceof Player){
  97.            
  98.             Player p = (Player)sender;
  99.             if(args.length == 0){
  100.                 int balance = sql.getBalance(p);
  101.                 p.sendMessage("§7Vous avez : §e" + balance+" §7coins");
  102.             }
  103.             if(args.length >= 1 || args.length == 2 ){
  104.                
  105.                 if(args[0].equalsIgnoreCase("add")){
  106.                    
  107.                     if(args.length == 1 || args.length == 2){
  108.                         p.sendMessage("§cVeuillez taper /coins add <montant> <joueur>");
  109.                     }
  110.                    
  111.                     if(args.length == 3){
  112.                          Player cible = Bukkit.getPlayer(args[2]);
  113.                          if(cible != null){
  114.                              int montant = Integer.valueOf(args[1]);
  115.                              sql.addMoney(cible, montant);
  116.                              cible.sendMessage("§aVous recevez : " + montant+" coins de la part de "+ p.getName());
  117.                              p.sendMessage("§aVous venez d'ajouter : " + montant+" coins à " + cible.getName());
  118.                          }else{
  119.                              p.sendMessage("§cTu n'as pas la permission d'utilisé cette commande !");
  120.                          }
  121.                        
  122.                 }
  123.             }
  124.                
  125.                 if(args[0].equalsIgnoreCase("remove")){
  126.                    
  127.                     if(args.length == 1 || args.length == 2){
  128.                         p.sendMessage("§aVeuillez taper /coins remove <montant> <joueur>");
  129.                    
  130.                 }
  131.                     if(args.length == 3){
  132.                         Player cible = Bukkit.getPlayer(args[2]);
  133.                         if(cible != null){
  134.                             int balance = sql.getBalance(cible);
  135.                             int montant = Integer.valueOf(args[1]);
  136.                             if((balance - montant) < 0)
  137.                             {
  138.                                 p.sendMessage("§aLe joueur n'a pas assez de coins.");
  139.                             }
  140.                             else
  141.                             {
  142.                             sql.removeMoney(cible, montant);
  143.                             cible.sendMessage("§cVous perdez : " + montant+" coins de la part de "+ p.getName());
  144.                             p.sendMessage("§aVous venez de retirer : " + montant+" coins à " + cible.getName());
  145.                        
  146.                 }
  147.                    
  148.         }
  149.                    
  150.         }
  151.                 if(args[0].equalsIgnoreCase("set")){
  152.                    
  153.                     if(args.length == 1 || args.length == 2){
  154.                         p.sendMessage("§aVeuillez taper /coins set <montant> <joueur>");
  155.                    
  156.                 }
  157.                     if(args.length == 3){
  158.                        
  159.                         Player cible = Bukkit.getPlayer(args[2]);
  160.                         if(cible != null){
  161.                             int montant = Integer.valueOf(args[1]);
  162.                             sql.setMoney(cible, montant);
  163.                             cible.sendMessage("§cTes coins a été modifié par "+ p.getName());
  164.                             p.sendMessage("§aVous venez de modifier les coins de " + cible.getName());
  165.                        
  166.                        
  167.                 }
  168.                    
  169.         }
  170.                    
  171.         }
  172.                 if(args[0].equalsIgnoreCase("pay")){
  173.                    
  174.                     if(args.length == 1 || args.length == 2){
  175.                         p.sendMessage("§aVeuillez taper /coins pay <montant> <joueur>");
  176.                    
  177.                 }
  178.                     if(args.length == 3){
  179.                        
  180.                         Player cible = Bukkit.getPlayer(args[2]);
  181.                         if(cible != null){
  182.                             int montant = Integer.valueOf(args[1]);
  183.                             sql.payMoney(p, cible, montant);
  184.                             cible.sendMessage("§a"+ p.getName() + " vous a payé " + montant);
  185.                             p.sendMessage("§aVous venez de payer " + montant + " coins à " + cible.getName());
  186.                        
  187.                        
  188.                 }
  189.                    
  190.         }
  191.                    
  192.         }
  193.       }
  194.  
  195.     }
  196. }
  197.         return false;
  198. }
  199. }
  200. Class SqlConnection:
  201. package be.farlax.azerapi;
  202.  
  203. import java.sql.Connection;
  204. import java.sql.DriverManager;
  205. import java.sql.PreparedStatement;
  206. import java.sql.ResultSet;
  207. import java.sql.SQLException;
  208.  
  209. import org.bukkit.entity.Player;
  210.  
  211. public class SqlConnection {
  212.    
  213.     private Connection connection;
  214.     private String urlbase,host,database,user,pass;
  215.  
  216.     public SqlConnection(String urlbase, String host, String database, String user, String pass) {
  217.         this.urlbase = urlbase;
  218.         this.host = host;
  219.         this.database = database;
  220.         this.user = user;
  221.         this.pass = pass;
  222.     }
  223.    
  224.     public void connection(){  
  225.         if(!isConnected()){
  226.         try {
  227.             connection = DriverManager.getConnection(urlbase + host + "/" + database, user, pass);
  228.             System.out.println("Connection : OK !");
  229.         } catch (SQLException e) {
  230.             e.printStackTrace();
  231.         }
  232.     }
  233.   }
  234.    
  235.     public void disconnect(){
  236.         if(isConnected()){
  237.         try {          
  238.                 System.out.print("Connection : Disconnected ");
  239.             connection.close();
  240.  
  241.         } catch (SQLException e) {
  242.             e.printStackTrace();
  243.         }
  244.         }
  245.     }
  246.    
  247.     public boolean isConnected(){
  248.         return connection != null;
  249.        
  250.     }
  251.    
  252.     public void createAccount(Player player){
  253.         if(!hasAccount(player)){
  254.            
  255.             try {
  256.                 PreparedStatement q = connection.prepareStatement("INSERT INTO joueurs(uuid,coins,grade) VALUES (?,?,?)");
  257.                 q.setString(1, player.getUniqueId().toString());
  258.                 q.setInt(2, 0);
  259.                 q.setString(3, "joueur");
  260.                 q.execute();
  261.                 q.close();
  262.             } catch (SQLException e) {
  263.                 e.printStackTrace();
  264.             }
  265.            
  266.         }
  267.        
  268.     }
  269.    
  270.     public boolean hasAccount(Player player){
  271.        
  272.        
  273.         try {
  274.             PreparedStatement q = connection.prepareStatement("SELECT uuid FROM joueurs WHERE uuid = ?");
  275.             q.setString(1, player.getUniqueId().toString());
  276.             ResultSet resultat = q.executeQuery();
  277.             boolean hasAccount = resultat.next();
  278.             q.close();
  279.             return hasAccount;
  280.         } catch (SQLException e) {
  281.             e.printStackTrace();
  282.         }
  283.        
  284.         return false;
  285.     }
  286.    
  287.     public int getBalance(Player player){
  288.        
  289.        
  290.         try {
  291.             PreparedStatement q = connection.prepareStatement("SELECT coins FROM joueurs WHERE uuid = ?");
  292.             q.setString(1, player.getUniqueId().toString());
  293.            
  294.             int balance = 0;
  295.             ResultSet rs = q.executeQuery();
  296.            
  297.             while(rs.next()){
  298.                 balance = rs.getInt("coins");
  299.             }
  300.            
  301.            
  302.             q.close();
  303.            
  304.             return balance;
  305.            
  306.         } catch (SQLException e) {
  307.             e.printStackTrace();
  308.         }
  309.         return 0;
  310.     }
  311.    
  312.     public void addMoney(Player player,int amount){
  313.  
  314.         int balance = getBalance(player);
  315.         int newbalance = balance + amount;
  316.  
  317.         try {
  318.             PreparedStatement rs = connection.prepareStatement("UPDATE joueurs SET coins = ? WHERE uuid = ?");
  319.             rs.setInt(1, newbalance);
  320.             rs.setString(2, player.getUniqueId().toString());
  321.             rs.executeUpdate();
  322.             rs.close();
  323.         } catch (SQLException e) {
  324.             e.printStackTrace();
  325.         }
  326.  
  327.     }
  328.    
  329.     public void removeMoney(Player player,int amount){
  330.        
  331.        
  332.         int balance = getBalance(player);
  333.         int newbalance = balance - amount;
  334.        
  335.         try {
  336.             PreparedStatement rs = connection.prepareStatement("UPDATE joueurs SET coins = ? WHERE uuid = ?");
  337.             rs.setInt(1, newbalance);
  338.             rs.setString(2, player.getUniqueId().toString());
  339.             rs.executeUpdate();
  340.             rs.close();
  341.         } catch (SQLException e) {
  342.             e.printStackTrace();
  343.         }
  344.     }
  345.    
  346.     public void setMoney(Player player,int amount){
  347.        
  348.         try {
  349.             PreparedStatement rs = connection.prepareStatement("UPDATE joueurs SET coins = ? WHERE uuid = ?");
  350.             rs.setInt(1, amount);
  351.             rs.setString(2, player.getUniqueId().toString());
  352.             rs.executeUpdate();
  353.             rs.close();
  354.         } catch (SQLException e) {
  355.             e.printStackTrace();
  356.         }
  357.     }
  358.    
  359.     public void payMoney(Player p, Player player,int amount){
  360.         int balancep = getBalance(p);
  361.         int balancepl = getBalance(player);
  362.         int npbalance = balancep - amount;
  363.         int nplbalance = balancepl + amount;
  364.        
  365.         try {
  366.             PreparedStatement rs = connection.prepareStatement("UPDATE joueurs SET coins = ? WHERE uuid = ?");
  367.             rs.setInt(1, nplbalance);
  368.             rs.setString(2, player.getUniqueId().toString());
  369.             rs.executeUpdate();
  370.             rs.close();
  371.             PreparedStatement a = connection.prepareStatement("UPDATE joueurs SET coins = ? WHERE uuid = ?");
  372.             a.setInt(1, npbalance);
  373.             a.setString(2, p.getUniqueId().toString());
  374.             a.executeUpdate();
  375.             a.close();
  376.         } catch (SQLException e) {
  377.             e.printStackTrace();
  378.         }
  379.     }
  380. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement