Advertisement
Guest User

Untitled

a guest
Jun 19th, 2019
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.07 KB | None | 0 0
  1. DrugsMain.java:
  2.  
  3. package me.stress.drugs;
  4.  
  5. import org.bukkit.plugin.java.JavaPlugin;
  6.  
  7. import me.stress.drugs.commands.DrugsCommand;
  8. import me.stress.utils.Common;
  9.  
  10. public class DrugsMain extends JavaPlugin {
  11.  
  12. public static DrugsMain instance;
  13.  
  14. @Override
  15. public void onEnable() {
  16. Common.registerCommand(new DrugsCommand());
  17. }
  18.  
  19. @Override
  20. public void onDisable() {
  21. instance = null;
  22. }
  23.  
  24. public static DrugsMain getInstance() {
  25. return instance;
  26. }
  27.  
  28. }
  29.  
  30.  
  31. DrugsCommand.java:
  32.  
  33. package me.stress.drugs.commands;
  34.  
  35. import java.util.Arrays;
  36.  
  37. import org.bukkit.Bukkit;
  38. import org.bukkit.Material;
  39. import org.bukkit.command.CommandSender;
  40. import org.bukkit.command.defaults.BukkitCommand;
  41. import org.bukkit.entity.Player;
  42. import org.bukkit.inventory.ItemStack;
  43.  
  44. import me.stress.utils.Common;
  45.  
  46. public class DrugsCommand extends BukkitCommand {
  47.  
  48. public DrugsCommand() {
  49. super("drugs");
  50.  
  51. setAliases(Arrays.asList("drug", "d"));
  52. setDescription("This is a basic Drugs core");
  53. }
  54.  
  55. @Override
  56. public boolean execute(CommandSender sender, String commandLabel, String[] args) {
  57.  
  58. if (!sender.hasPermission("drugs.use")) {
  59. Common.tell(sender, "&cYou do not have permission to use this command!");
  60.  
  61. return true;
  62. }
  63.  
  64. if (!sender.hasPermission("drugs.admin")) {
  65. Common.tell(sender, "&cYou do not have permission to use this command!");
  66.  
  67. return true;
  68. }
  69.  
  70. if (sender.hasPermission("drugs.use")) {
  71. if (args.length == 1) {
  72. if (args[0].equalsIgnoreCase("help")) {
  73. Common.tell(sender, "&8&m--------------------------------------------");
  74. Common.tell(sender, " &f/drugs help - Shows the help message");
  75. Common.tell(sender, " &f/drugs give - Gives a specified player drugs");
  76. Common.tell(sender, " &f/example - Example command");
  77. Common.tell(sender, " &aThis plugin was created by Stress_");
  78. Common.tell(sender, "&8&m--------------------------------------------");
  79. }
  80. }
  81.  
  82. }
  83.  
  84. if (sender.hasPermission("drugs.admin")) {
  85. if (args.length == 2) {
  86. if (args[0].equalsIgnoreCase("give")) {
  87. final Player target = Bukkit.getPlayer(args[1]);
  88. target.getInventory().addItem(new ItemStack(Material.WHEAT));
  89. Common.tell(sender, "&aYou have given drugs to " + args[1]);
  90.  
  91. if (args[1] == null) {
  92. Common.tell(sender, "&cThe specified player is not online!");
  93. return true;
  94. }
  95. }
  96. }
  97.  
  98. if (args.length < 1) {
  99. Common.tell(sender, "&8&m--------------------------------------------");
  100. Common.tell(sender, " &f/drugs help - Shows the help message");
  101. Common.tell(sender, " &f/drugs give - Gives a specified player drugs");
  102. Common.tell(sender, " &f/example - Example command");
  103. Common.tell(sender, " &aThis plugin was created by Stress_");
  104. Common.tell(sender, "&8&m--------------------------------------------");
  105. return true;
  106. }
  107. }
  108.  
  109. return true;
  110.  
  111. }
  112. }
  113.  
  114.  
  115. Common.java:
  116.  
  117. package me.stress.utils;
  118.  
  119. import java.lang.reflect.Field;
  120.  
  121. import org.bukkit.Bukkit;
  122. import org.bukkit.ChatColor;
  123. import org.bukkit.command.CommandMap;
  124. import org.bukkit.command.CommandSender;
  125. import org.bukkit.command.defaults.BukkitCommand;
  126.  
  127. public class Common {
  128.  
  129. public static void tell(CommandSender toWhom, String... messages) {
  130. for (final String message : messages)
  131. tell(toWhom, message);
  132. }
  133.  
  134. public static void tell(CommandSender toWhom, String message) {
  135. toWhom.sendMessage(colorize(message));
  136. }
  137.  
  138. public static String colorize(String message) {
  139. return ChatColor.translateAlternateColorCodes('&', message);
  140. }
  141.  
  142. public static void registerCommand(BukkitCommand command) {
  143. try {
  144. final Field commandMapField = Bukkit.getServer().getClass().getDeclaredField("commandMap");
  145. commandMapField.setAccessible(true);
  146.  
  147. final CommandMap commandMap = (CommandMap) commandMapField.get(Bukkit.getServer());
  148. commandMap.register(command.getLabel(), command);
  149. } catch(final Exception e) {
  150. e.printStackTrace();
  151. }
  152. }
  153.  
  154. }
  155.  
  156.  
  157. plugin.yml:
  158.  
  159. name: Drugs
  160. main: me.stress.drugs.DrugsMain
  161. version: 1.0.0
  162. author: Stress_
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement