Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package net.h31ix.nas;
- //All the bukkit imports
- import org.bukkit.ChatColor;
- import org.bukkit.command.Command;
- import org.bukkit.command.CommandExecutor;
- import org.bukkit.command.CommandSender;
- import org.bukkit.entity.Player;
- public class CommandWeather implements CommandExecutor {
- //The basic, routine setup for coding a command
- public CommandWeather(){
- }
- //The startup method, sometimes this is used, sometimes not like in this example
- public boolean onCommand(CommandSender cs, Command cmd, String alias, String[] args) {
- //This method is called when a command gets sent.
- //We get a couple of variables imported so we can use this, btw this is all just copied and pasted stuff everytime you make a new command, its nothing you have to memorize.
- //CommandSender cs = the entity that sent the command (note ENTITY, not player, we dont know at this point if its the console or a player sending the command)
- //Command cmd = the command that was sent
- //String alias = this isn't used much, at least not by me. Ignore it here.
- //String[] args = an array where any post-command arguements are stored. for example if you typed "/weather SUNNY" sunny is an ARGUEMENT to weather. Weather is the base command, and is therfor not an arguement. Anything following the base command is stored in this array. Remember that arrays start at 0, so if you typed "/weather DERP HERP" array spot 0 would be "DERP" and array spot 1 would be "HERP"
- //Here we get the player who sent the command, actually this should check first if it is actually a player before doing this, so it's not very good code. If "weather" was sent by the console, it would give an error because the console isnt a player and cant be stored as one.
- Player player = (Player)cs;
- //If the command spells "weather", do the following
- if (cmd.getName().equalsIgnoreCase("weather"))
- {
- //if the player has permission to use the command, do the following
- if (player.hasPermission("nas.weather"))
- {
- //if the command has ONE argument attacked to it (this would be either sun, rain, or thunder) then do the following (otherwise the command is being used in the wrong format)
- if (args.length == 1)
- {
- if (args[0].equalsIgnoreCase("Sun"))
- {
- //If the word after weather is "sun", do the following
- //Set the player's world storm setting to false (off)
- player.getWorld().setStorm(false);
- //Set the player's world thundering setting to false (off)
- player.getWorld().setThundering(false);
- //Send the player the following message:
- player.sendMessage("Set world: "+ChatColor.GREEN+player.getWorld().getName()+ChatColor.WHITE+" to sunny.");
- }
- //else = OTHERWISE, so if the word after weather is NOT sun, check this:
- else if (args[0].equalsIgnoreCase("Rain"))
- {
- //If the word after weather is "rain", do the following
- //Set the player's world's storm setting to true (on)
- player.getWorld().setStorm(true);
- //Send the following message:
- player.sendMessage("Set world: "+ChatColor.GREEN+player.getWorld().getName()+ChatColor.WHITE+" to rainy.");
- }
- //The last case here is thunder, so if the word after weather IS NOT SUN, AND IS NOT RAIN, check this:
- else if (args[0].equalsIgnoreCase("Thunder"))
- {
- //If it is, do this:
- //You get the jist
- player.getWorld().setThundering(true);
- player.sendMessage("Set world: "+ChatColor.GREEN+player.getWorld().getName()+ChatColor.WHITE+" to thundering.");
- }
- //A SINGLE else means "if NONE of those are true, do this:"
- else
- {
- //Send this message if the word after weather is neither sun or rain or thunder
- player.sendMessage("Usage: /weather [sun/rain/thunder]");
- }
- }
- else
- {
- //This is an else statement for the arg.length check back up there, so if there are more than one word after weather or no words, send the usage feedback again:
- player.sendMessage("Usage: /weather [sun/rain/thunder]");
- }
- }
- else
- {
- //This is an else statement for the permission check up there, so if the player does NOT have the proper permissions, tell them this
- player.sendMessage("Insufficient permissisons!");
- }
- }
- //Commands always make you "return true" at the end, I could explain but it would not make sense. You just do this at the end.
- return true;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment