Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.thecollapsemc.jobs;
- import java.util.Random;
- import org.bukkit.Location;
- import org.bukkit.Material;
- import org.bukkit.command.Command;
- import org.bukkit.command.CommandExecutor;
- import org.bukkit.command.CommandSender;
- import org.bukkit.entity.Player;
- import org.bukkit.inventory.ItemStack;
- import net.md_5.bungee.api.ChatColor;
- public class NewPackageCMD implements CommandExecutor {
- @Override
- public boolean onCommand(CommandSender s, Command arg1, String arg2, String[] args) {
- if(s instanceof Player){
- Player p = (Player) s;
- //They are not a postman, don't let them continue
- if(Jobs.getJobForPlayer(p) != "postman"){
- p.sendMessage(ChatColor.RED + "This command is for Postmen only!");
- return true;
- }else{
- for(String loc : Jobs.locations.keySet()){
- //This would be the potential package
- ItemStack potentialPackage = ItemUtils.createItem(Material.PAPER,ChatColor.YELLOW + "Drop off at the " + loc.toLowerCase(), ChatColor.GRAY+
- "Go to the " + loc.toLowerCase() + " with this, and type /dropoff");
- //They already have a package, don't give them a new one.
- if(p.getInventory().contains(potentialPackage)){
- p.sendMessage(ChatColor.RED + "You already have a package to deliver!");
- }else{
- //Randomly select a location from my HashMap locations that stores a <String, Location>
- Location newLoc = Jobs.locations.get(new Random().nextInt(Jobs.locations.size()));
- //This is the part that I think is causing the trouble,
- //I tried comparing all the locations in the HashMap to see if they were equal to the new one
- Location oldLoc = Jobs.locations.get(loc);
- if(Jobs.locations.get(loc).getX() == newLoc.getX() && oldLoc.getY() == newLoc.getY() && oldLoc.getZ() == newLoc.getZ()){
- p.getInventory().addItem(potentialPackage);
- }else{
- p.sendMessage(ChatColor.RED + "Oh no, something has gone wrong and we couldn't find a new package for you!");
- }
- }
- }
- }
- }
- return true;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement