Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package me.funnycube.testplugin;
- import org.bukkit.ChatColor;
- import org.bukkit.command.Command;
- import org.bukkit.command.CommandExecutor;
- import org.bukkit.command.CommandSender;
- import org.bukkit.entity.Player;
- import org.bukkit.plugin.java.JavaPlugin;
- public class Main extends JavaPlugin implements CommandExecutor {
- //so step 1
- //onEnable must be overriden
- //this is called an annotation
- //tells the compiler that we need to override the method in the JavaPlugin class
- //since this class extends JavaPlugin
- //means that is "extends" it or makes it more I guess
- //only 1 class will extend javaplugin and that is the class that has the onEnable and onDisable methods
- private String commandMessage = "&bYou typed a command";
- private int amountOfTimesCommandWasUsed = 0;
- private char colorcode = '&';
- @Override
- public void onEnable() {
- //you usually don't have to do this as onEnable already prints a message saying
- // <plugin> enabled
- //but what the hell, lets say it
- //now since we have a command below. We need to tell the server to register our command
- //we only need to do this 1 time, and only onEnable
- getCommand("test").setExecutor(this);
- //you see how this code didn't throw an error when all we typed was getCommand
- getLogger().info("Enabled funnycubes sick plugin!");
- }
- @Override
- public void onDisable() {
- getLogger().info("OMG Funnycubes plugin has been disabled");
- }
- //commandexecutor is an interface
- //it also needs to be overriden
- @Override
- public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
- if (!(sender instanceof Player)) {
- sender.sendMessage("You are not a player");
- return true;
- }
- Player player = (Player) sender;
- player.sendMessage(ChatColor.translateAlternateColorCodes(colorcode, commandMessage));
- amountOfTimesCommandWasUsed = amountOfTimesCommandWasUsed+1;
- player.sendMessage("Command was used "+amountOfTimesCommandWasUsed+" times");
- return true;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement