Advertisement
Guest User

Meow V1.0

a guest
Dec 16th, 2012
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.41 KB | None | 0 0
  1. package com.techresx.plugins.meow;
  2.  
  3. import java.util.HashMap;
  4. import org.bukkit.ChatColor;
  5. import org.bukkit.Sound;
  6. import org.bukkit.command.Command;
  7. import org.bukkit.command.CommandSender;
  8. import org.bukkit.entity.Player;
  9. import org.bukkit.plugin.java.JavaPlugin;
  10.  
  11.  
  12.  
  13. public class meow extends JavaPlugin {
  14.    
  15.     private static final String prefix = "[Meow] ";
  16.    
  17.     private static Integer cooldownInSeconds = 30;
  18.    
  19.     private HashMap<String, Long> cooldown = new HashMap<String,Long>();
  20.    
  21.     public void onEnable() {
  22.         loadConfiguration();
  23.         System.out.println(prefix + "has been loaded.");
  24.     }
  25.        
  26.     public void loadConfiguration(){
  27.         getConfig().addDefault("CooldownInSeconds", 30);
  28.         getConfig().options().copyDefaults(true);
  29.         saveConfig();
  30.         cooldownInSeconds = getConfig().getInt("CooldownInSeconds");
  31.     }
  32.    
  33.     @Override
  34.     public boolean onCommand(CommandSender sender, Command command, String label, String[] args)
  35.     {
  36.         if(label.equalsIgnoreCase("meow")) {
  37.             if(cooldown.containsKey(sender.getName()))
  38.             {
  39.                 Long lastUse = cooldown.get(sender.getName());
  40.                 Long diff = System.currentTimeMillis() - lastUse;
  41.                 if(diff <= cooldownInSeconds * 1000)
  42.                 {
  43.                     sender.sendMessage(ChatColor.GOLD + prefix + ChatColor.RED + "Please wait " + Long.toString(cooldownInSeconds - (diff / 1000), 0) + " seconds to use this command again");
  44.                     return true;   
  45.                 }
  46.             }
  47.             boolean self = false;
  48.             if(args.length != 1)
  49.             {
  50.                 self = true;
  51.             }
  52.             else if (!sender.getName().equalsIgnoreCase(args[0]))
  53.             {
  54.                
  55.                 Player p = getServer().getPlayer(args[0]);
  56.                 if(p != null && p.isOnline())
  57.                 {
  58.                     p.playSound(p.getLocation(), Sound.CAT_MEOW, 1, 0);
  59.                     p.sendMessage(ChatColor.GOLD + prefix + ChatColor.LIGHT_PURPLE + "You have been meow'd by " + sender.getName());
  60.                     cooldown.put(sender.getName(), System.currentTimeMillis());
  61.                 }
  62.                 else
  63.                 {
  64.                     sender.sendMessage(ChatColor.GOLD + prefix + ChatColor.RED + "Player is not online");
  65.                 }
  66.             }
  67.             else
  68.                 self = true;
  69.             if(self)
  70.             {
  71.                 sender.sendMessage(ChatColor.RED + "Don't meow yourself fool! Do /meow <player>");
  72.             }
  73.         }
  74.         return true;
  75.     }
  76. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement