/AndryPlugin/src/me/andriii25/andryplugin/AndryPlugin.java

https://bitbucket.org/andriii25/andryplugin · Java · 142 lines · 124 code · 18 blank · 0 comment · 40 complexity · 1b0fe3218f9bcd84c83beccc5705248d MD5 · raw file

  1. package me.andriii25.andryplugin;
  2. import java.util.Iterator;
  3. import java.util.List;
  4. import java.util.Arrays;
  5. import java.util.Random;
  6. import java.util.logging.Logger;
  7. import org.bukkit.*;
  8. import org.bukkit.command.Command;
  9. import org.bukkit.command.CommandSender;
  10. import org.bukkit.entity.Player;
  11. import org.bukkit.plugin.PluginDescriptionFile;
  12. import org.bukkit.plugin.PluginManager;
  13. import org.bukkit.plugin.java.JavaPlugin;
  14. public class AndryPlugin extends JavaPlugin {
  15. public final Logger logger = Logger.getLogger("Minecraft");
  16. public static AndryPlugin plugin;
  17. public final MyBlockListener bl = new MyBlockListener();
  18. public final MyPlayerListener pl = new MyPlayerListener();
  19. @Override
  20. public void onDisable() {
  21. PluginDescriptionFile pdfFile = this.getDescription();
  22. this.logger.info(pdfFile.getName() + " has been disabled!");
  23. }
  24. @Override
  25. public void onEnable() {
  26. PluginDescriptionFile pdfFile = this.getDescription();
  27. this.logger.info(pdfFile.getName() + " " + "Version" + " "
  28. + pdfFile.getVersion() + " has been enabled!");
  29. PluginManager pm = getServer().getPluginManager();
  30. pm.registerEvents(this.bl, this);
  31. pm.registerEvents(this.pl, this);
  32. getConfig().options().copyDefaults();
  33. saveConfig();
  34. }
  35. public boolean onCommand(CommandSender sender, Command cmd,
  36. String commandLabel, String[] args) {
  37. Player player = (Player) sender;
  38. if (commandLabel.equalsIgnoreCase("sendme")) {
  39. if (args.length == 1) {
  40. player.sendMessage(ChatColor.UNDERLINE + args[0]);
  41. }
  42. }else if (commandLabel.equalsIgnoreCase("heal")
  43. || commandLabel.equalsIgnoreCase("hea")) {
  44. if (args.length == 0) {
  45. player.setHealth(20);
  46. player.setFireTicks(0);
  47. player.sendMessage(ChatColor.GREEN + "You have been healed!");
  48. } else if (getServer().getPlayer(args[0]) != null) {
  49. Player targetPlayer = getServer().getPlayer(args[0]);
  50. targetPlayer.setHealth(20);
  51. targetPlayer.setFireTicks(0);
  52. targetPlayer.sendMessage(ChatColor.GREEN + "You have been healed by " + player.getDisplayName());
  53. player.sendMessage(ChatColor.GREEN + "You healed " + targetPlayer.getDisplayName());
  54. }
  55. }
  56. else if (commandLabel.equalsIgnoreCase("andryport")
  57. || commandLabel.equalsIgnoreCase("anpo")) {
  58. if (args.length == 0) {
  59. player.sendMessage(ChatColor.BOLD + "Too few arguments!");
  60. } else if (args.length == 1) {
  61. Player targetPlayer = player.getServer().getPlayer(args[0]);
  62. Location targetPlayerLocation = targetPlayer.getLocation();
  63. player.teleport(targetPlayerLocation);
  64. if (!targetPlayer.isOnline()){
  65. player.sendMessage(ChatColor.RED + "" + targetPlayer.getDisplayName() + "" + " is not online!");
  66. }
  67. if (targetPlayer.isBanned()) {
  68. player.sendMessage(ChatColor.RED + "" + targetPlayer.getDisplayName() + "" + " is banned!");
  69. }
  70. } else if (args.length == 2) {
  71. Player targetPlayer = player.getServer().getPlayer(args[0]);
  72. Player targetPlayer1 = player.getServer().getPlayer(args[1]);
  73. Location targetPlayer1Location = targetPlayer1.getLocation();
  74. targetPlayer.teleport(targetPlayer1Location);
  75. if (!targetPlayer.isOnline()){
  76. player.sendMessage(ChatColor.RED + "" + targetPlayer.getDisplayName() + "" + " is not online!");
  77. }
  78. if (targetPlayer.isBanned()) {
  79. player.sendMessage(ChatColor.RED + "" + targetPlayer.getDisplayName() + "" + " is banned!");
  80. }
  81. if (!targetPlayer1.isOnline()){
  82. player.sendMessage(ChatColor.RED + "" + targetPlayer1.getDisplayName() + "" + " is not online!");
  83. }
  84. if (targetPlayer1.isBanned()) {
  85. player.sendMessage(ChatColor.RED + "" + targetPlayer1.getDisplayName() + "" + " is banned!");
  86. }
  87. } else if (args.length == 3) {
  88. double x = Double.parseDouble(args[0]);
  89. double y = Double.parseDouble(args[1]);
  90. double z = Double.parseDouble(args[2]);
  91. Location cords = new Location(player.getWorld(), x, y, z);
  92. player.teleport(cords);
  93. } else if (args.length == 4) {
  94. double x = Double.parseDouble(args[1]);
  95. double y = Double.parseDouble(args[2]);
  96. double z = Double.parseDouble(args[3]);
  97. Player targetPlayer = player.getServer().getPlayer(args[0]);
  98. Location cords = new Location(targetPlayer.getWorld(), x, y, z);
  99. targetPlayer.teleport(cords);
  100. }
  101. else {
  102. player.sendMessage(ChatColor.DARK_RED + "Too much arguments");
  103. }
  104. }
  105. else if(commandLabel.equalsIgnoreCase("roll")){
  106. Random object = new Random();
  107. int i1;
  108. for (int i=1; i <= 1; i++) {
  109. i1 = object.nextInt(101);
  110. Bukkit.broadcastMessage(ChatColor.BOLD + "" + ChatColor.DARK_GRAY + player.getName() + " just rolled " + i1 + " from 100.");
  111. }
  112. }else if (commandLabel.equalsIgnoreCase("ko")){
  113. List<Player> onlinePlayers = Arrays.asList(Bukkit.getServer().getOnlinePlayers());
  114. Iterator<Player> iterator = onlinePlayers.iterator();
  115. while (iterator.hasNext()) {
  116. Player onlinePlayer = iterator.next();
  117. onlinePlayer.setHealth(0);
  118. }
  119. }else if (commandLabel.equalsIgnoreCase("motd")){
  120. player.sendMessage(ChatColor.GOLD + getConfig().getString("MOTD"));
  121. }
  122. return false;
  123. }
  124. }