SHARE
TWEET

Untitled

a guest Apr 20th, 2019 79 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package us.zonix.core.social.command;
  2.  
  3. import org.apache.commons.lang.StringUtils;
  4. import org.bukkit.Bukkit;
  5. import org.bukkit.ChatColor;
  6. import org.bukkit.entity.Player;
  7. import us.zonix.core.profile.Profile;
  8. import us.zonix.core.util.command.BaseCommand;
  9. import us.zonix.core.util.command.Command;
  10. import us.zonix.core.util.command.CommandArgs;
  11.  
  12. public class MessageCommand extends BaseCommand {
  13.  
  14.     @Command(name = "message", aliases = {"msg", "m", "whisper", "w", "tell"}, requiresPlayer = true)
  15.     public void onCommand(CommandArgs command) {
  16.         Player player = command.getPlayer();
  17.         Profile profile = Profile.getByUuid(player.getUniqueId());
  18.         String[] args = command.getArgs();
  19.  
  20.         if (args.length < 2) {
  21.             player.sendMessage(ChatColor.RED + "Usage: /message <player> <message>");
  22.             return;
  23.         }
  24.  
  25.         if (player.getName().toLowerCase().equalsIgnoreCase(args[0].toLowerCase())) {
  26.             player.sendMessage(ChatColor.RED + "You cannot message yourself.");
  27.             return;
  28.         }
  29.  
  30.         if (!profile.getOptions().isReceivePrivateMessages()) {
  31.             player.sendMessage(ChatColor.RED + "You cannot send messages if you cannot receive them.");
  32.         }
  33.  
  34.         Player target = Bukkit.getPlayer(args[0]);
  35.  
  36.         if (target == null) {
  37.             player.sendMessage(ChatColor.RED + "That player is not online.");
  38.             return;
  39.         }
  40.  
  41.         if (profile.getIgnored().contains(target.getUniqueId())) {
  42.             player.sendMessage(ChatColor.RED + "You can't send a message to an ignored player.");
  43.             return;
  44.         }
  45.  
  46.         Profile targetProfile = Profile.getByUuid(target.getUniqueId());
  47.  
  48.         if (targetProfile == null) {
  49.             return;
  50.         }
  51.  
  52.         if (!targetProfile.getOptions().isReceivePrivateMessages()) {
  53.             player.sendMessage(ChatColor.RED + "That player is not receiving private messages.");
  54.             return;
  55.         }
  56.  
  57.         if (targetProfile.getIgnored().contains(player.getUniqueId())) {
  58.             player.sendMessage(ChatColor.RED + "That player has ignored you.");
  59.             return;
  60.         }
  61.  
  62.         String message = StringUtils.join(args, ' ', 1, args.length);
  63.  
  64.         main.getSocialHelper().sendMessage(player, profile, target, targetProfile, message);
  65.  
  66.     }
  67.  
  68. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top