Advertisement
Guest User

Untitled

a guest
Jan 1st, 2017
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.04 KB | None | 0 0
  1. package com.thecollapsemc.jobs;
  2.  
  3. import java.util.Random;
  4.  
  5. import org.bukkit.Location;
  6. import org.bukkit.Material;
  7. import org.bukkit.command.Command;
  8. import org.bukkit.command.CommandExecutor;
  9. import org.bukkit.command.CommandSender;
  10. import org.bukkit.entity.Player;
  11. import org.bukkit.inventory.ItemStack;
  12.  
  13. import net.md_5.bungee.api.ChatColor;
  14.  
  15. public class NewPackageCMD implements CommandExecutor {
  16.  
  17.     @Override
  18.     public boolean onCommand(CommandSender s, Command arg1, String arg2, String[] args) {
  19.         if(s instanceof Player){
  20.             Player p = (Player) s;
  21.             //They are not a postman, don't let them continue
  22.             if(Jobs.getJobForPlayer(p) != "postman"){
  23.                 p.sendMessage(ChatColor.RED + "This command is for Postmen only!");
  24.                 return true;
  25.             }else{
  26.                 for(String loc : Jobs.locations.keySet()){
  27.                     //This would be the potential package
  28.                     ItemStack potentialPackage = ItemUtils.createItem(Material.PAPER,ChatColor.YELLOW + "Drop off at the " + loc.toLowerCase(), ChatColor.GRAY+
  29.                             "Go to the " + loc.toLowerCase() + " with this, and type /dropoff");
  30.                     //They already have a package, don't give them a new one.
  31.                     if(p.getInventory().contains(potentialPackage)){
  32.                         p.sendMessage(ChatColor.RED + "You already have a package to deliver!");
  33.                     }else{
  34.                         //Randomly select a location from my HashMap locations that stores a <String, Location>
  35.                         Location newLoc = Jobs.locations.get(new Random().nextInt(Jobs.locations.size()));
  36.                         //This is the part that I think is causing the trouble,
  37.                          //I tried comparing all the locations in the HashMap to see if they were equal to the new one
  38.                         Location oldLoc = Jobs.locations.get(loc);
  39.                         if(Jobs.locations.get(loc).getX() == newLoc.getX() && oldLoc.getY() == newLoc.getY() && oldLoc.getZ() == newLoc.getZ()){
  40.                             p.getInventory().addItem(potentialPackage);
  41.                            
  42.                         }else{
  43.                             p.sendMessage(ChatColor.RED + "Oh no, something has gone wrong and we couldn't find a new package for you!");
  44.                         }
  45.                     }
  46.                 }
  47.             }
  48.         }
  49.         return true;
  50.     }
  51.  
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement