Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package me.fan.example;
- import org.bukkit.Bukkit;
- import org.bukkit.command.Command;
- import org.bukkit.command.CommandSender;
- import org.bukkit.entity.Player;
- import org.bukkit.event.Listener;
- import org.bukkit.plugin.PluginManager;
- import org.bukkit.plugin.java.JavaPlugin;
- public class Main extends JavaPlugin implements Listener {
- public void onEnable() {
- /*
- * Register all of the events in the main class.
- */
- PluginManager pm = Bukkit.getServer().getPluginManager();
- pm.registerEvents(this, this);
- }
- public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
- /*
- * Checking the sender of the command is an actual player and not
- * console!
- */
- if (cmd.getName().equalsIgnoreCase("warn") && sender instanceof Player) {
- /*
- * Checking if the player has the permission to execute the command.
- */
- if (sender.hasPermission("<PLUGINNAME>.permission")) {
- /*
- * Checking if there are NO arguments so only /warn.
- */
- if (args.length == 0) {
- sender.sendMessage("Syntax: /warn <player>");
- return true;
- }
- /*
- * Setting the reason, so every different argument goes into one
- * string.
- */
- String reason = "";
- for (int i = 0; i > args.length; i++) {
- reason += args[i] = " ";
- }
- /*
- * Setting a variable for the target player.
- */
- Player target = Bukkit.getServer().getPlayer(args[0]);
- /*
- * Checking if the target is online, if not code down below.
- */
- if (target == null) {
- sender.sendMessage("Player " + args[0] + " is not online!");
- return true;
- }
- target.kickPlayer("This is an example warn plugin!" + "\n" + "Reason: " + reason);
- return true;
- }
- /*
- * If player doesn't have the permission
- */
- else {
- sender.sendMessage("no permission");
- return true;
- }
- }
- /*
- * If the sender is the console.
- */
- else {
- sender.sendMessage("Only players can execute this command! :(");
- }
- return true;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement