Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- DrugsMain.java:
- package me.stress.drugs;
- import org.bukkit.plugin.java.JavaPlugin;
- import me.stress.drugs.commands.DrugsCommand;
- import me.stress.utils.Common;
- public class DrugsMain extends JavaPlugin {
- public static DrugsMain instance;
- @Override
- public void onEnable() {
- Common.registerCommand(new DrugsCommand());
- }
- @Override
- public void onDisable() {
- instance = null;
- }
- public static DrugsMain getInstance() {
- return instance;
- }
- }
- DrugsCommand.java:
- package me.stress.drugs.commands;
- import java.util.Arrays;
- import org.bukkit.Bukkit;
- import org.bukkit.Material;
- import org.bukkit.command.CommandSender;
- import org.bukkit.command.defaults.BukkitCommand;
- import org.bukkit.entity.Player;
- import org.bukkit.inventory.ItemStack;
- import me.stress.utils.Common;
- public class DrugsCommand extends BukkitCommand {
- public DrugsCommand() {
- super("drugs");
- setAliases(Arrays.asList("drug", "d"));
- setDescription("This is a basic Drugs core");
- }
- @Override
- public boolean execute(CommandSender sender, String commandLabel, String[] args) {
- if (!sender.hasPermission("drugs.use")) {
- Common.tell(sender, "&cYou do not have permission to use this command!");
- return true;
- }
- if (!sender.hasPermission("drugs.admin")) {
- Common.tell(sender, "&cYou do not have permission to use this command!");
- return true;
- }
- if (sender.hasPermission("drugs.use")) {
- if (args.length == 1) {
- if (args[0].equalsIgnoreCase("help")) {
- Common.tell(sender, "&8&m--------------------------------------------");
- Common.tell(sender, " &f/drugs help - Shows the help message");
- Common.tell(sender, " &f/drugs give - Gives a specified player drugs");
- Common.tell(sender, " &f/example - Example command");
- Common.tell(sender, " &aThis plugin was created by Stress_");
- Common.tell(sender, "&8&m--------------------------------------------");
- }
- }
- }
- if (sender.hasPermission("drugs.admin")) {
- if (args.length == 2) {
- if (args[0].equalsIgnoreCase("give")) {
- final Player target = Bukkit.getPlayer(args[1]);
- target.getInventory().addItem(new ItemStack(Material.WHEAT));
- Common.tell(sender, "&aYou have given drugs to " + args[1]);
- if (args[1] == null) {
- Common.tell(sender, "&cThe specified player is not online!");
- return true;
- }
- }
- }
- if (args.length < 1) {
- Common.tell(sender, "&8&m--------------------------------------------");
- Common.tell(sender, " &f/drugs help - Shows the help message");
- Common.tell(sender, " &f/drugs give - Gives a specified player drugs");
- Common.tell(sender, " &f/example - Example command");
- Common.tell(sender, " &aThis plugin was created by Stress_");
- Common.tell(sender, "&8&m--------------------------------------------");
- return true;
- }
- }
- return true;
- }
- }
- Common.java:
- package me.stress.utils;
- import java.lang.reflect.Field;
- import org.bukkit.Bukkit;
- import org.bukkit.ChatColor;
- import org.bukkit.command.CommandMap;
- import org.bukkit.command.CommandSender;
- import org.bukkit.command.defaults.BukkitCommand;
- public class Common {
- public static void tell(CommandSender toWhom, String... messages) {
- for (final String message : messages)
- tell(toWhom, message);
- }
- public static void tell(CommandSender toWhom, String message) {
- toWhom.sendMessage(colorize(message));
- }
- public static String colorize(String message) {
- return ChatColor.translateAlternateColorCodes('&', message);
- }
- public static void registerCommand(BukkitCommand command) {
- try {
- final Field commandMapField = Bukkit.getServer().getClass().getDeclaredField("commandMap");
- commandMapField.setAccessible(true);
- final CommandMap commandMap = (CommandMap) commandMapField.get(Bukkit.getServer());
- commandMap.register(command.getLabel(), command);
- } catch(final Exception e) {
- e.printStackTrace();
- }
- }
- }
- plugin.yml:
- name: Drugs
- main: me.stress.drugs.DrugsMain
- version: 1.0.0
- author: Stress_
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement