Advertisement
Guest User

UltimateReporter

a guest
Apr 9th, 2017
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.27 KB | None | 0 0
  1. //Ma commande
  2.  
  3. package fr.xuarig.UltimateReporter;
  4.  
  5.  
  6. import org.bukkit.command.Command;
  7. import org.bukkit.command.CommandExecutor;
  8. import org.bukkit.command.CommandSender;
  9. import org.bukkit.entity.Player;
  10.  
  11. public class ReportCommand implements CommandExecutor {
  12.  
  13. /*
  14. * /report <player> <reason>
  15. */
  16.  
  17. @Override
  18. public boolean onCommand(CommandSender sender, Command cmd, String msg, String[] args) {
  19.  
  20. if(sender instanceof Player){
  21.  
  22. Player p = (Player)sender;
  23.  
  24. if(cmd.getName().equalsIgnoreCase("report")){
  25.  
  26. //Test de la commande /report
  27.  
  28. String reason = "";
  29. for (int i = 1; i < args.length; i++)
  30. {
  31. String arg = args[i] + " ";
  32. reason = reason + arg;
  33.  
  34. //Regarde uniquement les args de la Raison
  35. }
  36.  
  37. if(args.length == 0){
  38. p.sendMessage("§b[§6UltimateReporter§b] §4Votre commande est incomplète !");
  39. p.sendMessage("§b[§6UltimateReporter§b] §cCommande : /report <joueur> [Raison]");
  40.  
  41. //Message d'aide en cas de /report
  42. }
  43.  
  44.  
  45. if(args.length >= 1){
  46. Player target = p.getServer().getPlayerExact(args[0]);
  47. if(!args[0].equalsIgnoreCase(p.getName())){
  48. //Empèche le joueur de s'autoreport
  49. if(target != null){
  50. p.sendMessage("§b[§6UltimateReporter§b] §aVotre report a été pris en compte !");
  51.  
  52. for(Player player : p.getServer().getOnlinePlayers()) {
  53. if(player.isOp()) {
  54. //Teste les joueurs ops
  55.  
  56. String messageToSend = "§b[§6UltimateReporter§b]§4 " + target.getName() + " §6a été reporté par §4" + p.getName();
  57. String msgConsToSend = "\u001B[37mReport de \u001B[31m" + target.getName() + "\u001B[37m par \u001B[31m" + p.getName() + "\u001B[0m";
  58. if ( args.length >= 2 )
  59. {
  60. messageToSend = messageToSend + " §6! Raison :§4 " + reason;
  61. msgConsToSend = msgConsToSend + "\u001B[37m ! Raison : \u001B[33m" + reason + "\u001B[0m";
  62. }
  63. player.sendMessage(messageToSend); //Envoie le message aux modos
  64. System.out.println(msgConsToSend); //message report sur la console
  65.  
  66. }
  67. //Envoie l'information vers SqlConection via Parametres.
  68. Parametres.sqlConnection.report(p,target,reason);
  69. }
  70. }
  71.  
  72.  
  73.  
  74. }
  75. }
  76. }
  77.  
  78. }
  79. return false;
  80. }
  81. }
  82.  
  83. -------------------------------------------------------------------------------------------------------------------------
  84.  
  85. //Parametres.java
  86.  
  87. package fr.xuarig.UltimateReporter;
  88.  
  89. public class Parametres {
  90. static SqlConnection sqlConnection = null;
  91. }
  92.  
  93. ----------------------------------------------------------------------------------------------------------------------------
  94.  
  95. //SqlConnection.java
  96.  
  97. package fr.xuarig.UltimateReporter;
  98.  
  99. import java.sql.Connection;
  100. import java.sql.DriverManager;
  101. import java.sql.PreparedStatement;
  102. import java.sql.ResultSet;
  103. import java.sql.SQLException;
  104.  
  105.  
  106. import org.bukkit.entity.Player;
  107.  
  108. public class SqlConnection {
  109.  
  110. public static String raison;
  111. private Connection connection;
  112. private String urlbase,host,database,user,pass;
  113.  
  114. public SqlConnection(String urlbase, String host, String database, String user, String pass) {
  115. this.urlbase = urlbase;
  116. this.host = host;
  117. this.database = database;
  118. this.user = user;
  119. this.pass = pass;
  120. //Va chercher les infos de connection
  121. }
  122.  
  123. public void connection(){
  124. if(!isConnected()){
  125. try {
  126. connection = DriverManager.getConnection(urlbase + host + "/" + database, user, pass);
  127. System.out.println("\u001B[36m[\u001B[32mUltimateReporter\u001B[36m] \u001B[32mMySQL Connected \u001B[0m");
  128. } catch (SQLException e) {
  129. e.printStackTrace();
  130. //Se connecte
  131. }
  132. }
  133. }
  134.  
  135. public void disconnect(){
  136. if(isConnected()){
  137. try {
  138. connection.close();
  139. System.out.println("\u001B[36m[\u001B[31mUltimateReporter\u001B[36m] \u001B[31mMySQL Disconnected \u001B[0m");
  140. } catch (SQLException e) {
  141. e.printStackTrace();
  142. //Se déconnecte
  143. }
  144. }
  145.  
  146. }
  147.  
  148. public boolean isConnected(){
  149. return connection != null;
  150. //Teste si mysql est connecté
  151. }
  152.  
  153. public void report (Player p_player, Player p_target, String p_reason){
  154. //INSERT
  155. try {
  156. PreparedStatement q = connection.prepareStatement("INSERT INTO ultimatereporter(accusateur,accuse,dateheure,raison) VALUES (?,?,now(),?)");
  157. q.setString(1, p_player.getUniqueId().toString());
  158. q.setString(2, p_target.getUniqueId().toString());
  159. q.setString(3, p_reason);
  160. q.execute();
  161. q.close();
  162. } catch(SQLException e) {
  163. System.out.println(e.getMessage());
  164.  
  165. //Envoie les infos à la BDD
  166.  
  167.  
  168. }
  169. }
  170.  
  171.  
  172. public void getRaison(Player target){
  173. try {
  174. PreparedStatement q = connection.prepareStatement("SELECT raison FROM ultimatereporter WHERE accuse = ?");
  175. q.setString(1, target.getUniqueId().toString());
  176.  
  177. ResultSet rs = q.executeQuery();
  178.  
  179. while(rs.next()){
  180. raison = rs.getString("raison");
  181. if(raison == null){
  182.  
  183. }
  184. }
  185.  
  186.  
  187. q.close();
  188.  
  189.  
  190. } catch (SQLException e) {
  191. System.out.println(e.getMessage());
  192. //e.printStackTrace();
  193.  
  194. }
  195. }
  196. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement