Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- BungeeMOTD:
- Class Main:
- package be.farlax.motd;
- import net.md_5.bungee.api.ProxyServer;
- import net.md_5.bungee.api.plugin.Plugin;
- import net.md_5.bungee.api.plugin.PluginManager;
- public class Main
- extends Plugin
- {
- public void onEnable()
- {
- getProxy().getPluginManager().registerListener(this, new MOTD());
- }
- }
- Class MOTD:
- package be.farlax.motd;
- import net.md_5.bungee.api.ServerPing;
- import net.md_5.bungee.api.ServerPing.Players;
- import net.md_5.bungee.api.ServerPing.Protocol;
- import net.md_5.bungee.api.event.ProxyPingEvent;
- import net.md_5.bungee.api.plugin.Listener;
- import net.md_5.bungee.api.plugin.Plugin;
- import net.md_5.bungee.event.EventHandler;
- @SuppressWarnings("unused")
- public class MOTD
- extends Plugin
- implements Listener
- {
- @SuppressWarnings("deprecation")
- @EventHandler
- public void onProxyPing(ProxyPingEvent e)
- {
- ServerPing sp = e.getResponse();
- if (sp == null) {
- return;
- }
- sp.setPlayers(new ServerPing.Players(300, sp.getPlayers().getOnline(), e.getResponse().getPlayers().getSample()));
- sp.setDescription("§b §bArcaGames §b \n§a §aServeur SkyWars/OpPrison/Fac §a?");
- sp.setVersion(new ServerPing.Protocol("§c§l>> ArcaGames en dev !", 4));
- }
- }
- API Coins:
- Class API:
- package be.farlax.azerapi;
- 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 API extends JavaPlugin implements Listener{
- public SqlConnection sql;
- public void onEnable(){
- sql = new SqlConnection("jdbc:mysql://","localhost","azerapi","root","natan1999");
- sql.connection();
- getServer().getPluginManager().registerEvents(this, this);
- getCommand("coins").setExecutor(new CmdCoins(sql));
- }
- public void onDisable(){
- sql.disconnect();
- }
- @EventHandler
- public void join(PlayerJoinEvent e){
- Player p = e.getPlayer();
- sql.createAccount(p);
- }
- }
- Class CmdCoins:
- package be.farlax.azerapi;
- import org.bukkit.Bukkit;
- import org.bukkit.command.Command;
- import org.bukkit.command.CommandExecutor;
- import org.bukkit.command.CommandSender;
- import org.bukkit.entity.Player;
- public class CmdCoins implements CommandExecutor {
- private SqlConnection sql;
- public CmdCoins(SqlConnection sql) {
- this.sql = sql;
- }
- @Override
- public boolean onCommand(CommandSender sender, Command cmd, String msg, String[] args) {
- if(sender instanceof Player){
- Player p = (Player)sender;
- if(args.length == 0){
- int balance = sql.getBalance(p);
- p.sendMessage("§7Vous avez : §e" + balance+" §7coins");
- }
- if(args.length >= 1 || args.length == 2 ){
- if(args[0].equalsIgnoreCase("add")){
- if(args.length == 1 || args.length == 2){
- p.sendMessage("§cVeuillez taper /coins add <montant> <joueur>");
- }
- if(args.length == 3){
- Player cible = Bukkit.getPlayer(args[2]);
- if(cible != null){
- int montant = Integer.valueOf(args[1]);
- sql.addMoney(cible, montant);
- cible.sendMessage("§aVous recevez : " + montant+" coins de la part de "+ p.getName());
- p.sendMessage("§aVous venez d'ajouter : " + montant+" coins à " + cible.getName());
- }else{
- p.sendMessage("§cTu n'as pas la permission d'utilisé cette commande !");
- }
- }
- }
- if(args[0].equalsIgnoreCase("remove")){
- if(args.length == 1 || args.length == 2){
- p.sendMessage("§aVeuillez taper /coins remove <montant> <joueur>");
- }
- if(args.length == 3){
- Player cible = Bukkit.getPlayer(args[2]);
- if(cible != null){
- int balance = sql.getBalance(cible);
- int montant = Integer.valueOf(args[1]);
- if((balance - montant) < 0)
- {
- p.sendMessage("§aLe joueur n'a pas assez de coins.");
- }
- else
- {
- sql.removeMoney(cible, montant);
- cible.sendMessage("§cVous perdez : " + montant+" coins de la part de "+ p.getName());
- p.sendMessage("§aVous venez de retirer : " + montant+" coins à " + cible.getName());
- }
- }
- }
- if(args[0].equalsIgnoreCase("set")){
- if(args.length == 1 || args.length == 2){
- p.sendMessage("§aVeuillez taper /coins set <montant> <joueur>");
- }
- if(args.length == 3){
- Player cible = Bukkit.getPlayer(args[2]);
- if(cible != null){
- int montant = Integer.valueOf(args[1]);
- sql.setMoney(cible, montant);
- cible.sendMessage("§cTes coins a été modifié par "+ p.getName());
- p.sendMessage("§aVous venez de modifier les coins de " + cible.getName());
- }
- }
- }
- if(args[0].equalsIgnoreCase("pay")){
- if(args.length == 1 || args.length == 2){
- p.sendMessage("§aVeuillez taper /coins pay <montant> <joueur>");
- }
- if(args.length == 3){
- Player cible = Bukkit.getPlayer(args[2]);
- if(cible != null){
- int montant = Integer.valueOf(args[1]);
- sql.payMoney(p, cible, montant);
- cible.sendMessage("§a"+ p.getName() + " vous a payé " + montant);
- p.sendMessage("§aVous venez de payer " + montant + " coins à " + cible.getName());
- }
- }
- }
- }
- }
- }
- return false;
- }
- }
- Class SqlConnection:
- package be.farlax.azerapi;
- import java.sql.Connection;
- import java.sql.DriverManager;
- import java.sql.PreparedStatement;
- import java.sql.ResultSet;
- import java.sql.SQLException;
- import org.bukkit.entity.Player;
- public class SqlConnection {
- private Connection connection;
- private String urlbase,host,database,user,pass;
- public SqlConnection(String urlbase, String host, String database, String user, String pass) {
- this.urlbase = urlbase;
- this.host = host;
- this.database = database;
- this.user = user;
- this.pass = pass;
- }
- public void connection(){
- if(!isConnected()){
- try {
- connection = DriverManager.getConnection(urlbase + host + "/" + database, user, pass);
- System.out.println("Connection : OK !");
- } catch (SQLException e) {
- e.printStackTrace();
- }
- }
- }
- public void disconnect(){
- if(isConnected()){
- try {
- System.out.print("Connection : Disconnected ");
- connection.close();
- } catch (SQLException e) {
- e.printStackTrace();
- }
- }
- }
- public boolean isConnected(){
- return connection != null;
- }
- public void createAccount(Player player){
- if(!hasAccount(player)){
- try {
- PreparedStatement q = connection.prepareStatement("INSERT INTO joueurs(uuid,coins,grade) VALUES (?,?,?)");
- q.setString(1, player.getUniqueId().toString());
- q.setInt(2, 0);
- q.setString(3, "joueur");
- q.execute();
- q.close();
- } catch (SQLException e) {
- e.printStackTrace();
- }
- }
- }
- public boolean hasAccount(Player player){
- try {
- PreparedStatement q = connection.prepareStatement("SELECT uuid FROM joueurs WHERE uuid = ?");
- q.setString(1, player.getUniqueId().toString());
- ResultSet resultat = q.executeQuery();
- boolean hasAccount = resultat.next();
- q.close();
- return hasAccount;
- } catch (SQLException e) {
- e.printStackTrace();
- }
- return false;
- }
- public int getBalance(Player player){
- try {
- PreparedStatement q = connection.prepareStatement("SELECT coins FROM joueurs WHERE uuid = ?");
- q.setString(1, player.getUniqueId().toString());
- int balance = 0;
- ResultSet rs = q.executeQuery();
- while(rs.next()){
- balance = rs.getInt("coins");
- }
- q.close();
- return balance;
- } catch (SQLException e) {
- e.printStackTrace();
- }
- return 0;
- }
- public void addMoney(Player player,int amount){
- int balance = getBalance(player);
- int newbalance = balance + amount;
- try {
- PreparedStatement rs = connection.prepareStatement("UPDATE joueurs SET coins = ? WHERE uuid = ?");
- rs.setInt(1, newbalance);
- rs.setString(2, player.getUniqueId().toString());
- rs.executeUpdate();
- rs.close();
- } catch (SQLException e) {
- e.printStackTrace();
- }
- }
- public void removeMoney(Player player,int amount){
- int balance = getBalance(player);
- int newbalance = balance - amount;
- try {
- PreparedStatement rs = connection.prepareStatement("UPDATE joueurs SET coins = ? WHERE uuid = ?");
- rs.setInt(1, newbalance);
- rs.setString(2, player.getUniqueId().toString());
- rs.executeUpdate();
- rs.close();
- } catch (SQLException e) {
- e.printStackTrace();
- }
- }
- public void setMoney(Player player,int amount){
- try {
- PreparedStatement rs = connection.prepareStatement("UPDATE joueurs SET coins = ? WHERE uuid = ?");
- rs.setInt(1, amount);
- rs.setString(2, player.getUniqueId().toString());
- rs.executeUpdate();
- rs.close();
- } catch (SQLException e) {
- e.printStackTrace();
- }
- }
- public void payMoney(Player p, Player player,int amount){
- int balancep = getBalance(p);
- int balancepl = getBalance(player);
- int npbalance = balancep - amount;
- int nplbalance = balancepl + amount;
- try {
- PreparedStatement rs = connection.prepareStatement("UPDATE joueurs SET coins = ? WHERE uuid = ?");
- rs.setInt(1, nplbalance);
- rs.setString(2, player.getUniqueId().toString());
- rs.executeUpdate();
- rs.close();
- PreparedStatement a = connection.prepareStatement("UPDATE joueurs SET coins = ? WHERE uuid = ?");
- a.setInt(1, npbalance);
- a.setString(2, p.getUniqueId().toString());
- a.executeUpdate();
- a.close();
- } catch (SQLException e) {
- e.printStackTrace();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement