Advertisement
Guest User

Untitled

a guest
Apr 15th, 2018
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.80 KB | None | 0 0
  1. package fr.SuperAntonio31.AntoinePlug;
  2.  
  3. import java.io.File;
  4. import java.io.IOException;
  5. import java.util.ArrayList;
  6.  
  7. import java.util.Map;
  8.  
  9. import org.bukkit.Bukkit;
  10. import org.bukkit.command.Command;
  11. import org.bukkit.command.CommandExecutor;
  12. import org.bukkit.command.CommandSender;
  13. import org.bukkit.configuration.file.YamlConfiguration;
  14. import org.bukkit.entity.Player;
  15. import org.bukkit.scheduler.BukkitRunnable;
  16.  
  17. public class commands implements CommandExecutor{
  18. public File fileCommands;
  19. public Main main;
  20. Map<String, String> sms;
  21. ArrayList<String> bW ;
  22. ArrayList<Character> forFinal ;
  23. public commands (Main main) {
  24. this.fileCommands = main.fileCommands;
  25. this.main = main;
  26. this.sms = main.sms;
  27. this.bW = main.bW;
  28. this.forFinal = main.forFinal;
  29. }
  30. @Override
  31. public boolean onCommand(CommandSender s, Command cmd, String label, String[] a) {
  32. if(s instanceof Player) {
  33.  
  34. StringBuilder message = new StringBuilder();
  35. message.append(a[1]+" ");
  36.  
  37. YamlConfiguration config = YamlConfiguration.loadConfiguration(fileCommands);
  38. if(!config.contains("messages")) {
  39. config.set("messages.help-msg", ""
  40. + "§cHey ! §6Syntaxe de la commande: §b/msg §e[Pseudo] [Votre Message]"
  41. + "§fCette commande vous permet d'envoyer un message privé à un joueur spécifique.");
  42. config.set("messages.help-tell", ""
  43. + "§cHey ! §6Syntaxe de la commande: §b/tell §e[Pseudo] [Votre Message]"
  44. + "§fCette commande vous permet d'envoyer un message privé à un joueur spécifique.");
  45. config.set("messages.help-m", ""
  46. + "§cHey ! §6Syntaxe de la commande: §b/m §e[Pseudo] [Votre Message]"
  47. + "§fCette commande vous permet d'envoyer un message privé à un joueur spécifique.");
  48. try {
  49. config.save(fileCommands);
  50. } catch (IOException e) {
  51. // TODO Auto-generated catch block
  52. e.printStackTrace();
  53. }
  54. }
  55. String c = cmd.getName();
  56. Player p = (Player)s;
  57. if((c.equalsIgnoreCase("msg"))) {
  58.  
  59. if(a.length < 2) {
  60. p.sendMessage(config.getString("messages.help-msg"));
  61. }
  62.  
  63. if(a.length >= 2) {
  64.  
  65. Player p2 = Bukkit.getPlayer(a[0]);
  66. if(p2 instanceof Player) {
  67.  
  68.  
  69.  
  70.  
  71.  
  72. new BukkitRunnable() {
  73. StringBuilder motParMot = new StringBuilder();
  74. ArrayList<String> tableauDeMots = new ArrayList<String>();
  75. int i1 = -1;
  76. char lettreParLettre;
  77. @Override
  78. public void run() {
  79. if(i1 < message.length()-1) {
  80. i1++;
  81. lettreParLettre = message.charAt(i1);
  82. if(lettreParLettre != ' ') {
  83. motParMot.append(lettreParLettre); //ajout de la lettre au mot temporaire
  84. }else {
  85. if(motParMot != null) { //Si la phrase ne commence pas par un espace
  86. if(sms.containsKey(motParMot.toString().toLowerCase())) {
  87. ;
  88.  
  89. tableauDeMots.add(sms.get(motParMot.toString()));
  90. }
  91. else if(bW.contains(motParMot.toString().toLowerCase())) { //Si c'est un gros mots
  92. tableauDeMots.add(motParMot.toString().toLowerCase().replaceAll("[a-zA-Z!]","*"));
  93. motParMot.setLength(0);
  94. }else {
  95. tableauDeMots.add("§f"+motParMot.toString());
  96. }
  97.  
  98. motParMot.setLength(0);
  99. }
  100. }
  101.  
  102.  
  103.  
  104. }else {
  105. StringBuilder phrase = new StringBuilder();
  106. for ( String mot : tableauDeMots) {
  107. phrase.append(mot);
  108. phrase.append(' ');
  109. }
  110.  
  111. phrase.setCharAt(0,Character.toUpperCase(phrase.charAt(0)));
  112. phrase.deleteCharAt(phrase.length()-1);//j'enl_ve espace en trop
  113. if(forFinal.contains(phrase.charAt(phrase.length()-1))) {
  114.  
  115. p.sendMessage("§7["+p.getDisplayName()+"§7]"+"§6 --> "+"§7["+p2.getDisplayName()+"§7] "+"§f"+phrase);
  116. p2.sendMessage("§7["+p.getDisplayName()+"§7]"+"§6 --> "+"§7["+p2.getDisplayName()+"§7] "+"§f"+phrase);
  117.  
  118. }else {
  119. phrase.append('.');
  120. p.sendMessage("§7["+p.getDisplayName()+"§7]"+"§6 --> "+"§7["+p2.getDisplayName()+"§7] "+"§f"+phrase);
  121. p2.sendMessage("§7["+p.getDisplayName()+"§7]"+"§6 --> "+"§7["+p2.getDisplayName()+"§7] "+"§f"+phrase);
  122. }
  123. this.cancel();
  124.  
  125.  
  126. }
  127.  
  128.  
  129. }
  130. }.runTaskTimer(main, 0L, (long) 0.00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001);
  131. }else {
  132. p.sendMessage("§6Le joueur §b"+p.getName()+"§6 n'est pas en ligne !");
  133. }
  134.  
  135.  
  136.  
  137. }
  138.  
  139.  
  140. }
  141.  
  142.  
  143.  
  144.  
  145.  
  146.  
  147. if((c.equalsIgnoreCase("tell"))) {
  148.  
  149. if(a.length < 2) {
  150. p.sendMessage(config.getString("messages.help-tell"));
  151.  
  152. }
  153.  
  154. if(a.length >= 2) {
  155.  
  156. Player p2 = Bukkit.getPlayer(a[0]);
  157. if(p2 instanceof Player) {
  158.  
  159. new BukkitRunnable() {
  160. StringBuilder motParMot = new StringBuilder();
  161. ArrayList<String> tableauDeMots = new ArrayList<String>();
  162. int i1 = -1;
  163. char lettreParLettre;
  164. @Override
  165. public void run() {
  166. if(i1 < message.length()-1) {
  167. i1++;
  168. lettreParLettre = message.charAt(i1);
  169. if(lettreParLettre != ' ') {
  170. motParMot.append(lettreParLettre); //ajout de la lettre au mot temporaire
  171. }else {
  172. if(motParMot != null) { //Si la phrase ne commence pas par un espace
  173. if(sms.containsKey(motParMot.toString().toLowerCase())) {
  174. ;
  175.  
  176. tableauDeMots.add(sms.get(motParMot.toString()));
  177. }
  178. else if(bW.contains(motParMot.toString().toLowerCase())) { //Si c'est un gros mots
  179. tableauDeMots.add(motParMot.toString().toLowerCase().replaceAll("[a-zA-Z!]","*"));
  180. motParMot.setLength(0);
  181. }else {
  182. tableauDeMots.add("§f"+motParMot.toString());
  183. }
  184.  
  185. motParMot.setLength(0);
  186. }
  187. }
  188.  
  189.  
  190.  
  191. }else {
  192. StringBuilder phrase = new StringBuilder();
  193. for ( String mot : tableauDeMots) {
  194. phrase.append(mot);
  195. phrase.append(' ');
  196. }
  197.  
  198. phrase.setCharAt(0,Character.toUpperCase(phrase.charAt(0)));
  199. phrase.deleteCharAt(phrase.length()-1);//j'enl_ve espace en trop
  200. if(forFinal.contains(phrase.charAt(phrase.length()-1))) {
  201.  
  202. p.sendMessage("§7["+p.getDisplayName()+"§7]"+"§6 --> "+"§7["+p2.getDisplayName()+"§7] "+"§f"+phrase);
  203. p2.sendMessage("§7["+p.getDisplayName()+"§7]"+"§6 --> "+"§7["+p2.getDisplayName()+"§7] "+"§f"+phrase);
  204.  
  205. }else {
  206. phrase.append('.');
  207. p.sendMessage("§7["+p.getDisplayName()+"§7]"+"§6 --> "+"§7["+p2.getDisplayName()+"§7] "+"§f"+phrase);
  208. p2.sendMessage("§7["+p.getDisplayName()+"§7]"+"§6 --> "+"§7["+p2.getDisplayName()+"§7] "+"§f"+phrase);
  209. }
  210. this.cancel();
  211.  
  212.  
  213. }
  214.  
  215.  
  216. }
  217. }.runTaskTimer(main, 0L, (long) 0.00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001);
  218. }else {
  219. p.sendMessage("§6Le joueur §b"+p.getName()+"§6 n'est pas en ligne !");
  220. }
  221.  
  222.  
  223.  
  224. }
  225.  
  226.  
  227. }
  228.  
  229. if((c.equalsIgnoreCase("m"))) {
  230.  
  231. if(a.length < 2) {
  232. p.sendMessage(config.getString("messages.help-m"));
  233.  
  234. }
  235.  
  236. if(a.length >= 2) {
  237.  
  238. Player p2 = Bukkit.getPlayer(a[0]);
  239. if(p2 instanceof Player) {
  240.  
  241. new BukkitRunnable() {
  242. StringBuilder motParMot = new StringBuilder();
  243. ArrayList<String> tableauDeMots = new ArrayList<String>();
  244. int i1 = -1;
  245. char lettreParLettre;
  246. @Override
  247. public void run() {
  248. if(i1 < message.length()-1) {
  249. i1++;
  250. lettreParLettre = message.charAt(i1);
  251. if(lettreParLettre != ' ') {
  252. motParMot.append(lettreParLettre); //ajout de la lettre au mot temporaire
  253. }else {
  254. if(motParMot != null) { //Si la phrase ne commence pas par un espace
  255. if(sms.containsKey(motParMot.toString().toLowerCase())) {
  256.  
  257. tableauDeMots.add(sms.get(motParMot.toString()));
  258. }
  259. else if(bW.contains(motParMot.toString().toLowerCase())) { //Si c'est un gros mots
  260. tableauDeMots.add(motParMot.toString().toLowerCase().replaceAll("[a-zA-Z!]","*"));
  261. motParMot.setLength(0);
  262. }else {
  263. tableauDeMots.add("§f"+motParMot.toString());
  264. }
  265.  
  266. motParMot.setLength(0);
  267. }
  268. }
  269.  
  270.  
  271.  
  272. }else {
  273. StringBuilder phrase = new StringBuilder();
  274. for ( String mot : tableauDeMots) {
  275. phrase.append(mot);
  276. phrase.append(' ');
  277. }
  278.  
  279. phrase.setCharAt(0,Character.toUpperCase(phrase.charAt(0)));
  280. phrase.deleteCharAt(phrase.length()-1);//j'enl_ve espace en trop
  281. if(forFinal.contains(phrase.charAt(phrase.length()-1))) {
  282.  
  283. p.sendMessage("§7["+p.getDisplayName()+"§7]"+"§6 --> "+"§7["+p2.getDisplayName()+"§7] "+"§f"+phrase);
  284. p2.sendMessage("§7["+p.getDisplayName()+"§7]"+"§6 --> "+"§7["+p2.getDisplayName()+"§7] "+"§f"+phrase);
  285.  
  286. }else {
  287. phrase.append('.');
  288. p.sendMessage("§7["+p.getDisplayName()+"§7]"+"§6 --> "+"§7["+p2.getDisplayName()+"§7] "+"§f"+phrase);
  289. p2.sendMessage("§7["+p.getDisplayName()+"§7]"+"§6 --> "+"§7["+p2.getDisplayName()+"§7] "+"§f"+phrase);
  290. }
  291. this.cancel();
  292.  
  293.  
  294. }
  295.  
  296.  
  297. }
  298. }.runTaskTimer(main, 0L, (long) 0.00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001);
  299.  
  300. }else {
  301. p.sendMessage("§6Le joueur §b"+p.getName()+"§6 n'est pas en ligne !");
  302. }
  303.  
  304.  
  305.  
  306. }
  307.  
  308.  
  309. }
  310. }
  311. return false;
  312. }
  313. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement